refactor: planet owner
This commit is contained in:
@@ -6,39 +6,48 @@ import (
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type UnidentifiedPlanet struct {
|
||||
X Float `json:"x"`
|
||||
Y Float `json:"y"`
|
||||
Number uint `json:"number"`
|
||||
}
|
||||
|
||||
type UninhabitedPlanet struct {
|
||||
UnidentifiedPlanet
|
||||
Size Float `json:"size"`
|
||||
Name string `json:"name"`
|
||||
Resources Float `json:"resources"` // R - Ресурсы
|
||||
Capital Float `json:"capital"` // CAP $ - Запасы промышленности
|
||||
Material Float `json:"material"` // MAT M - Запасы ресурсов / сырьё
|
||||
}
|
||||
|
||||
type PlanetReport struct {
|
||||
UninhabitedPlanet
|
||||
Industry Float `json:"industry"` // I - Промышленность
|
||||
Population Float `json:"population"` // P - Население
|
||||
Colonists Float `json:"colonists"` // COL C - Количество колонистов
|
||||
Production Production `json:"production"` // TODO: internal/report format
|
||||
}
|
||||
|
||||
// TODO: unwrap in one struct
|
||||
type Planet struct {
|
||||
Owner uuid.UUID `json:"owner"` // FIXME: nil value when no owner
|
||||
Route map[RouteType]uint `json:"route"`
|
||||
PlanetReport
|
||||
X Float `json:"x"`
|
||||
Y Float `json:"y"`
|
||||
Number uint `json:"number"`
|
||||
Size Float `json:"size"`
|
||||
Name string `json:"name"`
|
||||
Owner *uuid.UUID `json:"owner,omitempty"`
|
||||
Resources Float `json:"resources"` // R - Ресурсы
|
||||
Capital Float `json:"capital"` // CAP $ - Запасы промышленности
|
||||
Material Float `json:"material"` // MAT M - Запасы ресурсов / сырьё
|
||||
Industry Float `json:"industry"` // I - Промышленность
|
||||
Population Float `json:"population"` // P - Население
|
||||
Colonists Float `json:"colonists"` // COL C - Количество колонистов
|
||||
Production Production `json:"production"`
|
||||
Route map[RouteType]uint `json:"route"`
|
||||
}
|
||||
|
||||
type PlanetReportForeign struct {
|
||||
RaceName string
|
||||
PlanetReport
|
||||
func (p *Planet) Own(v uuid.UUID) {
|
||||
if v == uuid.Nil {
|
||||
p.Free()
|
||||
return
|
||||
}
|
||||
if p.Owner == nil || *p.Owner != v {
|
||||
p.Production = ProductionCapital.AsType(uuid.Nil)
|
||||
}
|
||||
p.Owner = &v
|
||||
}
|
||||
|
||||
func (p *Planet) Free() {
|
||||
p.Owner = nil
|
||||
p.Production = ProductionNone.AsType(uuid.Nil)
|
||||
}
|
||||
|
||||
func (p Planet) Owned() bool {
|
||||
return p.Owner != nil && *p.Owner != uuid.Nil
|
||||
}
|
||||
|
||||
func (p Planet) OwnedBy(v uuid.UUID) bool {
|
||||
if !p.Owned() {
|
||||
return false
|
||||
}
|
||||
return *p.Owner == v
|
||||
}
|
||||
|
||||
func (p *Planet) Mat(v float64) {
|
||||
|
||||
Reference in New Issue
Block a user