For the default battle system codebase, you may want to read
this.
Specifically:
1. "making it a certain actor's or enemy's turn" is done by Game_Battler.prototype.makeActions, and their Game_Actor, Game_Enemy counterparts:
Spoiler
JavaScript:
Game_Battler.prototype.makeActions = function() {
this.clearActions();
if (this.canMove()) {
var actionTimes = this.makeActionTimes();
this._actions = [];
for (var i = 0; i < actionTimes; i++) {
this._actions.push(new Game_Action(this));
}
}
};
JavaScript:
Game_Actor.prototype.makeActions = function() {
Game_Battler.prototype.makeActions.call(this);
if (this.numActions() > 0) {
this.setActionState('undecided');
} else {
this.setActionState('waiting');
}
if (this.isAutoBattle()) {
this.makeAutoBattleActions();
} else if (this.isConfused()) {
this.makeConfusionActions();
}
};
JavaScript:
Game_Enemy.prototype.makeActions = function() {
Game_Battler.prototype.makeActions.call(this);
if (this.numActions() > 0) {
var actionList = this.enemy().actions.filter(function(a) {
return this.isActionValid(a);
}, this);
if (actionList.length > 0) {
this.selectAllActions(actionList);
}
}
this.setActionState('waiting');
};
In the default battle system, makeActions is called upon the start of the actor input phase for all battlers(or action execution phase for all enemies if there's no inputable actors).
In a CTB system, it should be called right after the hidden CTB meter of a battler becomes full.
2. "how to make your actor input when you need it" is done by Scene_Battle.prototype.startActorCommandSelection:
Spoiler
JavaScript:
Scene_Battle.prototype.startActorCommandSelection = function() {
this._statusWindow.select(BattleManager.actor().index());
this._partyCommandWindow.close();
this._actorCommandWindow.setup(BattleManager.actor());
};
In the default battle system, startActorCommandSelection is called by either the fight command of the party command window or finishing inputting all actions of the currently inputting actor.
In a CTB system, when an actor becomes inputable, it should notify BattleManager to update its list of inputable actors, then BattleManager should notify Scene_Battle that the list of inputable actors has changed so it might need to setup the actor command window for a newly inputable actor, if no inputable actors' already selected for inputting actions(things can be simplified if you're sure there will only be at most 1 inputable actor at a time).
Setting up such an actor should be done by BattleManager.changeActor:
Spoiler
JavaScript:
BattleManager.changeActor = function(newActorIndex, lastActorActionState) {
var lastActor = this.actor();
this._actorIndex = newActorIndex;
var newActor = this.actor();
if (lastActor) {
lastActor.setActionState(lastActorActionState);
}
if (newActor) {
newActor.setActionState('inputting');
}
};
Combining everything can lead to codes like this:
Spoiler
JavaScript:
BattleManager.addCTBInputableActor = function(actor) {
if (this._ctbInputableActors.contains(actor)) return;
this._ctbInputableActors.push(actor);
this.changeActor(actor.index(), "");
if (!$gameParty.inBattle()) return;
SceneManager._scene.startActorCommandSelection();
}
Game_Battler.prototype.updateCTB = function() {
if (this.ctbMeter >= this.maxCTBMeter) return;
this.ctbMeter += this.ctbRate();
if (this.ctbMeter < this.maxCTBMeter) return;
this.onCTBBecomesFull();
};
Game_Battler.prototype.onCTBBecomesFull = function() {
this.makeActions();
};
Game_Actor.prototype.onCTBBecomesFull = function() {
Game_Battler.prototype.onCTBBecomesFull.call(this);
BattleManager.addCTBInputableActor(this);
};
Alternatively, if you're sure there will only be at most 1 inputable actor at a time:
Spoiler
JavaScript:
Game_Battler.prototype.updateCTB = function() {
if (this.ctbMeter >= this.maxCTBMeter) return;
this.ctbMeter += this.ctbRate();
if (this.ctbMeter < this.maxCTBMeter) return;
this.onCTBBecomesFull();
};
Game_Battler.prototype.onCTBBecomesFull = function() {
this.makeActions();
};
Game_Actor.prototype.onCTBBecomesFull = function() {
Game_Battler.prototype.onCTBBecomesFull.call(this);
BattleManager.changeActor(this.index(), "");
if (!$gameParty.inBattle()) return;
SceneManager._scene.startActorCommandSelection();
};
Of course, this snippet can't be just embedded as-is, as it's just an example to show 1 such possible high level flow regarding "making it a certain actor's or enemy's turn" and "how to make your actor input when you need it, and you'll still have to polish it to make it work in your CTB system plugin
🙂