136 lines
3.0 KiB
Go
136 lines
3.0 KiB
Go
package controller
|
|
|
|
import (
|
|
"fmt"
|
|
"iter"
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/iliadenisov/galaxy/internal/model/game"
|
|
)
|
|
|
|
func (c *Cache) AddRace(n string) (int, uuid.UUID) {
|
|
id := uuid.New()
|
|
r := &game.Race{
|
|
ID: id,
|
|
VoteFor: id,
|
|
Name: n,
|
|
Tech: game.NewTechSet(),
|
|
Relations: make([]game.RaceRelation, len(c.g.Race)),
|
|
}
|
|
c.g.Race = append(c.g.Race, *r)
|
|
for i := range c.listRaceIdx() {
|
|
if c.g.Race[i].ID != id {
|
|
c.g.Race[i].Relations = append(c.g.Race[i].Relations, game.RaceRelation{RaceID: id, Relation: game.RelationPeace})
|
|
continue
|
|
}
|
|
for j := range c.g.Race[i].Relations {
|
|
c.g.Race[i].Relations[j].RaceID = c.g.Race[j].ID
|
|
c.g.Race[i].Relations[j].Relation = game.RelationPeace
|
|
}
|
|
}
|
|
return len(c.g.Race) - 1, id
|
|
}
|
|
|
|
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)
|
|
}
|
|
|
|
func (c *Cache) CreateShipsUnsafe_T(ri int, classID uuid.UUID, planet uint, quantity uint) {
|
|
c.createShipsUnsafe(ri, classID, planet, quantity)
|
|
}
|
|
|
|
func (c *Cache) WipeRace(ri int) {
|
|
c.wipeRace(ri)
|
|
}
|