mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
number of fixes
This commit is contained in:
@@ -7,6 +7,8 @@ from dcs.lua import parse
|
||||
from dcs.mission import Mission
|
||||
|
||||
from dcs.unitgroup import FlyingGroup
|
||||
from dcs.unit import Vehicle, VehicleType
|
||||
from dcs.vehicles import vehicle_map
|
||||
from dcs.unit import UnitType
|
||||
|
||||
from game import db
|
||||
@@ -20,20 +22,21 @@ class Debriefing:
|
||||
self.alive_units = alive_units # type: typing.Dict[str, typing.Dict[str, int]]
|
||||
|
||||
@classmethod
|
||||
def parse(cls, path: str, mission: Mission):
|
||||
def parse(cls, path: str):
|
||||
with open(path, "r") as f:
|
||||
table_string = f.read()
|
||||
table = parse.loads(table_string)
|
||||
units = table.get("debriefing", {}).get("world_state", {})
|
||||
alive_units = {}
|
||||
|
||||
for unit in units:
|
||||
type = unit["type"] # type: str
|
||||
for unit in units.values():
|
||||
unit_type = unit["type"] # type: str
|
||||
country_id = int(unit["country"])
|
||||
if type:
|
||||
country_dict = alive_units.get(unit[country_id], {})
|
||||
country_dict[type] = country_dict.get(type, 0) + 1
|
||||
alive_units[unit[country_id]] = country_dict
|
||||
|
||||
if type(unit_type) == str:
|
||||
country_dict = alive_units.get(country_id, {})
|
||||
country_dict[unit_type] = country_dict.get(unit_type, 0) + 1
|
||||
alive_units[country_id] = country_dict
|
||||
|
||||
return Debriefing(alive_units)
|
||||
|
||||
@@ -42,14 +45,20 @@ class Debriefing:
|
||||
result = {}
|
||||
for group in groups:
|
||||
for unit in group.units:
|
||||
result[unit.unit_type] = result.get(unit.unit_type, 0) + 1
|
||||
unit_type = None
|
||||
if isinstance(unit, Vehicle):
|
||||
unit_type = vehicle_map[unit.type]
|
||||
else:
|
||||
unit_type = unit.unit_type
|
||||
|
||||
result[unit_type] = result.get(unit_type, 0) + 1
|
||||
|
||||
return result
|
||||
|
||||
def calculate_losses(all_units: typing.Dict[UnitType, int], alive_units: typing.Dict[str, int]) -> typing.Dict[UnitType, int]:
|
||||
result = {}
|
||||
for t, count in all_units.items():
|
||||
result[t] = count - alive_units[db.unit_type_name(t)]
|
||||
result[t] = max(count - alive_units.get(db.unit_type_name(t), 0), 0)
|
||||
return result
|
||||
|
||||
player = mission.country(player_name)
|
||||
@@ -59,8 +68,8 @@ class Debriefing:
|
||||
enemy_units = count_groups(enemy.plane_group + enemy.vehicle_group)
|
||||
|
||||
self.destroyed_units = {
|
||||
player.name: calculate_losses(player_units, self.alive_units[player.id]),
|
||||
enemy.name: calculate_losses(enemy_units, self.alive_units[enemy.id]),
|
||||
player.name: calculate_losses(player_units, self.alive_units.get(player.id, {})),
|
||||
enemy.name: calculate_losses(enemy_units, self.alive_units.get(enemy.id, {})),
|
||||
}
|
||||
|
||||
def debriefing_directory_location() -> str:
|
||||
|
||||
Reference in New Issue
Block a user