Skip to content

Commit

Permalink
773 iron by biome (Revolutionary-Games#776)
Browse files Browse the repository at this point in the history
* Biomes now hold a list of "chunks" in their json, it doenst do anything right now.

* Compound grab radius is now halved for bacteria. 9 I needed something for the dev build)

* Changed aborber system halving to a more robust and usable "scale" based system

* On nitrogenase protein the tooltip now shows the  nitrogen icon instead of the word nitrogen, retooled css so we can add many of these new icons inside tooltips without problems for @nickthenick, recoolored phosphate

* Added chunk object to c++ and the json now also loads it up.

* Chunk now uses std::move to prevent memory leaks.

* ran code formatting script

* Removed std::move from copy constructor, it should only be used in the move constructor.

* meshes are now retrieved and stored, also added methods for getting chunks by ID, now basically i just need a bunch of methods and then to get rid of the current chunks and get the spawners set up and cleared in biomes.as

* All data except meshes can now be accessed for the new chunks

* ran formatting script

* Made tweaks to UI that were requested in: Revolutionary-Games#774

* Implemented mesh accessors to the chunks

* Implemented new system for having chunks per biome fully, eveyrthing is working now it spawns the chunks in each biome properly with the defined stats etc. Also upped mass of all iron chunks in biomes.json file

The only part that isnt fully implemented is the compounds in the chunks.

* chunk compounds can now vary by chunk, and now its all done.

* fixed some bugs, added ice chunks

* got rid of extra qualifiers that were causing ci to fail woops

* fixed a bunch of hhyyrylainen's issues

* Mesh accessors now use size_t

* Added chunkScale parameter, made iron have what it used to have, added giant ice crystals

* changed giant ice crystals

* Changed absorber scale to be based on multiplication
  • Loading branch information
Untrustedlife authored and hhyyrylainen committed Apr 20, 2019
1 parent 5ed6969 commit fcc4784
Show file tree
Hide file tree
Showing 15 changed files with 883 additions and 108 deletions.
401 changes: 390 additions & 11 deletions scripts/SimulationParameters/MicrobeStage/Biomes.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions scripts/SimulationParameters/MicrobeStage/Compounds.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@
},

"phosphates": {
"name": "Phosphates",
"name": "Phosphate",
"volume": 1,
"isCloud": true,
"isUseful": true,
"isEnvironmental": false,
"colour": {
"r": 0.7,
"g": 0.0,
"b": 0.7
"r": 0.8,
"g": 0.4,
"b": 1.0
}
},

Expand Down
1 change: 1 addition & 0 deletions scripts/gui/main_menu.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export function runMenuSetup(){
common.playButtonPressSound();
newGame();
}, true);

