本文整理汇总了Python中horizons.world.production.productionline.ProductionLine.alter_production_time方法的典型用法代码示例。如果您正苦于以下问题:Python ProductionLine.alter_production_time方法的具体用法?Python ProductionLine.alter_production_time怎么用?Python ProductionLine.alter_production_time使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类horizons.world.production.productionline.ProductionLine
的用法示例。
在下文中一共展示了ProductionLine.alter_production_time方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_alter_production_time
# 需要导入模块: from horizons.world.production.productionline import ProductionLine [as 别名]
# 或者: from horizons.world.production.productionline.ProductionLine import alter_production_time [as 别名]
def test_alter_production_time(self):
data = { 'time': 10 }
line = ProductionLine(1, data)
self.assertEqual(line.time, 10)
line.alter_production_time(2)
self.assertEqual(line.time, 20)
# Test that it modifies the original value (10)
line.alter_production_time(2)
self.assertEqual(line.time, 20)
line.alter_production_time(1.5)
self.assertEqual(line.time, 15.0)
示例2: test_alter_production_time
# 需要导入模块: from horizons.world.production.productionline import ProductionLine [as 别名]
# 或者: from horizons.world.production.productionline.ProductionLine import alter_production_time [as 别名]
def test_alter_production_time(self):
self.add_line(1, 10, 0)
line = ProductionLine(1)
self.assertEqual(line.time, 10)
line.alter_production_time(2)
self.assertEqual(line.time, 20)
# Test that it modifies the original value (10)
line.alter_production_time(2)
self.assertEqual(line.time, 20)
line.alter_production_time(1.5)
self.assertEqual(line.time, 15.0)
示例3: Production
# 需要导入模块: from horizons.world.production.productionline import ProductionLine [as 别名]
# 或者: from horizons.world.production.productionline.ProductionLine import alter_production_time [as 别名]
#.........这里部分代码省略.........
self._add_listeners(check_now=True)
elif self._state == PRODUCTION.STATES.producing:
# restore scheduler call
Scheduler().add_new_object(self._get_producing_callback(), self, \
self._pause_remaining_ticks)
else:
assert False, 'Unhandled production state: %s' % self._pause_old_state
else: # do pause
# switch state
self._pause_old_state = self._state
self._state = PRODUCTION.STATES.paused
if self._pause_old_state in (PRODUCTION.STATES.waiting_for_res, \
PRODUCTION.STATES.inventory_full):
self._remove_listeners()
elif self._pause_old_state == PRODUCTION.STATES.producing:
# save when production finishes and remove that call
self._pause_remaining_ticks = \
Scheduler().get_remaining_ticks(self, self._get_producing_callback())
Scheduler().rem_call(self, self._get_producing_callback())
else:
assert False, 'Unhandled production state: %s' % self._state
self._changed()
def finish_production_now(self):
"""Makes the production finish now"""
if self._state != PRODUCTION.STATES.producing:
return
Scheduler().rem_call(self, self._get_producing_callback())
self._finished_producing()
def alter_production_time(self, modifier):
"""@see ProductionLine.alter_production_time"""
try:
self._prod_line.alter_production_time(modifier)
except AttributeError: # production line doesn't have this alter method
pass
def get_state_history_times(self, ignore_pause):
"""
Returns the part of time 0 <= x <= 1 the production has been in a state during the last history_length ticks.
"""
self._clean_state_history()
result = defaultdict(lambda: 0)
current_tick = Scheduler().cur_tick
pause_state = PRODUCTION.STATES.paused.index
first_relevant_tick = self._get_first_relevant_tick(ignore_pause)
num_entries = len(self._state_history)
for i in xrange(num_entries):
if ignore_pause and self._state_history[i][1] == pause_state:
continue
tick = self._state_history[i][0]
if tick >= current_tick:
break
next_tick = min(self._state_history[i + 1][0], current_tick) if i + 1 < num_entries else current_tick
if next_tick <= first_relevant_tick:
continue
relevant_ticks = next_tick - tick
if tick < first_relevant_tick:
# the beginning is not relevant
relevant_ticks -= first_relevant_tick - tick