Public repository for MUR pre alpha
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

138 lines
2.9 KiB

  1. extends MeshInstance
  2. class_name Road
  3. export var end_rotation:Vector3 = Vector3(0,0,0)
  4. export var first_speed_factor:float = 1.0
  5. export var creator_speed_factor:float = 1.0
  6. export var chasers_speed_factor:float = 1.0
  7. export var reset_index:int = 0
  8. export (PoolVector3Array) var speed_constrains = PoolVector3Array()
  9. export (PoolVector3Array) var force_penalties = PoolVector3Array()
  10. export (PoolVector3Array) var torque_penalties = PoolVector3Array()
  11. export (Array,float) var path_penalties = []
  12. var body:StaticBody
  13. var creator:int = -1
  14. var preview:bool = false
  15. func _init():
  16. if not has_node("StaticBody"):
  17. body = StaticBody.new()
  18. body.set_name("StaticBody")
  19. var shape = CollisionShape.new()
  20. shape.set_name("CollisionShape")
  21. shape.shape = mesh.create_trimesh_shape()
  22. body.add_child(shape)
  23. body.set_collision_layer_bit(0,1)
  24. body.set_collision_layer_bit(1,1)
  25. body.set_collision_layer_bit(2,1)
  26. body.set_collision_layer_bit(3,1)
  27. add_child(body)
  28. else:
  29. body = get_node("StaticBody")
  30. func get_creator():
  31. return creator
  32. func set_creator(new_creator):
  33. creator = int(new_creator)
  34. func set_color(new_color):
  35. pass # TODO
  36. func get_path():
  37. return get_node("Path")
  38. func get_curve():
  39. return get_path().get_curve()
  40. func get_lane_curve(lane:int):
  41. if has_node("lanes"):
  42. return get_node("lanes").get_child(lane).get_curve()
  43. else:
  44. return get_path().get_curve()
  45. func get_end_rotation():
  46. return end_rotation
  47. func set_preview(prev):
  48. preview = prev
  49. if prev:
  50. set_material_override(SpatialMaterial.new())
  51. else:
  52. set_material_override(null)
  53. func is_preview():
  54. return preview
  55. func get_next_lane(lane):
  56. return lane
  57. func penalty_index(distance:float, speed:float):
  58. for index in range(speed_constrains.size()):
  59. var constrain = speed_constrains[index]
  60. if constrain.x <= distance && constrain.y >= distance:
  61. if constrain.z < 0 && speed < constrain.z * -1 || constrain.z > 0 && speed > constrain.z:
  62. return index
  63. return -1
  64. func get_torque_penalty(index:int):
  65. if index >= 0:
  66. if torque_penalties.size() < (index + 1):
  67. return get_torque_penalty(index - 1)
  68. if get_rotation().length() != 0:
  69. return torque_penalties[index].rotated(get_rotation().normalized(), get_rotation().length())
  70. else:
  71. return torque_penalties[index]
  72. return Vector3(0,0,0)
  73. func get_force_penalty(index:int):
  74. if index >= 0:
  75. if force_penalties.size() < (index + 1):
  76. return get_force_penalty(index - 1)
  77. if get_rotation().length() != 0:
  78. return force_penalties[index].rotated(get_rotation().normalized(), get_rotation().length())
  79. else:
  80. return force_penalties[index]
  81. return Vector3(0,0,0)
  82. func get_path_penalty(index:int):
  83. if index >= 0:
  84. if path_penalties.size() < (index + 1):
  85. return get_path_penalty(index - 1)
  86. return path_penalties[index]
  87. return 0.0
  88. func get_first_speed_factor():
  89. return first_speed_factor
  90. func get_creator_speed_factor():
  91. return creator_speed_factor
  92. func get_chasers_speed_factor():
  93. return chasers_speed_factor