123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260 |
- package main
- import (
- "fmt"
- "math/rand"
- )
- type PlanetType uint8
- func (p PlanetType) String() string {
- switch p {
- case EarthLike:
- return "Earth-Like"
- case Mountain:
- return "Mountain"
- case Ocean:
- return "Oceanic"
- case Volcanic:
- return "Volcanic"
- case Glacial:
- return "Glacial"
- default:
- return ""
- }
- }
- func (p PlanetType) Symbol() string {
- switch p {
- case EarthLike:
- return "E"
- case Mountain:
- return "M"
- case Ocean:
- return "O"
- case Volcanic:
- return "V"
- case Glacial:
- return "G"
- default:
- return ""
- }
- }
- func (p PlanetType) ProductionOre() int {
- switch p {
- case EarthLike:
- return 6
- case Mountain:
- return 4
- case Ocean:
- return 8
- case Volcanic:
- return 3
- case Glacial:
- return 10
- default:
- return -1
- }
- }
- func (p PlanetType) ProductionOrg() int {
- switch p {
- case EarthLike:
- return 5
- case Mountain:
- return 8
- case Ocean:
- return 3
- case Volcanic:
- return -1
- case Glacial:
- return -1
- default:
- return -1
- }
- }
- func (p PlanetType) ProductionEqu() int {
- switch p {
- case EarthLike:
- return 8
- case Mountain:
- return 6
- case Ocean:
- return 7
- case Volcanic:
- return -1
- case Glacial:
- return 10
- default:
- return -1
- }
- }
- func (p PlanetType) ProductionFig() int {
- switch p {
- case EarthLike:
- return 10
- case Mountain:
- return 7
- case Ocean:
- return 4
- case Volcanic, Glacial:
- return 12
- default:
- return -1
- }
- }
- func (p PlanetType) ProductionShield() int {
- switch p {
- case EarthLike:
- return 25
- case Mountain:
- return 20
- case Ocean:
- return 28
- case Volcanic:
- return 29
- case Glacial:
- return 30
- default:
- return -1
- }
- }
- const (
- EarthLike PlanetType = iota
- Mountain
- Ocean
- Volcanic
- Glacial
- )
- type Planet struct {
- ID ID
- Name string
- Owner ID
- CorpOwned bool
- Type PlanetType
- CitadelLvl uint16
- TeleportDist uint64
- TeleportShipDist uint64
- WarpDist uint64
- Credits uint64
- Shields uint64
-
- CannonSector uint8
- CannonLanding uint8
-
- FighterLanding uint8
-
- Population uint64
- Ore uint64
- MaxOre uint64
- Org uint64
- MaxOrg uint64
- Equ uint64
- MaxEqu uint64
- Fighters uint64
-
- ProductOre uint64
- ProductOrg uint64
- ProductEqu uint64
- }
- func (p *Planet) Produce() string {
- out := ""
- if p.Type.ProductionOre() != -1 {
- ore := p.ProductOre / uint64(p.Type.ProductionOre())
- if p.Ore+ore > p.MaxOre {
- over := p.MaxOre - (p.Ore + ore)
- out += fmt.Sprintf("Ore Produced: %d (%d over)", ore, over)
- p.Ore += ore - over
- } else {
- out += fmt.Sprintf("Ore Produced: %d", ore)
- p.Ore += ore
- }
- }
- if p.Type.ProductionOrg() != -1 {
- org := p.ProductOrg / uint64(p.Type.ProductionOrg())
- if len(out) != 0 {
- out += "\r\n"
- }
- if p.Org+org > p.MaxOrg {
- over := p.MaxOrg - (p.Org + org)
- out += fmt.Sprintf("Organics Produced: %d (%d over)", org, over)
- p.Org += org - over
- } else {
- out += fmt.Sprintf("Organics Produced: %d", org)
- p.Org += org
- }
- }
- if p.Type.ProductionEqu() != -1 {
- equ := p.ProductEqu / uint64(p.Type.ProductionEqu())
- if len(out) != 0 {
- out += "\r\n"
- }
- if p.Equ+equ > p.MaxEqu {
- over := p.MaxEqu - (p.Equ + equ)
- out += fmt.Sprintf("Equipment Produced: %d (%d over)", equ, over)
- p.Equ += equ - over
- } else {
- out += fmt.Sprintf("Equipment Produced: %d", equ)
- p.Equ += equ
- }
- }
- if p.Type.ProductionFig() != -1 {
- amt := p.Population / uint64(p.Type.ProductionFig())
- if len(out) != 0 {
- out += "\r\n"
- }
- out += fmt.Sprintf("Fighters Produced: %d", amt)
- p.Fighters += amt
- }
- if p.Type.ProductionShield() != -1 {
- amt := p.Population / uint64(p.Type.ProductionShield())
- if len(out) != 0 {
- out += "\r\n"
- }
- out += fmt.Sprintf("Shields Produced: %d", amt)
- p.Shields += amt
- }
-
-
-
- if p.Population >= 100 && rand.Intn(21)+1 >= 12 {
- perc := int64(p.Population % 100)
- amt := uint64(rand.Int63n(perc + 1))
- if amt == 0 {
- out += "\r\n"
- return out
- }
- if len(out) != 0 {
- out += "\r\n"
- }
- out += fmt.Sprintf("Population Growth: %d", amt)
- p.Population += amt
- } else if p.Population >= 100 {
- perc := int64(p.Population % 100)
- amt := uint64(rand.Int63n(perc + 1))
- if amt == 0 {
- out += "\r\n"
- return out
- }
- if len(out) != 0 {
- out += "\r\n"
- }
- if p.Population < amt {
- amt = p.Population
- }
- out += fmt.Sprintf("Population Decline: %d", amt)
- p.Population -= amt
- if p.Population == 0 {
- out += "\r\nNo Population!"
- }
- }
- out += "\r\n"
- return out
- }
|