feat: remove instant group breaking

This commit is contained in:
Ilia Denisov
2026-02-11 09:35:33 +02:00
parent 1515bc8599
commit 6e84cc3c51
17 changed files with 223 additions and 403 deletions
+11 -48
View File
@@ -96,6 +96,7 @@ func (c *Cache) TurnMergeEqualShipGroups() {
}
func (c *Cache) transferPendingGroups(ri int) {
c.validateRaceIndex(ri)
for sg := range c.listShipGroups(ri) {
if sg.State() == game.StateTransfer {
sg.StateTransfer = false
@@ -146,7 +147,8 @@ func (c *Cache) shipGroupMerge(ri int) {
}
}
func (c *Cache) shipGroupDismantle(ri int, groupIndex uuid.UUID, quantity uint) error {
func (c *Cache) shipGroupDismantle(ri int, groupIndex uuid.UUID) error {
c.validateRaceIndex(ri)
sgi, ok := c.raceShipGroupIndex(ri, groupIndex)
if !ok {
return e.NewEntityNotExistsError("group #%d", groupIndex)
@@ -156,10 +158,6 @@ func (c *Cache) shipGroupDismantle(ri int, groupIndex uuid.UUID, quantity uint)
return e.NewShipsBusyError("state: %s", state)
}
if c.ShipGroup(sgi).Number < quantity {
return e.NewBeakGroupNumberNotEnoughError("%d<%d", c.ShipGroup(sgi).Number, quantity)
}
pl, ok := c.Planet(c.ShipGroup(sgi).Destination)
if !ok {
return e.NewGameStateError("planet #%d", c.ShipGroup(sgi).Destination)
@@ -168,15 +166,6 @@ func (c *Cache) shipGroupDismantle(ri int, groupIndex uuid.UUID, quantity uint)
st := c.ShipGroupShipClass(sgi)
if quantity > 0 && quantity < c.ShipGroup(sgi).Number {
// make new group for disassembly
nsgi, err := c.breakGroup(ri, groupIndex, quantity)
if err != nil {
return err
}
sgi = nsgi
}
if c.ShipGroup(sgi).CargoType != nil {
ct := *c.ShipGroup(sgi).CargoType
load := c.ShipGroup(sgi).Load.F()
@@ -204,10 +193,8 @@ func (c *Cache) shipGroupDismantle(ri int, groupIndex uuid.UUID, quantity uint)
// Корабль может нести только один тип груза одновременно.
// Возможные типы груза - это колонисты, сырье и промышленность.
// Груз может быть доставлен на борт корабля с Вашей или не занятой планеты, на которой он имеется.
func (c *Cache) shipGroupLoad(ri int, groupID uuid.UUID, ct game.CargoType, ships uint, quantity float64) error {
if ships == 0 && quantity > 0 {
return e.NewCargoQuantityWithoutGroupBreakError()
}
func (c *Cache) shipGroupLoad(ri int, groupID uuid.UUID, ct game.CargoType, quantity float64) error {
c.validateRaceIndex(ri)
sgi, ok := c.raceShipGroupIndex(ri, groupID)
if !ok {
return e.NewEntityNotExistsError("group %s", groupID)
@@ -231,13 +218,7 @@ func (c *Cache) shipGroupLoad(ri int, groupID uuid.UUID, ct game.CargoType, ship
if c.ShipGroup(sgi).CargoType != nil && *c.ShipGroup(sgi).CargoType != ct {
return e.NewCargoLoadNotEqualError("cargo: %v", *c.ShipGroup(sgi).CargoType)
}
if ships > 0 && ships < c.ShipGroup(sgi).Number {
nsgi, err := c.breakGroup(ri, groupID, ships)
if err != nil {
return err
}
sgi = nsgi
}
capacity := c.ShipGroup(sgi).CargoCapacity(st)
freeShipGroupCargoLoad := capacity - float64(c.ShipGroup(sgi).Load)
if freeShipGroupCargoLoad == 0 {
@@ -274,11 +255,8 @@ func (c *Cache) shipGroupLoad(ri int, groupID uuid.UUID, ct game.CargoType, ship
// Промышленность и Сырье могут быть выгружены на любой планете.
// Колонисты могут быть высажены только на планеты, принадлежащие Вам или на необитаемые планеты.
func (c *Cache) shipGroupUnload(ri int, groupID uuid.UUID, ships uint, quantity float64) error {
func (c *Cache) shipGroupUnload(ri int, groupID uuid.UUID, quantity float64) error {
c.validateRaceIndex(ri)
if ships == 0 && quantity > 0 {
return e.NewCargoQuantityWithoutGroupBreakError()
}
sgi, ok := c.raceShipGroupIndex(ri, groupID)
if !ok {
return e.NewEntityNotExistsError("group %s", groupID)
@@ -300,13 +278,6 @@ func (c *Cache) shipGroupUnload(ri int, groupID uuid.UUID, ships uint, quantity
if ct == game.CargoColonist && p.Owned() && !p.OwnedBy(c.g.Race[ri].ID) {
return e.NewEntityNotOwnedError("planet #%d unload %v", p.Number, ct)
}
if ships > 0 && ships < c.ShipGroup(sgi).Number {
nsgi, err := c.breakGroup(ri, groupID, ships)
if err != nil {
return err
}
sgi = nsgi
}
toBeUnloaded := quantity
if quantity == 0 {
@@ -356,7 +327,8 @@ func (c *Cache) unsafeUnloadCargo(sgi int, q float64) {
p.UnpackCapital()
}
func (c *Cache) shipGroupTransfer(ri, riAccept int, groupID uuid.UUID, quantity uint) (err error) {
func (c *Cache) shipGroupTransfer(ri, riAccept int, groupID uuid.UUID) (err error) {
c.validateRaceIndex(ri)
if ri == riAccept {
return e.NewSameRaceError(c.g.Race[riAccept].Name)
}
@@ -369,9 +341,6 @@ func (c *Cache) shipGroupTransfer(ri, riAccept int, groupID uuid.UUID, quantity
if state == game.StateTransfer {
return e.NewShipsBusyError("state: %s", state)
}
if sg.Number < quantity {
return e.NewBeakGroupNumberNotEnoughError("%d<%d", sg.Number, quantity)
}
st := c.ShipGroupShipClass(sgi)
@@ -402,19 +371,13 @@ func (c *Cache) shipGroupTransfer(ri, riAccept int, groupID uuid.UUID, quantity
newGroup.StateTransfer = true
}
if quantity == 0 || quantity == sg.Number {
c.unsafeDeleteShipGroup(sgi)
} else {
newGroup.Number = quantity
sg.Number -= quantity
}
c.appendShipGroup(riAccept, &newGroup)
c.unsafeDeleteShipGroup(sgi)
return nil
}
func (c *Cache) ShipGroupBreak(ri int, groupID uuid.UUID, quantity uint) error {
func (c *Cache) ShipGroupBreak(ri int, groupID, newID uuid.UUID, quantity uint) error {
c.validateRaceIndex(ri)
sgi, ok := c.raceShipGroupIndex(ri, groupID)
if !ok {