RoundRobinize random livery selection from livery_set

This commit is contained in:
Raffson 2024-08-04 12:20:50 +02:00
parent 8796d629e8
commit 9dd25e933e
No known key found for this signature in database
GPG Key ID: B0402B2C9B764D99
3 changed files with 14 additions and 1 deletions

View File

@ -164,6 +164,7 @@ class Migrator:
try_set_attr(s, "max_size", 12) try_set_attr(s, "max_size", 12)
try_set_attr(s, "radio_presets", {}) try_set_attr(s, "radio_presets", {})
try_set_attr(s, "livery_set", []) try_set_attr(s, "livery_set", [])
try_set_attr(s, "_livery_pool", [])
if isinstance(s.country, str): if isinstance(s.country, str):
c = country_dict.get(s.country, s.country) c = country_dict.get(s.country, s.country)
s.country = countries_by_name[c]() s.country = countries_by_name[c]()

View File

@ -33,7 +33,7 @@ class AircraftPainter:
and (self.flight.squadron.use_livery_set or member_uses_livery_set) and (self.flight.squadron.use_livery_set or member_uses_livery_set)
): ):
return None return None
return random.choice(self.flight.squadron.livery_set) return self.flight.squadron.random_round_robin_livery_from_set()
def determine_livery(self, member_uses_livery_set: bool) -> Optional[str]: def determine_livery(self, member_uses_livery_set: bool) -> Optional[str]:
livery = self.livery_from_squadron_set(member_uses_livery_set) livery = self.livery_from_squadron_set(member_uses_livery_set)

View File

@ -92,6 +92,9 @@ class Squadron:
return False return False
return self.id == other.id return self.id == other.id
def __post_init__(self) -> None:
self._livery_pool: list[str] = []
@property @property
def player(self) -> bool: def player(self) -> bool:
return self.coalition.player return self.coalition.player
@ -104,6 +107,15 @@ class Squadron:
def pilot_limits_enabled(self) -> bool: def pilot_limits_enabled(self) -> bool:
return self.settings.enable_squadron_pilot_limits return self.settings.enable_squadron_pilot_limits
def random_round_robin_livery_from_set(self) -> str:
livery = random.choice(self.livery_set)
self._livery_pool.append(livery)
self.livery_set.remove(livery)
if not self.livery_set:
self.livery_set = self._livery_pool
self._livery_pool = []
return livery
def set_auto_assignable_mission_types( def set_auto_assignable_mission_types(
self, mission_types: Iterable[FlightType] self, mission_types: Iterable[FlightType]
) -> None: ) -> None: