2 .float train_wait_turning;
3 void train_next(entity this);
5 void train_use(entity this, entity actor, entity trigger);
7 void train_wait(entity this)
9 SUB_UseTargets(this.enemy, NULL, NULL);
12 // if turning is enabled, the train will turn toward the next point while waiting
13 if(this.platmovetype_turn && !this.train_wait_turning)
17 targ = find(NULL, targetname, this.target);
18 if((this.spawnflags & 1) && targ.curvetarget)
19 cp = find(NULL, targetname, targ.curvetarget);
23 if(cp) // bezier curves movement
24 ang = cp.origin - (this.origin - this.view_ofs); // use the origin of the control point of the next path_corner
25 else // linear movement
26 ang = targ.origin - (this.origin - this.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(this.wait > 0) // slow turning
31 SUB_CalcAngleMove(this, ang, TSPEED_TIME, this.SUB_LTIME - time + this.wait, train_wait);
32 else // instant turning
33 SUB_CalcAngleMove(this, ang, TSPEED_TIME, 0.0000001, train_wait);
34 this.train_wait_turning = true;
40 stopsoundto(MSG_BROADCAST, this, CH_TRIGGER_SINGLE); // send this as unreliable only, as the train will resume operation shortly anyway
44 entity tg = find(NULL, targetname, this.target);
48 SUB_THINK(this, func_null);
49 this.SUB_NEXTTHINK = 0;
53 if(this.wait < 0 || this.train_wait_turning) // no waiting or we already waited while turning
55 this.train_wait_turning = false;
60 SUB_THINK(this, train_next);
61 this.SUB_NEXTTHINK = this.SUB_LTIME + this.wait;
65 void train_next(entity this)
67 entity targ, cp = NULL;
68 vector cp_org = '0 0 0';
70 targ = find(NULL, targetname, this.target);
71 this.target = targ.target;
72 if (this.spawnflags & 1)
76 cp = find(NULL, targetname, targ.curvetarget); // get its second target (the control point)
77 cp_org = cp.origin - this.view_ofs; // no control point found, assume a straight line to the destination
80 if (this.target == "")
81 objerror(this, "train_next: no next target");
82 this.wait = targ.wait;
88 // this path_corner contains a movetype overrider, apply it
89 this.platmovetype_start = targ.platmovetype_start;
90 this.platmovetype_end = targ.platmovetype_end;
94 // this path_corner doesn't contain a movetype overrider, use the train's defaults
95 this.platmovetype_start = this.platmovetype_start_default;
96 this.platmovetype_end = this.platmovetype_end_default;
102 SUB_CalcMove_Bezier(this, cp_org, targ.origin - this.view_ofs, TSPEED_LINEAR, targ.speed, train_wait);
104 SUB_CalcMove(this, targ.origin - this.view_ofs, TSPEED_LINEAR, targ.speed, train_wait);
109 SUB_CalcMove_Bezier(this, cp_org, targ.origin - this.view_ofs, TSPEED_LINEAR, this.speed, train_wait);
111 SUB_CalcMove(this, targ.origin - this.view_ofs, TSPEED_LINEAR, this.speed, train_wait);
115 _sound(this, CH_TRIGGER_SINGLE, this.noise, VOL_BASE, ATTEN_IDLE);
118 REGISTER_NET_LINKED(ENT_CLIENT_TRAIN)
121 float train_send(entity this, entity to, float sf)
123 WriteHeader(MSG_ENTITY, ENT_CLIENT_TRAIN);
124 WriteByte(MSG_ENTITY, sf);
126 if(sf & SF_TRIGGER_INIT)
128 WriteString(MSG_ENTITY, this.platmovetype);
129 WriteByte(MSG_ENTITY, this.platmovetype_turn);
130 WriteByte(MSG_ENTITY, this.spawnflags);
132 WriteString(MSG_ENTITY, this.model);
134 trigger_common_write(this, true);
136 WriteString(MSG_ENTITY, this.curvetarget);
138 WriteCoord(MSG_ENTITY, this.pos1_x);
139 WriteCoord(MSG_ENTITY, this.pos1_y);
140 WriteCoord(MSG_ENTITY, this.pos1_z);
141 WriteCoord(MSG_ENTITY, this.pos2_x);
142 WriteCoord(MSG_ENTITY, this.pos2_y);
143 WriteCoord(MSG_ENTITY, this.pos2_z);
145 WriteCoord(MSG_ENTITY, this.size_x);
146 WriteCoord(MSG_ENTITY, this.size_y);
147 WriteCoord(MSG_ENTITY, this.size_z);
149 WriteCoord(MSG_ENTITY, this.view_ofs_x);
150 WriteCoord(MSG_ENTITY, this.view_ofs_y);
151 WriteCoord(MSG_ENTITY, this.view_ofs_z);
153 WriteAngle(MSG_ENTITY, this.mangle_x);
154 WriteAngle(MSG_ENTITY, this.mangle_y);
155 WriteAngle(MSG_ENTITY, this.mangle_z);
157 WriteShort(MSG_ENTITY, this.speed);
158 WriteShort(MSG_ENTITY, this.height);
159 WriteByte(MSG_ENTITY, this.lip);
160 WriteByte(MSG_ENTITY, this.state);
161 WriteByte(MSG_ENTITY, this.wait);
163 WriteShort(MSG_ENTITY, this.dmg);
164 WriteByte(MSG_ENTITY, this.dmgtime);
167 if(sf & SF_TRIGGER_RESET)
175 void train_link(entity this)
177 //Net_LinkEntity(this, 0, false, train_send);
180 void train_use(entity this, entity actor, entity trigger)
182 this.SUB_NEXTTHINK = this.SUB_LTIME + 1;
183 SUB_THINK(this, train_next);
184 this.use = func_null; // not again
187 void func_train_find(entity this)
190 targ = find(NULL, targetname, this.target);
191 this.target = targ.target;
192 if (this.target == "")
193 objerror(this, "func_train_find: no next target");
194 SUB_SETORIGIN(this, targ.origin - this.view_ofs);
196 if(!(this.spawnflags & 4))
198 this.SUB_NEXTTHINK = this.SUB_LTIME + 1;
199 SUB_THINK(this, 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 (this.noise != "")
216 precache_sound(this.noise);
218 if (this.target == "")
219 objerror(this, "func_train without a target");
223 if (!InitMovingBrushTrigger(this))
225 this.effects |= EF_LOWPRECISION;
227 if(this.spawnflags & 4)
228 this.use = train_use;
230 if (this.spawnflags & 2)
232 this.platmovetype_turn = true;
233 this.view_ofs = '0 0 0'; // don't offset a rotating train, origin works differently now
236 this.view_ofs = this.mins;
238 // wait for targets to spawn
239 InitializeEntity(this, func_train_find, INITPRIO_FINDTARGET);
241 setblocked(this, generic_plat_blocked);
242 if(this.dmg && (this.message == ""))
243 this.message = " was squished";
244 if(this.dmg && (this.message2 == ""))
245 this.message2 = "was squished by";
246 if(this.dmg && (!this.dmgtime))
248 this.dmgtime2 = time;
250 if(!set_platmovetype(this, this.platmovetype))
252 this.platmovetype_start_default = this.platmovetype_start;
253 this.platmovetype_end_default = this.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 this.platmovetype = strzone(ReadString());
271 this.platmovetype_turn = ReadByte();
272 this.spawnflags = ReadByte();
274 this.model = strzone(ReadString());
275 _setmodel(this, this.model);
277 trigger_common_read(this, true);
279 this.curvetarget = strzone(ReadString());
281 this.pos1_x = ReadCoord();
282 this.pos1_y = ReadCoord();
283 this.pos1_z = ReadCoord();
284 this.pos2_x = ReadCoord();
285 this.pos2_y = ReadCoord();
286 this.pos2_z = ReadCoord();
288 this.size_x = ReadCoord();
289 this.size_y = ReadCoord();
290 this.size_z = ReadCoord();
292 this.view_ofs_x = ReadCoord();
293 this.view_ofs_y = ReadCoord();
294 this.view_ofs_z = ReadCoord();
296 this.mangle_x = ReadAngle();
297 this.mangle_y = ReadAngle();
298 this.mangle_z = ReadAngle();
300 this.speed = ReadShort();
301 this.height = ReadShort();
302 this.lip = ReadByte();
303 this.state = ReadByte();
304 this.wait = ReadByte();
306 this.dmg = ReadShort();
307 this.dmgtime = ReadByte();
309 this.classname = "func_train";
310 this.solid = SOLID_BSP;
311 set_movetype(this, MOVETYPE_PUSH);
312 this.drawmask = MASK_NORMAL;
313 this.draw = train_draw;
314 if (isnew) IL_PUSH(g_drawables, this);
315 this.entremove = trigger_remove_generic;
317 if(set_platmovetype(this, this.platmovetype))
319 this.platmovetype_start_default = this.platmovetype_start;
320 this.platmovetype_end_default = this.platmovetype_end;
323 // everything is set up by the time the train is linked, we shouldn't need this
326 // but we will need these
329 set_movetype(this, MOVETYPE_PUSH);
330 this.move_time = time;
333 if(sf & SF_TRIGGER_RESET)
335 // TODO: make a reset function for trains