2026-10-25 16:22:34 -05:00
|
|
|
class_name CPUController extends BaseController
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _process(_delta: float) -> void:
|
|
|
|
|
if not jets_collection: return
|
|
|
|
|
|
|
|
|
|
for jet: Jet in jets_collection.get_children():
|
2026-10-25 19:45:31 -05:00
|
|
|
if Globals.ControlMode.PLAYER_MODE == jet.controller.control_mode:
|
|
|
|
|
continue
|
|
|
|
|
|
2026-10-25 23:12:51 -05:00
|
|
|
process_jet_plan(jet)
|
2026-10-25 19:45:31 -05:00
|
|
|
|
|
|
|
|
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:
|
2026-10-25 23:12:51 -05:00
|
|
|
assign_jet_target(jet)
|
2026-10-25 16:22:34 -05:00
|
|
|
|
2026-10-25 23:12:51 -05:00
|
|
|
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 process_jet_plan(jet: Jet) -> void:
|
|
|
|
|
if not is_instance_valid(jet.target): return
|
|
|
|
|
|
2026-10-30 23:08:47 -05:00
|
|
|
var target_local_position: Vector3 = jet.to_local(jet.target.global_position)
|
|
|
|
|
var target_direction: Vector3 = target_local_position.normalized()
|
|
|
|
|
jet.target_ray.target_position = target_direction * 8
|
2026-10-25 23:12:51 -05:00
|
|
|
|
|
|
|
|
|
2026-10-30 23:08:47 -05:00
|
|
|
jet.controller.cpu.yaw_left()
|
2026-10-25 23:12:51 -05:00
|
|
|
|
2026-10-30 23:08:47 -05:00
|
|
|
#var direction: Vector3 = (
|
|
|
|
|
#jet.target.global_position - jet.global_position
|
|
|
|
|
#).normalized()
|
|
|
|
|
#
|