예제 #1
0
    def handle(self, *args, **options):  # pylint: disable=R0914

        x = options['x']
        y = options['y']

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

        cell = generator.cell_info(x, y)
        power_cell = generator.cell_power_info(x, y)

        print('----CELL--x=%d--y=%d--' % (x, y))
        print('height:            %.2f \t\t| %r       ' %
              (cell.height, power_cell.height))
        print('temperature:       %.2f \t\t| %f       ' %
              (cell.temperature, power_cell.temperature))
        print('wind:              (%.2f, %.2f) \t| %r ' %
              (cell.wind[0], cell.wind[1], power_cell.wind))
        print('wetness:           %.2f \t\t| %f       ' %
              (cell.wetness, power_cell.wetness))
        print('vegetation:        %.2f \t\t| %r       ' %
              (cell.vegetation, power_cell.vegetation))
        print('soil:              %.2f \t\t| %f       ' %
              (cell.soil, power_cell.soil))
        print('atmo_wind:         (%.2f, %.2f) \t|    ' % cell.atmo_wind)
        print('atmo_temperature:  %.2f \t\t|          ' %
              (cell.atmo_temperature, ))
        print('atmo_wetness:      %.2f \t\t|          ' %
              (cell.atmo_wetness, ))

        terrain_points = []
        for terrain in TERRAIN.records:
            biom = Biom(id_=terrain)
            terrain_points.append(
                (terrain.text, biom.check(cell), biom.get_points(cell)))
        terrain_points = sorted(terrain_points, key=lambda x: -x[1])

        print()
        print('----TERRAIN----')
        for biom_name, total_power, aspects in terrain_points[:5]:
            print('%.2f\t%s' % (total_power, biom_name))

            for aspect_name, aspect_value in aspects:
                print('\t%.2f\t%s' % (aspect_value, aspect_name))

        print()
        print('----POINTS----')

        points = []
        for point in get_power_points():
            value = point.log_powers_for(generator, x=x, y=y)
            if value:
                points.append((point.name, value))
        points.sort()

        for name, value in points:
            print('%s %r' % (name.ljust(35), value))
예제 #2
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.places.shift_all(dx, dy)
        places_storage.buildings.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 range(0, generator.h):
        row = []
        terrain.append(row)
        for x in range(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.places.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()) }

    models.MapRegion.objects.create(turn_number=time.turn_number, data=data)
예제 #3
0
    def handle(self, *args, **options): # pylint: disable=R0914

        x = options['x']
        y = options['y']

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

        cell = generator.cell_info(x, y)
        power_cell = generator.cell_power_info(x, y)

        print '----CELL--x=%d--y=%d--' % (x, y)
        print 'height:            %.2f \t\t| %r       ' % (cell.height, power_cell.height)
        print 'temperature:       %.2f \t\t| %f       ' % (cell.temperature, power_cell.temperature)
        print 'wind:              (%.2f, %.2f) \t| %r ' % (cell.wind[0], cell.wind[1], power_cell.wind)
        print 'wetness:           %.2f \t\t| %f       ' % (cell.wetness, power_cell.wetness)
        print 'vegetation:        %.2f \t\t| %r       ' % (cell.vegetation, power_cell.vegetation)
        print 'soil:              %.2f \t\t| %f       ' % (cell.soil, power_cell.soil)
        print 'atmo_wind:         (%.2f, %.2f) \t|    ' % cell.atmo_wind
        print 'atmo_temperature:  %.2f \t\t|          ' % (cell.atmo_temperature,)
        print 'atmo_wetness:      %.2f \t\t|          ' % (cell.atmo_wetness,)

        terrain_points = []
        for terrain in TERRAIN.records:
            biom = Biom(id_=terrain)
            terrain_points.append((terrain.text, biom.check(cell), biom.get_points(cell)))
        terrain_points = sorted(terrain_points, key=lambda x: -x[1])

        print
        print '----TERRAIN----'
        for biom_name, total_power, aspects in terrain_points[:5]:
            print '%.2f\t%s' % (total_power, biom_name)

            for aspect_name, aspect_value in aspects:
                print '\t%.2f\t%s' % (aspect_value, aspect_name)

        print
        print '----POINTS----'

        points = []
        for point in get_power_points():
            value = point.log_powers_for(generator, x=x, y=y)
            if value:
                points.append((point.name, value))
        points.sort()

        for name, value in points:
            print '%s %r' % (name.ljust(35), value)
예제 #4
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.places.shift_all(dx, dy)
        places_storage.buildings.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.places.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)
예제 #5
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.places.shift_all(dx, dy)
        places_storage.buildings.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.places.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
파일: updater.py 프로젝트: Tiendil/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.places.shift_all(dx, dy)
        places_storage.buildings.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 range(0, generator.h):
        row = []
        terrain.append(row)
        for x in range(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.places.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()),
    }

    models.MapRegion.objects.create(turn_number=time.turn_number, data=data)