4 /* ammotype */ ATTRIB(Hook, ammo_field, .int, ammo_fuel);
5 /* impulse */ ATTRIB(Hook, impulse, int, 0);
6 /* flags */ ATTRIB(Hook, spawnflags, int, WEP_FLAG_CANCLIMB | WEP_TYPE_SPLASH);
7 /* rating */ ATTRIB(Hook, bot_pickupbasevalue, float, 0);
8 /* color */ ATTRIB(Hook, wpcolor, vector, '0 0.5 0');
9 /* modelname */ ATTRIB(Hook, mdl, string, "hookgun");
11 /* model */ ATTRIB(Hook, m_model, Model, MDL_HOOK_ITEM);
13 /* crosshair */ ATTRIB(Hook, w_crosshair, string, "gfx/crosshairhook");
14 /* crosshair */ ATTRIB(Hook, w_crosshair_size, float, 0.5);
15 /* wepimg */ ATTRIB(Hook, model2, string, "weaponhook");
16 /* refname */ ATTRIB(Hook, netname, string, "hook");
17 /* wepname */ ATTRIB(Hook, m_name, string, _("Grappling Hook"));
18 ATTRIB(Hook, ammo_factor, float, 1);
20 #define X(BEGIN, P, END, class, prefix) \
22 P(class, prefix, ammo, float, PRI) \
23 P(class, prefix, animtime, float, BOTH) \
24 P(class, prefix, damageforcescale, float, SEC) \
25 P(class, prefix, damage, float, SEC) \
26 P(class, prefix, duration, float, SEC) \
27 P(class, prefix, edgedamage, float, SEC) \
28 P(class, prefix, force, float, SEC) \
29 P(class, prefix, gravity, float, SEC) \
30 P(class, prefix, health, float, SEC) \
31 P(class, prefix, hooked_ammo, float, PRI) \
32 P(class, prefix, hooked_time_free, float, PRI) \
33 P(class, prefix, hooked_time_max, float, PRI) \
34 P(class, prefix, lifetime, float, SEC) \
35 P(class, prefix, power, float, SEC) \
36 P(class, prefix, radius, float, SEC) \
37 P(class, prefix, refire, float, BOTH) \
38 P(class, prefix, speed, float, SEC) \
39 P(class, prefix, switchdelay_drop, float, NONE) \
40 P(class, prefix, switchdelay_raise, float, NONE) \
41 P(class, prefix, weaponreplace, string, NONE) \
42 P(class, prefix, weaponstartoverride, float, NONE) \
43 P(class, prefix, weaponstart, float, NONE) \
44 P(class, prefix, weaponthrowable, float, NONE) \
46 W_PROPS(X, Hook, hook)
50 REGISTER_WEAPON(HOOK, hook, NEW(Hook));
52 CLASS(OffhandHook, OffhandWeapon)
54 METHOD(OffhandHook, offhand_think, void(OffhandHook this, entity actor, bool key_pressed))
56 Weapon wep = WEP_HOOK;
57 .entity weaponentity = weaponentities[1];
58 wep.wr_think(wep, actor, weaponentity, key_pressed ? 1 : 0);
62 OffhandHook OFFHAND_HOOK; STATIC_INIT(OFFHAND_HOOK) { OFFHAND_HOOK = NEW(OffhandHook); }
74 .float hook_time_hooked;
75 .float hook_time_fueldecrease;
81 spawnfunc(weapon_hook) { weapon_defaultspawnfunc(this, WEP_HOOK); }
83 void W_Hook_ExplodeThink(entity this)
85 float dt, dmg_remaining_next, f;
87 dt = time - this.teleport_time;
88 dmg_remaining_next = pow(bound(0, 1 - dt / this.dmg_duration, 1), this.dmg_power);
90 f = this.dmg_last - dmg_remaining_next;
91 this.dmg_last = dmg_remaining_next;
93 RadiusDamage(this, this.realowner, this.dmg * f, this.dmg_edge * f, this.dmg_radius, this.realowner, NULL, this.dmg_force * f, this.projectiledeathtype, NULL);
94 this.projectiledeathtype |= HITTYPE_BOUNCE;
95 //RadiusDamage(this, NULL, this.dmg * f, this.dmg_edge * f, this.dmg_radius, NULL, NULL, this.dmg_force * f, this.projectiledeathtype, NULL);
97 if(dt < this.dmg_duration)
98 this.nextthink = time + 0.05; // soon
103 void W_Hook_Explode2(entity this)
105 this.event_damage = func_null;
106 settouch(this, func_null);
107 this.effects |= EF_NODRAW;
109 setthink(this, W_Hook_ExplodeThink);
110 this.nextthink = time;
111 this.dmg = WEP_CVAR_SEC(hook, damage);
112 this.dmg_edge = WEP_CVAR_SEC(hook, edgedamage);
113 this.dmg_radius = WEP_CVAR_SEC(hook, radius);
114 this.dmg_force = WEP_CVAR_SEC(hook, force);
115 this.dmg_power = WEP_CVAR_SEC(hook, power);
116 this.dmg_duration = WEP_CVAR_SEC(hook, duration);
117 this.teleport_time = time;
119 set_movetype(this, MOVETYPE_NONE);
122 void W_Hook_Explode2_use(entity this, entity actor, entity trigger)
124 W_Hook_Explode2(this);
127 void W_Hook_Damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
132 if(!W_CheckProjectileDamage(inflictor.realowner, this.realowner, deathtype, -1)) // no exceptions
133 return; // g_projectiles_damage says to halt
135 this.health = this.health - damage;
138 W_PrepareExplosionByDamage(this, this.realowner, W_Hook_Explode2);
141 void W_Hook_Touch2(entity this, entity toucher)
143 PROJECTILE_TOUCH(this, toucher);
144 this.use(this, NULL, NULL);
147 void W_Hook_Attack2(Weapon thiswep, entity actor, .entity weaponentity)
149 //W_DecreaseAmmo(thiswep, actor, WEP_CVAR_SEC(hook, ammo)); // WEAPONTODO: Figure out how to handle ammo with hook secondary (gravitybomb)
150 W_SetupShot(actor, weaponentity, false, 4, SND_HOOKBOMB_FIRE, CH_WEAPON_A, WEP_CVAR_SEC(hook, damage));
152 entity gren = new(hookbomb);
153 gren.owner = gren.realowner = actor;
154 gren.bot_dodge = true;
155 gren.bot_dodgerating = WEP_CVAR_SEC(hook, damage);
156 set_movetype(gren, MOVETYPE_TOSS);
157 PROJECTILE_MAKETRIGGER(gren);
158 gren.projectiledeathtype = WEP_HOOK.m_id | HITTYPE_SECONDARY;
159 setorigin(gren, w_shotorg);
160 setsize(gren, '0 0 0', '0 0 0');
162 gren.nextthink = time + WEP_CVAR_SEC(hook, lifetime);
163 setthink(gren, adaptor_think2use_hittype_splash);
164 gren.use = W_Hook_Explode2_use;
165 settouch(gren, W_Hook_Touch2);
167 gren.takedamage = DAMAGE_YES;
168 gren.health = WEP_CVAR_SEC(hook, health);
169 gren.damageforcescale = WEP_CVAR_SEC(hook, damageforcescale);
170 gren.event_damage = W_Hook_Damage;
171 gren.damagedbycontents = true;
172 gren.missile_flags = MIF_SPLASH | MIF_ARC;
174 gren.velocity = '0 0 1' * WEP_CVAR_SEC(hook, speed);
175 if (autocvar_g_projectiles_newton_style)
176 gren.velocity = gren.velocity + actor.velocity;
178 gren.gravity = WEP_CVAR_SEC(hook, gravity);
179 //W_SetupProjVelocity_Basic(gren); // just falling down!
181 gren.angles = '0 0 0';
182 gren.flags = FL_PROJECTILE;
183 IL_PUSH(g_projectiles, gren);
184 IL_PUSH(g_bot_dodge, gren);
186 CSQCProjectile(gren, true, PROJECTILE_HOOKBOMB, true);
188 MUTATOR_CALLHOOK(EditProjectile, actor, gren);
191 METHOD(Hook, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
195 if(!(actor.hook_state & HOOK_WAITING_FOR_RELEASE))
196 if(time > actor.hook_refire)
197 if(weapon_prepareattack(thiswep, actor, weaponentity, false, -1))
199 W_DecreaseAmmo(thiswep, actor, thiswep.ammo_factor * WEP_CVAR_PRI(hook, ammo));
200 actor.hook_state |= HOOK_FIRING;
201 actor.hook_state |= HOOK_WAITING_FOR_RELEASE;
202 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(hook, animtime), w_ready);
205 actor.hook_state |= HOOK_REMOVING;
206 actor.hook_state &= ~HOOK_WAITING_FOR_RELEASE;
211 if(weapon_prepareattack(thiswep, actor, weaponentity, true, WEP_CVAR_SEC(hook, refire)))
213 W_Hook_Attack2(thiswep, actor, weaponentity);
214 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(hook, animtime), w_ready);
220 // if hooked, no bombs, and increase the timer
221 actor.hook_refire = max(actor.hook_refire, time + WEP_CVAR_PRI(hook, refire) * W_WeaponRateFactor(actor));
223 // hook also inhibits health regeneration, but only for 1 second
224 if(!(actor.items & IT_UNLIMITED_WEAPON_AMMO))
225 actor.pauseregen_finished = max(actor.pauseregen_finished, time + autocvar_g_balance_pause_fuel_regen);
228 if(actor.hook && actor.hook.state == 1)
230 float hooked_time_max = WEP_CVAR_PRI(hook, hooked_time_max);
231 if(hooked_time_max > 0)
233 if( time > actor.hook_time_hooked + hooked_time_max )
234 actor.hook_state |= HOOK_REMOVING;
237 float hooked_fuel = thiswep.ammo_factor * WEP_CVAR_PRI(hook, hooked_ammo);
240 if( time > actor.hook_time_fueldecrease )
242 if(!(actor.items & IT_UNLIMITED_WEAPON_AMMO))
244 if( actor.ammo_fuel >= (time - actor.hook_time_fueldecrease) * hooked_fuel )
246 W_DecreaseAmmo(thiswep, actor, (time - actor.hook_time_fueldecrease) * hooked_fuel);
247 actor.hook_time_fueldecrease = time;
248 // decrease next frame again
253 actor.hook_state |= HOOK_REMOVING;
254 W_SwitchWeapon_Force(actor, w_getbestweapon(actor));
262 actor.hook_time_hooked = time;
263 actor.hook_time_fueldecrease = time + WEP_CVAR_PRI(hook, hooked_time_free);
266 actor.hook_state = BITSET(actor.hook_state, HOOK_PULLING, (!PHYS_INPUT_BUTTON_CROUCH(actor) || !autocvar_g_balance_grapplehook_crouchslide));
268 if (actor.hook_state & HOOK_FIRING)
271 RemoveGrapplingHook(actor);
272 FireGrapplingHook(actor);
273 actor.hook_state &= ~HOOK_FIRING;
274 actor.hook_refire = max(actor.hook_refire, time + autocvar_g_balance_grapplehook_refire * W_WeaponRateFactor(actor));
276 else if (actor.hook_state & HOOK_REMOVING)
279 RemoveGrapplingHook(actor);
280 actor.hook_state &= ~HOOK_REMOVING;
283 METHOD(Hook, wr_setup, void(entity thiswep, entity actor))
285 actor.hook_state &= ~HOOK_WAITING_FOR_RELEASE;
287 METHOD(Hook, wr_checkammo1, bool(Hook thiswep, entity actor))
289 if (!thiswep.ammo_factor) return true;
291 return actor.ammo_fuel > 0;
293 return actor.ammo_fuel >= WEP_CVAR_PRI(hook, ammo);
295 METHOD(Hook, wr_checkammo2, bool(Hook thiswep, entity actor))
297 // infinite ammo for now
298 return true; // actor.ammo_cells >= WEP_CVAR_SEC(hook, ammo); // WEAPONTODO: see above
300 METHOD(Hook, wr_resetplayer, void(entity thiswep, entity actor))
302 RemoveGrapplingHook(actor);
304 actor.hook_refire = time;
306 METHOD(Hook, wr_killmessage, Notification(entity thiswep))
308 return WEAPON_HOOK_MURDER;
314 METHOD(Hook, wr_impacteffect, void(entity thiswep, entity actor))
317 org2 = w_org + w_backoff * 2;
318 pointparticles(EFFECT_HOOK_EXPLODE, org2, '0 0 0', 1);
320 sound(actor, CH_SHOTS, SND_HOOKBOMB_IMPACT, VOL_BASE, ATTN_NORM);
326 #include <lib/csqcmodel/interpolate.qh>
327 #include <lib/warpzone/common.qh>
329 float autocvar_cl_grapplehook_alpha = 1;
331 void Draw_CylindricLine(vector from, vector to, float thickness, string texture, float aspect, float shift, vector rgb, float theAlpha, float drawflag, vector vieworg);
334 class(Hook) .entity HookType; // ENT_CLIENT_*
335 class(Hook) .vector origin;
336 class(Hook) .vector velocity;
337 class(Hook) .float HookSilent;
338 class(Hook) .float HookRange;
340 string Draw_GrapplingHook_trace_callback_tex;
341 float Draw_GrapplingHook_trace_callback_rnd;
342 vector Draw_GrapplingHook_trace_callback_rgb;
343 float Draw_GrapplingHook_trace_callback_a;
344 void Draw_GrapplingHook_trace_callback(vector start, vector hit, vector end)
348 vorg = WarpZone_TransformOrigin(WarpZone_trace_transform, view_origin);
349 for(i = 0; i < Draw_GrapplingHook_trace_callback_a; ++i)
350 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);
351 Draw_GrapplingHook_trace_callback_rnd += 0.25 * vlen(hit - start) / 8;
354 class(Hook) .float teleport_time;
355 void Draw_GrapplingHook(entity this)
362 float intensity, offset;
364 if(this.teleport_time)
365 if(time > this.teleport_time)
367 sound (this, CH_SHOTS_SINGLE, SND_Null, VOL_BASE, ATTEN_NORM); // safeguard
368 this.teleport_time = 0;
371 InterpolateOrigin_Do(this);
373 int s = W_GetGunAlignment(NULL);
375 switch(this.HookType)
378 case NET_ENT_CLIENT_HOOK:
379 vs = hook_shotorigin[s];
381 case NET_ENT_CLIENT_ARC_BEAM:
382 vs = lightning_shotorigin[s];
386 if((this.owner.sv_entnum == player_localentnum - 1))
388 switch(this.HookType)
391 case NET_ENT_CLIENT_HOOK:
392 if(autocvar_chase_active > 0)
393 a = csqcplayer.origin;
395 a = view_origin + view_forward * vs.x + view_right * -vs.y + view_up * vs.z;
398 case NET_ENT_CLIENT_ARC_BEAM:
400 b = view_origin + view_forward * this.HookRange;
402 b = view_origin + view_forward * vlen(this.velocity - this.origin); // honor original length of beam!
403 WarpZone_TraceLine(view_origin, b, MOVE_NORMAL, NULL);
404 b = WarpZone_UnTransformOrigin(WarpZone_trace_transform, trace_endpos);
405 a = view_origin + view_forward * vs.x + view_right * -vs.y + view_up * vs.z;
411 switch(this.HookType)
414 case NET_ENT_CLIENT_HOOK:
418 case NET_ENT_CLIENT_ARC_BEAM:
425 t = entcs_GetTeamColor(this.owner.sv_entnum);
427 switch(this.HookType)
430 case NET_ENT_CLIENT_HOOK:
431 intensity = autocvar_cl_grapplehook_alpha;
435 case NUM_TEAM_1: tex = "particles/hook_red"; rgb = '1 0.3 0.3'; break;
436 case NUM_TEAM_2: tex = "particles/hook_blue"; rgb = '0.3 0.3 1'; break;
437 case NUM_TEAM_3: tex = "particles/hook_yellow"; rgb = '1 1 0.3'; break;
438 case NUM_TEAM_4: tex = "particles/hook_pink"; rgb = '1 0.3 1'; break;
439 default: tex = "particles/hook_white"; rgb = entcs_GetColor(this.sv_entnum - 1); break;
442 case NET_ENT_CLIENT_ARC_BEAM: // todo
443 intensity = bound(0.2, 1 + Noise_Pink(this, frametime) * 1 + Noise_Burst(this, frametime, 0.03) * 0.3, 2);
444 offset = Noise_Brown(this, frametime) * 10;
445 tex = "particles/lgbeam";
450 MUTATOR_CALLHOOK(DrawGrapplingHook, this, tex, rgb, t);
451 tex = M_ARGV(1, string);
452 rgb = M_ARGV(2, vector);
454 Draw_GrapplingHook_trace_callback_tex = tex;
455 Draw_GrapplingHook_trace_callback_rnd = offset;
456 Draw_GrapplingHook_trace_callback_rgb = rgb;
457 Draw_GrapplingHook_trace_callback_a = intensity;
458 WarpZone_TraceBox_ThroughZone(a, '0 0 0', '0 0 0', b, ((this.HookType == NET_ENT_CLIENT_HOOK) ? MOVE_NOTHING : MOVE_NORMAL), NULL, NULL, Draw_GrapplingHook_trace_callback);
459 Draw_GrapplingHook_trace_callback_tex = string_null;
461 atrans = WarpZone_TransformOrigin(WarpZone_trace_transform, a);
463 switch(this.HookType)
466 case NET_ENT_CLIENT_HOOK:
467 if(vdist(trace_endpos - atrans, >, 0.5))
469 setorigin(this, trace_endpos); // hook endpoint!
470 this.angles = vectoangles(trace_endpos - atrans);
471 this.drawmask = MASK_NORMAL;
478 case NET_ENT_CLIENT_ARC_BEAM:
479 setorigin(this, a); // beam origin!
483 switch(this.HookType)
486 case NET_ENT_CLIENT_HOOK:
488 case NET_ENT_CLIENT_ARC_BEAM:
489 pointparticles(EFFECT_ARC_LIGHTNING2, trace_endpos, normalize(atrans - trace_endpos), frametime * intensity); // todo: new effect
494 void Remove_GrapplingHook(entity this)
496 sound (this, CH_SHOTS_SINGLE, SND_Null, VOL_BASE, ATTEN_NORM);
498 if(csqcplayer && csqcplayer.hook == this)
499 csqcplayer.hook = NULL;
502 NET_HANDLE(ENT_CLIENT_HOOK, bool bIsNew)
504 this.HookType = NET_ENT_CLIENT_HOOK;
508 this.HookSilent = (sf & 0x80);
509 this.iflags = IFLAG_VELOCITY | IFLAG_ORIGIN;
511 InterpolateOrigin_Undo(this);
515 int myowner = ReadByte();
516 this.owner = playerslots[myowner - 1];
517 this.sv_entnum = myowner;
518 if(csqcplayer && myowner == player_localentnum)
519 csqcplayer.hook = this;
520 switch(this.HookType)
523 case NET_ENT_CLIENT_HOOK:
526 case NET_ENT_CLIENT_ARC_BEAM:
527 this.HookRange = ReadCoord();
533 this.origin_x = ReadCoord();
534 this.origin_y = ReadCoord();
535 this.origin_z = ReadCoord();
536 setorigin(this, this.origin);
540 this.velocity_x = ReadCoord();
541 this.velocity_y = ReadCoord();
542 this.velocity_z = ReadCoord();
545 InterpolateOrigin_Note(this);
547 if(bIsNew || !this.teleport_time)
549 this.draw = Draw_GrapplingHook;
550 IL_PUSH(g_drawables, this);
551 this.entremove = Remove_GrapplingHook;
553 switch(this.HookType)
556 case NET_ENT_CLIENT_HOOK:
558 setmodel(this, MDL_HOOK);
559 this.drawmask = MASK_NORMAL;
561 case NET_ENT_CLIENT_ARC_BEAM:
562 sound (this, CH_SHOTS_SINGLE, SND_LGBEAM_FLY, VOL_BASE, ATTEN_NORM);
567 this.teleport_time = time + 10;
571 // TODO: hook: temporarily transform this.origin for drawing the model along warpzones!