Clean up some uses of Point to prep for update.

This commit is contained in:
Dan Albert 2022-02-21 18:12:59 -08:00
parent bafc9dc65e
commit df7be8603b
6 changed files with 22 additions and 81 deletions

View File

@ -4,10 +4,10 @@ import logging
import random
from dataclasses import dataclass, field
from pathlib import Path
from typing import ClassVar, TYPE_CHECKING, Type, Any, Iterator, Optional
from typing import Any, ClassVar, Iterator, Optional, TYPE_CHECKING, Type
import yaml
from dcs import Point
from dcs.unittype import ShipType, StaticType, UnitType as DcsUnitType, VehicleType
from game.data.groups import GroupTask
from game.data.radar_db import UNITS_WITH_RADAR
@ -15,13 +15,10 @@ from game.dcs.groundunittype import GroundUnitType
from game.dcs.helpers import static_type_from_name
from game.dcs.shipunittype import ShipUnitType
from game.dcs.unittype import UnitType
from game.point_with_heading import PointWithHeading
from game.layout.layout import TgoLayout, AntiAirLayout, TgoLayoutGroup
from dcs.unittype import UnitType as DcsUnitType, VehicleType, ShipType, StaticType
from game.theater.theatergroup import TheaterGroup
from game.layout import LAYOUTS
from game.layout.layout import AntiAirLayout, TgoLayout, TgoLayoutGroup
from game.point_with_heading import PointWithHeading
from game.theater.theatergroup import TheaterGroup
if TYPE_CHECKING:
from game import Game
@ -218,10 +215,7 @@ class ForceGroup:
unit.id = game.next_unit_id()
unit.name = unit.unit_type.name if unit.unit_type else unit.type.name
unit.position = PointWithHeading.from_point(
Point(
ground_object.position.x + unit.position.x,
ground_object.position.y + unit.position.y,
),
ground_object.position + unit.position,
# Align heading to GroundObject defined by the campaign designer
unit.position.heading + ground_object.heading,
)

View File

@ -26,7 +26,6 @@ from .ato.flighttype import FlightType
from .campaignloader import CampaignAirWingConfig
from .coalition import Coalition
from .db.gamedb import GameDb
from .factions.faction import Faction
from .infos.information import Information
from .profiling import logged_duration
from .settings import Settings
@ -472,11 +471,6 @@ class Game:
continue
zones.append(package.target.position)
# Else 0,0, since we need a default value
# (in this case this means the whole map is owned by the same player, so it is not an issue)
if len(zones) == 0:
zones.append(Point(0, 0))
self.__culling_zones = zones
def add_destroyed_units(self, data: dict[str, Union[float, str]]) -> None:

View File

@ -1,3 +1,4 @@
import copy
import logging
import random
from typing import Any, Union
@ -244,7 +245,7 @@ class FlightGroupSpawner:
group.points[0].type = "TakeOffParkingHot"
for i in range(self.flight.count - 1):
group.units[1 + i].position = Point(helipad.x, helipad.y)
group.units[1 + i].position = copy.copy(helipad.position)
group.units[1 + i].heading = helipad.units[0].heading
try:
self.helipads[cp].pop()

View File

@ -10,19 +10,7 @@ from __future__ import annotations
import logging
import random
from collections import defaultdict
from typing import (
Any,
Dict,
Generic,
Iterator,
List,
Optional,
TYPE_CHECKING,
Type,
TypeVar,
List,
Any,
)
from typing import Any, Dict, Iterator, List, Optional, TYPE_CHECKING, Type
from dcs import Mission, Point, unitgroup
from dcs.action import DoScript, SceneryDestructionZone
@ -37,9 +25,8 @@ from dcs.ships import (
CV_1143_5,
KUZNECOW,
Stennis,
ship_map,
)
from dcs.statics import Fortification, fortification_map, warehouse_map
from dcs.statics import Fortification
from dcs.task import (
ActivateBeaconCommand,
ActivateICLSCommand,
@ -49,13 +36,11 @@ from dcs.task import (
)
from dcs.translation import String
from dcs.triggers import Event, TriggerOnce, TriggerStart, TriggerZone
from dcs.unit import InvisibleFARP, Ship, Unit, Vehicle
from dcs.unitgroup import ShipGroup, StaticGroup, VehicleGroup, MovingGroup
from dcs.unittype import ShipType, StaticType, VehicleType
from dcs.unit import Unit
from dcs.unitgroup import MovingGroup, ShipGroup, StaticGroup, VehicleGroup
from dcs.unittype import ShipType, VehicleType
from dcs.vehicles import vehicle_map
from game.data.building_data import FORTIFICATION_UNITS, FORTIFICATION_UNITS_ID
from game.dcs.helpers import static_type_from_name, unit_type_from_name
from game.radio.radios import RadioFrequency, RadioRegistry
from game.radio.tacan import TacanBand, TacanChannel, TacanRegistry, TacanUsage
from game.theater import ControlPoint, TheaterGroundObject, TheaterUnit
@ -139,11 +124,7 @@ class GroundObjectGenerator:
vehicle_group.units[0].name = unit.unit_name
self.set_alarm_state(vehicle_group)
else:
vehicle_unit = Vehicle(
self.m.next_unit_id(),
unit.unit_name,
unit.type.id,
)
vehicle_unit = self.m.vehicle(unit.unit_name, unit.type)
vehicle_unit.player_can_drive = True
vehicle_unit.position = unit.position
vehicle_unit.heading = unit.position.heading.degrees
@ -175,11 +156,7 @@ class GroundObjectGenerator:
ship_group.units[0].name = unit.unit_name
self.set_alarm_state(ship_group)
else:
ship_unit = Ship(
self.m.next_unit_id(),
unit.unit_name,
unit.type,
)
ship_unit = self.m.ship(unit.unit_name, unit.type)
if frequency:
ship_unit.set_frequency(frequency.hertz)
ship_unit.position = unit.position
@ -569,9 +546,13 @@ class HelipadGenerator:
self.helipads.append(sg)
name_i = name + "_" + str(i)
logging.info("Generating helipad static : " + name_i)
pad = InvisibleFARP(unit_id=self.m.next_unit_id(), name=name_i)
pad.position = Point(helipad.x, helipad.y)
pad.heading = helipad.heading.degrees
pad = self.m.farp(
country,
name_i,
helipad,
heading=helipad.heading.degrees,
farp_type="InvisibleFARP",
)
sg.add_unit(pad)
# Generate a FARP Ammo and Fuel stack for each pad
self.m.static_group(

View File

@ -15,10 +15,6 @@ if TYPE_CHECKING:
class Bullseye:
position: Point
@classmethod
def from_pydcs(cls, bulls: Dict[str, float]) -> Bullseye:
return cls(Point(bulls["x"], bulls["y"]))
def to_pydcs(self) -> Dict[str, float]:
return {"x": self.position.x, "y": self.position.y}

View File

@ -41,7 +41,6 @@ class ReferencePoint:
class ConflictTheater:
terrain: Terrain
reference_points: Tuple[ReferencePoint, ReferencePoint]
overview_image: str
landmap: Optional[Landmap]
"""
@ -293,10 +292,6 @@ class ConflictTheater:
class CaucasusTheater(ConflictTheater):
terrain = caucasus.Caucasus()
overview_image = "caumap.gif"
reference_points = (
ReferencePoint(caucasus.Gelendzhik.position, Point(176, 298)),
ReferencePoint(caucasus.Batumi.position, Point(1307, 1205)),
)
landmap = load_landmap(Path("resources/caulandmap.p"))
daytime_map = {
@ -326,10 +321,6 @@ class CaucasusTheater(ConflictTheater):
class PersianGulfTheater(ConflictTheater):
terrain = persiangulf.PersianGulf()
overview_image = "persiangulf.gif"
reference_points = (
ReferencePoint(persiangulf.Jiroft.position, Point(1692, 1343)),
ReferencePoint(persiangulf.Liwa_AFB.position, Point(358, 3238)),
)
landmap = load_landmap(Path("resources/gulflandmap.p"))
daytime_map = {
"dawn": (6, 8),
@ -358,10 +349,6 @@ class PersianGulfTheater(ConflictTheater):
class NevadaTheater(ConflictTheater):
terrain = nevada.Nevada()
overview_image = "nevada.gif"
reference_points = (
ReferencePoint(nevada.Mina.position, Point(252, 295)),
ReferencePoint(nevada.Laughlin.position, Point(844, 909)),
)
landmap = load_landmap(Path("resources/nevlandmap.p"))
daytime_map = {
"dawn": (4, 6),
@ -390,10 +377,6 @@ class NevadaTheater(ConflictTheater):
class NormandyTheater(ConflictTheater):
terrain = normandy.Normandy()
overview_image = "normandy.gif"
reference_points = (
ReferencePoint(normandy.Needs_Oar_Point.position, Point(515, 329)),
ReferencePoint(normandy.Evreux.position, Point(2029, 1709)),
)
landmap = load_landmap(Path("resources/normandylandmap.p"))
daytime_map = {
"dawn": (6, 8),
@ -422,10 +405,6 @@ class NormandyTheater(ConflictTheater):
class TheChannelTheater(ConflictTheater):
terrain = thechannel.TheChannel()
overview_image = "thechannel.gif"
reference_points = (
ReferencePoint(thechannel.Abbeville_Drucat.position, Point(2005, 2390)),
ReferencePoint(thechannel.Detling.position, Point(706, 382)),
)
landmap = load_landmap(Path("resources/channellandmap.p"))
daytime_map = {
"dawn": (6, 8),
@ -454,10 +433,6 @@ class TheChannelTheater(ConflictTheater):
class SyriaTheater(ConflictTheater):
terrain = syria.Syria()
overview_image = "syria.gif"
reference_points = (
ReferencePoint(syria.Eyn_Shemer.position, Point(564, 1289)),
ReferencePoint(syria.Tabqa.position, Point(1329, 491)),
)
landmap = load_landmap(Path("resources/syrialandmap.p"))
daytime_map = {
"dawn": (6, 8),