Xonotic
conveyor.qc
Go to the documentation of this file.
1 #include "conveyor.qh"
2 REGISTER_NET_LINKED(ENT_CLIENT_CONVEYOR)
3 
5 {
6 #ifdef CSQC
7  // TODO: check if this is what is causing the glitchiness when switching between them
8  float dt = time - this.move_time;
9  this.move_time = time;
10  if(dt <= 0) { return; }
11 #endif
12 
13  // set myself as current conveyor where possible
14  IL_EACH(g_conveyed, it.conveyor == this,
15  {
16  it.conveyor = NULL;
17  IL_REMOVE(g_conveyed, it);
18  });
19 
20  if(this.active == ACTIVE_ACTIVE)
21  {
22  FOREACH_ENTITY_RADIUS((this.absmin + this.absmax) * 0.5, vlen(this.absmax - this.absmin) * 0.5 + 1, it.conveyor.active == ACTIVE_NOT && isPushable(it),
23  {
24  vector emin = it.absmin;
25  vector emax = it.absmax;
26  if(this.solid == SOLID_BSP)
27  {
28  emin -= '1 1 1';
29  emax += '1 1 1';
30  }
31  if(boxesoverlap(emin, emax, this.absmin, this.absmax)) // quick
32  if(WarpZoneLib_BoxTouchesBrush(emin, emax, this, it)) // accurate
33  {
34  if(!it.conveyor)
35  IL_PUSH(g_conveyed, it);
36  it.conveyor = this;
37  }
38  });
39 
40  IL_EACH(g_conveyed, it.conveyor == this,
41  {
42  if(IS_CLIENT(it)) // doing it via velocity has quite some advantages
43  continue; // done in SV_PlayerPhysics continue;
44 
45  setorigin(it, it.origin + this.movedir * PHYS_INPUT_FRAMETIME);
46  move_out_of_solid(it);
47 #ifdef SVQC
48  UpdateCSQCProjectile(it);
49 #endif
50  /*
51  // stupid conveyor code
52  tracebox(it.origin, it.mins, it.maxs, it.origin + this.movedir * sys_frametime, MOVE_NORMAL, it);
53  if(trace_fraction > 0)
54  setorigin(it, trace_endpos);
55  */
56  });
57  }
58 
59 #ifdef SVQC
60  this.nextthink = time;
61 #endif
62 }
63 
64 #ifdef SVQC
65 
66 bool conveyor_send(entity this, entity to, int sendflags)
67 {
68  WriteHeader(MSG_ENTITY, ENT_CLIENT_CONVEYOR);
69  WriteByte(MSG_ENTITY, sendflags);
70 
71  if(sendflags & SF_TRIGGER_INIT)
72  {
73  WriteByte(MSG_ENTITY, this.warpzone_isboxy);
74  WriteVector(MSG_ENTITY, this.origin);
75 
76  WriteVector(MSG_ENTITY, this.mins);
77  WriteVector(MSG_ENTITY, this.maxs);
78 
79  WriteVector(MSG_ENTITY, this.movedir);
80 
81  WriteByte(MSG_ENTITY, this.speed);
82  WriteByte(MSG_ENTITY, this.active);
83 
84  WriteString(MSG_ENTITY, this.targetname);
85  WriteString(MSG_ENTITY, this.target);
86  }
87 
88  if(sendflags & SF_TRIGGER_UPDATE)
89  WriteByte(MSG_ENTITY, this.active);
90 
91  return true;
92 }
93 
94 void conveyor_init(entity this)
95 {
96  if (!this.speed) this.speed = 200;
97  this.movedir *= this.speed;
98  setthink(this, conveyor_think);
99  this.nextthink = time;
100  this.setactive = generic_netlinked_setactive;
101  if(this.targetname && this.targetname != "")
102  {
103  // backwards compatibility
104  this.use = generic_netlinked_legacy_use;
105  }
106  this.reset = generic_netlinked_reset;
107  this.reset(this);
108 
109  Net_LinkEntity(this, 0, false, conveyor_send);
110 
111  this.SendFlags |= SF_TRIGGER_INIT;
112 }
113 
114 spawnfunc(trigger_conveyor)
115 {
116  SetMovedir(this);
118  conveyor_init(this);
119 }
120 
121 spawnfunc(func_conveyor)
122 {
123  SetMovedir(this);
124  InitMovingBrushTrigger(this);
126  conveyor_init(this);
127 }
128 
129 #elif defined(CSQC)
130 
131 void conveyor_draw(entity this) { conveyor_think(this); }
132 
133 void conveyor_init(entity this, bool isnew)
134 {
135  if(isnew)
136  IL_PUSH(g_drawables, this);
137  this.draw = conveyor_draw;
138  this.drawmask = MASK_NORMAL;
139 
141  this.model = "";
142  this.solid = SOLID_TRIGGER;
143  this.move_time = time;
144 }
145 
146 NET_HANDLE(ENT_CLIENT_CONVEYOR, bool isnew)
147 {
148  int sendflags = ReadByte();
149 
150  if(sendflags & SF_TRIGGER_INIT)
151  {
152  this.warpzone_isboxy = ReadByte();
153  this.origin = ReadVector();
154  setorigin(this, this.origin);
155 
156  this.mins = ReadVector();
157  this.maxs = ReadVector();
158  setsize(this, this.mins, this.maxs);
159 
160  this.movedir = ReadVector();
161 
162  this.speed = ReadByte();
163  this.active = ReadByte();
164 
165  this.targetname = strzone(ReadString());
166  this.target = strzone(ReadString());
167 
168  conveyor_init(this, isnew);
169  }
170 
171  if(sendflags & SF_TRIGGER_UPDATE)
172  this.active = ReadByte();
173 
174  return true;
175 }
176 #endif
#define IL_EACH(this, cond, body)
float MOVETYPE_NONE
Definition: progsdefs.qc:246
#define REGISTER_NET_LINKED(id)
Definition: net.qh:67
float speed
Definition: subs.qh:41
IntrusiveList g_conveyed
Definition: conveyor.qh:4
#define EXACTTRIGGER_INIT
Definition: common.qh:117
const int SF_TRIGGER_INIT
Definition: defs.qh:22
#define ReadString
entity() spawn
vector maxs
Definition: csprogsdefs.qc:113
#define NET_HANDLE(id, param)
Definition: net.qh:12
entity to
Definition: self.qh:96
spawnfunc(info_player_attacker)
Definition: sv_assault.qc:283
origin
Definition: ent_cs.qc:114
string model
Definition: csprogsdefs.qc:108
vector absmax
Definition: csprogsdefs.qc:92
vector movedir
Definition: progsdefs.qc:203
vector mins
Definition: csprogsdefs.qc:113
ERASEABLE entity IL_PUSH(IntrusiveList this, entity it)
Push to tail.
ERASEABLE float boxesoverlap(vector m1, vector m2, vector m3, vector m4)
requires that m2>m1 in all coordinates, and that m4>m3
Definition: vector.qh:73
float WarpZoneLib_BoxTouchesBrush(vector mi, vector ma, entity e, entity ig)
Definition: common.qc:138
const int ACTIVE_ACTIVE
Definition: defs.qh:37
entity this
Definition: self.qh:83
const float MASK_NORMAL
Definition: csprogsdefs.qc:164
float drawmask
Definition: csprogsdefs.qc:95
float nextthink
Definition: csprogsdefs.qc:121
vector(float skel, float bonenum) _skel_get_boneabs_hidden
const float SOLID_BSP
Definition: csprogsdefs.qc:248
float move_time
Definition: movetypes.qh:77
float warpzone_isboxy
Definition: common.qh:12
const float SOLID_TRIGGER
Definition: csprogsdefs.qc:245
void conveyor_think(entity this)
Definition: conveyor.qc:4
string targetname
Definition: progsdefs.qc:194
int active
Definition: defs.qh:34
entity int sendflags
Definition: self.qh:96
setorigin(ent, v)
#define setthink(e, f)
#define use
Definition: csprogsdefs.qh:50
string target
Definition: progsdefs.qc:193
void
Definition: self.qh:83
vector absmin
Definition: csprogsdefs.qc:92
const int ACTIVE_NOT
Definition: defs.qh:36
float time
Definition: csprogsdefs.qc:16
bool isPushable(entity e)
Definition: triggers.qc:3
IntrusiveList g_drawables
Definition: main.qh:77
void set_movetype(entity this, int mt)
float solid
Definition: csprogsdefs.qc:99
const int SF_TRIGGER_UPDATE
Definition: defs.qh:23