Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
hook.qc File Reference
Include dependency graph for hook.qc:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

 classfield (Hook) .vector origin
void Draw_CylindricLine (vector from, vector to, float thickness, string texture, float aspect, float shift, vector rgb, float theAlpha, float drawflag, vector vieworg)
void Draw_GrapplingHook (entity this)
void Draw_GrapplingHook_trace_callback (vector start, vector hit, vector end)
 entityclass (Hook)
 NET_HANDLE (ENT_CLIENT_HOOK, bool isNew)
void Remove_GrapplingHook (entity this)
void W_Hook_Attack2 (Weapon thiswep, entity actor,.entity weaponentity)
void W_Hook_Damage (entity this, entity inflictor, entity attacker, float damage, int deathtype,.entity weaponentity, vector hitloc, vector force)
void W_Hook_Explode2 (entity this)
void W_Hook_Explode2_use (entity this, entity actor, entity trigger)
void W_Hook_ExplodeThink (entity this)
void W_Hook_Touch2 (entity this, entity toucher)

Variables

float autocvar_cl_grapplehook_alpha = 1
float Draw_GrapplingHook_trace_callback_a
vector Draw_GrapplingHook_trace_callback_rgb
float Draw_GrapplingHook_trace_callback_rnd
string Draw_GrapplingHook_trace_callback_tex
const float HOOK_SECONDARY_DELAY = 0.0625

Function Documentation

◆ classfield()

classfield ( Hook )

References origin, and velocity.

◆ Draw_CylindricLine()

void Draw_CylindricLine ( vector from,
vector to,
float thickness,
string texture,
float aspect,
float shift,
vector rgb,
float theAlpha,
float drawflag,
vector vieworg )

Definition at line 10 of file draw.qh.

11 {
12 // I want to draw a quad...
13 // from and to are MIDPOINTS.
14
15 float len = vlen(to - from);
16 if (!len)
17 return;
18
19 float length_tex = aspect * len / thickness;
20 vector axis = (to - from) / len; // same as axis = normalize(to - from) but cheaper
21
22 // direction is perpendicular to the view normal, and perpendicular to the axis
23 vector thickdir = normalize(cross(axis, vieworg - from));
24
25 vector ofs = thickdir * (thickness * 0.5);
26
27 R_BeginPolygon(texture, drawflag, false);
28 R_PolygonVertex(from - ofs, '0 0 0' + shift * '1 0 0', rgb, theAlpha);
29 R_PolygonVertex(from + ofs, '0 1 0' + shift * '1 0 0', rgb, theAlpha);
30 R_PolygonVertex(to + ofs, '0 1 0' + (shift + length_tex) * '1 0 0', rgb, theAlpha);
31 R_PolygonVertex(to - ofs, '0 0 0' + (shift + length_tex) * '1 0 0', rgb, theAlpha);
32 R_EndPolygon();
33 }
float vlen(vector v)
vector normalize(vector v)
vector
Definition self.qh:96
#define cross(a, b)
Definition vector.qh:25

References cross, normalize(), vector, and vlen().

Referenced by bumble_raygun_draw(), Draw_ArcBeam_callback(), Draw_GrapplingHook_trace_callback(), Draw_VaporizerBeam_trace_callback(), and Porto_Draw().

◆ Draw_GrapplingHook()

void Draw_GrapplingHook ( entity this)

Definition at line 264 of file hook.qc.

