]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/w_hook.qc
Merge branch 'master' into mirceakitsune/universal_reload_system
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / w_hook.qc
1 #ifdef REGISTER_WEAPON
2 REGISTER_WEAPON(HOOK, w_hook, IT_CELLS|IT_FUEL, 0, WEP_FLAG_CANCLIMB | WEP_TYPE_SPLASH, 0, "hookgun", "hook", _("Grappling Hook"))
3 #else
4 #ifdef SVQC
5 .float dmg;
6 .float dmg_edge;
7 .float dmg_radius;
8 .float dmg_force;
9 .float dmg_power;
10 .float dmg_duration;
11 .float dmg_last;
12 .float hook_refire;
13 .float hook_time_hooked;
14 .float hook_time_fueldecrease;
15
16 void W_Hook_SetAmmoCounter()
17 {
18         // this weapon doesn't have a reload system, so always set the clip to 0 when switching to it
19         self.clip_load = self.clip_size = 0; // also keeps crosshair ammo from displaying
20 }
21
22 void W_Hook_ExplodeThink (void)
23 {
24         float dt, dmg_remaining_next, f;
25
26         dt = time - self.teleport_time;
27         dmg_remaining_next = pow(bound(0, 1 - dt / self.dmg_duration, 1), self.dmg_power);
28
29         f = self.dmg_last - dmg_remaining_next;
30         self.dmg_last = dmg_remaining_next;
31
32         RadiusDamage (self, self.owner, self.dmg * f, self.dmg_edge * f, self.dmg_radius, self.owner, self.dmg_force * f, self.projectiledeathtype, world);
33         self.projectiledeathtype |= HITTYPE_BOUNCE;
34         //RadiusDamage (self, world, self.dmg * f, self.dmg_edge * f, self.dmg_radius, world, self.dmg_force * f, self.projectiledeathtype, world);
35
36         if(dt < self.dmg_duration)
37                 self.nextthink = time + 0.05; // soon
38         else
39                 remove(self);
40 }
41
42 void W_Hook_Explode2 (void)
43 {
44         self.event_damage = SUB_Null;
45         self.touch = SUB_Null;
46         self.effects |= EF_NODRAW;
47
48         self.think = W_Hook_ExplodeThink;
49         self.nextthink = time;
50         self.dmg = autocvar_g_balance_hook_secondary_damage;
51         self.dmg_edge = autocvar_g_balance_hook_secondary_edgedamage;
52         self.dmg_radius = autocvar_g_balance_hook_secondary_radius;
53         self.dmg_force = autocvar_g_balance_hook_secondary_force;
54         self.dmg_power = autocvar_g_balance_hook_secondary_power;
55         self.dmg_duration = autocvar_g_balance_hook_secondary_duration;
56         self.teleport_time = time;
57         self.dmg_last = 1;
58         self.movetype = MOVETYPE_NONE;
59 }
60
61 void W_Hook_Touch2 (void)
62 {
63         PROJECTILE_TOUCH;
64         self.use();
65 }
66
67 void W_Hook_Attack2()
68 {
69         local entity gren;
70
71         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
72                 self.ammo_cells = self.ammo_cells - autocvar_g_balance_hook_secondary_ammo;
73         W_SetupShot (self, FALSE, 4, "weapons/hookbomb_fire.wav", CHAN_WEAPON, autocvar_g_balance_hook_secondary_damage);
74
75         gren = spawn ();
76         gren.owner = self;
77         gren.classname = "hookbomb";
78         gren.bot_dodge = TRUE;
79         gren.bot_dodgerating = autocvar_g_balance_hook_secondary_damage;
80         gren.movetype = MOVETYPE_TOSS;
81         PROJECTILE_MAKETRIGGER(gren);
82         gren.projectiledeathtype = WEP_HOOK | HITTYPE_SECONDARY;
83         setorigin(gren, w_shotorg);
84         setsize(gren, '0 0 0', '0 0 0');
85
86         gren.nextthink = time + autocvar_g_balance_hook_secondary_lifetime;
87         gren.think = adaptor_think2use_hittype_splash;
88         gren.use = W_Hook_Explode2;
89         gren.touch = W_Hook_Touch2;
90
91         gren.velocity = '0 0 1' * autocvar_g_balance_hook_secondary_speed;
92         if(autocvar_g_projectiles_newton_style)
93                 gren.velocity = gren.velocity + self.velocity;
94
95         gren.gravity = autocvar_g_balance_hook_secondary_gravity;
96         //W_SetupProjectileVelocity(gren); // just falling down!
97
98         gren.angles = '0 0 0';
99         gren.flags = FL_PROJECTILE;
100
101         CSQCProjectile(gren, TRUE, PROJECTILE_HOOKBOMB, TRUE);
102
103         other = gren; MUTATOR_CALLHOOK(EditProjectile);
104 }
105
106 void spawnfunc_weapon_hook (void)
107 {
108         if(g_grappling_hook) // offhand hook
109         {
110                 startitem_failed = TRUE;
111                 remove(self);
112                 return;
113         }
114         weapon_defaultspawnfunc(WEP_HOOK);
115 }
116
117 float w_hook(float req)
118 {
119         float hooked_time_max, hooked_fuel;
120                 
121         if (req == WR_AIM)
122         {
123                 // ... sorry ...
124         }
125         else if (req == WR_THINK)
126         {
127                 if (self.BUTTON_ATCK || (!(self.items & IT_JETPACK) && self.BUTTON_HOOK))
128                 {
129                         if(!self.hook)
130                         if not(self.hook_state & HOOK_WAITING_FOR_RELEASE)
131                         if not(self.hook_state & HOOK_FIRING)
132                         if (time > self.hook_refire)
133                         if (weapon_prepareattack(0, -1))
134                         {
135                                 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
136                                         self.ammo_fuel = self.ammo_fuel - autocvar_g_balance_hook_primary_fuel;
137                                 self.hook_state |= HOOK_FIRING;
138                                 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_hook_primary_animtime, w_ready);                         
139                         }
140                 }
141
142                 if (self.BUTTON_ATCK2)
143                 {
144                         if (weapon_prepareattack(1, autocvar_g_balance_hook_secondary_refire))
145                         {
146                                 W_Hook_Attack2();
147                                 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_hook_secondary_animtime, w_ready);
148                         }
149                 }
150
151                 if(self.hook)
152                 {
153                         // if hooked, no bombs, and increase the timer
154                         self.hook_refire = max(self.hook_refire, time + autocvar_g_balance_hook_primary_refire);
155
156                         // hook also inhibits health regeneration, but only for 1 second
157                         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
158                                 self.pauseregen_finished = max(self.pauseregen_finished, time + autocvar_g_balance_pause_fuel_regen);
159                 }
160
161                 if(self.hook && self.hook.state == 1)
162                 {
163                         hooked_time_max = autocvar_g_balance_hook_primary_hooked_time_max;                      
164                         if (hooked_time_max > 0)
165                         {
166                                 if ( time > self.hook_time_hooked + hooked_time_max )
167                                         self.hook_state |= HOOK_REMOVING;
168                         }
169                         
170                         hooked_fuel = autocvar_g_balance_hook_primary_hooked_fuel;
171                         if (hooked_fuel > 0)
172                         {
173                                 if ( time > self.hook_time_fueldecrease )
174                                 {
175                                         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
176                                         {
177                                                 if ( self.ammo_fuel >= (time - self.hook_time_fueldecrease) * hooked_fuel )
178                                                 {
179                                                         self.ammo_fuel -= (time - self.hook_time_fueldecrease) * hooked_fuel;
180                                                         self.hook_time_fueldecrease = time;
181                                                         // decrease next frame again
182                                                 }
183                                                 else
184                                                 {
185                                                         self.ammo_fuel = 0;
186                                                         self.hook_state |= HOOK_REMOVING;
187                                                         W_SwitchWeapon_Force(self, w_getbestweapon(self));
188                                                 }
189                                         }
190                                 }
191                         }
192                 }
193                 else
194                 {
195                         self.hook_time_hooked = time;                           
196                         self.hook_time_fueldecrease = time + autocvar_g_balance_hook_primary_hooked_time_free;
197                 }
198
199                 if (self.BUTTON_CROUCH)
200                 {
201                         self.hook_state &~= HOOK_PULLING;
202                         if (self.BUTTON_ATCK || (!(self.items & IT_JETPACK) && self.BUTTON_HOOK))
203                                 self.hook_state &~= HOOK_RELEASING;
204                         else
205                                 self.hook_state |= HOOK_RELEASING;
206                 }
207                 else
208                 {
209                         self.hook_state |= HOOK_PULLING;
210                         self.hook_state &~= HOOK_RELEASING;
211
212                         if (self.BUTTON_ATCK || (!(self.items & IT_JETPACK) && self.BUTTON_HOOK))
213                         {
214                                 // already fired
215                                 if(self.hook)
216                                         self.hook_state |= HOOK_WAITING_FOR_RELEASE;
217                         }
218                         else
219                         {
220                                 self.hook_state |= HOOK_REMOVING;
221                                 self.hook_state &~= HOOK_WAITING_FOR_RELEASE;
222                         }
223                 }
224         }
225         else if (req == WR_PRECACHE)
226         {
227                 precache_model ("models/weapons/g_hookgun.md3");
228                 precache_model ("models/weapons/v_hookgun.md3");
229                 precache_model ("models/weapons/h_hookgun.iqm");
230                 precache_sound ("weapons/hook_impact.wav"); // done by g_hook.qc
231                 precache_sound ("weapons/hook_fire.wav");
232                 precache_sound ("weapons/hookbomb_fire.wav");
233         }
234         else if (req == WR_SETUP)
235         {
236                 weapon_setup(WEP_HOOK);
237                 W_Hook_SetAmmoCounter();
238                 self.hook_state &~= HOOK_WAITING_FOR_RELEASE;
239         }
240         else if (req == WR_CHECKAMMO1)
241         {
242                 if(self.hook)
243                         return self.ammo_fuel > 0;
244                 else
245                         return self.ammo_fuel >= autocvar_g_balance_hook_primary_fuel;
246         }
247         else if (req == WR_CHECKAMMO2)
248         {
249                 return self.ammo_cells >= autocvar_g_balance_hook_secondary_ammo;
250         }
251         else if (req == WR_RESETPLAYER)
252         {
253                 self.hook_refire = time;
254         }
255         return TRUE;
256 };
257 #endif
258 #ifdef CSQC
259 float w_hook(float req)
260 {
261         if(req == WR_IMPACTEFFECT)
262         {
263                 vector org2;
264                 org2 = w_org + w_backoff * 2;
265                 pointparticles(particleeffectnum("hookbomb_explode"), org2, '0 0 0', 1);
266                 if(!w_issilent)
267                         sound(self, CHAN_PROJECTILE, "weapons/hookbomb_impact.wav", VOL_BASE, ATTN_NORM);
268         }
269         else if(req == WR_PRECACHE)
270         {
271                 precache_sound("weapons/hookbomb_impact.wav");
272         }
273         else if (req == WR_SUICIDEMESSAGE)
274                 w_deathtypestring = _("%s did the impossible");
275         else if (req == WR_KILLMESSAGE)
276                 w_deathtypestring = _("%s has run into %s's gravity bomb");
277         return TRUE;
278 }
279 #endif
280 #endif