示例#1
0
    def create_place(self, x, y, size, roads_to, persons=(), name_forms=None, is_frontier=False): # pylint: disable=R0914

        place_power = int(max(place.power for place in places_storage.all()) * float(size) / places_settings.MAX_SIZE)

        place_power_steps = int(places_settings.POWER_HISTORY_LENGTH / c.MAP_SYNC_TIME)
        place_power_per_step = (place_power / place_power_steps) + 1

        place = PlacePrototype.create( x=x,
                                       y=y,
                                       utg_name=name_forms.word,
                                       is_frontier=is_frontier,
                                       size=size)

        initial_turn = TimePrototype.get_current_turn_number() - places_settings.POWER_HISTORY_LENGTH
        for i in xrange(place_power_steps):
            place.push_power(int(initial_turn+i*c.MAP_SYNC_TIME), int(place_power_per_step))

        for person_name_forms, power_percent, race, gender, tp in persons:
            person = PersonPrototype.create(place=place,
                                            race=race,
                                            gender=gender,
                                            tp=tp,
                                            name_forms=person_name_forms)

            person_power = place_power * power_percent
            person_power_steps = int(persons_conf.settings.POWER_HISTORY_LENGTH / c.MAP_SYNC_TIME)
            person_power_per_step = (person_power / person_power_steps) + 1
            initial_turn = TimePrototype.get_current_turn_number() - persons_conf.settings.POWER_HISTORY_LENGTH
            for i in xrange(person_power_steps):
                person.push_power(int(initial_turn+i*c.MAP_SYNC_TIME), int(person_power_per_step))
            person.save()

        place.sync_persons(force_add=True)

        power_delta = self.INITIAL_PERSON_POWER

        for person in place.persons:
            person.fill_power_evenly(power_delta)
            person.save()
            power_delta /= 2

        place.sync_race()
        place.save()

        for destination in roads_to:
            Road.objects.create(point_1=place._model, point_2=destination._model)

        persons_storage.update_version()
        places_storage.update_version()
        roads_storage.update_version()

        persons_storage.refresh()
        places_storage.refresh()
        roads_storage.refresh()

        return place
示例#2
0
def create_person(place, state):
    race = random.choice(RACE.records)
    gender = random.choice((GENDER.MASCULINE, GENDER.FEMININE))
    return PersonPrototype.create(place,
                                  state=state,
                                  race=race,
                                  tp=random.choice(PERSON_TYPE.records),
                                  utg_name=names.generator.get_name(
                                      race, gender),
                                  gender=gender)
示例#3
0
def create_person(place, state):
    race = random.choice(RACE.records)
    gender = random.choice((GENDER.MASCULINE, GENDER.FEMININE))
    return PersonPrototype.create(
        place,
        state=state,
        race=race,
        tp=random.choice(PERSON_TYPE.records),
        utg_name=names.generator.get_name(race, gender),
        gender=gender,
    )
示例#4
0
    def add_person(self):
        from the_tale.game.persons.relations import PERSON_TYPE
        from the_tale.game.persons.prototypes import PersonPrototype

        race = random.choice(RACE.records)
        gender = random.choice((GENDER.MASCULINE, GENDER.FEMININE))

        new_person = PersonPrototype.create(place=self,
                                            race=race,
                                            gender=gender,
                                            tp=random.choice(PERSON_TYPE.records),
                                            utg_name=names.generator.get_name(race, gender))

        signals.place_person_arrived.send(self.__class__, place=self, person=new_person)

        return new_person
示例#5
0
    def add_person(self):
        from the_tale.game.persons.relations import PERSON_TYPE
        from the_tale.game.persons.prototypes import PersonPrototype

        race = random.choice(RACE.records)
        gender = random.choice((GENDER.MASCULINE, GENDER.FEMININE))

        new_person = PersonPrototype.create(
            place=self,
            race=race,
            gender=gender,
            tp=random.choice(PERSON_TYPE.records),
            utg_name=names.generator.get_name(race, gender))

        signals.place_person_arrived.send(self.__class__,
                                          place=self,
                                          person=new_person)

        return new_person
示例#6
0
 def __init__(self, choosen_person_id, *args, **kwargs):  # pylint: disable=W0613
     super(UserForm, self).__init__(*args, **kwargs)
     self.fields['person'].choices = PersonPrototype.form_choices(
         predicate=self._person_has_building)
