Advertiser Content

Development New Battle System

Started by FBI November 24th, 2015 12:21 PM
  • 38585 views
  • 178 replies

FBI

Free supporter

Male
Unknown Island
Seen 15 Hours Ago
Posted March 30th, 2019
1,906 posts
6.4 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:


...

BLAx501!

Pokemon Flux

Male
Madrid, Spain
Seen 4 Weeks Ago
Posted February 5th, 2019
80 posts
5.7 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

FBI

Free supporter

Male
Unknown Island
Seen 15 Hours Ago
Posted March 30th, 2019
1,906 posts
6.4 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.
...
Seen January 7th, 2017
Posted August 6th, 2016
58 posts
3.8 Years
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?

FBI

Free supporter

Male
Unknown Island
Seen 15 Hours Ago
Posted March 30th, 2019
1,906 posts
6.4 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

Male
England
Seen December 15th, 2015
Posted December 7th, 2015
60 posts
3.6 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.

BLAx501!

Pokemon Flux

Male
Madrid, Spain
Seen 4 Weeks Ago
Posted February 5th, 2019
80 posts
5.7 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

BluRose

blu rass

Age 18
Male
rip x
Seen 5 Days Ago
Posted 1 Week Ago
762 posts
5.1 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!
am i cool yet

FBI

Free supporter

Male
Unknown Island
Seen 15 Hours Ago
Posted March 30th, 2019
1,906 posts
6.4 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
...

Chicken Fingers

Male
My House
Seen January 17th, 2016
Posted January 11th, 2016
229 posts
4 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. :)

Chacha Dinosaur

Adamant and adaptive dinosaur.

Age 24
Male
Seen March 4th, 2018
Posted September 8th, 2017
454 posts
5.9 Years
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:

* In Pure Power, Flower Gift and Hustle attack boost, the NOT (!) symbol is missing in the attack->is_special condition.
* Slow Start should only reduce attack.
* Flower Gift does not raise Attack and Sp. Def specially only for Cherrim. It raises Attack and Sp. Def for all allies and the user too in Sunlight if a Pokemon with Flower Gift is present at the user side.
* Mold Breaker is not a field ability. It only works for the user and negates the ability of the target. And it should ignore defensive boosts given by ally's Flower Gift and Friend Guard.
* Facade and Guts should ignore burn attack drop.

Lance32497

LanceKoijer of Pokemon_Addicts

Male
Criscanto town-Ginoa Region xD
Seen August 13th, 2017
Posted January 1st, 2017
793 posts
4.8 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
This signature has been disabled.
Scrollbar appears
Please review and fix the issues by reading the signature rules.

You must edit it to meet the limits set by the rules before you may remove the [sig-reason] code from your signature. Removing this tag will re-enable it.

Do not remove the tag until you fix the issues in your signature. You may be infracted for removing this tag if you do not fix the specified issues. Do not use this tag for decoration purposes.

PokemonBen

Kanto Champion

Male
England
Seen December 15th, 2015
Posted December 7th, 2015
60 posts
3.6 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?
My first thought of that was that it sounded stupid, but to be honest you could get more diverse hacks from that.

FBI

Free supporter

Male
Unknown Island
Seen 15 Hours Ago
Posted March 30th, 2019
1,906 posts
6.4 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. :)
Yeah, so I'm going to be using a lot of the default tables for this stuff. I might make it read from a second seperate table to toggle certain flagging bits in the battle sequence. That way you edit your standard trainer battles via tool, and added special flags can be done with a hex editor quite easily.

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:

