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

Go to the source code of this file.

Functions

void GrapplingHookThink (entity this)
void RemoveGrapplingHooks (entity pl)
void RemoveHook (entity this)

Variables

float autocvar_g_balance_grapplehook_airfriction
bool autocvar_g_balance_grapplehook_crouchslide
float autocvar_g_balance_grapplehook_damagedbycontents
float autocvar_g_balance_grapplehook_force_rubber
float autocvar_g_balance_grapplehook_force_rubber_overstretch
bool autocvar_g_balance_grapplehook_gravity
float autocvar_g_balance_grapplehook_health
float autocvar_g_balance_grapplehook_length_min
float autocvar_g_balance_grapplehook_nade_time
int autocvar_g_balance_grapplehook_pull_frozen
float autocvar_g_balance_grapplehook_refire
float autocvar_g_balance_grapplehook_speed_fly
float autocvar_g_balance_grapplehook_speed_pull
float autocvar_g_balance_grapplehook_stretch
entity hook
const float HOOK_FIRING = BIT(0)
float hook_length
const float HOOK_PULLING = BIT(2)
const float HOOK_RELEASING = BIT(3)
const float HOOK_REMOVING = BIT(1)
vector hook_shotorigin [4]
int hook_state
float hook_time
const float HOOK_WAITING_FOR_RELEASE = BIT(4)
int state

Function Documentation

◆ GrapplingHookThink()

void GrapplingHookThink ( entity this)

Definition at line 103 of file hook.qc.

104{
105 .entity weaponentity = this.weaponentity_fld;
106 if (this.realowner.(weaponentity).hook != this) // how did that happen?
107 {
108 error("Owner lost the hook!\n");
109 return;
110 }
113 || ((this.aiment.flags & FL_PROJECTILE) && this.aiment.classname != "nade"))
114 {
115 RemoveHook(this);
116 return;
117 }
118 if (this.aiment)
120
121 this.nextthink = time;
122
123 int s = W_GunAlign(this.realowner.(weaponentity), STAT(GUNALIGN, this.realowner)) - 1;
124
125 makevectors(this.realowner.v_angle);
126 vector vs = hook_shotorigin[s];
127 vs = v_forward * vs.x + v_right * -vs.y + v_up * vs.z;
128 vector org = this.realowner.origin + this.realowner.view_ofs + vs;
130
131 if (this.hook_length < 0)
132 this.hook_length = vlen(myorg - this.origin);
133
134 entity pull_entity = this.realowner;
136 float velocity_multiplier = 1;
137 MUTATOR_CALLHOOK(GrappleHookThink, this, tarzan, pull_entity, velocity_multiplier);
138 tarzan = M_ARGV(1, int);
139 pull_entity = M_ARGV(2, entity);
140 velocity_multiplier = M_ARGV(3, float);
141
142 if (this.state == 1)
143 {
145 // speed the rope is pulled with
146
148 // force the rope will use if it is stretched
149
150 float rubberforce_overstretch = autocvar_g_balance_grapplehook_force_rubber_overstretch;
151 // force the rope will use if it is stretched
152
154 // minimal rope length
155 // if the rope goes below this length, it isn't pulled any more
156
157 float ropestretch = autocvar_g_balance_grapplehook_stretch;
158 // if the rope is stretched by more than this amount, more rope is
159 // given to you again
160
161 float ropeairfriction = autocvar_g_balance_grapplehook_airfriction;
162 // while hanging on the rope, this friction component will help you a
163 // bit to control the rope
164
166 bool target_isfrozen = (STAT(FROZEN, this.aiment) || StatusEffects_active(STATUSEFFECT_Frozen, this.aiment));
167
168 vector dir = this.origin - myorg;
169 float dist = vlen(dir);
170
171 // TODO: Consider changing this back to `dir / dist` after https://github.com/graphitemaster/gmqcc/issues/210.
172 dir = (dist ? dir * (1 / dist) : '0 0 0'); // same as dir = normalize(dir); but cheaper
173
174 float spd;
175 if (tarzan)
176 {
177 vector v, v0;
178 v = v0 = WarpZone_RefSys_TransformVelocity(pull_entity, this, pull_entity.velocity);
179
180 // first pull the rope...
181 if (this.realowner.(weaponentity).hook_state & HOOK_PULLING)
182 {
183 float newlength = max(this.hook_length - pullspeed * frametime, minlength);
184
185 if (newlength < dist - ropestretch) // overstretched?
186 {
187 newlength = dist - ropestretch;
188 if (v * dir < 0) // only if not already moving in hook direction
189 v += frametime * dir * rubberforce_overstretch;
190 }
191
192 this.hook_length = newlength;
193 }
194
195 if (pull_entity.move_movetype == MOVETYPE_FLY)
196 set_movetype(pull_entity, MOVETYPE_WALK);
197
198 if (this.realowner.(weaponentity).hook_state & HOOK_RELEASING)
199 this.hook_length = dist;
200 else
201 {
202 // then pull the player
203 spd = bound(0, (dist - this.hook_length) / ropestretch, 1);
204 v *= 1 - frametime * ropeairfriction;
205 v += frametime * dir * spd * rubberforce;
206
207 vector dv = ((v - v0) * dir) * dir;
208 if (tarzan >= 2)
209 {
210 if (this.aiment.move_movetype == MOVETYPE_WALK || this.aiment.classname == "nade")
211 {
212 entity aim_ent = ((IS_VEHICLE(this.aiment) && this.aiment.owner) ? this.aiment.owner : this.aiment);
213 v -= dv * 0.5;
214 if ((frozen_pulling && target_isfrozen) || !frozen_pulling)
215 {
216 this.aiment.velocity -= dv * 0.5;
218 if (this.aiment.flags & FL_PROJECTILE)
220 }
221 if (this.aiment.classname == "nade")
222 this.aiment.nextthink = time + autocvar_g_balance_grapplehook_nade_time; // set time after letting go?
223 aim_ent.pusher = this.realowner;
224 aim_ent.pushltime = time + autocvar_g_maxpushtime;
225 aim_ent.istypefrag = PHYS_INPUT_BUTTON_CHAT(aim_ent);
226 }
227 }
228
229 UNSET_ONGROUND(pull_entity);
230 }
231
232 if (!frozen_pulling && !(this.aiment.flags & FL_PROJECTILE))
233 pull_entity.velocity = WarpZone_RefSys_TransformVelocity(this, pull_entity, v * velocity_multiplier);
234
235 if (frozen_pulling && autocvar_g_balance_grapplehook_pull_frozen == 2 && !target_isfrozen)
236 {
237 RemoveHook(this);
238 return;
239 }
240 }
241 else
242 {
243 vector end = this.origin - dir * 50;
244 dist = vlen(end - myorg);
245 if (dist < 200)
246 spd = dist * (pullspeed / 200);
247 else
248 spd = pullspeed;
249 if (spd < 50)
250 spd = 0;
251 this.realowner.velocity = dir * spd;
253
255 }
256 }
257
258 makevectors(this.angles.x * '-1 0 0' + this.angles.y * '0 1 0');
259 myorg = WarpZone_RefSys_TransformOrigin(this, this.realowner, this.origin); // + v_forward * (-9);
260
261 if (myorg != this.hook_start)
262 {
263 this.SendFlags |= 2;
264 this.hook_start = myorg;
265 }
266 if (org != this.hook_end)
267 {
268 this.SendFlags |= 4;
269 this.hook_end = org;
270 }
271}
#define MUTATOR_CALLHOOK(id,...)
Definition base.qh:143
int W_GunAlign(entity this, int preferred_align)
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
vector hook_shotorigin[4]
Definition main.qh:205
#define M_ARGV(x, type)
Definition events.qh:17
#define PHYS_INPUT_BUTTON_CHAT(s)
Definition player.qh:161
float game_stopped
Definition stats.qh:81
int LostMovetypeFollow(entity ent)
Definition util.qc:2159
const int FL_PROJECTILE
Definition constants.qh:85
vector v_up
float frametime
float time
vector v_right
float nextthink
vector v_forward
vector origin
void UpdateCSQCProjectile(entity e)
float autocvar_g_maxpushtime
Definition damage.qh:17
int state
ent angles
Definition ent_cs.qc:121
int SendFlags
Definition net.qh:159
#define STAT(...)
Definition stats.qh:82
vector WarpZone_RefSys_TransformVelocity(entity from, entity to, vector vel)
Definition common.qc:771
void WarpZone_RefSys_AddIncrementally(entity me, entity ref)
Definition common.qc:747
vector WarpZone_RefSys_TransformOrigin(entity from, entity to, vector org)
Definition common.qc:763
float bound(float min, float value, float max)
float vlen(vector v)
float max(float f,...)
void set_movetype(entity this, int mt)
Definition movetypes.qc:4
const int MOVETYPE_WALK
Definition movetypes.qh:132
const int MOVETYPE_FOLLOW
Definition movetypes.qh:141
entity aiment
Definition movetypes.qh:90
float move_movetype
Definition movetypes.qh:76
#define UNSET_ONGROUND(s)
Definition movetypes.qh:18
const int MOVETYPE_FLY
Definition movetypes.qh:134
#define makevectors
Definition post.qh:21
#define error
Definition pre.qh:6
#define round_handler_IsActive()
#define round_handler_IsRoundStarted()
vector
Definition self.qh:92
vector org
Definition self.qh:92
vector hook_start
Definition hook.qc:80
void RemoveHook(entity this)
Definition hook.qc:48
int autocvar_g_grappling_hook_tarzan
Definition hook.qc:101
vector hook_end
Definition hook.qc:80
const float HOOK_RELEASING
Definition hook.qh:30
float hook_length
Definition hook.qh:25
const float HOOK_PULLING
Definition hook.qh:29
float autocvar_g_balance_grapplehook_force_rubber
Definition hook.qh:4
int autocvar_g_balance_grapplehook_pull_frozen
Definition hook.qh:13
float autocvar_g_balance_grapplehook_airfriction
Definition hook.qh:3
float autocvar_g_balance_grapplehook_force_rubber_overstretch
Definition hook.qh:5
float autocvar_g_balance_grapplehook_length_min
Definition hook.qh:7
float autocvar_g_balance_grapplehook_speed_pull
Definition hook.qh:9
float autocvar_g_balance_grapplehook_nade_time
Definition hook.qh:14
float autocvar_g_balance_grapplehook_stretch
Definition hook.qh:10
int dir
Definition impulse.qc:89
bool StatusEffects_active(StatusEffect this, entity actor)
entity realowner
#define IS_VEHICLE(v)
Definition utils.qh:24
entity weaponentity_fld

References aiment, angles, autocvar_g_balance_grapplehook_airfriction, autocvar_g_balance_grapplehook_force_rubber, autocvar_g_balance_grapplehook_force_rubber_overstretch, autocvar_g_balance_grapplehook_length_min, autocvar_g_balance_grapplehook_nade_time, autocvar_g_balance_grapplehook_pull_frozen, autocvar_g_balance_grapplehook_speed_pull, autocvar_g_balance_grapplehook_stretch, autocvar_g_grappling_hook_tarzan, autocvar_g_maxpushtime, bound(), dir, entity(), error, FL_PROJECTILE, frametime, game_stopped, hook_end, hook_length, HOOK_PULLING, HOOK_RELEASING, hook_shotorigin, hook_start, IS_VEHICLE, LostMovetypeFollow(), M_ARGV, makevectors, max(), move_movetype, MOVETYPE_FLY, MOVETYPE_FOLLOW, MOVETYPE_WALK, MUTATOR_CALLHOOK, nextthink, org, origin, PHYS_INPUT_BUTTON_CHAT, realowner, RemoveHook(), round_handler_IsActive, round_handler_IsRoundStarted, SendFlags, set_movetype(), STAT, state, StatusEffects_active(), time, UNSET_ONGROUND, UpdateCSQCProjectile(), v_forward, v_right, v_up, vector, vlen(), W_GunAlign(), WarpZone_RefSys_AddIncrementally(), WarpZone_RefSys_TransformOrigin(), WarpZone_RefSys_TransformVelocity(), and weaponentity_fld.

Referenced by FireGrapplingHook(), and GrapplingHook_Stop().

◆ RemoveGrapplingHooks()

void RemoveGrapplingHooks ( entity pl)

Definition at line 30 of file hook.qc.

