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

Go to the source code of this file.

Functions

void SUB_CalcAngleMove (entity this, vector destangle, float tspeedtype, float tspeed, void(entity this) func)
 
void SUB_CalcAngleMoveDone (entity this)
 
void SUB_CalcAngleMoveEnt (entity ent, vector destangle, float tspeedtype, float tspeed, void(entity this) func)
 
void SUB_CalcMove (entity this, vector tdest, float tspeedtype, float tspeed, void(entity this) func)
 
void SUB_CalcMove_Bezier (entity this, vector tcontrol, vector tdest, float tspeedtype, float tspeed, void(entity this) func)
 
void SUB_CalcMove_controller_setbezier (entity controller, vector org, vector control, vector destin)
 
void SUB_CalcMove_controller_setlinear (entity controller, vector org, vector destin)
 
void SUB_CalcMove_controller_think (entity this)
 
void SUB_CalcMoveDone (entity this)
 
void SUB_CalcMoveEnt (entity ent, vector tdest, float tspeedtype, float tspeed, void(entity this) func)
 
void SUB_Friction (entity this)
 
void SUB_NullThink (entity this)
 
void SUB_SetFade (entity ent, float vanish_time, float fading_time)
 
void SUB_SetFade_Think (entity this)
 
void SUB_VanishOrRemove (entity ent)
 

Variables

float friction
 
float platmovetype_turn
 

Function Documentation

◆ SUB_CalcAngleMove()

