ui calculator
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"iter"
|
||||
"slices"
|
||||
|
||||
"galaxy/calc"
|
||||
"galaxy/util"
|
||||
|
||||
e "galaxy/error"
|
||||
@@ -16,7 +17,7 @@ import (
|
||||
|
||||
func (c *Cache) ShipClassCreate(ri int, typeName string, drive float64, ammo int, weapons, shileds, cargo float64) error {
|
||||
c.validateRaceIndex(ri)
|
||||
if err := validateShipTypeValues(drive, ammo, weapons, shileds, cargo); err != nil {
|
||||
if err := calc.ValidateShipTypeValues(drive, ammo, weapons, shileds, cargo); err != nil {
|
||||
return err
|
||||
}
|
||||
n, ok := util.ValidateTypeName(typeName)
|
||||
@@ -159,32 +160,3 @@ func (c *Cache) MustShipType(ri int, ID uuid.UUID) *game.ShipType {
|
||||
}
|
||||
panic(fmt.Sprintf("ship class not found: race_idx=%d id=%v", ri, ID))
|
||||
}
|
||||
|
||||
func validateShipTypeValues(d float64, a int, w, s, c float64) error {
|
||||
if !checkShipTypeValueDWSC(d) {
|
||||
return e.NewDriveValueError(d)
|
||||
}
|
||||
if !checkShipTypeValueDWSC(w) {
|
||||
return e.NewWeaponsValueError(w)
|
||||
}
|
||||
if !checkShipTypeValueDWSC(s) {
|
||||
return e.NewShieldsValueError(s)
|
||||
}
|
||||
if !checkShipTypeValueDWSC(c) {
|
||||
return e.NewCargoValueError(s)
|
||||
}
|
||||
if a < 0 {
|
||||
return e.NewShipTypeArmamentValueError(a)
|
||||
}
|
||||
if (w == 0 && a > 0) || (a == 0 && w > 0) {
|
||||
return e.NewShipTypeArmamentAndWeaponsValueError("A=%d W=%.0f", a, w)
|
||||
}
|
||||
if d == 0 && w == 0 && s == 0 && c == 0 && a == 0 {
|
||||
return e.NewShipTypeShipTypeZeroValuesError()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func checkShipTypeValueDWSC(v float64) bool {
|
||||
return v == 0 || v >= 1
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user