Xonotic
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]
 
float 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 154 of file hook.qc.

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(), frametime, hook_end, hook_length, HOOK_PULLING, HOOK_RELEASING, hook_shotorigin, hook_start, IS_VEHICLE, M_ARGV, makevectors, max(), move_movetype, MOVETYPE_FLY, MOVETYPE_FOLLOW, MOVETYPE_WALK, MUTATOR_CALLHOOK, nextthink, normalize(), origin, PHYS_INPUT_BUTTON_CHAT, realowner, RemoveHook(), round_handler_IsActive, round_handler_IsRoundStarted, set_movetype(), state, time, UNSET_ONGROUND, UpdateCSQCProjectile(), v, 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().

155 {
156  float spd, dist, minlength, pullspeed, ropestretch, ropeairfriction, rubberforce, newlength, rubberforce_overstretch;
157  vector dir, org, end, v0, dv, v, myorg, vs;
158  .entity weaponentity = this.weaponentity_fld;
159  if(this.realowner.(weaponentity).hook != this) // how did that happen?
160  {
161  error("Owner lost the hook!\n");
162  return;
163  }
164  if((this.move_movetype == MOVETYPE_FOLLOW && LostMovetypeFollow(this))
165  || game_stopped || (round_handler_IsActive() && !round_handler_IsRoundStarted())
166  || ((this.aiment.flags & FL_PROJECTILE) && this.aiment.classname != "nade"))
167  {
168  RemoveHook(this);
169  return;
170  }
171  if(this.aiment)
173 
174  this.nextthink = time;
175 
176  int s = W_GunAlign(this.realowner.(weaponentity), STAT(GUNALIGN, this.realowner)) - 1;
177  vs = hook_shotorigin[s];
178 
179  makevectors(this.realowner.v_angle);
180  org = this.realowner.origin + this.realowner.view_ofs + v_forward * vs.x + v_right * -vs.y + v_up * vs.z;
181  myorg = WarpZone_RefSys_TransformOrigin(this.realowner, this, org);
182 
183  if(this.hook_length < 0)
184  this.hook_length = vlen(myorg - this.origin);
185 
187  entity pull_entity = this.realowner;
188  float velocity_multiplier = 1;
189  MUTATOR_CALLHOOK(GrappleHookThink, this, tarzan, pull_entity, velocity_multiplier);
190  tarzan = M_ARGV(1, int);
191  pull_entity = M_ARGV(2, entity);
192  velocity_multiplier = M_ARGV(3, float);
193 
194  if(this.state == 1)
195  {
197  // speed the rope is pulled with
198 
199  rubberforce = autocvar_g_balance_grapplehook_force_rubber;//2000;
200  // force the rope will use if it is stretched
201 
202  rubberforce_overstretch = autocvar_g_balance_grapplehook_force_rubber_overstretch;//1000;
203  // force the rope will use if it is stretched
204 
206  // minimal rope length
207  // if the rope goes below this length, it isn't pulled any more
208 
209  ropestretch = autocvar_g_balance_grapplehook_stretch;//400;
210  // if the rope is stretched by more than this amount, more rope is
211  // given to you again
212 
213  ropeairfriction = autocvar_g_balance_grapplehook_airfriction;//0.2
214  // while hanging on the rope, this friction component will help you a
215  // bit to control the rope
216 
218 
219  dir = this.origin - myorg;
220  dist = vlen(dir);
221  dir = normalize(dir);
222 
223  if(tarzan)
224  {
225  v = v0 = WarpZone_RefSys_TransformVelocity(pull_entity, this, pull_entity.velocity);
226 
227  // first pull the rope...
228  if(this.realowner.(weaponentity).hook_state & HOOK_PULLING)
229  {
230  newlength = this.hook_length;
231  newlength = max(newlength - pullspeed * frametime, minlength);
232 
233  if(newlength < dist - ropestretch) // overstretched?
234  {
235  newlength = dist - ropestretch;
236  if(v * dir < 0) // only if not already moving in hook direction
237  v = v + frametime * dir * rubberforce_overstretch;
238  }
239 
240  this.hook_length = newlength;
241  }
242 
243  if(pull_entity.move_movetype == MOVETYPE_FLY)
244  set_movetype(pull_entity, MOVETYPE_WALK);
245 
246  if(this.realowner.(weaponentity).hook_state & HOOK_RELEASING)
247  {
248  newlength = dist;
249  this.hook_length = newlength;
250  }
251  else
252  {
253  // then pull the player
254  spd = bound(0, (dist - this.hook_length) / ropestretch, 1);
255  v = v * (1 - frametime * ropeairfriction);
256  v = v + frametime * dir * spd * rubberforce;
257 
258  dv = ((v - v0) * dir) * dir;
259  if(tarzan >= 2)
260  {
261  if(this.aiment.move_movetype == MOVETYPE_WALK || this.aiment.classname == "nade")
262  {
263  entity aim_ent = ((IS_VEHICLE(this.aiment) && this.aiment.owner) ? this.aiment.owner : this.aiment);
264  v = v - dv * 0.5;
265  if((frozen_pulling && STAT(FROZEN, this.aiment)) || !frozen_pulling)
266  {
267  this.aiment.velocity = this.aiment.velocity - dv * 0.5;
268  UNSET_ONGROUND(this.aiment);
269  if(this.aiment.flags & FL_PROJECTILE)
271  }
272  if(this.aiment.classname == "nade")
273  this.aiment.nextthink = time + autocvar_g_balance_grapplehook_nade_time; // set time after letting go?
274  aim_ent.pusher = this.realowner;
275  aim_ent.pushltime = time + autocvar_g_maxpushtime;
276  aim_ent.istypefrag = PHYS_INPUT_BUTTON_CHAT(aim_ent);
277  }
278  }
279 
280  UNSET_ONGROUND(pull_entity);
281  }
282 
283  if(!frozen_pulling && !(this.aiment.flags & FL_PROJECTILE))
284  pull_entity.velocity = WarpZone_RefSys_TransformVelocity(this, pull_entity, v * velocity_multiplier);
285 
286  if(frozen_pulling && autocvar_g_balance_grapplehook_pull_frozen == 2 && !STAT(FROZEN, this.aiment))
287  {
288  RemoveHook(this);
289  return;
290  }
291  }
292  else
293  {
294  end = this.origin - dir*50;
295  dist = vlen(end - myorg);
296  if(dist < 200)
297  spd = dist * (pullspeed / 200);
298  else
299  spd = pullspeed;
300  if(spd < 50)
301  spd = 0;
302  this.realowner.velocity = dir*spd;
304 
306  }
307  }
308 
309  makevectors(this.angles.x * '-1 0 0' + this.angles.y * '0 1 0');
310  myorg = WarpZone_RefSys_TransformOrigin(this, this.realowner, this.origin); // + v_forward * (-9);
311 
312  if(myorg != this.hook_start)
313  {
314  this.SendFlags |= 2;
315  this.hook_start = myorg;
316  }
317  if(org != this.hook_end)
318  {
319  this.SendFlags |= 4;
320  this.hook_end = org;
321  }
322 }
float state
Definition: subs.qh:32
#define round_handler_IsActive()
#define PHYS_INPUT_BUTTON_CHAT(s)
Definition: player.qh:155
float MOVETYPE_WALK
Definition: progsdefs.qc:249
float autocvar_g_balance_grapplehook_airfriction
Definition: hook.qh:3
float autocvar_g_balance_grapplehook_speed_pull
Definition: hook.qh:9
entity() spawn
const float HOOK_RELEASING
Definition: hook.qh:31
vector hook_shotorigin[4]
Definition: main.qh:177
float hook_length
Definition: hook.qh:26
entity weaponentity_fld
Definition: weaponsystem.qh:27
float autocvar_g_balance_grapplehook_stretch
Definition: hook.qh:10
origin
Definition: ent_cs.qc:114
int W_GunAlign(entity this, int preferred_align)
#define round_handler_IsRoundStarted()
void WarpZone_RefSys_AddIncrementally(entity me, entity ref)
Definition: common.qc:732
#define UNSET_ONGROUND(s)
Definition: movetypes.qh:18
vector WarpZone_RefSys_TransformVelocity(entity from, entity to, vector vel)
Definition: common.qc:756
float autocvar_g_maxpushtime
Definition: damage.qh:17
vector hook_end
Definition: hook.qc:128
float move_movetype
Definition: movetypes.qh:76
vector hook_start
Definition: hook.qc:128
int autocvar_g_grappling_hook_tarzan
Definition: hook.qc:152
float autocvar_g_balance_grapplehook_force_rubber_overstretch
Definition: hook.qh:5
vector WarpZone_RefSys_TransformOrigin(entity from, entity to, vector org)
Definition: common.qc:748
void UpdateCSQCProjectile(entity e)
vector v_up
Definition: csprogsdefs.qc:31
float autocvar_g_balance_grapplehook_length_min
Definition: hook.qh:7
const float HOOK_PULLING
Definition: hook.qh:30
float frametime
Definition: csprogsdefs.qc:17
#define M_ARGV(x, type)
Definition: events.qh:17
float nextthink
Definition: csprogsdefs.qc:121
vector(float skel, float bonenum) _skel_get_boneabs_hidden
#define IS_VEHICLE(v)
Definition: utils.qh:22
float autocvar_g_balance_grapplehook_force_rubber
Definition: hook.qh:4
vector v
Definition: ent_cs.qc:116
float MOVETYPE_FOLLOW
vector v_right
Definition: csprogsdefs.qc:31
entity realowner
Definition: common.qh:25
#define MUTATOR_CALLHOOK(id,...)
Definition: base.qh:140
entity aiment
Definition: movetypes.qh:90
vector angles
Definition: csprogsdefs.qc:104
int autocvar_g_balance_grapplehook_pull_frozen
Definition: hook.qh:13
float time
Definition: csprogsdefs.qc:16
int dir
Definition: impulse.qc:89
#define makevectors
Definition: post.qh:21
float autocvar_g_balance_grapplehook_nade_time
Definition: hook.qh:14
void set_movetype(entity this, int mt)
float MOVETYPE_FLY
Definition: progsdefs.qc:251
void RemoveHook(entity this)
Definition: hook.qc:96
vector v_forward
Definition: csprogsdefs.qc:31
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ RemoveGrapplingHooks()

