specialData = $this; } /** EV_DoDoor for one sector. */ public static function start(World $w, Sector $sec, int $type): self { $d = new self($sec); $d->type = $type; $lowest = World::lowestCeilingSurrounding($sec) - 4; switch ($type) { case self::BLAZE_CLOSE: $d->topHeight = $lowest; $d->direction = -1; $d->speed = self::VDOORSPEED * 4; $w->sectorSound($sec, 'bdcls'); break; case self::CLOSE: $d->topHeight = $lowest; $d->direction = -1; $w->sectorSound($sec, 'dorcls'); break; case self::CLOSE30_THEN_OPEN: $d->topHeight = $sec->ceilingHeight; $d->direction = -1; $w->sectorSound($sec, 'dorcls'); break; case self::BLAZE_RAISE: case self::BLAZE_OPEN: $d->direction = 1; $d->topHeight = $lowest; $d->speed = self::VDOORSPEED * 4; if ($d->topHeight != $sec->ceilingHeight) { $w->sectorSound($sec, 'bdopn'); } break; default: $d->direction = 1; $d->topHeight = $lowest; if ($d->topHeight != $sec->ceilingHeight) { $w->sectorSound($sec, 'doropn'); } } return $d; } /** P_SpawnDoorCloseIn30 (sector special 10). */ public static function closeIn30(Sector $sec): self { $d = new self($sec); $sec->special = 0; $d->direction = 0; $d->type = self::NORMAL; $d->topCountdown = 30 * 35; return $d; } /** P_SpawnDoorRaiseIn5Mins (sector special 14). */ public static function raiseIn5Mins(World $w, Sector $sec): self { $d = new self($sec); $sec->special = 0; $d->direction = 2; $d->type = self::RAISE_IN_5_MINS; $d->topHeight = World::lowestCeilingSurrounding($sec) - 4; $d->topCountdown = 5 * 60 * 35; return $d; } private function finish(): void { $this->sector->specialData = null; $this->removed = true; } public function think(World $w): void { $sec = $this->sector; switch ($this->direction) { case 0: if (--$this->topCountdown <= 0) { if ($this->type === self::BLAZE_RAISE) { $this->direction = -1; $w->sectorSound($sec, 'bdcls'); } elseif ($this->type === self::NORMAL) { $this->direction = -1; $w->sectorSound($sec, 'dorcls'); } elseif ($this->type === self::CLOSE30_THEN_OPEN) { $this->direction = 1; $w->sectorSound($sec, 'doropn'); } } break; case 2: if (--$this->topCountdown <= 0 && $this->type === self::RAISE_IN_5_MINS) { $this->direction = 1; $this->type = self::NORMAL; $w->sectorSound($sec, 'doropn'); } break; case -1: $res = $w->movePlane($sec, $this->speed, $sec->floorHeight, false, true, -1); if ($res === World::MOVE_PASTDEST) { if ($this->type === self::BLAZE_RAISE || $this->type === self::BLAZE_CLOSE) { $this->finish(); $w->sectorSound($sec, 'bdcls'); } elseif ($this->type === self::NORMAL || $this->type === self::CLOSE) { $this->finish(); } elseif ($this->type === self::CLOSE30_THEN_OPEN) { $this->direction = 0; $this->topCountdown = 35 * 30; } } elseif ($res === World::MOVE_CRUSHED) { if ($this->type !== self::BLAZE_CLOSE && $this->type !== self::CLOSE) { $this->direction = 1; // something is in the way: go back up $w->sectorSound($sec, 'doropn'); } } break; case 1: $res = $w->movePlane($sec, $this->speed, $this->topHeight, false, true, 1); if ($res === World::MOVE_PASTDEST) { if ($this->type === self::BLAZE_RAISE || $this->type === self::NORMAL) { $this->direction = 0; // wait at the top $this->topCountdown = $this->topWait; } else { $this->finish(); } } break; } } public function isRemoved(): bool { return $this->removed; } }