Skip to content

Commit

Permalink
Merge branch 'develop' into frontline
Browse files Browse the repository at this point in the history
  • Loading branch information
walterroach committed Nov 21, 2020
2 parents 2b6227f + f8b2dbe commit edd02d9
Show file tree
Hide file tree
Showing 51 changed files with 413 additions and 305 deletions.
6 changes: 3 additions & 3 deletions game/event/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import logging
import math
from typing import Dict, List, Optional, Type, TYPE_CHECKING
from typing import Dict, List, Optional, TYPE_CHECKING, Type

from dcs.mapping import Point
from dcs.task import Task
Expand All @@ -11,12 +11,12 @@
from game import db, persistency
from game.debriefing import Debriefing
from game.infos.information import Information
from game.operation.operation import Operation
from game.theater import ControlPoint
from gen.ground_forces.combat_stance import CombatStance
from theater import ControlPoint

if TYPE_CHECKING:
from ..game import Game
from game.operation.operation import Operation

DIFFICULTY_LOG_BASE = 1.1
EVENT_DEPARTURE_MAX_DISTANCE = 340000
Expand Down
14 changes: 1 addition & 13 deletions game/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,6 @@ def budget_reward_amount(self):
def _budget_player(self):
self.budget += self.budget_reward_amount

def awacs_expense_commit(self):
self.budget -= AWACS_BUDGET_COST

