5 /* ammotype */ IT_CELLS|IT_FUEL,
7 /* flags */ WEP_FLAG_CANCLIMB | WEP_TYPE_SPLASH,
10 /* shortname */ "hook",
11 /* fullname */ _("Grappling Hook")
15 void spawnfunc_weapon_hook()
17 if(g_grappling_hook) // offhand hook
19 startitem_failed = TRUE;
23 weapon_defaultspawnfunc(WEP_HOOK);
34 .float hook_time_hooked;
35 .float hook_time_fueldecrease;
37 void W_Hook_ExplodeThink (void)
39 float dt, dmg_remaining_next, f;
41 dt = time - self.teleport_time;
42 dmg_remaining_next = pow(bound(0, 1 - dt / self.dmg_duration, 1), self.dmg_power);
44 f = self.dmg_last - dmg_remaining_next;
45 self.dmg_last = dmg_remaining_next;
47 RadiusDamage (self, self.realowner, self.dmg * f, self.dmg_edge * f, self.dmg_radius, self.realowner, world, self.dmg_force * f, self.projectiledeathtype, world);
48 self.projectiledeathtype |= HITTYPE_BOUNCE;
49 //RadiusDamage (self, world, self.dmg * f, self.dmg_edge * f, self.dmg_radius, world, world, self.dmg_force * f, self.projectiledeathtype, world);
51 if(dt < self.dmg_duration)
52 self.nextthink = time + 0.05; // soon
57 void W_Hook_Explode2 (void)
59 self.event_damage = func_null;
60 self.touch = func_null;
61 self.effects |= EF_NODRAW;
63 self.think = W_Hook_ExplodeThink;
64 self.nextthink = time;
65 self.dmg = autocvar_g_balance_hook_secondary_damage;
66 self.dmg_edge = autocvar_g_balance_hook_secondary_edgedamage;
67 self.dmg_radius = autocvar_g_balance_hook_secondary_radius;
68 self.dmg_force = autocvar_g_balance_hook_secondary_force;
69 self.dmg_power = autocvar_g_balance_hook_secondary_power;
70 self.dmg_duration = autocvar_g_balance_hook_secondary_duration;
71 self.teleport_time = time;
73 self.movetype = MOVETYPE_NONE;
76 void W_Hook_Damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
81 if (!W_CheckProjectileDamage(inflictor.realowner, self.realowner, deathtype, -1)) // no exceptions
82 return; // g_projectiles_damage says to halt
84 self.health = self.health - damage;
87 W_PrepareExplosionByDamage(self.realowner, W_Hook_Explode2);
90 void W_Hook_Touch2 (void)
100 W_DecreaseAmmo(ammo_cells, autocvar_g_balance_hook_secondary_ammo, FALSE);
101 W_SetupShot (self, FALSE, 4, "weapons/hookbomb_fire.wav", CH_WEAPON_A, autocvar_g_balance_hook_secondary_damage);
104 gren.owner = gren.realowner = self;
105 gren.classname = "hookbomb";
106 gren.bot_dodge = TRUE;
107 gren.bot_dodgerating = autocvar_g_balance_hook_secondary_damage;
108 gren.movetype = MOVETYPE_TOSS;
109 PROJECTILE_MAKETRIGGER(gren);
110 gren.projectiledeathtype = WEP_HOOK | HITTYPE_SECONDARY;
111 setorigin(gren, w_shotorg);
112 setsize(gren, '0 0 0', '0 0 0');
114 gren.nextthink = time + autocvar_g_balance_hook_secondary_lifetime;
115 gren.think = adaptor_think2use_hittype_splash;
116 gren.use = W_Hook_Explode2;
117 gren.touch = W_Hook_Touch2;
119 gren.takedamage = DAMAGE_YES;
120 gren.health = autocvar_g_balance_hook_secondary_health;
121 gren.damageforcescale = autocvar_g_balance_hook_secondary_damageforcescale;
122 gren.event_damage = W_Hook_Damage;
123 gren.damagedbycontents = TRUE;
124 gren.missile_flags = MIF_SPLASH | MIF_ARC;
126 gren.velocity = '0 0 1' * autocvar_g_balance_hook_secondary_speed;
127 if(autocvar_g_projectiles_newton_style)
128 gren.velocity = gren.velocity + self.velocity;
130 gren.gravity = autocvar_g_balance_hook_secondary_gravity;
131 //W_SetupProjectileVelocity(gren); // just falling down!
133 gren.angles = '0 0 0';
134 gren.flags = FL_PROJECTILE;
136 CSQCProjectile(gren, TRUE, PROJECTILE_HOOKBOMB, TRUE);
138 other = gren; MUTATOR_CALLHOOK(EditProjectile);
141 float w_hook(float req)
143 float hooked_time_max, hooked_fuel;
149 // no bot AI for hook (yet?)
154 if (self.BUTTON_ATCK || (!(self.items & IT_JETPACK) && self.BUTTON_HOOK))
157 if not(self.hook_state & HOOK_WAITING_FOR_RELEASE)
158 if not(self.hook_state & HOOK_FIRING)
159 if (time > self.hook_refire)
160 if (weapon_prepareattack(0, -1))
162 W_DecreaseAmmo(ammo_fuel, autocvar_g_balance_hook_primary_fuel, FALSE);
163 self.hook_state |= HOOK_FIRING;
164 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_hook_primary_animtime, w_ready);
168 if (self.BUTTON_ATCK2)
170 if (weapon_prepareattack(1, autocvar_g_balance_hook_secondary_refire))
173 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_hook_secondary_animtime, w_ready);
179 // if hooked, no bombs, and increase the timer
180 self.hook_refire = max(self.hook_refire, time + autocvar_g_balance_hook_primary_refire * W_WeaponRateFactor());
182 // hook also inhibits health regeneration, but only for 1 second
183 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
184 self.pauseregen_finished = max(self.pauseregen_finished, time + autocvar_g_balance_pause_fuel_regen);
187 if(self.hook && self.hook.state == 1)
189 hooked_time_max = autocvar_g_balance_hook_primary_hooked_time_max;
190 if (hooked_time_max > 0)
192 if ( time > self.hook_time_hooked + hooked_time_max )
193 self.hook_state |= HOOK_REMOVING;
196 hooked_fuel = autocvar_g_balance_hook_primary_hooked_fuel;
199 if ( time > self.hook_time_fueldecrease )
201 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
203 if ( self.ammo_fuel >= (time - self.hook_time_fueldecrease) * hooked_fuel )
205 W_DecreaseAmmo(ammo_fuel, (time - self.hook_time_fueldecrease) * hooked_fuel, FALSE);
206 self.hook_time_fueldecrease = time;
207 // decrease next frame again
212 self.hook_state |= HOOK_REMOVING;
213 W_SwitchWeapon_Force(self, w_getbestweapon(self));
221 self.hook_time_hooked = time;
222 self.hook_time_fueldecrease = time + autocvar_g_balance_hook_primary_hooked_time_free;
225 if (self.BUTTON_CROUCH)
227 self.hook_state &~= HOOK_PULLING;
228 if (self.BUTTON_ATCK || (!(self.items & IT_JETPACK) && self.BUTTON_HOOK))
229 self.hook_state &~= HOOK_RELEASING;
231 self.hook_state |= HOOK_RELEASING;
235 self.hook_state |= HOOK_PULLING;
236 self.hook_state &~= HOOK_RELEASING;
238 if (self.BUTTON_ATCK || (!(self.items & IT_JETPACK) && self.BUTTON_HOOK))
242 self.hook_state |= HOOK_WAITING_FOR_RELEASE;
246 self.hook_state |= HOOK_REMOVING;
247 self.hook_state &~= HOOK_WAITING_FOR_RELEASE;
255 precache_model ("models/weapons/g_hookgun.md3");
256 precache_model ("models/weapons/v_hookgun.md3");
257 precache_model ("models/weapons/h_hookgun.iqm");
258 precache_sound ("weapons/hook_impact.wav"); // done by g_hook.qc
259 precache_sound ("weapons/hook_fire.wav");
260 precache_sound ("weapons/hookbomb_fire.wav");
265 weapon_setup(WEP_HOOK);
266 self.current_ammo = ammo_fuel;
267 self.hook_state &~= HOOK_WAITING_FOR_RELEASE;
273 return self.ammo_fuel > 0;
275 return self.ammo_fuel >= autocvar_g_balance_hook_primary_fuel;
279 return self.ammo_cells >= autocvar_g_balance_hook_secondary_ammo;
283 self.hook_refire = time;
286 case WR_SUICIDEMESSAGE:
292 return WEAPON_HOOK_MURDER;
299 float w_hook(float req)
303 case WR_IMPACTEFFECT:
306 org2 = w_org + w_backoff * 2;
307 pointparticles(particleeffectnum("hookbomb_explode"), org2, '0 0 0', 1);
309 sound(self, CH_SHOTS, "weapons/hookbomb_impact.wav", VOL_BASE, ATTN_NORM);
315 precache_sound("weapons/hookbomb_impact.wav");