• Our software update is now concluded. You will need to reset your password to log in. In order to do this, you will have to click "Log in" in the top right corner and then "Forgot your password?".
  • Forum moderator applications are now open! Click here for details.
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.

Research: Trainer AI in Firered

Deokishisu

Mr. Magius
989
Posts
18
Years
The routine that determines if the AI will switch is located at 08039C84, with the actual thinking happening at 08039A80. I have no idea how it works.


The routine that determines if the AI will use an item is located at 0803A1F4. It will identify the type of item at 0803A198:
Code:
1	full restore
2	heal hp
3	restore status	
4	increase stat	
5	guard spec		
6	other
(see http://www.pokecommunity.com/showpost.php?p=6745155&postcount=11 for more info on battle items).
Then, it will run checks based on the type of item - 1 (see the jump table at 0803A304). For example, it will use a full restore if the hp of the poke is less than 25% of its max hp.


If anyone wants to analyse those routines further, please do.

I find it interesting that the AI will attempt to use a Revival Herb (fruitlessly) if given one. Which check do you suppose allows for this? I would assume it's either heal hp, restore status, or other. It'd be interesting to see the logic that the game goes through to select a Revival Herb to use, with the obvious end goal being hacking the AI or battle scripts so that Revive-like items actually function for computer opponents. But damn, will that functionality be a nightmare for players when used by the wrong hackers.
 

daniilS

busy trying to do stuff not done yet
409
Posts
10
Years
  • Age 24
  • Seen Jan 29, 2024
I find it interesting that the AI will attempt to use a Revival Herb (fruitlessly) if given one. Which check do you suppose allows for this? I would assume it's either heal hp, restore status, or other. It'd be interesting to see the logic that the game goes through to select a Revival Herb to use, with the obvious end goal being hacking the AI or battle scripts so that Revive-like items actually function for computer opponents. But damn, will that functionality be a nightmare for players when used by the wrong hackers.

I think it gets passed of as heal hp, just check the flags. Coding that in is in my plans.
 

FIQ

251
Posts
11
Years
  • Seen Sep 15, 2022
Script 31 isn't unused, it's likely used in the RSE poochyena/zigzagoon fight to make it flee if your HP is low.
 

Criminon

Forever Spriting
265
Posts
11
Years
Hmm. Unable to use my asm insertion program to insert it at that address, so I just looked for free space, copied down the code that it produced. (084B58224243D21820321278914203D0002806D10220F3E7034A12689269203211547047E43B0202F43F0202) and then pasted this over the information at that address, but it keeps freezing. Where exactly does the original code end?


Edit: I'm an idiot. Working as intended. Thanks so much!
 
Last edited:
30
Posts
19
Years
  • Seen Apr 21, 2020
Sorry for this being a bit of a bump, but I noticed that one of the "trainer" AI scripts is that of the roaming/running Pokemon...does this mean that Pokemon such as Entei, Latios, etc (or really, anything) have an "AI value" as well that gets set to this? Does this only control its running behavior, or also the roaming behavior as well? This obviously isn't used for trainer battles, so I'm curious how this actually -is- applied in practice, potentially to create new roaming/fleeing encounters.

Also, are the values here the same as they would be in Emerald, minus the addresses? I know you mentioned Emerald having a bug fix, but other than that I would be able to use this at least as a reference? Thanks so much!
 

daniilS

busy trying to do stuff not done yet
409
Posts
10
Years
  • Age 24
  • Seen Jan 29, 2024
Sorry for this being a bit of a bump, but I noticed that one of the "trainer" AI scripts is that of the roaming/running Pokemon...does this mean that Pokemon such as Entei, Latios, etc (or really, anything) have an "AI value" as well that gets set to this? Does this only control its running behavior, or also the roaming behavior as well? This obviously isn't used for trainer battles, so I'm curious how this actually -is- applied in practice, potentially to create new roaming/fleeing encounters.

Also, are the values here the same as they would be in Emerald, minus the addresses? I know you mentioned Emerald having a bug fix, but other than that I would be able to use this at least as a reference? Thanks so much!

The script only makes the pokes flee, and the bit activating it is set if the roaming battle type flag is set.
The scripts should be the same in EM (maybe the unfinished ones are edited though, I haven't checked). I believe the only reason the 'bug fix' got there was because of double battles, where both sides could be the enemy of the ai and required guessing of abilities.
 
Back
Top