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.

143 lines
3.0 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 get_constrain_index(distance:float):
  58. for index in range(speed_constrains.size()):
  59. var constrain = speed_constrains[index]
  60. if constrain.x <= distance && constrain.y >= distance:
  61. return index
  62. return -1
  63. func penalty_index(distance:float, speed:float):
  64. var constrain_index = get_constrain_index(distance)
  65. if constrain_index >= 0:
  66. var constrain = speed_constrains[constrain_index]
  67. if constrain.z < 0 && speed < constrain.z * -1 || constrain.z > 0 && speed > constrain.z:
  68. return constrain_index
  69. return -1
  70. func get_torque_penalty(index:int):
  71. if index >= 0:
  72. if torque_penalties.size() < (index + 1):
  73. return get_torque_penalty(index - 1)
  74. return torque_penalties[index]
  75. return Vector3(0,0,0)
  76. func get_force_penalty(index:int):
  77. if index >= 0:
  78. if force_penalties.size() < (index + 1):
  79. return get_force_penalty(index - 1)
  80. if get_rotation().length() != 0:
  81. return force_penalties[index].rotated(get_rotation().normalized(), get_rotation().length())
  82. else:
  83. return force_penalties[index]
  84. return Vector3(0,0,0)
  85. func get_path_penalty(index:int):
  86. if index >= 0:
  87. if path_penalties.size() < (index + 1):
  88. return get_path_penalty(index - 1)
  89. return path_penalties[index]
  90. return 0.0
  91. func get_first_speed_factor():
  92. return first_speed_factor
  93. func get_creator_speed_factor():
  94. return creator_speed_factor
  95. func get_chasers_speed_factor():
  96. return chasers_speed_factor