12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- 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
- }
|