2 .float train_wait_turning;
4 void train_next(entity this);
6 void train_use(entity this, entity actor, entity trigger);
8 void train_wait(entity this)
10 SUB_UseTargets(this.enemy, NULL, NULL);
13 // if turning is enabled, the train will turn toward the next point while waiting
14 if (this.platmovetype_turn && !this.train_wait_turning) {
17 targ = this.future_target;
18 if ((this.spawnflags & 1) && targ.curvetarget) {
19 cp = find(NULL, targetname, targ.curvetarget);
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
29 ang = vectoangles(ang);
30 ang_x = -ang_x; // flip up / down orientation
32 if (this.wait > 0) { // slow turning
33 SUB_CalcAngleMove(this, ang, TSPEED_TIME, this.ltime - time + this.wait, train_wait);
34 } else { // instant turning
35 SUB_CalcAngleMove(this, ang, TSPEED_TIME, 0.0000001, train_wait);
37 this.train_wait_turning = true;
42 if (this.noise != "") {
43 stopsoundto(MSG_BROADCAST, this, CH_TRIGGER_SINGLE); // send this as unreliable only, as the train will resume operation shortly anyway
48 entity tg = this.future_target;
49 if (tg.spawnflags & 4) {
51 setthink(this, func_null);
55 if (this.wait < 0 || this.train_wait_turning) { // no waiting or we already waited while turning
56 this.train_wait_turning = false;
59 setthink(this, train_next);
60 this.nextthink = this.ltime + this.wait;
64 entity train_next_find(entity this)
66 if (this.target_random) {
67 RandomSelection_Init();
68 for (entity t = NULL; (t = find(t, targetname, this.target)); ) {
69 RandomSelection_AddEnt(t, 1, 0);
71 return RandomSelection_chosen_ent;
73 return find(NULL, targetname, this.target);
77 void train_next(entity this)
79 entity targ = NULL, cp = NULL;
80 vector cp_org = '0 0 0';
82 targ = this.future_target;
84 this.target = targ.target;
85 this.target_random = targ.target_random;
86 this.future_target = train_next_find(targ);
88 if (this.spawnflags & 1) {
89 if (targ.curvetarget) {
90 cp = find(NULL, targetname, targ.curvetarget); // get its second target (the control point)
91 cp_org = cp.origin - this.view_ofs; // no control point found, assume a straight line to the destination
94 if (this.target == "") {
95 objerror(this, "train_next: no next target");
97 this.wait = targ.wait;
102 if (targ.platmovetype) {
103 // this path_corner contains a movetype overrider, apply it
104 this.platmovetype_start = targ.platmovetype_start;
105 this.platmovetype_end = targ.platmovetype_end;
107 // this path_corner doesn't contain a movetype overrider, use the train's defaults
108 this.platmovetype_start = this.platmovetype_start_default;
109 this.platmovetype_end = this.platmovetype_end_default;
114 SUB_CalcMove_Bezier(this, cp_org, targ.origin - this.view_ofs, TSPEED_LINEAR, targ.speed, train_wait);
116 SUB_CalcMove(this, targ.origin - this.view_ofs, TSPEED_LINEAR, targ.speed, train_wait);
120 SUB_CalcMove_Bezier(this, cp_org, targ.origin - this.view_ofs, TSPEED_LINEAR, this.speed, train_wait);
122 SUB_CalcMove(this, targ.origin - this.view_ofs, TSPEED_LINEAR, this.speed, train_wait);
126 if (this.noise != "") {
127 _sound(this, CH_TRIGGER_SINGLE, this.noise, VOL_BASE, ATTEN_IDLE);
131 REGISTER_NET_LINKED(ENT_CLIENT_TRAIN)
134 float train_send(entity this, entity to, float sf)
136 WriteHeader(MSG_ENTITY, ENT_CLIENT_TRAIN);
137 WriteByte(MSG_ENTITY, sf);
139 if (sf & SF_TRIGGER_INIT) {
140 WriteString(MSG_ENTITY, this.platmovetype);
141 WriteByte(MSG_ENTITY, this.platmovetype_turn);
142 WriteByte(MSG_ENTITY, this.spawnflags);
144 WriteString(MSG_ENTITY, this.model);
146 trigger_common_write(this, true);
148 WriteString(MSG_ENTITY, this.curvetarget);
150 WriteCoord(MSG_ENTITY, this.pos1_x);
151 WriteCoord(MSG_ENTITY, this.pos1_y);
152 WriteCoord(MSG_ENTITY, this.pos1_z);
153 WriteCoord(MSG_ENTITY, this.pos2_x);
154 WriteCoord(MSG_ENTITY, this.pos2_y);
155 WriteCoord(MSG_ENTITY, this.pos2_z);
157 WriteCoord(MSG_ENTITY, this.size_x);
158 WriteCoord(MSG_ENTITY, this.size_y);
159 WriteCoord(MSG_ENTITY, this.size_z);
161 WriteCoord(MSG_ENTITY, this.view_ofs_x);
162 WriteCoord(MSG_ENTITY, this.view_ofs_y);
163 WriteCoord(MSG_ENTITY, this.view_ofs_z);
165 WriteAngle(MSG_ENTITY, this.mangle_x);
166 WriteAngle(MSG_ENTITY, this.mangle_y);
167 WriteAngle(MSG_ENTITY, this.mangle_z);
169 WriteShort(MSG_ENTITY, this.speed);
170 WriteShort(MSG_ENTITY, this.height);
171 WriteByte(MSG_ENTITY, this.lip);
172 WriteByte(MSG_ENTITY, this.state);
173 WriteByte(MSG_ENTITY, this.wait);
175 WriteShort(MSG_ENTITY, this.dmg);
176 WriteByte(MSG_ENTITY, this.dmgtime);
179 if (sf & SF_TRIGGER_RESET) {
186 void train_link(entity this)
188 // Net_LinkEntity(this, 0, false, train_send);
191 void train_use(entity this, entity actor, entity trigger)
193 this.nextthink = this.ltime + 1;
194 setthink(this, train_next);
195 this.use = func_null; // not again
196 if (trigger.target2 && trigger.target2 != "") {
197 this.future_target = find(NULL, targetname, trigger.target2);
201 void func_train_find(entity this)
203 entity targ = train_next_find(this);
204 this.target = targ.target;
205 this.target_random = targ.target_random;
206 // save the future target for later
207 this.future_target = train_next_find(targ);
208 if (this.target == "") {
209 objerror(this, "func_train_find: no next target");
211 setorigin(this, targ.origin - this.view_ofs);
213 if (!(this.spawnflags & 4)) {
214 this.nextthink = this.ltime + 1;
215 setthink(this, train_next);
223 /*QUAKED spawnfunc_func_train (0 .5 .8) ?
224 Ridable platform, targets spawnfunc_path_corner path to follow.
225 speed : speed the train moves (can be overridden by each spawnfunc_path_corner)
226 target : targetname of first spawnfunc_path_corner (starts here)
229 spawnfunc(func_train)
231 if (this.noise != "") {
232 precache_sound(this.noise);
235 if (this.target == "") {
236 objerror(this, "func_train without a target");
242 if (!InitMovingBrushTrigger(this)) {
245 this.effects |= EF_LOWPRECISION;
247 if (this.spawnflags & 4) {
248 this.use = train_use;
251 if (this.spawnflags & 2) {
252 this.platmovetype_turn = true;
253 this.view_ofs = '0 0 0'; // don't offset a rotating train, origin works differently now
255 this.view_ofs = this.mins;
258 // wait for targets to spawn
259 InitializeEntity(this, func_train_find, INITPRIO_FINDTARGET);
261 setblocked(this, generic_plat_blocked);
262 if (this.dmg && (this.message == "")) {
263 this.message = " was squished";
265 if (this.dmg && (this.message2 == "")) {
266 this.message2 = "was squished by";
268 if (this.dmg && (!this.dmgtime)) {
271 this.dmgtime2 = time;
273 if (!set_platmovetype(this, this.platmovetype)) {
276 this.platmovetype_start_default = this.platmovetype_start;
277 this.platmovetype_end_default = this.platmovetype_end;
279 // TODO make a reset function for this one
282 void train_draw(entity this)
284 // Movetype_Physics_NoMatchServer();
285 Movetype_Physics_MatchServer(this, autocvar_cl_projectiles_sloppy);
288 NET_HANDLE(ENT_CLIENT_TRAIN, bool isnew)
290 float sf = ReadByte();
292 if (sf & SF_TRIGGER_INIT) {
293 this.platmovetype = strzone(ReadString());
294 this.platmovetype_turn = ReadByte();
295 this.spawnflags = ReadByte();
297 this.model = strzone(ReadString());
298 _setmodel(this, this.model);
300 trigger_common_read(this, true);
302 this.curvetarget = strzone(ReadString());
304 this.pos1_x = ReadCoord();
305 this.pos1_y = ReadCoord();
306 this.pos1_z = ReadCoord();
307 this.pos2_x = ReadCoord();
308 this.pos2_y = ReadCoord();
309 this.pos2_z = ReadCoord();
311 this.size_x = ReadCoord();
312 this.size_y = ReadCoord();
313 this.size_z = ReadCoord();
315 this.view_ofs_x = ReadCoord();
316 this.view_ofs_y = ReadCoord();
317 this.view_ofs_z = ReadCoord();
319 this.mangle_x = ReadAngle();
320 this.mangle_y = ReadAngle();
321 this.mangle_z = ReadAngle();
323 this.speed = ReadShort();
324 this.height = ReadShort();
325 this.lip = ReadByte();
326 this.state = ReadByte();
327 this.wait = ReadByte();
329 this.dmg = ReadShort();
330 this.dmgtime = ReadByte();
332 this.classname = "func_train";
333 this.solid = SOLID_BSP;
334 set_movetype(this, MOVETYPE_PUSH);
335 this.drawmask = MASK_NORMAL;
336 this.draw = train_draw;
337 if (isnew) { IL_PUSH(g_drawables, this); }
338 this.entremove = trigger_remove_generic;
340 if (set_platmovetype(this, this.platmovetype)) {
341 this.platmovetype_start_default = this.platmovetype_start;
342 this.platmovetype_end_default = this.platmovetype_end;
345 // everything is set up by the time the train is linked, we shouldn't need this
346 // func_train_find();
348 // but we will need these
351 set_movetype(this, MOVETYPE_PUSH);
352 this.move_time = time;
355 if (sf & SF_TRIGGER_RESET) {
356 // TODO: make a reset function for trains