"""Functions and classes related to generating regions. """ from . import Utl, Node, Ifc, g def makelink(newnode, oldnode, direction): """Make reciprocal links between two nodes. This function takes two nodes and builds a link between them in the specified direction. @param newnode: The node the link is to. @type newnode: L{th.Node.Node} @param oldnode: The node the link is from. @type oldnode: L{th.Node.Node} @param direction: The direction the link is in. See L{th.Map} for possible directions. @type direction: L{int} """ if direction == 0: if oldnode: oldnode.north = newnode if newnode: newnode.south = oldnode elif direction == 1: if oldnode: oldnode.east = newnode if newnode: newnode.west = oldnode elif direction == 2: if oldnode: oldnode.south = newnode if newnode: newnode.north = oldnode elif direction == 3: if oldnode: oldnode.west = newnode if newnode: newnode.east = oldnode def gen_region(start, region_num, region_func): """Generate a region. This function is called by L{th.Map.genregions} with functions imported from the L{th.regions} modules. L{region_func} is called with L{start} as the first parameter, L{region_num} as the second parameter, and the initial direction of the region from the starting node as the third parameter. See L{th.Map} for possible directions. @type start: L{th.Node.Node} @type region_num: L{int} """ initdr, stop = Utl.rn(4), 0 while stop < 4: initdr = (initdr + 1) % 4 if (initdr == 0 and start.north) or (initdr == 1 and start.east) or \ (initdr == 2 and start.south) or (initdr == 3 and start.west): stop += 1 else: region_func(start, region_num, initdr) break class RegionBridge(Node.Node): """A node representing the bridge between the main grid and a region. """ def xinit(self): self.special_symbol = '&' self.description = """You are at a staircase in the steam tunnels. One way leads back out into the winding maze and one way leads deeper in.""" self.name = "Stairs Down" self.unique = True self.tunnel = False self.color = Ifc.BRIGHT_RED self.bridge = True self.north, self.south, self.east, self.west = ( self.src.north, self.src.south, self.src.east, self.src.west) if self.north: self.north.south = self if self.south: self.south.north = self if self.east: self.east.west = self if self.west: self.west.east = self self.mons, self.items = self.src.mons, self.src.items for o in self.mons + self.items: o.here = self self.x, self.y = self.pos = self.src.pos if self.src in g.nodes: g.nodes.remove(self.src) del self.src