105 lines
2.2 KiB
Go
105 lines
2.2 KiB
Go
package controller
|
|
|
|
import (
|
|
"fmt"
|
|
"iter"
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/iliadenisov/galaxy/internal/model/game"
|
|
)
|
|
|
|
func (c *Cache) Race(i int) game.Race {
|
|
c.validateRaceIndex(i)
|
|
return c.g.Race[i]
|
|
}
|
|
|
|
func (c *Cache) RaceShipGroups(ri int) iter.Seq[*game.ShipGroup] {
|
|
return c.listShipGroups(ri)
|
|
}
|
|
|
|
func (c *Cache) RaceScience(ri int) []game.Science {
|
|
return c.raceScience(ri)
|
|
}
|
|
|
|
func (c *Cache) ListFleets(ri int) iter.Seq[*game.Fleet] {
|
|
return c.listFleets(ri)
|
|
}
|
|
|
|
func (c *Cache) MustFleetID(ri int, name string) uuid.UUID {
|
|
for f := range c.listFleets(ri) {
|
|
if f.Name == name {
|
|
return f.ID
|
|
}
|
|
}
|
|
panic("fleet not found")
|
|
}
|
|
|
|
func (c *Cache) MustShipGroup(ri int, index uint) *game.ShipGroup {
|
|
for sg := range c.listShipGroups(ri) {
|
|
if sg.Index == index {
|
|
return sg
|
|
}
|
|
}
|
|
panic(fmt.Sprintf("race i=%d have no group i=%d", ri, index))
|
|
}
|
|
|
|
func (c *Cache) MustShipClass(ri int, name string) *game.ShipType {
|
|
st, _, ok := c.ShipClass(ri, name)
|
|
if !ok {
|
|
panic("ship class not found")
|
|
}
|
|
return st
|
|
}
|
|
|
|
func (c *Cache) PutPopulation(pn uint, v float64) {
|
|
c.putPopulation(pn, v)
|
|
}
|
|
|
|
func (c *Cache) PutColonists(pn uint, v float64) {
|
|
c.putColonists(pn, v)
|
|
}
|
|
|
|
func (c *Cache) PutMaterial(pn uint, v float64) {
|
|
c.putMaterial(pn, v)
|
|
}
|
|
|
|
func (c *Cache) RaceTechLevel(ri int, t game.Tech, v float64) {
|
|
c.raceTechLevel(ri, t, v)
|
|
}
|
|
|
|
func (c *Cache) ListRoutedSendGroupIds(pn uint) iter.Seq[int] {
|
|
return c.listRoutedSendGroupIds(pn)
|
|
}
|
|
|
|
func (c *Cache) ListRoutedUnloadShipGroupIds(pn uint, rt game.RouteType) iter.Seq[int] {
|
|
return c.listRoutedUnloadShipGroupIds(pn, rt)
|
|
}
|
|
|
|
func (c *Cache) SelectColUnloadGroup(groups []int) (result iter.Seq[int]) {
|
|
return c.selectColUnloadGroup(groups)
|
|
}
|
|
|
|
func (c *Cache) ListMoveableGroupIds() iter.Seq[int] {
|
|
return c.listMoveableGroupIds()
|
|
}
|
|
|
|
func (c *Cache) CollectBombingGroups() map[uint]map[int][]int {
|
|
return c.collectBombingGroups()
|
|
}
|
|
|
|
func BombPlanet(p *game.Planet, power float64) {
|
|
bombPlanet(p, power)
|
|
}
|
|
|
|
func (c *Cache) ListProducingPlanets() iter.Seq[uint] {
|
|
return c.listProducingPlanets()
|
|
}
|
|
|
|
func (c *Cache) VotesByRace() map[int]float64 {
|
|
return c.votesByRace()
|
|
}
|
|
|
|
func VotingWinners(calc []*VoteGroup, gameVotes float64) []int {
|
|
return votingWinners(calc, gameVotes)
|
|
}
|