2 ===========================================================================
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
22 In addition, the Doom 3 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 Source Code. If not, please request a copy in writing from id Software at the address below.
24 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.
26 ===========================================================================
29 #ifndef __GAME_PLAYER_H__
30 #define __GAME_PLAYER_H__
33 ===============================================================================
37 ===============================================================================
40 extern const idEventDef EV_Player_GetButtons;
41 extern const idEventDef EV_Player_GetMove;
42 extern const idEventDef EV_Player_GetViewAngles;
43 extern const idEventDef EV_Player_EnableWeapon;
44 extern const idEventDef EV_Player_DisableWeapon;
45 extern const idEventDef EV_Player_ExitTeleporter;
46 extern const idEventDef EV_Player_SelectWeapon;
47 extern const idEventDef EV_SpectatorTouch;
49 const float THIRD_PERSON_FOCUS_DISTANCE = 512.0f;
50 const int LAND_DEFLECT_TIME = 150;
51 const int LAND_RETURN_TIME = 300;
52 const int FOCUS_TIME = 300;
53 const int FOCUS_GUI_TIME = 500;
55 const int MAX_WEAPONS = 16;
57 const int DEAD_HEARTRATE = 0; // fall to as you die
58 const int LOWHEALTH_HEARTRATE_ADJ = 20; //
59 const int DYING_HEARTRATE = 30; // used for volumen calc when dying/dead
60 const int BASE_HEARTRATE = 70; // default
61 const int ZEROSTAMINA_HEARTRATE = 115; // no stamina
62 const int MAX_HEARTRATE = 130; // maximum
63 const int ZERO_VOLUME = -40; // volume at zero
64 const int DMG_VOLUME = 5; // volume when taking damage
65 const int DEATH_VOLUME = 15; // volume at death
67 const int SAVING_THROW_TIME = 5000; // maximum one "saving throw" every five seconds
69 const int ASYNC_PLAYER_INV_AMMO_BITS = idMath::BitsForInteger( 999 ); // 9 bits to cover the range [0, 999]
70 const int ASYNC_PLAYER_INV_CLIP_BITS = -7; // -7 bits to cover the range [-1, 60]
77 struct idObjectiveInfo {
83 struct idLevelTriggerInfo {
88 // powerups - the "type" in item .def must match
107 INFLUENCE_NONE = 0, // none
108 INFLUENCE_LEVEL1, // no gun or hud
109 INFLUENCE_LEVEL2, // no gun, hud, movement
110 INFLUENCE_LEVEL3, // slow player movement
120 int ammo[ AMMO_NUMTYPES ];
121 int clip[ MAX_WEAPONS ];
122 int powerupEndTime[ MAX_POWERUPS ];
130 int nextArmorDepleteTime;
132 int pdasViewed[4]; // 128 bit flags for indicating if a pda has been viewed
140 idList<idDict *> items;
142 idStrList pdaSecurity;
151 idList<idLevelTriggerInfo> levelTriggers;
153 idInventory() { Clear(); }
154 ~idInventory() { Clear(); }
157 void Save( idSaveGame *savefile ) const; // archives object for save game file
158 void Restore( idRestoreGame *savefile ); // unarchives object from save game file
161 void GivePowerUp( idPlayer *player, int powerup, int msec );
162 void ClearPowerUps( void );
163 void GetPersistantData( idDict &dict );
164 void RestoreInventory( idPlayer *owner, const idDict &dict );
165 bool Give( idPlayer *owner, const idDict &spawnArgs, const char *statname, const char *value, int *idealWeapon, bool updateHud );
166 void Drop( const idDict &spawnArgs, const char *weapon_classname, int weapon_index );
167 ammo_t AmmoIndexForAmmoClass( const char *ammo_classname ) const;
168 int MaxAmmoForAmmoClass( idPlayer *owner, const char *ammo_classname ) const;
169 int WeaponIndexForAmmoClass( const idDict & spawnArgs, const char *ammo_classname ) const;
170 ammo_t AmmoIndexForWeaponClass( const char *weapon_classname, int *ammoRequired );
171 const char * AmmoPickupNameForIndex( ammo_t ammonum ) const;
172 void AddPickupName( const char *name, const char *icon );
174 int HasAmmo( ammo_t type, int amount );
175 bool UseAmmo( ammo_t type, int amount );
176 int HasAmmo( const char *weapon_classname ); // looks up the ammo information for the weapon class first
178 void UpdateArmor( void );
183 idList<idItemInfo> pickupItemNames;
184 idList<idObjectiveInfo> objectiveNames;
189 idVec3 dir; // scaled larger for running
197 class idPlayer : public idActor {
200 EVENT_IMPULSE = idEntity::EVENT_MAXEVENTS,
201 EVENT_EXIT_TELEPORTER,
202 EVENT_ABORT_TELEPORTER,
210 class idPlayerView playerView; // handles damage kicks and effects
215 bool spawnAnglesSet; // on first usercmd, we must set deltaAngles
216 idAngles spawnAngles;
217 idAngles viewAngles; // player view angles
218 idAngles cmdAngles; // player cmd angles
224 int lastHitTime; // last time projectile fired by player hit target
225 int lastSndHitTime; // MP hit sound - != lastHitTime because we throttle
226 int lastSavingThrowTime; // for the "free miss" effect
228 idScriptBool AI_FORWARD;
229 idScriptBool AI_BACKWARD;
230 idScriptBool AI_STRAFE_LEFT;
231 idScriptBool AI_STRAFE_RIGHT;
232 idScriptBool AI_ATTACK_HELD;
233 idScriptBool AI_WEAPON_FIRED;
234 idScriptBool AI_JUMP;
235 idScriptBool AI_CROUCH;
236 idScriptBool AI_ONGROUND;
237 idScriptBool AI_ONLADDER;
238 idScriptBool AI_DEAD;
240 idScriptBool AI_PAIN;
241 idScriptBool AI_HARDLANDING;
242 idScriptBool AI_SOFTLANDING;
243 idScriptBool AI_RELOAD;
244 idScriptBool AI_TELEPORT;
245 idScriptBool AI_TURN_LEFT;
246 idScriptBool AI_TURN_RIGHT;
249 idInventory inventory;
251 idEntityPtr<idWeapon> weapon;
252 idUserInterface * hud; // MP: is NULL if not local player
253 idUserInterface * objectiveSystem;
254 bool objectiveSystemOpen;
261 idInterpolate<float> heartInfo;
265 int deathClearContentsTime;
267 int lastArmorPulse; // lastDmgTime if we had armor at time of hit
269 float healthPool; // amount of health to give over time
276 bool hiddenWeapon; // if the weapon is hidden ( in noWeapons maps )
277 idEntityPtr<idProjectile> soulCubeProjectile;
280 static idVec3 colorBarTable[ 5 ];
282 idVec3 colorBar; // used for scoreboard and hud display
285 bool forceScoreBoard;
288 int lastSpectateTeleport;
291 bool wantSpectate; // from userInfo
292 bool weaponGone; // force stop firing
293 bool useInitialSpawns; // toggled by a map restart to be active for the first game spawn
294 int latchedTeam; // need to track when team gets changed
295 int tourneyRank; // for tourney cycling - the higher, the more likely to play next - server
296 int tourneyLine; // client side - our spot in the wait line. 0 means no info.
297 int spawnedTime; // when client first enters the game
299 idEntityPtr<idEntity> teleportEntity; // while being teleported, this is set to the entity we'll use for exit
300 int teleportKiller; // entity number of an entity killing us at teleporter exit
301 bool lastManOver; // can't respawn in last man anymore (srv only)
302 bool lastManPlayAgain; // play again when end game delay is cancelled out before expiring (srv only)
303 bool lastManPresent; // true when player was in when game started (spectators can't join a running LMS)
304 bool isLagged; // replicated from server, true if packets haven't been received from client.
305 bool isChatting; // replicated from server, true if the player is chatting.
308 int minRespawnTime; // can respawn when time > this, force after g_forcerespawn
309 int maxRespawnTime; // force respawn after this time
311 // the first person view values are always calculated, even
312 // if a third person view is used
313 idVec3 firstPersonViewOrigin;
314 idMat3 firstPersonViewAxis;
316 idDragEntity dragEntity;
319 CLASS_PROTOTYPE( idPlayer );
328 void Save( idSaveGame *savefile ) const; // archives object for save game file
329 void Restore( idRestoreGame *savefile ); // unarchives object from save game file
331 virtual void Hide( void );
332 virtual void Show( void );
335 void PrepareForRestart( void );
336 virtual void Restart( void );
337 void LinkScriptVariables( void );
338 void SetupWeaponEntity( void );
339 void SelectInitialSpawnPoint( idVec3 &origin, idAngles &angles );
340 void SpawnFromSpawnSpot( void );
341 void SpawnToPoint( const idVec3 &spawn_origin, const idAngles &spawn_angles );
342 void SetClipModel( void ); // spectator mode uses a different bbox size
344 void SavePersistantInfo( void );
345 void RestorePersistantInfo( void );
346 void SetLevelTrigger( const char *levelName, const char *triggerName );
348 bool UserInfoChanged( bool canModify );
349 idDict * GetUserInfo( void );
350 bool BalanceTDM( void );
352 void CacheWeapons( void );
354 void EnterCinematic( void );
355 void ExitCinematic( void );
356 bool HandleESC( void );
357 bool SkipCinematic( void );
359 void UpdateConditions( void );
360 void SetViewAngles( const idAngles &angles );
362 // delta view angles to allow movers to rotate the view of the player
363 void UpdateDeltaViewAngles( const idAngles &angles );
365 virtual bool Collide( const trace_t &collision, const idVec3 &velocity );
367 virtual void GetAASLocation( idAAS *aas, idVec3 &pos, int &areaNum ) const;
368 virtual void GetAIAimTargets( const idVec3 &lastSightPos, idVec3 &headPos, idVec3 &chestPos );
369 virtual void DamageFeedback( idEntity *victim, idEntity *inflictor, int &damage );
370 void CalcDamagePoints( idEntity *inflictor, idEntity *attacker, const idDict *damageDef,
371 const float damageScale, const int location, int *health, int *armor );
372 virtual void Damage( idEntity *inflictor, idEntity *attacker, const idVec3 &dir, const char *damageDefName, const float damageScale, const int location );
374 // use exitEntityNum to specify a teleport with private camera view and delayed exit
375 virtual void Teleport( const idVec3 &origin, const idAngles &angles, idEntity *destination );
377 void Kill( bool delayRespawn, bool nodamage );
378 virtual void Killed( idEntity *inflictor, idEntity *attacker, int damage, const idVec3 &dir, int location );
379 void StartFxOnBone(const char *fx, const char *bone);
381 renderView_t * GetRenderView( void );
382 void CalculateRenderView( void ); // called every tic by player code
383 void CalculateFirstPersonView( void );
385 void DrawHUD( idUserInterface *hud );
387 void WeaponFireFeedback( const idDict *weaponDef );
389 float DefaultFov( void ) const;
390 float CalcFov( bool honorZoom );
391 void CalculateViewWeaponPos( idVec3 &origin, idMat3 &axis );
392 idVec3 GetEyePosition( void ) const;
393 void GetViewPos( idVec3 &origin, idMat3 &axis ) const;
394 void OffsetThirdPersonView( float angle, float range, float height, bool clip );
396 bool Give( const char *statname, const char *value );
397 bool GiveItem( idItem *item );
398 void GiveItem( const char *name );
399 void GiveHealthPool( float amt );
401 bool GiveInventoryItem( idDict *item );
402 void RemoveInventoryItem( idDict *item );
403 bool GiveInventoryItem( const char *name );
404 void RemoveInventoryItem( const char *name );
405 idDict * FindInventoryItem( const char *name );
407 void GivePDA( const char *pdaName, idDict *item );
408 void GiveVideo( const char *videoName, idDict *item );
409 void GiveEmail( const char *emailName );
410 void GiveSecurity( const char *security );
411 void GiveObjective( const char *title, const char *text, const char *screenshot );
412 void CompleteObjective( const char *title );
414 bool GivePowerUp( int powerup, int time );
415 void ClearPowerUps( void );
416 bool PowerUpActive( int powerup ) const;
417 float PowerUpModifier( int type );
419 int SlotForWeapon( const char *weaponName );
421 void NextWeapon( void );
422 void NextBestWeapon( void );
423 void PrevWeapon( void );
424 void SelectWeapon( int num, bool force );
425 void DropWeapon( bool died ) ;
426 void StealWeapon( idPlayer *player );
427 void AddProjectilesFired( int count );
428 void AddProjectileHits( int count );
429 void SetLastHitTime( int time );
430 void LowerWeapon( void );
431 void RaiseWeapon( void );
432 void WeaponLoweringCallback( void );
433 void WeaponRisingCallback( void );
434 void RemoveWeapon( const char *weap );
435 bool CanShowWeaponViewmodel( void ) const;
437 void AddAIKill( void );
438 void SetSoulCubeProjectile( idProjectile *projectile );
440 void AdjustHeartRate( int target, float timeInSecs, float delay, bool force );
441 void SetCurrentHeartRate( void );
442 int GetBaseHeartRate( void );
443 void UpdateAir( void );
445 virtual bool HandleSingleGuiCommand( idEntity *entityGui, idLexer *src );
446 bool GuiActive( void ) { return focusGUIent != NULL; }
448 void PerformImpulse( int impulse );
449 void Spectate( bool spectate );
450 void TogglePDA( void );
451 void ToggleScoreboard( void );
452 void RouteGuiMouse( idUserInterface *gui );
453 void UpdateHud( void );
454 const idDeclPDA * GetPDA( void ) const;
455 const idDeclVideo * GetVideo( int index );
456 void SetInfluenceFov( float fov );
457 void SetInfluenceView( const char *mtr, const char *skinname, float radius, idEntity *ent );
458 void SetInfluenceLevel( int level );
459 int GetInfluenceLevel( void ) { return influenceActive; };
460 void SetPrivateCameraView( idCamera *camView );
461 idCamera * GetPrivateCameraView( void ) const { return privateCameraView; }
462 void StartFxFov( float duration );
463 void UpdateHudWeapon( bool flashWeapon = true );
464 void UpdateHudStats( idUserInterface *hud );
465 void UpdateHudAmmo( idUserInterface *hud );
466 void Event_StopAudioLog( void );
467 void StartAudioLog( void );
468 void StopAudioLog( void );
469 void ShowTip( const char *title, const char *tip, bool autoHide );
470 void HideTip( void );
471 bool IsTipVisible( void ) { return tipUp; };
472 void ShowObjective( const char *obj );
473 void HideObjective( void );
475 virtual void ClientPredictionThink( void );
476 virtual void WriteToSnapshot( idBitMsgDelta &msg ) const;
477 virtual void ReadFromSnapshot( const idBitMsgDelta &msg );
478 void WritePlayerStateToSnapshot( idBitMsgDelta &msg ) const;
479 void ReadPlayerStateFromSnapshot( const idBitMsgDelta &msg );
481 virtual bool ServerReceiveEvent( int event, int time, const idBitMsg &msg );
483 virtual bool GetPhysicsToVisualTransform( idVec3 &origin, idMat3 &axis );
484 virtual bool GetPhysicsToSoundTransform( idVec3 &origin, idMat3 &axis );
486 virtual bool ClientReceiveEvent( int event, int time, const idBitMsg &msg );
487 bool IsReady( void );
488 bool IsRespawning( void );
489 bool IsInTeleport( void );
491 idEntity *GetInfluenceEntity( void ) { return influenceEntity; };
492 const idMaterial *GetInfluenceMaterial( void ) { return influenceMaterial; };
493 float GetInfluenceRadius( void ) { return influenceRadius; };
495 // server side work for in/out of spectate. takes care of spawning it into the world as well
496 void ServerSpectate( bool spectate );
497 // for very specific usage. != GetPhysics()
498 idPhysics *GetPlayerPhysics( void );
499 void TeleportDeath( int killer );
500 void SetLeader( bool lead );
501 bool IsLeader( void );
503 void UpdateSkinSetup( bool restart );
505 bool OnLadder( void ) const;
507 virtual void UpdatePlayerIcons( void );
508 virtual void DrawPlayerIcons( void );
509 virtual void HidePlayerIcons( void );
510 bool NeedsIcon( void );
512 bool SelfSmooth( void );
513 void SetSelfSmooth( bool b );
516 jointHandle_t hipJoint;
517 jointHandle_t chestJoint;
518 jointHandle_t headJoint;
520 idPhysics_Player physicsObj; // player physics
522 idList<aasLocation_t> aasLocation; // for AI tracking the player
527 int bobCycle; // for view bobbing and footstep generation
535 idAngles viewBobAngles;
543 int weaponSwitchTime;
545 bool showWeaponViewModel;
547 const idDeclSkin * skin;
548 const idDeclSkin * powerUpSkin;
551 int numProjectilesFired; // number of projectiles fired
552 int numProjectileHits; // number of hits on mobs
555 int airTics; // set to pm_airTics at start, drops in vacuum
562 idInterpolate<float> zoomFov;
563 idInterpolate<float> centerView;
567 int influenceActive; // level of influence.. 1 == no gun or hud .. 2 == 1 + no movement
568 idEntity * influenceEntity;
569 const idMaterial * influenceMaterial;
570 float influenceRadius;
571 const idDeclSkin * influenceSkin;
573 idCamera * privateCameraView;
575 static const int NUM_LOGGED_VIEW_ANGLES = 64; // for weapon turning angle offsets
576 idAngles loggedViewAngles[NUM_LOGGED_VIEW_ANGLES]; // [gameLocal.framenum&(LOGGED_VIEW_ANGLES-1)]
577 static const int NUM_LOGGED_ACCELS = 16; // for weapon turning angle offsets
578 loggedAccel_t loggedAccel[NUM_LOGGED_ACCELS]; // [currentLoggedAccel & (NUM_LOGGED_ACCELS-1)]
579 int currentLoggedAccel;
581 // if there is a focusGUIent, the attack button will be changed into mouse clicks
582 idEntity * focusGUIent;
583 idUserInterface * focusUI; // focusGUIent->renderEntity.gui, gui2, or gui3
584 idAI * focusCharacter;
585 int talkCursor; // show the state of the focusCharacter (0 == can't talk/dead, 1 == ready to talk, 2 == busy talking)
587 idAFEntity_Vehicle * focusVehicle;
588 idUserInterface * cursor;
590 // full screen guis track mouse movements directly
602 idVec3 lastDamageDir;
603 int lastDamageLocation;
605 bool smoothedOriginUpdated;
606 idVec3 smoothedOrigin;
607 idAngles smoothedAngles;
610 bool ready; // from userInfo
611 bool respawning; // set to true while in SpawnToPoint for telefrag checks
612 bool leader; // for sudden death situations
613 int lastSpectateChange;
615 unsigned int lastSnapshotSequence; // track state hitches on clients
616 bool weaponCatchup; // raise up the weapon silently ( state catchups )
617 int MPAim; // player num in aim
619 int lastMPAimTime; // last time the aim changed
620 int MPAimFadeTime; // for GUI fade
622 bool isTelefragged; // proper obituaries
624 idPlayerIcon playerIcon;
628 void LookAtKiller( idEntity *inflictor, idEntity *attacker );
630 void StopFiring( void );
631 void FireWeapon( void );
632 void Weapon_Combat( void );
633 void Weapon_NPC( void );
634 void Weapon_GUI( void );
635 void UpdateWeapon( void );
636 void UpdateSpectating( void );
637 void SpectateFreeFly( bool force ); // ignore the timeout to force when followed spec is no longer valid
638 void SpectateCycle( void );
639 idAngles GunTurningOffset( void );
640 idVec3 GunAcceleratingOffset( void );
642 void UseObjects( void );
643 void CrashLand( const idVec3 &oldOrigin, const idVec3 &oldVelocity );
644 void BobCycle( const idVec3 &pushVelocity );
645 void UpdateViewAngles( void );
646 void EvaluateControls( void );
647 void AdjustSpeed( void );
648 void AdjustBodyAngles( void );
649 void InitAASLocation( void );
650 void SetAASLocation( void );
652 void UpdatePowerUps( void );
653 void UpdateDeathSkin( bool state_hitch );
654 void ClearPowerup( int i );
655 void SetSpectateOrigin( void );
657 void ClearFocus( void );
658 void UpdateFocus( void );
659 void UpdateLocation( void );
660 idUserInterface * ActiveGui( void );
661 void UpdatePDAInfo( bool updatePDASel );
662 int AddGuiPDAData( const declType_t dataType, const char *listName, const idDeclPDA *src, idUserInterface *gui );
663 void ExtractEmailInfo( const idStr &email, const char *scan, idStr &out );
664 void UpdateObjectiveInfo( void );
666 void UseVehicle( void );
668 void Event_GetButtons( void );
669 void Event_GetMove( void );
670 void Event_GetViewAngles( void );
671 void Event_StopFxFov( void );
672 void Event_EnableWeapon( void );
673 void Event_DisableWeapon( void );
674 void Event_GetCurrentWeapon( void );
675 void Event_GetPreviousWeapon( void );
676 void Event_SelectWeapon( const char *weaponName );
677 void Event_GetWeaponEntity( void );
678 void Event_OpenPDA( void );
679 void Event_PDAAvailable( void );
680 void Event_InPDA( void );
681 void Event_ExitTeleporter( void );
682 void Event_HideTip( void );
683 void Event_LevelTrigger( void );
684 void Event_Gibbed( void );
685 void Event_GetIdealWeapon( void );
688 ID_INLINE bool idPlayer::IsReady( void ) {
689 return ready || forcedReady;
692 ID_INLINE bool idPlayer::IsRespawning( void ) {
696 ID_INLINE idPhysics* idPlayer::GetPlayerPhysics( void ) {
700 ID_INLINE bool idPlayer::IsInTeleport( void ) {
701 return ( teleportEntity.GetEntity() != NULL );
704 ID_INLINE void idPlayer::SetLeader( bool lead ) {
708 ID_INLINE bool idPlayer::IsLeader( void ) {
712 ID_INLINE bool idPlayer::SelfSmooth( void ) {
716 ID_INLINE void idPlayer::SetSelfSmooth( bool b ) {
720 #endif /* !__GAME_PLAYER_H__ */