2 .float train_wait_turning;
3 void train_next(entity this);
5 void train_use(entity this, entity actor, entity trigger);
7 void train_wait(entity this)
9 SUB_UseTargets(this.enemy, NULL, NULL);
12 // if turning is enabled, the train will turn toward the next point while waiting
13 if(this.platmovetype_turn && !this.train_wait_turning)
17 targ = find(NULL, targetname, this.target);
18 if((this.spawnflags & 1) && targ.curvetarget)
19 cp = find(NULL, targetname, targ.curvetarget);
23 if(cp) // bezier curves movement
24 ang = cp.origin - (this.origin - this.view_ofs); // use the origin of the control point of the next path_corner
25 else // linear movement
26 ang = targ.origin - (this.origin - this.view_ofs); // use the origin of the next path_corner
27 ang = vectoangles(ang);
28 ang_x = -ang_x; // flip up / down orientation
30 if(this.wait > 0) // slow turning
31 SUB_CalcAngleMove(this, ang, TSPEED_TIME, this.SUB_LTIME - time + this.wait, train_wait);
32 else // instant turning
33 SUB_CalcAngleMove(this, ang, TSPEED_TIME, 0.0000001, train_wait);
34 this.train_wait_turning = true;
40 stopsoundto(MSG_BROADCAST, this, CH_TRIGGER_SINGLE); // send this as unreliable only, as the train will resume operation shortly anyway
44 entity tg = find(NULL, targetname, this.target);
48 SUB_THINK(this, func_null);
49 this.SUB_NEXTTHINK = 0;
53 if(this.wait < 0 || this.train_wait_turning) // no waiting or we already waited while turning
55 this.train_wait_turning = false;
60 SUB_THINK(this, train_next);
61 this.SUB_NEXTTHINK = this.SUB_LTIME + this.wait;
65 entity train_next_find(entity this)
67 if(this.target_random)
69 RandomSelection_Init();
70 for(entity t = NULL; (t = find(t, targetname, this.target));)
72 RandomSelection_AddEnt(t, 1, 0);
74 return RandomSelection_chosen_ent;
78 return find(NULL, targetname, this.target);
82 void train_next(entity this)
84 entity targ = NULL, cp = NULL;
85 vector cp_org = '0 0 0';
87 targ = train_next_find(this);
89 this.target = targ.target;
90 this.target_random = targ.target_random;
92 if (this.spawnflags & 1)
96 cp = find(NULL, targetname, targ.curvetarget); // get its second target (the control point)
97 cp_org = cp.origin - this.view_ofs; // no control point found, assume a straight line to the destination
100 if (this.target == "")
101 objerror(this, "train_next: no next target");
102 this.wait = targ.wait;
106 if(targ.platmovetype)
108 // this path_corner contains a movetype overrider, apply it
109 this.platmovetype_start = targ.platmovetype_start;
110 this.platmovetype_end = targ.platmovetype_end;
114 // this path_corner doesn't contain a movetype overrider, use the train's defaults
115 this.platmovetype_start = this.platmovetype_start_default;
116 this.platmovetype_end = this.platmovetype_end_default;
122 SUB_CalcMove_Bezier(this, cp_org, targ.origin - this.view_ofs, TSPEED_LINEAR, targ.speed, train_wait);
124 SUB_CalcMove(this, targ.origin - this.view_ofs, TSPEED_LINEAR, targ.speed, train_wait);
129 SUB_CalcMove_Bezier(this, cp_org, targ.origin - this.view_ofs, TSPEED_LINEAR, this.speed, train_wait);
131 SUB_CalcMove(this, targ.origin - this.view_ofs, TSPEED_LINEAR, this.speed, train_wait);
135 _sound(this, CH_TRIGGER_SINGLE, this.noise, VOL_BASE, ATTEN_IDLE);
138 REGISTER_NET_LINKED(ENT_CLIENT_TRAIN)
141 float train_send(entity this, entity to, float sf)
143 WriteHeader(MSG_ENTITY, ENT_CLIENT_TRAIN);
144 WriteByte(MSG_ENTITY, sf);
146 if(sf & SF_TRIGGER_INIT)
148 WriteString(MSG_ENTITY, this.platmovetype);
149 WriteByte(MSG_ENTITY, this.platmovetype_turn);
150 WriteByte(MSG_ENTITY, this.spawnflags);
152 WriteString(MSG_ENTITY, this.model);
154 trigger_common_write(this, true);
156 WriteString(MSG_ENTITY, this.curvetarget);
158 WriteCoord(MSG_ENTITY, this.pos1_x);
159 WriteCoord(MSG_ENTITY, this.pos1_y);
160 WriteCoord(MSG_ENTITY, this.pos1_z);
161 WriteCoord(MSG_ENTITY, this.pos2_x);
162 WriteCoord(MSG_ENTITY, this.pos2_y);
163 WriteCoord(MSG_ENTITY, this.pos2_z);
165 WriteCoord(MSG_ENTITY, this.size_x);
166 WriteCoord(MSG_ENTITY, this.size_y);
167 WriteCoord(MSG_ENTITY, this.size_z);
169 WriteCoord(MSG_ENTITY, this.view_ofs_x);
170 WriteCoord(MSG_ENTITY, this.view_ofs_y);
171 WriteCoord(MSG_ENTITY, this.view_ofs_z);
173 WriteAngle(MSG_ENTITY, this.mangle_x);
174 WriteAngle(MSG_ENTITY, this.mangle_y);
175 WriteAngle(MSG_ENTITY, this.mangle_z);
177 WriteShort(MSG_ENTITY, this.speed);
178 WriteShort(MSG_ENTITY, this.height);
179 WriteByte(MSG_ENTITY, this.lip);
180 WriteByte(MSG_ENTITY, this.state);
181 WriteByte(MSG_ENTITY, this.wait);
183 WriteShort(MSG_ENTITY, this.dmg);
184 WriteByte(MSG_ENTITY, this.dmgtime);
187 if(sf & SF_TRIGGER_RESET)
195 void train_link(entity this)
197 //Net_LinkEntity(this, 0, false, train_send);
200 void train_use(entity this, entity actor, entity trigger)
202 this.SUB_NEXTTHINK = this.SUB_LTIME + 1;
203 SUB_THINK(this, train_next);
204 this.use = func_null; // not again
207 void func_train_find(entity this)
209 entity targ = train_next_find(this);
210 this.target = targ.target;
211 this.target_random = targ.target_random;
212 if (this.target == "")
213 objerror(this, "func_train_find: no next target");
214 SUB_SETORIGIN(this, targ.origin - this.view_ofs);
216 if(!(this.spawnflags & 4))
218 this.SUB_NEXTTHINK = this.SUB_LTIME + 1;
219 SUB_THINK(this, train_next);
227 /*QUAKED spawnfunc_func_train (0 .5 .8) ?
228 Ridable platform, targets spawnfunc_path_corner path to follow.
229 speed : speed the train moves (can be overridden by each spawnfunc_path_corner)
230 target : targetname of first spawnfunc_path_corner (starts here)
233 spawnfunc(func_train)
235 if (this.noise != "")
236 precache_sound(this.noise);
238 if (this.target == "")
239 objerror(this, "func_train without a target");
243 if (!InitMovingBrushTrigger(this))
245 this.effects |= EF_LOWPRECISION;
247 if(this.spawnflags & 4)
248 this.use = train_use;
250 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
256 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";
264 if(this.dmg && (this.message2 == ""))
265 this.message2 = "was squished by";
266 if(this.dmg && (!this.dmgtime))
268 this.dmgtime2 = time;
270 if(!set_platmovetype(this, this.platmovetype))
272 this.platmovetype_start_default = this.platmovetype_start;
273 this.platmovetype_end_default = this.platmovetype_end;
275 // TODO make a reset function for this one
278 void train_draw(entity this)
280 //Movetype_Physics_NoMatchServer();
281 Movetype_Physics_MatchServer(this, autocvar_cl_projectiles_sloppy);
284 NET_HANDLE(ENT_CLIENT_TRAIN, bool isnew)
286 float sf = ReadByte();
288 if(sf & SF_TRIGGER_INIT)
290 this.platmovetype = strzone(ReadString());
291 this.platmovetype_turn = ReadByte();
292 this.spawnflags = ReadByte();
294 this.model = strzone(ReadString());
295 _setmodel(this, this.model);
297 trigger_common_read(this, true);
299 this.curvetarget = strzone(ReadString());
301 this.pos1_x = ReadCoord();
302 this.pos1_y = ReadCoord();
303 this.pos1_z = ReadCoord();
304 this.pos2_x = ReadCoord();
305 this.pos2_y = ReadCoord();
306 this.pos2_z = ReadCoord();
308 this.size_x = ReadCoord();
309 this.size_y = ReadCoord();
310 this.size_z = ReadCoord();
312 this.view_ofs_x = ReadCoord();
313 this.view_ofs_y = ReadCoord();
314 this.view_ofs_z = ReadCoord();
316 this.mangle_x = ReadAngle();
317 this.mangle_y = ReadAngle();
318 this.mangle_z = ReadAngle();
320 this.speed = ReadShort();
321 this.height = ReadShort();
322 this.lip = ReadByte();
323 this.state = ReadByte();
324 this.wait = ReadByte();
326 this.dmg = ReadShort();
327 this.dmgtime = ReadByte();
329 this.classname = "func_train";
330 this.solid = SOLID_BSP;
331 set_movetype(this, MOVETYPE_PUSH);
332 this.drawmask = MASK_NORMAL;
333 this.draw = train_draw;
334 if (isnew) IL_PUSH(g_drawables, this);
335 this.entremove = trigger_remove_generic;
337 if(set_platmovetype(this, this.platmovetype))
339 this.platmovetype_start_default = this.platmovetype_start;
340 this.platmovetype_end_default = this.platmovetype_end;
343 // everything is set up by the time the train is linked, we shouldn't need this
346 // but we will need these
349 set_movetype(this, MOVETYPE_PUSH);
350 this.move_time = time;
353 if(sf & SF_TRIGGER_RESET)
355 // TODO: make a reset function for trains