package game import ( "math" "github.com/google/uuid" ) type UnidentifiedPlanet struct { X float64 `json:"x"` Y float64 `json:"y"` Number uint `json:"number"` } type UninhabitedPlanet struct { UnidentifiedPlanet Size float64 `json:"size"` Name string `json:"name"` Resources float64 `json:"resources"` // R - Ресурсы Capital float64 `json:"capital"` // CAP $ - Запасы промышленности Material float64 `json:"material"` // MAT M - Запасы ресурсов / сырьё } type PlanetReport struct { UninhabitedPlanet Industry float64 `json:"industry"` // I - Промышленность Population float64 `json:"population"` // P - Население Colonists float64 `json:"colonists"` // COL C - Количество колонистов Production Production `json:"production"` // TODO: internal/report format // Параметр "L" - Свободный производственный потенциал } type Planet struct { Owner uuid.UUID `json:"owner"` // FIXME: nil value when no owner Route map[RouteType]uint `json:"route"` PlanetReport } type PlanetReportForeign struct { RaceName string PlanetReport } // Производственный потенциал func (p Planet) ProductionCapacity() float64 { return PlanetProduction(p.Industry, p.Population) } func PlanetProduction(industry, population float64) float64 { return industry*0.75 + population*0.25 } // Производство промышленности // TODO: test on real values // [x] ind * 5 + ind / res = prod // [x] ind = (res * prod) / (5 * res + 1) // ind = 10 * 1000 / (5 * 10 + 1) = 10000 / 55 = 181.(81) // int = 10 * 500 / 55 = 5000 / 55 func (p *Planet) IncreaseIndustry() { production := p.ProductionCapacity() var ind float64 if p.Material > 0 { ind = math.Min(production/5, p.Material) p.Material -= ind production -= ind * 5. } ind += (production * p.Resources) / (5.*p.Resources + 1.) p.Industry += ind if p.Industry > p.Population { p.Capital += p.Industry - p.Population p.Industry = p.Population } } func (p *Planet) UnpackCAPtoIND() { if p.Capital == 0 { return } cap := p.Population - p.Industry if cap > p.Capital { cap = p.Capital } p.Capital -= cap p.Industry += cap } // Производство материалов // TODO: test on real values func (p *Planet) IncreaseMaterial() { p.Material += p.ProductionCapacity() * p.Resources } // Автоматическое увеличение населения на каждом ходу // TODO: test - whether POP is busy on production or not? func (p *Planet) IncreasePopulation() { p.Population *= 1.08 if p.Population > p.Size { p.Colonists += (p.Population - p.Size) / 8. p.Population = p.Size } } func (p *Planet) UnpackCOLtoPOP() { if p.Colonists < 1 { return } maxCOL := uint((p.Size - p.Population) / 8.) if float64(maxCOL) > p.Colonists { maxCOL = uint(p.Colonists) } maxCOL = uint(float64(maxCOL) - math.Mod(float64(maxCOL), 8.)) p.Colonists -= float64(maxCOL) p.Population += float64(maxCOL) * 8 } func UnloadColonists(p Planet, v float64) Planet { p.Population += v * 8 if p.Population > p.Size { p.Colonists += (p.Population - p.Size) / 8 p.Population = p.Size } return p }