fix boat bug

This commit is contained in:
evanpelle
2024-08-12 17:05:02 -07:00
parent a4799a3c21
commit fc562533e1
5 changed files with 15 additions and 5 deletions
+1 -1
View File
@@ -163,7 +163,7 @@ export class ClientGame {
if (tile.owner() != this.myPlayer && tile.terrain() == TerrainTypes.Land) {
if (this.myPlayer.sharesBorderWith(tile.owner())) {
this.sendAttackIntent(targetID, cell, this.config.player().attackAmount(this.myPlayer, owner))
} else {
} else if (owner.isPlayer()) {
// TODO verify on ocean
console.log('going to send boat')
this.sendBoatAttackIntent(targetID, cell, this.config.player().boatAttackAmount(this.myPlayer, owner))
+2 -2
View File
@@ -4,7 +4,7 @@ import {pastelTheme} from "./PastelTheme";
export const defaultConfig = new class implements Config {
player(): PlayerConfig {
throw new Error("Method not implemented.");
return defaultPlayerConfig
}
ticksPerTurn(): number {
@@ -49,7 +49,7 @@ export const defaultPlayerConfig = new class implements PlayerConfig {
const ratio = 1 - player.troops() / max
toAdd *= ratio * ratio * ratio
toAdd = Math.max(2, toAdd)
return Math.min(player.troops(), max)
return Math.min(player.troops() + toAdd, max)
}
attackLogic(attack: Player, defender: Player | TerraNullius): number {
+1
View File
@@ -64,6 +64,7 @@ export class AttackExecution implements Execution {
badTiles++
continue
}
// TODO: move this to configs
this._owner.conquer(tileToConquer)
if (this.target.isPlayer()) {
this.troops -= Math.max(this.target.troops() / this._owner.troops(), 1)
+10 -1
View File
@@ -47,6 +47,12 @@ export class BoatAttackExecution implements Execution {
this.src = this.closestShoreTileToTarget(this.attacker, this.cell)
this.dst = this.closestShoreTileToTarget(this.target, this.cell)
if(this.src == null || this.dst == null) {
this.active = false
return
}
this.path = this.computePath(this.src, this.dst)
if (this.path != null) {
console.log(`got path ${this.path.map(t => t.cell().toString())}`)
@@ -91,8 +97,11 @@ export class BoatAttackExecution implements Execution {
return this.active
}
private closestShoreTileToTarget(player: Player, target: Cell): Tile {
private closestShoreTileToTarget(player: Player, target: Cell): Tile | null {
const shoreTiles = Array.from(player.borderTiles()).filter(t => t.onShore())
if (shoreTiles.length == 0) {
return null
}
return shoreTiles.reduce((closest, current) => {
const closestDistance = manhattanDist(target, closest.cell());