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
This commit is contained in:
RndName 2021-06-24 21:50:02 +02:00 committed by Dan Albert
parent 3f42f1281d
commit 96be6c0efe
5 changed files with 29 additions and 18 deletions

View File

@ -19,10 +19,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.

View File

@ -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)

View File

@ -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

View File

@ -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):

View File

@ -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)