[is a wall, first picture, count, speed] */ private array $anims = []; /** @var array texture => its other switch texture */ private array $switchPairs = []; /** @var list scrolling walls (special 48) */ private array $scrollLines = []; /** @var list switches to put back: [line, where (0 top, 1 middle, 2 bottom), texture, tics] */ private array $buttons = []; /** @var list */ public array $activePlats = []; /** @var list */ public array $activeCeilings = []; // ================================================================ setup (P_SpawnSpecials, P_InitPicAnims) private function spawnSpecials(): void { $gfx = $this->gfx; if ($this->anims === []) { foreach (self::ANIMDEFS as [$isWall, $last, $first, $speed]) { if ($isWall) { if (!isset($gfx->textureNum[$first], $gfx->textureNum[$last])) { continue; } $base = $gfx->textureNum[$first]; $count = $gfx->textureNum[$last] - $base + 1; } else { if (!isset($gfx->flatNum[$first], $gfx->flatNum[$last])) { continue; } $base = $gfx->flatNum[$first]; $count = $gfx->flatNum[$last] - $base + 1; } if ($count >= 2) { $this->anims[] = [$isWall, $base, $count, $speed]; } } foreach (self::SWITCHES as $sw1) { $sw2 = 'SW2' . substr($sw1, 3); if (isset($gfx->textureNum[$sw1], $gfx->textureNum[$sw2])) { $this->switchPairs[$gfx->textureNum[$sw1]] = $gfx->textureNum[$sw2]; $this->switchPairs[$gfx->textureNum[$sw2]] = $gfx->textureNum[$sw1]; } } } $this->scrollLines = []; $this->buttons = []; $this->activePlats = []; $this->activeCeilings = []; foreach ($this->map->sectors as $sec) { switch ($sec->special) { case 1: $this->addThinker(LightFlash::spawn($this, $sec)); break; case 2: $this->addThinker(StrobeFlash::spawn($this, $sec, StrobeFlash::FASTDARK, false)); break; case 3: $this->addThinker(StrobeFlash::spawn($this, $sec, StrobeFlash::SLOWDARK, false)); break; case 4: $this->addThinker(StrobeFlash::spawn($this, $sec, StrobeFlash::FASTDARK, false)); $sec->special = 4; break; case 8: $this->addThinker(Glow::spawn($this, $sec)); break; case 9: $this->totalSecret++; break; case 10: $this->addThinker(Door::closeIn30($sec)); break; case 12: $this->addThinker(StrobeFlash::spawn($this, $sec, StrobeFlash::SLOWDARK, true)); break; case 13: $this->addThinker(StrobeFlash::spawn($this, $sec, StrobeFlash::FASTDARK, true)); break; case 14: $this->addThinker(Door::raiseIn5Mins($this, $sec)); break; case 17: $this->addThinker(FireFlicker::spawn($this, $sec)); break; } } foreach ($this->map->lines as $line) { if ($line->special === 48) { $this->scrollLines[] = $line; } } } /** P_UpdateSpecials: animations, scrolling walls, switches popping back. */ private function updateSpecials(): void { $gfx = $this->gfx; foreach ($this->anims as [$isWall, $base, $count, $speed]) { for ($i = $base; $i < $base + $count; $i++) { $pic = $base + ((intdiv($this->levelTime, $speed) + $i) % $count); if ($isWall) { $gfx->textureTranslation[$i] = $pic; } else { $gfx->flatTranslation[$i] = $pic; } } } foreach ($this->scrollLines as $line) { $this->map->sides[$line->sidenum[0]]->textureOffset += 1; } foreach ($this->buttons as $i => [$line, $where, $texture, $tics]) { if (--$this->buttons[$i][3] > 0) { continue; } $side = $this->map->sides[$line->sidenum[0]]; if ($where === 0) { $side->topTexture = $texture; } elseif ($where === 1) { $side->midTexture = $texture; } else { $side->bottomTexture = $texture; } $this->startSoundAt($line->frontSector->soundOrgX, $line->frontSector->soundOrgY, $this->sfx('swtchn')); unset($this->buttons[$i]); } } // ================================================================ helpers (p_spec.c) public static function nextSector(Line $line, Sector $sec): ?Sector { if (!($line->flags & Line::ML_TWOSIDED)) { return null; } return $line->frontSector === $sec ? $line->backSector : $line->frontSector; } public static function lowestFloorSurrounding(Sector $sec): float { $floor = $sec->floorHeight; foreach ($sec->lines as $l) { $other = self::nextSector($l, $sec); if ($other !== null && $other->floorHeight < $floor) { $floor = $other->floorHeight; } } return $floor; } public static function highestFloorSurrounding(Sector $sec): float { $floor = -500.0; foreach ($sec->lines as $l) { $other = self::nextSector($l, $sec); if ($other !== null && $other->floorHeight > $floor) { $floor = $other->floorHeight; } } return $floor; } public static function nextHighestFloor(Sector $sec, float $current): float { $best = null; foreach ($sec->lines as $l) { $other = self::nextSector($l, $sec); if ($other !== null && $other->floorHeight > $current && ($best === null || $other->floorHeight < $best)) { $best = $other->floorHeight; } } return $best ?? $current; } public static function lowestCeilingSurrounding(Sector $sec): float { $height = 32767.0; foreach ($sec->lines as $l) { $other = self::nextSector($l, $sec); if ($other !== null && $other->ceilingHeight < $height) { $height = $other->ceilingHeight; } } return $height; } public static function highestCeilingSurrounding(Sector $sec): float { $height = 0.0; foreach ($sec->lines as $l) { $other = self::nextSector($l, $sec); if ($other !== null && $other->ceilingHeight > $height) { $height = $other->ceilingHeight; } } return $height; } public static function minSurroundingLight(Sector $sec, int $max): int { $min = $max; foreach ($sec->lines as $l) { $other = self::nextSector($l, $sec); if ($other !== null && $other->lightLevel < $min) { $min = $other->lightLevel; } } return $min; } /** P_FindSectorFromLineTag: the next sector number after $start with the line's tag, -1 when none. */ private function findSectorFromTag(int $tag, int $start): int { $n = count($this->map->sectors); for ($i = $start + 1; $i < $n; $i++) { if ($this->map->sectors[$i]->tag === $tag) { return $i; } } return -1; } /** @return list the sectors with this tag and no mover yet */ private function freeTaggedSectors(int $tag): array { $out = []; foreach ($this->map->sectors as $sec) { if ($sec->tag === $tag && $sec->specialData === null) { $out[] = $sec; } } return $out; } public function sectorSound(Sector $sec, string $name): void { $this->startSoundAt($sec->soundOrgX, $sec->soundOrgY, $this->sfx($name)); } public const MOVE_OK = 0; public const MOVE_CRUSHED = 1; public const MOVE_PASTDEST = 2; /** T_MovePlane: moves a floor ($ceiling false) or a ceiling, stops on what does not fit unless it crushes. */ public function movePlane(Sector $sec, float $speed, float $dest, bool $crush, bool $ceiling, int $direction): int { if (!$ceiling) { $last = $sec->floorHeight; if ($direction === -1) { if ($sec->floorHeight - $speed < $dest) { $sec->floorHeight = $dest; if ($this->changeSector($sec, $crush)) { $sec->floorHeight = $last; $this->changeSector($sec, $crush); } return self::MOVE_PASTDEST; } $sec->floorHeight -= $speed; if ($this->changeSector($sec, $crush)) { $sec->floorHeight = $last; $this->changeSector($sec, $crush); return self::MOVE_CRUSHED; } return self::MOVE_OK; } if ($sec->floorHeight + $speed > $dest) { $sec->floorHeight = $dest; if ($this->changeSector($sec, $crush)) { $sec->floorHeight = $last; $this->changeSector($sec, $crush); } return self::MOVE_PASTDEST; } $sec->floorHeight += $speed; if ($this->changeSector($sec, $crush)) { if ($crush) { return self::MOVE_CRUSHED; } $sec->floorHeight = $last; $this->changeSector($sec, $crush); return self::MOVE_CRUSHED; } return self::MOVE_OK; } $last = $sec->ceilingHeight; if ($direction === -1) { if ($sec->ceilingHeight - $speed < $dest) { $sec->ceilingHeight = $dest; if ($this->changeSector($sec, $crush)) { $sec->ceilingHeight = $last; $this->changeSector($sec, $crush); } return self::MOVE_PASTDEST; } $sec->ceilingHeight -= $speed; if ($this->changeSector($sec, $crush)) { if ($crush) { return self::MOVE_CRUSHED; } $sec->ceilingHeight = $last; $this->changeSector($sec, $crush); return self::MOVE_CRUSHED; } return self::MOVE_OK; } if ($sec->ceilingHeight + $speed > $dest) { $sec->ceilingHeight = $dest; if ($this->changeSector($sec, $crush)) { $sec->ceilingHeight = $last; $this->changeSector($sec, $crush); } return self::MOVE_PASTDEST; } $sec->ceilingHeight += $speed; $this->changeSector($sec, $crush); return self::MOVE_OK; } public function exitLevel(): void { $this->exit = 'normal'; } public function secretExitLevel(): void { $this->exit = 'secret'; } // ================================================================ lines /** P_CrossSpecialLine: walk-over lines (W1 / WR). */ public function crossSpecialLine(Line $line, int $side, Mobj $thing): void { if ($thing->player === null) { // things that are not monsters do not trigger anything if (in_array($thing->type, [Info::MT_ROCKET, Info::MT_PLASMA, Info::MT_BFG, Info::MT_TROOPSHOT, Info::MT_HEADSHOT, Info::MT_BRUISERSHOT], true)) { return; } if (!in_array($line->special, [39, 97, 125, 126, 4, 10, 88], true)) { return; // what monsters can trigger } } $s = $line->special; $once = true; switch ($s) { // ---- triggers (once) case 2: $this->doDoor($line, Door::OPEN); break; case 3: $this->doDoor($line, Door::CLOSE); break; case 4: $this->doDoor($line, Door::NORMAL); break; case 5: $this->doFloor($line, FloorMove::RAISE_FLOOR); break; case 6: $this->doCeiling($line, Ceiling::FAST_CRUSH_AND_RAISE); break; case 8: $this->buildStairs($line, false); break; case 10: $this->doPlat($line, Plat::DOWN_WAIT_UP_STAY, 0); break; case 12: $this->lightTurnOn($line, 0); break; case 13: $this->lightTurnOn($line, 255); break; case 16: $this->doDoor($line, Door::CLOSE30_THEN_OPEN); break; case 17: $this->startLightStrobing($line); break; case 19: $this->doFloor($line, FloorMove::LOWER_FLOOR); break; case 22: $this->doPlat($line, Plat::RAISE_TO_NEAREST_AND_CHANGE, 0); break; case 25: $this->doCeiling($line, Ceiling::CRUSH_AND_RAISE); break; case 30: $this->doFloor($line, FloorMove::RAISE_TO_TEXTURE); break; case 35: $this->lightTurnOn($line, 35); break; case 36: $this->doFloor($line, FloorMove::TURBO_LOWER); break; case 37: $this->doFloor($line, FloorMove::LOWER_AND_CHANGE); break; case 38: $this->doFloor($line, FloorMove::LOWER_TO_LOWEST); break; case 39: $this->teleport($line, $side, $thing); break; case 40: $this->doCeiling($line, Ceiling::RAISE_TO_HIGHEST); $this->doFloor($line, FloorMove::LOWER_TO_LOWEST); break; case 44: $this->doCeiling($line, Ceiling::LOWER_AND_CRUSH); break; case 52: $this->exitLevel(); $once = false; break; case 53: $this->doPlat($line, Plat::PERPETUAL_RAISE, 0); break; case 54: $this->stopPlat($line); break; case 56: $this->doFloor($line, FloorMove::RAISE_FLOOR_CRUSH); break; case 57: $this->ceilingCrushStop($line); break; case 58: $this->doFloor($line, FloorMove::RAISE_FLOOR24); break; case 59: $this->doFloor($line, FloorMove::RAISE_FLOOR24_AND_CHANGE); break; case 104: $this->turnTagLightsOff($line); break; case 108: $this->doDoor($line, Door::BLAZE_RAISE); break; case 109: $this->doDoor($line, Door::BLAZE_OPEN); break; case 100: $this->buildStairs($line, true); break; case 110: $this->doDoor($line, Door::BLAZE_CLOSE); break; case 119: $this->doFloor($line, FloorMove::RAISE_FLOOR_TO_NEAREST); break; case 121: $this->doPlat($line, Plat::BLAZE_DWUS, 0); break; case 124: $this->secretExitLevel(); $once = false; break; case 125: if ($thing->player === null) { $this->teleport($line, $side, $thing); break; } return; case 130: $this->doFloor($line, FloorMove::RAISE_FLOOR_TURBO); break; case 141: $this->doCeiling($line, Ceiling::SILENT_CRUSH_AND_RAISE); break; // ---- retriggers default: $once = false; switch ($s) { case 72: $this->doCeiling($line, Ceiling::LOWER_AND_CRUSH); break; case 73: $this->doCeiling($line, Ceiling::CRUSH_AND_RAISE); break; case 74: $this->ceilingCrushStop($line); break; case 75: $this->doDoor($line, Door::CLOSE); break; case 76: $this->doDoor($line, Door::CLOSE30_THEN_OPEN); break; case 77: $this->doCeiling($line, Ceiling::FAST_CRUSH_AND_RAISE); break; case 79: $this->lightTurnOn($line, 35); break; case 80: $this->lightTurnOn($line, 0); break; case 81: $this->lightTurnOn($line, 255); break; case 82: $this->doFloor($line, FloorMove::LOWER_TO_LOWEST); break; case 83: $this->doFloor($line, FloorMove::LOWER_FLOOR); break; case 84: $this->doFloor($line, FloorMove::LOWER_AND_CHANGE); break; case 86: $this->doDoor($line, Door::OPEN); break; case 87: $this->doPlat($line, Plat::PERPETUAL_RAISE, 0); break; case 88: $this->doPlat($line, Plat::DOWN_WAIT_UP_STAY, 0); break; case 89: $this->stopPlat($line); break; case 90: $this->doDoor($line, Door::NORMAL); break; case 91: $this->doFloor($line, FloorMove::RAISE_FLOOR); break; case 92: $this->doFloor($line, FloorMove::RAISE_FLOOR24); break; case 93: $this->doFloor($line, FloorMove::RAISE_FLOOR24_AND_CHANGE); break; case 94: $this->doFloor($line, FloorMove::RAISE_FLOOR_CRUSH); break; case 95: $this->doPlat($line, Plat::RAISE_TO_NEAREST_AND_CHANGE, 0); break; case 96: $this->doFloor($line, FloorMove::RAISE_TO_TEXTURE); break; case 97: $this->teleport($line, $side, $thing); break; case 98: $this->doFloor($line, FloorMove::TURBO_LOWER); break; case 105: $this->doDoor($line, Door::BLAZE_RAISE); break; case 106: $this->doDoor($line, Door::BLAZE_OPEN); break; case 107: $this->doDoor($line, Door::BLAZE_CLOSE); break; case 120: $this->doPlat($line, Plat::BLAZE_DWUS, 0); break; case 126: if ($thing->player === null) { $this->teleport($line, $side, $thing); } break; case 128: $this->doFloor($line, FloorMove::RAISE_FLOOR_TO_NEAREST); break; case 129: $this->doFloor($line, FloorMove::RAISE_FLOOR_TURBO); break; } } if ($once) { $line->special = 0; } } /** P_ShootSpecialLine: gun-activated lines (G1 / GR). */ public function shootSpecialLine(Mobj $thing, Line $line): void { if ($thing->player === null && $line->special !== 46) { return; } switch ($line->special) { case 24: $this->doFloor($line, FloorMove::RAISE_FLOOR); $this->changeSwitchTexture($line, false); break; case 46: $this->doDoor($line, Door::OPEN); $this->changeSwitchTexture($line, true); break; case 47: $this->doPlat($line, Plat::RAISE_TO_NEAREST_AND_CHANGE, 0); $this->changeSwitchTexture($line, false); break; } } /** P_UseSpecialLine: switches and doors (S1 / SR / D). */ public function useSpecialLine(Mobj $thing, Line $line, int $side): bool { if ($side && $line->special !== 124) { return false; // use only from the front } if ($thing->player === null) { if ($line->flags & Line::ML_SECRET) { return false; // monsters never open secret doors } if (!in_array($line->special, [1, 32, 33, 34], true)) { return false; } } $s = $line->special; $sw = fn (bool $did, bool $again) => $did && $this->changeSwitchTexture($line, $again); switch ($s) { case 1: case 26: case 27: case 28: case 31: case 32: case 33: case 34: case 117: case 118: $this->verticalDoor($line, $thing); break; // ---- once case 7: $sw($this->buildStairs($line, false), false); break; case 9: $sw($this->doDonut($line), false); break; case 11: $this->changeSwitchTexture($line, false); $this->exitLevel(); break; case 14: $sw($this->doPlat($line, Plat::RAISE_AND_CHANGE, 32), false); break; case 15: $sw($this->doPlat($line, Plat::RAISE_AND_CHANGE, 24), false); break; case 18: $sw($this->doFloor($line, FloorMove::RAISE_FLOOR_TO_NEAREST), false); break; case 20: $sw($this->doPlat($line, Plat::RAISE_TO_NEAREST_AND_CHANGE, 0), false); break; case 21: $sw($this->doPlat($line, Plat::DOWN_WAIT_UP_STAY, 0), false); break; case 23: $sw($this->doFloor($line, FloorMove::LOWER_TO_LOWEST), false); break; case 29: $sw($this->doDoor($line, Door::NORMAL), false); break; case 41: $sw($this->doCeiling($line, Ceiling::LOWER_TO_FLOOR), false); break; case 71: $sw($this->doFloor($line, FloorMove::TURBO_LOWER), false); break; case 49: $sw($this->doCeiling($line, Ceiling::CRUSH_AND_RAISE), false); break; case 50: $sw($this->doDoor($line, Door::CLOSE), false); break; case 51: $this->changeSwitchTexture($line, false); $this->secretExitLevel(); break; case 55: $sw($this->doFloor($line, FloorMove::RAISE_FLOOR_CRUSH), false); break; case 101: $sw($this->doFloor($line, FloorMove::RAISE_FLOOR), false); break; case 102: $sw($this->doFloor($line, FloorMove::LOWER_FLOOR), false); break; case 103: $sw($this->doDoor($line, Door::OPEN), false); break; case 111: $sw($this->doDoor($line, Door::BLAZE_RAISE), false); break; case 112: $sw($this->doDoor($line, Door::BLAZE_OPEN), false); break; case 113: $sw($this->doDoor($line, Door::BLAZE_CLOSE), false); break; case 122: $sw($this->doPlat($line, Plat::BLAZE_DWUS, 0), false); break; case 127: $sw($this->buildStairs($line, true), false); break; case 131: $sw($this->doFloor($line, FloorMove::RAISE_FLOOR_TURBO), false); break; case 133: case 135: case 137: $sw($this->doLockedDoor($line, Door::BLAZE_OPEN, $thing), false); break; case 140: $sw($this->doFloor($line, FloorMove::RAISE_FLOOR512), false); break; // ---- buttons (again) case 42: $sw($this->doDoor($line, Door::CLOSE), true); break; case 43: $sw($this->doCeiling($line, Ceiling::LOWER_TO_FLOOR), true); break; case 45: $sw($this->doFloor($line, FloorMove::LOWER_FLOOR), true); break; case 60: $sw($this->doFloor($line, FloorMove::LOWER_TO_LOWEST), true); break; case 61: $sw($this->doDoor($line, Door::OPEN), true); break; case 62: $sw($this->doPlat($line, Plat::DOWN_WAIT_UP_STAY, 1), true); break; case 63: $sw($this->doDoor($line, Door::NORMAL), true); break; case 64: $sw($this->doFloor($line, FloorMove::RAISE_FLOOR), true); break; case 66: $sw($this->doPlat($line, Plat::RAISE_AND_CHANGE, 24), true); break; case 67: $sw($this->doPlat($line, Plat::RAISE_AND_CHANGE, 32), true); break; case 65: $sw($this->doFloor($line, FloorMove::RAISE_FLOOR_CRUSH), true); break; case 68: $sw($this->doPlat($line, Plat::RAISE_TO_NEAREST_AND_CHANGE, 0), true); break; case 69: $sw($this->doFloor($line, FloorMove::RAISE_FLOOR_TO_NEAREST), true); break; case 70: $sw($this->doFloor($line, FloorMove::TURBO_LOWER), true); break; case 114: $sw($this->doDoor($line, Door::BLAZE_RAISE), true); break; case 115: $sw($this->doDoor($line, Door::BLAZE_OPEN), true); break; case 116: $sw($this->doDoor($line, Door::BLAZE_CLOSE), true); break; case 123: $sw($this->doPlat($line, Plat::BLAZE_DWUS, 0), true); break; case 132: $sw($this->doFloor($line, FloorMove::RAISE_FLOOR_TURBO), true); break; case 99: case 134: case 136: $sw($this->doLockedDoor($line, Door::BLAZE_OPEN, $thing), true); break; case 138: $this->lightTurnOn($line, 255); $this->changeSwitchTexture($line, true); break; case 139: $this->lightTurnOn($line, 35); $this->changeSwitchTexture($line, true); break; } return true; } /** P_ChangeSwitchTexture: the switch shows its other picture; a button pops back after a second. */ private function changeSwitchTexture(Line $line, bool $useAgain): bool { $exit = $line->special === 11; if (!$useAgain) { $line->special = 0; } $side = $this->map->sides[$line->sidenum[0]]; $sound = $this->sfx($exit ? 'swtchx' : 'swtchn'); $front = $line->frontSector; foreach ([0 => 'topTexture', 1 => 'midTexture', 2 => 'bottomTexture'] as $where => $field) { $tex = $side->$field; if ($tex && isset($this->switchPairs[$tex])) { $this->startSoundAt($front->soundOrgX, $front->soundOrgY, $sound); $side->$field = $this->switchPairs[$tex]; if ($useAgain) { $this->buttons[] = [$line, $where, $tex, self::BUTTONTIME]; } return true; } } return true; } /** P_PlayerInSpecialSector: damaging floors, secrets, the end of the episode. */ public function playerInSpecialSector(Player $player): void { $sec = $player->mo->subsector->sector; if ($player->mo->z != $sec->floorHeight) { return; // not all the way down yet } $everySecond = !($this->levelTime & 0x1F); switch ($sec->special) { case 5: if (!$player->powers[Player::PW_IRONFEET] && $everySecond) { $this->damageMobj($player->mo, null, null, 10); } break; case 7: if (!$player->powers[Player::PW_IRONFEET] && $everySecond) { $this->damageMobj($player->mo, null, null, 5); } break; case 16: case 4: if ((!$player->powers[Player::PW_IRONFEET] || Random::p() < 5) && $everySecond) { $this->damageMobj($player->mo, null, null, 20); } break; case 9: $player->secretCount++; $sec->special = 0; break; case 11: $player->cheats &= ~2; if ($everySecond) { $this->damageMobj($player->mo, null, null, 20); } if ($player->health <= 10) { $this->exitLevel(); } break; } } /** EV_Teleport: to the teleport destination thing of the tagged sector. */ private function teleport(Line $line, int $side, Mobj $thing): bool { if ($thing->flags & Info::MF_MISSILE) { return false; } if ($side === 1) { return false; // the back of the line } foreach ($this->thinkers as $m) { if (!$m instanceof Mobj || $m->removed || $m->type !== Info::MT_TELEPORTMAN) { continue; } if ($m->subsector->sector->tag !== $line->tag) { continue; } $oldX = $thing->x; $oldY = $thing->y; $oldZ = $thing->z; if (!$this->teleportMove($thing, $m->x, $m->y)) { return false; } $thing->z = $thing->floorZ; if ($thing->player !== null) { $thing->player->viewZ = $thing->z + $thing->player->viewHeight; } $fog = $this->spawnMobj($oldX, $oldY, $oldZ, Info::MT_TFOG); $this->startSound($fog, $this->sfx('telept')); $fog = $this->spawnMobj($m->x + 20 * cos($m->angle), $m->y + 20 * sin($m->angle), $thing->z, Info::MT_TFOG); $this->startSound($fog, $this->sfx('telept')); if ($thing->player !== null) { $thing->reactionTime = 18; // do not move for a bit } $thing->angle = $m->angle; $thing->momX = $thing->momY = $thing->momZ = 0; return true; } return false; } // ================================================================ doors (p_doors.c) public function doDoor(Line $line, int $type): bool { $done = false; foreach ($this->freeTaggedSectors($line->tag) as $sec) { $done = true; $this->addThinker(Door::start($this, $sec, $type)); } return $done; } public function doDoorByTag(int $tag, int $type): void { foreach ($this->freeTaggedSectors($tag) as $sec) { $this->addThinker(Door::start($this, $sec, $type)); } } private function doLockedDoor(Line $line, int $type, Mobj $thing): bool { $player = $thing->player; if ($player === null) { return false; } $need = match ($line->special) { 99, 133 => [Player::IT_BLUECARD, Player::IT_BLUESKULL, 'PD_BLUEO'], 134, 135 => [Player::IT_REDCARD, Player::IT_REDSKULL, 'PD_REDO'], 136, 137 => [Player::IT_YELLOWCARD, Player::IT_YELLOWSKULL, 'PD_YELLOWO'], default => null, }; if ($need !== null && !$player->cards[$need[0]] && !$player->cards[$need[1]]) { $player->message = Strings::get($need[2]); $this->startSound(null, $this->sfx('oof')); return false; } return $this->doDoor($line, $type); } /** EV_VerticalDoor: a door opened by hand (the line's back sector). */ private function verticalDoor(Line $line, Mobj $thing): void { $player = $thing->player; $need = match ($line->special) { 26, 32 => [Player::IT_BLUECARD, Player::IT_BLUESKULL, 'PD_BLUEK'], 27, 34 => [Player::IT_YELLOWCARD, Player::IT_YELLOWSKULL, 'PD_YELLOWK'], 28, 33 => [Player::IT_REDCARD, Player::IT_REDSKULL, 'PD_REDK'], default => null, }; if ($need !== null) { if ($player === null) { return; } if (!$player->cards[$need[0]] && !$player->cards[$need[1]]) { $player->message = Strings::get($need[2]); $this->startSound(null, $this->sfx('oof')); return; } } $sec = $line->backSector; if ($sec === null) { return; } if ($sec->specialData !== null) { $door = $sec->specialData; if ($door instanceof Door && in_array($line->special, [1, 26, 27, 28, 117], true)) { if ($door->direction === -1) { $door->direction = 1; // go back up } elseif ($thing->player !== null) { $door->direction = -1; // start going down at once (monsters never close doors) } } return; } $this->sectorSound($sec, in_array($line->special, [117, 118], true) ? 'bdopn' : 'doropn'); $door = new Door($sec); $door->direction = 1; $door->speed = Door::VDOORSPEED; $door->topWait = Door::VDOORWAIT; switch ($line->special) { case 1: case 26: case 27: case 28: $door->type = Door::NORMAL; break; case 31: case 32: case 33: case 34: $door->type = Door::OPEN; $line->special = 0; break; case 117: $door->type = Door::BLAZE_RAISE; $door->speed = Door::VDOORSPEED * 4; break; case 118: $door->type = Door::BLAZE_OPEN; $line->special = 0; $door->speed = Door::VDOORSPEED * 4; break; } $door->topHeight = self::lowestCeilingSurrounding($sec) - 4; $this->addThinker($door); } // ================================================================ lifts (p_plats.c) public function doPlat(Line $line, int $type, int $amount): bool { if ($type === Plat::PERPETUAL_RAISE) { $this->activateInStasisPlats($line->tag); } $done = false; foreach ($this->freeTaggedSectors($line->tag) as $sec) { $done = true; $plat = Plat::start($this, $sec, $line, $type, $amount); $this->addThinker($plat); $this->activePlats[] = $plat; } return $done; } private function activateInStasisPlats(int $tag): void { foreach ($this->activePlats as $plat) { if ($plat->tag === $tag && $plat->status === Plat::IN_STASIS) { $plat->status = $plat->oldStatus; } } } private function stopPlat(Line $line): void { foreach ($this->activePlats as $plat) { if ($plat->status !== Plat::IN_STASIS && $plat->tag === $line->tag) { $plat->oldStatus = $plat->status; $plat->status = Plat::IN_STASIS; } } } public function removeActivePlat(Plat $plat): void { $plat->sector->specialData = null; $plat->removed = true; $this->activePlats = array_values(array_filter($this->activePlats, fn ($p) => $p !== $plat)); } // ================================================================ floors (p_floor.c) public function doFloor(Line $line, int $type): bool { $done = false; foreach ($this->freeTaggedSectors($line->tag) as $sec) { $done = true; $this->addThinker(FloorMove::start($this, $sec, $line, $type)); } return $done; } public function doFloorByTag(int $tag, int $type): void { foreach ($this->freeTaggedSectors($tag) as $sec) { $this->addThinker(FloorMove::start($this, $sec, null, $type)); } } /** EV_BuildStairs: the tagged sector, then the next ones with the same floor picture, each a step higher. */ private function buildStairs(Line $line, bool $turbo): bool { $done = false; $secNum = -1; while (($secNum = $this->findSectorFromTag($line->tag, $secNum)) >= 0) { $sec = $this->map->sectors[$secNum]; if ($sec->specialData !== null) { continue; } $done = true; $speed = $turbo ? FloorMove::FLOORSPEED * 4 : FloorMove::FLOORSPEED / 4; $size = $turbo ? 16 : 8; $height = $sec->floorHeight + $size; $this->addThinker(FloorMove::stair($sec, $speed, $height)); $texture = $sec->floorPic; do { $ok = false; foreach ($sec->lines as $l) { if (!($l->flags & Line::ML_TWOSIDED) || $l->frontSector !== $sec) { continue; } $tsec = $l->backSector; if ($tsec === null || $tsec->floorPic !== $texture) { continue; } $height += $size; if ($tsec->specialData !== null) { continue; } $sec = $tsec; $secNum = $tsec->id; $this->addThinker(FloorMove::stair($sec, $speed, $height)); $ok = true; break; } } while ($ok); } return $done; } /** EV_DoDonut: the pillar goes down while the slime around rises. */ private function doDonut(Line $line): bool { $done = false; foreach ($this->freeTaggedSectors($line->tag) as $s1) { $done = true; $s2 = $s1->lines === [] ? null : self::nextSector($s1->lines[0], $s1); if ($s2 === null) { continue; } foreach ($s2->lines as $l) { if (!($l->flags & Line::ML_TWOSIDED) || $l->backSector === $s1 || $l->backSector === null) { continue; } $s3 = $l->backSector; $this->addThinker(FloorMove::donut($s2, 1, $s3->floorHeight, $s3->floorPic)); $this->addThinker(FloorMove::donut($s1, -1, $s3->floorHeight, -1)); break; } } return $done; } // ================================================================ ceilings (p_ceilng.c) public function doCeiling(Line $line, int $type): bool { if (in_array($type, [Ceiling::FAST_CRUSH_AND_RAISE, Ceiling::SILENT_CRUSH_AND_RAISE, Ceiling::CRUSH_AND_RAISE], true)) { foreach ($this->activeCeilings as $c) { if ($c->tag === $line->tag && $c->direction === 0) { $c->direction = $c->oldDirection; } } } $done = false; foreach ($this->freeTaggedSectors($line->tag) as $sec) { $done = true; $c = Ceiling::start($sec, $type); $this->addThinker($c); $this->activeCeilings[] = $c; } return $done; } private function ceilingCrushStop(Line $line): void { foreach ($this->activeCeilings as $c) { if ($c->tag === $line->tag && $c->direction !== 0) { $c->oldDirection = $c->direction; $c->direction = 0; } } } public function removeActiveCeiling(Ceiling $c): void { $c->sector->specialData = null; $c->removed = true; $this->activeCeilings = array_values(array_filter($this->activeCeilings, fn ($x) => $x !== $c)); } // ================================================================ lights (p_lights.c) private function startLightStrobing(Line $line): void { foreach ($this->freeTaggedSectors($line->tag) as $sec) { $this->addThinker(StrobeFlash::spawn($this, $sec, StrobeFlash::SLOWDARK, false)); } } private function turnTagLightsOff(Line $line): void { foreach ($this->map->sectors as $sec) { if ($sec->tag !== $line->tag) { continue; } $min = $sec->lightLevel; foreach ($sec->lines as $l) { $t = self::nextSector($l, $sec); if ($t !== null && $t->lightLevel < $min) { $min = $t->lightLevel; } } $sec->lightLevel = $min; } } private function lightTurnOn(Line $line, int $bright): void { foreach ($this->map->sectors as $sec) { if ($sec->tag !== $line->tag) { continue; } if (!$bright) { // the brightest light around foreach ($sec->lines as $l) { $t = self::nextSector($l, $sec); if ($t !== null && $t->lightLevel > $bright) { $bright = $t->lightLevel; } } } $sec->lightLevel = $bright; } } }