from . import Utl, Ifc, Monster, g VT100 = '\044V^\170<\155\154\164>\152\153\165\161\166\167\156' VTCHARS = ' ><\161^\153\154\167\V\152\155\166\170\165\164\156' class Node(object): def __repr__(self): if self in g.nodes: return '' % g.nodes.index(self) else: return '' __str__ = __repr__ def __eq__(self, other): return self is other def __hash__(self): return id(self) def describe(self): ret = "%s%s%s\n%s\n%s\n" % ( Ifc.color(self.color or Ifc.BOLD), self.name, Ifc.color(), self.description, self.link_description() ) mons = len(self.mons) - (g.player in self.mons) if mons == 0: ret += "You are alone.\n" elif mons > 0: if mons == 1: ret += "There is a creature here:\n" else: ret += "There are creatures here:\n" for mon in self.mons: if mon is not g.player: ret += " %s\n" % mon.describe() itms = len(self.items) if itms > 0: if itms == 1: ret += "There is an item here:\n" else: ret += "There are things here:\n" for itm in self.items: ret += " %s\n" % itm.describe() return ret def update(self): if g.player.here is not self and Utl.rn(1000) < self.spawn_chance: if self.spawn: self.add(Utl.rn_seq(self.spawn).make()) else: self.add(Monster.good_mon().make()) def link_description(self): ret = '' if self.north: ret += '%s to the north.\n' % self.describe_link(self.north) if self.south: ret += '%s to the south.\n' % self.describe_link(self.south) if self.east: ret += '%s to the east.\n' % self.describe_link(self.east) if self.west: ret += '%s to the west.\n' % self.describe_link(self.west) return ret def describe_link(self, n): if self.tunnel: if n.tunnel: return "The tunnel continues" else: return "The tunnel opens into %s%s %s%s" % (Ifc.color(n.color), 'the' if n.unique else 'a', n.name, Ifc.color()) else: if n.tunnel: return "There is a tunnel" else: return "There is another room, %s%s %s%s," % (Ifc.color(n.color), 'the' if n.unique else 'a', n.name, Ifc.color()) def add(self, obj): if isinstance(obj, Monster.Monster): trap_result = 1 if g.phase > 0 and not self.in_trap: self.in_trap = True trap_result = self.check_trap(obj, obj.here) if not trap_result: obj.here.add(obj) self.in_trap = False return self.in_trap = False if obj is g.player: self.visited = True self.locked = False g.seen.append(self) self.mons.append(obj) obj.here = self if trap_result == 2: self.do_trap(obj) else: self.items.append(obj) obj.here = self def check_trap(self, mon, coming_from): return 1 def do_trap(self, mon): pass def unbiased_character(self): ret = 0 if self.north: ret += 1 if self.south: ret += 2 if self.east: ret += 4 if self.west: ret += 8 return VT100[ret] def character(self): if self.special_symbol: return self.special_symbol else: return self.unbiased_character() def countexits( self ): ret = 0 if self.north: ret += 1 if self.south: ret += 1 if self.east: ret += 1 if self.west: ret += 1 return ret def gen_closemons(self, maxdepth=5): stack = [(self, 0)] seen = [] while stack: n, depth = stack.pop() for m in n.mons: yield m if depth < maxdepth: for v in [n.north, n.south, n.east, n.west]: if not v: continue if v not in seen: stack.append((v, maxdepth + 1)) def __init__(self, pos=(0, 0), **options): self.north = self.south = self.east = self.west = None self.mons = [] self.items = [] self.name = self.description = self.family = "Steam Tunnels Proper" self.spawn = [] self.unique = False self.bridge = False self.region = self.bridge_region = 0 self.locked = False self.special_symbol = None self.color = Ifc.DEFAULT_COLOR self.visited = False self.seen = False self.trav = False self.tunnel = False self.spawn_chance = 0 self.in_trap = False self.p_distance = {} self.p_nodes = {} self.dijkstra = None self.pos = tuple(pos) self.x, self.y = self.pos for key, value in options.iteritems(): setattr(self, key, value) self.xinit() self.xmake() g.nodes.append(self) def xinit(self): pass def xmake(self): pass