本文整理汇总了Python中horizons.world.production.productionline.ProductionLine.get_original_copy方法的典型用法代码示例。如果您正苦于以下问题:Python ProductionLine.get_original_copy方法的具体用法?Python ProductionLine.get_original_copy怎么用?Python ProductionLine.get_original_copy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类horizons.world.production.productionline.ProductionLine
的用法示例。
在下文中一共展示了ProductionLine.get_original_copy方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Production
# 需要导入模块: from horizons.world.production.productionline import ProductionLine [as 别名]
# 或者: from horizons.world.production.productionline.ProductionLine import get_original_copy [as 别名]
class Production(ChangeListener):
"""Class for production to be used by ResourceHandler.
Controls production and starts it by watching the assigned building's inventory,
which is virtually the only "interface" to the building.
This ensures independence and encapsulation from the building code.
A Production is active by default, but you can pause it.
Before we can start production, we check certain assertions, i.e. if we have all the
resources, that the production takes and if there is enough space to store the produced goods.
It has basic states, which are useful for e.g. setting animation. Changes in state
can be observed via ChangeListener interface."""
log = logging.getLogger('world.production')
# optimisation:
# the special resource gold is only stored in the player's inventory.
# If productions want to use it, they will observer every change of it, which results in
# a lot calls. Therefore, this is not done by default but only for few subclasses that actually need it.
uses_gold = False
keep_original_prod_line = False
## INIT/DESTRUCT
def __init__(self, inventory, owner_inventory, prod_id, prod_data, \
start_finished=False, load=False, **kwargs):
"""
@param inventory: interface to the world, take res from here and put output back there
@param owner_inventory: same as inventory, but for gold. Usually the players'.
@param prod_id: int id of the production line
@param prod_data: ?
@param start_finished: Whether to start at the final state of a production
@param load: set to true if this production is supposed to load a saved production
"""
super(Production, self).__init__(**kwargs)
# this has grown to be a bit weird compared to other init/loads
# __init__ is always called before load, therefore load just overwrites some of the values here
self._state_history = deque()
self.prod_id = prod_id
self.prod_data = prod_data
self.__start_finished = start_finished
self.inventory = inventory
self.owner_inventory = owner_inventory
self._pause_remaining_ticks = None # only used in pause()
self._pause_old_state = None # only used in pause()
self._creation_tick = Scheduler().cur_tick
assert isinstance(prod_id, int)
self._prod_line = ProductionLine(id=prod_id, data=prod_data)
if self.__class__.keep_original_prod_line: # used by unit productions
self.original_prod_line = self._prod_line.get_original_copy()
if not load:
# init production to start right away
if self.__start_finished:
# finish the production
self._give_produced_res()
self._state = PRODUCTION.STATES.waiting_for_res
self._add_listeners(check_now=True)
def save(self, db, owner_id):
"""owner_id: worldid of the owner of the producer object that owns this production"""
self._clean_state_history()
current_tick = Scheduler().cur_tick
translated_creation_tick = self._creation_tick - current_tick + 1 # pre-translate the tick number for the loading process
remaining_ticks = None
if self._state == PRODUCTION.STATES.paused:
remaining_ticks = self._pause_remaining_ticks
elif self._state == PRODUCTION.STATES.producing:
remaining_ticks = Scheduler().get_remaining_ticks(self, self._get_producing_callback())
# use a number > 0 for ticks
if remaining_ticks < 1:
remaining_ticks = 1
db('INSERT INTO production(rowid, state, prod_line_id, remaining_ticks, _pause_old_state, creation_tick, owner) VALUES(?, ?, ?, ?, ?, ?, ?)', \
None, self._state.index, self._prod_line.id, remaining_ticks, \
None if self._pause_old_state is None else self._pause_old_state.index, translated_creation_tick, owner_id)
# save state history
for tick, state in self._state_history:
# pre-translate the tick number for the loading process
translated_tick = tick - current_tick + 1
db("INSERT INTO production_state_history(production, tick, state, object_id) VALUES(?, ?, ?, ?)", \
self.prod_id, translated_tick, state, owner_id)
def load(self, db, worldid):
# NOTE: __init__ must have been called with load=True
# worldid is the world id of the producer component instance calling this
super(Production, self).load(db, worldid)
db_data = db.get_production_by_id_and_owner(self.prod_id, worldid)
self._creation_tick = db_data[5]
self._state = PRODUCTION.STATES[db_data[0]]
self._pause_old_state = None if db_data[4] is None else PRODUCTION.STATES[db_data[4]]
if self._state == PRODUCTION.STATES.paused:
#.........这里部分代码省略.........