mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Merge branch 'theater-refactor' into develop
This commit is contained in:
@@ -1,19 +1,15 @@
|
||||
import random
|
||||
from abc import ABC
|
||||
|
||||
from dcs.vehicles import AirDefence
|
||||
from game import db
|
||||
from game import Game
|
||||
from gen.sam.group_generator import GroupGenerator
|
||||
from theater.theatergroundobject import SamGroundObject
|
||||
|
||||
|
||||
class GenericSamGroupGenerator(GroupGenerator):
|
||||
class GenericSamGroupGenerator(GroupGenerator, ABC):
|
||||
"""
|
||||
This is the base for all SAM group generators
|
||||
"""
|
||||
|
||||
@property
|
||||
def groupNamePrefix(self) -> str:
|
||||
# prefix the SAM site for use with the Skynet IADS plugin
|
||||
if self.faction == self.game.player_name: # this is the player faction
|
||||
return "BLUE SAM "
|
||||
else:
|
||||
return "RED SAM "
|
||||
def __init__(self, game: Game, ground_object: SamGroundObject) -> None:
|
||||
ground_object.skynet_capable = True
|
||||
super().__init__(game, ground_object)
|
||||
|
||||
@@ -22,31 +22,26 @@ if TYPE_CHECKING:
|
||||
# types rather than pydcs groups.
|
||||
class GroupGenerator:
|
||||
|
||||
def __init__(self, game: Game, ground_object: TheaterGroundObject, faction: Optional[Faction] = None): # faction is not mandatory because some subclasses do not use it
|
||||
def __init__(self, game: Game, ground_object: TheaterGroundObject) -> None:
|
||||
self.game = game
|
||||
self.go = ground_object
|
||||
self.position = ground_object.position
|
||||
self.heading = random.randint(0, 359)
|
||||
self.faction = faction
|
||||
self.vg = unitgroup.VehicleGroup(self.game.next_group_id(), self.groupNamePrefix + self.go.group_identifier)
|
||||
self.vg = unitgroup.VehicleGroup(self.game.next_group_id(),
|
||||
self.go.group_name)
|
||||
wp = self.vg.add_waypoint(self.position, PointAction.OffRoad, 0)
|
||||
wp.ETA_locked = True
|
||||
|
||||
@property
|
||||
def groupNamePrefix(self) -> str:
|
||||
return ""
|
||||
|
||||
def generate(self):
|
||||
raise NotImplementedError
|
||||
|
||||
def get_generated_group(self) -> unitgroup.VehicleGroup:
|
||||
return self.vg
|
||||
|
||||
def add_unit(self, unit_type: VehicleType, name: str, pos_x: float, pos_y: float, heading: int):
|
||||
nn = "cgroup|" + str(self.go.cp_id) + '|' + str(self.go.group_id) + '|' + str(self.go.group_identifier) + "|" + name
|
||||
|
||||
def add_unit(self, unit_type: VehicleType, name: str, pos_x: float,
|
||||
pos_y: float, heading: int) -> Vehicle:
|
||||
unit = Vehicle(self.game.next_unit_id(),
|
||||
nn, unit_type.id)
|
||||
f"{self.go.group_name}|{name}", unit_type.id)
|
||||
unit.position.x = pos_x
|
||||
unit.position.y = pos_y
|
||||
unit.heading = heading
|
||||
@@ -88,6 +83,7 @@ class GroupGenerator:
|
||||
current_offset += outer_offset
|
||||
return positions
|
||||
|
||||
|
||||
class ShipGroupGenerator(GroupGenerator):
|
||||
"""Abstract class for other ship generator classes"""
|
||||
def __init__(self, game: Game, ground_object: TheaterGroundObject, faction: Faction):
|
||||
@@ -96,15 +92,14 @@ class ShipGroupGenerator(GroupGenerator):
|
||||
self.position = ground_object.position
|
||||
self.heading = random.randint(0, 359)
|
||||
self.faction = faction
|
||||
self.vg = unitgroup.ShipGroup(self.game.next_group_id(), self.groupNamePrefix + self.go.group_identifier)
|
||||
self.vg = unitgroup.ShipGroup(self.game.next_group_id(),
|
||||
self.go.group_name)
|
||||
wp = self.vg.add_waypoint(self.position, 0)
|
||||
wp.ETA_locked = True
|
||||
|
||||
def add_unit(self, unit_type, name, pos_x, pos_y, heading):
|
||||
nn = "cgroup|" + str(self.go.cp_id) + '|' + str(self.go.group_id) + '|' + str(self.go.group_identifier) + "|" + name
|
||||
|
||||
def add_unit(self, unit_type, name, pos_x, pos_y, heading) -> Ship:
|
||||
unit = Ship(self.game.next_unit_id(),
|
||||
nn, unit_type)
|
||||
f"{self.go.group_name}|{name}", unit_type)
|
||||
unit.position.x = pos_x
|
||||
unit.position.y = pos_y
|
||||
unit.heading = heading
|
||||
|
||||
@@ -38,6 +38,7 @@ from gen.sam.sam_zu23_ural import ZU23UralGenerator
|
||||
from gen.sam.sam_zu23_ural_insurgent import ZU23UralInsurgentGenerator
|
||||
from gen.sam.freya_ewr import FreyaGenerator
|
||||
from theater import TheaterGroundObject
|
||||
from theater.theatergroundobject import SamGroundObject
|
||||
|
||||
SAM_MAP = {
|
||||
"HawkGenerator": HawkGenerator,
|
||||
@@ -129,13 +130,13 @@ def generate_anti_air_group(game: Game, ground_object: TheaterGroundObject,
|
||||
possible_sams_generators = get_faction_possible_sams_generator(faction)
|
||||
if len(possible_sams_generators) > 0:
|
||||
sam_generator_class = random.choice(possible_sams_generators)
|
||||
generator = sam_generator_class(game, ground_object, db.FACTIONS[faction])
|
||||
generator = sam_generator_class(game, ground_object)
|
||||
generator.generate()
|
||||
return generator.get_generated_group()
|
||||
return None
|
||||
|
||||
|
||||
def generate_shorad_group(game: Game, ground_object: TheaterGroundObject,
|
||||
def generate_shorad_group(game: Game, ground_object: SamGroundObject,
|
||||
faction_name: str) -> Optional[VehicleGroup]:
|
||||
faction = db.FACTIONS[faction_name]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user