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;
62 void spawnfunc_weapon_hook(void)
64 if(g_grappling_hook) // offhand hook
66 startitem_failed = true;
70 weapon_defaultspawnfunc(WEP_HOOK.m_id);
73 void W_Hook_ExplodeThink(void)
75 float dt, dmg_remaining_next, f;
77 dt = time - self.teleport_time;
78 dmg_remaining_next = pow(bound(0, 1 - dt / self.dmg_duration, 1), self.dmg_power);
80 f = self.dmg_last - dmg_remaining_next;
81 self.dmg_last = dmg_remaining_next;
83 RadiusDamage(self, self.realowner, self.dmg * f, self.dmg_edge * f, self.dmg_radius, self.realowner, world, self.dmg_force * f, self.projectiledeathtype, world);
84 self.projectiledeathtype |= HITTYPE_BOUNCE;
85 //RadiusDamage(self, world, self.dmg * f, self.dmg_edge * f, self.dmg_radius, world, world, self.dmg_force * f, self.projectiledeathtype, world);
87 if(dt < self.dmg_duration)
88 self.nextthink = time + 0.05; // soon
93 void W_Hook_Explode2(void)
95 self.event_damage = func_null;
96 self.touch = func_null;
97 self.effects |= EF_NODRAW;
99 self.think = W_Hook_ExplodeThink;
100 self.nextthink = time;
101 self.dmg = WEP_CVAR_SEC(hook, damage);
102 self.dmg_edge = WEP_CVAR_SEC(hook, edgedamage);
103 self.dmg_radius = WEP_CVAR_SEC(hook, radius);
104 self.dmg_force = WEP_CVAR_SEC(hook, force);
105 self.dmg_power = WEP_CVAR_SEC(hook, power);
106 self.dmg_duration = WEP_CVAR_SEC(hook, duration);
107 self.teleport_time = time;
109 self.movetype = MOVETYPE_NONE;
112 void W_Hook_Damage(entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
117 if(!W_CheckProjectileDamage(inflictor.realowner, self.realowner, deathtype, -1)) // no exceptions
118 return; // g_projectiles_damage says to halt
120 self.health = self.health - damage;
123 W_PrepareExplosionByDamage(self.realowner, W_Hook_Explode2);
126 void W_Hook_Touch2(void)
132 void W_Hook_Attack2(void)
136 //W_DecreaseAmmo(WEP_CVAR_SEC(hook, ammo)); // WEAPONTODO: Figure out how to handle ammo with hook secondary (gravitybomb)
137 W_SetupShot(self, false, 4, W_Sound("hookbomb_fire"), CH_WEAPON_A, WEP_CVAR_SEC(hook, damage));
140 gren.owner = gren.realowner = self;
141 gren.classname = "hookbomb";
142 gren.bot_dodge = true;
143 gren.bot_dodgerating = WEP_CVAR_SEC(hook, damage);
144 gren.movetype = MOVETYPE_TOSS;
145 PROJECTILE_MAKETRIGGER(gren);
146 gren.projectiledeathtype = WEP_HOOK.m_id | HITTYPE_SECONDARY;
147 setorigin(gren, w_shotorg);
148 setsize(gren, '0 0 0', '0 0 0');
150 gren.nextthink = time + WEP_CVAR_SEC(hook, lifetime);
151 gren.think = adaptor_think2use_hittype_splash;
152 gren.use = W_Hook_Explode2;
153 gren.touch = W_Hook_Touch2;
155 gren.takedamage = DAMAGE_YES;
156 gren.health = WEP_CVAR_SEC(hook, health);
157 gren.damageforcescale = WEP_CVAR_SEC(hook, damageforcescale);
158 gren.event_damage = W_Hook_Damage;
159 gren.damagedbycontents = true;
160 gren.missile_flags = MIF_SPLASH | MIF_ARC;
162 gren.velocity = '0 0 1' * WEP_CVAR_SEC(hook, speed);
163 if(autocvar_g_projectiles_newton_style)
164 gren.velocity = gren.velocity + self.velocity;
166 gren.gravity = WEP_CVAR_SEC(hook, gravity);
167 //W_SetupProjVelocity_Basic(gren); // just falling down!
169 gren.angles = '0 0 0';
170 gren.flags = FL_PROJECTILE;
172 CSQCProjectile(gren, true, PROJECTILE_HOOKBOMB, true);
174 MUTATOR_CALLHOOK(EditProjectile, self, gren);
179 float hooked_time_max, hooked_fuel;
185 // no bot AI for hook (yet?)
190 if(self.BUTTON_ATCK || self.BUTTON_HOOK)
193 if(!(self.hook_state & HOOK_WAITING_FOR_RELEASE))
194 if(!(self.hook_state & HOOK_FIRING))
195 if(time > self.hook_refire)
196 if(weapon_prepareattack(0, -1))
198 W_DecreaseAmmo(WEP_CVAR_PRI(hook, ammo));
199 self.hook_state |= HOOK_FIRING;
200 weapon_thinkf(WFRAME_FIRE1, WEP_CVAR_PRI(hook, animtime), w_ready);
204 if(self.BUTTON_ATCK2)
206 if(weapon_prepareattack(1, WEP_CVAR_SEC(hook, refire)))
209 weapon_thinkf(WFRAME_FIRE2, WEP_CVAR_SEC(hook, animtime), w_ready);
215 // if hooked, no bombs, and increase the timer
216 self.hook_refire = max(self.hook_refire, time + WEP_CVAR_PRI(hook, refire) * W_WeaponRateFactor());
218 // hook also inhibits health regeneration, but only for 1 second
219 if(!(self.items & IT_UNLIMITED_WEAPON_AMMO))
220 self.pauseregen_finished = max(self.pauseregen_finished, time + autocvar_g_balance_pause_fuel_regen);
223 if(self.hook && self.hook.state == 1)
225 hooked_time_max = WEP_CVAR_PRI(hook, hooked_time_max);
226 if(hooked_time_max > 0)
228 if( time > self.hook_time_hooked + hooked_time_max )
229 self.hook_state |= HOOK_REMOVING;
232 hooked_fuel = WEP_CVAR_PRI(hook, hooked_ammo);
235 if( time > self.hook_time_fueldecrease )
237 if(!(self.items & IT_UNLIMITED_WEAPON_AMMO))
239 if( self.ammo_fuel >= (time - self.hook_time_fueldecrease) * hooked_fuel )
241 W_DecreaseAmmo((time - self.hook_time_fueldecrease) * hooked_fuel);
242 self.hook_time_fueldecrease = time;
243 // decrease next frame again
248 self.hook_state |= HOOK_REMOVING;
249 W_SwitchWeapon_Force(self, w_getbestweapon(self));
257 self.hook_time_hooked = time;
258 self.hook_time_fueldecrease = time + WEP_CVAR_PRI(hook, hooked_time_free);
261 if(self.BUTTON_CROUCH)
263 self.hook_state &= ~HOOK_PULLING;
264 if(self.BUTTON_ATCK || self.BUTTON_HOOK)
265 self.hook_state &= ~HOOK_RELEASING;
267 self.hook_state |= HOOK_RELEASING;
271 self.hook_state |= HOOK_PULLING;
272 self.hook_state &= ~HOOK_RELEASING;
274 if(self.BUTTON_ATCK || self.BUTTON_HOOK)
278 self.hook_state |= HOOK_WAITING_FOR_RELEASE;
282 self.hook_state |= HOOK_REMOVING;
283 self.hook_state &= ~HOOK_WAITING_FOR_RELEASE;
291 precache_model(W_Model("g_hookgun.md3"));
292 precache_model(W_Model("v_hookgun.md3"));
293 precache_model(W_Model("h_hookgun.iqm"));
294 precache_sound(W_Sound("hook_impact")); // done by g_hook.qc
295 precache_sound(W_Sound("hook_fire"));
296 precache_sound(W_Sound("hookbomb_fire"));
297 HOOK_SETTINGS(WEP_SKIP_CVAR, WEP_SET_PROP);
302 self.hook_state &= ~HOOK_WAITING_FOR_RELEASE;
308 return self.ammo_fuel > 0;
310 return self.ammo_fuel >= WEP_CVAR_PRI(hook, ammo);
314 // infinite ammo for now
315 return true; // self.ammo_cells >= WEP_CVAR_SEC(hook, ammo); // WEAPONTODO: see above
319 HOOK_SETTINGS(WEP_CONFIG_WRITE_CVARS, WEP_CONFIG_WRITE_PROPS);
324 self.hook_refire = time;
327 case WR_SUICIDEMESSAGE:
333 return WEAPON_HOOK_MURDER;
344 case WR_IMPACTEFFECT:
347 org2 = w_org + w_backoff * 2;
348 pointparticles(particleeffectnum(EFFECT_HOOK_EXPLODE), org2, '0 0 0', 1);
350 sound(self, CH_SHOTS, W_Sound("hookbomb_impact"), VOL_BASE, ATTN_NORM);
356 precache_sound(W_Sound("hookbomb_impact"));
361 // no weapon specific image for this weapon