]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/triggers/platforms.qc
It actually compiles
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / triggers / platforms.qc
1 #ifdef SVQC
2 void generic_plat_blocked()
3 {
4     if(self.dmg && other.takedamage != DAMAGE_NO) {
5         if(self.dmgtime2 < time) {
6             Damage (other, self, self, self.dmg, DEATH_HURTTRIGGER, other.origin, '0 0 0');
7             self.dmgtime2 = time + self.dmgtime;
8         }
9
10         // Gib dead/dying stuff
11         if(other.deadflag != DEAD_NO)
12             Damage (other, self, self, 10000, DEATH_HURTTRIGGER, other.origin, '0 0 0');
13     }
14 }
15
16 void plat_spawn_inside_trigger()
17 {
18         entity trigger;
19         vector tmin, tmax;
20
21         trigger = spawn();
22         trigger.touch = plat_center_touch;
23         trigger.movetype = MOVETYPE_NONE;
24         trigger.solid = SOLID_TRIGGER;
25         trigger.enemy = self;
26
27         tmin = self.absmin + '25 25 0';
28         tmax = self.absmax - '25 25 -8';
29         tmin_z = tmax_z - (self.pos1_z - self.pos2_z + 8);
30         if (self.spawnflags & PLAT_LOW_TRIGGER)
31                 tmax_z = tmin_z + 8;
32
33         if (self.size_x <= 50)
34         {
35                 tmin_x = (self.mins_x + self.maxs_x) / 2;
36                 tmax_x = tmin_x + 1;
37         }
38         if (self.size_y <= 50)
39         {
40                 tmin_y = (self.mins_y + self.maxs_y) / 2;
41                 tmax_y = tmin_y + 1;
42         }
43
44         if(tmin_x < tmax_x)
45                 if(tmin_y < tmax_y)
46                         if(tmin_z < tmax_z)
47                         {
48                                 setsize (trigger, tmin, tmax);
49                                 return;
50                         }
51
52         // otherwise, something is fishy...
53         remove(trigger);
54         objerror("plat_spawn_inside_trigger: platform has odd size or lip, can't spawn");
55 }
56
57 void plat_hit_top()
58 {
59         sound (self, CH_TRIGGER_SINGLE, self.noise1, VOL_BASE, ATTEN_NORM);
60         self.state = 1;
61         self.think = plat_go_down;
62         self.nextthink = self.ltime + 3;
63 }
64
65 void plat_hit_bottom()
66 {
67         sound (self, CH_TRIGGER_SINGLE, self.noise1, VOL_BASE, ATTEN_NORM);
68         self.state = 2;
69 }
70
71 void plat_go_down()
72 {
73         sound (self, CH_TRIGGER_SINGLE, self.noise, VOL_BASE, ATTEN_NORM);
74         self.state = 3;
75         SUB_CalcMove (self.pos2, TSPEED_LINEAR, self.speed, plat_hit_bottom);
76 }
77
78 void plat_go_up()
79 {
80         sound (self, CH_TRIGGER_SINGLE, self.noise, VOL_BASE, ATTEN_NORM);
81         self.state = 4;
82         SUB_CalcMove (self.pos1, TSPEED_LINEAR, self.speed, plat_hit_top);
83 }
84
85 void plat_center_touch()
86 {
87         if (!other.iscreature)
88                 return;
89
90         if (other.health <= 0)
91                 return;
92
93         self = self.enemy;
94         if (self.state == 2)
95                 plat_go_up ();
96         else if (self.state == 1)
97                 self.nextthink = self.ltime + 1;        // delay going down
98 }
99
100 void plat_outside_touch()
101 {
102         if (!other.iscreature)
103                 return;
104
105         if (other.health <= 0)
106                 return;
107
108         self = self.enemy;
109         if (self.state == 1)
110                 plat_go_down ();
111 }
112
113 void plat_trigger_use()
114 {
115         if (self.think)
116                 return;         // already activated
117         plat_go_down();
118 }
119
120
121 void plat_crush()
122 {
123     if((self.spawnflags & 4) && (other.takedamage != DAMAGE_NO)) { // KIll Kill Kill!!
124         Damage (other, self, self, 10000, DEATH_HURTTRIGGER, other.origin, '0 0 0');
125     } else {
126         if((self.dmg) && (other.takedamage != DAMAGE_NO)) {   // Shall we bite?
127             Damage (other, self, self, self.dmg, DEATH_HURTTRIGGER, other.origin, '0 0 0');
128             // Gib dead/dying stuff
129             if(other.deadflag != DEAD_NO)
130                 Damage (other, self, self, 10000, DEATH_HURTTRIGGER, other.origin, '0 0 0');
131         }
132
133         if (self.state == 4)
134             plat_go_down ();
135         else if (self.state == 3)
136             plat_go_up ();
137         // when in other states, then the plat_crush event came delayed after
138         // plat state already had changed
139         // this isn't a bug per se!
140     }
141 }
142
143 void plat_use()
144 {
145         self.use = func_null;
146         if (self.state != 4)
147                 objerror ("plat_use: not in up state");
148         plat_go_down();
149 }
150
151 .string sound1, sound2;
152
153 void plat_reset()
154 {
155         IFTARGETED
156         {
157                 setorigin (self, self.pos1);
158                 self.state = 4;
159                 self.use = plat_use;
160         }
161         else
162         {
163                 setorigin (self, self.pos2);
164                 self.state = 2;
165                 self.use = plat_trigger_use;
166         }
167 }
168
169 .float platmovetype_start_default, platmovetype_end_default;
170 float set_platmovetype(entity e, string s)
171 {
172         // sets platmovetype_start and platmovetype_end based on a string consisting of two values
173
174         float n;
175         n = tokenize_console(s);
176         if(n > 0)
177                 e.platmovetype_start = stof(argv(0));
178         else
179                 e.platmovetype_start = 0;
180
181         if(n > 1)
182                 e.platmovetype_end = stof(argv(1));
183         else
184                 e.platmovetype_end = e.platmovetype_start;
185
186         if(n > 2)
187                 if(argv(2) == "force")
188                         return TRUE; // no checking, return immediately
189
190         if(!cubic_speedfunc_is_sane(e.platmovetype_start, e.platmovetype_end))
191         {
192                 objerror("Invalid platform move type; platform would go in reverse, which is not allowed.");
193                 return FALSE;
194         }
195
196         return TRUE;
197 }
198 #endif