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_WEAPON_H__
30 #define __GAME_WEAPON_H__
33 ===============================================================================
37 ===============================================================================
41 extern const idEventDef EV_Weapon_State;
54 static const int AMMO_NUMTYPES = 16;
58 static const int LIGHTID_WORLD_MUZZLE_FLASH = 1;
59 static const int LIGHTID_VIEW_MUZZLE_FLASH = 100;
66 char particlename[128];
69 jointHandle_t joint; //The joint on which to attach the particle
70 bool smoke; //Is this a smoke particle
71 const idDeclParticle* particle; //Used for smoke particles
72 idFuncEmitter* emitter; //Used for non-smoke particles
85 class idWeapon : public idAnimatedEntity {
87 CLASS_PROTOTYPE( idWeapon );
94 void SetOwner( idPlayer *owner );
95 idPlayer* GetOwner( void );
96 virtual bool ShouldConstructScriptObjectAtSpawn( void ) const;
98 static void CacheWeapon( const char *weaponName );
101 void Save( idSaveGame *savefile ) const; // archives object for save game file
102 void Restore( idRestoreGame *savefile ); // unarchives object from save game file
104 // Weapon definition management
106 void GetWeaponDef( const char *objectname, int ammoinclip );
107 bool IsLinked( void );
108 bool IsWorldModelReady( void );
111 const char * Icon( void ) const;
112 void UpdateGUI( void );
114 virtual void SetModel( const char *modelname );
115 bool GetGlobalJointTransform( bool viewModel, const jointHandle_t jointHandle, idVec3 &offset, idMat3 &axis );
116 void SetPushVelocity( const idVec3 &pushVelocity );
117 bool UpdateSkin( void );
119 // State control/player interface
122 void PutAway( void );
124 void LowerWeapon( void );
125 void RaiseWeapon( void );
126 void HideWeapon( void );
127 void ShowWeapon( void );
128 void HideWorldModel( void );
129 void ShowWorldModel( void );
130 void OwnerDied( void );
131 void BeginAttack( void );
132 void EndAttack( void );
133 bool IsReady( void ) const;
134 bool IsReloading( void ) const;
135 bool IsHolstered( void ) const;
136 bool ShowCrosshair( void ) const;
137 idEntity * DropItem( const idVec3 &velocity, int activateDelay, int removeDelay, bool died );
138 bool CanDrop( void ) const;
139 void WeaponStolen( void );
142 weaponStatus_t GetStatus() { return status; };
146 // Script state management
147 virtual idThread * ConstructScriptObject( void );
148 virtual void DeconstructScriptObject( void );
149 void SetState( const char *statename, int blendFrames );
150 void UpdateScript( void );
151 void EnterCinematic( void );
152 void ExitCinematic( void );
153 void NetCatchup( void );
155 // Visual presentation
156 void PresentWeapon( bool showViewModel );
157 int GetZoomFov( void );
158 void GetWeaponAngleOffsets( int *average, float *scale, float *max );
159 void GetWeaponTimeOffsets( float *time, float *scale );
160 bool BloodSplat( float size );
163 static ammo_t GetAmmoNumForName( const char *ammoname );
164 static const char *GetAmmoNameForNum( ammo_t ammonum );
165 static const char *GetAmmoPickupNameForNum( ammo_t ammonum );
166 ammo_t GetAmmoType( void ) const;
167 int AmmoAvailable( void ) const;
168 int AmmoInClip( void ) const;
169 void ResetAmmoClip( void );
170 int ClipSize( void ) const;
171 int LowAmmo( void ) const;
172 int AmmoRequired( void ) const;
174 int AmmoCount() const;
175 int GetGrabberState() const;
178 virtual void WriteToSnapshot( idBitMsgDelta &msg ) const;
179 virtual void ReadFromSnapshot( const idBitMsgDelta &msg );
182 EVENT_RELOAD = idEntity::EVENT_MAXEVENTS,
187 virtual bool ClientReceiveEvent( int event, int time, const idBitMsg &msg );
189 virtual void ClientPredictionThink( void );
193 idScriptBool WEAPON_ATTACK;
194 idScriptBool WEAPON_RELOAD;
195 idScriptBool WEAPON_NETRELOAD;
196 idScriptBool WEAPON_NETENDRELOAD;
197 idScriptBool WEAPON_NETFIRING;
198 idScriptBool WEAPON_RAISEWEAPON;
199 idScriptBool WEAPON_LOWERWEAPON;
200 weaponStatus_t status;
208 // precreated projectile
209 idEntity *projectileEnt;
212 idEntityPtr<idAnimatedEntity> worldModel;
214 // hiding (for GUIs and NPCs)
227 // these are the player render view parms, which include bobbing
228 idVec3 playerViewOrigin;
229 idMat3 playerViewAxis;
231 // the view weapon render entity parms
232 idVec3 viewWeaponOrigin;
233 idMat3 viewWeaponAxis;
235 // the muzzle bone's position, used for launching projectiles and trailing smoke
242 // we maintain local copies of the projectile and brass dictionaries so they
243 // do not have to be copied across the DLL boundary when entities are spawned
244 const idDeclEntityDef * weaponDef;
245 const idDeclEntityDef * meleeDef;
246 idDict projectileDict;
253 // view weapon gui light
254 renderLight_t guiLight;
258 renderLight_t muzzleFlash; // positioned on view weapon bone
259 int muzzleFlashHandle;
261 renderLight_t worldMuzzleFlash; // positioned on world weapon bone
262 int worldMuzzleFlashHandle;
276 int muzzle_kick_time;
277 int muzzle_kick_maxtime;
278 idAngles muzzle_kick_angles;
279 idVec3 muzzle_kick_offset;
283 int ammoRequired; // amount of ammo to use each shot. 0 means weapon doesn't need ammo.
284 int clipSize; // 0 means no reload
286 int lowAmmo; // if ammo in clip hits this threshold, snd_
287 bool powerAmmo; // true if the clip reduction is a factor of the power setting when
288 // a projectile is launched
293 int zoomFov; // variable zoom fov per weapon
295 // joints from models
296 jointHandle_t barrelJointView;
297 jointHandle_t flashJointView;
298 jointHandle_t ejectJointView;
299 jointHandle_t guiLightJointView;
300 jointHandle_t ventLightJointView;
302 jointHandle_t flashJointWorld;
303 jointHandle_t barrelJointWorld;
304 jointHandle_t ejectJointWorld;
307 jointHandle_t smokeJointView;
309 idHashTable<WeaponParticle_t> weaponParticles;
310 idHashTable<WeaponLight_t> weaponLights;
314 const idSoundShader * sndHum;
316 // new style muzzle smokes
317 const idDeclParticle * weaponSmoke; // null if it doesn't smoke
318 int weaponSmokeStartTime; // set to gameLocal.time every weapon fire
319 bool continuousSmoke; // if smoke is continuous ( chainsaw )
320 const idDeclParticle * strikeSmoke; // striking something in melee
321 int strikeSmokeStartTime; // timing
322 idVec3 strikePos; // position of last melee strike
323 idMat3 strikeAxis; // axis of last melee strike
324 int nextStrikeFx; // used for sound and decal ( may use for strike smoke too )
327 bool nozzleFx; // does this use nozzle effects ( parm5 at rest, parm6 firing )
328 // this also assumes a nozzle light atm
329 int nozzleFxFade; // time it takes to fade between the effects
330 int lastAttack; // last time an attack occured
331 renderLight_t nozzleGlow; // nozzle light
332 int nozzleGlowHandle; // handle for nozzle light
334 idVec3 nozzleGlowColor; // color of the nozzle glow
335 const idMaterial * nozzleGlowShader; // shader for glow light
336 float nozzleGlowRadius; // radius of glow light
338 // weighting for viewmodel angles
339 int weaponAngleOffsetAverages;
340 float weaponAngleOffsetScale;
341 float weaponAngleOffsetMax;
342 float weaponOffsetTime;
343 float weaponOffsetScale;
346 void AlertMonsters( void );
348 // Visual presentation
349 void InitWorldModel( const idDeclEntityDef *def );
350 void MuzzleFlashLight( void );
351 void MuzzleRise( idVec3 &origin, idMat3 &axis );
352 void UpdateNozzleFx( void );
353 void UpdateFlashPosition( void );
356 void Event_Clear( void );
357 void Event_GetOwner( void );
358 void Event_WeaponState( const char *statename, int blendFrames );
359 void Event_SetWeaponStatus( float newStatus );
360 void Event_WeaponReady( void );
361 void Event_WeaponOutOfAmmo( void );
362 void Event_WeaponReloading( void );
363 void Event_WeaponHolstered( void );
364 void Event_WeaponRising( void );
365 void Event_WeaponLowering( void );
366 void Event_UseAmmo( int amount );
367 void Event_AddToClip( int amount );
368 void Event_AmmoInClip( void );
369 void Event_AmmoAvailable( void );
370 void Event_TotalAmmoCount( void );
371 void Event_ClipSize( void );
372 void Event_PlayAnim( int channel, const char *animname );
373 void Event_PlayCycle( int channel, const char *animname );
374 void Event_AnimDone( int channel, int blendFrames );
375 void Event_SetBlendFrames( int channel, int blendFrames );
376 void Event_GetBlendFrames( int channel );
377 void Event_Next( void );
378 void Event_SetSkin( const char *skinname );
379 void Event_Flashlight( int enable );
380 void Event_GetLightParm( int parmnum );
381 void Event_SetLightParm( int parmnum, float value );
382 void Event_SetLightParms( float parm0, float parm1, float parm2, float parm3 );
383 void Event_LaunchProjectiles( int num_projectiles, float spread, float fuseOffset, float launchPower, float dmgPower );
384 void Event_CreateProjectile( void );
385 void Event_EjectBrass( void );
386 void Event_Melee( void );
387 void Event_GetWorldModel( void );
388 void Event_AllowDrop( int allow );
389 void Event_AutoReload( void );
390 void Event_NetReload( void );
391 void Event_IsInvisible( void );
392 void Event_NetEndReload( void );
398 void Event_Grabber( int enable );
399 void Event_GrabberHasTarget( void );
400 void Event_GrabberSetGrabDistance( float dist );
401 void Event_LaunchProjectilesEllipse( int num_projectiles, float spreada, float spreadb, float fuseOffset, float power );
402 void Event_LaunchPowerup( const char* powerup, float duration, int useAmmo );
404 void Event_StartWeaponSmoke();
405 void Event_StopWeaponSmoke();
407 void Event_StartWeaponParticle( const char* name);
408 void Event_StopWeaponParticle( const char* name);
410 void Event_StartWeaponLight( const char* name);
411 void Event_StopWeaponLight( const char* name);
415 ID_INLINE bool idWeapon::IsLinked( void ) {
419 ID_INLINE bool idWeapon::IsWorldModelReady( void ) {
420 return ( worldModel.GetEntity() != NULL );
423 ID_INLINE idPlayer* idWeapon::GetOwner( void ) {
427 #endif /* !__GAME_WEAPON_H__ */