Author Topic: Enemy AI needs better documentation. (research thread)  (Read 9896 times)

Mauron

  • Guru of Reason Emeritus
  • Errare Explorer (+1500)
  • *
  • Posts: 1764
  • Nu-chan
    • View Profile
    • Maurtopia
Enemy AI needs better documentation. (research thread)
« on: June 22, 2008, 11:34:22 am »
I know that more is known than the little covered in the encyclopedia, but I don't know how much. Let's put our heads together and fix it up a little.

jsondag2 has begun an AI editor with the information found here.

http://jpsondag.com/CE/AI/

Relevant sections of the encyclopedia:

http://www.chronocompendium.com/Term/Enemy_AI.html
http://www.chronocompendium.com/Term/Enemy_AI_Listings.html
http://www.chronocompendium.com/Term/Attacks.html

Edit: Copied actions into here. I'm going to keep this post updated from now on.

Edit 2: Link to AI editor, not going to keep editing this post now that the encyclopedia's being updated.

Edit 3: Added Encyclopedia links.
« Last Edit: July 11, 2008, 01:43:52 pm by Mauron »

Agent 12

  • Zurvan Surfer (+2500)
  • *
  • Posts: 2572
    • View Profile
Re: Enemy AI needs better documentation.
« Reply #1 on: June 22, 2008, 01:45:03 pm »
This is a fantastic thread I plan on eventually making an editor for this so the more info the better.

Jp

Mauron

  • Guru of Reason Emeritus
  • Errare Explorer (+1500)
  • *
  • Posts: 1764
  • Nu-chan
    • View Profile
    • Maurtopia
Re: Enemy AI needs better documentation.
« Reply #2 on: June 22, 2008, 03:30:55 pm »
I look forward to seeing your editor. Side note: The tech editor could benefit from the ability to export .Tech files containing the tech's data (Think .Flux files).

Actions are going to be trickier, since they have variable lengths. I'm assuming each command is identified by one byte.
Code: [Select]

00 00 06 00 - Seems to be assigned to most, if not all enemies. Purpose unknown.
01 ?? ?? ?? - Physical attack.
02 AA 00 - Use attack AA. Add 00 00 BB to display text BB. 00s unexplored.

All enemies have two sections, in separated by FE FF. They seem functionally identical.

Edit: Added 01 command.

Edit 2: Removed comment on physical attack relating to counterattack - Was not able to reproduce.
« Last Edit: June 22, 2008, 09:17:25 pm by Mauron »

Agent 12

  • Zurvan Surfer (+2500)
  • *
  • Posts: 2572
    • View Profile
Re: Enemy AI needs better documentation.
« Reply #3 on: June 30, 2008, 11:08:21 pm »
ok turns out that i've been parsing the data incorrectly you'll have to wait a bit for an editor :)

So ....how do we parse this....

Is it something along the lines of

-----Default---------              ------------Counter ----------------
XXXXXXXXXXXXXXX FE FF  YYYYYYYYYYYYYYYYYYYYY

with XXXXXXXXXX and YYYYYYYYYY having the form:

pre_condition_1  FE  action_1   FE     pre_condition_2  FE action_2   .... FE pre_cointion_n FE action_  n FE FF


For now i'm giong to treat all FE's as state switchers between pre_conditions and actions.  This could cause a bug if FE is used as a parameter but it's impossible to tell unless we know the lengths of each command.


--JP

Mauron

  • Guru of Reason Emeritus
  • Errare Explorer (+1500)
  • *
  • Posts: 1764
  • Nu-chan
    • View Profile
    • Maurtopia
Re: Enemy AI needs better documentation.
« Reply #4 on: July 01, 2008, 12:03:34 am »
I'll wait.

I tried reversing the two AI sections on a Blue Imp and it attacked normally, but remained stationary.

As for FE and FF, using them as values for the 02 command kept it functioning normally.

JLukas

  • Fan Project Leader
  • Squaretable Knight (+400)
  • *
  • Posts: 426
    • View Profile
Re: Enemy AI needs better documentation.
« Reply #5 on: July 01, 2008, 04:11:38 am »
Gato:

00000000FE Header

01000501 Use normal attack 00 on random PC, unknown 01
00000606 Skip turn, wander mode?
021005000000FEFF  Use tech 10 singing attack on random PC

1F06000FE If attacked (any attack - physical, tech, magic)
   If within attack range
      01010600FE Use normal attack 01 on nearest PC, unknown 00

   Else
      00000000FE No action
      0F03FEFF Display textbox, index 03 "Too far away to counterattack."

edit: updated
edit: updated again
« Last Edit: July 01, 2008, 08:44:44 am by JLukas »

Vehek

  • Errare Explorer (+1500)
  • *
  • Posts: 1756
    • View Profile
Re: Enemy AI needs better documentation.
« Reply #6 on: July 01, 2008, 04:19:07 am »
I suspect things like the 00000606 are used for moving around. (Waddler labeled "00" as "no attack" and put it with the physical attack command.)