示例#7
0
 def __init__(self, choosen_person_id, *args, **kwargs):
     super(UserForm, self).__init__(*args, **kwargs)
     self.fields['person'].choices = PersonPrototype.form_choices(only_weak=False, choosen_person=persons_storage.get(choosen_person_id))
示例#8
0
 def __init__(self, choosen_person_id, *args, **kwargs):
     super(UserForm, self).__init__(*args, **kwargs)
     self.fields['person'].choices = PersonPrototype.form_choices(only_weak=True, choosen_person=persons_storage.get(choosen_person_id))
示例#9
0
文件: forms.py 项目: Alkalit/the-tale
 def __init__(self, *args, **kwargs):
     super(PersonForm, self).__init__(*args, **kwargs)
     self.fields['person'].choices = PersonPrototype.form_choices(only_weak=False)
示例#10
0
文件: admin.py 项目: pavetok/the-tale
 def name(self, obj):
     from the_tale.game.persons.prototypes import PersonPrototype
     return PersonPrototype(model=obj).name
示例#11
0
文件: admin.py 项目: pavetok/the-tale
 def negative_bonus(self, obj):
     person = PersonPrototype(obj)
     return round(person.power_negative, 2)
示例#12
0
文件: admin.py 项目: pavetok/the-tale
 def raw_power(self, obj):
     person = PersonPrototype(obj)
     return int(person.raw_power)
示例#13
0
 def __init__(self, choosen_person_id, *args, **kwargs):  # pylint: disable=W0613
     super(UserForm, self).__init__(*args, **kwargs)
     self.fields['person'].choices = PersonPrototype.form_choices(predicate=lambda place, person: not person.has_building)
示例#14
0
    def create_place(self,
                     x,
                     y,
                     size,
                     roads_to,
                     persons=(),
                     name_forms=None,
                     is_frontier=False):  # pylint: disable=R0914

        place_power = int(
            max(place.power for place in places_storage.all()) * float(size) /
            places_settings.MAX_SIZE)

        place_power_steps = int(places_settings.POWER_HISTORY_LENGTH /
                                c.MAP_SYNC_TIME)
        place_power_per_step = (place_power / place_power_steps) + 1

        place = PlacePrototype.create(x=x,
                                      y=y,
                                      utg_name=name_forms.word,
                                      is_frontier=is_frontier,
                                      size=size)

        initial_turn = TimePrototype.get_current_turn_number(
        ) - places_settings.POWER_HISTORY_LENGTH
        for i in xrange(place_power_steps):
            place.push_power(int(initial_turn + i * c.MAP_SYNC_TIME),
                             int(place_power_per_step))

        for person_name_forms, power_percent, race, gender, tp in persons:
            person = PersonPrototype.create(place=place,
                                            race=race,
                                            gender=gender,
                                            tp=tp,
                                            name_forms=person_name_forms)

            person_power = place_power * power_percent
            person_power_steps = int(
                persons_conf.settings.POWER_HISTORY_LENGTH / c.MAP_SYNC_TIME)
            person_power_per_step = (person_power / person_power_steps) + 1
            initial_turn = TimePrototype.get_current_turn_number(
            ) - persons_conf.settings.POWER_HISTORY_LENGTH
            for i in xrange(person_power_steps):
                person.push_power(int(initial_turn + i * c.MAP_SYNC_TIME),
                                  int(person_power_per_step))
            person.save()

        place.sync_persons(force_add=True)

        power_delta = self.INITIAL_PERSON_POWER

        for person in place.persons:
            person.fill_power_evenly(power_delta)
            person.save()
            power_delta /= 2

        place.sync_race()
        place.save()

        for destination in roads_to:
            Road.objects.create(point_1=place._model,
                                point_2=destination._model)

        persons_storage.update_version()
        places_storage.update_version()
        roads_storage.update_version()

        persons_storage.refresh()
        places_storage.refresh()
        roads_storage.refresh()

        return place
示例#15
0
 def __init__(self, choosen_person_id, *args, **kwargs):  # pylint: disable=W0613
     super(UserForm, self).__init__(*args, **kwargs)
     self.fields["person"].choices = PersonPrototype.form_choices(predicate=self._person_has_building)
示例#16
0
 def __init__(self, *args, **kwargs):
     super(PersonForm, self).__init__(*args, **kwargs)
     self.fields['person'].choices = PersonPrototype.form_choices(
         only_weak=False)