Opened 14 years ago

Closed 13 years ago

Last modified 8 years ago

#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 Kieran P)

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)

animalAI.patch (16.7 KB ) - added by Badmadblacksad 14 years ago.
AnimalAIm-06-02-2010.patch (25.0 KB ) - added by Badmadblacksad 13 years ago.
AnimalAImm-16-02-2011.patch (33.0 KB ) - added by Badmadblacksad 13 years ago.

Download all attachments as: .zip

Change History (17)

by Badmadblacksad, 14 years ago

Attachment: animalAI.patch added

comment:1 by Philip Taylor, 14 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.

comment:2 by (none), 14 years ago

Milestone: Unclassified

Milestone Unclassified deleted

comment:3 by Andrew, 14 years ago

Milestone: Backlog

comment:4 by fabio, 13 years ago

Milestone: BacklogAlpha 3

comment:5 by Kieran P, 13 years ago

Milestone: Alpha 3Alpha 4

comment:6 by Kieran P, 13 years ago

Description: modified (diff)
Priority: minorcritical
Summary: AnimalAIImprove Animal AI

comment:7 by Kieran P, 13 years ago

Type: defectenhancement

by Badmadblacksad, 13 years ago

Attachment: AnimalAIm-06-02-2010.patch added

comment:8 by Badmadblacksad, 13 years ago

Keywords: review added

Here is a new version. Waiting for feedback. tchô :)

comment:9 by Kieran P, 13 years ago

Priority: Must HaveShould Have
Summary: Improve Animal AI[PATCH] Improve Animal AI

comment:10 by Philip Taylor, 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 during FEEDING.enter and is also in range during FEEDING.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 in ROAMING.enter or similar.
  • In ANIMAL.FEEDING.Timer, if Riposte returns false then I think the unit will be stuck in FEEDING 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. Then ANIMAL.COMBAT can be made a reference to INDIVIDUAL.COMBAT by extracting them into a separate var, 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 incremental LosRangeUpdates. So it shouldn't be used in COMBAT for checking the target is still visible - it should look for LosRangeUpdates where the current target is in msg.data.removed
  • ANIMAL doesn't need the ResourceGather 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 into UnitAI, I think it'd be cleaner and more efficient to just put the animal values in the UnitAI 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 a Timer, since there's no timer running in it.
  • Nitpicking:
    • this.behavior should be this.behaviour (since we mostly standardise on en-GB spellings). But actually it should probably just be this.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 be if (msg.data.added.length > 0), and UnitAI.prototype.Riposte should be indented with tabs).
    • template_unit_fauna.xml doesn't need to specify FormationController (it'll inherit the value from template_unit.xml and I think it's preferable to avoid redundancy).

by Badmadblacksad, 13 years ago

Attachment: AnimalAImm-16-02-2011.patch added

comment:11 by Badmadblacksad, 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 Philip Taylor, 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 philip, 13 years ago

Resolution: fixed
Status: newclosed

(In [8995]) # Improve animal AI, based on patch from Badmadblacksad. Fixes #563.

comment:14 by sanderd17, 8 years ago

Keywords: review removed
Note: See TracTickets for help on using tickets.