// The prototype doesn't really work so disabled for now
// document.getElementById("extrasButton").addEventListener("click", (event) => {
// event.stopPropagation();
Expand Down
12 changes: 6 additions & 6 deletions scripts/gui/microbe_hud.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -418,12 +418,12 @@ function updatePopulation(population){

// Update dissolved gasses
function updateDissolvedGasses(oxygen, c02, n2){
document.getElementById("oxygenPercent").textContent =
"O2: " + oxygen + "%";
document.getElementById("carbonDioxidePercent").textContent =
"CO2: " + c02 + "%";
document.getElementById("nitrogenPercent").textContent =
"N2: " + n2 + "%";
document.getElementById("oxygenPercent").innerHTML =
"O<sub>2</sub>" + ": " + oxygen + "%";
document.getElementById("carbonDioxidePercent").innerHTML =
"CO<sub>2</sub>" + ": " + c02 + "%";
document.getElementById("nitrogenPercent").innerHTML =
"N<sub>2</sub>" + ": " + n2 + "%";
}


Expand Down
14 changes: 7 additions & 7 deletions scripts/gui/thrive_gui.html
Original file line number Diff line number Diff line change
Expand Up @@ -121,19 +121,19 @@
<div class="oxygen">
<span id="oxygenTab"></span>
<div id="OxygenIcon"></div>
<span id="oxygenPercent">O2: 21%</span>
<span id="oxygenPercent">O<sub>2</sub>: 21%</span>
</div>
<!-- c02 percentage -->
<div class="carbondioxide">
<span id="carbonDioxideTab"></span>
<div id="CO2Icon"></div>
<span id="carbonDioxidePercent">CO2: 9%</span>
<span id="carbonDioxidePercent">CO<sub>2</sub>: 9%</span>
</div>
<!-- N2 percentage -->
<div class="nitrogen">
<span id="nitrogenTab"></span>
<div id="NitrogenIcon"></div>
<span id="nitrogenPercent">N2: 70%</span>
<span id="nitrogenPercent">N<sub>2</sub>: 70%</span>
</div>


Expand Down Expand Up @@ -234,7 +234,7 @@
<div class="BarBackground" id="microbeHUDPlayerPhosphatesBar">
<div class="BarForeground">
<div class="compoundIcon" id="PhosphatesIcon"></div>
<div class="BarTitle">Phosphates</div>
<div class="BarTitle">Phosphate</div>
<div class="BarValue">
<span id="microbeHUDPlayerPhosphates">0</span> /
<span id="microbeHUDPlayerPhosphatesMax">0</span>
Expand Down Expand Up @@ -262,7 +262,7 @@
<div class="BarBackground" id="microbeHUDPlayerIronBar">
<div class="BarForeground">
<div class="compoundIcon" id="IronIcon"></div>
<div class="BarTitle">Iron Ions</div>
<div class="BarTitle">Iron</div>
<div class="BarValue">
<span id="microbeHUDPlayerIron">0</span> /
<span id="microbeHUDPlayerIronMax">0</span>
Expand Down Expand Up @@ -300,7 +300,7 @@
ATP. Be careful not to let your ATP stores run out, or you
will slow down, lose health and eventually die.
<br><br> The various compound clouds are:<br><br> White –
Glucose <br> Yellow – Hydrogen Sulfide <br> Orange - Ammonia <br> Purple - Phosphates <br> Rust Brown - Iron Ions <br><br>
Glucose <br> Yellow – Hydrogen Sulfide <br> Orange - Ammonia <br> Purple - Phosphate <br> Rust Brown - Iron <br><br>

Glucose makes ATP<br>
Hydrogen Sulfide can be converted into glucose via chemoplasts and chemosynthesizing proteins<br>
Expand Down Expand Up @@ -422,7 +422,7 @@
<td id="addNitrogenase" class="OrganelleListItem">
<span class="tooltiptext">
Nitrogenase<hr><br> Cost: 55 mutation points<hr><br>
Performs Process: Anaerobic Nitrogen Fixation<br>(2 Nitrogen + 10 ATP -> 0.02 Ammonia)/Second (Depending On Environmental Nitrogen)<br>
Performs Process: Anaerobic Nitrogen Fixation<br>(2 <div class="compoundIcon" id="NitrogenNormalIcon"></div> + 10 ATP -> 0.02 Ammonia)/Second (Depending On Environmental Nitrogen)<br>
Performs Process: Glycolysis<br>(0.125 glucose -> 5 ATP)/Second<hr><br>
Storage Space: 2<hr><br>
Allows for synthesis of ammonia from atmospheric nitrogen anaerobically. For easier cell growth.
Expand Down
33 changes: 33 additions & 0 deletions scripts/gui/thrive_style.css
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,12 @@ video {
background-image: url("../../Textures/gui/bevel/Oxygen.png");
}

#OxygenNormalIcon {
background-image: url("../../Textures/gui/bevel/Oxygen.png");
background-repeat: no-repeat;
}


#OxygenBar {
background-color: #2dcbf0;
}
Expand All @@ -432,12 +438,18 @@ video {
background-image: url("../../Textures/gui/bevel/Nitrogen.png");
}

#NitrogenNormalIcon {
background-image: url("../../Textures/gui/bevel/Nitrogen.png");
background-repeat: no-repeat;
}

#AminoAcidsBar {
background-color: #f94b97;
}

#AmmoniaIcon {
background-image: url("../../Textures/gui/bevel/Ammonia.png");
background-repeat: no-repeat;
}

#microbeHUDPlayerAmmoniaBar {
Expand All @@ -446,6 +458,14 @@ video {

#GlucoseIcon {
background-image: url("../../Textures/gui/bevel/Glucose.png");
background-repeat: no-repeat;
}

.tooltiptext .compoundIcon {
position: relative;
display: inline-block;
top: 5px;
left: 1px;
}

#microbeHUDPlayerGlucoseBar {
Expand All @@ -462,12 +482,18 @@ video {
background-image: url("../../Textures/gui/bevel/CO2.png");
}

#CO2NormalIcon {
background-image: url("../../Textures/gui/bevel/CO2.png");
background-repeat: no-repeat;
}

#CO2Bar {
background-color: #153665;
}

#FattyAcidsIcon {
background-image: url("../../Textures/gui/bevel/FattyAcids.png");
background-repeat: no-repeat;
}

#FattyAcidsBar {
Expand All @@ -476,6 +502,7 @@ video {

#OxyToxyIcon {
background-image: url("../../Textures/gui/bevel/OxyToxy.png");
background-repeat: no-repeat;
}

#microbeHUDPlayerOxytoxyBar {
Expand All @@ -484,6 +511,7 @@ video {

#IronIcon {
background-image: url("../../Textures/gui/bevel/Iron.png");
background-repeat: no-repeat;
}

#microbeHUDPlayerIronBar {
Expand All @@ -492,6 +520,7 @@ video {

#HealthIcon {
background-image: url("../../Textures/gui/bevel/Hitpoints.png");
background-repeat: no-repeat;
}

#microbeHUDPlayerHitpointsBar {
Expand All @@ -501,6 +530,7 @@ video {

#MutationPointsIcon {
background-image: url("../../Textures/gui/bevel/MP.png");
background-repeat: no-repeat;
}

#microbeHUDPlayerMutationPointsBar {
Expand Down Expand Up @@ -528,6 +558,7 @@ video {

#PhosphatesIcon {
background-image: url("../../Textures/gui/bevel/Phosphates.png");
background-repeat: no-repeat;
}

#microbeHUDPlayerPhosphatesBar {
Expand All @@ -536,6 +567,7 @@ video {

#HydrogenSulfideIcon {
background-image: url("../../Textures/gui/bevel/HydrogenSulfide.png");
background-repeat: no-repeat;
}

#microbeHUDPlayerHydrogenSulfideBar {
Expand Down Expand Up @@ -1176,6 +1208,7 @@ video {
}



.OrganelleListItem:hover .tooltiptext {
visibility: visible;
}
Expand Down
124 changes: 124 additions & 0 deletions scripts/microbe_stage/biome.as
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,99 @@ class CloudFactory{
private CompoundId compound;
}

class Chunkfactory{

Chunkfactory(uint c){

chunkId = c;
}

ObjectID spawn(CellStageWorld@ world, Float3 pos){
return createChunk(world, chunkId, pos);
}

private uint chunkId;
}


ObjectID createChunk(CellStageWorld@ world, uint chunkId, Float3 pos)
{
auto biome = getCurrentBiome();
// chunk
ObjectID chunkEntity = world.CreateEntity();
const ChunkData@ chunk = biome.getChunk(chunkId);

//Position and render node
auto position = world.Create_Position(chunkEntity, pos,
Ogre::Quaternion(Ogre::Degree(GetEngine().GetRandom().GetNumber(0, 360)),
Ogre::Vector3(0,1,1)));


auto renderNode = world.Create_RenderNode(chunkEntity);
// Grab scale from json
double chunkScale = chunk.chunkScale;
renderNode.Scale = Float3(chunkScale, chunkScale, chunkScale);
renderNode.Marked = true;
renderNode.Node.setOrientation(Ogre::Quaternion(
Ogre::Degree(GetEngine().GetRandom().GetNumber(0, 360)),
Ogre::Vector3(0,1,1)));

renderNode.Node.setPosition(pos);

//Grab data
double ventAmount= chunk.ventAmount;
bool dissolves=chunk.dissolves;
int radius = chunk.radius;
int mass = chunk.mass;
int chunkSize = chunk.size;
auto meshListSize = chunk.getMeshListSize();
string mesh=chunk.getMesh(GetEngine().GetRandom().GetNumber(0,
meshListSize-1))+".mesh";

//Set things
auto venter = world.Create_CompoundVenterComponent(chunkEntity);
venter.setVentAmount(ventAmount);
venter.setDoDissolve(dissolves);
auto bag = world.Create_CompoundBagComponent(chunkEntity);
auto engulfable = world.Create_EngulfableComponent(chunkEntity);
engulfable.setSize(chunkSize);


auto chunkCompounds = chunk.getCompoundKeys();
//LOG_INFO("chunkCompounds.length = " + chunkCompounds.length());

for(uint i = 0; i < chunkCompounds.length(); ++i){
auto compoundId = SimulationParameters::compoundRegistry().getTypeData(chunkCompounds[i]).id;
//LOG_INFO("got here:");
if(SimulationParameters::compoundRegistry().getTypeData(compoundId).isCloud){
// And register new
const double amount = chunk.getCompound(chunkCompounds[i]).amount;
//LOG_INFO("amount:"+amount);
bag.setCompound(compoundId,amount);
}
}

auto model = world.Create_Model(chunkEntity, renderNode.Node, mesh);

// Need to set the tint
model.GraphicalObject.setCustomParameter(1, Ogre::Vector4(1, 1, 1, 1));

// Rigid Body
auto rigidBody = world.Create_Physics(chunkEntity, position);
auto body = rigidBody.CreatePhysicsBody(world.GetPhysicalWorld(),
world.GetPhysicalWorld().CreateSphere(radius),mass,
//engulfable
world.GetPhysicalMaterial("iron"));

body.ConstraintMovementAxises();

rigidBody.JumpTo(position);

return chunkEntity;
}

