-
-
Notifications
You must be signed in to change notification settings - Fork 512
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Let AI engulf even if running out of atp #5729
base: master
Are you sure you want to change the base?
Changes from all commits
5f0afe5
7a68e2e
4d70c95
208ff3c
4ba706d
1b5d95d
502ea9b
c9eb9cb
e698eea
10ce6e6
fecacc8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -280,6 +280,8 @@ private void ChooseActions(in Entity entity, ref MicrobeAI ai, ref CompoundAbsor | |
|
||
ref var control = ref entity.Get<MicrobeControl>(); | ||
|
||
ref var cellHealth = ref entity.Get<Health>(); | ||
|
||
ref var compoundStorage = ref entity.Get<CompoundStorage>(); | ||
|
||
var compounds = compoundStorage.Compounds; | ||
|
@@ -330,18 +332,30 @@ private void ChooseActions(in Entity entity, ref MicrobeAI ai, ref CompoundAbsor | |
control.SetMucocystState(ref organelles, ref compoundStorage, entity, false); | ||
} | ||
|
||
float atpLevel = compounds.GetCompoundAmount(Compound.ATP); | ||
|
||
// If this microbe is out of ATP, pick an amount of time to rest | ||
if (compounds.GetCompoundAmount(Compound.ATP) < 1.0f) | ||
if (atpLevel < 1.0f) | ||
{ | ||
// Keep the maximum at 95% full, as there is flickering when near full | ||
ai.ATPThreshold = 0.95f * speciesFocus / Constants.MAX_SPECIES_FOCUS; | ||
} | ||
|
||
if (ai.ATPThreshold > MathUtils.EPSILON) | ||
{ | ||
if (compounds.GetCompoundAmount(Compound.ATP) < | ||
compounds.GetCapacityForCompound(Compound.ATP) * ai.ATPThreshold) | ||
if (atpLevel < compounds.GetCapacityForCompound(Compound.ATP) * ai.ATPThreshold) | ||
{ | ||
if (cellHealth.CurrentHealth > 2 * Constants.ENGULF_NO_ATP_DAMAGE) | ||
{ | ||
// Even if we are out of ATP and there is microbe nearby, engulf them. | ||
// make sure engulfing doesn't kill the cell | ||
if (CheckForHuntingConditions(ref ai, ref position, ref organelles, ref ourSpecies, ref engulfer, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe it would be a good idea to move this check to after the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that maybe the if could be removed entirely? Because the state force code already skips the force if the cell would have so little health that it would die. |
||
ref cellProperties, ref control, ref cellHealth, ref compoundStorage, entity, speciesFocus, | ||
speciesAggression, speciesActivity, speciesOpportunism, strain, random, true, | ||
atpLevel)) | ||
return; | ||
} | ||
|
||
bool outOfSomething = false; | ||
foreach (var compound in compounds.Compounds) | ||
{ | ||
|
@@ -467,6 +481,37 @@ private void ChooseActions(in Entity entity, ref MicrobeAI ai, ref CompoundAbsor | |
} | ||
} | ||
|
||
// check if species can hunt any prey and if so - engage in chase | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment should too start with a capital letter |
||
bool isHunting = CheckForHuntingConditions(ref ai, ref position, ref organelles, ref ourSpecies, ref engulfer, | ||
ref cellProperties, ref control, ref health, ref compoundStorage, entity, speciesFocus, speciesAggression, | ||
speciesActivity, speciesOpportunism, strain, random, false, atpLevel); | ||
if (isHunting) | ||
return; | ||
|
||
// There is no reason to be engulfing at this stage | ||
control.SetStateColonyAware(entity, MicrobeState.Normal); | ||
|
||
// Otherwise just wander around and look for compounds | ||
if (!isSessile) | ||
{ | ||
SeekCompounds(in entity, ref ai, ref position, ref control, ref organelles, ref absorber, compounds, | ||
speciesActivity, speciesFocus, random); | ||
} | ||
else | ||
{ | ||
// This organism is sessile, and will not act until the environment changes | ||
control.SetMoveSpeed(0.0f); | ||
} | ||
} | ||
|
||
private bool CheckForHuntingConditions(ref MicrobeAI ai, ref WorldPosition position, | ||
ref OrganelleContainer organelles, ref SpeciesMember ourSpecies, | ||
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); | ||
|
@@ -482,32 +527,25 @@ private void ChooseActions(in Entity entity, ref MicrobeAI ai, ref CompoundAbsor | |
{ | ||
GD.PrintErr("Microbe AI tried to engage prey with no position: " + e); | ||
ai.FocusedPrey = default; | ||
return; | ||
return false; | ||
} | ||
|
||
bool engulfPrey = cellProperties.CanEngulfObject(ref ourSpecies, ref engulfer, possiblePrey) == | ||
EngulfCheckResult.Ok && position.Position.DistanceSquaredTo(prey) < | ||
10.0f * engulfer.EngulfingSize; | ||
|
||
EngagePrey(ref ai, ref control, ref organelles, ref position, compounds, entity, prey, engulfPrey, | ||
speciesAggression, speciesFocus, speciesActivity, strain, random); | ||
return; | ||
} | ||
|
||
// There is no reason to be engulfing at this stage | ||
control.SetStateColonyAware(entity, MicrobeState.Normal); | ||
// if out of ATP and the prey is out of reach to engulf, do nothing | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment should begin with a capital letter too |
||
if (outOfAtp && !engulfPrey) | ||
{ | ||
return false; | ||
} | ||
|
||
// Otherwise just wander around and look for compounds | ||
if (!isSessile) | ||
{ | ||
SeekCompounds(in entity, ref ai, ref position, ref control, ref organelles, ref absorber, compounds, | ||
speciesActivity, speciesFocus, random); | ||
} | ||
else | ||
{ | ||
// This organism is sessile, and will not act until the environment changes | ||
control.SetMoveSpeed(0.0f); | ||
EngagePrey(ref ai, ref control, ref organelles, ref position, ref compoundStorage, ref health, entity, | ||
prey, engulfPrey, speciesAggression, speciesFocus, speciesActivity, strain, random, atpLevel); | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
private (Entity Entity, Vector3 Position, float EngulfSize, CompoundBag Compounds)? GetNearestChunkItem( | ||
|
@@ -858,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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see the |
||
{ | ||
control.EnterEngulfModeForcedState(ref health, ref compoundStorage, entity, Compound.ATP); | ||
hhyyrylainen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
else | ||
{ | ||
control.SetStateColonyAware(entity, engulf ? MicrobeState.Engulf : MicrobeState.Normal); | ||
} | ||
|
||
ai.TargetPosition = target; | ||
control.LookAtPoint = ai.TargetPosition; | ||
if (CanShootToxin(ourCompounds, speciesFocus)) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be better to use the
health
variable that is already passed into this function?