Player.h 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925
  1. /*
  2. ===========================================================================
  3. Doom 3 BFG Edition GPL Source Code
  4. Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
  6. Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.
  17. If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
  18. ===========================================================================
  19. */
  20. #ifndef __GAME_PLAYER_H__
  21. #define __GAME_PLAYER_H__
  22. #include "PredictedValue.h"
  23. /*
  24. ===============================================================================
  25. Player entity.
  26. ===============================================================================
  27. */
  28. class idMenuHandler_PDA;
  29. class idMenuHandler_HUD;
  30. class idMenuScreen_HUD;
  31. class idTarget_SetPrimaryObjective;
  32. extern const idEventDef EV_Player_GetButtons;
  33. extern const idEventDef EV_Player_GetMove;
  34. extern const idEventDef EV_Player_GetViewAngles;
  35. extern const idEventDef EV_Player_EnableWeapon;
  36. extern const idEventDef EV_Player_DisableWeapon;
  37. extern const idEventDef EV_Player_ExitTeleporter;
  38. extern const idEventDef EV_Player_SelectWeapon;
  39. extern const idEventDef EV_SpectatorTouch;
  40. const float THIRD_PERSON_FOCUS_DISTANCE = 512.0f;
  41. const int LAND_DEFLECT_TIME = 150;
  42. const int LAND_RETURN_TIME = 300;
  43. const int FOCUS_TIME = 300;
  44. const int FOCUS_GUI_TIME = 500;
  45. const int NUM_QUICK_SLOTS = 4;
  46. const int MAX_WEAPONS = 32;
  47. const int DEAD_HEARTRATE = 0; // fall to as you die
  48. const int LOWHEALTH_HEARTRATE_ADJ = 20; //
  49. const int DYING_HEARTRATE = 30; // used for volumen calc when dying/dead
  50. const int BASE_HEARTRATE = 70; // default
  51. const int ZEROSTAMINA_HEARTRATE = 115; // no stamina
  52. const int MAX_HEARTRATE = 130; // maximum
  53. const int ZERO_VOLUME = -40; // volume at zero
  54. const int DMG_VOLUME = 5; // volume when taking damage
  55. const int DEATH_VOLUME = 15; // volume at death
  56. const int SAVING_THROW_TIME = 5000; // maximum one "saving throw" every five seconds
  57. const int ASYNC_PLAYER_INV_AMMO_BITS = idMath::BitsForInteger( 3000 );
  58. const int ASYNC_PLAYER_INV_CLIP_BITS = -7; // -7 bits to cover the range [-1, 60]
  59. enum gameExpansionType_t {
  60. GAME_BASE,
  61. GAME_D3XP,
  62. GAME_D3LE,
  63. GAME_UNKNOWN
  64. };
  65. struct idObjectiveInfo {
  66. idStr title;
  67. idStr text;
  68. const idMaterial * screenshot;
  69. };
  70. struct idLevelTriggerInfo {
  71. idStr levelName;
  72. idStr triggerName;
  73. };
  74. // powerups - the "type" in item .def must match
  75. enum {
  76. BERSERK = 0,
  77. INVISIBILITY,
  78. MEGAHEALTH,
  79. ADRENALINE,
  80. INVULNERABILITY,
  81. HELLTIME,
  82. ENVIROSUIT,
  83. //HASTE,
  84. ENVIROTIME,
  85. MAX_POWERUPS
  86. };
  87. // powerup modifiers
  88. enum {
  89. SPEED = 0,
  90. PROJECTILE_DAMAGE,
  91. MELEE_DAMAGE,
  92. MELEE_DISTANCE
  93. };
  94. // influence levels
  95. enum {
  96. INFLUENCE_NONE = 0, // none
  97. INFLUENCE_LEVEL1, // no gun or hud
  98. INFLUENCE_LEVEL2, // no gun, hud, movement
  99. INFLUENCE_LEVEL3, // slow player movement
  100. };
  101. typedef struct {
  102. int ammo;
  103. int rechargeTime;
  104. char ammoName[128];
  105. } RechargeAmmo_t;
  106. typedef struct {
  107. char name[64];
  108. idList<int, TAG_IDLIB_LIST_PLAYER> toggleList;
  109. int lastUsed;
  110. } WeaponToggle_t;
  111. class idInventory {
  112. public:
  113. int maxHealth;
  114. int weapons;
  115. int powerups;
  116. int armor;
  117. int maxarmor;
  118. int powerupEndTime[ MAX_POWERUPS ];
  119. RechargeAmmo_t rechargeAmmo[ AMMO_NUMTYPES ];
  120. // mp
  121. int ammoPredictTime; // Unused now but kept for save file compatibility.
  122. int deplete_armor;
  123. float deplete_rate;
  124. int deplete_ammount;
  125. int nextArmorDepleteTime;
  126. int pdasViewed[4]; // 128 bit flags for indicating if a pda has been viewed
  127. int selPDA;
  128. int selEMail;
  129. int selVideo;
  130. int selAudio;
  131. bool pdaOpened;
  132. idList<idDict *> items;
  133. idList<idStr> pdaSecurity;
  134. idList<const idDeclPDA *> pdas;
  135. idList<const idDeclVideo *> videos;
  136. idList<const idDeclEmail *> emails;
  137. bool ammoPulse;
  138. bool weaponPulse;
  139. bool armorPulse;
  140. int lastGiveTime;
  141. idList<idLevelTriggerInfo, TAG_IDLIB_LIST_PLAYER> levelTriggers;
  142. idInventory() { Clear(); }
  143. ~idInventory() { Clear(); }
  144. // save games
  145. void Save( idSaveGame *savefile ) const; // archives object for save game file
  146. void Restore( idRestoreGame *savefile ); // unarchives object from save game file
  147. void Clear();
  148. void GivePowerUp( idPlayer *player, int powerup, int msec );
  149. void ClearPowerUps();
  150. void GetPersistantData( idDict &dict );
  151. void RestoreInventory( idPlayer *owner, const idDict &dict );
  152. bool Give( idPlayer *owner, const idDict &spawnArgs, const char *statname, const char *value,
  153. idPredictedValue< int > * idealWeapon, bool updateHud, unsigned int giveFlags );
  154. void Drop( const idDict &spawnArgs, const char *weapon_classname, int weapon_index );
  155. ammo_t AmmoIndexForAmmoClass( const char *ammo_classname ) const;
  156. int MaxAmmoForAmmoClass( const idPlayer *owner, const char *ammo_classname ) const;
  157. int WeaponIndexForAmmoClass( const idDict & spawnArgs, const char *ammo_classname ) const;
  158. ammo_t AmmoIndexForWeaponClass( const char *weapon_classname, int *ammoRequired );
  159. const char * AmmoPickupNameForIndex( ammo_t ammonum ) const;
  160. void AddPickupName( const char * name, idPlayer * owner ); //_D3XP
  161. int HasAmmo( ammo_t type, int amount );
  162. bool UseAmmo( ammo_t type, int amount );
  163. int HasAmmo( const char *weapon_classname, bool includeClip = false, idPlayer* owner = NULL ); // _D3XP
  164. bool HasEmptyClipCannotRefill(const char *weapon_classname, idPlayer* owner);
  165. void UpdateArmor();
  166. void SetInventoryAmmoForType( const int ammoType, const int amount );
  167. void SetClipAmmoForWeapon( const int weapon, const int amount );
  168. int GetInventoryAmmoForType( const int ammoType ) const;
  169. int GetClipAmmoForWeapon( const int weapon ) const;
  170. void WriteAmmoToSnapshot( idBitMsg & msg ) const;
  171. void ReadAmmoFromSnapshot( const idBitMsg & msg, int ownerEntityNumber );
  172. void SetRemoteClientAmmo( const int ownerEntityNumber );
  173. int nextItemPickup;
  174. int nextItemNum;
  175. int onePickupTime;
  176. idList<idStr> pickupItemNames;
  177. idList<idObjectiveInfo> objectiveNames;
  178. void InitRechargeAmmo(idPlayer *owner);
  179. void RechargeAmmo(idPlayer *owner);
  180. bool CanGive( idPlayer *owner, const idDict &spawnArgs, const char *statname, const char *value );
  181. private:
  182. idArray< idPredictedValue< int >, AMMO_NUMTYPES > ammo;
  183. idArray< idPredictedValue< int >, MAX_WEAPONS > clip;
  184. };
  185. typedef struct {
  186. int time;
  187. idVec3 dir; // scaled larger for running
  188. } loggedAccel_t;
  189. typedef struct {
  190. int areaNum;
  191. idVec3 pos;
  192. } aasLocation_t;
  193. class idPlayer : public idActor {
  194. public:
  195. enum {
  196. EVENT_IMPULSE = idEntity::EVENT_MAXEVENTS,
  197. EVENT_EXIT_TELEPORTER,
  198. EVENT_ABORT_TELEPORTER,
  199. EVENT_POWERUP,
  200. EVENT_SPECTATE,
  201. EVENT_PICKUPNAME,
  202. EVENT_FORCE_ORIGIN,
  203. EVENT_KNOCKBACK,
  204. EVENT_MAXEVENTS
  205. };
  206. static const int MAX_PLAYER_PDA = 100;
  207. static const int MAX_PLAYER_VIDEO = 100;
  208. static const int MAX_PLAYER_AUDIO = 100;
  209. static const int MAX_PLAYER_AUDIO_ENTRIES = 2;
  210. usercmd_t oldCmd;
  211. usercmd_t usercmd;
  212. class idPlayerView playerView; // handles damage kicks and effects
  213. renderEntity_t laserSightRenderEntity; // replace crosshair for 3DTV
  214. qhandle_t laserSightHandle;
  215. bool noclip;
  216. bool godmode;
  217. bool spawnAnglesSet; // on first usercmd, we must set deltaAngles
  218. idAngles spawnAngles;
  219. idAngles viewAngles; // player view angles
  220. idAngles cmdAngles; // player cmd angles
  221. float independentWeaponPitchAngle; // viewAngles[PITCH} when head tracking is active
  222. // For interpolating angles between snapshots
  223. idQuat previousViewQuat;
  224. idQuat nextViewQuat;
  225. int buttonMask;
  226. int oldButtons;
  227. int oldImpulseSequence;
  228. int lastHitTime; // last time projectile fired by player hit target
  229. int lastSndHitTime; // MP hit sound - != lastHitTime because we throttle
  230. int lastSavingThrowTime; // for the "free miss" effect
  231. bool pdaHasBeenRead[ MAX_PLAYER_PDA ];
  232. bool videoHasBeenViewed[ MAX_PLAYER_VIDEO ];
  233. bool audioHasBeenHeard[ MAX_PLAYER_AUDIO ][ MAX_PLAYER_AUDIO_ENTRIES ];
  234. idScriptBool AI_FORWARD;
  235. idScriptBool AI_BACKWARD;
  236. idScriptBool AI_STRAFE_LEFT;
  237. idScriptBool AI_STRAFE_RIGHT;
  238. idScriptBool AI_ATTACK_HELD;
  239. idScriptBool AI_WEAPON_FIRED;
  240. idScriptBool AI_JUMP;
  241. idScriptBool AI_CROUCH;
  242. idScriptBool AI_ONGROUND;
  243. idScriptBool AI_ONLADDER;
  244. idScriptBool AI_DEAD;
  245. idScriptBool AI_RUN;
  246. idScriptBool AI_PAIN;
  247. idScriptBool AI_HARDLANDING;
  248. idScriptBool AI_SOFTLANDING;
  249. idScriptBool AI_RELOAD;
  250. idScriptBool AI_TELEPORT;
  251. idScriptBool AI_TURN_LEFT;
  252. idScriptBool AI_TURN_RIGHT;
  253. // inventory
  254. idInventory inventory;
  255. idTarget_SetPrimaryObjective * primaryObjective;
  256. int flashlightBattery;
  257. idEntityPtr<idWeapon> flashlight;
  258. idEntityPtr<idWeapon> weapon;
  259. idMenuHandler_HUD * hudManager;
  260. idMenuScreen_HUD * hud;
  261. idMenuHandler_PDA * pdaMenu;
  262. idSWF * mpMessages;
  263. bool objectiveSystemOpen;
  264. int quickSlot[ NUM_QUICK_SLOTS ];
  265. int weapon_soulcube;
  266. int weapon_pda;
  267. int weapon_fists;
  268. int weapon_flashlight;
  269. int weapon_chainsaw;
  270. int weapon_bloodstone;
  271. int weapon_bloodstone_active1;
  272. int weapon_bloodstone_active2;
  273. int weapon_bloodstone_active3;
  274. bool harvest_lock;
  275. int heartRate;
  276. idInterpolate<float> heartInfo;
  277. int lastHeartAdjust;
  278. int lastHeartBeat;
  279. int lastDmgTime;
  280. int deathClearContentsTime;
  281. bool doingDeathSkin;
  282. int lastArmorPulse; // lastDmgTime if we had armor at time of hit
  283. float stamina;
  284. float healthPool; // amount of health to give over time
  285. int nextHealthPulse;
  286. bool healthPulse;
  287. bool healthTake;
  288. int nextHealthTake;
  289. //-----------------------------------------------------------------
  290. // controller shake parms
  291. //-----------------------------------------------------------------
  292. const static int MAX_SHAKE_BUFFER = 3;
  293. float controllerShakeHighMag[ MAX_SHAKE_BUFFER ]; // magnitude of the high frequency controller shake
  294. float controllerShakeLowMag[ MAX_SHAKE_BUFFER ]; // magnitude of the low frequency controller shake
  295. int controllerShakeHighTime[ MAX_SHAKE_BUFFER ]; // time the controller shake ends for high frequency.
  296. int controllerShakeLowTime[ MAX_SHAKE_BUFFER ]; // time the controller shake ends for low frequency.
  297. int controllerShakeTimeGroup;
  298. bool hiddenWeapon; // if the weapon is hidden ( in noWeapons maps )
  299. idEntityPtr<idProjectile> soulCubeProjectile;
  300. idAimAssist aimAssist;
  301. int spectator;
  302. bool forceScoreBoard;
  303. bool forceRespawn;
  304. bool spectating;
  305. int lastSpectateTeleport;
  306. bool lastHitToggle;
  307. bool wantSpectate; // from userInfo
  308. bool weaponGone; // force stop firing
  309. bool useInitialSpawns; // toggled by a map restart to be active for the first game spawn
  310. int tourneyRank; // for tourney cycling - the higher, the more likely to play next - server
  311. int tourneyLine; // client side - our spot in the wait line. 0 means no info.
  312. int spawnedTime; // when client first enters the game
  313. bool carryingFlag; // is the player carrying the flag?
  314. idEntityPtr<idEntity> teleportEntity; // while being teleported, this is set to the entity we'll use for exit
  315. int teleportKiller; // entity number of an entity killing us at teleporter exit
  316. bool lastManOver; // can't respawn in last man anymore (srv only)
  317. bool lastManPlayAgain; // play again when end game delay is cancelled out before expiring (srv only)
  318. bool lastManPresent; // true when player was in when game started (spectators can't join a running LMS)
  319. bool isLagged; // replicated from server, true if packets haven't been received from client.
  320. int isChatting; // replicated from server, true if the player is chatting.
  321. // timers
  322. int minRespawnTime; // can respawn when time > this, force after g_forcerespawn
  323. int maxRespawnTime; // force respawn after this time
  324. // the first person view values are always calculated, even
  325. // if a third person view is used
  326. idVec3 firstPersonViewOrigin;
  327. idMat3 firstPersonViewAxis;
  328. idDragEntity dragEntity;
  329. idFuncMountedObject * mountedObject;
  330. idEntityPtr<idLight> enviroSuitLight;
  331. bool healthRecharge;
  332. int lastHealthRechargeTime;
  333. int rechargeSpeed;
  334. float new_g_damageScale;
  335. bool bloomEnabled;
  336. float bloomSpeed;
  337. float bloomIntensity;
  338. public:
  339. CLASS_PROTOTYPE( idPlayer );
  340. idPlayer();
  341. virtual ~idPlayer();
  342. void Spawn();
  343. void Think();
  344. void UpdateLaserSight();
  345. // save games
  346. void Save( idSaveGame *savefile ) const; // archives object for save game file
  347. void Restore( idRestoreGame *savefile ); // unarchives object from save game file
  348. virtual void Hide();
  349. virtual void Show();
  350. void Init();
  351. void PrepareForRestart();
  352. virtual void Restart();
  353. void LinkScriptVariables();
  354. void SetupWeaponEntity();
  355. void SelectInitialSpawnPoint( idVec3 &origin, idAngles &angles );
  356. void SpawnFromSpawnSpot();
  357. void SpawnToPoint( const idVec3 &spawn_origin, const idAngles &spawn_angles );
  358. void SetClipModel(); // spectator mode uses a different bbox size
  359. void SavePersistantInfo();
  360. void RestorePersistantInfo();
  361. void SetLevelTrigger( const char *levelName, const char *triggerName );
  362. void CacheWeapons();
  363. void EnterCinematic();
  364. void ExitCinematic();
  365. void UpdateConditions();
  366. void SetViewAngles( const idAngles &angles );
  367. // Controller Shake
  368. void ControllerShakeFromDamage( int damage );
  369. void SetControllerShake( float highMagnitude, int highDuration, float lowMagnitude, int lowDuration );
  370. void ResetControllerShake();
  371. void GetControllerShake( int & highMagnitude, int & lowMagnitude ) const;
  372. idAimAssist * GetAimAssist() { return &aimAssist; }
  373. // delta view angles to allow movers to rotate the view of the player
  374. void UpdateDeltaViewAngles( const idAngles &angles );
  375. virtual bool Collide( const trace_t &collision, const idVec3 &velocity );
  376. virtual void GetAASLocation( idAAS *aas, idVec3 &pos, int &areaNum ) const;
  377. virtual void GetAIAimTargets( const idVec3 &lastSightPos, idVec3 &headPos, idVec3 &chestPos );
  378. virtual void DamageFeedback( idEntity *victim, idEntity *inflictor, int &damage );
  379. void CalcDamagePoints( idEntity *inflictor, idEntity *attacker, const idDict *damageDef,
  380. const float damageScale, const int location, int *health, int *armor );
  381. virtual void Damage( idEntity *inflictor, idEntity *attacker, const idVec3 &dir, const char *damageDefName, const float damageScale, const int location );
  382. // New damage path for instant client feedback.
  383. void ServerDealDamage( int damage, idEntity & inflictor, idEntity & attacker, const idVec3 & dir, const char * damageDefName, const int location ); // Actually updates the player's health independent of feedback.
  384. int AdjustDamageAmount( const int inputDamage );
  385. // use exitEntityNum to specify a teleport with private camera view and delayed exit
  386. virtual void Teleport( const idVec3 &origin, const idAngles &angles, idEntity *destination );
  387. void Kill( bool delayRespawn, bool nodamage );
  388. virtual void Killed( idEntity *inflictor, idEntity *attacker, int damage, const idVec3 &dir, int location );
  389. void StartFxOnBone(const char *fx, const char *bone);
  390. renderView_t * GetRenderView();
  391. void CalculateRenderView(); // called every tic by player code
  392. void CalculateFirstPersonView();
  393. void AddChatMessage( int index, int alpha, const idStr & message );
  394. void UpdateSpectatingText();
  395. void ClearChatMessage( int index );
  396. void DrawHUD( idMenuHandler_HUD * hudManager );
  397. void WeaponFireFeedback( const idDict *weaponDef );
  398. float DefaultFov() const;
  399. float CalcFov( bool honorZoom );
  400. void CalculateViewWeaponPos( idVec3 &origin, idMat3 &axis );
  401. idVec3 GetEyePosition() const;
  402. void GetViewPos( idVec3 &origin, idMat3 &axis ) const;
  403. void OffsetThirdPersonView( float angle, float range, float height, bool clip );
  404. bool Give( const char *statname, const char *value, unsigned int giveFlags );
  405. bool GiveItem( idItem *item, unsigned int giveFlags );
  406. void GiveItem( const char *name );
  407. void GiveHealthPool( float amt );
  408. void SetPrimaryObjective( idTarget_SetPrimaryObjective * target ) { primaryObjective = target; }
  409. idTarget_SetPrimaryObjective * GetPrimaryObjective() { return primaryObjective; }
  410. idInventory & GetInventory() { return inventory; }
  411. bool GiveInventoryItem( idDict *item, unsigned int giveFlags );
  412. void RemoveInventoryItem( idDict *item );
  413. bool GiveInventoryItem( const char *name );
  414. void RemoveInventoryItem( const char *name );
  415. idDict * FindInventoryItem( const char *name );
  416. idDict * FindInventoryItem( int index );
  417. int GetNumInventoryItems();
  418. void PlayAudioLog( const idSoundShader * sound );
  419. void EndAudioLog();
  420. void PlayVideoDisk( const idDeclVideo * decl );
  421. void EndVideoDisk();
  422. const idMaterial * GetVideoMaterial() { return pdaVideoMat; }
  423. void SetQuickSlot( int index, int val );
  424. int GetQuickSlot( int index );
  425. void GivePDA( const idDeclPDA * pda, const char * securityItem );
  426. void GiveVideo( const idDeclVideo * video, const char * itemName );
  427. void GiveEmail( const idDeclEmail * email );
  428. void GiveSecurity( const char * security );
  429. void GiveObjective( const char * title, const char * text, const idMaterial * screenshot );
  430. void CompleteObjective( const char * title );
  431. bool GivePowerUp( int powerup, int time, unsigned int giveFlags );
  432. void ClearPowerUps();
  433. bool PowerUpActive( int powerup ) const;
  434. float PowerUpModifier( int type );
  435. int SlotForWeapon( const char *weaponName );
  436. void Reload();
  437. void NextWeapon();
  438. void NextBestWeapon();
  439. void PrevWeapon();
  440. void SetPreviousWeapon( int num ) { previousWeapon = num; }
  441. void SelectWeapon( int num, bool force );
  442. void DropWeapon( bool died ) ;
  443. void StealWeapon( idPlayer *player );
  444. void AddProjectilesFired( int count );
  445. void AddProjectileHits( int count );
  446. void SetLastHitTime( int time );
  447. void LowerWeapon();
  448. void RaiseWeapon();
  449. void WeaponLoweringCallback();
  450. void WeaponRisingCallback();
  451. void RemoveWeapon( const char *weap );
  452. void RemoveAllButEssentialWeapons();
  453. bool CanShowWeaponViewmodel() const;
  454. void AddAIKill();
  455. void SetSoulCubeProjectile( idProjectile *projectile );
  456. void AdjustHeartRate( int target, float timeInSecs, float delay, bool force );
  457. void SetCurrentHeartRate();
  458. int GetBaseHeartRate();
  459. void UpdateAir();
  460. void UpdatePowerupHud();
  461. virtual bool HandleSingleGuiCommand( idEntity *entityGui, idLexer *src );
  462. bool GuiActive() { return focusGUIent != NULL; }
  463. bool HandleGuiEvents( const sysEvent_t * ev );
  464. void PerformImpulse( int impulse );
  465. void Spectate( bool spectate, bool force = false );
  466. void TogglePDA();
  467. void RouteGuiMouse( idUserInterface *gui );
  468. void UpdateHud();
  469. const idDeclPDA * GetPDA() const;
  470. bool GetPDAOpen() const { return objectiveSystemOpen; }
  471. const idDeclVideo * GetVideo( int index );
  472. void SetInfluenceFov( float fov );
  473. void SetInfluenceView( const char *mtr, const char *skinname, float radius, idEntity *ent );
  474. void SetInfluenceLevel( int level );
  475. int GetInfluenceLevel() { return influenceActive; };
  476. void SetPrivateCameraView( idCamera *camView );
  477. idCamera * GetPrivateCameraView() const { return privateCameraView; }
  478. void StartFxFov( float duration );
  479. void UpdateHudWeapon( bool flashWeapon = true );
  480. void UpdateChattingHud();
  481. void UpdateHudStats( idMenuHandler_HUD * hudManager );
  482. void Event_StopAudioLog();
  483. bool IsSoundChannelPlaying( const s_channelType channel = SND_CHANNEL_ANY );
  484. void ShowTip( const char *title, const char *tip, bool autoHide );
  485. void HideTip();
  486. bool IsTipVisible() { return tipUp; };
  487. void HideObjective();
  488. virtual void ClientThink( const int curTime, const float fraction, const bool predict );
  489. virtual void WriteToSnapshot( idBitMsg &msg ) const;
  490. virtual void ReadFromSnapshot( const idBitMsg &msg );
  491. void WritePlayerStateToSnapshot( idBitMsg &msg ) const;
  492. void ReadPlayerStateFromSnapshot( const idBitMsg &msg );
  493. virtual bool ServerReceiveEvent( int event, int time, const idBitMsg &msg );
  494. virtual bool GetPhysicsToVisualTransform( idVec3 &origin, idMat3 &axis );
  495. virtual bool GetPhysicsToSoundTransform( idVec3 &origin, idMat3 &axis );
  496. virtual bool ClientReceiveEvent( int event, int time, const idBitMsg &msg );
  497. bool IsRespawning();
  498. bool IsInTeleport();
  499. int GetSkinIndex() const { return skinIndex; }
  500. idEntity *GetInfluenceEntity() { return influenceEntity; };
  501. const idMaterial *GetInfluenceMaterial() { return influenceMaterial; };
  502. float GetInfluenceRadius() { return influenceRadius; };
  503. // server side work for in/out of spectate. takes care of spawning it into the world as well
  504. void ServerSpectate( bool spectate );
  505. // for very specific usage. != GetPhysics()
  506. idPhysics *GetPlayerPhysics();
  507. void TeleportDeath( int killer );
  508. void SetLeader( bool lead );
  509. bool IsLeader();
  510. void UpdateSkinSetup();
  511. bool OnLadder() const;
  512. virtual void UpdatePlayerIcons();
  513. virtual void DrawPlayerIcons();
  514. virtual void HidePlayerIcons();
  515. bool NeedsIcon();
  516. void StartHealthRecharge(int speed);
  517. void StopHealthRecharge();
  518. idStr GetCurrentWeapon();
  519. int GetCurrentWeaponSlot() { return currentWeapon; }
  520. int GetIdealWeapon() { return idealWeapon.Get(); }
  521. idHashTable<WeaponToggle_t> GetWeaponToggles() const { return weaponToggles; }
  522. bool CanGive( const char *statname, const char *value );
  523. void StopHelltime( bool quick = true );
  524. void PlayHelltimeStopSound();
  525. void DropFlag(); // drop CTF item
  526. void ReturnFlag();
  527. virtual void FreeModelDef();
  528. bool SelfSmooth();
  529. void SetSelfSmooth( bool b );
  530. const idAngles & GetViewBobAngles() { return viewBobAngles; }
  531. const idVec3 & GetViewBob() { return viewBob; }
  532. idAchievementManager & GetAchievementManager() { return achievementManager; }
  533. const idAchievementManager & GetAchievementManager() const { return achievementManager; }
  534. int GetPlayedTime() const { return playedTimeSecs; }
  535. void HandleUserCmds( const usercmd_t & newcmd );
  536. int GetClientFireCount() const { return clientFireCount; }
  537. void IncrementFireCount() { ++clientFireCount; }
  538. void ShowRespawnHudMessage();
  539. void HideRespawnHudMessage();
  540. bool IsLocallyControlled() const { return entityNumber == gameLocal.GetLocalClientNum(); }
  541. gameExpansionType_t GetExpansionType() const;
  542. void AddProjectileKills() { numProjectileKills++; }
  543. int GetProjectileKills() const { return numProjectileKills; }
  544. void ResetProjectileKills() { numProjectileKills = 0; }
  545. private:
  546. // Stats & achievements
  547. idAchievementManager achievementManager;
  548. int playedTimeSecs;
  549. int playedTimeResidual;
  550. jointHandle_t hipJoint;
  551. jointHandle_t chestJoint;
  552. jointHandle_t headJoint;
  553. idPhysics_Player physicsObj; // player physics
  554. idList<aasLocation_t, TAG_IDLIB_LIST_PLAYER> aasLocation; // for AI tracking the player
  555. int bobFoot;
  556. float bobFrac;
  557. float bobfracsin;
  558. int bobCycle; // for view bobbing and footstep generation
  559. float xyspeed;
  560. int stepUpTime;
  561. float stepUpDelta;
  562. float idealLegsYaw;
  563. float legsYaw;
  564. bool legsForward;
  565. float oldViewYaw;
  566. idAngles viewBobAngles;
  567. idVec3 viewBob;
  568. int landChange;
  569. int landTime;
  570. int currentWeapon;
  571. idPredictedValue< int > idealWeapon;
  572. int previousWeapon;
  573. int weaponSwitchTime;
  574. bool weaponEnabled;
  575. int skinIndex;
  576. const idDeclSkin * skin;
  577. const idDeclSkin * powerUpSkin;
  578. int numProjectilesFired; // number of projectiles fired
  579. int numProjectileHits; // number of hits on mobs
  580. int numProjectileKills; // number of kills with a projectile.
  581. bool airless;
  582. int airMsec; // set to pm_airMsec at start, drops in vacuum
  583. int lastAirDamage;
  584. bool gibDeath;
  585. bool gibsLaunched;
  586. idVec3 gibsDir;
  587. idInterpolate<float> zoomFov;
  588. idInterpolate<float> centerView;
  589. bool fxFov;
  590. float influenceFov;
  591. int influenceActive; // level of influence.. 1 == no gun or hud .. 2 == 1 + no movement
  592. idEntity * influenceEntity;
  593. const idMaterial * influenceMaterial;
  594. float influenceRadius;
  595. const idDeclSkin * influenceSkin;
  596. idCamera * privateCameraView;
  597. static const int NUM_LOGGED_VIEW_ANGLES = 64; // for weapon turning angle offsets
  598. idAngles loggedViewAngles[NUM_LOGGED_VIEW_ANGLES]; // [gameLocal.framenum&(LOGGED_VIEW_ANGLES-1)]
  599. static const int NUM_LOGGED_ACCELS = 16; // for weapon turning angle offsets
  600. loggedAccel_t loggedAccel[NUM_LOGGED_ACCELS]; // [currentLoggedAccel & (NUM_LOGGED_ACCELS-1)]
  601. int currentLoggedAccel;
  602. // if there is a focusGUIent, the attack button will be changed into mouse clicks
  603. idEntity * focusGUIent;
  604. idUserInterface * focusUI; // focusGUIent->renderEntity.gui, gui2, or gui3
  605. idAI * focusCharacter;
  606. int talkCursor; // show the state of the focusCharacter (0 == can't talk/dead, 1 == ready to talk, 2 == busy talking)
  607. int focusTime;
  608. idAFEntity_Vehicle * focusVehicle;
  609. idUserInterface * cursor;
  610. // full screen guis track mouse movements directly
  611. int oldMouseX;
  612. int oldMouseY;
  613. const idMaterial * pdaVideoMat;
  614. bool tipUp;
  615. bool objectiveUp;
  616. int lastDamageDef;
  617. idVec3 lastDamageDir;
  618. int lastDamageLocation;
  619. int smoothedFrame;
  620. bool smoothedOriginUpdated;
  621. idVec3 smoothedOrigin;
  622. idAngles smoothedAngles;
  623. idHashTable<WeaponToggle_t> weaponToggles;
  624. int hudPowerup;
  625. int lastHudPowerup;
  626. int hudPowerupDuration;
  627. // mp
  628. bool respawning; // set to true while in SpawnToPoint for telefrag checks
  629. bool leader; // for sudden death situations
  630. int lastSpectateChange;
  631. int lastTeleFX;
  632. bool weaponCatchup; // raise up the weapon silently ( state catchups )
  633. int MPAim; // player num in aim
  634. int lastMPAim;
  635. int lastMPAimTime; // last time the aim changed
  636. int MPAimFadeTime; // for GUI fade
  637. bool MPAimHighlight;
  638. bool isTelefragged; // proper obituaries
  639. int serverOverridePositionTime;
  640. int clientFireCount;
  641. idPlayerIcon playerIcon;
  642. bool selfSmooth;
  643. netBoolEvent_t respawn_netEvent;
  644. void LookAtKiller( idEntity *inflictor, idEntity *attacker );
  645. void StopFiring();
  646. void FireWeapon();
  647. void Weapon_Combat();
  648. void Weapon_NPC();
  649. void Weapon_GUI();
  650. void UpdateWeapon();
  651. void UpdateFlashlight();
  652. void FlashlightOn();
  653. void FlashlightOff();
  654. void UpdateSpectating();
  655. void SpectateFreeFly( bool force ); // ignore the timeout to force when followed spec is no longer valid
  656. void SpectateCycle();
  657. idAngles GunTurningOffset();
  658. idVec3 GunAcceleratingOffset();
  659. void UseObjects();
  660. void CrashLand( const idVec3 &oldOrigin, const idVec3 &oldVelocity );
  661. void BobCycle( const idVec3 &pushVelocity );
  662. void UpdateViewAngles();
  663. void EvaluateControls();
  664. void AdjustSpeed();
  665. void AdjustBodyAngles();
  666. void InitAASLocation();
  667. void SetAASLocation();
  668. void Move();
  669. void Move_Interpolated( float fraction );
  670. void RunPhysics_RemoteClientCorrection();
  671. void UpdatePowerUps();
  672. void UpdateDeathSkin( bool state_hitch );
  673. void ClearPowerup( int i );
  674. void SetSpectateOrigin();
  675. bool AllowClientAuthPhysics();
  676. virtual int GetPhysicsTimeStep() const;
  677. void ClearFocus();
  678. void UpdateFocus();
  679. void UpdateLocation();
  680. idUserInterface * ActiveGui();
  681. // mp
  682. void Respawn_Shared();
  683. bool WeaponAvailable( const char* name );
  684. void UseVehicle();
  685. void Event_GetButtons();
  686. void Event_GetMove();
  687. void Event_GetViewAngles();
  688. void Event_StopFxFov();
  689. void Event_EnableWeapon();
  690. void Event_DisableWeapon();
  691. void Event_GetCurrentWeapon();
  692. void Event_GetPreviousWeapon();
  693. void Event_SelectWeapon( const char *weaponName );
  694. void Event_GetWeaponEntity();
  695. void Event_OpenPDA();
  696. void Event_PDAAvailable();
  697. void Event_InPDA();
  698. void Event_ExitTeleporter();
  699. void Event_HideTip();
  700. void Event_LevelTrigger();
  701. void Event_Gibbed();
  702. void Event_ForceOrigin( idVec3 & origin, idAngles & angles );
  703. void Event_GiveInventoryItem( const char* name );
  704. void Event_RemoveInventoryItem( const char* name );
  705. void Event_GetIdealWeapon();
  706. void Event_WeaponAvailable( const char* name );
  707. void Event_SetPowerupTime( int powerup, int time );
  708. void Event_IsPowerupActive( int powerup );
  709. void Event_StartWarp();
  710. void Event_StopHelltime( int mode );
  711. void Event_ToggleBloom( int on );
  712. void Event_SetBloomParms( float speed, float intensity );
  713. };
  714. ID_INLINE bool idPlayer::IsRespawning() {
  715. return respawning;
  716. }
  717. ID_INLINE idPhysics* idPlayer::GetPlayerPhysics() {
  718. return &physicsObj;
  719. }
  720. ID_INLINE bool idPlayer::IsInTeleport() {
  721. return ( teleportEntity.GetEntity() != NULL );
  722. }
  723. ID_INLINE void idPlayer::SetLeader( bool lead ) {
  724. leader = lead;
  725. }
  726. ID_INLINE bool idPlayer::IsLeader() {
  727. return leader;
  728. }
  729. ID_INLINE bool idPlayer::SelfSmooth() {
  730. return selfSmooth;
  731. }
  732. ID_INLINE void idPlayer::SetSelfSmooth( bool b ) {
  733. selfSmooth = b;
  734. }
  735. extern idCVar g_infiniteAmmo;
  736. #endif /* !__GAME_PLAYER_H__ */