• 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?".
  • 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.

Development: New Battle System

Blah

Free supporter
1,924
Posts
11
Years

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:

BLAx501!

Pokemon Flux
80
Posts
10
Years
Hmm, this seems pretty interesting, I can't believe there is no comments in here... I would love to help with this, but although I know some C programming from university, I've never done something like this. If there is anything I can do, I would be happy to help :3
 
Last edited:
15
Posts
9
Years
  • Age 28
  • Seen Nov 20, 2016
I think I can help. My main goto language has been C for years, and I've dabbled in ASM programming, both inside and outside the Pokemon Hacking Community. PM me or reply in the thread if you want my help.
 

Blah

Free supporter
1,924
Posts
11
Years
Hmm, this seems pretty interesting, I can't believe there is no comments in here... I would love to help with this, but although I know some C programming from university, I've never done something like this. If there is anything I can do, I would be happy to help :3

Yeah, I need people to help with programming it as well as someone who has a hobby in creating data tables (for moves like fling). I'd also like to rework some of the existing tables like the ability/move table to have some new entries required for the newer move mechanics. So if you can't help with the Programming side, that part is also available to do :P

I think I can help. My main goto language has been C for years, and I've dabbled in ASM programming, both inside and outside the Pokemon Hacking Community. PM me or reply in the thread if you want my help.

