Skip to content

Commit

Permalink
Pathfinder: Allow providing frequency and skippable flag
Browse files Browse the repository at this point in the history
  • Loading branch information
Ghabry committed Feb 22, 2025
1 parent e40c1cd commit cec667f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/game_character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1053,7 +1053,7 @@ bool Game_Character::CalculateMoveRoute(const CalculateMoveRouteArgs& args) {
std::string debug_output_path("");
if (list_move.size() > 0) {
lcf::rpg::MoveRoute route;
// route.skippable = true;
route.skippable = args.skip_when_failed;
route.repeat = false;

for (SearchNode node2 : list_move) {
Expand All @@ -1075,7 +1075,7 @@ bool Game_Character::CalculateMoveRoute(const CalculateMoveRouteArgs& args) {
cmd.command_id = 23;
route.move_commands.push_back(cmd);

ForceMoveRoute(route, 8);
ForceMoveRoute(route, args.frequency);
}
if (args.debug_print) {
Output::Debug(
Expand Down
2 changes: 2 additions & 0 deletions src/game_character.h
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,9 @@ class Game_Character {
int32_t search_max = std::numeric_limits<int32_t>::max();
bool allow_diagonal = false;
bool debug_print = false;
bool skip_when_failed = false;
Span<int> event_id_ignore_list;
int frequency = 3;
};

bool CalculateMoveRoute(const CalculateMoveRouteArgs& args);
Expand Down
37 changes: 23 additions & 14 deletions src/game_interpreter_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -897,33 +897,47 @@ bool Game_Interpreter_Map::CommandEasyRpgPathfinder(lcf::rpg::EventCommand const
Parameter 4, 5: Target Y coordinate
Parameter 6, 7: Iteration limit when searching
Parameter 8, 9: Length of the route in tiles
Parameter 10: Flags (1 = Wait when moving, 2 = Allow diagonal, 4 = Debug log, 8 = Do nothing when moving)
Parameter 10: Flags (1 = Wait when moving, 2 = Allow diagonal,
4 = Debug log, 8 = Skip command when moving, 16 = "skippable" flag of the route)
Parameter 11, 12: Ignore Event IDs
Parameter 13+: Number of Event IDs specified by 12
Parameter 13 - 13+N: Number of Event IDs specified by 12
Parameter 13+N+1, 13+N+2: Move frequency (default 3)
*/

Game_Character::CalculateMoveRouteArgs args;

int event_id = ValueOrVariable(com.parameters[0], com.parameters[1]);
int dest_x = ValueOrVariable(com.parameters[2], com.parameters[3]);
int dest_y = ValueOrVariable(com.parameters[4], com.parameters[5]);
int search_max = ValueOrVariable(com.parameters[6], com.parameters[7]);
int steps_max = ValueOrVariable(com.parameters[8], com.parameters[9]);
args.dest_x = ValueOrVariable(com.parameters[2], com.parameters[3]);
args.dest_y = ValueOrVariable(com.parameters[4], com.parameters[5]);
args.search_max = ValueOrVariable(com.parameters[6], com.parameters[7]);
args.steps_max = ValueOrVariable(com.parameters[8], com.parameters[9]);

int flags = com.parameters[10];
bool wait_when_moving = (flags & 1) > 0;
bool allow_diagonal = (flags & 2) > 0;
bool debug_log = (flags & 4) > 0;
args.allow_diagonal = (flags & 2) > 0;
args.debug_print = (flags & 4) > 0;
bool skip_when_moving = (flags & 8) > 0;
args.skip_when_failed = (flags & 16) > 0;

std::vector<int> event_id_ignore_list;
int ni; // ni = next_index;
if (com.parameters[11] == 0) {
// Part of the command
int num_events_ids = com.parameters[12];
event_id_ignore_list = {com.parameters.begin() + 13, com.parameters.begin() + 13 + num_events_ids};
ni = 13 + num_events_ids;
} else {
// Read from variables
int var = ValueOrVariable(com.parameters[11], com.parameters[12]);
int num_events_ids = Main_Data::game_variables->Get(var);
event_id_ignore_list = Main_Data::game_variables->GetRange(var + 1, num_events_ids);
auto lst = Main_Data::game_variables->GetRange(var + 1, num_events_ids);
std::copy(lst.begin(), lst.end(), event_id_ignore_list.begin());
ni = 13;
}
args.event_id_ignore_list = event_id_ignore_list;

if (com.parameters.size() > ni + 1) {
args.frequency = ValueOrVariable(com.parameters[ni], com.parameters[ni + 1]);
}

Game_Character* chara = GetCharacter(event_id, "EasyRpgPathFinder");
Expand All @@ -939,11 +953,6 @@ bool Game_Interpreter_Map::CommandEasyRpgPathfinder(lcf::rpg::EventCommand const
}
}

Game_Character::CalculateMoveRouteArgs args {
dest_x, dest_y, steps_max, search_max, allow_diagonal,
debug_log, event_id_ignore_list
};

chara->CalculateMoveRoute(args);

return true;
Expand Down

0 comments on commit cec667f

Please sign in to comment.