adding destroyer

This commit is contained in:
evanpelle
2024-11-10 18:28:21 -08:00
committed by Evan
parent 6a1a09c335
commit c7951d77c0
16 changed files with 249 additions and 42 deletions
+39
View File
@@ -0,0 +1,39 @@
import { AllPlayers, Cell, Execution, MutableGame, MutablePlayer, MutableUnit, PlayerID, UnitType } from "../game/Game";
export class DestroyerExecution implements Execution {
private _owner: MutablePlayer
private active = true
private destroyer: MutableUnit = null
private mg: MutableGame = null
constructor(
private playerID: PlayerID,
private cell: Cell,
) { }
init(mg: MutableGame, ticks: number): void {
this._owner = mg.player(this.playerID)
this.mg = mg
}
tick(ticks: number): void {
if (this.destroyer == null) {
this.destroyer = this._owner.addUnit(UnitType.Destroyer, 0, this.mg.tile(this.cell))
}
}
owner(): MutablePlayer {
return null
}
isActive(): boolean {
return this.active
}
activeDuringSpawnPhase(): boolean {
return false
}
}
+2 -2
View File
@@ -3,7 +3,7 @@ import { AttackIntent, BoatAttackIntentSchema, GameID, Intent, Turn } from "../S
import { AttackExecution } from "./AttackExecution";
import { SpawnExecution } from "./SpawnExecution";
import { BotSpawner } from "./BotSpawner";
import { BoatAttackExecution } from "./BoatAttackExecution";
import { TransportShipExecution } from "./TransportShipExecution";
import { PseudoRandom } from "../PseudoRandom";
import { FakeHumanExecution } from "./FakeHumanExecution";
import Usernames from '../../../resources/Usernames.txt'
@@ -52,7 +52,7 @@ export class Executor {
new Cell(intent.x, intent.y)
)
} else if (intent.type == "boat") {
return new BoatAttackExecution(
return new TransportShipExecution(
intent.attackerID,
intent.targetID,
new Cell(intent.x, intent.y),
+2 -2
View File
@@ -2,7 +2,7 @@ import { Cell, Execution, MutableGame, MutablePlayer, Player, PlayerInfo, Player
import { PseudoRandom } from "../PseudoRandom"
import { and, bfs, dist, simpleHash } from "../Util";
import { AttackExecution } from "./AttackExecution";
import { BoatAttackExecution } from "./BoatAttackExecution";
import { TransportShipExecution } from "./TransportShipExecution";
import { SpawnExecution } from "./SpawnExecution";
export class FakeHumanExecution implements Execution {
@@ -194,7 +194,7 @@ export class FakeHumanExecution implements Execution {
continue
}
this.mg.addExecution(new BoatAttackExecution(
this.mg.addExecution(new TransportShipExecution(
this.player.id(),
dst.hasOwner() ? dst.owner().id() : null,
dst.cell(),
+3 -1
View File
@@ -48,7 +48,9 @@ export class NukeExecution implements Execution {
mp.removeTroops(mp.troops() / mp.numTilesOwned())
}
}
this.mg.boats().filter(b => euclideanDist(this.cell, b.tile().cell()) < this.magnitude + 50).forEach(b => b.delete())
this.mg.units()
.filter(b => euclideanDist(this.cell, b.tile().cell()) < this.magnitude + 50)
.forEach(b => b.delete())
this.active = false
}
@@ -4,7 +4,7 @@ import { and, bfs, manhattanDistWrapped, sourceDstOceanShore } from "../Util";
import { AttackExecution } from "./AttackExecution";
import { DisplayMessageEvent, MessageType } from "../../client/graphics/layers/EventsDisplay";
export class BoatAttackExecution implements Execution {
export class TransportShipExecution implements Execution {
private lastMove: number
@@ -86,7 +86,7 @@ export class BoatAttackExecution implements Execution {
this.aStarPre.compute(5)
this.path = this.aStarPre.reconstructPath()
if (this.path != null) {
this.boat = this.attacker.addBoat(this.troops, this.src, this.target)
this.boat = this.attacker.addUnit(UnitType.TransportShip, this.troops, this.src)
} else {
console.log('got null path')
this.active = false
@@ -126,7 +126,9 @@ export class BoatAttackExecution implements Execution {
this.target.addTroops(this.troops)
} else {
this.attacker.conquer(this.dst)
this.mg.addExecution(new AttackExecution(this.troops, this.attacker.id(), this.targetID, this.dst.cell(), null, false))
this.mg.addExecution(
new AttackExecution(this.troops, this.attacker.id(), this.targetID, this.dst.cell(), null, false)
)
}
this.boat.delete()
this.active = false