/** * Animates a single step between hexes. * This will return before the animation actually finishes, allowing other * processing to occur during the animation. * * @param a The starting hex. * @param b The ending hex. * @param temp_unit The unit to animate (historically, a temporary unit). * @param step_num The number of steps taken so far (used to pick an animation). * @param step_left The number of steps remaining (used to pick an animation). * @param animator The unit_animator to use. This is assumed clear when we start, * but will likely not be clear when we return. * @param disp The game display. Assumed neither locked nor faked. * @returns The animation potential until this animation will finish. * INT_MIN indicates that no animation is pending. */ static int move_unit_between(const map_location& a, const map_location& b, unit_ptr temp_unit, unsigned int step_num, unsigned int step_left, unit_animator & animator, display& disp) { if ( disp.fogged(a) && disp.fogged(b) ) { return INT_MIN; } temp_unit->set_location(a); disp.invalidate(a); temp_unit->set_facing(a.get_relative_dir(b)); animator.replace_anim_if_invalid(temp_unit.get(),"movement",a,b,step_num, false,"",0,unit_animation::hit_type::INVALID,nullptr,nullptr,step_left); animator.start_animations(); animator.pause_animation(); disp.scroll_to_tiles(a, b, game_display::ONSCREEN, true, 0.0, false); animator.restart_animation(); // useless now, previous short draw() just did one // new_animation_frame(); int target_time = animator.get_animation_time_potential(); // target_time must be short to avoid jumpy move // std::cout << "target time: " << target_time << "\n"; // we round it to the next multiple of 200 target_time += 200; target_time -= target_time%200; // This code causes backwards teleport because the time > 200 causes offset > 1.0 // which will not match with the following -1.0 // if( target_time - animator.get_animation_time_potential() < 100 ) target_time +=200; return target_time; }
unit_map::umap_retval_pair_t unit_map::replace(const map_location& l, unit_ptr p) { self_check(); p->set_location(l); erase(l); return insert(p); }