extends Node class_name World var heightMap: Array var temperatureMap: Array var moistureMap: Array var blocs: Array var entities: Array var width: int var height: int func get_neighbours_8_at_same_height(point: Vector2i): var neighbours = 0 var current_bloc = heightMap[point.x][point.y] if heightMap[point.x-1][point.y-1] == current_bloc: neighbours += Global.directions_8.TOP_LEFT if heightMap[point.x][point.y-1] == current_bloc: neighbours += Global.directions_8.TOP if heightMap[point.x+1][point.y-1] == current_bloc: neighbours += Global.directions_8.TOP_RIGHT if heightMap[point.x+1][point.y] == current_bloc: neighbours += Global.directions_8.RIGHT if heightMap[point.x+1][point.y+1] == current_bloc: neighbours += Global.directions_8.BOTTOM_RIGHT if heightMap[point.x][point.y+1] == current_bloc: neighbours += Global.directions_8.BOTTOM if heightMap[point.x-1][point.y+1] == current_bloc: neighbours += Global.directions_8.BOTTOM_LEFT if heightMap[point.x-1][point.y] == current_bloc: neighbours += Global.directions_8.LEFT return neighbours func get_neighbours_4_at_same_height(point: Vector2i): var neighbours = 0 var current_bloc = heightMap[point.x][point.y] if heightMap[point.x][point.y-1] == current_bloc: neighbours += Global.directions_4.TOP if heightMap[point.x+1][point.y] == current_bloc: neighbours += Global.directions_4.RIGHT if heightMap[point.x][point.y+1] == current_bloc: neighbours += Global.directions_4.BOTTOM if heightMap[point.x-1][point.y] == current_bloc: neighbours += Global.directions_4.LEFT return neighbours func neighbours(point: Vector2i): var neighbours = [] return [ Vector2i(point.x, point.y - 1), Vector2i(point.x + 1, point.y), Vector2i(point.x, point.y + 1), Vector2i(point.x - 1, point.y), Vector2i(point.x + 1, point.y - 1), Vector2i(point.x + 1, point.y + 1), Vector2i(point.x - 1, point.y + 1), Vector2i(point.x - 1, point.y - 1) ] func get_bloc(point: Vector2i): var bloc = {} bloc["position"] = Vector3i(point.x, heightMap[point.x][point.y], point.y) for key in blocs[point.x][point.y].keys(): bloc[key] = blocs[point.x][point.y][key] return bloc func get_height(point: Vector2i): return heightMap[point.x][point.y] func add_entity(position: Vector2i): entities.append(Entity.new(entities.size(), position)) blocs[position.x][position.y]["entity"] = entities.size() - 1 return entities[entities.size() - 1] func cost(point1: Vector2i, point2: Vector2i): var cost = 1 if ( (point1.x == point2.x + 1 and point1.y == point2.y + 1) or (point1.x == point2.x + 1 and point1.y == point2.y - 1) or (point1.x == point2.x - 1 and point1.y == point2.y + 1) or (point1.x == point2.x - 1 and point1.y == point2.y - 1) ): cost = 1.1 return cost