def initialize(self): super(Settler, self).initialize() SettlerInhabitantsChanged.broadcast(self, self.inhabitants) happiness = self.__get_data("happiness_init_value") if happiness is not None: self.get_component(StorageComponent).inventory.alter(RES.HAPPINESS, happiness) if self.has_status_icon: self.get_component(StorageComponent).inventory.add_change_listener( self._update_status_icon ) # give the user a month (about 30 seconds) to build a main square in range if self.owner.is_local_player: Scheduler().add_new_object(self._check_main_square_in_range, self, Scheduler().get_ticks_of_month()) self.__init() self.run()
def initialize(self): super().initialize() SettlerInhabitantsChanged.broadcast(self, self.inhabitants) happiness = self.__get_data("happiness_init_value") if happiness is not None: self.get_component(StorageComponent).inventory.alter(RES.HAPPINESS, happiness) if self.has_status_icon: self.get_component(StorageComponent).inventory.add_change_listener( self._update_status_icon ) # give the user a month (about 30 seconds) to build a main square in range if self.owner.is_local_player: Scheduler().add_new_object(self._check_main_square_in_range, self, Scheduler().get_ticks_of_month(), loops=-1) self.__init() self.run()
def inhabitant_check(self): """Checks whether or not the population of this settler should increase or decrease""" change = 0 if self.happiness > self.session.db.get_settler_happiness_increase_requirement() and \ self.inhabitants < self.inhabitants_max: change = 1 self.log.debug("%s: inhabitants increase to %s", self, self.inhabitants) elif self.happiness < self.session.db.get_settler_happiness_decrease_limit() and \ self.inhabitants > 1: change = -1 self.log.debug("%s: inhabitants decrease to %s", self, self.inhabitants) if change != 0: # see http://wiki.unknown-horizons.org/w/Supply_citizens_with_resources self.get_component(Producer).alter_production_time( 6.0/7.0 * math.log( 1.5 * (self.inhabitants + 1.2) ) ) self.inhabitants += change SettlerInhabitantsChanged.broadcast(self, change) self._changed()
def inhabitant_check(self): """Checks whether or not the population of this settler should increase or decrease""" sad = self.session.db.get_lower_happiness_limit() happy = self.session.db.get_upper_happiness_limit() change = 0 if self.happiness > happy and self.inhabitants < self.inhabitants_max: change = 1 self.log.debug("%s: inhabitants increase to %s", self, self.inhabitants) elif self.happiness < sad and self.inhabitants > 1: change = -1 self.log.debug("%s: inhabitants decrease to %s", self, self.inhabitants) if change != 0: # see http://wiki.unknown-horizons.org/w/Supply_citizens_with_resources self.get_component(Producer).alter_production_time( 6.0 / 7.0 * math.log( 1.5 * (self.inhabitants + 1.2) ) ) self.inhabitants += change SettlerInhabitantsChanged.broadcast(self, change) self._changed()
def remove(self): SettlerInhabitantsChanged.broadcast(self, -self.inhabitants) UpgradePermissionsChanged.unsubscribe( self._on_change_upgrade_permissions, sender=self.settlement) super(Settler, self).remove()
def remove(self): SettlerInhabitantsChanged.broadcast(self, -self.inhabitants) UpgradePermissionsChanged.unsubscribe(self._on_change_upgrade_permissions, sender=self.settlement) super(Settler, self).remove()