Skip to content

Commit

Permalink
added opportunism as a behavior value, and cleaned up behavior value …
Browse files Browse the repository at this point in the history
…handling code in species system so its cleaner and more modular

fixe dtypo . commented out allchunk bit in AI
  • Loading branch information
Untrustedlife authored and hhyyrylainen committed Mar 15, 2019
1 parent a73a80e commit 197f24f
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 42 deletions.
4 changes: 3 additions & 1 deletion scripts/microbe_stage/configs.as
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,13 @@ const auto MAX_SPECIES_AGRESSION = 400.0f;
const auto MAX_SPECIES_FEAR = 400.0f;
const auto MAX_SPECIES_ACTIVITY = 400.0f;
const auto MAX_SPECIES_FOCUS = 400.0f;
const auto MAX_SPECIES_OPPORTUNISM = 400.0f;

// Personality Mutation
const auto MAX_SPECIES_PERSONALITY_MUTATION = 20.0f;
const auto MIN_SPECIES_PERSONALITY_MUTATION = -20.0f;

// Bacterial CXOlony configuration
// Bacterial COlony configuration
const auto MIN_BACTERIAL_COLONY_SIZE = 1;
const auto MAX_BACTERIAL_COLONY_SIZE = 5;
const auto MIN_BACTERIAL_LINE_SIZE = 3;
Expand All @@ -72,6 +73,7 @@ const auto AGRESSION_DIVISOR = 25.0f;
const auto FEAR_DIVISOR = 25.0f;
const auto ACTIVITY_DIVISOR = 100.0f;
const auto FOCUS_DIVISOR = 100.0f;
const auto OPPORTUNISM_DIVISOR = 100.0f;

