diff --git a/src/core/execution/BoatAttackExecution.ts b/src/core/execution/BoatAttackExecution.ts index 53f4478ab..8ab708fde 100644 --- a/src/core/execution/BoatAttackExecution.ts +++ b/src/core/execution/BoatAttackExecution.ts @@ -98,6 +98,10 @@ export class BoatAttackExecution implements Execution { if (!this.active) { return } + if (!this.boat.isActive()) { + this.active = false + return + } if (ticks - this.lastMove < this.ticksPerMove) { return } diff --git a/src/core/execution/NukeExecution.ts b/src/core/execution/NukeExecution.ts index 281111c9b..951ecaa26 100644 --- a/src/core/execution/NukeExecution.ts +++ b/src/core/execution/NukeExecution.ts @@ -8,8 +8,6 @@ export class NukeExecution implements Execution { private active = true - private toDestroy: Set = new Set() - private mg: MutableGame constructor( @@ -25,17 +23,17 @@ export class NukeExecution implements Execution { if (this.magnitude == null) { this.magnitude = 70 } - const rand = new PseudoRandom(mg.ticks()) - const tile = mg.tile(this.cell) - this.toDestroy = bfs(tile, (n: Tile) => { + } + + tick(ticks: number): void { + const rand = new PseudoRandom(this.mg.ticks()) + const tile = this.mg.tile(this.cell) + const toDestroy = bfs(tile, (n: Tile) => { const d = euclideanDist(tile.cell(), n.cell()) return (d <= this.magnitude || rand.chance(2)) && d <= this.magnitude + 30 }) - } - - tick(ticks: number): void { - for (const tile of this.toDestroy) { + for (const tile of toDestroy) { const owner = tile.owner() if (owner.isPlayer()) { const mp = this.mg.player(owner.id()) @@ -43,6 +41,7 @@ export class NukeExecution implements Execution { mp.removeTroops(mp.troops() / mp.numTilesOwned()) } } + this.mg.boats().filter(b => euclideanDist(this.cell, b.tile().cell()) < this.magnitude).forEach(b => b.delete()) this.active = false } diff --git a/src/core/game/Game.ts b/src/core/game/Game.ts index 0fd090902..45075b128 100644 --- a/src/core/game/Game.ts +++ b/src/core/game/Game.ts @@ -233,6 +233,7 @@ export interface Game { nations(): Nation[] config(): Config displayMessage(message: string, type: MessageType, playerID: PlayerID | null): void + boats(): Boat[] } export interface MutableGame extends Game { @@ -241,6 +242,7 @@ export interface MutableGame extends Game { players(): MutablePlayer[] addPlayer(playerInfo: PlayerInfo, troops: number): MutablePlayer executions(): Execution[] + boats(): MutableBoat[] } export class TileEvent implements GameEvent { diff --git a/src/core/game/GameImpl.ts b/src/core/game/GameImpl.ts index 79e298f03..5fcf060fa 100644 --- a/src/core/game/GameImpl.ts +++ b/src/core/game/GameImpl.ts @@ -10,6 +10,7 @@ import {AllianceRequestImpl} from "./AllianceRequestImpl"; import {AllianceImpl} from "./AllianceImpl"; import {ClientID} from "../Schemas"; import {DisplayMessageEvent, MessageType} from "../../client/graphics/layers/EventsDisplay"; +import {BoatImpl} from "./BoatImpl"; export function createGame(terrainMap: TerrainMap, eventBus: EventBus, config: Config): Game { return new GameImpl(terrainMap, eventBus, config) @@ -57,6 +58,9 @@ export class GameImpl implements MutableGame { n.strength )) } + boats(): BoatImpl[] { + return Array.from(this._players.values()).flatMap(p => p._boats) + } nations(): Nation[] { return this.nations_ }