Skip to content

Commit

Permalink
all species now descend from the player species
Browse files Browse the repository at this point in the history
processor stuff is now reset in restoreOrganelleLayour

fixed bug where species lacked a string code sometimes

New epithets (instead of mutated epithets) are more likely to be generated when a species splits, and new genuses are more likely to split off, and changed how species colors work, the more derived a species the more color diference now.

Started coming up with a way of coding locations,got rid of unused constants, moved mutation code to procedural_microbes, got rid of case that no longer exists

gneralized mutation code so eukaryotes and prokaryotes use the same thing

Game now keeps track of species organelle position so mor einteresting shapes can appear and spece sthat split from the player maintain their shape, but in the processi broke mutations

commented out debug Prints renamed getPosition method to something more descriptive because ill be using it for that.

cleaned up code a bunch, it now uses deleimiters and string.split instead of crazy substring shenanigans

cleaned up code to be in line with crodnus suggestion

Mutations that delete organelles now work

removed useless todo that  is now fixed

simplified code even more using join, also added an experimental "replacing" mutation

Changed replacement code a tad

cleaned up species code even more, moved membrane stuff to its own function

Rewrote a bunch of procedural_microbes.as adding organelles now works

Cleaned up code more, also array gets shuffled when placing new organelles on NPC cells to ensure organelles do not always end up on the same side of the cell, reworded comments to be more accurate

Changed AI a bit, to prevent randomly stopping while chasing prey.

AI base speed is now equal to cell base speed, there is a bug where AI player cells move unusually fast (about double), and that still exists, but at least the player themselves and the other species AI cells are now on a more equal playing ground. Added some spacing in movement_organelle so its more readable.

got rid of pointless normalize

Got rid of the cast hhenri mentioned, AI now can choose to move more slowly if they have toxins so they don't ram into cells when trying to shoot toxins at them.
  • Loading branch information
Untrustedlife authored and hhyyrylainen committed May 9, 2019
1 parent c0a2c44 commit 686e085
Show file tree
Hide file tree
Showing 7 changed files with 290 additions and 247 deletions.
13 changes: 10 additions & 3 deletions scripts/microbe_stage/configs.as
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,17 @@ const auto MAX_SPAWN_DISTANCE = 5000.0f;
// Cell Colors
const auto MIN_COLOR = 0.0f;
const auto MAX_COLOR = 0.9f;

// Too subtle?
const auto MIN_COLOR_MUTATION = -0.005f;
const auto MAX_COLOR_MUTATION = 0.005f;
const auto MIN_COLOR_MUTATION = -0.2f;
const auto MAX_COLOR_MUTATION = 0.2f;

const auto MIN_OPACITY = 0.5f;
const auto MAX_OPACITY = 1.8f;

const auto MIN_OPACITY_CHITIN = 0.4f;
const auto MAX_OPACITY_CHITIN = 1.2f;

// Min Opacity Mutation
const auto MIN_OPACITY_MUTATION = -0.01f;
const auto MAX_OPACITY_MUTATION = 0.01f;
Expand All @@ -40,9 +42,11 @@ const auto MAX_OPACITY_MUTATION = 0.01f;
const auto MUTATION_BACTERIA_TO_EUKARYOTE = 1;
const auto MUTATION_CREATION_RATE = 0.1f;
const auto MUTATION_DELETION_RATE = 0.1f;
const auto MUTATION_REPLACEMENT_RATE = 0.1f;

//Removal cost
const auto ORGANELLE_REMOVE_COST = 10;

// Spawn Radius
const auto MICROBE_SPAWN_RADIUS = 150;
const auto BACTERIA_SPAWN_RADIUS = 150;
Expand Down Expand Up @@ -101,8 +105,11 @@ const auto REGENERATION_RATE = 1.0f;
const auto FLAGELLA_ENERGY_COST = 7.1f;
const auto FLAGELLA_BASE_FORCE = 0.7f;
const auto CELL_BASE_THRUST = 1.6f;

// is set by this and modified by applyCellMovement like the player later
const auto AI_BASE_MOVEMENT = 1.0f;
const auto AI_BASE_MOVEMENT = 1.6f;
const auto AI_FOCUSED_MOVEMENT = 1.0f;

