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 #define X(BEGIN, P, END, class, prefix) \
21 P(class, prefix, ammo, float, PRI) \
22 P(class, prefix, animtime, float, BOTH) \
23 P(class, prefix, damageforcescale, float, SEC) \
24 P(class, prefix, damage, float, SEC) \
25 P(class, prefix, duration, float, SEC) \
26 P(class, prefix, edgedamage, float, SEC) \
27 P(class, prefix, force, float, SEC) \
28 P(class, prefix, gravity, float, SEC) \
29 P(class, prefix, health, float, SEC) \
30 P(class, prefix, hooked_ammo, float, PRI) \
31 P(class, prefix, hooked_time_free, float, PRI) \
32 P(class, prefix, hooked_time_max, float, PRI) \
33 P(class, prefix, lifetime, float, SEC) \
34 P(class, prefix, power, float, SEC) \
35 P(class, prefix, radius, float, SEC) \
36 P(class, prefix, refire, float, BOTH) \
37 P(class, prefix, speed, float, SEC) \
38 P(class, prefix, switchdelay_drop, float, NONE) \
39 P(class, prefix, switchdelay_raise, float, NONE) \
40 P(class, prefix, weaponreplace, string, NONE) \
41 P(class, prefix, weaponstartoverride, float, NONE) \
42 P(class, prefix, weaponstart, float, NONE) \
43 P(class, prefix, weaponthrowable, float, NONE) \
45 W_PROPS(X, Hook, hook)
49 REGISTER_WEAPON(HOOK, hook, NEW(Hook));
51 CLASS(OffhandHook, OffhandWeapon)
53 METHOD(OffhandHook, offhand_think, void(OffhandHook this, entity actor, bool key_pressed))
55 Weapon wep = WEP_HOOK;
56 .entity weaponentity = weaponentities[1];
57 wep.wr_think(wep, actor, weaponentity, key_pressed ? 1 : 0);
61 OffhandHook OFFHAND_HOOK; STATIC_INIT(OFFHAND_HOOK) { OFFHAND_HOOK = NEW(OffhandHook); }
73 .float hook_time_hooked;
74 .float hook_time_fueldecrease;
80 spawnfunc(weapon_hook) { weapon_defaultspawnfunc(this, WEP_HOOK); }
82 void W_Hook_ExplodeThink()
84 float dt, dmg_remaining_next, f;
86 dt = time - self.teleport_time;
87 dmg_remaining_next = pow(bound(0, 1 - dt / self.dmg_duration, 1), self.dmg_power);
89 f = self.dmg_last - dmg_remaining_next;
90 self.dmg_last = dmg_remaining_next;
92 RadiusDamage(self, self.realowner, self.dmg * f, self.dmg_edge * f, self.dmg_radius, self.realowner, world, self.dmg_force * f, self.projectiledeathtype, world);
93 self.projectiledeathtype |= HITTYPE_BOUNCE;
94 //RadiusDamage(self, world, self.dmg * f, self.dmg_edge * f, self.dmg_radius, world, world, self.dmg_force * f, self.projectiledeathtype, world);
96 if(dt < self.dmg_duration)
97 self.nextthink = time + 0.05; // soon
102 void W_Hook_Explode2()
104 self.event_damage = func_null;
105 self.touch = func_null;
106 self.effects |= EF_NODRAW;
108 self.think = W_Hook_ExplodeThink;
109 self.nextthink = time;
110 self.dmg = WEP_CVAR_SEC(hook, damage);
111 self.dmg_edge = WEP_CVAR_SEC(hook, edgedamage);
112 self.dmg_radius = WEP_CVAR_SEC(hook, radius);
113 self.dmg_force = WEP_CVAR_SEC(hook, force);
114 self.dmg_power = WEP_CVAR_SEC(hook, power);
115 self.dmg_duration = WEP_CVAR_SEC(hook, duration);
116 self.teleport_time = time;
118 self.movetype = MOVETYPE_NONE;
121 void W_Hook_Damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
126 if(!W_CheckProjectileDamage(inflictor.realowner, this.realowner, deathtype, -1)) // no exceptions
127 return; // g_projectiles_damage says to halt
129 this.health = this.health - damage;
132 WITH(entity, self, this, W_PrepareExplosionByDamage(this.realowner, W_Hook_Explode2));
141 void W_Hook_Attack2(Weapon thiswep, entity actor)
143 //W_DecreaseAmmo(thiswep, actor, WEP_CVAR_SEC(hook, ammo)); // WEAPONTODO: Figure out how to handle ammo with hook secondary (gravitybomb)
144 W_SetupShot(actor, false, 4, SND(HOOKBOMB_FIRE), CH_WEAPON_A, WEP_CVAR_SEC(hook, damage));
146 entity gren = new(hookbomb);
147 gren.owner = gren.realowner = actor;
148 gren.bot_dodge = true;
149 gren.bot_dodgerating = WEP_CVAR_SEC(hook, damage);
150 gren.movetype = MOVETYPE_TOSS;
151 PROJECTILE_MAKETRIGGER(gren);
152 gren.projectiledeathtype = WEP_HOOK.m_id | HITTYPE_SECONDARY;
153 setorigin(gren, w_shotorg);
154 setsize(gren, '0 0 0', '0 0 0');
156 gren.nextthink = time + WEP_CVAR_SEC(hook, lifetime);
157 gren.think = adaptor_think2use_hittype_splash;
158 gren.use = W_Hook_Explode2;
159 gren.touch = W_Hook_Touch2;
161 gren.takedamage = DAMAGE_YES;
162 gren.health = WEP_CVAR_SEC(hook, health);
163 gren.damageforcescale = WEP_CVAR_SEC(hook, damageforcescale);
164 gren.event_damage = W_Hook_Damage;
165 gren.damagedbycontents = true;
166 gren.missile_flags = MIF_SPLASH | MIF_ARC;
168 gren.velocity = '0 0 1' * WEP_CVAR_SEC(hook, speed);
169 if (autocvar_g_projectiles_newton_style)
170 gren.velocity = gren.velocity + actor.velocity;
172 gren.gravity = WEP_CVAR_SEC(hook, gravity);
173 //W_SetupProjVelocity_Basic(gren); // just falling down!
175 gren.angles = '0 0 0';
176 gren.flags = FL_PROJECTILE;
178 CSQCProjectile(gren, true, PROJECTILE_HOOKBOMB, true);
180 MUTATOR_CALLHOOK(EditProjectile, actor, gren);
183 METHOD(Hook, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
187 if(!(actor.hook_state & HOOK_WAITING_FOR_RELEASE))
188 if(time > actor.hook_refire)
189 if(weapon_prepareattack(thiswep, actor, weaponentity, false, -1))
191 W_DecreaseAmmo(thiswep, actor, thiswep.ammo_factor * WEP_CVAR_PRI(hook, ammo));
192 actor.hook_state |= HOOK_FIRING;
193 actor.hook_state |= HOOK_WAITING_FOR_RELEASE;
194 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(hook, animtime), w_ready);
197 actor.hook_state |= HOOK_REMOVING;
198 actor.hook_state &= ~HOOK_WAITING_FOR_RELEASE;
203 if(weapon_prepareattack(thiswep, actor, weaponentity, true, WEP_CVAR_SEC(hook, refire)))
205 W_Hook_Attack2(thiswep, actor);
206 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(hook, animtime), w_ready);
212 // if hooked, no bombs, and increase the timer
213 actor.hook_refire = max(actor.hook_refire, time + WEP_CVAR_PRI(hook, refire) * W_WeaponRateFactor());
215 // hook also inhibits health regeneration, but only for 1 second
216 if(!(actor.items & IT_UNLIMITED_WEAPON_AMMO))
217 actor.pauseregen_finished = max(actor.pauseregen_finished, time + autocvar_g_balance_pause_fuel_regen);
220 if(actor.hook && actor.hook.state == 1)
222 float hooked_time_max = WEP_CVAR_PRI(hook, hooked_time_max);
223 if(hooked_time_max > 0)
225 if( time > actor.hook_time_hooked + hooked_time_max )
226 actor.hook_state |= HOOK_REMOVING;
229 float hooked_fuel = thiswep.ammo_factor * WEP_CVAR_PRI(hook, hooked_ammo);
232 if( time > actor.hook_time_fueldecrease )
234 if(!(actor.items & IT_UNLIMITED_WEAPON_AMMO))
236 if( actor.ammo_fuel >= (time - actor.hook_time_fueldecrease) * hooked_fuel )
238 W_DecreaseAmmo(thiswep, actor, (time - actor.hook_time_fueldecrease) * hooked_fuel);
239 actor.hook_time_fueldecrease = time;
240 // decrease next frame again
245 actor.hook_state |= HOOK_REMOVING;
246 W_SwitchWeapon_Force(actor, w_getbestweapon(actor));
254 actor.hook_time_hooked = time;
255 actor.hook_time_fueldecrease = time + WEP_CVAR_PRI(hook, hooked_time_free);
258 actor.hook_state = BITSET(actor.hook_state, HOOK_PULLING, (!PHYS_INPUT_BUTTON_CROUCH(actor) || !autocvar_g_balance_grapplehook_crouchslide));
260 if (actor.hook_state & HOOK_FIRING)
263 RemoveGrapplingHook(actor);
264 WITH(entity, self, actor, FireGrapplingHook());
265 actor.hook_state &= ~HOOK_FIRING;
266 actor.hook_refire = max(actor.hook_refire, time + autocvar_g_balance_grapplehook_refire * W_WeaponRateFactor());
268 else if (actor.hook_state & HOOK_REMOVING)
271 RemoveGrapplingHook(actor);
272 actor.hook_state &= ~HOOK_REMOVING;
275 METHOD(Hook, wr_setup, void(entity thiswep))
277 self.hook_state &= ~HOOK_WAITING_FOR_RELEASE;
279 METHOD(Hook, wr_checkammo1, bool(Hook thiswep))
281 if (!thiswep.ammo_factor) return true;
283 return self.ammo_fuel > 0;
285 return self.ammo_fuel >= WEP_CVAR_PRI(hook, ammo);
287 METHOD(Hook, wr_checkammo2, bool(Hook thiswep))
289 // infinite ammo for now
290 return true; // self.ammo_cells >= WEP_CVAR_SEC(hook, ammo); // WEAPONTODO: see above
292 METHOD(Hook, wr_resetplayer, void(entity thiswep))
294 RemoveGrapplingHook(self);
296 self.hook_refire = time;
298 METHOD(Hook, wr_killmessage, Notification(entity thiswep))
300 return WEAPON_HOOK_MURDER;
306 METHOD(Hook, wr_impacteffect, void(entity thiswep))
309 org2 = w_org + w_backoff * 2;
310 pointparticles(EFFECT_HOOK_EXPLODE, org2, '0 0 0', 1);
312 sound(self, CH_SHOTS, SND_HOOKBOMB_IMPACT, VOL_BASE, ATTN_NORM);
318 #include <lib/csqcmodel/interpolate.qh>
319 #include <lib/warpzone/common.qh>
321 float autocvar_cl_grapplehook_alpha = 1;
323 void Draw_CylindricLine(vector from, vector to, float thickness, string texture, float aspect, float shift, vector rgb, float theAlpha, float drawflag, vector vieworg);
326 class(Hook) .entity HookType; // ENT_CLIENT_*
327 class(Hook) .vector origin;
328 class(Hook) .vector velocity;
329 class(Hook) .float HookSilent;
330 class(Hook) .float HookRange;
332 string Draw_GrapplingHook_trace_callback_tex;
333 float Draw_GrapplingHook_trace_callback_rnd;
334 vector Draw_GrapplingHook_trace_callback_rgb;
335 float Draw_GrapplingHook_trace_callback_a;
336 void Draw_GrapplingHook_trace_callback(vector start, vector hit, vector end)
340 vorg = WarpZone_TransformOrigin(WarpZone_trace_transform, view_origin);
341 for(i = 0; i < Draw_GrapplingHook_trace_callback_a; ++i)
342 Draw_CylindricLine(hit, start, 8, Draw_GrapplingHook_trace_callback_tex, 0.25, Draw_GrapplingHook_trace_callback_rnd, Draw_GrapplingHook_trace_callback_rgb, min(1, Draw_GrapplingHook_trace_callback_a - i), DRAWFLAG_NORMAL, vorg);
343 Draw_GrapplingHook_trace_callback_rnd += 0.25 * vlen(hit - start) / 8;
346 class(Hook) .float teleport_time;
347 void Draw_GrapplingHook(entity this)
354 float intensity, offset;
356 if(this.teleport_time)
357 if(time > this.teleport_time)
359 sound (this, CH_SHOTS_SINGLE, SND_Null, VOL_BASE, ATTEN_NORM); // safeguard
360 this.teleport_time = 0;
363 InterpolateOrigin_Do(this);
365 int s = W_GetGunAlignment(world);
367 switch(this.HookType)
370 case NET_ENT_CLIENT_HOOK:
371 vs = hook_shotorigin[s];
373 case NET_ENT_CLIENT_ARC_BEAM:
374 vs = lightning_shotorigin[s];
378 if((this.owner.sv_entnum == player_localentnum - 1) && autocvar_chase_active <= 0)
380 switch(this.HookType)
383 case NET_ENT_CLIENT_HOOK:
384 a = view_origin + view_forward * vs.x + view_right * -vs.y + view_up * vs.z;
387 case NET_ENT_CLIENT_ARC_BEAM:
389 b = view_origin + view_forward * this.HookRange;
391 b = view_origin + view_forward * vlen(this.velocity - this.origin); // honor original length of beam!
392 WarpZone_TraceLine(view_origin, b, MOVE_NORMAL, world);
393 b = WarpZone_UnTransformOrigin(WarpZone_trace_transform, trace_endpos);
394 a = view_origin + view_forward * vs.x + view_right * -vs.y + view_up * vs.z;
400 switch(this.HookType)
403 case NET_ENT_CLIENT_HOOK:
407 case NET_ENT_CLIENT_ARC_BEAM:
414 t = entcs_GetTeamColor(this.owner.sv_entnum);
416 switch(this.HookType)
419 case NET_ENT_CLIENT_HOOK:
420 intensity = autocvar_cl_grapplehook_alpha;
424 case NUM_TEAM_1: tex = "particles/hook_red"; rgb = '1 0.3 0.3'; break;
425 case NUM_TEAM_2: tex = "particles/hook_blue"; rgb = '0.3 0.3 1'; break;
426 case NUM_TEAM_3: tex = "particles/hook_yellow"; rgb = '1 1 0.3'; break;
427 case NUM_TEAM_4: tex = "particles/hook_pink"; rgb = '1 0.3 1'; break;
428 default: tex = "particles/hook_white"; rgb = entcs_GetColor(this.sv_entnum - 1); break;
431 case NET_ENT_CLIENT_ARC_BEAM: // todo
432 intensity = bound(0.2, 1 + Noise_Pink(this, frametime) * 1 + Noise_Burst(this, frametime, 0.03) * 0.3, 2);
433 offset = Noise_Brown(this, frametime) * 10;
434 tex = "particles/lgbeam";
439 Draw_GrapplingHook_trace_callback_tex = tex;
440 Draw_GrapplingHook_trace_callback_rnd = offset;
441 Draw_GrapplingHook_trace_callback_rgb = rgb;
442 Draw_GrapplingHook_trace_callback_a = intensity;
443 WarpZone_TraceBox_ThroughZone(a, '0 0 0', '0 0 0', b, ((this.HookType == NET_ENT_CLIENT_HOOK) ? MOVE_NOTHING : MOVE_NORMAL), world, world, Draw_GrapplingHook_trace_callback);
444 Draw_GrapplingHook_trace_callback_tex = string_null;
446 atrans = WarpZone_TransformOrigin(WarpZone_trace_transform, a);
448 switch(this.HookType)
451 case NET_ENT_CLIENT_HOOK:
452 if(vdist(trace_endpos - atrans, >, 0.5))
454 setorigin(this, trace_endpos); // hook endpoint!
455 this.angles = vectoangles(trace_endpos - atrans);
456 this.drawmask = MASK_NORMAL;
463 case NET_ENT_CLIENT_ARC_BEAM:
464 setorigin(this, a); // beam origin!
468 switch(this.HookType)
471 case NET_ENT_CLIENT_HOOK:
473 case NET_ENT_CLIENT_ARC_BEAM:
474 pointparticles(EFFECT_ARC_LIGHTNING2, trace_endpos, normalize(atrans - trace_endpos), frametime * intensity); // todo: new effect
479 void Remove_GrapplingHook(entity this)
481 sound (this, CH_SHOTS_SINGLE, SND_Null, VOL_BASE, ATTEN_NORM);
484 NET_HANDLE(ENT_CLIENT_HOOK, bool bIsNew)
486 self.HookType = NET_ENT_CLIENT_HOOK;
490 self.HookSilent = (sf & 0x80);
491 self.iflags = IFLAG_VELOCITY | IFLAG_ORIGIN;
493 InterpolateOrigin_Undo(self);
497 int myowner = ReadByte();
498 self.owner = playerslots[myowner - 1];
499 self.sv_entnum = myowner;
500 switch(self.HookType)
503 case NET_ENT_CLIENT_HOOK:
506 case NET_ENT_CLIENT_ARC_BEAM:
507 self.HookRange = ReadCoord();
513 self.origin_x = ReadCoord();
514 self.origin_y = ReadCoord();
515 self.origin_z = ReadCoord();
516 setorigin(self, self.origin);
520 self.velocity_x = ReadCoord();
521 self.velocity_y = ReadCoord();
522 self.velocity_z = ReadCoord();
525 InterpolateOrigin_Note(this);
527 if(bIsNew || !self.teleport_time)
529 self.draw = Draw_GrapplingHook;
530 self.entremove = Remove_GrapplingHook;
532 switch(self.HookType)
535 case NET_ENT_CLIENT_HOOK:
537 setmodel(self, MDL_HOOK);
538 self.drawmask = MASK_NORMAL;
540 case NET_ENT_CLIENT_ARC_BEAM:
541 sound (self, CH_SHOTS_SINGLE, SND_LGBEAM_FLY, VOL_BASE, ATTEN_NORM);
546 self.teleport_time = time + 10;
550 // TODO: hook: temporarily transform self.origin for drawing the model along warpzones!