CBaseMonster *CScriptedSentence::FindEntity( void ) { CBaseEntity* pTargetEnt = nullptr; CBaseMonster* pMonster = nullptr; while( (pTargetEnt = UTIL_FindEntityByTargetname( pTargetEnt, STRING( m_iszEntity ) )) ) { if( (pMonster = pTargetEnt->MyMonsterPointer()) ) { if( AcceptableSpeaker( pMonster ) ) return pMonster; //ALERT( at_console, "%s (%s), not acceptable\n", pMonster->GetClassname(), pMonster->GetTargetname() ); } } pTargetEnt = nullptr; while( (pTargetEnt = UTIL_FindEntityInSphere( pTargetEnt, GetAbsOrigin(), m_flRadius )) ) { if( pTargetEnt->ClassnameIs( m_iszEntity ) ) { if( pTargetEnt->GetFlags().Any( FL_MONSTER ) ) { pMonster = pTargetEnt->MyMonsterPointer(); if( AcceptableSpeaker( pMonster ) ) return pMonster; } } } return nullptr; }
// find a viable entity bool CCineMonster::FindEntity() { m_hTargetEnt = nullptr; CBaseEntity* pTargetEnt = nullptr; CBaseMonster* pTarget = nullptr; while( ( pTargetEnt = UTIL_FindEntityByTargetname( pTargetEnt, STRING( m_iszEntity ) ) ) != nullptr ) { if( pTargetEnt->GetFlags().Any( FL_MONSTER ) ) { pTarget = pTargetEnt->MyMonsterPointer(); if( pTarget && pTarget->CanPlaySequence( FCanOverrideState(), SS_INTERRUPT_BY_NAME ) ) { m_hTargetEnt = pTarget; return true; } ALERT( at_console, "Found %s, but can't play!\n", STRING( m_iszEntity ) ); } pTarget = nullptr; } if( !pTarget ) { pTargetEnt = nullptr; while( ( pTargetEnt = UTIL_FindEntityInSphere( pTargetEnt, GetAbsOrigin(), m_flRadius ) ) != nullptr ) { if( pTargetEnt->ClassnameIs( STRING( m_iszEntity ) ) ) { if( pTargetEnt->GetFlags().Any( FL_MONSTER ) ) { pTarget = pTargetEnt->MyMonsterPointer(); if( pTarget && pTarget->CanPlaySequence( FCanOverrideState(), SS_INTERRUPT_IDLE ) ) { m_hTargetEnt = pTarget; return true; } } } } } m_hTargetEnt = nullptr; return false; }
// find all the cinematic entities with my targetname and tell them to wait before starting void CCineMonster::DelayStart( const bool bState ) { CBaseEntity* pCine = nullptr; while( ( pCine = UTIL_FindEntityByTargetname( pCine, GetTargetname() ) ) != nullptr ) { if( pCine->ClassnameIs( "scripted_sequence" ) ) { CCineMonster *pTarget = static_cast<CCineMonster*>( pCine ); if( bState ) { pTarget->m_iDelay++; } else { pTarget->m_iDelay--; if( pTarget->m_iDelay <= 0 ) pTarget->m_startTime = gpGlobals->time + 0.05; } } } }
void CBaseDoor::Blocked( CBaseEntity *pOther ) { CBaseDoor *pDoor = NULL; // Hurt the blocker a little. if( GetDamage() ) pOther->TakeDamage( this, this, GetDamage(), DMG_CRUSH ); // if a door has a negative wait, it would never come back if blocked, // so let it just squash the object to death real fast if( m_flWait >= 0 ) { if( m_toggle_state == TS_GOING_DOWN ) { DoorGoUp(); } else { DoorGoDown(); } } // Block all door pieces with the same targetname here. if( HasTargetname() ) { CBaseEntity* pTarget = nullptr; while( ( pTarget = UTIL_FindEntityByTargetname( pTarget, GetTargetname() ) ) != nullptr ) { if( pTarget != this ) { if( pTarget->ClassnameIs( "func_door" ) || pTarget->ClassnameIs( "func_door_rotating" ) ) { pDoor = static_cast<CBaseDoor*>( pTarget ); if( pDoor->m_flWait >= 0 ) { //TODO: comparing avel with vel is probably wrong - Solokiller if( pDoor->GetAbsVelocity() == GetAbsVelocity() && pDoor->GetAngularVelocity() == GetAbsVelocity() ) { // this is the most hacked, evil, bastardized thing I've ever seen. kjb if( pTarget->ClassnameIs( "func_door" ) ) {// set origin to realign normal doors pDoor->SetAbsOrigin( GetAbsOrigin() ); pDoor->SetAbsVelocity( g_vecZero );// stop! } else {// set angles to realign rotating doors pDoor->SetAbsAngles( GetAbsAngles() ); pDoor->SetAngularVelocity( g_vecZero ); } } if( !GetSpawnFlags().Any( SF_DOOR_SILENT ) ) STOP_SOUND( this, CHAN_STATIC, ( char* ) STRING( pev->noiseMoving ) ); if( pDoor->m_toggle_state == TS_GOING_DOWN ) pDoor->DoorGoUp(); else pDoor->DoorGoDown(); } } } } } }