fix: a called-back command heads home from where it turned round: its return's sent_at lies as far back as it still had to go, so the map's straight line puts it in the right spot
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
874cb14b81
commit
64f0d40256
|
|
@ -190,13 +190,17 @@ final class Rally
|
||||||
->where('subject_id', $movement->id)->whereNull('processed_at')->delete();
|
->where('subject_id', $movement->id)->whereNull('processed_at')->delete();
|
||||||
Push::queue($movement->target_id);
|
Push::queue($movement->target_id);
|
||||||
|
|
||||||
|
// Home on the same line at the same pace: as if it had left the target as long ago
|
||||||
|
// as it still had to go, so a straight line from sent_at to arrives_at puts it where
|
||||||
|
// it turned round.
|
||||||
$elapsed = $now->getTimestampMs() - $movement->sent_at->getTimestampMs();
|
$elapsed = $now->getTimestampMs() - $movement->sent_at->getTimestampMs();
|
||||||
|
$left = $movement->arrives_at->getTimestampMs() - $now->getTimestampMs();
|
||||||
$movement->update([
|
$movement->update([
|
||||||
'type' => Movement::RETURN,
|
'type' => Movement::RETURN,
|
||||||
'origin_id' => $movement->target_id,
|
'origin_id' => $movement->target_id,
|
||||||
'target_id' => $this->village->id,
|
'target_id' => $this->village->id,
|
||||||
'catapult_target' => null,
|
'catapult_target' => null,
|
||||||
'sent_at' => $now,
|
'sent_at' => $now->subMilliseconds($left),
|
||||||
'arrives_at' => $now->addMilliseconds($elapsed),
|
'arrives_at' => $now->addMilliseconds($elapsed),
|
||||||
'visible_at' => $now,
|
'visible_at' => $now,
|
||||||
]);
|
]);
|
||||||
|
|
|
||||||
|
|
@ -198,7 +198,7 @@ Every group on the map is a `movement`: an attack, support, return, or trade car
|
||||||
|
|
||||||
- The rally point sends an attack or support from the units at home to the village at x|y (`rally.send`; `rally.preview` shows the target, distance and travel time first). A village needs a rally point to send anything. Travel time is the slowest unit's minutes per field × distance / (world speed × `movement.unit_speed` × mode speed), with the distance as the crow flies.
|
- The rally point sends an attack or support from the units at home to the village at x|y (`rally.send`; `rally.preview` shows the target, distance and travel time first). A village needs a rally point to send anything. Travel time is the slowest unit's minutes per field × distance / (world speed × `movement.unit_speed` × mode speed), with the distance as the crow flies.
|
||||||
- The troops leave at once. Their arrival is a `movement.arrives` event on the target, so it runs under the target's lock and in the target's event order; a `movement.spotted` event at `visible_at` only pushes the change. Reading a village first catches up the targets of its own due groups, so the owner never sees a group that should have arrived.
|
- The troops leave at once. Their arrival is a `movement.arrives` event on the target, so it runs under the target's lock and in the target's event order; a `movement.spotted` event at `visible_at` only pushes the change. Reading a village first catches up the targets of its own due groups, so the owner never sees a group that should have arrived.
|
||||||
- Within `movement.cancel_window` (10 real minutes) the sender can call a command back. It turns around and takes as long to get home as it had been under way.
|
- Within `movement.cancel_window` (10 real minutes) the sender can call a command back. It turns around where it is and takes as long to get home as it had been under way. The return runs from the target with `sent_at` set as far back as the group still had to go, so the straight line from `sent_at` to `arrives_at` puts it where it turned.
|
||||||
- An attack with survivors turns into its own return trip with the loot, taking as long as the way there. Loot that doesn't fit the storage is lost on arrival.
|
- An attack with survivors turns into its own return trip with the loot, taking as long as the way there. Loot that doesn't fit the storage is lost on arrival.
|
||||||
- Support stands in the host village as unit stacks with their own `home_village_id`. The host feeds it (it counts against the host's food budget), and hunger sends it home before any own soldier deserts. The host can send any support home (`rally.sendHome`), and the owner can withdraw it (`rally.withdraw`, a `support.recalled` event on the host's queue); both start a return trip. Groups under way eat nothing.
|
- Support stands in the host village as unit stacks with their own `home_village_id`. The host feeds it (it counts against the host's food budget), and hunger sends it home before any own soldier deserts. The host can send any support home (`rally.sendHome`), and the owner can withdraw it (`rally.withdraw`, a `support.recalled` event on the host's queue); both start a return trip. Groups under way eat nothing.
|
||||||
- Barbarian villages take no support, and own villages can't be attacked.
|
- Barbarian villages take no support, and own villages can't be attacked.
|
||||||
|
|
|
||||||
|
|
@ -152,6 +152,28 @@ it('calls an attack back within the cancel window', function () {
|
||||||
expect(rule(fn () => app(CancelMovement::class)(owner($village), $village->id, Movement::sole()->id)))->toBe('too_late');
|
expect(rule(fn () => app(CancelMovement::class)(owner($village), $village->id, Movement::sole()->id)))->toBe('too_late');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('draws a called-back command where it turned round, not at the target', function () {
|
||||||
|
$village = rallied(startVillage(), ['spear' => 10]);
|
||||||
|
$barbarian = barbarianNear($village, 3, 4);
|
||||||
|
// 5 fields at 18 minutes: 5400 s out.
|
||||||
|
send($village, $barbarian, ['spear' => 10]);
|
||||||
|
|
||||||
|
$this->travel(600)->seconds();
|
||||||
|
app(CancelMovement::class)(owner($village), $village->id, Movement::sole()->id);
|
||||||
|
$back = Movement::sole();
|
||||||
|
// On the line from the target home at the pace it marched, it stands 600 s from home.
|
||||||
|
$total = $back->arrives_at->getTimestamp() - $back->sent_at->getTimestamp();
|
||||||
|
$done = now()->getTimestamp() - $back->sent_at->getTimestamp();
|
||||||
|
expect($back->origin_id)->toBe($barbarian->id)
|
||||||
|
->and($back->target_id)->toBe($village->id)
|
||||||
|
->and($back->arrives_at->toIso8601ZuluString())->toBe('2026-10-29T12:20:00Z')
|
||||||
|
->and($total)->toBe(5400)
|
||||||
|
->and($done)->toBe(4800);
|
||||||
|
|
||||||
|
$this->travel(600)->seconds();
|
||||||
|
expect((array) shown($village)['troops'])->toBe(['spear' => 10]);
|
||||||
|
});
|
||||||
|
|
||||||
it('refuses what the rally point cannot do', function () {
|
it('refuses what the rally point cannot do', function () {
|
||||||
$village = startVillage();
|
$village = startVillage();
|
||||||
$other = startVillage();
|
$other = startVillage();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue