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