def test_apply(self):
        self.assertEqual(Building.objects.all().count(), 0)

        VotePrototype.create(self.account2, self.bill, False)
        VotePrototype.create(self.account3, self.bill, True)

        noun = names.generator.get_test_name('r-building-name')

        data = linguistics_helpers.get_word_post_data(noun, prefix='name')
        data.update({'approved': True})

        form = BuildingCreate.ModeratorForm(data)

        self.assertTrue(form.is_valid())
        self.bill.update_by_moderator(form)

        self.assertTrue(self.bill.apply())

        bill = BillPrototype.get_by_id(self.bill.id)
        self.assertTrue(bill.state.is_ACCEPTED)

        self.assertEqual(Building.objects.all().count(), 1)

        building = buildings_storage.all()[0]

        self.assertEqual(building.person.id, self.person_1.id)
        self.assertEqual(building.place.id, self.place1.id)
        self.assertEqual(building.utg_name, noun)
示例#2
0
    def test_apply(self):
        self.assertEqual(Building.objects.all().count(), 0)

        VotePrototype.create(self.account2, self.bill, False)
        VotePrototype.create(self.account3, self.bill, True)

        noun = names.generator.get_test_name('r-building-name')

        data = linguistics_helpers.get_word_post_data(noun, prefix='name')
        data.update({'approved': True})

        form = BuildingCreate.ModeratorForm(data)

        self.assertTrue(form.is_valid())
        self.bill.update_by_moderator(form)

        self.assertTrue(self.bill.apply())

        bill = BillPrototype.get_by_id(self.bill.id)
        self.assertTrue(bill.state.is_ACCEPTED)

        self.assertEqual(Building.objects.all().count(), 1)

        building = buildings_storage.all()[0]

        self.assertEqual(building.person.id, self.person_1.id)
        self.assertEqual(building.place.id, self.place1.id)
        self.assertEqual(building.utg_name, noun)
示例#3
0
def get_power_points():

    month = TimePrototype.get_current_time().game_time.month_record

    points = []

    points = [
        _default_temperature_points(delta={
            MONTHS.COLD: -0.1,
            MONTHS.HOT: 0.1
        }.get(month, 0)),
        _default_wetness_points(delta={
            MONTHS.DRY: -0.1,
            MONTHS.CRUDE: 0.1
        }.get(month, 0)),
        _default_vegetation_points(),
        _default_soil_points()
    ]

    for place in places_storage.all():
        points.extend(get_place_power_points(place))
        for race in RACE.records:
            points.extend(get_place_race_power_points(place, race))

    for building in buildings_storage.all():
        points.extend(get_building_power_points(building))

    return points
示例#4
0
    def sync_data(self, sheduled=True):

        self.logger.info('sync data')

        all_persons = persons_storage.persons_storage.filter(state=PERSON_STATE.IN_GAME)

        self.sync_persons_powers(persons=[person for person in all_persons if person.place.is_frontier])
        self.sync_persons_powers(persons=[person for person in all_persons if not person.place.is_frontier])

        for person in all_persons:
            person.update_friends_number()
            person.update_enemies_number()

        self.persons_power = {}

        self.sync_places_powers(places=[place for place in places_storage.all() if place.is_frontier])
        self.sync_places_powers(places=[place for place in places_storage.all() if not place.is_frontier])

        self.places_power = {}

        # update size
        if sheduled:
            self.sync_sizes([place for place in places_storage.all() if place.is_frontier],
                            hours=c.MAP_SYNC_TIME_HOURS,
                            max_size=places_settings.MAX_FRONTIER_SIZE)

            self.sync_sizes([place for place in places_storage.all() if not place.is_frontier],
                            hours=c.MAP_SYNC_TIME_HOURS,
                            max_size=places_settings.MAX_SIZE)


        for place in places_storage.all():
            place.sync_stability()
            place.sync_modifier()
            place.sync_habits()

            place.sync_parameters() # must be last operation to display and use real data

            place.update_heroes_number()
            place.update_heroes_habits()

            place.mark_as_updated()

        places_storage.save_all()

        persons_storage.persons_storage.remove_out_game_persons()
        persons_storage.persons_storage.save_all()

        persons_logic.sync_social_connections()

        if sheduled:
            for building in buildings_storage.all():
                building.amortize(c.MAP_SYNC_TIME)

        buildings_storage.save_all()

        self.logger.info('sync data completed')
