-
-
Notifications
You must be signed in to change notification settings - Fork 588
Expand file tree
/
Copy pathGenerateMiche.cs
More file actions
209 lines (163 loc) · 8.64 KB
/
GenerateMiche.cs
File metadata and controls
209 lines (163 loc) · 8.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
namespace AutoEvo;
/// <summary>
/// Dynamically generates the <see cref="Miche"/> tree for each <see cref="Patch"/>
/// </summary>
public class GenerateMiche : IRunStep
{
private readonly Patch patch;
private readonly AutoEvoGlobalCache globalCache;
public GenerateMiche(Patch patch, AutoEvoGlobalCache globalCache)
{
this.patch = patch;
this.globalCache = globalCache;
}
public int TotalSteps => 1;
public bool CanRunConcurrently => false;
public bool RunStep(RunResults results, SimulationCache cache)
{
var generatedMiche = GenerateMicheTree(globalCache);
results.AddNewMicheForPatch(patch, PopulateMiche(generatedMiche, cache));
return true;
}
public Miche GenerateMicheTree(AutoEvoGlobalCache globalCache)
{
var rootMiche = new Miche(globalCache.RootPressure);
var metabolicRoot = new Miche(globalCache.MetabolicStabilityPressure);
var avoidPredationMiche = new Miche(globalCache.GeneralAvoidPredationSelectionPressure);
var energyConsumptionMiche = new Miche(globalCache.EnergyConsumptionPressure);
var generatedMiche = new Miche(globalCache.EnvironmentalTolerancesPressure);
rootMiche.AddChild(metabolicRoot);
metabolicRoot.AddChild(avoidPredationMiche);
avoidPredationMiche.AddChild(energyConsumptionMiche);
energyConsumptionMiche.AddChild(generatedMiche);
// "Autotrophic" Miches
var phosphateMiche = new Miche(globalCache.PhosphatePressure);
var ammoniaMiche = new Miche(globalCache.AmmoniaPressure);
generatedMiche.AddChild(phosphateMiche);
phosphateMiche.AddChild(ammoniaMiche);
var lastGeneralMiche = ammoniaMiche;
// Glucose
if (patch.Biome.TryGetCompound(Compound.Glucose, CompoundAmountType.Biome, out var glucoseAmount) &&
glucoseAmount.Amount > 0)
{
var glucoseMiche = new Miche(globalCache.GlucoseConversionEfficiencyPressure);
glucoseMiche.AddChild(new Miche(globalCache.GlucoseCloudPressure));
lastGeneralMiche.AddChild(glucoseMiche);
}
var hasSmallIronChunk =
patch.Biome.Chunks.TryGetValue("ironSmallChunk", out var smallChunk) && smallChunk.Density > 0;
var hasBigIronChunk = patch.Biome.Chunks.TryGetValue("ironBigChunk", out var bigChunk) && bigChunk.Density > 0;
// Iron
if (hasSmallIronChunk || hasBigIronChunk)
{
var ironMiche = new Miche(globalCache.IronConversionEfficiencyPressure);
if (hasSmallIronChunk)
ironMiche.AddChild(new Miche(globalCache.SmallIronChunkPressure));
if (hasBigIronChunk)
ironMiche.AddChild(new Miche(globalCache.BigIronChunkPressure));
// TODO: maybe allowing direct iron in a patch should also be considered (though not currently used by
// any biome in the game)?
lastGeneralMiche.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;
var hasLargeSulfurChunk = patch.Biome.Chunks.TryGetValue("sulfurLargeChunk", out var largeSulfurChunk) &&
largeSulfurChunk.Density > 0;
// Hydrogen Sulfide
if ((patch.Biome.TryGetCompound(Compound.Hydrogensulfide, CompoundAmountType.Biome,
out var hydrogenSulfideAmount) &&
hydrogenSulfideAmount.Amount > 0) || hasSmallSulfurChunk || hasMediumSulfurChunk || hasLargeSulfurChunk)
{
var hydrogenSulfideMiche = new Miche(globalCache.HydrogenSulfideConversionEfficiencyPressure);
var generateATP = new Miche(globalCache.MinorGlucoseConversionEfficiencyPressure);
var maintainGlucose = new Miche(globalCache.MaintainGlucose);
if (hydrogenSulfideAmount.Amount > 0)
maintainGlucose.AddChild(new Miche(globalCache.HydrogenSulfideCloudPressure));
if (hasSmallSulfurChunk)
maintainGlucose.AddChild(new Miche(globalCache.SmallSulfurChunkPressure));
if (hasMediumSulfurChunk)
maintainGlucose.AddChild(new Miche(globalCache.MediumSulfurChunkPressure));
if (hasLargeSulfurChunk)
maintainGlucose.AddChild(new Miche(globalCache.LargeSulfurChunkPressure));
generateATP.AddChild(maintainGlucose);
hydrogenSulfideMiche.AddChild(generateATP);
lastGeneralMiche.AddChild(hydrogenSulfideMiche);
}
var hasRadioactiveChunk =
patch.Biome.Chunks.TryGetValue("radioactiveChunk", out var radioactiveChunk) &&
radioactiveChunk.Density > 0;
// Radioactive Chunk
if (hasRadioactiveChunk)
{
var radiationMiche = new Miche(globalCache.RadiationConversionEfficiencyPressure);
radiationMiche.AddChild(new Miche(globalCache.RadioactiveChunkPressure));
lastGeneralMiche.AddChild(radiationMiche);
}
// Sunlight
// TODO: should there be a dynamic energy level requirement rather than an absolute value?
if (patch.Biome.TryGetCompound(Compound.Sunlight, CompoundAmountType.Biome, out var sunlightAmount) &&
sunlightAmount.Ambient >= 0.25f)
{
var sunlightMiche = new Miche(globalCache.SunlightConversionEfficiencyPressure);
var generateATP = new Miche(globalCache.MinorGlucoseConversionEfficiencyPressure);
var maintainGlucose = new Miche(globalCache.MaintainGlucose);
var envPressure = new Miche(globalCache.SunlightCompoundPressure);
maintainGlucose.AddChild(envPressure);
generateATP.AddChild(maintainGlucose);
sunlightMiche.AddChild(generateATP);
lastGeneralMiche.AddChild(sunlightMiche);
}
// Heat
// TODO: the 60 here should be a constant or explained some other way what the threshold is
// As only non-LAWK organelles can use heat, we don't add the temperature miches when LAWK is on
if (patch.Biome.TryGetCompound(Compound.Temperature, CompoundAmountType.Biome,
out BiomeCompoundProperties temperatureAmount) &&
temperatureAmount.Ambient > 60 && globalCache.HasTemperature)
{
var tempMiche = new Miche(globalCache.TemperatureConversionEfficiencyPressure);
var tempSessilityMiche = new Miche(globalCache.TemperatureSessilityPressure);
var generateATP = new Miche(globalCache.MinorGlucoseConversionEfficiencyPressure);
var maintainGlucose = new Miche(globalCache.MaintainGlucose);
var tempCompPressure = new Miche(globalCache.TemperatureCompoundPressure);
tempSessilityMiche.AddChild(tempCompPressure);
maintainGlucose.AddChild(tempSessilityMiche);
generateATP.AddChild(maintainGlucose);
tempMiche.AddChild(generateATP);
lastGeneralMiche.AddChild(tempMiche);
}
var predationRoot = new Miche(globalCache.PredatorRoot);
var predationGlucose = new Miche(globalCache.MinorGlucoseConversionEfficiencyPressure);
// Per Target-Species Miches
foreach (var targetSpecies in patch.SpeciesInPatch)
{
// Predation Miches
predationGlucose.AddChild(new Miche(new PredationEffectivenessPressure(targetSpecies.Key, 6.0f)));
// Endosymbiosis Miches
if (targetSpecies.Key.PlayerSpecies && targetSpecies.Key.Endosymbiosis.StartedEndosymbiosis != null)
{
var endosymbiont = targetSpecies.Key.Endosymbiosis.StartedEndosymbiosis.Species;
var endosymbiosisPressure = new Miche(new EndosymbiosisPressure(endosymbiont, targetSpecies.Key, 1.0f));
generatedMiche.AddChild(endosymbiosisPressure);
}
}
if (patch.SpeciesInPatch.Count > 1)
predationRoot.AddChild(predationGlucose);
generatedMiche.AddChild(predationRoot);
return rootMiche;
}
public Miche PopulateMiche(Miche miche, SimulationCache cache)
{
// If no species, don't need to do anything
if (patch.SpeciesInPatch.Count < 1)
return miche;
var insertWorkMemory = new Miche.InsertWorkingMemory();
foreach (var species in patch.SpeciesInPatch.Keys)
{
miche.InsertSpecies(species, patch, null, cache, false, insertWorkMemory);
}
return miche;
}
}