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:
@@ -196,6 +196,24 @@ func FutureUpgradeLevel(raceLevel, groupLevel, limit float64) float64 {
|
||||
return target
|
||||
}
|
||||
|
||||
// upgradeCostNow returns the production cost to apply group sg's pending
|
||||
// upgrade to its CURRENT ship count. The cost stored on StateUpgrade is fixed
|
||||
// when the order is validated; if the group has since lost ships (for example
|
||||
// in the pre-departure battle, now that upgrading groups take part in it), the
|
||||
// stored total is stale, so the cost is recomputed from the stored target
|
||||
// levels, the group's current tech, and its current ship count.
|
||||
func (c *Cache) upgradeCostNow(sg *game.ShipGroup) float64 {
|
||||
if sg.StateUpgrade == nil {
|
||||
return 0
|
||||
}
|
||||
st := c.MustShipType(c.RaceIndex(sg.OwnerID), sg.TypeID)
|
||||
var perShip float64
|
||||
for _, pref := range sg.StateUpgrade.UpgradeTech {
|
||||
perShip += calc.BlockUpgradeCost(st.BlockMass(pref.Tech), sg.TechLevel(pref.Tech).F(), pref.Level.F())
|
||||
}
|
||||
return perShip * float64(sg.Number)
|
||||
}
|
||||
|
||||
func UpgradeGroupPreference(sg game.ShipGroup, st game.ShipType, tech game.Tech, v float64) game.ShipGroup {
|
||||
if v <= 0 || st.BlockMass(tech) == 0 || sg.TechLevel(tech).F() >= v {
|
||||
return sg
|
||||
|
||||
Reference in New Issue
Block a user