JLukas

  • Fan Project Leader
  • Squaretable Knight (+400)
  • *
  • Posts: 426
    • View Profile
Re: Enemy AI needs better documentation.
« Reply #7 on: July 01, 2008, 08:31:06 am »
Something important to point out is how the data relates to what is happening on screen.  With the Gato example, once it's attack meter is full, it performs the first attack.  The meter refills, then Gato skips a turn and wanders around until it's next turn, the singing attack.  Then the whole section repeats.

$5F Rubble is another intersting example.  It starts off with the Lock All action, then the Rubble sits idle 6 turns until running away.  The 3 byte run away command is 0A 93 48.  93 is a special animation, and 48 is the index for the textbox string "Runs Away!"

For creating an editor:

Start by reading the initial header as variable length until you hit FE.

Then decode commands with the lengths on the AI page.  When you hit FE that marks the end of the section, and when you hit FE FF, that marks the end of a bigger section of code.
« Last Edit: July 05, 2008, 04:01:19 pm by JLukas »

Agent 12

  • Zurvan Surfer (+2500)
  • *
  • Posts: 2572
    • View Profile
Re: Enemy AI needs better documentation.
« Reply #8 on: July 01, 2008, 11:41:53 am »
JLukas that is exactly what I needed!

Thanks for going through all that work, I have a couple more questions that I'd like to ask before I hammer down a UI.

a)  Is there one action for precondition or can one precondition result in multiple actions in a row for example
 0000 FE action_1 action_2 action_3 FE FF

Would action_1, action_2, action_3 be done in  row.....even if another condition became true...so essentially the enemy is stuck in this group.  Based off the example I sent you it seems like they are done in order, however that would require some sort of pointer/counter being used that noone has mentioned.

b)  Does the enemy start reading off conditions sequentially until it finds one that is true and then ignore the following conditions.  For example

condition_1 FE action_1 FE condition_2 FE action_2

Even if condition_1 and condition_2 are both true action_1 is done because it is first.


thanks again for all your help!

EDIT:

Thought of a couple more

c)  Is there always only two "big section" waddler seemed to think that it was "regular" and 'counter' sections.  Would you say based off the way the AI is loaded that it loaded something like this:

if(attacked)
   Load second big section
   if(!(any big section conditions are true))
   {
        Load first section
    }
else
Load first section

So it basically checks the second section first ONLY if they have been attacked.

d)  Just to clarify my post above was correct with the FE command switching between conditions/actions.  So a big section can be composed of multiple if statements?


---JP
« Last Edit: July 01, 2008, 11:46:43 am by jsondag2 »

Agent 12

  • Zurvan Surfer (+2500)
  • *
  • Posts: 2572
    • View Profile
Re: Enemy AI needs better documentation.
« Reply #9 on: July 01, 2008, 01:05:25 pm »
OK,

I'm late for work but I wanted to show you guys the little bit of progress I made.

Don't get to excited this thing doesn't even save yet but it does successfully load Gato (that's all the debugging I've done on it haha).

It'll probably crash if we hit a "variable length" command or a command that we dont know the length of.

http://jpsondag.com/CE/AI/

Download those two things into the same folder and you can run the AI editor er..viewer haha.  I'll work on saving later.  I tried to keep the same interface as the Tech editor.   Load up an unheadered rom, select the enemy from the drop down list.  It'll show somethign like

Condition1
Condition2
SectionEnd
Condition1

You can expand the conditions to see the actions for that condition.
 

Enjoy :)

It'll be alot better if we can figure out the other length of the commands.  I have to figure out a method for doing the variable length commands.  I did alot of copy/pasting from the tech editor but the interface I have set up is not very accomodating for variable length tree nodes....i'll see what I can do.


--JP

Agent 12

  • Zurvan Surfer (+2500)
  • *
  • Posts: 2572
    • View Profile
Re: Enemy AI needs better documentation.
« Reply #10 on: July 01, 2008, 02:45:44 pm »
I updated the Enemy AI page to make it more concise and add new info to it.  The old page is preserved on the page (it links to the old stuff).

Hope I didn't offend anyone it was just alot of info to sift through.

http://www.chronocompendium.com/Term/Enemy_AI.html


EDIT:

OK i seriously have to start working after this.  but I thought I'd show you guys an organized golem incase yous ee something I dont:

23 01 03 37 FE         //conditions intrigue me here....
00 00 06 05             //set wander mode
02 2A 05 00 00 00   //spell
00 00 06 05            //set wander mode
02 51 05 00 00 00   //spell
00 00 06 05            //set wanter mode
FE

24 02 03 37 FE       //conditions intrigue me here
00 00 06 05                  //wander mode
02 25 05 00 00 00         //spell
00 00 06 05                 //wander mode
02 54 05 00 00 00        //spell
00 00 06 05                 //wander mode
FE

25 03 03 37 FE            //conditions intrigue me here
00 00 06 05                   //wander mode
02 47 05 00 00 00         //spell
FE