265{
266 vector a, b;
267 string tex;
268
269 if (this.teleport_time && time > this.teleport_time)
270 {
271 sound(this, CH_SHOTS_SINGLE, SND_Null, VOL_BASE, ATTEN_NORM); // safeguard
272 this.teleport_time = 0;
273 }
274
276
277 int s = W_GunAlign(viewmodels[this.cnt], STAT(GUNALIGN)) - 1;
278 vector vs = hook_shotorigin[s];
279
280 if (this.owner.sv_entnum == player_localentnum - 1)
281 {
283 a = csqcplayer.origin + csqcplayer.view_ofs;
284 else
285 a = view_origin + view_forward * vs.x + view_right * -vs.y + view_up * vs.z;
286 b = this.origin;
287 }
288 else
289 {
290 a = this.velocity;
291 b = this.origin;
292 }
293
294 int t = entcs_GetTeamColor(this.owner.sv_entnum);
295
296 float intensity = autocvar_cl_grapplehook_alpha;
297 float offset = 0;
298 vector rgb = colormapPaletteColor(entcs_GetClientColors(this.sv_entnum - 1) & 0x0F, true);
299 switch (t)
300 {
301 case NUM_TEAM_1: tex = "particles/hook_red"; break;
302 case NUM_TEAM_2: tex = "particles/hook_blue"; break;
303 case NUM_TEAM_3: tex = "particles/hook_yellow"; break;
304 case NUM_TEAM_4: tex = "particles/hook_pink"; break;
305 default: tex = "particles/hook_white"; break;
306 }
307
308 MUTATOR_CALLHOOK(DrawGrapplingHook, this, tex, rgb, t);
309 tex = M_ARGV(1, string);
310 rgb = M_ARGV(2, vector);
311
318
320
321 if (vdist(trace_endpos - atrans, >, 0.5))
322 {
323 setorigin(this, trace_endpos); // hook endpoint!
324 this.angles = vectoangles(trace_endpos - atrans);
325 this.drawmask = MASK_NORMAL;
326 }
327 else
328 this.drawmask = 0;
329}
#define MUTATOR_CALLHOOK(id,...)
Definition base.qh:143
int W_GunAlign(entity this, int preferred_align)
entity csqcplayer
Definition cl_player.qh:26
float cnt
Definition powerups.qc:24
vector view_origin
Definition main.qh:109
entity owner
Definition main.qh:87
int sv_entnum
Definition main.qh:186
vector view_up
Definition main.qh:109
vector hook_shotorigin[4]
Definition main.qh:205
vector view_right
Definition main.qh:109
vector view_forward
Definition main.qh:109
#define colormapPaletteColor(c, isPants)
Definition color.qh:5
#define M_ARGV(x, type)
Definition events.qh:17
float teleport_time
Definition player.qh:218
string Draw_GrapplingHook_trace_callback_tex
Definition hook.qc:252
float Draw_GrapplingHook_trace_callback_a
Definition hook.qc:255
void Draw_GrapplingHook_trace_callback(vector start, vector hit, vector end)
Definition hook.qc:256
vector Draw_GrapplingHook_trace_callback_rgb
Definition hook.qc:254
float autocvar_cl_grapplehook_alpha
Definition hook.qc:242
float Draw_GrapplingHook_trace_callback_rnd
Definition hook.qc:253
float drawmask
const float MASK_NORMAL
vector velocity
float time
vector trace_endpos
float player_localentnum
vector origin
ent angles
Definition ent_cs.qc:146
int entcs_GetTeamColor(int i)
Definition ent_cs.qh:121
int entcs_GetClientColors(int i)
Definition ent_cs.qh:111
void InterpolateOrigin_Do(entity this)
set origin based on iorigin1 (old pos), iorigin2 (desired pos), and time
#define STAT(...)
Definition stats.qh:94
vector WarpZone_TransformOrigin(entity wz, vector org)
Transforms origin org across warpzone wz.
Definition common.qc:489
#define WarpZone_TraceLine_ThroughZone(org, end, nomonsters, forent, zone, cb)
Definition common.qh:47
entity WarpZone_trace_transform
Transform accumulator during a trace.
Definition common.qh:40
#define MOVE_NOTHING
Definition common.qh:35
vector vectoangles(vector v)
string string_null
Definition nil.qh:9
#define NULL
Definition post.qh:14
const float VOL_BASE
Definition sound.qh:36
const int CH_SHOTS_SINGLE
Definition sound.qh:15
const float ATTEN_NORM
Definition sound.qh:30
#define sound(e, c, s, v, a)
Definition sound.qh:52
const int NUM_TEAM_2
Definition teams.qh:14
const int NUM_TEAM_4
Definition teams.qh:16
const int NUM_TEAM_3
Definition teams.qh:15
const int NUM_TEAM_1
Definition teams.qh:13
#define vdist(v, cmp, f)
Vector distance comparison, avoids sqrt().
Definition vector.qh:8
int autocvar_chase_active
Definition view.qh:17
entity viewmodels[MAX_WEAPONSLOTS]
Definition view.qh:108

