destroyer moves upwards

This commit is contained in:
Evan
2024-11-10 19:50:57 -08:00
parent c7951d77c0
commit 975750b294
5 changed files with 64 additions and 44 deletions
+8 -2
View File
@@ -1,7 +1,7 @@
import { Colord } from "colord"; import { Colord } from "colord";
import { Theme } from "../../../core/configuration/Config"; import { Theme } from "../../../core/configuration/Config";
import { Unit, UnitEvent, Cell, Game, Tile, UnitType } from "../../../core/game/Game"; import { Unit, UnitEvent, Cell, Game, Tile, UnitType } from "../../../core/game/Game";
import { bfs, dist } from "../../../core/Util"; import { bfs, dist, euclDist } from "../../../core/Util";
import { Layer } from "./Layer"; import { Layer } from "./Layer";
import { EventBus } from "../../../core/EventBus"; import { EventBus } from "../../../core/EventBus";
@@ -72,7 +72,13 @@ export class UnitLayer implements Layer {
} }
private handleDestroyerEvent(event: UnitEvent) { private handleDestroyerEvent(event: UnitEvent) {
bfs(event.oldTile, euclDist(event.oldTile, 3)).forEach(t => {
this.clearCell(t.cell())
})
bfs(event.unit.tile(), euclDist(event.unit.tile(), 3))
.forEach(t => this.paintCell(t.cell(), this.theme.borderColor(event.unit.owner().info()), 255))
bfs(event.unit.tile(), euclDist(event.unit.tile(), 2))
.forEach(t => this.paintCell(t.cell(), this.theme.territoryColor(event.unit.owner().info()), 180))
} }
private handleBoatEvent(event: UnitEvent) { private handleBoatEvent(event: UnitEvent) {
+4
View File
@@ -30,6 +30,10 @@ export function within(value: number, min: number, max: number): number {
return Math.min(Math.max(value, min), max); return Math.min(Math.max(value, min), max);
} }
export function euclDist(root: Tile, dist: number): (tile: Tile) => boolean {
return (n: Tile) => euclideanDist(root.cell(), n.cell()) <= dist;
}
export function dist(root: Tile, dist: number): (tile: Tile) => boolean { export function dist(root: Tile, dist: number): (tile: Tile) => boolean {
return (n: Tile) => manhattanDist(root.cell(), n.cell()) <= dist; return (n: Tile) => manhattanDist(root.cell(), n.cell()) <= dist;
} }
+2
View File
@@ -21,7 +21,9 @@ export class DestroyerExecution implements Execution {
tick(ticks: number): void { tick(ticks: number): void {
if (this.destroyer == null) { if (this.destroyer == null) {
this.destroyer = this._owner.addUnit(UnitType.Destroyer, 0, this.mg.tile(this.cell)) this.destroyer = this._owner.addUnit(UnitType.Destroyer, 0, this.mg.tile(this.cell))
return
} }
this.destroyer.move(this.destroyer.tile().neighbors()[0])
} }
owner(): MutablePlayer { owner(): MutablePlayer {
+49 -41
View File
@@ -16,6 +16,7 @@ import { EmojiExecution } from "./EmojiExecution";
import { DonateExecution } from "./DonateExecution"; import { DonateExecution } from "./DonateExecution";
import { NukeExecution } from "./NukeExecution"; import { NukeExecution } from "./NukeExecution";
import { SetTargetTroopRatioExecution } from "./SetTargetTroopRatioExecution"; import { SetTargetTroopRatioExecution } from "./SetTargetTroopRatioExecution";
import { DestroyerExecution } from "./DestroyerExecution";
@@ -36,50 +37,57 @@ export class Executor {
} }
createExec(intent: Intent): Execution { createExec(intent: Intent): Execution {
if (intent.type == "attack") { switch (intent.type) {
const source: Cell | null = intent.sourceX != null && intent.sourceY != null ? new Cell(intent.sourceX, intent.sourceY) : null case "attack": {
const target: Cell | null = intent.targetX != null && intent.targetY != null ? new Cell(intent.targetX, intent.targetY) : null const source: Cell | null = intent.sourceX != null && intent.sourceY != null
return new AttackExecution( ? new Cell(intent.sourceX, intent.sourceY)
intent.troops, : null;
intent.attackerID, const target: Cell | null = intent.targetX != null && intent.targetY != null
intent.targetID, ? new Cell(intent.targetX, intent.targetY)
source, : null;
target, return new AttackExecution(
) intent.troops,
} else if (intent.type == "spawn") { intent.attackerID,
return new SpawnExecution( intent.targetID,
new PlayerInfo(sanitize(intent.name), intent.playerType, intent.clientID, intent.playerID), source,
new Cell(intent.x, intent.y) target,
) );
} else if (intent.type == "boat") { }
return new TransportShipExecution( case "spawn":
intent.attackerID, return new SpawnExecution(
intent.targetID, new PlayerInfo(sanitize(intent.name), intent.playerType, intent.clientID, intent.playerID),
new Cell(intent.x, intent.y), new Cell(intent.x, intent.y)
intent.troops );
) case "boat":
} else if (intent.type == "allianceRequest") { return new TransportShipExecution(
return new AllianceRequestExecution(intent.requestor, intent.recipient) intent.attackerID,
} else if (intent.type == "allianceRequestReply") { intent.targetID,
return new AllianceRequestReplyExecution(intent.requestor, intent.recipient, intent.accept) new Cell(intent.x, intent.y),
} else if (intent.type == "breakAlliance") { intent.troops
return new BreakAllianceExecution(intent.requestor, intent.recipient) );
} else if (intent.type == "targetPlayer") { case "allianceRequest":
return new TargetPlayerExecution(intent.requestor, intent.target) return new AllianceRequestExecution(intent.requestor, intent.recipient);
} else if (intent.type == "emoji") { case "allianceRequestReply":
return new EmojiExecution(intent.sender, intent.recipient, intent.emoji) return new AllianceRequestReplyExecution(intent.requestor, intent.recipient, intent.accept);
} else if (intent.type == "donate") { case "breakAlliance":
return new DonateExecution(intent.sender, intent.recipient, intent.troops) return new BreakAllianceExecution(intent.requestor, intent.recipient);
} else if (intent.type == "nuke") { case "targetPlayer":
return new NukeExecution(intent.sender, new Cell(intent.x, intent.y), intent.magnitude) return new TargetPlayerExecution(intent.requestor, intent.target);
} else if (intent.type == "troop_ratio") { case "emoji":
return new SetTargetTroopRatioExecution(intent.player, intent.ratio) return new EmojiExecution(intent.sender, intent.recipient, intent.emoji);
} else { case "donate":
throw new Error(`intent type ${intent} not found`) return new DonateExecution(intent.sender, intent.recipient, intent.troops);
case "nuke":
return new NukeExecution(intent.sender, new Cell(intent.x, intent.y), intent.magnitude);
case "troop_ratio":
return new SetTargetTroopRatioExecution(intent.player, intent.ratio);
case "create_destroyer":
return new DestroyerExecution(intent.player, new Cell(intent.x, intent.y))
default:
throw new Error(`intent type ${intent} not found`);
} }
} }
spawnBots(numBots: number): Execution[] { spawnBots(numBots: number): Execution[] {
return new BotSpawner(this.gs, this.gameID).spawnBots(numBots).map(i => this.createExec(i)) return new BotSpawner(this.gs, this.gameID).spawnBots(numBots).map(i => this.createExec(i))
} }
+1 -1
View File
@@ -36,7 +36,7 @@ export class Item {
export const Items = { export const Items = {
Nuke: new Item("Nuke", 1_000_000), Nuke: new Item("Nuke", 1_000_000),
Destroyer: new Item("Destroyer", 100_000) Destroyer: new Item("Destroyer", 10)
} as const; } as const;
export class Nation { export class Nation {