mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Generate random squadron nicknames.
A little weird that the animal names aren't plural, but good enough. https://github.com/dcs-liberation/dcs_liberation/issues/276
This commit is contained in:
parent
49102e510d
commit
2f8656d54f
@ -1,9 +1,10 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import itertools
|
import itertools
|
||||||
|
import random
|
||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Type, Tuple, List, TYPE_CHECKING, Optional, Iterable
|
from typing import Type, Tuple, List, TYPE_CHECKING, Optional, Iterable, Iterator
|
||||||
|
|
||||||
import yaml
|
import yaml
|
||||||
from dcs.unittype import FlyingType
|
from dcs.unittype import FlyingType
|
||||||
@ -118,11 +119,14 @@ class AirWing:
|
|||||||
|
|
||||||
self.game = game
|
self.game = game
|
||||||
self.player = player
|
self.player = player
|
||||||
self.squadrons = {
|
self.squadrons: dict[Type[FlyingType], list[Squadron]] = {
|
||||||
aircraft: [
|
aircraft: [] for aircraft in game.faction_for(player).aircrafts
|
||||||
|
}
|
||||||
|
for num, (aircraft, squadrons) in enumerate(self.squadrons.items()):
|
||||||
|
squadrons.append(
|
||||||
Squadron(
|
Squadron(
|
||||||
name=f"Squadron {num + 1:03}",
|
name=f"Squadron {num + 1:03}",
|
||||||
nickname="The Unremarkable",
|
nickname=self.random_nickname(),
|
||||||
role="Flying Squadron",
|
role="Flying Squadron",
|
||||||
aircraft=aircraft,
|
aircraft=aircraft,
|
||||||
mission_types=tuple(FlightType),
|
mission_types=tuple(FlightType),
|
||||||
@ -130,16 +134,47 @@ class AirWing:
|
|||||||
game=game,
|
game=game,
|
||||||
player=player,
|
player=player,
|
||||||
)
|
)
|
||||||
]
|
)
|
||||||
for num, aircraft in enumerate(game.faction_for(player).aircrafts)
|
|
||||||
}
|
|
||||||
|
|
||||||
def squadron_for(self, aircraft: Type[FlyingType]) -> Squadron:
|
def squadron_for(self, aircraft: Type[FlyingType]) -> Squadron:
|
||||||
return self.squadrons[aircraft][0]
|
return self.squadrons[aircraft][0]
|
||||||
|
|
||||||
|
def iter_squadrons(self) -> Iterator[Squadron]:
|
||||||
|
return itertools.chain.from_iterable(self.squadrons.values())
|
||||||
|
|
||||||
def squadron_at_index(self, index: int) -> Squadron:
|
def squadron_at_index(self, index: int) -> Squadron:
|
||||||
return list(itertools.chain.from_iterable(self.squadrons.values()))[index]
|
return list(self.iter_squadrons())[index]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def size(self) -> int:
|
def size(self) -> int:
|
||||||
return sum(len(s) for s in self.squadrons.values())
|
return sum(len(s) for s in self.squadrons.values())
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _make_random_nickname() -> str:
|
||||||
|
from gen.naming import ANIMALS
|
||||||
|
|
||||||
|
animal = random.choice(ANIMALS)
|
||||||
|
adjective = random.choice(
|
||||||
|
(
|
||||||
|
None,
|
||||||
|
"Red",
|
||||||
|
"Blue",
|
||||||
|
"Green",
|
||||||
|
"Golden",
|
||||||
|
"Black",
|
||||||
|
"Fighting",
|
||||||
|
"Flying",
|
||||||
|
)
|
||||||
|
)
|
||||||
|
if adjective is None:
|
||||||
|
return animal.title()
|
||||||
|
return f"{adjective} {animal}".title()
|
||||||
|
|
||||||
|
def random_nickname(self) -> str:
|
||||||
|
while True:
|
||||||
|
nickname = self._make_random_nickname()
|
||||||
|
for squadron in self.iter_squadrons():
|
||||||
|
if squadron.nickname == nickname:
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
return nickname
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user