mirror of
https://github.com/dcs-liberation/dcs_liberation.git
synced 2025-11-10 14:22:26 +00:00
Add livery selection for predefined squadrons.
https://github.com/dcs-liberation/dcs_liberation/issues/276
This commit is contained in:
parent
ac4a7441e9
commit
f36757b650
@ -43,6 +43,7 @@ class Squadron:
|
||||
country: str
|
||||
role: str
|
||||
aircraft: Type[FlyingType]
|
||||
livery: Optional[str]
|
||||
mission_types: Tuple[FlightType, ...]
|
||||
pilots: List[Pilot]
|
||||
available_pilots: List[Pilot] = field(init=False, hash=False, compare=False)
|
||||
@ -117,6 +118,7 @@ class Squadron:
|
||||
country=data["country"],
|
||||
role=data["role"],
|
||||
aircraft=unit_type,
|
||||
livery=data.get("livery"),
|
||||
mission_types=tuple(FlightType.from_name(n) for n in data["mission_types"]),
|
||||
pilots=[Pilot(n) for n in data.get("pilots", [])],
|
||||
game=game,
|
||||
@ -200,6 +202,7 @@ class AirWing:
|
||||
country=game.country_for(player),
|
||||
role="Flying Squadron",
|
||||
aircraft=aircraft,
|
||||
livery=None,
|
||||
mission_types=tuple(FlightType),
|
||||
pilots=[],
|
||||
game=game,
|
||||
|
||||
@ -761,6 +761,36 @@ class AircraftConflictGenerator:
|
||||
else:
|
||||
unit.set_player()
|
||||
|
||||
@staticmethod
|
||||
def livery_from_db(flight: Flight) -> Optional[str]:
|
||||
return db.PLANE_LIVERY_OVERRIDES.get(flight.unit_type)
|
||||
|
||||
def livery_from_faction(self, flight: Flight) -> Optional[str]:
|
||||
faction = self.game.faction_for(player=flight.departure.captured)
|
||||
if (choices := faction.liveries_overrides.get(flight.unit_type)) is not None:
|
||||
return random.choice(choices)
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
def livery_from_squadron(flight: Flight) -> Optional[str]:
|
||||
return flight.squadron.livery
|
||||
|
||||
def livery_for(self, flight: Flight) -> Optional[str]:
|
||||
if (livery := self.livery_from_squadron(flight)) is not None:
|
||||
return livery
|
||||
if (livery := self.livery_from_faction(flight)) is not None:
|
||||
return livery
|
||||
if (livery := self.livery_from_db(flight)) is not None:
|
||||
return livery
|
||||
return None
|
||||
|
||||
def _setup_livery(self, flight: Flight, group: FlyingGroup) -> None:
|
||||
livery = self.livery_for(flight)
|
||||
if livery is None:
|
||||
return
|
||||
for unit in group.units:
|
||||
unit.livery_id = livery
|
||||
|
||||
def _setup_group(
|
||||
self,
|
||||
group: FlyingGroup,
|
||||
@ -771,21 +801,7 @@ class AircraftConflictGenerator:
|
||||
unit_type = group.units[0].unit_type
|
||||
|
||||
self._setup_payload(flight, group)
|
||||
|
||||
if unit_type in db.PLANE_LIVERY_OVERRIDES:
|
||||
for unit_instance in group.units:
|
||||
unit_instance.livery_id = db.PLANE_LIVERY_OVERRIDES[unit_type]
|
||||
|
||||
# Override livery by faction file data
|
||||
if flight.from_cp.captured:
|
||||
faction = self.game.player_faction
|
||||
else:
|
||||
faction = self.game.enemy_faction
|
||||
|
||||
if unit_type in faction.liveries_overrides:
|
||||
livery = random.choice(faction.liveries_overrides[unit_type])
|
||||
for unit_instance in group.units:
|
||||
unit_instance.livery_id = livery
|
||||
self._setup_livery(flight, group)
|
||||
|
||||
for unit, pilot in zip(group.units, flight.pilots):
|
||||
player = pilot is not None and pilot.player
|
||||
@ -815,7 +831,7 @@ class AircraftConflictGenerator:
|
||||
self.flights.append(
|
||||
FlightData(
|
||||
package=package,
|
||||
country=faction.country,
|
||||
country=self.game.faction_for(player=flight.departure.captured).country,
|
||||
flight_type=flight.flight_type,
|
||||
units=group.units,
|
||||
size=len(group.units),
|
||||
|
||||
@ -4,6 +4,7 @@ nickname: Stingers
|
||||
country: USA
|
||||
role: Strike Fighter
|
||||
aircraft: FA-18C_hornet
|
||||
livery: VFA-113
|
||||
mission_types:
|
||||
- Anti-ship
|
||||
- BAI
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user