Final Fantasy XII's Gambit System was like programming for beginners
Tags: codenewbie, finalfantasy, beginners, gamedev
Published: 2019-10-15 22:10:04

As someone who grew up with video games, especially with the Squaresoft, Square-Enix titles, I thought that Final Fantasy XII's approach to their battle system was fascinating compared to any other of the titles. If you have not played any of the Final Fantasy games, here is a rundown on how the gameplay mechanic works for each title.

In traditional RPGs, battles are engaged through '[Random Encounters](https://en.wikipedia.org/wiki/Random_encounter).' This is generated by the amount of steps taken by the player before a battle is initialized.

```csharp
//using c# to describe this

Random random = new Random();
 
int steps = 0;
int battleTrigger = random.Next(64, 255);
bool inBattle = false;

public void PlayerMove() {
   //Get player's controller input, if playerMove was a method a Player class
   playerMove = step + 1;
   battleTrigger -= 4;
}  

while(!inBattle){
   PlayerMove();
   if(battleTrigger < steps){
     inBattle = true; <-- Random Battle Engaged! *Cue Battle Music*
   }
}

```
This was based on looking at the algorithm in the Random Encounter Wikipedia link I provided, where it states:

   1. Set X to a random integer between 64 and 255.
   2. For each step in plains, decrement X by 4. For each step in forest, swamp, or desert, decrement X by 8.
   3. When X < 0, a fight ensues. Go to step 1.

I felt this is more true to the Final Fantasy Random Encounters compared to the first algorithm given. 

There are the exceptions of battle encounters in Final Fantasy I where battles are triggered when you step on a tile adjacent to a dungeon treasure box, (which was super annoying but you knew there was always a battle waiting for you even though you were low on health traversing in a dungeon with low MP!).

###Final Fantasy I - III: Wait System

