update to ground objects parser; waypoints in briefings & general briefings update; minor fixes

This commit is contained in:
Vasyl Horbachenko
2018-09-13 05:09:57 +03:00
parent 03fc17fae6
commit edf9efddf9
18 changed files with 96 additions and 40 deletions

Binary file not shown.

View File

@@ -3,20 +3,41 @@ import typing
from dcs.mission import Mission
from dcs.mapping import Point
from dcs.terrain import *
from dcs.unitgroup import VehicleGroup, StaticGroup
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("./cau_groundobjects.miz")
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 parse_name(name: str) -> int:
first_part = name.split()[0].split("|")
return int(first_part[0]) if len(first_part) == 1 else int(first_part[1])
def closest_cp(location: Point) -> (int, float):
global theater
min_distance, min_cp = None, None
for cp in theater.controlpoints:
if not min_distance or location.distance_to_point(cp.position) < min_distance:
min_distance = location.distance_to_point(cp.position)
min_cp = cp.id
assert min_cp is not None
return min_cp
if __name__ == "__main__":
@@ -27,11 +48,6 @@ if __name__ == "__main__":
theater_object = TheaterGroundObject()
theater_object.object_id = len(theater_objects) + 1
try:
theater_object.cp_id = parse_name(str(unit.name))
except Exception as e:
theater_object.cp_id = parse_name(str(group.name))
theater_object.position = unit.position
theater_object.heading = unit.heading
@@ -40,15 +56,7 @@ if __name__ == "__main__":
else:
theater_object.dcs_identifier = unit.type
airport_distance = m.terrain.airport_by_id(theater_object.cp_id).position.distance_to_point(theater_object.position)
if airport_distance > 150000:
print("Object {} {} is placed {}m from airport {}!".format(theater_object.dcs_identifier,
group.name,
airport_distance,
m.terrain.airport_by_id(theater_object.cp_id)))
assert theater_object.dcs_identifier
assert theater_object.cp_id
assert theater_object.object_id
theater_objects.append(theater_object)
@@ -61,11 +69,15 @@ if __name__ == "__main__":
continue
elif object_a.group_id:
object_b.group_id = object_a.group_id
object_b.cp_id = object_a.cp_id
elif object_b.group_id:
object_a.group_id = object_b.group_id
object_a.cp_id = object_b.cp_id
else:
object_a.group_id = group_ids
object_b.group_id = group_ids
object_a.cp_id = closest_cp(object_a.position)
object_b.cp_id = object_a.cp_id
group_ids += 1
assert object_a.cp_id == object_b.cp_id, "Object {} and {} are placed in group with different airports!".format(object_a.string_identifier, object_b.string_identifier)
@@ -73,15 +85,23 @@ if __name__ == "__main__":
for a in theater_objects:
if not a.group_id:
a.group_id = group_ids
a.cp_id = closest_cp(a.position)
group_ids += 1
print("Total {} objects".format(len(theater_objects)))
with open("../cau_groundobjects.p", "wb") as f:
with open("resources/cau_groundobjects.p", "wb") as f:
result = {}
for theater_object in theater_objects:
assert theater_object.cp_id
assert theater_object.group_id
assert theater_object.object_id
if theater_object.cp_id not in result:
result[theater_object.cp_id] = []
result[theater_object.cp_id].append(theater_object)
print("Total {} objects".format(len(theater_objects)))
for cp_id, objects in result.items():
print("{}: total {} objects".format(m.terrain.airport_by_id(cp_id), len(objects)))
pickle.dump(result, f)