Mercurial > rinkhals
comparison gamelib/animal.py @ 601:23fbf4651f99
Roosters.
author | Jeremy Thurgood <firxen@gmail.com> |
---|---|
date | Sun, 06 Dec 2009 10:11:37 +0000 |
parents | 50d6c68ce267 |
children |
comparison
equal
deleted
inserted
replaced
600:f9276a4f7bdf | 601:23fbf4651f99 |
---|---|
226 self.gameboard.tv.set(tree_pos.to_tile_tuple(), self.gameboard.GRASSLAND) | 226 self.gameboard.tv.set(tree_pos.to_tile_tuple(), self.gameboard.GRASSLAND) |
227 | 227 |
228 def lay(self): | 228 def lay(self): |
229 """See if the chicken lays an egg""" | 229 """See if the chicken lays an egg""" |
230 if self.abode and self.abode.building.HENHOUSE: | 230 if self.abode and self.abode.building.HENHOUSE: |
231 # TODO: Find a cleaner way to do this | |
232 fertilised = False | |
233 for bird in self.abode.building.occupants(): | |
234 if getattr(bird, 'ROOSTER', None): | |
235 fertilised = True | |
231 if not self.eggs: | 236 if not self.eggs: |
232 for x in range(random.randint(1, 4)): | 237 for x in range(random.randint(1, 4)): |
233 self.eggs.append(Egg(self.pos, self.gameboard)) | 238 self.eggs.append(Egg(self.pos, self.gameboard, fertilised=fertilised)) |
234 self.equip(equipment.NestEgg()) | 239 self.equip(equipment.NestEgg()) |
235 self.gameboard.eggs += self.get_num_eggs() | 240 self.gameboard.eggs += self.get_num_eggs() |
236 | 241 |
237 def remove_eggs(self): | 242 def remove_eggs(self): |
238 """Clean up the egg state""" | 243 """Clean up the egg state""" |
293 def reload_weapon(self): | 298 def reload_weapon(self): |
294 """If we have a weapon that takes ammunition, reload it.""" | 299 """If we have a weapon that takes ammunition, reload it.""" |
295 for weapon in self.weapons(): | 300 for weapon in self.weapons(): |
296 weapon.refresh_ammo() | 301 weapon.refresh_ammo() |
297 | 302 |
303 | |
304 class Rooster(Chicken): | |
305 """A rooster""" | |
306 | |
307 IMAGE_FILE = 'sprites/rooster.png' | |
308 ROOSTER = True | |
309 | |
310 AGGRESSION = 50 | |
311 | |
312 def lay(self): | |
313 # Roosters don't lay eggs. | |
314 pass | |
315 | |
316 def start_night(self): | |
317 Chicken.start_night(self) | |
318 self._manly_fight() | |
319 | |
320 def _manly_fight(self): | |
321 if self.abode: | |
322 for rival in [occ for occ in self.abode.building.occupants() | |
323 if getattr(occ, 'ROOSTER', False)]: | |
324 if random.randint(1, 100) <= self.AGGRESSION: | |
325 rival.damage() | |
326 | |
327 | |
298 class Egg(Animal): | 328 class Egg(Animal): |
299 """An egg""" | 329 """An egg""" |
300 | 330 |
301 IMAGE_FILE = 'sprites/equip_egg.png' | 331 IMAGE_FILE = 'sprites/equip_egg.png' |
302 | 332 |
303 SIMPLIFY = Animal.SIMPLIFY + ['timer'] | 333 SIMPLIFY = Animal.SIMPLIFY + ['timer', 'fertilised'] |
304 | 334 |
305 def __init__(self, pos, gameboard): | 335 def __init__(self, pos, gameboard, fertilised=False): |
306 Animal.__init__(self, pos, gameboard) | 336 Animal.__init__(self, pos, gameboard) |
337 self.fertilised = fertilised | |
307 self.timer = 2 | 338 self.timer = 2 |
308 | 339 |
309 # Eggs don't move | 340 # Eggs don't move |
310 | 341 |
311 def hatch(self): | 342 def hatch(self): |
312 self.timer -= 1 | 343 self.timer -= 1 |
313 if self.timer == 0: | 344 if self.timer == 0 and self.fertilised: |
314 return Chicken(self.pos, self.gameboard) | 345 return random.choice([Chicken, Rooster])(self.pos, self.gameboard) |
315 return None | 346 return None |
347 | |
316 | 348 |
317 class Fox(Animal): | 349 class Fox(Animal): |
318 """A fox""" | 350 """A fox""" |
319 | 351 |
320 STEALTH = 20 | 352 STEALTH = 20 |