mirror of
https://github.com/spencershepard/RotorOps.git
synced 2025-11-10 15:45:30 +00:00
..
This commit is contained in:
@@ -22,105 +22,131 @@ def convertMeterToNM(meters=int):
|
||||
|
||||
class ImportObjects:
|
||||
|
||||
def __init__(self, mizfile, ref_point=None, ref_heading=0):
|
||||
def __init__(self, mizfile, source_point=None, source_heading=0):
|
||||
logger.info("Importing objects from " + mizfile)
|
||||
self.source_mission = dcs.mission.Mission()
|
||||
self.source_mission.load_file(mizfile)
|
||||
self.ref_heading = ref_heading
|
||||
if ref_point:
|
||||
self.ref_point = ref_point
|
||||
self.source_heading = source_heading
|
||||
if source_point:
|
||||
self.source_point = source_point
|
||||
else:
|
||||
self.ref_point = dcs.Point(self.source_mission.terrain.bullseye_blue["x"], self.source_mission.terrain.bullseye_blue["y"])
|
||||
self.source_point = dcs.Point(self.source_mission.terrain.bullseye_blue["x"], self.source_mission.terrain.bullseye_blue["y"])
|
||||
|
||||
|
||||
def anchorByGroupName(self, group_name):
|
||||
group = self.source_mission.find_group(group_name)
|
||||
if group:
|
||||
self.ref_point = group.units[0].position
|
||||
self.ref_heading = group.units[0].heading
|
||||
self.source_point = group.units[0].position
|
||||
self.source_heading = group.units[0].heading
|
||||
else:
|
||||
logger.warning("Unable to find group for anchor.")
|
||||
|
||||
|
||||
def copyTo(self, mission, dest_point=None, dest_heading=0):
|
||||
def copyTo(self, mission, dest_name, dest_point=None, dest_heading=0):
|
||||
logger.info("Copying objects as " + dest_name)
|
||||
if not dest_point:
|
||||
dest_point = dcs.Point(mission.terrain.bullseye_blue["x"], mission.terrain.bullseye_blue["y"])
|
||||
|
||||
#iterate over group types first?
|
||||
for side in "red", "blue":
|
||||
coalition = self.source_mission.coalition.get(side)
|
||||
for country in coalition.countries:
|
||||
for country_name in coalition.countries:
|
||||
|
||||
group_types = [coalition.countries[country].static_group, coalition.countries[country].vehicle_group, coalition.countries[country].helicopter_group, coalition.countries[country].plane_group,
|
||||
coalition.countries[country].ship_group]
|
||||
group_types = [coalition.countries[country_name].static_group, coalition.countries[country_name].vehicle_group, coalition.countries[country_name].helicopter_group, coalition.countries[country_name].plane_group,
|
||||
coalition.countries[country_name].ship_group]
|
||||
|
||||
for index, group_type in enumerate(group_types):
|
||||
for group in group_type:
|
||||
self.groupToPoint(group, self.ref_point, dest_point, self.ref_heading, dest_heading)
|
||||
if index == 0:
|
||||
mission.country(country).add_static_group(group)
|
||||
elif index == 1:
|
||||
mission.country(country).add_vehicle_group(group)
|
||||
elif index == 2:
|
||||
#mission.country(country).add_helicopter_group(group)
|
||||
print("helicopter groups not available for import")
|
||||
self.groupToPoint(group, self.source_point, dest_point, self.source_heading, dest_heading)
|
||||
|
||||
|
||||
if index == 0: # Statics
|
||||
type_name = group.units[0].type
|
||||
type_maps = [dcs.statics.cargo_map, dcs.statics.warehouse_map, dcs.statics.groundobject_map, dcs.statics.fortification_map]
|
||||
classed = False
|
||||
for type_map in type_maps:
|
||||
if type_name in type_map:
|
||||
classed = True
|
||||
unit_type = type_map[type_name]
|
||||
ng = mission.static_group(mission.country(country_name),
|
||||
group.name,
|
||||
unit_type,
|
||||
group.units[0].position,
|
||||
group.units[0].heading,
|
||||
hidden=False)
|
||||
if not classed:
|
||||
print("No pydcs class for " + type_name)
|
||||
|
||||
|
||||
class temp(dcs.unittype.StaticType):
|
||||
id = group.units[0].type
|
||||
name = group.units[0].name
|
||||
shape_name = group.units[0].shape_name
|
||||
rate = group.units[0].rate
|
||||
|
||||
|
||||
ng = mission.static_group(mission.country(country_name),
|
||||
group.name,
|
||||
temp,
|
||||
group.units[0].position,
|
||||
group.units[0].heading,
|
||||
hidden=False)
|
||||
|
||||
elif index == 1: # Vehicles
|
||||
|
||||
for i, unit in enumerate(group.units):
|
||||
if i == 0:
|
||||
ng = mission.vehicle_group(mission.country(country_name),
|
||||
group.name,
|
||||
dcs.vehicles.vehicle_map[group.units[0].type],
|
||||
group.units[0].position,
|
||||
group.units[0].heading)
|
||||
|
||||
|
||||
else:
|
||||
|
||||
u = mission.vehicle(group.units[i].name, dcs.vehicles.vehicle_map[group.units[i].type])
|
||||
u.position = group.units[i].position
|
||||
u.heading = group.units[i].heading
|
||||
ng.add_unit(u)
|
||||
|
||||
mission.country(country_name).add_vehicle_group(ng)
|
||||
|
||||
|
||||
elif index == 2: # Helicopters
|
||||
|
||||
if group.units[0].skill == dcs.unit.Skill.Client or group.units[0].skill == dcs.unit.Skill.Player:
|
||||
|
||||
farp = mission.farp(mission.country(country_name), dest_name + " " + group.name + " Pad", group.units[0].position, hidden=True, dead=False,
|
||||
farp_type=dcs.unit.InvisibleFARP)
|
||||
|
||||
ng = mission.flight_group_from_unit(mission.country(country_name),
|
||||
dest_name + " " + group.name,
|
||||
dcs.helicopters.helicopter_map[group.units[0].type],
|
||||
farp,
|
||||
group_size=1)
|
||||
|
||||
ng.points[0].action = dcs.point.PointAction.FromGroundArea
|
||||
ng.points[0].type = "TakeOffGround"
|
||||
ng.units[0].heading = group.units[0].heading
|
||||
ng.units[0].skill = group.units[0].skill
|
||||
ng.units[0].livery_id = group.units[0].livery_id
|
||||
ng.units[0].pylons = group.units[0].pylons
|
||||
|
||||
elif index == 3:
|
||||
#mission.country(country).add_plane_group(group)
|
||||
print("plane groups not available for import")
|
||||
print("not yet avail")
|
||||
elif index == 4:
|
||||
mission.country(country).add_ship_group(group)
|
||||
|
||||
|
||||
#mission.country(country).add_ship_group(group)
|
||||
print("not yet avail")
|
||||
|
||||
|
||||
@staticmethod
|
||||
def groupToPoint(group, ref_point, dest_point, ref_heading=0, dest_heading=0):
|
||||
def groupToPoint(group, src_point, dest_point, src_heading=0, dest_heading=0):
|
||||
for unit in group.units:
|
||||
heading_to_unit = dcs.mapping.heading_between_points(ref_point.x, ref_point.y, unit.position.x,
|
||||
heading_to_unit = dcs.mapping.heading_between_points(src_point.x, src_point.y, unit.position.x,
|
||||
unit.position.y)
|
||||
new_heading_to_unit = dest_heading + heading_to_unit
|
||||
unit_distance = ref_point.distance_to_point(unit.position)
|
||||
unit_distance = src_point.distance_to_point(unit.position)
|
||||
unit.position = dest_point.point_from_heading(new_heading_to_unit, unit_distance)
|
||||
return group
|
||||
|
||||
|
||||
|
||||
# class extractUnits:
|
||||
#
|
||||
# @staticmethod
|
||||
# def toPoint(filename, group_type, dest_point, dest_heading=0, side="blue"):
|
||||
# print("Attempting to extract units from " + filename + " relative to 'HELO_FARP' initial point.")
|
||||
#
|
||||
# source_mission = dcs.mission.Mission()
|
||||
# source_mission.load_file(filename)
|
||||
#
|
||||
#
|
||||
# # country = source_mission.country('Combined Joint Task Forces Blue')
|
||||
# # country.find
|
||||
#
|
||||
# #group_types = []
|
||||
#
|
||||
# groups = []
|
||||
#
|
||||
# for country in source_mission.coalition.get(side).countries:
|
||||
#
|
||||
# ref_point = country.find_static_group("HELO_FARP").position #units position instead of group?
|
||||
# ref_heading = country.find_static_group("HELO_FARP").heading
|
||||
# group_types = [country.static_group, country.vehicle_group, country.helicopter_group, country.plane_group, country.ship_group]
|
||||
#
|
||||
# for group_type in group_types:
|
||||
# for group in group_type:
|
||||
# for unit in group.units:
|
||||
# x_rel = ref_point.x - unit.position.x
|
||||
# y_rel = ref_point.y - unit.position.y
|
||||
# #heading_rel = ref_heading - unit.heading # heading of unit relative to heading of the reference object
|
||||
# heading_to_unit = dcs.mapping.heading_between_points(ref_point.x, ref_point.y, unit.position.x, unit.position.y)
|
||||
# new_heading_to_unit = dest_heading + heading_to_unit
|
||||
# unit_distance = ref_point.distance_to_point(unit.position)
|
||||
# unit.position = dest_point.point_from_heading(new_heading_to_unit, unit_distance)
|
||||
#
|
||||
# # unit.position.x = x - x_rel
|
||||
# # unit.position.y = y - y_rel
|
||||
#
|
||||
# groups.append(group)
|
||||
# return groups
|
||||
|
||||
unit.heading = unit.heading + dest_heading
|
||||
return group
|
||||
Reference in New Issue
Block a user