]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/g_subs.qc
Merge branch 'morphed/hpitems' of ssh://git.xonotic.org/xonotic-data.pk3dir into...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / g_subs.qc
1 void SUB_Null() {};
2 float SUB_True() { return 1; }
3 float SUB_False() { return 0; }
4
5 void(vector destangle, float tspeed, void() func) SUB_CalcAngleMove;
6 void()  SUB_CalcMoveDone;
7 void() SUB_CalcAngleMoveDone;
8 //void() SUB_UseTargets;
9 void() SUB_Remove;
10
11 void spawnfunc_info_null (void)
12 {
13         remove(self);
14         // if anything breaks, tell the mapper to fix his map! info_null is meant to remove itself immediately.
15 }
16
17 void setanim(entity e, vector anim, float looping, float override, float restart)
18 {
19         if (anim_x == e.animstate_startframe)
20         if (anim_y == e.animstate_numframes)
21         if (anim_z == e.animstate_framerate)
22         {
23                 if(restart)
24                 {
25                         if(restart > 0)
26                         if(anim_y == 1) // ZYM animation
27                                 BITXOR_ASSIGN(e.effects, EF_RESTARTANIM_BIT);
28                 }
29                 else
30                         return;
31         }
32         e.animstate_startframe = anim_x;
33         e.animstate_numframes = anim_y;
34         e.animstate_framerate = anim_z;
35         e.animstate_starttime = servertime - 0.1 * serverframetime; // shift it a little bit into the past to prevent float inaccuracy hiccups
36         e.animstate_endtime = e.animstate_starttime + e.animstate_numframes / e.animstate_framerate;
37         e.animstate_looping = looping;
38         e.animstate_override = override;
39         e.frame = e.animstate_startframe;
40         e.frame1time = servertime;
41 };
42
43 void updateanim(entity e)
44 {
45         if (time >= e.animstate_endtime)
46         {
47                 if (e.animstate_looping)
48                 {
49                         e.animstate_starttime = e.animstate_endtime;
50                         e.animstate_endtime = e.animstate_starttime + e.animstate_numframes / e.animstate_framerate;
51                 }
52                 e.animstate_override = FALSE;
53         }
54         e.frame = e.animstate_startframe + bound(0, (time - e.animstate_starttime) * e.animstate_framerate, e.animstate_numframes - 1);
55         //print(ftos(time), " -> ", ftos(e.frame), "\n");
56 };
57
58 float animparseerror;
59 vector animparseline(float animfile)
60 {
61         local string line;
62         local float c;
63         local vector anim;
64         if (animfile < 0)
65                 return '0 1 2';
66         line = fgets(animfile);
67         c = tokenize_console(line);
68         if (c < 3)
69         {
70                 animparseerror = TRUE;
71                 return '0 1 2';
72         }
73         anim_x = stof(argv(0));
74         anim_y = stof(argv(1));
75         anim_z = stof(argv(2));
76         // don't allow completely bogus values
77         if (anim_x < 0 || anim_y < 1 || anim_z < 0.001)
78                 anim = '0 1 2';
79         return anim;
80 };
81
82 /*
83 ==================
84 SUB_Remove
85
86 Remove self
87 ==================
88 */
89 void SUB_Remove (void)
90 {
91         remove (self);
92 }
93
94 /*
95 ==================
96 SUB_Friction
97
98 Applies some friction to self
99 ==================
100 */
101 .float friction;
102 void SUB_Friction (void)
103 {
104         self.nextthink = time;
105         if(self.flags & FL_ONGROUND)
106                 self.velocity = self.velocity * (1 - frametime * self.friction);
107 }
108
109 /*
110 ==================
111 SUB_VanishOrRemove
112
113 Makes client invisible or removes non-client
114 ==================
115 */
116 void SUB_VanishOrRemove (entity ent)
117 {
118         if (ent.flags & FL_CLIENT)
119         {
120                 // vanish
121                 ent.model = "";
122                 ent.effects = 0;
123                 ent.glow_size = 0;
124                 ent.pflags = 0;
125         }
126         else
127         {
128                 // remove
129                 remove (ent);
130         }
131 }
132
133 void SUB_SetFade_Think (void)
134 {
135         self.think = SUB_SetFade_Think;
136         self.nextthink = self.fade_time;
137         self.alpha = 1 - (time - self.fade_time) * self.fade_rate;
138         if (self.alpha < 0.01)
139                 SUB_VanishOrRemove(self);
140         self.alpha = bound(0.01, self.alpha, 1);
141 }
142
143 /*
144 ==================
145 SUB_SetFade
146
147 Fade 'ent' out when time >= 'when'
148 ==================
149 */
150 void SUB_SetFade (entity ent, float when, float fadetime)
151 {
152         //if (ent.flags & FL_CLIENT) // && ent.deadflag != DEAD_NO)
153         //      return;
154         //ent.alpha = 1;
155         ent.fade_rate = 1/fadetime;
156         ent.fade_time = when;
157         ent.think = SUB_SetFade_Think;
158         ent.nextthink = when;
159 }
160
161 /*
162 =============
163 SUB_CalcMove
164
165 calculate self.velocity and self.nextthink to reach dest from
166 self.origin traveling at speed
167 ===============
168 */
169 void SUB_CalcMoveDone (void)
170 {
171         // After moving, set origin to exact final destination
172
173         setorigin (self, self.finaldest);
174         self.velocity = '0 0 0';
175         self.nextthink = -1;
176         if (self.think1)
177                 self.think1 ();
178 }
179
180 void SUB_CalcMove_controller_think (void)
181 {
182         entity oldself;
183         float traveltime;
184         float phasepos;
185         float nexttick;
186         vector delta;
187         vector veloc;
188         vector nextpos;
189         if(time < self.animstate_endtime) {
190                 delta = self.destvec;
191                 nexttick = time + sys_frametime;
192
193                 if(nexttick < self.animstate_endtime) {
194                         traveltime = self.animstate_endtime - self.animstate_starttime;
195                         phasepos = (nexttick - self.animstate_starttime) / traveltime; // range: [0, 1]
196                         phasepos = 3.14159265 + (phasepos * 3.14159265); // range: [pi, 2pi]
197                         phasepos = cos(phasepos); // cos [pi, 2pi] is in [-1, 1]
198                         phasepos = phasepos + 1; // correct range to [0, 2]
199                         phasepos = phasepos / 2; // correct range to [0, 1]
200                         nextpos = self.origin + (delta * phasepos);
201
202                         veloc = nextpos - self.owner.origin;
203                         veloc = veloc * (1 / sys_frametime); // so it arrives for the next frame
204
205                 } else {
206                         veloc = self.finaldest - self.owner.origin;
207                         veloc = veloc * (1 / sys_frametime); // so it arrives for the next frame
208                 }
209                 self.owner.velocity = veloc;
210                 self.nextthink = nexttick;
211         } else {
212                 oldself = self;
213                 self.owner.think = self.think1;
214                 self = self.owner;
215                 remove(oldself);
216                 self.think();
217         }
218 }
219
220 void SUB_CalcMove (vector tdest, float tspeed, void() func)
221 {
222         vector  delta;
223         float   traveltime;
224         entity controller;
225
226         if (!tspeed)
227                 objerror ("No speed is defined!");
228
229         self.think1 = func;
230         self.finaldest = tdest;
231         self.think = SUB_CalcMoveDone;
232
233         if (tdest == self.origin)
234         {
235                 self.velocity = '0 0 0';
236                 self.nextthink = self.ltime + 0.1;
237                 return;
238         }
239
240         delta = tdest - self.origin;
241         traveltime = vlen (delta) / tspeed;
242
243         if (traveltime < 0.1)
244         {
245                 self.velocity = '0 0 0';
246                 self.nextthink = self.ltime + 0.1;
247                 return;
248         }
249
250         // Very short animations don't really show off the effect
251         // of controlled animation, so let's just use linear movement.
252         // Alternatively entities can choose to specify non-controlled movement.
253         // The only currently implemented alternative movement is linear (value 1)
254         if (traveltime < 0.15 || self.platmovetype == 1)
255         {
256                 self.velocity = delta * (1/traveltime); // QuakeC doesn't allow vector/float division
257                 self.nextthink = self.ltime + traveltime;
258                 return;
259         }
260
261         controller = spawn();
262         controller.classname = "SUB_CalcMove_controller";
263         controller.owner = self;
264         controller.origin = self.origin; // starting point
265         controller.finaldest = (tdest + '0 0 0.125'); // where do we want to end? Offset to overshoot a bit.
266         controller.destvec = delta;
267         controller.animstate_starttime = time;
268         controller.animstate_endtime = time + traveltime;
269         controller.think = SUB_CalcMove_controller_think;
270         controller.think1 = self.think;
271
272         // the thinking is now done by the controller
273         self.think = SUB_Null;
274         self.nextthink = self.ltime + traveltime;
275         
276         // invoke controller
277         self = controller;
278         self.think();
279         self = self.owner;
280 }
281
282 void SUB_CalcMoveEnt (entity ent, vector tdest, float tspeed, void() func)
283 {
284         entity  oldself;
285
286         oldself = self;
287         self = ent;
288
289         SUB_CalcMove (tdest, tspeed, func);
290
291         self = oldself;
292 }
293
294 /*
295 =============
296 SUB_CalcAngleMove
297
298 calculate self.avelocity and self.nextthink to reach destangle from
299 self.angles rotating
300
301 The calling function should make sure self.think is valid
302 ===============
303 */
304 void SUB_CalcAngleMoveDone (void)
305 {
306         // After rotating, set angle to exact final angle
307         self.angles = self.finalangle;
308         self.avelocity = '0 0 0';
309         self.nextthink = -1;
310         if (self.think1)
311                 self.think1 ();
312 }
313
314 // FIXME: I fixed this function only for rotation around the main axes
315 void SUB_CalcAngleMove (vector destangle, float tspeed, void() func)
316 {
317         vector  delta;
318         float   traveltime;
319
320         if (!tspeed)
321                 objerror ("No speed is defined!");
322
323         // take the shortest distance for the angles
324         self.angles_x -= 360 * floor((self.angles_x - destangle_x) / 360 + 0.5);
325         self.angles_y -= 360 * floor((self.angles_y - destangle_y) / 360 + 0.5);
326         self.angles_z -= 360 * floor((self.angles_z - destangle_z) / 360 + 0.5);
327         delta = destangle - self.angles;
328         traveltime = vlen (delta) / tspeed;
329
330         self.think1 = func;
331         self.finalangle = destangle;
332         self.think = SUB_CalcAngleMoveDone;
333
334         if (traveltime < 0.1)
335         {
336                 self.avelocity = '0 0 0';
337                 self.nextthink = self.ltime + 0.1;
338                 return;
339         }
340
341         self.avelocity = delta * (1 / traveltime);
342         self.nextthink = self.ltime + traveltime;
343 }
344
345 void SUB_CalcAngleMoveEnt (entity ent, vector destangle, float tspeed, void() func)
346 {
347         entity  oldself;
348
349         oldself = self;
350         self = ent;
351
352         SUB_CalcAngleMove (destangle, tspeed, func);
353
354         self = oldself;
355 }
356
357 /*
358 ==================
359 main
360
361 unused but required by the engine
362 ==================
363 */
364 void main (void)
365 {
366
367 }
368
369 // Misc
370
371 /*
372 ==================
373 traceline_antilag
374
375 A version of traceline that must be used by SOLID_SLIDEBOX things that want to hit SOLID_CORPSE things with a trace attack
376 Additionally it moves players back into the past before the trace and restores them afterward.
377 ==================
378 */
379 void tracebox_antilag_force_wz (entity source, vector v1, vector mi, vector ma, vector v2, float nomonst, entity forent, float lag, float wz)
380 {
381         local entity player;
382         local float oldsolid;
383
384         // check whether antilagged traces are enabled
385         if (lag < 0.001)
386                 lag = 0;
387         if (clienttype(forent) != CLIENTTYPE_REAL)
388                 lag = 0; // only antilag for clients
389
390         // change shooter to SOLID_BBOX so the shot can hit corpses
391         if(source)
392         {
393                 oldsolid = source.dphitcontentsmask;
394                 source.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_CORPSE;
395         }
396
397         if (lag)
398         {
399                 // take players back into the past
400                 player = player_list;
401                 while (player)
402                 {
403                         antilag_takeback(player, time - lag);
404                         player = player.nextplayer;
405                 }
406         }
407
408         // do the trace
409         if(wz)
410                 WarpZone_TraceBox (v1, mi, ma, v2, nomonst, forent);
411         else
412                 tracebox (v1, mi, ma, v2, nomonst, forent);
413
414         // restore players to current positions
415         if (lag)
416         {
417                 player = player_list;
418                 while (player)
419                 {
420                         antilag_restore(player);
421                         player = player.nextplayer;
422                 }
423         }
424
425         // restore shooter solid type
426         if(source)
427                 source.dphitcontentsmask = oldsolid;
428 }
429 void traceline_antilag_force (entity source, vector v1, vector v2, float nomonst, entity forent, float lag)
430 {
431         tracebox_antilag_force_wz(source, v1, '0 0 0', '0 0 0', v2, nomonst, forent, lag, FALSE);
432 }
433 void traceline_antilag (entity source, vector v1, vector v2, float nomonst, entity forent, float lag)
434 {
435         if (autocvar_g_antilag != 2 || source.cvar_cl_noantilag)
436                 lag = 0;
437         traceline_antilag_force(source, v1, v2, nomonst, forent, lag);
438 }
439 void tracebox_antilag (entity source, vector v1, vector mi, vector ma, vector v2, float nomonst, entity forent, float lag)
440 {
441         if (autocvar_g_antilag != 2 || source.cvar_cl_noantilag)
442                 lag = 0;
443         tracebox_antilag_force_wz(source, v1, mi, ma, v2, nomonst, forent, lag, FALSE);
444 }
445 void WarpZone_traceline_antilag_force (entity source, vector v1, vector v2, float nomonst, entity forent, float lag)
446 {
447         tracebox_antilag_force_wz(source, v1, '0 0 0', '0 0 0', v2, nomonst, forent, lag, TRUE);
448 }
449 void WarpZone_traceline_antilag (entity source, vector v1, vector v2, float nomonst, entity forent, float lag)
450 {
451         if (autocvar_g_antilag != 2 || source.cvar_cl_noantilag)
452                 lag = 0;
453         WarpZone_traceline_antilag_force(source, v1, v2, nomonst, forent, lag);
454 }
455 void WarpZone_tracebox_antilag (entity source, vector v1, vector mi, vector ma, vector v2, float nomonst, entity forent, float lag)
456 {
457         if (autocvar_g_antilag != 2 || source.cvar_cl_noantilag)
458                 lag = 0;
459         tracebox_antilag_force_wz(source, v1, mi, ma, v2, nomonst, forent, lag, TRUE);
460 }
461
462 float tracebox_inverted (vector v1, vector mi, vector ma, vector v2, float nomonsters, entity forent) // returns the number of traces done, for benchmarking
463 {
464         vector pos, dir, t;
465         float nudge;
466
467         //nudge = 2 * cvar("collision_impactnudge"); // why not?
468         nudge = 0.5;
469
470         dir = normalize(v2 - v1);
471
472         pos = v1 + dir * nudge;
473
474         float c;
475         c = 0;
476
477         for(;;)
478         {
479                 if((pos - v1) * dir >= (v2 - v1) * dir)
480                 {
481                         // went too far
482                         trace_fraction = 1;
483                         trace_endpos = v2;
484                         return c;
485                 }
486
487                 tracebox(pos, mi, ma, v2, nomonsters, forent);
488                 ++c;
489
490                 if(c == 50)
491                 {
492                         dprint("HOLY SHIT! When tracing from ", vtos(v1), " to ", vtos(v2), "\n");
493                         dprint("  Nudging gets us nowhere at ", vtos(pos), "\n");
494                         dprint("  trace_endpos is ", vtos(trace_endpos), "\n");
495                         dprint("  trace distance is ", ftos(vlen(pos - trace_endpos)), "\n");
496                 }
497
498                 if(trace_startsolid)
499                 {
500                         // we started inside solid.
501                         // then trace from endpos to pos
502                         t = trace_endpos;
503                         tracebox(t, mi, ma, pos, nomonsters, forent);
504                         ++c;
505                         if(trace_startsolid)
506                         {
507                                 // t is still inside solid? bad
508                                 // force advance, then, and retry
509                                 pos = t + dir * nudge;
510                         }
511                         else
512                         {
513                                 // we actually LEFT solid!
514                                 trace_fraction = ((trace_endpos - v1) * dir) / ((v2 - v1) * dir);
515                                 return c;
516                         }
517                 }
518                 else
519                 {
520                         // pos is outside solid?!? but why?!? never mind, just return it.
521                         trace_endpos = pos;
522                         trace_fraction = ((trace_endpos - v1) * dir) / ((v2 - v1) * dir);
523                         return c;
524                 }
525         }
526 }
527
528 void traceline_inverted (vector v1, vector v2, float nomonsters, entity forent)
529 {
530 #if 0
531         vector pos, dir, t;
532         float nudge;
533
534         //nudge = 2 * cvar("collision_impactnudge"); // why not?
535         nudge = 0.5;
536
537         dir = normalize(v2 - v1);
538
539         pos = v1 + dir * nudge;
540
541         for(;;)
542         {
543                 if((pos - v1) * dir >= (v2 - v1) * dir)
544                 {
545                         // went too far
546                         trace_fraction = 1;
547                         return;
548                 }
549
550                 traceline(pos, v2, nomonsters, forent);
551
552                 if(trace_startsolid)
553                 {
554                         // we started inside solid.
555                         // then trace from endpos to pos
556                         t = trace_endpos;
557                         traceline(t, pos, nomonsters, forent);
558                         if(trace_startsolid)
559                         {
560                                 // t is inside solid? bad
561                                 // force advance, then
562                                 pos = pos + dir * nudge;
563                         }
564                         else
565                         {
566                                 // we actually LEFT solid!
567                                 trace_fraction = ((trace_endpos - v1) * dir) / ((v2 - v1) * dir);
568                                 return;
569                         }
570                 }
571                 else
572                 {
573                         // pos is outside solid?!? but why?!? never mind, just return it.
574                         trace_endpos = pos;
575                         trace_fraction = ((trace_endpos - v1) * dir) / ((v2 - v1) * dir);
576                         return;
577                 }
578         }
579 #else
580         tracebox_inverted(v1, '0 0 0', '0 0 0', v2, nomonsters, forent);
581 }
582
583 /*
584 ==================
585 findbetterlocation
586
587 Returns a point at least 12 units away from walls
588 (useful for explosion animations, although the blast is performed where it really happened)
589 Ripped from DPMod
590 ==================
591 */
592 vector findbetterlocation (vector org, float mindist)
593 {
594         vector  loc;
595         vector vec;
596         float c, h;
597
598         vec = mindist * '1 0 0';
599         c = 0;
600         while (c < 6)
601         {
602                 traceline (org, org + vec, TRUE, world);
603                 vec = vec * -1;
604                 if (trace_fraction < 1)
605                 {
606                         loc = trace_endpos;
607                         traceline (loc, loc + vec, TRUE, world);
608                         if (trace_fraction >= 1)
609                                 org = loc + vec;
610                 }
611                 if (c & 1)
612                 {
613                         h = vec_y;
614                         vec_y = vec_x;
615                         vec_x = vec_z;
616                         vec_z = h;
617                 }
618                 c = c + 1;
619         }
620
621         return org;
622 }
623
624 /*
625 ==================
626 crandom
627
628 Returns a random number between -1.0 and 1.0
629 ==================
630 */
631 float crandom (void)
632 {
633         return 2 * (random () - 0.5);
634 }
635
636 /*
637 ==================
638 Angc used for animations
639 ==================
640 */
641
642
643 float angc (float a1, float a2)
644 {
645         float   a;
646
647         while (a1 > 180)
648                 a1 = a1 - 360;
649         while (a1 < -179)
650                 a1 = a1 + 360;
651
652         while (a2 > 180)
653                 a2 = a2 - 360;
654         while (a2 < -179)
655                 a2 = a2 + 360;
656
657         a = a1 - a2;
658         while (a > 180)
659                 a = a - 360;
660         while (a < -179)
661                 a = a + 360;
662
663         return a;
664 }
665
666 .string lodtarget1;
667 .string lodtarget2;
668 .string lodmodel1;
669 .string lodmodel2;
670 .float lodmodelindex0;
671 .float lodmodelindex1;
672 .float lodmodelindex2;
673 .float loddistance1;
674 .float loddistance2;
675
676 float LOD_customize()
677 {
678         float d;
679
680         if(autocvar_loddebug)
681         {
682                 d = autocvar_loddebug;
683                 if(d == 1)
684                         self.modelindex = self.lodmodelindex0;
685                 else if(d == 2 || !self.lodmodelindex2)
686                         self.modelindex = self.lodmodelindex1;
687                 else // if(d == 3)
688                         self.modelindex = self.lodmodelindex2;
689                 return TRUE;
690         }
691
692         // TODO csqc network this so it only gets sent once
693         d = vlen(NearestPointOnBox(self, other.origin) - other.origin);
694         if(d < self.loddistance1)
695                 self.modelindex = self.lodmodelindex0;
696         else if(!self.lodmodelindex2 || d < self.loddistance2)
697                 self.modelindex = self.lodmodelindex1;
698         else
699                 self.modelindex = self.lodmodelindex2;
700
701         return TRUE;
702 }
703
704 void LOD_uncustomize()
705 {
706         self.modelindex = self.lodmodelindex0;
707 }
708
709 void LODmodel_attach()
710 {
711         entity e;
712
713         if(!self.loddistance1)
714                 self.loddistance1 = 1000;
715         if(!self.loddistance2)
716                 self.loddistance2 = 2000;
717         self.lodmodelindex0 = self.modelindex;
718
719         if(self.lodtarget1 != "")
720         {
721                 e = find(world, targetname, self.lodtarget1);
722                 if(e)
723                 {
724                         self.lodmodel1 = e.model;
725                         remove(e);
726                 }
727         }
728         if(self.lodtarget2 != "")
729         {
730                 e = find(world, targetname, self.lodtarget2);
731                 if(e)
732                 {
733                         self.lodmodel2 = e.model;
734                         remove(e);
735                 }
736         }
737
738         if(autocvar_loddebug < 0)
739         {
740                 self.lodmodel1 = self.lodmodel2 = ""; // don't even initialize
741         }
742
743         if(self.lodmodel1 != "")
744         {
745                 vector mi, ma;
746                 mi = self.mins;
747                 ma = self.maxs;
748
749                 precache_model(self.lodmodel1);
750                 setmodel(self, self.lodmodel1);
751                 self.lodmodelindex1 = self.modelindex;
752
753                 if(self.lodmodel2 != "")
754                 {
755                         precache_model(self.lodmodel2);
756                         setmodel(self, self.lodmodel2);
757                         self.lodmodelindex2 = self.modelindex;
758                 }
759
760                 self.modelindex = self.lodmodelindex0;
761                 setsize(self, mi, ma);
762         }
763
764         if(self.lodmodelindex1)
765                 if not(self.SendEntity)
766                         SetCustomizer(self, LOD_customize, LOD_uncustomize);
767 }
768
769 void ApplyMinMaxScaleAngles(entity e)
770 {
771         if(e.angles_x != 0 || e.angles_z != 0 || self.avelocity_x != 0 || self.avelocity_z != 0) // "weird" rotation
772         {
773                 e.maxs = '1 1 1' * vlen(
774                         '1 0 0' * max(-e.mins_x, e.maxs_x) +
775                         '0 1 0' * max(-e.mins_y, e.maxs_y) +
776                         '0 0 1' * max(-e.mins_z, e.maxs_z)
777                 );
778                 e.mins = -e.maxs;
779         }
780         else if(e.angles_y != 0 || self.avelocity_y != 0) // yaw only is a bit better
781         {
782                 e.maxs_x = vlen(
783                         '1 0 0' * max(-e.mins_x, e.maxs_x) +
784                         '0 1 0' * max(-e.mins_y, e.maxs_y)
785                 );
786                 e.maxs_y = e.maxs_x;
787                 e.mins_x = -e.maxs_x;
788                 e.mins_y = -e.maxs_x;
789         }
790         if(e.scale)
791                 setsize(e, e.mins * e.scale, e.maxs * e.scale);
792         else
793                 setsize(e, e.mins, e.maxs);
794 }
795
796 void SetBrushEntityModel()
797 {
798         if(self.model != "")
799         {
800                 precache_model(self.model);
801                 setmodel(self, self.model); // no precision needed
802                 InitializeEntity(self, LODmodel_attach, INITPRIO_FINDTARGET);
803         }
804         setorigin(self, self.origin);
805         ApplyMinMaxScaleAngles(self);
806 }
807
808 void SetBrushEntityModelNoLOD()
809 {
810         if(self.model != "")
811         {
812                 precache_model(self.model);
813                 setmodel(self, self.model); // no precision needed
814         }
815         setorigin(self, self.origin);
816         ApplyMinMaxScaleAngles(self);
817 }
818
819 /*
820 ================
821 InitTrigger
822 ================
823 */
824
825 void SetMovedir()
826 {
827         if (self.movedir != '0 0 0')
828                 self.movedir = normalize(self.movedir);
829         else
830         {
831                 makevectors (self.angles);
832                 self.movedir = v_forward;
833         }
834
835         self.angles = '0 0 0';
836 };
837
838 void InitTrigger()
839 {
840 // trigger angles are used for one-way touches.  An angle of 0 is assumed
841 // to mean no restrictions, so use a yaw of 360 instead.
842         SetMovedir ();
843         self.solid = SOLID_TRIGGER;
844         SetBrushEntityModel();
845         self.movetype = MOVETYPE_NONE;
846         self.modelindex = 0;
847         self.model = "";
848 };
849
850 void InitSolidBSPTrigger()
851 {
852 // trigger angles are used for one-way touches.  An angle of 0 is assumed
853 // to mean no restrictions, so use a yaw of 360 instead.
854         SetMovedir ();
855         self.solid = SOLID_BSP;
856         SetBrushEntityModel();
857         self.movetype = MOVETYPE_NONE; // why was this PUSH? -div0
858 //      self.modelindex = 0;
859         self.model = "";
860 };
861
862 float InitMovingBrushTrigger()
863 {
864 // trigger angles are used for one-way touches.  An angle of 0 is assumed
865 // to mean no restrictions, so use a yaw of 360 instead.
866         self.solid = SOLID_BSP;
867         SetBrushEntityModel();
868         self.movetype = MOVETYPE_PUSH;
869         if(self.modelindex == 0)
870         {
871                 objerror("InitMovingBrushTrigger: no brushes found!");
872                 return 0;
873         }
874         return 1;
875 };