# HG changeset patch # User Simon Cross # Date 1258818932 0 # Node ID 1d0cc37b4e140fe0523463b49e558a5d20c6fe52 # Parent fbef17cab632fa84a8f4f1d7b182d8cac27e2d4d Add method for clearing all chickens (will be useful later). Cache animal positions only just before night starts. Range-check position before adding it to the cache. diff -r fbef17cab632 -r 1d0cc37b4e14 gamelib/gameboard.py --- a/gamelib/gameboard.py Sat Nov 21 15:53:17 2009 +0000 +++ b/gamelib/gameboard.py Sat Nov 21 15:55:32 2009 +0000 @@ -369,12 +369,12 @@ self.tv.sun(False) self.reset_states() self.toolbar.update_fin_tool(self.day) - self._cache_animal_positions() self.spawn_foxes() self.eggs = 0 for chicken in self.chickens.copy(): chicken.start_night(self) self.toolbar.update_egg_counter(self.eggs) + self._cache_animal_positions() def start_day(self): self.day, self.night = True, False @@ -788,6 +788,10 @@ self.remove_fox(fox) self.foxes = set() # Remove all the foxes + def clear_chickens(self): + for chicken in self.chickens.copy(): + self.remove_chicken(chicken) + def run_animations(self): # For legacy. if self.toolbar.anim_clear_tool: @@ -820,7 +824,8 @@ self._add_to_pos_cache(chick, 'chicken') def _add_to_pos_cache(self, animal, cache_type): - self._pos_cache[cache_type][animal.pos.x][animal.pos.y][animal.pos.z] = animal + if self.in_bounds(animal.pos): + self._pos_cache[cache_type][animal.pos.x][animal.pos.y][animal.pos.z] = animal def _update_pos_cache(self, old_pos, animal, cache_type): if self.in_bounds(old_pos) and self._pos_cache[cache_type]: