📄 weapon.cpp
字号:
//-----------------------------------------------------------------------------
//
// $Logfile:: /Quake 2 Engine/Sin/code/game/weapon.cpp $
// $Revision:: 143 $
// $Author:: Jimdose $
// $Date:: 12/16/98 5:43p $
//
// Copyright (C) 1997 by Ritual Entertainment, Inc.
// All rights reserved.
//
// This source is may not be distributed and/or modified without
// expressly written permission by Ritual Entertainment, Inc.
//
// $Log:: /Quake 2 Engine/Sin/code/game/weapon.cpp $
//
// 143 12/16/98 5:43p Jimdose
// infiniterockets no longer gives infinite mines
//
// 142 12/14/98 7:00p Jimdose
// added sv_infinitesniper
//
// 141 12/09/98 8:06p Jimdose
// added infinite ammo vars
//
// 140 11/19/98 9:29p Jimdose
// fixed dropping weapons when on different gravaxis
//
// 139 11/18/98 12:21a Jimdose
// Fixed gravaxis stuff.
//
// 138 11/15/98 11:19p Jimdose
// Fixed bug where reloading only worked if you had less ammo in your clip than
// in your inventory
//
// 137 11/13/98 1:47a Markd
// Put in FL_ROTATEDBOUNDS modification when picked up and then dropped
//
// 136 11/07/98 10:46p Markd
// don't reload weapons while in cinematic
//
// 135 10/22/98 7:57p Markd
// put in proper pre-caching in all the classes
//
// 134 10/22/98 12:19a Jimdose
// Added aimanim and aimframe
// Added SetAimAnim
//
// 133 10/21/98 5:29p Aldie
// Moved around mutant checks for picking up weapons
//
// 132 10/21/98 1:30a Jimdose
// DoneReloading now sends a weapon ready event to sentient
//
// 131 10/20/98 8:23p Jimdose
// no longer pickup weapons when you already have that weapon and enough ammo
// no longer switch to weapon when picking up if you already have it
//
// 130 10/19/98 12:07a Jimdose
// made all code use fast checks for inheritance (no text lookups when
// possible)
// isSubclassOf no longer requires ::_classinfo()
// moved Magnum-specific Drop code to magnum.cpp
//
// 129 10/18/98 6:42p Markd
// Added notdroppable event to weapons
//
// 128 10/16/98 9:50p Aldie
// Added SecondaryAmmo command
//
// 127 10/16/98 12:59a Aldie
// Fixed ammo types
//
// 126 10/14/98 1:46a Markd
// Moved RandomGlobalSound to null out weaponidle before detach
//
// 125 10/14/98 1:20a Jimdose
// Got cross-level persistant info working
//
// 124 10/11/98 7:41p Aldie
// Mutate and restore commands for Richard
//
// 123 10/10/98 5:58p Aldie
// More quantumdestab fixes
//
// 122 10/09/98 2:07a Aldie
// Updated DMFLAGS
//
// 121 10/08/98 5:47p Aldie
// Be able to pickup up dropped weapons in DF_WEAPONSSTAY mode
//
// 120 10/08/98 12:36a Jimdose
// Added ForceIdle
//
// 119 10/06/98 5:24p Markd
// put in bullet-proofing of owner variable
//
// 118 10/05/98 10:43p Aldie
// Converted over to new silencer methods
//
// 117 10/04/98 10:25p Markd
// Took out annoying warning, made the trace for gun position to muzzle
// position more bullet proof
//
// 116 10/03/98 7:14p Markd
// fixed muzzle position stuff
//
// 115 10/01/98 8:00p Aldie
// Don't pickup a weapon when mutant
//
// 114 9/19/98 4:47p Markd
// fixed music stuff and added actionincrement to weapons
//
// 113 9/12/98 11:10p Aldie
// Don't detach in putaway
//
// 112 9/12/98 5:16p Jimdose
// Added call to DetachGun in PutAway
//
// 111 9/09/98 6:24p Markd
// Added IsDroppable method
//
// 110 9/07/98 7:49p Markd
// went back to previous attaching of weapons
//
// 109 9/07/98 6:21p Markd
// don't attach if no worldmodel
//
// 108 9/05/98 12:13p Aldie
// Fixed a bug that 2015 found.
//
// 107 9/02/98 11:08a Markd
// Put in setModel into Sentient so that weapon could be properly detached and
// re-attached again.
//
// 106 8/31/98 7:45p Aldie
// Updated surface data structure and removed surfinfo field
//
// 105 8/31/98 4:19p Markd
// Made GetMuzzlePosition behave a bit more rationally.
//
// 104 8/29/98 9:47p Jimdose
// Added call info to G_Trace
//
// 103 8/29/98 5:27p Markd
// added specialfx, replaced misc with specialfx where appropriate
//
// 102 8/19/98 4:56p Jimdose
// Added check for "gun" bone to MuzzleOffset
//
// 101 8/18/98 8:12p Aldie
// Added dual mode weapons to base class
//
// 100 8/18/98 7:39p Aldie
// Added dual weapon modes to base class
//
// 99 8/14/98 5:48p Aldie
// Removed bloodsplat completely from weapon
//
// 98 8/13/98 7:29p Aldie
// Fixed magnum dropping when it gets shot out of your hand.
//
// 97 8/10/98 6:53p Aldie
// Added a better scaling for bloodsplats.
//
// 96 8/06/98 10:53p Aldie
// Added weapon tweaks and kickback. Also modified blast radius damage and
// rocket jumping.
//
// 95 8/06/98 6:54p Jimdose
// Added min/max range, and projkectile speed
//
// 94 7/26/98 2:13p Aldie
// Don't put bulletholes on hidden objects
//
// 93 7/26/98 9:22a Jimdose
// Bulletholes are now bound to entities
//
// 92 7/25/98 6:35p Aldie
// Bulletholes only in single player
//
// 91 7/24/98 3:50p Aldie
// Fix for deathmatch flag weapons staying around
//
// 90 7/22/98 9:58p Markd
// Added Raising, PuttingAway and Reloading functions
//
// 89 7/22/98 8:18p Aldie
// Made sure reloading only happens when weapon is ready.
//
// 88 7/22/98 7:03p Aldie
// Fixed reloading while reloading :-)
//
// 87 7/22/98 5:16p Aldie
// Fixed NextAttack time
//
// 86 7/20/98 6:43p Markd
// Put in new muzzle offset stuff
//
// 85 7/20/98 3:54p Aldie
// Made weapons post the init commands in the future.
//
// 84 7/19/98 5:41p Markd
// Added DetachFromOwner method
//
// 83 7/17/98 4:04p Markd
// Added HasAnim support to putaway and ready
//
// 82 7/17/98 11:32a Aldie
// Added clipammo and forcereload stuff
//
// 81 7/15/98 9:59p Markd
// Made muzzle flashes into TEMP_DLIGHT's
//
// 80 7/14/98 6:58p Aldie
// Made dropped weapons fade out
//
// 79 7/14/98 5:52p Aldie
// Don't drop magnums in deathmatch. Made the delay to pick up dropped weapons
// a little longer for the owner.
//
// 78 7/14/98 3:54p Markd
// made weapons cycle through their models when spawning
//
// 77 7/12/98 7:27p Jimdose
// Removed code setting scale and frame
//
// 76 7/11/98 8:20p Jimdose
// Drop now returns true or false depending upon whether the item can be
// dropped or not
//
// 75 7/10/98 5:39p Aldie
// Fixed printf of a warning
//
// 74 7/10/98 12:06a Aldie
// Autochange override when you pickup a new weapon. Currently only the
// sniperrifle will not be putaway if you are using it.
//
// 73 7/09/98 10:41p Aldie
// If no barrel in weapon, look for barrel bone in owner
//
// 72 7/01/98 7:04p Aldie
// Fixed assert with weapon reloading after death
//
// 71 6/26/98 12:24p Markd
// Changed SetAmmoAmount fixed picking upweapons
//
// 70 6/26/98 11:30a Markd
// Fixed weapon pickup bug
//
// 69 6/25/98 8:47p Markd
// Added keyed items for Triggers, Rewrote Item class, rewrote every pickup
// method
//
// 68 6/25/98 12:43p Aldie
// Changed bloodsplat scale and made a triggerdelay for dropping weapons
//
// 67 6/24/98 1:38p Aldie
// Implementation of inventory system and picking stuff up
//
// 66 6/19/98 9:28p Jimdose
// Added general weapon muzzle code
//
// 65 6/17/98 1:20a Jimdose
// Moved setOwner to Item.
// Added EV_Item_Pickup
//
// 64 6/16/98 4:08p Jimdose
// Gave dropping weapons velocity
//
// 63 6/15/98 10:39a Aldie
// Created MuzzleOffset derived from MuzzlePosition
//
// 62 6/11/98 12:40a Markd
// Added BasePosition and MuzzlePosition
//
// 61 6/10/98 9:49p Markd
// Made Finish attack set attack_finished to level.time not 0
//
// 60 6/10/98 7:45p Aldie
// Updated some reload functions.
//
// 59 6/10/98 3:46p Markd
// replaced instance of AmmoAvailable with HasAmmor to make monsters work right
//
// 58 6/10/98 2:10p Aldie
// Updated damage function.
//
// 57 6/10/98 1:18p Markd
// Added SetAmmoClipSize event removed NextAttack(0) from AttackDone
//
// 56 6/09/98 7:37p Markd
// Put in "0" ammo_clip_size support
//
// 55 6/09/98 3:58p Markd
// Fixed bug with double pickup of ammos from dropped guns
//
// 54 6/09/98 12:54p Aldie
// Updated ReadyToFire function
//
// 53 6/08/98 8:39p Markd
// Fixed some reload issues
//
// 52 6/08/98 8:19p Markd
// Added reloading support and ReadyToUse function
//
// 51 6/08/98 5:43p Markd
// removed "shoot" command from Fire function
//
// 50 6/05/98 6:21p Markd
// When picking up weapons, ammo is given if you already have that weapon
//
// 49 6/05/98 6:26p Aldie
// Added location to apply multi damage
//
// 48 6/04/98 7:36p Jimdose
// Drop now posts EV_Item_DropToFloor instead of processing it.
//
// 47 6/03/98 4:39p Markd
// Removed dummy weapon, there is now just a single weapon that gets sent over
//
// 46 5/27/98 5:03a Aldie
// Added queue for bulletsplats
//
// 45 5/27/98 3:20a Markd
// zeroed out animations for dropped weapons
//
// 44 5/27/98 2:33a Markd
// When dropping weapons, made sure to zero out the anim and frame for the
// weapon
//
// 43 5/25/98 8:51a Aldie
// Fixed sprayblood with masked textures
//
// 42 5/25/98 6:52a Aldie
// Added maxbulletholes to stop from overflowing.
//
// 41 5/24/98 8:46p Jimdose
// Made a lot of functions more str-friendly.
// Got rid of a lot of char * based strings
// Cleaned up get spawn arg functions and sound functions
// sound functions now use consistant syntax
//
// 40 5/24/98 1:05a Jimdose
// Changed worldmodel, viewmodel, and ammotype to str objects
// Added sound events for ai
//
// 39 5/23/98 10:20p Aldie
// Made some changes to bulletholes to try to get them to work with ents, but
// no luck.
//
// 38 5/23/98 4:48p Aldie
// Added bulletholes
//
// 37 5/14/98 4:27p Markd
// Fixed NULL weapon model issue
//
// 36 5/13/98 4:55p Jimdose
// now uses SafePtrs
// got rid of weapon_owner. replaced with owner which is a SafePtr.
//
// 35 5/11/98 11:25a Markd
// Changed some worldmodel stuff
//
// 34 5/03/98 4:34p Jimdose
// Changed Vector class
//
// 33 4/14/98 9:58p Jimdose
// Made SetModels set the dummy model if it exists
//
// 32 4/10/98 12:36a Jimdose
// Fire now cancels EV_Weapon_DoneFiring
//
// 31 4/09/98 3:30p Jimdose
// Added gettype and settype
// added sound so that anim sounds play from the owner
//
// 30 4/08/98 4:55p Jimdose
// Made ShowDummyOnClient and HideDummyOnClient check if dummy is NULL
// Fixed the bug with weapons not being shown on monsters. The dummy's origin
// was non 0,0,0
//
// 29 4/08/98 4:46p Jimdose
// Added ShowDummyOnClient and HideDummyOnClient
//
// 28 4/07/98 8:19p Jimdose
// Made assaultrifle fire at normal speed
//
// 27 4/07/98 8:00p Markd
// removed defhandle, changed all SINMDL calls to modelindex calls, removed
// SINMDL prefix
//
// 26 4/07/98 6:45p Jimdose
// Rewrote weapon code.
// Fixed weapon switching bugs
// fixed crash from freeing weapons at level changes
// Added order to rank
//
// 25 4/06/98 7:10p Aldie
// Added zooming for SniperRifle
//
// 24 4/05/98 11:17p Jimdose
// No longer see the gun lerping around
//
// 23 4/05/98 5:29p Jimdose
// Weapon attaching is back in (previous bug was probably related to not
// freeing the ents after a map change...go figure).
//
// 22 4/04/98 7:28p Jimdose
// Can't spray blood against sky anymore
//
// 21 4/04/98 6:11p Jimdose
// Made response from EV_Trigger_ActivateTargets to EV_Trigger_Effect
// Added attachable guns (currently disabled)
//
// 20 4/02/98 4:53p Jimdose
// Added AmmoAvailable
// Made SprayBlood work
// Added check for valid owner in AnimateFlash
//
// 19 3/31/98 1:05a Jimdose
// Made monsters always have ammo
//
// 18 3/30/98 2:35p Jimdose
// Added Ammo
// Added world models
//
// 17 3/27/98 11:03p Jimdose
// Added muzzle flash
//
// 16 3/26/98 8:17p Jimdose
// Temporarily disabled spray blood function
//
// 15 3/23/98 1:31p Jimdose
// Revamped event and command system
//
// 14 3/18/98 7:24p Jimdose
// Added code for handling readying and putting away weapons
// Made work with new animation system
//
// 13 3/02/98 8:49p Jimdose
// Changed the classid parameter of CLASS_DECLARATION to a quoted string so
// that you could have a NULL classid.
//
// 12 3/02/98 5:36p Jimdose
// Fixed setOwner so that it handles NULL being passed in when entites are
// freed or when the weapon is dropped.
//
// 11 2/19/98 2:35p Jimdose
// Updated to work with Q2 based progs
//
// 9 12/15/97 12:04p Aldie
// Fixed error message from coming up when checking for reload animations when
// there was none (I.e. Melee weapons).
//
// 8 12/14/97 7:49p Jimdose
// Fixed bug where if a weapon didn't have a "reload" animation, every other
// time the player tried to fire would fail.
//
// 7 12/12/97 2:10p Markd
// Changed NextAttacks in CheckReload and Fire to 1 second instead of 5
//
// 6 12/11/97 3:31p Markd
// Added SprayBlood function
//
// 5 12/09/97 7:46p Markd
// Added range variable. Added different behavior when firing...if there is no
// model, then go ahead and shoot right away
//
// 4 11/18/97 5:28p Markd
// Put in CheckTwitch, CheckIdle, put in clip support and other goodies
//
// 3 10/27/97 3:30p Jimdose
// Removed dependency on quakedef.h
//
// 2 9/26/97 4:46p Jimdose
// Added standard Ritual header
//
// DESCRIPTION:
// Source file for Weapon class. The weapon class is the base class for
// all weapons in Sin. Any entity created from a class derived from the weapon
// class will be usable by any Sentient (players and monsters) as a weapon.
//
#include "g_local.h"
#include "entity.h"
#include "item.h"
#include "weapon.h"
#include "scriptmaster.h"
#include "sentient.h"
#include "misc.h"
#include "specialfx.h"
#ifdef SIN_ARCADE
static ScriptVariablePtr sv_infinitebullets;
static ScriptVariablePtr sv_infiniterockets;
static ScriptVariablePtr sv_infiniteplasma;
static ScriptVariablePtr sv_infinitespears;
static ScriptVariablePtr sv_infinitesniper;
#endif
CLASS_DECLARATION( Item, Weapon, NULL );
Event EV_Weapon_Shoot( "shoot" );
Event EV_Weapon_FinishAttack( "attack_finished" );
Event EV_Weapon_DoneLowering( "putaway" );
Event EV_Weapon_DoneRaising( "ready" );
Event EV_Weapon_DoneFiring( "donefiring" );
Event EV_Weapon_Idle( "idle" );
Event EV_Weapon_MuzzleFlash( "muzzleflash" );
Event EV_Weapon_SecondaryUse( "secondaryuse" );
Event EV_Weapon_DoneReloading( "donereloading" );
Event EV_Weapon_SetAmmoClipSize( "ammoclipsize" );
Event EV_Weapon_ProcessModelCommands( "process_mdl_cmds" );
Event EV_Weapon_SetMaxRange( "maxrange" );
Event EV_Weapon_SetMinRange( "minrange" );
Event EV_Weapon_SetProjectileSpeed( "projectilespeed" );
Event EV_Weapon_SetKick( "kick" );
Event EV_Weapon_PrimaryMode( "primarymode" );
Event EV_Weapon_SecondaryMode( "secondarymode" );
Event EV_Weapon_ActionIncrement( "actionincrement" );
Event EV_Weapon_PutAwayAndRaise( "putawaythenraise" );
Event EV_Weapon_Raise( "raise" );
Event EV_Weapon_NotDroppable( "notdroppable" );
Event EV_Weapon_SetAimAnim( "setaimanim" );
ResponseDef Weapon::Responses[] =
{
{ &EV_Item_Pickup, ( Response )Weapon::PickupWeapon },
{ &EV_Weapon_FinishAttack, ( Response )Weapon::FinishAttack },
{ &EV_Weapon_DoneLowering, ( Response )Weapon::DoneLowering },
{ &EV_Weapon_DoneRaising, ( Response )Weapon::DoneRaising },
{ &EV_Weapon_DoneFiring, ( Response )Weapon::DoneFiring },
{ &EV_Weapon_Idle, ( Response )Weapon::Idle },
{ &EV_Weapon_MuzzleFlash, ( Response )Weapon::EventMuzzleFlash },
{ &EV_WeaponSound, ( Response )Weapon::WeaponSound },
{ &EV_Weapon_DoneReloading, ( Response )Weapon::DoneReloading },
{ &EV_Weapon_SetAmmoClipSize, ( Response )Weapon::SetAmmoClipSize },
{ &EV_Weapon_ProcessModelCommands, ( Response )Weapon::ProcessWeaponCommandsEvent },
{ &EV_Weapon_SetMaxRange, ( Response )Weapon::SetMaxRangeEvent },
{ &EV_Weapon_SetMinRange, ( Response )Weapon::SetMinRangeEvent },
{ &EV_Weapon_SetProjectileSpeed, ( Response )Weapon::SetProjectileSpeedEvent },
{ &EV_Weapon_SetKick, ( Response )Weapon::SetKick },
{ &EV_Weapon_SecondaryUse, ( Response )Weapon::SecondaryUse },
{ &EV_Weapon_PrimaryMode, ( Response )Weapon::PrimaryMode },
{ &EV_Weapon_SecondaryMode, ( Response )Weapon::SecondaryMode },
{ &EV_Weapon_ActionIncrement, ( Response )Weapon::SetActionLevelIncrement },
{ &EV_Weapon_PutAwayAndRaise, ( Response )Weapon::PutAwayAndRaise },
{ &EV_Weapon_Raise, ( Response )Weapon::Raise },
{ &EV_Weapon_NotDroppable, ( Response )Weapon::NotDroppableEvent },
{ &EV_Weapon_SetAimAnim, ( Response )Weapon::SetAimAnim },
{ NULL, NULL }
};
static int numBulletHoles = 0;
static Queue queueBulletHoles;
void ResetBulletHoles(void)
{
numBulletHoles = 0;
queueBulletHoles.Clear();
}
Weapon::Weapon()
{
attack_finished = 0;
owner = NULL;
ammorequired = 0;
secondary_ammorequired = 0;
startammo = 0;
rank = 0;
ammo_clip_size = 0;
ammo_in_clip = G_GetIntArg( "ammo_in_clip", 0 );
kick = 0;
last_attack_time = level.time-10;
nextweaponsoundtime = 0;
weaponstate = WEAPON_HOLSTERED;
weaponmode = ( weaponmode_t )G_GetIntArg( "weaponmode", PRIMARY );
dualmode = false;
silenced = G_GetIntArg( "silenced", false );
notdroppable = false;
aimanim = -1;
aimframe = 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -