Skip to content

Commit

Permalink
Added floating "iron"
Browse files Browse the repository at this point in the history
Iron particles now dont get destroyed when you run into them and are hard to push
  • Loading branch information
Untrustedlife authored and hhyyrylainen committed Feb 15, 2019
1 parent 8ef12a7 commit da9aecb
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 3 deletions.
68 changes: 65 additions & 3 deletions scripts/microbe_stage/setup.as
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,6 @@ void onReturnFromEditor(CellStageWorld@ world)

}

// TODO: also put these physics callback somewhere more sensible (maybe physics_callbacks.as?)
void cellHitFloatingOrganelle(GameWorld@ world, ObjectID firstEntity, ObjectID secondEntity)
{
// Determine which is the organelle
Expand All @@ -294,6 +293,31 @@ void cellHitFloatingOrganelle(GameWorld@ world, ObjectID firstEntity, ObjectID s
world.QueueDestroyEntity(floatingEntity);
}

// TODO: also put these physics callback somewhere more sensible (maybe physics_callbacks.as?)
void cellHitIron(GameWorld@ world, ObjectID firstEntity, ObjectID secondEntity)
{
// Determine which is the iron
CellStageWorld@ asCellWorld = cast<CellStageWorld>(world);

auto model = asCellWorld.GetComponent_Model(firstEntity);
auto floatingEntity = firstEntity;
auto cellEntity = secondEntity;

// Cell doesn't have a model
if(model is null){

@model = asCellWorld.GetComponent_Model(secondEntity);
floatingEntity = secondEntity;
cellEntity = firstEntity;
}

// TODO: use this to detect stuff
LOG_INFO("Model: " + model.GraphicalObject.getMesh().getName());
LOG_INFO("TODO: organelle unlock progress if cell: " + cellEntity + " is the player");

//world.QueueDestroyEntity(floatingEntity);
}

// Cell Hit Oxytoxy
// We can make this generic using the dictionary in agents.as
// eventually, but for now all we have is oxytoxy
Expand Down Expand Up @@ -624,6 +648,39 @@ ObjectID createChloroplast(CellStageWorld@ world, Float3 pos)
return chloroplastEntity;
}

ObjectID createIron(CellStageWorld@ world, Float3 pos)
{
// Chloroplasts
ObjectID ironEntity = world.CreateEntity();

auto position = world.Create_Position(ironEntity, pos,
Ogre::Quaternion(Ogre::Degree(GetEngine().GetRandom().GetNumber(0, 360)),
Ogre::Vector3(0,1,1)));

auto renderNode = world.Create_RenderNode(ironEntity);
renderNode.Scale = Float3(1, 1, 1);
renderNode.Marked = true;
renderNode.Node.setOrientation(Ogre::Quaternion(
Ogre::Degree(GetEngine().GetRandom().GetNumber(0, 360)),
Ogre::Vector3(0,1,1)));
renderNode.Node.setPosition(pos);
auto model = world.Create_Model(ironEntity, renderNode.Node, "iron_01.mesh");
// Need to set the tint
model.GraphicalObject.setCustomParameter(1, Ogre::Vector4(1, 1, 1, 1));

auto rigidBody = world.Create_Physics(ironEntity, position);
auto body = rigidBody.CreatePhysicsBody(world.GetPhysicalWorld(),
world.GetPhysicalWorld().CreateSphere(1), 100,
//iron
world.GetPhysicalMaterial("iron"));

body.ConstraintMovementAxises();

rigidBody.JumpTo(position);

return ironEntity;
}

// TODO: the player species handling would be more logically placed if
// it was in SpeciesSystem, so move it there
void setupSpawnSystem(CellStageWorld@ world){
Expand Down Expand Up @@ -663,13 +720,18 @@ void setupFloatingOrganelles(CellStageWorld@ world){
LOG_INFO("setting up free floating organelles");
SpawnSystem@ spawnSystem = world.GetSpawnSystem();

//spawn toxin and chloroplasts
// chloroplasts
const auto chloroId = spawnSystem.addSpawnType(
@createChloroplast, DEFAULT_SPAWN_DENSITY,
MICROBE_SPAWN_RADIUS);

//toxins
// toxins
const auto toxinId = spawnSystem.addSpawnType(
@createToxin, DEFAULT_SPAWN_DENSITY,
MICROBE_SPAWN_RADIUS);

// iron
const auto ironId = spawnSystem.addSpawnType(
@createIron, DEFAULT_SPAWN_DENSITY,
MICROBE_SPAWN_RADIUS);
}
27 changes: 27 additions & 0 deletions src/thrive_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,24 @@ void
LOG_ERROR("Failed to run script side cellHitFloatingOrganelle");
}

void
cellHitIron(Leviathan::PhysicalWorld& physicalWorld,
Leviathan::PhysicsBody& first,
Leviathan::PhysicsBody& second)
{
GameWorld* gameWorld = physicalWorld.GetGameWorld();

ScriptRunningSetup setup("cellHitIron");

auto result =
ThriveCommon::get()->getMicrobeScripts()->ExecuteOnModule<void>(setup,
false, gameWorld, first.GetOwningEntity(),
second.GetOwningEntity());

if(result.Result != SCRIPT_RUN_RESULT::Success)
LOG_ERROR("Failed to run script side cellHitIron");
}

//! \todo This should return false when either cell is engulfing and apply the
//! damaging effect
bool
Expand Down Expand Up @@ -244,6 +262,8 @@ std::unique_ptr<Leviathan::PhysicsMaterialManager>
std::make_unique<Leviathan::PhysicalMaterial>("cell", 1);
auto floatingOrganelleMaterial =
std::make_unique<Leviathan::PhysicalMaterial>("floatingOrganelle", 2);
auto ironMaterial =
std::make_unique<Leviathan::PhysicalMaterial>("iron", 2);
auto agentMaterial =
std::make_unique<Leviathan::PhysicalMaterial>("agentCollision", 3);

Expand All @@ -252,9 +272,15 @@ std::unique_ptr<Leviathan::PhysicsMaterialManager>
// Floating organelles
cellMaterial->FormPairWith(*floatingOrganelleMaterial)
.SetCallbacks(nullptr, cellHitFloatingOrganelle);

// Iron
cellMaterial->FormPairWith(*ironMaterial)
.SetCallbacks(nullptr, cellHitIron);

// Agents
cellMaterial->FormPairWith(*agentMaterial)
.SetCallbacks(agentCallback, agentCollided);

// Engulfing
cellMaterial->FormPairWith(*cellMaterial)
.SetCallbacks(cellOnCellAABBHitCallback, cellOnCellActualContact);
Expand All @@ -263,6 +289,7 @@ std::unique_ptr<Leviathan::PhysicsMaterialManager>

manager->LoadedMaterialAdd(std::move(cellMaterial));
manager->LoadedMaterialAdd(std::move(floatingOrganelleMaterial));
manager->LoadedMaterialAdd(std::move(ironMaterial));
manager->LoadedMaterialAdd(std::move(agentMaterial));

return manager;
Expand Down

0 comments on commit da9aecb

Please sign in to comment.