// // Name: CC_SwitchToPhyscannon // Author: Hekar Khani // Description: Concommand. Switches between Physcannon and last weapon // Notes: // void CC_SwitchToPhyscannon( void ) { CBasePlayer *pPlayer = ToBasePlayer( UTIL_GetCommandClient() ); if ( pPlayer ) { CBaseCombatWeapon *pWeapon = pPlayer->GetActiveWeapon(); if ( pWeapon ) { // Tell the client to stop selecting weapons engine->ClientCommand( UTIL_GetCommandClient()->edict(), "cancelselect" ); const char *strWeaponName = pWeapon->GetName(); if ( !Q_stricmp( strWeaponName, "weapon_lf_combat_cannon" ) ) { pPlayer->SelectLastItem(); } else { pPlayer->SelectItem( "weapon_lf_combat_cannon" ); } } } }
//----------------------------------------------------------------------------- // Purpose: allows the crate to open up when hit by a crowbar //----------------------------------------------------------------------------- int CItem_AmmoCrate::OnTakeDamage( const CTakeDamageInfo &info ) { // if it's the player hitting us with a crowbar, open up CBasePlayer *player = ToBasePlayer(info.GetAttacker()); if (player) { CBaseCombatWeapon *weapon = player->GetActiveWeapon(); if (weapon && !stricmp(weapon->GetName(), "weapon_crowbar")) { // play the normal use sound player->EmitSound( "HL2Player.Use" ); // open the crate Use(info.GetAttacker(), info.GetAttacker(), USE_TOGGLE, 0.0f); } } // don't actually take any damage return 0; }
//----------------------------------------------------------------------------- // Purpose: Runs movement commands for the player // Input : *player - // *ucmd - // *moveHelper - // Output : void CPlayerMove::RunCommand //----------------------------------------------------------------------------- void CPlayerMove::RunCommand ( CBasePlayer *player, CUserCmd *ucmd, IMoveHelper *moveHelper ) { StartCommand( player, ucmd ); // Set globals appropriately gpGlobals->curtime = player->m_nTickBase * TICK_INTERVAL; gpGlobals->frametime = player->m_bGamePaused ? 0 : TICK_INTERVAL; if ( player->m_bGamePaused ) { // If no clipping and cheats enabled and noclipduring game enabled, then leave // forwardmove and angles stuff in usercmd if ( player->GetMoveType() == MOVETYPE_NOCLIP && sv_cheats->GetBool() && sv_noclipduringpause.GetBool() ) { gpGlobals->frametime = TICK_INTERVAL; } } /* // TODO: We can check whether the player is sending more commands than elapsed real time cmdtimeremaining -= ucmd->msec; if ( cmdtimeremaining < 0 ) { // return; } */ IGameSystem::FrameUpdatePrePlayerRunCommandAllSystems( player, ucmd ); // Do weapon selection if ( ucmd->weaponselect != 0 ) { CBaseCombatWeapon *weapon = dynamic_cast< CBaseCombatWeapon * >( CBaseEntity::Instance( ucmd->weaponselect ) ); if ( weapon ) { VPROF( "player->SelectItem()" ); player->SelectItem( weapon->GetName(), ucmd->weaponsubtype ); } } IServerVehicle *pVehicle = player->GetVehicle(); // Latch in impulse. if ( ucmd->impulse ) { // Discard impulse commands unless the vehicle allows them. // FIXME: UsingStandardWeapons seems like a bad filter for this. The flashlight is an impulse command, for example. if ( !pVehicle || player->UsingStandardWeaponsInVehicle() ) { player->m_nImpulse = ucmd->impulse; } } // Update player input button states VPROF_SCOPE_BEGIN( "player->UpdateButtonState" ); player->UpdateButtonState( ucmd->buttons ); VPROF_SCOPE_END(); CheckMovingGround( player, TICK_INTERVAL ); g_pMoveData->m_vecOldAngles = player->pl.v_angle; // Copy from command to player unless game .dll has set angle using fixangle if ( player->pl.fixangle == FIXANGLE_NONE ) { player->pl.v_angle = ucmd->viewangles; } else if( player->pl.fixangle == FIXANGLE_RELATIVE ) { player->pl.v_angle = ucmd->viewangles + player->pl.anglechange; } // Call standard client pre-think RunPreThink( player ); // Call Think if one is set RunThink( player, TICK_INTERVAL ); // Setup input. SetupMove( player, ucmd, moveHelper, g_pMoveData ); // Let the game do the movement. if ( !pVehicle ) { VPROF( "g_pGameMovement->ProcessMovement()" ); Assert( g_pGameMovement ); g_pGameMovement->ProcessMovement( player, g_pMoveData ); } else { VPROF( "pVehicle->ProcessMovement()" ); pVehicle->ProcessMovement( player, g_pMoveData ); } // Copy output FinishMove( player, ucmd, g_pMoveData ); // Let server invoke any needed impact functions VPROF_SCOPE_BEGIN( "moveHelper->ProcessImpacts" ); moveHelper->ProcessImpacts(); VPROF_SCOPE_END(); RunPostThink( player ); FinishCommand( player ); // Let time pass player->m_nTickBase++; }
//----------------------------------------------------------------------------- // Purpose: Runs movement commands for the player // Input : *player - // *ucmd - // *moveHelper - // Output : void CPlayerMove::RunCommand //----------------------------------------------------------------------------- void CPlayerMove::RunCommand ( CBasePlayer *player, CUserCmd *ucmd, IMoveHelper *moveHelper ) { const float playerCurTime = player->m_nTickBase * TICK_INTERVAL; const float playerFrameTime = player->m_bGamePaused ? 0 : TICK_INTERVAL; const float flTimeAllowedForProcessing = player->ConsumeMovementTimeForUserCmdProcessing( playerFrameTime ); if ( !player->IsBot() && ( flTimeAllowedForProcessing < playerFrameTime ) ) { // Make sure that the activity in command is erased because player cheated or dropped too many packets double dblWarningFrequencyThrottle = sv_maxusrcmdprocessticks_warning.GetFloat(); if ( dblWarningFrequencyThrottle >= 0 ) { static double s_dblLastWarningTime = 0; double dblTimeNow = Plat_FloatTime(); if ( !s_dblLastWarningTime || ( dblTimeNow - s_dblLastWarningTime >= dblWarningFrequencyThrottle ) ) { s_dblLastWarningTime = dblTimeNow; Warning( "sv_maxusrcmdprocessticks_warning at server tick %u: Ignored client %s usrcmd (%.6f < %.6f)!\n", gpGlobals->tickcount, player->GetPlayerName(), flTimeAllowedForProcessing, playerFrameTime ); } } return; // Don't process this command } StartCommand( player, ucmd ); // Set globals appropriately gpGlobals->curtime = playerCurTime; gpGlobals->frametime = playerFrameTime; // Prevent hacked clients from sending us invalid view angles to try to get leaf server code to crash if ( !ucmd->viewangles.IsValid() || !IsEntityQAngleReasonable(ucmd->viewangles) ) { ucmd->viewangles = vec3_angle; } // Add and subtract buttons we're forcing on the player ucmd->buttons |= player->m_afButtonForced; ucmd->buttons &= ~player->m_afButtonDisabled; if ( player->m_bGamePaused ) { // If no clipping and cheats enabled and noclipduring game enabled, then leave // forwardmove and angles stuff in usercmd if ( player->GetMoveType() == MOVETYPE_NOCLIP && sv_cheats->GetBool() && sv_noclipduringpause.GetBool() ) { gpGlobals->frametime = TICK_INTERVAL; } } /* // TODO: We can check whether the player is sending more commands than elapsed real time cmdtimeremaining -= ucmd->msec; if ( cmdtimeremaining < 0 ) { // return; } */ g_pGameMovement->StartTrackPredictionErrors( player ); CommentarySystem_PePlayerRunCommand( player, ucmd ); // Do weapon selection if ( ucmd->weaponselect != 0 ) { CBaseCombatWeapon *weapon = dynamic_cast< CBaseCombatWeapon * >( CBaseEntity::Instance( ucmd->weaponselect ) ); if ( weapon ) { VPROF( "player->SelectItem()" ); player->SelectItem( weapon->GetName(), ucmd->weaponsubtype ); } } IServerVehicle *pVehicle = player->GetVehicle(); // Latch in impulse. if ( ucmd->impulse ) { // Discard impulse commands unless the vehicle allows them. // FIXME: UsingStandardWeapons seems like a bad filter for this. The flashlight is an impulse command, for example. if ( !pVehicle || player->UsingStandardWeaponsInVehicle() ) { player->m_nImpulse = ucmd->impulse; } } // Update player input button states VPROF_SCOPE_BEGIN( "player->UpdateButtonState" ); player->UpdateButtonState( ucmd->buttons ); VPROF_SCOPE_END(); CheckMovingGround( player, TICK_INTERVAL ); g_pMoveData->m_vecOldAngles = player->pl.v_angle; // Copy from command to player unless game .dll has set angle using fixangle if ( player->pl.fixangle == FIXANGLE_NONE ) { player->pl.v_angle = ucmd->viewangles; } else if( player->pl.fixangle == FIXANGLE_RELATIVE ) { player->pl.v_angle = ucmd->viewangles + player->pl.anglechange; } // Call standard client pre-think RunPreThink( player ); // Call Think if one is set RunThink( player, TICK_INTERVAL ); // Setup input. SetupMove( player, ucmd, moveHelper, g_pMoveData ); // Let the game do the movement. if ( !pVehicle ) { VPROF( "g_pGameMovement->ProcessMovement()" ); Assert( g_pGameMovement ); g_pGameMovement->ProcessMovement( player, g_pMoveData ); } else { VPROF( "pVehicle->ProcessMovement()" ); pVehicle->ProcessMovement( player, g_pMoveData ); } // Copy output FinishMove( player, ucmd, g_pMoveData ); // If we have to restore the view angle then do so right now if ( !player->IsBot() && ( gpGlobals->tickcount - player->GetLockViewanglesTickNumber() < sv_maxusrcmdprocessticks_holdaim.GetInt() ) ) { player->pl.v_angle = player->GetLockViewanglesData(); } // Let server invoke any needed impact functions VPROF_SCOPE_BEGIN( "moveHelper->ProcessImpacts" ); moveHelper->ProcessImpacts(); VPROF_SCOPE_END(); RunPostThink( player ); g_pGameMovement->FinishTrackPredictionErrors( player ); FinishCommand( player ); // Let time pass if ( gpGlobals->frametime > 0 ) { player->m_nTickBase++; } }