reimplement defense posts

This commit is contained in:
Evan
2025-02-08 09:56:07 -08:00
parent 741931b7a2
commit 0487509c03
12 changed files with 206 additions and 88 deletions
+1 -24
View File
@@ -1,7 +1,6 @@
import { consolex } from "../Consolex";
import {
Cell,
DefenseBonus,
Execution,
Game,
Player,
@@ -17,12 +16,7 @@ export class DefensePostExecution implements Execution {
private post: Unit;
private active: boolean = true;
private defenseBonuses: DefenseBonus[] = [];
constructor(
private ownerId: PlayerID,
private tile: TileRef,
) {}
constructor(private ownerId: PlayerID, private tile: TileRef) {}
init(mg: Game, ticks: number): void {
this.mg = mg;
@@ -38,25 +32,8 @@ export class DefensePostExecution implements Execution {
return;
}
this.post = this.player.buildUnit(UnitType.DefensePost, 0, spawnTile);
this.mg
.bfs(
spawnTile,
manhattanDistFN(spawnTile, this.mg.config().defensePostRange()),
)
.forEach((t) => {
if (this.mg.isLake(t)) {
this.defenseBonuses.push(
this.mg.addTileDefenseBonus(
t,
this.post,
this.mg.config().defensePostDefenseBonus(),
),
);
}
});
}
if (!this.post.isActive()) {
this.defenseBonuses.forEach((df) => this.mg.removeTileDefenseBonus(df));
this.active = false;
return;
}