From 54a6fc5e8c91bb502b2a1f32fc4adde7c0dea748 Mon Sep 17 00:00:00 2001 From: "Fabian @ Blax Software" Date: Fri, 30 Oct 2026 11:14:49 +0100 Subject: [PATCH] feat: map.view tells until when an own command can be called back (cancel_until), so the map can offer it Co-Authored-By: Claude Opus 5.5 (1M context) --- app/Actions/ShowMap.php | 6 +++++- docs/architecture.md | 2 +- tests/Feature/MapRelationsTest.php | 12 ++++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/app/Actions/ShowMap.php b/app/Actions/ShowMap.php index 567f6dc..2615da1 100644 --- a/app/Actions/ShowMap.php +++ b/app/Actions/ShowMap.php @@ -109,6 +109,7 @@ final class ShowMap private function movements(Player $me, World $world, CarbonImmutable $now): array { $size = new GroupSize($world->gameConfig()); + $window = (int) $world->gameConfig()->get('movement.cancel_window', 600); $mine = Village::where('player_id', $me->id)->pluck('id'); return Movement::with(['origin:id,name,x,y', 'target:id,name,x,y']) @@ -117,8 +118,9 @@ final class ShowMap ->orWhere(fn ($q) => $q->whereIn('target_id', $mine)->where('type', '!=', Movement::RETURN)->where('visible_at', '<=', Engine::stamp($now)))) ->where('arrives_at', '>', Engine::stamp($now)) ->orderBy('arrives_at')->limit(300)->get() - ->map(function (Movement $m) use ($me, $size) { + ->map(function (Movement $m) use ($me, $size, $window, $now) { $own = $m->player_id === $me->id; + $cancelUntil = $m->sent_at->addSeconds($window); return [ 'id' => $m->id, @@ -131,6 +133,8 @@ final class ShowMap 'arrives_at' => self::iso($m->arrives_at), 'size' => $size->tier($m->units), 'units' => $own ? $m->units : null, + // An own attack or support can be called back until then. + 'cancel_until' => $own && $m->type !== Movement::RETURN && $cancelUntil->greaterThan($now) ? self::iso($cancelUntil) : null, ]; })->values()->all(); } diff --git a/docs/architecture.md b/docs/architecture.md index 9e81453..736dbbf 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -188,7 +188,7 @@ The world grows the way Die Stämme's does (measured on de261, see the research - A village whose player has been inactive for too long turns barbarian (M6). - `php artisan game:reset-world {slug}` wipes a world back to empty (villages, players, movements, reports, events) and keeps user accounts and the world's config. -`map.view {world_id, x, y, w, h}` returns the villages in a `w × h` window (at most `map.max_view` per side) centred on `x|y`, kept inside the map, plus `size` and `min` (the lowest coordinate); without a centre it opens on the player's first village, else on 0|0. Each village comes with its coordinates, continent, name, points, owner (null for barbarians) with their tribe tag, whether it is the player's own, and its `relation` to the viewer for the colour: own, tribe, ally, nap, enemy, none (another player) or barbarian. It also carries `movements`: the player's own commands and groups going home (with units), and groups coming to their villages once spotted (with the size tier only: tiny under 50 heads, then small, medium, large and huge from `movement.size_tiers`). The client draws each as a line from origin to target with the group at its position, a straight line at constant speed from `sent_at` to `arrives_at`; raiders wait at their camp until they march. The client draws it like the Die Stämme map: a top-down field grid with coordinate rulers and continent lines. +`map.view {world_id, x, y, w, h}` returns the villages in a `w × h` window (at most `map.max_view` per side) centred on `x|y`, kept inside the map, plus `size` and `min` (the lowest coordinate); without a centre it opens on the player's first village, else on 0|0. Each village comes with its coordinates, continent, name, points, owner (null for barbarians) with their tribe tag, whether it is the player's own, and its `relation` to the viewer for the colour: own, tribe, ally, nap, enemy, none (another player) or barbarian. It also carries `movements`: the player's own commands and groups going home (with units, and `cancel_until` while an own attack or support can still be called back), and groups coming to their villages once spotted (with the size tier only: tiny under 50 heads, then small, medium, large and huge from `movement.size_tiers`). The client draws each as a line from origin to target with the group at its position, a straight line at constant speed from `sent_at` to `arrives_at`; raiders wait at their camp until they march. The client draws it like the Die Stämme map: a top-down field grid with coordinate rulers and continent lines. ## Movements and encounters diff --git a/tests/Feature/MapRelationsTest.php b/tests/Feature/MapRelationsTest.php index 1baef2a..36b0b06 100644 --- a/tests/Feature/MapRelationsTest.php +++ b/tests/Feature/MapRelationsTest.php @@ -61,3 +61,15 @@ it('shows own groups with units and spotted incoming ones by size only', functio ->and($mine[0]['to']['id'])->toBe($barbarian->id) ->and(mapAround($other)['movements'])->toBe([]); }); + +it('says until when an own command can be called back from the map', function () { + $me = startVillage(); + $barbarian = app(VillageFactory::class)->create($me->world, null, 'Barbarian village', $me->x + 3, $me->y, ['headquarters' => 1]); + $me->buildings()->create(['type' => 'rally_point', 'level' => 1]); + $me->troops()->create(['home_village_id' => $me->id, 'unit' => 'spear', 'count' => 10]); + app(SendTroops::class)(owner($me), $me->id, 'attack', $barbarian->x, $barbarian->y, ['spear' => 10], null, null); + + expect(mapAround($me)['movements'][0]['cancel_until'])->toBe('2026-10-29T12:10:00.000Z'); + $this->travel(11)->minutes(); + expect(mapAround($me)['movements'][0]['cancel_until'])->toBeNull(); +});