]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/triggers/func/train.qc
Remove a comment that is no longer true
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / triggers / func / train.qc
1 #include "train.qh"
2 .float train_wait_turning;
3 void train_next(entity this);
4 #ifdef SVQC
5 void train_use(entity this, entity actor, entity trigger);
6 #endif
7 void train_wait(entity this)
8 {
9         SUB_UseTargets(this.enemy, NULL, NULL);
10         this.enemy = NULL;
11
12         // if turning is enabled, the train will turn toward the next point while waiting
13         if(this.platmovetype_turn && !this.train_wait_turning)
14         {
15                 entity targ, cp;
16                 vector ang;
17                 targ = find(NULL, targetname, this.target);
18                 if((this.spawnflags & 1) && targ.curvetarget)
19                         cp = find(NULL, targetname, targ.curvetarget);
20                 else
21                         cp = NULL;
22
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
29
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;
35                 return;
36         }
37
38 #ifdef SVQC
39         if(this.noise != "")
40                 stopsoundto(MSG_BROADCAST, this, CH_TRIGGER_SINGLE); // send this as unreliable only, as the train will resume operation shortly anyway
41 #endif
42
43 #ifdef SVQC
44         entity tg = find(NULL, targetname, this.target);
45         if(tg.spawnflags & 4)
46         {
47                 this.use = train_use;
48                 SUB_THINK(this, func_null);
49                 this.SUB_NEXTTHINK = 0;
50         }
51         else
52 #endif
53              if(this.wait < 0 || this.train_wait_turning) // no waiting or we already waited while turning
54         {
55                 this.train_wait_turning = false;
56                 train_next(this);
57         }
58         else
59         {
60                 SUB_THINK(this, train_next);
61                 this.SUB_NEXTTHINK = this.SUB_LTIME + this.wait;
62         }
63 }
64
65 void train_next(entity this)
66 {
67         entity targ, cp = NULL;
68         vector cp_org = '0 0 0';
69
70         targ = find(NULL, targetname, this.target);
71         this.target = targ.target;
72         if (this.spawnflags & 1)
73         {
74                 if(targ.curvetarget)
75                 {
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
78                 }
79         }
80         if (this.target == "")
81                 objerror(this, "train_next: no next target");
82         this.wait = targ.wait;
83         if (!this.wait)
84                 this.wait = 0.1;
85
86         if(targ.platmovetype)
87         {
88                 // this path_corner contains a movetype overrider, apply it
89                 this.platmovetype_start = targ.platmovetype_start;
90                 this.platmovetype_end = targ.platmovetype_end;
91         }
92         else
93         {
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;
97         }
98
99         if (targ.speed)
100         {
101                 if (cp)
102                         SUB_CalcMove_Bezier(this, cp_org, targ.origin - this.view_ofs, TSPEED_LINEAR, targ.speed, train_wait);
103                 else
104                         SUB_CalcMove(this, targ.origin - this.view_ofs, TSPEED_LINEAR, targ.speed, train_wait);
105         }
106         else
107         {
108                 if (cp)
109                         SUB_CalcMove_Bezier(this, cp_org, targ.origin - this.view_ofs, TSPEED_LINEAR, this.speed, train_wait);
110                 else
111                         SUB_CalcMove(this, targ.origin - this.view_ofs, TSPEED_LINEAR, this.speed, train_wait);
112         }
113
114         if(this.noise != "")
115                 _sound(this, CH_TRIGGER_SINGLE, this.noise, VOL_BASE, ATTEN_IDLE);
116 }
117
118 REGISTER_NET_LINKED(ENT_CLIENT_TRAIN)
119
120 #ifdef SVQC
121 float train_send(entity this, entity to, float sf)
122 {
123         WriteHeader(MSG_ENTITY, ENT_CLIENT_TRAIN);
124         WriteByte(MSG_ENTITY, sf);
125
126         if(sf & SF_TRIGGER_INIT)
127         {
128                 WriteString(MSG_ENTITY, this.platmovetype);
129                 WriteByte(MSG_ENTITY, this.platmovetype_turn);
130                 WriteByte(MSG_ENTITY, this.spawnflags);
131
132                 WriteString(MSG_ENTITY, this.model);
133
134                 trigger_common_write(this, true);
135
136                 WriteString(MSG_ENTITY, this.curvetarget);
137
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);
144
145                 WriteCoord(MSG_ENTITY, this.size_x);
146                 WriteCoord(MSG_ENTITY, this.size_y);
147                 WriteCoord(MSG_ENTITY, this.size_z);
148
149                 WriteCoord(MSG_ENTITY, this.view_ofs_x);
150                 WriteCoord(MSG_ENTITY, this.view_ofs_y);
151                 WriteCoord(MSG_ENTITY, this.view_ofs_z);
152
153                 WriteAngle(MSG_ENTITY, this.mangle_x);
154                 WriteAngle(MSG_ENTITY, this.mangle_y);
155                 WriteAngle(MSG_ENTITY, this.mangle_z);
156
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);
162
163                 WriteShort(MSG_ENTITY, this.dmg);
164                 WriteByte(MSG_ENTITY, this.dmgtime);
165         }
166
167         if(sf & SF_TRIGGER_RESET)
168         {
169                 // used on client
170         }
171
172         return true;
173 }
174
175 void train_link(entity this)
176 {
177         //Net_LinkEntity(this, 0, false, train_send);
178 }
179
180 void train_use(entity this, entity actor, entity trigger)
181 {
182         this.SUB_NEXTTHINK = this.SUB_LTIME + 1;
183         SUB_THINK(this, train_next);
184         this.use = func_null; // not again
185 }
186
187 void func_train_find(entity this)
188 {
189         entity targ;
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);
195
196         if(!(this.spawnflags & 4))
197         {
198                 this.SUB_NEXTTHINK = this.SUB_LTIME + 1;
199                 SUB_THINK(this, train_next);
200         }
201
202         train_link(this);
203 }
204
205 #endif
206
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)
211 */
212 #ifdef SVQC
213 spawnfunc(func_train)
214 {
215         if (this.noise != "")
216                 precache_sound(this.noise);
217
218         if (this.target == "")
219                 objerror(this, "func_train without a target");
220         if (!this.speed)
221                 this.speed = 100;
222
223         if (!InitMovingBrushTrigger(this))
224                 return;
225         this.effects |= EF_LOWPRECISION;
226
227         if(this.spawnflags & 4)
228                 this.use = train_use;
229
230         if (this.spawnflags & 2)
231         {
232                 this.platmovetype_turn = true;
233                 this.view_ofs = '0 0 0'; // don't offset a rotating train, origin works differently now
234         }
235         else
236                 this.view_ofs = this.mins;
237
238         // wait for targets to spawn
239         InitializeEntity(this, func_train_find, INITPRIO_FINDTARGET);
240
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))
247                 this.dmgtime = 0.25;
248         this.dmgtime2 = time;
249
250         if(!set_platmovetype(this, this.platmovetype))
251                 return;
252         this.platmovetype_start_default = this.platmovetype_start;
253         this.platmovetype_end_default = this.platmovetype_end;
254
255         // TODO make a reset function for this one
256 }
257 #elif defined(CSQC)
258 void train_draw(entity this)
259 {
260         //Movetype_Physics_NoMatchServer();
261         Movetype_Physics_MatchServer(this, autocvar_cl_projectiles_sloppy);
262 }
263
264 NET_HANDLE(ENT_CLIENT_TRAIN, bool isnew)
265 {
266         float sf = ReadByte();
267
268         if(sf & SF_TRIGGER_INIT)
269         {
270                 this.platmovetype = strzone(ReadString());
271                 this.platmovetype_turn = ReadByte();
272                 this.spawnflags = ReadByte();
273
274                 this.model = strzone(ReadString());
275                 _setmodel(this, this.model);
276
277                 trigger_common_read(this, true);
278
279                 this.curvetarget = strzone(ReadString());
280
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();
287
288                 this.size_x = ReadCoord();
289                 this.size_y = ReadCoord();
290                 this.size_z = ReadCoord();
291
292                 this.view_ofs_x = ReadCoord();
293                 this.view_ofs_y = ReadCoord();
294                 this.view_ofs_z = ReadCoord();
295
296                 this.mangle_x = ReadAngle();
297                 this.mangle_y = ReadAngle();
298                 this.mangle_z = ReadAngle();
299
300                 this.speed = ReadShort();
301                 this.height = ReadShort();
302                 this.lip = ReadByte();
303                 this.state = ReadByte();
304                 this.wait = ReadByte();
305
306                 this.dmg = ReadShort();
307                 this.dmgtime = ReadByte();
308
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;
316
317                 if(set_platmovetype(this, this.platmovetype))
318                 {
319                         this.platmovetype_start_default = this.platmovetype_start;
320                         this.platmovetype_end_default = this.platmovetype_end;
321                 }
322
323                 // everything is set up by the time the train is linked, we shouldn't need this
324                 //func_train_find();
325
326                 // but we will need these
327                 train_next(this);
328
329                 set_movetype(this, MOVETYPE_PUSH);
330                 this.move_time = time;
331         }
332
333         if(sf & SF_TRIGGER_RESET)
334         {
335                 // TODO: make a reset function for trains
336         }
337
338         return true;
339 }
340
341 #endif