From de1dbff5705793913e05c99cf621774f41fad2bb Mon Sep 17 00:00:00 2001 From: evanpelle Date: Thu, 23 Jan 2025 11:12:01 -0800 Subject: [PATCH] combine Game & MutableGame --- src/client/ClientGameRunner.ts | 2 +- src/core/GameRunner.ts | 6 +-- src/core/Util.ts | 6 +-- src/core/execution/AttackExecution.ts | 6 +-- src/core/execution/BattleshipExecution.ts | 6 +-- src/core/execution/BotExecution.ts | 6 +-- src/core/execution/CityExecution.ts | 6 +-- src/core/execution/DefensePostExecution.ts | 6 +-- src/core/execution/DestroyerExecution.ts | 6 +-- src/core/execution/DonateExecution.ts | 4 +- src/core/execution/EmojiExecution.ts | 4 +- src/core/execution/ExecutionManager.ts | 2 +- src/core/execution/FakeHumanExecution.ts | 6 +-- src/core/execution/MissileSiloExecution.ts | 6 +-- src/core/execution/NukeExecution.ts | 6 +-- src/core/execution/PlayerExecution.ts | 6 +-- src/core/execution/PortExecution.ts | 6 +-- .../execution/SetTargetTroopRatioExecution.ts | 4 +- src/core/execution/ShellExecution.ts | 4 +- src/core/execution/SpawnExecution.ts | 6 +-- src/core/execution/TargetPlayerExecution.ts | 4 +- src/core/execution/TradeShipExecution.ts | 6 +-- src/core/execution/TransportShipExecution.ts | 6 +-- src/core/execution/WinCheckExecution.ts | 6 +-- .../alliance/AllianceRequestExecution.ts | 6 +-- .../alliance/AllianceRequestReplyExecution.ts | 6 +-- .../alliance/BreakAllianceExecution.ts | 6 +-- src/core/game/AllianceImpl.ts | 2 +- src/core/game/Game.ts | 52 ++++++++++--------- src/core/game/GameImpl.ts | 4 +- 30 files changed, 101 insertions(+), 101 deletions(-) diff --git a/src/client/ClientGameRunner.ts b/src/client/ClientGameRunner.ts index 7b63d5544..656404382 100644 --- a/src/client/ClientGameRunner.ts +++ b/src/client/ClientGameRunner.ts @@ -1,5 +1,5 @@ import { Executor } from "../core/execution/ExecutionManager"; -import { Cell, MutableGame, PlayerID, GameMapType, Difficulty, GameType } from "../core/game/Game"; +import { Cell, Game, PlayerID, GameMapType, Difficulty, GameType } from "../core/game/Game"; import { EventBus } from "../core/EventBus"; import { createRenderer, GameRenderer } from "./graphics/GameRenderer"; import { InputHandler, MouseUpEvent, ZoomEvent, DragEvent, MouseDownEvent } from "./InputHandler" diff --git a/src/core/GameRunner.ts b/src/core/GameRunner.ts index fb77c2fe5..b0a9cf029 100644 --- a/src/core/GameRunner.ts +++ b/src/core/GameRunner.ts @@ -4,7 +4,7 @@ import { getConfig } from "./configuration/Config"; import { EventBus } from "./EventBus"; import { Executor } from "./execution/ExecutionManager"; import { WinCheckExecution } from "./execution/WinCheckExecution"; -import { AllPlayers, Cell, DisplayMessageUpdate, Game, GameUpdateType, MessageType, MutableGame, NameViewData, Player, PlayerActions, PlayerID, PlayerProfile, PlayerType, UnitType } from "./game/Game"; +import { AllPlayers, Cell, DisplayMessageUpdate, Game, GameUpdateType, MessageType, NameViewData, Player, PlayerActions, PlayerID, PlayerProfile, PlayerType, UnitType } from "./game/Game"; import { createGame } from "./game/GameImpl"; import { loadTerrainMap as loadGameMap } from "./game/TerrainMapLoader"; import { GameConfig, Turn } from "./Schemas"; @@ -16,7 +16,7 @@ export async function createGameRunner(gameID: string, gameConfig: GameConfig, c const config = getConfig(gameConfig) const gameMap = await loadGameMap(gameConfig.gameMap); const game = createGame(gameMap.gameMap, gameMap.miniGameMap, gameMap.nationMap, config) - const gr = new GameRunner(game as MutableGame, new Executor(game, gameID), callBack) + const gr = new GameRunner(game as Game, new Executor(game, gameID), callBack) gr.init() return gr } @@ -30,7 +30,7 @@ export class GameRunner { private playerViewData: Record = {} constructor( - public game: MutableGame, + public game: Game, private execManager: Executor, private callBack: (gu: GameUpdateViewData) => void ) { diff --git a/src/core/Util.ts b/src/core/Util.ts index 67a3cd23f..7bd608739 100644 --- a/src/core/Util.ts +++ b/src/core/Util.ts @@ -1,9 +1,7 @@ import { v4 as uuidv4 } from 'uuid'; import twemoji from 'twemoji'; import DOMPurify from 'dompurify'; - - -import { Cell, Game, MutableGame, Player, Unit } from "./game/Game"; +import { Cell, Game, Player, Unit } from "./game/Game"; import { GameConfig, GameID, GameRecord, PlayerRecord, Turn } from './Schemas'; import { customAlphabet, nanoid } from 'nanoid'; import { andFN, GameMap, manhattanDistFN, TileRef } from './game/GameMap'; @@ -46,7 +44,7 @@ export function distSortUnit(gm: GameMap, target: Unit | TileRef): (a: Unit, b: // TODO: refactor to new file -export function sourceDstOceanShore(gm: MutableGame, src: Player, tile: TileRef): [TileRef | null, TileRef | null] { +export function sourceDstOceanShore(gm: Game, src: Player, tile: TileRef): [TileRef | null, TileRef | null] { const dst = gm.owner(tile) let srcTile = closestOceanShoreFromPlayer(gm, src, tile) let dstTile: TileRef | null = null diff --git a/src/core/execution/AttackExecution.ts b/src/core/execution/AttackExecution.ts index 8fc4f15a9..c15817ca5 100644 --- a/src/core/execution/AttackExecution.ts +++ b/src/core/execution/AttackExecution.ts @@ -1,5 +1,5 @@ import { PriorityQueue } from "@datastructures-js/priority-queue"; -import { Cell, Execution, MutableGame, Player, PlayerID, PlayerType, TerrainType, TerraNullius } from "../game/Game"; +import { Cell, Execution, Game, Player, PlayerID, PlayerType, TerrainType, TerraNullius } from "../game/Game"; import { PseudoRandom } from "../PseudoRandom"; import { MessageType } from '../game/Game'; import { renderNumber } from "../../client/Utils"; @@ -23,7 +23,7 @@ export class AttackExecution implements Execution { private _owner: Player private target: Player | TerraNullius - private mg: MutableGame + private mg: Game private border = new Set() @@ -43,7 +43,7 @@ export class AttackExecution implements Execution { return false } - init(mg: MutableGame, ticks: number) { + init(mg: Game, ticks: number) { if (!this.active) { return } diff --git a/src/core/execution/BattleshipExecution.ts b/src/core/execution/BattleshipExecution.ts index d07309d18..818a246d1 100644 --- a/src/core/execution/BattleshipExecution.ts +++ b/src/core/execution/BattleshipExecution.ts @@ -1,4 +1,4 @@ -import { Cell, Execution, MutableGame, Player, MutableUnit, PlayerID, TerrainType, Unit, UnitType } from "../game/Game"; +import { Cell, Execution, Game, Player, MutableUnit, PlayerID, TerrainType, Unit, UnitType } from "../game/Game"; import { PathFinder } from "../pathfinding/PathFinding"; import { PathFindResultType } from "../pathfinding/AStar"; import { PseudoRandom } from "../PseudoRandom"; @@ -13,7 +13,7 @@ export class BattleshipExecution implements Execution { private _owner: Player private active = true private battleship: MutableUnit = null - private mg: MutableGame = null + private mg: Game = null private pathfinder: PathFinder @@ -32,7 +32,7 @@ export class BattleshipExecution implements Execution { ) { } - init(mg: MutableGame, ticks: number): void { + init(mg: Game, ticks: number): void { this.pathfinder = PathFinder.Mini(mg, 5000, false) this._owner = mg.player(this.playerID) this.mg = mg diff --git a/src/core/execution/BotExecution.ts b/src/core/execution/BotExecution.ts index 730612a79..e2725c4eb 100644 --- a/src/core/execution/BotExecution.ts +++ b/src/core/execution/BotExecution.ts @@ -1,4 +1,4 @@ -import { Cell, Execution, MutableGame, Player, PlayerType, TerraNullius } from "../game/Game" +import { Cell, Execution, Game, Player, PlayerType, TerraNullius } from "../game/Game" import { PseudoRandom } from "../PseudoRandom" import { simpleHash } from "../Util"; import { AttackExecution } from "./AttackExecution"; @@ -8,7 +8,7 @@ export class BotExecution implements Execution { private active = true private random: PseudoRandom; private attackRate: number - private mg: MutableGame + private mg: Game private neighborsTerraNullius = true @@ -20,7 +20,7 @@ export class BotExecution implements Execution { return false } - init(mg: MutableGame, ticks: number) { + init(mg: Game, ticks: number) { this.mg = mg // this.neighborsTerra = this.bot.neighbors().filter(n => n == this.gs.terraNullius()).length > 0 } diff --git a/src/core/execution/CityExecution.ts b/src/core/execution/CityExecution.ts index 09ab06382..26d6b2e20 100644 --- a/src/core/execution/CityExecution.ts +++ b/src/core/execution/CityExecution.ts @@ -1,17 +1,17 @@ import { consolex } from "../Consolex"; -import { Execution, MutableGame, Player, MutableUnit, PlayerID, UnitType } from "../game/Game"; +import { Execution, Game, Player, MutableUnit, PlayerID, UnitType } from "../game/Game"; import { TileRef } from "../game/GameMap"; export class CityExecution implements Execution { private player: Player - private mg: MutableGame + private mg: Game private city: MutableUnit private active: boolean = true constructor(private ownerId: PlayerID, private tile: TileRef) { } - init(mg: MutableGame, ticks: number): void { + init(mg: Game, ticks: number): void { this.mg = mg this.player = mg.player(this.ownerId) } diff --git a/src/core/execution/DefensePostExecution.ts b/src/core/execution/DefensePostExecution.ts index 3ad3a8b3e..0754f9fb1 100644 --- a/src/core/execution/DefensePostExecution.ts +++ b/src/core/execution/DefensePostExecution.ts @@ -1,11 +1,11 @@ import { consolex } from "../Consolex"; -import { Cell, DefenseBonus, Execution, MutableGame, Player, MutableUnit, PlayerID, UnitType } from "../game/Game"; +import { Cell, DefenseBonus, Execution, Game, Player, MutableUnit, PlayerID, UnitType } from "../game/Game"; import { manhattanDistFN, TileRef } from "../game/GameMap"; export class DefensePostExecution implements Execution { private player: Player - private mg: MutableGame + private mg: Game private post: MutableUnit private active: boolean = true @@ -13,7 +13,7 @@ export class DefensePostExecution implements Execution { constructor(private ownerId: PlayerID, private tile: TileRef) { } - init(mg: MutableGame, ticks: number): void { + init(mg: Game, ticks: number): void { this.mg = mg this.player = mg.player(this.ownerId) } diff --git a/src/core/execution/DestroyerExecution.ts b/src/core/execution/DestroyerExecution.ts index fe1955725..774b3cd57 100644 --- a/src/core/execution/DestroyerExecution.ts +++ b/src/core/execution/DestroyerExecution.ts @@ -1,4 +1,4 @@ -import { Cell, Execution, MutableGame, Player, MutableUnit, PlayerID, TerrainType, UnitType } from "../game/Game"; +import { Cell, Execution, Game, Player, MutableUnit, PlayerID, TerrainType, UnitType } from "../game/Game"; import { PathFinder } from "../pathfinding/PathFinding"; import { PathFindResultType } from "../pathfinding/AStar"; import { PseudoRandom } from "../PseudoRandom"; @@ -12,7 +12,7 @@ export class DestroyerExecution implements Execution { private _owner: Player private active = true private destroyer: MutableUnit = null - private mg: MutableGame = null + private mg: Game = null private target: MutableUnit = null private pathfinder: PathFinder @@ -28,7 +28,7 @@ export class DestroyerExecution implements Execution { ) { } - init(mg: MutableGame, ticks: number): void { + init(mg: Game, ticks: number): void { this.pathfinder = PathFinder.Mini(mg, 5000, false) this._owner = mg.player(this.playerID) this.mg = mg diff --git a/src/core/execution/DonateExecution.ts b/src/core/execution/DonateExecution.ts index fa3cd8e1b..e0cd6b353 100644 --- a/src/core/execution/DonateExecution.ts +++ b/src/core/execution/DonateExecution.ts @@ -1,5 +1,5 @@ import { consolex } from "../Consolex"; -import { Execution, MutableGame, Player, PlayerID } from "../game/Game"; +import { Execution, Game, Player, PlayerID } from "../game/Game"; export class DonateExecution implements Execution { @@ -15,7 +15,7 @@ export class DonateExecution implements Execution { ) { } - init(mg: MutableGame, ticks: number): void { + init(mg: Game, ticks: number): void { this.sender = mg.player(this.senderID) this.recipient = mg.player(this.recipientID) if (this.troops == null) { diff --git a/src/core/execution/EmojiExecution.ts b/src/core/execution/EmojiExecution.ts index 438e8090e..a46c1347b 100644 --- a/src/core/execution/EmojiExecution.ts +++ b/src/core/execution/EmojiExecution.ts @@ -1,5 +1,5 @@ import { consolex } from "../Consolex"; -import { AllPlayers, Execution, MutableGame, Player, PlayerID, PlayerType, UnitType } from "../game/Game"; +import { AllPlayers, Execution, Game, Player, PlayerID, PlayerType, UnitType } from "../game/Game"; export class EmojiExecution implements Execution { @@ -15,7 +15,7 @@ export class EmojiExecution implements Execution { ) { } - init(mg: MutableGame, ticks: number): void { + init(mg: Game, ticks: number): void { this.requestor = mg.player(this.senderID) this.recipient = this.recipientID == AllPlayers ? AllPlayers : mg.player(this.recipientID) } diff --git a/src/core/execution/ExecutionManager.ts b/src/core/execution/ExecutionManager.ts index 8be61d442..9eee45b5c 100644 --- a/src/core/execution/ExecutionManager.ts +++ b/src/core/execution/ExecutionManager.ts @@ -1,4 +1,4 @@ -import { Cell, Execution, MutableGame, Game, Player, PlayerInfo, TerraNullius, PlayerType, Alliance, UnitType } from "../game/Game"; +import { Cell, Execution, Game, Player, PlayerInfo, TerraNullius, PlayerType, Alliance, UnitType } from "../game/Game"; import { AttackIntent, BoatAttackIntentSchema, GameID, Intent, Turn } from "../Schemas"; import { AttackExecution } from "./AttackExecution"; import { SpawnExecution } from "./SpawnExecution"; diff --git a/src/core/execution/FakeHumanExecution.ts b/src/core/execution/FakeHumanExecution.ts index d03fd5fb6..e5e230436 100644 --- a/src/core/execution/FakeHumanExecution.ts +++ b/src/core/execution/FakeHumanExecution.ts @@ -1,4 +1,4 @@ -import { AllianceRequest, Cell, Difficulty, Execution, MutableGame, Player, PlayerInfo, PlayerType, Relation, TerrainType, TerraNullius, UnitType } from "../game/Game" +import { AllianceRequest, Cell, Difficulty, Execution, Game, Player, PlayerInfo, PlayerType, Relation, TerrainType, TerraNullius, UnitType } from "../game/Game" import { PseudoRandom } from "../PseudoRandom" import { AttackExecution } from "./AttackExecution"; import { TransportShipExecution } from "./TransportShipExecution"; @@ -23,7 +23,7 @@ export class FakeHumanExecution implements Execution { private active = true private random: PseudoRandom; - private mg: MutableGame + private mg: Game private player: Player = null private enemy: Player | null = null @@ -36,7 +36,7 @@ export class FakeHumanExecution implements Execution { this.random = new PseudoRandom(simpleHash(playerInfo.id) + simpleHash(gameID)) } - init(mg: MutableGame, ticks: number) { + init(mg: Game, ticks: number) { this.mg = mg if (this.random.chance(10)) { // this.isTraitor = true diff --git a/src/core/execution/MissileSiloExecution.ts b/src/core/execution/MissileSiloExecution.ts index e5834461f..51661c0b5 100644 --- a/src/core/execution/MissileSiloExecution.ts +++ b/src/core/execution/MissileSiloExecution.ts @@ -1,11 +1,11 @@ import { consolex } from "../Consolex"; -import { Cell, Execution, MutableGame, Player, MutableUnit, PlayerID, UnitType } from "../game/Game"; +import { Cell, Execution, Game, Player, MutableUnit, PlayerID, UnitType } from "../game/Game"; import { TileRef } from "../game/GameMap"; export class MissileSiloExecution implements Execution { private active = true - private mg: MutableGame + private mg: Game private player: Player private silo: MutableUnit @@ -15,7 +15,7 @@ export class MissileSiloExecution implements Execution { ) { } - init(mg: MutableGame, ticks: number): void { + init(mg: Game, ticks: number): void { this.mg = mg this.player = mg.player(this._owner) } diff --git a/src/core/execution/NukeExecution.ts b/src/core/execution/NukeExecution.ts index de181e999..e6e56c5d0 100644 --- a/src/core/execution/NukeExecution.ts +++ b/src/core/execution/NukeExecution.ts @@ -1,5 +1,5 @@ import { nextTick } from "process"; -import { Cell, Execution, MutableGame, Player, PlayerID, MutableUnit, UnitType, TerraNullius } from "../game/Game"; +import { Cell, Execution, Game, Player, PlayerID, MutableUnit, UnitType, TerraNullius } from "../game/Game"; import { PathFinder } from "../pathfinding/PathFinding"; import { PathFindResultType } from "../pathfinding/AStar"; import { PseudoRandom } from "../PseudoRandom"; @@ -12,7 +12,7 @@ export class NukeExecution implements Execution { private active = true - private mg: MutableGame + private mg: Game private nuke: MutableUnit @@ -24,7 +24,7 @@ export class NukeExecution implements Execution { ) { } - init(mg: MutableGame, ticks: number): void { + init(mg: Game, ticks: number): void { this.mg = mg this.pathFinder = PathFinder.Mini(mg, 10_000, true) this.player = mg.player(this.senderID) diff --git a/src/core/execution/PlayerExecution.ts b/src/core/execution/PlayerExecution.ts index 45607dcd2..2a9fbcafb 100644 --- a/src/core/execution/PlayerExecution.ts +++ b/src/core/execution/PlayerExecution.ts @@ -1,5 +1,5 @@ import { Config } from "../configuration/Config" -import { Execution, MutableGame, Player, PlayerID, TerraNullius, UnitType } from "../game/Game" +import { Execution, Game, Player, PlayerID, TerraNullius, UnitType } from "../game/Game" import { calculateBoundingBox, getMode, inscribed, simpleHash } from "../Util" import { GameImpl } from "../game/GameImpl" import { consolex } from "../Consolex" @@ -12,7 +12,7 @@ export class PlayerExecution implements Execution { private player: Player private config: Config private lastCalc = 0 - private mg: MutableGame + private mg: Game private active = true constructor(private playerID: PlayerID) { @@ -22,7 +22,7 @@ export class PlayerExecution implements Execution { return false } - init(mg: MutableGame, ticks: number) { + init(mg: Game, ticks: number) { this.mg = mg this.config = mg.config() this.player = mg.player(this.playerID) diff --git a/src/core/execution/PortExecution.ts b/src/core/execution/PortExecution.ts index 48278ef3d..63806c3bf 100644 --- a/src/core/execution/PortExecution.ts +++ b/src/core/execution/PortExecution.ts @@ -1,4 +1,4 @@ -import { AllPlayers, Cell, Execution, MutableGame, Player, MutableUnit, PlayerID, TerrainType, UnitType } from "../game/Game"; +import { AllPlayers, Cell, Execution, Game, Player, MutableUnit, PlayerID, TerrainType, UnitType } from "../game/Game"; import { PathFinder } from "../pathfinding/PathFinding"; import { PathFindResultType } from "../pathfinding/AStar"; import { PseudoRandom } from "../PseudoRandom"; @@ -10,7 +10,7 @@ import { manhattanDistFN, TileRef } from "../game/GameMap"; export class PortExecution implements Execution { private active = true - private mg: MutableGame + private mg: Game private port: MutableUnit private random: PseudoRandom private portPaths = new Map() @@ -22,7 +22,7 @@ export class PortExecution implements Execution { ) { } - init(mg: MutableGame, ticks: number): void { + init(mg: Game, ticks: number): void { this.mg = mg this.random = new PseudoRandom(mg.ticks()) } diff --git a/src/core/execution/SetTargetTroopRatioExecution.ts b/src/core/execution/SetTargetTroopRatioExecution.ts index a353d8254..1938d45b0 100644 --- a/src/core/execution/SetTargetTroopRatioExecution.ts +++ b/src/core/execution/SetTargetTroopRatioExecution.ts @@ -1,5 +1,5 @@ import { consolex } from "../Consolex"; -import { Execution, MutableGame, Player, PlayerID } from "../game/Game"; +import { Execution, Game, Player, PlayerID } from "../game/Game"; export class SetTargetTroopRatioExecution implements Execution { @@ -10,7 +10,7 @@ export class SetTargetTroopRatioExecution implements Execution { constructor(private playerID: PlayerID, private targetTroopsRatio: number) { } - init(mg: MutableGame, ticks: number): void { + init(mg: Game, ticks: number): void { this.player = mg.player(this.playerID) } diff --git a/src/core/execution/ShellExecution.ts b/src/core/execution/ShellExecution.ts index 7b856e34a..1552b7be4 100644 --- a/src/core/execution/ShellExecution.ts +++ b/src/core/execution/ShellExecution.ts @@ -1,4 +1,4 @@ -import { Execution, MutableGame, Player, MutableUnit, Unit, UnitType } from "../game/Game"; +import { Execution, Game, Player, MutableUnit, Unit, UnitType } from "../game/Game"; import { PathFinder } from "../pathfinding/PathFinding"; import { PathFindResultType } from "../pathfinding/AStar"; import { consolex } from "../Consolex"; @@ -14,7 +14,7 @@ export class ShellExecution implements Execution { } - init(mg: MutableGame, ticks: number): void { + init(mg: Game, ticks: number): void { this.pathFinder = PathFinder.Mini(mg, 2000, true, 10) } diff --git a/src/core/execution/SpawnExecution.ts b/src/core/execution/SpawnExecution.ts index 51dec6038..9f74beef3 100644 --- a/src/core/execution/SpawnExecution.ts +++ b/src/core/execution/SpawnExecution.ts @@ -1,4 +1,4 @@ -import { Cell, Execution, MutableGame, Player, PlayerInfo, PlayerType } from "../game/Game" +import { Cell, Execution, Game, Player, PlayerInfo, PlayerType } from "../game/Game" import { TileRef } from "../game/GameMap" import { BotExecution } from "./BotExecution" import { PlayerExecution } from "./PlayerExecution" @@ -7,14 +7,14 @@ import { getSpawnTiles } from "./Util" export class SpawnExecution implements Execution { active: boolean = true - private mg: MutableGame + private mg: Game constructor( private playerInfo: PlayerInfo, private tile: TileRef ) { } - init(mg: MutableGame, ticks: number) { + init(mg: Game, ticks: number) { this.mg = mg } diff --git a/src/core/execution/TargetPlayerExecution.ts b/src/core/execution/TargetPlayerExecution.ts index 7e40b1ed1..ea3566e84 100644 --- a/src/core/execution/TargetPlayerExecution.ts +++ b/src/core/execution/TargetPlayerExecution.ts @@ -1,4 +1,4 @@ -import { Execution, MutableGame, Player, PlayerID } from "../game/Game"; +import { Execution, Game, Player, PlayerID } from "../game/Game"; export class TargetPlayerExecution implements Execution { @@ -10,7 +10,7 @@ export class TargetPlayerExecution implements Execution { constructor(private requestorID: PlayerID, private targetID: PlayerID) { } - init(mg: MutableGame, ticks: number): void { + init(mg: Game, ticks: number): void { this.requestor = mg.player(this.requestorID) this.target = mg.player(this.targetID) } diff --git a/src/core/execution/TradeShipExecution.ts b/src/core/execution/TradeShipExecution.ts index fe3ca80b7..95841ecb4 100644 --- a/src/core/execution/TradeShipExecution.ts +++ b/src/core/execution/TradeShipExecution.ts @@ -1,6 +1,6 @@ import { MessageType } from '../game/Game'; import { renderNumber } from "../../client/Utils"; -import { AllPlayers, Cell, Execution, MutableGame, MutableUnit, Player, PlayerID, UnitType } from "../game/Game"; +import { AllPlayers, Cell, Execution, Game, MutableUnit, Player, PlayerID, UnitType } from "../game/Game"; import { PathFinder } from "../pathfinding/PathFinding"; import { PathFindResultType } from "../pathfinding/AStar"; import { distSortUnit } from "../Util"; @@ -10,7 +10,7 @@ import { TileRef } from '../game/GameMap'; export class TradeShipExecution implements Execution { private active = true - private mg: MutableGame + private mg: Game private origOwner: Player private tradeShip: MutableUnit private index = 0 @@ -26,7 +26,7 @@ export class TradeShipExecution implements Execution { ) { } - init(mg: MutableGame, ticks: number): void { + init(mg: Game, ticks: number): void { this.mg = mg this.origOwner = mg.player(this._owner) } diff --git a/src/core/execution/TransportShipExecution.ts b/src/core/execution/TransportShipExecution.ts index 0de1c358c..9936c6567 100644 --- a/src/core/execution/TransportShipExecution.ts +++ b/src/core/execution/TransportShipExecution.ts @@ -1,4 +1,4 @@ -import { Unit, Cell, Execution, MutableUnit, MutableGame, Player, PlayerID, TerraNullius, UnitType, TerrainType } from "../game/Game"; +import { Unit, Cell, Execution, MutableUnit, Game, Player, PlayerID, TerraNullius, UnitType, TerrainType } from "../game/Game"; import { AttackExecution } from "./AttackExecution"; import { MessageType } from '../game/Game'; import { PathFinder } from "../pathfinding/PathFinding"; @@ -16,7 +16,7 @@ export class TransportShipExecution implements Execution { private active = true - private mg: MutableGame + private mg: Game private attacker: Player private target: Player | TerraNullius @@ -41,7 +41,7 @@ export class TransportShipExecution implements Execution { return false } - init(mg: MutableGame, ticks: number) { + init(mg: Game, ticks: number) { this.lastMove = ticks this.mg = mg this.pathFinder = PathFinder.Mini(mg, 10_000, false, 2) diff --git a/src/core/execution/WinCheckExecution.ts b/src/core/execution/WinCheckExecution.ts index 953dbe924..2de53cece 100644 --- a/src/core/execution/WinCheckExecution.ts +++ b/src/core/execution/WinCheckExecution.ts @@ -1,5 +1,5 @@ import { EventBus, GameEvent } from "../EventBus" -import { Execution, MutableGame, Player, PlayerID } from "../game/Game" +import { Execution, Game, Player, PlayerID } from "../game/Game" export class WinEvent implements GameEvent { constructor(public readonly winner: Player) { } @@ -9,12 +9,12 @@ export class WinCheckExecution implements Execution { private active = true - private mg: MutableGame + private mg: Game constructor() { } - init(mg: MutableGame, ticks: number) { + init(mg: Game, ticks: number) { this.mg = mg } diff --git a/src/core/execution/alliance/AllianceRequestExecution.ts b/src/core/execution/alliance/AllianceRequestExecution.ts index 2c3c0502c..091c5b0bc 100644 --- a/src/core/execution/alliance/AllianceRequestExecution.ts +++ b/src/core/execution/alliance/AllianceRequestExecution.ts @@ -1,15 +1,15 @@ import { consolex } from "../../Consolex"; -import {AllianceRequest, Execution, MutableGame, Player, PlayerID} from "../../game/Game"; +import {AllianceRequest, Execution, Game, Player, PlayerID} from "../../game/Game"; export class AllianceRequestExecution implements Execution { private active = true - private mg: MutableGame = null + private mg: Game = null private requestor: Player; private recipient: Player constructor(private requestorID: PlayerID, private recipientID: PlayerID) { } - init(mg: MutableGame, ticks: number): void { + init(mg: Game, ticks: number): void { this.mg = mg this.requestor = mg.player(this.requestorID) this.recipient = mg.player(this.recipientID) diff --git a/src/core/execution/alliance/AllianceRequestReplyExecution.ts b/src/core/execution/alliance/AllianceRequestReplyExecution.ts index 4efdf7e4d..216b8ab2c 100644 --- a/src/core/execution/alliance/AllianceRequestReplyExecution.ts +++ b/src/core/execution/alliance/AllianceRequestReplyExecution.ts @@ -1,15 +1,15 @@ import { consolex } from "../../Consolex"; -import { AllianceRequest, Execution, MutableGame, Player, PlayerID } from "../../game/Game"; +import { AllianceRequest, Execution, Game, Player, PlayerID } from "../../game/Game"; export class AllianceRequestReplyExecution implements Execution { private active = true - private mg: MutableGame = null + private mg: Game = null private requestor: Player; private recipient: Player constructor(private requestorID: PlayerID, private recipientID: PlayerID, private accept: boolean) { } - init(mg: MutableGame, ticks: number): void { + init(mg: Game, ticks: number): void { this.mg = mg this.requestor = mg.player(this.requestorID) this.recipient = mg.player(this.recipientID) diff --git a/src/core/execution/alliance/BreakAllianceExecution.ts b/src/core/execution/alliance/BreakAllianceExecution.ts index 63ea6c128..2ae94a30b 100644 --- a/src/core/execution/alliance/BreakAllianceExecution.ts +++ b/src/core/execution/alliance/BreakAllianceExecution.ts @@ -1,15 +1,15 @@ import { consolex } from "../../Consolex"; -import { AllianceRequest, Execution, MutableGame, Player, PlayerID } from "../../game/Game"; +import { AllianceRequest, Execution, Game, Player, PlayerID } from "../../game/Game"; export class BreakAllianceExecution implements Execution { private active = true private requestor: Player; private recipient: Player - private mg: MutableGame + private mg: Game constructor(private requestorID: PlayerID, private recipientID: PlayerID) { } - init(mg: MutableGame, ticks: number): void { + init(mg: Game, ticks: number): void { this.requestor = mg.player(this.requestorID) this.recipient = mg.player(this.recipientID) this.mg = mg diff --git a/src/core/game/AllianceImpl.ts b/src/core/game/AllianceImpl.ts index 569d247eb..f7e1c4933 100644 --- a/src/core/game/AllianceImpl.ts +++ b/src/core/game/AllianceImpl.ts @@ -1,4 +1,4 @@ -import {MutableAlliance, MutableGame, Player, Tick} from "./Game"; +import {MutableAlliance, Game, Player, Tick} from "./Game"; import {GameImpl} from "./GameImpl"; import {PlayerImpl} from "./PlayerImpl"; diff --git a/src/core/game/Game.ts b/src/core/game/Game.ts index 38c648abd..1620247f1 100644 --- a/src/core/game/Game.ts +++ b/src/core/game/Game.ts @@ -128,7 +128,7 @@ export interface ExecutionView { } export interface Execution extends ExecutionView { - init(mg: MutableGame, ticks: number): void + init(mg: Game, ticks: number): void tick(ticks: number): void owner(): Player } @@ -290,43 +290,45 @@ export interface Player { } export interface Game extends GameMap { - // Throws exception is player not found - player(id: PlayerID): Player - playerByClientID(id: ClientID): Player | null - hasPlayer(id: PlayerID): boolean - players(): Player[] + // Map & Dimensions isOnMap(cell: Cell): boolean width(): number height(): number - forEachTile(fn: (tile: TileRef) => void): void - executions(): ExecutionView[] - terraNullius(): TerraNullius - executeNextTick(): GameUpdates - ticks(): Tick - inSpawnPhase(): boolean - addExecution(...exec: Execution[]): void - nations(): Nation[] - config(): Config - displayMessage(message: string, type: MessageType, playerID: PlayerID | null): void - units(...types: UnitType[]): Unit[] - unitInfo(type: UnitType): UnitInfo - playerBySmallID(id: number): Player | TerraNullius map(): GameMap miniMap(): GameMap - owner(ref: TileRef): Player | TerraNullius -} + forEachTile(fn: (tile: TileRef) => void): void -export interface MutableGame extends Game { + // Player Management player(id: PlayerID): Player - playerByClientID(id: ClientID): Player | null players(): Player[] allPlayers(): Player[] + playerByClientID(id: ClientID): Player | null + playerBySmallID(id: number): Player | TerraNullius + hasPlayer(id: PlayerID): boolean addPlayer(playerInfo: PlayerInfo, manpower: number): Player - executions(): Execution[] + terraNullius(): TerraNullius + owner(ref: TileRef): Player | TerraNullius + + // Game State + ticks(): Tick + inSpawnPhase(): boolean + executeNextTick(): GameUpdates + setWinner(winner: Player): void + config(): Config + + // Units units(...types: UnitType[]): MutableUnit[] + unitInfo(type: UnitType): UnitInfo addTileDefenseBonus(tile: TileRef, unit: Unit, amount: number): DefenseBonus removeTileDefenseBonus(bonus: DefenseBonus): void - setWinner(winner: Player): void + + // Events & Messages + executions(): Execution[] + addExecution(...exec: Execution[]): void + displayMessage(message: string, type: MessageType, playerID: PlayerID | null): void + + // Nations + nations(): Nation[] } export enum GameUpdateType { diff --git a/src/core/game/GameImpl.ts b/src/core/game/GameImpl.ts index 98a9fbf44..5dc9a706d 100644 --- a/src/core/game/GameImpl.ts +++ b/src/core/game/GameImpl.ts @@ -1,5 +1,5 @@ import { Config } from "../configuration/Config"; -import { Cell, Execution, MutableGame, Game, PlayerID, PlayerInfo, Player, TerraNullius, Unit, MutableAllianceRequest, Alliance, Nation, UnitType, UnitInfo, DefenseBonus, GameUpdate, GameUpdateType, AllPlayers, GameUpdates, TerrainType, EmojiMessage } from "./Game"; +import { Cell, Execution, Game, PlayerID, PlayerInfo, Player, TerraNullius, Unit, MutableAllianceRequest, Alliance, Nation, UnitType, UnitInfo, DefenseBonus, GameUpdate, GameUpdateType, AllPlayers, GameUpdates, TerrainType, EmojiMessage } from "./Game"; import { NationMap } from "./TerrainMapLoader"; import { PlayerImpl } from "./PlayerImpl"; import { TerraNulliusImpl } from "./TerraNulliusImpl"; @@ -17,7 +17,7 @@ export function createGame(gameMap: GameMap, miniGameMap: GameMap, nationMap: Na export type CellString = string -export class GameImpl implements MutableGame { +export class GameImpl implements Game { private _ticks = 0 private unInitExecs: Execution[] = []