Blah
Free supporter
- 1,924
- Posts
- 12
- Years
- Unknown Island
- Seen Feb 19, 2025
Battle engine
Hello, I created this project because I didn't like the way that generation III's battle engine by GameFreak was programmed in an algorithmic sense. I find it very inefficient, cluttered, and hard to modify as a ROM hacker. The idea of having an updated engine with C source code is very appealing and as such I've made this project. Contributions are welcomed and encouraged! Feel free to ask for any help you may need.
How it works
First of all here's a Youtube video explaining, if you prefer that. A shorter text version will follow incase you don't wish to watch the video.
Spoiler:
GameFreak's battle engine has it's checks and edge cases card coded directly into the engine which leads to some sloppy code. I seek to improve upon this by pushing responsibility of edge case handing to the moves themselves and having the engine be just a skeleton in which to run moves. You can think of it like a T.V (the base engine) which plays DVDs (moves).
To do that, I've basically allowed moves to "interrupt" the normal chain of events which looks like this:
1) Check faster Pokemon
2) Faster Pokemon try to use move (accuracy checks ect.)
3) Calc damage
3) Apply dmg + recoil + drain
4) Do effect - status moves effects like baton pass for example
5) Apply secondary ailments/stat boosts from move
6) Start from 2) but with second Pokemon
Basically a certain place in these steps (which are actually many smaller steps), the battle engine will check to see if the move has something called a callback which it wants to execute at that point in time. A callback, in this context, is essentially a function which the main engine is going to call and execute. The callback is written from the move with no context of what's happening in the engine itself other than time of execution.
Some of these move callbacks are:
- before_turn
- before_switch
- on_start
- before_move
- on_move_fail
- on_modify_move
- on_tryhit_move
- on_inv_tryhit_move
- on_tryhit_side_move
- on_base_power_move
- on_damage_move
- on_effect_cb
- on_after_move
For specifics on when they run refer to the video. Names are kind of self explanatory. These callbacks are included as fields inside the move table for this engine, similar to PP, Accuracy and Base power for example.
Moves remaining to be done
You can find a list of them categorized over here:
https://github.com/EternalCode/battle_engine/issues
If you're just starting out, or have no programming experience, the moves under the "Easy Difficulty" section are still very possible for you!
Quick Guide to Building
I made a quick video to show someone how to build and get your hands on the project. The Readme.md file for the project is essentially a text version of the video I'm posting. I've done it in video format for those who requested it.
Link to Readme:
https://github.com/EternalCode/battle_engine/blob/master/README.md
Vid:
Spoiler:
Last edited: