mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Move TGOs out of MapModel.
This commit is contained in:
@@ -4,10 +4,11 @@ from .database import Database
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from game.ato import Flight
|
||||
from game.theater import FrontLine
|
||||
from game.theater import FrontLine, TheaterGroundObject
|
||||
|
||||
|
||||
class GameDb:
|
||||
def __init__(self) -> None:
|
||||
self.flights: Database[Flight] = Database()
|
||||
self.front_lines: Database[FrontLine] = Database()
|
||||
self.tgos: Database[TheaterGroundObject] = Database()
|
||||
|
||||
@@ -278,6 +278,8 @@ class Game:
|
||||
|
||||
for control_point in self.theater.controlpoints:
|
||||
control_point.initialize_turn_0()
|
||||
for tgo in control_point.connected_objectives:
|
||||
self.db.tgos.add(tgo.id, tgo)
|
||||
|
||||
self.blue.preinit_turn_0()
|
||||
self.red.preinit_turn_0()
|
||||
|
||||
@@ -9,7 +9,7 @@ from . import (
|
||||
frontlines,
|
||||
mapzones,
|
||||
navmesh,
|
||||
packagedialog,
|
||||
qt,
|
||||
supplyroutes,
|
||||
tgos,
|
||||
waypoints,
|
||||
@@ -29,7 +29,7 @@ app.include_router(flights.router)
|
||||
app.include_router(frontlines.router)
|
||||
app.include_router(mapzones.router)
|
||||
app.include_router(navmesh.router)
|
||||
app.include_router(packagedialog.router)
|
||||
app.include_router(qt.router)
|
||||
app.include_router(supplyroutes.router)
|
||||
app.include_router(tgos.router)
|
||||
app.include_router(waypoints.router)
|
||||
|
||||
@@ -2,7 +2,7 @@ from __future__ import annotations
|
||||
|
||||
from typing import Callable, TYPE_CHECKING
|
||||
|
||||
from game.theater import MissionTarget
|
||||
from game.theater import MissionTarget, TheaterGroundObject
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from game import Game
|
||||
@@ -28,8 +28,13 @@ class GameContext:
|
||||
|
||||
|
||||
class QtCallbacks:
|
||||
def __init__(self, create_new_package: Callable[[MissionTarget], None]) -> None:
|
||||
def __init__(
|
||||
self,
|
||||
create_new_package: Callable[[MissionTarget], None],
|
||||
show_tgo_info: Callable[[TheaterGroundObject], None],
|
||||
) -> None:
|
||||
self.create_new_package = create_new_package
|
||||
self.show_tgo_info = show_tgo_info
|
||||
|
||||
|
||||
class QtContext:
|
||||
|
||||
@@ -31,6 +31,7 @@ class GameUpdateEventsJs(BaseModel):
|
||||
new_front_lines: list[FrontLineJs]
|
||||
updated_front_lines: set[UUID]
|
||||
deleted_front_lines: set[UUID]
|
||||
updated_tgos: set[UUID]
|
||||
|
||||
@classmethod
|
||||
def from_events(cls, events: GameUpdateEvents, game: Game) -> GameUpdateEventsJs:
|
||||
@@ -62,4 +63,5 @@ class GameUpdateEventsJs(BaseModel):
|
||||
],
|
||||
updated_front_lines=events.updated_front_lines,
|
||||
deleted_front_lines=events.deleted_front_lines,
|
||||
updated_tgos=events.updated_tgos,
|
||||
)
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
from uuid import UUID
|
||||
|
||||
from fastapi import APIRouter, Depends
|
||||
|
||||
from game import Game
|
||||
from ..dependencies import GameContext, QtCallbacks, QtContext
|
||||
|
||||
router: APIRouter = APIRouter(prefix="/package-dialog")
|
||||
|
||||
|
||||
@router.post("/front-line/{front_line_id}")
|
||||
def new_front_line_package(
|
||||
front_line_id: UUID,
|
||||
game: Game = Depends(GameContext.get),
|
||||
qt: QtCallbacks = Depends(QtContext.get),
|
||||
) -> None:
|
||||
front_line = game.db.front_lines.get(front_line_id)
|
||||
qt.create_new_package(front_line)
|
||||
35
game/server/qt/routes.py
Normal file
35
game/server/qt/routes.py
Normal file
@@ -0,0 +1,35 @@
|
||||
from uuid import UUID
|
||||
|
||||
from fastapi import APIRouter, Depends
|
||||
|
||||
from game import Game
|
||||
from ..dependencies import GameContext, QtCallbacks, QtContext
|
||||
|
||||
router: APIRouter = APIRouter(prefix="/qt")
|
||||
|
||||
|
||||
@router.post("/create-package/front-line/{front_line_id}")
|
||||
def new_front_line_package(
|
||||
front_line_id: UUID,
|
||||
game: Game = Depends(GameContext.get),
|
||||
qt: QtCallbacks = Depends(QtContext.get),
|
||||
) -> None:
|
||||
qt.create_new_package(game.db.front_lines.get(front_line_id))
|
||||
|
||||
|
||||
@router.post("/create-package/tgo/{tgo_id}")
|
||||
def new_tgo_package(
|
||||
tgo_id: UUID,
|
||||
game: Game = Depends(GameContext.get),
|
||||
qt: QtCallbacks = Depends(QtContext.get),
|
||||
) -> None:
|
||||
qt.create_new_package(game.db.tgos.get(tgo_id))
|
||||
|
||||
|
||||
@router.post("/info/tgo/{tgo_id}")
|
||||
def show_tgo_info(
|
||||
tgo_id: UUID,
|
||||
game: Game = Depends(GameContext.get),
|
||||
qt: QtCallbacks = Depends(QtContext.get),
|
||||
) -> None:
|
||||
qt.show_tgo_info(game.db.tgos.get(tgo_id))
|
||||
@@ -1,5 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from uuid import UUID
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from game.server.leaflet import LeafletPoint
|
||||
@@ -7,16 +9,17 @@ from game.theater import TheaterGroundObject
|
||||
|
||||
|
||||
class TgoJs(BaseModel):
|
||||
id: UUID
|
||||
name: str
|
||||
control_point_name: str
|
||||
category: str
|
||||
blue: bool
|
||||
position: LeafletPoint
|
||||
units: list[str]
|
||||
threat_ranges: list[float]
|
||||
detection_ranges: list[float]
|
||||
dead: bool
|
||||
sidc: str
|
||||
units: list[str] # TODO: Event stream
|
||||
threat_ranges: list[float] # TODO: Event stream
|
||||
detection_ranges: list[float] # TODO: Event stream
|
||||
dead: bool # TODO: Event stream
|
||||
sidc: str # TODO: Event stream
|
||||
|
||||
@staticmethod
|
||||
def for_tgo(tgo: TheaterGroundObject) -> TgoJs:
|
||||
@@ -29,6 +32,7 @@ class TgoJs(BaseModel):
|
||||
tgo.detection_range(group).meters for group in tgo.groups
|
||||
]
|
||||
return TgoJs(
|
||||
id=tgo.id,
|
||||
name=tgo.name,
|
||||
control_point_name=tgo.control_point.name,
|
||||
category=tgo.category,
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
from uuid import UUID
|
||||
|
||||
from fastapi import APIRouter, Depends
|
||||
|
||||
from game import Game
|
||||
@@ -15,3 +17,8 @@ def list_tgos(game: Game = Depends(GameContext.get)) -> list[TgoJs]:
|
||||
if not tgo.is_control_point:
|
||||
tgos.append(TgoJs.for_tgo(tgo))
|
||||
return tgos
|
||||
|
||||
|
||||
@router.get("/{tgo_id}")
|
||||
def get_tgo(tgo_id: UUID, game: Game = Depends(GameContext.get)) -> TgoJs:
|
||||
return TgoJs.for_tgo(game.db.tgos.get(tgo_id))
|
||||
|
||||
@@ -9,7 +9,7 @@ from dcs import Point
|
||||
if TYPE_CHECKING:
|
||||
from game.ato import Flight, Package
|
||||
from game.sim.combat import FrozenCombat
|
||||
from game.theater import FrontLine
|
||||
from game.theater import FrontLine, TheaterGroundObject
|
||||
|
||||
|
||||
@dataclass
|
||||
@@ -30,6 +30,7 @@ class GameUpdateEvents:
|
||||
new_front_lines: set[FrontLine] = field(default_factory=set)
|
||||
updated_front_lines: set[UUID] = field(default_factory=set)
|
||||
deleted_front_lines: set[UUID] = field(default_factory=set)
|
||||
updated_tgos: set[UUID] = field(default_factory=set)
|
||||
shutting_down: bool = False
|
||||
|
||||
@property
|
||||
@@ -111,6 +112,10 @@ class GameUpdateEvents:
|
||||
self.deleted_front_lines.add(front_line.id)
|
||||
return self
|
||||
|
||||
def update_tgo(self, tgo: TheaterGroundObject) -> GameUpdateEvents:
|
||||
self.updated_tgos.add(tgo.id)
|
||||
return self
|
||||
|
||||
def shut_down(self) -> GameUpdateEvents:
|
||||
self.shutting_down = True
|
||||
return self
|
||||
|
||||
@@ -30,7 +30,7 @@ class MissionResultsProcessor:
|
||||
self.commit_convoy_losses(debriefing)
|
||||
self.commit_cargo_ship_losses(debriefing)
|
||||
self.commit_airlift_losses(debriefing)
|
||||
self.commit_ground_losses(debriefing)
|
||||
self.commit_ground_losses(debriefing, events)
|
||||
self.commit_damaged_runways(debriefing)
|
||||
self.commit_captures(debriefing, events)
|
||||
self.commit_front_line_battle_impact(debriefing, events)
|
||||
@@ -131,11 +131,11 @@ class MissionResultsProcessor:
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def commit_ground_losses(debriefing: Debriefing) -> None:
|
||||
def commit_ground_losses(debriefing: Debriefing, events: GameUpdateEvents) -> None:
|
||||
for ground_object_loss in debriefing.ground_object_losses:
|
||||
ground_object_loss.theater_unit.kill()
|
||||
ground_object_loss.theater_unit.kill(events)
|
||||
for scenery_object_loss in debriefing.scenery_object_losses:
|
||||
scenery_object_loss.ground_unit.kill()
|
||||
scenery_object_loss.ground_unit.kill(events)
|
||||
|
||||
@staticmethod
|
||||
def commit_damaged_runways(debriefing: Debriefing) -> None:
|
||||
|
||||
@@ -730,11 +730,11 @@ class ControlPoint(MissionTarget, SidcDescribable, ABC):
|
||||
for squadron in self.squadrons:
|
||||
self._retreat_squadron(game, squadron)
|
||||
|
||||
def depopulate_uncapturable_tgos(self) -> None:
|
||||
def depopulate_uncapturable_tgos(self, events: GameUpdateEvents) -> None:
|
||||
# TODO Rework this.
|
||||
for tgo in self.connected_objectives:
|
||||
if not tgo.capturable:
|
||||
tgo.clear()
|
||||
tgo.clear(events)
|
||||
|
||||
# TODO: Should be Airbase specific.
|
||||
def capture(self, game: Game, events: GameUpdateEvents, for_player: bool) -> None:
|
||||
@@ -742,7 +742,7 @@ class ControlPoint(MissionTarget, SidcDescribable, ABC):
|
||||
self.ground_unit_orders.refund_all(self.coalition)
|
||||
self.retreat_ground_units(game)
|
||||
self.retreat_air_units(game)
|
||||
self.depopulate_uncapturable_tgos()
|
||||
self.depopulate_uncapturable_tgos(events)
|
||||
|
||||
self._coalition = new_coalition
|
||||
self.base.set_strength_to_minimum()
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import itertools
|
||||
import uuid
|
||||
from abc import ABC
|
||||
from typing import Iterator, List, Optional, TYPE_CHECKING
|
||||
|
||||
@@ -22,6 +23,7 @@ from ..data.radar_db import LAUNCHER_TRACKER_PAIRS, TELARS, TRACK_RADARS
|
||||
from ..utils import Distance, Heading, meters
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from game.sim import GameUpdateEvents
|
||||
from .theatergroup import TheaterUnit, TheaterGroup
|
||||
from .controlpoint import ControlPoint
|
||||
from ..ato.flighttype import FlightType
|
||||
@@ -62,6 +64,7 @@ class TheaterGroundObject(MissionTarget, SidcDescribable, ABC):
|
||||
sea_object: bool,
|
||||
) -> None:
|
||||
super().__init__(name, position)
|
||||
self.id = uuid.uuid4()
|
||||
self.category = category
|
||||
self.heading = heading
|
||||
self.control_point = control_point
|
||||
@@ -212,8 +215,9 @@ class TheaterGroundObject(MissionTarget, SidcDescribable, ABC):
|
||||
def mark_locations(self) -> Iterator[Point]:
|
||||
yield self.position
|
||||
|
||||
def clear(self) -> None:
|
||||
def clear(self, events: GameUpdateEvents) -> None:
|
||||
self.groups = []
|
||||
events.update_tgo(self)
|
||||
|
||||
@property
|
||||
def capturable(self) -> bool:
|
||||
|
||||
@@ -1,22 +1,20 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
from dataclasses import dataclass
|
||||
from typing import Optional, Any, TYPE_CHECKING, Type
|
||||
from typing import Any, Optional, TYPE_CHECKING, Type
|
||||
|
||||
from dcs.triggers import TriggerZone
|
||||
from dcs.unittype import VehicleType, ShipType, StaticType
|
||||
from dcs.unittype import ShipType, StaticType, UnitType as DcsUnitType, VehicleType
|
||||
|
||||
from game.dcs.groundunittype import GroundUnitType
|
||||
from game.dcs.shipunittype import ShipUnitType
|
||||
from game.dcs.unittype import UnitType
|
||||
from dcs.unittype import UnitType as DcsUnitType
|
||||
|
||||
from game.point_with_heading import PointWithHeading
|
||||
from game.utils import Heading
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from game.layout.layout import LayoutUnit, TgoLayoutGroup
|
||||
from game.layout.layout import LayoutUnit
|
||||
from game.sim import GameUpdateEvents
|
||||
from game.theater import TheaterGroundObject
|
||||
|
||||
|
||||
@@ -58,8 +56,9 @@ class TheaterUnit:
|
||||
# None for not available StaticTypes
|
||||
return None
|
||||
|
||||
def kill(self) -> None:
|
||||
def kill(self, events: GameUpdateEvents) -> None:
|
||||
self.alive = False
|
||||
events.update_tgo(self.ground_object)
|
||||
|
||||
@property
|
||||
def unit_name(self) -> str:
|
||||
|
||||
Reference in New Issue
Block a user