// Cooldown for AI for toggling engulfing
const uint AI_ENGULF_INTERVAL=300;
Expand Down
6 changes: 5 additions & 1 deletion scripts/microbe_stage/microbe_ai.as
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class MicrobeAIControllerComponent : ScriptComponent{
double speciesFear = -1.0f;
double speciesActivity = -1.0f;
double speciesFocus = -1.0f;
double speciesOpportunism = -1.0;
bool hasTargetPosition = false;
Float3 targetPosition = Float3(0, 0, 0);
bool hasSearchedCompoundId = false;
Expand Down Expand Up @@ -102,7 +103,7 @@ class MicrobeAISystem : ScriptSystem{
// This list is quite expensive to build each frame but
// there's currently no good way to cache this
array<ObjectID>@ allMicrobes = world.GetScriptComponentHolder("MicrobeComponent").GetIndex();

//array<ObjectID>@ allChunks = world.GetScriptComponentHolder("EngulfableComponent").GetIndex();

for(uint i = 0; i < CachedComponents.length(); ++i){

Expand All @@ -129,6 +130,9 @@ class MicrobeAISystem : ScriptSystem{
if (aiComponent.speciesFocus == -1.0f){
aiComponent.speciesFocus = ourSpecies.focus;
}
if (aiComponent.speciesOpportunism == -1.0f){
aiComponent.speciesOpportunism = ourSpecies.opportunism;
}
}
// Were for debugging
/*LOG_INFO("AI aggression"+aiComponent.speciesAggression);
Expand Down
87 changes: 47 additions & 40 deletions scripts/microbe_stage/species_system.as
Original file line number Diff line number Diff line change
Expand Up @@ -312,15 +312,7 @@ class Species{
genus = generateNameSection();
epithet = generateNameSection();

// Variables used in AI to determine general behavior
this.aggression = GetEngine().GetRandom().GetFloat(0.0f,
MAX_SPECIES_AGRESSION);
this.fear = GetEngine().GetRandom().GetFloat(0.0f,
MAX_SPECIES_FEAR);
this.activity = GetEngine().GetRandom().GetFloat(0.0f,
MAX_SPECIES_ACTIVITY);
this.focus = GetEngine().GetRandom().GetFloat(0.0f,
MAX_SPECIES_FOCUS);
initializeBehavior();

auto stringSize = GetEngine().GetRandom().GetNumber(MIN_INITIAL_LENGTH,
MAX_INITIAL_LENGTH);
Expand Down Expand Up @@ -398,15 +390,7 @@ class Species{
}
genus = parent.genus;

// Variables used in AI to determine general behavior mutate these
this.aggression = parent.aggression+GetEngine().GetRandom().GetFloat(
MIN_SPECIES_PERSONALITY_MUTATION, MAX_SPECIES_PERSONALITY_MUTATION);
this.fear = parent.fear+GetEngine().GetRandom().GetFloat(
MIN_SPECIES_PERSONALITY_MUTATION, MAX_SPECIES_PERSONALITY_MUTATION);
this.activity = parent.activity+GetEngine().GetRandom().GetFloat(
MIN_SPECIES_PERSONALITY_MUTATION, MAX_SPECIES_PERSONALITY_MUTATION);
this.focus = parent.focus+GetEngine().GetRandom().GetFloat(
MIN_SPECIES_PERSONALITY_MUTATION, MAX_SPECIES_PERSONALITY_MUTATION);
mutateBehavior(parent);

// Make sure not over or under our scales
cleanPersonality();
Expand Down Expand Up @@ -493,8 +477,45 @@ class Species{
{
this.focus=0;
}

// Opportunism
if (this.opportunism > MAX_SPECIES_OPPORTUNISM)
{
this.opportunism=MAX_SPECIES_OPPORTUNISM;
}
if (this.opportunism < 0.0f)
{
this.opportunism=0;
}
}

private void initializeBehavior(){
// Variables used in AI to determine general behavior
this.aggression = GetEngine().GetRandom().GetFloat(0.0f,
MAX_SPECIES_AGRESSION);
this.fear = GetEngine().GetRandom().GetFloat(0.0f,
MAX_SPECIES_FEAR);
this.activity = GetEngine().GetRandom().GetFloat(0.0f,
MAX_SPECIES_ACTIVITY);
this.focus = GetEngine().GetRandom().GetFloat(0.0f,
MAX_SPECIES_FOCUS);
this.opportunism = GetEngine().GetRandom().GetFloat(0.0f,
MAX_SPECIES_OPPORTUNISM);
}

private void mutateBehavior(Species@ parent){
// Variables used in AI to determine general behavior mutate these
this.aggression = parent.aggression+GetEngine().GetRandom().GetFloat(
MIN_SPECIES_PERSONALITY_MUTATION, MAX_SPECIES_PERSONALITY_MUTATION);
this.fear = parent.fear+GetEngine().GetRandom().GetFloat(
MIN_SPECIES_PERSONALITY_MUTATION, MAX_SPECIES_PERSONALITY_MUTATION);
this.activity = parent.activity+GetEngine().GetRandom().GetFloat(
MIN_SPECIES_PERSONALITY_MUTATION, MAX_SPECIES_PERSONALITY_MUTATION);
this.focus = parent.focus+GetEngine().GetRandom().GetFloat(
MIN_SPECIES_PERSONALITY_MUTATION, MAX_SPECIES_PERSONALITY_MUTATION);
this.opportunism = parent.opportunism+GetEngine().GetRandom().GetFloat(
MIN_SPECIES_PERSONALITY_MUTATION, MAX_SPECIES_PERSONALITY_MUTATION);
}
private void commonConstructor(CellStageWorld@ world)
{
@forWorld = world;
Expand All @@ -505,12 +526,12 @@ class Species{
{
templateEntity = Species::createSpecies(forWorld, this.name, this.genus, this.epithet,
organelles, this.colour, this.isBacteria, this.speciesMembraneType,
DEFAULT_INITIAL_COMPOUNDS_IRON, this.aggression, this.fear, this.activity, this.focus);
DEFAULT_INITIAL_COMPOUNDS_IRON, this.aggression, this.fear, this.activity, this.focus, this.opportunism);
}
else {
templateEntity = Species::createSpecies(forWorld, this.name, this.genus, this.epithet,
organelles, this.colour, this.isBacteria, this.speciesMembraneType,
DEFAULT_INITIAL_COMPOUNDS, this.aggression, this.fear, this.activity, this.focus);
DEFAULT_INITIAL_COMPOUNDS, this.aggression, this.fear, this.activity, this.focus, this.opportunism);
}

}
Expand Down Expand Up @@ -710,15 +731,7 @@ class Species{
genus = generateNameSection();
epithet = generateNameSection();

// Variables used in AI to determine general behavior
this.aggression = GetEngine().GetRandom().GetFloat(0.0f,
MAX_SPECIES_AGRESSION);
this.fear = GetEngine().GetRandom().GetFloat(0.0f,
MAX_SPECIES_FEAR);
this.activity = GetEngine().GetRandom().GetFloat(0.0f,
MAX_SPECIES_ACTIVITY);
this.focus = GetEngine().GetRandom().GetFloat(0.0f,
MAX_SPECIES_FOCUS);
initializeBehavior();

// Bacteria are tiny, start off with a max of 3 hexes (maybe
// we should start them all off with just one? )
Expand Down Expand Up @@ -807,15 +820,7 @@ class Species{
}


// Variables used in AI to determine general behavior mutate these
this.aggression = parent.aggression+GetEngine().GetRandom().GetFloat(
MIN_SPECIES_PERSONALITY_MUTATION, MAX_SPECIES_PERSONALITY_MUTATION);
this.fear = parent.fear+GetEngine().GetRandom().GetFloat(
MIN_SPECIES_PERSONALITY_MUTATION, MAX_SPECIES_PERSONALITY_MUTATION);
this.activity = parent.activity+GetEngine().GetRandom().GetFloat(
MIN_SPECIES_PERSONALITY_MUTATION, MAX_SPECIES_PERSONALITY_MUTATION);
this.focus = parent.focus+GetEngine().GetRandom().GetFloat(
MIN_SPECIES_PERSONALITY_MUTATION, MAX_SPECIES_PERSONALITY_MUTATION);
mutateBehavior(parent);

// Make sure not over or under our scales
cleanPersonality();
Expand Down Expand Up @@ -904,6 +909,7 @@ class Species{
string epithet;
bool isBacteria;
double aggression = 100.0f;
double opportunism = 100.0f;
double fear = 100.0f;
double activity = 0.0f;
double focus = 0.0f;
Expand Down Expand Up @@ -1453,14 +1459,14 @@ ObjectID createSpecies(CellStageWorld@ world, const string &in name,

return createSpecies(world, name, "Player", "Species", convertedOrganelles,
fromTemplate.colour, fromTemplate.isBacteria, fromTemplate.speciesMembraneType,
fromTemplate.compounds, 100.0f, 100.0f, 100.0f, 200.0f);
fromTemplate.compounds, 100.0f, 100.0f, 100.0f, 200.0f, 100.0f);
}
//! Creates an entity that has all the species stuff on it
//! AI controlled ones need to be in addition in SpeciesSystem
ObjectID createSpecies(CellStageWorld@ world, const string &in name, const string &in genus,
const string &in epithet, array<PlacedOrganelle@> organelles, Float4 colour,
bool isBacteria, MEMBRANE_TYPE speciesMembraneType, const dictionary &in compounds,
double aggression, double fear, double activity, double focus)
double aggression, double fear, double activity, double focus, double opportunism)
{
ObjectID speciesEntity = world.CreateEntity();

Expand Down Expand Up @@ -1507,6 +1513,7 @@ ObjectID createSpecies(CellStageWorld@ world, const string &in name, const strin
speciesComponent.fear = fear;
speciesComponent.activity = activity;
speciesComponent.focus = focus;
speciesComponent.opportunism = opportunism;

// Iterates over all compounds, and sets amounts and priorities
uint64 compoundCount = SimulationParameters::compoundRegistry().getSize();
Expand Down
1 change: 1 addition & 0 deletions src/microbe_stage/species.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class Species : public RegistryType {
std::string epithet;
double fear;
double aggression;
double opportunism;
double activity;
double focus;
MEMBRANE_TYPE speciesMembraneType;
Expand Down
1 change: 1 addition & 0 deletions src/microbe_stage/species_component.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class SpeciesComponent : public Leviathan::Component {
double fear;
double activity;
double focus;
double opportunism;
int32_t population;
int32_t generation;

Expand Down
5 changes: 5 additions & 0 deletions src/scripting/script_initializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,11 @@ bool
ANGELSCRIPT_REGISTERFAIL;
}

if(engine->RegisterObjectProperty("SpeciesComponent", "double opportunism",
asOFFSET(SpeciesComponent, opportunism)) < 0) {
ANGELSCRIPT_REGISTERFAIL;
}

if(engine->RegisterObjectProperty("SpeciesComponent", "int32 population",
asOFFSET(SpeciesComponent, population)) < 0) {
ANGELSCRIPT_REGISTERFAIL;
Expand Down

0 comments on commit 197f24f

Please sign in to comment.