本文整理汇总了C++中CBasePlayer类的典型用法代码示例。如果您正苦于以下问题:C++ CBasePlayer类的具体用法?C++ CBasePlayer怎么用?C++ CBasePlayer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CBasePlayer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: HUD_WeaponsPostThink
/*
=====================
HUD_WeaponsPostThink
Run Weapon firing code on client
=====================
*/
void HUD_WeaponsPostThink( local_state_s *from, local_state_s *to, usercmd_t *cmd, double time, unsigned int random_seed )
{
int i;
int buttonsChanged;
CBasePlayerWeapon *pWeapon = NULL;
static int lasthealth;
int flags;
HUD_InitClientWeapons();
// Get current clock
gpGlobals->time = time;
// Fill in data based on selected weapon
switch ( from->client.m_iId )
{
case WEAPON_P228:
pWeapon = &g_P228;
break;
case WEAPON_SCOUT:
pWeapon = &g_SCOUT;
break;
case WEAPON_HEGRENADE:
pWeapon = &g_HEGrenade;
break;
case WEAPON_XM1014:
pWeapon = &g_XM1014;
break;
case WEAPON_C4:
pWeapon = &g_C4;
break;
case WEAPON_MAC10:
pWeapon = &g_MAC10;
break;
case WEAPON_AUG:
pWeapon = &g_AUG;
break;
case WEAPON_SMOKEGRENADE:
pWeapon = &g_SmokeGrenade;
break;
case WEAPON_ELITE:
pWeapon = &g_ELITE;
break;
case WEAPON_FIVESEVEN:
pWeapon = &g_FiveSeven;
break;
case WEAPON_UMP45:
pWeapon = &g_UMP45;
break;
case WEAPON_SG550:
pWeapon = &g_SG550;
break;
case WEAPON_GALIL:
pWeapon = &g_Galil;
break;
case WEAPON_FAMAS:
pWeapon = &g_Famas;
break;
case WEAPON_USP:
pWeapon = &g_USP;
break;
case WEAPON_GLOCK18:
pWeapon = &g_GLOCK18;
break;
case WEAPON_AWP:
pWeapon = &g_AWP;
break;
case WEAPON_MP5N:
pWeapon = &g_MP5N;
break;
case WEAPON_M249:
pWeapon = &g_M249;
break;
case WEAPON_M3:
//.........这里部分代码省略.........
示例2: ToBasePlayer
//-----------------------------------------------------------------------------
// Purpose: Overloaded to handle the zoom functionality.
//-----------------------------------------------------------------------------
void CWeaponSniperRifle::ItemPostFrame( void )
{
CBasePlayer *pPlayer = ToBasePlayer( GetOwner() );
if (pPlayer == NULL)
{
return;
}
if ((m_bInReload) && (m_flNextPrimaryAttack <= gpGlobals->curtime))
{
FinishReload();
m_bInReload = false;
}
if (pPlayer->m_nButtons & IN_ATTACK2)
{
if (m_fNextZoom <= gpGlobals->curtime)
{
Zoom();
pPlayer->m_nButtons &= ~IN_ATTACK2;
}
}
else if ((pPlayer->m_nButtons & IN_ATTACK) && (m_flNextPrimaryAttack <= gpGlobals->curtime))
{
if ( (m_iClip1 == 0 && UsesClipsForAmmo1()) || ( !UsesClipsForAmmo1() && !pPlayer->GetAmmoCount(m_iPrimaryAmmoType) ) )
{
m_bFireOnEmpty = true;
}
// Fire underwater?
if (pPlayer->GetWaterLevel() == 3 && m_bFiresUnderwater == false)
{
WeaponSound(EMPTY);
m_flNextPrimaryAttack = gpGlobals->curtime + 0.2;
return;
}
else
{
// If the firing button was just pressed, reset the firing time
if ( pPlayer && pPlayer->m_afButtonPressed & IN_ATTACK )
{
m_flNextPrimaryAttack = gpGlobals->curtime;
}
PrimaryAttack();
}
}
// -----------------------
// Reload pressed / Clip Empty
// -----------------------
if ( pPlayer->m_nButtons & IN_RELOAD && UsesClipsForAmmo1() && !m_bInReload )
{
// reload when reload is pressed, or if no buttons are down and weapon is empty.
Reload();
}
// -----------------------
// No buttons down
// -----------------------
if (!((pPlayer->m_nButtons & IN_ATTACK) || (pPlayer->m_nButtons & IN_ATTACK2) || (pPlayer->m_nButtons & IN_RELOAD)))
{
// no fire buttons down
m_bFireOnEmpty = false;
if ( !HasAnyAmmo() && m_flNextPrimaryAttack < gpGlobals->curtime )
{
// weapon isn't useable, switch.
if ( !(GetWeaponFlags() & ITEM_FLAG_NOAUTOSWITCHEMPTY) && pPlayer->SwitchToNextBestWeapon( this ) )
{
m_flNextPrimaryAttack = gpGlobals->curtime + 0.3;
return;
}
}
else
{
// weapon is useable. Reload if empty and weapon has waited as long as it has to after firing
if ( m_iClip1 == 0 && !(GetWeaponFlags() & ITEM_FLAG_NOAUTORELOAD) && m_flNextPrimaryAttack < gpGlobals->curtime )
{
Reload();
return;
}
}
WeaponIdle( );
return;
}
}
示例3: Host_Say
//// HOST_SAY
// String comes in as
// say blah blah blah
// or as
// blah blah blah
//
void Host_Say( edict_t *pEntity, int teamonly )
{
CBasePlayer *client;
int j;
char *p;
char text[128];
char szTemp[256];
const char *cpSay = "say";
const char *cpSayTeam = "say_team";
const char *pcmd = CMD_ARGV(0);
// We can get a raw string now, without the "say " prepended
if ( CMD_ARGC() == 0 )
return;
if ( !stricmp( pcmd, cpSay) || !stricmp( pcmd, cpSayTeam ) )
{
if ( CMD_ARGC() >= 2 )
{
p = (char *)CMD_ARGS();
}
else
{
// say with a blank message, nothing to do
return;
}
}
else // Raw text, need to prepend argv[0]
{
if ( CMD_ARGC() >= 2 )
{
sprintf( szTemp, "%s %s", ( char * )pcmd, (char *)CMD_ARGS() );
}
else
{
// Just a one word command, use the first word...sigh
sprintf( szTemp, "%s", ( char * )pcmd );
}
p = szTemp;
}
// remove quotes if present
if (*p == '"')
{
p++;
p[strlen(p)-1] = 0;
}
// make sure the text has content
for ( char *pc = p; pc != NULL && *pc != 0; pc++ )
{
if ( isprint( *pc ) && !isspace( *pc ) )
{
pc = NULL; // we've found an alphanumeric character, so text is valid
break;
}
}
if ( pc != NULL )
return; // no character found, so say nothing
// turn on color set 2 (color on, no sound)
if ( teamonly )
sprintf( text, "%c(TEAM) %s: ", 2, STRING( pEntity->v.netname ) );
else
sprintf( text, "%c%s: ", 2, STRING( pEntity->v.netname ) );
j = sizeof(text) - 2 - strlen(text); // -2 for /n and null terminator
if ( (int)strlen(p) > j )
p[j] = 0;
strcat( text, p );
strcat( text, "\n" );
// loop through all players
// Start with the first player.
// This may return the world in single player if the client types something between levels or during spawn
// so check it, or it will infinite loop
client = NULL;
while ( ((client = (CBasePlayer*)UTIL_FindEntityByClassname( client, "player" )) != NULL) && (!FNullEnt(client->edict())) )
{
if ( !client->pev )
continue;
if ( client->edict() == pEntity )
continue;
if ( !(client->IsNetClient()) ) // Not a client ? (should never be true)
continue;
if ( teamonly && g_pGameRules->PlayerRelationship(client, CBaseEntity::Instance(pEntity)) != GR_TEAMMATE )
continue;
MESSAGE_BEGIN( MSG_ONE, gmsgSayText, NULL, client->pev );
//.........这里部分代码省略.........
示例4: UTIL_Remove
//-----------------------------------------------------------------------------
// Purpose: Think method
//-----------------------------------------------------------------------------
void CTFFlameEntity::FlameThink( void )
{
// if we've expired, remove ourselves
if ( gpGlobals->curtime >= m_flTimeRemove )
{
UTIL_Remove( this );
return;
}
// Do collision detection. We do custom collision detection because we can do it more cheaply than the
// standard collision detection (don't need to check against world unless we might have hit an enemy) and
// flame entity collision detection w/o this was a bottleneck on the X360 server
if ( GetAbsOrigin() != m_vecPrevPos )
{
CTFPlayer *pAttacker = dynamic_cast<CTFPlayer *>( (CBaseEntity *) m_hAttacker );
if ( !pAttacker )
return;
CUtlVector<CTFTeam *> pTeamList;
CTFTeam *pTeam = pAttacker->GetTFTeam();
if ( pTeam )
pTeam->GetOpposingTFTeamList(&pTeamList);
else
return;
//CTFTeam *pTeam = pAttacker->GetOpposingTFTeam();
//if ( !pTeam )
// return;
bool bHitWorld = false;
for (int i = 0; i < pTeamList.Size(); i++)
{
if (pTeamList[i])
{
// check collision against all enemy players
for (int iPlayer = 0; iPlayer < pTeamList[i]->GetNumPlayers(); iPlayer++)
{
CBasePlayer *pPlayer = pTeamList[i]->GetPlayer(iPlayer);
// Is this player connected, alive, and an enemy?
if (pPlayer && pPlayer->IsConnected() && pPlayer->IsAlive() && pPlayer!=pAttacker)
{
CheckCollision(pPlayer, &bHitWorld);
if (bHitWorld)
return;
}
}
// check collision against all enemy objects
for (int iObject = 0; iObject < pTeamList[i]->GetNumObjects(); iObject++)
{
CBaseObject *pObject = pTeamList[i]->GetObject(iObject);
if (pObject)
{
CheckCollision(pObject, &bHitWorld);
if (bHitWorld)
return;
}
}
}
}
}
// Calculate how long the flame has been alive for
float flFlameElapsedTime = tf_flamethrower_flametime.GetFloat() - ( m_flTimeRemove - gpGlobals->curtime );
// Calculate how much of the attacker's velocity to blend in to the flame's velocity. The flame gets the attacker's velocity
// added right when the flame is fired, but that velocity addition fades quickly to zero.
float flAttackerVelocityBlend = RemapValClamped( flFlameElapsedTime, tf_flamethrower_velocityfadestart.GetFloat(),
tf_flamethrower_velocityfadeend.GetFloat(), 1.0, 0 );
// Reduce our base velocity by the air drag constant
m_vecBaseVelocity *= tf_flamethrower_drag.GetFloat();
// Add our float upward velocity
Vector vecVelocity = m_vecBaseVelocity + Vector( 0, 0, tf_flamethrower_float.GetFloat() ) + ( flAttackerVelocityBlend * m_vecAttackerVelocity );
// Update our velocity
SetAbsVelocity( vecVelocity );
// Render debug visualization if convar on
if ( tf_debug_flamethrower.GetInt() )
{
if ( m_hEntitiesBurnt.Count() > 0 )
{
int val = ( (int) ( gpGlobals->curtime * 10 ) ) % 255;
NDebugOverlay::EntityBounds(this, val, 255, val, 0 ,0 );
}
else
{
NDebugOverlay::EntityBounds(this, 0, 100, 255, 0 ,0) ;
}
}
SetNextThink( gpGlobals->curtime );
m_vecPrevPos = GetAbsOrigin();
}
示例5: ClientKill
void ClientKill( edict_t *pEdict, const Vector &vecForce, bool bExplode = false )
{
CBasePlayer *pPlayer = static_cast<CBasePlayer*>( GetContainingEntity( pEdict ) );
pPlayer->CommitSuicide( vecForce, bExplode );
}
示例6: UTIL_PlayerByIndex
//------------------------------------------------------------------------------
// Purpose : Draws a large crosshair at flCrossDistance from the debug player
// with tick marks
// Input :
// Output :
//------------------------------------------------------------------------------
void NDebugOverlay::DrawPositioningOverlay( float flCrossDistance )
{
CBasePlayer* pPlayer = UTIL_PlayerByIndex(CBaseEntity::m_nDebugPlayer);
if (!pPlayer)
{
return;
}
Vector pRight;
pPlayer->EyeVectors( NULL, &pRight, NULL );
#ifdef _WIN32
Vector topPos = NWCEdit::AirNodePlacementPosition();
#else
Vector pForward;
pPlayer->EyeVectors( &pForward );
Vector floorVec = pForward;
floorVec.z = 0;
VectorNormalize( floorVec );
VectorNormalize( pForward );
float cosAngle = DotProduct(floorVec,pForward);
float lookDist = g_pAINetworkManager->GetEditOps()->m_flAirEditDistance/cosAngle;
Vector topPos = pPlayer->EyePosition()+pForward * lookDist;
#endif
Vector bottomPos = topPos;
bottomPos.z = GetLongFloorZ(bottomPos);
// Make sure we can see the target pos
trace_t tr;
Vector endPos;
UTIL_TraceLine(pPlayer->EyePosition(), topPos, MASK_NPCSOLID_BRUSHONLY, pPlayer, COLLISION_GROUP_NONE, &tr);
if (tr.fraction == 1.0)
{
Vector rightTrace = topPos + pRight*400;
float traceLen = (topPos - rightTrace).Length();
UTIL_TraceLine(topPos, rightTrace, MASK_NPCSOLID_BRUSHONLY, pPlayer, COLLISION_GROUP_NONE, &tr);
endPos = topPos+(pRight*traceLen*tr.fraction);
NDebugOverlay::DrawTickMarkedLine(topPos, endPos, 24.0, 5, 255,0,0,false,0);
Vector leftTrace = topPos - pRight*400;
traceLen = (topPos - leftTrace).Length();
UTIL_TraceLine(topPos, leftTrace, MASK_NPCSOLID_BRUSHONLY, pPlayer, COLLISION_GROUP_NONE, &tr);
endPos = topPos-(pRight*traceLen*tr.fraction);
NDebugOverlay::DrawTickMarkedLine(topPos, endPos, 24.0, 5, 255,0,0,false,0);
Vector upTrace = topPos + Vector(0,0,1)*400;
traceLen = (topPos - upTrace).Length();
UTIL_TraceLine(topPos, upTrace, MASK_NPCSOLID_BRUSHONLY, pPlayer, COLLISION_GROUP_NONE, &tr);
endPos = topPos+(Vector(0,0,1)*traceLen*tr.fraction);
NDebugOverlay::DrawTickMarkedLine(bottomPos, endPos, 24.0, 5, 255,0,0,false,0);
// Draw white cross at center
Cross3D(topPos, Vector(-2,-2,-2), Vector(2,2,2), 255,255,255, true, 0);
}
else
{
// Draw warning cross at center
Cross3D(topPos, Vector(-2,-2,-2), Vector(2,2,2), 255,100,100, true, 0 );
}
/* Don't show distance for now.
char text[25];
Q_snprintf(text,sizeof(text),"%3.0f",flCrossDistance/12.0);
Vector textPos = topPos - pRight*16 + Vector(0,0,10);
NDebugOverlay::Text( textPos, text, true, 0 );
*/
}
示例7: ToBasePlayer
void CWeaponEgon::Fire( const Vector &vecOrigSrc, const Vector &vecDir )
{
CBasePlayer *pPlayer = ToBasePlayer( GetOwner() );
if ( !pPlayer )
{
return;
}
//CSoundEnt::InsertSound( SOUND_COMBAT, GetAbsOrigin(), 450, 0.1 );
WeaponSound( SINGLE );
Vector vecDest = vecOrigSrc + (vecDir * MAX_TRACE_LENGTH);
trace_t tr;
UTIL_TraceLine( vecOrigSrc, vecDest, MASK_SHOT, pPlayer, COLLISION_GROUP_NONE, &tr );
if ( tr.allsolid )
return;
CBaseEntity *pEntity = tr.m_pEnt;
if ( pEntity == NULL )
return;
if ( g_pGameRules->IsMultiplayer() )
{
if ( m_hSprite )
{
if ( pEntity->m_takedamage != DAMAGE_NO )
{
m_hSprite->TurnOn();
}
else
{
m_hSprite->TurnOff();
}
}
}
if ( m_flDmgTime < gpGlobals->curtime )
{
// wide mode does damage to the ent, and radius damage
if ( pEntity->m_takedamage != DAMAGE_NO )
{
ClearMultiDamage();
CTakeDamageInfo info(this, pPlayer, sk_plr_dmg_egon_wide.GetFloat() * g_pGameRules->GetDamageMultiplier(), DMG_ENERGYBEAM | DMG_ALWAYSGIB | DMG_CRUSH);
CalculateMeleeDamageForce( &info, vecDir, tr.endpos );
pEntity->DispatchTraceAttack( info, vecDir, &tr );
ApplyMultiDamage();
}
if ( g_pGameRules->IsMultiplayer() )
{
// radius damage a little more potent in multiplayer.
#ifndef CLIENT_DLL
RadiusDamage(CTakeDamageInfo(this, pPlayer, sk_plr_dmg_egon_wide.GetFloat() * g_pGameRules->GetDamageMultiplier() / 4, DMG_ENERGYBEAM | DMG_BLAST | DMG_ALWAYSGIB | DMG_CRUSH), tr.endpos, 128, CLASS_NONE, NULL);
#endif
}
if ( !pPlayer->IsAlive() )
return;
if ( g_pGameRules->IsMultiplayer() )
{
//multiplayer uses 5 ammo/second
if ( gpGlobals->curtime >= m_flAmmoUseTime )
{
UseAmmo( 1 );
m_flAmmoUseTime = gpGlobals->curtime + 0.2;
}
}
else
{
// Wide mode uses 10 charges per second in single player
if ( gpGlobals->curtime >= m_flAmmoUseTime )
{
UseAmmo( 1 );
m_flAmmoUseTime = gpGlobals->curtime + 0.1;
}
}
m_flDmgTime = gpGlobals->curtime + EGON_DISCHARGE_INTERVAL;
if ( m_flShakeTime < gpGlobals->curtime )
{
#ifndef CLIENT_DLL
UTIL_ScreenShake( tr.endpos, 5.0, 150.0, 0.75, 250.0, SHAKE_START );
#endif
m_flShakeTime = gpGlobals->curtime + 1.5;
}
}
Vector vecUp, vecRight;
QAngle angDir;
VectorAngles( vecDir, angDir );
AngleVectors( angDir, NULL, &vecRight, &vecUp );
Vector tmpSrc = vecOrigSrc + (vecUp * -8) + (vecRight * 3);
UpdateEffect( tmpSrc, tr.endpos );
}
示例8: UTIL_Remove
void CPlantedC4::C4Think()
{
if (!IsInWorld())
{
UTIL_Remove( this );
return;
}
//Bomb is dead, don't think anymore
if( !m_bBombTicking )
{
SetThink( NULL );
return;
}
SetNextThink( gpGlobals->curtime + 0.12 );
#ifndef CLIENT_DLL
// let the bots hear the bomb beeping
// BOTPORT: Emit beep events at same time as client effects
IGameEvent * event = gameeventmanager->CreateEvent( "bomb_beep" );
if( event )
{
event->SetInt( "entindex", entindex() );
gameeventmanager->FireEvent( event );
}
#endif
// IF the timer has expired ! blow this bomb up!
if (m_flC4Blow <= gpGlobals->curtime)
{
// give the defuser credit for defusing the bomb
CBasePlayer *pBombOwner = dynamic_cast< CBasePlayer* >( GetOwnerEntity() );
if ( pBombOwner )
{
pBombOwner->IncrementFragCount( 3 );
}
CSGameRules()->m_bBombDropped = false;
trace_t tr;
Vector vecSpot = GetAbsOrigin();
vecSpot[2] += 8;
UTIL_TraceLine( vecSpot, vecSpot + Vector ( 0, 0, -40 ), MASK_SOLID, this, COLLISION_GROUP_NONE, &tr );
Explode( &tr, DMG_BLAST );
CSGameRules()->m_bBombPlanted = false;
IGameEvent * event = gameeventmanager->CreateEvent( "bomb_exploded" );
if( event )
{
event->SetInt( "userid", pBombOwner?pBombOwner->GetUserID():-1 );
event->SetInt( "site", m_iBombSiteIndex );
event->SetInt( "priority", 9 );
gameeventmanager->FireEvent( event );
}
}
//if the defusing process has started
if ((m_bStartDefuse == true) && (m_pBombDefuser != NULL))
{
//if the defusing process has not ended yet
if ( m_flDefuseCountDown > gpGlobals->curtime)
{
int iOnGround = FBitSet( m_pBombDefuser->GetFlags(), FL_ONGROUND );
//if the bomb defuser has stopped defusing the bomb
if( m_flNextDefuse < gpGlobals->curtime || !iOnGround )
{
if ( !iOnGround && m_pBombDefuser->IsAlive() )
ClientPrint( m_pBombDefuser, HUD_PRINTCENTER, "#C4_Defuse_Must_Be_On_Ground");
// release the player from being frozen
m_pBombDefuser->ResetMaxSpeed();
m_pBombDefuser->m_bIsDefusing = false;
#ifndef CLIENT_DLL
// tell the bots someone has aborted defusing
IGameEvent * event = gameeventmanager->CreateEvent( "bomb_abortdefuse" );
if( event )
{
event->SetInt("userid", m_pBombDefuser->GetUserID() );
event->SetInt( "priority", 6 );
gameeventmanager->FireEvent( event );
}
#endif
//cancel the progress bar
m_pBombDefuser->SetProgressBarTime( 0 );
m_pBombDefuser = NULL;
m_bStartDefuse = false;
m_flDefuseCountDown = 0;
m_flDefuseLength = 0; //force it to show completely defused
}
return;
}
//.........这里部分代码省略.........
示例9: Square
//.........这里部分代码省略.........
float flMass = pBlockingEntity->VPhysicsGetObject()->GetMass();
float scale = flMass / MASS_ABSORB_ALL_DAMAGE;
// Absorbed all the damage.
if( scale >= 1.0f )
{
continue;
}
ASSERT( scale > 0.0f );
flBlockedDamagePercent = scale;
//Msg(" Object (%s) weighing %fkg blocked %f percent of explosion damage\n", pBlockingEntity->GetClassname(), flMass, scale * 100.0f);
}
else
{
// Some object that's not the world and not physics. Generically block 25% damage
flBlockedDamagePercent = 0.25f;
}
}
}
}
// decrease damage for an ent that's farther from the bomb.
flAdjustedDamage = ( vecSrc - tr.endpos ).Length() * falloff;
flAdjustedDamage = info.GetDamage() - flAdjustedDamage;
if ( flAdjustedDamage <= 0 )
{
continue;
}
// the explosion can 'see' this entity, so hurt them!
if (tr.startsolid)
{
// if we're stuck inside them, fixup the position and distance
tr.endpos = vecSrc;
tr.fraction = 0.0;
}
CTakeDamageInfo adjustedInfo = info;
//Msg("%s: Blocked damage: %f percent (in:%f out:%f)\n", pEntity->GetClassname(), flBlockedDamagePercent * 100, flAdjustedDamage, flAdjustedDamage - (flAdjustedDamage * flBlockedDamagePercent) );
adjustedInfo.SetDamage( flAdjustedDamage - (flAdjustedDamage * flBlockedDamagePercent) );
// Now make a consideration for skill level!
if( info.GetAttacker() && info.GetAttacker()->IsPlayer() && pEntity->IsNPC() )
{
// An explosion set off by the player is harming an NPC. Adjust damage accordingly.
adjustedInfo.AdjustPlayerDamageInflictedForSkillLevel();
}
Vector dir = vecSpot - vecSrc;
VectorNormalize( dir );
// If we don't have a damage force, manufacture one
if ( adjustedInfo.GetDamagePosition() == vec3_origin || adjustedInfo.GetDamageForce() == vec3_origin )
{
if ( !( adjustedInfo.GetDamageType() & DMG_PREVENT_PHYSICS_FORCE ) )
{
CalculateExplosiveDamageForce( &adjustedInfo, dir, vecSrc );
}
}
else
{
// Assume the force passed in is the maximum force. Decay it based on falloff.
float flForce = adjustedInfo.GetDamageForce().Length() * falloff;
adjustedInfo.SetDamageForce( dir * flForce );
adjustedInfo.SetDamagePosition( vecSrc );
}
if ( tr.fraction != 1.0 && pEntity == tr.m_pEnt )
{
ClearMultiDamage( );
pEntity->DispatchTraceAttack( adjustedInfo, dir, &tr );
ApplyMultiDamage();
}
else
{
pEntity->TakeDamage( adjustedInfo );
}
// Now hit all triggers along the way that respond to damage...
pEntity->TraceAttackToTriggers( adjustedInfo, vecSrc, tr.endpos, dir );
#if defined( GAME_DLL )
if ( info.GetAttacker() && info.GetAttacker()->IsPlayer() && ToBaseCombatCharacter( tr.m_pEnt ) )
{
// This is a total hack!!!
bool bIsPrimary = true;
CBasePlayer *player = ToBasePlayer( info.GetAttacker() );
CBaseCombatWeapon *pWeapon = player->GetActiveWeapon();
if ( pWeapon && FClassnameIs( pWeapon, "weapon_smg1" ) )
{
bIsPrimary = false;
}
gamestats->Event_WeaponHit( player, bIsPrimary, (pWeapon != NULL) ? player->GetActiveWeapon()->GetClassname() : "NULL", info );
}
#endif
}
}
示例10: ToBasePlayer
//------------------------------------------------------------------------------
// Purpose : Starts the swing of the weapon and determines the animation
// Input : bIsSecondary - is this a secondary attack?
//------------------------------------------------------------------------------
void CBaseHL2MPBludgeonWeapon::Swing( int bIsSecondary )
{
trace_t traceHit;
// Try a ray
CBasePlayer *pOwner = ToBasePlayer( GetOwner() );
if ( !pOwner )
return;
Vector swingStart = pOwner->Weapon_ShootPosition( );
Vector forward;
pOwner->EyeVectors( &forward, NULL, NULL );
Vector swingEnd = swingStart + forward * GetRange();
UTIL_TraceLine( swingStart, swingEnd, MASK_SHOT_HULL, pOwner, COLLISION_GROUP_NONE, &traceHit );
Activity nHitActivity = ACT_VM_HITCENTER;
#ifndef CLIENT_DLL
// Like bullets, bludgeon traces have to trace against triggers.
CTakeDamageInfo triggerInfo( GetOwner(), GetOwner(), GetDamageForActivity( nHitActivity ), DMG_CLUB );
TraceAttackToTriggers( triggerInfo, traceHit.startpos, traceHit.endpos, vec3_origin );
#endif
if ( traceHit.fraction == 1.0 )
{
float bludgeonHullRadius = 1.732f * BLUDGEON_HULL_DIM; // hull is +/- 16, so use cuberoot of 2 to determine how big the hull is from center to the corner point
// Back off by hull "radius"
swingEnd -= forward * bludgeonHullRadius;
UTIL_TraceHull( swingStart, swingEnd, g_bludgeonMins, g_bludgeonMaxs, MASK_SHOT_HULL, pOwner, COLLISION_GROUP_NONE, &traceHit );
if ( traceHit.fraction < 1.0 && traceHit.m_pEnt )
{
Vector vecToTarget = traceHit.m_pEnt->GetAbsOrigin() - swingStart;
VectorNormalize( vecToTarget );
float dot = vecToTarget.Dot( forward );
// YWB: Make sure they are sort of facing the guy at least...
if ( dot < 0.70721f )
{
// Force amiss
traceHit.fraction = 1.0f;
}
else
{
nHitActivity = ChooseIntersectionPointAndActivity( traceHit, g_bludgeonMins, g_bludgeonMaxs, pOwner );
}
}
}
WeaponSound( SINGLE );
// -------------------------
// Miss
// -------------------------
if ( traceHit.fraction == 1.0f )
{
nHitActivity = bIsSecondary ? ACT_VM_MISSCENTER2 : ACT_VM_MISSCENTER;
// We want to test the first swing again
Vector testEnd = swingStart + forward * GetRange();
// See if we happened to hit water
ImpactWater( swingStart, testEnd );
}
else
{
Hit( traceHit, nHitActivity );
}
// Send the anim
SendWeaponAnim( nHitActivity );
pOwner->SetAnimation( PLAYER_ATTACK1 );
ToHL2MPPlayer(pOwner)->DoAnimationEvent( PLAYERANIMEVENT_ATTACK_PRIMARY );
//Setup our next attack times
m_flNextPrimaryAttack = gpGlobals->curtime + GetFireRate();
m_flNextSecondaryAttack = gpGlobals->curtime + SequenceDuration();
}
示例11: 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 ) );
}
}
}
}
示例12: ToBasePlayer
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CWeapon357::PrimaryAttack( void )
{
// Only the player fires this way so we can cast
CBasePlayer *pPlayer = ToBasePlayer( GetOwner() );
if ( !pPlayer )
{
return;
}
if ( m_iClip1 <= 0 )
{
if ( !m_bFireOnEmpty )
{
Reload();
}
else
{
WeaponSound( EMPTY );
m_flNextPrimaryAttack = 0.15;
}
return;
}
WeaponSound( SINGLE );
pPlayer->DoMuzzleFlash();
SendWeaponAnim( ACT_VM_PRIMARYATTACK );
pPlayer->SetAnimation( PLAYER_ATTACK1 );
m_flNextPrimaryAttack = gpGlobals->curtime + 0.75;
m_flNextSecondaryAttack = gpGlobals->curtime + 0.75;
m_iClip1--;
Vector vecSrc = pPlayer->Weapon_ShootPosition();
Vector vecAiming = pPlayer->GetAutoaimVector( AUTOAIM_5DEGREES );
FireBulletsInfo_t info( 1, vecSrc, vecAiming, vec3_origin, MAX_TRACE_LENGTH, m_iPrimaryAmmoType );
info.m_pAttacker = pPlayer;
// Fire the bullets, and force the first shot to be perfectly accuracy
pPlayer->FireBullets( info );
//Disorient the player
QAngle angles = pPlayer->GetLocalAngles();
angles.x += random->RandomInt( -1, 1 );
angles.y += random->RandomInt( -1, 1 );
angles.z = 0;
#ifndef CLIENT_DLL
pPlayer->SnapEyeAngles( angles );
#endif
pPlayer->ViewPunch( QAngle( -8, random->RandomFloat( -2, 2 ), 0 ) );
if ( !m_iClip1 && pPlayer->GetAmmoCount( m_iPrimaryAmmoType ) <= 0 )
{
// HEV suit - indicate out of ammo condition
pPlayer->SetSuitUpdate( "!HEV_AMO0", FALSE, 0 );
}
}
示例13: this
//-----------------------------------------------------------------------------
// Purpose: See if I can make my leaping attack!!
//
//
//-----------------------------------------------------------------------------
int CFastZombie::RangeAttack1Conditions( float flDot, float flDist )
{
#define FASTZOMBIE_MINLEAP 128
#define FASTZOMBIE_MAXLEAP 508 // see me if you have questions about this (sjb - telegraphing)
if (GetEnemy() == NULL)
{
return( COND_NONE );
}
if( !(GetFlags() & FL_ONGROUND) )
{
return COND_NONE;
}
if( gpGlobals->curtime < m_flNextAttack )
{
return( COND_NONE );
}
if (flDot < 0.8)
{
//return COND_NOT_FACING_ATTACK;
return COND_NONE;
}
// make sure the enemy isn't on a roof and I'm in the streets (Ravenholm)
float flZDist;
flZDist = GetEnemy()->GetLocalOrigin().z - GetLocalOrigin().z;
if( flZDist > 128 )
{
return COND_TOO_FAR_TO_ATTACK;
}
if( flDist > FASTZOMBIE_MAXLEAP )
{
return COND_TOO_FAR_TO_ATTACK;
}
if( flDist < FASTZOMBIE_MINLEAP )
{
//return COND_TOO_CLOSE_TO_ATTACK;
return COND_NONE;
}
if ( !IsMoving() )
{
// I Have to be running!!!
return COND_NONE;
}
// Don't jump at the player unless he's facing me.
// This allows the player to get away if he turns and sprints
CBasePlayer *pPlayer = static_cast<CBasePlayer*>( GetEnemy() );
if( pPlayer )
{
// If the enemy is a player, don't attack from behind!
if( !pPlayer->FInViewCone( this ) )
{
return COND_NONE;
}
}
// Drumroll please!
// The final check! Is the path from my position to halfway between me
// and the player clear?
trace_t tr;
Vector vecDirToEnemy;
vecDirToEnemy = GetEnemy()->WorldSpaceCenter() - WorldSpaceCenter();
Vector vecHullMin( -16, -16, -16 );
Vector vecHullMax( 16, 16, 16 );
// only check half the distance. (the first part of the jump)
vecDirToEnemy = vecDirToEnemy * 0.5;
AI_TraceHull( WorldSpaceCenter(), WorldSpaceCenter() + vecDirToEnemy, vecHullMin, vecHullMax, MASK_SHOT, this, COLLISION_GROUP_NONE, &tr );
if( tr.fraction != 1.0 )
{
// There's some sort of obstacle pretty much right in front of me.
return COND_NONE;
}
return COND_CAN_RANGE_ATTACK1;
}
示例14: MaxAmmoCarry
//=========================================================
// CWeaponBox - Touch: try to add my contents to the toucher
// if the toucher is a player.
//=========================================================
void CWeaponBox::Touch(CBaseEntity *pOther)
{
if(!(pev->flags & FL_ONGROUND))
{
return;
}
if(!pOther->IsPlayer())
{
// only players may touch a weaponbox.
return;
}
if(!pOther->IsAlive())
{
// no dead guys.
return;
}
CBasePlayer *pPlayer = (CBasePlayer *)pOther;
int i;
// dole out ammo
for(i = 0; i < MAX_AMMO_SLOTS; i++)
{
if(!FStringNull(m_rgiszAmmo[i]))
{
// there's some ammo of this type.
pPlayer->GiveAmmo(m_rgAmmo[i], (char *)STRING(m_rgiszAmmo[i]), MaxAmmoCarry(m_rgiszAmmo[i]));
//ALERT ( at_console, "Gave %d rounds of %s\n", m_rgAmmo[i], STRING(m_rgiszAmmo[i]) );
// now empty the ammo from the weaponbox since we just gave it to the player
m_rgiszAmmo[i] = iStringNull;
m_rgAmmo[i] = 0;
}
}
// go through my weapons and try to give the usable ones to the player.
// it's important the the player be given ammo first, so the weapons code doesn't refuse
// to deploy a better weapon that the player may pick up because he has no ammo for it.
for(i = 0; i < MAX_ITEM_TYPES; i++)
{
if(m_rgpPlayerItems[i])
{
CBasePlayerItem *pItem;
// have at least one weapon in this slot
while(m_rgpPlayerItems[i])
{
//ALERT ( at_console, "trying to give %s\n", STRING( m_rgpPlayerItems[ i ]->pev->classname ) );
pItem = m_rgpPlayerItems[i];
m_rgpPlayerItems[i] = m_rgpPlayerItems[i]->m_pNext; // unlink this weapon from the box
if(pPlayer->AddPlayerItem(pItem))
{
pItem->AttachToPlayer(pPlayer);
}
}
}
}
EMIT_SOUND(pOther->edict(), CHAN_ITEM, "items/gunpickup2.wav", 1, ATTN_NORM);
SetTouch(NULL);
UTIL_Remove(this);
}
示例15: VPROF_BUDGET
void CLagCompensationManager::BacktrackPlayer( CBasePlayer *pPlayer, float flTargetTime )
{
Vector org;
Vector minsPreScaled;
Vector maxsPreScaled;
QAngle ang;
VPROF_BUDGET( "BacktrackPlayer", "CLagCompensationManager" );
int pl_index = pPlayer->entindex() - 1;
// get track history of this player
CUtlFixedLinkedList< LagRecord > *track = &m_PlayerTrack[ pl_index ];
// check if we have at leat one entry
if ( track->Count() <= 0 )
return;
int curr = track->Head();
LagRecord *prevRecord = NULL;
LagRecord *record = NULL;
Vector prevOrg = pPlayer->GetLocalOrigin();
// Walk context looking for any invalidating event
while( track->IsValidIndex(curr) )
{
// remember last record
prevRecord = record;
// get next record
record = &track->Element( curr );
if ( !(record->m_fFlags & LC_ALIVE) )
{
// player most be alive, lost track
return;
}
Vector delta = record->m_vecOrigin - prevOrg;
if ( delta.Length2DSqr() > m_flTeleportDistanceSqr )
{
// lost track, too much difference
return;
}
// did we find a context smaller than target time ?
if ( record->m_flSimulationTime <= flTargetTime )
break; // hurra, stop
prevOrg = record->m_vecOrigin;
// go one step back
curr = track->Next( curr );
}
Assert( record );
if ( !record )
{
if ( sv_unlag_debug.GetBool() )
{
DevMsg( "No valid positions in history for BacktrackPlayer client ( %s )\n", pPlayer->GetPlayerName() );
}
return; // that should never happen
}
float frac = 0.0f;
if ( prevRecord &&
(record->m_flSimulationTime < flTargetTime) &&
(record->m_flSimulationTime < prevRecord->m_flSimulationTime) )
{
// we didn't find the exact time but have a valid previous record
// so interpolate between these two records;
Assert( prevRecord->m_flSimulationTime > record->m_flSimulationTime );
Assert( flTargetTime < prevRecord->m_flSimulationTime );
// calc fraction between both records
frac = ( flTargetTime - record->m_flSimulationTime ) /
( prevRecord->m_flSimulationTime - record->m_flSimulationTime );
Assert( frac > 0 && frac < 1 ); // should never extrapolate
ang = Lerp( frac, record->m_vecAngles, prevRecord->m_vecAngles );
org = Lerp( frac, record->m_vecOrigin, prevRecord->m_vecOrigin );
minsPreScaled = Lerp( frac, record->m_vecMinsPreScaled, prevRecord->m_vecMinsPreScaled );
maxsPreScaled = Lerp( frac, record->m_vecMaxsPreScaled, prevRecord->m_vecMaxsPreScaled );
}
else
{
// we found the exact record or no other record to interpolate with
// just copy these values since they are the best we have
org = record->m_vecOrigin;
ang = record->m_vecAngles;
minsPreScaled = record->m_vecMinsPreScaled;
maxsPreScaled = record->m_vecMaxsPreScaled;
}
//.........这里部分代码省略.........