wip: battle mechanism

This commit is contained in:
Ilia Denisov
2026-01-11 20:27:43 +02:00
parent b3de13b6e1
commit ac60bb3020
4 changed files with 322 additions and 94 deletions
+9
View File
@@ -131,6 +131,7 @@ func (g Game) deleteShipTypeInternal(ri int, name string) error {
return nil
}
// TODO: D A W S C
func (g Game) CreateShipType(raceName, typeName string, d, w, s, c float64, a int) error {
ri, err := g.raceIndex(raceName)
if err != nil {
@@ -251,3 +252,11 @@ func ShipClass(g *Game, ri int, classID uuid.UUID) (ShipType, bool) {
}
return g.Race[ri].ShipTypes[sti], true
}
func ShipClassIndex(g *Game, ri int, classID uuid.UUID) (int, bool) {
if len(g.Race) < ri+1 {
panic(fmt.Sprintf("ShipClass: game race index %d invalid: len=%d", ri, len(g.Race)))
}
sti := slices.IndexFunc(g.Race[ri].ShipTypes, func(st ShipType) bool { return st.ID == classID })
return sti, sti >= 0
}