void RemoveGrapplingHooks ( entity  pl)

Definition at line 78 of file hook.qc.

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

Referenced by ClientDisconnect(), Freeze(), PlayerDamage(), PutObserverInServer(), Teleport_Touch(), and vehicles_enter().

79 {
80  if(pl.move_movetype == MOVETYPE_FLY)
82 
83  for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
84  {
85  .entity weaponentity = weaponentities[slot];
86  if(!pl.(weaponentity))
87  continue; // continue incase other slots exist?
88  if(pl.(weaponentity).hook)
89  delete(pl.(weaponentity).hook);
90  pl.(weaponentity).hook = NULL;
91  }
92 
93  //pl.disableclientprediction = false;
94 }
float MOVETYPE_WALK
Definition: progsdefs.qc:249
entity hook
Definition: hook.qh:19
const int MAX_WEAPONSLOTS
Definition: weapon.qh:13
#define NULL
Definition: post.qh:17
entity weaponentities[MAX_WEAPONSLOTS]
Definition: weapon.qh:14
void set_movetype(entity this, int mt)
float MOVETYPE_FLY
Definition: progsdefs.qc:251
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ RemoveHook()

void RemoveHook ( entity  this)

Definition at line 96 of file hook.qc.

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

Referenced by Damage(), Freeze(), GrapplingHook_Damage(), GrapplingHookReset(), GrapplingHookThink(), MUTATOR_HOOKFUNCTION(), Unfreeze(), vehicles_spawn(), and WarpZone_Projectile_Touch_ImpactFilter_Callback().

