diff --git a/game/data/building_data.py b/game/data/building_data.py new file mode 100644 index 00000000..9d7d5b65 --- /dev/null +++ b/game/data/building_data.py @@ -0,0 +1,16 @@ +import inspect +import dcs + +DEFAULT_AVAILABLE_BUILDINGS = ['fuel', 'ammo', 'comms', 'oil', 'ware', 'farp', 'fob', 'power', 'factory', 'derrick', 'aa'] + +WW2_GERMANY_BUILDINGS = ['fuel', 'factory', 'ww2bunker', 'ww2bunker', 'ww2bunker', 'allycamp', 'allycamp', 'aa'] +WW2_ALLIES_BUILDINGS = ['fuel', 'allycamp', 'allycamp', 'allycamp', 'allycamp', 'allycamp', 'aa'] + +FORTIFICATION_BUILDINGS = ['Siegfried Line', 'Concertina Wire', 'Czech hedgehogs 1', 'Czech hedgehogs 2', + 'Dragonteeth 1', 'Dragonteeth 2', 'Dragonteeth 3', 'Dragonteeth 4', 'Dragonteeth 5', + 'Haystack 1', 'Haystack 2', 'Haystack 3', 'Haystack 4', 'Hemmkurvenvenhindernis', + 'Log posts 1', 'Log posts 2', 'Log posts 3', 'Log ramps 1', 'Log ramps 2', 'Log ramps 3', + 'Belgian Gate', 'Container white'] + +FORTIFICATION_UNITS = [c for c in vars(dcs.vehicles.Fortification).values() if inspect.isclass(c)] +FORTIFICATION_UNITS_ID = [c.id for c in vars(dcs.vehicles.Fortification).values() if inspect.isclass(c)] \ No newline at end of file diff --git a/game/factions/germany_1944.py b/game/factions/germany_1944.py index c93f7699..9549f5fe 100644 --- a/game/factions/germany_1944.py +++ b/game/factions/germany_1944.py @@ -1,6 +1,8 @@ from dcs.planes import * from dcs.vehicles import * +from game.data.building_data import WW2_GERMANY_BUILDINGS + Germany_1944 = { "country": "Third Reich", "side": "red", @@ -32,5 +34,9 @@ Germany_1944 = { ], "shorad":[ AirDefence.AAA_8_8cm_Flak_36, - ] + ], + "objects": WW2_GERMANY_BUILDINGS, + "doctrine": { + # TODO + } } \ No newline at end of file diff --git a/game/factions/usa_1944.py b/game/factions/usa_1944.py index 192dd748..043041ce 100644 --- a/game/factions/usa_1944.py +++ b/game/factions/usa_1944.py @@ -2,6 +2,8 @@ from dcs.planes import * from dcs.ships import * from dcs.vehicles import * +from game.data.building_data import WW2_ALLIES_BUILDINGS + USA_1944 = { "country": "USA", "side": "blue", @@ -36,5 +38,5 @@ USA_1944 = { AirDefence.AAA_Bofors_40mm, ], "shorad":[ AirDefence.AAA_Bofors_40mm, - ] + ], "objects": WW2_ALLIES_BUILDINGS } \ No newline at end of file diff --git a/gen/flights/ai_flight_planner.py b/gen/flights/ai_flight_planner.py index 05557af9..739a895c 100644 --- a/gen/flights/ai_flight_planner.py +++ b/gen/flights/ai_flight_planner.py @@ -460,11 +460,11 @@ class FlightPlanner: orbit0p = loc.position.point_from_heading(hdg - 90, radius) orbit1p = loc.position.point_from_heading(hdg + 90, radius) else: - loc = for_cp.position.point_from_heading(random.randint(0, 360),random.randint(nm_to_meter(10), nm_to_meter(40))) - hdg = for_cp.position.heading_between_point(loc.position) + loc = for_cp.position.point_from_heading(random.randint(0, 360), random.randint(nm_to_meter(10), nm_to_meter(40))) + hdg = for_cp.position.heading_between_point(loc) radius = nm_to_meter(random.randint(15, 40)) - orbit0p = loc.position.point_from_heading(hdg - 90, radius) - orbit1p = loc.position.point_from_heading(hdg + 90, radius) + orbit0p = loc.point_from_heading(hdg - 90, radius) + orbit1p = loc.point_from_heading(hdg + 90, radius) # Create points ascend = self.generate_ascend_point(flight.from_cp) diff --git a/gen/groundobjectsgen.py b/gen/groundobjectsgen.py index e572fb6b..46a514e6 100644 --- a/gen/groundobjectsgen.py +++ b/gen/groundobjectsgen.py @@ -1,6 +1,7 @@ import logging from game import db +from game.data.building_data import FORTIFICATION_UNITS_ID, FORTIFICATION_UNITS from game.db import unit_type_from_name from .conflictgen import * from .naming import * @@ -50,9 +51,6 @@ class GroundObjectsGenerator: else: cp = self.conflict.from_cp - consumed_farps = set() - - for cp in self.game.theater.controlpoints: if cp.captured: @@ -113,25 +111,42 @@ class GroundObjectsGenerator: sg.points[0].tasks.append(ActivateICLSCommand(cp.icls, unit_id=sg.units[0].id)) else: + static_type = None if ground_object.dcs_identifier in warehouse_map: static_type = warehouse_map[ground_object.dcs_identifier] - else: + elif ground_object.dcs_identifier in fortification_map: static_type = fortification_map[ground_object.dcs_identifier] - - if not static_type: + elif ground_object.dcs_identifier in FORTIFICATION_UNITS_ID: + for f in FORTIFICATION_UNITS: + if f.id == ground_object.dcs_identifier: + unit_type = f + break + else: print("Didn't find {} in static _map(s)!".format(ground_object.dcs_identifier)) continue - group = self.m.static_group( - country=side, - name=ground_object.string_identifier, - _type=static_type, - position=ground_object.position, - heading=ground_object.heading, - dead=ground_object.is_dead, - ) + if static_type is None: + if not ground_object.is_dead: + group = self.m.vehicle_group( + country=side, + name=ground_object.string_identifier, + _type=unit_type, + position=ground_object.position, + heading=ground_object.heading, + ) + logging.info("generated {}object identifier {} with mission id {}".format( + "dead " if ground_object.is_dead else "", group.name, group.id)) + else: + group = self.m.static_group( + country=side, + name=ground_object.string_identifier, + _type=static_type, + position=ground_object.position, + heading=ground_object.heading, + dead=ground_object.is_dead, + ) - logging.info("generated {}object identifier {} with mission id {}".format("dead " if ground_object.is_dead else "", group.name, group.id)) + logging.info("generated {}object identifier {} with mission id {}".format("dead " if ground_object.is_dead else "", group.name, group.id)) def farp_aa(mission_obj, country, name, position: mapping.Point): diff --git a/qt_ui/widgets/map/QLiberationMap.py b/qt_ui/widgets/map/QLiberationMap.py index 59d74bbb..e2e4faf8 100644 --- a/qt_ui/widgets/map/QLiberationMap.py +++ b/qt_ui/widgets/map/QLiberationMap.py @@ -41,6 +41,7 @@ class QLiberationMap(QGraphicsView): self.setMinimumSize(800,600) self.setMaximumHeight(2160) self._zoom = 0 + self.factor = 1 self.init_scene() self.connectSignals() self.setGame(game) @@ -222,6 +223,7 @@ class QLiberationMap(QGraphicsView): else: self._zoom = -5 + def _transform_point(self, p: Point, treshold=30) -> (int, int): point_a = list(self.game.theater.reference_points.keys())[0] point_a_img = self.game.theater.reference_points[point_a] diff --git a/qt_ui/widgets/map/QMapGroundObject.py b/qt_ui/widgets/map/QMapGroundObject.py index 4e627bd5..c675d20f 100644 --- a/qt_ui/widgets/map/QMapGroundObject.py +++ b/qt_ui/widgets/map/QMapGroundObject.py @@ -17,7 +17,7 @@ class QMapGroundObject(QGraphicsRectItem): self.setAcceptHoverEvents(True) self.setZValue(2) self.buildings = buildings - #self.setFlag(QGraphicsItem.ItemIgnoresTransformations, True) + self.setFlag(QGraphicsItem.ItemIgnoresTransformations, False) if len(self.model.groups) > 0: units = {} diff --git a/resources/groundobject_templates.p b/resources/groundobject_templates.p index 5e409190..eb39274b 100644 Binary files a/resources/groundobject_templates.p and b/resources/groundobject_templates.p differ diff --git a/resources/tools/generate_groundobject_templates.py b/resources/tools/generate_groundobject_templates.py index 78f2cd3b..fce50a0f 100644 --- a/resources/tools/generate_groundobject_templates.py +++ b/resources/tools/generate_groundobject_templates.py @@ -13,7 +13,7 @@ def load_templates(): groups = {} # type: typing.Dict[str, typing.Dict[int, typing.List[Static]]] - for static_group in temp_mis.country("USA").static_group: + for static_group in temp_mis.country("USA").static_group + temp_mis.country("USAF Aggressors").static_group: for static in static_group.units: static_name = str(static.name).split()[0] tpl_name, tpl_idx = static_name[:-1], int(static_name[-1]) diff --git a/resources/tools/generate_groundobjectsmap.py b/resources/tools/generate_groundobjectsmap.py index a7962720..78c5cf74 100644 --- a/resources/tools/generate_groundobjectsmap.py +++ b/resources/tools/generate_groundobjectsmap.py @@ -1,19 +1,15 @@ import pickle -import typing -from dcs.mission import Mission -from dcs.mapping import Point -from dcs.terrain import * -from dcs.unitgroup import VehicleGroup, StaticGroup from dcs import vehicles +from dcs.mapping import Point +from dcs.mission import Mission +from dcs.terrain import * from dcs.unit import * -from dcs.statics import warehouse_map, fortification_map -from game import db from gen.groundobjectsgen import TheaterGroundObject from theater.caucasus import CaucasusTheater -from theater.persiangulf import PersianGulfTheater from theater.nevada import NevadaTheater +from theater.persiangulf import PersianGulfTheater m = Mission() m.load_file("resources/tools/cau_groundobjects.miz") diff --git a/resources/tools/groundobject_templates.miz b/resources/tools/groundobject_templates.miz index a6eb0bbd..10ddade8 100644 Binary files a/resources/tools/groundobject_templates.miz and b/resources/tools/groundobject_templates.miz differ diff --git a/resources/ui/ground_assets/allycamp.png b/resources/ui/ground_assets/allycamp.png new file mode 100644 index 00000000..72ea6ef1 Binary files /dev/null and b/resources/ui/ground_assets/allycamp.png differ diff --git a/resources/ui/ground_assets/allycamp_blue.png b/resources/ui/ground_assets/allycamp_blue.png new file mode 100644 index 00000000..fc146c24 Binary files /dev/null and b/resources/ui/ground_assets/allycamp_blue.png differ diff --git a/resources/ui/ground_assets/derrick.png b/resources/ui/ground_assets/derrick.png new file mode 100644 index 00000000..b9d21808 Binary files /dev/null and b/resources/ui/ground_assets/derrick.png differ diff --git a/resources/ui/ground_assets/derrick_blue.png b/resources/ui/ground_assets/derrick_blue.png new file mode 100644 index 00000000..f8de3263 Binary files /dev/null and b/resources/ui/ground_assets/derrick_blue.png differ diff --git a/resources/ui/ground_assets/village.png b/resources/ui/ground_assets/village.png new file mode 100644 index 00000000..bfb83f53 Binary files /dev/null and b/resources/ui/ground_assets/village.png differ diff --git a/resources/ui/ground_assets/village_blue.png b/resources/ui/ground_assets/village_blue.png new file mode 100644 index 00000000..7adfc845 Binary files /dev/null and b/resources/ui/ground_assets/village_blue.png differ diff --git a/resources/ui/ground_assets/warehouse.png b/resources/ui/ground_assets/ware.png similarity index 100% rename from resources/ui/ground_assets/warehouse.png rename to resources/ui/ground_assets/ware.png diff --git a/resources/ui/ground_assets/warehouse_blue.png b/resources/ui/ground_assets/ware_blue.png similarity index 100% rename from resources/ui/ground_assets/warehouse_blue.png rename to resources/ui/ground_assets/ware_blue.png diff --git a/resources/ui/ground_assets/ww2bunker.png b/resources/ui/ground_assets/ww2bunker.png new file mode 100644 index 00000000..32019d19 Binary files /dev/null and b/resources/ui/ground_assets/ww2bunker.png differ diff --git a/resources/ui/ground_assets/ww2bunker_blue.png b/resources/ui/ground_assets/ww2bunker_blue.png new file mode 100644 index 00000000..cfb28c54 Binary files /dev/null and b/resources/ui/ground_assets/ww2bunker_blue.png differ diff --git a/theater/start_generator.py b/theater/start_generator.py index 28910331..824650c4 100644 --- a/theater/start_generator.py +++ b/theater/start_generator.py @@ -4,6 +4,7 @@ import random import typing import logging +from game.data.building_data import DEFAULT_AVAILABLE_BUILDINGS from gen import namegen from gen.defenses.armor_group_generator import generate_armor_group from gen.fleet.ship_group_generator import generate_carrier_group, generate_lha_group @@ -74,7 +75,7 @@ def generate_groundobjects(theater: ConflictTheater, game): if cp.cptype == ControlPointType.AIRCRAFT_CARRIER_GROUP: # Create ground object group group_id = group_id + 1 - g = TheaterGroundObject() + g = TheaterGroundObject("CARRIER") g.group_id = group_id g.object_id = 0 g.cp_id = cp.id @@ -94,7 +95,7 @@ def generate_groundobjects(theater: ConflictTheater, game): elif cp.cptype == ControlPointType.LHA_GROUP: # Create ground object group group_id = group_id + 1 - g = TheaterGroundObject() + g = TheaterGroundObject("LHA") g.group_id = group_id g.object_id = 0 g.cp_id = cp.id @@ -125,7 +126,7 @@ def generate_groundobjects(theater: ConflictTheater, game): group_id = group_id + 1 - g = TheaterGroundObject() + g = TheaterGroundObject("aa") g.group_id = group_id g.object_id = 0 g.cp_id = cp.id @@ -235,10 +236,22 @@ def generate_cp_ground_points(cp: ControlPoint, theater, game, group_id, templat if cp.is_global: return False + if cp.captured: + faction = game.player_name + else: + faction = game.enemy_name + faction_data = db.FACTIONS[faction] + + available_categories = DEFAULT_AVAILABLE_BUILDINGS + if "objects" in faction_data.keys(): + available_categories = faction_data["objects"] + + if len(available_categories) == 0: + return False + amount = random.randrange(3, 8) for i in range(0, amount): - available_categories = list(templates) obj_name = namegen.random_objective_name() if i >= amount - 1: @@ -264,7 +277,7 @@ def generate_cp_ground_points(cp: ControlPoint, theater, game, group_id, templat for object in tpl: object_id += 1 - g = TheaterGroundObject() + g = TheaterGroundObject(tpl_category) g.group_id = group_id g.object_id = object_id g.cp_id = cp.id @@ -276,10 +289,6 @@ def generate_cp_ground_points(cp: ControlPoint, theater, game, group_id, templat 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 g.groups = [] group = generate_anti_air_group(game, cp, g, faction) if group is not None: diff --git a/theater/theatergroundobject.py b/theater/theatergroundobject.py index 05d0aa72..51c54e2c 100644 --- a/theater/theatergroundobject.py +++ b/theater/theatergroundobject.py @@ -1,19 +1,20 @@ -import typing - from dcs.mapping import Point -from dcs.statics import * NAME_BY_CATEGORY = { "power": "Power plant", "ammo": "Ammo depot", "fuel": "Fuel depot", "aa": "AA Defense Site", - "warehouse": "Warehouse", + "ware": "Warehouse", "farp": "FARP", "fob": "FOB", "factory": "Factory", "comms": "Comms. tower", - "oil": "Oil platform" + "oil": "Oil platform", + "derrick": "Derrick", + "ww2bunker": "Bunker", + "village": "Village", + "allycamp": "Camp" } ABBREV_NAME = { @@ -21,22 +22,28 @@ ABBREV_NAME = { "ammo": "AMMO", "fuel": "FUEL", "aa": "AA", - "warehouse": "WARE", + "ware": "WARE", "farp": "FARP", "fob": "FOB", "factory": "FACTORY", "comms": "COMMST", - "oil": "OILP" + "oil": "OILP", + "derrick": "DERK", + "ww2bunker": "BUNK", + "village": "VLG", + "allycamp": "CMP", } CATEGORY_MAP = { + # Special cases "CARRIER": ["CARRIER"], "LHA": ["LHA"], "aa": ["AA"], + # Buildings "power": ["Workshop A", "Electric power box", "Garage small A", "Farm B", "Repair workshop", "Garage B"], - "warehouse": ["Warehouse", "Hangar A"], + "ware": ["Warehouse", "Hangar A"], "fuel": ["Tank", "Tank 2", "Tank 3", "Fuel tank"], "ammo": [".Ammunition depot", "Hangar B"], "farp": ["FARP Tent", "FARP Ammo Dump Coating", "FARP Fuel Depot", "FARP Command Post", "FARP CP Blindage"], @@ -45,6 +52,9 @@ CATEGORY_MAP = { "comms": ["TV tower", "Comms tower M"], "oil": ["Oil platform"], "derrick": ["Oil derrick", "Pump station", "Subsidiary structure 2"], + "ww2bunker": ["Siegfried Line", "Fire Control Bunker", "SK_C_28_naval_gun", "Concertina Wire", "Czech hedgehogs 1"], + "village": ["Small house 1B", "Small House 1A", "Small warehouse 1"], + "allycamp": [], } @@ -60,12 +70,8 @@ class TheaterGroundObject: groups = [] obj_name = "" - @property - def category(self) -> str: - for k, v in CATEGORY_MAP.items(): - if self.dcs_identifier in v: - return k - assert False, "Identifier not found in mapping: {}".format(self.dcs_identifier) + def __init__(self, category: str): + self.category = category @property def string_identifier(self):