1 #include "platforms.qh"
2 void generic_plat_blocked(entity this, entity blocker)
5 if(this.dmg && blocker.takedamage != DAMAGE_NO)
7 if(this.dmgtime2 < time)
9 Damage (blocker, this, this, this.dmg, DEATH_HURTTRIGGER.m_id, DMG_NOWEP, blocker.origin, '0 0 0');
10 this.dmgtime2 = time + this.dmgtime;
13 // Gib dead/dying stuff
15 Damage (blocker, this, this, 10000, DEATH_HURTTRIGGER.m_id, DMG_NOWEP, blocker.origin, '0 0 0');
20 void plat_spawn_inside_trigger(entity this)
26 settouch(trigger, plat_center_touch);
27 set_movetype(trigger, MOVETYPE_NONE);
28 trigger.solid = SOLID_TRIGGER;
31 tmin = this.absmin + '25 25 0';
32 tmax = this.absmax - '25 25 -8';
33 tmin_z = tmax_z - (this.pos1_z - this.pos2_z + 8);
34 if (this.spawnflags & PLAT_LOW_TRIGGER)
37 if (this.size_x <= 50)
39 tmin_x = (this.mins_x + this.maxs_x) / 2;
42 if (this.size_y <= 50)
44 tmin_y = (this.mins_y + this.maxs_y) / 2;
52 setsize (trigger, tmin, tmax);
56 // otherwise, something is fishy...
58 objerror(this, "plat_spawn_inside_trigger: platform has odd size or lip, can't spawn");
61 void plat_hit_top(entity this)
63 _sound (this, CH_TRIGGER_SINGLE, this.noise1, VOL_BASE, ATTEN_NORM);
64 this.state = STATE_TOP;
66 setthink(this, plat_go_down);
67 this.nextthink = this.ltime + 3;
70 void plat_hit_bottom(entity this)
72 _sound (this, CH_TRIGGER_SINGLE, this.noise1, VOL_BASE, ATTEN_NORM);
73 this.state = STATE_BOTTOM;
76 void plat_go_down(entity this)
78 _sound (this, CH_TRIGGER_SINGLE, this.noise, VOL_BASE, ATTEN_NORM);
79 this.state = STATE_DOWN;
80 SUB_CalcMove (this, this.pos2, TSPEED_LINEAR, this.speed, plat_hit_bottom);
83 void plat_go_up(entity this)
85 _sound (this, CH_TRIGGER_SINGLE, this.noise, VOL_BASE, ATTEN_NORM);
86 this.state = STATE_UP;
87 SUB_CalcMove (this, this.pos1, TSPEED_LINEAR, this.speed, plat_hit_top);
90 void plat_center_touch(entity this, entity toucher)
93 if (!toucher.iscreature)
96 if (toucher.health <= 0)
99 if (!IS_PLAYER(toucher))
105 if (this.enemy.state == STATE_BOTTOM) {
106 plat_go_up(this.enemy);
107 } else if (this.enemy.state == STATE_TOP)
108 this.enemy.nextthink = this.enemy.ltime + 1;
111 void plat_outside_touch(entity this, entity toucher)
114 if (!toucher.iscreature)
117 if (toucher.health <= 0)
120 if (!IS_PLAYER(toucher))
124 if (this.enemy.state == STATE_TOP) {
125 entity e = this.enemy;
130 void plat_trigger_use(entity this, entity actor, entity trigger)
133 return; // already activated
138 void plat_crush(entity this, entity blocker)
140 if((this.spawnflags & PLAT_CRUSH) && (blocker.takedamage != DAMAGE_NO))
141 { // KIll Kill Kill!!
143 Damage (blocker, this, this, 10000, DEATH_HURTTRIGGER.m_id, DMG_NOWEP, blocker.origin, '0 0 0');
149 if((this.dmg) && (blocker.takedamage != DAMAGE_NO))
151 Damage (blocker, this, this, this.dmg, DEATH_HURTTRIGGER.m_id, DMG_NOWEP, blocker.origin, '0 0 0');
152 // Gib dead/dying stuff
154 Damage (blocker, this, this, 10000, DEATH_HURTTRIGGER.m_id, DMG_NOWEP, blocker.origin, '0 0 0');
158 if (this.state == STATE_UP)
160 else if (this.state == STATE_DOWN)
162 // when in other states, then the plat_crush event came delayed after
163 // plat state already had changed
164 // this isn't a bug per se!
168 void plat_use(entity this, entity actor, entity trigger)
170 this.use = func_null;
171 if (this.state != STATE_UP)
172 objerror (this, "plat_use: not in up state");
176 // WARNING: backwards compatibility because people don't use already existing fields :(
177 // TODO: Check if any maps use these fields and remove these fields if it doesn't break maps
178 .string sound1, sound2;
180 void plat_reset(entity this)
184 setorigin(this, this.pos1);
185 this.state = STATE_UP;
190 setorigin(this, this.pos2);
191 this.state = STATE_BOTTOM;
192 this.use = plat_trigger_use;
196 this.SendFlags |= SF_TRIGGER_RESET;
200 .float platmovetype_start_default, platmovetype_end_default;
201 bool set_platmovetype(entity e, string s)
203 // sets platmovetype_start and platmovetype_end based on a string consisting of two values
205 int n = tokenize_console(s);
207 e.platmovetype_start = stof(argv(0));
209 e.platmovetype_start = 0;
212 e.platmovetype_end = stof(argv(1));
214 e.platmovetype_end = e.platmovetype_start;
217 if(argv(2) == "force")
218 return true; // no checking, return immediately
220 if(!cubic_speedfunc_is_sane(e.platmovetype_start, e.platmovetype_end))
222 objerror(e, "Invalid platform move type; platform would go in reverse, which is not allowed.");