Skip to content

Commit

Permalink
Debug enter town: Move outdoor location. Fix calref#664
Browse files Browse the repository at this point in the history
  • Loading branch information
NQNStudios committed Mar 1, 2025
1 parent b213378 commit 3fd8aa6
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 30 deletions.
20 changes: 15 additions & 5 deletions src/game/boe.actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2148,20 +2148,30 @@ void debug_magic_map() {
print_buf();
}

extern void outd_move_to_first_town_entrance(int town);

void debug_enter_town() {
if(recording){
record_action("debug_enter_town", "");
}

std::vector<std::string> town_names;
for(cTown* town : univ.scenario.towns){
town_names.push_back(town->name);
}
int town = get_num_response(0, univ.scenario.towns.size() - 1, "Enter Town Number", town_names);

if(has_feature_flag("debug-enter-town", "move-outdoors")){
end_town_mode(false, {0,0}, true);
outd_move_to_first_town_entrance(town);
}

short find_direction_from;
if(univ.party.direction == 0) find_direction_from = 2;
else if(univ.party.direction == 4) find_direction_from = 0;
else if(univ.party.direction < 4) find_direction_from = 3;
else find_direction_from = 1;
std::vector<std::string> town_names;
for(cTown* town : univ.scenario.towns){
town_names.push_back(town->name);
}
start_town_mode(get_num_response(0, univ.scenario.towns.size() - 1, "Enter Town Number", town_names), find_direction_from);
start_town_mode(town, find_direction_from);
}

void debug_refresh_stores() {
Expand Down
59 changes: 34 additions & 25 deletions src/game/boe.main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,11 @@ std::string help_text_rsrc = "help";
{"graphics-sheet", {"V2", "V3"}}
}
*/
std::map<std::string,std::vector<std::string>> feature_flags = {};
std::map<std::string,std::vector<std::string>> feature_flags = {
// Legacy behavior of the T debug action (used by some replays)
// does not change the party's outdoors location
{"debug-enter-town", {"move-outdoors"}}
};

struct cParseEntrance {
boost::optional<short>& opt;
Expand Down Expand Up @@ -406,6 +410,33 @@ static void process_args(int argc, char* argv[]) {
}
}

void outd_move_to_first_town_entrance(int town) {
// Try to put the party in an outdoor section from which you can enter the town --
// so when you leave, you'll hopefully be in the right place.
auto town_entrances = univ.scenario.find_town_entrances(town);
if(!town_entrances.empty()){
// When there are multiple entrances, this part of the code shouldn't matter,
// but also won't hurt.
town_entrance_t first_entrance_found = town_entrances[0];
int x = first_entrance_found.out_sec.x;
int y = first_entrance_found.out_sec.y;
// Very janky but I don't know how else to make it properly load the right sections and set i_w_c
while(univ.party.outdoor_corner.x > x){
shift_universe_left();
}
while(univ.party.outdoor_corner.x < x){
shift_universe_right();
}
while(univ.party.outdoor_corner.y > y){
shift_universe_up();
}
while(univ.party.outdoor_corner.y < y){
shift_universe_down();
}
outd_move_party(local_to_global(first_entrance_found.loc), true);
}
}

static void handle_scenario_args() {
bool resetting = false;
if(scen_arg_path){
Expand Down Expand Up @@ -455,30 +486,8 @@ static void handle_scenario_args() {
std::cerr << "Expected a scenario with at least " << (*scen_arg_town + 1) << " towns" << std::endl;
exit(1);
}
// Try to put the party in an outdoor section from which you can enter the town --
// so when you leave, you'll hopefully be in the right place.
auto town_entrances = univ.scenario.find_town_entrances(*scen_arg_town);
if(!town_entrances.empty()){
// When there are multiple entrances, this part of the code shouldn't matter,
// but also won't hurt.
town_entrance_t first_entrance_found = town_entrances[0];
int x = first_entrance_found.out_sec.x;
int y = first_entrance_found.out_sec.y;
// Very janky but I don't know how else to make it properly load the right sections and set i_w_c
while(univ.party.outdoor_corner.x > x){
shift_universe_left();
}
while(univ.party.outdoor_corner.x < x){
shift_universe_right();
}
while(univ.party.outdoor_corner.y > y){
shift_universe_up();
}
while(univ.party.outdoor_corner.y < y){
shift_universe_down();
}
outd_move_party(local_to_global(first_entrance_found.loc), true);
}

outd_move_to_first_town_entrance(*scen_arg_town);

short town_entrance = 0;
location town_location;
Expand Down

0 comments on commit 3fd8aa6

Please sign in to comment.