2 REGISTER_WEAPON(HOOK, w_hook, IT_CELLS|IT_FUEL, 0, WEP_FLAG_CANCLIMB | WEP_TYPE_SPLASH, 0, "hookgun", "hook", _("Grappling Hook"))
13 .float hook_time_hooked;
14 .float hook_time_fueldecrease;
16 void W_Hook_ExplodeThink (void)
18 float dt, dmg_remaining_next, f;
20 dt = time - self.teleport_time;
21 dmg_remaining_next = pow(bound(0, 1 - dt / self.dmg_duration, 1), self.dmg_power);
23 f = self.dmg_last - dmg_remaining_next;
24 self.dmg_last = dmg_remaining_next;
26 RadiusDamage (self, self.realowner, self.dmg * f, self.dmg_edge * f, self.dmg_radius, self.realowner, self.dmg_force * f, self.projectiledeathtype, world);
27 self.projectiledeathtype |= HITTYPE_BOUNCE;
28 //RadiusDamage (self, world, self.dmg * f, self.dmg_edge * f, self.dmg_radius, world, self.dmg_force * f, self.projectiledeathtype, world);
30 if(dt < self.dmg_duration)
31 self.nextthink = time + 0.05; // soon
36 void W_Hook_Explode2 (void)
38 self.event_damage = SUB_Null;
39 self.touch = SUB_Null;
40 self.effects |= EF_NODRAW;
42 self.think = W_Hook_ExplodeThink;
43 self.nextthink = time;
44 self.dmg = autocvar_g_balance_hook_secondary_damage;
45 self.dmg_edge = autocvar_g_balance_hook_secondary_edgedamage;
46 self.dmg_radius = autocvar_g_balance_hook_secondary_radius;
47 self.dmg_force = autocvar_g_balance_hook_secondary_force;
48 self.dmg_power = autocvar_g_balance_hook_secondary_power;
49 self.dmg_duration = autocvar_g_balance_hook_secondary_duration;
50 self.teleport_time = time;
52 self.movetype = MOVETYPE_NONE;
55 void W_Hook_Damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
60 if (!W_CheckProjectileDamage(inflictor.realowner, self.realowner, deathtype, -1)) // no exceptions
61 return; // g_projectiles_damage says to halt
63 self.health = self.health - damage;
66 W_PrepareExplosionByDamage(self.realowner, W_Hook_Explode2);
69 void W_Hook_Touch2 (void)
79 W_DecreaseAmmo(ammo_cells, autocvar_g_balance_hook_secondary_ammo, FALSE);
80 W_SetupShot (self, FALSE, 4, "weapons/hookbomb_fire.wav", CH_WEAPON_A, autocvar_g_balance_hook_secondary_damage);
83 gren.owner = gren.realowner = self;
84 gren.classname = "hookbomb";
85 gren.bot_dodge = TRUE;
86 gren.bot_dodgerating = autocvar_g_balance_hook_secondary_damage;
87 gren.movetype = MOVETYPE_TOSS;
88 PROJECTILE_MAKETRIGGER(gren);
89 gren.projectiledeathtype = WEP_HOOK | HITTYPE_SECONDARY;
90 setorigin(gren, w_shotorg);
91 setsize(gren, '0 0 0', '0 0 0');
93 gren.nextthink = time + autocvar_g_balance_hook_secondary_lifetime;
94 gren.think = adaptor_think2use_hittype_splash;
95 gren.use = W_Hook_Explode2;
96 gren.touch = W_Hook_Touch2;
98 gren.takedamage = DAMAGE_YES;
99 gren.health = autocvar_g_balance_hook_secondary_health;
100 gren.damageforcescale = autocvar_g_balance_hook_secondary_damageforcescale;
101 gren.event_damage = W_Hook_Damage;
102 gren.damagedbycontents = TRUE;
104 gren.velocity = '0 0 1' * autocvar_g_balance_hook_secondary_speed;
105 if(autocvar_g_projectiles_newton_style)
106 gren.velocity = gren.velocity + self.velocity;
108 gren.gravity = autocvar_g_balance_hook_secondary_gravity;
109 //W_SetupProjectileVelocity(gren); // just falling down!
111 gren.angles = '0 0 0';
112 gren.flags = FL_PROJECTILE;
114 CSQCProjectile(gren, TRUE, PROJECTILE_HOOKBOMB, TRUE);
116 other = gren; MUTATOR_CALLHOOK(EditProjectile);
119 void spawnfunc_weapon_hook (void)
121 if(g_grappling_hook) // offhand hook
123 startitem_failed = TRUE;
127 weapon_defaultspawnfunc(WEP_HOOK);
130 float w_hook(float req)
132 float hooked_time_max, hooked_fuel;
138 else if (req == WR_THINK)
140 if (self.BUTTON_ATCK || (!(self.items & IT_JETPACK) && self.BUTTON_HOOK))
143 if not(self.hook_state & HOOK_WAITING_FOR_RELEASE)
144 if not(self.hook_state & HOOK_FIRING)
145 if (time > self.hook_refire)
146 if (weapon_prepareattack(0, -1))
148 W_DecreaseAmmo(ammo_fuel, autocvar_g_balance_hook_primary_fuel, FALSE);
149 self.hook_state |= HOOK_FIRING;
150 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_hook_primary_animtime, w_ready);
154 if (self.BUTTON_ATCK2)
156 if (weapon_prepareattack(1, autocvar_g_balance_hook_secondary_refire))
159 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_hook_secondary_animtime, w_ready);
165 // if hooked, no bombs, and increase the timer
166 self.hook_refire = max(self.hook_refire, time + autocvar_g_balance_hook_primary_refire * W_WeaponRateFactor());
168 // hook also inhibits health regeneration, but only for 1 second
169 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
170 self.pauseregen_finished = max(self.pauseregen_finished, time + autocvar_g_balance_pause_fuel_regen);
173 if(self.hook && self.hook.state == 1)
175 hooked_time_max = autocvar_g_balance_hook_primary_hooked_time_max;
176 if (hooked_time_max > 0)
178 if ( time > self.hook_time_hooked + hooked_time_max )
179 self.hook_state |= HOOK_REMOVING;
182 hooked_fuel = autocvar_g_balance_hook_primary_hooked_fuel;
185 if ( time > self.hook_time_fueldecrease )
187 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
189 if ( self.ammo_fuel >= (time - self.hook_time_fueldecrease) * hooked_fuel )
191 W_DecreaseAmmo(ammo_fuel, (time - self.hook_time_fueldecrease) * hooked_fuel, FALSE);
192 self.hook_time_fueldecrease = time;
193 // decrease next frame again
198 self.hook_state |= HOOK_REMOVING;
199 W_SwitchWeapon_Force(self, w_getbestweapon(self));
207 self.hook_time_hooked = time;
208 self.hook_time_fueldecrease = time + autocvar_g_balance_hook_primary_hooked_time_free;
211 if (self.BUTTON_CROUCH)
213 self.hook_state &~= HOOK_PULLING;
214 if (self.BUTTON_ATCK || (!(self.items & IT_JETPACK) && self.BUTTON_HOOK))
215 self.hook_state &~= HOOK_RELEASING;
217 self.hook_state |= HOOK_RELEASING;
221 self.hook_state |= HOOK_PULLING;
222 self.hook_state &~= HOOK_RELEASING;
224 if (self.BUTTON_ATCK || (!(self.items & IT_JETPACK) && self.BUTTON_HOOK))
228 self.hook_state |= HOOK_WAITING_FOR_RELEASE;
232 self.hook_state |= HOOK_REMOVING;
233 self.hook_state &~= HOOK_WAITING_FOR_RELEASE;
237 else if (req == WR_PRECACHE)
239 precache_model ("models/weapons/g_hookgun.md3");
240 precache_model ("models/weapons/v_hookgun.md3");
241 precache_model ("models/weapons/h_hookgun.iqm");
242 precache_sound ("weapons/hook_impact.wav"); // done by g_hook.qc
243 precache_sound ("weapons/hook_fire.wav");
244 precache_sound ("weapons/hookbomb_fire.wav");
246 else if (req == WR_SETUP)
248 weapon_setup(WEP_HOOK);
249 self.current_ammo = ammo_fuel;
250 self.hook_state &~= HOOK_WAITING_FOR_RELEASE;
252 else if (req == WR_CHECKAMMO1)
255 return self.ammo_fuel > 0;
257 return self.ammo_fuel >= autocvar_g_balance_hook_primary_fuel;
259 else if (req == WR_CHECKAMMO2)
261 return self.ammo_cells >= autocvar_g_balance_hook_secondary_ammo;
263 else if (req == WR_RESETPLAYER)
265 self.hook_refire = time;
271 float w_hook(float req)
273 if(req == WR_IMPACTEFFECT)
276 org2 = w_org + w_backoff * 2;
277 pointparticles(particleeffectnum("hookbomb_explode"), org2, '0 0 0', 1);
279 sound(self, CH_SHOTS, "weapons/hookbomb_impact.wav", VOL_BASE, ATTN_NORM);
281 else if(req == WR_PRECACHE)
283 precache_sound("weapons/hookbomb_impact.wav");
285 else if (req == WR_SUICIDEMESSAGE)
286 w_deathtypestring = _("%s did the impossible");
287 else if (req == WR_KILLMESSAGE)
288 w_deathtypestring = _("%s was caught in %s's hook gravity bomb");