Separate health and armor regen pauses
[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, 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 not(self.items & IT_UNLIMITED_WEAPON_AMMO)\r
53                 self.ammo_fuel = self.ammo_fuel - cvar("g_balance_grabber_secondary_ammo");\r
54 }\r
55 \r
56 void spawnfunc_weapon_grabber (void)\r
57 {\r
58         weapon_defaultspawnfunc(WEP_GRABBER);\r
59 }\r
60 \r
61 float w_grabber(float req)\r
62 {\r
63         if(self.predator.classname == "player") // we can't use weapons while in the stomach\r
64         {\r
65                 self.grabber_state |= GRABBER_REMOVING;\r
66                 return FALSE;\r
67         }\r
68 \r
69         float grabbered_time_max, grabbered_fuel;\r
70                 \r
71         if (req == WR_AIM)\r
72         {\r
73                 // ... sorry ...\r
74         }\r
75         else if (req == WR_THINK)\r
76         {\r
77                 if (self.BUTTON_ATCK || (!(self.items & IT_JETPACK) && self.BUTTON_JETPACK))\r
78                 {\r
79                         if(time < self.weapon_delay)\r
80                                 return FALSE;\r
81 \r
82                         if(!self.grabber)\r
83                         if not(self.grabber_state & GRABBER_WAITING_FOR_RELEASE)\r
84                         if not(self.grabber_state & GRABBER_FIRING)\r
85                         if (time > self.grabber_refire)\r
86                         if (weapon_prepareattack(0, -1))\r
87                         {\r
88                                 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)\r
89                                         self.ammo_fuel = self.ammo_fuel - cvar("g_balance_grabber_primary_ammo");\r
90                                 self.grabber_state |= GRABBER_FIRING;\r
91                                 weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_grabber_primary_animtime"), w_ready);                               \r
92                         }\r
93                 }\r
94 \r
95                 if (self.BUTTON_ATCK2)\r
96                 {\r
97                         if (weapon_prepareattack(1, cvar("g_balance_grabber_secondary_refire")))\r
98                         {\r
99                                 W_Grabber_Attack2();\r
100                                 weapon_thinkf(WFRAME_FIRE2, cvar("g_balance_grabber_secondary_animtime"), w_ready);\r
101                         }\r
102                 }\r
103 \r
104                 if(self.grabber)\r
105                 {\r
106                         // if grabbered, no melee attacks, and increase the timer\r
107                         self.grabber_refire = max(self.grabber_refire, time + cvar("g_balance_grabber_primary_refire"));\r
108 \r
109                         // grabber also inhibits health regeneration, but only for 1 second\r
110                         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)\r
111                                 self.pauseregenhealth_finished = max(self.pauseregenhealth_finished, time + cvar("g_balance_pause_fuel_regen"));\r
112                 }\r
113 \r
114                 if(self.grabber && self.grabber.state == 1)\r
115                 {\r
116                         grabbered_time_max = cvar("g_balance_grabber_primary_grabbered_time_max");                      \r
117                         if (grabbered_time_max > 0)\r
118                         {\r
119                                 if ( time > self.grabber_time_grabbered + grabbered_time_max )\r
120                                         self.grabber_state |= GRABBER_REMOVING;\r
121                         }\r
122                         \r
123                         grabbered_fuel = cvar("g_balance_grabber_primary_grabbered_fuel");\r
124                         if (grabbered_fuel > 0)\r
125                         {\r
126                                 if ( time > self.grabber_time_fueldecrease )\r
127                                 {\r
128                                         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)\r
129                                         {\r
130                                                 if ( self.ammo_fuel >= (time - self.grabber_time_fueldecrease) * grabbered_fuel )\r
131                                                 {\r
132                                                         self.ammo_fuel -= (time - self.grabber_time_fueldecrease) * grabbered_fuel;\r
133                                                         self.grabber_time_fueldecrease = time;\r
134                                                         // decrease next frame again\r
135                                                 }\r
136                                                 else\r
137                                                 {\r
138                                                         self.ammo_fuel = 0;\r
139                                                         self.grabber_state |= GRABBER_REMOVING;\r
140                                                         W_SwitchWeapon_Force(self, w_getbestweapon(self));\r
141                                                 }\r
142                                         }\r
143                                 }\r
144                         }\r
145                 }\r
146                 else\r
147                 {\r
148                         self.grabber_time_grabbered = time;                             \r
149                         self.grabber_time_fueldecrease = time + cvar("g_balance_grabber_primary_grabbered_time_free");\r
150                 }\r
151 \r
152                 if (self.BUTTON_CROUCH)\r
153                 {\r
154                         self.grabber_state &~= GRABBER_PULLING;\r
155                         if (self.BUTTON_ATCK || (!(self.items & IT_JETPACK) && self.BUTTON_JETPACK))\r
156                                 self.grabber_state &~= GRABBER_RELEASING;\r
157                         else\r
158                                 self.grabber_state |= GRABBER_RELEASING;\r
159                 }\r
160                 else\r
161                 {\r
162                         self.grabber_state |= GRABBER_PULLING;\r
163                         self.grabber_state &~= GRABBER_RELEASING;\r
164 \r
165                         if (self.BUTTON_ATCK || (!(self.items & IT_JETPACK) && self.BUTTON_JETPACK))\r
166                         {\r
167                                 // already fired\r
168                                 if(self.grabber)\r
169                                         self.grabber_state |= GRABBER_WAITING_FOR_RELEASE;\r
170                         }\r
171                         else\r
172                         {\r
173                                 self.grabber_state |= GRABBER_REMOVING;\r
174                                 self.grabber_state &~= GRABBER_WAITING_FOR_RELEASE;\r
175                         }\r
176                 }\r
177         }\r
178         else if (req == WR_PRECACHE)\r
179         {\r
180                 precache_model ("models/weapons/g_grabber.md3");\r
181                 precache_model ("models/weapons/v_grabber.md3");\r
182                 precache_model ("models/weapons/h_grabber.dpm");\r
183                 precache_sound ("weapons/grabber_impact.wav"); // done by g_grabber.qc\r
184                 precache_sound ("weapons/grabber_fire.wav");\r
185                 precache_sound ("weapons/grabber_altfire.wav");\r
186         }\r
187         else if (req == WR_SETUP)\r
188         {\r
189                 weapon_setup(WEP_GRABBER);\r
190                 self.grabber_state &~= GRABBER_WAITING_FOR_RELEASE;\r
191         }\r
192         else if (req == WR_CHECKAMMO1)\r
193         {\r
194                 if(self.grabber)\r
195                         return self.ammo_fuel > 0;\r
196                 else\r
197                         return self.ammo_fuel >= cvar("g_balance_grabber_primary_ammo");\r
198         }\r
199         else if (req == WR_CHECKAMMO2)\r
200         {\r
201                 return self.ammo_fuel >= cvar("g_balance_grabber_secondary_ammo");\r
202         }\r
203         else if (req == WR_SUICIDEMESSAGE)\r
204                 w_deathtypestring = "did the impossible";\r
205         else if (req == WR_KILLMESSAGE)\r
206                 w_deathtypestring = "has run into #'s paws";\r
207         else if (req == WR_RESETPLAYER)\r
208         {\r
209                 self.grabber_refire = time;\r
210         }\r
211         return TRUE;\r
212 };\r
213 #endif\r