def units_delivery_event(self, to_cp: ControlPoint) -> UnitsDeliveryEvent:
event = UnitsDeliveryEvent(attacker_name=self.player_name,
defender_name=self.player_name,
Expand All @@ -172,10 +169,6 @@ def units_delivery_event(self, to_cp: ControlPoint) -> UnitsDeliveryEvent:
self.events.append(event)
return event

def units_delivery_remove(self, event: Event):
if event in self.events:
self.events.remove(event)

def initiate_event(self, event: Event):
#assert event in self.events
logging.info("Generating {} (regular)".format(event))
Expand All @@ -202,12 +195,6 @@ def on_load(self) -> None:
LuaPluginManager.load_settings(self.settings)
ObjectiveDistanceCache.set_theater(self.theater)

# Save game compatibility.

# TODO: Remove in 2.3.
if not hasattr(self, "conditions"):
self.conditions = self.generate_conditions()

def pass_turn(self, no_action: bool = False) -> None:
logging.info("Pass turn")
self.informations.append(Information("End of turn #" + str(self.turn), "-" * 40, 0))
Expand Down Expand Up @@ -248,6 +235,7 @@ def initialize_turn(self) -> None:

self.aircraft_inventory.reset()
for cp in self.theater.controlpoints:
cp.pending_unit_deliveries = self.units_delivery_event(cp)
self.aircraft_inventory.set_from_control_point(cp)

# Plan flights & combat for next turn
Expand Down
26 changes: 15 additions & 11 deletions game/inventory.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
"""Inventory management APIs."""
from __future__ import annotations

from collections import defaultdict
from typing import Dict, Iterable, Iterator, Set, Tuple
from typing import Dict, Iterable, Iterator, Set, Tuple, TYPE_CHECKING

from dcs.unittype import UnitType
from dcs.unittype import FlyingType

from gen.flights.flight import Flight
from theater import ControlPoint

if TYPE_CHECKING:
from game.theater import ControlPoint


class ControlPointAircraftInventory:
"""Aircraft inventory for a single control point."""

def __init__(self, control_point: ControlPoint) -> None:
self.control_point = control_point
self.inventory: Dict[UnitType, int] = defaultdict(int)
self.inventory: Dict[FlyingType, int] = defaultdict(int)

def add_aircraft(self, aircraft: UnitType, count: int) -> None:
def add_aircraft(self, aircraft: FlyingType, count: int) -> None:
"""Adds aircraft to the inventory.
Args:
Expand All @@ -24,7 +28,7 @@ def add_aircraft(self, aircraft: UnitType, count: int) -> None:
"""
self.inventory[aircraft] += count

def remove_aircraft(self, aircraft: UnitType, count: int) -> None:
def remove_aircraft(self, aircraft: FlyingType, count: int) -> None:
"""Removes aircraft from the inventory.
Args:
Expand All @@ -43,7 +47,7 @@ def remove_aircraft(self, aircraft: UnitType, count: int) -> None:
)
self.inventory[aircraft] -= count

def available(self, aircraft: UnitType) -> int:
def available(self, aircraft: FlyingType) -> int:
"""Returns the number of available aircraft of the given type.
Args:
Expand All @@ -55,14 +59,14 @@ def available(self, aircraft: UnitType) -> int:
return 0

@property
def types_available(self) -> Iterator[UnitType]:
def types_available(self) -> Iterator[FlyingType]:
"""Iterates over all available aircraft types."""
for aircraft, count in self.inventory.items():
if count > 0:
yield aircraft

@property
def all_aircraft(self) -> Iterator[Tuple[UnitType, int]]:
def all_aircraft(self) -> Iterator[Tuple[FlyingType, int]]:
"""Iterates over all available aircraft types, including amounts."""
for aircraft, count in self.inventory.items():
if count > 0:
Expand Down Expand Up @@ -102,9 +106,9 @@ def for_control_point(
return self.inventories[control_point]

@property
def available_types_for_player(self) -> Iterator[UnitType]:
def available_types_for_player(self) -> Iterator[FlyingType]:
"""Iterates over all aircraft types available to the player."""
seen: Set[UnitType] = set()
seen: Set[FlyingType] = set()
for control_point, inventory in self.inventories.items():
if control_point.captured:
for aircraft in inventory.types_available:
Expand Down
2 changes: 1 addition & 1 deletion game/models/frontline_data.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from theater import ControlPoint
from game.theater import ControlPoint


class FrontlineData:
Expand Down
2 changes: 1 addition & 1 deletion game/operation/operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from dcs.unittype import UnitType

from game.plugins import LuaPluginManager
from game.theater import ControlPoint
from gen import Conflict, FlightType, VisualGenerator
from gen.aircraft import AIRCRAFT_DATA, AircraftConflictGenerator, FlightData
from gen.airfields import AIRFIELD_DATA
Expand All @@ -29,7 +30,6 @@
from gen.radios import RadioFrequency, RadioRegistry
from gen.tacan import TacanRegistry
from gen.triggergen import TRIGGER_RADIUS_MEDIUM, TriggersGenerator
from theater import ControlPoint
from .. import db
from ..debriefing import Debriefing

Expand Down
14 changes: 14 additions & 0 deletions game/theater/controlpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
Type_071_Amphibious_Transport_Dock,
)
from dcs.terrain.terrain import Airport
from dcs.unittype import FlyingType

from game import db
from gen.ground_forces.combat_stance import CombatStance
Expand All @@ -32,6 +33,7 @@
if TYPE_CHECKING:
from game import Game
from gen.flights.flight import FlightType
from ..event import UnitsDeliveryEvent


class ControlPointType(Enum):
Expand Down Expand Up @@ -157,6 +159,7 @@ def __init__(self, id: int, name: str, position: Point,
self.cptype = cptype
self.stances: Dict[int, CombatStance] = {}
self.airport = None
self.pending_unit_deliveries: Optional[UnitsDeliveryEvent] = None

@property
def ground_objects(self) -> List[TheaterGroundObject]:
Expand Down Expand Up @@ -366,6 +369,13 @@ def mission_types(self, for_player: bool) -> Iterator[FlightType]:
# TODO: FlightType.STRIKE
]

def can_land(self, aircraft: FlyingType) -> bool:
if self.is_carrier and aircraft not in db.CARRIER_CAPABLE:
return False
if self.is_lha and aircraft not in db.LHA_CAPABLE:
return False
return True


class OffMapSpawn(ControlPoint):
def __init__(self, id: int, name: str, position: Point):
Expand All @@ -379,3 +389,7 @@ def capture(self, game: Game, for_player: bool) -> None:

def mission_types(self, for_player: bool) -> Iterator[FlightType]:
yield from []

@property
def available_aircraft_slots(self) -> int:
return 1000
1 change: 0 additions & 1 deletion game/theater/frontline.py

This file was deleted.

5 changes: 3 additions & 2 deletions game/theater/start_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@
generate_anti_air_group,
generate_ewr_group, generate_shorad_group,
)
from theater import (
from . import (
ConflictTheater,
ControlPoint,
ControlPointType, OffMapSpawn,
ControlPointType,
OffMapSpawn,
)

GroundObjectTemplates = Dict[str, Dict[str, Any]]
Expand Down
2 changes: 1 addition & 1 deletion game/weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from dcs.weather import Weather as PydcsWeather, Wind

from game.settings import Settings
from theater import ConflictTheater
from game.theater import ConflictTheater


class TimeOfDay(Enum):
Expand Down
47 changes: 24 additions & 23 deletions gen/aircraft.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@
from game import db
from game.data.cap_capabilities_db import GUNFIGHTERS
from game.settings import Settings
from game.theater.controlpoint import (
ControlPoint,
ControlPointType,
OffMapSpawn,
)
from game.theater.theatergroundobject import TheaterGroundObject
from game.utils import knots_to_kph, nm_to_meter
from gen.airsupportgen import AirSupport
from gen.ato import AirTaskingOrder, Package
Expand All @@ -83,12 +89,6 @@
)
from gen.radios import MHz, Radio, RadioFrequency, RadioRegistry, get_radio
from gen.runways import RunwayData
from theater import TheaterGroundObject
from game.theater.controlpoint import (
ControlPoint,
ControlPointType,
OffMapSpawn,
)
from .conflictgen import Conflict
from .flights.flightplan import (
CasFlightPlan,
Expand Down Expand Up @@ -695,6 +695,18 @@ def _start_type(start_type: str) -> StartType:
return StartType.Cold
return StartType.Warm

def determine_runway(self, cp: ControlPoint, dynamic_runways) -> RunwayData:
fallback = RunwayData(cp.full_name, runway_heading=0, runway_name="")
if cp.cptype == ControlPointType.AIRBASE:
assigner = RunwayAssigner(self.game.conditions)
return assigner.get_preferred_runway(cp.airport)
elif cp.is_fleet:
return dynamic_runways.get(cp.name, fallback)
else:
logging.warning(
f"Unhandled departure/arrival control point: {cp.cptype}")
return fallback

def _setup_group(self, group: FlyingGroup, for_task: Type[Task],
package: Package, flight: Flight,
dynamic_runways: Dict[str, RunwayData]) -> None:
Expand Down Expand Up @@ -752,19 +764,9 @@ def _setup_group(self, group: FlyingGroup, for_task: Type[Task],
channel = self.get_intra_flight_channel(unit_type)
group.set_frequency(channel.mhz)

# TODO: Support for different departure/arrival airfields.
cp = flight.from_cp
fallback_runway = RunwayData(cp.full_name, runway_heading=0,
runway_name="")
if cp.cptype == ControlPointType.AIRBASE:
assigner = RunwayAssigner(self.game.conditions)
departure_runway = assigner.get_preferred_runway(
flight.from_cp.airport)
elif cp.is_fleet:
departure_runway = dynamic_runways.get(cp.name, fallback_runway)
else:
logging.warning(f"Unhandled departure control point: {cp.cptype}")
departure_runway = fallback_runway
divert = None
if flight.divert is not None:
divert = self.determine_runway(flight.divert, dynamic_runways)

self.flights.append(FlightData(
package=package,
Expand All @@ -774,10 +776,9 @@ def _setup_group(self, group: FlyingGroup, for_task: Type[Task],
friendly=flight.from_cp.captured,
# Set later.
departure_delay=timedelta(),
departure=departure_runway,
arrival=departure_runway,
# TODO: Support for divert airfields.
divert=None,
departure=self.determine_runway(flight.departure, dynamic_runways),
arrival=self.determine_runway(flight.arrival, dynamic_runways),
divert=divert,
# Waypoints are added later, after they've had their TOTs set.
waypoints=[],
intra_flight_channel=channel
Expand Down
3 changes: 2 additions & 1 deletion gen/conflictgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
from dcs.country import Country
from dcs.mapping import Point

from theater import ConflictTheater, ControlPoint, FrontLine
from game.theater.conflicttheater import ConflictTheater, FrontLine
from game.theater.controlpoint import ControlPoint

AIR_DISTANCE = 40000

Expand Down
Loading

0 comments on commit edd02d9

Please sign in to comment.