def place_passages(self): if not self.passages: return False passages = {} for which, passage in self.passages.items(): where, pos = passage if not pos: dist = r1d(self.size/2) + self.size/2 - 4 pos = Hexagon.perimeter(self.center, dist, random.choice(0, Hexagon.get_max_index(dist))).next() assert False, "Pos: %s" % str(pos) coords = Point(pos) self.cells[coords] = (dist, Stairs(which, where)) else: coords = Point(pos) self.cells[coords] = (None, Stairs(which, where)) passages[which] = self.cells[coords][1] # The terrain above self.passages = passages
def place_passages(self): """Place random stairs, then set their positions in a dict.""" if not self.passages: return False passages = {} perimeter = random.sample([h for h in Hexagon.perimeter(self.center, self.size - self.wall_width)], len(self.passages)) for which, passage in self.passages.items(): where, pos = passage if not pos: index, coords = perimeter.pop() # Block off the immediate surroundings. for rank, index, coords in Hexagon.area(coords): self.cells[coords] = (None, None) passages[which] = Path(which, where) self.cells[coords] = (None, passages[which]) self.passages = passages
def attempt(self): # Cornfield edge. for rank, index, coords in Hexagon.area(self.center, self.size): if rank >= self.size - self.wall_width: self.cells[coords] = (rank, self.place_corn()) else: self.cells[coords] = (rank, None) # TODO: Return corn rows. self.place_passages() return self.cells, self.passages
def draw(self, display): map_obj = self.level.get_map() self.center = self.get_focus() # Draw the encounter map. for rank, index, coords in Hexagon.area(self.center, self.zoom): if map_obj.valid(coords) is not False: glyph, col = self.get_glyph(map_obj, coords) else: glyph = ',' col = "red-black" display.hd(self, coords, glyph, col) # Draw highlights around the encounter map border. if len(self.get_controller().highlights) > 0: for highlight_id, highlight_obj in self.get_controller().highlights.items(): if Hexagon.distance(self.center, highlight_obj.coords) > self.viewport_rank: # TODO: Don't use Bresenham here, it flickers! continue cells = line(self.center, highlight_obj.coords, self.viewport_rank+2) cell = cells.pop() # TODO: Highlight color glyph, col = "*", "green-black" display.hd(self, cell, glyph, col)
def retarget(self): target = self.owner.call("Faction", "get_target").get_result() if target: self.target = target self.destination = self.target.coords debug.log("%s retargeted to %s." % (self.owner.appearance(), self.target.appearance())) return True destination = self.owner.call("Faction", "get_destination").get_result() if destination: self.destination = destination debug.log("%s found no target but instead a destination." % self.owner.appearance()) return True # Move somewhere random. debug.log("%s failed to retarget." % self.owner.appearance()) self.destination = random.choice([h for h in Hexagon.area(self.owner.coords, 10)]) return True
def attempt(self): for rank, index, coords in Hexagon.area(self.center, self.size): self.cells[coords] = (rank, None) self.place_passages()