Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Battle 2k3: Implement in-battle row command #2322

Merged
merged 2 commits into from Sep 10, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 74 additions & 37 deletions src/scene_battle_rpg2k3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,7 @@ void Scene_Battle_Rpg2k3::CreateBattleCommandWindow() {
}
++i;
}
commands.push_back(ToString(lcf::Data::terms.row));
}

command_window.reset(new Window_Command(commands, option_command_mov));
Expand Down Expand Up @@ -1198,43 +1199,49 @@ void Scene_Battle_Rpg2k3::OptionSelected() {
}

void Scene_Battle_Rpg2k3::CommandSelected() {
const lcf::rpg::BattleCommand* command = active_actor->GetBattleCommands()[command_window->GetIndex()];

switch (command->type) {
case lcf::rpg::BattleCommand::Type_attack:
AttackSelected();
break;
case lcf::rpg::BattleCommand::Type_defense:
DefendSelected();
break;
case lcf::rpg::BattleCommand::Type_escape:
if (!IsEscapeAllowedFromActorCommand()) {
Game_System::SePlay(Game_System::GetSystemSE(Game_System::SFX_Buzzer));
}
else {
int index = command_window->GetIndex();
// Row command always uses the last index
if (index < command_window->GetRowMax() - 1) {
const lcf::rpg::BattleCommand* command = active_actor->GetBattleCommands()[index];

switch (command->type) {
case lcf::rpg::BattleCommand::Type_attack:
AttackSelected();
break;
case lcf::rpg::BattleCommand::Type_defense:
DefendSelected();
break;
case lcf::rpg::BattleCommand::Type_escape:
if (!IsEscapeAllowedFromActorCommand()) {
Game_System::SePlay(Game_System::GetSystemSE(Game_System::SFX_Buzzer));
}
else {
Game_System::SePlay(Game_System::GetSystemSE(Game_System::SFX_Decision));
active_actor->SetAtbGauge(0);
SetState(State_Escape);
}
break;
case lcf::rpg::BattleCommand::Type_item:
Game_System::SePlay(Game_System::GetSystemSE(Game_System::SFX_Decision));
SetState(State_SelectItem);
break;
case lcf::rpg::BattleCommand::Type_skill:
Game_System::SePlay(Game_System::GetSystemSE(Game_System::SFX_Decision));
skill_window->SetSubsetFilter(0);
sp_window->SetBattler(*active_actor);
SetState(State_SelectSkill);
break;
case lcf::rpg::BattleCommand::Type_special:
Game_System::SePlay(Game_System::GetSystemSE(Game_System::SFX_Decision));
SpecialSelected();
break;
case lcf::rpg::BattleCommand::Type_subskill:
Game_System::SePlay(Game_System::GetSystemSE(Game_System::SFX_Decision));
active_actor->SetAtbGauge(0);
SetState(State_Escape);
SubskillSelected();
break;
}
break;
case lcf::rpg::BattleCommand::Type_item:
Game_System::SePlay(Game_System::GetSystemSE(Game_System::SFX_Decision));
SetState(State_SelectItem);
break;
case lcf::rpg::BattleCommand::Type_skill:
Game_System::SePlay(Game_System::GetSystemSE(Game_System::SFX_Decision));
skill_window->SetSubsetFilter(0);
sp_window->SetBattler(*active_actor);
SetState(State_SelectSkill);
break;
case lcf::rpg::BattleCommand::Type_special:
Game_System::SePlay(Game_System::GetSystemSE(Game_System::SFX_Decision));
SpecialSelected();
break;
case lcf::rpg::BattleCommand::Type_subskill:
Game_System::SePlay(Game_System::GetSystemSE(Game_System::SFX_Decision));
SubskillSelected();
break;
} else {
RowSelected();
}
}

Expand Down Expand Up @@ -1277,6 +1284,30 @@ void Scene_Battle_Rpg2k3::SpecialSelected() {
ActionSelectedCallback(active_actor);
}

void Scene_Battle_Rpg2k3::RowSelected() {
// Switching rows is only possible if in back row or
// if at least 2 party members are in front row
int current_row = active_actor->GetBattleRow();
int front_row_battlers = 0;
if (current_row == active_actor->IsDirectionFlipped()) {
for (auto& actor: Main_Data::game_party->GetActors()) {
if (actor->GetBattleRow() == actor->IsDirectionFlipped()) front_row_battlers++;
}
}
Copy link
Contributor

@mateofio mateofio Sep 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This case doesn't appear to handle back attacks etc..

I checked in RE tools and found that RPG_RT counts the number of actors which row == mirrored and then allows the row command if count >= 2 || current_hero.row != current_hero.mirrored

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did the change as requested and tested it. I have amended the commit and force pushed it because I assume you want this in one commit.

if (current_row != active_actor->IsDirectionFlipped() || front_row_battlers >= 2) {
if (active_actor->GetBattleRow() == Game_Actor::RowType::RowType_front) {
active_actor->SetBattleRow(Game_Actor::RowType::RowType_back);
} else {
active_actor->SetBattleRow(Game_Actor::RowType::RowType_front);
}
active_actor->SetBattlePosition(Game_Battle::Calculate2k3BattlePosition(*active_actor));
active_actor->SetBattleAlgorithm(std::make_shared<Game_BattleAlgorithm::NoMove>(active_actor));
ActionSelectedCallback(active_actor);
} else {
Game_System::SePlay(Game_System::GetSystemSE(Game_System::SFX_Buzzer));
}
}

void Scene_Battle_Rpg2k3::Escape(bool force_allow) {
if (force_allow || TryEscape()) {
// There is no success text for escape in 2k3
Expand Down Expand Up @@ -1461,8 +1492,14 @@ void Scene_Battle_Rpg2k3::ActionSelectedCallback(Game_Battler* for_battler) {
for_battler->SetAtbGauge(0);

if (for_battler->GetType() == Game_Battler::Type_Ally) {
const lcf::rpg::BattleCommand* command = static_cast<Game_Actor*>(for_battler)->GetBattleCommands()[command_window->GetIndex()];
for_battler->SetLastBattleAction(command->ID);
int index = command_window->GetIndex();
// Row command always uses the last index
if (index < command_window->GetRowMax() - 1) {
const lcf::rpg::BattleCommand* command = static_cast<Game_Actor*>(for_battler)->GetBattleCommands()[index];
for_battler->SetLastBattleAction(command->ID);
} else {
for_battler->SetLastBattleAction(-1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This must be verified because the last battle action is a battle page start condition (or was it a condition in a conditional branch?). So this value must match.
Even if the row command can't be picked there through the editor I bet there is at least one game that patched the value and checks for it (see Change Vehicle position with -1)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-1 is indeed the Row command, just tested this via LDB-patching 🤔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure it's actually -1. The logic I've seen in RPG_RT is usually something like this:

auto* batcmd = GetBattleCommandByIndex(window->currentchoice);
if (batcmd) {
  switch(batcmd->type) {
    // Handle each command
  }
} else {
  // Handle row command
}

What if you try -2 or a large value greater than the number of configured battle commands?

Copy link
Member

@Ghabry Ghabry Sep 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only tested -1 and -2. -2 didn't activate my event page. Note that I talk about the page condition, not about the Command index in the menu.

Copy link
Member

@Ghabry Ghabry Sep 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Figured it out by now: That's (kinda) a bug. Only kinda because this needs external tools to be utilized:

The GetBattleCommandByIndex function checks if the cmd idx is >= 6 and if yes it returns -1.
Otherwise it resolves the battle command of the actor. For the row this is 0.

Conclusion:
When an actor has 6 battle commands then row has an action ID of -1, otherwise it has an action ID of 0.

@rueter37 can you implement this behaviour? (SetLastBattleAction(-1) for "all/6 cmds", else SetLastBattleAction(0)). And add a comment that this is RPG_RT behaviour.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the LastBattleAction changes.

}
status_window->SetIndex(-1);
}

Expand Down
1 change: 1 addition & 0 deletions src/scene_battle_rpg2k3.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ class Scene_Battle_Rpg2k3 : public Scene_Battle {
void AttackSelected() override;
void SubskillSelected();
void SpecialSelected();
void RowSelected();

void Escape(bool force_allow = false);

Expand Down