Files
galaxy-game/pkg/calc/validator.go
T
Ilia Denisov dc621cc715
Tests · Go / test (push) Successful in 1m58s
Tests · Integration / integration (pull_request) Successful in 1m47s
Tests · Go / test (pull_request) Successful in 2m1s
fix(game): small reconciliation fixes (science, generation, dismantle, report)
A bundle of small rules-vs-engine corrections:

- Science proportions: accept a sum that equals 1 only up to float
  rounding (was an exact != 1 comparison); the rules example is reworded
  so it is unambiguous that proportions are fractions summing to 1.
- Generation: super-big planets get a resource strictly above 0 (minimum
  0.001, was a hard 0.1); the rules table is fixed for big planets (1-10,
  not 0.1-10) and the false "0.1-20 / average 1.5" resource claim removed.
- Dismantle over a neutral planet now unloads the colonists and settles
  it (the planet becomes the race's); over a foreign planet they are
  still lost. The rules clause is clarified for own / neutral / foreign.
- Report: ship-production entries are written at the compacted report
  index (was the planet's map index, which could write past the grown
  slice and panic); the incoming-group "remaining distance" is measured
  from the group's current hyperspace position, not its origin planet
  (matching OtherGroup).
- validator: the cargo-value error now carries the cargo value, not the
  shields value.

Tests added for each behavioural fix; rules.txt updated in the same patch.
2026-05-31 09:29:07 +02:00

35 lines
766 B
Go

package calc
import (
e "galaxy/error"
)
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(c)
}
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
}