wip: generate report

This commit is contained in:
Ilia Denisov
2026-02-03 23:41:18 +02:00
parent a567229f8a
commit adbe605783
36 changed files with 1037 additions and 391 deletions
+18 -18
View File
@@ -21,14 +21,15 @@ func (c *Cache) UpgradeGroup(ri int, groupIndex uint, techInput string, limitShi
return e.NewEntityNotExistsError("group #%d", groupIndex)
}
st := c.ShipGroupShipClass(sgi)
sg := c.ShipGroup(sgi)
if s := c.ShipGroup(sgi).State(); s != game.StateInOrbit && s != game.StateUpgrade {
if s := sg.State(); s != game.StateInOrbit { // && s != game.StateUpgrade
return e.NewShipsBusyError()
}
pl := c.MustPlanet(c.ShipGroup(sgi).Destination)
if pl.Owner != uuid.Nil && pl.Owner != c.g.Race[ri].ID {
return e.NewEntityNotOwnedError("planet #%d for upgrade group #%d", pl.Number, groupIndex)
p := c.MustPlanet(sg.Destination)
if p.Owner != uuid.Nil && p.Owner != c.g.Race[ri].ID {
return e.NewEntityNotOwnedError("planet #%d for upgrade group #%d", p.Number, groupIndex)
}
upgradeValidTech := map[string]game.Tech{
@@ -65,26 +66,25 @@ func (c *Cache) UpgradeGroup(ri int, groupIndex uint, techInput string, limitShi
if c.g.Race[ri].TechLevel(tech) < limitLevel {
return e.NewUpgradeTechLevelInsufficientError("%s=%.03f < %.03f", tech.String(), c.g.Race[ri].TechLevel(tech), limitLevel)
}
targetLevel[tech] = game.FutureUpgradeLevel(c.g.Race[ri].TechLevel(tech), c.ShipGroup(sgi).TechLevel(tech).F(), limitLevel)
targetLevel[tech] = game.FutureUpgradeLevel(c.g.Race[ri].TechLevel(tech), sg.TechLevel(tech).F(), limitLevel)
} else {
targetLevel[tech] = game.CurrentUpgradingLevel(c.g.ShipGroups[sgi], tech)
targetLevel[tech] = game.CurrentUpgradingLevel(sg, tech)
}
sumLevels += targetLevel[tech]
}
productionCapacity := c.PlanetProductionCapacity(pl.Number)
if c.ShipGroup(sgi).State() == game.StateUpgrade {
// to calculate actual capacity we must "compensate" upgrade cost of selected group, if it is in upgrade state
// TODO: this is not tested
productionCapacity += c.ShipGroup(sgi).StateUpgrade.Cost()
}
uc := game.GroupUpgradeCost(*(c.ShipGroup(sgi)), *st, targetLevel[game.TechDrive], targetLevel[game.TechWeapons], targetLevel[game.TechShields], targetLevel[game.TechCargo])
productionCapacity := c.PlanetProductionCapacity(p.Number)
// if sg.State() == game.StateUpgrade {
// // to calculate actual capacity we must "compensate" upgrade cost of selected group, if it is in upgrade state
// productionCapacity += sg.StateUpgrade.Cost()
// }
uc := game.GroupUpgradeCost(sg, *st, targetLevel[game.TechDrive], targetLevel[game.TechWeapons], targetLevel[game.TechShields], targetLevel[game.TechCargo])
costForShip := uc.UpgradeCost(1)
if costForShip == 0 {
return e.NewUpgradeShipsAlreadyUpToDateError("%#v", targetLevel)
}
shipsToUpgrade := c.ShipGroup(sgi).Number
shipsToUpgrade := sg.Number
// НЕ БОЛЕЕ УКАЗАННОГО
if limitShips > 0 && shipsToUpgrade > limitShips {
shipsToUpgrade = limitShips
@@ -118,16 +118,16 @@ func (c *Cache) UpgradeGroup(ri int, groupIndex uint, techInput string, limitShi
}
// sanity check
uc = game.GroupUpgradeCost(*(c.ShipGroup(sgi)), *st, targetLevel[game.TechDrive], targetLevel[game.TechWeapons], targetLevel[game.TechShields], targetLevel[game.TechCargo])
uc = game.GroupUpgradeCost(sg, *st, targetLevel[game.TechDrive], targetLevel[game.TechWeapons], targetLevel[game.TechShields], targetLevel[game.TechCargo])
costForGroup := uc.UpgradeCost(maxUpgradableShips)
if costForGroup > productionCapacity {
e.NewGameStateError("cost recalculation: coef=%f cost(%d)=%f L=%f", coef, maxUpgradableShips, costForGroup, productionCapacity)
}
// break group if needed
if maxUpgradableShips < c.ShipGroup(sgi).Number {
if c.ShipGroup(sgi).State() == game.StateUpgrade {
return e.NewUpgradeGroupBreakNotAllowedError("ships=%d max=%d", c.ShipGroup(sgi).Number, maxUpgradableShips)
if maxUpgradableShips < sg.Number {
if sg.State() == game.StateUpgrade {
return e.NewUpgradeGroupBreakNotAllowedError("ships=%d max=%d", sg.Number, maxUpgradableShips)
}
nsgi, err := c.breakGroupSafe(ri, groupIndex, maxUpgradableShips)
if err != nil {