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
39 if(self.wait < 0 || self.train_wait_turning) // no waiting or we already waited while turning
41 self.train_wait_turning = false;
46 self.SUB_THINK = train_next;
47 self.SUB_NEXTTHINK = self.SUB_LTIME + self.wait;
53 entity targ, cp = world;
54 vector cp_org = '0 0 0';
56 targ = find(world, targetname, self.target);
57 self.target = targ.target;
58 if (self.spawnflags & 1)
62 cp = find(world, targetname, targ.curvetarget); // get its second target (the control point)
63 cp_org = cp.origin - self.view_ofs; // no control point found, assume a straight line to the destination
66 if (self.target == "")
67 objerror("train_next: no next target");
68 self.wait = targ.wait;
74 // this path_corner contains a movetype overrider, apply it
75 self.platmovetype_start = targ.platmovetype_start;
76 self.platmovetype_end = targ.platmovetype_end;
80 // this path_corner doesn't contain a movetype overrider, use the train's defaults
81 self.platmovetype_start = self.platmovetype_start_default;
82 self.platmovetype_end = self.platmovetype_end_default;
88 SUB_CalcMove_Bezier(cp_org, targ.origin - self.view_ofs, TSPEED_LINEAR, targ.speed, train_wait);
90 SUB_CalcMove(targ.origin - self.view_ofs, TSPEED_LINEAR, targ.speed, train_wait);
95 SUB_CalcMove_Bezier(cp_org, targ.origin - self.view_ofs, TSPEED_LINEAR, self.speed, train_wait);
97 SUB_CalcMove(targ.origin - self.view_ofs, TSPEED_LINEAR, self.speed, train_wait);
101 _sound(self, CH_TRIGGER_SINGLE, self.noise, VOL_BASE, ATTEN_IDLE);
104 REGISTER_NET_LINKED(ENT_CLIENT_TRAIN)
107 float train_send(entity to, float sf)
109 WriteHeader(MSG_ENTITY, ENT_CLIENT_TRAIN);
110 WriteByte(MSG_ENTITY, sf);
112 if(sf & SF_TRIGGER_INIT)
114 WriteString(MSG_ENTITY, self.platmovetype);
115 WriteByte(MSG_ENTITY, self.platmovetype_turn);
116 WriteByte(MSG_ENTITY, self.spawnflags);
118 WriteString(MSG_ENTITY, self.model);
120 trigger_common_write(self, true);
122 WriteString(MSG_ENTITY, self.curvetarget);
124 WriteCoord(MSG_ENTITY, self.pos1_x);
125 WriteCoord(MSG_ENTITY, self.pos1_y);
126 WriteCoord(MSG_ENTITY, self.pos1_z);
127 WriteCoord(MSG_ENTITY, self.pos2_x);
128 WriteCoord(MSG_ENTITY, self.pos2_y);
129 WriteCoord(MSG_ENTITY, self.pos2_z);
131 WriteCoord(MSG_ENTITY, self.size_x);
132 WriteCoord(MSG_ENTITY, self.size_y);
133 WriteCoord(MSG_ENTITY, self.size_z);
135 WriteCoord(MSG_ENTITY, self.view_ofs_x);
136 WriteCoord(MSG_ENTITY, self.view_ofs_y);
137 WriteCoord(MSG_ENTITY, self.view_ofs_z);
139 WriteAngle(MSG_ENTITY, self.mangle_x);
140 WriteAngle(MSG_ENTITY, self.mangle_y);
141 WriteAngle(MSG_ENTITY, self.mangle_z);
143 WriteShort(MSG_ENTITY, self.speed);
144 WriteShort(MSG_ENTITY, self.height);
145 WriteByte(MSG_ENTITY, self.lip);
146 WriteByte(MSG_ENTITY, self.state);
147 WriteByte(MSG_ENTITY, self.wait);
149 WriteShort(MSG_ENTITY, self.dmg);
150 WriteByte(MSG_ENTITY, self.dmgtime);
153 if(sf & SF_TRIGGER_RESET)
163 //Net_LinkEntity(self, 0, false, train_send);
168 self.SUB_NEXTTHINK = self.SUB_LTIME + 1;
169 self.SUB_THINK = train_next;
170 self.use = func_null; // not again
173 void func_train_find()
176 targ = find(world, targetname, self.target);
177 self.target = targ.target;
178 if (self.target == "")
179 objerror("func_train_find: no next target");
180 SUB_SETORIGIN(self, targ.origin - self.view_ofs);
182 if(!(self.spawnflags & 4))
184 self.SUB_NEXTTHINK = self.SUB_LTIME + 1;
185 self.SUB_THINK = train_next;
193 /*QUAKED spawnfunc_func_train (0 .5 .8) ?
194 Ridable platform, targets spawnfunc_path_corner path to follow.
195 speed : speed the train moves (can be overridden by each spawnfunc_path_corner)
196 target : targetname of first spawnfunc_path_corner (starts here)
199 spawnfunc(func_train)
201 if (self.noise != "")
202 precache_sound(self.noise);
204 if (self.target == "")
205 objerror("func_train without a target");
209 if (!InitMovingBrushTrigger())
211 self.effects |= EF_LOWPRECISION;
213 if(self.spawnflags & 4)
214 self.use = train_use;
216 if (self.spawnflags & 2)
218 self.platmovetype_turn = true;
219 self.view_ofs = '0 0 0'; // don't offset a rotating train, origin works differently now
222 self.view_ofs = self.mins;
224 // wait for targets to spawn
225 InitializeEntity(self, func_train_find, INITPRIO_FINDTARGET);
227 self.blocked = generic_plat_blocked;
228 if(self.dmg && (self.message == ""))
229 self.message = " was squished";
230 if(self.dmg && (self.message2 == ""))
231 self.message2 = "was squished by";
232 if(self.dmg && (!self.dmgtime))
234 self.dmgtime2 = time;
236 if(!set_platmovetype(self, self.platmovetype))
238 self.platmovetype_start_default = self.platmovetype_start;
239 self.platmovetype_end_default = self.platmovetype_end;
241 // TODO make a reset function for this one
244 void train_draw(entity this)
246 //Movetype_Physics_NoMatchServer();
247 Movetype_Physics_MatchServer(this, autocvar_cl_projectiles_sloppy);
250 NET_HANDLE(ENT_CLIENT_TRAIN, bool isnew)
252 float sf = ReadByte();
254 if(sf & SF_TRIGGER_INIT)
256 self.platmovetype = strzone(ReadString());
257 self.platmovetype_turn = ReadByte();
258 self.spawnflags = ReadByte();
260 self.model = strzone(ReadString());
261 _setmodel(self, self.model);
263 trigger_common_read(true);
265 self.curvetarget = strzone(ReadString());
267 self.pos1_x = ReadCoord();
268 self.pos1_y = ReadCoord();
269 self.pos1_z = ReadCoord();
270 self.pos2_x = ReadCoord();
271 self.pos2_y = ReadCoord();
272 self.pos2_z = ReadCoord();
274 self.size_x = ReadCoord();
275 self.size_y = ReadCoord();
276 self.size_z = ReadCoord();
278 self.view_ofs_x = ReadCoord();
279 self.view_ofs_y = ReadCoord();
280 self.view_ofs_z = ReadCoord();
282 self.mangle_x = ReadAngle();
283 self.mangle_y = ReadAngle();
284 self.mangle_z = ReadAngle();
286 self.speed = ReadShort();
287 self.height = ReadShort();
288 self.lip = ReadByte();
289 self.state = ReadByte();
290 self.wait = ReadByte();
292 self.dmg = ReadShort();
293 self.dmgtime = ReadByte();
295 self.classname = "func_train";
296 self.solid = SOLID_BSP;
297 self.movetype = MOVETYPE_PUSH;
298 self.drawmask = MASK_NORMAL;
299 self.draw = train_draw;
300 self.entremove = trigger_remove_generic;
302 if(set_platmovetype(self, self.platmovetype))
304 self.platmovetype_start_default = self.platmovetype_start;
305 self.platmovetype_end_default = self.platmovetype_end;
308 // everything is set up by the time the train is linked, we shouldn't need this
311 // but we will need these
312 //self.move_nextthink = self.move_ltime + 0.1;
313 //self.move_think = train_next;
316 self.move_movetype = MOVETYPE_PUSH;
317 self.move_origin = self.origin;
318 self.move_angles = self.angles;
319 self.move_time = time;
322 if(sf & SF_TRIGGER_RESET)
324 // TODO: make a reset function for trains