]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/w_shotgun.qc
eject multiple shell casings from shotgun if ammo is more than 1
[divverent/nexuiz.git] / data / qcsrc / server / w_shotgun.qc
1
2 void W_Shotgun_Attack (void)
3 {
4         float   sc;
5         float   ammo;
6         float   bullets;
7         float   d;
8         float   f;
9         float   spread;
10         float   bulletspeed;
11         float   bulletconstant;
12         local entity flash;
13
14         ammo = cvar("g_balance_shotgun_primary_ammo");
15         bullets = cvar("g_balance_shotgun_primary_bullets");
16         d = cvar("g_balance_shotgun_primary_damage");
17         f = cvar("g_balance_shotgun_primary_force");
18         spread = cvar("g_balance_shotgun_primary_spread");
19         bulletspeed = cvar("g_balance_shotgun_primary_speed");
20         bulletconstant = cvar("g_balance_shotgun_primary_bulletconstant");
21
22         W_SetupShot (self, '28 8 -10', TRUE, 5, "weapons/shotgun_fire.wav");
23         for (sc = 0;sc < bullets;sc = sc + 1)
24                 fireBallisticBullet(w_shotorg, w_shotdir, spread, bulletspeed, 5, d, 0, f, WEP_SHOTGUN, 0, 1, bulletconstant);
25         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
26                 self.ammo_shells = self.ammo_shells - ammo;
27
28         pointparticles(particleeffectnum("shotgun_muzzleflash"), w_shotorg, w_shotdir * 1000, cvar("g_balance_shotgun_primary_ammo"));
29
30         // casing code
31         if (cvar("g_casings") >= 1)
32                 for (sc = 0;sc < ammo;sc = sc + 1)
33                         SpawnCasing (w_shotorg - v_forward * 10, ((random () * 50 + 50) * v_right) - (v_forward * (random () * 25 + 25)) - ((random () * 5 - 30) * v_up), 2, vectoangles(v_forward),'0 250 0', 100, 1);
34
35         // muzzle flash for 1st person view
36         flash = spawn();
37         setorigin(flash, '5 0 0');
38         setmodel(flash, "models/uziflash.md3"); // precision set below
39         if (gettagindex(self.weaponentity, "shot"))
40                 setattachment(flash, self.weaponentity, "shot");
41         else if (gettagindex(self.weaponentity, "bone02"))
42                 setattachment(flash, self.weaponentity, "bone02");
43         else
44         {
45                 setorigin(flash, '48 0 5');
46                 setattachment(flash, self.weaponentity, "");
47         }
48         flash.owner = self;
49         flash.viewmodelforclient = self;
50         flash.customizeentityforclient = CL_Weaponentity_CustomizeEntityForClient;
51         flash.think = SUB_Remove;
52         flash.nextthink = time + 0.06;
53         flash.angles_z = flash.v_angle_z + random() * 180;
54         flash.alpha = 1;
55         flash.effects = EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION;
56
57 }
58
59 void W_Shotgun_Attack2 (void)
60 {
61         float   sc;
62         float   bullets;
63         float   d;
64         float   f;
65         float   spread;
66         float   bulletspeed;
67         float   bulletconstant;
68         local entity flash;
69
70         bullets = cvar("g_balance_shotgun_secondary_bullets");
71         d = cvar("g_balance_shotgun_secondary_damage");
72         f = cvar("g_balance_shotgun_secondary_force");
73         spread = cvar("g_balance_shotgun_secondary_spread");
74         bulletspeed = cvar("g_balance_shotgun_secondary_speed");
75         bulletconstant = cvar("g_balance_shotgun_secondary_bulletconstant");
76
77         W_SetupShot (self, '25 8 -8', TRUE, 5, "weapons/shotgun_fire.wav");
78         for (sc = 0;sc < bullets;sc = sc + 1)
79                 fireBallisticBullet(w_shotorg, w_shotdir, spread, bulletspeed, 5, d, 0, f, WEP_SHOTGUN | HITTYPE_SECONDARY, 0, 1, bulletconstant);
80         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
81                 self.ammo_shells = self.ammo_shells - cvar("g_balance_shotgun_secondary_ammo");
82
83         pointparticles(particleeffectnum("shotgun_muzzleflash"), w_shotorg, w_shotdir * 1000, cvar("g_balance_shotgun_secondary_ammo"));
84
85         // casing code
86         if (cvar("g_casings") >= 1)
87                 SpawnCasing (w_shotorg - v_forward * 10, ((random () * 50 + 50) * v_right) - (v_forward * (random () * 25 + 25)) - ((random () * 5 - 30) * v_up), 2, vectoangles(v_forward),'0 250 0', 100, 1);
88
89         flash = spawn();
90         setorigin(flash, '53 5 0');
91         setmodel(flash, "models/uziflash.md3"); // precision set below
92         if (gettagindex(self.weaponentity, "shot"))
93                 setattachment(flash, self.weaponentity, "shot");
94         else if (gettagindex(self.weaponentity, "bone01"))
95                 setattachment(flash, self.weaponentity, "bone01");
96         else
97         {
98                 setorigin(flash, '48 0 5');
99                 setattachment(flash, self.weaponentity, "");
100         }
101         flash.owner = self;
102         flash.viewmodelforclient = self;
103         flash.customizeentityforclient = CL_Weaponentity_CustomizeEntityForClient;
104         flash.scale = 1.2;
105         flash.think = SUB_Remove;
106         flash.nextthink = time + 0.06;
107         flash.angles_z = flash.v_angle_z + random() * 180;
108         flash.alpha = 1;
109         flash.effects = EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION;
110 }
111
112 // weapon frames
113 void shotgun_fire2_03()
114 {
115         W_Shotgun_Attack2();
116         weapon_thinkf(WFRAME_FIRE2, cvar("g_balance_shotgun_secondary_animtime"), w_ready);
117 }
118 void shotgun_fire2_02()
119 {
120         W_Shotgun_Attack2();
121         weapon_thinkf(WFRAME_FIRE2, cvar("g_balance_shotgun_secondary_animtime"), shotgun_fire2_03);
122 }
123
124 void spawnfunc_weapon_shotgun(); // defined in t_items.qc
125
126 float w_shotgun(float req)
127 {
128         if (req == WR_AIM)
129                 if(vlen(self.origin-self.enemy.origin)>200)
130                         self.BUTTON_ATCK = bot_aim(1000000, 0, 0.001, FALSE);
131                 else
132                         self.BUTTON_ATCK2 = bot_aim(1000000, 0, 0.001, FALSE);
133         else if (req == WR_THINK)
134         {
135                 if (self.BUTTON_ATCK)
136                 if (weapon_prepareattack(0, cvar("g_balance_shotgun_primary_refire")))
137                 {
138                         W_Shotgun_Attack();
139                         weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_shotgun_primary_animtime"), w_ready);
140                 }
141                 if (self.BUTTON_ATCK2)
142                 if (weapon_prepareattack(1, cvar("g_balance_shotgun_secondary_refire")))
143                 {
144                         W_Shotgun_Attack2();
145                         weapon_thinkf(WFRAME_FIRE2, cvar("g_balance_shotgun_secondary_animtime"), shotgun_fire2_02);
146                 }
147         }
148         else if (req == WR_PRECACHE)
149         {
150                 precache_model ("models/uziflash.md3");
151                 precache_model ("models/weapons/g_shotgun.md3");
152                 precache_model ("models/weapons/v_shotgun.md3");
153                 precache_model ("models/weapons/w_shotgun.zym");
154                 precache_sound ("misc/itempickup.wav");
155                 precache_sound ("weapons/shotgun_fire.wav");
156         }
157         else if (req == WR_SETUP)
158                 weapon_setup(WEP_SHOTGUN);
159         else if (req == WR_CHECKAMMO1)
160                 return self.ammo_shells >= cvar("g_balance_shotgun_primary_ammo");
161         else if (req == WR_CHECKAMMO2)
162                 return self.ammo_shells >= cvar("g_balance_shotgun_secondary_ammo") * 3;
163         else if (req == WR_SUICIDEMESSAGE)
164                 w_deathtypestring = "did the impossible";
165         else if (req == WR_KILLMESSAGE)
166         {
167                 w_deathtypestring = "was gunned by"; // unchecked: SECONDARY
168         }
169         return TRUE;
170 };