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 106 of file hook.qc.

107{
108 float spd, dist;
109
110 .entity weaponentity = this.weaponentity_fld;
111 if(this.realowner.(weaponentity).hook != this) // how did that happen?
112 {
113 error("Owner lost the hook!\n");
114 return;
115 }
118 || ((this.aiment.flags & FL_PROJECTILE) && this.aiment.classname != "nade"))
119 {
120 RemoveHook(this);
121 return;
122 }
123 if(this.aiment)
125
126 this.nextthink = time;
127
128 int s = W_GunAlign(this.realowner.(weaponentity), STAT(GUNALIGN, this.realowner)) - 1;
129
130 makevectors(this.realowner.v_angle);
131 vector vs = hook_shotorigin[s];
132 vs = v_forward * vs.x + v_right * -vs.y + v_up * vs.z;
133 vector org = this.realowner.origin + this.realowner.view_ofs + vs;
135
136 if(this.hook_length < 0)
137 this.hook_length = vlen(myorg - this.origin);
138
140 entity pull_entity = this.realowner;
141 float velocity_multiplier = 1;
142 MUTATOR_CALLHOOK(GrappleHookThink, this, tarzan, pull_entity, velocity_multiplier);
143 tarzan = M_ARGV(1, int);
144 pull_entity = M_ARGV(2, entity);
145 velocity_multiplier = M_ARGV(3, float);
146
147 if(this.state == 1)
148 {
150 // speed the rope is pulled with
151
153 // force the rope will use if it is stretched
154
155 float rubberforce_overstretch = autocvar_g_balance_grapplehook_force_rubber_overstretch;
156 // force the rope will use if it is stretched
157
159 // minimal rope length
160 // if the rope goes below this length, it isn't pulled any more
161
162 float ropestretch = autocvar_g_balance_grapplehook_stretch;
163 // if the rope is stretched by more than this amount, more rope is
164 // given to you again
165
166 float ropeairfriction = autocvar_g_balance_grapplehook_airfriction;
167 // while hanging on the rope, this friction component will help you a
168 // bit to control the rope
169
171 bool target_isfrozen = (STAT(FROZEN, this.aiment) || StatusEffects_active(STATUSEFFECT_Frozen, this.aiment));
172
173 vector dir = this.origin - myorg;
174 dist = vlen(dir);
175
176 // TODO: Consider changing this back to `dir / dist` after https://github.com/graphitemaster/gmqcc/issues/210.
177 dir = (dist ? dir * (1 / dist) : '0 0 0'); // same as dir = normalize(dir); but cheaper
178
179 if(tarzan)
180 {
181 vector v, v0;
182 v = v0 = WarpZone_RefSys_TransformVelocity(pull_entity, this, pull_entity.velocity);
183
184 // first pull the rope...
185 if(this.realowner.(weaponentity).hook_state & HOOK_PULLING)
186 {
187 float newlength = max(this.hook_length - pullspeed * frametime, minlength);
188
189 if(newlength < dist - ropestretch) // overstretched?
190 {
191 newlength = dist - ropestretch;
192 if(v * dir < 0) // only if not already moving in hook direction
193 v = v + frametime * dir * rubberforce_overstretch;
194 }
195
196 this.hook_length = newlength;
197 }
198
199 if(pull_entity.move_movetype == MOVETYPE_FLY)
200 set_movetype(pull_entity, MOVETYPE_WALK);
201
202 if(this.realowner.(weaponentity).hook_state & HOOK_RELEASING)
203 {
204 this.hook_length = dist;
205 }
206 else
207 {
208 // then pull the player
209 spd = bound(0, (dist - this.hook_length) / ropestretch, 1);
210 v = v * (1 - frametime * ropeairfriction);
211 v = v + frametime * dir * spd * rubberforce;
212
213 vector dv = ((v - v0) * dir) * dir;
214 if(tarzan >= 2)
215 {
216 if(this.aiment.move_movetype == MOVETYPE_WALK || this.aiment.classname == "nade")
217 {
218 entity aim_ent = ((IS_VEHICLE(this.aiment) && this.aiment.owner) ? this.aiment.owner : this.aiment);
219 v = v - dv * 0.5;
220 if((frozen_pulling && target_isfrozen) || !frozen_pulling)
221 {
222 this.aiment.velocity = this.aiment.velocity - dv * 0.5;
224 if(this.aiment.flags & FL_PROJECTILE)
226 }
227 if(this.aiment.classname == "nade")
228 this.aiment.nextthink = time + autocvar_g_balance_grapplehook_nade_time; // set time after letting go?
229 aim_ent.pusher = this.realowner;
230 aim_ent.pushltime = time + autocvar_g_maxpushtime;
231 aim_ent.istypefrag = PHYS_INPUT_BUTTON_CHAT(aim_ent);
232 }
233 }
234
235 UNSET_ONGROUND(pull_entity);
236 }
237
238 if(!frozen_pulling && !(this.aiment.flags & FL_PROJECTILE))
239 pull_entity.velocity = WarpZone_RefSys_TransformVelocity(this, pull_entity, v * velocity_multiplier);
240
241 if(frozen_pulling && autocvar_g_balance_grapplehook_pull_frozen == 2 && !target_isfrozen)
242 {
243 RemoveHook(this);
244 return;
245 }
246 }
247 else
248 {
249 vector end = this.origin - dir * 50;
250 dist = vlen(end - myorg);
251 if(dist < 200)
252 spd = dist * (pullspeed / 200);
253 else
254 spd = pullspeed;
255 if(spd < 50)
256 spd = 0;
257 this.realowner.velocity = dir * spd;
259
261 }
262 }
263
264 makevectors(this.angles.x * '-1 0 0' + this.angles.y * '0 1 0');
265 myorg = WarpZone_RefSys_TransformOrigin(this, this.realowner, this.origin); // + v_forward * (-9);
266
267 if(myorg != this.hook_start)
268 {
269 this.SendFlags |= 2;
270 this.hook_start = myorg;
271 }
272 if(org != this.hook_end)
273 {
274 this.SendFlags |= 4;
275 this.hook_end = org;
276 }
277}
#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:159
float game_stopped
Definition stats.qh:81
int LostMovetypeFollow(entity ent)
Definition util.qc:2063
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:118
#define STAT(...)
Definition stats.qh:82
vector WarpZone_RefSys_TransformVelocity(entity from, entity to, vector vel)
Definition common.qc:773
void WarpZone_RefSys_AddIncrementally(entity me, entity ref)
Definition common.qc:749
vector WarpZone_RefSys_TransformOrigin(entity from, entity to, vector org)
Definition common.qc:765
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:104
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:22
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:239
#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(), 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.