]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/triggers/func/train.qc
Make things slightly less broken
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / triggers / func / train.qc
1 #ifdef SVQC
2 .float train_wait_turning;
3 void() train_next;
4 void train_wait()
5 {
6         entity oldself;
7         oldself = self;
8         self = self.enemy;
9         SUB_UseTargets();
10         self = oldself;
11         self.enemy = world;
12
13         // if turning is enabled, the train will turn toward the next point while waiting
14         if(self.platmovetype_turn && !self.train_wait_turning)
15         {
16                 entity targ, cp;
17                 vector ang;
18                 targ = find(world, targetname, self.target);
19                 if((self.spawnflags & 1) && targ.curvetarget)
20                         cp = find(world, targetname, targ.curvetarget);
21                 else
22                         cp = world;
23
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
30
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;
36                 return;
37         }
38
39         if(self.noise != "")
40                 stopsoundto(MSG_BROADCAST, self, CH_TRIGGER_SINGLE); // send this as unreliable only, as the train will resume operation shortly anyway
41
42         if(self.wait < 0 || self.train_wait_turning) // no waiting or we already waited while turning
43         {
44                 self.train_wait_turning = false;
45                 train_next();
46         }
47         else
48         {
49                 self.think = train_next;
50                 trigger_setnextthink(self, self.ltime + self.wait);
51         }
52 }
53
54 void train_next()
55 {
56         entity targ, cp = world;
57         vector cp_org = '0 0 0';
58
59         targ = find(world, targetname, self.target);
60         self.target = targ.target;
61         if (self.spawnflags & 1)
62         {
63                 if(targ.curvetarget)
64                 {
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
67                 }
68         }
69         if (self.target == "")
70                 objerror("train_next: no next target");
71         self.wait = targ.wait;
72         if (!self.wait)
73                 self.wait = 0.1;
74
75         if(targ.platmovetype)
76         {
77                 // this path_corner contains a movetype overrider, apply it
78                 self.platmovetype_start = targ.platmovetype_start;
79                 self.platmovetype_end = targ.platmovetype_end;
80         }
81         else
82         {
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;
86         }
87
88         if (targ.speed)
89         {
90                 if (cp)
91                         SUB_CalcMove_Bezier(cp_org, targ.origin - self.view_ofs, TSPEED_LINEAR, targ.speed, train_wait);
92                 else
93                         SUB_CalcMove(targ.origin - self.view_ofs, TSPEED_LINEAR, targ.speed, train_wait);
94         }
95         else
96         {
97                 if (cp)
98                         SUB_CalcMove_Bezier(cp_org, targ.origin - self.view_ofs, TSPEED_LINEAR, self.speed, train_wait);
99                 else
100                         SUB_CalcMove(targ.origin - self.view_ofs, TSPEED_LINEAR, self.speed, train_wait);
101         }
102
103         if(self.noise != "")
104                 sound(self, CH_TRIGGER_SINGLE, self.noise, VOL_BASE, ATTEN_IDLE);
105 }
106
107 void func_train_find()
108 {
109         entity targ;
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         trigger_setnextthink(self, self.ltime + 1);
116         self.think = train_next;
117 }
118
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)
123 */
124 void spawnfunc_func_train()
125 {
126         if (self.noise != "")
127                 precache_sound(self.noise);
128
129         if (self.target == "")
130                 objerror("func_train without a target");
131         if (!self.speed)
132                 self.speed = 100;
133
134         if (!InitMovingBrushTrigger())
135                 return;
136         self.effects |= EF_LOWPRECISION;
137         
138         if (self.spawnflags & 2)
139         {
140                 self.platmovetype_turn = true;
141                 self.view_ofs = '0 0 0'; // don't offset a rotating train, origin works differently now
142         }
143         else
144                 self.view_ofs = self.mins;
145
146         // wait for targets to spawn
147         InitializeEntity(self, func_train_find, INITPRIO_SETLOCATION);
148
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))
155                 self.dmgtime = 0.25;
156         self.dmgtime2 = time;
157
158         if(!set_platmovetype(self, self.platmovetype))
159                 return;
160         self.platmovetype_start_default = self.platmovetype_start;
161         self.platmovetype_end_default = self.platmovetype_end;
162
163         // TODO make a reset function for this one
164 }
165 #endif