expedition air mod (#17369)

Co-authored-by: deltanedas <@deltanedas:kde.org>
This commit is contained in:
deltanedas
2023-06-16 05:25:25 +00:00
committed by GitHub
parent f0896685ff
commit 41fae6e9cd
6 changed files with 181 additions and 11 deletions

View File

@@ -105,14 +105,15 @@ public sealed class SpawnSalvageMissionJob : Job<bool>
_entManager.Dirty(gravity, metadata); _entManager.Dirty(gravity, metadata);
// Atmos // Atmos
var atmos = _entManager.EnsureComponent<MapAtmosphereComponent>(mapUid); var air = _prototypeManager.Index<SalvageAirMod>(mission.Air);
atmos.Space = false; // copy into a new array since the yml deserialization discards the fixed length
var moles = new float[Atmospherics.AdjustedNumberOfGases]; var moles = new float[Atmospherics.AdjustedNumberOfGases];
moles[(int) Gas.Oxygen] = 21.824779f; air.Gases.CopyTo(moles, 0);
moles[(int) Gas.Nitrogen] = 82.10312f; var atmos = _entManager.EnsureComponent<MapAtmosphereComponent>(mapUid);
atmos.Space = air.Space;
atmos.Mixture = new GasMixture(2500) atmos.Mixture = new GasMixture(2500)
{ {
// TODO: temperature mods
Temperature = 293.15f, Temperature = 293.15f,
Moles = moles, Moles = moles,
}; };

View File

@@ -0,0 +1,43 @@
using Content.Shared.Atmos;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.List;
namespace Content.Shared.Salvage.Expeditions.Modifiers;
/// <summary>
/// Prototype for a planet's air gas mixture.
/// Used when creating the planet for a salvage expedition.
/// Which one is selected depends on the mission difficulty, different weightedRandoms are picked from.
/// </summary>
[Prototype("salvageAirMod")]
public sealed class SalvageAirMod : IPrototype, ISalvageMod
{
[IdDataField]
public string ID { get; } = default!;
/// <inheritdoc/>
[DataField("desc")]
public string Description { get; } = string.Empty;
/// <inheritdoc/>
[DataField("cost")]
public float Cost { get; } = 0f;
/// <summary>
/// Set to true if this planet will have no atmosphere.
/// </summary>
[DataField("space")]
public bool Space;
/// <summary>
/// Number of moles of each gas in the mixture.
/// </summary>
[DataField("gases")]
public float[] Gases = new float[Atmospherics.AdjustedNumberOfGases];
/// <summary>
/// Biomes this air mixture is allowed to occur in.
/// </summary>
[DataField("biomes", customTypeSerializer: typeof(PrototypeIdListSerializer<SalvageBiomeMod>))]
public List<string>? Biomes;
}

View File

@@ -100,6 +100,7 @@ public sealed record SalvageMission(
string Faction, string Faction,
SalvageMissionType Mission, SalvageMissionType Mission,
string Biome, string Biome,
string Air,
Color? Color, Color? Color,
TimeSpan Duration, TimeSpan Duration,
Dictionary<string, int> Loot, Dictionary<string, int> Loot,
@@ -135,6 +136,11 @@ public sealed record SalvageMission(
/// </summary> /// </summary>
public readonly string Biome = Biome; public readonly string Biome = Biome;
/// <summary>
/// Air mixture to be used for the mission's planet.
/// </summary>
public readonly string Air = Air;
/// <summary> /// <summary>
/// Lighting color to be used (AKA outdoor lighting). /// Lighting color to be used (AKA outdoor lighting).
/// </summary> /// </summary>

View File

@@ -101,11 +101,15 @@ public abstract class SharedSalvageSystem : EntitySystem
var dungeon = GetDungeon(biome.ID, rand, ref rating); var dungeon = GetDungeon(biome.ID, rand, ref rating);
var mods = new List<string>(); var mods = new List<string>();
SalvageLightMod? light = null; var air = GetAir(biome.ID, rand, ref rating);
if (air.Description != string.Empty)
if (biome.BiomePrototype != null) {
mods.Add(air.Description);
}
var light = GetLight(biome.ID, rand, ref rating);
if (light.Description != string.Empty)
{ {
light = GetLight(biome.ID, rand, ref rating);
mods.Add(light.Description); mods.Add(light.Description);
} }
@@ -115,15 +119,16 @@ public abstract class SharedSalvageSystem : EntitySystem
exactDuration = MathF.Round(exactDuration / 15f) * 15f; exactDuration = MathF.Round(exactDuration / 15f) * 15f;
var duration = TimeSpan.FromSeconds(exactDuration); var duration = TimeSpan.FromSeconds(exactDuration);
if (time.ID != "StandardTime") if (time.Description != string.Empty)
{ {
mods.Add(time.Description); mods.Add(time.Description);
} }
var loots = GetLoot(config, _proto.EnumeratePrototypes<SalvageLootPrototype>().Where(o => !o.Guaranteed).ToList(), GetDifficulty(difficulty), seed); var loots = GetLoot(config, _proto.EnumeratePrototypes<SalvageLootPrototype>().Where(o => !o.Guaranteed).ToList(), GetDifficulty(difficulty), seed);
return new SalvageMission(seed, difficulty, dungeon.ID, faction.ID, config, biome.ID, light?.Color, duration, loots, mods); return new SalvageMission(seed, difficulty, dungeon.ID, faction.ID, config, biome.ID, air.ID, light.Color, duration, loots, mods);
} }
// TODO: probably worth putting the biome whitelist thing in a common thing then having a getmod overload for it
public SalvageDungeonMod GetDungeon(string biome, System.Random rand, ref float rating) public SalvageDungeonMod GetDungeon(string biome, System.Random rand, ref float rating)
{ {
var mods = _proto.EnumeratePrototypes<SalvageDungeonMod>().ToList(); var mods = _proto.EnumeratePrototypes<SalvageDungeonMod>().ToList();
@@ -146,6 +151,25 @@ public abstract class SharedSalvageSystem : EntitySystem
throw new InvalidOperationException(); throw new InvalidOperationException();
} }
public SalvageAirMod GetAir(string biome, System.Random rand, ref float rating)
{
var mods = _proto.EnumeratePrototypes<SalvageAirMod>().ToList();
mods.Sort((x, y) => string.Compare(x.ID, y.ID, StringComparison.Ordinal));
rand.Shuffle(mods);
foreach (var mod in mods)
{
if (mod.Biomes?.Contains(biome) == false || mod.Cost > rating)
continue;
rating -= mod.Cost;
return mod;
}
throw new InvalidOperationException();
}
public SalvageLightMod GetLight(string biome, System.Random rand, ref float rating) public SalvageLightMod GetLight(string biome, System.Random rand, ref float rating)
{ {
var mods = _proto.EnumeratePrototypes<SalvageLightMod>().ToList(); var mods = _proto.EnumeratePrototypes<SalvageLightMod>().ToList();

View File

@@ -100,3 +100,98 @@
proto: LavaBrig proto: LavaBrig
biomeMods: biomeMods:
- Lava - Lava
# Air mixtures
- type: salvageAirMod
id: Space
desc: No atmosphere
space: true
cost: 1
biomes:
- Caves
- Lava
- type: salvageAirMod
id: Breathable
gases:
- 21.824779 # oxygen
- 82.10312 # nitrogen
biomes:
- Caves
#- LowDesert
- Snow
- Grasslands
- type: salvageAirMod
id: Sleepy
cost: 1
desc: Dangerous atmosphere
gases:
- 21.824779 # oxygen
- 72.10312 # nitrogen
- 0
- 0
- 0
- 0
- 0
- 10 # nitrous oxide
biomes:
- Caves
#- LowDesert
- Snow
- Grasslands
- Lava
- type: salvageAirMod
id: Poisoned
cost: 2
desc: Dangerous atmosphere
gases:
- 21.824779 # oxygen
- 77.10312 # nitrogen
- 10 # carbon dioxide
biomes:
- Caves
#- LowDesert
- Snow
- Grasslands
- Lava
- type: salvageAirMod
id: Poison
cost: 3
desc: Toxic atmosphere
gases:
- 21.824779 # oxygen
- 0
- 82.10312 # carbon dioxide
biomes:
- Caves
- Snow
- Lava
- type: salvageAirMod
id: Plasma
cost: 4
desc: Toxic atmosphere
gases:
- 0
- 0
- 0
- 103.927899 # plasma
biomes:
- Caves
- Lava
- type: salvageAirMod
id: Burnable
cost: 5
desc: Volatile atmosphere
gases:
- 21.824779 # oxygen
- 0
- 0
- 82.10312 # plasma
biomes:
- Caves
- Lava

View File

@@ -55,6 +55,7 @@
WeaponXrayCannon: 1.0 WeaponXrayCannon: 1.0
WeaponSniperHristov: 1.0 WeaponSniperHristov: 1.0
# extremely rare weapons # extremely rare weapons
GatfruitSeeds: 0.25
WeaponLauncherRocket: 0.1 WeaponLauncherRocket: 0.1
# rare chemicals # rare chemicals
CognizineChemistryBottle: 1.0 CognizineChemistryBottle: 1.0