1 .float train_wait_turning;
5 SELFCALL(self.enemy, SUB_UseTargets());
9 // if turning is enabled, the train will turn toward the next point while waiting
10 if(self.platmovetype_turn && !self.train_wait_turning)
14 targ = find(world, targetname, self.target);
15 if((self.spawnflags & 1) && targ.curvetarget)
16 cp = find(world, targetname, targ.curvetarget);
20 if(cp) // bezier curves movement
21 ang = cp.origin - (self.origin - self.view_ofs); // use the origin of the control point of the next path_corner
22 else // linear movement
23 ang = targ.origin - (self.origin - self.view_ofs); // use the origin of the next path_corner
24 ang = vectoangles(ang);
25 ang_x = -ang_x; // flip up / down orientation
27 if(self.wait > 0) // slow turning
28 SUB_CalcAngleMove(ang, TSPEED_TIME, self.SUB_LTIME - time + self.wait, train_wait);
29 else // instant turning
30 SUB_CalcAngleMove(ang, TSPEED_TIME, 0.0000001, train_wait);
31 self.train_wait_turning = true;
37 stopsoundto(MSG_BROADCAST, self, CH_TRIGGER_SINGLE); // send this as unreliable only, as the train will resume operation shortly anyway
40 if(self.wait < 0 || self.train_wait_turning) // no waiting or we already waited while turning
42 self.train_wait_turning = false;
47 self.SUB_THINK = train_next;
48 self.SUB_NEXTTHINK = self.SUB_LTIME + self.wait;
54 entity targ, cp = world;
55 vector cp_org = '0 0 0';
57 targ = find(world, targetname, self.target);
58 self.target = targ.target;
59 if (self.spawnflags & 1)
63 cp = find(world, targetname, targ.curvetarget); // get its second target (the control point)
64 cp_org = cp.origin - self.view_ofs; // no control point found, assume a straight line to the destination
67 if (self.target == "")
68 objerror("train_next: no next target");
69 self.wait = targ.wait;
75 // this path_corner contains a movetype overrider, apply it
76 self.platmovetype_start = targ.platmovetype_start;
77 self.platmovetype_end = targ.platmovetype_end;
81 // this path_corner doesn't contain a movetype overrider, use the train's defaults
82 self.platmovetype_start = self.platmovetype_start_default;
83 self.platmovetype_end = self.platmovetype_end_default;
89 SUB_CalcMove_Bezier(cp_org, targ.origin - self.view_ofs, TSPEED_LINEAR, targ.speed, train_wait);
91 SUB_CalcMove(targ.origin - self.view_ofs, TSPEED_LINEAR, targ.speed, train_wait);
96 SUB_CalcMove_Bezier(cp_org, targ.origin - self.view_ofs, TSPEED_LINEAR, self.speed, train_wait);
98 SUB_CalcMove(targ.origin - self.view_ofs, TSPEED_LINEAR, self.speed, train_wait);
102 sound(self, CH_TRIGGER_SINGLE, self.noise, VOL_BASE, ATTEN_IDLE);
106 float train_send(entity to, float sf)
108 WriteByte(MSG_ENTITY, ENT_CLIENT_TRAIN);
109 WriteByte(MSG_ENTITY, sf);
111 if(sf & SF_TRIGGER_INIT)
113 WriteString(MSG_ENTITY, self.platmovetype);
114 WriteByte(MSG_ENTITY, self.platmovetype_turn);
115 WriteByte(MSG_ENTITY, self.spawnflags);
117 WriteString(MSG_ENTITY, self.model);
119 trigger_common_write(true);
121 WriteString(MSG_ENTITY, self.curvetarget);
123 WriteCoord(MSG_ENTITY, self.pos1_x);
124 WriteCoord(MSG_ENTITY, self.pos1_y);
125 WriteCoord(MSG_ENTITY, self.pos1_z);
126 WriteCoord(MSG_ENTITY, self.pos2_x);
127 WriteCoord(MSG_ENTITY, self.pos2_y);
128 WriteCoord(MSG_ENTITY, self.pos2_z);
130 WriteCoord(MSG_ENTITY, self.size_x);
131 WriteCoord(MSG_ENTITY, self.size_y);
132 WriteCoord(MSG_ENTITY, self.size_z);
134 WriteCoord(MSG_ENTITY, self.view_ofs_x);
135 WriteCoord(MSG_ENTITY, self.view_ofs_y);
136 WriteCoord(MSG_ENTITY, self.view_ofs_z);
138 WriteAngle(MSG_ENTITY, self.mangle_x);
139 WriteAngle(MSG_ENTITY, self.mangle_y);
140 WriteAngle(MSG_ENTITY, self.mangle_z);
142 WriteShort(MSG_ENTITY, self.speed);
143 WriteShort(MSG_ENTITY, self.height);
144 WriteByte(MSG_ENTITY, self.lip);
145 WriteByte(MSG_ENTITY, self.state);
146 WriteByte(MSG_ENTITY, self.wait);
148 WriteShort(MSG_ENTITY, self.dmg);
149 WriteByte(MSG_ENTITY, self.dmgtime);
152 if(sf & SF_TRIGGER_RESET)
162 //Net_LinkEntity(self, 0, false, train_send);
165 void func_train_find()
168 targ = find(world, targetname, self.target);
169 self.target = targ.target;
170 if (self.target == "")
171 objerror("func_train_find: no next target");
172 SUB_SETORIGIN(self, targ.origin - self.view_ofs);
173 self.SUB_NEXTTHINK = self.SUB_LTIME + 1;
174 self.SUB_THINK = train_next;
181 /*QUAKED spawnfunc_func_train (0 .5 .8) ?
182 Ridable platform, targets spawnfunc_path_corner path to follow.
183 speed : speed the train moves (can be overridden by each spawnfunc_path_corner)
184 target : targetname of first spawnfunc_path_corner (starts here)
187 void spawnfunc_func_train()
189 if (self.noise != "")
190 precache_sound(self.noise);
192 if (self.target == "")
193 objerror("func_train without a target");
197 if (!InitMovingBrushTrigger())
199 self.effects |= EF_LOWPRECISION;
201 if (self.spawnflags & 2)
203 self.platmovetype_turn = true;
204 self.view_ofs = '0 0 0'; // don't offset a rotating train, origin works differently now
207 self.view_ofs = self.mins;
209 // wait for targets to spawn
210 InitializeEntity(self, func_train_find, INITPRIO_FINDTARGET);
212 self.blocked = generic_plat_blocked;
213 if(self.dmg && (self.message == ""))
214 self.message = " was squished";
215 if(self.dmg && (self.message2 == ""))
216 self.message2 = "was squished by";
217 if(self.dmg && (!self.dmgtime))
219 self.dmgtime2 = time;
221 if(!set_platmovetype(self, self.platmovetype))
223 self.platmovetype_start_default = self.platmovetype_start;
224 self.platmovetype_end_default = self.platmovetype_end;
226 // TODO make a reset function for this one
231 //Movetype_Physics_NoMatchServer();
232 Movetype_Physics_MatchServer(autocvar_cl_projectiles_sloppy);
237 float sf = ReadByte();
239 if(sf & SF_TRIGGER_INIT)
241 self.platmovetype = strzone(ReadString());
242 self.platmovetype_turn = ReadByte();
243 self.spawnflags = ReadByte();
245 self.model = strzone(ReadString());
246 setmodel(self, self.model);
248 trigger_common_read(true);
250 self.curvetarget = strzone(ReadString());
252 self.pos1_x = ReadCoord();
253 self.pos1_y = ReadCoord();
254 self.pos1_z = ReadCoord();
255 self.pos2_x = ReadCoord();
256 self.pos2_y = ReadCoord();
257 self.pos2_z = ReadCoord();
259 self.size_x = ReadCoord();
260 self.size_y = ReadCoord();
261 self.size_z = ReadCoord();
263 self.view_ofs_x = ReadCoord();
264 self.view_ofs_y = ReadCoord();
265 self.view_ofs_z = ReadCoord();
267 self.mangle_x = ReadAngle();
268 self.mangle_y = ReadAngle();
269 self.mangle_z = ReadAngle();
271 self.speed = ReadShort();
272 self.height = ReadShort();
273 self.lip = ReadByte();
274 self.state = ReadByte();
275 self.wait = ReadByte();
277 self.dmg = ReadShort();
278 self.dmgtime = ReadByte();
280 self.classname = "func_train";
281 self.solid = SOLID_BSP;
282 self.movetype = MOVETYPE_PUSH;
283 self.drawmask = MASK_NORMAL;
284 self.draw = train_draw;
285 self.entremove = trigger_remove_generic;
287 if(set_platmovetype(self, self.platmovetype))
289 self.platmovetype_start_default = self.platmovetype_start;
290 self.platmovetype_end_default = self.platmovetype_end;
293 // everything is set up by the time the train is linked, we shouldn't need this
296 // but we will need these
297 //self.move_nextthink = self.move_ltime + 0.1;
298 //self.move_think = train_next;
301 self.move_movetype = MOVETYPE_PUSH;
302 self.move_origin = self.origin;
303 self.move_angles = self.angles;
304 self.move_time = time;
307 if(sf & SF_TRIGGER_RESET)
309 // TODO: make a reset function for trains