References angles, ATTEN_NORM, autocvar_chase_active, autocvar_cl_grapplehook_alpha, CH_SHOTS_SINGLE, cnt, colormapPaletteColor, csqcplayer, Draw_GrapplingHook_trace_callback(), Draw_GrapplingHook_trace_callback_a, Draw_GrapplingHook_trace_callback_rgb, Draw_GrapplingHook_trace_callback_rnd, Draw_GrapplingHook_trace_callback_tex, drawmask, entcs_GetClientColors(), entcs_GetTeamColor(), entity(), hook_shotorigin, InterpolateOrigin_Do(), M_ARGV, MASK_NORMAL, MOVE_NOTHING, MUTATOR_CALLHOOK, NULL, NUM_TEAM_1, NUM_TEAM_2, NUM_TEAM_3, NUM_TEAM_4, origin, owner, player_localentnum, sound, STAT, string_null, sv_entnum, teleport_time, time, trace_endpos, vdist, vectoangles(), vector, velocity, view_forward, view_origin, view_right, view_up, viewmodels, VOL_BASE, W_GunAlign(), WarpZone_trace_transform, WarpZone_TraceLine_ThroughZone, and WarpZone_TransformOrigin().

Referenced by NET_HANDLE().

◆ Draw_GrapplingHook_trace_callback()

void Draw_GrapplingHook_trace_callback ( vector start,
vector hit,
vector end )

Definition at line 256 of file hook.qc.

257{
259 for (int i = 0; i < Draw_GrapplingHook_trace_callback_a; ++i)
261 Draw_GrapplingHook_trace_callback_rnd += (0.25 / 8) * vlen(hit - start);
262}
void Draw_CylindricLine(vector from, vector to, float thickness, string texture, float aspect, float shift, vector rgb, float theAlpha, float drawflag, vector vieworg)
Definition draw.qh:10
const float DRAWFLAG_NORMAL
float min(float f,...)

References Draw_CylindricLine(), Draw_GrapplingHook_trace_callback_a, Draw_GrapplingHook_trace_callback_rgb, Draw_GrapplingHook_trace_callback_rnd, Draw_GrapplingHook_trace_callback_tex, DRAWFLAG_NORMAL, min(), vector, view_origin, vlen(), WarpZone_trace_transform, and WarpZone_TransformOrigin().

Referenced by Draw_GrapplingHook().

◆ entityclass()

entityclass ( Hook )

◆ NET_HANDLE()

NET_HANDLE ( ENT_CLIENT_HOOK ,
bool isNew )

Definition at line 343 of file hook.qc.

344{
345 int sf = ReadByte();
346
347 this.HookSilent = sf & 0x80;
349
351
352 if (sf & 1)
353 {
354 this.sv_entnum = ReadByte();
355 int slot = ReadByte();
356 this.owner = playerslots[this.sv_entnum - 1];
357 if (this.sv_entnum == player_localentnum)
358 viewmodels[slot].hook = this;
359 this.cnt = slot;
360 this.HookRange = 0;
361 }
362 if (sf & 2)
363 {
364 this.origin = ReadVector();
365 setorigin(this, this.origin);
366 }
367 if (sf & 4)
368 this.velocity = ReadVector();
369
371
372 if (isNew || !this.teleport_time)
373 {
374 this.draw = Draw_GrapplingHook;
375 if (!IL_CONTAINS(g_drawables, this))
376 IL_PUSH(g_drawables, this);
377 this.entremove = Remove_GrapplingHook;
378
379 setmodel(this, MDL_HOOK);
380 this.drawmask = MASK_NORMAL;
381 }
382
383 this.teleport_time = time + 10;
384 return true;
385}
entity playerslots[255]
Definition main.qh:84
IntrusiveList g_drawables
Definition main.qh:91
#define setmodel(this, m)
Definition model.qh:26
void Draw_GrapplingHook(entity this)
Definition hook.qc:264
void Remove_GrapplingHook(entity this)
Definition hook.qc:331
void InterpolateOrigin_Undo(entity this)
snap origin to iorigin2 (actual origin)
void InterpolateOrigin_Note(entity this)
const int IFLAG_VELOCITY
const int IFLAG_ORIGIN
int iflags
ERASEABLE entity IL_PUSH(IntrusiveList this, entity it)
Push to tail.
ERASEABLE bool IL_CONTAINS(IntrusiveList this, entity it)
#define ReadVector()
Definition net.qh:349
int ReadByte()

