Weapon.h 14 KB

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