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) <noreply@anthropic.com>
This commit is contained in:
Fabian @ Blax Software 2026-10-30 11:14:49 +01:00
parent fcdcb089cc
commit 54a6fc5e8c
3 changed files with 18 additions and 2 deletions

View File

@ -109,6 +109,7 @@ final class ShowMap
private function movements(Player $me, World $world, CarbonImmutable $now): array private function movements(Player $me, World $world, CarbonImmutable $now): array
{ {
$size = new GroupSize($world->gameConfig()); $size = new GroupSize($world->gameConfig());
$window = (int) $world->gameConfig()->get('movement.cancel_window', 600);
$mine = Village::where('player_id', $me->id)->pluck('id'); $mine = Village::where('player_id', $me->id)->pluck('id');
return Movement::with(['origin:id,name,x,y', 'target:id,name,x,y']) 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)))) ->orWhere(fn ($q) => $q->whereIn('target_id', $mine)->where('type', '!=', Movement::RETURN)->where('visible_at', '<=', Engine::stamp($now))))
->where('arrives_at', '>', Engine::stamp($now)) ->where('arrives_at', '>', Engine::stamp($now))
->orderBy('arrives_at')->limit(300)->get() ->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; $own = $m->player_id === $me->id;
$cancelUntil = $m->sent_at->addSeconds($window);
return [ return [
'id' => $m->id, 'id' => $m->id,
@ -131,6 +133,8 @@ final class ShowMap
'arrives_at' => self::iso($m->arrives_at), 'arrives_at' => self::iso($m->arrives_at),
'size' => $size->tier($m->units), 'size' => $size->tier($m->units),
'units' => $own ? $m->units : null, '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(); })->values()->all();
} }

View File

@ -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). - 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. - `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 ## Movements and encounters

View File

@ -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($mine[0]['to']['id'])->toBe($barbarian->id)
->and(mapAround($other)['movements'])->toBe([]); ->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();
});