From c8d22925ee0ca23fd41aa41395422aa9fcad7b35 Mon Sep 17 00:00:00 2001 From: RndName Date: Thu, 24 Jun 2021 21:50:02 +0200 Subject: [PATCH] correct prices for ewr and sams prices will now be calculated for the whole group by the generator by looking up the price using the GroundUnitType wrapper fixes #1163 (cherry picked from commit 96be6c0efe4b6b0f3af38bf5c43a9818e1eed4e6) --- changelog.md | 2 ++ gen/sam/airdefensegroupgenerator.py | 2 -- gen/sam/ewrs.py | 5 ---- gen/sam/group_generator.py | 14 +++++++++++ .../windows/groundobject/QGroundObjectMenu.py | 24 ++++++++++--------- 5 files changed, 29 insertions(+), 18 deletions(-) diff --git a/changelog.md b/changelog.md index bff6a277..40829da5 100644 --- a/changelog.md +++ b/changelog.md @@ -11,10 +11,12 @@ Saves from 4.0.0 are compatible with 4.1.0. * **[UI]** Hovering over the weather information now dispalys the cloud base (meters and feet). * **[UI]** Google search link added to unit information when there is no information provided. * **[UI]** Control point name displayed with ground object group name on map. +* **[UI]** Buy or Replace will now show the correct price for generated ground objects like sams. ## Fixes * **[Campaign]** Fixed the Silkworm generator to include launchers and not all radars. +* **[Economy]** EWRs can now be bought and sold for the correct price and can no longer be used to generate money * **[Flight Planning]** Fixed potential issue with angles > 360° or < 0° being generated when summing two angles. * **[Mission Generation]** The lua data for other plugins is now generated correctly * **[UI]** Statistics window tick marks are now always integers. diff --git a/gen/sam/airdefensegroupgenerator.py b/gen/sam/airdefensegroupgenerator.py index 7d269ece..bc192691 100644 --- a/gen/sam/airdefensegroupgenerator.py +++ b/gen/sam/airdefensegroupgenerator.py @@ -43,8 +43,6 @@ class AirDefenseGroupGenerator(GroupGenerator, ABC): This is the base for all SAM group generators """ - price: int - def __init__(self, game: Game, ground_object: SamGroundObject) -> None: super().__init__(game, ground_object) diff --git a/gen/sam/ewrs.py b/gen/sam/ewrs.py index df27e6ad..3678fe79 100644 --- a/gen/sam/ewrs.py +++ b/gen/sam/ewrs.py @@ -13,11 +13,6 @@ class EwrGenerator(GroupGenerator): def name(cls) -> str: return cls.unit_type.name - @staticmethod - def price() -> int: - # TODO: Differentiate sites. - return 20 - def generate(self) -> None: self.add_unit( self.unit_type, "EWR", self.position.x, self.position.y, self.heading diff --git a/gen/sam/group_generator.py b/gen/sam/group_generator.py index 65eb0b50..f41b9543 100644 --- a/gen/sam/group_generator.py +++ b/gen/sam/group_generator.py @@ -1,5 +1,6 @@ from __future__ import annotations +import logging import math import random from typing import TYPE_CHECKING, Type @@ -10,6 +11,7 @@ from dcs.point import PointAction from dcs.unit import Ship, Vehicle from dcs.unittype import VehicleType +from game.dcs.groundunittype import GroundUnitType from game.factions.faction import Faction from game.theater.theatergroundobject import TheaterGroundObject @@ -23,11 +25,15 @@ if TYPE_CHECKING: # care about in the format we want if we just generate our own group description # types rather than pydcs groups. class GroupGenerator: + + price: int + def __init__(self, game: Game, ground_object: TheaterGroundObject) -> None: self.game = game self.go = ground_object self.position = ground_object.position self.heading = random.randint(0, 359) + self.price = 0 self.vg = unitgroup.VehicleGroup(self.game.next_group_id(), self.go.group_name) wp = self.vg.add_waypoint(self.position, PointAction.OffRoad, 0) wp.ETA_locked = True @@ -62,6 +68,14 @@ class GroupGenerator: unit.position = position unit.heading = heading group.add_unit(unit) + + # get price of unit to calculate the real price of the whole group + try: + ground_unit_type = next(GroundUnitType.for_dcs_type(unit_type)) + self.price += ground_unit_type.price + except StopIteration: + logging.error(f"Cannot get price for unit {unit_type.name}") + return unit def get_circular_position(self, num_units, launcher_distance, coverage=90): diff --git a/qt_ui/windows/groundobject/QGroundObjectMenu.py b/qt_ui/windows/groundobject/QGroundObjectMenu.py index 96debe14..7f955f3d 100644 --- a/qt_ui/windows/groundobject/QGroundObjectMenu.py +++ b/qt_ui/windows/groundobject/QGroundObjectMenu.py @@ -305,8 +305,11 @@ class QBuyGroupForGroundObjectDialog(QDialog): possible_sams = get_faction_possible_sams_generator(faction) for sam in possible_sams: + # Pre Generate SAM to get the real price + generator = sam(self.game, self.ground_object) + generator.generate() self.samCombo.addItem( - sam.name + " [$" + str(sam.price) + "M]", userData=sam + generator.name + " [$" + str(generator.price) + "M]", userData=generator ) self.samCombo.currentIndexChanged.connect(self.samComboChanged) @@ -331,8 +334,12 @@ class QBuyGroupForGroundObjectDialog(QDialog): buy_ewr_layout.addWidget(self.ewr_selector, 0, 1, alignment=Qt.AlignRight) ewr_types = get_faction_possible_ewrs_generator(faction) for ewr_type in ewr_types: + # Pre Generate to get the real price + generator = ewr_type(self.game, self.ground_object) + generator.generate() self.ewr_selector.addItem( - f"{ewr_type.name()} [${ewr_type.price()}M]", ewr_type + generator.name() + " [$" + str(generator.price) + "M]", + userData=generator, ) self.ewr_selector.currentIndexChanged.connect(self.on_ewr_selection_changed) @@ -402,7 +409,7 @@ class QBuyGroupForGroundObjectDialog(QDialog): def on_ewr_selection_changed(self, index): ewr = self.ewr_selector.itemData(index) self.buy_ewr_button.setText( - f"Buy [${ewr.price()}M][-${self.current_group_value}M]" + f"Buy [${ewr.price}M][-${self.current_group_value}M]" ) def armorComboChanged(self, index): @@ -443,25 +450,20 @@ class QBuyGroupForGroundObjectDialog(QDialog): else: self.game.budget -= price - # Generate SAM - generator = sam_generator(self.game, self.ground_object) - generator.generate() - self.ground_object.groups = list(generator.groups) + self.ground_object.groups = list(sam_generator.groups) GameUpdateSignal.get_instance().updateGame(self.game) def buy_ewr(self): ewr_generator = self.ewr_selector.itemData(self.ewr_selector.currentIndex()) - price = ewr_generator.price() - self.current_group_value + price = ewr_generator.price - self.current_group_value if price > self.game.budget: self.error_money() return else: self.game.budget -= price - generator = ewr_generator(self.game, self.ground_object) - generator.generate() - self.ground_object.groups = [generator.vg] + self.ground_object.groups = [ewr_generator.vg] GameUpdateSignal.get_instance().updateGame(self.game)