//! The drag force is calculated by taking the current velocity and multiplying it by this.
//! This must be negative!
const auto CELL_DRAG_MULTIPLIER = -0.12f;
Expand Down
49 changes: 37 additions & 12 deletions scripts/microbe_stage/microbe_ai.as
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class MicrobeAIControllerComponent : ScriptComponent{
ObjectID prey = NULL_OBJECT;
ObjectID targetChunk = NULL_OBJECT;
ObjectID predator = NULL_OBJECT;
bool moveThisHunt = true;
bool moveFocused = false;
bool preyPegged=false;
// Prey and predator lists
array<ObjectID> predatoryMicrobes;
Expand Down Expand Up @@ -521,12 +523,17 @@ class MicrobeAISystem : ScriptSystem{
aiComponent.hasTargetPosition = true;

//Always set target Position, for use later in AI
if (aiComponent.speciesAggression+GetEngine().GetRandom().GetNumber(-100.0f,100.0f) > aiComponent.speciesActivity){
microbeComponent.movementDirection = Float3(0, 0, -AI_BASE_MOVEMENT);
if (aiComponent.moveThisHunt){
if (aiComponent.moveFocused){
microbeComponent.movementDirection = Float3(0.0f,0.0f,-AI_FOCUSED_MOVEMENT);
}
else{
microbeComponent.movementDirection = Float3(0, 0, 0);
microbeComponent.movementDirection = Float3(0.0f,0.0f,-AI_BASE_MOVEMENT);
}
}
else{
microbeComponent.movementDirection = Float3(0, 0, 0);
}

// Turn off engulf if prey is Dead
// This is probabbly not working
Expand Down Expand Up @@ -614,11 +621,11 @@ class MicrobeAISystem : ScriptSystem{
aiComponent.targetPosition = world.GetComponent_Position(chunk)._Position;
auto vec = (aiComponent.targetPosition - position._Position);
aiComponent.direction = vec.Normalize();
microbeComponent.facingTargetPoint = aiComponent.targetPosition;
microbeComponent.facingTargetPoint = aiComponent.targetPosition;
aiComponent.hasTargetPosition = true;

//Always set target Position, for use later in AI
microbeComponent.movementDirection = Float3(0, 0, -AI_BASE_MOVEMENT);
microbeComponent.movementDirection = Float3(0.0f,0.0f,-AI_BASE_MOVEMENT);

// Turn off engulf if chunk is gone
if (engulfableComponent is null){
Expand Down Expand Up @@ -707,7 +714,7 @@ class MicrobeAISystem : ScriptSystem{
auto vec = (position._Position-aiComponent.targetPosition);
aiComponent.direction = vec.Normalize();
microbeComponent.facingTargetPoint = -aiComponent.targetPosition;
microbeComponent.movementDirection = Float3(0, 0, -(AI_BASE_MOVEMENT));
microbeComponent.movementDirection = Float3(0.0f,0.0f,-AI_BASE_MOVEMENT);
aiComponent.hasTargetPosition = true;

//Freak out and fire toxins everywhere
Expand All @@ -727,24 +734,30 @@ class MicrobeAISystem : ScriptSystem{
//LOG_INFO("evaluating");
MicrobeAIControllerComponent@ aiComponent = components.first;
Position@ position = components.third;
MicrobeComponent@ microbeComponent = components.second;
CompoundId oxytoxyId = SimulationParameters::compoundRegistry().getTypeId("oxytoxy");
int numberOfAgentVacuoles = int(
microbeComponent.specialStorageOrganelles[formatUInt(oxytoxyId)]);

//rollCheck(aiComponent.speciesOpportunism,500.0f)
if (rollCheck(aiComponent.speciesOpportunism,500.0f))
{
aiComponent.lifeState = SCAVENGING_STATE;
aiComponent.boredom = 0;
}
else if (rollCheck(aiComponent.speciesActivity,500.0f))
{
aiComponent.lifeState = PLANTLIKE_STATE;
aiComponent.boredom = 0;
}
else {
if (prey != NULL_OBJECT && predator != NULL_OBJECT)
{
//LOG_INFO("Both");
if (GetEngine().GetRandom().GetNumber(0.0f,aiComponent.speciesAggression) >
GetEngine().GetRandom().GetNumber(0.0f,aiComponent.speciesFear) &&
(aiComponent.preyMicrobes.length() > 0)){
aiComponent.moveThisHunt=!rollCheck(aiComponent.speciesActivity,500.0f);

if (numberOfAgentVacuoles > 0){
aiComponent.moveFocused = rollCheck(aiComponent.speciesFocus,500.0f);
}

aiComponent.lifeState = PREDATING_STATE;
}
else if (GetEngine().GetRandom().GetNumber(0.0f,aiComponent.speciesAggression) <
Expand All @@ -756,6 +769,12 @@ class MicrobeAISystem : ScriptSystem{
else if (aiComponent.speciesAggression == aiComponent.speciesFear &&
(aiComponent.preyMicrobes.length() > 0)){
// Prefer predating (makes game more fun)
aiComponent.moveThisHunt=!rollCheck(aiComponent.speciesActivity,500.0f);

if (numberOfAgentVacuoles > 0){
aiComponent.moveFocused = rollCheck(aiComponent.speciesFocus,500.0f);
}

aiComponent.lifeState = PREDATING_STATE;
}
else if (rollCheck(aiComponent.speciesFocus,500.0f) && GetEngine().GetRandom().GetNumber(0,10) <= 2){
Expand All @@ -764,6 +783,12 @@ class MicrobeAISystem : ScriptSystem{
}
else if (prey != NULL_OBJECT){
//LOG_INFO("prey only");
aiComponent.moveThisHunt=!rollCheck(aiComponent.speciesActivity,500.0f);

if (numberOfAgentVacuoles > 0){
aiComponent.moveFocused = rollCheck(aiComponent.speciesFocus,500.0f);
}

aiComponent.lifeState = PREDATING_STATE;
}
else if (predator != NULL_OBJECT){
Expand Down Expand Up @@ -845,7 +870,7 @@ class MicrobeAISystem : ScriptSystem{
auto vec = (aiComponent.targetPosition - position._Position);
aiComponent.direction = vec.Normalize();
microbeComponent.facingTargetPoint = aiComponent.targetPosition;
microbeComponent.movementDirection = Float3(0, 0, -AI_BASE_MOVEMENT);
microbeComponent.movementDirection = Float3(0.0f,0.0f,-AI_BASE_MOVEMENT);
aiComponent.hasTargetPosition = true;

}
Expand Down
14 changes: 12 additions & 2 deletions scripts/microbe_stage/microbe_editor/microbe_editor.as
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,20 @@ class MicrobeEditor{
playerSpecies.organelles);

editedMicrobe.resize(0);
playerSpecies.stringCode="";
for(uint i = 0; i < templateOrganelles.length(); ++i){
editedMicrobe.insertLast(cast<PlacedOrganelle>(templateOrganelles[i]));
auto organelle = cast<PlacedOrganelle>(templateOrganelles[i]);
editedMicrobe.insertLast(organelle);
playerSpecies.stringCode+=organelle._organelle.gene;
// This will always be added after each organelle so its safe to assume its there
playerSpecies.stringCode+=","+organelle.q+","+
organelle.r+","+
organelle.rotation;
if (i != templateOrganelles.length()-1){
playerSpecies.stringCode+="|";
}
}

LOG_INFO(playerSpecies.stringCode);
LOG_INFO("Starting microbe editor with: " + editedMicrobe.length() +
" organelles in the microbe");

Expand Down
2 changes: 1 addition & 1 deletion scripts/microbe_stage/organelle.as
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,7 @@ class PlacedOrganelle : SpeciesStoredOrganelleType{
}
}

private Organelle@ _organelle;
Organelle@ _organelle;

// q and r are radial coordinates instead of cartesian
// Could use the class AxialCoordinates here
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,12 @@ class MovementOrganelle : OrganelleComponent{
MicrobeComponent@ microbeComponent = cast<MicrobeComponent>(
organelle.world.GetScriptComponentHolder("MicrobeComponent").Find(microbeEntity));
auto pos = organelle.world.GetComponent_Position(microbeEntity);


const auto force = calculateMovementForce(microbeEntity, organelle, logicTime,
microbeComponent, pos);


if(force != Float3(0, 0, 0))
microbeComponent.addMovementForce(force);
}
Expand Down
Loading

0 comments on commit 686e085

Please sign in to comment.