Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

The past months I've been busy programming a 2D JRPG (Japanese-style RPG) in C++ using the SDL library. The exploration mode is more or less done. Now I'm tackling the battle mode.

I have been unable to find any resources about how a classic turn-based JRPG battle system is structured. All I find are discussions about damage formula. I've tried googling, searching gamedev.net's message board, and crawling through C++-related questions here on Stack Exchange. I've also tried reading source code of existing open source RPGs, but without a guide of some sort it's like trying to find a needle in a haystack.

I'm not looking for a set of rules like D&D or anything similar. I'm talking purely about code and object structure design. A battle system asks the player for input using menus. Next the battle turn is executed as the heroes and the enemies execute their actions.

Can anyone point me in the right direction? Thanks in advance.

share|improve this question
3  
there are no common hard-set rules. All games have their own way, unless we speak of dungeons and dragons derived rulesets. I must say, i'm not quite sure if that is what you meant. Elaborate. –  Toni May 1 '12 at 17:48
    
What do you mean by JRPG exactly? –  ashes999 May 1 '12 at 17:57
2  
Why don't you define first what you want the player to experience, then write an implementation spec based on that? –  Tetrad May 1 '12 at 18:52
1  
@ashes999 The most influential classic example is probably the Ultima series. Other more recent and popular examples: the Baldur's Gate series (BG2 is often considered the best CRPG of all time) or The Elder Scrolls series (Morrowind, Oblivion, Skyrim in particular for their fame). –  David Gouveia May 1 '12 at 19:07
1  
"A battle system asks the player for input using menus. Next the battle turn is executed as the heroes and the enemies execute their actions." You seem to have a handle on the algorithm. So... what exactly are you looking for? Advice on how to structure your code? Also, what is a "classic turn-based JRPG battle system"? You know, there are more than one classic JRPG, and many of them have very different battle systems. So what exactly are you trying to accomplish? –  Nicol Bolas Sep 25 '12 at 21:34
show 2 more comments

1 Answer

I have never seen much resources on this subject either, but the best one I've found is probably the:

It provides insight into the enemies AI such as this:

AI: Setup
{
   TempVar:TurnsUntilGrenade = 3
   TempVar:GrenadeAmmo = 4
}
AI: Main
{
   If (Stage == 0) Then
   {
      If (TempVar:TurnsUntilGrenade == 0) Then
      {
         If (TempVar:GrenadeAmmo > 0) Then
         {
            Choose Random Opponent with Lowest HP
            Use Hand Grenade on Target
            TempVar:GrenadeAmmo = TempVar:GrenadeAmmo - 1
            TempVar:TurnsUntilGrenade = 3
         } Else {
            Choose Random Opponent with Lowest HP
            Use <Machine Gun> on Target
         }
      } Else {
         Choose Random Opponent
         Use <Machine Gun> on Target
         TempVar:TurnsUntilGrenade = TempVar:TurnsUntilGrenade - 1
      }
   } Else {
      If (TempVar:GrenadeAmmo > 0) Then
      {
         Choose Random Opponent with Lowest HP
         Use Hand Grenade on Target
         TempVar:GrenadeAmmo = TempVar:GrenadeAmmo - 1
      } Else {
         Choose Random Opponent
         Use <Machine Gun> on Target
      }
   }
}
AI: Counter - General
{
   If (Grenade Combatant's HP <= 3 * [Grenade Combatant's Max HP / 4]) Then
   {
      Stage = 1
   } Else {
      Stage = 0
   }
}

With this you can see that your enemies will probably need a state machine to manage the different states they can be in, and each state will have its own behavior to execute each turn, either hardcoded into the enemy, or data-driven by a scripting language.

There's a lot of variation even between turn based JRPGs, so there is no set of rules for all of them. For instance, you can issue all party commands before any of them taking place, or they can take place immediately after choosing. Attack order might be random, or more often determined by the Speed stat.

But for instance, let's say you have a purely turn based battle system, where you issue all party commands first, and then all the action happens at the end of the turn. You could approach it like:

  • Store all entities (players + enemies) participating in the battle in a list.
  • For each player in the list get input and store it.
  • Sort the entity list by the Speed attribute.
  • For each entity in the list, if it's a player execute the stored action, otherwise run the AI script for the current state.
  • Advance turn and repeat.

The Battle Mechanics FAQ also has a lot of useful information, in particular about time management in the battles. But unfortunately this system (aka ATB or Active Time Battle) is patented so you can't make anything similar.

EDIT I also recently found this website which provides a lot of technical information about the implementation of FF7. Unfortunately the battle module sections does not seem to be completely written yet.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.