Autoplanner support for ArmedRecon

This commit is contained in:
Raffson 2024-09-15 21:12:34 +02:00
parent 73d2f8fda1
commit 49211dae4f
No known key found for this signature in database
GPG Key ID: B0402B2C9B764D99
3 changed files with 32 additions and 0 deletions

View File

@ -1,5 +1,6 @@
from collections.abc import Iterator
from game.commander.tasks.primitive.armedrecon import PlanArmedRecon
from game.commander.tasks.primitive.bai import PlanBai
from game.commander.theaterstate import TheaterState
from game.htn import CompoundTask, Method
@ -10,3 +11,6 @@ class AttackBattlePositions(CompoundTask[TheaterState]):
for battle_positions in state.enemy_battle_positions.values():
for battle_position in battle_positions.in_priority_order:
yield [PlanBai(battle_position)]
# Only plan against the 2 most important CPs
for cp in state.control_point_priority_queue[:2]:
yield [PlanArmedRecon(cp)]

View File

@ -0,0 +1,25 @@
from __future__ import annotations
from dataclasses import dataclass
from game.ato.flighttype import FlightType
from game.commander.tasks.packageplanningtask import PackagePlanningTask
from game.commander.theaterstate import TheaterState
from game.theater import ControlPoint
@dataclass
class PlanArmedRecon(PackagePlanningTask[ControlPoint]):
def preconditions_met(self, state: TheaterState) -> bool:
if self.target not in state.control_point_priority_queue:
return False
if not self.target_area_preconditions_met(state):
return False
return super().preconditions_met(state)
def apply_effects(self, state: TheaterState) -> None:
state.control_point_priority_queue.remove(self.target)
def propose_flights(self) -> None:
self.propose_flight(FlightType.ARMED_RECON, self.get_flight_size())
self.propose_common_escorts()

View File

@ -63,6 +63,7 @@ class TheaterState(WorldState["TheaterState"]):
enemy_barcaps: list[ControlPoint]
threat_zones: ThreatZones
vulnerable_control_points: list[ControlPoint]
control_point_priority_queue: list[ControlPoint]
def _rebuild_threat_zones(self) -> None:
"""Recreates the theater's threat zones based on the current planned state."""
@ -137,6 +138,7 @@ class TheaterState(WorldState["TheaterState"]):
threatening_air_defenses=self.threatening_air_defenses,
detecting_air_defenses=self.detecting_air_defenses,
vulnerable_control_points=self.vulnerable_control_points,
control_point_priority_queue=self.control_point_priority_queue,
)
@classmethod
@ -198,4 +200,5 @@ class TheaterState(WorldState["TheaterState"]):
enemy_barcaps=list(game.theater.control_points_for(not player)),
threat_zones=game.threat_zone_for(not player),
vulnerable_control_points=vulnerable_control_points,
control_point_priority_queue=ordered_capturable_points,
)