#563 closed enhancement (fixed)
[PATCH] Improve Animal AI
Reported by: | Badmadblacksad | Owned by: | |
---|---|---|---|
Priority: | Should Have | Milestone: | Alpha 4 |
Component: | UI & Simulation | Keywords: | ai, animal |
Cc: | Patch: |
Description (last modified by )
We have passive, idle, and skittish.
Add violent, aggressive and defensive behaviors to animalAI.js
Possibly generalize the code so it can be applied to opponent AI (#707)
Attachments (3)
Change History (17)
by , 14 years ago
Attachment: | animalAI.patch added |
---|
comment:1 by , 14 years ago
Keywords: | review removed |
---|
comment:3 by , 14 years ago
Milestone: | → Backlog |
---|
comment:4 by , 13 years ago
Milestone: | Backlog → Alpha 3 |
---|
comment:5 by , 13 years ago
Milestone: | Alpha 3 → Alpha 4 |
---|
comment:6 by , 13 years ago
Description: | modified (diff) |
---|---|
Priority: | minor → critical |
Summary: | AnimalAI → Improve Animal AI |
comment:7 by , 13 years ago
Type: | defect → enhancement |
---|
by , 13 years ago
Attachment: | AnimalAIm-06-02-2010.patch added |
---|
comment:8 by , 13 years ago
Keywords: | review added |
---|
Here is a new version. Waiting for feedback. tchô :)
comment:9 by , 13 years ago
Priority: | Must Have → Should Have |
---|---|
Summary: | Improve Animal AI → [PATCH] Improve Animal AI |
comment:10 by , 13 years ago
Thanks, this looks mostly sensible to me :-) . But I see some issues:
- What is
ANIMAL.FEEDING.Timer
trying to do? It looks like it's finding the first entity which was in range duringFEEDING.enter
and is also in range duringFEEDING.Timer
, and then attacks it if it's a valid target and otherwise doesn't attack anything (even if the second entity is a good target); but I'm not sure why it's doing all that, instead of just doing a single check inROAMING.enter
or similar. - In
ANIMAL.FEEDING.Timer
, ifRiposte
returns false then I think the unit will be stuck inFEEDING
forever. - Duplicating most of the
COMBAT
logic doesn't seem nice. It looks like the main difference is checking that the target is still visible - probably we should make normal units do the same check, so it doesn't need to be animal-specific. ThenANIMAL.COMBAT
can be made a reference toINDIVIDUAL.COMBAT
by extracting them into a separatevar
, or by using sharp variables. ResetActiveQuery
is relatively expensive (since it has to return the list of every single entity in range) - the purpose of active queries is that you don't need to repeatedly compute them, you just need to reset them once then listen for incrementalLosRangeUpdate
s. So it shouldn't be used inCOMBAT
for checking the target is still visible - it should look forLosRangeUpdate
s where the current target is inmsg.data.removed
ANIMAL
doesn't need theResourceGather
handler (you can't gather resources until the animal has been killed, since we implemented hunting).- The
AnimalAI
changes from r8899 and r8900 need to be merged in. (I suppose that's my fault since I committed them after this patch :-p ) - Rather than keeping a separate
AnimalAI
and copying the values intoUnitAI
, I think it'd be cleaner and more efficient to just put the animal values in theUnitAI
schema instead. (Probably put them inside an<optional><interleave> ... </interleave></optional>
block so that they can all be omitted, for non-animal units). (Efficiency matters a little because the template values copied into the UnitAI component will be serialised for saved games and sync-checking. Not a major concern, but it's nicer to avoid the redundancy and access the template directly instead of copying values.) FLEEING
shouldn't need aTimer
, since there's no timer running in it.- Nitpicking:
this.behavior
should bethis.behaviour
(since we mostly standardise on en-GB spellings). But actually it should probably just bethis.template.NaturalBehaviour
, given the previous comment about not copying values from templates.- Whitespace should be consistent with the existing code (e.g.
if(msg.data.added.length>0)
should instead beif (msg.data.added.length > 0)
, andUnitAI.prototype.Riposte
should be indented with tabs). template_unit_fauna.xml
doesn't need to specifyFormationController
(it'll inherit the value fromtemplate_unit.xml
and I think it's preferable to avoid redundancy).
by , 13 years ago
Attachment: | AnimalAImm-16-02-2011.patch added |
---|
comment:11 by , 13 years ago
Hello. I tried to correct the things that Philip pointed out. COMBAT mode is still duplicate, I didn't manage to do better for now.
comment:12 by , 13 years ago
Thanks again! I think this looks like an improvement. There's a few small changes I've made:
If a unit is owned by a non-Gaia player (which we'll probably want to support so players can capture animals and make them walk around), some orders will switch it to the INDIVIDUAL
state and it'll forget to be an animal. I made it ignore walk orders, and made it unable to garrison, and I think no other orders will be possible (since animals won't have ResourceGatherer
or Builder
) so hopefully it's okay now.
LeaveFoundation
needed to be Order.LeaveFoundation
.
I changed the FSM system so the COMBAT
sub-state can be shared by animals (and gave animals an IDLE
so that FinishOrder
works).
The LosRangeUpdate
stuff seems a bit unreliable since it's only triggered when a unit enters the range; if two units enter, an aggressive animal will attack one and then never notice the second (unless it leaves and re-enters range). But that's probably okay for now.
Instead of having SetupRangeQuery
handle owner == 0
specially, I changed the setup code so Gaia is a diplomatic enemy of everybody, since that seems a bit cleaner.
comment:13 by , 13 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:14 by , 8 years ago
Keywords: | review removed |
---|
Thanks, this looks good. My only concern is the growing duplication between AnimalAI and UnitAI - that was originally my fault, and this increases it, and we'll need more once players can capture units and give them move orders. Unless I'm missing some major problem (or some nicer way to manage the complexity), I think it'll be better in the long term to merge the animal behaviour into UnitAI (probably as an extra state group alongside FORMATIONCONTROLLER/FORMATIONMEMBER/INDIVIDUAL) so it can share all the basic functions. Applying this patch will add some complexity and make it harder to merge later, so I'd prefer them to be merged first.