From 09b8ff6b93dfdf39a56b49d703dbdaab777a90f0 Mon Sep 17 00:00:00 2001 From: Khopa Date: Mon, 14 Oct 2019 01:25:48 +0200 Subject: [PATCH] Generate AA & armor to defend airbase. Destruction status correctly tracked. --- game/factions/china_2000.py | 7 +- game/factions/france_1995.py | 4 ++ game/factions/germany_1990.py | 5 +- game/factions/india_2010.py | 11 +++- game/factions/iran_2015.py | 4 ++ game/factions/israel_2000.py | 3 + game/factions/italy_1990.py | 4 +- game/factions/netherlands_1990.py | 3 + game/factions/north_korea_2000.py | 4 ++ game/factions/russia_1965.py | 4 +- game/factions/russia_1975.py | 4 ++ game/factions/russia_1990.py | 5 ++ game/factions/russia_2010.py | 5 +- game/factions/spain_1990.py | 2 + game/factions/turkey_2005.py | 5 +- game/factions/usa_1960.py | 3 + game/factions/usa_1965.py | 5 +- game/factions/usa_1990.py | 4 +- game/factions/usa_2005.py | 2 + game/operation/operation.py | 2 +- gen/aircraft.py | 2 +- gen/defenses/armor_group_generator.py | 24 +++++++ gen/defenses/armored_group_generator.py | 27 ++++++++ gen/sam/aaa_bofors.py | 4 +- gen/sam/aaa_flak36.py | 4 +- gen/sam/aaa_zu23_insurgent.py | 4 +- gen/sam/group_generator.py | 4 +- gen/sam/sam_avenger.py | 4 +- gen/sam/sam_chaparral.py | 4 +- gen/sam/sam_gepard.py | 4 +- gen/sam/sam_group_generator.py | 88 ++++++++++++++----------- gen/sam/sam_hawk.py | 4 +- gen/sam/sam_hq7.py | 4 +- gen/sam/sam_linebacker.py | 4 +- gen/sam/sam_patriot.py | 4 +- gen/sam/sam_rapier.py | 4 +- gen/sam/sam_roland.py | 4 +- gen/sam/sam_sa10.py | 4 +- gen/sam/sam_sa11.py | 4 +- gen/sam/sam_sa13.py | 4 +- gen/sam/sam_sa15.py | 4 +- gen/sam/sam_sa19.py | 4 +- gen/sam/sam_sa2.py | 4 +- gen/sam/sam_sa3.py | 4 +- gen/sam/sam_sa6.py | 4 +- gen/sam/sam_sa8.py | 4 +- gen/sam/sam_sa9.py | 4 +- gen/sam/sam_vulcan.py | 4 +- gen/sam/sam_zsu23.py | 4 +- gen/sam/sam_zu23.py | 4 +- gen/sam/sam_zu23_ural.py | 4 +- gen/sam/sam_zu23_ural_insurgent.py | 4 +- qt_ui/widgets/map/QMapGroundObject.py | 1 + theater/start_generator.py | 65 +++++++++++++++--- theater/theatergroundobject.py | 1 + 55 files changed, 289 insertions(+), 117 deletions(-) create mode 100644 gen/defenses/armor_group_generator.py create mode 100644 gen/defenses/armored_group_generator.py diff --git a/game/factions/china_2000.py b/game/factions/china_2000.py index b20978c7..1e654d15 100644 --- a/game/factions/china_2000.py +++ b/game/factions/china_2000.py @@ -22,8 +22,6 @@ China_2000 = { Mi_8MT, - AirDefence.AAA_ZU_23_Closed, - AirDefence.Rapier_FSA_Launcher, # Standing as PL-9C Shorad AirDefence.SAM_SA_10_S_300PS_LN_5P85C, # Standing as HQ-9+ AirDefence.SAM_SA_6_Kub_LN_2P25, AirDefence.HQ_7_Self_Propelled_LN, @@ -41,5 +39,10 @@ China_2000 = { Bulk_cargo_ship_Yakushev, Dry_cargo_ship_Ivanov, Tanker_Elnya_160 + ], + "shorad":[ + AirDefence.AAA_ZU_23_Closed, + AirDefence.Rapier_FSA_Launcher, # Standing as PL-9C Shorad + AirDefence.HQ_7_Self_Propelled_LN ] } \ No newline at end of file diff --git a/game/factions/france_1995.py b/game/factions/france_1995.py index b5916513..406f9b3e 100644 --- a/game/factions/france_1995.py +++ b/game/factions/france_1995.py @@ -31,5 +31,9 @@ France_1995 = { CVN_74_John_C__Stennis, LHA_1_Tarawa, Armed_speedboat, + + ], "shorad":[ + AirDefence.HQ_7_Self_Propelled_LN, + AirDefence.SAM_Roland_ADS ] } \ No newline at end of file diff --git a/game/factions/germany_1990.py b/game/factions/germany_1990.py index 23e3eeab..e819b8ca 100644 --- a/game/factions/germany_1990.py +++ b/game/factions/germany_1990.py @@ -27,12 +27,15 @@ Germany_1990 = { Unarmed.Transport_M818, Infantry.Infantry_M4, - AirDefence.SPAAA_Gepard, AirDefence.SAM_Roland_ADS, AirDefence.SAM_Hawk_PCP, CVN_74_John_C__Stennis, LHA_1_Tarawa, Armed_speedboat, + ], + "shorad":[ + AirDefence.SPAAA_Gepard, + AirDefence.SAM_Roland_ADS, ] } \ No newline at end of file diff --git a/game/factions/india_2010.py b/game/factions/india_2010.py index 3434c0f9..15eb1fca 100644 --- a/game/factions/india_2010.py +++ b/game/factions/india_2010.py @@ -31,12 +31,17 @@ India_2010 = { AirDefence.SAM_SA_6_Kub_LN_2P25, AirDefence.SAM_SA_3_S_125_LN_5P73, - AirDefence.SAM_SA_8_Osa_9A33, - AirDefence.SAM_SA_13_Strela_10M3_9A35M3, - AirDefence.SAM_SA_19_Tunguska_2S6, CVN_74_John_C__Stennis, LHA_1_Tarawa, Armed_speedboat, + ], + "shorad":[ + AirDefence.SAM_SA_8_Osa_9A33, + AirDefence.AAA_ZU_23_Emplacement, + AirDefence.SPAAA_ZSU_23_4_Shilka, + AirDefence.SAM_SA_13_Strela_10M3_9A35M3, + AirDefence.SAM_SA_8_Osa_9A33, + AirDefence.SAM_SA_19_Tunguska_2S6 ] } \ No newline at end of file diff --git a/game/factions/iran_2015.py b/game/factions/iran_2015.py index ebfcfeea..b0ae4743 100644 --- a/game/factions/iran_2015.py +++ b/game/factions/iran_2015.py @@ -48,5 +48,9 @@ Iran_2015 = { Bulk_cargo_ship_Yakushev, Dry_cargo_ship_Ivanov, Tanker_Elnya_160 + ], + "shorad":[ + AirDefence.HQ_7_Self_Propelled_LN, + AirDefence.AAA_ZU_23_Insurgent_Closed ] } \ No newline at end of file diff --git a/game/factions/israel_2000.py b/game/factions/israel_2000.py index 45eebd38..438bf33e 100644 --- a/game/factions/israel_2000.py +++ b/game/factions/israel_2000.py @@ -30,5 +30,8 @@ Israel_2000 = { CVN_74_John_C__Stennis, LHA_1_Tarawa, Armed_speedboat, + ], + "shorad":[ + AirDefence.SAM_Avenger_M1097 ] } \ No newline at end of file diff --git a/game/factions/italy_1990.py b/game/factions/italy_1990.py index 474a0a29..8d1a6210 100644 --- a/game/factions/italy_1990.py +++ b/game/factions/italy_1990.py @@ -31,5 +31,7 @@ Italy_1990 = { CVN_74_John_C__Stennis, LHA_1_Tarawa, Armed_speedboat, - ] + ], "shorad":[ + AirDefence.SAM_Avenger_M1097, + ] } diff --git a/game/factions/netherlands_1990.py b/game/factions/netherlands_1990.py index 92add3be..5f5b0d48 100644 --- a/game/factions/netherlands_1990.py +++ b/game/factions/netherlands_1990.py @@ -29,5 +29,8 @@ Netherlands_1990 = { CVN_74_John_C__Stennis, LHA_1_Tarawa, Armed_speedboat, + ], + "shorad":[ + AirDefence.SAM_Avenger_M1097 ] } \ No newline at end of file diff --git a/game/factions/north_korea_2000.py b/game/factions/north_korea_2000.py index be63204c..b920e0e1 100644 --- a/game/factions/north_korea_2000.py +++ b/game/factions/north_korea_2000.py @@ -42,5 +42,9 @@ NorthKorea_2000 = { Bulk_cargo_ship_Yakushev, Dry_cargo_ship_Ivanov, Tanker_Elnya_160 + ], + "shorad":[ + AirDefence.AAA_ZU_23_Emplacement, + AirDefence.SPAAA_ZSU_23_4_Shilka ] } \ No newline at end of file diff --git a/game/factions/russia_1965.py b/game/factions/russia_1965.py index c5febcaa..d57a57f8 100644 --- a/game/factions/russia_1965.py +++ b/game/factions/russia_1965.py @@ -21,7 +21,6 @@ Russia_1965 = { Mi_8MT, - AirDefence.AAA_ZU_23_Closed, AirDefence.SAM_SA_6_Kub_LN_2P25, AirDefence.SAM_SA_2_LN_SM_90, AirDefence.SAM_SA_3_S_125_LN_5P73, @@ -41,5 +40,8 @@ Russia_1965 = { Bulk_cargo_ship_Yakushev, Dry_cargo_ship_Ivanov, Tanker_Elnya_160 + ], + "shorad":[ + AirDefence.AAA_ZU_23_Closed ] } \ No newline at end of file diff --git a/game/factions/russia_1975.py b/game/factions/russia_1975.py index f3e4cfb4..e002fd90 100644 --- a/game/factions/russia_1975.py +++ b/game/factions/russia_1975.py @@ -47,5 +47,9 @@ Russia_1975 = { Bulk_cargo_ship_Yakushev, Dry_cargo_ship_Ivanov, Tanker_Elnya_160 + ], + "shorad":[ + AirDefence.AAA_ZU_23_Emplacement, + AirDefence.SPAAA_ZSU_23_4_Shilka ] } \ No newline at end of file diff --git a/game/factions/russia_1990.py b/game/factions/russia_1990.py index f18f7c69..42228528 100644 --- a/game/factions/russia_1990.py +++ b/game/factions/russia_1990.py @@ -48,5 +48,10 @@ Russia_1990 = { Bulk_cargo_ship_Yakushev, Dry_cargo_ship_Ivanov, Tanker_Elnya_160 + ], + "shorad":[ + AirDefence.SAM_SA_9_Strela_1_9P31, + AirDefence.SAM_SA_13_Strela_10M3_9A35M3, + AirDefence.SPAAA_ZSU_23_4_Shilka ] } \ No newline at end of file diff --git a/game/factions/russia_2010.py b/game/factions/russia_2010.py index cbc3e62e..c53ddd90 100644 --- a/game/factions/russia_2010.py +++ b/game/factions/russia_2010.py @@ -29,7 +29,6 @@ Russia_2010 = { Ka_50, Mi_8MT, - AirDefence.SPAAA_ZSU_23_4_Shilka, AirDefence.SAM_SA_19_Tunguska_2S6, AirDefence.SAM_SA_11_Buk_LN_9A310M1, AirDefence.SAM_SA_10_S_300PS_LN_5P85C, @@ -46,5 +45,9 @@ Russia_2010 = { Bulk_cargo_ship_Yakushev, Dry_cargo_ship_Ivanov, Tanker_Elnya_160, + ], + "shorad":[ + AirDefence.SAM_SA_19_Tunguska_2S6, + AirDefence.SAM_SA_13_Strela_10M3_9A35M3 ] } diff --git a/game/factions/spain_1990.py b/game/factions/spain_1990.py index 8a37ad61..5109a6cd 100644 --- a/game/factions/spain_1990.py +++ b/game/factions/spain_1990.py @@ -28,5 +28,7 @@ Spain_1990 = { CVN_74_John_C__Stennis, LHA_1_Tarawa, Armed_speedboat, + ], "shorad":[ + AirDefence.SAM_Avenger_M1097, ] } \ No newline at end of file diff --git a/game/factions/turkey_2005.py b/game/factions/turkey_2005.py index 4ffb6629..3ca96948 100644 --- a/game/factions/turkey_2005.py +++ b/game/factions/turkey_2005.py @@ -21,7 +21,7 @@ Turkey_2005 = { Armor.MBT_Leopard_2, Armor.MBT_Leopard_1A3, - Armor.MBT_M60A3_Patton, # Standing as VAB + Armor.MBT_M60A3_Patton, Armor.APC_Cobra, Armor.APC_BTR_80, @@ -33,5 +33,8 @@ Turkey_2005 = { CVN_74_John_C__Stennis, LHA_1_Tarawa, Armed_speedboat, + ], "shorad":[ + AirDefence.AAA_ZU_23_Emplacement, + AirDefence.SPAAA_ZSU_23_4_Shilka ] } \ No newline at end of file diff --git a/game/factions/usa_1960.py b/game/factions/usa_1960.py index d528762d..57d4a996 100644 --- a/game/factions/usa_1960.py +++ b/game/factions/usa_1960.py @@ -28,5 +28,8 @@ USA_1960 = { CVN_74_John_C__Stennis, LHA_1_Tarawa, Armed_speedboat, + ], + "shorad":[ + AirDefence.AAA_Vulcan_M163 ] } \ No newline at end of file diff --git a/game/factions/usa_1965.py b/game/factions/usa_1965.py index b3d66d26..177759b6 100644 --- a/game/factions/usa_1965.py +++ b/game/factions/usa_1965.py @@ -25,12 +25,15 @@ USA_1965 = { Unarmed.Transport_M818, Infantry.Infantry_M4, - AirDefence.AAA_Vulcan_M163, AirDefence.SAM_Chaparral_M48, AirDefence.SAM_Hawk_PCP, CVN_74_John_C__Stennis, LHA_1_Tarawa, Armed_speedboat, + ], + "shorad":[ + AirDefence.AAA_Vulcan_M163, + AirDefence.SAM_Chaparral_M48 ] } \ No newline at end of file diff --git a/game/factions/usa_1990.py b/game/factions/usa_1990.py index 0a330a6d..0238ebce 100644 --- a/game/factions/usa_1990.py +++ b/game/factions/usa_1990.py @@ -33,10 +33,12 @@ USA_1990 = { Infantry.Infantry_M4, AirDefence.SAM_Hawk_PCP, - AirDefence.SAM_Avenger_M1097, + CVN_74_John_C__Stennis, LHA_1_Tarawa, Armed_speedboat, + ], "shorad":[ + AirDefence.SAM_Avenger_M1097, ] } \ No newline at end of file diff --git a/game/factions/usa_2005.py b/game/factions/usa_2005.py index 9bdbdb9e..bbcc8cf7 100644 --- a/game/factions/usa_2005.py +++ b/game/factions/usa_2005.py @@ -38,5 +38,7 @@ USA_2005 = { CVN_74_John_C__Stennis, LHA_1_Tarawa, Armed_speedboat, + ], "shorad":[ + AirDefence.SAM_Avenger_M1097, ] } \ No newline at end of file diff --git a/game/operation/operation.py b/game/operation/operation.py index 8bf0f875..1b82ded7 100644 --- a/game/operation/operation.py +++ b/game/operation/operation.py @@ -170,7 +170,7 @@ class Operation: else: self.current_mission.groundControl.red_tactical_commander = self.ca_slots - self.extra_aagen.generate() + #self.extra_aagen.generate() # triggers if self.game.is_player_attack(self.conflict.attackers_country): diff --git a/gen/aircraft.py b/gen/aircraft.py index b9472b00..bc3a1951 100644 --- a/gen/aircraft.py +++ b/gen/aircraft.py @@ -340,7 +340,7 @@ class AircraftConflictGenerator: patrolled = [] for ground_object in cp.ground_objects: - if not ground_object.group_id in patrolled: + if not ground_object.group_id in patrolled and not ground_object.airbase_group: group.add_waypoint(ground_object.position, patrol_alt) patrolled.append(ground_object.group_id) diff --git a/gen/defenses/armor_group_generator.py b/gen/defenses/armor_group_generator.py new file mode 100644 index 00000000..dec5196d --- /dev/null +++ b/gen/defenses/armor_group_generator.py @@ -0,0 +1,24 @@ +import random + +from dcs.vehicles import Armor + +from game import db +from gen.defenses.armored_group_generator import ArmoredGroupGenerator + + +def generate_armor_group(faction:str, game, ground_object): + """ + This generate a SAM group + :param parentCp: The parent control point + :param ground_object: The ground object which will own the sam group + :param country: Owner country + :return: Nothing, but put the group reference inside the ground object + """ + + possible_unit = [u for u in db.FACTIONS[faction]["units"] if u in Armor.__dict__.values()] + if len(possible_unit) > 0: + unit_type = random.choice(possible_unit) + generator = ArmoredGroupGenerator(game, ground_object, unit_type) + generator.generate() + return generator.get_generated_group() + return None diff --git a/gen/defenses/armored_group_generator.py b/gen/defenses/armored_group_generator.py new file mode 100644 index 00000000..f678af81 --- /dev/null +++ b/gen/defenses/armored_group_generator.py @@ -0,0 +1,27 @@ +import random + +from gen.sam.group_generator import GroupGenerator + + +class ArmoredGroupGenerator(GroupGenerator): + + def __init__(self, game, ground_object, unit_type): + super(ArmoredGroupGenerator, self).__init__(game, ground_object) + self.unit_type = unit_type + + def generate(self): + + grid_x = random.randint(2, 3) + grid_y = random.randint(1, 2) + + spacing = random.randint(30, 80) + + index = 0 + for i in range(grid_x): + for j in range(grid_y): + index = index + 1 + self.add_unit(self.unit_type, "Armor#" + str(index), + self.position.x + spacing * i, + self.position.y + spacing * j, self.heading) + + diff --git a/gen/sam/aaa_bofors.py b/gen/sam/aaa_bofors.py index 2989667b..7cab286a 100644 --- a/gen/sam/aaa_bofors.py +++ b/gen/sam/aaa_bofors.py @@ -2,10 +2,10 @@ import random from dcs.vehicles import AirDefence -from gen.sam.group_generator import AntiAirGroupGenerator +from gen.sam.group_generator import GroupGenerator -class BoforsGenerator(AntiAirGroupGenerator): +class BoforsGenerator(GroupGenerator): """ This generate a Bofors flak artillery group """ diff --git a/gen/sam/aaa_flak36.py b/gen/sam/aaa_flak36.py index 961fbe76..34571341 100644 --- a/gen/sam/aaa_flak36.py +++ b/gen/sam/aaa_flak36.py @@ -2,10 +2,10 @@ import random from dcs.vehicles import AirDefence -from gen.sam.group_generator import AntiAirGroupGenerator +from gen.sam.group_generator import GroupGenerator -class Flak36Generator(AntiAirGroupGenerator): +class Flak36Generator(GroupGenerator): """ This generate a Bofors flak artillery group """ diff --git a/gen/sam/aaa_zu23_insurgent.py b/gen/sam/aaa_zu23_insurgent.py index e4cc2498..ec207d84 100644 --- a/gen/sam/aaa_zu23_insurgent.py +++ b/gen/sam/aaa_zu23_insurgent.py @@ -2,10 +2,10 @@ import random from dcs.vehicles import AirDefence -from gen.sam.group_generator import AntiAirGroupGenerator +from gen.sam.group_generator import GroupGenerator -class ZU23InsurgentGenerator(AntiAirGroupGenerator): +class ZU23InsurgentGenerator(GroupGenerator): """ This generate a ZU23 insurgent flak artillery group """ diff --git a/gen/sam/group_generator.py b/gen/sam/group_generator.py index 59fb37fa..e6620211 100644 --- a/gen/sam/group_generator.py +++ b/gen/sam/group_generator.py @@ -6,9 +6,9 @@ from dcs.point import PointAction from dcs.unit import Vehicle -class AntiAirGroupGenerator(): +class GroupGenerator(): - def __init__(self, game, ground_object, group_object_group_id): + def __init__(self, game, ground_object): self.game = game self.go = ground_object self.position = ground_object.position diff --git a/gen/sam/sam_avenger.py b/gen/sam/sam_avenger.py index 41597617..d2d7c52b 100644 --- a/gen/sam/sam_avenger.py +++ b/gen/sam/sam_avenger.py @@ -2,10 +2,10 @@ import random from dcs.vehicles import AirDefence, Unarmed -from gen.sam.group_generator import AntiAirGroupGenerator +from gen.sam.group_generator import GroupGenerator -class AvengerGenerator(AntiAirGroupGenerator): +class AvengerGenerator(GroupGenerator): """ This generate an Avenger group """ diff --git a/gen/sam/sam_chaparral.py b/gen/sam/sam_chaparral.py index fc03add8..09d0f2a8 100644 --- a/gen/sam/sam_chaparral.py +++ b/gen/sam/sam_chaparral.py @@ -2,10 +2,10 @@ import random from dcs.vehicles import AirDefence, Unarmed -from gen.sam.group_generator import AntiAirGroupGenerator +from gen.sam.group_generator import GroupGenerator -class ChaparralGenerator(AntiAirGroupGenerator): +class ChaparralGenerator(GroupGenerator): """ This generate a Chaparral group """ diff --git a/gen/sam/sam_gepard.py b/gen/sam/sam_gepard.py index 84fd3a4f..15daa7d3 100644 --- a/gen/sam/sam_gepard.py +++ b/gen/sam/sam_gepard.py @@ -2,10 +2,10 @@ import random from dcs.vehicles import AirDefence, Unarmed -from gen.sam.group_generator import AntiAirGroupGenerator +from gen.sam.group_generator import GroupGenerator -class GepardGenerator(AntiAirGroupGenerator): +class GepardGenerator(GroupGenerator): """ This generate a Gepard group """ diff --git a/gen/sam/sam_group_generator.py b/gen/sam/sam_group_generator.py index 31d0769e..4569333c 100644 --- a/gen/sam/sam_group_generator.py +++ b/gen/sam/sam_group_generator.py @@ -36,6 +36,39 @@ from gen.sam.sam_zu23 import ZU23Generator from gen.sam.sam_zu23_ural import ZU23UralGenerator from gen.sam.sam_zu23_ural_insurgent import ZU23UralInsurgentGenerator +SAM_MAP = { + AirDefence.SAM_Hawk_PCP: HawkGenerator, + AirDefence.AAA_ZU_23_Emplacement: ZU23Generator, + AirDefence.AAA_ZU_23_Closed: ZU23Generator, + AirDefence.AAA_ZU_23_on_Ural_375: ZU23UralGenerator, + AirDefence.AAA_ZU_23_Insurgent_on_Ural_375: ZU23UralInsurgentGenerator, + AirDefence.AAA_ZU_23_Insurgent_Closed: ZU23InsurgentGenerator, + AirDefence.AAA_ZU_23_Insurgent: ZU23InsurgentGenerator, + AirDefence.SPAAA_ZSU_23_4_Shilka: ZSU23Generator, + AirDefence.AAA_Vulcan_M163: VulcanGenerator, + AirDefence.SAM_Linebacker_M6: LinebackerGenerator, + AirDefence.Rapier_FSA_Launcher: RapierGenerator, + AirDefence.SAM_Avenger_M1097: AvengerGenerator, + AirDefence.SPAAA_Gepard: GepardGenerator, + AirDefence.SAM_Roland_ADS: RolandGenerator, + AirDefence.SAM_Patriot_LN_M901: PatriotGenerator, + AirDefence.SAM_Patriot_EPP_III: PatriotGenerator, + AirDefence.SAM_Chaparral_M48: ChaparralGenerator, + AirDefence.AAA_Bofors_40mm: BoforsGenerator, + AirDefence.AAA_Flak_36: Flak36Generator, + AirDefence.SAM_SA_2_LN_SM_90: SA2Generator, + AirDefence.SAM_SA_3_S_125_LN_5P73: SA3Generator, + AirDefence.SAM_SA_6_Kub_LN_2P25: SA6Generator, + AirDefence.SAM_SA_8_Osa_9A33: SA8Generator, + AirDefence.SAM_SA_9_Strela_1_9P31: SA9Generator, + AirDefence.SAM_SA_10_S_300PS_LN_5P85C: SA10Generator, + AirDefence.SAM_SA_10_S_300PS_CP_54K6: SA10Generator, + AirDefence.SAM_SA_11_Buk_LN_9A310M1: SA11Generator, + AirDefence.SAM_SA_13_Strela_10M3_9A35M3: SA13Generator, + AirDefence.SAM_SA_15_Tor_9A331: SA15Generator, + AirDefence.SAM_SA_19_Tunguska_2S6: SA19Generator, + AirDefence.HQ_7_Self_Propelled_LN: HQ7Generator +} def generate_anti_air_group(game, parent_cp, ground_object, faction:str): """ @@ -45,49 +78,26 @@ 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 """ - - SAM_MAP = { - - AirDefence.SAM_Hawk_PCP:HawkGenerator, - AirDefence.AAA_ZU_23_Emplacement: ZU23Generator, - AirDefence.AAA_ZU_23_Closed:ZU23Generator, - AirDefence.AAA_ZU_23_on_Ural_375: ZU23UralGenerator, - AirDefence.AAA_ZU_23_Insurgent_on_Ural_375:ZU23UralInsurgentGenerator, - AirDefence.AAA_ZU_23_Insurgent_Closed: ZU23InsurgentGenerator, - AirDefence.AAA_ZU_23_Insurgent: ZU23InsurgentGenerator, - AirDefence.SPAAA_ZSU_23_4_Shilka:ZSU23Generator, - AirDefence.AAA_Vulcan_M163: VulcanGenerator, - AirDefence.SAM_Linebacker_M6: LinebackerGenerator, - AirDefence.Rapier_FSA_Launcher: RapierGenerator, - AirDefence.SAM_Avenger_M1097: AvengerGenerator, - AirDefence.SPAAA_Gepard: GepardGenerator, - AirDefence.SAM_Roland_ADS: RolandGenerator, - AirDefence.SAM_Patriot_LN_M901: PatriotGenerator, - AirDefence.SAM_Patriot_EPP_III: PatriotGenerator, - AirDefence.SAM_Chaparral_M48: ChaparralGenerator, - AirDefence.AAA_Bofors_40mm: BoforsGenerator, - AirDefence.AAA_Flak_36: Flak36Generator, - - AirDefence.SAM_SA_2_LN_SM_90: SA2Generator, - AirDefence.SAM_SA_3_S_125_LN_5P73: SA3Generator, - AirDefence.SAM_SA_6_Kub_LN_2P25: SA6Generator, - AirDefence.SAM_SA_8_Osa_9A33: SA8Generator, - AirDefence.SAM_SA_9_Strela_1_9P31: SA9Generator, - AirDefence.SAM_SA_10_S_300PS_LN_5P85C: SA10Generator, - AirDefence.SAM_SA_10_S_300PS_CP_54K6: SA10Generator, - AirDefence.SAM_SA_11_Buk_LN_9A310M1: SA11Generator, - AirDefence.SAM_SA_13_Strela_10M3_9A35M3: SA13Generator, - AirDefence.SAM_SA_15_Tor_9A331: SA15Generator, - AirDefence.SAM_SA_19_Tunguska_2S6: SA19Generator, - AirDefence.HQ_7_Self_Propelled_LN: HQ7Generator - } - possible_sams = [u for u in db.FACTIONS[faction]["units"] if u in AirDefence.__dict__.values()] if len(possible_sams) > 0: sam = random.choice(possible_sams) - generator = SAM_MAP[sam](game, ground_object, 0) + generator = SAM_MAP[sam](game, ground_object) generator.generate() - ground_object.groups = [generator.get_generated_group()] + return generator.get_generated_group() + return None + + +def generate_shorad_group(game, parent_cp, ground_object, faction:str): + if("shorad") in db.FACTIONS[faction].keys(): + shorad = db.FACTIONS[faction]["shorad"] + sam = random.choice(shorad) + generator = SAM_MAP[sam](game, ground_object) + generator.generate() + return generator.get_generated_group() + else: + return generate_anti_air_group(game, parent_cp, ground_object, faction) + + diff --git a/gen/sam/sam_hawk.py b/gen/sam/sam_hawk.py index ab181d5e..4b43b79d 100644 --- a/gen/sam/sam_hawk.py +++ b/gen/sam/sam_hawk.py @@ -2,10 +2,10 @@ import random from dcs.vehicles import AirDefence -from gen.sam.group_generator import AntiAirGroupGenerator +from gen.sam.group_generator import GroupGenerator -class HawkGenerator(AntiAirGroupGenerator): +class HawkGenerator(GroupGenerator): """ This generate an HAWK group """ diff --git a/gen/sam/sam_hq7.py b/gen/sam/sam_hq7.py index b450438e..8bd5f528 100644 --- a/gen/sam/sam_hq7.py +++ b/gen/sam/sam_hq7.py @@ -2,10 +2,10 @@ import random from dcs.vehicles import AirDefence -from gen.sam.group_generator import AntiAirGroupGenerator +from gen.sam.group_generator import GroupGenerator -class HQ7Generator(AntiAirGroupGenerator): +class HQ7Generator(GroupGenerator): """ This generate an HQ7 group """ diff --git a/gen/sam/sam_linebacker.py b/gen/sam/sam_linebacker.py index e9dd6bcd..be2dafb7 100644 --- a/gen/sam/sam_linebacker.py +++ b/gen/sam/sam_linebacker.py @@ -2,10 +2,10 @@ import random from dcs.vehicles import AirDefence, Unarmed -from gen.sam.group_generator import AntiAirGroupGenerator +from gen.sam.group_generator import GroupGenerator -class LinebackerGenerator(AntiAirGroupGenerator): +class LinebackerGenerator(GroupGenerator): """ This generate an m6 linebacker group """ diff --git a/gen/sam/sam_patriot.py b/gen/sam/sam_patriot.py index 24730b40..5505ba2a 100644 --- a/gen/sam/sam_patriot.py +++ b/gen/sam/sam_patriot.py @@ -2,10 +2,10 @@ import random from dcs.vehicles import AirDefence -from gen.sam.group_generator import AntiAirGroupGenerator +from gen.sam.group_generator import GroupGenerator -class PatriotGenerator(AntiAirGroupGenerator): +class PatriotGenerator(GroupGenerator): """ This generate a Patriot group """ diff --git a/gen/sam/sam_rapier.py b/gen/sam/sam_rapier.py index 3e1aeecc..2ff0d2bb 100644 --- a/gen/sam/sam_rapier.py +++ b/gen/sam/sam_rapier.py @@ -2,10 +2,10 @@ import random from dcs.vehicles import AirDefence -from gen.sam.group_generator import AntiAirGroupGenerator +from gen.sam.group_generator import GroupGenerator -class RapierGenerator(AntiAirGroupGenerator): +class RapierGenerator(GroupGenerator): """ This generate a Rapier Group """ diff --git a/gen/sam/sam_roland.py b/gen/sam/sam_roland.py index e61777c8..6ee438e6 100644 --- a/gen/sam/sam_roland.py +++ b/gen/sam/sam_roland.py @@ -1,9 +1,9 @@ from dcs.vehicles import AirDefence, Unarmed -from gen.sam.group_generator import AntiAirGroupGenerator +from gen.sam.group_generator import GroupGenerator -class RolandGenerator(AntiAirGroupGenerator): +class RolandGenerator(GroupGenerator): """ This generate a Roland group """ diff --git a/gen/sam/sam_sa10.py b/gen/sam/sam_sa10.py index 11e9074a..d85def5c 100644 --- a/gen/sam/sam_sa10.py +++ b/gen/sam/sam_sa10.py @@ -2,10 +2,10 @@ import random from dcs.vehicles import AirDefence -from gen.sam.group_generator import AntiAirGroupGenerator +from gen.sam.group_generator import GroupGenerator -class SA10Generator(AntiAirGroupGenerator): +class SA10Generator(GroupGenerator): """ This generate a SA-10 group """ diff --git a/gen/sam/sam_sa11.py b/gen/sam/sam_sa11.py index 16e0fbd5..d3709550 100644 --- a/gen/sam/sam_sa11.py +++ b/gen/sam/sam_sa11.py @@ -2,10 +2,10 @@ import random from dcs.vehicles import AirDefence -from gen.sam.group_generator import AntiAirGroupGenerator +from gen.sam.group_generator import GroupGenerator -class SA11Generator(AntiAirGroupGenerator): +class SA11Generator(GroupGenerator): """ This generate a SA-11 group """ diff --git a/gen/sam/sam_sa13.py b/gen/sam/sam_sa13.py index c398974e..c3e45745 100644 --- a/gen/sam/sam_sa13.py +++ b/gen/sam/sam_sa13.py @@ -2,10 +2,10 @@ import random from dcs.vehicles import AirDefence, Unarmed -from gen.sam.group_generator import AntiAirGroupGenerator +from gen.sam.group_generator import GroupGenerator -class SA13Generator(AntiAirGroupGenerator): +class SA13Generator(GroupGenerator): """ This generate a SA-13 group """ diff --git a/gen/sam/sam_sa15.py b/gen/sam/sam_sa15.py index 3da935cd..592c1a34 100644 --- a/gen/sam/sam_sa15.py +++ b/gen/sam/sam_sa15.py @@ -1,9 +1,9 @@ from dcs.vehicles import AirDefence, Unarmed -from gen.sam.group_generator import AntiAirGroupGenerator +from gen.sam.group_generator import GroupGenerator -class SA15Generator(AntiAirGroupGenerator): +class SA15Generator(GroupGenerator): """ This generate a SA-15 group """ diff --git a/gen/sam/sam_sa19.py b/gen/sam/sam_sa19.py index 506666e6..b81fd35d 100644 --- a/gen/sam/sam_sa19.py +++ b/gen/sam/sam_sa19.py @@ -2,10 +2,10 @@ import random from dcs.vehicles import AirDefence -from gen.sam.group_generator import AntiAirGroupGenerator +from gen.sam.group_generator import GroupGenerator -class SA19Generator(AntiAirGroupGenerator): +class SA19Generator(GroupGenerator): """ This generate a SA-19 group """ diff --git a/gen/sam/sam_sa2.py b/gen/sam/sam_sa2.py index 810013ee..384b3a06 100644 --- a/gen/sam/sam_sa2.py +++ b/gen/sam/sam_sa2.py @@ -2,10 +2,10 @@ import random from dcs.vehicles import AirDefence -from gen.sam.group_generator import AntiAirGroupGenerator +from gen.sam.group_generator import GroupGenerator -class SA2Generator(AntiAirGroupGenerator): +class SA2Generator(GroupGenerator): """ This generate a SA-2 group """ diff --git a/gen/sam/sam_sa3.py b/gen/sam/sam_sa3.py index dd329c61..d4095a7e 100644 --- a/gen/sam/sam_sa3.py +++ b/gen/sam/sam_sa3.py @@ -2,10 +2,10 @@ import random from dcs.vehicles import AirDefence -from gen.sam.group_generator import AntiAirGroupGenerator +from gen.sam.group_generator import GroupGenerator -class SA3Generator(AntiAirGroupGenerator): +class SA3Generator(GroupGenerator): """ This generate a SA-3 group """ diff --git a/gen/sam/sam_sa6.py b/gen/sam/sam_sa6.py index 52700ce6..64c6c15c 100644 --- a/gen/sam/sam_sa6.py +++ b/gen/sam/sam_sa6.py @@ -2,10 +2,10 @@ import random from dcs.vehicles import AirDefence -from gen.sam.group_generator import AntiAirGroupGenerator +from gen.sam.group_generator import GroupGenerator -class SA6Generator(AntiAirGroupGenerator): +class SA6Generator(GroupGenerator): """ This generate a SA-6 group """ diff --git a/gen/sam/sam_sa8.py b/gen/sam/sam_sa8.py index 80dfea46..d2e7e8d6 100644 --- a/gen/sam/sam_sa8.py +++ b/gen/sam/sam_sa8.py @@ -2,10 +2,10 @@ import random from dcs.vehicles import AirDefence -from gen.sam.group_generator import AntiAirGroupGenerator +from gen.sam.group_generator import GroupGenerator -class SA8Generator(AntiAirGroupGenerator): +class SA8Generator(GroupGenerator): """ This generate a SA-8 group """ diff --git a/gen/sam/sam_sa9.py b/gen/sam/sam_sa9.py index 53a17e4a..f16b7cca 100644 --- a/gen/sam/sam_sa9.py +++ b/gen/sam/sam_sa9.py @@ -2,10 +2,10 @@ import random from dcs.vehicles import AirDefence, Unarmed -from gen.sam.group_generator import AntiAirGroupGenerator +from gen.sam.group_generator import GroupGenerator -class SA9Generator(AntiAirGroupGenerator): +class SA9Generator(GroupGenerator): """ This generate a SA-9 group """ diff --git a/gen/sam/sam_vulcan.py b/gen/sam/sam_vulcan.py index a1acbe76..7cd8d7aa 100644 --- a/gen/sam/sam_vulcan.py +++ b/gen/sam/sam_vulcan.py @@ -2,10 +2,10 @@ import random from dcs.vehicles import AirDefence, Unarmed -from gen.sam.group_generator import AntiAirGroupGenerator +from gen.sam.group_generator import GroupGenerator -class VulcanGenerator(AntiAirGroupGenerator): +class VulcanGenerator(GroupGenerator): """ This generate a Vulcan group """ diff --git a/gen/sam/sam_zsu23.py b/gen/sam/sam_zsu23.py index 535d8cf3..b0707416 100644 --- a/gen/sam/sam_zsu23.py +++ b/gen/sam/sam_zsu23.py @@ -2,10 +2,10 @@ import random from dcs.vehicles import AirDefence -from gen.sam.group_generator import AntiAirGroupGenerator +from gen.sam.group_generator import GroupGenerator -class ZSU23Generator(AntiAirGroupGenerator): +class ZSU23Generator(GroupGenerator): """ This generate a ZSU 23 group """ diff --git a/gen/sam/sam_zu23.py b/gen/sam/sam_zu23.py index 075baa13..34a892ab 100644 --- a/gen/sam/sam_zu23.py +++ b/gen/sam/sam_zu23.py @@ -2,10 +2,10 @@ import random from dcs.vehicles import AirDefence -from gen.sam.group_generator import AntiAirGroupGenerator +from gen.sam.group_generator import GroupGenerator -class ZU23Generator(AntiAirGroupGenerator): +class ZU23Generator(GroupGenerator): """ This generate a ZU23 flak artillery group """ diff --git a/gen/sam/sam_zu23_ural.py b/gen/sam/sam_zu23_ural.py index 1b11024b..248b84a0 100644 --- a/gen/sam/sam_zu23_ural.py +++ b/gen/sam/sam_zu23_ural.py @@ -2,10 +2,10 @@ import random from dcs.vehicles import AirDefence -from gen.sam.group_generator import AntiAirGroupGenerator +from gen.sam.group_generator import GroupGenerator -class ZU23UralGenerator(AntiAirGroupGenerator): +class ZU23UralGenerator(GroupGenerator): """ This generate a Zu23 Ural group """ diff --git a/gen/sam/sam_zu23_ural_insurgent.py b/gen/sam/sam_zu23_ural_insurgent.py index 04ae3ccd..282f3d20 100644 --- a/gen/sam/sam_zu23_ural_insurgent.py +++ b/gen/sam/sam_zu23_ural_insurgent.py @@ -2,10 +2,10 @@ import random from dcs.vehicles import AirDefence -from gen.sam.group_generator import AntiAirGroupGenerator +from gen.sam.group_generator import GroupGenerator -class ZU23UralInsurgentGenerator(AntiAirGroupGenerator): +class ZU23UralInsurgentGenerator(GroupGenerator): """ This generate a Zu23 Ural group """ diff --git a/qt_ui/widgets/map/QMapGroundObject.py b/qt_ui/widgets/map/QMapGroundObject.py index aaafa7da..6c08bd06 100644 --- a/qt_ui/widgets/map/QMapGroundObject.py +++ b/qt_ui/widgets/map/QMapGroundObject.py @@ -21,6 +21,7 @@ class QMapGroundObject(QGraphicsRectItem): if len(self.model.groups) > 0: units = {} for g in self.model.groups: + print(g) for u in g.units: if u.type in units.keys(): units[u.type] = units[u.type]+1 diff --git a/theater/start_generator.py b/theater/start_generator.py index 55c810a2..c7d78943 100644 --- a/theater/start_generator.py +++ b/theater/start_generator.py @@ -4,7 +4,8 @@ import random import typing import logging -from gen.sam.sam_group_generator import generate_anti_air_group +from gen.defenses.armor_group_generator import generate_armor_group +from gen.sam.sam_group_generator import generate_anti_air_group, generate_shorad_group from theater.base import * from theater.conflicttheater import * @@ -61,6 +62,50 @@ def generate_groundobjects(theater: ConflictTheater, game): for cp in theater.controlpoints: group_id = generate_cp_ground_points(cp, theater, game, group_id, tpls) + # CP + if cp.captured: + faction = game.player_name + else: + faction = game.enemy_name + + for i in range(random.randint(2,6)): + point = find_location(True, cp.position, theater, 1000, 2800, []) + + if point is None: + print("Couldn't find point for {}".format(cp)) + continue + + group_id = group_id + 1 + + g = TheaterGroundObject() + g.group_id = group_id + g.object_id = 0 + g.cp_id = cp.id + g.airbase_group = True + g.dcs_identifier = "AA" + g.heading = 0 + g.position = Point(point.x, point.y) + + if i == 0: + group = generate_armor_group(faction, game, g) + elif i == 1 and random.randint(0,1) == 0: + group = generate_anti_air_group(game, cp, g, faction) + elif random.randint(0, 2) == 1: + group = generate_shorad_group(game, cp, g, faction) + else: + group = generate_armor_group(faction, game, g) + + g.groups = [] + if group is not None: + g.groups.append(group) + cp.ground_objects.append(g) + + print("---------------------------") + print("CP Generation : " + cp.name) + for ground_object in cp.ground_objects: + print(ground_object.groups) + + def find_location(on_ground, near, theater, min, max, others) -> typing.Optional[Point]: """ Find a valid ground object location @@ -115,19 +160,18 @@ def generate_cp_ground_points(cp: ControlPoint, theater, game, group_id, templat if cp.is_global: return False - amount = random.randrange(1, 11) + amount = random.randrange(1, 7) for i in range(0, amount): available_categories = list(templates) if i >= amount - 1: tpl_category = "aa" else: - if random.randint(0, 1) == 1: - tpl_category = random.choice(available_categories) - else: + if random.randint(0, 2) == 0: tpl_category = "aa" + else: + tpl_category = random.choice(available_categories) tpl = random.choice(list(templates[tpl_category].values())) - point = find_location(tpl_category != "oil", cp.position, theater, 10000, 40000, cp.ground_objects) if point is None: @@ -145,17 +189,22 @@ def generate_cp_ground_points(cp: ControlPoint, theater, game, group_id, templat g.group_id = group_id g.object_id = object_id g.cp_id = cp.id + g.airbase_gorup = False g.dcs_identifier = object["type"] g.heading = object["heading"] g.position = Point(point.x + object["offset"].x, point.y + object["offset"].y) + if g.dcs_identifier == "AA": if cp.captured: faction = game.player_name else: faction = game.enemy_name - generate_anti_air_group(game, cp, g, faction) + g.groups = [] + group = generate_anti_air_group(game, cp, g, faction) + if group is not None: + g.groups.append(group) cp.ground_objects.append(g) - return group_id \ No newline at end of file + return group_id diff --git a/theater/theatergroundobject.py b/theater/theatergroundobject.py index b7ad4b6a..5b53454c 100644 --- a/theater/theatergroundobject.py +++ b/theater/theatergroundobject.py @@ -51,6 +51,7 @@ class TheaterGroundObject: dcs_identifier = None # type: str is_dead = False + airbase_group = False heading = 0 position = None # type: Point