# HG changeset patch # User Jeremy Thurgood # Date 1258807692 0 # Node ID 9096c237928c2968a56ecf5d9350bf8ba05588bb # Parent bdc4757e04979ad857d718c7c4208a4a89c40d60 Dear most illustrious brother, I seek your cooperation with the refactoring of egg layerings and the reloading of guns. Please to provide bank details. diff -r bdc4757e0497 -r 9096c237928c gamelib/animal.py --- a/gamelib/animal.py Sat Nov 21 12:07:01 2009 +0000 +++ b/gamelib/animal.py Sat Nov 21 12:48:12 2009 +0000 @@ -155,6 +155,10 @@ Animal.__init__(self, image_left, image_right, pos) self.eggs = [] + def start_night(self, gameboard): + self.lay(gameboard) + self.reload_weapon() + def _game_death(self, gameboard): gameboard.remove_chicken(self) @@ -162,12 +166,14 @@ """A free chicken will move away from other free chickens""" pass - def lay(self): + def lay(self, gameboard): """See if the chicken lays an egg""" - if not self.eggs: - for x in range(random.randint(1, 4)): - self.eggs.append(Egg(self.pos)) - self.equip(equipment.NestEgg()) + if self.abode and self.abode.building.HENHOUSE: + if not self.eggs: + for x in range(random.randint(1, 4)): + self.eggs.append(Egg(self.pos)) + self.equip(equipment.NestEgg()) + gameboard.eggs += self.get_num_eggs() def remove_eggs(self): """Clean up the egg state""" diff -r bdc4757e0497 -r 9096c237928c gamelib/buildings.py --- a/gamelib/buildings.py Sat Nov 21 12:07:01 2009 +0000 +++ b/gamelib/buildings.py Sat Nov 21 12:48:12 2009 +0000 @@ -68,6 +68,7 @@ BREAKABLE = False ABODE = False FLOORS = None + HENHOUSE = False def __init__(self, pos): """Initial image, tile vid position, size and tile number for building.""" @@ -316,6 +317,8 @@ NAME = 'Henhouse' FLOORS = [0] + HENHOUSE = True + class DoubleStoryHenHouse(HenHouse): """A double story hen house.""" @@ -368,9 +371,6 @@ """Return true if obj is a build class.""" return getattr(obj, "IS_BUILDING", False) and hasattr(obj, "NAME") -# Building hens can lay eggs in -HENHOUSES = [HenHouse.NAME, DoubleStoryHenHouse.NAME] - BUILDINGS = [] for name in dir(): obj = eval(name) diff -r bdc4757e0497 -r 9096c237928c gamelib/gameboard.py --- a/gamelib/gameboard.py Sat Nov 21 12:07:01 2009 +0000 +++ b/gamelib/gameboard.py Sat Nov 21 12:48:12 2009 +0000 @@ -369,9 +369,10 @@ self.toolbar.update_fin_tool(self.day) self._cache_animal_positions() self.spawn_foxes() - self.lay_eggs() + self.eggs = 0 for chicken in self.chickens: - chicken.reload_weapon() + chicken.start_night(self) + self.toolbar.update_egg_counter(self.eggs) def start_day(self): self.day, self.night = True, False @@ -453,7 +454,7 @@ chick = self.get_outside_chicken(tile_pos) if chick is None: building = self.get_building(tile_pos) - if building and building.NAME in buildings.HENHOUSES: + if building and building.HENHOUSE: self.open_building_dialog(building, do_sell) return do_sell(chick) @@ -479,7 +480,7 @@ return False building = self.get_building(tile_pos) - if building and building.NAME in buildings.HENHOUSES: + if building and building.HENHOUSE: self.open_building_dialog(building, do_sell) def select_animal_to_place(self, animal): @@ -875,18 +876,9 @@ self.buildings.append(building) self.tv.sprites.append(building, layer='buildings') - def lay_eggs(self): - self.eggs = 0 - for building in self.buildings: - if building.NAME in buildings.HENHOUSES: - for chicken in building.occupants(): - chicken.lay() - self.eggs += chicken.get_num_eggs() - self.toolbar.update_egg_counter(self.eggs) - def hatch_eggs(self): for building in self.buildings: - if building.NAME in buildings.HENHOUSES: + if building.HENHOUSE: for chicken in building.occupants(): new_chick = chicken.hatch(self) if new_chick: