Advertisement
Guest User

Untitled

a guest
Nov 18th, 2020
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. extends Node
  2.  
  3.  
  4. class HyperAStar2D:
  5.     extends AStar2D
  6.    
  7.     func _compute_cost(u : int, v : int):
  8.         print("blamo")
  9.         return 1.0
  10.    
  11.     func _estimate_cost(u : int, v : int):
  12.         print("blamo")
  13.         return 1.0
  14.  
  15.  
  16. var astar : HyperAStar2D
  17.  
  18. var map_nodes_by_name : Dictionary
  19. var map_nodes_by_id : Dictionary
  20.  
  21.  
  22. func setup(map_nodes, map_edges):
  23.     # initialize the pathfinder + the map nodes dict
  24.     astar = HyperAStar2D.new()
  25.     map_nodes_by_name = map_nodes
  26.     map_nodes_by_id = {}
  27.    
  28.    
  29.     for node in map_nodes.values():
  30.         # add to map nodes by ID so this script can pass back MapNode objects
  31.         # rather than id numbers
  32.         map_nodes_by_id[node.system_id] = node
  33.        
  34.         # add point to astar
  35.         astar.add_point(node.system_id, node.coordinates)
  36.        
  37.     for edge in map_edges:
  38.         var system_id_a = edge.system_a.system_id
  39.         var system_id_b = edge.system_b.system_id
  40.        
  41.         astar.connect_points(system_id_a, system_id_b)
  42.  
  43.  
  44. func get_path_by_sysname(system_a : String, system_b : String) -> Array:
  45.     var system_id_a : int = map_nodes_by_name[system_a].system_id
  46.     var system_id_b : int = map_nodes_by_name[system_b].system_id
  47.    
  48.     var id_path = astar.get_id_path(system_id_a, system_id_b)
  49.     var node_path = []
  50.    
  51.     for id in id_path:
  52.         var node = map_nodes_by_id[id]
  53.         node_path.append(node)
  54.        
  55.     return node_path
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement