// // This search function will sit with the turret deployed and look for a new target. // After a set amount of time, the barrel will spin down. After m_flMaxWait, the turret will // retact. // void CBaseTurret::SearchThink(void) { // ensure rethink SetTurretAnim(TURRET_ANIM_SPIN); StudioFrameAdvance( ); pev->nextthink = gpGlobals->time + 0.1; if (m_flSpinUpTime == 0 && m_flMaxSpin) m_flSpinUpTime = gpGlobals->time + m_flMaxSpin; Ping( ); // If we have a target and we're still healthy if (m_hEnemy != NULL) { if (!m_hEnemy->IsAlive() ) m_hEnemy = NULL;// Dead enemy forces a search for new one } // Acquire Target if (m_hEnemy == NULL) { Look(TURRET_RANGE); m_hEnemy = BestVisibleEnemy(); } // If we've found a target, spin up the barrel and start to attack if (m_hEnemy != NULL) { m_flLastSight = 0; m_flSpinUpTime = 0; SetThink(&CBaseTurret::ActiveThink); } else { // Are we out of time, do we need to retract? if (gpGlobals->time > m_flLastSight) { //Before we retrace, make sure that we are spun down. m_flLastSight = 0; m_flSpinUpTime = 0; SetThink(&CBaseTurret::Retire); } // should we stop the spin? else if ((m_flSpinUpTime) && (gpGlobals->time > m_flSpinUpTime)) { SpinDownCall(); } // generic hunt for new victims m_vecGoalAngles.y = (m_vecGoalAngles.y + 0.1 * m_fTurnRate); if (m_vecGoalAngles.y >= 360) m_vecGoalAngles.y -= 360; MoveTurret(); } }
//========================================================= // Retire - stop being active //========================================================= void CNPC_BaseTurret::Retire(void) { // make the turret level m_vecGoalAngles.x = 0; m_vecGoalAngles.y = m_flStartYaw; SetNextThink( gpGlobals->curtime + 0.1 ); StudioFrameAdvance( ); EyeOff( ); if (!MoveTurret()) { if (m_iSpin) { SpinDownCall(); } else if (GetSequence() != TURRET_ANIM_RETIRE) { SetTurretAnim(TURRET_ANIM_RETIRE); CPASAttenuationFilter filter( this ); EmitSound( filter, entindex(), "Turret.Undeploy" ); m_OnDeactivate.FireOutput(this, this); } //else if (IsSequenceFinished()) else if( GetSequence() == TURRET_ANIM_RETIRE && GetCycle() <= 0.0 ) { m_iOn = 0; m_flLastSight = 0; //SetTurretAnim(TURRET_ANIM_NONE); Vector curmins, curmaxs; curmins = WorldAlignMins(); curmaxs = WorldAlignMaxs(); curmaxs.z = m_iRetractHeight; curmins.z = -m_iRetractHeight; SetCollisionBounds( curmins, curmaxs ); if (m_iAutoStart) { SetThink(&CNPC_BaseTurret::AutoSearchThink); SetNextThink( gpGlobals->curtime + 0.1 ); } else { SetThink( &CBaseEntity::SUB_DoNothing ); } } } else { SetTurretAnim(TURRET_ANIM_SPIN); } }
void CBaseTurret::Retire(void) { // make the turret level m_vecGoalAngles.x = 0; m_vecGoalAngles.y = m_flStartYaw; pev->nextthink = gpGlobals->time + 0.1; StudioFrameAdvance( ); EyeOff( ); if (!MoveTurret()) { if (m_iSpin) { SpinDownCall(); } else if (pev->sequence != TURRET_ANIM_RETIRE) { SetTurretAnim(TURRET_ANIM_RETIRE); EMIT_SOUND_DYN(ENT(pev), CHAN_BODY, "turret/tu_deploy.wav", TURRET_MACHINE_VOLUME, ATTN_NORM, 0, 120); SUB_UseTargets( this, USE_OFF, 0 ); } else if (m_fSequenceFinished) { m_iOn = 0; m_flLastSight = 0; SetTurretAnim(TURRET_ANIM_NONE); pev->maxs.z = m_iRetractHeight; pev->mins.z = -m_iRetractHeight; UTIL_SetSize(pev, pev->mins, pev->maxs); if (m_iAutoStart) { SetThink(&CBaseTurret::AutoSearchThink); pev->nextthink = gpGlobals->time + .1; } else SetThink(&CBaseTurret::SUB_DoNothing); } } else { SetTurretAnim(TURRET_ANIM_SPIN); } }