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

Go to the source code of this file.

Functions

void train_next (entity this)
 
entity train_next_find (entity this)
 
void train_wait (entity this)
 

Variables

entity future_target
 
float train_wait_turning
 

Function Documentation

◆ train_next()

void train_next ( entity  this)

Definition at line 83 of file train.qc.

References _sound, ATTEN_IDLE, autocvar_cl_projectiles_sloppy, CH_TRIGGER_SINGLE, classname, curvetarget, dmg, dmgtime, dmgtime2, drawmask, EF_LOWPRECISION, effects, entity(), find(), func_null(), future_target, g_drawables, generic_plat_blocked(), height, IL_PUSH(), InitializeEntity(), lip, ltime, mangle, MASK_NORMAL, message, mins, model, move_time, Movetype_Physics_MatchServer(), MOVETYPE_PUSH, NET_HANDLE, nextthink, noise, NULL, objerror(), platmovetype, platmovetype_end, platmovetype_end_default, platmovetype_start, platmovetype_start_default, platmovetype_turn, pos1, pos2, precache_sound(), ReadString, REGISTER_NET_LINKED, set_movetype(), set_platmovetype(), setorigin(), setthink, SF_TRIGGER_INIT, SF_TRIGGER_RESET, size, solid, SOLID_BSP, spawnflags, spawnfunc(), speed, state, strzone(), SUB_CalcMove(), SUB_CalcMove_Bezier(), target, target_random, targetname, time, to, TRAIN_CURVE, TRAIN_NEEDACTIVATION, train_next_find(), TRAIN_TURN, train_wait(), TSPEED_LINEAR, use, vector(), view_ofs, VOL_BASE, wait, WriteByte(), WriteShort(), and WriteString().

Referenced by train_wait().

84 {
85  entity targ = NULL, cp = NULL;
86  vector cp_org = '0 0 0';
87 
88  targ = this.future_target;
89 
90  this.target = targ.target;
91  this.target_random = targ.target_random;
92  this.future_target = train_next_find(targ);
93 
94  if (this.spawnflags & TRAIN_CURVE)
95  {
96  if(targ.curvetarget)
97  {
98  cp = find(NULL, targetname, targ.curvetarget); // get its second target (the control point)
99  cp_org = cp.origin - this.view_ofs; // no control point found, assume a straight line to the destination
100  }
101  }
102  if (this.target == "")
103  objerror(this, "train_next: no next target");
104  this.wait = targ.wait;
105  if (!this.wait)
106  this.wait = 0.1;
107 
108  if(targ.platmovetype)
109  {
110  // this path_corner contains a movetype overrider, apply it
111  this.platmovetype_start = targ.platmovetype_start;
112  this.platmovetype_end = targ.platmovetype_end;
113  }
114  else
115  {
116  // this path_corner doesn't contain a movetype overrider, use the train's defaults
119  }
120 
121  if (targ.speed)
122  {
123  if (cp)
124  SUB_CalcMove_Bezier(this, cp_org, targ.origin - this.view_ofs, TSPEED_LINEAR, targ.speed, train_wait);
125  else
126  SUB_CalcMove(this, targ.origin - this.view_ofs, TSPEED_LINEAR, targ.speed, train_wait);
127  }
128  else
129  {
130  if (cp)
131  SUB_CalcMove_Bezier(this, cp_org, targ.origin - this.view_ofs, TSPEED_LINEAR, this.speed, train_wait);
132  else
133  SUB_CalcMove(this, targ.origin - this.view_ofs, TSPEED_LINEAR, this.speed, train_wait);
134  }
135 
136  if(this.noise != "")
138 }
const int TRAIN_CURVE
Definition: train.qh:4
float target_random
Definition: subs.qh:57
entity future_target
Definition: train.qc:3
vector view_ofs
Definition: progsdefs.qc:151
string noise
Definition: progsdefs.qc:209
float platmovetype_end
Definition: subs.qh:44
entity train_next_find(entity this)
Definition: train.qc:66
entity() spawn
const int TSPEED_LINEAR
Definition: subs.qh:71
float platmovetype_end_default
Definition: platforms.qc:200
void SUB_CalcMove(entity this, vector tdest, float tspeedtype, float tspeed, void(entity this) func)
Definition: subs.qc:256
float spawnflags
Definition: progsdefs.qc:191
float platmovetype_start_default
Definition: platforms.qc:200
float wait
Definition: subs.qh:39
#define NULL
Definition: post.qh:17
float platmovetype_start
Definition: subs.qh:44
const float VOL_BASE
Definition: sound.qh:36
const int CH_TRIGGER_SINGLE
Definition: sound.qh:13
vector(float skel, float bonenum) _skel_get_boneabs_hidden
void train_wait(entity this)
Definition: train.qc:8
#define _sound(e, c, s, v, a)
Definition: sound.qh:50
string targetname
Definition: progsdefs.qc:194
string target
Definition: progsdefs.qc:193
void SUB_CalcMove_Bezier(entity this, vector tcontrol, vector tdest, float tspeedtype, float tspeed, void(entity this) func)
Definition: subs.qc:194
const float ATTEN_IDLE
Definition: sound.qh:32
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ train_next_find()

entity train_next_find ( entity  this)

Definition at line 66 of file train.qc.

References entity(), find(), NULL, RandomSelection_AddEnt, RandomSelection_chosen_ent, RandomSelection_Init(), target, target_random, and targetname.

Referenced by train_next().

67 {
68  if(this.target_random)
69  {
71  for(entity t = NULL; (t = find(t, targetname, this.target));)
72  {
73  RandomSelection_AddEnt(t, 1, 0);
74  }
76  }
77  else
78  {
79  return find(NULL, targetname, this.target);
80  }
81 }
float target_random
Definition: subs.qh:57
ERASEABLE void RandomSelection_Init()
Definition: random.qc:4
entity() spawn
#define RandomSelection_AddEnt(e, weight, priority)
Definition: random.qh:14
entity RandomSelection_chosen_ent
Definition: random.qh:5
#define NULL
Definition: post.qh:17
string targetname
Definition: progsdefs.qc:194
string target
Definition: progsdefs.qc:193
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ train_wait()

void train_wait ( entity  this)

Definition at line 8 of file train.qc.

References CH_TRIGGER_SINGLE, enemy, entity(), find(), func_null(), future_target, ltime, MSG_BROADCAST, nextthink, noise, NULL, origin, platmovetype_turn, setthink, spawnflags, SUB_CalcAngleMove(), SUB_UseTargets(), targetname, time, TRAIN_CURVE, TRAIN_NEEDACTIVATION, train_next(), train_wait_turning, TSPEED_TIME, use, vectoangles(), vector(), view_ofs, and wait.

Referenced by train_next().

9 {
10  SUB_UseTargets(this.enemy, NULL, NULL);
11  this.enemy = NULL;
12 
13  // if turning is enabled, the train will turn toward the next point while waiting
14  if(this.platmovetype_turn && !this.train_wait_turning)
15  {
16  entity targ, cp;
17  vector ang;
18  targ = this.future_target;
19  if((this.spawnflags & TRAIN_CURVE) && targ.curvetarget)
20  cp = find(NULL, targetname, targ.curvetarget);
21  else
22  cp = NULL;
23 
24  if(cp) // bezier curves movement
25  ang = cp.origin - (this.origin - this.view_ofs); // use the origin of the control point of the next path_corner
26  else // linear movement
27  ang = targ.origin - (this.origin - this.view_ofs); // use the origin of the next path_corner
28  ang = vectoangles(ang);
29  ang_x = -ang_x; // flip up / down orientation
30 
31  if(this.wait > 0) // slow turning
32  SUB_CalcAngleMove(this, ang, TSPEED_TIME, this.ltime - time + this.wait, train_wait);
33  else // instant turning
34  SUB_CalcAngleMove(this, ang, TSPEED_TIME, 0.0000001, train_wait);
35  this.train_wait_turning = true;
36  return;
37  }
38 
39 #ifdef SVQC
40  if(this.noise != "")
41  stopsoundto(MSG_BROADCAST, this, CH_TRIGGER_SINGLE); // send this as unreliable only, as the train will resume operation shortly anyway
42 #endif
43 
44 #ifdef SVQC
45  entity tg = this.future_target;
46  if(tg.spawnflags & TRAIN_NEEDACTIVATION)
47  {
48  this.use = train_use;
49  setthink(this, func_null);
50  this.nextthink = 0;
51  }
52  else
53 #endif
54  if(this.wait < 0 || this.train_wait_turning) // no waiting or we already waited while turning
55  {
56  this.train_wait_turning = false;
57  train_next(this);
58  }
59  else
60  {
61  setthink(this, train_next);
62  this.nextthink = this.ltime + this.wait;
63  }
64 }
const int TRAIN_CURVE
Definition: train.qh:4
entity future_target
Definition: train.qc:3
vector view_ofs
Definition: progsdefs.qc:151
string noise
Definition: progsdefs.qc:209
void train_next(entity this)
Definition: train.qc:83
entity() spawn
void SUB_UseTargets(entity this, entity actor, entity trigger)
Definition: triggers.qc:366
float train_wait_turning
Definition: train.qc:2
origin
Definition: ent_cs.qc:114
float ltime
Definition: progsdefs.qc:107
float spawnflags
Definition: progsdefs.qc:191
float platmovetype_turn
Definition: subs.qc:105
const int TRAIN_NEEDACTIVATION
Definition: train.qh:6
entity enemy
Definition: sv_ctf.qh:143
float wait
Definition: subs.qh:39
const int TSPEED_TIME
Definition: subs.qh:70
#define NULL
Definition: post.qh:17
float nextthink
Definition: csprogsdefs.qc:121
const int CH_TRIGGER_SINGLE
Definition: sound.qh:13
vector(float skel, float bonenum) _skel_get_boneabs_hidden
void train_wait(entity this)
Definition: train.qc:8
string targetname
Definition: progsdefs.qc:194
#define setthink(e, f)
void SUB_CalcAngleMove(entity this, vector destangle, float tspeedtype, float tspeed, void(entity this) func)
Definition: subs.qc:331
#define use
Definition: csprogsdefs.qh:50
float time
Definition: csprogsdefs.qc:16
var void func_null()
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ future_target

entity future_target

Definition at line 3 of file train.qc.

Referenced by train_next(), and train_wait().

◆ train_wait_turning

float train_wait_turning

Definition at line 2 of file train.qc.

Referenced by train_wait().