<?php/* * dmmotor — a lift or a moving floor that waits (plat_t, T_PlatRaise of p_plats.c). * Copyright (C) 1993-1996 by id Software, Inc.; PHP port for dmmotor. GPL v2 (see LICENSE). */namespace App\Dm\Play;use App\Dm\Line;use App\Dm\Sector;final class Plat implements Thinker{ public const PERPETUAL_RAISE = 0; public const DOWN_WAIT_UP_STAY = 1; public const RAISE_AND_CHANGE = 2; public const RAISE_TO_NEAREST_AND_CHANGE = 3; public const BLAZE_DWUS = 4; public const UP = 0; public const DOWN = 1; public const WAITING = 2; public const IN_STASIS = 3; public const PLATWAIT = 3; public const PLATSPEED = 1.0; public int $type = 0; public float $speed = self::PLATSPEED; public float $low = 0; public float $high = 0; public int $wait = 0; public int $count = 0; public int $status = self::UP; public int $oldStatus = self::UP; public bool $crush = false; public int $tag = 0; public bool $removed = false; public function __construct(public Sector $sector) { $sector->specialData = $this; } public static function start(World $w, Sector $sec, Line $line, int $type, int $amount): self { $p = new self($sec); $p->type = $type; $p->tag = $line->tag; switch ($type) { case self::RAISE_TO_NEAREST_AND_CHANGE: $p->speed = self::PLATSPEED / 2; $sec->floorPic = $line->frontSector->floorPic; $p->high = World::nextHighestFloor($sec, $sec->floorHeight); $p->status = self::UP; $sec->special = 0; // no more damage $w->sectorSound($sec, 'stnmov'); break; case self::RAISE_AND_CHANGE: $p->speed = self::PLATSPEED / 2; $sec->floorPic = $line->frontSector->floorPic; $p->high = $sec->floorHeight + $amount; $p->status = self::UP; $w->sectorSound($sec, 'stnmov'); break; case self::DOWN_WAIT_UP_STAY: case self::BLAZE_DWUS: $p->speed = self::PLATSPEED * ($type === self::BLAZE_DWUS ? 8 : 4); $p->low = min(World::lowestFloorSurrounding($sec), $sec->floorHeight); $p->high = $sec->floorHeight; $p->wait = 35 * self::PLATWAIT; $p->status = self::DOWN; $w->sectorSound($sec, 'pstart'); break; case self::PERPETUAL_RAISE: $p->speed = self::PLATSPEED; $p->low = min(World::lowestFloorSurrounding($sec), $sec->floorHeight); $p->high = max(World::highestFloorSurrounding($sec), $sec->floorHeight); $p->wait = 35 * self::PLATWAIT; $p->status = Random::p() & 1; $w->sectorSound($sec, 'pstart'); break; } return $p; } public function think(World $w): void { $sec = $this->sector; switch ($this->status) { case self::UP: $res = $w->movePlane($sec, $this->speed, $this->high, $this->crush, false, 1); if (($this->type === self::RAISE_AND_CHANGE || $this->type === self::RAISE_TO_NEAREST_AND_CHANGE) && !($w->levelTime & 7)) { $w->sectorSound($sec, 'stnmov'); } if ($res === World::MOVE_CRUSHED && !$this->crush) { $this->count = $this->wait; $this->status = self::DOWN; $w->sectorSound($sec, 'pstart'); } elseif ($res === World::MOVE_PASTDEST) { $this->count = $this->wait; $this->status = self::WAITING; $w->sectorSound($sec, 'pstop'); if ($this->type !== self::PERPETUAL_RAISE) { $w->removeActivePlat($this); } } break; case self::DOWN: $res = $w->movePlane($sec, $this->speed, $this->low, false, false, -1); if ($res === World::MOVE_PASTDEST) { $this->count = $this->wait; $this->status = self::WAITING; $w->sectorSound($sec, 'pstop'); } break; case self::WAITING: if (--$this->count <= 0) { $this->status = $sec->floorHeight == $this->low ? self::UP : self::DOWN; $w->sectorSound($sec, 'pstart'); } break; } } public function isRemoved(): bool { return $this->removed; }}