Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added sulfur chunk energy source to auto-evo #5762

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/auto-evo/AutoEvoGlobalCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public class AutoEvoGlobalCache

public readonly CompoundConversionEfficiencyPressure HydrogenSulfideConversionEfficiencyPressure;
public readonly CompoundCloudPressure HydrogenSulfideCloudPressure;
public readonly ChunkCompoundPressure SmallSulfurChunkPressure;
public readonly ChunkCompoundPressure MediumSulfurChunkPressure;

public readonly CompoundConversionEfficiencyPressure SunlightConversionEfficiencyPressure;
public readonly EnvironmentalCompoundPressure SunlightCompoundPressure;
Expand Down Expand Up @@ -54,6 +56,10 @@ public AutoEvoGlobalCache(WorldGenerationSettings worldSettings)
Compound.Glucose, 1.0f);
HydrogenSulfideCloudPressure = new CompoundCloudPressure(Compound.Hydrogensulfide,
worldSettings.DayNightCycleEnabled, 1.0f);
SmallSulfurChunkPressure = new ChunkCompoundPressure("sulfurSmallChunk",
new LocalizedString("SMALL_SULFUR_CHUNK"), Compound.Hydrogensulfide, 1.0f);
MediumSulfurChunkPressure = new ChunkCompoundPressure("sulfurMediumChunk",
new LocalizedString("MEDIUM_SULFUR_CHUNK"), Compound.Hydrogensulfide, 1.0f);

SunlightConversionEfficiencyPressure =
new CompoundConversionEfficiencyPressure(Compound.Sunlight, Compound.Glucose, 1.0f);
Expand Down
24 changes: 19 additions & 5 deletions src/auto-evo/steps/GenerateMiche.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,31 @@ public Miche GenerateMicheTree(AutoEvoGlobalCache globalCache)
generatedMiche.AddChild(ironMiche);
}

var hasSmallSulfurChunk =
patch.Biome.Chunks.TryGetValue("sulfurSmallChunk", out var smallSulfurChunk) &&
smallSulfurChunk.Density > 0;

var hasMediumSulfurChunk = patch.Biome.Chunks.TryGetValue("sulfurMediumChunk", out var mediumSulfurChunk) &&
mediumSulfurChunk.Density > 0;

// Hydrogen Sulfide
if (patch.Biome.TryGetCompound(Compound.Hydrogensulfide, CompoundAmountType.Biome,
out var hydrogenSulfideAmount) &&
hydrogenSulfideAmount.Amount > 0)
if ((patch.Biome.TryGetCompound(Compound.Hydrogensulfide, CompoundAmountType.Biome,
out var hydrogenSulfideAmount) &&
hydrogenSulfideAmount.Amount > 0) || hasSmallSulfurChunk || hasMediumSulfurChunk)
{
var hydrogenSulfideMiche = new Miche(globalCache.HydrogenSulfideConversionEfficiencyPressure);
var generateATP = new Miche(globalCache.MinorGlucoseConversionEfficiencyPressure);
var maintainGlucose = new Miche(globalCache.MaintainGlucose);
var envPressure = new Miche(globalCache.HydrogenSulfideCloudPressure);

maintainGlucose.AddChild(envPressure);
if (hydrogenSulfideAmount.Amount > 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If hydrogenSulfide is not present in the patch, just the chunks, I might be wrong, but isn't this a crash?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think my IDE or the C# compiler should have prevented that. As hydrogenSulfideAmount is a struct, when the TryGet fails it returns a default initialized struct instance (i.e. so all values are initialized to 0, which should mean the amount is zero in the case that the TryGet failed). And that should mean writing this check is safe like this.

maintainGlucose.AddChild(new Miche(globalCache.HydrogenSulfideCloudPressure));

if (hasSmallSulfurChunk)
maintainGlucose.AddChild(new Miche(globalCache.SmallSulfurChunkPressure));

if (hasMediumSulfurChunk)
maintainGlucose.AddChild(new Miche(globalCache.MediumSulfurChunkPressure));

generateATP.AddChild(maintainGlucose);
hydrogenSulfideMiche.AddChild(generateATP);
generatedMiche.AddChild(hydrogenSulfideMiche);
Expand Down