add defense post unit (no execution)

This commit is contained in:
Evan
2024-11-30 20:54:42 -08:00
parent 7ff0509b40
commit e7039d3e07
13 changed files with 126 additions and 8 deletions
+5
View File
@@ -64,6 +64,11 @@ export class DefaultConfig implements Config {
cost: () => 1_000_000,
territoryBound: true
}
case UnitType.DefensePost:
return {
cost: (p: Player) => Math.pow(2, p.units(UnitType.Port).length) * 100_000,
territoryBound: true
}
default:
assertNever(type)
}
+1 -1
View File
@@ -5,7 +5,7 @@ export const devConfig = new class extends DefaultConfig {
unitInfo(type: UnitType): UnitInfo {
const info = super.unitInfo(type)
const oldCost = info.cost
// info.cost = (p: Player) => oldCost(p) / 1000
info.cost = (p: Player) => oldCost(p) / 1000
return info
}
@@ -0,0 +1,43 @@
import { Cell, Execution, MutableGame, MutablePlayer, MutableUnit, PlayerID, Tile, UnitType } from "../game/Game";
export class DefensePostExecution implements Execution {
private player: MutablePlayer
private mg: MutableGame
private post: MutableUnit
private tile: Tile
private active: boolean = true
constructor(private ownerId: PlayerID, private cell: Cell) { }
init(mg: MutableGame, ticks: number): void {
this.mg = mg
this.tile = mg.tile(this.cell)
this.player = mg.player(this.ownerId)
}
tick(ticks: number): void {
if (this.post == null) {
const spawnTile = this.player.canBuild(UnitType.DefensePost, this.tile)
if (spawnTile == false) {
console.warn('cannot build Defense Post')
this.active = false
return
}
this.post = this.player.buildUnit(UnitType.DefensePost, 0, spawnTile)
}
}
owner(): MutablePlayer {
return null
}
isActive(): boolean {
return this.active
}
activeDuringSpawnPhase(): boolean {
return false
}
}
+3
View File
@@ -22,6 +22,7 @@ import { MissileSiloExecution } from "./MissileSiloExecution";
import { BattleshipExecution } from "./BattleshipExecution";
import { PathFinder } from "../pathfinding/PathFinding";
import { WorkerClient } from "../worker/WorkerClient";
import { DefensePostExecution } from "./DefensePostExecution";
@@ -97,6 +98,8 @@ export class Executor {
return new PortExecution(intent.player, new Cell(intent.x, intent.y), this.workerClient)
case UnitType.MissileSilo:
return new MissileSiloExecution(intent.player, new Cell(intent.x, intent.y))
case UnitType.DefensePost:
return new DefensePostExecution(intent.player, new Cell(intent.x, intent.y))
default:
throw Error(`unit type ${intent.unit} not supported`)
}
+1
View File
@@ -31,6 +31,7 @@ export class PortExecution implements Execution {
tick(ticks: number): void {
if (this.port == null) {
// TODO: use canBuild
const tile = this.mg.tile(this.cell)
const player = this.mg.player(this._owner)
if (!player.canBuild(UnitType.Port, tile)) {
+1
View File
@@ -39,6 +39,7 @@ export enum UnitType {
HydrogenBomb = "Hydrogen Bomb",
TradeShip = "Trade Ship",
MissileSilo = "Missile Silo",
DefensePost = "Defense Post"
}
export class Nation {
+4 -2
View File
@@ -365,7 +365,9 @@ export class PlayerImpl implements MutablePlayer {
case UnitType.Shell:
return targetTile
case UnitType.MissileSilo:
return this.missileSiloSpawn(targetTile)
return this.landBasedStructureSpawn(targetTile)
case UnitType.DefensePost:
return this.landBasedStructureSpawn(targetTile)
case UnitType.TransportShip:
return this.transportShipSpawn(targetTile)
case UnitType.TradeShip:
@@ -406,7 +408,7 @@ export class PlayerImpl implements MutablePlayer {
return spawns[0].tile()
}
missileSiloSpawn(tile: Tile): Tile | false {
landBasedStructureSpawn(tile: Tile): Tile | false {
if (tile.owner() != this) {
return false
}