An added check to make sure we can only fire when we have enough ammo (an issue due...
[voretournament/voretournament.git] / data / qcsrc / server / w_grabber.qc
1 #ifdef REGISTER_WEAPON\r
2 REGISTER_WEAPON(GRABBER, w_grabber, IT_FUEL, 0, WEP_FLAG_CANCLIMB | WEP_TYPE_HITSCAN | WEP_FLAG_RELOADABLE, 0, "grabber", "grabber", "Grabber");\r
3 #else\r
4 .float dmg;\r
5 .float dmg_edge;\r
6 .float dmg_radius;\r
7 .float dmg_force;\r
8 .float grabber_refire;\r
9 .float grabber_time_grabbered;\r
10 .float grabber_time_fueldecrease;\r
11 \r
12 void W_Grabber_UpdateStats(entity e, float shot, float hit)\r
13 {\r
14         // this may not be entierly right, but for the time being we're handling grabber accuracy here\r
15         // this is likely needed for detecting if the hook has hit (linked to) another player, which is counted as a hit\r
16         if(shot)\r
17         {\r
18                 e.stats_fired[e.weapon - 1] += 1;\r
19                 e.stat_fired = e.weapon + 64 * floor(e.stats_fired[e.weapon - 1]);\r
20         }\r
21         if(hit)\r
22         {\r
23                 e.stats_hit[e.weapon - 1] += 1;\r
24                 e.stat_hit = e.weapon + 64 * floor(e.stats_hit[e.weapon - 1]);\r
25         }\r
26 }\r
27 \r
28 void W_Grabber_Touch2 (void)\r
29 {\r
30         PROJECTILE_TOUCH;\r
31         self.use();\r
32 }\r
33 \r
34 void W_Grabber_Attack2()\r
35 {\r
36         if(time < self.weapon_delay)\r
37                 return;\r
38 \r
39         W_SetupShot (self, TRUE, 0, "weapons/grabber_altfire.wav", cvar("g_balance_grabber_secondary_damage"));\r
40         W_Grabber_UpdateStats(self, TRUE, FALSE); // the hit is recorded below\r
41 \r
42         WarpZone_traceline_antilag(self, w_shotorg, w_shotorg + w_shotdir * cvar("g_balance_grabber_secondary_radius"), FALSE, self, ANTILAG_LATENCY(self));\r
43 \r
44         pointparticles(particleeffectnum("grabber_melee"), w_shotorg + w_shotdir * cvar("g_balance_grabber_secondary_radius"), '0 0 0', 1);\r
45 \r
46         if (trace_fraction < 1)\r
47         {\r
48                 Damage(trace_ent, self, self, cvar("g_balance_grabber_secondary_damage"), WEP_GRABBER | HITTYPE_SECONDARY, trace_endpos, cvar("g_balance_grabber_secondary_force") * w_shotdir);\r
49                 W_Grabber_UpdateStats(self, FALSE, TRUE); // the shot is recorded above\r
50         }\r
51 \r
52         if (!g_norecoil)\r
53                 self.punchangle_x -= cvar("g_balance_grabber_secondary_recoil");\r
54 \r
55         W_DecreaseAmmo(ammo_fuel, cvar("g_balance_grabber_secondary_ammo"), cvar("g_balance_grabber_reload_ammo"));\r
56 }\r
57 \r
58 void spawnfunc_weapon_grabber (void)\r
59 {\r
60         weapon_defaultspawnfunc(WEP_GRABBER);\r
61 }\r
62 \r
63 float w_grabber(float req)\r
64 {\r
65         if(self.predator.classname == "player") // we can't use weapons while in the stomach\r
66         {\r
67                 self.grabber_state |= GRABBER_REMOVING;\r
68                 return FALSE;\r
69         }\r
70 \r
71         float ammo_amount;\r
72         float grabbered_time_max, grabbered_fuel;\r
73                 \r
74         if (req == WR_AIM)\r
75         {\r
76                 // ... sorry ...\r
77         }\r
78         else if (req == WR_THINK)\r
79         {\r
80                 grabbered_fuel = cvar("g_balance_grabber_primary_grabbered_fuel");\r
81                 // forced reload\r
82                 if(cvar("g_balance_grabber_reload_ammo") && self.clip_load < min(cvar("g_balance_grabber_primary_ammo"), cvar("g_balance_grabber_secondary_ammo"))\r
83                 && !(self.clip_load >= (time - self.grabber_time_fueldecrease) * grabbered_fuel && self.BUTTON_ATCK)) // not while hooked and still have ammo to stay hooked\r
84                 {\r
85                         if(self.ammo_fuel >= 1) // we only have one weapon in VT, so nothing else to switch to if we're out of ammo\r
86                                 weapon_action(self.weapon, WR_RELOAD);\r
87                 }\r
88                 else if not(self.clip_load < 0) // we're not currently reloading\r
89                 {\r
90                         if (self.BUTTON_ATCK && weapon_action(self.weapon, WR_CHECKAMMO1))\r
91                         {\r
92                                 if(time < self.weapon_delay)\r
93                                         return FALSE;\r
94 \r
95                                 if(!self.grabber)\r
96                                 if not(self.grabber_state & GRABBER_WAITING_FOR_RELEASE)\r
97                                 if not(self.grabber_state & GRABBER_FIRING)\r
98                                 if (time > self.grabber_refire)\r
99                                 if (weapon_prepareattack(0, -1))\r
100                                 {\r
101                                         if (!g_norecoil)\r
102                                                 self.punchangle_x -= cvar("g_balance_grabber_primary_recoil");\r
103                                         W_DecreaseAmmo(ammo_fuel, cvar("g_balance_grabber_primary_ammo"), cvar("g_balance_grabber_reload_ammo"));\r
104                                         self.grabber_state |= GRABBER_FIRING;\r
105                                         weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_grabber_primary_animtime"), w_ready);                               \r
106                                 }\r
107                         }\r
108                         if (self.BUTTON_ATCK2 && weapon_action(self.weapon, WR_CHECKAMMO2))\r
109                         {\r
110                                 if (weapon_prepareattack(1, cvar("g_balance_grabber_secondary_refire")))\r
111                                 {\r
112                                         W_Grabber_Attack2();\r
113                                         weapon_thinkf(WFRAME_FIRE2, cvar("g_balance_grabber_secondary_animtime"), w_ready);\r
114                                         sound (self, CHAN_WEAPON2, "weapons/grabber_swing.wav", VOL_BASE, ATTN_NORM);\r
115                                 }\r
116                         }\r
117                 }\r
118 \r
119                 if(self.grabber)\r
120                 {\r
121                         // if grabbered, no melee attacks, and increase the timer\r
122                         self.grabber_refire = max(self.grabber_refire, time + cvar("g_balance_grabber_primary_refire"));\r
123 \r
124                         // grabber also inhibits health regeneration, but only for 1 second\r
125                         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)\r
126                                 self.pauseregenhealth_finished = max(self.pauseregenhealth_finished, time + cvar("g_balance_pause_fuel_regen"));\r
127                 }\r
128 \r
129                 if(self.grabber && self.grabber.state == 1)\r
130                 {\r
131                         grabbered_time_max = cvar("g_balance_grabber_primary_grabbered_time_max");                      \r
132                         if (grabbered_time_max > 0)\r
133                         {\r
134                                 if ( time > self.grabber_time_grabbered + grabbered_time_max )\r
135                                         self.grabber_state |= GRABBER_REMOVING;\r
136                         }\r
137 \r
138                         if (grabbered_fuel > 0)\r
139                         {\r
140                                 if ( time > self.grabber_time_fueldecrease )\r
141                                 {\r
142                                         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)\r
143                                         {\r
144                                                 if ( self.ammo_fuel >= (time - self.grabber_time_fueldecrease) * grabbered_fuel )\r
145                                                 {\r
146                                                         W_DecreaseAmmo(ammo_fuel, (time - self.grabber_time_fueldecrease) * grabbered_fuel, cvar("g_balance_grabber_reload_ammo"));\r
147                                                         self.grabber_time_fueldecrease = time;\r
148                                                         // decrease next frame again\r
149                                                 }\r
150                                                 else\r
151                                                 {\r
152                                                         self.grabber_state |= GRABBER_REMOVING;\r
153                                                         W_SwitchWeapon_Force(self, w_getbestweapon(self));\r
154                                                 }\r
155                                         }\r
156                                 }\r
157                         }\r
158                 }\r
159                 else\r
160                 {\r
161                         self.grabber_time_grabbered = time;                             \r
162                         self.grabber_time_fueldecrease = time + cvar("g_balance_grabber_primary_grabbered_time_free");\r
163                 }\r
164 \r
165                 if (self.BUTTON_CROUCH)\r
166                 {\r
167                         self.grabber_state &~= GRABBER_PULLING;\r
168                         if (self.BUTTON_ATCK)\r
169                                 self.grabber_state &~= GRABBER_RELEASING;\r
170                         else\r
171                                 self.grabber_state |= GRABBER_RELEASING;\r
172                 }\r
173                 else\r
174                 {\r
175                         self.grabber_state |= GRABBER_PULLING;\r
176                         self.grabber_state &~= GRABBER_RELEASING;\r
177 \r
178                         if (self.BUTTON_ATCK)\r
179                         {\r
180                                 // already fired\r
181                                 if(self.grabber)\r
182                                         self.grabber_state |= GRABBER_WAITING_FOR_RELEASE;\r
183                         }\r
184                         else\r
185                         {\r
186                                 self.grabber_state |= GRABBER_REMOVING;\r
187                                 self.grabber_state &~= GRABBER_WAITING_FOR_RELEASE;\r
188                         }\r
189                 }\r
190         }\r
191         else if (req == WR_PRECACHE)\r
192         {\r
193                 precache_model ("models/weapons/g_grabber.md3");\r
194                 precache_model ("models/weapons/v_grabber.md3");\r
195                 precache_model ("models/weapons/h_grabber.iqm");\r
196                 precache_sound ("weapons/grabber_impact.wav"); // done by g_grabber.qc\r
197                 precache_sound ("weapons/grabber_fire.wav");\r
198                 precache_sound ("weapons/grabber_altfire.wav");\r
199                 precache_sound ("weapons/grabber_swing.wav");\r
200                 precache_sound ("weapons/reload.wav");\r
201         }\r
202         else if (req == WR_SETUP)\r
203         {\r
204                 weapon_setup(WEP_GRABBER);\r
205                 self.grabber_state &~= GRABBER_WAITING_FOR_RELEASE;\r
206                 self.current_ammo = ammo_fuel;\r
207         }\r
208         else if (req == WR_CHECKAMMO1)\r
209         {\r
210                 if(self.grabber)\r
211                 {\r
212                         ammo_amount = self.ammo_fuel > 0;\r
213                         ammo_amount += self.weapon_load[WEP_GRABBER] > 0;\r
214                 }\r
215                 else\r
216                 {\r
217                         ammo_amount = self.ammo_fuel >= cvar("g_balance_grabber_primary_ammo");\r
218                         ammo_amount += self.weapon_load[WEP_GRABBER] >= cvar("g_balance_grabber_primary_ammo");\r
219                 }\r
220                 return ammo_amount;\r
221         }\r
222         else if (req == WR_CHECKAMMO2)\r
223         {\r
224                 ammo_amount = self.ammo_fuel >= cvar("g_balance_grabber_secondary_ammo");\r
225                 ammo_amount += self.weapon_load[WEP_GRABBER] >= cvar("g_balance_grabber_secondary_ammo");\r
226                 return ammo_amount;\r
227         }\r
228         else if (req == WR_RELOAD)\r
229         {\r
230                 self.grabber_state |= GRABBER_REMOVING;\r
231                 W_Reload(min(cvar("g_balance_grabber_primary_ammo"), cvar("g_balance_grabber_secondary_ammo")), cvar("g_balance_grabber_reload_ammo"), cvar("g_balance_grabber_reload_time"), "weapons/reload.wav");\r
232         }\r
233         else if (req == WR_SUICIDEMESSAGE)\r
234                 w_deathtypestring = "did the impossible";\r
235         else if (req == WR_KILLMESSAGE)\r
236                 w_deathtypestring = "has run into #'s paws";\r
237         else if (req == WR_RESETPLAYER)\r
238         {\r
239                 self.grabber_refire = time;\r
240         }\r
241         return TRUE;\r
242 };\r
243 #endif\r