mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Don't skip QuadPoint trigger zones
Added code to deduce a radius given a QuadPoint trigger zone
This commit is contained in:
parent
429a397cc8
commit
3966e03ea5
@ -13,7 +13,6 @@ from dcs.planes import F_15C
|
|||||||
from dcs.ships import HandyWind, LHA_Tarawa, Stennis, USS_Arleigh_Burke_IIa
|
from dcs.ships import HandyWind, LHA_Tarawa, Stennis, USS_Arleigh_Burke_IIa
|
||||||
from dcs.statics import Fortification, Warehouse
|
from dcs.statics import Fortification, Warehouse
|
||||||
from dcs.terrain import Airport
|
from dcs.terrain import Airport
|
||||||
from dcs.triggers import TriggerZoneCircular
|
|
||||||
from dcs.unitgroup import PlaneGroup, ShipGroup, StaticGroup, VehicleGroup
|
from dcs.unitgroup import PlaneGroup, ShipGroup, StaticGroup, VehicleGroup
|
||||||
from dcs.vehicles import AirDefence, Armor, MissilesSS, Unarmed
|
from dcs.vehicles import AirDefence, Armor, MissilesSS, Unarmed
|
||||||
|
|
||||||
@ -240,11 +239,7 @@ class MizCampaignLoader:
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def scenery(self) -> List[SceneryGroup]:
|
def scenery(self) -> List[SceneryGroup]:
|
||||||
return SceneryGroup.from_trigger_zones(
|
return SceneryGroup.from_trigger_zones(self.mission.triggers._zones)
|
||||||
z
|
|
||||||
for z in self.mission.triggers._zones
|
|
||||||
if isinstance(z, TriggerZoneCircular)
|
|
||||||
)
|
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def control_points(self) -> dict[UUID, ControlPoint]:
|
def control_points(self) -> dict[UUID, ControlPoint]:
|
||||||
|
|||||||
@ -1,11 +1,27 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
from typing import Iterable, List
|
from typing import Iterable, List
|
||||||
|
|
||||||
from dcs.triggers import TriggerZoneCircular
|
from dcs.triggers import TriggerZone, TriggerZoneCircular, TriggerZoneQuadPoint
|
||||||
|
|
||||||
from game.theater.theatergroundobject import NAME_BY_CATEGORY
|
from game.theater.theatergroundobject import NAME_BY_CATEGORY
|
||||||
|
|
||||||
|
|
||||||
|
def _deduce_radius_from_quad(tz: TriggerZoneQuadPoint) -> float:
|
||||||
|
pos = tz.position
|
||||||
|
radius = 0.0
|
||||||
|
mids = []
|
||||||
|
for i in range(len(tz.verticies)):
|
||||||
|
for j in range(i, len(tz.verticies)):
|
||||||
|
if i is j:
|
||||||
|
continue
|
||||||
|
mids.append(tz.verticies[i].midpoint(tz.verticies[j]))
|
||||||
|
for point in mids:
|
||||||
|
dist = pos.distance_to_point(point)
|
||||||
|
if dist > radius:
|
||||||
|
radius = dist
|
||||||
|
return radius
|
||||||
|
|
||||||
|
|
||||||
class SceneryGroupError(RuntimeError):
|
class SceneryGroupError(RuntimeError):
|
||||||
"""Error for when there are insufficient conditions to create a SceneryGroup."""
|
"""Error for when there are insufficient conditions to create a SceneryGroup."""
|
||||||
|
|
||||||
@ -16,10 +32,7 @@ class SceneryGroup:
|
|||||||
"""Store information about a scenery objective."""
|
"""Store information about a scenery objective."""
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self, zone_def: TriggerZone, zones: Iterable[TriggerZone], category: str
|
||||||
zone_def: TriggerZoneCircular,
|
|
||||||
zones: Iterable[TriggerZoneCircular],
|
|
||||||
category: str,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
|
|
||||||
self.zone_def = zone_def
|
self.zone_def = zone_def
|
||||||
@ -28,9 +41,7 @@ class SceneryGroup:
|
|||||||
self.category = category
|
self.category = category
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_trigger_zones(
|
def from_trigger_zones(trigger_zones: Iterable[TriggerZone]) -> List[SceneryGroup]:
|
||||||
trigger_zones: Iterable[TriggerZoneCircular],
|
|
||||||
) -> List[SceneryGroup]:
|
|
||||||
"""Define scenery objectives based on their encompassing blue/red circle."""
|
"""Define scenery objectives based on their encompassing blue/red circle."""
|
||||||
zone_definitions = []
|
zone_definitions = []
|
||||||
white_zones = []
|
white_zones = []
|
||||||
@ -46,7 +57,13 @@ class SceneryGroup:
|
|||||||
|
|
||||||
# For each objective definition.
|
# For each objective definition.
|
||||||
for zone_def in zone_definitions:
|
for zone_def in zone_definitions:
|
||||||
zone_def_radius = zone_def.radius
|
if isinstance(zone_def, TriggerZoneCircular):
|
||||||
|
zone_def_radius = zone_def.radius
|
||||||
|
elif isinstance(zone_def, TriggerZoneQuadPoint):
|
||||||
|
zone_def_radius = _deduce_radius_from_quad(zone_def)
|
||||||
|
else:
|
||||||
|
raise RuntimeError(f"Invalid trigger-zone: {zone_def}")
|
||||||
|
print(zone_def_radius, zone_def.__dict__)
|
||||||
zone_def_position = zone_def.position
|
zone_def_position = zone_def.position
|
||||||
zone_def_name = zone_def.name
|
zone_def_name = zone_def.name
|
||||||
|
|
||||||
@ -84,11 +101,11 @@ class SceneryGroup:
|
|||||||
return scenery_groups
|
return scenery_groups
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def is_blue(zone: TriggerZoneCircular) -> bool:
|
def is_blue(zone: TriggerZone) -> bool:
|
||||||
# Blue in RGB is [0 Red], [0 Green], [1 Blue]. Ignore the fourth position: Transparency.
|
# Blue in RGB is [0 Red], [0 Green], [1 Blue]. Ignore the fourth position: Transparency.
|
||||||
return zone.color[1] == 0 and zone.color[2] == 0 and zone.color[3] == 1
|
return zone.color[1] == 0 and zone.color[2] == 0 and zone.color[3] == 1
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def is_white(zone: TriggerZoneCircular) -> bool:
|
def is_white(zone: TriggerZone) -> bool:
|
||||||
# White in RGB is [1 Red], [1 Green], [1 Blue]. Ignore the fourth position: Transparency.
|
# White in RGB is [1 Red], [1 Green], [1 Blue]. Ignore the fourth position: Transparency.
|
||||||
return zone.color[1] == 1 and zone.color[2] == 1 and zone.color[3] == 1
|
return zone.color[1] == 1 and zone.color[2] == 1 and zone.color[3] == 1
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user