void SUB_CalcAngleMove ( entity  this,
vector  destangle,
float  tspeedtype,
float  tspeed,
void(entity this func 
)

Definition at line 331 of file subs.qc.

References angles, avelocity, finalangle, floor(), ltime, nextthink, objerror(), setthink, SUB_CalcAngleMoveDone(), TSPEED_END, TSPEED_LINEAR, TSPEED_START, TSPEED_TIME, vector(), and vlen().

Referenced by SUB_CalcAngleMoveEnt(), and train_wait().

332 {
333  if (!tspeed)
334  objerror (this, "No speed is defined!");
335 
336  // take the shortest distance for the angles
337  this.angles_x -= 360 * floor((this.angles_x - destangle_x) / 360 + 0.5);
338  this.angles_y -= 360 * floor((this.angles_y - destangle_y) / 360 + 0.5);
339  this.angles_z -= 360 * floor((this.angles_z - destangle_z) / 360 + 0.5);
340  vector delta = destangle - this.angles;
341  float traveltime;
342 
343  switch(tspeedtype)
344  {
345  default:
346  case TSPEED_START:
347  case TSPEED_END:
348  case TSPEED_LINEAR:
349  traveltime = vlen (delta) / tspeed;
350  break;
351  case TSPEED_TIME:
352  traveltime = tspeed;
353  break;
354  }
355 
356  this.think1 = func;
357  this.finalangle = destangle;
359 
360  if (traveltime < 0.1)
361  {
362  this.avelocity = '0 0 0';
363  this.nextthink = this.ltime + 0.1;
364  return;
365  }
366 
367  this.avelocity = delta * (1 / traveltime);
368  this.nextthink = this.ltime + traveltime;
369 }
const int TSPEED_LINEAR
Definition: subs.qh:71
vector avelocity
Definition: csprogsdefs.qc:105
void SUB_CalcAngleMoveDone(entity this)
Definition: subs.qc:320
float ltime
Definition: progsdefs.qc:107
const int TSPEED_START
Definition: subs.qh:72
const int TSPEED_TIME
Definition: subs.qh:70
float nextthink
Definition: csprogsdefs.qc:121
vector(float skel, float bonenum) _skel_get_boneabs_hidden
vector finalangle
Definition: subs.qh:30
const int TSPEED_END
Definition: subs.qh:73
#define setthink(e, f)
vector angles
Definition: csprogsdefs.qc:104
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SUB_CalcAngleMoveDone()

void SUB_CalcAngleMoveDone ( entity  this)

Definition at line 320 of file subs.qc.

References angles, avelocity, finalangle, nextthink, and SUB_CalcAngleMoveDone().

Referenced by SUB_CalcAngleMove(), SUB_CalcAngleMoveDone(), and SUB_NullThink().

321 {
322  // After rotating, set angle to exact final angle
323  this.angles = this.finalangle;
324  this.avelocity = '0 0 0';
325  this.nextthink = -1;
326  if (this.think1 && this.think1 != SUB_CalcAngleMoveDone) // avoid endless loops
327  this.think1 (this);
328 }
vector avelocity
Definition: csprogsdefs.qc:105
void SUB_CalcAngleMoveDone(entity this)
Definition: subs.qc:320
float nextthink
Definition: csprogsdefs.qc:121
vector finalangle
Definition: subs.qh:30
vector angles
Definition: csprogsdefs.qc:104
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SUB_CalcAngleMoveEnt()

void SUB_CalcAngleMoveEnt ( entity  ent,
vector  destangle,
float  tspeedtype,
float  tspeed,
void(entity this func 
)

Definition at line 371 of file subs.qc.

References anglemods(), angles, endsWith, entity(), find(), getSendEntity, InitializeEntity(), lodmodelindex0, lodmodelindex1, lodmodelindex2, makevectors, max(), maxs, mins, model, modelindex, movedir, MOVETYPE_NONE, MOVETYPE_PUSH, normalize(), NULL, objerror(), origin, set_movetype(), setorigin(), solid, SOLID_BSP, SOLID_TRIGGER, SUB_CalcAngleMove(), targetname, v_forward, vdist, vector(), and vlen().

372 {
373  SUB_CalcAngleMove (ent, destangle, tspeedtype, tspeed, func);
374 }
void SUB_CalcAngleMove(entity this, vector destangle, float tspeedtype, float tspeed, void(entity this) func)
Definition: subs.qc:331
+ Here is the call graph for this function:

◆ SUB_CalcMove()

void SUB_CalcMove ( entity  this,
vector  tdest,
float  tspeedtype,
float  tspeed,
void(entity this func 
)

Definition at line 256 of file subs.qc.

References finaldest, ltime, nextthink, objerror(), origin, platmovetype_end, platmovetype_start, setthink, SUB_CalcMove_Bezier(), SUB_CalcMoveDone(), TSPEED_END, TSPEED_LINEAR, TSPEED_START, TSPEED_TIME, vector(), velocity, and vlen().

Referenced by door_go_down(), door_go_up(), plat_go_down(), plat_go_up(), SUB_CalcMoveEnt(), and train_next().

257 {
258  vector delta;
259  float traveltime;
260 
261  if (!tspeed)
262  objerror (this, "No speed is defined!");
263 
264  this.think1 = func;
265  this.finaldest = tdest;
266  setthink(this, SUB_CalcMoveDone);
267 
268  if (tdest == this.origin)
269  {
270  this.velocity = '0 0 0';
271  this.nextthink = this.ltime + 0.1;
272  return;
273  }
274 
275  delta = tdest - this.origin;
276 
277  switch(tspeedtype)
278  {
279  default:
280  case TSPEED_START:
281  case TSPEED_END:
282  case TSPEED_LINEAR:
283  traveltime = vlen (delta) / tspeed;
284  break;
285  case TSPEED_TIME:
286  traveltime = tspeed;
287  break;
288  }
289 
290  // Very short animations don't really show off the effect
291  // of controlled animation, so let's just use linear movement.
292  // Alternatively entities can choose to specify non-controlled movement.
293  // The only currently implemented alternative movement is linear (value 1)
294  if (traveltime < 0.15 || (this.platmovetype_start == 1 && this.platmovetype_end == 1)) // is this correct?
295  {
296  this.velocity = delta * (1/traveltime); // QuakeC doesn't allow vector/float division
297  this.nextthink = this.ltime + traveltime;
298  return;
299  }
300 
301  // now just run like a bezier curve...
302  SUB_CalcMove_Bezier(this, (this.origin + tdest) * 0.5, tdest, tspeedtype, tspeed, func);
303 }
float platmovetype_end
Definition: subs.qh:44
const int TSPEED_LINEAR
Definition: subs.qh:71
origin
Definition: ent_cs.qc:114
float ltime
Definition: progsdefs.qc:107
const int TSPEED_START
Definition: subs.qh:72
const int TSPEED_TIME
Definition: subs.qh:70
void SUB_CalcMoveDone(entity this)
Definition: subs.qc:94
float platmovetype_start
Definition: subs.qh:44
float nextthink
Definition: csprogsdefs.qc:121
vector(float skel, float bonenum) _skel_get_boneabs_hidden
const int TSPEED_END
Definition: subs.qh:73
#define setthink(e, f)
vector finaldest
Definition: subs.qh:30
vector velocity
Definition: csprogsdefs.qc:103
void SUB_CalcMove_Bezier(entity this, vector tcontrol, vector tdest, float tspeedtype, float tspeed, void(entity this) func)
Definition: subs.qc:194
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SUB_CalcMove_Bezier()

void SUB_CalcMove_Bezier ( entity  this,
vector  tcontrol,
vector  tdest,
float  tspeedtype,
float  tspeed,
void(entity this func 
)

Definition at line 194 of file subs.qc.

References entity(), finaldest, getthink, ltime, move_controller, new_pure, nextthink, NULL, objerror(), origin, platmovetype, platmovetype_end, platmovetype_start, setthink, SUB_CalcMove_controller_setbezier(), SUB_CalcMove_controller_think(), SUB_CalcMoveDone(), SUB_NullThink(), time, TSPEED_END, TSPEED_LINEAR, TSPEED_START, TSPEED_TIME, velocity, and vlen().

Referenced by SUB_CalcMove(), and train_next().

195 {
196  float traveltime;
197  entity controller;
198 
199  if (!tspeed)
200  objerror (this, "No speed is defined!");
201 
202  this.think1 = func;
203  this.finaldest = tdest;
204  setthink(this, SUB_CalcMoveDone);
205 
206  switch(tspeedtype)
207  {
208  default:
209  case TSPEED_START:
210  traveltime = 2 * vlen(tcontrol - this.origin) / tspeed;
211  break;
212  case TSPEED_END:
213  traveltime = 2 * vlen(tcontrol - tdest) / tspeed;
214  break;
215  case TSPEED_LINEAR:
216  traveltime = vlen(tdest - this.origin) / tspeed;
217  break;
218  case TSPEED_TIME:
219  traveltime = tspeed;
220  break;
221  }
222 
223  if (traveltime < 0.1) // useless anim
224  {
225  this.velocity = '0 0 0';
226  this.nextthink = this.ltime + 0.1;
227  return;
228  }
229 
230  // delete the previous controller, otherwise changing movement midway is glitchy
231  if (this.move_controller != NULL)
232  {
233  delete(this.move_controller);
234  }
235  controller = new_pure(SUB_CalcMove_controller);
236  controller.owner = this;
237  this.move_controller = controller;
238  controller.platmovetype = this.platmovetype;
239  controller.platmovetype_start = this.platmovetype_start;
240  controller.platmovetype_end = this.platmovetype_end;
241  SUB_CalcMove_controller_setbezier(controller, this.origin, tcontrol, tdest);
242  controller.finaldest = (tdest + '0 0 0.125'); // where do we want to end? Offset to overshoot a bit.
243  controller.animstate_starttime = time;
244  controller.animstate_endtime = time + traveltime;
246  controller.think1 = getthink(this);
247 
248  // the thinking is now done by the controller
249  setthink(this, SUB_NullThink); // for PushMove
250  this.nextthink = this.ltime + traveltime;
251 
252  // invoke controller
253  getthink(controller)(controller);
254 }
#define getthink(e)
float platmovetype_end
Definition: subs.qh:44
entity() spawn
entity move_controller
Definition: subs.qh:68
const int TSPEED_LINEAR
Definition: subs.qh:71
origin
Definition: ent_cs.qc:114
string platmovetype
Definition: subs.qh:43
float ltime
Definition: progsdefs.qc:107
const int TSPEED_START
Definition: subs.qh:72
const int TSPEED_TIME
Definition: subs.qh:70
void SUB_CalcMoveDone(entity this)
Definition: subs.qc:94
#define NULL
Definition: post.qh:17
float platmovetype_start
Definition: subs.qh:44
float nextthink
Definition: csprogsdefs.qc:121
void SUB_CalcMove_controller_think(entity this)
Definition: subs.qc:106
void SUB_NullThink(entity this)
Definition: subs.qc:3
const int TSPEED_END
Definition: subs.qh:73
#define new_pure(class)
purely logical entities (.origin doesn&#39;t work)
Definition: oo.qh:62
#define setthink(e, f)
vector finaldest
Definition: subs.qh:30
float time
Definition: csprogsdefs.qc:16
void SUB_CalcMove_controller_setbezier(entity controller, vector org, vector control, vector destin)
Definition: subs.qc:166
vector velocity
Definition: csprogsdefs.qc:103
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SUB_CalcMove_controller_setbezier()

void SUB_CalcMove_controller_setbezier ( entity  controller,
vector  org,
vector  control,
vector  destin 
)

Definition at line 166 of file subs.qc.

References setorigin().

Referenced by SUB_CalcMove_Bezier().

167 {
168  // 0 * (1-t) * (1-t) + 2 * control * t * (1-t) + destin * t * t
169  // 2 * control * t - 2 * control * t * t + destin * t * t
170  // 2 * control * t + (destin - 2 * control) * t * t
171 
172  setorigin(controller, org);
173  control -= org;
174  destin -= org;
175 
176  controller.destvec = 2 * control; // control point
177  controller.destvec2 = destin - 2 * control; // quadratic part required to reach end point
178  // also: initial d/dphasepos origin = 2 * control, final speed = 2 * (destin - control)
179 }
setorigin(ent, v)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SUB_CalcMove_controller_setlinear()

void SUB_CalcMove_controller_setlinear ( entity  controller,
vector  org,
vector  destin 
)

Definition at line 181 of file subs.qc.

References setorigin().

182 {
183  // 0 * (1-t) * (1-t) + 2 * control * t * (1-t) + destin * t * t
184  // 2 * control * t - 2 * control * t * t + destin * t * t
185  // 2 * control * t + (destin - 2 * control) * t * t
186 
187  setorigin(controller, org);
188  destin -= org;
189 
190  controller.destvec = destin; // end point
191  controller.destvec2 = '0 0 0';
192 }
setorigin(ent, v)
+ Here is the call graph for this function:

◆ SUB_CalcMove_controller_think()

void SUB_CalcMove_controller_think ( entity  this)

Definition at line 106 of file subs.qc.

References animstate_endtime, animstate_starttime, cubic_speedfunc(), destvec, destvec2, entity(), finaldest, floor(), getthink, nextthink, NULL, origin, owner, platmovetype_end, platmovetype_start, setthink, time, v, vectoangles(), and vector().

Referenced by SUB_CalcMove_Bezier().

107 {
108  float traveltime;
109  float phasepos;
110  float nexttick;
111  vector delta;
112  vector delta2;
113  vector veloc;
114  vector angloc;
115  vector nextpos;
116  delta = this.destvec;
117  delta2 = this.destvec2;
118  if(time < this.animstate_endtime)
119  {
120  nexttick = time + PHYS_INPUT_FRAMETIME;
121 
122  traveltime = this.animstate_endtime - this.animstate_starttime;
123  phasepos = (nexttick - this.animstate_starttime) / traveltime; // range: [0, 1]
124  phasepos = cubic_speedfunc(this.platmovetype_start, this.platmovetype_end, phasepos);
125  nextpos = this.origin + (delta * phasepos) + (delta2 * phasepos * phasepos);
126  // derivative: delta + 2 * delta2 * phasepos (e.g. for angle positioning)
127 
128  if(this.owner.platmovetype_turn)
129  {
130  vector destangle;
131  destangle = delta + 2 * delta2 * phasepos;
132  destangle = vectoangles(destangle);
133  destangle_x = -destangle_x; // flip up / down orientation
134 
135  // take the shortest distance for the angles
136  vector v = this.owner.angles;
137  v.x -= 360 * floor((v.x - destangle_x) / 360 + 0.5);
138  v.y -= 360 * floor((v.y - destangle_y) / 360 + 0.5);
139  v.z -= 360 * floor((v.z - destangle_z) / 360 + 0.5);
140  this.owner.angles = v;
141  angloc = destangle - this.owner.angles;
142  angloc = angloc * (1 / PHYS_INPUT_FRAMETIME); // so it arrives for the next frame
143  this.owner.avelocity = angloc;
144  }
145  if(nexttick < this.animstate_endtime)
146  veloc = nextpos - this.owner.origin;
147  else
148  veloc = this.finaldest - this.owner.origin;
149  veloc = veloc * (1 / PHYS_INPUT_FRAMETIME); // so it arrives for the next frame
150 
151  this.owner.velocity = veloc;
152  this.nextthink = nexttick;
153  }
154  else
155  {
156  // derivative: delta + 2 * delta2 (e.g. for angle positioning)
157  entity own = this.owner;
158  setthink(own, this.think1);
159  // set the owner's reference to this entity to NULL
160  own.move_controller = NULL;
161  delete(this);
162  getthink(own)(own);
163  }
164 }
vector destvec2
Definition: subs.qh:36
float animstate_endtime
Definition: anim.qh:38
#define getthink(e)
vector destvec
Definition: subs.qh:35
float platmovetype_end
Definition: subs.qh:44
entity() spawn
origin
Definition: ent_cs.qc:114
entity owner
Definition: main.qh:73
#define NULL
Definition: post.qh:17
float platmovetype_start
Definition: subs.qh:44
ERASEABLE float cubic_speedfunc(float startspeedfactor, float endspeedfactor, float spd)
Definition: math.qh:129
float nextthink
Definition: csprogsdefs.qc:121
vector(float skel, float bonenum) _skel_get_boneabs_hidden
vector v
Definition: ent_cs.qc:116
float animstate_starttime
Definition: anim.qh:37
#define setthink(e, f)
vector finaldest
Definition: subs.qh:30
float time
Definition: csprogsdefs.qc:16
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SUB_CalcMoveDone()

void SUB_CalcMoveDone ( entity  this)

Definition at line 94 of file subs.qc.

References finaldest, nextthink, setorigin(), SUB_CalcMoveDone(), and velocity.

Referenced by SUB_CalcMove(), SUB_CalcMove_Bezier(), SUB_CalcMoveDone(), and SUB_NullThink().

95 {
96  // After moving, set origin to exact final destination
97 
98  setorigin (this, this.finaldest);
99  this.velocity = '0 0 0';
100  this.nextthink = -1;
101  if (this.think1 && this.think1 != SUB_CalcMoveDone)
102  this.think1 (this);
103 }
void SUB_CalcMoveDone(entity this)
Definition: subs.qc:94
float nextthink
Definition: csprogsdefs.qc:121
setorigin(ent, v)
vector finaldest
Definition: subs.qh:30
vector velocity
Definition: csprogsdefs.qc:103
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SUB_CalcMoveEnt()

void SUB_CalcMoveEnt ( entity  ent,
vector  tdest,
float  tspeedtype,
float  tspeed,
void(entity this func 
)

Definition at line 305 of file subs.qc.

References SUB_CalcMove().

306 {
307  SUB_CalcMove(ent, tdest, tspeedtype, tspeed, func);
308 }
void SUB_CalcMove(entity this, vector tdest, float tspeedtype, float tspeed, void(entity this) func)
Definition: subs.qc:256
+ Here is the call graph for this function:

◆ SUB_Friction()

void SUB_Friction ( entity  this)

Definition at line 24 of file subs.qc.

References frametime, friction, IS_ONGROUND, nextthink, time, and velocity.

25 {
26  this.nextthink = time;
27  if(IS_ONGROUND(this))
28  this.velocity = this.velocity * (1 - frametime * this.friction);
29 }
#define IS_ONGROUND(s)
Definition: movetypes.qh:16
float frametime
Definition: csprogsdefs.qc:17
float nextthink
Definition: csprogsdefs.qc:121
float friction
Definition: subs.qc:23
float time
Definition: csprogsdefs.qc:16
vector velocity
Definition: csprogsdefs.qc:103

◆ SUB_NullThink()

void SUB_NullThink ( entity  this)

Definition at line 3 of file subs.qc.

References entity(), spawnfunc(), SUB_CalcAngleMoveDone(), and SUB_CalcMoveDone().

Referenced by SUB_CalcMove_Bezier().

3 { }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SUB_SetFade()

void SUB_SetFade ( entity  ent,
float  vanish_time,
float  fading_time 
)

Definition at line 77 of file subs.qc.

References setthink, and SUB_SetFade_Think().

Referenced by Item_InitializeLoot(), Monster_Dead_Fade(), monster_dropitem(), PlayerDamage(), Portal_Remove(), respawn(), and thrown_wep_think().

78 {
79  if (fading_time <= 0)
80  fading_time = 0.01;
81  ent.fade_rate = 1/fading_time;
83  ent.nextthink = vanish_time;
84 }
void SUB_SetFade_Think(entity this)
Definition: subs.qc:57
#define setthink(e, f)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SUB_SetFade_Think()

void SUB_SetFade_Think ( entity  this)

Definition at line 57 of file subs.qc.

References alpha, fade_rate, frametime, nextthink, setthink, SUB_SetFade_Think(), SUB_VanishOrRemove(), and time.

Referenced by SUB_SetFade(), and SUB_SetFade_Think().

58 {
59  if(this.alpha == 0)
60  this.alpha = 1;
62  this.nextthink = time;
63  this.alpha -= frametime * this.fade_rate;
64  if (this.alpha < 0.01)
65  SUB_VanishOrRemove(this);
66  else
67  this.nextthink = time;
68 }
float alpha
Definition: items.qc:14
void SUB_VanishOrRemove(entity ent)
Definition: subs.qc:38
fade_rate
Definition: projectile.qh:14
void SUB_SetFade_Think(entity this)
Definition: subs.qc:57
float frametime
Definition: csprogsdefs.qc:17
float nextthink
Definition: csprogsdefs.qc:121
#define setthink(e, f)
float time
Definition: csprogsdefs.qc:16
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SUB_VanishOrRemove()

void SUB_VanishOrRemove ( entity  ent)

Definition at line 38 of file subs.qc.

References IS_CLIENT.

Referenced by SUB_SetFade_Think(), and thrown_wep_think().

39 {
40  if (IS_CLIENT(ent))
41  {
42  // vanish
43  ent.alpha = -1;
44  ent.effects = 0;
45 #ifdef SVQC
46  ent.glow_size = 0;
47  ent.pflags = 0;
48 #endif
49  }
50  else
51  {
52  // remove
53  delete(ent);
54  }
55 }
#define IS_CLIENT(v)
Definition: utils.qh:13
+ Here is the caller graph for this function:

Variable Documentation

◆ friction

float friction

Definition at line 23 of file subs.qc.

Referenced by SUB_Friction().

◆ platmovetype_turn

float platmovetype_turn

Definition at line 105 of file subs.qc.

Referenced by train_next(), and train_wait().