add missile silo

This commit is contained in:
Evan
2024-11-16 11:45:28 -08:00
parent 006539455d
commit e26230275b
11 changed files with 240 additions and 42 deletions
+3
View File
@@ -18,6 +18,7 @@ import { NukeExecution } from "./NukeExecution";
import { SetTargetTroopRatioExecution } from "./SetTargetTroopRatioExecution";
import { DestroyerExecution } from "./DestroyerExecution";
import { PortExecution } from "./PortExecution";
import { MissileSiloExecution } from "./MissileSiloExecution";
@@ -88,6 +89,8 @@ export class Executor {
return new DestroyerExecution(intent.player, new Cell(intent.x, intent.y))
case UnitType.Port:
return new PortExecution(intent.player, new Cell(intent.x, intent.y))
case UnitType.MissileSilo:
return new MissileSiloExecution(intent.player, new Cell(intent.x, intent.y))
default:
throw Error(`unit type ${intent.unit} not supported`)
}
@@ -0,0 +1,60 @@
import { BuildValidator } from "../game/BuildValidator";
import { AllPlayers, BuildItem, BuildItems, Cell, Execution, MutableGame, MutablePlayer, MutableUnit, Player, PlayerID, Tile, Unit, UnitType } from "../game/Game";
import { AStar, PathFinder } from "../PathFinding";
import { PseudoRandom } from "../PseudoRandom";
import { bfs, dist, manhattanDist } from "../Util";
import { TradeShipExecution } from "./TradeShipExecution";
export class MissileSiloExecution implements Execution {
private active = true
private mg: MutableGame
private player: MutablePlayer
private silo: MutableUnit
constructor(
private _owner: PlayerID,
private cell: Cell
) { }
init(mg: MutableGame, ticks: number): void {
this.mg = mg
this.player = mg.player(this._owner)
}
tick(ticks: number): void {
if (this.silo == null) {
const tile = this.mg.tile(this.cell)
if (!new BuildValidator(this.mg).canBuild(this.player, tile, BuildItems.MissileSilo)) {
console.warn(`player ${this.player} cannot build port at ${this.cell}`)
this.active = false
return
}
this.silo = this.player.addUnit(UnitType.MissileSilo, 0, tile)
}
if (!this.silo.tile().hasOwner()) {
this.silo.delete()
this.active = false
return
}
if (this.silo.tile().owner() != this.silo.owner()) {
this.silo.setOwner(this.silo.tile().owner() as Player)
this.player = this.silo.owner()
}
}
owner(): MutablePlayer {
return null
}
isActive(): boolean {
return this.active
}
activeDuringSpawnPhase(): boolean {
return false
}
}
+1
View File
@@ -55,6 +55,7 @@ export class PortExecution implements Execution {
}
if (this.port.tile().owner() != this.port.owner()) {
this.port.setOwner(this.port.tile().owner() as Player)
this.player = this.port.owner()
}
const allPorts = this.mg.units(UnitType.Port)