1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- package main
- import "slices"
- type Sector struct {
- ID ID
- Beacon string
- NavHaz uint8
- Warps []ID
- Port ID
- Planets []ID
-
- Fighters []ID
- Mines []ID
- TrackerMines []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
- }
|