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 dcs import Point
|
||||
from dcs.triggers import TriggerZoneCircular
|
||||
|
||||
from game.theater.theatergroundobject import NAME_BY_CATEGORY
|
||||
@ -18,60 +19,65 @@ class SceneryGroup:
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
zone_def: TriggerZoneCircular,
|
||||
zones: Iterable[TriggerZoneCircular],
|
||||
group_zone: TriggerZoneCircular,
|
||||
target_zones: Iterable[TriggerZoneCircular],
|
||||
category: str,
|
||||
) -> None:
|
||||
|
||||
self.zone_def = zone_def
|
||||
self.zones = zones
|
||||
self.position = zone_def.position
|
||||
self.group_zone = group_zone
|
||||
self.target_zones = target_zones
|
||||
self.centroid = group_zone.position
|
||||
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
|
||||
def from_trigger_zones(
|
||||
trigger_zones: Iterable[TriggerZoneCircular],
|
||||
) -> List[SceneryGroup]:
|
||||
"""Define scenery objectives based on their encompassing blue/red circle."""
|
||||
zone_definitions = []
|
||||
white_zones = []
|
||||
group_zones = []
|
||||
target_zones = []
|
||||
|
||||
scenery_groups = []
|
||||
|
||||
# Aggregate trigger zones into different groups based on color.
|
||||
for zone in trigger_zones:
|
||||
if SceneryGroup.is_blue(zone):
|
||||
zone_definitions.append(zone)
|
||||
if SceneryGroup.is_white(zone):
|
||||
white_zones.append(zone)
|
||||
if SceneryGroup.is_group_zone(zone):
|
||||
group_zones.append(zone)
|
||||
if SceneryGroup.is_target_zone(zone):
|
||||
target_zones.append(zone)
|
||||
|
||||
# For each objective definition.
|
||||
for zone_def in zone_definitions:
|
||||
for group_zone in group_zones:
|
||||
|
||||
zone_def_radius = zone_def.radius
|
||||
zone_def_position = zone_def.position
|
||||
zone_def_name = zone_def.name
|
||||
zone_def_radius = group_zone.radius
|
||||
zone_def_position = group_zone.position
|
||||
zone_def_name = group_zone.name
|
||||
|
||||
if len(zone_def.properties) == 0:
|
||||
if len(group_zone.properties) == 0:
|
||||
raise SceneryGroupError(
|
||||
"Undefined SceneryGroup category in TriggerZone: " + zone_def_name
|
||||
)
|
||||
|
||||
# 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:
|
||||
valid_white_zones.append(zone)
|
||||
white_zones.remove(zone)
|
||||
valid_target_zones.append(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(
|
||||
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(
|
||||
"No white triggerzones found in: " + zone_def_name
|
||||
)
|
||||
@ -86,11 +92,11 @@ class SceneryGroup:
|
||||
return scenery_groups
|
||||
|
||||
@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.
|
||||
return zone.color[1] == 0 and zone.color[2] == 0 and zone.color[3] == 1
|
||||
|
||||
@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.
|
||||
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(
|
||||
namegen.random_objective_name(),
|
||||
scenery.category,
|
||||
PresetLocation(scenery.zone_def.name, scenery.position),
|
||||
PresetLocation(scenery.group_zone.name, scenery.centroid),
|
||||
self.control_point,
|
||||
)
|
||||
ground_group = TheaterGroup(
|
||||
self.game.next_group_id(),
|
||||
scenery.zone_def.name,
|
||||
PointWithHeading.from_point(scenery.position, Heading.from_degrees(0)),
|
||||
scenery.group_zone.name,
|
||||
PointWithHeading.from_point(scenery.centroid, Heading.from_degrees(0)),
|
||||
[],
|
||||
g,
|
||||
)
|
||||
@ -396,7 +396,7 @@ class AirbaseGroundObjectGenerator(ControlPointGroundObjectGenerator):
|
||||
|
||||
g.groups.append(ground_group)
|
||||
# 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)
|
||||
scenery_unit = SceneryUnit(
|
||||
zone.id,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user