Skip to content

Commit

Permalink
Relocate CallMovementAction to the Map interpreter
Browse files Browse the repository at this point in the history
  • Loading branch information
Ghabry committed Nov 3, 2024
1 parent 16128f6 commit 875e012
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 74 deletions.
73 changes: 0 additions & 73 deletions src/game_interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -786,8 +786,6 @@ bool Game_Interpreter::ExecuteCommand(lcf::rpg::EventCommand const& com) {
return CommandManiacControlStrings(com);
case Cmd::Maniac_CallCommand:
return CommandManiacCallCommand(com);
case Cmd::EasyRpg_CallMovementAction:
return CommandCallMovement(com);
case Cmd::EasyRpg_SetInterpreterFlag:
return CommandEasyRpgSetInterpreterFlag(com);
case Cmd::EasyRpg_CloneMapEvent:
Expand Down Expand Up @@ -5081,77 +5079,6 @@ bool Game_Interpreter::CommandEasyRpgDestroyMapEvent(lcf::rpg::EventCommand cons
return true;
}

bool Game_Interpreter::CommandCallMovement(lcf::rpg::EventCommand const& com) {
// CommandSetMovement("moveCommand",[useVarID, ID, useVarOutput, output])

int eventID = ValueOrVariable(com.parameters[0], com.parameters[1]);
int outputParam = ValueOrVariable(com.parameters[2], com.parameters[3]);
int outputParamB = ValueOrVariable(com.parameters[4], com.parameters[5]);

Game_Character* event = GetCharacter(eventID);
Game_Character* target;

std::string moveCommand = ToString(com.string);
std::string outputString = event->GetSpriteName();

std::size_t pos = moveCommand.find('/');

if (pos != std::string::npos) {
outputString = moveCommand.substr(pos + 1);
moveCommand = moveCommand.substr(0, pos);
}

if (moveCommand == "SetMoveSpeed")event->SetMoveSpeed(outputParam);
if (moveCommand == "SetMoveFrequency")event->SetMoveFrequency(outputParam);
if (moveCommand == "SetTransparency")event->SetTransparency(outputParam);
if (moveCommand == "SetAnimationType")event->SetAnimationType(static_cast<Game_Character::AnimType>(outputParam));


if (moveCommand == "Event2Event") {
target = GetCharacter(outputParam);
if (!target) {
return true;
}
event->SetFacing(target->GetFacing());
event->SetDirection(target->GetDirection());
event->SetX(target->GetX());
event->SetY(target->GetY());
}

if (moveCommand == "FaceTowards"){
if(!event->IsMoving()) {
target = GetCharacter(outputParam);
if (!target) {
return true;
}
event->TurnTowardCharacter(*target);
event->UpdateFacing();
}
}

if (moveCommand == "FaceAway"){
if (!event->IsMoving()) {
target = GetCharacter(outputParam);
if (!target) {
return true;
}
event->TurnAwayFromCharacter(*target);
event->UpdateFacing();
}
}

if (moveCommand == "SetFacingLocked")event->SetFacingLocked(outputParam);
if (moveCommand == "SetLayer")event->SetLayer(outputParam);
if (moveCommand == "SetFlying")event->SetFlying(outputParam); //FIXME: I wish any event could imitate an airship, lacks more work.
if (moveCommand == "ChangeCharset")event->SetSpriteGraphic(outputString,outputParam); // syntax ChangeCharset/actor1

if (moveCommand == "JumpTo")event->Game_Character::Jump(outputParam, outputParamB);

if (moveCommand == "StopMovement")event->CancelMoveRoute();

return true;
}

Game_Interpreter& Game_Interpreter::GetForegroundInterpreter() {
return Game_Battle::IsBattleRunning()
? Game_Battle::GetInterpreter()
Expand Down
1 change: 0 additions & 1 deletion src/game_interpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,6 @@ class Game_Interpreter : public Game_BaseInterpreterContext
bool CommandEasyRpgSetInterpreterFlag(lcf::rpg::EventCommand const& com);
bool CommandEasyRpgCloneMapEvent(lcf::rpg::EventCommand const& com);
bool CommandEasyRpgDestroyMapEvent(lcf::rpg::EventCommand const& com);
bool CommandCallMovement(lcf::rpg::EventCommand const& com);

int DecodeInt(lcf::DBArray<int32_t>::const_iterator& it);
const std::string DecodeString(lcf::DBArray<int32_t>::const_iterator& it);
Expand Down
74 changes: 74 additions & 0 deletions src/game_interpreter_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ bool Game_Interpreter_Map::ExecuteCommand(lcf::rpg::EventCommand const& com) {
return CommandToggleAtbMode(com);
case Cmd::EasyRpg_TriggerEventAt:
return CommandEasyRpgTriggerEventAt(com);
case Cmd::EasyRpg_CallMovementAction:
return CommandEasyRpgCallMovementAction(com);
case Cmd::EasyRpg_WaitForSingleMovement:
return CommandEasyRpgWaitForSingleMovement(com);
default:
Expand Down Expand Up @@ -832,6 +834,78 @@ bool Game_Interpreter_Map::CommandEasyRpgTriggerEventAt(lcf::rpg::EventCommand c
return true;
}


bool Game_Interpreter_Map::CommandEasyRpgCallMovementAction(lcf::rpg::EventCommand const& com) {
// CommandSetMovement("moveCommand",[useVarID, ID, useVarOutput, output])

int eventID = ValueOrVariable(com.parameters[0], com.parameters[1]);
int outputParam = ValueOrVariable(com.parameters[2], com.parameters[3]);
int outputParamB = ValueOrVariable(com.parameters[4], com.parameters[5]);

Game_Character* event = GetCharacter(eventID);
Game_Character* target;

std::string moveCommand = ToString(com.string);
std::string outputString = event->GetSpriteName();

std::size_t pos = moveCommand.find('/');

if (pos != std::string::npos) {
outputString = moveCommand.substr(pos + 1);
moveCommand = moveCommand.substr(0, pos);
}

if (moveCommand == "SetMoveSpeed")event->SetMoveSpeed(outputParam);
if (moveCommand == "SetMoveFrequency")event->SetMoveFrequency(outputParam);
if (moveCommand == "SetTransparency")event->SetTransparency(outputParam);
if (moveCommand == "SetAnimationType")event->SetAnimationType(static_cast<Game_Character::AnimType>(outputParam));


if (moveCommand == "Event2Event") {
target = GetCharacter(outputParam);
if (!target) {
return true;
}
event->SetFacing(target->GetFacing());
event->SetDirection(target->GetDirection());
event->SetX(target->GetX());
event->SetY(target->GetY());
}

if (moveCommand == "FaceTowards"){
if(!event->IsMoving()) {
target = GetCharacter(outputParam);
if (!target) {
return true;
}
event->TurnTowardCharacter(*target);
event->UpdateFacing();
}
}

if (moveCommand == "FaceAway"){
if (!event->IsMoving()) {
target = GetCharacter(outputParam);
if (!target) {
return true;
}
event->TurnAwayFromCharacter(*target);
event->UpdateFacing();
}
}

if (moveCommand == "SetFacingLocked")event->SetFacingLocked(outputParam);
if (moveCommand == "SetLayer")event->SetLayer(outputParam);
if (moveCommand == "SetFlying")event->SetFlying(outputParam); //FIXME: I wish any event could imitate an airship, lacks more work.
if (moveCommand == "ChangeCharset")event->SetSpriteGraphic(outputString,outputParam); // syntax ChangeCharset/actor1

if (moveCommand == "JumpTo")event->Game_Character::Jump(outputParam, outputParamB);

if (moveCommand == "StopMovement")event->CancelMoveRoute();

return true;
}

bool Game_Interpreter_Map::CommandEasyRpgWaitForSingleMovement(lcf::rpg::EventCommand const& com) {
if (!Player::HasEasyRpgExtensions()) {
return true;
Expand Down
1 change: 1 addition & 0 deletions src/game_interpreter_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class Game_Interpreter_Map : public Game_Interpreter
bool CommandToggleAtbMode(lcf::rpg::EventCommand const& com);

bool CommandEasyRpgTriggerEventAt(lcf::rpg::EventCommand const& com);
bool CommandEasyRpgCallMovementAction(lcf::rpg::EventCommand const& com);
bool CommandEasyRpgWaitForSingleMovement(lcf::rpg::EventCommand const& com);

AsyncOp ContinuationShowInnStart(int indent, int choice_result, int price);
Expand Down

0 comments on commit 875e012

Please sign in to comment.