Advertisement
SmallBlue

Pathfinding Component

Jul 8th, 2021
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. /**
  2. * # Speech Component
  3. *
  4. * Sends a message. Requires a shell.
  5. */
  6. /obj/item/circuit_component/pathfind
  7. display_name = "Pathfinder"
  8. display_desc = "Calcualtes a path, returns a list of entities. Each entity is the next step in the path. Can be used with the direction component to move."
  9. circuit_flags = CIRCUIT_FLAG_INPUT_SIGNAL|CIRCUIT_FLAG_OUTPUT_SIGNAL
  10.  
  11. var/datum/port/input/target_X
  12. var/datum/port/input/target_Y
  13.  
  14. var/datum/port/output/output
  15. var/datum/port/output/on_fail
  16.  
  17. /obj/item/circuit_component/pathfind/Initialize()
  18. . = ..()
  19. target_X = add_input_port("X", PORT_TYPE_NUMBER, FALSE)
  20. target_Y = add_input_port("Y", PORT_TYPE_NUMBER, FALSE)
  21.  
  22. output = add_output_port("Output", PORT_TYPE_LIST)
  23. on_fail = add_output_port("Failed", PORT_TYPE_SIGNAL)
  24.  
  25. /obj/item/circuit_component/pathfind/Destroy()
  26. target_X = null
  27. target_Y = null
  28. output = null
  29. on_fail = null
  30. return ..()
  31.  
  32. /obj/item/circuit_component/pathfind/input_received(datum/port/input/port)
  33. . = ..()
  34. if(.)
  35. return
  36.  
  37. if(isnull(target_X))
  38. return
  39.  
  40. if(isnull(target_Y))
  41. return
  42.  
  43. var/atom/movable/shell = parent.shell
  44. var/turf/currentpos = get_turf(shell)
  45. var/turf/destination = locate(target_X, target_Y, currentpos.z)
  46.  
  47. var/list/path = get_path_to(shell, destination)
  48. if(!length(path))
  49. on_fail.set_output(COMPONENT_SIGNAL)
  50. return
  51. else
  52. output.set_output(path)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement