Esempio n. 1
0
def check_step(step_name):
    step = Step.get_by_name(step_name)
    if step is None:
        print("ERROR: unknown step name, using default 'full'")
        return Step.get_by_name("full")
    else:
        return step
Esempio n. 2
0
    def _from_protobuf_world(cls, p_world):
        w = World(p_world.name, p_world.width, p_world.height,
                  p_world.generationData.seed,
                  p_world.generationData.n_plates,
                  p_world.generationData.ocean_level,
                  Step.get_by_name(p_world.generationData.step))

        # Elevation
        e = numpy.array(World._from_protobuf_matrix(p_world.heightMapData))
        e_th = [('sea', p_world.heightMapTh_sea),
                ('plain', p_world.heightMapTh_plain),
                ('hill', p_world.heightMapTh_hill),
                ('mountain', None)]
        w.set_elevation(e, e_th)

        # Plates
        w.set_plates(numpy.array(World._from_protobuf_matrix(p_world.plates)))

        # Ocean
        w.set_ocean(numpy.array(World._from_protobuf_matrix(p_world.ocean)))
        w.sea_depth = numpy.array(World._from_protobuf_matrix(p_world.sea_depth))

        # Biome
        if len(p_world.biome.rows) > 0:
            w.set_biome(numpy.array(
                World._from_protobuf_matrix(
                    p_world.biome, biome_index_to_name), dtype = object))

        # Humidity
        # FIXME: use setters
        if len(p_world.humidity.rows) > 0:
            w.humidity = World._from_protobuf_matrix_with_quantiles(
                p_world.humidity)
            w.humidity['data'] = numpy.array(w.humidity['data'])#numpy conversion

        if len(p_world.irrigation.rows) > 0:
            w.irrigation = numpy.array(World._from_protobuf_matrix(p_world.irrigation))

        if len(p_world.permeabilityData.rows) > 0:
            p = numpy.array(World._from_protobuf_matrix(p_world.permeabilityData))
            p_th = [
                ('low', p_world.permeability_low),
                ('med', p_world.permeability_med),
                ('hig', None)
            ]
            w.set_permeability(p, p_th)

        if len(p_world.watermapData.rows) > 0:
            w.watermap = dict()
            w.watermap['data'] = numpy.array(World._from_protobuf_matrix(
                p_world.watermapData))
            w.watermap['thresholds'] = {}
            w.watermap['thresholds']['creek'] = p_world.watermap_creek
            w.watermap['thresholds']['river'] = p_world.watermap_river
            w.watermap['thresholds']['main river'] = p_world.watermap_mainriver

        if len(p_world.precipitationData.rows) > 0:
            p = numpy.array(World._from_protobuf_matrix(p_world.precipitationData))
            p_th = [
                ('low', p_world.precipitation_low),
                ('med', p_world.precipitation_med),
                ('hig', None)
            ]
            w.set_precipitation(p, p_th)

        if len(p_world.temperatureData.rows) > 0:
            t = numpy.array(World._from_protobuf_matrix(p_world.temperatureData))
            t_th = [
                ('polar', p_world.temperature_polar),
                ('alpine', p_world.temperature_alpine),
                ('boreal', p_world.temperature_boreal),
                ('cool', p_world.temperature_cool),
                ('warm', p_world.temperature_warm),
                ('subtropical', p_world.temperature_subtropical),
                ('tropical', None)
            ]
            w.set_temperature(t, t_th)

        if len(p_world.lakemap.rows) > 0:
            m = numpy.array(World._from_protobuf_matrix(p_world.lakemap))
            w.set_lakemap(m)

        if len(p_world.rivermap.rows) > 0:
            m = numpy.array(World._from_protobuf_matrix(p_world.rivermap))
            w.set_rivermap(m)

        if len(p_world.icecap.rows) > 0:
            w.icecap = numpy.array(World._from_protobuf_matrix(p_world.icecap))

        return w
