5 /* ammotype */ ammo_fuel,
7 /* flags */ WEP_FLAG_CANCLIMB | WEP_TYPE_SPLASH,
10 /* model */ "hookgun",
12 /* fullname */ _("Grappling Hook")
15 #define HOOK_SETTINGS(w_cvar,w_prop) HOOK_SETTINGS_LIST(w_cvar, w_prop, HOOK, hook)
16 #define HOOK_SETTINGS_LIST(w_cvar,w_prop,id,sn) \
17 w_cvar(id, sn, BOTH, animtime) \
18 w_cvar(id, sn, BOTH, refire) \
19 w_cvar(id, sn, PRI, ammo) \
20 w_cvar(id, sn, PRI, hooked_ammo) \
21 w_cvar(id, sn, PRI, hooked_time_free) \
22 w_cvar(id, sn, PRI, hooked_time_max) \
23 w_cvar(id, sn, SEC, damage) \
24 w_cvar(id, sn, SEC, duration) \
25 w_cvar(id, sn, SEC, edgedamage) \
26 w_cvar(id, sn, SEC, force) \
27 w_cvar(id, sn, SEC, gravity) \
28 w_cvar(id, sn, SEC, lifetime) \
29 w_cvar(id, sn, SEC, power) \
30 w_cvar(id, sn, SEC, radius) \
31 w_cvar(id, sn, SEC, speed) \
32 w_cvar(id, sn, SEC, health) \
33 w_cvar(id, sn, SEC, damageforcescale) \
34 w_prop(id, sn, float, switchdelay_raise, switchdelay_raise) \
35 w_prop(id, sn, float, switchdelay_drop, switchdelay_drop) \
36 w_prop(id, sn, string, weaponreplace, weaponreplace) \
37 w_prop(id, sn, float, weaponstart, weaponstart) \
38 w_prop(id, sn, float, weaponstartoverride, weaponstartoverride)
41 HOOK_SETTINGS(WEP_ADD_CVAR, WEP_ADD_PROP)
51 .float hook_time_hooked;
52 .float hook_time_fueldecrease;
57 void spawnfunc_weapon_hook()
59 if(g_grappling_hook) // offhand hook
61 startitem_failed = TRUE;
65 weapon_defaultspawnfunc(WEP_HOOK);
68 void W_Hook_ExplodeThink (void)
70 float dt, dmg_remaining_next, f;
72 dt = time - self.teleport_time;
73 dmg_remaining_next = pow(bound(0, 1 - dt / self.dmg_duration, 1), self.dmg_power);
75 f = self.dmg_last - dmg_remaining_next;
76 self.dmg_last = dmg_remaining_next;
78 RadiusDamage (self, self.realowner, self.dmg * f, self.dmg_edge * f, self.dmg_radius, self.realowner, world, self.dmg_force * f, self.projectiledeathtype, world);
79 self.projectiledeathtype |= HITTYPE_BOUNCE;
80 //RadiusDamage (self, world, self.dmg * f, self.dmg_edge * f, self.dmg_radius, world, world, self.dmg_force * f, self.projectiledeathtype, world);
82 if(dt < self.dmg_duration)
83 self.nextthink = time + 0.05; // soon
88 void W_Hook_Explode2 (void)
90 self.event_damage = func_null;
91 self.touch = func_null;
92 self.effects |= EF_NODRAW;
94 self.think = W_Hook_ExplodeThink;
95 self.nextthink = time;
96 self.dmg = WEP_CVAR_SEC(hook, damage);
97 self.dmg_edge = WEP_CVAR_SEC(hook, edgedamage);
98 self.dmg_radius = WEP_CVAR_SEC(hook, radius);
99 self.dmg_force = WEP_CVAR_SEC(hook, force);
100 self.dmg_power = WEP_CVAR_SEC(hook, power);
101 self.dmg_duration = WEP_CVAR_SEC(hook, duration);
102 self.teleport_time = time;
104 self.movetype = MOVETYPE_NONE;
107 void W_Hook_Damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
109 if (self.health <= 0)
112 if (!W_CheckProjectileDamage(inflictor.realowner, self.realowner, deathtype, -1)) // no exceptions
113 return; // g_projectiles_damage says to halt
115 self.health = self.health - damage;
117 if (self.health <= 0)
118 W_PrepareExplosionByDamage(self.realowner, W_Hook_Explode2);
121 void W_Hook_Touch2 (void)
127 void W_Hook_Attack2()
131 //W_DecreaseAmmo(WEP_CVAR_SEC(hook, ammo)); // WEAPONTODO: Figure out how to handle ammo with hook secondary (gravitybomb)
132 W_SetupShot (self, FALSE, 4, "weapons/hookbomb_fire.wav", CH_WEAPON_A, WEP_CVAR_SEC(hook, damage));
135 gren.owner = gren.realowner = self;
136 gren.classname = "hookbomb";
137 gren.bot_dodge = TRUE;
138 gren.bot_dodgerating = WEP_CVAR_SEC(hook, damage);
139 gren.movetype = MOVETYPE_TOSS;
140 PROJECTILE_MAKETRIGGER(gren);
141 gren.projectiledeathtype = WEP_HOOK | HITTYPE_SECONDARY;
142 setorigin(gren, w_shotorg);
143 setsize(gren, '0 0 0', '0 0 0');
145 gren.nextthink = time + WEP_CVAR_SEC(hook, lifetime);
146 gren.think = adaptor_think2use_hittype_splash;
147 gren.use = W_Hook_Explode2;
148 gren.touch = W_Hook_Touch2;
150 gren.takedamage = DAMAGE_YES;
151 gren.health = WEP_CVAR_SEC(hook, health);
152 gren.damageforcescale = WEP_CVAR_SEC(hook, damageforcescale);
153 gren.event_damage = W_Hook_Damage;
154 gren.damagedbycontents = TRUE;
155 gren.missile_flags = MIF_SPLASH | MIF_ARC;
157 gren.velocity = '0 0 1' * WEP_CVAR_SEC(hook, speed);
158 if(autocvar_g_projectiles_newton_style)
159 gren.velocity = gren.velocity + self.velocity;
161 gren.gravity = WEP_CVAR_SEC(hook, gravity);
162 //W_SetupProjVelocity_Basic(gren); // just falling down!
164 gren.angles = '0 0 0';
165 gren.flags = FL_PROJECTILE;
167 CSQCProjectile(gren, TRUE, PROJECTILE_HOOKBOMB, TRUE);
169 other = gren; MUTATOR_CALLHOOK(EditProjectile);
172 float W_Hook(float req)
174 float hooked_time_max, hooked_fuel;
180 // no bot AI for hook (yet?)
185 if (self.BUTTON_ATCK || (!(self.items & IT_JETPACK) && self.BUTTON_HOOK))
188 if(!(self.hook_state & HOOK_WAITING_FOR_RELEASE))
189 if(!(self.hook_state & HOOK_FIRING))
190 if (time > self.hook_refire)
191 if (weapon_prepareattack(0, -1))
193 W_DecreaseAmmo(WEP_CVAR_PRI(hook, ammo));
194 self.hook_state |= HOOK_FIRING;
195 weapon_thinkf(WFRAME_FIRE1, WEP_CVAR_PRI(hook, animtime), w_ready);
199 if (self.BUTTON_ATCK2)
201 if (weapon_prepareattack(1, WEP_CVAR_SEC(hook, refire)))
204 weapon_thinkf(WFRAME_FIRE2, WEP_CVAR_SEC(hook, animtime), w_ready);
210 // if hooked, no bombs, and increase the timer
211 self.hook_refire = max(self.hook_refire, time + WEP_CVAR_PRI(hook, refire) * W_WeaponRateFactor());
213 // hook also inhibits health regeneration, but only for 1 second
214 if(!(self.items & IT_UNLIMITED_WEAPON_AMMO))
215 self.pauseregen_finished = max(self.pauseregen_finished, time + autocvar_g_balance_pause_fuel_regen);
218 if(self.hook && self.hook.state == 1)
220 hooked_time_max = WEP_CVAR_PRI(hook, hooked_time_max);
221 if (hooked_time_max > 0)
223 if ( time > self.hook_time_hooked + hooked_time_max )
224 self.hook_state |= HOOK_REMOVING;
227 hooked_fuel = WEP_CVAR_PRI(hook, hooked_ammo);
230 if ( time > self.hook_time_fueldecrease )
232 if(!(self.items & IT_UNLIMITED_WEAPON_AMMO))
234 if ( self.ammo_fuel >= (time - self.hook_time_fueldecrease) * hooked_fuel )
236 W_DecreaseAmmo((time - self.hook_time_fueldecrease) * hooked_fuel);
237 self.hook_time_fueldecrease = time;
238 // decrease next frame again
243 self.hook_state |= HOOK_REMOVING;
244 W_SwitchWeapon_Force(self, w_getbestweapon(self));
252 self.hook_time_hooked = time;
253 self.hook_time_fueldecrease = time + WEP_CVAR_PRI(hook, hooked_time_free);
256 if (self.BUTTON_CROUCH)
258 self.hook_state &= ~HOOK_PULLING;
259 if (self.BUTTON_ATCK || (!(self.items & IT_JETPACK) && self.BUTTON_HOOK))
260 self.hook_state &= ~HOOK_RELEASING;
262 self.hook_state |= HOOK_RELEASING;
266 self.hook_state |= HOOK_PULLING;
267 self.hook_state &= ~HOOK_RELEASING;
269 if (self.BUTTON_ATCK || (!(self.items & IT_JETPACK) && self.BUTTON_HOOK))
273 self.hook_state |= HOOK_WAITING_FOR_RELEASE;
277 self.hook_state |= HOOK_REMOVING;
278 self.hook_state &= ~HOOK_WAITING_FOR_RELEASE;
286 precache_model ("models/weapons/g_hookgun.md3");
287 precache_model ("models/weapons/v_hookgun.md3");
288 precache_model ("models/weapons/h_hookgun.iqm");
289 precache_sound ("weapons/hook_impact.wav"); // done by g_hook.qc
290 precache_sound ("weapons/hook_fire.wav");
291 precache_sound ("weapons/hookbomb_fire.wav");
292 HOOK_SETTINGS(WEP_SKIPCVAR, WEP_SET_PROP)
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 // infinite ammo for now
310 return TRUE; // self.ammo_cells >= WEP_CVAR_SEC(hook, ammo); // WEAPONTODO: see above
314 HOOK_SETTINGS(WEP_CONFIG_WRITE_CVARS, WEP_CONFIG_WRITE_PROPS)
319 self.hook_refire = time;
322 case WR_SUICIDEMESSAGE:
328 return WEAPON_HOOK_MURDER;
335 float W_Hook(float req)
339 case WR_IMPACTEFFECT:
342 org2 = w_org + w_backoff * 2;
343 pointparticles(particleeffectnum("hookbomb_explode"), org2, '0 0 0', 1);
345 sound(self, CH_SHOTS, "weapons/hookbomb_impact.wav", VOL_BASE, ATTN_NORM);
351 precache_sound("weapons/hookbomb_impact.wav");
356 // no weapon specific image for this weapon