1 .float train_wait_turning;
8 WITHSELF(self.enemy, SUB_UseTargets());
11 // if turning is enabled, the train will turn toward the next point while waiting
12 if(self.platmovetype_turn && !self.train_wait_turning)
16 targ = find(world, targetname, self.target);
17 if((self.spawnflags & 1) && targ.curvetarget)
18 cp = find(world, targetname, targ.curvetarget);
22 if(cp) // bezier curves movement
23 ang = cp.origin - (self.origin - self.view_ofs); // use the origin of the control point of the next path_corner
24 else // linear movement
25 ang = targ.origin - (self.origin - self.view_ofs); // use the origin of the next path_corner
26 ang = vectoangles(ang);
27 ang_x = -ang_x; // flip up / down orientation
29 if(self.wait > 0) // slow turning
30 SUB_CalcAngleMove(ang, TSPEED_TIME, self.SUB_LTIME - time + self.wait, train_wait);
31 else // instant turning
32 SUB_CalcAngleMove(ang, TSPEED_TIME, 0.0000001, train_wait);
33 self.train_wait_turning = true;
39 stopsoundto(MSG_BROADCAST, self, CH_TRIGGER_SINGLE); // send this as unreliable only, as the train will resume operation shortly anyway
43 entity tg = find(world, targetname, self.target);
47 self.SUB_THINK = func_null;
48 self.SUB_NEXTTHINK = 0;
52 if(self.wait < 0 || self.train_wait_turning) // no waiting or we already waited while turning
54 self.train_wait_turning = false;
59 self.SUB_THINK = train_next;
60 self.SUB_NEXTTHINK = self.SUB_LTIME + self.wait;
66 entity targ, cp = world;
67 vector cp_org = '0 0 0';
69 targ = find(world, targetname, self.target);
70 self.target = targ.target;
71 if (self.spawnflags & 1)
75 cp = find(world, targetname, targ.curvetarget); // get its second target (the control point)
76 cp_org = cp.origin - self.view_ofs; // no control point found, assume a straight line to the destination
79 if (self.target == "")
80 objerror("train_next: no next target");
81 self.wait = targ.wait;
87 // this path_corner contains a movetype overrider, apply it
88 self.platmovetype_start = targ.platmovetype_start;
89 self.platmovetype_end = targ.platmovetype_end;
93 // this path_corner doesn't contain a movetype overrider, use the train's defaults
94 self.platmovetype_start = self.platmovetype_start_default;
95 self.platmovetype_end = self.platmovetype_end_default;
101 SUB_CalcMove_Bezier(cp_org, targ.origin - self.view_ofs, TSPEED_LINEAR, targ.speed, train_wait);
103 SUB_CalcMove(targ.origin - self.view_ofs, TSPEED_LINEAR, targ.speed, train_wait);
108 SUB_CalcMove_Bezier(cp_org, targ.origin - self.view_ofs, TSPEED_LINEAR, self.speed, train_wait);
110 SUB_CalcMove(targ.origin - self.view_ofs, TSPEED_LINEAR, self.speed, train_wait);
114 _sound(self, CH_TRIGGER_SINGLE, self.noise, VOL_BASE, ATTEN_IDLE);
117 REGISTER_NET_LINKED(ENT_CLIENT_TRAIN)
120 float train_send(entity to, float sf)
122 WriteHeader(MSG_ENTITY, ENT_CLIENT_TRAIN);
123 WriteByte(MSG_ENTITY, sf);
125 if(sf & SF_TRIGGER_INIT)
127 WriteString(MSG_ENTITY, self.platmovetype);
128 WriteByte(MSG_ENTITY, self.platmovetype_turn);
129 WriteByte(MSG_ENTITY, self.spawnflags);
131 WriteString(MSG_ENTITY, self.model);
133 trigger_common_write(self, true);
135 WriteString(MSG_ENTITY, self.curvetarget);
137 WriteCoord(MSG_ENTITY, self.pos1_x);
138 WriteCoord(MSG_ENTITY, self.pos1_y);
139 WriteCoord(MSG_ENTITY, self.pos1_z);
140 WriteCoord(MSG_ENTITY, self.pos2_x);
141 WriteCoord(MSG_ENTITY, self.pos2_y);
142 WriteCoord(MSG_ENTITY, self.pos2_z);
144 WriteCoord(MSG_ENTITY, self.size_x);
145 WriteCoord(MSG_ENTITY, self.size_y);
146 WriteCoord(MSG_ENTITY, self.size_z);
148 WriteCoord(MSG_ENTITY, self.view_ofs_x);
149 WriteCoord(MSG_ENTITY, self.view_ofs_y);
150 WriteCoord(MSG_ENTITY, self.view_ofs_z);
152 WriteAngle(MSG_ENTITY, self.mangle_x);
153 WriteAngle(MSG_ENTITY, self.mangle_y);
154 WriteAngle(MSG_ENTITY, self.mangle_z);
156 WriteShort(MSG_ENTITY, self.speed);
157 WriteShort(MSG_ENTITY, self.height);
158 WriteByte(MSG_ENTITY, self.lip);
159 WriteByte(MSG_ENTITY, self.state);
160 WriteByte(MSG_ENTITY, self.wait);
162 WriteShort(MSG_ENTITY, self.dmg);
163 WriteByte(MSG_ENTITY, self.dmgtime);
166 if(sf & SF_TRIGGER_RESET)
176 //Net_LinkEntity(self, 0, false, train_send);
182 self.SUB_NEXTTHINK = self.SUB_LTIME + 1;
183 self.SUB_THINK = train_next;
184 self.use = func_null; // not again
187 void func_train_find()
190 targ = find(world, targetname, self.target);
191 self.target = targ.target;
192 if (self.target == "")
193 objerror("func_train_find: no next target");
194 SUB_SETORIGIN(self, targ.origin - self.view_ofs);
196 if(!(self.spawnflags & 4))
198 self.SUB_NEXTTHINK = self.SUB_LTIME + 1;
199 self.SUB_THINK = train_next;
207 /*QUAKED spawnfunc_func_train (0 .5 .8) ?
208 Ridable platform, targets spawnfunc_path_corner path to follow.
209 speed : speed the train moves (can be overridden by each spawnfunc_path_corner)
210 target : targetname of first spawnfunc_path_corner (starts here)
213 spawnfunc(func_train)
215 if (self.noise != "")
216 precache_sound(self.noise);
218 if (self.target == "")
219 objerror("func_train without a target");
223 if (!InitMovingBrushTrigger())
225 self.effects |= EF_LOWPRECISION;
227 if(self.spawnflags & 4)
228 self.use = train_use;
230 if (self.spawnflags & 2)
232 self.platmovetype_turn = true;
233 self.view_ofs = '0 0 0'; // don't offset a rotating train, origin works differently now
236 self.view_ofs = self.mins;
238 // wait for targets to spawn
239 InitializeEntity(self, func_train_find, INITPRIO_FINDTARGET);
241 self.blocked = generic_plat_blocked;
242 if(self.dmg && (self.message == ""))
243 self.message = " was squished";
244 if(self.dmg && (self.message2 == ""))
245 self.message2 = "was squished by";
246 if(self.dmg && (!self.dmgtime))
248 self.dmgtime2 = time;
250 if(!set_platmovetype(self, self.platmovetype))
252 self.platmovetype_start_default = self.platmovetype_start;
253 self.platmovetype_end_default = self.platmovetype_end;
255 // TODO make a reset function for this one
258 void train_draw(entity this)
260 //Movetype_Physics_NoMatchServer();
261 Movetype_Physics_MatchServer(this, autocvar_cl_projectiles_sloppy);
264 NET_HANDLE(ENT_CLIENT_TRAIN, bool isnew)
266 float sf = ReadByte();
268 if(sf & SF_TRIGGER_INIT)
270 self.platmovetype = strzone(ReadString());
271 self.platmovetype_turn = ReadByte();
272 self.spawnflags = ReadByte();
274 self.model = strzone(ReadString());
275 _setmodel(self, self.model);
277 trigger_common_read(true);
279 self.curvetarget = strzone(ReadString());
281 self.pos1_x = ReadCoord();
282 self.pos1_y = ReadCoord();
283 self.pos1_z = ReadCoord();
284 self.pos2_x = ReadCoord();
285 self.pos2_y = ReadCoord();
286 self.pos2_z = ReadCoord();
288 self.size_x = ReadCoord();
289 self.size_y = ReadCoord();
290 self.size_z = ReadCoord();
292 self.view_ofs_x = ReadCoord();
293 self.view_ofs_y = ReadCoord();
294 self.view_ofs_z = ReadCoord();
296 self.mangle_x = ReadAngle();
297 self.mangle_y = ReadAngle();
298 self.mangle_z = ReadAngle();
300 self.speed = ReadShort();
301 self.height = ReadShort();
302 self.lip = ReadByte();
303 self.state = ReadByte();
304 self.wait = ReadByte();
306 self.dmg = ReadShort();
307 self.dmgtime = ReadByte();
309 self.classname = "func_train";
310 self.solid = SOLID_BSP;
311 self.movetype = MOVETYPE_PUSH;
312 self.drawmask = MASK_NORMAL;
313 self.draw = train_draw;
314 self.entremove = trigger_remove_generic;
316 if(set_platmovetype(self, self.platmovetype))
318 self.platmovetype_start_default = self.platmovetype_start;
319 self.platmovetype_end_default = self.platmovetype_end;
322 // everything is set up by the time the train is linked, we shouldn't need this
325 // but we will need these
326 //self.move_nextthink = self.move_ltime + 0.1;
327 //self.move_think = train_next;
330 self.move_movetype = MOVETYPE_PUSH;
331 self.move_origin = self.origin;
332 self.move_angles = self.angles;
333 self.move_time = time;
336 if(sf & SF_TRIGGER_RESET)
338 // TODO: make a reset function for trains