Esempio n. 3
0
    def _from_protobuf_world(cls, p_world):
        w = World(
            p_world.name, Size(p_world.width, p_world.height),
            p_world.generationData.seed,
            GenerationParameters(p_world.generationData.n_plates,
                                 p_world.generationData.ocean_level,
                                 Step.get_by_name(
                                     p_world.generationData.step)))

        # Elevation
        e = numpy.array(World._from_protobuf_matrix(p_world.heightMapData))
        e_th = [('sea', p_world.heightMapTh_sea),
                ('plain', p_world.heightMapTh_plain),
                ('hill', p_world.heightMapTh_hill), ('mountain', None)]
        w.elevation = (e, e_th)

        # Plates
        w.plates = numpy.array(World._from_protobuf_matrix(p_world.plates))

        # Ocean
        w.ocean = numpy.array(World._from_protobuf_matrix(p_world.ocean))
        w.sea_depth = numpy.array(
            World._from_protobuf_matrix(p_world.sea_depth))

        # Biome
        if len(p_world.biome.rows) > 0:
            w.biome = numpy.array(World._from_protobuf_matrix(
                p_world.biome, biome_index_to_name),
                                  dtype=object)

        # Humidity
        if len(p_world.humidity.rows) > 0:
            w.humidity = World._from_protobuf_matrix_with_quantiles(
                p_world.humidity)

        if len(p_world.irrigation.rows) > 0:
            w.irrigation = numpy.array(
                World._from_protobuf_matrix(p_world.irrigation))

        if len(p_world.permeabilityData.rows) > 0:
            p = numpy.array(
                World._from_protobuf_matrix(p_world.permeabilityData))
            p_th = [('low', p_world.permeability_low),
                    ('med', p_world.permeability_med), ('hig', None)]
            w.permeability = (p, p_th)

        if len(p_world.watermapData.rows) > 0:
            data = numpy.array(
                World._from_protobuf_matrix(p_world.watermapData))
            thresholds = {}
            thresholds['creek'] = p_world.watermap_creek
            thresholds['river'] = p_world.watermap_river
            thresholds['main river'] = p_world.watermap_mainriver
            w.watermap = (data, thresholds)

        if len(p_world.precipitationData.rows) > 0:
            p = numpy.array(
                World._from_protobuf_matrix(p_world.precipitationData))
            p_th = [('low', p_world.precipitation_low),
                    ('med', p_world.precipitation_med), ('hig', None)]
            w.precipitation = (p, p_th)

        if len(p_world.temperatureData.rows) > 0:
            t = numpy.array(
                World._from_protobuf_matrix(p_world.temperatureData))
            t_th = [('polar', p_world.temperature_polar),
                    ('alpine', p_world.temperature_alpine),
                    ('boreal', p_world.temperature_boreal),
                    ('cool', p_world.temperature_cool),
                    ('warm', p_world.temperature_warm),
                    ('subtropical', p_world.temperature_subtropical),
                    ('tropical', None)]
            w.temperature = (t, t_th)

        if len(p_world.lakemap.rows) > 0:
            w.lakemap = numpy.array(
                World._from_protobuf_matrix(p_world.lakemap))

        if len(p_world.rivermap.rows) > 0:
            w.rivermap = numpy.array(
                World._from_protobuf_matrix(p_world.rivermap))

        if len(p_world.icecap.rows) > 0:
            w.icecap = numpy.array(World._from_protobuf_matrix(p_world.icecap))

        return w
Esempio n. 4
0
    def _from_protobuf_world(cls, p_world):
        w = World(p_world.name, p_world.width, p_world.height,
                  p_world.generationData.seed, p_world.generationData.n_plates,
                  p_world.generationData.ocean_level,
                  Step.get_by_name(p_world.generationData.step))

        # Elevation
        e = numpy.array(World._from_protobuf_matrix(p_world.heightMapData))
        e_th = [('sea', p_world.heightMapTh_sea),
                ('plain', p_world.heightMapTh_plain),
                ('hill', p_world.heightMapTh_hill), ('mountain', None)]
        w.set_elevation(e, e_th)

        # Plates
        w.set_plates(numpy.array(World._from_protobuf_matrix(p_world.plates)))

        # Ocean
        w.set_ocean(numpy.array(World._from_protobuf_matrix(p_world.ocean)))
        w.sea_depth = numpy.array(
            World._from_protobuf_matrix(p_world.sea_depth))

        # Biome
        if len(p_world.biome.rows) > 0:
            w.set_biome(
                numpy.array(World._from_protobuf_matrix(
                    p_world.biome, biome_index_to_name),
                            dtype=object))

        # Humidity
        # FIXME: use setters
        if len(p_world.humidity.rows) > 0:
            w.humidity = World._from_protobuf_matrix_with_quantiles(
                p_world.humidity)
            w.humidity['data'] = numpy.array(
                w.humidity['data'])  #numpy conversion

        if len(p_world.irrigation.rows) > 0:
            w.irrigation = numpy.array(
                World._from_protobuf_matrix(p_world.irrigation))

        if len(p_world.permeabilityData.rows) > 0:
            p = numpy.array(
                World._from_protobuf_matrix(p_world.permeabilityData))
            p_th = [('low', p_world.permeability_low),
                    ('med', p_world.permeability_med), ('hig', None)]
            w.set_permeability(p, p_th)

        if len(p_world.watermapData.rows) > 0:
            w.watermap = dict()
            w.watermap['data'] = numpy.array(
                World._from_protobuf_matrix(p_world.watermapData))
            w.watermap['thresholds'] = {}
            w.watermap['thresholds']['creek'] = p_world.watermap_creek
            w.watermap['thresholds']['river'] = p_world.watermap_river
            w.watermap['thresholds']['main river'] = p_world.watermap_mainriver

        if len(p_world.precipitationData.rows) > 0:
            p = numpy.array(
                World._from_protobuf_matrix(p_world.precipitationData))
            p_th = [('low', p_world.precipitation_low),
                    ('med', p_world.precipitation_med), ('hig', None)]
            w.set_precipitation(p, p_th)

        if len(p_world.temperatureData.rows) > 0:
            t = numpy.array(
                World._from_protobuf_matrix(p_world.temperatureData))
            t_th = [('polar', p_world.temperature_polar),
                    ('alpine', p_world.temperature_alpine),
                    ('boreal', p_world.temperature_boreal),
                    ('cool', p_world.temperature_cool),
                    ('warm', p_world.temperature_warm),
                    ('subtropical', p_world.temperature_subtropical),
                    ('tropical', None)]
            w.set_temperature(t, t_th)

        if len(p_world.lakemap.rows) > 0:
            m = numpy.array(World._from_protobuf_matrix(p_world.lakemap))
            w.set_lakemap(m)

        if len(p_world.rivermap.rows) > 0:
            m = numpy.array(World._from_protobuf_matrix(p_world.rivermap))
            w.set_rivermap(m)

        if len(p_world.icecap.rows) > 0:
            w.icecap = numpy.array(World._from_protobuf_matrix(p_world.icecap))

        return w
