sector.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package main
  2. import "slices"
  3. type Sector struct {
  4. ID ID
  5. Beacon string
  6. NavHaz uint8
  7. Warps []ID // Sector
  8. Port ID // Port
  9. Planets []ID // Planet
  10. // Deploy-ables
  11. Fighters []ID // DeployedFighter
  12. Mines []ID // DeployedMine
  13. TrackerMines []ID // DeployedTrackerMine
  14. }
  15. func (s *Sector) IsWarp(to ID) bool {
  16. return slices.Contains(s.Warps, to)
  17. }
  18. func (s *Sector) WarpCount() int {
  19. return len(s.Warps)
  20. }
  21. func (s *Sector) HasPort() bool {
  22. return s.Port != 0
  23. }
  24. func (s *Sector) HazChance() int {
  25. if s.NavHaz > 5 {
  26. return 0
  27. }
  28. return int(s.NavHaz) / 2
  29. }
  30. func (s *Sector) HazDamage() int {
  31. if s.NavHaz > 5 {
  32. return 0
  33. }
  34. return int(s.NavHaz) * 8
  35. }
  36. func (s *Sector) WarpLink(from ID) {
  37. if s.IsWarp(from) {
  38. return
  39. }
  40. if s.WarpCount() >= 6 {
  41. return
  42. }
  43. s.Warps = append(s.Warps, from)
  44. }
  45. func (s *Sector) WarpDeLink(from ID) {
  46. if !s.IsWarp(from) {
  47. return
  48. }
  49. wps := make([]ID, s.WarpCount()-1)
  50. for _, w := range s.Warps {
  51. if w != from {
  52. wps = append(wps, w)
  53. }
  54. }
  55. s.Warps = wps
  56. }