Xonotic
impulse.qc File Reference
#include "impulse.qh"
+ Include dependency graph for impulse.qc:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void trigger_impulse_touch_accel (entity this, entity toucher)
 
void trigger_impulse_touch_directional (entity this, entity toucher)
 
void trigger_impulse_touch_radial (entity this, entity toucher)
 

Function Documentation

◆ trigger_impulse_touch_accel()

void trigger_impulse_touch_accel ( entity  this,
entity  toucher 
)

Definition at line 59 of file impulse.qc.

References active, ACTIVE_ACTIVE, EXACTTRIGGER_TOUCH, IMPULSE_MAX_PUSHDELTATIME, isPushable(), strength, time, and UpdateCSQCProjectile().

Referenced by trigger_impulse_touch_radial().

60 {
61  float pushdeltatime;
62 
63  if (this.active != ACTIVE_ACTIVE)
64  return;
65 
66  if (!isPushable(toucher))
67  return;
68 
69  EXACTTRIGGER_TOUCH(this, toucher);
70 
71  pushdeltatime = time - toucher.lastpushtime;
72  if (pushdeltatime > IMPULSE_MAX_PUSHDELTATIME)
73  {
74  pushdeltatime = 0;
75  }
76  toucher.lastpushtime = time;
77  if(!pushdeltatime)
78  {
79  return;
80  }
81 
82  // div0: ticrate independent, 1 = identity (not 20)
83  toucher.velocity = toucher.velocity * (this.strength ** pushdeltatime);
84 
85 #ifdef SVQC
86  UpdateCSQCProjectile(toucher);
87 #endif
88 }
float strength
Definition: impulse.qh:13
#define EXACTTRIGGER_TOUCH(e, t)
Definition: common.qh:116
void UpdateCSQCProjectile(entity e)
const int ACTIVE_ACTIVE
Definition: defs.qh:37
int active
Definition: defs.qh:34
const float IMPULSE_MAX_PUSHDELTATIME
Definition: impulse.qh:26
float time
Definition: csprogsdefs.qc:16
bool isPushable(entity e)
Definition: triggers.qc:3
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ trigger_impulse_touch_directional()

void trigger_impulse_touch_directional ( entity  this,
entity  toucher 
)

Definition at line 3 of file impulse.qc.

References active, ACTIVE_ACTIVE, entity(), EXACTTRIGGER_TOUCH, find(), IMPULSE_DIRECTIONAL_MAX_ACCEL_FACTOR, IMPULSE_DIRECTIONAL_SPEEDTARGET, IMPULSE_MAX_PUSHDELTATIME, isPushable(), min(), normalize(), NULL, objerror(), spawnflags, strength, target, targetname, time, UNSET_ONGROUND, and UpdateCSQCProjectile().

Referenced by trigger_impulse_touch_radial().

4 {
5  entity targ;
6  float pushdeltatime;
7  float str;
8 
9  if (this.active != ACTIVE_ACTIVE)
10  return;
11 
12  if (!isPushable(toucher))
13  return;
14 
15  EXACTTRIGGER_TOUCH(this, toucher);
16 
17  targ = find(NULL, targetname, this.target);
18  if(!targ)
19  {
20  objerror(this, "trigger_force without a (valid) .target!\n");
21  delete(this);
22  return;
23  }
24 
25  // falloff is not supported because radius is always 0 in directional mode
26  str = this.strength;
27 
28  pushdeltatime = time - toucher.lastpushtime;
29  if (pushdeltatime > IMPULSE_MAX_PUSHDELTATIME)
30  {
31  pushdeltatime = 0;
32  }
33  toucher.lastpushtime = time;
34  if(!pushdeltatime)
35  {
36  return;
37  }
38 
40  {
41  float addspeed = str - toucher.velocity * normalize(targ.origin - this.origin);
42  if (addspeed > 0)
43  {
44  float accelspeed = min(IMPULSE_DIRECTIONAL_MAX_ACCEL_FACTOR * pushdeltatime * str, addspeed);
45  toucher.velocity += accelspeed * normalize(targ.origin - this.origin);
46  }
47  }
48  else
49  toucher.velocity = toucher.velocity + normalize(targ.origin - this.origin) * str * pushdeltatime;
50 
51  UNSET_ONGROUND(toucher);
52 
53 #ifdef SVQC
54  UpdateCSQCProjectile(toucher);
55 #endif
56 }
const int IMPULSE_DIRECTIONAL_SPEEDTARGET
Definition: impulse.qh:20
float strength
Definition: impulse.qh:13
#define EXACTTRIGGER_TOUCH(e, t)
Definition: common.qh:116
entity() spawn
#define UNSET_ONGROUND(s)
Definition: movetypes.qh:18
float spawnflags
Definition: progsdefs.qc:191
void UpdateCSQCProjectile(entity e)
const int ACTIVE_ACTIVE
Definition: defs.qh:37
#define NULL
Definition: post.qh:17
const float IMPULSE_DIRECTIONAL_MAX_ACCEL_FACTOR
Definition: impulse.qh:28
string targetname
Definition: progsdefs.qc:194
int active
Definition: defs.qh:34
const float IMPULSE_MAX_PUSHDELTATIME
Definition: impulse.qh:26
string target
Definition: progsdefs.qc:193
float time
Definition: csprogsdefs.qc:16
bool isPushable(entity e)
Definition: triggers.qc:3
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ trigger_impulse_touch_radial()