dictionary compoundSpawnTypes;
dictionary chunkSpawnTypes;

// Setting the current biome to the one with the specified name.
void setBiome(uint64 biomeId, CellStageWorld@ world){
Expand All @@ -58,6 +150,38 @@ void setBiome(uint64 biomeId, CellStageWorld@ world){
currentBiome = biomeId;
auto biome = getCurrentBiome();

auto chunks = biome.getChunkKeys();
LOG_INFO("chunks.length = " + chunks.length());

// clearing chunks (all of them)
for (uint c = 0; c < chunkSpawnTypes.getSize(); ++c){
const string typeStr = formatUInt(c);
if(chunkSpawnTypes.exists(typeStr)){
world.GetSpawnSystem().removeSpawnType(SpawnerTypeId(
chunkSpawnTypes[typeStr]));
LOG_INFO("deleting chunk spawn");
}
}

for(uint i = 0; i < chunks.length(); ++i){
auto chunkId = chunks[i];
Chunkfactory@ spawnChunk = Chunkfactory(chunkId);
const string typeStr = formatUInt(chunkId);
// And register new
const auto density = biome.getChunk(chunkId).density;
const auto name = biome.getChunk(chunkId).name;

if(density <= 0){
LOG_WARNING("chunk spawn density is 0. It won't spawn");
}

LOG_INFO("registering chunk: " + chunkId + " Name: "+name +" density: " + density);
SpawnFactoryFunc@ factory = SpawnFactoryFunc(spawnChunk.spawn);
chunkSpawnTypes[typeStr] = world.GetSpawnSystem().addSpawnType(factory, density,
MICROBE_SPAWN_RADIUS);

}

auto biomeCompounds = biome.getCompoundKeys();
LOG_INFO("biomeCompounds.length = " + biomeCompounds.length());
for(uint i = 0; i < biomeCompounds.length(); ++i){
Expand Down
4 changes: 4 additions & 0 deletions scripts/microbe_stage/microbe_editor/microbe_editor.as
Original file line number Diff line number Diff line change
Expand Up @@ -966,16 +966,20 @@ class MicrobeEditor{

// Grab render node of player cell
auto node = world.GetComponent_RenderNode(player);
auto absorber = world.GetComponent_CompoundAbsorberComponent(
player);

// Change player species cell size depending on whether they are a bacteria or not
if(checkIsNucleusPresent()) {
playerSpecies.isBacteria = false;
node.Scale = Float3(1.0, 1.0, 1.0);
node.Marked = true;
absorber.setGrabScale(1.0f);
} else {
playerSpecies.isBacteria = true;
node.Scale = Float3(0.5, 0.5, 0.5);
node.Marked = true;
absorber.setGrabScale(0.5f);
}

LOG_INFO("MicrobeEditor: updated organelles for species: " + playerSpecies.name);
Expand Down
4 changes: 4 additions & 0 deletions scripts/microbe_stage/microbe_operations.as
Original file line number Diff line number Diff line change
Expand Up @@ -1013,6 +1013,10 @@ ObjectID _createMicrobeEntity(CellStageWorld@ world, bool aiControlled,

auto compoundAbsorberComponent = world.Create_CompoundAbsorberComponent(entity);

if (species.isBacteria) {
compoundAbsorberComponent.setGrabScale(0.5f);
}

world.Create_RenderNode(entity);
auto compoundBag = world.Create_CompoundBagComponent(entity);

Expand Down
Loading

0 comments on commit fcc4784

Please sign in to comment.