feat: produce on planets, unload on routes
This commit is contained in:
@@ -25,10 +25,16 @@ func (c *Cache) CreateShips(ri int, shipTypeName string, planetNumber uint, quan
|
||||
return e.NewEntityNotOwnedError("planet #%d", planetNumber)
|
||||
}
|
||||
|
||||
c.createShipsUnsafe(ri, class.ID, p.Number, uint(quantity))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Cache) createShipsUnsafe(ri int, classID uuid.UUID, planet uint, quantity uint) {
|
||||
c.appendShipGroup(ri, &game.ShipGroup{
|
||||
OwnerID: c.g.Race[ri].ID,
|
||||
TypeID: class.ID,
|
||||
Destination: p.Number,
|
||||
TypeID: classID,
|
||||
Destination: planet,
|
||||
Number: uint(quantity),
|
||||
Tech: map[game.Tech]float64{
|
||||
game.TechDrive: c.g.Race[ri].TechLevel(game.TechDrive),
|
||||
@@ -37,7 +43,7 @@ func (c *Cache) CreateShips(ri int, shipTypeName string, planetNumber uint, quan
|
||||
game.TechCargo: c.g.Race[ri].TechLevel(game.TechCargo),
|
||||
},
|
||||
})
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
// ShipGroup is a proxy func, nothing to cache
|
||||
@@ -123,7 +129,7 @@ func (c *Controller) JoinEqualGroups(raceName string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Cache) CmdJoinEqualGroups() {
|
||||
func (c *Cache) TurnMergeEqualShipGroups() {
|
||||
for i := range c.g.Race {
|
||||
c.JoinEqualGroups(i)
|
||||
}
|
||||
@@ -354,29 +360,12 @@ func (c *Cache) UnloadCargo(ri int, groupIndex uint, ships uint, quantity float6
|
||||
if c.ShipGroup(sgi).CargoType == nil || c.ShipGroup(sgi).Load == 0 {
|
||||
return e.NewCargoUnloadEmptyError()
|
||||
}
|
||||
|
||||
ct := *c.ShipGroup(sgi).CargoType
|
||||
p, ok := c.Planet(c.ShipGroup(sgi).Destination)
|
||||
if !ok {
|
||||
return e.NewGameStateError("planet #%d", c.ShipGroup(sgi).Destination)
|
||||
}
|
||||
if ct == game.CargoColonist {
|
||||
if p.Owner != uuid.Nil && p.Owner != c.g.Race[ri].ID {
|
||||
return e.NewEntityNotOwnedError("planet #%d unload %v", p.Number, ct)
|
||||
}
|
||||
if p.Owner == uuid.Nil {
|
||||
p.Owner = c.g.Race[ri].ID
|
||||
}
|
||||
}
|
||||
var availableOnPlanet *float64
|
||||
switch ct {
|
||||
case game.CargoMaterial:
|
||||
availableOnPlanet = &p.Material
|
||||
case game.CargoCapital:
|
||||
availableOnPlanet = &p.Capital
|
||||
case game.CargoColonist:
|
||||
availableOnPlanet = &p.Colonists
|
||||
default:
|
||||
return e.NewGameStateError("CargoType not accepted: %v", ct)
|
||||
p := c.MustPlanet(c.ShipGroup(sgi).Destination)
|
||||
|
||||
if ct == game.CargoColonist && p.Owner != uuid.Nil && p.Owner != 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.breakGroupSafe(ri, groupIndex, ships)
|
||||
@@ -385,6 +374,7 @@ func (c *Cache) UnloadCargo(ri int, groupIndex uint, ships uint, quantity float6
|
||||
}
|
||||
sgi = nsgi
|
||||
}
|
||||
|
||||
toBeUnloaded := quantity
|
||||
if quantity == 0 {
|
||||
toBeUnloaded = c.ShipGroup(sgi).Load
|
||||
@@ -392,13 +382,43 @@ func (c *Cache) UnloadCargo(ri int, groupIndex uint, ships uint, quantity float6
|
||||
if toBeUnloaded > c.ShipGroup(sgi).Load {
|
||||
return e.NewCargoUnoadNotEnoughError("load: %.03f", c.ShipGroup(sgi).Load)
|
||||
}
|
||||
*availableOnPlanet += toBeUnloaded
|
||||
c.ShipGroup(sgi).Load -= toBeUnloaded
|
||||
|
||||
c.unloadCargoUnsafe(sgi, toBeUnloaded)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Cache) unloadCargoUnsafe(sgi int, q float64) {
|
||||
if q <= 0 {
|
||||
return
|
||||
}
|
||||
c.validateShipGroupIndex(sgi)
|
||||
p := c.MustPlanet(c.ShipGroup(sgi).Destination)
|
||||
ct := *c.ShipGroup(sgi).CargoType
|
||||
|
||||
var availableOnPlanet *float64
|
||||
switch ct {
|
||||
case game.CargoColonist:
|
||||
availableOnPlanet = &p.Colonists
|
||||
if p.Owner == uuid.Nil {
|
||||
p.Owner = c.ShipGroup(sgi).OwnerID
|
||||
p.Production = game.ProductionCapital.AsType(uuid.Nil)
|
||||
}
|
||||
case game.CargoMaterial:
|
||||
availableOnPlanet = &p.Material
|
||||
case game.CargoCapital:
|
||||
availableOnPlanet = &p.Capital
|
||||
}
|
||||
*availableOnPlanet += q
|
||||
|
||||
// FIXME: unpack COL / CAP
|
||||
|
||||
c.ShipGroup(sgi).Load -= q
|
||||
if c.ShipGroup(sgi).Load == 0 {
|
||||
c.ShipGroup(sgi).CargoType = nil
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Controller) GiveawayGroup(raceName, raceAcceptor string, groupIndex, quantity uint) error {
|
||||
ri, err := c.Cache.raceIndex(raceName)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user