func (self *Graph) Coasts(prov common.Province) (result []common.Province) { if node, ok := self.nodes[prov.Super()]; ok { for _, sub := range node.subs { result = append(result, sub.getName()) } } return }
func (self *Graph) edges(n common.Province) (result map[common.Province]*edge) { p, c := n.Split() if node, ok := self.nodes[p]; ok { if sub, ok := node.subs[c]; ok { result = sub.edges } } return }
func (self *Graph) Flags(n common.Province) (result map[common.Flag]bool) { p, c := n.Split() if node, ok := self.nodes[p]; ok { if sub, ok := node.subs[c]; ok { result = sub.flags } } return }
func (self *Graph) Has(n common.Province) (result bool) { p, c := n.Split() if node, ok := self.nodes[p]; ok { if _, ok := node.subs[c]; ok { result = true } } return }
func (self *Graph) Prov(n common.Province) *subNode { p, c := n.Split() if self.nodes[p] == nil { self.nodes[p] = &node{ name: p, subs: make(map[common.Province]*subNode), graph: self, } } return self.nodes[p].sub(c) }
func (self *Graph) AllFlags(n common.Province) (result map[common.Flag]bool) { result = map[common.Flag]bool{} p, _ := n.Split() if node, ok := self.nodes[p]; ok { for _, sub := range node.subs { for flag, _ := range sub.flags { result[flag] = true } } } return }
func (self *State) AddBounce(src, dst common.Province) { if existing, ok := self.bounces[dst.Super()]; ok { existing[src.Super()] = true } else { self.bounces[dst.Super()] = map[common.Province]bool{ src.Super(): true, } } }
func (self *State) Order(prov common.Province) (o common.Order, p common.Province, ok bool) { if o, ok = self.orders[prov]; ok { p = prov return } sup, _ := prov.Split() if o, ok = self.orders[sup]; ok { p = sup return } for _, name := range self.graph.Coasts(prov) { if o, ok = self.orders[name]; ok { p = name return } } return }
func (self *State) SupplyCenter(prov common.Province) (n common.Nation, p common.Province, ok bool) { if n, ok = self.supplyCenters[prov]; ok { p = prov return } sup, _ := prov.Split() if n, ok = self.supplyCenters[sup]; ok { p = sup return } for _, name := range self.graph.Coasts(prov) { if n, ok = self.supplyCenters[name]; ok { p = name return } } return }
func (self *State) Unit(prov common.Province) (u common.Unit, p common.Province, ok bool) { if u, ok = self.units[prov]; ok { p = prov return } sup, _ := prov.Split() if u, ok = self.units[sup]; ok { p = sup return } for _, name := range self.graph.Coasts(prov) { if u, ok = self.units[name]; ok { p = name return } } return }
func (self *State) Bounce(src, dst common.Province) bool { if sources, ok := self.bounces[dst.Super()]; ok { if dislodger, ok := self.dislodgers[dst.Super()]; ok { if len(sources) == 1 && sources[dislodger.Super()] { return false } } return true } if self.dislodgers[dst.Super()] == src.Super() { return true } return false }
func (self *Graph) SC(n common.Province) (result *common.Nation) { if node, ok := self.nodes[n.Super()]; ok { result = node.sc } return }
func (self *State) SetDislodger(attacker, victim common.Province) { self.dislodgers[attacker.Super()] = victim.Super() }