Weapon.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. /*
  2. ===========================================================================
  3. Doom 3 GPL Source Code
  4. Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
  6. Doom 3 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 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 Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. 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.
  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_WEAPON_H__
  21. #define __GAME_WEAPON_H__
  22. /*
  23. ===============================================================================
  24. Player Weapon
  25. ===============================================================================
  26. */
  27. typedef enum {
  28. WP_READY,
  29. WP_OUTOFAMMO,
  30. WP_RELOAD,
  31. WP_HOLSTERED,
  32. WP_RISING,
  33. WP_LOWERING
  34. } weaponStatus_t;
  35. typedef int ammo_t;
  36. static const int AMMO_NUMTYPES = 16;
  37. class idPlayer;
  38. static const int LIGHTID_WORLD_MUZZLE_FLASH = 1;
  39. static const int LIGHTID_VIEW_MUZZLE_FLASH = 100;
  40. class idMoveableItem;
  41. class idWeapon : public idAnimatedEntity {
  42. public:
  43. CLASS_PROTOTYPE( idWeapon );
  44. idWeapon();
  45. virtual ~idWeapon();
  46. // Init
  47. void Spawn( void );
  48. void SetOwner( idPlayer *owner );
  49. idPlayer* GetOwner( void );
  50. virtual bool ShouldConstructScriptObjectAtSpawn( void ) const;
  51. static void CacheWeapon( const char *weaponName );
  52. // save games
  53. void Save( idSaveGame *savefile ) const; // archives object for save game file
  54. void Restore( idRestoreGame *savefile ); // unarchives object from save game file
  55. // Weapon definition management
  56. void Clear( void );
  57. void GetWeaponDef( const char *objectname, int ammoinclip );
  58. bool IsLinked( void );
  59. bool IsWorldModelReady( void );
  60. // GUIs
  61. const char * Icon( void ) const;
  62. void UpdateGUI( void );
  63. virtual void SetModel( const char *modelname );
  64. bool GetGlobalJointTransform( bool viewModel, const jointHandle_t jointHandle, idVec3 &offset, idMat3 &axis );
  65. void SetPushVelocity( const idVec3 &pushVelocity );
  66. bool UpdateSkin( void );
  67. // State control/player interface
  68. void Think( void );
  69. void Raise( void );
  70. void PutAway( void );
  71. void Reload( void );
  72. void LowerWeapon( void );
  73. void RaiseWeapon( void );
  74. void HideWeapon( void );
  75. void ShowWeapon( void );
  76. void HideWorldModel( void );
  77. void ShowWorldModel( void );
  78. void OwnerDied( void );
  79. void BeginAttack( void );
  80. void EndAttack( void );
  81. bool IsReady( void ) const;
  82. bool IsReloading( void ) const;
  83. bool IsHolstered( void ) const;
  84. bool ShowCrosshair( void ) const;
  85. idEntity * DropItem( const idVec3 &velocity, int activateDelay, int removeDelay, bool died );
  86. bool CanDrop( void ) const;
  87. void WeaponStolen( void );
  88. // Script state management
  89. virtual idThread * ConstructScriptObject( void );
  90. virtual void DeconstructScriptObject( void );
  91. void SetState( const char *statename, int blendFrames );
  92. void UpdateScript( void );
  93. void EnterCinematic( void );
  94. void ExitCinematic( void );
  95. void NetCatchup( void );
  96. // Visual presentation
  97. void PresentWeapon( bool showViewModel );
  98. int GetZoomFov( void );
  99. void GetWeaponAngleOffsets( int *average, float *scale, float *max );
  100. void GetWeaponTimeOffsets( float *time, float *scale );
  101. bool BloodSplat( float size );
  102. // Ammo
  103. static ammo_t GetAmmoNumForName( const char *ammoname );
  104. static const char *GetAmmoNameForNum( ammo_t ammonum );
  105. static const char *GetAmmoPickupNameForNum( ammo_t ammonum );
  106. ammo_t GetAmmoType( void ) const;
  107. int AmmoAvailable( void ) const;
  108. int AmmoInClip( void ) const;
  109. void ResetAmmoClip( void );
  110. int ClipSize( void ) const;
  111. int LowAmmo( void ) const;
  112. int AmmoRequired( void ) const;
  113. virtual void WriteToSnapshot( idBitMsgDelta &msg ) const;
  114. virtual void ReadFromSnapshot( const idBitMsgDelta &msg );
  115. enum {
  116. EVENT_RELOAD = idEntity::EVENT_MAXEVENTS,
  117. EVENT_ENDRELOAD,
  118. EVENT_CHANGESKIN,
  119. EVENT_MAXEVENTS
  120. };
  121. virtual bool ClientReceiveEvent( int event, int time, const idBitMsg &msg );
  122. virtual void ClientPredictionThink( void );
  123. private:
  124. // script control
  125. idScriptBool WEAPON_ATTACK;
  126. idScriptBool WEAPON_RELOAD;
  127. idScriptBool WEAPON_NETRELOAD;
  128. idScriptBool WEAPON_NETENDRELOAD;
  129. idScriptBool WEAPON_NETFIRING;
  130. idScriptBool WEAPON_RAISEWEAPON;
  131. idScriptBool WEAPON_LOWERWEAPON;
  132. weaponStatus_t status;
  133. idThread * thread;
  134. idStr state;
  135. idStr idealState;
  136. int animBlendFrames;
  137. int animDoneTime;
  138. bool isLinked;
  139. // precreated projectile
  140. idEntity *projectileEnt;
  141. idPlayer * owner;
  142. idEntityPtr<idAnimatedEntity> worldModel;
  143. // hiding (for GUIs and NPCs)
  144. int hideTime;
  145. float hideDistance;
  146. int hideStartTime;
  147. float hideStart;
  148. float hideEnd;
  149. float hideOffset;
  150. bool hide;
  151. bool disabled;
  152. // berserk
  153. int berserk;
  154. // these are the player render view parms, which include bobbing
  155. idVec3 playerViewOrigin;
  156. idMat3 playerViewAxis;
  157. // the view weapon render entity parms
  158. idVec3 viewWeaponOrigin;
  159. idMat3 viewWeaponAxis;
  160. // the muzzle bone's position, used for launching projectiles and trailing smoke
  161. idVec3 muzzleOrigin;
  162. idMat3 muzzleAxis;
  163. idVec3 pushVelocity;
  164. // weapon definition
  165. // we maintain local copies of the projectile and brass dictionaries so they
  166. // do not have to be copied across the DLL boundary when entities are spawned
  167. const idDeclEntityDef * weaponDef;
  168. const idDeclEntityDef * meleeDef;
  169. idDict projectileDict;
  170. float meleeDistance;
  171. idStr meleeDefName;
  172. idDict brassDict;
  173. int brassDelay;
  174. idStr icon;
  175. // view weapon gui light
  176. renderLight_t guiLight;
  177. int guiLightHandle;
  178. // muzzle flash
  179. renderLight_t muzzleFlash; // positioned on view weapon bone
  180. int muzzleFlashHandle;
  181. renderLight_t worldMuzzleFlash; // positioned on world weapon bone
  182. int worldMuzzleFlashHandle;
  183. idVec3 flashColor;
  184. int muzzleFlashEnd;
  185. int flashTime;
  186. bool lightOn;
  187. bool silent_fire;
  188. bool allowDrop;
  189. // effects
  190. bool hasBloodSplat;
  191. // weapon kick
  192. int kick_endtime;
  193. int muzzle_kick_time;
  194. int muzzle_kick_maxtime;
  195. idAngles muzzle_kick_angles;
  196. idVec3 muzzle_kick_offset;
  197. // ammo management
  198. ammo_t ammoType;
  199. int ammoRequired; // amount of ammo to use each shot. 0 means weapon doesn't need ammo.
  200. int clipSize; // 0 means no reload
  201. int ammoClip;
  202. int lowAmmo; // if ammo in clip hits this threshold, snd_
  203. bool powerAmmo; // true if the clip reduction is a factor of the power setting when
  204. // a projectile is launched
  205. // mp client
  206. bool isFiring;
  207. // zoom
  208. int zoomFov; // variable zoom fov per weapon
  209. // joints from models
  210. jointHandle_t barrelJointView;
  211. jointHandle_t flashJointView;
  212. jointHandle_t ejectJointView;
  213. jointHandle_t guiLightJointView;
  214. jointHandle_t ventLightJointView;
  215. jointHandle_t flashJointWorld;
  216. jointHandle_t barrelJointWorld;
  217. jointHandle_t ejectJointWorld;
  218. // sound
  219. const idSoundShader * sndHum;
  220. // new style muzzle smokes
  221. const idDeclParticle * weaponSmoke; // null if it doesn't smoke
  222. int weaponSmokeStartTime; // set to gameLocal.time every weapon fire
  223. bool continuousSmoke; // if smoke is continuous ( chainsaw )
  224. const idDeclParticle * strikeSmoke; // striking something in melee
  225. int strikeSmokeStartTime; // timing
  226. idVec3 strikePos; // position of last melee strike
  227. idMat3 strikeAxis; // axis of last melee strike
  228. int nextStrikeFx; // used for sound and decal ( may use for strike smoke too )
  229. // nozzle effects
  230. bool nozzleFx; // does this use nozzle effects ( parm5 at rest, parm6 firing )
  231. // this also assumes a nozzle light atm
  232. int nozzleFxFade; // time it takes to fade between the effects
  233. int lastAttack; // last time an attack occured
  234. renderLight_t nozzleGlow; // nozzle light
  235. int nozzleGlowHandle; // handle for nozzle light
  236. idVec3 nozzleGlowColor; // color of the nozzle glow
  237. const idMaterial * nozzleGlowShader; // shader for glow light
  238. float nozzleGlowRadius; // radius of glow light
  239. // weighting for viewmodel angles
  240. int weaponAngleOffsetAverages;
  241. float weaponAngleOffsetScale;
  242. float weaponAngleOffsetMax;
  243. float weaponOffsetTime;
  244. float weaponOffsetScale;
  245. // flashlight
  246. void AlertMonsters( void );
  247. // Visual presentation
  248. void InitWorldModel( const idDeclEntityDef *def );
  249. void MuzzleFlashLight( void );
  250. void MuzzleRise( idVec3 &origin, idMat3 &axis );
  251. void UpdateNozzleFx( void );
  252. void UpdateFlashPosition( void );
  253. // script events
  254. void Event_Clear( void );
  255. void Event_GetOwner( void );
  256. void Event_WeaponState( const char *statename, int blendFrames );
  257. void Event_SetWeaponStatus( float newStatus );
  258. void Event_WeaponReady( void );
  259. void Event_WeaponOutOfAmmo( void );
  260. void Event_WeaponReloading( void );
  261. void Event_WeaponHolstered( void );
  262. void Event_WeaponRising( void );
  263. void Event_WeaponLowering( void );
  264. void Event_UseAmmo( int amount );
  265. void Event_AddToClip( int amount );
  266. void Event_AmmoInClip( void );
  267. void Event_AmmoAvailable( void );
  268. void Event_TotalAmmoCount( void );
  269. void Event_ClipSize( void );
  270. void Event_PlayAnim( int channel, const char *animname );
  271. void Event_PlayCycle( int channel, const char *animname );
  272. void Event_AnimDone( int channel, int blendFrames );
  273. void Event_SetBlendFrames( int channel, int blendFrames );
  274. void Event_GetBlendFrames( int channel );
  275. void Event_Next( void );
  276. void Event_SetSkin( const char *skinname );
  277. void Event_Flashlight( int enable );
  278. void Event_GetLightParm( int parmnum );
  279. void Event_SetLightParm( int parmnum, float value );
  280. void Event_SetLightParms( float parm0, float parm1, float parm2, float parm3 );
  281. void Event_LaunchProjectiles( int num_projectiles, float spread, float fuseOffset, float launchPower, float dmgPower );
  282. void Event_CreateProjectile( void );
  283. void Event_EjectBrass( void );
  284. void Event_Melee( void );
  285. void Event_GetWorldModel( void );
  286. void Event_AllowDrop( int allow );
  287. void Event_AutoReload( void );
  288. void Event_NetReload( void );
  289. void Event_IsInvisible( void );
  290. void Event_NetEndReload( void );
  291. };
  292. ID_INLINE bool idWeapon::IsLinked( void ) {
  293. return isLinked;
  294. }
  295. ID_INLINE bool idWeapon::IsWorldModelReady( void ) {
  296. return ( worldModel.GetEntity() != NULL );
  297. }
  298. ID_INLINE idPlayer* idWeapon::GetOwner( void ) {
  299. return owner;
  300. }
  301. #endif /* !__GAME_WEAPON_H__ */