type hinting and comment cleanup

This commit is contained in:
walterroach 2020-11-03 16:21:15 -06:00 committed by Dan Albert
parent 9087f3487d
commit 1f165835c6
9 changed files with 74 additions and 52 deletions

View File

@ -4,7 +4,7 @@ from gen.sam.group_generator import ShipGroupGenerator
class CarrierGroupGenerator(ShipGroupGenerator):
def generate(self):
# Add carrier
@ -23,4 +23,4 @@ class CarrierGroupGenerator(ShipGroupGenerator):
self.add_unit(dd_type, "DD3", self.position.x + 4500, self.position.y + 8500, self.heading)
self.add_unit(dd_type, "DD4", self.position.x + 4500, self.position.y - 8500, self.heading)
self.get_generated_group().points[0].speed = 20
self.get_generated_group().points[0].speed = 20

View File

@ -1,8 +1,23 @@
import random
from __future__ import annotations
import random
from typing import TYPE_CHECKING
from dcs.ships import (
Type_052C_Destroyer,
Type_052B_Destroyer,
Type_054A_Frigate,
CGN_1144_2_Pyotr_Velikiy,
)
from game.factions.faction import Faction
from gen.fleet.dd_group import DDGroupGenerator
from gen.sam.group_generator import ShipGroupGenerator
from dcs.ships import *
from theater.theatergroundobject import TheaterGroundObject
if TYPE_CHECKING:
from game.game import Game
class ChineseNavyGroupGenerator(ShipGroupGenerator):
@ -34,5 +49,5 @@ class ChineseNavyGroupGenerator(ShipGroupGenerator):
class Type54GroupGenerator(DDGroupGenerator):
def __init__(self, game, ground_object, faction):
def __init__(self, game: Game, ground_object: TheaterGroundObject, faction: Faction):
super(Type54GroupGenerator, self).__init__(game, ground_object, faction, Type_054A_Frigate)

View File

@ -1,13 +1,21 @@
import random
from __future__ import annotations
from typing import TYPE_CHECKING
from game.factions.faction import Faction
from theater.theatergroundobject import TheaterGroundObject
from gen.sam.group_generator import ShipGroupGenerator
from dcs.ships import *
from dcs.unittype import ShipType
from dcs.ships import Oliver_Hazzard_Perry_class, USS_Arleigh_Burke_IIa
if TYPE_CHECKING:
from game.game import Game
class DDGroupGenerator(ShipGroupGenerator):
def __init__(self, game, ground_object, faction, ddtype):
super(DDGroupGenerator, self).__init__(game, ground_object, faction, ddtype)
def __init__(self, game: Game, ground_object: TheaterGroundObject, faction: Faction, ddtype: ShipType):
super(DDGroupGenerator, self).__init__(game, ground_object, faction)
self.ddtype = ddtype
def generate(self):
@ -16,12 +24,11 @@ class DDGroupGenerator(ShipGroupGenerator):
self.get_generated_group().points[0].speed = 20
class OliverHazardPerryGroupGenerator(DDGroupGenerator):
def __init__(self, game, ground_object, faction):
def __init__(self, game: Game, ground_object: TheaterGroundObject, faction: Faction):
super(OliverHazardPerryGroupGenerator, self).__init__(game, ground_object, faction, Oliver_Hazzard_Perry_class)
class ArleighBurkeGroupGenerator(DDGroupGenerator):
def __init__(self, game, ground_object, faction):
def __init__(self, game: Game, ground_object: TheaterGroundObject, faction: Faction):
super(ArleighBurkeGroupGenerator, self).__init__(game, ground_object, faction, USS_Arleigh_Burke_IIa)

View File

@ -18,4 +18,4 @@ class LHAGroupGenerator(ShipGroupGenerator):
self.add_unit(dd_type, "DD1", self.position.x + 1250, self.position.y + 1450, self.heading)
self.add_unit(dd_type, "DD2", self.position.x + 1250, self.position.y - 1450, self.heading)
self.get_generated_group().points[0].speed = 20
self.get_generated_group().points[0].speed = 20

View File

