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);
105 float train_send(entity to, float sf)
107 WriteByte(MSG_ENTITY, ENT_CLIENT_TRAIN);
108 WriteByte(MSG_ENTITY, sf);
110 if(sf & SF_TRIGGER_INIT)
112 WriteString(MSG_ENTITY, self.platmovetype);
113 WriteByte(MSG_ENTITY, self.platmovetype_turn);
114 WriteByte(MSG_ENTITY, self.spawnflags);
116 WriteString(MSG_ENTITY, self.model);
118 trigger_common_write(true);
120 WriteString(MSG_ENTITY, self.curvetarget);
122 WriteCoord(MSG_ENTITY, self.pos1_x);
123 WriteCoord(MSG_ENTITY, self.pos1_y);
124 WriteCoord(MSG_ENTITY, self.pos1_z);
125 WriteCoord(MSG_ENTITY, self.pos2_x);
126 WriteCoord(MSG_ENTITY, self.pos2_y);
127 WriteCoord(MSG_ENTITY, self.pos2_z);
129 WriteCoord(MSG_ENTITY, self.size_x);
130 WriteCoord(MSG_ENTITY, self.size_y);
131 WriteCoord(MSG_ENTITY, self.size_z);
133 WriteCoord(MSG_ENTITY, self.view_ofs_x);
134 WriteCoord(MSG_ENTITY, self.view_ofs_y);
135 WriteCoord(MSG_ENTITY, self.view_ofs_z);
137 WriteAngle(MSG_ENTITY, self.mangle_x);
138 WriteAngle(MSG_ENTITY, self.mangle_y);
139 WriteAngle(MSG_ENTITY, self.mangle_z);
141 WriteShort(MSG_ENTITY, self.speed);
142 WriteShort(MSG_ENTITY, self.height);
143 WriteByte(MSG_ENTITY, self.lip);
144 WriteByte(MSG_ENTITY, self.state);
145 WriteByte(MSG_ENTITY, self.wait);
147 WriteShort(MSG_ENTITY, self.dmg);
148 WriteByte(MSG_ENTITY, self.dmgtime);
151 if(sf & SF_TRIGGER_RESET)
161 //Net_LinkEntity(self, 0, false, train_send);
164 void func_train_find()
167 targ = find(world, targetname, self.target);
168 self.target = targ.target;
169 if (self.target == "")
170 objerror("func_train_find: no next target");
171 SUB_SETORIGIN(self, targ.origin - self.view_ofs);
172 self.SUB_NEXTTHINK = self.SUB_LTIME + 1;
173 self.SUB_THINK = train_next;
180 /*QUAKED spawnfunc_func_train (0 .5 .8) ?
181 Ridable platform, targets spawnfunc_path_corner path to follow.
182 speed : speed the train moves (can be overridden by each spawnfunc_path_corner)
183 target : targetname of first spawnfunc_path_corner (starts here)
186 spawnfunc(func_train)
188 if (self.noise != "")
189 precache_sound(self.noise);
191 if (self.target == "")
192 objerror("func_train without a target");
196 if (!InitMovingBrushTrigger())
198 self.effects |= EF_LOWPRECISION;
200 if (self.spawnflags & 2)
202 self.platmovetype_turn = true;
203 self.view_ofs = '0 0 0'; // don't offset a rotating train, origin works differently now
206 self.view_ofs = self.mins;
208 // wait for targets to spawn
209 InitializeEntity(self, func_train_find, INITPRIO_FINDTARGET);
211 self.blocked = generic_plat_blocked;
212 if(self.dmg && (self.message == ""))
213 self.message = " was squished";
214 if(self.dmg && (self.message2 == ""))
215 self.message2 = "was squished by";
216 if(self.dmg && (!self.dmgtime))
218 self.dmgtime2 = time;
220 if(!set_platmovetype(self, self.platmovetype))
222 self.platmovetype_start_default = self.platmovetype_start;
223 self.platmovetype_end_default = self.platmovetype_end;
225 // TODO make a reset function for this one
230 //Movetype_Physics_NoMatchServer();
231 Movetype_Physics_MatchServer(autocvar_cl_projectiles_sloppy);
236 float sf = ReadByte();
238 if(sf & SF_TRIGGER_INIT)
240 self.platmovetype = strzone(ReadString());
241 self.platmovetype_turn = ReadByte();
242 self.spawnflags = ReadByte();
244 self.model = strzone(ReadString());
245 _setmodel(self, self.model);
247 trigger_common_read(true);
249 self.curvetarget = strzone(ReadString());
251 self.pos1_x = ReadCoord();
252 self.pos1_y = ReadCoord();
253 self.pos1_z = ReadCoord();
254 self.pos2_x = ReadCoord();
255 self.pos2_y = ReadCoord();
256 self.pos2_z = ReadCoord();
258 self.size_x = ReadCoord();
259 self.size_y = ReadCoord();
260 self.size_z = ReadCoord();
262 self.view_ofs_x = ReadCoord();
263 self.view_ofs_y = ReadCoord();
264 self.view_ofs_z = ReadCoord();
266 self.mangle_x = ReadAngle();
267 self.mangle_y = ReadAngle();
268 self.mangle_z = ReadAngle();
270 self.speed = ReadShort();
271 self.height = ReadShort();
272 self.lip = ReadByte();
273 self.state = ReadByte();
274 self.wait = ReadByte();
276 self.dmg = ReadShort();
277 self.dmgtime = ReadByte();
279 self.classname = "func_train";
280 self.solid = SOLID_BSP;
281 self.movetype = MOVETYPE_PUSH;
282 self.drawmask = MASK_NORMAL;
283 self.draw = train_draw;
284 self.entremove = trigger_remove_generic;
286 if(set_platmovetype(self, self.platmovetype))
288 self.platmovetype_start_default = self.platmovetype_start;
289 self.platmovetype_end_default = self.platmovetype_end;
292 // everything is set up by the time the train is linked, we shouldn't need this
295 // but we will need these
296 //self.move_nextthink = self.move_ltime + 0.1;
297 //self.move_think = train_next;
300 self.move_movetype = MOVETYPE_PUSH;
301 self.move_origin = self.origin;
302 self.move_angles = self.angles;
303 self.move_time = time;
306 if(sf & SF_TRIGGER_RESET)
308 // TODO: make a reset function for trains