31{
32 if (pl.move_movetype == MOVETYPE_FLY)
34
35 for (int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
36 {
37 .entity weaponentity = weaponentities[slot];
38 if (!pl.(weaponentity))
39 continue; // continue incase other slots exist?
40 if (pl.(weaponentity).hook)
41 delete(pl.(weaponentity).hook);
42 pl.(weaponentity).hook = NULL;
43 }
44
45 //pl.disableclientprediction = false;
46}
entity hook
Definition player.qh:238
#define NULL
Definition post.qh:14
const int MAX_WEAPONSLOTS
Definition weapon.qh:16
entity weaponentities[MAX_WEAPONSLOTS]
Definition weapon.qh:17

References entity(), hook, MAX_WEAPONSLOTS, MOVETYPE_FLY, MOVETYPE_WALK, NULL, set_movetype(), and weaponentities.

Referenced by bumblebee_gunner_enter(), ClientDisconnect(), freezetag_Freeze(), PlayerDamage(), PutObserverInServer(), target_teleport_use(), Teleport_Touch(), and vehicles_enter().

◆ RemoveHook()

void RemoveHook ( entity this)

Definition at line 48 of file hook.qc.

49{
50 entity player = this.realowner;
51 .entity weaponentity = this.weaponentity_fld;
52
53 if (player.(weaponentity).hook == this)
54 player.(weaponentity).hook = NULL;
55
56 if (player.move_movetype == MOVETYPE_FLY)
58 delete(this);
59}

References entity(), hook, MOVETYPE_FLY, MOVETYPE_WALK, NULL, realowner, set_movetype(), and weaponentity_fld.

Referenced by Damage(), freezetag_Freeze(), freezetag_Unfreeze(), GrapplingHook_Damage(), GrapplingHookReset(), GrapplingHookThink(), MUTATOR_HOOKFUNCTION(), nade_boom(), nade_touch(), vehicles_spawn(), and WarpZone_Projectile_Touch_ImpactFilter_Callback().

Variable Documentation

◆ autocvar_g_balance_grapplehook_airfriction

float autocvar_g_balance_grapplehook_airfriction

Definition at line 3 of file hook.qh.

Referenced by GrapplingHookThink().

◆ autocvar_g_balance_grapplehook_crouchslide

bool autocvar_g_balance_grapplehook_crouchslide

Definition at line 16 of file hook.qh.

◆ autocvar_g_balance_grapplehook_damagedbycontents

float autocvar_g_balance_grapplehook_damagedbycontents

Definition at line 11 of file hook.qh.

Referenced by FireGrapplingHook().

◆ autocvar_g_balance_grapplehook_force_rubber

float autocvar_g_balance_grapplehook_force_rubber

Definition at line 4 of file hook.qh.

Referenced by GrapplingHookThink().

◆ autocvar_g_balance_grapplehook_force_rubber_overstretch

float autocvar_g_balance_grapplehook_force_rubber_overstretch

Definition at line 5 of file hook.qh.

Referenced by GrapplingHookThink().

◆ autocvar_g_balance_grapplehook_gravity

bool autocvar_g_balance_grapplehook_gravity

Definition at line 15 of file hook.qh.

Referenced by FireGrapplingHook().

◆ autocvar_g_balance_grapplehook_health

float autocvar_g_balance_grapplehook_health

Definition at line 6 of file hook.qh.

Referenced by FireGrapplingHook().

◆ autocvar_g_balance_grapplehook_length_min

float autocvar_g_balance_grapplehook_length_min

Definition at line 7 of file hook.qh.

Referenced by GrapplingHookThink().

◆ autocvar_g_balance_grapplehook_nade_time

float autocvar_g_balance_grapplehook_nade_time

Definition at line 14 of file hook.qh.

Referenced by GrapplingHookThink().

◆ autocvar_g_balance_grapplehook_pull_frozen

int autocvar_g_balance_grapplehook_pull_frozen

Definition at line 13 of file hook.qh.

Referenced by GrapplingHookThink().

◆ autocvar_g_balance_grapplehook_refire

float autocvar_g_balance_grapplehook_refire

Definition at line 12 of file hook.qh.

◆ autocvar_g_balance_grapplehook_speed_fly

float autocvar_g_balance_grapplehook_speed_fly

Definition at line 8 of file hook.qh.

Referenced by FireGrapplingHook().

◆ autocvar_g_balance_grapplehook_speed_pull

float autocvar_g_balance_grapplehook_speed_pull

Definition at line 9 of file hook.qh.

Referenced by GrapplingHookThink().

◆ autocvar_g_balance_grapplehook_stretch

float autocvar_g_balance_grapplehook_stretch

Definition at line 10 of file hook.qh.

Referenced by GrapplingHookThink().

◆ hook

entity hook

Definition at line 19 of file hook.qh.

◆ HOOK_FIRING

const float HOOK_FIRING = BIT(0)

Definition at line 27 of file hook.qh.

◆ hook_length

float hook_length

Definition at line 25 of file hook.qh.

Referenced by GrapplingHook_Stop(), and GrapplingHookThink().

◆ HOOK_PULLING

const float HOOK_PULLING = BIT(2)

Definition at line 29 of file hook.qh.

Referenced by GrapplingHookThink().

◆ HOOK_RELEASING

const float HOOK_RELEASING = BIT(3)

Definition at line 30 of file hook.qh.

Referenced by GrapplingHookThink().

◆ HOOK_REMOVING

const float HOOK_REMOVING = BIT(1)

Definition at line 28 of file hook.qh.

◆ hook_shotorigin

vector hook_shotorigin[4]

Definition at line 35 of file hook.qh.

◆ hook_state

int hook_state

Definition at line 32 of file hook.qh.

◆ hook_time

float hook_time

Definition at line 24 of file hook.qh.

◆ HOOK_WAITING_FOR_RELEASE

const float HOOK_WAITING_FOR_RELEASE = BIT(4)

Definition at line 31 of file hook.qh.

◆ state

int state

Definition at line 33 of file hook.qh.