Started refactoring on ground objects. WW2 factions will have WW2 style buildings. Added ground objects templates for : "village", "ww2bunker", "allycamp"

This commit is contained in:
Khopa 2020-06-11 21:50:09 +02:00
parent 90d588353c
commit c708abafc8
23 changed files with 106 additions and 54 deletions

View File

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

View File

@ -1,6 +1,8 @@
from dcs.planes import * from dcs.planes import *
from dcs.vehicles import * from dcs.vehicles import *
from game.data.building_data import WW2_GERMANY_BUILDINGS
Germany_1944 = { Germany_1944 = {
"country": "Third Reich", "country": "Third Reich",
"side": "red", "side": "red",
@ -32,5 +34,9 @@ Germany_1944 = {
], ],
"shorad":[ "shorad":[
AirDefence.AAA_8_8cm_Flak_36, AirDefence.AAA_8_8cm_Flak_36,
] ],
"objects": WW2_GERMANY_BUILDINGS,
"doctrine": {
# TODO
}
} }

View File

@ -2,6 +2,8 @@ from dcs.planes import *
from dcs.ships import * from dcs.ships import *
from dcs.vehicles import * from dcs.vehicles import *
from game.data.building_data import WW2_ALLIES_BUILDINGS
USA_1944 = { USA_1944 = {
"country": "USA", "country": "USA",
"side": "blue", "side": "blue",
@ -36,5 +38,5 @@ USA_1944 = {
AirDefence.AAA_Bofors_40mm, AirDefence.AAA_Bofors_40mm,
], "shorad":[ ], "shorad":[
AirDefence.AAA_Bofors_40mm, AirDefence.AAA_Bofors_40mm,
] ], "objects": WW2_ALLIES_BUILDINGS
} }

View File

@ -461,10 +461,10 @@ class FlightPlanner:
orbit1p = loc.position.point_from_heading(hdg + 90, radius) orbit1p = loc.position.point_from_heading(hdg + 90, radius)
else: else:
loc = for_cp.position.point_from_heading(random.randint(0, 360), random.randint(nm_to_meter(10), nm_to_meter(40))) 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) hdg = for_cp.position.heading_between_point(loc)
radius = nm_to_meter(random.randint(15, 40)) radius = nm_to_meter(random.randint(15, 40))
orbit0p = loc.position.point_from_heading(hdg - 90, radius) orbit0p = loc.point_from_heading(hdg - 90, radius)
orbit1p = loc.position.point_from_heading(hdg + 90, radius) orbit1p = loc.point_from_heading(hdg + 90, radius)
# Create points # Create points
ascend = self.generate_ascend_point(flight.from_cp) ascend = self.generate_ascend_point(flight.from_cp)

View File

