예제 #1
0
    def create(cls, turn_number, width, height, terrain, world):  # pylint: disable=R0914
        from the_tale.game.map.generator.descriptors import UICells

        terrain_percents = {}

        terrain_squares = collections.defaultdict(int)

        for y in range(0, height):
            for x in range(0, width):
                cell = world.generator.cell_info(x, y)

                if cell.height < -0.2:
                    terrain_squares[MAP_STATISTICS.LOWLANDS] += 1
                elif cell.height < 0.3:
                    terrain_squares[MAP_STATISTICS.PLAINS] += 1
                else:
                    terrain_squares[MAP_STATISTICS.UPLANDS] += 1

                if cell.vegetation == VEGETATION_TYPE.DESERT:
                    terrain_squares[MAP_STATISTICS.DESERTS] += 1
                elif cell.vegetation == VEGETATION_TYPE.GRASS:
                    terrain_squares[MAP_STATISTICS.GRASS] += 1
                else:
                    terrain_squares[MAP_STATISTICS.FORESTS] += 1

        total_cells = width * height

        terrain_percents = dict((id_.value, float(square) / total_cells)
                                for id_, square in terrain_squares.items())

        person_race_percents = get_person_race_percents(
            persons_storage.persons.all())
        race_percents = get_race_percents(places_storage.places.all())

        #race to cities percents
        race_cities = dict((race.value, 0) for race in RACE.records)
        for place_model in Place.objects.all():
            place = places_logic.load_place(place_model=place_model)
            race_cities[place.race.value] += 1

        statistics = {
            'terrain_percents': terrain_percents,
            'person_race_percents': person_race_percents,
            'race_percents': race_percents,
            'race_cities': race_cities
        }

        model = MapInfo.objects.create(
            turn_number=turn_number,
            width=width,
            height=height,
            terrain=s11n.to_json([[cell.value for cell in row]
                                  for row in terrain]),
            cells=s11n.to_json(UICells.create(world.generator).serialize()),
            world=world._model,
            statistics=s11n.to_json(statistics))
        return cls(model)
예제 #2
0
파일: races.py 프로젝트: Jazzis18/the-tale
    def demographics(self, persons):
        races = []

        next_delta = self.get_next_delta(persons)

        persons_percents = get_person_race_percents(persons)

        for race in RACE.records:
            races.append(RaceInfo(race=race, percents=self._races[race], delta=next_delta[race], persons_percents=persons_percents[race.value]))

        return sorted(races, key=lambda r: -r.percents)
예제 #3
0
파일: races.py 프로젝트: he1mdallr/the-tale
    def demographics(self, persons):
        races = []

        next_delta = self.get_next_delta(persons)

        persons_percents = get_person_race_percents(persons)

        for race in RACE.records:
            races.append(RaceInfo(race=race, percents=self._races[race], delta=next_delta[race], persons_percents=persons_percents[race.value]))

        return sorted(races, key=lambda r: -r.percents)
예제 #4
0
    def create(cls, turn_number, width, height, terrain, world): # pylint: disable=R0914
        from the_tale.game.map.generator.descriptors import UICells

        terrain_percents = {}

        terrain_squares = collections.defaultdict(int)

        for y in xrange(0, height):
            for x in xrange(0, width):
                cell = world.generator.cell_info(x, y)

                if cell.height < -0.2:
                    terrain_squares[MAP_STATISTICS.LOWLANDS] += 1
                elif cell.height < 0.3:
                    terrain_squares[MAP_STATISTICS.PLAINS] += 1
                else:
                    terrain_squares[MAP_STATISTICS.UPLANDS] += 1

                if cell.vegetation == VEGETATION_TYPE.DESERT:
                    terrain_squares[MAP_STATISTICS.DESERTS] += 1
                elif cell.vegetation == VEGETATION_TYPE.GRASS:
                    terrain_squares[MAP_STATISTICS.GRASS] += 1
                else:
                    terrain_squares[MAP_STATISTICS.FORESTS] += 1

        total_cells = width * height

        terrain_percents = dict( (id_.value, float(square) / total_cells) for id_, square in terrain_squares.items())

        person_race_percents = get_person_race_percents(persons_storage.filter(state=PERSON_STATE.IN_GAME))
        race_percents = get_race_percents(places_storage.all())

        #race to cities percents
        race_cities = dict( (race.value, 0) for race in RACE.records)
        for place_model in Place.objects.all():
            place = PlacePrototype(place_model)
            race_cities[place.race.value] += 1

        statistics = {'terrain_percents': terrain_percents,
                      'person_race_percents': person_race_percents,
                      'race_percents': race_percents,
                      'race_cities': race_cities}

        model = MapInfo.objects.create(turn_number=turn_number,
                                       width=width,
                                       height=height,
                                       terrain=s11n.to_json([ [cell.value for cell in row] for row in terrain]),
                                       cells=s11n.to_json(UICells.create(world.generator).serialize()),
                                       world=world._model,
                                       statistics=s11n.to_json(statistics))
        return cls(model)