예제 #1
0
파일: unit.hpp 프로젝트: dodikk/iWesnoth
	/** Called on every draw */
	void refresh(const game_display& disp,const map_location& loc) {
		if (state_ == STATE_FORGET  && anim_ && anim_->animation_finished_potential()) {
			set_standing( loc);
			return;
		}
		if (state_ != STATE_STANDING || (get_current_animation_tick() < next_idling_) || incapacitated()) return;
		if (get_current_animation_tick() > next_idling_ + 1000) { // prevent all units animating at the same
			set_standing(loc);
		} else {
			set_idling(disp, loc);
		}
	}
void unit_animation_component::start_animation (int start_time, const unit_animation *animation,
	bool with_bars,  const std::string &text, Uint32 text_color, STATE state)
{
	const display * disp =  display::get_singleton();
	if (!animation) {
		if (state == STATE_STANDING)
			state_ = state;
		if (!anim_ && state_ != STATE_STANDING)
			set_standing(with_bars);
		return ;
	}
	state_ = state;
	// everything except standing select and idle
	bool accelerate = (state != STATE_FORGET && state != STATE_STANDING);
	draw_bars_ =  with_bars;
	anim_.reset(new unit_animation(*animation));
	const int real_start_time = start_time == INT_MAX ? anim_->get_begin_time() : start_time;
	anim_->start_animation(real_start_time, u_.loc_, u_.loc_.get_direction(u_.facing_),
		 text, text_color, accelerate);
	frame_begin_time_ = anim_->get_begin_time() -1;
	if (disp->idle_anim()) {
		next_idling_ = get_current_animation_tick()
			+ static_cast<int>((20000 + rand() % 20000) * disp->idle_anim_rate());
	} else {
		next_idling_ = INT_MAX;
	}
}
void unit_animation_component::refresh()
{
	if (state_ == STATE_FORGET && anim_ && anim_->animation_finished_potential())
	{
		set_standing();
		return;
	}
	display &disp = *display::get_singleton();
	if (state_ != STATE_STANDING || get_current_animation_tick() < next_idling_ ||
	    !disp.tile_nearly_on_screen(u_.loc_) || u_.incapacitated())
	{
		return;
	}
	if (get_current_animation_tick() > next_idling_ + 1000)
	{
		// prevent all units animating at the same time
		if (disp.idle_anim()) {
			next_idling_ = get_current_animation_tick()
				+ static_cast<int>((20000 + rand() % 20000) * disp.idle_anim_rate());
		} else {
			next_idling_ = INT_MAX;
		}
	} else {
		set_idling();
	}
}