@ -1,6 +1,7 @@
import logging import logging
from game import db from game import db
from game.data.building_data import FORTIFICATION_UNITS_ID, FORTIFICATION_UNITS
from game.db import unit_type_from_name from game.db import unit_type_from_name
from .conflictgen import * from .conflictgen import *
from .naming import * from .naming import *
@ -50,9 +51,6 @@ class GroundObjectsGenerator:
else: else:
cp = self.conflict.from_cp cp = self.conflict.from_cp
consumed_farps = set()
for cp in self.game.theater.controlpoints: for cp in self.game.theater.controlpoints:
if cp.captured: if cp.captured:
@ -113,15 +111,32 @@ class GroundObjectsGenerator:
sg.points[0].tasks.append(ActivateICLSCommand(cp.icls, unit_id=sg.units[0].id)) sg.points[0].tasks.append(ActivateICLSCommand(cp.icls, unit_id=sg.units[0].id))
else: else:
static_type = None
if ground_object.dcs_identifier in warehouse_map: if ground_object.dcs_identifier in warehouse_map:
static_type = warehouse_map[ground_object.dcs_identifier] 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] static_type = fortification_map[ground_object.dcs_identifier]
elif ground_object.dcs_identifier in FORTIFICATION_UNITS_ID:
if not static_type: 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)) print("Didn't find {} in static _map(s)!".format(ground_object.dcs_identifier))
continue continue
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( group = self.m.static_group(
country=side, country=side,
name=ground_object.string_identifier, name=ground_object.string_identifier,

View File

@ -41,6 +41,7 @@ class QLiberationMap(QGraphicsView):
self.setMinimumSize(800,600) self.setMinimumSize(800,600)
self.setMaximumHeight(2160) self.setMaximumHeight(2160)
self._zoom = 0 self._zoom = 0
self.factor = 1
self.init_scene() self.init_scene()
self.connectSignals() self.connectSignals()
self.setGame(game) self.setGame(game)
@ -222,6 +223,7 @@ class QLiberationMap(QGraphicsView):
else: else:
self._zoom = -5 self._zoom = -5
def _transform_point(self, p: Point, treshold=30) -> (int, int): def _transform_point(self, p: Point, treshold=30) -> (int, int):
point_a = list(self.game.theater.reference_points.keys())[0] point_a = list(self.game.theater.reference_points.keys())[0]
point_a_img = self.game.theater.reference_points[point_a] point_a_img = self.game.theater.reference_points[point_a]

View File

@ -17,7 +17,7 @@ class QMapGroundObject(QGraphicsRectItem):
self.setAcceptHoverEvents(True) self.setAcceptHoverEvents(True)
self.setZValue(2) self.setZValue(2)
self.buildings = buildings self.buildings = buildings
#self.setFlag(QGraphicsItem.ItemIgnoresTransformations, True) self.setFlag(QGraphicsItem.ItemIgnoresTransformations, False)
if len(self.model.groups) > 0: if len(self.model.groups) > 0:
units = {} units = {}

Binary file not shown.

View File

@ -13,7 +13,7 @@ def load_templates():
groups = {} # type: typing.Dict[str, typing.Dict[int, typing.List[Static]]] 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: for static in static_group.units:
static_name = str(static.name).split()[0] static_name = str(static.name).split()[0]
tpl_name, tpl_idx = static_name[:-1], int(static_name[-1]) tpl_name, tpl_idx = static_name[:-1], int(static_name[-1])

View File

@ -1,19 +1,15 @@
import pickle 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 import vehicles
from dcs.mapping import Point
from dcs.mission import Mission
from dcs.terrain import *
from dcs.unit import * from dcs.unit import *
from dcs.statics import warehouse_map, fortification_map
from game import db
from gen.groundobjectsgen import TheaterGroundObject from gen.groundobjectsgen import TheaterGroundObject
from theater.caucasus import CaucasusTheater from theater.caucasus import CaucasusTheater
from theater.persiangulf import PersianGulfTheater
from theater.nevada import NevadaTheater from theater.nevada import NevadaTheater
from theater.persiangulf import PersianGulfTheater
m = Mission() m = Mission()
m.load_file("resources/tools/cau_groundobjects.miz") m.load_file("resources/tools/cau_groundobjects.miz")

Binary file not shown.

After

Width:  |  Height:  |  Size: 206 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 206 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 194 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 194 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 231 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 239 B

View File

Before

Width:  |  Height:  |  Size: 229 B

After

Width:  |  Height:  |  Size: 229 B

View File

Before

Width:  |  Height:  |  Size: 229 B

After

Width:  |  Height:  |  Size: 229 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 210 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 210 B

View File

@ -4,6 +4,7 @@ import random
import typing import typing
import logging import logging
from game.data.building_data import DEFAULT_AVAILABLE_BUILDINGS
from gen import namegen from gen import namegen
from gen.defenses.armor_group_generator import generate_armor_group from gen.defenses.armor_group_generator import generate_armor_group
from gen.fleet.ship_group_generator import generate_carrier_group, generate_lha_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: if cp.cptype == ControlPointType.AIRCRAFT_CARRIER_GROUP:
# Create ground object group # Create ground object group
group_id = group_id + 1 group_id = group_id + 1
g = TheaterGroundObject() g = TheaterGroundObject("CARRIER")
g.group_id = group_id g.group_id = group_id
g.object_id = 0 g.object_id = 0
g.cp_id = cp.id g.cp_id = cp.id
@ -94,7 +95,7 @@ def generate_groundobjects(theater: ConflictTheater, game):
elif cp.cptype == ControlPointType.LHA_GROUP: elif cp.cptype == ControlPointType.LHA_GROUP:
# Create ground object group # Create ground object group
group_id = group_id + 1 group_id = group_id + 1
g = TheaterGroundObject() g = TheaterGroundObject("LHA")
g.group_id = group_id g.group_id = group_id
g.object_id = 0 g.object_id = 0
g.cp_id = cp.id g.cp_id = cp.id
@ -125,7 +126,7 @@ def generate_groundobjects(theater: ConflictTheater, game):
group_id = group_id + 1 group_id = group_id + 1
g = TheaterGroundObject() g = TheaterGroundObject("aa")
g.group_id = group_id g.group_id = group_id
g.object_id = 0 g.object_id = 0
g.cp_id = cp.id 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: if cp.is_global:
return False 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) amount = random.randrange(3, 8)
for i in range(0, amount): for i in range(0, amount):
available_categories = list(templates)
obj_name = namegen.random_objective_name() obj_name = namegen.random_objective_name()
if i >= amount - 1: if i >= amount - 1:
@ -264,7 +277,7 @@ def generate_cp_ground_points(cp: ControlPoint, theater, game, group_id, templat
for object in tpl: for object in tpl:
object_id += 1 object_id += 1
g = TheaterGroundObject() g = TheaterGroundObject(tpl_category)
g.group_id = group_id g.group_id = group_id
g.object_id = object_id g.object_id = object_id
g.cp_id = cp.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) g.position = Point(point.x + object["offset"].x, point.y + object["offset"].y)
if g.dcs_identifier == "AA": if g.dcs_identifier == "AA":
if cp.captured:
faction = game.player_name
else:
faction = game.enemy_name
g.groups = [] g.groups = []
group = generate_anti_air_group(game, cp, g, faction) group = generate_anti_air_group(game, cp, g, faction)
if group is not None: if group is not None:

View File

@ -1,19 +1,20 @@
import typing
from dcs.mapping import Point from dcs.mapping import Point
from dcs.statics import *
NAME_BY_CATEGORY = { NAME_BY_CATEGORY = {
"power": "Power plant", "power": "Power plant",
"ammo": "Ammo depot", "ammo": "Ammo depot",
"fuel": "Fuel depot", "fuel": "Fuel depot",
"aa": "AA Defense Site", "aa": "AA Defense Site",
"warehouse": "Warehouse", "ware": "Warehouse",
"farp": "FARP", "farp": "FARP",
"fob": "FOB", "fob": "FOB",
"factory": "Factory", "factory": "Factory",
"comms": "Comms. tower", "comms": "Comms. tower",
"oil": "Oil platform" "oil": "Oil platform",
"derrick": "Derrick",
"ww2bunker": "Bunker",
"village": "Village",
"allycamp": "Camp"
} }
ABBREV_NAME = { ABBREV_NAME = {
@ -21,22 +22,28 @@ ABBREV_NAME = {
"ammo": "AMMO", "ammo": "AMMO",
"fuel": "FUEL", "fuel": "FUEL",
"aa": "AA", "aa": "AA",
"warehouse": "WARE", "ware": "WARE",
"farp": "FARP", "farp": "FARP",
"fob": "FOB", "fob": "FOB",
"factory": "FACTORY", "factory": "FACTORY",
"comms": "COMMST", "comms": "COMMST",
"oil": "OILP" "oil": "OILP",
"derrick": "DERK",
"ww2bunker": "BUNK",
"village": "VLG",
"allycamp": "CMP",
} }
CATEGORY_MAP = { CATEGORY_MAP = {
# Special cases # Special cases
"CARRIER": ["CARRIER"], "CARRIER": ["CARRIER"],
"LHA": ["LHA"], "LHA": ["LHA"],
"aa": ["AA"], "aa": ["AA"],
# Buildings # Buildings
"power": ["Workshop A", "Electric power box", "Garage small A", "Farm B", "Repair workshop", "Garage B"], "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"], "fuel": ["Tank", "Tank 2", "Tank 3", "Fuel tank"],
"ammo": [".Ammunition depot", "Hangar B"], "ammo": [".Ammunition depot", "Hangar B"],
"farp": ["FARP Tent", "FARP Ammo Dump Coating", "FARP Fuel Depot", "FARP Command Post", "FARP CP Blindage"], "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"], "comms": ["TV tower", "Comms tower M"],
"oil": ["Oil platform"], "oil": ["Oil platform"],
"derrick": ["Oil derrick", "Pump station", "Subsidiary structure 2"], "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 = [] groups = []
obj_name = "" obj_name = ""
@property def __init__(self, category: str):
def category(self) -> str: self.category = category
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)
@property @property
def string_identifier(self): def string_identifier(self):