Added disband menu in ground object menu.

This commit is contained in:
Khopa 2020-09-19 14:02:53 +02:00
parent 59e7665b65
commit e210dcb4df
29 changed files with 101 additions and 2 deletions

View File

@ -10,6 +10,8 @@ class BoforsGenerator(GroupGenerator):
This generate a Bofors flak artillery group
"""
name = "Bofors AAA"
def generate(self):
grid_x = random.randint(2, 4)
grid_y = random.randint(2, 4)

View File

@ -11,6 +11,8 @@ class FlakGenerator(GroupGenerator):
This generate a German flak artillery group
"""
name = "Flak Site"
def generate(self):
grid_x = random.randint(2, 4)
grid_y = random.randint(2, 4)

View File

@ -10,6 +10,8 @@ class ZU23InsurgentGenerator(GroupGenerator):
This generate a ZU23 insurgent flak artillery group
"""
name = "Zu-23 Site"
def generate(self):
grid_x = random.randint(2, 4)
grid_y = random.randint(2, 4)

View File

@ -10,6 +10,8 @@ class AvengerGenerator(GroupGenerator):
This generate an Avenger group
"""
name = "Avenger Group"
def generate(self):
num_launchers = random.randint(2, 3)

View File

@ -10,6 +10,8 @@ class ChaparralGenerator(GroupGenerator):
This generate a Chaparral group
"""
name = "Chaparral Group"
def generate(self):
num_launchers = random.randint(2, 4)

View File

@ -10,6 +10,8 @@ class GepardGenerator(GroupGenerator):
This generate a Gepard group
"""
name = "Gepard Group"
def generate(self):
self.add_unit(AirDefence.SPAAA_Gepard, "SPAAA", self.position.x, self.position.y, self.heading)
if random.randint(0, 1) == 1:

View File

@ -1,5 +1,7 @@
import random
from typing import List
from dcs.unittype import UnitType
from dcs.vehicles import AirDefence
from game import db
@ -99,6 +101,17 @@ SAM_PRICES = {
AirDefence.HQ_7_Self_Propelled_LN: 35
}
def get_faction_possible_sams_units(faction: str) -> List[UnitType]:
"""
Return the list
:param faction: Faction to search units for
:return:
"""
return [u for u in db.FACTIONS[faction]["units"] if u in AirDefence.__dict__.values()]
def get_sam_names():
pass
def generate_anti_air_group(game, parent_cp, ground_object, faction:str):
"""
This generate a SAM group
@ -107,7 +120,7 @@ def generate_anti_air_group(game, parent_cp, ground_object, faction:str):
:param country: Owner country
:return: Nothing, but put the group reference inside the ground object
"""
possible_sams = [u for u in db.FACTIONS[faction]["units"] if u in AirDefence.__dict__.values()]
possible_sams = get_faction_possible_sams_units(faction)
if len(possible_sams) > 0:
sam = random.choice(possible_sams)
generator = SAM_MAP[sam](game, ground_object)

View File

@ -10,6 +10,8 @@ class HawkGenerator(GroupGenerator):
This generate an HAWK group
"""
name = "Hawk Site"
def generate(self):
self.add_unit(AirDefence.SAM_Hawk_PCP, "PCP", self.position.x, self.position.y, self.heading)
self.add_unit(AirDefence.SAM_Hawk_SR_AN_MPQ_50, "SR", self.position.x + 20, self.position.y, self.heading)

View File

@ -10,6 +10,8 @@ class HQ7Generator(GroupGenerator):
This generate an HQ7 group
"""
name = "HQ-7 Site"
def generate(self):
self.add_unit(AirDefence.HQ_7_Self_Propelled_STR, "STR", self.position.x, self.position.y, self.heading)
self.add_unit(AirDefence.HQ_7_Self_Propelled_LN, "LN", self.position.x + 20, self.position.y, self.heading)

View File

@ -10,6 +10,8 @@ class LinebackerGenerator(GroupGenerator):
This generate an m6 linebacker group
"""
name = "Linebacker Group"
def generate(self):
num_launchers = random.randint(2, 4)

View File

@ -10,6 +10,8 @@ class PatriotGenerator(GroupGenerator):
This generate a Patriot group
"""
name = "Patriot Battery"
def generate(self):
# Command Post
self.add_unit(AirDefence.SAM_Patriot_AMG_AN_MRC_137, "MRC", self.position.x, self.position.y, self.heading)

