fix(game): fight before departure and reorder the turn sequence
Per the documented turn order (game/rules.txt "Последовательность действий"), no ship should dodge the pre-departure battle by slipping into hyperspace. MakeTurn now runs merge -> battle -> load+launch routed groups -> fly -> merge -> battle, so: - ships ordered to depart (Launched) and ships being upgraded now take part in the pre-departure battle at their planet (CollectPlanetGroups / FilterBattleGroups); only survivors then enter hyperspace; - routed transports are loaded and launched AFTER that battle, so they fight empty and cannot escape it. A just-launched group has no stored hyperspace position, so moveShipGroup starts its first leg from the origin planet; the previous code read the nil launch coordinate and would panic. Because upgrading groups can now lose ships in the battle, the pending upgrade cost is recomputed from the group's current ship count instead of the value stored when the order was validated. Rules: reordered "Последовательность действий" and rewrote the combat note that ordered/routed ships skip the battle. Tests: launched-group move from origin, launched/upgrade groups taking part in battle, upgrade cost tracking ship losses. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -45,3 +45,20 @@ func TestListMoveableGroupIds(t *testing.T) {
|
||||
assert.NotEqual(t, game.StateTransfer, sg.State())
|
||||
}
|
||||
}
|
||||
|
||||
// TestMoveLaunchedGroupFromOrigin guards the launched-coordinate fix: a group
|
||||
// just sent by an order is Launched with no stored hyperspace position, so its
|
||||
// first leg must start from the origin planet. The pre-fix code dereferenced
|
||||
// the nil launch coordinate and panicked.
|
||||
func TestMoveLaunchedGroupFromOrigin(t *testing.T) {
|
||||
c, g := newCache()
|
||||
assert.NoError(t, c.CreateShips(Race_0_idx, ShipType_Cruiser, R0_Planet_0_num, 1))
|
||||
assert.NoError(t, g.ShipGroupSend(Race_0.Name, c.ShipGroup(0).ID, R0_Planet_2_num))
|
||||
assert.Equal(t, game.StateLaunched, c.ShipGroup(0).State())
|
||||
|
||||
// Must not panic on the nil launch coordinate. Planet_0 (1,1) -> Planet_2
|
||||
// (3,3) is ~2.83 ly; a Cruiser covers it in one turn and arrives.
|
||||
c.MoveShipGroups()
|
||||
assert.Equal(t, game.StateInOrbit, c.ShipGroup(0).State())
|
||||
assert.Equal(t, R0_Planet_2_num, c.ShipGroup(0).Destination)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user