# HG changeset patch # User Jeremy Thurgood # Date 1259429833 0 # Node ID 11c4cebfe4c51f124660a9d48719b5667da6832f # Parent dc8ff47371f2dca45b1ebae75a87641f2a8fe9f5 Preparatory work for woodland biodiversity. diff -r dc8ff47371f2 -r 11c4cebfe4c5 gamelib/animal.py --- a/gamelib/animal.py Sat Nov 28 17:37:10 2009 +0000 +++ b/gamelib/animal.py Sat Nov 28 17:37:13 2009 +0000 @@ -217,7 +217,7 @@ if self.has_axe(): pos_x, pos_y = self.pos.to_tile_tuple() surrounds = [Position(pos_x + dx, pos_y + dy) for dx in [-1, 0, 1] for dy in [-1, 0, 1]] - tree_options = [pos for pos in surrounds if self.gameboard.in_bounds(pos) and self.gameboard.tv.get(pos.to_tile_tuple()) == self.gameboard.WOODLAND] + tree_options = [pos for pos in surrounds if self.gameboard.in_bounds(pos) and self.gameboard.is_woodland_tile(pos)] if tree_options: num_trees_to_cut = random.randint(1, len(tree_options)) trees_to_cut = random.sample(tree_options, num_trees_to_cut) @@ -832,7 +832,7 @@ return False distance = watcher.pos.dist(watchee.pos) - 1 # Intervening forests get in the way a bit. - woods = len([pos for pos in positions if gameboard.tv.get(pos.to_tile_tuple()) == gameboard.WOODLAND]) + woods = len([pos for pos in positions if gameboard.is_woodland_tile(pos)]) roll = random.randint(1, 100) return roll > watchee.STEALTH - vision_bonus + range_penalty*distance + constants.WOODLAND_CONCEALMENT*woods diff -r dc8ff47371f2 -r 11c4cebfe4c5 gamelib/gameboard.py --- a/gamelib/gameboard.py Sat Nov 28 17:37:10 2009 +0000 +++ b/gamelib/gameboard.py Sat Nov 28 17:37:13 2009 +0000 @@ -75,7 +75,6 @@ GRASSLAND = tiles.REVERSE_TILE_MAP['grassland'] FENCE = tiles.REVERSE_TILE_MAP['fence'] - WOODLAND = tiles.REVERSE_TILE_MAP['woodland'] BROKEN_FENCE = tiles.REVERSE_TILE_MAP['broken fence'] SIMPLIFY = [ @@ -887,12 +886,14 @@ def advance_day(self): self.days += 1 + def is_woodland_tile(self, pos): + return tiles.TILE_MAP[self.tv.get(pos.to_tile_tuple())] == 'woodland' + def clear_foxes(self): for fox in self.foxes.copy(): # Any foxes that didn't make it to the woods are automatically # killed - if self.in_bounds(fox.pos) and \ - self.tv.get(fox.pos.to_tile_tuple()) != self.WOODLAND: + if self.in_bounds(fox.pos) and not self.is_woodland_tile(fox.pos): self.kill_fox(fox) else: self.remove_fox(fox) @@ -1114,7 +1115,7 @@ def trees_left(self): width, height = self.tv.size - return len([(x,y) for x in range(width) for y in range(height) if self.tv.get((x,y)) == self.WOODLAND]) + return len([(x,y) for x in range(width) for y in range(height) if self.is_woodland_tile(misc.Position(x,y))]) def calculate_wood_groat_exchange_rate(self): # per five planks diff -r dc8ff47371f2 -r 11c4cebfe4c5 gamelib/tiles.py --- a/gamelib/tiles.py Sat Nov 28 17:37:10 2009 +0000 +++ b/gamelib/tiles.py Sat Nov 28 17:37:13 2009 +0000 @@ -18,6 +18,10 @@ 4: ("guardtower", "grassland.png"), 5: ("broken fence", "broken_fence.png"), 6: ("hendominium", "grassland.png"), + + 255: ("woodland", "woodland.png"), + 254: ("woodland", "woodland2.png"), + 253: ("woodland", "woodland3.png"), } def __init__(self, tiles=None): @@ -25,6 +29,8 @@ tiles = self.DEFAULT_TILES.copy() self._tiles = tiles self._reverse_map = dict((v[0], k) for k, v in self._tiles.iteritems()) + # Wood is different: + self._reverse_map["woodland"] = 0 def __getitem__(self, n): """Get the string name of tile n."""