sector.go 872 B

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