def load_templates():
    temp_mis = Mission()
    temp_mis.load_file("resources/tools/groundobject_templates.miz")

    groups = {
    }  # type: typing.Dict[str, typing.Dict[int, typing.List[Static]]]

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

            groups[tpl_name] = groups.get(tpl_name, {})
            groups[tpl_name][tpl_idx] = groups[tpl_name].get(tpl_idx, [])
            groups[tpl_name][tpl_idx].append(static)

    tpls = {
        name: {idx: []
               for idx in groups[name].keys()}
        for name in groups.keys()
    }
    for category_name, category_groups in groups.items():
        for idx, static_groups in category_groups.items():
            dist = -1
            a, b = None, None
            for aa in static_groups:
                for bb in static_groups:
                    if aa.position.distance_to_point(bb.position) > dist:
                        dist = aa.position.distance_to_point(bb.position)
                        a = aa
                        b = bb

            center = a.position.point_from_heading(
                a.position.heading_between_point(b.position), dist / 2)
            for static in static_groups:
                tpls[category_name][idx].append({
                    "type":
                    static.type,
                    "offset":
                    Point(center.x - static.position.x,
                          center.y - static.position.y),
                    "heading":
                    static.heading,
                })

    tpls["aa"] = {0: [{"type": "AA", "offset": Point(0, 0), "heading": 0}]}
    return tpls
import pickle

from dcs.mission import Mission
from shapely import geometry

for terrain in ["cau", "nev", "syria", "channel", "normandy", "gulf"]:
    print("Terrain " + terrain)
    m = Mission()
    m.load_file("./{}_terrain.miz".format(terrain))

    inclusion_zones = []
    exclusion_zones = []
    seas_zones = []
    for plane_group in m.country("USA").plane_group:
        zone = [(x.position.x, x.position.y) for x in plane_group.points]

        if terrain == "cau" and inclusion_zones:
            # legacy
            exclusion_zones.append(geometry.Polygon(zone))
        else:
            if plane_group.units[0].type == "F-15C":
                exclusion_zones.append(geometry.Polygon(zone))
            else:
                inclusion_zones.append(geometry.Polygon(zone))

    for ship_group in m.country("USA").ship_group:
        zone = [(x.position.x, x.position.y) for x in ship_group.points]
        seas_zones.append(geometry.Polygon(zone))

    with open("../{}landmap.p".format(terrain), "wb") as f:
        print(len(inclusion_zones), len(exclusion_zones), len(seas_zones))
Beispiel #3
0
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.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

m = Mission()
m.load_file("resources/tools/cau_groundobjects.miz")

if isinstance(m.terrain, Caucasus):
    theater = CaucasusTheater(load_ground_objects=False)
elif isinstance(m.terrain, PersianGulf):
    theater = PersianGulfTheater(load_ground_objects=False)
elif isinstance(m.terrain, Nevada):
    theater = NevadaTheater(load_ground_objects=False)
else:
    assert False


def closest_cp(location: Point) -> (int, float):
    global theater
    min_distance, min_cp = None, None