Merge branch 'master' of git://ctpug.org.za/naja
authorDavid Sharpe <decoydavid@gmail.com>
Sat, 17 May 2014 20:17:42 +0000 (22:17 +0200)
committerDavid Sharpe <decoydavid@gmail.com>
Sat, 17 May 2014 20:17:42 +0000 (22:17 +0200)
1  2 
naja/actions.py

diff --combined naja/actions.py
index 9513a0a32ad2bb15843220049e98e49ce69f62be,395a1f502d63aa4e73f24a7761fe500d72c1ebf8..5701109fec37a31959b73c9fe02b2cd77772a9df
@@@ -16,6 -16,9 +16,9 @@@ class LocationAction(object)
          self.required_bits = required_bits
          self.data = data
  
+     def sanity_check(self, location):
+         pass
      def get_glyphs(self):
          return self.GLYPHS
  
@@@ -116,7 -119,7 +119,7 @@@ class ClearBits(LocationAction)
  
  
  class ClearBitsAndHealth(LocationAction):
 -    TEXT = "Clear %(location_bits)s and {HEALTH}."
 +    TEXT = "Clear %(location_bits)s and lose {HEALTH}."
      GLYPHS = (ACTION_GLYPHS.CLEAR_BITS, ACTION_GLYPHS.DAMAGE)
  
      def perform_action(self, board, location):
@@@ -153,6 -156,16 +156,16 @@@ class GenericBits(LocationAction)
          self.acquire_win = self.data.get('acquire_win', False)
          self.lose_health = self.data.get('lose_health', False)
  
+     def sanity_check(self, location):
+         missing_bits = set()
+         missing_bits.update(self.set_bits - set(location.bitwise_operand))
+         missing_bits.update(self.clear_bits - set(location.bitwise_operand))
+         missing_bits.update(self.toggle_bits - set(location.bitwise_operand))
+         if missing_bits:
+             raise ValueError(
+                 "Location %s missing bits %r"
+                 % (location.card_name, sorted(list(missing_bits))))
      def perform_action(self, board, location):
          bits = board.player.bits
          bits.set_bits(self.set_bits)