3 /* ammotype */ ATTRIB(Hook, ammo_field, .int, ammo_fuel)
4 /* impulse */ ATTRIB(Hook, impulse, int, 0)
5 /* flags */ ATTRIB(Hook, spawnflags, int, WEP_FLAG_CANCLIMB | WEP_TYPE_SPLASH);
6 /* rating */ ATTRIB(Hook, bot_pickupbasevalue, float, 0);
7 /* color */ ATTRIB(Hook, wpcolor, vector, '0 0.5 0');
8 /* modelname */ ATTRIB(Hook, mdl, string, "hookgun");
10 /* model */ ATTRIB(Hook, m_model, Model, MDL_HOOK_ITEM);
12 /* crosshair */ ATTRIB(Hook, w_crosshair, string, "gfx/crosshairhook");
13 /* crosshair */ ATTRIB(Hook, w_crosshair_size, float, 0.5);
14 /* wepimg */ ATTRIB(Hook, model2, string, "weaponhook");
15 /* refname */ ATTRIB(Hook, netname, string, "hook");
16 /* wepname */ ATTRIB(Hook, message, string, _("Grappling Hook"));
18 REGISTER_WEAPON(HOOK, NEW(Hook));
20 CLASS(OffhandHook, OffhandWeapon)
21 METHOD(OffhandHook, offhand_think, void(OffhandHook this, entity player, bool key_pressed))
23 Weapon wep = WEP_HOOK;
24 WITH(entity, self, player, wep.wr_think(wep, self, key_pressed, false));
27 OffhandHook OFFHAND_HOOK; STATIC_INIT(OFFHAND_HOOK) { OFFHAND_HOOK = NEW(OffhandHook); }
29 #define HOOK_SETTINGS(w_cvar,w_prop) HOOK_SETTINGS_LIST(w_cvar, w_prop, HOOK, hook)
30 #define HOOK_SETTINGS_LIST(w_cvar,w_prop,id,sn) \
31 w_cvar(id, sn, BOTH, animtime) \
32 w_cvar(id, sn, BOTH, refire) \
33 w_cvar(id, sn, PRI, ammo) \
34 w_cvar(id, sn, PRI, hooked_ammo) \
35 w_cvar(id, sn, PRI, hooked_time_free) \
36 w_cvar(id, sn, PRI, hooked_time_max) \
37 w_cvar(id, sn, SEC, damage) \
38 w_cvar(id, sn, SEC, duration) \
39 w_cvar(id, sn, SEC, edgedamage) \
40 w_cvar(id, sn, SEC, force) \
41 w_cvar(id, sn, SEC, gravity) \
42 w_cvar(id, sn, SEC, lifetime) \
43 w_cvar(id, sn, SEC, power) \
44 w_cvar(id, sn, SEC, radius) \
45 w_cvar(id, sn, SEC, speed) \
46 w_cvar(id, sn, SEC, health) \
47 w_cvar(id, sn, SEC, damageforcescale) \
48 w_prop(id, sn, float, switchdelay_raise, switchdelay_raise) \
49 w_prop(id, sn, float, switchdelay_drop, switchdelay_drop) \
50 w_prop(id, sn, string, weaponreplace, weaponreplace) \
51 w_prop(id, sn, float, weaponstart, weaponstart) \
52 w_prop(id, sn, float, weaponstartoverride, weaponstartoverride) \
53 w_prop(id, sn, float, weaponthrowable, weaponthrowable)
56 HOOK_SETTINGS(WEP_ADD_CVAR, WEP_ADD_PROP)
66 .float hook_time_hooked;
67 .float hook_time_fueldecrease;
73 spawnfunc(weapon_hook) { weapon_defaultspawnfunc(WEP_HOOK.m_id); }
75 void W_Hook_ExplodeThink(void)
77 float dt, dmg_remaining_next, f;
79 dt = time - self.teleport_time;
80 dmg_remaining_next = pow(bound(0, 1 - dt / self.dmg_duration, 1), self.dmg_power);
82 f = self.dmg_last - dmg_remaining_next;
83 self.dmg_last = dmg_remaining_next;
85 RadiusDamage(self, self.realowner, self.dmg * f, self.dmg_edge * f, self.dmg_radius, self.realowner, world, self.dmg_force * f, self.projectiledeathtype, world);
86 self.projectiledeathtype |= HITTYPE_BOUNCE;
87 //RadiusDamage(self, world, self.dmg * f, self.dmg_edge * f, self.dmg_radius, world, world, self.dmg_force * f, self.projectiledeathtype, world);
89 if(dt < self.dmg_duration)
90 self.nextthink = time + 0.05; // soon
95 void W_Hook_Explode2(void)
97 self.event_damage = func_null;
98 self.touch = func_null;
99 self.effects |= EF_NODRAW;
101 self.think = W_Hook_ExplodeThink;
102 self.nextthink = time;
103 self.dmg = WEP_CVAR_SEC(hook, damage);
104 self.dmg_edge = WEP_CVAR_SEC(hook, edgedamage);
105 self.dmg_radius = WEP_CVAR_SEC(hook, radius);
106 self.dmg_force = WEP_CVAR_SEC(hook, force);
107 self.dmg_power = WEP_CVAR_SEC(hook, power);
108 self.dmg_duration = WEP_CVAR_SEC(hook, duration);
109 self.teleport_time = time;
111 self.movetype = MOVETYPE_NONE;
114 void W_Hook_Damage(entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
119 if(!W_CheckProjectileDamage(inflictor.realowner, self.realowner, deathtype, -1)) // no exceptions
120 return; // g_projectiles_damage says to halt
122 self.health = self.health - damage;
125 W_PrepareExplosionByDamage(self.realowner, W_Hook_Explode2);
128 void W_Hook_Touch2(void)
134 void W_Hook_Attack2(Weapon thiswep)
138 //W_DecreaseAmmo(thiswep, self, WEP_CVAR_SEC(hook, ammo)); // WEAPONTODO: Figure out how to handle ammo with hook secondary (gravitybomb)
139 W_SetupShot(self, false, 4, SND(HOOKBOMB_FIRE), CH_WEAPON_A, WEP_CVAR_SEC(hook, damage));
142 gren.owner = gren.realowner = self;
143 gren.classname = "hookbomb";
144 gren.bot_dodge = true;
145 gren.bot_dodgerating = WEP_CVAR_SEC(hook, damage);
146 gren.movetype = MOVETYPE_TOSS;
147 PROJECTILE_MAKETRIGGER(gren);
148 gren.projectiledeathtype = WEP_HOOK.m_id | HITTYPE_SECONDARY;
149 setorigin(gren, w_shotorg);
150 setsize(gren, '0 0 0', '0 0 0');
152 gren.nextthink = time + WEP_CVAR_SEC(hook, lifetime);
153 gren.think = adaptor_think2use_hittype_splash;
154 gren.use = W_Hook_Explode2;
155 gren.touch = W_Hook_Touch2;
157 gren.takedamage = DAMAGE_YES;
158 gren.health = WEP_CVAR_SEC(hook, health);
159 gren.damageforcescale = WEP_CVAR_SEC(hook, damageforcescale);
160 gren.event_damage = W_Hook_Damage;
161 gren.damagedbycontents = true;
162 gren.missile_flags = MIF_SPLASH | MIF_ARC;
164 gren.velocity = '0 0 1' * WEP_CVAR_SEC(hook, speed);
165 if(autocvar_g_projectiles_newton_style)
166 gren.velocity = gren.velocity + self.velocity;
168 gren.gravity = WEP_CVAR_SEC(hook, gravity);
169 //W_SetupProjVelocity_Basic(gren); // just falling down!
171 gren.angles = '0 0 0';
172 gren.flags = FL_PROJECTILE;
174 CSQCProjectile(gren, true, PROJECTILE_HOOKBOMB, true);
176 MUTATOR_CALLHOOK(EditProjectile, self, gren);
179 METHOD(Hook, wr_think, void(entity thiswep, entity actor, bool fire1, bool fire2))
181 if(fire1 || actor.BUTTON_HOOK)
184 if(!(actor.hook_state & HOOK_WAITING_FOR_RELEASE))
185 if(!(actor.hook_state & HOOK_FIRING))
186 if(time > actor.hook_refire)
187 if(weapon_prepareattack(actor, false, -1))
189 W_DecreaseAmmo(thiswep, actor, WEP_CVAR_PRI(hook, ammo));
190 actor.hook_state |= HOOK_FIRING;
191 weapon_thinkf(actor, WFRAME_FIRE1, WEP_CVAR_PRI(hook, animtime), w_ready);
197 if(weapon_prepareattack(actor, true, WEP_CVAR_SEC(hook, refire)))
199 W_Hook_Attack2(thiswep);
200 weapon_thinkf(actor, WFRAME_FIRE2, WEP_CVAR_SEC(hook, animtime), w_ready);
206 // if hooked, no bombs, and increase the timer
207 actor.hook_refire = max(actor.hook_refire, time + WEP_CVAR_PRI(hook, refire) * W_WeaponRateFactor());
209 // hook also inhibits health regeneration, but only for 1 second
210 if(!(actor.items & IT_UNLIMITED_WEAPON_AMMO))
211 actor.pauseregen_finished = max(actor.pauseregen_finished, time + autocvar_g_balance_pause_fuel_regen);
214 if(actor.hook && actor.hook.state == 1)
216 float hooked_time_max = WEP_CVAR_PRI(hook, hooked_time_max);
217 if(hooked_time_max > 0)
219 if( time > actor.hook_time_hooked + hooked_time_max )
220 actor.hook_state |= HOOK_REMOVING;
223 float hooked_fuel = WEP_CVAR_PRI(hook, hooked_ammo);
226 if( time > actor.hook_time_fueldecrease )
228 if(!(actor.items & IT_UNLIMITED_WEAPON_AMMO))
230 if( actor.ammo_fuel >= (time - actor.hook_time_fueldecrease) * hooked_fuel )
232 W_DecreaseAmmo(thiswep, actor, (time - actor.hook_time_fueldecrease) * hooked_fuel);
233 actor.hook_time_fueldecrease = time;
234 // decrease next frame again
239 actor.hook_state |= HOOK_REMOVING;
240 W_SwitchWeapon_Force(actor, w_getbestweapon(actor));
248 actor.hook_time_hooked = time;
249 actor.hook_time_fueldecrease = time + WEP_CVAR_PRI(hook, hooked_time_free);
252 if(actor.BUTTON_CROUCH)
254 actor.hook_state &= ~HOOK_PULLING;
255 if(fire1 || actor.BUTTON_HOOK)
256 actor.hook_state &= ~HOOK_RELEASING;
258 actor.hook_state |= HOOK_RELEASING;
262 actor.hook_state |= HOOK_PULLING;
263 actor.hook_state &= ~HOOK_RELEASING;
265 if(fire1 || actor.BUTTON_HOOK)
269 actor.hook_state |= HOOK_WAITING_FOR_RELEASE;
273 actor.hook_state |= HOOK_REMOVING;
274 actor.hook_state &= ~HOOK_WAITING_FOR_RELEASE;
278 _GrapplingHookFrame();
280 METHOD(Hook, wr_init, void(entity thiswep))
282 HOOK_SETTINGS(WEP_SKIP_CVAR, WEP_SET_PROP);
284 METHOD(Hook, wr_setup, void(entity thiswep))
286 self.hook_state &= ~HOOK_WAITING_FOR_RELEASE;
288 METHOD(Hook, wr_checkammo1, bool(entity thiswep))
291 return self.ammo_fuel > 0;
293 return self.ammo_fuel >= WEP_CVAR_PRI(hook, ammo);
295 METHOD(Hook, wr_checkammo2, bool(entity thiswep))
297 // infinite ammo for now
298 return true; // self.ammo_cells >= WEP_CVAR_SEC(hook, ammo); // WEAPONTODO: see above
300 METHOD(Hook, wr_config, void(entity thiswep))
302 HOOK_SETTINGS(WEP_CONFIG_WRITE_CVARS, WEP_CONFIG_WRITE_PROPS);
304 METHOD(Hook, wr_resetplayer, void(entity thiswep))
306 self.hook_refire = time;
308 METHOD(Hook, wr_suicidemessage, int(entity thiswep))
312 METHOD(Hook, wr_killmessage, int(entity thiswep))
314 return WEAPON_HOOK_MURDER;
320 METHOD(Hook, wr_impacteffect, void(entity thiswep))
323 org2 = w_org + w_backoff * 2;
324 pointparticles(particleeffectnum(EFFECT_HOOK_EXPLODE), org2, '0 0 0', 1);
326 sound(self, CH_SHOTS, SND_HOOKBOMB_IMPACT, VOL_BASE, ATTN_NORM);