mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Consider trasnfers when counting parking.
This commit is contained in:
parent
493e53c28f
commit
d7b328b887
@ -6,7 +6,7 @@ import random
|
|||||||
import re
|
import re
|
||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from typing import Dict, Iterator, List, Optional, TYPE_CHECKING
|
from typing import Dict, Iterator, List, Optional, TYPE_CHECKING, Tuple
|
||||||
|
|
||||||
from dcs.mapping import Point
|
from dcs.mapping import Point
|
||||||
from dcs.ships import (
|
from dcs.ships import (
|
||||||
@ -125,6 +125,17 @@ class PresetLocations:
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True)
|
||||||
|
class PendingOccupancy:
|
||||||
|
present: int
|
||||||
|
ordered: int
|
||||||
|
transferring: int
|
||||||
|
|
||||||
|
@property
|
||||||
|
def total(self) -> int:
|
||||||
|
return self.present + self.ordered + self.transferring
|
||||||
|
|
||||||
|
|
||||||
class ControlPoint(MissionTarget):
|
class ControlPoint(MissionTarget):
|
||||||
|
|
||||||
position = None # type: Point
|
position = None # type: Point
|
||||||
@ -379,18 +390,36 @@ class ControlPoint(MissionTarget):
|
|||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@property
|
def aircraft_transferring(self, game: Game) -> int:
|
||||||
def expected_aircraft_next_turn(self) -> int:
|
if self.captured:
|
||||||
total = self.base.total_aircraft
|
ato = game.blue_ato
|
||||||
assert self.pending_unit_deliveries
|
else:
|
||||||
for unit_bought in self.pending_unit_deliveries.units:
|
ato = game.red_ato
|
||||||
if issubclass(unit_bought, FlyingType):
|
|
||||||
total += self.pending_unit_deliveries.units[unit_bought]
|
total = 0
|
||||||
|
for package in ato.packages:
|
||||||
|
for flight in package.flights:
|
||||||
|
if flight.departure == flight.arrival:
|
||||||
|
continue
|
||||||
|
if flight.departure == self:
|
||||||
|
total -= flight.count
|
||||||
|
elif flight.arrival == self:
|
||||||
|
total += flight.count
|
||||||
return total
|
return total
|
||||||
|
|
||||||
@property
|
def expected_aircraft_next_turn(self, game: Game) -> PendingOccupancy:
|
||||||
def unclaimed_parking(self) -> int:
|
assert self.pending_unit_deliveries
|
||||||
return self.total_aircraft_parking - self.expected_aircraft_next_turn
|
on_order = 0
|
||||||
|
for unit_bought in self.pending_unit_deliveries.units:
|
||||||
|
if issubclass(unit_bought, FlyingType):
|
||||||
|
on_order += self.pending_unit_deliveries.units[unit_bought]
|
||||||
|
|
||||||
|
return PendingOccupancy(self.base.total_aircraft, on_order,
|
||||||
|
self.aircraft_transferring(game))
|
||||||
|
|
||||||
|
def unclaimed_parking(self, game: Game) -> int:
|
||||||
|
return (self.total_aircraft_parking -
|
||||||
|
self.expected_aircraft_next_turn(game).total)
|
||||||
|
|
||||||
|
|
||||||
class OffMapSpawn(ControlPoint):
|
class OffMapSpawn(ControlPoint):
|
||||||
|
|||||||
@ -38,7 +38,7 @@ class QAircraftRecruitmentMenu(QFrame, QRecruitBehaviour):
|
|||||||
self.bought_amount_labels = {}
|
self.bought_amount_labels = {}
|
||||||
self.existing_units_labels = {}
|
self.existing_units_labels = {}
|
||||||
|
|
||||||
self.hangar_status = QHangarStatus(self.cp)
|
self.hangar_status = QHangarStatus(game_model, self.cp)
|
||||||
|
|
||||||
self.init_ui()
|
self.init_ui()
|
||||||
|
|
||||||
@ -82,7 +82,7 @@ class QAircraftRecruitmentMenu(QFrame, QRecruitBehaviour):
|
|||||||
|
|
||||||
def buy(self, unit_type):
|
def buy(self, unit_type):
|
||||||
if self.maximum_units > 0:
|
if self.maximum_units > 0:
|
||||||
if self.cp.unclaimed_parking <= 0:
|
if self.cp.unclaimed_parking(self.game_model.game) <= 0:
|
||||||
logging.debug(f"No space for additional aircraft at {self.cp}.")
|
logging.debug(f"No space for additional aircraft at {self.cp}.")
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -110,8 +110,10 @@ class QAircraftRecruitmentMenu(QFrame, QRecruitBehaviour):
|
|||||||
|
|
||||||
class QHangarStatus(QHBoxLayout):
|
class QHangarStatus(QHBoxLayout):
|
||||||
|
|
||||||
def __init__(self, control_point: ControlPoint) -> None:
|
def __init__(self, game_model: GameModel,
|
||||||
|
control_point: ControlPoint) -> None:
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
self.game_model = game_model
|
||||||
self.control_point = control_point
|
self.control_point = control_point
|
||||||
|
|
||||||
self.icon = QLabel()
|
self.icon = QLabel()
|
||||||
@ -125,6 +127,22 @@ class QHangarStatus(QHBoxLayout):
|
|||||||
self.setAlignment(Qt.AlignLeft)
|
self.setAlignment(Qt.AlignLeft)
|
||||||
|
|
||||||
def update_label(self) -> None:
|
def update_label(self) -> None:
|
||||||
current_amount = self.control_point.expected_aircraft_next_turn
|
next_turn = self.control_point.expected_aircraft_next_turn(
|
||||||
|
self.game_model.game)
|
||||||
max_amount = self.control_point.total_aircraft_parking
|
max_amount = self.control_point.total_aircraft_parking
|
||||||
self.text.setText(f"<strong>{current_amount}/{max_amount}</strong>")
|
|
||||||
|
components = [f"{next_turn.present} present"]
|
||||||
|
if next_turn.ordered > 0:
|
||||||
|
components.append(f"{next_turn.ordered} purchased")
|
||||||
|
elif next_turn.ordered < 0:
|
||||||
|
components.append(f"{-next_turn.ordered} sold")
|
||||||
|
|
||||||
|
transferring = next_turn.transferring
|
||||||
|
if transferring > 0:
|
||||||
|
components.append(f"{transferring} transferring in")
|
||||||
|
if transferring < 0:
|
||||||
|
components.append(f"{-transferring} transferring out")
|
||||||
|
|
||||||
|
details = ", ".join(components)
|
||||||
|
self.text.setText(
|
||||||
|
f"<strong>{next_turn.total}/{max_amount}</strong> ({details})")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user