fix port ally finding bug, fix transport ship crashing game when target tile not found

This commit is contained in:
Evan
2024-11-20 20:22:51 -08:00
parent 8b391c7ae0
commit 819b8ef23a
4 changed files with 20 additions and 10 deletions
+7
View File
@@ -169,6 +169,13 @@ export class PathFinder {
) { }
nextTile(curr: Tile, dst: Tile, dist: number = 1): TileResult {
if (curr == null) {
console.error('curr is null')
}
if (dst == null) {
console.error('dst is null')
}
if (manhattanDist(curr.cell(), dst.cell()) < dist) {
return { type: PathFindResultType.Completed, tile: curr }
}
+1 -1
View File
@@ -109,7 +109,7 @@ export class FakeHumanExecution implements Execution {
const enemyborder = Array.from(this.player.borderTiles()).flatMap(t => t.neighbors()).filter(t => t.hasOwner() && t.owner() != this.player)
if (enemyborder.length == 0 || this.random.chance(5)) {
if (enemyborder.length == 0 || this.random.chance(1)) {
this.sendBoat()
return
}
+5 -6
View File
@@ -54,7 +54,7 @@ export class PortExecution implements Execution {
for (const port of allPorts) {
if (this.computingPaths.has(port)) {
const aStar = this.computingPaths.get(port)
switch(aStar.compute()) {
switch (aStar.compute()) {
case PathFindResultType.Completed:
this.portPaths.set(port, aStar.reconstructPath())
this.computingPaths.delete(port)
@@ -76,11 +76,10 @@ export class PortExecution implements Execution {
}
}
if (this.portPaths.size > 0 && this.random.chance(50)) {
const port = this.random.randElement(
Array.from(this.portPaths.keys())
.filter(p => this.port.owner().isAlliedWith(p.owner()))
)
const allyPorts = Array.from(this.portPaths.keys())
.filter(p => this.port.owner().isAlliedWith(p.owner()))
if (allPorts.length > 0 && this.random.chance(50)) {
const port = this.random.randElement(allPorts)
const path = this.portPaths.get(port)
this.mg.addExecution(new TradeShipExecution(this._owner, this.port, port, path))
}
+7 -3
View File
@@ -63,8 +63,13 @@ export class TransportShipExecution implements Execution {
this.troops = Math.min(this.troops, this.attacker.troops())
const dstTile = targetTransportTile(this.mg, this.mg.tile(this.cell))
const src = this.attacker.canBuild(UnitType.TransportShip, dstTile)
this.dst = targetTransportTile(this.mg, this.mg.tile(this.cell))
if (this.dst == null) {
console.warn(`${this.attacker} cannot send ship to ${this.target}, cannot find attack tile`)
this.active = false
return
}
const src = this.attacker.canBuild(UnitType.TransportShip, this.dst)
if (src == false) {
console.warn(`can't build transport ship`)
this.active = false
@@ -72,7 +77,6 @@ export class TransportShipExecution implements Execution {
}
this.src = src
this.dst = dstTile
this.boat = this.attacker.buildUnit(UnitType.TransportShip, this.troops, this.src)
}