Skip to content

Commit

Permalink
Venter system can now delete entities when it runs out of compounds i…
Browse files Browse the repository at this point in the history
…n its compound bag if you set the doDissolve flag in the CompoundVenterComponent to true

added test chunks to see how gameplay feels

game now divides up compounds between chunks evenly, which isnt ideal as they run out fast, maybe each cell should only break into a very small amount of chunks?

Added some constants for fine tuning the chunk stuff
  • Loading branch information
Untrustedlife authored and hhyyrylainen committed Mar 15, 2019
1 parent 08a5397 commit f5b3288
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 15 deletions.
3 changes: 3 additions & 0 deletions scripts/microbe_stage/configs.as
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ const auto POWERUP_SPAWN_RADIUS = 85;
const auto DEFAULT_SPAWN_DENSITY = 1/25000.f;
const auto STARTING_SPAWN_DENSITY = 45000.0f;
const auto MAX_SPAWN_DENSITY = 20000.0f;
//Corpse info
const auto CORPSE_COMPOUND_COMPENSATION = 2.0f;
const auto CORPSE_CHUNK_DIVISER = 5;

// Cell Spawn Variation
const auto MIN_SPAWN_DISTANCE = -5000.0f;
Expand Down
49 changes: 34 additions & 15 deletions scripts/microbe_stage/microbe_operations.as
Original file line number Diff line number Diff line change
Expand Up @@ -1174,24 +1174,43 @@ void kill(CellStageWorld@ world, ObjectID microbeEntity)
}
}

// They were added in order already so looping through this other thing is fine
for(uint64 compoundID = 0; compoundID <


for(uint i = 0; i < max(1,microbeComponent.organelles.length()/CORPSE_CHUNK_DIVISER); ++i){
double amount = max(1,microbeComponent.organelles.length()/CORPSE_CHUNK_DIVISER);
// Chunk(should separate into own function)
ObjectID chunkEntity = world.CreateEntity();
auto chunkPosition = world.Create_Position(chunkEntity, position._Position,
Ogre::Quaternion(Ogre::Degree(GetEngine().GetRandom().GetNumber(0, 360)),
Ogre::Vector3(0,1,1)));

auto renderNode = world.Create_RenderNode(chunkEntity);
renderNode.Scale = Float3(2, 2, 2);
renderNode.Marked = true;
renderNode.Node.setOrientation(Ogre::Quaternion(
Ogre::Degree(GetEngine().GetRandom().GetNumber(0, 360)), Ogre::Vector3(0,1,1)));
renderNode.Node.setPosition(chunkPosition._Position);
// temp model for testing
auto model = world.Create_Model(chunkEntity, renderNode.Node, "mitochondrion.mesh");
// Color chunk based on cell
model.GraphicalObject.setCustomParameter(1, microbeComponent.speciesColour);
auto rigidBody = world.Create_Physics(chunkEntity, chunkPosition);
auto body = rigidBody.CreatePhysicsBody(world.GetPhysicalWorld(),
world.GetPhysicalWorld().CreateSphere(1), 10);
body.ConstraintMovementAxises();
rigidBody.JumpTo(chunkPosition);
auto venter = world.Create_CompoundVenterComponent(chunkEntity);
// So that larger iron chunks give out more compounds
venter.setVentAmount(3);
venter.setDoDissolve(true);
auto bag = world.Create_CompoundBagComponent(chunkEntity);
// They were added in order already so looping through this other thing is fine
for(uint64 compoundID = 0; compoundID <
SimulationParameters::compoundRegistry().getSize(); ++compoundID)
{
//LOG_INFO(""+float(compoundsToRelease[formatInt(compoundID)]));
//LOG_INFO(""+float(compoundsToRelease[formatUInt(compoundID)]));
if (SimulationParameters::compoundRegistry().getTypeData(compoundID).isCloud &&
float(compoundsToRelease[formatUInt(compoundID)]) > 0.0f)
{
//Earlier we added all of the keys to the list by ID,in order, so this is fine
//LOG_INFO("Releasing "+float(compoundsToRelease[formatUInt(compoundID)]));
if (SimulationParameters::compoundRegistry().getTypeData(compoundID).isCloud)
{
ejectCompound(world, microbeEntity, uint64(compoundID),float(compoundsToRelease[formatUInt(compoundID)]));
}
bag.setCompound(compoundID, (float(compoundsToRelease[formatUInt(compoundID)])/amount)*CORPSE_COMPOUND_COMPENSATION);
}
}

}
// Play the death sound
playSoundWithDistance(world, "Data/Sound/soundeffects/microbe-death.ogg", microbeEntity);

Expand Down
20 changes: 20 additions & 0 deletions src/microbe_stage/compound_venter_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ void
CompoundBagComponent& bag = std::get<0>(*value.second);
CompoundVenterComponent& venter = std::get<1>(*value.second);
// Loop through all the compounds in the storage bag and eject them
bool vented = false;
for(const auto& compound : bag.compounds) {
double compoundAmount = compound.second.amount;
CompoundId compoundId = compound.first;
Expand All @@ -45,8 +46,15 @@ void
venter.ventCompound(
position, compoundId, venter.ventAmount, world);
bag.takeCompound(compoundId, venter.ventAmount);
vented = true;
}
}

// If you did not vent anything this step and the venter component
// is flagged to dissolve tyou, dissolve you
if(vented == false && venter.getDoDissolve()) {
world.QueueDestroyEntity(value.first);
}
}
}
}
Expand All @@ -71,4 +79,16 @@ float
CompoundVenterComponent::getVentAmount()
{
return this->ventAmount;
}

void
CompoundVenterComponent::setDoDissolve(bool dissolve)
{
this->doDissolve = dissolve;
}

bool
CompoundVenterComponent::getDoDissolve()
{
return this->doDissolve;
}
8 changes: 8 additions & 0 deletions src/microbe_stage/compound_venter_system.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class CompoundVenterComponent : public Leviathan::Component {

float x, y;
float ventAmount = 5.0f;
bool doDissolve = false;

REFERENCE_HANDLE_UNCOUNTED_TYPE(CompoundVenterComponent);

static constexpr auto TYPE =
Expand All @@ -38,6 +40,12 @@ class CompoundVenterComponent : public Leviathan::Component {

float
getVentAmount();

void
setDoDissolve(bool dissolve);

bool
getDoDissolve();
};

class CompoundVenterSystem
Expand Down
14 changes: 14 additions & 0 deletions src/scripting/script_initializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,20 @@ bool
asCALL_THISCALL) < 0) {
ANGELSCRIPT_REGISTERFAIL;
}

if(engine->RegisterObjectMethod("CompoundVenterComponent",
"bool getDoDissolve()",
asMETHOD(CompoundVenterComponent, getDoDissolve),
asCALL_THISCALL) < 0) {
ANGELSCRIPT_REGISTERFAIL;
}

if(engine->RegisterObjectMethod("CompoundVenterComponent",
"void setDoDissolve(bool dissolve)",
asMETHOD(CompoundVenterComponent, setDoDissolve),
asCALL_THISCALL) < 0) {
ANGELSCRIPT_REGISTERFAIL;
}
// ------------------------------------ //
if(engine->RegisterObjectType(
"SpawnedComponent", 0, asOBJ_REF | asOBJ_NOCOUNT) < 0) {
Expand Down

0 comments on commit f5b3288

Please sign in to comment.