Added loadout editor to mission preparation screen.

This commit is contained in:
Khopa
2019-10-19 16:14:40 +02:00
parent 48a40f2511
commit 9f319ab99a
15 changed files with 180 additions and 44 deletions

View File

@@ -120,6 +120,10 @@ class AircraftConflictGenerator:
else:
group.units[idx].set_client()
# Do not generate player group with late activation.
if group.late_activation:
group.late_activation = False
# Set up F-14 Client to have pre-stored alignement
if unit_type is F_14B:
group.units[idx].set_property(F_14B.Properties.INSAlignmentStored.id, True)
@@ -284,20 +288,45 @@ class AircraftConflictGenerator:
groups.append(group)
return groups
def _setup_custom_payload(self, flight, group:FlyingGroup):
if flight.use_custom_loadout:
logging.info("Custom loadout for flight : " + flight.__repr__())
for p in group.units:
p.pylons.clear()
for key in flight.loadout.keys():
if "Pylon" + key in flight.unit_type.__dict__.keys():
print(flight.loadout)
weapon_dict = flight.unit_type.__dict__["Pylon" + key].__dict__
if flight.loadout[key] in weapon_dict.keys():
weapon = weapon_dict[flight.loadout[key]]
group.load_pylon(weapon, int(key))
else:
logging.warning("Pylon not found ! => Pylon" + key + " on " + str(flight.unit_type))
def generate_flights(self, cp, country, flight_planner:FlightPlanner):
for flight in flight_planner.interceptor_flights:
group = self.generate_planned_flight(cp, country, flight)
self.setup_group_as_intercept_flight(group, flight)
self._setup_custom_payload(flight, group)
for flight in flight_planner.cap_flights:
group = self.generate_planned_flight(cp, country, flight)
self.setup_group_as_cap_flight(group, flight)
self._setup_custom_payload(flight, group)
for flight in flight_planner.cas_flights:
group = self.generate_planned_flight(cp, country, flight)
self.setup_group_as_cas_flight(group, flight)
self._setup_custom_payload(flight, group)
for flight in flight_planner.sead_flights:
group = self.generate_planned_flight(cp, country, flight)
self.setup_group_as_sead_flight(group, flight)
self._setup_custom_payload(flight, group)
def generate_planned_flight(self, cp, country, flight:Flight):
try:
@@ -321,10 +350,16 @@ class AircraftConflictGenerator:
group.points[0].ETA = flight.scheduled_in * 60
return group
def setup_group_as_intercept_flight(self, group, flight):
group.points[0].ETA = 0
group.late_activation = True
self._setup_group(group, Intercept, flight.client_count)
def setup_group_as_cap_flight(self, group, flight):
self._setup_group(group, CAP, flight.client_count)
for point in flight.points:
group.add_waypoint(Point(point[0],point[1]), point[2])
group.add_waypoint(Point(point.x,point.y), point.alt)
def setup_group_as_cas_flight(self, group, flight):
group.task = CAS.name
@@ -335,8 +370,8 @@ class AircraftConflictGenerator:
group.points[0].tasks.append(OptReactOnThreat(OptReactOnThreat.Values.EvadeFire))
group.points[0].tasks.append(OptROE(OptROE.Values.OpenFireWeaponFree))
for location in flight.points:
group.add_waypoint(Point(location[0], location[1]), location[2])
for point in flight.points:
group.add_waypoint(Point(point.x,point.y), point.alt)
def setup_group_as_sead_flight(self, group, flight):
self._setup_group(group, SEAD, flight.client_count)
@@ -347,7 +382,7 @@ class AircraftConflictGenerator:
group.points[0].tasks.append(OptROE(OptROE.Values.WeaponFree))
for point in flight.points:
group.add_waypoint(Point(point[0], point[1]), point[2])
group.add_waypoint(Point(point.x,point.y), point.alt)
def generate_cas_strikegroup(self, attackers: db.PlaneDict, clients: db.PlaneDict, at: db.StartingPosition = None, escort=True):
assert not escort or len(self.escort_targets) == 0

View File

