Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Patryk26g committed Dec 12, 2024
1 parent 9d440cd commit e5d76b3
Showing 1 changed file with 28 additions and 18 deletions.
46 changes: 28 additions & 18 deletions src/microbe_stage/systems/MicrobeAISystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,6 @@ private void ChooseActions(in Entity entity, ref MicrobeAI ai, ref CompoundAbsor

float atpLevel = compounds.GetCompoundAmount(Compound.ATP);

float atpLevel = compounds.GetCompoundAmount(Compound.ATP);

// If this microbe is out of ATP, pick an amount of time to rest
if (atpLevel < 1.0f)
{
Expand All @@ -349,13 +347,12 @@ private void ChooseActions(in Entity entity, ref MicrobeAI ai, ref CompoundAbsor
{
if (cellHealth.CurrentHealth > 2 * Constants.ENGULF_NO_ATP_DAMAGE)
{
// even if we are out of ATP and there is microbe nearby, engulf them.
// Even if we are out of ATP and there is microbe nearby, engulf them.
// make sure engulfing doesn't kill the cell
bool isMicrobeHunting = CheckForHuntingConditions(ref ai, ref position, ref organelles,
ref ourSpecies, ref engulfer, ref cellProperties, ref control, entity, compounds,
speciesFocus, speciesAggression, speciesActivity, speciesOpportunism, strain,
random, true);
if (isMicrobeHunting)
if (CheckForHuntingConditions(ref ai, ref position, ref organelles, ref ourSpecies, ref engulfer,
ref cellProperties, ref control, ref cellHealth, ref compoundStorage, entity, speciesFocus,
speciesAggression, speciesActivity, speciesOpportunism, strain, random, true,
atpLevel))
return;
}

Expand Down Expand Up @@ -486,8 +483,8 @@ private void ChooseActions(in Entity entity, ref MicrobeAI ai, ref CompoundAbsor

// check if species can hunt any prey and if so - engage in chase
bool isHunting = CheckForHuntingConditions(ref ai, ref position, ref organelles, ref ourSpecies, ref engulfer,
ref cellProperties, ref control, entity, compounds, speciesFocus, speciesAggression,
speciesActivity, speciesOpportunism, strain, random, false);
ref cellProperties, ref control, ref health, ref compoundStorage, entity, speciesFocus, speciesAggression,
speciesActivity, speciesOpportunism, strain, random, false, atpLevel);
if (isHunting)
return;

Expand All @@ -509,10 +506,12 @@ private void ChooseActions(in Entity entity, ref MicrobeAI ai, ref CompoundAbsor

private bool CheckForHuntingConditions(ref MicrobeAI ai, ref WorldPosition position,
ref OrganelleContainer organelles, ref SpeciesMember ourSpecies,
ref Engulfer engulfer, ref CellProperties cellProperties, ref MicrobeControl control, in Entity entity,
CompoundBag compounds, float speciesFocus, float speciesAggression, float speciesActivity,
float speciesOpportunism, float strain, Random random, bool outOfAtp)
ref Engulfer engulfer, ref CellProperties cellProperties, ref MicrobeControl control, ref Health health,
ref CompoundStorage compoundStorage, in Entity entity, float speciesFocus, float speciesAggression,
float speciesActivity, float speciesOpportunism, float strain, Random random, bool outOfAtp, float atpLevel)
{
var compounds = compoundStorage.Compounds;

// If there are no chunks, look for living prey to hunt
var possiblePrey = GetNearestPreyItem(ref ai, ref position, ref organelles, ref ourSpecies, ref engulfer,
compounds, speciesFocus, speciesAggression, speciesOpportunism, random);
Expand Down Expand Up @@ -541,8 +540,8 @@ private bool CheckForHuntingConditions(ref MicrobeAI ai, ref WorldPosition posit
return false;
}

EngagePrey(ref ai, ref control, ref organelles, ref position, compounds, entity, prey, engulfPrey,
speciesAggression, speciesFocus, speciesActivity, strain, random);
EngagePrey(ref ai, ref control, ref organelles, ref position, ref compoundStorage, ref health, entity,
prey, engulfPrey, speciesAggression, speciesFocus, speciesActivity, strain, random, atpLevel);
return true;
}

Expand Down Expand Up @@ -897,10 +896,21 @@ private void FleeFromPredators(ref WorldPosition position, ref MicrobeAI ai, ref
}

private void EngagePrey(ref MicrobeAI ai, ref MicrobeControl control, ref OrganelleContainer organelles,
ref WorldPosition position, CompoundBag ourCompounds, in Entity entity, Vector3 target, bool engulf,
float speciesAggression, float speciesFocus, float speciesActivity, float strain, Random random)
ref WorldPosition position, ref CompoundStorage compoundStorage, ref Health health, in Entity entity,
Vector3 target, bool engulf, float speciesAggression, float speciesFocus, float speciesActivity,
float strain, Random random, float atpLevel)
{
control.SetStateColonyAware(entity, engulf ? MicrobeState.Engulf : MicrobeState.Normal);
var ourCompounds = compoundStorage.Compounds;

if (atpLevel <= Constants.ENGULF_NO_ATP_TRIGGER_THRESHOLD)
{
control.EnterEngulfModeForcedState(ref health, ref compoundStorage, entity, Compound.ATP);
}
else
{
control.SetStateColonyAware(entity, engulf ? MicrobeState.Engulf : MicrobeState.Normal);
}

ai.TargetPosition = target;
control.LookAtPoint = ai.TargetPosition;
if (CanShootToxin(ourCompounds, speciesFocus))
Expand Down

0 comments on commit e5d76b3

Please sign in to comment.