26 04 03 37 FE         //conditions intrigue me here
00 00 06 05                    //set wander mode
02 27 05 00 00 00           //spell
FE

00 00 00 00 FE
02 41 05 00 00 58            //spell with text?
02 80 05 00 00 00            //spell
FE FF



20 00 00 00 FE              //final attack "blurp copying Dalton"
02 5D 05 00 00 75 FE

15 20 00 00 FE                               //elemental counter  Ice
11 37 01 37 01 37 01 37 01 D9 FE

15 10 00 00 FE                               //elemental counter fire
11 37 02 37 02 37 02 37 02 DA FE

15 40 00 00 FE                               //elemental counter 40 shadow
11 37 03 37 03 37 03 37 03 D8 FE


15 80 00 00 FE                               //elemental counter lightning
11 37 04 37 04 37 04 37 04 D7 FE

00 00 00 00 FE                               //if alive
11 37 0A 37 0A 37 0A 37 0A 4A FE FF

Whats interesting is the conditions before the FE/FF....

Not only does the first byte increment but the second one as well.  I'm wondering if maybe what were looking at here is the link between the "counter" mode and the reguar mode (left side of FE FF and right side of FE FF).  I'm pretty sure that when you fight golem if you hit him with fire he continuously uses fire spells back at you?  so I feel like something must be set somewhere so he remembers?


---JP
« Last Edit: July 01, 2008, 03:06:46 pm by jsondag2 »

Agent 12

  • Zurvan Surfer (+2500)
  • *
  • Posts: 2572
    • View Profile
Re: Enemy AI needs better documentation.
« Reply #11 on: July 01, 2008, 10:59:51 pm »
OK,

I updated the link above to the AI editor.  Still no saving :(

Sorry, it took longer than I thought to add all the commands that are on the wiki.  I few notes:


I put 01 XX YY ZZ as "attack" i'm pretty sure that's what it is since some enemies only have that command so it must  have sometthing to do with attack right?

I'd say the big ones right now are:

Confirming

conditions:

07 XX YY ZZ
17 XX YY ZZ

attacks:

Figure out how long 04 is.  I have definately seen it a few times.

Tomorrow I'll try to do saving I promise

--JP

Mauron

  • Guru of Reason Emeritus
  • Errare Explorer (+1500)
  • *
  • Posts: 1764
  • Nu-chan
    • View Profile
    • Maurtopia
Re: Enemy AI needs better documentation.
« Reply #12 on: July 01, 2008, 11:20:25 pm »
02 41 05 00 00 58            //spell with text?
Correct, that last byte represents the text displayed. It's one of the things I've tested most.

0A XX YY - Retreat using attack XX, displaying text YY. It's listed as Disable right now.

I'll examine the Golem AI later.

JLukas

  • Fan Project Leader
  • Squaretable Knight (+400)
  • *
  • Posts: 426
    • View Profile
Re: Enemy AI needs better documentation.
« Reply #13 on: July 02, 2008, 09:52:23 am »
Some updates:

First, it seems that the initial header for ALL enemies is only 4 bytes (before the FE byte)  With 00 00 00 00 FE enemies, like Gato, there is only 1 section of actions before the FE FF.

Next, take a look at enemy $05 Hench.  The initial header is 17 10 00 00 FE.
Then there's three sets of action patterns:
1) Use tech 45, textbox 2C, - Crimson Rain HP down
FE
2) No action
FE
3 Wander, attack, wander
Then it hits the FE FF end.

It appears to me that the 17 in the initial header means that it selects a random pattern, and the 10 is a % chance for using the first pattern.

I'm not sure why Golem has multiple headers highlighted in red above but it is worth pointing out that first and second bytes increment for each header.

Yep, 0A is Run away/retreat.

jsondag, you might want to label everything before the FE FF as "Action" and everything after "Reaction"

Agent 12

  • Zurvan Surfer (+2500)
  • *
  • Posts: 2572
    • View Profile
Re: Enemy AI needs better documentation.
« Reply #14 on: July 02, 2008, 11:51:07 am »

Quote
I'm not sure why Golem has multiple headers highlighted in red above but it is worth pointing out that first and second bytes increment for each header.

Ha ha great minds think alike :)
Quote
Whats interesting is the conditions before the FE/FF....

Not only does the first byte increment but the second one as well.

I personally think that the red sections somehow connect the Action and Reaction part.  Simply because I recall the fight with Golem being along the lines of you hit him with fire and he continuously responds by casting "fire related" techs.  Which means the action part remembers you hit him with fire.

Of it could be something much simpler like "if last element used was"

Hm...we need a better name for  action for the action/reaction sections because I have been referring to "XXXX FE YYYY" as condition -> action.   Normal?

JLukas I know you and geiger did alot of work on strings, do you have a list of these somewhere?  Something I can copy/paste into the program so I can give them a drop down?  I won't make it editable cause if TF can't already edit the then I'm sure it will soon. 

Also have you noticed where it is pulling the tech index from? If we can go backtrace the index i'll be able to add enemies to the Tech editor relatively easy.

--JP