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