Skip to content

Commit

Permalink
Biome dissolved compound numbers are now applied whenever the biome i…
Browse files Browse the repository at this point in the history
…s set.
  • Loading branch information
Untrustedlife authored and hhyyrylainen committed Jan 12, 2019
1 parent 144fb69 commit 79d4b49
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 3 deletions.
14 changes: 14 additions & 0 deletions scripts/gui/microbe_hud.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ export function runMicrobeHUDSetup(){
checkExtinction(vars.population);
});

// Event for updating o2 and c02 numbers
Leviathan.OnGeneric("UpdateDissolvedGasses", (event, vars) => {
updateDissolvedGasses(vars.oxygenPercent, vars.co2Percent);
});

// Event for checking win conditions
Leviathan.OnGeneric("CheckWin", (event, vars) => {
checkGeneration(vars.generation, vars.population);
Expand Down Expand Up @@ -392,6 +397,15 @@ function updatePopulation(population){
population;
}

// Update dissolved gasses
function updateDissolvedGasses(oxygen, c02){
document.getElementById("oxygenPercent").textContent =
"O2: " + oxygen + "%";
document.getElementById("carbonDioxidePercent").textContent =
"CO2: " + c02 + "%";
}


//! Checks if the player is extinct
function checkExtinction(population){
if(population <= 0){
Expand Down
2 changes: 1 addition & 1 deletion scripts/gui/thrive_gui.html
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
<div class="oxygen">
<span id="oxygenTab"></span>
<div id="OxygenIcon"></div>
<span id="oxygenPercent">O2: 20%</span>
<span id="oxygenPercent">O2: 21%</span>
</div>
<!-- c02 percentage -->
<div class="carbondioxide">
Expand Down
11 changes: 11 additions & 0 deletions scripts/microbe_stage/biome.as
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,17 @@ void setBiome(uint64 biomeId, CellStageWorld@ world){
GetThriveGame().setBackgroundMaterial(biome.background);
//Update biome for process system
world.GetProcessSystem().setProcessBiome(biomeId);

// Update oxygen and carbon dioxide numbers
auto oxyId = SimulationParameters::compoundRegistry().getTypeId("oxygen");
auto c02Id = SimulationParameters::compoundRegistry().getTypeId("carbondioxide");
GenericEvent@ updateDissolvedGasses = GenericEvent("UpdateDissolvedGasses");
NamedVars@ vars = updateDissolvedGasses.GetNamedVars();
vars.AddValue(ScriptSafeVariableBlock("oxygenPercent",
world.GetProcessSystem().getDissolved(oxyId)*100));
vars.AddValue(ScriptSafeVariableBlock("co2Percent",
world.GetProcessSystem().getDissolved(c02Id)*100));
GetEngine().GetEventHandler().CallEvent(updateDissolvedGasses);
}

void setSunlightForBiome(CellStageWorld@ world){
Expand Down
4 changes: 3 additions & 1 deletion scripts/microbe_stage/microbe_operations.as
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,10 @@ void respawnPlayer(CellStageWorld@ world)
sceneNodeComponent.Marked = true;

setRandomBiome(world);

cast<MicrobeStageHudSystem>(world.GetScriptSystem("MicrobeStageHudSystem")).
suicideButtonreset();
suicideButtonreset();

// Reset membrane color to fix the bug that made membranes sometimes red after you respawn.
MicrobeOperations::applyMembraneColour(world, playerEntity);
}
Expand Down
2 changes: 1 addition & 1 deletion src/scripting/script_initializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1150,7 +1150,7 @@ bool
}

if(engine->RegisterObjectMethod("ProcessSystem",
"void getDissolved(CompoundId compoundData)",
"double getDissolved(CompoundId compoundData)",
asMETHOD(ProcessSystem, getDissolved), asCALL_THISCALL) < 0) {
ANGELSCRIPT_REGISTERFAIL;
}
Expand Down

0 comments on commit 79d4b49

Please sign in to comment.