Combine Unit & MutableUnit

This commit is contained in:
evanpelle
2025-01-23 11:14:08 -08:00
committed by Evan
parent de1dbff570
commit 75fe718f16
13 changed files with 49 additions and 44 deletions
+2 -2
View File
@@ -1,4 +1,4 @@
import { Cell, Execution, Game, Player, MutableUnit, PlayerID, TerrainType, Unit, UnitType } from "../game/Game";
import { Cell, Execution, Game, Player, Unit, 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 BattleshipExecution implements Execution {
private _owner: Player
private active = true
private battleship: MutableUnit = null
private battleship: Unit = null
private mg: Game = null
private pathfinder: PathFinder
+2 -2
View File
@@ -1,12 +1,12 @@
import { consolex } from "../Consolex";
import { Execution, Game, Player, MutableUnit, PlayerID, UnitType } from "../game/Game";
import { Execution, Game, Player, Unit, PlayerID, UnitType } from "../game/Game";
import { TileRef } from "../game/GameMap";
export class CityExecution implements Execution {
private player: Player
private mg: Game
private city: MutableUnit
private city: Unit
private active: boolean = true
constructor(private ownerId: PlayerID, private tile: TileRef) { }
+2 -2
View File
@@ -1,12 +1,12 @@
import { consolex } from "../Consolex";
import { Cell, DefenseBonus, Execution, Game, Player, MutableUnit, PlayerID, UnitType } from "../game/Game";
import { Cell, DefenseBonus, Execution, Game, Player, Unit, PlayerID, UnitType } from "../game/Game";
import { manhattanDistFN, TileRef } from "../game/GameMap";
export class DefensePostExecution implements Execution {
private player: Player
private mg: Game
private post: MutableUnit
private post: Unit
private active: boolean = true
private defenseBonuses: DefenseBonus[] = []
+3 -3
View File
@@ -1,4 +1,4 @@
import { Cell, Execution, Game, Player, MutableUnit, PlayerID, TerrainType, UnitType } from "../game/Game";
import { Cell, Execution, Game, Player, Unit, PlayerID, TerrainType, UnitType } from "../game/Game";
import { PathFinder } from "../pathfinding/PathFinding";
import { PathFindResultType } from "../pathfinding/AStar";
import { PseudoRandom } from "../PseudoRandom";
@@ -11,10 +11,10 @@ export class DestroyerExecution implements Execution {
private _owner: Player
private active = true
private destroyer: MutableUnit = null
private destroyer: Unit = null
private mg: Game = null
private target: MutableUnit = null
private target: Unit = null
private pathfinder: PathFinder
private patrolTile: TileRef;
+2 -2
View File
@@ -1,5 +1,5 @@
import { consolex } from "../Consolex";
import { Cell, Execution, Game, Player, MutableUnit, PlayerID, UnitType } from "../game/Game";
import { Cell, Execution, Game, Player, Unit, PlayerID, UnitType } from "../game/Game";
import { TileRef } from "../game/GameMap";
export class MissileSiloExecution implements Execution {
@@ -7,7 +7,7 @@ export class MissileSiloExecution implements Execution {
private active = true
private mg: Game
private player: Player
private silo: MutableUnit
private silo: Unit
constructor(
private _owner: PlayerID,
+2 -2
View File
@@ -1,5 +1,5 @@
import { nextTick } from "process";
import { Cell, Execution, Game, Player, PlayerID, MutableUnit, UnitType, TerraNullius } from "../game/Game";
import { Cell, Execution, Game, Player, PlayerID, Unit, UnitType, TerraNullius } from "../game/Game";
import { PathFinder } from "../pathfinding/PathFinding";
import { PathFindResultType } from "../pathfinding/AStar";
import { PseudoRandom } from "../PseudoRandom";
@@ -14,7 +14,7 @@ export class NukeExecution implements Execution {
private mg: Game
private nuke: MutableUnit
private nuke: Unit
private pathFinder: PathFinder
constructor(
+4 -4
View File
@@ -1,4 +1,4 @@
import { AllPlayers, Cell, Execution, Game, Player, MutableUnit, PlayerID, TerrainType, UnitType } from "../game/Game";
import { AllPlayers, Cell, Execution, Game, Player, Unit, PlayerID, TerrainType, UnitType } from "../game/Game";
import { PathFinder } from "../pathfinding/PathFinding";
import { PathFindResultType } from "../pathfinding/AStar";
import { PseudoRandom } from "../PseudoRandom";
@@ -11,10 +11,10 @@ export class PortExecution implements Execution {
private active = true
private mg: Game
private port: MutableUnit
private port: Unit
private random: PseudoRandom
private portPaths = new Map<MutableUnit, TileRef[]>()
private computingPaths = new Map<MutableUnit, MiniAStar>()
private portPaths = new Map<Unit, TileRef[]>()
private computingPaths = new Map<Unit, MiniAStar>()
constructor(
private _owner: PlayerID,
+3 -3
View File
@@ -1,4 +1,4 @@
import { Execution, Game, Player, MutableUnit, Unit, UnitType } from "../game/Game";
import { Execution, Game, Player, Unit, UnitType } from "../game/Game";
import { PathFinder } from "../pathfinding/PathFinding";
import { PathFindResultType } from "../pathfinding/AStar";
import { consolex } from "../Consolex";
@@ -8,9 +8,9 @@ export class ShellExecution implements Execution {
private active = true
private pathFinder: PathFinder
private shell: MutableUnit
private shell: Unit
constructor(private spawn: TileRef, private _owner: Player, private ownerUnit: Unit, private target: MutableUnit) {
constructor(private spawn: TileRef, private _owner: Player, private ownerUnit: Unit, private target: Unit) {
}
+4 -4
View File
@@ -1,6 +1,6 @@
import { MessageType } from '../game/Game';
import { renderNumber } from "../../client/Utils";
import { AllPlayers, Cell, Execution, Game, MutableUnit, Player, PlayerID, UnitType } from "../game/Game";
import { AllPlayers, Cell, Execution, Game, Unit, Player, PlayerID, UnitType } from "../game/Game";
import { PathFinder } from "../pathfinding/PathFinding";
import { PathFindResultType } from "../pathfinding/AStar";
import { distSortUnit } from "../Util";
@@ -12,14 +12,14 @@ export class TradeShipExecution implements Execution {
private active = true
private mg: Game
private origOwner: Player
private tradeShip: MutableUnit
private tradeShip: Unit
private index = 0
private wasCaptured = false
constructor(
private _owner: PlayerID,
private srcPort: MutableUnit,
private dstPort: MutableUnit,
private srcPort: Unit,
private dstPort: Unit,
private pathFinder: PathFinder,
// don't modify
private path: TileRef[]
+2 -2
View File
@@ -1,4 +1,4 @@
import { Unit, Cell, Execution, MutableUnit, Game, Player, PlayerID, TerraNullius, UnitType, TerrainType } from "../game/Game";
import { Unit, Cell, Execution, Game, Player, PlayerID, TerraNullius, UnitType, TerrainType } from "../game/Game";
import { AttackExecution } from "./AttackExecution";
import { MessageType } from '../game/Game';
import { PathFinder } from "../pathfinding/PathFinding";
@@ -26,7 +26,7 @@ export class TransportShipExecution implements Execution {
private dst: TileRef | null
private boat: MutableUnit
private boat: Unit
private pathFinder: PathFinder
+19 -14
View File
@@ -177,23 +177,28 @@ export interface DefenseBonus {
}
export interface Unit {
// Properties
type(): UnitType
troops(): number
tile(): TileRef
owner(): Player
info(): UnitInfo
// Location
tile(): TileRef
lastTile(): TileRef
move(tile: TileRef): void
// State
isActive(): boolean
hasHealth(): boolean
health(): number
lastTile(): TileRef
}
export interface MutableUnit extends Unit {
move(tile: TileRef): void
owner(): Player
setTroops(troops: number): void
info(): UnitInfo
delete(displayerMessage?: boolean): void
modifyHealth(delta: number): void
// Mutations
setTroops(troops: number): void
delete(displayerMessage?: boolean): void
// Updates
toUpdate(): UnitUpdate
}
@@ -245,10 +250,10 @@ export interface Player {
removeTroops(troops: number): number
// Units
units(...types: UnitType[]): MutableUnit[]
units(...types: UnitType[]): Unit[]
canBuild(type: UnitType, targetTile: TileRef): TileRef | false
buildUnit(type: UnitType, troops: number, tile: TileRef): MutableUnit
captureUnit(unit: MutableUnit): void
buildUnit(type: UnitType, troops: number, tile: TileRef): Unit
captureUnit(unit: Unit): void
// Relations & Diplomacy
neighbors(): (Player | TerraNullius)[]
@@ -317,7 +322,7 @@ export interface Game extends GameMap {
config(): Config
// Units
units(...types: UnitType[]): MutableUnit[]
units(...types: UnitType[]): Unit[]
unitInfo(type: UnitType): UnitInfo
addTileDefenseBonus(tile: TileRef, unit: Unit, amount: number): DefenseBonus
removeTileDefenseBonus(bonus: DefenseBonus): void
+2 -2
View File
@@ -1,4 +1,4 @@
import { Player, PlayerInfo, PlayerID, PlayerType, TerraNullius, Cell, Execution, AllianceRequest, MutableAllianceRequest, MutableAlliance, Alliance, Tick, AllPlayers, Gold, UnitType, Unit, MutableUnit, Relation, PlayerUpdate, GameUpdateType, EmojiMessage } from "./Game";
import { Player, PlayerInfo, PlayerID, PlayerType, TerraNullius, Cell, Execution, AllianceRequest, MutableAllianceRequest, MutableAlliance, Alliance, Tick, AllPlayers, Gold, UnitType, Unit, Relation, PlayerUpdate, GameUpdateType, EmojiMessage } from "./Game";
import { ClientID } from "../Schemas";
import { assertNever, closestOceanShoreFromPlayer, distSortUnit, simpleHash, sourceDstOceanShore, within } from "../Util";
import { CellString, GameImpl } from "./GameImpl";
@@ -425,7 +425,7 @@ export class PlayerImpl implements Player {
return toRemove
}
captureUnit(unit: MutableUnit): void {
captureUnit(unit: Unit): void {
if (unit.owner() == this) {
throw new Error(`Cannot capture unit, ${this} already owns ${unit}`)
}
+2 -2
View File
@@ -1,12 +1,12 @@
import { GameUpdateType, MessageType, UnitUpdate } from './Game';
import { simpleHash, within } from "../Util";
import { MutableUnit, TerraNullius, UnitType, Player, UnitInfo } from "./Game";
import { Unit, TerraNullius, UnitType, Player, UnitInfo } from "./Game";
import { GameImpl } from "./GameImpl";
import { PlayerImpl } from "./PlayerImpl";
import { TileRef } from './GameMap';
export class UnitImpl implements MutableUnit {
export class UnitImpl implements Unit {
private _active = true;
private _health: number
private _lastTile: TileRef = null