diff --git a/src/client/ClientGameRunner.ts b/src/client/ClientGameRunner.ts index c03820c2f..f4f6f119e 100644 --- a/src/client/ClientGameRunner.ts +++ b/src/client/ClientGameRunner.ts @@ -423,7 +423,7 @@ export class ClientGameRunner { this.myPlayer.troops() * this.renderer.uiState.attackRatio, ), ); - } else if (this.canBoatAttack(actions, tile)) { + } else if (this.canAutoBoat(actions, tile)) { this.sendBoatAttackIntent(tile); } @@ -519,7 +519,7 @@ export class ClientGameRunner { } this.myPlayer.actions(tile).then((actions) => { - if (!actions.canAttack && this.canBoatAttack(actions, tile)) { + if (this.canBoatAttack(actions) !== false) { this.sendBoatAttackIntent(tile); } }); @@ -567,7 +567,7 @@ export class ClientGameRunner { return this.gameView.ref(cell.x, cell.y); } - private canBoatAttack(actions: PlayerActions, tile: TileRef): boolean { + private canBoatAttack(actions: PlayerActions): false | TileRef { const bu = actions.buildableUnits.find( (bu) => bu.type === UnitType.TransportShip, ); @@ -575,11 +575,7 @@ export class ClientGameRunner { console.warn(`no transport ship buildable units`); return false; } - return ( - bu.canBuild !== false && - this.shouldBoat(tile, bu.canBuild) && - this.gameView.isLand(tile) - ); + return bu.canBuild; } private sendBoatAttackIntent(tile: TileRef) { @@ -598,16 +594,20 @@ export class ClientGameRunner { }); } - private shouldBoat(tile: TileRef, src: TileRef) { + private canAutoBoat(actions: PlayerActions, tile: TileRef): boolean { + if (!this.gameView.isLand(tile)) return false; + + const canBuild = this.canBoatAttack(actions); + if (canBuild === false) return false; + // TODO: Global enable flag // TODO: Global limit autoboat to nearby shore flag // if (!enableAutoBoat) return false; // if (!limitAutoBoatNear) return true; - const distanceSquared = this.gameView.euclideanDistSquared(tile, src); + const distanceSquared = this.gameView.euclideanDistSquared(tile, canBuild); const limit = 100; const limitSquared = limit * limit; - if (distanceSquared > limitSquared) return false; - return true; + return distanceSquared < limitSquared; } private onMouseMove(event: MouseMoveEvent) {