Indie Dev

Hello Guest!. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, sell your games, upload content, as well as connect with other members through your own private inbox!

Basic knowledge on writing ATB(Active Time Battle) system plugins

DoubleX

Adventurer
Xy$
1.11
Related topics
Solid understanding on writing ATB(Active Time Battle) system plugins(Possibly upcoming)
Thorough Comprehension on writing ATB(Active Time Battle) system plugins(Possibly upcoming)

Goal
Shares my experiences and understandings on writing a basic ATB system plugin and their addons, meaning easy, simple and small cases will be the focus.

Targeting Audiences
Those having some battle related javascript coding proficiency(inexperienced junior plugin developer having written several easy, simple ans small battle related plugins without nontrivial bugs), and:
1. Basic knowledge to the default RMMV battle flow implementations
2. Basic knowledge on how the fundamental ATB system concepts work on the user level

Contents
I. Fundamental ATB system plugin implementation concepts
1. ATB Frame Update
2. ATB Wait Condition
3. Battle Turn Clock
4. Battler ATB Clock
5. ATB Flow Overview
6. Summary
II. Differences between the default RMMV battle flow and the ATB flow
1. Stuffs to be gone in the default RMMV battle flow to become the ATB flow
2. Stuffs to be edited in the default RMMV battle flow to become the ATB flow
3. Stuffs to be added in the default RMMV battle flow to become the ATB flow
4. Summary
III. Ways to write the easiest, simplest and smallest ATB system ever
1. Clarification
2. Stuffs to be implemented
3. Writing DoubleX RMMV Minimalized ATB from scratch
4. Summary
IV. Ways to write a basic ATB system having all core functionalities
1. Clarification
2. Stuffs to be implemented
3. Writing DoubleX RMMV Popularized ATB Core from scratch
4. Summary
V. Comparisons between DoubleX RMMV Minimalized ATB and DoubleX RMMV Popularized ATB Core
1. Shortcuts taken in writing DoubleX RMMV Minimalized ATB
2. Testing various ATB Wait Conditions
3. Summary
VI. Ways to write an easy, simple and small ATB system addon
1. The Core Addon Approach basics
2. Interactions between the core and an addon
3. Some easy, simple and small ATB system addon examples
4. Summary
VII. Ways to study some other ATB system plugins
1. Ellye's ATB(also includes CTB option)
2. YEP.24 - Battle System - Active Time Battle
3. Summary
VIII. Summary

With the framework's set, let's get started. I'm going to talk about Fundamental ATB system plugin implementation concepts:
ATB Frame Update
While you know the battle system is run per frame, you may wonder what's the difference between Battle Frame Update and ATB Frame Update.
Basically, the difference is that, the former will always run while the latter won't run when the ATB Wait Condition's met, and the former's universal to all battle systems while the latter's unique to ATB systems.
The latter mainly does the following(these details will be explained later):
1. Runs each battler's Battler ATB Clocks
2. Runs the Battle Turn Clock
3. Set a battler that becomes able to execute actions to be the Action Execution Subject when there's none
4. Setups an actor that becomes inputable when there's none
5. Updates all actors' atb bars(unless you don't even implement actor atb bars)
Bear in mind that the action execution itself's updated by the Battle Frame Update but not the ATB Frame Update.

