5 /* ammotype */ ammo_fuel,
7 /* flags */ WEP_FLAG_CANCLIMB | WEP_TYPE_SPLASH,
10 /* modelname */ "hookgun",
11 /* simplemdl */ "foobar",
12 /* crosshair */ "gfx/crosshairhook 0.5",
13 /* wepimg */ "weaponhook",
15 /* wepname */ _("Grappling Hook")
18 #define HOOK_SETTINGS(w_cvar,w_prop) HOOK_SETTINGS_LIST(w_cvar, w_prop, HOOK, hook)
19 #define HOOK_SETTINGS_LIST(w_cvar,w_prop,id,sn) \
20 w_cvar(id, sn, BOTH, animtime) \
21 w_cvar(id, sn, BOTH, refire) \
22 w_cvar(id, sn, PRI, ammo) \
23 w_cvar(id, sn, PRI, hooked_ammo) \
24 w_cvar(id, sn, PRI, hooked_time_free) \
25 w_cvar(id, sn, PRI, hooked_time_max) \
26 w_cvar(id, sn, SEC, damage) \
27 w_cvar(id, sn, SEC, duration) \
28 w_cvar(id, sn, SEC, edgedamage) \
29 w_cvar(id, sn, SEC, force) \
30 w_cvar(id, sn, SEC, gravity) \
31 w_cvar(id, sn, SEC, lifetime) \
32 w_cvar(id, sn, SEC, power) \
33 w_cvar(id, sn, SEC, radius) \
34 w_cvar(id, sn, SEC, speed) \
35 w_cvar(id, sn, SEC, health) \
36 w_cvar(id, sn, SEC, damageforcescale) \
37 w_prop(id, sn, float, switchdelay_raise, switchdelay_raise) \
38 w_prop(id, sn, float, switchdelay_drop, switchdelay_drop) \
39 w_prop(id, sn, string, weaponreplace, weaponreplace) \
40 w_prop(id, sn, float, weaponstart, weaponstart) \
41 w_prop(id, sn, float, weaponstartoverride, weaponstartoverride) \
42 w_prop(id, sn, float, weaponthrowable, weaponthrowable)
45 HOOK_SETTINGS(WEP_ADD_CVAR, WEP_ADD_PROP)
55 .float hook_time_hooked;
56 .float hook_time_fueldecrease;
61 void spawnfunc_weapon_hook(void)
63 if(g_grappling_hook) // offhand hook
65 startitem_failed = true;
69 weapon_defaultspawnfunc(WEP_HOOK);
72 void W_Hook_ExplodeThink(void)
74 float dt, dmg_remaining_next, f;
76 dt = time - self.teleport_time;
77 dmg_remaining_next = pow(bound(0, 1 - dt / self.dmg_duration, 1), self.dmg_power);
79 f = self.dmg_last - dmg_remaining_next;
80 self.dmg_last = dmg_remaining_next;
82 RadiusDamage(self, self.realowner, self.dmg * f, self.dmg_edge * f, self.dmg_radius, self.realowner, world, self.dmg_force * f, self.projectiledeathtype, world);
83 self.projectiledeathtype |= HITTYPE_BOUNCE;
84 //RadiusDamage(self, world, self.dmg * f, self.dmg_edge * f, self.dmg_radius, world, world, self.dmg_force * f, self.projectiledeathtype, world);
86 if(dt < self.dmg_duration)
87 self.nextthink = time + 0.05; // soon
92 void W_Hook_Explode2(void)
94 self.event_damage = func_null;
95 self.touch = func_null;
96 self.effects |= EF_NODRAW;
98 self.think = W_Hook_ExplodeThink;
99 self.nextthink = time;
100 self.dmg = WEP_CVAR_SEC(hook, damage);
101 self.dmg_edge = WEP_CVAR_SEC(hook, edgedamage);
102 self.dmg_radius = WEP_CVAR_SEC(hook, radius);
103 self.dmg_force = WEP_CVAR_SEC(hook, force);
104 self.dmg_power = WEP_CVAR_SEC(hook, power);
105 self.dmg_duration = WEP_CVAR_SEC(hook, duration);
106 self.teleport_time = time;
108 self.movetype = MOVETYPE_NONE;
111 void W_Hook_Damage(entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
116 if(!W_CheckProjectileDamage(inflictor.realowner, self.realowner, deathtype, -1)) // no exceptions
117 return; // g_projectiles_damage says to halt
119 self.health = self.health - damage;
122 W_PrepareExplosionByDamage(self.realowner, W_Hook_Explode2);
125 void W_Hook_Touch2(void)
131 void W_Hook_Attack2(void)
135 //W_DecreaseAmmo(WEP_CVAR_SEC(hook, ammo)); // WEAPONTODO: Figure out how to handle ammo with hook secondary (gravitybomb)
136 W_SetupShot(self, false, 4, "weapons/hookbomb_fire.wav", CH_WEAPON_A, WEP_CVAR_SEC(hook, damage));
139 gren.owner = gren.realowner = self;
140 gren.classname = "hookbomb";
141 gren.bot_dodge = true;
142 gren.bot_dodgerating = WEP_CVAR_SEC(hook, damage);
143 gren.movetype = MOVETYPE_TOSS;
144 PROJECTILE_MAKETRIGGER(gren);
145 gren.projectiledeathtype = WEP_HOOK | HITTYPE_SECONDARY;
146 setorigin(gren, w_shotorg);
147 setsize(gren, '0 0 0', '0 0 0');
149 gren.nextthink = time + WEP_CVAR_SEC(hook, lifetime);
150 gren.think = adaptor_think2use_hittype_splash;
151 gren.use = W_Hook_Explode2;
152 gren.touch = W_Hook_Touch2;
154 gren.takedamage = DAMAGE_YES;
155 gren.health = WEP_CVAR_SEC(hook, health);
156 gren.damageforcescale = WEP_CVAR_SEC(hook, damageforcescale);
157 gren.event_damage = W_Hook_Damage;
158 gren.damagedbycontents = true;
159 gren.missile_flags = MIF_SPLASH | MIF_ARC;
161 gren.velocity = '0 0 1' * WEP_CVAR_SEC(hook, speed);
162 if(autocvar_g_projectiles_newton_style)
163 gren.velocity = gren.velocity + self.velocity;
165 gren.gravity = WEP_CVAR_SEC(hook, gravity);
166 //W_SetupProjVelocity_Basic(gren); // just falling down!
168 gren.angles = '0 0 0';
169 gren.flags = FL_PROJECTILE;
171 CSQCProjectile(gren, true, PROJECTILE_HOOKBOMB, true);
173 MUTATOR_CALLHOOK(EditProjectile, self, gren);
178 float hooked_time_max, hooked_fuel;
184 // no bot AI for hook (yet?)
189 if(self.BUTTON_ATCK || self.BUTTON_HOOK)
192 if(!(self.hook_state & HOOK_WAITING_FOR_RELEASE))
193 if(!(self.hook_state & HOOK_FIRING))
194 if(time > self.hook_refire)
195 if(weapon_prepareattack(0, -1))
197 W_DecreaseAmmo(WEP_CVAR_PRI(hook, ammo));
198 self.hook_state |= HOOK_FIRING;
199 weapon_thinkf(WFRAME_FIRE1, WEP_CVAR_PRI(hook, animtime), w_ready);
203 if(self.BUTTON_ATCK2)
205 if(weapon_prepareattack(1, WEP_CVAR_SEC(hook, refire)))
208 weapon_thinkf(WFRAME_FIRE2, WEP_CVAR_SEC(hook, animtime), w_ready);
214 // if hooked, no bombs, and increase the timer
215 self.hook_refire = max(self.hook_refire, time + WEP_CVAR_PRI(hook, refire) * W_WeaponRateFactor());
217 // hook also inhibits health regeneration, but only for 1 second
218 if(!(self.items & IT_UNLIMITED_WEAPON_AMMO))
219 self.pauseregen_finished = max(self.pauseregen_finished, time + autocvar_g_balance_pause_fuel_regen);
222 if(self.hook && self.hook.state == 1)
224 hooked_time_max = WEP_CVAR_PRI(hook, hooked_time_max);
225 if(hooked_time_max > 0)
227 if( time > self.hook_time_hooked + hooked_time_max )
228 self.hook_state |= HOOK_REMOVING;
231 hooked_fuel = WEP_CVAR_PRI(hook, hooked_ammo);
234 if( time > self.hook_time_fueldecrease )
236 if(!(self.items & IT_UNLIMITED_WEAPON_AMMO))
238 if( self.ammo_fuel >= (time - self.hook_time_fueldecrease) * hooked_fuel )
240 W_DecreaseAmmo((time - self.hook_time_fueldecrease) * hooked_fuel);
241 self.hook_time_fueldecrease = time;
242 // decrease next frame again
247 self.hook_state |= HOOK_REMOVING;
248 W_SwitchWeapon_Force(self, w_getbestweapon(self));
256 self.hook_time_hooked = time;
257 self.hook_time_fueldecrease = time + WEP_CVAR_PRI(hook, hooked_time_free);
260 if(self.BUTTON_CROUCH)
262 self.hook_state &= ~HOOK_PULLING;
263 if(self.BUTTON_ATCK || self.BUTTON_HOOK)
264 self.hook_state &= ~HOOK_RELEASING;
266 self.hook_state |= HOOK_RELEASING;
270 self.hook_state |= HOOK_PULLING;
271 self.hook_state &= ~HOOK_RELEASING;
273 if(self.BUTTON_ATCK || self.BUTTON_HOOK)
277 self.hook_state |= HOOK_WAITING_FOR_RELEASE;
281 self.hook_state |= HOOK_REMOVING;
282 self.hook_state &= ~HOOK_WAITING_FOR_RELEASE;
290 precache_model("models/weapons/g_hookgun.md3");
291 precache_model("models/weapons/v_hookgun.md3");
292 precache_model("models/weapons/h_hookgun.iqm");
293 precache_sound("weapons/hook_impact.wav"); // done by g_hook.qc
294 precache_sound("weapons/hook_fire.wav");
295 precache_sound("weapons/hookbomb_fire.wav");
296 HOOK_SETTINGS(WEP_SKIP_CVAR, WEP_SET_PROP);
301 self.hook_state &= ~HOOK_WAITING_FOR_RELEASE;
307 return self.ammo_fuel > 0;
309 return self.ammo_fuel >= WEP_CVAR_PRI(hook, ammo);
313 // infinite ammo for now
314 return true; // self.ammo_cells >= WEP_CVAR_SEC(hook, ammo); // WEAPONTODO: see above
318 HOOK_SETTINGS(WEP_CONFIG_WRITE_CVARS, WEP_CONFIG_WRITE_PROPS);
323 self.hook_refire = time;
326 case WR_SUICIDEMESSAGE:
332 return WEAPON_HOOK_MURDER;
343 case WR_IMPACTEFFECT:
346 org2 = w_org + w_backoff * 2;
347 pointparticles(particleeffectnum("hookbomb_explode"), org2, '0 0 0', 1);
349 sound(self, CH_SHOTS, "weapons/hookbomb_impact.wav", VOL_BASE, ATTN_NORM);
355 precache_sound("weapons/hookbomb_impact.wav");
360 // no weapon specific image for this weapon