5 /* ammotype */ IT_CELLS|IT_FUEL,
7 /* flags */ WEP_FLAG_CANCLIMB | WEP_TYPE_SPLASH,
11 /* fullname */ _("Grappling Hook")
14 #define HOOK_SETTINGS(w_cvar,w_prop) \
15 w_cvar(WEP_HOOK, hook, MO_BOTH, animtime) \
16 w_cvar(WEP_HOOK, hook, MO_BOTH, ammo) \
17 w_cvar(WEP_HOOK, hook, MO_BOTH, refire) \
18 w_cvar(WEP_HOOK, hook, MO_PRI, hooked_ammo) \
19 w_cvar(WEP_HOOK, hook, MO_PRI, hooked_time_free) \
20 w_cvar(WEP_HOOK, hook, MO_PRI, hooked_time_max) \
21 w_cvar(WEP_HOOK, hook, MO_SEC, damage) \
22 w_cvar(WEP_HOOK, hook, MO_SEC, duration) \
23 w_cvar(WEP_HOOK, hook, MO_SEC, edgedamage) \
24 w_cvar(WEP_HOOK, hook, MO_SEC, force) \
25 w_cvar(WEP_HOOK, hook, MO_SEC, gravity) \
26 w_cvar(WEP_HOOK, hook, MO_SEC, lifetime) \
27 w_cvar(WEP_HOOK, hook, MO_SEC, power) \
28 w_cvar(WEP_HOOK, hook, MO_SEC, radius) \
29 w_cvar(WEP_HOOK, hook, MO_SEC, speed) \
30 w_cvar(WEP_HOOK, hook, MO_SEC, health) \
31 w_cvar(WEP_HOOK, hook, MO_SEC, damageforcescale) \
32 w_prop(WEP_HOOK, hook, float, reloading_ammo, reload_ammo) \
33 w_prop(WEP_HOOK, hook, float, reloading_time, reload_time) \
34 w_prop(WEP_HOOK, hook, float, switchdelay_raise, switchdelay_raise) \
35 w_prop(WEP_HOOK, hook, float, switchdelay_drop, switchdelay_drop) \
36 w_prop(WEP_HOOK, hook, string, weaponreplace, weaponreplace) \
37 w_prop(WEP_HOOK, hook, float, weaponstart, weaponstart)
40 HOOK_SETTINGS(WEP_ADD_CVAR, WEP_ADD_PROP)
50 .float hook_time_hooked;
51 .float hook_time_fueldecrease;
56 void spawnfunc_weapon_hook()
58 if(g_grappling_hook) // offhand hook
60 startitem_failed = TRUE;
64 weapon_defaultspawnfunc(WEP_HOOK);
67 void W_Hook_ExplodeThink (void)
69 float dt, dmg_remaining_next, f;
71 dt = time - self.teleport_time;
72 dmg_remaining_next = pow(bound(0, 1 - dt / self.dmg_duration, 1), self.dmg_power);
74 f = self.dmg_last - dmg_remaining_next;
75 self.dmg_last = dmg_remaining_next;
77 RadiusDamage (self, self.realowner, self.dmg * f, self.dmg_edge * f, self.dmg_radius, self.realowner, world, self.dmg_force * f, self.projectiledeathtype, world);
78 self.projectiledeathtype |= HITTYPE_BOUNCE;
79 //RadiusDamage (self, world, self.dmg * f, self.dmg_edge * f, self.dmg_radius, world, world, self.dmg_force * f, self.projectiledeathtype, world);
81 if(dt < self.dmg_duration)
82 self.nextthink = time + 0.05; // soon
87 void W_Hook_Explode2 (void)
89 self.event_damage = func_null;
90 self.touch = func_null;
91 self.effects |= EF_NODRAW;
93 self.think = W_Hook_ExplodeThink;
94 self.nextthink = time;
95 self.dmg = WEP_CVAR_SEC(hook, damage);
96 self.dmg_edge = WEP_CVAR_SEC(hook, edgedamage);
97 self.dmg_radius = WEP_CVAR_SEC(hook, radius);
98 self.dmg_force = WEP_CVAR_SEC(hook, force);
99 self.dmg_power = WEP_CVAR_SEC(hook, power);
100 self.dmg_duration = WEP_CVAR_SEC(hook, duration);
101 self.teleport_time = time;
103 self.movetype = MOVETYPE_NONE;
106 void W_Hook_Damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
108 if (self.health <= 0)
111 if (!W_CheckProjectileDamage(inflictor.realowner, self.realowner, deathtype, -1)) // no exceptions
112 return; // g_projectiles_damage says to halt
114 self.health = self.health - damage;
116 if (self.health <= 0)
117 W_PrepareExplosionByDamage(self.realowner, W_Hook_Explode2);
120 void W_Hook_Touch2 (void)
126 void W_Hook_Attack2()
130 W_DecreaseAmmo(ammo_cells, WEP_CVAR_SEC(hook, ammo), FALSE);
131 W_SetupShot (self, FALSE, 4, "weapons/hookbomb_fire.wav", CH_WEAPON_A, WEP_CVAR_SEC(hook, damage));
134 gren.owner = gren.realowner = self;
135 gren.classname = "hookbomb";
136 gren.bot_dodge = TRUE;
137 gren.bot_dodgerating = WEP_CVAR_SEC(hook, damage);
138 gren.movetype = MOVETYPE_TOSS;
139 PROJECTILE_MAKETRIGGER(gren);
140 gren.projectiledeathtype = WEP_HOOK | HITTYPE_SECONDARY;
141 setorigin(gren, w_shotorg);
142 setsize(gren, '0 0 0', '0 0 0');
144 gren.nextthink = time + WEP_CVAR_SEC(hook, lifetime);
145 gren.think = adaptor_think2use_hittype_splash;
146 gren.use = W_Hook_Explode2;
147 gren.touch = W_Hook_Touch2;
149 gren.takedamage = DAMAGE_YES;
150 gren.health = WEP_CVAR_SEC(hook, health);
151 gren.damageforcescale = WEP_CVAR_SEC(hook, damageforcescale);
152 gren.event_damage = W_Hook_Damage;
153 gren.damagedbycontents = TRUE;
154 gren.missile_flags = MIF_SPLASH | MIF_ARC;
156 gren.velocity = '0 0 1' * WEP_CVAR_SEC(hook, speed);
157 if(autocvar_g_projectiles_newton_style)
158 gren.velocity = gren.velocity + self.velocity;
160 gren.gravity = WEP_CVAR_SEC(hook, gravity);
161 //W_SetupProjectileVelocity(gren); // just falling down!
163 gren.angles = '0 0 0';
164 gren.flags = FL_PROJECTILE;
166 CSQCProjectile(gren, TRUE, PROJECTILE_HOOKBOMB, TRUE);
168 other = gren; MUTATOR_CALLHOOK(EditProjectile);
171 float w_hook(float req)
173 float hooked_time_max, hooked_fuel;
179 // no bot AI for hook (yet?)
184 if (self.BUTTON_ATCK || (!(self.items & IT_JETPACK) && self.BUTTON_HOOK))
187 if(!(self.hook_state & HOOK_WAITING_FOR_RELEASE))
188 if(!(self.hook_state & HOOK_FIRING))
189 if (time > self.hook_refire)
190 if (weapon_prepareattack(0, -1))
192 W_DecreaseAmmo(ammo_fuel, WEP_CVAR_PRI(hook, ammo), FALSE);
193 self.hook_state |= HOOK_FIRING;
194 weapon_thinkf(WFRAME_FIRE1, WEP_CVAR_PRI(hook, animtime), w_ready);
198 if (self.BUTTON_ATCK2)
200 if (weapon_prepareattack(1, WEP_CVAR_SEC(hook, refire)))
203 weapon_thinkf(WFRAME_FIRE2, WEP_CVAR_SEC(hook, animtime), w_ready);
209 // if hooked, no bombs, and increase the timer
210 self.hook_refire = max(self.hook_refire, time + WEP_CVAR_PRI(hook, refire) * W_WeaponRateFactor());
212 // hook also inhibits health regeneration, but only for 1 second
213 if(!(self.items & IT_UNLIMITED_WEAPON_AMMO))
214 self.pauseregen_finished = max(self.pauseregen_finished, time + autocvar_g_balance_pause_fuel_regen);
217 if(self.hook && self.hook.state == 1)
219 hooked_time_max = WEP_CVAR_PRI(hook, hooked_time_max);
220 if (hooked_time_max > 0)
222 if ( time > self.hook_time_hooked + hooked_time_max )
223 self.hook_state |= HOOK_REMOVING;
226 hooked_fuel = WEP_CVAR_PRI(hook, hooked_ammo);
229 if ( time > self.hook_time_fueldecrease )
231 if(!(self.items & IT_UNLIMITED_WEAPON_AMMO))
233 if ( self.ammo_fuel >= (time - self.hook_time_fueldecrease) * hooked_fuel )
235 W_DecreaseAmmo(ammo_fuel, (time - self.hook_time_fueldecrease) * hooked_fuel, FALSE);
236 self.hook_time_fueldecrease = time;
237 // decrease next frame again
242 self.hook_state |= HOOK_REMOVING;
243 W_SwitchWeapon_Force(self, w_getbestweapon(self));
251 self.hook_time_hooked = time;
252 self.hook_time_fueldecrease = time + WEP_CVAR_PRI(hook, hooked_time_free);
255 if (self.BUTTON_CROUCH)
257 self.hook_state &= ~HOOK_PULLING;
258 if (self.BUTTON_ATCK || (!(self.items & IT_JETPACK) && self.BUTTON_HOOK))
259 self.hook_state &= ~HOOK_RELEASING;
261 self.hook_state |= HOOK_RELEASING;
265 self.hook_state |= HOOK_PULLING;
266 self.hook_state &= ~HOOK_RELEASING;
268 if (self.BUTTON_ATCK || (!(self.items & IT_JETPACK) && self.BUTTON_HOOK))
272 self.hook_state |= HOOK_WAITING_FOR_RELEASE;
276 self.hook_state |= HOOK_REMOVING;
277 self.hook_state &= ~HOOK_WAITING_FOR_RELEASE;
285 precache_model ("models/weapons/g_hookgun.md3");
286 precache_model ("models/weapons/v_hookgun.md3");
287 precache_model ("models/weapons/h_hookgun.iqm");
288 precache_sound ("weapons/hook_impact.wav"); // done by g_hook.qc
289 precache_sound ("weapons/hook_fire.wav");
290 precache_sound ("weapons/hookbomb_fire.wav");
291 HOOK_SETTINGS(WEP_SKIPCVAR, WEP_SET_PROP)
296 self.current_ammo = ammo_fuel;
297 self.hook_state &= ~HOOK_WAITING_FOR_RELEASE;
303 return self.ammo_fuel > 0;
305 return self.ammo_fuel >= WEP_CVAR_PRI(hook, ammo);
309 return self.ammo_cells >= WEP_CVAR_SEC(hook, ammo);
313 HOOK_SETTINGS(WEP_CONFIG_WRITE_CVARS, WEP_CONFIG_WRITE_PROPS)
318 self.hook_refire = time;
321 case WR_SUICIDEMESSAGE:
327 return WEAPON_HOOK_MURDER;
334 float w_hook(float req)
338 case WR_IMPACTEFFECT:
341 org2 = w_org + w_backoff * 2;
342 pointparticles(particleeffectnum("hookbomb_explode"), org2, '0 0 0', 1);
344 sound(self, CH_SHOTS, "weapons/hookbomb_impact.wav", VOL_BASE, ATTN_NORM);
350 precache_sound("weapons/hookbomb_impact.wav");