Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
MackValentine committed Nov 9, 2024
1 parent 14a024a commit deb9b6c
Show file tree
Hide file tree
Showing 25 changed files with 182 additions and 94 deletions.
2 changes: 1 addition & 1 deletion src/game_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ bool Game_Actor::IsSkillUsable(int skill_id) const {
else
Game_Map::GetInterpreter().Push(common_event);

common_event->ForceCreate(eventID);
common_event->ForceCreateNoCheck(eventID);
common_event->ForceUpdate(false);

}
Expand Down
7 changes: 6 additions & 1 deletion src/game_battlealgorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ void Game_BattleAlgorithm::AlgorithmBase::Start() {
}

// Target Var
int size = std::distance(targets.begin(), targets.end());
int size = 1;
if (GetType() == Type::Normal) {

size = 1;
Expand All @@ -415,6 +415,11 @@ void Game_BattleAlgorithm::AlgorithmBase::Start() {
}

}
else if (GetType() == Type::Skill) {
// Fix for multiple targets
auto* skill = static_cast<Game_BattleAlgorithm::Skill*>(this);
size = std::distance(skill->GetOriginalTargets().begin(), skill->GetOriginalTargets().end());
}

if (size > 1) {
if (current_target[0]->GetType() != source->GetType()) {
Expand Down
40 changes: 26 additions & 14 deletions src/game_commonevent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,6 @@ Game_CommonEvent::Game_CommonEvent(int common_event_id) :

}

void Game_CommonEvent::ForceCreate(int ce_ID) {
auto* ce = lcf::ReaderUtil::GetElement(lcf::Data::commonevents, ce_ID);

if ((ce->trigger == lcf::rpg::EventPage::Trigger_parallel || ce->ID == ManiacsBattle::Get_ATBCE() || ce->ID == ManiacsBattle::Get_TargetCE() ||
ce->ID == ManiacsBattle::Get_DamageCE() || ce->ID == ManiacsBattle::Get_StateCE() || ce->ID == ManiacsBattle::Get_StatsCE())
&& !ce->event_commands.empty())
{
interpreter.reset(new Game_Interpreter_Map());
interpreter->Push(this);
}
}

void Game_CommonEvent::SetSaveData(const lcf::rpg::SaveEventExecState& data) {
// RPG_RT Savegames have empty stacks for parallel events.
// We are LSD compatible but don't load these into interpreter.
Expand Down Expand Up @@ -80,12 +68,36 @@ AsyncOp Game_CommonEvent::Update(bool resume_async) {
void Game_CommonEvent::ForceCreate(int ce_ID) {
auto* ce = lcf::ReaderUtil::GetElement(lcf::Data::commonevents, ce_ID);

if ((ce->trigger == lcf::rpg::EventPage::Trigger_parallel || ce->ID == ManiacsBattle::Get_ATBCE() || ce->ID == ManiacsBattle::Get_TargetCE() ||
ce->ID == ManiacsBattle::Get_DamageCE() || ce->ID == ManiacsBattle::Get_StateCE() || ce->ID == ManiacsBattle::Get_StatsCE())
&& !ce->event_commands.empty())
{
if (!interpreter)
interpreter.reset(new Game_Interpreter_Map());
interpreter.reset(new Game_Interpreter_Map());
interpreter->Push(this);
}
}
void Game_CommonEvent::ForceCreateNoCheck(int ce_ID) {
auto* ce = lcf::ReaderUtil::GetElement(lcf::Data::commonevents, ce_ID);


{
interpreter.reset(new Game_Interpreter_Map());
interpreter->Push(this);
}
}
AsyncOp Game_CommonEvent::ForceUpdate(bool resume_async) {
if (interpreter) {
assert(interpreter->IsRunning());
interpreter->Update(!resume_async);

// Suspend due to async op ...
if (interpreter->IsAsyncPending()) {
return interpreter->GetAsyncOp();
}
}

return {};
}

AsyncOp Game_CommonEvent::UpdateBattle(bool resume_async, int ce_ID) {
if (interpreter) {
Expand Down
9 changes: 2 additions & 7 deletions src/game_commonevent.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ class Game_CommonEvent {
*/
AsyncOp ForceUpdate(bool resume_async);
void ForceCreate(int ce_ID);

void ForceCreateNoCheck(int ce_ID);
/**
* Gets common event index.
*
Expand Down Expand Up @@ -117,13 +119,6 @@ class Game_CommonEvent {
*/
bool IsWaitingBackgroundExecution(bool force_run) const;

/**
* Force creation of Common Event
*
* @param ce_ID Common Event ID
*/
void ForceCreate(int ce_ID);

private:
int common_event_id;

Expand Down
86 changes: 85 additions & 1 deletion src/game_interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,8 @@ bool Game_Interpreter::ExecuteCommand(lcf::rpg::EventCommand const& com) {
return CommandShowStringPicSelectable(com);
case 3029:
return CommandManiacControlMessage(com);
case Cmd::EnableCombo:
return CommandEnableCombo(com);
default:
return true;
}
Expand Down Expand Up @@ -4158,6 +4160,10 @@ bool Game_Interpreter::CommandChangeClass(lcf::rpg::EventCommand const& com) { /
}

int class_id = com.parameters[2]; // 0: No class, 1+: Specific class

int mode = 1;
class_id = ValueOrVariable(mode, com.parameters[2]);

bool level1 = com.parameters[3] > 0;
int skill_mode = com.parameters[4]; // no change, replace, add
int param_mode = com.parameters[5]; // no change, halve, level 1, current level
Expand Down Expand Up @@ -5595,6 +5601,30 @@ bool Game_Interpreter::CommandShowStringPicSelectable(lcf::rpg::EventCommand con
if (Main_Data::game_windows->GetWindow(picIndex).window->GetActive()) {
Main_Data::game_windows->GetWindow(picIndex).window->Update();

// *** Mouse controls

Point mouse_pos = Input::GetMousePosition();
int x = Main_Data::game_pictures->GetPicture(picIndex).sprite->GetX() - Main_Data::game_windows->GetWindow(picIndex).window->GetWidth() / 2;
int y = Main_Data::game_pictures->GetPicture(picIndex).sprite->GetY() - Main_Data::game_windows->GetWindow(picIndex).window->GetHeight() / 2;

int index = Main_Data::game_windows->GetWindow(picIndex).window->CursorHitTest({ mouse_pos.x - x, mouse_pos.y - y });

if (index >= 0)
DisplayUi->ChangeCursor(1);
if (index >= 0 && index != Main_Data::game_windows->GetWindow(picIndex).window->GetIndex() && Input::MouseMoved()) {
// FIXME: Index changed callback?
Main_Data::game_windows->GetWindow(picIndex).window->SetIndex(index);

Main_Data::game_system->SePlay(Main_Data::game_system->GetSystemSE(Main_Data::game_system->SFX_Cursor));
}

if (index == -1 && Input::MouseMoved() && Main_Data::game_windows->GetWindow(picIndex).window->GetIndex() != -999) {
Main_Data::game_windows->GetWindow(picIndex).window->SetMouseOldIndex(Main_Data::game_windows->GetWindow(picIndex).window->GetIndex());
Main_Data::game_windows->GetWindow(picIndex).window->SetIndex(-999);
}

// ***

if (Input::IsTriggered(Input::CANCEL)) {
Main_Data::game_system->SePlay(Main_Data::game_system->GetSystemSE(Main_Data::game_system->SFX_Cancel));
int choice_result = Main_Data::game_windows->GetWindow(picIndex).window->GetPageItemMax();
Expand Down Expand Up @@ -5635,10 +5665,13 @@ bool Game_Interpreter::CommandShowStringPicSelectable(lcf::rpg::EventCommand con
return true;
}
if (Input::IsTriggered(Input::DECISION)) {
Main_Data::game_system->SePlay(Main_Data::game_system->GetSystemSE(Main_Data::game_system->SFX_Decision));
int choice_result = Main_Data::game_windows->GetWindow(picIndex).window->GetIndex();
//Output::Debug("CONFIRM {}", choice_result);
if (choice_result == -999) {
return false;
}

Main_Data::game_system->SePlay(Main_Data::game_system->GetSystemSE(Main_Data::game_system->SFX_Decision));

int label_id = com.parameters[0];

Expand Down Expand Up @@ -5678,6 +5711,7 @@ bool Game_Interpreter::CommandShowStringPicSelectable(lcf::rpg::EventCommand con
//Output::Debug("!Active");
Main_Data::game_windows->GetWindow(picIndex).window->SetIndex(0);
Main_Data::game_windows->GetWindow(picIndex).window->SetActive(true);

auto text = Main_Data::game_windows->GetWindow(picIndex).data.texts;
int maxItem = 0;
for (const auto& text : text) {
Expand All @@ -5696,6 +5730,29 @@ bool Game_Interpreter::CommandShowStringPicSelectable(lcf::rpg::EventCommand con
else if (type == 2) {
Main_Data::game_windows->GetWindow(picIndex).window->Update();

// *** Mouse controls

Point mouse_pos = Input::GetMousePosition();
int x = Main_Data::game_pictures->GetPicture(picIndex).sprite->GetX() - Main_Data::game_windows->GetWindow(picIndex).window->GetWidth() / 2;
int y = Main_Data::game_pictures->GetPicture(picIndex).sprite->GetY() - Main_Data::game_windows->GetWindow(picIndex).window->GetHeight() / 2;

int index = Main_Data::game_windows->GetWindow(picIndex).window->CursorHitTest({ mouse_pos.x - x, mouse_pos.y - y });
if (index >= 0)
DisplayUi->ChangeCursor(1);
if (index >= 0 && index != Main_Data::game_windows->GetWindow(picIndex).window->GetIndex() && Input::MouseMoved()) {
// FIXME: Index changed callback?
Main_Data::game_windows->GetWindow(picIndex).window->SetIndex(index);

Main_Data::game_system->SePlay(Main_Data::game_system->GetSystemSE(Main_Data::game_system->SFX_Cursor));
}

if (index == -1 && Input::MouseMoved() && Main_Data::game_windows->GetWindow(picIndex).window->GetIndex() != -999) {
Main_Data::game_windows->GetWindow(picIndex).window->SetMouseOldIndex(Main_Data::game_windows->GetWindow(picIndex).window->GetIndex());
Main_Data::game_windows->GetWindow(picIndex).window->SetIndex(-999);
}

// ***

int variableID = ValueOrVariable(com.parameters[3], com.parameters[4]);
int value = Main_Data::game_windows->GetWindow(picIndex).window->GetIndex();
Main_Data::game_variables->Set(variableID, value);
Expand All @@ -5706,3 +5763,30 @@ bool Game_Interpreter::CommandShowStringPicSelectable(lcf::rpg::EventCommand con
}
return true;
}

bool Game_Interpreter::CommandEnableCombo(lcf::rpg::EventCommand const& com) {
if (!Player::IsRPG2k3Commands()) {
return true;
}


int actor_id = com.parameters[0];

if (!Main_Data::game_party->IsActorInParty(actor_id)) {
return true;
}

int command_id = com.parameters[1];
int multiple = com.parameters[2];

Game_Actor* actor = Main_Data::game_actors->GetActor(actor_id);

if (!actor) {
Output::Warning("EnableCombo: Invalid actor ID {}", actor_id);
return true;
}

actor->SetBattleCombo(command_id, multiple);

return true;
}
3 changes: 2 additions & 1 deletion src/game_interpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,8 @@ class Game_Interpreter
bool CommandForceSelectingActor(lcf::rpg::EventCommand const& com);
bool CommandShowStringPicSelectable(lcf::rpg::EventCommand const& com);
bool CommandManiacControlMessage(lcf::rpg::EventCommand const& com);

bool CommandEnableCombo(lcf::rpg::EventCommand const& com);

void tokenize(std::string const& str, const char delim, std::vector<std::string>& out);
void tokenizeRegex(std::string const& str, const char delim, std::vector<std::string>& out);

Expand Down
26 changes: 0 additions & 26 deletions src/game_interpreter_battle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,6 @@ bool Game_Interpreter_Battle::ExecuteCommand(lcf::rpg::EventCommand const& com)
return CommandCallCommonEvent(com);
case Cmd::ForceFlee:
return CommandForceFlee(com);
case Cmd::EnableCombo:
return CommandEnableCombo(com);
case Cmd::ChangeMonsterHP:
return CommandChangeMonsterHP(com);
case Cmd::ChangeMonsterMP:
Expand Down Expand Up @@ -297,31 +295,7 @@ bool Game_Interpreter_Battle::CommandForceFlee(lcf::rpg::EventCommand const& com
return true;
}

bool Game_Interpreter_Battle::CommandEnableCombo(lcf::rpg::EventCommand const& com) {
if (!Player::IsRPG2k3Commands()) {
return true;
}

int actor_id = com.parameters[0];

if (!Main_Data::game_party->IsActorInParty(actor_id)) {
return true;
}

int command_id = com.parameters[1];
int multiple = com.parameters[2];

Game_Actor* actor = Main_Data::game_actors->GetActor(actor_id);

if (!actor) {
Output::Warning("EnableCombo: Invalid actor ID {}", actor_id);
return true;
}

actor->SetBattleCombo(command_id, multiple);

return true;
}

bool Game_Interpreter_Battle::CommandChangeMonsterHP(lcf::rpg::EventCommand const& com) {
auto* enemy = Main_Data::game_enemyparty->GetEnemy(com.parameters[0]);
Expand Down
1 change: 0 additions & 1 deletion src/game_interpreter_battle.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ class Game_Interpreter_Battle : public Game_Interpreter
private:
bool CommandCallCommonEvent(lcf::rpg::EventCommand const& com);
bool CommandForceFlee(lcf::rpg::EventCommand const& com);
bool CommandEnableCombo(lcf::rpg::EventCommand const& com);
bool CommandChangeMonsterHP(lcf::rpg::EventCommand const& com);
bool CommandChangeMonsterMP(lcf::rpg::EventCommand const& com);
bool CommandChangeMonsterCondition(lcf::rpg::EventCommand const& com);
Expand Down
20 changes: 18 additions & 2 deletions src/scene_battle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,13 +291,29 @@ void Scene_Battle::CreateUi() {

}

win_name = "Help";
it2 = CustomBattle::customWindows.find(win_name);

if (it2 != CustomBattle::customWindows.end()) {

help_window->SetX(CustomBattle::customWindows[win_name].x);
help_window->SetY(CustomBattle::customWindows[win_name].y);
help_window->SetWidth(CustomBattle::customWindows[win_name].w);
help_window->SetHeight(CustomBattle::customWindows[win_name].h);
help_window->SetOpacity(CustomBattle::customWindows[win_name].opacity);
help_window->SetBackOpacity(CustomBattle::customWindows[win_name].opacity);

help_window->SetVisible(!CustomBattle::customWindows[win_name].hide);

}

win_name = "Skills";
it2 = CustomBattle::customWindows.find(win_name);


if (it2 != CustomBattle::customWindows.end()) {

skill_window.reset(new Window_BattleSkillCustom(Player::menu_offset_x, (Player::menu_offset_y + MENU_HEIGHT - 80), MENU_WIDTH, 80));
skill_window.reset(new Window_BattleSkillCustom(this, Player::menu_offset_x, (Player::menu_offset_y + MENU_HEIGHT - 80), MENU_WIDTH, 80));

skill_window->SetX(CustomBattle::customWindows[win_name].x);
skill_window->SetY(CustomBattle::customWindows[win_name].y);
Expand All @@ -315,7 +331,7 @@ void Scene_Battle::CreateUi() {
}
else {

skill_window.reset(new Window_BattleSkill(Player::menu_offset_x, (Player::menu_offset_y + MENU_HEIGHT - 80), MENU_WIDTH, 80));
skill_window.reset(new Window_BattleSkill(this, Player::menu_offset_x, (Player::menu_offset_y + MENU_HEIGHT - 80), MENU_WIDTH, 80));

skill_window->SetHelpWindow(help_window.get());
}
Expand Down
Loading

0 comments on commit deb9b6c

Please sign in to comment.