ATB Wait Condition
Unless one can flawlessly implement executing more than 1 actions at the same time, no ATB system can have absolutely no waits, meaning every ATB system has an ATB Wait Condition determining if a Battle Frame Update should run an ATB Frame Update.
Usually, the ATB Wait Condition's 1 of the below:
1. Wait when the ATB Frame Update can be run without inducing bugs(situations like having a message displayed can induce bugs if the ATB Frame Update's run)
2. Wait when an action's animation's playing as well
3. Wait when an actor's picking the action's targets as well
4. Wait when an actor's picking a skill/item as well
5. Wait when an actor's can input actions as well

Battle Turn Clock
Unless you're going to abandon the whole battle turn number concept entirely, you'll need a global atb clock to run it, as its implementation used by the default RMMV battle system won't work in any ATB system anymore. It's because both the party and troop have the action input phase and action execution phase in battles, and its turn number mechanics's built around it, while no ATB system will ever divide a battle that way(details will be explained in Differences between the default RMMV battle flow and the ATB flow). As the battle turn clock must be run by the battle itself, a Battle Turn Clock will be needed to run it.
The Battle Turn Clock normally uses 1 one of the below 2 units:
- Frames. Each battle turn consists of a specific number of ATB Frame Updates
- Actions. Each battle turn consists of a specific number of executed actions
For both units, when that specific number's reached in a battle turn, the battle turn number will be increased by 1 and the Battle Turn Clock will be reset.

Battler ATB Clock
In an ATB system, each battler has an independent action input phase and action execution phase, as well as an ATB refill phase, meaning each battler needs to have an independent Battler ATB Clock.
The Battler ATB Clock's usually used in 1 one of the below 2 ways:
- Checks if the battler should be able to act. When it's true, that battler can input then execute actions, and the Battler ATB Clock will be reset afterwards; When it's false, that battler will need to wait until the aforementioned check returns true.
- Checks if the battler's inputted actions should be executed. When it's true, that action will be executed and then that battler can input actions again; When it's false, that action will need to wait until the aforementioned check returns true.
For both ways, the battler's speed must be used to run that Battler ATB Clock, as the essence of an atb system is to make the some battlers act faster and more frequently than the others. Using the default RMMV settings, the battler's speed's determined by that battler's agi. This also implies that the skill/item invocation speed's mostly useless in the 1st way of using the battler atb clock.

ATB Flow Overview
Consider the below simplified flowchart:
Basically, the ATB system only has 2 battle phase - Not Executing Actions and Executing Actions, and 3 battler phase per battler - Refilling ATB, Full ATB, Executing Actions.
The ATB system battle phase's divided that way because of the below 2 of the most fundamental Scene_Battle based foundations(too advanced to be explained here):
1. Only 1 battler, the Action Execution Subject, can execute actions at a time.
2. Only 1 action, the Currently Executing Action, can be executed at a time.
So it's vital to check if any battler's already executing actions before letting any other battler that can execute actions to execute them.

On a side note: Some addons need to add some more battler phases in order to work, but those will be covered later.

The below explains how the simplified ATB flow works:
Battle Frame Update
It'll always run per frame(technically there are some exceptions but let's ignore them now for the sake of simplicity) and is always run by Scene_Battle(It can't be run by BattleManager.update or the ATB Wait Conditions will be restricted to wait when an actor's inputable, which will be explained in Differences between the default RMMV battle flow and the ATB flow).
The Battle Frame Update will first check if the ATB Wait Condition's met.
If that's the case, the ATB Frame Update will be run.
Otherwise the Battle Frame Update will continue to execute any executing action.
If the action execution reaches its end, the Action Execution Subject's Battler ATB Clock will be reset, and the battler will be marked as Unactable(impossible to be the Action Execution Subject right now) and shift from Executing Actions to Refilling ATB(And the battle phase will shift from Executing Actions to Not Executing Actions as well).
ATB Frame Update
It won't run if the ATB Wait Condition's met.
It'll first update each battler's Battler ATB Clock.
If a battler's Battler ATB Clock becomes full, that battler will make actions, be marked as Actable(possible to be the Action Execution Subject right now), and shift from Refilling ATB to Full ATB.
Then the ATB Frame Update will check if any action's executing. If that's not the case, exactly 1 Actable battler that has finished inputting actions will become the Action Execution Subject and shift from Full ATB to Executing Actions(And the battle phase will shift from Not Executing Actions to Executing Actions as well). For either case, the action will begin/continue to be executed.
If the action execution reaches its end, the Action Execution Subject's Battler ATB Clock will be reset, and the battler will be marked as Unactable(impossible to be the Action Execution Subject right now) and shift from Executing Actions to Refilling ATB(And the battle phase will shift from Executing Actions to Not Executing Actions as well).
Recall that the action execution itself's updated by the Battle Frame Update but not the ATB Frame Update. The latter just marks that the former needs to/need not update action executions by manipulating the battle phase.
The ATB Frame Update will then check if any actor becomes inputable, and will setups the actor command window for that actor if that's the case and no other actors are inputable.
Finally, the ATB Frame Update will update all actors' atb bars. Nothing else will be updated in most cases to boost time performance(too advanced to be explained here).