void trigger_impulse_touch_radial ( entity  this,
entity  toucher 
)

Definition at line 91 of file impulse.qc.

References active, ACTIVE_ACTIVE, entity(), EXACTTRIGGER_TOUCH, falloff, FALLOFF_LINEAR, FALLOFF_LINEAR_INV, IMPULSE_DEFAULT_ACCEL_STRENGTH, IMPULSE_DEFAULT_DIRECTIONAL_STRENGTH, IMPULSE_DEFAULT_RADIAL_STRENGTH, IMPULSE_MAX_PUSHDELTATIME, isPushable(), min(), move_time, NET_HANDLE, normalize(), origin, radius, REGISTER_NET_LINKED, setorigin(), solid, SOLID_TRIGGER, spawnflags, spawnfunc(), strength, target, time, to, trigger_impulse_touch_accel(), trigger_impulse_touch_directional(), UpdateCSQCProjectile(), vlen(), WriteByte(), and WriteCoord().

92 {
93  float pushdeltatime;
94  float str;
95 
96  if (this.active != ACTIVE_ACTIVE)
97  return;
98 
99  if (!isPushable(toucher))
100  return;
101 
102  EXACTTRIGGER_TOUCH(this, toucher);
103 
104  pushdeltatime = time - toucher.lastpushtime;
105  if (pushdeltatime > IMPULSE_MAX_PUSHDELTATIME)
106  {
107  pushdeltatime = 0;
108  }
109  toucher.lastpushtime = time;
110  if(!pushdeltatime)
111  {
112  return;
113  }
114 
115  setsize(this, '-1 -1 -1' * this.radius,'1 1 1' * this.radius);
116 
117  str = min(this.radius, vlen(this.origin - toucher.origin));
118 
119  if(this.falloff == FALLOFF_LINEAR)
120  str = (1 - str / this.radius) * this.strength; // 1 in the inside
121  else if(this.falloff == FALLOFF_LINEAR_INV)
122  str = (str / this.radius) * this.strength; // 0 in the inside
123  else
124  str = this.strength;
125 
126  toucher.velocity = toucher.velocity + normalize(toucher.origin - this.origin) * str * pushdeltatime;
127 
128 #ifdef SVQC
129  UpdateCSQCProjectile(toucher);
130 #endif
131 }
int falloff
Definition: impulse.qh:12
float strength
Definition: impulse.qh:13
#define EXACTTRIGGER_TOUCH(e, t)
Definition: common.qh:116
float radius
Definition: impulse.qh:11
const int FALLOFF_LINEAR
Definition: impulse.qh:17
origin
Definition: ent_cs.qc:114
void UpdateCSQCProjectile(entity e)
const int ACTIVE_ACTIVE
Definition: defs.qh:37
int active
Definition: defs.qh:34
const float IMPULSE_MAX_PUSHDELTATIME
Definition: impulse.qh:26
float time
Definition: csprogsdefs.qc:16
bool isPushable(entity e)
Definition: triggers.qc:3
const int FALLOFF_LINEAR_INV
Definition: impulse.qh:18
+ Here is the call graph for this function: