Include gmqcc binaries for Windows and Linux
[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, cvar("g_balance_grabber_secondary_recoil"), "weapons/grabber_altfire.wav", cvar("g_balance_grabber_secondary_damage"));\r
40         pointparticles(particleeffectnum("grabber_muzzleflash"), w_shotorg, '0 0 0', 1);\r
41         W_Grabber_UpdateStats(self, TRUE, FALSE); // the hit is recorded below\r
42 \r
43         WarpZone_traceline_antilag(self, w_shotorg, w_shotorg + w_shotdir * cvar("g_balance_grabber_secondary_radius"), FALSE, self, ANTILAG_LATENCY(self));\r
44 \r
45         if(trace_fraction < 1) // should always be true, but just in case\r
46         {\r
47                 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
48                 pointparticles(particleeffectnum("grabber_impact2"), trace_endpos, '0 0 0', 1);\r
49 \r
50                 if(trace_ent.classname == "player")\r
51                 {\r
52                         trace_ent.armorvalue = bound(0, trace_ent.armorvalue - cvar("g_balance_grabber_secondary_armordamage"), cvar("g_balance_armor_limit"));\r
53                         trace_ent.grabber_stunned = time + cvar("g_balance_grabber_secondary_stun_maxtime") * random();\r
54                         sound (self, CHAN_PROJECTILE, "weapons/grabber_impact2_player.wav", VOL_BASE, ATTN_NORM);\r
55                 }\r
56                 else\r
57                 {\r
58                         sound (self, CHAN_PROJECTILE, "weapons/grabber_impact2_world.wav", VOL_BASE, ATTN_NORM);\r
59                         if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS)\r
60                                 pointparticles(particleeffectnum("ground_metal"), trace_endpos, '0 0 0', 1);\r
61                         else\r
62                                 pointparticles(particleeffectnum("ground_dirt"), trace_endpos, '0 0 0', 1);\r
63                 }\r
64 \r
65                 W_Grabber_UpdateStats(self, FALSE, TRUE); // the shot is recorded above\r
66         }\r
67 \r
68         W_DecreaseAmmo(ammo_fuel, cvar("g_balance_grabber_secondary_ammo"), cvar("g_balance_grabber_reload_ammo"));\r
69 }\r
70 \r
71 void spawnfunc_weapon_grabber (void)\r
72 {\r
73         weapon_defaultspawnfunc(WEP_GRABBER);\r
74 }\r
75 \r
76 float w_grabber(float req)\r
77 {\r
78         if(self.stat_eaten) // we can't use weapons while in the stomach\r
79                 self.grabber_state |= GRABBER_REMOVING;\r
80 \r
81         float ammo_amount;\r
82         float grabbered_time_max, grabbered_fuel;\r
83                 \r
84         if (req == WR_AIM)\r
85         {\r
86                 // ... sorry ...\r
87         }\r
88         else if (req == WR_THINK)\r
89         {\r
90                 // determine by distance if this will be primary fire or alternate fire\r
91                 W_SetupShot (self, TRUE, 0, "", 0); // do this to update w_shotorg\r
92                 WarpZone_traceline_antilag(self, w_shotorg, w_shotorg + w_shotdir * cvar("g_balance_grabber_secondary_radius"), FALSE, self, ANTILAG_LATENCY(self));\r
93                 if(cvar("g_balance_grabber_secondary") && trace_fraction < 1 && !self.grabber) // not if hooked or firing the hook\r
94                         self.stat_crosshair_style = 1;\r
95                 else\r
96                         self.stat_crosshair_style = 0;\r
97 \r
98                 grabbered_fuel = cvar("g_balance_grabber_primary_grabbered_fuel");\r
99                 // forced reload\r
100                 if(cvar("g_balance_grabber_reload_ammo") && self.clip_load < min(cvar("g_balance_grabber_primary_ammo"), cvar("g_balance_grabber_secondary_ammo"))\r
101                 && !(self.clip_load >= (time - self.grabber_time_fueldecrease) * grabbered_fuel && (self.grabber || self.grabber_state & GRABBER_FIRING))) // not while hooked and still have ammo to stay hooked\r
102                 {\r
103                         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
104                                 weapon_action(self.weapon, WR_RELOAD);\r
105                 }\r
106                 else if(self.clip_load >= 0 && !self.stat_eaten) // we're not currently reloading or eaten\r
107                 {\r
108                         if(!self.stat_crosshair_style && self.BUTTON_ATCK2 && weapon_action(self.weapon, WR_CHECKAMMO1)) // primary attack\r
109                         {\r
110                                 if(time < self.weapon_delay)\r
111                                         return FALSE;\r
112 \r
113                                 if(!self.grabber)\r
114                                 if not(self.grabber_state & GRABBER_WAITING_FOR_RELEASE)\r
115                                 if not(self.grabber_state & GRABBER_FIRING)\r
116                                 if (time > self.grabber_refire)\r
117                                 if (weapon_prepareattack(0, -1))\r
118                                 {\r
119                                         W_SetupShot (self, TRUE, cvar("g_balance_grabber_primary_recoil"), "", 0); // do this for recoil\r
120                                         W_DecreaseAmmo(ammo_fuel, cvar("g_balance_grabber_primary_ammo"), cvar("g_balance_grabber_reload_ammo"));\r
121                                         self.grabber_state |= GRABBER_FIRING;\r
122                                         weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_grabber_primary_animtime"), w_ready);                               \r
123                                 }\r
124                         }\r
125                         else if (self.BUTTON_ATCK2 && weapon_action(self.weapon, WR_CHECKAMMO2)) // secondary attack\r
126                         {\r
127                                 if (weapon_prepareattack(1, cvar("g_balance_grabber_secondary_refire")))\r
128                                 {\r
129                                         W_Grabber_Attack2();\r
130                                         weapon_thinkf(WFRAME_FIRE2, cvar("g_balance_grabber_secondary_animtime"), w_ready);\r
131                                         sound (self, CHAN_WEAPON2, "weapons/grabber_swing.wav", VOL_BASE, ATTN_NORM);\r
132                                 }\r
133                         }\r
134                 }\r
135 \r
136                 if(self.grabber)\r
137                 {\r
138                         // if grabbered, no melee attacks, and increase the timer\r
139                         self.grabber_refire = max(self.grabber_refire, time + cvar("g_balance_grabber_primary_refire"));\r
140 \r
141                         // grabber also inhibits health regeneration, but only for 1 second\r
142                         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)\r
143                                 self.pauseregenhealth_finished = max(self.pauseregenhealth_finished, time + cvar("g_balance_pause_fuel_regen"));\r
144                 }\r
145 \r
146                 if(self.grabber && self.grabber.state == 1)\r
147                 {\r
148                         grabbered_time_max = cvar("g_balance_grabber_primary_grabbered_time_max");                      \r
149                         if (grabbered_time_max > 0)\r
150                         {\r
151                                 if ( time > self.grabber_time_grabbered + grabbered_time_max )\r
152                                         self.grabber_state |= GRABBER_REMOVING;\r
153                         }\r
154 \r
155                         if (grabbered_fuel > 0)\r
156                         {\r
157                                 if ( time > self.grabber_time_fueldecrease )\r
158                                 {\r
159                                         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)\r
160                                         {\r
161                                                 float active_ammo;\r
162                                                 if(cvar("g_balance_grabber_reload_ammo"))\r
163                                                         active_ammo = self.clip_load;\r
164                                                 else\r
165                                                         active_ammo = self.ammo_fuel;\r
166 \r
167                                                 if (active_ammo >= (time - self.grabber_time_fueldecrease) * grabbered_fuel )\r
168                                                 {\r
169                                                         W_DecreaseAmmo(ammo_fuel, (time - self.grabber_time_fueldecrease) * grabbered_fuel, cvar("g_balance_grabber_reload_ammo"));\r
170                                                         self.grabber_time_fueldecrease = time;\r
171                                                         // decrease next frame again\r
172                                                 }\r
173                                                 else\r
174                                                 {\r
175                                                         self.grabber_state |= GRABBER_REMOVING;\r
176                                                         W_SwitchWeapon_Force(self, w_getbestweapon(self));\r
177                                                 }\r
178                                         }\r
179                                 }\r
180                         }\r
181                 }\r
182                 else\r
183                 {\r
184                         self.grabber_time_grabbered = time;                             \r
185                         self.grabber_time_fueldecrease = time + cvar("g_balance_grabber_primary_grabbered_time_free");\r
186                 }\r
187 \r
188                 self.grabber_state |= GRABBER_PULLING;\r
189                 self.grabber_state &~= GRABBER_RELEASING;\r
190 \r
191                 if (self.BUTTON_ATCK2)\r
192                 {\r
193                         // already fired\r
194                         if(self.grabber)\r
195                                 self.grabber_state |= GRABBER_WAITING_FOR_RELEASE;\r
196                 }\r
197                 else\r
198                 {\r
199                         self.grabber_state |= GRABBER_REMOVING;\r
200                         self.grabber_state &~= GRABBER_WAITING_FOR_RELEASE;\r
201                 }\r
202         }\r
203         else if (req == WR_PRECACHE)\r
204         {\r
205                 precache_model ("models/weapons/g_grabber.md3");\r
206                 precache_model ("models/weapons/v_grabber.md3");\r
207                 precache_model ("models/weapons/h_grabber.iqm");\r
208                 precache_sound ("weapons/grabber_impact_player.wav");\r
209                 precache_sound ("weapons/grabber_impact_world.wav");\r
210                 precache_sound ("weapons/grabber_impact2_player.wav");\r
211                 precache_sound ("weapons/grabber_impact2_world.wav");\r
212                 precache_sound ("weapons/grabber_fire.wav");\r
213                 precache_sound ("weapons/grabber_altfire.wav");\r
214                 precache_sound ("weapons/grabber_swing.wav");\r
215                 precache_sound ("weapons/reload.wav");\r
216         }\r
217         else if (req == WR_SETUP)\r
218         {\r
219                 weapon_setup(WEP_GRABBER);\r
220                 self.grabber_state &~= GRABBER_WAITING_FOR_RELEASE;\r
221                 self.current_ammo = ammo_fuel;\r
222         }\r
223         else if (req == WR_CHECKAMMO1)\r
224         {\r
225                 if(self.grabber)\r
226                 {\r
227                         if(cvar("g_balance_grabber_reload_ammo"))\r
228                                 ammo_amount = self.weapon_load[WEP_GRABBER] > 0;\r
229                         else\r
230                                 ammo_amount = self.ammo_fuel > 0;\r
231                 }\r
232                 else\r
233                 {\r
234                         if(cvar("g_balance_grabber_reload_ammo"))\r
235                                 ammo_amount = self.weapon_load[WEP_GRABBER] >= cvar("g_balance_grabber_primary_ammo");\r
236                         else\r
237                                 ammo_amount = self.ammo_fuel >= cvar("g_balance_grabber_primary_ammo");\r
238                 }\r
239                 return ammo_amount;\r
240         }\r
241         else if (req == WR_CHECKAMMO2)\r
242         {\r
243                 if(cvar("g_balance_grabber_reload_ammo"))\r
244                         ammo_amount = self.weapon_load[WEP_GRABBER] >= cvar("g_balance_grabber_secondary_ammo");\r
245                 else\r
246                         ammo_amount = self.ammo_fuel >= cvar("g_balance_grabber_secondary_ammo");\r
247                 return ammo_amount;\r
248         }\r
249         else if (req == WR_RELOAD)\r
250         {\r
251                 if(self.clip_load >= 0) // prevents a bug\r
252                         self.grabber_state |= GRABBER_REMOVING;\r
253                 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
254         }\r
255         else if (req == WR_SUICIDEMESSAGE)\r
256                 w_deathtypestring = "did the impossible";\r
257         else if (req == WR_KILLMESSAGE)\r
258                 w_deathtypestring = "has run into #'s paws";\r
259         else if (req == WR_RESETPLAYER)\r
260         {\r
261                 self.grabber_refire = time;\r
262         }\r
263         return TRUE;\r
264 };\r
265 #endif\r