* In Pure Power, Flower Gift and Hustle attack boost, the NOT (!) symbol is missing in the attack->is_special condition.
* Slow Start should only reduce attack.
* Flower Gift does not raise Attack and Sp. Def specially only for Cherrim. It raises Attack and Sp. Def for all allies and the user too in Sunlight if a Pokemon with Flower Gift is present at the user side.
* Mold Breaker is not a field ability. It only works for the user and negates the ability of the target. And it should ignore defensive boosts given by ally's Flower Gift and Friend Guard.
* Facade and Guts should ignore burn attack drop.
Wow, thanks a lot. I really have no idea how half of these mechanics work, and I misinterpret bulbapedia a lot. Doesnt has been my go-to PokeDictionary for this sort of stuff, but obviously I try not to bother him with a lot of questions. I'll get to fixing these, and once again thanks for looking through and pointing them out :D

Perhaps, there's a tutorial on how to install these features
People are free to write tutorials if they want. But as far as I'm concerned all you need to do is:
cd path
python scripts/build
python scripts/insert
Into the terminal. So it's kind of straight forward.

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.
So unfortunately, the GBA doesn't have a touch screen, and as such this style of capturing is physically impossible to implement. You could write your own emulator and make it possible to use your mouse as the stylus, but at that point it's not a GBA game and you should probably just make a new game, rather than a hack.
...

esperance

Age 22
Male
Ohio
Seen 1 Day Ago
Posted May 11th, 2019
3,825 posts
9.2 Years
This is a great idea! And you've been working on it very quickly.
I'm no C expert but if I see something I can do I'll surely give it a try.

Also, after taking a quick peek through the damage calculator, I noticed that in get_base_attack you never actually check for the soul dew, but rather apply the bonus to all Lati@s.
https://github.com/EternalCode/Battle-System/blob/master/src/damage_calculator.c#L1361 (line 1361)
What are you so afraid of?

FBI

Free supporter

Male
Unknown Island
Seen 15 Hours Ago
Posted March 30th, 2019
1,906 posts
6.4 Years
I've checked a bit of your code. Sadly I don't program in C, though there some things I caught that might be improved :
[spoiler]

-Mega stone

Pokémons can lose/been knocked off holding a mega stone if they can't mega evolve with it.
Damage calculator doesn't handle this sort of thing. It simply just calculates damage.


-Boost item:
case LIFE_ORB:
item_boost = 30
Here you don't allow the user/hacker to set the power of the boost in an item editor.
Maybe later, it would've been nice to know the item table had a field like that before I made this code :x


-Base power move :

case AVALANCHE:
if (defender->last_move_target == attacker_id) {
atk_base_power = 120;
} else {
atk_base_power = 60;

Here the same principles applie. We could do:
atk_base_power = base_power*2
else
atk_base_power=base_power
This is definitely better, good catch.


-Reckless:

It'd be better to check the move effect. If you check directly the move, we'd have to update the code everytime we add a move with recoil effect.

-What I call "table ability" : Iron fist, strong jaw... :
Perhaps we could add a flag the move structure, to make easier to have move affected or
not by those abilities.
That's a temporary solution. In one of the header files I've made some settings to use a table instead of this way, but I haven't gotten around to making the actual table so a switch statement was put for place-holding. I'm waiting for contributions for this kind of thing :D

To current date, people have offered to contribute, even asked for details, but I've yet to receive any dev. help as of yet.
...

FBI

Free supporter

Male
Unknown Island
Seen 15 Hours Ago
Posted March 30th, 2019
1,906 posts
6.4 Years
This is a great idea! And you've been working on it very quickly.
I'm no C expert but if I see something I can do I'll surely give it a try.

Also, after taking a quick peek through the damage calculator, I noticed that in get_base_attack you never actually check for the soul dew, but rather apply the bonus to all Lati@s.
https://github.com/EternalCode/Battle-System/blob/master/src/damage_calculator.c#L1361 (line 1361)
Whoops...
...

BLAx501!

Pokemon Flux

Male
Madrid, Spain
Seen 4 Weeks Ago
Posted February 5th, 2019
80 posts
5.7 Years
To current date, people have offered to contribute, even asked for details, but I've yet to receive any dev. help as of yet.
I'm very busy with university these weeks, but I'll try to take a deep look to your Git, I'm not a total noob on C programming, so maybe there is something I can help :P
Advertiser Content