@@ -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