2 .float train_wait_turning;
13 // if turning is enabled, the train will turn toward the next point while waiting
14 if(self.platmovetype_turn && !self.train_wait_turning)
18 targ = find(world, targetname, self.target);
19 if((self.spawnflags & 1) && targ.curvetarget)
20 cp = find(world, targetname, targ.curvetarget);
24 if(cp) // bezier curves movement
25 ang = cp.origin - (self.origin - self.view_ofs); // use the origin of the control point of the next path_corner
26 else // linear movement
27 ang = targ.origin - (self.origin - self.view_ofs); // use the origin of the next path_corner
28 ang = vectoangles(ang);
29 ang_x = -ang_x; // flip up / down orientation
31 if(self.wait > 0) // slow turning
32 SUB_CalcAngleMove(ang, TSPEED_TIME, self.ltime - time + self.wait, train_wait);
33 else // instant turning
34 SUB_CalcAngleMove(ang, TSPEED_TIME, 0.0000001, train_wait);
35 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
42 if(self.wait < 0 || self.train_wait_turning) // no waiting or we already waited while turning
44 self.train_wait_turning = FALSE;
49 self.think = train_next;
50 self.nextthink = self.ltime + self.wait;
56 entity targ, cp = world;
57 vector cp_org = '0 0 0';
59 targ = find(world, targetname, self.target);
60 self.target = targ.target;
61 if (self.spawnflags & 1)
65 cp = find(world, targetname, targ.curvetarget); // get its second target (the control point)
66 cp_org = cp.origin - self.view_ofs; // no control point found, assume a straight line to the destination
69 if (self.target == "")
70 objerror("train_next: no next target");
71 self.wait = targ.wait;
77 // this path_corner contains a movetype overrider, apply it
78 self.platmovetype_start = targ.platmovetype_start;
79 self.platmovetype_end = targ.platmovetype_end;
83 // this path_corner doesn't contain a movetype overrider, use the train's defaults
84 self.platmovetype_start = self.platmovetype_start_default;
85 self.platmovetype_end = self.platmovetype_end_default;
91 SUB_CalcMove_Bezier(cp_org, targ.origin - self.view_ofs, TSPEED_LINEAR, targ.speed, train_wait);
93 SUB_CalcMove(targ.origin - self.view_ofs, TSPEED_LINEAR, targ.speed, train_wait);
98 SUB_CalcMove_Bezier(cp_org, targ.origin - self.view_ofs, TSPEED_LINEAR, self.speed, train_wait);
100 SUB_CalcMove(targ.origin - self.view_ofs, TSPEED_LINEAR, self.speed, train_wait);
104 sound(self, CH_TRIGGER_SINGLE, self.noise, VOL_BASE, ATTEN_IDLE);
107 void func_train_find()
110 targ = find(world, targetname, self.target);
111 self.target = targ.target;
112 if (self.target == "")
113 objerror("func_train_find: no next target");
114 setorigin(self, targ.origin - self.view_ofs);
115 self.nextthink = self.ltime + 1;
116 self.think = train_next;
119 /*QUAKED spawnfunc_func_train (0 .5 .8) ?
120 Ridable platform, targets spawnfunc_path_corner path to follow.
121 speed : speed the train moves (can be overridden by each spawnfunc_path_corner)
122 target : targetname of first spawnfunc_path_corner (starts here)
124 void spawnfunc_func_train()
126 if (self.noise != "")
127 precache_sound(self.noise);
129 if (self.target == "")
130 objerror("func_train without a target");
134 if (!InitMovingBrushTrigger())
136 self.effects |= EF_LOWPRECISION;
138 if (self.spawnflags & 2)
140 self.platmovetype_turn = TRUE;
141 self.view_ofs = '0 0 0'; // don't offset a rotating train, origin works differently now
144 self.view_ofs = self.mins;
146 // wait for targets to spawn
147 InitializeEntity(self, func_train_find, INITPRIO_SETLOCATION);
149 self.blocked = generic_plat_blocked;
150 if(self.dmg && (self.message == ""))
151 self.message = " was squished";
152 if(self.dmg && (self.message2 == ""))
153 self.message2 = "was squished by";
154 if(self.dmg && (!self.dmgtime))
156 self.dmgtime2 = time;
158 if(!set_platmovetype(self, self.platmovetype))
160 self.platmovetype_start_default = self.platmovetype_start;
161 self.platmovetype_end_default = self.platmovetype_end;
163 // TODO make a reset function for this one