mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Add unit name -> Liberation object map.
Generated units are added to this during mission generation so we can map destroyed units back to the data that generated them. Currently only implemented for aircraft as a proof of concept.
This commit is contained in:
23
game/unitmap.py
Normal file
23
game/unitmap.py
Normal file
@@ -0,0 +1,23 @@
|
||||
"""Maps generated units back to their Liberation types."""
|
||||
from typing import Dict, Optional
|
||||
|
||||
from dcs.unitgroup import FlyingGroup
|
||||
|
||||
from gen.flights.flight import Flight
|
||||
|
||||
|
||||
class UnitMap:
|
||||
def __init__(self) -> None:
|
||||
self.aircraft: Dict[str, Flight] = {}
|
||||
|
||||
def add_aircraft(self, group: FlyingGroup, flight: Flight) -> None:
|
||||
for unit in group.units:
|
||||
# The actual name is a String (the pydcs translatable string), which
|
||||
# doesn't define __eq__.
|
||||
name = str(unit.name)
|
||||
if name in self.aircraft:
|
||||
raise RuntimeError(f"Duplicate unit name: {name}")
|
||||
self.aircraft[name] = flight
|
||||
|
||||
def flight(self, group_name: str) -> Optional[Flight]:
|
||||
return self.aircraft.get(group_name, None)
|
||||
Reference in New Issue
Block a user