Skip to content

Commit a3c3e8d

Browse files
author
Gin
committed
more cleanup
1 parent c518347 commit a3c3e8d

File tree

3 files changed

+21
-14
lines changed

3 files changed

+21
-14
lines changed

SerialPrograms/Source/PokemonLZA/Programs/PokemonLZA_BasicNavigation.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ void wait_until_overworld(
391391
}
392392

393393

394-
double get_current_facing_angle(
394+
double get_facing_direction(
395395
ConsoleHandle& console,
396396
ProControllerContext& context
397397
){
@@ -406,7 +406,7 @@ double get_current_facing_angle(
406406
console.overlay().add_log("No Minimap Arrow Found", COLOR_RED);
407407
OperationFailedException::fire(
408408
ErrorReport::SEND_ERROR_REPORT,
409-
"get_current_facing_angle(): Direction arrow on minimap not detected within 1 second",
409+
"get_facing_direction(): Direction arrow on minimap not detected within 1 second",
410410
console
411411
);
412412
}
@@ -416,6 +416,13 @@ double get_current_facing_angle(
416416
return angle;
417417
}
418418

419+
double get_angle_between_facing_directions(double dir1, double dir2){
420+
double angle = std::fabs(dir1 - dir2);
421+
if (angle > 180.0){
422+
angle = 360.0 - angle;
423+
}
424+
return angle;
425+
}
419426

420427
bool leave_zone_gate(ConsoleHandle& console, ProControllerContext& context){
421428
console.log("Leaving zone gate");

SerialPrograms/Source/PokemonLZA/Programs/PokemonLZA_BasicNavigation.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,10 @@ void wait_until_overworld(
9191
// Return a float of [0.0, 360.0), the angle of the arrow using the clock setting, i.e.
9292
// - Pointing upwards is 0.0 degree.
9393
// - Pointing to the right is 90.0 degrees.
94-
double get_current_facing_angle(ConsoleHandle& console, ProControllerContext& context);
94+
double get_facing_direction(ConsoleHandle& console, ProControllerContext& context);
95+
96+
// Given two facing directions, find the angle between them. The angle range is [0, 180).
97+
double get_angle_between_facing_directions(double dir1, double dir2);
9598

9699
// While at the gate in the zone, mash A to leave the zone. If day/night changes while
97100
// leaving, it will wait until the change is done.

SerialPrograms/Source/PokemonLZA/Programs/ShinyHunting/PokemonLZA_WildZoneEntrance.cpp

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ void leave_zone_and_reset_spawns(
296296
env.log("Escaping");
297297
env.console.overlay().add_log("Escaping Back to Entrance");
298298

299-
const double starting_angle = get_current_facing_angle(env.console, context);
299+
const double starting_direction = get_facing_direction(env.console, context);
300300

301301
const ImageFloatBox button_A_box{0.3, 0.2, 0.4, 0.7};
302302
int ret = run_towards_wild_zone_gate(env.console, context, button_A_box, 128, 255, walk_time_in_zone);
@@ -305,29 +305,26 @@ void leave_zone_and_reset_spawns(
305305
break;
306306
case 1: // Day/night change happened.
307307
{
308-
double current_facing_angle = get_current_facing_angle(env.console, context);
309-
double angle_between = std::fabs(starting_angle - current_facing_angle);
310-
if (angle_between > 180.0){
311-
angle_between = 360.0 - angle_between;
312-
}
313-
env.log("Facing angle difference after day/night change: " + tostr_fixed(angle_between, 0) + " deg, from "
314-
+ tostr_fixed(starting_angle, 0) + " to " + tostr_fixed(current_facing_angle, 0) + " deg");
308+
const double cur_direction = get_facing_direction(env.console, context);
309+
const double direction_change = get_angle_between_facing_directions(starting_direction, cur_direction);
310+
env.log("Facing direction difference after day/night change: " + tostr_fixed(direction_change, 0) + " deg, from "
311+
+ tostr_fixed(starting_direction, 0) + " to " + tostr_fixed(cur_direction, 0) + " deg");
315312

316313
uint8_t joystick_y = 0;
317-
if (angle_between > 150.0){
314+
if (direction_change > 150.0){
318315
// we are facing towards the gate
319316
env.log("Running forward");
320317
env.console.overlay().add_log("Running Forward");
321318
joystick_y = 0;
322-
}else if(angle_between < 30.0){
319+
}else if(direction_change < 30.0){
323320
// we are facing away from the gate
324321
env.log("Running back");
325322
env.console.overlay().add_log("Running Back");
326323
joystick_y = 255;
327324
}else{
328325
OperationFailedException::fire(
329326
ErrorReport::SEND_ERROR_REPORT,
330-
"leave_zone_and_reset_spawns(): Facing direction after day/night change is wrong: " + tostr_fixed(angle_between, 0) + " deg",
327+
"leave_zone_and_reset_spawns(): Facing direction after day/night change is wrong: " + tostr_fixed(direction_change, 0) + " deg",
331328
env.console
332329
);
333330
}

0 commit comments

Comments
 (0)