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, m_name, string, _("Grappling Hook"));
17 ATTRIB(Hook, ammo_factor, float, 1)
19 REGISTER_WEAPON(HOOK, NEW(Hook));
21 CLASS(OffhandHook, OffhandWeapon)
22 METHOD(OffhandHook, offhand_think, void(OffhandHook this, entity actor, bool key_pressed))
24 Weapon wep = WEP_HOOK;
25 wep.wr_think(wep, actor, key_pressed, false);
28 OffhandHook OFFHAND_HOOK; STATIC_INIT(OFFHAND_HOOK) { OFFHAND_HOOK = NEW(OffhandHook); }
30 #define HOOK_SETTINGS(w_cvar,w_prop) HOOK_SETTINGS_LIST(w_cvar, w_prop, HOOK, hook)
31 #define HOOK_SETTINGS_LIST(w_cvar,w_prop,id,sn) \
32 w_cvar(id, sn, BOTH, animtime) \
33 w_cvar(id, sn, BOTH, refire) \
34 w_cvar(id, sn, PRI, ammo) \
35 w_cvar(id, sn, PRI, hooked_ammo) \
36 w_cvar(id, sn, PRI, hooked_time_free) \
37 w_cvar(id, sn, PRI, hooked_time_max) \
38 w_cvar(id, sn, SEC, damage) \
39 w_cvar(id, sn, SEC, duration) \
40 w_cvar(id, sn, SEC, edgedamage) \
41 w_cvar(id, sn, SEC, force) \
42 w_cvar(id, sn, SEC, gravity) \
43 w_cvar(id, sn, SEC, lifetime) \
44 w_cvar(id, sn, SEC, power) \
45 w_cvar(id, sn, SEC, radius) \
46 w_cvar(id, sn, SEC, speed) \
47 w_cvar(id, sn, SEC, health) \
48 w_cvar(id, sn, SEC, damageforcescale) \
49 w_prop(id, sn, float, switchdelay_raise, switchdelay_raise) \
50 w_prop(id, sn, float, switchdelay_drop, switchdelay_drop) \
51 w_prop(id, sn, string, weaponreplace, weaponreplace) \
52 w_prop(id, sn, float, weaponstart, weaponstart) \
53 w_prop(id, sn, float, weaponstartoverride, weaponstartoverride) \
54 w_prop(id, sn, float, weaponthrowable, weaponthrowable)
57 HOOK_SETTINGS(WEP_ADD_CVAR, WEP_ADD_PROP)
67 .float hook_time_hooked;
68 .float hook_time_fueldecrease;
74 spawnfunc(weapon_hook) { weapon_defaultspawnfunc(this, WEP_HOOK); }
76 void W_Hook_ExplodeThink(void)
78 float dt, dmg_remaining_next, f;
80 dt = time - self.teleport_time;
81 dmg_remaining_next = pow(bound(0, 1 - dt / self.dmg_duration, 1), self.dmg_power);
83 f = self.dmg_last - dmg_remaining_next;
84 self.dmg_last = dmg_remaining_next;
86 RadiusDamage(self, self.realowner, self.dmg * f, self.dmg_edge * f, self.dmg_radius, self.realowner, world, self.dmg_force * f, self.projectiledeathtype, world);
87 self.projectiledeathtype |= HITTYPE_BOUNCE;
88 //RadiusDamage(self, world, self.dmg * f, self.dmg_edge * f, self.dmg_radius, world, world, self.dmg_force * f, self.projectiledeathtype, world);
90 if(dt < self.dmg_duration)
91 self.nextthink = time + 0.05; // soon
96 void W_Hook_Explode2(void)
98 self.event_damage = func_null;
99 self.touch = func_null;
100 self.effects |= EF_NODRAW;
102 self.think = W_Hook_ExplodeThink;
103 self.nextthink = time;
104 self.dmg = WEP_CVAR_SEC(hook, damage);
105 self.dmg_edge = WEP_CVAR_SEC(hook, edgedamage);
106 self.dmg_radius = WEP_CVAR_SEC(hook, radius);
107 self.dmg_force = WEP_CVAR_SEC(hook, force);
108 self.dmg_power = WEP_CVAR_SEC(hook, power);
109 self.dmg_duration = WEP_CVAR_SEC(hook, duration);
110 self.teleport_time = time;
112 self.movetype = MOVETYPE_NONE;
115 void W_Hook_Damage(entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
120 if(!W_CheckProjectileDamage(inflictor.realowner, self.realowner, deathtype, -1)) // no exceptions
121 return; // g_projectiles_damage says to halt
123 self.health = self.health - damage;
126 W_PrepareExplosionByDamage(self.realowner, W_Hook_Explode2);
129 void W_Hook_Touch2(void)
135 void W_Hook_Attack2(Weapon thiswep, entity actor)
137 //W_DecreaseAmmo(thiswep, actor, WEP_CVAR_SEC(hook, ammo)); // WEAPONTODO: Figure out how to handle ammo with hook secondary (gravitybomb)
138 W_SetupShot(actor, false, 4, SND(HOOKBOMB_FIRE), CH_WEAPON_A, WEP_CVAR_SEC(hook, damage));
140 entity gren = new(hookbomb);
141 gren.owner = gren.realowner = actor;
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 + actor.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, actor, gren);
177 METHOD(Hook, wr_think, void(entity thiswep, entity actor, bool fire1, bool fire2))
181 if(!(actor.hook_state & HOOK_WAITING_FOR_RELEASE))
182 if(time > actor.hook_refire)
183 if(weapon_prepareattack(thiswep, actor, false, -1))
185 W_DecreaseAmmo(thiswep, actor, thiswep.ammo_factor * WEP_CVAR_PRI(hook, ammo));
186 actor.hook_state |= HOOK_FIRING;
187 actor.hook_state |= HOOK_WAITING_FOR_RELEASE;
188 weapon_thinkf(actor, WFRAME_FIRE1, WEP_CVAR_PRI(hook, animtime), w_ready);
191 actor.hook_state |= HOOK_REMOVING;
192 actor.hook_state &= ~HOOK_WAITING_FOR_RELEASE;
197 if(weapon_prepareattack(thiswep, actor, true, WEP_CVAR_SEC(hook, refire)))
199 W_Hook_Attack2(thiswep, actor);
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 = thiswep.ammo_factor * 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 actor.hook_state = BITSET(actor.hook_state, HOOK_PULLING, (!actor.BUTTON_CROUCH || !autocvar_g_balance_grapplehook_crouchslide));
254 if (actor.hook_state & HOOK_FIRING)
257 RemoveGrapplingHook(actor);
258 WITH(entity, self, actor, FireGrapplingHook());
259 actor.hook_state &= ~HOOK_FIRING;
260 actor.hook_refire = max(actor.hook_refire, time + autocvar_g_balance_grapplehook_refire * W_WeaponRateFactor());
262 else if (actor.hook_state & HOOK_REMOVING)
265 RemoveGrapplingHook(actor);
266 actor.hook_state &= ~HOOK_REMOVING;
269 METHOD(Hook, wr_init, void(entity thiswep))
271 HOOK_SETTINGS(WEP_SKIP_CVAR, WEP_SET_PROP);
273 METHOD(Hook, wr_setup, void(entity thiswep))
275 self.hook_state &= ~HOOK_WAITING_FOR_RELEASE;
277 METHOD(Hook, wr_checkammo1, bool(Hook thiswep))
279 if (!thiswep.ammo_factor) return true;
281 return self.ammo_fuel > 0;
283 return self.ammo_fuel >= WEP_CVAR_PRI(hook, ammo);
285 METHOD(Hook, wr_checkammo2, bool(Hook thiswep))
287 // infinite ammo for now
288 return true; // self.ammo_cells >= WEP_CVAR_SEC(hook, ammo); // WEAPONTODO: see above
290 METHOD(Hook, wr_config, void(entity thiswep))
292 HOOK_SETTINGS(WEP_CONFIG_WRITE_CVARS, WEP_CONFIG_WRITE_PROPS);
294 METHOD(Hook, wr_resetplayer, void(entity thiswep))
296 self.hook_refire = time;
298 METHOD(Hook, wr_suicidemessage, int(entity thiswep))
302 METHOD(Hook, wr_killmessage, int(entity thiswep))
304 return WEAPON_HOOK_MURDER;
310 METHOD(Hook, wr_impacteffect, void(entity thiswep))
313 org2 = w_org + w_backoff * 2;
314 pointparticles(particleeffectnum(EFFECT_HOOK_EXPLODE), org2, '0 0 0', 1);
316 sound(self, CH_SHOTS, SND_HOOKBOMB_IMPACT, VOL_BASE, ATTN_NORM);