diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..90a3258f --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "submodules/dcs"] + path = submodules/dcs + url = https://github.com/pydcs/dcs diff --git a/__init__.py b/__init__.py index d0f0f4d5..ae9ff0be 100755 --- a/__init__.py +++ b/__init__.py @@ -20,11 +20,6 @@ m = dcs.Mission() theater = theater.caucasus.CaucasusTheater() start_generator.generate_initial(theater, "Russia") -theater.kutaisi.base.aircraft = { - F_15C: 4, - A_10C: 2, -} - g = Game(theater=theater) w = ui.window.Window() diff --git a/dcs b/dcs new file mode 120000 index 00000000..f77acded --- /dev/null +++ b/dcs @@ -0,0 +1 @@ +submodules/dcs/dcs \ No newline at end of file diff --git a/game/event.py b/game/event.py index c2b475a3..62b3caf2 100644 --- a/game/event.py +++ b/game/event.py @@ -83,6 +83,7 @@ class GroundInterceptEvent(Event): defender=self.defender, attacker_clients=clients, defender_clients={}, + from_cp=self.from_cp, position=position, target=targets, strikegroup=strikegroup) @@ -120,8 +121,8 @@ class InterceptEvent(Event): defender=self.defender, attacker_clients=clients, defender_clients={}, - destination=self.to_cp, - destination_port=self.to_cp.airport, + from_cp=self.from_cp, + to_cp=self.to_cp, escort=escort, transport={transport_unit: 1}, airdefense={airdefense_unit: self.AIRDEFENSE_COUNT}, @@ -137,8 +138,8 @@ class InterceptEvent(Event): defender=self.defender, attacker_clients={}, defender_clients=clients, - destination=self.to_cp, - destination_port=self.to_cp.airport, + from_cp=self.from_cp, + to_cp=self.to_cp, escort=escort, transport={transport_unit: 1}, interceptors=interceptors, diff --git a/game/game.py b/game/game.py index 1cfcebe9..2a45b906 100644 --- a/game/game.py +++ b/game/game.py @@ -23,8 +23,8 @@ COMMISION_AMOUNTS_FACTORS = { } -ENEMY_INTERCEPT_PROBABILITY_BASE = 15 -ENEMY_CAPTURE_PROBABILITY_BASE = 5 +ENEMY_INTERCEPT_PROBABILITY_BASE = 10 +ENEMY_CAPTURE_PROBABILITY_BASE = 3 PLAYER_INTERCEPT_PROBABILITY_BASE = 30 PLAYER_GROUNDINTERCEPT_PROBABILITY_BASE = 30 @@ -128,7 +128,8 @@ class Game: return event def units_delivery_remove(self, event: Event): - self.events.remove(event) + if event in self.events: + self.events.remove(event) def initiate_event(self, event: Event): event.operation.generate() diff --git a/game/operation.py b/game/operation.py index 18e1cd01..c811345c 100644 --- a/game/operation.py +++ b/game/operation.py @@ -13,6 +13,7 @@ from shop import * from gen.armor import * from gen.aircraft import * from gen.aaa import * +from gen.shipgen import * from gen.conflictgen import * @@ -23,6 +24,7 @@ class Operation: self.armorgen = ArmorConflictGenerator(self.mission, self.conflict) self.airgen = AircraftConflictGenerator(self.mission, self.conflict) self.aagen = AAConflictGenerator(self.mission, self.conflict) + self.shipgen = ShipGenerator(self.mission, self.conflict) def units_of(self, country_name: str) -> typing.Collection[UnitType]: return [] @@ -67,10 +69,11 @@ class CaptureOperation(Operation): def generate(self): self.armorgen.generate(self.attack, self.defense) - self.airgen.generate_cas(self.cas, clients=self.attacker_clients) - self.airgen.generate_cas_escort(self.escort, clients=self.attacker_clients) - self.airgen.generate_defense(self.intercept, clients=self.defender_clients) self.aagen.generate(self.aa) + self.airgen.generate_defense(self.intercept, clients=self.defender_clients) + + self.airgen.generate_cas(self.cas, clients=self.attacker_clients, at=self.from_cp.at) + self.airgen.generate_cas_escort(self.escort, clients=self.attacker_clients, at=self.from_cp.at) class InterceptOperation(Operation): @@ -80,8 +83,8 @@ class InterceptOperation(Operation): defender: Country, attacker_clients: db.PlaneDict, defender_clients: db.PlaneDict, - destination: ControlPoint, - destination_port: Airport, + from_cp: ControlPoint, + to_cp: ControlPoint, escort: db.PlaneDict, transport: db.PlaneDict, airdefense: db.AirDefenseDict, @@ -89,13 +92,14 @@ class InterceptOperation(Operation): conflict = Conflict.intercept_conflict( attacker=attacker, defender=defender, - position=destination.position, + position=to_cp.position, heading=randint(0, 360), radials=ALL_RADIALS ) super(InterceptOperation, self).__init__(mission, conflict) - self.destination_port = destination_port + self.to_cp = to_cp + self.from_cp = from_cp self.attacker_clients = attacker_clients self.defender_clients = defender_clients self.escort = escort @@ -104,17 +108,22 @@ class InterceptOperation(Operation): self.interceptors = interceptors def generate(self): - self.airgen.generate_transport(self.transport, self.destination_port) + self.airgen.generate_transport(self.transport, self.to_cp.at) self.airgen.generate_transport_escort(self.escort, clients=self.defender_clients) - self.airgen.generate_interception(self.interceptors, clients=self.attacker_clients) self.aagen.generate(self.airdefense) + if self.from_cp.is_global: + self.airgen.generate_interception(self.interceptors, clients=self.attacker_clients, at=self.shipgen.generate(self.from_cp.at)) + else: + self.airgen.generate_interception(self.interceptors, clients=self.attacker_clients, at=self.from_cp.at) + class GroundInterceptOperation(Operation): def __init__(self, mission: Mission, attacker: Country, defender: Country, + from_cp: ControlPoint, attacker_clients: db.PlaneDict, defender_clients: db.PlaneDict, position: Point, @@ -131,10 +140,10 @@ class GroundInterceptOperation(Operation): super(GroundInterceptOperation, self).__init__(mission, conflict) self.attacker_clients = attacker_clients self.defender_clients = defender_clients + self.from_cp = from_cp self.strikegroup = strikegroup self.target = target def generate(self): - self.airgen.generate_cas(self.strikegroup, clients=self.attacker_clients) + self.airgen.generate_cas(self.strikegroup, clients=self.attacker_clients, at=self.from_cp.at) self.armorgen.generate({}, self.target) - diff --git a/gen/aircraft.py b/gen/aircraft.py index fa0f5b95..e96c3171 100644 --- a/gen/aircraft.py +++ b/gen/aircraft.py @@ -45,28 +45,39 @@ class AircraftConflictGenerator: ) return point.random_point_within(distance, self.conflict.size * SPREAD_DISTANCE_FACTOR[0]) - def _generate_group( - self, - name: str, - side: Country, - unit: PlaneType, - count: int, - client_count: int, - at: Point = None, - airport: Airport = None) -> FlyingGroup: - starttype = airport is None and StartType.Warm or StartType.Cold + def _generate_at_airport(self, name: str, side: Country, unit_type: FlyingType, count: int, client_count: int, airport: Airport = None) -> FlyingGroup: assert count > 0 + assert unit is not None + + group = self.m.flight_group_from_airport( + country=side, + name=name, + aircraft_type=unit_type, + airport=self.m.terrain.airport_by_id(airport.id), + maintask=None, + start_type=StartType.Cold, + group_size=count, + parking_slots=None) + + for idx in range(client_count): + group.units[idx].set_client() + + return group + + def _generate_inflight(self, name: str, side: Country, unit_type: FlyingType, count: int, client_count: int, at: Point) -> FlyingGroup: + assert count > 0 + assert unit is not None group = self.m.flight_group( country=side, name=name, - aircraft_type=unit, - airport=airport, + aircraft_type=unit_type, + airport=None, position=at, altitude=WARM_START_ALTITUDE, speed=WARM_START_AIRSPEED, maintask=None, - start_type=starttype, + start_type=StartType.Warm, group_size=count) for idx in range(client_count): @@ -74,7 +85,35 @@ class AircraftConflictGenerator: return group - def _generate_escort(self, units: db.PlaneDict, clients: db.PlaneDict, airport: Airport, side: Country, location: Point): + def _generate_at_carrier(self, name: str, side: Country, unit_type: FlyingType, count: int, client_count: int, at: ShipGroup) -> FlyingGroup: + assert count > 0 + assert unit is not None + + group = self.m.flight_group_from_unit( + country=side, + name=name, + aircraft_type=unit_type, + pad_group=at, + maintask=None, + start_type=StartType.Warm, + group_size=count) + + for idx in range(client_count): + group.units[idx].set_client() + + return group + + def _generate_group(self, name: str, side: Country, unit_type: FlyingType, count: int, client_count: int, at: db.StartingPosition): + if isinstance(at, Point): + return self._generate_inflight(name, side, unit_type, count, client_count, at) + elif issubclass(at, Airport): + return self._generate_at_airport(name, side, unit_type, count, client_count, at) + elif isinstance(at, ShipGroup): + return self._generate_at_carrier(name, side, unit_type, count, client_count, at) + else: + assert False + + def _generate_escort(self, side: Country, units: db.PlaneDict, clients: db.PlaneDict, at: db.StartingPosition): if len(self.escort_targets) == 0: return @@ -82,11 +121,10 @@ class AircraftConflictGenerator: group = self._generate_group( name=namegen.next_escort_group_name(), side=side, - unit=type, + unit_type=type, count=count, client_count=clients.get(type, 0), - at=location, - airport=airport) + at=at) group.task = Escort.name group.load_task_default_loadout(dcs.task.Escort) @@ -98,52 +136,46 @@ class AircraftConflictGenerator: for group in self.escort_targets: wayp.tasks.append(EscortTaskAction(group.id, engagement_max_dist=ESCORT_MAX_DIST)) - def generate_cas(self, attackers: db.PlaneDict, clients: db.PlaneDict, airport: Airport = None): + def generate_cas(self, attackers: db.PlaneDict, clients: db.PlaneDict, at: db.StartingPosition = None): assert len(self.escort_targets) == 0 for type, count in attackers.items(): group = self._generate_group( name=namegen.next_cas_group_name(), side=self.conflict.attackers_side, - unit=type, + unit_type=type, count=count, client_count=clients.get(type, 0), - at=airport is None and self._group_point(self.conflict.air_attackers_location) or None, - airport=airport) + at=at and at or self._group_point(self.conflict.air_attackers_location)) self.escort_targets.append(group) group.add_waypoint(self.conflict.position, CAS_ALTITUDE) group.task = CAS.name group.load_task_default_loadout(CAS) - def generate_cas_escort(self, attackers: db.PlaneDict, clients: db.PlaneDict, airport: Airport = None): + def generate_cas_escort(self, attackers: db.PlaneDict, clients: db.PlaneDict, at: db.StartingPosition = None): self._generate_escort( + side=self.conflict.attackers_side, units=attackers, clients=clients, - airport=airport, - side=self.conflict.attackers_side, - location=airport is None and self._group_point(self.conflict.air_attackers_location) or None - ) + at=at and at or self._group_point(self.conflict.air_attackers_location)) - def generate_transport_escort(self, escort: db.PlaneDict, clients: db.PlaneDict, airport: Airport = None): + def generate_transport_escort(self, escort: db.PlaneDict, clients: db.PlaneDict, at: db.StartingPosition = None): self._generate_escort( + side=self.conflict.defenders_side, units=escort, clients=clients, - airport=airport, - side=self.conflict.defenders_side, - location=airport is None and self._group_point(self.conflict.air_defenders_location) or None - ) + at=at and at or self._group_point(self.conflict.air_defenders_location)) - def generate_defense(self, defenders: db.PlaneDict, clients: db.PlaneDict, airport: Airport = None): + def generate_defense(self, defenders: db.PlaneDict, clients: db.PlaneDict, at: db.StartingPosition = None): for type, count in defenders.items(): group = self._generate_group( - name=namegen.next_intercept_group_name(), - side=self.conflict.defenders_side, - unit=type, - count=count, - client_count=clients.get(type, 0), - at=airport is None and self._group_point(self.conflict.air_defenders_location) or None, - airport=airport) + name=namegen.next_intercept_group_name(), + side=self.conflict.defenders_side, + unit_type=type, + count=count, + client_count=clients.get(type, 0), + at=at and at or self._group_point(self.conflict.air_defenders_location)) group.task = FighterSweep.name group.load_task_default_loadout(FighterSweep) @@ -158,29 +190,25 @@ class AircraftConflictGenerator: group = self._generate_group( name=namegen.next_transport_group_name(), side=self.conflict.defenders_side, - unit=type, + unit_type=type, count=count, client_count=0, - at=self._group_point(self.conflict.air_defenders_location), - airport=None - ) + at=self._group_point(self.conflict.air_defenders_location)) group.task = Transport.name self.escort_targets.append(group) group.land_at(destination) - def generate_interception(self, interceptors: db.PlaneDict, clients: db.PlaneDict, airport: Airport = None): + def generate_interception(self, interceptors: db.PlaneDict, clients: db.PlaneDict, at: db.StartingPosition = None): for type, count in interceptors.items(): group = self._generate_group( name=namegen.next_intercept_group_name(), side=self.conflict.attackers_side, - unit=type, + unit_type=type, count=count, client_count=clients.get(type, 0), - at=airport is None and self._group_point(self.conflict.air_attackers_location) or None, - airport=airport - ) + at=at and at or self._group_point(self.conflict.air_attackers_location)) group.task = FighterSweep.name group.load_task_default_loadout(FighterSweep) diff --git a/gen/shipgen.py b/gen/shipgen.py new file mode 100644 index 00000000..7c04cd7f --- /dev/null +++ b/gen/shipgen.py @@ -0,0 +1,31 @@ +import typing +import pdb +import dcs + +from random import randint + +import globals + +from .conflictgen import * +from .naming import * + +from dcs.mission import * +from dcs.vehicles import * +from dcs.unitgroup import * +from dcs.unittype import * +from dcs.mapping import * +from dcs.point import * +from dcs.task import * + + +class ShipGenerator: + def __init__(self, mission: Mission, conflict: Conflict): + self.m = mission + self.conflict = conflict + + def generate(self, at: Point) -> ShipGroup: + return self.m.ship_group( + country=self.conflict.attackers_side, + name=namegen.next_transport_group_name(), + _type=dcs.ships.CVN_74_John_C__Stennis, + position=at) diff --git a/shop/db.py b/shop/db.py index 50941400..6f3c351f 100644 --- a/shop/db.py +++ b/shop/db.py @@ -17,6 +17,9 @@ PRICES = { A_10A: 18, A_10C: 20, + F_A_18C: 18, + AV8BNA: 15, + Su_27: 30, Su_33: 33, F_15C: 30, @@ -45,7 +48,7 @@ PRICES = { } UNIT_BY_TASK = { - FighterSweep: [Su_27, Su_33, Su_25, F_15C, MiG_15bis, MiG_21Bis, MiG_29A, ], + FighterSweep: [Su_27, Su_33, Su_25, F_15C, MiG_15bis, MiG_21Bis, MiG_29A, F_A_18C, AV8BNA], CAS: [Su_25T, A_10A, A_10C, ], CAP: [Armor.MBT_T_90, Armor.MBT_T_80U, Armor.MBT_T_55, Armor.MBT_M1A2_Abrams, Armor.MBT_M60A3_Patton, Armor.ATGM_M1134_Stryker, Armor.APC_BTR_80, ], AirDefence: [AirDefence.AAA_ZU_23_on_Ural_375, ], @@ -53,14 +56,15 @@ UNIT_BY_TASK = { } UNIT_BY_COUNTRY = { -"Russia": [Su_25T, Su_27, Su_33, Su_25, MiG_15bis, MiG_21Bis, MiG_29A, AirDefence.AAA_ZU_23_on_Ural_375, Armor.APC_BTR_80, Armor.MBT_T_90, Armor.MBT_T_80U, Armor.MBT_T_55, IL_76MD, ], - "USA": [F_15C, A_10C, Armor.MBT_M1A2_Abrams, Armor.MBT_M60A3_Patton, Armor.ATGM_M1134_Stryker, S_3B_Tanker], + "Russia": [Su_25T, Su_27, Su_33, Su_25, MiG_15bis, MiG_21Bis, MiG_29A, AirDefence.AAA_ZU_23_on_Ural_375, Armor.APC_BTR_80, Armor.MBT_T_90, Armor.MBT_T_80U, Armor.MBT_T_55, IL_76MD, ], + "USA": [F_15C, A_10C, F_A_18C, AV8BNA, Armor.MBT_M1A2_Abrams, Armor.MBT_M60A3_Patton, Armor.ATGM_M1134_Stryker, S_3B_Tanker], } UnitsDict = typing.Dict[UnitType, int] PlaneDict = typing.Dict[PlaneType, int] ArmorDict = typing.Dict[VehicleType, int] AirDefenseDict = typing.Dict[AirDefence, int] +StartingPosition = typing.Optional[typing.Union[ShipGroup, Airport, Point]] def unit_task(unit: UnitType) -> Task: diff --git a/submodules/dcs b/submodules/dcs new file mode 160000 index 00000000..d982dfe5 --- /dev/null +++ b/submodules/dcs @@ -0,0 +1 @@ +Subproject commit d982dfe594e16a45851050e8f63cec03c91aeed9 diff --git a/theater/base.py b/theater/base.py index 5964ed72..c727b383 100644 --- a/theater/base.py +++ b/theater/base.py @@ -29,6 +29,7 @@ class Base: self.armor = {} self.aa = {} self.commision_points = {} + self.strength = 1 @property def total_planes(self) -> int: diff --git a/theater/caucasus.py b/theater/caucasus.py index c1e8fc5e..055287f3 100644 --- a/theater/caucasus.py +++ b/theater/caucasus.py @@ -5,28 +5,36 @@ from .base import * class CaucasusTheater(ConflictTheater): - soganlug = ControlPoint(caucasus.Soganlug, ALL_RADIALS, SIZE_SMALL, IMPORTANCE_LOW) - kutaisi = ControlPoint(caucasus.Kutaisi, ALL_RADIALS, SIZE_SMALL, IMPORTANCE_LOW) - senaki = ControlPoint(caucasus.Senaki, ALL_RADIALS, SIZE_REGULAR, IMPORTANCE_LOW) - kobuleti = ControlPoint(caucasus.Kobuleti, COAST_VERTICAL, SIZE_SMALL, IMPORTANCE_LOW) - batumi = ControlPoint(caucasus.Batumi, COAST_VERTICAL, SIZE_SMALL, IMPORTANCE_MEDIUM) - sukhumi = ControlPoint(caucasus.Sukhumi, COAST_VERTICAL, SIZE_REGULAR, IMPORTANCE_MEDIUM) - gudauta = ControlPoint(caucasus.Gudauta, COAST_VERTICAL, SIZE_REGULAR, IMPORTANCE_MEDIUM) - sochi = ControlPoint(caucasus.Sochi, COAST_VERTICAL, SIZE_BIG, IMPORTANCE_HIGH) + reference_points = {(-317948.32727306, 635639.37385346): (282.5, 319), + (-355692.3067714, 617269.96285781): (269, 352), } - maykop = ControlPoint(caucasus.Maykop, ALL_RADIALS, SIZE_LARGE, IMPORTANCE_HIGH) - krasnodar = ControlPoint(caucasus.KrasnodarCenter, ALL_RADIALS, SIZE_LARGE, IMPORTANCE_HIGH) - novorossiysk = ControlPoint(caucasus.Novorossiysk, COAST_VERTICAL, SIZE_BIG, IMPORTANCE_HIGH) - gelendzhik = ControlPoint(caucasus.Gelendzhik, COAST_VERTICAL, SIZE_BIG, IMPORTANCE_HIGH) - krymsk = ControlPoint(caucasus.Krymsk, ALL_RADIALS, SIZE_LARGE, IMPORTANCE_HIGH) - anapa = ControlPoint(caucasus.Anapa, ALL_RADIALS, SIZE_LARGE, IMPORTANCE_HIGH) + soganlug = ControlPoint.from_airport(caucasus.Soganlug, ALL_RADIALS, SIZE_SMALL, IMPORTANCE_LOW) + kutaisi = ControlPoint.from_airport(caucasus.Kutaisi, ALL_RADIALS, SIZE_SMALL, IMPORTANCE_LOW) + senaki = ControlPoint.from_airport(caucasus.Senaki_Kolkhi, ALL_RADIALS, SIZE_REGULAR, IMPORTANCE_LOW) + kobuleti = ControlPoint.from_airport(caucasus.Kobuleti, COAST_VERTICAL, SIZE_SMALL, IMPORTANCE_LOW) + batumi = ControlPoint.from_airport(caucasus.Batumi, COAST_VERTICAL, SIZE_SMALL, IMPORTANCE_MEDIUM) + sukhumi = ControlPoint.from_airport(caucasus.Sukhumi_Babushara, COAST_VERTICAL, SIZE_REGULAR, IMPORTANCE_MEDIUM) + gudauta = ControlPoint.from_airport(caucasus.Gudauta, COAST_VERTICAL, SIZE_REGULAR, IMPORTANCE_MEDIUM) + sochi = ControlPoint.from_airport(caucasus.Sochi_Adler, COAST_VERTICAL, SIZE_BIG, IMPORTANCE_HIGH) - beslan = ControlPoint(caucasus.Beslan, ALL_RADIALS, SIZE_REGULAR, IMPORTANCE_MEDIUM) - nalchik = ControlPoint(caucasus.Nalchik, ALL_RADIALS, SIZE_REGULAR, IMPORTANCE_MEDIUM) - mineralnye = ControlPoint(caucasus.Mineralnye, ALL_RADIALS, SIZE_BIG, IMPORTANCE_HIGH) - mozdok = ControlPoint(caucasus.Mozdok, ALL_RADIALS, SIZE_BIG, IMPORTANCE_HIGH) + gelendzhik = ControlPoint.from_airport(caucasus.Gelendzhik, COAST_VERTICAL, SIZE_BIG, IMPORTANCE_MEDIUM) + maykop = ControlPoint.from_airport(caucasus.Maykop_Khanskaya, ALL_RADIALS, SIZE_LARGE, IMPORTANCE_HIGH) + krasnodar = ControlPoint.from_airport(caucasus.Krasnodar_Center, ALL_RADIALS, SIZE_LARGE, IMPORTANCE_HIGH) + novorossiysk = ControlPoint.from_airport(caucasus.Novorossiysk, COAST_VERTICAL, SIZE_BIG, IMPORTANCE_MEDIUM) + krymsk = ControlPoint.from_airport(caucasus.Krymsk, ALL_RADIALS, SIZE_LARGE, IMPORTANCE_HIGH) + anapa = ControlPoint.from_airport(caucasus.Anapa_Vityazevo, ALL_RADIALS, SIZE_LARGE, IMPORTANCE_HIGH) + + beslan = ControlPoint.from_airport(caucasus.Beslan, ALL_RADIALS, SIZE_REGULAR, IMPORTANCE_LOW) + nalchik = ControlPoint.from_airport(caucasus.Nalchik, ALL_RADIALS, SIZE_REGULAR, IMPORTANCE_LOW) + mineralnye = ControlPoint.from_airport(caucasus.Mineralnye_Vody, ALL_RADIALS, SIZE_BIG, IMPORTANCE_MEDIUM) + mozdok = ControlPoint.from_airport(caucasus.Mozdok, ALL_RADIALS, SIZE_BIG, IMPORTANCE_MEDIUM) + + carrier_1 = ControlPoint.carrier("Carrier", mapping.Point(-355810.6875, 516399.1875)) def __init__(self): + super(CaucasusTheater, self).__init__() + + self.carrier_1.captured = True self.soganlug.captured = True self.add_controlpoint(self.soganlug, connected_to=[self.kutaisi, self.beslan]) @@ -49,3 +57,5 @@ class CaucasusTheater(ConflictTheater): self.add_controlpoint(self.krymsk, connected_to=[self.novorossiysk, self.anapa, self.krasnodar]) self.add_controlpoint(self.anapa, connected_to=[self.novorossiysk, self.krymsk]) self.add_controlpoint(self.krasnodar, connected_to=[self.krymsk, self.maykop]) + + self.add_controlpoint(self.carrier_1) diff --git a/theater/conflicttheater.py b/theater/conflicttheater.py index b82abda4..9aba464d 100644 --- a/theater/conflicttheater.py +++ b/theater/conflicttheater.py @@ -20,7 +20,8 @@ COAST_HORIZONTAL = [315, 0, 45, ] class ConflictTheater: - controlpoints = [] # type: typing.List[ControlPoint] + controlpoints = None # type: typing.Collection[ControlPoint] + reference_points = None # type: typing.Dict def __init__(self): self.controlpoints = [] diff --git a/theater/controlpoint.py b/theater/controlpoint.py index e5446497..762dd50c 100644 --- a/theater/controlpoint.py +++ b/theater/controlpoint.py @@ -13,14 +13,15 @@ class ControlPoint: position = None # type: Point captured = False base: None # type: theater.base.Base - airport: None # type: Airport + at: None # type: db.StartPosition - def __init__(self, airport: Airport, radials: typing.Collection[int], size: int, importance: int): + def __init__(self, name: str, position: Point, at, radials: typing.Collection[int], size: int, importance: int): import theater.base - self.name = airport.name - self.position = airport.position - self.airport = airport + self.name = name + self.position = position + self.at = at + self.size = size self.importance = importance self.captured = False @@ -28,9 +29,22 @@ class ControlPoint: self.connected_points = [] self.base = theater.base.Base() + @classmethod + def from_airport(cls, airport: Airport, radials: typing.Collection[int], size: int, importance: int): + return cls(airport.name, airport.position, airport, radials, size, importance) + + @classmethod + def carrier(cls, name: str, at: Point): + import theater.conflicttheater + return cls(name, at, at, theater.conflicttheater.ALL_RADIALS, theater.conflicttheater.SIZE_SMALL, 1) + def __str__(self): return self.name + @property + def is_global(self): + return not self.connected_points + def connect(self, to): self.connected_points.append(to) @@ -61,5 +75,3 @@ class ControlPoint: position=self.position, size=self.size, radials=self.radials) - - diff --git a/theater/start_generator.py b/theater/start_generator.py index c46577d4..97c1059a 100644 --- a/theater/start_generator.py +++ b/theater/start_generator.py @@ -19,11 +19,12 @@ def generate_initial(theater: ConflictTheater, enemy: str): for task in [CAP, FighterSweep, CAS, AirDefence]: suitable_unittypes = db.find_unittype(task, enemy) - suitable_unittypes.sort(key=lambda x: db.PRICES[x]) + suitable_unittypes.sort(key=lambda x: db.PRICES[x], reverse=True) - importance = cp.importance * 10 - 10 - units_idx_start = int(importance * UNIT_VARIETY) + importance = IMPORTANCE_HIGH * 10 - cp.importance * 10 + units_idx_start = int(importance) units_idx_end = units_idx_start + UNIT_VARIETY + print("{} - {}-{}".format(cp.name, units_idx_start, units_idx_end)) range_start = min(len(suitable_unittypes)-1, units_idx_start) range_end = min(len(suitable_unittypes), units_idx_end) @@ -31,5 +32,4 @@ def generate_initial(theater: ConflictTheater, enemy: str): typecount = max(math.floor(importance * UNIT_AMOUNT_FACTOR), 1) units = {unittype: typecount for unittype in unittypes} - print("{} - {}".format(cp.name, units)) cp.base.commision_units(units) diff --git a/ui/mainmenu.py b/ui/mainmenu.py index 0412ace3..0a9dddfd 100644 --- a/ui/mainmenu.py +++ b/ui/mainmenu.py @@ -15,10 +15,6 @@ class MainMenu(Menu): def __init__(self, window: Window, parent, game: Game): super(MainMenu, self).__init__(window, parent, game) - #self.image = PhotoImage(file="resources/caumap.gif") - #map = Label(window.left_pane, image=self.image) - #map.grid() - self.upd = OverviewCanvas(self.window.left_pane, self, game) self.upd.update() diff --git a/ui/overviewcanvas.py b/ui/overviewcanvas.py index b124f046..9e1032f4 100644 --- a/ui/overviewcanvas.py +++ b/ui/overviewcanvas.py @@ -4,6 +4,7 @@ from tkinter.ttk import * from ui.window import * from game.game import * +from theater.conflicttheater import * class OverviewCanvas: @@ -18,11 +19,11 @@ class OverviewCanvas: self.game = game def cp_coordinates(self, cp: ControlPoint) -> (int, int): - point_a = (-317948.32727306, 635639.37385346) - point_a_img = 282.5, 319 + point_a = list(self.game.theater.reference_points.keys())[0] + point_a_img = self.game.theater.reference_points[point_a] - point_b = (-355692.3067714, 617269.96285781) - point_b_img = 269, 352 + point_b = list(self.game.theater.reference_points.keys())[1] + point_b_img = self.game.theater.reference_points[point_b] x_dist = point_a_img[0] - point_b_img[0] lon_dist = point_a[1] - point_b[1]