DOOM-3-BFG

DOOM 3 BFG Edition
Log | Files | Refs

Weapon.h (14161B)


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