create territoryBound, have player execution check units for capture

fix bug where PortExecution tries to get random element from empty list and crashes
This commit is contained in:
evanpelle
2024-11-17 19:56:54 -08:00
parent 371a33b406
commit 108fad8096
7 changed files with 50 additions and 25 deletions
+1 -12
View File
@@ -46,17 +46,6 @@ export class PortExecution implements Execution {
this.port = this.player.buildUnit(UnitType.Port, 0, spawns[0])
}
if (!this.port.tile().hasOwner()) {
this.port.delete()
this.active = false
return
}
if (this.port.tile().owner() != this.port.owner()) {
this.port.setOwner(this.port.tile().owner() as Player)
this.player = this.port.owner()
}
const allPorts = this.mg.units(UnitType.Port)
.filter(u => u.owner() != this.player)
if (allPorts.length == 0) {
@@ -82,7 +71,7 @@ export class PortExecution implements Execution {
}
}
if (this.random.chance(50)) {
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()))