2020-03-19 15:57:31 +00:00
|
|
|
class_name Plan
|
|
|
|
|
|
|
|
const TURN_TIME : float = 5.0
|
|
|
|
|
|
|
|
var elements = [] # All elements of the plan thus far
|
|
|
|
var current_elements = [] # All elements of the next 5 seconds
|
|
|
|
|
2020-04-18 17:26:09 +00:00
|
|
|
func current_time() -> float:
|
2020-04-02 18:24:42 +00:00
|
|
|
var total_time : float = 0.0
|
|
|
|
for current_element in current_elements:
|
|
|
|
var _element : PlanElement = (current_element as PlanElement)
|
|
|
|
total_time += _element.time
|
2020-04-18 17:26:09 +00:00
|
|
|
return total_time
|
|
|
|
|
|
|
|
func add_element(element : PlanElement) -> bool:
|
|
|
|
var total_time : float = self.current_time()
|
2020-04-02 18:24:42 +00:00
|
|
|
if total_time + element.time > TURN_TIME:
|
|
|
|
return false
|
|
|
|
current_elements.append(element)
|
|
|
|
return true
|
|
|
|
|
|
|
|
func remove_last_element() -> void:
|
|
|
|
current_elements.pop_back()
|
|
|
|
|
|
|
|
func remove_all_elements() -> void:
|
|
|
|
current_elements.clear()
|
|
|
|
|
|
|
|
func new_turn() -> void:
|
2021-05-14 10:26:04 +00:00
|
|
|
for i in range(len(current_elements)):
|
2020-08-16 12:10:31 +00:00
|
|
|
elements.push_back(current_elements.pop_front())
|
2020-04-02 18:24:42 +00:00
|
|
|
|
2020-03-19 15:57:31 +00:00
|
|
|
func sanity_check() -> bool:
|
|
|
|
# Returns true if sane and false if insane
|
|
|
|
var total_time : float = 0.0
|
|
|
|
for current_element in current_elements:
|
|
|
|
var element : PlanElement = (current_element as PlanElement)
|
2020-04-02 18:24:42 +00:00
|
|
|
total_time += element.time
|
2020-03-19 15:57:31 +00:00
|
|
|
if !element.sanity_check():
|
|
|
|
return false
|
|
|
|
if total_time > TURN_TIME:
|
|
|
|
return false
|
|
|
|
return true
|