Exemplo n.º 1
0
    def __init__(self, **settings):
        self.height = settings['height']
        self.width = settings['width']
        self.wrapping = settings['wrapping']

        self.tiles = [None] * self.height
        for i in range(self.height):
            self.tiles[i] = [None] * self.width
            for j in range(self.width):
                self.tiles[i][j] = Tile((j, i), self)
Exemplo n.º 2
0
def kml_zone_to_tiles(kml_file):
    k = kml.KML()
    with open(kml_file, 'rb') as kml_handle:
        doc = kml_handle.read()
        k.from_string(doc)

    features = list(k.features())
    folder = list(features[0].features())[0]
    geometry = folder.geometry
    tiles_inner = set()
    tiles_outer = set()

    if hasattr(geometry, 'geoms'):
        geoms = geometry.geoms
    else:
        geoms = [geometry]

    for geo in geoms:
        polygon = Polygon(geo)
        (min_x, min_y, max_x, max_y) = polygon.bounds

        tile_min_x, tile_min_y = tile_from_coord(min_y, min_x)
        tile_max_x, tile_max_y = tile_from_coord(max_y, max_x)
        if tile_max_x < tile_min_x:
            tmp = tile_min_x
            tile_min_x = tile_max_x
            tile_max_x = tmp
        if tile_max_y < tile_min_y:
            tmp = tile_min_y
            tile_min_y = tile_max_y
            tile_max_y = tmp
        for x in range(tile_min_x, tile_max_x + 1):
            for y in range(tile_min_y, tile_max_y + 1):
                t = Tile(x, y)
                if polygon.intersects(t.polygon):
                    tiles_outer.add((x, y))
                    if polygon.contains(t.polygon):
                        tiles_inner.add((x, y))
    return tiles_inner, tiles_outer
Exemplo n.º 3
0
 def generate(self, name, heightmap):
     """
     Generates region
     heightmap is a grayscale bitmap for height
     colormap is color bitmap for terrain texture
     terrainTextureDB is data on texture to use for color map
     """
     self.heightmap = heightmap
     heightmapBuffer = StringIO.StringIO(self.heightmap)
     heightmapImage = Image.open(heightmapBuffer)
     self.width, self.height = heightmapImage.size
     # Image is 1 px more than number of tiles
     self.width -= 1
     self.height -= 1
     self.name = name
     # Generate the simulation tiles
     tileid = 0
     for y in range(self.height):
         for x in range(self.width):
             tile = Tile(tileid, coords=(x,y))
             self.tiles.append(tile)
             tileid+= 1
     # Other generations such as initial roads, etc, is done here
     self.sendGameState()
users = load_users()
config = load_config()

community_tiles = set()
geoms_users = []

for user in users:
    print(user['name'])
    url_uid = user['url'].split('/')[-1]

    user_tiles = statshunters.tiles_from_activities(
        url_uid, filter_fct=lambda act: 'Virtual' not in act['type'])
    community_tiles |= user_tiles

    geom_z = unary_union([Tile(*t).polygon for t in user_tiles])
    geoms_users.append(geom_z)

geom_z = unary_union(geoms_users)

output_file = os.path.join(GEN_USERS, "kikourou_tiles.kml")
if output_file:
    kml_file_from_polygons(geom_z, output_file)

report = ""
db_report = ""
for country in config['countries']:
    outer_zones = zones.load_zones_outer(
        re_filter=config['countries'][country])

    all_tiles_country = set()
Exemplo n.º 5
0
def create_kml_for_tiles(tiles, kml_file):
    kml_file_from_polygons([Tile(x, y).polygon for (x, y) in tiles], kml_file)
Exemplo n.º 6
0
 def __init__(self, moves=1):
     Tile.__init__(self)
     self.moves = moves
Exemplo n.º 7
0
 def __init__(self):
     Tile.__init__(self)
Exemplo n.º 8
0
 def __init__(self, angle=0):
     Tile.__init__(self, angle)
Exemplo n.º 9
0
 def __init__(self, kind=0):
     Tile.__init__(self)
     self.kind = kind
Exemplo n.º 10
0
 def __init__(self, directions: [DeltaCoord], angle=0):
     Tile.__init__(self, angle)
     self.directions = directions
Exemplo n.º 11
0
 def __init__(self, bottles):
     Tile.__init__(self)
     self.bottles = bottles
Exemplo n.º 12
0
 def __init__(self, steps=0):
     Tile.__init__(self)
     self.steps = steps
Exemplo n.º 13
0
 def __init__(self, money):
     Tile.__init__(self)
     self.money = money