def __init_production_lines(self): production_lines = self._get_producer_building( ).get_component_template(Producer)['productionlines'] for key, value in production_lines.iteritems(): production_line = ProductionLine(key, value) assert len(production_line.produced_res) == 1 self.lines[production_line.produced_res.keys() [0]] = production_line
def get_unit_production_queue(self): """Returns a list unit type ids that are going to be produced. Does not include the currently produced unit. List is in order.""" queue = [] for prod_line_id in self.production_queue: prod_line = ProductionLine(prod_line_id, self.production_lines[prod_line_id]) units = prod_line.unit_production.keys() if len(units) > 1: print 'WARNING: unit production system has been designed for 1 type per order' queue.append(units[0]) return queue
def __init_production_lines(self): production_lines = self._get_producer_building().get_component_template(Producer)['productionlines'] for key, value in production_lines.iteritems(): production_line = ProductionLine(key, value) production_line.id = None production_line.production = {} production_line.produced_res = {} for resource_id, amount in production_line.consumed_res.iteritems(): production_line.production[resource_id] = -amount production_line.produced_res[resource_id] = -amount production_line.consumed_res = {} self.lines[production_line.produced_res.keys()[0]] = production_line
def test_change_amount(self): data = {'time': 10, 'produces': [[2, 3]], 'consumes': [[4, -5]]} line = ProductionLine(1, data) line.change_amount(2, 10) self.assertEqual(line.production, {2: 10, 4: -5}) self.assertEqual(line.produced_res, {2: 10}) self.assertEqual(line.consumed_res, {4: -5}) line.change_amount(4, -1) self.assertEqual(line.production, {2: 10, 4: -1}) self.assertEqual(line.produced_res, {2: 10}) self.assertEqual(line.consumed_res, {4: -1})
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)
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 test_init(self): # NOTE: this has been broken by optimizations and will soon be moved to yaml, therefore not fixing it now #self.add_line(1, {10: 4, 12: 8}) data = {'enabled_by_default': False, 'time': 90, 'level': [0, 1, 2], 'changes_animation': False, 'produces': [[14, 1]], 'consumes': [[19, -1]] } line = ProductionLine(1, data) self.assertEqual(line.time, 90) self.assertEqual(line.changes_animation, False) self.assertEqual(line.production, {14: 1, 19: -1}) self.assertEqual(line.produced_res, {14: 1}) self.assertEqual(line.consumed_res, {19: -1})
def create_production_line(self, id): """Creates a production line instance, this is meant only for data transfer and READONLY use! If you want to use production lines for anything else, go the proper way of the production class.""" assert id in self.production_lines data = self.production_lines[id] return ProductionLine(id, data)
def _create_production_line(self, prod_line_id): """Returns a changeable production line instance""" return ProductionLine(prod_line_id)