当前位置: 首页>>代码示例>>Python>>正文


Python productionline.ProductionLine类代码示例

本文整理汇总了Python中horizons.world.production.productionline.ProductionLine的典型用法代码示例。如果您正苦于以下问题:Python ProductionLine类的具体用法?Python ProductionLine怎么用?Python ProductionLine使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ProductionLine类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _create_production_line

	def _create_production_line(self, prod_line_id):
		"""Returns a non-changeable production line instance"""
		try:
			return ProductionLine.data[prod_line_id]
		except KeyError:
			ProductionLine.load_data(prod_line_id)
			return ProductionLine.data[prod_line_id]
开发者ID:mitfik,项目名称:unknown-horizons,代码行数:7,代码来源:production.py

示例2: test_reset

	def test_reset(self):
		self.add_line(1, 10, 0)
		self.assertFalse(ProductionLine._data)

		ProductionLine.get_const_production_line(1)
		self.assertTrue(ProductionLine._data)

		ProductionLine.reset()
		self.assertFalse(ProductionLine._data)
开发者ID:mihaibivol,项目名称:unknown-horizons,代码行数:9,代码来源:test_productionline.py

示例3: test_reset

	def test_reset(self):
		self.add_line(1, 10, 0)
		self.assertFalse(ProductionLine.data)

		ProductionLine.load_data(1)
		self.assertTrue(ProductionLine.data)

		ProductionLine.reset()
		self.assertFalse(ProductionLine.data)
开发者ID:mitfik,项目名称:unknown-horizons,代码行数:9,代码来源:test_productionline.py

示例4: test_change_amount

	def test_change_amount(self):
		self.add_line(1, 10, 0, {2: 3, 4: -5})
		line = ProductionLine(1)

		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})
开发者ID:mihaibivol,项目名称:unknown-horizons,代码行数:13,代码来源:test_productionline.py

示例5: test_change_amount

	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})
开发者ID:perher,项目名称:unknown-horizons,代码行数:17,代码来源:test_productionline.py

示例6: __init_production_lines

	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
开发者ID:Antagonym,项目名称:unknown-horizons,代码行数:12,代码来源:fakeresourcedeposit.py

示例7: __init

	def __init(self, inventory, owner_inventory, prod_id, prod_data, state, creation_tick, pause_old_state = None):
		"""
		@param inventory: inventory of assigned building
		@param prod_line_id: id of production line.
		"""
		self.inventory = inventory
		self.owner_inventory = owner_inventory
		self._state = state
		self._pause_remaining_ticks = None # only used in pause()
		self._pause_old_state = pause_old_state # only used in pause()
		self._creation_tick = creation_tick

		assert isinstance(prod_id, int)
		self._prod_line = ProductionLine(id=prod_id, data=prod_data)
开发者ID:Vivek-sagar,项目名称:unknown-horizons,代码行数:14,代码来源:production.py

示例8: test_alter_production_time

	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)
开发者ID:perher,项目名称:unknown-horizons,代码行数:15,代码来源:test_productionline.py

示例9: test_alter_production_time

	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)
开发者ID:mihaibivol,项目名称:unknown-horizons,代码行数:15,代码来源:test_productionline.py

示例10: __init__

	def __init__(self, building_id, name, settler_level, production_line_ids):
		super(AbstractFakeResourceDeposit, self).__init__(building_id, name, settler_level, [])
		self.lines = {} # output_resource_id: ProductionLine
		assert len(production_line_ids) == 1, 'expected exactly 1 production line'
		for production_line_id in production_line_ids:
			# create a fake production line that is similar to the higher level building one
			# TODO: use a better way of producing fake ProductionLine-s
			production_line = ProductionLine(production_line_id)
			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
开发者ID:mitfik,项目名称:unknown-horizons,代码行数:16,代码来源:fakeresourcedeposit.py

示例11: __init__

	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)
开发者ID:alanshi,项目名称:unknown-horizons,代码行数:40,代码来源:production.py

示例12: Production

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:
#.........这里部分代码省略.........
开发者ID:alanshi,项目名称:unknown-horizons,代码行数:101,代码来源:production.py

示例13: setUp

	def setUp(self):
		"""Clear ProductionLine cache."""
		ProductionLine.reset()
		super(TestProductionLine, self).setUp()
开发者ID:mihaibivol,项目名称:unknown-horizons,代码行数:4,代码来源:test_productionline.py

示例14: _create_production_line

	def _create_production_line(self, prod_line_id):
		"""Returns a non-changeable production line instance"""
		return ProductionLine.get_const_production_line(prod_line_id)
开发者ID:mihaibivol,项目名称:unknown-horizons,代码行数:3,代码来源:production.py


注:本文中的horizons.world.production.productionline.ProductionLine类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。