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:
@@ -32,14 +32,23 @@ type BattleAction struct {
|
||||
func CollectPlanetGroups(c *Cache) map[uint]map[int]bool {
|
||||
planetGroup := make(map[uint]map[int]bool)
|
||||
for groupIndex := range c.ShipGroupsIndex() {
|
||||
state := c.ShipGroup(groupIndex).State()
|
||||
if state == game.StateInOrbit || state == game.StateUpgrade {
|
||||
planetNumber := c.ShipGroup(groupIndex).Destination
|
||||
if _, ok := planetGroup[planetNumber]; !ok {
|
||||
planetGroup[planetNumber] = make(map[int]bool)
|
||||
}
|
||||
planetGroup[planetNumber][groupIndex] = false
|
||||
sg := c.ShipGroup(groupIndex)
|
||||
var planetNumber uint
|
||||
switch sg.State() {
|
||||
case game.StateInOrbit, game.StateUpgrade:
|
||||
planetNumber = sg.Destination
|
||||
case game.StateLaunched:
|
||||
// Ordered to depart but still physically at the origin planet, so
|
||||
// it joins the pre-departure battle there; only survivors then
|
||||
// enter hyperspace.
|
||||
planetNumber = sg.StateInSpace.Origin
|
||||
default:
|
||||
continue
|
||||
}
|
||||
if _, ok := planetGroup[planetNumber]; !ok {
|
||||
planetGroup[planetNumber] = make(map[int]bool)
|
||||
}
|
||||
planetGroup[planetNumber][groupIndex] = false
|
||||
}
|
||||
for pl := range planetGroup {
|
||||
if len(planetGroup[pl]) < 2 {
|
||||
@@ -50,7 +59,18 @@ func CollectPlanetGroups(c *Cache) map[uint]map[int]bool {
|
||||
}
|
||||
|
||||
func FilterBattleGroups(c *Cache, groups map[int]bool) []int {
|
||||
return slices.DeleteFunc(slices.Collect(maps.Keys(groups)), func(groupIndex int) bool { return c.ShipGroup(groupIndex).State() != game.StateInOrbit })
|
||||
return slices.DeleteFunc(slices.Collect(maps.Keys(groups)), func(groupIndex int) bool {
|
||||
// Everything physically present at the planet fights: ships in orbit,
|
||||
// ships being upgraded, and ships ordered to depart that have not yet
|
||||
// entered hyperspace (Launched). Only ships already in hyperspace are
|
||||
// out of reach.
|
||||
switch c.ShipGroup(groupIndex).State() {
|
||||
case game.StateInOrbit, game.StateUpgrade, game.StateLaunched:
|
||||
return false
|
||||
default:
|
||||
return true
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func FilterBattleOpponents(c *Cache, attIdx, defIdx int, cacheProbability map[int]map[int]float64) bool {
|
||||
|
||||
Reference in New Issue
Block a user