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

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

  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.constants import BUILD_RESULT 
 23  from horizons.ai.aiplayer.goal.settlementgoal import SettlementGoal 
 24  from horizons.constants import RES 
25 26 27 -class ProductionChainGoal(SettlementGoal):
28 - def __init__(self, settlement_manager, resource_id, name):
29 super().__init__(settlement_manager) 30 self.chain = settlement_manager.production_chain[resource_id] 31 self.name = name 32 self._may_import = True
33 34 @property
35 - def active(self):
36 return super().active and self._is_active
37
38 - def execute(self):
39 result = self.chain.build(self._needed_amount) 40 if result != BUILD_RESULT.ALL_BUILT and result != BUILD_RESULT.SKIP: 41 self._log_generic_build_result(result, self.name) 42 return self._translate_build_result(result)
43
44 - def _update_needed_amount(self):
45 self._needed_amount = self.settlement_manager.get_resource_production_requirement(self.chain.resource_id) * \ 46 self.settlement_manager.personality.production_level_multiplier
47
48 - def update(self):
49 super().update() 50 if self.can_be_activated: 51 self._update_needed_amount() 52 self._current_amount = self.chain.reserve(self._needed_amount, self._may_import) 53 self._is_active = self.chain.need_to_build_more_buildings(self._needed_amount) 54 else: 55 self._is_active = False
56
57 58 -class FaithGoal(ProductionChainGoal):
59 - def __init__(self, settlement_manager):
60 super().__init__(settlement_manager, RES.FAITH, 'pavilion')
61
62 - def get_personality_name(self):
63 return 'FaithGoal'
64
65 66 -class TextileGoal(ProductionChainGoal):
67 - def __init__(self, settlement_manager):
68 super().__init__(settlement_manager, RES.TEXTILE, 'textile producer')
69
70 - def get_personality_name(self):
71 return 'TextileGoal'
72
73 74 -class BricksGoal(ProductionChainGoal):
75 - def __init__(self, settlement_manager):
76 super().__init__(settlement_manager, RES.BRICKS, 'bricks producer')
77
78 - def get_personality_name(self):
79 return 'BricksGoal'
80
81 82 -class EducationGoal(ProductionChainGoal):
83 - def __init__(self, settlement_manager):
84 super().__init__(settlement_manager, RES.EDUCATION, 'school')
85
86 - def get_personality_name(self):
87 return 'EducationGoal'
88 89 @property
90 - def can_be_activated(self):
91 return super().can_be_activated and self.settlement_manager.get_resource_production(RES.BRICKS) > 0
92
93 94 -class GetTogetherGoal(ProductionChainGoal):
95 - def __init__(self, settlement_manager):
96 super().__init__(settlement_manager, RES.GET_TOGETHER, 'get-together producer')
97
98 - def get_personality_name(self):
99 return 'GetTogetherGoal'
100 101 @property
102 - def can_be_activated(self):
103 return super().can_be_activated and self.settlement_manager.get_resource_production(RES.BRICKS) > 0
104
105 106 -class ToolsGoal(ProductionChainGoal):
107 - def __init__(self, settlement_manager):
108 super().__init__(settlement_manager, RES.TOOLS, 'tools producer')
109
110 - def get_personality_name(self):
111 return 'ToolsGoal'
112 113 @property
114 - def can_be_activated(self):
115 return super().can_be_activated \ 116 and self.production_builder.have_deposit(RES.RAW_IRON) \ 117 and self.settlement_manager.get_resource_production(RES.BRICKS) > 0
118
119 120 -class BoardsGoal(ProductionChainGoal):
121 - def __init__(self, settlement_manager):
122 super().__init__(settlement_manager, RES.BOARDS, 'boards producer')
123
124 - def get_personality_name(self):
125 return 'BoardsGoal'
126
127 128 -class FoodGoal(ProductionChainGoal):
129 - def __init__(self, settlement_manager):
130 super().__init__(settlement_manager, RES.FOOD, 'food producer')
131
132 - def get_personality_name(self):
133 return 'FoodGoal'
134
135 136 -class CommunityGoal(ProductionChainGoal):
137 - def __init__(self, settlement_manager):
138 super().__init__(settlement_manager, RES.COMMUNITY, 'main square')
139
140 - def get_personality_name(self):
141 return 'CommunityGoal'
142
143 144 -class TobaccoProductsGoal(ProductionChainGoal):
145 - def __init__(self, settlement_manager):
146 super().__init__(settlement_manager, RES.TOBACCO_PRODUCTS, 'tobacco products producer')
147
148 - def get_personality_name(self):
149 return 'TobaccoProductsGoal'
150
151 152 -class MedicalHerbsProductsGoal(ProductionChainGoal):
153 - def __init__(self, settlement_manager):
154 super().__init__(settlement_manager, RES.MEDICAL_HERBS, 'medical herbs products producer')
155
156 - def get_personality_name(self):
157 return 'MedicalHerbsProductsGoal'
158
159 160 -class SaltGoal(ProductionChainGoal):
161 - def __init__(self, settlement_manager):
162 super().__init__(settlement_manager, RES.SALT, 'salt producer')
163
164 - def get_personality_name(self):
165 return 'SaltGoal'
166