From 197f24f46d1421579bfe5956d6a91bc23b3c16ed Mon Sep 17 00:00:00 2001 From: Untrustedlife Date: Sun, 24 Feb 2019 12:40:04 -0600 Subject: [PATCH] added opportunism as a behavior value, and cleaned up behavior value handling code in species system so its cleaner and more modular fixe dtypo . commented out allchunk bit in AI --- scripts/microbe_stage/configs.as | 4 +- scripts/microbe_stage/microbe_ai.as | 6 +- scripts/microbe_stage/species_system.as | 87 +++++++++++++------------ src/microbe_stage/species.h | 1 + src/microbe_stage/species_component.h | 1 + src/scripting/script_initializer.cpp | 5 ++ 6 files changed, 62 insertions(+), 42 deletions(-) diff --git a/scripts/microbe_stage/configs.as b/scripts/microbe_stage/configs.as index 3543d34545f..c5ff979c366 100644 --- a/scripts/microbe_stage/configs.as +++ b/scripts/microbe_stage/configs.as @@ -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; @@ -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; diff --git a/scripts/microbe_stage/microbe_ai.as b/scripts/microbe_stage/microbe_ai.as index 471ef9cadf5..74056c947de 100644 --- a/scripts/microbe_stage/microbe_ai.as +++ b/scripts/microbe_stage/microbe_ai.as @@ -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; @@ -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@ allMicrobes = world.GetScriptComponentHolder("MicrobeComponent").GetIndex(); - + //array@ allChunks = world.GetScriptComponentHolder("EngulfableComponent").GetIndex(); for(uint i = 0; i < CachedComponents.length(); ++i){ @@ -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); diff --git a/scripts/microbe_stage/species_system.as b/scripts/microbe_stage/species_system.as index 78127f80249..8017d134d92 100644 --- a/scripts/microbe_stage/species_system.as +++ b/scripts/microbe_stage/species_system.as @@ -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); @@ -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(); @@ -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; @@ -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); } } @@ -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? ) @@ -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(); @@ -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; @@ -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 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(); @@ -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(); diff --git a/src/microbe_stage/species.h b/src/microbe_stage/species.h index 8537c685dcf..3aa53d0ea3d 100644 --- a/src/microbe_stage/species.h +++ b/src/microbe_stage/species.h @@ -22,6 +22,7 @@ class Species : public RegistryType { std::string epithet; double fear; double aggression; + double opportunism; double activity; double focus; MEMBRANE_TYPE speciesMembraneType; diff --git a/src/microbe_stage/species_component.h b/src/microbe_stage/species_component.h index 4ca1b1e9330..53132e8f888 100644 --- a/src/microbe_stage/species_component.h +++ b/src/microbe_stage/species_component.h @@ -37,6 +37,7 @@ class SpeciesComponent : public Leviathan::Component { double fear; double activity; double focus; + double opportunism; int32_t population; int32_t generation; diff --git a/src/scripting/script_initializer.cpp b/src/scripting/script_initializer.cpp index 3ac9070089b..7d755ac806c 100644 --- a/src/scripting/script_initializer.cpp +++ b/src/scripting/script_initializer.cpp @@ -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;