Make AI use the signaling agent and add more conditions for responding to commands#6736
Make AI use the signaling agent and add more conditions for responding to commands#6736
Conversation
AI_SIGNALING_CHANCE is so that it's not used a billion times per second (Thanks to Patryk26g for suggesting to use NextSingle instead of Next) This is only the very beginning of this.
| // Use signaling agent if I have any with a chance of 5% per think | ||
| if (organelles.HasSignalingAgent && random.NextSingle() < Constants.AI_SIGNALING_CHANCE) | ||
| { | ||
| UseSignalingAgent(ref organelles, speciesAggression, ref signaling, ref control, random); |
There was a problem hiding this comment.
It seems like there's only one case where the signalling command is set to None. That means that cells do not stop signalling! That's a very, very major bug in my opinion because eventually I think most cells will just be signalling all the time.
Also I think another key part still missing is that cells should decide to ignore an incoming signalling command in certain situations (like if become aggressive signal is too far away, or a move signal is far away and the cell is not that full on resources).
Without those two things I think the signals will quite effectively destroy any useful AI behaviours as they'll get permanently locked into following the signal of the first species member of them that triggered it.
There was a problem hiding this comment.
Do you have suggestions for when it should be set to no command?
There was a problem hiding this comment.
I'd say whenever the original condition to set a signal is gone, or like after 15-30 seconds of the cell not feeling like it should send the same signal again. Something like that, but I'm sure someone else more familiar with the AI could come up with a more advanced codnitions.
Hopefully this is only a temporary workaround.
|
Upon reading the latest commit it does seem a bit better. It seems the flee signal would now get emitted, it does still seem that the other signals are very easy to overwrite with the non-command. But I think this might be about ready for playtesting. |
| else | ||
| { | ||
| signalExists = false; | ||
| } |
There was a problem hiding this comment.
is this "else" needed? can do without it, just make "bool signalExists = signaling.ReceivedCommand != MicrobeSignalCommand.None && entity.IsAliveAndHas()". Btw what is " entity.IsAliveAndHas()" used for? Shouldn't it be "signaling.ReceivedCommandFromEntity.IsAliveAndHas()"?
There was a problem hiding this comment.
Btw what is " entity.IsAliveAndHas()" used for?
It's so that the game doesn't crash when there isn't a signal.
There was a problem hiding this comment.
This else still should be removed... it literally if signal == false then signal = false
| private void UseSignalingAgent(ref OrganelleContainer organelles, float speciesAggression, | ||
| ref CommandSignaler signaling, Random random) | ||
| { | ||
| var willBeAggressiveThisTime = RollCheck(speciesAggression, Constants.MAX_SPECIES_AGGRESSION, random); |
There was a problem hiding this comment.
willBeAggressiveThisTime -> shouldBecomeAggresive
There was a problem hiding this comment.
Personally, I think that's an inaccurate name considering what the variable is being used for.
There was a problem hiding this comment.
As I said in other comment, future tense variables should be omitted.
| signaling.QueuedSignalingCommand = MicrobeSignalCommand.None; | ||
| } | ||
| } | ||
| else |
There was a problem hiding this comment.
I guess it is right now, but since I want to add more sub-conditions I'll keep it.
There was a problem hiding this comment.
Are you going to do this in this PR? If not, then you should remove it. YAGNI
There was a problem hiding this comment.
Yes, I'm gonna do it in this PR.
There was a problem hiding this comment.
So there was unimplemented stuff? Good thing that I didn't spend any more review energy yet...
|
|
||
| // Adjusted behaviour values (calculated here as these are needed by various methods) | ||
| var speciesBehaviour = ourSpecies.Species.Behaviour; | ||
| var willAdjustBehaviourValues = signaling.ReceivedCommand == MicrobeSignalCommand.BecomeAggressive && |
There was a problem hiding this comment.
I think we should omit future tense in variables... adjustBehaviourValues is fine. or event better "shouldBeAggresive"
There was a problem hiding this comment.
You know, I never thought about it, but you are right that future tense is not used in variable names customarily. So yeah, this sounds like a good naming change, and I would definitely have named this variable something along the lines of needsToAdjustBehaviour.
| bool signalExists = signaling.ReceivedCommand != MicrobeSignalCommand.None && | ||
| entity.IsAliveAndHas<WorldPosition>(); | ||
| Vector3 signalerPosition = default; | ||
| float squaredDistanceToSignaler = default; |
There was a problem hiding this comment.
squaredDistanceToSignaler -> signalerDistanceSquared
| ai.ATPThreshold = 0.0f; | ||
| } | ||
|
|
||
| // Use signaling agent if I have any with a small chance per think |
There was a problem hiding this comment.
Is this supposed to be "per tick"?
There was a problem hiding this comment.
I hope not because we do not have "ticks" in the game (the closest concept we have is a game simulation update)...
There was a problem hiding this comment.
I do mean "think", as in each time AIThink() is called. I guess it should say "per update", then?
There was a problem hiding this comment.
I think "per think" is perfectly understandable, and I have a feeling that there are existing comments that are of similar format. But for clarity it could be written as "per think method call".
| private void UseSignalingAgent(ref OrganelleContainer organelles, float speciesAggression, | ||
| ref CommandSignaler signaling, Random random) | ||
| { | ||
| var shouldBeAggressive = RollCheck(speciesAggression, Constants.MAX_SPECIES_AGGRESSION, random); |
There was a problem hiding this comment.
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.
Brief Description of What This PR Does
This PR makes the microbe AI use the signaling agent and adds more conditions for responding to commands.
Related Issues
Closes #5118
Discussion: https://forum.revolutionarygamesstudio.com/t/how-should-ai-use-the-signaling-agent/1233
Progress Checklist
Note: before starting this checklist the PR should be marked as non-draft.
break existing features:
https://wiki.revolutionarygamesstudio.com/wiki/Testing_Checklist
(this is important as to not waste the time of Thrive team
members reviewing this PR)
styleguide.
Before merging all CI jobs should finish on this PR without errors, if
there are automatically detected style issues they should be fixed by
the PR author. Merging must follow our
styleguide.