diff --git a/sp/src/game/client/hl2mp/c_hl2mp_player.cpp b/sp/src/game/client/hl2mp/c_hl2mp_player.cpp deleted file mode 100644 index 49e55e29..00000000 --- a/sp/src/game/client/hl2mp/c_hl2mp_player.cpp +++ /dev/null @@ -1,985 +0,0 @@ -//========= Copyright Valve Corporation, All rights reserved. ============// -// -// Purpose: Player for HL2. -// -//=============================================================================// - -#include "cbase.h" -#include "vcollide_parse.h" -#include "c_hl2mp_player.h" -#include "view.h" -#include "takedamageinfo.h" -#include "hl2mp_gamerules.h" -#include "in_buttons.h" -#include "iviewrender_beams.h" // flashlight beam -#include "r_efx.h" -#include "dlight.h" - -// Don't alias here -#if defined( CHL2MP_Player ) -#undef CHL2MP_Player -#endif - -LINK_ENTITY_TO_CLASS( player, C_HL2MP_Player ); - -IMPLEMENT_CLIENTCLASS_DT(C_HL2MP_Player, DT_HL2MP_Player, CHL2MP_Player) - RecvPropFloat( RECVINFO( m_angEyeAngles[0] ) ), - RecvPropFloat( RECVINFO( m_angEyeAngles[1] ) ), - RecvPropEHandle( RECVINFO( m_hRagdoll ) ), - RecvPropInt( RECVINFO( m_iSpawnInterpCounter ) ), - RecvPropInt( RECVINFO( m_iPlayerSoundType) ), - - RecvPropBool( RECVINFO( m_fIsWalking ) ), -END_RECV_TABLE() - -BEGIN_PREDICTION_DATA( C_HL2MP_Player ) - DEFINE_PRED_FIELD( m_fIsWalking, FIELD_BOOLEAN, FTYPEDESC_INSENDTABLE ), -END_PREDICTION_DATA() - -#define HL2_WALK_SPEED 150 -#define HL2_NORM_SPEED 190 -#define HL2_SPRINT_SPEED 320 - -static ConVar cl_playermodel( "cl_playermodel", "none", FCVAR_USERINFO | FCVAR_ARCHIVE | FCVAR_SERVER_CAN_EXECUTE, "Default Player Model"); -static ConVar cl_defaultweapon( "cl_defaultweapon", "weapon_physcannon", FCVAR_USERINFO | FCVAR_ARCHIVE, "Default Spawn Weapon"); - -void SpawnBlood (Vector vecSpot, const Vector &vecDir, int bloodColor, float flDamage); - -C_HL2MP_Player::C_HL2MP_Player() : m_PlayerAnimState( this ), m_iv_angEyeAngles( "C_HL2MP_Player::m_iv_angEyeAngles" ) -{ - m_iIDEntIndex = 0; - m_iSpawnInterpCounterCache = 0; - - m_angEyeAngles.Init(); - - AddVar( &m_angEyeAngles, &m_iv_angEyeAngles, LATCH_SIMULATION_VAR ); - - m_EntClientFlags |= ENTCLIENTFLAG_DONTUSEIK; - m_blinkTimer.Invalidate(); - - m_pFlashlightBeam = NULL; -} - -C_HL2MP_Player::~C_HL2MP_Player( void ) -{ - ReleaseFlashlight(); -} - -int C_HL2MP_Player::GetIDTarget() const -{ - return m_iIDEntIndex; -} - -//----------------------------------------------------------------------------- -// Purpose: Update this client's target entity -//----------------------------------------------------------------------------- -void C_HL2MP_Player::UpdateIDTarget() -{ - if ( !IsLocalPlayer() ) - return; - - // Clear old target and find a new one - m_iIDEntIndex = 0; - - // don't show IDs in chase spec mode - if ( GetObserverMode() == OBS_MODE_CHASE || - GetObserverMode() == OBS_MODE_DEATHCAM ) - return; - - trace_t tr; - Vector vecStart, vecEnd; - VectorMA( MainViewOrigin(), 1500, MainViewForward(), vecEnd ); - VectorMA( MainViewOrigin(), 10, MainViewForward(), vecStart ); - UTIL_TraceLine( vecStart, vecEnd, MASK_SOLID, this, COLLISION_GROUP_NONE, &tr ); - - if ( !tr.startsolid && tr.DidHitNonWorldEntity() ) - { - C_BaseEntity *pEntity = tr.m_pEnt; - - if ( pEntity && (pEntity != this) ) - { - m_iIDEntIndex = pEntity->entindex(); - } - } -} - -void C_HL2MP_Player::TraceAttack( const CTakeDamageInfo &info, const Vector &vecDir, trace_t *ptr, CDmgAccumulator *pAccumulator ) -{ - Vector vecOrigin = ptr->endpos - vecDir * 4; - - float flDistance = 0.0f; - - if ( info.GetAttacker() ) - { - flDistance = (ptr->endpos - info.GetAttacker()->GetAbsOrigin()).Length(); - } - - if ( m_takedamage ) - { - AddMultiDamage( info, this ); - - int blood = BloodColor(); - - CBaseEntity *pAttacker = info.GetAttacker(); - - if ( pAttacker ) - { - if ( HL2MPRules()->IsTeamplay() && pAttacker->InSameTeam( this ) == true ) - return; - } - - if ( blood != DONT_BLEED ) - { - SpawnBlood( vecOrigin, vecDir, blood, flDistance );// a little surface blood. - TraceBleed( flDistance, vecDir, ptr, info.GetDamageType() ); - } - } -} - - -C_HL2MP_Player* C_HL2MP_Player::GetLocalHL2MPPlayer() -{ - return (C_HL2MP_Player*)C_BasePlayer::GetLocalPlayer(); -} - -void C_HL2MP_Player::Initialize( void ) -{ - m_headYawPoseParam = LookupPoseParameter( "head_yaw" ); - GetPoseParameterRange( m_headYawPoseParam, m_headYawMin, m_headYawMax ); - - m_headPitchPoseParam = LookupPoseParameter( "head_pitch" ); - GetPoseParameterRange( m_headPitchPoseParam, m_headPitchMin, m_headPitchMax ); - - CStudioHdr *hdr = GetModelPtr(); - for ( int i = 0; i < hdr->GetNumPoseParameters() ; i++ ) - { - SetPoseParameter( hdr, i, 0.0 ); - } -} - -CStudioHdr *C_HL2MP_Player::OnNewModel( void ) -{ - CStudioHdr *hdr = BaseClass::OnNewModel(); - - Initialize( ); - - return hdr; -} - -//----------------------------------------------------------------------------- -/** - * Orient head and eyes towards m_lookAt. - */ -void C_HL2MP_Player::UpdateLookAt( void ) -{ - // head yaw - if (m_headYawPoseParam < 0 || m_headPitchPoseParam < 0) - return; - - // orient eyes - m_viewtarget = m_vLookAtTarget; - - // blinking - if (m_blinkTimer.IsElapsed()) - { - m_blinktoggle = !m_blinktoggle; - m_blinkTimer.Start( RandomFloat( 1.5f, 4.0f ) ); - } - - // Figure out where we want to look in world space. - QAngle desiredAngles; - Vector to = m_vLookAtTarget - EyePosition(); - VectorAngles( to, desiredAngles ); - - // Figure out where our body is facing in world space. - QAngle bodyAngles( 0, 0, 0 ); - bodyAngles[YAW] = GetLocalAngles()[YAW]; - - - float flBodyYawDiff = bodyAngles[YAW] - m_flLastBodyYaw; - m_flLastBodyYaw = bodyAngles[YAW]; - - - // Set the head's yaw. - float desired = AngleNormalize( desiredAngles[YAW] - bodyAngles[YAW] ); - desired = clamp( desired, m_headYawMin, m_headYawMax ); - m_flCurrentHeadYaw = ApproachAngle( desired, m_flCurrentHeadYaw, 130 * gpGlobals->frametime ); - - // Counterrotate the head from the body rotation so it doesn't rotate past its target. - m_flCurrentHeadYaw = AngleNormalize( m_flCurrentHeadYaw - flBodyYawDiff ); - desired = clamp( desired, m_headYawMin, m_headYawMax ); - - SetPoseParameter( m_headYawPoseParam, m_flCurrentHeadYaw ); - - - // Set the head's yaw. - desired = AngleNormalize( desiredAngles[PITCH] ); - desired = clamp( desired, m_headPitchMin, m_headPitchMax ); - - m_flCurrentHeadPitch = ApproachAngle( desired, m_flCurrentHeadPitch, 130 * gpGlobals->frametime ); - m_flCurrentHeadPitch = AngleNormalize( m_flCurrentHeadPitch ); - SetPoseParameter( m_headPitchPoseParam, m_flCurrentHeadPitch ); -} - -void C_HL2MP_Player::ClientThink( void ) -{ - bool bFoundViewTarget = false; - - Vector vForward; - AngleVectors( GetLocalAngles(), &vForward ); - - for( int iClient = 1; iClient <= gpGlobals->maxClients; ++iClient ) - { - CBaseEntity *pEnt = UTIL_PlayerByIndex( iClient ); - if(!pEnt || !pEnt->IsPlayer()) - continue; - - if ( pEnt->entindex() == entindex() ) - continue; - - Vector vTargetOrigin = pEnt->GetAbsOrigin(); - Vector vMyOrigin = GetAbsOrigin(); - - Vector vDir = vTargetOrigin - vMyOrigin; - - if ( vDir.Length() > 128 ) - continue; - - VectorNormalize( vDir ); - - if ( DotProduct( vForward, vDir ) < 0.0f ) - continue; - - m_vLookAtTarget = pEnt->EyePosition(); - bFoundViewTarget = true; - break; - } - - if ( bFoundViewTarget == false ) - { - m_vLookAtTarget = GetAbsOrigin() + vForward * 512; - } - - UpdateIDTarget(); -} - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -int C_HL2MP_Player::DrawModel( int flags ) -{ - if ( !m_bReadyToDraw ) - return 0; - - return BaseClass::DrawModel(flags); -} - -//----------------------------------------------------------------------------- -// Should this object receive shadows? -//----------------------------------------------------------------------------- -bool C_HL2MP_Player::ShouldReceiveProjectedTextures( int flags ) -{ - Assert( flags & SHADOW_FLAGS_PROJECTED_TEXTURE_TYPE_MASK ); - - if ( IsEffectActive( EF_NODRAW ) ) - return false; - - if( flags & SHADOW_FLAGS_FLASHLIGHT ) - { - return true; - } - - return BaseClass::ShouldReceiveProjectedTextures( flags ); -} - -void C_HL2MP_Player::DoImpactEffect( trace_t &tr, int nDamageType ) -{ - if ( GetActiveWeapon() ) - { - GetActiveWeapon()->DoImpactEffect( tr, nDamageType ); - return; - } - - BaseClass::DoImpactEffect( tr, nDamageType ); -} - -void C_HL2MP_Player::PreThink( void ) -{ - QAngle vTempAngles = GetLocalAngles(); - - if ( GetLocalPlayer() == this ) - { - vTempAngles[PITCH] = EyeAngles()[PITCH]; - } - else - { - vTempAngles[PITCH] = m_angEyeAngles[PITCH]; - } - - if ( vTempAngles[YAW] < 0.0f ) - { - vTempAngles[YAW] += 360.0f; - } - - SetLocalAngles( vTempAngles ); - - BaseClass::PreThink(); - - HandleSpeedChanges(); - - if ( m_HL2Local.m_flSuitPower <= 0.0f ) - { - if( IsSprinting() ) - { - StopSprinting(); - } - } -} - -const QAngle &C_HL2MP_Player::EyeAngles() -{ - if( IsLocalPlayer() ) - { - return BaseClass::EyeAngles(); - } - else - { - return m_angEyeAngles; - } -} - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void C_HL2MP_Player::AddEntity( void ) -{ - BaseClass::AddEntity(); - - QAngle vTempAngles = GetLocalAngles(); - vTempAngles[PITCH] = m_angEyeAngles[PITCH]; - - SetLocalAngles( vTempAngles ); - - m_PlayerAnimState.Update(); - - // Zero out model pitch, blending takes care of all of it. - SetLocalAnglesDim( X_INDEX, 0 ); - - if( this != C_BasePlayer::GetLocalPlayer() ) - { - if ( IsEffectActive( EF_DIMLIGHT ) ) - { - int iAttachment = LookupAttachment( "anim_attachment_RH" ); - - if ( iAttachment < 0 ) - return; - - Vector vecOrigin; - QAngle eyeAngles = m_angEyeAngles; - - GetAttachment( iAttachment, vecOrigin, eyeAngles ); - - Vector vForward; - AngleVectors( eyeAngles, &vForward ); - - trace_t tr; - UTIL_TraceLine( vecOrigin, vecOrigin + (vForward * 200), MASK_SHOT, this, COLLISION_GROUP_NONE, &tr ); - - if( !m_pFlashlightBeam ) - { - BeamInfo_t beamInfo; - beamInfo.m_nType = TE_BEAMPOINTS; - beamInfo.m_vecStart = tr.startpos; - beamInfo.m_vecEnd = tr.endpos; - beamInfo.m_pszModelName = "sprites/glow01.vmt"; - beamInfo.m_pszHaloName = "sprites/glow01.vmt"; - beamInfo.m_flHaloScale = 3.0; - beamInfo.m_flWidth = 8.0f; - beamInfo.m_flEndWidth = 35.0f; - beamInfo.m_flFadeLength = 300.0f; - beamInfo.m_flAmplitude = 0; - beamInfo.m_flBrightness = 60.0; - beamInfo.m_flSpeed = 0.0f; - beamInfo.m_nStartFrame = 0.0; - beamInfo.m_flFrameRate = 0.0; - beamInfo.m_flRed = 255.0; - beamInfo.m_flGreen = 255.0; - beamInfo.m_flBlue = 255.0; - beamInfo.m_nSegments = 8; - beamInfo.m_bRenderable = true; - beamInfo.m_flLife = 0.5; - beamInfo.m_nFlags = FBEAM_FOREVER | FBEAM_ONLYNOISEONCE | FBEAM_NOTILE | FBEAM_HALOBEAM; - - m_pFlashlightBeam = beams->CreateBeamPoints( beamInfo ); - } - - if( m_pFlashlightBeam ) - { - BeamInfo_t beamInfo; - beamInfo.m_vecStart = tr.startpos; - beamInfo.m_vecEnd = tr.endpos; - beamInfo.m_flRed = 255.0; - beamInfo.m_flGreen = 255.0; - beamInfo.m_flBlue = 255.0; - - beams->UpdateBeamInfo( m_pFlashlightBeam, beamInfo ); - - dlight_t *el = effects->CL_AllocDlight( 0 ); - el->origin = tr.endpos; - el->radius = 50; - el->color.r = 200; - el->color.g = 200; - el->color.b = 200; - el->die = gpGlobals->curtime + 0.1; - } - } - else if ( m_pFlashlightBeam ) - { - ReleaseFlashlight(); - } - } -} - -ShadowType_t C_HL2MP_Player::ShadowCastType( void ) -{ - if ( !IsVisible() ) - return SHADOWS_NONE; - - return SHADOWS_RENDER_TO_TEXTURE_DYNAMIC; -} - - -const QAngle& C_HL2MP_Player::GetRenderAngles() -{ - if ( IsRagdoll() ) - { - return vec3_angle; - } - else - { - return m_PlayerAnimState.GetRenderAngles(); - } -} - -bool C_HL2MP_Player::ShouldDraw( void ) -{ - // If we're dead, our ragdoll will be drawn for us instead. - if ( !IsAlive() ) - return false; - -// if( GetTeamNumber() == TEAM_SPECTATOR ) -// return false; - - if( IsLocalPlayer() && IsRagdoll() ) - return true; - - if ( IsRagdoll() ) - return false; - - return BaseClass::ShouldDraw(); -} - -void C_HL2MP_Player::NotifyShouldTransmit( ShouldTransmitState_t state ) -{ - if ( state == SHOULDTRANSMIT_END ) - { - if( m_pFlashlightBeam != NULL ) - { - ReleaseFlashlight(); - } - } - - BaseClass::NotifyShouldTransmit( state ); -} - -void C_HL2MP_Player::OnDataChanged( DataUpdateType_t type ) -{ - BaseClass::OnDataChanged( type ); - - if ( type == DATA_UPDATE_CREATED ) - { - SetNextClientThink( CLIENT_THINK_ALWAYS ); - } - - UpdateVisibility(); -} - -void C_HL2MP_Player::PostDataUpdate( DataUpdateType_t updateType ) -{ - if ( m_iSpawnInterpCounter != m_iSpawnInterpCounterCache ) - { - MoveToLastReceivedPosition( true ); - ResetLatched(); - m_iSpawnInterpCounterCache = m_iSpawnInterpCounter; - } - - BaseClass::PostDataUpdate( updateType ); -} - -void C_HL2MP_Player::ReleaseFlashlight( void ) -{ - if( m_pFlashlightBeam ) - { - m_pFlashlightBeam->flags = 0; - m_pFlashlightBeam->die = gpGlobals->curtime - 1; - - m_pFlashlightBeam = NULL; - } -} - -float C_HL2MP_Player::GetFOV( void ) -{ - //Find our FOV with offset zoom value - float flFOVOffset = C_BasePlayer::GetFOV() + GetZoom(); - - // Clamp FOV in MP - int min_fov = GetMinFOV(); - - // Don't let it go too low - flFOVOffset = MAX( min_fov, flFOVOffset ); - - return flFOVOffset; -} - -//========================================================= -// Autoaim -// set crosshair position to point to enemey -//========================================================= -Vector C_HL2MP_Player::GetAutoaimVector( float flDelta ) -{ - // Never autoaim a predicted weapon (for now) - Vector forward; - AngleVectors( EyeAngles() + m_Local.m_vecPunchAngle, &forward ); - return forward; -} - -//----------------------------------------------------------------------------- -// Purpose: Returns whether or not we are allowed to sprint now. -//----------------------------------------------------------------------------- -bool C_HL2MP_Player::CanSprint( void ) -{ - return ( (!m_Local.m_bDucked && !m_Local.m_bDucking) && (GetWaterLevel() != 3) ); -} - - -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -void C_HL2MP_Player::StartSprinting( void ) -{ - if( m_HL2Local.m_flSuitPower < 10 ) - { - // Don't sprint unless there's a reasonable - // amount of suit power. - CPASAttenuationFilter filter( this ); - filter.UsePredictionRules(); - EmitSound( filter, entindex(), "HL2Player.SprintNoPower" ); - return; - } - - CPASAttenuationFilter filter( this ); - filter.UsePredictionRules(); - EmitSound( filter, entindex(), "HL2Player.SprintStart" ); - - SetMaxSpeed( HL2_SPRINT_SPEED ); - m_fIsSprinting = true; -} - - -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -void C_HL2MP_Player::StopSprinting( void ) -{ - SetMaxSpeed( HL2_NORM_SPEED ); - m_fIsSprinting = false; -} - -void C_HL2MP_Player::HandleSpeedChanges( void ) -{ - int buttonsChanged = m_afButtonPressed | m_afButtonReleased; - - if( buttonsChanged & IN_SPEED ) - { - // The state of the sprint/run button has changed. - if ( IsSuitEquipped() ) - { - if ( !(m_afButtonPressed & IN_SPEED) && IsSprinting() ) - { - StopSprinting(); - } - else if ( (m_afButtonPressed & IN_SPEED) && !IsSprinting() ) - { - if ( CanSprint() ) - { - StartSprinting(); - } - else - { - // Reset key, so it will be activated post whatever is suppressing it. - m_nButtons &= ~IN_SPEED; - } - } - } - } - else if( buttonsChanged & IN_WALK ) - { - if ( IsSuitEquipped() ) - { - // The state of the WALK button has changed. - if( IsWalking() && !(m_afButtonPressed & IN_WALK) ) - { - StopWalking(); - } - else if( !IsWalking() && !IsSprinting() && (m_afButtonPressed & IN_WALK) && !(m_nButtons & IN_DUCK) ) - { - StartWalking(); - } - } - } - - if ( IsSuitEquipped() && m_fIsWalking && !(m_nButtons & IN_WALK) ) - StopWalking(); -} - -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -void C_HL2MP_Player::StartWalking( void ) -{ - SetMaxSpeed( HL2_WALK_SPEED ); - m_fIsWalking = true; -} - -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -void C_HL2MP_Player::StopWalking( void ) -{ - SetMaxSpeed( HL2_NORM_SPEED ); - m_fIsWalking = false; -} - -void C_HL2MP_Player::ItemPreFrame( void ) -{ - if ( GetFlags() & FL_FROZEN ) - return; - - // Disallow shooting while zooming - if ( m_nButtons & IN_ZOOM ) - { - //FIXME: Held weapons like the grenade get sad when this happens - m_nButtons &= ~(IN_ATTACK|IN_ATTACK2); - } - - BaseClass::ItemPreFrame(); - -} - -void C_HL2MP_Player::ItemPostFrame( void ) -{ - if ( GetFlags() & FL_FROZEN ) - return; - - BaseClass::ItemPostFrame(); -} - -C_BaseAnimating *C_HL2MP_Player::BecomeRagdollOnClient() -{ - // Let the C_CSRagdoll entity do this. - // m_builtRagdoll = true; - return NULL; -} - -void C_HL2MP_Player::CalcView( Vector &eyeOrigin, QAngle &eyeAngles, float &zNear, float &zFar, float &fov ) -{ - if ( m_lifeState != LIFE_ALIVE && !IsObserver() ) - { - Vector origin = EyePosition(); - - IRagdoll *pRagdoll = GetRepresentativeRagdoll(); - - if ( pRagdoll ) - { - origin = pRagdoll->GetRagdollOrigin(); - origin.z += VEC_DEAD_VIEWHEIGHT_SCALED( this ).z; // look over ragdoll, not through - } - - BaseClass::CalcView( eyeOrigin, eyeAngles, zNear, zFar, fov ); - - eyeOrigin = origin; - - Vector vForward; - AngleVectors( eyeAngles, &vForward ); - - VectorNormalize( vForward ); - VectorMA( origin, -CHASE_CAM_DISTANCE_MAX, vForward, eyeOrigin ); - - Vector WALL_MIN( -WALL_OFFSET, -WALL_OFFSET, -WALL_OFFSET ); - Vector WALL_MAX( WALL_OFFSET, WALL_OFFSET, WALL_OFFSET ); - - trace_t trace; // clip against world - C_BaseEntity::PushEnableAbsRecomputations( false ); // HACK don't recompute positions while doing RayTrace - UTIL_TraceHull( origin, eyeOrigin, WALL_MIN, WALL_MAX, MASK_SOLID_BRUSHONLY, this, COLLISION_GROUP_NONE, &trace ); - C_BaseEntity::PopEnableAbsRecomputations(); - - if (trace.fraction < 1.0) - { - eyeOrigin = trace.endpos; - } - - return; - } - - BaseClass::CalcView( eyeOrigin, eyeAngles, zNear, zFar, fov ); -} - -IRagdoll* C_HL2MP_Player::GetRepresentativeRagdoll() const -{ - if ( m_hRagdoll.Get() ) - { - C_HL2MPRagdoll *pRagdoll = (C_HL2MPRagdoll*)m_hRagdoll.Get(); - - return pRagdoll->GetIRagdoll(); - } - else - { - return NULL; - } -} - -//HL2MPRAGDOLL - - -IMPLEMENT_CLIENTCLASS_DT_NOBASE( C_HL2MPRagdoll, DT_HL2MPRagdoll, CHL2MPRagdoll ) - RecvPropVector( RECVINFO(m_vecRagdollOrigin) ), - RecvPropEHandle( RECVINFO( m_hPlayer ) ), - RecvPropInt( RECVINFO( m_nModelIndex ) ), - RecvPropInt( RECVINFO(m_nForceBone) ), - RecvPropVector( RECVINFO(m_vecForce) ), - RecvPropVector( RECVINFO( m_vecRagdollVelocity ) ) -END_RECV_TABLE() - - - -C_HL2MPRagdoll::C_HL2MPRagdoll() -{ - -} - -C_HL2MPRagdoll::~C_HL2MPRagdoll() -{ - PhysCleanupFrictionSounds( this ); - - if ( m_hPlayer ) - { - m_hPlayer->CreateModelInstance(); - } -} - -void C_HL2MPRagdoll::Interp_Copy( C_BaseAnimatingOverlay *pSourceEntity ) -{ - if ( !pSourceEntity ) - return; - - VarMapping_t *pSrc = pSourceEntity->GetVarMapping(); - VarMapping_t *pDest = GetVarMapping(); - - // Find all the VarMapEntry_t's that represent the same variable. - for ( int i = 0; i < pDest->m_Entries.Count(); i++ ) - { - VarMapEntry_t *pDestEntry = &pDest->m_Entries[i]; - const char *pszName = pDestEntry->watcher->GetDebugName(); - for ( int j=0; j < pSrc->m_Entries.Count(); j++ ) - { - VarMapEntry_t *pSrcEntry = &pSrc->m_Entries[j]; - if ( !Q_strcmp( pSrcEntry->watcher->GetDebugName(), pszName ) ) - { - pDestEntry->watcher->Copy( pSrcEntry->watcher ); - break; - } - } - } -} - -void C_HL2MPRagdoll::ImpactTrace( trace_t *pTrace, int iDamageType, const char *pCustomImpactName ) -{ - IPhysicsObject *pPhysicsObject = VPhysicsGetObject(); - - if( !pPhysicsObject ) - return; - - Vector dir = pTrace->endpos - pTrace->startpos; - - if ( iDamageType == DMG_BLAST ) - { - dir *= 4000; // adjust impact strenght - - // apply force at object mass center - pPhysicsObject->ApplyForceCenter( dir ); - } - else - { - Vector hitpos; - - VectorMA( pTrace->startpos, pTrace->fraction, dir, hitpos ); - VectorNormalize( dir ); - - dir *= 4000; // adjust impact strenght - - // apply force where we hit it - pPhysicsObject->ApplyForceOffset( dir, hitpos ); - - // Blood spray! -// FX_CS_BloodSpray( hitpos, dir, 10 ); - } - - m_pRagdoll->ResetRagdollSleepAfterTime(); -} - - -void C_HL2MPRagdoll::CreateHL2MPRagdoll( void ) -{ - // First, initialize all our data. If we have the player's entity on our client, - // then we can make ourselves start out exactly where the player is. - C_HL2MP_Player *pPlayer = dynamic_cast< C_HL2MP_Player* >( m_hPlayer.Get() ); - - if ( pPlayer && !pPlayer->IsDormant() ) - { - // move my current model instance to the ragdoll's so decals are preserved. - pPlayer->SnatchModelInstance( this ); - - VarMapping_t *varMap = GetVarMapping(); - - // Copy all the interpolated vars from the player entity. - // The entity uses the interpolated history to get bone velocity. - bool bRemotePlayer = (pPlayer != C_BasePlayer::GetLocalPlayer()); - if ( bRemotePlayer ) - { - Interp_Copy( pPlayer ); - - SetAbsAngles( pPlayer->GetRenderAngles() ); - GetRotationInterpolator().Reset(); - - m_flAnimTime = pPlayer->m_flAnimTime; - SetSequence( pPlayer->GetSequence() ); - m_flPlaybackRate = pPlayer->GetPlaybackRate(); - } - else - { - // This is the local player, so set them in a default - // pose and slam their velocity, angles and origin - SetAbsOrigin( m_vecRagdollOrigin ); - - SetAbsAngles( pPlayer->GetRenderAngles() ); - - SetAbsVelocity( m_vecRagdollVelocity ); - - int iSeq = pPlayer->GetSequence(); - if ( iSeq == -1 ) - { - Assert( false ); // missing walk_lower? - iSeq = 0; - } - - SetSequence( iSeq ); // walk_lower, basic pose - SetCycle( 0.0 ); - - Interp_Reset( varMap ); - } - } - else - { - // overwrite network origin so later interpolation will - // use this position - SetNetworkOrigin( m_vecRagdollOrigin ); - - SetAbsOrigin( m_vecRagdollOrigin ); - SetAbsVelocity( m_vecRagdollVelocity ); - - Interp_Reset( GetVarMapping() ); - - } - - SetModelIndex( m_nModelIndex ); - - // Make us a ragdoll.. - m_nRenderFX = kRenderFxRagdoll; - - matrix3x4_t boneDelta0[MAXSTUDIOBONES]; - matrix3x4_t boneDelta1[MAXSTUDIOBONES]; - matrix3x4_t currentBones[MAXSTUDIOBONES]; - const float boneDt = 0.05f; - - if ( pPlayer && !pPlayer->IsDormant() ) - { - pPlayer->GetRagdollInitBoneArrays( boneDelta0, boneDelta1, currentBones, boneDt ); - } - else - { - GetRagdollInitBoneArrays( boneDelta0, boneDelta1, currentBones, boneDt ); - } - - InitAsClientRagdoll( boneDelta0, boneDelta1, currentBones, boneDt ); -} - - -void C_HL2MPRagdoll::OnDataChanged( DataUpdateType_t type ) -{ - BaseClass::OnDataChanged( type ); - - if ( type == DATA_UPDATE_CREATED ) - { - CreateHL2MPRagdoll(); - } -} - -IRagdoll* C_HL2MPRagdoll::GetIRagdoll() const -{ - return m_pRagdoll; -} - -void C_HL2MPRagdoll::UpdateOnRemove( void ) -{ - VPhysicsSetObject( NULL ); - - BaseClass::UpdateOnRemove(); -} - -//----------------------------------------------------------------------------- -// Purpose: clear out any face/eye values stored in the material system -//----------------------------------------------------------------------------- -void C_HL2MPRagdoll::SetupWeights( const matrix3x4_t *pBoneToWorld, int nFlexWeightCount, float *pFlexWeights, float *pFlexDelayedWeights ) -{ - BaseClass::SetupWeights( pBoneToWorld, nFlexWeightCount, pFlexWeights, pFlexDelayedWeights ); - - static float destweight[128]; - static bool bIsInited = false; - - CStudioHdr *hdr = GetModelPtr(); - if ( !hdr ) - return; - - int nFlexDescCount = hdr->numflexdesc(); - if ( nFlexDescCount ) - { - Assert( !pFlexDelayedWeights ); - memset( pFlexWeights, 0, nFlexWeightCount * sizeof(float) ); - } - - if ( m_iEyeAttachment > 0 ) - { - matrix3x4_t attToWorld; - if (GetAttachment( m_iEyeAttachment, attToWorld )) - { - Vector local, tmp; - local.Init( 1000.0f, 0.0f, 0.0f ); - VectorTransform( local, attToWorld, tmp ); - modelrender->SetViewTarget( GetModelPtr(), GetBody(), tmp ); - } - } -} - -void C_HL2MP_Player::PostThink( void ) -{ - BaseClass::PostThink(); - - // Store the eye angles pitch so the client can compute its animation state correctly. - m_angEyeAngles = EyeAngles(); -} \ No newline at end of file diff --git a/sp/src/game/client/hl2mp/c_hl2mp_player.h b/sp/src/game/client/hl2mp/c_hl2mp_player.h deleted file mode 100644 index bac41977..00000000 --- a/sp/src/game/client/hl2mp/c_hl2mp_player.h +++ /dev/null @@ -1,173 +0,0 @@ -//========= Copyright Valve Corporation, All rights reserved. ============// -// -// Purpose: -// -// $NoKeywords: $ -// -//=============================================================================// -#ifndef HL2MP_PLAYER_H -#define HL2MP_PLAYER_H -#pragma once - -class C_HL2MP_Player; -#include "c_basehlplayer.h" -#include "hl2mp_player_shared.h" -#include "beamdraw.h" - -//============================================================================= -// >> HL2MP_Player -//============================================================================= -class C_HL2MP_Player : public C_BaseHLPlayer -{ -public: - DECLARE_CLASS( C_HL2MP_Player, C_BaseHLPlayer ); - - DECLARE_CLIENTCLASS(); - DECLARE_PREDICTABLE(); - DECLARE_INTERPOLATION(); - - - C_HL2MP_Player(); - ~C_HL2MP_Player( void ); - - void ClientThink( void ); - - static C_HL2MP_Player* GetLocalHL2MPPlayer(); - - virtual int DrawModel( int flags ); - virtual void AddEntity( void ); - - QAngle GetAnimEyeAngles( void ) { return m_angEyeAngles; } - Vector GetAttackSpread( CBaseCombatWeapon *pWeapon, CBaseEntity *pTarget = NULL ); - - - // Should this object cast shadows? - virtual ShadowType_t ShadowCastType( void ); - virtual C_BaseAnimating *BecomeRagdollOnClient(); - virtual const QAngle& GetRenderAngles(); - virtual bool ShouldDraw( void ); - virtual void OnDataChanged( DataUpdateType_t type ); - virtual float GetFOV( void ); - virtual CStudioHdr *OnNewModel( void ); - virtual void TraceAttack( const CTakeDamageInfo &info, const Vector &vecDir, trace_t *ptr, CDmgAccumulator *pAccumulator ); - virtual void ItemPreFrame( void ); - virtual void ItemPostFrame( void ); - virtual float GetMinFOV() const { return 5.0f; } - virtual Vector GetAutoaimVector( float flDelta ); - virtual void NotifyShouldTransmit( ShouldTransmitState_t state ); - virtual void CreateLightEffects( void ) {} - virtual bool ShouldReceiveProjectedTextures( int flags ); - virtual void PostDataUpdate( DataUpdateType_t updateType ); - virtual void PlayStepSound( Vector &vecOrigin, surfacedata_t *psurface, float fvol, bool force ); - virtual void PreThink( void ); - virtual void DoImpactEffect( trace_t &tr, int nDamageType ); - IRagdoll* GetRepresentativeRagdoll() const; - virtual void CalcView( Vector &eyeOrigin, QAngle &eyeAngles, float &zNear, float &zFar, float &fov ); - virtual const QAngle& EyeAngles( void ); - - - bool CanSprint( void ); - void StartSprinting( void ); - void StopSprinting( void ); - void HandleSpeedChanges( void ); - void UpdateLookAt( void ); - void Initialize( void ); - int GetIDTarget() const; - void UpdateIDTarget( void ); - void PrecacheFootStepSounds( void ); - const char *GetPlayerModelSoundPrefix( void ); - - HL2MPPlayerState State_Get() const; - - // Walking - void StartWalking( void ); - void StopWalking( void ); - bool IsWalking( void ) { return m_fIsWalking; } - - virtual void PostThink( void ); - -private: - - C_HL2MP_Player( const C_HL2MP_Player & ); - - CPlayerAnimState m_PlayerAnimState; - - QAngle m_angEyeAngles; - - CInterpolatedVar< QAngle > m_iv_angEyeAngles; - - EHANDLE m_hRagdoll; - - int m_headYawPoseParam; - int m_headPitchPoseParam; - float m_headYawMin; - float m_headYawMax; - float m_headPitchMin; - float m_headPitchMax; - - bool m_isInit; - Vector m_vLookAtTarget; - - float m_flLastBodyYaw; - float m_flCurrentHeadYaw; - float m_flCurrentHeadPitch; - - int m_iIDEntIndex; - - CountdownTimer m_blinkTimer; - - int m_iSpawnInterpCounter; - int m_iSpawnInterpCounterCache; - - int m_iPlayerSoundType; - - void ReleaseFlashlight( void ); - Beam_t *m_pFlashlightBeam; - - CNetworkVar( HL2MPPlayerState, m_iPlayerState ); - - bool m_fIsWalking; -}; - -inline C_HL2MP_Player *ToHL2MPPlayer( CBaseEntity *pEntity ) -{ - if ( !pEntity || !pEntity->IsPlayer() ) - return NULL; - - return dynamic_cast( pEntity ); -} - - -class C_HL2MPRagdoll : public C_BaseAnimatingOverlay -{ -public: - DECLARE_CLASS( C_HL2MPRagdoll, C_BaseAnimatingOverlay ); - DECLARE_CLIENTCLASS(); - - C_HL2MPRagdoll(); - ~C_HL2MPRagdoll(); - - virtual void OnDataChanged( DataUpdateType_t type ); - - int GetPlayerEntIndex() const; - IRagdoll* GetIRagdoll() const; - - void ImpactTrace( trace_t *pTrace, int iDamageType, const char *pCustomImpactName ); - void UpdateOnRemove( void ); - virtual void SetupWeights( const matrix3x4_t *pBoneToWorld, int nFlexWeightCount, float *pFlexWeights, float *pFlexDelayedWeights ); - -private: - - C_HL2MPRagdoll( const C_HL2MPRagdoll & ) {} - - void Interp_Copy( C_BaseAnimatingOverlay *pDestinationEntity ); - void CreateHL2MPRagdoll( void ); - -private: - - EHANDLE m_hPlayer; - CNetworkVector( m_vecRagdollVelocity ); - CNetworkVector( m_vecRagdollOrigin ); -}; - -#endif //HL2MP_PLAYER_H diff --git a/sp/src/game/client/hl2mp/c_te_hl2mp_shotgun_shot.cpp b/sp/src/game/client/hl2mp/c_te_hl2mp_shotgun_shot.cpp deleted file mode 100644 index 4283c3b0..00000000 --- a/sp/src/game/client/hl2mp/c_te_hl2mp_shotgun_shot.cpp +++ /dev/null @@ -1,160 +0,0 @@ -//========= Copyright Valve Corporation, All rights reserved. ============// -// -// Purpose: -// -//=============================================================================// - -#include "cbase.h" -#include "c_basetempentity.h" -#include -#include "ammodef.h" -#include "c_te_effect_dispatch.h" -#include "shot_manipulator.h" - -class C_TEHL2MPFireBullets : public C_BaseTempEntity -{ -public: - DECLARE_CLASS( C_TEHL2MPFireBullets, C_BaseTempEntity ); - DECLARE_CLIENTCLASS(); - - virtual void PostDataUpdate( DataUpdateType_t updateType ); - - void CreateEffects( void ); - -public: - int m_iPlayer; - Vector m_vecOrigin; - Vector m_vecDir; - int m_iAmmoID; - int m_iWeaponIndex; - int m_iSeed; - float m_flSpread; - int m_iShots; - bool m_bDoImpacts; - bool m_bDoTracers; -}; - -class CTraceFilterSkipPlayerAndViewModelOnly : public CTraceFilter -{ -public: - virtual bool ShouldHitEntity( IHandleEntity *pServerEntity, int contentsMask ) - { - C_BaseEntity *pEntity = EntityFromEntityHandle( pServerEntity ); - if( pEntity && - ( ( dynamic_cast( pEntity ) != NULL ) || - ( dynamic_cast( pEntity ) != NULL ) ) ) - { - return false; - } - else - { - return true; - } - } -}; - -void C_TEHL2MPFireBullets::CreateEffects( void ) -{ - CAmmoDef* pAmmoDef = GetAmmoDef(); - - if ( pAmmoDef == NULL ) - return; - - C_BaseEntity *pEnt = ClientEntityList().GetEnt( m_iPlayer ); - - if ( pEnt ) - { - C_BasePlayer *pPlayer = dynamic_cast(pEnt); - - if ( pPlayer && pPlayer->GetActiveWeapon() ) - { - C_BaseCombatWeapon *pWpn = dynamic_cast( pPlayer->GetActiveWeapon() ); - - if ( pWpn ) - { - int iSeed = m_iSeed; - - CShotManipulator Manipulator( m_vecDir ); - - for (int iShot = 0; iShot < m_iShots; iShot++) - { - RandomSeed( iSeed ); // init random system with this seed - - // Don't run the biasing code for the player at the moment. - Vector vecDir = Manipulator.ApplySpread( Vector( m_flSpread, m_flSpread, m_flSpread ) ); - Vector vecEnd = m_vecOrigin + vecDir * MAX_TRACE_LENGTH; - trace_t tr; - CTraceFilterSkipPlayerAndViewModelOnly traceFilter; - - if( m_iShots > 1 && iShot % 2 ) - { - // Half of the shotgun pellets are hulls that make it easier to hit targets with the shotgun. - UTIL_TraceHull( m_vecOrigin, vecEnd, Vector( -3, -3, -3 ), Vector( 3, 3, 3 ), MASK_SHOT, &traceFilter, &tr ); - } - else - { - UTIL_TraceLine( m_vecOrigin, vecEnd, MASK_SHOT, &traceFilter, &tr); - } - - if ( m_bDoTracers ) - { - const char *pTracerName = pWpn->GetTracerType(); - - CEffectData data; - data.m_vStart = tr.startpos; - data.m_vOrigin = tr.endpos; - data.m_hEntity = pWpn->GetRefEHandle(); - data.m_flScale = 0.0f; - data.m_fFlags |= TRACER_FLAG_USEATTACHMENT; - // Stomp the start, since it's not going to be used anyway - data.m_nAttachmentIndex = 1; - - if ( pTracerName ) - { - DispatchEffect( pTracerName, data ); - } - else - { - DispatchEffect( "Tracer", data ); - } - } - - if ( m_bDoImpacts ) - { - pWpn->DoImpactEffect( tr, pAmmoDef->DamageType( m_iAmmoID ) ); - } - - iSeed++; - } - } - } - } - -} - -void C_TEHL2MPFireBullets::PostDataUpdate( DataUpdateType_t updateType ) -{ - if ( m_bDoTracers || m_bDoImpacts ) - { - CreateEffects(); - } -} - - -IMPLEMENT_CLIENTCLASS_EVENT( C_TEHL2MPFireBullets, DT_TEHL2MPFireBullets, CTEHL2MPFireBullets ); - - -BEGIN_RECV_TABLE_NOBASE(C_TEHL2MPFireBullets, DT_TEHL2MPFireBullets ) - RecvPropVector( RECVINFO( m_vecOrigin ) ), - RecvPropVector( RECVINFO( m_vecDir ) ), - RecvPropInt( RECVINFO( m_iAmmoID ) ), - RecvPropInt( RECVINFO( m_iSeed ) ), - RecvPropInt( RECVINFO( m_iShots ) ), - RecvPropInt( RECVINFO( m_iPlayer ) ), - RecvPropInt( RECVINFO( m_iWeaponIndex ) ), - RecvPropFloat( RECVINFO( m_flSpread ) ), - RecvPropBool( RECVINFO( m_bDoImpacts ) ), - RecvPropBool( RECVINFO( m_bDoTracers ) ), -END_RECV_TABLE() - - diff --git a/sp/src/game/client/hl2mp/clientmode_hl2mpnormal.cpp b/sp/src/game/client/hl2mp/clientmode_hl2mpnormal.cpp deleted file mode 100644 index 35bfd1c1..00000000 --- a/sp/src/game/client/hl2mp/clientmode_hl2mpnormal.cpp +++ /dev/null @@ -1,128 +0,0 @@ -//========= Copyright Valve Corporation, All rights reserved. ============// -// -// Purpose: Draws the normal TF2 or HL2 HUD. -// -// $Workfile: $ -// $Date: $ -// $NoKeywords: $ -//=============================================================================// -#include "cbase.h" -#include "clientmode_hl2mpnormal.h" -#include "vgui_int.h" -#include "hud.h" -#include -#include -#include -#include -#include "iinput.h" -#include "hl2mpclientscoreboard.h" -#include "hl2mptextwindow.h" -#include "ienginevgui.h" - -// memdbgon must be the last include file in a .cpp file!!! -#include "tier0/memdbgon.h" -//----------------------------------------------------------------------------- -// Globals -//----------------------------------------------------------------------------- -vgui::HScheme g_hVGuiCombineScheme = 0; - - -// Instance the singleton and expose the interface to it. -IClientMode *GetClientModeNormal() -{ - static ClientModeHL2MPNormal g_ClientModeNormal; - return &g_ClientModeNormal; -} - -ClientModeHL2MPNormal* GetClientModeHL2MPNormal() -{ - Assert( dynamic_cast< ClientModeHL2MPNormal* >( GetClientModeNormal() ) ); - - return static_cast< ClientModeHL2MPNormal* >( GetClientModeNormal() ); -} - -//----------------------------------------------------------------------------- -// Purpose: this is the viewport that contains all the hud elements -//----------------------------------------------------------------------------- -class CHudViewport : public CBaseViewport -{ -private: - DECLARE_CLASS_SIMPLE( CHudViewport, CBaseViewport ); - -protected: - virtual void ApplySchemeSettings( vgui::IScheme *pScheme ) - { - BaseClass::ApplySchemeSettings( pScheme ); - - gHUD.InitColors( pScheme ); - - SetPaintBackgroundEnabled( false ); - } - - virtual IViewPortPanel *CreatePanelByName( const char *szPanelName ); -}; - -int ClientModeHL2MPNormal::GetDeathMessageStartHeight( void ) -{ - return m_pViewport->GetDeathMessageStartHeight(); -} - -IViewPortPanel* CHudViewport::CreatePanelByName( const char *szPanelName ) -{ - IViewPortPanel* newpanel = NULL; - - if ( Q_strcmp( PANEL_SCOREBOARD, szPanelName) == 0 ) - { - newpanel = new CHL2MPClientScoreBoardDialog( this ); - return newpanel; - } - else if ( Q_strcmp(PANEL_INFO, szPanelName) == 0 ) - { - newpanel = new CHL2MPTextWindow( this ); - return newpanel; - } - else if ( Q_strcmp(PANEL_SPECGUI, szPanelName) == 0 ) - { - newpanel = new CHL2MPSpectatorGUI( this ); - return newpanel; - } - - - return BaseClass::CreatePanelByName( szPanelName ); -} - -//----------------------------------------------------------------------------- -// ClientModeHLNormal implementation -//----------------------------------------------------------------------------- -ClientModeHL2MPNormal::ClientModeHL2MPNormal() -{ - m_pViewport = new CHudViewport(); - m_pViewport->Start( gameuifuncs, gameeventmanager ); -} - - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -ClientModeHL2MPNormal::~ClientModeHL2MPNormal() -{ -} - - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void ClientModeHL2MPNormal::Init() -{ - BaseClass::Init(); - - // Load up the combine control panel scheme - g_hVGuiCombineScheme = vgui::scheme()->LoadSchemeFromFileEx( enginevgui->GetPanel( PANEL_CLIENTDLL ), "resource/CombinePanelScheme.res", "CombineScheme" ); - if (!g_hVGuiCombineScheme) - { - Warning( "Couldn't load combine panel scheme!\n" ); - } -} - - - diff --git a/sp/src/game/client/hl2mp/clientmode_hl2mpnormal.h b/sp/src/game/client/hl2mp/clientmode_hl2mpnormal.h deleted file mode 100644 index 2b06a6f8..00000000 --- a/sp/src/game/client/hl2mp/clientmode_hl2mpnormal.h +++ /dev/null @@ -1,47 +0,0 @@ -//========= Copyright Valve Corporation, All rights reserved. ============// -// -// Purpose: -// -// $Workfile: $ -// $Date: $ -// $NoKeywords: $ -//=============================================================================// -#if !defined( CLIENTMODE_HLNORMAL_H ) -#define CLIENTMODE_HLNORMAL_H -#ifdef _WIN32 -#pragma once -#endif - -#include "clientmode_shared.h" -#include -#include - -class CHudViewport; - -namespace vgui -{ - typedef unsigned long HScheme; -} - - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -class ClientModeHL2MPNormal : public ClientModeShared -{ -public: - DECLARE_CLASS( ClientModeHL2MPNormal, ClientModeShared ); - - ClientModeHL2MPNormal(); - ~ClientModeHL2MPNormal(); - - virtual void Init(); - virtual int GetDeathMessageStartHeight( void ); -}; - -extern IClientMode *GetClientModeNormal(); -extern vgui::HScheme g_hVGuiCombineScheme; - -extern ClientModeHL2MPNormal* GetClientModeHL2MPNormal(); - -#endif // CLIENTMODE_HLNORMAL_H diff --git a/sp/src/game/client/hl2mp/hl2mp_hud_chat.cpp b/sp/src/game/client/hl2mp/hl2mp_hud_chat.cpp deleted file mode 100644 index 67f47148..00000000 --- a/sp/src/game/client/hl2mp/hl2mp_hud_chat.cpp +++ /dev/null @@ -1,116 +0,0 @@ -//========= Copyright Valve Corporation, All rights reserved. ============// -// -// Purpose: -// -//=============================================================================// - -#include "cbase.h" -#include "hl2mp_hud_chat.h" -#include "hud_macros.h" -#include "text_message.h" -#include "vguicenterprint.h" -#include "vgui/ILocalize.h" -#include "c_team.h" -#include "c_playerresource.h" -#include "c_hl2mp_player.h" -#include "hl2mp_gamerules.h" -#include "ihudlcd.h" - - - -DECLARE_HUDELEMENT( CHudChat ); - -DECLARE_HUD_MESSAGE( CHudChat, SayText ); -DECLARE_HUD_MESSAGE( CHudChat, SayText2 ); -DECLARE_HUD_MESSAGE( CHudChat, TextMsg ); - - -//===================== -//CHudChatLine -//===================== - -void CHudChatLine::ApplySchemeSettings(vgui::IScheme *pScheme) -{ - BaseClass::ApplySchemeSettings( pScheme ); -} - -//===================== -//CHudChatInputLine -//===================== - -void CHudChatInputLine::ApplySchemeSettings(vgui::IScheme *pScheme) -{ - BaseClass::ApplySchemeSettings(pScheme); -} - -//===================== -//CHudChat -//===================== - -CHudChat::CHudChat( const char *pElementName ) : BaseClass( pElementName ) -{ - -} - -void CHudChat::CreateChatInputLine( void ) -{ - m_pChatInput = new CHudChatInputLine( this, "ChatInputLine" ); - m_pChatInput->SetVisible( false ); -} - -void CHudChat::CreateChatLines( void ) -{ - m_ChatLine = new CHudChatLine( this, "ChatLine1" ); - m_ChatLine->SetVisible( false ); -} - -void CHudChat::ApplySchemeSettings( vgui::IScheme *pScheme ) -{ - BaseClass::ApplySchemeSettings( pScheme ); -} - - -void CHudChat::Init( void ) -{ - BaseClass::Init(); - - HOOK_HUD_MESSAGE( CHudChat, SayText ); - HOOK_HUD_MESSAGE( CHudChat, SayText2 ); - HOOK_HUD_MESSAGE( CHudChat, TextMsg ); -} - -//----------------------------------------------------------------------------- -// Purpose: Overrides base reset to not cancel chat at round restart -//----------------------------------------------------------------------------- -void CHudChat::Reset( void ) -{ -} - -int CHudChat::GetChatInputOffset( void ) -{ - if ( m_pChatInput->IsVisible() ) - { - return m_iFontHeight; - } - else - return 0; -} - -Color CHudChat::GetClientColor( int clientIndex ) -{ - if ( clientIndex == 0 ) // console msg - { - return g_ColorYellow; - } - else if( g_PR ) - { - switch ( g_PR->GetTeam( clientIndex ) ) - { - case TEAM_COMBINE : return g_ColorBlue; - case TEAM_REBELS : return g_ColorRed; - default : return g_ColorYellow; - } - } - - return g_ColorYellow; -} \ No newline at end of file diff --git a/sp/src/game/client/hl2mp/hl2mp_hud_chat.h b/sp/src/game/client/hl2mp/hl2mp_hud_chat.h deleted file mode 100644 index 5eb2157c..00000000 --- a/sp/src/game/client/hl2mp/hl2mp_hud_chat.h +++ /dev/null @@ -1,65 +0,0 @@ -//========= Copyright Valve Corporation, All rights reserved. ============// -// -// Purpose: -// -// $NoKeywords: $ -//=============================================================================// - -#ifndef CS_HUD_CHAT_H -#define CS_HUD_CHAT_H -#ifdef _WIN32 -#pragma once -#endif - -#include - -class CHudChatLine : public CBaseHudChatLine -{ - DECLARE_CLASS_SIMPLE( CHudChatLine, CBaseHudChatLine ); - -public: - CHudChatLine( vgui::Panel *parent, const char *panelName ) : CBaseHudChatLine( parent, panelName ) {} - - virtual void ApplySchemeSettings(vgui::IScheme *pScheme); - - void MsgFunc_SayText(bf_read &msg); - - - -private: - CHudChatLine( const CHudChatLine & ); // not defined, not accessible -}; - -//----------------------------------------------------------------------------- -// Purpose: The prompt and text entry area for chat messages -//----------------------------------------------------------------------------- -class CHudChatInputLine : public CBaseHudChatInputLine -{ - DECLARE_CLASS_SIMPLE( CHudChatInputLine, CBaseHudChatInputLine ); - -public: - CHudChatInputLine( CBaseHudChat *parent, char const *panelName ) : CBaseHudChatInputLine( parent, panelName ) {} - - virtual void ApplySchemeSettings(vgui::IScheme *pScheme); -}; - -class CHudChat : public CBaseHudChat -{ - DECLARE_CLASS_SIMPLE( CHudChat, CBaseHudChat ); - -public: - CHudChat( const char *pElementName ); - - virtual void CreateChatInputLine( void ); - virtual void CreateChatLines( void ); - - virtual void Init( void ); - virtual void Reset( void ); - virtual void ApplySchemeSettings(vgui::IScheme *pScheme); - - int GetChatInputOffset( void ); - - virtual Color GetClientColor( int clientIndex ); -}; - -#endif //CS_HUD_CHAT_H \ No newline at end of file diff --git a/sp/src/game/client/hl2mp/hl2mp_hud_target_id.cpp b/sp/src/game/client/hl2mp/hl2mp_hud_target_id.cpp deleted file mode 100644 index dc7f164e..00000000 --- a/sp/src/game/client/hl2mp/hl2mp_hud_target_id.cpp +++ /dev/null @@ -1,222 +0,0 @@ -//========= Copyright Valve Corporation, All rights reserved. ============// -// -// Purpose: HUD Target ID element -// -// $NoKeywords: $ -//=============================================================================// -#include "cbase.h" -#include "hud.h" -#include "hudelement.h" -#include "c_hl2mp_player.h" -#include "c_playerresource.h" -#include "vgui_entitypanel.h" -#include "iclientmode.h" -#include "vgui/ILocalize.h" -#include "hl2mp_gamerules.h" - -// memdbgon must be the last include file in a .cpp file!!! -#include "tier0/memdbgon.h" - -#define PLAYER_HINT_DISTANCE 150 -#define PLAYER_HINT_DISTANCE_SQ (PLAYER_HINT_DISTANCE*PLAYER_HINT_DISTANCE) - -static ConVar hud_centerid( "hud_centerid", "1" ); -static ConVar hud_showtargetid( "hud_showtargetid", "1" ); - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -class CTargetID : public CHudElement, public vgui::Panel -{ - DECLARE_CLASS_SIMPLE( CTargetID, vgui::Panel ); - -public: - CTargetID( const char *pElementName ); - void Init( void ); - virtual void ApplySchemeSettings( vgui::IScheme *scheme ); - virtual void Paint( void ); - void VidInit( void ); - -private: - Color GetColorForTargetTeam( int iTeamNumber ); - - vgui::HFont m_hFont; - int m_iLastEntIndex; - float m_flLastChangeTime; -}; - -DECLARE_HUDELEMENT( CTargetID ); - -using namespace vgui; - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -CTargetID::CTargetID( const char *pElementName ) : - CHudElement( pElementName ), BaseClass( NULL, "TargetID" ) -{ - vgui::Panel *pParent = g_pClientMode->GetViewport(); - SetParent( pParent ); - - m_hFont = g_hFontTrebuchet24; - m_flLastChangeTime = 0; - m_iLastEntIndex = 0; - - SetHiddenBits( HIDEHUD_MISCSTATUS ); -} - -//----------------------------------------------------------------------------- -// Purpose: Setup -//----------------------------------------------------------------------------- -void CTargetID::Init( void ) -{ -}; - -void CTargetID::ApplySchemeSettings( vgui::IScheme *scheme ) -{ - BaseClass::ApplySchemeSettings( scheme ); - - m_hFont = scheme->GetFont( "TargetID", IsProportional() ); - - SetPaintBackgroundEnabled( false ); -} - -//----------------------------------------------------------------------------- -// Purpose: clear out string etc between levels -//----------------------------------------------------------------------------- -void CTargetID::VidInit() -{ - CHudElement::VidInit(); - - m_flLastChangeTime = 0; - m_iLastEntIndex = 0; -} - -Color CTargetID::GetColorForTargetTeam( int iTeamNumber ) -{ - return GameResources()->GetTeamColor( iTeamNumber ); -} - -//----------------------------------------------------------------------------- -// Purpose: Draw function for the element -//----------------------------------------------------------------------------- -void CTargetID::Paint() -{ -#define MAX_ID_STRING 256 - wchar_t sIDString[ MAX_ID_STRING ]; - sIDString[0] = 0; - - C_HL2MP_Player *pPlayer = C_HL2MP_Player::GetLocalHL2MPPlayer(); - - if ( !pPlayer ) - return; - - Color c; - - // Get our target's ent index - int iEntIndex = pPlayer->GetIDTarget(); - // Didn't find one? - if ( !iEntIndex ) - { - // Check to see if we should clear our ID - if ( m_flLastChangeTime && (gpGlobals->curtime > (m_flLastChangeTime + 0.5)) ) - { - m_flLastChangeTime = 0; - sIDString[0] = 0; - m_iLastEntIndex = 0; - } - else - { - // Keep re-using the old one - iEntIndex = m_iLastEntIndex; - } - } - else - { - m_flLastChangeTime = gpGlobals->curtime; - } - - // Is this an entindex sent by the server? - if ( iEntIndex ) - { - C_BasePlayer *pPlayer = static_cast(cl_entitylist->GetEnt( iEntIndex )); - C_BasePlayer *pLocalPlayer = C_BasePlayer::GetLocalPlayer(); - - const char *printFormatString = NULL; - wchar_t wszPlayerName[ MAX_PLAYER_NAME_LENGTH ]; - wchar_t wszHealthText[ 10 ]; - bool bShowHealth = false; - bool bShowPlayerName = false; - - // Some entities we always want to check, cause the text may change - // even while we're looking at it - // Is it a player? - if ( IsPlayerIndex( iEntIndex ) ) - { - c = GetColorForTargetTeam( pPlayer->GetTeamNumber() ); - - bShowPlayerName = true; - g_pVGuiLocalize->ConvertANSIToUnicode( pPlayer->GetPlayerName(), wszPlayerName, sizeof(wszPlayerName) ); - - if ( HL2MPRules()->IsTeamplay() == true && pPlayer->InSameTeam(pLocalPlayer) ) - { - printFormatString = "#Playerid_sameteam"; - bShowHealth = true; - } - else - { - printFormatString = "#Playerid_diffteam"; - } - - - if ( bShowHealth ) - { - _snwprintf( wszHealthText, ARRAYSIZE(wszHealthText) - 1, L"%.0f%%", ((float)pPlayer->GetHealth() / (float)pPlayer->GetMaxHealth() ) ); - wszHealthText[ ARRAYSIZE(wszHealthText)-1 ] = '\0'; - } - } - - if ( printFormatString ) - { - if ( bShowPlayerName && bShowHealth ) - { - g_pVGuiLocalize->ConstructString( sIDString, sizeof(sIDString), g_pVGuiLocalize->Find(printFormatString), 2, wszPlayerName, wszHealthText ); - } - else if ( bShowPlayerName ) - { - g_pVGuiLocalize->ConstructString( sIDString, sizeof(sIDString), g_pVGuiLocalize->Find(printFormatString), 1, wszPlayerName ); - } - else if ( bShowHealth ) - { - g_pVGuiLocalize->ConstructString( sIDString, sizeof(sIDString), g_pVGuiLocalize->Find(printFormatString), 1, wszHealthText ); - } - else - { - g_pVGuiLocalize->ConstructString( sIDString, sizeof(sIDString), g_pVGuiLocalize->Find(printFormatString), 0 ); - } - } - - if ( sIDString[0] ) - { - int wide, tall; - int ypos = YRES(260); - int xpos = XRES(10); - - vgui::surface()->GetTextSize( m_hFont, sIDString, wide, tall ); - - if( hud_centerid.GetInt() == 0 ) - { - ypos = YRES(420); - } - else - { - xpos = (ScreenWidth() - wide) / 2; - } - - vgui::surface()->DrawSetTextFont( m_hFont ); - vgui::surface()->DrawSetTextPos( xpos, ypos ); - vgui::surface()->DrawSetTextColor( c ); - vgui::surface()->DrawPrintText( sIDString, wcslen(sIDString) ); - } - } -} diff --git a/sp/src/game/client/hl2mp/hl2mp_hud_team.cpp b/sp/src/game/client/hl2mp/hl2mp_hud_team.cpp deleted file mode 100644 index c3f0c058..00000000 --- a/sp/src/game/client/hl2mp/hl2mp_hud_team.cpp +++ /dev/null @@ -1,189 +0,0 @@ -//========= Copyright Valve Corporation, All rights reserved. ============// -// -// Purpose: HUD Target ID element -// -// $NoKeywords: $ -//=============================================================================// -#include "cbase.h" -#include "hud.h" -#include "hudelement.h" -#include "c_hl2mp_player.h" -#include "c_playerresource.h" -#include "vgui_entitypanel.h" -#include "iclientmode.h" -#include "vgui/ILocalize.h" -#include "hl2mp_gamerules.h" -#include "c_team.h" -#include -// memdbgon must be the last include file in a .cpp file!!! -#include "tier0/memdbgon.h" - - -//----------------------------------------------------------------------------- -// Purpose: Displays current ammunition level -//----------------------------------------------------------------------------- -class CTeamPlayHud : public vgui::Panel, public CHudElement -{ - DECLARE_CLASS_SIMPLE( CTeamPlayHud, vgui::Panel ); - -public: - CTeamPlayHud( const char *pElementName ); - void Reset(); - - virtual void PerformLayout(); - -protected: - virtual void ApplySchemeSettings( vgui::IScheme *pScheme ); - virtual void OnThink(); - -private: - vgui::HFont m_hFont; - Color m_bgColor; - - vgui::Label *m_pWarmupLabel; // "Warmup Mode" - - vgui::Label *m_pBackground; // black box - - bool m_bSuitAuxPowerUsed; - - CPanelAnimationVarAliasType( int, m_iTextX, "text_xpos", "8", "proportional_int" ); - CPanelAnimationVarAliasType( int, m_iTextY, "text_ypos", "8", "proportional_int" ); -}; - -DECLARE_HUDELEMENT( CTeamPlayHud ); - -//----------------------------------------------------------------------------- -// Purpose: Constructor -//----------------------------------------------------------------------------- -CTeamPlayHud::CTeamPlayHud( const char *pElementName ) : BaseClass(NULL, "TeamDisplay"), CHudElement( pElementName ) -{ - vgui::Panel *pParent = g_pClientMode->GetViewport(); - SetParent( pParent ); - SetVisible( false ); - SetAlpha( 255 ); - - m_pBackground = new vgui::Label( this, "Background", "" ); - - m_pWarmupLabel = new vgui::Label( this, "RoundState_warmup", "test label" /*g_pVGuiLocalize->Find( "#Clan_warmup_mode" )*/ ); - m_pWarmupLabel->SetPaintBackgroundEnabled( false ); - m_pWarmupLabel->SetPaintBorderEnabled( false ); - m_pWarmupLabel->SizeToContents(); - m_pWarmupLabel->SetContentAlignment( vgui::Label::a_west ); - m_pWarmupLabel->SetFgColor( GetFgColor() ); - - m_bSuitAuxPowerUsed = false; -} - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void CTeamPlayHud::Reset() -{ -} - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void CTeamPlayHud::ApplySchemeSettings( vgui::IScheme *pScheme ) -{ - BaseClass::ApplySchemeSettings( pScheme ); - - SetFgColor( Color(0,0,0,0) ); //GetSchemeColor("RoundStateFg", pScheme) ); - m_hFont = pScheme->GetFont( "Default", true ); - - m_pBackground->SetBgColor( GetSchemeColor("BgColor", pScheme) ); - m_pBackground->SetPaintBackgroundType( 2 ); - - SetAlpha( 255 ); - SetBgColor( Color( 0, 0, 0, 0 ) ); - SetPaintBackgroundType( 0 ); -} - -//----------------------------------------------------------------------------- -// Purpose: Resizes the label -//----------------------------------------------------------------------------- -void CTeamPlayHud::PerformLayout() -{ - - BaseClass::PerformLayout(); - - int wide, tall; - GetSize( wide, tall ); - - // find the widest line - int labelWide = m_pWarmupLabel->GetWide(); - - // find the total height - int fontTall = vgui::surface()->GetFontTall( m_hFont ); - int labelTall = fontTall; - - labelWide += m_iTextX*2; - labelTall += m_iTextY*2; - - m_pBackground->SetBounds( 0, 0, labelWide, labelTall ); - - int xOffset = (labelWide - m_pWarmupLabel->GetWide())/2; - m_pWarmupLabel->SetPos( 0 + xOffset, 0 + m_iTextY ); -} - -//----------------------------------------------------------------------------- -// Purpose: Updates the label color each frame -//----------------------------------------------------------------------------- -void CTeamPlayHud::OnThink() -{ - SetVisible( false ); - - C_BaseHLPlayer *pLocalPlayer = (C_BaseHLPlayer *)C_BasePlayer::GetLocalPlayer(); - - if ( pLocalPlayer == NULL ) - return; - - if ( HL2MPRules()->IsTeamplay() == false ) - return; - - if ( pLocalPlayer->IsAlive() == false ) - return; - - if ( pLocalPlayer->m_HL2Local.m_flSuitPower < 100 ) - { - if ( m_bSuitAuxPowerUsed == false ) - { - g_pClientMode->GetViewportAnimationController()->StartAnimationSequence("FadeOutTeamLine"); - m_bSuitAuxPowerUsed = true; - } - } - else - { - if ( m_bSuitAuxPowerUsed == true ) - { - g_pClientMode->GetViewportAnimationController()->StartAnimationSequence("FadeInTeamLine"); - m_bSuitAuxPowerUsed = false; - } - } - - int iTeamNumber = pLocalPlayer->GetTeamNumber(); - Color c = GameResources()->GetTeamColor( iTeamNumber ); - - wchar_t string1[1024]; - C_Team *pTeam = GetGlobalTeam( iTeamNumber ); - - if ( pTeam ) - { - wchar_t TeamName[64]; - g_pVGuiLocalize->ConvertANSIToUnicode( pTeam->Get_Name(), TeamName, sizeof(TeamName) ); - - g_pVGuiLocalize->ConstructString( string1, sizeof(string1), g_pVGuiLocalize->Find("#Team"), 1, TeamName ); - - m_pBackground->SetFgColor( GetFgColor() ); - m_pWarmupLabel->SetFgColor(c); - - m_pWarmupLabel->SetText( string1 ); - m_pWarmupLabel->SetVisible( true ); - - m_pWarmupLabel->SizeToContents(); - - SetVisible( true ); - } - - InvalidateLayout(); -} diff --git a/sp/src/game/client/hl2mp/hud_deathnotice.cpp b/sp/src/game/client/hl2mp/hud_deathnotice.cpp deleted file mode 100644 index cbdaa024..00000000 --- a/sp/src/game/client/hl2mp/hud_deathnotice.cpp +++ /dev/null @@ -1,352 +0,0 @@ -//========= Copyright Valve Corporation, All rights reserved. ============// -// -// Purpose: Draws CSPort's death notices -// -// $NoKeywords: $ -//=============================================================================// -#include "cbase.h" -#include "hudelement.h" -#include "hud_macros.h" -#include "c_playerresource.h" -#include "clientmode_hl2mpnormal.h" -#include -#include -#include -#include -#include -#include "c_baseplayer.h" -#include "c_team.h" - - -// memdbgon must be the last include file in a .cpp file!!! -#include "tier0/memdbgon.h" - -static ConVar hud_deathnotice_time( "hud_deathnotice_time", "6", 0 ); - -// Player entries in a death notice -struct DeathNoticePlayer -{ - char szName[MAX_PLAYER_NAME_LENGTH]; - int iEntIndex; -}; - -// Contents of each entry in our list of death notices -struct DeathNoticeItem -{ - DeathNoticePlayer Killer; - DeathNoticePlayer Victim; - CHudTexture *iconDeath; - int iSuicide; - float flDisplayTime; - bool bHeadshot; -}; - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -class CHudDeathNotice : public CHudElement, public vgui::Panel -{ - DECLARE_CLASS_SIMPLE( CHudDeathNotice, vgui::Panel ); -public: - CHudDeathNotice( const char *pElementName ); - - void Init( void ); - void VidInit( void ); - virtual bool ShouldDraw( void ); - virtual void Paint( void ); - virtual void ApplySchemeSettings( vgui::IScheme *scheme ); - - void SetColorForNoticePlayer( int iTeamNumber ); - void RetireExpiredDeathNotices( void ); - - virtual void FireGameEvent( IGameEvent * event ); - -private: - - CPanelAnimationVarAliasType( float, m_flLineHeight, "LineHeight", "15", "proportional_float" ); - - CPanelAnimationVar( float, m_flMaxDeathNotices, "MaxDeathNotices", "4" ); - - CPanelAnimationVar( bool, m_bRightJustify, "RightJustify", "1" ); - - CPanelAnimationVar( vgui::HFont, m_hTextFont, "TextFont", "HudNumbersTimer" ); - - // Texture for skull symbol - CHudTexture *m_iconD_skull; - CHudTexture *m_iconD_headshot; - - CUtlVector m_DeathNotices; -}; - -using namespace vgui; - -DECLARE_HUDELEMENT( CHudDeathNotice ); - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -CHudDeathNotice::CHudDeathNotice( const char *pElementName ) : - CHudElement( pElementName ), BaseClass( NULL, "HudDeathNotice" ) -{ - vgui::Panel *pParent = g_pClientMode->GetViewport(); - SetParent( pParent ); - - m_iconD_headshot = NULL; - m_iconD_skull = NULL; - - SetHiddenBits( HIDEHUD_MISCSTATUS ); -} - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void CHudDeathNotice::ApplySchemeSettings( IScheme *scheme ) -{ - BaseClass::ApplySchemeSettings( scheme ); - SetPaintBackgroundEnabled( false ); -} - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void CHudDeathNotice::Init( void ) -{ - ListenForGameEvent( "player_death" ); -} - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void CHudDeathNotice::VidInit( void ) -{ - m_iconD_skull = gHUD.GetIcon( "d_skull" ); - m_DeathNotices.Purge(); -} - -//----------------------------------------------------------------------------- -// Purpose: Draw if we've got at least one death notice in the queue -//----------------------------------------------------------------------------- -bool CHudDeathNotice::ShouldDraw( void ) -{ - return ( CHudElement::ShouldDraw() && ( m_DeathNotices.Count() ) ); -} - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void CHudDeathNotice::SetColorForNoticePlayer( int iTeamNumber ) -{ - surface()->DrawSetTextColor( GameResources()->GetTeamColor( iTeamNumber ) ); -} - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void CHudDeathNotice::Paint() -{ - if ( !m_iconD_skull ) - return; - - int yStart = GetClientModeHL2MPNormal()->GetDeathMessageStartHeight(); - - surface()->DrawSetTextFont( m_hTextFont ); - surface()->DrawSetTextColor( GameResources()->GetTeamColor( 0 ) ); - - - int iCount = m_DeathNotices.Count(); - for ( int i = 0; i < iCount; i++ ) - { - CHudTexture *icon = m_DeathNotices[i].iconDeath; - if ( !icon ) - continue; - - wchar_t victim[ 256 ]; - wchar_t killer[ 256 ]; - - // Get the team numbers for the players involved - int iKillerTeam = 0; - int iVictimTeam = 0; - - if( g_PR ) - { - iKillerTeam = g_PR->GetTeam( m_DeathNotices[i].Killer.iEntIndex ); - iVictimTeam = g_PR->GetTeam( m_DeathNotices[i].Victim.iEntIndex ); - } - - g_pVGuiLocalize->ConvertANSIToUnicode( m_DeathNotices[i].Victim.szName, victim, sizeof( victim ) ); - g_pVGuiLocalize->ConvertANSIToUnicode( m_DeathNotices[i].Killer.szName, killer, sizeof( killer ) ); - - // Get the local position for this notice - int len = UTIL_ComputeStringWidth( m_hTextFont, victim ); - int y = yStart + (m_flLineHeight * i); - - int iconWide; - int iconTall; - - if( icon->bRenderUsingFont ) - { - iconWide = surface()->GetCharacterWidth( icon->hFont, icon->cCharacterInFont ); - iconTall = surface()->GetFontTall( icon->hFont ); - } - else - { - float scale = ( (float)ScreenHeight() / 480.0f ); //scale based on 640x480 - iconWide = (int)( scale * (float)icon->Width() ); - iconTall = (int)( scale * (float)icon->Height() ); - } - - int x; - if ( m_bRightJustify ) - { - x = GetWide() - len - iconWide; - } - else - { - x = 0; - } - - // Only draw killers name if it wasn't a suicide - if ( !m_DeathNotices[i].iSuicide ) - { - if ( m_bRightJustify ) - { - x -= UTIL_ComputeStringWidth( m_hTextFont, killer ); - } - - SetColorForNoticePlayer( iKillerTeam ); - - // Draw killer's name - surface()->DrawSetTextPos( x, y ); - surface()->DrawSetTextFont( m_hTextFont ); - surface()->DrawUnicodeString( killer ); - surface()->DrawGetTextPos( x, y ); - } - - Color iconColor( 255, 80, 0, 255 ); - - // Draw death weapon - //If we're using a font char, this will ignore iconTall and iconWide - icon->DrawSelf( x, y, iconWide, iconTall, iconColor ); - x += iconWide; - - SetColorForNoticePlayer( iVictimTeam ); - - // Draw victims name - surface()->DrawSetTextPos( x, y ); - surface()->DrawSetTextFont( m_hTextFont ); //reset the font, draw icon can change it - surface()->DrawUnicodeString( victim ); - } - - // Now retire any death notices that have expired - RetireExpiredDeathNotices(); -} - -//----------------------------------------------------------------------------- -// Purpose: This message handler may be better off elsewhere -//----------------------------------------------------------------------------- -void CHudDeathNotice::RetireExpiredDeathNotices( void ) -{ - // Loop backwards because we might remove one - int iSize = m_DeathNotices.Size(); - for ( int i = iSize-1; i >= 0; i-- ) - { - if ( m_DeathNotices[i].flDisplayTime < gpGlobals->curtime ) - { - m_DeathNotices.Remove(i); - } - } -} - -//----------------------------------------------------------------------------- -// Purpose: Server's told us that someone's died -//----------------------------------------------------------------------------- -void CHudDeathNotice::FireGameEvent( IGameEvent * event ) -{ - if (!g_PR) - return; - - if ( hud_deathnotice_time.GetFloat() == 0 ) - return; - - // the event should be "player_death" - int killer = engine->GetPlayerForUserID( event->GetInt("attacker") ); - int victim = engine->GetPlayerForUserID( event->GetInt("userid") ); - const char *killedwith = event->GetString( "weapon" ); - - char fullkilledwith[128]; - if ( killedwith && *killedwith ) - { - Q_snprintf( fullkilledwith, sizeof(fullkilledwith), "death_%s", killedwith ); - } - else - { - fullkilledwith[0] = 0; - } - - // Do we have too many death messages in the queue? - if ( m_DeathNotices.Count() > 0 && - m_DeathNotices.Count() >= (int)m_flMaxDeathNotices ) - { - // Remove the oldest one in the queue, which will always be the first - m_DeathNotices.Remove(0); - } - - // Get the names of the players - const char *killer_name = g_PR->GetPlayerName( killer ); - const char *victim_name = g_PR->GetPlayerName( victim ); - - if ( !killer_name ) - killer_name = ""; - if ( !victim_name ) - victim_name = ""; - - // Make a new death notice - DeathNoticeItem deathMsg; - deathMsg.Killer.iEntIndex = killer; - deathMsg.Victim.iEntIndex = victim; - Q_strncpy( deathMsg.Killer.szName, killer_name, MAX_PLAYER_NAME_LENGTH ); - Q_strncpy( deathMsg.Victim.szName, victim_name, MAX_PLAYER_NAME_LENGTH ); - deathMsg.flDisplayTime = gpGlobals->curtime + hud_deathnotice_time.GetFloat(); - deathMsg.iSuicide = ( !killer || killer == victim ); - - // Try and find the death identifier in the icon list - deathMsg.iconDeath = gHUD.GetIcon( fullkilledwith ); - - if ( !deathMsg.iconDeath || deathMsg.iSuicide ) - { - // Can't find it, so use the default skull & crossbones icon - deathMsg.iconDeath = m_iconD_skull; - } - - // Add it to our list of death notices - m_DeathNotices.AddToTail( deathMsg ); - - char sDeathMsg[512]; - - // Record the death notice in the console - if ( deathMsg.iSuicide ) - { - if ( !strcmp( fullkilledwith, "d_worldspawn" ) ) - { - Q_snprintf( sDeathMsg, sizeof( sDeathMsg ), "%s died.\n", deathMsg.Victim.szName ); - } - else //d_world - { - Q_snprintf( sDeathMsg, sizeof( sDeathMsg ), "%s suicided.\n", deathMsg.Victim.szName ); - } - } - else - { - Q_snprintf( sDeathMsg, sizeof( sDeathMsg ), "%s killed %s", deathMsg.Killer.szName, deathMsg.Victim.szName ); - - if ( fullkilledwith && *fullkilledwith && (*fullkilledwith > 13 ) ) - { - Q_strncat( sDeathMsg, VarArgs( " with %s.\n", fullkilledwith+6 ), sizeof( sDeathMsg ), COPY_ALL_CHARACTERS ); - } - } - - Msg( "%s", sDeathMsg ); -} - - - diff --git a/sp/src/game/client/hl2mp/ui/backgroundpanel.cpp b/sp/src/game/client/hl2mp/ui/backgroundpanel.cpp deleted file mode 100644 index da35a965..00000000 --- a/sp/src/game/client/hl2mp/ui/backgroundpanel.cpp +++ /dev/null @@ -1,431 +0,0 @@ -//========= Copyright Valve Corporation, All rights reserved. ============// -// -// Purpose: -// -// $NoKeywords: $ -//=============================================================================// - -#include "cbase.h" -#include "backgroundpanel.h" - -#include -#include -#include -#include -#include -#include "vgui_controls/BuildGroup.h" -#include "vgui_controls/BitmapImagePanel.h" - -using namespace vgui; - -#define DEBUG_WINDOW_RESIZING 0 -#define DEBUG_WINDOW_REPOSITIONING 0 - -class CaptionLabel : public Label -{ -public: - CaptionLabel(Panel *parent, const char *panelName, const char *text) : Label(parent, panelName, text) - { - } - - virtual void ApplySchemeSettings( vgui::IScheme *pScheme ) - { - Label::ApplySchemeSettings( pScheme ); - SetFont( pScheme->GetFont( "MenuTitle", IsProportional() ) ); - } -}; - -//----------------------------------------------------------------------------- -// Purpose: transform a normalized value into one that is scaled based the minimum -// of the horizontal and vertical ratios -//----------------------------------------------------------------------------- -static int GetAlternateProportionalValueFromNormal(int normalizedValue) -{ - int wide, tall; - GetHudSize( wide, tall ); - int proH, proW; - surface()->GetProportionalBase( proW, proH ); - double scaleH = (double)tall / (double)proH; - double scaleW = (double)wide / (double)proW; - double scale = (scaleW < scaleH) ? scaleW : scaleH; - - return (int)( normalizedValue * scale ); -} - -//----------------------------------------------------------------------------- -// Purpose: transform a standard scaled value into one that is scaled based the minimum -// of the horizontal and vertical ratios -//----------------------------------------------------------------------------- -int GetAlternateProportionalValueFromScaled( HScheme hScheme, int scaledValue) -{ - return GetAlternateProportionalValueFromNormal( scheme()->GetProportionalNormalizedValueEx( hScheme, scaledValue ) ); -} - -//----------------------------------------------------------------------------- -// Purpose: moves and resizes a single control -//----------------------------------------------------------------------------- -static void RepositionControl( Panel *pPanel ) -{ - int x, y, w, h; - pPanel->GetBounds(x, y, w, h); - -#if DEBUG_WINDOW_RESIZING - int x1, y1, w1, h1; - pPanel->GetBounds(x1, y1, w1, h1); - int x2, y2, w2, h2; - x2 = scheme()->GetProportionalNormalizedValueEx( pPanel->GetScheme(), x1 ); - y2 = scheme()->GetProportionalNormalizedValueEx( pPanel->GetScheme(), y1 ); - w2 = scheme()->GetProportionalNormalizedValueEx( pPanel->GetScheme(), w1 ); - h2 = scheme()->GetProportionalNormalizedValueEx( pPanel->GetScheme(), h1 ); -#endif - - x = GetAlternateProportionalValueFromScaled(pPanel->GetScheme(),x); - y = GetAlternateProportionalValueFromScaled(pPanel->GetScheme(),y); - w = GetAlternateProportionalValueFromScaled(pPanel->GetScheme(),w); - h = GetAlternateProportionalValueFromScaled(pPanel->GetScheme(),h); - - pPanel->SetBounds(x, y, w, h); - -#if DEBUG_WINDOW_RESIZING - DevMsg( "Resizing '%s' from (%d,%d) %dx%d to (%d,%d) %dx%d -- initially was (%d,%d) %dx%d\n", - pPanel->GetName(), x1, y1, w1, h1, x, y, w, h, x2, y2, w2, h2 ); -#endif -} - -//----------------------------------------------------------------------------- -// Purpose: Sets colors etc for background image panels -//----------------------------------------------------------------------------- -void ApplyBackgroundSchemeSettings( EditablePanel *pWindow, vgui::IScheme *pScheme ) -{ - Color bgColor = Color( 255, 255, 255, pScheme->GetColor( "BgColor", Color( 0, 0, 0, 0 ) )[3] ); - Color fgColor = pScheme->GetColor( "FgColor", Color( 0, 0, 0, 0 ) ); - - if ( !pWindow ) - return; - - CBitmapImagePanel *pBitmapPanel; - - // corners -------------------------------------------- - pBitmapPanel = dynamic_cast< CBitmapImagePanel * >(pWindow->FindChildByName( "TopLeftPanel" )); - if ( pBitmapPanel ) - { - pBitmapPanel->setImageColor( bgColor ); - } - pBitmapPanel = dynamic_cast< CBitmapImagePanel * >(pWindow->FindChildByName( "TopRightPanel" )); - if ( pBitmapPanel ) - { - pBitmapPanel->setImageColor( bgColor ); - } - pBitmapPanel = dynamic_cast< CBitmapImagePanel * >(pWindow->FindChildByName( "BottomLeftPanel" )); - if ( pBitmapPanel ) - { - pBitmapPanel->setImageColor( bgColor ); - } - pBitmapPanel = dynamic_cast< CBitmapImagePanel * >(pWindow->FindChildByName( "BottomRightPanel" )); - if ( pBitmapPanel ) - { - pBitmapPanel->setImageColor( bgColor ); - } - - // background ----------------------------------------- - pBitmapPanel = dynamic_cast< CBitmapImagePanel * >(pWindow->FindChildByName( "TopSolid" )); - if ( pBitmapPanel ) - { - pBitmapPanel->setImageColor( bgColor ); - } - pBitmapPanel = dynamic_cast< CBitmapImagePanel * >(pWindow->FindChildByName( "UpperMiddleSolid" )); - if ( pBitmapPanel ) - { - pBitmapPanel->setImageColor( bgColor ); - } - pBitmapPanel = dynamic_cast< CBitmapImagePanel * >(pWindow->FindChildByName( "LowerMiddleSolid" )); - if ( pBitmapPanel ) - { - pBitmapPanel->setImageColor( bgColor ); - } - pBitmapPanel = dynamic_cast< CBitmapImagePanel * >(pWindow->FindChildByName( "BottomSolid" )); - if ( pBitmapPanel ) - { - pBitmapPanel->setImageColor( bgColor ); - } - - // Logo ----------------------------------------------- - pBitmapPanel = dynamic_cast< CBitmapImagePanel * >(pWindow->FindChildByName( "ExclamationPanel" )); - if ( pBitmapPanel ) - { - pBitmapPanel->setImageColor( fgColor ); - } -} - -//----------------------------------------------------------------------------- -// Purpose: Re-aligns background image panels so they are touching. -//----------------------------------------------------------------------------- -static void FixupBackgroundPanels( EditablePanel *pWindow, int offsetX, int offsetY ) -{ - if ( !pWindow ) - return; - - int screenWide, screenTall; - pWindow->GetSize( screenWide, screenTall ); - - int inset = GetAlternateProportionalValueFromNormal( 20 ); - int cornerSize = GetAlternateProportionalValueFromNormal( 10 ); - - int titleHeight = GetAlternateProportionalValueFromNormal( 42 ); - int mainHeight = GetAlternateProportionalValueFromNormal( 376 ); - - int logoSize = titleHeight; - - int captionInset = GetAlternateProportionalValueFromNormal( 76 ); - - Panel *pPanel; - - // corners -------------------------------------------- - pPanel = pWindow->FindChildByName( "TopLeftPanel" ); - if ( pPanel ) - { - pPanel->SetZPos( -20 ); - pPanel->SetBounds( offsetX + inset, offsetY + inset, cornerSize, cornerSize ); - } - - pPanel = pWindow->FindChildByName( "TopRightPanel" ); - if ( pPanel ) - { - pPanel->SetZPos( -20 ); - pPanel->SetBounds( screenWide - offsetX - inset - cornerSize, offsetY + inset, cornerSize, cornerSize ); - } - - pPanel = pWindow->FindChildByName( "BottomLeftPanel" ); - if ( pPanel ) - { - pPanel->SetZPos( -20 ); - pPanel->SetBounds( offsetX + inset, screenTall - offsetY - inset - cornerSize, cornerSize, cornerSize ); - } - - pPanel = pWindow->FindChildByName( "BottomRightPanel" ); - if ( pPanel ) - { - pPanel->SetZPos( -20 ); - pPanel->SetBounds( screenWide - offsetX - inset - cornerSize, screenTall - offsetY - inset - cornerSize, cornerSize, cornerSize ); - } - - // background ----------------------------------------- - pPanel = pWindow->FindChildByName( "TopSolid" ); - if ( pPanel ) - { - pPanel->SetZPos( -20 ); - pPanel->SetBounds( offsetX + inset + cornerSize, offsetY + inset, screenWide - 2*offsetX - 2*inset - 2*cornerSize, cornerSize ); - } - - pPanel = pWindow->FindChildByName( "UpperMiddleSolid" ); - if ( pPanel ) - { - pPanel->SetZPos( -20 ); - pPanel->SetBounds( offsetX + inset, offsetY + inset + cornerSize, screenWide - 2*offsetX - 2*inset, titleHeight ); - } - - pPanel = pWindow->FindChildByName( "LowerMiddleSolid" ); - if ( pPanel ) - { - pPanel->SetZPos( -20 ); - pPanel->SetBounds( offsetX + inset + cornerSize, screenTall - offsetY - inset - cornerSize, screenWide - 2*offsetX - 2*inset - 2*cornerSize, cornerSize ); - } - - pPanel = pWindow->FindChildByName( "BottomSolid" ); - if ( pPanel ) - { - pPanel->SetZPos( -20 ); - pPanel->SetBounds( offsetX + inset, screenTall - offsetY - inset - cornerSize - mainHeight, screenWide - 2*offsetX - 2*inset, mainHeight ); - } - - // transparent border --------------------------------- - pPanel = pWindow->FindChildByName( "TopClear" ); - if ( pPanel ) - { - pPanel->SetZPos( -20 ); - pPanel->SetBounds( 0, 0, screenWide, offsetY + inset ); - } - - pPanel = pWindow->FindChildByName( "BottomClear" ); - if ( pPanel ) - { - pPanel->SetZPos( -20 ); - pPanel->SetBounds( 0, screenTall - offsetY - inset, screenWide, offsetY + inset ); - } - - pPanel = pWindow->FindChildByName( "LeftClear" ); - if ( pPanel ) - { - pPanel->SetZPos( -20 ); - pPanel->SetBounds( 0, offsetY + inset, offsetX + inset, screenTall - 2*offsetY - 2*inset ); - } - - pPanel = pWindow->FindChildByName( "RightClear" ); - if ( pPanel ) - { - pPanel->SetZPos( -20 ); - pPanel->SetBounds( screenWide - offsetX - inset, offsetY + inset, offsetX + inset, screenTall - 2*offsetY - 2*inset ); - } - - // Logo ----------------------------------------------- - int logoInset = (cornerSize + titleHeight - logoSize)/2; - pPanel = pWindow->FindChildByName( "ExclamationPanel" ); - if ( pPanel ) - { - pPanel->SetZPos( -19 ); // higher than the background - pPanel->SetBounds( offsetX + inset + logoInset, offsetY + inset + logoInset, logoSize, logoSize ); - } - - // Title caption -------------------------------------- - pPanel = dynamic_cast< Label * >(pWindow->FindChildByName( "CaptionLabel" )); - if ( pPanel ) - { - pPanel->SetZPos( -19 ); // higher than the background - pPanel->SetBounds( offsetX + captionInset/*inset + 2*logoInset + logoSize*/, offsetY + inset + logoInset, screenWide, logoSize ); - } -} - -//----------------------------------------------------------------------------- -// Purpose: Creates background image panels -//----------------------------------------------------------------------------- -void CreateBackground( EditablePanel *pWindow ) -{ - // corners -------------------------------------------- - new CBitmapImagePanel( pWindow, "TopLeftPanel", "gfx/vgui/round_corner_nw" ); - new CBitmapImagePanel( pWindow, "TopRightPanel", "gfx/vgui/round_corner_ne" ); - new CBitmapImagePanel( pWindow, "BottomLeftPanel", "gfx/vgui/round_corner_sw" ); - new CBitmapImagePanel( pWindow, "BottomRightPanel", "gfx/vgui/round_corner_se" ); - - // background ----------------------------------------- - new CBitmapImagePanel( pWindow, "TopSolid", "gfx/vgui/solid_background" ); - new CBitmapImagePanel( pWindow, "UpperMiddleSolid", "gfx/vgui/solid_background" ); - new CBitmapImagePanel( pWindow, "LowerMiddleSolid", "gfx/vgui/solid_background" ); - new CBitmapImagePanel( pWindow, "BottomSolid", "gfx/vgui/solid_background" ); - - // transparent border --------------------------------- - new CBitmapImagePanel( pWindow, "TopClear", "gfx/vgui/trans_background" ); - new CBitmapImagePanel( pWindow, "BottomClear", "gfx/vgui/trans_background" ); - new CBitmapImagePanel( pWindow, "LeftClear", "gfx/vgui/trans_background" ); - new CBitmapImagePanel( pWindow, "RightClear", "gfx/vgui/trans_background" ); - - // Logo ----------------------------------------------- - new CBitmapImagePanel( pWindow, "ExclamationPanel", "gfx/vgui/hl2mp_logo" ); - - // Title caption -------------------------------------- - Panel *pPanel = dynamic_cast< Label * >(pWindow->FindChildByName( "CaptionLabel" )); - if ( !pPanel ) - new CaptionLabel( pWindow, "CaptionLabel", "" ); -} - -void ResizeWindowControls( EditablePanel *pWindow, int tall, int wide, int offsetX, int offsetY ) -{ - if (!pWindow || !pWindow->GetBuildGroup() || !pWindow->GetBuildGroup()->GetPanelList()) - return; - - CUtlVector *panelList = pWindow->GetBuildGroup()->GetPanelList(); - CUtlVector resizedPanels; - CUtlVector movedPanels; - - // Resize to account for 1.25 aspect ratio (1280x1024) screens - { - for ( int i = 0; i < panelList->Size(); ++i ) - { - PHandle handle = (*panelList)[i]; - - Panel *panel = handle.Get(); - - bool found = false; - for ( int j = 0; j < resizedPanels.Size(); ++j ) - { - if (panel == resizedPanels[j]) - found = true; - } - - if (!panel || found) - { - continue; - } - - resizedPanels.AddToTail( panel ); // don't move a panel more than once - - if ( panel != pWindow ) - { - RepositionControl( panel ); - } - } - } - - // and now re-center them. Woohoo! - for ( int i = 0; i < panelList->Size(); ++i ) - { - PHandle handle = (*panelList)[i]; - - Panel *panel = handle.Get(); - - bool found = false; - for ( int j = 0; j < movedPanels.Size(); ++j ) - { - if (panel == movedPanels[j]) - found = true; - } - - if (!panel || found) - { - continue; - } - - movedPanels.AddToTail( panel ); // don't move a panel more than once - - if ( panel != pWindow ) - { - int x, y; - - panel->GetPos( x, y ); - panel->SetPos( x + offsetX, y + offsetY ); - -#if DEBUG_WINDOW_REPOSITIONING - DevMsg( "Repositioning '%s' from (%d,%d) to (%d,%d) -- a distance of (%d,%d)\n", - panel->GetName(), x, y, x + offsetX, y + offsetY, offsetX, offsetY ); -#endif - } - } -} - -//----------------------------------------------------------------------------- -// Purpose: Resizes windows to fit completely on-screen (for 1280x1024), and -// centers them on the screen. Sub-controls are also resized and moved. -//----------------------------------------------------------------------------- -void LayoutBackgroundPanel( EditablePanel *pWindow ) -{ - if ( !pWindow ) - return; - - int screenW, screenH; - GetHudSize( screenW, screenH ); - - int wide, tall; - pWindow->GetSize( wide, tall ); - - int offsetX = 0; - int offsetY = 0; - - // Slide everything over to the center - pWindow->SetBounds( 0, 0, screenW, screenH ); - - if ( wide != screenW || tall != screenH ) - { - wide = GetAlternateProportionalValueFromScaled(pWindow->GetScheme(), wide); - tall = GetAlternateProportionalValueFromScaled(pWindow->GetScheme(), tall); - - offsetX = (screenW - wide)/2; - offsetY = (screenH - tall)/2; - - ResizeWindowControls( pWindow, tall, wide, offsetX, offsetY ); - } - - // now that the panels are moved/resized, look for some bg panels, and re-align them - FixupBackgroundPanels( pWindow, offsetX, offsetY ); -} - -//----------------------------------------------------------------------------- - diff --git a/sp/src/game/client/hl2mp/ui/backgroundpanel.h b/sp/src/game/client/hl2mp/ui/backgroundpanel.h deleted file mode 100644 index 54cb2ca5..00000000 --- a/sp/src/game/client/hl2mp/ui/backgroundpanel.h +++ /dev/null @@ -1,43 +0,0 @@ -//========= Copyright Valve Corporation, All rights reserved. ============// -// -// Purpose: -// -// $NoKeywords: $ -//=============================================================================// - -#ifndef CSBACKGROUND_H -#define CSBACKGROUND_H - -#include -#include - -//----------------------------------------------------------------------------- -// Purpose: Creates background image panels -//----------------------------------------------------------------------------- -void CreateBackground( vgui::EditablePanel *pWindow ); - -//----------------------------------------------------------------------------- -// Purpose: Resizes windows to fit completely on-screen (for 1280x1024), and -// centers them on the screen. Sub-controls are also resized and moved. -//----------------------------------------------------------------------------- -void LayoutBackgroundPanel( vgui::EditablePanel *pWindow ); - -//----------------------------------------------------------------------------- -// Purpose: Sets colors etc for background image panels -//----------------------------------------------------------------------------- -void ApplyBackgroundSchemeSettings( vgui::EditablePanel *pWindow, vgui::IScheme *pScheme ); - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void ResizeWindowControls( vgui::EditablePanel *pWindow, int tall, int wide, int offsetX, int offsetY ); - -//----------------------------------------------------------------------------- -// Purpose: transform a standard scaled value into one that is scaled based the minimum -// of the horizontal and vertical ratios -//----------------------------------------------------------------------------- -int GetAlternateProportionalValueFromScaled( vgui::HScheme hScheme, int scaledValue ); - -//----------------------------------------------------------------------------- - -#endif // CSBACKGROUND_H diff --git a/sp/src/game/client/hl2mp/ui/hl2mpclientscoreboard.cpp b/sp/src/game/client/hl2mp/ui/hl2mpclientscoreboard.cpp deleted file mode 100644 index 941c976d..00000000 --- a/sp/src/game/client/hl2mp/ui/hl2mpclientscoreboard.cpp +++ /dev/null @@ -1,653 +0,0 @@ -//========= Copyright Valve Corporation, All rights reserved. ============// -// -// Purpose: -// -// $NoKeywords: $ -//=============================================================================// - -#include "cbase.h" -#include "hud.h" -#include "hl2mpclientscoreboard.h" -#include "c_team.h" -#include "c_playerresource.h" -#include "c_hl2mp_player.h" -#include "hl2mp_gamerules.h" - -#include - -#include -#include -#include -#include -#include - -#include "voice_status.h" - -using namespace vgui; - -#define TEAM_MAXCOUNT 5 - -// id's of sections used in the scoreboard -enum EScoreboardSections -{ - SCORESECTION_COMBINE = 1, - SCORESECTION_REBELS = 2, - SCORESECTION_FREEFORALL = 3, - SCORESECTION_SPECTATOR = 4 -}; - -const int NumSegments = 7; -static int coord[NumSegments+1] = { - 0, - 1, - 2, - 3, - 4, - 6, - 9, - 10 -}; - -//----------------------------------------------------------------------------- -// Purpose: Konstructor -//----------------------------------------------------------------------------- -CHL2MPClientScoreBoardDialog::CHL2MPClientScoreBoardDialog(IViewPort *pViewPort):CClientScoreBoardDialog(pViewPort) -{ -} - -//----------------------------------------------------------------------------- -// Purpose: Destructor -//----------------------------------------------------------------------------- -CHL2MPClientScoreBoardDialog::~CHL2MPClientScoreBoardDialog() -{ -} - -//----------------------------------------------------------------------------- -// Purpose: Paint background for rounded corners -//----------------------------------------------------------------------------- -void CHL2MPClientScoreBoardDialog::PaintBackground() -{ - m_pPlayerList->SetBgColor( Color(0, 0, 0, 0) ); - m_pPlayerList->SetBorder(NULL); - - int x1, x2, y1, y2; - surface()->DrawSetColor(m_bgColor); - surface()->DrawSetTextColor(m_bgColor); - - int wide, tall; - GetSize( wide, tall ); - - int i; - - // top-left corner -------------------------------------------------------- - int xDir = 1; - int yDir = -1; - int xIndex = 0; - int yIndex = NumSegments - 1; - int xMult = 1; - int yMult = 1; - int x = 0; - int y = 0; - for ( i=0; iDrawFilledRect( x1, y1, x2, y2 ); - - xIndex += xDir; - yIndex += yDir; - } - - // top-right corner ------------------------------------------------------- - xDir = 1; - yDir = -1; - xIndex = 0; - yIndex = NumSegments - 1; - x = wide; - y = 0; - xMult = -1; - yMult = 1; - for ( i=0; iDrawFilledRect( x1, y1, x2, y2 ); - xIndex += xDir; - yIndex += yDir; - } - - // bottom-right corner ---------------------------------------------------- - xDir = 1; - yDir = -1; - xIndex = 0; - yIndex = NumSegments - 1; - x = wide; - y = tall; - xMult = -1; - yMult = -1; - for ( i=0; iDrawFilledRect( x1, y1, x2, y2 ); - xIndex += xDir; - yIndex += yDir; - } - - // bottom-left corner ----------------------------------------------------- - xDir = 1; - yDir = -1; - xIndex = 0; - yIndex = NumSegments - 1; - x = 0; - y = tall; - xMult = 1; - yMult = -1; - for ( i=0; iDrawFilledRect( x1, y1, x2, y2 ); - xIndex += xDir; - yIndex += yDir; - } - - // paint between top left and bottom left --------------------------------- - x1 = 0; - x2 = coord[NumSegments]; - y1 = coord[NumSegments]; - y2 = tall - coord[NumSegments]; - surface()->DrawFilledRect( x1, y1, x2, y2 ); - - // paint between left and right ------------------------------------------- - x1 = coord[NumSegments]; - x2 = wide - coord[NumSegments]; - y1 = 0; - y2 = tall; - surface()->DrawFilledRect( x1, y1, x2, y2 ); - - // paint between top right and bottom right ------------------------------- - x1 = wide - coord[NumSegments]; - x2 = wide; - y1 = coord[NumSegments]; - y2 = tall - coord[NumSegments]; - surface()->DrawFilledRect( x1, y1, x2, y2 ); -} - -//----------------------------------------------------------------------------- -// Purpose: Paint border for rounded corners -//----------------------------------------------------------------------------- -void CHL2MPClientScoreBoardDialog::PaintBorder() -{ - int x1, x2, y1, y2; - surface()->DrawSetColor(m_borderColor); - surface()->DrawSetTextColor(m_borderColor); - - int wide, tall; - GetSize( wide, tall ); - - int i; - - // top-left corner -------------------------------------------------------- - int xDir = 1; - int yDir = -1; - int xIndex = 0; - int yIndex = NumSegments - 1; - int xMult = 1; - int yMult = 1; - int x = 0; - int y = 0; - for ( i=0; iDrawFilledRect( x1, y1, x2, y2 ); - - xIndex += xDir; - yIndex += yDir; - } - - // top-right corner ------------------------------------------------------- - xDir = 1; - yDir = -1; - xIndex = 0; - yIndex = NumSegments - 1; - x = wide; - y = 0; - xMult = -1; - yMult = 1; - for ( i=0; iDrawFilledRect( x1, y1, x2, y2 ); - xIndex += xDir; - yIndex += yDir; - } - - // bottom-right corner ---------------------------------------------------- - xDir = 1; - yDir = -1; - xIndex = 0; - yIndex = NumSegments - 1; - x = wide; - y = tall; - xMult = -1; - yMult = -1; - for ( i=0; iDrawFilledRect( x1, y1, x2, y2 ); - xIndex += xDir; - yIndex += yDir; - } - - // bottom-left corner ----------------------------------------------------- - xDir = 1; - yDir = -1; - xIndex = 0; - yIndex = NumSegments - 1; - x = 0; - y = tall; - xMult = 1; - yMult = -1; - for ( i=0; iDrawFilledRect( x1, y1, x2, y2 ); - xIndex += xDir; - yIndex += yDir; - } - - // top -------------------------------------------------------------------- - x1 = coord[NumSegments]; - x2 = wide - coord[NumSegments]; - y1 = 0; - y2 = 1; - surface()->DrawFilledRect( x1, y1, x2, y2 ); - - // bottom ----------------------------------------------------------------- - x1 = coord[NumSegments]; - x2 = wide - coord[NumSegments]; - y1 = tall - 1; - y2 = tall; - surface()->DrawFilledRect( x1, y1, x2, y2 ); - - // left ------------------------------------------------------------------- - x1 = 0; - x2 = 1; - y1 = coord[NumSegments]; - y2 = tall - coord[NumSegments]; - surface()->DrawFilledRect( x1, y1, x2, y2 ); - - // right ------------------------------------------------------------------ - x1 = wide - 1; - x2 = wide; - y1 = coord[NumSegments]; - y2 = tall - coord[NumSegments]; - surface()->DrawFilledRect( x1, y1, x2, y2 ); -} - -//----------------------------------------------------------------------------- -// Purpose: Apply scheme settings -//----------------------------------------------------------------------------- -void CHL2MPClientScoreBoardDialog::ApplySchemeSettings( vgui::IScheme *pScheme ) -{ - BaseClass::ApplySchemeSettings( pScheme ); - - m_bgColor = GetSchemeColor("SectionedListPanel.BgColor", GetBgColor(), pScheme); - m_borderColor = pScheme->GetColor( "FgColor", Color( 0, 0, 0, 0 ) ); - - SetBgColor( Color(0, 0, 0, 0) ); - SetBorder( pScheme->GetBorder( "BaseBorder" ) ); -} - - -//----------------------------------------------------------------------------- -// Purpose: sets up base sections -//----------------------------------------------------------------------------- -void CHL2MPClientScoreBoardDialog::InitScoreboardSections() -{ - m_pPlayerList->SetBgColor( Color(0, 0, 0, 0) ); - m_pPlayerList->SetBorder(NULL); - - // fill out the structure of the scoreboard - AddHeader(); - - if ( HL2MPRules()->IsTeamplay() ) - { - // add the team sections - AddSection( TYPE_TEAM, TEAM_COMBINE ); - AddSection( TYPE_TEAM, TEAM_REBELS ); - } - else - { - AddSection( TYPE_TEAM, TEAM_UNASSIGNED ); - } - AddSection( TYPE_TEAM, TEAM_SPECTATOR ); -} - -//----------------------------------------------------------------------------- -// Purpose: resets the scoreboard team info -//----------------------------------------------------------------------------- -void CHL2MPClientScoreBoardDialog::UpdateTeamInfo() -{ - if ( g_PR == NULL ) - return; - - int iNumPlayersInGame = 0; - - for ( int j = 1; j <= gpGlobals->maxClients; j++ ) - { - if ( g_PR->IsConnected( j ) ) - { - iNumPlayersInGame++; - } - } - - // update the team sections in the scoreboard - for ( int i = TEAM_SPECTATOR; i < TEAM_MAXCOUNT; i++ ) - { - wchar_t *teamName = NULL; - int sectionID = 0; - C_Team *team = GetGlobalTeam(i); - - if ( team ) - { - sectionID = GetSectionFromTeamNumber( i ); - - // update team name - wchar_t name[64]; - wchar_t string1[1024]; - wchar_t wNumPlayers[6]; - - if ( HL2MPRules()->IsTeamplay() == false ) - { - _snwprintf( wNumPlayers, ARRAYSIZE(wNumPlayers), L"%i", iNumPlayersInGame ); -#ifdef WIN32 - _snwprintf( name, ARRAYSIZE(name), L"%s", g_pVGuiLocalize->Find("#ScoreBoard_Deathmatch") ); -#else - _snwprintf( name, ARRAYSIZE(name), L"%S", g_pVGuiLocalize->Find("#ScoreBoard_Deathmatch") ); -#endif - - teamName = name; - - if ( iNumPlayersInGame == 1) - { - g_pVGuiLocalize->ConstructString( string1, sizeof(string1), g_pVGuiLocalize->Find("#ScoreBoard_Player"), 2, teamName, wNumPlayers ); - } - else - { - g_pVGuiLocalize->ConstructString( string1, sizeof(string1), g_pVGuiLocalize->Find("#ScoreBoard_Players"), 2, teamName, wNumPlayers ); - } - } - else - { - _snwprintf(wNumPlayers, ARRAYSIZE(wNumPlayers), L"%i", team->Get_Number_Players()); - - if (!teamName && team) - { - g_pVGuiLocalize->ConvertANSIToUnicode(team->Get_Name(), name, sizeof(name)); - teamName = name; - } - - if (team->Get_Number_Players() == 1) - { - g_pVGuiLocalize->ConstructString( string1, sizeof(string1), g_pVGuiLocalize->Find("#ScoreBoard_Player"), 2, teamName, wNumPlayers ); - } - else - { - g_pVGuiLocalize->ConstructString( string1, sizeof(string1), g_pVGuiLocalize->Find("#ScoreBoard_Players"), 2, teamName, wNumPlayers ); - } - - // update stats - wchar_t val[6]; - V_snwprintf(val, ARRAYSIZE(val), L"%d", team->Get_Score()); - m_pPlayerList->ModifyColumn(sectionID, "frags", val); - if (team->Get_Ping() < 1) - { - m_pPlayerList->ModifyColumn(sectionID, "ping", L""); - } - else - { - V_snwprintf(val, ARRAYSIZE(val), L"%d", team->Get_Ping()); - m_pPlayerList->ModifyColumn(sectionID, "ping", val); - } - - } - - m_pPlayerList->ModifyColumn(sectionID, "name", string1); - } - } -} - -//----------------------------------------------------------------------------- -// Purpose: adds the top header of the scoreboars -//----------------------------------------------------------------------------- -void CHL2MPClientScoreBoardDialog::AddHeader() -{ - // add the top header - m_pPlayerList->AddSection(0, ""); - m_pPlayerList->SetSectionAlwaysVisible(0); - HFont hFallbackFont = scheme()->GetIScheme( GetScheme() )->GetFont( "DefaultVerySmallFallBack", false ); - m_pPlayerList->AddColumnToSection(0, "name", "", 0, scheme()->GetProportionalScaledValueEx( GetScheme(), CSTRIKE_NAME_WIDTH ), hFallbackFont ); - m_pPlayerList->AddColumnToSection(0, "class", "", 0, scheme()->GetProportionalScaledValueEx( GetScheme(), CSTRIKE_CLASS_WIDTH ) ); - m_pPlayerList->AddColumnToSection(0, "frags", "#PlayerScore", 0 | SectionedListPanel::COLUMN_RIGHT, scheme()->GetProportionalScaledValueEx( GetScheme(), CSTRIKE_SCORE_WIDTH ) ); - m_pPlayerList->AddColumnToSection(0, "deaths", "#PlayerDeath", 0 | SectionedListPanel::COLUMN_RIGHT, scheme()->GetProportionalScaledValueEx( GetScheme(), CSTRIKE_DEATH_WIDTH ) ); - m_pPlayerList->AddColumnToSection(0, "ping", "#PlayerPing", 0 | SectionedListPanel::COLUMN_RIGHT, scheme()->GetProportionalScaledValueEx( GetScheme(), CSTRIKE_PING_WIDTH ) ); -// m_pPlayerList->AddColumnToSection(0, "voice", "#PlayerVoice", SectionedListPanel::COLUMN_IMAGE | SectionedListPanel::HEADER_TEXT| SectionedListPanel::COLUMN_CENTER, scheme()->GetProportionalScaledValueEx( GetScheme(), CSTRIKE_VOICE_WIDTH ) ); -// m_pPlayerList->AddColumnToSection(0, "tracker", "#PlayerTracker", SectionedListPanel::COLUMN_IMAGE | SectionedListPanel::HEADER_TEXT, scheme()->GetProportionalScaledValueEx( GetScheme(), CSTRIKE_FRIENDS_WIDTH ) ); -} - -//----------------------------------------------------------------------------- -// Purpose: Adds a new section to the scoreboard (i.e the team header) -//----------------------------------------------------------------------------- -void CHL2MPClientScoreBoardDialog::AddSection(int teamType, int teamNumber) -{ - HFont hFallbackFont = scheme()->GetIScheme( GetScheme() )->GetFont( "DefaultVerySmallFallBack", false ); - - int sectionID = GetSectionFromTeamNumber( teamNumber ); - if ( teamType == TYPE_TEAM ) - { - m_pPlayerList->AddSection(sectionID, "", StaticPlayerSortFunc); - - // setup the columns - m_pPlayerList->AddColumnToSection(sectionID, "name", "", 0, scheme()->GetProportionalScaledValueEx( GetScheme(), CSTRIKE_NAME_WIDTH ), hFallbackFont ); - m_pPlayerList->AddColumnToSection(sectionID, "class", "" , 0, scheme()->GetProportionalScaledValueEx( GetScheme(), CSTRIKE_CLASS_WIDTH ) ); - m_pPlayerList->AddColumnToSection(sectionID, "frags", "", SectionedListPanel::COLUMN_RIGHT, scheme()->GetProportionalScaledValueEx( GetScheme(), CSTRIKE_SCORE_WIDTH ) ); - m_pPlayerList->AddColumnToSection(sectionID, "deaths", "", SectionedListPanel::COLUMN_RIGHT, scheme()->GetProportionalScaledValueEx( GetScheme(), CSTRIKE_DEATH_WIDTH ) ); - m_pPlayerList->AddColumnToSection(sectionID, "ping", "", SectionedListPanel::COLUMN_RIGHT, scheme()->GetProportionalScaledValueEx( GetScheme(), CSTRIKE_PING_WIDTH ) ); - - // set the section to have the team color - if ( teamNumber ) - { - if ( GameResources() ) - m_pPlayerList->SetSectionFgColor(sectionID, GameResources()->GetTeamColor(teamNumber)); - } - - m_pPlayerList->SetSectionAlwaysVisible(sectionID); - } - else if ( teamType == TYPE_SPECTATORS ) - { - m_pPlayerList->AddSection(sectionID, ""); - m_pPlayerList->AddColumnToSection(sectionID, "name", "#Spectators", 0, scheme()->GetProportionalScaledValueEx( GetScheme(), CSTRIKE_NAME_WIDTH ), hFallbackFont ); - m_pPlayerList->AddColumnToSection(sectionID, "class", "" , 0, scheme()->GetProportionalScaledValueEx( GetScheme(), 100 ) ); - } -} - -int CHL2MPClientScoreBoardDialog::GetSectionFromTeamNumber( int teamNumber ) -{ - switch ( teamNumber ) - { - case TEAM_COMBINE: - return SCORESECTION_COMBINE; - case TEAM_REBELS: - return SCORESECTION_REBELS; - case TEAM_SPECTATOR: - return SCORESECTION_SPECTATOR; - default: - return SCORESECTION_FREEFORALL; - } - return SCORESECTION_FREEFORALL; -} - -//----------------------------------------------------------------------------- -// Purpose: Adds a new row to the scoreboard, from the playerinfo structure -//----------------------------------------------------------------------------- -bool CHL2MPClientScoreBoardDialog::GetPlayerScoreInfo(int playerIndex, KeyValues *kv) -{ - kv->SetInt("playerIndex", playerIndex); - kv->SetInt("team", g_PR->GetTeam( playerIndex ) ); - kv->SetString("name", g_PR->GetPlayerName(playerIndex) ); - kv->SetInt("deaths", g_PR->GetDeaths( playerIndex )); - kv->SetInt("frags", g_PR->GetPlayerScore( playerIndex )); - kv->SetString("class", ""); - - if (g_PR->GetPing( playerIndex ) < 1) - { - if ( g_PR->IsFakePlayer( playerIndex ) ) - { - kv->SetString("ping", "BOT"); - } - else - { - kv->SetString("ping", ""); - } - } - else - { - kv->SetInt("ping", g_PR->GetPing( playerIndex )); - } - - return true; -} - -enum { - MAX_PLAYERS_PER_TEAM = 16, - MAX_SCOREBOARD_PLAYERS = 32 -}; -struct PlayerScoreInfo -{ - int index; - int frags; - int deaths; - bool important; - bool alive; -}; - -int PlayerScoreInfoSort( const PlayerScoreInfo *p1, const PlayerScoreInfo *p2 ) -{ - // check local - if ( p1->important ) - return -1; - if ( p2->important ) - return 1; - - // check alive - if ( p1->alive && !p2->alive ) - return -1; - if ( p2->alive && !p1->alive ) - return 1; - - // check frags - if ( p1->frags > p2->frags ) - return -1; - if ( p2->frags > p1->frags ) - return 1; - - // check deaths - if ( p1->deaths < p2->deaths ) - return -1; - if ( p2->deaths < p1->deaths ) - return 1; - - // check index - if ( p1->index < p2->index ) - return -1; - - return 1; -} - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void CHL2MPClientScoreBoardDialog::UpdatePlayerInfo() -{ - m_iSectionId = 0; // 0'th row is a header - int selectedRow = -1; - int i; - - CBasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer(); - - if ( !pPlayer || !g_PR ) - return; - - // walk all the players and make sure they're in the scoreboard - for ( i = 1; i <= gpGlobals->maxClients; i++ ) - { - bool shouldShow = g_PR->IsConnected( i ); - if ( shouldShow ) - { - // add the player to the list - KeyValues *playerData = new KeyValues("data"); - GetPlayerScoreInfo( i, playerData ); - int itemID = FindItemIDForPlayerIndex( i ); - int sectionID = GetSectionFromTeamNumber( g_PR->GetTeam( i ) ); - - if (itemID == -1) - { - // add a new row - itemID = m_pPlayerList->AddItem( sectionID, playerData ); - } - else - { - // modify the current row - m_pPlayerList->ModifyItem( itemID, sectionID, playerData ); - } - - if ( i == pPlayer->entindex() ) - { - selectedRow = itemID; // this is the local player, hilight this row - } - - // set the row color based on the players team - m_pPlayerList->SetItemFgColor( itemID, g_PR->GetTeamColor( g_PR->GetTeam( i ) ) ); - - playerData->deleteThis(); - } - else - { - // remove the player - int itemID = FindItemIDForPlayerIndex( i ); - if (itemID != -1) - { - m_pPlayerList->RemoveItem(itemID); - } - } - } - - if ( selectedRow != -1 ) - { - m_pPlayerList->SetSelectedItem(selectedRow); - } - - -} diff --git a/sp/src/game/client/hl2mp/ui/hl2mpclientscoreboard.h b/sp/src/game/client/hl2mp/ui/hl2mpclientscoreboard.h deleted file mode 100644 index d933658e..00000000 --- a/sp/src/game/client/hl2mp/ui/hl2mpclientscoreboard.h +++ /dev/null @@ -1,63 +0,0 @@ -//========= Copyright Valve Corporation, All rights reserved. ============// -// -// Purpose: -// -// $NoKeywords: $ -//=============================================================================// - -#ifndef CHL2MPCLIENTSCOREBOARDDIALOG_H -#define CHL2MPCLIENTSCOREBOARDDIALOG_H -#ifdef _WIN32 -#pragma once -#endif - -#include - -//----------------------------------------------------------------------------- -// Purpose: Game ScoreBoard -//----------------------------------------------------------------------------- -class CHL2MPClientScoreBoardDialog : public CClientScoreBoardDialog -{ -private: - DECLARE_CLASS_SIMPLE(CHL2MPClientScoreBoardDialog, CClientScoreBoardDialog); - -public: - CHL2MPClientScoreBoardDialog(IViewPort *pViewPort); - ~CHL2MPClientScoreBoardDialog(); - - -protected: - // scoreboard overrides - virtual void InitScoreboardSections(); - virtual void UpdateTeamInfo(); - virtual bool GetPlayerScoreInfo(int playerIndex, KeyValues *outPlayerInfo); - virtual void UpdatePlayerInfo(); - - // vgui overrides for rounded corner background - virtual void PaintBackground(); - virtual void PaintBorder(); - virtual void ApplySchemeSettings( vgui::IScheme *pScheme ); - -private: - virtual void AddHeader(); // add the start header of the scoreboard - virtual void AddSection(int teamType, int teamNumber); // add a new section header for a team - - int GetSectionFromTeamNumber( int teamNumber ); - enum - { - CSTRIKE_NAME_WIDTH = 320, - CSTRIKE_CLASS_WIDTH = 56, - CSTRIKE_SCORE_WIDTH = 40, - CSTRIKE_DEATH_WIDTH = 46, - CSTRIKE_PING_WIDTH = 46, -// CSTRIKE_VOICE_WIDTH = 40, -// CSTRIKE_FRIENDS_WIDTH = 24, - }; - - // rounded corners - Color m_bgColor; - Color m_borderColor; -}; - - -#endif // CHL2MPCLIENTSCOREBOARDDIALOG_H diff --git a/sp/src/game/client/hl2mp/ui/hl2mptextwindow.cpp b/sp/src/game/client/hl2mp/ui/hl2mptextwindow.cpp deleted file mode 100644 index dcf5a07b..00000000 --- a/sp/src/game/client/hl2mp/ui/hl2mptextwindow.cpp +++ /dev/null @@ -1,174 +0,0 @@ -//========= Copyright Valve Corporation, All rights reserved. ============// -// -// Purpose: -// -// $NoKeywords: $ -//=============================================================================// - -#include "cbase.h" -#include "hl2mptextwindow.h" -#include "backgroundpanel.h" -#include - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include "IGameUIFuncs.h" // for key bindings -#include -extern IGameUIFuncs *gameuifuncs; // for key binding details - -#include - -// memdbgon must be the last include file in a .cpp file!!! -#include "tier0/memdbgon.h" - -using namespace vgui; - -//----------------------------------------------------------------------------- -// Purpose: Constructor -//----------------------------------------------------------------------------- -CHL2MPTextWindow::CHL2MPTextWindow(IViewPort *pViewPort) : CTextWindow( pViewPort ) -{ - SetProportional( true ); - - m_iScoreBoardKey = BUTTON_CODE_INVALID; // this is looked up in Activate() - - CreateBackground( this ); - m_backgroundLayoutFinished = false; -} - -//----------------------------------------------------------------------------- -// Purpose: Destructor -//----------------------------------------------------------------------------- -CHL2MPTextWindow::~CHL2MPTextWindow() -{ -} - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void CHL2MPTextWindow::Update() -{ - BaseClass::Update(); - - m_pOK->RequestFocus(); -} - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void CHL2MPTextWindow::SetVisible(bool state) -{ - BaseClass::SetVisible(state); - - if ( state ) - { - m_pOK->RequestFocus(); - } -} - -//----------------------------------------------------------------------------- -// Purpose: shows the text window -//----------------------------------------------------------------------------- -void CHL2MPTextWindow::ShowPanel(bool bShow) -{ - if ( bShow ) - { - // get key binding if shown - if ( m_iScoreBoardKey == BUTTON_CODE_INVALID ) // you need to lookup the jump key AFTER the engine has loaded - { - m_iScoreBoardKey = gameuifuncs->GetButtonCodeForBind( "showscores" ); - } - } - - BaseClass::ShowPanel( bShow ); -} - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void CHL2MPTextWindow::OnKeyCodePressed(KeyCode code) -{ - if ( m_iScoreBoardKey != BUTTON_CODE_INVALID && m_iScoreBoardKey == code ) - { - gViewPortInterface->ShowPanel( PANEL_SCOREBOARD, true ); - gViewPortInterface->PostMessageToPanel( PANEL_SCOREBOARD, new KeyValues( "PollHideCode", "code", code ) ); - } - else - { - BaseClass::OnKeyCodePressed( code ); - } -} - -//----------------------------------------------------------------------------- -// Purpose: The CS background is painted by image panels, so we should do nothing -//----------------------------------------------------------------------------- -void CHL2MPTextWindow::PaintBackground() -{ -} - -//----------------------------------------------------------------------------- -// Purpose: Scale / center the window -//----------------------------------------------------------------------------- -void CHL2MPTextWindow::PerformLayout() -{ - BaseClass::PerformLayout(); - - // stretch the window to fullscreen - if ( !m_backgroundLayoutFinished ) - LayoutBackgroundPanel( this ); - m_backgroundLayoutFinished = true; -} - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void CHL2MPTextWindow::ApplySchemeSettings( vgui::IScheme *pScheme ) -{ - BaseClass::ApplySchemeSettings( pScheme ); - ApplyBackgroundSchemeSettings( this, pScheme ); -} - -CHL2MPSpectatorGUI::CHL2MPSpectatorGUI(IViewPort *pViewPort) : CSpectatorGUI(pViewPort) -{ -} - - -bool CHL2MPSpectatorGUI::NeedsUpdate( void ) -{ - if ( !C_BasePlayer::GetLocalPlayer() ) - return false; - - if ( m_nLastSpecMode != C_BasePlayer::GetLocalPlayer()->GetObserverMode() ) - return true; - - if ( m_nLastSpecTarget != C_BasePlayer::GetLocalPlayer()->GetObserverTarget() ) - return true; - - return BaseClass::NeedsUpdate(); -} - - -void CHL2MPSpectatorGUI::Update() -{ - BaseClass::Update(); - - C_BasePlayer *pLocalPlayer = C_BasePlayer::GetLocalPlayer(); - - if( pLocalPlayer ) - { - m_nLastSpecMode = pLocalPlayer->GetObserverMode(); - m_nLastSpecTarget = pLocalPlayer->GetObserverTarget(); - } -} - - diff --git a/sp/src/game/client/hl2mp/ui/hl2mptextwindow.h b/sp/src/game/client/hl2mp/ui/hl2mptextwindow.h deleted file mode 100644 index 55e378ff..00000000 --- a/sp/src/game/client/hl2mp/ui/hl2mptextwindow.h +++ /dev/null @@ -1,67 +0,0 @@ -//========= Copyright Valve Corporation, All rights reserved. ============// -// -// Purpose: -// -// $NoKeywords: $ -//=============================================================================// - -#ifndef CSTEXTWINDOW_H -#define CSTEXTWINDOW_H -#ifdef _WIN32 -#pragma once -#endif - -#include "vguitextwindow.h" -#include - -//----------------------------------------------------------------------------- -// Purpose: displays the MOTD -//----------------------------------------------------------------------------- - -class CHL2MPTextWindow : public CTextWindow -{ -private: - DECLARE_CLASS_SIMPLE( CHL2MPTextWindow, CTextWindow ); - -public: - CHL2MPTextWindow(IViewPort *pViewPort); - virtual ~CHL2MPTextWindow(); - - virtual void Update(); - virtual void SetVisible(bool state); - virtual void ShowPanel( bool bShow ); - virtual void OnKeyCodePressed(vgui::KeyCode code); - -protected: - ButtonCode_t m_iScoreBoardKey; - - // Background panel ------------------------------------------------------- - -public: - virtual void PaintBackground(); - virtual void PerformLayout(); - virtual void ApplySchemeSettings( vgui::IScheme *pScheme ); - bool m_backgroundLayoutFinished; - - // End background panel --------------------------------------------------- -}; - -class CHL2MPSpectatorGUI : public CSpectatorGUI -{ -private: - DECLARE_CLASS_SIMPLE( CHL2MPSpectatorGUI, CSpectatorGUI ); - -public: - CHL2MPSpectatorGUI( IViewPort *pViewPort ); - - virtual void Update( void ); - virtual bool NeedsUpdate( void ); - -protected: - int m_nLastSpecMode; - CBaseEntity *m_nLastSpecTarget; -}; - - - -#endif // CSTEXTWINDOW_H diff --git a/sp/src/game/server/hl2/grenade_satchel.cpp b/sp/src/game/server/hl2/grenade_satchel.cpp deleted file mode 100644 index d8777f94..00000000 --- a/sp/src/game/server/hl2/grenade_satchel.cpp +++ /dev/null @@ -1,365 +0,0 @@ -//========= Copyright Valve Corporation, All rights reserved. ============// -// -// Purpose: -// -// $NoKeywords: $ -// -//=============================================================================// - -#include "cbase.h" -#include "grenade_satchel.h" -#include "player.h" -#include "soundenvelope.h" -#include "engine/IEngineSound.h" - -// memdbgon must be the last include file in a .cpp file!!! -#include "tier0/memdbgon.h" - -ConVar sk_plr_dmg_satchel ( "sk_plr_dmg_satchel","0"); -ConVar sk_npc_dmg_satchel ( "sk_npc_dmg_satchel","0"); -ConVar sk_satchel_radius ( "sk_satchel_radius","0"); - -BEGIN_DATADESC( CSatchelCharge ) - - DEFINE_SOUNDPATCH( m_soundSlide ), - - DEFINE_FIELD( m_flSlideVolume, FIELD_FLOAT ), - DEFINE_FIELD( m_flNextBounceSoundTime, FIELD_TIME ), - DEFINE_FIELD( m_bInAir, FIELD_BOOLEAN ), - DEFINE_FIELD( m_vLastPosition, FIELD_POSITION_VECTOR ), - DEFINE_FIELD( m_pMyWeaponSLAM, FIELD_CLASSPTR ), - DEFINE_FIELD( m_bIsAttached, FIELD_BOOLEAN ), - - // Function Pointers - DEFINE_FUNCTION( SatchelTouch ), - DEFINE_FUNCTION( SatchelThink ), - DEFINE_FUNCTION( SatchelUse ), - -END_DATADESC() - -LINK_ENTITY_TO_CLASS( npc_satchel, CSatchelCharge ); - -//========================================================= -// Deactivate - do whatever it is we do to an orphaned -// satchel when we don't want it in the world anymore. -//========================================================= -void CSatchelCharge::Deactivate( void ) -{ - AddSolidFlags( FSOLID_NOT_SOLID ); - UTIL_Remove( this ); -} - - -void CSatchelCharge::Spawn( void ) -{ - Precache( ); - // motor - SetMoveType( MOVETYPE_FLYGRAVITY, MOVECOLLIDE_FLY_BOUNCE ); - SetSolid( SOLID_BBOX ); - SetCollisionGroup( COLLISION_GROUP_PROJECTILE ); - SetModel( "models/Weapons/w_slam.mdl" ); - - UTIL_SetSize(this, Vector( -6, -6, -2), Vector(6, 6, 2)); - - SetTouch( SatchelTouch ); - SetUse( SatchelUse ); - SetThink( SatchelThink ); - SetNextThink( gpGlobals->curtime + 0.1f ); - - m_flDamage = sk_plr_dmg_satchel.GetFloat(); - m_DmgRadius = sk_satchel_radius.GetFloat(); - m_takedamage = DAMAGE_YES; - m_iHealth = 1; - - SetGravity( UTIL_ScaleForGravity( 560 ) ); // slightly lower gravity - SetFriction( 1.0 ); - SetSequence( 1 ); - - m_bIsAttached = false; - m_bInAir = true; - m_flSlideVolume = -1.0; - m_flNextBounceSoundTime = 0; - - m_vLastPosition = vec3_origin; - - InitSlideSound(); -} - -//----------------------------------------------------------------------------- - -void CSatchelCharge::InitSlideSound(void) -{ - CSoundEnvelopeController &controller = CSoundEnvelopeController::GetController(); - CPASAttenuationFilter filter( this ); - m_soundSlide = controller.SoundCreate( filter, entindex(), CHAN_STATIC, "SatchelCharge.Slide", ATTN_NORM ); -} - -//----------------------------------------------------------------------------- -// Purpose: -// Input : -// Output : -//----------------------------------------------------------------------------- -void CSatchelCharge::KillSlideSound(void) -{ - CSoundEnvelopeController &controller = CSoundEnvelopeController::GetController(); - controller.CommandClear( m_soundSlide ); - controller.SoundFadeOut( m_soundSlide, 0.0 ); -} - -//----------------------------------------------------------------------------- -// Purpose: -// Input : -// Output : -//----------------------------------------------------------------------------- -void CSatchelCharge::SatchelUse( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value ) -{ - KillSlideSound(); - SetThink( Detonate ); - SetNextThink( gpGlobals->curtime ); -} - -//----------------------------------------------------------------------------- -// Purpose: -// Input : -// Output : -//----------------------------------------------------------------------------- -void CSatchelCharge::SatchelTouch( CBaseEntity *pOther ) -{ - Assert( pOther ); - if ( !pOther->IsSolid() ) - return; - - // If successfully thrown and touching the - // NPC that released this grenade, pick it up - if ( pOther == GetThrower() && GetOwnerEntity() == NULL ) - { - CBasePlayer *pPlayer = ToBasePlayer( m_pMyWeaponSLAM->GetOwner() ); - if (pPlayer) - { - // Give the player ammo - pPlayer->GiveAmmo(1, m_pMyWeaponSLAM->m_iSecondaryAmmoType); - - CPASAttenuationFilter filter( pPlayer, "SatchelCharge.Pickup" ); - EmitSound( filter, pPlayer->entindex(), "SatchelCharge.Pickup" ); - - m_bIsLive = false; - - // Take weapon out of detonate mode if necessary - if (!m_pMyWeaponSLAM->AnyUndetonatedCharges()) - { - m_pMyWeaponSLAM->m_bDetonatorArmed = false; - m_pMyWeaponSLAM->m_bNeedDetonatorHolster = true; - - // Put detonator away right away - m_pMyWeaponSLAM->SetWeaponIdleTime( gpGlobals->curtime ); - } - - // Kill any sliding sound - KillSlideSound(); - - // Remove satchel charge from world - UTIL_Remove( this ); - return; - } - - } - - StudioFrameAdvance( ); - - // Is it attached to a wall? - if (m_bIsAttached) - { - return; - } - - SetGravity( 1 );// normal gravity now - - // HACKHACK - On ground isn't always set, so look for ground underneath - trace_t tr; - UTIL_TraceLine( GetAbsOrigin(), GetAbsOrigin() - Vector(0,0,10), MASK_SOLID_BRUSHONLY, this, COLLISION_GROUP_NONE, &tr ); - - if ( tr.fraction < 1.0 ) - { - // add a bit of static friction - SetAbsVelocity( GetAbsVelocity() * 0.85 ); - SetLocalAngularVelocity( GetLocalAngularVelocity() * 0.8 ); - } - - UpdateSlideSound(); - - if (m_bInAir) - { - BounceSound(); - m_bInAir = false; - } - -} - -void CSatchelCharge::UpdateSlideSound( void ) -{ - if (!m_soundSlide) - { - return; - } - - float volume = GetAbsVelocity().Length2D()/1000; - if (volume < 0.01 && m_soundSlide) - { - KillSlideSound(); - return; - } - // HACKHACK - On ground isn't always set, so look for ground underneath - trace_t tr; - UTIL_TraceLine( GetAbsOrigin(), GetAbsOrigin() - Vector(0,0,10), MASK_SOLID_BRUSHONLY, this, COLLISION_GROUP_NONE, &tr ); - - CSoundEnvelopeController &controller = CSoundEnvelopeController::GetController(); - - - if ( tr.fraction < 1.0 ) - { - if (m_flSlideVolume == -1.0) - { - controller.CommandClear( m_soundSlide ); - controller.Play( m_soundSlide, 1.0, 100 ); - m_flSlideVolume = 1.0; - } - else - { - float volume = GetAbsVelocity().Length()/1000; - if ( volume < m_flSlideVolume ) - { - m_flSlideVolume = volume; - controller.CommandClear( m_soundSlide ); - controller.SoundChangeVolume( m_soundSlide, volume, 0.1 ); - } - } - } - else - { - controller.CommandClear( m_soundSlide ); - controller.SoundChangeVolume( m_soundSlide, 0.0, 0.01 ); - m_flSlideVolume = -1.0; - m_bInAir = true; - return; - } -} - -void CSatchelCharge::SatchelThink( void ) -{ - // If attached resize so player can pick up off wall - if (m_bIsAttached) - { - UTIL_SetSize(this, Vector( -2, -2, -6), Vector(2, 2, 6)); - } - - UpdateSlideSound(); - - // See if I can lose my owner (has dropper moved out of way?) - // Want do this so owner can shoot the satchel charge - if (GetOwnerEntity()) - { - trace_t tr; - Vector vUpABit = GetAbsOrigin(); - vUpABit.z += 5.0; - - CBaseEntity* saveOwner = GetOwnerEntity(); - SetOwnerEntity( NULL ); - UTIL_TraceEntity( this, GetAbsOrigin(), vUpABit, MASK_SOLID, &tr ); - if ( tr.startsolid || tr.fraction != 1.0 ) - { - SetOwnerEntity( saveOwner ); - } - } - - // Bounce movement code gets this think stuck occasionally so check if I've - // succeeded in moving, otherwise kill my motions. - else if ((GetAbsOrigin() - m_vLastPosition).LengthSqr()<1) - { - SetAbsVelocity( vec3_origin ); - - QAngle angVel = GetLocalAngularVelocity(); - angVel.y = 0; - SetLocalAngularVelocity( angVel ); - - // Kill any remaining sound - KillSlideSound(); - - // Clear think function - SetThink(NULL); - return; - } - m_vLastPosition= GetAbsOrigin(); - - StudioFrameAdvance( ); - SetNextThink( gpGlobals->curtime + 0.1f ); - - if (!IsInWorld()) - { - // Kill any remaining sound - KillSlideSound(); - - UTIL_Remove( this ); - return; - } - - // Is it attached to a wall? - if (m_bIsAttached) - { - return; - } - - Vector vecNewVel = GetAbsVelocity(); - if (GetWaterLevel() == 3) - { - SetMoveType( MOVETYPE_FLY ); - vecNewVel *= 0.8; - vecNewVel.z += 8; - SetLocalAngularVelocity( GetLocalAngularVelocity() * 0.9 ); - } - else if (GetWaterLevel() == 0) - { - SetMoveType( MOVETYPE_FLYGRAVITY, MOVECOLLIDE_FLY_BOUNCE ); - } - else - { - vecNewVel.z -= 8; - } - SetAbsVelocity( vecNewVel ); -} - -void CSatchelCharge::Precache( void ) -{ - PrecacheModel("models/Weapons/w_slam.mdl"); - - PrecacheScriptSound( "SatchelCharge.Pickup" ); - PrecacheScriptSound( "SatchelCharge.Bounce" ); - - PrecacheScriptSound( "SatchelCharge.Slide" ); -} - -void CSatchelCharge::BounceSound( void ) -{ - if (gpGlobals->curtime > m_flNextBounceSoundTime) - { - EmitSound( "SatchelCharge.Bounce" ); - - m_flNextBounceSoundTime = gpGlobals->curtime + 0.1; - } -} - -//----------------------------------------------------------------------------- -// Purpose: Constructor -// Input : -// Output : -//----------------------------------------------------------------------------- -CSatchelCharge::CSatchelCharge(void) -{ - m_vLastPosition.Init(); - m_pMyWeaponSLAM = NULL; -} - -CSatchelCharge::~CSatchelCharge(void) -{ - CSoundEnvelopeController &controller = CSoundEnvelopeController::GetController(); - controller.SoundDestroy( m_soundSlide ); -} diff --git a/sp/src/game/server/hl2/grenade_satchel.h b/sp/src/game/server/hl2/grenade_satchel.h deleted file mode 100644 index d614dbcd..00000000 --- a/sp/src/game/server/hl2/grenade_satchel.h +++ /dev/null @@ -1,57 +0,0 @@ -//========= Copyright Valve Corporation, All rights reserved. ============// -// -// Purpose: Satchel Charge -// -// $Workfile: $ -// $Date: $ -// $NoKeywords: $ -//=============================================================================// - -#ifndef SATCHEL_H -#define SATCHEL_H - -#ifdef _WIN32 -#pragma once -#endif - - -#include "basegrenade_shared.h" -#include "hl2mp/weapon_slam.h" - -class CSoundPatch; - -class CSatchelCharge : public CBaseGrenade -{ -public: - DECLARE_CLASS( CSatchelCharge, CBaseGrenade ); - - void Spawn( void ); - void Precache( void ); - void BounceSound( void ); - void UpdateSlideSound( void ); - void KillSlideSound(void); - void SatchelTouch( CBaseEntity *pOther ); - void SatchelThink( void ); - void SatchelUse( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value ); - - CSoundPatch* m_soundSlide; - float m_flSlideVolume; - float m_flNextBounceSoundTime; - bool m_bInAir; - Vector m_vLastPosition; - -public: - CWeapon_SLAM* m_pMyWeaponSLAM; // Who shot me.. - bool m_bIsAttached; - void Deactivate( void ); - - CSatchelCharge(); - ~CSatchelCharge(); - - DECLARE_DATADESC(); - -private: - void InitSlideSound(void); -}; - -#endif //SATCHEL_H diff --git a/sp/src/game/server/hl2/grenade_tripmine.cpp b/sp/src/game/server/hl2/grenade_tripmine.cpp deleted file mode 100644 index 45ea1150..00000000 --- a/sp/src/game/server/hl2/grenade_tripmine.cpp +++ /dev/null @@ -1,266 +0,0 @@ -//========= Copyright Valve Corporation, All rights reserved. ============// -// -// Purpose: Implements the tripmine grenade. -// -// $NoKeywords: $ -//=============================================================================// - -#include "cbase.h" -#include "beam_shared.h" -#include "shake.h" -#include "grenade_tripmine.h" -#include "vstdlib/random.h" -#include "engine/IEngineSound.h" - -// memdbgon must be the last include file in a .cpp file!!! -#include "tier0/memdbgon.h" - -extern const char* g_pModelNameLaser; - -ConVar sk_plr_dmg_tripmine ( "sk_plr_dmg_tripmine","0"); -ConVar sk_npc_dmg_tripmine ( "sk_npc_dmg_tripmine","0"); -ConVar sk_tripmine_radius ( "sk_tripmine_radius","0"); - -LINK_ENTITY_TO_CLASS( npc_tripmine, CTripmineGrenade ); - -BEGIN_DATADESC( CTripmineGrenade ) - - DEFINE_FIELD( m_hOwner, FIELD_EHANDLE ), - DEFINE_FIELD( m_flPowerUp, FIELD_TIME ), - DEFINE_FIELD( m_vecDir, FIELD_VECTOR ), - DEFINE_FIELD( m_vecEnd, FIELD_POSITION_VECTOR ), - DEFINE_FIELD( m_flBeamLength, FIELD_FLOAT ), - DEFINE_FIELD( m_pBeam, FIELD_CLASSPTR ), - DEFINE_FIELD( m_posOwner, FIELD_POSITION_VECTOR ), - DEFINE_FIELD( m_angleOwner, FIELD_VECTOR ), - - // Function Pointers - DEFINE_FUNCTION( WarningThink ), - DEFINE_FUNCTION( PowerupThink ), - DEFINE_FUNCTION( BeamBreakThink ), - DEFINE_FUNCTION( DelayDeathThink ), - -END_DATADESC() - -CTripmineGrenade::CTripmineGrenade() -{ - m_vecDir.Init(); - m_vecEnd.Init(); - m_posOwner.Init(); - m_angleOwner.Init(); -} - -void CTripmineGrenade::Spawn( void ) -{ - Precache( ); - // motor - SetMoveType( MOVETYPE_FLY ); - SetSolid( SOLID_BBOX ); - AddSolidFlags( FSOLID_NOT_SOLID ); - SetModel( "models/Weapons/w_slam.mdl" ); - - - m_flCycle = 0; - m_nBody = 3; - m_flDamage = sk_plr_dmg_tripmine.GetFloat(); - m_DmgRadius = sk_tripmine_radius.GetFloat(); - - ResetSequenceInfo( ); - m_flPlaybackRate = 0; - - UTIL_SetSize(this, Vector( -4, -4, -2), Vector(4, 4, 2)); - - m_flPowerUp = gpGlobals->curtime + 2.0; - - SetThink( PowerupThink ); - SetNextThink( gpGlobals->curtime + 0.2 ); - - m_takedamage = DAMAGE_YES; - - m_iHealth = 1; - - EmitSound( "TripmineGrenade.Charge" ); - - // Tripmine sits at 90 on wall so rotate back to get m_vecDir - QAngle angles = GetLocalAngles(); - angles.x -= 90; - - AngleVectors( angles, &m_vecDir ); - m_vecEnd = GetLocalOrigin() + m_vecDir * 2048; -} - - -void CTripmineGrenade::Precache( void ) -{ - PrecacheModel("models/Weapons/w_slam.mdl"); - - PrecacheScriptSound( "TripmineGrenade.Charge" ); - PrecacheScriptSound( "TripmineGrenade.PowerUp" ); - PrecacheScriptSound( "TripmineGrenade.StopSound" ); - PrecacheScriptSound( "TripmineGrenade.Activate" ); - PrecacheScriptSound( "TripmineGrenade.ShootRope" ); - PrecacheScriptSound( "TripmineGrenade.Hook" ); -} - - -void CTripmineGrenade::WarningThink( void ) -{ - // set to power up - SetThink( PowerupThink ); - SetNextThink( gpGlobals->curtime + 1.0f ); -} - - -void CTripmineGrenade::PowerupThink( void ) -{ - if (gpGlobals->curtime > m_flPowerUp) - { - MakeBeam( ); - RemoveSolidFlags( FSOLID_NOT_SOLID ); - m_bIsLive = true; - - // play enabled sound - EmitSound( "TripmineGrenade.PowerUp" );; - } - SetNextThink( gpGlobals->curtime + 0.1f ); -} - - -void CTripmineGrenade::KillBeam( void ) -{ - if ( m_pBeam ) - { - UTIL_Remove( m_pBeam ); - m_pBeam = NULL; - } -} - - -void CTripmineGrenade::MakeBeam( void ) -{ - trace_t tr; - - UTIL_TraceLine( GetAbsOrigin(), m_vecEnd, MASK_SHOT, this, COLLISION_GROUP_NONE, &tr ); - - m_flBeamLength = tr.fraction; - - - - // If I hit a living thing, send the beam through me so it turns on briefly - // and then blows the living thing up - CBaseEntity *pEntity = tr.m_pEnt; - CBaseCombatCharacter *pBCC = ToBaseCombatCharacter( pEntity ); - - // Draw length is not the beam length if entity is in the way - float drawLength = tr.fraction; - if (pBCC) - { - SetOwnerEntity( pBCC ); - UTIL_TraceLine( GetAbsOrigin(), m_vecEnd, MASK_SHOT, this, COLLISION_GROUP_NONE, &tr ); - m_flBeamLength = tr.fraction; - SetOwnerEntity( NULL ); - - } - - // set to follow laser spot - SetThink( BeamBreakThink ); - - // Delay first think slightly so beam has time - // to appear if person right in front of it - SetNextThink( gpGlobals->curtime + 1.0f ); - - Vector vecTmpEnd = GetLocalOrigin() + m_vecDir * 2048 * drawLength; - - m_pBeam = CBeam::BeamCreate( g_pModelNameLaser, 1.0 ); - m_pBeam->PointEntInit( vecTmpEnd, this ); - m_pBeam->SetColor( 0, 214, 198 ); - m_pBeam->SetScrollRate( 25.6 ); - m_pBeam->SetBrightness( 64 ); -} - - -void CTripmineGrenade::BeamBreakThink( void ) -{ - // See if I can go solid yet (has dropper moved out of way?) - if (IsSolidFlagSet( FSOLID_NOT_SOLID )) - { - trace_t tr; - Vector vUpBit = GetAbsOrigin(); - vUpBit.z += 5.0; - - UTIL_TraceEntity( this, GetAbsOrigin(), vUpBit, MASK_SHOT, &tr ); - if ( !tr.startsolid && (tr.fraction == 1.0) ) - { - RemoveSolidFlags( FSOLID_NOT_SOLID ); - } - } - - trace_t tr; - - // NOT MASK_SHOT because we want only simple hit boxes - UTIL_TraceLine( GetAbsOrigin(), m_vecEnd, MASK_SOLID, this, COLLISION_GROUP_NONE, &tr ); - - // ALERT( at_console, "%f : %f\n", tr.flFraction, m_flBeamLength ); - - // respawn detect. - if ( !m_pBeam ) - { - MakeBeam( ); - if ( tr.m_pEnt ) - m_hOwner = tr.m_pEnt; // reset owner too - } - - - CBaseEntity *pEntity = tr.m_pEnt; - CBaseCombatCharacter *pBCC = ToBaseCombatCharacter( pEntity ); - - if (pBCC || fabs( m_flBeamLength - tr.fraction ) > 0.001) - { - m_iHealth = 0; - Event_Killed( CTakeDamageInfo( (CBaseEntity*)m_hOwner, this, 100, GIB_NORMAL ) ); - return; - } - - SetNextThink( gpGlobals->curtime + 0.1f ); -} - -int CTripmineGrenade::OnTakeDamage_Alive( const CTakeDamageInfo &info ) -{ - if (gpGlobals->curtime < m_flPowerUp && info.GetDamage() < m_iHealth) - { - // disable - // Create( "weapon_tripmine", GetLocalOrigin() + m_vecDir * 24, GetAngles() ); - SetThink( SUB_Remove ); - SetNextThink( gpGlobals->curtime + 0.1f ); - KillBeam(); - return FALSE; - } - return BaseClass::OnTakeDamage_Alive( info ); -} - -//----------------------------------------------------------------------------- -// Purpose: -// Input : -// Output : -//----------------------------------------------------------------------------- -void CTripmineGrenade::Event_Killed( const CTakeDamageInfo &info ) -{ - m_takedamage = DAMAGE_NO; - - SetThink( DelayDeathThink ); - SetNextThink( gpGlobals->curtime + 0.5 ); - - EmitSound( "TripmineGrenade.StopSound" ); -} - - -void CTripmineGrenade::DelayDeathThink( void ) -{ - KillBeam(); - trace_t tr; - UTIL_TraceLine ( GetAbsOrigin() + m_vecDir * 8, GetAbsOrigin() - m_vecDir * 64, MASK_SOLID, this, COLLISION_GROUP_NONE, & tr); - UTIL_ScreenShake( GetAbsOrigin(), 25.0, 150.0, 1.0, 750, SHAKE_START ); - - Explode( &tr, DMG_BLAST ); -} - diff --git a/sp/src/game/server/hl2/grenade_tripmine.h b/sp/src/game/server/hl2/grenade_tripmine.h deleted file mode 100644 index d905edb7..00000000 --- a/sp/src/game/server/hl2/grenade_tripmine.h +++ /dev/null @@ -1,55 +0,0 @@ -//========= Copyright Valve Corporation, All rights reserved. ============// -// -// Purpose: -// -// $NoKeywords: $ -//=============================================================================// - -#ifndef GRENADE_TRIPMINE_H -#define GRENADE_TRIPMINE_H -#ifdef _WIN32 -#pragma once -#endif - -#include "basegrenade_shared.h" - -class CBeam; - - -class CTripmineGrenade : public CBaseGrenade -{ -public: - DECLARE_CLASS( CTripmineGrenade, CBaseGrenade ); - - CTripmineGrenade(); - void Spawn( void ); - void Precache( void ); - - int OnTakeDamage_Alive( const CTakeDamageInfo &info ); - - void WarningThink( void ); - void PowerupThink( void ); - void BeamBreakThink( void ); - void DelayDeathThink( void ); - void Event_Killed( const CTakeDamageInfo &info ); - - void MakeBeam( void ); - void KillBeam( void ); - -public: - EHANDLE m_hOwner; - -private: - float m_flPowerUp; - Vector m_vecDir; - Vector m_vecEnd; - float m_flBeamLength; - - CBeam *m_pBeam; - Vector m_posOwner; - Vector m_angleOwner; - - DECLARE_DATADESC(); -}; - -#endif // GRENADE_TRIPMINE_H diff --git a/sp/src/game/server/hl2/hl2_player.cpp b/sp/src/game/server/hl2/hl2_player.cpp index e61519a3..1f15cc25 100644 --- a/sp/src/game/server/hl2/hl2_player.cpp +++ b/sp/src/game/server/hl2/hl2_player.cpp @@ -56,7 +56,6 @@ #include "physobj.h" #include "ai_network.h" #include "ai_node.h" -#include "weapon_physcannon.h" #include "saverestoretypes.h" #include "saverestore.h" #include "chaos.h" diff --git a/sp/src/game/server/hl2/weapon_slam.cpp b/sp/src/game/server/hl2/weapon_slam.cpp index 958282fe..f4d73e60 100644 --- a/sp/src/game/server/hl2/weapon_slam.cpp +++ b/sp/src/game/server/hl2/weapon_slam.cpp @@ -5,22 +5,623 @@ //=============================================================================// #include "cbase.h" -#include "basehlcombatweapon.h" +#include "basehlcombatweapon_shared.h" +#include "basegrenade_shared.h" #include "player.h" #include "gamerules.h" -#include "grenade_tripmine.h" -#include "grenade_satchel.h" +//#include "grenade_tripmine.h" +//#include "grenade_satchel.h" #include "entitylist.h" #include "weapon_slam.h" #include "npcevent.h" #include "in_buttons.h" +#include "soundenvelope.h" #include "engine/IEngineSound.h" +#include "beam_shared.h" +#include "shake.h" +#include "vstdlib/random.h" // memdbgon must be the last include file in a .cpp file!!! #include "tier0/memdbgon.h" #define SLAM_PRIMARY_VOLUME 450 +ConVar sk_plr_dmg_satchel ( "sk_plr_dmg_satchel","0"); +ConVar sk_npc_dmg_satchel("sk_npc_dmg_satchel", "0"); +ConVar sk_satchel_radius("sk_satchel_radius", "0"); + +extern const char* g_pModelNameLaser; + +ConVar sk_plr_dmg_tripmine("sk_plr_dmg_tripmine", "0"); +ConVar sk_npc_dmg_tripmine("sk_npc_dmg_tripmine", "0"); +ConVar sk_tripmine_radius("sk_tripmine_radius", "0"); + +LINK_ENTITY_TO_CLASS(npc_tripmine, CTripmineGrenade); + +BEGIN_DATADESC(CTripmineGrenade) + DEFINE_FIELD(m_hOwner, FIELD_EHANDLE), + DEFINE_FIELD(m_flPowerUp, FIELD_TIME), + DEFINE_FIELD(m_vecDir, FIELD_VECTOR), + DEFINE_FIELD(m_vecEnd, FIELD_POSITION_VECTOR), + DEFINE_FIELD(m_flBeamLength, FIELD_FLOAT), + DEFINE_FIELD(m_pBeam, FIELD_CLASSPTR), + DEFINE_FIELD(m_posOwner, FIELD_POSITION_VECTOR), + DEFINE_FIELD(m_angleOwner, FIELD_VECTOR), + // Function Pointers + DEFINE_THINKFUNC(WarningThink), + DEFINE_THINKFUNC(PowerupThink), + DEFINE_THINKFUNC(BeamBreakThink), + DEFINE_THINKFUNC(DelayDeathThink), +END_DATADESC() + +CTripmineGrenade::CTripmineGrenade() +{ + m_vecDir.Init(); + m_vecEnd.Init(); + m_posOwner.Init(); + m_angleOwner.Init(); +} + +void CTripmineGrenade::Spawn(void) +{ + Precache(); + // motor + SetMoveType(MOVETYPE_FLY); + SetSolid(SOLID_BBOX); + AddSolidFlags(FSOLID_NOT_SOLID); + SetModel("models/Weapons/w_slam.mdl"); + + + //m_flCycle = 0; + SetCycle(0); + m_nBody = 3; + m_flDamage = sk_plr_dmg_tripmine.GetFloat(); + m_DmgRadius = sk_tripmine_radius.GetFloat(); + + ResetSequenceInfo(); + m_flPlaybackRate = 0; + + UTIL_SetSize(this, Vector(-4, -4, -2), Vector(4, 4, 2)); + + m_flPowerUp = gpGlobals->curtime + 2.0; + + SetThink(&CTripmineGrenade::PowerupThink); + SetNextThink(gpGlobals->curtime + 0.2); + + m_takedamage = DAMAGE_YES; + + m_iHealth = 1; + + EmitSound("TripmineGrenade.Charge"); + + // Tripmine sits at 90 on wall so rotate back to get m_vecDir + QAngle angles = GetLocalAngles(); + angles.x -= 90; + + AngleVectors(angles, &m_vecDir); + m_vecEnd = GetLocalOrigin() + m_vecDir * 2048; +} + + +void CTripmineGrenade::Precache(void) +{ + PrecacheModel("models/Weapons/w_slam.mdl"); + + PrecacheScriptSound("TripmineGrenade.Charge"); + PrecacheScriptSound("TripmineGrenade.PowerUp"); + PrecacheScriptSound("TripmineGrenade.StopSound"); + PrecacheScriptSound("TripmineGrenade.Activate"); + PrecacheScriptSound("TripmineGrenade.ShootRope"); + PrecacheScriptSound("TripmineGrenade.Hook"); +} + + +void CTripmineGrenade::WarningThink(void) +{ + // set to power up + SetThink(&CTripmineGrenade::PowerupThink); + SetNextThink(gpGlobals->curtime + 1.0f); +} + + +void CTripmineGrenade::PowerupThink(void) +{ + if (gpGlobals->curtime > m_flPowerUp) + { + MakeBeam(); + RemoveSolidFlags(FSOLID_NOT_SOLID); + m_bIsLive = true; + + // play enabled sound + EmitSound("TripmineGrenade.PowerUp");; + } + SetNextThink(gpGlobals->curtime + 0.1f); +} + + +void CTripmineGrenade::KillBeam(void) +{ + if (m_pBeam) + { + UTIL_Remove(m_pBeam); + m_pBeam = NULL; + } +} + + +void CTripmineGrenade::MakeBeam(void) +{ + trace_t tr; + + UTIL_TraceLine(GetAbsOrigin(), m_vecEnd, MASK_SHOT, this, COLLISION_GROUP_NONE, &tr); + + m_flBeamLength = tr.fraction; + + + + // If I hit a living thing, send the beam through me so it turns on briefly + // and then blows the living thing up + CBaseEntity *pEntity = tr.m_pEnt; + CBaseCombatCharacter *pBCC = ToBaseCombatCharacter(pEntity); + + // Draw length is not the beam length if entity is in the way + float drawLength = tr.fraction; + if (pBCC) + { + SetOwnerEntity(pBCC); + UTIL_TraceLine(GetAbsOrigin(), m_vecEnd, MASK_SHOT, this, COLLISION_GROUP_NONE, &tr); + m_flBeamLength = tr.fraction; + SetOwnerEntity(NULL); + + } + + // set to follow laser spot + SetThink(&CTripmineGrenade::BeamBreakThink); + + // Delay first think slightly so beam has time + // to appear if person right in front of it + SetNextThink(gpGlobals->curtime + 1.0f); + + Vector vecTmpEnd = GetLocalOrigin() + m_vecDir * 2048 * drawLength; + + m_pBeam = CBeam::BeamCreate(g_pModelNameLaser, 1.0); + m_pBeam->PointEntInit(vecTmpEnd, this); + m_pBeam->SetColor(0, 214, 198); + m_pBeam->SetScrollRate(25.6); + m_pBeam->SetBrightness(64); +} + + +void CTripmineGrenade::BeamBreakThink(void) +{ + // See if I can go solid yet (has dropper moved out of way?) + if (IsSolidFlagSet(FSOLID_NOT_SOLID)) + { + trace_t tr; + Vector vUpBit = GetAbsOrigin(); + vUpBit.z += 5.0; + + UTIL_TraceEntity(this, GetAbsOrigin(), vUpBit, MASK_SHOT, &tr); + if (!tr.startsolid && (tr.fraction == 1.0)) + { + RemoveSolidFlags(FSOLID_NOT_SOLID); + } + } + + trace_t tr; + + // NOT MASK_SHOT because we want only simple hit boxes + UTIL_TraceLine(GetAbsOrigin(), m_vecEnd, MASK_SOLID, this, COLLISION_GROUP_NONE, &tr); + + // ALERT( at_console, "%f : %f\n", tr.flFraction, m_flBeamLength ); + + // respawn detect. + if (!m_pBeam) + { + MakeBeam(); + if (tr.m_pEnt) + m_hOwner = tr.m_pEnt; // reset owner too + } + + + CBaseEntity *pEntity = tr.m_pEnt; + CBaseCombatCharacter *pBCC = ToBaseCombatCharacter(pEntity); + + if (pBCC || fabs(m_flBeamLength - tr.fraction) > 0.001) + { + m_iHealth = 0; + Event_Killed(CTakeDamageInfo((CBaseEntity*)m_hOwner, this, 100, GIB_NORMAL)); + return; + } + + SetNextThink(gpGlobals->curtime + 0.1f); +} + +int CTripmineGrenade::OnTakeDamage_Alive(const CTakeDamageInfo &info) +{ + if (gpGlobals->curtime < m_flPowerUp && info.GetDamage() < m_iHealth) + { + // disable + // Create( "weapon_tripmine", GetLocalOrigin() + m_vecDir * 24, GetAngles() ); + SetThink(&CTripmineGrenade::SUB_Remove); + SetNextThink(gpGlobals->curtime + 0.1f); + KillBeam(); + //return false; + } + return false;// BaseClass::OnTakeDamage_Alive(info); +} + +//----------------------------------------------------------------------------- +// Purpose: +// Input : +// Output : +//----------------------------------------------------------------------------- +void CTripmineGrenade::Event_Killed(const CTakeDamageInfo &info) +{ + m_takedamage = DAMAGE_NO; + + SetThink(&CTripmineGrenade::DelayDeathThink); + SetNextThink(gpGlobals->curtime + 0.5); + + EmitSound("TripmineGrenade.StopSound"); +} + + +void CTripmineGrenade::DelayDeathThink(void) +{ + KillBeam(); + trace_t tr; + UTIL_TraceLine(GetAbsOrigin() + m_vecDir * 8, GetAbsOrigin() - m_vecDir * 64, MASK_SOLID, this, COLLISION_GROUP_NONE, &tr); + UTIL_ScreenShake(GetAbsOrigin(), 25.0, 150.0, 1.0, 750, SHAKE_START); + + Explode(&tr, DMG_BLAST); +} + +BEGIN_DATADESC(CSatchelCharge) + +DEFINE_SOUNDPATCH(m_soundSlide), + +DEFINE_FIELD(m_flSlideVolume, FIELD_FLOAT), +DEFINE_FIELD(m_flNextBounceSoundTime, FIELD_TIME), +DEFINE_FIELD(m_bInAir, FIELD_BOOLEAN), +DEFINE_FIELD(m_vLastPosition, FIELD_POSITION_VECTOR), +DEFINE_FIELD(m_pMyWeaponSLAM, FIELD_CLASSPTR), +DEFINE_FIELD(m_bIsAttached, FIELD_BOOLEAN), + +// Function Pointers +DEFINE_ENTITYFUNC(SatchelTouch), +DEFINE_THINKFUNC(SatchelThink), +DEFINE_USEFUNC(SatchelUse), + +END_DATADESC() + +LINK_ENTITY_TO_CLASS(npc_satchel, CSatchelCharge); + +//========================================================= +// Deactivate - do whatever it is we do to an orphaned +// satchel when we don't want it in the world anymore. +//========================================================= +void CSatchelCharge::Deactivate(void) +{ + AddSolidFlags(FSOLID_NOT_SOLID); + UTIL_Remove(this); +} + + +void CSatchelCharge::Spawn(void) +{ + Precache(); + // motor + SetMoveType(MOVETYPE_FLYGRAVITY, MOVECOLLIDE_FLY_BOUNCE); + SetSolid(SOLID_BBOX); + SetCollisionGroup(COLLISION_GROUP_PROJECTILE); + SetModel("models/Weapons/w_slam.mdl"); + + UTIL_SetSize(this, Vector(-6, -6, -2), Vector(6, 6, 2)); + + SetTouch(&CSatchelCharge::SatchelTouch); + SetUse(&CSatchelCharge::SatchelUse); + SetThink(&CSatchelCharge::SatchelThink); + SetNextThink(gpGlobals->curtime + 0.1f); + + m_flDamage = sk_plr_dmg_satchel.GetFloat(); + m_DmgRadius = sk_satchel_radius.GetFloat(); + m_takedamage = DAMAGE_YES; + m_iHealth = 1; + + SetGravity(UTIL_ScaleForGravity(560)); // slightly lower gravity + SetFriction(1.0); + SetSequence(1); + + m_bIsAttached = false; + m_bInAir = true; + m_flSlideVolume = -1.0; + m_flNextBounceSoundTime = 0; + + m_vLastPosition = vec3_origin; + + InitSlideSound(); +} + +//----------------------------------------------------------------------------- + +void CSatchelCharge::InitSlideSound(void) +{ + CSoundEnvelopeController &controller = CSoundEnvelopeController::GetController(); + CPASAttenuationFilter filter(this); + m_soundSlide = controller.SoundCreate(filter, entindex(), CHAN_STATIC, "SatchelCharge.Slide", ATTN_NORM); +} + +//----------------------------------------------------------------------------- +// Purpose: +// Input : +// Output : +//----------------------------------------------------------------------------- +void CSatchelCharge::KillSlideSound(void) +{ + CSoundEnvelopeController &controller = CSoundEnvelopeController::GetController(); + controller.CommandClear(m_soundSlide); + controller.SoundFadeOut(m_soundSlide, 0.0); +} + +//----------------------------------------------------------------------------- +// Purpose: +// Input : +// Output : +//----------------------------------------------------------------------------- +void CSatchelCharge::SatchelUse(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value) +{ + KillSlideSound(); + SetThink(&CSatchelCharge::Detonate); + SetNextThink(gpGlobals->curtime); +} + +//----------------------------------------------------------------------------- +// Purpose: +// Input : +// Output : +//----------------------------------------------------------------------------- +void CSatchelCharge::SatchelTouch(CBaseEntity *pOther) +{ + Assert(pOther); + if (!pOther->IsSolid()) + return; + + // If successfully thrown and touching the + // NPC that released this grenade, pick it up + if (pOther == GetThrower() && GetOwnerEntity() == NULL) + { + CBasePlayer *pPlayer = ToBasePlayer(m_pMyWeaponSLAM->GetOwner()); + if (pPlayer) + { + // Give the player ammo + pPlayer->GiveAmmo(1, m_pMyWeaponSLAM->m_iSecondaryAmmoType); + + CPASAttenuationFilter filter(pPlayer, "SatchelCharge.Pickup"); + EmitSound(filter, pPlayer->entindex(), "SatchelCharge.Pickup"); + + m_bIsLive = false; + + // Take weapon out of detonate mode if necessary + if (!m_pMyWeaponSLAM->AnyUndetonatedCharges()) + { + m_pMyWeaponSLAM->m_bDetonatorArmed = false; + m_pMyWeaponSLAM->m_bNeedDetonatorHolster = true; + + // Put detonator away right away + m_pMyWeaponSLAM->SetWeaponIdleTime(gpGlobals->curtime); + } + + // Kill any sliding sound + KillSlideSound(); + + // Remove satchel charge from world + UTIL_Remove(this); + return; + } + + } + + StudioFrameAdvance(); + + // Is it attached to a wall? + if (m_bIsAttached) + { + return; + } + + SetGravity(1);// normal gravity now + + // HACKHACK - On ground isn't always set, so look for ground underneath + trace_t tr; + UTIL_TraceLine(GetAbsOrigin(), GetAbsOrigin() - Vector(0, 0, 10), MASK_SOLID_BRUSHONLY, this, COLLISION_GROUP_NONE, &tr); + + if (tr.fraction < 1.0) + { + // add a bit of static friction + SetAbsVelocity(GetAbsVelocity() * 0.85); + SetLocalAngularVelocity(GetLocalAngularVelocity() * 0.8); + } + + UpdateSlideSound(); + + if (m_bInAir) + { + BounceSound(); + m_bInAir = false; + } + +} + +void CSatchelCharge::UpdateSlideSound(void) +{ + if (!m_soundSlide) + { + return; + } + + float volume = GetAbsVelocity().Length2D() / 1000; + if (volume < 0.01 && m_soundSlide) + { + KillSlideSound(); + return; + } + // HACKHACK - On ground isn't always set, so look for ground underneath + trace_t tr; + UTIL_TraceLine(GetAbsOrigin(), GetAbsOrigin() - Vector(0, 0, 10), MASK_SOLID_BRUSHONLY, this, COLLISION_GROUP_NONE, &tr); + + CSoundEnvelopeController &controller = CSoundEnvelopeController::GetController(); + + + if (tr.fraction < 1.0) + { + if (m_flSlideVolume == -1.0) + { + controller.CommandClear(m_soundSlide); + controller.Play(m_soundSlide, 1.0, 100); + m_flSlideVolume = 1.0; + } + else + { + float volume = GetAbsVelocity().Length() / 1000; + if (volume < m_flSlideVolume) + { + m_flSlideVolume = volume; + controller.CommandClear(m_soundSlide); + controller.SoundChangeVolume(m_soundSlide, volume, 0.1); + } + } + } + else + { + controller.CommandClear(m_soundSlide); + controller.SoundChangeVolume(m_soundSlide, 0.0, 0.01); + m_flSlideVolume = -1.0; + m_bInAir = true; + return; + } +} + +void CSatchelCharge::SatchelThink(void) +{ + // If attached resize so player can pick up off wall + if (m_bIsAttached) + { + UTIL_SetSize(this, Vector(-2, -2, -6), Vector(2, 2, 6)); + } + + UpdateSlideSound(); + + // See if I can lose my owner (has dropper moved out of way?) + // Want do this so owner can shoot the satchel charge + if (GetOwnerEntity()) + { + trace_t tr; + Vector vUpABit = GetAbsOrigin(); + vUpABit.z += 5.0; + + CBaseEntity* saveOwner = GetOwnerEntity(); + SetOwnerEntity(NULL); + UTIL_TraceEntity(this, GetAbsOrigin(), vUpABit, MASK_SOLID, &tr); + if (tr.startsolid || tr.fraction != 1.0) + { + SetOwnerEntity(saveOwner); + } + } + + // Bounce movement code gets this think stuck occasionally so check if I've + // succeeded in moving, otherwise kill my motions. + else if ((GetAbsOrigin() - m_vLastPosition).LengthSqr()<1) + { + SetAbsVelocity(vec3_origin); + + QAngle angVel = GetLocalAngularVelocity(); + angVel.y = 0; + SetLocalAngularVelocity(angVel); + + // Kill any remaining sound + KillSlideSound(); + + // Clear think function + SetThink(NULL); + return; + } + m_vLastPosition = GetAbsOrigin(); + + StudioFrameAdvance(); + SetNextThink(gpGlobals->curtime + 0.1f); + + if (!IsInWorld()) + { + // Kill any remaining sound + KillSlideSound(); + + UTIL_Remove(this); + return; + } + + // Is it attached to a wall? + if (m_bIsAttached) + { + return; + } + + Vector vecNewVel = GetAbsVelocity(); + if (GetWaterLevel() == 3) + { + SetMoveType(MOVETYPE_FLY); + vecNewVel *= 0.8; + vecNewVel.z += 8; + SetLocalAngularVelocity(GetLocalAngularVelocity() * 0.9); + } + else if (GetWaterLevel() == 0) + { + SetMoveType(MOVETYPE_FLYGRAVITY, MOVECOLLIDE_FLY_BOUNCE); + } + else + { + vecNewVel.z -= 8; + } + SetAbsVelocity(vecNewVel); +} + +void CSatchelCharge::Precache(void) +{ + PrecacheModel("models/Weapons/w_slam.mdl"); + + PrecacheScriptSound("SatchelCharge.Pickup"); + PrecacheScriptSound("SatchelCharge.Bounce"); + + PrecacheScriptSound("SatchelCharge.Slide"); +} + +void CSatchelCharge::BounceSound(void) +{ + if (gpGlobals->curtime > m_flNextBounceSoundTime) + { + EmitSound("SatchelCharge.Bounce"); + + m_flNextBounceSoundTime = gpGlobals->curtime + 0.1; + } +} + +//----------------------------------------------------------------------------- +// Purpose: Constructor +// Input : +// Output : +//----------------------------------------------------------------------------- +CSatchelCharge::CSatchelCharge(void) +{ + m_vLastPosition.Init(); + m_pMyWeaponSLAM = NULL; +} + +CSatchelCharge::~CSatchelCharge(void) +{ + CSoundEnvelopeController &controller = CSoundEnvelopeController::GetController(); + controller.SoundDestroy(m_soundSlide); +} + BEGIN_DATADESC( CWeapon_SLAM ) DEFINE_FIELD( m_tSlamState, FIELD_INTEGER ), @@ -35,8 +636,8 @@ BEGIN_DATADESC( CWeapon_SLAM ) DEFINE_FIELD( m_flWallSwitchTime, FIELD_TIME ), // Function Pointers - DEFINE_FUNCTION( SLAMThink ), - DEFINE_FUNCTION( SlamTouch ), + DEFINE_THINKFUNC(SLAMThink), + DEFINE_USEFUNC(SlamTouch), END_DATADESC() @@ -97,7 +698,7 @@ void CWeapon_SLAM::Precache( void ) //------------------------------------------------------------------------------ void CWeapon_SLAM::SetPickupTouch( void ) { - SetTouch(SlamTouch); + SetTouch(&CWeapon_SLAM::SlamTouch); } //----------------------------------------------------------------------------- @@ -934,7 +1535,7 @@ bool CWeapon_SLAM::Deploy( void ) m_bDetonatorArmed = AnyUndetonatedCharges(); - SetThink( SLAMThink ); + SetThink(&CWeapon_SLAM::SLAMThink); SetNextThink( gpGlobals->curtime + 0.1f ); SetModel( GetViewModel() ); @@ -993,4 +1594,4 @@ CWeapon_SLAM::CWeapon_SLAM(void) m_bAttachTripmine = false; m_bNeedDetonatorDraw = false; m_bNeedDetonatorHolster = false; -} +} \ No newline at end of file diff --git a/sp/src/game/server/hl2/weapon_slam.h b/sp/src/game/server/hl2/weapon_slam.h index 8c0b473c..f175c31b 100644 --- a/sp/src/game/server/hl2/weapon_slam.h +++ b/sp/src/game/server/hl2/weapon_slam.h @@ -11,12 +11,13 @@ // $NoKeywords: $ //=============================================================================// -#ifndef WEAPONSLAM_H -#define WEAPONSLAM_H -#ifndef HL2MP - +//i don't know why but this has to be changed to 2. +#ifndef WEAPONSLAM2_H +#define WEAPONSLAM2_H +#pragma once #include "basegrenade_shared.h" -#include "basehlcombatweapon.h" +#include "basehlcombatweapon_shared.h" +class CSoundPatch;// enum SlamState_t { @@ -25,10 +26,12 @@ enum SlamState_t SLAM_SATCHEL_ATTACH, }; +class CBeam; + class CWeapon_SLAM : public CBaseHLCombatWeapon { public: - DECLARE_CLASS( CWeapon_SLAM, CBaseHLCombatWeapon ); + DECLARE_CLASS(CWeapon_SLAM, CBaseHLCombatWeapon); DECLARE_SERVERCLASS(); @@ -43,34 +46,34 @@ public: bool m_bAttachTripmine; float m_flWallSwitchTime; - void Spawn( void ); - void Precache( void ); + void Spawn(void); + void Precache(void); - int CapabilitiesGet( void ) { return bits_CAP_WEAPON_RANGE_ATTACK1; } - void PrimaryAttack( void ); - void SecondaryAttack( void ); - void WeaponIdle( void ); - void WeaponSwitch( void ); - void SLAMThink( void ); - - void SetPickupTouch( void ); - void SlamTouch( CBaseEntity *pOther ); // default weapon touch - void ItemPostFrame( void ); - bool Reload( void ); - void SetSlamState( SlamState_t newState ); + int CapabilitiesGet(void) { return bits_CAP_WEAPON_RANGE_ATTACK1; } + void PrimaryAttack(void); + void SecondaryAttack(void); + void WeaponIdle(void); + void WeaponSwitch(void); + void SLAMThink(void); + + void SetPickupTouch(void); + void SlamTouch(CBaseEntity *pOther); // default weapon touch + void ItemPostFrame(void); + bool Reload(void); + void SetSlamState(SlamState_t newState); bool CanAttachSLAM(void); // In position where can attach SLAM? bool AnyUndetonatedCharges(void); - void StartTripmineAttach( void ); - void TripmineAttach( void ); + void StartTripmineAttach(void); + void TripmineAttach(void); - void StartSatchelDetonate( void ); - void SatchelDetonate( void ); - void StartSatchelThrow( void ); - void StartSatchelAttach( void ); - void SatchelThrow( void ); - void SatchelAttach( void ); - bool Deploy( void ); - bool Holster( CBaseCombatWeapon *pSwitchingTo = NULL ); + void StartSatchelDetonate(void); + void SatchelDetonate(void); + void StartSatchelThrow(void); + void StartSatchelAttach(void); + void SatchelThrow(void); + void SatchelAttach(void); + bool Deploy(void); + bool Holster(CBaseCombatWeapon *pSwitchingTo = NULL); CWeapon_SLAM(); @@ -79,5 +82,71 @@ public: DECLARE_DATADESC(); }; -#endif //HL2MP -#endif //WEAPONSLAM_H +class CSatchelCharge : public CBaseGrenade +{ +public: + DECLARE_CLASS(CSatchelCharge, CBaseGrenade); + + void Spawn(void); + void Precache(void); + void BounceSound(void); + void UpdateSlideSound(void); + void KillSlideSound(void); + void SatchelTouch(CBaseEntity *pOther); + void SatchelThink(void); + void SatchelUse(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value); + + CSoundPatch* m_soundSlide; + float m_flSlideVolume; + float m_flNextBounceSoundTime; + bool m_bInAir; + Vector m_vLastPosition; + +public: + CWeapon_SLAM* m_pMyWeaponSLAM; // Who shot me.. + bool m_bIsAttached; + void Deactivate(void); + + CSatchelCharge(); + ~CSatchelCharge(); + + DECLARE_DATADESC(); + +private: + void InitSlideSound(void); +}; + +class CTripmineGrenade : public CBaseGrenade +{ +public: + DECLARE_CLASS(CTripmineGrenade, CBaseGrenade); + + CTripmineGrenade(); + void Spawn(void); + void Precache(void); + + int OnTakeDamage_Alive(const CTakeDamageInfo &info); + + void WarningThink(void); + void PowerupThink(void); + void BeamBreakThink(void); + void DelayDeathThink(void); + void Event_Killed(const CTakeDamageInfo &info); + + void MakeBeam(void); + void KillBeam(void); + + EHANDLE m_hOwner; + + float m_flPowerUp; + Vector m_vecDir; + Vector m_vecEnd; + float m_flBeamLength; + + CBeam *m_pBeam; + Vector m_posOwner; + Vector m_angleOwner; + + DECLARE_DATADESC(); +}; +#endif //WEAPONSLAM2_H diff --git a/sp/src/game/server/hl2mp/grenade_satchel.cpp b/sp/src/game/server/hl2mp/grenade_satchel.cpp deleted file mode 100644 index 9b304ad8..00000000 --- a/sp/src/game/server/hl2mp/grenade_satchel.cpp +++ /dev/null @@ -1,217 +0,0 @@ -//========= Copyright Valve Corporation, All rights reserved. ============// -// -// Purpose: -// -// $NoKeywords: $ -// -//=============================================================================// - -#include "cbase.h" -#include "player.h" -#include "soundenvelope.h" -#include "engine/IEngineSound.h" -#include "explode.h" -#include "Sprite.h" -#include "grenade_satchel.h" - -// memdbgon must be the last include file in a .cpp file!!! -#include "tier0/memdbgon.h" - -#define SLAM_SPRITE "sprites/redglow1.vmt" - -ConVar sk_plr_dmg_satchel ( "sk_plr_dmg_satchel","0"); -ConVar sk_npc_dmg_satchel ( "sk_npc_dmg_satchel","0"); -ConVar sk_satchel_radius ( "sk_satchel_radius","0"); - -BEGIN_DATADESC( CSatchelCharge ) - - DEFINE_FIELD( m_flNextBounceSoundTime, FIELD_TIME ), - DEFINE_FIELD( m_bInAir, FIELD_BOOLEAN ), - DEFINE_FIELD( m_vLastPosition, FIELD_POSITION_VECTOR ), - DEFINE_FIELD( m_pMyWeaponSLAM, FIELD_CLASSPTR ), - DEFINE_FIELD( m_bIsAttached, FIELD_BOOLEAN ), - - // Function Pointers - DEFINE_THINKFUNC( SatchelThink ), - - // Inputs - DEFINE_INPUTFUNC( FIELD_VOID, "Explode", InputExplode), - -END_DATADESC() - -LINK_ENTITY_TO_CLASS( npc_satchel, CSatchelCharge ); - -//========================================================= -// Deactivate - do whatever it is we do to an orphaned -// satchel when we don't want it in the world anymore. -//========================================================= -void CSatchelCharge::Deactivate( void ) -{ - AddSolidFlags( FSOLID_NOT_SOLID ); - UTIL_Remove( this ); - - if ( m_hGlowSprite != NULL ) - { - UTIL_Remove( m_hGlowSprite ); - m_hGlowSprite = NULL; - } -} - - -void CSatchelCharge::Spawn( void ) -{ - Precache( ); - SetModel( "models/Weapons/w_slam.mdl" ); - - VPhysicsInitNormal( SOLID_BBOX, GetSolidFlags() | FSOLID_TRIGGER, false ); - SetMoveType( MOVETYPE_VPHYSICS ); - - SetCollisionGroup( COLLISION_GROUP_WEAPON ); - - UTIL_SetSize(this, Vector( -6, -6, -2), Vector(6, 6, 2)); - - SetThink( &CSatchelCharge::SatchelThink ); - SetNextThink( gpGlobals->curtime + 0.1f ); - - m_flDamage = sk_plr_dmg_satchel.GetFloat(); - m_DmgRadius = sk_satchel_radius.GetFloat(); - m_takedamage = DAMAGE_YES; - m_iHealth = 1; - - SetGravity( UTIL_ScaleForGravity( 560 ) ); // slightly lower gravity - SetFriction( 1.0 ); - SetSequence( 1 ); - SetDamage( 150 ); - - m_bIsAttached = false; - m_bInAir = true; - m_flNextBounceSoundTime = 0; - - m_vLastPosition = vec3_origin; - - m_hGlowSprite = NULL; - CreateEffects(); -} - -//----------------------------------------------------------------------------- -// Purpose: Start up any effects for us -//----------------------------------------------------------------------------- -void CSatchelCharge::CreateEffects( void ) -{ - // Only do this once - if ( m_hGlowSprite != NULL ) - return; - - // Create a blinking light to show we're an active SLAM - m_hGlowSprite = CSprite::SpriteCreate( SLAM_SPRITE, GetAbsOrigin(), false ); - m_hGlowSprite->SetAttachment( this, 0 ); - m_hGlowSprite->SetTransparency( kRenderTransAdd, 255, 255, 255, 255, kRenderFxStrobeFast ); - m_hGlowSprite->SetBrightness( 255, 1.0f ); - m_hGlowSprite->SetScale( 0.2f, 0.5f ); - m_hGlowSprite->TurnOn(); -} - -//----------------------------------------------------------------------------- -// Purpose: -// Input : -// Output : -//----------------------------------------------------------------------------- -void CSatchelCharge::InputExplode( inputdata_t &inputdata ) -{ - ExplosionCreate( GetAbsOrigin() + Vector( 0, 0, 16 ), GetAbsAngles(), GetThrower(), GetDamage(), 200, - SF_ENVEXPLOSION_NOSPARKS | SF_ENVEXPLOSION_NODLIGHTS | SF_ENVEXPLOSION_NOSMOKE, 0.0f, this); - - UTIL_Remove( this ); -} - - -void CSatchelCharge::SatchelThink( void ) -{ - // If attached resize so player can pick up off wall - if (m_bIsAttached) - { - UTIL_SetSize(this, Vector( -2, -2, -6), Vector(2, 2, 6)); - } - - // See if I can lose my owner (has dropper moved out of way?) - // Want do this so owner can shoot the satchel charge - if (GetOwnerEntity()) - { - trace_t tr; - Vector vUpABit = GetAbsOrigin(); - vUpABit.z += 5.0; - - CBaseEntity* saveOwner = GetOwnerEntity(); - SetOwnerEntity( NULL ); - UTIL_TraceEntity( this, GetAbsOrigin(), vUpABit, MASK_SOLID, &tr ); - if ( tr.startsolid || tr.fraction != 1.0 ) - { - SetOwnerEntity( saveOwner ); - } - } - - // Bounce movement code gets this think stuck occasionally so check if I've - // succeeded in moving, otherwise kill my motions. - else if ((GetAbsOrigin() - m_vLastPosition).LengthSqr()<1) - { - SetAbsVelocity( vec3_origin ); - - QAngle angVel = GetLocalAngularVelocity(); - angVel.y = 0; - SetLocalAngularVelocity( angVel ); - - // Clear think function - SetThink(NULL); - return; - } - m_vLastPosition= GetAbsOrigin(); - - StudioFrameAdvance( ); - SetNextThink( gpGlobals->curtime + 0.1f ); - - if (!IsInWorld()) - { - UTIL_Remove( this ); - return; - } - - // Is it attached to a wall? - if (m_bIsAttached) - { - return; - } -} - -void CSatchelCharge::Precache( void ) -{ - PrecacheModel("models/Weapons/w_slam.mdl"); - PrecacheModel(SLAM_SPRITE); -} - -void CSatchelCharge::BounceSound( void ) -{ - if (gpGlobals->curtime > m_flNextBounceSoundTime) - { - m_flNextBounceSoundTime = gpGlobals->curtime + 0.1; - } -} - -//----------------------------------------------------------------------------- -// Purpose: Constructor -// Input : -// Output : -//----------------------------------------------------------------------------- -CSatchelCharge::CSatchelCharge(void) -{ - m_vLastPosition.Init(); - m_pMyWeaponSLAM = NULL; -} - -CSatchelCharge::~CSatchelCharge(void) -{ - if ( m_hGlowSprite != NULL ) - { - UTIL_Remove( m_hGlowSprite ); - m_hGlowSprite = NULL; - } -} diff --git a/sp/src/game/server/hl2mp/grenade_satchel.h b/sp/src/game/server/hl2mp/grenade_satchel.h deleted file mode 100644 index 68d5d5a3..00000000 --- a/sp/src/game/server/hl2mp/grenade_satchel.h +++ /dev/null @@ -1,56 +0,0 @@ -//========= Copyright Valve Corporation, All rights reserved. ============// -// -// Purpose: Satchel Charge -// -// $Workfile: $ -// $Date: $ -// $NoKeywords: $ -//=============================================================================// - -#ifndef SATCHEL_H -#define SATCHEL_H - -#ifdef _WIN32 -#pragma once -#endif - -#include "basegrenade_shared.h" -#include "hl2mp/weapon_slam.h" - -class CSoundPatch; -class CSprite; - -class CSatchelCharge : public CBaseGrenade -{ -public: - DECLARE_CLASS( CSatchelCharge, CBaseGrenade ); - - void Spawn( void ); - void Precache( void ); - void BounceSound( void ); - void SatchelTouch( CBaseEntity *pOther ); - void SatchelThink( void ); - - // Input handlers - void InputExplode( inputdata_t &inputdata ); - - float m_flNextBounceSoundTime; - bool m_bInAir; - Vector m_vLastPosition; - -public: - CWeapon_SLAM* m_pMyWeaponSLAM; // Who shot me.. - bool m_bIsAttached; - void Deactivate( void ); - - CSatchelCharge(); - ~CSatchelCharge(); - - DECLARE_DATADESC(); - -private: - void CreateEffects( void ); - CHandle m_hGlowSprite; -}; - -#endif //SATCHEL_H diff --git a/sp/src/game/server/hl2mp/grenade_tripmine.cpp b/sp/src/game/server/hl2mp/grenade_tripmine.cpp deleted file mode 100644 index e14a929d..00000000 --- a/sp/src/game/server/hl2mp/grenade_tripmine.cpp +++ /dev/null @@ -1,276 +0,0 @@ -//========= Copyright Valve Corporation, All rights reserved. ============// -// -// Purpose: Implements the tripmine grenade. -// -// $NoKeywords: $ -//=============================================================================// - -#include "cbase.h" -#include "beam_shared.h" -#include "shake.h" -#include "grenade_tripmine.h" -#include "vstdlib/random.h" -#include "engine/IEngineSound.h" -#include "explode.h" - -// memdbgon must be the last include file in a .cpp file!!! -#include "tier0/memdbgon.h" - -extern const char* g_pModelNameLaser; - -ConVar sk_plr_dmg_tripmine ( "sk_plr_dmg_tripmine","0"); -ConVar sk_npc_dmg_tripmine ( "sk_npc_dmg_tripmine","0"); -ConVar sk_tripmine_radius ( "sk_tripmine_radius","0"); - -LINK_ENTITY_TO_CLASS( npc_tripmine, CTripmineGrenade ); - -BEGIN_DATADESC( CTripmineGrenade ) - - DEFINE_FIELD( m_hOwner, FIELD_EHANDLE ), - DEFINE_FIELD( m_flPowerUp, FIELD_TIME ), - DEFINE_FIELD( m_vecDir, FIELD_VECTOR ), - DEFINE_FIELD( m_vecEnd, FIELD_POSITION_VECTOR ), - DEFINE_FIELD( m_flBeamLength, FIELD_FLOAT ), - DEFINE_FIELD( m_pBeam, FIELD_CLASSPTR ), - DEFINE_FIELD( m_posOwner, FIELD_POSITION_VECTOR ), - DEFINE_FIELD( m_angleOwner, FIELD_VECTOR ), - - // Function Pointers - DEFINE_THINKFUNC( WarningThink ), - DEFINE_THINKFUNC( PowerupThink ), - DEFINE_THINKFUNC( BeamBreakThink ), - DEFINE_THINKFUNC( DelayDeathThink ), - -END_DATADESC() - -CTripmineGrenade::CTripmineGrenade() -{ - m_vecDir.Init(); - m_vecEnd.Init(); - m_posOwner.Init(); - m_angleOwner.Init(); -} - -void CTripmineGrenade::Spawn( void ) -{ - Precache( ); - // motor - SetMoveType( MOVETYPE_FLY ); - SetSolid( SOLID_BBOX ); - SetModel( "models/Weapons/w_slam.mdl" ); - - IPhysicsObject *pObject = VPhysicsInitNormal( SOLID_BBOX, GetSolidFlags() | FSOLID_TRIGGER, true ); - pObject->EnableMotion( false ); - SetCollisionGroup( COLLISION_GROUP_WEAPON ); - - SetCycle( 0.0f ); - m_nBody = 3; - m_flDamage = sk_plr_dmg_tripmine.GetFloat(); - m_DmgRadius = sk_tripmine_radius.GetFloat(); - - ResetSequenceInfo( ); - m_flPlaybackRate = 0; - - UTIL_SetSize(this, Vector( -4, -4, -2), Vector(4, 4, 2)); - - m_flPowerUp = gpGlobals->curtime + 2.0; - - SetThink( &CTripmineGrenade::PowerupThink ); - SetNextThink( gpGlobals->curtime + 0.2 ); - - m_takedamage = DAMAGE_YES; - - m_iHealth = 1; - - EmitSound( "TripmineGrenade.Place" ); - SetDamage ( 200 ); - - // Tripmine sits at 90 on wall so rotate back to get m_vecDir - QAngle angles = GetAbsAngles(); - angles.x -= 90; - - AngleVectors( angles, &m_vecDir ); - m_vecEnd = GetAbsOrigin() + m_vecDir * 2048; - - AddEffects( EF_NOSHADOW ); -} - - -void CTripmineGrenade::Precache( void ) -{ - PrecacheModel("models/Weapons/w_slam.mdl"); - - PrecacheScriptSound( "TripmineGrenade.Place" ); - PrecacheScriptSound( "TripmineGrenade.Activate" ); -} - - -void CTripmineGrenade::WarningThink( void ) -{ - // set to power up - SetThink( &CTripmineGrenade::PowerupThink ); - SetNextThink( gpGlobals->curtime + 1.0f ); -} - - -void CTripmineGrenade::PowerupThink( void ) -{ - if (gpGlobals->curtime > m_flPowerUp) - { - MakeBeam( ); - RemoveSolidFlags( FSOLID_NOT_SOLID ); - m_bIsLive = true; - - // play enabled sound - EmitSound( "TripmineGrenade.Activate" ); - } - SetNextThink( gpGlobals->curtime + 0.1f ); -} - - -void CTripmineGrenade::KillBeam( void ) -{ - if ( m_pBeam ) - { - UTIL_Remove( m_pBeam ); - m_pBeam = NULL; - } -} - - -void CTripmineGrenade::MakeBeam( void ) -{ - trace_t tr; - - UTIL_TraceLine( GetAbsOrigin(), m_vecEnd, MASK_SHOT, this, COLLISION_GROUP_NONE, &tr ); - - m_flBeamLength = tr.fraction; - - - - // If I hit a living thing, send the beam through me so it turns on briefly - // and then blows the living thing up - CBaseEntity *pEntity = tr.m_pEnt; - CBaseCombatCharacter *pBCC = ToBaseCombatCharacter( pEntity ); - - // Draw length is not the beam length if entity is in the way - float drawLength = tr.fraction; - if (pBCC) - { - SetOwnerEntity( pBCC ); - UTIL_TraceLine( GetAbsOrigin(), m_vecEnd, MASK_SHOT, this, COLLISION_GROUP_NONE, &tr ); - m_flBeamLength = tr.fraction; - SetOwnerEntity( NULL ); - - } - - // set to follow laser spot - SetThink( &CTripmineGrenade::BeamBreakThink ); - - // Delay first think slightly so beam has time - // to appear if person right in front of it - SetNextThink( gpGlobals->curtime + 1.0f ); - - Vector vecTmpEnd = GetLocalOrigin() + m_vecDir * 2048 * drawLength; - - m_pBeam = CBeam::BeamCreate( g_pModelNameLaser, 0.35 ); - m_pBeam->PointEntInit( vecTmpEnd, this ); - m_pBeam->SetColor( 255, 55, 52 ); - m_pBeam->SetScrollRate( 25.6 ); - m_pBeam->SetBrightness( 64 ); - - int beamAttach = LookupAttachment("beam_attach"); - m_pBeam->SetEndAttachment( beamAttach ); -} - - -void CTripmineGrenade::BeamBreakThink( void ) -{ - // See if I can go solid yet (has dropper moved out of way?) - if (IsSolidFlagSet( FSOLID_NOT_SOLID )) - { - trace_t tr; - Vector vUpBit = GetAbsOrigin(); - vUpBit.z += 5.0; - - UTIL_TraceEntity( this, GetAbsOrigin(), vUpBit, MASK_SHOT, &tr ); - if ( !tr.startsolid && (tr.fraction == 1.0) ) - { - RemoveSolidFlags( FSOLID_NOT_SOLID ); - } - } - - trace_t tr; - - // NOT MASK_SHOT because we want only simple hit boxes - UTIL_TraceLine( GetAbsOrigin(), m_vecEnd, MASK_SOLID, this, COLLISION_GROUP_NONE, &tr ); - - // ALERT( at_console, "%f : %f\n", tr.flFraction, m_flBeamLength ); - - // respawn detect. - if ( !m_pBeam ) - { - MakeBeam( ); - if ( tr.m_pEnt ) - m_hOwner = tr.m_pEnt; // reset owner too - } - - - CBaseEntity *pEntity = tr.m_pEnt; - CBaseCombatCharacter *pBCC = ToBaseCombatCharacter( pEntity ); - - if (pBCC || fabs( m_flBeamLength - tr.fraction ) > 0.001) - { - m_iHealth = 0; - Event_Killed( CTakeDamageInfo( (CBaseEntity*)m_hOwner, this, 100, GIB_NORMAL ) ); - return; - } - - SetNextThink( gpGlobals->curtime + 0.05f ); -} - -#if 0 // FIXME: OnTakeDamage_Alive() is no longer called now that base grenade derives from CBaseAnimating -int CTripmineGrenade::OnTakeDamage_Alive( const CTakeDamageInfo &info ) -{ - if (gpGlobals->curtime < m_flPowerUp && info.GetDamage() < m_iHealth) - { - // disable - // Create( "weapon_tripmine", GetLocalOrigin() + m_vecDir * 24, GetAngles() ); - SetThink( &CTripmineGrenade::SUB_Remove ); - SetNextThink( gpGlobals->curtime + 0.1f ); - KillBeam(); - return FALSE; - } - return BaseClass::OnTakeDamage_Alive( info ); -} -#endif - -//----------------------------------------------------------------------------- -// Purpose: -// Input : -// Output : -//----------------------------------------------------------------------------- -void CTripmineGrenade::Event_Killed( const CTakeDamageInfo &info ) -{ - m_takedamage = DAMAGE_NO; - - SetThink( &CTripmineGrenade::DelayDeathThink ); - SetNextThink( gpGlobals->curtime + 0.25 ); - - EmitSound( "TripmineGrenade.StopSound" ); -} - - -void CTripmineGrenade::DelayDeathThink( void ) -{ - KillBeam(); - trace_t tr; - UTIL_TraceLine ( GetAbsOrigin() + m_vecDir * 8, GetAbsOrigin() - m_vecDir * 64, MASK_SOLID, this, COLLISION_GROUP_NONE, & tr); - UTIL_ScreenShake( GetAbsOrigin(), 25.0, 150.0, 1.0, 750, SHAKE_START ); - - ExplosionCreate( GetAbsOrigin() + m_vecDir * 8, GetAbsAngles(), m_hOwner, GetDamage(), 200, - SF_ENVEXPLOSION_NOSPARKS | SF_ENVEXPLOSION_NODLIGHTS | SF_ENVEXPLOSION_NOSMOKE, 0.0f, this); - - UTIL_Remove( this ); -} - diff --git a/sp/src/game/server/hl2mp/grenade_tripmine.h b/sp/src/game/server/hl2mp/grenade_tripmine.h deleted file mode 100644 index e1887096..00000000 --- a/sp/src/game/server/hl2mp/grenade_tripmine.h +++ /dev/null @@ -1,56 +0,0 @@ -//========= Copyright Valve Corporation, All rights reserved. ============// -// -// Purpose: -// -// $NoKeywords: $ -//=============================================================================// - -#ifndef GRENADE_TRIPMINE_H -#define GRENADE_TRIPMINE_H -#ifdef _WIN32 -#pragma once -#endif - -#include "basegrenade_shared.h" - -class CBeam; - - -class CTripmineGrenade : public CBaseGrenade -{ -public: - DECLARE_CLASS( CTripmineGrenade, CBaseGrenade ); - - CTripmineGrenade(); - void Spawn( void ); - void Precache( void ); - -#if 0 // FIXME: OnTakeDamage_Alive() is no longer called now that base grenade derives from CBaseAnimating - int OnTakeDamage_Alive( const CTakeDamageInfo &info ); -#endif - void WarningThink( void ); - void PowerupThink( void ); - void BeamBreakThink( void ); - void DelayDeathThink( void ); - void Event_Killed( const CTakeDamageInfo &info ); - - void MakeBeam( void ); - void KillBeam( void ); - -public: - EHANDLE m_hOwner; - -private: - float m_flPowerUp; - Vector m_vecDir; - Vector m_vecEnd; - float m_flBeamLength; - - CBeam *m_pBeam; - Vector m_posOwner; - Vector m_angleOwner; - - DECLARE_DATADESC(); -}; - -#endif // GRENADE_TRIPMINE_H diff --git a/sp/src/game/server/hl2mp/hl2mp_bot_temp.cpp b/sp/src/game/server/hl2mp/hl2mp_bot_temp.cpp deleted file mode 100644 index 054eea40..00000000 --- a/sp/src/game/server/hl2mp/hl2mp_bot_temp.cpp +++ /dev/null @@ -1,435 +0,0 @@ -//========= Copyright Valve Corporation, All rights reserved. ============// -// -// Purpose: Basic BOT handling. -// -// $Workfile: $ -// $Date: $ -// -//----------------------------------------------------------------------------- -// $Log: $ -// -// $NoKeywords: $ -//=============================================================================// - - -#include "cbase.h" -#include "player.h" -#include "hl2mp_player.h" -#include "in_buttons.h" -#include "movehelper_server.h" - -void ClientPutInServer( edict_t *pEdict, const char *playername ); -void Bot_Think( CHL2MP_Player *pBot ); - -#ifdef DEBUG - -ConVar bot_forcefireweapon( "bot_forcefireweapon", "", 0, "Force bots with the specified weapon to fire." ); -ConVar bot_forceattack2( "bot_forceattack2", "0", 0, "When firing, use attack2." ); -ConVar bot_forceattackon( "bot_forceattackon", "0", 0, "When firing, don't tap fire, hold it down." ); -ConVar bot_flipout( "bot_flipout", "0", 0, "When on, all bots fire their guns." ); -ConVar bot_defend( "bot_defend", "0", 0, "Set to a team number, and that team will all keep their combat shields raised." ); -ConVar bot_changeclass( "bot_changeclass", "0", 0, "Force all bots to change to the specified class." ); -ConVar bot_zombie( "bot_zombie", "0", 0, "Brraaaaaiiiins." ); -static ConVar bot_mimic_yaw_offset( "bot_mimic_yaw_offset", "0", 0, "Offsets the bot yaw." ); -ConVar bot_attack( "bot_attack", "1", 0, "Shoot!" ); - -ConVar bot_sendcmd( "bot_sendcmd", "", 0, "Forces bots to send the specified command." ); - -ConVar bot_crouch( "bot_crouch", "0", 0, "Bot crouches" ); - -#ifdef NEXT_BOT -extern ConVar bot_mimic; -#else -ConVar bot_mimic( "bot_mimic", "0", 0, "Bot uses usercmd of player by index." ); -#endif - -static int BotNumber = 1; -static int g_iNextBotTeam = -1; -static int g_iNextBotClass = -1; - -typedef struct -{ - bool backwards; - - float nextturntime; - bool lastturntoright; - - float nextstrafetime; - float sidemove; - - QAngle forwardAngle; - QAngle lastAngles; - - float m_flJoinTeamTime; - int m_WantedTeam; - int m_WantedClass; -} botdata_t; - -static botdata_t g_BotData[ MAX_PLAYERS ]; - - -//----------------------------------------------------------------------------- -// Purpose: Create a new Bot and put it in the game. -// Output : Pointer to the new Bot, or NULL if there's no free clients. -//----------------------------------------------------------------------------- -CBasePlayer *BotPutInServer( bool bFrozen, int iTeam ) -{ - g_iNextBotTeam = iTeam; - - char botname[ 64 ]; - Q_snprintf( botname, sizeof( botname ), "Bot%02i", BotNumber ); - - // This is an evil hack, but we use it to prevent sv_autojointeam from kicking in. - - edict_t *pEdict = engine->CreateFakeClient( botname ); - - if (!pEdict) - { - Msg( "Failed to create Bot.\n"); - return NULL; - } - - // Allocate a CBasePlayer for the bot, and call spawn - //ClientPutInServer( pEdict, botname ); - CHL2MP_Player *pPlayer = ((CHL2MP_Player *)CBaseEntity::Instance( pEdict )); - pPlayer->ClearFlags(); - pPlayer->AddFlag( FL_CLIENT | FL_FAKECLIENT ); - - if ( bFrozen ) - pPlayer->AddEFlags( EFL_BOT_FROZEN ); - - BotNumber++; - - g_BotData[pPlayer->entindex()-1].m_WantedTeam = iTeam; - g_BotData[pPlayer->entindex()-1].m_flJoinTeamTime = gpGlobals->curtime + 0.3; - - return pPlayer; -} - -//----------------------------------------------------------------------------- -// Purpose: Run through all the Bots in the game and let them think. -//----------------------------------------------------------------------------- -void Bot_RunAll( void ) -{ - for ( int i = 1; i <= gpGlobals->maxClients; i++ ) - { - CHL2MP_Player *pPlayer = ToHL2MPPlayer( UTIL_PlayerByIndex( i ) ); - - if ( pPlayer && (pPlayer->GetFlags() & FL_FAKECLIENT) ) - { - Bot_Think( pPlayer ); - } - } -} - -bool RunMimicCommand( CUserCmd& cmd ) -{ - if ( bot_mimic.GetInt() <= 0 ) - return false; - - if ( bot_mimic.GetInt() > gpGlobals->maxClients ) - return false; - - - CBasePlayer *pPlayer = UTIL_PlayerByIndex( bot_mimic.GetInt() ); - if ( !pPlayer ) - return false; - - if ( !pPlayer->GetLastUserCommand() ) - return false; - - cmd = *pPlayer->GetLastUserCommand(); - cmd.viewangles[YAW] += bot_mimic_yaw_offset.GetFloat(); - - return true; -} - -//----------------------------------------------------------------------------- -// Purpose: Simulates a single frame of movement for a player -// Input : *fakeclient - -// *viewangles - -// forwardmove - -// sidemove - -// upmove - -// buttons - -// impulse - -// msec - -// Output : virtual void -//----------------------------------------------------------------------------- -static void RunPlayerMove( CHL2MP_Player *fakeclient, const QAngle& viewangles, float forwardmove, float sidemove, float upmove, unsigned short buttons, byte impulse, float frametime ) -{ - if ( !fakeclient ) - return; - - CUserCmd cmd; - - // Store off the globals.. they're gonna get whacked - float flOldFrametime = gpGlobals->frametime; - float flOldCurtime = gpGlobals->curtime; - - float flTimeBase = gpGlobals->curtime + gpGlobals->frametime - frametime; - fakeclient->SetTimeBase( flTimeBase ); - - Q_memset( &cmd, 0, sizeof( cmd ) ); - - if ( !RunMimicCommand( cmd ) && !bot_zombie.GetBool() ) - { - VectorCopy( viewangles, cmd.viewangles ); - cmd.forwardmove = forwardmove; - cmd.sidemove = sidemove; - cmd.upmove = upmove; - cmd.buttons = buttons; - cmd.impulse = impulse; - cmd.random_seed = random->RandomInt( 0, 0x7fffffff ); - } - - if( bot_crouch.GetInt() ) - cmd.buttons |= IN_DUCK; - - if ( bot_attack.GetBool() ) - cmd.buttons |= IN_ATTACK; - - MoveHelperServer()->SetHost( fakeclient ); - fakeclient->PlayerRunCommand( &cmd, MoveHelperServer() ); - - // save off the last good usercmd - fakeclient->SetLastUserCommand( cmd ); - - // Clear out any fixangle that has been set - fakeclient->pl.fixangle = FIXANGLE_NONE; - - // Restore the globals.. - gpGlobals->frametime = flOldFrametime; - gpGlobals->curtime = flOldCurtime; -} - -//----------------------------------------------------------------------------- -// Purpose: Run this Bot's AI for one frame. -//----------------------------------------------------------------------------- -void Bot_Think( CHL2MP_Player *pBot ) -{ - // Make sure we stay being a bot - pBot->AddFlag( FL_FAKECLIENT ); - - botdata_t *botdata = &g_BotData[ ENTINDEX( pBot->edict() ) - 1 ]; - - QAngle vecViewAngles; - float forwardmove = 0.0; - float sidemove = botdata->sidemove; - float upmove = 0.0; - unsigned short buttons = 0; - byte impulse = 0; - float frametime = gpGlobals->frametime; - - vecViewAngles = pBot->GetLocalAngles(); - - - // Create some random values - if ( pBot->IsAlive() && (pBot->GetSolid() == SOLID_BBOX) ) - { - trace_t trace; - - // Stop when shot - if ( !pBot->IsEFlagSet(EFL_BOT_FROZEN) ) - { - if ( pBot->m_iHealth == 100 ) - { - forwardmove = 600 * ( botdata->backwards ? -1 : 1 ); - if ( botdata->sidemove != 0.0f ) - { - forwardmove *= random->RandomFloat( 0.1, 1.0f ); - } - } - else - { - forwardmove = 0; - } - } - - // Only turn if I haven't been hurt - if ( !pBot->IsEFlagSet(EFL_BOT_FROZEN) && pBot->m_iHealth == 100 ) - { - Vector vecEnd; - Vector forward; - - QAngle angle; - float angledelta = 15.0; - - int maxtries = (int)360.0/angledelta; - - if ( botdata->lastturntoright ) - { - angledelta = -angledelta; - } - - angle = pBot->GetLocalAngles(); - - Vector vecSrc; - while ( --maxtries >= 0 ) - { - AngleVectors( angle, &forward ); - - vecSrc = pBot->GetLocalOrigin() + Vector( 0, 0, 36 ); - - vecEnd = vecSrc + forward * 10; - - UTIL_TraceHull( vecSrc, vecEnd, VEC_HULL_MIN_SCALED( pBot ), VEC_HULL_MAX_SCALED( pBot ), - MASK_PLAYERSOLID, pBot, COLLISION_GROUP_NONE, &trace ); - - if ( trace.fraction == 1.0 ) - { - if ( gpGlobals->curtime < botdata->nextturntime ) - { - break; - } - } - - angle.y += angledelta; - - if ( angle.y > 180 ) - angle.y -= 360; - else if ( angle.y < -180 ) - angle.y += 360; - - botdata->nextturntime = gpGlobals->curtime + 2.0; - botdata->lastturntoright = random->RandomInt( 0, 1 ) == 0 ? true : false; - - botdata->forwardAngle = angle; - botdata->lastAngles = angle; - - } - - - if ( gpGlobals->curtime >= botdata->nextstrafetime ) - { - botdata->nextstrafetime = gpGlobals->curtime + 1.0f; - - if ( random->RandomInt( 0, 5 ) == 0 ) - { - botdata->sidemove = -600.0f + 1200.0f * random->RandomFloat( 0, 2 ); - } - else - { - botdata->sidemove = 0; - } - sidemove = botdata->sidemove; - - if ( random->RandomInt( 0, 20 ) == 0 ) - { - botdata->backwards = true; - } - else - { - botdata->backwards = false; - } - } - - pBot->SetLocalAngles( angle ); - vecViewAngles = angle; - } - - // Is my team being forced to defend? - if ( bot_defend.GetInt() == pBot->GetTeamNumber() ) - { - buttons |= IN_ATTACK2; - } - // If bots are being forced to fire a weapon, see if I have it - else if ( bot_forcefireweapon.GetString() ) - { - CBaseCombatWeapon *pWeapon = pBot->Weapon_OwnsThisType( bot_forcefireweapon.GetString() ); - if ( pWeapon ) - { - // Switch to it if we don't have it out - CBaseCombatWeapon *pActiveWeapon = pBot->GetActiveWeapon(); - - // Switch? - if ( pActiveWeapon != pWeapon ) - { - pBot->Weapon_Switch( pWeapon ); - } - else - { - // Start firing - // Some weapons require releases, so randomise firing - if ( bot_forceattackon.GetBool() || (RandomFloat(0.0,1.0) > 0.5) ) - { - buttons |= bot_forceattack2.GetBool() ? IN_ATTACK2 : IN_ATTACK; - } - } - } - } - - if ( bot_flipout.GetInt() ) - { - if ( bot_forceattackon.GetBool() || (RandomFloat(0.0,1.0) > 0.5) ) - { - buttons |= bot_forceattack2.GetBool() ? IN_ATTACK2 : IN_ATTACK; - } - } - - if ( strlen( bot_sendcmd.GetString() ) > 0 ) - { - //send the cmd from this bot - CCommand args; - args.Tokenize( bot_sendcmd.GetString() ); - pBot->ClientCommand( args ); - - bot_sendcmd.SetValue(""); - } - } - else - { - // Wait for Reinforcement wave - if ( !pBot->IsAlive() ) - { - // Try hitting my buttons occasionally - if ( random->RandomInt( 0, 100 ) > 80 ) - { - // Respawn the bot - if ( random->RandomInt( 0, 1 ) == 0 ) - { - buttons |= IN_JUMP; - } - else - { - buttons = 0; - } - } - } - } - - if ( bot_flipout.GetInt() >= 2 ) - { - - QAngle angOffset = RandomAngle( -1, 1 ); - - botdata->lastAngles += angOffset; - - for ( int i = 0 ; i < 2; i++ ) - { - if ( fabs( botdata->lastAngles[ i ] - botdata->forwardAngle[ i ] ) > 15.0f ) - { - if ( botdata->lastAngles[ i ] > botdata->forwardAngle[ i ] ) - { - botdata->lastAngles[ i ] = botdata->forwardAngle[ i ] + 15; - } - else - { - botdata->lastAngles[ i ] = botdata->forwardAngle[ i ] - 15; - } - } - } - - botdata->lastAngles[ 2 ] = 0; - - pBot->SetLocalAngles( botdata->lastAngles ); - } - - RunPlayerMove( pBot, pBot->GetLocalAngles(), forwardmove, sidemove, upmove, buttons, impulse, frametime ); -} - - - - -#endif - diff --git a/sp/src/game/server/hl2mp/hl2mp_bot_temp.h b/sp/src/game/server/hl2mp/hl2mp_bot_temp.h deleted file mode 100644 index f78e63e8..00000000 --- a/sp/src/game/server/hl2mp/hl2mp_bot_temp.h +++ /dev/null @@ -1,19 +0,0 @@ -//========= Copyright Valve Corporation, All rights reserved. ============// -// -// Purpose: -// -// $NoKeywords: $ -//=============================================================================// -#ifndef BOT_BASE_H -#define BOT_BASE_H -#ifdef _WIN32 -#pragma once -#endif - - -// If iTeam or iClass is -1, then a team or class is randomly chosen. -CBasePlayer *BotPutInServer( bool bFrozen, int iTeam ); - - -#endif // BOT_BASE_H - diff --git a/sp/src/game/server/hl2mp/hl2mp_client.cpp b/sp/src/game/server/hl2mp/hl2mp_client.cpp deleted file mode 100644 index 571fbb85..00000000 --- a/sp/src/game/server/hl2mp/hl2mp_client.cpp +++ /dev/null @@ -1,201 +0,0 @@ -//========= Copyright Valve Corporation, All rights reserved. ============// -// -// Purpose: -// -// $NoKeywords: $ -// -//=============================================================================// -/* - -===== tf_client.cpp ======================================================== - - HL2 client/server game specific stuff - -*/ - -#include "cbase.h" -#include "hl2mp_player.h" -#include "hl2mp_gamerules.h" -#include "gamerules.h" -#include "teamplay_gamerules.h" -#include "entitylist.h" -#include "physics.h" -#include "game.h" -#include "player_resource.h" -#include "engine/IEngineSound.h" -#include "team.h" -#include "viewport_panel_names.h" - -#include "tier0/vprof.h" - -// memdbgon must be the last include file in a .cpp file!!! -#include "tier0/memdbgon.h" - -void Host_Say( edict_t *pEdict, bool teamonly ); - -ConVar sv_motd_unload_on_dismissal( "sv_motd_unload_on_dismissal", "0", 0, "If enabled, the MOTD contents will be unloaded when the player closes the MOTD." ); - -extern CBaseEntity* FindPickerEntityClass( CBasePlayer *pPlayer, char *classname ); -extern bool g_fGameOver; - -void FinishClientPutInServer( CHL2MP_Player *pPlayer ) -{ - pPlayer->InitialSpawn(); - pPlayer->Spawn(); - - - char sName[128]; - Q_strncpy( sName, pPlayer->GetPlayerName(), sizeof( sName ) ); - - // First parse the name and remove any %'s - for ( char *pApersand = sName; pApersand != NULL && *pApersand != 0; pApersand++ ) - { - // Replace it with a space - if ( *pApersand == '%' ) - *pApersand = ' '; - } - - // notify other clients of player joining the game - UTIL_ClientPrintAll( HUD_PRINTNOTIFY, "#Game_connected", sName[0] != 0 ? sName : "" ); - - if ( HL2MPRules()->IsTeamplay() == true ) - { - ClientPrint( pPlayer, HUD_PRINTTALK, "You are on team %s1\n", pPlayer->GetTeam()->GetName() ); - } - - const ConVar *hostname = cvar->FindVar( "hostname" ); - const char *title = (hostname) ? hostname->GetString() : "MESSAGE OF THE DAY"; - - KeyValues *data = new KeyValues("data"); - data->SetString( "title", title ); // info panel title - data->SetString( "type", "1" ); // show userdata from stringtable entry - data->SetString( "msg", "motd" ); // use this stringtable entry - data->SetBool( "unload", sv_motd_unload_on_dismissal.GetBool() ); - - pPlayer->ShowViewPortPanel( PANEL_INFO, true, data ); - - data->deleteThis(); -} - -/* -=========== -ClientPutInServer - -called each time a player is spawned into the game -============ -*/ -void ClientPutInServer( edict_t *pEdict, const char *playername ) -{ - // Allocate a CBaseTFPlayer for pev, and call spawn - CHL2MP_Player *pPlayer = CHL2MP_Player::CreatePlayer( "player", pEdict ); - pPlayer->SetPlayerName( playername ); -} - - -void ClientActive( edict_t *pEdict, bool bLoadGame ) -{ - // Can't load games in CS! - Assert( !bLoadGame ); - - CHL2MP_Player *pPlayer = ToHL2MPPlayer( CBaseEntity::Instance( pEdict ) ); - FinishClientPutInServer( pPlayer ); -} - - -/* -=============== -const char *GetGameDescription() - -Returns the descriptive name of this .dll. E.g., Half-Life, or Team Fortress 2 -=============== -*/ -const char *GetGameDescription() -{ - if ( g_pGameRules ) // this function may be called before the world has spawned, and the game rules initialized - return g_pGameRules->GetGameDescription(); - else - return "Half-Life 2 Deathmatch"; -} - -//----------------------------------------------------------------------------- -// Purpose: Given a player and optional name returns the entity of that -// classname that the player is nearest facing -// -// Input : -// Output : -//----------------------------------------------------------------------------- -CBaseEntity* FindEntity( edict_t *pEdict, char *classname) -{ - // If no name was given set bits based on the picked - if (FStrEq(classname,"")) - { - return (FindPickerEntityClass( static_cast(GetContainingEntity(pEdict)), classname )); - } - return NULL; -} - -//----------------------------------------------------------------------------- -// Purpose: Precache game-specific models & sounds -//----------------------------------------------------------------------------- -void ClientGamePrecache( void ) -{ - CBaseEntity::PrecacheModel("models/player.mdl"); - CBaseEntity::PrecacheModel( "models/gibs/agibs.mdl" ); - CBaseEntity::PrecacheModel ("models/weapons/v_hands.mdl"); - - CBaseEntity::PrecacheScriptSound( "HUDQuickInfo.LowAmmo" ); - CBaseEntity::PrecacheScriptSound( "HUDQuickInfo.LowHealth" ); - - CBaseEntity::PrecacheScriptSound( "FX_AntlionImpact.ShellImpact" ); - CBaseEntity::PrecacheScriptSound( "Missile.ShotDown" ); - CBaseEntity::PrecacheScriptSound( "Bullets.DefaultNearmiss" ); - CBaseEntity::PrecacheScriptSound( "Bullets.GunshipNearmiss" ); - CBaseEntity::PrecacheScriptSound( "Bullets.StriderNearmiss" ); - - CBaseEntity::PrecacheScriptSound( "Geiger.BeepHigh" ); - CBaseEntity::PrecacheScriptSound( "Geiger.BeepLow" ); -} - - -// called by ClientKill and DeadThink -void respawn( CBaseEntity *pEdict, bool fCopyCorpse ) -{ - CHL2MP_Player *pPlayer = ToHL2MPPlayer( pEdict ); - - if ( pPlayer ) - { - if ( gpGlobals->curtime > pPlayer->GetDeathTime() + DEATH_ANIMATION_TIME ) - { - // respawn player - pPlayer->Spawn(); - } - else - { - pPlayer->SetNextThink( gpGlobals->curtime + 0.1f ); - } - } -} - -void GameStartFrame( void ) -{ - VPROF("GameStartFrame()"); - if ( g_fGameOver ) - return; - - gpGlobals->teamplay = (teamplay.GetInt() != 0); - -#ifdef DEBUG - extern void Bot_RunAll(); - Bot_RunAll(); -#endif -} - -//========================================================= -// instantiate the proper game rules object -//========================================================= -void InstallGameRules() -{ - // vanilla deathmatch - CreateGameRulesObject( "CHL2MPRules" ); -} - diff --git a/sp/src/game/server/hl2mp/hl2mp_cvars.cpp b/sp/src/game/server/hl2mp/hl2mp_cvars.cpp deleted file mode 100644 index 11986ee8..00000000 --- a/sp/src/game/server/hl2mp/hl2mp_cvars.cpp +++ /dev/null @@ -1,25 +0,0 @@ -//========= Copyright Valve Corporation, All rights reserved. ============// -// -// Purpose: -// -// $NoKeywords: $ -//=============================================================================// - -#include "cbase.h" -#include "hl2mp_cvars.h" - - - -// Ready restart -ConVar mp_readyrestart( - "mp_readyrestart", - "0", - FCVAR_GAMEDLL, - "If non-zero, game will restart once each player gives the ready signal" ); - -// Ready signal -ConVar mp_ready_signal( - "mp_ready_signal", - "ready", - FCVAR_GAMEDLL, - "Text that each player must speak for the match to begin" ); \ No newline at end of file diff --git a/sp/src/game/server/hl2mp/hl2mp_cvars.h b/sp/src/game/server/hl2mp/hl2mp_cvars.h deleted file mode 100644 index 4baf52f4..00000000 --- a/sp/src/game/server/hl2mp/hl2mp_cvars.h +++ /dev/null @@ -1,20 +0,0 @@ -//========= Copyright Valve Corporation, All rights reserved. ============// -// -// Purpose: -// -// $NoKeywords: $ -//=============================================================================// - -#ifndef HL2MP_CVARS_H -#define HL2MP_CVARS_H -#ifdef _WIN32 -#pragma once -#endif - -#define MAX_INTERMISSION_TIME 120 - -extern ConVar mp_restartround; -extern ConVar mp_readyrestart; -extern ConVar mp_ready_signal; - -#endif //HL2MP_CVARS_H \ No newline at end of file diff --git a/sp/src/game/server/hl2mp/hl2mp_gameinterface.cpp b/sp/src/game/server/hl2mp/hl2mp_gameinterface.cpp deleted file mode 100644 index b5881f7b..00000000 --- a/sp/src/game/server/hl2mp/hl2mp_gameinterface.cpp +++ /dev/null @@ -1,32 +0,0 @@ -//========= Copyright Valve Corporation, All rights reserved. ============// -// -// Purpose: -// -//=============================================================================// - -#include "cbase.h" -#include "gameinterface.h" -#include "mapentities.h" -#include "hl2mp_gameinterface.h" - -// memdbgon must be the last include file in a .cpp file!!! -#include "tier0/memdbgon.h" - -// -------------------------------------------------------------------------------------------- // -// Mod-specific CServerGameClients implementation. -// -------------------------------------------------------------------------------------------- // - -void CServerGameClients::GetPlayerLimits( int& minplayers, int& maxplayers, int &defaultMaxPlayers ) const -{ - minplayers = defaultMaxPlayers = 2; - maxplayers = 16; -} - -// -------------------------------------------------------------------------------------------- // -// Mod-specific CServerGameDLL implementation. -// -------------------------------------------------------------------------------------------- // - -void CServerGameDLL::LevelInit_ParseAllEntities( const char *pMapEntities ) -{ -} - diff --git a/sp/src/game/server/hl2mp/hl2mp_gameinterface.h b/sp/src/game/server/hl2mp/hl2mp_gameinterface.h deleted file mode 100644 index 4955e46c..00000000 --- a/sp/src/game/server/hl2mp/hl2mp_gameinterface.h +++ /dev/null @@ -1,10 +0,0 @@ -//========= Copyright Valve Corporation, All rights reserved. ============// -#ifndef HL2MP_GAMEINTERFACE_H -#define HL2MP_GAMEINTERFACE_H -#ifdef _WIN32 -#pragma once -#endif - -#include "gameinterface.h" - -#endif \ No newline at end of file diff --git a/sp/src/game/server/hl2mp/hl2mp_player.cpp b/sp/src/game/server/hl2mp/hl2mp_player.cpp deleted file mode 100644 index 1469d842..00000000 --- a/sp/src/game/server/hl2mp/hl2mp_player.cpp +++ /dev/null @@ -1,1629 +0,0 @@ -//========= Copyright Valve Corporation, All rights reserved. ============// -// -// Purpose: Player for HL2. -// -//=============================================================================// - -#include "cbase.h" -#include "weapon_hl2mpbasehlmpcombatweapon.h" -#include "hl2mp_player.h" -#include "globalstate.h" -#include "game.h" -#include "gamerules.h" -#include "hl2mp_player_shared.h" -#include "predicted_viewmodel.h" -#include "in_buttons.h" -#include "hl2mp_gamerules.h" -#include "KeyValues.h" -#include "team.h" -#include "weapon_hl2mpbase.h" -#include "grenade_satchel.h" -#include "eventqueue.h" -#include "gamestats.h" - -#include "engine/IEngineSound.h" -#include "SoundEmitterSystem/isoundemittersystembase.h" - -#include "ilagcompensationmanager.h" - -int g_iLastCitizenModel = 0; -int g_iLastCombineModel = 0; - -CBaseEntity *g_pLastCombineSpawn = NULL; -CBaseEntity *g_pLastRebelSpawn = NULL; -extern CBaseEntity *g_pLastSpawn; - -#define HL2MP_COMMAND_MAX_RATE 0.3 - -void DropPrimedFragGrenade( CHL2MP_Player *pPlayer, CBaseCombatWeapon *pGrenade ); - -LINK_ENTITY_TO_CLASS( player, CHL2MP_Player ); - -LINK_ENTITY_TO_CLASS( info_player_combine, CPointEntity ); -LINK_ENTITY_TO_CLASS( info_player_rebel, CPointEntity ); - -IMPLEMENT_SERVERCLASS_ST(CHL2MP_Player, DT_HL2MP_Player) - SendPropAngle( SENDINFO_VECTORELEM(m_angEyeAngles, 0), 11, SPROP_CHANGES_OFTEN ), - SendPropAngle( SENDINFO_VECTORELEM(m_angEyeAngles, 1), 11, SPROP_CHANGES_OFTEN ), - SendPropEHandle( SENDINFO( m_hRagdoll ) ), - SendPropInt( SENDINFO( m_iSpawnInterpCounter), 4 ), - SendPropInt( SENDINFO( m_iPlayerSoundType), 3 ), - - SendPropExclude( "DT_BaseAnimating", "m_flPoseParameter" ), - SendPropExclude( "DT_BaseFlex", "m_viewtarget" ), - -// SendPropExclude( "DT_ServerAnimationData" , "m_flCycle" ), -// SendPropExclude( "DT_AnimTimeMustBeFirst" , "m_flAnimTime" ), - -END_SEND_TABLE() - -BEGIN_DATADESC( CHL2MP_Player ) -END_DATADESC() - -const char *g_ppszRandomCitizenModels[] = -{ - "models/humans/group03/male_01.mdl", - "models/humans/group03/male_02.mdl", - "models/humans/group03/female_01.mdl", - "models/humans/group03/male_03.mdl", - "models/humans/group03/female_02.mdl", - "models/humans/group03/male_04.mdl", - "models/humans/group03/female_03.mdl", - "models/humans/group03/male_05.mdl", - "models/humans/group03/female_04.mdl", - "models/humans/group03/male_06.mdl", - "models/humans/group03/female_06.mdl", - "models/humans/group03/male_07.mdl", - "models/humans/group03/female_07.mdl", - "models/humans/group03/male_08.mdl", - "models/humans/group03/male_09.mdl", -}; - -const char *g_ppszRandomCombineModels[] = -{ - "models/combine_soldier.mdl", - "models/combine_soldier_prisonguard.mdl", - "models/combine_super_soldier.mdl", - "models/police.mdl", -}; - - -#define MAX_COMBINE_MODELS 4 -#define MODEL_CHANGE_INTERVAL 5.0f -#define TEAM_CHANGE_INTERVAL 5.0f - -#define HL2MPPLAYER_PHYSDAMAGE_SCALE 4.0f - -#pragma warning( disable : 4355 ) - -CHL2MP_Player::CHL2MP_Player() : m_PlayerAnimState( this ) -{ - m_angEyeAngles.Init(); - - m_iLastWeaponFireUsercmd = 0; - - m_flNextModelChangeTime = 0.0f; - m_flNextTeamChangeTime = 0.0f; - - m_iSpawnInterpCounter = 0; - - m_bEnterObserver = false; - m_bReady = false; - - BaseClass::ChangeTeam( 0 ); - -// UseClientSideAnimation(); -} - -CHL2MP_Player::~CHL2MP_Player( void ) -{ - -} - -void CHL2MP_Player::UpdateOnRemove( void ) -{ - if ( m_hRagdoll ) - { - UTIL_RemoveImmediate( m_hRagdoll ); - m_hRagdoll = NULL; - } - - BaseClass::UpdateOnRemove(); -} - -void CHL2MP_Player::Precache( void ) -{ - BaseClass::Precache(); - - PrecacheModel ( "sprites/glow01.vmt" ); - - //Precache Citizen models - int nHeads = ARRAYSIZE( g_ppszRandomCitizenModels ); - int i; - - for ( i = 0; i < nHeads; ++i ) - PrecacheModel( g_ppszRandomCitizenModels[i] ); - - //Precache Combine Models - nHeads = ARRAYSIZE( g_ppszRandomCombineModels ); - - for ( i = 0; i < nHeads; ++i ) - PrecacheModel( g_ppszRandomCombineModels[i] ); - - PrecacheFootStepSounds(); - - PrecacheScriptSound( "NPC_MetroPolice.Die" ); - PrecacheScriptSound( "NPC_CombineS.Die" ); - PrecacheScriptSound( "NPC_Citizen.die" ); -} - -void CHL2MP_Player::GiveAllItems( void ) -{ - EquipSuit(); - - CBasePlayer::GiveAmmo( 255, "Pistol"); - CBasePlayer::GiveAmmo( 255, "AR2" ); - CBasePlayer::GiveAmmo( 5, "AR2AltFire" ); - CBasePlayer::GiveAmmo( 255, "SMG1"); - CBasePlayer::GiveAmmo( 1, "smg1_grenade"); - CBasePlayer::GiveAmmo( 255, "Buckshot"); - CBasePlayer::GiveAmmo( 32, "357" ); - CBasePlayer::GiveAmmo( 3, "rpg_round"); - - CBasePlayer::GiveAmmo( 1, "grenade" ); - CBasePlayer::GiveAmmo( 2, "slam" ); - - GiveNamedItem( "weapon_crowbar" ); - GiveNamedItem( "weapon_stunstick" ); - GiveNamedItem( "weapon_pistol" ); - GiveNamedItem( "weapon_357" ); - - GiveNamedItem( "weapon_smg1" ); - GiveNamedItem( "weapon_ar2" ); - - GiveNamedItem( "weapon_shotgun" ); - GiveNamedItem( "weapon_frag" ); - - GiveNamedItem( "weapon_crossbow" ); - - GiveNamedItem( "weapon_rpg" ); - - GiveNamedItem( "weapon_slam" ); - - GiveNamedItem( "weapon_physcannon" ); - -} - -void CHL2MP_Player::GiveDefaultItems( void ) -{ - EquipSuit(); - - CBasePlayer::GiveAmmo( 255, "Pistol"); - CBasePlayer::GiveAmmo( 45, "SMG1"); - CBasePlayer::GiveAmmo( 1, "grenade" ); - CBasePlayer::GiveAmmo( 6, "Buckshot"); - CBasePlayer::GiveAmmo( 6, "357" ); - - if ( GetPlayerModelType() == PLAYER_SOUNDS_METROPOLICE || GetPlayerModelType() == PLAYER_SOUNDS_COMBINESOLDIER ) - { - GiveNamedItem( "weapon_stunstick" ); - } - else if ( GetPlayerModelType() == PLAYER_SOUNDS_CITIZEN ) - { - GiveNamedItem( "weapon_crowbar" ); - } - - GiveNamedItem( "weapon_pistol" ); - GiveNamedItem( "weapon_smg1" ); - GiveNamedItem( "weapon_frag" ); - GiveNamedItem( "weapon_physcannon" ); - - const char *szDefaultWeaponName = engine->GetClientConVarValue( engine->IndexOfEdict( edict() ), "cl_defaultweapon" ); - - CBaseCombatWeapon *pDefaultWeapon = Weapon_OwnsThisType( szDefaultWeaponName ); - - if ( pDefaultWeapon ) - { - Weapon_Switch( pDefaultWeapon ); - } - else - { - Weapon_Switch( Weapon_OwnsThisType( "weapon_physcannon" ) ); - } -} - -void CHL2MP_Player::PickDefaultSpawnTeam( void ) -{ - if ( GetTeamNumber() == 0 ) - { - if ( HL2MPRules()->IsTeamplay() == false ) - { - if ( GetModelPtr() == NULL ) - { - const char *szModelName = NULL; - szModelName = engine->GetClientConVarValue( engine->IndexOfEdict( edict() ), "cl_playermodel" ); - - if ( ValidatePlayerModel( szModelName ) == false ) - { - char szReturnString[512]; - - Q_snprintf( szReturnString, sizeof (szReturnString ), "cl_playermodel models/combine_soldier.mdl\n" ); - engine->ClientCommand ( edict(), szReturnString ); - } - - ChangeTeam( TEAM_UNASSIGNED ); - } - } - else - { - CTeam *pCombine = g_Teams[TEAM_COMBINE]; - CTeam *pRebels = g_Teams[TEAM_REBELS]; - - if ( pCombine == NULL || pRebels == NULL ) - { - ChangeTeam( random->RandomInt( TEAM_COMBINE, TEAM_REBELS ) ); - } - else - { - if ( pCombine->GetNumPlayers() > pRebels->GetNumPlayers() ) - { - ChangeTeam( TEAM_REBELS ); - } - else if ( pCombine->GetNumPlayers() < pRebels->GetNumPlayers() ) - { - ChangeTeam( TEAM_COMBINE ); - } - else - { - ChangeTeam( random->RandomInt( TEAM_COMBINE, TEAM_REBELS ) ); - } - } - } - } -} - -//----------------------------------------------------------------------------- -// Purpose: Sets HL2 specific defaults. -//----------------------------------------------------------------------------- -void CHL2MP_Player::Spawn(void) -{ - m_flNextModelChangeTime = 0.0f; - m_flNextTeamChangeTime = 0.0f; - - PickDefaultSpawnTeam(); - - BaseClass::Spawn(); - - if ( !IsObserver() ) - { - pl.deadflag = false; - RemoveSolidFlags( FSOLID_NOT_SOLID ); - - RemoveEffects( EF_NODRAW ); - - GiveDefaultItems(); - } - - SetNumAnimOverlays( 3 ); - ResetAnimation(); - - m_nRenderFX = kRenderNormal; - - m_Local.m_iHideHUD = 0; - - AddFlag(FL_ONGROUND); // set the player on the ground at the start of the round. - - m_impactEnergyScale = HL2MPPLAYER_PHYSDAMAGE_SCALE; - - if ( HL2MPRules()->IsIntermission() ) - { - AddFlag( FL_FROZEN ); - } - else - { - RemoveFlag( FL_FROZEN ); - } - - m_iSpawnInterpCounter = (m_iSpawnInterpCounter + 1) % 8; - - m_Local.m_bDucked = false; - - SetPlayerUnderwater(false); - - m_bReady = false; -} - -void CHL2MP_Player::PickupObject( CBaseEntity *pObject, bool bLimitMassAndSize ) -{ - -} - -bool CHL2MP_Player::ValidatePlayerModel( const char *pModel ) -{ - int iModels = ARRAYSIZE( g_ppszRandomCitizenModels ); - int i; - - for ( i = 0; i < iModels; ++i ) - { - if ( !Q_stricmp( g_ppszRandomCitizenModels[i], pModel ) ) - { - return true; - } - } - - iModels = ARRAYSIZE( g_ppszRandomCombineModels ); - - for ( i = 0; i < iModels; ++i ) - { - if ( !Q_stricmp( g_ppszRandomCombineModels[i], pModel ) ) - { - return true; - } - } - - return false; -} - -void CHL2MP_Player::SetPlayerTeamModel( void ) -{ - const char *szModelName = NULL; - szModelName = engine->GetClientConVarValue( engine->IndexOfEdict( edict() ), "cl_playermodel" ); - - int modelIndex = modelinfo->GetModelIndex( szModelName ); - - if ( modelIndex == -1 || ValidatePlayerModel( szModelName ) == false ) - { - szModelName = "models/Combine_Soldier.mdl"; - m_iModelType = TEAM_COMBINE; - - char szReturnString[512]; - - Q_snprintf( szReturnString, sizeof (szReturnString ), "cl_playermodel %s\n", szModelName ); - engine->ClientCommand ( edict(), szReturnString ); - } - - if ( GetTeamNumber() == TEAM_COMBINE ) - { - if ( Q_stristr( szModelName, "models/human") ) - { - int nHeads = ARRAYSIZE( g_ppszRandomCombineModels ); - - g_iLastCombineModel = ( g_iLastCombineModel + 1 ) % nHeads; - szModelName = g_ppszRandomCombineModels[g_iLastCombineModel]; - } - - m_iModelType = TEAM_COMBINE; - } - else if ( GetTeamNumber() == TEAM_REBELS ) - { - if ( !Q_stristr( szModelName, "models/human") ) - { - int nHeads = ARRAYSIZE( g_ppszRandomCitizenModels ); - - g_iLastCitizenModel = ( g_iLastCitizenModel + 1 ) % nHeads; - szModelName = g_ppszRandomCitizenModels[g_iLastCitizenModel]; - } - - m_iModelType = TEAM_REBELS; - } - - SetModel( szModelName ); - SetupPlayerSoundsByModel( szModelName ); - - m_flNextModelChangeTime = gpGlobals->curtime + MODEL_CHANGE_INTERVAL; -} - -void CHL2MP_Player::SetPlayerModel( void ) -{ - const char *szModelName = NULL; - const char *pszCurrentModelName = modelinfo->GetModelName( GetModel()); - - szModelName = engine->GetClientConVarValue( engine->IndexOfEdict( edict() ), "cl_playermodel" ); - - if ( ValidatePlayerModel( szModelName ) == false ) - { - char szReturnString[512]; - - if ( ValidatePlayerModel( pszCurrentModelName ) == false ) - { - pszCurrentModelName = "models/Combine_Soldier.mdl"; - } - - Q_snprintf( szReturnString, sizeof (szReturnString ), "cl_playermodel %s\n", pszCurrentModelName ); - engine->ClientCommand ( edict(), szReturnString ); - - szModelName = pszCurrentModelName; - } - - if ( GetTeamNumber() == TEAM_COMBINE ) - { - int nHeads = ARRAYSIZE( g_ppszRandomCombineModels ); - - g_iLastCombineModel = ( g_iLastCombineModel + 1 ) % nHeads; - szModelName = g_ppszRandomCombineModels[g_iLastCombineModel]; - - m_iModelType = TEAM_COMBINE; - } - else if ( GetTeamNumber() == TEAM_REBELS ) - { - int nHeads = ARRAYSIZE( g_ppszRandomCitizenModels ); - - g_iLastCitizenModel = ( g_iLastCitizenModel + 1 ) % nHeads; - szModelName = g_ppszRandomCitizenModels[g_iLastCitizenModel]; - - m_iModelType = TEAM_REBELS; - } - else - { - if ( Q_strlen( szModelName ) == 0 ) - { - szModelName = g_ppszRandomCitizenModels[0]; - } - - if ( Q_stristr( szModelName, "models/human") ) - { - m_iModelType = TEAM_REBELS; - } - else - { - m_iModelType = TEAM_COMBINE; - } - } - - int modelIndex = modelinfo->GetModelIndex( szModelName ); - - if ( modelIndex == -1 ) - { - szModelName = "models/Combine_Soldier.mdl"; - m_iModelType = TEAM_COMBINE; - - char szReturnString[512]; - - Q_snprintf( szReturnString, sizeof (szReturnString ), "cl_playermodel %s\n", szModelName ); - engine->ClientCommand ( edict(), szReturnString ); - } - - SetModel( szModelName ); - SetupPlayerSoundsByModel( szModelName ); - - m_flNextModelChangeTime = gpGlobals->curtime + MODEL_CHANGE_INTERVAL; -} - -void CHL2MP_Player::SetupPlayerSoundsByModel( const char *pModelName ) -{ - if ( Q_stristr( pModelName, "models/human") ) - { - m_iPlayerSoundType = (int)PLAYER_SOUNDS_CITIZEN; - } - else if ( Q_stristr(pModelName, "police" ) ) - { - m_iPlayerSoundType = (int)PLAYER_SOUNDS_METROPOLICE; - } - else if ( Q_stristr(pModelName, "combine" ) ) - { - m_iPlayerSoundType = (int)PLAYER_SOUNDS_COMBINESOLDIER; - } -} - -void CHL2MP_Player::ResetAnimation( void ) -{ - if ( IsAlive() ) - { - SetSequence ( -1 ); - SetActivity( ACT_INVALID ); - - if (!GetAbsVelocity().x && !GetAbsVelocity().y) - SetAnimation( PLAYER_IDLE ); - else if ((GetAbsVelocity().x || GetAbsVelocity().y) && ( GetFlags() & FL_ONGROUND )) - SetAnimation( PLAYER_WALK ); - else if (GetWaterLevel() > 1) - SetAnimation( PLAYER_WALK ); - } -} - - -bool CHL2MP_Player::Weapon_Switch( CBaseCombatWeapon *pWeapon, int viewmodelindex ) -{ - bool bRet = BaseClass::Weapon_Switch( pWeapon, viewmodelindex ); - - if ( bRet == true ) - { - ResetAnimation(); - } - - return bRet; -} - -void CHL2MP_Player::PreThink( void ) -{ - QAngle vOldAngles = GetLocalAngles(); - QAngle vTempAngles = GetLocalAngles(); - - vTempAngles = EyeAngles(); - - if ( vTempAngles[PITCH] > 180.0f ) - { - vTempAngles[PITCH] -= 360.0f; - } - - SetLocalAngles( vTempAngles ); - - BaseClass::PreThink(); - State_PreThink(); - - //Reset bullet force accumulator, only lasts one frame - m_vecTotalBulletForce = vec3_origin; - SetLocalAngles( vOldAngles ); -} - -void CHL2MP_Player::PostThink( void ) -{ - BaseClass::PostThink(); - - if ( GetFlags() & FL_DUCKING ) - { - SetCollisionBounds( VEC_CROUCH_TRACE_MIN, VEC_CROUCH_TRACE_MAX ); - } - - m_PlayerAnimState.Update(); - - // Store the eye angles pitch so the client can compute its animation state correctly. - m_angEyeAngles = EyeAngles(); - - QAngle angles = GetLocalAngles(); - angles[PITCH] = 0; - SetLocalAngles( angles ); -} - -void CHL2MP_Player::PlayerDeathThink() -{ - if( !IsObserver() ) - { - BaseClass::PlayerDeathThink(); - } -} - -void CHL2MP_Player::FireBullets ( const FireBulletsInfo_t &info ) -{ - // Move other players back to history positions based on local player's lag - lagcompensation->StartLagCompensation( this, this->GetCurrentCommand() ); - - FireBulletsInfo_t modinfo = info; - - CWeaponHL2MPBase *pWeapon = dynamic_cast( GetActiveWeapon() ); - - if ( pWeapon ) - { - modinfo.m_iPlayerDamage = modinfo.m_flDamage = pWeapon->GetHL2MPWpnData().m_iPlayerDamage; - } - - NoteWeaponFired(); - - BaseClass::FireBullets( modinfo ); - - // Move other players back to history positions based on local player's lag - lagcompensation->FinishLagCompensation( this ); -} - -void CHL2MP_Player::NoteWeaponFired( void ) -{ - Assert( m_pCurrentCommand ); - if( m_pCurrentCommand ) - { - m_iLastWeaponFireUsercmd = m_pCurrentCommand->command_number; - } -} - -extern ConVar sv_maxunlag; - -bool CHL2MP_Player::WantsLagCompensationOnEntity( const CBasePlayer *pPlayer, const CUserCmd *pCmd, const CBitVec *pEntityTransmitBits ) const -{ - // No need to lag compensate at all if we're not attacking in this command and - // we haven't attacked recently. - if ( !( pCmd->buttons & IN_ATTACK ) && (pCmd->command_number - m_iLastWeaponFireUsercmd > 5) ) - return false; - - // If this entity hasn't been transmitted to us and acked, then don't bother lag compensating it. - if ( pEntityTransmitBits && !pEntityTransmitBits->Get( pPlayer->entindex() ) ) - return false; - - const Vector &vMyOrigin = GetAbsOrigin(); - const Vector &vHisOrigin = pPlayer->GetAbsOrigin(); - - // get max distance player could have moved within max lag compensation time, - // multiply by 1.5 to to avoid "dead zones" (sqrt(2) would be the exact value) - float maxDistance = 1.5 * pPlayer->MaxSpeed() * sv_maxunlag.GetFloat(); - - // If the player is within this distance, lag compensate them in case they're running past us. - if ( vHisOrigin.DistTo( vMyOrigin ) < maxDistance ) - return true; - - // If their origin is not within a 45 degree cone in front of us, no need to lag compensate. - Vector vForward; - AngleVectors( pCmd->viewangles, &vForward ); - - Vector vDiff = vHisOrigin - vMyOrigin; - VectorNormalize( vDiff ); - - float flCosAngle = 0.707107f; // 45 degree angle - if ( vForward.Dot( vDiff ) < flCosAngle ) - return false; - - return true; -} - -Activity CHL2MP_Player::TranslateTeamActivity( Activity ActToTranslate ) -{ - if ( m_iModelType == TEAM_COMBINE ) - return ActToTranslate; - - if ( ActToTranslate == ACT_RUN ) - return ACT_RUN_AIM_AGITATED; - - if ( ActToTranslate == ACT_IDLE ) - return ACT_IDLE_AIM_AGITATED; - - if ( ActToTranslate == ACT_WALK ) - return ACT_WALK_AIM_AGITATED; - - return ActToTranslate; -} - -extern ConVar hl2_normspeed; - -// Set the activity based on an event or current state -void CHL2MP_Player::SetAnimation( PLAYER_ANIM playerAnim ) -{ - int animDesired; - - float speed; - - speed = GetAbsVelocity().Length2D(); - - - // bool bRunning = true; - - //Revisit! -/* if ( ( m_nButtons & ( IN_FORWARD | IN_BACK | IN_MOVELEFT | IN_MOVERIGHT ) ) ) - { - if ( speed > 1.0f && speed < hl2_normspeed.GetFloat() - 20.0f ) - { - bRunning = false; - } - }*/ - - if ( GetFlags() & ( FL_FROZEN | FL_ATCONTROLS ) ) - { - speed = 0; - playerAnim = PLAYER_IDLE; - } - - Activity idealActivity = ACT_HL2MP_RUN; - - // This could stand to be redone. Why is playerAnim abstracted from activity? (sjb) - if ( playerAnim == PLAYER_JUMP ) - { - idealActivity = ACT_HL2MP_JUMP; - } - else if ( playerAnim == PLAYER_DIE ) - { - if ( m_lifeState == LIFE_ALIVE ) - { - return; - } - } - else if ( playerAnim == PLAYER_ATTACK1 ) - { - if ( GetActivity( ) == ACT_HOVER || - GetActivity( ) == ACT_SWIM || - GetActivity( ) == ACT_HOP || - GetActivity( ) == ACT_LEAP || - GetActivity( ) == ACT_DIESIMPLE ) - { - idealActivity = GetActivity( ); - } - else - { - idealActivity = ACT_HL2MP_GESTURE_RANGE_ATTACK; - } - } - else if ( playerAnim == PLAYER_RELOAD ) - { - idealActivity = ACT_HL2MP_GESTURE_RELOAD; - } - else if ( playerAnim == PLAYER_IDLE || playerAnim == PLAYER_WALK ) - { - if ( !( GetFlags() & FL_ONGROUND ) && GetActivity( ) == ACT_HL2MP_JUMP ) // Still jumping - { - idealActivity = GetActivity( ); - } - /* - else if ( GetWaterLevel() > 1 ) - { - if ( speed == 0 ) - idealActivity = ACT_HOVER; - else - idealActivity = ACT_SWIM; - } - */ - else - { - if ( GetFlags() & FL_DUCKING ) - { - if ( speed > 0 ) - { - idealActivity = ACT_HL2MP_WALK_CROUCH; - } - else - { - idealActivity = ACT_HL2MP_IDLE_CROUCH; - } - } - else - { - if ( speed > 0 ) - { - /* - if ( bRunning == false ) - { - idealActivity = ACT_WALK; - } - else - */ - { - idealActivity = ACT_HL2MP_RUN; - } - } - else - { - idealActivity = ACT_HL2MP_IDLE; - } - } - } - - idealActivity = TranslateTeamActivity( idealActivity ); - } - - if ( idealActivity == ACT_HL2MP_GESTURE_RANGE_ATTACK ) - { - RestartGesture( Weapon_TranslateActivity( idealActivity ) ); - - // FIXME: this seems a bit wacked - Weapon_SetActivity( Weapon_TranslateActivity( ACT_RANGE_ATTACK1 ), 0 ); - - return; - } - else if ( idealActivity == ACT_HL2MP_GESTURE_RELOAD ) - { - RestartGesture( Weapon_TranslateActivity( idealActivity ) ); - return; - } - else - { - SetActivity( idealActivity ); - - animDesired = SelectWeightedSequence( Weapon_TranslateActivity ( idealActivity ) ); - - if (animDesired == -1) - { - animDesired = SelectWeightedSequence( idealActivity ); - - if ( animDesired == -1 ) - { - animDesired = 0; - } - } - - // Already using the desired animation? - if ( GetSequence() == animDesired ) - return; - - m_flPlaybackRate = 1.0; - ResetSequence( animDesired ); - SetCycle( 0 ); - return; - } - - // Already using the desired animation? - if ( GetSequence() == animDesired ) - return; - - //Msg( "Set animation to %d\n", animDesired ); - // Reset to first frame of desired animation - ResetSequence( animDesired ); - SetCycle( 0 ); -} - - -extern int gEvilImpulse101; -//----------------------------------------------------------------------------- -// Purpose: Player reacts to bumping a weapon. -// Input : pWeapon - the weapon that the player bumped into. -// Output : Returns true if player picked up the weapon -//----------------------------------------------------------------------------- -bool CHL2MP_Player::BumpWeapon( CBaseCombatWeapon *pWeapon ) -{ - CBaseCombatCharacter *pOwner = pWeapon->GetOwner(); - - // Can I have this weapon type? - if ( !IsAllowedToPickupWeapons() ) - return false; - - if ( pOwner || !Weapon_CanUse( pWeapon ) || !g_pGameRules->CanHavePlayerItem( this, pWeapon ) ) - { - if ( gEvilImpulse101 ) - { - UTIL_Remove( pWeapon ); - } - return false; - } - - // Don't let the player fetch weapons through walls (use MASK_SOLID so that you can't pickup through windows) - if( !pWeapon->FVisible( this, MASK_SOLID ) && !(GetFlags() & FL_NOTARGET) ) - { - return false; - } - - bool bOwnsWeaponAlready = !!Weapon_OwnsThisType( pWeapon->GetClassname(), pWeapon->GetSubType()); - - if ( bOwnsWeaponAlready == true ) - { - //If we have room for the ammo, then "take" the weapon too. - if ( Weapon_EquipAmmoOnly( pWeapon ) ) - { - pWeapon->CheckRespawn(); - - UTIL_Remove( pWeapon ); - return true; - } - else - { - return false; - } - } - - pWeapon->CheckRespawn(); - Weapon_Equip( pWeapon ); - - return true; -} - -void CHL2MP_Player::ChangeTeam( int iTeam ) -{ -/* if ( GetNextTeamChangeTime() >= gpGlobals->curtime ) - { - char szReturnString[128]; - Q_snprintf( szReturnString, sizeof( szReturnString ), "Please wait %d more seconds before trying to switch teams again.\n", (int)(GetNextTeamChangeTime() - gpGlobals->curtime) ); - - ClientPrint( this, HUD_PRINTTALK, szReturnString ); - return; - }*/ - - bool bKill = false; - - if ( HL2MPRules()->IsTeamplay() != true && iTeam != TEAM_SPECTATOR ) - { - //don't let them try to join combine or rebels during deathmatch. - iTeam = TEAM_UNASSIGNED; - } - - if ( HL2MPRules()->IsTeamplay() == true ) - { - if ( iTeam != GetTeamNumber() && GetTeamNumber() != TEAM_UNASSIGNED ) - { - bKill = true; - } - } - - BaseClass::ChangeTeam( iTeam ); - - m_flNextTeamChangeTime = gpGlobals->curtime + TEAM_CHANGE_INTERVAL; - - if ( HL2MPRules()->IsTeamplay() == true ) - { - SetPlayerTeamModel(); - } - else - { - SetPlayerModel(); - } - - if ( iTeam == TEAM_SPECTATOR ) - { - RemoveAllItems( true ); - - State_Transition( STATE_OBSERVER_MODE ); - } - - if ( bKill == true ) - { - CommitSuicide(); - } -} - -bool CHL2MP_Player::HandleCommand_JoinTeam( int team ) -{ - if ( !GetGlobalTeam( team ) || team == 0 ) - { - Warning( "HandleCommand_JoinTeam( %d ) - invalid team index.\n", team ); - return false; - } - - if ( team == TEAM_SPECTATOR ) - { - // Prevent this is the cvar is set - if ( !mp_allowspectators.GetInt() ) - { - ClientPrint( this, HUD_PRINTCENTER, "#Cannot_Be_Spectator" ); - return false; - } - - if ( GetTeamNumber() != TEAM_UNASSIGNED && !IsDead() ) - { - m_fNextSuicideTime = gpGlobals->curtime; // allow the suicide to work - - CommitSuicide(); - - // add 1 to frags to balance out the 1 subtracted for killing yourself - IncrementFragCount( 1 ); - } - - ChangeTeam( TEAM_SPECTATOR ); - - return true; - } - else - { - StopObserverMode(); - State_Transition(STATE_ACTIVE); - } - - // Switch their actual team... - ChangeTeam( team ); - - return true; -} - -bool CHL2MP_Player::ClientCommand( const CCommand &args ) -{ - if ( FStrEq( args[0], "spectate" ) ) - { - if ( ShouldRunRateLimitedCommand( args ) ) - { - // instantly join spectators - HandleCommand_JoinTeam( TEAM_SPECTATOR ); - } - return true; - } - else if ( FStrEq( args[0], "jointeam" ) ) - { - if ( args.ArgC() < 2 ) - { - Warning( "Player sent bad jointeam syntax\n" ); - } - - if ( ShouldRunRateLimitedCommand( args ) ) - { - int iTeam = atoi( args[1] ); - HandleCommand_JoinTeam( iTeam ); - } - return true; - } - else if ( FStrEq( args[0], "joingame" ) ) - { - return true; - } - - return BaseClass::ClientCommand( args ); -} - -void CHL2MP_Player::CheatImpulseCommands( int iImpulse ) -{ - switch ( iImpulse ) - { - case 101: - { - if( sv_cheats->GetBool() ) - { - GiveAllItems(); - } - } - break; - - default: - BaseClass::CheatImpulseCommands( iImpulse ); - } -} - -bool CHL2MP_Player::ShouldRunRateLimitedCommand( const CCommand &args ) -{ - int i = m_RateLimitLastCommandTimes.Find( args[0] ); - if ( i == m_RateLimitLastCommandTimes.InvalidIndex() ) - { - m_RateLimitLastCommandTimes.Insert( args[0], gpGlobals->curtime ); - return true; - } - else if ( (gpGlobals->curtime - m_RateLimitLastCommandTimes[i]) < HL2MP_COMMAND_MAX_RATE ) - { - // Too fast. - return false; - } - else - { - m_RateLimitLastCommandTimes[i] = gpGlobals->curtime; - return true; - } -} - -void CHL2MP_Player::CreateViewModel( int index /*=0*/ ) -{ - Assert( index >= 0 && index < MAX_VIEWMODELS ); - - if ( GetViewModel( index ) ) - return; - - CPredictedViewModel *vm = ( CPredictedViewModel * )CreateEntityByName( "predicted_viewmodel" ); - if ( vm ) - { - vm->SetAbsOrigin( GetAbsOrigin() ); - vm->SetOwner( this ); - vm->SetIndex( index ); - DispatchSpawn( vm ); - vm->FollowEntity( this, false ); - m_hViewModel.Set( index, vm ); - } -} - -bool CHL2MP_Player::BecomeRagdollOnClient( const Vector &force ) -{ - return true; -} - -// -------------------------------------------------------------------------------- // -// Ragdoll entities. -// -------------------------------------------------------------------------------- // - -class CHL2MPRagdoll : public CBaseAnimatingOverlay -{ -public: - DECLARE_CLASS( CHL2MPRagdoll, CBaseAnimatingOverlay ); - DECLARE_SERVERCLASS(); - - // Transmit ragdolls to everyone. - virtual int UpdateTransmitState() - { - return SetTransmitState( FL_EDICT_ALWAYS ); - } - -public: - // In case the client has the player entity, we transmit the player index. - // In case the client doesn't have it, we transmit the player's model index, origin, and angles - // so they can create a ragdoll in the right place. - CNetworkHandle( CBaseEntity, m_hPlayer ); // networked entity handle - CNetworkVector( m_vecRagdollVelocity ); - CNetworkVector( m_vecRagdollOrigin ); -}; - -LINK_ENTITY_TO_CLASS( hl2mp_ragdoll, CHL2MPRagdoll ); - -IMPLEMENT_SERVERCLASS_ST_NOBASE( CHL2MPRagdoll, DT_HL2MPRagdoll ) - SendPropVector( SENDINFO(m_vecRagdollOrigin), -1, SPROP_COORD ), - SendPropEHandle( SENDINFO( m_hPlayer ) ), - SendPropModelIndex( SENDINFO( m_nModelIndex ) ), - SendPropInt ( SENDINFO(m_nForceBone), 8, 0 ), - SendPropVector ( SENDINFO(m_vecForce), -1, SPROP_NOSCALE ), - SendPropVector( SENDINFO( m_vecRagdollVelocity ) ) -END_SEND_TABLE() - - -void CHL2MP_Player::CreateRagdollEntity( void ) -{ - if ( m_hRagdoll ) - { - UTIL_RemoveImmediate( m_hRagdoll ); - m_hRagdoll = NULL; - } - - // If we already have a ragdoll, don't make another one. - CHL2MPRagdoll *pRagdoll = dynamic_cast< CHL2MPRagdoll* >( m_hRagdoll.Get() ); - - if ( !pRagdoll ) - { - // create a new one - pRagdoll = dynamic_cast< CHL2MPRagdoll* >( CreateEntityByName( "hl2mp_ragdoll" ) ); - } - - if ( pRagdoll ) - { - pRagdoll->m_hPlayer = this; - pRagdoll->m_vecRagdollOrigin = GetAbsOrigin(); - pRagdoll->m_vecRagdollVelocity = GetAbsVelocity(); - pRagdoll->m_nModelIndex = m_nModelIndex; - pRagdoll->m_nForceBone = m_nForceBone; - pRagdoll->m_vecForce = m_vecTotalBulletForce; - pRagdoll->SetAbsOrigin( GetAbsOrigin() ); - } - - // ragdolls will be removed on round restart automatically - m_hRagdoll = pRagdoll; -} - -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -int CHL2MP_Player::FlashlightIsOn( void ) -{ - return IsEffectActive( EF_DIMLIGHT ); -} - -extern ConVar flashlight; - -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -void CHL2MP_Player::FlashlightTurnOn( void ) -{ - if( flashlight.GetInt() > 0 && IsAlive() ) - { - AddEffects( EF_DIMLIGHT ); - EmitSound( "HL2Player.FlashlightOn" ); - } -} - - -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -void CHL2MP_Player::FlashlightTurnOff( void ) -{ - RemoveEffects( EF_DIMLIGHT ); - - if( IsAlive() ) - { - EmitSound( "HL2Player.FlashlightOff" ); - } -} - -void CHL2MP_Player::Weapon_Drop( CBaseCombatWeapon *pWeapon, const Vector *pvecTarget, const Vector *pVelocity ) -{ - //Drop a grenade if it's primed. - if ( GetActiveWeapon() ) - { - CBaseCombatWeapon *pGrenade = Weapon_OwnsThisType("weapon_frag"); - - if ( GetActiveWeapon() == pGrenade ) - { - if ( ( m_nButtons & IN_ATTACK ) || (m_nButtons & IN_ATTACK2) ) - { - DropPrimedFragGrenade( this, pGrenade ); - return; - } - } - } - - BaseClass::Weapon_Drop( pWeapon, pvecTarget, pVelocity ); -} - - -void CHL2MP_Player::DetonateTripmines( void ) -{ - CBaseEntity *pEntity = NULL; - - while ((pEntity = gEntList.FindEntityByClassname( pEntity, "npc_satchel" )) != NULL) - { - CSatchelCharge *pSatchel = dynamic_cast(pEntity); - if (pSatchel->m_bIsLive && pSatchel->GetThrower() == this ) - { - g_EventQueue.AddEvent( pSatchel, "Explode", 0.20, this, this ); - } - } - - // Play sound for pressing the detonator - EmitSound( "Weapon_SLAM.SatchelDetonate" ); -} - -void CHL2MP_Player::Event_Killed( const CTakeDamageInfo &info ) -{ - //update damage info with our accumulated physics force - CTakeDamageInfo subinfo = info; - subinfo.SetDamageForce( m_vecTotalBulletForce ); - - SetNumAnimOverlays( 0 ); - - // Note: since we're dead, it won't draw us on the client, but we don't set EF_NODRAW - // because we still want to transmit to the clients in our PVS. - CreateRagdollEntity(); - - DetonateTripmines(); - - BaseClass::Event_Killed( subinfo ); - - if ( info.GetDamageType() & DMG_DISSOLVE ) - { - if ( m_hRagdoll ) - { - m_hRagdoll->GetBaseAnimating()->Dissolve( NULL, gpGlobals->curtime, false, ENTITY_DISSOLVE_NORMAL ); - } - } - - CBaseEntity *pAttacker = info.GetAttacker(); - - if ( pAttacker ) - { - int iScoreToAdd = 1; - - if ( pAttacker == this ) - { - iScoreToAdd = -1; - } - - GetGlobalTeam( pAttacker->GetTeamNumber() )->AddScore( iScoreToAdd ); - } - - FlashlightTurnOff(); - - m_lifeState = LIFE_DEAD; - - RemoveEffects( EF_NODRAW ); // still draw player body - StopZooming(); -} - -int CHL2MP_Player::OnTakeDamage( const CTakeDamageInfo &inputInfo ) -{ - //return here if the player is in the respawn grace period vs. slams. - if ( gpGlobals->curtime < m_flSlamProtectTime && (inputInfo.GetDamageType() == DMG_BLAST ) ) - return 0; - - m_vecTotalBulletForce += inputInfo.GetDamageForce(); - - gamestats->Event_PlayerDamage( this, inputInfo ); - - return BaseClass::OnTakeDamage( inputInfo ); -} - -void CHL2MP_Player::DeathSound( const CTakeDamageInfo &info ) -{ - if ( m_hRagdoll && m_hRagdoll->GetBaseAnimating()->IsDissolving() ) - return; - - char szStepSound[128]; - - Q_snprintf( szStepSound, sizeof( szStepSound ), "%s.Die", GetPlayerModelSoundPrefix() ); - - const char *pModelName = STRING( GetModelName() ); - - CSoundParameters params; - if ( GetParametersForSound( szStepSound, params, pModelName ) == false ) - return; - - Vector vecOrigin = GetAbsOrigin(); - - CRecipientFilter filter; - filter.AddRecipientsByPAS( vecOrigin ); - - EmitSound_t ep; - ep.m_nChannel = params.channel; - ep.m_pSoundName = params.soundname; - ep.m_flVolume = params.volume; - ep.m_SoundLevel = params.soundlevel; - ep.m_nFlags = 0; - ep.m_nPitch = params.pitch; - ep.m_pOrigin = &vecOrigin; - - EmitSound( filter, entindex(), ep ); -} - -CBaseEntity* CHL2MP_Player::EntSelectSpawnPoint( void ) -{ - CBaseEntity *pSpot = NULL; - CBaseEntity *pLastSpawnPoint = g_pLastSpawn; - edict_t *player = edict(); - const char *pSpawnpointName = "info_player_deathmatch"; - - if ( HL2MPRules()->IsTeamplay() == true ) - { - if ( GetTeamNumber() == TEAM_COMBINE ) - { - pSpawnpointName = "info_player_combine"; - pLastSpawnPoint = g_pLastCombineSpawn; - } - else if ( GetTeamNumber() == TEAM_REBELS ) - { - pSpawnpointName = "info_player_rebel"; - pLastSpawnPoint = g_pLastRebelSpawn; - } - - if ( gEntList.FindEntityByClassname( NULL, pSpawnpointName ) == NULL ) - { - pSpawnpointName = "info_player_deathmatch"; - pLastSpawnPoint = g_pLastSpawn; - } - } - - pSpot = pLastSpawnPoint; - // Randomize the start spot - for ( int i = random->RandomInt(1,5); i > 0; i-- ) - pSpot = gEntList.FindEntityByClassname( pSpot, pSpawnpointName ); - if ( !pSpot ) // skip over the null point - pSpot = gEntList.FindEntityByClassname( pSpot, pSpawnpointName ); - - CBaseEntity *pFirstSpot = pSpot; - - do - { - if ( pSpot ) - { - // check if pSpot is valid - if ( g_pGameRules->IsSpawnPointValid( pSpot, this ) ) - { - if ( pSpot->GetLocalOrigin() == vec3_origin ) - { - pSpot = gEntList.FindEntityByClassname( pSpot, pSpawnpointName ); - continue; - } - - // if so, go to pSpot - goto ReturnSpot; - } - } - // increment pSpot - pSpot = gEntList.FindEntityByClassname( pSpot, pSpawnpointName ); - } while ( pSpot != pFirstSpot ); // loop if we're not back to the start - - // we haven't found a place to spawn yet, so kill any guy at the first spawn point and spawn there - if ( pSpot ) - { - CBaseEntity *ent = NULL; - for ( CEntitySphereQuery sphere( pSpot->GetAbsOrigin(), 128 ); (ent = sphere.GetCurrentEntity()) != NULL; sphere.NextEntity() ) - { - // if ent is a client, kill em (unless they are ourselves) - if ( ent->IsPlayer() && !(ent->edict() == player) ) - ent->TakeDamage( CTakeDamageInfo( GetContainingEntity(INDEXENT(0)), GetContainingEntity(INDEXENT(0)), 300, DMG_GENERIC ) ); - } - goto ReturnSpot; - } - - if ( !pSpot ) - { - pSpot = gEntList.FindEntityByClassname( pSpot, "info_player_start" ); - - if ( pSpot ) - goto ReturnSpot; - } - -ReturnSpot: - - if ( HL2MPRules()->IsTeamplay() == true ) - { - if ( GetTeamNumber() == TEAM_COMBINE ) - { - g_pLastCombineSpawn = pSpot; - } - else if ( GetTeamNumber() == TEAM_REBELS ) - { - g_pLastRebelSpawn = pSpot; - } - } - - g_pLastSpawn = pSpot; - - m_flSlamProtectTime = gpGlobals->curtime + 0.5; - - return pSpot; -} - - -CON_COMMAND( timeleft, "prints the time remaining in the match" ) -{ - CHL2MP_Player *pPlayer = ToHL2MPPlayer( UTIL_GetCommandClient() ); - - int iTimeRemaining = (int)HL2MPRules()->GetMapRemainingTime(); - - if ( iTimeRemaining == 0 ) - { - if ( pPlayer ) - { - ClientPrint( pPlayer, HUD_PRINTTALK, "This game has no timelimit." ); - } - else - { - Msg( "* No Time Limit *\n" ); - } - } - else - { - int iMinutes, iSeconds; - iMinutes = iTimeRemaining / 60; - iSeconds = iTimeRemaining % 60; - - char minutes[8]; - char seconds[8]; - - Q_snprintf( minutes, sizeof(minutes), "%d", iMinutes ); - Q_snprintf( seconds, sizeof(seconds), "%2.2d", iSeconds ); - - if ( pPlayer ) - { - ClientPrint( pPlayer, HUD_PRINTTALK, "Time left in map: %s1:%s2", minutes, seconds ); - } - else - { - Msg( "Time Remaining: %s:%s\n", minutes, seconds ); - } - } -} - - -void CHL2MP_Player::Reset() -{ - ResetDeathCount(); - ResetFragCount(); -} - -bool CHL2MP_Player::IsReady() -{ - return m_bReady; -} - -void CHL2MP_Player::SetReady( bool bReady ) -{ - m_bReady = bReady; -} - -void CHL2MP_Player::CheckChatText( char *p, int bufsize ) -{ - //Look for escape sequences and replace - - char *buf = new char[bufsize]; - int pos = 0; - - // Parse say text for escape sequences - for ( char *pSrc = p; pSrc != NULL && *pSrc != 0 && pos < bufsize-1; pSrc++ ) - { - // copy each char across - buf[pos] = *pSrc; - pos++; - } - - buf[pos] = '\0'; - - // copy buf back into p - Q_strncpy( p, buf, bufsize ); - - delete[] buf; - - const char *pReadyCheck = p; - - HL2MPRules()->CheckChatForReadySignal( this, pReadyCheck ); -} - -void CHL2MP_Player::State_Transition( HL2MPPlayerState newState ) -{ - State_Leave(); - State_Enter( newState ); -} - - -void CHL2MP_Player::State_Enter( HL2MPPlayerState newState ) -{ - m_iPlayerState = newState; - m_pCurStateInfo = State_LookupInfo( newState ); - - // Initialize the new state. - if ( m_pCurStateInfo && m_pCurStateInfo->pfnEnterState ) - (this->*m_pCurStateInfo->pfnEnterState)(); -} - - -void CHL2MP_Player::State_Leave() -{ - if ( m_pCurStateInfo && m_pCurStateInfo->pfnLeaveState ) - { - (this->*m_pCurStateInfo->pfnLeaveState)(); - } -} - - -void CHL2MP_Player::State_PreThink() -{ - if ( m_pCurStateInfo && m_pCurStateInfo->pfnPreThink ) - { - (this->*m_pCurStateInfo->pfnPreThink)(); - } -} - - -CHL2MPPlayerStateInfo *CHL2MP_Player::State_LookupInfo( HL2MPPlayerState state ) -{ - // This table MUST match the - static CHL2MPPlayerStateInfo playerStateInfos[] = - { - { STATE_ACTIVE, "STATE_ACTIVE", &CHL2MP_Player::State_Enter_ACTIVE, NULL, &CHL2MP_Player::State_PreThink_ACTIVE }, - { STATE_OBSERVER_MODE, "STATE_OBSERVER_MODE", &CHL2MP_Player::State_Enter_OBSERVER_MODE, NULL, &CHL2MP_Player::State_PreThink_OBSERVER_MODE } - }; - - for ( int i=0; i < ARRAYSIZE( playerStateInfos ); i++ ) - { - if ( playerStateInfos[i].m_iPlayerState == state ) - return &playerStateInfos[i]; - } - - return NULL; -} - -bool CHL2MP_Player::StartObserverMode(int mode) -{ - //we only want to go into observer mode if the player asked to, not on a death timeout - if ( m_bEnterObserver == true ) - { - VPhysicsDestroyObject(); - return BaseClass::StartObserverMode( mode ); - } - return false; -} - -void CHL2MP_Player::StopObserverMode() -{ - m_bEnterObserver = false; - BaseClass::StopObserverMode(); -} - -void CHL2MP_Player::State_Enter_OBSERVER_MODE() -{ - int observerMode = m_iObserverLastMode; - if ( IsNetClient() ) - { - const char *pIdealMode = engine->GetClientConVarValue( engine->IndexOfEdict( edict() ), "cl_spec_mode" ); - if ( pIdealMode ) - { - observerMode = atoi( pIdealMode ); - if ( observerMode <= OBS_MODE_FIXED || observerMode > OBS_MODE_ROAMING ) - { - observerMode = m_iObserverLastMode; - } - } - } - m_bEnterObserver = true; - StartObserverMode( observerMode ); -} - -void CHL2MP_Player::State_PreThink_OBSERVER_MODE() -{ - // Make sure nobody has changed any of our state. - // Assert( GetMoveType() == MOVETYPE_FLY ); - Assert( m_takedamage == DAMAGE_NO ); - Assert( IsSolidFlagSet( FSOLID_NOT_SOLID ) ); - // Assert( IsEffectActive( EF_NODRAW ) ); - - // Must be dead. - Assert( m_lifeState == LIFE_DEAD ); - Assert( pl.deadflag ); -} - - -void CHL2MP_Player::State_Enter_ACTIVE() -{ - SetMoveType( MOVETYPE_WALK ); - - // md 8/15/07 - They'll get set back to solid when they actually respawn. If we set them solid now and mp_forcerespawn - // is false, then they'll be spectating but blocking live players from moving. - // RemoveSolidFlags( FSOLID_NOT_SOLID ); - - m_Local.m_iHideHUD = 0; -} - - -void CHL2MP_Player::State_PreThink_ACTIVE() -{ - //we don't really need to do anything here. - //This state_prethink structure came over from CS:S and was doing an assert check that fails the way hl2dm handles death -} - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -bool CHL2MP_Player::CanHearAndReadChatFrom( CBasePlayer *pPlayer ) -{ - // can always hear the console unless we're ignoring all chat - if ( !pPlayer ) - return false; - - return true; -} diff --git a/sp/src/game/server/hl2mp/hl2mp_player.h b/sp/src/game/server/hl2mp/hl2mp_player.h deleted file mode 100644 index f91513c7..00000000 --- a/sp/src/game/server/hl2mp/hl2mp_player.h +++ /dev/null @@ -1,176 +0,0 @@ -//========= Copyright Valve Corporation, All rights reserved. ============// -// -// Purpose: -// -// $NoKeywords: $ -// -//=============================================================================// -#ifndef HL2MP_PLAYER_H -#define HL2MP_PLAYER_H -#pragma once - -class CHL2MP_Player; - -#include "basemultiplayerplayer.h" -#include "hl2_playerlocaldata.h" -#include "hl2_player.h" -#include "simtimer.h" -#include "soundenvelope.h" -#include "hl2mp_player_shared.h" -#include "hl2mp_gamerules.h" -#include "utldict.h" - -//============================================================================= -// >> HL2MP_Player -//============================================================================= -class CHL2MPPlayerStateInfo -{ -public: - HL2MPPlayerState m_iPlayerState; - const char *m_pStateName; - - void (CHL2MP_Player::*pfnEnterState)(); // Init and deinit the state. - void (CHL2MP_Player::*pfnLeaveState)(); - - void (CHL2MP_Player::*pfnPreThink)(); // Do a PreThink() in this state. -}; - -class CHL2MP_Player : public CHL2_Player -{ -public: - DECLARE_CLASS( CHL2MP_Player, CHL2_Player ); - - CHL2MP_Player(); - ~CHL2MP_Player( void ); - - static CHL2MP_Player *CreatePlayer( const char *className, edict_t *ed ) - { - CHL2MP_Player::s_PlayerEdict = ed; - return (CHL2MP_Player*)CreateEntityByName( className ); - } - - DECLARE_SERVERCLASS(); - DECLARE_DATADESC(); - - virtual void Precache( void ); - virtual void Spawn( void ); - virtual void PostThink( void ); - virtual void PreThink( void ); - virtual void PlayerDeathThink( void ); - virtual void SetAnimation( PLAYER_ANIM playerAnim ); - virtual bool HandleCommand_JoinTeam( int team ); - virtual bool ClientCommand( const CCommand &args ); - virtual void CreateViewModel( int viewmodelindex = 0 ); - virtual bool BecomeRagdollOnClient( const Vector &force ); - virtual void Event_Killed( const CTakeDamageInfo &info ); - virtual int OnTakeDamage( const CTakeDamageInfo &inputInfo ); - virtual bool WantsLagCompensationOnEntity( const CBasePlayer *pPlayer, const CUserCmd *pCmd, const CBitVec *pEntityTransmitBits ) const; - virtual void FireBullets ( const FireBulletsInfo_t &info ); - virtual bool Weapon_Switch( CBaseCombatWeapon *pWeapon, int viewmodelindex = 0); - virtual bool BumpWeapon( CBaseCombatWeapon *pWeapon ); - virtual void ChangeTeam( int iTeam ); - virtual void PickupObject ( CBaseEntity *pObject, bool bLimitMassAndSize ); - virtual void PlayStepSound( Vector &vecOrigin, surfacedata_t *psurface, float fvol, bool force ); - virtual void Weapon_Drop( CBaseCombatWeapon *pWeapon, const Vector *pvecTarget = NULL, const Vector *pVelocity = NULL ); - virtual void UpdateOnRemove( void ); - virtual void DeathSound( const CTakeDamageInfo &info ); - virtual CBaseEntity* EntSelectSpawnPoint( void ); - - int FlashlightIsOn( void ); - void FlashlightTurnOn( void ); - void FlashlightTurnOff( void ); - void PrecacheFootStepSounds( void ); - bool ValidatePlayerModel( const char *pModel ); - - QAngle GetAnimEyeAngles( void ) { return m_angEyeAngles.Get(); } - - Vector GetAttackSpread( CBaseCombatWeapon *pWeapon, CBaseEntity *pTarget = NULL ); - - void CheatImpulseCommands( int iImpulse ); - void CreateRagdollEntity( void ); - void GiveAllItems( void ); - void GiveDefaultItems( void ); - - void NoteWeaponFired( void ); - - void ResetAnimation( void ); - void SetPlayerModel( void ); - void SetPlayerTeamModel( void ); - Activity TranslateTeamActivity( Activity ActToTranslate ); - - float GetNextModelChangeTime( void ) { return m_flNextModelChangeTime; } - float GetNextTeamChangeTime( void ) { return m_flNextTeamChangeTime; } - void PickDefaultSpawnTeam( void ); - void SetupPlayerSoundsByModel( const char *pModelName ); - const char *GetPlayerModelSoundPrefix( void ); - int GetPlayerModelType( void ) { return m_iPlayerSoundType; } - - void DetonateTripmines( void ); - - void Reset(); - - bool IsReady(); - void SetReady( bool bReady ); - - void CheckChatText( char *p, int bufsize ); - - void State_Transition( HL2MPPlayerState newState ); - void State_Enter( HL2MPPlayerState newState ); - void State_Leave(); - void State_PreThink(); - CHL2MPPlayerStateInfo *State_LookupInfo( HL2MPPlayerState state ); - - void State_Enter_ACTIVE(); - void State_PreThink_ACTIVE(); - void State_Enter_OBSERVER_MODE(); - void State_PreThink_OBSERVER_MODE(); - - - virtual bool StartObserverMode( int mode ); - virtual void StopObserverMode( void ); - - - Vector m_vecTotalBulletForce; //Accumulator for bullet force in a single frame - - // Tracks our ragdoll entity. - CNetworkHandle( CBaseEntity, m_hRagdoll ); // networked entity handle - - virtual bool CanHearAndReadChatFrom( CBasePlayer *pPlayer ); - - -private: - - CNetworkQAngle( m_angEyeAngles ); - CPlayerAnimState m_PlayerAnimState; - - int m_iLastWeaponFireUsercmd; - int m_iModelType; - CNetworkVar( int, m_iSpawnInterpCounter ); - CNetworkVar( int, m_iPlayerSoundType ); - - float m_flNextModelChangeTime; - float m_flNextTeamChangeTime; - - float m_flSlamProtectTime; - - HL2MPPlayerState m_iPlayerState; - CHL2MPPlayerStateInfo *m_pCurStateInfo; - - bool ShouldRunRateLimitedCommand( const CCommand &args ); - - // This lets us rate limit the commands the players can execute so they don't overflow things like reliable buffers. - CUtlDict m_RateLimitLastCommandTimes; - - bool m_bEnterObserver; - bool m_bReady; -}; - -inline CHL2MP_Player *ToHL2MPPlayer( CBaseEntity *pEntity ) -{ - if ( !pEntity || !pEntity->IsPlayer() ) - return NULL; - - return dynamic_cast( pEntity ); -} - -#endif //HL2MP_PLAYER_H diff --git a/sp/src/game/server/hl2mp/te_hl2mp_shotgun_shot.cpp b/sp/src/game/server/hl2mp/te_hl2mp_shotgun_shot.cpp deleted file mode 100644 index 6c937765..00000000 --- a/sp/src/game/server/hl2mp/te_hl2mp_shotgun_shot.cpp +++ /dev/null @@ -1,104 +0,0 @@ -//========= Copyright Valve Corporation, All rights reserved. ============// -// -// Purpose: -// -// $Workfile: $ -// $Date: $ -// -//----------------------------------------------------------------------------- -// $Log: $ -// -// $NoKeywords: $ -//=============================================================================// -#include "cbase.h" -#include "basetempentity.h" - - -#define NUM_BULLET_SEED_BITS 8 - - -//----------------------------------------------------------------------------- -// Purpose: Display's a blood sprite -//----------------------------------------------------------------------------- -class CTEHL2MPFireBullets : public CBaseTempEntity -{ -public: - DECLARE_CLASS( CTEHL2MPFireBullets, CBaseTempEntity ); - DECLARE_SERVERCLASS(); - - CTEHL2MPFireBullets( const char *name ); - virtual ~CTEHL2MPFireBullets( void ); - -public: - CNetworkVar( int, m_iPlayer ); - CNetworkVector( m_vecOrigin ); - CNetworkVector( m_vecDir ); - CNetworkVar( int, m_iAmmoID ); - CNetworkVar( int, m_iSeed ); - CNetworkVar( int, m_iShots ); - CNetworkVar( float, m_flSpread ); - CNetworkVar( bool, m_bDoImpacts ); - CNetworkVar( bool, m_bDoTracers ); -}; - -//----------------------------------------------------------------------------- -// Purpose: -// Input : *name - -//----------------------------------------------------------------------------- -CTEHL2MPFireBullets::CTEHL2MPFireBullets( const char *name ) : - CBaseTempEntity( name ) -{ -} - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -CTEHL2MPFireBullets::~CTEHL2MPFireBullets( void ) -{ -} - -IMPLEMENT_SERVERCLASS_ST_NOBASE(CTEHL2MPFireBullets, DT_TEHL2MPFireBullets) - SendPropVector( SENDINFO(m_vecOrigin), -1, SPROP_COORD ), - SendPropVector( SENDINFO(m_vecDir), -1 ), - SendPropInt( SENDINFO( m_iAmmoID ), 5, SPROP_UNSIGNED ), - SendPropInt( SENDINFO( m_iSeed ), NUM_BULLET_SEED_BITS, SPROP_UNSIGNED ), - SendPropInt( SENDINFO( m_iShots ), 5, SPROP_UNSIGNED ), - SendPropInt( SENDINFO( m_iPlayer ), 6, SPROP_UNSIGNED ), // max 64 players, see MAX_PLAYERS - SendPropFloat( SENDINFO( m_flSpread ), 10, 0, 0, 1 ), - SendPropBool( SENDINFO( m_bDoImpacts ) ), - SendPropBool( SENDINFO( m_bDoTracers ) ), -END_SEND_TABLE() - - -// Singleton -static CTEHL2MPFireBullets g_TEHL2MPFireBullets( "Shotgun Shot" ); - - -void TE_HL2MPFireBullets( - int iPlayerIndex, - const Vector &vOrigin, - const Vector &vDir, - int iAmmoID, - int iSeed, - int iShots, - float flSpread, - bool bDoTracers, - bool bDoImpacts ) -{ - CPASFilter filter( vOrigin ); - filter.UsePredictionRules(); - - g_TEHL2MPFireBullets.m_iPlayer = iPlayerIndex; - g_TEHL2MPFireBullets.m_vecOrigin = vOrigin; - g_TEHL2MPFireBullets.m_vecDir = vDir; - g_TEHL2MPFireBullets.m_iSeed = iSeed; - g_TEHL2MPFireBullets.m_iShots = iShots; - g_TEHL2MPFireBullets.m_flSpread = flSpread; - g_TEHL2MPFireBullets.m_iAmmoID = iAmmoID; - g_TEHL2MPFireBullets.m_bDoTracers = bDoTracers; - g_TEHL2MPFireBullets.m_bDoImpacts = bDoImpacts; - - Assert( iSeed < (1 << NUM_BULLET_SEED_BITS) ); - - g_TEHL2MPFireBullets.Create( filter, 0 ); -} diff --git a/sp/src/game/server/hl2mp/te_hl2mp_shotgun_shot.h b/sp/src/game/server/hl2mp/te_hl2mp_shotgun_shot.h deleted file mode 100644 index d6a68330..00000000 --- a/sp/src/game/server/hl2mp/te_hl2mp_shotgun_shot.h +++ /dev/null @@ -1,26 +0,0 @@ -//========= Copyright Valve Corporation, All rights reserved. ============// -// -// Purpose: -// -//=============================================================================// - -#ifndef TE_HL2MP_SHOTGUN_SHOT_H -#define TE_HL2MP_SHOTGUN_SHOT_H -#ifdef _WIN32 -#pragma once -#endif - - -void TE_HL2MPFireBullets( - int iPlayerIndex, - const Vector &vOrigin, - const Vector &vDir, - int iAmmoID, - int iSeed, - int iShots, - float flSpread, - bool bDoTracers, - bool bDoImpacts ); - - -#endif // TE_HL2MP_SHOTGUN_SHOT_H diff --git a/sp/src/game/server/server_episodic.vcxproj b/sp/src/game/server/server_episodic.vcxproj index b7657c3f..ce392160 100644 --- a/sp/src/game/server/server_episodic.vcxproj +++ b/sp/src/game/server/server_episodic.vcxproj @@ -19,7 +19,7 @@ DynamicLibrary MultiByte server - v120 + v120_xp DynamicLibrary @@ -58,9 +58,6 @@ false true - - true - if EXIST ..\..\..\game\mod_episodic\bin\.\$(TargetFileName) for /f "delims=" %%A in ('attrib "..\..\..\game\mod_episodic\bin\.\$(TargetFileName)"') do set valveTmpIsReadOnly="%%A" @@ -74,7 +71,7 @@ if ERRORLEVEL 1 exit /b 1 /Zm200 /Gw Disabled ..\..\common;..\..\public;..\..\public\tier0;..\..\public\tier1;..\..\game\server\generated_proto_mod_episodic;..\..\thirdparty\protobuf-2.3.0\src;.\;..\..\game\shared;..\..\utils\common;..\..\game\shared\econ;..\..\game\server\NextBot;..\..\game\shared\hl2;..\..\game\shared\episodic;.\hl2;.\episodic - VPC;RAD_TELEMETRY_DISABLED;_HAS_ITERATOR_DEBUGGING=0;WIN32;_WIN32;_DEBUG;DEBUG;_WINDOWS;_USRDLL;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_ALLOW_RUNTIME_LIBRARY_MISMATCH;_ALLOW_ITERATOR_DEBUG_LEVEL_MISMATCH;_ALLOW_MSC_VER_MISMATCH;%(PreprocessorDefinitions);COMPILER_MSVC32;COMPILER_MSVC32;COMPILER_MSVC;_DLL_EXT=.dll;DLLNAME=server;BINK_VIDEO;AVI_VIDEO;WMV_VIDEO;DEV_BUILD;FRAME_POINTER_OMISSION_DISABLED;GAME_DLL;VECTOR;VERSION_SAFE_STEAM_API_INTERFACES;PROTECTED_THINGS_ENABLE;sprintf=use_Q_snprintf_instead_of_sprintf;strncpy=use_Q_strncpy_instead;_snprintf=use_Q_snprintf_instead;fopen=dont_use_fopen;HL2_DLL;HL2_EPISODIC;USES_SAVERESTORE;_EXTERNAL_DLL_EXT=.dll;VPCGAMECAPS=VALVE;PROJECTDIR=C:\sourceproject\halflife2chaos\sp\src\game\server;_DLL_EXT=.dll;VPCGAME=valve;SOURCE1=1 + VPC;RAD_TELEMETRY_DISABLED;_HAS_ITERATOR_DEBUGGING=0;WIN32;_WIN32;_DEBUG;DEBUG;_WINDOWS;_USRDLL;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_ALLOW_RUNTIME_LIBRARY_MISMATCH;_ALLOW_ITERATOR_DEBUG_LEVEL_MISMATCH;_ALLOW_MSC_VER_MISMATCH;%(PreprocessorDefinitions);COMPILER_MSVC32;COMPILER_MSVC32;COMPILER_MSVC;_DLL_EXT=.dll;DLLNAME=server;BINK_VIDEO;AVI_VIDEO;WMV_VIDEO;DEV_BUILD;FRAME_POINTER_OMISSION_DISABLED;GAME_DLL;VECTOR;VERSION_SAFE_STEAM_API_INTERFACES;PROTECTED_THINGS_ENABLE;sprintf=use_Q_snprintf_instead_of_sprintf;strncpy=use_Q_strncpy_instead;_snprintf=use_Q_snprintf_instead;fopen=dont_use_fopen;HL2_DLL;HL2_EPISODIC;USES_SAVERESTORE;_EXTERNAL_DLL_EXT=.dll;VPCGAMECAPS=VALVE;PROJECTDIR=C:\sourceproject\halflife2chaos\sp\src\game\server;_DLL_EXT=.dll;SOURCE1=1;VPCGAME=valve true false Default @@ -100,7 +97,6 @@ if ERRORLEVEL 1 exit /b 1 true $(IntDir)/ Prompt - true ;_DEBUG;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;%(PreprocessorDefinitions) @@ -119,8 +115,7 @@ if ERRORLEVEL 1 exit /b 1 true $(IntDir)/$(TargetName).pdb Windows - - + MachineX86 PromptImmediately false @@ -174,7 +169,7 @@ if ERRORLEVEL 1 exit /b 1 true Speed ..\..\common;..\..\public;..\..\public\tier0;..\..\public\tier1;..\..\game\server\generated_proto_mod_episodic;..\..\thirdparty\protobuf-2.3.0\src;.\;..\..\game\shared;..\..\utils\common;..\..\game\shared\econ;..\..\game\server\NextBot;..\..\game\shared\hl2;..\..\game\shared\episodic;.\hl2;.\episodic - VPC;RAD_TELEMETRY_DISABLED;WIN32;_WIN32;NDEBUG;_WINDOWS;_USRDLL;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_ALLOW_RUNTIME_LIBRARY_MISMATCH;_ALLOW_ITERATOR_DEBUG_LEVEL_MISMATCH;_ALLOW_MSC_VER_MISMATCH;%(PreprocessorDefinitions);COMPILER_MSVC32;COMPILER_MSVC32;COMPILER_MSVC;_DLL_EXT=.dll;DLLNAME=server;BINK_VIDEO;AVI_VIDEO;WMV_VIDEO;DEV_BUILD;FRAME_POINTER_OMISSION_DISABLED;GAME_DLL;VECTOR;VERSION_SAFE_STEAM_API_INTERFACES;PROTECTED_THINGS_ENABLE;sprintf=use_Q_snprintf_instead_of_sprintf;strncpy=use_Q_strncpy_instead;_snprintf=use_Q_snprintf_instead;fopen=dont_use_fopen;HL2_DLL;HL2_EPISODIC;USES_SAVERESTORE;_EXTERNAL_DLL_EXT=.dll;VPCGAMECAPS=VALVE;PROJECTDIR=C:\sourceproject\halflife2chaos\sp\src\game\server;_DLL_EXT=.dll;VPCGAME=valve;SOURCE1=1 + VPC;RAD_TELEMETRY_DISABLED;WIN32;_WIN32;NDEBUG;_WINDOWS;_USRDLL;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_ALLOW_RUNTIME_LIBRARY_MISMATCH;_ALLOW_ITERATOR_DEBUG_LEVEL_MISMATCH;_ALLOW_MSC_VER_MISMATCH;%(PreprocessorDefinitions);COMPILER_MSVC32;COMPILER_MSVC32;COMPILER_MSVC;_DLL_EXT=.dll;DLLNAME=server;BINK_VIDEO;AVI_VIDEO;WMV_VIDEO;DEV_BUILD;FRAME_POINTER_OMISSION_DISABLED;GAME_DLL;VECTOR;VERSION_SAFE_STEAM_API_INTERFACES;PROTECTED_THINGS_ENABLE;sprintf=use_Q_snprintf_instead_of_sprintf;strncpy=use_Q_strncpy_instead;_snprintf=use_Q_snprintf_instead;fopen=dont_use_fopen;HL2_DLL;HL2_EPISODIC;USES_SAVERESTORE;_EXTERNAL_DLL_EXT=.dll;VPCGAMECAPS=VALVE;PROJECTDIR=C:\sourceproject\halflife2chaos\sp\src\game\server;_DLL_EXT=.dll;SOURCE1=1;VPCGAME=valve true false MultiThreaded @@ -220,8 +215,7 @@ if ERRORLEVEL 1 exit /b 1 Windows true false - - + MachineX86 PromptImmediately false @@ -814,6 +808,7 @@ exit 1 + @@ -832,6 +827,7 @@ exit 1 + @@ -1447,6 +1443,7 @@ exit 1 + @@ -1522,10 +1519,10 @@ exit 1 Compiling pointeroverride.asm - "$(VCInstallDir)bin\ml.exe" /safeseh /c /Cp /Zi /Fo"$(IntDir)\%(Filename).obj" "%(FullPath)" + "$(VCInstallDir)bin\ml.exe" /safeseh /c /Cp /Zi /Fo"$(IntDir)\%(Filename).obj" "%(FullPath)" $(IntDir)\%(Filename).obj Compiling pointeroverride.asm - "$(VCInstallDir)bin\ml.exe" /safeseh /c /Cp /Zi /Fo"$(IntDir)\%(Filename).obj" "%(FullPath)" + "$(VCInstallDir)bin\ml.exe" /safeseh /c /Cp /Zi /Fo"$(IntDir)\%(Filename).obj" "%(FullPath)" $(IntDir)\%(Filename).obj @@ -1559,4 +1556,4 @@ echo crc_complete > C:\sourceproject\halflife2chaos\sp\src\game\server\server - \ No newline at end of file + diff --git a/sp/src/game/server/server_episodic.vcxproj.filters b/sp/src/game/server/server_episodic.vcxproj.filters index 5c3bf64e..176e49a8 100644 --- a/sp/src/game/server/server_episodic.vcxproj.filters +++ b/sp/src/game/server/server_episodic.vcxproj.filters @@ -1748,6 +1748,9 @@ Source Files\HL2 DLL + + Source Files\HL2 DLL + Source Files\HL2 DLL @@ -3319,6 +3322,9 @@ Source Files\HL2 DLL + + Source Files\HL2 DLL + Source Files\HL2 DLL diff --git a/sp/src/game/server/server_episodic.vcxproj.vpc_crc b/sp/src/game/server/server_episodic.vcxproj.vpc_crc index 11fc6043..7f27e27d 100644 --- a/sp/src/game/server/server_episodic.vcxproj.vpc_crc +++ b/sp/src/game/server/server_episodic.vcxproj.vpc_crc @@ -1,7 +1,7 @@ [vpc crc file version 2] 8209bbc3 C:\sourceproject\halflife2chaos\sp\src\devtools\bin\vpc.exe _Nc_VS2013/vpcgame:valve_ -2919ad95 server_episodic.vpc +2cf78c7c server_episodic.vpc cd2921c2 ..\..\game\server\server_base.vpc 4832e67a ..\..\vpc_scripts\source_dll_base.vpc d752cf80 ..\..\vpc_scripts\platform_dirs.vpc diff --git a/sp/src/game/server/server_episodic.vpc b/sp/src/game/server/server_episodic.vpc index db50072e..6ca61f68 100644 --- a/sp/src/game/server/server_episodic.vpc +++ b/sp/src/game/server/server_episodic.vpc @@ -263,6 +263,8 @@ $Project "Server (Episodic)" $File "hl2\weapon_pistol.cpp" $File "hl2\weapon_rpg.cpp" $File "hl2\weapon_rpg.h" + $File "hl2\weapon_slam.cpp" + $File "hl2\weapon_slam.h" $File "hl2\weapon_shotgun.cpp" $File "hl2\weapon_smg1.cpp" $File "episodic\weapon_oldmanharpoon.cpp" diff --git a/sp/src/game/server/server_hl2.vcxproj b/sp/src/game/server/server_hl2.vcxproj index de012f67..fecf2dc0 100644 --- a/sp/src/game/server/server_hl2.vcxproj +++ b/sp/src/game/server/server_hl2.vcxproj @@ -19,7 +19,7 @@ DynamicLibrary MultiByte server - v120 + v120_xp DynamicLibrary @@ -58,9 +58,6 @@ false true - - true - if EXIST ..\..\..\game\mod_hl2\bin\.\$(TargetFileName) for /f "delims=" %%A in ('attrib "..\..\..\game\mod_hl2\bin\.\$(TargetFileName)"') do set valveTmpIsReadOnly="%%A" @@ -74,7 +71,7 @@ if ERRORLEVEL 1 exit /b 1 /Zm200 /Gw Disabled ..\..\common;..\..\public;..\..\public\tier0;..\..\public\tier1;..\..\game\server\generated_proto_mod_hl2;..\..\thirdparty\protobuf-2.3.0\src;.\;..\..\game\shared;..\..\utils\common;..\..\game\shared\econ;..\..\game\server\NextBot;..\..\game\shared\hl2;.\hl2 - VPC;RAD_TELEMETRY_DISABLED;_HAS_ITERATOR_DEBUGGING=0;WIN32;_WIN32;_DEBUG;DEBUG;_WINDOWS;_USRDLL;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_ALLOW_RUNTIME_LIBRARY_MISMATCH;_ALLOW_ITERATOR_DEBUG_LEVEL_MISMATCH;_ALLOW_MSC_VER_MISMATCH;%(PreprocessorDefinitions);COMPILER_MSVC32;COMPILER_MSVC32;COMPILER_MSVC;_DLL_EXT=.dll;DLLNAME=server;BINK_VIDEO;AVI_VIDEO;WMV_VIDEO;DEV_BUILD;FRAME_POINTER_OMISSION_DISABLED;GAME_DLL;VECTOR;VERSION_SAFE_STEAM_API_INTERFACES;PROTECTED_THINGS_ENABLE;sprintf=use_Q_snprintf_instead_of_sprintf;strncpy=use_Q_strncpy_instead;_snprintf=use_Q_snprintf_instead;fopen=dont_use_fopen;HL2_DLL;USES_SAVERESTORE;_EXTERNAL_DLL_EXT=.dll;VPCGAMECAPS=VALVE;PROJECTDIR=C:\sourceproject\halflife2chaos\sp\src\game\server;_DLL_EXT=.dll;VPCGAME=valve;SOURCE1=1 + VPC;RAD_TELEMETRY_DISABLED;_HAS_ITERATOR_DEBUGGING=0;WIN32;_WIN32;_DEBUG;DEBUG;_WINDOWS;_USRDLL;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_ALLOW_RUNTIME_LIBRARY_MISMATCH;_ALLOW_ITERATOR_DEBUG_LEVEL_MISMATCH;_ALLOW_MSC_VER_MISMATCH;%(PreprocessorDefinitions);COMPILER_MSVC32;COMPILER_MSVC32;COMPILER_MSVC;_DLL_EXT=.dll;DLLNAME=server;BINK_VIDEO;AVI_VIDEO;WMV_VIDEO;DEV_BUILD;FRAME_POINTER_OMISSION_DISABLED;GAME_DLL;VECTOR;VERSION_SAFE_STEAM_API_INTERFACES;PROTECTED_THINGS_ENABLE;sprintf=use_Q_snprintf_instead_of_sprintf;strncpy=use_Q_strncpy_instead;_snprintf=use_Q_snprintf_instead;fopen=dont_use_fopen;HL2_DLL;USES_SAVERESTORE;_EXTERNAL_DLL_EXT=.dll;VPCGAMECAPS=VALVE;PROJECTDIR=C:\sourceproject\halflife2chaos\sp\src\game\server;_DLL_EXT=.dll;SOURCE1=1;VPCGAME=valve true false Default @@ -100,7 +97,6 @@ if ERRORLEVEL 1 exit /b 1 true $(IntDir)/ Prompt - true ;_DEBUG;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;%(PreprocessorDefinitions) @@ -119,8 +115,7 @@ if ERRORLEVEL 1 exit /b 1 true $(IntDir)/$(TargetName).pdb Windows - - + MachineX86 PromptImmediately false @@ -170,7 +165,7 @@ if ERRORLEVEL 1 exit /b 1 true Speed ..\..\common;..\..\public;..\..\public\tier0;..\..\public\tier1;..\..\game\server\generated_proto_mod_hl2;..\..\thirdparty\protobuf-2.3.0\src;.\;..\..\game\shared;..\..\utils\common;..\..\game\shared\econ;..\..\game\server\NextBot;..\..\game\shared\hl2;.\hl2 - VPC;RAD_TELEMETRY_DISABLED;WIN32;_WIN32;NDEBUG;_WINDOWS;_USRDLL;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_ALLOW_RUNTIME_LIBRARY_MISMATCH;_ALLOW_ITERATOR_DEBUG_LEVEL_MISMATCH;_ALLOW_MSC_VER_MISMATCH;%(PreprocessorDefinitions);COMPILER_MSVC32;COMPILER_MSVC32;COMPILER_MSVC;_DLL_EXT=.dll;DLLNAME=server;BINK_VIDEO;AVI_VIDEO;WMV_VIDEO;DEV_BUILD;FRAME_POINTER_OMISSION_DISABLED;GAME_DLL;VECTOR;VERSION_SAFE_STEAM_API_INTERFACES;PROTECTED_THINGS_ENABLE;sprintf=use_Q_snprintf_instead_of_sprintf;strncpy=use_Q_strncpy_instead;_snprintf=use_Q_snprintf_instead;fopen=dont_use_fopen;HL2_DLL;USES_SAVERESTORE;_EXTERNAL_DLL_EXT=.dll;VPCGAMECAPS=VALVE;PROJECTDIR=C:\sourceproject\halflife2chaos\sp\src\game\server;_DLL_EXT=.dll;VPCGAME=valve;SOURCE1=1 + VPC;RAD_TELEMETRY_DISABLED;WIN32;_WIN32;NDEBUG;_WINDOWS;_USRDLL;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_ALLOW_RUNTIME_LIBRARY_MISMATCH;_ALLOW_ITERATOR_DEBUG_LEVEL_MISMATCH;_ALLOW_MSC_VER_MISMATCH;%(PreprocessorDefinitions);COMPILER_MSVC32;COMPILER_MSVC32;COMPILER_MSVC;_DLL_EXT=.dll;DLLNAME=server;BINK_VIDEO;AVI_VIDEO;WMV_VIDEO;DEV_BUILD;FRAME_POINTER_OMISSION_DISABLED;GAME_DLL;VECTOR;VERSION_SAFE_STEAM_API_INTERFACES;PROTECTED_THINGS_ENABLE;sprintf=use_Q_snprintf_instead_of_sprintf;strncpy=use_Q_strncpy_instead;_snprintf=use_Q_snprintf_instead;fopen=dont_use_fopen;HL2_DLL;USES_SAVERESTORE;_EXTERNAL_DLL_EXT=.dll;VPCGAMECAPS=VALVE;PROJECTDIR=C:\sourceproject\halflife2chaos\sp\src\game\server;_DLL_EXT=.dll;SOURCE1=1;VPCGAME=valve true false MultiThreaded @@ -216,8 +211,7 @@ if ERRORLEVEL 1 exit /b 1 Windows true false - - + MachineX86 PromptImmediately false @@ -800,6 +794,7 @@ exit 1 + @@ -819,6 +814,7 @@ exit 1 + @@ -1410,6 +1406,7 @@ exit 1 + @@ -1521,4 +1518,4 @@ echo crc_complete > C:\sourceproject\halflife2chaos\sp\src\game\server\server - \ No newline at end of file + diff --git a/sp/src/game/server/server_hl2.vcxproj.filters b/sp/src/game/server/server_hl2.vcxproj.filters index d908f901..7a4930c8 100644 --- a/sp/src/game/server/server_hl2.vcxproj.filters +++ b/sp/src/game/server/server_hl2.vcxproj.filters @@ -1733,6 +1733,9 @@ Source Files\HL2 DLL + + Source Files\HL2 DLL + Source Files\HL2 DLL @@ -3250,6 +3253,9 @@ Source Files\HL2 DLL + + Source Files\HL2 DLL + Source Files\HL2 DLL diff --git a/sp/src/game/server/server_hl2.vcxproj.vpc_crc b/sp/src/game/server/server_hl2.vcxproj.vpc_crc index ffd22000..2677f787 100644 --- a/sp/src/game/server/server_hl2.vcxproj.vpc_crc +++ b/sp/src/game/server/server_hl2.vcxproj.vpc_crc @@ -1,7 +1,7 @@ [vpc crc file version 2] 8209bbc3 C:\sourceproject\halflife2chaos\sp\src\devtools\bin\vpc.exe _Nc_VS2013/vpcgame:valve_ -ad055d7e server_hl2.vpc +bcc57729 server_hl2.vpc cd2921c2 ..\..\game\server\server_base.vpc 4832e67a ..\..\vpc_scripts\source_dll_base.vpc d752cf80 ..\..\vpc_scripts\platform_dirs.vpc diff --git a/sp/src/game/server/server_hl2.vpc b/sp/src/game/server/server_hl2.vpc index c7aba493..ab87e4fc 100644 --- a/sp/src/game/server/server_hl2.vpc +++ b/sp/src/game/server/server_hl2.vpc @@ -248,6 +248,8 @@ $Project "Server (HL2)" $File "hl2\weapon_pistol.cpp" $File "hl2\weapon_rpg.cpp" $File "hl2\weapon_rpg.h" + $File "hl2\weapon_slam.cpp" + $File "hl2\weapon_slam.h" $File "hl2\weapon_shotgun.cpp" $File "hl2\weapon_smg1.cpp" $File "hl2\weapon_stunstick.cpp" diff --git a/sp/src/game/shared/hl2mp/hl2mp_gamerules.cpp b/sp/src/game/shared/hl2mp/hl2mp_gamerules.cpp deleted file mode 100644 index 604e409c..00000000 --- a/sp/src/game/shared/hl2mp/hl2mp_gamerules.cpp +++ /dev/null @@ -1,1280 +0,0 @@ -//========= Copyright Valve Corporation, All rights reserved. ============// -// -// Purpose: -// -// $NoKeywords: $ -//=============================================================================// -#include "cbase.h" -#include "hl2mp_gamerules.h" -#include "viewport_panel_names.h" -#include "gameeventdefs.h" -#include -#include "ammodef.h" - -#ifdef CLIENT_DLL - #include "c_hl2mp_player.h" -#else - - #include "eventqueue.h" - #include "player.h" - #include "gamerules.h" - #include "game.h" - #include "items.h" - #include "entitylist.h" - #include "mapentities.h" - #include "in_buttons.h" - #include - #include "voice_gamemgr.h" - #include "iscorer.h" - #include "hl2mp_player.h" - #include "weapon_hl2mpbasehlmpcombatweapon.h" - #include "team.h" - #include "voice_gamemgr.h" - #include "hl2mp_gameinterface.h" - #include "hl2mp_cvars.h" - -#ifdef DEBUG - #include "hl2mp_bot_temp.h" -#endif - -extern void respawn(CBaseEntity *pEdict, bool fCopyCorpse); - -extern bool FindInList( const char **pStrings, const char *pToFind ); - -ConVar sv_hl2mp_weapon_respawn_time( "sv_hl2mp_weapon_respawn_time", "20", FCVAR_GAMEDLL | FCVAR_NOTIFY ); -ConVar sv_hl2mp_item_respawn_time( "sv_hl2mp_item_respawn_time", "30", FCVAR_GAMEDLL | FCVAR_NOTIFY ); -ConVar sv_report_client_settings("sv_report_client_settings", "0", FCVAR_GAMEDLL | FCVAR_NOTIFY ); - -extern ConVar mp_chattime; - -extern CBaseEntity *g_pLastCombineSpawn; -extern CBaseEntity *g_pLastRebelSpawn; - -#define WEAPON_MAX_DISTANCE_FROM_SPAWN 64 - -#endif - - -REGISTER_GAMERULES_CLASS( CHL2MPRules ); - -BEGIN_NETWORK_TABLE_NOBASE( CHL2MPRules, DT_HL2MPRules ) - - #ifdef CLIENT_DLL - RecvPropBool( RECVINFO( m_bTeamPlayEnabled ) ), - #else - SendPropBool( SENDINFO( m_bTeamPlayEnabled ) ), - #endif - -END_NETWORK_TABLE() - - -LINK_ENTITY_TO_CLASS( hl2mp_gamerules, CHL2MPGameRulesProxy ); -IMPLEMENT_NETWORKCLASS_ALIASED( HL2MPGameRulesProxy, DT_HL2MPGameRulesProxy ) - -static HL2MPViewVectors g_HL2MPViewVectors( - Vector( 0, 0, 64 ), //VEC_VIEW (m_vView) - - Vector(-16, -16, 0 ), //VEC_HULL_MIN (m_vHullMin) - Vector( 16, 16, 72 ), //VEC_HULL_MAX (m_vHullMax) - - Vector(-16, -16, 0 ), //VEC_DUCK_HULL_MIN (m_vDuckHullMin) - Vector( 16, 16, 36 ), //VEC_DUCK_HULL_MAX (m_vDuckHullMax) - Vector( 0, 0, 28 ), //VEC_DUCK_VIEW (m_vDuckView) - - Vector(-10, -10, -10 ), //VEC_OBS_HULL_MIN (m_vObsHullMin) - Vector( 10, 10, 10 ), //VEC_OBS_HULL_MAX (m_vObsHullMax) - - Vector( 0, 0, 14 ), //VEC_DEAD_VIEWHEIGHT (m_vDeadViewHeight) - - Vector(-16, -16, 0 ), //VEC_CROUCH_TRACE_MIN (m_vCrouchTraceMin) - Vector( 16, 16, 60 ) //VEC_CROUCH_TRACE_MAX (m_vCrouchTraceMax) -); - -static const char *s_PreserveEnts[] = -{ - "ai_network", - "ai_hint", - "hl2mp_gamerules", - "team_manager", - "player_manager", - "env_soundscape", - "env_soundscape_proxy", - "env_soundscape_triggerable", - "env_sun", - "env_wind", - "env_fog_controller", - "func_brush", - "func_wall", - "func_buyzone", - "func_illusionary", - "infodecal", - "info_projecteddecal", - "info_node", - "info_target", - "info_node_hint", - "info_player_deathmatch", - "info_player_combine", - "info_player_rebel", - "info_map_parameters", - "keyframe_rope", - "move_rope", - "info_ladder", - "player", - "point_viewcontrol", - "scene_manager", - "shadow_control", - "sky_camera", - "soundent", - "trigger_soundscape", - "viewmodel", - "predicted_viewmodel", - "worldspawn", - "point_devshot_camera", - "", // END Marker -}; - - - -#ifdef CLIENT_DLL - void RecvProxy_HL2MPRules( const RecvProp *pProp, void **pOut, void *pData, int objectID ) - { - CHL2MPRules *pRules = HL2MPRules(); - Assert( pRules ); - *pOut = pRules; - } - - BEGIN_RECV_TABLE( CHL2MPGameRulesProxy, DT_HL2MPGameRulesProxy ) - RecvPropDataTable( "hl2mp_gamerules_data", 0, 0, &REFERENCE_RECV_TABLE( DT_HL2MPRules ), RecvProxy_HL2MPRules ) - END_RECV_TABLE() -#else - void* SendProxy_HL2MPRules( const SendProp *pProp, const void *pStructBase, const void *pData, CSendProxyRecipients *pRecipients, int objectID ) - { - CHL2MPRules *pRules = HL2MPRules(); - Assert( pRules ); - return pRules; - } - - BEGIN_SEND_TABLE( CHL2MPGameRulesProxy, DT_HL2MPGameRulesProxy ) - SendPropDataTable( "hl2mp_gamerules_data", 0, &REFERENCE_SEND_TABLE( DT_HL2MPRules ), SendProxy_HL2MPRules ) - END_SEND_TABLE() -#endif - -#ifndef CLIENT_DLL - - class CVoiceGameMgrHelper : public IVoiceGameMgrHelper - { - public: - virtual bool CanPlayerHearPlayer( CBasePlayer *pListener, CBasePlayer *pTalker, bool &bProximity ) - { - return ( pListener->GetTeamNumber() == pTalker->GetTeamNumber() ); - } - }; - CVoiceGameMgrHelper g_VoiceGameMgrHelper; - IVoiceGameMgrHelper *g_pVoiceGameMgrHelper = &g_VoiceGameMgrHelper; - -#endif - -// NOTE: the indices here must match TEAM_TERRORIST, TEAM_CT, TEAM_SPECTATOR, etc. -char *sTeamNames[] = -{ - "Unassigned", - "Spectator", - "Combine", - "Rebels", -}; - -CHL2MPRules::CHL2MPRules() -{ -#ifndef CLIENT_DLL - // Create the team managers - for ( int i = 0; i < ARRAYSIZE( sTeamNames ); i++ ) - { - CTeam *pTeam = static_cast(CreateEntityByName( "team_manager" )); - pTeam->Init( sTeamNames[i], i ); - - g_Teams.AddToTail( pTeam ); - } - - m_bTeamPlayEnabled = teamplay.GetBool(); - m_flIntermissionEndTime = 0.0f; - m_flGameStartTime = 0; - - m_hRespawnableItemsAndWeapons.RemoveAll(); - m_tmNextPeriodicThink = 0; - m_flRestartGameTime = 0; - m_bCompleteReset = false; - m_bHeardAllPlayersReady = false; - m_bAwaitingReadyRestart = false; - m_bChangelevelDone = false; - -#endif -} - -const CViewVectors* CHL2MPRules::GetViewVectors()const -{ - return &g_HL2MPViewVectors; -} - -const HL2MPViewVectors* CHL2MPRules::GetHL2MPViewVectors()const -{ - return &g_HL2MPViewVectors; -} - -CHL2MPRules::~CHL2MPRules( void ) -{ -#ifndef CLIENT_DLL - // Note, don't delete each team since they are in the gEntList and will - // automatically be deleted from there, instead. - g_Teams.Purge(); -#endif -} - -void CHL2MPRules::CreateStandardEntities( void ) -{ - -#ifndef CLIENT_DLL - // Create the entity that will send our data to the client. - - BaseClass::CreateStandardEntities(); - - g_pLastCombineSpawn = NULL; - g_pLastRebelSpawn = NULL; - -#ifdef DBGFLAG_ASSERT - CBaseEntity *pEnt = -#endif - CBaseEntity::Create( "hl2mp_gamerules", vec3_origin, vec3_angle ); - Assert( pEnt ); -#endif -} - -//========================================================= -// FlWeaponRespawnTime - what is the time in the future -// at which this weapon may spawn? -//========================================================= -float CHL2MPRules::FlWeaponRespawnTime( CBaseCombatWeapon *pWeapon ) -{ -#ifndef CLIENT_DLL - if ( weaponstay.GetInt() > 0 ) - { - // make sure it's only certain weapons - if ( !(pWeapon->GetWeaponFlags() & ITEM_FLAG_LIMITINWORLD) ) - { - return 0; // weapon respawns almost instantly - } - } - - return sv_hl2mp_weapon_respawn_time.GetFloat(); -#endif - - return 0; // weapon respawns almost instantly -} - - -bool CHL2MPRules::IsIntermission( void ) -{ -#ifndef CLIENT_DLL - return m_flIntermissionEndTime > gpGlobals->curtime; -#endif - - return false; -} - -void CHL2MPRules::PlayerKilled( CBasePlayer *pVictim, const CTakeDamageInfo &info ) -{ -#ifndef CLIENT_DLL - if ( IsIntermission() ) - return; - BaseClass::PlayerKilled( pVictim, info ); -#endif -} - - -void CHL2MPRules::Think( void ) -{ - -#ifndef CLIENT_DLL - - CGameRules::Think(); - - if ( g_fGameOver ) // someone else quit the game already - { - // check to see if we should change levels now - if ( m_flIntermissionEndTime < gpGlobals->curtime ) - { - if ( !m_bChangelevelDone ) - { - ChangeLevel(); // intermission is over - m_bChangelevelDone = true; - } - } - - return; - } - -// float flTimeLimit = mp_timelimit.GetFloat() * 60; - float flFragLimit = fraglimit.GetFloat(); - - if ( GetMapRemainingTime() < 0 ) - { - GoToIntermission(); - return; - } - - if ( flFragLimit ) - { - if( IsTeamplay() == true ) - { - CTeam *pCombine = g_Teams[TEAM_COMBINE]; - CTeam *pRebels = g_Teams[TEAM_REBELS]; - - if ( pCombine->GetScore() >= flFragLimit || pRebels->GetScore() >= flFragLimit ) - { - GoToIntermission(); - return; - } - } - else - { - // check if any player is over the frag limit - for ( int i = 1; i <= gpGlobals->maxClients; i++ ) - { - CBasePlayer *pPlayer = UTIL_PlayerByIndex( i ); - - if ( pPlayer && pPlayer->FragCount() >= flFragLimit ) - { - GoToIntermission(); - return; - } - } - } - } - - if ( gpGlobals->curtime > m_tmNextPeriodicThink ) - { - CheckAllPlayersReady(); - CheckRestartGame(); - m_tmNextPeriodicThink = gpGlobals->curtime + 1.0; - } - - if ( m_flRestartGameTime > 0.0f && m_flRestartGameTime <= gpGlobals->curtime ) - { - RestartGame(); - } - - if( m_bAwaitingReadyRestart && m_bHeardAllPlayersReady ) - { - UTIL_ClientPrintAll( HUD_PRINTCENTER, "All players ready. Game will restart in 5 seconds" ); - UTIL_ClientPrintAll( HUD_PRINTCONSOLE, "All players ready. Game will restart in 5 seconds" ); - - m_flRestartGameTime = gpGlobals->curtime + 5; - m_bAwaitingReadyRestart = false; - } - - ManageObjectRelocation(); - -#endif -} - -void CHL2MPRules::GoToIntermission( void ) -{ -#ifndef CLIENT_DLL - if ( g_fGameOver ) - return; - - g_fGameOver = true; - - m_flIntermissionEndTime = gpGlobals->curtime + mp_chattime.GetInt(); - - for ( int i = 0; i < MAX_PLAYERS; i++ ) - { - CBasePlayer *pPlayer = UTIL_PlayerByIndex( i ); - - if ( !pPlayer ) - continue; - - pPlayer->ShowViewPortPanel( PANEL_SCOREBOARD ); - pPlayer->AddFlag( FL_FROZEN ); - } -#endif - -} - -bool CHL2MPRules::CheckGameOver() -{ -#ifndef CLIENT_DLL - if ( g_fGameOver ) // someone else quit the game already - { - // check to see if we should change levels now - if ( m_flIntermissionEndTime < gpGlobals->curtime ) - { - ChangeLevel(); // intermission is over - } - - return true; - } -#endif - - return false; -} - -// when we are within this close to running out of entities, items -// marked with the ITEM_FLAG_LIMITINWORLD will delay their respawn -#define ENTITY_INTOLERANCE 100 - -//========================================================= -// FlWeaponRespawnTime - Returns 0 if the weapon can respawn -// now, otherwise it returns the time at which it can try -// to spawn again. -//========================================================= -float CHL2MPRules::FlWeaponTryRespawn( CBaseCombatWeapon *pWeapon ) -{ -#ifndef CLIENT_DLL - if ( pWeapon && (pWeapon->GetWeaponFlags() & ITEM_FLAG_LIMITINWORLD) ) - { - if ( gEntList.NumberOfEntities() < (gpGlobals->maxEntities - ENTITY_INTOLERANCE) ) - return 0; - - // we're past the entity tolerance level, so delay the respawn - return FlWeaponRespawnTime( pWeapon ); - } -#endif - return 0; -} - -//========================================================= -// VecWeaponRespawnSpot - where should this weapon spawn? -// Some game variations may choose to randomize spawn locations -//========================================================= -Vector CHL2MPRules::VecWeaponRespawnSpot( CBaseCombatWeapon *pWeapon ) -{ -#ifndef CLIENT_DLL - CWeaponHL2MPBase *pHL2Weapon = dynamic_cast< CWeaponHL2MPBase*>( pWeapon ); - - if ( pHL2Weapon ) - { - return pHL2Weapon->GetOriginalSpawnOrigin(); - } -#endif - - return pWeapon->GetAbsOrigin(); -} - -#ifndef CLIENT_DLL - -CItem* IsManagedObjectAnItem( CBaseEntity *pObject ) -{ - return dynamic_cast< CItem*>( pObject ); -} - -CWeaponHL2MPBase* IsManagedObjectAWeapon( CBaseEntity *pObject ) -{ - return dynamic_cast< CWeaponHL2MPBase*>( pObject ); -} - -bool GetObjectsOriginalParameters( CBaseEntity *pObject, Vector &vOriginalOrigin, QAngle &vOriginalAngles ) -{ - if ( CItem *pItem = IsManagedObjectAnItem( pObject ) ) - { - if ( pItem->m_flNextResetCheckTime > gpGlobals->curtime ) - return false; - - vOriginalOrigin = pItem->GetOriginalSpawnOrigin(); - vOriginalAngles = pItem->GetOriginalSpawnAngles(); - - pItem->m_flNextResetCheckTime = gpGlobals->curtime + sv_hl2mp_item_respawn_time.GetFloat(); - return true; - } - else if ( CWeaponHL2MPBase *pWeapon = IsManagedObjectAWeapon( pObject )) - { - if ( pWeapon->m_flNextResetCheckTime > gpGlobals->curtime ) - return false; - - vOriginalOrigin = pWeapon->GetOriginalSpawnOrigin(); - vOriginalAngles = pWeapon->GetOriginalSpawnAngles(); - - pWeapon->m_flNextResetCheckTime = gpGlobals->curtime + sv_hl2mp_weapon_respawn_time.GetFloat(); - return true; - } - - return false; -} - -void CHL2MPRules::ManageObjectRelocation( void ) -{ - int iTotal = m_hRespawnableItemsAndWeapons.Count(); - - if ( iTotal > 0 ) - { - for ( int i = 0; i < iTotal; i++ ) - { - CBaseEntity *pObject = m_hRespawnableItemsAndWeapons[i].Get(); - - if ( pObject ) - { - Vector vSpawOrigin; - QAngle vSpawnAngles; - - if ( GetObjectsOriginalParameters( pObject, vSpawOrigin, vSpawnAngles ) == true ) - { - float flDistanceFromSpawn = (pObject->GetAbsOrigin() - vSpawOrigin ).Length(); - - if ( flDistanceFromSpawn > WEAPON_MAX_DISTANCE_FROM_SPAWN ) - { - bool shouldReset = false; - IPhysicsObject *pPhysics = pObject->VPhysicsGetObject(); - - if ( pPhysics ) - { - shouldReset = pPhysics->IsAsleep(); - } - else - { - shouldReset = (pObject->GetFlags() & FL_ONGROUND) ? true : false; - } - - if ( shouldReset ) - { - pObject->Teleport( &vSpawOrigin, &vSpawnAngles, NULL ); - pObject->EmitSound( "AlyxEmp.Charge" ); - - IPhysicsObject *pPhys = pObject->VPhysicsGetObject(); - - if ( pPhys ) - { - pPhys->Wake(); - } - } - } - } - } - } - } -} - -//========================================================= -//AddLevelDesignerPlacedWeapon -//========================================================= -void CHL2MPRules::AddLevelDesignerPlacedObject( CBaseEntity *pEntity ) -{ - if ( m_hRespawnableItemsAndWeapons.Find( pEntity ) == -1 ) - { - m_hRespawnableItemsAndWeapons.AddToTail( pEntity ); - } -} - -//========================================================= -//RemoveLevelDesignerPlacedWeapon -//========================================================= -void CHL2MPRules::RemoveLevelDesignerPlacedObject( CBaseEntity *pEntity ) -{ - if ( m_hRespawnableItemsAndWeapons.Find( pEntity ) != -1 ) - { - m_hRespawnableItemsAndWeapons.FindAndRemove( pEntity ); - } -} - -//========================================================= -// Where should this item respawn? -// Some game variations may choose to randomize spawn locations -//========================================================= -Vector CHL2MPRules::VecItemRespawnSpot( CItem *pItem ) -{ - return pItem->GetOriginalSpawnOrigin(); -} - -//========================================================= -// What angles should this item use to respawn? -//========================================================= -QAngle CHL2MPRules::VecItemRespawnAngles( CItem *pItem ) -{ - return pItem->GetOriginalSpawnAngles(); -} - -//========================================================= -// At what time in the future may this Item respawn? -//========================================================= -float CHL2MPRules::FlItemRespawnTime( CItem *pItem ) -{ - return sv_hl2mp_item_respawn_time.GetFloat(); -} - - -//========================================================= -// CanHaveWeapon - returns false if the player is not allowed -// to pick up this weapon -//========================================================= -bool CHL2MPRules::CanHavePlayerItem( CBasePlayer *pPlayer, CBaseCombatWeapon *pItem ) -{ - if ( weaponstay.GetInt() > 0 ) - { - if ( pPlayer->Weapon_OwnsThisType( pItem->GetClassname(), pItem->GetSubType() ) ) - return false; - } - - return BaseClass::CanHavePlayerItem( pPlayer, pItem ); -} - -#endif - -//========================================================= -// WeaponShouldRespawn - any conditions inhibiting the -// respawning of this weapon? -//========================================================= -int CHL2MPRules::WeaponShouldRespawn( CBaseCombatWeapon *pWeapon ) -{ -#ifndef CLIENT_DLL - if ( pWeapon->HasSpawnFlags( SF_NORESPAWN ) ) - { - return GR_WEAPON_RESPAWN_NO; - } -#endif - - return GR_WEAPON_RESPAWN_YES; -} - -//----------------------------------------------------------------------------- -// Purpose: Player has just left the game -//----------------------------------------------------------------------------- -void CHL2MPRules::ClientDisconnected( edict_t *pClient ) -{ -#ifndef CLIENT_DLL - // Msg( "CLIENT DISCONNECTED, REMOVING FROM TEAM.\n" ); - - CBasePlayer *pPlayer = (CBasePlayer *)CBaseEntity::Instance( pClient ); - if ( pPlayer ) - { - // Remove the player from his team - if ( pPlayer->GetTeam() ) - { - pPlayer->GetTeam()->RemovePlayer( pPlayer ); - } - } - - BaseClass::ClientDisconnected( pClient ); - -#endif -} - - -//========================================================= -// Deathnotice. -//========================================================= -void CHL2MPRules::DeathNotice( CBasePlayer *pVictim, const CTakeDamageInfo &info ) -{ -#ifndef CLIENT_DLL - // Work out what killed the player, and send a message to all clients about it - const char *killer_weapon_name = "world"; // by default, the player is killed by the world - int killer_ID = 0; - - // Find the killer & the scorer - CBaseEntity *pInflictor = info.GetInflictor(); - CBaseEntity *pKiller = info.GetAttacker(); - CBasePlayer *pScorer = GetDeathScorer( pKiller, pInflictor ); - - // Custom kill type? - if ( info.GetDamageCustom() ) - { - killer_weapon_name = GetDamageCustomString( info ); - if ( pScorer ) - { - killer_ID = pScorer->GetUserID(); - } - } - else - { - // Is the killer a client? - if ( pScorer ) - { - killer_ID = pScorer->GetUserID(); - - if ( pInflictor ) - { - if ( pInflictor == pScorer ) - { - // If the inflictor is the killer, then it must be their current weapon doing the damage - if ( pScorer->GetActiveWeapon() ) - { - killer_weapon_name = pScorer->GetActiveWeapon()->GetClassname(); - } - } - else - { - killer_weapon_name = pInflictor->GetClassname(); // it's just that easy - } - } - } - else - { - killer_weapon_name = pInflictor->GetClassname(); - } - - // strip the NPC_* or weapon_* from the inflictor's classname - if ( strncmp( killer_weapon_name, "weapon_", 7 ) == 0 ) - { - killer_weapon_name += 7; - } - else if ( strncmp( killer_weapon_name, "npc_", 4 ) == 0 ) - { - killer_weapon_name += 4; - } - else if ( strncmp( killer_weapon_name, "func_", 5 ) == 0 ) - { - killer_weapon_name += 5; - } - else if ( strstr( killer_weapon_name, "physics" ) ) - { - killer_weapon_name = "physics"; - } - - if ( strcmp( killer_weapon_name, "prop_combine_ball" ) == 0 ) - { - killer_weapon_name = "combine_ball"; - } - else if ( strcmp( killer_weapon_name, "grenade_ar2" ) == 0 ) - { - killer_weapon_name = "smg1_grenade"; - } - else if ( strcmp( killer_weapon_name, "satchel" ) == 0 || strcmp( killer_weapon_name, "tripmine" ) == 0) - { - killer_weapon_name = "slam"; - } - - - } - - IGameEvent *event = gameeventmanager->CreateEvent( "player_death" ); - if( event ) - { - event->SetInt("userid", pVictim->GetUserID() ); - event->SetInt("attacker", killer_ID ); - event->SetString("weapon", killer_weapon_name ); - event->SetInt( "priority", 7 ); - gameeventmanager->FireEvent( event ); - } -#endif - -} - -void CHL2MPRules::ClientSettingsChanged( CBasePlayer *pPlayer ) -{ -#ifndef CLIENT_DLL - - CHL2MP_Player *pHL2Player = ToHL2MPPlayer( pPlayer ); - - if ( pHL2Player == NULL ) - return; - - const char *pCurrentModel = modelinfo->GetModelName( pPlayer->GetModel() ); - const char *szModelName = engine->GetClientConVarValue( engine->IndexOfEdict( pPlayer->edict() ), "cl_playermodel" ); - - //If we're different. - if ( stricmp( szModelName, pCurrentModel ) ) - { - //Too soon, set the cvar back to what it was. - //Note: this will make this function be called again - //but since our models will match it'll just skip this whole dealio. - if ( pHL2Player->GetNextModelChangeTime() >= gpGlobals->curtime ) - { - char szReturnString[512]; - - Q_snprintf( szReturnString, sizeof (szReturnString ), "cl_playermodel %s\n", pCurrentModel ); - engine->ClientCommand ( pHL2Player->edict(), szReturnString ); - - Q_snprintf( szReturnString, sizeof( szReturnString ), "Please wait %d more seconds before trying to switch.\n", (int)(pHL2Player->GetNextModelChangeTime() - gpGlobals->curtime) ); - ClientPrint( pHL2Player, HUD_PRINTTALK, szReturnString ); - return; - } - - if ( HL2MPRules()->IsTeamplay() == false ) - { - pHL2Player->SetPlayerModel(); - - const char *pszCurrentModelName = modelinfo->GetModelName( pHL2Player->GetModel() ); - - char szReturnString[128]; - Q_snprintf( szReturnString, sizeof( szReturnString ), "Your player model is: %s\n", pszCurrentModelName ); - - ClientPrint( pHL2Player, HUD_PRINTTALK, szReturnString ); - } - else - { - if ( Q_stristr( szModelName, "models/human") ) - { - pHL2Player->ChangeTeam( TEAM_REBELS ); - } - else - { - pHL2Player->ChangeTeam( TEAM_COMBINE ); - } - } - } - if ( sv_report_client_settings.GetInt() == 1 ) - { - UTIL_LogPrintf( "\"%s\" cl_cmdrate = \"%s\"\n", pHL2Player->GetPlayerName(), engine->GetClientConVarValue( pHL2Player->entindex(), "cl_cmdrate" )); - } - - BaseClass::ClientSettingsChanged( pPlayer ); -#endif - -} - -int CHL2MPRules::PlayerRelationship( CBaseEntity *pPlayer, CBaseEntity *pTarget ) -{ -#ifndef CLIENT_DLL - // half life multiplay has a simple concept of Player Relationships. - // you are either on another player's team, or you are not. - if ( !pPlayer || !pTarget || !pTarget->IsPlayer() || IsTeamplay() == false ) - return GR_NOTTEAMMATE; - - if ( (*GetTeamID(pPlayer) != '\0') && (*GetTeamID(pTarget) != '\0') && !stricmp( GetTeamID(pPlayer), GetTeamID(pTarget) ) ) - { - return GR_TEAMMATE; - } -#endif - - return GR_NOTTEAMMATE; -} - -const char *CHL2MPRules::GetGameDescription( void ) -{ - if ( IsTeamplay() ) - return "Team Deathmatch"; - - return "Deathmatch"; -} - -bool CHL2MPRules::IsConnectedUserInfoChangeAllowed( CBasePlayer *pPlayer ) -{ - return true; -} - -float CHL2MPRules::GetMapRemainingTime() -{ - // if timelimit is disabled, return 0 - if ( mp_timelimit.GetInt() <= 0 ) - return 0; - - // timelimit is in minutes - - float timeleft = (m_flGameStartTime + mp_timelimit.GetInt() * 60.0f ) - gpGlobals->curtime; - - return timeleft; -} - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void CHL2MPRules::Precache( void ) -{ - CBaseEntity::PrecacheScriptSound( "AlyxEmp.Charge" ); -} - -bool CHL2MPRules::ShouldCollide( int collisionGroup0, int collisionGroup1 ) -{ - if ( collisionGroup0 > collisionGroup1 ) - { - // swap so that lowest is always first - V_swap(collisionGroup0,collisionGroup1); - } - - if ( (collisionGroup0 == COLLISION_GROUP_PLAYER || collisionGroup0 == COLLISION_GROUP_PLAYER_MOVEMENT) && - collisionGroup1 == COLLISION_GROUP_WEAPON ) - { - return false; - } - - return BaseClass::ShouldCollide( collisionGroup0, collisionGroup1 ); - -} - -bool CHL2MPRules::ClientCommand( CBaseEntity *pEdict, const CCommand &args ) -{ -#ifndef CLIENT_DLL - if( BaseClass::ClientCommand( pEdict, args ) ) - return true; - - - CHL2MP_Player *pPlayer = (CHL2MP_Player *) pEdict; - - if ( pPlayer->ClientCommand( args ) ) - return true; -#endif - - return false; -} - -// shared ammo definition -// JAY: Trying to make a more physical bullet response -#define BULLET_MASS_GRAINS_TO_LB(grains) (0.002285*(grains)/16.0f) -#define BULLET_MASS_GRAINS_TO_KG(grains) lbs2kg(BULLET_MASS_GRAINS_TO_LB(grains)) - -// exaggerate all of the forces, but use real numbers to keep them consistent -#define BULLET_IMPULSE_EXAGGERATION 3.5 -// convert a velocity in ft/sec and a mass in grains to an impulse in kg in/s -#define BULLET_IMPULSE(grains, ftpersec) ((ftpersec)*12*BULLET_MASS_GRAINS_TO_KG(grains)*BULLET_IMPULSE_EXAGGERATION) - - -CAmmoDef *GetAmmoDef() -{ - static CAmmoDef def; - static bool bInitted = false; - - if ( !bInitted ) - { - bInitted = true; - - def.AddAmmoType("AR2", DMG_BULLET, TRACER_LINE_AND_WHIZ, 0, 0, 60, BULLET_IMPULSE(200, 1225), 0 ); - def.AddAmmoType("AR2AltFire", DMG_DISSOLVE, TRACER_NONE, 0, 0, 3, 0, 0 ); - def.AddAmmoType("Pistol", DMG_BULLET, TRACER_LINE_AND_WHIZ, 0, 0, 150, BULLET_IMPULSE(200, 1225), 0 ); - def.AddAmmoType("SMG1", DMG_BULLET, TRACER_LINE_AND_WHIZ, 0, 0, 225, BULLET_IMPULSE(200, 1225), 0 ); - def.AddAmmoType("357", DMG_BULLET, TRACER_LINE_AND_WHIZ, 0, 0, 12, BULLET_IMPULSE(800, 5000), 0 ); - def.AddAmmoType("XBowBolt", DMG_BULLET, TRACER_LINE, 0, 0, 10, BULLET_IMPULSE(800, 8000), 0 ); - def.AddAmmoType("Buckshot", DMG_BULLET | DMG_BUCKSHOT, TRACER_LINE, 0, 0, 30, BULLET_IMPULSE(400, 1200), 0 ); - def.AddAmmoType("RPG_Round", DMG_BURN, TRACER_NONE, 0, 0, 3, 0, 0 ); - def.AddAmmoType("SMG1_Grenade", DMG_BURN, TRACER_NONE, 0, 0, 3, 0, 0 ); - def.AddAmmoType("Grenade", DMG_BURN, TRACER_NONE, 0, 0, 5, 0, 0 ); - def.AddAmmoType("slam", DMG_BURN, TRACER_NONE, 0, 0, 5, 0, 0 ); - } - - return &def; -} - -#ifdef CLIENT_DLL - - ConVar cl_autowepswitch( - "cl_autowepswitch", - "1", - FCVAR_ARCHIVE | FCVAR_USERINFO, - "Automatically switch to picked up weapons (if more powerful)" ); - -#else - -#ifdef DEBUG - - // Handler for the "bot" command. - void Bot_f() - { - // Look at -count. - int count = 1; - count = clamp( count, 1, 16 ); - - int iTeam = TEAM_COMBINE; - - // Look at -frozen. - bool bFrozen = false; - - // Ok, spawn all the bots. - while ( --count >= 0 ) - { - BotPutInServer( bFrozen, iTeam ); - } - } - - - ConCommand cc_Bot( "bot", Bot_f, "Add a bot.", FCVAR_CHEAT ); - -#endif - - bool CHL2MPRules::FShouldSwitchWeapon( CBasePlayer *pPlayer, CBaseCombatWeapon *pWeapon ) - { - if ( pPlayer->GetActiveWeapon() && pPlayer->IsNetClient() ) - { - // Player has an active item, so let's check cl_autowepswitch. - const char *cl_autowepswitch = engine->GetClientConVarValue( engine->IndexOfEdict( pPlayer->edict() ), "cl_autowepswitch" ); - if ( cl_autowepswitch && atoi( cl_autowepswitch ) <= 0 ) - { - return false; - } - } - - return BaseClass::FShouldSwitchWeapon( pPlayer, pWeapon ); - } - -#endif - -#ifndef CLIENT_DLL - -void CHL2MPRules::RestartGame() -{ - // bounds check - if ( mp_timelimit.GetInt() < 0 ) - { - mp_timelimit.SetValue( 0 ); - } - m_flGameStartTime = gpGlobals->curtime; - if ( !IsFinite( m_flGameStartTime.Get() ) ) - { - Warning( "Trying to set a NaN game start time\n" ); - m_flGameStartTime.GetForModify() = 0.0f; - } - - CleanUpMap(); - - // now respawn all players - for (int i = 1; i <= gpGlobals->maxClients; i++ ) - { - CHL2MP_Player *pPlayer = (CHL2MP_Player*) UTIL_PlayerByIndex( i ); - - if ( !pPlayer ) - continue; - - if ( pPlayer->GetActiveWeapon() ) - { - pPlayer->GetActiveWeapon()->Holster(); - } - pPlayer->RemoveAllItems( true ); - respawn( pPlayer, false ); - pPlayer->Reset(); - } - - // Respawn entities (glass, doors, etc..) - - CTeam *pRebels = GetGlobalTeam( TEAM_REBELS ); - CTeam *pCombine = GetGlobalTeam( TEAM_COMBINE ); - - if ( pRebels ) - { - pRebels->SetScore( 0 ); - } - - if ( pCombine ) - { - pCombine->SetScore( 0 ); - } - - m_flIntermissionEndTime = 0; - m_flRestartGameTime = 0.0; - m_bCompleteReset = false; - - IGameEvent * event = gameeventmanager->CreateEvent( "round_start" ); - if ( event ) - { - event->SetInt("fraglimit", 0 ); - event->SetInt( "priority", 6 ); // HLTV event priority, not transmitted - - event->SetString("objective","DEATHMATCH"); - - gameeventmanager->FireEvent( event ); - } -} - -void CHL2MPRules::CleanUpMap() -{ - // Recreate all the map entities from the map data (preserving their indices), - // then remove everything else except the players. - - // Get rid of all entities except players. - CBaseEntity *pCur = gEntList.FirstEnt(); - while ( pCur ) - { - CBaseHL2MPCombatWeapon *pWeapon = dynamic_cast< CBaseHL2MPCombatWeapon* >( pCur ); - // Weapons with owners don't want to be removed.. - if ( pWeapon ) - { - if ( !pWeapon->GetPlayerOwner() ) - { - UTIL_Remove( pCur ); - } - } - // remove entities that has to be restored on roundrestart (breakables etc) - else if ( !FindInList( s_PreserveEnts, pCur->GetClassname() ) ) - { - UTIL_Remove( pCur ); - } - - pCur = gEntList.NextEnt( pCur ); - } - - // Really remove the entities so we can have access to their slots below. - gEntList.CleanupDeleteList(); - - // Cancel all queued events, in case a func_bomb_target fired some delayed outputs that - // could kill respawning CTs - g_EventQueue.Clear(); - - // Now reload the map entities. - class CHL2MPMapEntityFilter : public IMapEntityFilter - { - public: - virtual bool ShouldCreateEntity( const char *pClassname ) - { - // Don't recreate the preserved entities. - if ( !FindInList( s_PreserveEnts, pClassname ) ) - { - return true; - } - else - { - // Increment our iterator since it's not going to call CreateNextEntity for this ent. - if ( m_iIterator != g_MapEntityRefs.InvalidIndex() ) - m_iIterator = g_MapEntityRefs.Next( m_iIterator ); - - return false; - } - } - - - virtual CBaseEntity* CreateNextEntity( const char *pClassname ) - { - if ( m_iIterator == g_MapEntityRefs.InvalidIndex() ) - { - // This shouldn't be possible. When we loaded the map, it should have used - // CCSMapLoadEntityFilter, which should have built the g_MapEntityRefs list - // with the same list of entities we're referring to here. - Assert( false ); - return NULL; - } - else - { - CMapEntityRef &ref = g_MapEntityRefs[m_iIterator]; - m_iIterator = g_MapEntityRefs.Next( m_iIterator ); // Seek to the next entity. - - if ( ref.m_iEdict == -1 || engine->PEntityOfEntIndex( ref.m_iEdict ) ) - { - // Doh! The entity was delete and its slot was reused. - // Just use any old edict slot. This case sucks because we lose the baseline. - return CreateEntityByName( pClassname ); - } - else - { - // Cool, the slot where this entity was is free again (most likely, the entity was - // freed above). Now create an entity with this specific index. - return CreateEntityByName( pClassname, ref.m_iEdict ); - } - } - } - - public: - int m_iIterator; // Iterator into g_MapEntityRefs. - }; - CHL2MPMapEntityFilter filter; - filter.m_iIterator = g_MapEntityRefs.Head(); - - // DO NOT CALL SPAWN ON info_node ENTITIES! - - MapEntity_ParseAllEntities( engine->GetMapEntitiesString(), &filter, true ); -} - -void CHL2MPRules::CheckChatForReadySignal( CHL2MP_Player *pPlayer, const char *chatmsg ) -{ - if( m_bAwaitingReadyRestart && FStrEq( chatmsg, mp_ready_signal.GetString() ) ) - { - if( !pPlayer->IsReady() ) - { - pPlayer->SetReady( true ); - } - } -} - -void CHL2MPRules::CheckRestartGame( void ) -{ - // Restart the game if specified by the server - int iRestartDelay = mp_restartgame.GetInt(); - - if ( iRestartDelay > 0 ) - { - if ( iRestartDelay > 60 ) - iRestartDelay = 60; - - - // let the players know - char strRestartDelay[64]; - Q_snprintf( strRestartDelay, sizeof( strRestartDelay ), "%d", iRestartDelay ); - UTIL_ClientPrintAll( HUD_PRINTCENTER, "Game will restart in %s1 %s2", strRestartDelay, iRestartDelay == 1 ? "SECOND" : "SECONDS" ); - UTIL_ClientPrintAll( HUD_PRINTCONSOLE, "Game will restart in %s1 %s2", strRestartDelay, iRestartDelay == 1 ? "SECOND" : "SECONDS" ); - - m_flRestartGameTime = gpGlobals->curtime + iRestartDelay; - m_bCompleteReset = true; - mp_restartgame.SetValue( 0 ); - } - - if( mp_readyrestart.GetBool() ) - { - m_bAwaitingReadyRestart = true; - m_bHeardAllPlayersReady = false; - - - const char *pszReadyString = mp_ready_signal.GetString(); - - - // Don't let them put anything malicious in there - if( pszReadyString == NULL || Q_strlen(pszReadyString) > 16 ) - { - pszReadyString = "ready"; - } - - IGameEvent *event = gameeventmanager->CreateEvent( "hl2mp_ready_restart" ); - if ( event ) - gameeventmanager->FireEvent( event ); - - mp_readyrestart.SetValue( 0 ); - - // cancel any restart round in progress - m_flRestartGameTime = -1; - } -} - -void CHL2MPRules::CheckAllPlayersReady( void ) -{ - for (int i = 1; i <= gpGlobals->maxClients; i++ ) - { - CHL2MP_Player *pPlayer = (CHL2MP_Player*) UTIL_PlayerByIndex( i ); - - if ( !pPlayer ) - continue; - if ( !pPlayer->IsReady() ) - return; - } - m_bHeardAllPlayersReady = true; -} - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -const char *CHL2MPRules::GetChatFormat( bool bTeamOnly, CBasePlayer *pPlayer ) -{ - if ( !pPlayer ) // dedicated server output - { - return NULL; - } - - const char *pszFormat = NULL; - - // team only - if ( bTeamOnly == TRUE ) - { - if ( pPlayer->GetTeamNumber() == TEAM_SPECTATOR ) - { - pszFormat = "HL2MP_Chat_Spec"; - } - else - { - const char *chatLocation = GetChatLocation( bTeamOnly, pPlayer ); - if ( chatLocation && *chatLocation ) - { - pszFormat = "HL2MP_Chat_Team_Loc"; - } - else - { - pszFormat = "HL2MP_Chat_Team"; - } - } - } - // everyone - else - { - if ( pPlayer->GetTeamNumber() != TEAM_SPECTATOR ) - { - pszFormat = "HL2MP_Chat_All"; - } - else - { - pszFormat = "HL2MP_Chat_AllSpec"; - } - } - - return pszFormat; -} - -#endif \ No newline at end of file diff --git a/sp/src/game/shared/hl2mp/hl2mp_gamerules.h b/sp/src/game/shared/hl2mp/hl2mp_gamerules.h deleted file mode 100644 index 8d91554c..00000000 --- a/sp/src/game/shared/hl2mp/hl2mp_gamerules.h +++ /dev/null @@ -1,172 +0,0 @@ -//========= Copyright Valve Corporation, All rights reserved. ============// -// -// Purpose: -// -// $Workfile: $ -// $Date: $ -// -//----------------------------------------------------------------------------- -// $Log: $ -// -// $NoKeywords: $ -//=============================================================================// - -#ifndef HL2MP_GAMERULES_H -#define HL2MP_GAMERULES_H -#pragma once - -#include "gamerules.h" -#include "teamplay_gamerules.h" -#include "gamevars_shared.h" - -#ifndef CLIENT_DLL -#include "hl2mp_player.h" -#endif - -#define VEC_CROUCH_TRACE_MIN HL2MPRules()->GetHL2MPViewVectors()->m_vCrouchTraceMin -#define VEC_CROUCH_TRACE_MAX HL2MPRules()->GetHL2MPViewVectors()->m_vCrouchTraceMax - -enum -{ - TEAM_COMBINE = 2, - TEAM_REBELS, -}; - - -#ifdef CLIENT_DLL - #define CHL2MPRules C_HL2MPRules - #define CHL2MPGameRulesProxy C_HL2MPGameRulesProxy -#endif - -class CHL2MPGameRulesProxy : public CGameRulesProxy -{ -public: - DECLARE_CLASS( CHL2MPGameRulesProxy, CGameRulesProxy ); - DECLARE_NETWORKCLASS(); -}; - -class HL2MPViewVectors : public CViewVectors -{ -public: - HL2MPViewVectors( - Vector vView, - Vector vHullMin, - Vector vHullMax, - Vector vDuckHullMin, - Vector vDuckHullMax, - Vector vDuckView, - Vector vObsHullMin, - Vector vObsHullMax, - Vector vDeadViewHeight, - Vector vCrouchTraceMin, - Vector vCrouchTraceMax ) : - CViewVectors( - vView, - vHullMin, - vHullMax, - vDuckHullMin, - vDuckHullMax, - vDuckView, - vObsHullMin, - vObsHullMax, - vDeadViewHeight ) - { - m_vCrouchTraceMin = vCrouchTraceMin; - m_vCrouchTraceMax = vCrouchTraceMax; - } - - Vector m_vCrouchTraceMin; - Vector m_vCrouchTraceMax; -}; - -class CHL2MPRules : public CTeamplayRules -{ -public: - DECLARE_CLASS( CHL2MPRules, CTeamplayRules ); - -#ifdef CLIENT_DLL - - DECLARE_CLIENTCLASS_NOBASE(); // This makes datatables able to access our private vars. - -#else - - DECLARE_SERVERCLASS_NOBASE(); // This makes datatables able to access our private vars. -#endif - - CHL2MPRules(); - virtual ~CHL2MPRules(); - - virtual void Precache( void ); - virtual bool ShouldCollide( int collisionGroup0, int collisionGroup1 ); - virtual bool ClientCommand( CBaseEntity *pEdict, const CCommand &args ); - - virtual float FlWeaponRespawnTime( CBaseCombatWeapon *pWeapon ); - virtual float FlWeaponTryRespawn( CBaseCombatWeapon *pWeapon ); - virtual Vector VecWeaponRespawnSpot( CBaseCombatWeapon *pWeapon ); - virtual int WeaponShouldRespawn( CBaseCombatWeapon *pWeapon ); - virtual void Think( void ); - virtual void CreateStandardEntities( void ); - virtual void ClientSettingsChanged( CBasePlayer *pPlayer ); - virtual int PlayerRelationship( CBaseEntity *pPlayer, CBaseEntity *pTarget ); - virtual void GoToIntermission( void ); - virtual void DeathNotice( CBasePlayer *pVictim, const CTakeDamageInfo &info ); - virtual const char *GetGameDescription( void ); - // derive this function if you mod uses encrypted weapon info files - virtual const unsigned char *GetEncryptionKey( void ) { return (unsigned char *)"x9Ke0BY7"; } - virtual const CViewVectors* GetViewVectors() const; - const HL2MPViewVectors* GetHL2MPViewVectors() const; - - float GetMapRemainingTime(); - void CleanUpMap(); - void CheckRestartGame(); - void RestartGame(); - -#ifndef CLIENT_DLL - virtual Vector VecItemRespawnSpot( CItem *pItem ); - virtual QAngle VecItemRespawnAngles( CItem *pItem ); - virtual float FlItemRespawnTime( CItem *pItem ); - virtual bool CanHavePlayerItem( CBasePlayer *pPlayer, CBaseCombatWeapon *pItem ); - virtual bool FShouldSwitchWeapon( CBasePlayer *pPlayer, CBaseCombatWeapon *pWeapon ); - - void AddLevelDesignerPlacedObject( CBaseEntity *pEntity ); - void RemoveLevelDesignerPlacedObject( CBaseEntity *pEntity ); - void ManageObjectRelocation( void ); - void CheckChatForReadySignal( CHL2MP_Player *pPlayer, const char *chatmsg ); - const char *GetChatFormat( bool bTeamOnly, CBasePlayer *pPlayer ); - -#endif - virtual void ClientDisconnected( edict_t *pClient ); - - bool CheckGameOver( void ); - bool IsIntermission( void ); - - void PlayerKilled( CBasePlayer *pVictim, const CTakeDamageInfo &info ); - - - bool IsTeamplay( void ) { return m_bTeamPlayEnabled; } - void CheckAllPlayersReady( void ); - - virtual bool IsConnectedUserInfoChangeAllowed( CBasePlayer *pPlayer ); - -private: - - CNetworkVar( bool, m_bTeamPlayEnabled ); - CNetworkVar( float, m_flGameStartTime ); - CUtlVector m_hRespawnableItemsAndWeapons; - float m_tmNextPeriodicThink; - float m_flRestartGameTime; - bool m_bCompleteReset; - bool m_bAwaitingReadyRestart; - bool m_bHeardAllPlayersReady; - -#ifndef CLIENT_DLL - bool m_bChangelevelDone; -#endif -}; - -inline CHL2MPRules* HL2MPRules() -{ - return static_cast(g_pGameRules); -} - -#endif //HL2MP_GAMERULES_H diff --git a/sp/src/game/shared/hl2mp/hl2mp_player_shared.cpp b/sp/src/game/shared/hl2mp/hl2mp_player_shared.cpp deleted file mode 100644 index 503d498c..00000000 --- a/sp/src/game/shared/hl2mp/hl2mp_player_shared.cpp +++ /dev/null @@ -1,577 +0,0 @@ -//========= Copyright Valve Corporation, All rights reserved. ============// -// -// Purpose: -// -// $NoKeywords: $ -// -//=============================================================================// -#include "cbase.h" - -#ifdef CLIENT_DLL -#include "c_hl2mp_player.h" -#include "prediction.h" -#define CRecipientFilter C_RecipientFilter -#else -#include "hl2mp_player.h" -#endif - -#include "engine/IEngineSound.h" -#include "SoundEmitterSystem/isoundemittersystembase.h" - -extern ConVar sv_footsteps; - -const char *g_ppszPlayerSoundPrefixNames[PLAYER_SOUNDS_MAX] = -{ - "NPC_Citizen", - "NPC_CombineS", - "NPC_MetroPolice", -}; - -const char *CHL2MP_Player::GetPlayerModelSoundPrefix( void ) -{ - return g_ppszPlayerSoundPrefixNames[m_iPlayerSoundType]; -} - -void CHL2MP_Player::PrecacheFootStepSounds( void ) -{ - int iFootstepSounds = ARRAYSIZE( g_ppszPlayerSoundPrefixNames ); - int i; - - for ( i = 0; i < iFootstepSounds; ++i ) - { - char szFootStepName[128]; - - Q_snprintf( szFootStepName, sizeof( szFootStepName ), "%s.RunFootstepLeft", g_ppszPlayerSoundPrefixNames[i] ); - PrecacheScriptSound( szFootStepName ); - - Q_snprintf( szFootStepName, sizeof( szFootStepName ), "%s.RunFootstepRight", g_ppszPlayerSoundPrefixNames[i] ); - PrecacheScriptSound( szFootStepName ); - } -} - -//----------------------------------------------------------------------------- -// Consider the weapon's built-in accuracy, this character's proficiency with -// the weapon, and the status of the target. Use this information to determine -// how accurately to shoot at the target. -//----------------------------------------------------------------------------- -Vector CHL2MP_Player::GetAttackSpread( CBaseCombatWeapon *pWeapon, CBaseEntity *pTarget ) -{ - if ( pWeapon ) - return pWeapon->GetBulletSpread( WEAPON_PROFICIENCY_PERFECT ); - - return VECTOR_CONE_15DEGREES; -} - -//----------------------------------------------------------------------------- -// Purpose: -// Input : step - -// fvol - -// force - force sound to play -//----------------------------------------------------------------------------- -void CHL2MP_Player::PlayStepSound( Vector &vecOrigin, surfacedata_t *psurface, float fvol, bool force ) -{ - if ( gpGlobals->maxClients > 1 && !sv_footsteps.GetFloat() ) - return; - -#if defined( CLIENT_DLL ) - // during prediction play footstep sounds only once - if ( !prediction->IsFirstTimePredicted() ) - return; -#endif - - if ( GetFlags() & FL_DUCKING ) - return; - - m_Local.m_nStepside = !m_Local.m_nStepside; - - char szStepSound[128]; - - if ( m_Local.m_nStepside ) - { - Q_snprintf( szStepSound, sizeof( szStepSound ), "%s.RunFootstepLeft", g_ppszPlayerSoundPrefixNames[m_iPlayerSoundType] ); - } - else - { - Q_snprintf( szStepSound, sizeof( szStepSound ), "%s.RunFootstepRight", g_ppszPlayerSoundPrefixNames[m_iPlayerSoundType] ); - } - - CSoundParameters params; - if ( GetParametersForSound( szStepSound, params, NULL ) == false ) - return; - - CRecipientFilter filter; - filter.AddRecipientsByPAS( vecOrigin ); - -#ifndef CLIENT_DLL - // im MP, server removed all players in origins PVS, these players - // generate the footsteps clientside - if ( gpGlobals->maxClients > 1 ) - filter.RemoveRecipientsByPVS( vecOrigin ); -#endif - - EmitSound_t ep; - ep.m_nChannel = CHAN_BODY; - ep.m_pSoundName = params.soundname; - ep.m_flVolume = fvol; - ep.m_SoundLevel = params.soundlevel; - ep.m_nFlags = 0; - ep.m_nPitch = params.pitch; - ep.m_pOrigin = &vecOrigin; - - EmitSound( filter, entindex(), ep ); -} - - -//========================== -// ANIMATION CODE -//========================== - - -// Below this many degrees, slow down turning rate linearly -#define FADE_TURN_DEGREES 45.0f -// After this, need to start turning feet -#define MAX_TORSO_ANGLE 90.0f -// Below this amount, don't play a turning animation/perform IK -#define MIN_TURN_ANGLE_REQUIRING_TURN_ANIMATION 15.0f - -static ConVar tf2_feetyawrunscale( "tf2_feetyawrunscale", "2", FCVAR_REPLICATED, "Multiplier on tf2_feetyawrate to allow turning faster when running." ); -extern ConVar sv_backspeed; -extern ConVar mp_feetyawrate; -extern ConVar mp_facefronttime; -extern ConVar mp_ik; - -CPlayerAnimState::CPlayerAnimState( CHL2MP_Player *outer ) - : m_pOuter( outer ) -{ - m_flGaitYaw = 0.0f; - m_flGoalFeetYaw = 0.0f; - m_flCurrentFeetYaw = 0.0f; - m_flCurrentTorsoYaw = 0.0f; - m_flLastYaw = 0.0f; - m_flLastTurnTime = 0.0f; - m_flTurnCorrectionTime = 0.0f; -}; - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void CPlayerAnimState::Update() -{ - m_angRender = GetOuter()->GetLocalAngles(); - m_angRender[ PITCH ] = m_angRender[ ROLL ] = 0.0f; - - ComputePoseParam_BodyYaw(); - ComputePoseParam_BodyPitch(GetOuter()->GetModelPtr()); - ComputePoseParam_BodyLookYaw(); - - ComputePlaybackRate(); - -#ifdef CLIENT_DLL - GetOuter()->UpdateLookAt(); -#endif - -} - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void CPlayerAnimState::ComputePlaybackRate() -{ - // Determine ideal playback rate - Vector vel; - GetOuterAbsVelocity( vel ); - - float speed = vel.Length2D(); - - bool isMoving = ( speed > 0.5f ) ? true : false; - - float maxspeed = GetOuter()->GetSequenceGroundSpeed( GetOuter()->GetSequence() ); - - if ( isMoving && ( maxspeed > 0.0f ) ) - { - float flFactor = 1.0f; - - // Note this gets set back to 1.0 if sequence changes due to ResetSequenceInfo below - GetOuter()->SetPlaybackRate( ( speed * flFactor ) / maxspeed ); - - // BUG BUG: - // This stuff really should be m_flPlaybackRate = speed / m_flGroundSpeed - } - else - { - GetOuter()->SetPlaybackRate( 1.0f ); - } -} - -//----------------------------------------------------------------------------- -// Purpose: -// Output : CBasePlayer -//----------------------------------------------------------------------------- -CHL2MP_Player *CPlayerAnimState::GetOuter() -{ - return m_pOuter; -} - -//----------------------------------------------------------------------------- -// Purpose: -// Input : dt - -//----------------------------------------------------------------------------- -void CPlayerAnimState::EstimateYaw( void ) -{ - float dt = gpGlobals->frametime; - - if ( !dt ) - { - return; - } - - Vector est_velocity; - QAngle angles; - - GetOuterAbsVelocity( est_velocity ); - - angles = GetOuter()->GetLocalAngles(); - - if ( est_velocity[1] == 0 && est_velocity[0] == 0 ) - { - float flYawDiff = angles[YAW] - m_flGaitYaw; - flYawDiff = flYawDiff - (int)(flYawDiff / 360) * 360; - if (flYawDiff > 180) - flYawDiff -= 360; - if (flYawDiff < -180) - flYawDiff += 360; - - if (dt < 0.25) - flYawDiff *= dt * 4; - else - flYawDiff *= dt; - - m_flGaitYaw += flYawDiff; - m_flGaitYaw = m_flGaitYaw - (int)(m_flGaitYaw / 360) * 360; - } - else - { - m_flGaitYaw = (atan2(est_velocity[1], est_velocity[0]) * 180 / M_PI); - - if (m_flGaitYaw > 180) - m_flGaitYaw = 180; - else if (m_flGaitYaw < -180) - m_flGaitYaw = -180; - } -} - -//----------------------------------------------------------------------------- -// Purpose: Override for backpeddling -// Input : dt - -//----------------------------------------------------------------------------- -void CPlayerAnimState::ComputePoseParam_BodyYaw( void ) -{ - int iYaw = GetOuter()->LookupPoseParameter( "move_yaw" ); - if ( iYaw < 0 ) - return; - - // view direction relative to movement - float flYaw; - - EstimateYaw(); - - QAngle angles = GetOuter()->GetLocalAngles(); - float ang = angles[ YAW ]; - if ( ang > 180.0f ) - { - ang -= 360.0f; - } - else if ( ang < -180.0f ) - { - ang += 360.0f; - } - - // calc side to side turning - flYaw = ang - m_flGaitYaw; - // Invert for mapping into 8way blend - flYaw = -flYaw; - flYaw = flYaw - (int)(flYaw / 360) * 360; - - if (flYaw < -180) - { - flYaw = flYaw + 360; - } - else if (flYaw > 180) - { - flYaw = flYaw - 360; - } - - GetOuter()->SetPoseParameter( iYaw, flYaw ); - -#ifndef CLIENT_DLL - //Adrian: Make the model's angle match the legs so the hitboxes match on both sides. - GetOuter()->SetLocalAngles( QAngle( GetOuter()->GetAnimEyeAngles().x, m_flCurrentFeetYaw, 0 ) ); -#endif -} - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void CPlayerAnimState::ComputePoseParam_BodyPitch( CStudioHdr *pStudioHdr ) -{ - // Get pitch from v_angle - float flPitch = GetOuter()->GetLocalAngles()[ PITCH ]; - - if ( flPitch > 180.0f ) - { - flPitch -= 360.0f; - } - flPitch = clamp( flPitch, -90, 90 ); - - QAngle absangles = GetOuter()->GetAbsAngles(); - absangles.x = 0.0f; - m_angRender = absangles; - m_angRender[ PITCH ] = m_angRender[ ROLL ] = 0.0f; - - // See if we have a blender for pitch - GetOuter()->SetPoseParameter( pStudioHdr, "aim_pitch", flPitch ); -} - -//----------------------------------------------------------------------------- -// Purpose: -// Input : goal - -// maxrate - -// dt - -// current - -// Output : int -//----------------------------------------------------------------------------- -int CPlayerAnimState::ConvergeAngles( float goal,float maxrate, float dt, float& current ) -{ - int direction = TURN_NONE; - - float anglediff = goal - current; - float anglediffabs = fabs( anglediff ); - - anglediff = AngleNormalize( anglediff ); - - float scale = 1.0f; - if ( anglediffabs <= FADE_TURN_DEGREES ) - { - scale = anglediffabs / FADE_TURN_DEGREES; - // Always do at least a bit of the turn ( 1% ) - scale = clamp( scale, 0.01f, 1.0f ); - } - - float maxmove = maxrate * dt * scale; - - if ( fabs( anglediff ) < maxmove ) - { - current = goal; - } - else - { - if ( anglediff > 0 ) - { - current += maxmove; - direction = TURN_LEFT; - } - else - { - current -= maxmove; - direction = TURN_RIGHT; - } - } - - current = AngleNormalize( current ); - - return direction; -} - -void CPlayerAnimState::ComputePoseParam_BodyLookYaw( void ) -{ - QAngle absangles = GetOuter()->GetAbsAngles(); - absangles.y = AngleNormalize( absangles.y ); - m_angRender = absangles; - m_angRender[ PITCH ] = m_angRender[ ROLL ] = 0.0f; - - // See if we even have a blender for pitch - int upper_body_yaw = GetOuter()->LookupPoseParameter( "aim_yaw" ); - if ( upper_body_yaw < 0 ) - { - return; - } - - // Assume upper and lower bodies are aligned and that we're not turning - float flGoalTorsoYaw = 0.0f; - int turning = TURN_NONE; - float turnrate = 360.0f; - - Vector vel; - - GetOuterAbsVelocity( vel ); - - bool isMoving = ( vel.Length() > 1.0f ) ? true : false; - - if ( !isMoving ) - { - // Just stopped moving, try and clamp feet - if ( m_flLastTurnTime <= 0.0f ) - { - m_flLastTurnTime = gpGlobals->curtime; - m_flLastYaw = GetOuter()->GetAnimEyeAngles().y; - // Snap feet to be perfectly aligned with torso/eyes - m_flGoalFeetYaw = GetOuter()->GetAnimEyeAngles().y; - m_flCurrentFeetYaw = m_flGoalFeetYaw; - m_nTurningInPlace = TURN_NONE; - } - - // If rotating in place, update stasis timer - if ( m_flLastYaw != GetOuter()->GetAnimEyeAngles().y ) - { - m_flLastTurnTime = gpGlobals->curtime; - m_flLastYaw = GetOuter()->GetAnimEyeAngles().y; - } - - if ( m_flGoalFeetYaw != m_flCurrentFeetYaw ) - { - m_flLastTurnTime = gpGlobals->curtime; - } - - turning = ConvergeAngles( m_flGoalFeetYaw, turnrate, gpGlobals->frametime, m_flCurrentFeetYaw ); - - QAngle eyeAngles = GetOuter()->GetAnimEyeAngles(); - QAngle vAngle = GetOuter()->GetLocalAngles(); - - // See how far off current feetyaw is from true yaw - float yawdelta = GetOuter()->GetAnimEyeAngles().y - m_flCurrentFeetYaw; - yawdelta = AngleNormalize( yawdelta ); - - bool rotated_too_far = false; - - float yawmagnitude = fabs( yawdelta ); - - // If too far, then need to turn in place - if ( yawmagnitude > 45 ) - { - rotated_too_far = true; - } - - // Standing still for a while, rotate feet around to face forward - // Or rotated too far - // FIXME: Play an in place turning animation - if ( rotated_too_far || - ( gpGlobals->curtime > m_flLastTurnTime + mp_facefronttime.GetFloat() ) ) - { - m_flGoalFeetYaw = GetOuter()->GetAnimEyeAngles().y; - m_flLastTurnTime = gpGlobals->curtime; - - /* float yd = m_flCurrentFeetYaw - m_flGoalFeetYaw; - if ( yd > 0 ) - { - m_nTurningInPlace = TURN_RIGHT; - } - else if ( yd < 0 ) - { - m_nTurningInPlace = TURN_LEFT; - } - else - { - m_nTurningInPlace = TURN_NONE; - } - - turning = ConvergeAngles( m_flGoalFeetYaw, turnrate, gpGlobals->frametime, m_flCurrentFeetYaw ); - yawdelta = GetOuter()->GetAnimEyeAngles().y - m_flCurrentFeetYaw;*/ - - } - - // Snap upper body into position since the delta is already smoothed for the feet - flGoalTorsoYaw = yawdelta; - m_flCurrentTorsoYaw = flGoalTorsoYaw; - } - else - { - m_flLastTurnTime = 0.0f; - m_nTurningInPlace = TURN_NONE; - m_flCurrentFeetYaw = m_flGoalFeetYaw = GetOuter()->GetAnimEyeAngles().y; - flGoalTorsoYaw = 0.0f; - m_flCurrentTorsoYaw = GetOuter()->GetAnimEyeAngles().y - m_flCurrentFeetYaw; - } - - - if ( turning == TURN_NONE ) - { - m_nTurningInPlace = turning; - } - - if ( m_nTurningInPlace != TURN_NONE ) - { - // If we're close to finishing the turn, then turn off the turning animation - if ( fabs( m_flCurrentFeetYaw - m_flGoalFeetYaw ) < MIN_TURN_ANGLE_REQUIRING_TURN_ANIMATION ) - { - m_nTurningInPlace = TURN_NONE; - } - } - - // Rotate entire body into position - absangles = GetOuter()->GetAbsAngles(); - absangles.y = m_flCurrentFeetYaw; - m_angRender = absangles; - m_angRender[ PITCH ] = m_angRender[ ROLL ] = 0.0f; - - GetOuter()->SetPoseParameter( upper_body_yaw, clamp( m_flCurrentTorsoYaw, -60.0f, 60.0f ) ); - - /* - // FIXME: Adrian, what is this? - int body_yaw = GetOuter()->LookupPoseParameter( "body_yaw" ); - - if ( body_yaw >= 0 ) - { - GetOuter()->SetPoseParameter( body_yaw, 30 ); - } - */ - -} - - - -//----------------------------------------------------------------------------- -// Purpose: -// Input : activity - -// Output : Activity -//----------------------------------------------------------------------------- -Activity CPlayerAnimState::BodyYawTranslateActivity( Activity activity ) -{ - // Not even standing still, sigh - if ( activity != ACT_IDLE ) - return activity; - - // Not turning - switch ( m_nTurningInPlace ) - { - default: - case TURN_NONE: - return activity; - /* - case TURN_RIGHT: - return ACT_TURNRIGHT45; - case TURN_LEFT: - return ACT_TURNLEFT45; - */ - case TURN_RIGHT: - case TURN_LEFT: - return mp_ik.GetBool() ? ACT_TURN : activity; - } - - Assert( 0 ); - return activity; -} - -const QAngle& CPlayerAnimState::GetRenderAngles() -{ - return m_angRender; -} - - -void CPlayerAnimState::GetOuterAbsVelocity( Vector& vel ) -{ -#if defined( CLIENT_DLL ) - GetOuter()->EstimateAbsVelocity( vel ); -#else - vel = GetOuter()->GetAbsVelocity(); -#endif -} \ No newline at end of file diff --git a/sp/src/game/shared/hl2mp/hl2mp_player_shared.h b/sp/src/game/shared/hl2mp/hl2mp_player_shared.h deleted file mode 100644 index 3aee9237..00000000 --- a/sp/src/game/shared/hl2mp/hl2mp_player_shared.h +++ /dev/null @@ -1,97 +0,0 @@ -//========= Copyright Valve Corporation, All rights reserved. ============// -// -// Purpose: -// -// $NoKeywords: $ -// -//=============================================================================// -#ifndef HL2MP_PLAYER_SHARED_H -#define HL2MP_PLAYER_SHARED_H -#pragma once - -#define HL2MP_PUSHAWAY_THINK_INTERVAL (1.0f / 20.0f) -#include "studio.h" - - -enum -{ - PLAYER_SOUNDS_CITIZEN = 0, - PLAYER_SOUNDS_COMBINESOLDIER, - PLAYER_SOUNDS_METROPOLICE, - PLAYER_SOUNDS_MAX, -}; - -enum HL2MPPlayerState -{ - // Happily running around in the game. - STATE_ACTIVE=0, - STATE_OBSERVER_MODE, // Noclipping around, watching players, etc. - NUM_PLAYER_STATES -}; - - -#if defined( CLIENT_DLL ) -#define CHL2MP_Player C_HL2MP_Player -#endif - -class CPlayerAnimState -{ -public: - enum - { - TURN_NONE = 0, - TURN_LEFT, - TURN_RIGHT - }; - - CPlayerAnimState( CHL2MP_Player *outer ); - - Activity BodyYawTranslateActivity( Activity activity ); - - void Update(); - - const QAngle& GetRenderAngles(); - - void GetPoseParameters( CStudioHdr *pStudioHdr, float poseParameter[MAXSTUDIOPOSEPARAM] ); - - CHL2MP_Player *GetOuter(); - -private: - void GetOuterAbsVelocity( Vector& vel ); - - int ConvergeAngles( float goal,float maxrate, float dt, float& current ); - - void EstimateYaw( void ); - void ComputePoseParam_BodyYaw( void ); - void ComputePoseParam_BodyPitch( CStudioHdr *pStudioHdr ); - void ComputePoseParam_BodyLookYaw( void ); - - void ComputePlaybackRate(); - - CHL2MP_Player *m_pOuter; - - float m_flGaitYaw; - float m_flStoredCycle; - - // The following variables are used for tweaking the yaw of the upper body when standing still and - // making sure that it smoothly blends in and out once the player starts moving - // Direction feet were facing when we stopped moving - float m_flGoalFeetYaw; - float m_flCurrentFeetYaw; - - float m_flCurrentTorsoYaw; - - // To check if they are rotating in place - float m_flLastYaw; - // Time when we stopped moving - float m_flLastTurnTime; - - // One of the above enums - int m_nTurningInPlace; - - QAngle m_angRender; - - float m_flTurnCorrectionTime; -}; - -#endif //HL2MP_PLAYER_SHARED_h diff --git a/sp/src/game/shared/hl2mp/hl2mp_weapon_parse.cpp b/sp/src/game/shared/hl2mp/hl2mp_weapon_parse.cpp deleted file mode 100644 index 9b83dce7..00000000 --- a/sp/src/game/shared/hl2mp/hl2mp_weapon_parse.cpp +++ /dev/null @@ -1,32 +0,0 @@ -//========= Copyright Valve Corporation, All rights reserved. ============// -// -// Purpose: -// -//=============================================================================// - -#include "cbase.h" -#include -#include "hl2mp_weapon_parse.h" -#include "ammodef.h" - -FileWeaponInfo_t* CreateWeaponInfo() -{ - return new CHL2MPSWeaponInfo; -} - - - -CHL2MPSWeaponInfo::CHL2MPSWeaponInfo() -{ - m_iPlayerDamage = 0; -} - - -void CHL2MPSWeaponInfo::Parse( KeyValues *pKeyValuesData, const char *szWeaponName ) -{ - BaseClass::Parse( pKeyValuesData, szWeaponName ); - - m_iPlayerDamage = pKeyValuesData->GetInt( "damage", 0 ); -} - - diff --git a/sp/src/game/shared/hl2mp/hl2mp_weapon_parse.h b/sp/src/game/shared/hl2mp/hl2mp_weapon_parse.h deleted file mode 100644 index 2ec16dd6..00000000 --- a/sp/src/game/shared/hl2mp/hl2mp_weapon_parse.h +++ /dev/null @@ -1,35 +0,0 @@ -//========= Copyright Valve Corporation, All rights reserved. ============// -// -// Purpose: -// -//=============================================================================// - -#ifndef HL2MP_WEAPON_PARSE_H -#define HL2MP_WEAPON_PARSE_H -#ifdef _WIN32 -#pragma once -#endif - - -#include "weapon_parse.h" -#include "networkvar.h" - - -//-------------------------------------------------------------------------------------------------------- -class CHL2MPSWeaponInfo : public FileWeaponInfo_t -{ -public: - DECLARE_CLASS_GAMEROOT( CHL2MPSWeaponInfo, FileWeaponInfo_t ); - - CHL2MPSWeaponInfo(); - - virtual void Parse( ::KeyValues *pKeyValuesData, const char *szWeaponName ); - - -public: - - int m_iPlayerDamage; -}; - - -#endif // HL2MP_WEAPON_PARSE_H diff --git a/sp/src/game/shared/hl2mp/weapon_357.cpp b/sp/src/game/shared/hl2mp/weapon_357.cpp deleted file mode 100644 index d943f278..00000000 --- a/sp/src/game/shared/hl2mp/weapon_357.cpp +++ /dev/null @@ -1,154 +0,0 @@ - -//========= Copyright Valve Corporation, All rights reserved. ============// -// -// Purpose: -// -//=============================================================================// - -#include "cbase.h" -#include "npcevent.h" -#include "in_buttons.h" - -#ifdef CLIENT_DLL - #include "c_hl2mp_player.h" -#else - #include "hl2mp_player.h" -#endif - -#include "weapon_hl2mpbasehlmpcombatweapon.h" - -#ifdef CLIENT_DLL -#define CWeapon357 C_Weapon357 -#endif - -//----------------------------------------------------------------------------- -// CWeapon357 -//----------------------------------------------------------------------------- - -class CWeapon357 : public CBaseHL2MPCombatWeapon -{ - DECLARE_CLASS( CWeapon357, CBaseHL2MPCombatWeapon ); -public: - - CWeapon357( void ); - - void PrimaryAttack( void ); - DECLARE_NETWORKCLASS(); - DECLARE_PREDICTABLE(); - -#ifndef CLIENT_DLL - DECLARE_ACTTABLE(); -#endif - -private: - - CWeapon357( const CWeapon357 & ); -}; - -IMPLEMENT_NETWORKCLASS_ALIASED( Weapon357, DT_Weapon357 ) - -BEGIN_NETWORK_TABLE( CWeapon357, DT_Weapon357 ) -END_NETWORK_TABLE() - -BEGIN_PREDICTION_DATA( CWeapon357 ) -END_PREDICTION_DATA() - -LINK_ENTITY_TO_CLASS( weapon_357, CWeapon357 ); -PRECACHE_WEAPON_REGISTER( weapon_357 ); - - -#ifndef CLIENT_DLL -acttable_t CWeapon357::m_acttable[] = -{ - { ACT_HL2MP_IDLE, ACT_HL2MP_IDLE_PISTOL, false }, - { ACT_HL2MP_RUN, ACT_HL2MP_RUN_PISTOL, false }, - { ACT_HL2MP_IDLE_CROUCH, ACT_HL2MP_IDLE_CROUCH_PISTOL, false }, - { ACT_HL2MP_WALK_CROUCH, ACT_HL2MP_WALK_CROUCH_PISTOL, false }, - { ACT_HL2MP_GESTURE_RANGE_ATTACK, ACT_HL2MP_GESTURE_RANGE_ATTACK_PISTOL, false }, - { ACT_HL2MP_GESTURE_RELOAD, ACT_HL2MP_GESTURE_RELOAD_PISTOL, false }, - { ACT_HL2MP_JUMP, ACT_HL2MP_JUMP_PISTOL, false }, - { ACT_RANGE_ATTACK1, ACT_RANGE_ATTACK_PISTOL, false }, -}; - - - -IMPLEMENT_ACTTABLE( CWeapon357 ); - -#endif - -//----------------------------------------------------------------------------- -// Purpose: Constructor -//----------------------------------------------------------------------------- -CWeapon357::CWeapon357( void ) -{ - m_bReloadsSingly = false; - m_bFiresUnderwater = false; -} - -//----------------------------------------------------------------------------- -// 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 ); - } -} diff --git a/sp/src/game/shared/hl2mp/weapon_ar2.cpp b/sp/src/game/shared/hl2mp/weapon_ar2.cpp deleted file mode 100644 index 5086db1b..00000000 --- a/sp/src/game/shared/hl2mp/weapon_ar2.cpp +++ /dev/null @@ -1,312 +0,0 @@ -//========= Copyright Valve Corporation, All rights reserved. ============// -// -// Purpose: -// -// $NoKeywords: $ -//=============================================================================// - -#include "cbase.h" -#include "npcevent.h" - -#ifdef CLIENT_DLL - #include "c_hl2mp_player.h" - #include "c_te_effect_dispatch.h" -#else - #include "hl2mp_player.h" - #include "te_effect_dispatch.h" - #include "prop_combine_ball.h" -#endif - -#include "weapon_ar2.h" -#include "effect_dispatch_data.h" - - -// memdbgon must be the last include file in a .cpp file!!! -#include "tier0/memdbgon.h" - -#ifndef CLIENT_DLL -ConVar sk_weapon_ar2_alt_fire_radius( "sk_weapon_ar2_alt_fire_radius", "10" ); -ConVar sk_weapon_ar2_alt_fire_duration( "sk_weapon_ar2_alt_fire_duration", "4" ); -ConVar sk_weapon_ar2_alt_fire_mass( "sk_weapon_ar2_alt_fire_mass", "150" ); -#endif - -//========================================================= -//========================================================= - - -IMPLEMENT_NETWORKCLASS_ALIASED( WeaponAR2, DT_WeaponAR2 ) - -BEGIN_NETWORK_TABLE( CWeaponAR2, DT_WeaponAR2 ) -END_NETWORK_TABLE() - -BEGIN_PREDICTION_DATA( CWeaponAR2 ) -END_PREDICTION_DATA() - -LINK_ENTITY_TO_CLASS( weapon_ar2, CWeaponAR2 ); -PRECACHE_WEAPON_REGISTER(weapon_ar2); - - -#ifndef CLIENT_DLL - -acttable_t CWeaponAR2::m_acttable[] = -{ - { ACT_HL2MP_IDLE, ACT_HL2MP_IDLE_AR2, false }, - { ACT_HL2MP_RUN, ACT_HL2MP_RUN_AR2, false }, - { ACT_HL2MP_IDLE_CROUCH, ACT_HL2MP_IDLE_CROUCH_AR2, false }, - { ACT_HL2MP_WALK_CROUCH, ACT_HL2MP_WALK_CROUCH_AR2, false }, - { ACT_HL2MP_GESTURE_RANGE_ATTACK, ACT_HL2MP_GESTURE_RANGE_ATTACK_AR2, false }, - { ACT_HL2MP_GESTURE_RELOAD, ACT_HL2MP_GESTURE_RELOAD_AR2, false }, - { ACT_HL2MP_JUMP, ACT_HL2MP_JUMP_AR2, false }, - { ACT_RANGE_ATTACK1, ACT_RANGE_ATTACK_AR2, false }, -}; - -IMPLEMENT_ACTTABLE(CWeaponAR2); - -#endif - -CWeaponAR2::CWeaponAR2( ) -{ - m_fMinRange1 = 65; - m_fMaxRange1 = 2048; - - m_fMinRange2 = 256; - m_fMaxRange2 = 1024; - - m_nShotsFired = 0; - m_nVentPose = -1; -} - -void CWeaponAR2::Precache( void ) -{ - BaseClass::Precache(); - -#ifndef CLIENT_DLL - - UTIL_PrecacheOther( "prop_combine_ball" ); - UTIL_PrecacheOther( "env_entity_dissolver" ); -#endif - -} - -//----------------------------------------------------------------------------- -// Purpose: Handle grenade detonate in-air (even when no ammo is left) -//----------------------------------------------------------------------------- -void CWeaponAR2::ItemPostFrame( void ) -{ - // See if we need to fire off our secondary round - if ( m_bShotDelayed && gpGlobals->curtime > m_flDelayedFire ) - { - DelayedAttack(); - } - - // Update our pose parameter for the vents - CBasePlayer *pOwner = ToBasePlayer( GetOwner() ); - - if ( pOwner ) - { - CBaseViewModel *pVM = pOwner->GetViewModel(); - - if ( pVM ) - { - if ( m_nVentPose == -1 ) - { - m_nVentPose = pVM->LookupPoseParameter( "VentPoses" ); - } - - float flVentPose = RemapValClamped( m_nShotsFired, 0, 5, 0.0f, 1.0f ); - pVM->SetPoseParameter( m_nVentPose, flVentPose ); - } - } - - BaseClass::ItemPostFrame(); -} - -//----------------------------------------------------------------------------- -// Purpose: -// Output : Activity -//----------------------------------------------------------------------------- -Activity CWeaponAR2::GetPrimaryAttackActivity( void ) -{ - if ( m_nShotsFired < 2 ) - return ACT_VM_PRIMARYATTACK; - - if ( m_nShotsFired < 3 ) - return ACT_VM_RECOIL1; - - if ( m_nShotsFired < 4 ) - return ACT_VM_RECOIL2; - - return ACT_VM_RECOIL3; -} - -//----------------------------------------------------------------------------- -// Purpose: -// Input : &tr - -// nDamageType - -//----------------------------------------------------------------------------- -void CWeaponAR2::DoImpactEffect( trace_t &tr, int nDamageType ) -{ - CEffectData data; - - data.m_vOrigin = tr.endpos + ( tr.plane.normal * 1.0f ); - data.m_vNormal = tr.plane.normal; - - DispatchEffect( "AR2Impact", data ); - - BaseClass::DoImpactEffect( tr, nDamageType ); -} - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void CWeaponAR2::DelayedAttack( void ) -{ - m_bShotDelayed = false; - - CBasePlayer *pOwner = ToBasePlayer( GetOwner() ); - - if ( pOwner == NULL ) - return; - - // Deplete the clip completely - SendWeaponAnim( ACT_VM_SECONDARYATTACK ); - m_flNextSecondaryAttack = pOwner->m_flNextAttack = gpGlobals->curtime + SequenceDuration(); - - // Register a muzzleflash for the AI - pOwner->DoMuzzleFlash(); - - WeaponSound( WPN_DOUBLE ); - - // Fire the bullets - Vector vecSrc = pOwner->Weapon_ShootPosition( ); - Vector vecAiming = pOwner->GetAutoaimVector( AUTOAIM_2DEGREES ); - Vector impactPoint = vecSrc + ( vecAiming * MAX_TRACE_LENGTH ); - - // Fire the bullets - Vector vecVelocity = vecAiming * 1000.0f; - -#ifndef CLIENT_DLL - // Fire the combine ball - CreateCombineBall( vecSrc, - vecVelocity, - sk_weapon_ar2_alt_fire_radius.GetFloat(), - sk_weapon_ar2_alt_fire_mass.GetFloat(), - sk_weapon_ar2_alt_fire_duration.GetFloat(), - pOwner ); - - // View effects - color32 white = {255, 255, 255, 64}; - UTIL_ScreenFade( pOwner, white, 0.1, 0, FFADE_IN ); -#endif - - //Disorient the player - QAngle angles = pOwner->GetLocalAngles(); - - angles.x += random->RandomInt( -4, 4 ); - angles.y += random->RandomInt( -4, 4 ); - angles.z = 0; - -// pOwner->SnapEyeAngles( angles ); - - pOwner->ViewPunch( QAngle( SharedRandomInt( "ar2pax", -8, -12 ), SharedRandomInt( "ar2pay", 1, 2 ), 0 ) ); - - // Decrease ammo - pOwner->RemoveAmmo( 1, m_iSecondaryAmmoType ); - - // Can shoot again immediately - m_flNextPrimaryAttack = gpGlobals->curtime + 0.5f; - - // Can blow up after a short delay (so have time to release mouse button) - m_flNextSecondaryAttack = gpGlobals->curtime + 1.0f; -} - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void CWeaponAR2::SecondaryAttack( void ) -{ - if ( m_bShotDelayed ) - return; - - // Cannot fire underwater - if ( GetOwner() && GetOwner()->GetWaterLevel() == 3 ) - { - SendWeaponAnim( ACT_VM_DRYFIRE ); - BaseClass::WeaponSound( EMPTY ); - m_flNextSecondaryAttack = gpGlobals->curtime + 0.5f; - return; - } - - m_bShotDelayed = true; - m_flNextPrimaryAttack = m_flNextSecondaryAttack = m_flDelayedFire = gpGlobals->curtime + 0.5f; - - SendWeaponAnim( ACT_VM_FIDGET ); - WeaponSound( SPECIAL1 ); -} - -//----------------------------------------------------------------------------- -// Purpose: Override if we're waiting to release a shot -// Output : Returns true on success, false on failure. -//----------------------------------------------------------------------------- -bool CWeaponAR2::CanHolster( void ) -{ - if ( m_bShotDelayed ) - return false; - - return BaseClass::CanHolster(); -} - - -bool CWeaponAR2::Deploy( void ) -{ - m_bShotDelayed = false; - m_flDelayedFire = 0.0f; - - return BaseClass::Deploy(); -} - -//----------------------------------------------------------------------------- -// Purpose: Override if we're waiting to release a shot -//----------------------------------------------------------------------------- -bool CWeaponAR2::Reload( void ) -{ - if ( m_bShotDelayed ) - return false; - - return BaseClass::Reload(); -} - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void CWeaponAR2::AddViewKick( void ) -{ - #define EASY_DAMPEN 0.5f - #define MAX_VERTICAL_KICK 8.0f //Degrees - #define SLIDE_LIMIT 5.0f //Seconds - - //Get the view kick - CBasePlayer *pPlayer = ToBasePlayer( GetOwner() ); - - if (!pPlayer) - return; - - DoMachineGunKick( pPlayer, EASY_DAMPEN, MAX_VERTICAL_KICK, m_fFireDuration, SLIDE_LIMIT ); -} - -//----------------------------------------------------------------------------- -const WeaponProficiencyInfo_t *CWeaponAR2::GetProficiencyValues() -{ - static WeaponProficiencyInfo_t proficiencyTable[] = - { - { 7.0, 0.75 }, - { 5.00, 0.75 }, - { 3.0, 0.85 }, - { 5.0/3.0, 0.75 }, - { 1.00, 1.0 }, - }; - - COMPILE_TIME_ASSERT( ARRAYSIZE(proficiencyTable) == WEAPON_PROFICIENCY_PERFECT + 1); - - return proficiencyTable; -} diff --git a/sp/src/game/shared/hl2mp/weapon_ar2.h b/sp/src/game/shared/hl2mp/weapon_ar2.h deleted file mode 100644 index 8aa8dde8..00000000 --- a/sp/src/game/shared/hl2mp/weapon_ar2.h +++ /dev/null @@ -1,84 +0,0 @@ -//========= Copyright Valve Corporation, All rights reserved. ============// -// -// Purpose: Projectile shot from the AR2 -// -// $Workfile: $ -// $Date: $ -// -//----------------------------------------------------------------------------- -// $Log: $ -// -// $NoKeywords: $ -//=============================================================================// - -#ifndef WEAPONAR2_H -#define WEAPONAR2_H - -#include "basegrenade_shared.h" -#include "weapon_hl2mpbase_machinegun.h" - -#ifdef CLIENT_DLL -#define CWeaponAR2 C_WeaponAR2 -#endif - -class CWeaponAR2 : public CHL2MPMachineGun -{ -public: - DECLARE_CLASS( CWeaponAR2, CHL2MPMachineGun ); - - CWeaponAR2(); - - DECLARE_NETWORKCLASS(); - DECLARE_PREDICTABLE(); - - void ItemPostFrame( void ); - void Precache( void ); - - void SecondaryAttack( void ); - void DelayedAttack( void ); - - const char *GetTracerType( void ) { return "AR2Tracer"; } - - void AddViewKick( void ); - - int GetMinBurst( void ) { return 2; } - int GetMaxBurst( void ) { return 5; } - float GetFireRate( void ) { return 0.1f; } - - bool CanHolster( void ); - bool Reload( void ); - - Activity GetPrimaryAttackActivity( void ); - - void DoImpactEffect( trace_t &tr, int nDamageType ); - - virtual bool Deploy( void ); - - - virtual const Vector& GetBulletSpread( void ) - { - static Vector cone; - - cone = VECTOR_CONE_3DEGREES; - - return cone; - } - - const WeaponProficiencyInfo_t *GetProficiencyValues(); - -private: - CWeaponAR2( const CWeaponAR2 & ); - -protected: - - float m_flDelayedFire; - bool m_bShotDelayed; - int m_nVentPose; - -#ifndef CLIENT_DLL - DECLARE_ACTTABLE(); -#endif -}; - - -#endif //WEAPONAR2_H diff --git a/sp/src/game/shared/hl2mp/weapon_crossbow.cpp b/sp/src/game/shared/hl2mp/weapon_crossbow.cpp deleted file mode 100644 index 9e8d92e0..00000000 --- a/sp/src/game/shared/hl2mp/weapon_crossbow.cpp +++ /dev/null @@ -1,956 +0,0 @@ -//========= Copyright Valve Corporation, All rights reserved. ============// -// -// Purpose: -// -//=============================================================================// - -#include "cbase.h" -#include "npcevent.h" -#include "in_buttons.h" - -#ifdef CLIENT_DLL - #include "c_hl2mp_player.h" - #include "c_te_effect_dispatch.h" -#else - #include "hl2mp_player.h" - #include "te_effect_dispatch.h" - #include "IEffects.h" - #include "Sprite.h" - #include "SpriteTrail.h" - #include "beam_shared.h" -#endif - -#include "weapon_hl2mpbasehlmpcombatweapon.h" -#include "effect_dispatch_data.h" - -// memdbgon must be the last include file in a .cpp file!!! -#include "tier0/memdbgon.h" - -//#define BOLT_MODEL "models/crossbow_bolt.mdl" -#define BOLT_MODEL "models/weapons/w_missile_closed.mdl" - -#define BOLT_AIR_VELOCITY 3500 -#define BOLT_WATER_VELOCITY 1500 -#define BOLT_SKIN_NORMAL 0 -#define BOLT_SKIN_GLOW 1 - - -#ifndef CLIENT_DLL - -extern ConVar sk_plr_dmg_crossbow; -extern ConVar sk_npc_dmg_crossbow; - -void TE_StickyBolt( IRecipientFilter& filter, float delay, Vector vecDirection, const Vector *origin ); - -//----------------------------------------------------------------------------- -// Crossbow Bolt -//----------------------------------------------------------------------------- -class CCrossbowBolt : public CBaseCombatCharacter -{ - DECLARE_CLASS( CCrossbowBolt, CBaseCombatCharacter ); - -public: - CCrossbowBolt() { }; - ~CCrossbowBolt(); - - Class_T Classify( void ) { return CLASS_NONE; } - -public: - void Spawn( void ); - void Precache( void ); - void BubbleThink( void ); - void BoltTouch( CBaseEntity *pOther ); - bool CreateVPhysics( void ); - unsigned int PhysicsSolidMaskForEntity() const; - static CCrossbowBolt *BoltCreate( const Vector &vecOrigin, const QAngle &angAngles, int iDamage, CBaseEntity *pentOwner = NULL ); - -protected: - - bool CreateSprites( void ); - - CHandle m_pGlowSprite; - //CHandle m_pGlowTrail; - - int m_iDamage; - - DECLARE_DATADESC(); - DECLARE_SERVERCLASS(); -}; -LINK_ENTITY_TO_CLASS( crossbow_bolt, CCrossbowBolt ); - -BEGIN_DATADESC( CCrossbowBolt ) - // Function Pointers - DEFINE_FUNCTION( BubbleThink ), - DEFINE_FUNCTION( BoltTouch ), - - // These are recreated on reload, they don't need storage - DEFINE_FIELD( m_pGlowSprite, FIELD_EHANDLE ), - //DEFINE_FIELD( m_pGlowTrail, FIELD_EHANDLE ), - -END_DATADESC() - -IMPLEMENT_SERVERCLASS_ST( CCrossbowBolt, DT_CrossbowBolt ) -END_SEND_TABLE() - -CCrossbowBolt *CCrossbowBolt::BoltCreate(const Vector &vecOrigin, const QAngle &angAngles, int iDamage, CBaseEntity *pentOwner) -{ - // Create a new entity with CCrossbowBolt private data - CCrossbowBolt *pBolt = (CCrossbowBolt *)CreateEntityByName( "crossbow_bolt" ); - UTIL_SetOrigin( pBolt, vecOrigin ); - pBolt->SetAbsAngles( angAngles ); - pBolt->Spawn(); - pBolt->SetOwnerEntity( pentOwner ); - - pBolt->m_iDamage = iDamage; - - return pBolt; -} - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -CCrossbowBolt::~CCrossbowBolt( void ) -{ - if ( m_pGlowSprite ) - { - UTIL_Remove( m_pGlowSprite ); - } -} - -//----------------------------------------------------------------------------- -// Purpose: -// Output : Returns true on success, false on failure. -//----------------------------------------------------------------------------- -bool CCrossbowBolt::CreateVPhysics( void ) -{ - // Create the object in the physics system - VPhysicsInitNormal( SOLID_BBOX, FSOLID_NOT_STANDABLE, false ); - - return true; -} - -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -unsigned int CCrossbowBolt::PhysicsSolidMaskForEntity() const -{ - return ( BaseClass::PhysicsSolidMaskForEntity() | CONTENTS_HITBOX ) & ~CONTENTS_GRATE; -} - -//----------------------------------------------------------------------------- -// Purpose: -// Output : Returns true on success, false on failure. -//----------------------------------------------------------------------------- -bool CCrossbowBolt::CreateSprites( void ) -{ - // Start up the eye glow - m_pGlowSprite = CSprite::SpriteCreate( "sprites/light_glow02_noz.vmt", GetLocalOrigin(), false ); - - if ( m_pGlowSprite != NULL ) - { - m_pGlowSprite->FollowEntity( this ); - m_pGlowSprite->SetTransparency( kRenderGlow, 255, 255, 255, 128, kRenderFxNoDissipation ); - m_pGlowSprite->SetScale( 0.2f ); - m_pGlowSprite->TurnOff(); - } - - return true; -} - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void CCrossbowBolt::Spawn( void ) -{ - Precache( ); - - SetModel( "models/crossbow_bolt.mdl" ); - SetMoveType( MOVETYPE_FLYGRAVITY, MOVECOLLIDE_FLY_CUSTOM ); - UTIL_SetSize( this, -Vector(1,1,1), Vector(1,1,1) ); - SetSolid( SOLID_BBOX ); - SetGravity( 0.05f ); - - // Make sure we're updated if we're underwater - UpdateWaterState(); - - SetTouch( &CCrossbowBolt::BoltTouch ); - - SetThink( &CCrossbowBolt::BubbleThink ); - SetNextThink( gpGlobals->curtime + 0.1f ); - - CreateSprites(); - - // Make us glow until we've hit the wall - m_nSkin = BOLT_SKIN_GLOW; -} - - -void CCrossbowBolt::Precache( void ) -{ - PrecacheModel( BOLT_MODEL ); - - // This is used by C_TEStickyBolt, despte being different from above!!! - PrecacheModel( "models/crossbow_bolt.mdl" ); - - PrecacheModel( "sprites/light_glow02_noz.vmt" ); -} - -//----------------------------------------------------------------------------- -// Purpose: -// Input : *pOther - -//----------------------------------------------------------------------------- -void CCrossbowBolt::BoltTouch( CBaseEntity *pOther ) -{ - if ( !pOther->IsSolid() || pOther->IsSolidFlagSet(FSOLID_VOLUME_CONTENTS) ) - return; - - if ( pOther->m_takedamage != DAMAGE_NO ) - { - trace_t tr, tr2; - tr = BaseClass::GetTouchTrace(); - Vector vecNormalizedVel = GetAbsVelocity(); - - ClearMultiDamage(); - VectorNormalize( vecNormalizedVel ); - - if( GetOwnerEntity() && GetOwnerEntity()->IsPlayer() && pOther->IsNPC() ) - { - CTakeDamageInfo dmgInfo( this, GetOwnerEntity(), m_iDamage, DMG_NEVERGIB ); - dmgInfo.AdjustPlayerDamageInflictedForSkillLevel(); - CalculateMeleeDamageForce( &dmgInfo, vecNormalizedVel, tr.endpos, 0.7f ); - dmgInfo.SetDamagePosition( tr.endpos ); - pOther->DispatchTraceAttack( dmgInfo, vecNormalizedVel, &tr ); - } - else - { - CTakeDamageInfo dmgInfo( this, GetOwnerEntity(), m_iDamage, DMG_BULLET | DMG_NEVERGIB ); - CalculateMeleeDamageForce( &dmgInfo, vecNormalizedVel, tr.endpos, 0.7f ); - dmgInfo.SetDamagePosition( tr.endpos ); - pOther->DispatchTraceAttack( dmgInfo, vecNormalizedVel, &tr ); - } - - ApplyMultiDamage(); - - //Adrian: keep going through the glass. - if ( pOther->GetCollisionGroup() == COLLISION_GROUP_BREAKABLE_GLASS ) - return; - - SetAbsVelocity( Vector( 0, 0, 0 ) ); - - // play body "thwack" sound - EmitSound( "Weapon_Crossbow.BoltHitBody" ); - - Vector vForward; - - AngleVectors( GetAbsAngles(), &vForward ); - VectorNormalize ( vForward ); - - UTIL_TraceLine( GetAbsOrigin(), GetAbsOrigin() + vForward * 128, MASK_OPAQUE, pOther, COLLISION_GROUP_NONE, &tr2 ); - - if ( tr2.fraction != 1.0f ) - { -// NDebugOverlay::Box( tr2.endpos, Vector( -16, -16, -16 ), Vector( 16, 16, 16 ), 0, 255, 0, 0, 10 ); -// NDebugOverlay::Box( GetAbsOrigin(), Vector( -16, -16, -16 ), Vector( 16, 16, 16 ), 0, 0, 255, 0, 10 ); - - if ( tr2.m_pEnt == NULL || ( tr2.m_pEnt && tr2.m_pEnt->GetMoveType() == MOVETYPE_NONE ) ) - { - CEffectData data; - - data.m_vOrigin = tr2.endpos; - data.m_vNormal = vForward; - data.m_nEntIndex = tr2.fraction != 1.0f; - - DispatchEffect( "BoltImpact", data ); - } - } - - SetTouch( NULL ); - SetThink( NULL ); - - UTIL_Remove( this ); - } - else - { - trace_t tr; - tr = BaseClass::GetTouchTrace(); - - // See if we struck the world - if ( pOther->GetMoveType() == MOVETYPE_NONE && !( tr.surface.flags & SURF_SKY ) ) - { - EmitSound( "Weapon_Crossbow.BoltHitWorld" ); - - // if what we hit is static architecture, can stay around for a while. - Vector vecDir = GetAbsVelocity(); - float speed = VectorNormalize( vecDir ); - - // See if we should reflect off this surface - float hitDot = DotProduct( tr.plane.normal, -vecDir ); - - if ( ( hitDot < 0.5f ) && ( speed > 100 ) ) - { - Vector vReflection = 2.0f * tr.plane.normal * hitDot + vecDir; - - QAngle reflectAngles; - - VectorAngles( vReflection, reflectAngles ); - - SetLocalAngles( reflectAngles ); - - SetAbsVelocity( vReflection * speed * 0.75f ); - - // Start to sink faster - SetGravity( 1.0f ); - } - else - { - SetThink( &CCrossbowBolt::SUB_Remove ); - SetNextThink( gpGlobals->curtime + 2.0f ); - - //FIXME: We actually want to stick (with hierarchy) to what we've hit - SetMoveType( MOVETYPE_NONE ); - - Vector vForward; - - AngleVectors( GetAbsAngles(), &vForward ); - VectorNormalize ( vForward ); - - CEffectData data; - - data.m_vOrigin = tr.endpos; - data.m_vNormal = vForward; - data.m_nEntIndex = 0; - - DispatchEffect( "BoltImpact", data ); - - UTIL_ImpactTrace( &tr, DMG_BULLET ); - - AddEffects( EF_NODRAW ); - SetTouch( NULL ); - SetThink( &CCrossbowBolt::SUB_Remove ); - SetNextThink( gpGlobals->curtime + 2.0f ); - - if ( m_pGlowSprite != NULL ) - { - m_pGlowSprite->TurnOn(); - m_pGlowSprite->FadeAndDie( 3.0f ); - } - } - - // Shoot some sparks - if ( UTIL_PointContents( GetAbsOrigin() ) != CONTENTS_WATER) - { - g_pEffects->Sparks( GetAbsOrigin() ); - } - } - else - { - // Put a mark unless we've hit the sky - if ( ( tr.surface.flags & SURF_SKY ) == false ) - { - UTIL_ImpactTrace( &tr, DMG_BULLET ); - } - - UTIL_Remove( this ); - } - } - - if ( g_pGameRules->IsMultiplayer() ) - { -// SetThink( &CCrossbowBolt::ExplodeThink ); -// SetNextThink( gpGlobals->curtime + 0.1f ); - } -} - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void CCrossbowBolt::BubbleThink( void ) -{ - QAngle angNewAngles; - - VectorAngles( GetAbsVelocity(), angNewAngles ); - SetAbsAngles( angNewAngles ); - - SetNextThink( gpGlobals->curtime + 0.1f ); - - if ( GetWaterLevel() == 0 ) - return; - - UTIL_BubbleTrail( GetAbsOrigin() - GetAbsVelocity() * 0.1f, GetAbsOrigin(), 5 ); -} - -#endif - -//----------------------------------------------------------------------------- -// CWeaponCrossbow -//----------------------------------------------------------------------------- - -#ifdef CLIENT_DLL -#define CWeaponCrossbow C_WeaponCrossbow -#endif - -class CWeaponCrossbow : public CBaseHL2MPCombatWeapon -{ - DECLARE_CLASS( CWeaponCrossbow, CBaseHL2MPCombatWeapon ); -public: - - CWeaponCrossbow( void ); - - virtual void Precache( void ); - virtual void PrimaryAttack( void ); - virtual void SecondaryAttack( void ); - virtual bool Deploy( void ); - virtual bool Holster( CBaseCombatWeapon *pSwitchingTo = NULL ); - virtual bool Reload( void ); - virtual void ItemPostFrame( void ); - virtual void ItemBusyFrame( void ); - virtual bool SendWeaponAnim( int iActivity ); - -#ifndef CLIENT_DLL - virtual void Operator_HandleAnimEvent( animevent_t *pEvent, CBaseCombatCharacter *pOperator ); -#endif - - DECLARE_NETWORKCLASS(); - DECLARE_PREDICTABLE(); - -private: - - void SetSkin( int skinNum ); - void CheckZoomToggle( void ); - void FireBolt( void ); - void ToggleZoom( void ); - - // Various states for the crossbow's charger - enum ChargerState_t - { - CHARGER_STATE_START_LOAD, - CHARGER_STATE_START_CHARGE, - CHARGER_STATE_READY, - CHARGER_STATE_DISCHARGE, - CHARGER_STATE_OFF, - }; - - void CreateChargerEffects( void ); - void SetChargerState( ChargerState_t state ); - void DoLoadEffect( void ); - -#ifndef CLIENT_DLL - DECLARE_ACTTABLE(); -#endif - -private: - - // Charger effects - ChargerState_t m_nChargeState; - -#ifndef CLIENT_DLL - CHandle m_hChargerSprite; -#endif - - CNetworkVar( bool, m_bInZoom ); - CNetworkVar( bool, m_bMustReload ); - - CWeaponCrossbow( const CWeaponCrossbow & ); -}; - -IMPLEMENT_NETWORKCLASS_ALIASED( WeaponCrossbow, DT_WeaponCrossbow ) - -BEGIN_NETWORK_TABLE( CWeaponCrossbow, DT_WeaponCrossbow ) -#ifdef CLIENT_DLL - RecvPropBool( RECVINFO( m_bInZoom ) ), - RecvPropBool( RECVINFO( m_bMustReload ) ), -#else - SendPropBool( SENDINFO( m_bInZoom ) ), - SendPropBool( SENDINFO( m_bMustReload ) ), -#endif -END_NETWORK_TABLE() - -#ifdef CLIENT_DLL -BEGIN_PREDICTION_DATA( CWeaponCrossbow ) - DEFINE_PRED_FIELD( m_bInZoom, FIELD_BOOLEAN, FTYPEDESC_INSENDTABLE ), - DEFINE_PRED_FIELD( m_bMustReload, FIELD_BOOLEAN, FTYPEDESC_INSENDTABLE ), -END_PREDICTION_DATA() -#endif - -LINK_ENTITY_TO_CLASS( weapon_crossbow, CWeaponCrossbow ); - -PRECACHE_WEAPON_REGISTER( weapon_crossbow ); - -#ifndef CLIENT_DLL - -acttable_t CWeaponCrossbow::m_acttable[] = -{ - { ACT_HL2MP_IDLE, ACT_HL2MP_IDLE_CROSSBOW, false }, - { ACT_HL2MP_RUN, ACT_HL2MP_RUN_CROSSBOW, false }, - { ACT_HL2MP_IDLE_CROUCH, ACT_HL2MP_IDLE_CROUCH_CROSSBOW, false }, - { ACT_HL2MP_WALK_CROUCH, ACT_HL2MP_WALK_CROUCH_CROSSBOW, false }, - { ACT_HL2MP_GESTURE_RANGE_ATTACK, ACT_HL2MP_GESTURE_RANGE_ATTACK_CROSSBOW, false }, - { ACT_HL2MP_GESTURE_RELOAD, ACT_HL2MP_GESTURE_RELOAD_CROSSBOW, false }, - { ACT_HL2MP_JUMP, ACT_HL2MP_JUMP_CROSSBOW, false }, -}; - -IMPLEMENT_ACTTABLE(CWeaponCrossbow); - -#endif - -//----------------------------------------------------------------------------- -// Purpose: Constructor -//----------------------------------------------------------------------------- -CWeaponCrossbow::CWeaponCrossbow( void ) -{ - m_bReloadsSingly = true; - m_bFiresUnderwater = true; - m_bInZoom = false; - m_bMustReload = false; -} - -#define CROSSBOW_GLOW_SPRITE "sprites/light_glow02_noz.vmt" -#define CROSSBOW_GLOW_SPRITE2 "sprites/blueflare1.vmt" - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void CWeaponCrossbow::Precache( void ) -{ -#ifndef CLIENT_DLL - UTIL_PrecacheOther( "crossbow_bolt" ); -#endif - - PrecacheScriptSound( "Weapon_Crossbow.BoltHitBody" ); - PrecacheScriptSound( "Weapon_Crossbow.BoltHitWorld" ); - PrecacheScriptSound( "Weapon_Crossbow.BoltSkewer" ); - - PrecacheModel( CROSSBOW_GLOW_SPRITE ); - PrecacheModel( CROSSBOW_GLOW_SPRITE2 ); - - BaseClass::Precache(); -} - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void CWeaponCrossbow::PrimaryAttack( void ) -{ - if ( m_bInZoom && g_pGameRules->IsMultiplayer() ) - { -// FireSniperBolt(); - FireBolt(); - } - else - { - FireBolt(); - } - - // Signal a reload - m_bMustReload = true; - - SetWeaponIdleTime( gpGlobals->curtime + SequenceDuration( ACT_VM_PRIMARYATTACK ) ); -} - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void CWeaponCrossbow::SecondaryAttack( void ) -{ - //NOTENOTE: The zooming is handled by the post/busy frames -} - -//----------------------------------------------------------------------------- -// Purpose: -// Output : Returns true on success, false on failure. -//----------------------------------------------------------------------------- -bool CWeaponCrossbow::Reload( void ) -{ - if ( BaseClass::Reload() ) - { - m_bMustReload = false; - return true; - } - - return false; -} - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void CWeaponCrossbow::CheckZoomToggle( void ) -{ - CBasePlayer *pPlayer = ToBasePlayer( GetOwner() ); - - if ( pPlayer->m_afButtonPressed & IN_ATTACK2 ) - { - ToggleZoom(); - } -} - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void CWeaponCrossbow::ItemBusyFrame( void ) -{ - // Allow zoom toggling even when we're reloading - CheckZoomToggle(); -} - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void CWeaponCrossbow::ItemPostFrame( void ) -{ - // Allow zoom toggling - CheckZoomToggle(); - - if ( m_bMustReload && HasWeaponIdleTimeElapsed() ) - { - Reload(); - } - - BaseClass::ItemPostFrame(); -} - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void CWeaponCrossbow::FireBolt( void ) -{ - if ( m_iClip1 <= 0 ) - { - if ( !m_bFireOnEmpty ) - { - Reload(); - } - else - { - WeaponSound( EMPTY ); - m_flNextPrimaryAttack = 0.15; - } - - return; - } - - CBasePlayer *pOwner = ToBasePlayer( GetOwner() ); - - if ( pOwner == NULL ) - return; - -#ifndef CLIENT_DLL - Vector vecAiming = pOwner->GetAutoaimVector( 0 ); - Vector vecSrc = pOwner->Weapon_ShootPosition(); - - QAngle angAiming; - VectorAngles( vecAiming, angAiming ); - - CCrossbowBolt *pBolt = CCrossbowBolt::BoltCreate( vecSrc, angAiming, GetHL2MPWpnData().m_iPlayerDamage, pOwner ); - - if ( pOwner->GetWaterLevel() == 3 ) - { - pBolt->SetAbsVelocity( vecAiming * BOLT_WATER_VELOCITY ); - } - else - { - pBolt->SetAbsVelocity( vecAiming * BOLT_AIR_VELOCITY ); - } - -#endif - - m_iClip1--; - - pOwner->ViewPunch( QAngle( -2, 0, 0 ) ); - - WeaponSound( SINGLE ); - WeaponSound( SPECIAL2 ); - - SendWeaponAnim( ACT_VM_PRIMARYATTACK ); - - if ( !m_iClip1 && pOwner->GetAmmoCount( m_iPrimaryAmmoType ) <= 0 ) - { - // HEV suit - indicate out of ammo condition - pOwner->SetSuitUpdate("!HEV_AMO0", FALSE, 0); - } - - m_flNextPrimaryAttack = m_flNextSecondaryAttack = gpGlobals->curtime + 0.75; - - DoLoadEffect(); - SetChargerState( CHARGER_STATE_DISCHARGE ); -} - -//----------------------------------------------------------------------------- -// Purpose: -// Output : Returns true on success, false on failure. -//----------------------------------------------------------------------------- -bool CWeaponCrossbow::Deploy( void ) -{ - if ( m_iClip1 <= 0 ) - { - return DefaultDeploy( (char*)GetViewModel(), (char*)GetWorldModel(), ACT_CROSSBOW_DRAW_UNLOADED, (char*)GetAnimPrefix() ); - } - - SetSkin( BOLT_SKIN_GLOW ); - - return BaseClass::Deploy(); -} - -//----------------------------------------------------------------------------- -// Purpose: -// Input : *pSwitchingTo - -// Output : Returns true on success, false on failure. -//----------------------------------------------------------------------------- -bool CWeaponCrossbow::Holster( CBaseCombatWeapon *pSwitchingTo ) -{ - if ( m_bInZoom ) - { - ToggleZoom(); - } - - SetChargerState( CHARGER_STATE_OFF ); - - return BaseClass::Holster( pSwitchingTo ); -} - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void CWeaponCrossbow::ToggleZoom( void ) -{ - CBasePlayer *pPlayer = ToBasePlayer( GetOwner() ); - - if ( pPlayer == NULL ) - return; - -#ifndef CLIENT_DLL - - if ( m_bInZoom ) - { - if ( pPlayer->SetFOV( this, 0, 0.2f ) ) - { - m_bInZoom = false; - } - } - else - { - if ( pPlayer->SetFOV( this, 20, 0.1f ) ) - { - m_bInZoom = true; - } - } -#endif -} - -#define BOLT_TIP_ATTACHMENT 2 - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void CWeaponCrossbow::CreateChargerEffects( void ) -{ -#ifndef CLIENT_DLL - CBasePlayer *pOwner = ToBasePlayer( GetOwner() ); - - if ( m_hChargerSprite != NULL ) - return; - - m_hChargerSprite = CSprite::SpriteCreate( CROSSBOW_GLOW_SPRITE, GetAbsOrigin(), false ); - - if ( m_hChargerSprite ) - { - m_hChargerSprite->SetAttachment( pOwner->GetViewModel(), BOLT_TIP_ATTACHMENT ); - m_hChargerSprite->SetTransparency( kRenderTransAdd, 255, 128, 0, 255, kRenderFxNoDissipation ); - m_hChargerSprite->SetBrightness( 0 ); - m_hChargerSprite->SetScale( 0.1f ); - m_hChargerSprite->TurnOff(); - } -#endif -} - -//----------------------------------------------------------------------------- -// Purpose: -// Input : skinNum - -//----------------------------------------------------------------------------- -void CWeaponCrossbow::SetSkin( int skinNum ) -{ - CBasePlayer *pOwner = ToBasePlayer( GetOwner() ); - - if ( pOwner == NULL ) - return; - - CBaseViewModel *pViewModel = pOwner->GetViewModel(); - - if ( pViewModel == NULL ) - return; - - pViewModel->m_nSkin = skinNum; -} - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void CWeaponCrossbow::DoLoadEffect( void ) -{ - SetSkin( BOLT_SKIN_GLOW ); - - CBasePlayer *pOwner = ToBasePlayer( GetOwner() ); - - if ( pOwner == NULL ) - return; - - CBaseViewModel *pViewModel = pOwner->GetViewModel(); - - if ( pViewModel == NULL ) - return; - - CEffectData data; - -#ifdef CLIENT_DLL - data.m_hEntity = pViewModel->GetRefEHandle(); -#else - data.m_nEntIndex = pViewModel->entindex(); -#endif - data.m_nAttachmentIndex = 1; - - DispatchEffect( "CrossbowLoad", data ); - -#ifndef CLIENT_DLL - - CSprite *pBlast = CSprite::SpriteCreate( CROSSBOW_GLOW_SPRITE2, GetAbsOrigin(), false ); - - if ( pBlast ) - { - pBlast->SetAttachment( pOwner->GetViewModel(), 1 ); - pBlast->SetTransparency( kRenderTransAdd, 255, 255, 255, 255, kRenderFxNone ); - pBlast->SetBrightness( 128 ); - pBlast->SetScale( 0.2f ); - pBlast->FadeOutFromSpawn(); - } -#endif - -} - -//----------------------------------------------------------------------------- -// Purpose: -// Input : state - -//----------------------------------------------------------------------------- -void CWeaponCrossbow::SetChargerState( ChargerState_t state ) -{ - // Make sure we're setup - CreateChargerEffects(); - - // Don't do this twice - if ( state == m_nChargeState ) - return; - - m_nChargeState = state; - - switch( m_nChargeState ) - { - case CHARGER_STATE_START_LOAD: - - WeaponSound( SPECIAL1 ); - - // Shoot some sparks and draw a beam between the two outer points - DoLoadEffect(); - - break; -#ifndef CLIENT_DLL - case CHARGER_STATE_START_CHARGE: - { - if ( m_hChargerSprite == NULL ) - break; - - m_hChargerSprite->SetBrightness( 32, 0.5f ); - m_hChargerSprite->SetScale( 0.025f, 0.5f ); - m_hChargerSprite->TurnOn(); - } - - break; - - case CHARGER_STATE_READY: - { - // Get fully charged - if ( m_hChargerSprite == NULL ) - break; - - m_hChargerSprite->SetBrightness( 80, 1.0f ); - m_hChargerSprite->SetScale( 0.1f, 0.5f ); - m_hChargerSprite->TurnOn(); - } - - break; - - case CHARGER_STATE_DISCHARGE: - { - SetSkin( BOLT_SKIN_NORMAL ); - - if ( m_hChargerSprite == NULL ) - break; - - m_hChargerSprite->SetBrightness( 0 ); - m_hChargerSprite->TurnOff(); - } - - break; -#endif - case CHARGER_STATE_OFF: - { - SetSkin( BOLT_SKIN_NORMAL ); - -#ifndef CLIENT_DLL - if ( m_hChargerSprite == NULL ) - break; - - m_hChargerSprite->SetBrightness( 0 ); - m_hChargerSprite->TurnOff(); -#endif - } - break; - - default: - break; - } -} - -#ifndef CLIENT_DLL -//----------------------------------------------------------------------------- -// Purpose: -// Input : *pEvent - -// *pOperator - -//----------------------------------------------------------------------------- -void CWeaponCrossbow::Operator_HandleAnimEvent( animevent_t *pEvent, CBaseCombatCharacter *pOperator ) -{ - switch( pEvent->event ) - { - case EVENT_WEAPON_THROW: - SetChargerState( CHARGER_STATE_START_LOAD ); - break; - - case EVENT_WEAPON_THROW2: - SetChargerState( CHARGER_STATE_START_CHARGE ); - break; - - case EVENT_WEAPON_THROW3: - SetChargerState( CHARGER_STATE_READY ); - break; - - default: - BaseClass::Operator_HandleAnimEvent( pEvent, pOperator ); - break; - } -} - -#endif - -//----------------------------------------------------------------------------- -// Purpose: Set the desired activity for the weapon and its viewmodel counterpart -// Input : iActivity - activity to play -//----------------------------------------------------------------------------- -bool CWeaponCrossbow::SendWeaponAnim( int iActivity ) -{ - int newActivity = iActivity; - - // The last shot needs a non-loaded activity - if ( ( newActivity == ACT_VM_IDLE ) && ( m_iClip1 <= 0 ) ) - { - newActivity = ACT_VM_FIDGET; - } - - //For now, just set the ideal activity and be done with it - return BaseClass::SendWeaponAnim( newActivity ); -} diff --git a/sp/src/game/shared/hl2mp/weapon_crowbar.cpp b/sp/src/game/shared/hl2mp/weapon_crowbar.cpp deleted file mode 100644 index 55a03d1d..00000000 --- a/sp/src/game/shared/hl2mp/weapon_crowbar.cpp +++ /dev/null @@ -1,228 +0,0 @@ -//========= Copyright Valve Corporation, All rights reserved. ============// -// -// Purpose: Crowbar - an old favorite -// -// $NoKeywords: $ -//=============================================================================// - -#include "cbase.h" -#include "hl2mp/weapon_crowbar.h" -#include "weapon_hl2mpbasehlmpcombatweapon.h" -#include "gamerules.h" -#include "ammodef.h" -#include "mathlib/mathlib.h" -#include "in_buttons.h" -#include "vstdlib/random.h" -#include "npcevent.h" - -#if defined( CLIENT_DLL ) - #include "c_hl2mp_player.h" -#else - #include "hl2mp_player.h" - #include "ai_basenpc.h" -#endif - - -// memdbgon must be the last include file in a .cpp file!!! -#include "tier0/memdbgon.h" - -#define CROWBAR_RANGE 75.0f -#define CROWBAR_REFIRE 0.4f - - -//----------------------------------------------------------------------------- -// CWeaponCrowbar -//----------------------------------------------------------------------------- - -IMPLEMENT_NETWORKCLASS_ALIASED( WeaponCrowbar, DT_WeaponCrowbar ) - -BEGIN_NETWORK_TABLE( CWeaponCrowbar, DT_WeaponCrowbar ) -END_NETWORK_TABLE() - -BEGIN_PREDICTION_DATA( CWeaponCrowbar ) -END_PREDICTION_DATA() - -LINK_ENTITY_TO_CLASS( weapon_crowbar, CWeaponCrowbar ); -PRECACHE_WEAPON_REGISTER( weapon_crowbar ); - -#ifndef CLIENT_DLL - -acttable_t CWeaponCrowbar::m_acttable[] = -{ - { ACT_RANGE_ATTACK1, ACT_RANGE_ATTACK_SLAM, true }, - { ACT_HL2MP_IDLE, ACT_HL2MP_IDLE_MELEE, false }, - { ACT_HL2MP_RUN, ACT_HL2MP_RUN_MELEE, false }, - { ACT_HL2MP_IDLE_CROUCH, ACT_HL2MP_IDLE_CROUCH_MELEE, false }, - { ACT_HL2MP_WALK_CROUCH, ACT_HL2MP_WALK_CROUCH_MELEE, false }, - { ACT_HL2MP_GESTURE_RANGE_ATTACK, ACT_HL2MP_GESTURE_RANGE_ATTACK_MELEE, false }, - { ACT_HL2MP_GESTURE_RELOAD, ACT_HL2MP_GESTURE_RELOAD_MELEE, false }, - { ACT_HL2MP_JUMP, ACT_HL2MP_JUMP_MELEE, false }, -}; - -IMPLEMENT_ACTTABLE(CWeaponCrowbar); - -#endif - -//----------------------------------------------------------------------------- -// Constructor -//----------------------------------------------------------------------------- -CWeaponCrowbar::CWeaponCrowbar( void ) -{ -} - -//----------------------------------------------------------------------------- -// Purpose: Get the damage amount for the animation we're doing -// Input : hitActivity - currently played activity -// Output : Damage amount -//----------------------------------------------------------------------------- -float CWeaponCrowbar::GetDamageForActivity( Activity hitActivity ) -{ - return 25.0f; -} - -//----------------------------------------------------------------------------- -// Purpose: Add in a view kick for this weapon -//----------------------------------------------------------------------------- -void CWeaponCrowbar::AddViewKick( void ) -{ - CBasePlayer *pPlayer = ToBasePlayer( GetOwner() ); - - if ( pPlayer == NULL ) - return; - - QAngle punchAng; - - punchAng.x = SharedRandomFloat( "crowbarpax", 1.0f, 2.0f ); - punchAng.y = SharedRandomFloat( "crowbarpay", -2.0f, -1.0f ); - punchAng.z = 0.0f; - - pPlayer->ViewPunch( punchAng ); -} - - -#ifndef CLIENT_DLL -//----------------------------------------------------------------------------- -// Animation event handlers -//----------------------------------------------------------------------------- -void CWeaponCrowbar::HandleAnimEventMeleeHit( animevent_t *pEvent, CBaseCombatCharacter *pOperator ) -{ - // Trace up or down based on where the enemy is... - // But only if we're basically facing that direction - Vector vecDirection; - AngleVectors( GetAbsAngles(), &vecDirection ); - - Vector vecEnd; - VectorMA( pOperator->Weapon_ShootPosition(), 50, vecDirection, vecEnd ); - CBaseEntity *pHurt = pOperator->CheckTraceHullAttack( pOperator->Weapon_ShootPosition(), vecEnd, - Vector(-16,-16,-16), Vector(36,36,36), GetDamageForActivity( GetActivity() ), DMG_CLUB, 0.75 ); - - // did I hit someone? - if ( pHurt ) - { - // play sound - WeaponSound( MELEE_HIT ); - - // Fake a trace impact, so the effects work out like a player's crowbaw - trace_t traceHit; - UTIL_TraceLine( pOperator->Weapon_ShootPosition(), pHurt->GetAbsOrigin(), MASK_SHOT_HULL, pOperator, COLLISION_GROUP_NONE, &traceHit ); - ImpactEffect( traceHit ); - } - else - { - WeaponSound( MELEE_MISS ); - } -} - - -//----------------------------------------------------------------------------- -// Animation event -//----------------------------------------------------------------------------- -void CWeaponCrowbar::Operator_HandleAnimEvent( animevent_t *pEvent, CBaseCombatCharacter *pOperator ) -{ - switch( pEvent->event ) - { - case EVENT_WEAPON_MELEE_HIT: - HandleAnimEventMeleeHit( pEvent, pOperator ); - break; - - default: - BaseClass::Operator_HandleAnimEvent( pEvent, pOperator ); - break; - } -} - -//----------------------------------------------------------------------------- -// Attempt to lead the target (needed because citizens can't hit manhacks with the crowbar!) -//----------------------------------------------------------------------------- -ConVar sk_crowbar_lead_time( "sk_crowbar_lead_time", "0.9" ); - -int CWeaponCrowbar::WeaponMeleeAttack1Condition( float flDot, float flDist ) -{ - // Attempt to lead the target (needed because citizens can't hit manhacks with the crowbar!) - CAI_BaseNPC *pNPC = GetOwner()->MyNPCPointer(); - CBaseEntity *pEnemy = pNPC->GetEnemy(); - if (!pEnemy) - return COND_NONE; - - Vector vecVelocity; - vecVelocity = pEnemy->GetSmoothedVelocity( ); - - // Project where the enemy will be in a little while - float dt = sk_crowbar_lead_time.GetFloat(); - dt += SharedRandomFloat( "crowbarmelee1", -0.3f, 0.2f ); - if ( dt < 0.0f ) - dt = 0.0f; - - Vector vecExtrapolatedPos; - VectorMA( pEnemy->WorldSpaceCenter(), dt, vecVelocity, vecExtrapolatedPos ); - - Vector vecDelta; - VectorSubtract( vecExtrapolatedPos, pNPC->WorldSpaceCenter(), vecDelta ); - - if ( fabs( vecDelta.z ) > 70 ) - { - return COND_TOO_FAR_TO_ATTACK; - } - - Vector vecForward = pNPC->BodyDirection2D( ); - vecDelta.z = 0.0f; - float flExtrapolatedDist = Vector2DNormalize( vecDelta.AsVector2D() ); - if ((flDist > 64) && (flExtrapolatedDist > 64)) - { - return COND_TOO_FAR_TO_ATTACK; - } - - float flExtrapolatedDot = DotProduct2D( vecDelta.AsVector2D(), vecForward.AsVector2D() ); - if ((flDot < 0.7) && (flExtrapolatedDot < 0.7)) - { - return COND_NOT_FACING_ATTACK; - } - - return COND_CAN_MELEE_ATTACK1; -} - -#endif - - - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void CWeaponCrowbar::Drop( const Vector &vecVelocity ) -{ -#ifndef CLIENT_DLL - UTIL_Remove( this ); -#endif -} - -float CWeaponCrowbar::GetRange( void ) -{ - return CROWBAR_RANGE; -} - -float CWeaponCrowbar::GetFireRate( void ) -{ - return CROWBAR_REFIRE; -} - - diff --git a/sp/src/game/shared/hl2mp/weapon_crowbar.h b/sp/src/game/shared/hl2mp/weapon_crowbar.h deleted file mode 100644 index 2cd10fb9..00000000 --- a/sp/src/game/shared/hl2mp/weapon_crowbar.h +++ /dev/null @@ -1,70 +0,0 @@ -//========= Copyright Valve Corporation, All rights reserved. ============// -// -// Purpose: -// -// $Workfile: $ -// $Date: $ -// -//----------------------------------------------------------------------------- -// $Log: $ -// -// $NoKeywords: $ -//=============================================================================// - -#ifndef HL2MP_WEAPON_CROWBAR_H -#define HL2MP_WEAPON_CROWBAR_H -#pragma once - - -#include "weapon_hl2mpbasehlmpcombatweapon.h" -#include "weapon_hl2mpbasebasebludgeon.h" - - -#ifdef CLIENT_DLL -#define CWeaponCrowbar C_WeaponCrowbar -#endif - -//----------------------------------------------------------------------------- -// CWeaponCrowbar -//----------------------------------------------------------------------------- - -class CWeaponCrowbar : public CBaseHL2MPBludgeonWeapon -{ -public: - DECLARE_CLASS( CWeaponCrowbar, CBaseHL2MPBludgeonWeapon ); - - DECLARE_NETWORKCLASS(); - DECLARE_PREDICTABLE(); - -#ifndef CLIENT_DLL - DECLARE_ACTTABLE(); -#endif - - CWeaponCrowbar(); - - float GetRange( void ); - float GetFireRate( void ); - - void AddViewKick( void ); - float GetDamageForActivity( Activity hitActivity ); - void SecondaryAttack( void ) { return; } - - void Drop( const Vector &vecVelocity ); - - - // Animation event -#ifndef CLIENT_DLL - virtual void Operator_HandleAnimEvent( animevent_t *pEvent, CBaseCombatCharacter *pOperator ); - void HandleAnimEventMeleeHit( animevent_t *pEvent, CBaseCombatCharacter *pOperator ); - int WeaponMeleeAttack1Condition( float flDot, float flDist ); -#endif - - CWeaponCrowbar( const CWeaponCrowbar & ); - -private: - -}; - - -#endif // HL2MP_WEAPON_CROWBAR_H - diff --git a/sp/src/game/shared/hl2mp/weapon_frag.cpp b/sp/src/game/shared/hl2mp/weapon_frag.cpp deleted file mode 100644 index 9ddcb813..00000000 --- a/sp/src/game/shared/hl2mp/weapon_frag.cpp +++ /dev/null @@ -1,552 +0,0 @@ -//========= Copyright Valve Corporation, All rights reserved. ============// -// -// Purpose: -// -//=============================================================================// - -#include "cbase.h" -#include "npcevent.h" -#include "in_buttons.h" - -#ifdef CLIENT_DLL - #include "c_hl2mp_player.h" - #include "c_te_effect_dispatch.h" -#else - #include "hl2mp_player.h" - #include "te_effect_dispatch.h" - #include "grenade_frag.h" -#endif - -#include "weapon_ar2.h" -#include "effect_dispatch_data.h" -#include "weapon_hl2mpbasehlmpcombatweapon.h" - -// memdbgon must be the last include file in a .cpp file!!! -#include "tier0/memdbgon.h" - -#define GRENADE_TIMER 2.5f //Seconds - -#define GRENADE_PAUSED_NO 0 -#define GRENADE_PAUSED_PRIMARY 1 -#define GRENADE_PAUSED_SECONDARY 2 - -#define GRENADE_RADIUS 4.0f // inches - -#define GRENADE_DAMAGE_RADIUS 250.0f - -#ifdef CLIENT_DLL -#define CWeaponFrag C_WeaponFrag -#endif - -//----------------------------------------------------------------------------- -// Fragmentation grenades -//----------------------------------------------------------------------------- -class CWeaponFrag: public CBaseHL2MPCombatWeapon -{ - DECLARE_CLASS( CWeaponFrag, CBaseHL2MPCombatWeapon ); -public: - - DECLARE_NETWORKCLASS(); - DECLARE_PREDICTABLE(); - - CWeaponFrag(); - - void Precache( void ); - void PrimaryAttack( void ); - void SecondaryAttack( void ); - void DecrementAmmo( CBaseCombatCharacter *pOwner ); - void ItemPostFrame( void ); - - bool Deploy( void ); - bool Holster( CBaseCombatWeapon *pSwitchingTo = NULL ); - - bool Reload( void ); - -#ifndef CLIENT_DLL - void Operator_HandleAnimEvent( animevent_t *pEvent, CBaseCombatCharacter *pOperator ); -#endif - - void ThrowGrenade( CBasePlayer *pPlayer ); - bool IsPrimed( bool ) { return ( m_AttackPaused != 0 ); } - -private: - - void RollGrenade( CBasePlayer *pPlayer ); - void LobGrenade( CBasePlayer *pPlayer ); - // check a throw from vecSrc. If not valid, move the position back along the line to vecEye - void CheckThrowPosition( CBasePlayer *pPlayer, const Vector &vecEye, Vector &vecSrc ); - - CNetworkVar( bool, m_bRedraw ); //Draw the weapon again after throwing a grenade - - CNetworkVar( int, m_AttackPaused ); - CNetworkVar( bool, m_fDrawbackFinished ); - - CWeaponFrag( const CWeaponFrag & ); - -#ifndef CLIENT_DLL - DECLARE_ACTTABLE(); -#endif -}; - -#ifndef CLIENT_DLL - -acttable_t CWeaponFrag::m_acttable[] = -{ - { ACT_HL2MP_IDLE, ACT_HL2MP_IDLE_GRENADE, false }, - { ACT_HL2MP_RUN, ACT_HL2MP_RUN_GRENADE, false }, - { ACT_HL2MP_IDLE_CROUCH, ACT_HL2MP_IDLE_CROUCH_GRENADE, false }, - { ACT_HL2MP_WALK_CROUCH, ACT_HL2MP_WALK_CROUCH_GRENADE, false }, - { ACT_HL2MP_GESTURE_RANGE_ATTACK, ACT_HL2MP_GESTURE_RANGE_ATTACK_GRENADE, false }, - { ACT_HL2MP_GESTURE_RELOAD, ACT_HL2MP_GESTURE_RELOAD_GRENADE, false }, - { ACT_HL2MP_JUMP, ACT_HL2MP_JUMP_GRENADE, false }, -}; - -IMPLEMENT_ACTTABLE(CWeaponFrag); - -#endif - -IMPLEMENT_NETWORKCLASS_ALIASED( WeaponFrag, DT_WeaponFrag ) - -BEGIN_NETWORK_TABLE( CWeaponFrag, DT_WeaponFrag ) - -#ifdef CLIENT_DLL - RecvPropBool( RECVINFO( m_bRedraw ) ), - RecvPropBool( RECVINFO( m_fDrawbackFinished ) ), - RecvPropInt( RECVINFO( m_AttackPaused ) ), -#else - SendPropBool( SENDINFO( m_bRedraw ) ), - SendPropBool( SENDINFO( m_fDrawbackFinished ) ), - SendPropInt( SENDINFO( m_AttackPaused ) ), -#endif - -END_NETWORK_TABLE() - -#ifdef CLIENT_DLL -BEGIN_PREDICTION_DATA( CWeaponFrag ) - DEFINE_PRED_FIELD( m_bRedraw, FIELD_BOOLEAN, FTYPEDESC_INSENDTABLE ), - DEFINE_PRED_FIELD( m_fDrawbackFinished, FIELD_BOOLEAN, FTYPEDESC_INSENDTABLE ), - DEFINE_PRED_FIELD( m_AttackPaused, FIELD_INTEGER, FTYPEDESC_INSENDTABLE ), -END_PREDICTION_DATA() -#endif - -LINK_ENTITY_TO_CLASS( weapon_frag, CWeaponFrag ); -PRECACHE_WEAPON_REGISTER(weapon_frag); - -CWeaponFrag::CWeaponFrag( void ) : - CBaseHL2MPCombatWeapon() -{ - m_bRedraw = false; -} - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void CWeaponFrag::Precache( void ) -{ - BaseClass::Precache(); - -#ifndef CLIENT_DLL - UTIL_PrecacheOther( "npc_grenade_frag" ); -#endif - - PrecacheScriptSound( "WeaponFrag.Throw" ); - PrecacheScriptSound( "WeaponFrag.Roll" ); -} - -#ifndef CLIENT_DLL -//----------------------------------------------------------------------------- -// Purpose: -// Input : *pEvent - -// *pOperator - -//----------------------------------------------------------------------------- -void CWeaponFrag::Operator_HandleAnimEvent( animevent_t *pEvent, CBaseCombatCharacter *pOperator ) -{ - CBasePlayer *pOwner = ToBasePlayer( GetOwner() ); - bool fThrewGrenade = false; - - switch( pEvent->event ) - { - case EVENT_WEAPON_SEQUENCE_FINISHED: - m_fDrawbackFinished = true; - break; - - case EVENT_WEAPON_THROW: - ThrowGrenade( pOwner ); - DecrementAmmo( pOwner ); - fThrewGrenade = true; - break; - - case EVENT_WEAPON_THROW2: - RollGrenade( pOwner ); - DecrementAmmo( pOwner ); - fThrewGrenade = true; - break; - - case EVENT_WEAPON_THROW3: - LobGrenade( pOwner ); - DecrementAmmo( pOwner ); - fThrewGrenade = true; - break; - - default: - BaseClass::Operator_HandleAnimEvent( pEvent, pOperator ); - break; - } - -#define RETHROW_DELAY 0.5 - if( fThrewGrenade ) - { - m_flNextPrimaryAttack = gpGlobals->curtime + RETHROW_DELAY; - m_flNextSecondaryAttack = gpGlobals->curtime + RETHROW_DELAY; - m_flTimeWeaponIdle = FLT_MAX; //NOTE: This is set once the animation has finished up! - } -} - -#endif - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -bool CWeaponFrag::Deploy( void ) -{ - m_bRedraw = false; - m_fDrawbackFinished = false; - - return BaseClass::Deploy(); -} - -//----------------------------------------------------------------------------- -// Purpose: -// Output : Returns true on success, false on failure. -//----------------------------------------------------------------------------- -bool CWeaponFrag::Holster( CBaseCombatWeapon *pSwitchingTo ) -{ - m_bRedraw = false; - m_fDrawbackFinished = false; - - return BaseClass::Holster( pSwitchingTo ); -} - -//----------------------------------------------------------------------------- -// Purpose: -// Output : Returns true on success, false on failure. -//----------------------------------------------------------------------------- -bool CWeaponFrag::Reload( void ) -{ - if ( !HasPrimaryAmmo() ) - return false; - - if ( ( m_bRedraw ) && ( m_flNextPrimaryAttack <= gpGlobals->curtime ) && ( m_flNextSecondaryAttack <= gpGlobals->curtime ) ) - { - //Redraw the weapon - SendWeaponAnim( ACT_VM_DRAW ); - - //Update our times - m_flNextPrimaryAttack = gpGlobals->curtime + SequenceDuration(); - m_flNextSecondaryAttack = gpGlobals->curtime + SequenceDuration(); - m_flTimeWeaponIdle = gpGlobals->curtime + SequenceDuration(); - - //Mark this as done - m_bRedraw = false; - } - - return true; -} - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void CWeaponFrag::SecondaryAttack( void ) -{ - if ( m_bRedraw ) - return; - - if ( !HasPrimaryAmmo() ) - return; - - CBaseCombatCharacter *pOwner = GetOwner(); - - if ( pOwner == NULL ) - return; - - CBasePlayer *pPlayer = ToBasePlayer( pOwner ); - - if ( pPlayer == NULL ) - return; - - // Note that this is a secondary attack and prepare the grenade attack to pause. - m_AttackPaused = GRENADE_PAUSED_SECONDARY; - SendWeaponAnim( ACT_VM_PULLBACK_LOW ); - - // Don't let weapon idle interfere in the middle of a throw! - m_flTimeWeaponIdle = FLT_MAX; - m_flNextSecondaryAttack = FLT_MAX; - - // If I'm now out of ammo, switch away - if ( !HasPrimaryAmmo() ) - { - pPlayer->SwitchToNextBestWeapon( this ); - } -} - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void CWeaponFrag::PrimaryAttack( void ) -{ - if ( m_bRedraw ) - return; - - CBaseCombatCharacter *pOwner = GetOwner(); - - if ( pOwner == NULL ) - { - return; - } - - CBasePlayer *pPlayer = ToBasePlayer( GetOwner() );; - - if ( !pPlayer ) - return; - - // Note that this is a primary attack and prepare the grenade attack to pause. - m_AttackPaused = GRENADE_PAUSED_PRIMARY; - SendWeaponAnim( ACT_VM_PULLBACK_HIGH ); - - // Put both of these off indefinitely. We do not know how long - // the player will hold the grenade. - m_flTimeWeaponIdle = FLT_MAX; - m_flNextPrimaryAttack = FLT_MAX; - - // If I'm now out of ammo, switch away - if ( !HasPrimaryAmmo() ) - { - pPlayer->SwitchToNextBestWeapon( this ); - } -} - -//----------------------------------------------------------------------------- -// Purpose: -// Input : *pOwner - -//----------------------------------------------------------------------------- -void CWeaponFrag::DecrementAmmo( CBaseCombatCharacter *pOwner ) -{ - pOwner->RemoveAmmo( 1, m_iPrimaryAmmoType ); -} - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void CWeaponFrag::ItemPostFrame( void ) -{ - if( m_fDrawbackFinished ) - { - CBasePlayer *pOwner = ToBasePlayer( GetOwner() ); - - if (pOwner) - { - switch( m_AttackPaused ) - { - case GRENADE_PAUSED_PRIMARY: - if( !(pOwner->m_nButtons & IN_ATTACK) ) - { - SendWeaponAnim( ACT_VM_THROW ); - m_fDrawbackFinished = false; - } - break; - - case GRENADE_PAUSED_SECONDARY: - if( !(pOwner->m_nButtons & IN_ATTACK2) ) - { - //See if we're ducking - if ( pOwner->m_nButtons & IN_DUCK ) - { - //Send the weapon animation - SendWeaponAnim( ACT_VM_SECONDARYATTACK ); - } - else - { - //Send the weapon animation - SendWeaponAnim( ACT_VM_HAULBACK ); - } - - m_fDrawbackFinished = false; - } - break; - - default: - break; - } - } - } - - BaseClass::ItemPostFrame(); - - if ( m_bRedraw ) - { - if ( IsViewModelSequenceFinished() ) - { - Reload(); - } - } -} - - // check a throw from vecSrc. If not valid, move the position back along the line to vecEye -void CWeaponFrag::CheckThrowPosition( CBasePlayer *pPlayer, const Vector &vecEye, Vector &vecSrc ) -{ - trace_t tr; - - UTIL_TraceHull( vecEye, vecSrc, -Vector(GRENADE_RADIUS+2,GRENADE_RADIUS+2,GRENADE_RADIUS+2), Vector(GRENADE_RADIUS+2,GRENADE_RADIUS+2,GRENADE_RADIUS+2), - pPlayer->PhysicsSolidMaskForEntity(), pPlayer, pPlayer->GetCollisionGroup(), &tr ); - - if ( tr.DidHit() ) - { - vecSrc = tr.endpos; - } -} - -void DropPrimedFragGrenade( CHL2MP_Player *pPlayer, CBaseCombatWeapon *pGrenade ) -{ - CWeaponFrag *pWeaponFrag = dynamic_cast( pGrenade ); - - if ( pWeaponFrag ) - { - pWeaponFrag->ThrowGrenade( pPlayer ); - pWeaponFrag->DecrementAmmo( pPlayer ); - } -} - -//----------------------------------------------------------------------------- -// Purpose: -// Input : *pPlayer - -//----------------------------------------------------------------------------- -void CWeaponFrag::ThrowGrenade( CBasePlayer *pPlayer ) -{ -#ifndef CLIENT_DLL - Vector vecEye = pPlayer->EyePosition(); - Vector vForward, vRight; - - pPlayer->EyeVectors( &vForward, &vRight, NULL ); - Vector vecSrc = vecEye + vForward * 18.0f + vRight * 8.0f; - CheckThrowPosition( pPlayer, vecEye, vecSrc ); -// vForward[0] += 0.1f; - vForward[2] += 0.1f; - - Vector vecThrow; - pPlayer->GetVelocity( &vecThrow, NULL ); - vecThrow += vForward * 1200; - CBaseGrenade *pGrenade = Fraggrenade_Create( vecSrc, vec3_angle, vecThrow, AngularImpulse(600,random->RandomInt(-1200,1200),0), pPlayer, GRENADE_TIMER, false ); - - if ( pGrenade ) - { - if ( pPlayer && pPlayer->m_lifeState != LIFE_ALIVE ) - { - pPlayer->GetVelocity( &vecThrow, NULL ); - - IPhysicsObject *pPhysicsObject = pGrenade->VPhysicsGetObject(); - if ( pPhysicsObject ) - { - pPhysicsObject->SetVelocity( &vecThrow, NULL ); - } - } - - pGrenade->SetDamage( GetHL2MPWpnData().m_iPlayerDamage ); - pGrenade->SetDamageRadius( GRENADE_DAMAGE_RADIUS ); - } -#endif - - m_bRedraw = true; - - WeaponSound( SINGLE ); - - // player "shoot" animation - pPlayer->SetAnimation( PLAYER_ATTACK1 ); -} - -//----------------------------------------------------------------------------- -// Purpose: -// Input : *pPlayer - -//----------------------------------------------------------------------------- -void CWeaponFrag::LobGrenade( CBasePlayer *pPlayer ) -{ -#ifndef CLIENT_DLL - Vector vecEye = pPlayer->EyePosition(); - Vector vForward, vRight; - - pPlayer->EyeVectors( &vForward, &vRight, NULL ); - Vector vecSrc = vecEye + vForward * 18.0f + vRight * 8.0f + Vector( 0, 0, -8 ); - CheckThrowPosition( pPlayer, vecEye, vecSrc ); - - Vector vecThrow; - pPlayer->GetVelocity( &vecThrow, NULL ); - vecThrow += vForward * 350 + Vector( 0, 0, 50 ); - CBaseGrenade *pGrenade = Fraggrenade_Create( vecSrc, vec3_angle, vecThrow, AngularImpulse(200,random->RandomInt(-600,600),0), pPlayer, GRENADE_TIMER, false ); - - if ( pGrenade ) - { - pGrenade->SetDamage( GetHL2MPWpnData().m_iPlayerDamage ); - pGrenade->SetDamageRadius( GRENADE_DAMAGE_RADIUS ); - } -#endif - - WeaponSound( WPN_DOUBLE ); - - // player "shoot" animation - pPlayer->SetAnimation( PLAYER_ATTACK1 ); - - m_bRedraw = true; -} - -//----------------------------------------------------------------------------- -// Purpose: -// Input : *pPlayer - -//----------------------------------------------------------------------------- -void CWeaponFrag::RollGrenade( CBasePlayer *pPlayer ) -{ -#ifndef CLIENT_DLL - // BUGBUG: Hardcoded grenade width of 4 - better not change the model :) - Vector vecSrc; - pPlayer->CollisionProp()->NormalizedToWorldSpace( Vector( 0.5f, 0.5f, 0.0f ), &vecSrc ); - vecSrc.z += GRENADE_RADIUS; - - Vector vecFacing = pPlayer->BodyDirection2D( ); - // no up/down direction - vecFacing.z = 0; - VectorNormalize( vecFacing ); - trace_t tr; - UTIL_TraceLine( vecSrc, vecSrc - Vector(0,0,16), MASK_PLAYERSOLID, pPlayer, COLLISION_GROUP_NONE, &tr ); - if ( tr.fraction != 1.0 ) - { - // compute forward vec parallel to floor plane and roll grenade along that - Vector tangent; - CrossProduct( vecFacing, tr.plane.normal, tangent ); - CrossProduct( tr.plane.normal, tangent, vecFacing ); - } - vecSrc += (vecFacing * 18.0); - CheckThrowPosition( pPlayer, pPlayer->WorldSpaceCenter(), vecSrc ); - - Vector vecThrow; - pPlayer->GetVelocity( &vecThrow, NULL ); - vecThrow += vecFacing * 700; - // put it on its side - QAngle orientation(0,pPlayer->GetLocalAngles().y,-90); - // roll it - AngularImpulse rotSpeed(0,0,720); - CBaseGrenade *pGrenade = Fraggrenade_Create( vecSrc, orientation, vecThrow, rotSpeed, pPlayer, GRENADE_TIMER, false ); - - if ( pGrenade ) - { - pGrenade->SetDamage( GetHL2MPWpnData().m_iPlayerDamage ); - pGrenade->SetDamageRadius( GRENADE_DAMAGE_RADIUS ); - } - -#endif - - WeaponSound( SPECIAL1 ); - - // player "shoot" animation - pPlayer->SetAnimation( PLAYER_ATTACK1 ); - - m_bRedraw = true; -} - diff --git a/sp/src/game/shared/hl2mp/weapon_hl2mpbase.cpp b/sp/src/game/shared/hl2mp/weapon_hl2mpbase.cpp deleted file mode 100644 index 15995a5b..00000000 --- a/sp/src/game/shared/hl2mp/weapon_hl2mpbase.cpp +++ /dev/null @@ -1,330 +0,0 @@ -//========= Copyright Valve Corporation, All rights reserved. ============// -// -// Purpose: -// -// $NoKeywords: $ -//=============================================================================// - -#include "cbase.h" -#include "in_buttons.h" -#include "takedamageinfo.h" -#include "ammodef.h" -#include "hl2mp_gamerules.h" - - -#ifdef CLIENT_DLL -extern IVModelInfoClient* modelinfo; -#else -extern IVModelInfo* modelinfo; -#endif - - -#if defined( CLIENT_DLL ) - - #include "vgui/ISurface.h" - #include "vgui_controls/Controls.h" - #include "c_hl2mp_player.h" - #include "hud_crosshair.h" - -#else - - #include "hl2mp_player.h" - #include "vphysics/constraints.h" - -#endif - -#include "weapon_hl2mpbase.h" - - -// ----------------------------------------------------------------------------- // -// Global functions. -// ----------------------------------------------------------------------------- // - -bool IsAmmoType( int iAmmoType, const char *pAmmoName ) -{ - return GetAmmoDef()->Index( pAmmoName ) == iAmmoType; -} - -static const char * s_WeaponAliasInfo[] = -{ - "none", // WEAPON_NONE = 0, - - //Melee - "shotgun", //WEAPON_AMERKNIFE, - - NULL, // end of list marker -}; - - -// ----------------------------------------------------------------------------- // -// CWeaponHL2MPBase tables. -// ----------------------------------------------------------------------------- // - -IMPLEMENT_NETWORKCLASS_ALIASED( WeaponHL2MPBase, DT_WeaponHL2MPBase ) - -BEGIN_NETWORK_TABLE( CWeaponHL2MPBase, DT_WeaponHL2MPBase ) - -#ifdef CLIENT_DLL - -#else - // world weapon models have no aminations - // SendPropExclude( "DT_AnimTimeMustBeFirst", "m_flAnimTime" ), -// SendPropExclude( "DT_BaseAnimating", "m_nSequence" ), -// SendPropExclude( "DT_LocalActiveWeaponData", "m_flTimeWeaponIdle" ), -#endif - -END_NETWORK_TABLE() - -BEGIN_PREDICTION_DATA( CWeaponHL2MPBase ) -END_PREDICTION_DATA() - -LINK_ENTITY_TO_CLASS( weapon_hl2mp_base, CWeaponHL2MPBase ); - - -#ifdef GAME_DLL - - BEGIN_DATADESC( CWeaponHL2MPBase ) - - END_DATADESC() - -#endif - -// ----------------------------------------------------------------------------- // -// CWeaponHL2MPBase implementation. -// ----------------------------------------------------------------------------- // -CWeaponHL2MPBase::CWeaponHL2MPBase() -{ - SetPredictionEligible( true ); - AddSolidFlags( FSOLID_TRIGGER ); // Nothing collides with these but it gets touches. - - m_flNextResetCheckTime = 0.0f; -} - - -bool CWeaponHL2MPBase::IsPredicted() const -{ - return true; -} - -void CWeaponHL2MPBase::WeaponSound( WeaponSound_t sound_type, float soundtime /* = 0.0f */ ) -{ -#ifdef CLIENT_DLL - - // If we have some sounds from the weapon classname.txt file, play a random one of them - const char *shootsound = GetWpnData().aShootSounds[ sound_type ]; - if ( !shootsound || !shootsound[0] ) - return; - - CBroadcastRecipientFilter filter; // this is client side only - if ( !te->CanPredict() ) - return; - - CBaseEntity::EmitSound( filter, GetPlayerOwner()->entindex(), shootsound, &GetPlayerOwner()->GetAbsOrigin() ); -#else - BaseClass::WeaponSound( sound_type, soundtime ); -#endif -} - - -CBasePlayer* CWeaponHL2MPBase::GetPlayerOwner() const -{ - return dynamic_cast< CBasePlayer* >( GetOwner() ); -} - -CHL2MP_Player* CWeaponHL2MPBase::GetHL2MPPlayerOwner() const -{ - return dynamic_cast< CHL2MP_Player* >( GetOwner() ); -} - -#ifdef CLIENT_DLL - -void CWeaponHL2MPBase::OnDataChanged( DataUpdateType_t type ) -{ - BaseClass::OnDataChanged( type ); - - if ( GetPredictable() && !ShouldPredict() ) - ShutdownPredictable(); -} - - -bool CWeaponHL2MPBase::ShouldPredict() -{ - if ( GetOwner() && GetOwner() == C_BasePlayer::GetLocalPlayer() ) - return true; - - return BaseClass::ShouldPredict(); -} - - -#else - -void CWeaponHL2MPBase::Spawn() -{ - BaseClass::Spawn(); - - // Set this here to allow players to shoot dropped weapons - SetCollisionGroup( COLLISION_GROUP_WEAPON ); -} - -void CWeaponHL2MPBase::Materialize( void ) -{ - if ( IsEffectActive( EF_NODRAW ) ) - { - // changing from invisible state to visible. - EmitSound( "AlyxEmp.Charge" ); - - RemoveEffects( EF_NODRAW ); - DoMuzzleFlash(); - } - - if ( HasSpawnFlags( SF_NORESPAWN ) == false ) - { - VPhysicsInitNormal( SOLID_BBOX, GetSolidFlags() | FSOLID_TRIGGER, false ); - SetMoveType( MOVETYPE_VPHYSICS ); - - HL2MPRules()->AddLevelDesignerPlacedObject( this ); - } - - if ( HasSpawnFlags( SF_NORESPAWN ) == false ) - { - if ( GetOriginalSpawnOrigin() == vec3_origin ) - { - m_vOriginalSpawnOrigin = GetAbsOrigin(); - m_vOriginalSpawnAngles = GetAbsAngles(); - } - } - - SetPickupTouch(); - - SetThink (NULL); -} - -int CWeaponHL2MPBase::ObjectCaps() -{ - return BaseClass::ObjectCaps() & ~FCAP_IMPULSE_USE; -} - -#endif - -void CWeaponHL2MPBase::FallInit( void ) -{ -#ifndef CLIENT_DLL - SetModel( GetWorldModel() ); - VPhysicsDestroyObject(); - - if ( HasSpawnFlags( SF_NORESPAWN ) == false ) - { - SetMoveType( MOVETYPE_NONE ); - SetSolid( SOLID_BBOX ); - AddSolidFlags( FSOLID_TRIGGER ); - - UTIL_DropToFloor( this, MASK_SOLID ); - } - else - { - if ( !VPhysicsInitNormal( SOLID_BBOX, GetSolidFlags() | FSOLID_TRIGGER, false ) ) - { - SetMoveType( MOVETYPE_NONE ); - SetSolid( SOLID_BBOX ); - AddSolidFlags( FSOLID_TRIGGER ); - } - else - { - #if !defined( CLIENT_DLL ) - // Constrained start? - if ( HasSpawnFlags( SF_WEAPON_START_CONSTRAINED ) ) - { - //Constrain the weapon in place - IPhysicsObject *pReferenceObject, *pAttachedObject; - - pReferenceObject = g_PhysWorldObject; - pAttachedObject = VPhysicsGetObject(); - - if ( pReferenceObject && pAttachedObject ) - { - constraint_fixedparams_t fixed; - fixed.Defaults(); - fixed.InitWithCurrentObjectState( pReferenceObject, pAttachedObject ); - - fixed.constraint.forceLimit = lbs2kg( 10000 ); - fixed.constraint.torqueLimit = lbs2kg( 10000 ); - - IPhysicsConstraint *pConstraint = GetConstraint(); - - pConstraint = physenv->CreateFixedConstraint( pReferenceObject, pAttachedObject, NULL, fixed ); - - pConstraint->SetGameData( (void *) this ); - } - } - #endif //CLIENT_DLL - } - } - - SetPickupTouch(); - - SetThink( &CBaseCombatWeapon::FallThink ); - - SetNextThink( gpGlobals->curtime + 0.1f ); - -#endif -} - -const CHL2MPSWeaponInfo &CWeaponHL2MPBase::GetHL2MPWpnData() const -{ - const FileWeaponInfo_t *pWeaponInfo = &GetWpnData(); - const CHL2MPSWeaponInfo *pHL2MPInfo; - - #ifdef _DEBUG - pHL2MPInfo = dynamic_cast< const CHL2MPSWeaponInfo* >( pWeaponInfo ); - Assert( pHL2MPInfo ); - #else - pHL2MPInfo = static_cast< const CHL2MPSWeaponInfo* >( pWeaponInfo ); - #endif - - return *pHL2MPInfo; -} -void CWeaponHL2MPBase::FireBullets( const FireBulletsInfo_t &info ) -{ - FireBulletsInfo_t modinfo = info; - - modinfo.m_iPlayerDamage = GetHL2MPWpnData().m_iPlayerDamage; - - BaseClass::FireBullets( modinfo ); -} - - -#if defined( CLIENT_DLL ) - -#include "c_te_effect_dispatch.h" - -#define NUM_MUZZLE_FLASH_TYPES 4 - -bool CWeaponHL2MPBase::OnFireEvent( C_BaseViewModel *pViewModel, const Vector& origin, const QAngle& angles, int event, const char *options ) -{ - return BaseClass::OnFireEvent( pViewModel, origin, angles, event, options ); -} - - -void UTIL_ClipPunchAngleOffset( QAngle &in, const QAngle &punch, const QAngle &clip ) -{ - QAngle final = in + punch; - - //Clip each component - for ( int i = 0; i < 3; i++ ) - { - if ( final[i] > clip[i] ) - { - final[i] = clip[i]; - } - else if ( final[i] < -clip[i] ) - { - final[i] = -clip[i]; - } - - //Return the result - in[i] = final[i] - punch[i]; - } -} - -#endif - diff --git a/sp/src/game/shared/hl2mp/weapon_hl2mpbase.h b/sp/src/game/shared/hl2mp/weapon_hl2mpbase.h deleted file mode 100644 index 0f21044b..00000000 --- a/sp/src/game/shared/hl2mp/weapon_hl2mpbase.h +++ /dev/null @@ -1,93 +0,0 @@ -//========= Copyright Valve Corporation, All rights reserved. ============// -// -// Purpose: -// -//=============================================================================// - -#ifndef WEAPON_HL2MPBASE_H -#define WEAPON_HL2MPBASE_H -#ifdef _WIN32 -#pragma once -#endif - -#include "hl2mp_player_shared.h" -#include "basecombatweapon_shared.h" -#include "hl2mp_weapon_parse.h" - -#if defined( CLIENT_DLL ) - #define CWeaponHL2MPBase C_WeaponHL2MPBase - void UTIL_ClipPunchAngleOffset( QAngle &in, const QAngle &punch, const QAngle &clip ); -#endif - -class CHL2MP_Player; - -// These are the names of the ammo types that go in the CAmmoDefs and that the -// weapon script files reference. - -// Given an ammo type (like from a weapon's GetPrimaryAmmoType()), this compares it -// against the ammo name you specify. -// MIKETODO: this should use indexing instead of searching and strcmp()'ing all the time. -bool IsAmmoType( int iAmmoType, const char *pAmmoName ); - -class CWeaponHL2MPBase : public CBaseCombatWeapon -{ -public: - DECLARE_CLASS( CWeaponHL2MPBase, CBaseCombatWeapon ); - DECLARE_NETWORKCLASS(); - DECLARE_PREDICTABLE(); - - CWeaponHL2MPBase(); - - #ifdef GAME_DLL - DECLARE_DATADESC(); - - void SendReloadSoundEvent( void ); - - void Materialize( void ); - virtual int ObjectCaps( void ); - #endif - - // All predicted weapons need to implement and return true - virtual bool IsPredicted() const; - - CBasePlayer* GetPlayerOwner() const; - CHL2MP_Player* GetHL2MPPlayerOwner() const; - - void WeaponSound( WeaponSound_t sound_type, float soundtime = 0.0f ); - - CHL2MPSWeaponInfo const &GetHL2MPWpnData() const; - - - virtual void FireBullets( const FireBulletsInfo_t &info ); - virtual void FallInit( void ); - -public: - #if defined( CLIENT_DLL ) - - virtual bool ShouldPredict(); - virtual void OnDataChanged( DataUpdateType_t type ); - - virtual bool OnFireEvent( C_BaseViewModel *pViewModel, const Vector& origin, const QAngle& angles, int event, const char *options ); - - #else - - virtual void Spawn(); - - #endif - - float m_flPrevAnimTime; - float m_flNextResetCheckTime; - - Vector GetOriginalSpawnOrigin( void ) { return m_vOriginalSpawnOrigin; } - QAngle GetOriginalSpawnAngles( void ) { return m_vOriginalSpawnAngles; } - -private: - - CWeaponHL2MPBase( const CWeaponHL2MPBase & ); - - Vector m_vOriginalSpawnOrigin; - QAngle m_vOriginalSpawnAngles; -}; - - -#endif // WEAPON_HL2MPBASE_H diff --git a/sp/src/game/shared/hl2mp/weapon_hl2mpbase_machinegun.cpp b/sp/src/game/shared/hl2mp/weapon_hl2mpbase_machinegun.cpp deleted file mode 100644 index b5a0040e..00000000 --- a/sp/src/game/shared/hl2mp/weapon_hl2mpbase_machinegun.cpp +++ /dev/null @@ -1,242 +0,0 @@ -//========= Copyright Valve Corporation, All rights reserved. ============// -// -// Purpose: -// -//=============================================================================// - -#include "cbase.h" - -#if defined( CLIENT_DLL ) - #include "c_hl2mp_player.h" -#else - #include "hl2mp_player.h" -#endif - -#include "weapon_hl2mpbase_machinegun.h" -#include "in_buttons.h" - -// memdbgon must be the last include file in a .cpp file!!! -#include "tier0/memdbgon.h" - -IMPLEMENT_NETWORKCLASS_ALIASED( HL2MPMachineGun, DT_HL2MPMachineGun ) - -BEGIN_NETWORK_TABLE( CHL2MPMachineGun, DT_HL2MPMachineGun ) -END_NETWORK_TABLE() - -BEGIN_PREDICTION_DATA( CHL2MPMachineGun ) -END_PREDICTION_DATA() - -//========================================================= -// >> CHLSelectFireMachineGun -//========================================================= -BEGIN_DATADESC( CHL2MPMachineGun ) - - DEFINE_FIELD( m_nShotsFired, FIELD_INTEGER ), - DEFINE_FIELD( m_flNextSoundTime, FIELD_TIME ), - -END_DATADESC() - - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -CHL2MPMachineGun::CHL2MPMachineGun( void ) -{ -} - -const Vector &CHL2MPMachineGun::GetBulletSpread( void ) -{ - static Vector cone = VECTOR_CONE_3DEGREES; - return cone; -} - -//----------------------------------------------------------------------------- -// Purpose: -// -// -//----------------------------------------------------------------------------- -void CHL2MPMachineGun::PrimaryAttack( void ) -{ - // Only the player fires this way so we can cast - CBasePlayer *pPlayer = ToBasePlayer( GetOwner() ); - if (!pPlayer) - return; - - // Abort here to handle burst and auto fire modes - if ( (UsesClipsForAmmo1() && m_iClip1 == 0) || ( !UsesClipsForAmmo1() && !pPlayer->GetAmmoCount(m_iPrimaryAmmoType) ) ) - return; - - m_nShotsFired++; - - pPlayer->DoMuzzleFlash(); - - // To make the firing framerate independent, we may have to fire more than one bullet here on low-framerate systems, - // especially if the weapon we're firing has a really fast rate of fire. - int iBulletsToFire = 0; - float fireRate = GetFireRate(); - - while ( m_flNextPrimaryAttack <= gpGlobals->curtime ) - { - // MUST call sound before removing a round from the clip of a CHLMachineGun - WeaponSound(SINGLE, m_flNextPrimaryAttack); - m_flNextPrimaryAttack = m_flNextPrimaryAttack + fireRate; - iBulletsToFire++; - } - - // Make sure we don't fire more than the amount in the clip, if this weapon uses clips - if ( UsesClipsForAmmo1() ) - { - if ( iBulletsToFire > m_iClip1 ) - iBulletsToFire = m_iClip1; - m_iClip1 -= iBulletsToFire; - } - - CHL2MP_Player *pHL2MPPlayer = ToHL2MPPlayer( pPlayer ); - - // Fire the bullets - FireBulletsInfo_t info; - info.m_iShots = iBulletsToFire; - info.m_vecSrc = pHL2MPPlayer->Weapon_ShootPosition( ); - info.m_vecDirShooting = pPlayer->GetAutoaimVector( AUTOAIM_5DEGREES ); - info.m_vecSpread = pHL2MPPlayer->GetAttackSpread( this ); - info.m_flDistance = MAX_TRACE_LENGTH; - info.m_iAmmoType = m_iPrimaryAmmoType; - info.m_iTracerFreq = 2; - FireBullets( info ); - - //Factor in the view kick - AddViewKick(); - - if (!m_iClip1 && pPlayer->GetAmmoCount(m_iPrimaryAmmoType) <= 0) - { - // HEV suit - indicate out of ammo condition - pPlayer->SetSuitUpdate("!HEV_AMO0", FALSE, 0); - } - - SendWeaponAnim( GetPrimaryAttackActivity() ); - pPlayer->SetAnimation( PLAYER_ATTACK1 ); -} - -//----------------------------------------------------------------------------- -// Purpose: -// Input : &info - -//----------------------------------------------------------------------------- -void CHL2MPMachineGun::FireBullets( const FireBulletsInfo_t &info ) -{ - if(CBasePlayer *pPlayer = ToBasePlayer ( GetOwner() ) ) - { - pPlayer->FireBullets(info); - } -} - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void CHL2MPMachineGun::DoMachineGunKick( CBasePlayer *pPlayer, float dampEasy, float maxVerticleKickAngle, float fireDurationTime, float slideLimitTime ) -{ - #define KICK_MIN_X 0.2f //Degrees - #define KICK_MIN_Y 0.2f //Degrees - #define KICK_MIN_Z 0.1f //Degrees - - QAngle vecScratch; - int iSeed = CBaseEntity::GetPredictionRandomSeed() & 255; - - //Find how far into our accuracy degradation we are - float duration = ( fireDurationTime > slideLimitTime ) ? slideLimitTime : fireDurationTime; - float kickPerc = duration / slideLimitTime; - - // do this to get a hard discontinuity, clear out anything under 10 degrees punch - pPlayer->ViewPunchReset( 10 ); - - //Apply this to the view angles as well - vecScratch.x = -( KICK_MIN_X + ( maxVerticleKickAngle * kickPerc ) ); - vecScratch.y = -( KICK_MIN_Y + ( maxVerticleKickAngle * kickPerc ) ) / 3; - vecScratch.z = KICK_MIN_Z + ( maxVerticleKickAngle * kickPerc ) / 8; - - RandomSeed( iSeed ); - - //Wibble left and right - if ( RandomInt( -1, 1 ) >= 0 ) - vecScratch.y *= -1; - - iSeed++; - - //Wobble up and down - if ( RandomInt( -1, 1 ) >= 0 ) - vecScratch.z *= -1; - - //Clip this to our desired min/max - UTIL_ClipPunchAngleOffset( vecScratch, pPlayer->m_Local.m_vecPunchAngle, QAngle( 24.0f, 3.0f, 1.0f ) ); - - //Add it to the view punch - // NOTE: 0.5 is just tuned to match the old effect before the punch became simulated - pPlayer->ViewPunch( vecScratch * 0.5 ); -} - -//----------------------------------------------------------------------------- -// Purpose: Reset our shots fired -//----------------------------------------------------------------------------- -bool CHL2MPMachineGun::Deploy( void ) -{ - m_nShotsFired = 0; - - return BaseClass::Deploy(); -} - - - -//----------------------------------------------------------------------------- -// Purpose: Make enough sound events to fill the estimated think interval -// returns: number of shots needed -//----------------------------------------------------------------------------- -int CHL2MPMachineGun::WeaponSoundRealtime( WeaponSound_t shoot_type ) -{ - int numBullets = 0; - - // ran out of time, clamp to current - if (m_flNextSoundTime < gpGlobals->curtime) - { - m_flNextSoundTime = gpGlobals->curtime; - } - - // make enough sound events to fill up the next estimated think interval - float dt = clamp( m_flAnimTime - m_flPrevAnimTime, 0, 0.2 ); - if (m_flNextSoundTime < gpGlobals->curtime + dt) - { - WeaponSound( SINGLE_NPC, m_flNextSoundTime ); - m_flNextSoundTime += GetFireRate(); - numBullets++; - } - if (m_flNextSoundTime < gpGlobals->curtime + dt) - { - WeaponSound( SINGLE_NPC, m_flNextSoundTime ); - m_flNextSoundTime += GetFireRate(); - numBullets++; - } - - return numBullets; -} - - - - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void CHL2MPMachineGun::ItemPostFrame( void ) -{ - CBasePlayer *pOwner = ToBasePlayer( GetOwner() ); - - if ( pOwner == NULL ) - return; - - // Debounce the recoiling counter - if ( ( pOwner->m_nButtons & IN_ATTACK ) == false ) - { - m_nShotsFired = 0; - } - - BaseClass::ItemPostFrame(); -} - - diff --git a/sp/src/game/shared/hl2mp/weapon_hl2mpbase_machinegun.h b/sp/src/game/shared/hl2mp/weapon_hl2mpbase_machinegun.h deleted file mode 100644 index c7f9a56b..00000000 --- a/sp/src/game/shared/hl2mp/weapon_hl2mpbase_machinegun.h +++ /dev/null @@ -1,58 +0,0 @@ -//========= Copyright Valve Corporation, All rights reserved. ============// -// -// Purpose: -// -//=============================================================================// - -#include "weapon_hl2mpbase.h" - -#ifndef BASEHLCOMBATWEAPON_H -#define BASEHLCOMBATWEAPON_H -#ifdef _WIN32 -#pragma once -#endif - -#if defined( CLIENT_DLL ) - #define CHL2MPMachineGun C_HL2MPMachineGun -#endif - -//========================================================= -// Machine gun base class -//========================================================= -class CHL2MPMachineGun : public CWeaponHL2MPBase -{ -public: - DECLARE_CLASS( CHL2MPMachineGun, CWeaponHL2MPBase ); - DECLARE_DATADESC(); - - CHL2MPMachineGun(); - - DECLARE_NETWORKCLASS(); - DECLARE_PREDICTABLE(); - - void PrimaryAttack( void ); - - // Default calls through to m_hOwner, but plasma weapons can override and shoot projectiles here. - virtual void ItemPostFrame( void ); - virtual void FireBullets( const FireBulletsInfo_t &info ); - virtual bool Deploy( void ); - - virtual const Vector &GetBulletSpread( void ); - - int WeaponSoundRealtime( WeaponSound_t shoot_type ); - - // utility function - static void DoMachineGunKick( CBasePlayer *pPlayer, float dampEasy, float maxVerticleKickAngle, float fireDurationTime, float slideLimitTime ); - -private: - - CHL2MPMachineGun( const CHL2MPMachineGun & ); - -protected: - - int m_nShotsFired; // Number of consecutive shots fired - - float m_flNextSoundTime; // real-time clock of when to make next sound -}; - -#endif // BASEHLCOMBATWEAPON_H diff --git a/sp/src/game/shared/hl2mp/weapon_hl2mpbasebasebludgeon.cpp b/sp/src/game/shared/hl2mp/weapon_hl2mpbasebasebludgeon.cpp deleted file mode 100644 index 21373ca8..00000000 --- a/sp/src/game/shared/hl2mp/weapon_hl2mpbasebasebludgeon.cpp +++ /dev/null @@ -1,363 +0,0 @@ -//========= Copyright Valve Corporation, All rights reserved. ============// -// -// Purpose: -// -// $NoKeywords: $ -// -//=============================================================================// - -#include "cbase.h" -#include "weapon_hl2mpbasebasebludgeon.h" -#include "gamerules.h" -#include "ammodef.h" -#include "mathlib/mathlib.h" -#include "in_buttons.h" -#include "animation.h" - -#if defined( CLIENT_DLL ) - #include "c_hl2mp_player.h" -#else - #include "hl2mp_player.h" - #include "ndebugoverlay.h" - #include "te_effect_dispatch.h" - #include "ilagcompensationmanager.h" -#endif - -// memdbgon must be the last include file in a .cpp file!!! -#include "tier0/memdbgon.h" - -IMPLEMENT_NETWORKCLASS_ALIASED( BaseHL2MPBludgeonWeapon, DT_BaseHL2MPBludgeonWeapon ) - -BEGIN_NETWORK_TABLE( CBaseHL2MPBludgeonWeapon, DT_BaseHL2MPBludgeonWeapon ) -END_NETWORK_TABLE() - -BEGIN_PREDICTION_DATA( CBaseHL2MPBludgeonWeapon ) -END_PREDICTION_DATA() - -#define BLUDGEON_HULL_DIM 16 - -static const Vector g_bludgeonMins(-BLUDGEON_HULL_DIM,-BLUDGEON_HULL_DIM,-BLUDGEON_HULL_DIM); -static const Vector g_bludgeonMaxs(BLUDGEON_HULL_DIM,BLUDGEON_HULL_DIM,BLUDGEON_HULL_DIM); - -//----------------------------------------------------------------------------- -// Constructor -//----------------------------------------------------------------------------- -CBaseHL2MPBludgeonWeapon::CBaseHL2MPBludgeonWeapon() -{ - m_bFiresUnderwater = true; -} - -//----------------------------------------------------------------------------- -// Purpose: Spawn the weapon -//----------------------------------------------------------------------------- -void CBaseHL2MPBludgeonWeapon::Spawn( void ) -{ - m_fMinRange1 = 0; - m_fMinRange2 = 0; - m_fMaxRange1 = 64; - m_fMaxRange2 = 64; - //Call base class first - BaseClass::Spawn(); -} - -//----------------------------------------------------------------------------- -// Purpose: Precache the weapon -//----------------------------------------------------------------------------- -void CBaseHL2MPBludgeonWeapon::Precache( void ) -{ - //Call base class first - BaseClass::Precache(); -} - -//------------------------------------------------------------------------------ -// Purpose : Update weapon -//------------------------------------------------------------------------------ -void CBaseHL2MPBludgeonWeapon::ItemPostFrame( void ) -{ - CBasePlayer *pOwner = ToBasePlayer( GetOwner() ); - - if ( pOwner == NULL ) - return; - - if ( (pOwner->m_nButtons & IN_ATTACK) && (m_flNextPrimaryAttack <= gpGlobals->curtime) ) - { - PrimaryAttack(); - } - else if ( (pOwner->m_nButtons & IN_ATTACK2) && (m_flNextSecondaryAttack <= gpGlobals->curtime) ) - { - SecondaryAttack(); - } - else - { - WeaponIdle(); - return; - } -} - -//------------------------------------------------------------------------------ -// Purpose : -// Input : -// Output : -//------------------------------------------------------------------------------ -void CBaseHL2MPBludgeonWeapon::PrimaryAttack() -{ - -#ifndef CLIENT_DLL - CHL2MP_Player *pPlayer = ToHL2MPPlayer( GetPlayerOwner() ); - // Move other players back to history positions based on local player's lag - lagcompensation->StartLagCompensation( pPlayer, pPlayer->GetCurrentCommand() ); -#endif - Swing( false ); -#ifndef CLIENT_DLL - // Move other players back to history positions based on local player's lag - lagcompensation->FinishLagCompensation( pPlayer ); -#endif - -} - -//------------------------------------------------------------------------------ -// Purpose : -// Input : -// Output : -//------------------------------------------------------------------------------ -void CBaseHL2MPBludgeonWeapon::SecondaryAttack() -{ - Swing( true ); -} - - -//------------------------------------------------------------------------------ -// Purpose: Implement impact function -//------------------------------------------------------------------------------ -void CBaseHL2MPBludgeonWeapon::Hit( trace_t &traceHit, Activity nHitActivity ) -{ - CBasePlayer *pPlayer = ToBasePlayer( GetOwner() ); - - //Do view kick -// AddViewKick(); - - CBaseEntity *pHitEntity = traceHit.m_pEnt; - - //Apply damage to a hit target - if ( pHitEntity != NULL ) - { - Vector hitDirection; - pPlayer->EyeVectors( &hitDirection, NULL, NULL ); - VectorNormalize( hitDirection ); - -#ifndef CLIENT_DLL - CTakeDamageInfo info( GetOwner(), GetOwner(), GetDamageForActivity( nHitActivity ), DMG_CLUB ); - - if( pPlayer && pHitEntity->IsNPC() ) - { - // If bonking an NPC, adjust damage. - info.AdjustPlayerDamageInflictedForSkillLevel(); - } - - CalculateMeleeDamageForce( &info, hitDirection, traceHit.endpos ); - - pHitEntity->DispatchTraceAttack( info, hitDirection, &traceHit ); - ApplyMultiDamage(); - - // Now hit all triggers along the ray that... - TraceAttackToTriggers( info, traceHit.startpos, traceHit.endpos, hitDirection ); -#endif - WeaponSound( MELEE_HIT ); - } - - // Apply an impact effect - ImpactEffect( traceHit ); -} - -Activity CBaseHL2MPBludgeonWeapon::ChooseIntersectionPointAndActivity( trace_t &hitTrace, const Vector &mins, const Vector &maxs, CBasePlayer *pOwner ) -{ - int i, j, k; - float distance; - const float *minmaxs[2] = {mins.Base(), maxs.Base()}; - trace_t tmpTrace; - Vector vecHullEnd = hitTrace.endpos; - Vector vecEnd; - - distance = 1e6f; - Vector vecSrc = hitTrace.startpos; - - vecHullEnd = vecSrc + ((vecHullEnd - vecSrc)*2); - UTIL_TraceLine( vecSrc, vecHullEnd, MASK_SHOT_HULL, pOwner, COLLISION_GROUP_NONE, &tmpTrace ); - if ( tmpTrace.fraction == 1.0 ) - { - for ( i = 0; i < 2; i++ ) - { - for ( j = 0; j < 2; j++ ) - { - for ( k = 0; k < 2; k++ ) - { - vecEnd.x = vecHullEnd.x + minmaxs[i][0]; - vecEnd.y = vecHullEnd.y + minmaxs[j][1]; - vecEnd.z = vecHullEnd.z + minmaxs[k][2]; - - UTIL_TraceLine( vecSrc, vecEnd, MASK_SHOT_HULL, pOwner, COLLISION_GROUP_NONE, &tmpTrace ); - if ( tmpTrace.fraction < 1.0 ) - { - float thisDistance = (tmpTrace.endpos - vecSrc).Length(); - if ( thisDistance < distance ) - { - hitTrace = tmpTrace; - distance = thisDistance; - } - } - } - } - } - } - else - { - hitTrace = tmpTrace; - } - - - return ACT_VM_HITCENTER; -} - -//----------------------------------------------------------------------------- -// Purpose: -// Input : &traceHit - -//----------------------------------------------------------------------------- -bool CBaseHL2MPBludgeonWeapon::ImpactWater( const Vector &start, const Vector &end ) -{ - //FIXME: This doesn't handle the case of trying to splash while being underwater, but that's not going to look good - // right now anyway... - - // We must start outside the water - if ( UTIL_PointContents( start ) & (CONTENTS_WATER|CONTENTS_SLIME)) - return false; - - // We must end inside of water - if ( !(UTIL_PointContents( end ) & (CONTENTS_WATER|CONTENTS_SLIME))) - return false; - - trace_t waterTrace; - - UTIL_TraceLine( start, end, (CONTENTS_WATER|CONTENTS_SLIME), GetOwner(), COLLISION_GROUP_NONE, &waterTrace ); - - if ( waterTrace.fraction < 1.0f ) - { -#ifndef CLIENT_DLL - CEffectData data; - - data.m_fFlags = 0; - data.m_vOrigin = waterTrace.endpos; - data.m_vNormal = waterTrace.plane.normal; - data.m_flScale = 8.0f; - - // See if we hit slime - if ( waterTrace.contents & CONTENTS_SLIME ) - { - data.m_fFlags |= FX_WATER_IN_SLIME; - } - - DispatchEffect( "watersplash", data ); -#endif - } - - return true; -} - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void CBaseHL2MPBludgeonWeapon::ImpactEffect( trace_t &traceHit ) -{ - // See if we hit water (we don't do the other impact effects in this case) - if ( ImpactWater( traceHit.startpos, traceHit.endpos ) ) - return; - - //FIXME: need new decals - UTIL_ImpactTrace( &traceHit, DMG_CLUB ); -} - - -//------------------------------------------------------------------------------ -// 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 ); - - //Setup our next attack times - m_flNextPrimaryAttack = gpGlobals->curtime + GetFireRate(); - m_flNextSecondaryAttack = gpGlobals->curtime + SequenceDuration(); -} diff --git a/sp/src/game/shared/hl2mp/weapon_hl2mpbasebasebludgeon.h b/sp/src/game/shared/hl2mp/weapon_hl2mpbasebasebludgeon.h deleted file mode 100644 index d268b321..00000000 --- a/sp/src/game/shared/hl2mp/weapon_hl2mpbasebasebludgeon.h +++ /dev/null @@ -1,66 +0,0 @@ -//========= Copyright Valve Corporation, All rights reserved. ============// -// -// Purpose: The class from which all bludgeon melee -// weapons are derived. -// -// $Workfile: $ -// $Date: $ -// $NoKeywords: $ -//=============================================================================// - -#include "weapon_hl2mpbasehlmpcombatweapon.h" - -#ifndef BASEBLUDGEONWEAPON_H -#define BASEBLUDGEONWEAPON_H - -#ifdef _WIN32 -#pragma once -#endif - - -#if defined( CLIENT_DLL ) -#define CBaseHL2MPBludgeonWeapon C_BaseHL2MPBludgeonWeapon -#endif - -//========================================================= -// CBaseHLBludgeonWeapon -//========================================================= -class CBaseHL2MPBludgeonWeapon : public CBaseHL2MPCombatWeapon -{ - DECLARE_CLASS( CBaseHL2MPBludgeonWeapon, CBaseHL2MPCombatWeapon ); -public: - CBaseHL2MPBludgeonWeapon(); - - DECLARE_NETWORKCLASS(); - DECLARE_PREDICTABLE(); - - virtual void Spawn( void ); - virtual void Precache( void ); - - //Attack functions - virtual void PrimaryAttack( void ); - virtual void SecondaryAttack( void ); - - virtual void ItemPostFrame( void ); - - //Functions to select animation sequences - virtual Activity GetPrimaryAttackActivity( void ) { return ACT_VM_HITCENTER; } - virtual Activity GetSecondaryAttackActivity( void ) { return ACT_VM_HITCENTER2; } - - virtual float GetFireRate( void ) { return 0.2f; } - virtual float GetRange( void ) { return 32.0f; } - virtual float GetDamageForActivity( Activity hitActivity ) { return 1.0f; } - - CBaseHL2MPBludgeonWeapon( const CBaseHL2MPBludgeonWeapon & ); - -protected: - virtual void ImpactEffect( trace_t &trace ); - -private: - bool ImpactWater( const Vector &start, const Vector &end ); - void Swing( int bIsSecondary ); - void Hit( trace_t &traceHit, Activity nHitActivity ); - Activity ChooseIntersectionPointAndActivity( trace_t &hitTrace, const Vector &mins, const Vector &maxs, CBasePlayer *pOwner ); -}; - -#endif \ No newline at end of file diff --git a/sp/src/game/shared/hl2mp/weapon_hl2mpbasehlmpcombatweapon.cpp b/sp/src/game/shared/hl2mp/weapon_hl2mpbasehlmpcombatweapon.cpp deleted file mode 100644 index 361a53f1..00000000 --- a/sp/src/game/shared/hl2mp/weapon_hl2mpbasehlmpcombatweapon.cpp +++ /dev/null @@ -1,416 +0,0 @@ -//========= Copyright Valve Corporation, All rights reserved. ============// -// -// Purpose: -// -//=============================================================================// - -#include "cbase.h" -#include "weapon_hl2mpbasehlmpcombatweapon.h" - -#include "hl2mp_player_shared.h" - -// memdbgon must be the last include file in a .cpp file!!! -#include "tier0/memdbgon.h" - -LINK_ENTITY_TO_CLASS( basehl2mpcombatweapon, CBaseHL2MPCombatWeapon ); - -IMPLEMENT_NETWORKCLASS_ALIASED( BaseHL2MPCombatWeapon , DT_BaseHL2MPCombatWeapon ) - -BEGIN_NETWORK_TABLE( CBaseHL2MPCombatWeapon , DT_BaseHL2MPCombatWeapon ) -#if !defined( CLIENT_DLL ) -// SendPropInt( SENDINFO( m_bReflectViewModelAnimations ), 1, SPROP_UNSIGNED ), -#else -// RecvPropInt( RECVINFO( m_bReflectViewModelAnimations ) ), -#endif -END_NETWORK_TABLE() - - -#if !defined( CLIENT_DLL ) - -#include "globalstate.h" - -//--------------------------------------------------------- -// Save/Restore -//--------------------------------------------------------- -BEGIN_DATADESC( CBaseHL2MPCombatWeapon ) - - DEFINE_FIELD( m_bLowered, FIELD_BOOLEAN ), - DEFINE_FIELD( m_flRaiseTime, FIELD_TIME ), - DEFINE_FIELD( m_flHolsterTime, FIELD_TIME ), - -END_DATADESC() - -#endif - -BEGIN_PREDICTION_DATA( CBaseHL2MPCombatWeapon ) -END_PREDICTION_DATA() - -extern ConVar sk_auto_reload_time; - -CBaseHL2MPCombatWeapon::CBaseHL2MPCombatWeapon( void ) -{ - -} - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void CBaseHL2MPCombatWeapon::ItemHolsterFrame( void ) -{ - BaseClass::ItemHolsterFrame(); - - // Must be player held - if ( GetOwner() && GetOwner()->IsPlayer() == false ) - return; - - // We can't be active - if ( GetOwner()->GetActiveWeapon() == this ) - return; - - // If it's been longer than three seconds, reload - if ( ( gpGlobals->curtime - m_flHolsterTime ) > sk_auto_reload_time.GetFloat() ) - { - // Just load the clip with no animations - FinishReload(); - m_flHolsterTime = gpGlobals->curtime; - } -} - -//----------------------------------------------------------------------------- -// Purpose: Drops the weapon into a lowered pose -// Output : Returns true on success, false on failure. -//----------------------------------------------------------------------------- -bool CBaseHL2MPCombatWeapon::Lower( void ) -{ - //Don't bother if we don't have the animation - if ( SelectWeightedSequence( ACT_VM_IDLE_LOWERED ) == ACTIVITY_NOT_AVAILABLE ) - return false; - - m_bLowered = true; - return true; -} - -//----------------------------------------------------------------------------- -// Purpose: Brings the weapon up to the ready position -// Output : Returns true on success, false on failure. -//----------------------------------------------------------------------------- -bool CBaseHL2MPCombatWeapon::Ready( void ) -{ - //Don't bother if we don't have the animation - if ( SelectWeightedSequence( ACT_VM_LOWERED_TO_IDLE ) == ACTIVITY_NOT_AVAILABLE ) - return false; - - m_bLowered = false; - m_flRaiseTime = gpGlobals->curtime + 0.5f; - return true; -} - -//----------------------------------------------------------------------------- -// Purpose: -// Output : Returns true on success, false on failure. -//----------------------------------------------------------------------------- -bool CBaseHL2MPCombatWeapon::Deploy( void ) -{ - // If we should be lowered, deploy in the lowered position - // We have to ask the player if the last time it checked, the weapon was lowered - if ( GetOwner() && GetOwner()->IsPlayer() ) - { - CHL2MP_Player *pPlayer = assert_cast( GetOwner() ); - if ( pPlayer->IsWeaponLowered() ) - { - if ( SelectWeightedSequence( ACT_VM_IDLE_LOWERED ) != ACTIVITY_NOT_AVAILABLE ) - { - if ( DefaultDeploy( (char*)GetViewModel(), (char*)GetWorldModel(), ACT_VM_IDLE_LOWERED, (char*)GetAnimPrefix() ) ) - { - m_bLowered = true; - - // Stomp the next attack time to fix the fact that the lower idles are long - pPlayer->SetNextAttack( gpGlobals->curtime + 1.0 ); - m_flNextPrimaryAttack = gpGlobals->curtime + 1.0; - m_flNextSecondaryAttack = gpGlobals->curtime + 1.0; - return true; - } - } - } - } - - m_bLowered = false; - return BaseClass::Deploy(); -} - -//----------------------------------------------------------------------------- -// Purpose: -// Output : Returns true on success, false on failure. -//----------------------------------------------------------------------------- -bool CBaseHL2MPCombatWeapon::Holster( CBaseCombatWeapon *pSwitchingTo ) -{ - if ( BaseClass::Holster( pSwitchingTo ) ) - { - SetWeaponVisible( false ); - m_flHolsterTime = gpGlobals->curtime; - return true; - } - - return false; -} - -//----------------------------------------------------------------------------- -// Purpose: -// Output : Returns true on success, false on failure. -//----------------------------------------------------------------------------- -bool CBaseHL2MPCombatWeapon::WeaponShouldBeLowered( void ) -{ - // Can't be in the middle of another animation - if ( GetIdealActivity() != ACT_VM_IDLE_LOWERED && GetIdealActivity() != ACT_VM_IDLE && - GetIdealActivity() != ACT_VM_IDLE_TO_LOWERED && GetIdealActivity() != ACT_VM_LOWERED_TO_IDLE ) - return false; - - if ( m_bLowered ) - return true; - -#if !defined( CLIENT_DLL ) - - if ( GlobalEntity_GetState( "friendly_encounter" ) == GLOBAL_ON ) - return true; - -#endif - - return false; -} - -//----------------------------------------------------------------------------- -// Purpose: Allows the weapon to choose proper weapon idle animation -//----------------------------------------------------------------------------- -void CBaseHL2MPCombatWeapon::WeaponIdle( void ) -{ - //See if we should idle high or low - if ( WeaponShouldBeLowered() ) - { - // Move to lowered position if we're not there yet - if ( GetActivity() != ACT_VM_IDLE_LOWERED && GetActivity() != ACT_VM_IDLE_TO_LOWERED - && GetActivity() != ACT_TRANSITION ) - { - SendWeaponAnim( ACT_VM_IDLE_LOWERED ); - } - else if ( HasWeaponIdleTimeElapsed() ) - { - // Keep idling low - SendWeaponAnim( ACT_VM_IDLE_LOWERED ); - } - } - else - { - // See if we need to raise immediately - if ( m_flRaiseTime < gpGlobals->curtime && GetActivity() == ACT_VM_IDLE_LOWERED ) - { - SendWeaponAnim( ACT_VM_IDLE ); - } - else if ( HasWeaponIdleTimeElapsed() ) - { - SendWeaponAnim( ACT_VM_IDLE ); - } - } -} - -#if defined( CLIENT_DLL ) - -#define HL2_BOB_CYCLE_MIN 1.0f -#define HL2_BOB_CYCLE_MAX 0.45f -#define HL2_BOB 0.002f -#define HL2_BOB_UP 0.5f - -extern float g_lateralBob; -extern float g_verticalBob; - -static ConVar cl_bobcycle( "cl_bobcycle","0.8" ); -static ConVar cl_bob( "cl_bob","0.002" ); -static ConVar cl_bobup( "cl_bobup","0.5" ); - -// Register these cvars if needed for easy tweaking -static ConVar v_iyaw_cycle( "v_iyaw_cycle", "2", FCVAR_REPLICATED | FCVAR_CHEAT ); -static ConVar v_iroll_cycle( "v_iroll_cycle", "0.5", FCVAR_REPLICATED | FCVAR_CHEAT ); -static ConVar v_ipitch_cycle( "v_ipitch_cycle", "1", FCVAR_REPLICATED | FCVAR_CHEAT ); -static ConVar v_iyaw_level( "v_iyaw_level", "0.3", FCVAR_REPLICATED | FCVAR_CHEAT ); -static ConVar v_iroll_level( "v_iroll_level", "0.1", FCVAR_REPLICATED | FCVAR_CHEAT ); -static ConVar v_ipitch_level( "v_ipitch_level", "0.3", FCVAR_REPLICATED | FCVAR_CHEAT ); - -//----------------------------------------------------------------------------- -// Purpose: -// Output : float -//----------------------------------------------------------------------------- -float CBaseHL2MPCombatWeapon::CalcViewmodelBob( void ) -{ - static float bobtime; - static float lastbobtime; - float cycle; - - CBasePlayer *player = ToBasePlayer( GetOwner() ); - //Assert( player ); - - //NOTENOTE: For now, let this cycle continue when in the air, because it snaps badly without it - - if ( ( !gpGlobals->frametime ) || ( player == NULL ) ) - { - //NOTENOTE: We don't use this return value in our case (need to restructure the calculation function setup!) - return 0.0f;// just use old value - } - - //Find the speed of the player - float speed = player->GetLocalVelocity().Length2D(); - - //FIXME: This maximum speed value must come from the server. - // MaxSpeed() is not sufficient for dealing with sprinting - jdw - - speed = clamp( speed, -320, 320 ); - - float bob_offset = RemapVal( speed, 0, 320, 0.0f, 1.0f ); - - bobtime += ( gpGlobals->curtime - lastbobtime ) * bob_offset; - lastbobtime = gpGlobals->curtime; - - //Calculate the vertical bob - cycle = bobtime - (int)(bobtime/HL2_BOB_CYCLE_MAX)*HL2_BOB_CYCLE_MAX; - cycle /= HL2_BOB_CYCLE_MAX; - - if ( cycle < HL2_BOB_UP ) - { - cycle = M_PI * cycle / HL2_BOB_UP; - } - else - { - cycle = M_PI + M_PI*(cycle-HL2_BOB_UP)/(1.0 - HL2_BOB_UP); - } - - g_verticalBob = speed*0.005f; - g_verticalBob = g_verticalBob*0.3 + g_verticalBob*0.7*sin(cycle); - - g_verticalBob = clamp( g_verticalBob, -7.0f, 4.0f ); - - //Calculate the lateral bob - cycle = bobtime - (int)(bobtime/HL2_BOB_CYCLE_MAX*2)*HL2_BOB_CYCLE_MAX*2; - cycle /= HL2_BOB_CYCLE_MAX*2; - - if ( cycle < HL2_BOB_UP ) - { - cycle = M_PI * cycle / HL2_BOB_UP; - } - else - { - cycle = M_PI + M_PI*(cycle-HL2_BOB_UP)/(1.0 - HL2_BOB_UP); - } - - g_lateralBob = speed*0.005f; - g_lateralBob = g_lateralBob*0.3 + g_lateralBob*0.7*sin(cycle); - g_lateralBob = clamp( g_lateralBob, -7.0f, 4.0f ); - - //NOTENOTE: We don't use this return value in our case (need to restructure the calculation function setup!) - return 0.0f; -} - -//----------------------------------------------------------------------------- -// Purpose: -// Input : &origin - -// &angles - -// viewmodelindex - -//----------------------------------------------------------------------------- -void CBaseHL2MPCombatWeapon::AddViewmodelBob( CBaseViewModel *viewmodel, Vector &origin, QAngle &angles ) -{ - Vector forward, right; - AngleVectors( angles, &forward, &right, NULL ); - - CalcViewmodelBob(); - - // Apply bob, but scaled down to 40% - VectorMA( origin, g_verticalBob * 0.1f, forward, origin ); - - // Z bob a bit more - origin[2] += g_verticalBob * 0.1f; - - // bob the angles - angles[ ROLL ] += g_verticalBob * 0.5f; - angles[ PITCH ] -= g_verticalBob * 0.4f; - - angles[ YAW ] -= g_lateralBob * 0.3f; - - VectorMA( origin, g_lateralBob * 0.8f, right, origin ); -} - -//----------------------------------------------------------------------------- -Vector CBaseHL2MPCombatWeapon::GetBulletSpread( WeaponProficiency_t proficiency ) -{ - return BaseClass::GetBulletSpread( proficiency ); -} - -//----------------------------------------------------------------------------- -float CBaseHL2MPCombatWeapon::GetSpreadBias( WeaponProficiency_t proficiency ) -{ - return BaseClass::GetSpreadBias( proficiency ); -} -//----------------------------------------------------------------------------- - -const WeaponProficiencyInfo_t *CBaseHL2MPCombatWeapon::GetProficiencyValues() -{ - return NULL; -} - -#else - -// Server stubs -float CBaseHL2MPCombatWeapon::CalcViewmodelBob( void ) -{ - return 0.0f; -} - -//----------------------------------------------------------------------------- -// Purpose: -// Input : &origin - -// &angles - -// viewmodelindex - -//----------------------------------------------------------------------------- -void CBaseHL2MPCombatWeapon::AddViewmodelBob( CBaseViewModel *viewmodel, Vector &origin, QAngle &angles ) -{ -} - - -//----------------------------------------------------------------------------- -Vector CBaseHL2MPCombatWeapon::GetBulletSpread( WeaponProficiency_t proficiency ) -{ - Vector baseSpread = BaseClass::GetBulletSpread( proficiency ); - - const WeaponProficiencyInfo_t *pProficiencyValues = GetProficiencyValues(); - float flModifier = (pProficiencyValues)[ proficiency ].spreadscale; - return ( baseSpread * flModifier ); -} - -//----------------------------------------------------------------------------- -float CBaseHL2MPCombatWeapon::GetSpreadBias( WeaponProficiency_t proficiency ) -{ - const WeaponProficiencyInfo_t *pProficiencyValues = GetProficiencyValues(); - return (pProficiencyValues)[ proficiency ].bias; -} - -//----------------------------------------------------------------------------- -const WeaponProficiencyInfo_t *CBaseHL2MPCombatWeapon::GetProficiencyValues() -{ - return GetDefaultProficiencyValues(); -} - -//----------------------------------------------------------------------------- -const WeaponProficiencyInfo_t *CBaseHL2MPCombatWeapon::GetDefaultProficiencyValues() -{ - // Weapon proficiency table. Keep this in sync with WeaponProficiency_t enum in the header!! - static WeaponProficiencyInfo_t g_BaseWeaponProficiencyTable[] = - { - { 2.50, 1.0 }, - { 2.00, 1.0 }, - { 1.50, 1.0 }, - { 1.25, 1.0 }, - { 1.00, 1.0 }, - }; - - COMPILE_TIME_ASSERT( ARRAYSIZE(g_BaseWeaponProficiencyTable) == WEAPON_PROFICIENCY_PERFECT + 1); - - return g_BaseWeaponProficiencyTable; -} - -#endif \ No newline at end of file diff --git a/sp/src/game/shared/hl2mp/weapon_hl2mpbasehlmpcombatweapon.h b/sp/src/game/shared/hl2mp/weapon_hl2mpbasehlmpcombatweapon.h deleted file mode 100644 index e8469326..00000000 --- a/sp/src/game/shared/hl2mp/weapon_hl2mpbasehlmpcombatweapon.h +++ /dev/null @@ -1,63 +0,0 @@ -//========= Copyright Valve Corporation, All rights reserved. ============// -#ifndef WEAPON_BASEHL2MPCOMBATWEAPON_SHARED_H -#define WEAPON_BASEHL2MPCOMBATWEAPON_SHARED_H -#ifdef _WIN32 -#pragma once -#endif - -#ifdef CLIENT_DLL - #include "c_hl2mp_player.h" -#else - #include "hl2mp_player.h" -#endif - -#include "weapon_hl2mpbase.h" - -#if defined( CLIENT_DLL ) -#define CBaseHL2MPCombatWeapon C_BaseHL2MPCombatWeapon -#endif - -class CBaseHL2MPCombatWeapon : public CWeaponHL2MPBase -{ -#if !defined( CLIENT_DLL ) - DECLARE_DATADESC(); -#endif - - DECLARE_CLASS( CBaseHL2MPCombatWeapon, CWeaponHL2MPBase ); -public: - DECLARE_NETWORKCLASS(); - DECLARE_PREDICTABLE(); - - CBaseHL2MPCombatWeapon(); - - virtual bool WeaponShouldBeLowered( void ); - - virtual bool Ready( void ); - virtual bool Lower( void ); - virtual bool Deploy( void ); - virtual bool Holster( CBaseCombatWeapon *pSwitchingTo ); - virtual void WeaponIdle( void ); - - virtual void AddViewmodelBob( CBaseViewModel *viewmodel, Vector &origin, QAngle &angles ); - virtual float CalcViewmodelBob( void ); - - virtual Vector GetBulletSpread( WeaponProficiency_t proficiency ); - virtual float GetSpreadBias( WeaponProficiency_t proficiency ); - - virtual const WeaponProficiencyInfo_t *GetProficiencyValues(); - static const WeaponProficiencyInfo_t *GetDefaultProficiencyValues(); - - virtual void ItemHolsterFrame( void ); - -protected: - - bool m_bLowered; // Whether the viewmodel is raised or lowered - float m_flRaiseTime; // If lowered, the time we should raise the viewmodel - float m_flHolsterTime; // When the weapon was holstered - -private: - - CBaseHL2MPCombatWeapon( const CBaseHL2MPCombatWeapon & ); -}; - -#endif // WEAPON_BASEHL2MPCOMBATWEAPON_SHARED_H diff --git a/sp/src/game/shared/hl2mp/weapon_physcannon.cpp b/sp/src/game/shared/hl2mp/weapon_physcannon.cpp deleted file mode 100644 index 4972a1ed..00000000 --- a/sp/src/game/shared/hl2mp/weapon_physcannon.cpp +++ /dev/null @@ -1,3685 +0,0 @@ -//========= Copyright Valve Corporation, All rights reserved. ============// -// -// Purpose: Physics cannon -// -//=============================================================================// - -#include "cbase.h" - -#ifdef CLIENT_DLL - #include "c_hl2mp_player.h" - #include "vcollide_parse.h" - #include "engine/ivdebugoverlay.h" - #include "iviewrender_beams.h" - #include "beamdraw.h" - #include "c_te_effect_dispatch.h" - #include "model_types.h" - #include "clienteffectprecachesystem.h" - #include "fx_interpvalue.h" -#else - #include "hl2mp_player.h" - #include "soundent.h" - #include "ndebugoverlay.h" - #include "ai_basenpc.h" - #include "player_pickup.h" - #include "physics_prop_ragdoll.h" - #include "globalstate.h" - #include "props.h" - #include "te_effect_dispatch.h" - #include "util.h" -#endif - -#include "gamerules.h" -#include "soundenvelope.h" -#include "engine/IEngineSound.h" -#include "physics.h" -#include "in_buttons.h" -#include "IEffects.h" -#include "shake.h" -#include "beam_shared.h" -#include "Sprite.h" -#include "weapon_physcannon.h" -#include "physics_saverestore.h" -#include "movevars_shared.h" -#include "weapon_hl2mpbasehlmpcombatweapon.h" -#include "vphysics/friction.h" -#include "debugoverlay_shared.h" - -// memdbgon must be the last include file in a .cpp file!!! -#include "tier0/memdbgon.h" - -#define SPRITE_SCALE 128.0f - -static const char *s_pWaitForUpgradeContext = "WaitForUpgrade"; - -ConVar g_debug_physcannon( "g_debug_physcannon", "0", FCVAR_REPLICATED | FCVAR_CHEAT ); - -ConVar physcannon_minforce( "physcannon_minforce", "700", FCVAR_REPLICATED | FCVAR_CHEAT ); -ConVar physcannon_maxforce( "physcannon_maxforce", "1500", FCVAR_REPLICATED | FCVAR_CHEAT ); -ConVar physcannon_maxmass( "physcannon_maxmass", "250", FCVAR_REPLICATED | FCVAR_CHEAT ); -ConVar physcannon_tracelength( "physcannon_tracelength", "250", FCVAR_REPLICATED | FCVAR_CHEAT ); -ConVar physcannon_chargetime("physcannon_chargetime", "2", FCVAR_REPLICATED | FCVAR_CHEAT ); -ConVar physcannon_pullforce( "physcannon_pullforce", "4000", FCVAR_REPLICATED | FCVAR_CHEAT ); -ConVar physcannon_cone( "physcannon_cone", "0.97", FCVAR_REPLICATED | FCVAR_CHEAT ); -ConVar physcannon_ball_cone( "physcannon_ball_cone", "0.997", FCVAR_REPLICATED | FCVAR_CHEAT ); -ConVar player_throwforce( "player_throwforce", "1000", FCVAR_REPLICATED | FCVAR_CHEAT ); - -#ifndef CLIENT_DLL -extern ConVar hl2_normspeed; -extern ConVar hl2_walkspeed; -#endif - -#define PHYSCANNON_BEAM_SPRITE "sprites/orangelight1.vmt" -#define PHYSCANNON_BEAM_SPRITE_NOZ "sprites/orangelight1_noz.vmt" -#define PHYSCANNON_GLOW_SPRITE "sprites/glow04_noz" -#define PHYSCANNON_ENDCAP_SPRITE "sprites/orangeflare1" -#define PHYSCANNON_CENTER_GLOW "sprites/orangecore1" -#define PHYSCANNON_BLAST_SPRITE "sprites/orangecore2" - -#ifdef CLIENT_DLL - - //Precahce the effects - CLIENTEFFECT_REGISTER_BEGIN( PrecacheEffectPhysCannon ) - CLIENTEFFECT_MATERIAL( "sprites/orangelight1" ) - CLIENTEFFECT_MATERIAL( "sprites/orangelight1_noz" ) - CLIENTEFFECT_MATERIAL( PHYSCANNON_GLOW_SPRITE ) - CLIENTEFFECT_MATERIAL( PHYSCANNON_ENDCAP_SPRITE ) - CLIENTEFFECT_MATERIAL( PHYSCANNON_CENTER_GLOW ) - CLIENTEFFECT_MATERIAL( PHYSCANNON_BLAST_SPRITE ) - CLIENTEFFECT_REGISTER_END() - -#endif // CLIENT_DLL - -#ifndef CLIENT_DLL - -void PhysCannonBeginUpgrade( CBaseAnimating *pAnim ) -{ - -} - -bool PlayerHasMegaPhysCannon( void ) -{ - return false; -} - -bool PhysCannonAccountableForObject( CBaseCombatWeapon *pPhysCannon, CBaseEntity *pObject ) -{ - // BRJ: FIXME! This can't be implemented trivially, so I'm leaving it to Steve or Adrian - Assert( 0 ); - return false; -} - -#endif - -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -// this will hit skip the pass entity, but not anything it owns -// (lets player grab own grenades) -class CTraceFilterNoOwnerTest : public CTraceFilterSimple -{ -public: - DECLARE_CLASS( CTraceFilterNoOwnerTest, CTraceFilterSimple ); - - CTraceFilterNoOwnerTest( const IHandleEntity *passentity, int collisionGroup ) - : CTraceFilterSimple( NULL, collisionGroup ), m_pPassNotOwner(passentity) - { - } - - virtual bool ShouldHitEntity( IHandleEntity *pHandleEntity, int contentsMask ) - { - if ( pHandleEntity != m_pPassNotOwner ) - return BaseClass::ShouldHitEntity( pHandleEntity, contentsMask ); - - return false; - } - -protected: - const IHandleEntity *m_pPassNotOwner; -}; - -static void MatrixOrthogonalize( matrix3x4_t &matrix, int column ) -{ - Vector columns[3]; - int i; - - for ( i = 0; i < 3; i++ ) - { - MatrixGetColumn( matrix, i, columns[i] ); - } - - int index0 = column; - int index1 = (column+1)%3; - int index2 = (column+2)%3; - - columns[index2] = CrossProduct( columns[index0], columns[index1] ); - columns[index1] = CrossProduct( columns[index2], columns[index0] ); - VectorNormalize( columns[index2] ); - VectorNormalize( columns[index1] ); - MatrixSetColumn( columns[index1], index1, matrix ); - MatrixSetColumn( columns[index2], index2, matrix ); -} - -#define SIGN(x) ( (x) < 0 ? -1 : 1 ) - -static QAngle AlignAngles( const QAngle &angles, float cosineAlignAngle ) -{ - matrix3x4_t alignMatrix; - AngleMatrix( angles, alignMatrix ); - - // NOTE: Must align z first - for ( int j = 3; --j >= 0; ) - { - Vector vec; - MatrixGetColumn( alignMatrix, j, vec ); - for ( int i = 0; i < 3; i++ ) - { - if ( fabs(vec[i]) > cosineAlignAngle ) - { - vec[i] = SIGN(vec[i]); - vec[(i+1)%3] = 0; - vec[(i+2)%3] = 0; - MatrixSetColumn( vec, j, alignMatrix ); - MatrixOrthogonalize( alignMatrix, j ); - break; - } - } - } - - QAngle out; - MatrixAngles( alignMatrix, out ); - return out; -} - - -static void TraceCollideAgainstBBox( const CPhysCollide *pCollide, const Vector &start, const Vector &end, const QAngle &angles, const Vector &boxOrigin, const Vector &mins, const Vector &maxs, trace_t *ptr ) -{ - physcollision->TraceBox( boxOrigin, boxOrigin + (start-end), mins, maxs, pCollide, start, angles, ptr ); - - if ( ptr->DidHit() ) - { - ptr->endpos = start * (1-ptr->fraction) + end * ptr->fraction; - ptr->startpos = start; - ptr->plane.dist = -ptr->plane.dist; - ptr->plane.normal *= -1; - } -} - -//----------------------------------------------------------------------------- -// Purpose: Computes a local matrix for the player clamped to valid carry ranges -//----------------------------------------------------------------------------- -// when looking level, hold bottom of object 8 inches below eye level -#define PLAYER_HOLD_LEVEL_EYES -8 - -// when looking down, hold bottom of object 0 inches from feet -#define PLAYER_HOLD_DOWN_FEET 2 - -// when looking up, hold bottom of object 24 inches above eye level -#define PLAYER_HOLD_UP_EYES 24 - -// use a +/-30 degree range for the entire range of motion of pitch -#define PLAYER_LOOK_PITCH_RANGE 30 - -// player can reach down 2ft below his feet (otherwise he'll hold the object above the bottom) -#define PLAYER_REACH_DOWN_DISTANCE 24 - -static void ComputePlayerMatrix( CBasePlayer *pPlayer, matrix3x4_t &out ) -{ - if ( !pPlayer ) - return; - - QAngle angles = pPlayer->EyeAngles(); - Vector origin = pPlayer->EyePosition(); - - // 0-360 / -180-180 - //angles.x = init ? 0 : AngleDistance( angles.x, 0 ); - //angles.x = clamp( angles.x, -PLAYER_LOOK_PITCH_RANGE, PLAYER_LOOK_PITCH_RANGE ); - angles.x = 0; - - float feet = pPlayer->GetAbsOrigin().z + pPlayer->WorldAlignMins().z; - float eyes = origin.z; - float zoffset = 0; - // moving up (negative pitch is up) - if ( angles.x < 0 ) - { - zoffset = RemapVal( angles.x, 0, -PLAYER_LOOK_PITCH_RANGE, PLAYER_HOLD_LEVEL_EYES, PLAYER_HOLD_UP_EYES ); - } - else - { - zoffset = RemapVal( angles.x, 0, PLAYER_LOOK_PITCH_RANGE, PLAYER_HOLD_LEVEL_EYES, PLAYER_HOLD_DOWN_FEET + (feet - eyes) ); - } - origin.z += zoffset; - angles.x = 0; - AngleMatrix( angles, origin, out ); -} - - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- - -// derive from this so we can add save/load data to it -struct game_shadowcontrol_params_t : public hlshadowcontrol_params_t -{ - DECLARE_SIMPLE_DATADESC(); -}; - -BEGIN_SIMPLE_DATADESC( game_shadowcontrol_params_t ) - - DEFINE_FIELD( targetPosition, FIELD_POSITION_VECTOR ), - DEFINE_FIELD( targetRotation, FIELD_VECTOR ), - DEFINE_FIELD( maxAngular, FIELD_FLOAT ), - DEFINE_FIELD( maxDampAngular, FIELD_FLOAT ), - DEFINE_FIELD( maxSpeed, FIELD_FLOAT ), - DEFINE_FIELD( maxDampSpeed, FIELD_FLOAT ), - DEFINE_FIELD( dampFactor, FIELD_FLOAT ), - DEFINE_FIELD( teleportDistance, FIELD_FLOAT ), - -END_DATADESC() - -//----------------------------------------------------------------------------- -class CGrabController : public IMotionEvent -{ -public: - - CGrabController( void ); - ~CGrabController( void ); - void AttachEntity( CBasePlayer *pPlayer, CBaseEntity *pEntity, IPhysicsObject *pPhys, bool bIsMegaPhysCannon, const Vector &vGrabPosition, bool bUseGrabPosition ); - void DetachEntity( bool bClearVelocity ); - void OnRestore(); - - bool UpdateObject( CBasePlayer *pPlayer, float flError ); - - void SetTargetPosition( const Vector &target, const QAngle &targetOrientation ); - float ComputeError(); - float GetLoadWeight( void ) const { return m_flLoadWeight; } - void SetAngleAlignment( float alignAngleCosine ) { m_angleAlignment = alignAngleCosine; } - void SetIgnorePitch( bool bIgnore ) { m_bIgnoreRelativePitch = bIgnore; } - QAngle TransformAnglesToPlayerSpace( const QAngle &anglesIn, CBasePlayer *pPlayer ); - QAngle TransformAnglesFromPlayerSpace( const QAngle &anglesIn, CBasePlayer *pPlayer ); - - CBaseEntity *GetAttached() { return (CBaseEntity *)m_attachedEntity; } - - IMotionEvent::simresult_e Simulate( IPhysicsMotionController *pController, IPhysicsObject *pObject, float deltaTime, Vector &linear, AngularImpulse &angular ); - float GetSavedMass( IPhysicsObject *pObject ); - - QAngle m_attachedAnglesPlayerSpace; - Vector m_attachedPositionObjectSpace; - -private: - // Compute the max speed for an attached object - void ComputeMaxSpeed( CBaseEntity *pEntity, IPhysicsObject *pPhysics ); - - game_shadowcontrol_params_t m_shadow; - float m_timeToArrive; - float m_errorTime; - float m_error; - float m_contactAmount; - float m_angleAlignment; - bool m_bCarriedEntityBlocksLOS; - bool m_bIgnoreRelativePitch; - - float m_flLoadWeight; - float m_savedRotDamping[VPHYSICS_MAX_OBJECT_LIST_COUNT]; - float m_savedMass[VPHYSICS_MAX_OBJECT_LIST_COUNT]; - EHANDLE m_attachedEntity; - QAngle m_vecPreferredCarryAngles; - bool m_bHasPreferredCarryAngles; - - - IPhysicsMotionController *m_controller; - int m_frameCount; - friend class CWeaponPhysCannon; -}; - -const float DEFAULT_MAX_ANGULAR = 360.0f * 10.0f; -const float REDUCED_CARRY_MASS = 1.0f; - -CGrabController::CGrabController( void ) -{ - m_shadow.dampFactor = 1.0; - m_shadow.teleportDistance = 0; - m_errorTime = 0; - m_error = 0; - // make this controller really stiff! - m_shadow.maxSpeed = 1000; - m_shadow.maxAngular = DEFAULT_MAX_ANGULAR; - m_shadow.maxDampSpeed = m_shadow.maxSpeed*2; - m_shadow.maxDampAngular = m_shadow.maxAngular; - m_attachedEntity = NULL; - m_vecPreferredCarryAngles = vec3_angle; - m_bHasPreferredCarryAngles = false; -} - -CGrabController::~CGrabController( void ) -{ - DetachEntity( false ); -} - -void CGrabController::OnRestore() -{ - if ( m_controller ) - { - m_controller->SetEventHandler( this ); - } -} - -void CGrabController::SetTargetPosition( const Vector &target, const QAngle &targetOrientation ) -{ - m_shadow.targetPosition = target; - m_shadow.targetRotation = targetOrientation; - - m_timeToArrive = gpGlobals->frametime; - - CBaseEntity *pAttached = GetAttached(); - if ( pAttached ) - { - IPhysicsObject *pObj = pAttached->VPhysicsGetObject(); - - if ( pObj != NULL ) - { - pObj->Wake(); - } - else - { - DetachEntity( false ); - } - } -} - -//----------------------------------------------------------------------------- -// Purpose: -// Output : float -//----------------------------------------------------------------------------- -float CGrabController::ComputeError() -{ - if ( m_errorTime <= 0 ) - return 0; - - CBaseEntity *pAttached = GetAttached(); - if ( pAttached ) - { - Vector pos; - IPhysicsObject *pObj = pAttached->VPhysicsGetObject(); - - if ( pObj ) - { - pObj->GetShadowPosition( &pos, NULL ); - - float error = (m_shadow.targetPosition - pos).Length(); - if ( m_errorTime > 0 ) - { - if ( m_errorTime > 1 ) - { - m_errorTime = 1; - } - float speed = error / m_errorTime; - if ( speed > m_shadow.maxSpeed ) - { - error *= 0.5; - } - m_error = (1-m_errorTime) * m_error + error * m_errorTime; - } - } - else - { - DevMsg( "Object attached to Physcannon has no physics object\n" ); - DetachEntity( false ); - return 9999; // force detach - } - } - - if ( pAttached->IsEFlagSet( EFL_IS_BEING_LIFTED_BY_BARNACLE ) ) - { - m_error *= 3.0f; - } - - m_errorTime = 0; - - return m_error; -} - - -#define MASS_SPEED_SCALE 60 -#define MAX_MASS 40 - -void CGrabController::ComputeMaxSpeed( CBaseEntity *pEntity, IPhysicsObject *pPhysics ) -{ -#ifndef CLIENT_DLL - m_shadow.maxSpeed = 1000; - m_shadow.maxAngular = DEFAULT_MAX_ANGULAR; - - // Compute total mass... - float flMass = PhysGetEntityMass( pEntity ); - float flMaxMass = physcannon_maxmass.GetFloat(); - if ( flMass <= flMaxMass ) - return; - - float flLerpFactor = clamp( flMass, flMaxMass, 500.0f ); - flLerpFactor = SimpleSplineRemapVal( flLerpFactor, flMaxMass, 500.0f, 0.0f, 1.0f ); - - float invMass = pPhysics->GetInvMass(); - float invInertia = pPhysics->GetInvInertia().Length(); - - float invMaxMass = 1.0f / MAX_MASS; - float ratio = invMaxMass / invMass; - invMass = invMaxMass; - invInertia *= ratio; - - float maxSpeed = invMass * MASS_SPEED_SCALE * 200; - float maxAngular = invInertia * MASS_SPEED_SCALE * 360; - - m_shadow.maxSpeed = Lerp( flLerpFactor, m_shadow.maxSpeed, maxSpeed ); - m_shadow.maxAngular = Lerp( flLerpFactor, m_shadow.maxAngular, maxAngular ); -#endif -} - - -QAngle CGrabController::TransformAnglesToPlayerSpace( const QAngle &anglesIn, CBasePlayer *pPlayer ) -{ - if ( m_bIgnoreRelativePitch ) - { - matrix3x4_t test; - QAngle angleTest = pPlayer->EyeAngles(); - angleTest.x = 0; - AngleMatrix( angleTest, test ); - return TransformAnglesToLocalSpace( anglesIn, test ); - } - return TransformAnglesToLocalSpace( anglesIn, pPlayer->EntityToWorldTransform() ); -} - -QAngle CGrabController::TransformAnglesFromPlayerSpace( const QAngle &anglesIn, CBasePlayer *pPlayer ) -{ - if ( m_bIgnoreRelativePitch ) - { - matrix3x4_t test; - QAngle angleTest = pPlayer->EyeAngles(); - angleTest.x = 0; - AngleMatrix( angleTest, test ); - return TransformAnglesToWorldSpace( anglesIn, test ); - } - return TransformAnglesToWorldSpace( anglesIn, pPlayer->EntityToWorldTransform() ); -} - - -void CGrabController::AttachEntity( CBasePlayer *pPlayer, CBaseEntity *pEntity, IPhysicsObject *pPhys, bool bIsMegaPhysCannon, const Vector &vGrabPosition, bool bUseGrabPosition ) -{ - // play the impact sound of the object hitting the player - // used as feedback to let the player know he picked up the object -#ifndef CLIENT_DLL - PhysicsImpactSound( pPlayer, pPhys, CHAN_STATIC, pPhys->GetMaterialIndex(), pPlayer->VPhysicsGetObject()->GetMaterialIndex(), 1.0, 64 ); -#endif - Vector position; - QAngle angles; - pPhys->GetPosition( &position, &angles ); - // If it has a preferred orientation, use that instead. -#ifndef CLIENT_DLL - Pickup_GetPreferredCarryAngles( pEntity, pPlayer, pPlayer->EntityToWorldTransform(), angles ); -#endif - -// ComputeMaxSpeed( pEntity, pPhys ); - - // Carried entities can never block LOS - m_bCarriedEntityBlocksLOS = pEntity->BlocksLOS(); - pEntity->SetBlocksLOS( false ); - m_controller = physenv->CreateMotionController( this ); - m_controller->AttachObject( pPhys, true ); - // Don't do this, it's causing trouble with constraint solvers. - //m_controller->SetPriority( IPhysicsMotionController::HIGH_PRIORITY ); - - pPhys->Wake(); - PhysSetGameFlags( pPhys, FVPHYSICS_PLAYER_HELD ); - SetTargetPosition( position, angles ); - m_attachedEntity = pEntity; - IPhysicsObject *pList[VPHYSICS_MAX_OBJECT_LIST_COUNT]; - int count = pEntity->VPhysicsGetObjectList( pList, ARRAYSIZE(pList) ); - m_flLoadWeight = 0; - float damping = 10; - float flFactor = count / 7.5f; - if ( flFactor < 1.0f ) - { - flFactor = 1.0f; - } - for ( int i = 0; i < count; i++ ) - { - float mass = pList[i]->GetMass(); - pList[i]->GetDamping( NULL, &m_savedRotDamping[i] ); - m_flLoadWeight += mass; - m_savedMass[i] = mass; - - // reduce the mass to prevent the player from adding crazy amounts of energy to the system - pList[i]->SetMass( REDUCED_CARRY_MASS / flFactor ); - pList[i]->SetDamping( NULL, &damping ); - } - - // Give extra mass to the phys object we're actually picking up - pPhys->SetMass( REDUCED_CARRY_MASS ); - pPhys->EnableDrag( false ); - - m_errorTime = -1.0f; // 1 seconds until error starts accumulating - m_error = 0; - m_contactAmount = 0; - - m_attachedAnglesPlayerSpace = TransformAnglesToPlayerSpace( angles, pPlayer ); - if ( m_angleAlignment != 0 ) - { - m_attachedAnglesPlayerSpace = AlignAngles( m_attachedAnglesPlayerSpace, m_angleAlignment ); - } - - VectorITransform( pEntity->WorldSpaceCenter(), pEntity->EntityToWorldTransform(), m_attachedPositionObjectSpace ); - -#ifndef CLIENT_DLL - // If it's a prop, see if it has desired carry angles - CPhysicsProp *pProp = dynamic_cast(pEntity); - if ( pProp ) - { - m_bHasPreferredCarryAngles = pProp->GetPropDataAngles( "preferred_carryangles", m_vecPreferredCarryAngles ); - } - else - { - m_bHasPreferredCarryAngles = false; - } -#else - - m_bHasPreferredCarryAngles = false; -#endif - -} - -static void ClampPhysicsVelocity( IPhysicsObject *pPhys, float linearLimit, float angularLimit ) -{ - Vector vel; - AngularImpulse angVel; - pPhys->GetVelocity( &vel, &angVel ); - float speed = VectorNormalize(vel) - linearLimit; - float angSpeed = VectorNormalize(angVel) - angularLimit; - speed = speed < 0 ? 0 : -speed; - angSpeed = angSpeed < 0 ? 0 : -angSpeed; - vel *= speed; - angVel *= angSpeed; - pPhys->AddVelocity( &vel, &angVel ); -} - -void CGrabController::DetachEntity( bool bClearVelocity ) -{ - CBaseEntity *pEntity = GetAttached(); - if ( pEntity ) - { - // Restore the LS blocking state - pEntity->SetBlocksLOS( m_bCarriedEntityBlocksLOS ); - IPhysicsObject *pList[VPHYSICS_MAX_OBJECT_LIST_COUNT]; - int count = pEntity->VPhysicsGetObjectList( pList, ARRAYSIZE(pList) ); - - for ( int i = 0; i < count; i++ ) - { - IPhysicsObject *pPhys = pList[i]; - if ( !pPhys ) - continue; - - // on the odd chance that it's gone to sleep while under anti-gravity - pPhys->EnableDrag( true ); - pPhys->Wake(); - pPhys->SetMass( m_savedMass[i] ); - pPhys->SetDamping( NULL, &m_savedRotDamping[i] ); - PhysClearGameFlags( pPhys, FVPHYSICS_PLAYER_HELD ); - if ( bClearVelocity ) - { - PhysForceClearVelocity( pPhys ); - } - else - { -#ifndef CLIENT_DLL - ClampPhysicsVelocity( pPhys, hl2_normspeed.GetFloat() * 1.5f, 2.0f * 360.0f ); -#endif - } - - } - } - - m_attachedEntity = NULL; - if ( physenv ) - { - physenv->DestroyMotionController( m_controller ); - } - m_controller = NULL; -} - -static bool InContactWithHeavyObject( IPhysicsObject *pObject, float heavyMass ) -{ - bool contact = false; - IPhysicsFrictionSnapshot *pSnapshot = pObject->CreateFrictionSnapshot(); - while ( pSnapshot->IsValid() ) - { - IPhysicsObject *pOther = pSnapshot->GetObject( 1 ); - if ( !pOther->IsMoveable() || pOther->GetMass() > heavyMass ) - { - contact = true; - break; - } - pSnapshot->NextFrictionData(); - } - pObject->DestroyFrictionSnapshot( pSnapshot ); - return contact; -} - -IMotionEvent::simresult_e CGrabController::Simulate( IPhysicsMotionController *pController, IPhysicsObject *pObject, float deltaTime, Vector &linear, AngularImpulse &angular ) -{ - game_shadowcontrol_params_t shadowParams = m_shadow; - if ( InContactWithHeavyObject( pObject, GetLoadWeight() ) ) - { - m_contactAmount = Approach( 0.1f, m_contactAmount, deltaTime*2.0f ); - } - else - { - m_contactAmount = Approach( 1.0f, m_contactAmount, deltaTime*2.0f ); - } - shadowParams.maxAngular = m_shadow.maxAngular * m_contactAmount * m_contactAmount * m_contactAmount; -#ifndef CLIENT_DLL - m_timeToArrive = pObject->ComputeShadowControl( shadowParams, m_timeToArrive, deltaTime ); -#else - m_timeToArrive = pObject->ComputeShadowControl( shadowParams, (TICK_INTERVAL*2), deltaTime ); -#endif - - // Slide along the current contact points to fix bouncing problems - Vector velocity; - AngularImpulse angVel; - pObject->GetVelocity( &velocity, &angVel ); - PhysComputeSlideDirection( pObject, velocity, angVel, &velocity, &angVel, GetLoadWeight() ); - pObject->SetVelocityInstantaneous( &velocity, NULL ); - - linear.Init(); - angular.Init(); - m_errorTime += deltaTime; - - return SIM_LOCAL_ACCELERATION; -} - -float CGrabController::GetSavedMass( IPhysicsObject *pObject ) -{ - CBaseEntity *pHeld = m_attachedEntity; - if ( pHeld ) - { - if ( pObject->GetGameData() == (void*)pHeld ) - { - IPhysicsObject *pList[VPHYSICS_MAX_OBJECT_LIST_COUNT]; - int count = pHeld->VPhysicsGetObjectList( pList, ARRAYSIZE(pList) ); - for ( int i = 0; i < count; i++ ) - { - if ( pList[i] == pObject ) - return m_savedMass[i]; - } - } - } - return 0.0f; -} - -//----------------------------------------------------------------------------- -// Player pickup controller -//----------------------------------------------------------------------------- - -class CPlayerPickupController : public CBaseEntity -{ - DECLARE_CLASS( CPlayerPickupController, CBaseEntity ); -public: - void Init( CBasePlayer *pPlayer, CBaseEntity *pObject ); - void Shutdown( bool bThrown = false ); - bool OnControls( CBaseEntity *pControls ) { return true; } - void Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value ); - void OnRestore() - { - m_grabController.OnRestore(); - } - void VPhysicsUpdate( IPhysicsObject *pPhysics ){} - void VPhysicsShadowUpdate( IPhysicsObject *pPhysics ) {} - - bool IsHoldingEntity( CBaseEntity *pEnt ); - CGrabController &GetGrabController() { return m_grabController; } - -private: - CGrabController m_grabController; - CBasePlayer *m_pPlayer; -}; - -LINK_ENTITY_TO_CLASS( player_pickup, CPlayerPickupController ); - -//----------------------------------------------------------------------------- -// Purpose: -// Input : *pPlayer - -// *pObject - -//----------------------------------------------------------------------------- -void CPlayerPickupController::Init( CBasePlayer *pPlayer, CBaseEntity *pObject ) -{ -#ifndef CLIENT_DLL - // Holster player's weapon - if ( pPlayer->GetActiveWeapon() ) - { - if ( !pPlayer->GetActiveWeapon()->Holster() ) - { - Shutdown(); - return; - } - } - - - CHL2MP_Player *pOwner = (CHL2MP_Player *)ToBasePlayer( pPlayer ); - if ( pOwner ) - { - pOwner->EnableSprint( false ); - } - - // If the target is debris, convert it to non-debris - if ( pObject->GetCollisionGroup() == COLLISION_GROUP_DEBRIS ) - { - // Interactive debris converts back to debris when it comes to rest - pObject->SetCollisionGroup( COLLISION_GROUP_INTERACTIVE_DEBRIS ); - } - - // done so I'll go across level transitions with the player - SetParent( pPlayer ); - m_grabController.SetIgnorePitch( true ); - m_grabController.SetAngleAlignment( DOT_30DEGREE ); - m_pPlayer = pPlayer; - IPhysicsObject *pPhysics = pObject->VPhysicsGetObject(); - Pickup_OnPhysGunPickup( pObject, m_pPlayer ); - - m_grabController.AttachEntity( pPlayer, pObject, pPhysics, false, vec3_origin, false ); - - m_pPlayer->m_Local.m_iHideHUD |= HIDEHUD_WEAPONSELECTION; - m_pPlayer->SetUseEntity( this ); -#endif -} - - -//----------------------------------------------------------------------------- -// Purpose: -// Input : bool - -//----------------------------------------------------------------------------- -void CPlayerPickupController::Shutdown( bool bThrown ) -{ -#ifndef CLIENT_DLL - CBaseEntity *pObject = m_grabController.GetAttached(); - - bool bClearVelocity = false; - if ( !bThrown && pObject && pObject->VPhysicsGetObject() && pObject->VPhysicsGetObject()->GetContactPoint(NULL,NULL) ) - { - bClearVelocity = true; - } - - m_grabController.DetachEntity( bClearVelocity ); - - if ( pObject != NULL ) - { - Pickup_OnPhysGunDrop( pObject, m_pPlayer, bThrown ? THROWN_BY_PLAYER : DROPPED_BY_PLAYER ); - } - - if ( m_pPlayer ) - { - CHL2MP_Player *pOwner = (CHL2MP_Player *)ToBasePlayer( m_pPlayer ); - if ( pOwner ) - { - pOwner->EnableSprint( true ); - } - - m_pPlayer->SetUseEntity( NULL ); - if ( m_pPlayer->GetActiveWeapon() ) - { - if ( !m_pPlayer->GetActiveWeapon()->Deploy() ) - { - // We tried to restore the player's weapon, but we couldn't. - // This usually happens when they're holding an empty weapon that doesn't - // autoswitch away when out of ammo. Switch to next best weapon. - m_pPlayer->SwitchToNextBestWeapon( NULL ); - } - } - - m_pPlayer->m_Local.m_iHideHUD &= ~HIDEHUD_WEAPONSELECTION; - } - Remove(); - -#endif - -} - - -void CPlayerPickupController::Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value ) -{ - if ( ToBasePlayer(pActivator) == m_pPlayer ) - { - CBaseEntity *pAttached = m_grabController.GetAttached(); - - // UNDONE: Use vphysics stress to decide to drop objects - // UNDONE: Must fix case of forcing objects into the ground you're standing on (causes stress) before that will work - if ( !pAttached || useType == USE_OFF || (m_pPlayer->m_nButtons & IN_ATTACK2) || m_grabController.ComputeError() > 12 ) - { - Shutdown(); - return; - } - - //Adrian: Oops, our object became motion disabled, let go! - IPhysicsObject *pPhys = pAttached->VPhysicsGetObject(); - if ( pPhys && pPhys->IsMoveable() == false ) - { - Shutdown(); - return; - } - -#if STRESS_TEST - vphysics_objectstress_t stress; - CalculateObjectStress( pPhys, pAttached, &stress ); - if ( stress.exertedStress > 250 ) - { - Shutdown(); - return; - } -#endif - // +ATTACK will throw phys objects - if ( m_pPlayer->m_nButtons & IN_ATTACK ) - { - Shutdown( true ); - Vector vecLaunch; - m_pPlayer->EyeVectors( &vecLaunch ); - // JAY: Scale this with mass because some small objects really go flying - float massFactor = clamp( pPhys->GetMass(), 0.5, 15 ); - massFactor = RemapVal( massFactor, 0.5, 15, 0.5, 4 ); - vecLaunch *= player_throwforce.GetFloat() * massFactor; - - pPhys->ApplyForceCenter( vecLaunch ); - AngularImpulse aVel = RandomAngularImpulse( -10, 10 ) * massFactor; - pPhys->ApplyTorqueCenter( aVel ); - return; - } - - if ( useType == USE_SET ) - { - // update position - m_grabController.UpdateObject( m_pPlayer, 12 ); - } - } -} - -//----------------------------------------------------------------------------- -// Purpose: -// Input : *pEnt - -// Output : Returns true on success, false on failure. -//----------------------------------------------------------------------------- -bool CPlayerPickupController::IsHoldingEntity( CBaseEntity *pEnt ) -{ - return ( m_grabController.GetAttached() == pEnt ); -} - -void PlayerPickupObject( CBasePlayer *pPlayer, CBaseEntity *pObject ) -{ - -#ifndef CLIENT_DLL - - //Don't pick up if we don't have a phys object. - if ( pObject->VPhysicsGetObject() == NULL ) - return; - - CPlayerPickupController *pController = (CPlayerPickupController *)CBaseEntity::Create( "player_pickup", pObject->GetAbsOrigin(), vec3_angle, pPlayer ); - - if ( !pController ) - return; - - pController->Init( pPlayer, pObject ); - -#endif - -} - -//---------------------------------------------------------------------------------------------------------------------------------------------------------- -// CInterpolatedValue class -//---------------------------------------------------------------------------------------------------------------------------------------------------------- - -#ifdef CLIENT_DLL - -//---------------------------------------------------------------------------------------------------------------------------------------------------------- -// CPhysCannonEffect class -//---------------------------------------------------------------------------------------------------------------------------------------------------------- - -class CPhysCannonEffect -{ -public: - CPhysCannonEffect( void ) : m_vecColor( 255, 255, 255 ), m_bVisible( true ), m_nAttachment( -1 ) {}; - - void SetAttachment( int attachment ) { m_nAttachment = attachment; } - int GetAttachment( void ) const { return m_nAttachment; } - - void SetVisible( bool visible = true ) { m_bVisible = visible; } - int IsVisible( void ) const { return m_bVisible; } - - void SetColor( const Vector &color ) { m_vecColor = color; } - const Vector &GetColor( void ) const { return m_vecColor; } - - bool SetMaterial( const char *materialName ) - { - m_hMaterial.Init( materialName, TEXTURE_GROUP_CLIENT_EFFECTS ); - return ( m_hMaterial != NULL ); - } - - CMaterialReference &GetMaterial( void ) { return m_hMaterial; } - - CInterpolatedValue &GetAlpha( void ) { return m_Alpha; } - CInterpolatedValue &GetScale( void ) { return m_Scale; } - -private: - CInterpolatedValue m_Alpha; - CInterpolatedValue m_Scale; - - Vector m_vecColor; - bool m_bVisible; - int m_nAttachment; - CMaterialReference m_hMaterial; -}; - -//---------------------------------------------------------------------------------------------------------------------------------------------------------- -// CPhysCannonEffectBeam class -//---------------------------------------------------------------------------------------------------------------------------------------------------------- - -class CPhysCannonEffectBeam -{ -public: - CPhysCannonEffectBeam( void ) : m_pBeam( NULL ) {}; - - ~CPhysCannonEffectBeam( void ) - { - Release(); - } - - void Release( void ) - { - if ( m_pBeam != NULL ) - { - m_pBeam->flags = 0; - m_pBeam->die = gpGlobals->curtime - 1; - - m_pBeam = NULL; - } - } - - void Init( int startAttachment, int endAttachment, CBaseEntity *pEntity, bool firstPerson ) - { - if ( m_pBeam != NULL ) - return; - - BeamInfo_t beamInfo; - - beamInfo.m_pStartEnt = pEntity; - beamInfo.m_nStartAttachment = startAttachment; - beamInfo.m_pEndEnt = pEntity; - beamInfo.m_nEndAttachment = endAttachment; - beamInfo.m_nType = TE_BEAMPOINTS; - beamInfo.m_vecStart = vec3_origin; - beamInfo.m_vecEnd = vec3_origin; - - beamInfo.m_pszModelName = ( firstPerson ) ? PHYSCANNON_BEAM_SPRITE_NOZ : PHYSCANNON_BEAM_SPRITE; - - beamInfo.m_flHaloScale = 0.0f; - beamInfo.m_flLife = 0.0f; - - if ( firstPerson ) - { - beamInfo.m_flWidth = 0.0f; - beamInfo.m_flEndWidth = 4.0f; - } - else - { - beamInfo.m_flWidth = 0.5f; - beamInfo.m_flEndWidth = 2.0f; - } - - beamInfo.m_flFadeLength = 0.0f; - beamInfo.m_flAmplitude = 16; - beamInfo.m_flBrightness = 255.0; - beamInfo.m_flSpeed = 150.0f; - beamInfo.m_nStartFrame = 0.0; - beamInfo.m_flFrameRate = 30.0; - beamInfo.m_flRed = 255.0; - beamInfo.m_flGreen = 255.0; - beamInfo.m_flBlue = 255.0; - beamInfo.m_nSegments = 8; - beamInfo.m_bRenderable = true; - beamInfo.m_nFlags = FBEAM_FOREVER; - - m_pBeam = beams->CreateBeamEntPoint( beamInfo ); - } - - void SetVisible( bool state = true ) - { - if ( m_pBeam == NULL ) - return; - - m_pBeam->brightness = ( state ) ? 255.0f : 0.0f; - } - -private: - Beam_t *m_pBeam; -}; - -#endif - -//---------------------------------------------------------------------------------------------------------------------------------------------------------- -// CWeaponPhysCannon class -//---------------------------------------------------------------------------------------------------------------------------------------------------------- - -#ifdef CLIENT_DLL -#define CWeaponPhysCannon C_WeaponPhysCannon -#endif - -class CWeaponPhysCannon : public CBaseHL2MPCombatWeapon -{ -public: - DECLARE_CLASS( CWeaponPhysCannon, CBaseHL2MPCombatWeapon ); - - DECLARE_NETWORKCLASS(); - DECLARE_PREDICTABLE(); - - CWeaponPhysCannon( void ); - - void Drop( const Vector &vecVelocity ); - void Precache(); - virtual void OnRestore(); - virtual void StopLoopingSounds(); - virtual void UpdateOnRemove(void); - void PrimaryAttack(); - void SecondaryAttack(); - void WeaponIdle(); - void ItemPreFrame(); - void ItemPostFrame(); - - void ForceDrop( void ); - bool DropIfEntityHeld( CBaseEntity *pTarget ); // Drops its held entity if it matches the entity passed in - CGrabController &GetGrabController() { return m_grabController; } - - bool CanHolster( void ); - bool Holster( CBaseCombatWeapon *pSwitchingTo = NULL ); - bool Deploy( void ); - - bool HasAnyAmmo( void ) { return true; } - - virtual void SetViewModel( void ); - virtual const char *GetShootSound( int iIndex ) const; - -#ifndef CLIENT_DLL - CNetworkQAngle ( m_attachedAnglesPlayerSpace ); -#else - QAngle m_attachedAnglesPlayerSpace; -#endif - - CNetworkVector ( m_attachedPositionObjectSpace ); - - CNetworkHandle( CBaseEntity, m_hAttachedObject ); - - EHANDLE m_hOldAttachedObject; - -protected: - enum FindObjectResult_t - { - OBJECT_FOUND = 0, - OBJECT_NOT_FOUND, - OBJECT_BEING_DETACHED, - }; - - void DoEffect( int effectType, Vector *pos = NULL ); - - void OpenElements( void ); - void CloseElements( void ); - - // Pickup and throw objects. - bool CanPickupObject( CBaseEntity *pTarget ); - void CheckForTarget( void ); - -#ifndef CLIENT_DLL - bool AttachObject( CBaseEntity *pObject, const Vector &vPosition ); - FindObjectResult_t FindObject( void ); - CBaseEntity *FindObjectInCone( const Vector &vecOrigin, const Vector &vecDir, float flCone ); -#endif // !CLIENT_DLL - - void UpdateObject( void ); - void DetachObject( bool playSound = true, bool wasLaunched = false ); - void LaunchObject( const Vector &vecDir, float flForce ); - void StartEffects( void ); // Initialize all sprites and beams - void StopEffects( bool stopSound = true ); // Hide all effects temporarily - void DestroyEffects( void ); // Destroy all sprites and beams - - // Punt objects - this is pointing at an object in the world and applying a force to it. - void PuntNonVPhysics( CBaseEntity *pEntity, const Vector &forward, trace_t &tr ); - void PuntVPhysics( CBaseEntity *pEntity, const Vector &forward, trace_t &tr ); - - // Velocity-based throw common to punt and launch code. - void ApplyVelocityBasedForce( CBaseEntity *pEntity, const Vector &forward ); - - // Physgun effects - void DoEffectClosed( void ); - void DoEffectReady( void ); - void DoEffectHolding( void ); - void DoEffectLaunch( Vector *pos ); - void DoEffectNone( void ); - void DoEffectIdle( void ); - - // Trace length - float TraceLength(); - - // Sprite scale factor - float SpriteScaleFactor(); - - float GetLoadPercentage(); - CSoundPatch *GetMotorSound( void ); - - void DryFire( void ); - void PrimaryFireEffect( void ); - -#ifndef CLIENT_DLL - // What happens when the physgun picks up something - void Physgun_OnPhysGunPickup( CBaseEntity *pEntity, CBasePlayer *pOwner, PhysGunPickup_t reason ); -#endif // !CLIENT_DLL - -#ifdef CLIENT_DLL - - enum EffectType_t - { - PHYSCANNON_CORE = 0, - - PHYSCANNON_BLAST, - - PHYSCANNON_GLOW1, // Must be in order! - PHYSCANNON_GLOW2, - PHYSCANNON_GLOW3, - PHYSCANNON_GLOW4, - PHYSCANNON_GLOW5, - PHYSCANNON_GLOW6, - - PHYSCANNON_ENDCAP1, // Must be in order! - PHYSCANNON_ENDCAP2, - PHYSCANNON_ENDCAP3, // Only used in third-person! - - NUM_PHYSCANNON_PARAMETERS // Must be last! - }; - -#define NUM_GLOW_SPRITES ((CWeaponPhysCannon::PHYSCANNON_GLOW6-CWeaponPhysCannon::PHYSCANNON_GLOW1)+1) -#define NUM_ENDCAP_SPRITES ((CWeaponPhysCannon::PHYSCANNON_ENDCAP3-CWeaponPhysCannon::PHYSCANNON_ENDCAP1)+1) - -#define NUM_PHYSCANNON_BEAMS 3 - - virtual int DrawModel( int flags ); - virtual void ViewModelDrawn( C_BaseViewModel *pBaseViewModel ); - virtual bool IsTransparent( void ); - virtual void OnDataChanged( DataUpdateType_t type ); - virtual void ClientThink( void ); - - void ManagePredictedObject( void ); - void DrawEffects( void ); - void GetEffectParameters( EffectType_t effectID, color32 &color, float &scale, IMaterial **pMaterial, Vector &vecAttachment ); - void DrawEffectSprite( EffectType_t effectID ); - inline bool IsEffectVisible( EffectType_t effectID ); - void UpdateElementPosition( void ); - - // We need to render opaque and translucent pieces - RenderGroup_t GetRenderGroup( void ) { return RENDER_GROUP_TWOPASS; } - - CInterpolatedValue m_ElementParameter; // Used to interpolate the position of the articulated elements - CPhysCannonEffect m_Parameters[NUM_PHYSCANNON_PARAMETERS]; // Interpolated parameters for the effects - CPhysCannonEffectBeam m_Beams[NUM_PHYSCANNON_BEAMS]; // Beams - - int m_nOldEffectState; // Used for parity checks - bool m_bOldOpen; // Used for parity checks - - void NotifyShouldTransmit( ShouldTransmitState_t state ); - -#endif // CLIENT_DLL - - int m_nChangeState; // For delayed state change of elements - float m_flCheckSuppressTime; // Amount of time to suppress the checking for targets - bool m_flLastDenySoundPlayed; // Debounce for deny sound - int m_nAttack2Debounce; - - CNetworkVar( bool, m_bActive ); - CNetworkVar( int, m_EffectState ); // Current state of the effects on the gun - CNetworkVar( bool, m_bOpen ); - - bool m_bResetOwnerEntity; - - float m_flElementDebounce; - - CSoundPatch *m_sndMotor; // Whirring sound for the gun - - CGrabController m_grabController; - - float m_flRepuntObjectTime; - EHANDLE m_hLastPuntedObject; - -private: - CWeaponPhysCannon( const CWeaponPhysCannon & ); - -#ifndef CLIENT_DLL - DECLARE_ACTTABLE(); -#endif -}; - -IMPLEMENT_NETWORKCLASS_ALIASED( WeaponPhysCannon, DT_WeaponPhysCannon ) - -BEGIN_NETWORK_TABLE( CWeaponPhysCannon, DT_WeaponPhysCannon ) -#ifdef CLIENT_DLL - RecvPropBool( RECVINFO( m_bActive ) ), - RecvPropEHandle( RECVINFO( m_hAttachedObject ) ), - RecvPropVector( RECVINFO( m_attachedPositionObjectSpace ) ), - RecvPropFloat( RECVINFO( m_attachedAnglesPlayerSpace[0] ) ), - RecvPropFloat( RECVINFO( m_attachedAnglesPlayerSpace[1] ) ), - RecvPropFloat( RECVINFO( m_attachedAnglesPlayerSpace[2] ) ), - RecvPropInt( RECVINFO( m_EffectState ) ), - RecvPropBool( RECVINFO( m_bOpen ) ), -#else - SendPropBool( SENDINFO( m_bActive ) ), - SendPropEHandle( SENDINFO( m_hAttachedObject ) ), - SendPropVector(SENDINFO( m_attachedPositionObjectSpace ), -1, SPROP_COORD), - SendPropAngle( SENDINFO_VECTORELEM(m_attachedAnglesPlayerSpace, 0 ), 11 ), - SendPropAngle( SENDINFO_VECTORELEM(m_attachedAnglesPlayerSpace, 1 ), 11 ), - SendPropAngle( SENDINFO_VECTORELEM(m_attachedAnglesPlayerSpace, 2 ), 11 ), - SendPropInt( SENDINFO( m_EffectState ) ), - SendPropBool( SENDINFO( m_bOpen ) ), -#endif -END_NETWORK_TABLE() - -#ifdef CLIENT_DLL -BEGIN_PREDICTION_DATA( CWeaponPhysCannon ) - DEFINE_PRED_FIELD( m_EffectState, FIELD_INTEGER, FTYPEDESC_INSENDTABLE ), - DEFINE_PRED_FIELD( m_bOpen, FIELD_BOOLEAN, FTYPEDESC_INSENDTABLE ), -END_PREDICTION_DATA() -#endif - -LINK_ENTITY_TO_CLASS( weapon_physcannon, CWeaponPhysCannon ); -PRECACHE_WEAPON_REGISTER( weapon_physcannon ); - -#ifndef CLIENT_DLL - -acttable_t CWeaponPhysCannon::m_acttable[] = -{ - { ACT_HL2MP_IDLE, ACT_HL2MP_IDLE_PHYSGUN, false }, - { ACT_HL2MP_RUN, ACT_HL2MP_RUN_PHYSGUN, false }, - { ACT_HL2MP_IDLE_CROUCH, ACT_HL2MP_IDLE_CROUCH_PHYSGUN, false }, - { ACT_HL2MP_WALK_CROUCH, ACT_HL2MP_WALK_CROUCH_PHYSGUN, false }, - { ACT_HL2MP_GESTURE_RANGE_ATTACK, ACT_HL2MP_GESTURE_RANGE_ATTACK_PHYSGUN, false }, - { ACT_HL2MP_GESTURE_RELOAD, ACT_HL2MP_GESTURE_RELOAD_PHYSGUN, false }, - { ACT_HL2MP_JUMP, ACT_HL2MP_JUMP_PHYSGUN, false }, -}; - -IMPLEMENT_ACTTABLE(CWeaponPhysCannon); - -#endif - - -enum -{ - ELEMENT_STATE_NONE = -1, - ELEMENT_STATE_OPEN, - ELEMENT_STATE_CLOSED, -}; - -enum -{ - EFFECT_NONE, - EFFECT_CLOSED, - EFFECT_READY, - EFFECT_HOLDING, - EFFECT_LAUNCH, -}; - -//----------------------------------------------------------------------------- -// Constructor -//----------------------------------------------------------------------------- -CWeaponPhysCannon::CWeaponPhysCannon( void ) -{ - m_bOpen = false; - m_nChangeState = ELEMENT_STATE_NONE; - m_flCheckSuppressTime = 0.0f; - m_EffectState = (int)EFFECT_NONE; - m_flLastDenySoundPlayed = false; - -#ifdef CLIENT_DLL - m_nOldEffectState = EFFECT_NONE; - m_bOldOpen = false; -#endif -} - -//----------------------------------------------------------------------------- -// Purpose: Precache -//----------------------------------------------------------------------------- -void CWeaponPhysCannon::Precache( void ) -{ - PrecacheModel( PHYSCANNON_BEAM_SPRITE ); - PrecacheModel( PHYSCANNON_BEAM_SPRITE_NOZ ); - - PrecacheScriptSound( "Weapon_PhysCannon.HoldSound" ); - - BaseClass::Precache(); -} - -//----------------------------------------------------------------------------- -// Purpose: Restore -//----------------------------------------------------------------------------- -void CWeaponPhysCannon::OnRestore() -{ - BaseClass::OnRestore(); - m_grabController.OnRestore(); - - // Tracker 8106: Physcannon effects disappear through level transition, so - // just recreate any effects here - if ( m_EffectState != EFFECT_NONE ) - { - DoEffect( m_EffectState, NULL ); - } -} - - -//----------------------------------------------------------------------------- -// On Remove -//----------------------------------------------------------------------------- -void CWeaponPhysCannon::UpdateOnRemove(void) -{ - DestroyEffects( ); - BaseClass::UpdateOnRemove(); -} - -#ifdef CLIENT_DLL -void CWeaponPhysCannon::OnDataChanged( DataUpdateType_t type ) -{ - BaseClass::OnDataChanged( type ); - - if ( type == DATA_UPDATE_CREATED ) - { - SetNextClientThink( CLIENT_THINK_ALWAYS ); - - C_BaseAnimating::AutoAllowBoneAccess boneaccess( true, false ); - StartEffects(); - } - - if ( GetOwner() == NULL ) - { - if ( m_hAttachedObject ) - { - m_hAttachedObject->VPhysicsDestroyObject(); - } - - if ( m_hOldAttachedObject ) - { - m_hOldAttachedObject->VPhysicsDestroyObject(); - } - } - - // Update effect state when out of parity with the server - if ( m_nOldEffectState != m_EffectState ) - { - DoEffect( m_EffectState ); - m_nOldEffectState = m_EffectState; - } - - // Update element state when out of parity - if ( m_bOldOpen != m_bOpen ) - { - if ( m_bOpen ) - { - m_ElementParameter.InitFromCurrent( 1.0f, 0.2f, INTERP_SPLINE ); - } - else - { - m_ElementParameter.InitFromCurrent( 0.0f, 0.5f, INTERP_SPLINE ); - } - - m_bOldOpen = (bool) m_bOpen; - } -} -#endif - -//----------------------------------------------------------------------------- -// Sprite scale factor -//----------------------------------------------------------------------------- -inline float CWeaponPhysCannon::SpriteScaleFactor() -{ - return 1.0f; -} - - -//----------------------------------------------------------------------------- -// Purpose: -// Output : Returns true on success, false on failure. -//----------------------------------------------------------------------------- -bool CWeaponPhysCannon::Deploy( void ) -{ - CloseElements(); - DoEffect( EFFECT_READY ); - - bool bReturn = BaseClass::Deploy(); - - m_flNextSecondaryAttack = m_flNextPrimaryAttack = gpGlobals->curtime; - - CBasePlayer *pOwner = ToBasePlayer( GetOwner() ); - - if ( pOwner ) - { - pOwner->SetNextAttack( gpGlobals->curtime ); - } - - return bReturn; -} - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void CWeaponPhysCannon::SetViewModel( void ) -{ - BaseClass::SetViewModel(); -} - -//----------------------------------------------------------------------------- -// Purpose: Force the cannon to drop anything it's carrying -//----------------------------------------------------------------------------- -void CWeaponPhysCannon::ForceDrop( void ) -{ - CloseElements(); - DetachObject(); - StopEffects(); -} - - -//----------------------------------------------------------------------------- -// Purpose: Drops its held entity if it matches the entity passed in -// Input : *pTarget - -// Output : Returns true on success, false on failure. -//----------------------------------------------------------------------------- -bool CWeaponPhysCannon::DropIfEntityHeld( CBaseEntity *pTarget ) -{ - if ( pTarget == NULL ) - return false; - - CBaseEntity *pHeld = m_grabController.GetAttached(); - - if ( pHeld == NULL ) - return false; - - if ( pHeld == pTarget ) - { - ForceDrop(); - return true; - } - - return false; -} - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void CWeaponPhysCannon::Drop( const Vector &vecVelocity ) -{ - ForceDrop(); - -#ifndef CLIENT_DLL - UTIL_Remove( this ); -#endif -} - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -bool CWeaponPhysCannon::CanHolster( void ) -{ - //Don't holster this weapon if we're holding onto something - if ( m_bActive ) - return false; - - return BaseClass::CanHolster(); -}; - -//----------------------------------------------------------------------------- -// Purpose: -// Output : Returns true on success, false on failure. -//----------------------------------------------------------------------------- -bool CWeaponPhysCannon::Holster( CBaseCombatWeapon *pSwitchingTo ) -{ - //Don't holster this weapon if we're holding onto something - if ( m_bActive ) - return false; - - ForceDrop(); - DestroyEffects(); - - return BaseClass::Holster( pSwitchingTo ); -} - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void CWeaponPhysCannon::DryFire( void ) -{ - SendWeaponAnim( ACT_VM_PRIMARYATTACK ); - - WeaponSound( EMPTY ); -} - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void CWeaponPhysCannon::PrimaryFireEffect( void ) -{ - CBasePlayer *pOwner = ToBasePlayer( GetOwner() ); - - if ( pOwner == NULL ) - return; - - pOwner->ViewPunch( QAngle(-6, SharedRandomInt( "physcannonfire", -2,2) ,0) ); - -#ifndef CLIENT_DLL - color32 white = { 245, 245, 255, 32 }; - UTIL_ScreenFade( pOwner, white, 0.1f, 0.0f, FFADE_IN ); -#endif - - WeaponSound( SINGLE ); -} - -#define MAX_KNOCKBACK_FORCE 128 - -//----------------------------------------------------------------------------- -// Punt non-physics -//----------------------------------------------------------------------------- -void CWeaponPhysCannon::PuntNonVPhysics( CBaseEntity *pEntity, const Vector &forward, trace_t &tr ) -{ - if ( m_hLastPuntedObject == pEntity && gpGlobals->curtime < m_flRepuntObjectTime ) - return; - -#ifndef CLIENT_DLL - CTakeDamageInfo info; - - info.SetAttacker( GetOwner() ); - info.SetInflictor( this ); - info.SetDamage( 1.0f ); - info.SetDamageType( DMG_CRUSH | DMG_PHYSGUN ); - info.SetDamageForce( forward ); // Scale? - info.SetDamagePosition( tr.endpos ); - - m_hLastPuntedObject = pEntity; - m_flRepuntObjectTime = gpGlobals->curtime + 0.5f; - - pEntity->DispatchTraceAttack( info, forward, &tr ); - - ApplyMultiDamage(); - - //Explosion effect - DoEffect( EFFECT_LAUNCH, &tr.endpos ); -#endif - - PrimaryFireEffect(); - SendWeaponAnim( ACT_VM_SECONDARYATTACK ); - - m_nChangeState = ELEMENT_STATE_CLOSED; - m_flElementDebounce = gpGlobals->curtime + 0.5f; - m_flCheckSuppressTime = gpGlobals->curtime + 0.25f; -} - - -#ifndef CLIENT_DLL -//----------------------------------------------------------------------------- -// What happens when the physgun picks up something -//----------------------------------------------------------------------------- -void CWeaponPhysCannon::Physgun_OnPhysGunPickup( CBaseEntity *pEntity, CBasePlayer *pOwner, PhysGunPickup_t reason ) -{ - // If the target is debris, convert it to non-debris - if ( pEntity->GetCollisionGroup() == COLLISION_GROUP_DEBRIS ) - { - // Interactive debris converts back to debris when it comes to rest - pEntity->SetCollisionGroup( COLLISION_GROUP_INTERACTIVE_DEBRIS ); - } - - Pickup_OnPhysGunPickup( pEntity, pOwner, reason ); -} -#endif - -//----------------------------------------------------------------------------- -// Punt vphysics -//----------------------------------------------------------------------------- -void CWeaponPhysCannon::PuntVPhysics( CBaseEntity *pEntity, const Vector &vecForward, trace_t &tr ) -{ - CBasePlayer *pOwner = ToBasePlayer( GetOwner() ); - - - if ( m_hLastPuntedObject == pEntity && gpGlobals->curtime < m_flRepuntObjectTime ) - return; - - m_hLastPuntedObject = pEntity; - m_flRepuntObjectTime = gpGlobals->curtime + 0.5f; - -#ifndef CLIENT_DLL - CTakeDamageInfo info; - - Vector forward = vecForward; - - info.SetAttacker( GetOwner() ); - info.SetInflictor( this ); - info.SetDamage( 0.0f ); - info.SetDamageType( DMG_PHYSGUN ); - pEntity->DispatchTraceAttack( info, forward, &tr ); - ApplyMultiDamage(); - - - if ( Pickup_OnAttemptPhysGunPickup( pEntity, pOwner, PUNTED_BY_CANNON ) ) - { - IPhysicsObject *pList[VPHYSICS_MAX_OBJECT_LIST_COUNT]; - int listCount = pEntity->VPhysicsGetObjectList( pList, ARRAYSIZE(pList) ); - if ( !listCount ) - { - //FIXME: Do we want to do this if there's no physics object? - Physgun_OnPhysGunPickup( pEntity, pOwner, PUNTED_BY_CANNON ); - DryFire(); - return; - } - - if( forward.z < 0 ) - { - //reflect, but flatten the trajectory out a bit so it's easier to hit standing targets - forward.z *= -0.65f; - } - - // NOTE: Do this first to enable motion (if disabled) - so forces will work - // Tell the object it's been punted - Physgun_OnPhysGunPickup( pEntity, pOwner, PUNTED_BY_CANNON ); - - // don't push vehicles that are attached to the world via fixed constraints - // they will just wiggle... - if ( (pList[0]->GetGameFlags() & FVPHYSICS_CONSTRAINT_STATIC) && pEntity->GetServerVehicle() ) - { - forward.Init(); - } - - if ( !Pickup_ShouldPuntUseLaunchForces( pEntity, PHYSGUN_FORCE_PUNTED ) ) - { - int i; - - // limit mass to avoid punting REALLY huge things - float totalMass = 0; - for ( i = 0; i < listCount; i++ ) - { - totalMass += pList[i]->GetMass(); - } - float maxMass = 250; - IServerVehicle *pVehicle = pEntity->GetServerVehicle(); - if ( pVehicle ) - { - maxMass *= 2.5; // 625 for vehicles - } - float mass = MIN(totalMass, maxMass); // max 250kg of additional force - - // Put some spin on the object - for ( i = 0; i < listCount; i++ ) - { - const float hitObjectFactor = 0.5f; - const float otherObjectFactor = 1.0f - hitObjectFactor; - // Must be light enough - float ratio = pList[i]->GetMass() / totalMass; - if ( pList[i] == pEntity->VPhysicsGetObject() ) - { - ratio += hitObjectFactor; - ratio = MIN(ratio,1.0f); - } - else - { - ratio *= otherObjectFactor; - } - pList[i]->ApplyForceCenter( forward * 15000.0f * ratio ); - pList[i]->ApplyForceOffset( forward * mass * 600.0f * ratio, tr.endpos ); - } - } - else - { - ApplyVelocityBasedForce( pEntity, vecForward ); - } - } - -#endif - // Add recoil - QAngle recoil = QAngle( random->RandomFloat( 1.0f, 2.0f ), random->RandomFloat( -1.0f, 1.0f ), 0 ); - pOwner->ViewPunch( recoil ); - - //Explosion effect - DoEffect( EFFECT_LAUNCH, &tr.endpos ); - - PrimaryFireEffect(); - SendWeaponAnim( ACT_VM_SECONDARYATTACK ); - - m_nChangeState = ELEMENT_STATE_CLOSED; - m_flElementDebounce = gpGlobals->curtime + 0.5f; - m_flCheckSuppressTime = gpGlobals->curtime + 0.25f; - - // Don't allow the gun to regrab a thrown object!! - m_flNextSecondaryAttack = m_flNextPrimaryAttack = gpGlobals->curtime + 0.5f; -} - -//----------------------------------------------------------------------------- -// Purpose: Applies velocity-based forces to throw the entity. This code is -// called from both punt and launch carried code. -// ASSUMES: that pEntity is a vphysics entity. -// Input : - -//----------------------------------------------------------------------------- -void CWeaponPhysCannon::ApplyVelocityBasedForce( CBaseEntity *pEntity, const Vector &forward ) -{ -#ifndef CLIENT_DLL - IPhysicsObject *pPhysicsObject = pEntity->VPhysicsGetObject(); - Assert(pPhysicsObject); // Shouldn't ever get here with a non-vphysics object. - if (!pPhysicsObject) - return; - - float flForceMax = physcannon_maxforce.GetFloat(); - float flForce = flForceMax; - - float mass = pPhysicsObject->GetMass(); - if (mass > 100) - { - mass = MIN(mass, 1000); - float flForceMin = physcannon_minforce.GetFloat(); - flForce = SimpleSplineRemapVal(mass, 100, 600, flForceMax, flForceMin); - } - - Vector vVel = forward * flForce; - // FIXME: Josh needs to put a real value in for PHYSGUN_FORCE_PUNTED - AngularImpulse aVel = Pickup_PhysGunLaunchAngularImpulse( pEntity, PHYSGUN_FORCE_PUNTED ); - - pPhysicsObject->AddVelocity( &vVel, &aVel ); - -#endif - -} - - -//----------------------------------------------------------------------------- -// Trace length -//----------------------------------------------------------------------------- -float CWeaponPhysCannon::TraceLength() -{ - return physcannon_tracelength.GetFloat(); -} - - -//----------------------------------------------------------------------------- -// Purpose: -// -// This mode is a toggle. Primary fire one time to pick up a physics object. -// With an object held, click primary fire again to drop object. -//----------------------------------------------------------------------------- -void CWeaponPhysCannon::PrimaryAttack( void ) -{ - if( m_flNextPrimaryAttack > gpGlobals->curtime ) - return; - - CBasePlayer *pOwner = ToBasePlayer( GetOwner() ); - - if ( pOwner == NULL ) - return; - - if( m_bActive ) - { - // Punch the object being held!! - Vector forward; - pOwner->EyeVectors( &forward ); - - // Validate the item is within punt range - CBaseEntity *pHeld = m_grabController.GetAttached(); - Assert( pHeld != NULL ); - - if ( pHeld != NULL ) - { - float heldDist = ( pHeld->WorldSpaceCenter() - pOwner->WorldSpaceCenter() ).Length(); - - if ( heldDist > physcannon_tracelength.GetFloat() ) - { - // We can't punt this yet - DryFire(); - return; - } - } - - LaunchObject( forward, physcannon_maxforce.GetFloat() ); - - PrimaryFireEffect(); - SendWeaponAnim( ACT_VM_SECONDARYATTACK ); - return; - } - - // If not active, just issue a physics punch in the world. - m_flNextPrimaryAttack = gpGlobals->curtime + 0.5f; - - Vector forward; - pOwner->EyeVectors( &forward ); - - // NOTE: Notice we're *not* using the mega tracelength here - // when you have the mega cannon. Punting has shorter range. - Vector start, end; - start = pOwner->Weapon_ShootPosition(); - float flPuntDistance = physcannon_tracelength.GetFloat(); - VectorMA( start, flPuntDistance, forward, end ); - - CTraceFilterNoOwnerTest filter( pOwner, COLLISION_GROUP_NONE ); - trace_t tr; - UTIL_TraceHull( start, end, -Vector(8,8,8), Vector(8,8,8), MASK_SHOT|CONTENTS_GRATE, &filter, &tr ); - bool bValid = true; - CBaseEntity *pEntity = tr.m_pEnt; - if ( tr.fraction == 1 || !tr.m_pEnt || tr.m_pEnt->IsEFlagSet( EFL_NO_PHYSCANNON_INTERACTION ) ) - { - bValid = false; - } - else if ( (pEntity->GetMoveType() != MOVETYPE_VPHYSICS) && ( pEntity->m_takedamage == DAMAGE_NO ) ) - { - bValid = false; - } - - // If the entity we've hit is invalid, try a traceline instead - if ( !bValid ) - { - UTIL_TraceLine( start, end, MASK_SHOT|CONTENTS_GRATE, &filter, &tr ); - if ( tr.fraction == 1 || !tr.m_pEnt || tr.m_pEnt->IsEFlagSet( EFL_NO_PHYSCANNON_INTERACTION ) ) - { - // Play dry-fire sequence - DryFire(); - return; - } - - pEntity = tr.m_pEnt; - } - - // See if we hit something - if ( pEntity->GetMoveType() != MOVETYPE_VPHYSICS ) - { - if ( pEntity->m_takedamage == DAMAGE_NO ) - { - DryFire(); - return; - } - - if( GetOwner()->IsPlayer() ) - { - // Don't let the player zap any NPC's except regular antlions and headcrabs. - if( pEntity->IsPlayer() ) - { - DryFire(); - return; - } - } - - PuntNonVPhysics( pEntity, forward, tr ); - } - else - { - if ( pEntity->VPhysicsIsFlesh( ) ) - { - DryFire(); - return; - } - PuntVPhysics( pEntity, forward, tr ); - } -} - - -//----------------------------------------------------------------------------- -// Purpose: Click secondary attack whilst holding an object to hurl it. -//----------------------------------------------------------------------------- -void CWeaponPhysCannon::SecondaryAttack( void ) -{ -#ifndef CLIENT_DLL - if ( m_flNextSecondaryAttack > gpGlobals->curtime ) - return; - - CBasePlayer *pOwner = ToBasePlayer( GetOwner() ); - - if ( pOwner == NULL ) - return; - - // See if we should drop a held item - if ( ( m_bActive ) && ( pOwner->m_afButtonPressed & IN_ATTACK2 ) ) - { - // Drop the held object - m_flNextPrimaryAttack = gpGlobals->curtime + 0.5; - m_flNextSecondaryAttack = gpGlobals->curtime + 0.5; - - DetachObject(); - - DoEffect( EFFECT_READY ); - - SendWeaponAnim( ACT_VM_PRIMARYATTACK ); - } - else - { - // Otherwise pick it up - FindObjectResult_t result = FindObject(); - switch ( result ) - { - case OBJECT_FOUND: - WeaponSound( SPECIAL1 ); - SendWeaponAnim( ACT_VM_PRIMARYATTACK ); - m_flNextSecondaryAttack = gpGlobals->curtime + 0.5f; - - // We found an object. Debounce the button - m_nAttack2Debounce |= pOwner->m_nButtons; - break; - - case OBJECT_NOT_FOUND: - m_flNextSecondaryAttack = gpGlobals->curtime + 0.1f; - CloseElements(); - break; - - case OBJECT_BEING_DETACHED: - m_flNextSecondaryAttack = gpGlobals->curtime + 0.01f; - break; - } - - DoEffect( EFFECT_HOLDING ); - } -#endif -} - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void CWeaponPhysCannon::WeaponIdle( void ) -{ - if ( HasWeaponIdleTimeElapsed() ) - { - if ( m_bActive ) - { - //Shake when holding an item - SendWeaponAnim( ACT_VM_RELOAD ); - } - else - { - //Otherwise idle simply - SendWeaponAnim( ACT_VM_IDLE ); - } - } -} - -#ifndef CLIENT_DLL - -//----------------------------------------------------------------------------- -// Purpose: -// Input : *pObject - -//----------------------------------------------------------------------------- -bool CWeaponPhysCannon::AttachObject( CBaseEntity *pObject, const Vector &vPosition ) -{ - - if ( m_bActive ) - return false; - - if ( CanPickupObject( pObject ) == false ) - return false; - - m_grabController.SetIgnorePitch( false ); - m_grabController.SetAngleAlignment( 0 ); - - IPhysicsObject *pPhysics = pObject->VPhysicsGetObject(); - - // Must be valid - if ( !pPhysics ) - return false; - - CHL2MP_Player *pOwner = (CHL2MP_Player *)ToBasePlayer( GetOwner() ); - - m_bActive = true; - if( pOwner ) - { - // NOTE: This can change the mass; so it must be done before max speed setting - Physgun_OnPhysGunPickup( pObject, pOwner, PICKED_UP_BY_CANNON ); - } - - // NOTE :This must happen after OnPhysGunPickup because that can change the mass - m_grabController.AttachEntity( pOwner, pObject, pPhysics, false, vPosition, false ); - m_hAttachedObject = pObject; - m_attachedPositionObjectSpace = m_grabController.m_attachedPositionObjectSpace; - m_attachedAnglesPlayerSpace = m_grabController.m_attachedAnglesPlayerSpace; - - m_bResetOwnerEntity = false; - - if ( m_hAttachedObject->GetOwnerEntity() == NULL ) - { - m_hAttachedObject->SetOwnerEntity( pOwner ); - m_bResetOwnerEntity = true; - } - -/* if( pOwner ) - { - pOwner->EnableSprint( false ); - - float loadWeight = ( 1.0f - GetLoadPercentage() ); - float maxSpeed = hl2_walkspeed.GetFloat() + ( ( hl2_normspeed.GetFloat() - hl2_walkspeed.GetFloat() ) * loadWeight ); - - //Msg( "Load perc: %f -- Movement speed: %f/%f\n", loadWeight, maxSpeed, hl2_normspeed.GetFloat() ); - pOwner->SetMaxSpeed( maxSpeed ); - }*/ - - // Don't drop again for a slight delay, in case they were pulling objects near them - m_flNextSecondaryAttack = gpGlobals->curtime + 0.4f; - - DoEffect( EFFECT_HOLDING ); - OpenElements(); - - if ( GetMotorSound() ) - { - (CSoundEnvelopeController::GetController()).Play( GetMotorSound(), 0.0f, 50 ); - (CSoundEnvelopeController::GetController()).SoundChangePitch( GetMotorSound(), 100, 0.5f ); - (CSoundEnvelopeController::GetController()).SoundChangeVolume( GetMotorSound(), 0.8f, 0.5f ); - } - - - - return true; -} - -CWeaponPhysCannon::FindObjectResult_t CWeaponPhysCannon::FindObject( void ) -{ - CBasePlayer *pPlayer = ToBasePlayer( GetOwner() ); - - Assert( pPlayer ); - if ( pPlayer == NULL ) - return OBJECT_NOT_FOUND; - - Vector forward; - pPlayer->EyeVectors( &forward ); - - // Setup our positions - Vector start = pPlayer->Weapon_ShootPosition(); - float testLength = TraceLength() * 4.0f; - Vector end = start + forward * testLength; - - // Try to find an object by looking straight ahead - trace_t tr; - CTraceFilterNoOwnerTest filter( pPlayer, COLLISION_GROUP_NONE ); - UTIL_TraceLine( start, end, MASK_SHOT|CONTENTS_GRATE, &filter, &tr ); - - // Try again with a hull trace - if ( ( tr.fraction == 1.0 ) || ( tr.m_pEnt == NULL ) || ( tr.m_pEnt->IsWorld() ) ) - { - UTIL_TraceHull( start, end, -Vector(4,4,4), Vector(4,4,4), MASK_SHOT|CONTENTS_GRATE, &filter, &tr ); - } - - CBaseEntity *pEntity = tr.m_pEnt ? tr.m_pEnt->GetRootMoveParent() : NULL; - bool bAttach = false; - bool bPull = false; - - // If we hit something, pick it up or pull it - if ( ( tr.fraction != 1.0f ) && ( tr.m_pEnt ) && ( tr.m_pEnt->IsWorld() == false ) ) - { - // Attempt to attach if within range - if ( tr.fraction <= 0.25f ) - { - bAttach = true; - } - else if ( tr.fraction > 0.25f ) - { - bPull = true; - } - } - - // Find anything within a general cone in front - CBaseEntity *pConeEntity = NULL; - - if (!bAttach && !bPull) - { - pConeEntity = FindObjectInCone( start, forward, physcannon_cone.GetFloat() ); - } - - if ( pConeEntity ) - { - pEntity = pConeEntity; - - // If the object is near, grab it. Else, pull it a bit. - if ( pEntity->WorldSpaceCenter().DistToSqr( start ) <= (testLength * testLength) ) - { - bAttach = true; - } - else - { - bPull = true; - } - } - - if ( CanPickupObject( pEntity ) == false ) - { - // Make a noise to signify we can't pick this up - if ( !m_flLastDenySoundPlayed ) - { - m_flLastDenySoundPlayed = true; - WeaponSound( SPECIAL3 ); - } - - return OBJECT_NOT_FOUND; - } - - // Check to see if the object is constrained + needs to be ripped off... - CBasePlayer *pOwner = ToBasePlayer( GetOwner() ); - if ( !Pickup_OnAttemptPhysGunPickup( pEntity, pOwner, PICKED_UP_BY_CANNON ) ) - return OBJECT_BEING_DETACHED; - - if ( bAttach ) - { - return AttachObject( pEntity, tr.endpos ) ? OBJECT_FOUND : OBJECT_NOT_FOUND; - } - - if ( !bPull ) - return OBJECT_NOT_FOUND; - - // FIXME: This needs to be run through the CanPickupObject logic - IPhysicsObject *pObj = pEntity->VPhysicsGetObject(); - if ( !pObj ) - return OBJECT_NOT_FOUND; - - // If we're too far, simply start to pull the object towards us - Vector pullDir = start - pEntity->WorldSpaceCenter(); - VectorNormalize( pullDir ); - pullDir *= physcannon_pullforce.GetFloat(); - - float mass = PhysGetEntityMass( pEntity ); - if ( mass < 50.0f ) - { - pullDir *= (mass + 0.5) * (1/50.0f); - } - - // Nudge it towards us - pObj->ApplyForceCenter( pullDir ); - return OBJECT_NOT_FOUND; -} - -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -CBaseEntity *CWeaponPhysCannon::FindObjectInCone( const Vector &vecOrigin, const Vector &vecDir, float flCone ) -{ - // Find the nearest physics-based item in a cone in front of me. - CBaseEntity *list[256]; - float flNearestDist = TraceLength() + 1.0; - Vector mins = vecOrigin - Vector( flNearestDist, flNearestDist, flNearestDist ); - Vector maxs = vecOrigin + Vector( flNearestDist, flNearestDist, flNearestDist ); - - CBaseEntity *pNearest = NULL; - - int count = UTIL_EntitiesInBox( list, 256, mins, maxs, 0 ); - for( int i = 0 ; i < count ; i++ ) - { - if ( !list[ i ]->VPhysicsGetObject() ) - continue; - - // Closer than other objects - Vector los = ( list[ i ]->WorldSpaceCenter() - vecOrigin ); - float flDist = VectorNormalize( los ); - if( flDist >= flNearestDist ) - continue; - - // Cull to the cone - if ( DotProduct( los, vecDir ) <= flCone ) - continue; - - // Make sure it isn't occluded! - trace_t tr; - CTraceFilterNoOwnerTest filter( GetOwner(), COLLISION_GROUP_NONE ); - UTIL_TraceLine( vecOrigin, list[ i ]->WorldSpaceCenter(), MASK_SHOT|CONTENTS_GRATE, &filter, &tr ); - if( tr.m_pEnt == list[ i ] ) - { - flNearestDist = flDist; - pNearest = list[ i ]; - } - } - - return pNearest; -} - -#endif - -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -bool CGrabController::UpdateObject( CBasePlayer *pPlayer, float flError ) -{ - CBaseEntity *pEntity = GetAttached(); - if ( !pEntity ) - return false; - if ( ComputeError() > flError ) - return false; - if ( pPlayer->GetGroundEntity() == pEntity ) - return false; - if (!pEntity->VPhysicsGetObject() ) - return false; - - //Adrian: Oops, our object became motion disabled, let go! - IPhysicsObject *pPhys = pEntity->VPhysicsGetObject(); - if ( pPhys && pPhys->IsMoveable() == false ) - { - return false; - } - - if ( m_frameCount == gpGlobals->framecount ) - { - return true; - } - m_frameCount = gpGlobals->framecount; - Vector forward, right, up; - QAngle playerAngles = pPlayer->EyeAngles(); - - float pitch = AngleDistance(playerAngles.x,0); - playerAngles.x = clamp( pitch, -75, 75 ); - AngleVectors( playerAngles, &forward, &right, &up ); - - // Now clamp a sphere of object radius at end to the player's bbox - Vector radial = physcollision->CollideGetExtent( pPhys->GetCollide(), vec3_origin, pEntity->GetAbsAngles(), -forward ); - Vector player2d = pPlayer->CollisionProp()->OBBMaxs(); - float playerRadius = player2d.Length2D(); - float flDot = DotProduct( forward, radial ); - - float radius = playerRadius + fabs( flDot ); - - float distance = 24 + ( radius * 2.0f ); - - Vector start = pPlayer->Weapon_ShootPosition(); - Vector end = start + ( forward * distance ); - - trace_t tr; - CTraceFilterSkipTwoEntities traceFilter( pPlayer, pEntity, COLLISION_GROUP_NONE ); - Ray_t ray; - ray.Init( start, end ); - enginetrace->TraceRay( ray, MASK_SOLID_BRUSHONLY, &traceFilter, &tr ); - - if ( tr.fraction < 0.5 ) - { - end = start + forward * (radius*0.5f); - } - else if ( tr.fraction <= 1.0f ) - { - end = start + forward * ( distance - radius ); - } - - Vector playerMins, playerMaxs, nearest; - pPlayer->CollisionProp()->WorldSpaceAABB( &playerMins, &playerMaxs ); - Vector playerLine = pPlayer->CollisionProp()->WorldSpaceCenter(); - CalcClosestPointOnLine( end, playerLine+Vector(0,0,playerMins.z), playerLine+Vector(0,0,playerMaxs.z), nearest, NULL ); - - Vector delta = end - nearest; - float len = VectorNormalize(delta); - if ( len < radius ) - { - end = nearest + radius * delta; - } - - QAngle angles = TransformAnglesFromPlayerSpace( m_attachedAnglesPlayerSpace, pPlayer ); - - //Show overlays of radius - if ( g_debug_physcannon.GetBool() ) - { - -#ifdef CLIENT_DLL - - debugoverlay->AddBoxOverlay( end, -Vector( 2,2,2 ), Vector(2,2,2), angles, 0, 255, 255, true, 0 ); - - debugoverlay->AddBoxOverlay( GetAttached()->WorldSpaceCenter(), - -Vector( radius, radius, radius), - Vector( radius, radius, radius ), - angles, - 255, 255, 0, - true, - 0.0f ); - -#else - - NDebugOverlay::Box( end, -Vector( 2,2,2 ), Vector(2,2,2), 0, 255, 0, true, 0 ); - - NDebugOverlay::Box( GetAttached()->WorldSpaceCenter(), - -Vector( radius+5, radius+5, radius+5), - Vector( radius+5, radius+5, radius+5 ), - 255, 0, 0, - true, - 0.0f ); -#endif - } - -#ifndef CLIENT_DLL - // If it has a preferred orientation, update to ensure we're still oriented correctly. - Pickup_GetPreferredCarryAngles( pEntity, pPlayer, pPlayer->EntityToWorldTransform(), angles ); - - - // We may be holding a prop that has preferred carry angles - if ( m_bHasPreferredCarryAngles ) - { - matrix3x4_t tmp; - ComputePlayerMatrix( pPlayer, tmp ); - angles = TransformAnglesToWorldSpace( m_vecPreferredCarryAngles, tmp ); - } - -#endif - - matrix3x4_t attachedToWorld; - Vector offset; - AngleMatrix( angles, attachedToWorld ); - VectorRotate( m_attachedPositionObjectSpace, attachedToWorld, offset ); - - SetTargetPosition( end - offset, angles ); - - return true; -} - -void CWeaponPhysCannon::UpdateObject( void ) -{ - CBasePlayer *pPlayer = ToBasePlayer( GetOwner() ); - Assert( pPlayer ); - - float flError = 12; - if ( !m_grabController.UpdateObject( pPlayer, flError ) ) - { - DetachObject(); - return; - } -} - -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -void CWeaponPhysCannon::DetachObject( bool playSound, bool wasLaunched ) -{ -#ifndef CLIENT_DLL - if ( m_bActive == false ) - return; - - CHL2MP_Player *pOwner = (CHL2MP_Player *)ToBasePlayer( GetOwner() ); - if( pOwner != NULL ) - { - pOwner->EnableSprint( true ); - pOwner->SetMaxSpeed( hl2_normspeed.GetFloat() ); - } - - CBaseEntity *pObject = m_grabController.GetAttached(); - - m_grabController.DetachEntity( wasLaunched ); - - if ( pObject != NULL ) - { - Pickup_OnPhysGunDrop( pObject, pOwner, wasLaunched ? LAUNCHED_BY_CANNON : DROPPED_BY_CANNON ); - } - - // Stop our looping sound - if ( GetMotorSound() ) - { - (CSoundEnvelopeController::GetController()).SoundChangeVolume( GetMotorSound(), 0.0f, 1.0f ); - (CSoundEnvelopeController::GetController()).SoundChangePitch( GetMotorSound(), 50, 1.0f ); - } - - if ( pObject && m_bResetOwnerEntity == true ) - { - pObject->SetOwnerEntity( NULL ); - } - - m_bActive = false; - m_hAttachedObject = NULL; - - - if ( playSound ) - { - //Play the detach sound - WeaponSound( MELEE_MISS ); - } - -#else - - m_grabController.DetachEntity( wasLaunched ); - - if ( m_hAttachedObject ) - { - m_hAttachedObject->VPhysicsDestroyObject(); - } -#endif -} - - -#ifdef CLIENT_DLL -void CWeaponPhysCannon::ManagePredictedObject( void ) -{ - CBaseEntity *pAttachedObject = m_hAttachedObject.Get(); - - if ( m_hAttachedObject ) - { - // NOTE :This must happen after OnPhysGunPickup because that can change the mass - if ( pAttachedObject != GetGrabController().GetAttached() ) - { - IPhysicsObject *pPhysics = pAttachedObject->VPhysicsGetObject(); - - if ( pPhysics == NULL ) - { - solid_t tmpSolid; - PhysModelParseSolid( tmpSolid, m_hAttachedObject, pAttachedObject->GetModelIndex() ); - - pAttachedObject->VPhysicsInitNormal( SOLID_VPHYSICS, 0, false, &tmpSolid ); - } - - pPhysics = pAttachedObject->VPhysicsGetObject(); - - if ( pPhysics ) - { - m_grabController.SetIgnorePitch( false ); - m_grabController.SetAngleAlignment( 0 ); - - GetGrabController().AttachEntity( ToBasePlayer( GetOwner() ), pAttachedObject, pPhysics, false, vec3_origin, false ); - GetGrabController().m_attachedPositionObjectSpace = m_attachedPositionObjectSpace; - GetGrabController().m_attachedAnglesPlayerSpace = m_attachedAnglesPlayerSpace; - } - } - } - else - { - if ( m_hOldAttachedObject && m_hOldAttachedObject->VPhysicsGetObject() ) - { - GetGrabController().DetachEntity( false ); - - m_hOldAttachedObject->VPhysicsDestroyObject(); - } - } - - m_hOldAttachedObject = m_hAttachedObject; -} - -#endif - -#ifdef CLIENT_DLL - -//----------------------------------------------------------------------------- -// Purpose: Update the pose parameter for the gun -//----------------------------------------------------------------------------- -void CWeaponPhysCannon::UpdateElementPosition( void ) -{ - CBasePlayer *pOwner = ToBasePlayer( GetOwner() ); - - float flElementPosition = m_ElementParameter.Interp( gpGlobals->curtime ); - - if ( ShouldDrawUsingViewModel() ) - { - if ( pOwner != NULL ) - { - CBaseViewModel *vm = pOwner->GetViewModel(); - - if ( vm != NULL ) - { - vm->SetPoseParameter( "active", flElementPosition ); - } - } - } - else - { - SetPoseParameter( "active", flElementPosition ); - } -} - -//----------------------------------------------------------------------------- -// Purpose: Think function for the client -//----------------------------------------------------------------------------- - -void CWeaponPhysCannon::ClientThink( void ) -{ - // Update our elements visually - UpdateElementPosition(); - - // Update our effects - DoEffectIdle(); -} - -#endif // CLIENT_DLL - -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -void CWeaponPhysCannon::ItemPreFrame() -{ - BaseClass::ItemPreFrame(); - -#ifdef CLIENT_DLL - C_BasePlayer *localplayer = C_BasePlayer::GetLocalPlayer(); - - if ( localplayer && !localplayer->IsObserver() ) - ManagePredictedObject(); -#endif - - // Update the object if the weapon is switched on. - if( m_bActive ) - { - UpdateObject(); - } -} - - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void CWeaponPhysCannon::CheckForTarget( void ) -{ -#ifndef CLIENT_DLL - //See if we're suppressing this - if ( m_flCheckSuppressTime > gpGlobals->curtime ) - return; - - // holstered - if ( IsEffectActive( EF_NODRAW ) ) - return; - - CBasePlayer *pOwner = ToBasePlayer( GetOwner() ); - - if ( pOwner == NULL ) - return; - - if ( m_bActive ) - return; - - Vector aimDir; - pOwner->EyeVectors( &aimDir ); - - Vector startPos = pOwner->Weapon_ShootPosition(); - Vector endPos; - VectorMA( startPos, TraceLength(), aimDir, endPos ); - - trace_t tr; - UTIL_TraceHull( startPos, endPos, -Vector(4,4,4), Vector(4,4,4), MASK_SHOT|CONTENTS_GRATE, pOwner, COLLISION_GROUP_NONE, &tr ); - - if ( ( tr.fraction != 1.0f ) && ( tr.m_pEnt != NULL ) ) - { - // FIXME: Try just having the elements always open when pointed at a physics object - if ( CanPickupObject( tr.m_pEnt ) || Pickup_ForcePhysGunOpen( tr.m_pEnt, pOwner ) ) - // if ( ( tr.m_pEnt->VPhysicsGetObject() != NULL ) && ( tr.m_pEnt->GetMoveType() == MOVETYPE_VPHYSICS ) ) - { - m_nChangeState = ELEMENT_STATE_NONE; - OpenElements(); - return; - } - } - - // Close the elements after a delay to prevent overact state switching - if ( ( m_flElementDebounce < gpGlobals->curtime ) && ( m_nChangeState == ELEMENT_STATE_NONE ) ) - { - m_nChangeState = ELEMENT_STATE_CLOSED; - m_flElementDebounce = gpGlobals->curtime + 0.5f; - } -#endif -} - - -//----------------------------------------------------------------------------- -// Purpose: Idle effect (pulsing) -//----------------------------------------------------------------------------- -void CWeaponPhysCannon::DoEffectIdle( void ) -{ -#ifdef CLIENT_DLL - - StartEffects(); - - //if ( ShouldDrawUsingViewModel() ) - { - // Turn on the glow sprites - for ( int i = PHYSCANNON_GLOW1; i < (PHYSCANNON_GLOW1+NUM_GLOW_SPRITES); i++ ) - { - m_Parameters[i].GetScale().SetAbsolute( random->RandomFloat( 0.075f, 0.05f ) * SPRITE_SCALE ); - m_Parameters[i].GetAlpha().SetAbsolute( random->RandomInt( 24, 32 ) ); - } - - // Turn on the glow sprites - for ( int i = PHYSCANNON_ENDCAP1; i < (PHYSCANNON_ENDCAP1+NUM_ENDCAP_SPRITES); i++ ) - { - m_Parameters[i].GetScale().SetAbsolute( random->RandomFloat( 3, 5 ) ); - m_Parameters[i].GetAlpha().SetAbsolute( random->RandomInt( 200, 255 ) ); - } - - if ( m_EffectState != EFFECT_HOLDING ) - { - // Turn beams off - m_Beams[0].SetVisible( false ); - m_Beams[1].SetVisible( false ); - m_Beams[2].SetVisible( false ); - } - } - /* - else - { - // Turn on the glow sprites - for ( int i = PHYSCANNON_GLOW1; i < (PHYSCANNON_GLOW1+NUM_GLOW_SPRITES); i++ ) - { - m_Parameters[i].GetScale().SetAbsolute( random->RandomFloat( 0.075f, 0.05f ) * SPRITE_SCALE ); - m_Parameters[i].GetAlpha().SetAbsolute( random->RandomInt( 24, 32 ) ); - } - - // Turn on the glow sprites - for ( i = PHYSCANNON_ENDCAP1; i < (PHYSCANNON_ENDCAP1+NUM_ENDCAP_SPRITES); i++ ) - { - m_Parameters[i].GetScale().SetAbsolute( random->RandomFloat( 3, 5 ) ); - m_Parameters[i].GetAlpha().SetAbsolute( random->RandomInt( 200, 255 ) ); - } - - if ( m_EffectState != EFFECT_HOLDING ) - { - // Turn beams off - m_Beams[0].SetVisible( false ); - m_Beams[1].SetVisible( false ); - m_Beams[2].SetVisible( false ); - } - } - */ -#endif -} - -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -void CWeaponPhysCannon::ItemPostFrame() -{ - CBasePlayer *pOwner = ToBasePlayer( GetOwner() ); - if ( pOwner == NULL ) - { - // We found an object. Debounce the button - m_nAttack2Debounce = 0; - return; - } - - //Check for object in pickup range - if ( m_bActive == false ) - { - CheckForTarget(); - - if ( ( m_flElementDebounce < gpGlobals->curtime ) && ( m_nChangeState != ELEMENT_STATE_NONE ) ) - { - if ( m_nChangeState == ELEMENT_STATE_OPEN ) - { - OpenElements(); - } - else if ( m_nChangeState == ELEMENT_STATE_CLOSED ) - { - CloseElements(); - } - - m_nChangeState = ELEMENT_STATE_NONE; - } - } - - // NOTE: Attack2 will be considered to be pressed until the first item is picked up. - int nAttack2Mask = pOwner->m_nButtons & (~m_nAttack2Debounce); - if ( nAttack2Mask & IN_ATTACK2 ) - { - SecondaryAttack(); - } - else - { - // Reset our debouncer - m_flLastDenySoundPlayed = false; - - if ( m_bActive == false ) - { - DoEffect( EFFECT_READY ); - } - } - - if (( pOwner->m_nButtons & IN_ATTACK2 ) == 0 ) - { - m_nAttack2Debounce = 0; - } - - if ( pOwner->m_nButtons & IN_ATTACK ) - { - PrimaryAttack(); - } - else - { - WeaponIdle(); - } -} - - -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -#define PHYSCANNON_DANGER_SOUND_RADIUS 128 - -void CWeaponPhysCannon::LaunchObject( const Vector &vecDir, float flForce ) -{ - CBaseEntity *pObject = m_grabController.GetAttached(); - - if ( !(m_hLastPuntedObject == pObject && gpGlobals->curtime < m_flRepuntObjectTime) ) - { - // FIRE!!! - if( pObject != NULL ) - { - DetachObject( false, true ); - - m_hLastPuntedObject = pObject; - m_flRepuntObjectTime = gpGlobals->curtime + 0.5f; - - // Launch - ApplyVelocityBasedForce( pObject, vecDir ); - - // Don't allow the gun to regrab a thrown object!! - m_flNextSecondaryAttack = m_flNextPrimaryAttack = gpGlobals->curtime + 0.5; - - Vector center = pObject->WorldSpaceCenter(); - - //Do repulse effect - DoEffect( EFFECT_LAUNCH, ¢er ); - - m_hAttachedObject = NULL; - m_bActive = false; - } - } - - // Stop our looping sound - if ( GetMotorSound() ) - { - (CSoundEnvelopeController::GetController()).SoundChangeVolume( GetMotorSound(), 0.0f, 1.0f ); - (CSoundEnvelopeController::GetController()).SoundChangePitch( GetMotorSound(), 50, 1.0f ); - } - - //Close the elements and suppress checking for a bit - m_nChangeState = ELEMENT_STATE_CLOSED; - m_flElementDebounce = gpGlobals->curtime + 0.1f; - m_flCheckSuppressTime = gpGlobals->curtime + 0.25f; -} - -bool UTIL_IsCombineBall( CBaseEntity *pEntity ); - -//----------------------------------------------------------------------------- -// Purpose: -// Input : *pTarget - -// Output : Returns true on success, false on failure. -//----------------------------------------------------------------------------- -bool CWeaponPhysCannon::CanPickupObject( CBaseEntity *pTarget ) -{ -#ifndef CLIENT_DLL - if ( pTarget == NULL ) - return false; - - if ( pTarget->GetBaseAnimating() && pTarget->GetBaseAnimating()->IsDissolving() ) - return false; - - if ( pTarget->IsEFlagSet( EFL_NO_PHYSCANNON_INTERACTION ) ) - return false; - - CBasePlayer *pOwner = ToBasePlayer( GetOwner() ); - - if ( pOwner && pOwner->GetGroundEntity() == pTarget ) - return false; - - if ( pTarget->VPhysicsIsFlesh( ) ) - return false; - - IPhysicsObject *pObj = pTarget->VPhysicsGetObject(); - - if ( pObj && pObj->GetGameFlags() & FVPHYSICS_PLAYER_HELD ) - return false; - - if ( UTIL_IsCombineBall( pTarget ) ) - { - return CBasePlayer::CanPickupObject( pTarget, 0, 0 ); - } - - return CBasePlayer::CanPickupObject( pTarget, physcannon_maxmass.GetFloat(), 0 ); -#else - return false; -#endif - -} - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void CWeaponPhysCannon::OpenElements( void ) -{ - if ( m_bOpen ) - return; - - WeaponSound( SPECIAL2 ); - - CBasePlayer *pOwner = ToBasePlayer( GetOwner() ); - - if ( pOwner == NULL ) - return; - - SendWeaponAnim( ACT_VM_IDLE ); - - m_bOpen = true; - - DoEffect( EFFECT_READY ); - -#ifdef CLIENT - // Element prediction - m_ElementParameter.InitFromCurrent( 1.0f, 0.2f, INTERP_SPLINE ); - m_bOldOpen = true; -#endif -} - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void CWeaponPhysCannon::CloseElements( void ) -{ - if ( m_bOpen == false ) - return; - - WeaponSound( MELEE_HIT ); - - CBasePlayer *pOwner = ToBasePlayer( GetOwner() ); - - if ( pOwner == NULL ) - return; - - SendWeaponAnim( ACT_VM_IDLE ); - - m_bOpen = false; - - if ( GetMotorSound() ) - { - (CSoundEnvelopeController::GetController()).SoundChangeVolume( GetMotorSound(), 0.0f, 1.0f ); - (CSoundEnvelopeController::GetController()).SoundChangePitch( GetMotorSound(), 50, 1.0f ); - } - - DoEffect( EFFECT_CLOSED ); - -#ifdef CLIENT - // Element prediction - m_ElementParameter.InitFromCurrent( 0.0f, 0.5f, INTERP_SPLINE ); - m_bOldOpen = false; -#endif -} - -#define PHYSCANNON_MAX_MASS 500 - - -//----------------------------------------------------------------------------- -// Purpose: -// Output : float -//----------------------------------------------------------------------------- -float CWeaponPhysCannon::GetLoadPercentage( void ) -{ - float loadWeight = m_grabController.GetLoadWeight(); - loadWeight /= physcannon_maxmass.GetFloat(); - loadWeight = clamp( loadWeight, 0.0f, 1.0f ); - return loadWeight; -} - - -//----------------------------------------------------------------------------- -// Purpose: -// Output : CSoundPatch -//----------------------------------------------------------------------------- -CSoundPatch *CWeaponPhysCannon::GetMotorSound( void ) -{ - if ( m_sndMotor == NULL ) - { - CPASAttenuationFilter filter( this ); - - m_sndMotor = (CSoundEnvelopeController::GetController()).SoundCreate( filter, entindex(), CHAN_STATIC, "Weapon_PhysCannon.HoldSound", ATTN_NORM ); - } - - return m_sndMotor; -} - - -//----------------------------------------------------------------------------- -// Shuts down sounds -//----------------------------------------------------------------------------- -void CWeaponPhysCannon::StopLoopingSounds() -{ - if ( m_sndMotor != NULL ) - { - (CSoundEnvelopeController::GetController()).SoundDestroy( m_sndMotor ); - m_sndMotor = NULL; - } - -#ifndef CLIENT_DLL - BaseClass::StopLoopingSounds(); -#endif - -} - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void CWeaponPhysCannon::DestroyEffects( void ) -{ -#ifdef CLIENT_DLL - - // Free our beams - m_Beams[0].Release(); - m_Beams[1].Release(); - m_Beams[2].Release(); - -#endif - - // Stop everything - StopEffects(); -} - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void CWeaponPhysCannon::StopEffects( bool stopSound ) -{ - // Turn off our effect state - DoEffect( EFFECT_NONE ); - -#ifndef CLIENT_DLL - //Shut off sounds - if ( stopSound && GetMotorSound() != NULL ) - { - (CSoundEnvelopeController::GetController()).SoundFadeOut( GetMotorSound(), 0.1f ); - } -#endif // !CLIENT_DLL -} - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void CWeaponPhysCannon::StartEffects( void ) -{ -#ifdef CLIENT_DLL - - // ------------------------------------------ - // Core - // ------------------------------------------ - - if ( m_Parameters[PHYSCANNON_CORE].GetMaterial() == NULL ) - { - m_Parameters[PHYSCANNON_CORE].GetScale().Init( 0.0f, 1.0f, 0.1f ); - m_Parameters[PHYSCANNON_CORE].GetAlpha().Init( 255.0f, 255.0f, 0.1f ); - m_Parameters[PHYSCANNON_CORE].SetAttachment( 1 ); - - if ( m_Parameters[PHYSCANNON_CORE].SetMaterial( PHYSCANNON_CENTER_GLOW ) == false ) - { - // This means the texture was not found - Assert( 0 ); - } - } - - // ------------------------------------------ - // Blast - // ------------------------------------------ - - if ( m_Parameters[PHYSCANNON_BLAST].GetMaterial() == NULL ) - { - m_Parameters[PHYSCANNON_BLAST].GetScale().Init( 0.0f, 1.0f, 0.1f ); - m_Parameters[PHYSCANNON_BLAST].GetAlpha().Init( 255.0f, 255.0f, 0.1f ); - m_Parameters[PHYSCANNON_BLAST].SetAttachment( 1 ); - m_Parameters[PHYSCANNON_BLAST].SetVisible( false ); - - if ( m_Parameters[PHYSCANNON_BLAST].SetMaterial( PHYSCANNON_BLAST_SPRITE ) == false ) - { - // This means the texture was not found - Assert( 0 ); - } - } - - // ------------------------------------------ - // Glows - // ------------------------------------------ - - const char *attachNamesGlowThirdPerson[NUM_GLOW_SPRITES] = - { - "fork1m", - "fork1t", - "fork2m", - "fork2t", - "fork3m", - "fork3t", - }; - - const char *attachNamesGlow[NUM_GLOW_SPRITES] = - { - "fork1b", - "fork1m", - "fork1t", - "fork2b", - "fork2m", - "fork2t" - }; - - //Create the glow sprites - for ( int i = PHYSCANNON_GLOW1; i < (PHYSCANNON_GLOW1+NUM_GLOW_SPRITES); i++ ) - { - if ( m_Parameters[i].GetMaterial() != NULL ) - continue; - - m_Parameters[i].GetScale().SetAbsolute( 0.05f * SPRITE_SCALE ); - m_Parameters[i].GetAlpha().SetAbsolute( 64.0f ); - - // Different for different views - if ( ShouldDrawUsingViewModel() ) - { - m_Parameters[i].SetAttachment( LookupAttachment( attachNamesGlow[i-PHYSCANNON_GLOW1] ) ); - } - else - { - m_Parameters[i].SetAttachment( LookupAttachment( attachNamesGlowThirdPerson[i-PHYSCANNON_GLOW1] ) ); - } - m_Parameters[i].SetColor( Vector( 255, 128, 0 ) ); - - if ( m_Parameters[i].SetMaterial( PHYSCANNON_GLOW_SPRITE ) == false ) - { - // This means the texture was not found - Assert( 0 ); - } - } - - // ------------------------------------------ - // End caps - // ------------------------------------------ - - const char *attachNamesEndCap[NUM_ENDCAP_SPRITES] = - { - "fork1t", - "fork2t", - "fork3t" - }; - - //Create the glow sprites - for ( int i = PHYSCANNON_ENDCAP1; i < (PHYSCANNON_ENDCAP1+NUM_ENDCAP_SPRITES); i++ ) - { - if ( m_Parameters[i].GetMaterial() != NULL ) - continue; - - m_Parameters[i].GetScale().SetAbsolute( 0.05f * SPRITE_SCALE ); - m_Parameters[i].GetAlpha().SetAbsolute( 255.0f ); - m_Parameters[i].SetAttachment( LookupAttachment( attachNamesEndCap[i-PHYSCANNON_ENDCAP1] ) ); - m_Parameters[i].SetVisible( false ); - - if ( m_Parameters[i].SetMaterial( PHYSCANNON_ENDCAP_SPRITE ) == false ) - { - // This means the texture was not found - Assert( 0 ); - } - } - -#endif - -} - -//----------------------------------------------------------------------------- -// Purpose: Closing effects -//----------------------------------------------------------------------------- -void CWeaponPhysCannon::DoEffectClosed( void ) -{ - -#ifdef CLIENT_DLL - - // Turn off the end-caps - for ( int i = PHYSCANNON_ENDCAP1; i < (PHYSCANNON_ENDCAP1+NUM_ENDCAP_SPRITES); i++ ) - { - m_Parameters[i].SetVisible( false ); - } - -#endif - -} - -//----------------------------------------------------------------------------- -// Purpose: Ready effects -//----------------------------------------------------------------------------- -void CWeaponPhysCannon::DoEffectReady( void ) -{ - -#ifdef CLIENT_DLL - - // Special POV case - if ( ShouldDrawUsingViewModel() ) - { - //Turn on the center sprite - m_Parameters[PHYSCANNON_CORE].GetScale().InitFromCurrent( 14.0f, 0.2f ); - m_Parameters[PHYSCANNON_CORE].GetAlpha().InitFromCurrent( 128.0f, 0.2f ); - m_Parameters[PHYSCANNON_CORE].SetVisible(); - } - else - { - //Turn off the center sprite - m_Parameters[PHYSCANNON_CORE].GetScale().InitFromCurrent( 8.0f, 0.2f ); - m_Parameters[PHYSCANNON_CORE].GetAlpha().InitFromCurrent( 0.0f, 0.2f ); - m_Parameters[PHYSCANNON_CORE].SetVisible(); - } - - // Turn on the glow sprites - for ( int i = PHYSCANNON_GLOW1; i < (PHYSCANNON_GLOW1+NUM_GLOW_SPRITES); i++ ) - { - m_Parameters[i].GetScale().InitFromCurrent( 0.4f * SPRITE_SCALE, 0.2f ); - m_Parameters[i].GetAlpha().InitFromCurrent( 64.0f, 0.2f ); - m_Parameters[i].SetVisible(); - } - - // Turn on the glow sprites - for ( int i = PHYSCANNON_ENDCAP1; i < (PHYSCANNON_ENDCAP1+NUM_ENDCAP_SPRITES); i++ ) - { - m_Parameters[i].SetVisible( false ); - } - -#endif - -} - - -//----------------------------------------------------------------------------- -// Holding effects -//----------------------------------------------------------------------------- -void CWeaponPhysCannon::DoEffectHolding( void ) -{ - -#ifdef CLIENT_DLL - - if ( ShouldDrawUsingViewModel() ) - { - // Scale up the center sprite - m_Parameters[PHYSCANNON_CORE].GetScale().InitFromCurrent( 16.0f, 0.2f ); - m_Parameters[PHYSCANNON_CORE].GetAlpha().InitFromCurrent( 255.0f, 0.1f ); - m_Parameters[PHYSCANNON_CORE].SetVisible(); - - // Prepare for scale up - m_Parameters[PHYSCANNON_BLAST].SetVisible( false ); - - // Turn on the glow sprites - for ( int i = PHYSCANNON_GLOW1; i < (PHYSCANNON_GLOW1+NUM_GLOW_SPRITES); i++ ) - { - m_Parameters[i].GetScale().InitFromCurrent( 0.5f * SPRITE_SCALE, 0.2f ); - m_Parameters[i].GetAlpha().InitFromCurrent( 64.0f, 0.2f ); - m_Parameters[i].SetVisible(); - } - - // Turn on the glow sprites - // NOTE: The last glow is left off for first-person - for ( int i = PHYSCANNON_ENDCAP1; i < (PHYSCANNON_ENDCAP1+NUM_ENDCAP_SPRITES-1); i++ ) - { - m_Parameters[i].SetVisible(); - } - - // Create our beams - CBasePlayer *pOwner = ToBasePlayer( GetOwner() ); - CBaseEntity *pBeamEnt = pOwner->GetViewModel(); - - // Setup the beams - m_Beams[0].Init( LookupAttachment( "fork1t" ), 1, pBeamEnt, true ); - m_Beams[1].Init( LookupAttachment( "fork2t" ), 1, pBeamEnt, true ); - - // Set them visible - m_Beams[0].SetVisible(); - m_Beams[1].SetVisible(); - } - else - { - // Scale up the center sprite - m_Parameters[PHYSCANNON_CORE].GetScale().InitFromCurrent( 14.0f, 0.2f ); - m_Parameters[PHYSCANNON_CORE].GetAlpha().InitFromCurrent( 255.0f, 0.1f ); - m_Parameters[PHYSCANNON_CORE].SetVisible(); - - // Prepare for scale up - m_Parameters[PHYSCANNON_BLAST].SetVisible( false ); - - // Turn on the glow sprites - for ( int i = PHYSCANNON_GLOW1; i < (PHYSCANNON_GLOW1+NUM_GLOW_SPRITES); i++ ) - { - m_Parameters[i].GetScale().InitFromCurrent( 0.5f * SPRITE_SCALE, 0.2f ); - m_Parameters[i].GetAlpha().InitFromCurrent( 64.0f, 0.2f ); - m_Parameters[i].SetVisible(); - } - - // Turn on the glow sprites - for ( int i = PHYSCANNON_ENDCAP1; i < (PHYSCANNON_ENDCAP1+NUM_ENDCAP_SPRITES); i++ ) - { - m_Parameters[i].SetVisible(); - } - - // Setup the beams - m_Beams[0].Init( LookupAttachment( "fork1t" ), 1, this, false ); - m_Beams[1].Init( LookupAttachment( "fork2t" ), 1, this, false ); - m_Beams[2].Init( LookupAttachment( "fork3t" ), 1, this, false ); - - // Set them visible - m_Beams[0].SetVisible(); - m_Beams[1].SetVisible(); - m_Beams[2].SetVisible(); - } - -#endif - -} - - -//----------------------------------------------------------------------------- -// Launch effects -//----------------------------------------------------------------------------- -void CWeaponPhysCannon::DoEffectLaunch( Vector *pos ) -{ - CBasePlayer *pOwner = ToBasePlayer( GetOwner() ); - if ( pOwner == NULL ) - return; - - Vector endPos; - Vector shotDir; - - // See if we need to predict this position - if ( pos == NULL ) - { - // Hit an entity if we're holding one - if ( m_hAttachedObject ) - { - endPos = m_hAttachedObject->WorldSpaceCenter(); - - shotDir = endPos - pOwner->Weapon_ShootPosition(); - VectorNormalize( shotDir ); - } - else - { - // Otherwise try and find the right spot - endPos = pOwner->Weapon_ShootPosition(); - pOwner->EyeVectors( &shotDir ); - - trace_t tr; - UTIL_TraceLine( endPos, endPos + ( shotDir * MAX_TRACE_LENGTH ), MASK_SHOT, pOwner, COLLISION_GROUP_NONE, &tr ); - - endPos = tr.endpos; - shotDir = endPos - pOwner->Weapon_ShootPosition(); - VectorNormalize( shotDir ); - } - } - else - { - // Use what is supplied - endPos = *pos; - shotDir = ( endPos - pOwner->Weapon_ShootPosition() ); - VectorNormalize( shotDir ); - } - - // End hit - CPVSFilter filter( endPos ); - - // Don't send this to the owning player, they already had it predicted - if ( IsPredicted() ) - { - filter.UsePredictionRules(); - } - - // Do an impact hit - CEffectData data; - data.m_vOrigin = endPos; -#ifdef CLIENT_DLL - data.m_hEntity = GetRefEHandle(); -#else - data.m_nEntIndex = entindex(); -#endif - - te->DispatchEffect( filter, 0.0, data.m_vOrigin, "PhyscannonImpact", data ); - -#ifdef CLIENT_DLL - - //Turn on the blast sprite and scale - m_Parameters[PHYSCANNON_BLAST].GetScale().Init( 8.0f, 64.0f, 0.1f ); - m_Parameters[PHYSCANNON_BLAST].GetAlpha().Init( 255.0f, 0.0f, 0.2f ); - m_Parameters[PHYSCANNON_BLAST].SetVisible(); - -#endif - -} - -//----------------------------------------------------------------------------- -// Purpose: Shutdown for the weapon when it's holstered -//----------------------------------------------------------------------------- -void CWeaponPhysCannon::DoEffectNone( void ) -{ -#ifdef CLIENT_DLL - - //Turn off main glows - m_Parameters[PHYSCANNON_CORE].SetVisible( false ); - m_Parameters[PHYSCANNON_BLAST].SetVisible( false ); - - for ( int i = PHYSCANNON_GLOW1; i < (PHYSCANNON_GLOW1+NUM_GLOW_SPRITES); i++ ) - { - m_Parameters[i].SetVisible( false ); - } - - // Turn on the glow sprites - for ( int i = PHYSCANNON_ENDCAP1; i < (PHYSCANNON_ENDCAP1+NUM_ENDCAP_SPRITES); i++ ) - { - m_Parameters[i].SetVisible( false ); - } - - m_Beams[0].SetVisible( false ); - m_Beams[1].SetVisible( false ); - m_Beams[2].SetVisible( false ); - -#endif -} - -//----------------------------------------------------------------------------- -// Purpose: -// Input : effectType - -//----------------------------------------------------------------------------- -void CWeaponPhysCannon::DoEffect( int effectType, Vector *pos ) -{ - m_EffectState = effectType; - -#ifdef CLIENT_DLL - // Save predicted state - m_nOldEffectState = m_EffectState; -#endif - - switch( effectType ) - { - case EFFECT_CLOSED: - DoEffectClosed( ); - break; - - case EFFECT_READY: - DoEffectReady( ); - break; - - case EFFECT_HOLDING: - DoEffectHolding(); - break; - - case EFFECT_LAUNCH: - DoEffectLaunch( pos ); - break; - - default: - case EFFECT_NONE: - DoEffectNone(); - break; - } -} - -//----------------------------------------------------------------------------- -// Purpose: -// Input : iIndex - -// Output : const char -//----------------------------------------------------------------------------- -const char *CWeaponPhysCannon::GetShootSound( int iIndex ) const -{ - return BaseClass::GetShootSound( iIndex ); -} - -#ifdef CLIENT_DLL - -extern void FormatViewModelAttachment( Vector &vOrigin, bool bInverse ); - -//----------------------------------------------------------------------------- -// Purpose: Gets the complete list of values needed to render an effect from an -// effect parameter -//----------------------------------------------------------------------------- -void CWeaponPhysCannon::GetEffectParameters( EffectType_t effectID, color32 &color, float &scale, IMaterial **pMaterial, Vector &vecAttachment ) -{ - const float dt = gpGlobals->curtime; - - // Get alpha - float alpha = m_Parameters[effectID].GetAlpha().Interp( dt ); - - // Get scale - scale = m_Parameters[effectID].GetScale().Interp( dt ); - - // Get material - *pMaterial = (IMaterial *) m_Parameters[effectID].GetMaterial(); - - // Setup the color - color.r = (int) m_Parameters[effectID].GetColor().x; - color.g = (int) m_Parameters[effectID].GetColor().y; - color.b = (int) m_Parameters[effectID].GetColor().z; - color.a = (int) alpha; - - // Setup the attachment - int attachment = m_Parameters[effectID].GetAttachment(); - QAngle angles; - - // Format for first-person - if ( ShouldDrawUsingViewModel() ) - { - CBasePlayer *pOwner = ToBasePlayer( GetOwner() ); - - if ( pOwner != NULL ) - { - pOwner->GetViewModel()->GetAttachment( attachment, vecAttachment, angles ); - ::FormatViewModelAttachment( vecAttachment, true ); - } - } - else - { - GetAttachment( attachment, vecAttachment, angles ); - } -} - -//----------------------------------------------------------------------------- -// Purpose: Whether or not an effect is set to display -//----------------------------------------------------------------------------- -bool CWeaponPhysCannon::IsEffectVisible( EffectType_t effectID ) -{ - return m_Parameters[effectID].IsVisible(); -} - -//----------------------------------------------------------------------------- -// Purpose: Draws the effect sprite, given an effect parameter ID -//----------------------------------------------------------------------------- -void CWeaponPhysCannon::DrawEffectSprite( EffectType_t effectID ) -{ - color32 color; - float scale; - IMaterial *pMaterial; - Vector vecAttachment; - - // Don't draw invisible effects - if ( IsEffectVisible( effectID ) == false ) - return; - - // Get all of our parameters - GetEffectParameters( effectID, color, scale, &pMaterial, vecAttachment ); - - // Msg( "Scale: %.2f\tAlpha: %.2f\n", scale, alpha ); - - // Don't render fully translucent objects - if ( color.a <= 0.0f ) - return; - - // Draw the sprite - CMatRenderContextPtr pRenderContext( materials ); - pRenderContext->Bind( pMaterial, this ); - DrawSprite( vecAttachment, scale, scale, color ); -} - -//----------------------------------------------------------------------------- -// Purpose: Render our third-person effects -//----------------------------------------------------------------------------- -void CWeaponPhysCannon::DrawEffects( void ) -{ - // Draw the core effects - DrawEffectSprite( PHYSCANNON_CORE ); - DrawEffectSprite( PHYSCANNON_BLAST ); - - // Draw the glows - for ( int i = PHYSCANNON_GLOW1; i < (PHYSCANNON_GLOW1+NUM_GLOW_SPRITES); i++ ) - { - DrawEffectSprite( (EffectType_t) i ); - } - - // Draw the endcaps - for ( int i = PHYSCANNON_ENDCAP1; i < (PHYSCANNON_ENDCAP1+NUM_ENDCAP_SPRITES); i++ ) - { - DrawEffectSprite( (EffectType_t) i ); - } -} - -//----------------------------------------------------------------------------- -// Purpose: Third-person function call to render world model -//----------------------------------------------------------------------------- -int CWeaponPhysCannon::DrawModel( int flags ) -{ - // Only render these on the transparent pass - if ( flags & STUDIO_TRANSPARENCY ) - { - DrawEffects(); - return 1; - } - - // Only do this on the opaque pass - return BaseClass::DrawModel( flags ); -} - -//----------------------------------------------------------------------------- -// Purpose: First-person function call after viewmodel has been drawn -//----------------------------------------------------------------------------- -void CWeaponPhysCannon::ViewModelDrawn( C_BaseViewModel *pBaseViewModel ) -{ - // Render our effects - DrawEffects(); - - // Pass this back up - BaseClass::ViewModelDrawn( pBaseViewModel ); -} - -//----------------------------------------------------------------------------- -// Purpose: We are always considered transparent -//----------------------------------------------------------------------------- -bool CWeaponPhysCannon::IsTransparent( void ) -{ - return true; -} - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void CWeaponPhysCannon::NotifyShouldTransmit( ShouldTransmitState_t state ) -{ - BaseClass::NotifyShouldTransmit(state); - - if ( state == SHOULDTRANSMIT_END ) - { - DoEffect( EFFECT_NONE ); - } -} - -#endif - -//----------------------------------------------------------------------------- -// EXTERNAL API -//----------------------------------------------------------------------------- -void PhysCannonForceDrop( CBaseCombatWeapon *pActiveWeapon, CBaseEntity *pOnlyIfHoldingThis ) -{ - CWeaponPhysCannon *pCannon = dynamic_cast(pActiveWeapon); - if ( pCannon ) - { - if ( pOnlyIfHoldingThis ) - { - pCannon->DropIfEntityHeld( pOnlyIfHoldingThis ); - } - else - { - pCannon->ForceDrop(); - } - } -} - -bool PlayerPickupControllerIsHoldingEntity( CBaseEntity *pPickupControllerEntity, CBaseEntity *pHeldEntity ) -{ - CPlayerPickupController *pController = dynamic_cast(pPickupControllerEntity); - - return pController ? pController->IsHoldingEntity( pHeldEntity ) : false; -} - - -float PhysCannonGetHeldObjectMass( CBaseCombatWeapon *pActiveWeapon, IPhysicsObject *pHeldObject ) -{ - float mass = 0.0f; - CWeaponPhysCannon *pCannon = dynamic_cast(pActiveWeapon); - if ( pCannon ) - { - CGrabController &grab = pCannon->GetGrabController(); - mass = grab.GetSavedMass( pHeldObject ); - } - - return mass; -} - -CBaseEntity *PhysCannonGetHeldEntity( CBaseCombatWeapon *pActiveWeapon ) -{ - CWeaponPhysCannon *pCannon = dynamic_cast(pActiveWeapon); - if ( pCannon ) - { - CGrabController &grab = pCannon->GetGrabController(); - return grab.GetAttached(); - } - - return NULL; -} - -float PlayerPickupGetHeldObjectMass( CBaseEntity *pPickupControllerEntity, IPhysicsObject *pHeldObject ) -{ - float mass = 0.0f; - CPlayerPickupController *pController = dynamic_cast(pPickupControllerEntity); - if ( pController ) - { - CGrabController &grab = pController->GetGrabController(); - mass = grab.GetSavedMass( pHeldObject ); - } - return mass; -} - -#ifdef CLIENT_DLL - -extern void FX_GaussExplosion( const Vector &pos, const Vector &dir, int type ); - -void CallbackPhyscannonImpact( const CEffectData &data ) -{ - C_BaseEntity *pEnt = data.GetEntity(); - if ( pEnt == NULL ) - return; - - Vector vecAttachment; - QAngle vecAngles; - - C_BaseCombatWeapon *pWeapon = dynamic_cast(pEnt); - - if ( pWeapon == NULL ) - return; - - pWeapon->GetAttachment( 1, vecAttachment, vecAngles ); - - Vector dir = ( data.m_vOrigin - vecAttachment ); - VectorNormalize( dir ); - - // Do special first-person fix-up - if ( pWeapon->GetOwner() == CBasePlayer::GetLocalPlayer() ) - { - // Translate the attachment entity to the viewmodel - C_BasePlayer *pPlayer = dynamic_cast(pWeapon->GetOwner()); - - if ( pPlayer ) - { - pEnt = pPlayer->GetViewModel(); - } - - // Format attachment for first-person view! - ::FormatViewModelAttachment( vecAttachment, true ); - - // Explosions at the impact point - FX_GaussExplosion( data.m_vOrigin, -dir, 0 ); - - // Draw a beam - BeamInfo_t beamInfo; - - beamInfo.m_pStartEnt = pEnt; - beamInfo.m_nStartAttachment = 1; - beamInfo.m_pEndEnt = NULL; - beamInfo.m_nEndAttachment = -1; - beamInfo.m_vecStart = vec3_origin; - beamInfo.m_vecEnd = data.m_vOrigin; - beamInfo.m_pszModelName = PHYSCANNON_BEAM_SPRITE; - beamInfo.m_flHaloScale = 0.0f; - beamInfo.m_flLife = 0.1f; - beamInfo.m_flWidth = 12.0f; - beamInfo.m_flEndWidth = 4.0f; - beamInfo.m_flFadeLength = 0.0f; - beamInfo.m_flAmplitude = 0; - beamInfo.m_flBrightness = 255.0; - beamInfo.m_flSpeed = 0.0f; - beamInfo.m_nStartFrame = 0.0; - beamInfo.m_flFrameRate = 30.0; - beamInfo.m_flRed = 255.0; - beamInfo.m_flGreen = 255.0; - beamInfo.m_flBlue = 255.0; - beamInfo.m_nSegments = 16; - beamInfo.m_bRenderable = true; - beamInfo.m_nFlags = FBEAM_ONLYNOISEONCE; - - beams->CreateBeamEntPoint( beamInfo ); - } - else - { - // Explosion at the starting point - FX_GaussExplosion( vecAttachment, dir, 0 ); - } -} - -DECLARE_CLIENT_EFFECT( "PhyscannonImpact", CallbackPhyscannonImpact ); - -#endif diff --git a/sp/src/game/shared/hl2mp/weapon_physcannon.h b/sp/src/game/shared/hl2mp/weapon_physcannon.h deleted file mode 100644 index 03f60f80..00000000 --- a/sp/src/game/shared/hl2mp/weapon_physcannon.h +++ /dev/null @@ -1,30 +0,0 @@ -//========= Copyright Valve Corporation, All rights reserved. ============// -// -// Purpose: -// -//=============================================================================// - -#ifndef WEAPON_PHYSCANNON_H -#define WEAPON_PHYSCANNON_H -#ifdef _WIN32 -#pragma once -#endif - - - -//----------------------------------------------------------------------------- -// Do we have the super-phys gun? -//----------------------------------------------------------------------------- -bool PlayerHasMegaPhysCannon(); - -// force the physcannon to drop an object (if carried) -void PhysCannonForceDrop( CBaseCombatWeapon *pActiveWeapon, CBaseEntity *pOnlyIfHoldingThis ); -void PhysCannonBeginUpgrade( CBaseAnimating *pAnim ); - -bool PlayerPickupControllerIsHoldingEntity( CBaseEntity *pPickupController, CBaseEntity *pHeldEntity ); -float PlayerPickupGetHeldObjectMass( CBaseEntity *pPickupControllerEntity, IPhysicsObject *pHeldObject ); -float PhysCannonGetHeldObjectMass( CBaseCombatWeapon *pActiveWeapon, IPhysicsObject *pHeldObject ); - -CBaseEntity *PhysCannonGetHeldEntity( CBaseCombatWeapon *pActiveWeapon ); - -#endif // WEAPON_PHYSCANNON_H diff --git a/sp/src/game/shared/hl2mp/weapon_pistol.cpp b/sp/src/game/shared/hl2mp/weapon_pistol.cpp deleted file mode 100644 index 5a9533c4..00000000 --- a/sp/src/game/shared/hl2mp/weapon_pistol.cpp +++ /dev/null @@ -1,339 +0,0 @@ -//========= Copyright Valve Corporation, All rights reserved. ============// -// -// Purpose: -// -//=============================================================================// - -#include "cbase.h" -#include "npcevent.h" -#include "in_buttons.h" - -#ifdef CLIENT_DLL - #include "c_hl2mp_player.h" -#else - #include "hl2mp_player.h" -#endif - -#include "weapon_hl2mpbasehlmpcombatweapon.h" - -#define PISTOL_FASTEST_REFIRE_TIME 0.1f -#define PISTOL_FASTEST_DRY_REFIRE_TIME 0.2f - -#define PISTOL_ACCURACY_SHOT_PENALTY_TIME 0.2f // Applied amount of time each shot adds to the time we must recover from -#define PISTOL_ACCURACY_MAXIMUM_PENALTY_TIME 1.5f // Maximum penalty to deal out - -#ifdef CLIENT_DLL -#define CWeaponPistol C_WeaponPistol -#endif - -//----------------------------------------------------------------------------- -// CWeaponPistol -//----------------------------------------------------------------------------- - -class CWeaponPistol : public CBaseHL2MPCombatWeapon -{ -public: - DECLARE_CLASS( CWeaponPistol, CBaseHL2MPCombatWeapon ); - - CWeaponPistol(void); - - DECLARE_NETWORKCLASS(); - DECLARE_PREDICTABLE(); - - void Precache( void ); - void ItemPostFrame( void ); - void ItemPreFrame( void ); - void ItemBusyFrame( void ); - void PrimaryAttack( void ); - void AddViewKick( void ); - void DryFire( void ); - - void UpdatePenaltyTime( void ); - - Activity GetPrimaryAttackActivity( void ); - - virtual bool Reload( void ); - - virtual const Vector& GetBulletSpread( void ) - { - static Vector cone; - - float ramp = RemapValClamped( m_flAccuracyPenalty, - 0.0f, - PISTOL_ACCURACY_MAXIMUM_PENALTY_TIME, - 0.0f, - 1.0f ); - - // We lerp from very accurate to inaccurate over time - VectorLerp( VECTOR_CONE_1DEGREES, VECTOR_CONE_6DEGREES, ramp, cone ); - - return cone; - } - - virtual int GetMinBurst() - { - return 1; - } - - virtual int GetMaxBurst() - { - return 3; - } - - virtual float GetFireRate( void ) - { - return 0.5f; - } - -#ifndef CLIENT_DLL - DECLARE_ACTTABLE(); -#endif - -private: - CNetworkVar( float, m_flSoonestPrimaryAttack ); - CNetworkVar( float, m_flLastAttackTime ); - CNetworkVar( float, m_flAccuracyPenalty ); - CNetworkVar( int, m_nNumShotsFired ); - -private: - CWeaponPistol( const CWeaponPistol & ); -}; - -IMPLEMENT_NETWORKCLASS_ALIASED( WeaponPistol, DT_WeaponPistol ) - -BEGIN_NETWORK_TABLE( CWeaponPistol, DT_WeaponPistol ) -#ifdef CLIENT_DLL - RecvPropTime( RECVINFO( m_flSoonestPrimaryAttack ) ), - RecvPropTime( RECVINFO( m_flLastAttackTime ) ), - RecvPropFloat( RECVINFO( m_flAccuracyPenalty ) ), - RecvPropInt( RECVINFO( m_nNumShotsFired ) ), -#else - SendPropTime( SENDINFO( m_flSoonestPrimaryAttack ) ), - SendPropTime( SENDINFO( m_flLastAttackTime ) ), - SendPropFloat( SENDINFO( m_flAccuracyPenalty ) ), - SendPropInt( SENDINFO( m_nNumShotsFired ) ), -#endif -END_NETWORK_TABLE() - -#ifdef CLIENT_DLL -BEGIN_PREDICTION_DATA( CWeaponPistol ) - DEFINE_PRED_FIELD( m_flSoonestPrimaryAttack, FIELD_FLOAT, FTYPEDESC_INSENDTABLE ), - DEFINE_PRED_FIELD( m_flLastAttackTime, FIELD_FLOAT, FTYPEDESC_INSENDTABLE ), - DEFINE_PRED_FIELD( m_flAccuracyPenalty, FIELD_FLOAT, FTYPEDESC_INSENDTABLE ), - DEFINE_PRED_FIELD( m_nNumShotsFired, FIELD_INTEGER, FTYPEDESC_INSENDTABLE ), -END_PREDICTION_DATA() -#endif - -LINK_ENTITY_TO_CLASS( weapon_pistol, CWeaponPistol ); -PRECACHE_WEAPON_REGISTER( weapon_pistol ); - -#ifndef CLIENT_DLL -acttable_t CWeaponPistol::m_acttable[] = -{ - { ACT_HL2MP_IDLE, ACT_HL2MP_IDLE_PISTOL, false }, - { ACT_HL2MP_RUN, ACT_HL2MP_RUN_PISTOL, false }, - { ACT_HL2MP_IDLE_CROUCH, ACT_HL2MP_IDLE_CROUCH_PISTOL, false }, - { ACT_HL2MP_WALK_CROUCH, ACT_HL2MP_WALK_CROUCH_PISTOL, false }, - { ACT_HL2MP_GESTURE_RANGE_ATTACK, ACT_HL2MP_GESTURE_RANGE_ATTACK_PISTOL, false }, - { ACT_HL2MP_GESTURE_RELOAD, ACT_HL2MP_GESTURE_RELOAD_PISTOL, false }, - { ACT_HL2MP_JUMP, ACT_HL2MP_JUMP_PISTOL, false }, - { ACT_RANGE_ATTACK1, ACT_RANGE_ATTACK_PISTOL, false }, -}; - - -IMPLEMENT_ACTTABLE( CWeaponPistol ); - -#endif - -//----------------------------------------------------------------------------- -// Purpose: Constructor -//----------------------------------------------------------------------------- -CWeaponPistol::CWeaponPistol( void ) -{ - m_flSoonestPrimaryAttack = gpGlobals->curtime; - m_flAccuracyPenalty = 0.0f; - - m_fMinRange1 = 24; - m_fMaxRange1 = 1500; - m_fMinRange2 = 24; - m_fMaxRange2 = 200; - - m_bFiresUnderwater = true; -} - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void CWeaponPistol::Precache( void ) -{ - BaseClass::Precache(); -} - - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void CWeaponPistol::DryFire( void ) -{ - WeaponSound( EMPTY ); - SendWeaponAnim( ACT_VM_DRYFIRE ); - - m_flSoonestPrimaryAttack = gpGlobals->curtime + PISTOL_FASTEST_DRY_REFIRE_TIME; - m_flNextPrimaryAttack = gpGlobals->curtime + SequenceDuration(); -} - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void CWeaponPistol::PrimaryAttack( void ) -{ - if ( ( gpGlobals->curtime - m_flLastAttackTime ) > 0.5f ) - { - m_nNumShotsFired = 0; - } - else - { - m_nNumShotsFired++; - } - - m_flLastAttackTime = gpGlobals->curtime; - m_flSoonestPrimaryAttack = gpGlobals->curtime + PISTOL_FASTEST_REFIRE_TIME; - - CBasePlayer *pOwner = ToBasePlayer( GetOwner() ); - - if( pOwner ) - { - // Each time the player fires the pistol, reset the view punch. This prevents - // the aim from 'drifting off' when the player fires very quickly. This may - // not be the ideal way to achieve this, but it's cheap and it works, which is - // great for a feature we're evaluating. (sjb) - pOwner->ViewPunchReset(); - } - - BaseClass::PrimaryAttack(); - - // Add an accuracy penalty which can move past our maximum penalty time if we're really spastic - m_flAccuracyPenalty += PISTOL_ACCURACY_SHOT_PENALTY_TIME; -} - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void CWeaponPistol::UpdatePenaltyTime( void ) -{ - CBasePlayer *pOwner = ToBasePlayer( GetOwner() ); - - if ( pOwner == NULL ) - return; - - // Check our penalty time decay - if ( ( ( pOwner->m_nButtons & IN_ATTACK ) == false ) && ( m_flSoonestPrimaryAttack < gpGlobals->curtime ) ) - { - m_flAccuracyPenalty -= gpGlobals->frametime; - m_flAccuracyPenalty = clamp( m_flAccuracyPenalty, 0.0f, PISTOL_ACCURACY_MAXIMUM_PENALTY_TIME ); - } -} - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void CWeaponPistol::ItemPreFrame( void ) -{ - UpdatePenaltyTime(); - - BaseClass::ItemPreFrame(); -} - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void CWeaponPistol::ItemBusyFrame( void ) -{ - UpdatePenaltyTime(); - - BaseClass::ItemBusyFrame(); -} - -//----------------------------------------------------------------------------- -// Purpose: Allows firing as fast as button is pressed -//----------------------------------------------------------------------------- -void CWeaponPistol::ItemPostFrame( void ) -{ - BaseClass::ItemPostFrame(); - - if ( m_bInReload ) - return; - - CBasePlayer *pOwner = ToBasePlayer( GetOwner() ); - - if ( pOwner == NULL ) - return; - - if ( pOwner->m_nButtons & IN_ATTACK2 ) - { - m_flLastAttackTime = gpGlobals->curtime + PISTOL_FASTEST_REFIRE_TIME; - m_flSoonestPrimaryAttack = gpGlobals->curtime + PISTOL_FASTEST_REFIRE_TIME; - m_flNextPrimaryAttack = gpGlobals->curtime + PISTOL_FASTEST_REFIRE_TIME; - } - - //Allow a refire as fast as the player can click - if ( ( ( pOwner->m_nButtons & IN_ATTACK ) == false ) && ( m_flSoonestPrimaryAttack < gpGlobals->curtime ) ) - { - m_flNextPrimaryAttack = gpGlobals->curtime - 0.1f; - } - else if ( ( pOwner->m_nButtons & IN_ATTACK ) && ( m_flNextPrimaryAttack < gpGlobals->curtime ) && ( m_iClip1 <= 0 ) ) - { - DryFire(); - } -} - -//----------------------------------------------------------------------------- -// Purpose: -// Output : int -//----------------------------------------------------------------------------- -Activity CWeaponPistol::GetPrimaryAttackActivity( void ) -{ - if ( m_nNumShotsFired < 1 ) - return ACT_VM_PRIMARYATTACK; - - if ( m_nNumShotsFired < 2 ) - return ACT_VM_RECOIL1; - - if ( m_nNumShotsFired < 3 ) - return ACT_VM_RECOIL2; - - return ACT_VM_RECOIL3; -} - -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -bool CWeaponPistol::Reload( void ) -{ - bool fRet = DefaultReload( GetMaxClip1(), GetMaxClip2(), ACT_VM_RELOAD ); - if ( fRet ) - { - WeaponSound( RELOAD ); - m_flAccuracyPenalty = 0.0f; - } - return fRet; -} - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void CWeaponPistol::AddViewKick( void ) -{ - CBasePlayer *pPlayer = ToBasePlayer( GetOwner() ); - - if ( pPlayer == NULL ) - return; - - QAngle viewPunch; - - viewPunch.x = SharedRandomFloat( "pistolpax", 0.25f, 0.5f ); - viewPunch.y = SharedRandomFloat( "pistolpay", -.6f, .6f ); - viewPunch.z = 0.0f; - - //Add it to the view punch - pPlayer->ViewPunch( viewPunch ); -} diff --git a/sp/src/game/shared/hl2mp/weapon_rpg.cpp b/sp/src/game/shared/hl2mp/weapon_rpg.cpp deleted file mode 100644 index aa3cc8fd..00000000 --- a/sp/src/game/shared/hl2mp/weapon_rpg.cpp +++ /dev/null @@ -1,2283 +0,0 @@ -//========= Copyright Valve Corporation, All rights reserved. ============// -// -// Purpose: -// -//=============================================================================// - -#include "cbase.h" -#include "npcevent.h" -#include "in_buttons.h" -#include "weapon_rpg.h" - -#ifdef CLIENT_DLL - #include "c_hl2mp_player.h" - #include "model_types.h" - #include "beamdraw.h" - #include "fx_line.h" - #include "view.h" -#else - #include "basecombatcharacter.h" - #include "movie_explosion.h" - #include "soundent.h" - #include "player.h" - #include "rope.h" - #include "vstdlib/random.h" - #include "engine/IEngineSound.h" - #include "explode.h" - #include "util.h" - #include "in_buttons.h" - #include "shake.h" - #include "te_effect_dispatch.h" - #include "triggers.h" - #include "smoke_trail.h" - #include "collisionutils.h" - #include "hl2_shareddefs.h" -#endif - -#include "debugoverlay_shared.h" - -// memdbgon must be the last include file in a .cpp file!!! -#include "tier0/memdbgon.h" - -#define RPG_SPEED 1500 - -#ifndef CLIENT_DLL -const char *g_pLaserDotThink = "LaserThinkContext"; - -static ConVar sk_apc_missile_damage("sk_apc_missile_damage", "15"); -#define APC_MISSILE_DAMAGE sk_apc_missile_damage.GetFloat() - -#endif - -#ifdef CLIENT_DLL -#define CLaserDot C_LaserDot -#endif - -//----------------------------------------------------------------------------- -// Laser Dot -//----------------------------------------------------------------------------- -class CLaserDot : public CBaseEntity -{ - DECLARE_CLASS( CLaserDot, CBaseEntity ); -public: - - CLaserDot( void ); - ~CLaserDot( void ); - - static CLaserDot *Create( const Vector &origin, CBaseEntity *pOwner = NULL, bool bVisibleDot = true ); - - void SetTargetEntity( CBaseEntity *pTarget ) { m_hTargetEnt = pTarget; } - CBaseEntity *GetTargetEntity( void ) { return m_hTargetEnt; } - - void SetLaserPosition( const Vector &origin, const Vector &normal ); - Vector GetChasePosition(); - void TurnOn( void ); - void TurnOff( void ); - bool IsOn() const { return m_bIsOn; } - - void Toggle( void ); - - int ObjectCaps() { return (BaseClass::ObjectCaps() & ~FCAP_ACROSS_TRANSITION) | FCAP_DONT_SAVE; } - - void MakeInvisible( void ); - -#ifdef CLIENT_DLL - - virtual bool IsTransparent( void ) { return true; } - virtual RenderGroup_t GetRenderGroup( void ) { return RENDER_GROUP_TRANSLUCENT_ENTITY; } - virtual int DrawModel( int flags ); - virtual void OnDataChanged( DataUpdateType_t updateType ); - virtual bool ShouldDraw( void ) { return (IsEffectActive(EF_NODRAW)==false); } - - CMaterialReference m_hSpriteMaterial; -#endif - -protected: - Vector m_vecSurfaceNormal; - EHANDLE m_hTargetEnt; - bool m_bVisibleLaserDot; - bool m_bIsOn; - - DECLARE_NETWORKCLASS(); - DECLARE_DATADESC(); -public: - CLaserDot *m_pNext; -}; - -IMPLEMENT_NETWORKCLASS_ALIASED( LaserDot, DT_LaserDot ) - -BEGIN_NETWORK_TABLE( CLaserDot, DT_LaserDot ) -END_NETWORK_TABLE() - -#ifndef CLIENT_DLL - -// a list of laser dots to search quickly -CEntityClassList g_LaserDotList; -template <> CLaserDot *CEntityClassList::m_pClassList = NULL; -CLaserDot *GetLaserDotList() -{ - return g_LaserDotList.m_pClassList; -} - -BEGIN_DATADESC( CMissile ) - - DEFINE_FIELD( m_hOwner, FIELD_EHANDLE ), - DEFINE_FIELD( m_hRocketTrail, FIELD_EHANDLE ), - DEFINE_FIELD( m_flAugerTime, FIELD_TIME ), - DEFINE_FIELD( m_flMarkDeadTime, FIELD_TIME ), - DEFINE_FIELD( m_flGracePeriodEndsAt, FIELD_TIME ), - DEFINE_FIELD( m_flDamage, FIELD_FLOAT ), - - // Function Pointers - DEFINE_FUNCTION( MissileTouch ), - DEFINE_FUNCTION( AccelerateThink ), - DEFINE_FUNCTION( AugerThink ), - DEFINE_FUNCTION( IgniteThink ), - DEFINE_FUNCTION( SeekThink ), - -END_DATADESC() - -LINK_ENTITY_TO_CLASS( rpg_missile, CMissile ); - -class CWeaponRPG; - -//----------------------------------------------------------------------------- -// Constructor -//----------------------------------------------------------------------------- -CMissile::CMissile() -{ - m_hRocketTrail = NULL; -} - -CMissile::~CMissile() -{ -} - - -//----------------------------------------------------------------------------- -// Purpose: -// -// -//----------------------------------------------------------------------------- -void CMissile::Precache( void ) -{ - PrecacheModel( "models/weapons/w_missile.mdl" ); - PrecacheModel( "models/weapons/w_missile_launch.mdl" ); - PrecacheModel( "models/weapons/w_missile_closed.mdl" ); -} - - -//----------------------------------------------------------------------------- -// Purpose: -// -// -//----------------------------------------------------------------------------- -void CMissile::Spawn( void ) -{ - Precache(); - - SetSolid( SOLID_BBOX ); - SetModel("models/weapons/w_missile_launch.mdl"); - UTIL_SetSize( this, -Vector(4,4,4), Vector(4,4,4) ); - - SetTouch( &CMissile::MissileTouch ); - - SetMoveType( MOVETYPE_FLYGRAVITY, MOVECOLLIDE_FLY_BOUNCE ); - SetThink( &CMissile::IgniteThink ); - - SetNextThink( gpGlobals->curtime + 0.3f ); - - m_takedamage = DAMAGE_YES; - m_iHealth = m_iMaxHealth = 100; - m_bloodColor = DONT_BLEED; - m_flGracePeriodEndsAt = 0; - - AddFlag( FL_OBJECT ); -} - - -//--------------------------------------------------------- -//--------------------------------------------------------- -void CMissile::Event_Killed( const CTakeDamageInfo &info ) -{ - m_takedamage = DAMAGE_NO; - - ShotDown(); -} - -unsigned int CMissile::PhysicsSolidMaskForEntity( void ) const -{ - return BaseClass::PhysicsSolidMaskForEntity() | CONTENTS_HITBOX; -} - -//--------------------------------------------------------- -//--------------------------------------------------------- -int CMissile::OnTakeDamage_Alive( const CTakeDamageInfo &info ) -{ - if ( ( info.GetDamageType() & (DMG_MISSILEDEFENSE | DMG_AIRBOAT) ) == false ) - return 0; - - bool bIsDamaged; - if( m_iHealth <= AugerHealth() ) - { - // This missile is already damaged (i.e., already running AugerThink) - bIsDamaged = true; - } - else - { - // This missile isn't damaged enough to wobble in flight yet - bIsDamaged = false; - } - - int nRetVal = BaseClass::OnTakeDamage_Alive( info ); - - if( !bIsDamaged ) - { - if ( m_iHealth <= AugerHealth() ) - { - ShotDown(); - } - } - - return nRetVal; -} - - -//----------------------------------------------------------------------------- -// Purpose: Stops any kind of tracking and shoots dumb -//----------------------------------------------------------------------------- -void CMissile::DumbFire( void ) -{ - SetThink( NULL ); - SetMoveType( MOVETYPE_FLY ); - - SetModel("models/weapons/w_missile.mdl"); - UTIL_SetSize( this, vec3_origin, vec3_origin ); - - EmitSound( "Missile.Ignite" ); - - // Smoke trail. - CreateSmokeTrail(); -} - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void CMissile::SetGracePeriod( float flGracePeriod ) -{ - m_flGracePeriodEndsAt = gpGlobals->curtime + flGracePeriod; - - // Go non-solid until the grace period ends - AddSolidFlags( FSOLID_NOT_SOLID ); -} - -//--------------------------------------------------------- -//--------------------------------------------------------- -void CMissile::AccelerateThink( void ) -{ - Vector vecForward; - - // !!!UNDONE - make this work exactly the same as HL1 RPG, lest we have looping sound bugs again! - EmitSound( "Missile.Accelerate" ); - - // SetEffects( EF_LIGHT ); - - AngleVectors( GetLocalAngles(), &vecForward ); - SetAbsVelocity( vecForward * RPG_SPEED ); - - SetThink( &CMissile::SeekThink ); - SetNextThink( gpGlobals->curtime + 0.1f ); -} - -#define AUGER_YDEVIANCE 20.0f -#define AUGER_XDEVIANCEUP 8.0f -#define AUGER_XDEVIANCEDOWN 1.0f - -//--------------------------------------------------------- -//--------------------------------------------------------- -void CMissile::AugerThink( void ) -{ - // If we've augered long enough, then just explode - if ( m_flAugerTime < gpGlobals->curtime ) - { - Explode(); - return; - } - - if ( m_flMarkDeadTime < gpGlobals->curtime ) - { - m_lifeState = LIFE_DYING; - } - - QAngle angles = GetLocalAngles(); - - angles.y += random->RandomFloat( -AUGER_YDEVIANCE, AUGER_YDEVIANCE ); - angles.x += random->RandomFloat( -AUGER_XDEVIANCEDOWN, AUGER_XDEVIANCEUP ); - - SetLocalAngles( angles ); - - Vector vecForward; - - AngleVectors( GetLocalAngles(), &vecForward ); - - SetAbsVelocity( vecForward * 1000.0f ); - - SetNextThink( gpGlobals->curtime + 0.05f ); -} - -//----------------------------------------------------------------------------- -// Purpose: Causes the missile to spiral to the ground and explode, due to damage -//----------------------------------------------------------------------------- -void CMissile::ShotDown( void ) -{ - CEffectData data; - data.m_vOrigin = GetAbsOrigin(); - - DispatchEffect( "RPGShotDown", data ); - - if ( m_hRocketTrail != NULL ) - { - m_hRocketTrail->m_bDamaged = true; - } - - SetThink( &CMissile::AugerThink ); - SetNextThink( gpGlobals->curtime ); - m_flAugerTime = gpGlobals->curtime + 1.5f; - m_flMarkDeadTime = gpGlobals->curtime + 0.75; - - // Let the RPG start reloading immediately - if ( m_hOwner != NULL ) - { - m_hOwner->NotifyRocketDied(); - m_hOwner = NULL; - } -} - - -//----------------------------------------------------------------------------- -// The actual explosion -//----------------------------------------------------------------------------- -void CMissile::DoExplosion( void ) -{ - // Explode - ExplosionCreate( GetAbsOrigin(), GetAbsAngles(), GetOwnerEntity(), GetDamage(), GetDamage() * 2, - SF_ENVEXPLOSION_NOSPARKS | SF_ENVEXPLOSION_NODLIGHTS | SF_ENVEXPLOSION_NOSMOKE, 0.0f, this); -} - - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void CMissile::Explode( void ) -{ - // Don't explode against the skybox. Just pretend that - // the missile flies off into the distance. - Vector forward; - - GetVectors( &forward, NULL, NULL ); - - trace_t tr; - UTIL_TraceLine( GetAbsOrigin(), GetAbsOrigin() + forward * 16, MASK_SHOT, this, COLLISION_GROUP_NONE, &tr ); - - m_takedamage = DAMAGE_NO; - SetSolid( SOLID_NONE ); - if( tr.fraction == 1.0 || !(tr.surface.flags & SURF_SKY) ) - { - DoExplosion(); - } - - if( m_hRocketTrail ) - { - m_hRocketTrail->SetLifetime(0.1f); - m_hRocketTrail = NULL; - } - - if ( m_hOwner != NULL ) - { - m_hOwner->NotifyRocketDied(); - m_hOwner = NULL; - } - - StopSound( "Missile.Ignite" ); - UTIL_Remove( this ); -} - -//----------------------------------------------------------------------------- -// Purpose: -// Input : *pOther - -//----------------------------------------------------------------------------- -void CMissile::MissileTouch( CBaseEntity *pOther ) -{ - Assert( pOther ); - - // Don't touch triggers (but DO hit weapons) - if ( pOther->IsSolidFlagSet(FSOLID_TRIGGER|FSOLID_VOLUME_CONTENTS) && pOther->GetCollisionGroup() != COLLISION_GROUP_WEAPON ) - return; - - Explode(); -} - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void CMissile::CreateSmokeTrail( void ) -{ - if ( m_hRocketTrail ) - return; - - // Smoke trail. - if ( (m_hRocketTrail = RocketTrail::CreateRocketTrail()) != NULL ) - { - m_hRocketTrail->m_Opacity = 0.2f; - m_hRocketTrail->m_SpawnRate = 100; - m_hRocketTrail->m_ParticleLifetime = 0.5f; - m_hRocketTrail->m_StartColor.Init( 0.65f, 0.65f , 0.65f ); - m_hRocketTrail->m_EndColor.Init( 0.0, 0.0, 0.0 ); - m_hRocketTrail->m_StartSize = 8; - m_hRocketTrail->m_EndSize = 32; - m_hRocketTrail->m_SpawnRadius = 4; - m_hRocketTrail->m_MinSpeed = 2; - m_hRocketTrail->m_MaxSpeed = 16; - - m_hRocketTrail->SetLifetime( 999 ); - m_hRocketTrail->FollowEntity( this, "0" ); - } -} - - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void CMissile::IgniteThink( void ) -{ - SetMoveType( MOVETYPE_FLY ); - SetModel("models/weapons/w_missile.mdl"); - UTIL_SetSize( this, vec3_origin, vec3_origin ); - RemoveSolidFlags( FSOLID_NOT_SOLID ); - - //TODO: Play opening sound - - Vector vecForward; - - EmitSound( "Missile.Ignite" ); - - AngleVectors( GetLocalAngles(), &vecForward ); - SetAbsVelocity( vecForward * RPG_SPEED ); - - SetThink( &CMissile::SeekThink ); - SetNextThink( gpGlobals->curtime ); - - if ( m_hOwner && m_hOwner->GetOwner() ) - { - CBasePlayer *pPlayer = ToBasePlayer( m_hOwner->GetOwner() ); - - color32 white = { 255,225,205,64 }; - UTIL_ScreenFade( pPlayer, white, 0.1f, 0.0f, FFADE_IN ); - } - - CreateSmokeTrail(); -} - - -//----------------------------------------------------------------------------- -// Gets the shooting position -//----------------------------------------------------------------------------- -void CMissile::GetShootPosition( CLaserDot *pLaserDot, Vector *pShootPosition ) -{ - if ( pLaserDot->GetOwnerEntity() != NULL ) - { - //FIXME: Do we care this isn't exactly the muzzle position? - *pShootPosition = pLaserDot->GetOwnerEntity()->WorldSpaceCenter(); - } - else - { - *pShootPosition = pLaserDot->GetChasePosition(); - } -} - - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -#define RPG_HOMING_SPEED 0.125f - -void CMissile::ComputeActualDotPosition( CLaserDot *pLaserDot, Vector *pActualDotPosition, float *pHomingSpeed ) -{ - *pHomingSpeed = RPG_HOMING_SPEED; - if ( pLaserDot->GetTargetEntity() ) - { - *pActualDotPosition = pLaserDot->GetChasePosition(); - return; - } - - Vector vLaserStart; - GetShootPosition( pLaserDot, &vLaserStart ); - - //Get the laser's vector - Vector vLaserDir; - VectorSubtract( pLaserDot->GetChasePosition(), vLaserStart, vLaserDir ); - - //Find the length of the current laser - float flLaserLength = VectorNormalize( vLaserDir ); - - //Find the length from the missile to the laser's owner - float flMissileLength = GetAbsOrigin().DistTo( vLaserStart ); - - //Find the length from the missile to the laser's position - Vector vecTargetToMissile; - VectorSubtract( GetAbsOrigin(), pLaserDot->GetChasePosition(), vecTargetToMissile ); - float flTargetLength = VectorNormalize( vecTargetToMissile ); - - // See if we should chase the line segment nearest us - if ( ( flMissileLength < flLaserLength ) || ( flTargetLength <= 512.0f ) ) - { - *pActualDotPosition = UTIL_PointOnLineNearestPoint( vLaserStart, pLaserDot->GetChasePosition(), GetAbsOrigin() ); - *pActualDotPosition += ( vLaserDir * 256.0f ); - } - else - { - // Otherwise chase the dot - *pActualDotPosition = pLaserDot->GetChasePosition(); - } - -// NDebugOverlay::Line( pLaserDot->GetChasePosition(), vLaserStart, 0, 255, 0, true, 0.05f ); -// NDebugOverlay::Line( GetAbsOrigin(), *pActualDotPosition, 255, 0, 0, true, 0.05f ); -// NDebugOverlay::Cross3D( *pActualDotPosition, -Vector(4,4,4), Vector(4,4,4), 255, 0, 0, true, 0.05f ); -} - - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void CMissile::SeekThink( void ) -{ - CBaseEntity *pBestDot = NULL; - float flBestDist = MAX_TRACE_LENGTH; - float dotDist; - - // If we have a grace period, go solid when it ends - if ( m_flGracePeriodEndsAt ) - { - if ( m_flGracePeriodEndsAt < gpGlobals->curtime ) - { - RemoveSolidFlags( FSOLID_NOT_SOLID ); - m_flGracePeriodEndsAt = 0; - } - } - - //Search for all dots relevant to us - for( CLaserDot *pEnt = GetLaserDotList(); pEnt != NULL; pEnt = pEnt->m_pNext ) - { - if ( !pEnt->IsOn() ) - continue; - - if ( pEnt->GetOwnerEntity() != GetOwnerEntity() ) - continue; - - dotDist = (GetAbsOrigin() - pEnt->GetAbsOrigin()).Length(); - - //Find closest - if ( dotDist < flBestDist ) - { - pBestDot = pEnt; - flBestDist = dotDist; - } - } - - //If we have a dot target - if ( pBestDot == NULL ) - { - //Think as soon as possible - SetNextThink( gpGlobals->curtime ); - return; - } - - CLaserDot *pLaserDot = (CLaserDot *)pBestDot; - Vector targetPos; - - float flHomingSpeed; - Vector vecLaserDotPosition; - ComputeActualDotPosition( pLaserDot, &targetPos, &flHomingSpeed ); - - if ( IsSimulatingOnAlternateTicks() ) - flHomingSpeed *= 2; - - Vector vTargetDir; - VectorSubtract( targetPos, GetAbsOrigin(), vTargetDir ); - float flDist = VectorNormalize( vTargetDir ); - - Vector vDir = GetAbsVelocity(); - float flSpeed = VectorNormalize( vDir ); - Vector vNewVelocity = vDir; - if ( gpGlobals->frametime > 0.0f ) - { - if ( flSpeed != 0 ) - { - vNewVelocity = ( flHomingSpeed * vTargetDir ) + ( ( 1 - flHomingSpeed ) * vDir ); - - // This computation may happen to cancel itself out exactly. If so, slam to targetdir. - if ( VectorNormalize( vNewVelocity ) < 1e-3 ) - { - vNewVelocity = (flDist != 0) ? vTargetDir : vDir; - } - } - else - { - vNewVelocity = vTargetDir; - } - } - - QAngle finalAngles; - VectorAngles( vNewVelocity, finalAngles ); - SetAbsAngles( finalAngles ); - - vNewVelocity *= flSpeed; - SetAbsVelocity( vNewVelocity ); - - if( GetAbsVelocity() == vec3_origin ) - { - // Strange circumstances have brought this missile to halt. Just blow it up. - Explode(); - return; - } - - // Think as soon as possible - SetNextThink( gpGlobals->curtime ); -} - - -//----------------------------------------------------------------------------- -// Purpose: -// -// Input : &vecOrigin - -// &vecAngles - -// NULL - -// -// Output : CMissile -//----------------------------------------------------------------------------- -CMissile *CMissile::Create( const Vector &vecOrigin, const QAngle &vecAngles, edict_t *pentOwner = NULL ) -{ - //CMissile *pMissile = (CMissile *)CreateEntityByName("rpg_missile" ); - CMissile *pMissile = (CMissile *) CBaseEntity::Create( "rpg_missile", vecOrigin, vecAngles, CBaseEntity::Instance( pentOwner ) ); - pMissile->SetOwnerEntity( Instance( pentOwner ) ); - pMissile->Spawn(); - pMissile->AddEffects( EF_NOSHADOW ); - - Vector vecForward; - AngleVectors( vecAngles, &vecForward ); - - pMissile->SetAbsVelocity( vecForward * 300 + Vector( 0,0, 128 ) ); - - return pMissile; -} - - - -//----------------------------------------------------------------------------- -// This entity is used to create little force boxes that the helicopter -// should avoid. -//----------------------------------------------------------------------------- -class CInfoAPCMissileHint : public CBaseEntity -{ - DECLARE_DATADESC(); - -public: - DECLARE_CLASS( CInfoAPCMissileHint, CBaseEntity ); - - virtual void Spawn( ); - virtual void Activate(); - virtual void UpdateOnRemove(); - - static CBaseEntity *FindAimTarget( CBaseEntity *pMissile, const char *pTargetName, - const Vector &vecCurrentTargetPos, const Vector &vecCurrentTargetVel ); - -private: - EHANDLE m_hTarget; - - typedef CHandle APCMissileHintHandle_t; - static CUtlVector< APCMissileHintHandle_t > s_APCMissileHints; -}; - - -//----------------------------------------------------------------------------- -// -// This entity is used to create little force boxes that the helicopters should avoid. -// -//----------------------------------------------------------------------------- -CUtlVector< CInfoAPCMissileHint::APCMissileHintHandle_t > CInfoAPCMissileHint::s_APCMissileHints; - -LINK_ENTITY_TO_CLASS( info_apc_missile_hint, CInfoAPCMissileHint ); - -BEGIN_DATADESC( CInfoAPCMissileHint ) - DEFINE_FIELD( m_hTarget, FIELD_EHANDLE ), -END_DATADESC() - - -//----------------------------------------------------------------------------- -// Spawn, remove -//----------------------------------------------------------------------------- -void CInfoAPCMissileHint::Spawn( ) -{ - SetModel( STRING( GetModelName() ) ); - SetSolid( SOLID_BSP ); - AddSolidFlags( FSOLID_NOT_SOLID ); - AddEffects( EF_NODRAW ); -} - -void CInfoAPCMissileHint::Activate( ) -{ - BaseClass::Activate(); - - m_hTarget = gEntList.FindEntityByName( NULL, m_target ); - if ( m_hTarget == NULL ) - { - DevWarning( "%s: Could not find target '%s'!\n", GetClassname(), STRING( m_target ) ); - } - else - { - s_APCMissileHints.AddToTail( this ); - } -} - -void CInfoAPCMissileHint::UpdateOnRemove( ) -{ - s_APCMissileHints.FindAndRemove( this ); - BaseClass::UpdateOnRemove(); -} - - -//----------------------------------------------------------------------------- -// Where are how should we avoid? -//----------------------------------------------------------------------------- -#define HINT_PREDICTION_TIME 3.0f - -CBaseEntity *CInfoAPCMissileHint::FindAimTarget( CBaseEntity *pMissile, const char *pTargetName, - const Vector &vecCurrentEnemyPos, const Vector &vecCurrentEnemyVel ) -{ - if ( !pTargetName ) - return NULL; - - float flOOSpeed = pMissile->GetAbsVelocity().Length(); - if ( flOOSpeed != 0.0f ) - { - flOOSpeed = 1.0f / flOOSpeed; - } - - for ( int i = s_APCMissileHints.Count(); --i >= 0; ) - { - CInfoAPCMissileHint *pHint = s_APCMissileHints[i]; - if ( !pHint->NameMatches( pTargetName ) ) - continue; - - if ( !pHint->m_hTarget ) - continue; - - Vector vecMissileToHint, vecMissileToEnemy; - VectorSubtract( pHint->m_hTarget->WorldSpaceCenter(), pMissile->GetAbsOrigin(), vecMissileToHint ); - VectorSubtract( vecCurrentEnemyPos, pMissile->GetAbsOrigin(), vecMissileToEnemy ); - float flDistMissileToHint = VectorNormalize( vecMissileToHint ); - VectorNormalize( vecMissileToEnemy ); - if ( DotProduct( vecMissileToHint, vecMissileToEnemy ) < 0.866f ) - continue; - - // Determine when the target will be inside the volume. - // Project at most 3 seconds in advance - Vector vecRayDelta; - VectorMultiply( vecCurrentEnemyVel, HINT_PREDICTION_TIME, vecRayDelta ); - - BoxTraceInfo_t trace; - if ( !IntersectRayWithOBB( vecCurrentEnemyPos, vecRayDelta, pHint->CollisionProp()->CollisionToWorldTransform(), - pHint->CollisionProp()->OBBMins(), pHint->CollisionProp()->OBBMaxs(), 0.0f, &trace )) - { - continue; - } - - // Determine the amount of time it would take the missile to reach the target - // If we can reach the target within the time it takes for the enemy to reach the - float tSqr = flDistMissileToHint * flOOSpeed / HINT_PREDICTION_TIME; - if ( (tSqr < (trace.t1 * trace.t1)) || (tSqr > (trace.t2 * trace.t2)) ) - continue; - - return pHint->m_hTarget; - } - - return NULL; -} - - -//----------------------------------------------------------------------------- -// a list of missiles to search quickly -//----------------------------------------------------------------------------- -CEntityClassList g_APCMissileList; -template <> CAPCMissile *CEntityClassList::m_pClassList = NULL; -CAPCMissile *GetAPCMissileList() -{ - return g_APCMissileList.m_pClassList; -} - -//----------------------------------------------------------------------------- -// Finds apc missiles in cone -//----------------------------------------------------------------------------- -CAPCMissile *FindAPCMissileInCone( const Vector &vecOrigin, const Vector &vecDirection, float flAngle ) -{ - float flCosAngle = cos( DEG2RAD( flAngle ) ); - for( CAPCMissile *pEnt = GetAPCMissileList(); pEnt != NULL; pEnt = pEnt->m_pNext ) - { - if ( !pEnt->IsSolid() ) - continue; - - Vector vecDelta; - VectorSubtract( pEnt->GetAbsOrigin(), vecOrigin, vecDelta ); - VectorNormalize( vecDelta ); - float flDot = DotProduct( vecDelta, vecDirection ); - if ( flDot > flCosAngle ) - return pEnt; - } - - return NULL; -} - - -//----------------------------------------------------------------------------- -// -// Specialized version of the missile -// -//----------------------------------------------------------------------------- -#define MAX_HOMING_DISTANCE 2250.0f -#define MIN_HOMING_DISTANCE 1250.0f -#define MAX_NEAR_HOMING_DISTANCE 1750.0f -#define MIN_NEAR_HOMING_DISTANCE 1000.0f -#define DOWNWARD_BLEND_TIME_START 0.2f -#define MIN_HEIGHT_DIFFERENCE 250.0f -#define MAX_HEIGHT_DIFFERENCE 550.0f -#define CORRECTION_TIME 0.2f -#define APC_LAUNCH_HOMING_SPEED 0.1f -#define APC_HOMING_SPEED 0.025f -#define HOMING_SPEED_ACCEL 0.01f - -BEGIN_DATADESC( CAPCMissile ) - - DEFINE_FIELD( m_flReachedTargetTime, FIELD_TIME ), - DEFINE_FIELD( m_flIgnitionTime, FIELD_TIME ), - DEFINE_FIELD( m_bGuidingDisabled, FIELD_BOOLEAN ), - DEFINE_FIELD( m_hSpecificTarget, FIELD_EHANDLE ), - DEFINE_FIELD( m_strHint, FIELD_STRING ), - DEFINE_FIELD( m_flLastHomingSpeed, FIELD_FLOAT ), -// DEFINE_FIELD( m_pNext, FIELD_CLASSPTR ), - - DEFINE_THINKFUNC( BeginSeekThink ), - DEFINE_THINKFUNC( AugerStartThink ), - DEFINE_THINKFUNC( ExplodeThink ), - - DEFINE_FUNCTION( APCMissileTouch ), - -END_DATADESC() - -LINK_ENTITY_TO_CLASS( apc_missile, CAPCMissile ); - -CAPCMissile *CAPCMissile::Create( const Vector &vecOrigin, const QAngle &vecAngles, const Vector &vecVelocity, CBaseEntity *pOwner ) -{ - CAPCMissile *pMissile = (CAPCMissile *)CBaseEntity::Create( "apc_missile", vecOrigin, vecAngles, pOwner ); - pMissile->SetOwnerEntity( pOwner ); - pMissile->Spawn(); - pMissile->SetAbsVelocity( vecVelocity ); - pMissile->AddFlag( FL_NOTARGET ); - pMissile->AddEffects( EF_NOSHADOW ); - return pMissile; -} - - -//----------------------------------------------------------------------------- -// Constructor, destructor -//----------------------------------------------------------------------------- -CAPCMissile::CAPCMissile() -{ - g_APCMissileList.Insert( this ); -} - -CAPCMissile::~CAPCMissile() -{ - g_APCMissileList.Remove( this ); -} - - -//----------------------------------------------------------------------------- -// Shared initialization code -//----------------------------------------------------------------------------- -void CAPCMissile::Init() -{ - SetMoveType( MOVETYPE_FLY ); - SetModel("models/weapons/w_missile.mdl"); - UTIL_SetSize( this, vec3_origin, vec3_origin ); - CreateSmokeTrail(); - SetTouch( &CAPCMissile::APCMissileTouch ); - m_flLastHomingSpeed = APC_HOMING_SPEED; -} - - -//----------------------------------------------------------------------------- -// For hitting a specific target -//----------------------------------------------------------------------------- -void CAPCMissile::AimAtSpecificTarget( CBaseEntity *pTarget ) -{ - m_hSpecificTarget = pTarget; -} - - -//----------------------------------------------------------------------------- -// Purpose: -// Input : *pOther - -//----------------------------------------------------------------------------- -void CAPCMissile::APCMissileTouch( CBaseEntity *pOther ) -{ - Assert( pOther ); - if ( !pOther->IsSolid() && !pOther->IsSolidFlagSet(FSOLID_VOLUME_CONTENTS) ) - return; - - Explode(); -} - - -//----------------------------------------------------------------------------- -// Specialized version of the missile -//----------------------------------------------------------------------------- -void CAPCMissile::IgniteDelay( void ) -{ - m_flIgnitionTime = gpGlobals->curtime + 0.3f; - - SetThink( &CAPCMissile::BeginSeekThink ); - SetNextThink( m_flIgnitionTime ); - Init(); - AddSolidFlags( FSOLID_NOT_SOLID ); -} - -void CAPCMissile::AugerDelay( float flDelay ) -{ - m_flIgnitionTime = gpGlobals->curtime; - SetThink( &CAPCMissile::AugerStartThink ); - SetNextThink( gpGlobals->curtime + flDelay ); - Init(); - DisableGuiding(); -} - -void CAPCMissile::AugerStartThink() -{ - if ( m_hRocketTrail != NULL ) - { - m_hRocketTrail->m_bDamaged = true; - } - m_flAugerTime = gpGlobals->curtime + random->RandomFloat( 1.0f, 2.0f ); - SetThink( &CAPCMissile::AugerThink ); - SetNextThink( gpGlobals->curtime ); -} - -void CAPCMissile::ExplodeDelay( float flDelay ) -{ - m_flIgnitionTime = gpGlobals->curtime; - SetThink( &CAPCMissile::ExplodeThink ); - SetNextThink( gpGlobals->curtime + flDelay ); - Init(); - DisableGuiding(); -} - - -void CAPCMissile::BeginSeekThink( void ) -{ - RemoveSolidFlags( FSOLID_NOT_SOLID ); - SetThink( &CAPCMissile::SeekThink ); - SetNextThink( gpGlobals->curtime ); -} - -void CAPCMissile::ExplodeThink() -{ - DoExplosion(); -} - -//----------------------------------------------------------------------------- -// Health lost at which augering starts -//----------------------------------------------------------------------------- -int CAPCMissile::AugerHealth() -{ - return m_iMaxHealth - 25; -} - - -//----------------------------------------------------------------------------- -// Health lost at which augering starts -//----------------------------------------------------------------------------- -void CAPCMissile::DisableGuiding() -{ - m_bGuidingDisabled = true; -} - - -//----------------------------------------------------------------------------- -// Guidance hints -//----------------------------------------------------------------------------- -void CAPCMissile::SetGuidanceHint( const char *pHintName ) -{ - m_strHint = MAKE_STRING( pHintName ); -} - - -//----------------------------------------------------------------------------- -// The actual explosion -//----------------------------------------------------------------------------- -void CAPCMissile::DoExplosion( void ) -{ - if ( GetWaterLevel() != 0 ) - { - CEffectData data; - data.m_vOrigin = WorldSpaceCenter(); - data.m_flMagnitude = 128; - data.m_flScale = 128; - data.m_fFlags = 0; - DispatchEffect( "WaterSurfaceExplosion", data ); - } - else - { - ExplosionCreate( GetAbsOrigin(), GetAbsAngles(), GetOwnerEntity(), - APC_MISSILE_DAMAGE, 100, true, 20000 ); - } -} - - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void CAPCMissile::ComputeLeadingPosition( const Vector &vecShootPosition, CBaseEntity *pTarget, Vector *pLeadPosition ) -{ - Vector vecTarget = pTarget->BodyTarget( vecShootPosition, false ); - float flShotSpeed = GetAbsVelocity().Length(); - if ( flShotSpeed == 0 ) - { - *pLeadPosition = vecTarget; - return; - } - - Vector vecVelocity = pTarget->GetSmoothedVelocity(); - vecVelocity.z = 0.0f; - float flTargetSpeed = VectorNormalize( vecVelocity ); - Vector vecDelta; - VectorSubtract( vecShootPosition, vecTarget, vecDelta ); - float flTargetToShooter = VectorNormalize( vecDelta ); - float flCosTheta = DotProduct( vecDelta, vecVelocity ); - - // Law of cosines... z^2 = x^2 + y^2 - 2xy cos Theta - // where z = flShooterToPredictedTargetPosition = flShotSpeed * predicted time - // x = flTargetSpeed * predicted time - // y = flTargetToShooter - // solve for predicted time using at^2 + bt + c = 0, t = (-b +/- sqrt( b^2 - 4ac )) / 2a - float a = flTargetSpeed * flTargetSpeed - flShotSpeed * flShotSpeed; - float b = -2.0f * flTargetToShooter * flCosTheta * flTargetSpeed; - float c = flTargetToShooter * flTargetToShooter; - - float flDiscrim = b*b - 4*a*c; - if (flDiscrim < 0) - { - *pLeadPosition = vecTarget; - return; - } - - flDiscrim = sqrt(flDiscrim); - float t = (-b + flDiscrim) / (2.0f * a); - float t2 = (-b - flDiscrim) / (2.0f * a); - if ( t < t2 ) - { - t = t2; - } - - if ( t <= 0.0f ) - { - *pLeadPosition = vecTarget; - return; - } - - VectorMA( vecTarget, flTargetSpeed * t, vecVelocity, *pLeadPosition ); -} - - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void CAPCMissile::ComputeActualDotPosition( CLaserDot *pLaserDot, Vector *pActualDotPosition, float *pHomingSpeed ) -{ - if ( m_bGuidingDisabled ) - { - *pActualDotPosition = GetAbsOrigin(); - *pHomingSpeed = 0.0f; - m_flLastHomingSpeed = *pHomingSpeed; - return; - } - - if ( ( m_strHint != NULL_STRING ) && (!m_hSpecificTarget) ) - { - Vector vecOrigin, vecVelocity; - CBaseEntity *pTarget = pLaserDot->GetTargetEntity(); - if ( pTarget ) - { - vecOrigin = pTarget->BodyTarget( GetAbsOrigin(), false ); - vecVelocity = pTarget->GetSmoothedVelocity(); - } - else - { - vecOrigin = pLaserDot->GetChasePosition(); - vecVelocity = vec3_origin; - } - - m_hSpecificTarget = CInfoAPCMissileHint::FindAimTarget( this, STRING( m_strHint ), vecOrigin, vecVelocity ); - } - - CBaseEntity *pLaserTarget = m_hSpecificTarget ? m_hSpecificTarget.Get() : pLaserDot->GetTargetEntity(); - if ( !pLaserTarget ) - { - BaseClass::ComputeActualDotPosition( pLaserDot, pActualDotPosition, pHomingSpeed ); - m_flLastHomingSpeed = *pHomingSpeed; - return; - } - - if ( pLaserTarget->ClassMatches( "npc_bullseye" ) ) - { - if ( m_flLastHomingSpeed != RPG_HOMING_SPEED ) - { - if (m_flLastHomingSpeed > RPG_HOMING_SPEED) - { - m_flLastHomingSpeed -= HOMING_SPEED_ACCEL * UTIL_GetSimulationInterval(); - if ( m_flLastHomingSpeed < RPG_HOMING_SPEED ) - { - m_flLastHomingSpeed = RPG_HOMING_SPEED; - } - } - else - { - m_flLastHomingSpeed += HOMING_SPEED_ACCEL * UTIL_GetSimulationInterval(); - if ( m_flLastHomingSpeed > RPG_HOMING_SPEED ) - { - m_flLastHomingSpeed = RPG_HOMING_SPEED; - } - } - } - *pHomingSpeed = m_flLastHomingSpeed; - *pActualDotPosition = pLaserTarget->WorldSpaceCenter(); - return; - } - - Vector vLaserStart; - GetShootPosition( pLaserDot, &vLaserStart ); - *pHomingSpeed = APC_LAUNCH_HOMING_SPEED; - - //Get the laser's vector - Vector vecTargetPosition = pLaserTarget->BodyTarget( GetAbsOrigin(), false ); - - // Compute leading position - Vector vecLeadPosition; - ComputeLeadingPosition( GetAbsOrigin(), pLaserTarget, &vecLeadPosition ); - - Vector vecTargetToMissile, vecTargetToShooter; - VectorSubtract( GetAbsOrigin(), vecTargetPosition, vecTargetToMissile ); - VectorSubtract( vLaserStart, vecTargetPosition, vecTargetToShooter ); - - *pActualDotPosition = vecLeadPosition; - - float flMinHomingDistance = MIN_HOMING_DISTANCE; - float flMaxHomingDistance = MAX_HOMING_DISTANCE; - float flBlendTime = gpGlobals->curtime - m_flIgnitionTime; - if ( flBlendTime > DOWNWARD_BLEND_TIME_START ) - { - if ( m_flReachedTargetTime != 0.0f ) - { - *pHomingSpeed = APC_HOMING_SPEED; - float flDeltaTime = clamp( gpGlobals->curtime - m_flReachedTargetTime, 0.0f, CORRECTION_TIME ); - *pHomingSpeed = SimpleSplineRemapVal( flDeltaTime, 0.0f, CORRECTION_TIME, 0.2f, *pHomingSpeed ); - flMinHomingDistance = SimpleSplineRemapVal( flDeltaTime, 0.0f, CORRECTION_TIME, MIN_NEAR_HOMING_DISTANCE, flMinHomingDistance ); - flMaxHomingDistance = SimpleSplineRemapVal( flDeltaTime, 0.0f, CORRECTION_TIME, MAX_NEAR_HOMING_DISTANCE, flMaxHomingDistance ); - } - else - { - flMinHomingDistance = MIN_NEAR_HOMING_DISTANCE; - flMaxHomingDistance = MAX_NEAR_HOMING_DISTANCE; - Vector vecDelta; - VectorSubtract( GetAbsOrigin(), *pActualDotPosition, vecDelta ); - if ( vecDelta.z > MIN_HEIGHT_DIFFERENCE ) - { - float flClampedHeight = clamp( vecDelta.z, MIN_HEIGHT_DIFFERENCE, MAX_HEIGHT_DIFFERENCE ); - float flHeightAdjustFactor = SimpleSplineRemapVal( flClampedHeight, MIN_HEIGHT_DIFFERENCE, MAX_HEIGHT_DIFFERENCE, 0.0f, 1.0f ); - - vecDelta.z = 0.0f; - float flDist = VectorNormalize( vecDelta ); - - float flForwardOffset = 2000.0f; - if ( flDist > flForwardOffset ) - { - Vector vecNewPosition; - VectorMA( GetAbsOrigin(), -flForwardOffset, vecDelta, vecNewPosition ); - vecNewPosition.z = pActualDotPosition->z; - - VectorLerp( *pActualDotPosition, vecNewPosition, flHeightAdjustFactor, *pActualDotPosition ); - } - } - else - { - m_flReachedTargetTime = gpGlobals->curtime; - } - } - - // Allows for players right at the edge of rocket range to be threatened - if ( flBlendTime > 0.6f ) - { - float flTargetLength = GetAbsOrigin().DistTo( pLaserTarget->WorldSpaceCenter() ); - flTargetLength = clamp( flTargetLength, flMinHomingDistance, flMaxHomingDistance ); - *pHomingSpeed = SimpleSplineRemapVal( flTargetLength, flMaxHomingDistance, flMinHomingDistance, *pHomingSpeed, 0.01f ); - } - } - - float flDot = DotProduct2D( vecTargetToShooter.AsVector2D(), vecTargetToMissile.AsVector2D() ); - if ( ( flDot < 0 ) || m_bGuidingDisabled ) - { - *pHomingSpeed = 0.0f; - } - - m_flLastHomingSpeed = *pHomingSpeed; - -// NDebugOverlay::Line( vecLeadPosition, GetAbsOrigin(), 0, 255, 0, true, 0.05f ); -// NDebugOverlay::Line( GetAbsOrigin(), *pActualDotPosition, 255, 0, 0, true, 0.05f ); -// NDebugOverlay::Cross3D( *pActualDotPosition, -Vector(4,4,4), Vector(4,4,4), 255, 0, 0, true, 0.05f ); -} - -#endif - -#define RPG_BEAM_SPRITE "effects/laser1.vmt" -#define RPG_BEAM_SPRITE_NOZ "effects/laser1_noz.vmt" -#define RPG_LASER_SPRITE "sprites/redglow1" - -//============================================================================= -// RPG -//============================================================================= - -LINK_ENTITY_TO_CLASS( weapon_rpg, CWeaponRPG ); -PRECACHE_WEAPON_REGISTER(weapon_rpg); - -IMPLEMENT_NETWORKCLASS_ALIASED( WeaponRPG, DT_WeaponRPG ) - -#ifdef CLIENT_DLL -void RecvProxy_MissileDied( const CRecvProxyData *pData, void *pStruct, void *pOut ) -{ - CWeaponRPG *pRPG = ((CWeaponRPG*)pStruct); - - RecvProxy_IntToEHandle( pData, pStruct, pOut ); - - CBaseEntity *pNewMissile = pRPG->GetMissile(); - - if ( pNewMissile == NULL ) - { - if ( pRPG->GetOwner() && pRPG->GetOwner()->GetActiveWeapon() == pRPG ) - { - pRPG->NotifyRocketDied(); - } - } -} - -#endif - -BEGIN_NETWORK_TABLE( CWeaponRPG, DT_WeaponRPG ) -#ifdef CLIENT_DLL - RecvPropBool( RECVINFO( m_bInitialStateUpdate ) ), - RecvPropBool( RECVINFO( m_bGuiding ) ), - RecvPropBool( RECVINFO( m_bHideGuiding ) ), - RecvPropEHandle( RECVINFO( m_hMissile ), RecvProxy_MissileDied ), - RecvPropVector( RECVINFO( m_vecLaserDot ) ), -#else - SendPropBool( SENDINFO( m_bInitialStateUpdate ) ), - SendPropBool( SENDINFO( m_bGuiding ) ), - SendPropBool( SENDINFO( m_bHideGuiding ) ), - SendPropEHandle( SENDINFO( m_hMissile ) ), - SendPropVector( SENDINFO( m_vecLaserDot ) ), -#endif -END_NETWORK_TABLE() - -#ifdef CLIENT_DLL - -BEGIN_PREDICTION_DATA( CWeaponRPG ) - DEFINE_PRED_FIELD( m_bInitialStateUpdate, FIELD_BOOLEAN, FTYPEDESC_INSENDTABLE ), - DEFINE_PRED_FIELD( m_bGuiding, FIELD_BOOLEAN, FTYPEDESC_INSENDTABLE ), - DEFINE_PRED_FIELD( m_bHideGuiding, FIELD_BOOLEAN, FTYPEDESC_INSENDTABLE ), -END_PREDICTION_DATA() - -#endif - -#ifndef CLIENT_DLL -acttable_t CWeaponRPG::m_acttable[] = -{ - { ACT_HL2MP_IDLE, ACT_HL2MP_IDLE_RPG, false }, - { ACT_HL2MP_RUN, ACT_HL2MP_RUN_RPG, false }, - { ACT_HL2MP_IDLE_CROUCH, ACT_HL2MP_IDLE_CROUCH_RPG, false }, - { ACT_HL2MP_WALK_CROUCH, ACT_HL2MP_WALK_CROUCH_RPG, false }, - { ACT_HL2MP_GESTURE_RANGE_ATTACK, ACT_HL2MP_GESTURE_RANGE_ATTACK_RPG, false }, - { ACT_HL2MP_GESTURE_RELOAD, ACT_HL2MP_GESTURE_RELOAD_RPG, false }, - { ACT_HL2MP_JUMP, ACT_HL2MP_JUMP_RPG, false }, - { ACT_RANGE_ATTACK1, ACT_RANGE_ATTACK_RPG, false }, -}; - -IMPLEMENT_ACTTABLE(CWeaponRPG); - -#endif - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -CWeaponRPG::CWeaponRPG() -{ - m_bReloadsSingly = true; - m_bInitialStateUpdate= false; - m_bHideGuiding = false; - m_bGuiding = false; - - m_fMinRange1 = m_fMinRange2 = 40*12; - m_fMaxRange1 = m_fMaxRange2 = 500*12; -} - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -CWeaponRPG::~CWeaponRPG() -{ -#ifndef CLIENT_DLL - if ( m_hLaserDot != NULL ) - { - UTIL_Remove( m_hLaserDot ); - m_hLaserDot = NULL; - } -#endif -} - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void CWeaponRPG::Precache( void ) -{ - BaseClass::Precache(); - - PrecacheScriptSound( "Missile.Ignite" ); - PrecacheScriptSound( "Missile.Accelerate" ); - - // Laser dot... - PrecacheModel( "sprites/redglow1.vmt" ); - PrecacheModel( RPG_LASER_SPRITE ); - PrecacheModel( RPG_BEAM_SPRITE ); - PrecacheModel( RPG_BEAM_SPRITE_NOZ ); - -#ifndef CLIENT_DLL - UTIL_PrecacheOther( "rpg_missile" ); -#endif - -} - - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void CWeaponRPG::Activate( void ) -{ - BaseClass::Activate(); - - // Restore the laser pointer after transition - if ( m_bGuiding ) - { - CBasePlayer *pOwner = ToBasePlayer( GetOwner() ); - - if ( pOwner == NULL ) - return; - - if ( pOwner->GetActiveWeapon() == this ) - { - StartGuiding(); - } - } -} - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -bool CWeaponRPG::HasAnyAmmo( void ) -{ - if ( m_hMissile != NULL ) - return true; - - return BaseClass::HasAnyAmmo(); -} - -//----------------------------------------------------------------------------- -// Purpose: -// Output : Returns true on success, false on failure. -//----------------------------------------------------------------------------- -bool CWeaponRPG::WeaponShouldBeLowered( void ) -{ - // Lower us if we're out of ammo - if ( !HasAnyAmmo() ) - return true; - - return BaseClass::WeaponShouldBeLowered(); -} - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void CWeaponRPG::PrimaryAttack( void ) -{ - // Only the player fires this way so we can cast - CBasePlayer *pPlayer = ToBasePlayer( GetOwner() ); - - if (!pPlayer) - return; - - // Can't have an active missile out - if ( m_hMissile != NULL ) - return; - - // Can't be reloading - if ( GetActivity() == ACT_VM_RELOAD ) - return; - - Vector vecOrigin; - Vector vecForward; - - m_flNextPrimaryAttack = gpGlobals->curtime + 0.5f; - - CBasePlayer *pOwner = ToBasePlayer( GetOwner() ); - - if ( pOwner == NULL ) - return; - - Vector vForward, vRight, vUp; - - pOwner->EyeVectors( &vForward, &vRight, &vUp ); - - Vector muzzlePoint = pOwner->Weapon_ShootPosition() + vForward * 12.0f + vRight * 6.0f + vUp * -3.0f; - -#ifndef CLIENT_DLL - QAngle vecAngles; - VectorAngles( vForward, vecAngles ); - - CMissile *pMissile = CMissile::Create( muzzlePoint, vecAngles, GetOwner()->edict() ); - pMissile->m_hOwner = this; - - // If the shot is clear to the player, give the missile a grace period - trace_t tr; - Vector vecEye = pOwner->EyePosition(); - UTIL_TraceLine( vecEye, vecEye + vForward * 128, MASK_SHOT, this, COLLISION_GROUP_NONE, &tr ); - if ( tr.fraction == 1.0 ) - { - pMissile->SetGracePeriod( 0.3 ); - } - - pMissile->SetDamage( GetHL2MPWpnData().m_iPlayerDamage ); - - m_hMissile = pMissile; -#endif - - DecrementAmmo( GetOwner() ); - SendWeaponAnim( ACT_VM_PRIMARYATTACK ); - WeaponSound( SINGLE ); - - // player "shoot" animation - pPlayer->SetAnimation( PLAYER_ATTACK1 ); -} - -//----------------------------------------------------------------------------- -// Purpose: -// Input : *pOwner - -//----------------------------------------------------------------------------- -void CWeaponRPG::DecrementAmmo( CBaseCombatCharacter *pOwner ) -{ - // Take away our primary ammo type - pOwner->RemoveAmmo( 1, m_iPrimaryAmmoType ); -} - -//----------------------------------------------------------------------------- -// Purpose: -// Input : state - -//----------------------------------------------------------------------------- -void CWeaponRPG::SuppressGuiding( bool state ) -{ - m_bHideGuiding = state; - -#ifndef CLIENT_DLL - - if ( m_hLaserDot == NULL ) - { - StartGuiding(); - - //STILL!? - if ( m_hLaserDot == NULL ) - return; - } - - if ( state ) - { - m_hLaserDot->TurnOff(); - } - else - { - m_hLaserDot->TurnOn(); - } -#endif - -} - -//----------------------------------------------------------------------------- -// Purpose: Override this if we're guiding a missile currently -// Output : Returns true on success, false on failure. -//----------------------------------------------------------------------------- -bool CWeaponRPG::Lower( void ) -{ - if ( m_hMissile != NULL ) - return false; - - return BaseClass::Lower(); -} - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void CWeaponRPG::ItemPostFrame( void ) -{ - BaseClass::ItemPostFrame(); - - CBasePlayer *pPlayer = ToBasePlayer( GetOwner() ); - - if ( pPlayer == NULL ) - return; - - //If we're pulling the weapon out for the first time, wait to draw the laser - if ( ( m_bInitialStateUpdate ) && ( GetActivity() != ACT_VM_DRAW ) ) - { - StartGuiding(); - m_bInitialStateUpdate = false; - } - - // Supress our guiding effects if we're lowered - if ( GetIdealActivity() == ACT_VM_IDLE_LOWERED ) - { - SuppressGuiding(); - } - else - { - SuppressGuiding( false ); - } - - //Move the laser - UpdateLaserPosition(); - - if ( pPlayer->GetAmmoCount(m_iPrimaryAmmoType) <= 0 && m_hMissile == NULL ) - { - StopGuiding(); - } -} - -//----------------------------------------------------------------------------- -// Purpose: -// Output : Vector -//----------------------------------------------------------------------------- -Vector CWeaponRPG::GetLaserPosition( void ) -{ -#ifndef CLIENT_DLL - CreateLaserPointer(); - - if ( m_hLaserDot != NULL ) - return m_hLaserDot->GetAbsOrigin(); - - //FIXME: The laser dot sprite is not active, this code should not be allowed! - assert(0); -#endif - return vec3_origin; -} - -//----------------------------------------------------------------------------- -// Purpose: NPC RPG users cheat and directly set the laser pointer's origin -// Input : &vecTarget - -//----------------------------------------------------------------------------- -void CWeaponRPG::UpdateNPCLaserPosition( const Vector &vecTarget ) -{ - -} - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void CWeaponRPG::SetNPCLaserPosition( const Vector &vecTarget ) -{ -} - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -const Vector &CWeaponRPG::GetNPCLaserPosition( void ) -{ - return vec3_origin; -} - -//----------------------------------------------------------------------------- -// Purpose: -// Output : Returns true if the rocket is being guided, false if it's dumb -//----------------------------------------------------------------------------- -bool CWeaponRPG::IsGuiding( void ) -{ - return m_bGuiding; -} - -//----------------------------------------------------------------------------- -// Purpose: -// Output : Returns true on success, false on failure. -//----------------------------------------------------------------------------- -bool CWeaponRPG::Deploy( void ) -{ - m_bInitialStateUpdate = true; - - return BaseClass::Deploy(); -} - -bool CWeaponRPG::CanHolster( void ) -{ - //Can't have an active missile out - if ( m_hMissile != NULL ) - return false; - - return BaseClass::CanHolster(); -} - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -bool CWeaponRPG::Holster( CBaseCombatWeapon *pSwitchingTo ) -{ - StopGuiding(); - - return BaseClass::Holster( pSwitchingTo ); -} - -//----------------------------------------------------------------------------- -// Purpose: Turn on the guiding laser -//----------------------------------------------------------------------------- -void CWeaponRPG::StartGuiding( void ) -{ - // Don't start back up if we're overriding this - if ( m_bHideGuiding ) - return; - - m_bGuiding = true; - -#ifndef CLIENT_DLL - WeaponSound(SPECIAL1); - - CreateLaserPointer(); -#endif - -} - -//----------------------------------------------------------------------------- -// Purpose: Turn off the guiding laser -//----------------------------------------------------------------------------- -void CWeaponRPG::StopGuiding( void ) -{ - m_bGuiding = false; - -#ifndef CLIENT_DLL - - WeaponSound( SPECIAL2 ); - - // Kill the dot completely - if ( m_hLaserDot != NULL ) - { - m_hLaserDot->TurnOff(); - UTIL_Remove( m_hLaserDot ); - m_hLaserDot = NULL; - } -#else - if ( m_pBeam ) - { - //Tell it to die right away and let the beam code free it. - m_pBeam->brightness = 0.0f; - m_pBeam->flags &= ~FBEAM_FOREVER; - m_pBeam->die = gpGlobals->curtime - 0.1; - m_pBeam = NULL; - } -#endif - -} - -//----------------------------------------------------------------------------- -// Purpose: Toggle the guiding laser -//----------------------------------------------------------------------------- -void CWeaponRPG::ToggleGuiding( void ) -{ - if ( IsGuiding() ) - { - StopGuiding(); - } - else - { - StartGuiding(); - } -} - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void CWeaponRPG::Drop( const Vector &vecVelocity ) -{ - StopGuiding(); - - BaseClass::Drop( vecVelocity ); -} - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void CWeaponRPG::UpdateLaserPosition( Vector vecMuzzlePos, Vector vecEndPos ) -{ - -#ifndef CLIENT_DLL - if ( vecMuzzlePos == vec3_origin || vecEndPos == vec3_origin ) - { - CBasePlayer *pPlayer = ToBasePlayer( GetOwner() ); - if ( !pPlayer ) - return; - - vecMuzzlePos = pPlayer->Weapon_ShootPosition(); - Vector forward; - pPlayer->EyeVectors( &forward ); - vecEndPos = vecMuzzlePos + ( forward * MAX_TRACE_LENGTH ); - } - - //Move the laser dot, if active - trace_t tr; - - // Trace out for the endpoint - UTIL_TraceLine( vecMuzzlePos, vecEndPos, (MASK_SHOT & ~CONTENTS_WINDOW), GetOwner(), COLLISION_GROUP_NONE, &tr ); - - // Move the laser sprite - if ( m_hLaserDot != NULL ) - { - Vector laserPos = tr.endpos; - m_hLaserDot->SetLaserPosition( laserPos, tr.plane.normal ); - - if ( tr.DidHitNonWorldEntity() ) - { - CBaseEntity *pHit = tr.m_pEnt; - - if ( ( pHit != NULL ) && ( pHit->m_takedamage ) ) - { - m_hLaserDot->SetTargetEntity( pHit ); - } - else - { - m_hLaserDot->SetTargetEntity( NULL ); - } - } - else - { - m_hLaserDot->SetTargetEntity( NULL ); - } - } -#endif -} - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void CWeaponRPG::CreateLaserPointer( void ) -{ -#ifndef CLIENT_DLL - if ( m_hLaserDot != NULL ) - return; - - CBaseCombatCharacter *pOwner = GetOwner(); - - if ( pOwner == NULL ) - return; - - if ( pOwner->GetAmmoCount(m_iPrimaryAmmoType) <= 0 ) - return; - - m_hLaserDot = CLaserDot::Create( GetAbsOrigin(), GetOwner() ); - m_hLaserDot->TurnOff(); - - UpdateLaserPosition(); -#endif -} - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void CWeaponRPG::NotifyRocketDied( void ) -{ - m_hMissile = NULL; - - if ( GetActivity() == ACT_VM_RELOAD ) - return; - - Reload(); -} - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -bool CWeaponRPG::Reload( void ) -{ - CBaseCombatCharacter *pOwner = GetOwner(); - - if ( pOwner == NULL ) - return false; - - if ( pOwner->GetAmmoCount(m_iPrimaryAmmoType) <= 0 ) - return false; - - WeaponSound( RELOAD ); - - SendWeaponAnim( ACT_VM_RELOAD ); - - return true; -} - -#ifdef CLIENT_DLL - -#define RPG_MUZZLE_ATTACHMENT 1 -#define RPG_GUIDE_ATTACHMENT 2 -#define RPG_GUIDE_TARGET_ATTACHMENT 3 - -#define RPG_GUIDE_ATTACHMENT_3RD 4 -#define RPG_GUIDE_TARGET_ATTACHMENT_3RD 5 - -#define RPG_LASER_BEAM_LENGTH 128 - -extern void FormatViewModelAttachment( Vector &vOrigin, bool bInverse ); - -//----------------------------------------------------------------------------- -// Purpose: Returns the attachment point on either the world or viewmodel -// This should really be worked into the CBaseCombatWeapon class! -//----------------------------------------------------------------------------- -void CWeaponRPG::GetWeaponAttachment( int attachmentId, Vector &outVector, Vector *dir /*= NULL*/ ) -{ - QAngle angles; - - if ( ShouldDrawUsingViewModel() ) - { - CBasePlayer *pOwner = ToBasePlayer( GetOwner() ); - - if ( pOwner != NULL ) - { - pOwner->GetViewModel()->GetAttachment( attachmentId, outVector, angles ); - ::FormatViewModelAttachment( outVector, true ); - } - } - else - { - // We offset the IDs to make them correct for our world model - BaseClass::GetAttachment( attachmentId, outVector, angles ); - } - - // Supply the direction, if requested - if ( dir != NULL ) - { - AngleVectors( angles, dir, NULL, NULL ); - } -} - -//----------------------------------------------------------------------------- -// Purpose: Setup our laser beam -//----------------------------------------------------------------------------- -void CWeaponRPG::InitBeam( void ) -{ - if ( m_pBeam != NULL ) - return; - - CBaseCombatCharacter *pOwner = GetOwner(); - - if ( pOwner == NULL ) - return; - - if ( pOwner->GetAmmoCount(m_iPrimaryAmmoType) <= 0 ) - return; - - - BeamInfo_t beamInfo; - - CBaseEntity *pEntity = NULL; - - if ( ShouldDrawUsingViewModel() ) - { - CBasePlayer *pOwner = ToBasePlayer( GetOwner() ); - - if ( pOwner != NULL ) - { - pEntity = pOwner->GetViewModel(); - } - } - else - { - pEntity = this; - } - - beamInfo.m_pStartEnt = pEntity; - beamInfo.m_pEndEnt = pEntity; - beamInfo.m_nType = TE_BEAMPOINTS; - beamInfo.m_vecStart = vec3_origin; - beamInfo.m_vecEnd = vec3_origin; - - beamInfo.m_pszModelName = ( ShouldDrawUsingViewModel() ) ? RPG_BEAM_SPRITE_NOZ : RPG_BEAM_SPRITE; - - beamInfo.m_flHaloScale = 0.0f; - beamInfo.m_flLife = 0.0f; - - if ( ShouldDrawUsingViewModel() ) - { - beamInfo.m_flWidth = 2.0f; - beamInfo.m_flEndWidth = 2.0f; - beamInfo.m_nStartAttachment = RPG_GUIDE_ATTACHMENT; - beamInfo.m_nEndAttachment = RPG_GUIDE_TARGET_ATTACHMENT; - } - else - { - beamInfo.m_flWidth = 1.0f; - beamInfo.m_flEndWidth = 1.0f; - beamInfo.m_nStartAttachment = RPG_GUIDE_ATTACHMENT_3RD; - beamInfo.m_nEndAttachment = RPG_GUIDE_TARGET_ATTACHMENT_3RD; - } - - beamInfo.m_flFadeLength = 0.0f; - beamInfo.m_flAmplitude = 0; - beamInfo.m_flBrightness = 255.0; - beamInfo.m_flSpeed = 1.0f; - beamInfo.m_nStartFrame = 0.0; - beamInfo.m_flFrameRate = 30.0; - beamInfo.m_flRed = 255.0; - beamInfo.m_flGreen = 0.0; - beamInfo.m_flBlue = 0.0; - beamInfo.m_nSegments = 4; - beamInfo.m_bRenderable = true; - beamInfo.m_nFlags = (FBEAM_FOREVER|FBEAM_SHADEOUT); - - m_pBeam = beams->CreateBeamEntPoint( beamInfo ); -} - -//----------------------------------------------------------------------------- -// Purpose: Draw effects for our weapon -//----------------------------------------------------------------------------- -void CWeaponRPG::DrawEffects( void ) -{ - // Must be guiding and not hidden - if ( !m_bGuiding || m_bHideGuiding ) - { - if ( m_pBeam != NULL ) - { - m_pBeam->brightness = 0; - } - - return; - } - - // Setup our sprite - if ( m_hSpriteMaterial == NULL ) - { - m_hSpriteMaterial.Init( RPG_LASER_SPRITE, TEXTURE_GROUP_CLIENT_EFFECTS ); - } - - // Setup our beam - if ( m_hBeamMaterial == NULL ) - { - m_hBeamMaterial.Init( RPG_BEAM_SPRITE, TEXTURE_GROUP_CLIENT_EFFECTS ); - } - - color32 color={255,255,255,255}; - Vector vecAttachment, vecDir; - QAngle angles; - - float scale = 8.0f + random->RandomFloat( -2.0f, 2.0f ); - - int attachmentID = ( ShouldDrawUsingViewModel() ) ? RPG_GUIDE_ATTACHMENT : RPG_GUIDE_ATTACHMENT_3RD; - - GetWeaponAttachment( attachmentID, vecAttachment, &vecDir ); - - // Draw the sprite - CMatRenderContextPtr pRenderContext( materials ); - pRenderContext->Bind( m_hSpriteMaterial, this ); - DrawSprite( vecAttachment, scale, scale, color ); - - // Get the beam's run - trace_t tr; - UTIL_TraceLine( vecAttachment, vecAttachment + ( vecDir * RPG_LASER_BEAM_LENGTH ), MASK_SHOT, GetOwner(), COLLISION_GROUP_NONE, &tr ); - - InitBeam(); - - if ( m_pBeam != NULL ) - { - m_pBeam->fadeLength = RPG_LASER_BEAM_LENGTH * tr.fraction; - m_pBeam->brightness = random->RandomInt( 128, 200 ); - } -} - -//----------------------------------------------------------------------------- -// Purpose: Called on third-person weapon drawing -//----------------------------------------------------------------------------- -int CWeaponRPG::DrawModel( int flags ) -{ - // Only render these on the transparent pass - if ( flags & STUDIO_TRANSPARENCY ) - { - DrawEffects(); - return 1; - } - - // Draw the model as normal - return BaseClass::DrawModel( flags ); -} - -//----------------------------------------------------------------------------- -// Purpose: Called after first-person viewmodel is drawn -//----------------------------------------------------------------------------- -void CWeaponRPG::ViewModelDrawn( C_BaseViewModel *pBaseViewModel ) -{ - // Draw our laser effects - DrawEffects(); - - BaseClass::ViewModelDrawn( pBaseViewModel ); -} - -//----------------------------------------------------------------------------- -// Purpose: Used to determine sorting of model when drawn -//----------------------------------------------------------------------------- -bool CWeaponRPG::IsTranslucent( void ) -{ - // Must be guiding and not hidden - if ( m_bGuiding && !m_bHideGuiding ) - return true; - - return false; -} - -//----------------------------------------------------------------------------- -// Purpose: Turns off effects when leaving the PVS -//----------------------------------------------------------------------------- -void CWeaponRPG::NotifyShouldTransmit( ShouldTransmitState_t state ) -{ - BaseClass::NotifyShouldTransmit(state); - - if ( state == SHOULDTRANSMIT_END ) - { - if ( m_pBeam != NULL ) - { - m_pBeam->brightness = 0.0f; - } - } -} - -#endif //CLIENT_DLL - - -//============================================================================= -// Laser Dot -//============================================================================= - -LINK_ENTITY_TO_CLASS( env_laserdot, CLaserDot ); - -BEGIN_DATADESC( CLaserDot ) - DEFINE_FIELD( m_vecSurfaceNormal, FIELD_VECTOR ), - DEFINE_FIELD( m_hTargetEnt, FIELD_EHANDLE ), - DEFINE_FIELD( m_bVisibleLaserDot, FIELD_BOOLEAN ), - DEFINE_FIELD( m_bIsOn, FIELD_BOOLEAN ), - - //DEFINE_FIELD( m_pNext, FIELD_CLASSPTR ), // don't save - regenerated by constructor -END_DATADESC() - - -//----------------------------------------------------------------------------- -// Finds missiles in cone -//----------------------------------------------------------------------------- -CBaseEntity *CreateLaserDot( const Vector &origin, CBaseEntity *pOwner, bool bVisibleDot ) -{ - return CLaserDot::Create( origin, pOwner, bVisibleDot ); -} - -void SetLaserDotTarget( CBaseEntity *pLaserDot, CBaseEntity *pTarget ) -{ - CLaserDot *pDot = assert_cast< CLaserDot* >(pLaserDot ); - pDot->SetTargetEntity( pTarget ); -} - -void EnableLaserDot( CBaseEntity *pLaserDot, bool bEnable ) -{ - CLaserDot *pDot = assert_cast< CLaserDot* >(pLaserDot ); - if ( bEnable ) - { - pDot->TurnOn(); - } - else - { - pDot->TurnOff(); - } -} - -CLaserDot::CLaserDot( void ) -{ - m_hTargetEnt = NULL; - m_bIsOn = true; -#ifndef CLIENT_DLL - g_LaserDotList.Insert( this ); -#endif -} - -CLaserDot::~CLaserDot( void ) -{ -#ifndef CLIENT_DLL - g_LaserDotList.Remove( this ); -#endif -} - - -//----------------------------------------------------------------------------- -// Purpose: -// Input : &origin - -// Output : CLaserDot -//----------------------------------------------------------------------------- -CLaserDot *CLaserDot::Create( const Vector &origin, CBaseEntity *pOwner, bool bVisibleDot ) -{ -#ifndef CLIENT_DLL - CLaserDot *pLaserDot = (CLaserDot *) CBaseEntity::Create( "env_laserdot", origin, QAngle(0,0,0) ); - - if ( pLaserDot == NULL ) - return NULL; - - pLaserDot->m_bVisibleLaserDot = bVisibleDot; - pLaserDot->SetMoveType( MOVETYPE_NONE ); - pLaserDot->AddSolidFlags( FSOLID_NOT_SOLID ); - pLaserDot->AddEffects( EF_NOSHADOW ); - UTIL_SetSize( pLaserDot, -Vector(4,4,4), Vector(4,4,4) ); - - pLaserDot->SetOwnerEntity( pOwner ); - - pLaserDot->AddEFlags( EFL_FORCE_CHECK_TRANSMIT ); - - if ( !bVisibleDot ) - { - pLaserDot->MakeInvisible(); - } - - return pLaserDot; -#else - return NULL; -#endif -} - -void CLaserDot::SetLaserPosition( const Vector &origin, const Vector &normal ) -{ - SetAbsOrigin( origin ); - m_vecSurfaceNormal = normal; -} - -Vector CLaserDot::GetChasePosition() -{ - return GetAbsOrigin() - m_vecSurfaceNormal * 10; -} - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void CLaserDot::TurnOn( void ) -{ - m_bIsOn = true; - if ( m_bVisibleLaserDot ) - { - //BaseClass::TurnOn(); - } -} - - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void CLaserDot::TurnOff( void ) -{ - m_bIsOn = false; - if ( m_bVisibleLaserDot ) - { - //BaseClass::TurnOff(); - } -} - - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void CLaserDot::MakeInvisible( void ) -{ -} - -#ifdef CLIENT_DLL - -//----------------------------------------------------------------------------- -// Purpose: Draw our sprite -//----------------------------------------------------------------------------- -int CLaserDot::DrawModel( int flags ) -{ - color32 color={255,255,255,255}; - Vector vecAttachment, vecDir; - QAngle angles; - - float scale; - Vector endPos; - - C_HL2MP_Player *pOwner = ToHL2MPPlayer( GetOwnerEntity() ); - - if ( pOwner != NULL && pOwner->IsDormant() == false ) - { - // Always draw the dot in front of our faces when in first-person - if ( pOwner->IsLocalPlayer() ) - { - // Take our view position and orientation - vecAttachment = CurrentViewOrigin(); - vecDir = CurrentViewForward(); - } - else - { - // Take the eye position and direction - vecAttachment = pOwner->EyePosition(); - - QAngle angles = pOwner->GetAnimEyeAngles(); - AngleVectors( angles, &vecDir ); - } - - trace_t tr; - UTIL_TraceLine( vecAttachment, vecAttachment + ( vecDir * MAX_TRACE_LENGTH ), MASK_SHOT, pOwner, COLLISION_GROUP_NONE, &tr ); - - // Backup off the hit plane - endPos = tr.endpos + ( tr.plane.normal * 4.0f ); - } - else - { - // Just use our position if we can't predict it otherwise - endPos = GetAbsOrigin(); - } - - // Randomly flutter - scale = 16.0f + random->RandomFloat( -4.0f, 4.0f ); - - // Draw our laser dot in space - CMatRenderContextPtr pRenderContext( materials ); - pRenderContext->Bind( m_hSpriteMaterial, this ); - DrawSprite( endPos, scale, scale, color ); - - return 1; -} - -//----------------------------------------------------------------------------- -// Purpose: Setup our sprite reference -//----------------------------------------------------------------------------- -void CLaserDot::OnDataChanged( DataUpdateType_t updateType ) -{ - if ( updateType == DATA_UPDATE_CREATED ) - { - m_hSpriteMaterial.Init( RPG_LASER_SPRITE, TEXTURE_GROUP_CLIENT_EFFECTS ); - } -} - -#endif //CLIENT_DLL diff --git a/sp/src/game/shared/hl2mp/weapon_rpg.h b/sp/src/game/shared/hl2mp/weapon_rpg.h deleted file mode 100644 index bbd6f2dd..00000000 --- a/sp/src/game/shared/hl2mp/weapon_rpg.h +++ /dev/null @@ -1,267 +0,0 @@ -//========= Copyright Valve Corporation, All rights reserved. ============// -// -// Purpose: -// -// $NoKeywords: $ -//=============================================================================// - -#ifndef WEAPON_RPG_H -#define WEAPON_RPG_H - -#ifdef _WIN32 -#pragma once -#endif - -#include "weapon_hl2mpbasehlmpcombatweapon.h" - -#ifdef CLIENT_DLL - - #include "iviewrender_beams.h" - -#endif - -#ifndef CLIENT_DLL -#include "Sprite.h" -#include "npcevent.h" -#include "beam_shared.h" - -class CWeaponRPG; -class CLaserDot; -class RocketTrail; - -//########################################################################### -// >> CMissile (missile launcher class is below this one!) -//########################################################################### -class CMissile : public CBaseCombatCharacter -{ - DECLARE_CLASS( CMissile, CBaseCombatCharacter ); - -public: - CMissile(); - ~CMissile(); - -#ifdef HL1_DLL - Class_T Classify( void ) { return CLASS_NONE; } -#else - Class_T Classify( void ) { return CLASS_MISSILE; } -#endif - - void Spawn( void ); - void Precache( void ); - void MissileTouch( CBaseEntity *pOther ); - void Explode( void ); - void ShotDown( void ); - void AccelerateThink( void ); - void AugerThink( void ); - void IgniteThink( void ); - void SeekThink( void ); - void DumbFire( void ); - void SetGracePeriod( float flGracePeriod ); - - int OnTakeDamage_Alive( const CTakeDamageInfo &info ); - void Event_Killed( const CTakeDamageInfo &info ); - - virtual float GetDamage() { return m_flDamage; } - virtual void SetDamage(float flDamage) { m_flDamage = flDamage; } - - unsigned int PhysicsSolidMaskForEntity( void ) const; - - CHandle m_hOwner; - - static CMissile *Create( const Vector &vecOrigin, const QAngle &vecAngles, edict_t *pentOwner ); - -protected: - virtual void DoExplosion(); - virtual void ComputeActualDotPosition( CLaserDot *pLaserDot, Vector *pActualDotPosition, float *pHomingSpeed ); - virtual int AugerHealth() { return m_iMaxHealth - 20; } - - // Creates the smoke trail - void CreateSmokeTrail( void ); - - // Gets the shooting position - void GetShootPosition( CLaserDot *pLaserDot, Vector *pShootPosition ); - - CHandle m_hRocketTrail; - float m_flAugerTime; // Amount of time to auger before blowing up anyway - float m_flMarkDeadTime; - float m_flDamage; - -private: - float m_flGracePeriodEndsAt; - - DECLARE_DATADESC(); -}; - - -//----------------------------------------------------------------------------- -// Laser dot control -//----------------------------------------------------------------------------- -CBaseEntity *CreateLaserDot( const Vector &origin, CBaseEntity *pOwner, bool bVisibleDot ); -void SetLaserDotTarget( CBaseEntity *pLaserDot, CBaseEntity *pTarget ); -void EnableLaserDot( CBaseEntity *pLaserDot, bool bEnable ); - - -//----------------------------------------------------------------------------- -// Specialized mizzizzile -//----------------------------------------------------------------------------- -class CAPCMissile : public CMissile -{ - DECLARE_CLASS( CMissile, CMissile ); - DECLARE_DATADESC(); - -public: - static CAPCMissile *Create( const Vector &vecOrigin, const QAngle &vecAngles, const Vector &vecVelocity, CBaseEntity *pOwner ); - - CAPCMissile(); - ~CAPCMissile(); - void IgniteDelay( void ); - void AugerDelay( float flDelayTime ); - void ExplodeDelay( float flDelayTime ); - void DisableGuiding(); -#if defined( HL2_DLL ) - virtual Class_T Classify ( void ) { return CLASS_COMBINE; } -#endif - - void AimAtSpecificTarget( CBaseEntity *pTarget ); - void SetGuidanceHint( const char *pHintName ); - - CAPCMissile *m_pNext; - -protected: - virtual void DoExplosion(); - virtual void ComputeActualDotPosition( CLaserDot *pLaserDot, Vector *pActualDotPosition, float *pHomingSpeed ); - virtual int AugerHealth(); - -private: - void Init(); - void ComputeLeadingPosition( const Vector &vecShootPosition, CBaseEntity *pTarget, Vector *pLeadPosition ); - void BeginSeekThink(); - void AugerStartThink(); - void ExplodeThink(); - void APCMissileTouch( CBaseEntity *pOther ); - - float m_flReachedTargetTime; - float m_flIgnitionTime; - bool m_bGuidingDisabled; - float m_flLastHomingSpeed; - EHANDLE m_hSpecificTarget; - string_t m_strHint; -}; - - -//----------------------------------------------------------------------------- -// Finds apc missiles in cone -//----------------------------------------------------------------------------- -CAPCMissile *FindAPCMissileInCone( const Vector &vecOrigin, const Vector &vecDirection, float flAngle ); - -#endif - -//----------------------------------------------------------------------------- -// RPG -//----------------------------------------------------------------------------- - -#ifdef CLIENT_DLL -#define CWeaponRPG C_WeaponRPG -#endif - -class CWeaponRPG : public CBaseHL2MPCombatWeapon -{ - DECLARE_CLASS( CWeaponRPG, CBaseHL2MPCombatWeapon ); -public: - - CWeaponRPG(); - ~CWeaponRPG(); - - DECLARE_NETWORKCLASS(); - DECLARE_PREDICTABLE(); - - void Precache( void ); - - void PrimaryAttack( void ); - virtual float GetFireRate( void ) { return 1; }; - void ItemPostFrame( void ); - - void Activate( void ); - void DecrementAmmo( CBaseCombatCharacter *pOwner ); - - bool Deploy( void ); - bool Holster( CBaseCombatWeapon *pSwitchingTo = NULL ); - bool Reload( void ); - bool WeaponShouldBeLowered( void ); - bool Lower( void ); - - bool CanHolster( void ); - - virtual void Drop( const Vector &vecVelocity ); - - int GetMinBurst() { return 1; } - int GetMaxBurst() { return 1; } - float GetMinRestTime() { return 4.0; } - float GetMaxRestTime() { return 4.0; } - - void StartGuiding( void ); - void StopGuiding( void ); - void ToggleGuiding( void ); - bool IsGuiding( void ); - - void NotifyRocketDied( void ); - - bool HasAnyAmmo( void ); - - void SuppressGuiding( bool state = true ); - - void CreateLaserPointer( void ); - void UpdateLaserPosition( Vector vecMuzzlePos = vec3_origin, Vector vecEndPos = vec3_origin ); - Vector GetLaserPosition( void ); - - // NPC RPG users cheat and directly set the laser pointer's origin - void UpdateNPCLaserPosition( const Vector &vecTarget ); - void SetNPCLaserPosition( const Vector &vecTarget ); - const Vector &GetNPCLaserPosition( void ); - -#ifdef CLIENT_DLL - - // We need to render opaque and translucent pieces - virtual RenderGroup_t GetRenderGroup( void ) { return RENDER_GROUP_TWOPASS; } - - virtual void NotifyShouldTransmit( ShouldTransmitState_t state ); - virtual int DrawModel( int flags ); - virtual void ViewModelDrawn( C_BaseViewModel *pBaseViewModel ); - virtual bool IsTranslucent( void ); - - void InitBeam( void ); - void GetWeaponAttachment( int attachmentId, Vector &outVector, Vector *dir = NULL ); - void DrawEffects( void ); -// void DrawLaserDot( void ); - - CMaterialReference m_hSpriteMaterial; // Used for the laser glint - CMaterialReference m_hBeamMaterial; // Used for the laser beam - Beam_t *m_pBeam; // Laser beam temp entity - -#endif //CLIENT_DLL - - CBaseEntity *GetMissile( void ) { return m_hMissile; } - -#ifndef CLIENT_DLL - DECLARE_ACTTABLE(); -#endif - -protected: - - CNetworkVar( bool, m_bInitialStateUpdate ); - CNetworkVar( bool, m_bGuiding ); - CNetworkVar( bool, m_bHideGuiding ); - - CNetworkHandle( CBaseEntity, m_hMissile ); - CNetworkVar( Vector, m_vecLaserDot ); - -#ifndef CLIENT_DLL - CHandle m_hLaserDot; -#endif - -private: - - CWeaponRPG( const CWeaponRPG & ); -}; - -#endif // WEAPON_RPG_H diff --git a/sp/src/game/shared/hl2mp/weapon_shotgun.cpp b/sp/src/game/shared/hl2mp/weapon_shotgun.cpp deleted file mode 100644 index da370b53..00000000 --- a/sp/src/game/shared/hl2mp/weapon_shotgun.cpp +++ /dev/null @@ -1,634 +0,0 @@ -//========= Copyright Valve Corporation, All rights reserved. ============// -// -// Purpose: -// -//=============================================================================// - -#include "cbase.h" -#include "npcevent.h" -#include "in_buttons.h" - -#ifdef CLIENT_DLL - #include "c_hl2mp_player.h" -#else - #include "hl2mp_player.h" -#endif - -#include "weapon_hl2mpbasehlmpcombatweapon.h" - -#ifdef CLIENT_DLL -#define CWeaponShotgun C_WeaponShotgun -#endif - -extern ConVar sk_auto_reload_time; -extern ConVar sk_plr_num_shotgun_pellets; - -class CWeaponShotgun : public CBaseHL2MPCombatWeapon -{ -public: - DECLARE_CLASS( CWeaponShotgun, CBaseHL2MPCombatWeapon ); - - DECLARE_NETWORKCLASS(); - DECLARE_PREDICTABLE(); - -private: - CNetworkVar( bool, m_bNeedPump ); // When emptied completely - CNetworkVar( bool, m_bDelayedFire1 ); // Fire primary when finished reloading - CNetworkVar( bool, m_bDelayedFire2 ); // Fire secondary when finished reloading - CNetworkVar( bool, m_bDelayedReload ); // Reload when finished pump - -public: - virtual const Vector& GetBulletSpread( void ) - { - static Vector cone = VECTOR_CONE_10DEGREES; - return cone; - } - - virtual int GetMinBurst() { return 1; } - virtual int GetMaxBurst() { return 3; } - - bool StartReload( void ); - bool Reload( void ); - void FillClip( void ); - void FinishReload( void ); - void CheckHolsterReload( void ); - void Pump( void ); -// void WeaponIdle( void ); - void ItemHolsterFrame( void ); - void ItemPostFrame( void ); - void PrimaryAttack( void ); - void SecondaryAttack( void ); - void DryFire( void ); - virtual float GetFireRate( void ) { return 0.7; }; - -#ifndef CLIENT_DLL - DECLARE_ACTTABLE(); -#endif - - CWeaponShotgun(void); - -private: - CWeaponShotgun( const CWeaponShotgun & ); -}; - -IMPLEMENT_NETWORKCLASS_ALIASED( WeaponShotgun, DT_WeaponShotgun ) - -BEGIN_NETWORK_TABLE( CWeaponShotgun, DT_WeaponShotgun ) -#ifdef CLIENT_DLL - RecvPropBool( RECVINFO( m_bNeedPump ) ), - RecvPropBool( RECVINFO( m_bDelayedFire1 ) ), - RecvPropBool( RECVINFO( m_bDelayedFire2 ) ), - RecvPropBool( RECVINFO( m_bDelayedReload ) ), -#else - SendPropBool( SENDINFO( m_bNeedPump ) ), - SendPropBool( SENDINFO( m_bDelayedFire1 ) ), - SendPropBool( SENDINFO( m_bDelayedFire2 ) ), - SendPropBool( SENDINFO( m_bDelayedReload ) ), -#endif -END_NETWORK_TABLE() - -#ifdef CLIENT_DLL -BEGIN_PREDICTION_DATA( CWeaponShotgun ) - DEFINE_PRED_FIELD( m_bNeedPump, FIELD_BOOLEAN, FTYPEDESC_INSENDTABLE ), - DEFINE_PRED_FIELD( m_bDelayedFire1, FIELD_BOOLEAN, FTYPEDESC_INSENDTABLE ), - DEFINE_PRED_FIELD( m_bDelayedFire2, FIELD_BOOLEAN, FTYPEDESC_INSENDTABLE ), - DEFINE_PRED_FIELD( m_bDelayedReload, FIELD_BOOLEAN, FTYPEDESC_INSENDTABLE ), -END_PREDICTION_DATA() -#endif - -LINK_ENTITY_TO_CLASS( weapon_shotgun, CWeaponShotgun ); -PRECACHE_WEAPON_REGISTER(weapon_shotgun); - -#ifndef CLIENT_DLL -acttable_t CWeaponShotgun::m_acttable[] = -{ - { ACT_HL2MP_IDLE, ACT_HL2MP_IDLE_SHOTGUN, false }, - { ACT_HL2MP_RUN, ACT_HL2MP_RUN_SHOTGUN, false }, - { ACT_HL2MP_IDLE_CROUCH, ACT_HL2MP_IDLE_CROUCH_SHOTGUN, false }, - { ACT_HL2MP_WALK_CROUCH, ACT_HL2MP_WALK_CROUCH_SHOTGUN, false }, - { ACT_HL2MP_GESTURE_RANGE_ATTACK, ACT_HL2MP_GESTURE_RANGE_ATTACK_SHOTGUN, false }, - { ACT_HL2MP_GESTURE_RELOAD, ACT_HL2MP_GESTURE_RELOAD_SHOTGUN, false }, - { ACT_HL2MP_JUMP, ACT_HL2MP_JUMP_SHOTGUN, false }, - { ACT_RANGE_ATTACK1, ACT_RANGE_ATTACK_SHOTGUN, false }, -}; - -IMPLEMENT_ACTTABLE(CWeaponShotgun); - -#endif - - -//----------------------------------------------------------------------------- -// Purpose: Override so only reload one shell at a time -// Input : -// Output : -//----------------------------------------------------------------------------- -bool CWeaponShotgun::StartReload( void ) -{ - if ( m_bNeedPump ) - return false; - - CBaseCombatCharacter *pOwner = GetOwner(); - - if ( pOwner == NULL ) - return false; - - if (pOwner->GetAmmoCount(m_iPrimaryAmmoType) <= 0) - return false; - - if (m_iClip1 >= GetMaxClip1()) - return false; - - - int j = MIN(1, pOwner->GetAmmoCount(m_iPrimaryAmmoType)); - - if (j <= 0) - return false; - - SendWeaponAnim( ACT_SHOTGUN_RELOAD_START ); - - // Make shotgun shell visible - SetBodygroup(1,0); - - pOwner->m_flNextAttack = gpGlobals->curtime; - m_flNextPrimaryAttack = gpGlobals->curtime + SequenceDuration(); - - m_bInReload = true; - return true; -} - -//----------------------------------------------------------------------------- -// Purpose: Override so only reload one shell at a time -// Input : -// Output : -//----------------------------------------------------------------------------- -bool CWeaponShotgun::Reload( void ) -{ - // Check that StartReload was called first - if (!m_bInReload) - { - Warning("ERROR: Shotgun Reload called incorrectly!\n"); - } - - CBaseCombatCharacter *pOwner = GetOwner(); - - if ( pOwner == NULL ) - return false; - - if (pOwner->GetAmmoCount(m_iPrimaryAmmoType) <= 0) - return false; - - if (m_iClip1 >= GetMaxClip1()) - return false; - - int j = MIN(1, pOwner->GetAmmoCount(m_iPrimaryAmmoType)); - - if (j <= 0) - return false; - - FillClip(); - // Play reload on different channel as otherwise steals channel away from fire sound - WeaponSound(RELOAD); - SendWeaponAnim( ACT_VM_RELOAD ); - - pOwner->m_flNextAttack = gpGlobals->curtime; - m_flNextPrimaryAttack = gpGlobals->curtime + SequenceDuration(); - - return true; -} - -//----------------------------------------------------------------------------- -// Purpose: Play finish reload anim and fill clip -// Input : -// Output : -//----------------------------------------------------------------------------- -void CWeaponShotgun::FinishReload( void ) -{ - // Make shotgun shell invisible - SetBodygroup(1,1); - - CBaseCombatCharacter *pOwner = GetOwner(); - - if ( pOwner == NULL ) - return; - - m_bInReload = false; - - // Finish reload animation - SendWeaponAnim( ACT_SHOTGUN_RELOAD_FINISH ); - - pOwner->m_flNextAttack = gpGlobals->curtime; - m_flNextPrimaryAttack = gpGlobals->curtime + SequenceDuration(); -} - -//----------------------------------------------------------------------------- -// Purpose: Play finish reload anim and fill clip -// Input : -// Output : -//----------------------------------------------------------------------------- -void CWeaponShotgun::FillClip( void ) -{ - CBaseCombatCharacter *pOwner = GetOwner(); - - if ( pOwner == NULL ) - return; - - // Add them to the clip - if ( pOwner->GetAmmoCount( m_iPrimaryAmmoType ) > 0 ) - { - if ( Clip1() < GetMaxClip1() ) - { - m_iClip1++; - pOwner->RemoveAmmo( 1, m_iPrimaryAmmoType ); - } - } -} - -//----------------------------------------------------------------------------- -// Purpose: Play weapon pump anim -// Input : -// Output : -//----------------------------------------------------------------------------- -void CWeaponShotgun::Pump( void ) -{ - CBaseCombatCharacter *pOwner = GetOwner(); - - if ( pOwner == NULL ) - return; - - m_bNeedPump = false; - - if ( m_bDelayedReload ) - { - m_bDelayedReload = false; - StartReload(); - } - - WeaponSound( SPECIAL1 ); - - // Finish reload animation - SendWeaponAnim( ACT_SHOTGUN_PUMP ); - - pOwner->m_flNextAttack = gpGlobals->curtime + SequenceDuration(); - m_flNextPrimaryAttack = gpGlobals->curtime + SequenceDuration(); -} - -//----------------------------------------------------------------------------- -// Purpose: -// -// -//----------------------------------------------------------------------------- -void CWeaponShotgun::DryFire( void ) -{ - WeaponSound(EMPTY); - SendWeaponAnim( ACT_VM_DRYFIRE ); - - m_flNextPrimaryAttack = gpGlobals->curtime + SequenceDuration(); -} - -//----------------------------------------------------------------------------- -// Purpose: -// -// -//----------------------------------------------------------------------------- -void CWeaponShotgun::PrimaryAttack( void ) -{ - // Only the player fires this way so we can cast - CBasePlayer *pPlayer = ToBasePlayer( GetOwner() ); - - if (!pPlayer) - { - return; - } - - // MUST call sound before removing a round from the clip of a CMachineGun - WeaponSound(SINGLE); - - pPlayer->DoMuzzleFlash(); - - SendWeaponAnim( ACT_VM_PRIMARYATTACK ); - - // Don't fire again until fire animation has completed - m_flNextPrimaryAttack = gpGlobals->curtime + SequenceDuration(); - m_iClip1 -= 1; - - // player "shoot" animation - pPlayer->SetAnimation( PLAYER_ATTACK1 ); - - Vector vecSrc = pPlayer->Weapon_ShootPosition( ); - Vector vecAiming = pPlayer->GetAutoaimVector( AUTOAIM_10DEGREES ); - - FireBulletsInfo_t info( 7, vecSrc, vecAiming, GetBulletSpread(), MAX_TRACE_LENGTH, m_iPrimaryAmmoType ); - info.m_pAttacker = pPlayer; - - // Fire the bullets, and force the first shot to be perfectly accuracy - pPlayer->FireBullets( info ); - - QAngle punch; - punch.Init( SharedRandomFloat( "shotgunpax", -2, -1 ), SharedRandomFloat( "shotgunpay", -2, 2 ), 0 ); - pPlayer->ViewPunch( punch ); - - if (!m_iClip1 && pPlayer->GetAmmoCount(m_iPrimaryAmmoType) <= 0) - { - // HEV suit - indicate out of ammo condition - pPlayer->SetSuitUpdate("!HEV_AMO0", FALSE, 0); - } - - m_bNeedPump = true; -} - -//----------------------------------------------------------------------------- -// Purpose: -// -// -//----------------------------------------------------------------------------- -void CWeaponShotgun::SecondaryAttack( void ) -{ - // Only the player fires this way so we can cast - CBasePlayer *pPlayer = ToBasePlayer( GetOwner() ); - - if (!pPlayer) - { - return; - } - - pPlayer->m_nButtons &= ~IN_ATTACK2; - // MUST call sound before removing a round from the clip of a CMachineGun - WeaponSound(WPN_DOUBLE); - - pPlayer->DoMuzzleFlash(); - - SendWeaponAnim( ACT_VM_SECONDARYATTACK ); - - // Don't fire again until fire animation has completed - m_flNextPrimaryAttack = gpGlobals->curtime + SequenceDuration(); - m_iClip1 -= 2; // Shotgun uses same clip for primary and secondary attacks - - // player "shoot" animation - pPlayer->SetAnimation( PLAYER_ATTACK1 ); - - Vector vecSrc = pPlayer->Weapon_ShootPosition(); - Vector vecAiming = pPlayer->GetAutoaimVector( AUTOAIM_10DEGREES ); - - FireBulletsInfo_t info( 12, vecSrc, vecAiming, GetBulletSpread(), MAX_TRACE_LENGTH, m_iPrimaryAmmoType ); - info.m_pAttacker = pPlayer; - - // Fire the bullets, and force the first shot to be perfectly accuracy - pPlayer->FireBullets( info ); - pPlayer->ViewPunch( QAngle(SharedRandomFloat( "shotgunsax", -5, 5 ),0,0) ); - - if (!m_iClip1 && pPlayer->GetAmmoCount(m_iPrimaryAmmoType) <= 0) - { - // HEV suit - indicate out of ammo condition - pPlayer->SetSuitUpdate("!HEV_AMO0", FALSE, 0); - } - - m_bNeedPump = true; -} - -//----------------------------------------------------------------------------- -// Purpose: Override so shotgun can do mulitple reloads in a row -//----------------------------------------------------------------------------- -void CWeaponShotgun::ItemPostFrame( void ) -{ - CBasePlayer *pOwner = ToBasePlayer( GetOwner() ); - if (!pOwner) - { - return; - } - - if ( m_bNeedPump && ( pOwner->m_nButtons & IN_RELOAD ) ) - { - m_bDelayedReload = true; - } - - if (m_bInReload) - { - // If I'm primary firing and have one round stop reloading and fire - if ((pOwner->m_nButtons & IN_ATTACK ) && (m_iClip1 >=1) && !m_bNeedPump ) - { - m_bInReload = false; - m_bNeedPump = false; - m_bDelayedFire1 = true; - } - // If I'm secondary firing and have two rounds stop reloading and fire - else if ((pOwner->m_nButtons & IN_ATTACK2 ) && (m_iClip1 >=2) && !m_bNeedPump ) - { - m_bInReload = false; - m_bNeedPump = false; - m_bDelayedFire2 = true; - } - else if (m_flNextPrimaryAttack <= gpGlobals->curtime) - { - // If out of ammo end reload - if (pOwner->GetAmmoCount(m_iPrimaryAmmoType) <=0) - { - FinishReload(); - return; - } - // If clip not full reload again - if (m_iClip1 < GetMaxClip1()) - { - Reload(); - return; - } - // Clip full, stop reloading - else - { - FinishReload(); - return; - } - } - } - else - { - // Make shotgun shell invisible - SetBodygroup(1,1); - } - - if ((m_bNeedPump) && (m_flNextPrimaryAttack <= gpGlobals->curtime)) - { - Pump(); - return; - } - - // Shotgun uses same timing and ammo for secondary attack - if ((m_bDelayedFire2 || pOwner->m_nButtons & IN_ATTACK2)&&(m_flNextPrimaryAttack <= gpGlobals->curtime)) - { - m_bDelayedFire2 = false; - - if ( (m_iClip1 <= 1 && UsesClipsForAmmo1())) - { - // If only one shell is left, do a single shot instead - if ( m_iClip1 == 1 ) - { - PrimaryAttack(); - } - else if (!pOwner->GetAmmoCount(m_iPrimaryAmmoType)) - { - DryFire(); - } - else - { - StartReload(); - } - } - - // Fire underwater? - else if (GetOwner()->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 ( pOwner->m_afButtonPressed & IN_ATTACK ) - { - m_flNextPrimaryAttack = gpGlobals->curtime; - } - SecondaryAttack(); - } - } - else if ( (m_bDelayedFire1 || pOwner->m_nButtons & IN_ATTACK) && m_flNextPrimaryAttack <= gpGlobals->curtime) - { - m_bDelayedFire1 = false; - if ( (m_iClip1 <= 0 && UsesClipsForAmmo1()) || ( !UsesClipsForAmmo1() && !pOwner->GetAmmoCount(m_iPrimaryAmmoType) ) ) - { - if (!pOwner->GetAmmoCount(m_iPrimaryAmmoType)) - { - DryFire(); - } - else - { - StartReload(); - } - } - // Fire underwater? - else if (pOwner->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 - CBasePlayer *pPlayer = ToBasePlayer( GetOwner() ); - if ( pPlayer && pPlayer->m_afButtonPressed & IN_ATTACK ) - { - m_flNextPrimaryAttack = gpGlobals->curtime; - } - PrimaryAttack(); - } - } - - if ( pOwner->m_nButtons & IN_RELOAD && UsesClipsForAmmo1() && !m_bInReload ) - { - // reload when reload is pressed, or if no buttons are down and weapon is empty. - StartReload(); - } - else - { - // no fire buttons down - m_bFireOnEmpty = false; - - if ( !HasAnyAmmo() && m_flNextPrimaryAttack < gpGlobals->curtime ) - { - // weapon isn't useable, switch. - if ( !(GetWeaponFlags() & ITEM_FLAG_NOAUTOSWITCHEMPTY) && pOwner->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 ) - { - if (StartReload()) - { - // if we've successfully started to reload, we're done - return; - } - } - } - - WeaponIdle( ); - return; - } - -} - - - -//----------------------------------------------------------------------------- -// Purpose: Constructor -//----------------------------------------------------------------------------- -CWeaponShotgun::CWeaponShotgun( void ) -{ - m_bReloadsSingly = true; - - m_bNeedPump = false; - m_bDelayedFire1 = false; - m_bDelayedFire2 = false; - - m_fMinRange1 = 0.0; - m_fMaxRange1 = 500; - m_fMinRange2 = 0.0; - m_fMaxRange2 = 200; -} - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void CWeaponShotgun::ItemHolsterFrame( void ) -{ - // Must be player held - if ( GetOwner() && GetOwner()->IsPlayer() == false ) - return; - - // We can't be active - if ( GetOwner()->GetActiveWeapon() == this ) - return; - - // If it's been longer than three seconds, reload - if ( ( gpGlobals->curtime - m_flHolsterTime ) > sk_auto_reload_time.GetFloat() ) - { - // Reset the timer - m_flHolsterTime = gpGlobals->curtime; - - if ( GetOwner() == NULL ) - return; - - if ( m_iClip1 == GetMaxClip1() ) - return; - - // Just load the clip with no animations - int ammoFill = MIN( (GetMaxClip1() - m_iClip1), GetOwner()->GetAmmoCount( GetPrimaryAmmoType() ) ); - - GetOwner()->RemoveAmmo( ammoFill, GetPrimaryAmmoType() ); - m_iClip1 += ammoFill; - } -} - -//================================================== -// Purpose: -//================================================== -/* -void CWeaponShotgun::WeaponIdle( void ) -{ - //Only the player fires this way so we can cast - CBasePlayer *pPlayer = GetOwner() - - if ( pPlayer == NULL ) - return; - - //If we're on a target, play the new anim - if ( pPlayer->IsOnTarget() ) - { - SendWeaponAnim( ACT_VM_IDLE_ACTIVE ); - } -} -*/ diff --git a/sp/src/game/shared/hl2mp/weapon_slam.cpp b/sp/src/game/shared/hl2mp/weapon_slam.cpp deleted file mode 100644 index bcdec40c..00000000 --- a/sp/src/game/shared/hl2mp/weapon_slam.cpp +++ /dev/null @@ -1,1052 +0,0 @@ -//========= Copyright Valve Corporation, All rights reserved. ============// -// -// Purpose: -// -//=============================================================================// - -#include "cbase.h" -#include "gamerules.h" -#include "npcevent.h" -#include "in_buttons.h" -#include "engine/IEngineSound.h" - -#if defined( CLIENT_DLL ) - #include "c_hl2mp_player.h" -#else - #include "hl2mp_player.h" - #include "grenade_tripmine.h" - #include "grenade_satchel.h" - #include "entitylist.h" - #include "eventqueue.h" -#endif - -#include "hl2mp/weapon_slam.h" - -// memdbgon must be the last include file in a .cpp file!!! -#include "tier0/memdbgon.h" - -#define SLAM_PRIMARY_VOLUME 450 - -IMPLEMENT_NETWORKCLASS_ALIASED( Weapon_SLAM, DT_Weapon_SLAM ) - -BEGIN_NETWORK_TABLE( CWeapon_SLAM, DT_Weapon_SLAM ) -#ifdef CLIENT_DLL - RecvPropInt( RECVINFO( m_tSlamState ) ), - RecvPropBool( RECVINFO( m_bDetonatorArmed ) ), - RecvPropBool( RECVINFO( m_bNeedDetonatorDraw ) ), - RecvPropBool( RECVINFO( m_bNeedDetonatorHolster ) ), - RecvPropBool( RECVINFO( m_bNeedReload ) ), - RecvPropBool( RECVINFO( m_bClearReload ) ), - RecvPropBool( RECVINFO( m_bThrowSatchel ) ), - RecvPropBool( RECVINFO( m_bAttachSatchel ) ), - RecvPropBool( RECVINFO( m_bAttachTripmine ) ), -#else - SendPropInt( SENDINFO( m_tSlamState ) ), - SendPropBool( SENDINFO( m_bDetonatorArmed ) ), - SendPropBool( SENDINFO( m_bNeedDetonatorDraw ) ), - SendPropBool( SENDINFO( m_bNeedDetonatorHolster ) ), - SendPropBool( SENDINFO( m_bNeedReload ) ), - SendPropBool( SENDINFO( m_bClearReload ) ), - SendPropBool( SENDINFO( m_bThrowSatchel ) ), - SendPropBool( SENDINFO( m_bAttachSatchel ) ), - SendPropBool( SENDINFO( m_bAttachTripmine ) ), -#endif -END_NETWORK_TABLE() - -#ifdef CLIENT_DLL - -BEGIN_PREDICTION_DATA( CWeapon_SLAM ) - DEFINE_PRED_FIELD( m_tSlamState, FIELD_INTEGER, FTYPEDESC_INSENDTABLE ), - DEFINE_PRED_FIELD( m_bDetonatorArmed, FIELD_BOOLEAN, FTYPEDESC_INSENDTABLE ), - DEFINE_PRED_FIELD( m_bNeedDetonatorDraw, FIELD_BOOLEAN, FTYPEDESC_INSENDTABLE ), - DEFINE_PRED_FIELD( m_bNeedDetonatorHolster, FIELD_BOOLEAN, FTYPEDESC_INSENDTABLE ), - DEFINE_PRED_FIELD( m_bNeedReload, FIELD_BOOLEAN, FTYPEDESC_INSENDTABLE ), - DEFINE_PRED_FIELD( m_bClearReload, FIELD_BOOLEAN, FTYPEDESC_INSENDTABLE ), - DEFINE_PRED_FIELD( m_bThrowSatchel, FIELD_BOOLEAN, FTYPEDESC_INSENDTABLE ), - DEFINE_PRED_FIELD( m_bAttachSatchel, FIELD_BOOLEAN, FTYPEDESC_INSENDTABLE ), - DEFINE_PRED_FIELD( m_bAttachTripmine, FIELD_BOOLEAN, FTYPEDESC_INSENDTABLE ), -END_PREDICTION_DATA() - -#endif - -LINK_ENTITY_TO_CLASS( weapon_slam, CWeapon_SLAM ); -PRECACHE_WEAPON_REGISTER(weapon_slam); - -#ifndef CLIENT_DLL - -BEGIN_DATADESC( CWeapon_SLAM ) - - DEFINE_FIELD( m_tSlamState, FIELD_INTEGER ), - DEFINE_FIELD( m_bDetonatorArmed, FIELD_BOOLEAN ), - DEFINE_FIELD( m_bNeedDetonatorDraw, FIELD_BOOLEAN ), - DEFINE_FIELD( m_bNeedDetonatorHolster, FIELD_BOOLEAN ), - DEFINE_FIELD( m_bNeedReload, FIELD_BOOLEAN ), - DEFINE_FIELD( m_bClearReload, FIELD_BOOLEAN ), - DEFINE_FIELD( m_bThrowSatchel, FIELD_BOOLEAN ), - DEFINE_FIELD( m_bAttachSatchel, FIELD_BOOLEAN ), - DEFINE_FIELD( m_bAttachTripmine, FIELD_BOOLEAN ), - DEFINE_FIELD( m_flWallSwitchTime, FIELD_TIME ), - - // Function Pointers - DEFINE_FUNCTION( SlamTouch ), - -END_DATADESC() - -acttable_t CWeapon_SLAM::m_acttable[] = -{ - { ACT_RANGE_ATTACK1, ACT_RANGE_ATTACK_SLAM, true }, - { ACT_HL2MP_IDLE, ACT_HL2MP_IDLE_SLAM, false }, - { ACT_HL2MP_RUN, ACT_HL2MP_RUN_SLAM, false }, - { ACT_HL2MP_IDLE_CROUCH, ACT_HL2MP_IDLE_CROUCH_SLAM, false }, - { ACT_HL2MP_WALK_CROUCH, ACT_HL2MP_WALK_CROUCH_SLAM, false }, - { ACT_HL2MP_GESTURE_RANGE_ATTACK, ACT_HL2MP_GESTURE_RANGE_ATTACK_SLAM, false }, - { ACT_HL2MP_GESTURE_RELOAD, ACT_HL2MP_GESTURE_RELOAD_SLAM, false }, - { ACT_HL2MP_JUMP, ACT_HL2MP_JUMP_SLAM, false }, -}; - -IMPLEMENT_ACTTABLE(CWeapon_SLAM); -#endif - - -void CWeapon_SLAM::Spawn( ) -{ - BaseClass::Spawn(); - - Precache( ); - - FallInit();// get ready to fall down - - m_tSlamState = (int)SLAM_SATCHEL_THROW; - m_flWallSwitchTime = 0; - - // Give 1 piece of default ammo when first picked up - m_iClip2 = 1; -} - -void CWeapon_SLAM::Precache( void ) -{ - BaseClass::Precache(); - -#ifndef CLIENT_DLL - UTIL_PrecacheOther( "npc_tripmine" ); - UTIL_PrecacheOther( "npc_satchel" ); -#endif - - PrecacheScriptSound( "Weapon_SLAM.TripMineMode" ); - PrecacheScriptSound( "Weapon_SLAM.SatchelDetonate" ); - PrecacheScriptSound( "Weapon_SLAM.SatchelThrow" ); -} - -//------------------------------------------------------------------------------ -// Purpose : Override to use slam's pickup touch function -// Input : -// Output : -//------------------------------------------------------------------------------ -void CWeapon_SLAM::SetPickupTouch( void ) -{ - SetTouch(&CWeapon_SLAM::SlamTouch); -} - -//----------------------------------------------------------------------------- -// Purpose: Override so give correct ammo -// Input : pOther - the entity that touched me -// Output : -//----------------------------------------------------------------------------- -void CWeapon_SLAM::SlamTouch( CBaseEntity *pOther ) -{ -#ifdef GAME_DLL - CBaseCombatCharacter* pBCC = ToBaseCombatCharacter( pOther ); - - // Can I even pick stuff up? - if ( pBCC && !pBCC->IsAllowedToPickupWeapons() ) - return; -#endif - - // --------------------------------------------------- - // First give weapon to touching entity if allowed - // --------------------------------------------------- - BaseClass::DefaultTouch(pOther); -} - -//------------------------------------------------------------------------------ -// Purpose : -// Input : -// Output : -//------------------------------------------------------------------------------ -bool CWeapon_SLAM::Holster( CBaseCombatWeapon *pSwitchingTo ) -{ - SetThink(NULL); - return BaseClass::Holster(pSwitchingTo); -} - -//----------------------------------------------------------------------------- -// Purpose: SLAM has no reload, but must call weapon idle to update state -// Input : -// Output : -//----------------------------------------------------------------------------- -bool CWeapon_SLAM::Reload( void ) -{ - WeaponIdle( ); - return true; -} - -//----------------------------------------------------------------------------- -// Purpose: -// Input : -// Output : -//----------------------------------------------------------------------------- -void CWeapon_SLAM::PrimaryAttack( void ) -{ - CBaseCombatCharacter *pOwner = GetOwner(); - if (!pOwner) - { - return; - } - - if (pOwner->GetAmmoCount(m_iSecondaryAmmoType) <= 0) - { - return; - } - - switch (m_tSlamState) - { - case SLAM_TRIPMINE_READY: - if (CanAttachSLAM()) - { - StartTripmineAttach(); - } - break; - case SLAM_SATCHEL_THROW: - StartSatchelThrow(); - break; - case SLAM_SATCHEL_ATTACH: - StartSatchelAttach(); - break; - } -} - -//----------------------------------------------------------------------------- -// Purpose: Secondary attack switches between satchel charge and tripmine mode -// Input : -// Output : -//----------------------------------------------------------------------------- -void CWeapon_SLAM::SecondaryAttack( void ) -{ - CBaseCombatCharacter *pOwner = GetOwner(); - if (!pOwner) - { - return; - } - - if (m_bDetonatorArmed) - { - StartSatchelDetonate(); - } -} - -//----------------------------------------------------------------------------- -// Purpose: -// Input : -// Output : -//----------------------------------------------------------------------------- -void CWeapon_SLAM::SatchelDetonate() -{ -#ifndef CLIENT_DLL - CBaseEntity *pEntity = NULL; - - while ((pEntity = gEntList.FindEntityByClassname( pEntity, "npc_satchel" )) != NULL) - { - CSatchelCharge *pSatchel = dynamic_cast(pEntity); - if (pSatchel->m_bIsLive && pSatchel->GetThrower() && GetOwner() && pSatchel->GetThrower() == GetOwner()) - { - //pSatchel->Use( GetOwner(), GetOwner(), USE_ON, 0 ); - //variant_t emptyVariant; - //pSatchel->AcceptInput( "Explode", NULL, NULL, emptyVariant, 5 ); - g_EventQueue.AddEvent( pSatchel, "Explode", 0.20, GetOwner(), GetOwner() ); - } - } -#endif - // Play sound for pressing the detonator - EmitSound( "Weapon_SLAM.SatchelDetonate" ); - - m_bDetonatorArmed = false; -} - -//----------------------------------------------------------------------------- -// Purpose: Returns true if there are any undetonated charges in the world -// that belong to this player -// Input : -// Output : -//----------------------------------------------------------------------------- -bool CWeapon_SLAM::AnyUndetonatedCharges(void) -{ -#ifndef CLIENT_DLL - CBaseEntity *pEntity = NULL; - - while ((pEntity = gEntList.FindEntityByClassname( pEntity, "npc_satchel" )) != NULL) - { - CSatchelCharge* pSatchel = dynamic_cast(pEntity); - if (pSatchel->m_bIsLive && pSatchel->GetThrower() && pSatchel->GetThrower() == GetOwner()) - { - return true; - } - } -#endif - return false; -} - -//----------------------------------------------------------------------------- -// Purpose: -// Input : -// Output : -//----------------------------------------------------------------------------- -void CWeapon_SLAM::StartSatchelDetonate() -{ - - if ( GetActivity() != ACT_SLAM_DETONATOR_IDLE && GetActivity() != ACT_SLAM_THROW_IDLE ) - return; - - // ----------------------------------------- - // Play detonate animation - // ----------------------------------------- - if (m_bNeedReload) - { - SendWeaponAnim(ACT_SLAM_DETONATOR_DETONATE); - } - else if (m_tSlamState == SLAM_SATCHEL_ATTACH) - { - SendWeaponAnim(ACT_SLAM_STICKWALL_DETONATE); - } - else if (m_tSlamState == SLAM_SATCHEL_THROW) - { - SendWeaponAnim(ACT_SLAM_THROW_DETONATE); - } - else - { - return; - } - SatchelDetonate(); - - m_flNextPrimaryAttack = gpGlobals->curtime + SequenceDuration(); - m_flNextSecondaryAttack = gpGlobals->curtime + SequenceDuration(); -} - - -//----------------------------------------------------------------------------- -// Purpose: -// Input : -// Output : -//----------------------------------------------------------------------------- -void CWeapon_SLAM::TripmineAttach( void ) -{ - CHL2MP_Player *pOwner = ToHL2MPPlayer( GetOwner() ); - if (!pOwner) - { - return; - } - - m_bAttachTripmine = false; - - Vector vecSrc, vecAiming; - - // Take the eye position and direction - vecSrc = pOwner->EyePosition(); - - QAngle angles = pOwner->GetLocalAngles(); - - AngleVectors( angles, &vecAiming ); - - trace_t tr; - - UTIL_TraceLine( vecSrc, vecSrc + (vecAiming * 128), MASK_SOLID, pOwner, COLLISION_GROUP_NONE, &tr ); - - if (tr.fraction < 1.0) - { - CBaseEntity *pEntity = tr.m_pEnt; - if (pEntity && !(pEntity->GetFlags() & FL_CONVEYOR)) - { - -#ifndef CLIENT_DLL - QAngle angles; - VectorAngles(tr.plane.normal, angles); - - angles.x += 90; - - CBaseEntity *pEnt = CBaseEntity::Create( "npc_tripmine", tr.endpos + tr.plane.normal * 3, angles, NULL ); - - CTripmineGrenade *pMine = (CTripmineGrenade *)pEnt; - pMine->m_hOwner = GetOwner(); - -#endif - - pOwner->RemoveAmmo( 1, m_iSecondaryAmmoType ); - } - } -} - -//----------------------------------------------------------------------------- -// Purpose: -// Input : -// Output : -//----------------------------------------------------------------------------- -void CWeapon_SLAM::StartTripmineAttach( void ) -{ - // Only the player fires this way so we can cast - CBasePlayer *pPlayer = ToBasePlayer( GetOwner() ); - if (!pPlayer) - { - return; - } - - Vector vecSrc, vecAiming; - - // Take the eye position and direction - vecSrc = pPlayer->EyePosition(); - - QAngle angles = pPlayer->GetLocalAngles(); - - AngleVectors( angles, &vecAiming ); - - trace_t tr; - - UTIL_TraceLine( vecSrc, vecSrc + (vecAiming * 128), MASK_SOLID, pPlayer, COLLISION_GROUP_NONE, &tr ); - - if (tr.fraction < 1.0) - { - // ALERT( at_console, "hit %f\n", tr.flFraction ); - - CBaseEntity *pEntity = tr.m_pEnt; - if (pEntity && !(pEntity->GetFlags() & FL_CONVEYOR)) - { - // player "shoot" animation - pPlayer->SetAnimation( PLAYER_ATTACK1 ); - - // ----------------------------------------- - // Play attach animation - // ----------------------------------------- - - if (m_bDetonatorArmed) - { - SendWeaponAnim(ACT_SLAM_STICKWALL_ATTACH); - } - else - { - SendWeaponAnim(ACT_SLAM_TRIPMINE_ATTACH); - } - - m_bNeedReload = true; - m_bAttachTripmine = true; - m_bNeedDetonatorDraw = m_bDetonatorArmed; - } - else - { - // ALERT( at_console, "no deploy\n" ); - } - } - - m_flNextPrimaryAttack = gpGlobals->curtime + SequenceDuration(); - m_flNextSecondaryAttack = gpGlobals->curtime + SequenceDuration(); -// SetWeaponIdleTime( gpGlobals->curtime + SequenceDuration() ); -} - -//----------------------------------------------------------------------------- -// Purpose: -// Input : -// Output : -//----------------------------------------------------------------------------- -void CWeapon_SLAM::SatchelThrow( void ) -{ -#ifndef CLIENT_DLL - m_bThrowSatchel = false; - - // Only the player fires this way so we can cast - CBasePlayer *pPlayer = ToBasePlayer( GetOwner() ); - - Vector vecSrc = pPlayer->WorldSpaceCenter(); - Vector vecFacing = pPlayer->BodyDirection3D( ); - vecSrc = vecSrc + vecFacing * 18.0; - // BUGBUG: is this because vecSrc is not from Weapon_ShootPosition()??? - vecSrc.z += 24.0f; - - Vector vecThrow; - GetOwner()->GetVelocity( &vecThrow, NULL ); - vecThrow += vecFacing * 500; - - // Player may have turned to face a wall during the throw anim in which case - // we don't want to throw the SLAM into the wall - if (CanAttachSLAM()) - { - vecThrow = vecFacing; - vecSrc = pPlayer->WorldSpaceCenter() + vecFacing * 5.0; - } - - CSatchelCharge *pSatchel = (CSatchelCharge*)Create( "npc_satchel", vecSrc, vec3_angle, GetOwner() ); - - if ( pSatchel ) - { - pSatchel->SetThrower( GetOwner() ); - pSatchel->ApplyAbsVelocityImpulse( vecThrow ); - pSatchel->SetLocalAngularVelocity( QAngle( 0, 400, 0 ) ); - pSatchel->m_bIsLive = true; - pSatchel->m_pMyWeaponSLAM = this; - } - - pPlayer->RemoveAmmo( 1, m_iSecondaryAmmoType ); - pPlayer->SetAnimation( PLAYER_ATTACK1 ); - -#endif - - // Play throw sound - EmitSound( "Weapon_SLAM.SatchelThrow" ); -} - -//----------------------------------------------------------------------------- -// Purpose: -// Input : -// Output : -//----------------------------------------------------------------------------- -void CWeapon_SLAM::StartSatchelThrow( void ) -{ - // ----------------------------------------- - // Play throw animation - // ----------------------------------------- - if (m_bDetonatorArmed) - { - SendWeaponAnim(ACT_SLAM_THROW_THROW); - } - else - { - SendWeaponAnim(ACT_SLAM_THROW_THROW_ND); - if (!m_bDetonatorArmed) - { - m_bDetonatorArmed = true; - m_bNeedDetonatorDraw = true; - } - } - - m_bNeedReload = true; - m_bThrowSatchel = true; - - m_flNextPrimaryAttack = gpGlobals->curtime + SequenceDuration(); - m_flNextSecondaryAttack = gpGlobals->curtime + SequenceDuration(); -} - -//----------------------------------------------------------------------------- -// Purpose: -// Input : -// Output : -//----------------------------------------------------------------------------- -void CWeapon_SLAM::SatchelAttach( void ) -{ -#ifndef CLIENT_DLL - CBaseCombatCharacter *pOwner = GetOwner(); - if (!pOwner) - { - return; - } - - m_bAttachSatchel = false; - - Vector vecSrc = pOwner->Weapon_ShootPosition( ); - Vector vecAiming = pOwner->BodyDirection2D( ); - - trace_t tr; - - UTIL_TraceLine( vecSrc, vecSrc + (vecAiming * 128), MASK_SOLID, pOwner, COLLISION_GROUP_NONE, &tr ); - - if (tr.fraction < 1.0) - { - CBaseEntity *pEntity = tr.m_pEnt; - if (pEntity && !(pEntity->GetFlags() & FL_CONVEYOR)) - { - QAngle angles; - VectorAngles(tr.plane.normal, angles); - angles.y -= 90; - angles.z -= 90; - tr.endpos.z -= 6.0f; - - CSatchelCharge *pSatchel = (CSatchelCharge*)CBaseEntity::Create( "npc_satchel", tr.endpos + tr.plane.normal * 3, angles, NULL ); - pSatchel->SetMoveType( MOVETYPE_FLY ); // no gravity - pSatchel->m_bIsAttached = true; - pSatchel->m_bIsLive = true; - pSatchel->SetThrower( GetOwner() ); - pSatchel->SetOwnerEntity( ((CBaseEntity*)GetOwner()) ); - pSatchel->m_pMyWeaponSLAM = this; - - pOwner->RemoveAmmo( 1, m_iSecondaryAmmoType ); - } - } -#endif -} - -//----------------------------------------------------------------------------- -// Purpose: -// Input : -// Output : -//----------------------------------------------------------------------------- -void CWeapon_SLAM::StartSatchelAttach( void ) -{ -#ifndef CLIENT_DLL - CBaseCombatCharacter *pOwner = GetOwner(); - if (!pOwner) - { - return; - } - - Vector vecSrc = pOwner->Weapon_ShootPosition( ); - Vector vecAiming = pOwner->BodyDirection2D( ); - - trace_t tr; - - UTIL_TraceLine( vecSrc, vecSrc + (vecAiming * 128), MASK_SOLID, pOwner, COLLISION_GROUP_NONE, &tr ); - - if (tr.fraction < 1.0) - { - CBaseEntity *pEntity = tr.m_pEnt; - if (pEntity && !(pEntity->GetFlags() & FL_CONVEYOR)) - { - // Only the player fires this way so we can cast - CBasePlayer *pPlayer = ToBasePlayer( pOwner ); - - // player "shoot" animation - pPlayer->SetAnimation( PLAYER_ATTACK1 ); - - // ----------------------------------------- - // Play attach animation - // ----------------------------------------- - if (m_bDetonatorArmed) - { - SendWeaponAnim(ACT_SLAM_STICKWALL_ATTACH); - } - else - { - SendWeaponAnim(ACT_SLAM_STICKWALL_ND_ATTACH); - if (!m_bDetonatorArmed) - { - m_bDetonatorArmed = true; - m_bNeedDetonatorDraw = true; - } - } - - m_bNeedReload = true; - m_bAttachSatchel = true; - - m_flNextPrimaryAttack = gpGlobals->curtime + SequenceDuration(); - } - } -#endif -} - -//----------------------------------------------------------------------------- -// Purpose: -// Input : -// Output : -//----------------------------------------------------------------------------- -void CWeapon_SLAM::SetSlamState( int newState ) -{ - // Set set and set idle time so animation gets updated with state change - m_tSlamState = newState; - SetWeaponIdleTime( gpGlobals->curtime ); -} - -//----------------------------------------------------------------------------- -// Purpose: -// Input : -// Output : -//----------------------------------------------------------------------------- -void CWeapon_SLAM::SLAMThink( void ) -{ - if ( m_flWallSwitchTime > gpGlobals->curtime ) - return; - - - // If not in tripmine mode we need to check to see if we are close to - // a wall. If we are we go into satchel_attach mode - CBaseCombatCharacter *pOwner = GetOwner(); - - if ( (pOwner && pOwner->GetAmmoCount(m_iSecondaryAmmoType) > 0)) - { - if (CanAttachSLAM()) - { - if (m_tSlamState == SLAM_SATCHEL_THROW) - { - SetSlamState(SLAM_TRIPMINE_READY); - int iAnim = m_bDetonatorArmed ? ACT_SLAM_THROW_TO_STICKWALL : ACT_SLAM_THROW_TO_TRIPMINE_ND; - SendWeaponAnim( iAnim ); - m_flWallSwitchTime = gpGlobals->curtime + SequenceDuration(); - m_bNeedReload = false; - } - } - else - { - if (m_tSlamState == SLAM_TRIPMINE_READY) - { - SetSlamState(SLAM_SATCHEL_THROW); - int iAnim = m_bDetonatorArmed ? ACT_SLAM_STICKWALL_TO_THROW : ACT_SLAM_TRIPMINE_TO_THROW_ND; - SendWeaponAnim( iAnim ); - m_flWallSwitchTime = gpGlobals->curtime + SequenceDuration(); - m_bNeedReload = false; - } - } - } -} - -//----------------------------------------------------------------------------- -// Purpose: -// Input : -// Output : -//----------------------------------------------------------------------------- -bool CWeapon_SLAM::CanAttachSLAM( void ) -{ - CHL2MP_Player *pOwner = ToHL2MPPlayer( GetOwner() ); - - if (!pOwner) - { - return false; - } - - Vector vecSrc, vecAiming; - - // Take the eye position and direction - vecSrc = pOwner->EyePosition(); - - QAngle angles = pOwner->GetLocalAngles(); - - AngleVectors( angles, &vecAiming ); - - trace_t tr; - - Vector vecEnd = vecSrc + (vecAiming * 42); - UTIL_TraceLine( vecSrc, vecEnd, MASK_SOLID, pOwner, COLLISION_GROUP_NONE, &tr ); - - if (tr.fraction < 1.0) - { - // Don't attach to a living creature - if (tr.m_pEnt) - { - CBaseEntity *pEntity = tr.m_pEnt; - CBaseCombatCharacter *pBCC = ToBaseCombatCharacter( pEntity ); - if (pBCC) - { - return false; - } - } - return true; - } - else - { - return false; - } -} - -//----------------------------------------------------------------------------- -// Purpose: Override so SLAM to so secondary attack when no secondary ammo -// but satchel is in the world -// Input : -// Output : -//----------------------------------------------------------------------------- -void CWeapon_SLAM::ItemPostFrame( void ) -{ - CBasePlayer *pOwner = ToBasePlayer( GetOwner() ); - if (!pOwner) - { - return; - } - - SLAMThink(); - - if ((pOwner->m_nButtons & IN_ATTACK2) && (m_flNextSecondaryAttack <= gpGlobals->curtime)) - { - SecondaryAttack(); - } - else if (!m_bNeedReload && (pOwner->m_nButtons & IN_ATTACK) && (m_flNextPrimaryAttack <= gpGlobals->curtime)) - { - PrimaryAttack(); - } - - // ----------------------- - // No buttons down - // ----------------------- - else - { - WeaponIdle( ); - return; - } -} - -//----------------------------------------------------------------------------- -// Purpose: Switch to next best weapon -// Input : -// Output : -//----------------------------------------------------------------------------- -void CWeapon_SLAM::Weapon_Switch( void ) -{ - // Note that we may pick the SLAM again, when we switch - // weapons, in which case we have to save and restore the - // detonator armed state. - // The SLAMs may be about to blow up, but haven't done so yet - // and the deploy function will find the undetonated charges - // and we are armed - bool saveState = m_bDetonatorArmed; - CBaseCombatCharacter *pOwner = GetOwner(); - pOwner->SwitchToNextBestWeapon( pOwner->GetActiveWeapon() ); - if (pOwner->GetActiveWeapon() == this) - { - m_bDetonatorArmed = saveState; - } - -#ifndef CLIENT_DLL - // If not armed and have no ammo - if (!m_bDetonatorArmed && pOwner->GetAmmoCount(m_iSecondaryAmmoType) <= 0) - { - pOwner->ClearActiveWeapon(); - } -#endif - -} - -//----------------------------------------------------------------------------- -// Purpose: -// Input : -// Output : -//----------------------------------------------------------------------------- -void CWeapon_SLAM::WeaponIdle( void ) -{ - // Ready to switch animations? - if ( HasWeaponIdleTimeElapsed() ) - { - // Don't allow throw to attach switch unless in idle - if (m_bClearReload) - { - m_bNeedReload = false; - m_bClearReload = false; - } - CBaseCombatCharacter *pOwner = GetOwner(); - if (!pOwner) - { - return; - } - - int iAnim = 0; - - if (m_bThrowSatchel) - { - SatchelThrow(); - if (m_bDetonatorArmed && !m_bNeedDetonatorDraw) - { - iAnim = ACT_SLAM_THROW_THROW2; - } - else - { - iAnim = ACT_SLAM_THROW_THROW_ND2; - } - } - else if (m_bAttachSatchel) - { - SatchelAttach(); - if (m_bDetonatorArmed && !m_bNeedDetonatorDraw) - { - iAnim = ACT_SLAM_STICKWALL_ATTACH2; - } - else - { - iAnim = ACT_SLAM_STICKWALL_ND_ATTACH2; - } - } - else if (m_bAttachTripmine) - { - TripmineAttach(); - iAnim = m_bNeedDetonatorDraw ? ACT_SLAM_STICKWALL_ATTACH2 : ACT_SLAM_TRIPMINE_ATTACH2; - } - else if ( m_bNeedReload ) - { - // If owner had ammo draw the correct SLAM type - if (pOwner->GetAmmoCount(m_iSecondaryAmmoType) > 0) - { - switch( m_tSlamState) - { - case SLAM_TRIPMINE_READY: - { - iAnim = m_bNeedDetonatorDraw ? ACT_SLAM_STICKWALL_DRAW : ACT_SLAM_TRIPMINE_DRAW; - } - break; - case SLAM_SATCHEL_ATTACH: - { - if (m_bNeedDetonatorHolster) - { - iAnim = ACT_SLAM_STICKWALL_DETONATOR_HOLSTER; - m_bNeedDetonatorHolster = false; - } - else if (m_bDetonatorArmed) - { - iAnim = m_bNeedDetonatorDraw ? ACT_SLAM_DETONATOR_STICKWALL_DRAW : ACT_SLAM_STICKWALL_DRAW; - m_bNeedDetonatorDraw = false; - } - else - { - iAnim = ACT_SLAM_STICKWALL_ND_DRAW; - } - } - break; - case SLAM_SATCHEL_THROW: - { - if (m_bNeedDetonatorHolster) - { - iAnim = ACT_SLAM_THROW_DETONATOR_HOLSTER; - m_bNeedDetonatorHolster = false; - } - else if (m_bDetonatorArmed) - { - iAnim = m_bNeedDetonatorDraw ? ACT_SLAM_DETONATOR_THROW_DRAW : ACT_SLAM_THROW_DRAW; - m_bNeedDetonatorDraw = false; - } - else - { - iAnim = ACT_SLAM_THROW_ND_DRAW; - } - } - break; - } - m_bClearReload = true; - } - // If no ammo and armed, idle with only the detonator - else if (m_bDetonatorArmed) - { - iAnim = m_bNeedDetonatorDraw ? ACT_SLAM_DETONATOR_DRAW : ACT_SLAM_DETONATOR_IDLE; - m_bNeedDetonatorDraw = false; - } - else - { -#ifndef CLIENT_DLL - pOwner->Weapon_Drop( this ); - UTIL_Remove(this); -#endif - } - } - else if (pOwner->GetAmmoCount(m_iSecondaryAmmoType) <= 0) - { -#ifndef CLIENT_DLL - pOwner->Weapon_Drop( this ); - UTIL_Remove(this); -#endif - } - - // If I don't need to reload just do the appropriate idle - else - { - switch( m_tSlamState) - { - case SLAM_TRIPMINE_READY: - { - iAnim = m_bDetonatorArmed ? ACT_SLAM_STICKWALL_IDLE : ACT_SLAM_TRIPMINE_IDLE; - m_flWallSwitchTime = 0; - } - break; - case SLAM_SATCHEL_THROW: - { - if (m_bNeedDetonatorHolster) - { - iAnim = ACT_SLAM_THROW_DETONATOR_HOLSTER; - m_bNeedDetonatorHolster = false; - } - else - { - iAnim = m_bDetonatorArmed ? ACT_SLAM_THROW_IDLE : ACT_SLAM_THROW_ND_IDLE; - m_flWallSwitchTime = 0; - } - } - break; - case SLAM_SATCHEL_ATTACH: - { - if (m_bNeedDetonatorHolster) - { - iAnim = ACT_SLAM_STICKWALL_DETONATOR_HOLSTER; - m_bNeedDetonatorHolster = false; - } - else - { - iAnim = m_bDetonatorArmed ? ACT_SLAM_STICKWALL_IDLE : ACT_SLAM_TRIPMINE_IDLE; - m_flWallSwitchTime = 0; - } - } - break; - } - } - SendWeaponAnim( iAnim ); - } -} - -bool CWeapon_SLAM::Deploy( void ) -{ - CBaseCombatCharacter *pOwner = GetOwner(); - if (!pOwner) - { - return false; - } - - m_bDetonatorArmed = AnyUndetonatedCharges(); - - - SetModel( GetViewModel() ); - - m_tSlamState = (int)SLAM_SATCHEL_THROW; - - // ------------------------------ - // Pick the right draw animation - // ------------------------------ - int iActivity; - - // If detonator is already armed - m_bNeedReload = false; - if (m_bDetonatorArmed) - { - if (pOwner->GetAmmoCount(m_iSecondaryAmmoType) <= 0) - { - iActivity = ACT_SLAM_DETONATOR_DRAW; - m_bNeedReload = true; - } - else if (CanAttachSLAM()) - { - iActivity = ACT_SLAM_DETONATOR_STICKWALL_DRAW; - SetSlamState(SLAM_TRIPMINE_READY); - } - else - { - iActivity = ACT_SLAM_DETONATOR_THROW_DRAW; - SetSlamState(SLAM_SATCHEL_THROW); - } - } - else - { - if (CanAttachSLAM()) - { - iActivity = ACT_SLAM_TRIPMINE_DRAW; - SetSlamState(SLAM_TRIPMINE_READY); - } - else - { - iActivity = ACT_SLAM_THROW_ND_DRAW; - SetSlamState(SLAM_SATCHEL_THROW); - } - } - - return DefaultDeploy( (char*)GetViewModel(), (char*)GetWorldModel(), iActivity, (char*)GetAnimPrefix() ); -} - -//----------------------------------------------------------------------------- -// Purpose: Constructor -// Input : -// Output : -//----------------------------------------------------------------------------- -CWeapon_SLAM::CWeapon_SLAM(void) -{ - m_tSlamState = (int)SLAM_SATCHEL_THROW; - m_bDetonatorArmed = false; - m_bNeedReload = true; - m_bClearReload = false; - m_bThrowSatchel = false; - m_bAttachSatchel = false; - m_bAttachTripmine = false; - m_bNeedDetonatorDraw = false; - m_bNeedDetonatorHolster = false; -} diff --git a/sp/src/game/shared/hl2mp/weapon_slam.h b/sp/src/game/shared/hl2mp/weapon_slam.h deleted file mode 100644 index 0b59bed7..00000000 --- a/sp/src/game/shared/hl2mp/weapon_slam.h +++ /dev/null @@ -1,91 +0,0 @@ -//========= Copyright Valve Corporation, All rights reserved. ============// -// -// Purpose: SLAM -// -// $Workfile: $ -// $Date: $ -// -//----------------------------------------------------------------------------- -// $Log: $ -// -// $NoKeywords: $ -//=============================================================================// - -#ifndef WEAPONSLAM_H -#define WEAPONSLAM_H - -#include "basegrenade_shared.h" -#include "weapon_hl2mpbasehlmpcombatweapon.h" - -enum -{ - SLAM_TRIPMINE_READY, - SLAM_SATCHEL_THROW, - SLAM_SATCHEL_ATTACH, -}; - -#ifdef CLIENT_DLL -#define CWeapon_SLAM C_Weapon_SLAM -#endif - -class CWeapon_SLAM : public CBaseHL2MPCombatWeapon -{ -public: - DECLARE_CLASS( CWeapon_SLAM, CBaseHL2MPCombatWeapon ); - - DECLARE_NETWORKCLASS(); - DECLARE_PREDICTABLE(); - - CNetworkVar( int, m_tSlamState ); - CNetworkVar( bool, m_bDetonatorArmed ); - CNetworkVar( bool, m_bNeedDetonatorDraw); - CNetworkVar( bool, m_bNeedDetonatorHolster); - CNetworkVar( bool, m_bNeedReload); - CNetworkVar( bool, m_bClearReload); - CNetworkVar( bool, m_bThrowSatchel); - CNetworkVar( bool, m_bAttachSatchel); - CNetworkVar( bool, m_bAttachTripmine); - float m_flWallSwitchTime; - - void Spawn( void ); - void Precache( void ); - - void PrimaryAttack( void ); - void SecondaryAttack( void ); - void WeaponIdle( void ); - void Weapon_Switch( void ); - void SLAMThink( void ); - - void SetPickupTouch( void ); - void SlamTouch( CBaseEntity *pOther ); // default weapon touch - void ItemPostFrame( void ); - bool Reload( void ); - void SetSlamState( int newState ); - bool CanAttachSLAM(void); // In position where can attach SLAM? - bool AnyUndetonatedCharges(void); - void StartTripmineAttach( void ); - void TripmineAttach( void ); - - void StartSatchelDetonate( void ); - void SatchelDetonate( void ); - void StartSatchelThrow( void ); - void StartSatchelAttach( void ); - void SatchelThrow( void ); - void SatchelAttach( void ); - bool Deploy( void ); - bool Holster( CBaseCombatWeapon *pSwitchingTo = NULL ); - - - CWeapon_SLAM(); - -#ifndef CLIENT_DLL - DECLARE_ACTTABLE(); - DECLARE_DATADESC(); -#endif - -private: - CWeapon_SLAM( const CWeapon_SLAM & ); -}; - - -#endif //WEAPONSLAM_H diff --git a/sp/src/game/shared/hl2mp/weapon_smg1.cpp b/sp/src/game/shared/hl2mp/weapon_smg1.cpp deleted file mode 100644 index bd6e1d42..00000000 --- a/sp/src/game/shared/hl2mp/weapon_smg1.cpp +++ /dev/null @@ -1,264 +0,0 @@ -//========= Copyright Valve Corporation, All rights reserved. ============// -// -// Purpose: -// -//=============================================================================// - -#include "cbase.h" -#include "npcevent.h" -#include "in_buttons.h" - -#ifdef CLIENT_DLL - #include "c_hl2mp_player.h" -#else - #include "grenade_ar2.h" - #include "hl2mp_player.h" - #include "basegrenade_shared.h" -#endif - -#include "weapon_hl2mpbase.h" -#include "weapon_hl2mpbase_machinegun.h" - -#ifdef CLIENT_DLL -#define CWeaponSMG1 C_WeaponSMG1 -#endif - -// memdbgon must be the last include file in a .cpp file!!! -#include "tier0/memdbgon.h" - -#define SMG1_GRENADE_DAMAGE 100.0f -#define SMG1_GRENADE_RADIUS 250.0f - -class CWeaponSMG1 : public CHL2MPMachineGun -{ -public: - DECLARE_CLASS( CWeaponSMG1, CHL2MPMachineGun ); - - CWeaponSMG1(); - - DECLARE_NETWORKCLASS(); - DECLARE_PREDICTABLE(); - - - void Precache( void ); - void AddViewKick( void ); - void SecondaryAttack( void ); - - int GetMinBurst() { return 2; } - int GetMaxBurst() { return 5; } - - virtual void Equip( CBaseCombatCharacter *pOwner ); - bool Reload( void ); - - float GetFireRate( void ) { return 0.075f; } // 13.3hz - Activity GetPrimaryAttackActivity( void ); - - virtual const Vector& GetBulletSpread( void ) - { - static const Vector cone = VECTOR_CONE_5DEGREES; - return cone; - } - - const WeaponProficiencyInfo_t *GetProficiencyValues(); - -#ifndef CLIENT_DLL - DECLARE_ACTTABLE(); -#endif - -protected: - - Vector m_vecTossVelocity; - float m_flNextGrenadeCheck; - -private: - CWeaponSMG1( const CWeaponSMG1 & ); -}; - -IMPLEMENT_NETWORKCLASS_ALIASED( WeaponSMG1, DT_WeaponSMG1 ) - -BEGIN_NETWORK_TABLE( CWeaponSMG1, DT_WeaponSMG1 ) -END_NETWORK_TABLE() - -BEGIN_PREDICTION_DATA( CWeaponSMG1 ) -END_PREDICTION_DATA() - -LINK_ENTITY_TO_CLASS( weapon_smg1, CWeaponSMG1 ); -PRECACHE_WEAPON_REGISTER(weapon_smg1); - -#ifndef CLIENT_DLL -acttable_t CWeaponSMG1::m_acttable[] = -{ - { ACT_HL2MP_IDLE, ACT_HL2MP_IDLE_SMG1, false }, - { ACT_HL2MP_RUN, ACT_HL2MP_RUN_SMG1, false }, - { ACT_HL2MP_IDLE_CROUCH, ACT_HL2MP_IDLE_CROUCH_SMG1, false }, - { ACT_HL2MP_WALK_CROUCH, ACT_HL2MP_WALK_CROUCH_SMG1, false }, - { ACT_HL2MP_GESTURE_RANGE_ATTACK, ACT_HL2MP_GESTURE_RANGE_ATTACK_SMG1, false }, - { ACT_HL2MP_GESTURE_RELOAD, ACT_HL2MP_GESTURE_RELOAD_SMG1, false }, - { ACT_HL2MP_JUMP, ACT_HL2MP_JUMP_SMG1, false }, - { ACT_RANGE_ATTACK1, ACT_RANGE_ATTACK_SMG1, false }, -}; - -IMPLEMENT_ACTTABLE(CWeaponSMG1); -#endif - -//========================================================= -CWeaponSMG1::CWeaponSMG1( ) -{ - m_fMinRange1 = 0;// No minimum range. - m_fMaxRange1 = 1400; -} - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void CWeaponSMG1::Precache( void ) -{ -#ifndef CLIENT_DLL - UTIL_PrecacheOther("grenade_ar2"); -#endif - - BaseClass::Precache(); -} - -//----------------------------------------------------------------------------- -// Purpose: Give this weapon longer range when wielded by an ally NPC. -//----------------------------------------------------------------------------- -void CWeaponSMG1::Equip( CBaseCombatCharacter *pOwner ) -{ - m_fMaxRange1 = 1400; - - BaseClass::Equip( pOwner ); -} - -//----------------------------------------------------------------------------- -// Purpose: -// Output : Activity -//----------------------------------------------------------------------------- -Activity CWeaponSMG1::GetPrimaryAttackActivity( void ) -{ - if ( m_nShotsFired < 2 ) - return ACT_VM_PRIMARYATTACK; - - if ( m_nShotsFired < 3 ) - return ACT_VM_RECOIL1; - - if ( m_nShotsFired < 4 ) - return ACT_VM_RECOIL2; - - return ACT_VM_RECOIL3; -} - -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -bool CWeaponSMG1::Reload( void ) -{ - bool fRet; - float fCacheTime = m_flNextSecondaryAttack; - - fRet = DefaultReload( GetMaxClip1(), GetMaxClip2(), ACT_VM_RELOAD ); - if ( fRet ) - { - // Undo whatever the reload process has done to our secondary - // attack timer. We allow you to interrupt reloading to fire - // a grenade. - m_flNextSecondaryAttack = GetOwner()->m_flNextAttack = fCacheTime; - - WeaponSound( RELOAD ); - } - - return fRet; -} - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void CWeaponSMG1::AddViewKick( void ) -{ - #define EASY_DAMPEN 0.5f - #define MAX_VERTICAL_KICK 1.0f //Degrees - #define SLIDE_LIMIT 2.0f //Seconds - - //Get the view kick - CBasePlayer *pPlayer = ToBasePlayer( GetOwner() ); - - if ( pPlayer == NULL ) - return; - - DoMachineGunKick( pPlayer, EASY_DAMPEN, MAX_VERTICAL_KICK, m_fFireDuration, SLIDE_LIMIT ); -} - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void CWeaponSMG1::SecondaryAttack( void ) -{ - // Only the player fires this way so we can cast - CBasePlayer *pPlayer = ToBasePlayer( GetOwner() ); - - if ( pPlayer == NULL ) - return; - - //Must have ammo - if ( ( pPlayer->GetAmmoCount( m_iSecondaryAmmoType ) <= 0 ) || ( pPlayer->GetWaterLevel() == 3 ) ) - { - SendWeaponAnim( ACT_VM_DRYFIRE ); - BaseClass::WeaponSound( EMPTY ); - m_flNextSecondaryAttack = gpGlobals->curtime + 0.5f; - return; - } - - if( m_bInReload ) - m_bInReload = false; - - // MUST call sound before removing a round from the clip of a CMachineGun - BaseClass::WeaponSound( WPN_DOUBLE ); - - Vector vecSrc = pPlayer->Weapon_ShootPosition(); - Vector vecThrow; - // Don't autoaim on grenade tosses - AngleVectors( pPlayer->EyeAngles() + pPlayer->GetPunchAngle(), &vecThrow ); - VectorScale( vecThrow, 1000.0f, vecThrow ); - -#ifndef CLIENT_DLL - //Create the grenade - CGrenadeAR2 *pGrenade = (CGrenadeAR2*)Create( "grenade_ar2", vecSrc, vec3_angle, pPlayer ); - pGrenade->SetAbsVelocity( vecThrow ); - - pGrenade->SetLocalAngularVelocity( RandomAngle( -400, 400 ) ); - pGrenade->SetMoveType( MOVETYPE_FLYGRAVITY, MOVECOLLIDE_FLY_BOUNCE ); - pGrenade->SetThrower( GetOwner() ); - pGrenade->SetDamage( SMG1_GRENADE_DAMAGE ); - pGrenade->SetDamageRadius( SMG1_GRENADE_RADIUS ); -#endif - - SendWeaponAnim( ACT_VM_SECONDARYATTACK ); - - // player "shoot" animation - pPlayer->SetAnimation( PLAYER_ATTACK1 ); - - // Decrease ammo - pPlayer->RemoveAmmo( 1, m_iSecondaryAmmoType ); - - // Can shoot again immediately - m_flNextPrimaryAttack = gpGlobals->curtime + 0.5f; - - // Can blow up after a short delay (so have time to release mouse button) - m_flNextSecondaryAttack = gpGlobals->curtime + 1.0f; -} - -//----------------------------------------------------------------------------- -const WeaponProficiencyInfo_t *CWeaponSMG1::GetProficiencyValues() -{ - static WeaponProficiencyInfo_t proficiencyTable[] = - { - { 7.0, 0.75 }, - { 5.00, 0.75 }, - { 10.0/3.0, 0.75 }, - { 5.0/3.0, 0.75 }, - { 1.00, 1.0 }, - }; - - COMPILE_TIME_ASSERT( ARRAYSIZE(proficiencyTable) == WEAPON_PROFICIENCY_PERFECT + 1); - - return proficiencyTable; -} diff --git a/sp/src/game/shared/hl2mp/weapon_stunstick.cpp b/sp/src/game/shared/hl2mp/weapon_stunstick.cpp deleted file mode 100644 index 9f706983..00000000 --- a/sp/src/game/shared/hl2mp/weapon_stunstick.cpp +++ /dev/null @@ -1,902 +0,0 @@ -//========= Copyright Valve Corporation, All rights reserved. ============// -// -// Purpose: Stun Stick- beating stick with a zappy end -// -// $NoKeywords: $ -//=============================================================================// - -#include "cbase.h" -#include "npcevent.h" -#include "weapon_hl2mpbasebasebludgeon.h" -#include "IEffects.h" -#include "debugoverlay_shared.h" - -#ifndef CLIENT_DLL - #include "npc_metropolice.h" - #include "te_effect_dispatch.h" -#endif - -#ifdef CLIENT_DLL - - #include "iviewrender_beams.h" - #include "beam_shared.h" - #include "materialsystem/imaterial.h" - #include "model_types.h" - #include "c_te_effect_dispatch.h" - #include "fx_quad.h" - #include "fx.h" - - extern void DrawHalo( IMaterial* pMaterial, const Vector &source, float scale, float const *color, float flHDRColorScale ); - extern void FormatViewModelAttachment( Vector &vOrigin, bool bInverse ); - -#endif - -// memdbgon must be the last include file in a .cpp file!!! -#include "tier0/memdbgon.h" - -extern ConVar metropolice_move_and_melee; - -#define STUNSTICK_RANGE 75.0f -#define STUNSTICK_REFIRE 0.8f -#define STUNSTICK_BEAM_MATERIAL "sprites/lgtning.vmt" -#define STUNSTICK_GLOW_MATERIAL "sprites/light_glow02_add" -#define STUNSTICK_GLOW_MATERIAL2 "effects/blueflare1" -#define STUNSTICK_GLOW_MATERIAL_NOZ "sprites/light_glow02_add_noz" - -#ifdef CLIENT_DLL -#define CWeaponStunStick C_WeaponStunStick -#endif - -class CWeaponStunStick : public CBaseHL2MPBludgeonWeapon -{ - DECLARE_CLASS( CWeaponStunStick, CBaseHL2MPBludgeonWeapon ); - -public: - - CWeaponStunStick(); - - DECLARE_NETWORKCLASS(); - DECLARE_PREDICTABLE(); - -#ifndef CLIENT_DLL - DECLARE_ACTTABLE(); -#endif - -#ifdef CLIENT_DLL - virtual int DrawModel( int flags ); - virtual void ClientThink( void ); - virtual void OnDataChanged( DataUpdateType_t updateType ); - virtual RenderGroup_t GetRenderGroup( void ); - virtual void ViewModelDrawn( C_BaseViewModel *pBaseViewModel ); - -#endif - - virtual void Precache(); - - void Spawn(); - - float GetRange( void ) { return STUNSTICK_RANGE; } - float GetFireRate( void ) { return STUNSTICK_REFIRE; } - - - bool Deploy( void ); - bool Holster( CBaseCombatWeapon *pSwitchingTo = NULL ); - - void Drop( const Vector &vecVelocity ); - void ImpactEffect( trace_t &traceHit ); - void SecondaryAttack( void ) {} - void SetStunState( bool state ); - bool GetStunState( void ); - -#ifndef CLIENT_DLL - void Operator_HandleAnimEvent( animevent_t *pEvent, CBaseCombatCharacter *pOperator ); - int WeaponMeleeAttack1Condition( float flDot, float flDist ); -#endif - - float GetDamageForActivity( Activity hitActivity ); - - CWeaponStunStick( const CWeaponStunStick & ); - -private: - -#ifdef CLIENT_DLL - - #define NUM_BEAM_ATTACHMENTS 9 - - struct stunstickBeamInfo_t - { - int IDs[2]; // 0 - top, 1 - bottom - }; - - stunstickBeamInfo_t m_BeamAttachments[NUM_BEAM_ATTACHMENTS]; // Lookup for arc attachment points on the head of the stick - int m_BeamCenterAttachment; // "Core" of the effect (center of the head) - - void SetupAttachmentPoints( void ); - void DrawFirstPersonEffects( void ); - void DrawThirdPersonEffects( void ); - void DrawEffects( void ); - bool InSwing( void ); - - bool m_bSwungLastFrame; - - #define FADE_DURATION 0.25f - - float m_flFadeTime; - -#endif - - CNetworkVar( bool, m_bActive ); -}; - -//----------------------------------------------------------------------------- -// CWeaponStunStick -//----------------------------------------------------------------------------- -IMPLEMENT_NETWORKCLASS_ALIASED( WeaponStunStick, DT_WeaponStunStick ) - -BEGIN_NETWORK_TABLE( CWeaponStunStick, DT_WeaponStunStick ) -#ifdef CLIENT_DLL - RecvPropInt( RECVINFO( m_bActive ) ), -#else - SendPropInt( SENDINFO( m_bActive ), 1, SPROP_UNSIGNED ), -#endif - -END_NETWORK_TABLE() - -BEGIN_PREDICTION_DATA( CWeaponStunStick ) -END_PREDICTION_DATA() - -LINK_ENTITY_TO_CLASS( weapon_stunstick, CWeaponStunStick ); -PRECACHE_WEAPON_REGISTER( weapon_stunstick ); - - -#ifndef CLIENT_DLL - -acttable_t CWeaponStunStick::m_acttable[] = -{ - { ACT_RANGE_ATTACK1, ACT_RANGE_ATTACK_SLAM, true }, - { ACT_HL2MP_IDLE, ACT_HL2MP_IDLE_MELEE, false }, - { ACT_HL2MP_RUN, ACT_HL2MP_RUN_MELEE, false }, - { ACT_HL2MP_IDLE_CROUCH, ACT_HL2MP_IDLE_CROUCH_MELEE, false }, - { ACT_HL2MP_WALK_CROUCH, ACT_HL2MP_WALK_CROUCH_MELEE, false }, - { ACT_HL2MP_GESTURE_RANGE_ATTACK, ACT_HL2MP_GESTURE_RANGE_ATTACK_MELEE, false }, - { ACT_HL2MP_GESTURE_RELOAD, ACT_HL2MP_GESTURE_RELOAD_MELEE, false }, - { ACT_HL2MP_JUMP, ACT_HL2MP_JUMP_MELEE, false }, -}; - -IMPLEMENT_ACTTABLE(CWeaponStunStick); - -#endif - - -//----------------------------------------------------------------------------- -// Constructor -//----------------------------------------------------------------------------- -CWeaponStunStick::CWeaponStunStick( void ) -{ - // HACK: Don't call SetStunState because this tried to Emit a sound before - // any players are connected which is a bug - m_bActive = false; - -#ifdef CLIENT_DLL - m_bSwungLastFrame = false; - m_flFadeTime = FADE_DURATION; // Start off past the fade point -#endif -} - -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -void CWeaponStunStick::Spawn() -{ - Precache(); - - BaseClass::Spawn(); - AddSolidFlags( FSOLID_NOT_STANDABLE ); -} - -void CWeaponStunStick::Precache() -{ - BaseClass::Precache(); - - PrecacheScriptSound( "Weapon_StunStick.Activate" ); - PrecacheScriptSound( "Weapon_StunStick.Deactivate" ); - - PrecacheModel( STUNSTICK_BEAM_MATERIAL ); - PrecacheModel( "sprites/light_glow02_add.vmt" ); - PrecacheModel( "effects/blueflare1.vmt" ); - PrecacheModel( "sprites/light_glow02_add_noz.vmt" ); -} - -//----------------------------------------------------------------------------- -// Purpose: Get the damage amount for the animation we're doing -// Input : hitActivity - currently played activity -// Output : Damage amount -//----------------------------------------------------------------------------- -float CWeaponStunStick::GetDamageForActivity( Activity hitActivity ) -{ - return 40.0f; -} - -//----------------------------------------------------------------------------- -// Attempt to lead the target (needed because citizens can't hit manhacks with the crowbar!) -//----------------------------------------------------------------------------- -extern ConVar sk_crowbar_lead_time; - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -void CWeaponStunStick::ImpactEffect( trace_t &traceHit ) -{ - -//#ifndef CLIENT_DLL - - CEffectData data; - - data.m_vNormal = traceHit.plane.normal; - data.m_vOrigin = traceHit.endpos + ( data.m_vNormal * 4.0f ); - - DispatchEffect( "StunstickImpact", data ); - -//#endif - - //FIXME: need new decals - UTIL_ImpactTrace( &traceHit, DMG_CLUB ); -} - -#ifndef CLIENT_DLL - - -int CWeaponStunStick::WeaponMeleeAttack1Condition( float flDot, float flDist ) -{ - // Attempt to lead the target (needed because citizens can't hit manhacks with the crowbar!) - CAI_BaseNPC *pNPC = GetOwner()->MyNPCPointer(); - CBaseEntity *pEnemy = pNPC->GetEnemy(); - if (!pEnemy) - return COND_NONE; - - Vector vecVelocity; - AngularImpulse angVelocity; - pEnemy->GetVelocity( &vecVelocity, &angVelocity ); - - // Project where the enemy will be in a little while, add some randomness so he doesn't always hit - float dt = sk_crowbar_lead_time.GetFloat(); - dt += random->RandomFloat( -0.3f, 0.2f ); - if ( dt < 0.0f ) - dt = 0.0f; - - Vector vecExtrapolatedPos; - VectorMA( pEnemy->WorldSpaceCenter(), dt, vecVelocity, vecExtrapolatedPos ); - - Vector vecDelta; - VectorSubtract( vecExtrapolatedPos, pNPC->WorldSpaceCenter(), vecDelta ); - - if ( fabs( vecDelta.z ) > 70 ) - { - return COND_TOO_FAR_TO_ATTACK; - } - - Vector vecForward = pNPC->BodyDirection2D( ); - vecDelta.z = 0.0f; - float flExtrapolatedDot = DotProduct2D( vecDelta.AsVector2D(), vecForward.AsVector2D() ); - if ((flDot < 0.7) && (flExtrapolatedDot < 0.7)) - { - return COND_NOT_FACING_ATTACK; - } - - float flExtrapolatedDist = Vector2DNormalize( vecDelta.AsVector2D() ); - - if( pEnemy->IsPlayer() ) - { - //Vector vecDir = pEnemy->GetSmoothedVelocity(); - //float flSpeed = VectorNormalize( vecDir ); - - // If player will be in front of me in one-half second, clock his arse. - Vector vecProjectEnemy = pEnemy->GetAbsOrigin() + (pEnemy->GetAbsVelocity() * 0.35); - Vector vecProjectMe = GetAbsOrigin(); - - if( (vecProjectMe - vecProjectEnemy).Length2D() <= 48.0f ) - { - return COND_CAN_MELEE_ATTACK1; - } - } -/* - if( metropolice_move_and_melee.GetBool() ) - { - if( pNPC->IsMoving() ) - { - flTargetDist *= 1.5f; - } - } -*/ - float flTargetDist = 48.0f; - if ((flDist > flTargetDist) && (flExtrapolatedDist > flTargetDist)) - { - return COND_TOO_FAR_TO_ATTACK; - } - - return COND_CAN_MELEE_ATTACK1; -} - - -void CWeaponStunStick::Operator_HandleAnimEvent( animevent_t *pEvent, CBaseCombatCharacter *pOperator ) -{ - switch( pEvent->event ) - { - case EVENT_WEAPON_MELEE_HIT: - { - // Trace up or down based on where the enemy is... - // But only if we're basically facing that direction - Vector vecDirection; - AngleVectors( GetAbsAngles(), &vecDirection ); - - CBaseEntity *pEnemy = pOperator->MyNPCPointer() ? pOperator->MyNPCPointer()->GetEnemy() : NULL; - if ( pEnemy ) - { - Vector vecDelta; - VectorSubtract( pEnemy->WorldSpaceCenter(), pOperator->Weapon_ShootPosition(), vecDelta ); - VectorNormalize( vecDelta ); - - Vector2D vecDelta2D = vecDelta.AsVector2D(); - Vector2DNormalize( vecDelta2D ); - if ( DotProduct2D( vecDelta2D, vecDirection.AsVector2D() ) > 0.8f ) - { - vecDirection = vecDelta; - } - } - - Vector vecEnd; - VectorMA( pOperator->Weapon_ShootPosition(), 32, vecDirection, vecEnd ); - // Stretch the swing box down to catch low level physics objects - CBaseEntity *pHurt = pOperator->CheckTraceHullAttack( pOperator->Weapon_ShootPosition(), vecEnd, - Vector(-16,-16,-40), Vector(16,16,16), GetDamageForActivity( GetActivity() ), DMG_CLUB, 0.5f, false ); - - // did I hit someone? - if ( pHurt ) - { - // play sound - WeaponSound( MELEE_HIT ); - - CBasePlayer *pPlayer = ToBasePlayer( pHurt ); - - bool bFlashed = false; - - // Punch angles - if ( pPlayer != NULL && !(pPlayer->GetFlags() & FL_GODMODE) ) - { - float yawKick = random->RandomFloat( -48, -24 ); - - //Kick the player angles - pPlayer->ViewPunch( QAngle( -16, yawKick, 2 ) ); - - Vector dir = pHurt->GetAbsOrigin() - GetAbsOrigin(); - - // If the player's on my head, don't knock him up - if ( pPlayer->GetGroundEntity() == pOperator ) - { - dir = vecDirection; - dir.z = 0; - } - - VectorNormalize(dir); - - dir *= 500.0f; - - //If not on ground, then don't make them fly! - if ( !(pPlayer->GetFlags() & FL_ONGROUND ) ) - dir.z = 0.0f; - - //Push the target back - pHurt->ApplyAbsVelocityImpulse( dir ); - - if ( !bFlashed ) - { - color32 red = {128,0,0,128}; - UTIL_ScreenFade( pPlayer, red, 0.5f, 0.1f, FFADE_IN ); - } - - // Force the player to drop anyting they were holding - pPlayer->ForceDropOfCarriedPhysObjects(); - } - - // do effect? - } - else - { - WeaponSound( MELEE_MISS ); - } - } - break; - default: - BaseClass::Operator_HandleAnimEvent( pEvent, pOperator ); - break; - } -} - -#endif - -//----------------------------------------------------------------------------- -// Purpose: Sets the state of the stun stick -//----------------------------------------------------------------------------- -void CWeaponStunStick::SetStunState( bool state ) -{ - m_bActive = state; - - if ( m_bActive ) - { - //FIXME: START - Move to client-side - - Vector vecAttachment; - QAngle vecAttachmentAngles; - - GetAttachment( 1, vecAttachment, vecAttachmentAngles ); - g_pEffects->Sparks( vecAttachment ); - - //FIXME: END - Move to client-side - - EmitSound( "Weapon_StunStick.Activate" ); - } - else - { - EmitSound( "Weapon_StunStick.Deactivate" ); - } -} - -//----------------------------------------------------------------------------- -// Purpose: -// Output : Returns true on success, false on failure. -//----------------------------------------------------------------------------- -bool CWeaponStunStick::Deploy( void ) -{ - SetStunState( true ); - - return BaseClass::Deploy(); -} - -//----------------------------------------------------------------------------- -// Purpose: -//----------------------------------------------------------------------------- -bool CWeaponStunStick::Holster( CBaseCombatWeapon *pSwitchingTo ) -{ - if ( BaseClass::Holster( pSwitchingTo ) == false ) - return false; - - SetStunState( false ); - SetWeaponVisible( false ); - - return true; -} - -//----------------------------------------------------------------------------- -// Purpose: -// Input : &vecVelocity - -//----------------------------------------------------------------------------- -void CWeaponStunStick::Drop( const Vector &vecVelocity ) -{ - SetStunState( false ); - -#ifndef CLIENT_DLL - UTIL_Remove( this ); -#endif - -} - -//----------------------------------------------------------------------------- -// Purpose: -// Output : Returns true on success, false on failure. -//----------------------------------------------------------------------------- -bool CWeaponStunStick::GetStunState( void ) -{ - return m_bActive; -} - -#ifdef CLIENT_DLL - -//----------------------------------------------------------------------------- -// Purpose: Get the attachment point on a viewmodel that a base weapon is using -//----------------------------------------------------------------------------- -bool UTIL_GetWeaponAttachment( C_BaseCombatWeapon *pWeapon, int attachmentID, Vector &absOrigin, QAngle &absAngles ) -{ - // This is already correct in third-person - if ( pWeapon && pWeapon->ShouldDrawUsingViewModel() == false ) - { - return pWeapon->GetAttachment( attachmentID, absOrigin, absAngles ); - } - - // Otherwise we need to translate the attachment to the viewmodel's version and reformat it - CBasePlayer *pOwner = ToBasePlayer( pWeapon->GetOwner() ); - - if ( pOwner != NULL ) - { - int ret = pOwner->GetViewModel()->GetAttachment( attachmentID, absOrigin, absAngles ); - FormatViewModelAttachment( absOrigin, true ); - - return ret; - } - - // Wasn't found - return false; -} - -#define BEAM_ATTACH_CORE_NAME "sparkrear" - -//----------------------------------------------------------------------------- -// Purpose: Sets up the attachment point lookup for the model -//----------------------------------------------------------------------------- -void C_WeaponStunStick::SetupAttachmentPoints( void ) -{ - // Setup points for both types of views - if ( ShouldDrawUsingViewModel() ) - { - const char *szBeamAttachNamesTop[NUM_BEAM_ATTACHMENTS] = - { - "spark1a","spark2a","spark3a","spark4a", - "spark5a","spark6a","spark7a","spark8a", - "spark9a", - }; - - const char *szBeamAttachNamesBottom[NUM_BEAM_ATTACHMENTS] = - { - "spark1b","spark2b","spark3b","spark4b", - "spark5b","spark6b","spark7b","spark8b", - "spark9b", - }; - - // Lookup and store all connections - for ( int i = 0; i < NUM_BEAM_ATTACHMENTS; i++ ) - { - m_BeamAttachments[i].IDs[0] = LookupAttachment( szBeamAttachNamesTop[i] ); - m_BeamAttachments[i].IDs[1] = LookupAttachment( szBeamAttachNamesBottom[i] ); - } - - // Setup the center beam point - m_BeamCenterAttachment = LookupAttachment( BEAM_ATTACH_CORE_NAME ); - } - else - { - // Setup the center beam point - m_BeamCenterAttachment = 1; - } -} - -//----------------------------------------------------------------------------- -// Purpose: Draws the stunstick model (with extra effects) -//----------------------------------------------------------------------------- -int C_WeaponStunStick::DrawModel( int flags ) -{ - if ( ShouldDraw() == false ) - return 0; - - // Only render these on the transparent pass - if ( flags & STUDIO_TRANSPARENCY ) - { - DrawEffects(); - return 1; - } - - return BaseClass::DrawModel( flags ); -} - -//----------------------------------------------------------------------------- -// Purpose: Randomly adds extra effects -//----------------------------------------------------------------------------- -void C_WeaponStunStick::ClientThink( void ) -{ - if ( InSwing() == false ) - { - if ( m_bSwungLastFrame ) - { - // Start fading - m_flFadeTime = gpGlobals->curtime; - m_bSwungLastFrame = false; - } - - return; - } - - // Remember if we were swinging last frame - m_bSwungLastFrame = InSwing(); - - if ( IsEffectActive( EF_NODRAW ) ) - return; - - if ( ShouldDrawUsingViewModel() ) - { - // Update our effects - if ( gpGlobals->frametime != 0.0f && ( random->RandomInt( 0, 3 ) == 0 ) ) - { - Vector vecOrigin; - QAngle vecAngles; - - // Inner beams - BeamInfo_t beamInfo; - - int attachment = random->RandomInt( 0, 15 ); - - UTIL_GetWeaponAttachment( this, attachment, vecOrigin, vecAngles ); - ::FormatViewModelAttachment( vecOrigin, false ); - - CBasePlayer *pOwner = ToBasePlayer( GetOwner() ); - CBaseEntity *pBeamEnt = pOwner->GetViewModel(); - - beamInfo.m_vecStart = vec3_origin; - beamInfo.m_pStartEnt= pBeamEnt; - beamInfo.m_nStartAttachment = attachment; - - beamInfo.m_pEndEnt = NULL; - beamInfo.m_nEndAttachment = -1; - beamInfo.m_vecEnd = vecOrigin + RandomVector( -8, 8 ); - - beamInfo.m_pszModelName = STUNSTICK_BEAM_MATERIAL; - beamInfo.m_flHaloScale = 0.0f; - beamInfo.m_flLife = 0.05f; - beamInfo.m_flWidth = random->RandomFloat( 1.0f, 2.0f ); - beamInfo.m_flEndWidth = 0; - beamInfo.m_flFadeLength = 0.0f; - beamInfo.m_flAmplitude = random->RandomFloat( 16, 32 ); - beamInfo.m_flBrightness = 255.0; - beamInfo.m_flSpeed = 0.0; - beamInfo.m_nStartFrame = 0.0; - beamInfo.m_flFrameRate = 1.0f; - beamInfo.m_flRed = 255.0f;; - beamInfo.m_flGreen = 255.0f; - beamInfo.m_flBlue = 255.0f; - beamInfo.m_nSegments = 16; - beamInfo.m_bRenderable = true; - beamInfo.m_nFlags = 0; - - beams->CreateBeamEntPoint( beamInfo ); - } - } -} - -//----------------------------------------------------------------------------- -// Purpose: Starts the client-side version thinking -//----------------------------------------------------------------------------- -void C_WeaponStunStick::OnDataChanged( DataUpdateType_t updateType ) -{ - BaseClass::OnDataChanged( updateType ); - if ( updateType == DATA_UPDATE_CREATED ) - { - SetNextClientThink( CLIENT_THINK_ALWAYS ); - SetupAttachmentPoints(); - } -} - -//----------------------------------------------------------------------------- -// Purpose: Tells us we're always a translucent entity -//----------------------------------------------------------------------------- -RenderGroup_t C_WeaponStunStick::GetRenderGroup( void ) -{ - return RENDER_GROUP_TWOPASS; -} - -//----------------------------------------------------------------------------- -// Purpose: Tells us we're always a translucent entity -//----------------------------------------------------------------------------- -bool C_WeaponStunStick::InSwing( void ) -{ - int activity = GetActivity(); - - // FIXME: This is needed until the actual animation works - if ( ShouldDrawUsingViewModel() == false ) - return true; - - // These are the swing activities this weapon can play - if ( activity == GetPrimaryAttackActivity() || - activity == GetSecondaryAttackActivity() || - activity == ACT_VM_MISSCENTER || - activity == ACT_VM_MISSCENTER2 ) - return true; - - return false; -} - -//----------------------------------------------------------------------------- -// Purpose: Draw our special effects -//----------------------------------------------------------------------------- -void C_WeaponStunStick::DrawThirdPersonEffects( void ) -{ - Vector vecOrigin; - QAngle vecAngles; - float color[3]; - float scale; - - CMatRenderContextPtr pRenderContext( materials ); - IMaterial *pMaterial = materials->FindMaterial( STUNSTICK_GLOW_MATERIAL, NULL, false ); - pRenderContext->Bind( pMaterial ); - - // Get bright when swung - if ( InSwing() ) - { - color[0] = color[1] = color[2] = 0.4f; - scale = 22.0f; - } - else - { - color[0] = color[1] = color[2] = 0.1f; - scale = 20.0f; - } - - // Draw an all encompassing glow around the entire head - UTIL_GetWeaponAttachment( this, m_BeamCenterAttachment, vecOrigin, vecAngles ); - DrawHalo( pMaterial, vecOrigin, scale, color ); - - if ( InSwing() ) - { - pMaterial = materials->FindMaterial( STUNSTICK_GLOW_MATERIAL2, NULL, false ); - pRenderContext->Bind( pMaterial ); - - color[0] = color[1] = color[2] = random->RandomFloat( 0.6f, 0.8f ); - scale = random->RandomFloat( 4.0f, 6.0f ); - - // Draw an all encompassing glow around the entire head - UTIL_GetWeaponAttachment( this, m_BeamCenterAttachment, vecOrigin, vecAngles ); - DrawHalo( pMaterial, vecOrigin, scale, color ); - - // Update our effects - if ( gpGlobals->frametime != 0.0f && ( random->RandomInt( 0, 5 ) == 0 ) ) - { - Vector vecOrigin; - QAngle vecAngles; - - GetAttachment( 1, vecOrigin, vecAngles ); - - Vector vForward; - AngleVectors( vecAngles, &vForward ); - - Vector vEnd = vecOrigin - vForward * 1.0f; - - // Inner beams - BeamInfo_t beamInfo; - - beamInfo.m_vecStart = vEnd; - Vector offset = RandomVector( -12, 8 ); - - offset += Vector(4,4,4); - beamInfo.m_vecEnd = vecOrigin + offset; - - beamInfo.m_pStartEnt= cl_entitylist->GetEnt( BEAMENT_ENTITY( entindex() ) ); - beamInfo.m_pEndEnt = cl_entitylist->GetEnt( BEAMENT_ENTITY( entindex() ) ); - beamInfo.m_nStartAttachment = 1; - beamInfo.m_nEndAttachment = -1; - - beamInfo.m_nType = TE_BEAMTESLA; - beamInfo.m_pszModelName = STUNSTICK_BEAM_MATERIAL; - beamInfo.m_flHaloScale = 0.0f; - beamInfo.m_flLife = 0.01f; - beamInfo.m_flWidth = random->RandomFloat( 1.0f, 3.0f ); - beamInfo.m_flEndWidth = 0; - beamInfo.m_flFadeLength = 0.0f; - beamInfo.m_flAmplitude = random->RandomFloat( 1, 2 ); - beamInfo.m_flBrightness = 255.0; - beamInfo.m_flSpeed = 0.0; - beamInfo.m_nStartFrame = 0.0; - beamInfo.m_flFrameRate = 1.0f; - beamInfo.m_flRed = 255.0f;; - beamInfo.m_flGreen = 255.0f; - beamInfo.m_flBlue = 255.0f; - beamInfo.m_nSegments = 16; - beamInfo.m_bRenderable = true; - beamInfo.m_nFlags = FBEAM_SHADEOUT; - - beams->CreateBeamPoints( beamInfo ); - } - } -} - -//----------------------------------------------------------------------------- -// Purpose: Draw our special effects -//----------------------------------------------------------------------------- -void C_WeaponStunStick::DrawFirstPersonEffects( void ) -{ - Vector vecOrigin; - QAngle vecAngles; - float color[3]; - float scale; - - CMatRenderContextPtr pRenderContext( materials ); - IMaterial *pMaterial = materials->FindMaterial( STUNSTICK_GLOW_MATERIAL_NOZ, NULL, false ); - // FIXME: Needs to work with new IMaterial system! - pRenderContext->Bind( pMaterial ); - - // Find where we are in the fade - float fadeAmount = RemapValClamped( gpGlobals->curtime, m_flFadeTime, m_flFadeTime + FADE_DURATION, 1.0f, 0.1f ); - - // Get bright when swung - if ( InSwing() ) - { - color[0] = color[1] = color[2] = 0.4f; - scale = 22.0f; - } - else - { - color[0] = color[1] = color[2] = 0.4f * fadeAmount; - scale = 20.0f; - } - - if ( color[0] > 0.0f ) - { - // Draw an all encompassing glow around the entire head - UTIL_GetWeaponAttachment( this, m_BeamCenterAttachment, vecOrigin, vecAngles ); - DrawHalo( pMaterial, vecOrigin, scale, color ); - } - - // Draw bright points at each attachment location - for ( int i = 0; i < (NUM_BEAM_ATTACHMENTS*2)+1; i++ ) - { - if ( InSwing() ) - { - color[0] = color[1] = color[2] = random->RandomFloat( 0.05f, 0.5f ); - scale = random->RandomFloat( 4.0f, 5.0f ); - } - else - { - color[0] = color[1] = color[2] = random->RandomFloat( 0.05f, 0.5f ) * fadeAmount; - scale = random->RandomFloat( 4.0f, 5.0f ) * fadeAmount; - } - - if ( color[0] > 0.0f ) - { - UTIL_GetWeaponAttachment( this, i, vecOrigin, vecAngles ); - DrawHalo( pMaterial, vecOrigin, scale, color ); - } - } -} - -//----------------------------------------------------------------------------- -// Purpose: Draw our special effects -//----------------------------------------------------------------------------- -void C_WeaponStunStick::DrawEffects( void ) -{ - if ( ShouldDrawUsingViewModel() ) - { - DrawFirstPersonEffects(); - } - else - { - DrawThirdPersonEffects(); - } -} - -//----------------------------------------------------------------------------- -// Purpose: Viewmodel was drawn -//----------------------------------------------------------------------------- -void C_WeaponStunStick::ViewModelDrawn( C_BaseViewModel *pBaseViewModel ) -{ - // Don't bother when we're not deployed - if ( IsWeaponVisible() ) - { - // Do all our special effects - DrawEffects(); - } - - BaseClass::ViewModelDrawn( pBaseViewModel ); -} - -//----------------------------------------------------------------------------- -// Purpose: Draw a cheap glow quad at our impact point (with sparks) -//----------------------------------------------------------------------------- -void StunstickImpactCallback( const CEffectData &data ) -{ - float scale = random->RandomFloat( 16, 32 ); - - FX_AddQuad( data.m_vOrigin, - data.m_vNormal, - scale, - scale*2.0f, - 1.0f, - 1.0f, - 0.0f, - 0.0f, - random->RandomInt( 0, 360 ), - 0, - Vector( 1.0f, 1.0f, 1.0f ), - 0.1f, - "sprites/light_glow02_add", - 0 ); - - FX_Sparks( data.m_vOrigin, 1, 2, data.m_vNormal, 6, 64, 256 ); -} - -DECLARE_CLIENT_EFFECT( "StunstickImpact", StunstickImpactCallback ); - -#endif \ No newline at end of file diff --git a/sp/src/games.sln b/sp/src/games.sln index 8c0fe65c..395195d9 100644 --- a/sp/src/games.sln +++ b/sp/src/games.sln @@ -1,8 +1,11 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Express 2013 for Windows Desktop -VisualStudioVersion = 12.0.40629.0 -MinimumVisualStudioVersion = 10.0.40219.1 +# Visual Studio 2013 +# +# Automatically generated solution: +# devtools\bin\vpc /hl2 /episodic +game /mksln games.sln +# +# Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Client (HL2)", "game\client\client_hl2.vcxproj", "{09E5D61D-4897-7B98-288B-C87442D14BFF}" ProjectSection(ProjectDependencies) = postProject {BAB92FF0-D72A-D7E5-1988-74628D39B94F} = {BAB92FF0-D72A-D7E5-1988-74628D39B94F} @@ -37,46 +40,3 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "tier1", "tier1\tier1.vcxpro EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "vgui_controls", "vgui2\vgui_controls\vgui_controls.vcxproj", "{F69B3672-C5E8-CD1A-257F-253A25B5B939}" EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Win32 = Debug|Win32 - Release|Win32 = Release|Win32 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {09E5D61D-4897-7B98-288B-C87442D14BFF}.Debug|Win32.ActiveCfg = Debug|Win32 - {09E5D61D-4897-7B98-288B-C87442D14BFF}.Debug|Win32.Build.0 = Debug|Win32 - {09E5D61D-4897-7B98-288B-C87442D14BFF}.Release|Win32.ActiveCfg = Release|Win32 - {09E5D61D-4897-7B98-288B-C87442D14BFF}.Release|Win32.Build.0 = Release|Win32 - {353A799F-E73F-7A69-07AD-B2AD57F3B775}.Debug|Win32.ActiveCfg = Debug|Win32 - {353A799F-E73F-7A69-07AD-B2AD57F3B775}.Debug|Win32.Build.0 = Debug|Win32 - {353A799F-E73F-7A69-07AD-B2AD57F3B775}.Release|Win32.ActiveCfg = Release|Win32 - {353A799F-E73F-7A69-07AD-B2AD57F3B775}.Release|Win32.Build.0 = Release|Win32 - {BAB92FF0-D72A-D7E5-1988-74628D39B94F}.Debug|Win32.ActiveCfg = Debug|Win32 - {BAB92FF0-D72A-D7E5-1988-74628D39B94F}.Debug|Win32.Build.0 = Debug|Win32 - {BAB92FF0-D72A-D7E5-1988-74628D39B94F}.Release|Win32.ActiveCfg = Release|Win32 - {BAB92FF0-D72A-D7E5-1988-74628D39B94F}.Release|Win32.Build.0 = Release|Win32 - {95D67225-8415-236F-9128-DCB171B7DEC6}.Debug|Win32.ActiveCfg = Debug|Win32 - {95D67225-8415-236F-9128-DCB171B7DEC6}.Debug|Win32.Build.0 = Debug|Win32 - {95D67225-8415-236F-9128-DCB171B7DEC6}.Release|Win32.ActiveCfg = Release|Win32 - {95D67225-8415-236F-9128-DCB171B7DEC6}.Release|Win32.Build.0 = Release|Win32 - {C3EE918E-6836-5578-1FA2-5703048552B9}.Debug|Win32.ActiveCfg = Debug|Win32 - {C3EE918E-6836-5578-1FA2-5703048552B9}.Debug|Win32.Build.0 = Debug|Win32 - {C3EE918E-6836-5578-1FA2-5703048552B9}.Release|Win32.ActiveCfg = Release|Win32 - {C3EE918E-6836-5578-1FA2-5703048552B9}.Release|Win32.Build.0 = Release|Win32 - {7855B476-B6D4-535D-F7A9-D623245F8B07}.Debug|Win32.ActiveCfg = Debug|Win32 - {7855B476-B6D4-535D-F7A9-D623245F8B07}.Debug|Win32.Build.0 = Debug|Win32 - {7855B476-B6D4-535D-F7A9-D623245F8B07}.Release|Win32.ActiveCfg = Release|Win32 - {7855B476-B6D4-535D-F7A9-D623245F8B07}.Release|Win32.Build.0 = Release|Win32 - {EC1C516D-E1D9-BC0A-F79D-E91E954ED8EC}.Debug|Win32.ActiveCfg = Debug|Win32 - {EC1C516D-E1D9-BC0A-F79D-E91E954ED8EC}.Debug|Win32.Build.0 = Debug|Win32 - {EC1C516D-E1D9-BC0A-F79D-E91E954ED8EC}.Release|Win32.ActiveCfg = Release|Win32 - {EC1C516D-E1D9-BC0A-F79D-E91E954ED8EC}.Release|Win32.Build.0 = Release|Win32 - {F69B3672-C5E8-CD1A-257F-253A25B5B939}.Debug|Win32.ActiveCfg = Debug|Win32 - {F69B3672-C5E8-CD1A-257F-253A25B5B939}.Debug|Win32.Build.0 = Debug|Win32 - {F69B3672-C5E8-CD1A-257F-253A25B5B939}.Release|Win32.ActiveCfg = Release|Win32 - {F69B3672-C5E8-CD1A-257F-253A25B5B939}.Release|Win32.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal