Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends Node
- class HyperAStar2D:
- extends AStar2D
- func _compute_cost(u : int, v : int):
- print("blamo")
- return 1.0
- func _estimate_cost(u : int, v : int):
- print("blamo")
- return 1.0
- var astar : HyperAStar2D
- var map_nodes_by_name : Dictionary
- var map_nodes_by_id : Dictionary
- func setup(map_nodes, map_edges):
- # initialize the pathfinder + the map nodes dict
- astar = HyperAStar2D.new()
- map_nodes_by_name = map_nodes
- map_nodes_by_id = {}
- for node in map_nodes.values():
- # add to map nodes by ID so this script can pass back MapNode objects
- # rather than id numbers
- map_nodes_by_id[node.system_id] = node
- # add point to astar
- astar.add_point(node.system_id, node.coordinates)
- for edge in map_edges:
- var system_id_a = edge.system_a.system_id
- var system_id_b = edge.system_b.system_id
- astar.connect_points(system_id_a, system_id_b)
- func get_path_by_sysname(system_a : String, system_b : String) -> Array:
- var system_id_a : int = map_nodes_by_name[system_a].system_id
- var system_id_b : int = map_nodes_by_name[system_b].system_id
- var id_path = astar.get_id_path(system_id_a, system_id_b)
- var node_path = []
- for id in id_path:
- var node = map_nodes_by_id[id]
- node_path.append(node)
- return node_path
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement