# HG changeset patch # User Simon Cross # Date 1258820907 0 # Node ID 42777630956afd281760bdaa06b56e614042819c # Parent a356e57529ea1a3340081bf5becbda5de1402b07 Add ammo to things serialized and deserialized. diff -r a356e57529ea -r 42777630956a gamelib/animal.py --- a/gamelib/animal.py Sat Nov 21 16:21:38 2009 +0000 +++ b/gamelib/animal.py Sat Nov 21 16:28:27 2009 +0000 @@ -275,12 +275,8 @@ def reload_weapon(self): """If we have a weapon that takes ammunition, reload it.""" - if not self.weapons(): - # Nothing to reload - return for weapon in self.weapons(): - if hasattr(weapon, 'AMMUNITION'): - weapon.ammunition = weapon.AMMUNITION + weapon.refresh_ammo() class Egg(Animal): """An egg""" diff -r a356e57529ea -r 42777630956a gamelib/equipment.py --- a/gamelib/equipment.py Sat Nov 21 16:21:38 2009 +0000 +++ b/gamelib/equipment.py Sat Nov 21 16:28:27 2009 +0000 @@ -12,17 +12,20 @@ DRAW_LAYER = 0 UNDER_LIMB = False UNDER_EYE = False + AMMUNITION = None SIMPLIFY = [ '_buy_price', '_sell_price', '_name', + 'ammunition', ] def __init__(self): self._buy_price = self.BUY_PRICE self._sell_price = self.SELL_PRICE self._name = self.NAME + self.refresh_ammo() def make(cls): """Override default Simplifiable object creation.""" @@ -58,6 +61,9 @@ eq_image_right.blit(eye_right, (0,0)) return eq_image_left, eq_image_right, self.DRAW_LAYER + def refresh_ammo(self): + self.ammunition = getattr(self, 'AMMUNITION', None) + class Weapon(Equipment): IS_WEAPON = True DRAW_LAYER = 10 @@ -77,7 +83,7 @@ def hit(self, gameboard, wielder, target): """Is the potentially unlucky target actually unlucky?""" - if hasattr(self, 'AMMUNITION'): + if self.ammunition is not None: if self.ammunition <= 0: # Out of ammunition, so we don't get to shoot. return