]> icculus.org git repositories - icculus/iodoom3.git/blob - neo/d3xp/Weapon.h
hello world
[icculus/iodoom3.git] / neo / d3xp / Weapon.h
1 /*
2 ===========================================================================
3
4 Doom 3 GPL Source Code
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company. 
6
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).  
8
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.
13
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.
18
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/>.
21
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.
23
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.
25
26 ===========================================================================
27 */
28
29 #ifndef __GAME_WEAPON_H__
30 #define __GAME_WEAPON_H__
31
32 /*
33 ===============================================================================
34
35         Player Weapon
36         
37 ===============================================================================
38 */
39
40 #ifdef _D3XP
41 extern const idEventDef EV_Weapon_State;
42 #endif
43
44 typedef enum {
45         WP_READY,
46         WP_OUTOFAMMO,
47         WP_RELOAD,
48         WP_HOLSTERED,
49         WP_RISING,
50         WP_LOWERING
51 } weaponStatus_t;
52
53 typedef int ammo_t;
54 static const int AMMO_NUMTYPES = 16;
55
56 class idPlayer;
57
58 static const int LIGHTID_WORLD_MUZZLE_FLASH = 1;
59 static const int LIGHTID_VIEW_MUZZLE_FLASH = 100;
60
61 class idMoveableItem;
62
63 #ifdef _D3XP
64 typedef struct {
65         char                    name[64];
66         char                    particlename[128];
67         bool                    active;
68         int                             startTime;
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
73 } WeaponParticle_t;
74
75 typedef struct {
76         char                    name[64];
77         bool                    active;
78         int                             startTime;
79         jointHandle_t   joint;
80         int                             lightHandle;
81         renderLight_t   light;
82 } WeaponLight_t;
83 #endif
84
85 class idWeapon : public idAnimatedEntity {
86 public:
87         CLASS_PROTOTYPE( idWeapon );
88
89                                                         idWeapon();
90         virtual                                 ~idWeapon();
91
92         // Init
93         void                                    Spawn( void );
94         void                                    SetOwner( idPlayer *owner );
95         idPlayer*                               GetOwner( void );
96         virtual bool                    ShouldConstructScriptObjectAtSpawn( void ) const;
97
98         static void                             CacheWeapon( const char *weaponName );
99
100         // save games
101         void                                    Save( idSaveGame *savefile ) const;                                     // archives object for save game file
102         void                                    Restore( idRestoreGame *savefile );                                     // unarchives object from save game file
103
104         // Weapon definition management
105         void                                    Clear( void );
106         void                                    GetWeaponDef( const char *objectname, int ammoinclip );
107         bool                                    IsLinked( void );
108         bool                                    IsWorldModelReady( void );
109
110         // GUIs
111         const char *                    Icon( void ) const;
112         void                                    UpdateGUI( void );
113
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 );
118
119         // State control/player interface
120         void                                    Think( void );
121         void                                    Raise( void );
122         void                                    PutAway( void );
123         void                                    Reload( 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 );
140
141 #ifdef _D3XP
142         weaponStatus_t                  GetStatus() { return status; };
143
144 #endif
145
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 );
154
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 );
161
162         // Ammo
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;
173 #ifdef _D3XP
174         int                                             AmmoCount() const;
175         int                                             GetGrabberState() const;
176 #endif
177
178         virtual void                    WriteToSnapshot( idBitMsgDelta &msg ) const;
179         virtual void                    ReadFromSnapshot( const idBitMsgDelta &msg );
180
181         enum {
182                 EVENT_RELOAD = idEntity::EVENT_MAXEVENTS,
183                 EVENT_ENDRELOAD,
184                 EVENT_CHANGESKIN,
185                 EVENT_MAXEVENTS
186         };
187         virtual bool                    ClientReceiveEvent( int event, int time, const idBitMsg &msg );
188
189         virtual void                    ClientPredictionThink( void );
190
191 private:
192         // script control
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;
201         idThread *                              thread;
202         idStr                                   state;
203         idStr                                   idealState;
204         int                                             animBlendFrames;
205         int                                             animDoneTime;
206         bool                                    isLinked;
207
208         // precreated projectile
209         idEntity                                *projectileEnt;
210
211         idPlayer *                              owner;
212         idEntityPtr<idAnimatedEntity>   worldModel;
213
214         // hiding (for GUIs and NPCs)
215         int                                             hideTime;
216         float                                   hideDistance;
217         int                                             hideStartTime;
218         float                                   hideStart;
219         float                                   hideEnd;
220         float                                   hideOffset;
221         bool                                    hide;
222         bool                                    disabled;
223
224         // berserk
225         int                                             berserk;
226
227         // these are the player render view parms, which include bobbing
228         idVec3                                  playerViewOrigin;
229         idMat3                                  playerViewAxis;
230
231         // the view weapon render entity parms
232         idVec3                                  viewWeaponOrigin;
233         idMat3                                  viewWeaponAxis;
234         
235         // the muzzle bone's position, used for launching projectiles and trailing smoke
236         idVec3                                  muzzleOrigin;
237         idMat3                                  muzzleAxis;
238
239         idVec3                                  pushVelocity;
240
241         // weapon definition
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;
247         float                                   meleeDistance;
248         idStr                                   meleeDefName;
249         idDict                                  brassDict;
250         int                                             brassDelay;
251         idStr                                   icon;
252
253         // view weapon gui light
254         renderLight_t                   guiLight;
255         int                                             guiLightHandle;
256
257         // muzzle flash
258         renderLight_t                   muzzleFlash;            // positioned on view weapon bone
259         int                                             muzzleFlashHandle;
260
261         renderLight_t                   worldMuzzleFlash;       // positioned on world weapon bone
262         int                                             worldMuzzleFlashHandle;
263
264         idVec3                                  flashColor;
265         int                                             muzzleFlashEnd;
266         int                                             flashTime;
267         bool                                    lightOn;
268         bool                                    silent_fire;
269         bool                                    allowDrop;
270
271         // effects
272         bool                                    hasBloodSplat;
273
274         // weapon kick
275         int                                             kick_endtime;
276         int                                             muzzle_kick_time;
277         int                                             muzzle_kick_maxtime;
278         idAngles                                muzzle_kick_angles;
279         idVec3                                  muzzle_kick_offset;
280
281         // ammo management
282         ammo_t                                  ammoType;
283         int                                             ammoRequired;           // amount of ammo to use each shot.  0 means weapon doesn't need ammo.
284         int                                             clipSize;                       // 0 means no reload
285         int                                             ammoClip;
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
289         // mp client
290         bool                                    isFiring;
291
292         // zoom
293     int                                         zoomFov;                        // variable zoom fov per weapon
294
295         // joints from models
296         jointHandle_t                   barrelJointView;
297         jointHandle_t                   flashJointView;
298         jointHandle_t                   ejectJointView;
299         jointHandle_t                   guiLightJointView;
300         jointHandle_t                   ventLightJointView;
301
302         jointHandle_t                   flashJointWorld;
303         jointHandle_t                   barrelJointWorld;
304         jointHandle_t                   ejectJointWorld;
305
306 #ifdef _D3XP
307         jointHandle_t                   smokeJointView;
308
309         idHashTable<WeaponParticle_t>   weaponParticles;
310         idHashTable<WeaponLight_t>              weaponLights;
311 #endif
312
313         // sound
314         const idSoundShader *   sndHum;
315
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 )
325
326         // nozzle effects
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
333
334         idVec3                                  nozzleGlowColor;        // color of the nozzle glow
335         const idMaterial *              nozzleGlowShader;       // shader for glow light
336         float                                   nozzleGlowRadius;       // radius of glow light
337
338         // weighting for viewmodel angles
339         int                                             weaponAngleOffsetAverages;
340         float                                   weaponAngleOffsetScale;
341         float                                   weaponAngleOffsetMax;
342         float                                   weaponOffsetTime;
343         float                                   weaponOffsetScale;
344
345         // flashlight
346         void                                    AlertMonsters( void );
347
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 );
354
355         // script events
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 );
393
394 #ifdef _D3XP
395         idGrabber                               grabber;
396         int                                             grabberState;
397
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 );
403
404         void                                    Event_StartWeaponSmoke();
405         void                                    Event_StopWeaponSmoke();
406
407         void                                    Event_StartWeaponParticle( const char* name);
408         void                                    Event_StopWeaponParticle( const char* name);
409
410         void                                    Event_StartWeaponLight( const char* name);
411         void                                    Event_StopWeaponLight( const char* name);
412 #endif
413 };
414
415 ID_INLINE bool idWeapon::IsLinked( void ) {
416         return isLinked;
417 }
418
419 ID_INLINE bool idWeapon::IsWorldModelReady( void ) {
420         return ( worldModel.GetEntity() != NULL );
421 }
422
423 ID_INLINE idPlayer* idWeapon::GetOwner( void ) {
424         return owner;
425 }
426
427 #endif /* !__GAME_WEAPON_H__ */