![FFI Battle](http://i.imgur.com/gW9y52u.jpg)

The player has all of the time in the world to select a command in their array of actions:

Example:

- Attack
- (Magic) or (Skill) <- According to their class/job
- Defend (or Guard which is the same thing just worded differently sometimes)
- Item
- Flee

###Final Fantasy IV: Slight Active System (Wait System Choice Optional)

![FFIV](https://static.giantbomb.com/uploads/original/0/3068/205345-atb.jpg)

- Attack
- Exclusive Skill to Character
- Additional Exclusive Skill to Character
- Item

with side commands Run, Defend, change Row (which affects all party members)

###Final Fantasy V: Slight Active or Wait System

![FFV](https://craftygamercraft.files.wordpress.com/2015/05/33732-final_fantasy_v_japan_en_by_rpge_v1-1-5.jpg)
Job System

- Attack
- Current Job Skill or Customized Command from learnt Job skill if Freelancer 
- Customized Command from learnt Job skill
- Item

with side commands Run and Defend, change Row (affects that member)

![FFVI](https://cdn.gamer-network.net/2018/usgamer/Final-Fantasy-6-Shot-01.jpg)

###Final Fantasy VI: Slight Active or Wait System
Magic System

- Attack
- Exclusive Skill to Character
- Magic
- Item

with side commands Run and Defend, change Row (affects that member)

I call these **slight active systems** because it is a small detail but whenever a command has been initiated and animation starts playing for that action, all of the character's battle gauges are not paused from filling up and the enemies are also waiting as well. **Battle Gauges** are the wait time for the party member. He or she cannot perform any actions until this gauge is filled, which then resets after their action is performed or an enemy disrupts it with certain attacks. 

###Final Fantasy VII: Full Active or Wait System

![FFVII](https://i.pinimg.com/originals/9b/4f/80/9b4f80b03f47f2424039cfed23520abb.jpg)

Materia System

Yellow - Special Variations of Attack Command
Green - Magic Command
Red - Summon Command

- Attack (Or custom skill using a Yellow Materia equipped)/Limit Break
- Any custom command using Green or Red Materia
- Item

with side commands Run and Defend, change Row (affects that member)

I would call this a Full Active System because of the battle gauges are continuously filling even though an action animation plays through. Although the next chosen action will not trigger until the current animation is playing, it still allows the player to wait and get to their character's command menu during the animation playing out. 

###Final Fantasy VIII: Slight Active or Wait System
![FFVIII](https://cdn.mos.cms.futurecdn.net/521040823b16d000291e8f2d5d0c39e0.jpg)
Junction System

- Attack (This can vary depending on Junction commands)/Limit Break
- Draw/Cast 
- Custom Command
- Custom Command

with side commands Run and Defend, change Row (affects that member)

###Final Fantasy IX: Active or Wait System

![FFIX](https://www.thefinalfantasy.com/gallery/screenshots/ff8/dynamic_previews/ff8-battle-3_scale_800_700.png)
Crystal System

- Attack/Trance
- Exclusive Skill for Character
- Exclusive Skill for Character
- Item

with side commands Run and Defend, change Row (affects that member)

###Final Fantasy X: Wait System

![FFX](https://vignette.wikia.nocookie.net/techxperts/images/8/81/Finalfantasyx_1214_screen001.jpg/revision/latest?cb=20100715002715)
Sphere Grid System

- Attack/Overdrive
- Summon (Exclusive to Yuna)
- Skills
- Specials
- Magics 
- Defend
- Item

Side Command to switch party members in battle

From here on out, the random encounter becomes abandoned, only to adopt to the "On-map" battle encounter where you can visually see enemies you are about to engage with. Other titles such as Chrono Trigger, Persona series, Tales of Series, use this approach. 

###Final Fantasy XI: MMORPG 
I'm actually unfamiliar as I have not experienced this game but from my understanding of watching some footage, you engage into enemies wandering across the map.

![FFXI](https://www.rpgfan.com/reviews/finalfantasy11/ss-02.jpg)

- Attack/Switch Target
- Magic/Casting Time (Wait time when casting a spell)
- Abilities
- Items
- Disengage/Call for Help 
- Check (Analyze Description in the log window)

##And Now We reach to Final Fantasy XII
If you've stuck around till now, thanks for reading so far, I know this was a handful to read but I wanted to provide this information to understand the progression of evolution Square-Enix took in order to change up the battle mechanics for traditional RPGs. 

###Final Fantasy XII: Active but also Wait System And Introducing the **Gambit System**

So what is the [Gambit](https://finalfantasy.fandom.com/wiki/Gambits) System?

Gambits are the functionality used to control the action commands for your party members in battle. The control of Active or Wait System is interesting for this game. Since there are no random encounters but on-map encounters, the player can engage battle if they want, unless there are monsters who are aggressive and will engage you instead. When inputting commands, 'Active' let's time to keep running while selecting from the command menu. 'Wait' pauses the game in motion as you are selecting your next action. After the action has been selected, that character will always perform that action whenever the gauge fills up, until you give another command. This would be the case when Gambit is selected Off because you have to micro manage every action for each character.

This is the main command list for Character Actions.
- Attack
- Magick & Technicks
- Mist
- Gambit [On or Off Toggle]
- Items

![FFXII License Board](http://www.novacrystallis.com/wp-content/uploads/2017/05/FFXII-TZA-Board.jpg)

This is the License Grid where the Player can choose the skills, equipment, status increases, in order to improve their characters.

I did not play Zodiac Age but I saw that the big change was dividing up all the licenses to learn by the Job System.

![FFXII Job System](https://d2skuhm0vrry40.cloudfront.net/2017/articles/2017-07-11-15-39/11_07_2017_03.jpg/EG11/resize/690x-1/quality/75/format/jpg)

Here is video footage of the battle system in play.

![FFXII Battle](http://hardcore-gamer.s3.amazonaws.com/uploads/2017/07/ffxii3.jpg)

{% youtube kNluu5Ab2PA %}

So now, turning on Gambits, we are turning on custom functionality for our party members in order to determine actions they will take according to certain conditions. Let's take a look at how these Gambit Commands look:

![Baltier's Gambit Actions](https://thepracticaldev.s3.amazonaws.com/i/0lr7x79zfxcbcnyqa8i1.jpg)
Picture from: https://news.xbox.com/en-us/wp-content/uploads/sites/2/3-FFXII-The-Zodiac-Age-Xbox-One-Gambit-Detail.jpg?resize=1020%2C574

Alright Baltier, you awesome sky pirate, let's see what you got!

We see that each action is indexed from 1 - 12 on the left. This is the priority level with 1 being the highest priority and 12 being the lowest priority.

1. Foe: HP = 100% -> Steal

This is saying that once a battle is engaged, With a foe at full health, Baltier will use the steal command at that foe. Then if an ally deals damage to that foe, Baltier will check if that foe's health is 100%, which is not so it moves on to the next command. Next,

2. Ally: any -> *Phoenix Down

*Phoenix Down is a revival item when a party member is dead.

This says that Baltier will use a Phoenix Down on any member, although the item only works if the member is dead.

Red Commands = Offensive Actions 
Blue Commands = Defensive Actions  

Let's take a look at one more:

10. Foe: 5+ foes present -> Flare

When there are 5 or more foes alive and nearby, Baltier will cast Flare (A non-elemental magic attack). 

Let's look at this in a code

```csharp

if(FoeHP.CurrentHP == FoeHP.MaxHP)
{
   BaltierAction.Steal(Foe);
} 
else if(Ally)
{
   BaltierAction.useItem("Phoenix Down", Ally);
} 
else if(Ally.CurrentMP < ((30 / Ally.MaxMP) * 100))
{
   BaltierAction.useItem("Hi-Ether", Ally);//Ether recovers magic points
}
else if(Ally.CurrentHP < ((30 / Ally.MaxHP) * 100))
{
   BaltierAction.castSpell("Curaga", Ally);
}
else if(Ally)
{
   BaltierAction.castSpell("Esuna", Ally);
}
else if(Foe.Status == "Reflect")
{
   BaltierAction.castSpell("Dispel Mote", Foe);
}
else if(Foe.Weakness == "Fire")
{
   BaltierAction.castSpell("Firaga", Foe);
}
else if(Foe.Weakness == "Lightning")
{
   BaltierAction.castSpell("Thundaga", Foe);
}
else if(Foe.Weakness == "Ice")
{
   BaltierAction.castSpell("Blizzaga", Foe);
}
else if(FoeCount >= 5)
{
   BaltierAction.castSpell("Flare", FoesArray);
}
else if(FoeArray >= 1)
{
   //This is an interesting situation
}
else if(Ally == "Ashe")
{
   BaltierAction.castSpell("Bubble", "Ashe");
}

```

Seeing 11. Foe: Highest HP -> Attack

This is more like a while loop because what if there is more than 1 foe? Baltier would take into consideration of attack a foe who's HP will always be the highest out of the other foes. If it was just one foe, they it would be an easy action call with

```csharp
BaltierAction.Attack(Foe);
```

But account for multiple foes, I would think it would be an array of foes, and checking the foe in that array whoever has the highest CurrentHP, which Baltier will target that Foe. 

I feel like there would be a method call for the FoeArray in order to check this condition like:

```csharp
//There is probably a better way to do this since this is an O(n)
pubic Foe FoeWithHighestHP(FoeArray){
   Foe HighestHPFoe = FoeArray[0];

   foreach(Foe foe in FoeArray)
   {
      if(foe.CurrentHP > HighestHPFoe.CurrentHP)
      {
          HighestHPFoe = foe;
      }
   }
   return HighestHPFoe
}

BaltierAction.Attack(FoeWithHighestHP(FoeArray));
```
But you get the idea, seeing how much control and customization you have with characters actions in order to fight through the battles. I feel like this is a nice introduction of programming without actually knowing code and Square-Enix did such an interesting take behind the scenes to give this freedom to the player. It's like we are scripting our own AI allies in the way we want them to act.

I thought this was just a nice fun blog to write because I was always fascinated by connection of Final Fantasy XII's battle system with programming.