示例#5
0
    def test_apply(self):
        self.assertEqual(Building.objects.filter(state=BUILDING_STATE.WORKING).count(), 2)

        VotePrototype.create(self.account2, self.bill, False)
        VotePrototype.create(self.account3, self.bill, True)

        form = BuildingDestroy.ModeratorForm({'approved': True})
        self.assertTrue(form.is_valid())
        self.bill.update_by_moderator(form)

        self.assertTrue(self.bill.apply())

        bill = BillPrototype.get_by_id(self.bill.id)
        self.assertTrue(bill.state.is_ACCEPTED)

        self.assertEqual(Building.objects.filter(state=BUILDING_STATE.WORKING).count(), 1)
        self.assertEqual(len(buildings_storage.all()), 1)

        building = buildings_storage.all()[0]

        self.assertNotEqual(building.id, self.building_1.id)
示例#6
0
    def get_available_positions(
        cls,
        center_x,
        center_y,
        building_position_radius=places_settings.BUILDING_POSITION_RADIUS):  # pylint: disable=R0914
        from the_tale.game.map.places.storage import places_storage, buildings_storage
        from the_tale.game.map.roads.storage import roads_storage
        from the_tale.game.map.roads.relations import PATH_DIRECTION

        positions = set()

        for i in xrange(0, building_position_radius + 1):
            for j in xrange(0, building_position_radius + 1):
                positions.add((center_x + i, center_y + j))
                positions.add((center_x - i, center_y + j))
                positions.add((center_x + i, center_y - j))
                positions.add((center_x - i, center_y - j))

        positions = set(pos for pos in positions
                        if 0 <= pos[0] < map_settings.WIDTH
                        and 0 <= pos[1] < map_settings.HEIGHT)

        removed_positions = set()

        for place in places_storage.all():
            removed_positions.add((place.x, place.y))

        for building in buildings_storage.all():
            removed_positions.add((building.x, building.y))

        for road in roads_storage.all_exists_roads():
            x, y = road.point_1.x, road.point_1.y
            for direction in road.path:
                if direction == PATH_DIRECTION.LEFT.value: x -= 1
                elif direction == PATH_DIRECTION.RIGHT.value: x += 1
                elif direction == PATH_DIRECTION.UP.value: y -= 1
                elif direction == PATH_DIRECTION.DOWN.value: y += 1

                removed_positions.add((x, y))

        result = positions - removed_positions

        return result if result else cls.get_available_positions(
            center_x,
            center_y,
            building_position_radius=building_position_radius + 1)
示例#7
0
def get_draw_info(biomes_map):

    width = map_info_storage.item.width
    height = map_info_storage.item.height

    map_images = []
    for y in xrange(height):
        map_images.append([])
        for x in xrange(width):
            map_images[-1].append(CellDrawer())


    roads_map = get_roads_map(width, height, roads_storage.all())

    for y in xrange(height):
        for x in xrange(width):
            biom = biomes_map[y][x]
            cell_drawer = map_images[y][x]

            cell_drawer.terrain = SPRITES.index_name[biom.id.name]

            if roads_map[y][x]:
                road_sprite = get_road_sprite_info(roads_map, x, y)

                cell_drawer.road = SPRITES.index_name[road_sprite['name']]
                cell_drawer.road_rotate = road_sprite['rotate']

    for place in places_storage.all():
        if place.size < 3: verbose_size = 'small'
        elif place.size < 6: verbose_size = 'medium'
        elif place.size < 9: verbose_size = 'large'
        else: verbose_size = 'capital'

        sprite_name = ('city_%s_%s' % (place.race.name.lower(), verbose_size)).upper()

        cell_drawer = map_images[place.y][place.x]
        cell_drawer.object = SPRITES.index_name[sprite_name]

    for building in buildings_storage.all():
        sprite_name = 'BUILDING_%s' % building.type.name

        cell_drawer = map_images[building.y][building.x]
        cell_drawer.object = SPRITES.index_name[sprite_name]

    return map_images
示例#8
0
    def test_get_available_positions(self):

        building = BuildingPrototype.create(self.place_1.persons[0],
                                            utg_name=names.generator.get_test_name(name='building-name'))

        positions = BuildingPrototype.get_available_positions(self.place_1.x, self.place_1.y)

        self.assertTrue(positions)

        for place in places_storage.all():
            self.assertFalse((place.x, place.y) in positions)

        for building in buildings_storage.all():
            self.assertFalse((building.x, building.y) in positions)

        for x, y in positions:
            self.assertTrue(0 <= x < map_settings.WIDTH)
            self.assertTrue(0 <= y < map_settings.HEIGHT)
