Fix a tiny issue
[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_SPLASH, 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_Touch2 (void)\r
13 {\r
14         PROJECTILE_TOUCH;\r
15         self.use();\r
16 }\r
17 \r
18 void W_Grabber_Attack2()\r
19 {\r
20         if(time < self.weapon_delay)\r
21                 return;\r
22 \r
23         W_SetupShot (self, TRUE, 0, "weapons/grabber_altfire.wav", cvar("g_balance_grabber_secondary_damage"));\r
24 \r
25         WarpZone_traceline_antilag(self, w_shotorg, w_shotorg + w_shotdir * cvar("g_balance_grabber_secondary_radius"), FALSE, self, ANTILAG_LATENCY(self));\r
26 \r
27         pointparticles(particleeffectnum("grabber_melee"), w_shotorg + w_shotdir * cvar("g_balance_grabber_secondary_radius"), '0 0 0', 1);\r
28 \r
29         if (trace_fraction < 1)\r
30                 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
31 \r
32         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)\r
33                 self.ammo_fuel = self.ammo_fuel - cvar("g_balance_grabber_secondary_ammo");\r
34 }\r
35 \r
36 void spawnfunc_weapon_grabber (void)\r
37 {\r
38         weapon_defaultspawnfunc(WEP_GRABBER);\r
39 }\r
40 \r
41 float w_grabber(float req)\r
42 {\r
43         if(self.eater.classname == "player") // we can't use weapons while in the stomach\r
44         {\r
45                 self.grabber_state |= GRABBER_REMOVING;\r
46                 return FALSE;\r
47         }\r
48 \r
49         float grabbered_time_max, grabbered_fuel;\r
50                 \r
51         if (req == WR_AIM)\r
52         {\r
53                 // ... sorry ...\r
54         }\r
55         else if (req == WR_THINK)\r
56         {\r
57                 if (self.BUTTON_ATCK || (!(self.items & IT_JETPACK) && self.BUTTON_JETPACK))\r
58                 {\r
59                         if(time < self.weapon_delay)\r
60                                 return FALSE;\r
61 \r
62                         if(!self.grabber)\r
63                         if not(self.grabber_state & GRABBER_WAITING_FOR_RELEASE)\r
64                         if not(self.grabber_state & GRABBER_FIRING)\r
65                         if (time > self.grabber_refire)\r
66                         if (weapon_prepareattack(0, -1))\r
67                         {\r
68                                 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)\r
69                                         self.ammo_fuel = self.ammo_fuel - cvar("g_balance_grabber_primary_ammo");\r
70                                 self.grabber_state |= GRABBER_FIRING;\r
71                                 weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_grabber_primary_animtime"), w_ready);                               \r
72                         }\r
73                 }\r
74 \r
75                 if (self.BUTTON_ATCK2)\r
76                 {\r
77                         if (weapon_prepareattack(1, cvar("g_balance_grabber_secondary_refire")))\r
78                         {\r
79                                 W_Grabber_Attack2();\r
80                                 weapon_thinkf(WFRAME_FIRE2, cvar("g_balance_grabber_secondary_animtime"), w_ready);\r
81                         }\r
82                 }\r
83 \r
84                 if(self.grabber)\r
85                 {\r
86                         // if grabbered, no melee attacks, and increase the timer\r
87                         self.grabber_refire = max(self.grabber_refire, time + cvar("g_balance_grabber_primary_refire"));\r
88 \r
89                         // grabber also inhibits health regeneration, but only for 1 second\r
90                         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)\r
91                                 self.pauseregen_finished = max(self.pauseregen_finished, time + cvar("g_balance_pause_fuel_regen"));\r
92                 }\r
93 \r
94                 if(self.grabber && self.grabber.state == 1)\r
95                 {\r
96                         grabbered_time_max = cvar("g_balance_grabber_primary_grabbered_time_max");                      \r
97                         if (grabbered_time_max > 0)\r
98                         {\r
99                                 if ( time > self.grabber_time_grabbered + grabbered_time_max )\r
100                                         self.grabber_state |= GRABBER_REMOVING;\r
101                         }\r
102                         \r
103                         grabbered_fuel = cvar("g_balance_grabber_primary_grabbered_fuel");\r
104                         if (grabbered_fuel > 0)\r
105                         {\r
106                                 if ( time > self.grabber_time_fueldecrease )\r
107                                 {\r
108                                         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)\r
109                                         {\r
110                                                 if ( self.ammo_fuel >= (time - self.grabber_time_fueldecrease) * grabbered_fuel )\r
111                                                 {\r
112                                                         self.ammo_fuel -= (time - self.grabber_time_fueldecrease) * grabbered_fuel;\r
113                                                         self.grabber_time_fueldecrease = time;\r
114                                                         // decrease next frame again\r
115                                                 }\r
116                                                 else\r
117                                                 {\r
118                                                         self.ammo_fuel = 0;\r
119                                                         self.grabber_state |= GRABBER_REMOVING;\r
120                                                         W_SwitchWeapon_Force(self, w_getbestweapon(self));\r
121                                                 }\r
122                                         }\r
123                                 }\r
124                         }\r
125                 }\r
126                 else\r
127                 {\r
128                         self.grabber_time_grabbered = time;                             \r
129                         self.grabber_time_fueldecrease = time + cvar("g_balance_grabber_primary_grabbered_time_free");\r
130                 }\r
131 \r
132                 if (self.BUTTON_CROUCH)\r
133                 {\r
134                         self.grabber_state &~= GRABBER_PULLING;\r
135                         if (self.BUTTON_ATCK || (!(self.items & IT_JETPACK) && self.BUTTON_JETPACK))\r
136                                 self.grabber_state &~= GRABBER_RELEASING;\r
137                         else\r
138                                 self.grabber_state |= GRABBER_RELEASING;\r
139                 }\r
140                 else\r
141                 {\r
142                         self.grabber_state |= GRABBER_PULLING;\r
143                         self.grabber_state &~= GRABBER_RELEASING;\r
144 \r
145                         if (self.BUTTON_ATCK || (!(self.items & IT_JETPACK) && self.BUTTON_JETPACK))\r
146                         {\r
147                                 // already fired\r
148                                 if(self.grabber)\r
149                                         self.grabber_state |= GRABBER_WAITING_FOR_RELEASE;\r
150                         }\r
151                         else\r
152                         {\r
153                                 self.grabber_state |= GRABBER_REMOVING;\r
154                                 self.grabber_state &~= GRABBER_WAITING_FOR_RELEASE;\r
155                         }\r
156                 }\r
157         }\r
158         else if (req == WR_PRECACHE)\r
159         {\r
160                 precache_model ("models/weapons/g_grabber.md3");\r
161                 precache_model ("models/weapons/v_grabber.md3");\r
162                 precache_model ("models/weapons/h_grabber.dpm");\r
163                 precache_sound ("weapons/grabber_impact.wav"); // done by g_grabber.qc\r
164                 precache_sound ("weapons/grabber_fire.wav");\r
165                 precache_sound ("weapons/grabber_altfire.wav");\r
166         }\r
167         else if (req == WR_SETUP)\r
168         {\r
169                 weapon_setup(WEP_GRABBER);\r
170                 self.grabber_state &~= GRABBER_WAITING_FOR_RELEASE;\r
171         }\r
172         else if (req == WR_CHECKAMMO1)\r
173         {\r
174                 if(self.grabber)\r
175                         return self.ammo_fuel > 0;\r
176                 else\r
177                         return self.ammo_fuel >= cvar("g_balance_grabber_primary_ammo");\r
178         }\r
179         else if (req == WR_CHECKAMMO2)\r
180         {\r
181                 return self.ammo_fuel >= cvar("g_balance_grabber_secondary_ammo");\r
182         }\r
183         else if (req == WR_SUICIDEMESSAGE)\r
184                 w_deathtypestring = "did the impossible";\r
185         else if (req == WR_KILLMESSAGE)\r
186                 w_deathtypestring = "has run into #'s paws";\r
187         else if (req == WR_RESETPLAYER)\r
188         {\r
189                 self.grabber_refire = time;\r
190         }\r
191         return TRUE;\r
192 };\r
193 #endif\r