Summary
1. The ATB system consists of 2 battle phase - Not Executing Actions and Executing Actions, and 3 battler phase per battler - Refilling ATB, Full ATB, Executing Actions.
2. The Battle Frame Update, which updates the action execution itself, will always be run per frame, while the ATB Frame Update won't run when the ATB Wait Condition's met.
3. The ATB Frame Update runs each battler's Battler ATB Clocks and the Battle Turn Clock, and sets an Actable battler that has finished inputting actions to be the Action Execution Subject when there's none.
4. A battler becomes Actable when that battler shifts from Refilling ATB to Full ATB, becomes the Action Execution Subject when that battler shifts from Full ATB to Executing Actions, and becomes Unactable when that battler shifts from Executing Actions to Refilling ATB, which occurs when that battler has finished executing the Currently Executing Action.

That's all for now. The remaining parts will be covered later

[doublepost=1452776775,1452410510][/doublepost]Now I'm going to talk about Differences between the default RMMV battle flow and the ATB flow. But before that, let's cite the simplified default RMMV battle flowchart and the simplified ATB flowchart:
Simplified default RMMV battle flowchart -
Simplified ATB flowchart -

Stuffs to be gone in the default RMMV battle flow to become the ATB flow
BattleManager.update
Recall that BattleManager.update, which run the Battle Frame Update for the default RMMV battle system, will only be called when the battle isn't in the Action Input Phase(too advanced to be explained here).
This has to be gone completely unless the ATB Wait Condition will always be true whenever an actor's inputable.
Start Input
[SPOILER
Recall that Start Input in the default RMMV battle system will ask all battlers to make actions upon the start of the Action Input Phase.
This has to be gone completely because:
1. The ATB system has no Action Input Phase at all.
2. For each battler, make actions must be only caused by that battler becoming Actable, which is absolutely unrelated to what the battle phase is.
If making actions for a battler can occur at any timing that's not controlled by that battler, the battler phase can be severely disrupted, as the previously made actions can be overridden with the new ones even before the formers are executed at all.
Make Action Order Queue/Get Next Subject
Recall that the Action Order Queue in the default RMMV battle system will be made upon the start of the Action Execution Phase.
All these have to be gone completely because:
1. The ATB system has no Action Execution Phase at all, as that phase's meant to process all inputted actions in the Action Input Phase as a single batch by making an Action Order Queue, while ATB always processes inputted actions in real time.
It also means Get Next Subject has to be gone, as its sole purpose is to extract the 1st battler from the Action Order Queue.
The Action Order Queue itself, however, can be edited instead of having to be gone altogether(more on that below).
[/SPOILER]

Stuffs to be edited in the default RMMV battle flow to become the ATB flow
Turn Start/Turn End
Recall that in the default RMMV battle system, Turn Start is the transition from the Action Input Phase to the Action Execution Phase, while Turn End is the opposite transition.
All these have to be edited because:
1. The ATB system has neither Action Input Phase nor Action Execution Phase.
Neither of these can be gone completely unless the ATB system's going to abandon the whole battle turn concept altogether.
Also, recall that in the ATB system, a Battle Turn Clock will be used to run the battle turn.
All these mean that Turn Start and Turn End in the ATB system's essentially the same thing, as the former will come immediately after the latter, which comes when the Battle Turn Clock's reset due to reaching its maximum. These also mean that Turn Start can't be triggered by Next Command and Turn End can't be triggered by failing to find a new Action Execution Subject.
Technically speaking, however, both Turn Start and Turn End will need to exist to preserve a vital Scene_Battle based battle system(having battle turn) invariant - A Turn Start always lead to a Turn End before leading to another Turn Start, and a Turn End always lead to a Turn Start before leading to another Turn End(too advanced to be explained here).
Action Order Queue
As mentioned, the Action Order Queue can be edited instead of having to be gone altogether.
It can(but not required) mark which battlers are Actable, thus easing the checking when finding a battler to become the new Action Execution Subject and setting an inputable actor's command window, as both Action Execution Subject and inputable actors must be Actable.

Stuffs to be added in the default RMMV battle flow to become the ATB flow
ATB Wait Condition
Recall that the ATB Wait Condition determines if the ATB Frame Update should be run for each Battle Frame Update.
This has to be added because:
1. The default RMMV battle system has neither ATB Wait Condition nor anything that can be edited to be just that, unless it's always true whenever an actor's inputable.
2. Without it, the ATB Frame Update would always run for each Battle Frame Update, even in cases where doing so could cause the game to crash(like while a message's displaying).
ATB Frame Update
Recall that the ATB Frame Update runs each battler's Battler ATB Clock, the Battle Turn Clock(unless the ATB system abandons the whole battle turn concept altogether), setups a new Action Execution Subject, setups a newly inputable actor and updates all actors' ATB bars(unless the ATB system isn't going to implement that).
This has to be added because:
1. The default RMMV battle system has neither ATB Frame Update nor anything that can be edited to be just that.
2. Without it, the ATB system wouldn't even run, as all Battler ATB Clock, setups for new Action Execution Subjects and inputable actors, which are all integral to implementing all the essential ATB system concepts, must be run by the ATB Frame Update(explained in Ways to write the easiest, simplest and smallest ATB system ever).
Battler ATB Clock/Reset Battler ATB
Recall that the Battler ATB Clock uses the battler's speed to control the time needed for that battler to stay in Refilling ATB before transiting to Full ATB, and Reset Battler resets the Action Execution Subject's Battler ATB Clock and causes that battler to transit from Executing Actions to Refilling ATB.
All these have to be added because:
1. The default RMMV battle system has neither Battler ATB Clock, Reset Battler ATB, nor anything that can be edited to be just either of those.
2. Without both of them, the essence of the whole ATB system concept - Letting speedy battlers act more frequently, couldn't be implemented at all, causing the entire ATB system to be effectively meaningless and pointless.
Setup Newly Inputable Actor
Recall that Setup Newly Inputable Actor, which setups the actor command window for the newly inputable actor, will be called whenever such actor's found while running the ATB Frame Update.
This has to be added because:
1. The default RMMV battle system has neither Setup Newly Inputable Actor in real time(it's always done as a single batch at the start of the Action input Phase), nor anything that can be edited to be just that.
2. Without it, players wouldn't be able to input actions for inputable actors, effectively taking all control and freedom from those players in the ATB system, and hence causing it to be useless.
On a side note: both the Battle Turn Clock and updates of all actors' ATB bars should be added too, but strictly speaking, they're not absolutely needed in the ATB system, even though such ATB systems would be generally considered mostly broken.

Summary
The below have to be gone from the default RMMV battle system:
1. BattleManager.update
2. Start Input
3. Make Action Order Queue/Get Next Subject

The below have to be edited from the default RMMV battler system to be used in the ATB system:
1. Turn Start/Turn End to be called by the Battle Turn Clock instead
2. Action Order Queue to mark all Actable battlers instead(not required)

The below has to be added to the ATB system:
1. ATB Wait Condition
2. ATB Frame Update
3. Battler ATB Clock/Reset Battler ATB
4. Setup Newly Inputable Actor(in real time instead of as a single batch)
(Battle Turn clock and updates of all actors' ATB bars should be added too)

P.S.: You might wonder why Next Command/Prior Command can remain intact(neither gone nor edited) during the transformation from the default RMMV battle system to the ATB system. I'll explain it in Ways to write the easiest, simplest and smallest ATB system ever.
 
Last edited:
Top