Calculate orientation of specific TGOs automatically

This will allow to automatically calculate the orientation of TGOs which are required to head to the conflict if the campaign designer has not defined a specific heading in the campaign miz. This is for example required for silkworm, scuds or some SAM systems like the SA-11.
Added the should_head_to_conflict property to the TGO
This commit is contained in:
RndName 2022-05-06 17:30:43 +02:00
parent 2d39fb496c
commit a10e55cfd7
No known key found for this signature in database
GPG Key ID: 5EF516FD9537F7C0
3 changed files with 37 additions and 0 deletions

View File

@ -286,6 +286,18 @@ class Game:
for tgo in control_point.connected_objectives:
self.db.tgos.add(tgo.id, tgo)
# Correct the heading of specifc TGOs, can only be done after init turn 0
for tgo in self.theater.ground_objects:
# If heading is 0 then we change the orientation to head towards the
# closest conflict. Heading of 0 means that the campaign designer wants
# to determine the heading automatically by liberation. Values other
# than 0 mean it is custom defined.
if tgo.should_head_to_conflict and tgo.heading.degrees == 0:
# Calculate the heading to conflict
heading = self.theater.heading_to_conflict_from(tgo.position)
# Rotate the whole TGO with the new heading
tgo.rotate(heading or tgo.heading)
self.blue.preinit_turn_0()
self.red.preinit_turn_0()
# We don't need to actually stream events for turn zero because we haven't given

View File

@ -262,6 +262,11 @@ class TheaterGroundObject(MissionTarget, SidcDescribable, ABC):
unit.position.heading += rotation
unit.position.rotate(self.position, rotation)
@property
def should_head_to_conflict(self) -> bool:
"""Should this TGO head towards the closest conflict to work properly?"""
return False
class BuildingGroundObject(TheaterGroundObject):
def __init__(
@ -421,6 +426,10 @@ class MissileSiteGroundObject(TheaterGroundObject):
def purchasable(self) -> bool:
return False
@property
def should_head_to_conflict(self) -> bool:
return True
class CoastalSiteGroundObject(TheaterGroundObject):
def __init__(
@ -449,6 +458,10 @@ class CoastalSiteGroundObject(TheaterGroundObject):
def purchasable(self) -> bool:
return False
@property
def should_head_to_conflict(self) -> bool:
return True
class IadsGroundObject(TheaterGroundObject, ABC):
def __init__(
@ -473,6 +486,10 @@ class IadsGroundObject(TheaterGroundObject, ABC):
yield FlightType.DEAD
yield from super().mission_types(for_player)
@property
def should_head_to_conflict(self) -> bool:
return True
# The SamGroundObject represents all type of AA
# The TGO can have multiple types of units (AAA,SAM,Support...)
@ -554,6 +571,10 @@ class VehicleGroupGroundObject(TheaterGroundObject):
def purchasable(self) -> bool:
return True
@property
def should_head_to_conflict(self) -> bool:
return True
class EwrGroundObject(IadsGroundObject):
def __init__(

View File

@ -134,6 +134,10 @@ VERSION = _build_version_string()
#: also used later in mission generation to orient the group accordingly.
#: This removes the randomization of the orientation from the generation.
#: Most campaigns will not need any updates and will work out of the box.
#: If the campaign designer sets the heading to 0 then we will automatically change
#: the orientation of the generated TGO to head towards the conflict if it is
#: required by the TGO to work properly. Values other than 0 will prevent the
#: automatic orientation.
#:
#: Version 10.1
#: * Campaign designers can now define the recommended economy settings: