2
0
mirror of https://github.com/FWGS/hlsdk-xash3d synced 2024-11-22 01:47:45 +01:00
hlsdk-xash3d/dlls/player.cpp

4936 lines
126 KiB
C++
Raw Normal View History

/***
2016-06-04 15:24:23 +02:00
*
* Copyright (c) 1996-2002, Valve LLC. All rights reserved.
*
* This product contains software technology licensed from Id
* Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc.
* All Rights Reserved.
*
* Use, distribution, and modification of this source code and/or resulting
* object code is restricted to non-commercial enhancements to products from
* Valve LLC. All other use, distribution, or modification is prohibited
* without written permission from Valve LLC.
*
****/
/*
===== player.cpp ========================================================
functions dealing with the player
*/
#include "extdll.h"
#include "util.h"
#include "cbase.h"
#include "player.h"
#include "trains.h"
#include "nodes.h"
#include "weapons.h"
#include "soundent.h"
#include "monsters.h"
#include "shake.h"
#include "decals.h"
#include "gamerules.h"
#include "game.h"
#include "pm_shared.h"
2016-06-04 15:24:23 +02:00
#include "hltv.h"
// #define DUCKFIX
2016-07-31 15:48:50 +02:00
extern DLL_GLOBAL ULONG g_ulModelIndexPlayer;
extern DLL_GLOBAL BOOL g_fGameOver;
extern DLL_GLOBAL BOOL g_fDrawLines;
2016-06-04 15:24:23 +02:00
int gEvilImpulse101;
2016-07-31 15:48:50 +02:00
extern DLL_GLOBAL int g_iSkillLevel, gDisplayTitle;
2016-06-04 15:24:23 +02:00
BOOL gInitHUD = TRUE;
2016-07-31 15:48:50 +02:00
extern void CopyToBodyQue( entvars_t *pev);
extern void respawn( entvars_t *pev, BOOL fCopyCorpse );
extern Vector VecBModelOrigin( entvars_t *pevBModel );
2016-06-04 15:24:23 +02:00
extern edict_t *EntSelectSpawnPoint( CBaseEntity *pPlayer );
// the world node graph
2016-07-31 15:48:50 +02:00
extern CGraph WorldGraph;
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
#define TRAIN_ACTIVE 0x80
2016-06-04 15:24:23 +02:00
#define TRAIN_NEW 0xc0
#define TRAIN_OFF 0x00
2016-07-31 15:48:50 +02:00
#define TRAIN_NEUTRAL 0x01
2016-06-04 15:24:23 +02:00
#define TRAIN_SLOW 0x02
2016-07-31 15:48:50 +02:00
#define TRAIN_MEDIUM 0x03
#define TRAIN_FAST 0x04
2016-06-04 15:24:23 +02:00
#define TRAIN_BACK 0x05
2019-10-13 13:49:25 +02:00
#define FLASH_DRAIN_TIME 1.2f //100 units/3 minutes
#define FLASH_CHARGE_TIME 0.2f // 100 units/20 seconds (seconds per unit)
2016-06-04 15:24:23 +02:00
// Global Savedata for player
TYPEDESCRIPTION CBasePlayer::m_playerSaveData[] =
2016-06-04 15:24:23 +02:00
{
DEFINE_FIELD( CBasePlayer, m_flFlashLightTime, FIELD_TIME ),
DEFINE_FIELD( CBasePlayer, m_iFlashBattery, FIELD_INTEGER ),
DEFINE_FIELD( CBasePlayer, m_afButtonLast, FIELD_INTEGER ),
DEFINE_FIELD( CBasePlayer, m_afButtonPressed, FIELD_INTEGER ),
DEFINE_FIELD( CBasePlayer, m_afButtonReleased, FIELD_INTEGER ),
DEFINE_ARRAY( CBasePlayer, m_rgItems, FIELD_INTEGER, MAX_ITEMS ),
DEFINE_FIELD( CBasePlayer, m_afPhysicsFlags, FIELD_INTEGER ),
DEFINE_FIELD( CBasePlayer, m_flTimeStepSound, FIELD_TIME ),
DEFINE_FIELD( CBasePlayer, m_flTimeWeaponIdle, FIELD_TIME ),
DEFINE_FIELD( CBasePlayer, m_flSwimTime, FIELD_TIME ),
DEFINE_FIELD( CBasePlayer, m_flDuckTime, FIELD_TIME ),
DEFINE_FIELD( CBasePlayer, m_flWallJumpTime, FIELD_TIME ),
DEFINE_FIELD( CBasePlayer, m_flSuitUpdate, FIELD_TIME ),
DEFINE_ARRAY( CBasePlayer, m_rgSuitPlayList, FIELD_INTEGER, CSUITPLAYLIST ),
DEFINE_FIELD( CBasePlayer, m_iSuitPlayNext, FIELD_INTEGER ),
DEFINE_ARRAY( CBasePlayer, m_rgiSuitNoRepeat, FIELD_INTEGER, CSUITNOREPEAT ),
DEFINE_ARRAY( CBasePlayer, m_rgflSuitNoRepeatTime, FIELD_TIME, CSUITNOREPEAT ),
DEFINE_FIELD( CBasePlayer, m_lastDamageAmount, FIELD_INTEGER ),
DEFINE_ARRAY( CBasePlayer, m_rgpPlayerItems, FIELD_CLASSPTR, MAX_ITEM_TYPES ),
DEFINE_FIELD( CBasePlayer, m_pActiveItem, FIELD_CLASSPTR ),
DEFINE_FIELD( CBasePlayer, m_pLastItem, FIELD_CLASSPTR ),
2016-06-04 15:24:23 +02:00
DEFINE_ARRAY( CBasePlayer, m_rgAmmo, FIELD_INTEGER, MAX_AMMO_SLOTS ),
DEFINE_FIELD( CBasePlayer, m_idrowndmg, FIELD_INTEGER ),
DEFINE_FIELD( CBasePlayer, m_idrownrestored, FIELD_INTEGER ),
DEFINE_FIELD( CBasePlayer, m_tSneaking, FIELD_TIME ),
DEFINE_FIELD( CBasePlayer, m_iTrain, FIELD_INTEGER ),
DEFINE_FIELD( CBasePlayer, m_bitsHUDDamage, FIELD_INTEGER ),
DEFINE_FIELD( CBasePlayer, m_flFallVelocity, FIELD_FLOAT ),
DEFINE_FIELD( CBasePlayer, m_iTargetVolume, FIELD_INTEGER ),
DEFINE_FIELD( CBasePlayer, m_iWeaponVolume, FIELD_INTEGER ),
DEFINE_FIELD( CBasePlayer, m_iExtraSoundTypes, FIELD_INTEGER ),
DEFINE_FIELD( CBasePlayer, m_iWeaponFlash, FIELD_INTEGER ),
DEFINE_FIELD( CBasePlayer, m_fLongJump, FIELD_BOOLEAN ),
DEFINE_FIELD( CBasePlayer, m_fInitHUD, FIELD_BOOLEAN ),
DEFINE_FIELD( CBasePlayer, m_tbdPrev, FIELD_TIME ),
DEFINE_FIELD( CBasePlayer, m_pTank, FIELD_EHANDLE ),
DEFINE_FIELD( CBasePlayer, m_iHideHUD, FIELD_INTEGER ),
DEFINE_FIELD( CBasePlayer, m_iFOV, FIELD_INTEGER ),
2016-06-04 15:24:23 +02:00
//DEFINE_FIELD( CBasePlayer, m_fDeadTime, FIELD_FLOAT ), // only used in multiplayer games
//DEFINE_FIELD( CBasePlayer, m_fGameHUDInitialized, FIELD_INTEGER ), // only used in multiplayer games
//DEFINE_FIELD( CBasePlayer, m_flStopExtraSoundTime, FIELD_TIME ),
//DEFINE_FIELD( CBasePlayer, m_fKnownItem, FIELD_INTEGER ), // reset to zero on load
//DEFINE_FIELD( CBasePlayer, m_iPlayerSound, FIELD_INTEGER ), // Don't restore, set in Precache()
//DEFINE_FIELD( CBasePlayer, m_pentSndLast, FIELD_EDICT ), // Don't restore, client needs reset
//DEFINE_FIELD( CBasePlayer, m_flSndRoomtype, FIELD_FLOAT ), // Don't restore, client needs reset
//DEFINE_FIELD( CBasePlayer, m_flSndRange, FIELD_FLOAT ), // Don't restore, client needs reset
//DEFINE_FIELD( CBasePlayer, m_fNewAmmo, FIELD_INTEGER ), // Don't restore, client needs reset
//DEFINE_FIELD( CBasePlayer, m_flgeigerRange, FIELD_FLOAT ), // Don't restore, reset in Precache()
//DEFINE_FIELD( CBasePlayer, m_flgeigerDelay, FIELD_FLOAT ), // Don't restore, reset in Precache()
//DEFINE_FIELD( CBasePlayer, m_igeigerRangePrev, FIELD_FLOAT ), // Don't restore, reset in Precache()
//DEFINE_FIELD( CBasePlayer, m_iStepLeft, FIELD_INTEGER ), // Don't need to restore
//DEFINE_ARRAY( CBasePlayer, m_szTextureName, FIELD_CHARACTER, CBTEXTURENAMEMAX ), // Don't need to restore
//DEFINE_FIELD( CBasePlayer, m_chTextureType, FIELD_CHARACTER ), // Don't need to restore
//DEFINE_FIELD( CBasePlayer, m_fNoPlayerSound, FIELD_BOOLEAN ), // Don't need to restore, debug
//DEFINE_FIELD( CBasePlayer, m_iUpdateTime, FIELD_INTEGER ), // Don't need to restore
//DEFINE_FIELD( CBasePlayer, m_iClientHealth, FIELD_INTEGER ), // Don't restore, client needs reset
//DEFINE_FIELD( CBasePlayer, m_iClientBattery, FIELD_INTEGER ), // Don't restore, client needs reset
//DEFINE_FIELD( CBasePlayer, m_iClientHideHUD, FIELD_INTEGER ), // Don't restore, client needs reset
//DEFINE_FIELD( CBasePlayer, m_fWeapon, FIELD_BOOLEAN ), // Don't restore, client needs reset
//DEFINE_FIELD( CBasePlayer, m_nCustomSprayFrames, FIELD_INTEGER ), // Don't restore, depends on server message after spawning and only matters in multiplayer
//DEFINE_FIELD( CBasePlayer, m_vecAutoAim, FIELD_VECTOR ), // Don't save/restore - this is recomputed
//DEFINE_ARRAY( CBasePlayer, m_rgAmmoLast, FIELD_INTEGER, MAX_AMMO_SLOTS ), // Don't need to restore
//DEFINE_FIELD( CBasePlayer, m_fOnTarget, FIELD_BOOLEAN ), // Don't need to restore
//DEFINE_FIELD( CBasePlayer, m_nCustomSprayFrames, FIELD_INTEGER ), // Don't need to restore
};
int giPrecacheGrunt = 0;
int gmsgShake = 0;
int gmsgFade = 0;
int gmsgSelAmmo = 0;
int gmsgFlashlight = 0;
int gmsgFlashBattery = 0;
int gmsgResetHUD = 0;
int gmsgInitHUD = 0;
int gmsgShowGameTitle = 0;
int gmsgCurWeapon = 0;
int gmsgHealth = 0;
int gmsgDamage = 0;
int gmsgBattery = 0;
int gmsgTrain = 0;
int gmsgLogo = 0;
int gmsgWeaponList = 0;
int gmsgAmmoX = 0;
int gmsgHudText = 0;
int gmsgDeathMsg = 0;
int gmsgScoreInfo = 0;
int gmsgTeamInfo = 0;
int gmsgTeamScore = 0;
int gmsgGameMode = 0;
int gmsgMOTD = 0;
int gmsgServerName = 0;
int gmsgAmmoPickup = 0;
int gmsgWeapPickup = 0;
int gmsgItemPickup = 0;
int gmsgHideWeapon = 0;
int gmsgSetCurWeap = 0;
int gmsgSayText = 0;
int gmsgTextMsg = 0;
int gmsgSetFOV = 0;
int gmsgShowMenu = 0;
int gmsgGeigerRange = 0;
int gmsgTeamNames = 0;
int gmsgStatusText = 0;
2016-07-31 15:48:50 +02:00
int gmsgStatusValue = 0;
2016-06-04 15:24:23 +02:00
void LinkUserMessages( void )
{
// Already taken care of?
2016-07-31 15:48:50 +02:00
if( gmsgSelAmmo )
2016-06-04 15:24:23 +02:00
{
return;
}
2016-07-31 15:48:50 +02:00
gmsgSelAmmo = REG_USER_MSG( "SelAmmo", sizeof(SelAmmo) );
gmsgCurWeapon = REG_USER_MSG( "CurWeapon", 3 );
gmsgGeigerRange = REG_USER_MSG( "Geiger", 1 );
gmsgFlashlight = REG_USER_MSG( "Flashlight", 2 );
gmsgFlashBattery = REG_USER_MSG( "FlashBat", 1 );
2016-06-04 15:24:23 +02:00
gmsgHealth = REG_USER_MSG( "Health", 1 );
gmsgDamage = REG_USER_MSG( "Damage", 12 );
gmsgBattery = REG_USER_MSG( "Battery", 2);
2016-07-31 15:48:50 +02:00
gmsgTrain = REG_USER_MSG( "Train", 1 );
//gmsgHudText = REG_USER_MSG( "HudTextPro", -1 );
gmsgHudText = REG_USER_MSG( "HudText", -1 ); // we don't use the message but 3rd party addons may!
2016-06-04 15:24:23 +02:00
gmsgSayText = REG_USER_MSG( "SayText", -1 );
gmsgTextMsg = REG_USER_MSG( "TextMsg", -1 );
2016-07-31 15:48:50 +02:00
gmsgWeaponList = REG_USER_MSG( "WeaponList", -1 );
gmsgResetHUD = REG_USER_MSG( "ResetHUD", 1 ); // called every respawn
gmsgInitHUD = REG_USER_MSG( "InitHUD", 0 ); // called every time a new player joins the server
gmsgShowGameTitle = REG_USER_MSG( "GameTitle", 1 );
2016-06-04 15:24:23 +02:00
gmsgDeathMsg = REG_USER_MSG( "DeathMsg", -1 );
gmsgScoreInfo = REG_USER_MSG( "ScoreInfo", 9 );
gmsgTeamInfo = REG_USER_MSG( "TeamInfo", -1 ); // sets the name of a player's team
gmsgTeamScore = REG_USER_MSG( "TeamScore", -1 ); // sets the score of a team on the scoreboard
gmsgGameMode = REG_USER_MSG( "GameMode", 1 );
gmsgMOTD = REG_USER_MSG( "MOTD", -1 );
gmsgServerName = REG_USER_MSG( "ServerName", -1 );
gmsgAmmoPickup = REG_USER_MSG( "AmmoPickup", 2 );
gmsgWeapPickup = REG_USER_MSG( "WeapPickup", 1 );
gmsgItemPickup = REG_USER_MSG( "ItemPickup", -1 );
gmsgHideWeapon = REG_USER_MSG( "HideWeapon", 1 );
gmsgSetFOV = REG_USER_MSG( "SetFOV", 1 );
gmsgShowMenu = REG_USER_MSG( "ShowMenu", -1 );
2016-07-31 15:48:50 +02:00
gmsgShake = REG_USER_MSG( "ScreenShake", sizeof(ScreenShake) );
gmsgFade = REG_USER_MSG( "ScreenFade", sizeof(ScreenFade) );
gmsgAmmoX = REG_USER_MSG( "AmmoX", 2 );
2016-06-04 15:24:23 +02:00
gmsgTeamNames = REG_USER_MSG( "TeamNames", -1 );
2016-07-31 15:48:50 +02:00
gmsgStatusText = REG_USER_MSG( "StatusText", -1 );
gmsgStatusValue = REG_USER_MSG( "StatusValue", 3 );
2016-06-04 15:24:23 +02:00
}
LINK_ENTITY_TO_CLASS( player, CBasePlayer )
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
void CBasePlayer::Pain( void )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
float flRndSound;//sound randomizer
2016-06-04 15:24:23 +02:00
2019-10-13 13:49:25 +02:00
flRndSound = RANDOM_FLOAT( 0.0f, 1.0f );
2019-10-13 13:49:25 +02:00
if( flRndSound <= 0.33f )
2016-07-31 15:48:50 +02:00
EMIT_SOUND( ENT( pev ), CHAN_VOICE, "player/pl_pain5.wav", 1, ATTN_NORM );
2019-10-13 13:49:25 +02:00
else if( flRndSound <= 0.66f )
2016-07-31 15:48:50 +02:00
EMIT_SOUND( ENT( pev ), CHAN_VOICE, "player/pl_pain6.wav", 1, ATTN_NORM );
2016-06-04 15:24:23 +02:00
else
2016-07-31 15:48:50 +02:00
EMIT_SOUND( ENT( pev ), CHAN_VOICE, "player/pl_pain7.wav", 1, ATTN_NORM );
2016-06-04 15:24:23 +02:00
}
2016-07-31 15:48:50 +02:00
Vector VecVelocityForDamage( float flDamage )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
Vector vec( RANDOM_FLOAT( -100, 100 ), RANDOM_FLOAT( -100, 100 ), RANDOM_FLOAT( 200, 300 ) );
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
if( flDamage > -50 )
2019-10-13 13:49:25 +02:00
vec = vec * 0.7f;
2016-07-31 15:48:50 +02:00
else if( flDamage > -200 )
2016-06-04 15:24:23 +02:00
vec = vec * 2;
else
vec = vec * 10;
2016-06-04 15:24:23 +02:00
return vec;
}
2016-07-31 15:48:50 +02:00
#if 0
static void ThrowGib( entvars_t *pev, char *szGibModel, float flDamage )
2016-06-04 15:24:23 +02:00
{
edict_t *pentNew = CREATE_ENTITY();
2016-07-31 15:48:50 +02:00
entvars_t *pevNew = VARS( pentNew );
2016-06-04 15:24:23 +02:00
pevNew->origin = pev->origin;
2016-07-31 15:48:50 +02:00
SET_MODEL( ENT( pevNew ), szGibModel );
UTIL_SetSize( pevNew, g_vecZero, g_vecZero );
pevNew->velocity = VecVelocityForDamage( flDamage );
pevNew->movetype = MOVETYPE_BOUNCE;
pevNew->solid = SOLID_NOT;
pevNew->avelocity.x = RANDOM_FLOAT( 0, 600 );
pevNew->avelocity.y = RANDOM_FLOAT( 0, 600 );
pevNew->avelocity.z = RANDOM_FLOAT( 0, 600 );
CHANGE_METHOD( ENT( pevNew ), em_think, SUB_Remove );
pevNew->ltime = gpGlobals->time;
pevNew->nextthink = gpGlobals->time + RANDOM_FLOAT( 10, 20 );
pevNew->frame = 0;
pevNew->flags = 0;
2016-06-04 15:24:23 +02:00
}
2016-07-31 15:48:50 +02:00
static void ThrowHead( entvars_t *pev, char *szGibModel, floatflDamage )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
SET_MODEL( ENT( pev ), szGibModel );
pev->frame = 0;
pev->nextthink = -1;
pev->movetype = MOVETYPE_BOUNCE;
pev->takedamage = DAMAGE_NO;
pev->solid = SOLID_NOT;
pev->view_ofs = Vector( 0, 0, 8 );
UTIL_SetSize( pev, Vector( -16, -16, 0 ), Vector( 16, 16, 56 ) );
pev->velocity = VecVelocityForDamage( flDamage );
pev->avelocity = RANDOM_FLOAT( -1, 1 ) * Vector( 0, 600, 0 );
2016-06-04 15:24:23 +02:00
pev->origin.z -= 24;
2016-07-31 15:48:50 +02:00
ClearBits( pev->flags, FL_ONGROUND );
2016-06-04 15:24:23 +02:00
}
#endif
2016-07-31 15:48:50 +02:00
int TrainSpeed( int iSpeed, int iMax )
2016-06-04 15:24:23 +02:00
{
float fSpeed, fMax;
int iRet = 0;
fMax = (float)iMax;
fSpeed = iSpeed;
2019-10-13 13:49:25 +02:00
fSpeed = fSpeed / fMax;
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
if( iSpeed < 0 )
2016-06-04 15:24:23 +02:00
iRet = TRAIN_BACK;
2019-10-13 13:49:25 +02:00
else if( iSpeed == 0.0f )
2016-06-04 15:24:23 +02:00
iRet = TRAIN_NEUTRAL;
2019-10-13 13:49:25 +02:00
else if( fSpeed < 0.33f )
2016-06-04 15:24:23 +02:00
iRet = TRAIN_SLOW;
2019-10-13 13:49:25 +02:00
else if( fSpeed < 0.66f )
2016-06-04 15:24:23 +02:00
iRet = TRAIN_MEDIUM;
else
iRet = TRAIN_FAST;
return iRet;
}
2016-07-31 15:48:50 +02:00
void CBasePlayer::DeathSound( void )
2016-06-04 15:24:23 +02:00
{
// water death sounds
/*
2016-07-31 15:48:50 +02:00
if( pev->waterlevel == 3 )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
EMIT_SOUND( ENT( pev ), CHAN_VOICE, "player/h2odeath.wav", 1, ATTN_NONE );
2016-06-04 15:24:23 +02:00
return;
}
*/
// temporarily using pain sounds for death sounds
2016-07-31 15:48:50 +02:00
switch( RANDOM_LONG( 1, 5 ) )
2016-06-04 15:24:23 +02:00
{
case 1:
2016-07-31 15:48:50 +02:00
EMIT_SOUND( ENT( pev ), CHAN_VOICE, "player/pl_pain5.wav", 1, ATTN_NORM );
2016-06-04 15:24:23 +02:00
break;
case 2:
2016-07-31 15:48:50 +02:00
EMIT_SOUND( ENT( pev ), CHAN_VOICE, "player/pl_pain6.wav", 1, ATTN_NORM );
2016-06-04 15:24:23 +02:00
break;
case 3:
2016-07-31 15:48:50 +02:00
EMIT_SOUND( ENT( pev ), CHAN_VOICE, "player/pl_pain7.wav", 1, ATTN_NORM );
2016-06-04 15:24:23 +02:00
break;
}
// play one of the suit death alarms
2016-07-31 15:48:50 +02:00
EMIT_GROUPNAME_SUIT( ENT( pev ), "HEV_DEAD" );
2016-06-04 15:24:23 +02:00
}
// override takehealth
// bitsDamageType indicates type of damage healed.
2016-07-31 15:48:50 +02:00
int CBasePlayer::TakeHealth( float flHealth, int bitsDamageType )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
return CBaseMonster::TakeHealth( flHealth, bitsDamageType );
2016-06-04 15:24:23 +02:00
}
2016-07-31 15:48:50 +02:00
Vector CBasePlayer::GetGunPosition()
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
//UTIL_MakeVectors( pev->v_angle );
//m_HackedGunPos = pev->view_ofs;
2016-06-04 15:24:23 +02:00
Vector origin;
2016-06-04 15:24:23 +02:00
origin = pev->origin + pev->view_ofs;
return origin;
}
//=========================================================
// TraceAttack
//=========================================================
2016-07-31 15:48:50 +02:00
void CBasePlayer::TraceAttack( entvars_t *pevAttacker, float flDamage, Vector vecDir, TraceResult *ptr, int bitsDamageType )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( pev->takedamage )
2016-06-04 15:24:23 +02:00
{
m_LastHitGroup = ptr->iHitgroup;
2016-07-31 15:48:50 +02:00
switch( ptr->iHitgroup )
2016-06-04 15:24:23 +02:00
{
case HITGROUP_GENERIC:
break;
case HITGROUP_HEAD:
flDamage *= gSkillData.plrHead;
break;
case HITGROUP_CHEST:
flDamage *= gSkillData.plrChest;
break;
case HITGROUP_STOMACH:
flDamage *= gSkillData.plrStomach;
break;
case HITGROUP_LEFTARM:
case HITGROUP_RIGHTARM:
flDamage *= gSkillData.plrArm;
break;
case HITGROUP_LEFTLEG:
case HITGROUP_RIGHTLEG:
flDamage *= gSkillData.plrLeg;
break;
default:
break;
}
2016-07-31 15:48:50 +02:00
SpawnBlood( ptr->vecEndPos, BloodColor(), flDamage );// a little surface blood.
2016-06-04 15:24:23 +02:00
TraceBleed( flDamage, vecDir, ptr, bitsDamageType );
AddMultiDamage( pevAttacker, this, flDamage, bitsDamageType );
}
}
/*
Take some damage.
NOTE: each call to TakeDamage with bitsDamageType set to a time-based damage
type will cause the damage time countdown to be reset. Thus the ongoing effects of poison, radiation
etc are implemented with subsequent calls to TakeDamage using DMG_GENERIC.
*/
2016-07-31 15:48:50 +02:00
#define ARMOR_RATIO 0.2 // Armor Takes 80% of the damage
#define ARMOR_BONUS 0.5 // Each Point of Armor is work 1/x points of health
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
int CBasePlayer::TakeDamage( entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, int bitsDamageType )
2016-06-04 15:24:23 +02:00
{
// have suit diagnose the problem - ie: report damage type
int bitsDamage = bitsDamageType;
int ffound = TRUE;
int fmajor;
int fcritical;
int fTookDamage;
int ftrivial;
float flRatio;
float flBonus;
float flHealthPrev = pev->health;
flBonus = ARMOR_BONUS;
flRatio = ARMOR_RATIO;
2016-07-31 15:48:50 +02:00
if( ( bitsDamageType & DMG_BLAST ) && g_pGameRules->IsMultiplayer() )
2016-06-04 15:24:23 +02:00
{
// blasts damage armor more.
flBonus *= 2;
}
// Already dead
2016-07-31 15:48:50 +02:00
if( !IsAlive() )
2016-06-04 15:24:23 +02:00
return 0;
2016-07-31 15:48:50 +02:00
// go take the damage first
CBaseEntity *pAttacker = CBaseEntity::Instance( pevAttacker );
2016-07-31 15:48:50 +02:00
if( !g_pGameRules->FPlayerCanTakeDamage( this, pAttacker ) )
2016-06-04 15:24:23 +02:00
{
// Refuse the damage
return 0;
}
// keep track of amount of damage last sustained
2017-06-29 15:56:03 +02:00
m_lastDamageAmount = (int)flDamage;
2016-06-04 15:24:23 +02:00
// Armor.
if( !( pev->flags & FL_GODMODE ) && pev->armorvalue && !( bitsDamageType & ( DMG_FALL | DMG_DROWN ) ) )// armor doesn't protect against fall or drown damage!
2016-06-04 15:24:23 +02:00
{
float flNew = flDamage * flRatio;
float flArmor;
2016-07-31 15:48:50 +02:00
flArmor = ( flDamage - flNew ) * flBonus;
2016-06-04 15:24:23 +02:00
// Does this use more armor than we have?
2016-07-31 15:48:50 +02:00
if( flArmor > pev->armorvalue )
2016-06-04 15:24:23 +02:00
{
flArmor = pev->armorvalue;
2016-07-31 15:48:50 +02:00
flArmor *= ( 1 / flBonus );
2016-06-04 15:24:23 +02:00
flNew = flDamage - flArmor;
pev->armorvalue = 0;
}
else
pev->armorvalue -= flArmor;
2016-07-31 15:48:50 +02:00
2016-06-04 15:24:23 +02:00
flDamage = flNew;
}
// this cast to INT is critical!!! If a player ends up with 0.5 health, the engine will get that
// as an int (zero) and think the player is dead! (this will incite a clientside screentilt, etc)
2016-07-31 15:48:50 +02:00
fTookDamage = CBaseMonster::TakeDamage( pevInflictor, pevAttacker, (int)flDamage, bitsDamageType );
2016-06-04 15:24:23 +02:00
// reset damage time countdown for each type of time based damage player just sustained
{
2016-07-31 15:48:50 +02:00
for( int i = 0; i < CDMG_TIMEBASED; i++ )
if( bitsDamageType & ( DMG_PARALYZE << i ) )
2016-06-04 15:24:23 +02:00
m_rgbTimeBasedDamage[i] = 0;
}
// tell director about it
MESSAGE_BEGIN( MSG_SPEC, SVC_DIRECTOR );
2016-07-31 15:48:50 +02:00
WRITE_BYTE( 9 ); // command length in bytes
WRITE_BYTE( DRC_CMD_EVENT ); // take damage event
WRITE_SHORT( ENTINDEX( this->edict() ) ); // index number of primary entity
WRITE_SHORT( ENTINDEX( ENT( pevInflictor ) ) ); // index number of secondary entity
2016-06-04 15:24:23 +02:00
WRITE_LONG( 5 ); // eventflags (priority and flags)
MESSAGE_END();
// how bad is it, doc?
2016-07-31 15:48:50 +02:00
ftrivial = ( pev->health > 75 || m_lastDamageAmount < 5 );
fmajor = ( m_lastDamageAmount > 25 );
fcritical = ( pev->health < 30 );
2016-06-04 15:24:23 +02:00
// handle all bits set in this damage message,
// let the suit give player the diagnosis
// UNDONE: add sounds for types of damage sustained (ie: burn, shock, slash )
// UNDONE: still need to record damage and heal messages for the following types
2016-07-31 15:48:50 +02:00
// DMG_BURN
2016-06-04 15:24:23 +02:00
// DMG_FREEZE
// DMG_BLAST
// DMG_SHOCK
m_bitsDamageType |= bitsDamage; // Save this so we can report it to the client
m_bitsHUDDamage = -1; // make sure the damage bits get resent
2016-07-31 15:48:50 +02:00
while( fTookDamage && ( !ftrivial || ( bitsDamage & DMG_TIMEBASED ) ) && ffound && bitsDamage )
2016-06-04 15:24:23 +02:00
{
ffound = FALSE;
2016-07-31 15:48:50 +02:00
if( bitsDamage & DMG_CLUB )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( fmajor )
SetSuitUpdate( "!HEV_DMG4", FALSE, SUIT_NEXT_IN_30SEC ); // minor fracture
2016-06-04 15:24:23 +02:00
bitsDamage &= ~DMG_CLUB;
ffound = TRUE;
}
2016-07-31 15:48:50 +02:00
if( bitsDamage & ( DMG_FALL | DMG_CRUSH ) )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( fmajor )
SetSuitUpdate( "!HEV_DMG5", FALSE, SUIT_NEXT_IN_30SEC ); // major fracture
2016-06-04 15:24:23 +02:00
else
2016-07-31 15:48:50 +02:00
SetSuitUpdate( "!HEV_DMG4", FALSE, SUIT_NEXT_IN_30SEC ); // minor fracture
2016-07-31 15:48:50 +02:00
bitsDamage &= ~( DMG_FALL | DMG_CRUSH );
2016-06-04 15:24:23 +02:00
ffound = TRUE;
}
2016-07-31 15:48:50 +02:00
if( bitsDamage & DMG_BULLET )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( m_lastDamageAmount > 5 )
SetSuitUpdate( "!HEV_DMG6", FALSE, SUIT_NEXT_IN_30SEC ); // blood loss detected
2016-06-04 15:24:23 +02:00
//else
2016-07-31 15:48:50 +02:00
// SetSuitUpdate( "!HEV_DMG0", FALSE, SUIT_NEXT_IN_30SEC ); // minor laceration
2016-06-04 15:24:23 +02:00
bitsDamage &= ~DMG_BULLET;
ffound = TRUE;
}
2016-07-31 15:48:50 +02:00
if( bitsDamage & DMG_SLASH )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( fmajor )
SetSuitUpdate( "!HEV_DMG1", FALSE, SUIT_NEXT_IN_30SEC ); // major laceration
2016-06-04 15:24:23 +02:00
else
2016-07-31 15:48:50 +02:00
SetSuitUpdate( "!HEV_DMG0", FALSE, SUIT_NEXT_IN_30SEC ); // minor laceration
2016-06-04 15:24:23 +02:00
bitsDamage &= ~DMG_SLASH;
ffound = TRUE;
}
2016-07-31 15:48:50 +02:00
if( bitsDamage & DMG_SONIC )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( fmajor )
SetSuitUpdate( "!HEV_DMG2", FALSE, SUIT_NEXT_IN_1MIN ); // internal bleeding
2016-06-04 15:24:23 +02:00
bitsDamage &= ~DMG_SONIC;
ffound = TRUE;
}
2016-07-31 15:48:50 +02:00
if( bitsDamage & ( DMG_POISON | DMG_PARALYZE ) )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
SetSuitUpdate( "!HEV_DMG3", FALSE, SUIT_NEXT_IN_1MIN ); // blood toxins detected
bitsDamage &= ~( DMG_POISON | DMG_PARALYZE );
2016-06-04 15:24:23 +02:00
ffound = TRUE;
}
2016-07-31 15:48:50 +02:00
if( bitsDamage & DMG_ACID )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
SetSuitUpdate( "!HEV_DET1", FALSE, SUIT_NEXT_IN_1MIN ); // hazardous chemicals detected
2016-06-04 15:24:23 +02:00
bitsDamage &= ~DMG_ACID;
ffound = TRUE;
}
2016-07-31 15:48:50 +02:00
if( bitsDamage & DMG_NERVEGAS )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
SetSuitUpdate( "!HEV_DET0", FALSE, SUIT_NEXT_IN_1MIN ); // biohazard detected
2016-06-04 15:24:23 +02:00
bitsDamage &= ~DMG_NERVEGAS;
ffound = TRUE;
}
2016-07-31 15:48:50 +02:00
if( bitsDamage & DMG_RADIATION )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
SetSuitUpdate( "!HEV_DET2", FALSE, SUIT_NEXT_IN_1MIN ); // radiation detected
2016-06-04 15:24:23 +02:00
bitsDamage &= ~DMG_RADIATION;
ffound = TRUE;
}
2016-07-31 15:48:50 +02:00
if( bitsDamage & DMG_SHOCK )
2016-06-04 15:24:23 +02:00
{
bitsDamage &= ~DMG_SHOCK;
ffound = TRUE;
}
}
pev->punchangle.x = -2;
2016-07-31 15:48:50 +02:00
if( fTookDamage && !ftrivial && fmajor && flHealthPrev >= 75 )
2016-06-04 15:24:23 +02:00
{
// first time we take major damage...
// turn automedic on if not on
2016-07-31 15:48:50 +02:00
SetSuitUpdate( "!HEV_MED1", FALSE, SUIT_NEXT_IN_30MIN ); // automedic on
2016-06-04 15:24:23 +02:00
// give morphine shot if not given recently
2016-07-31 15:48:50 +02:00
SetSuitUpdate( "!HEV_HEAL7", FALSE, SUIT_NEXT_IN_30MIN ); // morphine shot
2016-06-04 15:24:23 +02:00
}
2016-07-31 15:48:50 +02:00
if( fTookDamage && !ftrivial && fcritical && flHealthPrev < 75 )
2016-06-04 15:24:23 +02:00
{
// already took major damage, now it's critical...
2016-07-31 15:48:50 +02:00
if( pev->health < 6 )
SetSuitUpdate( "!HEV_HLTH3", FALSE, SUIT_NEXT_IN_10MIN ); // near death
else if( pev->health < 20 )
SetSuitUpdate( "!HEV_HLTH2", FALSE, SUIT_NEXT_IN_10MIN ); // health critical
2016-06-04 15:24:23 +02:00
// give critical health warnings
2016-07-31 15:48:50 +02:00
if( !RANDOM_LONG( 0, 3 ) && flHealthPrev < 50 )
SetSuitUpdate( "!HEV_DMG7", FALSE, SUIT_NEXT_IN_5MIN ); //seek medical attention
2016-06-04 15:24:23 +02:00
}
// if we're taking time based damage, warn about its continuing effects
2016-07-31 15:48:50 +02:00
if( fTookDamage && ( bitsDamageType & DMG_TIMEBASED ) && flHealthPrev < 75 )
{
if( flHealthPrev < 50 )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( !RANDOM_LONG( 0, 3 ) )
SetSuitUpdate( "!HEV_DMG7", FALSE, SUIT_NEXT_IN_5MIN ); //seek medical attention
2016-06-04 15:24:23 +02:00
}
2016-07-31 15:48:50 +02:00
else
SetSuitUpdate( "!HEV_HLTH1", FALSE, SUIT_NEXT_IN_10MIN ); // health dropping
}
2016-06-04 15:24:23 +02:00
return fTookDamage;
}
//=========================================================
// PackDeadPlayerItems - call this when a player dies to
// pack up the appropriate weapons and ammo items, and to
// destroy anything that shouldn't be packed.
//
// This is pretty brute force :(
//=========================================================
void CBasePlayer::PackDeadPlayerItems( void )
{
int iWeaponRules;
int iAmmoRules;
2024-02-03 18:58:03 +01:00
int i, j;
2017-10-14 21:12:26 +02:00
CBasePlayerWeapon *rgpPackWeapons[MAX_WEAPONS] = {0,};
int iPackAmmo[MAX_AMMO_SLOTS];
2016-06-04 15:24:23 +02:00
int iPW = 0;// index into packweapons array
int iPA = 0;// index into packammo array
2016-07-31 15:48:50 +02:00
memset( iPackAmmo, -1, sizeof(iPackAmmo) );
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
// get the game rules
2016-06-04 15:24:23 +02:00
iWeaponRules = g_pGameRules->DeadPlayerWeapons( this );
iAmmoRules = g_pGameRules->DeadPlayerAmmo( this );
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
if( iWeaponRules == GR_PLR_DROP_GUN_NO && iAmmoRules == GR_PLR_DROP_AMMO_NO )
2016-06-04 15:24:23 +02:00
{
// nothing to pack. Remove the weapons and return. Don't call create on the box!
RemoveAllItems( TRUE );
return;
}
// go through all of the weapons and make a list of the ones to pack
for( i = 0; i < MAX_ITEM_TYPES && iPW < MAX_WEAPONS; i++ )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( m_rgpPlayerItems[i] )
2016-06-04 15:24:23 +02:00
{
// there's a weapon here. Should I pack it?
2016-07-31 15:48:50 +02:00
CBasePlayerItem *pPlayerItem = m_rgpPlayerItems[i];
2016-06-04 15:24:23 +02:00
while( pPlayerItem && iPW < MAX_WEAPONS )
2016-06-04 15:24:23 +02:00
{
switch( iWeaponRules )
{
case GR_PLR_DROP_GUN_ACTIVE:
2016-07-31 15:48:50 +02:00
if( m_pActiveItem && pPlayerItem == m_pActiveItem )
2016-06-04 15:24:23 +02:00
{
// this is the active item. Pack it.
2024-02-03 18:58:03 +01:00
rgpPackWeapons[iPW] = (CBasePlayerWeapon *)pPlayerItem;
2016-06-04 15:24:23 +02:00
}
break;
case GR_PLR_DROP_GUN_ALL:
2024-02-03 18:58:03 +01:00
rgpPackWeapons[iPW] = (CBasePlayerWeapon *)pPlayerItem;
2016-06-04 15:24:23 +02:00
break;
default:
break;
}
2024-02-03 18:58:03 +01:00
if( rgpPackWeapons[iPW] )
{
// complete the reload.
j = Q_min( rgpPackWeapons[iPW]->iMaxClip() - rgpPackWeapons[iPW]->m_iClip, m_rgAmmo[rgpPackWeapons[iPW]->m_iPrimaryAmmoType] );
// Add them to the clip
rgpPackWeapons[iPW]->m_iClip += j;
m_rgAmmo[rgpPackWeapons[iPW]->m_iPrimaryAmmoType] -= j;
iPW++;
}
2016-06-04 15:24:23 +02:00
pPlayerItem = pPlayerItem->m_pNext;
}
}
}
// now go through ammo and make a list of which types to pack.
2016-07-31 15:48:50 +02:00
if( iAmmoRules != GR_PLR_DROP_AMMO_NO )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
for( i = 0; i < MAX_AMMO_SLOTS; i++ )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( m_rgAmmo[i] > 0 )
2016-06-04 15:24:23 +02:00
{
// player has some ammo of this type.
2016-07-31 15:48:50 +02:00
switch( iAmmoRules )
2016-06-04 15:24:23 +02:00
{
case GR_PLR_DROP_AMMO_ALL:
2016-07-31 15:48:50 +02:00
iPackAmmo[iPA++] = i;
2016-06-04 15:24:23 +02:00
break;
case GR_PLR_DROP_AMMO_ACTIVE:
2016-07-31 15:48:50 +02:00
if( m_pActiveItem && i == m_pActiveItem->PrimaryAmmoIndex() )
2016-06-04 15:24:23 +02:00
{
// this is the primary ammo type for the active weapon
2016-07-31 15:48:50 +02:00
iPackAmmo[iPA++] = i;
2016-06-04 15:24:23 +02:00
}
2016-07-31 15:48:50 +02:00
else if( m_pActiveItem && i == m_pActiveItem->SecondaryAmmoIndex() )
2016-06-04 15:24:23 +02:00
{
// this is the secondary ammo type for the active weapon
2016-07-31 15:48:50 +02:00
iPackAmmo[iPA++] = i;
2016-06-04 15:24:23 +02:00
}
break;
default:
break;
}
}
}
}
// create a box to pack the stuff into.
2016-06-04 15:24:23 +02:00
CWeaponBox *pWeaponBox = (CWeaponBox *)CBaseEntity::Create( "weaponbox", pev->origin, pev->angles, edict() );
pWeaponBox->pev->angles.x = 0;// don't let weaponbox tilt.
pWeaponBox->pev->angles.z = 0;
pWeaponBox->SetThink( &CWeaponBox::Kill );
pWeaponBox->pev->nextthink = gpGlobals->time + 120;
// back these two lists up to their first elements
2016-06-04 15:24:23 +02:00
iPA = 0;
iPW = 0;
if( g_pGameRules->IsBustingGame())
2016-06-04 15:24:23 +02:00
{
while( rgpPackWeapons[iPW] )
{
// weapon unhooked from the player. Pack it into der box.
if( FClassnameIs( rgpPackWeapons[iPW]->pev, "weapon_egon" ))
{
pWeaponBox->PackWeapon( rgpPackWeapons[iPW] );
SET_MODEL( pWeaponBox->edict(), "models/w_egon.mdl" );
pWeaponBox->pev->velocity = g_vecZero;
pWeaponBox->pev->renderfx = kRenderFxGlowShell;
pWeaponBox->pev->renderamt = 25;
pWeaponBox->pev->rendercolor = Vector( 0, 75, 250 );
break;
}
iPW++;
}
2016-06-04 15:24:23 +02:00
}
else
2016-06-04 15:24:23 +02:00
{
// pack the ammo
while( iPackAmmo[iPA] != -1 )
{
pWeaponBox->PackAmmo( MAKE_STRING( CBasePlayerItem::AmmoInfoArray[iPackAmmo[iPA]].pszName ), m_rgAmmo[iPackAmmo[iPA]] );
iPA++;
}
2016-06-04 15:24:23 +02:00
// now pack all of the items in the lists
while( rgpPackWeapons[iPW] )
{
// weapon unhooked from the player. Pack it into der box.
pWeaponBox->PackWeapon( rgpPackWeapons[iPW] );
2016-06-04 15:24:23 +02:00
iPW++;
}
2024-02-03 18:58:03 +01:00
pWeaponBox->pev->velocity = pev->velocity * 1.2f;// weaponbox has player's velocity, then some.
}
2016-06-04 15:24:23 +02:00
RemoveAllItems( TRUE );// now strip off everything that wasn't handled by the code above.
}
void CBasePlayer::RemoveAllItems( BOOL removeSuit )
{
int i;
CBasePlayerItem *pPendingItem;
2016-07-31 15:48:50 +02:00
if( m_pActiveItem )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
ResetAutoaim();
m_pActiveItem->Holster();
2016-06-04 15:24:23 +02:00
m_pActiveItem = NULL;
}
m_pLastItem = NULL;
2017-06-29 15:56:03 +02:00
if( m_pTank != 0 )
m_pTank->Use( this, this, USE_OFF, 0 );
m_iTrain = TRAIN_NEW; // turn off train
2016-07-31 15:48:50 +02:00
for( i = 0; i < MAX_ITEM_TYPES; i++ )
2016-06-04 15:24:23 +02:00
{
m_pActiveItem = m_rgpPlayerItems[i];
m_rgpPlayerItems[i] = NULL;
2016-07-31 15:48:50 +02:00
while( m_pActiveItem )
2016-06-04 15:24:23 +02:00
{
pPendingItem = m_pActiveItem->m_pNext;
2016-07-31 15:48:50 +02:00
m_pActiveItem->Drop();
2016-06-04 15:24:23 +02:00
m_pActiveItem = pPendingItem;
}
}
m_pActiveItem = NULL;
2016-07-31 15:48:50 +02:00
pev->viewmodel = 0;
pev->weaponmodel = 0;
2016-07-31 15:48:50 +02:00
if( removeSuit )
2016-06-04 15:24:23 +02:00
pev->weapons = 0;
else
pev->weapons &= ~WEAPON_ALLWEAPONS;
2017-07-10 16:28:56 +02:00
// Turn off flashlight
ClearBits( pev->effects, EF_DIMLIGHT );
2016-07-31 15:48:50 +02:00
for( i = 0; i < MAX_AMMO_SLOTS; i++ )
2016-06-04 15:24:23 +02:00
m_rgAmmo[i] = 0;
2017-07-20 09:22:02 +02:00
if( satchelfix.value )
DeactivateSatchels( this );
2016-06-04 15:24:23 +02:00
UpdateClientData();
2016-06-04 15:24:23 +02:00
// send Selected Weapon Message to our client
MESSAGE_BEGIN( MSG_ONE, gmsgCurWeapon, NULL, pev );
2016-07-31 15:48:50 +02:00
WRITE_BYTE( 0 );
WRITE_BYTE( 0 );
WRITE_BYTE( 0 );
2016-06-04 15:24:23 +02:00
MESSAGE_END();
}
/*
* GLOBALS ASSUMED SET: g_ulModelIndexPlayer
*
* ENTITY_METHOD(PlayerDie)
*/
entvars_t *g_pevLastInflictor; // Set in combat.cpp. Used to pass the damage inflictor for death messages.
// Better solution: Add as parameter to all Killed() functions.
2016-06-04 15:24:23 +02:00
void CBasePlayer::Killed( entvars_t *pevAttacker, int iGib )
{
CSound *pSound;
// Holster weapon immediately, to allow it to cleanup
2016-07-31 15:48:50 +02:00
if( m_pActiveItem )
m_pActiveItem->Holster();
2016-06-04 15:24:23 +02:00
g_pGameRules->PlayerKilled( this, pevAttacker, g_pevLastInflictor );
2017-06-29 15:56:03 +02:00
if( m_pTank != 0 )
2016-06-04 15:24:23 +02:00
m_pTank->Use( this, this, USE_OFF, 0 );
// this client isn't going to be thinking for a while, so reset the sound until they respawn
pSound = CSoundEnt::SoundPointerForIndex( CSoundEnt::ClientSoundIndex( edict() ) );
{
2016-07-31 15:48:50 +02:00
if( pSound )
2016-06-04 15:24:23 +02:00
{
pSound->Reset();
}
}
SetAnimation( PLAYER_DIE );
m_flRespawnTimer = 0;
2016-06-04 15:24:23 +02:00
pev->modelindex = g_ulModelIndexPlayer; // don't use eyes
2016-07-31 15:48:50 +02:00
pev->deadflag = DEAD_DYING;
pev->movetype = MOVETYPE_TOSS;
2016-06-04 15:24:23 +02:00
ClearBits( pev->flags, FL_ONGROUND );
2016-07-31 15:48:50 +02:00
if( pev->velocity.z < 10 )
pev->velocity.z += RANDOM_FLOAT( 0, 300 );
2016-06-04 15:24:23 +02:00
// clear out the suit message cache so we don't keep chattering
2016-07-31 15:48:50 +02:00
SetSuitUpdate( NULL, FALSE, 0 );
2016-06-04 15:24:23 +02:00
// send "health" update message to zero
m_iClientHealth = 0;
MESSAGE_BEGIN( MSG_ONE, gmsgHealth, NULL, pev );
WRITE_BYTE( m_iClientHealth );
MESSAGE_END();
// Tell Ammo Hud that the player is dead
MESSAGE_BEGIN( MSG_ONE, gmsgCurWeapon, NULL, pev );
2016-07-31 15:48:50 +02:00
WRITE_BYTE( 0 );
WRITE_BYTE( 0XFF );
WRITE_BYTE( 0xFF );
2016-06-04 15:24:23 +02:00
MESSAGE_END();
// reset FOV
pev->fov = m_iFOV = m_iClientFOV = 0;
MESSAGE_BEGIN( MSG_ONE, gmsgSetFOV, NULL, pev );
2016-07-31 15:48:50 +02:00
WRITE_BYTE( 0 );
2016-06-04 15:24:23 +02:00
MESSAGE_END();
// UNDONE: Put this in, but add FFADE_PERMANENT and make fade time 8.8 instead of 4.12
2016-07-31 15:48:50 +02:00
// UTIL_ScreenFade( edict(), Vector( 128, 0, 0 ), 6, 15, 255, FFADE_OUT | FFADE_MODULATE );
2016-06-04 15:24:23 +02:00
if( g_pGameRules->IsMultiplayer())
pev->solid = SOLID_NOT;
2016-07-31 15:48:50 +02:00
if( ( pev->health < -40 && iGib != GIB_NEVER ) || iGib == GIB_ALWAYS )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
pev->solid = SOLID_NOT;
2016-06-04 15:24:23 +02:00
GibMonster(); // This clears pev->model
pev->effects |= EF_NODRAW;
return;
}
DeathSound();
2016-06-04 15:24:23 +02:00
pev->angles.x = 0;
pev->angles.z = 0;
SetThink( &CBasePlayer::PlayerDeathThink );
2019-10-13 13:49:25 +02:00
pev->nextthink = gpGlobals->time + 0.1f;
2016-06-04 15:24:23 +02:00
}
// Set the activity based on an event or current state
void CBasePlayer::SetAnimation( PLAYER_ANIM playerAnim )
{
int animDesired;
float speed;
char szAnim[64];
speed = pev->velocity.Length2D();
2016-07-31 15:48:50 +02:00
if( pev->flags & FL_FROZEN )
2016-06-04 15:24:23 +02:00
{
speed = 0;
playerAnim = PLAYER_IDLE;
}
2016-07-31 15:48:50 +02:00
switch( playerAnim )
2016-06-04 15:24:23 +02:00
{
case PLAYER_JUMP:
m_IdealActivity = ACT_HOP;
break;
case PLAYER_SUPERJUMP:
m_IdealActivity = ACT_LEAP;
break;
case PLAYER_DIE:
m_IdealActivity = ACT_DIESIMPLE;
2016-07-31 15:48:50 +02:00
m_IdealActivity = GetDeathActivity();
2016-06-04 15:24:23 +02:00
break;
2016-07-31 15:48:50 +02:00
case PLAYER_ATTACK1:
2016-06-04 15:24:23 +02:00
switch( m_Activity )
{
case ACT_HOVER:
case ACT_SWIM:
case ACT_HOP:
case ACT_LEAP:
case ACT_DIESIMPLE:
m_IdealActivity = m_Activity;
break;
default:
m_IdealActivity = ACT_RANGE_ATTACK1;
break;
}
break;
case PLAYER_IDLE:
case PLAYER_WALK:
2016-07-31 15:48:50 +02:00
if( !FBitSet( pev->flags, FL_ONGROUND ) && ( m_Activity == ACT_HOP || m_Activity == ACT_LEAP ) ) // Still jumping
2016-06-04 15:24:23 +02:00
{
m_IdealActivity = m_Activity;
}
2016-07-31 15:48:50 +02:00
else if( pev->waterlevel > 1 )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( speed == 0 )
2016-06-04 15:24:23 +02:00
m_IdealActivity = ACT_HOVER;
else
m_IdealActivity = ACT_SWIM;
}
else
{
m_IdealActivity = ACT_WALK;
}
break;
}
2016-07-31 15:48:50 +02:00
switch( m_IdealActivity )
2016-06-04 15:24:23 +02:00
{
case ACT_HOVER:
case ACT_LEAP:
case ACT_SWIM:
case ACT_HOP:
case ACT_DIESIMPLE:
default:
2016-07-31 15:48:50 +02:00
if( m_Activity == m_IdealActivity )
2016-06-04 15:24:23 +02:00
return;
m_Activity = m_IdealActivity;
animDesired = LookupActivity( m_Activity );
2016-06-04 15:24:23 +02:00
// Already using the desired animation?
2016-07-31 15:48:50 +02:00
if( pev->sequence == animDesired )
2016-06-04 15:24:23 +02:00
return;
pev->gaitsequence = 0;
2016-07-31 15:48:50 +02:00
pev->sequence = animDesired;
pev->frame = 0;
ResetSequenceInfo();
2016-06-04 15:24:23 +02:00
return;
case ACT_RANGE_ATTACK1:
2016-07-31 15:48:50 +02:00
if( FBitSet( pev->flags, FL_DUCKING ) ) // crouching
2016-06-04 15:24:23 +02:00
strcpy( szAnim, "crouch_shoot_" );
else
strcpy( szAnim, "ref_shoot_" );
strcat( szAnim, m_szAnimExtention );
animDesired = LookupSequence( szAnim );
2016-07-31 15:48:50 +02:00
if( animDesired == -1 )
2016-06-04 15:24:23 +02:00
animDesired = 0;
2016-07-31 15:48:50 +02:00
if( pev->sequence != animDesired || !m_fSequenceLoops )
2016-06-04 15:24:23 +02:00
{
pev->frame = 0;
}
2016-07-31 15:48:50 +02:00
if( !m_fSequenceLoops )
2016-06-04 15:24:23 +02:00
{
pev->effects |= EF_NOINTERP;
}
m_Activity = m_IdealActivity;
2016-07-31 15:48:50 +02:00
pev->sequence = animDesired;
ResetSequenceInfo();
2016-06-04 15:24:23 +02:00
break;
case ACT_WALK:
2016-07-31 15:48:50 +02:00
if( m_Activity != ACT_RANGE_ATTACK1 || m_fSequenceFinished )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( FBitSet( pev->flags, FL_DUCKING ) ) // crouching
2016-06-04 15:24:23 +02:00
strcpy( szAnim, "crouch_aim_" );
else
strcpy( szAnim, "ref_aim_" );
strcat( szAnim, m_szAnimExtention );
animDesired = LookupSequence( szAnim );
2016-07-31 15:48:50 +02:00
if( animDesired == -1 )
2016-06-04 15:24:23 +02:00
animDesired = 0;
m_Activity = ACT_WALK;
}
else
{
animDesired = pev->sequence;
}
}
2016-07-31 15:48:50 +02:00
if( FBitSet( pev->flags, FL_DUCKING ) )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( speed == 0 )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
pev->gaitsequence = LookupActivity( ACT_CROUCHIDLE );
// pev->gaitsequence = LookupActivity( ACT_CROUCH );
2016-06-04 15:24:23 +02:00
}
else
{
2016-07-31 15:48:50 +02:00
pev->gaitsequence = LookupActivity( ACT_CROUCH );
2016-06-04 15:24:23 +02:00
}
}
2016-07-31 15:48:50 +02:00
else if( speed > 220 )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
pev->gaitsequence = LookupActivity( ACT_RUN );
2016-06-04 15:24:23 +02:00
}
2016-07-31 15:48:50 +02:00
else if( speed > 0 )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
pev->gaitsequence = LookupActivity( ACT_WALK );
2016-06-04 15:24:23 +02:00
}
else
{
2016-07-31 15:48:50 +02:00
// pev->gaitsequence = LookupActivity( ACT_WALK );
pev->gaitsequence = LookupSequence( "deep_idle" );
2016-06-04 15:24:23 +02:00
}
// Already using the desired animation?
2016-07-31 15:48:50 +02:00
if( pev->sequence == animDesired )
2016-06-04 15:24:23 +02:00
return;
//ALERT( at_console, "Set animation to %d\n", animDesired );
// Reset to first frame of desired animation
2016-07-31 15:48:50 +02:00
pev->sequence = animDesired;
pev->frame = 0;
ResetSequenceInfo();
2016-06-04 15:24:23 +02:00
}
/*
===========
TabulateAmmo
This function is used to find and store
all the ammo we have into the ammo vars.
============
*/
void CBasePlayer::TabulateAmmo()
{
ammo_9mm = AmmoInventory( GetAmmoIndex( "9mm" ) );
ammo_357 = AmmoInventory( GetAmmoIndex( "357" ) );
ammo_argrens = AmmoInventory( GetAmmoIndex( "ARgrenades" ) );
ammo_bolts = AmmoInventory( GetAmmoIndex( "bolts" ) );
ammo_buckshot = AmmoInventory( GetAmmoIndex( "buckshot" ) );
ammo_rockets = AmmoInventory( GetAmmoIndex( "rockets" ) );
ammo_uranium = AmmoInventory( GetAmmoIndex( "uranium" ) );
ammo_hornets = AmmoInventory( GetAmmoIndex( "Hornets" ) );
}
/*
===========
WaterMove
============
*/
#define AIRTIME 12 // lung full of air lasts this many seconds
void CBasePlayer::WaterMove()
{
int air;
2016-07-31 15:48:50 +02:00
if( pev->movetype == MOVETYPE_NOCLIP )
2016-06-04 15:24:23 +02:00
return;
2016-07-31 15:48:50 +02:00
if( pev->health < 0 )
2016-06-04 15:24:23 +02:00
return;
// waterlevel 0 - not in water
// waterlevel 1 - feet in water
// waterlevel 2 - waist in water
// waterlevel 3 - head in water
2016-07-31 15:48:50 +02:00
if( pev->waterlevel != 3 )
2016-06-04 15:24:23 +02:00
{
// not underwater
2016-06-04 15:24:23 +02:00
// play 'up for air' sound
2016-07-31 15:48:50 +02:00
if( pev->air_finished < gpGlobals->time )
EMIT_SOUND( ENT( pev ), CHAN_VOICE, "player/pl_wade1.wav", 1, ATTN_NORM );
else if( pev->air_finished < gpGlobals->time + 9 )
EMIT_SOUND( ENT( pev ), CHAN_VOICE, "player/pl_wade2.wav", 1, ATTN_NORM );
2016-06-04 15:24:23 +02:00
pev->air_finished = gpGlobals->time + AIRTIME;
pev->dmg = 2;
// if we took drowning damage, give it back slowly
2016-07-31 15:48:50 +02:00
if( m_idrowndmg > m_idrownrestored )
2016-06-04 15:24:23 +02:00
{
// set drowning damage bit. hack - dmg_drownrecover actually
// makes the time based damage code 'give back' health over time.
// make sure counter is cleared so we start count correctly.
2016-06-04 15:24:23 +02:00
// NOTE: this actually causes the count to continue restarting
// until all drowning damage is healed.
m_bitsDamageType |= DMG_DROWNRECOVER;
m_bitsDamageType &= ~DMG_DROWN;
m_rgbTimeBasedDamage[itbd_DrownRecover] = 0;
}
}
else
{ // fully under water
// stop restoring damage while underwater
m_bitsDamageType &= ~DMG_DROWNRECOVER;
m_rgbTimeBasedDamage[itbd_DrownRecover] = 0;
2016-07-31 15:48:50 +02:00
if( pev->air_finished < gpGlobals->time ) // drown!
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( pev->pain_finished < gpGlobals->time )
2016-06-04 15:24:23 +02:00
{
// take drowning damage
pev->dmg += 1;
2016-07-31 15:48:50 +02:00
if( pev->dmg > 5 )
2016-06-04 15:24:23 +02:00
pev->dmg = 5;
2016-07-31 15:48:50 +02:00
TakeDamage( VARS( eoNullEntity ), VARS( eoNullEntity ), pev->dmg, DMG_DROWN );
2016-06-04 15:24:23 +02:00
pev->pain_finished = gpGlobals->time + 1;
2016-06-04 15:24:23 +02:00
// track drowning damage, give it back when
// player finally takes a breath
2017-06-29 15:56:03 +02:00
m_idrowndmg += (int)pev->dmg;
2016-06-04 15:24:23 +02:00
}
}
else
{
m_bitsDamageType &= ~DMG_DROWN;
}
}
2016-07-31 15:48:50 +02:00
if( !pev->waterlevel )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( FBitSet( pev->flags, FL_INWATER ) )
{
ClearBits( pev->flags, FL_INWATER );
2016-06-04 15:24:23 +02:00
}
return;
}
// make bubbles
if( pev->waterlevel == 3 )
2016-06-04 15:24:23 +02:00
{
air = (int)( pev->air_finished - gpGlobals->time );
if( !RANDOM_LONG( 0, 0x1f ) && RANDOM_LONG( 0, AIRTIME - 1 ) >= air )
2016-07-31 15:48:50 +02:00
{
switch( RANDOM_LONG( 0, 3 ) )
{
case 0:
EMIT_SOUND( ENT( pev ), CHAN_BODY, "player/pl_swim1.wav", 0.8, ATTN_NORM );
break;
case 1:
EMIT_SOUND( ENT( pev ), CHAN_BODY, "player/pl_swim2.wav", 0.8, ATTN_NORM );
break;
case 2:
EMIT_SOUND( ENT( pev ), CHAN_BODY, "player/pl_swim3.wav", 0.8, ATTN_NORM );
break;
case 3:
EMIT_SOUND( ENT( pev ), CHAN_BODY, "player/pl_swim4.wav", 0.8, ATTN_NORM );
break;
}
2016-06-04 15:24:23 +02:00
}
}
2016-07-31 15:48:50 +02:00
if( pev->watertype == CONTENT_LAVA ) // do damage
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( pev->dmgtime < gpGlobals->time )
TakeDamage( VARS( eoNullEntity ), VARS( eoNullEntity ), 10 * pev->waterlevel, DMG_BURN );
2016-06-04 15:24:23 +02:00
}
2016-07-31 15:48:50 +02:00
else if( pev->watertype == CONTENT_SLIME ) // do damage
2016-06-04 15:24:23 +02:00
{
pev->dmgtime = gpGlobals->time + 1;
2016-07-31 15:48:50 +02:00
TakeDamage( VARS( eoNullEntity ), VARS( eoNullEntity ), 4 * pev->waterlevel, DMG_ACID );
2016-06-04 15:24:23 +02:00
}
2016-07-31 15:48:50 +02:00
if( !FBitSet( pev->flags, FL_INWATER ) )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
SetBits( pev->flags, FL_INWATER );
2016-06-04 15:24:23 +02:00
pev->dmgtime = 0;
}
}
// TRUE if the player is attached to a ladder
BOOL CBasePlayer::IsOnLadder( void )
{
return ( pev->movetype == MOVETYPE_FLY );
}
2016-07-31 15:48:50 +02:00
void CBasePlayer::PlayerDeathThink( void )
2016-06-04 15:24:23 +02:00
{
float flForward;
2016-07-31 15:48:50 +02:00
if( FBitSet( pev->flags, FL_ONGROUND ) )
2016-06-04 15:24:23 +02:00
{
flForward = pev->velocity.Length() - 20;
2016-07-31 15:48:50 +02:00
if( flForward <= 0 )
2016-06-04 15:24:23 +02:00
pev->velocity = g_vecZero;
else
pev->velocity = flForward * pev->velocity.Normalize();
}
2016-07-31 15:48:50 +02:00
if( HasWeapons() )
2016-06-04 15:24:23 +02:00
{
// we drop the guns here because weapons that have an area effect and can kill their user
// will sometimes crash coming back from CBasePlayer::Killed() if they kill their owner because the
// player class sometimes is freed. It's safer to manipulate the weapons once we know
// we aren't calling into any of their code anymore through the player pointer.
PackDeadPlayerItems();
}
2024-02-13 14:42:37 +01:00
if( pev->modelindex && ( !m_fSequenceFinished ) && ( pev->deadflag == DEAD_DYING ))
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
StudioFrameAdvance();
2016-06-04 15:24:23 +02:00
m_flRespawnTimer = gpGlobals->frametime + m_flRespawnTimer; // Note, these aren't necessarily real "frames", so behavior is dependent on # of client movement commands
if( m_flRespawnTimer < 4.0f ) // Animations should be no longer than this
2016-06-04 15:24:23 +02:00
return;
}
2016-07-31 15:48:50 +02:00
if( pev->deadflag == DEAD_DYING )
{
2024-02-13 14:42:37 +01:00
if( g_pGameRules->IsMultiplayer() && m_fSequenceFinished && pev->movetype == MOVETYPE_NONE )
{
CopyToBodyQue( pev );
pev->modelindex = 0;
}
2016-06-04 15:24:23 +02:00
pev->deadflag = DEAD_DEAD;
}
2024-02-13 14:42:37 +01:00
// once we're done animating our death and we're on the ground, we want to set movetype to None so our dead body won't do collisions and stuff anymore
// this prevents a bug where the dead body would go to a player's head if he walked over it while the dead player was clicking their button to respawn
if( pev->movetype != MOVETYPE_NONE && FBitSet( pev->flags, FL_ONGROUND ) )
pev->movetype = MOVETYPE_NONE;
2016-06-04 15:24:23 +02:00
StopAnimation();
pev->effects |= EF_NOINTERP;
pev->framerate = 0.0;
2016-07-31 15:48:50 +02:00
BOOL fAnyButtonDown = ( pev->button & ~IN_SCORE );
2016-06-04 15:24:23 +02:00
// wait for all buttons released
2016-07-31 15:48:50 +02:00
if( pev->deadflag == DEAD_DEAD )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( fAnyButtonDown )
2016-06-04 15:24:23 +02:00
return;
2016-07-31 15:48:50 +02:00
if( g_pGameRules->FPlayerCanRespawn( this ) )
2016-06-04 15:24:23 +02:00
{
m_fDeadTime = gpGlobals->time;
pev->deadflag = DEAD_RESPAWNABLE;
}
2016-06-04 15:24:23 +02:00
return;
}
// if the player has been dead for one second longer than allowed by forcerespawn,
// forcerespawn isn't on. Send the player off to an intermission camera until they
// choose to respawn.
2016-07-31 15:48:50 +02:00
if( g_pGameRules->IsMultiplayer() && ( gpGlobals->time > ( m_fDeadTime + 6 ) ) && !( m_afPhysicsFlags & PFLAG_OBSERVER ) )
2016-06-04 15:24:23 +02:00
{
// go to dead camera.
StartDeathCam();
}
if( pev->iuser1 ) // player is in spectator mode
return;
// wait for any button down, or mp_forcerespawn is set and the respawn time is up
2016-07-31 15:48:50 +02:00
if( !fAnyButtonDown && !( g_pGameRules->IsMultiplayer() && forcerespawn.value > 0 && ( gpGlobals->time > ( m_fDeadTime + 5 ) ) ) )
2016-06-04 15:24:23 +02:00
return;
pev->button = 0;
m_flRespawnTimer = 0;
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
//ALERT( at_console, "Respawn\n" );
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
respawn( pev, !( m_afPhysicsFlags & PFLAG_OBSERVER ) );// don't copy a corpse if we're in deathcam.
2016-06-04 15:24:23 +02:00
pev->nextthink = -1;
}
//=========================================================
// StartDeathCam - find an intermission spot and send the
// player off into observer mode
//=========================================================
void CBasePlayer::StartDeathCam( void )
{
edict_t *pSpot, *pNewSpot;
int iRand;
2016-07-31 15:48:50 +02:00
if( pev->view_ofs == g_vecZero )
2016-06-04 15:24:23 +02:00
{
// don't accept subsequent attempts to StartDeathCam()
return;
}
2016-07-31 15:48:50 +02:00
pSpot = FIND_ENTITY_BY_CLASSNAME( NULL, "info_intermission" );
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
if( !FNullEnt( pSpot ) )
2016-06-04 15:24:23 +02:00
{
// at least one intermission spot in the world.
iRand = RANDOM_LONG( 0, 3 );
2016-07-31 15:48:50 +02:00
while( iRand > 0 )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
pNewSpot = FIND_ENTITY_BY_CLASSNAME( pSpot, "info_intermission" );
2016-07-31 15:48:50 +02:00
if( pNewSpot )
2016-06-04 15:24:23 +02:00
{
pSpot = pNewSpot;
}
iRand--;
}
CopyToBodyQue( pev );
UTIL_SetOrigin( pev, pSpot->v.origin );
pev->angles = pev->v_angle = pSpot->v.v_angle;
2016-06-04 15:24:23 +02:00
}
else
{
// no intermission spot. Push them up in the air, looking down at their corpse
TraceResult tr;
CopyToBodyQue( pev );
UTIL_TraceLine( pev->origin, pev->origin + Vector( 0, 0, 128 ), ignore_monsters, edict(), &tr );
UTIL_SetOrigin( pev, tr.vecEndPos );
pev->angles = pev->v_angle = UTIL_VecToAngles( tr.vecEndPos - pev->origin );
2016-06-04 15:24:23 +02:00
}
// start death cam
m_afPhysicsFlags |= PFLAG_OBSERVER;
pev->view_ofs = g_vecZero;
pev->fixangle = TRUE;
pev->solid = SOLID_NOT;
pev->takedamage = DAMAGE_NO;
pev->movetype = MOVETYPE_NONE;
pev->modelindex = 0;
2016-06-04 15:24:23 +02:00
}
void CBasePlayer::StartObserver( Vector vecPosition, Vector vecViewAngle )
{
// clear any clientside entities attached to this player
MESSAGE_BEGIN( MSG_PAS, SVC_TEMPENTITY, pev->origin );
WRITE_BYTE( TE_KILLPLAYERATTACHMENTS );
WRITE_BYTE( (BYTE)entindex() );
MESSAGE_END();
// Holster weapon immediately, to allow it to cleanup
if( m_pActiveItem )
m_pActiveItem->Holster();
2017-06-29 15:56:03 +02:00
if( m_pTank != 0 )
m_pTank->Use( this, this, USE_OFF, 0 );
2016-06-04 15:24:23 +02:00
// clear out the suit message cache so we don't keep chattering
SetSuitUpdate( NULL, FALSE, 0 );
// Tell Ammo Hud that the player is dead
MESSAGE_BEGIN( MSG_ONE, gmsgCurWeapon, NULL, pev );
WRITE_BYTE( 0 );
WRITE_BYTE( 0XFF );
WRITE_BYTE( 0xFF );
MESSAGE_END();
// reset FOV
m_iFOV = m_iClientFOV = 0;
pev->fov = m_iFOV;
MESSAGE_BEGIN( MSG_ONE, gmsgSetFOV, NULL, pev );
WRITE_BYTE( 0 );
MESSAGE_END();
// Setup flags
m_iHideHUD = ( HIDEHUD_HEALTH | HIDEHUD_FLASHLIGHT | HIDEHUD_WEAPONS );
m_afPhysicsFlags |= PFLAG_OBSERVER;
pev->effects = EF_NODRAW;
2016-06-04 15:24:23 +02:00
pev->view_ofs = g_vecZero;
pev->angles = pev->v_angle = vecViewAngle;
pev->fixangle = TRUE;
pev->solid = SOLID_NOT;
pev->takedamage = DAMAGE_NO;
pev->movetype = MOVETYPE_NONE;
ClearBits( m_afPhysicsFlags, PFLAG_DUCKING );
ClearBits( pev->flags, FL_DUCKING );
pev->deadflag = DEAD_RESPAWNABLE;
pev->health = 1;
// Clear out the status bar
m_fInitHUD = TRUE;
pev->team = 0;
MESSAGE_BEGIN( MSG_ALL, gmsgTeamInfo );
WRITE_BYTE( ENTINDEX(edict()) );
WRITE_STRING( "" );
MESSAGE_END();
// Remove all the player's stuff
RemoveAllItems( FALSE );
// Move them to the new position
2016-06-04 15:24:23 +02:00
UTIL_SetOrigin( pev, vecPosition );
// Find a player to watch
m_flNextObserverInput = 0;
Observer_SetMode( m_iObserverLastMode );
2016-06-04 15:24:23 +02:00
}
//
2016-06-04 15:24:23 +02:00
// PlayerUse - handles USE keypress
//
#define PLAYER_SEARCH_RADIUS (float)64
2016-07-31 15:48:50 +02:00
void CBasePlayer::PlayerUse( void )
2016-06-04 15:24:23 +02:00
{
if( IsObserver() )
return;
2016-06-04 15:24:23 +02:00
// Was use pressed or released?
2016-07-31 15:48:50 +02:00
if( !( ( pev->button | m_afButtonPressed | m_afButtonReleased) & IN_USE ) )
2016-06-04 15:24:23 +02:00
return;
// Hit Use on a train?
2016-07-31 15:48:50 +02:00
if( m_afButtonPressed & IN_USE )
2016-06-04 15:24:23 +02:00
{
2017-06-29 15:56:03 +02:00
if( m_pTank != 0 )
2016-06-04 15:24:23 +02:00
{
// Stop controlling the tank
// TODO: Send HUD Update
m_pTank->Use( this, this, USE_OFF, 0 );
return;
}
else
{
2016-07-31 15:48:50 +02:00
if( m_afPhysicsFlags & PFLAG_ONTRAIN )
2016-06-04 15:24:23 +02:00
{
m_afPhysicsFlags &= ~PFLAG_ONTRAIN;
m_iTrain = TRAIN_NEW|TRAIN_OFF;
CBaseEntity *pTrain = Instance( pev->groundentity );
if( pTrain && pTrain->Classify() == CLASS_VEHICLE )
{
( (CFuncVehicle *)pTrain )->m_pDriver = NULL;
}
2016-06-04 15:24:23 +02:00
return;
}
else
{ // Start controlling the train!
CBaseEntity *pTrain = CBaseEntity::Instance( pev->groundentity );
if( pTrain && !( pev->button & IN_JUMP ) && FBitSet( pev->flags, FL_ONGROUND ) && ( pTrain->ObjectCaps() & FCAP_DIRECTIONAL_USE ) && pTrain->OnControls( pev ) )
2016-06-04 15:24:23 +02:00
{
m_afPhysicsFlags |= PFLAG_ONTRAIN;
2017-06-29 15:56:03 +02:00
m_iTrain = TrainSpeed( (int)pTrain->pev->speed, pTrain->pev->impulse );
2016-06-04 15:24:23 +02:00
m_iTrain |= TRAIN_NEW;
if( pTrain->Classify() == CLASS_VEHICLE )
{
EMIT_SOUND( ENT( pev ), CHAN_ITEM, "plats/vehicle_ignition.wav", 0.8, ATTN_NORM );
( (CFuncVehicle *)pTrain )->m_pDriver = this;
}
else
EMIT_SOUND( ENT( pev ), CHAN_ITEM, "plats/train_use1.wav", 0.8, ATTN_NORM );
2016-06-04 15:24:23 +02:00
return;
}
}
}
}
CBaseEntity *pObject = NULL;
CBaseEntity *pClosest = NULL;
2016-07-31 15:48:50 +02:00
Vector vecLOS;
2016-06-04 15:24:23 +02:00
float flMaxDot = VIEW_FIELD_NARROW;
float flDot;
2016-07-31 15:48:50 +02:00
UTIL_MakeVectors( pev->v_angle );// so we know which way we are facing
2016-07-31 15:48:50 +02:00
while( ( pObject = UTIL_FindEntityInSphere( pObject, pev->origin, PLAYER_SEARCH_RADIUS ) ) != NULL )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( pObject->ObjectCaps() & ( FCAP_IMPULSE_USE | FCAP_CONTINUOUS_USE | FCAP_ONOFF_USE ) )
2016-06-04 15:24:23 +02:00
{
// !!!PERFORMANCE- should this check be done on a per case basis AFTER we've determined that
// this object is actually usable? This dot is being done for every object within PLAYER_SEARCH_RADIUS
// when player hits the use key. How many objects can be in that area, anyway? (sjb)
2016-07-31 15:48:50 +02:00
vecLOS = ( VecBModelOrigin( pObject->pev ) - ( pev->origin + pev->view_ofs ) );
2016-06-04 15:24:23 +02:00
// This essentially moves the origin of the target to the corner nearest the player to test to see
// if it's "hull" is in the view cone
vecLOS = UTIL_ClampVectorToBox( vecLOS, pObject->pev->size * 0.5 );
2016-07-31 15:48:50 +02:00
flDot = DotProduct( vecLOS , gpGlobals->v_forward );
if( flDot > flMaxDot )
{
// only if the item is in front of the user
2016-06-04 15:24:23 +02:00
pClosest = pObject;
flMaxDot = flDot;
//ALERT( at_console, "%s : %f\n", STRING( pObject->pev->classname ), flDot );
2016-06-04 15:24:23 +02:00
}
//ALERT( at_console, "%s : %f\n", STRING( pObject->pev->classname ), flDot );
2016-06-04 15:24:23 +02:00
}
}
pObject = pClosest;
// Found an object
2016-07-31 15:48:50 +02:00
if( pObject )
2016-06-04 15:24:23 +02:00
{
//!!!UNDONE: traceline here to prevent USEing buttons through walls
int caps = pObject->ObjectCaps();
2016-07-31 15:48:50 +02:00
if( m_afButtonPressed & IN_USE )
EMIT_SOUND( ENT(pev), CHAN_ITEM, "common/wpn_select.wav", 0.4, ATTN_NORM );
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
if( ( ( pev->button & IN_USE ) && ( caps & FCAP_CONTINUOUS_USE ) ) ||
( ( m_afButtonPressed & IN_USE ) && ( caps & ( FCAP_IMPULSE_USE | FCAP_ONOFF_USE ) ) ) )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( caps & FCAP_CONTINUOUS_USE )
2016-06-04 15:24:23 +02:00
m_afPhysicsFlags |= PFLAG_USING;
pObject->Use( this, this, USE_SET, 1 );
}
// UNDONE: Send different USE codes for ON/OFF. Cache last ONOFF_USE object to send 'off' if you turn away
2016-07-31 15:48:50 +02:00
else if( ( m_afButtonReleased & IN_USE ) && ( pObject->ObjectCaps() & FCAP_ONOFF_USE ) ) // BUGBUG This is an "off" use
2016-06-04 15:24:23 +02:00
{
pObject->Use( this, this, USE_SET, 0 );
}
}
else
{
2016-07-31 15:48:50 +02:00
if( m_afButtonPressed & IN_USE )
EMIT_SOUND( ENT( pev ), CHAN_ITEM, "common/wpn_denyselect.wav", 0.4, ATTN_NORM );
2016-06-04 15:24:23 +02:00
}
}
void CBasePlayer::Jump()
{
2016-07-31 15:48:50 +02:00
Vector vecWallCheckDir;// direction we're tracing a line to find a wall when walljumping
Vector vecAdjustedVelocity;
Vector vecSpot;
TraceResult tr;
2016-07-31 15:48:50 +02:00
if( FBitSet( pev->flags, FL_WATERJUMP ) )
2016-06-04 15:24:23 +02:00
return;
2016-07-31 15:48:50 +02:00
if( pev->waterlevel >= 2 )
2016-06-04 15:24:23 +02:00
{
return;
}
// jump velocity is sqrt( height * gravity * 2)
// If this isn't the first frame pressing the jump button, break out.
2016-07-31 15:48:50 +02:00
if( !FBitSet( m_afButtonPressed, IN_JUMP ) )
2016-06-04 15:24:23 +02:00
return; // don't pogo stick
2016-07-31 15:48:50 +02:00
if( !( pev->flags & FL_ONGROUND ) || !pev->groundentity )
2016-06-04 15:24:23 +02:00
{
return;
}
// many features in this function use v_forward, so makevectors now.
2016-07-31 15:48:50 +02:00
UTIL_MakeVectors( pev->angles );
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
// ClearBits( pev->flags, FL_ONGROUND ); // don't stairwalk
2016-06-04 15:24:23 +02:00
SetAnimation( PLAYER_JUMP );
2016-07-31 15:48:50 +02:00
if( m_fLongJump &&
( pev->button & IN_DUCK ) &&
2016-06-04 15:24:23 +02:00
( pev->flDuckTime > 0 ) &&
pev->velocity.Length() > 50 )
{
SetAnimation( PLAYER_SUPERJUMP );
}
// If you're standing on a conveyor, add it's velocity to yours (for momentum)
2016-07-31 15:48:50 +02:00
entvars_t *pevGround = VARS( pev->groundentity );
if( pevGround )
2016-06-04 15:24:23 +02:00
{
if( pevGround->flags & FL_CONVEYOR )
{
pev->velocity = pev->velocity + pev->basevelocity;
}
if( FClassnameIs( pevGround, "func_vehicle" ))
{
pev->velocity = pevGround->velocity + pev->velocity;
}
2016-06-04 15:24:23 +02:00
}
}
// This is a glorious hack to find free space when you've crouched into some solid space
// Our crouching collisions do not work correctly for some reason and this is easier
// than fixing the problem :(
void FixPlayerCrouchStuck( edict_t *pPlayer )
{
TraceResult trace;
// Move up as many as 18 pixels if the player is stuck.
2016-07-31 15:48:50 +02:00
for( int i = 0; i < 18; i++ )
2016-06-04 15:24:23 +02:00
{
UTIL_TraceHull( pPlayer->v.origin, pPlayer->v.origin, dont_ignore_monsters, head_hull, pPlayer, &trace );
2016-07-31 15:48:50 +02:00
if( trace.fStartSolid )
pPlayer->v.origin.z++;
2016-06-04 15:24:23 +02:00
else
break;
}
}
2016-07-31 15:48:50 +02:00
void CBasePlayer::Duck()
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( pev->button & IN_DUCK )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( m_IdealActivity != ACT_LEAP )
2016-06-04 15:24:23 +02:00
{
SetAnimation( PLAYER_WALK );
}
}
}
//
// ID's player as such.
//
2016-07-31 15:48:50 +02:00
int CBasePlayer::Classify( void )
2016-06-04 15:24:23 +02:00
{
return CLASS_PLAYER;
}
void CBasePlayer::AddPoints( int score, BOOL bAllowNegativeScore )
{
// Positive score always adds
2016-07-31 15:48:50 +02:00
if( score < 0 )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( !bAllowNegativeScore )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( pev->frags < 0 ) // Can't go more negative
2016-06-04 15:24:23 +02:00
return;
2016-07-31 15:48:50 +02:00
if( -score > pev->frags ) // Will this go negative?
2016-06-04 15:24:23 +02:00
{
2017-06-29 15:56:03 +02:00
score = (int)( -pev->frags ); // Sum will be 0
2016-06-04 15:24:23 +02:00
}
}
}
pev->frags += score;
MESSAGE_BEGIN( MSG_ALL, gmsgScoreInfo );
2016-07-31 15:48:50 +02:00
WRITE_BYTE( ENTINDEX( edict() ) );
2017-06-29 15:56:03 +02:00
WRITE_SHORT( (int)pev->frags );
2016-06-04 15:24:23 +02:00
WRITE_SHORT( m_iDeaths );
WRITE_SHORT( 0 );
WRITE_SHORT( g_pGameRules->GetTeamIndex( m_szTeamName ) + 1 );
MESSAGE_END();
}
void CBasePlayer::AddPointsToTeam( int score, BOOL bAllowNegativeScore )
{
int index = entindex();
2016-07-31 15:48:50 +02:00
for( int i = 1; i <= gpGlobals->maxClients; i++ )
2016-06-04 15:24:23 +02:00
{
CBaseEntity *pPlayer = UTIL_PlayerByIndex( i );
2016-07-31 15:48:50 +02:00
if( pPlayer && i != index )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( g_pGameRules->PlayerRelationship( this, pPlayer ) == GR_TEAMMATE )
2016-06-04 15:24:23 +02:00
{
pPlayer->AddPoints( score, bAllowNegativeScore );
}
}
}
}
//Player ID
void CBasePlayer::InitStatusBar()
{
m_flStatusBarDisappearDelay = 0;
m_SbarString1[0] = m_SbarString0[0] = 0;
}
void CBasePlayer::UpdateStatusBar()
{
2016-08-02 13:59:22 +02:00
int newSBarState[SBAR_END] = {0};
2016-07-31 15:48:50 +02:00
char sbuf0[SBAR_STRING_SIZE];
2016-06-04 15:24:23 +02:00
char sbuf1[ SBAR_STRING_SIZE ];
strcpy( sbuf0, m_SbarString0 );
strcpy( sbuf1, m_SbarString1 );
// Find an ID Target
TraceResult tr;
UTIL_MakeVectors( pev->v_angle + pev->punchangle );
Vector vecSrc = EyePosition();
2016-07-31 15:48:50 +02:00
Vector vecEnd = vecSrc + ( gpGlobals->v_forward * MAX_ID_RANGE );
UTIL_TraceLine( vecSrc, vecEnd, dont_ignore_monsters, edict(), &tr );
2016-06-04 15:24:23 +02:00
2019-10-13 13:49:25 +02:00
if( tr.flFraction != 1.0f )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( !FNullEnt( tr.pHit ) )
2016-06-04 15:24:23 +02:00
{
CBaseEntity *pEntity = CBaseEntity::Instance( tr.pHit );
2016-07-31 15:48:50 +02:00
if( pEntity->Classify() == CLASS_PLAYER )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
newSBarState[SBAR_ID_TARGETNAME] = ENTINDEX( pEntity->edict() );
2016-06-04 15:24:23 +02:00
strcpy( sbuf1, "1 %p1\n2 Health: %i2%%\n3 Armor: %i3%%" );
// allies and medics get to see the targets health
2016-07-31 15:48:50 +02:00
if( g_pGameRules->PlayerRelationship( this, pEntity ) == GR_TEAMMATE )
2016-06-04 15:24:23 +02:00
{
2017-06-29 15:56:03 +02:00
newSBarState[SBAR_ID_TARGETHEALTH] = (int)( 100 * ( pEntity->pev->health / pEntity->pev->max_health ) );
newSBarState[SBAR_ID_TARGETARMOR] = (int)pEntity->pev->armorvalue; //No need to get it % based since 100 it's the max.
2016-06-04 15:24:23 +02:00
}
2019-10-13 13:49:25 +02:00
m_flStatusBarDisappearDelay = gpGlobals->time + 1.0f;
2016-06-04 15:24:23 +02:00
}
}
2016-07-31 15:48:50 +02:00
else if( m_flStatusBarDisappearDelay > gpGlobals->time )
2016-06-04 15:24:23 +02:00
{
// hold the values for a short amount of time after viewing the object
2016-07-31 15:48:50 +02:00
newSBarState[SBAR_ID_TARGETNAME] = m_izSBarState[SBAR_ID_TARGETNAME];
newSBarState[SBAR_ID_TARGETHEALTH] = m_izSBarState[SBAR_ID_TARGETHEALTH];
newSBarState[SBAR_ID_TARGETARMOR] = m_izSBarState[SBAR_ID_TARGETARMOR];
2016-06-04 15:24:23 +02:00
}
}
BOOL bForceResend = FALSE;
2016-07-31 15:48:50 +02:00
if( strcmp( sbuf0, m_SbarString0 ) )
2016-06-04 15:24:23 +02:00
{
MESSAGE_BEGIN( MSG_ONE, gmsgStatusText, NULL, pev );
WRITE_BYTE( 0 );
WRITE_STRING( sbuf0 );
MESSAGE_END();
strcpy( m_SbarString0, sbuf0 );
// make sure everything's resent
bForceResend = TRUE;
}
2016-07-31 15:48:50 +02:00
if( strcmp( sbuf1, m_SbarString1 ) )
2016-06-04 15:24:23 +02:00
{
MESSAGE_BEGIN( MSG_ONE, gmsgStatusText, NULL, pev );
WRITE_BYTE( 1 );
WRITE_STRING( sbuf1 );
MESSAGE_END();
strcpy( m_SbarString1, sbuf1 );
// make sure everything's resent
bForceResend = TRUE;
}
// Check values and send if they don't match
2016-07-31 15:48:50 +02:00
for( int i = 1; i < SBAR_END; i++ )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( newSBarState[i] != m_izSBarState[i] || bForceResend )
2016-06-04 15:24:23 +02:00
{
MESSAGE_BEGIN( MSG_ONE, gmsgStatusValue, NULL, pev );
WRITE_BYTE( i );
WRITE_SHORT( newSBarState[i] );
MESSAGE_END();
m_izSBarState[i] = newSBarState[i];
}
}
}
2016-07-31 15:48:50 +02:00
#define CLIMB_SHAKE_FREQUENCY 22 // how many frames in between screen shakes when climbing
2016-06-04 15:24:23 +02:00
#define MAX_CLIMB_SPEED 200 // fastest vertical climbing speed possible
#define CLIMB_SPEED_DEC 15 // climbing deceleration rate
#define CLIMB_PUNCH_X -7 // how far to 'punch' client X axis when climbing
#define CLIMB_PUNCH_Z 7 // how far to 'punch' client Z axis when climbing
2016-07-31 15:48:50 +02:00
void CBasePlayer::PreThink( void )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
int buttonsChanged = ( m_afButtonLast ^ pev->button ); // These buttons have changed this frame
2016-06-04 15:24:23 +02:00
// Debounced button codes for pressed/released
// UNDONE: Do we need auto-repeat?
m_afButtonPressed = buttonsChanged & pev->button; // The changed ones still down are "pressed"
2016-07-31 15:48:50 +02:00
m_afButtonReleased = buttonsChanged & ( ~pev->button ); // The ones not down are "released"
2016-06-04 15:24:23 +02:00
g_pGameRules->PlayerThink( this );
2016-07-31 15:48:50 +02:00
if( g_fGameOver )
2016-06-04 15:24:23 +02:00
return; // intermission or finale
2016-07-31 15:48:50 +02:00
UTIL_MakeVectors( pev->v_angle ); // is this still used?
2016-07-31 15:48:50 +02:00
ItemPreFrame();
2016-06-04 15:24:23 +02:00
WaterMove();
2016-07-31 15:48:50 +02:00
if( g_pGameRules && g_pGameRules->FAllowFlashlight() )
2016-06-04 15:24:23 +02:00
m_iHideHUD &= ~HIDEHUD_FLASHLIGHT;
else
m_iHideHUD |= HIDEHUD_FLASHLIGHT;
// JOHN: checks if new client data (for HUD and view control) needs to be sent to the client
UpdateClientData();
2016-06-04 15:24:23 +02:00
CheckTimeBasedDamage();
CheckSuitUpdate();
// Observer Button Handling
if( IsObserver() )
{
Observer_HandleButtons();
Observer_CheckTarget();
Observer_CheckProperties();
pev->impulse = 0;
return;
}
2016-07-31 15:48:50 +02:00
if( pev->deadflag >= DEAD_DYING )
2016-06-04 15:24:23 +02:00
{
PlayerDeathThink();
return;
}
// So the correct flags get sent to client asap.
//
2016-07-31 15:48:50 +02:00
if( m_afPhysicsFlags & PFLAG_ONTRAIN )
2016-06-04 15:24:23 +02:00
pev->flags |= FL_ONTRAIN;
else
pev->flags &= ~FL_ONTRAIN;
// Train speed control
2016-07-31 15:48:50 +02:00
if( m_afPhysicsFlags & PFLAG_ONTRAIN )
2016-06-04 15:24:23 +02:00
{
CBaseEntity *pTrain = CBaseEntity::Instance( pev->groundentity );
float vel;
int iGearId; // Vit_amiN: keeps the train control HUD in sync
2016-07-31 15:48:50 +02:00
if( !pTrain )
2016-06-04 15:24:23 +02:00
{
TraceResult trainTrace;
// Maybe this is on the other side of a level transition
2016-07-31 15:48:50 +02:00
UTIL_TraceLine( pev->origin, pev->origin + Vector( 0, 0, -38 ), ignore_monsters, ENT( pev ), &trainTrace );
2016-06-04 15:24:23 +02:00
// HACKHACK - Just look for the func_tracktrain classname
2019-10-13 13:49:25 +02:00
if( trainTrace.flFraction != 1.0f && trainTrace.pHit )
2016-06-04 15:24:23 +02:00
pTrain = CBaseEntity::Instance( trainTrace.pHit );
2016-07-31 15:48:50 +02:00
if( !pTrain || !( pTrain->ObjectCaps() & FCAP_DIRECTIONAL_USE ) || !pTrain->OnControls( pev ) )
2016-06-04 15:24:23 +02:00
{
//ALERT( at_error, "In train mode with no train!\n" );
m_afPhysicsFlags &= ~PFLAG_ONTRAIN;
m_iTrain = TRAIN_NEW|TRAIN_OFF;
if( pTrain )
( (CFuncVehicle *)pTrain )->m_pDriver = NULL;
2016-06-04 15:24:23 +02:00
return;
}
}
else if( !FBitSet( pev->flags, FL_ONGROUND ) || FBitSet( pTrain->pev->spawnflags, SF_TRACKTRAIN_NOCONTROL )
|| ( ( pev->button & ( IN_MOVELEFT | IN_MOVERIGHT )) && pTrain->Classify() != CLASS_VEHICLE ))
2016-06-04 15:24:23 +02:00
{
// Turn off the train if you jump, strafe, or the train controls go dead
m_afPhysicsFlags &= ~PFLAG_ONTRAIN;
2016-07-31 15:48:50 +02:00
m_iTrain = TRAIN_NEW | TRAIN_OFF;
( (CFuncVehicle *)pTrain )->m_pDriver = NULL;
2016-06-04 15:24:23 +02:00
return;
}
pev->velocity = g_vecZero;
vel = 0;
if( pTrain->Classify() == CLASS_VEHICLE )
2016-06-04 15:24:23 +02:00
{
if( pev->button & IN_FORWARD )
{
vel = 1;
pTrain->Use( this, this, USE_SET, vel );
}
if( pev->button & IN_BACK )
{
vel = -1;
pTrain->Use( this, this, USE_SET, vel );
}
if( pev->button & IN_MOVELEFT )
{
vel = 20;
pTrain->Use( this, this, USE_SET, vel );
}
if( pev->button & IN_MOVERIGHT )
{
vel = 30;
pTrain->Use( this, this, USE_SET, vel );
}
2016-06-04 15:24:23 +02:00
}
else
2016-06-04 15:24:23 +02:00
{
if( m_afButtonPressed & IN_FORWARD )
{
vel = 1;
pTrain->Use( this, this, USE_SET, vel );
}
else if( m_afButtonPressed & IN_BACK )
{
vel = -1;
pTrain->Use( this, this, USE_SET, vel );
}
2016-06-04 15:24:23 +02:00
}
iGearId = TrainSpeed( pTrain->pev->speed, pTrain->pev->impulse );
if( iGearId != ( m_iTrain & 0x0F ) ) // Vit_amiN: speed changed
2016-06-04 15:24:23 +02:00
{
m_iTrain = iGearId;
m_iTrain |= TRAIN_ACTIVE | TRAIN_NEW;
2016-06-04 15:24:23 +02:00
}
}
else if( m_iTrain & TRAIN_ACTIVE )
2016-06-04 15:24:23 +02:00
m_iTrain = TRAIN_NEW; // turn off train
2016-07-31 15:48:50 +02:00
if( pev->button & IN_JUMP )
2016-06-04 15:24:23 +02:00
{
// If on a ladder, jump off the ladder
// else Jump
Jump();
}
// If trying to duck, already ducked, or in the process of ducking
2016-07-31 15:48:50 +02:00
if( ( pev->button & IN_DUCK ) || FBitSet( pev->flags,FL_DUCKING ) || ( m_afPhysicsFlags & PFLAG_DUCKING ) )
2016-06-04 15:24:23 +02:00
Duck();
2016-07-31 15:48:50 +02:00
if( !FBitSet( pev->flags, FL_ONGROUND ) )
2016-06-04 15:24:23 +02:00
{
m_flFallVelocity = -pev->velocity.z;
}
2016-07-31 15:48:50 +02:00
// StudioFrameAdvance();//!!!HACKHACK!!! Can't be hit by traceline when not animating?
2016-06-04 15:24:23 +02:00
// Clear out ladder pointer
m_hEnemy = NULL;
2016-07-31 15:48:50 +02:00
if( m_afPhysicsFlags & PFLAG_ONBARNACLE )
2016-06-04 15:24:23 +02:00
{
pev->velocity = g_vecZero;
}
}
/* Time based Damage works as follows:
1) There are several types of timebased damage:
#define DMG_PARALYZE (1 << 14) // slows affected creature down
#define DMG_NERVEGAS (1 << 15) // nerve toxins, very bad
2016-07-31 15:48:50 +02:00
#define DMG_POISON (1 << 16) // blood poisioning
2016-06-04 15:24:23 +02:00
#define DMG_RADIATION (1 << 17) // radiation exposure
#define DMG_DROWNRECOVER (1 << 18) // drown recovery
2016-07-31 15:48:50 +02:00
#define DMG_ACID (1 << 19) // toxic chemicals or acid burns
2016-06-04 15:24:23 +02:00
#define DMG_SLOWBURN (1 << 20) // in an oven
#define DMG_SLOWFREEZE (1 << 21) // in a subzero freezer
2) A new hit inflicting tbd restarts the tbd counter - each monster has an 8bit counter,
per damage type. The counter is decremented every second, so the maximum time
an effect will last is 255/60 = 4.25 minutes. Of course, staying within the radius
of a damaging effect like fire, nervegas, radiation will continually reset the counter to max.
3) Every second that a tbd counter is running, the player takes damage. The damage
is determined by the type of tdb.
Paralyze - 1/2 movement rate, 30 second duration.
Nervegas - 5 points per second, 16 second duration = 80 points max dose.
Poison - 2 points per second, 25 second duration = 50 points max dose.
Radiation - 1 point per second, 50 second duration = 50 points max dose.
Drown - 5 points per second, 2 second duration.
Acid/Chemical - 5 points per second, 10 second duration = 50 points max.
Burn - 10 points per second, 2 second duration.
Freeze - 3 points per second, 10 second duration = 30 points max.
4) Certain actions or countermeasures counteract the damaging effects of tbds:
Armor/Heater/Cooler - Chemical(acid),burn, freeze all do damage to armor power, then to body
- recharged by suit recharger
Air In Lungs - drowning damage is done to air in lungs first, then to body
- recharged by poking head out of water
- 10 seconds if swiming fast
Air In SCUBA - drowning damage is done to air in tanks first, then to body
- 2 minutes in tanks. Need new tank once empty.
Radiation Syringe - Each syringe full provides protection vs one radiation dosage
Antitoxin Syringe - Each syringe full provides protection vs one poisoning (nervegas or poison).
Health kit - Immediate stop to acid/chemical, fire or freeze damage.
Radiation Shower - Immediate stop to radiation damage, acid/chemical or fire damage.
*/
// If player is taking time based damage, continue doing damage to player -
// this simulates the effect of being poisoned, gassed, dosed with radiation etc -
// anything that continues to do damage even after the initial contact stops.
// Update all time based damage counters, and shut off any that are done.
// The m_bitsDamageType bit MUST be set if any damage is to be taken.
// This routine will detect the initial on value of the m_bitsDamageType
// and init the appropriate counter. Only processes damage every second.
2016-07-31 15:48:50 +02:00
//#define PARALYZE_DURATION 30 // number of 2 second intervals to take damage
2016-06-04 15:24:23 +02:00
//#define PARALYZE_DAMAGE 0.0 // damage to take each 2 second interval
2016-07-31 15:48:50 +02:00
//#define NERVEGAS_DURATION 16
2016-06-04 15:24:23 +02:00
//#define NERVEGAS_DAMAGE 5.0
//#define POISON_DURATION 25
2016-07-31 15:48:50 +02:00
//#define POISON_DAMAGE 2.0
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
//#define RADIATION_DURATION 50
//#define RADIATION_DAMAGE 1.0
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
//#define ACID_DURATION 10
2016-06-04 15:24:23 +02:00
//#define ACID_DAMAGE 5.0
2016-07-31 15:48:50 +02:00
//#define SLOWBURN_DURATION 2
2016-06-04 15:24:23 +02:00
//#define SLOWBURN_DAMAGE 1.0
2016-07-31 15:48:50 +02:00
//#define SLOWFREEZE_DURATION 1.0
//#define SLOWFREEZE_DAMAGE 3.0
2016-06-04 15:24:23 +02:00
void CBasePlayer::CheckTimeBasedDamage()
{
int i;
BYTE bDuration = 0;
2017-06-29 15:56:03 +02:00
//static float gtbdPrev = 0.0;
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
if( !( m_bitsDamageType & DMG_TIMEBASED ) )
2016-06-04 15:24:23 +02:00
return;
// only check for time based damage approx. every 2 seconds
2019-10-13 13:49:25 +02:00
if( fabs( gpGlobals->time - m_tbdPrev ) < 2.0f )
2016-06-04 15:24:23 +02:00
return;
2016-06-04 15:24:23 +02:00
m_tbdPrev = gpGlobals->time;
2016-07-31 15:48:50 +02:00
for( i = 0; i < CDMG_TIMEBASED; i++ )
2016-06-04 15:24:23 +02:00
{
// make sure bit is set for damage type
2016-07-31 15:48:50 +02:00
if( m_bitsDamageType & ( DMG_PARALYZE << i ) )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
switch( i )
2016-06-04 15:24:23 +02:00
{
case itbd_Paralyze:
// UNDONE - flag movement as half-speed
bDuration = PARALYZE_DURATION;
break;
case itbd_NerveGas:
2016-07-31 15:48:50 +02:00
//TakeDamage( pev, pev, NERVEGAS_DAMAGE, DMG_GENERIC );
2016-06-04 15:24:23 +02:00
bDuration = NERVEGAS_DURATION;
break;
case itbd_Poison:
2016-07-31 15:48:50 +02:00
TakeDamage( pev, pev, POISON_DAMAGE, DMG_GENERIC );
2016-06-04 15:24:23 +02:00
bDuration = POISON_DURATION;
break;
case itbd_Radiation:
2016-07-31 15:48:50 +02:00
//TakeDamage( pev, pev, RADIATION_DAMAGE, DMG_GENERIC );
2016-06-04 15:24:23 +02:00
bDuration = RADIATION_DURATION;
break;
case itbd_DrownRecover:
// NOTE: this hack is actually used to RESTORE health
// after the player has been drowning and finally takes a breath
2016-07-31 15:48:50 +02:00
if( m_idrowndmg > m_idrownrestored )
2016-06-04 15:24:23 +02:00
{
2017-10-14 21:57:55 +02:00
int idif = Q_min( m_idrowndmg - m_idrownrestored, 10 );
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
TakeHealth( idif, DMG_GENERIC );
2016-06-04 15:24:23 +02:00
m_idrownrestored += idif;
}
bDuration = 4; // get up to 5*10 = 50 points back
break;
case itbd_Acid:
2016-07-31 15:48:50 +02:00
//TakeDamage( pev, pev, ACID_DAMAGE, DMG_GENERIC );
2016-06-04 15:24:23 +02:00
bDuration = ACID_DURATION;
break;
case itbd_SlowBurn:
2016-07-31 15:48:50 +02:00
//TakeDamage( pev, pev, SLOWBURN_DAMAGE, DMG_GENERIC );
2016-06-04 15:24:23 +02:00
bDuration = SLOWBURN_DURATION;
break;
case itbd_SlowFreeze:
2016-07-31 15:48:50 +02:00
//TakeDamage( pev, pev, SLOWFREEZE_DAMAGE, DMG_GENERIC );
2016-06-04 15:24:23 +02:00
bDuration = SLOWFREEZE_DURATION;
break;
default:
bDuration = 0;
}
2016-07-31 15:48:50 +02:00
if( m_rgbTimeBasedDamage[i] )
2016-06-04 15:24:23 +02:00
{
// use up an antitoxin on poison or nervegas after a few seconds of damage
2016-07-31 15:48:50 +02:00
if( ( ( i == itbd_NerveGas ) && ( m_rgbTimeBasedDamage[i] < NERVEGAS_DURATION ) ) ||
( ( i == itbd_Poison ) && ( m_rgbTimeBasedDamage[i] < POISON_DURATION ) ) )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( m_rgItems[ITEM_ANTIDOTE] )
2016-06-04 15:24:23 +02:00
{
m_rgbTimeBasedDamage[i] = 0;
m_rgItems[ITEM_ANTIDOTE]--;
2016-07-31 15:48:50 +02:00
SetSuitUpdate( "!HEV_HEAL4", FALSE, SUIT_REPEAT_OK );
2016-06-04 15:24:23 +02:00
}
}
// decrement damage duration, detect when done.
2016-07-31 15:48:50 +02:00
if( !m_rgbTimeBasedDamage[i] || --m_rgbTimeBasedDamage[i] == 0 )
2016-06-04 15:24:23 +02:00
{
m_rgbTimeBasedDamage[i] = 0;
2016-06-04 15:24:23 +02:00
// if we're done, clear damage bits
2016-07-31 15:48:50 +02:00
m_bitsDamageType &= ~( DMG_PARALYZE << i );
2016-06-04 15:24:23 +02:00
}
}
else
// first time taking this damage type - init damage duration
m_rgbTimeBasedDamage[i] = bDuration;
}
}
}
/*
THE POWER SUIT
The Suit provides 3 main functions: Protection, Notification and Augmentation.
Some functions are automatic, some require power.
The player gets the suit shortly after getting off the train in C1A0 and it stays
with him for the entire game.
Protection
Heat/Cold
When the player enters a hot/cold area, the heating/cooling indicator on the suit
will come on and the battery will drain while the player stays in the area.
After the battery is dead, the player starts to take damage.
This feature is built into the suit and is automatically engaged.
Radiation Syringe
This will cause the player to be immune from the effects of radiation for N seconds. Single use item.
Anti-Toxin Syringe
This will cure the player from being poisoned. Single use item.
Health
Small (1st aid kits, food, etc.)
Large (boxes on walls)
Armor
The armor works using energy to create a protective field that deflects a
percentage of damage projectile and explosive attacks. After the armor has been deployed,
it will attempt to recharge itself to full capacity with the energy reserves from the battery.
It takes the armor N seconds to fully charge.
Notification (via the HUD)
x Health
x Ammo
x Automatic Health Care
Notifies the player when automatic healing has been engaged.
x Geiger counter
Classic Geiger counter sound and status bar at top of HUD
alerts player to dangerous levels of radiation. This is not visible when radiation levels are normal.
x Poison
Armor
Displays the current level of armor.
Augmentation
Reanimation (w/adrenaline)
Causes the player to come back to life after he has been dead for 3 seconds.
Will not work if player was gibbed. Single use.
Long Jump
Used by hitting the ??? key(s). Caused the player to further than normal.
SCUBA
Used automatically after picked up and after player enters the water.
Works for N seconds. Single use.
Things powered by the battery
Armor
Uses N watts for every M units of damage.
Heat/Cool
Uses N watts for every second in hot/cold area.
Long Jump
Uses N watts for every jump.
Alien Cloak
Uses N watts for each use. Each use lasts M seconds.
Alien Shield
Augments armor. Reduces Armor drain by one half
*/
// if in range of radiation source, ping geiger counter
2019-10-13 13:49:25 +02:00
#define GEIGERDELAY 0.25f
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
void CBasePlayer::UpdateGeigerCounter( void )
2016-06-04 15:24:23 +02:00
{
BYTE range;
// delay per update ie: don't flood net with these msgs
2016-07-31 15:48:50 +02:00
if( gpGlobals->time < m_flgeigerDelay )
2016-06-04 15:24:23 +02:00
return;
m_flgeigerDelay = gpGlobals->time + GEIGERDELAY;
// send range to radition source to client
2016-07-31 15:48:50 +02:00
range = (BYTE)( m_flgeigerRange / 4 );
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
if( range != m_igeigerRangePrev )
2016-06-04 15:24:23 +02:00
{
m_igeigerRangePrev = range;
MESSAGE_BEGIN( MSG_ONE, gmsgGeigerRange, NULL, pev );
WRITE_BYTE( range );
MESSAGE_END();
}
// reset counter and semaphore
2016-07-31 15:48:50 +02:00
if( !RANDOM_LONG( 0, 3 ) )
2016-06-04 15:24:23 +02:00
m_flgeigerRange = 1000;
}
/*
================
CheckSuitUpdate
Play suit update if it's time
================
*/
2019-10-13 13:49:25 +02:00
#define SUITUPDATETIME 3.5f
#define SUITFIRSTUPDATETIME 0.1f
2016-06-04 15:24:23 +02:00
void CBasePlayer::CheckSuitUpdate()
{
int i;
int isentence = 0;
int isearch = m_iSuitPlayNext;
2016-06-04 15:24:23 +02:00
// Ignore suit updates if no suit
2016-07-31 15:48:50 +02:00
if( !( pev->weapons & ( 1 << WEAPON_SUIT ) ) )
2016-06-04 15:24:23 +02:00
return;
// if in range of radiation source, ping geiger counter
UpdateGeigerCounter();
2016-07-31 15:48:50 +02:00
if( g_pGameRules->IsMultiplayer() )
2016-06-04 15:24:23 +02:00
{
// don't bother updating HEV voice in multiplayer.
return;
}
2016-07-31 15:48:50 +02:00
if( gpGlobals->time >= m_flSuitUpdate && m_flSuitUpdate > 0 )
2016-06-04 15:24:23 +02:00
{
// play a sentence off of the end of the queue
2016-07-31 15:48:50 +02:00
for( i = 0; i < CSUITPLAYLIST; i++ )
{
2016-07-31 15:48:50 +02:00
if( ( isentence = m_rgSuitPlayList[isearch] ) )
2016-06-04 15:24:23 +02:00
break;
2016-07-31 15:48:50 +02:00
if( ++isearch == CSUITPLAYLIST )
2016-06-04 15:24:23 +02:00
isearch = 0;
}
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
if( isentence )
2016-06-04 15:24:23 +02:00
{
m_rgSuitPlayList[isearch] = 0;
2016-07-31 15:48:50 +02:00
if( isentence > 0 )
2016-06-04 15:24:23 +02:00
{
// play sentence number
char sentence[CBSENTENCENAME_MAX + 1];
2016-07-31 15:48:50 +02:00
strcpy( sentence, "!" );
strcat( sentence, gszallsentencenames[isentence] );
EMIT_SOUND_SUIT( ENT( pev ), sentence );
2016-06-04 15:24:23 +02:00
}
else
{
// play sentence group
2016-07-31 15:48:50 +02:00
EMIT_GROUPID_SUIT( ENT( pev ), -isentence );
2016-06-04 15:24:23 +02:00
}
m_flSuitUpdate = gpGlobals->time + SUITUPDATETIME;
2016-06-04 15:24:23 +02:00
}
else
// queue is empty, don't check
m_flSuitUpdate = 0;
}
}
2016-06-04 15:24:23 +02:00
// add sentence to suit playlist queue. if fgroup is true, then
// name is a sentence group (HEV_AA), otherwise name is a specific
// sentence name ie: !HEV_AA0. If iNoRepeat is specified in
// seconds, then we won't repeat playback of this word or sentence
// for at least that number of seconds.
2017-06-29 15:56:03 +02:00
void CBasePlayer::SetSuitUpdate( const char *name, int fgroup, int iNoRepeatTime )
2016-06-04 15:24:23 +02:00
{
int i;
int isentence;
int iempty = -1;
2016-06-04 15:24:23 +02:00
// Ignore suit updates if no suit
2016-07-31 15:48:50 +02:00
if( !( pev->weapons & ( 1 << WEAPON_SUIT ) ) )
2016-06-04 15:24:23 +02:00
return;
2016-07-31 15:48:50 +02:00
if( g_pGameRules->IsMultiplayer() )
2016-06-04 15:24:23 +02:00
{
// due to static channel design, etc. We don't play HEV sounds in multiplayer right now.
return;
}
// if name == NULL, then clear out the queue
2016-07-31 15:48:50 +02:00
if( !name )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
for( i = 0; i < CSUITPLAYLIST; i++ )
2016-06-04 15:24:23 +02:00
m_rgSuitPlayList[i] = 0;
return;
}
2016-06-04 15:24:23 +02:00
// get sentence or group number
2016-07-31 15:48:50 +02:00
if( !fgroup )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
isentence = SENTENCEG_Lookup( name, NULL );
if( isentence < 0 )
2016-06-04 15:24:23 +02:00
return;
}
else
// mark group number as negative
2016-07-31 15:48:50 +02:00
isentence = -SENTENCEG_GetIndex( name );
2016-06-04 15:24:23 +02:00
// check norepeat list - this list lets us cancel
// the playback of words or sentences that have already
// been played within a certain time.
2016-07-31 15:48:50 +02:00
for( i = 0; i < CSUITNOREPEAT; i++ )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( isentence == m_rgiSuitNoRepeat[i] )
{
2016-06-04 15:24:23 +02:00
// this sentence or group is already in
// the norepeat list
2016-07-31 15:48:50 +02:00
if( m_rgflSuitNoRepeatTime[i] < gpGlobals->time )
{
2016-06-04 15:24:23 +02:00
// norepeat time has expired, clear it out
m_rgiSuitNoRepeat[i] = 0;
m_rgflSuitNoRepeatTime[i] = 0.0;
iempty = i;
break;
}
2016-06-04 15:24:23 +02:00
else
{
2016-06-04 15:24:23 +02:00
// don't play, still marked as norepeat
return;
}
}
2016-06-04 15:24:23 +02:00
// keep track of empty slot
2016-07-31 15:48:50 +02:00
if( !m_rgiSuitNoRepeat[i] )
2016-06-04 15:24:23 +02:00
iempty = i;
}
// sentence is not in norepeat list, save if norepeat time was given
2016-07-31 15:48:50 +02:00
if( iNoRepeatTime )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( iempty < 0 )
iempty = RANDOM_LONG( 0, CSUITNOREPEAT - 1 ); // pick random slot to take over
2016-06-04 15:24:23 +02:00
m_rgiSuitNoRepeat[iempty] = isentence;
m_rgflSuitNoRepeatTime[iempty] = iNoRepeatTime + gpGlobals->time;
}
// find empty spot in queue, or overwrite last spot
m_rgSuitPlayList[m_iSuitPlayNext++] = isentence;
2016-07-31 15:48:50 +02:00
if( m_iSuitPlayNext == CSUITPLAYLIST )
2016-06-04 15:24:23 +02:00
m_iSuitPlayNext = 0;
2016-07-31 15:48:50 +02:00
if( m_flSuitUpdate <= gpGlobals->time )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( m_flSuitUpdate == 0 )
2016-06-04 15:24:23 +02:00
// play queue is empty, don't delay too long before playback
m_flSuitUpdate = gpGlobals->time + SUITFIRSTUPDATETIME;
else
m_flSuitUpdate = gpGlobals->time + SUITUPDATETIME;
}
}
/*
================
CheckPowerups
Check for turning off powerups
GLOBALS ASSUMED SET: g_ulModelIndexPlayer
================
*/
2016-07-31 15:48:50 +02:00
static void CheckPowerups( entvars_t *pev )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( pev->health <= 0 )
2016-06-04 15:24:23 +02:00
return;
pev->modelindex = g_ulModelIndexPlayer; // don't use eyes
}
//=========================================================
// UpdatePlayerSound - updates the position of the player's
// reserved sound slot in the sound list.
//=========================================================
2016-07-31 15:48:50 +02:00
void CBasePlayer::UpdatePlayerSound( void )
2016-06-04 15:24:23 +02:00
{
int iBodyVolume;
int iVolume;
CSound *pSound;
2016-07-31 15:48:50 +02:00
pSound = CSoundEnt::SoundPointerForIndex( CSoundEnt::ClientSoundIndex( edict() ) );
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
if( !pSound )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
ALERT( at_console, "Client lost reserved sound!\n" );
2016-06-04 15:24:23 +02:00
return;
}
pSound->m_iType = bits_SOUND_NONE;
// now calculate the best target volume for the sound. If the player's weapon
// is louder than his body/movement, use the weapon volume, else, use the body volume.
2016-07-31 15:48:50 +02:00
if( FBitSet( pev->flags, FL_ONGROUND ) )
{
2017-06-29 15:56:03 +02:00
iBodyVolume = (int)pev->velocity.Length();
2016-06-04 15:24:23 +02:00
// clamp the noise that can be made by the body, in case a push trigger,
// weapon recoil, or anything shoves the player abnormally fast.
2016-07-31 15:48:50 +02:00
if( iBodyVolume > 512 )
2016-06-04 15:24:23 +02:00
{
iBodyVolume = 512;
}
}
else
{
iBodyVolume = 0;
}
2016-07-31 15:48:50 +02:00
if( pev->button & IN_JUMP )
2016-06-04 15:24:23 +02:00
{
iBodyVolume += 100;
}
// convert player move speed and actions into sound audible by monsters.
2016-07-31 15:48:50 +02:00
if( m_iWeaponVolume > iBodyVolume )
2016-06-04 15:24:23 +02:00
{
m_iTargetVolume = m_iWeaponVolume;
// OR in the bits for COMBAT sound if the weapon is being louder than the player.
pSound->m_iType |= bits_SOUND_COMBAT;
}
else
{
m_iTargetVolume = iBodyVolume;
}
// decay weapon volume over time so bits_SOUND_COMBAT stays set for a while
2017-06-29 15:56:03 +02:00
m_iWeaponVolume -= (int)( 250 * gpGlobals->frametime );
2016-07-31 15:48:50 +02:00
if( m_iWeaponVolume < 0 )
2016-06-04 15:24:23 +02:00
{
iVolume = 0;
}
// if target volume is greater than the player sound's current volume, we paste the new volume in
// immediately. If target is less than the current volume, current volume is not set immediately to the
// lower volume, rather works itself towards target volume over time. This gives monsters a much better chance
// to hear a sound, especially if they don't listen every frame.
iVolume = pSound->m_iVolume;
2016-07-31 15:48:50 +02:00
if( m_iTargetVolume > iVolume )
2016-06-04 15:24:23 +02:00
{
iVolume = m_iTargetVolume;
}
2016-07-31 15:48:50 +02:00
else if( iVolume > m_iTargetVolume )
2016-06-04 15:24:23 +02:00
{
2017-06-29 15:56:03 +02:00
iVolume -= (int)( 250 * gpGlobals->frametime );
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
if( iVolume < m_iTargetVolume )
2016-06-04 15:24:23 +02:00
{
iVolume = 0;
}
}
2016-07-31 15:48:50 +02:00
if( m_fNoPlayerSound )
2016-06-04 15:24:23 +02:00
{
// debugging flag, lets players move around and shoot without monsters hearing.
iVolume = 0;
}
2016-07-31 15:48:50 +02:00
if( gpGlobals->time > m_flStopExtraSoundTime )
2016-06-04 15:24:23 +02:00
{
// since the extra sound that a weapon emits only lasts for one client frame, we keep that sound around for a server frame or two
// after actual emission to make sure it gets heard.
m_iExtraSoundTypes = 0;
}
2016-07-31 15:48:50 +02:00
if( pSound )
2016-06-04 15:24:23 +02:00
{
pSound->m_vecOrigin = pev->origin;
pSound->m_iType |= ( bits_SOUND_PLAYER | m_iExtraSoundTypes );
pSound->m_iVolume = iVolume;
}
// keep track of virtual muzzle flash
2017-06-29 15:56:03 +02:00
m_iWeaponFlash -= (int)( 256 * gpGlobals->frametime );
2016-07-31 15:48:50 +02:00
if( m_iWeaponFlash < 0 )
2016-06-04 15:24:23 +02:00
m_iWeaponFlash = 0;
2016-07-31 15:48:50 +02:00
//UTIL_MakeVectors( pev->angles );
2016-06-04 15:24:23 +02:00
//gpGlobals->v_forward.z = 0;
// Below are a couple of useful little bits that make it easier to determine just how much noise the
// player is making.
2016-07-31 15:48:50 +02:00
// UTIL_ParticleEffect( pev->origin + gpGlobals->v_forward * iVolume, g_vecZero, 255, 25 );
//ALERT( at_console, "%d/%d\n", iVolume, m_iTargetVolume );
2016-06-04 15:24:23 +02:00
}
void CBasePlayer::PostThink()
{
2016-07-31 15:48:50 +02:00
if( g_fGameOver )
goto pt_end; // intermission or finale
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
if( !IsAlive() )
2016-06-04 15:24:23 +02:00
goto pt_end;
// Handle Tank controlling
2017-06-29 15:56:03 +02:00
if( m_pTank != 0 )
{
// if they've moved too far from the gun, or selected a weapon, unuse the gun
2016-07-31 15:48:50 +02:00
if( m_pTank->OnControls( pev ) && !pev->weaponmodel )
2016-06-04 15:24:23 +02:00
{
m_pTank->Use( this, this, USE_SET, 2 ); // try fire the gun
}
else
{
// they've moved off the platform
2016-06-04 15:24:23 +02:00
m_pTank->Use( this, this, USE_OFF, 0 );
}
}
// do weapon stuff
2016-07-31 15:48:50 +02:00
ItemPostFrame();
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
// check to see if player landed hard enough to make a sound
// falling farther than half of the maximum safe distance, but not as far a max safe distance will
// play a bootscrape sound, and no damage will be inflicted. Fallling a distance shorter than half
// of maximum safe distance will make no sound. Falling farther than max safe distance will play a
// fallpain sound, and damage will be inflicted based on how far the player fell
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
if( ( FBitSet( pev->flags, FL_ONGROUND ) ) && ( pev->health > 0 ) && m_flFallVelocity >= PLAYER_FALL_PUNCH_THRESHHOLD )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
// ALERT( at_console, "%f\n", m_flFallVelocity );
if( pev->watertype == CONTENT_WATER )
2016-06-04 15:24:23 +02:00
{
// Did he hit the world or a non-moving entity?
// BUG - this happens all the time in water, especially when
// BUG - water has current force
2016-07-31 15:48:50 +02:00
// if( !pev->groundentity || VARS(pev->groundentity )->velocity.z == 0 )
// EMIT_SOUND( ENT( pev ), CHAN_BODY, "player/pl_wade1.wav", 1, ATTN_NORM );
2016-06-04 15:24:23 +02:00
}
2016-07-31 15:48:50 +02:00
else if( m_flFallVelocity > PLAYER_MAX_SAFE_FALL_SPEED )
{
// after this point, we start doing damage
2016-06-04 15:24:23 +02:00
float flFallDamage = g_pGameRules->FlPlayerFallDamage( this );
2016-07-31 15:48:50 +02:00
if( flFallDamage > pev->health )
{
//splat
2016-06-04 15:24:23 +02:00
// note: play on item channel because we play footstep landing on body channel
2016-07-31 15:48:50 +02:00
EMIT_SOUND( ENT( pev ), CHAN_ITEM, "common/bodysplat.wav", 1, ATTN_NORM );
2016-06-04 15:24:23 +02:00
}
2016-07-31 15:48:50 +02:00
if( flFallDamage > 0 )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
TakeDamage( VARS( eoNullEntity ), VARS( eoNullEntity ), flFallDamage, DMG_FALL );
2016-06-04 15:24:23 +02:00
pev->punchangle.x = 0;
}
}
2016-07-31 15:48:50 +02:00
if( IsAlive() )
2016-06-04 15:24:23 +02:00
{
SetAnimation( PLAYER_WALK );
}
}
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
if( FBitSet( pev->flags, FL_ONGROUND ) )
{
if( m_flFallVelocity > 64 && !g_pGameRules->IsMultiplayer() )
2016-06-04 15:24:23 +02:00
{
2017-06-29 15:56:03 +02:00
CSoundEnt::InsertSound( bits_SOUND_PLAYER, pev->origin, (int)m_flFallVelocity, 0.2 );
2016-06-04 15:24:23 +02:00
// ALERT( at_console, "fall %f\n", m_flFallVelocity );
}
m_flFallVelocity = 0;
}
// select the proper animation for the player character
2016-07-31 15:48:50 +02:00
if( IsAlive() )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( !pev->velocity.x && !pev->velocity.y )
2016-06-04 15:24:23 +02:00
SetAnimation( PLAYER_IDLE );
2016-07-31 15:48:50 +02:00
else if( ( pev->velocity.x || pev->velocity.y ) && ( FBitSet( pev->flags, FL_ONGROUND ) ) )
2016-06-04 15:24:23 +02:00
SetAnimation( PLAYER_WALK );
2016-07-31 15:48:50 +02:00
else if( pev->waterlevel > 1 )
2016-06-04 15:24:23 +02:00
SetAnimation( PLAYER_WALK );
}
2016-07-31 15:48:50 +02:00
StudioFrameAdvance();
CheckPowerups( pev );
2016-06-04 15:24:23 +02:00
UpdatePlayerSound();
pt_end:
if( pev->deadflag == DEAD_NO )
m_vecLastViewAngles = pev->angles;
else
pev->angles = m_vecLastViewAngles;
2016-06-04 15:24:23 +02:00
// Track button info so we can detect 'pressed' and 'released' buttons next frame
m_afButtonLast = pev->button;
2021-06-07 16:17:22 +02:00
#if CLIENT_WEAPONS
// Decay timers on weapons
2016-06-04 15:24:23 +02:00
// go through all of the weapons and make a list of the ones to pack
2016-07-31 15:48:50 +02:00
for( int i = 0; i < MAX_ITEM_TYPES; i++ )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( m_rgpPlayerItems[i] )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
CBasePlayerItem *pPlayerItem = m_rgpPlayerItems[i];
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
while( pPlayerItem )
2016-06-04 15:24:23 +02:00
{
CBasePlayerWeapon *gun;
gun = (CBasePlayerWeapon *)pPlayerItem->GetWeaponPtr();
2016-07-31 15:48:50 +02:00
if( gun && gun->UseDecrement() )
2016-06-04 15:24:23 +02:00
{
2019-10-13 13:49:25 +02:00
gun->m_flNextPrimaryAttack = Q_max( gun->m_flNextPrimaryAttack - gpGlobals->frametime, -1.0f );
gun->m_flNextSecondaryAttack = Q_max( gun->m_flNextSecondaryAttack - gpGlobals->frametime, -0.001f );
2016-06-04 15:24:23 +02:00
2019-10-13 13:49:25 +02:00
if( gun->m_flTimeWeaponIdle != 1000.0f )
2016-06-04 15:24:23 +02:00
{
2019-10-13 13:49:25 +02:00
gun->m_flTimeWeaponIdle = Q_max( gun->m_flTimeWeaponIdle - gpGlobals->frametime, -0.001f );
2016-06-04 15:24:23 +02:00
}
2019-10-13 13:49:25 +02:00
if( gun->pev->fuser1 != 1000.0f )
2016-06-04 15:24:23 +02:00
{
2019-10-13 13:49:25 +02:00
gun->pev->fuser1 = Q_max( gun->pev->fuser1 - gpGlobals->frametime, -0.001f );
2016-06-04 15:24:23 +02:00
}
// Only decrement if not flagged as NO_DECREMENT
2019-10-13 13:49:25 +02:00
/*if( gun->m_flPumpTime != 1000.0f )
{
2019-10-13 13:49:25 +02:00
gun->m_flPumpTime = Q_max( gun->m_flPumpTime - gpGlobals->frametime, -0.001f );
}*/
2016-06-04 15:24:23 +02:00
}
pPlayerItem = pPlayerItem->m_pNext;
}
}
}
m_flNextAttack -= gpGlobals->frametime;
2019-10-13 13:49:25 +02:00
if( m_flNextAttack < -0.001f )
m_flNextAttack = -0.001f;
2016-06-04 15:24:23 +02:00
2019-10-13 13:49:25 +02:00
if( m_flNextAmmoBurn != 1000.0f )
2016-06-04 15:24:23 +02:00
{
m_flNextAmmoBurn -= gpGlobals->frametime;
2016-07-31 15:48:50 +02:00
2019-10-13 13:49:25 +02:00
if( m_flNextAmmoBurn < -0.001f )
m_flNextAmmoBurn = -0.001f;
2016-06-04 15:24:23 +02:00
}
2019-10-13 13:49:25 +02:00
if( m_flAmmoStartCharge != 1000.0f )
2016-06-04 15:24:23 +02:00
{
m_flAmmoStartCharge -= gpGlobals->frametime;
2016-07-31 15:48:50 +02:00
2019-10-13 13:49:25 +02:00
if( m_flAmmoStartCharge < -0.001f )
m_flAmmoStartCharge = -0.001f;
2016-06-04 15:24:23 +02:00
}
#else
return;
#endif
}
// checks if the spot is clear of players
BOOL IsSpawnPointValid( CBaseEntity *pPlayer, CBaseEntity *pSpot )
{
CBaseEntity *ent = NULL;
2016-07-31 15:48:50 +02:00
if( !pSpot->IsTriggered( pPlayer ) )
2016-06-04 15:24:23 +02:00
{
return FALSE;
}
2016-07-31 15:48:50 +02:00
while( ( ent = UTIL_FindEntityInSphere( ent, pSpot->pev->origin, 128 ) ) != NULL )
2016-06-04 15:24:23 +02:00
{
// if ent is a client, don't spawn on 'em
2016-07-31 15:48:50 +02:00
if( ent->IsPlayer() && ent != pPlayer )
2016-06-04 15:24:23 +02:00
return FALSE;
}
return TRUE;
}
DLL_GLOBAL CBaseEntity *g_pLastSpawn;
2016-07-31 15:48:50 +02:00
inline int FNullEnt( CBaseEntity *ent ) { return ( ent == NULL ) || FNullEnt( ent->edict() ); }
2016-06-04 15:24:23 +02:00
/*
============
EntSelectSpawnPoint
Returns the entity to spawn at
USES AND SETS GLOBAL g_pLastSpawn
============
*/
edict_t *EntSelectSpawnPoint( CBaseEntity *pPlayer )
{
CBaseEntity *pSpot;
2016-07-31 15:48:50 +02:00
edict_t *player;
2016-06-04 15:24:23 +02:00
player = pPlayer->edict();
// choose a info_player_deathmatch point
2016-07-31 15:48:50 +02:00
if( g_pGameRules->IsCoOp() )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
pSpot = UTIL_FindEntityByClassname( g_pLastSpawn, "info_player_coop" );
if( !FNullEnt( pSpot ) )
2016-06-04 15:24:23 +02:00
goto ReturnSpot;
2016-07-31 15:48:50 +02:00
pSpot = UTIL_FindEntityByClassname( g_pLastSpawn, "info_player_start" );
if( !FNullEnt(pSpot) )
2016-06-04 15:24:23 +02:00
goto ReturnSpot;
}
2016-07-31 15:48:50 +02:00
else if( g_pGameRules->IsDeathmatch() )
2016-06-04 15:24:23 +02:00
{
pSpot = g_pLastSpawn;
// Randomize the start spot
for( int i = RANDOM_LONG( 1, 9 ); i > 0; i-- )
2016-06-04 15:24:23 +02:00
pSpot = UTIL_FindEntityByClassname( pSpot, "info_player_deathmatch" );
2016-07-31 15:48:50 +02:00
if( FNullEnt( pSpot ) ) // skip over the null point
2016-06-04 15:24:23 +02:00
pSpot = UTIL_FindEntityByClassname( pSpot, "info_player_deathmatch" );
CBaseEntity *pFirstSpot = pSpot;
do
{
2016-07-31 15:48:50 +02:00
if( pSpot )
2016-06-04 15:24:23 +02:00
{
// check if pSpot is valid
2016-07-31 15:48:50 +02:00
if( IsSpawnPointValid( pPlayer, pSpot ) )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( pSpot->pev->origin == Vector( 0, 0, 0 ) )
2016-06-04 15:24:23 +02:00
{
pSpot = UTIL_FindEntityByClassname( pSpot, "info_player_deathmatch" );
continue;
}
// if so, go to pSpot
goto ReturnSpot;
}
}
// increment pSpot
pSpot = UTIL_FindEntityByClassname( pSpot, "info_player_deathmatch" );
2016-07-31 15:48:50 +02:00
} while( pSpot != pFirstSpot ); // loop if we're not back to the start
2016-06-04 15:24:23 +02:00
// we haven't found a place to spawn yet, so kill any guy at the first spawn point and spawn there
2016-07-31 15:48:50 +02:00
if( !FNullEnt( pSpot ) )
2016-06-04 15:24:23 +02:00
{
CBaseEntity *ent = NULL;
2016-07-31 15:48:50 +02:00
while( ( ent = UTIL_FindEntityInSphere( ent, pSpot->pev->origin, 128 ) ) != NULL )
2016-06-04 15:24:23 +02:00
{
// if ent is a client, kill em (unless they are ourselves)
2016-07-31 15:48:50 +02:00
if( ent->IsPlayer() && !(ent->edict() == player) )
ent->TakeDamage( VARS( INDEXENT( 0 ) ), VARS( INDEXENT( 0 ) ), 300, DMG_GENERIC );
2016-06-04 15:24:23 +02:00
}
goto ReturnSpot;
}
}
// If startspot is set, (re)spawn there.
2019-09-24 00:00:37 +02:00
if( FStringNull( gpGlobals->startspot ) || (STRING( gpGlobals->startspot ) )[0] == '\0')
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
pSpot = UTIL_FindEntityByClassname( NULL, "info_player_start" );
if( !FNullEnt( pSpot ) )
2016-06-04 15:24:23 +02:00
goto ReturnSpot;
}
else
{
2016-07-31 15:48:50 +02:00
pSpot = UTIL_FindEntityByTargetname( NULL, STRING( gpGlobals->startspot ) );
if( !FNullEnt( pSpot ) )
2016-06-04 15:24:23 +02:00
goto ReturnSpot;
}
ReturnSpot:
2016-07-31 15:48:50 +02:00
if( FNullEnt( pSpot ) )
2016-06-04 15:24:23 +02:00
{
ALERT( at_error, "PutClientInServer: no info_player_start on level\n" );
2016-07-31 15:48:50 +02:00
return INDEXENT( 0 );
2016-06-04 15:24:23 +02:00
}
g_pLastSpawn = pSpot;
return pSpot->edict();
}
void CBasePlayer::Spawn( void )
{
2024-01-26 22:40:20 +01:00
m_flStartCharge = gpGlobals->time;
2016-07-31 15:48:50 +02:00
pev->classname = MAKE_STRING( "player" );
pev->health = 100;
pev->armorvalue = 0;
pev->takedamage = DAMAGE_AIM;
pev->solid = SOLID_SLIDEBOX;
pev->movetype = MOVETYPE_WALK;
pev->max_health = pev->health;
pev->flags &= FL_PROXY; // keep proxy flag sey by engine
pev->flags |= FL_CLIENT;
pev->air_finished = gpGlobals->time + 12;
pev->dmg = 2; // initial water damage
pev->effects = 0;
pev->deadflag = DEAD_NO;
pev->dmg_take = 0;
pev->dmg_save = 0;
2019-10-13 13:49:25 +02:00
pev->friction = 1.0f;
pev->gravity = 1.0f;
2016-07-31 15:48:50 +02:00
m_bitsHUDDamage = -1;
m_bitsDamageType = 0;
m_afPhysicsFlags = 0;
m_fLongJump = FALSE;// no longjump module.
2016-06-04 15:24:23 +02:00
g_engfuncs.pfnSetPhysicsKeyValue( edict(), "slj", "0" );
g_engfuncs.pfnSetPhysicsKeyValue( edict(), "hl", "1" );
2023-04-09 22:53:41 +02:00
g_engfuncs.pfnSetPhysicsKeyValue( edict(), "fr", "1" );
2023-04-09 23:25:44 +02:00
g_engfuncs.pfnSetPhysicsKeyValue( edict(), "bj", bhopcap.value ? "0" : "1" );
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
pev->fov = m_iFOV = 0;// init field of view.
m_iClientFOV = -1; // make sure fov reset is sent
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
m_flNextDecalTime = 0;// let this player decal as soon as he spawns.
2016-06-04 15:24:23 +02:00
2019-10-13 13:49:25 +02:00
m_flgeigerDelay = gpGlobals->time + 2.0f; // wait a few seconds until user-defined message registrations
// are recieved by all clients
2016-07-31 15:48:50 +02:00
m_flTimeStepSound = 0;
2016-06-04 15:24:23 +02:00
m_iStepLeft = 0;
2019-10-13 13:49:25 +02:00
m_flFieldOfView = 0.5f;// some monsters use this to determine whether or not the player is looking at them.
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
m_bloodColor = BLOOD_COLOR_RED;
m_flNextAttack = UTIL_WeaponTimeBase();
2016-06-04 15:24:23 +02:00
StartSneaking();
m_iFlashBattery = 99;
m_flFlashLightTime = 1; // force first message
// dont let uninitialized value here hurt the player
2016-06-04 15:24:23 +02:00
m_flFallVelocity = 0;
g_pGameRules->SetDefaultPlayerTeam( this );
g_pGameRules->GetPlayerSpawnSpot( this );
2016-07-31 15:48:50 +02:00
SET_MODEL( ENT( pev ), "models/player.mdl" );
g_ulModelIndexPlayer = pev->modelindex;
2016-07-31 15:48:50 +02:00
pev->sequence = LookupActivity( ACT_IDLE );
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
if( FBitSet( pev->flags, FL_DUCKING ) )
UTIL_SetSize( pev, VEC_DUCK_HULL_MIN, VEC_DUCK_HULL_MAX );
2016-06-04 15:24:23 +02:00
else
2016-07-31 15:48:50 +02:00
UTIL_SetSize( pev, VEC_HULL_MIN, VEC_HULL_MAX );
2016-06-04 15:24:23 +02:00
pev->view_ofs = VEC_VIEW;
2016-06-04 15:24:23 +02:00
Precache();
2016-07-31 15:48:50 +02:00
m_HackedGunPos = Vector( 0, 32, 0 );
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
if( m_iPlayerSound == SOUNDLIST_EMPTY )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
ALERT( at_console, "Couldn't alloc player sound slot!\n" );
2016-06-04 15:24:23 +02:00
}
m_fNoPlayerSound = FALSE;// normal sound behavior.
m_pLastItem = NULL;
m_fInitHUD = TRUE;
m_iClientHideHUD = -1; // force this to be recalculated
m_fWeapon = FALSE;
m_pClientActiveItem = NULL;
m_iClientBattery = -1;
// reset all ammo values to 0
2016-07-31 15:48:50 +02:00
for( int i = 0; i < MAX_AMMO_SLOTS; i++ )
2016-06-04 15:24:23 +02:00
{
m_rgAmmo[i] = 0;
m_rgAmmoLast[i] = 0; // client ammo values also have to be reset (the death hud clear messages does on the client side)
}
m_lastx = m_lasty = 0;
2016-07-31 15:48:50 +02:00
2016-06-04 15:24:23 +02:00
m_flNextChatTime = gpGlobals->time;
g_pGameRules->PlayerSpawn( this );
}
2016-07-31 15:48:50 +02:00
void CBasePlayer::Precache( void )
2016-06-04 15:24:23 +02:00
{
// in the event that the player JUST spawned, and the level node graph
// was loaded, fix all of the node graph pointers before the game starts.
2016-07-31 15:48:50 +02:00
2016-06-04 15:24:23 +02:00
// !!!BUGBUG - now that we have multiplayer, this needs to be moved!
2016-07-31 15:48:50 +02:00
if( WorldGraph.m_fGraphPresent && !WorldGraph.m_fGraphPointersSet )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( !WorldGraph.FSetGraphPointers() )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
ALERT( at_console, "**Graph pointers were not set!\n" );
2016-06-04 15:24:23 +02:00
}
else
{
2016-07-31 15:48:50 +02:00
ALERT( at_console, "**Graph Pointers Set!\n" );
}
2016-06-04 15:24:23 +02:00
}
// SOUNDS / MODELS ARE PRECACHED in ClientPrecache() (game specific)
// because they need to precache before any clients have connected
// init geiger counter vars during spawn and each time
// we cross a level transition
m_flgeigerRange = 1000;
m_igeigerRangePrev = 1000;
m_bitsDamageType = 0;
m_bitsHUDDamage = -1;
m_iClientBattery = -1;
m_flFlashLightTime = 1;
m_iTrain |= TRAIN_NEW;
// Make sure any necessary user messages have been registered
LinkUserMessages();
m_iUpdateTime = 5; // won't update for 1/2 a second
2016-07-31 15:48:50 +02:00
if( gInitHUD )
2016-06-04 15:24:23 +02:00
m_fInitHUD = TRUE;
pev->fov = m_iFOV; // Vit_amiN: restore the FOV on level change or map/saved game load
2016-06-04 15:24:23 +02:00
}
int CBasePlayer::Save( CSave &save )
{
2016-07-31 15:48:50 +02:00
if( !CBaseMonster::Save( save ) )
2016-06-04 15:24:23 +02:00
return 0;
2016-07-31 15:48:50 +02:00
return save.WriteFields( "PLAYER", this, m_playerSaveData, ARRAYSIZE( m_playerSaveData ) );
2016-06-04 15:24:23 +02:00
}
//
// Marks everything as new so the player will resend this to the hud.
//
2016-07-31 15:48:50 +02:00
void CBasePlayer::RenewItems( void )
2016-06-04 15:24:23 +02:00
{
}
int CBasePlayer::Restore( CRestore &restore )
{
2016-07-31 15:48:50 +02:00
if( !CBaseMonster::Restore( restore ) )
2016-06-04 15:24:23 +02:00
return 0;
2016-07-31 15:48:50 +02:00
int status = restore.ReadFields( "PLAYER", this, m_playerSaveData, ARRAYSIZE( m_playerSaveData ) );
2016-06-04 15:24:23 +02:00
SAVERESTOREDATA *pSaveData = (SAVERESTOREDATA *)gpGlobals->pSaveData;
// landmark isn't present.
2016-07-31 15:48:50 +02:00
if( !pSaveData->fUseLandmark )
2016-06-04 15:24:23 +02:00
{
ALERT( at_console, "No Landmark:%s\n", pSaveData->szLandmarkName );
// default to normal spawn
2016-07-31 15:48:50 +02:00
edict_t *pentSpawnSpot = EntSelectSpawnPoint( this );
pev->origin = VARS( pentSpawnSpot )->origin + Vector( 0, 0, 1 );
pev->angles = VARS( pentSpawnSpot )->angles;
2016-06-04 15:24:23 +02:00
}
pev->v_angle.z = 0; // Clear out roll
pev->angles = pev->v_angle;
pev->fixangle = TRUE; // turn this way immediately
// Copied from spawn() for now
2016-07-31 15:48:50 +02:00
m_bloodColor = BLOOD_COLOR_RED;
2016-06-04 15:24:23 +02:00
g_ulModelIndexPlayer = pev->modelindex;
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
if( FBitSet( pev->flags, FL_DUCKING ) )
2016-06-04 15:24:23 +02:00
{
// Use the crouch HACK
//FixPlayerCrouchStuck( edict() );
// Don't need to do this with new player prediction code.
2016-07-31 15:48:50 +02:00
UTIL_SetSize( pev, VEC_DUCK_HULL_MIN, VEC_DUCK_HULL_MAX );
2016-06-04 15:24:23 +02:00
}
else
{
2016-07-31 15:48:50 +02:00
UTIL_SetSize( pev, VEC_HULL_MIN, VEC_HULL_MAX );
2016-06-04 15:24:23 +02:00
}
g_engfuncs.pfnSetPhysicsKeyValue( edict(), "hl", "1" );
2016-07-31 15:48:50 +02:00
if( m_fLongJump )
2016-06-04 15:24:23 +02:00
{
g_engfuncs.pfnSetPhysicsKeyValue( edict(), "slj", "1" );
}
else
{
g_engfuncs.pfnSetPhysicsKeyValue( edict(), "slj", "0" );
}
RenewItems();
2021-06-07 16:17:22 +02:00
#if CLIENT_WEAPONS
2016-06-04 15:24:23 +02:00
// HACK: This variable is saved/restored in CBaseMonster as a time variable, but we're using it
// as just a counter. Ideally, this needs its own variable that's saved as a plain float.
// Barring that, we clear it out here instead of using the incorrect restored time value.
m_flNextAttack = UTIL_WeaponTimeBase();
#endif
2024-01-26 21:46:15 +01:00
if( m_flFlashLightTime == 0.0f )
m_flFlashLightTime = 1.0f;
2016-06-04 15:24:23 +02:00
return status;
}
void CBasePlayer::SelectNextItem( int iItem )
{
CBasePlayerItem *pItem;
2016-07-31 15:48:50 +02:00
pItem = m_rgpPlayerItems[iItem];
if( !pItem )
2016-06-04 15:24:23 +02:00
return;
2016-07-31 15:48:50 +02:00
if( pItem == m_pActiveItem )
2016-06-04 15:24:23 +02:00
{
// select the next one in the chain
pItem = m_pActiveItem->m_pNext;
2016-07-31 15:48:50 +02:00
if( !pItem )
2016-06-04 15:24:23 +02:00
{
return;
}
CBasePlayerItem *pLast;
pLast = pItem;
2016-07-31 15:48:50 +02:00
while( pLast->m_pNext )
2016-06-04 15:24:23 +02:00
pLast = pLast->m_pNext;
// relink chain
pLast->m_pNext = m_pActiveItem;
m_pActiveItem->m_pNext = NULL;
2016-07-31 15:48:50 +02:00
m_rgpPlayerItems[iItem] = pItem;
2016-06-04 15:24:23 +02:00
}
2016-07-31 15:48:50 +02:00
ResetAutoaim();
2016-06-04 15:24:23 +02:00
// FIX, this needs to queue them up and delay
2016-07-31 15:48:50 +02:00
if( m_pActiveItem )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
m_pActiveItem->Holster();
2016-06-04 15:24:23 +02:00
}
2016-07-31 15:48:50 +02:00
2016-06-04 15:24:23 +02:00
m_pActiveItem = pItem;
2016-07-31 15:48:50 +02:00
if( m_pActiveItem )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
m_pActiveItem->Deploy();
m_pActiveItem->UpdateItemInfo();
2016-06-04 15:24:23 +02:00
}
}
2016-07-31 15:48:50 +02:00
void CBasePlayer::SelectItem( const char *pstr )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( !pstr )
2016-06-04 15:24:23 +02:00
return;
CBasePlayerItem *pItem = NULL;
2016-07-31 15:48:50 +02:00
for( int i = 0; i < MAX_ITEM_TYPES; i++ )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( m_rgpPlayerItems[i] )
2016-06-04 15:24:23 +02:00
{
pItem = m_rgpPlayerItems[i];
2016-07-31 15:48:50 +02:00
while( pItem )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( FClassnameIs( pItem->pev, pstr ) )
2016-06-04 15:24:23 +02:00
break;
pItem = pItem->m_pNext;
}
}
2016-07-31 15:48:50 +02:00
if( pItem )
2016-06-04 15:24:23 +02:00
break;
}
2016-07-31 15:48:50 +02:00
if( !pItem )
2016-06-04 15:24:23 +02:00
return;
2016-07-31 15:48:50 +02:00
if( pItem == m_pActiveItem )
2016-06-04 15:24:23 +02:00
return;
2016-07-31 15:48:50 +02:00
ResetAutoaim();
2016-06-04 15:24:23 +02:00
// FIX, this needs to queue them up and delay
2016-07-31 15:48:50 +02:00
if( m_pActiveItem )
m_pActiveItem->Holster();
2016-06-04 15:24:23 +02:00
m_pLastItem = m_pActiveItem;
m_pActiveItem = pItem;
2016-07-31 15:48:50 +02:00
if( m_pActiveItem )
2016-06-04 15:24:23 +02:00
{
m_pActiveItem->pev->oldbuttons = 1;
2016-07-31 15:48:50 +02:00
m_pActiveItem->Deploy();
m_pActiveItem->pev->oldbuttons = 0;
2016-07-31 15:48:50 +02:00
m_pActiveItem->UpdateItemInfo();
2016-06-04 15:24:23 +02:00
}
}
2016-07-31 15:48:50 +02:00
void CBasePlayer::SelectLastItem( void )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( !m_pLastItem )
2016-06-04 15:24:23 +02:00
{
return;
}
2016-07-31 15:48:50 +02:00
if( m_pActiveItem && !m_pActiveItem->CanHolster() )
2016-06-04 15:24:23 +02:00
{
return;
}
2016-07-31 15:48:50 +02:00
ResetAutoaim();
2016-06-04 15:24:23 +02:00
// FIX, this needs to queue them up and delay
2016-07-31 15:48:50 +02:00
if( m_pActiveItem )
m_pActiveItem->Holster();
2016-06-04 15:24:23 +02:00
CBasePlayerItem *pTemp = m_pActiveItem;
m_pActiveItem = m_pLastItem;
m_pLastItem = pTemp;
m_pActiveItem->pev->oldbuttons = 1;
2016-07-31 15:48:50 +02:00
m_pActiveItem->Deploy();
m_pActiveItem->pev->oldbuttons = 0;
2016-07-31 15:48:50 +02:00
m_pActiveItem->UpdateItemInfo();
2016-06-04 15:24:23 +02:00
}
//==============================================
// HasWeapons - do I have any weapons at all?
//==============================================
BOOL CBasePlayer::HasWeapons( void )
{
int i;
2016-07-31 15:48:50 +02:00
for( i = 0; i < MAX_ITEM_TYPES; i++ )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( m_rgpPlayerItems[i] )
2016-06-04 15:24:23 +02:00
{
return TRUE;
}
}
return FALSE;
}
void CBasePlayer::SelectPrevItem( int iItem )
{
}
const char *CBasePlayer::TeamID( void )
{
2016-07-31 15:48:50 +02:00
if( pev == NULL ) // Not fully connected yet
2016-06-04 15:24:23 +02:00
return "";
// return their team name
return m_szTeamName;
}
//==============================================
// !!!UNDONE:ultra temporary SprayCan entity to apply
// decal frame at a time. For PreAlpha CD
//==============================================
class CSprayCan : public CBaseEntity
{
public:
2016-07-31 15:48:50 +02:00
void Spawn( entvars_t *pevOwner );
void Think( void );
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
virtual int ObjectCaps( void ) { return FCAP_DONT_SAVE; }
2016-06-04 15:24:23 +02:00
};
2016-07-31 15:48:50 +02:00
void CSprayCan::Spawn( entvars_t *pevOwner )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
pev->origin = pevOwner->origin + Vector( 0, 0, 32 );
2016-06-04 15:24:23 +02:00
pev->angles = pevOwner->v_angle;
2016-07-31 15:48:50 +02:00
pev->owner = ENT( pevOwner );
2016-06-04 15:24:23 +02:00
pev->frame = 0;
2019-10-13 13:49:25 +02:00
pev->nextthink = gpGlobals->time + 0.1f;
2016-07-31 15:48:50 +02:00
EMIT_SOUND( ENT( pev ), CHAN_VOICE, "player/sprayer.wav", 1, ATTN_NORM );
2016-06-04 15:24:23 +02:00
}
void CSprayCan::Think( void )
{
2016-07-31 15:48:50 +02:00
TraceResult tr;
2016-06-04 15:24:23 +02:00
int playernum;
int nFrames;
CBasePlayer *pPlayer;
2016-07-31 15:48:50 +02:00
pPlayer = (CBasePlayer *)GET_PRIVATE( pev->owner );
if( pPlayer )
2016-06-04 15:24:23 +02:00
nFrames = pPlayer->GetCustomDecalFrames();
else
nFrames = -1;
2016-07-31 15:48:50 +02:00
playernum = ENTINDEX( pev->owner );
// ALERT( at_console, "Spray by player %i, %i of %i\n", playernum, (int)( pev->frame + 1 ), nFrames );
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
UTIL_MakeVectors( pev->angles );
UTIL_TraceLine( pev->origin, pev->origin + gpGlobals->v_forward * 128, ignore_monsters, pev->owner, & tr );
2016-06-04 15:24:23 +02:00
// No customization present.
2016-07-31 15:48:50 +02:00
if( nFrames == -1 )
2016-06-04 15:24:23 +02:00
{
UTIL_DecalTrace( &tr, DECAL_LAMBDA6 );
UTIL_Remove( this );
}
else
{
2017-06-29 15:56:03 +02:00
UTIL_PlayerDecalTrace( &tr, playernum, (int)pev->frame, TRUE );
2016-06-04 15:24:23 +02:00
// Just painted last custom frame.
2016-07-31 15:48:50 +02:00
if( pev->frame++ >= ( nFrames - 1 ) )
2016-06-04 15:24:23 +02:00
UTIL_Remove( this );
}
2019-10-13 13:49:25 +02:00
pev->nextthink = gpGlobals->time + 0.1f;
2016-06-04 15:24:23 +02:00
}
2016-07-31 15:48:50 +02:00
class CBloodSplat : public CBaseEntity
2016-06-04 15:24:23 +02:00
{
public:
2016-07-31 15:48:50 +02:00
void Spawn( entvars_t *pevOwner );
void Spray( void );
2016-06-04 15:24:23 +02:00
};
2016-07-31 15:48:50 +02:00
void CBloodSplat::Spawn( entvars_t *pevOwner )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
pev->origin = pevOwner->origin + Vector( 0, 0, 32 );
2016-06-04 15:24:23 +02:00
pev->angles = pevOwner->v_angle;
2016-07-31 15:48:50 +02:00
pev->owner = ENT( pevOwner );
2016-06-04 15:24:23 +02:00
SetThink( &CBloodSplat::Spray );
2019-10-13 13:49:25 +02:00
pev->nextthink = gpGlobals->time + 0.1f;
2016-06-04 15:24:23 +02:00
}
2016-07-31 15:48:50 +02:00
void CBloodSplat::Spray( void )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
TraceResult tr;
UTIL_MakeVectors( pev->angles );
UTIL_TraceLine( pev->origin, pev->origin + gpGlobals->v_forward * 128, ignore_monsters, pev->owner, & tr );
UTIL_BloodDecalTrace( &tr, BLOOD_COLOR_RED );
2016-06-04 15:24:23 +02:00
SetThink( &CBaseEntity::SUB_Remove );
2019-10-13 13:49:25 +02:00
pev->nextthink = gpGlobals->time + 0.1f;
2016-06-04 15:24:23 +02:00
}
//==============================================
void CBasePlayer::GiveNamedItem( const char *pszName )
{
edict_t *pent;
2016-07-31 15:48:50 +02:00
int istr = MAKE_STRING( pszName );
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
pent = CREATE_NAMED_ENTITY( istr );
if( FNullEnt( pent ) )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
ALERT( at_console, "NULL Ent in GiveNamedItem!\n" );
2016-06-04 15:24:23 +02:00
return;
}
VARS( pent )->origin = pev->origin;
pent->v.spawnflags |= SF_NORESPAWN;
DispatchSpawn( pent );
DispatchTouch( pent, ENT( pev ) );
}
CBaseEntity *FindEntityForward( CBaseEntity *pMe )
{
TraceResult tr;
2016-07-31 15:48:50 +02:00
UTIL_MakeVectors( pMe->pev->v_angle );
UTIL_TraceLine( pMe->pev->origin + pMe->pev->view_ofs,pMe->pev->origin + pMe->pev->view_ofs + gpGlobals->v_forward * 8192,dont_ignore_monsters, pMe->edict(), &tr );
2019-10-13 13:49:25 +02:00
if( tr.flFraction != 1.0f && !FNullEnt( tr.pHit ) )
2016-06-04 15:24:23 +02:00
{
CBaseEntity *pHit = CBaseEntity::Instance( tr.pHit );
return pHit;
}
return NULL;
}
2016-07-31 15:48:50 +02:00
BOOL CBasePlayer::FlashlightIsOn( void )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
return FBitSet( pev->effects, EF_DIMLIGHT );
2016-06-04 15:24:23 +02:00
}
2016-07-31 15:48:50 +02:00
void CBasePlayer::FlashlightTurnOn( void )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( !g_pGameRules->FAllowFlashlight() )
2016-06-04 15:24:23 +02:00
{
return;
}
2016-07-31 15:48:50 +02:00
if( (pev->weapons & ( 1 << WEAPON_SUIT ) ) )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
EMIT_SOUND_DYN( ENT( pev ), CHAN_WEAPON, SOUND_FLASHLIGHT_ON, 1.0, ATTN_NORM, 0, PITCH_NORM );
SetBits( pev->effects, EF_DIMLIGHT );
2016-06-04 15:24:23 +02:00
MESSAGE_BEGIN( MSG_ONE, gmsgFlashlight, NULL, pev );
2016-07-31 15:48:50 +02:00
WRITE_BYTE( 1 );
WRITE_BYTE( m_iFlashBattery );
2016-06-04 15:24:23 +02:00
MESSAGE_END();
m_flFlashLightTime = FLASH_DRAIN_TIME + gpGlobals->time;
}
}
2016-07-31 15:48:50 +02:00
void CBasePlayer::FlashlightTurnOff( void )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
EMIT_SOUND_DYN( ENT( pev ), CHAN_WEAPON, SOUND_FLASHLIGHT_OFF, 1.0, ATTN_NORM, 0, PITCH_NORM );
ClearBits( pev->effects, EF_DIMLIGHT );
2016-06-04 15:24:23 +02:00
MESSAGE_BEGIN( MSG_ONE, gmsgFlashlight, NULL, pev );
2016-07-31 15:48:50 +02:00
WRITE_BYTE( 0 );
WRITE_BYTE( m_iFlashBattery );
2016-06-04 15:24:23 +02:00
MESSAGE_END();
m_flFlashLightTime = FLASH_CHARGE_TIME + gpGlobals->time;
}
/*
===============
ForceClientDllUpdate
When recording a demo, we need to have the server tell us the entire client state
so that the client side .dll can behave correctly.
Reset stuff so that the state is transmitted.
===============
*/
2016-07-31 15:48:50 +02:00
void CBasePlayer::ForceClientDllUpdate( void )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
m_iClientHealth = -1;
2016-06-04 15:24:23 +02:00
m_iClientBattery = -1;
m_iClientHideHUD = -1; // Vit_amiN: forcing to update
m_iClientFOV = -1; // Vit_amiN: force client weapons to be sent
2016-06-04 15:24:23 +02:00
m_iTrain |= TRAIN_NEW; // Force new train message.
m_fWeapon = FALSE; // Force weapon send
m_fKnownItem = FALSE; // Force weaponinit messages.
m_fInitHUD = TRUE; // Force HUD gmsgResetHUD message
memset( m_rgAmmoLast, 0, sizeof( m_rgAmmoLast )); // a1ba: Force update AmmoX
2016-06-04 15:24:23 +02:00
// Now force all the necessary messages
// to be sent.
UpdateClientData();
}
/*
============
ImpulseCommands
============
*/
extern cvar_t *g_enable_cheats;
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
void CBasePlayer::ImpulseCommands()
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
TraceResult tr;// UNDONE: kill me! This is temporary for PreAlpha CDs
2016-06-04 15:24:23 +02:00
// Handle use events
PlayerUse();
2016-06-04 15:24:23 +02:00
int iImpulse = (int)pev->impulse;
2016-07-31 15:48:50 +02:00
switch( iImpulse )
2016-06-04 15:24:23 +02:00
{
case 99:
int iOn;
2016-07-31 15:48:50 +02:00
if( !gmsgLogo )
2016-06-04 15:24:23 +02:00
{
iOn = 1;
2016-07-31 15:48:50 +02:00
gmsgLogo = REG_USER_MSG( "Logo", 1 );
2016-06-04 15:24:23 +02:00
}
else
{
iOn = 0;
}
2016-06-04 15:24:23 +02:00
ASSERT( gmsgLogo > 0 );
2016-06-04 15:24:23 +02:00
// send "health" update message
MESSAGE_BEGIN( MSG_ONE, gmsgLogo, NULL, pev );
2016-07-31 15:48:50 +02:00
WRITE_BYTE( iOn );
2016-06-04 15:24:23 +02:00
MESSAGE_END();
if(!iOn)
gmsgLogo = 0;
break;
case 100:
// temporary flashlight for level designers
2016-07-31 15:48:50 +02:00
if( FlashlightIsOn() )
2016-06-04 15:24:23 +02:00
{
FlashlightTurnOff();
}
2016-07-31 15:48:50 +02:00
else
2016-06-04 15:24:23 +02:00
{
FlashlightTurnOn();
}
break;
case 201:
// paint decal
2016-07-31 15:48:50 +02:00
if( gpGlobals->time < m_flNextDecalTime )
2016-06-04 15:24:23 +02:00
{
// too early!
break;
}
2016-07-31 15:48:50 +02:00
UTIL_MakeVectors( pev->v_angle );
UTIL_TraceLine( pev->origin + pev->view_ofs, pev->origin + pev->view_ofs + gpGlobals->v_forward * 128, ignore_monsters, ENT( pev ), &tr );
2016-06-04 15:24:23 +02:00
2019-10-13 13:49:25 +02:00
if( tr.flFraction != 1.0f )
{
// line hit something, so paint a decal
2016-06-04 15:24:23 +02:00
m_flNextDecalTime = gpGlobals->time + decalfrequency.value;
2016-07-31 15:48:50 +02:00
CSprayCan *pCan = GetClassPtr( (CSprayCan *)NULL );
2016-06-04 15:24:23 +02:00
pCan->Spawn( pev );
}
break;
default:
// check all of the cheat impulse commands now
CheatImpulseCommands( iImpulse );
break;
}
2016-06-04 15:24:23 +02:00
pev->impulse = 0;
}
//=========================================================
//=========================================================
void CBasePlayer::CheatImpulseCommands( int iImpulse )
{
2021-06-07 16:17:22 +02:00
#if !HLDEMO_BUILD
if( g_enable_cheats->value == 0 )
2016-06-04 15:24:23 +02:00
{
return;
}
CBaseEntity *pEntity;
TraceResult tr;
2016-07-31 15:48:50 +02:00
switch( iImpulse )
2016-06-04 15:24:23 +02:00
{
case 76:
2016-07-31 15:48:50 +02:00
if( !giPrecacheGrunt )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
giPrecacheGrunt = 1;
ALERT( at_console, "You must now restart to use Grunt-o-matic.\n" );
2016-06-04 15:24:23 +02:00
}
2016-07-31 15:48:50 +02:00
else
{
UTIL_MakeVectors( Vector( 0, pev->v_angle.y, 0 ) );
Create( "monster_human_grunt", pev->origin + gpGlobals->v_forward * 128, pev->angles );
}
break;
2016-06-04 15:24:23 +02:00
case 101:
gEvilImpulse101 = TRUE;
GiveNamedItem( "item_suit" );
GiveNamedItem( "item_battery" );
GiveNamedItem( "weapon_crowbar" );
GiveNamedItem( "weapon_9mmhandgun" );
GiveNamedItem( "ammo_9mmclip" );
GiveNamedItem( "weapon_shotgun" );
GiveNamedItem( "ammo_buckshot" );
GiveNamedItem( "weapon_9mmAR" );
GiveNamedItem( "ammo_9mmAR" );
GiveNamedItem( "ammo_ARgrenades" );
GiveNamedItem( "weapon_handgrenade" );
GiveNamedItem( "weapon_tripmine" );
2021-06-07 02:05:58 +02:00
#if !OEM_BUILD
2016-06-04 15:24:23 +02:00
GiveNamedItem( "weapon_357" );
GiveNamedItem( "ammo_357" );
GiveNamedItem( "weapon_crossbow" );
GiveNamedItem( "ammo_crossbow" );
GiveNamedItem( "weapon_egon" );
GiveNamedItem( "weapon_gauss" );
GiveNamedItem( "ammo_gaussclip" );
GiveNamedItem( "weapon_rpg" );
GiveNamedItem( "ammo_rpgclip" );
GiveNamedItem( "weapon_satchel" );
GiveNamedItem( "weapon_snark" );
GiveNamedItem( "weapon_hornetgun" );
#endif
gEvilImpulse101 = FALSE;
break;
case 102:
// Gibbage!!!
CGib::SpawnRandomGibs( pev, 1, 1 );
break;
case 103:
// What the hell are you doing?
pEntity = FindEntityForward( this );
2016-07-31 15:48:50 +02:00
if( pEntity )
2016-06-04 15:24:23 +02:00
{
CBaseMonster *pMonster = pEntity->MyMonsterPointer();
2016-07-31 15:48:50 +02:00
if( pMonster )
2016-06-04 15:24:23 +02:00
pMonster->ReportAIState();
}
break;
case 104:
// Dump all of the global state varaibles (and global entity names)
gGlobalState.DumpGlobals();
break;
case 105:// player makes no sound for monsters to hear.
2016-07-31 15:48:50 +02:00
if( m_fNoPlayerSound )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
ALERT( at_console, "Player is audible\n" );
m_fNoPlayerSound = FALSE;
}
else
{
ALERT( at_console, "Player is silent\n" );
m_fNoPlayerSound = TRUE;
2016-06-04 15:24:23 +02:00
}
2016-07-31 15:48:50 +02:00
break;
2016-06-04 15:24:23 +02:00
case 106:
// Give me the classname and targetname of this entity.
pEntity = FindEntityForward( this );
2016-07-31 15:48:50 +02:00
if( pEntity )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
ALERT( at_console, "Classname: %s", STRING( pEntity->pev->classname ) );
if( !FStringNull( pEntity->pev->targetname ) )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
ALERT( at_console, " - Targetname: %s\n", STRING( pEntity->pev->targetname ) );
2016-06-04 15:24:23 +02:00
}
else
{
2016-07-31 15:48:50 +02:00
ALERT( at_console, " - TargetName: No Targetname\n" );
2016-06-04 15:24:23 +02:00
}
2016-07-31 15:48:50 +02:00
ALERT( at_console, "Model: %s\n", STRING( pEntity->pev->model ) );
if( pEntity->pev->globalname )
ALERT( at_console, "Globalname: %s\n", STRING( pEntity->pev->globalname ) );
2016-06-04 15:24:23 +02:00
}
break;
case 107:
{
//TraceResult tr;
2016-07-31 15:48:50 +02:00
edict_t *pWorld = g_engfuncs.pfnPEntityOfEntIndex( 0 );
2016-06-04 15:24:23 +02:00
Vector start = pev->origin + pev->view_ofs;
Vector end = start + gpGlobals->v_forward * 1024;
UTIL_TraceLine( start, end, ignore_monsters, edict(), &tr );
2016-07-31 15:48:50 +02:00
if( tr.pHit )
2016-06-04 15:24:23 +02:00
pWorld = tr.pHit;
const char *pTextureName = TRACE_TEXTURE( pWorld, start, end );
2016-07-31 15:48:50 +02:00
if( pTextureName )
2016-06-04 15:24:23 +02:00
ALERT( at_console, "Texture: %s\n", pTextureName );
}
break;
2016-07-31 15:48:50 +02:00
case 195:
// show shortest paths for entire level to nearest node
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
Create( "node_viewer_fly", pev->origin, pev->angles );
2016-06-04 15:24:23 +02:00
}
break;
2016-07-31 15:48:50 +02:00
case 196:
// show shortest paths for entire level to nearest node
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
Create( "node_viewer_large", pev->origin, pev->angles );
2016-06-04 15:24:23 +02:00
}
break;
2016-07-31 15:48:50 +02:00
case 197:
// show shortest paths for entire level to nearest node
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
Create( "node_viewer_human", pev->origin, pev->angles );
2016-06-04 15:24:23 +02:00
}
break;
2016-07-31 15:48:50 +02:00
case 199:
// show nearest node and all connections
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
ALERT( at_console, "%d\n", WorldGraph.FindNearestNode( pev->origin, bits_NODE_GROUP_REALM ) );
WorldGraph.ShowNodeConnections( WorldGraph.FindNearestNode( pev->origin, bits_NODE_GROUP_REALM ) );
2016-06-04 15:24:23 +02:00
}
break;
2016-07-31 15:48:50 +02:00
case 202:
// Random blood splatter
UTIL_MakeVectors( pev->v_angle );
UTIL_TraceLine( pev->origin + pev->view_ofs, pev->origin + pev->view_ofs + gpGlobals->v_forward * 128, ignore_monsters, ENT( pev ), &tr );
2016-06-04 15:24:23 +02:00
2019-10-13 13:49:25 +02:00
if( tr.flFraction != 1.0f )
{
// line hit something, so paint a decal
2016-07-31 15:48:50 +02:00
CBloodSplat *pBlood = GetClassPtr( (CBloodSplat *)NULL );
2016-06-04 15:24:23 +02:00
pBlood->Spawn( pev );
}
break;
2016-07-31 15:48:50 +02:00
case 203:
// remove creature.
2016-06-04 15:24:23 +02:00
pEntity = FindEntityForward( this );
2016-07-31 15:48:50 +02:00
if( pEntity )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( pEntity->pev->takedamage )
pEntity->SetThink( &CBaseEntity::SUB_Remove );
2016-06-04 15:24:23 +02:00
}
break;
}
#endif // HLDEMO_BUILD
}
//
// Add a weapon to the player (Item == Weapon == Selectable Object)
//
int CBasePlayer::AddPlayerItem( CBasePlayerItem *pItem )
{
CBasePlayerItem *pInsert;
2016-06-04 15:24:23 +02:00
pInsert = m_rgpPlayerItems[pItem->iItemSlot()];
2016-07-31 15:48:50 +02:00
while( pInsert )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( FClassnameIs( pInsert->pev, STRING( pItem->pev->classname ) ) )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( pItem->AddDuplicate( pInsert ) )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
g_pGameRules->PlayerGotWeapon( this, pItem );
2016-06-04 15:24:23 +02:00
pItem->CheckRespawn();
// ugly hack to update clip w/o an update clip message
2016-07-31 15:48:50 +02:00
pInsert->UpdateItemInfo();
if( m_pActiveItem )
m_pActiveItem->UpdateItemInfo();
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
pItem->Kill();
2016-06-04 15:24:23 +02:00
}
2016-07-31 15:48:50 +02:00
else if( gEvilImpulse101 )
2016-06-04 15:24:23 +02:00
{
// FIXME: remove anyway for deathmatch testing
2016-07-31 15:48:50 +02:00
pItem->Kill();
2016-06-04 15:24:23 +02:00
}
return FALSE;
}
pInsert = pInsert->m_pNext;
}
2016-07-31 15:48:50 +02:00
if( pItem->AddToPlayer( this ) )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
g_pGameRules->PlayerGotWeapon( this, pItem );
2016-06-04 15:24:23 +02:00
pItem->CheckRespawn();
pItem->m_pNext = m_rgpPlayerItems[pItem->iItemSlot()];
m_rgpPlayerItems[pItem->iItemSlot()] = pItem;
// should we switch to this item?
2016-07-31 15:48:50 +02:00
if( g_pGameRules->FShouldSwitchWeapon( this, pItem ) )
2016-06-04 15:24:23 +02:00
{
SwitchWeapon( pItem );
}
return TRUE;
}
2016-07-31 15:48:50 +02:00
else if( gEvilImpulse101 )
2016-06-04 15:24:23 +02:00
{
// FIXME: remove anyway for deathmatch testing
2016-07-31 15:48:50 +02:00
pItem->Kill();
2016-06-04 15:24:23 +02:00
}
return FALSE;
}
int CBasePlayer::RemovePlayerItem( CBasePlayerItem *pItem, bool bCallHolster )
2016-06-04 15:24:23 +02:00
{
pItem->pev->nextthink = 0;// crowbar may be trying to swing again, etc.
pItem->SetThink( NULL );
2016-07-31 15:48:50 +02:00
if( m_pActiveItem == pItem )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
ResetAutoaim();
if( bCallHolster )
pItem->Holster();
2016-06-04 15:24:23 +02:00
m_pActiveItem = NULL;
pev->viewmodel = 0;
pev->weaponmodel = 0;
}
// In some cases an item can be both the active and last item, like for instance dropping all weapons and only having an exhaustible weapon left. - Solokiller
if( m_pLastItem == pItem )
2016-06-04 15:24:23 +02:00
m_pLastItem = NULL;
CBasePlayerItem *pPrev = m_rgpPlayerItems[pItem->iItemSlot()];
2016-07-31 15:48:50 +02:00
if( pPrev == pItem )
2016-06-04 15:24:23 +02:00
{
m_rgpPlayerItems[pItem->iItemSlot()] = pItem->m_pNext;
return TRUE;
}
else
{
2016-07-31 15:48:50 +02:00
while( pPrev && pPrev->m_pNext != pItem )
2016-06-04 15:24:23 +02:00
{
pPrev = pPrev->m_pNext;
}
2016-07-31 15:48:50 +02:00
if( pPrev )
2016-06-04 15:24:23 +02:00
{
pPrev->m_pNext = pItem->m_pNext;
return TRUE;
}
}
return FALSE;
}
//
// Returns the unique ID for the ammo, or -1 if error
//
2017-06-29 15:56:03 +02:00
int CBasePlayer::GiveAmmo( int iCount, const char *szName, int iMax )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( !szName )
2016-06-04 15:24:23 +02:00
{
// no ammo.
return -1;
}
2016-07-31 15:48:50 +02:00
if( !g_pGameRules->CanHaveAmmo( this, szName, iMax ) )
2016-06-04 15:24:23 +02:00
{
// game rules say I can't have any more of this ammo type.
return -1;
}
int i = 0;
i = GetAmmoIndex( szName );
2016-07-31 15:48:50 +02:00
if( i < 0 || i >= MAX_AMMO_SLOTS )
2016-06-04 15:24:23 +02:00
return -1;
2017-10-14 21:57:55 +02:00
int iAdd = Q_min( iCount, iMax - m_rgAmmo[i] );
2016-07-31 15:48:50 +02:00
if( iAdd < 1 )
2016-06-04 15:24:23 +02:00
return i;
2016-07-31 15:48:50 +02:00
m_rgAmmo[i] += iAdd;
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
if( gmsgAmmoPickup ) // make sure the ammo messages have been linked first
2016-06-04 15:24:23 +02:00
{
// Send the message that ammo has been picked up
MESSAGE_BEGIN( MSG_ONE, gmsgAmmoPickup, NULL, pev );
2016-07-31 15:48:50 +02:00
WRITE_BYTE( GetAmmoIndex( szName ) ); // ammo ID
2016-06-04 15:24:23 +02:00
WRITE_BYTE( iAdd ); // amount
MESSAGE_END();
}
TabulateAmmo();
return i;
}
/*
============
ItemPreFrame
Called every frame by the player PreThink
============
*/
void CBasePlayer::ItemPreFrame()
{
2021-06-07 16:17:22 +02:00
#if CLIENT_WEAPONS
2016-07-31 15:48:50 +02:00
if( m_flNextAttack > 0 )
2016-06-04 15:24:23 +02:00
#else
2016-07-31 15:48:50 +02:00
if( gpGlobals->time < m_flNextAttack )
2016-06-04 15:24:23 +02:00
#endif
{
return;
}
2016-07-31 15:48:50 +02:00
if( !m_pActiveItem )
2016-06-04 15:24:23 +02:00
return;
2016-07-31 15:48:50 +02:00
m_pActiveItem->ItemPreFrame();
2016-06-04 15:24:23 +02:00
}
/*
============
ItemPostFrame
Called every frame by the player PostThink
============
*/
void CBasePlayer::ItemPostFrame()
{
2017-06-29 15:56:03 +02:00
//static int fInSelect = FALSE;
2016-06-04 15:24:23 +02:00
// check if the player is using a tank
2017-06-29 15:56:03 +02:00
if( m_pTank != 0 )
2016-06-04 15:24:23 +02:00
return;
2021-06-07 16:17:22 +02:00
#if CLIENT_WEAPONS
2016-07-31 15:48:50 +02:00
if( m_flNextAttack > 0 )
2016-06-04 15:24:23 +02:00
#else
2016-07-31 15:48:50 +02:00
if( gpGlobals->time < m_flNextAttack )
2016-06-04 15:24:23 +02:00
#endif
{
return;
}
ImpulseCommands();
2016-07-31 15:48:50 +02:00
if( !m_pActiveItem )
2016-06-04 15:24:23 +02:00
return;
2016-07-31 15:48:50 +02:00
m_pActiveItem->ItemPostFrame();
2016-06-04 15:24:23 +02:00
}
int CBasePlayer::AmmoInventory( int iAmmoIndex )
{
2016-07-31 15:48:50 +02:00
if( iAmmoIndex == -1 )
2016-06-04 15:24:23 +02:00
{
return -1;
}
2016-07-31 15:48:50 +02:00
return m_rgAmmo[iAmmoIndex];
2016-06-04 15:24:23 +02:00
}
2016-07-31 15:48:50 +02:00
int CBasePlayer::GetAmmoIndex( const char *psz )
2016-06-04 15:24:23 +02:00
{
int i;
2016-07-31 15:48:50 +02:00
if( !psz )
2016-06-04 15:24:23 +02:00
return -1;
2016-07-31 15:48:50 +02:00
for( i = 1; i < MAX_AMMO_SLOTS; i++ )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( !CBasePlayerItem::AmmoInfoArray[i].pszName )
2016-06-04 15:24:23 +02:00
continue;
2016-07-31 15:48:50 +02:00
if( stricmp( psz, CBasePlayerItem::AmmoInfoArray[i].pszName ) == 0 )
2016-06-04 15:24:23 +02:00
return i;
}
return -1;
}
// Called from UpdateClientData
// makes sure the client has all the necessary ammo info, if values have changed
2016-07-31 15:48:50 +02:00
void CBasePlayer::SendAmmoUpdate( void )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
for( int i = 0; i < MAX_AMMO_SLOTS; i++ )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( m_rgAmmo[i] != m_rgAmmoLast[i] )
2016-06-04 15:24:23 +02:00
{
m_rgAmmoLast[i] = m_rgAmmo[i];
ASSERT( m_rgAmmo[i] >= 0 );
ASSERT( m_rgAmmo[i] < 255 );
// send "Ammo" update message
MESSAGE_BEGIN( MSG_ONE, gmsgAmmoX, NULL, pev );
WRITE_BYTE( i );
2017-10-14 21:57:55 +02:00
WRITE_BYTE( Q_max( Q_min( m_rgAmmo[i], 254 ), 0 ) ); // clamp the value to one byte
2016-06-04 15:24:23 +02:00
MESSAGE_END();
}
}
}
/*
=========================================================
UpdateClientData
resends any changed player HUD info to the client.
Called every frame by PlayerPreThink
Also called at start of demo recording and playback by
ForceClientDllUpdate to ensure the demo gets messages
reflecting all of the HUD state info.
=========================================================
*/
2016-07-31 15:48:50 +02:00
void CBasePlayer::UpdateClientData( void )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( m_fInitHUD )
2016-06-04 15:24:23 +02:00
{
m_fInitHUD = FALSE;
gInitHUD = FALSE;
MESSAGE_BEGIN( MSG_ONE, gmsgResetHUD, NULL, pev );
WRITE_BYTE( 0 );
MESSAGE_END();
2016-07-31 15:48:50 +02:00
if( !m_fGameHUDInitialized )
2016-06-04 15:24:23 +02:00
{
MESSAGE_BEGIN( MSG_ONE, gmsgInitHUD, NULL, pev );
MESSAGE_END();
g_pGameRules->InitHUD( this );
m_fGameHUDInitialized = TRUE;
m_iObserverLastMode = OBS_ROAMING;
2016-07-31 15:48:50 +02:00
if( g_pGameRules->IsMultiplayer() )
2016-06-04 15:24:23 +02:00
{
FireTargets( "game_playerjoin", this, this, USE_TOGGLE, 0 );
}
}
FireTargets( "game_playerspawn", this, this, USE_TOGGLE, 0 );
// Send flashlight status
MESSAGE_BEGIN( MSG_ONE, gmsgFlashlight, NULL, pev );
WRITE_BYTE( FlashlightIsOn() ? 1 : 0 );
WRITE_BYTE( m_iFlashBattery );
MESSAGE_END();
// Vit_amiN: the geiger state could run out of sync, too
MESSAGE_BEGIN( MSG_ONE, gmsgGeigerRange, NULL, pev );
WRITE_BYTE( 0 );
MESSAGE_END();
2016-06-04 15:24:23 +02:00
InitStatusBar();
}
2016-07-31 15:48:50 +02:00
if( m_iHideHUD != m_iClientHideHUD )
2016-06-04 15:24:23 +02:00
{
MESSAGE_BEGIN( MSG_ONE, gmsgHideWeapon, NULL, pev );
WRITE_BYTE( m_iHideHUD );
MESSAGE_END();
m_iClientHideHUD = m_iHideHUD;
}
2016-07-31 15:48:50 +02:00
if( m_iFOV != m_iClientFOV )
2016-06-04 15:24:23 +02:00
{
MESSAGE_BEGIN( MSG_ONE, gmsgSetFOV, NULL, pev );
WRITE_BYTE( m_iFOV );
MESSAGE_END();
// cache FOV change at end of function, so weapon updates can see that FOV has changed
}
// HACKHACK -- send the message to display the game title
2016-07-31 15:48:50 +02:00
if( gDisplayTitle )
2016-06-04 15:24:23 +02:00
{
MESSAGE_BEGIN( MSG_ONE, gmsgShowGameTitle, NULL, pev );
WRITE_BYTE( 0 );
MESSAGE_END();
gDisplayTitle = 0;
}
2016-07-31 15:48:50 +02:00
if( pev->health != m_iClientHealth )
2016-06-04 15:24:23 +02:00
{
#define clamp( val, min, max ) ( ((val) > (max)) ? (max) : ( ((val) < (min)) ? (min) : (val) ) )
int iHealth = clamp( pev->health, 0, 255 ); // make sure that no negative health values are sent
if( pev->health > 0.0f && pev->health <= 1.0f )
iHealth = 1;
2016-06-04 15:24:23 +02:00
// send "health" update message
MESSAGE_BEGIN( MSG_ONE, gmsgHealth, NULL, pev );
WRITE_BYTE( iHealth );
MESSAGE_END();
2017-06-29 15:56:03 +02:00
m_iClientHealth = (int)pev->health;
2016-06-04 15:24:23 +02:00
}
if( (int)pev->armorvalue != m_iClientBattery )
2016-06-04 15:24:23 +02:00
{
2017-06-29 15:56:03 +02:00
m_iClientBattery = (int)pev->armorvalue;
2016-06-04 15:24:23 +02:00
ASSERT( gmsgBattery > 0 );
2016-06-04 15:24:23 +02:00
// send "health" update message
MESSAGE_BEGIN( MSG_ONE, gmsgBattery, NULL, pev );
2016-07-31 15:48:50 +02:00
WRITE_SHORT( (int)pev->armorvalue );
2016-06-04 15:24:23 +02:00
MESSAGE_END();
}
2016-07-31 15:48:50 +02:00
if( pev->dmg_take || pev->dmg_save || m_bitsHUDDamage != m_bitsDamageType )
2016-06-04 15:24:23 +02:00
{
// Comes from inside me if not set
Vector damageOrigin = pev->origin;
// send "damage" message
// causes screen to flash, and pain compass to show direction of damage
edict_t *other = pev->dmg_inflictor;
2016-07-31 15:48:50 +02:00
if( other )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
CBaseEntity *pEntity = CBaseEntity::Instance( other );
if( pEntity )
2016-06-04 15:24:23 +02:00
damageOrigin = pEntity->Center();
}
// only send down damage type that have hud art
int visibleDamageBits = m_bitsDamageType & DMG_SHOWNHUD;
MESSAGE_BEGIN( MSG_ONE, gmsgDamage, NULL, pev );
2017-06-29 15:56:03 +02:00
WRITE_BYTE( (int)pev->dmg_save );
WRITE_BYTE( (int)pev->dmg_take );
2016-06-04 15:24:23 +02:00
WRITE_LONG( visibleDamageBits );
WRITE_COORD( damageOrigin.x );
WRITE_COORD( damageOrigin.y );
WRITE_COORD( damageOrigin.z );
MESSAGE_END();
2016-07-31 15:48:50 +02:00
2016-06-04 15:24:23 +02:00
pev->dmg_take = 0;
pev->dmg_save = 0;
m_bitsHUDDamage = m_bitsDamageType;
2016-07-31 15:48:50 +02:00
2016-06-04 15:24:23 +02:00
// Clear off non-time-based damage indicators
m_bitsDamageType &= DMG_TIMEBASED;
}
// Update Flashlight
2016-07-31 15:48:50 +02:00
if( ( m_flFlashLightTime ) && ( m_flFlashLightTime <= gpGlobals->time ) )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( FlashlightIsOn() )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( m_iFlashBattery )
2016-06-04 15:24:23 +02:00
{
m_flFlashLightTime = FLASH_DRAIN_TIME + gpGlobals->time;
m_iFlashBattery--;
2016-07-31 15:48:50 +02:00
if( !m_iFlashBattery )
2016-06-04 15:24:23 +02:00
FlashlightTurnOff();
}
}
else
{
2016-07-31 15:48:50 +02:00
if( m_iFlashBattery < 100 )
2016-06-04 15:24:23 +02:00
{
m_flFlashLightTime = FLASH_CHARGE_TIME + gpGlobals->time;
m_iFlashBattery++;
}
else
m_flFlashLightTime = 0;
}
MESSAGE_BEGIN( MSG_ONE, gmsgFlashBattery, NULL, pev );
2016-07-31 15:48:50 +02:00
WRITE_BYTE( m_iFlashBattery );
2016-06-04 15:24:23 +02:00
MESSAGE_END();
}
2016-07-31 15:48:50 +02:00
if( m_iTrain & TRAIN_NEW )
2016-06-04 15:24:23 +02:00
{
ASSERT( gmsgTrain > 0 );
2016-06-04 15:24:23 +02:00
// send "health" update message
MESSAGE_BEGIN( MSG_ONE, gmsgTrain, NULL, pev );
2016-07-31 15:48:50 +02:00
WRITE_BYTE( m_iTrain & 0xF );
2016-06-04 15:24:23 +02:00
MESSAGE_END();
m_iTrain &= ~TRAIN_NEW;
}
//
// New Weapon?
//
2016-07-31 15:48:50 +02:00
if( !m_fKnownItem )
2016-06-04 15:24:23 +02:00
{
m_fKnownItem = TRUE;
// WeaponInit Message
// byte = # of weapons
//
// for each weapon:
// byte name str length (not including null)
// bytes... name
// byte Ammo Type
// byte Ammo2 Type
// byte bucket
// byte bucket pos
2016-07-31 15:48:50 +02:00
// byte flags
2016-06-04 15:24:23 +02:00
// ???? Icons
2016-06-04 15:24:23 +02:00
// Send ALL the weapon info now
int i;
2016-07-31 15:48:50 +02:00
for( i = 0; i < MAX_WEAPONS; i++ )
2016-06-04 15:24:23 +02:00
{
ItemInfo& II = CBasePlayerItem::ItemInfoArray[i];
2016-07-31 15:48:50 +02:00
if( !II.iId )
2016-06-04 15:24:23 +02:00
continue;
const char *pszName;
2016-07-31 15:48:50 +02:00
if( !II.pszName )
2016-06-04 15:24:23 +02:00
pszName = "Empty";
else
pszName = II.pszName;
MESSAGE_BEGIN( MSG_ONE, gmsgWeaponList, NULL, pev );
2016-07-31 15:48:50 +02:00
WRITE_STRING( pszName ); // string weapon name
WRITE_BYTE( GetAmmoIndex( II.pszAmmo1 ) ); // byte Ammo Type
WRITE_BYTE( II.iMaxAmmo1 ); // byte Max Ammo 1
WRITE_BYTE( GetAmmoIndex( II.pszAmmo2 ) ); // byte Ammo2 Type
WRITE_BYTE( II.iMaxAmmo2 ); // byte Max Ammo 2
WRITE_BYTE( II.iSlot ); // byte bucket
WRITE_BYTE( II.iPosition ); // byte bucket pos
WRITE_BYTE( II.iId ); // byte id (bit index into pev->weapons)
WRITE_BYTE( II.iFlags ); // byte Flags
2016-06-04 15:24:23 +02:00
MESSAGE_END();
}
}
SendAmmoUpdate();
// Update all the items
2016-07-31 15:48:50 +02:00
for( int i = 0; i < MAX_ITEM_TYPES; i++ )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( m_rgpPlayerItems[i] ) // each item updates it's successors
2016-06-04 15:24:23 +02:00
m_rgpPlayerItems[i]->UpdateClientData( this );
}
// Cache and client weapon change
m_pClientActiveItem = m_pActiveItem;
m_iClientFOV = m_iFOV;
// Update Status Bar
2016-07-31 15:48:50 +02:00
if( m_flNextSBarUpdateTime < gpGlobals->time )
2016-06-04 15:24:23 +02:00
{
UpdateStatusBar();
2019-10-13 13:49:25 +02:00
m_flNextSBarUpdateTime = gpGlobals->time + 0.2f;
2016-06-04 15:24:23 +02:00
}
}
//=========================================================
// FBecomeProne - Overridden for the player to set the proper
// physics flags when a barnacle grabs player.
//=========================================================
2016-07-31 15:48:50 +02:00
BOOL CBasePlayer::FBecomeProne( void )
2016-06-04 15:24:23 +02:00
{
m_afPhysicsFlags |= PFLAG_ONBARNACLE;
return TRUE;
}
//=========================================================
// BarnacleVictimBitten - bad name for a function that is called
// by Barnacle victims when the barnacle pulls their head
// into its mouth. For the player, just die.
//=========================================================
2016-07-31 15:48:50 +02:00
void CBasePlayer::BarnacleVictimBitten( entvars_t *pevBarnacle )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
TakeDamage( pevBarnacle, pevBarnacle, pev->health + pev->armorvalue, DMG_SLASH | DMG_ALWAYSGIB );
2016-06-04 15:24:23 +02:00
}
//=========================================================
// BarnacleVictimReleased - overridden for player who has
// physics flags concerns.
//=========================================================
2016-07-31 15:48:50 +02:00
void CBasePlayer::BarnacleVictimReleased( void )
2016-06-04 15:24:23 +02:00
{
m_afPhysicsFlags &= ~PFLAG_ONBARNACLE;
}
//=========================================================
// Illumination
// return player light level plus virtual muzzle flash
//=========================================================
2016-07-31 15:48:50 +02:00
int CBasePlayer::Illumination( void )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
int iIllum = CBaseEntity::Illumination();
2016-06-04 15:24:23 +02:00
iIllum += m_iWeaponFlash;
2016-07-31 15:48:50 +02:00
if( iIllum > 255 )
2016-06-04 15:24:23 +02:00
return 255;
return iIllum;
}
void CBasePlayer::SetPrefsFromUserinfo( char *infobuffer )
{
const char *pszKeyVal;
pszKeyVal = g_engfuncs.pfnInfoKeyValue( infobuffer, "cl_autowepswitch" );
if( pszKeyVal[0] != '\0' )
m_iAutoWepSwitch = atoi( pszKeyVal );
else
m_iAutoWepSwitch = 1;
}
2016-07-31 15:48:50 +02:00
void CBasePlayer::EnableControl( BOOL fControl )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( !fControl )
2016-06-04 15:24:23 +02:00
pev->flags |= FL_FROZEN;
else
pev->flags &= ~FL_FROZEN;
}
#define DOT_1DEGREE 0.9998476951564
#define DOT_2DEGREE 0.9993908270191
#define DOT_3DEGREE 0.9986295347546
#define DOT_4DEGREE 0.9975640502598
#define DOT_5DEGREE 0.9961946980917
#define DOT_6DEGREE 0.9945218953683
#define DOT_7DEGREE 0.9925461516413
#define DOT_8DEGREE 0.9902680687416
#define DOT_9DEGREE 0.9876883405951
#define DOT_10DEGREE 0.9848077530122
#define DOT_15DEGREE 0.9659258262891
#define DOT_20DEGREE 0.9396926207859
#define DOT_25DEGREE 0.9063077870367
//=========================================================
// Autoaim
// set crosshair position to point to enemey
//=========================================================
2016-07-31 15:48:50 +02:00
Vector CBasePlayer::GetAutoaimVector( float flDelta )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( g_iSkillLevel == SKILL_HARD )
2016-06-04 15:24:23 +02:00
{
UTIL_MakeVectors( pev->v_angle + pev->punchangle );
return gpGlobals->v_forward;
}
2016-07-31 15:48:50 +02:00
Vector vecSrc = GetGunPosition();
2019-10-13 13:49:25 +02:00
float flDist = 8192.0f;
2016-06-04 15:24:23 +02:00
// always use non-sticky autoaim
// UNDONE: use sever variable to chose!
2016-07-31 15:48:50 +02:00
if( 1 || g_iSkillLevel == SKILL_MEDIUM )
2016-06-04 15:24:23 +02:00
{
m_vecAutoAim = Vector( 0, 0, 0 );
// flDelta *= 0.5;
}
BOOL m_fOldTargeting = m_fOnTarget;
Vector angles = AutoaimDeflection(vecSrc, flDist, flDelta );
// update ontarget if changed
2016-07-31 15:48:50 +02:00
if( !g_pGameRules->AllowAutoTargetCrosshair() )
2016-06-04 15:24:23 +02:00
m_fOnTarget = 0;
2016-07-31 15:48:50 +02:00
else if( m_fOldTargeting != m_fOnTarget )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
m_pActiveItem->UpdateItemInfo();
2016-06-04 15:24:23 +02:00
}
2016-07-31 15:48:50 +02:00
if( angles.x > 180 )
2016-06-04 15:24:23 +02:00
angles.x -= 360;
2016-07-31 15:48:50 +02:00
if( angles.x < -180 )
2016-06-04 15:24:23 +02:00
angles.x += 360;
2016-07-31 15:48:50 +02:00
if( angles.y > 180 )
2016-06-04 15:24:23 +02:00
angles.y -= 360;
2016-07-31 15:48:50 +02:00
if( angles.y < -180 )
2016-06-04 15:24:23 +02:00
angles.y += 360;
2016-07-31 15:48:50 +02:00
if( angles.x > 25 )
2016-06-04 15:24:23 +02:00
angles.x = 25;
2016-07-31 15:48:50 +02:00
if( angles.x < -25 )
2016-06-04 15:24:23 +02:00
angles.x = -25;
2016-07-31 15:48:50 +02:00
if( angles.y > 12 )
2016-06-04 15:24:23 +02:00
angles.y = 12;
2016-07-31 15:48:50 +02:00
if( angles.y < -12 )
2016-06-04 15:24:23 +02:00
angles.y = -12;
// always use non-sticky autoaim
// UNDONE: use sever variable to chose!
2016-07-31 15:48:50 +02:00
if( 0 || g_iSkillLevel == SKILL_EASY )
2016-06-04 15:24:23 +02:00
{
2019-10-13 13:49:25 +02:00
m_vecAutoAim = m_vecAutoAim * 0.67f + angles * 0.33f;
2016-06-04 15:24:23 +02:00
}
else
{
2019-10-13 13:49:25 +02:00
m_vecAutoAim = angles * 0.9f;
2016-06-04 15:24:23 +02:00
}
// m_vecAutoAim = m_vecAutoAim * 0.99;
// Don't send across network if sv_aim is 0
2016-07-31 15:48:50 +02:00
if( g_psv_aim->value != 0 )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( m_vecAutoAim.x != m_lastx || m_vecAutoAim.y != m_lasty )
2016-06-04 15:24:23 +02:00
{
SET_CROSSHAIRANGLE( edict(), -m_vecAutoAim.x, m_vecAutoAim.y );
2016-07-31 15:48:50 +02:00
2017-06-29 15:56:03 +02:00
m_lastx = (int)m_vecAutoAim.x;
m_lasty = (int)m_vecAutoAim.y;
2016-06-04 15:24:23 +02:00
}
}
// ALERT( at_console, "%f %f\n", angles.x, angles.y );
UTIL_MakeVectors( pev->v_angle + pev->punchangle + m_vecAutoAim );
return gpGlobals->v_forward;
}
2016-07-31 15:48:50 +02:00
Vector CBasePlayer::AutoaimDeflection( Vector &vecSrc, float flDist, float flDelta )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
edict_t *pEdict = g_engfuncs.pfnPEntityOfEntIndex( 1 );
CBaseEntity *pEntity;
float bestdot;
Vector bestdir;
edict_t *bestent;
2016-06-04 15:24:23 +02:00
TraceResult tr;
2016-07-31 15:48:50 +02:00
if( g_psv_aim->value == 0 )
2016-06-04 15:24:23 +02:00
{
m_fOnTarget = FALSE;
return g_vecZero;
}
UTIL_MakeVectors( pev->v_angle + pev->punchangle + m_vecAutoAim );
// try all possible entities
bestdir = gpGlobals->v_forward;
bestdot = flDelta; // +- 10 degrees
bestent = NULL;
m_fOnTarget = FALSE;
UTIL_TraceLine( vecSrc, vecSrc + bestdir * flDist, dont_ignore_monsters, edict(), &tr );
2016-07-31 15:48:50 +02:00
if( tr.pHit && tr.pHit->v.takedamage != DAMAGE_NO )
2016-06-04 15:24:23 +02:00
{
// don't look through water
2016-07-31 15:48:50 +02:00
if( !( ( pev->waterlevel != 3 && tr.pHit->v.waterlevel == 3 ) || ( pev->waterlevel == 3 && tr.pHit->v.waterlevel == 0 ) ) )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( tr.pHit->v.takedamage == DAMAGE_AIM )
2016-06-04 15:24:23 +02:00
m_fOnTarget = TRUE;
return m_vecAutoAim;
}
}
2016-07-31 15:48:50 +02:00
for( int i = 1; i < gpGlobals->maxEntities; i++, pEdict++ )
2016-06-04 15:24:23 +02:00
{
Vector center;
Vector dir;
float dot;
2016-07-31 15:48:50 +02:00
if( pEdict->free ) // Not in use
2016-06-04 15:24:23 +02:00
continue;
2016-07-31 15:48:50 +02:00
if( pEdict->v.takedamage != DAMAGE_AIM )
2016-06-04 15:24:23 +02:00
continue;
2016-07-31 15:48:50 +02:00
if( pEdict == edict() )
2016-06-04 15:24:23 +02:00
continue;
2016-07-31 15:48:50 +02:00
//if( pev->team > 0 && pEdict->v.team == pev->team )
// continue; // don't aim at teammate
2016-07-31 15:48:50 +02:00
if( !g_pGameRules->ShouldAutoAim( this, pEdict ) )
2016-06-04 15:24:23 +02:00
continue;
pEntity = Instance( pEdict );
2016-07-31 15:48:50 +02:00
if( pEntity == NULL )
2016-06-04 15:24:23 +02:00
continue;
2016-07-31 15:48:50 +02:00
if( !pEntity->IsAlive() )
2016-06-04 15:24:23 +02:00
continue;
// don't look through water
2016-07-31 15:48:50 +02:00
if( ( pev->waterlevel != 3 && pEntity->pev->waterlevel == 3 ) || ( pev->waterlevel == 3 && pEntity->pev->waterlevel == 0 ) )
2016-06-04 15:24:23 +02:00
continue;
center = pEntity->BodyTarget( vecSrc );
2016-07-31 15:48:50 +02:00
dir = ( center - vecSrc ).Normalize();
2016-06-04 15:24:23 +02:00
// make sure it's in front of the player
2016-07-31 15:48:50 +02:00
if( DotProduct( dir, gpGlobals->v_forward ) < 0 )
2016-06-04 15:24:23 +02:00
continue;
2019-10-13 13:49:25 +02:00
dot = fabs( DotProduct( dir, gpGlobals->v_right ) ) + fabs( DotProduct( dir, gpGlobals->v_up ) ) * 0.5f;
2016-06-04 15:24:23 +02:00
// tweek for distance
2019-10-13 13:49:25 +02:00
dot *= 1.0f + 0.2f * ( ( center - vecSrc ).Length() / flDist );
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
if( dot > bestdot )
2016-06-04 15:24:23 +02:00
continue; // to far to turn
UTIL_TraceLine( vecSrc, center, dont_ignore_monsters, edict(), &tr );
2019-10-13 13:49:25 +02:00
if( tr.flFraction != 1.0f && tr.pHit != pEdict )
2016-06-04 15:24:23 +02:00
{
// ALERT( at_console, "hit %s, can't see %s\n", STRING( tr.pHit->v.classname ), STRING( pEdict->v.classname ) );
continue;
}
// don't shoot at friends
2016-07-31 15:48:50 +02:00
if( IRelationship( pEntity ) < 0 )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( !pEntity->IsPlayer() && !g_pGameRules->IsDeathmatch() )
// ALERT( at_console, "friend\n" );
2016-06-04 15:24:23 +02:00
continue;
}
// can shoot at this one
bestdot = dot;
bestent = pEdict;
bestdir = dir;
}
2016-07-31 15:48:50 +02:00
if( bestent )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
bestdir = UTIL_VecToAngles( bestdir );
2016-06-04 15:24:23 +02:00
bestdir.x = -bestdir.x;
bestdir = bestdir - pev->v_angle - pev->punchangle;
2016-07-31 15:48:50 +02:00
if( bestent->v.takedamage == DAMAGE_AIM )
2016-06-04 15:24:23 +02:00
m_fOnTarget = TRUE;
return bestdir;
}
return Vector( 0, 0, 0 );
}
2016-07-31 15:48:50 +02:00
void CBasePlayer::ResetAutoaim()
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( m_vecAutoAim.x != 0 || m_vecAutoAim.y != 0 )
2016-06-04 15:24:23 +02:00
{
m_vecAutoAim = Vector( 0, 0, 0 );
SET_CROSSHAIRANGLE( edict(), 0, 0 );
}
m_fOnTarget = FALSE;
}
/*
=============
SetCustomDecalFrames
UNDONE: Determine real frame limit, 8 is a placeholder.
Note: -1 means no custom frames present.
=============
*/
2016-07-31 15:48:50 +02:00
void CBasePlayer::SetCustomDecalFrames( int nFrames )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( nFrames > 0 && nFrames < 8 )
2016-06-04 15:24:23 +02:00
m_nCustomSprayFrames = nFrames;
else
m_nCustomSprayFrames = -1;
}
/*
=============
GetCustomDecalFrames
Returns the # of custom frames this player's custom clan logo contains.
=============
*/
2016-07-31 15:48:50 +02:00
int CBasePlayer::GetCustomDecalFrames( void )
2016-06-04 15:24:23 +02:00
{
return m_nCustomSprayFrames;
}
//=========================================================
// DropPlayerItem - drop the named item, or if no name,
// the active item.
//=========================================================
2016-07-31 15:48:50 +02:00
void CBasePlayer::DropPlayerItem( char *pszItemName )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( !g_pGameRules->IsMultiplayer() || ( weaponstay.value > 0 ) )
2016-06-04 15:24:23 +02:00
{
// no dropping in single player.
return;
}
2019-09-24 00:00:37 +02:00
if( pszItemName[0] == '\0' )
2016-06-04 15:24:23 +02:00
{
// if this string has no length, the client didn't type a name!
// assume player wants to drop the active item.
// make the string null to make future operations in this function easier
pszItemName = NULL;
}
CBasePlayerItem *pWeapon;
int i;
2016-07-31 15:48:50 +02:00
for( i = 0; i < MAX_ITEM_TYPES; i++ )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
pWeapon = m_rgpPlayerItems[i];
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
while( pWeapon )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( pszItemName )
2016-06-04 15:24:23 +02:00
{
// try to match by name.
2016-07-31 15:48:50 +02:00
if( !strcmp( pszItemName, STRING( pWeapon->pev->classname ) ) )
2016-06-04 15:24:23 +02:00
{
// match!
break;
}
}
else
{
// trying to drop active item
2016-07-31 15:48:50 +02:00
if( pWeapon == m_pActiveItem )
2016-06-04 15:24:23 +02:00
{
// active item!
break;
}
}
pWeapon = pWeapon->m_pNext;
}
// if we land here with a valid pWeapon pointer, that's because we found the
// item we want to drop and hit a BREAK; pWeapon is the item.
2016-07-31 15:48:50 +02:00
if( pWeapon )
2016-06-04 15:24:23 +02:00
{
if( !g_pGameRules->GetNextBestWeapon( this, pWeapon ) )
return; // can't drop the item they asked for, may be our last item or something we can't holster
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
UTIL_MakeVectors( pev->angles );
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
pev->weapons &= ~( 1 << pWeapon->m_iId );// take item off hud
2016-06-04 15:24:23 +02:00
CWeaponBox *pWeaponBox = (CWeaponBox *)CBaseEntity::Create( "weaponbox", pev->origin + gpGlobals->v_forward * 10, pev->angles, edict() );
pWeaponBox->pev->angles.x = 0;
pWeaponBox->pev->angles.z = 0;
pWeaponBox->PackWeapon( pWeapon );
pWeaponBox->pev->velocity = gpGlobals->v_forward * 300 + gpGlobals->v_forward * 100;
// drop half of the ammo for this weapon.
2016-07-31 15:48:50 +02:00
int iAmmoIndex;
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
iAmmoIndex = GetAmmoIndex( pWeapon->pszAmmo1() ); // ???
if( iAmmoIndex != -1 )
2016-06-04 15:24:23 +02:00
{
// this weapon weapon uses ammo, so pack an appropriate amount.
2016-07-31 15:48:50 +02:00
if( pWeapon->iFlags() & ITEM_FLAG_EXHAUSTIBLE )
2016-06-04 15:24:23 +02:00
{
// pack up all the ammo, this weapon is its own ammo type
2016-07-31 15:48:50 +02:00
pWeaponBox->PackAmmo( MAKE_STRING( pWeapon->pszAmmo1() ), m_rgAmmo[iAmmoIndex] );
m_rgAmmo[iAmmoIndex] = 0;
2016-06-04 15:24:23 +02:00
}
else
{
// pack half of the ammo
2016-07-31 15:48:50 +02:00
pWeaponBox->PackAmmo( MAKE_STRING( pWeapon->pszAmmo1() ), m_rgAmmo[iAmmoIndex] / 2 );
m_rgAmmo[iAmmoIndex] /= 2;
2016-06-04 15:24:23 +02:00
}
}
return;// we're done, so stop searching with the FOR loop.
}
}
}
//=========================================================
// HasPlayerItem Does the player already have this item?
//=========================================================
BOOL CBasePlayer::HasPlayerItem( CBasePlayerItem *pCheckItem )
{
CBasePlayerItem *pItem = m_rgpPlayerItems[pCheckItem->iItemSlot()];
2016-07-31 15:48:50 +02:00
while( pItem )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( FClassnameIs( pItem->pev, STRING( pCheckItem->pev->classname ) ) )
2016-06-04 15:24:23 +02:00
{
return TRUE;
}
pItem = pItem->m_pNext;
}
return FALSE;
}
//=========================================================
// HasNamedPlayerItem Does the player already have this item?
//=========================================================
BOOL CBasePlayer::HasNamedPlayerItem( const char *pszItemName )
{
CBasePlayerItem *pItem;
int i;
2016-07-31 15:48:50 +02:00
for( i = 0; i < MAX_ITEM_TYPES; i++ )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
pItem = m_rgpPlayerItems[i];
while( pItem )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( !strcmp( pszItemName, STRING( pItem->pev->classname ) ) )
2016-06-04 15:24:23 +02:00
{
return TRUE;
}
pItem = pItem->m_pNext;
}
}
return FALSE;
}
//=========================================================
// HasPlayerItemFromID
//=========================================================
BOOL CBasePlayer::HasPlayerItemFromID( int nID )
{
CBasePlayerItem *pItem;
int i;
for( i = 0; i < MAX_ITEM_TYPES; i++ )
{
pItem = m_rgpPlayerItems[i];
while( pItem )
{
if( nID == pItem->m_iId )
{
return TRUE;
}
pItem = pItem->m_pNext;
}
}
return FALSE;
}
2016-06-04 15:24:23 +02:00
//=========================================================
//
//=========================================================
2016-07-31 15:48:50 +02:00
BOOL CBasePlayer::SwitchWeapon( CBasePlayerItem *pWeapon )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( !pWeapon->CanDeploy() )
2016-06-04 15:24:23 +02:00
{
return FALSE;
}
2016-07-31 15:48:50 +02:00
ResetAutoaim();
if( m_pActiveItem )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
m_pActiveItem->Holster();
2016-06-04 15:24:23 +02:00
}
m_pActiveItem = pWeapon;
pWeapon->pev->oldbuttons = 1;
2016-07-31 15:48:50 +02:00
pWeapon->Deploy();
pWeapon->pev->oldbuttons = 0;
2016-06-04 15:24:23 +02:00
return TRUE;
}
//=========================================================
// Dead HEV suit prop
//=========================================================
class CDeadHEV : public CBaseMonster
{
public:
void Spawn( void );
2016-07-31 15:48:50 +02:00
int Classify( void )
{
return CLASS_HUMAN_MILITARY;
}
2016-06-04 15:24:23 +02:00
void KeyValue( KeyValueData *pkvd );
2016-07-31 15:48:50 +02:00
int m_iPose;// which sequence to display -- temporary, don't need to save
2017-06-29 15:56:03 +02:00
static const char *m_szPoses[4];
2016-06-04 15:24:23 +02:00
};
2017-06-29 15:56:03 +02:00
const char *CDeadHEV::m_szPoses[] =
2016-07-31 15:48:50 +02:00
{
"deadback",
"deadsitting",
"deadstomach",
"deadtable"
};
2016-06-04 15:24:23 +02:00
void CDeadHEV::KeyValue( KeyValueData *pkvd )
{
2016-07-31 15:48:50 +02:00
if( FStrEq( pkvd->szKeyName, "pose" ) )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
m_iPose = atoi( pkvd->szValue );
2016-06-04 15:24:23 +02:00
pkvd->fHandled = TRUE;
}
2016-07-31 15:48:50 +02:00
else
2016-06-04 15:24:23 +02:00
CBaseMonster::KeyValue( pkvd );
}
LINK_ENTITY_TO_CLASS( monster_hevsuit_dead, CDeadHEV )
2016-06-04 15:24:23 +02:00
//=========================================================
// ********** DeadHEV SPAWN **********
//=========================================================
2016-07-31 15:48:50 +02:00
void CDeadHEV::Spawn( void )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
PRECACHE_MODEL( "models/player.mdl" );
SET_MODEL( ENT( pev ), "models/player.mdl" );
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
pev->effects = 0;
pev->yaw_speed = 8;
pev->sequence = 0;
pev->body = 1;
m_bloodColor = BLOOD_COLOR_RED;
2016-06-04 15:24:23 +02:00
pev->sequence = LookupSequence( m_szPoses[m_iPose] );
2016-07-31 15:48:50 +02:00
if( pev->sequence == -1 )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
ALERT( at_console, "Dead hevsuit with bad pose\n" );
2016-06-04 15:24:23 +02:00
pev->sequence = 0;
pev->effects = EF_BRIGHTFIELD;
}
// Corpses have less health
2016-07-31 15:48:50 +02:00
pev->health = 8;
2016-06-04 15:24:23 +02:00
MonsterInitDead();
}
class CStripWeapons : public CPointEntity
{
public:
2016-07-31 15:48:50 +02:00
void Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value );
2016-06-04 15:24:23 +02:00
private:
};
LINK_ENTITY_TO_CLASS( player_weaponstrip, CStripWeapons )
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
void CStripWeapons::Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value )
2016-06-04 15:24:23 +02:00
{
CBasePlayer *pPlayer = NULL;
2016-07-31 15:48:50 +02:00
if( pActivator && pActivator->IsPlayer() )
2016-06-04 15:24:23 +02:00
{
pPlayer = (CBasePlayer *)pActivator;
}
2016-07-31 15:48:50 +02:00
else if( !g_pGameRules->IsDeathmatch() )
2016-06-04 15:24:23 +02:00
{
pPlayer = (CBasePlayer *)CBaseEntity::Instance( g_engfuncs.pfnPEntityOfEntIndex( 1 ) );
}
2016-07-31 15:48:50 +02:00
if( pPlayer )
2016-06-04 15:24:23 +02:00
pPlayer->RemoveAllItems( FALSE );
}
class CRevertSaved : public CPointEntity
{
public:
2016-07-31 15:48:50 +02:00
void Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value );
void EXPORT MessageThink( void );
void EXPORT LoadThink( void );
void KeyValue( KeyValueData *pkvd );
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
virtual int Save( CSave &save );
virtual int Restore( CRestore &restore );
static TYPEDESCRIPTION m_SaveData[];
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
inline float Duration( void ) { return pev->dmg_take; }
inline float HoldTime( void ) { return pev->dmg_save; }
inline float MessageTime( void ) { return m_messageTime; }
inline float LoadTime( void ) { return m_loadTime; }
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
inline void SetDuration( float duration ) { pev->dmg_take = duration; }
inline void SetHoldTime( float hold ) { pev->dmg_save = hold; }
inline void SetMessageTime( float time ) { m_messageTime = time; }
inline void SetLoadTime( float time ) { m_loadTime = time; }
2016-06-04 15:24:23 +02:00
private:
2016-07-31 15:48:50 +02:00
float m_messageTime;
float m_loadTime;
2016-06-04 15:24:23 +02:00
};
LINK_ENTITY_TO_CLASS( player_loadsaved, CRevertSaved )
2016-06-04 15:24:23 +02:00
TYPEDESCRIPTION CRevertSaved::m_SaveData[] =
2016-06-04 15:24:23 +02:00
{
DEFINE_FIELD( CRevertSaved, m_messageTime, FIELD_FLOAT ), // These are not actual times, but durations, so save as floats
DEFINE_FIELD( CRevertSaved, m_loadTime, FIELD_FLOAT ),
};
IMPLEMENT_SAVERESTORE( CRevertSaved, CPointEntity )
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
void CRevertSaved::KeyValue( KeyValueData *pkvd )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( FStrEq( pkvd->szKeyName, "duration" ) )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
SetDuration( atof( pkvd->szValue ) );
2016-06-04 15:24:23 +02:00
pkvd->fHandled = TRUE;
}
2016-07-31 15:48:50 +02:00
else if( FStrEq( pkvd->szKeyName, "holdtime" ) )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
SetHoldTime( atof( pkvd->szValue ) );
2016-06-04 15:24:23 +02:00
pkvd->fHandled = TRUE;
}
2016-07-31 15:48:50 +02:00
else if( FStrEq( pkvd->szKeyName, "messagetime" ) )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
SetMessageTime( atof( pkvd->szValue ) );
2016-06-04 15:24:23 +02:00
pkvd->fHandled = TRUE;
}
2016-07-31 15:48:50 +02:00
else if( FStrEq( pkvd->szKeyName, "loadtime" ) )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
SetLoadTime( atof( pkvd->szValue ) );
2016-06-04 15:24:23 +02:00
pkvd->fHandled = TRUE;
}
2016-07-31 15:48:50 +02:00
else
2016-06-04 15:24:23 +02:00
CPointEntity::KeyValue( pkvd );
}
2016-07-31 15:48:50 +02:00
void CRevertSaved::Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value )
2016-06-04 15:24:23 +02:00
{
2017-06-29 15:56:03 +02:00
UTIL_ScreenFadeAll( pev->rendercolor, Duration(), HoldTime(), (int)pev->renderamt, FFADE_OUT );
2016-06-04 15:24:23 +02:00
pev->nextthink = gpGlobals->time + MessageTime();
SetThink( &CRevertSaved::MessageThink );
}
2016-07-31 15:48:50 +02:00
void CRevertSaved::MessageThink( void )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
UTIL_ShowMessageAll( STRING( pev->message ) );
2016-06-04 15:24:23 +02:00
float nextThink = LoadTime() - MessageTime();
2016-07-31 15:48:50 +02:00
if( nextThink > 0 )
2016-06-04 15:24:23 +02:00
{
pev->nextthink = gpGlobals->time + nextThink;
SetThink( &CRevertSaved::LoadThink );
}
else
LoadThink();
}
2016-07-31 15:48:50 +02:00
void CRevertSaved::LoadThink( void )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( !gpGlobals->deathmatch )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
SERVER_COMMAND( "reload\n" );
2016-06-04 15:24:23 +02:00
}
}
//=========================================================
// Multiplayer intermission spots.
//=========================================================
class CInfoIntermission:public CPointEntity
{
void Spawn( void );
void Think( void );
};
void CInfoIntermission::Spawn( void )
{
UTIL_SetOrigin( pev, pev->origin );
pev->solid = SOLID_NOT;
pev->effects = EF_NODRAW;
pev->v_angle = g_vecZero;
2019-10-13 13:49:25 +02:00
pev->nextthink = gpGlobals->time + 2.0f;// let targets spawn!
2016-06-04 15:24:23 +02:00
}
2016-07-31 15:48:50 +02:00
void CInfoIntermission::Think( void )
2016-06-04 15:24:23 +02:00
{
edict_t *pTarget;
// find my target
2016-07-31 15:48:50 +02:00
pTarget = FIND_ENTITY_BY_TARGETNAME( NULL, STRING( pev->target ) );
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
if( !FNullEnt( pTarget ) )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
pev->v_angle = UTIL_VecToAngles( ( pTarget->v.origin - pev->origin ).Normalize() );
2016-06-04 15:24:23 +02:00
pev->v_angle.x = -pev->v_angle.x;
}
}
LINK_ENTITY_TO_CLASS( info_intermission, CInfoIntermission )