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)
18 targ = this.future_target;
19 if((this.spawnflags & 1) && targ.curvetarget)
20 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
28 ang = vectoangles(ang);
29 ang_x = -ang_x; // flip up / down orientation
31 if(this.wait > 0) // slow turning
32 SUB_CalcAngleMove(this, ang, TSPEED_TIME, this.SUB_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;
41 stopsoundto(MSG_BROADCAST, this, CH_TRIGGER_SINGLE); // send this as unreliable only, as the train will resume operation shortly anyway
45 entity tg = this.future_target;
49 SUB_THINK(this, func_null);
50 this.SUB_NEXTTHINK = 0;
54 if(this.wait < 0 || this.train_wait_turning) // no waiting or we already waited while turning
56 this.train_wait_turning = false;
61 SUB_THINK(this, train_next);
62 this.SUB_NEXTTHINK = this.SUB_LTIME + this.wait;
66 entity train_next_find(entity this)
68 if(this.target_random)
70 RandomSelection_Init();
71 for(entity t = NULL; (t = find(t, targetname, this.target));)
73 RandomSelection_AddEnt(t, 1, 0);
75 return RandomSelection_chosen_ent;
79 return find(NULL, targetname, this.target);
83 void train_next(entity this)
85 entity targ = NULL, cp = NULL;
86 vector cp_org = '0 0 0';
88 targ = this.future_target;
90 this.target = targ.target;
91 this.target_random = targ.target_random;
92 this.future_target = train_next_find(targ);
94 if (this.spawnflags & 1)
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
102 if (this.target == "")
103 objerror(this, "train_next: no next target");
104 this.wait = targ.wait;
108 if(targ.platmovetype)
110 // this path_corner contains a movetype overrider, apply it
111 this.platmovetype_start = targ.platmovetype_start;
112 this.platmovetype_end = targ.platmovetype_end;
116 // this path_corner doesn't contain a movetype overrider, use the train's defaults
117 this.platmovetype_start = this.platmovetype_start_default;
118 this.platmovetype_end = this.platmovetype_end_default;
124 SUB_CalcMove_Bezier(this, cp_org, targ.origin - this.view_ofs, TSPEED_LINEAR, targ.speed, train_wait);
126 SUB_CalcMove(this, targ.origin - this.view_ofs, TSPEED_LINEAR, targ.speed, train_wait);
131 SUB_CalcMove_Bezier(this, cp_org, targ.origin - this.view_ofs, TSPEED_LINEAR, this.speed, train_wait);
133 SUB_CalcMove(this, targ.origin - this.view_ofs, TSPEED_LINEAR, this.speed, train_wait);
137 _sound(this, CH_TRIGGER_SINGLE, this.noise, VOL_BASE, ATTEN_IDLE);
140 REGISTER_NET_LINKED(ENT_CLIENT_TRAIN)
143 float train_send(entity this, entity to, float sf)
145 WriteHeader(MSG_ENTITY, ENT_CLIENT_TRAIN);
146 WriteByte(MSG_ENTITY, sf);
148 if(sf & SF_TRIGGER_INIT)
150 WriteString(MSG_ENTITY, this.platmovetype);
151 WriteByte(MSG_ENTITY, this.platmovetype_turn);
152 WriteByte(MSG_ENTITY, this.spawnflags);
154 WriteString(MSG_ENTITY, this.model);
156 trigger_common_write(this, true);
158 WriteString(MSG_ENTITY, this.curvetarget);
160 WriteCoord(MSG_ENTITY, this.pos1_x);
161 WriteCoord(MSG_ENTITY, this.pos1_y);
162 WriteCoord(MSG_ENTITY, this.pos1_z);
163 WriteCoord(MSG_ENTITY, this.pos2_x);
164 WriteCoord(MSG_ENTITY, this.pos2_y);
165 WriteCoord(MSG_ENTITY, this.pos2_z);
167 WriteCoord(MSG_ENTITY, this.size_x);
168 WriteCoord(MSG_ENTITY, this.size_y);
169 WriteCoord(MSG_ENTITY, this.size_z);
171 WriteCoord(MSG_ENTITY, this.view_ofs_x);
172 WriteCoord(MSG_ENTITY, this.view_ofs_y);
173 WriteCoord(MSG_ENTITY, this.view_ofs_z);
175 WriteAngle(MSG_ENTITY, this.mangle_x);
176 WriteAngle(MSG_ENTITY, this.mangle_y);
177 WriteAngle(MSG_ENTITY, this.mangle_z);
179 WriteShort(MSG_ENTITY, this.speed);
180 WriteShort(MSG_ENTITY, this.height);
181 WriteByte(MSG_ENTITY, this.lip);
182 WriteByte(MSG_ENTITY, this.state);
183 WriteByte(MSG_ENTITY, this.wait);
185 WriteShort(MSG_ENTITY, this.dmg);
186 WriteByte(MSG_ENTITY, this.dmgtime);
189 if(sf & SF_TRIGGER_RESET)
197 void train_link(entity this)
199 //Net_LinkEntity(this, 0, false, train_send);
202 void train_use(entity this, entity actor, entity trigger)
204 this.SUB_NEXTTHINK = this.SUB_LTIME + 1;
205 SUB_THINK(this, train_next);
206 this.use = func_null; // not again
209 void func_train_find(entity this)
211 entity targ = train_next_find(this);
212 this.target = targ.target;
213 this.target_random = targ.target_random;
214 // save the future target for later
215 this.future_target = train_next_find(targ);
216 if (this.target == "")
217 objerror(this, "func_train_find: no next target");
218 SUB_SETORIGIN(this, targ.origin - this.view_ofs);
220 if(!(this.spawnflags & 4))
222 this.SUB_NEXTTHINK = this.SUB_LTIME + 1;
223 SUB_THINK(this, train_next);
231 /*QUAKED spawnfunc_func_train (0 .5 .8) ?
232 Ridable platform, targets spawnfunc_path_corner path to follow.
233 speed : speed the train moves (can be overridden by each spawnfunc_path_corner)
234 target : targetname of first spawnfunc_path_corner (starts here)
237 spawnfunc(func_train)
239 if (this.noise != "")
240 precache_sound(this.noise);
242 if (this.target == "")
243 objerror(this, "func_train without a target");
247 if (!InitMovingBrushTrigger(this))
249 this.effects |= EF_LOWPRECISION;
251 if(this.spawnflags & 4)
252 this.use = train_use;
254 if (this.spawnflags & 2)
256 this.platmovetype_turn = true;
257 this.view_ofs = '0 0 0'; // don't offset a rotating train, origin works differently now
260 this.view_ofs = this.mins;
262 // wait for targets to spawn
263 InitializeEntity(this, func_train_find, INITPRIO_FINDTARGET);
265 setblocked(this, generic_plat_blocked);
266 if(this.dmg && (this.message == ""))
267 this.message = " was squished";
268 if(this.dmg && (this.message2 == ""))
269 this.message2 = "was squished by";
270 if(this.dmg && (!this.dmgtime))
272 this.dmgtime2 = time;
274 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)
294 this.platmovetype = strzone(ReadString());
295 this.platmovetype_turn = ReadByte();
296 this.spawnflags = ReadByte();
298 this.model = strzone(ReadString());
299 _setmodel(this, this.model);
301 trigger_common_read(this, true);
303 this.curvetarget = strzone(ReadString());
305 this.pos1_x = ReadCoord();
306 this.pos1_y = ReadCoord();
307 this.pos1_z = ReadCoord();
308 this.pos2_x = ReadCoord();
309 this.pos2_y = ReadCoord();
310 this.pos2_z = ReadCoord();
312 this.size_x = ReadCoord();
313 this.size_y = ReadCoord();
314 this.size_z = ReadCoord();
316 this.view_ofs_x = ReadCoord();
317 this.view_ofs_y = ReadCoord();
318 this.view_ofs_z = ReadCoord();
320 this.mangle_x = ReadAngle();
321 this.mangle_y = ReadAngle();
322 this.mangle_z = ReadAngle();
324 this.speed = ReadShort();
325 this.height = ReadShort();
326 this.lip = ReadByte();
327 this.state = ReadByte();
328 this.wait = ReadByte();
330 this.dmg = ReadShort();
331 this.dmgtime = ReadByte();
333 this.classname = "func_train";
334 this.solid = SOLID_BSP;
335 set_movetype(this, MOVETYPE_PUSH);
336 this.drawmask = MASK_NORMAL;
337 this.draw = train_draw;
338 if (isnew) IL_PUSH(g_drawables, this);
339 this.entremove = trigger_remove_generic;
341 if(set_platmovetype(this, this.platmovetype))
343 this.platmovetype_start_default = this.platmovetype_start;
344 this.platmovetype_end_default = this.platmovetype_end;
347 // everything is set up by the time the train is linked, we shouldn't need this
350 // but we will need these
353 set_movetype(this, MOVETYPE_PUSH);
354 this.move_time = time;
357 if(sf & SF_TRIGGER_RESET)
359 // TODO: make a reset function for trains