From 6d66165400859ef8388f6b2a4f202e8ae97a1e5f Mon Sep 17 00:00:00 2001 From: adQuid <28126232+adQuid@users.noreply.github.com> Date: Sun, 10 Nov 2024 08:58:09 -0500 Subject: [PATCH 01/11] make compound changes work on targets instead of raw additions --- .../PhotosynthesisProductionEffect.cs | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/general/world_effects/PhotosynthesisProductionEffect.cs b/src/general/world_effects/PhotosynthesisProductionEffect.cs index 3c50a06d93..81ee8342c2 100644 --- a/src/general/world_effects/PhotosynthesisProductionEffect.cs +++ b/src/general/world_effects/PhotosynthesisProductionEffect.cs @@ -49,8 +49,10 @@ private void ApplyCompoundsAddition() if (patch.SpeciesInPatch.Count < 1) continue; - float oxygenBalance = 0; - float co2Balance = 0; + float oxygenIn = 0; + float oxygenOut = 0; + float co2In = 0; + float co2Out = 0; foreach (var species in patch.SpeciesInPatch) { @@ -101,11 +103,11 @@ private void ApplyCompoundsAddition() { if (input.Key.ID is Compound.Oxygen) { - oxygenBalance -= input.Value * inputModifier * effectiveSpeed * species.Value; + oxygenOut += input.Value * inputModifier * effectiveSpeed * species.Value; } else if (input.Key.ID is Compound.Carbondioxide) { - co2Balance -= input.Value * inputModifier * effectiveSpeed * species.Value; + co2Out += input.Value * inputModifier * effectiveSpeed * species.Value; } } @@ -114,18 +116,18 @@ private void ApplyCompoundsAddition() { if (output.Key.ID is Compound.Oxygen) { - oxygenBalance += output.Value * outputModifier * effectiveSpeed * species.Value; + oxygenIn += output.Value * outputModifier * effectiveSpeed * species.Value; } else if (output.Key.ID is Compound.Carbondioxide) { - co2Balance += output.Value * outputModifier * effectiveSpeed * species.Value; + co2In += output.Value * outputModifier * effectiveSpeed * species.Value; } } } } // Scale the balances to make the changes less drastic - oxygenBalance *= modifier; + /*oxygenBalance *= modifier; co2Balance *= modifier; changesToApply.Clear(); @@ -134,7 +136,15 @@ private void ApplyCompoundsAddition() changesToApply[Compound.Oxygen] = oxygenBalance; if (co2Balance != 0) - changesToApply[Compound.Carbondioxide] = co2Balance; + changesToApply[Compound.Carbondioxide] = co2Balance;*/ + + float oxygenTarget = oxygenIn / oxygenOut * 20.0f; + patch.Biome.TryGetCompound(Compound.Oxygen, CompoundAmountType.Biome, out var existingOxygen); + changesToApply[Compound.Oxygen] = oxygenTarget - existingOxygen.Ambient; + + float co2Target = co2In / co2Out * 20.0f; + patch.Biome.TryGetCompound(Compound.Carbondioxide, CompoundAmountType.Biome, out var existingCo2); + changesToApply[Compound.Carbondioxide] = co2Target - existingCo2.Ambient; if (changesToApply.Count > 0) patch.Biome.ApplyLongTermCompoundChanges(patch.BiomeTemplate, changesToApply, cloudSizes); From 01a1eedcb204c5e3ef735f196cd2462f29d955e1 Mon Sep 17 00:00:00 2001 From: adQuid <28126232+adQuid@users.noreply.github.com> Date: Sun, 17 Nov 2024 20:20:05 -0500 Subject: [PATCH 02/11] rebalance world effects --- .../world_effects/CompoundDiffusionEffect.cs | 3 +- .../PhotosynthesisProductionEffect.cs | 60 ++++++++++++------- src/general/world_effects/VolcanismEffect.cs | 2 +- 3 files changed, 40 insertions(+), 25 deletions(-) diff --git a/src/general/world_effects/CompoundDiffusionEffect.cs b/src/general/world_effects/CompoundDiffusionEffect.cs index b4ef79b040..921e440751 100644 --- a/src/general/world_effects/CompoundDiffusionEffect.cs +++ b/src/general/world_effects/CompoundDiffusionEffect.cs @@ -33,8 +33,7 @@ private static (float Ambient, float Density) CalculateWantedMoveAmounts(Patch s // Apply patch distance to diminish how much to move (to make ocean bottoms receive less surface // resources like oxygen) // TODO: improve the formula here as sqrt isn't the best - float moveModifier = Constants.COMPOUND_DIFFUSE_BASE_MOVE_AMOUNT / - MathF.Sqrt(Constants.COMPOUND_DIFFUSE_BASE_DISTANCE + Math.Abs(sourcePatch.Depth[0] - adjacent.Depth[0])); + float moveModifier = Constants.COMPOUND_DIFFUSE_BASE_MOVE_AMOUNT; adjacent.Biome.TryGetCompound(compound.Key, CompoundAmountType.Biome, out var destinationAmount); diff --git a/src/general/world_effects/PhotosynthesisProductionEffect.cs b/src/general/world_effects/PhotosynthesisProductionEffect.cs index 81ee8342c2..11e5ba4b5b 100644 --- a/src/general/world_effects/PhotosynthesisProductionEffect.cs +++ b/src/general/world_effects/PhotosynthesisProductionEffect.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using Godot; using Newtonsoft.Json; using Systems; @@ -29,12 +30,9 @@ public void OnTimePassed(double elapsed, double totalTimePassed) private void ApplyCompoundsAddition() { // These affect the final balance - var outputModifier = 1.5f; + var outputModifier = 1.0f; var inputModifier = 1.0f; - // This affects how fast the conditions change, but also the final balance somewhat - var modifier = 0.00015f; - List microbeProcesses = []; var cloudSizes = new Dictionary(); @@ -103,11 +101,11 @@ private void ApplyCompoundsAddition() { if (input.Key.ID is Compound.Oxygen) { - oxygenOut += input.Value * inputModifier * effectiveSpeed * species.Value; + oxygenIn += input.Value * inputModifier * effectiveSpeed * species.Value; } else if (input.Key.ID is Compound.Carbondioxide) { - co2Out += input.Value * inputModifier * effectiveSpeed * species.Value; + co2In += input.Value * inputModifier * effectiveSpeed * species.Value; } } @@ -116,35 +114,53 @@ private void ApplyCompoundsAddition() { if (output.Key.ID is Compound.Oxygen) { - oxygenIn += output.Value * outputModifier * effectiveSpeed * species.Value; + oxygenOut += output.Value * outputModifier * effectiveSpeed * species.Value; } else if (output.Key.ID is Compound.Carbondioxide) { - co2In += output.Value * outputModifier * effectiveSpeed * species.Value; + co2Out += output.Value * outputModifier * effectiveSpeed * species.Value; } } } } - // Scale the balances to make the changes less drastic - /*oxygenBalance *= modifier; - co2Balance *= modifier; + float oxygenTarget; + float co2Target; - changesToApply.Clear(); + patch.Biome.TryGetCompound(Compound.Oxygen, CompoundAmountType.Biome, out var existingOxygen); + patch.Biome.TryGetCompound(Compound.Carbondioxide, CompoundAmountType.Biome, out var existingCo2); - if (oxygenBalance != 0) - changesToApply[Compound.Oxygen] = oxygenBalance; + float total = existingOxygen.Ambient + existingCo2.Ambient; - if (co2Balance != 0) - changesToApply[Compound.Carbondioxide] = co2Balance;*/ + if (oxygenOut == 0) + { + if (co2Out == 0) + { + //in the rare event we aren't making either compound, do nothing + GD.Print(patch.Name + " not producing either compound"); + return; + } - float oxygenTarget = oxygenIn / oxygenOut * 20.0f; - patch.Biome.TryGetCompound(Compound.Oxygen, CompoundAmountType.Biome, out var existingOxygen); - changesToApply[Compound.Oxygen] = oxygenTarget - existingOxygen.Ambient; + oxygenTarget = 0; + co2Target = total; + } + else if (co2Out == 0) + { + oxygenTarget = total; + co2Target = 0; + } + else + { + GD.Print("\no2 production detected in "+patch.Name+": \n o2 = " + oxygenOut + ", co2 = " + co2Out+", total = "+total+ + "\n existing o2 = "+existingOxygen.Ambient+", existingCo2 = "+existingCo2.Ambient); + oxygenTarget = oxygenOut / (oxygenIn + co2In) * total; + co2Target = co2Out / (oxygenIn + co2In) * total; - float co2Target = co2In / co2Out * 20.0f; - patch.Biome.TryGetCompound(Compound.Carbondioxide, CompoundAmountType.Biome, out var existingCo2); - changesToApply[Compound.Carbondioxide] = co2Target - existingCo2.Ambient; + GD.Print("=>target O2 = " + oxygenTarget + ", target CO2 = " + co2Target); + } + + changesToApply[Compound.Oxygen] = (oxygenTarget - existingOxygen.Ambient) / 2.0f; + changesToApply[Compound.Carbondioxide] = (co2Target - existingCo2.Ambient) / 2.0f; if (changesToApply.Count > 0) patch.Biome.ApplyLongTermCompoundChanges(patch.BiomeTemplate, changesToApply, cloudSizes); diff --git a/src/general/world_effects/VolcanismEffect.cs b/src/general/world_effects/VolcanismEffect.cs index 4e629b6417..8ba92e3c5a 100644 --- a/src/general/world_effects/VolcanismEffect.cs +++ b/src/general/world_effects/VolcanismEffect.cs @@ -72,7 +72,7 @@ private void ProduceCO2(Patch patch, float co2Strength, float threshold) return; // TODO: should this clamp or not? - addedCo2[Compound.Carbondioxide] = Math.Clamp(amount.Ambient + co2Strength, 0, threshold); + addedCo2[Compound.Carbondioxide] = Math.Clamp(co2Strength, 0, threshold); patch.Biome.ApplyLongTermCompoundChanges(patch.BiomeTemplate, addedCo2, cloudSizesDummy); } From eb051d65d39b1726db6c0bab575b9f7aeb84f8c8 Mon Sep 17 00:00:00 2001 From: adQuid <28126232+adQuid@users.noreply.github.com> Date: Sun, 17 Nov 2024 21:03:31 -0500 Subject: [PATCH 03/11] fix return statement --- .../world_effects/PhotosynthesisProductionEffect.cs | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/general/world_effects/PhotosynthesisProductionEffect.cs b/src/general/world_effects/PhotosynthesisProductionEffect.cs index 11e5ba4b5b..31ab9a67c0 100644 --- a/src/general/world_effects/PhotosynthesisProductionEffect.cs +++ b/src/general/world_effects/PhotosynthesisProductionEffect.cs @@ -136,9 +136,8 @@ private void ApplyCompoundsAddition() { if (co2Out == 0) { - //in the rare event we aren't making either compound, do nothing - GD.Print(patch.Name + " not producing either compound"); - return; + // in the rare event we aren't making either compound, do nothing + continue; } oxygenTarget = 0; @@ -151,12 +150,8 @@ private void ApplyCompoundsAddition() } else { - GD.Print("\no2 production detected in "+patch.Name+": \n o2 = " + oxygenOut + ", co2 = " + co2Out+", total = "+total+ - "\n existing o2 = "+existingOxygen.Ambient+", existingCo2 = "+existingCo2.Ambient); oxygenTarget = oxygenOut / (oxygenIn + co2In) * total; co2Target = co2Out / (oxygenIn + co2In) * total; - - GD.Print("=>target O2 = " + oxygenTarget + ", target CO2 = " + co2Target); } changesToApply[Compound.Oxygen] = (oxygenTarget - existingOxygen.Ambient) / 2.0f; From e887839bb5fece4390e955d47c41d16d32111ea4 Mon Sep 17 00:00:00 2001 From: adQuid <28126232+adQuid@users.noreply.github.com> Date: Sun, 17 Nov 2024 21:07:37 -0500 Subject: [PATCH 04/11] more trimming --- simulation_parameters/Constants.cs | 3 +-- src/auto-evo/AutoEvoGlobalCache.cs | 2 +- src/general/world_effects/VolcanismEffect.cs | 3 +++ 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/simulation_parameters/Constants.cs b/simulation_parameters/Constants.cs index 0c65b9fac7..2efbe06c61 100644 --- a/simulation_parameters/Constants.cs +++ b/simulation_parameters/Constants.cs @@ -1164,8 +1164,7 @@ public static class Constants public const float GLUCOSE_MIN = 0.0f; // Tweak variable for how fast compounds diffuse between patches - public const float COMPOUND_DIFFUSE_BASE_MOVE_AMOUNT = 1; - public const float COMPOUND_DIFFUSE_BASE_DISTANCE = 1; + public const float COMPOUND_DIFFUSE_BASE_MOVE_AMOUNT = 0.8f; // Volcanism co2 production configuration public const float VOLCANISM_VENTS_CO2_STRENGTH = 0.15f; diff --git a/src/auto-evo/AutoEvoGlobalCache.cs b/src/auto-evo/AutoEvoGlobalCache.cs index d4efff6e6a..b4a2c79bc2 100644 --- a/src/auto-evo/AutoEvoGlobalCache.cs +++ b/src/auto-evo/AutoEvoGlobalCache.cs @@ -55,7 +55,7 @@ public AutoEvoGlobalCache(WorldGenerationSettings worldSettings) SunlightConversionEfficiencyPressure = new CompoundConversionEfficiencyPressure(Compound.Sunlight, Compound.Glucose, 1.0f); - SunlightCompoundPressure = new EnvironmentalCompoundPressure(Compound.Sunlight, Compound.Glucose, 20000, 1.0f); + SunlightCompoundPressure = new EnvironmentalCompoundPressure(Compound.Sunlight, Compound.Glucose, 400000, 1.0f); TemperatureConversionEfficiencyPressure = new CompoundConversionEfficiencyPressure(Compound.Temperature, Compound.ATP, 1.0f); diff --git a/src/general/world_effects/VolcanismEffect.cs b/src/general/world_effects/VolcanismEffect.cs index 8ba92e3c5a..5cb962a525 100644 --- a/src/general/world_effects/VolcanismEffect.cs +++ b/src/general/world_effects/VolcanismEffect.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using Godot; using Newtonsoft.Json; /// @@ -32,6 +33,8 @@ private void ApplyVolcanism() { foreach (var patchKeyValue in targetWorld.Map.Patches) { + GD.Print(patchKeyValue.Value + " volcanism"); + // TODO: make these configured by the biomes.json file if (patchKeyValue.Value.BiomeType == BiomeType.Vents) { From c87d669b6bb92d24c05d1b57027665078de135a7 Mon Sep 17 00:00:00 2001 From: adQuid <28126232+adQuid@users.noreply.github.com> Date: Mon, 18 Nov 2024 07:15:13 -0500 Subject: [PATCH 05/11] remove unneeded import --- src/general/world_effects/CompoundDiffusionEffect.cs | 3 +-- src/general/world_effects/PhotosynthesisProductionEffect.cs | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/general/world_effects/CompoundDiffusionEffect.cs b/src/general/world_effects/CompoundDiffusionEffect.cs index 921e440751..7317a15f0d 100644 --- a/src/general/world_effects/CompoundDiffusionEffect.cs +++ b/src/general/world_effects/CompoundDiffusionEffect.cs @@ -1,5 +1,4 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using Godot; using Newtonsoft.Json; diff --git a/src/general/world_effects/PhotosynthesisProductionEffect.cs b/src/general/world_effects/PhotosynthesisProductionEffect.cs index 31ab9a67c0..dbc76c59a3 100644 --- a/src/general/world_effects/PhotosynthesisProductionEffect.cs +++ b/src/general/world_effects/PhotosynthesisProductionEffect.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using Godot; using Newtonsoft.Json; using Systems; From d773d72fb4044c61096d57eaf496d609fe1bdac8 Mon Sep 17 00:00:00 2001 From: adQuid <28126232+adQuid@users.noreply.github.com> Date: Mon, 18 Nov 2024 08:02:23 -0500 Subject: [PATCH 06/11] remove debugging code --- src/general/world_effects/VolcanismEffect.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/general/world_effects/VolcanismEffect.cs b/src/general/world_effects/VolcanismEffect.cs index 5cb962a525..8ba92e3c5a 100644 --- a/src/general/world_effects/VolcanismEffect.cs +++ b/src/general/world_effects/VolcanismEffect.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using Godot; using Newtonsoft.Json; /// @@ -33,8 +32,6 @@ private void ApplyVolcanism() { foreach (var patchKeyValue in targetWorld.Map.Patches) { - GD.Print(patchKeyValue.Value + " volcanism"); - // TODO: make these configured by the biomes.json file if (patchKeyValue.Value.BiomeType == BiomeType.Vents) { From 78587684d70f278c5b3fee4b95838184b3fdc9dc Mon Sep 17 00:00:00 2001 From: adQuid <28126232+adQuid@users.noreply.github.com> Date: Mon, 18 Nov 2024 17:43:16 -0500 Subject: [PATCH 07/11] remove unused parameter (might add back later) --- src/general/world_effects/CompoundDiffusionEffect.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/general/world_effects/CompoundDiffusionEffect.cs b/src/general/world_effects/CompoundDiffusionEffect.cs index 7317a15f0d..487ed94109 100644 --- a/src/general/world_effects/CompoundDiffusionEffect.cs +++ b/src/general/world_effects/CompoundDiffusionEffect.cs @@ -26,12 +26,11 @@ public void OnTimePassed(double elapsed, double totalTimePassed) HandlePatchCompoundDiffusion(); } - private static (float Ambient, float Density) CalculateWantedMoveAmounts(Patch sourcePatch, Patch adjacent, + private static (float Ambient, float Density) CalculateWantedMoveAmounts(Patch adjacent, KeyValuePair compound) { // Apply patch distance to diminish how much to move (to make ocean bottoms receive less surface // resources like oxygen) - // TODO: improve the formula here as sqrt isn't the best float moveModifier = Constants.COMPOUND_DIFFUSE_BASE_MOVE_AMOUNT; adjacent.Biome.TryGetCompound(compound.Key, CompoundAmountType.Biome, @@ -72,7 +71,7 @@ private void HandlePatchCompoundDiffusion() foreach (var adjacent in patch.Value.Adjacent) { - var (ambient, density) = CalculateWantedMoveAmounts(patch.Value, adjacent, compound); + var (ambient, density) = CalculateWantedMoveAmounts(adjacent, compound); // If there's nothing really to move, then skip (or if negative as those moves are added by the // other patch) @@ -93,7 +92,7 @@ private void HandlePatchCompoundDiffusion() foreach (var adjacent in patch.Value.Adjacent) { - var (ambient, density) = CalculateWantedMoveAmounts(patch.Value, adjacent, compound); + var (ambient, density) = CalculateWantedMoveAmounts(adjacent, compound); if (ambient < MathUtils.EPSILON && density < MathUtils.EPSILON) continue; From eee74492676659861922b1908171fc67771e8c18 Mon Sep 17 00:00:00 2001 From: adQuid <28126232+adQuid@users.noreply.github.com> Date: Sat, 23 Nov 2024 18:24:44 -0500 Subject: [PATCH 08/11] minor review corrections --- src/general/world_effects/CompoundDiffusionEffect.cs | 2 -- src/general/world_effects/PhotosynthesisProductionEffect.cs | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/general/world_effects/CompoundDiffusionEffect.cs b/src/general/world_effects/CompoundDiffusionEffect.cs index 487ed94109..b1e1b42d05 100644 --- a/src/general/world_effects/CompoundDiffusionEffect.cs +++ b/src/general/world_effects/CompoundDiffusionEffect.cs @@ -29,8 +29,6 @@ public void OnTimePassed(double elapsed, double totalTimePassed) private static (float Ambient, float Density) CalculateWantedMoveAmounts(Patch adjacent, KeyValuePair compound) { - // Apply patch distance to diminish how much to move (to make ocean bottoms receive less surface - // resources like oxygen) float moveModifier = Constants.COMPOUND_DIFFUSE_BASE_MOVE_AMOUNT; adjacent.Biome.TryGetCompound(compound.Key, CompoundAmountType.Biome, diff --git a/src/general/world_effects/PhotosynthesisProductionEffect.cs b/src/general/world_effects/PhotosynthesisProductionEffect.cs index dbc76c59a3..480929a50d 100644 --- a/src/general/world_effects/PhotosynthesisProductionEffect.cs +++ b/src/general/world_effects/PhotosynthesisProductionEffect.cs @@ -153,8 +153,8 @@ private void ApplyCompoundsAddition() co2Target = co2Out / (oxygenIn + co2In) * total; } - changesToApply[Compound.Oxygen] = (oxygenTarget - existingOxygen.Ambient) / 2.0f; - changesToApply[Compound.Carbondioxide] = (co2Target - existingCo2.Ambient) / 2.0f; + changesToApply[Compound.Oxygen] = (oxygenTarget - existingOxygen.Ambient) * 0.5f; + changesToApply[Compound.Carbondioxide] = (co2Target - existingCo2.Ambient) * 0.5f; if (changesToApply.Count > 0) patch.Biome.ApplyLongTermCompoundChanges(patch.BiomeTemplate, changesToApply, cloudSizes); From 47c6b9aab834c4b9bf1c7542564a7b791d5aeeb3 Mon Sep 17 00:00:00 2001 From: adQuid <28126232+adQuid@users.noreply.github.com> Date: Sat, 23 Nov 2024 19:13:33 -0500 Subject: [PATCH 09/11] rework equilibrium equations --- .../PhotosynthesisProductionEffect.cs | 51 +++++++++++-------- 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/src/general/world_effects/PhotosynthesisProductionEffect.cs b/src/general/world_effects/PhotosynthesisProductionEffect.cs index 480929a50d..1b45254a19 100644 --- a/src/general/world_effects/PhotosynthesisProductionEffect.cs +++ b/src/general/world_effects/PhotosynthesisProductionEffect.cs @@ -46,10 +46,10 @@ private void ApplyCompoundsAddition() if (patch.SpeciesInPatch.Count < 1) continue; - float oxygenIn = 0; - float oxygenOut = 0; - float co2In = 0; - float co2Out = 0; + float oxygenConsumed = 0; + float oxygenProduced = 0; + float co2Consumed = 0; + float co2Produced = 0; foreach (var species in patch.SpeciesInPatch) { @@ -72,6 +72,7 @@ private void ApplyCompoundsAddition() microbeProcesses.Clear(); ProcessSystem.ComputeActiveProcessList(microbeSpecies.Organelles, ref microbeProcesses); + // Iterate over each process and determine compounds produced and consumed foreach (var process in microbeProcesses) { if (process.Process.InternalName == "protein_respiration") @@ -100,11 +101,11 @@ private void ApplyCompoundsAddition() { if (input.Key.ID is Compound.Oxygen) { - oxygenIn += input.Value * inputModifier * effectiveSpeed * species.Value; + oxygenConsumed += input.Value * inputModifier * effectiveSpeed * species.Value; } else if (input.Key.ID is Compound.Carbondioxide) { - co2In += input.Value * inputModifier * effectiveSpeed * species.Value; + co2Consumed += input.Value * inputModifier * effectiveSpeed * species.Value; } } @@ -113,11 +114,11 @@ private void ApplyCompoundsAddition() { if (output.Key.ID is Compound.Oxygen) { - oxygenOut += output.Value * outputModifier * effectiveSpeed * species.Value; + oxygenProduced += output.Value * outputModifier * effectiveSpeed * species.Value; } else if (output.Key.ID is Compound.Carbondioxide) { - co2Out += output.Value * outputModifier * effectiveSpeed * species.Value; + co2Produced += output.Value * outputModifier * effectiveSpeed * species.Value; } } } @@ -131,26 +132,34 @@ private void ApplyCompoundsAddition() float total = existingOxygen.Ambient + existingCo2.Ambient; - if (oxygenOut == 0) + // Special (but common) case where zero oxygen is being produced + if (oxygenProduced == 0 && oxygenConsumed > 0) { - if (co2Out == 0) + oxygenTarget = 0.0f; + + if (co2Produced > 0) { - // in the rare event we aren't making either compound, do nothing - continue; + co2Target = total; } - - oxygenTarget = 0; - co2Target = total; } - else if (co2Out == 0) + + // Special (but common) case where zero carbon dioxide is being produced + if (co2Produced == 0 && co2Consumed > 0) { - oxygenTarget = total; - co2Target = 0; + co2Target = 0.0f; + + if (oxygenProduced > 0) + { + oxygenTarget = total; + } } - else + + // if both compounds are being produced, calculate an aproximate steady state value + if (oxygenProduced > 0 && co2Produced > 0) { - oxygenTarget = oxygenOut / (oxygenIn + co2In) * total; - co2Target = co2Out / (oxygenIn + co2In) * total; + // Calculate long-term equilibrium balances based on production and consumption ratio + oxygenTarget = oxygenProduced / (oxygenConsumed + co2Consumed) * total; + co2Target = co2Produced / (oxygenConsumed + co2Consumed) * total; } changesToApply[Compound.Oxygen] = (oxygenTarget - existingOxygen.Ambient) * 0.5f; From f505fdbc6f9a55d20c08e816e24f6771d497a024 Mon Sep 17 00:00:00 2001 From: adQuid <28126232+adQuid@users.noreply.github.com> Date: Sat, 23 Nov 2024 19:18:23 -0500 Subject: [PATCH 10/11] whoops --- .../world_effects/PhotosynthesisProductionEffect.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/general/world_effects/PhotosynthesisProductionEffect.cs b/src/general/world_effects/PhotosynthesisProductionEffect.cs index 1b45254a19..0a0cf9427f 100644 --- a/src/general/world_effects/PhotosynthesisProductionEffect.cs +++ b/src/general/world_effects/PhotosynthesisProductionEffect.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using Godot; using Newtonsoft.Json; using Systems; @@ -124,12 +125,13 @@ private void ApplyCompoundsAddition() } } - float oxygenTarget; - float co2Target; - patch.Biome.TryGetCompound(Compound.Oxygen, CompoundAmountType.Biome, out var existingOxygen); patch.Biome.TryGetCompound(Compound.Carbondioxide, CompoundAmountType.Biome, out var existingCo2); + // Unless something else changes it, compound values stay the same + float oxygenTarget = existingOxygen.Ambient; + float co2Target = existingCo2.Ambient; + float total = existingOxygen.Ambient + existingCo2.Ambient; // Special (but common) case where zero oxygen is being produced @@ -158,8 +160,8 @@ private void ApplyCompoundsAddition() if (oxygenProduced > 0 && co2Produced > 0) { // Calculate long-term equilibrium balances based on production and consumption ratio - oxygenTarget = oxygenProduced / (oxygenConsumed + co2Consumed) * total; - co2Target = co2Produced / (oxygenConsumed + co2Consumed) * total; + oxygenTarget = oxygenProduced / (oxygenConsumed + co2Consumed + MathUtils.EPSILON) * total; + co2Target = co2Produced / (oxygenConsumed + co2Consumed + MathUtils.EPSILON) * total; } changesToApply[Compound.Oxygen] = (oxygenTarget - existingOxygen.Ambient) * 0.5f; From 497880f2a2db3c343153128b5ad8ba8f2c2c5619 Mon Sep 17 00:00:00 2001 From: adQuid <28126232+adQuid@users.noreply.github.com> Date: Sat, 23 Nov 2024 19:49:42 -0500 Subject: [PATCH 11/11] drop unneeded import --- src/general/world_effects/PhotosynthesisProductionEffect.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/general/world_effects/PhotosynthesisProductionEffect.cs b/src/general/world_effects/PhotosynthesisProductionEffect.cs index 0a0cf9427f..91a517ba88 100644 --- a/src/general/world_effects/PhotosynthesisProductionEffect.cs +++ b/src/general/world_effects/PhotosynthesisProductionEffect.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using Godot; using Newtonsoft.Json; using Systems;