Battle Mode

From Hero of Allacrost Wiki
Jump to: navigation, search

Battle Design[edit]

Before beginning to discuss the code itself, a cursory understanding of the battle design and major features is required. The battle system is active-time based, meaning that characters and enemies (collectively referred to as actors) take a certain amount of seconds to prepare their actions in battle. The player chooses actions for their characters in a GUI menu like traditional RPGs do. There is no movement of character or enemy sprites on the battle field after they are initially placed, and the position and distance to a target do not have any effect in battle.

The following are core features for the Allacrost battle system.

MAPS MAPS stands for Multiple Attack Points System. Each character or enemy in battle can have attacks targeted at different points on their body. Each attack point can have different vulnerabilities and chances of being hit. Additionally, certain attack points may trigger status effects temporarily. For example, striking the head could cause blindness, the arms a temporary loss of physical attack strength, and the legs a drop in agility. This allows the player to choose different strategies and either take risks by going for high damage but low hit rate targets, or trying to cause a status effect to occur.

Skill Actions Instead of having a "Fight" command and a "Magic" command like most RPGs tend to employ, Allacrost implements skills for each character. Types of skills can vary from physical attacks, healing, ethereal (magical) support, and so on. Every skill requires some amount of skill points (SP) in order to use it. A small amount of SP regenerates naturally for a character every turn.

Battle Fatigue Characters start each battle at full HP and SP. But their maximum HP and SP are reduced by what we call battle fatigue. Battle fatigue for HP occurs when a character gets attacked. Battle fatigue for SP occurs when a player uses a skill. The stamina and resilience attributes determine what amount if any, of fatigue is accumulated upon receiving damage or consuming SP. A player has to consider fatigue mitigation as part of their long-term battle strategy.

Battle Retry Allacrost battles are designed to be difficult and it is expected that the average player will not win every battle. If a player loses a battle, they have the option to retry the battle at a cost of reduced rewards should they win a later attempt (reduced experience, drunes, and item drops payed out). Players have three attempts to win a battle, after which it is game over and the player must reload the game from the last save point.

Status Effect Intensities Status effects have multiple (four) degrees of intensity. For example, a weaker poison status may reduce an actor's HP by 2% a turn, while the strongest may reduce it by 15% per turn. Status effects naturally weaken in intensity and eventually disappear over time, so the player must choose to cure the status ailment immediately or let it heal by itself. Status effects do not persist outside of battle.


Battle States[edit]

There are many different states that the battle can be in at any given time. These states are enumerated in battle_utils.h. The battle state is used to determine what needs to happen in the battle, what graphics should be visible on the screen, etc.

//! \brief Used to indicate what state the overall battle is currently operating in
enum BATTLE_STATE {
	BATTLE_STATE_INVALID   = -1,
	BATTLE_STATE_INITIAL   =  0, //!< Character sprites are running in from off-screen to their battle positions
	BATTLE_STATE_NORMAL    =  1, //!< Normal state where player is watching actions play out and waiting for a turn
	BATTLE_STATE_COMMAND   =  2, //!< Player is choosing a command for a character
	BATTLE_STATE_EVENT     =  3, //!< A scripted event is taking place, suspending all standard action
	BATTLE_STATE_VICTORY   =  4, //!< Battle has ended with the characters victorious
	BATTLE_STATE_DEFEAT    =  5, //!< Battle has ended with the characters defeated
	BATTLE_STATE_EXITING   =  6, //!< Player has closed battle windows and battle mode is fading out
	BATTLE_STATE_TOTAL     =  7
};

In addition to these, each battle actor (character or enemy) also has a state which is one of the following (also enumerated in battle_utils.h)

//! \brief Represents the possible states that a BattleActor may be in as they pertain to the stamina bar
enum ACTOR_STATE {
	ACTOR_STATE_INVALID       = -1,
	ACTOR_STATE_IDLE          =  0, //!< Actor is recovering so they can execute another action
	ACTOR_STATE_COMMAND       =  1, //!< Actor is finished with the idle state but has not yet selected an action to execute
	ACTOR_STATE_WARM_UP       =  2, //!< Actor has selected an action and is preparing to execute it
	ACTOR_STATE_READY         =  3, //!< Actor is prepared to execute action and is waiting their turn to act
	ACTOR_STATE_ACTING        =  4, //!< Actor is in the process of executing their selected action
	ACTOR_STATE_DEAD          =  5, //!< Actor has perished and is inactive in battle
	ACTOR_STATE_PARALYZED     =  6, //!< Actor is in some state of paralysis and can not act 
	ACTOR_STATE_TOTAL         =  7
};

The standard state progression for a character is: IDLE -> COMMAND -> WARM UP -> READY -> ACTING. Enemies follow the same sequence but skip the COMMAND state, since the AI instantly chooses an action.

Battle Code Architecture[edit]

Files[edit]

All C++ battle code files can be found in src/modes/battle/. The table below lists each file name (minus the .h/.cpp extension) and what the code in that file is generally responsible for doing.

File Name Description
battle The main battle class is found here. This code makes appropriate update and draw calls based on the current battle state
battle_actions Manages the properties and execution of actions in battle (using skills or items)
battle_actors Handles the state and data for each actor on the battlefield. Includes handling state management for the actors as well as the draw logic.
battle_command Responsible for the command window where the player enters actions for their characters.
battle_dialogue Inherits from the CommonDialogue class to implement a dialogue window at the top of the battle screen
battle_effects Manages the state of all status effects and other temporary changes to an actor's state
battle_finish Implements the victory and defeat screens that are seen after a battle is won or lost, showing character growth and battle rewards.
battle_indicators Manages brief UI elements that show damage received, icons reflecting status changes, and so on.
battle_sequence Manages the battle state for certain common sequences, such as the transition into battle where the battle UI appears
battle_utils Utilities used throughout battle mode. Includes numerous constants, common damage/evasion calculation formulas, and an advanced timer class.

Supervisors[edit]

The highest level class in the battle code is the BattleMode class, which derives from the GameMode class in the mode management engine. Because there is so much to manage and process for each battle, there are a number of "supervisor" classes that handle a specific piece of functionality so that the BattleMode class can remain a manageable size. The BattleMode class creates an instance of each of these supervisor classes upon construction. The table below lists all supervisor classes and what types of data and operations that they are responsible for. Additional data and responsibilities of the battle code not listed in the table are usually managed by the BattleMode class directly.


Supervisor Class Name Responsibilities
CommandSupervisor Manages GUI visuals and processes input commands when the player is selecting an action for a character
DialogueSupervisor Stores and processes any dialogue that is to occur during the battle
FinishSupervisor Presents the player with information and options after a battle has concluded in either victory or defeat
SequenceSupervisor Manages update and draw calls during special battle sequences (such as the battle intro and exit scenes)