Browse Source

Added Deployables (Fighters, Mines, TrackerMines)

Also updated Sector with the new Deployables.

PlanetTypes now define Production values for Ore, Org, Equ, Fighters and Shields.

Planets can now Produce() which should return a string of what was produced (Useful for logging what happened during the every X hour "maintenance" period that happens on the Server)

There are some bugs in Planet.Produce() that need to be worked on (such as keeping the Population at even 100s won't cause any global growth or decline to happen)
david 7 months ago
parent
commit
2d0f3042f7
3 changed files with 276 additions and 6 deletions
  1. 49 0
      deployables.go
  2. 220 3
      planet.go
  3. 7 3
      sector.go

+ 49 - 0
deployables.go

@@ -0,0 +1,49 @@
+package main
+
+type FighterMode uint8
+
+const (
+	Attack FighterMode = iota
+	Toll
+	Pass
+)
+
+type DeployedFighter struct {
+	ID        ID
+	Amount    uint64
+	Mode      FighterMode
+	Owner     ID
+	CorpOwned bool
+}
+
+func (f *DeployedFighter) TollCost() uint64 {
+	if f.Mode != Toll {
+		return 0
+	}
+	return f.Amount * 3
+}
+
+func (f *DeployedFighter) Damage() int64 {
+	if f.Mode == Pass {
+		return 0
+	}
+	return int64(f.Amount) * 6
+}
+
+type DeployedMine struct {
+	ID        ID
+	Amount    uint64
+	Owner     ID
+	CorpOwned bool
+}
+
+func (m *DeployedMine) Damage() int64 {
+	return int64(m.Amount) * 15
+}
+
+type DeployedTrackerMine struct {
+	ID        ID
+	Amount    uint64
+	Owner     ID
+	CorpOwned bool
+}

+ 220 - 3
planet.go

@@ -1,13 +1,135 @@
 package main
 
+import (
+	"fmt"
+	"math/rand"
+)
+
 type PlanetType uint8
 
-const ( // Production: The Ratio is 1:X where X is the number of population designated
+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 ( // Production: The Ratio is 1:X where X is the number of population designated (This excludes Fighters and Shields, which are total population)
 	EarthLike PlanetType = iota // Production: Ore=1:6, Org=1:5, Equ=1:8, Fig=1:10, Shields=1:25
 	Mountain                    // Production: Ore=1:4, Org=1:8, Equ=1:6, Fig=1:7, Shields=1:20
 	Ocean                       // Production: Ore=1:8, Org=1:3, Equ=1:6, Fig=1:4, Shields=1:28
-	Volcanic                    // Production: Ore=NA, Org=NA, Equ=NA, Fig=NA, Shields=NA
-	Glacial                     // Production: Ore=1:7, Org=NA, Equ=1:7, Fig=1:12, Shields=1:30
+	Volcanic                    // Production: Ore=1:3, Org=NA, Equ=NA, Fig=1:12, Shields=1:29
+	Glacial                     // Production: Ore=1:10, Org=NA, Equ=1:10, Fig=1:12, Shields=1:30
 )
 
 type Planet struct {
@@ -41,3 +163,98 @@ type Planet struct {
 	ProductOrg uint64 // Organics production
 	ProductEqu uint64 // Equipment production
 }
+
+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
+	}
+	// TODO: Refine Population growth and declines
+	// Right now it's a 1d20 anything higher than 12 growth, lower than is decline
+	// Also the amount grown or declined is random of the same base math (out of ever 100 pop, so best to keep your planets at even 100s and nothing will ever happen!?!)
+	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
+}

+ 7 - 3
sector.go

@@ -6,9 +6,13 @@ type Sector struct {
 	ID      ID
 	Beacon  string
 	NavHaz  uint8
-	Warps   []ID
-	Port    ID
-	Planets []ID
+	Warps   []ID // Sector
+	Port    ID   // Port
+	Planets []ID // Planet
+	// Deploy-ables
+	Fighters     []ID // DeployedFighter
+	Mines        []ID // DeployedMine
+	TrackerMines []ID // DeployedTrackerMine
 }
 
 func (s *Sector) IsWarp(to ID) bool {