<?php/* * dmmotor — the player (player_t of d_player.h, weapon info of d_items.c). * Copyright (C) 1993-1996 by id Software, Inc.; PHP port for dmmotor. GPL v2 (see LICENSE). */namespace App\Dm\Play;use App\Dm\Info;final class Player{ public const LIVE = 0; public const DEAD = 1; public const REBORN = 2; // weapons public const WP_FIST = 0; public const WP_PISTOL = 1; public const WP_SHOTGUN = 2; public const WP_CHAINGUN = 3; public const WP_MISSILE = 4; public const WP_PLASMA = 5; public const WP_BFG = 6; public const WP_CHAINSAW = 7; public const WP_SUPERSHOTGUN = 8; public const WP_NOCHANGE = 10; // ammo public const AM_CLIP = 0; public const AM_SHELL = 1; public const AM_CELL = 2; public const AM_MISL = 3; public const AM_NOAMMO = 5; // powers public const PW_INVULNERABILITY = 0; public const PW_STRENGTH = 1; public const PW_INVISIBILITY = 2; public const PW_IRONFEET = 3; public const PW_ALLMAP = 4; public const PW_INFRARED = 5; // keys: blue, yellow, red cards, then skulls public const IT_BLUECARD = 0; public const IT_YELLOWCARD = 1; public const IT_REDCARD = 2; public const IT_BLUESKULL = 3; public const IT_YELLOWSKULL = 4; public const IT_REDSKULL = 5; public const MAXAMMO = [200, 50, 300, 50]; public const CLIPAMMO = [10, 4, 20, 1]; /** weaponinfo: [ammo, upstate, downstate, readystate, atkstate, flashstate] */ public const WEAPONINFO = [ [self::AM_NOAMMO, Info::S_PUNCHUP, Info::S_PUNCHDOWN, Info::S_PUNCH, Info::S_PUNCH1, Info::S_NULL], [self::AM_CLIP, Info::S_PISTOLUP, Info::S_PISTOLDOWN, Info::S_PISTOL, Info::S_PISTOL1, Info::S_PISTOLFLASH], [self::AM_SHELL, Info::S_SGUNUP, Info::S_SGUNDOWN, Info::S_SGUN, Info::S_SGUN1, Info::S_SGUNFLASH1], [self::AM_CLIP, Info::S_CHAINUP, Info::S_CHAINDOWN, Info::S_CHAIN, Info::S_CHAIN1, Info::S_CHAINFLASH1], [self::AM_MISL, Info::S_MISSILEUP, Info::S_MISSILEDOWN, Info::S_MISSILE, Info::S_MISSILE1, Info::S_MISSILEFLASH1], [self::AM_CELL, Info::S_PLASMAUP, Info::S_PLASMADOWN, Info::S_PLASMA, Info::S_PLASMA1, Info::S_PLASMAFLASH1], [self::AM_CELL, Info::S_BFGUP, Info::S_BFGDOWN, Info::S_BFG, Info::S_BFG1, Info::S_BFGFLASH1], [self::AM_NOAMMO, Info::S_SAWUP, Info::S_SAWDOWN, Info::S_SAW, Info::S_SAW1, Info::S_NULL], [self::AM_SHELL, Info::S_DSGUNUP, Info::S_DSGUNDOWN, Info::S_DSGUN, Info::S_DSGUN1, Info::S_DSGUNFLASH1], ]; public const PS_WEAPON = 0; public const PS_FLASH = 1; public ?Mobj $mo = null; public int $playerState = self::LIVE; public TicCmd $cmd; /** eye height (absolute), its offset over the floor and its change (landing) */ public float $viewZ = 0; public float $viewHeight = 41; public float $deltaViewHeight = 0; public float $bob = 0; public int $health = 100; public int $armorPoints = 0; /** 0 = none, 1 = green, 2 = blue */ public int $armorType = 0; /** @var array<int,int> tics left of each power */ public array $powers = [0, 0, 0, 0, 0, 0]; /** @var array<int,bool> */ public array $cards = [false, false, false, false, false, false]; public bool $backpack = false; public int $readyWeapon = self::WP_PISTOL; public int $pendingWeapon = self::WP_NOCHANGE; /** @var array<int,bool> */ public array $weaponOwned = [true, true, false, false, false, false, false, false, false]; /** @var array<int,int> */ public array $ammo = [50, 0, 0, 0]; /** @var array<int,int> */ public array $maxAmmo = self::MAXAMMO; public bool $attackDown = false; public bool $useDown = false; public int $cheats = 0; public int $refire = 0; public int $killCount = 0; public int $itemCount = 0; public int $secretCount = 0; public ?string $message = null; public int $damageCount = 0; public int $bonusCount = 0; public ?Mobj $attacker = null; public int $extraLight = 0; public int $fixedColormap = 0; /** @var array<int,PSprite> weapon and flash */ public array $psprites = []; /** the camera is this player's eyes: his own sprite is not drawn */ public bool $isViewer = true; public function __construct() { $this->cmd = new TicCmd(); $this->psprites = [new PSprite(), new PSprite()]; } /** G_PlayerReborn: back to the start of the level with a pistol. */ public function reborn(): void { $kills = $this->killCount; $items = $this->itemCount; $secrets = $this->secretCount; $fresh = new self(); foreach (get_object_vars($fresh) as $k => $v) { $this->$k = $v; } $this->killCount = $kills; $this->itemCount = $items; $this->secretCount = $secrets; $this->useDown = $this->attackDown = true; // do not fire or use at once $this->playerState = self::LIVE; } /** G_PlayerFinishLevel: powers, keys and screen flashes do not carry over. */ public function finishLevel(): void { $this->powers = [0, 0, 0, 0, 0, 0]; $this->cards = [false, false, false, false, false, false]; if ($this->mo !== null) { $this->mo->flags &= ~Info::MF_SHADOW; } $this->extraLight = 0; $this->fixedColormap = 0; $this->damageCount = 0; $this->bonusCount = 0; }}