1 .float train_wait_turning;
2 void train_next(entity this);
4 void train_use(entity this, entity actor, entity trigger);
6 void train_wait(entity this)
8 SUB_UseTargets(this.enemy, NULL, NULL);
11 // if turning is enabled, the train will turn toward the next point while waiting
12 if(this.platmovetype_turn && !this.train_wait_turning)
16 targ = find(NULL, targetname, this.target);
17 if((this.spawnflags & 1) && targ.curvetarget)
18 cp = find(NULL, targetname, targ.curvetarget);
22 if(cp) // bezier curves movement
23 ang = cp.origin - (this.origin - this.view_ofs); // use the origin of the control point of the next path_corner
24 else // linear movement
25 ang = targ.origin - (this.origin - this.view_ofs); // use the origin of the next path_corner
26 ang = vectoangles(ang);
27 ang_x = -ang_x; // flip up / down orientation
29 if(this.wait > 0) // slow turning
30 SUB_CalcAngleMove(this, ang, TSPEED_TIME, this.SUB_LTIME - time + this.wait, train_wait);
31 else // instant turning
32 SUB_CalcAngleMove(this, ang, TSPEED_TIME, 0.0000001, train_wait);
33 this.train_wait_turning = true;
39 stopsoundto(MSG_BROADCAST, this, CH_TRIGGER_SINGLE); // send this as unreliable only, as the train will resume operation shortly anyway
43 entity tg = find(NULL, targetname, this.target);
47 SUB_THINK(this, func_null);
48 this.SUB_NEXTTHINK = 0;
52 if(this.wait < 0 || this.train_wait_turning) // no waiting or we already waited while turning
54 this.train_wait_turning = false;
59 SUB_THINK(this, train_next);
60 this.SUB_NEXTTHINK = this.SUB_LTIME + this.wait;
64 void train_next(entity this)
66 entity targ, cp = NULL;
67 vector cp_org = '0 0 0';
69 targ = find(NULL, targetname, this.target);
70 this.target = targ.target;
71 if (this.spawnflags & 1)
75 cp = find(NULL, targetname, targ.curvetarget); // get its second target (the control point)
76 cp_org = cp.origin - this.view_ofs; // no control point found, assume a straight line to the destination
79 if (this.target == "")
80 objerror(this, "train_next: no next target");
81 this.wait = targ.wait;
87 // this path_corner contains a movetype overrider, apply it
88 this.platmovetype_start = targ.platmovetype_start;
89 this.platmovetype_end = targ.platmovetype_end;
93 // this path_corner doesn't contain a movetype overrider, use the train's defaults
94 this.platmovetype_start = this.platmovetype_start_default;
95 this.platmovetype_end = this.platmovetype_end_default;
101 SUB_CalcMove_Bezier(this, cp_org, targ.origin - this.view_ofs, TSPEED_LINEAR, targ.speed, train_wait);
103 SUB_CalcMove(this, targ.origin - this.view_ofs, TSPEED_LINEAR, targ.speed, train_wait);
108 SUB_CalcMove_Bezier(this, cp_org, targ.origin - this.view_ofs, TSPEED_LINEAR, this.speed, train_wait);
110 SUB_CalcMove(this, targ.origin - this.view_ofs, TSPEED_LINEAR, this.speed, train_wait);
114 _sound(this, CH_TRIGGER_SINGLE, this.noise, VOL_BASE, ATTEN_IDLE);
117 REGISTER_NET_LINKED(ENT_CLIENT_TRAIN)
120 float train_send(entity this, entity to, float sf)
122 WriteHeader(MSG_ENTITY, ENT_CLIENT_TRAIN);
123 WriteByte(MSG_ENTITY, sf);
125 if(sf & SF_TRIGGER_INIT)
127 WriteString(MSG_ENTITY, this.platmovetype);
128 WriteByte(MSG_ENTITY, this.platmovetype_turn);
129 WriteByte(MSG_ENTITY, this.spawnflags);
131 WriteString(MSG_ENTITY, this.model);
133 trigger_common_write(this, true);
135 WriteString(MSG_ENTITY, this.curvetarget);
137 WriteCoord(MSG_ENTITY, this.pos1_x);
138 WriteCoord(MSG_ENTITY, this.pos1_y);
139 WriteCoord(MSG_ENTITY, this.pos1_z);
140 WriteCoord(MSG_ENTITY, this.pos2_x);
141 WriteCoord(MSG_ENTITY, this.pos2_y);
142 WriteCoord(MSG_ENTITY, this.pos2_z);
144 WriteCoord(MSG_ENTITY, this.size_x);
145 WriteCoord(MSG_ENTITY, this.size_y);
146 WriteCoord(MSG_ENTITY, this.size_z);
148 WriteCoord(MSG_ENTITY, this.view_ofs_x);
149 WriteCoord(MSG_ENTITY, this.view_ofs_y);
150 WriteCoord(MSG_ENTITY, this.view_ofs_z);
152 WriteAngle(MSG_ENTITY, this.mangle_x);
153 WriteAngle(MSG_ENTITY, this.mangle_y);
154 WriteAngle(MSG_ENTITY, this.mangle_z);
156 WriteShort(MSG_ENTITY, this.speed);
157 WriteShort(MSG_ENTITY, this.height);
158 WriteByte(MSG_ENTITY, this.lip);
159 WriteByte(MSG_ENTITY, this.state);
160 WriteByte(MSG_ENTITY, this.wait);
162 WriteShort(MSG_ENTITY, this.dmg);
163 WriteByte(MSG_ENTITY, this.dmgtime);
166 if(sf & SF_TRIGGER_RESET)
174 void train_link(entity this)
176 //Net_LinkEntity(this, 0, false, train_send);
179 void train_use(entity this, entity actor, entity trigger)
181 this.SUB_NEXTTHINK = this.SUB_LTIME + 1;
182 SUB_THINK(this, train_next);
183 this.use = func_null; // not again
186 void func_train_find(entity this)
189 targ = find(NULL, targetname, this.target);
190 this.target = targ.target;
191 if (this.target == "")
192 objerror(this, "func_train_find: no next target");
193 SUB_SETORIGIN(this, targ.origin - this.view_ofs);
195 if(!(this.spawnflags & 4))
197 this.SUB_NEXTTHINK = this.SUB_LTIME + 1;
198 SUB_THINK(this, train_next);
206 /*QUAKED spawnfunc_func_train (0 .5 .8) ?
207 Ridable platform, targets spawnfunc_path_corner path to follow.
208 speed : speed the train moves (can be overridden by each spawnfunc_path_corner)
209 target : targetname of first spawnfunc_path_corner (starts here)
212 spawnfunc(func_train)
214 if (this.noise != "")
215 precache_sound(this.noise);
217 if (this.target == "")
218 objerror(this, "func_train without a target");
222 if (!InitMovingBrushTrigger(this))
224 this.effects |= EF_LOWPRECISION;
226 if(this.spawnflags & 4)
227 this.use = train_use;
229 if (this.spawnflags & 2)
231 this.platmovetype_turn = true;
232 this.view_ofs = '0 0 0'; // don't offset a rotating train, origin works differently now
235 this.view_ofs = this.mins;
237 // wait for targets to spawn
238 InitializeEntity(this, func_train_find, INITPRIO_FINDTARGET);
240 setblocked(this, generic_plat_blocked);
241 if(this.dmg && (this.message == ""))
242 this.message = " was squished";
243 if(this.dmg && (this.message2 == ""))
244 this.message2 = "was squished by";
245 if(this.dmg && (!this.dmgtime))
247 this.dmgtime2 = time;
249 if(!set_platmovetype(this, this.platmovetype))
251 this.platmovetype_start_default = this.platmovetype_start;
252 this.platmovetype_end_default = this.platmovetype_end;
254 // TODO make a reset function for this one
257 void train_draw(entity this)
259 //Movetype_Physics_NoMatchServer();
260 Movetype_Physics_MatchServer(this, autocvar_cl_projectiles_sloppy);
263 NET_HANDLE(ENT_CLIENT_TRAIN, bool isnew)
265 float sf = ReadByte();
267 if(sf & SF_TRIGGER_INIT)
269 this.platmovetype = strzone(ReadString());
270 this.platmovetype_turn = ReadByte();
271 this.spawnflags = ReadByte();
273 this.model = strzone(ReadString());
274 _setmodel(this, this.model);
276 trigger_common_read(this, true);
278 this.curvetarget = strzone(ReadString());
280 this.pos1_x = ReadCoord();
281 this.pos1_y = ReadCoord();
282 this.pos1_z = ReadCoord();
283 this.pos2_x = ReadCoord();
284 this.pos2_y = ReadCoord();
285 this.pos2_z = ReadCoord();
287 this.size_x = ReadCoord();
288 this.size_y = ReadCoord();
289 this.size_z = ReadCoord();
291 this.view_ofs_x = ReadCoord();
292 this.view_ofs_y = ReadCoord();
293 this.view_ofs_z = ReadCoord();
295 this.mangle_x = ReadAngle();
296 this.mangle_y = ReadAngle();
297 this.mangle_z = ReadAngle();
299 this.speed = ReadShort();
300 this.height = ReadShort();
301 this.lip = ReadByte();
302 this.state = ReadByte();
303 this.wait = ReadByte();
305 this.dmg = ReadShort();
306 this.dmgtime = ReadByte();
308 this.classname = "func_train";
309 this.solid = SOLID_BSP;
310 this.move_movetype = MOVETYPE_PUSH;
311 this.drawmask = MASK_NORMAL;
312 this.draw = train_draw;
313 this.entremove = trigger_remove_generic;
315 if(set_platmovetype(this, this.platmovetype))
317 this.platmovetype_start_default = this.platmovetype_start;
318 this.platmovetype_end_default = this.platmovetype_end;
321 // everything is set up by the time the train is linked, we shouldn't need this
324 // but we will need these
327 this.move_movetype = MOVETYPE_PUSH;
328 this.move_time = time;
331 if(sf & SF_TRIGGER_RESET)
333 // TODO: make a reset function for trains