本文整理汇总了C++中CBaseEntity类的典型用法代码示例。如果您正苦于以下问题:C++ CBaseEntity类的具体用法?C++ CBaseEntity怎么用?C++ CBaseEntity使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CBaseEntity类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Reload
void CHgun::SecondaryAttack( void )
{
Reload();
if (m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] <= 0)
{
return;
}
//Wouldn't be a bad idea to completely predict these, since they fly so fast...
#ifndef CLIENT_DLL
CBaseEntity *pHornet;
Vector vecSrc;
UTIL_MakeVectors( m_pPlayer->pev->v_angle );
vecSrc = m_pPlayer->GetGunPosition( ) + gpGlobals->v_forward * 16 + gpGlobals->v_right * 8 + gpGlobals->v_up * -12;
m_iFirePhase++;
switch ( m_iFirePhase )
{
case 1:
vecSrc = vecSrc + gpGlobals->v_up * 8;
break;
case 2:
vecSrc = vecSrc + gpGlobals->v_up * 8;
vecSrc = vecSrc + gpGlobals->v_right * 8;
break;
case 3:
vecSrc = vecSrc + gpGlobals->v_right * 8;
break;
case 4:
vecSrc = vecSrc + gpGlobals->v_up * -8;
vecSrc = vecSrc + gpGlobals->v_right * 8;
break;
case 5:
vecSrc = vecSrc + gpGlobals->v_up * -8;
break;
case 6:
vecSrc = vecSrc + gpGlobals->v_up * -8;
vecSrc = vecSrc + gpGlobals->v_right * -8;
break;
case 7:
vecSrc = vecSrc + gpGlobals->v_right * -8;
break;
case 8:
vecSrc = vecSrc + gpGlobals->v_up * 8;
vecSrc = vecSrc + gpGlobals->v_right * -8;
m_iFirePhase = 0;
break;
}
pHornet = CBaseEntity::Create( "hornet", vecSrc, m_pPlayer->pev->v_angle, m_pPlayer->edict() );
pHornet->pev->velocity = gpGlobals->v_forward * 1200;
pHornet->pev->angles = UTIL_VecToAngles( pHornet->pev->velocity );
pHornet->SetThink( &CHornet::StartDart );
m_flRechargeTime = gpGlobals->time + 0.5;
#endif
int flags;
#if defined( CLIENT_WEAPONS )
flags = FEV_NOTHOST;
#else
flags = 0;
#endif
PLAYBACK_EVENT_FULL( flags, m_pPlayer->edict(), m_usHornetFire, 0.0, (float *)&g_vecZero, (float *)&g_vecZero, 0.0, 0.0, FIREMODE_FAST, 0, 0, 0 );
m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType]--;
m_pPlayer->m_iWeaponVolume = NORMAL_GUN_VOLUME;
m_pPlayer->m_iWeaponFlash = DIM_GUN_FLASH;
// player "shoot" animation
m_pPlayer->SetAnimation( PLAYER_ATTACK1 );
m_flNextPrimaryAttack = m_flNextSecondaryAttack = UTIL_WeaponTimeBase() + 0.1;
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + UTIL_SharedRandomFloat( m_pPlayer->random_seed, 10, 15 );
}
示例2: defined
void CBasePlayer::SimulatePlayerSimulatedEntities( void )
{
int c = m_SimulatedByThisPlayer.Count();
int i;
for ( i = c - 1; i >= 0; i-- )
{
CHandle< CBaseEntity > h;
h = m_SimulatedByThisPlayer[ i ];
CBaseEntity *e = h;
if ( !e || !e->IsPlayerSimulated() )
{
m_SimulatedByThisPlayer.Remove( i );
continue;
}
#if defined( CLIENT_DLL )
if ( e->IsClientCreated() && prediction->InPrediction() && !prediction->IsFirstTimePredicted() )
{
continue;
}
#endif
Assert( e->IsPlayerSimulated() );
Assert( e->GetSimulatingPlayer() == this );
e->PhysicsSimulate();
}
// Loop through all entities again, checking their untouch if flagged to do so
c = m_SimulatedByThisPlayer.Count();
for ( i = c - 1; i >= 0; i-- )
{
CHandle< CBaseEntity > h;
h = m_SimulatedByThisPlayer[ i ];
CBaseEntity *e = h;
if ( !e || !e->IsPlayerSimulated() )
{
m_SimulatedByThisPlayer.Remove( i );
continue;
}
#if defined( CLIENT_DLL )
if ( e->IsClientCreated() && prediction->InPrediction() && !prediction->IsFirstTimePredicted() )
{
continue;
}
#endif
Assert( e->IsPlayerSimulated() );
Assert( e->GetSimulatingPlayer() == this );
if ( !e->GetCheckUntouch() )
continue;
e->PhysicsCheckForEntityUntouch();
}
}
示例3: UTIL_TraceLine
/* <1bc358> ../cstrike/dlls/vehicle.cpp:466 */
void CFuncVehicle::CollisionDetection()
{
TraceResult tr;
bool bHitSomething = false;
if (pev->speed < 0)
{
UTIL_TraceLine(m_vBackLeft, m_vBackLeft + (gpGlobals->v_forward * 16.0), ignore_monsters, dont_ignore_glass, ENT(pev), &tr);
if (tr.flFraction == 1.0f)
{
UTIL_TraceLine(m_vBackRight, m_vBackRight + (gpGlobals->v_forward * 16.0), ignore_monsters, dont_ignore_glass, ENT(pev), &tr);
if (tr.flFraction == 1.0f)
{
UTIL_TraceLine(m_vBack, m_vBack + (gpGlobals->v_forward * 16.0), ignore_monsters, dont_ignore_glass, ENT(pev), &tr);
if (tr.flFraction == 1.0f)
{
return;
}
}
if (DotProduct(gpGlobals->v_forward, tr.vecPlaneNormal * -1.0) < 0.7 && tr.vecPlaneNormal.z < 0.1)
{
m_vSurfaceNormal = tr.vecPlaneNormal;
m_vSurfaceNormal.z = 0;
pev->speed *= 0.99;
}
else if (tr.vecPlaneNormal.z < 0.65 || tr.fStartSolid)
{
pev->speed *= -1.0;
}
else
{
m_vSurfaceNormal = tr.vecPlaneNormal;
}
}
else
{
if (DotProduct(gpGlobals->v_forward, tr.vecPlaneNormal * -1.0) < 0.7 && tr.vecPlaneNormal.z < 0.1)
{
m_vSurfaceNormal = tr.vecPlaneNormal;
m_vSurfaceNormal.z = 0;
pev->speed *= 0.99;
}
else if (tr.vecPlaneNormal[2] < 0.65 || tr.fStartSolid)
{
pev->speed *= -1.0;
}
else
{
m_vSurfaceNormal = tr.vecPlaneNormal;
}
CBaseEntity *pHit = CBaseEntity::Instance(tr.pHit);
if (pHit && pHit->Classify() == CLASS_VEHICLE)
{
bHitSomething = true;
ALERT(at_console, "I hit another vehicle\n");
}
}
}
else if (pev->speed > 0)
{
UTIL_TraceLine(m_vFrontLeft, m_vFrontLeft - (gpGlobals->v_forward * 16.0), dont_ignore_monsters, dont_ignore_glass, ENT(pev), &tr);
if (tr.flFraction == 1.0f)
{
UTIL_TraceLine(m_vFrontRight, m_vFrontRight - (gpGlobals->v_forward * 16.0), ignore_monsters, dont_ignore_glass, ENT(pev), &tr);
if (tr.flFraction == 1.0f)
{
UTIL_TraceLine(m_vFront, m_vFront - (gpGlobals->v_forward * 16.0), ignore_monsters, dont_ignore_glass, ENT(pev), &tr);
if (tr.flFraction == 1.0f)
{
return;
}
}
}
if (DotProduct(gpGlobals->v_forward, tr.vecPlaneNormal * -1.0) > -0.7 && tr.vecPlaneNormal.z < 0.1)
{
m_vSurfaceNormal = tr.vecPlaneNormal;
m_vSurfaceNormal.z = 0;
pev->speed *= 0.99;
}
else if (tr.vecPlaneNormal.z < 0.65 || tr.fStartSolid)
{
pev->speed *= -1.0;
}
else
{
m_vSurfaceNormal = tr.vecPlaneNormal;
//.........这里部分代码省略.........
示例4: GetOwner
//-----------------------------------------------------------------------------
// Purpose:
// Input : flDot -
// flDist -
// Output : int
//-----------------------------------------------------------------------------
int CWeaponSMG1::WeaponRangeAttack2Condition( float flDot, float flDist )
{
CAI_BaseNPC *npcOwner = GetOwner()->MyNPCPointer();
return COND_NONE;
/*
// --------------------------------------------------------
// Assume things haven't changed too much since last time
// --------------------------------------------------------
if (gpGlobals->curtime < m_flNextGrenadeCheck )
return m_lastGrenadeCondition;
*/
// -----------------------
// If moving, don't check.
// -----------------------
if ( npcOwner->IsMoving())
return COND_NONE;
CBaseEntity *pEnemy = npcOwner->GetEnemy();
if (!pEnemy)
return COND_NONE;
Vector vecEnemyLKP = npcOwner->GetEnemyLKP();
if ( !( pEnemy->GetFlags() & FL_ONGROUND ) && pEnemy->GetWaterLevel() == 0 && vecEnemyLKP.z > (GetAbsOrigin().z + WorldAlignMaxs().z) )
{
//!!!BUGBUG - we should make this check movetype and make sure it isn't FLY? Players who jump a lot are unlikely to
// be grenaded.
// don't throw grenades at anything that isn't on the ground!
return COND_NONE;
}
// --------------------------------------
// Get target vector
// --------------------------------------
Vector vecTarget;
if (random->RandomInt(0,1))
{
// magically know where they are
vecTarget = pEnemy->WorldSpaceCenter();
}
else
{
// toss it to where you last saw them
vecTarget = vecEnemyLKP;
}
// vecTarget = m_vecEnemyLKP + (pEnemy->BodyTarget( GetLocalOrigin() ) - pEnemy->GetLocalOrigin());
// estimate position
// vecTarget = vecTarget + pEnemy->m_vecVelocity * 2;
if ( ( vecTarget - npcOwner->GetLocalOrigin() ).Length2D() <= COMBINE_MIN_GRENADE_CLEAR_DIST )
{
// crap, I don't want to blow myself up
m_flNextGrenadeCheck = gpGlobals->curtime + 1; // one full second.
return (COND_NONE);
}
// ---------------------------------------------------------------------
// Are any friendlies near the intended grenade impact area?
// ---------------------------------------------------------------------
CBaseEntity *pTarget = NULL;
while ( ( pTarget = gEntList.FindEntityInSphere( pTarget, vecTarget, COMBINE_MIN_GRENADE_CLEAR_DIST ) ) != NULL )
{
//Check to see if the default relationship is hatred, and if so intensify that
if ( npcOwner->IRelationType( pTarget ) == D_LI )
{
// crap, I might blow my own guy up. Don't throw a grenade and don't check again for a while.
m_flNextGrenadeCheck = gpGlobals->curtime + 1; // one full second.
return (COND_WEAPON_BLOCKED_BY_FRIEND);
}
}
// ---------------------------------------------------------------------
// Check that throw is legal and clear
// ---------------------------------------------------------------------
// FIXME: speed is based on difficulty...
Vector vecToss = VecCheckThrow( this, npcOwner->GetLocalOrigin() + Vector(0,0,60), vecTarget, 600.0, 0.5 );
if ( vecToss != vec3_origin )
{
m_vecTossVelocity = vecToss;
// don't check again for a while.
// JAY: HL1 keeps checking - test?
//m_flNextGrenadeCheck = gpGlobals->curtime;
m_flNextGrenadeCheck = gpGlobals->curtime + 0.3; // 1/3 second.
return COND_CAN_RANGE_ATTACK2;
}
else
{
//.........这里部分代码省略.........
示例5: AI_GetSinglePlayer
int CAI_LeadBehavior::SelectSchedule()
{
if (HasGoal())
{
if (HasCondition(COND_LEAD_SUCCESS))
{
return SCHED_LEAD_SUCCEED;
}
// Player's here, but does he have the weapon we want him to have?
if (m_weaponname != NULL_STRING)
{
CBasePlayer *pFollower = AI_GetSinglePlayer();
if (pFollower && !pFollower->Weapon_OwnsThisType(STRING(m_weaponname)))
{
// If the safety timeout has run out, just give the player the weapon
if (!m_flWeaponSafetyTimeOut || (m_flWeaponSafetyTimeOut > gpGlobals->curtime))
return SCHED_LEAD_PLAYERNEEDSWEAPON;
string_t iszItem = AllocPooledString("weapon_bugbait");
pFollower->GiveNamedItem(STRING(iszItem));
}
}
// If we have a waitpoint, we want to wait at it for the player.
if (HasWaitPoint() && !PlayerIsAheadOfMe(true))
{
bool bKeepWaiting = true;
// If we have no wait distance, trigger as soon as the player comes in view
if (!m_waitdistance)
{
if (HasCondition(COND_SEE_PLAYER))
{
// We've spotted the player, so stop waiting
bKeepWaiting = false;
}
}
else
{
// We have to collect data about the person we're leading around.
CBaseEntity *pFollower = AI_GetSinglePlayer();
if (pFollower)
{
float flFollowerDist = (WorldSpaceCenter() - pFollower->WorldSpaceCenter()).Length();
if (flFollowerDist < m_waitdistance)
{
bKeepWaiting = false;
}
}
}
// Player still not here?
if (bKeepWaiting)
return SCHED_LEAD_WAITFORPLAYER;
// We're finished waiting
m_waitpoint = vec3_origin;
Speak(TLK_LEAD_WAITOVER);
// Don't speak the start line, because we've said
m_hasspokenstart = true;
return SCHED_WAIT_FOR_SPEAK_FINISH;
}
// If we haven't spoken our start speech, do that first
if (!m_hasspokenstart)
{
if (HasCondition(COND_LEAD_HAVE_FOLLOWER_LOS) && HasCondition(COND_LEAD_FOLLOWER_VERY_CLOSE))
return SCHED_LEAD_SPEAK_START;
// We haven't spoken to him, and we still need to. Go get him.
return SCHED_LEAD_RETRIEVE;
}
if (HasCondition(COND_LEAD_FOLLOWER_LOST))
{
if (m_args.iRetrievePlayer)
{
// If not, we want to go get the player.
DevMsg(GetOuter(), "Follower lost. Spoke COMING_BACK.\n");
Speak(TLK_LEAD_COMINGBACK);
m_MoveMonitor.ClearMark();
// If we spoke something, wait for it to finish
if (m_args.iComingBackWaitForSpeak && IsSpeaking())
return SCHED_LEAD_SPEAK_THEN_RETRIEVE_PLAYER;
return SCHED_LEAD_RETRIEVE;
}
else
{
// Just stay right here and wait.
return SCHED_LEAD_WAITFORPLAYERIDLE;
}
}
if (HasCondition(COND_LEAD_FOLLOWER_LAGGING))
{
//.........这里部分代码省略.........
示例6: EnumElement
IterationRetval_t CPortalCollideableEnumerator::EnumElement( IHandleEntity *pHandleEntity )
{
EHANDLE hEnt = pHandleEntity->GetRefEHandle();
CBaseEntity *pEnt = hEnt.Get();
if( pEnt == NULL ) //I really never thought this would be necessary
return ITERATION_CONTINUE;
if( hEnt == m_hTestPortal )
return ITERATION_CONTINUE; //ignore this portal
/*if( staticpropmgr->IsStaticProp( pHandleEntity ) )
{
//we're dealing with a static prop, which unfortunately doesn't have everything I want to use for checking
ICollideable *pCollideable = pEnt->GetCollideable();
Vector vMins, vMaxs;
pCollideable->WorldSpaceSurroundingBounds( &vMins, &vMaxs );
Vector ptTest( (m_vPlaneNormal.x > 0.0f)?(vMaxs.x):(vMins.x),
(m_vPlaneNormal.y > 0.0f)?(vMaxs.y):(vMins.y),
(m_vPlaneNormal.z > 0.0f)?(vMaxs.z):(vMins.z) );
float fPtPlaneDist = m_vPlaneNormal.Dot( ptTest ) - m_fPlaneDist;
if( fPtPlaneDist <= 0.0f )
return ITERATION_CONTINUE;
}
else*/
{
//not a static prop, w00t
CCollisionProperty *pEntityCollision = pEnt->CollisionProp();
if( !pEntityCollision->IsSolid() )
return ITERATION_CONTINUE; //not solid
Vector ptEntCenter = pEntityCollision->WorldSpaceCenter();
float fBoundRadius = pEntityCollision->BoundingRadius();
float fPtPlaneDist = m_vPlaneNormal.Dot( ptEntCenter ) - m_fPlaneDist;
if( fPtPlaneDist < -fBoundRadius )
return ITERATION_CONTINUE; //object wholly behind the portal
if( !(fPtPlaneDist > fBoundRadius) && (fPtPlaneDist > -fBoundRadius) ) //object is not wholly in front of the portal, but could be partially in front, do more checks
{
Vector ptNearest;
pEntityCollision->CalcNearestPoint( m_ptForward1000, &ptNearest );
fPtPlaneDist = m_vPlaneNormal.Dot( ptNearest ) - m_fPlaneDist;
if( fPtPlaneDist < 0.0f )
return ITERATION_CONTINUE; //closest point was behind the portal plane, we don't want it
}
}
//if we're down here, this entity needs to be added to our enumeration
Assert( m_iHandleCount < 1024 );
if( m_iHandleCount < 1024 )
m_pHandles[m_iHandleCount] = pHandleEntity;
++m_iHandleCount;
return ITERATION_CONTINUE;
}
示例7: MapEntity_ParseAllEntities
//-----------------------------------------------------------------------------
// Purpose: Only called on BSP load. Parses and spawns all the entities in the BSP.
// Input : pMapData - Pointer to the entity data block to parse.
//-----------------------------------------------------------------------------
void MapEntity_ParseAllEntities(const char *pMapData, IMapEntityFilter *pFilter, bool bActivateEntities)
{
VPROF("MapEntity_ParseAllEntities");
HierarchicalSpawnMapData_t pSpawnMapData[NUM_ENT_ENTRIES];
HierarchicalSpawn_t pSpawnList[NUM_ENT_ENTRIES];
CUtlVector< CPointTemplate* > pPointTemplates;
int nEntities = 0;
char szTokenBuffer[MAPKEY_MAXLENGTH];
#if !defined( _RETAIL )
#if defined( _XBOX )
char sz[ 128 ];
Q_snprintf( sz, sizeof( sz ), "MapEntity_ParseAllEntities():Start" );
XBX_rTimeStampLog( Plat_FloatTime(), sz );
#endif
#endif
// Allow the tools to spawn different things
if ( serverenginetools )
{
pMapData = serverenginetools->GetEntityData( pMapData );
}
// Loop through all entities in the map data, creating each.
for ( ; true; pMapData = MapEntity_SkipToNextEntity(pMapData, szTokenBuffer) )
{
//
// Parse the opening brace.
//
char token[MAPKEY_MAXLENGTH];
pMapData = MapEntity_ParseToken( pMapData, token );
//
// Check to see if we've finished or not.
//
if (!pMapData)
break;
if (token[0] != '{')
{
Error( "MapEntity_ParseAllEntities: found %s when expecting {", token);
continue;
}
//
// Parse the entity and add it to the spawn list.
//
CBaseEntity *pEntity;
const char *pCurMapData = pMapData;
pMapData = MapEntity_ParseEntity(pEntity, pMapData, pFilter);
if (pEntity == NULL)
continue;
if (pEntity->IsTemplate())
{
// It's a template entity. Squirrel away its keyvalue text so that we can
// recreate the entity later via a spawner. pMapData points at the '}'
// so we must add one to include it in the string.
Templates_Add(pEntity, pCurMapData, (pMapData - pCurMapData) + 2);
// Remove the template entity so that it does not show up in FindEntityXXX searches.
UTIL_Remove(pEntity);
gEntList.CleanupDeleteList();
continue;
}
// To
if ( dynamic_cast<CWorld*>( pEntity ) )
{
VPROF( "MapEntity_ParseAllEntities_SpawnWorld");
pEntity->m_iParent = NULL_STRING; // don't allow a parent on the first entity (worldspawn)
DispatchSpawn(pEntity);
continue;
}
CNodeEnt *pNode = dynamic_cast<CNodeEnt*>(pEntity);
if ( pNode )
{
VPROF( "MapEntity_ParseAllEntities_SpawnTransients");
// We overflow the max edicts on large maps that have lots of entities.
// Nodes & Lights remove themselves immediately on Spawn(), so dispatch their
// spawn now, to free up the slot inside this loop.
// NOTE: This solution prevents nodes & lights from being used inside point_templates.
//
// NOTE: Nodes spawn other entities (ai_hint) if they need to have a persistent presence.
// To ensure keys are copied over into the new entity, we pass the mapdata into the
// node spawn function.
if ( pNode->Spawn( pCurMapData ) < 0 )
{
gEntList.CleanupDeleteList();
}
continue;
//.........这里部分代码省略.........
示例8: GetAbsOrigin
void CASW_Simple_Alien::MeleeAttack( float distance, float damage, QAngle &viewPunch, Vector &shove )
{
Vector vecForceDir;
// Always hurt bullseyes for now
if ( ( GetEnemy() != NULL ) && ( GetEnemy()->Classify() == CLASS_BULLSEYE ) )
{
vecForceDir = (GetEnemy()->GetAbsOrigin() - GetAbsOrigin());
CTakeDamageInfo info( this, this, damage, DMG_SLASH );
CalculateMeleeDamageForce( &info, vecForceDir, GetEnemy()->GetAbsOrigin() );
GetEnemy()->TakeDamage( info );
return;
}
CBaseEntity *pHurt = CheckTraceHullAttack( distance, -Vector(16,16,32), Vector(16,16,32), damage, DMG_SLASH, 5.0f );
if ( pHurt )
{
vecForceDir = ( pHurt->WorldSpaceCenter() - WorldSpaceCenter() );
CBasePlayer *pPlayer = ToBasePlayer( pHurt );
if ( pPlayer != NULL )
{
//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
pHurt->ApplyAbsVelocityImpulse( - right * shove[1] - forward * shove[0] );
}
// Play a random attack hit sound
AttackSound();
// bleed em
if ( UTIL_ShouldShowBlood(pHurt->BloodColor()) )
{
// Hit an NPC. Bleed them!
Vector vecBloodPos;
Vector forward, right, up;
AngleVectors( GetAbsAngles(), &forward, &right, &up );
//if( GetAttachment( "leftclaw", vecBloodPos ) )
{
//Vector diff = vecBloodPos - GetAbsOrigin();
//if (diff.z < 0)
//vecBloodPos.z = GetAbsOrigin().z - (diff.z * 2);
vecBloodPos = GetAbsOrigin() + forward * 60 - right * 14 + up * 50;
SpawnBlood( vecBloodPos, g_vecAttackDir, pHurt->BloodColor(), MIN( damage, 30 ) );
}
//if( GetAttachment( "rightclaw", vecBloodPos ) )
{
vecBloodPos = GetAbsOrigin() + forward * 60 + right * 14 + up * 50;
SpawnBlood( vecBloodPos, g_vecAttackDir, pHurt->BloodColor(), MIN( damage, 30 ) );
}
}
}
}
示例9: while
void AvHBaseBuildable::WorldUpdate()
{
this->UpdateTechSlots();
// Organic buildings heal themselves
if(this->GetIsOrganic())
{
this->UpdateAutoHeal();
}
else
{
//this->UpdateDamageEffects();
}
// If we're electrified, set render mode
if(GetHasUpgrade(this->pev->iuser4, MASK_UPGRADE_11))
{
// Base marine building
const int kElectrifyRenderMode = kRenderFxGlowShell;
const int kElectrifyRenderAmount = 40;
this->pev->renderfx = kElectrifyRenderMode;
this->pev->renderamt = kElectrifyRenderAmount;
this->pev->rendercolor.x = kTeamColors[this->pev->team][0];
this->pev->rendercolor.y = kTeamColors[this->pev->team][1];
this->pev->rendercolor.z = kTeamColors[this->pev->team][2];
// Check for enemy players/structures nearby
CBaseEntity* theBaseEntity = NULL;
int theNumEntsDamaged = 0;
while(((theBaseEntity = UTIL_FindEntityInSphere(theBaseEntity, this->pev->origin, BALANCE_VAR(kElectricalRange))) != NULL) && (theNumEntsDamaged < BALANCE_VAR(kElectricalMaxTargets)))
{
// When "electric" cheat is enabled, shock all non-self entities, else shock enemies
if((GetGameRules()->GetIsCheatEnabled(kcElectric) && (theBaseEntity != this)) || ((theBaseEntity->pev->team != this->pev->team) && theBaseEntity->IsAlive()))
{
// Make sure it's not blocked
TraceResult theTraceResult;
UTIL_TraceLine(this->pev->origin, theBaseEntity->pev->origin, ignore_monsters, dont_ignore_glass, this->edict(), &theTraceResult);
if(theTraceResult.flFraction == 1.0f)
{
CBaseEntity* theAttacker = this->GetAttacker();
ASSERT(theAttacker);
if(theBaseEntity->TakeDamage(this->pev, theAttacker->pev, BALANCE_VAR(kElectricalDamage), DMG_GENERIC) > 0)
{
MESSAGE_BEGIN( MSG_BROADCAST, SVC_TEMPENTITY );
WRITE_BYTE(TE_BEAMENTPOINT);
WRITE_SHORT(theBaseEntity->entindex());
WRITE_COORD( this->pev->origin.x);
WRITE_COORD( this->pev->origin.y);
WRITE_COORD( this->pev->origin.z);
WRITE_SHORT( this->mElectricalSprite );
WRITE_BYTE( 0 ); // framestart
WRITE_BYTE( (int)15); // framerate
WRITE_BYTE( (int)(2) ); // life
WRITE_BYTE( 60 ); // width
WRITE_BYTE( 15 ); // noise
WRITE_BYTE( (int)this->pev->rendercolor.x ); // r, g, b
WRITE_BYTE( (int)this->pev->rendercolor.y ); // r, g, b
WRITE_BYTE( (int)this->pev->rendercolor.z ); // r, g, b
WRITE_BYTE( 200 ); // brightness
WRITE_BYTE( 10 ); // speed
MESSAGE_END();
gSoundListManager.PlaySoundInList(kElectricSparkSoundList, this, CHAN_AUTO, .7f);
UTIL_Sparks(theBaseEntity->pev->origin);
theNumEntsDamaged++;
}
}
}
}
}
}
示例10: GetAbsStartPos
//-----------------------------------------------------------------------------
// Computes the bounding box of a beam local to the origin of the beam
//-----------------------------------------------------------------------------
void CBeam::ComputeBounds( Vector& mins, Vector& maxs )
{
Vector vecAbsStart = GetAbsStartPos();
Vector vecAbsEnd = GetAbsEndPos();
// May need extra points for creating the min/max bounds
bool bUseExtraPoints = false;
Vector vecAbsExtra1, vecAbsExtra2;
#ifdef PORTAL
CBaseEntity *pStartEntity = GetStartEntityPtr();
CTraceFilterSkipClassname traceFilter( pStartEntity, "prop_energy_ball", COLLISION_GROUP_NONE );
ITraceFilter *pEntityBeamTraceFilter = NULL;
if ( pStartEntity )
pEntityBeamTraceFilter = pStartEntity->GetBeamTraceFilter();
CTraceFilterChain traceFilterChain( &traceFilter, pEntityBeamTraceFilter );
bUseExtraPoints = UTIL_Portal_Trace_Beam( this, vecAbsStart, vecAbsEnd, vecAbsExtra1, vecAbsExtra2, &traceFilterChain );
#endif
switch( GetType() )
{
case BEAM_LASER:
case BEAM_ENTS:
case BEAM_SPLINE:
case BEAM_ENTPOINT:
{
// Compute the bounds here...
Vector attachmentPoint( 0, 0, 0 );
mins.Init( 99999, 99999, 99999 );
maxs.Init( -99999, -99999, -99999 );
for (int i = 0; i < m_nNumBeamEnts; ++i )
{
C_BaseEntity *pTestEnt = m_hAttachEntity[i].Get();
if ( pTestEnt )
{
if ( pTestEnt == this )
{
mins = maxs = GetAbsOrigin();
}
else
{
// We do this so we don't have to calculate attachments (and do expensive bone-setup calculations) on our attachments.
Vector attMins, attMaxs;
m_hAttachEntity[i]->GetRenderBoundsWorldspace( attMins, attMaxs );
mins = mins.Min( attMins );
mins = mins.Min( attMaxs );
maxs = maxs.Max( attMins );
maxs = maxs.Max( attMaxs );
}
//ASSERT_COORD( mins );
//ASSERT_COORD( maxs );
}
else
{
if (i == 0)
{
VectorCopy( vecAbsStart, attachmentPoint );
}
else if (i == 1)
{
VectorCopy( vecAbsEnd, attachmentPoint );
}
else
{
Assert(0);
}
mins = mins.Min( attachmentPoint );
maxs = maxs.Max( attachmentPoint );
}
}
}
break;
case BEAM_POINTS:
default:
{
for (int i = 0; i < 3; ++i)
{
if (vecAbsStart[i] < vecAbsEnd[i])
{
mins[i] = vecAbsStart[i];
maxs[i] = vecAbsEnd[i];
}
else
{
mins[i] = vecAbsEnd[i];
maxs[i] = vecAbsStart[i];
}
}
//.........这里部分代码省略.........
示例11: CalcDeathForceVector
Vector CASW_Simple_Alien::CalcDeathForceVector( const CTakeDamageInfo &info )
{
// Already have a damage force in the data, use that.
if ( info.GetDamageForce() != vec3_origin || (g_pGameRules->Damage_NoPhysicsForce(info.GetDamageType())))
{
if( info.GetDamageType() & DMG_BLAST )
{
float scale = random->RandomFloat( 0.85, 1.15 );
Vector force = info.GetDamageForce();
force.x *= scale;
force.y *= scale;
// Try to always exaggerate the upward force because we've got pretty harsh gravity
force.z *= (force.z > 0) ? 1.15 : scale;
return force;
}
return info.GetDamageForce();
}
CBaseEntity *pForce = info.GetInflictor();
if ( !pForce )
{
pForce = info.GetAttacker();
}
if ( pForce )
{
// Calculate an impulse large enough to push a 75kg man 4 in/sec per point of damage
float forceScale = info.GetDamage() * 75 * 4;
Vector forceVector;
// If the damage is a blast, point the force vector higher than usual, this gives
// the ragdolls a bodacious "really got blowed up" look.
if( info.GetDamageType() & DMG_BLAST )
{
// exaggerate the force from explosions a little (37.5%)
forceVector = (GetLocalOrigin() + Vector(0, 0, WorldAlignSize().z) ) - pForce->GetLocalOrigin();
VectorNormalize(forceVector);
forceVector *= 1.375f;
}
else
{
// taking damage from self? Take a little random force, but still try to collapse on the spot.
if ( this == pForce )
{
forceVector.x = random->RandomFloat( -1.0f, 1.0f );
forceVector.y = random->RandomFloat( -1.0f, 1.0f );
forceVector.z = 0.0;
forceScale = random->RandomFloat( 1000.0f, 2000.0f );
}
else
{
// UNDONE: Collision forces are baked in to CTakeDamageInfo now
// UNDONE: Is this MOVETYPE_VPHYSICS code still necessary?
if ( pForce->GetMoveType() == MOVETYPE_VPHYSICS )
{
// killed by a physics object
IPhysicsObject *pPhysics = VPhysicsGetObject();
if ( !pPhysics )
{
pPhysics = pForce->VPhysicsGetObject();
}
pPhysics->GetVelocity( &forceVector, NULL );
forceScale = pPhysics->GetMass();
}
else
{
forceVector = GetLocalOrigin() - pForce->GetLocalOrigin();
VectorNormalize(forceVector);
}
}
}
return forceVector * forceScale;
}
return vec3_origin;
}
示例12: GatherConditions
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
void CNPC_Monk::GatherConditions()
{
BaseClass::GatherConditions();
// Build my zombie danger index!
m_iNumZombies = 0;
m_iDangerousZombies = 0;
AISightIter_t iter;
CBaseEntity *pSightEnt;
pSightEnt = GetSenses()->GetFirstSeenEntity( &iter );
while( pSightEnt )
{
if( pSightEnt->Classify() == CLASS_ZOMBIE && pSightEnt->IsAlive() )
{
// Is this zombie coming for me?
CAI_BaseNPC *pZombie = dynamic_cast<CAI_BaseNPC*>(pSightEnt);
if( pZombie && pZombie->GetEnemy() == this )
{
m_iNumZombies++;
// if this zombie is close enough to attack, add him to the zombie danger!
float flDist;
flDist = (pZombie->GetAbsOrigin() - GetAbsOrigin()).Length2DSqr();
if( flDist <= 128.0f * 128.0f )
{
m_iDangerousZombies++;
}
}
}
pSightEnt = GetSenses()->GetNextSeenEntity( &iter );
}
if( m_iDangerousZombies >= 3 || (GetEnemy() && GetHealth() < 25) )
{
// I see many zombies, or I'm quite injured.
SpeakIfAllowed( TLK_HELP_ME );
}
// NOTE!!!!!! This code assumes grigori is using annabelle!
ClearCondition(COND_LOW_PRIMARY_AMMO);
if ( GetActiveWeapon() )
{
if ( GetActiveWeapon()->UsesPrimaryAmmo() )
{
if (!GetActiveWeapon()->HasPrimaryAmmo() )
{
SetCondition(COND_NO_PRIMARY_AMMO);
}
else if ( m_NPCState != NPC_STATE_COMBAT && GetActiveWeapon()->UsesClipsForAmmo1() && GetActiveWeapon()->Clip1() < 2 )
{
// Don't send a low ammo message unless we're not in combat.
SetCondition(COND_LOW_PRIMARY_AMMO);
}
}
}
}
示例13: strcpy
//=========================================================
//=========================================================
void CHalfLifeTeamplay::RecountTeams( bool bResendInfo )
{
char *pName;
char teamlist[TEAMPLAY_TEAMLISTLENGTH];
// loop through all teams, recounting everything
num_teams = 0;
// Copy all of the teams from the teamlist
// make a copy because strtok is destructive
strcpy( teamlist, m_szTeamList );
pName = teamlist;
pName = strtok( pName, ";" );
while ( pName != NULL && *pName )
{
if ( GetTeamIndex( pName ) < 0 )
{
strcpy( team_names[num_teams], pName );
num_teams++;
}
pName = strtok( NULL, ";" );
}
if ( num_teams < 2 )
{
num_teams = 0;
m_teamLimit = FALSE;
}
// Sanity check
memset( team_scores, 0, sizeof(team_scores) );
// loop through all clients
for ( int i = 1; i <= gpGlobals->maxClients; i++ )
{
CBaseEntity *plr = UTIL_PlayerByIndex( i );
if ( plr )
{
const char *pTeamName = plr->TeamID();
// try add to existing team
int tm = GetTeamIndex( pTeamName );
if ( tm < 0 ) // no team match found
{
if ( !m_teamLimit )
{
// add to new team
tm = num_teams;
num_teams++;
team_scores[tm] = 0;
strncpy( team_names[tm], pTeamName, MAX_TEAMNAME_LENGTH );
}
}
if ( tm >= 0 )
{
team_scores[tm] += plr->pev->frags;
}
if ( bResendInfo ) //Someone's info changed, let's send the team info again.
{
if ( plr && IsValidTeam( plr->TeamID() ) )
{
MESSAGE_BEGIN( MSG_ALL, gmsgTeamInfo, NULL );
WRITE_BYTE( plr->entindex() );
WRITE_STRING( plr->TeamID() );
MESSAGE_END();
}
}
}
}
}
示例14: switch
//-----------------------------------------------------------------------------
// Purpose: Catches the monster-specific messages that occur when tagged
// animation frames are played.
// Input : *pEvent -
//-----------------------------------------------------------------------------
void CNPC_Headcrab::HandleAnimEvent( animevent_t *pEvent )
{
switch ( pEvent->event )
{
case HC_AE_JUMPATTACK:
{
RemoveFlag( FL_ONGROUND );
//
// Take him off ground so engine doesn't instantly reset FL_ONGROUND.
//
UTIL_SetOrigin( this, GetAbsOrigin() + Vector( 0 , 0 , 1 ));
Vector vecJumpDir;
CBaseEntity *pEnemy = GetEnemy();
if ( pEnemy )
{
Vector vecEnemyEyePos = pEnemy->EyePosition();
float gravity = sv_gravity.GetFloat();
if ( gravity <= 1 )
{
gravity = 1;
}
//
// How fast does the headcrab need to travel to reach my enemy's eyes given gravity?
//
float height = ( vecEnemyEyePos.z - GetAbsOrigin().z );
if ( height < 16 )
{
height = 16;
}
else if ( height > 120 )
{
height = 120;
}
float speed = sqrt( 2 * gravity * height );
float time = speed / gravity;
//
// Scale the sideways velocity to get there at the right time
//
vecJumpDir = vecEnemyEyePos - GetAbsOrigin();
vecJumpDir = vecJumpDir / time;
//
// Speed to offset gravity at the desired height.
//
vecJumpDir.z = speed;
//
// Don't jump too far/fast.
//
float distance = vecJumpDir.Length();
if ( distance > 650 )
{
vecJumpDir = vecJumpDir * ( 650.0 / distance );
}
}
else
{
//
// Jump hop, don't care where.
//
Vector forward, up;
AngleVectors( GetAbsAngles(), &forward, NULL, &up );
vecJumpDir = Vector( forward.x, forward.y, up.z ) * 350;
}
int iSound = random->RandomInt( 0 , 1 );
if ( iSound != 0 )
{
AttackSound();
}
SetAbsVelocity( vecJumpDir );
m_flNextAttack = gpGlobals->curtime + 2;
break;
}
default:
{
CAI_BaseNPC::HandleAnimEvent( pEvent );
break;
}
}
}
示例15: FIND_CLIENT_IN_PVS
void CFuncTank::TrackTarget(void)
{
TraceResult tr;
edict_t * pPlayer = FIND_CLIENT_IN_PVS(edict());
BOOL updateTime = FALSE, lineOfSight;
Vector angles, direction, targetPosition, barrelEnd;
edict_t * pTarget;
// Get a position to aim for
if(m_pController)
{
// Tanks attempt to mirror the player's angles
angles = m_pController->pev->v_angle;
angles[0] = 0 - angles[0];
pev->nextthink = pev->ltime + 0.05;
}
else
{
if(IsActive())
pev->nextthink = pev->ltime + 0.1;
else
return;
if(FNullEnt(pPlayer))
{
if(IsActive())
pev->nextthink = pev->ltime + 2; // Wait 2 secs
return;
}
pTarget = FindTarget(pPlayer);
if(!pTarget)
return;
// Calculate angle needed to aim at target
barrelEnd = BarrelPosition();
targetPosition = pTarget->v.origin + pTarget->v.view_ofs;
float range = (targetPosition - barrelEnd).Length();
if(!InRange(range))
return;
UTIL_TraceLine(barrelEnd, targetPosition, dont_ignore_monsters, edict(), &tr);
lineOfSight = FALSE;
// No line of sight, don't track
if(tr.flFraction == 1.0 || tr.pHit == pTarget)
{
lineOfSight = TRUE;
CBaseEntity *pInstance = CBaseEntity::Instance(pTarget);
if(InRange(range) && pInstance && pInstance->IsAlive())
{
updateTime = TRUE;
m_sightOrigin = UpdateTargetPosition(pInstance);
}
}
// Track sight origin
// !!! I'm not sure what i changed
direction = m_sightOrigin - pev->origin;
// direction = m_sightOrigin - barrelEnd;
angles = UTIL_VecToAngles(direction);
// Calculate the additional rotation to point the end of the barrel at the target (not the gun's center)
AdjustAnglesForBarrel(angles, direction.Length());
}
angles.x = -angles.x;
// Force the angles to be relative to the center position
angles.y = m_yawCenter + UTIL_AngleDistance(angles.y, m_yawCenter);
angles.x = m_pitchCenter + UTIL_AngleDistance(angles.x, m_pitchCenter);
// Limit against range in y
if(angles.y > m_yawCenter + m_yawRange)
{
angles.y = m_yawCenter + m_yawRange;
updateTime = FALSE; // Don't update if you saw the player, but out of range
}
else if(angles.y < (m_yawCenter - m_yawRange))
{
angles.y = (m_yawCenter - m_yawRange);
updateTime = FALSE; // Don't update if you saw the player, but out of range
}
if(updateTime)
m_lastSightTime = gpGlobals->time;
// Move toward target at rate or less
float distY = UTIL_AngleDistance(angles.y, pev->angles.y);
pev->avelocity.y = distY * 10;
if(pev->avelocity.y > m_yawRate)
pev->avelocity.y = m_yawRate;
else if(pev->avelocity.y < -m_yawRate)
pev->avelocity.y = -m_yawRate;
// Limit against range in x
if(angles.x > m_pitchCenter + m_pitchRange)
angles.x = m_pitchCenter + m_pitchRange;
//.........这里部分代码省略.........