EN
games/dmmotor / src / Dm / Play / LightFlash.php · commit 9d248a4
<?php/* * dmmotor — a broken light that flashes at random (lightflash_t of p_lights.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 LightFlash implements Thinker{    public int $count = 0;    public int $maxLight = 0;    public int $minLight = 0;    public int $maxTime = 64;    public int $minTime = 7;    public function __construct(public Sector $sector)    {    }    public static function spawn(World $w, Sector $sec): self    {        $sec->special = 0;        $f = new self($sec);        $f->maxLight = $sec->lightLevel;        $f->minLight = World::minSurroundingLight($sec, $sec->lightLevel);        $f->count = (Random::p() & $f->maxTime) + 1;        return $f;    }    public function think(World $w): void    {        if (--$this->count > 0) {            return;        }        if ($this->sector->lightLevel === $this->maxLight) {            $this->sector->lightLevel = $this->minLight;            $this->count = (Random::p() & $this->minTime) + 1;        } else {            $this->sector->lightLevel = $this->maxLight;            $this->count = (Random::p() & $this->maxTime) + 1;        }    }    public function isRemoved(): bool    {        return false;    }}