-
Notifications
You must be signed in to change notification settings - Fork 185
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add campaign support for ferry-only bases.
Fixes #3170.
- Loading branch information
Showing
12 changed files
with
256 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
from dcs import Point | ||
from dcs.terrain import Airport | ||
|
||
from game.campaignloader.controlpointconfig import ControlPointConfig | ||
from game.theater import ( | ||
Airfield, | ||
Carrier, | ||
ConflictTheater, | ||
ControlPoint, | ||
Fob, | ||
Lha, | ||
OffMapSpawn, | ||
) | ||
|
||
|
||
class ControlPointBuilder: | ||
def __init__( | ||
self, theater: ConflictTheater, configs: dict[str | int, ControlPointConfig] | ||
) -> None: | ||
self.theater = theater | ||
self.config = configs | ||
|
||
def create_airfield(self, airport: Airport) -> Airfield: | ||
cp = Airfield(airport, self.theater, starts_blue=airport.is_blue()) | ||
|
||
# Use the unlimited aircraft option to determine if an airfield should | ||
# be owned by the player when the campaign is "inverted". | ||
cp.captured_invert = airport.unlimited_aircrafts | ||
|
||
self._apply_config(airport.id, cp) | ||
return cp | ||
|
||
def create_fob( | ||
self, | ||
name: str, | ||
position: Point, | ||
theater: ConflictTheater, | ||
starts_blue: bool, | ||
captured_invert: bool, | ||
) -> Fob: | ||
cp = Fob(name, position, theater, starts_blue) | ||
cp.captured_invert = captured_invert | ||
self._apply_config(name, cp) | ||
return cp | ||
|
||
def create_carrier( | ||
self, | ||
name: str, | ||
position: Point, | ||
theater: ConflictTheater, | ||
starts_blue: bool, | ||
captured_invert: bool, | ||
) -> Carrier: | ||
cp = Carrier(name, position, theater, starts_blue) | ||
cp.captured_invert = captured_invert | ||
self._apply_config(name, cp) | ||
return cp | ||
|
||
def create_lha( | ||
self, | ||
name: str, | ||
position: Point, | ||
theater: ConflictTheater, | ||
starts_blue: bool, | ||
captured_invert: bool, | ||
) -> Lha: | ||
cp = Lha(name, position, theater, starts_blue) | ||
cp.captured_invert = captured_invert | ||
self._apply_config(name, cp) | ||
return cp | ||
|
||
def create_off_map( | ||
self, | ||
name: str, | ||
position: Point, | ||
theater: ConflictTheater, | ||
starts_blue: bool, | ||
captured_invert: bool, | ||
) -> OffMapSpawn: | ||
cp = OffMapSpawn(name, position, theater, starts_blue) | ||
cp.captured_invert = captured_invert | ||
self._apply_config(name, cp) | ||
return cp | ||
|
||
def _apply_config(self, cp_id: str | int, control_point: ControlPoint) -> None: | ||
config = self.config.get(cp_id) | ||
if config is None: | ||
return | ||
|
||
control_point.ferry_only = config.ferry_only |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from __future__ import annotations | ||
|
||
from collections.abc import Iterator | ||
from dataclasses import dataclass | ||
from typing import Any | ||
|
||
|
||
@dataclass(frozen=True) | ||
class ControlPointConfig: | ||
ferry_only: bool | ||
|
||
@staticmethod | ||
def from_data(data: dict[str, Any]) -> ControlPointConfig: | ||
return ControlPointConfig(ferry_only=data.get("ferry_only", False)) | ||
|
||
@staticmethod | ||
def iter_from_data( | ||
data: dict[str | int, Any] | ||
) -> Iterator[tuple[str | int, ControlPointConfig]]: | ||
for name_or_id, cp_data in data.items(): | ||
yield name_or_id, ControlPointConfig.from_data(cp_data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.