From 088e3a41ff28f07b9f2b4f19ba6c1dd385f02ddb Mon Sep 17 00:00:00 2001 From: evanpelle Date: Wed, 2 Oct 2024 17:34:28 -0700 Subject: [PATCH] no attack if not connected to the empty land. --- TODO.txt | 2 +- src/client/ClientGame.ts | 17 ++++++++++++----- src/client/graphics/layers/RadialMenu.ts | 17 ++++++++++++++--- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/TODO.txt b/TODO.txt index c9050c070..5319da25a 100644 --- a/TODO.txt +++ b/TODO.txt @@ -153,7 +153,7 @@ * make create/break alliance single button DONE 10/1/2024 * add request attack other players DONE 10/2/2024 * Improve alliance icon DONE 10/2/2024 -* BUG: center button should be disabled select island +* BUG: center button should be disabled select island DONE 10/2/2024 * BUG: boat icon appears when click inland * BUG: double tap zooms on mobile * Make fake humans spawn by their country diff --git a/src/client/ClientGame.ts b/src/client/ClientGame.ts index 82de4cf8a..dbd9e4cca 100644 --- a/src/client/ClientGame.ts +++ b/src/client/ClientGame.ts @@ -169,11 +169,18 @@ export class ClientGame { } if (tile.isLand()) { - for (const border of this.myPlayer.borderTiles()) { - for (const n of border.neighbors()) { - if (n.owner() == tile.owner()) { - this.eventBus.emit(new SendAttackIntentEvent(targetID)) - return + if (tile.hasOwner()) { + if (this.myPlayer.sharesBorderWith(tile.owner())) { + this.eventBus.emit(new SendAttackIntentEvent(targetID)) + } + } else { + + outer_loop: for (const t of bfs(tile, and(t => !t.hasOwner() && t.isLand(), dist(tile, 200)))) { + for (const n of t.neighbors()) { + if (n.owner() == this.myPlayer) { + this.eventBus.emit(new SendAttackIntentEvent(targetID)) + break outer_loop + } } } } diff --git a/src/client/graphics/layers/RadialMenu.ts b/src/client/graphics/layers/RadialMenu.ts index a0b7c046e..ab75fd27c 100644 --- a/src/client/graphics/layers/RadialMenu.ts +++ b/src/client/graphics/layers/RadialMenu.ts @@ -1,7 +1,7 @@ import {EventBus} from "../../../core/EventBus"; import {Cell, Game, Player, PlayerID} from "../../../core/game/Game"; import {ClientID} from "../../../core/Schemas"; -import {manhattanDist, manhattanDistWrapped, sourceDstOceanShore} from "../../../core/Util"; +import {and, bfs, dist, manhattanDist, manhattanDistWrapped, sourceDstOceanShore} from "../../../core/Util"; import {ContextMenuEvent, MouseUpEvent} from "../../InputHandler"; import {SendAllianceRequestIntentEvent, SendAttackIntentEvent, SendBoatAttackIntentEvent, SendBreakAllianceIntentEvent, SendSpawnIntentEvent, SendTargetPlayerIntentEvent} from "../../Transport"; import {TransformHandler} from "../TransformHandler"; @@ -231,8 +231,19 @@ export class RadialMenu implements Layer { } if (tile.owner() != myPlayer && tile.isLand() && myPlayer.sharesBorderWith(other)) { - if (!other.isPlayer() || !myPlayer.isAlliedWith(other)) { - this.renderCenterButton(true) + if (other.isPlayer()) { + if (!myPlayer.isAlliedWith(other)) { + this.renderCenterButton(true) + } + } else { + outer_loop: for (const t of bfs(tile, and(t => !t.hasOwner() && t.isLand(), dist(tile, 200)))) { + for (const n of t.neighbors()) { + if (n.owner() == myPlayer) { + this.renderCenterButton(true) + break outer_loop + } + } + } } }