Exemple #1
0
void TankGob::DefUpdate()
{
	// Try to make the turrent point toward the target (unless we're already firing)

	if (m_wptTarget.wx != kwxInvalid && !(m_wfMunt & kfMuntFiring)) {
		// Get the aim point. If we have a unit target, it is the unit's center
		// If we don't have a unit target, it is whatever is in m_wptTarget
		
		WPoint wptAim = m_wptTarget;
		Gob *pgobTarget = ggobm.GetGob(m_gidTarget);
		if (pgobTarget != NULL)
			pgobTarget->GetCenter(&wptAim);

		// If the target is in the tile we're in stop trying to look exactly at it

		if (WcTrunc(m_wx) != WcTrunc(wptAim.wx) || WcTrunc(m_wy) != WcTrunc(wptAim.wy)) {

			Direction16 dir16 = CalcDir16(wptAim.wx - m_wx, wptAim.wy - m_wy);

			// Make sure we're facing the way we want to go

			int d = dir16 - m_dir16Turret;
			if (d != 0) {
				if (d < -8)
					d = 1;
				else if (d > 8)
					d = -1;
				if (d < 0)
					m_dir16Turret--;
				else
					m_dir16Turret++;
				m_dir16Turret = ((unsigned int)m_dir16Turret) % 16;
				SetAnimationStrip(&m_aniTurret, m_pmuntc->anFiringStripIndices[m_dir16Turret]);
				m_unvl.MinSkip();
			}
		}
	}

	AdvanceAnimation(&m_aniTurret);

	MobileUnitGob::DefUpdate();
}
void NzSkeletalModel::Update()
{
	if (m_animationEnabled && m_animation)
		AdvanceAnimation(m_scene->GetUpdateTime());
}