Skip to content

Commit 6452470

Browse files
committed
Call Movement Action + Wait for Single Movement( can Detect fail cases)
Call Movement Action: `@raw 2050, "SetMoveSpeed", 0, 10001, 1, 3` @2050("typeOfAction",[targetIsVar,target, parameterIsvar, parameter]) ```js @raw 2051, "", 0, 10001 //Wait for Single Movement @raw 20140, "Fails to move x times", 8 // start fail branch @raw 10 //empty space for more cmds @raw 20141 // end of fail branch ``` ------------------------------- old commits comments: Update Feature - Support Detecting when Move Route Fails Thanks @MackValentine Mack for solving some Core Issues
1 parent ad6e823 commit 6452470

File tree

4 files changed

+107
-0
lines changed

4 files changed

+107
-0
lines changed

src/game_character.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,23 @@ void Game_Character::CancelMoveRoute() {
782782
SetMoveRouteFinished(false);
783783
}
784784

785+
bool Game_Character::isStuck(int i) {
786+
if(i == 0 ) i =1;
787+
int currentPose = 500;
788+
if (GetMoveRouteIndex() < GetMoveRoute().move_commands.size()) {
789+
if (IsStopping() && GetMoveRoute().move_commands[GetMoveRouteIndex()].command_id < 12) {
790+
failsMove++;
791+
} else {
792+
failsMove = 0;
793+
}
794+
} else {
795+
failsMove = 0;
796+
}
797+
798+
//Output::Warning("stuck? - {} {} {} -- {}", failsMove, IsPaused(), i, GetMaxStopCount());
799+
return failsMove > i && (GetStopCount() == 0 || GetStopCount() > GetMaxStopCount());
800+
}
801+
785802
int Game_Character::GetSpriteX() const {
786803
int x = GetX() * SCREEN_TILE_SIZE;
787804

src/game_character.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,9 @@ class Game_Character {
861861
static constexpr int GetDxFromDirection(int dir);
862862
static constexpr int GetDyFromDirection(int dir);
863863

864+
int failsMove = 0;
865+
bool isStuck(int i);
866+
864867
protected:
865868
explicit Game_Character(Type type, lcf::rpg::SaveMapEventBase* d);
866869
/** Check for and fix incorrect data after loading save game */

src/game_interpreter.cpp

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,10 @@ bool Game_Interpreter::ExecuteCommand(lcf::rpg::EventCommand const& com) {
821821
return CommandManiacSetGameOption(com);
822822
case Cmd::Maniac_CallCommand:
823823
return CommandManiacCallCommand(com);
824+
case static_cast<Game_Interpreter::Cmd>(2050): //Cmd::EasyRpg_CallMovement
825+
return CommandCallMovement(com);
826+
case static_cast<Game_Interpreter::Cmd>(2051): //Cmd::EasyRpg_WaitForMovement
827+
return CommandWaitForMovement(com);
824828
default:
825829
return true;
826830
}
@@ -4643,6 +4647,87 @@ bool Game_Interpreter::CommandManiacCallCommand(lcf::rpg::EventCommand const&) {
46434647
return true;
46444648
}
46454649

4650+
bool Game_Interpreter::CommandCallMovement(lcf::rpg::EventCommand const& com) {
4651+
// CommandSetMovement("moveCommand",[useVarID, ID, useVarOutput, output])
4652+
4653+
int eventID = ValueOrVariable(com.parameters[0], com.parameters[1]);
4654+
int outputParam = ValueOrVariable(com.parameters[2], com.parameters[3]);
4655+
4656+
Game_Character* event = GetCharacter(eventID);
4657+
Game_Character* target;
4658+
4659+
std::string moveCommand = ToString(com.string);
4660+
std::string outputString = event->GetSpriteName();
4661+
4662+
std::size_t pos = moveCommand.find('/');
4663+
4664+
if (pos != std::string::npos) {
4665+
outputString = moveCommand.substr(pos + 1);
4666+
moveCommand = moveCommand.substr(0, pos);
4667+
}
4668+
4669+
if (moveCommand == "SetMoveSpeed")event->SetMoveSpeed(outputParam);
4670+
if (moveCommand == "SetMoveFrequency")event->SetMoveFrequency(outputParam);
4671+
if (moveCommand == "SetTransparency")event->SetTransparency(outputParam);
4672+
4673+
if (moveCommand == "Event2Event") {
4674+
target = GetCharacter(outputParam);
4675+
event->SetFacing(target->GetFacing());
4676+
event->SetDirection(target->GetDirection());
4677+
event->SetX(target->GetX());
4678+
event->SetY(target->GetY());
4679+
}
4680+
4681+
if (moveCommand == "SetFacingLocked")event->SetFacingLocked(outputParam);
4682+
if (moveCommand == "SetLayer")event->SetLayer(outputParam);
4683+
if (moveCommand == "SetFlying")event->SetFlying(outputParam); //FIXME: I wish any event could imitate an airship, lacks more work.
4684+
if (moveCommand == "ChangeCharset")event->SetSpriteGraphic(outputString,outputParam); // syntax ChangeCharset/actor1
4685+
4686+
if (moveCommand == "StopMovement")event->CancelMoveRoute();
4687+
4688+
return true;
4689+
}
4690+
4691+
bool Game_Interpreter::CommandWaitForMovement(lcf::rpg::EventCommand const& com) {
4692+
// CommandWaitForMovement(useVarID, ID)
4693+
4694+
// Needed for ShowChoice
4695+
auto* frame = GetFramePtr();
4696+
const auto& list = frame->commands;
4697+
auto& index = frame->current_command;
4698+
4699+
// Retrieve event ID
4700+
int eventID = ValueOrVariable(com.parameters[0], com.parameters[1]);
4701+
if (eventID == 0)
4702+
eventID = GetCurrentEventId();
4703+
4704+
// Get the character associated with the event ID
4705+
Game_Character* ev = GetCharacter(eventID);
4706+
4707+
// Check if movement exists and if it's currently running
4708+
bool movementExists = !ev->GetMoveRoute().move_commands.empty();
4709+
bool movementIsRunning = movementExists && (ev->IsMoveRouteOverwritten() && !ev->IsMoveRouteFinished());
4710+
4711+
int i = frame->current_command + 1;
4712+
4713+
// Check the next command for a specific condition
4714+
const auto& cmd = list[i];
4715+
const int32_t failBranch = static_cast<int>(Cmd::ShowChoiceOption);
4716+
4717+
// If the next command is "Fails to move x times" and the character is stuck, cancel movement
4718+
if (cmd.code == failBranch && cmd.string == "Fails to move x times")
4719+
if (ev->isStuck(cmd.parameters[0])) {
4720+
ev->failsMove = 0;
4721+
ev->CancelMoveRoute();
4722+
frame->current_command = i + 1;
4723+
return true;
4724+
}
4725+
4726+
// Return false if movement is still in progress
4727+
if(!movementIsRunning) ev->failsMove = 0;
4728+
return !movementIsRunning;
4729+
}
4730+
46464731
Game_Interpreter& Game_Interpreter::GetForegroundInterpreter() {
46474732
return Game_Battle::IsBattleRunning()
46484733
? Game_Battle::GetInterpreter()

src/game_interpreter.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,8 @@ class Game_Interpreter
284284
bool CommandManiacChangePictureId(lcf::rpg::EventCommand const& com);
285285
bool CommandManiacSetGameOption(lcf::rpg::EventCommand const& com);
286286
bool CommandManiacCallCommand(lcf::rpg::EventCommand const& com);
287+
bool CommandCallMovement(lcf::rpg::EventCommand const& com);
288+
bool CommandWaitForMovement(lcf::rpg::EventCommand const& com);
287289

288290
int DecodeInt(lcf::DBArray<int32_t>::const_iterator& it);
289291
const std::string DecodeString(lcf::DBArray<int32_t>::const_iterator& it);

0 commit comments

Comments
 (0)