@@ -303,11 +303,8 @@ void leave_zone_and_reset_spawns(
303303 switch (ret){
304304 case 0 : // Found button A. Reached the gate.
305305 break ;
306- case 1 :
307- env.log (" Day/night change happened while escaping" );
308- env.console .overlay ().add_log (" Day/Night Change Detected" );
306+ case 1 : // Day/night change happened.
309307 {
310- wait_until_overworld (env.console , context);
311308 double current_facing_angle = get_current_facing_angle (env.console , context);
312309 double angle_between = std::fabs (starting_angle - current_facing_angle);
313310 if (angle_between > 180.0 ){
@@ -351,51 +348,28 @@ void leave_zone_and_reset_spawns(
351348 default :
352349 stats.errors ++;
353350 env.update_stats ();
354- #if 0
355- OperationFailedException::fire(
356- ErrorReport::SEND_ERROR_REPORT,
357- "leave_zone_and_reset_spawns(): Cannot run back to entrance after being chased by wild pokemon.",
358- env.console
359- );
360- #else
361351 throw UserSetupError (
362352 env.logger (),
363353 " Program stuck in the zone while escaping from wild pokemon. "
364354 " Pick a path that won't get you stuck by terrain or obstacles."
365355 );
366- #endif
367356 }
368357 shiny_sound_handler.process_pending (context);
369358
370359 // Found button A, so we are at the entrance.
371360 // Mash A to leave Zone.
372- env.log (" Found button A. Leaving Zone" );
373- env.console .overlay ().add_log (" Found Button A. Leaving Zone" );
374-
375- WallClock start_time = current_time ();
376- leave_zone_gate (env.console , context);
377- WallClock end_time = current_time ();
378- shiny_sound_handler.process_pending (context);
379361
380362 std::string extra_eror_msg = " This is after leaving zone." ;
381363
382- auto duration = end_time - start_time;
383- auto second_count = std::chrono::duration_cast<std::chrono::seconds>(duration).count ();
384364 // Due to day/night change may eating the mashing button A sequence, we may still be inside the zone!
385365 // We need to check if we can fast travel
386- if (duration < 16s){
387- env.log (" Leaving zone function took " + std::to_string (second_count) + " sec. No day/night change" );
388- // The animation of leaving the gate does not take more than 15 sec.
389- // In this case, there is no day/night change. We are sure we are outside the wild zone
390- // (unless some angry Garchomp or Drilbur used Dig and escaped wild zone containment... We don't
391- // consider this case for now)
366+ if (leave_zone_gate (env.console , context)){
367+ shiny_sound_handler.process_pending (context);
392368 // Do a fast travel outside the gate to reset spawns
393369 fast_travel_outside_zone (env, context, wild_zone, to_max_zoom_level_on_map, std::move (extra_eror_msg));
394370 return ;
395371 }
396372
397- env.log (" Leaving zone function took " + std::to_string (second_count) + " sec. Day/night change happened" );
398-
399373 // there is a day/night change while leaving the zone. We don't know if we are still inside the zone.
400374 FastTravelState travel_status = open_map_and_fly_in_place (env.console , context, to_max_zoom_level_on_map);
401375 if (travel_status == FastTravelState::SUCCESS){
@@ -419,6 +393,7 @@ void leave_zone_and_reset_spawns(
419393 // Mash A to leave zone gate
420394 env.log (" Mashing A again to leave zone" );
421395 leave_zone_gate (env.console , context);
396+ shiny_sound_handler.process_pending (context);
422397 // Do a fast travel outside the gate to reset spawns
423398 env.log (" Finally, we should have left the zone" );
424399 fast_travel_outside_zone (env, context, wild_zone, to_max_zoom_level_on_map, std::move (extra_eror_msg));
0 commit comments