Esempio n. 5
0
    def _from_protobuf_world(cls, p_world):
        w = World(p_world.name, Size(p_world.width, p_world.height),
                  p_world.generationData.seed,
                  GenerationParameters(p_world.generationData.n_plates,
                        p_world.generationData.ocean_level,
                        Step.get_by_name(p_world.generationData.step)))

        # Elevation
        e = numpy.array(World._from_protobuf_matrix(p_world.heightMapData))
        e_th = [('sea', p_world.heightMapTh_sea),
                ('plain', p_world.heightMapTh_plain),
                ('hill', p_world.heightMapTh_hill),
                ('mountain', None)]
        w.elevation = (e, e_th)

        # Plates
        w.plates = numpy.array(World._from_protobuf_matrix(p_world.plates))

        # Ocean
        w.ocean = numpy.array(World._from_protobuf_matrix(p_world.ocean))
        w.sea_depth = numpy.array(World._from_protobuf_matrix(p_world.sea_depth))

        # Biome
        if len(p_world.biome.rows) > 0:
            w.biome = numpy.array(World._from_protobuf_matrix(p_world.biome, biome_index_to_name), dtype=object)

        # Humidity
        if len(p_world.humidity.rows) > 0:
            w.humidity = World._from_protobuf_matrix_with_quantiles(p_world.humidity)

        if len(p_world.irrigation.rows) > 0:
            w.irrigation = numpy.array(World._from_protobuf_matrix(p_world.irrigation))

        if len(p_world.permeabilityData.rows) > 0:
            p = numpy.array(World._from_protobuf_matrix(p_world.permeabilityData))
            p_th = [
                ('low', p_world.permeability_low),
                ('med', p_world.permeability_med),
                ('hig', None)
            ]
            w.permeability = (p, p_th)

        if len(p_world.watermapData.rows) > 0:
            data = numpy.array(World._from_protobuf_matrix(
                p_world.watermapData))
            thresholds = {}
            thresholds['creek'] = p_world.watermap_creek
            thresholds['river'] = p_world.watermap_river
            thresholds['main river'] = p_world.watermap_mainriver
            w.watermap = (data, thresholds)

        if len(p_world.precipitationData.rows) > 0:
            p = numpy.array(World._from_protobuf_matrix(p_world.precipitationData))
            p_th = [
                ('low', p_world.precipitation_low),
                ('med', p_world.precipitation_med),
                ('hig', None)
            ]
            w.precipitation = (p, p_th)

        if len(p_world.temperatureData.rows) > 0:
            t = numpy.array(World._from_protobuf_matrix(p_world.temperatureData))
            t_th = [
                ('polar', p_world.temperature_polar),
                ('alpine', p_world.temperature_alpine),
                ('boreal', p_world.temperature_boreal),
                ('cool', p_world.temperature_cool),
                ('warm', p_world.temperature_warm),
                ('subtropical', p_world.temperature_subtropical),
                ('tropical', None)
            ]
            w.temperature = (t, t_th)

        if len(p_world.lakemap.rows) > 0:
            w.lakemap = numpy.array(World._from_protobuf_matrix(p_world.lakemap))

        if len(p_world.rivermap.rows) > 0:
            w.rivermap = numpy.array(World._from_protobuf_matrix(p_world.rivermap))

        if len(p_world.icecap.rows) > 0:
            w.icecap = numpy.array(World._from_protobuf_matrix(p_world.icecap))

        return w