Move calculation of aircraft amounts into game.

The planner needs to know how much space is still expected to be
available next turn.
This commit is contained in:
Dan Albert
2020-11-20 18:25:03 -08:00
parent f8b2dbe283
commit c4b8a41742
7 changed files with 44 additions and 48 deletions

View File

@@ -57,7 +57,7 @@ class QBaseMenu2(QDialog):
title = QLabel("<b>" + self.cp.name + "</b>")
title.setAlignment(Qt.AlignLeft | Qt.AlignTop)
title.setProperty("style", "base-title")
unitsPower = QLabel("{} / {} / Runway : {}".format(self.cp.base.total_planes, self.cp.base.total_armor,
unitsPower = QLabel("{} / {} / Runway : {}".format(self.cp.base.total_aircraft, self.cp.base.total_armor,
"Available" if self.cp.has_runway() else "Unavailable"))
self.topLayout.addWidget(title)
self.topLayout.addWidget(unitsPower)

View File

@@ -126,13 +126,6 @@ class QRecruitBehaviour:
QRecruitBehaviour.BUDGET_FORMAT.format(self.budget))
def buy(self, unit_type):
if self.maximum_units > 0:
if self.total_units + 1 > self.maximum_units:
logging.info("Not enough space left !")
# TODO : display modal warning
return
price = db.PRICES[unit_type]
if self.budget >= price:
self.pending_deliveries.deliver({unit_type: 1})
@@ -158,19 +151,6 @@ class QRecruitBehaviour:
self._update_count_label(unit_type)
self.update_available_budget()
@property
def total_units(self):
total = 0
for unit_type in self.recruitables_types:
total += self.cp.base.total_units(unit_type)
if self.pending_deliveries:
for unit_bought in self.pending_deliveries.units:
if db.unit_task(unit_bought) in self.recruitables_types:
total += self.pending_deliveries.units[unit_bought]
return total
def set_maximum_units(self, maximum_units):
"""
Set the maximum number of units that can be bought

View File

@@ -1,3 +1,4 @@
import logging
from typing import Optional, Set
from PySide2.QtCore import Qt
@@ -37,7 +38,7 @@ class QAircraftRecruitmentMenu(QFrame, QRecruitBehaviour):
self.bought_amount_labels = {}
self.existing_units_labels = {}
self.hangar_status = QHangarStatus(self.total_units, self.cp.available_aircraft_slots)
self.hangar_status = QHangarStatus(self.total_aircraft, self.cp.available_aircraft_slots)
self.init_ui()
@@ -80,8 +81,18 @@ class QAircraftRecruitmentMenu(QFrame, QRecruitBehaviour):
self.setLayout(main_layout)
def buy(self, unit_type):
if self.maximum_units > 0:
if self.total_aircraft + 1 > self.maximum_units:
logging.debug(f"No space for additional aircraft at {self.cp}.")
return
super().buy(unit_type)
self.hangar_status.update_label(self.total_units, self.cp.available_aircraft_slots)
self.hangar_status.update_label(self.total_aircraft,
self.cp.available_aircraft_slots)
@property
def total_aircraft(self) -> int:
return self.cp.expected_aircraft_next_turn
def sell(self, unit_type: UnitType):
# Don't need to remove aircraft from the inventory if we're canceling
@@ -99,7 +110,7 @@ class QAircraftRecruitmentMenu(QFrame, QRecruitBehaviour):
"assigned to a mission?", QMessageBox.Ok)
return
super().sell(unit_type)
self.hangar_status.update_label(self.total_units, self.cp.available_aircraft_slots)
self.hangar_status.update_label(self.total_aircraft, self.cp.available_aircraft_slots)
class QHangarStatus(QHBoxLayout):