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 var chunk_size = 64 var chunk_number = 6 var player_position: Vector2i signal new_entity func get_neighbours_8_at_same_height(point: Vector2i): var neighbours = 0 var current_bloc = get_height(Vector2i(point.x, point.y)) if get_height(Vector2i(point.x-1, point.y-1)) == current_bloc: neighbours += Global.directions_8.TOP_LEFT if get_height(Vector2i(point.x, point.y-1)) == current_bloc: neighbours += Global.directions_8.TOP if get_height(Vector2i(point.x+1,point.y-1)) == current_bloc: neighbours += Global.directions_8.TOP_RIGHT if get_height(Vector2i(point.x+1, point.y)) == current_bloc: neighbours += Global.directions_8.RIGHT if get_height(Vector2i(point.x+1, point.y+1)) == current_bloc: neighbours += Global.directions_8.BOTTOM_RIGHT if get_height(Vector2i(point.x, point.y+1)) == current_bloc: neighbours += Global.directions_8.BOTTOM if get_height(Vector2i(point.x-1, point.y+1)) == current_bloc: neighbours += Global.directions_8.BOTTOM_LEFT if get_height(Vector2i(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 = get_height(Vector2i(point.x, point.y)) if get_height(Vector2i(point.x, point.y-1)) == current_bloc: neighbours += Global.directions_4.TOP if get_height(Vector2i(point.x+1, point.y)) == current_bloc: neighbours += Global.directions_4.RIGHT if get_height(Vector2i(point.x, point.y+1)) == current_bloc: neighbours += Global.directions_4.BOTTOM if get_height(Vector2i(point.x-1, point.y)) == current_bloc: neighbours += Global.directions_4.LEFT return neighbours func neighbours(point: Vector2i): var neighbours = [] return [ get_real_coordinates(Vector2i(point.x, point.y - 1)), get_real_coordinates(Vector2i(point.x + 1, point.y)), get_real_coordinates(Vector2i(point.x, point.y + 1)), get_real_coordinates(Vector2i(point.x - 1, point.y)), get_real_coordinates(Vector2i(point.x + 1, point.y - 1)), get_real_coordinates(Vector2i(point.x + 1, point.y + 1)), get_real_coordinates(Vector2i(point.x - 1, point.y + 1)), get_real_coordinates(Vector2i(point.x - 1, point.y - 1)) ] func get_real_coordinates(point: Vector2i): return Vector2i(fposmod(point.x, width), fposmod(point.y, height)) func get_bloc(point: Vector2i): point = get_real_coordinates(point) var bloc = {} bloc["position"] = Vector3i(point.x, get_height(Vector2i(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): point = get_real_coordinates(point) 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 emit_signal("new_entity", entities[entities.size() - 1]) return entities[entities.size() - 1] func cost(point1: Vector2i, point2: Vector2i): var cost = 1 point1 = get_real_coordinates(point1) point2 = get_real_coordinates(point2) 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 func vec_distance(start: Vector2, end: Vector2): var dx = end.x - start.x var dy = end.y - start.y if dx > Global.world.width / 2: dx -= Global.world.width elif dx < -Global.world.width / 2: dx += Global.world.width if dy > Global.world.height / 2: dy -= Global.world.height elif dy < 0 and dy < -Global.world.height / 2: dy += Global.world.height return Vector2i(dx, dy)