📄 tf_playerclass.cpp
字号:
// Purpose: New technology has been gained. Recalculate any class specific technology dependencies.
//-----------------------------------------------------------------------------
void CPlayerClass::GainedNewTechnology( CBaseTechnology *pTechnology )
{
int i;
// Tell the player's weapons that this player's gained new technology
for ( i = 0; i < m_pPlayer->WeaponCount(); i++ )
{
if ( m_pPlayer->GetWeapon(i) )
{
((CBaseTFCombatWeapon*)m_pPlayer->GetWeapon(i))->GainedNewTechnology( pTechnology );
}
}
// Tell the player's objects that this player's gained new technology
for ( i = 0; i < m_pPlayer->GetObjectCount(); i++ )
{
if (m_pPlayer->GetObject(i))
{
m_pPlayer->GetObject(i)->GainedNewTechnology( pTechnology );
}
}
}
//-----------------------------------------------------------------------------
// Purpose: Return true if this player's allowed to build another one of the specified objects
//-----------------------------------------------------------------------------
int CPlayerClass::CanBuild( int iObjectType )
{
int iObjectCount = GetNumObjects( iObjectType );
// Make sure we haven't hit maximum number
if ( tf2_object_hard_limits.GetBool() )
{
if ( iObjectCount >= GetObjectInfo( iObjectType )->m_nMaxObjects )
return CB_LIMIT_REACHED;
}
else
{
// Find out how much the next object should cost
int iCost = CalculateObjectCost( iObjectType, GetNumObjects( iObjectType ), m_pPlayer->GetTeamNumber() );
// Make sure we have enough resources
if ( m_pPlayer->GetBankResources() < iCost )
return CB_NEED_RESOURCES;
}
return CB_CAN_BUILD;
}
//-----------------------------------------------------------------------------
// Purpose: Object built by this player has been destroyed
//-----------------------------------------------------------------------------
void CPlayerClass::OwnedObjectDestroyed( CBaseObject *pObject )
{
}
//-----------------------------------------------------------------------------
// Purpose: Get the number of the specified objects built by the player
//-----------------------------------------------------------------------------
int CPlayerClass::GetNumObjects( int iObjectType )
{
// For the purposes of costs/limits, Sentryguns tally up all sentrygun types
if ( iObjectType == OBJ_SENTRYGUN_PLASMA || iObjectType == OBJ_SENTRYGUN_ROCKET_LAUNCHER )
{
return ( m_pPlayer->GetNumObjects( OBJ_SENTRYGUN_PLASMA ) + m_pPlayer->GetNumObjects( OBJ_SENTRYGUN_ROCKET_LAUNCHER ) );
}
return m_pPlayer->GetNumObjects( iObjectType );
}
//-----------------------------------------------------------------------------
// Purpose: Player has started building an object
//-----------------------------------------------------------------------------
int CPlayerClass::StartedBuildingObject( int iObjectType )
{
// Deduct the cost of the object
if ( !tf2_object_hard_limits.GetBool() )
{
int iCost = CalculateObjectCost( iObjectType, GetNumObjects( iObjectType ), m_pPlayer->GetTeamNumber() );
if ( iCost > m_pPlayer->GetBankResources() )
{
// Player must have lost resources since he started placing
return 0;
}
m_pPlayer->RemoveBankResources( iCost );
// If the object costs 0, we need to return non-0 to mean success
if ( !iCost )
return 1;
return iCost;
}
return 1;
}
//-----------------------------------------------------------------------------
// Purpose: Player has aborted a build
//-----------------------------------------------------------------------------
void CPlayerClass::StoppedBuilding( int iObjectType )
{
// Return the cost of the object
if ( !tf2_object_hard_limits.GetBool() )
{
int iCost = CalculateObjectCost( iObjectType, GetNumObjects( iObjectType ), m_pPlayer->GetTeamNumber() );
m_pPlayer->AddBankResources( iCost );
}
}
//-----------------------------------------------------------------------------
// Purpose: Object has been built by this player
//-----------------------------------------------------------------------------
void CPlayerClass::FinishedObject( CBaseObject *pObject )
{
}
//-----------------------------------------------------------------------------
// Purpose: Object has been picked up by this player
//-----------------------------------------------------------------------------
void CPlayerClass::PickupObject( CBaseObject *pObject )
{
// Return the cost of the object
if ( !tf2_object_hard_limits.GetBool() )
{
int iCost = CalculateObjectCost( pObject->GetType(), GetNumObjects( pObject->GetType() ), m_pPlayer->GetTeamNumber(), true );
m_pPlayer->AddBankResources( iCost );
}
}
//-----------------------------------------------------------------------------
// Purpose: Create a personal order for this player
//-----------------------------------------------------------------------------
bool CPlayerClass::CreateInitialOrder()
{
if( AnyNonResourceZoneOrders() )
return true;
return false;
}
void CPlayerClass::CreatePersonalOrder()
{
if( CreateInitialOrder() )
return;
// Make an order to fix any objects we own.
if ( COrderRepair::CreateOrder_RepairOwnObjects( this ) )
return;
}
bool CPlayerClass::AnyResourceZoneOrders()
{
return !!m_pPlayer->GetNumResourceZoneOrders();
}
bool CPlayerClass::AnyNonResourceZoneOrders()
{
return
m_pPlayer->GetNumResourceZoneOrders() == 0 &&
m_pPlayer->GetOrder();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CPlayerClass::ClassThink( void )
{
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CPlayerClass::PowerupStart( int iPowerup, float flAmount, CBaseEntity *pAttacker, CDamageModifier *pDamageModifier )
{
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CPlayerClass::PowerupEnd( int iPowerup )
{
}
//-----------------------------------------------------------------------------
// Purpose: My player has just died
//-----------------------------------------------------------------------------
void CPlayerClass::PlayerDied( CBaseEntity *pAttacker )
{
if ( pAttacker )
{
CBaseTFPlayer *pAttackerPlayer = dynamic_cast< CBaseTFPlayer* >( pAttacker );
if ( pAttackerPlayer )
{
CPlayerClass *pAttackerClass = pAttackerPlayer->GetPlayerClass();
if ( pAttackerClass )
{
int iStatGroup = GetStatGroupFor( pAttackerPlayer );
g_PlayerClassStats[ iStatGroup ].m_InterClassStats[GetTFClass()].m_nKills++;
}
}
}
}
//-----------------------------------------------------------------------------
// Purpose: My player just killed another player
//-----------------------------------------------------------------------------
void CPlayerClass::PlayerKilledPlayer( CBaseTFPlayer *pVictim )
{
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CPlayerClass::SetPlayerHull( void )
{
// Use the generic player hull if the class doesn't override this function.
if ( m_pPlayer->GetFlags() & FL_DUCKING )
{
m_pPlayer->SetCollisionBounds( PLAYERCLASS_HULL_DUCK_MIN, PLAYERCLASS_HULL_DUCK_MAX );
}
else
{
m_pPlayer->SetCollisionBounds( PLAYERCLASS_HULL_STAND_MIN, PLAYERCLASS_HULL_STAND_MAX );
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CPlayerClass::GetPlayerHull( bool bDucking, Vector &vecMin, Vector &vecMax )
{
// Use the generic player hull if the class doesn't override this function.
if ( bDucking )
{
VectorCopy( PLAYERCLASS_HULL_DUCK_MIN, vecMin );
VectorCopy( PLAYERCLASS_HULL_DUCK_MAX, vecMax );
}
else
{
VectorCopy( PLAYERCLASS_HULL_STAND_MIN, vecMin );
VectorCopy( PLAYERCLASS_HULL_STAND_MAX, vecMax );
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CPlayerClass::InitVCollision( void )
{
CPhysCollide *pStandModel = PhysCreateBbox( PLAYERCLASS_HULL_STAND_MIN, PLAYERCLASS_HULL_STAND_MAX );
CPhysCollide *pCrouchModel = PhysCreateBbox( PLAYERCLASS_HULL_DUCK_MIN, PLAYERCLASS_HULL_DUCK_MAX );
solid_t solid;
solid.params = g_PhysDefaultObjectParams;
solid.params.mass = 85.0f;
solid.params.inertia = 1e24f;
solid.params.enableCollisions = false;
//disable drag
solid.params.dragCoefficient = 0;
// create standing hull
m_pPlayer->m_pShadowStand = PhysModelCreateCustom( m_pPlayer, pStandModel, m_pPlayer->GetLocalOrigin(), m_pPlayer->GetLocalAngles(), "tfplayer_generic", false, &solid );
m_pPlayer->m_pShadowStand->SetCallbackFlags( CALLBACK_SHADOW_COLLISION );
// create crouchig hull
m_pPlayer->m_pShadowCrouch = PhysModelCreateCustom( m_pPlayer, pCrouchModel, m_pPlayer->GetLocalOrigin(), m_pPlayer->GetLocalAngles(), "tfplayer_generic", false, &solid );
m_pPlayer->m_pShadowCrouch->SetCallbackFlags( CALLBACK_SHADOW_COLLISION );
// default to stand
m_pPlayer->VPhysicsSetObject( m_pPlayer->m_pShadowStand );
//disable drag
m_pPlayer->m_pShadowStand->EnableDrag( false );
m_pPlayer->m_pShadowCrouch->EnableDrag( false );
// tell physics lists I'm a shadow controller object
PhysAddShadow( m_pPlayer );
m_pPlayer->m_pPhysicsController = physenv->CreatePlayerController( m_pPlayer->m_pShadowStand );
// init state
if ( m_pPlayer->GetFlags() & FL_DUCKING )
{
m_pPlayer->SetVCollisionState( VPHYS_CROUCH );
}
else
{
m_pPlayer->SetVCollisionState( VPHYS_WALK );
}
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : *pObject -
// *pNewOwner -
//-----------------------------------------------------------------------------
void CPlayerClass::OwnedObjectChangeToTeam( CBaseObject *pObject, CBaseTFPlayer *pNewOwner )
{
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : *pObject -
// *pOldOwner -
//-----------------------------------------------------------------------------
void CPlayerClass::OwnedObjectChangeFromTeam( CBaseObject *pObject, CBaseTFPlayer *pOldOwner )
{
}
//-----------------------------------------------------------------------------
// Purpose: Check to see if there are any deteriorating objects I once owned that
// I can now re-own (i.e. I switched teams back to my original team).
// TODO: Make this use Steam IDs, so disconnecting & reconnecting players
// get their objects back.
//-----------------------------------------------------------------------------
void CPlayerClass::CheckDeterioratingObjects( void )
{
if ( !GetTeam() )
return;
// Cycle through the team's objects looking for any deteriorating objects once owned by me
for ( int i = 0; i < GetTeam()->GetNumObjects(); i++ )
{
CBaseObject *pObject = GetTeam()->GetObject(i);
if ( pObject->IsDeteriorating() && pObject->GetOriginalBuilder() == m_pPlayer )
{
// Can this class build this object?
if ( ClassCanBuild( GetTFClass(), pObject->GetType() ) )
{
// Give the object back to this player
pObject->SetBuilder( m_pPlayer );
m_pPlayer->AddObject( pObject );
}
}
}
}
//-----------------------------------------------------------------------------
// Purpose:
// Output : edict_t
//-----------------------------------------------------------------------------
CBaseEntity *CPlayerClass::SelectSpawnPoint( void )
{
return NULL;
}
//-----------------------------------------------------------------------------
// Purpose: Add a new weapon/tech association. Weapons that the player has the associated tech for
// will automatically be given out if the player has the tech.
//-----------------------------------------------------------------------------
void CPlayerClass::AddWeaponTechAssoc( char *pWeaponTech )
{
Assert( m_iNumWeaponTechAssociations < MAX_WEAPONS );
m_WeaponTechAssociations[m_iNumWeaponTechAssociations].pWeaponTech = pWeaponTech;
m_iNumWeaponTechAssociations++;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CPlayerClass::ClearAllWeaponTechAssoc( )
{
m_iNumWeaponTechAssociations = 0;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CTFTeam *CPlayerClass::GetTeam()
{
return (CTFTeam*)GetPlayer()->GetTeam();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CPlayerClass::ResetViewOffset( void )
{
if ( m_pPlayer )
{
m_pPlayer->SetViewOffset( PLAYERCLASS_VIEWOFFSET_STAND );
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -