Package horizons :: Package ai :: Package aiplayer :: Package goal :: Module feederchaingoal
[hide private]
[frames] | no frames]

Source Code for Module horizons.ai.aiplayer.goal.feederchaingoal

  1  # ################################################### 
  2  # Copyright (C) 2008-2017 The Unknown Horizons Team 
  3  # team@unknown-horizons.org 
  4  # This file is part of Unknown Horizons. 
  5  # 
  6  # Unknown Horizons is free software; you can redistribute it and/or modify 
  7  # it under the terms of the GNU General Public License as published by 
  8  # the Free Software Foundation; either version 2 of the License, or 
  9  # (at your option) any later version. 
 10  # 
 11  # This program is distributed in the hope that it will be useful, 
 12  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
 13  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 14  # GNU General Public License for more details. 
 15  # 
 16  # You should have received a copy of the GNU General Public License 
 17  # along with this program; if not, write to the 
 18  # Free Software Foundation, Inc., 
 19  # 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA 
 20  # ################################################### 
 21   
 22  from horizons.ai.aiplayer.goal.productionchaingoal import ProductionChainGoal 
 23  from horizons.constants import RES 
24 25 26 -class FeederChainGoal(ProductionChainGoal):
27 """ 28 Objects of this class are used for production chains on feeder islands 29 The update call reserved the production for the (non-existent) settlement so it can't be transferred. 30 The late_update call declares that the settlement doesn't need it after all thus freeing it. 31 TODO: make that a single explicit action: right now import quotas are deleted by the first step which can make it look like less resources can be imported. 32 """ 33
34 - def __init__(self, settlement_manager, resource_id, name):
35 super().__init__(settlement_manager, resource_id, name) 36 self._may_import = False 37 self._feeder_personality = self.owner.personality_manager.get('FeederChainGoal')
38 39 @property
40 - def priority(self):
41 return super().priority + self._feeder_personality.extra_priority
42
43 - def execute(self):
44 self.chain.reserve(self._needed_amount, self._may_import) 45 result = super().execute() 46 self.chain.reserve(0, False) 47 return result
48
49 - def _update_needed_amount(self):
50 self._needed_amount = self.settlement_manager.get_ideal_production_level(self.chain.resource_id)
51
52 - def update(self):
53 super().update() 54 self.chain.reserve(0, False)
55
56 57 -class FeederFoodGoal(FeederChainGoal):
58 - def __init__(self, settlement_manager):
59 super().__init__(settlement_manager, RES.FOOD, 'food producer')
60
61 - def get_personality_name(self):
62 return 'FoodGoal'
63
64 65 -class FeederTextileGoal(FeederChainGoal):
66 - def __init__(self, settlement_manager):
67 super().__init__(settlement_manager, RES.TEXTILE, 'textile producer')
68
69 - def get_personality_name(self):
70 return 'TextileGoal'
71
72 73 -class FeederLiquorGoal(FeederChainGoal):
74 - def __init__(self, settlement_manager):
75 super().__init__(settlement_manager, RES.LIQUOR, 'liquor producer')
76
77 - def get_personality_name(self):
78 return 'LiquorGoal'
79 80 @property
81 - def can_be_activated(self):
82 return super().can_be_activated and self.settlement_manager.get_resource_production(RES.BRICKS) > 0
83
84 85 -class FeederTobaccoProductsGoal(FeederChainGoal):
86 - def __init__(self, settlement_manager):
87 super().__init__(settlement_manager, RES.TOBACCO_PRODUCTS, 'tobacco products producer')
88
89 - def get_personality_name(self):
90 return 'FeederTobaccoProductsGoal'
91 92 @property
93 - def can_be_activated(self):
94 return super().can_be_activated and self.settlement_manager.get_resource_production(RES.BRICKS) > 0
95
96 97 -class FeederMedicalProductsGoal(FeederChainGoal):
98 - def __init__(self, settlement_manager):
99 super().__init__(settlement_manager, RES.MEDICAL_HERBS, 'medical herbs producer')
100
101 - def get_personality_name(self):
102 return 'FeederMedicalProductsGoal'
103 104 @property
105 - def can_be_activated(self):
106 return super().can_be_activated and self.settlement_manager.get_resource_production(RES.BRICKS) > 0
107
108 109 -class FeederSaltGoal(FeederChainGoal):
110 - def __init__(self, settlement_manager):
111 super().__init__(settlement_manager, RES.SALT, 'salt producer')
112
113 - def get_personality_name(self):
114 return 'FeederSaltGoal'
115