mirror of
https://github.com/dcs-liberation/dcs_liberation.git
synced 2025-11-10 14:22:26 +00:00
Rename some scenery group variables for clarity.
These were perfectly obvious to me when I reviewed them, but not so much months later when I need to make changes :)
This commit is contained in:
parent
60b92a5577
commit
83c084e476
@ -2,6 +2,7 @@ from __future__ import annotations
|
|||||||
|
|
||||||
from typing import Iterable, List
|
from typing import Iterable, List
|
||||||
|
|
||||||
|
from dcs import Point
|
||||||
from dcs.triggers import TriggerZoneCircular
|
from dcs.triggers import TriggerZoneCircular
|
||||||
|
|
||||||
from game.theater.theatergroundobject import NAME_BY_CATEGORY
|
from game.theater.theatergroundobject import NAME_BY_CATEGORY
|
||||||
@ -18,60 +19,65 @@ class SceneryGroup:
|
|||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
zone_def: TriggerZoneCircular,
|
group_zone: TriggerZoneCircular,
|
||||||
zones: Iterable[TriggerZoneCircular],
|
target_zones: Iterable[TriggerZoneCircular],
|
||||||
category: str,
|
category: str,
|
||||||
) -> None:
|
) -> None:
|
||||||
|
|
||||||
self.zone_def = zone_def
|
self.group_zone = group_zone
|
||||||
self.zones = zones
|
self.target_zones = target_zones
|
||||||
self.position = zone_def.position
|
self.centroid = group_zone.position
|
||||||
self.category = category
|
self.category = category
|
||||||
|
|
||||||
|
@property
|
||||||
|
def position(self) -> Point:
|
||||||
|
# TODO: Remove this property. It cannot have a useful answer for quad zones.
|
||||||
|
return self.centroid
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_trigger_zones(
|
def from_trigger_zones(
|
||||||
trigger_zones: Iterable[TriggerZoneCircular],
|
trigger_zones: Iterable[TriggerZoneCircular],
|
||||||
) -> List[SceneryGroup]:
|
) -> List[SceneryGroup]:
|
||||||
"""Define scenery objectives based on their encompassing blue/red circle."""
|
"""Define scenery objectives based on their encompassing blue/red circle."""
|
||||||
zone_definitions = []
|
group_zones = []
|
||||||
white_zones = []
|
target_zones = []
|
||||||
|
|
||||||
scenery_groups = []
|
scenery_groups = []
|
||||||
|
|
||||||
# Aggregate trigger zones into different groups based on color.
|
# Aggregate trigger zones into different groups based on color.
|
||||||
for zone in trigger_zones:
|
for zone in trigger_zones:
|
||||||
if SceneryGroup.is_blue(zone):
|
if SceneryGroup.is_group_zone(zone):
|
||||||
zone_definitions.append(zone)
|
group_zones.append(zone)
|
||||||
if SceneryGroup.is_white(zone):
|
if SceneryGroup.is_target_zone(zone):
|
||||||
white_zones.append(zone)
|
target_zones.append(zone)
|
||||||
|
|
||||||
# For each objective definition.
|
# For each objective definition.
|
||||||
for zone_def in zone_definitions:
|
for group_zone in group_zones:
|
||||||
|
|
||||||
zone_def_radius = zone_def.radius
|
zone_def_radius = group_zone.radius
|
||||||
zone_def_position = zone_def.position
|
zone_def_position = group_zone.position
|
||||||
zone_def_name = zone_def.name
|
zone_def_name = group_zone.name
|
||||||
|
|
||||||
if len(zone_def.properties) == 0:
|
if len(group_zone.properties) == 0:
|
||||||
raise SceneryGroupError(
|
raise SceneryGroupError(
|
||||||
"Undefined SceneryGroup category in TriggerZone: " + zone_def_name
|
"Undefined SceneryGroup category in TriggerZone: " + zone_def_name
|
||||||
)
|
)
|
||||||
|
|
||||||
# Arbitrary campaign design requirement: First property must define the category.
|
# Arbitrary campaign design requirement: First property must define the category.
|
||||||
zone_def_category = zone_def.properties[1].get("value").lower()
|
zone_def_category = group_zone.properties[1].get("value").lower()
|
||||||
|
|
||||||
valid_white_zones = []
|
valid_target_zones = []
|
||||||
|
|
||||||
for zone in list(white_zones):
|
for zone in list(target_zones):
|
||||||
if zone.position.distance_to_point(zone_def_position) < zone_def_radius:
|
if zone.position.distance_to_point(zone_def_position) < zone_def_radius:
|
||||||
valid_white_zones.append(zone)
|
valid_target_zones.append(zone)
|
||||||
white_zones.remove(zone)
|
target_zones.remove(zone)
|
||||||
|
|
||||||
if len(valid_white_zones) > 0 and zone_def_category in NAME_BY_CATEGORY:
|
if len(valid_target_zones) > 0 and zone_def_category in NAME_BY_CATEGORY:
|
||||||
scenery_groups.append(
|
scenery_groups.append(
|
||||||
SceneryGroup(zone_def, valid_white_zones, zone_def_category)
|
SceneryGroup(group_zone, valid_target_zones, zone_def_category)
|
||||||
)
|
)
|
||||||
elif len(valid_white_zones) == 0:
|
elif len(valid_target_zones) == 0:
|
||||||
raise SceneryGroupError(
|
raise SceneryGroupError(
|
||||||
"No white triggerzones found in: " + zone_def_name
|
"No white triggerzones found in: " + zone_def_name
|
||||||
)
|
)
|
||||||
@ -86,11 +92,11 @@ class SceneryGroup:
|
|||||||
return scenery_groups
|
return scenery_groups
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def is_blue(zone: TriggerZoneCircular) -> bool:
|
def is_group_zone(zone: TriggerZoneCircular) -> 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_target_zone(zone: TriggerZoneCircular) -> 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
|
||||||
|
|||||||
@ -380,13 +380,13 @@ class AirbaseGroundObjectGenerator(ControlPointGroundObjectGenerator):
|
|||||||
g = tgo_type(
|
g = tgo_type(
|
||||||
namegen.random_objective_name(),
|
namegen.random_objective_name(),
|
||||||
scenery.category,
|
scenery.category,
|
||||||
PresetLocation(scenery.zone_def.name, scenery.position),
|
PresetLocation(scenery.group_zone.name, scenery.centroid),
|
||||||
self.control_point,
|
self.control_point,
|
||||||
)
|
)
|
||||||
ground_group = TheaterGroup(
|
ground_group = TheaterGroup(
|
||||||
self.game.next_group_id(),
|
self.game.next_group_id(),
|
||||||
scenery.zone_def.name,
|
scenery.group_zone.name,
|
||||||
PointWithHeading.from_point(scenery.position, Heading.from_degrees(0)),
|
PointWithHeading.from_point(scenery.centroid, Heading.from_degrees(0)),
|
||||||
[],
|
[],
|
||||||
g,
|
g,
|
||||||
)
|
)
|
||||||
@ -396,7 +396,7 @@ class AirbaseGroundObjectGenerator(ControlPointGroundObjectGenerator):
|
|||||||
|
|
||||||
g.groups.append(ground_group)
|
g.groups.append(ground_group)
|
||||||
# Each nested trigger zone is a target/building/unit for an objective.
|
# Each nested trigger zone is a target/building/unit for an objective.
|
||||||
for zone in scenery.zones:
|
for zone in scenery.target_zones:
|
||||||
zone.name = escape_string_for_lua(zone.name)
|
zone.name = escape_string_for_lua(zone.name)
|
||||||
scenery_unit = SceneryUnit(
|
scenery_unit = SceneryUnit(
|
||||||
zone.id,
|
zone.id,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user