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