def test_refresh_attributes__stability_maximum(self): self.p1.effects.add(effects.Effect(name='test', attribute=relations.ATTRIBUTE.STABILITY, value=0.6)) self.p1.effects.add(effects.Effect(name='test', attribute=relations.ATTRIBUTE.STABILITY, value=0.55)) self.p1.refresh_attributes() self.assertEqual(self.p1.attrs.stability, 1.0)
def test_refresh_attributes__stability(self): self.p1.effects.add(effects.Effect(name='test', attribute=relations.ATTRIBUTE.STABILITY, value=-0.5)) self.p1.effects.add(effects.Effect(name='test', attribute=relations.ATTRIBUTE.STABILITY, value=0.25)) self.p1.refresh_attributes() self.assertTrue(-0.001 < self.p1.attrs.stability - (1.0 - 0.5 + 0.25 - 0.05 * len(self.p1.persons)) < 0.001)
def place_effects(self): for attribute, modifier in self.get_economic_modifiers(): yield effects.Effect(name=self.name, attribute=attribute, value=modifier) yield from self.specialization_effects() if self.attrs.terrain_radius_bonus != 0: yield effects.Effect( name=self.name, attribute=places_relations.ATTRIBUTE.TERRAIN_RADIUS, value=self.attrs.terrain_radius_bonus) if self.attrs.politic_radius_bonus != 0: yield effects.Effect( name=self.name, attribute=places_relations.ATTRIBUTE.POLITIC_RADIUS, value=self.attrs.politic_radius_bonus) if self.attrs.stability_renewing_bonus != 0: yield effects.Effect( name=self.name, attribute=places_relations.ATTRIBUTE.STABILITY_RENEWING_SPEED, value=self.attrs.stability_renewing_bonus)
def test_stability__reduce_effects(self): self.p1.effects.add( effects.Effect(name=u'x', attribute=relations.ATTRIBUTE.STABILITY, value=-0.5)) self.p1.effects.add( effects.Effect(name=u'y', attribute=relations.ATTRIBUTE.STABILITY, value=0.25)) self.p1.refresh_attributes() self.assertTrue(-0.001 < self.p1.attrs.stability - (0.75 - 0.05 * len(self.p1.persons)) < 0.001) self.p1.effects_update_step() self.assertEqual(len(self.p1.effects.effects), 2) for effect in self.p1.effects.effects: if effect.name == 'x': self.assertEqual(effect.value, -0.5 + c.PLACE_STABILITY_RECOVER_SPEED / 2) else: self.assertEqual(effect.value, 0.25 - c.PLACE_STABILITY_RECOVER_SPEED / 2)
def effects_generator(self, order): # TODO: do something with postchecks safety = 0 transport = 0 stability = 0 for effect in self._effects_generator(): if effect.attribute.order != order: continue if effect.attribute.is_SAFETY: safety += effect.value if effect.attribute.is_TRANSPORT: transport += effect.value if effect.attribute.is_STABILITY: stability += effect.value yield effect if relations.ATTRIBUTE.SAFETY.order == order: if safety < c.PLACE_MIN_SAFETY: yield effects.Effect(name=u'Серый Орден', attribute=relations.ATTRIBUTE.SAFETY, value=c.PLACE_MIN_SAFETY - safety) if relations.ATTRIBUTE.TRANSPORT.order == order: if transport < c.PLACE_MIN_TRANSPORT: yield effects.Effect(name=u'Серый Орден', attribute=relations.ATTRIBUTE.TRANSPORT, value=c.PLACE_MIN_TRANSPORT - transport) if relations.ATTRIBUTE.STABILITY.order == order: if stability < c.PLACE_MIN_STABILITY: yield effects.Effect(name=u'Серый Орден', attribute=relations.ATTRIBUTE.STABILITY, value=c.PLACE_MIN_STABILITY - stability) if stability > 1: yield effects.Effect(name=u'демоны', attribute=relations.ATTRIBUTE.STABILITY, value=1 - stability)
def test_stability__stability_deltas_sum_equal_to_stability_renewing_speed( self): self.p1.attrs.stability_renewing_speed = 0.25 self.p1.effects.add( effects.Effect(name='x', attribute=relations.ATTRIBUTE.STABILITY, value=-0.5)) self.p1.effects.add( effects.Effect(name='y', attribute=relations.ATTRIBUTE.STABILITY, value=0.25)) self.p1.effects.add( effects.Effect(name='z', attribute=relations.ATTRIBUTE.STABILITY, value=-0.5)) self.p1.effects_update_step() for i in range(len(self.p1.effects) - 1): self.assertTrue(self.p1.effects.effects[i].delta >= self.p1.effects.effects[i + 1].delta) self.assertEqual( self.p1.attrs.stability_renewing_speed, sum(effect.delta for effect in self.p1.effects.effects))
def test_stability__parameters_removed(self): self.p1.attrs.stability_renewing_speed = 0.25 self.p1.effects.add( effects.Effect(name='x', attribute=relations.ATTRIBUTE.STABILITY, value=-0.5)) self.p1.effects.add( effects.Effect(name='y', attribute=relations.ATTRIBUTE.STABILITY, value=0.25)) self.p1.effects_update_step() self.assertEqual(len(self.p1.effects.effects), 2) self.p1.effects_update_step() self.assertEqual(len(self.p1.effects.effects), 2) self.p1.effects_update_step() self.assertEqual(len(self.p1.effects.effects), 1) self.assertEqual(self.p1.effects.effects[0].name, 'y') self.assertEqual(self.p1.effects.effects[0].value, 0.0625) self.p1.effects_update_step() self.assertEqual(len(self.p1.effects.effects), 0)
def test_refresh_attributes__stability__minimum(self): self.p1.effects.add(effects.Effect(name='test', attribute=relations.ATTRIBUTE.STABILITY, value=-0.6)) self.p1.effects.add(effects.Effect(name='test', attribute=relations.ATTRIBUTE.STABILITY, value=-0.55)) self.p1.refresh_attributes() self.assertTrue(-0.001 < self.p1.attrs.stability - c.PLACE_MIN_STABILITY < 0.001)
def personality(name, value, text, attribute, attribute_value, male_text, female_text, description): return (name, value, text, effects.Effect(name=text, attribute=getattr(ATTRIBUTE, attribute), value=attribute_value), male_text, female_text, description)
def use(self, task, storage, highlevel=None, **kwargs): # pylint: disable=R0911,W0613 place_id = task.data.get('value') if place_id not in places_storage.places: return task.logic_result( next_step=postponed_tasks.UseCardTask.STEP.ERROR, message='Город не найден.') if task.step.is_LOGIC: return task.logic_result( next_step=postponed_tasks.UseCardTask.STEP.HIGHLEVEL) elif task.step.is_HIGHLEVEL: place = places_storage.places[place_id] place.effects.add( effects.Effect(name='Хранитель {}'.format( accounts_prototypes.AccountPrototype.get_by_id( task.hero_id).nick), attribute=places_relations.ATTRIBUTE.STABILITY, value=self.modificator, delta=place.attrs.stability_renewing_speed)) place.refresh_attributes() places_logic.save_place(place) places_storage.places.update_version() return task.logic_result()
def test_refresh_attributes__safety__max_value(self): self.p1.effects.add(effects.Effect(name='test', attribute=relations.ATTRIBUTE.SAFETY, value=1000)) self._create_test_exchanges() self.p1.refresh_attributes() self.assertTrue(-0.001 < self.p1.attrs.safety - 1 < 0.001)
def test_refresh_attributes__transport__min_value(self): self.p1.effects.add(effects.Effect(name='test', attribute=relations.ATTRIBUTE.TRANSPORT, value=-1000)) self._create_test_exchanges() self.p1.refresh_attributes() self.assertTrue(-0.001 < self.p1.attrs.transport - c.PLACE_MIN_TRANSPORT < 0.001)
def test_refresh_attributes__culture__min_value(self): self.p1.effects.add(effects.Effect(name='test', attribute=relations.ATTRIBUTE.CULTURE, value=-1000)) self._create_test_exchanges() self.p1.refresh_attributes() self.assertTrue(-0.001 < self.p1.attrs.culture - c.PLACE_MIN_CULTURE < 0.001)
def effects_generator(self, order): # TODO: do something with postchecks safety = 0 transport = 0 stability = 0 culture = 0 freedom = 0 for effect in self._effects_generator(): if effect.attribute.order != order: continue if effect.attribute.is_SAFETY: safety += effect.value if effect.attribute.is_TRANSPORT: transport += effect.value if effect.attribute.is_STABILITY: stability += effect.value if effect.attribute.is_CULTURE: culture += effect.value if effect.attribute.is_FREEDOM: freedom += effect.value yield effect if relations.ATTRIBUTE.SAFETY.order == order: if safety < c.PLACE_MIN_SAFETY: yield effects.Effect(name='Серый Орден', attribute=relations.ATTRIBUTE.SAFETY, value=c.PLACE_MIN_SAFETY - safety) if safety > 1: yield effects.Effect(name='демоны', attribute=relations.ATTRIBUTE.SAFETY, value=1 - safety) if relations.ATTRIBUTE.TRANSPORT.order == order: if transport < c.PLACE_MIN_TRANSPORT: yield effects.Effect(name='Серый Орден', attribute=relations.ATTRIBUTE.TRANSPORT, value=c.PLACE_MIN_TRANSPORT - transport) if relations.ATTRIBUTE.STABILITY.order == order: if stability < c.PLACE_MIN_STABILITY: yield effects.Effect(name='Серый Орден', attribute=relations.ATTRIBUTE.STABILITY, value=c.PLACE_MIN_STABILITY - stability) if stability > 1: yield effects.Effect(name='демоны', attribute=relations.ATTRIBUTE.STABILITY, value=1 - stability) if relations.ATTRIBUTE.CULTURE.order == order: if culture < c.PLACE_MIN_CULTURE: yield effects.Effect(name='бродячие артисты', attribute=relations.ATTRIBUTE.CULTURE, value=c.PLACE_MIN_CULTURE - culture) if relations.ATTRIBUTE.FREEDOM.order == order: if freedom < c.PLACE_MIN_FREEDOM: yield effects.Effect(name='Пять звёзд', attribute=relations.ATTRIBUTE.FREEDOM, value=c.PLACE_MIN_FREEDOM - freedom)
def test_refresh_attributes__freedom(self): self.p1.set_modifier(modifiers.CITY_MODIFIERS.POLIC) self.p1.effects.add(effects.Effect(name='test', attribute=relations.ATTRIBUTE.FREEDOM, value=1000)) self._create_test_exchanges() self.p1.refresh_attributes() self.assertTrue(-0.001 < self.p1.attrs.freedom - (1000 + 100 * len(self.p1.persons) + 1.0 + 0.1) < 0.001)
def specialization_effects(self): for specialization, points in self.specialization_attributes.items(): if specialization.points_attribute is None: continue yield effects.Effect( name=self.name, attribute=specialization.points_attribute, value=self.modify_specialization_points(points))
def record(name, value, text, quest, modifier_effects, description): return (name, value, text, quest, getattr(technical_words, 'MODIFIER_{}'.format(name)), _modifier_linguistics_restrictions(name), tuple([effects.Effect(name=text, attribute=getattr(relations.ATTRIBUTE, attribute), value=value) for attribute, value in modifier_effects]), description, getattr(relations.ATTRIBUTE, 'MODIFIER_{}'.format(name)) if name != 'NONE' else None)
def place_effects(self): for attribute, modifier in self.get_economic_modifiers(): yield effects.Effect(name=self.name, attribute=attribute, value=modifier) for specialization, points in self.specialization_attributes.iteritems(): if specialization.points_attribute is None: continue MAX_PERSON_POINTS = 100 yield effects.Effect(name=self.name, attribute=specialization.points_attribute, value=MAX_PERSON_POINTS * points * self.total_politic_power_fraction * self.place.attrs.modifier_multiplier) if self.attrs.terrain_radius_bonus != 0: yield effects.Effect(name=self.name, attribute=places_relations.ATTRIBUTE.TERRAIN_RADIUS, value=self.attrs.terrain_radius_bonus) if self.attrs.politic_radius_bonus != 0: yield effects.Effect(name=self.name, attribute=places_relations.ATTRIBUTE.POLITIC_RADIUS, value=self.attrs.politic_radius_bonus) if self.attrs.stability_renewing_bonus != 0: yield effects.Effect(name=self.name, attribute=places_relations.ATTRIBUTE.STABILITY_RENEWING_SPEED, value=self.attrs.stability_renewing_bonus)
def test_refresh_attributes__stability__parameters_descreased(self): self._create_test_exchanges() self.p1.refresh_attributes() self.p1.effects.add(effects.Effect(name='x', attribute=relations.ATTRIBUTE.STABILITY, value=-1.0)) with self.check_decreased(lambda: self.p1.attrs.production): with self.check_increased(lambda: self.p1.attrs.freedom): with self.check_decreased(lambda: self.p1.attrs.transport): with self.check_decreased(lambda: self.p1.attrs.safety): self.p1.refresh_attributes()
def apply_negative(self, actor_type, actor_name, place, person, positive_heroes, negative_heroes, job_power): effect_value = self.base_value*job_power effect_delta = effect_value * (1.0 / c.NORMAL_JOB_LENGTH) place.effects.add(effects.Effect(name=actor_name, attribute=self.attribute, value=-effect_value, delta=effect_delta)) return self.apply_to_heroes(actor_type=actor_type, effect=getattr(EFFECT, 'PLACE_{}'.format(self.attribute.name)), method_names=('job_message', 'job_message'), method_kwargs={'place_id': place.id, 'person_id': person.id if person else None, 'job_power': job_power}, positive_heroes=positive_heroes, negative_heroes=negative_heroes, direction='negative')
def test_refresh_attributes__freedom__min_value(self): self.p1.effects.add( effects.Effect(name='test', attribute=relations.ATTRIBUTE.FREEDOM, value=-1000)) self._create_test_exchanges() self.p1.refresh_attributes() self.assertTrue( -0.001 < self.p1.attrs.freedom - c.PLACE_MIN_FREEDOM < 0.001)
def test_refresh_attributes__stability_penalty_for_wrong_specialization(self): self.p1.refresh_attributes() with self.check_not_changed(lambda: self.p1.attrs.stability): self.p1.set_modifier(modifiers.CITY_MODIFIERS.TRADE_CENTER) self.p1.effects.add(effects.Effect(name='x', attribute=relations.ATTRIBUTE.MODIFIER_TRADE_CENTER, value=100)) self.p1.refresh_attributes() with self.check_delta(lambda: self.p1.attrs.stability, -0.5): self.p1.attrs.modifier_trade_center = 0 self.p1.effects.clear() self.p1.refresh_attributes()
def test_refresh_attributes__transport(self): self.p1.set_modifier(modifiers.CITY_MODIFIERS.TRANSPORT_NODE) self.p1.effects.add(effects.Effect(name='test', attribute=relations.ATTRIBUTE.TRANSPORT, value=1000)) self._create_test_exchanges() self.p1.refresh_attributes() expected_transport = (1.0 + 1000 + 100 * len(self.p1.persons) + 0.2 - relations.RESOURCE_EXCHANGE_TYPE.TRANSPORT_SMALL.amount + relations.RESOURCE_EXCHANGE_TYPE.TRANSPORT_LARGE.amount - c.TRANSPORT_FROM_PLACE_SIZE_PENALTY * self.p1.attrs.size) self.assertTrue(-0.001 < self.p1.attrs.transport - expected_transport < 0.001)
def test_stability__stability_deltas_sum_equal_to_stability_renewing_speed__a_lot_of_effects( self): self.p1.attrs.stability_renewing_speed = 0.25 for i in range(10): self.p1.effects.add( effects.Effect(name=str(i), attribute=relations.ATTRIBUTE.STABILITY, value=100 * random.choice([-1, 1]))) self.p1.effects_update_step() for i in range(len(self.p1.effects) - 1): self.assertTrue(self.p1.effects.effects[i].delta >= self.p1.effects.effects[i + 1].delta) self.assertEqual( self.p1.attrs.stability_renewing_speed, sum(effect.delta for effect in self.p1.effects.effects)) self.assertEqual( self.p1.attrs.stability_renewing_speed, sum(abs(effect.delta) for effect in self.p1.effects.effects))
def apply(self): if not self.state.is_VOTING: raise exceptions.ApplyBillInWrongStateError(bill_id=self.id) if not self.approved_by_moderator: raise exceptions.ApplyUnapprovedBillError(bill_id=self.id) if self.time_before_voting_end != datetime.timedelta(seconds=0): raise exceptions.ApplyBillBeforeVoteWasEndedError(bill_id=self.id) self.recalculate_votes() self._model.min_votes_percents_required = bills_settings.MIN_VOTES_PERCENT results_text = 'Итоги голосования: %d «за», %d «против» (итого %.1f%% «за»), %d «воздержалось».' % ( self.votes_for, self.votes_against, round(self.votes_for_percents, 3) * 100, self.votes_refrained) self._model.voting_end_at = datetime.datetime.now() self.applyed_at_turn = turn.number() with transaction.atomic(): if self.is_percents_barier_not_passed: self.state = BILL_STATE.REJECTED self.save() PostPrototype.create(ThreadPrototype(self._model.forum_thread), get_system_user(), 'Запись отклонена.\n\n%s' % results_text, technical=True) signals.bill_processed.send(self.__class__, bill=self) return False self.data.apply(self) self.state = BILL_STATE.ACCEPTED with achievements_storage.verify( type=ACHIEVEMENT_TYPE.POLITICS_ACCEPTED_BILLS, object=self.owner): self.save() PostPrototype.create( ThreadPrototype(self._model.forum_thread), get_system_user(), 'Запись одобрена. Изменения вступят в силу в ближайшее время.\n\n%s' % results_text, technical=True) for actor in self.actors: if isinstance(actor, places_objects.Place): actor.effects.add( effects.Effect( name='запись №{}'.format(self.id), attribute=places_relations.ATTRIBUTE.STABILITY, value=-self.type.stability)) logic.initiate_actual_bills_update(self._model.owner_id) signals.bill_processed.send(self.__class__, bill=self) return True
def _effects_generator(self): from . import storage yield effects.Effect(name=u'город', attribute=relations.ATTRIBUTE.TAX, value=0.0) yield effects.Effect(name=u'город', attribute=relations.ATTRIBUTE.STABILITY, value=1.0) yield effects.Effect(name=u'город', attribute=relations.ATTRIBUTE.STABILITY_RENEWING_SPEED, value=c.PLACE_STABILITY_RECOVER_SPEED) yield effects.Effect(name=u'город', attribute=relations.ATTRIBUTE.POLITIC_RADIUS, value=self.attrs.size*1.25) yield effects.Effect(name=u'город', attribute=relations.ATTRIBUTE.TERRAIN_RADIUS, value=self.attrs.size) for effect in self.effects.effects: yield effect if self.is_modifier_active(): for effect in self._modifier.effects: yield effect elif not self.modifier.is_NONE: yield effects.Effect(name=u'Несоответствие специализации', attribute=relations.ATTRIBUTE.STABILITY, value=-c.PLACE_STABILITY_UNIT) for exchange in storage.resource_exchanges.get_exchanges_for_place(self): resource_1, resource_2, place_2 = exchange.get_resources_for_place(self) if resource_1.parameter is not None: yield effects.Effect(name=place_2.name if place_2 is not None else resource_2.text, attribute=resource_1.parameter, value=-resource_1.amount * resource_1.direction) if resource_2.parameter is not None: yield effects.Effect(name=place_2.name if place_2 is not None else resource_1.text, attribute=resource_2.parameter, value=resource_2.amount * resource_2.direction) # economic yield effects.Effect(name=u'экономика', attribute=relations.ATTRIBUTE.PRODUCTION, value=f.place_goods_production(self.attrs.power_economic)) yield effects.Effect(name=u'потребление', attribute=relations.ATTRIBUTE.PRODUCTION, value=-f.place_goods_consumption(self.attrs.size)) yield effects.Effect(name=u'стабильность', attribute=relations.ATTRIBUTE.PRODUCTION, value=(1.0-self.attrs.stability) * c.PLACE_STABILITY_MAX_PRODUCTION_PENALTY) if self.attrs.get_next_keepers_goods_spend_amount(): yield effects.Effect(name=u'дары Хранителей', attribute=relations.ATTRIBUTE.PRODUCTION, value=self.attrs.get_next_keepers_goods_spend_amount()) # safety yield effects.Effect(name=u'город', attribute=relations.ATTRIBUTE.SAFETY, value=1.0) yield effects.Effect(name=u'монстры', attribute=relations.ATTRIBUTE.SAFETY, value=-c.BATTLES_PER_TURN) yield effects.Effect(name=u'стабильность', attribute=relations.ATTRIBUTE.SAFETY, value=(1.0-self.attrs.stability) * c.PLACE_STABILITY_MAX_SAFETY_PENALTY) if self.is_frontier: yield effects.Effect(name=u'дикие земли', attribute=relations.ATTRIBUTE.SAFETY, value=-c.WHILD_BATTLES_PER_TURN_BONUS) # transport yield effects.Effect(name=u'дороги', attribute=relations.ATTRIBUTE.TRANSPORT, value=1.0) yield effects.Effect(name=u'трафик', attribute=relations.ATTRIBUTE.TRANSPORT, value=-c.TRANSPORT_FROM_PLACE_SIZE_PENALTY * self.attrs.size) if self.is_frontier: yield effects.Effect(name=u'бездорожье', attribute=relations.ATTRIBUTE.TRANSPORT, value=-c.WHILD_TRANSPORT_PENALTY) yield effects.Effect(name=u'стабильность', attribute=relations.ATTRIBUTE.TRANSPORT, value=(1.0-self.attrs.stability) * c.PLACE_STABILITY_MAX_TRANSPORT_PENALTY) # freedom yield effects.Effect(name=u'город', attribute=relations.ATTRIBUTE.FREEDOM, value=1.0) yield effects.Effect(name=u'стабильность', attribute=relations.ATTRIBUTE.FREEDOM, value=(1.0-self.attrs.stability) * c.PLACE_STABILITY_MAX_FREEDOM_PENALTY) for person in self.persons: for effect in person.place_effects(): yield effect
def _effects_generator(self): from . import storage yield effects.Effect(name='город', attribute=relations.ATTRIBUTE.TAX, value=0.0) yield effects.Effect(name='город', attribute=relations.ATTRIBUTE.STABILITY, value=1.0) if len(self.persons) > c.PLACE_MAX_PERSONS: yield effects.Effect(name='избыток Мастеров', attribute=relations.ATTRIBUTE.STABILITY, value=c.PLACE_STABILITY_PENALTY_FOR_MASTER * (len(self.persons) - c.PLACE_MAX_PERSONS)) if self.is_wrong_race(): dominant_race_power = self.races.get_race_percents( self.races.dominant_race) current_race_power = self.races.get_race_percents(self.race) yield effects.Effect(name='расовая дискриминация', attribute=relations.ATTRIBUTE.STABILITY, value=c.PLACE_STABILITY_PENALTY_FOR_RACES * (dominant_race_power - current_race_power)) yield effects.Effect( name='город', attribute=relations.ATTRIBUTE.STABILITY_RENEWING_SPEED, value=c.PLACE_STABILITY_RECOVER_SPEED) # politic radius yield effects.Effect(name='размер города', attribute=relations.ATTRIBUTE.POLITIC_RADIUS, value=self.attrs.size * 0.625) yield effects.Effect(name='культура', attribute=relations.ATTRIBUTE.POLITIC_RADIUS, value=self.attrs.size * self.attrs.culture * 0.625) # terrain radius yield effects.Effect(name='размер города', attribute=relations.ATTRIBUTE.TERRAIN_RADIUS, value=self.attrs.size * 0.5) yield effects.Effect(name='культура', attribute=relations.ATTRIBUTE.TERRAIN_RADIUS, value=self.attrs.size * self.attrs.culture * 0.5) for effect in self.effects.effects: yield effect if self.is_modifier_active(): for effect in self._modifier.effects: yield effect elif not self.modifier.is_NONE: modifier_points = getattr( self.attrs, 'MODIFIER_{}'.format(self.modifier.name).lower(), 0) yield effects.Effect( name='Несоответствие специализации', attribute=relations.ATTRIBUTE.STABILITY, value=c.PLACE_STABILITY_PENALTY_FOR_SPECIALIZATION * (c.PLACE_TYPE_ENOUGH_BORDER - modifier_points) / c.PLACE_TYPE_ENOUGH_BORDER) for exchange in storage.resource_exchanges.get_exchanges_for_place( self): resource_1, resource_2, place_2 = exchange.get_resources_for_place( self) if resource_1.parameter is not None: yield effects.Effect( name=place_2.name if place_2 is not None else resource_2.text, attribute=resource_1.parameter, value=-resource_1.amount * resource_1.direction) if resource_2.parameter is not None: yield effects.Effect( name=place_2.name if place_2 is not None else resource_1.text, attribute=resource_2.parameter, value=resource_2.amount * resource_2.direction) # economic yield effects.Effect(name='город', attribute=relations.ATTRIBUTE.AREA, value=len(self.nearest_cells)) # мы ожидаем, что радиус владений города сравним с его размером и домножаем на поправочный коэфициент area_size_equivalent = ((math.sqrt(self.attrs.area) - 1) / 2) * 2 if self.is_frontier: area_size_equivalent /= 2 yield effects.Effect(name='экономика', attribute=relations.ATTRIBUTE.PRODUCTION, value=0.66 * self.attrs.power_economic * c.PLACE_GOODS_BONUS) yield effects.Effect(name='владения', attribute=relations.ATTRIBUTE.PRODUCTION, value=0.34 * area_size_equivalent * c.PLACE_GOODS_BONUS) yield effects.Effect(name='потребление', attribute=relations.ATTRIBUTE.PRODUCTION, value=-self.attrs.size * c.PLACE_GOODS_BONUS) yield effects.Effect(name='стабильность', attribute=relations.ATTRIBUTE.PRODUCTION, value=(1.0 - self.attrs.stability) * c.PLACE_STABILITY_MAX_PRODUCTION_PENALTY) if self.attrs.get_next_keepers_goods_spend_amount(): yield effects.Effect( name='дары Хранителей', attribute=relations.ATTRIBUTE.PRODUCTION, value=self.attrs.get_next_keepers_goods_spend_amount()) # safety yield effects.Effect(name='город', attribute=relations.ATTRIBUTE.SAFETY, value=1.0) yield effects.Effect(name='монстры', attribute=relations.ATTRIBUTE.SAFETY, value=-c.BATTLES_PER_TURN) yield effects.Effect(name='стабильность', attribute=relations.ATTRIBUTE.SAFETY, value=(1.0 - self.attrs.stability) * c.PLACE_STABILITY_MAX_SAFETY_PENALTY) if self.is_frontier: yield effects.Effect(name='дикие земли', attribute=relations.ATTRIBUTE.SAFETY, value=-c.WHILD_BATTLES_PER_TURN_BONUS) # transport yield effects.Effect(name='дороги', attribute=relations.ATTRIBUTE.TRANSPORT, value=1.0) yield effects.Effect(name='трафик', attribute=relations.ATTRIBUTE.TRANSPORT, value=-c.TRANSPORT_FROM_PLACE_SIZE_PENALTY * self.attrs.size) if self.is_frontier: yield effects.Effect(name='бездорожье', attribute=relations.ATTRIBUTE.TRANSPORT, value=-c.WHILD_TRANSPORT_PENALTY) yield effects.Effect(name='стабильность', attribute=relations.ATTRIBUTE.TRANSPORT, value=(1.0 - self.attrs.stability) * c.PLACE_STABILITY_MAX_TRANSPORT_PENALTY) # freedom yield effects.Effect(name='город', attribute=relations.ATTRIBUTE.FREEDOM, value=1.0) yield effects.Effect(name='стабильность', attribute=relations.ATTRIBUTE.FREEDOM, value=(1.0 - self.attrs.stability) * c.PLACE_STABILITY_MAX_FREEDOM_PENALTY) # culture yield effects.Effect(name='город', attribute=relations.ATTRIBUTE.CULTURE, value=1.0) yield effects.Effect(name='стабильность', attribute=relations.ATTRIBUTE.CULTURE, value=(1.0 - self.attrs.stability) * c.PLACE_STABILITY_MAX_CULTURE_PENALTY) for person in self.persons: for effect in person.place_effects(): yield effect