<?php/* * dmmotor — a moving ceiling: crushers, raise, lower (ceiling_t, T_MoveCeiling, EV_DoCeiling of p_ceilng.c). * Copyright (C) 1993-1996 by id Software, Inc.; PHP port for dmmotor. GPL v2 (see LICENSE). */namespace App\Dm\Play;use App\Dm\Sector;final class Ceiling implements Thinker{ public const LOWER_TO_FLOOR = 0; public const RAISE_TO_HIGHEST = 1; public const LOWER_AND_CRUSH = 2; public const CRUSH_AND_RAISE = 3; public const FAST_CRUSH_AND_RAISE = 4; public const SILENT_CRUSH_AND_RAISE = 5; public const CEILSPEED = 1.0; public int $type = 0; public float $bottomHeight = 0; public float $topHeight = 0; public float $speed = self::CEILSPEED; public bool $crush = false; /** 1 up, 0 stopped, -1 down */ public int $direction = -1; public int $oldDirection = -1; public int $tag = 0; public bool $removed = false; public function __construct(public Sector $sector) { $sector->specialData = $this; $this->tag = $sector->tag; } public static function start(Sector $sec, int $type): self { $c = new self($sec); $c->type = $type; switch ($type) { case self::FAST_CRUSH_AND_RAISE: $c->crush = true; $c->topHeight = $sec->ceilingHeight; $c->bottomHeight = $sec->floorHeight + 8; $c->direction = -1; $c->speed = self::CEILSPEED * 2; break; case self::SILENT_CRUSH_AND_RAISE: case self::CRUSH_AND_RAISE: case self::LOWER_AND_CRUSH: case self::LOWER_TO_FLOOR: if ($type === self::SILENT_CRUSH_AND_RAISE || $type === self::CRUSH_AND_RAISE) { $c->crush = true; $c->topHeight = $sec->ceilingHeight; } $c->bottomHeight = $sec->floorHeight + ($type !== self::LOWER_TO_FLOOR ? 8 : 0); $c->direction = -1; break; case self::RAISE_TO_HIGHEST: $c->topHeight = World::highestCeilingSurrounding($sec); $c->direction = 1; break; } return $c; } public function think(World $w): void { $sec = $this->sector; $silent = $this->type === self::SILENT_CRUSH_AND_RAISE; switch ($this->direction) { case 1: $res = $w->movePlane($sec, $this->speed, $this->topHeight, false, true, 1); if (!($w->levelTime & 7) && !$silent) { $w->sectorSound($sec, 'stnmov'); } if ($res === World::MOVE_PASTDEST) { if ($this->type === self::RAISE_TO_HIGHEST) { $w->removeActiveCeiling($this); } elseif ($silent || $this->type === self::FAST_CRUSH_AND_RAISE || $this->type === self::CRUSH_AND_RAISE) { if ($silent) { $w->sectorSound($sec, 'pstop'); } $this->direction = -1; } } break; case -1: $res = $w->movePlane($sec, $this->speed, $this->bottomHeight, $this->crush, true, -1); if (!($w->levelTime & 7) && !$silent) { $w->sectorSound($sec, 'stnmov'); } if ($res === World::MOVE_PASTDEST) { if ($silent || $this->type === self::CRUSH_AND_RAISE || $this->type === self::FAST_CRUSH_AND_RAISE) { if ($silent) { $w->sectorSound($sec, 'pstop'); } if ($this->type === self::CRUSH_AND_RAISE || $silent) { $this->speed = self::CEILSPEED; } $this->direction = 1; } elseif ($this->type === self::LOWER_AND_CRUSH || $this->type === self::LOWER_TO_FLOOR) { $w->removeActiveCeiling($this); } } elseif ($res === World::MOVE_CRUSHED) { if ($silent || $this->type === self::CRUSH_AND_RAISE || $this->type === self::LOWER_AND_CRUSH) { $this->speed = self::CEILSPEED / 8; // slow down on what it crushes } } break; } } public function isRemoved(): bool { return $this->removed; }}