mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Restrict transfers to connected bases.
https://github.com/Khopa/dcs_liberation/issues/824
This commit is contained in:
@@ -8,7 +8,7 @@ from abc import ABC, abstractmethod
|
||||
from dataclasses import dataclass, field
|
||||
from enum import Enum
|
||||
from functools import total_ordering
|
||||
from typing import Any, Dict, Iterator, List, Optional, TYPE_CHECKING, Type
|
||||
from typing import Any, Dict, Iterator, List, Optional, Set, TYPE_CHECKING, Type
|
||||
|
||||
from dcs.mapping import Point
|
||||
from dcs.ships import (
|
||||
@@ -292,6 +292,23 @@ class ControlPoint(MissionTarget, ABC):
|
||||
def is_global(self):
|
||||
return not self.connected_points
|
||||
|
||||
def transitive_connected_friendly_points(
|
||||
self, seen: Optional[Set[ControlPoint]] = None
|
||||
) -> List[ControlPoint]:
|
||||
if seen is None:
|
||||
seen = {self}
|
||||
|
||||
connected = []
|
||||
for cp in self.connected_points:
|
||||
if cp.captured != self.captured:
|
||||
continue
|
||||
if cp in seen:
|
||||
continue
|
||||
seen.add(cp)
|
||||
connected.append(cp)
|
||||
connected.extend(cp.transitive_connected_friendly_points(seen))
|
||||
return connected
|
||||
|
||||
@property
|
||||
def is_carrier(self):
|
||||
"""
|
||||
|
||||
23
game/theater/supplyroutes.py
Normal file
23
game/theater/supplyroutes.py
Normal file
@@ -0,0 +1,23 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Iterator, List, Optional
|
||||
|
||||
from game.theater.controlpoint import ControlPoint
|
||||
|
||||
|
||||
class SupplyRoute:
|
||||
def __init__(self, control_points: List[ControlPoint]) -> None:
|
||||
self.control_points = control_points
|
||||
|
||||
def __contains__(self, item: ControlPoint) -> bool:
|
||||
return item in self.control_points
|
||||
|
||||
def __iter__(self) -> Iterator[ControlPoint]:
|
||||
yield from self.control_points
|
||||
|
||||
@classmethod
|
||||
def for_control_point(cls, control_point: ControlPoint) -> Optional[SupplyRoute]:
|
||||
connected_friendly_points = control_point.transitive_connected_friendly_points()
|
||||
if not connected_friendly_points:
|
||||
return None
|
||||
return SupplyRoute([control_point] + connected_friendly_points)
|
||||
Reference in New Issue
Block a user