<?php/* * dmmotor — a moving floor: raise, lower, stairs, donuts (floormove_t, T_MoveFloor, EV_DoFloor of p_floor.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 FloorMove implements Thinker{ public const LOWER_FLOOR = 0; public const LOWER_TO_LOWEST = 1; public const TURBO_LOWER = 2; public const RAISE_FLOOR = 3; public const RAISE_FLOOR_TO_NEAREST = 4; public const RAISE_TO_TEXTURE = 5; public const LOWER_AND_CHANGE = 6; public const RAISE_FLOOR24 = 7; public const RAISE_FLOOR24_AND_CHANGE = 8; public const RAISE_FLOOR_CRUSH = 9; public const RAISE_FLOOR_TURBO = 10; public const DONUT_RAISE = 11; public const RAISE_FLOOR512 = 12; public const STAIRS = 13; public const FLOORSPEED = 1.0; public int $type = 0; public bool $crush = false; public int $direction = 1; public int $newSpecial = 0; /** the floor picture to set at the end (-1 = none) */ public int $texture = -1; public float $destHeight = 0; public float $speed = self::FLOORSPEED; public bool $removed = false; public function __construct(public Sector $sector) { $sector->specialData = $this; } /** EV_DoFloor for one sector ($line: the one used, null for a boss death). */ public static function start(World $w, Sector $sec, ?Line $line, int $type): self { $f = new self($sec); $f->type = $type; switch ($type) { case self::LOWER_FLOOR: $f->direction = -1; $f->destHeight = World::highestFloorSurrounding($sec); break; case self::LOWER_TO_LOWEST: $f->direction = -1; $f->destHeight = World::lowestFloorSurrounding($sec); break; case self::TURBO_LOWER: $f->direction = -1; $f->speed = self::FLOORSPEED * 4; $f->destHeight = World::highestFloorSurrounding($sec); if ($f->destHeight != $sec->floorHeight) { $f->destHeight += 8; } break; case self::RAISE_FLOOR_CRUSH: case self::RAISE_FLOOR: $f->crush = $type === self::RAISE_FLOOR_CRUSH; $f->direction = 1; $f->destHeight = min(World::lowestCeilingSurrounding($sec), $sec->ceilingHeight); if ($f->crush) { $f->destHeight -= 8; } break; case self::RAISE_FLOOR_TURBO: $f->direction = 1; $f->speed = self::FLOORSPEED * 4; $f->destHeight = World::nextHighestFloor($sec, $sec->floorHeight); break; case self::RAISE_FLOOR_TO_NEAREST: $f->direction = 1; $f->destHeight = World::nextHighestFloor($sec, $sec->floorHeight); break; case self::RAISE_FLOOR24: $f->direction = 1; $f->destHeight = $sec->floorHeight + 24; break; case self::RAISE_FLOOR512: $f->direction = 1; $f->destHeight = $sec->floorHeight + 512; break; case self::RAISE_FLOOR24_AND_CHANGE: $f->direction = 1; $f->destHeight = $sec->floorHeight + 24; if ($line !== null) { $sec->floorPic = $line->frontSector->floorPic; $sec->special = $line->frontSector->special; } break; case self::RAISE_TO_TEXTURE: $f->direction = 1; $min = 32000; foreach ($sec->lines as $l) { if (!($l->flags & Line::ML_TWOSIDED)) { continue; } foreach ($l->sidenum as $sn) { $side = $w->map->sides[$sn] ?? null; if ($side !== null && $side->bottomTexture > 0) { $min = min($min, $w->gfx->textures[$side->bottomTexture]->height); } } } $f->destHeight = $sec->floorHeight + $min; break; case self::LOWER_AND_CHANGE: $f->direction = -1; $f->destHeight = World::lowestFloorSurrounding($sec); $f->texture = $sec->floorPic; foreach ($sec->lines as $l) { if (!($l->flags & Line::ML_TWOSIDED)) { continue; } $other = $l->frontSector === $sec ? $l->backSector : $l->frontSector; if ($other !== null && $other->floorHeight == $f->destHeight) { $f->texture = $other->floorPic; $f->newSpecial = $other->special; break; } } break; } return $f; } public static function stair(Sector $sec, float $speed, float $height): self { $f = new self($sec); $f->type = self::STAIRS; $f->direction = 1; $f->speed = $speed; $f->destHeight = $height; return $f; } public static function donut(Sector $sec, int $direction, float $height, int $texture): self { $f = new self($sec); $f->type = $direction === 1 ? self::DONUT_RAISE : self::LOWER_FLOOR; $f->direction = $direction; $f->speed = self::FLOORSPEED / 2; $f->destHeight = $height; $f->texture = $texture; return $f; } public function think(World $w): void { $sec = $this->sector; $res = $w->movePlane($sec, $this->speed, $this->destHeight, $this->crush, false, $this->direction); if (!($w->levelTime & 7)) { $w->sectorSound($sec, 'stnmov'); } if ($res !== World::MOVE_PASTDEST) { return; } $sec->specialData = null; if (($this->direction === 1 && $this->type === self::DONUT_RAISE) || ($this->direction === -1 && $this->type === self::LOWER_AND_CHANGE)) { $sec->special = $this->newSpecial; if ($this->texture >= 0) { $sec->floorPic = $this->texture; } } $this->removed = true; $w->sectorSound($sec, 'pstop'); } public function isRemoved(): bool { return $this->removed; }}