Initial Upload

This commit is contained in:
FrederikBaerentsen 2024-12-17 21:38:41 +01:00
parent 73b4d564c8
commit eec9c0a84b
6 changed files with 63331 additions and 0 deletions

31760
FlightPathFinder.lua Normal file

File diff suppressed because it is too large Load Diff

7
FlightPathFinder.toc Normal file
View File

@ -0,0 +1,7 @@
## Interface: 11405
## Title: FlightPathFinder
## Notes: A simple addon to find the nearest flight path.
## Version: 1.0
## Dependencies: HereBeDragons
FlightPathFinder.lua

22141
Flights.lua Normal file

File diff suppressed because it is too large Load Diff

9299
flight_points.lua Normal file

File diff suppressed because it is too large Load Diff

52
luaTable.py Normal file
View File

@ -0,0 +1,52 @@
import csv
def escape_lua_string(value):
"""
Escape double quotes and backslashes for Lua strings.
Lua uses \" to escape double quotes and \\ for backslashes.
"""
return value.replace("\\", "\\\\").replace("'", "\\'")
def csv_to_lua_table(input_csv, output_lua):
# Define the fields we care about
fields_to_include = ["name", "y", "x", "ID", "ContinentID"]
with open(input_csv, mode='r', newline='', encoding='utf-8') as csv_file:
# Assuming comma-delimited CSV
csv_reader = csv.DictReader(csv_file)
with open(output_lua, mode='w', encoding='utf-8') as lua_file:
lua_file.write("flightPoints = {\n")
for row in csv_reader:
lua_file.write(" {\n")
for field in fields_to_include:
value = row[field]
# Escape and format Lua strings with single quotes
if field == "name":
if "'" in value:
lua_value.replace("'","\'")
lua_value = f"'{escape_lua_string(value)}'"
# Handle numeric fields
elif value.replace('.', '', 1).isdigit() or (value[0] == '-' and value[1:].replace('.', '', 1).isdigit()):
lua_value = value
else:
lua_value = f"'{value}'"
lua_file.write(f" {field} = {lua_value},\n")
lua_file.write(" },\n")
lua_file.write("}\n\n")
# Input CSV file and output Lua file paths
input_csv = "flight_points.csv"
output_lua = "flight_points.lua"
# Convert CSV to Lua table
csv_to_lua_table(input_csv, output_lua)
print(f"Lua table has been written to {output_lua}")

72
test.lua Normal file
View File

@ -0,0 +1,72 @@
-- main.lua
-- Import the A* algorithm and graph
local a_star = require("a_star")
local Flights = require("Flights")
-- Input parameters
local faction = "Alliance"
local start_node = 2089
local end_node = 66 --ashenvale
-- Run the A* algorithm
local paths, cost = a_star.run(Flights, faction, start_node, end_node)
-- Output the result
if paths then
print("Total cost: " .. cost .. " seconds")
print("Paths found:")
for i, path in ipairs(paths) do
-- Construct path names
local path_names = {}
for _, node in ipairs(path) do
local name = Flights[faction][node]["name"]
table.insert(path_names, name or "Unknown")
end
-- Output each path
print(string.format("Path %d (IDs): %s", i, table.concat(path, " -> ")))
print(string.format("Path %d (Names): %s", i, table.concat(path_names, " -> ")))
end
else
print("Error: " .. cost)
end
local input_node = 2089 -- Node ID for which we want to list available neighbors
-- -- Get all neighbors with their travel time
-- local neighbors, err = a_star.get_neighbors_with_cost(Flights, faction, input_node)
-- -- Output the result
-- if neighbors then
-- print("Available end nodes from node " .. input_node .. ":")
-- for _, neighbor_info in ipairs(neighbors) do
-- local node = neighbor_info.neighbor
-- local cost = neighbor_info.cost
-- local name = Flights[faction][node]["name"] or "Unknown"
-- print(string.format("Node ID: %d, Name: %s, Time: %d seconds", node, name, cost))
-- end
-- else
-- print("Error: " .. err)
-- end
local paths, err = a_star.get_all_paths_with_cost(Flights, faction, start_node)
-- Output the result
if paths then
print("All reachable end nodes from node " .. start_node .. ":")
for _, path_info in ipairs(paths) do
local node = path_info.neighbor
local cost = path_info.cost
-- Check if the node exists in the faction and fetch its name
local node_data = Flights[faction][node]
local name = node_data and node_data["name"] or "Unknown"
print(string.format("Node ID: %d, Name: %s, Time: %d seconds", node, name, cost))
end
else
print("Error: " .. err)
end