コード例 #1
0
ファイル: models.py プロジェクト: dmoisset/evolve
 def pre_apply_action(self):
     """
     Pre-apply action played
     (actions are applied in two phases)
     """
     assert self.action
     # Buildings need to be added first, so applied effects related to
     # existing buildings count other buildings built in the same turn
     if self.action in (self.BUILD_ACTION, self.FREE_ACTION):
         if self.action==self.BUILD_ACTION:
             item = self.option_picked.building
         else:
             item = self.next_special() 
         # Check payment. This needs to be done before building, so raising
         # a commercial building does not affect its own price, and building
         # a resource does not allow to pay for itself.
         # Anyway, build options should try to avoid that happening
         payment = economy.can_pay(
             self.payment_options(item), 
             self.trade_left,
             self.trade_right
         )
         assert payment is not None
         # Pay local money. Trade is handled later
         self.money -= payment.money
         self.buildings.add(self.option_picked.building)
コード例 #2
0
ファイル: models.py プロジェクト: dmoisset/evolve
 def play(self, action, option, trade_left, trade_right):
     """
     Choose to play the given action with the given build option.
     
     Note that this is the selection of the option, the action is not applied
     until the end of turn (which is checked at the end of this method).
     
     Preconditions:
      - action is one of the Player.ACTIONS
      - option in self.current_options.all()
      - option == FREE_ACTION implies self.can_build_free()
      - option == SPECIAL_ACTION implies self.can_build_special()
      - option == BUILD_ACTION implies option.cost can be paid with given trade
     """
     assert action in (name for name,label in self.ACTIONS)
     assert option in self.current_options.all()
     assert option != self.FREE_ACTION or self.can_build_free()
     assert option != self.SPECIAL_ACTION or self.can_build_special()
     assert option != self.BUILD_ACTION or economy.can_pay(self.payment_options(option.building), trade_left, trade_right)
     
     self.action = action
     self.option_picked = option
     self.trade_left = trade_left
     self.trade_right = trade_right
     self.save()
     
     self.game.turn_check()
コード例 #3
0
    def play(self, action, option, trade_left, trade_right):
        """
        Choose to play the given action with the given build option.
        
        Note that this is the selection of the option, the action is not applied
        until the end of turn (which is checked at the end of this method).
        
        Preconditions:
         - action is one of the Player.ACTIONS
         - option in self.current_options.all()
         - option == FREE_ACTION implies self.can_build_free()
         - option == SPECIAL_ACTION implies self.can_build_special()
         - option == BUILD_ACTION implies option.cost can be paid with given trade
        """
        assert action in (name for name, label in self.ACTIONS)
        assert option in self.current_options.all()
        assert option != self.FREE_ACTION or self.can_build_free()
        assert option != self.SPECIAL_ACTION or self.can_build_special()
        assert option != self.BUILD_ACTION or economy.can_pay(
            self.payment_options(option.building), trade_left, trade_right)

        self.action = action
        self.option_picked = option
        self.trade_left = trade_left
        self.trade_right = trade_right
        self.save()

        self.game.turn_check()
コード例 #4
0
 def pre_apply_action(self):
     """
     Pre-apply action played
     (actions are applied in two phases)
     """
     assert self.action
     # Buildings need to be added first, so applied effects related to
     # existing buildings count other buildings built in the same turn
     if self.action in (self.BUILD_ACTION, self.FREE_ACTION):
         if self.action == self.BUILD_ACTION:
             item = self.option_picked.building
         else:
             item = self.next_special()
         # Check payment. This needs to be done before building, so raising
         # a commercial building does not affect its own price, and building
         # a resource does not allow to pay for itself.
         # Anyway, build options should try to avoid that happening
         payment = economy.can_pay(self.payment_options(item),
                                   self.trade_left, self.trade_right)
         assert payment is not None
         # Pay local money. Trade is handled later
         self.money -= payment.money
         self.buildings.add(self.option_picked.building)