]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/triggers/triggers.qc
Make things slightly less broken
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / triggers / triggers.qc
1 void SUB_DontUseTargets() { }
2
3 void() SUB_UseTargets;
4
5 void DelayThink()
6 {
7         activator = self.enemy;
8         SUB_UseTargets ();
9         remove(self);
10 }
11
12 void FixSize(entity e)
13 {
14         e.mins_x = rint(e.mins_x);
15         e.mins_y = rint(e.mins_y);
16         e.mins_z = rint(e.mins_z);
17
18         e.maxs_x = rint(e.maxs_x);
19         e.maxs_y = rint(e.maxs_y);
20         e.maxs_z = rint(e.maxs_z);
21 }
22
23 void trigger_setnextthink(entity e, float dtime)
24 {
25 #ifdef CSQC
26         e.nextthink = time + dtime;
27 #else
28         e.nextthink = dtime;
29 #endif
30 }
31
32 /*
33 ==============================
34 SUB_UseTargets
35
36 the global "activator" should be set to the entity that initiated the firing.
37
38 If self.delay is set, a DelayedUse entity will be created that will actually
39 do the SUB_UseTargets after that many seconds have passed.
40
41 Centerprints any self.message to the activator.
42
43 Removes all entities with a targetname that match self.killtarget,
44 and removes them, so some events can remove other triggers.
45
46 Search for (string)targetname in all entities that
47 match (string)self.target and call their .use function
48
49 ==============================
50 */
51 void SUB_UseTargets()
52 {
53         entity t, stemp, otemp, act;
54         string s;
55         float i;
56
57 //
58 // check for a delay
59 //
60         if (self.delay)
61         {
62         // create a temp object to fire at a later time
63                 t = spawn();
64                 t.classname = "DelayedUse";
65                 t.nextthink = time + self.delay;
66                 t.think = DelayThink;
67                 t.enemy = activator;
68                 t.message = self.message;
69                 t.killtarget = self.killtarget;
70                 t.target = self.target;
71                 t.target2 = self.target2;
72                 t.target3 = self.target3;
73                 t.target4 = self.target4;
74                 return;
75         }
76
77
78 //
79 // print the message
80 //
81 #ifdef SVQC
82         if(self)
83         if(IS_PLAYER(activator) && self.message != "")
84         if(IS_REAL_CLIENT(activator))
85         {
86                 centerprint(activator, self.message);
87                 if (self.noise == "")
88                         play2(activator, "misc/talk.wav");
89         }
90
91 //
92 // kill the killtagets
93 //
94         s = self.killtarget;
95         if (s != "")
96         {
97                 for(t = world; (t = find(t, targetname, s)); )
98                         remove(t);
99         }
100 #endif
101
102 //
103 // fire targets
104 //
105         act = activator;
106         stemp = self;
107         otemp = other;
108
109         if(stemp.target_random)
110                 RandomSelection_Init();
111
112         for(i = 0; i < 4; ++i)
113         {
114                 switch(i)
115                 {
116                         default:
117                         case 0: s = stemp.target; break;
118                         case 1: s = stemp.target2; break;
119                         case 2: s = stemp.target3; break;
120                         case 3: s = stemp.target4; break;
121                 }
122                 if (s != "")
123                 {
124                         for(t = world; (t = find(t, targetname, s)); )
125                         if(t.use)
126                         {
127                                 if(stemp.target_random)
128                                 {
129                                         RandomSelection_Add(t, 0, string_null, 1, 0);
130                                 }
131                                 else
132                                 {
133                                         self = t;
134                                         other = stemp;
135                                         activator = act;
136                                         self.use();
137                                 }
138                         }
139                 }
140         }
141
142         if(stemp.target_random && RandomSelection_chosen_ent)
143         {
144                 self = RandomSelection_chosen_ent;
145                 other = stemp;
146                 activator = act;
147                 self.use();
148         }
149
150         activator = act;
151         self = stemp;
152         other = otemp;
153 }
154
155 #ifdef CSQC
156 void trigger_touch_generic(void() touchfunc)
157 {
158         entity e;
159         for(e = findradius((self.absmin + self.absmax) * 0.5, vlen(self.absmax - self.absmin) * 0.5 + 1); e; e = e.chain)
160         if(e.isplayermodel)
161         {
162                 vector emin = e.absmin, emax = e.absmax;
163                 if(self.solid == SOLID_BSP)
164                 {
165                         emin -= '1 1 1';
166                         emax += '1 1 1';
167                 }
168                 if(boxesoverlap(emin, emax, self.absmin, self.absmax)) // quick
169                 if(WarpZoneLib_BoxTouchesBrush(emin, emax, self, e)) // accurate
170                 {
171                         other = e;
172                         touchfunc();
173                 }
174         }
175 }
176 void trigger_draw_generic()
177 {
178         float dt = time - self.move_time;
179         self.move_time = time;
180         if(dt <= 0) { return; }
181
182         setorigin(self, self.origin + self.velocity * frametime);
183
184         if(self.trigger_touch) { trigger_touch_generic(self.trigger_touch); }
185 }
186 #endif