Files
GrowlerFury/scripts/controllers/cpu_system/cpu_controller.gd
T

41 lines
1.0 KiB
GDScript
Raw Normal View History

class_name CPUController extends BaseController
func _process(_delta: float) -> void:
if not jets_collection: return
for jet: Jet in jets_collection.get_children():
if Globals.ControlMode.PLAYER_MODE == jet.controller.control_mode:
continue
process_jet_plan(jet)
func _controller_message(event: BaseEvent) -> void:
if event is InitSpawnsLoadedEvent:
handle_init_spawns_loaded_event()
func handle_init_spawns_loaded_event() -> void:
for jet: Jet in jets_collection.get_children():
create_jet_plan(jet)
func create_jet_plan(jet: Jet) -> void:
assign_jet_target(jet)
assign_jet_action(jet)
func assign_jet_target(jet: Jet) -> void:
for _jet: Jet in jets_collection.get_children():
if _jet.faction == jet.faction: continue
if _jet.targeted_by: continue
_jet.targeted_by = jet
jet.target = _jet
break
func assign_jet_action(jet: Jet) -> void:
jet.strategy_stack.add_child( MoveTowards.new() )
jet.strategy_stack.add_child( RollLeftSideUp.new() )
func process_jet_plan(jet: Jet) -> void:
jet.strategy_stack.process_action(jet)