예제 #1
0
 def test_return_from_road__after_resurrect(self):
     self.action_idl.state = prototypes.ActionIdlenessPrototype.STATE.RESURRECT
     self.hero.position.set_road(list(roads_storage.all())[0], percents=0.5)
     self.storage.process_turn()
     self.assertEqual(self.hero.actions.number, 2)
     self.assertEqual(self.hero.actions.current_action.TYPE,
                      prototypes.ActionMoveToPrototype.TYPE)
예제 #2
0
파일: drawer.py 프로젝트: pavetok/the-tale
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
예제 #3
0
 def test_get_minumum_distance_to__check_map_structure(self):
     self.assertEqual(len(roads_storage.all()), 2)
예제 #4
0
 def test_return_from_road__after_resurrect(self):
     self.action_idl.state = prototypes.ActionIdlenessPrototype.STATE.RESURRECT
     self.hero.position.set_road(list(roads_storage.all())[0], percents=0.5)
     self.storage.process_turn()
     self.assertEqual(self.hero.actions.number, 2)
     self.assertEqual(self.hero.actions.current_action.TYPE, prototypes.ActionMoveToPrototype.TYPE)
예제 #5
0
파일: updater.py 프로젝트: Alkalit/the-tale
def update_map(index):

    generator = WorldInfoPrototype.get_by_id(map_info_storage.item.world_id).generator

    generator.clear_power_points()
    generator.clear_biomes()

    if generator.w != map_settings.WIDTH or generator.h != map_settings.HEIGHT:
        dx, dy = generator.resize(map_settings.WIDTH, map_settings.HEIGHT)
        places_storage.shift_all(dx, dy)
        buildings_storage.shift_all(dx, dy)

    for point in get_power_points():
        generator.add_power_point(point)

    for terrain in TERRAIN.records:
        generator.add_biom(Biom(id_=terrain))

    generator.do_step()

    biomes_map = generator.get_biomes_map()

    time = TimePrototype.get_current_time()

    draw_info = get_draw_info(biomes_map)

    terrain = []
    for y in xrange(0, generator.h):
        row = []
        terrain.append(row)
        for x in xrange(0, generator.w):
            row.append(biomes_map[y][x].id)

    map_info_storage.set_item(MapInfoPrototype.create(turn_number=time.turn_number,
                                                      width=generator.w,
                                                      height=generator.h,
                                                      terrain=terrain,
                                                      world=WorldInfoPrototype.create_from_generator(generator)))

    MapInfoPrototype.remove_old_infos()

    raw_draw_info = []
    for row in draw_info:
        raw_draw_info.append([])
        for cell in row:
            raw_draw_info[-1].append(cell.get_sprites())

    data = {'width': generator.w,
            'height': generator.h,
            'map_version': map_info_storage.version,
            'format_version': '0.1',
            'draw_info': raw_draw_info,
            'places': dict( (place.id, place.map_info() ) for place in places_storage.all() ),
            # 'buildings': dict( (building.id, building.map_info() ) for building in buildings_storage.all() ),
            'roads': dict( (road.id, road.map_info() ) for road in roads_storage.all()) }

    region_js_file = map_settings.GEN_REGION_OUTPUT % map_info_storage.version

    output_dir_name = os.path.dirname(region_js_file)
    if not os.path.exists(output_dir_name):
        os.makedirs(output_dir_name, 0755)

    with open(region_js_file, 'w') as region_json_file:
        region_json_file.write(s11n.to_json(data).encode('utf-8'))

    if project_settings.DEBUG:
        deworld.draw_world(index, generator, catalog=map_settings.GEN_WORLD_PROGRESSION)
예제 #6
0
def update_map(index):

    generator = WorldInfoPrototype.get_by_id(
        map_info_storage.item.world_id).generator

    generator.clear_power_points()
    generator.clear_biomes()

    if generator.w != map_settings.WIDTH or generator.h != map_settings.HEIGHT:
        dx, dy = generator.resize(map_settings.WIDTH, map_settings.HEIGHT)
        places_storage.shift_all(dx, dy)
        buildings_storage.shift_all(dx, dy)

    for point in get_power_points():
        generator.add_power_point(point)

    for terrain in TERRAIN.records:
        generator.add_biom(Biom(id_=terrain))

    generator.do_step()

    biomes_map = generator.get_biomes_map()

    time = TimePrototype.get_current_time()

    draw_info = get_draw_info(biomes_map)

    terrain = []
    for y in xrange(0, generator.h):
        row = []
        terrain.append(row)
        for x in xrange(0, generator.w):
            row.append(biomes_map[y][x].id)

    map_info_storage.set_item(
        MapInfoPrototype.create(
            turn_number=time.turn_number,
            width=generator.w,
            height=generator.h,
            terrain=terrain,
            world=WorldInfoPrototype.create_from_generator(generator)))

    MapInfoPrototype.remove_old_infos()

    raw_draw_info = []
    for row in draw_info:
        raw_draw_info.append([])
        for cell in row:
            raw_draw_info[-1].append(cell.get_sprites())

    data = {
        'width':
        generator.w,
        'height':
        generator.h,
        'map_version':
        map_info_storage.version,
        'format_version':
        '0.1',
        'draw_info':
        raw_draw_info,
        'places':
        dict((place.id, place.map_info()) for place in places_storage.all()),
        # 'buildings': dict( (building.id, building.map_info() ) for building in buildings_storage.all() ),
        'roads':
        dict((road.id, road.map_info()) for road in roads_storage.all())
    }

    region_js_file = map_settings.GEN_REGION_OUTPUT % map_info_storage.version

    output_dir_name = os.path.dirname(region_js_file)
    if not os.path.exists(output_dir_name):
        os.makedirs(output_dir_name, 0755)

    with open(region_js_file, 'w') as region_json_file:
        region_json_file.write(s11n.to_json(data).encode('utf-8'))

    if project_settings.DEBUG:
        deworld.draw_world(index,
                           generator,
                           catalog=map_settings.GEN_WORLD_PROGRESSION)
예제 #7
0
    def handle(self, *args, **options):

        for road in roads_storage.all():
            road.update()

        roads_storage.save_all()
예제 #8
0
    def handle(self, *args, **options):

        for road in roads_storage.all():
            road.update()

        roads_storage.save_all()