//----------------------------------------------------------------------------- // Purpose: Figure out if I should be using an attached item rather than this vehicle itself. //----------------------------------------------------------------------------- bool CBaseTFVehicle::UseAttachedItem( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value ) { CBaseTFPlayer* pPlayer = dynamic_cast<CBaseTFPlayer*>(pActivator); if ( !pPlayer || !InSameTeam(pPlayer) ) return false; Vector vecPlayerOrigin = pPlayer->GetAbsOrigin(); int nBestBuildPoint = -1; float fBestDistance = FLT_MAX; // Get the closest regular entry point: int nRole = LocateEntryPoint( pPlayer, &fBestDistance ); // Iterate through each of the build points, if any, and see which we are closest to. int nBuildPoints = GetNumBuildPoints(); for( int i = 0; i < nBuildPoints; i++ ) { CBaseObject* pObject = GetBuildPointObject(i); // If there's something in the build point that isn't in the process of being built or placed: if( pObject && !pObject->IsPlacing() && !pObject->IsBuilding() ) { Vector vecOrigin; QAngle vecAngles; // If the build point is the default point for this role, just take it if (GetBuildPointPassenger(i) == nRole) { nBestBuildPoint = i; break; } // And I can get the build point. if( GetBuildPoint( i, vecOrigin, vecAngles ) ) { float fLength2dSqr = (vecOrigin - vecPlayerOrigin).AsVector2D().LengthSqr(); if( fLength2dSqr < fBestDistance ) { nBestBuildPoint = i; fBestDistance = fLength2dSqr; } } } } if( nBestBuildPoint >= 0 ) { // They're using an item on me, so push out the deterioration time ResetDeteriorationTime(); GetBuildPointObject(nBestBuildPoint)->Use( pActivator, pCaller, useType, value ); return true; } return false; }
//----------------------------------------------------------------------------- // Purpose: Handle commands sent from vgui panels on the client //----------------------------------------------------------------------------- bool CBaseTFVehicle::ClientCommand( CBaseTFPlayer *pPlayer, const CCommand &args ) { ResetDeteriorationTime(); if ( FStrEq( pCmd, "toggle_use" ) ) { AttemptToBoardVehicle( pPlayer ); return true; } return BaseClass::ClientCommand( pPlayer, args ); }
//----------------------------------------------------------------------------- // Purpose: Handle commands sent from vgui panels on the client //----------------------------------------------------------------------------- bool CBaseTFVehicle::ClientCommand( CBaseTFPlayer *pPlayer, const char *pCmd, ICommandArguments *pArg ) { ResetDeteriorationTime(); if ( FStrEq( pCmd, "toggle_use" ) ) { AttemptToBoardVehicle( pPlayer ); return true; } return BaseClass::ClientCommand( pPlayer, pCmd, pArg ); }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CBaseTFVehicle::VehiclePassengerThink( void ) { SetNextThink( gpGlobals->curtime + 10.0, PASSENGER_THINK_CONTEXT ); if ( IsPlacing() ) { ResetDeteriorationTime(); return; } // If there are any passengers in the vehicle, push off deterioration time if ( GetPassengerCount() ) { ResetDeteriorationTime(); return; } // See if there are any team members nearby if ( GetTeam() ) { int iNumPlayers = GetTFTeam()->GetNumPlayers(); for ( int i = 0; i < iNumPlayers; i++ ) { if ( GetTFTeam()->GetPlayer(i) ) { Vector vecOrigin = GetTFTeam()->GetPlayer(i)->GetAbsOrigin(); if ( (vecOrigin - GetAbsOrigin()).LengthSqr() < DETERIORATION_DISTANCE ) { // Found one nearby, reset our deterioration time ResetDeteriorationTime(); return; } } } } }
//----------------------------------------------------------------------------- // Purpose: Get and set the current driver. //----------------------------------------------------------------------------- void CBaseTFVehicle::SetPassenger( int nRole, CBasePlayer *pEnt ) { Assert( !pEnt || pEnt->IsPlayer() ); Assert( nRole >= 0 && nRole < m_nMaxPassengers ); Assert( !m_hPassengers[nRole].Get() || !pEnt ); m_hPassengers.Set( nRole, dynamic_cast<CBaseTFPlayer*>(pEnt) ); // If the vehicle's deteriorating, I get to own it now if ( IsDeteriorating() ) { StopDeteriorating(); SetBuilder( (CBaseTFPlayer*)pEnt, true ); } ResetDeteriorationTime(); }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CVehicleTeleportStation::DoTeleport( void ) { ResetDeteriorationTime(); if ( m_hTeleportExit ) { // Teleport all players attached to me that are within my bbox. EHANDLE hMCV; hMCV = this; m_hTeleportExit->DoTeleport( GetTFTeam(), m_hTeleportExit->GetAbsMins(), m_hTeleportExit->GetAbsMaxs(), m_vecTeleporterCenter, true, true, hMCV ); } // Shrink the corner sprites for ( int i = 0; i < 5; i++ ) { if ( m_hTeleportCornerSprites[i] ) { m_hTeleportCornerSprites[i]->SetScale( 0.1 ); } } SetContextThink( PostTeleportThink, gpGlobals->curtime + 0.1, TELEPORT_STATION_THINK_CONTEXT ); }
bool CVehicleMortar::ClientCommand( CBaseTFPlayer *pPlayer, const char *pCmd, ICommandArguments *pArg ) { ResetDeteriorationTime(); if ( !Q_stricmp( pCmd, "Deploy" ) ) { Deploy(); return true; } else if ( !Q_stricmp( pCmd, "Undeploy" ) ) { UnDeploy(); } else if ( !Q_stricmp( pCmd, "CancelDeploy" ) ) { CancelDeploy(); return true; } else if ( !Q_stricmp( pCmd, "FireMortar" ) ) { if ( pArg->Argc() == 3 ) { FireMortar( atof( pArg->Argv(1) ), atof( pArg->Argv(2) ), false, false ); } return true; } else if ( !Q_stricmp( pCmd, "MortarYaw" ) ) { if ( pArg->Argc() == 2 ) { m_flMortarYaw = atof( pArg->Argv(1) ); } return true; } return BaseClass::ClientCommand( pPlayer, pCmd, pArg ); }
//----------------------------------------------------------------------------- // Recharge think... //----------------------------------------------------------------------------- void CObjectMannedPlasmagun::RechargeThink( ) { // Prevent manned guns from deteriorating ResetDeteriorationTime(); float flNextRechargeTime = MANNED_PLASMAGUN_RECHARGE_TIME; /* ROBIN: Remove idle recharging for now if (gpGlobals->curtime >= m_flNextIdleTime) flNextRechargeTime = MANNED_PLASMAGUN_IDLE_RECHARGE_TIME; else flNextRechargeTime = MANNED_PLASMAGUN_RECHARGE_TIME; */ // If I'm EMPed, slow the recharge rate down if ( HasPowerup(POWERUP_EMP) ) { flNextRechargeTime *= 1.5; } SetNextThink( gpGlobals->curtime + flNextRechargeTime ); // I can't do anything if I'm not active if ( !ShouldBeActive() ) return; if (m_nAmmoCount < m_nMaxAmmoCount) { ++m_nAmmoCount; } else { // No need to think when it's full SetNextThink( gpGlobals->curtime + 5.0f ); } }