View File

@ -10,6 +10,8 @@ class RapierGenerator(GroupGenerator):
This generate a Rapier Group
"""
name = "Rapier AA Site"
def generate(self):
self.add_unit(AirDefence.Rapier_FSA_Blindfire_Tracker, "BT", self.position.x, self.position.y, self.heading)
self.add_unit(AirDefence.Rapier_FSA_Optical_Tracker, "OT", self.position.x + 20, self.position.y, self.heading)

View File

@ -8,6 +8,8 @@ class RolandGenerator(GroupGenerator):
This generate a Roland group
"""
name = "Roland Site"
def generate(self):
self.add_unit(AirDefence.SAM_Roland_ADS, "ADS", self.position.x, self.position.y, self.heading)
self.add_unit(AirDefence.SAM_Roland_EWR, "EWR", self.position.x + 40, self.position.y, self.heading)

View File

@ -10,6 +10,8 @@ class SA10Generator(GroupGenerator):
This generate a SA-10 group
"""
name = "SA-10/S-300PS Battery"
def generate(self):
# Command Post
self.add_unit(AirDefence.SAM_SA_10_S_300PS_CP_54K6, "CP", self.position.x, self.position.y, self.heading)

View File

@ -10,6 +10,8 @@ class SA11Generator(GroupGenerator):
This generate a SA-11 group
"""
name = "SA-11 Buk Battery"
def generate(self):
self.add_unit(AirDefence.SAM_SA_11_Buk_CC_9S470M1, "CC", self.position.x, self.position.y, self.heading)
self.add_unit(AirDefence.SAM_SA_11_Buk_SR_9S18M1, "SR", self.position.x+20, self.position.y, self.heading)

View File

@ -10,6 +10,8 @@ class SA13Generator(GroupGenerator):
This generate a SA-13 group
"""
name = "SA-13 Strela Group"
def generate(self):
self.add_unit(Unarmed.Transport_UAZ_469, "UAZ", self.position.x, self.position.y, self.heading)
self.add_unit(Unarmed.Transport_KAMAZ_43101, "TRUCK", self.position.x+40, self.position.y, self.heading)

View File

@ -8,6 +8,8 @@ class SA15Generator(GroupGenerator):
This generate a SA-15 group
"""
name = "SA-15 Tor Group"
def generate(self):
self.add_unit(AirDefence.SAM_SA_15_Tor_9A331, "ADS", self.position.x, self.position.y, self.heading)
self.add_unit(Unarmed.Transport_UAZ_469, "EWR", self.position.x + 40, self.position.y, self.heading)

View File

@ -10,6 +10,8 @@ class SA19Generator(GroupGenerator):
This generate a SA-19 group
"""
name = "SA-19 Tunguska Group"
def generate(self):
num_launchers = random.randint(1, 3)

View File

@ -10,6 +10,8 @@ class SA2Generator(GroupGenerator):
This generate a SA-2 group
"""
name = "SA-2/S-75 Site"
def generate(self):
self.add_unit(AirDefence.SAM_SR_P_19, "SR", self.position.x, self.position.y, self.heading)
self.add_unit(AirDefence.SAM_SA_2_TR_SNR_75_Fan_Song, "TR", self.position.x + 20, self.position.y, self.heading)

View File

@ -10,6 +10,8 @@ class SA3Generator(GroupGenerator):
This generate a SA-3 group
"""
name = "SA-3/S-125 Site"
def generate(self):
self.add_unit(AirDefence.SAM_SR_P_19, "SR", self.position.x, self.position.y, self.heading)
self.add_unit(AirDefence.SAM_SA_3_S_125_TR_SNR, "TR", self.position.x + 20, self.position.y, self.heading)

View File

@ -10,6 +10,8 @@ class SA6Generator(GroupGenerator):
This generate a SA-6 group
"""
name = "SA-6 Kub Site"
def generate(self):
self.add_unit(AirDefence.SAM_SA_6_Kub_STR_9S91, "STR", self.position.x, self.position.y, self.heading)

View File

@ -10,6 +10,8 @@ class SA8Generator(GroupGenerator):
This generate a SA-8 group
"""
name = "SA-8 OSA Site"
def generate(self):
self.add_unit(AirDefence.SAM_SA_8_Osa_9A33, "OSA", self.position.x, self.position.y, self.heading)
self.add_unit(AirDefence.SAM_SA_8_Osa_LD_9T217, "LD", self.position.x + 20, self.position.y, self.heading)

View File

@ -10,6 +10,8 @@ class SA9Generator(GroupGenerator):
This generate a SA-9 group
"""
name = "SA-9 Group"
def generate(self):
self.add_unit(Unarmed.Transport_UAZ_469, "UAZ", self.position.x, self.position.y, self.heading)
self.add_unit(Unarmed.Transport_KAMAZ_43101, "TRUCK", self.position.x+40, self.position.y, self.heading)

View File

@ -10,6 +10,8 @@ class VulcanGenerator(GroupGenerator):
This generate a Vulcan group
"""
name = "Vulcan Group"
def generate(self):
self.add_unit(AirDefence.AAA_Vulcan_M163, "SPAAA", self.position.x, self.position.y, self.heading)
if random.randint(0, 1) == 1:

View File

@ -10,6 +10,8 @@ class ZSU23Generator(GroupGenerator):
This generate a ZSU 23 group
"""
name = "ZSU-23 Group"
def generate(self):
num_launchers = random.randint(2, 5)

View File

@ -10,6 +10,8 @@ class ZU23Generator(GroupGenerator):
This generate a ZU23 flak artillery group
"""
name = "ZU-23 Group"
def generate(self):
grid_x = random.randint(2, 4)
grid_y = random.randint(2, 4)

View File

@ -10,6 +10,8 @@ class ZU23UralGenerator(GroupGenerator):
This generate a Zu23 Ural group
"""
name = "ZU-23 Ural Group"
def generate(self):
num_launchers = random.randint(2, 8)

View File

@ -10,6 +10,8 @@ class ZU23UralInsurgentGenerator(GroupGenerator):
This generate a Zu23 Ural group
"""
name = "ZU-23 Ural Insurgent Group"
def generate(self):
num_launchers = random.randint(2, 8)

View File

@ -29,6 +29,7 @@ class QGroundObjectMenu(QDialog):
self.buildingBox = QGroupBox("Buildings :")
self.intelLayout = QGridLayout()
self.buildingsLayout = QGridLayout()
self.total_value = 0
self.init_ui()
def init_ui(self):
@ -43,9 +44,19 @@ class QGroundObjectMenu(QDialog):
self.mainLayout.addWidget(self.intelBox)
else:
self.mainLayout.addWidget(self.buildingBox)
self.actionLayout = QHBoxLayout()
sell_all_button = QPushButton("Disband (+" + str(self.total_value) + "M)")
sell_all_button.clicked.connect(self.sell_all)
self.actionLayout.addWidget(sell_all_button)
if self.total_value > 0:
self.mainLayout.addLayout(self.actionLayout)
self.setLayout(self.mainLayout)
def doLayout(self):
self.update_total_value()
self.intelBox = QGroupBox("Units :")
self.intelLayout = QGridLayout()
i = 0
@ -94,6 +105,18 @@ class QGroundObjectMenu(QDialog):
self.mainLayout.addWidget(self.buildingBox)
except Exception as e:
print(e)
self.update_total_value()
def update_total_value(self):
total_value = 0
for group in self.ground_object.groups:
for u in group.units:
utype = unit_type_of(u)
if utype in PRICES:
total_value = total_value + PRICES[utype]
else:
total_value = total_value + 1
self.total_value = total_value
def repair_unit(self, group, unit, price):
if self.game.budget > price:
@ -113,5 +136,14 @@ class QGroundObjectMenu(QDialog):
self.do_refresh_layout()
def closeEvent(self, closeEvent: QCloseEvent):
def sell_all(self):
self.update_total_value()
self.game.budget = self.game.budget + self.total_value
self.ground_object.groups = []
GameUpdateSignal.get_instance().updateGame(self.game)
def buy_group(self):
pass
def closeEvent(self, closeEvent: QCloseEvent):
pass