1 .float train_wait_turning;
5 WITH(entity, self, self.enemy, SUB_UseTargets());
8 // if turning is enabled, the train will turn toward the next point while waiting
9 if(self.platmovetype_turn && !self.train_wait_turning)
13 targ = find(world, targetname, self.target);
14 if((self.spawnflags & 1) && targ.curvetarget)
15 cp = find(world, targetname, targ.curvetarget);
19 if(cp) // bezier curves movement
20 ang = cp.origin - (self.origin - self.view_ofs); // use the origin of the control point of the next path_corner
21 else // linear movement
22 ang = targ.origin - (self.origin - self.view_ofs); // use the origin of the next path_corner
23 ang = vectoangles(ang);
24 ang_x = -ang_x; // flip up / down orientation
26 if(self.wait > 0) // slow turning
27 SUB_CalcAngleMove(ang, TSPEED_TIME, self.SUB_LTIME - time + self.wait, train_wait);
28 else // instant turning
29 SUB_CalcAngleMove(ang, TSPEED_TIME, 0.0000001, train_wait);
30 self.train_wait_turning = true;
36 stopsoundto(MSG_BROADCAST, self, CH_TRIGGER_SINGLE); // send this as unreliable only, as the train will resume operation shortly anyway
40 entity tg = find(world, targetname, self.target);
44 self.SUB_THINK = func_null;
45 self.SUB_NEXTTHINK = 0;
49 if(self.wait < 0 || self.train_wait_turning) // no waiting or we already waited while turning
51 self.train_wait_turning = false;
56 self.SUB_THINK = train_next;
57 self.SUB_NEXTTHINK = self.SUB_LTIME + self.wait;
63 entity targ, cp = world;
64 vector cp_org = '0 0 0';
66 targ = find(world, targetname, self.target);
67 self.target = targ.target;
68 if (self.spawnflags & 1)
72 cp = find(world, targetname, targ.curvetarget); // get its second target (the control point)
73 cp_org = cp.origin - self.view_ofs; // no control point found, assume a straight line to the destination
76 if (self.target == "")
77 objerror("train_next: no next target");
78 self.wait = targ.wait;
84 // this path_corner contains a movetype overrider, apply it
85 self.platmovetype_start = targ.platmovetype_start;
86 self.platmovetype_end = targ.platmovetype_end;
90 // this path_corner doesn't contain a movetype overrider, use the train's defaults
91 self.platmovetype_start = self.platmovetype_start_default;
92 self.platmovetype_end = self.platmovetype_end_default;
98 SUB_CalcMove_Bezier(cp_org, targ.origin - self.view_ofs, TSPEED_LINEAR, targ.speed, train_wait);
100 SUB_CalcMove(targ.origin - self.view_ofs, TSPEED_LINEAR, targ.speed, train_wait);
105 SUB_CalcMove_Bezier(cp_org, targ.origin - self.view_ofs, TSPEED_LINEAR, self.speed, train_wait);
107 SUB_CalcMove(targ.origin - self.view_ofs, TSPEED_LINEAR, self.speed, train_wait);
111 _sound(self, CH_TRIGGER_SINGLE, self.noise, VOL_BASE, ATTEN_IDLE);
114 REGISTER_NET_LINKED(ENT_CLIENT_TRAIN)
117 float train_send(entity to, float sf)
119 WriteHeader(MSG_ENTITY, ENT_CLIENT_TRAIN);
120 WriteByte(MSG_ENTITY, sf);
122 if(sf & SF_TRIGGER_INIT)
124 WriteString(MSG_ENTITY, self.platmovetype);
125 WriteByte(MSG_ENTITY, self.platmovetype_turn);
126 WriteByte(MSG_ENTITY, self.spawnflags);
128 WriteString(MSG_ENTITY, self.model);
130 trigger_common_write(self, true);
132 WriteString(MSG_ENTITY, self.curvetarget);
134 WriteCoord(MSG_ENTITY, self.pos1_x);
135 WriteCoord(MSG_ENTITY, self.pos1_y);
136 WriteCoord(MSG_ENTITY, self.pos1_z);
137 WriteCoord(MSG_ENTITY, self.pos2_x);
138 WriteCoord(MSG_ENTITY, self.pos2_y);
139 WriteCoord(MSG_ENTITY, self.pos2_z);
141 WriteCoord(MSG_ENTITY, self.size_x);
142 WriteCoord(MSG_ENTITY, self.size_y);
143 WriteCoord(MSG_ENTITY, self.size_z);
145 WriteCoord(MSG_ENTITY, self.view_ofs_x);
146 WriteCoord(MSG_ENTITY, self.view_ofs_y);
147 WriteCoord(MSG_ENTITY, self.view_ofs_z);
149 WriteAngle(MSG_ENTITY, self.mangle_x);
150 WriteAngle(MSG_ENTITY, self.mangle_y);
151 WriteAngle(MSG_ENTITY, self.mangle_z);
153 WriteShort(MSG_ENTITY, self.speed);
154 WriteShort(MSG_ENTITY, self.height);
155 WriteByte(MSG_ENTITY, self.lip);
156 WriteByte(MSG_ENTITY, self.state);
157 WriteByte(MSG_ENTITY, self.wait);
159 WriteShort(MSG_ENTITY, self.dmg);
160 WriteByte(MSG_ENTITY, self.dmgtime);
163 if(sf & SF_TRIGGER_RESET)
173 //Net_LinkEntity(self, 0, false, train_send);
178 self.SUB_NEXTTHINK = self.SUB_LTIME + 1;
179 self.SUB_THINK = train_next;
180 self.use = func_null; // not again
183 void func_train_find()
186 targ = find(world, targetname, self.target);
187 self.target = targ.target;
188 if (self.target == "")
189 objerror("func_train_find: no next target");
190 SUB_SETORIGIN(self, targ.origin - self.view_ofs);
192 if(!(self.spawnflags & 4))
194 self.SUB_NEXTTHINK = self.SUB_LTIME + 1;
195 self.SUB_THINK = train_next;
203 /*QUAKED spawnfunc_func_train (0 .5 .8) ?
204 Ridable platform, targets spawnfunc_path_corner path to follow.
205 speed : speed the train moves (can be overridden by each spawnfunc_path_corner)
206 target : targetname of first spawnfunc_path_corner (starts here)
209 spawnfunc(func_train)
211 if (self.noise != "")
212 precache_sound(self.noise);
214 if (self.target == "")
215 objerror("func_train without a target");
219 if (!InitMovingBrushTrigger())
221 self.effects |= EF_LOWPRECISION;
223 if(self.spawnflags & 4)
224 self.use = train_use;
226 if (self.spawnflags & 2)
228 self.platmovetype_turn = true;
229 self.view_ofs = '0 0 0'; // don't offset a rotating train, origin works differently now
232 self.view_ofs = self.mins;
234 // wait for targets to spawn
235 InitializeEntity(self, func_train_find, INITPRIO_FINDTARGET);
237 self.blocked = generic_plat_blocked;
238 if(self.dmg && (self.message == ""))
239 self.message = " was squished";
240 if(self.dmg && (self.message2 == ""))
241 self.message2 = "was squished by";
242 if(self.dmg && (!self.dmgtime))
244 self.dmgtime2 = time;
246 if(!set_platmovetype(self, self.platmovetype))
248 self.platmovetype_start_default = self.platmovetype_start;
249 self.platmovetype_end_default = self.platmovetype_end;
251 // TODO make a reset function for this one
254 void train_draw(entity this)
256 //Movetype_Physics_NoMatchServer();
257 Movetype_Physics_MatchServer(this, autocvar_cl_projectiles_sloppy);
260 NET_HANDLE(ENT_CLIENT_TRAIN, bool isnew)
262 float sf = ReadByte();
264 if(sf & SF_TRIGGER_INIT)
266 self.platmovetype = strzone(ReadString());
267 self.platmovetype_turn = ReadByte();
268 self.spawnflags = ReadByte();
270 self.model = strzone(ReadString());
271 _setmodel(self, self.model);
273 trigger_common_read(true);
275 self.curvetarget = strzone(ReadString());
277 self.pos1_x = ReadCoord();
278 self.pos1_y = ReadCoord();
279 self.pos1_z = ReadCoord();
280 self.pos2_x = ReadCoord();
281 self.pos2_y = ReadCoord();
282 self.pos2_z = ReadCoord();
284 self.size_x = ReadCoord();
285 self.size_y = ReadCoord();
286 self.size_z = ReadCoord();
288 self.view_ofs_x = ReadCoord();
289 self.view_ofs_y = ReadCoord();
290 self.view_ofs_z = ReadCoord();
292 self.mangle_x = ReadAngle();
293 self.mangle_y = ReadAngle();
294 self.mangle_z = ReadAngle();
296 self.speed = ReadShort();
297 self.height = ReadShort();
298 self.lip = ReadByte();
299 self.state = ReadByte();
300 self.wait = ReadByte();
302 self.dmg = ReadShort();
303 self.dmgtime = ReadByte();
305 self.classname = "func_train";
306 self.solid = SOLID_BSP;
307 self.movetype = MOVETYPE_PUSH;
308 self.drawmask = MASK_NORMAL;
309 self.draw = train_draw;
310 self.entremove = trigger_remove_generic;
312 if(set_platmovetype(self, self.platmovetype))
314 self.platmovetype_start_default = self.platmovetype_start;
315 self.platmovetype_end_default = self.platmovetype_end;
318 // everything is set up by the time the train is linked, we shouldn't need this
321 // but we will need these
322 //self.move_nextthink = self.move_ltime + 0.1;
323 //self.move_think = train_next;
326 self.move_movetype = MOVETYPE_PUSH;
327 self.move_origin = self.origin;
328 self.move_angles = self.angles;
329 self.move_time = time;
332 if(sf & SF_TRIGGER_RESET)
334 // TODO: make a reset function for trains