1 .float train_wait_turning;
12 // if turning is enabled, the train will turn toward the next point while waiting
13 if(self.platmovetype_turn && !self.train_wait_turning)
17 targ = find(world, targetname, self.target);
18 if((self.spawnflags & 1) && targ.curvetarget)
19 cp = find(world, targetname, targ.curvetarget);
23 if(cp) // bezier curves movement
24 ang = cp.origin - (self.origin - self.view_ofs); // use the origin of the control point of the next path_corner
25 else // linear movement
26 ang = targ.origin - (self.origin - self.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(self.wait > 0) // slow turning
31 SUB_CalcAngleMove(ang, TSPEED_TIME, self.SUB_LTIME - time + self.wait, train_wait);
32 else // instant turning
33 SUB_CalcAngleMove(ang, TSPEED_TIME, 0.0000001, train_wait);
34 self.train_wait_turning = true;
40 stopsoundto(MSG_BROADCAST, self, CH_TRIGGER_SINGLE); // send this as unreliable only, as the train will resume operation shortly anyway
43 if(self.wait < 0 || self.train_wait_turning) // no waiting or we already waited while turning
45 self.train_wait_turning = false;
50 self.SUB_THINK = train_next;
51 self.SUB_NEXTTHINK = self.SUB_LTIME + self.wait;
57 entity targ, cp = world;
58 vector cp_org = '0 0 0';
60 targ = find(world, targetname, self.target);
61 self.target = targ.target;
62 if (self.spawnflags & 1)
66 cp = find(world, targetname, targ.curvetarget); // get its second target (the control point)
67 cp_org = cp.origin - self.view_ofs; // no control point found, assume a straight line to the destination
70 if (self.target == "")
71 objerror("train_next: no next target");
72 self.wait = targ.wait;
78 // this path_corner contains a movetype overrider, apply it
79 self.platmovetype_start = targ.platmovetype_start;
80 self.platmovetype_end = targ.platmovetype_end;
84 // this path_corner doesn't contain a movetype overrider, use the train's defaults
85 self.platmovetype_start = self.platmovetype_start_default;
86 self.platmovetype_end = self.platmovetype_end_default;
92 SUB_CalcMove_Bezier(cp_org, targ.origin - self.view_ofs, TSPEED_LINEAR, targ.speed, train_wait);
94 SUB_CalcMove(targ.origin - self.view_ofs, TSPEED_LINEAR, targ.speed, train_wait);
99 SUB_CalcMove_Bezier(cp_org, targ.origin - self.view_ofs, TSPEED_LINEAR, self.speed, train_wait);
101 SUB_CalcMove(targ.origin - self.view_ofs, TSPEED_LINEAR, self.speed, train_wait);
105 sound(self, CH_TRIGGER_SINGLE, self.noise, VOL_BASE, ATTEN_IDLE);
109 float train_send(entity to, float sf)
111 WriteByte(MSG_ENTITY, ENT_CLIENT_TRAIN);
112 WriteByte(MSG_ENTITY, sf);
114 if(sf & SF_TRIGGER_INIT)
116 WriteString(MSG_ENTITY, self.platmovetype);
117 WriteByte(MSG_ENTITY, self.platmovetype_turn);
118 WriteByte(MSG_ENTITY, self.spawnflags);
120 WriteString(MSG_ENTITY, self.model);
122 trigger_common_write(true);
124 WriteString(MSG_ENTITY, self.curvetarget);
126 WriteCoord(MSG_ENTITY, self.pos1_x);
127 WriteCoord(MSG_ENTITY, self.pos1_y);
128 WriteCoord(MSG_ENTITY, self.pos1_z);
129 WriteCoord(MSG_ENTITY, self.pos2_x);
130 WriteCoord(MSG_ENTITY, self.pos2_y);
131 WriteCoord(MSG_ENTITY, self.pos2_z);
133 WriteCoord(MSG_ENTITY, self.size_x);
134 WriteCoord(MSG_ENTITY, self.size_y);
135 WriteCoord(MSG_ENTITY, self.size_z);
137 WriteCoord(MSG_ENTITY, self.view_ofs_x);
138 WriteCoord(MSG_ENTITY, self.view_ofs_y);
139 WriteCoord(MSG_ENTITY, self.view_ofs_z);
141 WriteAngle(MSG_ENTITY, self.mangle_x);
142 WriteAngle(MSG_ENTITY, self.mangle_y);
143 WriteAngle(MSG_ENTITY, self.mangle_z);
145 WriteShort(MSG_ENTITY, self.speed);
146 WriteShort(MSG_ENTITY, self.height);
147 WriteByte(MSG_ENTITY, self.lip);
148 WriteByte(MSG_ENTITY, self.state);
149 WriteByte(MSG_ENTITY, self.wait);
151 WriteShort(MSG_ENTITY, self.dmg);
152 WriteByte(MSG_ENTITY, self.dmgtime);
155 if(sf & SF_TRIGGER_RESET)
165 //Net_LinkEntity(self, 0, false, train_send);
168 void func_train_find()
171 targ = find(world, targetname, self.target);
172 self.target = targ.target;
173 if (self.target == "")
174 objerror("func_train_find: no next target");
175 SUB_SETORIGIN(self, targ.origin - self.view_ofs);
176 self.SUB_NEXTTHINK = self.SUB_LTIME + 1;
177 self.SUB_THINK = train_next;
184 /*QUAKED spawnfunc_func_train (0 .5 .8) ?
185 Ridable platform, targets spawnfunc_path_corner path to follow.
186 speed : speed the train moves (can be overridden by each spawnfunc_path_corner)
187 target : targetname of first spawnfunc_path_corner (starts here)
190 void spawnfunc_func_train()
192 if (self.noise != "")
193 precache_sound(self.noise);
195 if (self.target == "")
196 objerror("func_train without a target");
200 if (!InitMovingBrushTrigger())
202 self.effects |= EF_LOWPRECISION;
204 if (self.spawnflags & 2)
206 self.platmovetype_turn = true;
207 self.view_ofs = '0 0 0'; // don't offset a rotating train, origin works differently now
210 self.view_ofs = self.mins;
212 // wait for targets to spawn
213 InitializeEntity(self, func_train_find, INITPRIO_FINDTARGET);
215 self.blocked = generic_plat_blocked;
216 if(self.dmg && (self.message == ""))
217 self.message = " was squished";
218 if(self.dmg && (self.message2 == ""))
219 self.message2 = "was squished by";
220 if(self.dmg && (!self.dmgtime))
222 self.dmgtime2 = time;
224 if(!set_platmovetype(self, self.platmovetype))
226 self.platmovetype_start_default = self.platmovetype_start;
227 self.platmovetype_end_default = self.platmovetype_end;
229 // TODO make a reset function for this one
234 //Movetype_Physics_NoMatchServer();
235 Movetype_Physics_MatchServer(autocvar_cl_projectiles_sloppy);
240 float sf = ReadByte();
242 if(sf & SF_TRIGGER_INIT)
244 self.platmovetype = strzone(ReadString());
245 self.platmovetype_turn = ReadByte();
246 self.spawnflags = ReadByte();
248 self.model = strzone(ReadString());
249 setmodel(self, self.model);
251 trigger_common_read(true);
253 self.curvetarget = strzone(ReadString());
255 self.pos1_x = ReadCoord();
256 self.pos1_y = ReadCoord();
257 self.pos1_z = ReadCoord();
258 self.pos2_x = ReadCoord();
259 self.pos2_y = ReadCoord();
260 self.pos2_z = ReadCoord();
262 self.size_x = ReadCoord();
263 self.size_y = ReadCoord();
264 self.size_z = ReadCoord();
266 self.view_ofs_x = ReadCoord();
267 self.view_ofs_y = ReadCoord();
268 self.view_ofs_z = ReadCoord();
270 self.mangle_x = ReadAngle();
271 self.mangle_y = ReadAngle();
272 self.mangle_z = ReadAngle();
274 self.speed = ReadShort();
275 self.height = ReadShort();
276 self.lip = ReadByte();
277 self.state = ReadByte();
278 self.wait = ReadByte();
280 self.dmg = ReadShort();
281 self.dmgtime = ReadByte();
283 self.classname = "func_train";
284 self.solid = SOLID_BSP;
285 self.movetype = MOVETYPE_PUSH;
286 self.drawmask = MASK_NORMAL;
287 self.draw = train_draw;
288 self.entremove = trigger_remove_generic;
290 if(set_platmovetype(self, self.platmovetype))
292 self.platmovetype_start_default = self.platmovetype_start;
293 self.platmovetype_end_default = self.platmovetype_end;
296 // everything is set up by the time the train is linked, we shouldn't need this
299 // but we will need these
300 //self.move_nextthink = self.move_ltime + 0.1;
301 //self.move_think = train_next;
304 self.move_movetype = MOVETYPE_PUSH;
305 self.move_origin = self.origin;
306 self.move_angles = self.angles;
307 self.move_time = time;
310 if(sf & SF_TRIGGER_RESET)
312 // TODO: make a reset function for trains