97 {
98  entity player = this.realowner;
99  .entity weaponentity = this.weaponentity_fld;
100 
101  if(player.(weaponentity).hook == this)
102  player.(weaponentity).hook = NULL;
103 
104  if(player.move_movetype == MOVETYPE_FLY)
105  set_movetype(player, MOVETYPE_WALK);
106  delete(this);
107 }
float MOVETYPE_WALK
Definition: progsdefs.qc:249
entity() spawn
entity weaponentity_fld
Definition: weaponsystem.qh:27
#define NULL
Definition: post.qh:17
entity realowner
Definition: common.qh:25
void set_movetype(entity this, int mt)
float MOVETYPE_FLY
Definition: progsdefs.qc:251
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

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

◆ HOOK_FIRING

const float HOOK_FIRING = BIT(0)

Definition at line 28 of file hook.qh.

◆ hook_length

float hook_length

Definition at line 26 of file hook.qh.

Referenced by GrapplingHook_Stop(), and GrapplingHookThink().

◆ HOOK_PULLING

const float HOOK_PULLING = BIT(2)

Definition at line 30 of file hook.qh.

Referenced by GrapplingHookThink().

◆ HOOK_RELEASING

const float HOOK_RELEASING = BIT(3)

Definition at line 31 of file hook.qh.

Referenced by GrapplingHookThink().

◆ HOOK_REMOVING

const float HOOK_REMOVING = BIT(1)

Definition at line 29 of file hook.qh.

◆ hook_shotorigin

vector hook_shotorigin[4]

Definition at line 36 of file hook.qh.

◆ hook_state

float hook_state

Definition at line 33 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 32 of file hook.qh.

◆ state

int state

Definition at line 34 of file hook.qh.