@ -1,8 +1,26 @@
from __future__ import annotations
import random
from typing import TYPE_CHECKING
from dcs.ships import (
FFL_1124_4_Grisha,
FSG_1241_1MP_Molniya,
FFG_11540_Neustrashimy,
FF_1135M_Rezky,
CG_1164_Moskva,
CGN_1144_2_Pyotr_Velikiy,
SSK_877,
SSK_641B
)
from gen.fleet.dd_group import DDGroupGenerator
from gen.sam.group_generator import ShipGroupGenerator
from dcs.ships import *
from game.factions.faction import Faction
from theater.theatergroundobject import TheaterGroundObject
if TYPE_CHECKING:
from game.game import Game
class RussianNavyGroupGenerator(ShipGroupGenerator):
@ -35,21 +53,20 @@ class RussianNavyGroupGenerator(ShipGroupGenerator):
class GrishaGroupGenerator(DDGroupGenerator):
def __init__(self, game, ground_object, faction):
def __init__(self, game: Game, ground_object: TheaterGroundObject, faction: Faction):
super(GrishaGroupGenerator, self).__init__(game, ground_object, faction, FFL_1124_4_Grisha)
class MolniyaGroupGenerator(DDGroupGenerator):
def __init__(self, game, ground_object, faction):
def __init__(self, game: Game, ground_object: TheaterGroundObject, faction: Faction):
super(MolniyaGroupGenerator, self).__init__(game, ground_object, faction, FSG_1241_1MP_Molniya)
class KiloSubGroupGenerator(DDGroupGenerator):
def __init__(self, game, ground_object, faction):
def __init__(self, game: Game, ground_object: TheaterGroundObject, faction: Faction):
super(KiloSubGroupGenerator, self).__init__(game, ground_object, faction, SSK_877)
class TangoSubGroupGenerator(DDGroupGenerator):
def __init__(self, game, ground_object, faction):
def __init__(self, game: Game, ground_object: TheaterGroundObject, faction: Faction):
super(TangoSubGroupGenerator, self).__init__(game, ground_object, faction, SSK_641B)

View File

@ -12,4 +12,4 @@ class SchnellbootGroupGenerator(ShipGroupGenerator):
for i in range(random.randint(2, 4)):
self.add_unit(Schnellboot_type_S130, "Schnellboot" + str(i), self.position.x + i * random.randint(100, 250), self.position.y + (random.randint(100, 200)-100), self.heading)
self.get_generated_group().points[0].speed = 20
self.get_generated_group().points[0].speed = 20

View File

@ -11,8 +11,6 @@ from gen.fleet.ru_dd_group import RussianNavyGroupGenerator, GrishaGroupGenerato
from gen.fleet.schnellboot import SchnellbootGroupGenerator
from gen.fleet.uboat import UBoatGroupGenerator
from gen.fleet.ww2lst import WW2LSTGroupGenerator
# from dcs import unitgroup
# from dcs.unit import Ship
SHIP_MAP = {
@ -48,7 +46,7 @@ def generate_ship_group(game, ground_object, faction_name: str):
return None
def generate_carrier_group(faction:str, game, ground_object):
def generate_carrier_group(faction: str, game, ground_object):
"""
This generate a carrier group
:param parentCp: The parent control point
@ -61,7 +59,7 @@ def generate_carrier_group(faction:str, game, ground_object):
return generator.get_generated_group()
def generate_lha_group(faction:str, game, ground_object):
def generate_lha_group(faction: str, game, ground_object):
"""
This generate a lha carrier group
:param parentCp: The parent control point
@ -72,26 +70,3 @@ def generate_lha_group(faction:str, game, ground_object):
generator = LHAGroupGenerator(game, ground_object, db.FACTIONS[faction])
generator.generate()
return generator.get_generated_group()
# class ShipGroupGenerator(GroupGenerator):
# """Abstract class for other ship generator classes"""
# def __init__(self, game, ground_object, faction):
# self.game = game
# self.go = ground_object
# 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)
# 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
# unit = Ship(self.game.next_unit_id(),
# nn, unit_type)
# unit.position.x = pos_x
# unit.position.y = pos_y
# unit.heading = heading
# self.vg.add_unit(unit)
# return unit

View File

@ -1,14 +1,23 @@
from __future__ import annotations
import math
import random
from typing import TYPE_CHECKING, Optional
from dcs import unitgroup
from dcs.point import PointAction
from dcs.unit import Vehicle, Ship
from dcs.unittype import VehicleType
from game.factions.faction import Faction
from theater.theatergroundobject import TheaterGroundObject
if TYPE_CHECKING:
from game.game import Game
class GroupGenerator():
def __init__(self, game, ground_object, faction = None): # faction is not mandatory because some subclasses do not use it
def __init__(self, game: Game, ground_object: TheaterGroundObject, faction: Optional[Faction] = None): # faction is not mandatory because some subclasses do not use it
self.game = game
self.go = ground_object
self.position = ground_object.position
@ -28,8 +37,7 @@ class GroupGenerator():
def get_generated_group(self):
return self.vg
def add_unit(self, unit_type, name, pos_x, pos_y, heading):
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
unit = Vehicle(self.game.next_unit_id(),
@ -77,7 +85,7 @@ class GroupGenerator():
class ShipGroupGenerator(GroupGenerator):
"""Abstract class for other ship generator classes"""
def __init__(self, game, ground_object, faction):
def __init__(self, game: Game, ground_object: TheaterGroundObject, faction: Faction):
self.game = game
self.go = ground_object
self.position = ground_object.position

View File

@ -122,7 +122,7 @@ def generate_anti_air_group(game, parent_cp, ground_object, faction: str):
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, faction)
generator = sam_generator_class(game, ground_object, db.FACTIONS[faction])
generator.generate()
return generator.get_generated_group()
return None