]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/triggers/triggers.qc
c9b5fdc6df6b2531d25bc8aea41abbfc6082c5c2
[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 /*
24 ==============================
25 SUB_UseTargets
26
27 the global "activator" should be set to the entity that initiated the firing.
28
29 If self.delay is set, a DelayedUse entity will be created that will actually
30 do the SUB_UseTargets after that many seconds have passed.
31
32 Centerprints any self.message to the activator.
33
34 Removes all entities with a targetname that match self.killtarget,
35 and removes them, so some events can remove other triggers.
36
37 Search for (string)targetname in all entities that
38 match (string)self.target and call their .use function
39
40 ==============================
41 */
42 void SUB_UseTargets()
43 {
44         entity t, stemp, otemp, act;
45         string s;
46         float i;
47
48 //
49 // check for a delay
50 //
51         if (self.delay)
52         {
53         // create a temp object to fire at a later time
54                 t = spawn();
55                 t.classname = "DelayedUse";
56                 t.nextthink = time + self.delay;
57                 t.think = DelayThink;
58                 t.enemy = activator;
59                 t.message = self.message;
60                 t.killtarget = self.killtarget;
61                 t.target = self.target;
62                 t.target2 = self.target2;
63                 t.target3 = self.target3;
64                 t.target4 = self.target4;
65                 return;
66         }
67
68
69 //
70 // print the message
71 //
72 #ifdef SVQC
73         if(self)
74         if(IS_PLAYER(activator) && self.message != "")
75         if(IS_REAL_CLIENT(activator))
76         {
77                 centerprint(activator, self.message);
78                 if (self.noise == "")
79                         play2(activator, "misc/talk.wav");
80         }
81
82 //
83 // kill the killtagets
84 //
85         s = self.killtarget;
86         if (s != "")
87         {
88                 for(t = world; (t = find(t, targetname, s)); )
89                         remove(t);
90         }
91 #endif
92
93 //
94 // fire targets
95 //
96         act = activator;
97         stemp = self;
98         otemp = other;
99
100         if(stemp.target_random)
101                 RandomSelection_Init();
102
103         for(i = 0; i < 4; ++i)
104         {
105                 switch(i)
106                 {
107                         default:
108                         case 0: s = stemp.target; break;
109                         case 1: s = stemp.target2; break;
110                         case 2: s = stemp.target3; break;
111                         case 3: s = stemp.target4; break;
112                 }
113                 if (s != "")
114                 {
115                         for(t = world; (t = find(t, targetname, s)); )
116                         if(t.use)
117                         {
118                                 if(stemp.target_random)
119                                 {
120                                         RandomSelection_Add(t, 0, string_null, 1, 0);
121                                 }
122                                 else
123                                 {
124                                         self = t;
125                                         other = stemp;
126                                         activator = act;
127                                         self.use();
128                                 }
129                         }
130                 }
131         }
132
133         if(stemp.target_random && RandomSelection_chosen_ent)
134         {
135                 self = RandomSelection_chosen_ent;
136                 other = stemp;
137                 activator = act;
138                 self.use();
139         }
140
141         activator = act;
142         self = stemp;
143         other = otemp;
144 }