-
-
Notifications
You must be signed in to change notification settings - Fork 595
Make AI use the signaling agent and add more conditions for responding to commands #6736
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
base: master
Are you sure you want to change the base?
Changes from all commits
224cb54
51c70e1
8d88abe
d5ed2a0
e491f3d
2d9a1c6
a45ef6b
144a74b
4d8bc43
e9f1932
8195e59
ecca883
36de1a4
f5fc4c8
07f62e2
08cbe44
c758755
0920682
74ac805
4c1708e
d471a74
43032a9
16a1d7e
b98eb16
880c09f
6340dba
ef56fc8
66cff35
8ae66c4
3426b61
01abd06
0301823
e1d3cc1
9179fa4
8d134db
9d5b1f8
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 |
|---|---|---|
|
|
@@ -263,16 +263,30 @@ private void ChooseActions(in Entity entity, ref MicrobeAI ai, ref CompoundAbsor | |
|
|
||
| var compounds = compoundStorage.Compounds; | ||
|
|
||
| bool signalExists = signaling.ReceivedCommand != MicrobeSignalCommand.None && | ||
| entity.IsAliveAndHas<WorldPosition>(); | ||
| Vector3 signalerPosition = default; | ||
| float signalerDistanceSquared = default; | ||
|
|
||
| if (signalExists) | ||
| { | ||
| signalerPosition = signaling.ReceivedCommandFromEntity.Get<WorldPosition>().Position; | ||
| signalerDistanceSquared = position.Position.DistanceSquaredTo(signalerPosition); | ||
| } | ||
|
|
||
| // Adjusted behaviour values (calculated here as these are needed by various methods) | ||
| var speciesBehaviour = ourSpecies.Species.Behaviour; | ||
| var adjustBehaviourValues = signaling.ReceivedCommand == MicrobeSignalCommand.BecomeAggressive && | ||
| signalerDistanceSquared < Constants.AI_BECOME_AGGRESSIVE_DISTANCE_SQUARED; | ||
|
Comment on lines
+279
to
+280
Member
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 this needs to check the |
||
|
|
||
| float speciesAggression = speciesBehaviour.Aggression * | ||
| (signaling.ReceivedCommand == MicrobeSignalCommand.BecomeAggressive ? 1.5f : 1.0f); | ||
| (adjustBehaviourValues ? 1.5f : 1.0f); | ||
|
|
||
| float speciesFear = speciesBehaviour.Fear * | ||
| (signaling.ReceivedCommand == MicrobeSignalCommand.BecomeAggressive ? 0.75f : 1.0f); | ||
| (adjustBehaviourValues ? 0.75f : 1.0f); | ||
|
|
||
| float speciesActivity = speciesBehaviour.Activity * | ||
| (signaling.ReceivedCommand == MicrobeSignalCommand.BecomeAggressive ? 1.25f : 1.0f); | ||
| (adjustBehaviourValues ? 1.25f : 1.0f); | ||
|
|
||
| // Adjust activity for night if it is currently night | ||
| // TODO: also check if the current species relies on varying compounds (otherwise it shouldn't react to it | ||
|
|
@@ -297,9 +311,15 @@ private void ChooseActions(in Entity entity, ref MicrobeAI ai, ref CompoundAbsor | |
| if (control.State == MicrobeState.MucocystShield) | ||
| return; | ||
|
|
||
| FleeFromPredators(ref position, ref ai, ref control, ref organelles, ref compoundStorage, entity, | ||
| predator.Value.Position, predator.Value.Entity, speciesFocus, | ||
| FleeFromPredators(ref position, ref ai, ref control, ref organelles, ref signaling, ref compoundStorage, | ||
| entity, predator.Value.Position, predator.Value.Entity, speciesFocus, | ||
| speciesActivity, speciesAggression, speciesFear, strain, random); | ||
|
|
||
| if (organelles.HasSignalingAgent && random.NextSingle() < Constants.AI_SIGNALING_CHANCE) | ||
| { | ||
| signaling.QueuedSignalingCommand = MicrobeSignalCommand.FleeFromMe; | ||
| } | ||
|
|
||
| return; | ||
| } | ||
|
|
||
|
|
@@ -377,8 +397,14 @@ private void ChooseActions(in Entity entity, ref MicrobeAI ai, ref CompoundAbsor | |
| ai.ATPThreshold = 0.0f; | ||
| } | ||
|
|
||
| // Use signaling agent if I have any with a small chance per think method call | ||
| if (organelles.HasSignalingAgent && random.NextSingle() < Constants.AI_SIGNALING_CHANCE) | ||
| { | ||
| UseSignalingAgent(ref position, ref organelles, speciesAggression, ref signaling, random, ref ourSpecies); | ||
| } | ||
|
|
||
| // Follow received commands if we have them | ||
| if (organelles.HasSignalingAgent && signaling.ReceivedCommand != MicrobeSignalCommand.None) | ||
| if (organelles.HasSignalingAgent && signalExists) | ||
| { | ||
| // TODO: tweak the balance between following commands and doing normal behaviours | ||
| // TODO: and also probably we want to add some randomness to the positions and speeds based on distance | ||
|
|
@@ -390,8 +416,11 @@ private void ChooseActions(in Entity entity, ref MicrobeAI ai, ref CompoundAbsor | |
| // was smelled from | ||
| if (signaling.ReceivedCommandFromEntity.IsAliveAndHas<WorldPosition>()) | ||
| { | ||
| ai.MoveToLocation(signaling.ReceivedCommandFromEntity.Get<WorldPosition>().Position, | ||
| ref control, entity); | ||
| if (signalerDistanceSquared < Constants.AI_MOVE_DISTANCE_SQUARED) | ||
|
Member
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. How small is this distance? The signal is literally meant to bump into other members to make using the binding agent easy for the player, so I don't really agree with this change... |
||
| { | ||
| ai.MoveToLocation(signalerPosition, ref control, entity); | ||
| } | ||
|
|
||
| return; | ||
| } | ||
|
|
||
|
|
@@ -402,9 +431,8 @@ private void ChooseActions(in Entity entity, ref MicrobeAI ai, ref CompoundAbsor | |
| { | ||
| if (signaling.ReceivedCommandFromEntity.IsAliveAndHas<WorldPosition>()) | ||
| { | ||
| var signalerPosition = signaling.ReceivedCommandFromEntity.Get<WorldPosition>().Position; | ||
| if (position.Position.DistanceSquaredTo(signalerPosition) > | ||
| Constants.AI_FOLLOW_DISTANCE_SQUARED) | ||
| if (signalerDistanceSquared > Constants.AI_FOLLOW_DISTANCE_SQUARED && | ||
| signalerDistanceSquared < Constants.AI_MOVE_DISTANCE_SQUARED) | ||
| { | ||
| ai.MoveToLocation(signalerPosition, ref control, entity); | ||
| } | ||
|
|
@@ -419,9 +447,7 @@ private void ChooseActions(in Entity entity, ref MicrobeAI ai, ref CompoundAbsor | |
| { | ||
| if (signaling.ReceivedCommandFromEntity.IsAliveAndHas<WorldPosition>()) | ||
| { | ||
| var signalerPosition = signaling.ReceivedCommandFromEntity.Get<WorldPosition>().Position; | ||
| if (position.Position.DistanceSquaredTo(signalerPosition) < | ||
| Constants.AI_FLEE_DISTANCE_SQUARED) | ||
| if (signalerDistanceSquared < Constants.AI_FLEE_DISTANCE_SQUARED) | ||
| { | ||
| control.SetStateColonyAware(entity, MicrobeState.Normal); | ||
| control.SetMoveSpeed(Constants.AI_BASE_MOVEMENT); | ||
|
|
@@ -525,6 +551,53 @@ private void ChooseActions(in Entity entity, ref MicrobeAI ai, ref CompoundAbsor | |
| } | ||
| } | ||
|
|
||
| private void UseSignalingAgent(ref WorldPosition position, ref OrganelleContainer organelles, | ||
| float speciesAggression, ref CommandSignaler signaling, Random random, ref SpeciesMember ourSpecies) | ||
| { | ||
| var shouldBeAggressive = RollCheck(speciesAggression, Constants.MAX_SPECIES_AGGRESSION, random); | ||
|
Contributor
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. So this, combined with the section below is just deciding whether they should be trying to travel in a group? (Because this is outside specific responses, just passive, right?) I think this would make sense not just for aggressive predators, but also for some Brave prey.
Member
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 looks like it was not marked as solved?
Member
Author
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. Patryk26g told me to not resolve (his) comments as solved myself.
Member
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. You should ask for a review again / comment again mentioning their name to ask for further feedback if a reviewer is not responding in a reasonable amount of time to your further changes (I do know from personal experience that it is easy to miss new changes that were related to a review comment I left). |
||
| var speciesMembers = GetSpeciesMembers(ourSpecies.Species); | ||
|
|
||
| if (organelles.HasBindingAgent) | ||
| { | ||
| signaling.QueuedSignalingCommand = MicrobeSignalCommand.MoveToMe; | ||
|
Member
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 line seems useless so should be deleted (there's no early exit so we always execute the line Or alternatively it could be use some logic to detect when cells would be good to group together and would then set this but only if already in binding mode / going into binding mode, as otherwise it is useless to trigger this signal.
Member
Author
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. Doesn't it make more sense to remove the
Member
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. Well there has to be a some quite common condition to reset the signal as I don't want the AI to be entirely made so that it is assumed that there's almost always a signal. It is better for signals to only be sent occasionally so that the AI just doesn't become a total mess where it is always just forced to respond to other signals. Also for safety I think most "non-urgent" signals should not be activated if the current cell is receiving another signal as that just adds to the signal noise. |
||
| } | ||
|
|
||
| if (shouldBeAggressive) | ||
| { | ||
| foreach (var organelle in organelles.Organelles!) | ||
| { | ||
| // Has pili or toxins | ||
| if (organelle.Definition.HasPilusComponent || organelles.AgentVacuoleCount > 0) | ||
| { | ||
| var membersNearEnough = 0; | ||
| var enoughMembers = (int)speciesAggression / 100; | ||
|
|
||
| foreach (var member in speciesMembers!) | ||
| { | ||
| if (position.Position.DistanceSquaredTo(member.Position) | ||
| < Constants.AI_BECOME_AGGRESSIVE_DISTANCE_SQUARED) | ||
| { | ||
| ++membersNearEnough; | ||
| } | ||
| } | ||
|
|
||
| if (membersNearEnough >= enoughMembers) | ||
| { | ||
| signaling.QueuedSignalingCommand = MicrobeSignalCommand.BecomeAggressive; | ||
| break; | ||
| } | ||
|
|
||
| signaling.QueuedSignalingCommand = MicrobeSignalCommand.FollowMe; | ||
| break; | ||
| } | ||
|
|
||
| signaling.QueuedSignalingCommand = MicrobeSignalCommand.None; | ||
|
Comment on lines
+570
to
+594
Member
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 loop looks very suspicious to me. I think instead what you actually want to do is first setup variables for pilus count, and then do a count of pili, and only then would you do the membersNearEnough calculation as that's an expensive calculation to do each loop iteration so I'm quite sure you didn't meant to put that logic inside this loop. |
||
| } | ||
| } | ||
|
|
||
| signaling.QueuedSignalingCommand = MicrobeSignalCommand.None; | ||
| } | ||
|
|
||
| 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, | ||
|
|
@@ -925,8 +998,8 @@ private void PursueAndConsumeChunks(ref WorldPosition position, ref MicrobeAI ai | |
| } | ||
|
|
||
| private void FleeFromPredators(ref WorldPosition position, ref MicrobeAI ai, ref MicrobeControl control, | ||
| ref OrganelleContainer organelles, ref CompoundStorage compoundStorage, in Entity entity, | ||
| Vector3 predatorLocation, Entity predatorEntity, float speciesFocus, float speciesActivity, | ||
| ref OrganelleContainer organelles, ref CommandSignaler signaling, ref CompoundStorage compoundStorage, | ||
| in Entity entity, Vector3 predatorLocation, Entity predatorEntity, float speciesFocus, float speciesActivity, | ||
| float speciesAggression, float speciesFear, float strain, Random random) | ||
| { | ||
| var ourCompounds = compoundStorage.Compounds; | ||
|
|
@@ -987,13 +1060,19 @@ private void FleeFromPredators(ref WorldPosition position, ref MicrobeAI ai, ref | |
| } | ||
|
|
||
| // If prey is confident enough, it will try and launch toxin at the predator | ||
| // and send follow me command if it has signaling agent and the chance hits | ||
| if (speciesAggression > speciesFear && | ||
| position.Position.DistanceSquaredTo(predatorLocation) > | ||
| 300.0f - (5.0f * speciesAggression) + (6.0f * speciesFear) && | ||
| RollCheck(speciesAggression, Constants.MAX_SPECIES_AGGRESSION, random)) | ||
| { | ||
| LaunchToxin(ref control, ref organelles, ref position, predatorLocation, ourCompounds, speciesFocus, | ||
| speciesActivity); | ||
|
|
||
| if (organelles.HasSignalingAgent && random.NextSingle() < Constants.AI_SIGNALING_CHANCE) | ||
| { | ||
| signaling.QueuedSignalingCommand = MicrobeSignalCommand.FollowMe; | ||
| } | ||
| } | ||
|
|
||
| // No matter what, I want to make sure I'm moving | ||
|
|
||
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.
Isn't
entitywrong here? The system should not even run if the entity is dead, so shouldn't this code be checking ifReceivedCommandFromEntityis the one that is alive?