From 8647f8487dd90f42f435f28fbd39bbd273f504cd Mon Sep 17 00:00:00 2001 From: Untrustedlife Date: Wed, 20 Feb 2019 14:51:03 -0600 Subject: [PATCH] Added EngulfableComponent and its variables and exposed them to angelscript Small iron now dissolves when its done, added engulfable component to iron chunks and cell chunks. Cells now immediately stop absorbing when they die. (as it wasn't disabling immediately for some reason until the cell un-loaded, so there may be a bug in that code) apparently i didnt actually add an engulfable to iron earlier, now i have. --- scripts/microbe_stage/configs.as | 5 +++- scripts/microbe_stage/microbe_operations.as | 15 ++++++++---- scripts/microbe_stage/setup.as | 8 ++++++- src/engine/component_types.h | 2 +- src/microbe_stage/compound_venter_system.cpp | 16 +++++++++++++ src/microbe_stage/compound_venter_system.h | 18 ++++++++++++++ .../generate_cell_stage_world.rb | 1 + src/scripting/script_initializer.cpp | 24 +++++++++++++++++++ 8 files changed, 82 insertions(+), 7 deletions(-) diff --git a/scripts/microbe_stage/configs.as b/scripts/microbe_stage/configs.as index d897232ad28..5338b463be4 100644 --- a/scripts/microbe_stage/configs.as +++ b/scripts/microbe_stage/configs.as @@ -10,7 +10,7 @@ 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; +const auto CORPSE_CHUNK_DIVISER = 5.0f; // Cell Spawn Variation const auto MIN_SPAWN_DISTANCE = -5000.0f; @@ -166,8 +166,11 @@ const uint AGENT_EMISSION_COOLDOWN = 2000; // Iron amounts per chunk. // big iron ejects ten per 20 clicks , so about 30 per second, so ill give it enough for 1000 seconds) const double IRON_PER_BIG_CHUNK = 30000.0f; +const bool LARGE_IRON_DISSOLVES = false; // small iron ejects 3 per 20 clicks , so about 9 per second, so ill give it enough for 1000 seconds aswell const double IRON_PER_SMALL_CHUNK = 9000.0f; +const bool SMALL_IRON_DISSOLVES = true; + //Auto Evo Values const int CREATURE_DEATH_POPULATION_LOSS = -60; const int CREATURE_KILL_POPULATION_GAIN = 50; diff --git a/scripts/microbe_stage/microbe_operations.as b/scripts/microbe_stage/microbe_operations.as index 85de2f97978..d79a5229155 100644 --- a/scripts/microbe_stage/microbe_operations.as +++ b/scripts/microbe_stage/microbe_operations.as @@ -1174,8 +1174,8 @@ void kill(CellStageWorld@ world, ObjectID microbeEntity) } } - - + + 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) @@ -1183,9 +1183,9 @@ void kill(CellStageWorld@ world, ObjectID microbeEntity) 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.Scale = Float3(amount*0.5f, amount*0.5f, amount*0.5f); renderNode.Marked = true; renderNode.Node.setOrientation(Ogre::Quaternion( Ogre::Degree(GetEngine().GetRandom().GetNumber(0, 360)), Ogre::Vector3(0,1,1))); @@ -1200,6 +1200,9 @@ void kill(CellStageWorld@ world, ObjectID microbeEntity) body.ConstraintMovementAxises(); rigidBody.JumpTo(chunkPosition); auto venter = world.Create_CompoundVenterComponent(chunkEntity); + //Engulfable + auto engulfable = world.Create_EngulfableComponent(chunkEntity); + engulfable.setSize(amount); // So that larger iron chunks give out more compounds venter.setVentAmount(3); venter.setDoDissolve(true); @@ -1236,6 +1239,10 @@ void kill(CellStageWorld@ world, ObjectID microbeEntity) microbeComponent.dead = true; microbeComponent.deathTimer = 5000; microbeComponent.movementDirection = Float3(0,0,0); + //so they stop absorbing the compounds from the chunks they release immediately + auto compoundAbsorberComponent = world.GetComponent_CompoundAbsorberComponent( + microbeEntity); + compoundAbsorberComponent.disable(); if(rigidBodyComponent.Body !is null) rigidBodyComponent.Body.ClearVelocity(); diff --git a/scripts/microbe_stage/setup.as b/scripts/microbe_stage/setup.as index 57adda766c5..8c4e6d2de1f 100644 --- a/scripts/microbe_stage/setup.as +++ b/scripts/microbe_stage/setup.as @@ -661,6 +661,8 @@ ObjectID createIron(CellStageWorld@ world, Float3 pos) // 5 is the default float ironAmount = 3.0f; double ironBagAmount= IRON_PER_SMALL_CHUNK; + bool dissolves=SMALL_IRON_DISSOLVES; + int ironEngulfSize = 2; // There are four kinds switch (GetEngine().GetRandom().GetNumber(0, 4)) { @@ -680,7 +682,9 @@ ObjectID createIron(CellStageWorld@ world, Float3 pos) mesh="iron_05.mesh"; ironSize=10; ironAmount=10.0f; + ironEngulfSize = 100; ironBagAmount=IRON_PER_BIG_CHUNK; + dissolves=LARGE_IRON_DISSOLVES; break; } @@ -688,8 +692,10 @@ ObjectID createIron(CellStageWorld@ world, Float3 pos) auto venter = world.Create_CompoundVenterComponent(ironEntity); // So that larger iron chunks give out more compounds venter.setVentAmount(ironAmount); + venter.setDoDissolve(dissolves); auto bag = world.Create_CompoundBagComponent(ironEntity); - + auto engulfable = world.Create_EngulfableComponent(ironEntity); + engulfable.setSize(ironEngulfSize); bag.setCompound(SimulationParameters::compoundRegistry().getTypeId("iron"),ironBagAmount); auto model = world.Create_Model(ironEntity, renderNode.Node, mesh); // Need to set the tint diff --git a/src/engine/component_types.h b/src/engine/component_types.h index 5311d147e6f..e97b5c81a2d 100644 --- a/src/engine/component_types.h +++ b/src/engine/component_types.h @@ -22,7 +22,7 @@ enum class THRIVE_COMPONENT : uint16_t { TIMED_LIFE, PROPERTIES, COMPOUND_VENTER, - + ENGULFABLE, // TODO: check is this needed for anything // INVALID }; diff --git a/src/microbe_stage/compound_venter_system.cpp b/src/microbe_stage/compound_venter_system.cpp index a3283abaca6..8d67da44e1d 100644 --- a/src/microbe_stage/compound_venter_system.cpp +++ b/src/microbe_stage/compound_venter_system.cpp @@ -21,6 +21,22 @@ using namespace thrive; // CompoundVenterComponent CompoundVenterComponent::CompoundVenterComponent() : Leviathan::Component(TYPE) {} +// ------------------------------------ // +// EngulfableComponent +EngulfableComponent::EngulfableComponent() : Leviathan::Component(TYPE) {} + +void + EngulfableComponent::setSize(float size) +{ + this->size = size; +} + +float + EngulfableComponent::getSize() +{ + return this->size; +} + void CompoundVenterSystem::Run(CellStageWorld& world) diff --git a/src/microbe_stage/compound_venter_system.h b/src/microbe_stage/compound_venter_system.h index 4c167a13320..42c43345a3a 100644 --- a/src/microbe_stage/compound_venter_system.h +++ b/src/microbe_stage/compound_venter_system.h @@ -48,6 +48,24 @@ class CompoundVenterComponent : public Leviathan::Component { getDoDissolve(); }; +class EngulfableComponent : public Leviathan::Component { +public: + EngulfableComponent(); + + float size; + + REFERENCE_HANDLE_UNCOUNTED_TYPE(EngulfableComponent); + + static constexpr auto TYPE = + componentTypeConvert(THRIVE_COMPONENT::ENGULFABLE); + + void + setSize(float size); + + float + getSize(); +}; + class CompoundVenterSystem : public Leviathan::System(ProcessorComponent::TYPE); static uint16_t CompoundVenterTYPEProxy = static_cast(CompoundVenterComponent::TYPE); +static uint16_t EngulfableComponentTYPEProxy = + static_cast(EngulfableComponent::TYPE); static uint16_t SpawnedComponentTYPEProxy = static_cast(SpawnedComponent::TYPE); static uint16_t AgentCloudComponentTYPEProxy = @@ -543,6 +545,28 @@ bool asCALL_THISCALL) < 0) { ANGELSCRIPT_REGISTERFAIL; } + + // ------------------------------------ // + if(engine->RegisterObjectType( + "EngulfableComponent", 0, asOBJ_REF | asOBJ_NOCOUNT) < 0) { + ANGELSCRIPT_REGISTERFAIL; + } + + if(!bindComponentTypeId( + engine, "EngulfableComponent", &EngulfableComponentTYPEProxy)) + return false; + + if(engine->RegisterObjectMethod("EngulfableComponent", "float getSize()", + asMETHOD(EngulfableComponent, getSize), asCALL_THISCALL) < 0) { + ANGELSCRIPT_REGISTERFAIL; + } + + if(engine->RegisterObjectMethod("EngulfableComponent", + "void setSize(float size)", asMETHOD(EngulfableComponent, setSize), + asCALL_THISCALL) < 0) { + ANGELSCRIPT_REGISTERFAIL; + } + // ------------------------------------ // if(engine->RegisterObjectType( "SpawnedComponent", 0, asOBJ_REF | asOBJ_NOCOUNT) < 0) {