nukes destroy boats

This commit is contained in:
evanpelle
2024-10-19 19:48:56 -07:00
parent 0a266f5ef8
commit 1a34462f66
4 changed files with 18 additions and 9 deletions
@@ -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
}
+8 -9
View File
@@ -8,8 +8,6 @@ export class NukeExecution implements Execution {
private active = true
private toDestroy: Set<Tile> = 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
}
+2
View File
@@ -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 {
+4
View File
@@ -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_
}