@@ -5,8 +5,7 @@ import random
from game import db
from gen.flights.ai_flight_planner_db import INTERCEPT_CAPABLE, CAP_CAPABLE, CAS_CAPABLE, SEAD_CAPABLE
from gen.flights.flight import Flight, FlightType
from gen.flights.flight import Flight, FlightType, FlightWaypoint
# TODO : Ideally should be based on the aircraft type instead / Availability of fuel
STRIKE_MAX_RANGE = 150000
@@ -36,6 +35,7 @@ class FlightPlanner:
def __init__(self, from_cp, game):
# TODO : have the flight planner depend on a 'stance' setting : [Defensive, Aggresive... etc] and faction doctrine
# TODO : the flight planner should plan package and operations
self.from_cp = from_cp
self.game = game
self.aircraft_inventory = {} # local copy of the airbase inventory
@@ -132,7 +132,9 @@ class FlightPlanner:
patrolled = []
for ground_object in self.from_cp.ground_objects:
if ground_object.group_id not in patrolled and not ground_object.airbase_group:
flight.points.append([ground_object.position.x, ground_object.position.y, patrol_alt])
point = FlightWaypoint(ground_object.position.x, ground_object.position.y, patrol_alt)
point.description = "Patrol #" + str(len(flight.points))
flight.points.append(point)
patrolled.append(ground_object.group_id)
self.cap_flights.append(flight)
@@ -170,7 +172,9 @@ class FlightPlanner:
location = random.choice(cas_location)
flight.targets.append(cas_location)
flight.points.append([location[0], location[1], 1000]) # TODO : Egress / Ingress points
point = FlightWaypoint(location[0], location[1], 1000)
point.description = "PROVIDE CAS"
flight.points.append(point)
self.cas_flights.append(flight)
self.flights.append(flight)
@@ -203,13 +207,16 @@ class FlightPlanner:
inventory[unit] = inventory[unit] - 2
flight = Flight(unit, 2, self.from_cp, random.choice([FlightType.SEAD, FlightType.DEAD]))
# Flight path : fly over each ground object (TODO : improve)
flight.points = []
flight.scheduled_in = offset + i*random.randint(SEAD_EVERY_X_MINUTES-5, SEAD_EVERY_X_MINUTES+5)
location = self.potential_sead_targets[0][0]
self.potential_sead_targets.pop(0)
flight.points.append([location.position.x, location.position.y, 1000]) # TODO : Egress / Ingress points
point = FlightWaypoint(location.position.x, location.position.y, 1000)
point.description = "SEAD"
point.targets.append(location)
flight.points.append(point)
self.cas_flights.append(flight)
self.flights.append(flight)

View File

@@ -1,5 +1,8 @@
from dcs.unittype import UnitType
from enum import Enum
from typing import List
from dcs.unittype import UnitType
from game import db
@@ -26,36 +29,52 @@ class FlightType(Enum):
EWAR = 16
class Flight:
class FlightWaypoint():
unit_type: UnitType
def __init__(self, x: float, y: float, alt=0):
self.x = x
self.y = y
self.alt = alt
self.name = ""
self.description = ""
self.targets = []
class Flight:
unit_type: UnitType = None
from_cp = None
points = []
type = ""
count = 0
client_count = 0
points: List[FlightWaypoint] = []
flight_type: FlightType = None
count: int = 0
client_count: int = 0
targets = []
use_custom_loadout = False
loadout = {}
preset_loadout_name = ""
# How long before this flight should take off
scheduled_in = 0
def __init__(self, unit_type: UnitType, count: int, from_cp, flight_type: FlightType):
self.unit_type = unit_type
self.count = count
self.from_cp = from_cp
self.flight_type = flight_type
self.points = []
self.targets = []
self.loadout = {}
def __repr__(self):
return self.flight_type.name + " | " + str(self.count) + "x" + db.unit_type_name(self.unit_type)\
return self.flight_type.name + " | " + str(self.count) + "x" + db.unit_type_name(self.unit_type) \
+ " in " + str(self.scheduled_in) + " minutes (" + str(len(self.points)) + " wpt)"
# Test
if __name__ == '__main__':
from dcs.planes import A_10C
from theater import ControlPoint, Point
from theater import ControlPoint, Point, List
from_cp = ControlPoint(0, "AA", Point(0,0), None, [], 0, 0)
from_cp = ControlPoint(0, "AA", Point(0, 0), None, [], 0, 0)
f = Flight(A_10C, 4, from_cp, FlightType.CAS)
f.scheduled_in = 50
print(f)
print(f)