Yes! Help would be awesome.
http://chat.linkandzelda.com:9090/?channels=rh
Join, and see if someone named FBI is online (that's me!). If I'm there type my name in the chat and I'll respond with more info.

This sounds great!

That's 'cause it is great. Imagine having a large ROM mechanic in C source code. You'd be able to get a lot of hacking/expanding/other customization done to the battle engine with fair ease. Battling is arguably the largest make or break feature in hacks, since you spend a large portion of the game battling trainers ect. Hackers also go through a lot of trouble to update battle graphics, and mechanics to keep things fresh.


--

Maybe I'll make update posts here on what's needed to pending work - work that needs doing. Or would it be preferred if I just dumped everything on my Github and had people contribute that way? Github is normally the way to go, but I don't want to gimp community participation by introducing version control software. We'll see how it goes, I'll probably use git for myself and have the other things in this thread. We can have both.
 

PokemonBen

Kanto Champion
60
Posts
8
Years
  • Age 24
  • Seen Apr 27, 2020
I would prefer you to make update posts on here. Just giving a list of completed, in-dev and planned features.
 
58
Posts
8
Years
  • Age 31
  • Seen Jan 7, 2017
I was making lots of hacks for the battle engine in Fire Red, to the point at which I think I might as well rewrite the whole thing. The entire engine is sort of outdated, large parts of it are undocumented, people are changing different things and are losing compatibility with other hacks, ect. Thus, my motivation to just rewrite the entire thing.
Amazing. Jambo51 may be doing something similar here, would it be helpful?
 

Blah

Free supporter
1,924
Posts
11
Years
I would prefer you to make update posts on here. Just giving a list of completed, in-dev and planned features.

Yeah, I'll keep a log here too. Will edit the OP shortly.

Amazing. Jambo51 may be doing something similar here, would it be helpful?

That's a much bigger project. Jambo is writing an entire game engine, I don't think his battle system is being worked on either. Looks like he has higher priorities for his game atm.





---
I'll edit the OP with stuff regarding the project soon~
 

PokemonBen

Kanto Champion
60
Posts
8
Years
  • Age 24
  • Seen Apr 27, 2020
Nice one! I am a noob when it comes to stuff like this so I have to ask how this will be implemented? It doesn't sound like it with be with Software so we can check/uncheck features and it doesn't feel right for it to be in an IPS patch. But I just check the thread and you are writing it in C so am I right in assuming that you will be releasing this as a software?

Sorry for the idiot question, many facepalms must be going on now.
 
534
Posts
11
Years
  • Age 26
  • Seen Jul 24, 2023
Awesome! ^O^ I was just thinking of creating a new battle system that is script-based but yours is so much better! (Which will mean my hack will be delayed more. Hahaha!) Happy hacking! ^O^

P.S. It would be awesome if it can support sideview battles for un-Pokemon Hacks. :D
 

BLAx501!

Pokemon Flux
80
Posts
10
Years
Nice one! I am a noob when it comes to stuff like this so I have to ask how this will be implemented? It doesn't sound like it with be with Software so we can check/uncheck features and it doesn't feel right for it to be in an IPS patch. But I just check the thread and you are writing it in C so am I right in assuming that you will be releasing this as a software?

Sorry for the idiot question, many facepalms must be going on now.

As far as I'm concerned, Pokemon games are programmed with a mix between ASM, C and scripting (a friendlier way for programming), so, yes, it is going to be a "software" solution but it is implemented directly on the game engine, so you have nothing to worry hahaha
 

PokemonBen

Kanto Champion
60
Posts
8
Years
  • Age 24
  • Seen Apr 27, 2020
Thanks for the reply, just went and checked the thread and I have seen it says 'Easy flexibility to add and delete things' so I should have have known. Trying to learn C# right now, but if you want to learn programming on the Internet, you really do need dual monitors.
 

BluRose

blu rass
811
Posts
10
Years
Wow, this is an incredible undertaking!
I would love to help in any way possible, but I don't exactly know how to program in C (or really at all for that matter), haha...
I wish y'all luck nonetheless! I look forward to the day that I can contribute to this meaningfully!
 

Blah

Free supporter
1,924
Posts
11
Years
Nice one! I am a noob when it comes to stuff like this so I have to ask how this will be implemented? It doesn't sound like it with be with Software so we can check/uncheck features and it doesn't feel right for it to be in an IPS patch. But I just check the thread and you are writing it in C so am I right in assuming that you will be releasing this as a software?

Sorry for the idiot question, many facepalms must be going on now.

No, you'll have to build it into your game. The same way you have to build Touched's Mega evolution solution for FireRed. It's customizable and easy because the source is in C and mainly commented/English. So you can very easily just delete features you don't want to have. Though I guess I mean when thinking about raw ASM code it's comparatively much easier.

I might include a patch as well, but I'm unsure if I want to download LIPs or something yet.

Awesome! ^O^ I was just thinking of creating a new battle system that is script-based but yours is so much better! (Which will mean my hack will be delayed more. Hahaha!) Happy hacking! ^O^

P.S. It would be awesome if it can support sideview battles for un-Pokemon Hacks. :D

This is easy to incorporate I think. Currently, for double and triple battles, the Pokemon's position on the platform changes. Which means you can just make it to where to positioning is directly on the sides. You'll have to edit the C source though (which isn't that hard).


As far as I'm concerned, Pokemon games are programmed with a mix between ASM, C and scripting (a friendlier way for programming), so, yes, it is going to be a "software" solution but it is implemented directly on the game engine, so you have nothing to worry hahaha

Hmm, Hackers program Pokemon games in ASM and C mostly. Scripts are just libraries which were written in C that are called and used, which isn't a programming language. This solution needs to be compiled and inserted yourself (though all you'd need to do is execute a couple of python scripts, the process is dumbed down significantly for easier development).


Wow, this is an incredible undertaking!
I would love to help in any way possible, but I don't exactly know how to program in C (or really at all for that matter), haha...
I wish y'all luck nonetheless! I look forward to the day that I can contribute to this meaningfully!

Thanks. You can make table files if you want to contribute & don't know how. Some knowledge of python is also neat, so you can make scripts to generated defines for me :3


---

So some updates here on my end. I finished the damage calculator mostly. Some of the names I use in the file are invalid because the associated #defines files have yet to be created. I've also written some scripts which generated #defines for moves and abilities. I'll make one for items shortly.

You can see source here if you're interested: https://github.com/EternalCode/Battle-System

EDIT: Also did the same for items, weather and types. You can add these files to you XSE if you wanted (https://github.com/EternalCode/Battle-System/tree/master/src/Defines) :D
 
Last edited:
229
Posts
8
Years
I don't have much time to assist on this, but I do have one question.

Will the features involved be compatible with trainer editors? What I'm wondering really, is how will we call upon the newer battle styles?

This is a great project and it could change the whole field of hacking. Good luck in it and I hope you receive adequate help. :)
 

Trainer 781

Guest
0
Posts
This a great concept! Plus, it allows full control over the source. And programming in C is much more easier than doing ASM.
I would like to actively contribute to this resource, but few exams are remaining.
But I managed to get some time looking at the damagecalc code and found some bugs:
Spoiler:
 
Last edited:

Lance32497

LanceKoijer of Pokemon_Addicts
792
Posts
9
Years
No, you'll have to build it into your game. The same way you have to build Touched's Mega evolution solution for FireRed. It's customizable and easy because the source is in C and mainly commented/English. So you can very easily just delete features you don't want to have. Though I guess I mean when thinking about raw ASM code it's comparatively much easier.

I might include a patch as well, but I'm unsure if I want to download LIPs or something yet.



This is easy to incorporate I think. Currently, for double and triple battles, the Pokemon's position on the platform changes. Which means you can just make it to where to positioning is directly on the sides. You'll have to edit the C source though (which isn't that hard).




Hmm, Hackers program Pokemon games in ASM and C mostly. Scripts are just libraries which were written in C that are called and used, which isn't a programming language. This solution needs to be compiled and inserted yourself (though all you'd need to do is execute a couple of python scripts, the process is dumbed down significantly for easier development).




Thanks. You can make table files if you want to contribute & don't know how. Some knowledge of python is also neat, so you can make scripts to generated defines for me :3


---

So some updates here on my end. I finished the damage calculator mostly. Some of the names I use in the file are invalid because the associated #defines files have yet to be created. I've also written some scripts which generated #defines for moves and abilities. I'll make one for items shortly.

You can see source here if you're interested: https://github.com/EternalCode/Battle-System

EDIT: Also did the same for items, weather and types. You can add these files to you XSE if you wanted (https://github.com/EternalCode/Battle-System/tree/master/src/Defines) :D

Perhaps, there's a tutorial on how to install these features
 
26
Posts
8
Years
Wow, this looks awesome! Do you think it would be possible implement a capture styler option where you can catch pokemon pokemon ranger style?
 

PokemonBen

Kanto Champion
60
Posts
8
Years
  • Age 24
  • Seen Apr 27, 2020
Wow, this looks awesome! Do you think it would be possible implement a capture styler option where you can catch pokemon pokemon ranger style?
My first thought of that was that it sounded stupid, but to be honest you could get more diverse hacks from that.
 
Back
Top