Browse Source

Adds Sector, Port, and Planet

I use a ID (uint64) for Sectors, Ports and Planets, and probably for
Deplayables too (Fighters, Mines, Tracker Mines, etc).
Apollo 7 months ago
parent
commit
8fb82287d6
8 changed files with 146 additions and 4 deletions
  1. 1 1
      LICENSE
  2. 4 3
      README.md
  3. 3 0
      go.mod
  4. 43 0
      planet.go
  5. 30 0
      port.go
  6. 61 0
      sector.go
  7. 1 0
      server.go
  8. 3 0
      utils.go

+ 1 - 1
LICENSE

@@ -1,5 +1,5 @@
 MIT License
-Copyright (c) <year> <copyright holders>
+Copyright (c) 2024 David Thielemann (Apollo)
 
 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
 

+ 4 - 3
README.md

@@ -1,4 +1,5 @@
-# TradeTrek
+# Trade Trek
 
-Trade Wars 2002 & Yankee Trader meet Star Trek (TOS)
-Golang Powered
+[Trade Wars 2002](http://tradewars.com/default.html) & [Yankee Trader](https://breakintochat.com/wiki/Yankee_Trader) meet the year 2024!
+
+[Golang](https://beanzilla.net/go) Powered

+ 3 - 0
go.mod

@@ -0,0 +1,3 @@
+module git.red-green.com/david/tradetrek
+
+go 1.23.0

+ 43 - 0
planet.go

@@ -0,0 +1,43 @@
+package main
+
+type PlanetType uint8
+
+const ( // Production: The Ratio is 1:X where X is the number of population designated
+	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
+)
+
+type Planet struct {
+	ID               ID
+	Name             string
+	Owner            ID
+	CorpOwned        bool
+	Type             PlanetType
+	CitadelLvl       uint16 // Lvl1 Unlocks Fighter Defense and Bank, Lvl2 Unlocks Planetary Cannon, Lvl3 Unlocks Production for Shields, Lvl4 Unlocks Teleport and TeleportShip, Lvl5 Unlocks Warp
+	TeleportDist     uint64 // Beam the player to another ship
+	TeleportShipDist uint64 // Beam the player in the current ship
+	WarpDist         uint64 // Move the planet
+	Credits          uint64
+	Shields          uint64
+	// Planetary Cannon Settings
+	CannonSector  uint8 // Percentage of fuel Ore too consume per shot when a non-corp or hostile ship enters the sector (1 ore to 5 damage)
+	CannonLanding uint8 // Percentage of fuel Ore too consume per shot when a non-corp or hostile ship attempts to land on the planet (1 ore to 10 damage)
+	// Planetary Defense (Fighter) Settings
+	FighterLanding uint8 // Percentage of fighters too attack a non-corp or hostile ship when they attempt to land on the planet (fighter odds 1:2, essentially double damage)
+	// Inventory
+	Population uint64 // Population in supposed 1,000s
+	Ore        uint64 // Per Ton
+	MaxOre     uint64
+	Org        uint64
+	MaxOrg     uint64
+	Equ        uint64
+	MaxEqu     uint64
+	Fighters   uint64 // Per Unit
+	// Production Settings
+	ProductOre uint64 // Population placed for fuel Ore production (based on planet type)
+	ProductOrg uint64 // Organics production
+	ProductEqu uint64 // Equipment production
+}

+ 30 - 0
port.go

@@ -0,0 +1,30 @@
+package main
+
+type PortType uint8
+
+const (
+	BBB PortType = iota
+	SSS
+	BBS
+	SBB
+	BSB
+	SBS
+	SSB
+	BSS
+	StarDock
+)
+
+type Port struct {
+	ID        ID
+	Name      string
+	Owner     ID
+	CorpOwned bool
+	Type      PortType
+	Credits   uint64
+	Ore       uint64
+	MaxOre    uint64
+	Org       uint64
+	MaxOrg    uint64
+	Equ       uint64
+	MaxEqu    uint64
+}

+ 61 - 0
sector.go

@@ -0,0 +1,61 @@
+package main
+
+import "slices"
+
+type Sector struct {
+	ID      ID
+	Beacon  string
+	NavHaz  uint8
+	Warps   []ID
+	Port    ID
+	Planets []ID
+}
+
+func (s *Sector) IsWarp(to ID) bool {
+	return slices.Contains(s.Warps, to)
+}
+
+func (s *Sector) WarpCount() int {
+	return len(s.Warps)
+}
+
+func (s *Sector) HasPort() bool {
+	return s.Port != 0
+}
+
+func (s *Sector) HazChance() int {
+	if s.NavHaz > 5 {
+		return 0
+	}
+	return int(s.NavHaz) / 2
+}
+
+func (s *Sector) HazDamage() int {
+	if s.NavHaz > 5 {
+		return 0
+	}
+	return int(s.NavHaz) * 8
+}
+
+func (s *Sector) WarpLink(from ID) {
+	if s.IsWarp(from) {
+		return
+	}
+	if s.WarpCount() >= 6 {
+		return
+	}
+	s.Warps = append(s.Warps, from)
+}
+
+func (s *Sector) WarpDeLink(from ID) {
+	if !s.IsWarp(from) {
+		return
+	}
+	wps := make([]ID, s.WarpCount()-1)
+	for _, w := range s.Warps {
+		if w != from {
+			wps = append(wps, w)
+		}
+	}
+	s.Warps = wps
+}

+ 1 - 0
server.go

@@ -0,0 +1 @@
+package main

+ 3 - 0
utils.go

@@ -0,0 +1,3 @@
+package main
+
+type ID uint64