Weapon.h 13 KB

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