1 #include "platforms.qh"
3 void generic_plat_blocked(entity this, entity blocker)
6 if(this.dmg && blocker.takedamage != DAMAGE_NO)
8 if(this.dmgtime2 < time)
10 Damage (blocker, this, this, this.dmg, DEATH_HURTTRIGGER.m_id, DMG_NOWEP, blocker.origin, '0 0 0');
11 this.dmgtime2 = time + this.dmgtime;
14 // Gib dead/dying stuff
16 Damage (blocker, this, this, 10000, DEATH_HURTTRIGGER.m_id, DMG_NOWEP, blocker.origin, '0 0 0');
21 void plat_spawn_inside_trigger(entity this)
27 settouch(trigger, plat_center_touch);
28 set_movetype(trigger, MOVETYPE_NONE);
29 trigger.solid = SOLID_TRIGGER;
32 tmin = this.absmin + '25 25 0';
33 tmax = this.absmax - '25 25 -8';
34 tmin_z = tmax_z - (this.pos1_z - this.pos2_z + 8);
35 if (this.spawnflags & PLAT_LOW_TRIGGER)
38 if (this.size_x <= 50)
40 tmin_x = (this.mins_x + this.maxs_x) / 2;
43 if (this.size_y <= 50)
45 tmin_y = (this.mins_y + this.maxs_y) / 2;
53 setsize (trigger, tmin, tmax);
57 // otherwise, something is fishy...
59 objerror(this, "plat_spawn_inside_trigger: platform has odd size or lip, can't spawn");
62 void plat_hit_top(entity this)
64 _sound (this, CH_TRIGGER_SINGLE, this.noise1, VOL_BASE, ATTEN_NORM);
65 this.state = STATE_TOP;
67 setthink(this, plat_go_down);
68 this.nextthink = this.ltime + 3;
71 void plat_hit_bottom(entity this)
73 _sound (this, CH_TRIGGER_SINGLE, this.noise1, VOL_BASE, ATTEN_NORM);
74 this.state = STATE_BOTTOM;
77 void plat_go_down(entity this)
79 _sound (this, CH_TRIGGER_SINGLE, this.noise, VOL_BASE, ATTEN_NORM);
80 this.state = STATE_DOWN;
81 SUB_CalcMove (this, this.pos2, TSPEED_LINEAR, this.speed, plat_hit_bottom);
84 void plat_go_up(entity this)
86 _sound (this, CH_TRIGGER_SINGLE, this.noise, VOL_BASE, ATTEN_NORM);
87 this.state = STATE_UP;
88 SUB_CalcMove (this, this.pos1, TSPEED_LINEAR, this.speed, plat_hit_top);
91 void plat_center_touch(entity this, entity toucher)
94 if (!toucher.iscreature)
97 if (GetResource(toucher, RES_HEALTH) <= 0)
100 if (!IS_PLAYER(toucher))
106 if (this.enemy.state == STATE_BOTTOM) {
107 plat_go_up(this.enemy);
108 } else if (this.enemy.state == STATE_TOP)
109 this.enemy.nextthink = this.enemy.ltime + 1;
112 void plat_outside_touch(entity this, entity toucher)
115 if (!toucher.iscreature)
118 if (GetResource(toucher, RES_HEALTH) <= 0)
121 if (!IS_PLAYER(toucher))
125 if (this.enemy.state == STATE_TOP) {
126 entity e = this.enemy;
131 void plat_trigger_use(entity this, entity actor, entity trigger)
134 return; // already activated
139 void plat_crush(entity this, entity blocker)
141 if((this.spawnflags & CRUSH) && (blocker.takedamage != DAMAGE_NO))
142 { // KIll Kill Kill!!
144 Damage (blocker, this, this, 10000, DEATH_HURTTRIGGER.m_id, DMG_NOWEP, blocker.origin, '0 0 0');
150 if((this.dmg) && (blocker.takedamage != DAMAGE_NO))
152 Damage (blocker, this, this, this.dmg, DEATH_HURTTRIGGER.m_id, DMG_NOWEP, blocker.origin, '0 0 0');
153 // Gib dead/dying stuff
155 Damage (blocker, this, this, 10000, DEATH_HURTTRIGGER.m_id, DMG_NOWEP, blocker.origin, '0 0 0');
159 if (this.state == STATE_UP)
161 else if (this.state == STATE_DOWN)
163 // when in other states, then the plat_crush event came delayed after
164 // plat state already had changed
165 // this isn't a bug per se!
169 void plat_use(entity this, entity actor, entity trigger)
171 this.use = func_null;
172 if (this.state != STATE_UP)
173 objerror (this, "plat_use: not in up state");
177 // WARNING: backwards compatibility because people don't use already existing fields :(
178 // TODO: Check if any maps use these fields and remove these fields if it doesn't break maps
179 .string sound1, sound2;
181 void plat_reset(entity this)
183 if(this.targetname && this.targetname != "")
185 setorigin(this, this.pos1);
186 this.state = STATE_UP;
191 setorigin(this, this.pos2);
192 this.state = STATE_BOTTOM;
193 this.use = plat_trigger_use;
197 this.SendFlags |= SF_TRIGGER_RESET;
201 .float platmovetype_start_default, platmovetype_end_default;
202 bool set_platmovetype(entity e, string s)
204 // sets platmovetype_start and platmovetype_end based on a string consisting of two values
206 int n = tokenize_console(s);
208 e.platmovetype_start = stof(argv(0));
210 e.platmovetype_start = 0;
213 e.platmovetype_end = stof(argv(1));
215 e.platmovetype_end = e.platmovetype_start;
218 if(argv(2) == "force")
219 return true; // no checking, return immediately
221 if(!cubic_speedfunc_is_sane(e.platmovetype_start, e.platmovetype_end))
223 objerror(e, "Invalid platform move type; platform would go in reverse, which is not allowed.");