示例#9
0
    def test_get_available_positions(self):

        building = BuildingPrototype.create(
            self.place_1.persons[0],
            utg_name=names.generator.get_test_name(name='building-name'))

        positions = BuildingPrototype.get_available_positions(
            self.place_1.x, self.place_1.y)

        self.assertTrue(positions)

        for place in places_storage.all():
            self.assertFalse((place.x, place.y) in positions)

        for building in buildings_storage.all():
            self.assertFalse((building.x, building.y) in positions)

        for x, y in positions:
            self.assertTrue(0 <= x < map_settings.WIDTH)
            self.assertTrue(0 <= y < map_settings.HEIGHT)
示例#10
0
def get_power_points():

    month = TimePrototype.get_current_time().game_time.month_record

    points = []

    points = [_default_temperature_points(delta={MONTHS.COLD: -0.1, MONTHS.HOT: 0.1}.get(month, 0)),
              _default_wetness_points(delta={MONTHS.DRY: -0.1, MONTHS.CRUDE: 0.1}.get(month, 0)),
              _default_vegetation_points(),
              _default_soil_points()]

    for place in places_storage.all():
        points.extend(get_place_power_points(place))
        for race in RACE.records:
            points.extend(get_place_race_power_points(place, race))

    for building in buildings_storage.all():
        points.extend(get_building_power_points(building))

    return points
示例#11
0
    def get_available_positions(cls, center_x, center_y, building_position_radius=places_settings.BUILDING_POSITION_RADIUS): # pylint: disable=R0914
        from the_tale.game.map.places.storage import places_storage, buildings_storage
        from the_tale.game.map.roads.storage import roads_storage
        from the_tale.game.map.roads.relations import PATH_DIRECTION

        positions = set()

        for i in xrange(0, building_position_radius+1):
            for j in xrange(0, building_position_radius+1):
                positions.add((center_x+i, center_y+j))
                positions.add((center_x-i, center_y+j))
                positions.add((center_x+i, center_y-j))
                positions.add((center_x-i, center_y-j))

        positions =  set(pos for pos in positions
                         if 0 <= pos[0] < map_settings.WIDTH and 0 <= pos[1] < map_settings.HEIGHT)

        removed_positions = set()

        for place in places_storage.all():
            removed_positions.add((place.x, place.y))

        for building in buildings_storage.all():
            removed_positions.add((building.x, building.y))

        for road in roads_storage.all_exists_roads():
            x, y = road.point_1.x, road.point_1.y
            for direction in road.path:
                if direction == PATH_DIRECTION.LEFT.value: x -= 1
                elif direction == PATH_DIRECTION.RIGHT.value: x += 1
                elif direction == PATH_DIRECTION.UP.value: y -= 1
                elif direction == PATH_DIRECTION.DOWN.value: y += 1

                removed_positions.add((x, y))

        result = positions - removed_positions

        return result if result else cls.get_available_positions(center_x, center_y, building_position_radius=building_position_radius+1)
示例#12
0
    def sync_data(self, sheduled=True):

        self.logger.info('sync data')

        all_persons = persons_storage.persons_storage.filter(
            state=PERSON_STATE.IN_GAME)

        self.sync_persons_powers(persons=[
            person for person in all_persons if person.place.is_frontier
        ])
        self.sync_persons_powers(persons=[
            person for person in all_persons if not person.place.is_frontier
        ])

        for person in all_persons:
            person.update_friends_number()
            person.update_enemies_number()

        self.persons_power = {}

        self.sync_places_powers(places=[
            place for place in places_storage.all() if place.is_frontier
        ])
        self.sync_places_powers(places=[
            place for place in places_storage.all() if not place.is_frontier
        ])

        self.places_power = {}

        # update size
        if sheduled:
            self.sync_sizes(
                [place for place in places_storage.all() if place.is_frontier],
                hours=c.MAP_SYNC_TIME_HOURS,
                max_size=places_settings.MAX_FRONTIER_SIZE)

            self.sync_sizes([
                place
                for place in places_storage.all() if not place.is_frontier
            ],
                            hours=c.MAP_SYNC_TIME_HOURS,
                            max_size=places_settings.MAX_SIZE)

        for place in places_storage.all():
            place.sync_stability()
            place.sync_modifier()
            place.sync_habits()

            place.sync_parameters(
            )  # must be last operation to display and use real data

            place.update_heroes_number()
            place.update_heroes_habits()

            place.mark_as_updated()

        places_storage.save_all()

        persons_storage.persons_storage.remove_out_game_persons()
        persons_storage.persons_storage.save_all()

        persons_logic.sync_social_connections()

        if sheduled:
            for building in buildings_storage.all():
                building.amortize(c.MAP_SYNC_TIME)

        buildings_storage.save_all()

        self.logger.info('sync data completed')