-
-
Notifications
You must be signed in to change notification settings - Fork 515
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
Merged
hhyyrylainen
merged 18 commits into
Revolutionary-Games:master
from
Patryk26g:engulfEvenIfOutOfAtp
Feb 3, 2025
+70
−24
Merged
Changes from 14 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
5f0afe5
Engulf microbe even if out of ATP
Patryk26g 7a68e2e
Fix
Patryk26g 4d70c95
Fix 2
Patryk26g 208ff3c
Fix
Patryk26g 4ba706d
Fix
Patryk26g 1b5d95d
Engulf microbe even if out of ATP
Patryk26g 502ea9b
Fix
Patryk26g c9eb9cb
Fix 2
Patryk26g e698eea
rebase
Patryk26g 10ce6e6
Fix
Patryk26g fecacc8
Fix
Patryk26g d7b3e19
Fixes
Patryk26g 98aa729
Merge branch 'master' into engulfEvenIfOutOfAtp
Patryk26g 1ec349a
Fix
Patryk26g a558d50
Style fix
Patryk26g b032d5f
Fixes
Patryk26g 6241339
Fix
Patryk26g aa72d08
Update MicrobeAISystem.cs
Patryk26g File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -330,17 +330,26 @@ 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; | ||
} | ||
|
||
// Even if we are out of ATP and there is microbe nearby, engulf them. | ||
// make sure engulfing doesn't kill the cell. The cell won't engulf if it would kill it | ||
if (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, true, | ||
atpLevel)) | ||
return; | ||
Patryk26g marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if (ai.ATPThreshold > MathUtils.EPSILON) | ||
{ | ||
if (compounds.GetCompoundAmount(Compound.ATP) < | ||
compounds.GetCapacityForCompound(Compound.ATP) * ai.ATPThreshold) | ||
if (atpLevel < compounds.GetCapacityForCompound(Compound.ATP) * ai.ATPThreshold) | ||
{ | ||
bool outOfSomething = false; | ||
foreach (var compound in compounds.Compounds) | ||
|
@@ -467,6 +476,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 | ||
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) | ||
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. Wouldn't it be cleaner to not split out the |
||
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 +522,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 | ||
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 +891,14 @@ 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; | ||
|
||
control.EnterEngulfModeForcedState(ref health, ref compoundStorage, entity, Compound.ATP); | ||
|
||
ai.TargetPosition = target; | ||
control.LookAtPoint = ai.TargetPosition; | ||
if (CanShootToxin(ourCompounds, speciesFocus)) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I think this comment line is pretty unclear and either should be removed or reworded.