Example #1
0
	def level_check(self):
		"""Checks whether we should level up or down."""
		if self.happiness > self.__get_data("happiness_level_up_requirement"):
			if self.level >= self.level_max:
				# max level reached already, can't allow an update
				if self.owner.is_local_player:
					if not self.__class__._max_increment_reached_notification_displayed:
						self.__class__._max_increment_reached_notification_displayed = True
						self.session.ingame_gui.message_widget.add( \
							self.position.center().x, self.position.center().y, 'MAX_INCR_REACHED')
				return
			# add a production line that gets the necessary upgrade material.
			# when the production finishes, it calls upgrade_materials_collected.
			upgrade_material_prodline = self.session.db.get_settler_upgrade_material_prodline(self.level+1)
			if self.get_component(Producer).has_production_line(upgrade_material_prodline):
				return # already waiting for res
			prodline_data = self.session.db.get_production_line_data(upgrade_material_prodline)
			owner_inventory = self._get_owner_inventory()
			upgrade_material_production = SingleUseProduction(self.get_component(StorageComponent).inventory, owner_inventory, \
			                                                  upgrade_material_prodline, prodline_data)
			upgrade_material_production.add_production_finished_listener(self.level_up)
			# drive the car out of the garage to make space for the building material
			for res, amount in upgrade_material_production.get_consumed_resources().iteritems():
				self.get_component(StorageComponent).inventory.add_resource_slot(res, abs(amount))
			self.get_component(Producer).add_production(upgrade_material_production)
			self.log.debug("%s: Waiting for material to upgrade from %s", self, self.level)
			if not self.upgrade_allowed:
				ToggleActive(self.get_component(Producer), upgrade_material_production).execute(self.session, True)
		elif self.happiness < self.__get_data("happiness_level_down_limit"):
			self.level_down()
			self._changed()
	def level_check(self):
		"""Checks whether we should level up or down."""
		if self.happiness > self.__get_data("happiness_level_up_requirement") and \
			 self.level < self.level_max:
			# add a production line that gets the necessary upgrade material.
			# when the production finished, it calls level_up as callback.
			upgrade_material_prodline = self.session.db.get_settler_upgrade_material_prodline(self.level+1)
			if self.has_production_line(upgrade_material_prodline):
				return # already waiting for res
			upgrade_material_production = SingleUseProduction(self.inventory, \
			                                   upgrade_material_prodline, callback = self.level_up)
			# drive the car out of the garage to make space for the building material
			for res, amount in upgrade_material_production.get_consumed_resources().iteritems():
				self.inventory.add_resource_slot(res, abs(amount))
			self.add_production(upgrade_material_production)
			self.log.debug("%s: Waiting for material to upgrade from %s", self, self.level)
		elif self.happiness < self.__get_data("happiness_level_down_limit"):
			self.level_down()
			self._changed()
Example #3
0
	def level_check(self):
		"""Checks whether we should level up or down."""
		if self.happiness > self.__get_data("happiness_level_up_requirement") and \
			 self.level < self.level_max:
			# add a production line that gets the necessary upgrade material.
			# when the production finished, it calls level_up as callback.
			upgrade_material_prodline = self.session.db.get_settler_upgrade_material_prodline(self.level+1)
			if self.has_production_line(upgrade_material_prodline):
				return # already waiting for res
			upgrade_material_production = SingleUseProduction(self.inventory, upgrade_material_prodline)
			upgrade_material_production.add_production_finished_listener(self.level_up)
			# drive the car out of the garage to make space for the building material
			for res, amount in upgrade_material_production.get_consumed_resources().iteritems():
				self.inventory.add_resource_slot(res, abs(amount))
			self.add_production(upgrade_material_production)
			self.log.debug("%s: Waiting for material to upgrade from %s", self, self.level)
		elif self.happiness < self.__get_data("happiness_level_down_limit"):
			self.level_down()
			self._changed()
Example #4
0
	def load_production(self, db, worldid):
		if db.get_production_line_id(worldid) == self.session.db.get_settler_upgrade_material_prodline(self.level + 1):
			return SingleUseProduction.load(db, worldid)
		else:
			return super(Settler, self).load_production(db, worldid)