void CController :: StartTask ( const Task_t& task ) { switch ( task.iTask ) { case TASK_RANGE_ATTACK1: CSquadMonster :: StartTask ( task ); break; case TASK_GET_PATH_TO_ENEMY_LKP: { if (BuildNearestRoute( m_vecEnemyLKP, GetViewOffset(), task.flData, (m_vecEnemyLKP - GetAbsOrigin()).Length() + 1024 )) { TaskComplete(); } else { // no way to get there =( ALERT ( at_aiconsole, "GetPathToEnemyLKP failed!!\n" ); TaskFail(); } break; } case TASK_GET_PATH_TO_ENEMY: { CBaseEntity *pEnemy = m_hEnemy; if ( pEnemy == NULL ) { TaskFail(); return; } if (BuildNearestRoute( pEnemy->GetAbsOrigin(), pEnemy->GetViewOffset(), task.flData, (pEnemy->GetAbsOrigin() - GetAbsOrigin()).Length() + 1024 )) { TaskComplete(); } else { // no way to get there =( ALERT ( at_aiconsole, "GetPathToEnemy failed!!\n" ); TaskFail(); } break; } default: CSquadMonster :: StartTask ( task ); break; } }
void CAI_PlaneSolver::GenerateObstacleNpcs( const AILocalMoveGoal_t &goal, float probeDist ) { if ( !ProbeForNpcs() ) { CAI_BaseNPC **ppAIs = g_AI_Manager.AccessAIs(); Vector minsSelf, maxsSelf; m_pNpc->CollisionProp()->WorldSpaceSurroundingBounds( &minsSelf, &maxsSelf ); float radiusSelf = (minsSelf.AsVector2D() - maxsSelf.AsVector2D()).Length() * 0.5; for ( int i = 0; i < g_AI_Manager.NumAIs(); i++ ) { CAI_BaseNPC *pAI = ppAIs[i]; if ( pAI != m_pNpc && pAI->IsAlive() && ( !goal.pPath || pAI != goal.pPath->GetTarget() ) ) { Vector mins, maxs; pAI->CollisionProp()->WorldSpaceSurroundingBounds( &mins, &maxs ); if ( mins.z < maxsSelf.z + 12.0 && maxs.z > minsSelf.z - 12.0 ) { float radius = (mins.AsVector2D() - maxs.AsVector2D()).Length() * 0.5; float distance = ( pAI->GetAbsOrigin().AsVector2D() - m_pNpc->GetAbsOrigin().AsVector2D() ).Length(); if ( distance - radius < radiusSelf + probeDist ) { AddObstacle( pAI->WorldSpaceCenter(), radius, pAI, AIMST_AVOID_NPC ); } } } } CBaseEntity *pPlayer = UTIL_PlayerByIndex( 1 ); if ( pPlayer ) { Vector mins, maxs; pPlayer->CollisionProp()->WorldSpaceSurroundingBounds( &mins, &maxs ); if ( mins.z < maxsSelf.z + 12.0 && maxs.z > minsSelf.z - 12.0 ) { float radius = (mins.AsVector2D() - maxs.AsVector2D()).Length(); float distance = ( pPlayer->GetAbsOrigin().AsVector2D() - m_pNpc->GetAbsOrigin().AsVector2D() ).Length(); if ( distance - radius < radiusSelf + probeDist ) { AddObstacle( pPlayer->WorldSpaceCenter(), radius, pPlayer, AIMST_AVOID_NPC ); } } } } }
void CSDKPlayer::MoveToNextIntroCamera() { m_pIntroCamera = gEntList.FindEntityByClassname( m_pIntroCamera, "point_viewcontrol" ); // if m_pIntroCamera is NULL we just were at end of list, start searching from start again if(!m_pIntroCamera) m_pIntroCamera = gEntList.FindEntityByClassname(m_pIntroCamera, "point_viewcontrol"); // find the target CBaseEntity *Target = NULL; if( m_pIntroCamera ) { Target = gEntList.FindEntityByName( NULL, STRING(m_pIntroCamera->m_target) ); } // if we still couldn't find a camera, goto T spawn if(!m_pIntroCamera) m_pIntroCamera = gEntList.FindEntityByClassname(m_pIntroCamera, "info_player_terrorist"); SetViewOffset( vec3_origin ); // no view offset UTIL_SetSize( this, vec3_origin, vec3_origin ); // no bbox if( !Target ) //if there are no cameras(or the camera has no target, find a spawn point and black out the screen { if ( m_pIntroCamera.IsValid() ) SetAbsOrigin( m_pIntroCamera->GetAbsOrigin() + VEC_VIEW ); SetAbsAngles( QAngle( 0, 0, 0 ) ); m_pIntroCamera = NULL; // never update again return; } Vector vCamera = Target->GetAbsOrigin() - m_pIntroCamera->GetAbsOrigin(); Vector vIntroCamera = m_pIntroCamera->GetAbsOrigin(); VectorNormalize( vCamera ); QAngle CamAngles; VectorAngles( vCamera, CamAngles ); SetAbsOrigin( vIntroCamera ); SetAbsAngles( CamAngles ); SnapEyeAngles( CamAngles ); m_fIntroCamTime = gpGlobals->curtime + 6; }
void C_HL2MP_Player::ClientThink( void ) { bool bFoundViewTarget = false; Vector vForward; AngleVectors( GetLocalAngles(), &vForward ); for( int iClient = 1; iClient <= gpGlobals->maxClients; ++iClient ) { CBaseEntity *pEnt = UTIL_PlayerByIndex( iClient ); if(!pEnt || !pEnt->IsPlayer()) continue; if ( pEnt->entindex() == entindex() ) continue; Vector vTargetOrigin = pEnt->GetAbsOrigin(); Vector vMyOrigin = GetAbsOrigin(); Vector vDir = vTargetOrigin - vMyOrigin; if ( vDir.Length() > 128 ) continue; VectorNormalize( vDir ); if ( DotProduct( vForward, vDir ) < 0.0f ) continue; m_vLookAtTarget = pEnt->EyePosition(); bFoundViewTarget = true; break; } if ( bFoundViewTarget == false ) { m_vLookAtTarget = GetAbsOrigin() + vForward * 512; } UpdateIDTarget(); // Avoidance if ( gpGlobals->curtime >= m_fNextThinkPushAway ) { PerformObstaclePushaway( this ); m_fNextThinkPushAway = gpGlobals->curtime + PUSHAWAY_THINK_INTERVAL; } }
//========================================================= //========================================================= CBaseEntity *CGameRules::GetPlayerSpawnSpot( CBasePlayer *pPlayer ) { CBaseEntity *pSpawnSpot = pPlayer->EntSelectSpawnPoint(); Assert( pSpawnSpot ); if ( pSpawnSpot == NULL ) return NULL; pPlayer->SetLocalOrigin( pSpawnSpot->GetAbsOrigin() + Vector(0,0,1) ); pPlayer->SetAbsVelocity( vec3_origin ); pPlayer->SetLocalAngles( pSpawnSpot->GetLocalAngles() ); pPlayer->m_Local.m_vecPunchAngle = vec3_angle; pPlayer->m_Local.m_vecPunchAngleVel = vec3_angle; pPlayer->SnapEyeAngles( pSpawnSpot->GetLocalAngles() ); return pSpawnSpot; }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CEnvLaser::StrikeThink( void ) { CBaseEntity *pEnd = RandomTargetname( STRING( m_iszLaserTarget ) ); Vector vecFireAt = GetAbsEndPos(); if ( pEnd ) { vecFireAt = pEnd->GetAbsOrigin(); } trace_t tr; UTIL_TraceLine( GetAbsOrigin(), vecFireAt, MASK_SOLID, NULL, COLLISION_GROUP_NONE, &tr ); FireAtPoint( tr ); SetNextThink( gpGlobals->curtime ); }
//----------------------------------------------------------------------------- // Purpose: // Output : int //----------------------------------------------------------------------------- int CAI_PolicingBehavior::SelectSuppressSchedule( void ) { CBaseEntity *pTarget = m_hPoliceGoal->GetTarget(); m_flAggressiveTime = gpGlobals->curtime + 4.0f; if ( m_bTargetIsHostile == false ) { // Mark this as a valid target m_bTargetIsHostile = true; // Attack the target GetOuter()->SetEnemy( pTarget ); GetOuter()->SetState( NPC_STATE_COMBAT ); GetOuter()->UpdateEnemyMemory( pTarget, pTarget->GetAbsOrigin() ); HostSetBatonState( true ); // Remember that we're angry with the target m_nNumWarnings = POLICE_MAX_WARNINGS; // We need to let the system pickup the new enemy and deal with it on the next frame return SCHED_COMBAT_FACE; } // If we're supposed to stand still, then we need to show aggression if ( m_hPoliceGoal->ShouldRemainAtPost() ) { // If we're off our mark, fight to it if ( MaintainGoalPosition() ) { return SCHED_CHASE_ENEMY; } //FIXME: This needs to be a more aggressive warning to the player if ( m_flNextHarassTime < gpGlobals->curtime ) { return SCHED_POLICE_WARN_TARGET; } else { return SCHED_COMBAT_FACE; } } return SCHED_CHASE_ENEMY; }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CNPC_Bug_Warrior::MeleeAttack( float distance, float damage, QAngle& viewPunch, Vector& shove ) { if ( GetEnemy() == NULL ) return; // Trace directly at my target Vector vStart = GetAbsOrigin(); vStart.z += WorldAlignSize().z * 0.5; Vector vecForward = (GetEnemy()->EyePosition() - vStart); VectorNormalize( vecForward ); Vector vEnd = vStart + (vecForward * distance ); // Use half the size of my target for the box Vector vecHalfTraceBox = (GetEnemy()->WorldAlignMaxs() - GetEnemy()->WorldAlignMins()) * 0.25; //NDebugOverlay::Box( vStart, -Vector(10,10,10), Vector(10,10,10), 0,255,0,20,1.0); //NDebugOverlay::Box( GetEnemy()->EyePosition(), -Vector(10,10,10), Vector(10,10,10), 255,255,255,20,1.0); CBaseEntity *pHurt = CheckTraceHullAttack( vStart, vEnd, -vecHalfTraceBox, vecHalfTraceBox, damage, DMG_SLASH ); if ( pHurt ) { CBasePlayer *pPlayer = ToBasePlayer( pHurt ); if ( pPlayer ) { //Kick the player angles pPlayer->ViewPunch( viewPunch ); Vector dir = pHurt->GetAbsOrigin() - GetAbsOrigin(); VectorNormalize(dir); QAngle angles; VectorAngles( dir, angles ); Vector forward, right; AngleVectors( angles, &forward, &right, NULL ); // Push the target back Vector vecImpulse; VectorMultiply( right, -shove[1], vecImpulse ); VectorMA( vecImpulse, -shove[0], forward, vecImpulse ); pHurt->ApplyAbsVelocityImpulse( vecImpulse ); } // Play a random attack hit sound EmitSound( "NPC_Bug_Warrior.AttackHit" ); } }
//----------------------------------------------------------------------------- //----------------------------------------------------------------------------- bool CAI_AssaultBehavior::IsValidShootPosition( const Vector &vLocation, CAI_Node *pNode, CAI_Hint const *pHint ) { CBaseEntity *pCuePoint = NULL; if( m_bHitRallyPoint && !m_bHitAssaultPoint && !AssaultHasBegun() ) { pCuePoint = m_hRallyPoint; } else if( m_bHitAssaultPoint ) { pCuePoint = m_hAssaultPoint; } if ( pCuePoint && (vLocation - pCuePoint->GetAbsOrigin()).Length2DSqr() > Square( CUE_POINT_TOLERANCE - 0.1 ) ) return false; return BaseClass::IsValidShootPosition( vLocation, pNode, pHint ); }
void CKnownEntity::UpdatePosition() { CBaseEntity *ent = this->m_hEntity(); if (ent == nullptr) { return; } this->m_Position = ent->GetAbsOrigin(); CNavArea *area = nullptr; if (this->m_hEntity()->IsCombatCharacter()) { CBaseCombatCharacter *cbcc = static_cast<CBaseCombatCharacter *>(this->m_hEntity()); area = cbcc->GetLastKnownArea(); } this->m_NavArea = area; this->m_flTimeLastKnown = gpGlobals->curtime; }
//----------------------------------------------------------------------------- // Purpose: Force the driver to drop his held entity at a specific point // Input : &inputdata - //----------------------------------------------------------------------------- void CNPC_CraneDriver::InputForceDrop( inputdata_t &inputdata ) { string_t iszDropName = inputdata.value.StringID(); if ( iszDropName != NULL_STRING ) { CBaseEntity *pEntity = gEntList.FindEntityByName( NULL, iszDropName, NULL ); if ( !pEntity ) { Warning("Crane couldn't find entity named %s\n", STRING(iszDropName) ); return; } m_bForcedPickup = false; m_bForcedDropoff = true; SetDesiredPosition( pEntity->GetAbsOrigin() ); SetCondition( COND_PROVOKED ); CLEARBITS( m_spawnflags, SF_VEHICLEDRIVER_INACTIVE ); } }
const Vector &CBeam::GetAbsEndPos( void ) const { if ( GetType() != BEAM_POINTS && GetType() != BEAM_HOSE && GetEndEntity() ) { edict_t *pent = engine->PEntityOfEntIndex( GetEndEntity() ); CBaseEntity *ent = CBaseEntity::Instance( pent ); if ( ent ) return ent->GetAbsOrigin(); } if (!const_cast<CBeam*>(this)->GetMoveParent()) return m_vecEndPos.Get(); // FIXME: Cache this off? static Vector vecAbsPos; VectorTransform( m_vecEndPos, EntityToWorldTransform(), vecAbsPos ); return vecAbsPos; }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CScriptIntro::InputSetCameraViewEntity( inputdata_t &inputdata ) { // Find the specified entity string_t iszEntityName = inputdata.value.StringID(); if ( iszEntityName == NULL_STRING ) return; CBaseEntity *pEntity = gEntList.FindEntityByName( NULL, iszEntityName, NULL, inputdata.pActivator, inputdata.pCaller ); if ( !pEntity ) { Warning("script_intro %s couldn't find SetCameraViewEntity named %s\n", STRING(GetEntityName()), STRING(iszEntityName) ); return; } m_hCameraEntity = pEntity; m_vecCameraView = pEntity->GetAbsOrigin(); m_vecCameraViewAngles = pEntity->GetAbsAngles(); }
//========================================================= //========================================================= edict_t *CGameRules :: GetPlayerSpawnSpot( CBasePlayer *pPlayer ) { edict_t *pentSpawnSpot = EntSelectSpawnPoint( pPlayer ); CBaseEntity *pSpawnSpot = CBaseEntity::Instance( pentSpawnSpot ); pPlayer->SetAbsOrigin( pSpawnSpot->GetAbsOrigin() + Vector(0,0,1) ); pPlayer->pev->v_angle = g_vecZero; pPlayer->SetAbsVelocity( g_vecZero ); pPlayer->SetAbsAngles( pSpawnSpot->GetAbsAngles() ); pPlayer->pev->punchangle = g_vecZero; pPlayer->pev->fixangle = TRUE; if( pSpawnSpot->pev->spawnflags & 1 ) // the START WITH SUIT flag { pPlayer->pev->weapons |= BIT( WEAPON_SUIT ); } return pentSpawnSpot; }
//----------------------------------------------------------------------------- // Animation event handlers //----------------------------------------------------------------------------- void CWeaponCrowbar::HandleAnimEventMeleeHit( animevent_t *pEvent, CBaseCombatCharacter *pOperator ) { // Trace up or down based on where the enemy is... // But only if we're basically facing that direction Vector vecDirection; AngleVectors( GetAbsAngles(), &vecDirection ); CBaseEntity *pEnemy = pOperator->MyNPCPointer() ? pOperator->MyNPCPointer()->GetEnemy() : NULL; if ( pEnemy ) { Vector vecDelta; VectorSubtract( pEnemy->WorldSpaceCenter(), pOperator->Weapon_ShootPosition(), vecDelta ); VectorNormalize( vecDelta ); Vector2D vecDelta2D = vecDelta.AsVector2D(); Vector2DNormalize( vecDelta2D ); if ( DotProduct2D( vecDelta2D, vecDirection.AsVector2D() ) > 0.8f ) { vecDirection = vecDelta; } } Vector vecEnd; VectorMA( pOperator->Weapon_ShootPosition(), 50, vecDirection, vecEnd ); CBaseEntity *pHurt = pOperator->CheckTraceHullAttack( pOperator->Weapon_ShootPosition(), vecEnd, Vector(-16,-16,-16), Vector(36,36,36), sk_npc_dmg_crowbar.GetInt(), DMG_CLUB, 0.75 ); // did I hit someone? if ( pHurt ) { // play sound WeaponSound( MELEE_HIT ); // Fake a trace impact, so the effects work out like a player's crowbaw trace_t traceHit; UTIL_TraceLine( pOperator->Weapon_ShootPosition(), pHurt->GetAbsOrigin(), MASK_SHOT_HULL, pOperator, COLLISION_GROUP_NONE, &traceHit ); ImpactEffect( traceHit ); } else { WeaponSound( MELEE_MISS ); } }
void CASW_Spawn_Manager::PrespawnAliens(int multiplier) { // spawn random parasites 7, boomers 3, mortars 3, harvesters 4, // drones 15, uber drones 2, shieldbug 1, shaman 7, flies 1 // get num nodes // get random node // check if it's far enough from player start, 1000 units // check if valid spawn point for an alien // spawn alien const int NUM_PARASITES = rm_prespawn_num_parasites.GetInt(); const int NUM_BOOMERS = rm_prespawn_num_boomers.GetInt(); const int NUM_MORTARS = rm_prespawn_num_mortars.GetInt(); const int NUM_HARVESTERS = rm_prespawn_num_harvesters.GetInt(); const int NUM_DRONES = rm_prespawn_num_drones.GetInt(); const int NUM_UBER_DRONES = rm_prespawn_num_uber_drones.GetInt(); const int NUM_SHIELDBUGS = rm_prespawn_num_shieldbugs.GetInt(); const int NUM_SHAMANS = rm_prespawn_num_shamans.GetInt(); //const int NUM_FLIES = rm_prespawn_num_buzzers.GetInt(); const int NUM_RANGERS = rm_prespawn_num_rangers.GetInt(); int iNumNodes = g_pBigAINet->NumNodes(); if (iNumNodes < 50) return; CBaseEntity *pPlayerStart = gEntList.FindEntityByClassname(NULL, "info_player_start"); if (!pPlayerStart) return; Vector playerStartPos = pPlayerStart->GetAbsOrigin(); PrespawnAlienAtRandomNode("asw_parasite", NUM_PARASITES * multiplier, HULL_TINY, playerStartPos, iNumNodes); PrespawnAlienAtRandomNode("asw_boomer", NUM_BOOMERS * multiplier, HULL_LARGE, playerStartPos, iNumNodes); PrespawnAlienAtRandomNode("asw_mortarbug", NUM_MORTARS * multiplier, HULL_WIDE_SHORT, playerStartPos, iNumNodes); PrespawnAlienAtRandomNode("asw_harvester", NUM_HARVESTERS * multiplier, HULL_WIDE_SHORT, playerStartPos, iNumNodes); PrespawnAlienAtRandomNode("asw_drone", NUM_DRONES * multiplier, HULL_MEDIUMBIG, playerStartPos, iNumNodes); PrespawnAlienAtRandomNode("asw_drone_uber", NUM_UBER_DRONES * multiplier, HULL_MEDIUMBIG, playerStartPos, iNumNodes); PrespawnAlienAtRandomNode("asw_shieldbug", NUM_SHIELDBUGS * multiplier, HULL_WIDE_SHORT, playerStartPos, iNumNodes); PrespawnAlienAtRandomNode("asw_shaman", NUM_SHAMANS * multiplier, HULL_MEDIUM, playerStartPos, iNumNodes); //PrespawnAlienAtRandomNode("asw_buzzer", NUM_FLIES * multiplier, HULL_LARGE, playerStartPos, iNumNodes); PrespawnAlienAtRandomNode("asw_ranger", NUM_RANGERS * multiplier, HULL_MEDIUMBIG, playerStartPos, iNumNodes); }
int CAI_Senses::LookForObjects( int iDistance ) { const int BOX_QUERY_MASK = FL_OBJECT; int nSeen = 0; if ( gpGlobals->curtime - m_TimeLastLookMisc > AI_MISC_SEARCH_TIME ) { AI_PROFILE_SENSES(CAI_Senses_LookForObjects); m_TimeLastLookMisc = gpGlobals->curtime; BeginGather(); float distSq = ( iDistance * iDistance ); const Vector &origin = GetAbsOrigin(); int iter; CBaseEntity *pEnt = g_AI_SensedObjectsManager.GetFirst( &iter ); while ( pEnt ) { if ( pEnt->GetFlags() & BOX_QUERY_MASK ) { if ( origin.DistToSqr(pEnt->GetAbsOrigin()) < distSq && Look( pEnt) ) { nSeen++; } } pEnt = g_AI_SensedObjectsManager.GetNext( &iter ); } EndGather( nSeen, &m_SeenMisc ); } else { for ( int i = m_SeenMisc.Count() - 1; i >= 0; --i ) { if ( m_SeenMisc[i].Get() == NULL ) m_SeenMisc.FastRemove( i ); } nSeen = m_SeenMisc.Count(); } return nSeen; }
//--------------------------------------------------------- //--------------------------------------------------------- void CNPC_Roller::MarcoSound( void ) { if( gpGlobals->curtime < m_flTimeMarcoSound ) { return; } EmitSound( "NPC_Roller.Marco" ); // Look for all the other rollers in the effective radius and tell them to polo me. CBaseEntity *pEntity = gEntList.FindEntityByClassname( NULL, "npc_roller" ); while( pEntity ) { if( UTIL_DistApprox( GetAbsOrigin(), pEntity->GetAbsOrigin() ) <= ROLLER_MARCOPOLO_DIST ) { CNPC_Roller *pRoller; pRoller = dynamic_cast<CNPC_Roller *>(pEntity); if( pRoller && pRoller != this ) { // Don't interfere with a roller that's // supposed to be replying to someone else. if( pRoller->m_flTimePoloSound == TIME_NEVER ) { // Tell this Roller to polo in a couple seconds. pRoller->m_flTimePoloSound = gpGlobals->curtime + 1 + random->RandomFloat( 0, 2 ); // Tell him also not to marco for quite some time. pRoller->m_flTimeMarcoSound = gpGlobals->curtime + ROLLER_MARCO_FREQUENCY * 2; } } } pEntity = gEntList.FindEntityByClassname( pEntity, "npc_roller" ); } m_flTimeMarcoSound = gpGlobals->curtime + ROLLER_MARCO_FREQUENCY; }
//----------------------------------------------------------------------------- // Purpose: Finds the nearest entity by class name withing given search radius. // Input : szName - Entity name to search for. Treated as a target name first, // then as an entity class name, ie "info_target". // vecSrc - Center of search radius. // flRadius - Search radius for classname search, 0 to search everywhere. // Output : Returns a pointer to the found entity, NULL if none. //----------------------------------------------------------------------------- CBaseEntity *CGlobalEntityList::FindEntityByClassnameNearest( const char *szName, const Vector &vecSrc, float flRadius, int brushPrecision ) { CBaseEntity *pEntity = NULL; // // Check for matching class names within the search radius. // float flMaxDist2 = flRadius * flRadius; if (flMaxDist2 == 0) { flMaxDist2 = MAX_TRACE_LENGTH * MAX_TRACE_LENGTH; } CBaseEntity *pSearch = NULL; while ((pSearch = gEntList.FindEntityByClassname( pSearch, szName )) != NULL) { if ( !pSearch->edict() ) continue; Vector origin; if ( pSearch->IsBSPModel() && pSearch->CollisionProp()) { if ( brushPrecision == BRUSHPRECISION_NEAREST ) pSearch->CollisionProp()->CalcNearestPoint(vecSrc,&origin); else origin = pSearch->CollisionProp()->GetCollisionOrigin(); } else origin = pSearch->GetAbsOrigin(); float flDist2 = (origin - vecSrc).LengthSqr(); if (flMaxDist2 > flDist2) { pEntity = pSearch; flMaxDist2 = flDist2; } } return pEntity; }
void CAISound::InputEmitAISound( inputdata_t &inputdata ) { Vector vecLocation = GetAbsOrigin(); if( m_iszProxyEntityName != NULL_STRING ) { CBaseEntity *pProxy = gEntList.FindEntityByName( NULL, m_iszProxyEntityName ); if( pProxy ) { vecLocation = pProxy->GetAbsOrigin(); } else { DevWarning("Warning- ai_sound cannot find proxy entity named '%s'. Using self.\n", STRING(m_iszProxyEntityName) ); } } g_pSoundEnt->InsertSound( m_iSoundType | m_iSoundContext, vecLocation, m_iVolume, m_flDuration, this ); }
//----------------------------------------------------------------------------- // Purpose: Override base class to add display of paths //----------------------------------------------------------------------------- void CPathCorner::DrawDebugGeometryOverlays(void) { // ---------------------------------------------- // Draw line to next target is bbox is selected // ---------------------------------------------- if (m_debugOverlays & (OVERLAY_BBOX_BIT|OVERLAY_ABSBOX_BIT)) { NDebugOverlay::Box(GetAbsOrigin(), Vector(-10,-10,-10), Vector(10,10,10), 255, 100, 100, 0 ,0); if (m_target != NULL_STRING) { CBaseEntity *pTarget = gEntList.FindEntityByName( NULL, m_target ); if (pTarget) { NDebugOverlay::Line(GetAbsOrigin(),pTarget->GetAbsOrigin(),255,100,100,true,0.0); } } } BaseClass::DrawDebugGeometryOverlays(); }
int CAI_Senses::LookForHighPriorityEntities( int iDistance ) { int nSeen = 0; if ( gpGlobals->curtime - m_TimeLastLookHighPriority > AI_HIGH_PRIORITY_SEARCH_TIME ) { AI_PROFILE_SENSES(CAI_Senses_LookForHighPriorityEntities); m_TimeLastLookHighPriority = gpGlobals->curtime; BeginGather(); float distSq = ( iDistance * iDistance ); const Vector &origin = GetAbsOrigin(); // Players for ( int i = 1; i <= gpGlobals->maxClients; i++ ) { CBaseEntity *pPlayer = UTIL_PlayerByIndex( i ); if ( pPlayer ) { if ( origin.DistToSqr(pPlayer->GetAbsOrigin()) < distSq && Look( pPlayer ) ) { nSeen++; } } } EndGather( nSeen, &m_SeenHighPriority ); } else { for ( int i = m_SeenHighPriority.Count() - 1; i >= 0; --i ) { if ( m_SeenHighPriority[i].Get() == NULL ) m_SeenHighPriority.FastRemove( i ); } nSeen = m_SeenHighPriority.Count(); } return nSeen; }
void CGrenadeSpit::Think( void ) { InitHissSound(); if ( m_pHissSound == NULL ) return; // Add a doppler effect to the balls as they travel #ifdef HL2SB CBaseEntity *pPlayer = AI_GetNearestPlayer( GetAbsOrigin() ); #else CBaseEntity *pPlayer = AI_GetSinglePlayer(); #endif if ( pPlayer != NULL ) { Vector dir; VectorSubtract( pPlayer->GetAbsOrigin(), GetAbsOrigin(), dir ); VectorNormalize(dir); float velReceiver = DotProduct( pPlayer->GetAbsVelocity(), dir ); float velTransmitter = -DotProduct( GetAbsVelocity(), dir ); // speed of sound == 13049in/s int iPitch = 100 * ((1 - velReceiver / 13049) / (1 + velTransmitter / 13049)); // clamp pitch shifts if ( iPitch > 250 ) { iPitch = 250; } if ( iPitch < 50 ) { iPitch = 50; } // Set the pitch we've calculated CSoundEnvelopeController::GetController().SoundChangePitch( m_pHissSound, iPitch, 0.1f ); } // Set us up to think again shortly SetNextThink( gpGlobals->curtime + 0.05f ); }
//----------------------------------------------------------------------------- // Test for impact! //----------------------------------------------------------------------------- void CEnvHeadcrabCanister::TestForCollisionsAgainstEntities( const Vector &vecEndPosition ) { // Debugging!! // NDebugOverlay::Box( GetAbsOrigin(), m_vecMin * 0.5f, m_vecMax * 0.5f, 255, 255, 0, 0, 5 ); // NDebugOverlay::Box( vecEndPosition, m_vecMin, m_vecMax, 255, 0, 0, 0, 5 ); float flRadius = CollisionProp()->BoundingRadius(); Vector vecMins( -flRadius, -flRadius, -flRadius ); Vector vecMaxs( flRadius, flRadius, flRadius ); Ray_t ray; ray.Init( GetAbsOrigin(), vecEndPosition, vecMins, vecMaxs ); CCollideList collideList( &ray, this, MASK_SOLID ); enginetrace->EnumerateEntities( ray, false, &collideList ); float flDamage = m_flDamage; // Now get each entity and react accordinly! for( int iEntity = collideList.m_Entities.Count(); --iEntity >= 0; ) { CBaseEntity *pEntity = collideList.m_Entities[iEntity]; Vector vecForceDir = m_Shared.m_vecDirection; // Check for a physics object and apply force! IPhysicsObject *pPhysObject = pEntity->VPhysicsGetObject(); if ( pPhysObject ) { float flMass = PhysGetEntityMass( pEntity ); vecForceDir *= flMass * 750; pPhysObject->ApplyForceCenter( vecForceDir ); } if ( pEntity->m_takedamage && ( m_flDamage != 0.0f ) ) { CTakeDamageInfo info( this, this, flDamage, DMG_BLAST ); CalculateExplosiveDamageForce( &info, vecForceDir, pEntity->GetAbsOrigin() ); pEntity->TakeDamage( info ); } } }
void C_ColorCorrection::ClientThink() { if ( m_CCHandle == INVALID_CLIENT_CCHANDLE ) return; if ( mat_colcorrection_disableentities.GetInt() ) { // Allow the colorcorrectionui panel (or user) to turn off color-correction entities g_pColorCorrectionMgr->SetColorCorrectionWeight( m_CCHandle, 0.0f ); return; } if( !m_bEnabled && m_flCurWeight == 0.0f ) { g_pColorCorrectionMgr->SetColorCorrectionWeight( m_CCHandle, 0.0f ); return; } CBaseEntity *pPlayer = UTIL_PlayerByIndex(1); if( !pPlayer ) return; Vector playerOrigin = pPlayer->GetAbsOrigin(); float weight = 0; if ( ( m_minFalloff != -1 ) && ( m_maxFalloff != -1 ) && m_minFalloff != m_maxFalloff ) { float dist = (playerOrigin - m_vecOrigin).Length(); weight = (dist-m_minFalloff) / (m_maxFalloff-m_minFalloff); if ( weight<0.0f ) weight = 0.0f; if ( weight>1.0f ) weight = 1.0f; } #if defined ( SWARM_DLL ) g_pColorCorrectionMgr->SetColorCorrectionWeight( m_CCHandle, m_flCurWeight * ( 1.0 - weight ), false ); #else g_pColorCorrectionMgr->SetColorCorrectionWeight( m_CCHandle, m_flCurWeight * ( 1.0 - weight ) ); #endif BaseClass::ClientThink(); }
void C_MSS_Player::ClientThink( void ) { bool bFoundViewTarget = false; Vector vForward; AngleVectors( GetLocalAngles(), &vForward ); for( int iClient = 1; iClient <= gpGlobals->maxClients; ++iClient ) { CBaseEntity *pEnt = UTIL_PlayerByIndex( iClient ); if(!pEnt || !pEnt->IsPlayer()) continue; if ( pEnt->entindex() == entindex() ) continue; Vector vTargetOrigin = pEnt->GetAbsOrigin(); Vector vMyOrigin = GetAbsOrigin(); Vector vDir = vTargetOrigin - vMyOrigin; if ( vDir.Length() > 128 ) continue; VectorNormalize( vDir ); if ( DotProduct( vForward, vDir ) < 0.0f ) continue; m_vLookAtTarget = pEnt->EyePosition(); bFoundViewTarget = true; break; } if ( bFoundViewTarget == false ) { m_vLookAtTarget = GetAbsOrigin() + vForward * 512; } UpdateIDTarget(); }
void CEnvSoundscape::WriteAudioParamsTo( audioparams_t &audio ) { audio.ent.Set( this ); audio.soundscapeIndex = m_soundscapeIndex; audio.localBits = 0; for ( int i = 0; i < ARRAYSIZE(m_positionNames); i++ ) { if ( m_positionNames[i] != NULL_STRING ) { // We are a valid entity for a sound position CBaseEntity *pEntity = gEntList.FindEntityByName( NULL, m_positionNames[i], this, this ); if ( pEntity ) { audio.localBits |= 1<<i; audio.localSound.Set( i, pEntity->GetAbsOrigin() ); } } } m_OnPlay.FireOutput( this, this ); }
void CFuncAreaPortalWindow::Activate() { BaseClass::Activate(); // Find our background model. CBaseEntity *pBackground = gEntList.FindEntityByName( NULL, m_iBackgroundBModelName ); if( pBackground ) { m_iBackgroundModelIndex = modelinfo->GetModelIndex( STRING( pBackground->GetModelName() ) ); pBackground->AddEffects( EF_NODRAW ); // we will draw for it. } // Find our target and steal its bmodel. CBaseEntity *pTarget = gEntList.FindEntityByName( NULL, m_target ); if( pTarget ) { SetModel( STRING(pTarget->GetModelName()) ); SetAbsOrigin( pTarget->GetAbsOrigin() ); pTarget->AddEffects( EF_NODRAW ); // we will draw for it. } }
//----------------------------------------------------------------------------- // Purpose: Find the nearest entity along the facing direction from the given origin // within the angular threshold (ignores worldspawn) with the // given classname. // Input : origin - // facing - // threshold - // classname - //----------------------------------------------------------------------------- CBaseEntity *CGlobalEntityList::FindEntityClassNearestFacing( const Vector &origin, const Vector &facing, float threshold, char *classname) { float bestDot = threshold; CBaseEntity *best_ent = NULL; const CEntInfo *pInfo = FirstEntInfo(); for ( ;pInfo; pInfo = pInfo->m_pNext ) { CBaseEntity *ent = (CBaseEntity *)pInfo->m_pEntity; if ( !ent ) { DevWarning( "NULL entity in global entity list!\n" ); continue; } // FIXME: why is this skipping pointsize entities? if (ent->IsPointSized() ) continue; // Make vector to entity Vector to_ent = (ent->GetAbsOrigin() - origin); VectorNormalize( to_ent ); float dot = DotProduct (facing , to_ent ); if (dot > bestDot) { if (FClassnameIs(ent,classname)) { // Ignore if worldspawn if (!FClassnameIs( ent, "worldspawn" ) && !FClassnameIs( ent, "soundent")) { bestDot = dot; best_ent = ent; } } } } return best_ent; }
//----------------------------------------------------------------------------- // Purpose: Give the harpoon a yank //----------------------------------------------------------------------------- void CWeaponHarpoon::YankHarpoon( void ) { CBasePlayer *pPlayer = dynamic_cast<CBasePlayer*>( GetOwner() ); if ( !pPlayer ) return; #if !defined( CLIENT_DLL ) if ( m_bActiveHarpoon && m_hHarpoon.Get() ) { // If the harpoon's impaled something, pull it towards me CBaseEntity *pTarget = m_hHarpoon->GetImpaledTarget(); if ( pTarget ) { if ( !pTarget->IsBSPModel() && pTarget->GetMoveType() != MOVETYPE_NONE ) { // Bring him to me! EmitSound( "Harpoon.Yank" ); // Get a yank vector, and raise it a little to get them off the ground if they're on it Vector vecOverHere = ( pPlayer->GetAbsOrigin() - pTarget->GetAbsOrigin() ); VectorNormalize( vecOverHere ); if ( pTarget->GetFlags() & FL_ONGROUND ) { pTarget->SetGroundEntity( NULL ); vecOverHere.z = 0.5; } pTarget->ApplyAbsVelocityImpulse( vecOverHere * 500 ); PlayAttackAnimation( ACT_VM_HAULBACK ); } } m_hHarpoon->SetThink( SUB_Remove ); m_hHarpoon->SetNextThink( gpGlobals->curtime + 5.0 ); m_hHarpoon = NULL; m_bActiveHarpoon = false; } DetachRope(); #endif }