References cnt, Draw_GrapplingHook(), drawmask, g_drawables, IFLAG_ORIGIN, IFLAG_VELOCITY, iflags, IL_CONTAINS(), IL_PUSH(), InterpolateOrigin_Note(), InterpolateOrigin_Undo(), MASK_NORMAL, origin, owner, player_localentnum, playerslots, ReadByte(), ReadVector, Remove_GrapplingHook(), setmodel, sv_entnum, teleport_time, time, velocity, and viewmodels.

◆ Remove_GrapplingHook()

void Remove_GrapplingHook ( entity this)

Definition at line 331 of file hook.qc.

332{
333 sound(this, CH_SHOTS_SINGLE, SND_Null, VOL_BASE, ATTEN_NORM);
334
335 for (int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
336 {
337 entity wep = viewmodels[slot];
338 if (wep.hook == this)
339 wep.hook = NULL;
340 }
341}
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
const int MAX_WEAPONSLOTS
Definition weapon.qh:16

References ATTEN_NORM, CH_SHOTS_SINGLE, entity(), MAX_WEAPONSLOTS, NULL, sound, viewmodels, and VOL_BASE.

Referenced by NET_HANDLE().

◆ W_Hook_Attack2()

void W_Hook_Attack2 ( Weapon thiswep,
entity actor,
.entity weaponentity )

Definition at line 56 of file hook.qc.

57{
58 //W_DecreaseAmmo(thiswep, actor, WEP_CVAR_SEC(WEP_HOOK, ammo)); // WEAPONTODO: Figure out how to handle ammo with hook secondary (gravitybomb)
59 W_SetupShot(actor, weaponentity, false, 4, SND_HOOKBOMB_FIRE, CH_WEAPON_A, WEP_CVAR_SEC(WEP_HOOK, damage), WEP_HOOK.m_id | HITTYPE_SECONDARY);
60
61 entity gren = new(hookbomb);
62 gren.owner = gren.realowner = actor;
63 gren.bot_dodge = true;
64 gren.bot_dodgerating = WEP_CVAR_SEC(WEP_HOOK, damage);
67 gren.projectiledeathtype = WEP_HOOK.m_id | HITTYPE_SECONDARY;
68 gren.weaponentity_fld = weaponentity;
69 setorigin(gren, w_shotorg);
70 setsize(gren, '0 0 0', '0 0 0');
71
72 gren.nextthink = time + WEP_CVAR_SEC(WEP_HOOK, lifetime);
74 gren.use = W_Hook_Explode2_use;
76
77 gren.takedamage = DAMAGE_YES;
78 SetResourceExplicit(gren, RES_HEALTH, WEP_CVAR_SEC(WEP_HOOK, health));
79 gren.damageforcescale = WEP_CVAR_SEC(WEP_HOOK, damageforcescale);
80 gren.event_damage = W_Hook_Damage;
81 gren.damagedbycontents = true;
83 gren.missile_flags = MIF_SPLASH | MIF_ARC;
84
85 gren.velocity = '0 0 1' * WEP_CVAR_SEC(WEP_HOOK, speed);
87 gren.velocity += actor.velocity;
88
89 gren.gravity = WEP_CVAR_SEC(WEP_HOOK, gravity);
90 //W_SetupProjVelocity_Basic(gren); // just falling down!
91
92 gren.angles = '0 0 0';
93 gren.flags = FL_PROJECTILE;
95 IL_PUSH(g_bot_dodge, gren);
96
97 CSQCProjectile(gren, true, PROJECTILE_HOOKBOMB, true);
98
99 MUTATOR_CALLHOOK(EditProjectile, actor, gren);
100}
IntrusiveList g_bot_dodge
Definition api.qh:150
float lifetime
Definition powerups.qc:23
float gravity
Definition items.qh:17
void W_Hook_Damage(entity this, entity inflictor, entity attacker, float damage, int deathtype,.entity weaponentity, vector hitloc, vector force)
Definition hook.qc:37
void W_Hook_Explode2_use(entity this, entity actor, entity trigger)
Definition hook.qc:32
void W_Hook_Touch2(entity this, entity toucher)
Definition hook.qc:50
const int FL_PROJECTILE
Definition constants.qh:77
void CSQCProjectile(entity e, float clientanimate, int type, float docull)
IntrusiveList g_damagedbycontents
Definition damage.qh:143
float damageforcescale
const int HITTYPE_SECONDARY
Definition all.qh:31
float speed
Definition dynlight.qc:9
SetResourceExplicit(ent, RES_ARMOR, ReadByte() *DEC_FACTOR)) ENTCS_PROP(NAME
void set_movetype(entity this, int mt)
Definition movetypes.qc:4
const int MOVETYPE_TOSS
Definition movetypes.qh:139
const int PROJECTILE_HOOKBOMB
float health
Legacy fields for the resources. To be removed.
Definition resources.qh:9
#define setthink(e, f)
#define settouch(e, f)
Definition self.qh:77
void adaptor_think2use_hittype_splash(entity this)
Definition common.qc:106
const int MIF_SPLASH
Definition common.qh:58
IntrusiveList g_projectiles
Definition common.qh:70
const int MIF_ARC
Definition common.qh:59
#define PROJECTILE_MAKETRIGGER(e)
Definition common.qh:46
const int CH_WEAPON_A
Definition sound.qh:7
const int DAMAGE_YES
Definition subs.qh:80
int autocvar_g_projectiles_newton_style
Definition tracing.qh:11
vector w_shotorg
Definition tracing.qh:19
#define W_SetupShot(ent, wepent, antilag, recoil, snd, chan, maxdamage, deathtype)
Definition tracing.qh:34
#define WEP_CVAR_SEC(wep, name)
Definition all.qh:339

References adaptor_think2use_hittype_splash(), autocvar_g_projectiles_newton_style, CH_WEAPON_A, CSQCProjectile(), DAMAGE_YES, damageforcescale, entity(), FL_PROJECTILE, g_bot_dodge, g_damagedbycontents, g_projectiles, gravity, health, HITTYPE_SECONDARY, IL_PUSH(), lifetime, MIF_ARC, MIF_SPLASH, MOVETYPE_TOSS, MUTATOR_CALLHOOK, PROJECTILE_HOOKBOMB, PROJECTILE_MAKETRIGGER, set_movetype(), SetResourceExplicit(), setthink, settouch, speed, time, W_Hook_Damage(), W_Hook_Explode2_use(), W_Hook_Touch2(), W_SetupShot, w_shotorg, and WEP_CVAR_SEC.

◆ W_Hook_Damage()

void W_Hook_Damage ( entity this,
entity inflictor,
entity attacker,
float damage,
int deathtype,
.entity weaponentity,
vector hitloc,
vector force )

Definition at line 37 of file hook.qc.

38{
39 if (GetResource(this, RES_HEALTH) <= 0)
40 return;
41 if (!W_CheckProjectileDamage(inflictor.realowner, this.realowner, deathtype, -1)) // no exceptions
42 return; // g_projectiles_damage says to halt
43
44 SetResourceExplicit(this, RES_HEALTH, GetResource(this, RES_HEALTH));
45
46 if (GetResource(this, RES_HEALTH) <= 0)
48}
float GetResource(entity e, Resource res_type)
Returns the current amount of resource the given entity has.
void W_Hook_Explode2(entity this)
Definition hook.qc:19
float W_CheckProjectileDamage(entity inflictor, entity projowner, int deathtype, float exception)
Definition common.qc:45
void W_PrepareExplosionByDamage(entity this, entity attacker, void(entity this) explode)
Definition common.qc:87
entity realowner

References entity(), GetResource(), realowner, SetResourceExplicit(), vector, W_CheckProjectileDamage(), W_Hook_Explode2(), and W_PrepareExplosionByDamage().

Referenced by W_Hook_Attack2().

◆ W_Hook_Explode2()

void W_Hook_Explode2 ( entity this)

Definition at line 19 of file hook.qc.

20{
21 this.event_damage = func_null;
22 settouch(this, func_null);
23 this.effects |= EF_NODRAW;
24
27 this.teleport_time = time;
28 this.dmg_last = 1;
30}
const float HOOK_SECONDARY_DELAY
Definition hook.qc:5
void W_Hook_ExplodeThink(entity this)
Definition hook.qc:6
float effects
float nextthink
const float EF_NODRAW
const int MOVETYPE_NONE
Definition movetypes.qh:133
var void func_null()
float dmg_last
Definition common.qh:27

References dmg_last, EF_NODRAW, effects, entity(), func_null(), HOOK_SECONDARY_DELAY, MOVETYPE_NONE, nextthink, set_movetype(), setthink, settouch, teleport_time, time, and W_Hook_ExplodeThink().

Referenced by W_Hook_Damage(), and W_Hook_Explode2_use().

◆ W_Hook_Explode2_use()

void W_Hook_Explode2_use ( entity this,
entity actor,
entity trigger )

Definition at line 32 of file hook.qc.

33{
34 W_Hook_Explode2(this);
35}

References entity(), and W_Hook_Explode2().

Referenced by W_Hook_Attack2().

◆ W_Hook_ExplodeThink()

void W_Hook_ExplodeThink ( entity this)

Definition at line 6 of file hook.qc.

7{
9 WEP_CVAR_SEC(WEP_HOOK, duration),
10 WEP_CVAR_SEC(WEP_HOOK, power),
11 WEP_CVAR_SEC(WEP_HOOK, damage),
12 WEP_CVAR_SEC(WEP_HOOK, edgedamage),
13 WEP_CVAR_SEC(WEP_HOOK, radius),
14 WEP_CVAR_SEC(WEP_HOOK, force),
15 this.realowner,
17}
float radius
Definition impulse.qh:11
void W_DamageOverTime_Think(entity this, float duration, float duration_power, float damage, float edgedamage, float rad, float force, entity cantbe, float think_delay)
Applies damage over time, called within a think function.
Definition common.qc:285

References entity(), HOOK_SECONDARY_DELAY, radius, realowner, W_DamageOverTime_Think(), and WEP_CVAR_SEC.

Referenced by W_Hook_Explode2().

◆ W_Hook_Touch2()

void W_Hook_Touch2 ( entity this,
entity toucher )

Definition at line 50 of file hook.qc.

51{
53 this.use(this, NULL, NULL);
54}
#define use
entity entity toucher
Definition self.qh:76
#define PROJECTILE_TOUCH(e, t)
Definition common.qh:40

References entity(), NULL, PROJECTILE_TOUCH, toucher, and use.

Referenced by W_Hook_Attack2().

Variable Documentation

◆ autocvar_cl_grapplehook_alpha

float autocvar_cl_grapplehook_alpha = 1

Definition at line 242 of file hook.qc.

Referenced by Draw_GrapplingHook().

◆ Draw_GrapplingHook_trace_callback_a

float Draw_GrapplingHook_trace_callback_a

Definition at line 255 of file hook.qc.

Referenced by Draw_GrapplingHook(), and Draw_GrapplingHook_trace_callback().

◆ Draw_GrapplingHook_trace_callback_rgb

vector Draw_GrapplingHook_trace_callback_rgb

Definition at line 254 of file hook.qc.

Referenced by Draw_GrapplingHook(), and Draw_GrapplingHook_trace_callback().

◆ Draw_GrapplingHook_trace_callback_rnd

float Draw_GrapplingHook_trace_callback_rnd

Definition at line 253 of file hook.qc.

Referenced by Draw_GrapplingHook(), and Draw_GrapplingHook_trace_callback().

◆ Draw_GrapplingHook_trace_callback_tex

string Draw_GrapplingHook_trace_callback_tex

Definition at line 252 of file hook.qc.

Referenced by Draw_GrapplingHook(), and Draw_GrapplingHook_trace_callback().

◆ HOOK_SECONDARY_DELAY

const float HOOK_SECONDARY_DELAY = 0.0625

Definition at line 5 of file hook.qc.

Referenced by W_Hook_Explode2(), and W_Hook_ExplodeThink().