Skip to content

Commit

Permalink
Added EngulfableComponent and its variables and exposed them to angel…
Browse files Browse the repository at this point in the history
…script

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.
  • Loading branch information
Untrustedlife authored and hhyyrylainen committed Mar 15, 2019
1 parent f5b3288 commit 8647f84
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 7 deletions.
5 changes: 4 additions & 1 deletion scripts/microbe_stage/configs.as
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
15 changes: 11 additions & 4 deletions scripts/microbe_stage/microbe_operations.as
Original file line number Diff line number Diff line change
Expand Up @@ -1174,18 +1174,18 @@ 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)
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.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)));
Expand All @@ -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);
Expand Down Expand Up @@ -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();
Expand Down
8 changes: 7 additions & 1 deletion scripts/microbe_stage/setup.as
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand All @@ -680,16 +682,20 @@ 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;
}


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
Expand Down
2 changes: 1 addition & 1 deletion src/engine/component_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ enum class THRIVE_COMPONENT : uint16_t {
TIMED_LIFE,
PROPERTIES,
COMPOUND_VENTER,

ENGULFABLE,
// TODO: check is this needed for anything
// INVALID
};
Expand Down
16 changes: 16 additions & 0 deletions src/microbe_stage/compound_venter_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 18 additions & 0 deletions src/microbe_stage/compound_venter_system.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::tuple<CompoundBagComponent&,
CompoundVenterComponent&,
Expand Down
1 change: 1 addition & 0 deletions src/microbe_stage/generate_cell_stage_world.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
EntityComponent.new("ProcessorComponent", [ConstructorInfo.new([])]),
EntityComponent.new("CompoundBagComponent", [ConstructorInfo.new([])]),
EntityComponent.new("CompoundVenterComponent", [ConstructorInfo.new([])]),
EntityComponent.new("EngulfableComponent", [ConstructorInfo.new([])]),
EntityComponent.new("SpeciesComponent", [ConstructorInfo.new([
Variable.new("name", "std::string",
memberaccess: "name",
Expand Down
24 changes: 24 additions & 0 deletions src/scripting/script_initializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,8 @@ static uint16_t ProcessorComponentTYPEProxy =
static_cast<uint16_t>(ProcessorComponent::TYPE);
static uint16_t CompoundVenterTYPEProxy =
static_cast<uint16_t>(CompoundVenterComponent::TYPE);
static uint16_t EngulfableComponentTYPEProxy =
static_cast<uint16_t>(EngulfableComponent::TYPE);
static uint16_t SpawnedComponentTYPEProxy =
static_cast<uint16_t>(SpawnedComponent::TYPE);
static uint16_t AgentCloudComponentTYPEProxy =
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 8647f84

Please sign in to comment.