Compare commits

...

28 Commits

Author SHA1 Message Date
Vasyl Horbachenko
12853feec3 updated version check 2018-09-11 03:35:52 +03:00
Vasyl Horbachenko
d31876b65e FARP spawn for helis on frontline cas; updated ground object placements 2018-09-11 03:12:33 +03:00
Vasyl Horbachenko
ca521e7e51 FARPs for heli flights WIP 2018-09-10 23:12:04 +03:00
Vasyl Horbachenko
f21c515d5c convert resource files to gif 2018-09-10 21:46:34 +03:00
Vasyl Horbachenko
fa5259d1f2 minor fixes before rc 2018-09-10 01:48:38 +03:00
Vasyl Horbachenko
7a5361c057 minor updates and strike mission objects expand 2018-09-10 01:38:50 +03:00
Vasyl Horbachenko
40bfb6fa88 strike operations fixes 2018-09-09 23:56:30 +03:00
Vasyl Horbachenko
61a237d1ae proper settings for barcap 2018-09-09 20:57:32 +03:00
Vasyl Horbachenko
cf7276b528 updated AA units 2018-09-09 20:39:49 +03:00
Vasyl Horbachenko
67f69d0a7f updated AA units 2018-09-09 20:27:53 +03:00
Vasyl Horbachenko
a918914431 dont limit aircraft to predefined role; better scrambling screen 2018-09-09 20:21:07 +03:00
Vasyl Horbachenko
4ba1dd87e8 updates to strike missions; frontline operations invalid units placement fixed; minor UI updates 2018-09-09 04:15:44 +03:00
Vasyl Horbachenko
e0d82da6cb save game version check; mission description in briefings; minor fixes and improvements; predefined ground objects (statics) support; strike mission WIP 2018-09-09 01:21:32 +03:00
Vasyl Horbachenko
2179e4af47 Merge pull request #12 from Khopa/ui_dev
Modified UI Style
2018-09-08 19:15:52 +03:00
Khopa
75d734d6e4 Typo in UI 2018-08-09 13:08:07 +02:00
Khopa
1d73affa08 New style for event result menu 2018-08-08 23:40:10 +02:00
Khopa
834ee30c86 Style for event result menu 2018-08-08 23:18:49 +02:00
Khopa
d236b8a94d UI alignement in base menu 2018-08-08 22:38:09 +02:00
Khopa
a132cba7ef Changed the color of text on map (easier to read this way for now imo) 2018-08-08 22:30:33 +02:00
Khopa
86706231e0 New style for event/mission menu 2018-08-08 22:30:12 +02:00
Khopa
5eb921948a Display the units x/x/x value of the base in the base menu. 2018-08-08 21:52:09 +02:00
Khopa
fd54a5f86c Display the name of the base in base menu 2018-08-08 21:41:16 +02:00
Khopa
1b2ad5b419 Improved style of main menu, configuration menu, and base menu 2018-08-08 21:22:00 +02:00
Khopa
14cd54668e Improved style of new game menu 2018-08-08 18:45:25 +02:00
Khopa
2047089b64 Added icon to ui windows. 2018-08-08 16:27:42 +02:00
Khopa
ee924ef36e Added title name to UI window 2018-08-08 16:24:20 +02:00
Vasyl Horbachenko
f9c1dd980b spamram for fa18; non-randomized groups vertical separation on spawn; argument to affect DCS folder selection 2018-08-04 04:35:27 +03:00
Vasyl Horbachenko
74c1861240 build archieve tool 2018-07-31 23:40:35 +03:00
68 changed files with 1612 additions and 862 deletions

View File

@@ -1,7 +1,9 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import os import os
import re
import sys import sys
import dcs import dcs
import logging
import theater.caucasus import theater.caucasus
import theater.persiangulf import theater.persiangulf
@@ -14,11 +16,16 @@ import ui.corruptedsavemenu
from game.game import Game from game.game import Game
from theater import start_generator from theater import start_generator
from userdata import persistency, logging from userdata import persistency, logging as logging_module
assert len(sys.argv) >= 3, "__init__.py should be started with two mandatory arguments: %UserProfile% location and application version"
persistency.setup(sys.argv[1]) persistency.setup(sys.argv[1])
dcs.planes.FlyingType.payload_dirs.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), "resources\\payloads")) dcs.planes.FlyingType.payload_dirs = [os.path.join(os.path.dirname(os.path.realpath(__file__)), "resources\\payloads")]
VERSION_STRING = sys.argv[2]
logging_module.setup_version_string(VERSION_STRING)
logging.info("Using {} as userdata folder".format(persistency.base_path()))
def proceed_to_main_menu(game: Game): def proceed_to_main_menu(game: Game):
@@ -26,10 +33,29 @@ def proceed_to_main_menu(game: Game):
m.display() m.display()
def is_version_compatible(save_version):
current_version_components = re.split(r"[\._]", VERSION_STRING)
save_version_components = re.split(r"[\._]", save_version)
if "--ignore-save" in sys.argv:
return False
if current_version_components == save_version_components:
return True
if save_version == "1.4_rc1":
return False
if current_version_components[:2] == save_version_components[:2]:
return True
return False
w = ui.window.Window() w = ui.window.Window()
try: try:
game = persistency.restore_game() game = persistency.restore_game()
if not game: if not game or not is_version_compatible(game.settings.version):
new_game_menu = None # type: NewGameMenu new_game_menu = None # type: NewGameMenu
def start_new_game(player_name: str, enemy_name: str, terrain: str, sams: bool, midgame: bool, multiplier: float): def start_new_game(player_name: str, enemy_name: str, terrain: str, sams: bool, midgame: bool, multiplier: float):
@@ -51,6 +77,7 @@ try:
game.budget = int(game.budget * multiplier) game.budget = int(game.budget * multiplier)
game.settings.multiplier = multiplier game.settings.multiplier = multiplier
game.settings.sams = sams game.settings.sams = sams
game.settings.version = VERSION_STRING
if midgame: if midgame:
game.budget = game.budget * 4 * len(list(conflicttheater.conflicts())) game.budget = game.budget * 4 * len(list(conflicttheater.conflicts()))
@@ -60,8 +87,10 @@ try:
new_game_menu = ui.newgamemenu.NewGameMenu(w, start_new_game) new_game_menu = ui.newgamemenu.NewGameMenu(w, start_new_game)
new_game_menu.display() new_game_menu.display()
else: else:
game.settings.version = VERSION_STRING
proceed_to_main_menu(game) proceed_to_main_menu(game)
except Exception as e: except Exception as e:
logging.exception(e)
ui.corruptedsavemenu.CorruptedSaveMenu(w).display() ui.corruptedsavemenu.CorruptedSaveMenu(w).display()
w.run() w.run()

View File

@@ -1,4 +1,5 @@
import typing import typing
import enum
from dcs.vehicles import * from dcs.vehicles import *
from dcs.unitgroup import * from dcs.unitgroup import *
@@ -99,13 +100,11 @@ PRICES = {
Unarmed.Transport_M818: 3, Unarmed.Transport_M818: 3,
AirDefence.AAA_Vulcan_M163: 5, AirDefence.AAA_Vulcan_M163: 5,
AirDefence.SAM_Avenger_M1097: 10, AirDefence.SAM_Linebacker_M6: 10,
AirDefence.SAM_Patriot_ICC: 15,
AirDefence.AAA_ZU_23_on_Ural_375: 5, AirDefence.SPAAA_ZSU_23_4_Shilka: 8,
AirDefence.SAM_SA_18_Igla_S_MANPADS: 8, AirDefence.SAM_SA_9_Strela_1_9P31: 13,
AirDefence.SAM_SA_19_Tunguska_2S6: 15, AirDefence.SAM_SA_8_Osa_9A33: 18,
AirDefence.SAM_SA_8_Osa_9A33: 13,
# ship # ship
CV_1143_5_Admiral_Kuznetsov: 100, CV_1143_5_Admiral_Kuznetsov: 100,
@@ -182,17 +181,15 @@ UNIT_BY_TASK = {
# those are listed multiple times here to balance prioritization more into lower tier AAs # those are listed multiple times here to balance prioritization more into lower tier AAs
AirDefence.AAA_Vulcan_M163, AirDefence.AAA_Vulcan_M163,
AirDefence.AAA_Vulcan_M163, AirDefence.AAA_Vulcan_M163,
AirDefence.SAM_Avenger_M1097, AirDefence.AAA_Vulcan_M163,
AirDefence.SAM_Avenger_M1097, AirDefence.SAM_Linebacker_M6,
AirDefence.SAM_Avenger_M1097,
AirDefence.SAM_Patriot_ICC,
AirDefence.AAA_ZU_23_on_Ural_375, AirDefence.SPAAA_ZSU_23_4_Shilka,
AirDefence.AAA_ZU_23_on_Ural_375, AirDefence.SPAAA_ZSU_23_4_Shilka,
AirDefence.AAA_ZU_23_on_Ural_375, AirDefence.SPAAA_ZSU_23_4_Shilka,
AirDefence.SAM_SA_9_Strela_1_9P31,
AirDefence.SAM_SA_9_Strela_1_9P31,
AirDefence.SAM_SA_8_Osa_9A33, AirDefence.SAM_SA_8_Osa_9A33,
AirDefence.SAM_SA_8_Osa_9A33,
AirDefence.SAM_SA_19_Tunguska_2S6,
], ],
Reconnaissance: [Unarmed.Transport_M818, Unarmed.Transport_Ural_375, Unarmed.Transport_UAZ_469], Reconnaissance: [Unarmed.Transport_M818, Unarmed.Transport_Ural_375, Unarmed.Transport_UAZ_469],
@@ -207,10 +204,9 @@ UNIT_BY_TASK = {
Units from AirDefense category of UNIT_BY_TASK that will be removed from use if "No SAM" option is checked at the start of the game Units from AirDefense category of UNIT_BY_TASK that will be removed from use if "No SAM" option is checked at the start of the game
""" """
SAM_BAN = [ SAM_BAN = [
AirDefence.SAM_Avenger_M1097, AirDefence.SAM_Linebacker_M6,
AirDefence.SAM_Patriot_ICC,
AirDefence.SAM_SA_19_Tunguska_2S6, AirDefence.SAM_SA_9_Strela_1_9P31,
AirDefence.SAM_SA_8_Osa_9A33, AirDefence.SAM_SA_8_Osa_9A33,
] ]
@@ -232,8 +228,8 @@ CARRIER_TAKEOFF_BAN = [
AirDefense units that will be spawned at control points not related to the current operation AirDefense units that will be spawned at control points not related to the current operation
""" """
EXTRA_AA = { EXTRA_AA = {
"Russia": AirDefence.SAM_SA_9_Strela_1_9P31, "Russia": AirDefence.SAM_SA_19_Tunguska_2S6,
"USA": AirDefence.SAM_Patriot_EPP_III, "USA": AirDefence.SAM_Linebacker_M6,
} }
""" """
@@ -270,10 +266,9 @@ UNIT_BY_COUNTRY = {
UH_1H, UH_1H,
Mi_8MT, Mi_8MT,
AirDefence.AAA_ZU_23_on_Ural_375, AirDefence.SPAAA_ZSU_23_4_Shilka,
AirDefence.SAM_SA_18_Igla_S_MANPADS, AirDefence.SAM_SA_9_Strela_1_9P31,
AirDefence.SAM_SA_8_Osa_9A33, AirDefence.SAM_SA_8_Osa_9A33,
AirDefence.SAM_SA_19_Tunguska_2S6,
Armor.APC_BTR_80, Armor.APC_BTR_80,
Armor.MBT_T_90, Armor.MBT_T_90,
@@ -317,8 +312,7 @@ UNIT_BY_COUNTRY = {
Infantry.Infantry_M4, Infantry.Infantry_M4,
AirDefence.AAA_Vulcan_M163, AirDefence.AAA_Vulcan_M163,
AirDefence.SAM_Avenger_M1097, AirDefence.SAM_Linebacker_M6,
AirDefence.SAM_Patriot_ICC,
CVN_74_John_C__Stennis, CVN_74_John_C__Stennis,
LHA_1_Tarawa, LHA_1_Tarawa,
@@ -343,11 +337,11 @@ Payload will be used for operation of following type, "*" category will be used
""" """
PLANE_PAYLOAD_OVERRIDES = { PLANE_PAYLOAD_OVERRIDES = {
FA_18C_hornet: { FA_18C_hornet: {
"*": "AIM-9M*6, AIM-7M*2, FUEL*3", CAP: "AIM-120*4,AIM-9*2,AIM-7*2,Fuel",
}, },
Su_33: { Su_33: {
"*": "R-73*4,R-27R*2,R-27ER*6", CAP: "R-73*4,R-27R*2,R-27ER*6",
}, },
AJS37: { AJS37: {
@@ -360,18 +354,20 @@ PLANE_PAYLOAD_OVERRIDES = {
A_10C: { A_10C: {
CAS: "AGM-65D*2,AGM-65H*2,GBU-12*2,GBU-38*2,AIM-9*2,TGP,ECM,MK151*7", CAS: "AGM-65D*2,AGM-65H*2,GBU-12*2,GBU-38*2,AIM-9*2,TGP,ECM,MK151*7",
GroundAttack: "AGM-65K*2,GBU-12*8,AIM-9M*2.ECM,TGP",
}, },
Ka_50: { Ka_50: {
"*": "12x9A4172, 40xS-8", CAS: "12x9A4172, 40xS-8",
GroundAttack: "12x9A4172, 40xS-8",
}, },
M_2000C: { M_2000C: {
"*": "Combat Air Patrol", CAP: "Combat Air Patrol",
}, },
MiG_21Bis: { MiG_21Bis: {
"*": "Patrol, medium range", CAP: "Patrol, medium range",
} }
} }
@@ -397,7 +393,11 @@ HeliDict = typing.Dict[HelicopterType, int]
ArmorDict = typing.Dict[VehicleType, int] ArmorDict = typing.Dict[VehicleType, int]
ShipDict = typing.Dict[ShipType, int] ShipDict = typing.Dict[ShipType, int]
AirDefenseDict = typing.Dict[AirDefence, int] AirDefenseDict = typing.Dict[AirDefence, int]
StartingPosition = typing.Optional[typing.Union[ShipGroup, Airport, Point]]
AssignedUnitsDict = typing.Dict[typing.Type[UnitType], typing.Tuple[int, int]]
TaskForceDict = typing.Dict[typing.Type[Task], AssignedUnitsDict]
StartingPosition = typing.Optional[typing.Union[ShipGroup, StaticGroup, Airport, Point]]
def unit_task(unit: UnitType) -> Task: def unit_task(unit: UnitType) -> Task:
@@ -476,6 +476,39 @@ def unitdict_restrict_count(unit_dict: UnitsDict, total_count: int) -> UnitsDict
return {} return {}
def assigned_units_split(fd: AssignedUnitsDict) -> typing.Tuple[PlaneDict, PlaneDict]:
return {k: v1 for k, (v1, v2) in fd.items()}, {k: v2 for k, (v1, v2) in fd.items()},
def assigned_units_from(d: PlaneDict) -> AssignedUnitsDict:
return {k: (v, 0) for k, v in d.items()}
def assignedunits_split_to_count(dict: AssignedUnitsDict, count: int):
buffer_dict = {}
for unit_type, (unit_count, client_count) in dict.items():
for _ in range(unit_count):
new_count, new_client_count = buffer_dict.get(unit_type, (0, 0))
new_count += 1
if client_count > 0:
new_client_count += 1
client_count -= 1
buffer_dict[unit_type] = new_count, new_client_count
if new_count >= count:
yield buffer_dict
buffer_dict = {}
if len(buffer_dict):
yield buffer_dict
def unitdict_from(fd: AssignedUnitsDict) -> Dict:
return {k: v1 for k, (v1, v2) in fd.items()}
def _validate_db(): def _validate_db():
# check unit by task uniquity # check unit by task uniquity
total_set = set() total_set = set()

View File

@@ -4,6 +4,6 @@ from .frontlinepatrol import *
from .intercept import * from .intercept import *
from .baseattack import * from .baseattack import *
from .navalintercept import * from .navalintercept import *
from .antiaastrike import *
from .insurgentattack import * from .insurgentattack import *
from .infantrytransport import * from .infantrytransport import *
from .strike import *

View File

@@ -1,86 +0,0 @@
import math
import random
from dcs.task import *
from game import *
from game.event import *
from game.operation.antiaastrike import AntiAAStrikeOperation
from userdata.debriefing import Debriefing
class AntiAAStrikeEvent(Event):
TARGET_AMOUNT_MAX = 2
STRENGTH_INFLUENCE = 0.3
SUCCESS_TARGETS_HIT_PERCENTAGE = 0.5
targets = None # type: db.ArmorDict
def __str__(self):
return "Anti-AA strike"
def is_successfull(self, debriefing: Debriefing):
total_targets = sum(self.targets.values())
destroyed_targets = 0
for unit, count in debriefing.destroyed_units[self.defender_name].items():
if unit in self.targets:
destroyed_targets += count
if self.from_cp.captured:
return math.ceil(float(destroyed_targets) / total_targets) >= self.SUCCESS_TARGETS_HIT_PERCENTAGE
else:
return math.ceil(float(destroyed_targets) / total_targets) < self.SUCCESS_TARGETS_HIT_PERCENTAGE
def commit(self, debriefing: Debriefing):
super(AntiAAStrikeEvent, self).commit(debriefing)
if self.from_cp.captured:
if self.is_successfull(debriefing):
self.to_cp.base.affect_strength(-self.STRENGTH_INFLUENCE)
else:
self.to_cp.base.affect_strength(+self.STRENGTH_INFLUENCE)
else:
if self.is_successfull(debriefing):
self.from_cp.base.affect_strength(-self.STRENGTH_INFLUENCE)
else:
self.to_cp.base.affect_strength(-self.STRENGTH_INFLUENCE)
def skip(self):
if self.to_cp.captured:
self.to_cp.base.affect_strength(-0.1)
def player_attacking(self, strikegroup: db.PlaneDict, clients: db.PlaneDict):
self.targets = self.to_cp.base.assemble_aa(count=self.to_cp.base.total_aa)
op = AntiAAStrikeOperation(game=self.game,
attacker_name=self.attacker_name,
defender_name=self.defender_name,
attacker_clients=clients,
defender_clients={},
from_cp=self.from_cp,
to_cp=self.to_cp)
op.setup(target=self.targets,
strikegroup=strikegroup,
interceptors={})
self.operation = op
def player_defending(self, interceptors: db.PlaneDict, clients: db.PlaneDict):
self.targets = self.to_cp.base.assemble_aa()
op = AntiAAStrikeOperation(
self.game,
attacker_name=self.attacker_name,
defender_name=self.defender_name,
attacker_clients={},
defender_clients=clients,
from_cp=self.from_cp,
to_cp=self.to_cp
)
strikegroup = self.from_cp.base.scramble_cas(self.game.settings.multiplier)
op.setup(target=self.targets,
strikegroup=strikegroup,
interceptors=interceptors)
self.operation = op

View File

@@ -1,13 +1,7 @@
import math
import random
from dcs.task import *
from game import db
from game.operation.baseattack import BaseAttackOperation from game.operation.baseattack import BaseAttackOperation
from userdata.debriefing import Debriefing
from .event import Event from .event import *
from game.db import assigned_units_from
class BaseAttackEvent(Event): class BaseAttackEvent(Event):
@@ -18,6 +12,18 @@ class BaseAttackEvent(Event):
def __str__(self): def __str__(self):
return "Base attack" return "Base attack"
@property
def tasks(self):
return [CAP, CAS, PinpointStrike]
def flight_name(self, for_task: typing.Type[Task]) -> str:
if for_task == CAP:
return "Escort flight"
elif for_task == CAS:
return "CAS flight"
elif for_task == PinpointStrike:
return "Ground attack"
def is_successfull(self, debriefing: Debriefing): def is_successfull(self, debriefing: Debriefing):
alive_attackers = sum([v for k, v in debriefing.alive_units[self.attacker_name].items() if db.unit_task(k) == PinpointStrike]) alive_attackers = sum([v for k, v in debriefing.alive_units[self.attacker_name].items() if db.unit_task(k) == PinpointStrike])
alive_defenders = sum([v for k, v in debriefing.alive_units[self.defender_name].items() if db.unit_task(k) == PinpointStrike]) alive_defenders = sum([v for k, v in debriefing.alive_units[self.defender_name].items() if db.unit_task(k) == PinpointStrike])
@@ -32,6 +38,7 @@ class BaseAttackEvent(Event):
if self.is_successfull(debriefing): if self.is_successfull(debriefing):
if self.from_cp.captured: if self.from_cp.captured:
self.to_cp.captured = True self.to_cp.captured = True
self.to_cp.ground_objects = []
self.to_cp.base.filter_units(db.UNIT_BY_COUNTRY[self.attacker_name]) self.to_cp.base.filter_units(db.UNIT_BY_COUNTRY[self.attacker_name])
self.to_cp.base.affect_strength(+self.STRENGTH_RECOVERY) self.to_cp.base.affect_strength(+self.STRENGTH_RECOVERY)
@@ -44,7 +51,9 @@ class BaseAttackEvent(Event):
if not self.is_player_attacking and self.to_cp.captured: if not self.is_player_attacking and self.to_cp.captured:
self.to_cp.captured = False self.to_cp.captured = False
def player_defending(self, interceptors: db.PlaneDict, clients: db.PlaneDict): def player_defending(self, flights: db.TaskForceDict):
assert CAP in flights and len(flights) == 1, "Invalid scrambled flights"
cas = self.from_cp.base.scramble_cas(self.game.settings.multiplier) cas = self.from_cp.base.scramble_cas(self.game.settings.multiplier)
escort = self.from_cp.base.scramble_sweep(self.game.settings.multiplier) escort = self.from_cp.base.scramble_sweep(self.game.settings.multiplier)
attackers = self.from_cp.base.armor attackers = self.from_cp.base.armor
@@ -52,36 +61,34 @@ class BaseAttackEvent(Event):
op = BaseAttackOperation(game=self.game, op = BaseAttackOperation(game=self.game,
attacker_name=self.attacker_name, attacker_name=self.attacker_name,
defender_name=self.defender_name, defender_name=self.defender_name,
attacker_clients={},
defender_clients=clients,
from_cp=self.from_cp, from_cp=self.from_cp,
to_cp=self.to_cp) to_cp=self.to_cp)
op.setup(cas=cas, op.setup(cas=assigned_units_from(cas),
escort=escort, escort=assigned_units_from(escort),
intercept=flights[CAP],
attack=attackers, attack=attackers,
intercept=interceptors,
defense=self.to_cp.base.armor, defense=self.to_cp.base.armor,
aa=self.to_cp.base.aa) aa=self.to_cp.base.aa)
self.operation = op self.operation = op
def player_attacking(self, cas: db.PlaneDict, escort: db.PlaneDict, armor: db.ArmorDict, clients: db.PlaneDict): def player_attacking(self, flights: db.TaskForceDict):
assert CAP in flights and CAS in flights and PinpointStrike in flights and len(flights) == 3, "Invalid flights"
op = BaseAttackOperation(game=self.game, op = BaseAttackOperation(game=self.game,
attacker_name=self.attacker_name, attacker_name=self.attacker_name,
defender_name=self.defender_name, defender_name=self.defender_name,
attacker_clients=clients,
defender_clients={},
from_cp=self.from_cp, from_cp=self.from_cp,
to_cp=self.to_cp) to_cp=self.to_cp)
defenders = self.to_cp.base.scramble_sweep(self.game.settings.multiplier) defenders = self.to_cp.base.scramble_sweep(self.game.settings.multiplier)
defenders.update(self.to_cp.base.scramble_cas(self.game.settings.multiplier)) defenders.update(self.to_cp.base.scramble_cas(self.game.settings.multiplier))
op.setup(cas=cas, op.setup(cas=flights[CAS],
escort=escort, escort=flights[CAP],
attack=armor, attack=flights[PinpointStrike],
intercept=defenders, intercept=assigned_units_from(defenders),
defense=self.to_cp.base.armor, defense=self.to_cp.base.armor,
aa=self.to_cp.base.assemble_aa()) aa=self.to_cp.base.assemble_aa())

View File

@@ -1,8 +1,14 @@
import typing
import logging
from dcs.unittype import UnitType
from dcs.task import *
from dcs.unittype import UnitType from dcs.unittype import UnitType
from game import * from game import *
from theater import * from theater import *
from gen.environmentgen import EnvironmentSettings from gen.environmentgen import EnvironmentSettings
from game.db import assigned_units_from, unitdict_from
from userdata.debriefing import Debriefing from userdata.debriefing import Debriefing
from userdata import persistency from userdata import persistency
@@ -42,12 +48,29 @@ class Event:
def threat_description(self) -> str: def threat_description(self) -> str:
return "" return ""
def flight_name(self, for_task: typing.Type[typing.Type[Task]]) -> str:
return "Flight"
@property
def tasks(self) -> typing.Collection[typing.Type[Task]]:
return []
@property
def ai_banned_tasks(self) -> typing.Collection[typing.Type[Task]]:
return []
def bonus(self) -> int: def bonus(self) -> int:
return int(math.log(self.to_cp.importance + 1, DIFFICULTY_LOG_BASE) * self.BONUS_BASE) return int(math.log(self.to_cp.importance + 1, DIFFICULTY_LOG_BASE) * self.BONUS_BASE)
def is_successfull(self, debriefing: Debriefing) -> bool: def is_successfull(self, debriefing: Debriefing) -> bool:
return self.operation.is_successfull(debriefing) return self.operation.is_successfull(debriefing)
def player_attacking(self, flights: db.TaskForceDict):
assert False
def player_defending(self, flights: db.TaskForceDict):
assert False
def generate(self): def generate(self):
self.operation.is_awacs_enabled = self.is_awacs_enabled self.operation.is_awacs_enabled = self.is_awacs_enabled
@@ -71,8 +94,24 @@ class Event:
else: else:
cp = self.to_cp cp = self.to_cp
logging.info("base {} commit losses {}".format(cp.base, losses))
cp.base.commit_losses(losses) cp.base.commit_losses(losses)
for object_identifier in debriefing.destroyed_objects:
for cp in self.game.theater.controlpoints:
remove_ids = []
if not cp.ground_objects:
continue
for i, ground_object in enumerate(cp.ground_objects):
if ground_object.matches_string_identifier(object_identifier):
logging.info("cp {} removing ground object {}".format(cp, ground_object.string_identifier))
remove_ids.append(i)
remove_ids.reverse()
for i in remove_ids:
del cp.ground_objects[i]
def skip(self): def skip(self):
pass pass

View File

@@ -1,10 +1,3 @@
import math
import random
from dcs.task import *
from dcs.vehicles import AirDefence
from game import *
from game.event import * from game.event import *
from game.operation.frontlineattack import FrontlineAttackOperation from game.operation.frontlineattack import FrontlineAttackOperation
from userdata.debriefing import Debriefing from userdata.debriefing import Debriefing
@@ -24,6 +17,21 @@ class FrontlineAttackEvent(Event):
def threat_description(self): def threat_description(self):
return "{} vehicles".format(self.to_cp.base.assemble_count()) return "{} vehicles".format(self.to_cp.base.assemble_count())
@property
def tasks(self) -> typing.Collection[typing.Type[Task]]:
if self.is_player_attacking:
return [CAS, PinpointStrike]
else:
return [CAP, PinpointStrike]
def flight_name(self, for_task: typing.Type[Task]) -> str:
if for_task == CAS:
return "CAS flight"
elif for_task == CAP:
return "CAP flight"
elif for_task == PinpointStrike:
return "Ground attack"
def __str__(self): def __str__(self):
return "Frontline attack" return "Frontline attack"
@@ -54,20 +62,21 @@ class FrontlineAttackEvent(Event):
if self.to_cp.captured: if self.to_cp.captured:
self.to_cp.base.affect_strength(-0.1) self.to_cp.base.affect_strength(-0.1)
def player_attacking(self, armor: db.ArmorDict, strikegroup: db.PlaneDict, clients: db.PlaneDict): def player_attacking(self, flights: db.TaskForceDict):
assert CAS in flights and PinpointStrike in flights and len(flights) == 2, "Invalid flights"
self.defenders = self.to_cp.base.assemble_attack() self.defenders = self.to_cp.base.assemble_attack()
op = FrontlineAttackOperation(game=self.game, op = FrontlineAttackOperation(game=self.game,
attacker_name=self.attacker_name, attacker_name=self.attacker_name,
defender_name=self.defender_name, defender_name=self.defender_name,
attacker_clients=clients,
defender_clients={},
from_cp=self.from_cp, from_cp=self.from_cp,
to_cp=self.to_cp) to_cp=self.to_cp)
armor = unitdict_from(flights[PinpointStrike])
op.setup(target=self.defenders, op.setup(target=self.defenders,
attackers=db.unitdict_restrict_count(armor, sum(self.defenders.values())), attackers=db.unitdict_restrict_count(armor, sum(self.defenders.values())),
strikegroup=strikegroup) strikegroup=flights[CAS])
self.operation = op self.operation = op

View File

@@ -1,10 +1,3 @@
import math
import random
from dcs.task import *
from dcs.vehicles import AirDefence
from game import *
from game.event import * from game.event import *
from game.operation.frontlinepatrol import FrontlinePatrolOperation from game.operation.frontlinepatrol import FrontlinePatrolOperation
from userdata.debriefing import Debriefing from userdata.debriefing import Debriefing
@@ -22,23 +15,19 @@ class FrontlinePatrolEvent(Event):
def threat_description(self): def threat_description(self):
return "{} aircraft + ? CAS".format(self.to_cp.base.scramble_count(self.game.settings.multiplier * self.ESCORT_FACTOR, CAP)) return "{} aircraft + ? CAS".format(self.to_cp.base.scramble_count(self.game.settings.multiplier * self.ESCORT_FACTOR, CAP))
@property
def tasks(self):
return [CAP, PinpointStrike]
def flight_name(self, for_task: typing.Type[Task]) -> str:
if for_task == CAP:
return "CAP flight"
elif for_task == PinpointStrike:
return "Ground attack"
def __str__(self): def __str__(self):
return "Frontline CAP" return "Frontline CAP"
"""
def is_successfull(self, debriefing: Debriefing):
total_targets = sum(self.cas.values())
destroyed_targets = 0
for unit, count in debriefing.destroyed_units[self.defender_name].items():
if unit in self.cas:
destroyed_targets += count
if self.from_cp.captured:
return float(destroyed_targets) / total_targets >= self.SUCCESS_TARGETS_HIT_PERCENTAGE
else:
return float(destroyed_targets) / total_targets < self.SUCCESS_TARGETS_HIT_PERCENTAGE
"""
def is_successfull(self, debriefing: Debriefing): def is_successfull(self, debriefing: Debriefing):
alive_attackers = sum([v for k, v in debriefing.alive_units[self.attacker_name].items() if db.unit_task(k) == PinpointStrike]) alive_attackers = sum([v for k, v in debriefing.alive_units[self.attacker_name].items() if db.unit_task(k) == PinpointStrike])
alive_defenders = sum([v for k, v in debriefing.alive_units[self.defender_name].items() if db.unit_task(k) == PinpointStrike]) alive_defenders = sum([v for k, v in debriefing.alive_units[self.defender_name].items() if db.unit_task(k) == PinpointStrike])
@@ -65,23 +54,23 @@ class FrontlinePatrolEvent(Event):
def skip(self): def skip(self):
pass pass
def player_attacking(self, interceptors: db.PlaneDict, clients: db.PlaneDict, armor: db.ArmorDict): def player_attacking(self, flights: db.TaskForceDict):
assert CAP in flights and PinpointStrike in flights and len(flights) == 2, "Invalid flights"
self.cas = self.to_cp.base.scramble_cas(self.game.settings.multiplier) self.cas = self.to_cp.base.scramble_cas(self.game.settings.multiplier)
self.escort = self.to_cp.base.scramble_sweep(self.game.settings.multiplier * self.ESCORT_FACTOR) self.escort = self.to_cp.base.scramble_sweep(self.game.settings.multiplier * self.ESCORT_FACTOR)
op = FrontlinePatrolOperation(game=self.game, op = FrontlinePatrolOperation(game=self.game,
attacker_name=self.attacker_name, attacker_name=self.attacker_name,
defender_name=self.defender_name, defender_name=self.defender_name,
attacker_clients=clients,
defender_clients={},
from_cp=self.from_cp, from_cp=self.from_cp,
to_cp=self.to_cp) to_cp=self.to_cp)
defenders = self.to_cp.base.assemble_attack() defenders = self.to_cp.base.assemble_attack()
op.setup(cas=self.cas, op.setup(cas=assigned_units_from(self.cas),
escort=self.escort, escort=assigned_units_from(self.escort),
interceptors=interceptors, interceptors=flights[CAP],
armor_attackers=db.unitdict_restrict_count(armor, sum(defenders.values())), armor_attackers=db.unitdict_restrict_count(dict_from_flight(flights[PinpointStrike]), sum(defenders.values())),
armor_defenders=defenders) armor_defenders=defenders)
self.operation = op self.operation = op

View File

@@ -9,7 +9,7 @@ from game.operation.infantrytransport import InfantryTransportOperation
from theater.conflicttheater import * from theater.conflicttheater import *
from userdata.debriefing import Debriefing from userdata.debriefing import Debriefing
from .event import Event from .event import *
class InfantryTransportEvent(Event): class InfantryTransportEvent(Event):
@@ -18,6 +18,14 @@ class InfantryTransportEvent(Event):
def __str__(self): def __str__(self):
return "Frontline transport troops" return "Frontline transport troops"
@property
def tasks(self):
return [Embarking]
def flight_name(self, for_task: typing.Type[Task]) -> str:
if for_task == Embarking:
return "Transport flight"
def is_successfull(self, debriefing: Debriefing): def is_successfull(self, debriefing: Debriefing):
return True return True
@@ -29,19 +37,19 @@ class InfantryTransportEvent(Event):
else: else:
self.from_cp.base.affect_strength(-self.STRENGTH_INFLUENCE) self.from_cp.base.affect_strength(-self.STRENGTH_INFLUENCE)
def player_attacking(self, transport: db.HeliDict, clients: db.HeliDict): def player_attacking(self, flights: db.TaskForceDict):
assert Embarking in flights and len(flights) == 1, "Invalid flights"
op = InfantryTransportOperation( op = InfantryTransportOperation(
game=self.game, game=self.game,
attacker_name=self.attacker_name, attacker_name=self.attacker_name,
defender_name=self.defender_name, defender_name=self.defender_name,
attacker_clients=clients,
defender_clients={},
from_cp=self.from_cp, from_cp=self.from_cp,
to_cp=self.to_cp to_cp=self.to_cp
) )
air_defense = db.find_unittype(AirDefence, self.defender_name)[0] air_defense = db.find_unittype(AirDefence, self.defender_name)[0]
op.setup(transport=transport, op.setup(transport=flights[Embarking],
aa={air_defense: 2}) aa={air_defense: 2})
self.operation = op self.operation = op

View File

@@ -8,6 +8,8 @@ from game.event import *
from game.event.frontlineattack import FrontlineAttackEvent from game.event.frontlineattack import FrontlineAttackEvent
from game.operation.insurgentattack import InsurgentAttackOperation from game.operation.insurgentattack import InsurgentAttackOperation
from .event import *
class InsurgentAttackEvent(Event): class InsurgentAttackEvent(Event):
SUCCESS_FACTOR = 0.7 SUCCESS_FACTOR = 0.7
@@ -18,6 +20,14 @@ class InsurgentAttackEvent(Event):
def threat_description(self): def threat_description(self):
return "" return ""
@property
def tasks(self):
return [CAS]
def flight_name(self, for_task: typing.Type[Task]) -> str:
if for_task == CAS:
return "Ground intercept flight"
def __str__(self): def __str__(self):
return "Destroy insurgents" return "Destroy insurgents"
@@ -30,7 +40,9 @@ class InsurgentAttackEvent(Event):
else: else:
return not attackers_success return not attackers_success
def player_defending(self, strikegroup: db.PlaneDict, clients: db.PlaneDict): def player_defending(self, flights: db.TaskForceDict):
assert CAS in flights and len(flights) == 1, "Invalid flights"
suitable_unittypes = db.find_unittype(Reconnaissance, self.attacker_name) suitable_unittypes = db.find_unittype(Reconnaissance, self.attacker_name)
random.shuffle(suitable_unittypes) random.shuffle(suitable_unittypes)
unittypes = suitable_unittypes[:self.TARGET_VARIETY] unittypes = suitable_unittypes[:self.TARGET_VARIETY]
@@ -40,14 +52,9 @@ class InsurgentAttackEvent(Event):
op = InsurgentAttackOperation(game=self.game, op = InsurgentAttackOperation(game=self.game,
attacker_name=self.attacker_name, attacker_name=self.attacker_name,
defender_name=self.defender_name, defender_name=self.defender_name,
attacker_clients={},
defender_clients=clients,
from_cp=self.from_cp, from_cp=self.from_cp,
to_cp=self.to_cp) to_cp=self.to_cp)
op.setup(target=self.targets, op.setup(target=self.targets,
strikegroup=strikegroup) strikegroup=flights[CAS])
self.operation = op self.operation = op
def player_attacking(self, interceptors: db.PlaneDict, clients: db.PlaneDict):
assert False

View File

@@ -1,15 +1,6 @@
import math
import random
from dcs.task import *
from dcs.vehicles import *
from game import db
from game.operation.intercept import InterceptOperation from game.operation.intercept import InterceptOperation
from theater.conflicttheater import *
from userdata.debriefing import Debriefing
from .event import Event from .event import *
class InterceptEvent(Event): class InterceptEvent(Event):
@@ -20,7 +11,18 @@ class InterceptEvent(Event):
transport_unit = None # type: FlyingType transport_unit = None # type: FlyingType
def __str__(self): def __str__(self):
return "Intercept" return "Air Intercept"
@property
def tasks(self):
return [CAP]
def flight_name(self, for_task: typing.Type[Task]) -> str:
if for_task == CAP:
if self.is_player_attacking:
return "Intercept flight"
else:
return "Escort flight"
def _enemy_scramble_multiplier(self) -> float: def _enemy_scramble_multiplier(self) -> float:
is_global = self.from_cp.is_global or self.to_cp.is_global is_global = self.from_cp.is_global or self.to_cp.is_global
@@ -57,7 +59,9 @@ class InterceptEvent(Event):
if self.to_cp.captured: if self.to_cp.captured:
self.to_cp.base.affect_strength(-self.STRENGTH_INFLUENCE) self.to_cp.base.affect_strength(-self.STRENGTH_INFLUENCE)
def player_attacking(self, interceptors: db.PlaneDict, clients: db.PlaneDict): def player_attacking(self, flights: db.TaskForceDict):
assert CAP in flights and len(flights) == 1, "Invalid flights"
escort = self.to_cp.base.scramble_sweep(self._enemy_scramble_multiplier()) escort = self.to_cp.base.scramble_sweep(self._enemy_scramble_multiplier())
self.transport_unit = random.choice(db.find_unittype(Transport, self.defender_name)) self.transport_unit = random.choice(db.find_unittype(Transport, self.defender_name))
@@ -67,20 +71,19 @@ class InterceptEvent(Event):
op = InterceptOperation(game=self.game, op = InterceptOperation(game=self.game,
attacker_name=self.attacker_name, attacker_name=self.attacker_name,
defender_name=self.defender_name, defender_name=self.defender_name,
attacker_clients=clients,
defender_clients={},
from_cp=self.from_cp, from_cp=self.from_cp,
to_cp=self.to_cp) to_cp=self.to_cp)
op.setup(escort=escort, op.setup(escort=assigned_units_from(escort),
transport={self.transport_unit: 1}, transport={self.transport_unit: 1},
airdefense={airdefense_unit: self.AIRDEFENSE_COUNT}, airdefense={airdefense_unit: self.AIRDEFENSE_COUNT},
interceptors=interceptors) interceptors=flights[CAP])
self.operation = op self.operation = op
def player_defending(self, escort: db.PlaneDict, clients: db.PlaneDict): def player_defending(self, flights: db.TaskForceDict):
# TODO: even not quick mission is too quick assert CAP in flights and len(flights) == 1, "Invalid flights"
interceptors = self.from_cp.base.scramble_interceptors(self.game.settings.multiplier) interceptors = self.from_cp.base.scramble_interceptors(self.game.settings.multiplier)
self.transport_unit = random.choice(db.find_unittype(Transport, self.defender_name)) self.transport_unit = random.choice(db.find_unittype(Transport, self.defender_name))
@@ -89,14 +92,12 @@ class InterceptEvent(Event):
op = InterceptOperation(game=self.game, op = InterceptOperation(game=self.game,
attacker_name=self.attacker_name, attacker_name=self.attacker_name,
defender_name=self.defender_name, defender_name=self.defender_name,
attacker_clients={},
defender_clients=clients,
from_cp=self.from_cp, from_cp=self.from_cp,
to_cp=self.to_cp) to_cp=self.to_cp)
op.setup(escort=escort, op.setup(escort=flights[CAP],
transport={self.transport_unit: 1}, transport={self.transport_unit: 1},
interceptors=interceptors, interceptors=assigned_units_from(interceptors),
airdefense={}) airdefense={})
self.operation = op self.operation = op

View File

@@ -1,15 +1,6 @@
import typing
import math
import random
from dcs.task import *
from dcs.vehicles import *
from game import db
from game.operation.navalintercept import NavalInterceptionOperation from game.operation.navalintercept import NavalInterceptionOperation
from userdata.debriefing import Debriefing
from .event import Event from .event import *
class NavalInterceptEvent(Event): class NavalInterceptEvent(Event):
@@ -19,13 +10,26 @@ class NavalInterceptEvent(Event):
targets = None # type: db.ShipDict targets = None # type: db.ShipDict
def _targets_count(self) -> int: def _targets_count(self) -> int:
from gen.conflictgen import IMPORTANCE_LOW, IMPORTANCE_HIGH from gen.conflictgen import IMPORTANCE_LOW
factor = (self.to_cp.importance - IMPORTANCE_LOW) * 10 factor = (self.to_cp.importance - IMPORTANCE_LOW) * 10
return max(int(factor), 1) return max(int(factor), 1)
def __str__(self) -> str: def __str__(self) -> str:
return "Naval intercept" return "Naval intercept"
@property
def tasks(self):
if self.is_player_attacking:
return [CAS]
else:
return [CAP]
def flight_name(self, for_task: typing.Type[Task]) -> str:
if for_task == CAS:
return "Naval intercept flight"
elif for_task == CAP:
return "CAP flight"
@property @property
def threat_description(self): def threat_description(self):
s = "{} ship(s)".format(self._targets_count()) s = "{} ship(s)".format(self._targets_count())
@@ -64,7 +68,9 @@ class NavalInterceptEvent(Event):
if self.to_cp.captured: if self.to_cp.captured:
self.to_cp.base.affect_strength(-self.STRENGTH_INFLUENCE) self.to_cp.base.affect_strength(-self.STRENGTH_INFLUENCE)
def player_attacking(self, strikegroup: db.PlaneDict, clients: db.PlaneDict): def player_attacking(self, flights: db.TaskForceDict):
assert CAS in flights and len(flights) == 1, "Invalid flights"
self.targets = { self.targets = {
random.choice(db.find_unittype(CargoTransportation, self.defender_name)): self._targets_count(), random.choice(db.find_unittype(CargoTransportation, self.defender_name)): self._targets_count(),
} }
@@ -73,19 +79,19 @@ class NavalInterceptEvent(Event):
self.game, self.game,
attacker_name=self.attacker_name, attacker_name=self.attacker_name,
defender_name=self.defender_name, defender_name=self.defender_name,
attacker_clients=clients,
defender_clients={},
from_cp=self.from_cp, from_cp=self.from_cp,
to_cp=self.to_cp to_cp=self.to_cp
) )
op.setup(strikegroup=strikegroup, op.setup(strikegroup=flights[CAS],
interceptors={}, interceptors={},
targets=self.targets) targets=self.targets)
self.operation = op self.operation = op
def player_defending(self, interceptors: db.PlaneDict, clients: db.PlaneDict): def player_defending(self, flights: db.TaskForceDict):
assert CAP in flights and len(flights) == 1, "Invalid flights"
self.targets = { self.targets = {
random.choice(db.find_unittype(CargoTransportation, self.defender_name)): self._targets_count(), random.choice(db.find_unittype(CargoTransportation, self.defender_name)): self._targets_count(),
} }
@@ -94,15 +100,13 @@ class NavalInterceptEvent(Event):
self.game, self.game,
attacker_name=self.attacker_name, attacker_name=self.attacker_name,
defender_name=self.defender_name, defender_name=self.defender_name,
attacker_clients={},
defender_clients=clients,
from_cp=self.from_cp, from_cp=self.from_cp,
to_cp=self.to_cp to_cp=self.to_cp
) )
strikegroup = self.from_cp.base.scramble_cas(self.game.settings.multiplier) strikegroup = self.from_cp.base.scramble_cas(self.game.settings.multiplier)
op.setup(strikegroup=strikegroup, op.setup(strikegroup=assigned_units_from(strikegroup),
interceptors=interceptors, interceptors=flights[CAP],
targets=self.targets) targets=self.targets)
self.operation = op self.operation = op

60
game/event/strike.py Normal file
View File

@@ -0,0 +1,60 @@
from game.operation.strike import StrikeOperation
from .event import *
class StrikeEvent(Event):
STRENGTH_INFLUENCE = 0.0
SINGLE_OBJECT_STRENGTH_INFLUENCE = 0.03
def __str__(self):
return "Strike"
def is_successfull(self, debriefing: Debriefing):
return True
@property
def threat_description(self):
return "{} aircraft + AA".format(self.to_cp.base.scramble_count(self.game.settings.multiplier, CAP))
@property
def tasks(self):
if self.is_player_attacking:
return [CAP, CAS]
else:
return [CAP]
@property
def ai_banned_tasks(self):
return [CAS]
def flight_name(self, for_task: typing.Type[Task]) -> str:
if for_task == CAP:
if self.is_player_attacking:
return "Escort flight"
else:
return "CAP flight"
elif for_task == CAS:
return "Strike flight"
def commit(self, debriefing: Debriefing):
super(StrikeEvent, self).commit(debriefing)
self.to_cp.base.affect_strength(-self.SINGLE_OBJECT_STRENGTH_INFLUENCE * len(debriefing.destroyed_objects))
def player_attacking(self, flights: db.TaskForceDict):
assert CAP in flights and CAS in flights and len(flights) == 2, "Invalid flights"
op = StrikeOperation(
self.game,
attacker_name=self.attacker_name,
defender_name=self.defender_name,
from_cp=self.from_cp,
to_cp=self.to_cp
)
interceptors = self.to_cp.base.scramble_interceptors(self.game.settings.multiplier)
op.setup(strikegroup=flights[CAS],
escort=flights[CAP],
interceptors=assigned_units_from(interceptors))
self.operation = op

View File

@@ -52,10 +52,10 @@ EVENT_PROBABILITIES = {
BaseAttackEvent: [100, 10], BaseAttackEvent: [100, 10],
FrontlineAttackEvent: [100, 0], FrontlineAttackEvent: [100, 0],
FrontlinePatrolEvent: [100, 0], FrontlinePatrolEvent: [100, 0],
StrikeEvent: [100, 0],
InterceptEvent: [25, 10], InterceptEvent: [25, 10],
InsurgentAttackEvent: [0, 10], InsurgentAttackEvent: [0, 10],
NavalInterceptEvent: [25, 10], NavalInterceptEvent: [25, 10],
AntiAAStrikeEvent: [25, 10],
InfantryTransportEvent: [25, 0], InfantryTransportEvent: [25, 0],
} }
@@ -120,15 +120,18 @@ class Game:
if not Conflict.has_frontline_between(player_cp, enemy_cp): if not Conflict.has_frontline_between(player_cp, enemy_cp):
continue continue
if self._roll(player_probability, player_cp.base.strength): if player_probability == 100 or self._roll(player_probability, player_cp.base.strength):
if event_class == NavalInterceptEvent and enemy_cp.radials == LAND: if event_class == NavalInterceptEvent and enemy_cp.radials == LAND:
pass pass
else: else:
if event_class == BaseAttackEvent and enemy_cp.base.strength > PLAYER_BASEATTACK_THRESHOLD: if event_class == BaseAttackEvent and enemy_cp.base.strength > PLAYER_BASEATTACK_THRESHOLD:
pass pass
else: else:
self.events.append(event_class(self.player, self.enemy, player_cp, enemy_cp, self)) if event_class == StrikeEvent and not enemy_cp.ground_objects:
elif self._roll(enemy_probability, enemy_cp.base.strength): pass
else:
self.events.append(event_class(self.player, self.enemy, player_cp, enemy_cp, self))
elif enemy_probability == 100 or self._roll(enemy_probability, enemy_cp.base.strength):
if event_class in enemy_generated_types: if event_class in enemy_generated_types:
continue continue
@@ -141,15 +144,15 @@ class Game:
if event_class == NavalInterceptEvent: if event_class == NavalInterceptEvent:
if player_cp.radials == LAND: if player_cp.radials == LAND:
continue continue
elif event_class == StrikeEvent:
if not player_cp.ground_objects:
continue
elif event_class == BaseAttackEvent: elif event_class == BaseAttackEvent:
if enemy_cap_generated: if enemy_cap_generated:
continue continue
if enemy_cp.base.total_armor == 0: if enemy_cp.base.total_armor == 0:
continue continue
enemy_cap_generated = True enemy_cap_generated = True
elif event_class == AntiAAStrikeEvent:
if player_cp.base.total_aa == 0:
continue
enemy_generated_types.append(event_class) enemy_generated_types.append(event_class)
self.events.append(event_class(self.enemy, self.player, enemy_cp, player_cp, self)) self.events.append(event_class(self.enemy, self.player, enemy_cp, player_cp, self))

View File

@@ -1,53 +0,0 @@
from dcs.terrain import Terrain
from game import db
from gen.armor import *
from gen.aircraft import *
from gen.aaa import *
from gen.shipgen import *
from gen.triggergen import *
from gen.airsupportgen import *
from gen.visualgen import *
from gen.conflictgen import Conflict
from .operation import Operation
class AntiAAStrikeOperation(Operation):
strikegroup = None # type: db.PlaneDict
interceptors = None # type: db.PlaneDict
target = None # type: db.ArmorDict
def setup(self,
target: db.ArmorDict,
strikegroup: db.PlaneDict,
interceptors: db.PlaneDict):
self.strikegroup = strikegroup
self.interceptors = interceptors
self.target = target
def prepare(self, terrain: Terrain, is_quick: bool):
super(AntiAAStrikeOperation, self).prepare(terrain, is_quick)
if self.defender_name == self.game.player:
self.attackers_starting_position = None
self.defenders_starting_position = None
conflict = Conflict.ground_base_attack(
attacker=self.mission.country(self.attacker_name),
defender=self.mission.country(self.defender_name),
from_cp=self.from_cp,
to_cp=self.to_cp,
theater=self.game.theater
)
self.initialize(mission=self.mission,
conflict=conflict)
def generate(self):
self.airgen.generate_cas_strikegroup(self.strikegroup, clients=self.attacker_clients, at=self.attackers_starting_position)
if self.interceptors:
self.airgen.generate_defense(self.interceptors, clients=self.defender_clients, at=self.defenders_starting_position)
self.armorgen.generate({}, self.target)
super(AntiAAStrikeOperation, self).generate()

View File

@@ -1,21 +1,14 @@
from game import db from game.db import assigned_units_split
from gen.conflictgen import Conflict
from gen.armor import *
from gen.aircraft import *
from gen.aaa import *
from gen.shipgen import *
from gen.triggergen import * from gen.triggergen import *
from gen.airsupportgen import *
from gen.visualgen import *
from .operation import Operation from .operation import *
class BaseAttackOperation(Operation): class BaseAttackOperation(Operation):
cas = None # type: db.PlaneDict cas = None # type: db.AssignedUnitsDict
escort = None # type: db.PlaneDict escort = None # type: db.AssignedUnitsDict
intercept = None # type: db.PlaneDict intercept = None # type: db.AssignedUnitsDict
attack = None # type: db.ArmorDict attack = None # type: db.ArmorDict
defense = None # type: db.ArmorDict defense = None # type: db.ArmorDict
aa = None # type: db.AirDefenseDict aa = None # type: db.AirDefenseDict
@@ -23,10 +16,10 @@ class BaseAttackOperation(Operation):
trigger_radius = TRIGGER_RADIUS_SMALL trigger_radius = TRIGGER_RADIUS_SMALL
def setup(self, def setup(self,
cas: db.PlaneDict, cas: db.AssignedUnitsDict,
escort: db.PlaneDict, escort: db.AssignedUnitsDict,
attack: db.ArmorDict, attack: db.AssignedUnitsDict,
intercept: db.PlaneDict, intercept: db.AssignedUnitsDict,
defense: db.ArmorDict, defense: db.ArmorDict,
aa: db.AirDefenseDict): aa: db.AirDefenseDict):
self.cas = cas self.cas = cas
@@ -57,11 +50,14 @@ class BaseAttackOperation(Operation):
self.armorgen.generate(self.attack, self.defense) self.armorgen.generate(self.attack, self.defense)
self.aagen.generate(self.aa) self.aagen.generate(self.aa)
self.airgen.generate_defense(self.intercept, clients=self.defender_clients, at=self.defenders_starting_position) self.airgen.generate_defense(*assigned_units_split(self.intercept), at=self.defenders_starting_position)
self.airgen.generate_cas_strikegroup(self.cas, clients=self.attacker_clients, at=self.attackers_starting_position) self.airgen.generate_cas_strikegroup(*assigned_units_split(self.cas), at=self.attackers_starting_position)
self.airgen.generate_attackers_escort(self.escort, clients=self.attacker_clients, at=self.attackers_starting_position) self.airgen.generate_attackers_escort(*assigned_units_split(self.escort), at=self.attackers_starting_position)
self.visualgen.generate_target_smokes(self.to_cp) self.visualgen.generate_target_smokes(self.to_cp)
self.briefinggen.title = "Base attack"
self.briefinggen.description = "The goal of an attacker is to lower defender presence by destroying their armor and aircraft. Base will be considered captured if attackers on the ground overrun the defenders. Be advised that your flight will not attack anything until you explicitly tell them so by comms menu."
super(BaseAttackOperation, self).generate() super(BaseAttackOperation, self).generate()

View File

@@ -1,32 +1,20 @@
from itertools import zip_longest from game.db import assigned_units_split
from dcs.terrain import Terrain from .operation import *
from game import db
from gen.armor import *
from gen.aircraft import *
from gen.aaa import *
from gen.shipgen import *
from gen.triggergen import *
from gen.airsupportgen import *
from gen.visualgen import *
from gen.conflictgen import Conflict
from .operation import Operation
MAX_DISTANCE_BETWEEN_GROUPS = 12000 MAX_DISTANCE_BETWEEN_GROUPS = 12000
class FrontlineAttackOperation(Operation): class FrontlineAttackOperation(Operation):
strikegroup = None # type: db.AssignedUnitsDict
attackers = None # type: db.ArmorDict attackers = None # type: db.ArmorDict
strikegroup = None # type: db.PlaneDict
target = None # type: db.ArmorDict target = None # type: db.ArmorDict
def setup(self, def setup(self,
target: db.ArmorDict, target: db.ArmorDict,
attackers: db.ArmorDict, attackers: db.ArmorDict,
strikegroup: db.PlaneDict): strikegroup: db.AssignedUnitsDict):
self.strikegroup = strikegroup self.strikegroup = strikegroup
self.target = target self.target = target
self.attackers = attackers self.attackers = attackers
@@ -50,5 +38,17 @@ class FrontlineAttackOperation(Operation):
def generate(self): def generate(self):
self.armorgen.generate_vec(self.attackers, self.target) self.armorgen.generate_vec(self.attackers, self.target)
self.airgen.generate_cas_strikegroup(self.strikegroup, clients=self.attacker_clients, at=self.attackers_starting_position)
planes_flights = {k: v for k, v in self.strikegroup.items() if k in plane_map.values()}
self.airgen.generate_cas_strikegroup(*assigned_units_split(planes_flights), at=self.attackers_starting_position)
heli_flights = {k: v for k, v in self.strikegroup.items() if k in helicopters.helicopter_map.values()}
if heli_flights:
self.briefinggen.append_frequency("FARP", "127.5 MHz AM")
for farp, dict in zip(self.groundobjectgen.generate_farps(sum([x[0] for x in heli_flights.values()])),
db.assignedunits_split_to_count(heli_flights, self.groundobjectgen.FARP_CAPACITY)):
self.airgen.generate_cas_strikegroup(*assigned_units_split(dict), at=farp, escort=False)
self.briefinggen.title = "Frontline CAS"
self.briefinggen.description = "Provide CAS for the ground forces attacking enemy lines. Operation will be considered successful if total number of enemy units will be lower than your own by a factor of 1.5 (i.e. with 12 units from both sides, enemy forces need to be reduced to at least 8), meaning that you (and, probably, your wingmans) should concentrate on destroying the enemy units. Target base strength will be lowered as a result. Be advised that your flight will not attack anything until you explicitly tell them so by comms menu."
super(FrontlineAttackOperation, self).generate() super(FrontlineAttackOperation, self).generate()

View File

@@ -1,32 +1,25 @@
from itertools import zip_longest from game.db import assigned_units_split
from dcs.terrain import Terrain from .operation import *
from game import db
from gen.armor import *
from gen.aircraft import *
from gen.aaa import *
from gen.shipgen import *
from gen.triggergen import *
from gen.airsupportgen import *
from gen.visualgen import *
from gen.conflictgen import Conflict
from .operation import Operation
MAX_DISTANCE_BETWEEN_GROUPS = 12000 MAX_DISTANCE_BETWEEN_GROUPS = 12000
class FrontlinePatrolOperation(Operation): class FrontlinePatrolOperation(Operation):
cas = None # type: db.PlaneDict cas = None # type: db.AssignedUnitsDict
escort = None # type: db.PlaneDict escort = None # type: db.AssignedUnitsDict
interceptors = None # type: db.PlaneDict interceptors = None # type: db.AssignedUnitsDict
armor_attackers = None # type: db.ArmorDict armor_attackers = None # type: db.ArmorDict
armor_defenders = None # type: db.ArmorDict armor_defenders = None # type: db.ArmorDict
def setup(self, cas: db.PlaneDict, escort: db.PlaneDict, interceptors: db.PlaneDict, armor_attackers: db.ArmorDict, armor_defenders: db.ArmorDict): def setup(self,
cas: db.AssignedUnitsDict,
escort: db.AssignedUnitsDict,
interceptors: db.AssignedUnitsDict,
armor_attackers: db.ArmorDict,
armor_defenders: db.ArmorDict):
self.cas = cas self.cas = cas
self.escort = escort self.escort = escort
self.interceptors = interceptors self.interceptors = interceptors
@@ -50,9 +43,12 @@ class FrontlinePatrolOperation(Operation):
conflict=conflict) conflict=conflict)
def generate(self): def generate(self):
self.airgen.generate_defenders_cas(self.cas, {}, self.defenders_starting_position) self.airgen.generate_defenders_cas(*assigned_units_split(self.cas), at=self.defenders_starting_position)
self.airgen.generate_defenders_escort(self.escort, {}, self.defenders_starting_position) self.airgen.generate_defenders_escort(*assigned_units_split(self.escort), at=self.defenders_starting_position)
self.airgen.generate_patrol(self.interceptors, self.attacker_clients, self.attackers_starting_position) self.airgen.generate_migcap(*assigned_units_split(self.interceptors), at=self.attackers_starting_position)
self.armorgen.generate_vec(self.armor_attackers, self.armor_defenders) self.armorgen.generate_vec(self.armor_attackers, self.armor_defenders)
self.briefinggen.title = "Frontline CAP"
self.briefinggen.description = "Providing CAP support for ground units attacking enemy lines. Enemy will scramble its CAS and your task is to intercept it. Operation will be considered successful if total number of friendly units will be lower than enemy by at least a factor of 0.8 (i.e. with 12 units from both sides, there should be at least 8 friendly units alive), lowering targets strength as a result."
super(FrontlinePatrolOperation, self).generate() super(FrontlinePatrolOperation, self).generate()

View File

@@ -1,23 +1,13 @@
from dcs.terrain import Terrain from game.db import assigned_units_split
from game import db from .operation import *
from gen.armor import *
from gen.aircraft import *
from gen.aaa import *
from gen.shipgen import *
from gen.triggergen import *
from gen.airsupportgen import *
from gen.visualgen import *
from gen.conflictgen import Conflict
from .operation import Operation
class InfantryTransportOperation(Operation): class InfantryTransportOperation(Operation):
transport = None # type: db.HeliDict transport = None # type: db.AssignedUnitsDict
aa = None # type: db.AirDefenseDict aa = None # type: db.AirDefenseDict
def setup(self, transport: db.HeliDict, aa: db.AirDefenseDict): def setup(self, transport: db.AssignedUnitsDict, aa: db.AirDefenseDict):
self.transport = transport self.transport = transport
self.aa = aa self.aa = aa
@@ -36,11 +26,7 @@ class InfantryTransportOperation(Operation):
conflict=conflict) conflict=conflict)
def generate(self): def generate(self):
self.airgen.generate_passenger_transport( self.airgen.generate_passenger_transport(*assigned_units_split(self.transport), at=self.attackers_starting_position)
helis=self.transport,
clients=self.attacker_clients,
at=self.attackers_starting_position
)
self.armorgen.generate_passengers(count=6) self.armorgen.generate_passengers(count=6)
self.aagen.generate_at_defenders_location(self.aa) self.aagen.generate_at_defenders_location(self.aa)
@@ -48,6 +34,9 @@ class InfantryTransportOperation(Operation):
self.visualgen.generate_transportation_marker(self.conflict.ground_attackers_location) self.visualgen.generate_transportation_marker(self.conflict.ground_attackers_location)
self.visualgen.generate_transportation_destination(self.conflict.position) self.visualgen.generate_transportation_destination(self.conflict.position)
self.briefinggen.title = "Infantry transport"
self.briefinggen.description = "Helicopter operation to transport infantry troops from the base to the front line. Lowers target strength"
# TODO: horrible, horrible hack # TODO: horrible, horrible hack
# this will disable vehicle activation triggers, # this will disable vehicle activation triggers,
# which aren't needed on this type of missions # which aren't needed on this type of missions

View File

@@ -1,25 +1,15 @@
from dcs.terrain import Terrain from game.db import assigned_units_split
from game import db from .operation import *
from gen.armor import *
from gen.aircraft import *
from gen.aaa import *
from gen.shipgen import *
from gen.triggergen import *
from gen.airsupportgen import *
from gen.visualgen import *
from gen.conflictgen import Conflict
from .operation import Operation
class InsurgentAttackOperation(Operation): class InsurgentAttackOperation(Operation):
strikegroup = None # type: db.PlaneDict strikegroup = None # type: db.AssignedUnitsDict
target = None # type: db.ArmorDict target = None # type: db.ArmorDict
def setup(self, def setup(self,
target: db.ArmorDict, target: db.ArmorDict,
strikegroup: db.PlaneDict): strikegroup: db.AssignedUnitsDict):
self.strikegroup = strikegroup self.strikegroup = strikegroup
self.target = target self.target = target
@@ -38,7 +28,10 @@ class InsurgentAttackOperation(Operation):
conflict=conflict) conflict=conflict)
def generate(self): def generate(self):
self.airgen.generate_defense(self.strikegroup, self.defender_clients, self.defenders_starting_position) self.airgen.generate_defense(*assigned_units_split(self.strikegroup), at=self.defenders_starting_position)
self.armorgen.generate(self.target, {}) self.armorgen.generate(self.target, {})
self.briefinggen.title = "Destroy insurgents"
self.briefinggen.description = "Destroy vehicles of insurgents in close proximity of the friendly base. Be advised that your flight will not attack anything until you explicitly tell them so by comms menu."
super(InsurgentAttackOperation, self).generate() super(InsurgentAttackOperation, self).generate()

View File

@@ -1,22 +1,21 @@
from dcs.terrain import Terrain from game.db import assigned_units_split
from gen import * from .operation import *
from .operation import Operation
class InterceptOperation(Operation): class InterceptOperation(Operation):
escort = None # type: db.PlaneDict escort = None # type: db.AssignedUnitsDict
transport = None # type: db.PlaneDict transport = None # type: db.PlaneDict
interceptors = None # type: db.PlaneDict interceptors = None # type: db.AssignedUnitsDict
airdefense = None # type: db.AirDefenseDict airdefense = None # type: db.AirDefenseDict
trigger_radius = TRIGGER_RADIUS_LARGE trigger_radius = TRIGGER_RADIUS_LARGE
def setup(self, def setup(self,
escort: db.PlaneDict, escort: db.AssignedUnitsDict,
transport: db.PlaneDict, transport: db.PlaneDict,
airdefense: db.AirDefenseDict, airdefense: db.AirDefenseDict,
interceptors: db.PlaneDict): interceptors: db.AssignedUnitsDict):
self.escort = escort self.escort = escort
self.transport = transport self.transport = transport
self.airdefense = airdefense self.airdefense = airdefense
@@ -52,8 +51,12 @@ class InterceptOperation(Operation):
self.attackers_starting_position = ship self.attackers_starting_position = ship
self.airgen.generate_transport(self.transport, self.to_cp.at) self.airgen.generate_transport(self.transport, self.to_cp.at)
self.airgen.generate_defenders_escort(self.escort, clients=self.defender_clients) self.airgen.generate_defenders_escort(*assigned_units_split(self.escort), at=self.defenders_starting_position)
self.airgen.generate_interception(*assigned_units_split(self.interceptors), at=self.attackers_starting_position)
self.briefinggen.title = "Air Intercept"
self.briefinggen.description = "Intercept enemy supply transport aircraft. Escort will also be present if there are available planes on the base. Operation will be considered successful if most of the targets are destroyed, lowering targets strength as a result"
self.airgen.generate_interception(self.interceptors, clients=self.attacker_clients, at=self.attackers_starting_position)
super(InterceptOperation, self).generate() super(InterceptOperation, self).generate()

View File

@@ -1,18 +1,17 @@
from dcs.terrain import Terrain from game.db import assigned_units_split
from gen import * from .operation import *
from .operation import Operation
class NavalInterceptionOperation(Operation): class NavalInterceptionOperation(Operation):
strikegroup = None # type: db.PlaneDict strikegroup = None # type: db.AssignedUnitsDict
interceptors = None # type: db.PlaneDict interceptors = None # type: db.AssignedUnitsDict
targets = None # type: db.ShipDict targets = None # type: db.ShipDict
trigger_radius = TRIGGER_RADIUS_LARGE trigger_radius = TRIGGER_RADIUS_LARGE
def setup(self, def setup(self,
strikegroup: db.PlaneDict, strikegroup: db.AssignedUnitsDict,
interceptors: db.PlaneDict, interceptors: db.AssignedUnitsDict,
targets: db.ShipDict): targets: db.ShipDict):
self.strikegroup = strikegroup self.strikegroup = strikegroup
self.interceptors = interceptors self.interceptors = interceptors
@@ -34,20 +33,22 @@ class NavalInterceptionOperation(Operation):
self.initialize(self.mission, conflict) self.initialize(self.mission, conflict)
def generate(self): def generate(self):
super(NavalInterceptionOperation, self).generate()
target_groups = self.shipgen.generate_cargo(units=self.targets) target_groups = self.shipgen.generate_cargo(units=self.targets)
self.airgen.generate_ship_strikegroup( self.airgen.generate_ship_strikegroup(
attackers=self.strikegroup, *assigned_units_split(self.strikegroup),
clients=self.attacker_clients,
target_groups=target_groups, target_groups=target_groups,
at=self.attackers_starting_position at=self.attackers_starting_position
) )
if self.interceptors: if self.interceptors:
self.airgen.generate_defense( self.airgen.generate_defense(
defenders=self.interceptors, *assigned_units_split(self.interceptors),
clients=self.defender_clients,
at=self.defenders_starting_position at=self.defenders_starting_position
) )
self.briefinggen.title = "Naval Intercept"
self.briefinggen.description = "Destroy supply transport ships. Lowers target strength. Be advised that your flight will not attack anything until you explicitly tell them so by comms menu."
super(NavalInterceptionOperation, self).generate()

View File

@@ -1,15 +1,14 @@
from dcs.terrain import Terrain
from dcs.lua.parse import loads from dcs.lua.parse import loads
from userdata.debriefing import * from userdata.debriefing import *
from theater import *
from gen import * from gen import *
class Operation: class Operation:
attackers_starting_position = None # type: db.StartingPosition attackers_starting_position = None # type: db.StartingPosition
defenders_starting_position = None # type: db.StartingPosition defenders_starting_position = None # type: db.StartingPosition
mission = None # type: dcs.Mission mission = None # type: dcs.Mission
conflict = None # type: Conflict conflict = None # type: Conflict
armorgen = None # type: ArmorConflictGenerator armorgen = None # type: ArmorConflictGenerator
@@ -18,9 +17,11 @@ class Operation:
extra_aagen = None # type: ExtraAAConflictGenerator extra_aagen = None # type: ExtraAAConflictGenerator
shipgen = None # type: ShipGenerator shipgen = None # type: ShipGenerator
triggersgen = None # type: TriggersGenerator triggersgen = None # type: TriggersGenerator
awacsgen = None # type: AirSupportConflictGenerator airsupportgen = None # type: AirSupportConflictGenerator
visualgen = None # type: VisualGenerator visualgen = None # type: VisualGenerator
envgen = None # type: EnvironmentGenerator envgen = None # type: EnvironmentGenerator
groundobjectgen = None # type: GroundObjectsGenerator
briefinggen = None # type: BriefingGenerator
environment_settings = None environment_settings = None
trigger_radius = TRIGGER_RADIUS_MEDIUM trigger_radius = TRIGGER_RADIUS_MEDIUM
@@ -31,19 +32,21 @@ class Operation:
game, game,
attacker_name: str, attacker_name: str,
defender_name: str, defender_name: str,
attacker_clients: db.PlaneDict,
defender_clients: db.PlaneDict,
from_cp: ControlPoint, from_cp: ControlPoint,
to_cp: ControlPoint = None): to_cp: ControlPoint = None):
self.game = game self.game = game
self.attacker_name = attacker_name self.attacker_name = attacker_name
self.defender_name = defender_name self.defender_name = defender_name
self.attacker_clients = attacker_clients
self.defender_clients = defender_clients
self.from_cp = from_cp self.from_cp = from_cp
self.to_cp = to_cp self.to_cp = to_cp
self.is_quick = False self.is_quick = False
def units_of(self, country_name: str) -> typing.Collection[UnitType]:
return []
def is_successfull(self, debriefing: Debriefing) -> bool:
return True
def initialize(self, mission: Mission, conflict: Conflict): def initialize(self, mission: Mission, conflict: Conflict):
self.mission = mission self.mission = mission
self.conflict = conflict self.conflict = conflict
@@ -52,10 +55,12 @@ class Operation:
self.airgen = AircraftConflictGenerator(mission, conflict, self.game.settings) self.airgen = AircraftConflictGenerator(mission, conflict, self.game.settings)
self.aagen = AAConflictGenerator(mission, conflict) self.aagen = AAConflictGenerator(mission, conflict)
self.shipgen = ShipGenerator(mission, conflict) self.shipgen = ShipGenerator(mission, conflict)
self.awacsgen = AirSupportConflictGenerator(mission, conflict, self.game) self.airsupportgen = AirSupportConflictGenerator(mission, conflict, self.game)
self.triggersgen = TriggersGenerator(mission, conflict, self.game) self.triggersgen = TriggersGenerator(mission, conflict, self.game)
self.visualgen = VisualGenerator(mission, conflict, self.game) self.visualgen = VisualGenerator(mission, conflict, self.game)
self.envgen = EnviromentGenerator(mission, conflict, self.game) self.envgen = EnviromentGenerator(mission, conflict, self.game)
self.groundobjectgen = GroundObjectsGenerator(mission, conflict, self.game)
self.briefinggen = BriefingGenerator(mission, conflict, self.game)
player_name = self.from_cp.captured and self.attacker_name or self.defender_name player_name = self.from_cp.captured and self.attacker_name or self.defender_name
enemy_name = self.from_cp.captured and self.defender_name or self.attacker_name enemy_name = self.from_cp.captured and self.defender_name or self.attacker_name
@@ -78,10 +83,18 @@ class Operation:
def generate(self): def generate(self):
self.visualgen.generate() self.visualgen.generate()
self.awacsgen.generate(self.is_awacs_enabled)
# air support
self.airsupportgen.generate(self.is_awacs_enabled)
self.briefinggen.append_frequency("Tanker", "10X/240 MHz FM")
if self.is_awacs_enabled:
self.briefinggen.append_frequency("AWACS", "244 MHz FM")
# ground infrastructure
self.groundobjectgen.generate()
self.extra_aagen.generate() self.extra_aagen.generate()
# triggers
if self.game.is_player_attack(self.conflict.attackers_side): if self.game.is_player_attack(self.conflict.attackers_side):
cp = self.conflict.from_cp cp = self.conflict.from_cp
else: else:
@@ -92,13 +105,16 @@ class Operation:
activation_trigger_radius=self.trigger_radius, activation_trigger_radius=self.trigger_radius,
awacs_enabled=self.is_awacs_enabled) awacs_enabled=self.is_awacs_enabled)
# env settings
if self.environment_settings is None: if self.environment_settings is None:
self.environment_settings = self.envgen.generate() self.environment_settings = self.envgen.generate()
else: else:
self.envgen.load(self.environment_settings) self.envgen.load(self.environment_settings)
def units_of(self, country_name: str) -> typing.Collection[UnitType]: # main frequencies
return [] self.briefinggen.append_frequency("Flight", "251 MHz FM")
if self.conflict.from_cp.is_global or self.conflict.to_cp.is_global:
self.briefinggen.append_frequency("Carrier", "20X/ICLS CHAN1")
def is_successfull(self, debriefing: Debriefing) -> bool: # briefing
return True self.briefinggen.generate()

64
game/operation/strike.py Normal file
View File

@@ -0,0 +1,64 @@
from game.db import assigned_units_split
from .operation import *
class StrikeOperation(Operation):
strikegroup = None # type: db.AssignedUnitsDict
escort = None # type: db.AssignedUnitsDict
interceptors = None # type: db.AssignedUnitsDict
def setup(self,
strikegroup: db.AssignedUnitsDict,
escort: db.AssignedUnitsDict,
interceptors: db.AssignedUnitsDict):
self.strikegroup = strikegroup
self.escort = escort
self.interceptors = interceptors
def prepare(self, terrain: Terrain, is_quick: bool):
super(StrikeOperation, self).prepare(terrain, is_quick)
self.defenders_starting_position = None
if self.game.player == self.defender_name:
self.attackers_starting_position = None
conflict = Conflict.strike_conflict(
attacker=self.mission.country(self.attacker_name),
defender=self.mission.country(self.defender_name),
from_cp=self.from_cp,
to_cp=self.to_cp,
theater=self.game.theater
)
self.initialize(mission=self.mission,
conflict=conflict)
def generate(self):
targets = [] # type: typing.List[typing.Tuple[str, Point]]
category_counters = {} # type: typing.Dict[str, int]
processed_groups = []
for object in self.to_cp.ground_objects:
if object.group_identifier in processed_groups:
continue
processed_groups.append(object.group_identifier)
category_counters[object.category] = category_counters.get(object.category, 0) + 1
markpoint_name = "{}{}".format(object.name_abbrev, category_counters[object.category])
targets.append((markpoint_name, object.position))
self.briefinggen.append_target(str(object), markpoint_name)
targets.sort(key=lambda x: self.from_cp.position.distance_to_point(x[1]))
self.airgen.generate_ground_attack_strikegroup(*assigned_units_split(self.strikegroup),
targets=targets,
at=self.attackers_starting_position)
self.airgen.generate_attackers_escort(*assigned_units_split(self.escort), at=self.attackers_starting_position)
self.airgen.generate_barcap(*assigned_units_split(self.interceptors), at=self.defenders_starting_position)
self.briefinggen.title = "Strike"
self.briefinggen.description = "Destroy infrastructure assets and military supplies in the region. Each building destroyed will lower targets strength."
super(StrikeOperation, self).generate()

View File

@@ -2,8 +2,9 @@
class Settings: class Settings:
player_skill = "Good" player_skill = "Good"
enemy_skill = "Average" enemy_skill = "Average"
only_player_takeoff = False only_player_takeoff = True
night_disabled = False night_disabled = False
multiplier = 1 multiplier = 1
sams = True sams = True
cold_start = False cold_start = False
version = None

View File

@@ -7,6 +7,8 @@ from .shipgen import *
from .visualgen import * from .visualgen import *
from .triggergen import * from .triggergen import *
from .environmentgen import * from .environmentgen import *
from .groundobjectsgen import *
from .briefinggen import *
from . import naming from . import naming

View File

@@ -1,6 +1,3 @@
from game import *
from theater.conflicttheater import ConflictTheater
from .conflictgen import * from .conflictgen import *
from .naming import * from .naming import *
@@ -8,6 +5,7 @@ from dcs.mission import *
DISTANCE_FACTOR = 0.5, 1 DISTANCE_FACTOR = 0.5, 1
EXTRA_AA_MIN_DISTANCE = 35000 EXTRA_AA_MIN_DISTANCE = 35000
EXTRA_AA_MAX_DISTANCE = 150000
EXTRA_AA_POSITION_FROM_CP = 550 EXTRA_AA_POSITION_FROM_CP = 550
@@ -61,6 +59,9 @@ class ExtraAAConflictGenerator:
if cp.position.distance_to_point(self.conflict.from_cp.position) < EXTRA_AA_MIN_DISTANCE: if cp.position.distance_to_point(self.conflict.from_cp.position) < EXTRA_AA_MIN_DISTANCE:
continue continue
if cp.position.distance_to_point(self.conflict.position) > EXTRA_AA_MAX_DISTANCE:
continue
country_name = cp.captured and self.player_name or self.enemy_name country_name = cp.captured and self.player_name or self.enemy_name
position = cp.position.point_from_heading(0, EXTRA_AA_POSITION_FROM_CP) position = cp.position.point_from_heading(0, EXTRA_AA_POSITION_FROM_CP)
@@ -69,6 +70,6 @@ class ExtraAAConflictGenerator:
name=namegen.next_basedefense_name(), name=namegen.next_basedefense_name(),
_type=db.EXTRA_AA[country_name], _type=db.EXTRA_AA[country_name],
position=position, position=position,
group_size=2 group_size=1
) )

View File

@@ -24,6 +24,7 @@ WARM_START_AIRSPEED = 550
INTERCEPTION_ALT = 3000 INTERCEPTION_ALT = 3000
INTERCEPTION_AIRSPEED = 1000 INTERCEPTION_AIRSPEED = 1000
BARCAP_RACETRACK_DISTANCE = 20000
ATTACK_CIRCLE_ALT = 5000 ATTACK_CIRCLE_ALT = 5000
ATTACK_CIRCLE_DURATION = 15 ATTACK_CIRCLE_DURATION = 15
@@ -37,14 +38,18 @@ TRANSPORT_LANDING_ALT = 1000
DEFENCE_ENGAGEMENT_MAX_DISTANCE = 60000 DEFENCE_ENGAGEMENT_MAX_DISTANCE = 60000
INTERCEPT_MAX_DISTANCE = 200000 INTERCEPT_MAX_DISTANCE = 200000
GROUP_VERTICAL_OFFSET = 300
class AircraftConflictGenerator: class AircraftConflictGenerator:
escort_targets = [] # type: typing.List[typing.Tuple[PlaneGroup, int]] escort_targets = [] # type: typing.List[typing.Tuple[FlyingGroup, int]]
vertical_offset = None # type: int
def __init__(self, mission: Mission, conflict: Conflict, settings: Settings): def __init__(self, mission: Mission, conflict: Conflict, settings: Settings):
self.m = mission self.m = mission
self.settings = settings self.settings = settings
self.conflict = conflict self.conflict = conflict
self.vertical_offset = 0
self.escort_targets = [] self.escort_targets = []
def _start_type(self) -> StartType: def _start_type(self) -> StartType:
@@ -72,18 +77,22 @@ class AircraftConflictGenerator:
count -= group_size count -= group_size
client_count -= client_size client_count -= client_size
def _setup_group(self, group: FlyingGroup, for_task: Task, client_count: int): def _setup_group(self, group: FlyingGroup, for_task: typing.Type[Task], client_count: int):
did_load_loadout = False did_load_loadout = False
unit_type = group.units[0].unit_type unit_type = group.units[0].unit_type
if unit_type in db.PLANE_PAYLOAD_OVERRIDES: if unit_type in db.PLANE_PAYLOAD_OVERRIDES:
override_loadout = db.PLANE_PAYLOAD_OVERRIDES[unit_type] override_loadout = db.PLANE_PAYLOAD_OVERRIDES[unit_type]
if type(override_loadout) == dict: if type(override_loadout) == dict:
if for_task in db.PLANE_PAYLOAD_OVERRIDES[unit_type]: if for_task in db.PLANE_PAYLOAD_OVERRIDES[unit_type]:
group.load_loadout(db.PLANE_PAYLOAD_OVERRIDES[unit_type][for_task]) payload_name = db.PLANE_PAYLOAD_OVERRIDES[unit_type][for_task]
group.load_loadout(payload_name)
did_load_loadout = True did_load_loadout = True
logging.info("Loaded overridden payload for {} - {} for task {}".format(unit_type, payload_name, for_task))
elif "*" in db.PLANE_PAYLOAD_OVERRIDES[unit_type]: elif "*" in db.PLANE_PAYLOAD_OVERRIDES[unit_type]:
group.load_loadout(db.PLANE_PAYLOAD_OVERRIDES[unit_type]["*"]) payload_name = db.PLANE_PAYLOAD_OVERRIDES[unit_type]["*"]
group.load_loadout(payload_name)
did_load_loadout = True did_load_loadout = True
logging.info("Loaded overridden payload for {} - {} for task {}".format(unit_type, payload_name, for_task))
elif issubclass(override_loadout, MainTask): elif issubclass(override_loadout, MainTask):
group.load_task_default_loadout(override_loadout) group.load_task_default_loadout(override_loadout)
did_load_loadout = True did_load_loadout = True
@@ -103,6 +112,7 @@ class AircraftConflictGenerator:
group.units[idx].set_client() group.units[idx].set_client()
group.points[0].tasks.append(OptReactOnThreat(OptReactOnThreat.Values.EvadeFire)) group.points[0].tasks.append(OptReactOnThreat(OptReactOnThreat.Values.EvadeFire))
group.set_frequency(251.0)
def _generate_at_airport(self, name: str, side: Country, unit_type: FlyingType, count: int, client_count: int, airport: Airport = None) -> FlyingGroup: 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 count > 0
@@ -123,11 +133,12 @@ class AircraftConflictGenerator:
assert count > 0 assert count > 0
assert unit is not None assert unit is not None
self.vertical_offset += GROUP_VERTICAL_OFFSET
if unit_type in helicopters.helicopter_map.values(): if unit_type in helicopters.helicopter_map.values():
alt = WARM_START_HELI_ALT + random.randint(50, 200) alt = WARM_START_HELI_ALT + self.vertical_offset
speed = WARM_START_HELI_AIRSPEED speed = WARM_START_HELI_AIRSPEED
else: else:
alt = WARM_START_ALTITUDE + random.randint(50, 800) alt = WARM_START_ALTITUDE + self.vertical_offset
speed = WARM_START_AIRSPEED speed = WARM_START_AIRSPEED
pos = Point(at.x + random.randint(100, 1000), at.y + random.randint(100, 1000)) pos = Point(at.x + random.randint(100, 1000), at.y + random.randint(100, 1000))
@@ -145,11 +156,11 @@ class AircraftConflictGenerator:
start_type=self._start_type(), start_type=self._start_type(),
group_size=count) group_size=count)
def _generate_at_carrier(self, name: str, side: Country, unit_type: FlyingType, count: int, client_count: int, at: ShipGroup) -> FlyingGroup: def _generate_at_group(self, name: str, side: Country, unit_type: FlyingType, count: int, client_count: int, at: typing.Union[ShipGroup, StaticGroup]) -> FlyingGroup:
assert count > 0 assert count > 0
assert unit is not None assert unit is not None
logging.info("airgen: {} for {} at carrier {}".format(unit_type, side.id, at)) logging.info("airgen: {} for {} at unit {}".format(unit_type, side.id, at))
return self.m.flight_group_from_unit( return self.m.flight_group_from_unit(
country=side, country=side,
name=name, name=name,
@@ -162,10 +173,10 @@ class AircraftConflictGenerator:
def _generate_group(self, name: str, side: Country, unit_type: FlyingType, count: int, client_count: int, at: db.StartingPosition): def _generate_group(self, name: str, side: Country, unit_type: FlyingType, count: int, client_count: int, at: db.StartingPosition):
if isinstance(at, Point): if isinstance(at, Point):
return self._generate_inflight(name, side, unit_type, count, client_count, at) return self._generate_inflight(name, side, unit_type, count, client_count, at)
elif isinstance(at, ShipGroup): elif isinstance(at, Group):
takeoff_ban = unit_type in db.CARRIER_TAKEOFF_BAN takeoff_ban = unit_type in db.CARRIER_TAKEOFF_BAN
if not takeoff_ban: if not takeoff_ban:
return self._generate_at_carrier(name, side, unit_type, count, client_count, at) return self._generate_at_group(name, side, unit_type, count, client_count, at)
else: else:
return self._generate_inflight(name, side, unit_type, count, client_count, at.position) return self._generate_inflight(name, side, unit_type, count, client_count, at.position)
elif issubclass(at, Airport): elif issubclass(at, Airport):
@@ -182,14 +193,16 @@ class AircraftConflictGenerator:
assert False assert False
def _rtb_for(self, group: FlyingGroup, cp: ControlPoint, at: db.StartingPosition = None): def _rtb_for(self, group: FlyingGroup, cp: ControlPoint, at: db.StartingPosition = None):
group.add_waypoint(cp.position, RTB_ALTITUDE) if not at:
at = cp.at
if isinstance(cp.at, Point): if isinstance(at, Point):
pass group.add_waypoint(at, RTB_ALTITUDE)
elif isinstance(cp.at, ShipGroup): elif isinstance(at, Group):
pass group.add_waypoint(at.position, RTB_ALTITUDE)
elif issubclass(cp.at, Airport): elif issubclass(at, Airport):
group.land_at(cp.at) group.add_waypoint(at.position, RTB_ALTITUDE)
group.land_at(at)
def _at_position(self, at) -> Point: def _at_position(self, at) -> Point:
if isinstance(at, Point): if isinstance(at, Point):
@@ -213,12 +226,6 @@ class AircraftConflictGenerator:
at=at) at=at)
group.task = Escort.name group.task = Escort.name
"""
heading = group.position.heading_between_point(self.conflict.position)
position = group.position # type: Point
wayp = group.add_waypoint(position.point_from_heading(heading, WORKAROUND_WAYP_DIST), CAS_ALTITUDE, WARM_START_AIRSPEED)
"""
self._setup_group(group, CAP, client_count) self._setup_group(group, CAP, client_count)
for escorted_group, waypoint_index in self.escort_targets: for escorted_group, waypoint_index in self.escort_targets:
@@ -239,8 +246,8 @@ class AircraftConflictGenerator:
groups.append(group) groups.append(group)
return groups return groups
def generate_cas_strikegroup(self, attackers: db.PlaneDict, clients: db.PlaneDict, at: db.StartingPosition = None): def generate_cas_strikegroup(self, attackers: db.PlaneDict, clients: db.PlaneDict, at: db.StartingPosition = None, escort=True):
assert len(self.escort_targets) == 0 assert not escort or len(self.escort_targets) == 0
for flying_type, count, client_count in self._split_to_groups(attackers, clients): for flying_type, count, client_count in self._split_to_groups(attackers, clients):
group = self._generate_group( group = self._generate_group(
@@ -257,11 +264,37 @@ class AircraftConflictGenerator:
group.task = CAS.name group.task = CAS.name
self._setup_group(group, CAS, client_count) self._setup_group(group, CAS, client_count)
self.escort_targets.append((group, group.points.index(waypoint))) if escort:
self.escort_targets.append((group, group.points.index(waypoint)))
self._rtb_for(group, self.conflict.from_cp, at) self._rtb_for(group, self.conflict.from_cp, at)
def generate_defenders_cas(self, defenders: db.PlaneDict, clients: db.PlaneDict, at: db.StartingPosition = None): def generate_ground_attack_strikegroup(self, strikegroup: db.PlaneDict, clients: db.PlaneDict, targets: typing.List[typing.Tuple[str, Point]], at: db.StartingPosition = None, escort=True):
assert len(self.escort_targets) == 0 assert not escort or len(self.escort_targets) == 0
for flying_type, count, client_count in self._split_to_groups(strikegroup, clients):
group = self._generate_group(
name=namegen.next_unit_name(self.conflict.attackers_side, flying_type),
side=self.conflict.attackers_side,
unit_type=flying_type,
count=count,
client_count=client_count,
at=at and at or self._group_point(self.conflict.air_attackers_location))
escort_until_waypoint = None
for name, pos in targets:
waypoint = group.add_waypoint(pos, 0, WARM_START_AIRSPEED, self.m.translation.create_string(name))
if escort_until_waypoint is None:
escort_until_waypoint = waypoint
group.task = GroundAttack.name
self._setup_group(group, GroundAttack, client_count)
if escort:
self.escort_targets.append((group, group.points.index(escort_until_waypoint)))
self._rtb_for(group, self.conflict.from_cp, at)
def generate_defenders_cas(self, defenders: db.PlaneDict, clients: db.PlaneDict, at: db.StartingPosition = None, escort=True):
assert not escort or len(self.escort_targets) == 0
for flying_type, count, client_count in self._split_to_groups(defenders, clients): for flying_type, count, client_count in self._split_to_groups(defenders, clients):
group = self._generate_group( group = self._generate_group(
@@ -282,11 +315,12 @@ class AircraftConflictGenerator:
group.task = CAS.name group.task = CAS.name
self._setup_group(group, CAS, client_count) self._setup_group(group, CAS, client_count)
self.escort_targets.append((group, group.points.index(waypoint))) if escort:
self.escort_targets.append((group, group.points.index(waypoint)))
self._rtb_for(group, self.conflict.to_cp, at) self._rtb_for(group, self.conflict.to_cp, at)
def generate_ship_strikegroup(self, attackers: db.PlaneDict, clients: db.PlaneDict, target_groups: typing.Collection[ShipGroup], at: db.StartingPosition = None): def generate_ship_strikegroup(self, attackers: db.PlaneDict, clients: db.PlaneDict, target_groups: typing.Collection[ShipGroup], at: db.StartingPosition = None, escort=True):
assert len(self.escort_targets) == 0 assert not escort or len(self.escort_targets) == 0
for flying_type, count, client_count in self._split_to_groups(attackers, clients): for flying_type, count, client_count in self._split_to_groups(attackers, clients):
group = self._generate_group( group = self._generate_group(
@@ -303,7 +337,8 @@ class AircraftConflictGenerator:
group.task = AntishipStrike.name group.task = AntishipStrike.name
self._setup_group(group, AntishipStrike, client_count) self._setup_group(group, AntishipStrike, client_count)
self.escort_targets.append((group, group.points.index(wayp))) if escort:
self.escort_targets.append((group, group.points.index(wayp)))
self._rtb_for(group, self.conflict.from_cp, at) self._rtb_for(group, self.conflict.from_cp, at)
def generate_attackers_escort(self, attackers: db.PlaneDict, clients: db.PlaneDict, at: db.StartingPosition = None): def generate_attackers_escort(self, attackers: db.PlaneDict, clients: db.PlaneDict, at: db.StartingPosition = None):
@@ -343,7 +378,7 @@ class AircraftConflictGenerator:
self._setup_group(group, CAP, client_count) self._setup_group(group, CAP, client_count)
self._rtb_for(group, self.conflict.to_cp, at) self._rtb_for(group, self.conflict.to_cp, at)
def generate_patrol(self, patrol: db.PlaneDict, clients: db.PlaneDict, at: db.StartingPosition = None): def generate_migcap(self, patrol: db.PlaneDict, clients: db.PlaneDict, at: db.StartingPosition = None):
for flying_type, count, client_count in self._split_to_groups(patrol, clients): for flying_type, count, client_count in self._split_to_groups(patrol, clients):
group = self._generate_group( group = self._generate_group(
name=namegen.next_unit_name(self.conflict.attackers_side, flying_type), name=namegen.next_unit_name(self.conflict.attackers_side, flying_type),
@@ -361,8 +396,32 @@ class AircraftConflictGenerator:
self._setup_group(group, CAP, client_count) self._setup_group(group, CAP, client_count)
self._rtb_for(group, self.conflict.from_cp, at) self._rtb_for(group, self.conflict.from_cp, at)
def generate_transport(self, transport: db.PlaneDict, destination: Airport): def generate_barcap(self, patrol: db.PlaneDict, clients: db.PlaneDict, at: db.StartingPosition = None):
assert len(self.escort_targets) == 0 for flying_type, count, client_count in self._split_to_groups(patrol, clients):
group = self._generate_group(
name=namegen.next_unit_name(self.conflict.defenders_side, flying_type),
side=self.conflict.defenders_side,
unit_type=flying_type,
count=count,
client_count=client_count,
at=at and at or self._group_point(self.conflict.air_defenders_location))
waypoint = group.add_waypoint(self.conflict.position, WARM_START_ALTITUDE, WARM_START_AIRSPEED)
if self.conflict.is_vector:
group.add_waypoint(self.conflict.tail, WARM_START_ALTITUDE, WARM_START_AIRSPEED)
else:
heading = group.position.heading_between_point(self.conflict.position)
waypoint = group.add_waypoint(self.conflict.position.point_from_heading(heading, BARCAP_RACETRACK_DISTANCE),
WARM_START_ALTITUDE,
WARM_START_AIRSPEED)
waypoint.tasks.append(OrbitAction(WARM_START_ALTITUDE, WARM_START_AIRSPEED))
group.task = CAP.name
self._setup_group(group, CAP, client_count)
self._rtb_for(group, self.conflict.to_cp, at)
def generate_transport(self, transport: db.PlaneDict, destination: Airport, escort=True):
assert not escort or len(self.escort_targets) == 0
for flying_type, count, client_count in self._split_to_groups(transport): for flying_type, count, client_count in self._split_to_groups(transport):
group = self._generate_group( group = self._generate_group(
@@ -374,8 +433,8 @@ class AircraftConflictGenerator:
at=self._group_point(self.conflict.air_defenders_location)) at=self._group_point(self.conflict.air_defenders_location))
waypoint = group.add_waypoint(destination.position.random_point_within(0, 0), TRANSPORT_LANDING_ALT) waypoint = group.add_waypoint(destination.position.random_point_within(0, 0), TRANSPORT_LANDING_ALT)
self.escort_targets.append((group, group.points.index(waypoint))) if escort:
self.escort_targets.append((group, group.points.index(waypoint)))
group.task = Transport.name group.task = Transport.name
group.land_at(destination) group.land_at(destination)

View File

@@ -100,8 +100,10 @@ class ArmorConflictGenerator:
attacker_groups = list(db.unitdict_split(attackers, single_fight_attackers_count)) attacker_groups = list(db.unitdict_split(attackers, single_fight_attackers_count))
for attacker_group_dict, target_group_dict in zip_longest(attacker_groups, defender_groups): for attacker_group_dict, target_group_dict in zip_longest(attacker_groups, defender_groups):
padding = FRONTLINE_CAS_PADDING if FRONTLINE_CAS_PADDING < self.conflict.distance else 0
position = self.conflict.position.point_from_heading(self.conflict.heading, position = self.conflict.position.point_from_heading(self.conflict.heading,
random.randint(FRONTLINE_CAS_PADDING, int(self.conflict.distance - FRONTLINE_CAS_PADDING))) random.randint(padding, int(self.conflict.distance - padding)))
self._generate_fight_at(attacker_group_dict, target_group_dict, position) self._generate_fight_at(attacker_group_dict, target_group_dict, position)
def generate_passengers(self, count: int): def generate_passengers(self, count: int):

49
gen/briefinggen.py Normal file
View File

@@ -0,0 +1,49 @@
import logging
from game import db
from .conflictgen import *
from .naming import *
from dcs.mission import *
class BriefingGenerator:
freqs = None # type: typing.List[typing.Tuple[str, str]]
title = "" # type: str
description = "" # type: str
targets = None # type: typing.List[typing.Tuple[str, str]]
def __init__(self, mission: Mission, conflict: Conflict, game):
self.m = mission
self.conflict = conflict
self.game = game
self.freqs = []
self.targets = []
def append_frequency(self, name: str, frequency: str):
self.freqs.append((name, frequency))
def append_target(self, description: str, markpoint: str = None):
self.targets.append((description, markpoint))
def generate(self):
description = ""
if self.title:
description += self.title
if self.description:
description += "\n\n" + self.description
if self.freqs:
description += "\n\nCOMMS:"
for name, freq in self.freqs:
description += "\n{}: {}".format(name, freq)
if self.targets:
description += "\n\nTARGETS:"
for name, tp in self.targets:
description += "\n{} {}".format(name, "(TP {})".format(tp) if tp else "")
self.m.set_description_text(description)

View File

@@ -21,6 +21,9 @@ AIR_DISTANCE = 40000
CAPTURE_AIR_ATTACKERS_DISTANCE = 25000 CAPTURE_AIR_ATTACKERS_DISTANCE = 25000
CAPTURE_AIR_DEFENDERS_DISTANCE = 60000 CAPTURE_AIR_DEFENDERS_DISTANCE = 60000
STRIKE_AIR_ATTACKERS_DISTANCE = 45000
STRIKE_AIR_DEFENDERS_DISTANCE = 25000
CAP_CAS_DISTANCE = 10000, 120000 CAP_CAS_DISTANCE = 10000, 120000
GROUND_INTERCEPT_SPREAD = 5000 GROUND_INTERCEPT_SPREAD = 5000
@@ -139,6 +142,9 @@ class Conflict:
y = lerp * dy + self.tail.y y = lerp * dy + self.tail.y
return Point(x, y) return Point(x, y)
def find_ground_position(self, at: Point, heading: int, max_distance: int = 40000) -> typing.Optional[Point]:
return Conflict._find_ground_position(at, max_distance, heading, self.theater)
@classmethod @classmethod
def has_frontline_between(cls, from_cp: ControlPoint, to_cp: ControlPoint) -> bool: def has_frontline_between(cls, from_cp: ControlPoint, to_cp: ControlPoint) -> bool:
return from_cp.has_frontline and to_cp.has_frontline return from_cp.has_frontline and to_cp.has_frontline
@@ -152,36 +158,48 @@ class Conflict:
@classmethod @classmethod
def frontline_vector(cls, from_cp: ControlPoint, to_cp: ControlPoint, theater: ConflictTheater) -> typing.Tuple[Point, int, int]: def frontline_vector(cls, from_cp: ControlPoint, to_cp: ControlPoint, theater: ConflictTheater) -> typing.Tuple[Point, int, int]:
center_position, heading = cls.frontline_position(from_cp, to_cp) center_position, heading = cls.frontline_position(from_cp, to_cp)
left_position, right_position = None, None
left_position = center_position if not theater.is_on_land(center_position):
pos = cls._find_ground_position(center_position, FRONTLINE_LENGTH, _heading_sum(heading, -90), theater)
for offset in range(0, int(FRONTLINE_LENGTH / 2), 1000): if pos:
pos = center_position.point_from_heading(_heading_sum(heading, -90), offset)
if not theater.is_on_land(pos):
break
else:
left_position = pos
right_position = center_position
for offset in range(0, int(FRONTLINE_LENGTH / 2), 1000):
pos = center_position.point_from_heading(_heading_sum(heading, 90), offset)
if not theater.is_on_land(pos):
break
else:
right_position = pos right_position = pos
center_position = pos
else:
pos = cls._find_ground_position(center_position, FRONTLINE_LENGTH, _heading_sum(heading, +90), theater)
if pos:
left_position = pos
center_position = pos
print("{} - {} {}".format(from_cp, to_cp, center_position))
return left_position, _heading_sum(heading, 90), right_position.distance_to_point(left_position) if left_position is None:
left_position = cls._extend_ground_position(center_position, int(FRONTLINE_LENGTH/2), _heading_sum(heading, -90), theater)
if right_position is None:
right_position = cls._extend_ground_position(center_position, int(FRONTLINE_LENGTH/2), _heading_sum(heading, 90), theater)
return left_position, _heading_sum(heading, 90), int(right_position.distance_to_point(left_position))
@classmethod @classmethod
def _find_ground_location(cls, initial: Point, max_distance: int, heading: int, theater: ConflictTheater) -> Point: def _extend_ground_position(cls, initial: Point, max_distance: int, heading: int, theater: ConflictTheater) -> Point:
for _ in range(0, int(max_distance), 800): pos = initial
for _ in range(3): for offset in range(0, int(max_distance), 500):
if theater.is_on_land(initial): new_pos = initial.point_from_heading(heading, offset)
return initial if theater.is_on_land(new_pos):
pos = new_pos
else:
return pos
initial = initial.random_point_within(1000, 1000) return pos
initial = initial.point_from_heading(heading, 800) @classmethod
def _find_ground_position(cls, initial: Point, max_distance: int, heading: int, theater: ConflictTheater) -> typing.Optional[Point]:
pos = initial
for _ in range(0, int(max_distance), 500):
if theater.is_on_land(pos):
return pos
pos = pos.point_from_heading(heading, 500)
logging.info("Didn't find ground position!") logging.info("Didn't find ground position!")
return None return None
@@ -195,10 +213,10 @@ class Conflict:
distance = to_cp.size * GROUND_DISTANCE_FACTOR distance = to_cp.size * GROUND_DISTANCE_FACTOR
attackers_location = position.point_from_heading(attack_heading, distance) attackers_location = position.point_from_heading(attack_heading, distance)
attackers_location = Conflict._find_ground_location(attackers_location, distance * 2, _heading_sum(attack_heading, 180), theater) attackers_location = Conflict._find_ground_position(attackers_location, distance * 2, _heading_sum(attack_heading, 180), theater)
defenders_location = position.point_from_heading(defense_heading, distance) defenders_location = position.point_from_heading(defense_heading, distance)
defenders_location = Conflict._find_ground_location(defenders_location, distance * 2, _heading_sum(defense_heading, 180), theater) defenders_location = Conflict._find_ground_position(defenders_location, distance * 2, _heading_sum(defense_heading, 180), theater)
return cls( return cls(
position=position, position=position,
@@ -213,6 +231,33 @@ class Conflict:
air_defenders_location=position.point_from_heading(_opposite_heading(attack_raw_heading), CAPTURE_AIR_DEFENDERS_DISTANCE) air_defenders_location=position.point_from_heading(_opposite_heading(attack_raw_heading), CAPTURE_AIR_DEFENDERS_DISTANCE)
) )
@classmethod
def strike_conflict(cls, attacker: Country, defender: Country, from_cp: ControlPoint, to_cp: ControlPoint, theater: ConflictTheater):
position = to_cp.position
attack_raw_heading = to_cp.position.heading_between_point(from_cp.position)
attack_heading = to_cp.find_radial(attack_raw_heading)
defense_heading = to_cp.find_radial(from_cp.position.heading_between_point(to_cp.position), ignored_radial=attack_heading)
distance = to_cp.size * GROUND_DISTANCE_FACTOR
attackers_location = position.point_from_heading(attack_heading, distance)
attackers_location = Conflict._find_ground_position(attackers_location, distance * 2, _heading_sum(attack_heading, 180), theater)
defenders_location = position.point_from_heading(defense_heading, distance)
defenders_location = Conflict._find_ground_position(defenders_location, distance * 2, _heading_sum(defense_heading, 180), theater)
return cls(
position=position,
theater=theater,
from_cp=from_cp,
to_cp=to_cp,
attackers_side=attacker,
defenders_side=defender,
ground_attackers_location=attackers_location,
ground_defenders_location=defenders_location,
air_attackers_location=position.point_from_heading(attack_raw_heading, STRIKE_AIR_ATTACKERS_DISTANCE),
air_defenders_location=position.point_from_heading(_opposite_heading(attack_raw_heading), STRIKE_AIR_DEFENDERS_DISTANCE)
)
@classmethod @classmethod
def intercept_conflict(cls, attacker: Country, defender: Country, from_cp: ControlPoint, to_cp: ControlPoint, theater: ConflictTheater): def intercept_conflict(cls, attacker: Country, defender: Country, from_cp: ControlPoint, to_cp: ControlPoint, theater: ConflictTheater):
raw_distance = from_cp.position.distance_to_point(to_cp.position) * 1.5 raw_distance = from_cp.position.distance_to_point(to_cp.position) * 1.5
@@ -238,7 +283,7 @@ class Conflict:
def ground_attack_conflict(cls, attacker: Country, defender: Country, from_cp: ControlPoint, to_cp: ControlPoint, theater: ConflictTheater): def ground_attack_conflict(cls, attacker: Country, defender: Country, from_cp: ControlPoint, to_cp: ControlPoint, theater: ConflictTheater):
heading = random.choice(to_cp.radials) heading = random.choice(to_cp.radials)
initial_location = to_cp.position.random_point_within(*GROUND_ATTACK_DISTANCE) initial_location = to_cp.position.random_point_within(*GROUND_ATTACK_DISTANCE)
position = Conflict._find_ground_location(initial_location, GROUND_INTERCEPT_SPREAD, _heading_sum(heading, 180), theater) position = Conflict._find_ground_position(initial_location, GROUND_INTERCEPT_SPREAD, _heading_sum(heading, 180), theater)
if not position: if not position:
heading = to_cp.find_radial(to_cp.position.heading_between_point(from_cp.position)) heading = to_cp.find_radial(to_cp.position.heading_between_point(from_cp.position))
position = to_cp.position.point_from_heading(heading, to_cp.size * GROUND_DISTANCE_FACTOR) position = to_cp.position.point_from_heading(heading, to_cp.size * GROUND_DISTANCE_FACTOR)
@@ -306,7 +351,7 @@ class Conflict:
distance = to_cp.size * GROUND_DISTANCE_FACTOR distance = to_cp.size * GROUND_DISTANCE_FACTOR
defenders_location = position.point_from_heading(defense_heading, distance) defenders_location = position.point_from_heading(defense_heading, distance)
defenders_location = Conflict._find_ground_location(defenders_location, distance * 2, _heading_sum(defense_heading, 180), theater) defenders_location = Conflict._find_ground_position(defenders_location, distance * 2, _heading_sum(defense_heading, 180), theater)
return cls( return cls(
position=position, position=position,
@@ -351,7 +396,7 @@ class Conflict:
def transport_conflict(cls, attacker: Country, defender: Country, from_cp: ControlPoint, to_cp: ControlPoint, theater: ConflictTheater): def transport_conflict(cls, attacker: Country, defender: Country, from_cp: ControlPoint, to_cp: ControlPoint, theater: ConflictTheater):
frontline_position, heading = cls.frontline_position(from_cp, to_cp) frontline_position, heading = cls.frontline_position(from_cp, to_cp)
initial_dest = frontline_position.point_from_heading(heading, TRANSPORT_FRONTLINE_DIST) initial_dest = frontline_position.point_from_heading(heading, TRANSPORT_FRONTLINE_DIST)
dest = cls._find_ground_location(initial_dest, from_cp.position.distance_to_point(to_cp.position) / 3, heading, theater) dest = cls._find_ground_position(initial_dest, from_cp.position.distance_to_point(to_cp.position) / 3, heading, theater)
if not dest: if not dest:
radial = to_cp.find_radial(to_cp.position.heading_between_point(from_cp.position)) radial = to_cp.find_radial(to_cp.position.heading_between_point(from_cp.position))
dest = to_cp.position.point_from_heading(radial, to_cp.size * GROUND_DISTANCE_FACTOR) dest = to_cp.position.point_from_heading(radial, to_cp.size * GROUND_DISTANCE_FACTOR)

View File

@@ -49,7 +49,7 @@ class EnviromentGenerator:
self.game = game self.game = game
def _gen_random_time(self): def _gen_random_time(self):
start_time = datetime.combine(datetime.today(), time()) start_time = datetime.fromtimestamp(1527206400)
time_range = None time_range = None
for k, v in RANDOM_TIME.items(): for k, v in RANDOM_TIME.items():
if self.game.settings.night_disabled and k == "night": if self.game.settings.night_disabled and k == "night":

78
gen/groundobjectsgen.py Normal file
View File

@@ -0,0 +1,78 @@
import logging
from game import db
from .conflictgen import *
from .naming import *
from dcs.mission import *
from dcs.statics import *
FARP_FRONTLINE_DISTANCE = 10000
CATEGORY_MAPPING = {
"power": [Fortification.Workshop_A],
"warehouse": [Warehouse.Warehouse],
"fuel": [Warehouse.Tank],
"ammo": [Warehouse.Ammunition_depot],
"farp": [Fortification.FARP_Tent],
"comms": [Fortification.TV_tower],
"oil": [Fortification.Oil_platform],
}
class GroundObjectsGenerator:
FARP_CAPACITY = 4
def __init__(self, mission: Mission, conflict: Conflict, game):
self.m = mission
self.conflict = conflict
self.game = game
def generate_farps(self, number_of_units=1) -> typing.Collection[StaticGroup]:
assert self.conflict.is_vector, "FARP could be generated only on frontline conflicts!"
for i, _ in enumerate(range(0, number_of_units, self.FARP_CAPACITY)):
heading = self.conflict.heading - 90
position = self.conflict.find_ground_position(self.conflict.center.point_from_heading(heading, FARP_FRONTLINE_DISTANCE), heading)
position = position.point_from_heading(0, i * 275)
yield self.m.farp(
country=self.m.country(self.game.player),
name="FARP",
position=position,
)
def generate(self):
side = self.m.country(self.game.enemy)
cp = None # type: ControlPoint
if self.conflict.attackers_side.name == self.game.player:
cp = self.conflict.to_cp
else:
cp = self.conflict.from_cp
for ground_object in cp.ground_objects:
if ground_object.category == "defense":
unit_type = random.choice(self.game.commision_unit_types(cp, AirDefence))
assert unit_type is not None, "Cannot find unit type for GroundObject defense ({})!".format(cp)
group = self.m.vehicle_group(
country=side,
name=ground_object.string_identifier,
_type=unit_type,
position=ground_object.position,
heading=ground_object.heading
)
logging.info("generated defense object identifier {} with mission id {}".format(group.name, group.id))
else:
group = self.m.static_group(
country=side,
name=ground_object.string_identifier,
_type=random.choice(CATEGORY_MAPPING[ground_object.category]),
position=ground_object.position,
heading=ground_object.heading
)
logging.info("generated object identifier {} with mission id {}".format(group.name, group.id))

5
gen/heli.py Normal file
View File

@@ -0,0 +1,5 @@
from .aircraft import *
class HelicopterConflictGenerator(AircraftConflictGenerator):
pass

View File

@@ -72,32 +72,35 @@ class TriggersGenerator:
for coalition_name, coalition in self.mission.coalition.items(): for coalition_name, coalition in self.mission.coalition.items():
for country in coalition.countries.values(): for country in coalition.countries.values():
if coalition_name == player_coalition: if coalition_name == player_coalition:
for plane_group in country.plane_group + country.helicopter_group: for group in country.plane_group + country.helicopter_group:
if plane_group.task == AWACS.name or plane_group.task == Refueling.name: if group.task == AWACS.name or group.task == Refueling.name:
continue
if player_cp.position.distance_to_point(group.position) > PUSH_TRIGGER_SIZE * 3:
continue continue
regroup_heading = self.conflict.to_cp.position.heading_between_point(player_cp.position) regroup_heading = self.conflict.to_cp.position.heading_between_point(player_cp.position)
pos1 = plane_group.position.point_from_heading(regroup_heading, REGROUP_ZONE_DISTANCE) pos1 = group.position.point_from_heading(regroup_heading, REGROUP_ZONE_DISTANCE)
pos2 = plane_group.position.point_from_heading(regroup_heading, REGROUP_ZONE_DISTANCE+5000) pos2 = group.position.point_from_heading(regroup_heading, REGROUP_ZONE_DISTANCE+5000)
w1 = plane_group.add_waypoint(pos1, REGROUP_ALT) w1 = group.add_waypoint(pos1, REGROUP_ALT)
w2 = plane_group.add_waypoint(pos2, REGROUP_ALT) w2 = group.add_waypoint(pos2, REGROUP_ALT)
plane_group.points.remove(w1) group.points.remove(w1)
plane_group.points.remove(w2) group.points.remove(w2)
plane_group.points.insert(1, w2) group.points.insert(1, w2)
plane_group.points.insert(1, w1) group.points.insert(1, w1)
w1.tasks.append(Silence(True)) w1.tasks.append(Silence(True))
switch_waypoint_task = ControlledTask(SwitchWaypoint(from_waypoint=3, to_waypoint=2)) switch_waypoint_task = ControlledTask(SwitchWaypoint(from_waypoint=3, to_waypoint=2))
switch_waypoint_task.start_if_user_flag(1, False) switch_waypoint_task.start_if_user_flag(1, False)
w2.tasks.append(switch_waypoint_task) w2.tasks.append(switch_waypoint_task)
plane_group.points[3].tasks.append(Silence(False)) group.points[3].tasks.append(Silence(False))
plane_group.add_trigger_action(SwitchWaypoint(to_waypoint=4)) group.add_trigger_action(SwitchWaypoint(to_waypoint=4))
push_by_trigger.append(plane_group) push_by_trigger.append(group)
push_trigger_zone = self.mission.triggers.add_triggerzone(player_cp.position, PUSH_TRIGGER_SIZE, name="Push zone") push_trigger_zone = self.mission.triggers.add_triggerzone(player_cp.position, PUSH_TRIGGER_SIZE, name="Push zone")
push_trigger = TriggerOnce(Event.NoEvent, "Push trigger") push_trigger = TriggerOnce(Event.NoEvent, "Push trigger")
@@ -146,19 +149,6 @@ class TriggersGenerator:
self._set_skill(player_coalition, enemy_coalition) self._set_skill(player_coalition, enemy_coalition)
self._set_allegiances(player_coalition, enemy_coalition) self._set_allegiances(player_coalition, enemy_coalition)
description = ""
description += "FREQUENCIES:"
description += "\nFlight: 251 MHz AM"
description += "\nTanker: 10X/240 MHz"
if awacs_enabled:
description += "\nAWACS: 244 MHz"
if self.conflict.from_cp.is_global or self.conflict.to_cp.is_global:
description += "\nCarrier: 20X/ICLS CHAN1"
self.mission.set_description_text(description)
if not is_quick: if not is_quick:
# TODO: waypoint parts of this should not be post-hacked but added in airgen # TODO: waypoint parts of this should not be post-hacked but added in airgen
self._gen_activation_trigger(activation_trigger_radius, player_cp, player_coalition, enemy_coalition) self._gen_activation_trigger(activation_trigger_radius, player_cp, player_coalition, enemy_coalition)

BIN
icon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 81 KiB

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,86 @@
import pickle
import typing
from game import db
from gen.groundobjectsgen import TheaterGroundObject
from dcs.mission import Mission
from dcs.mapping import Point
m = Mission()
m.load_file("./cau_groundobjects.miz")
result = {}
result_by_groups = {} # type: typing.Dict[int, TheaterGroundObject]
cp_counters = {}
ids_counters = {}
group_id_counter = 0
previous_group_id = None
def append_group(cp_id, category, group_id, object_id, position, heading):
global result
global result_by_groups
ground_object = TheaterGroundObject(category, cp_id, group_id, object_id, position, heading)
if cp_id not in result:
result[cp_id] = []
result[cp_id].append(ground_object)
result_by_groups_key = "{}_{}_{}".format(cp_id, category, group_id)
if result_by_groups_key not in result_by_groups:
result_by_groups[result_by_groups_key] = []
result_by_groups[result_by_groups_key].append(ground_object)
def parse_name(name: str) -> typing.Tuple:
args = str(name.split()[0]).split("|")
if len(args) == 2:
global group_id_counter
group_id_counter += 1
args.append(str(group_id_counter))
else:
global previous_group_id
if previous_group_id != args[2]:
group_id_counter += 1
previous_group_id = args[2]
return args[0], int(args[1]), int(args[2])
for group in m.country("Russia").static_group + m.country("Russia").vehicle_group:
try:
category, cp_id, group_id = parse_name(str(group.name))
except:
print("Failed to parse {}".format(group.name))
continue
ids_counters_key = "{}_{}".format(cp_id, group_id)
ids_counters[ids_counters_key] = ids_counters.get(ids_counters_key, 0) + 1
object_id = ids_counters[ids_counters_key]
cp_counters[cp_id] = cp_counters.get(cp_id, 0) + 1
append_group(cp_id, category, group_id, object_id, group.position, group.units[0].heading)
GROUP_TRESHOLD = 2000
did_check_pairs = []
for group_id, objects_in_group in result_by_groups.items():
for a in objects_in_group:
for b in objects_in_group:
if (a, b) in did_check_pairs:
continue
did_check_pairs.append((a, b))
distance = a.position.distance_to_point(b.position)
if distance > GROUP_TRESHOLD:
print("Objects {} and {} in group {} are too far apart ({})!".format(a.string_identifier, b.string_identifier, group_id, distance))
print("Total {} objects".format(sum([len(x) for x in result.values()])))
for cp_id, count in cp_counters.items():
print("{} - {} objects".format(cp_id, count))
with open("../cau_groundobjects.p", "wb") as f:
pickle.dump(result, f)

View File

@@ -1,14 +1,14 @@
import pickle import pickle
from dcs.mission import Mission from dcs.mission import Mission
from dcs.terrain import PersianGulf
m = Mission() for terrain in ["cau", "gulf"]:
m.load_file("./gulf_terrain.miz") m = Mission()
m.load_file("./{}_terrain.miz".format(terrain))
landmap = [] landmap = []
for plane_group in m.country("USA").plane_group: for plane_group in m.country("USA").plane_group:
landmap.append([(x.position.x, x.position.y) for x in plane_group.points]) landmap.append([(x.position.x, x.position.y) for x in plane_group.points])
with open("../gulflandmap.p", "wb") as f: with open("../{}landmap.p".format(terrain), "wb") as f:
pickle.dump(landmap, f) pickle.dump(landmap, f)

View File

@@ -1,10 +1,14 @@
import os
import dcs import dcs
from gen.aircraft import AircraftConflictGenerator
from game import db from game import db
from gen.aircraft import AircraftConflictGenerator
dcs.planes.FlyingType.payload_dirs = [os.path.join(os.path.dirname(os.path.realpath(__file__)), "..\\payloads")]
mis = dcs.Mission(dcs.terrain.PersianGulf()) mis = dcs.Mission(dcs.terrain.PersianGulf())
pos = dcs.terrain.PersianGulf().khasab().position pos = dcs.terrain.PersianGulf().khasab().position
airgen = AircraftConflictGenerator(mis, None) airgen = AircraftConflictGenerator(mis, None, None)
for t, uts in db.UNIT_BY_TASK.items(): for t, uts in db.UNIT_BY_TASK.items():
if t != dcs.task.CAP and t != dcs.task.CAS: if t != dcs.task.CAP and t != dcs.task.CAS:
@@ -25,6 +29,6 @@ for t, uts in db.UNIT_BY_TASK.items():
altitude=10000 altitude=10000
) )
g.task = t.name g.task = t.name
airgen._setup_group(g, t) airgen._setup_group(g, t, 0)
mis.save("loadout_test.miz") mis.save("loadout_test.miz")

View File

@@ -0,0 +1,52 @@
import os
from zipfile import *
IGNORED_PATHS = [
"__pycache__",
".gitignore",
".gitmodules",
".git",
".idea",
".DS_Store",
"submodules",
"build",
"venv",
]
VERSION = input("version str:")
def _zip_dir(archieve, path):
for path, directories, files in os.walk(path):
is_ignored = False
for ignored_path in IGNORED_PATHS:
if ignored_path in path:
is_ignored = True
break
if is_ignored:
continue
for file in files:
if file in IGNORED_PATHS:
continue
archieve.write(os.path.join(path, file))
def _mk_archieve():
path = os.path.join("build", "dcs_liberation_{}.zip".format(VERSION))
if os.path.exists(path):
print("version already exists")
return
archieve = ZipFile(path, "w")
archieve.writestr("start.bat", "py.exe __init__.py \"%UserProfile%\" \"{}\"".format(VERSION))
_zip_dir(archieve, ".")
os.chdir("submodules\\dcs")
_zip_dir(archieve, "dcs")
_mk_archieve()

Binary file not shown.

After

Width:  |  Height:  |  Size: 852 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

BIN
resources/ui/terrain_pg.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

@@ -1 +0,0 @@
py.exe __init__.py "%UserProfile%"

View File

@@ -13,7 +13,7 @@ class CaucasusTheater(ConflictTheater):
overview_image = "caumap.gif" overview_image = "caumap.gif"
reference_points = {(-317948.32727306, 635639.37385346): (282.5, 319), reference_points = {(-317948.32727306, 635639.37385346): (282.5, 319),
(-355692.3067714, 617269.96285781): (269, 352), } (-355692.3067714, 617269.96285781): (269, 352), }
landmap_poly = load_poly("resources\\caulandmap.p") landmap = load_landmap("resources\\caulandmap.p")
daytime_map = { daytime_map = {
"dawn": (6, 9), "dawn": (6, 9),
"day": (9, 18), "day": (9, 18),
@@ -73,7 +73,10 @@ class CaucasusTheater(ConflictTheater):
self.carrier_1.captured = True self.carrier_1.captured = True
self.soganlug.captured = True self.soganlug.captured = True
with open("resources/cau_groundobjects.p", "rb") as f:
self.set_groundobject(pickle.load(f))
def add_controlpoint(self, point: ControlPoint, connected_to: typing.Collection[ControlPoint] = []): def add_controlpoint(self, point: ControlPoint, connected_to: typing.Collection[ControlPoint] = []):
point.name = " ".join(re.split(r" |-", point.name)[:1]) point.name = " ".join(re.split(r"[ -]", point.name)[:1])
super(CaucasusTheater, self).add_controlpoint(point, connected_to=connected_to) super(CaucasusTheater, self).add_controlpoint(point, connected_to=connected_to)

View File

@@ -4,8 +4,9 @@ import itertools
import dcs import dcs
from dcs.mapping import Point from dcs.mapping import Point
from .landmap import ray_tracing from .landmap import Landmap, poly_contains
from .controlpoint import ControlPoint from .controlpoint import ControlPoint
from .theatergroundobject import TheaterGroundObject
SIZE_TINY = 150 SIZE_TINY = 150
SIZE_SMALL = 600 SIZE_SMALL = 600
@@ -48,14 +49,22 @@ COAST_DR_W = [135, 180, 225, 315]
class ConflictTheater: class ConflictTheater:
terrain = None # type: dcs.terrain.Terrain terrain = None # type: dcs.terrain.Terrain
controlpoints = None # type: typing.Collection[ControlPoint] controlpoints = None # type: typing.Collection[ControlPoint]
reference_points = None # type: typing.Dict reference_points = None # type: typing.Dict
overview_image = None # type: str overview_image = None # type: str
landmap_poly = None landmap = None # type: landmap.Landmap
daytime_map = None # type: typing.Dict[str, typing.Tuple[int, int]] daytime_map = None # type: typing.Dict[str, typing.Tuple[int, int]]
def __init__(self): def __init__(self):
self.controlpoints = [] self.controlpoints = []
def set_groundobject(self, dictionary: typing.Dict[int, typing.Collection[TheaterGroundObject]]):
for id, value in dictionary.items():
for cp in self.controlpoints:
if cp.id == id:
cp.ground_objects = value
break
def add_controlpoint(self, point: ControlPoint, connected_to: typing.Collection[ControlPoint] = []): def add_controlpoint(self, point: ControlPoint, connected_to: typing.Collection[ControlPoint] = []):
for connected_point in connected_to: for connected_point in connected_to:
point.connect(to=connected_point) point.connect(to=connected_point)
@@ -63,14 +72,20 @@ class ConflictTheater:
self.controlpoints.append(point) self.controlpoints.append(point)
def is_on_land(self, point: Point) -> bool: def is_on_land(self, point: Point) -> bool:
if not self.landmap_poly: if not self.landmap:
return True return True
for poly in self.landmap_poly: # check first poly (main land poly)
if ray_tracing(point.x, point.y, poly): if not poly_contains(point.x, point.y, self.landmap[0]):
return True return False
return False # check others polys (exclusion zones from main)
for poly in self.landmap[1:]:
if poly_contains(point.x, point.y, poly):
# point is in one of the exclusion zones, meaning that it's in the lake or something
return False
return True
def player_points(self) -> typing.Collection[ControlPoint]: def player_points(self) -> typing.Collection[ControlPoint]:
return [point for point in self.controlpoints if point.captured] return [point for point in self.controlpoints if point.captured]

View File

@@ -5,22 +5,28 @@ from dcs.mapping import *
from dcs.country import * from dcs.country import *
from dcs.terrain import Airport from dcs.terrain import Airport
from .theatergroundobject import TheaterGroundObject
class ControlPoint: class ControlPoint:
connected_points = [] # type: typing.List[ControlPoint] connected_points = None # type: typing.List[ControlPoint]
ground_objects = None # type: typing.Collection[TheaterGroundObject]
position = None # type: Point position = None # type: Point
captured = False captured = False
has_frontline = True has_frontline = True
id = 0
base = None # type: theater.base.Base base = None # type: theater.base.Base
at = None # type: db.StartPosition at = None # type: db.StartPosition
def __init__(self, name: str, position: Point, at, radials: typing.Collection[int], size: int, importance: int, has_frontline=True): def __init__(self, id: int, name: str, position: Point, at, radials: typing.Collection[int], size: int, importance: int, has_frontline=True):
import theater.base import theater.base
self.id = id
self.name = " ".join(re.split(r" |-", name)[:2]) self.name = " ".join(re.split(r" |-", name)[:2])
self.full_name = name self.full_name = name
self.position = position self.position = position
self.at = at self.at = at
self.ground_objects = []
self.size = size self.size = size
self.importance = importance self.importance = importance
@@ -33,12 +39,12 @@ class ControlPoint:
@classmethod @classmethod
def from_airport(cls, airport: Airport, radials: typing.Collection[int], size: int, importance: int, has_frontline=True): def from_airport(cls, airport: Airport, radials: typing.Collection[int], size: int, importance: int, has_frontline=True):
assert airport assert airport
return cls(airport.name, airport.position, airport, radials, size, importance, has_frontline) return cls(airport.id, airport.name, airport.position, airport, radials, size, importance, has_frontline)
@classmethod @classmethod
def carrier(cls, name: str, at: Point): def carrier(cls, name: str, at: Point):
import theater.conflicttheater import theater.conflicttheater
return cls(name, at, at, theater.conflicttheater.LAND, theater.conflicttheater.SIZE_SMALL, 1) return cls(0, name, at, at, theater.conflicttheater.LAND, theater.conflicttheater.SIZE_SMALL, 1)
def __str__(self): def __str__(self):
return self.name return self.name

View File

@@ -1,7 +1,10 @@
import pickle import pickle
import typing
Landmap = typing.Collection[typing.Collection[typing.Tuple[float, float]]]
def load_poly(filename: str): def load_landmap(filename: str) -> Landmap:
try: try:
with open(filename, "rb") as f: with open(filename, "rb") as f:
return pickle.load(f) return pickle.load(f)
@@ -9,7 +12,7 @@ def load_poly(filename: str):
return None return None
def ray_tracing(x, y, poly): def poly_contains(x, y, poly):
n = len(poly) n = len(poly)
inside = False inside = False
xints = 0.0 xints = 0.0
@@ -25,3 +28,11 @@ def ray_tracing(x, y, poly):
inside = not inside inside = not inside
p1x, p1y = p2x, p2y p1x, p1y = p2x, p2y
return inside return inside
def poly_centroid(poly) -> typing.Tuple[float, float]:
x_list = [vertex[0] for vertex in poly]
y_list = [vertex[1] for vertex in poly]
x = sum(x_list) / len(poly)
y = sum(y_list) / len(poly)
return (x, y)

View File

@@ -3,7 +3,7 @@ from dcs import mapping
from .conflicttheater import * from .conflicttheater import *
from .base import * from .base import *
from .landmap import load_poly from .landmap import load_landmap
class PersianGulfTheater(ConflictTheater): class PersianGulfTheater(ConflictTheater):
@@ -11,7 +11,7 @@ class PersianGulfTheater(ConflictTheater):
overview_image = "persiangulf.gif" overview_image = "persiangulf.gif"
reference_points = {(persiangulf.Sir_Abu_Nuayr.position.x, persiangulf.Sir_Abu_Nuayr.position.y): (321, 145), reference_points = {(persiangulf.Sir_Abu_Nuayr.position.x, persiangulf.Sir_Abu_Nuayr.position.y): (321, 145),
(persiangulf.Sirri_Island.position.x, persiangulf.Sirri_Island.position.y): (347, 82), } (persiangulf.Sirri_Island.position.x, persiangulf.Sirri_Island.position.y): (347, 82), }
landmap_poly = load_poly("resources\\gulflandmap.p") landmap = load_landmap("resources\\gulflandmap.p")
daytime_map = { daytime_map = {
"dawn": (6, 8), "dawn": (6, 8),
"day": (8, 16), "day": (8, 16),

View File

@@ -0,0 +1,60 @@
import typing
from dcs.mapping import Point
NAME_BY_CATEGORY = {
"power": "Power plant",
"ammo": "Ammo depot",
"fuel": "Fuel depot",
"defense": "AA Defense Site",
"warehouse": "Warehouse",
"farp": "FARP",
"comms": "Comms. tower",
"oil": "Oil platform"
}
ABBREV_NAME = {
"power": "PLANT",
"ammo": "AMMO",
"fuel": "FUEL",
"defense": "AA",
"warehouse": "WARE",
"farp": "FARP",
"comms": "COMMST",
"oil": "OILP"
}
class TheaterGroundObject:
object_id = 0
cp_id = 0
group_id = 0
heading = 0
position = None # type: Point
category = None # type: str
def __init__(self, category, cp_id, group_id, object_id, position, heading):
self.category = category
self.cp_id = cp_id
self.group_id = group_id
self.object_id = object_id
self.position = position
self.heading = heading
@property
def string_identifier(self):
return "{}|{}|{}|{}".format(self.category, self.cp_id, self.group_id, self.object_id)
@property
def group_identifier(self) -> str:
return "{}|{}".format(self.category, self.group_id)
@property
def name_abbrev(self) -> str:
return ABBREV_NAME[self.category]
def __str__(self):
return NAME_BY_CATEGORY[self.category]
def matches_string_identifier(self, id):
return self.string_identifier == id

View File

@@ -1,6 +1,7 @@
from ui.eventmenu import * from ui.eventmenu import *
from game.game import * from game.game import *
from .styles import STYLES
class BaseMenu(Menu): class BaseMenu(Menu):
@@ -9,7 +10,6 @@ class BaseMenu(Menu):
def __init__(self, window: Window, parent, game: Game, cp: ControlPoint): def __init__(self, window: Window, parent, game: Game, cp: ControlPoint):
super(BaseMenu, self).__init__(window, parent, game) super(BaseMenu, self).__init__(window, parent, game)
self.cp = cp self.cp = cp
self.base = cp.base self.base = cp.base
self.frame = window.right_pane self.frame = window.right_pane
@@ -26,15 +26,15 @@ class BaseMenu(Menu):
existing_units = self.base.total_units_of_type(unit_type) existing_units = self.base.total_units_of_type(unit_type)
scheduled_units = self.event.units.get(unit_type, 0) scheduled_units = self.event.units.get(unit_type, 0)
Label(self.frame, text="{}".format(db.unit_type_name(unit_type))).grid(row=row, sticky=W) Label(self.frame, text="{}".format(db.unit_type_name(unit_type)), **STYLES["widget"]).grid(row=row, sticky=W)
label = Label(self.frame, text="({})".format(existing_units)) label = Label(self.frame, text="({})".format(existing_units), **STYLES["widget"])
label.grid(column=1, row=row) label.grid(column=1, row=row)
self.bought_amount_labels[unit_type] = label self.bought_amount_labels[unit_type] = label
Label(self.frame, text="{}m".format(unit_price)).grid(column=2, row=row) Label(self.frame, text="{}m".format(unit_price), **STYLES["widget"]).grid(column=2, row=row, sticky=E)
Button(self.frame, text="+", command=self.buy(unit_type)).grid(column=3, row=row) Button(self.frame, text="+", command=self.buy(unit_type), **STYLES["btn-primary"]).grid(column=3, row=row, padx=(10,0))
Button(self.frame, text="-", command=self.sell(unit_type)).grid(column=4, row=row) Button(self.frame, text="-", command=self.sell(unit_type), **STYLES["btn-warning"]).grid(column=4, row=row, padx=(10,5))
row += 1 row += 1
units = { units = {
@@ -45,13 +45,21 @@ class BaseMenu(Menu):
AirDefence: db.find_unittype(AirDefence, self.game.player), AirDefence: db.find_unittype(AirDefence, self.game.player),
} }
self.budget_label = Label(self.frame, text="Budget: {}m".format(self.game.budget)) # Header
head = Frame(self.frame, **STYLES["header"])
head.grid(row=row, column=0, columnspan=5, sticky=NSEW, pady=5)
Label(head, text=self.cp.name, **STYLES["title"]).grid(row=0, column=0, sticky=NW+S)
units_title = "{}/{}/{}".format(self.cp.base.total_planes, self.cp.base.total_armor, self.cp.base.total_aa)
Label(head, text=units_title, **STYLES["strong-grey"]).grid(row=0, column=1, sticky=NE+S)
row += 1
self.budget_label = Label(self.frame, text="Budget: {}m".format(self.game.budget), **STYLES["widget"])
self.budget_label.grid(row=row, sticky=W) self.budget_label.grid(row=row, sticky=W)
Button(self.frame, text="Back", command=self.dismiss).grid(column=4, row=row) Button(self.frame, text="Back", command=self.dismiss, **STYLES["btn-primary"]).grid(column=4, row=row, padx=(0,15), pady=(0,5))
row += 1 row += 1
for task_type, units in units.items(): for task_type, units in units.items():
Label(self.frame, text="{}".format(db.task_name(task_type))).grid(row=row, columnspan=5); row += 1 Label(self.frame, text="{}".format(db.task_name(task_type)), **STYLES["strong"]).grid(row=row, columnspan=5, sticky=NSEW); row += 1
units = list(set(units)) units = list(set(units))
units.sort(key=lambda x: db.PRICES[x]) units.sort(key=lambda x: db.PRICES[x])

View File

@@ -1,5 +1,8 @@
import webbrowser
from tkinter import * from tkinter import *
from tkinter.ttk import * from tkinter.ttk import *
from .styles import STYLES
from ui.window import * from ui.window import *
@@ -34,22 +37,45 @@ class ConfigurationMenu(Menu):
def display(self): def display(self):
self.window.clear_right_pane() self.window.clear_right_pane()
Label(self.frame, text="Player coalition skill").grid(row=0, column=0) # Header
Label(self.frame, text="Enemy coalition skill").grid(row=1, column=0) head = Frame(self.frame, **STYLES["header"])
head.grid(row=0, column=0, columnspan=2, sticky=NSEW)
Label(head, text="Configuration", **STYLES["title"]).grid()
OptionMenu(self.frame, self.player_skill_var, "Average", "Good", "High", "Excellent").grid(row=0, column=1) # Body
OptionMenu(self.frame, self.enemy_skill_var, "Average", "Good", "High", "Excellent").grid(row=1, column=1) body = Frame(self.frame, **STYLES["body"])
body.grid(row=1, column=0, sticky=NSEW)
Label(self.frame, text="Aircraft cold start").grid(row=2, column=0) Label(body, text="Player coalition skill", **STYLES["widget"]).grid(row=0, column=0, sticky=W)
Label(self.frame, text="Takeoff only for player group").grid(row=3, column=0) Label(body, text="Enemy coalition skill", **STYLES["widget"]).grid(row=1, column=0, sticky=W)
Label(self.frame, text="Disable night missions").grid(row=4, column=0)
Checkbutton(self.frame, variable=self.cold_start_var).grid(row=2, column=1) p_skill = OptionMenu(body, self.player_skill_var, "Average", "Good", "High", "Excellent")
Checkbutton(self.frame, variable=self.takeoff_var).grid(row=3, column=1) p_skill.grid(row=0, column=1, sticky=E, pady=5)
Checkbutton(self.frame, variable=self.night_var).grid(row=4, column=1) p_skill.configure(**STYLES["btn-primary"])
Button(self.frame, text="Back", command=self.dismiss).grid(row=5, column=0, columnspan=1) e_skill = OptionMenu(body, self.enemy_skill_var, "Average", "Good", "High", "Excellent")
Button(self.frame, text="Cheat +200m", command=self.cheat_money).grid(row=6, column=1) e_skill.grid(row=1, column=1, sticky=E)
e_skill.configure(**STYLES["btn-primary"])
Label(body, text="Aircraft cold start", **STYLES["widget"]).grid(row=2, column=0, sticky=W)
Label(body, text="Takeoff only for player group", **STYLES["widget"]).grid(row=3, column=0, sticky=W)
Label(body, text="Disable night missions", **STYLES["widget"]).grid(row=4, column=0, sticky=W)
Checkbutton(body, variable=self.cold_start_var, **STYLES["radiobutton"]).grid(row=2, column=1, sticky=E)
Checkbutton(body, variable=self.takeoff_var, **STYLES["radiobutton"]).grid(row=3, column=1, sticky=E)
Checkbutton(body, variable=self.night_var, **STYLES["radiobutton"]).grid(row=4, column=1, sticky=E)
Button(body, text="Back", command=self.dismiss, **STYLES["btn-primary"]).grid(row=5, column=1, sticky=E, pady=30)
Label(body, text="Contributors: ", **STYLES["widget"]).grid(row=6, column=0, sticky=W)
Label(body, text="shdwp - author, maintainer", **STYLES["widget"]).grid(row=7, column=0, sticky=W)
Button(body, text="[github]", command=lambda: webbrowser.open_new_tab("http://github.com/shdwp"), **STYLES["widget"]).grid(row=7, column=1, sticky=E)
Label(body, text="Khopa - contributions", **STYLES["widget"]).grid(row=8, column=0, sticky=W)
Button(body, text="[github]", command=lambda: webbrowser.open_new_tab("http://github.com/Khopa"), **STYLES["widget"]).grid(row=8, column=1, sticky=E)
Button(body, text="Cheat +200m", command=self.cheat_money, **STYLES["btn-danger"]).grid(row=10, column=1, pady=30)
def cheat_money(self): def cheat_money(self):
self.game.budget += 200 self.game.budget += 200

View File

@@ -1,5 +1,6 @@
from tkinter import * from tkinter import *
from tkinter.ttk import * from tkinter.ttk import *
from .styles import STYLES
from ui.window import * from ui.window import *
@@ -12,6 +13,6 @@ class CorruptedSaveMenu(Menu):
def display(self): def display(self):
self.window.clear_right_pane() self.window.clear_right_pane()
Label(text="Your save game was corrupted!").grid(row=0, column=0) Label(text="Your save game is either incompatible or was corrupted!", **STYLES["widget"]).grid(row=0, column=0)
Label(text="Please restore it by replacing \"liberation_save\" file with \"liberation_save_tmp\" to restore last saved copy.").grid(row=1, column=0) Label(text="Please restore it by replacing \"liberation_save\" file with \"liberation_save_tmp\" to restore last saved copy.", **STYLES["widget"]).grid(row=1, column=0)
Label(text="You can find those files under user DCS directory.").grid(row=2, column=0) Label(text="You can find those files under user Saved Games\\DCS directory.", **STYLES["widget"]).grid(row=2, column=0)

View File

@@ -4,33 +4,20 @@ from ui.eventresultsmenu import *
from game import * from game import *
from game.event import * from game.event import *
from .styles import STYLES, RED
UNITTYPES_FOR_EVENTS = {
FrontlineAttackEvent: [CAS, PinpointStrike],
FrontlinePatrolEvent: [CAP, PinpointStrike],
BaseAttackEvent: [CAP, CAS, PinpointStrike],
InterceptEvent: [CAP],
InsurgentAttackEvent: [CAS],
NavalInterceptEvent: [CAS],
AntiAAStrikeEvent: [CAS],
InfantryTransportEvent: [Embarking],
}
class EventMenu(Menu): class EventMenu(Menu):
aircraft_scramble_entries = None # type: typing.Dict[PlaneType , Entry] scramble_entries = None # type: typing.Dict[typing.Type[Task], typing.Dict[typing.Type[UnitType], typing.Tuple[Entry, Entry]]]
aircraft_client_entries = None # type: typing.Dict[PlaneType, Entry]
armor_scramble_entries = None # type: typing.Dict[VehicleType, Entry] error_label = None # type: Label
awacs = None # type: IntVar awacs = None # type: IntVar
def __init__(self, window: Window, parent, game: Game, event: event.Event): def __init__(self, window: Window, parent, game: Game, event: event.Event):
super(EventMenu, self).__init__(window, parent, game) super(EventMenu, self).__init__(window, parent, game)
self.event = event self.event = event
self.aircraft_scramble_entries = {} self.scramble_entries = {k: {} for k in self.event.tasks}
self.armor_scramble_entries = {}
self.aircraft_client_entries = {}
if self.event.attacker_name == self.game.player: if self.event.attacker_name == self.game.player:
self.base = self.event.from_cp.base self.base = self.event.from_cp.base
@@ -44,39 +31,41 @@ class EventMenu(Menu):
self.window.clear_right_pane() self.window.clear_right_pane()
row = 0 row = 0
def label(text, _row=None, _column=None, sticky=None): def header(text, style="strong"):
nonlocal row nonlocal row
Label(self.frame, text=text).grid(row=_row and _row or row, column=_column and _column or 0, sticky=sticky) head = Frame(self.frame, **STYLES["header"])
head.grid(row=row, column=0, sticky=N+EW, columnspan=5)
Label(head, text=text, **STYLES[style]).grid()
row += 1
def label(text, _row=None, _column=None, columnspan=None, sticky=None):
nonlocal row
new_label = Label(self.frame, text=text, **STYLES["widget"])
new_label.grid(row=_row and _row or row, column=_column and _column or 0, columnspan=columnspan, sticky=sticky)
if _row is None: if _row is None:
row += 1 row += 1
def scrable_row(unit_type, unit_count): return new_label
def scrable_row(task_type, unit_type, unit_count, client_slots: bool):
nonlocal row nonlocal row
Label(self.frame, text="{} ({})".format(db.unit_type_name(unit_type), unit_count)).grid(row=row, sticky=W) Label(self.frame, text="{} ({})".format(db.unit_type_name(unit_type), unit_count), **STYLES["widget"]).grid(row=row, sticky=W)
scramble_entry = Entry(self.frame, width=2) scramble_entry = Entry(self.frame, width=2)
scramble_entry.grid(column=1, row=row, sticky=W) scramble_entry.grid(column=1, row=row, sticky=E, padx=5)
scramble_entry.insert(0, "0") scramble_entry.insert(0, "0")
self.aircraft_scramble_entries[unit_type] = scramble_entry Button(self.frame, text="+", command=self.scramble_half(task_type, unit_type), **STYLES["btn-primary"]).grid(column=2, row=row)
Button(self.frame, text="+", command=self.scramble_half(True, unit_type)).grid(column=2, row=row)
client_entry = Entry(self.frame, width=2) if client_slots:
client_entry.grid(column=3, row=row, sticky=E) client_entry = Entry(self.frame, width=2)
client_entry.insert(0, "0") client_entry.grid(column=3, row=row, sticky=E, padx=5)
self.aircraft_client_entries[unit_type] = client_entry client_entry.insert(0, "0")
Button(self.frame, text="+", command=self.client_one(unit_type)).grid(column=4, row=row) Button(self.frame, text="+", command=self.client_one(task_type, unit_type), **STYLES["btn-primary"]).grid(column=4, row=row)
else:
client_entry = None
row += 1 self.scramble_entries[task_type][unit_type] = scramble_entry, client_entry
def scramble_armor_row(unit_type, unit_count):
nonlocal row
Label(self.frame, text="{} ({})".format(db.unit_type_name(unit_type), unit_count)).grid(row=row, sticky=W)
scramble_entry = Entry(self.frame, width=2)
scramble_entry.insert(0, "0")
scramble_entry.grid(column=1, row=row)
self.armor_scramble_entries[unit_type] = scramble_entry
Button(self.frame, text="+", command=self.scramble_half(False, unit_type)).grid(column=2, row=row)
row += 1 row += 1
@@ -84,78 +73,60 @@ class EventMenu(Menu):
if threat_descr: if threat_descr:
threat_descr = "Approx. {}".format(threat_descr) threat_descr = "Approx. {}".format(threat_descr)
Label(self.frame, text="{}. {}".format(self.event, threat_descr)).grid(row=row, column=0, columnspan=5) # Header
header("Mission Menu", "title")
# Mission Description
Label(self.frame, text="{}. {}".format(self.event, threat_descr), **STYLES["mission-preview"]).grid(row=row, column=0, columnspan=5, sticky=S+EW, padx=5, pady=5)
row += 1 row += 1
Button(self.frame, text="Commit", command=self.start).grid(column=3, row=row, sticky=E) Label(self.frame, text="Amount", **STYLES["widget"]).grid(row=row, column=1, columnspan=2)
Button(self.frame, text="Back", command=self.dismiss).grid(column=4, row=row, sticky=E) Label(self.frame, text="Client slots", **STYLES["widget"]).grid(row=row, column=3, columnspan=2)
awacs_enabled = self.game.budget >= AWACS_BUDGET_COST and NORMAL or DISABLED
Checkbutton(self.frame, text="AWACS ({}m)".format(AWACS_BUDGET_COST), var=self.awacs, state=awacs_enabled).grid(row=row, column=0, sticky=W)
row += 1 row += 1
label("Aircraft") for flight_task in self.event.tasks:
header("{}:".format(self.event.flight_name(flight_task)))
if self.base.aircraft: if flight_task == PinpointStrike:
Label(self.frame, text="Amount").grid(row=row, column=1, columnspan=2) if not self.base.armor:
Label(self.frame, text="Client slots").grid(row=row, column=3, columnspan=2) label("No units")
row += 1 for t, c in self.base.armor.items():
scrable_row(flight_task, t, c, client_slots=False)
filter_to = UNITTYPES_FOR_EVENTS[self.event.__class__]
for unit_type, count in self.base.aircraft.items():
if filter_to and db.unit_task(unit_type) not in filter_to:
continue
if unit_type in helicopter_map and self.event.__class__ != InsurgentAttackEvent:
continue
scrable_row(unit_type, count)
if not self.base.total_planes:
label("None", sticky=W)
label("Armor")
for unit_type, count in self.base.armor.items():
if filter_to and db.unit_task(unit_type) not in filter_to:
continue
scramble_armor_row(unit_type, count)
if not self.base.total_armor:
label("None", sticky=W)
def _scrambled_aircraft_count(self, unit_type: UnitType) -> int:
value = self.aircraft_scramble_entries[unit_type].get()
if value and int(value) > 0:
return min(int(value), self.base.aircraft[unit_type])
return 0
def _scrambled_armor_count(self, unit_type: UnitType) -> int:
value = self.armor_scramble_entries[unit_type].get()
if value and int(value) > 0:
return min(int(value), self.base.armor[unit_type])
return 0
def scramble_half(self, aircraft: bool, unit_type: UnitType) -> typing.Callable:
def action():
entry = None # type: Entry
total_count = 0
if aircraft:
entry = self.aircraft_scramble_entries[unit_type]
total_count = self.base.aircraft[unit_type]
else: else:
entry = self.armor_scramble_entries[unit_type] if not self.base.aircraft:
total_count = self.base.armor[unit_type] label("No units")
for t, c in self.base.aircraft.items():
scrable_row(flight_task, t, c, client_slots=True)
existing_count = int(entry.get()) header("Support:")
# Options
awacs_enabled = self.game.budget >= AWACS_BUDGET_COST and NORMAL or DISABLED
Checkbutton(self.frame, var=self.awacs, state=awacs_enabled, **STYLES["radiobutton"]).grid(row=row, column=0, sticky=E)
Label(self.frame, text="AWACS ({}m)".format(AWACS_BUDGET_COST), **STYLES["widget"]).grid(row=row, column=3, sticky=W, padx=5, pady=5)
row += 1
header("Ready?")
self.error_label = label("", columnspan=4)
self.error_label["fg"] = RED
Button(self.frame, text="Commit", command=self.start, **STYLES["btn-primary"]).grid(column=0, row=row, sticky=E, padx=5, pady=(10,10))
Button(self.frame, text="Back", command=self.dismiss, **STYLES["btn-warning"]).grid(column=3, row=row, sticky=E, padx=5, pady=(10,10))
row += 1
def scramble_half(self, task: typing.Type[UnitType], unit_type: UnitType) -> typing.Callable:
def action():
entry = self.scramble_entries[task][unit_type][0] # type: Entry
value = entry.get()
total_units = self.base.total_units_of_type(unit_type)
amount = int(value and value or "0")
entry.delete(0, END) entry.delete(0, END)
entry.insert(0, "{}".format(int(existing_count + math.ceil(total_count/2)))) entry.insert(0, str(amount + int(math.ceil(total_units/2))))
return action return action
def client_one(self, unit_type: UnitType) -> typing.Callable: def client_one(self, task: typing.Type[Task], unit_type: UnitType) -> typing.Callable:
def action(): def action():
entry = self.aircraft_client_entries[unit_type] # type: Entry entry = self.scramble_entries[task][unit_type][1] # type: Entry
value = entry.get() value = entry.get()
amount = int(value and value or "0") amount = int(value and value or "0")
entry.delete(0, END) entry.delete(0, END)
@@ -169,82 +140,48 @@ class EventMenu(Menu):
else: else:
self.event.is_awacs_enabled = False self.event.is_awacs_enabled = False
scrambled_aircraft = {} flights = {k: {} for k in self.event.tasks} # type: db.TaskForceDict
scrambled_sweep = {} units_scramble_counts = {} # type: typing.Dict[typing.Type[UnitType], int]
scrambled_cas = {} tasks_scramble_counts = {} # type: typing.Dict[typing.Type[Task], int]
for unit_type, field in self.aircraft_scramble_entries.items(): tasks_clients_counts = {} # type: typing.Dict[typing.Type[Task], int]
amount = self._scrambled_aircraft_count(unit_type)
if amount > 0:
task = db.unit_task(unit_type)
scrambled_aircraft[unit_type] = amount def dampen_count(for_task: typing.Type[Task], unit_type: typing.Type[UnitType], count: int) -> int:
if task == CAS: nonlocal units_scramble_counts
scrambled_cas[unit_type] = amount total_count = self.base.total_units_of_type(unit_type)
elif task == CAP:
scrambled_sweep[unit_type] = amount
scrambled_clients = {} total_scrambled = units_scramble_counts.get(unit_type, 0)
for unit_type, field in self.aircraft_client_entries.items(): dampened_value = count if count + total_scrambled < total_count else total_count - total_scrambled
value = field.get() units_scramble_counts[unit_type] = units_scramble_counts.get(unit_type, 0) + dampened_value
if value and int(value) > 0:
amount = int(value)
scrambled_clients[unit_type] = amount
scrambled_armor = {} return dampened_value
for unit_type, field in self.armor_scramble_entries.items():
amount = self._scrambled_armor_count(unit_type)
if amount > 0:
scrambled_armor[unit_type] = amount
if type(self.event) is BaseAttackEvent: for task_type, dict in self.scramble_entries.items():
e = self.event # type: BaseAttackEvent for unit_type, (count_entry, clients_entry) in dict.items():
if self.game.is_player_attack(self.event): try:
e.player_attacking(cas=scrambled_cas, count = int(count_entry.get())
escort=scrambled_sweep, except:
armor=scrambled_armor, count = 0
clients=scrambled_clients)
else:
e.player_defending(interceptors=scrambled_aircraft,
clients=scrambled_clients)
elif type(self.event) is InterceptEvent:
e = self.event # type: InterceptEvent
if self.game.is_player_attack(self.event):
e.player_attacking(interceptors=scrambled_aircraft,
clients=scrambled_clients)
else:
e.player_defending(escort=scrambled_aircraft,
clients=scrambled_clients)
elif type(self.event) is FrontlineAttackEvent:
e = self.event # type: FrontlineAttackEvent
e.player_attacking(armor=scrambled_armor, strikegroup=scrambled_aircraft, clients=scrambled_clients)
elif type(self.event) is FrontlinePatrolEvent:
e = self.event # type: FrontlinePatrolEvent
e.player_attacking(interceptors=scrambled_aircraft, clients=scrambled_clients, armor=scrambled_armor)
elif type(self.event) is NavalInterceptEvent:
e = self.event # type: NavalInterceptEvent
if self.game.is_player_attack(self.event): try:
e.player_attacking(strikegroup=scrambled_aircraft, clients=scrambled_clients) clients_count = int(clients_entry and clients_entry.get() or 0)
else: except:
e.player_defending(interceptors=scrambled_aircraft, clients=scrambled_clients) clients_count = 0
elif type(self.event) is AntiAAStrikeEvent:
e = self.event # type: AntiAAStrikeEvent dampened_count = dampen_count(task_type, unit_type, count)
if self.game.is_player_attack(self.event): tasks_clients_counts[task_type] = tasks_clients_counts.get(task_type, 0) + clients_count
e.player_attacking(strikegroup=scrambled_aircraft, clients=scrambled_clients) tasks_scramble_counts[task_type] = tasks_scramble_counts.get(task_type, 0) + dampened_count
else:
e.player_defending(interceptors=scrambled_aircraft, clients=scrambled_clients) flights[task_type][unit_type] = dampened_count, clients_count
elif type(self.event) is InsurgentAttackEvent:
e = self.event # type: InsurgentAttackEvent for task in self.event.ai_banned_tasks:
if self.game.is_player_attack(self.event): if tasks_clients_counts.get(task, 0) == 0 and tasks_scramble_counts.get(task, 0) > 0:
assert False self.error_label["text"] = "Need at least one player in flight {}".format(self.event.flight_name(task))
else: return
e.player_defending(strikegroup=scrambled_aircraft, clients=scrambled_clients)
elif type(self.event) is InfantryTransportEvent: if self.game.is_player_attack(self.event):
e = self.event # type: InfantryTransportEvent self.event.player_attacking(flights)
if self.game.is_player_attack(self.event): else:
e.player_attacking(transport=scrambled_aircraft, clients=scrambled_clients) self.event.player_defending(flights)
else:
assert False
self.game.initiate_event(self.event) self.game.initiate_event(self.event)
EventResultsMenu(self.window, self.parent, self.game, self.event).display() EventResultsMenu(self.window, self.parent, self.game, self.event).display()

View File

@@ -3,6 +3,7 @@ from ui.window import *
from game.game import * from game.game import *
from userdata.debriefing import * from userdata.debriefing import *
from .styles import STYLES
class EventResultsMenu(Menu): class EventResultsMenu(Menu):
@@ -13,6 +14,7 @@ class EventResultsMenu(Menu):
def __init__(self, window: Window, parent, game: Game, event: Event): def __init__(self, window: Window, parent, game: Game, event: Event):
super(EventResultsMenu, self).__init__(window, parent, game) super(EventResultsMenu, self).__init__(window, parent, game)
self.frame = window.right_pane self.frame = window.right_pane
self.frame.grid_rowconfigure(0, weight=0)
self.event = event self.event = event
self.finished = False self.finished = False
@@ -21,46 +23,84 @@ class EventResultsMenu(Menu):
def display(self): def display(self):
self.window.clear_right_pane() self.window.clear_right_pane()
row = 0
def header(text, style="strong"):
nonlocal row
head = Frame(self.frame, **STYLES["header"])
head.grid(row=row, column=0, sticky=N + EW, columnspan=2, pady=(0, 10))
Label(head, text=text, **STYLES[style]).grid()
row += 1
def label(text, style="widget"):
nonlocal row
Label(self.frame, text=text, **STYLES[style]).grid(row=row, column=0, sticky=NW, columnspan=2)
row += 1
if not self.finished: if not self.finished:
Label(self.frame, text="Play the mission and save debriefing to").grid(row=0, column=0)
Label(self.frame, text=debriefing_directory_location()).grid(row=1, column=0)
""" header("You are clear for takeoff!")
For debugging purposes
""" label("In DCS, open and play the mission:")
label("liberation_nextturn", "italic")
label("or")
label("liberation_nextturn_quick", "italic")
header("Then save the debriefing to the folder:")
label(debriefing_directory_location(), "italic")
header("Waiting for results...")
pg = Progressbar(self.frame, orient="horizontal", length=200, mode="determinate")
pg.grid(row=row, column=0, columnspan=2, sticky=EW, pady=5, padx=5)
pg.start(10)
row += 1
Label(self.frame, text="Cheat operation results: ", **STYLES["strong"]).grid(column=0, row=row,
columnspan=2, sticky=NSEW,
pady=5)
row += 1
Button(self.frame, text="full enemy losses", command=self.simulate_result(0, 1),
**STYLES["btn-warning"]).grid(column=0, row=row, padx=5, pady=5)
Button(self.frame, text="full player losses", command=self.simulate_result(1, 0),
**STYLES["btn-warning"]).grid(column=1, row=row, padx=5, pady=5)
row += 1
Button(self.frame, text="some enemy losses", command=self.simulate_result(0, 0.8),
**STYLES["btn-warning"]).grid(column=0, row=row, padx=5, pady=5)
Button(self.frame, text="some player losses", command=self.simulate_result(0.8, 0),
**STYLES["btn-warning"]).grid(column=1, row=row, padx=5, pady=5)
row += 1
row = 3
Separator(self.frame, orient=HORIZONTAL).grid(row=row, sticky=EW); row += 1
Label(self.frame, text="Cheat operation results: ").grid(row=row); row += 1
Button(self.frame, text="full enemy losses", command=self.simulate_result(0, 1)).grid(row=row); row += 1
Button(self.frame, text="full player losses", command=self.simulate_result(1, 0)).grid(row=row); row += 1
Button(self.frame, text="some enemy losses", command=self.simulate_result(0, 0.8)).grid(row=row); row += 1
Button(self.frame, text="some player losses", command=self.simulate_result(0.8, 0)).grid(row=row); row += 1
else: else:
row = 0 row = 0
if self.event.is_successfull(self.debriefing): if self.event.is_successfull(self.debriefing):
Label(self.frame, text="Operation success").grid(row=row, columnspan=1); row += 1 header("Operation success", "title-green")
else: else:
Label(self.frame, text="Operation failed").grid(row=row, columnspan=1); row += 1 header("Operation failed", "title-red")
header("Player losses")
Separator(self.frame, orient='horizontal').grid(row=row, columnspan=1, sticky=NE); row += 1
Label(self.frame, text="Player losses").grid(row=row, columnspan=1); row += 1
for unit_type, count in self.player_losses.items(): for unit_type, count in self.player_losses.items():
Label(self.frame, text=db.unit_type_name(unit_type)).grid(row=row) Label(self.frame, text=db.unit_type_name(unit_type), **STYLES["widget"]).grid(row=row)
Label(self.frame, text="{}".format(count)).grid(column=1, row=row) Label(self.frame, text="{}".format(count), **STYLES["widget"]).grid(column=1, row=row)
row += 1
header("Enemy losses")
if self.debriefing.destroyed_objects:
Label(self.frame, text="Ground assets", **STYLES["widget"]).grid(row=row)
Label(self.frame, text="{}".format(len(self.debriefing.destroyed_objects)), **STYLES["widget"]).grid(column=1, row=row)
row += 1 row += 1
Separator(self.frame, orient='horizontal').grid(row=row, columnspan=1, sticky=NE); row += 1
Label(self.frame, text="Enemy losses").grid(columnspan=1, row=row); row += 1
for unit_type, count in self.enemy_losses.items(): for unit_type, count in self.enemy_losses.items():
if count == 0: if count == 0:
continue continue
Label(self.frame, text=db.unit_type_name(unit_type)).grid(row=row) Label(self.frame, text=db.unit_type_name(unit_type), **STYLES["widget"]).grid(row=row)
Label(self.frame, text="{}".format(count)).grid(column=1, row=row) Label(self.frame, text="{}".format(count), **STYLES["widget"]).grid(column=1, row=row)
row += 1 row += 1
Button(self.frame, text="Okay", command=self.dismiss).grid(columnspan=1, row=row); row += 1 Button(self.frame, text="Okay", command=self.dismiss, **STYLES["btn-primary"]).grid(columnspan=1, row=row);
row += 1
def process_debriefing(self, debriefing: Debriefing): def process_debriefing(self, debriefing: Debriefing):
self.debriefing = debriefing self.debriefing = debriefing
@@ -78,7 +118,7 @@ class EventResultsMenu(Menu):
def simulate_result(self, player_factor: float, enemy_factor: float): def simulate_result(self, player_factor: float, enemy_factor: float):
def action(): def action():
debriefing = Debriefing({}) debriefing = Debriefing({}, [])
def count(country: Country) -> typing.Dict[UnitType, int]: def count(country: Country) -> typing.Dict[UnitType, int]:
result = {} result = {}
@@ -106,8 +146,10 @@ class EventResultsMenu(Menu):
alive_player_units = count(player) alive_player_units = count(player)
alive_enemy_units = count(enemy) alive_enemy_units = count(enemy)
destroyed_player_units = db.unitdict_restrict_count(alive_player_units, math.ceil(sum(alive_player_units.values()) * player_factor)) destroyed_player_units = db.unitdict_restrict_count(alive_player_units, math.ceil(
destroyed_enemy_units = db.unitdict_restrict_count(alive_enemy_units, math.ceil(sum(alive_enemy_units.values()) * enemy_factor)) sum(alive_player_units.values()) * player_factor))
destroyed_enemy_units = db.unitdict_restrict_count(alive_enemy_units, math.ceil(
sum(alive_enemy_units.values()) * enemy_factor))
alive_player_units = {k: v - destroyed_player_units.get(k, 0) for k, v in alive_player_units.items()} alive_player_units = {k: v - destroyed_player_units.get(k, 0) for k, v in alive_player_units.items()}
alive_enemy_units = {k: v - destroyed_enemy_units.get(k, 0) for k, v in alive_enemy_units.items()} alive_enemy_units = {k: v - destroyed_enemy_units.get(k, 0) for k, v in alive_enemy_units.items()}

View File

@@ -1,11 +1,13 @@
import pickle
from ui.basemenu import *
from ui.overviewcanvas import *
from ui.configurationmenu import *
from game.game import * from game.game import *
from ui.basemenu import *
from ui.configurationmenu import *
from ui.overviewcanvas import *
from userdata import persistency from userdata import persistency
from .styles import STYLES
import tkinter as tk
from tkinter import ttk
class MainMenu(Menu): class MainMenu(Menu):
@@ -18,56 +20,69 @@ class MainMenu(Menu):
self.upd.update() self.upd.update()
self.frame = self.window.right_pane self.frame = self.window.right_pane
self.frame.grid_columnconfigure(0, weight=1) self.frame.columnconfigure(0, weight=1)
self.frame.rowconfigure(0, weight=1)
def display(self): def display(self):
persistency.save_game(self.game) persistency.save_game(self.game)
self.window.clear_right_pane() self.window.clear_right_pane()
self.upd.update() self.upd.update()
row = 1 row = 0
# Header :
header = Frame(self.frame, **STYLES["header"])
Button(header, text="Configuration", command=self.configuration_menu, **STYLES["btn-primary"]).grid(column=0, row=0, sticky=NE)
Label(header, text="Budget: {}m (+{}m)".format(self.game.budget, self.game.budget_reward_amount), **STYLES["strong"]).grid(column=1, row=0, sticky=NSEW, padx=50)
Button(header, text="Pass turn", command=self.pass_turn, **STYLES["btn-primary"]).grid(column=2, row=0, sticky=NW)
header.grid(column=0, row=0, sticky=N+EW)
body = LabelFrame(self.frame, **STYLES["body"])
body.grid(column=0, row=1, sticky=NSEW)
def label(text): def label(text):
nonlocal row nonlocal row, body
Label(self.frame, text=text).grid(row=row, sticky=NW) frame = LabelFrame(body, **STYLES["label-frame"])
frame.grid(row=row, sticky=NSEW, columnspan=2)
Label(frame, text=text, **STYLES["widget"]).grid(row=row, sticky=NS)
row += 1 row += 1
def event_button(event): def event_button(event):
nonlocal row nonlocal row, body
Message(self.frame, text="{}{} at {}".format( frame = LabelFrame(body, **STYLES["label-frame"])
frame.grid(row=row, sticky=NSEW)
Message(frame, text="{}{}".format(
event.defender_name == self.game.player and "Enemy attacking: " or "", event.defender_name == self.game.player and "Enemy attacking: " or "",
event, event
event.to_cp, ), aspect=1600, **STYLES["widget"]).grid(column=0, row=0, sticky=NSEW)
), aspect=1600).grid(column=0, row=row, sticky=NW) Button(body, text=">", command=self.start_event(event), **STYLES["btn-primary"]).grid(column=1, row=row, sticky=E)
Button(self.frame, text=">", command=self.start_event(event)).grid(column=0, row=row, sticky=NE+S); row += 1 row += 1
def destination_header(text, separator=True): def destination_header(text, pady=0):
nonlocal row nonlocal row, body
if separator: Label(body, text=text, **STYLES["strong"]).grid(column=0, columnspan=2, row=row, sticky=N+EW, pady=(pady,0)); row += 1
Separator(self.frame, orient=HORIZONTAL).grid(row=row, sticky=EW); row += 1
Label(self.frame, text=text).grid(column=0, row=row, sticky=N); row += 1
Button(self.frame, text="Configuration", command=self.configuration_menu).grid(column=0, row=0, sticky=NE)
Button(self.frame, text="Pass turn", command=self.pass_turn).grid(column=0, row=0, sticky=NW)
Label(self.frame, text="Budget: {}m (+{}m)".format(self.game.budget, self.game.budget_reward_amount)).grid(column=0, row=0, sticky=N)
Separator(self.frame, orient='horizontal').grid(row=row, sticky=EW); row += 1
events = self.game.events events = self.game.events
events.sort(key=lambda x: x.to_cp.name)
events.sort(key=lambda x: x.from_cp.name) events.sort(key=lambda x: x.from_cp.name)
events.sort(key=lambda x: x.informational and 2 or (self.game.is_player_attack(x) and 1 or 0)) events.sort(key=lambda x: x.informational and 2 or (self.game.is_player_attack(x) and 1 or 0))
destination = None destination = None
deliveries = False
for event in events: for event in events:
if not event.informational: if not event.informational:
if self.game.is_player_attack(event): if self.game.is_player_attack(event):
new_destination = event.from_cp.name new_destination = "From {} to {}".format(event.from_cp.name, event.to_cp.name)
else: else:
new_destination = "Enemy attack" new_destination = "Enemy attack"
if destination != new_destination: if destination != new_destination:
destination_header(new_destination, destination is not None) destination_header(new_destination)
destination = new_destination destination = new_destination
if event.informational: if event.informational:
if not deliveries:
deliveries = True
destination_header("Deliveries", 15)
label(str(event)) label(str(event))
else: else:
event_button(event) event_button(event)
@@ -92,3 +107,7 @@ class MainMenu(Menu):
self.basemenu = BaseMenu(self.window, self, self.game, cp) self.basemenu = BaseMenu(self.window, self, self.game, cp)
self.basemenu.display() self.basemenu.display()

View File

@@ -1,7 +1,9 @@
import os
from tkinter import * from tkinter import *
from tkinter.ttk import * from tkinter.ttk import *
from ui.window import * from ui.window import *
from .styles import STYLES
class NewGameMenu(Menu): class NewGameMenu(Menu):
@@ -14,6 +16,7 @@ class NewGameMenu(Menu):
def __init__(self, window: Window, callback: typing.Callable): def __init__(self, window: Window, callback: typing.Callable):
super(NewGameMenu, self).__init__(window, None, None) super(NewGameMenu, self).__init__(window, None, None)
self.frame = window.right_pane self.frame = window.right_pane
window.left_pane.configure(background="black")
self.callback = callback self.callback = callback
self.selected_country = IntVar() self.selected_country = IntVar()
@@ -57,23 +60,72 @@ class NewGameMenu(Menu):
def display(self): def display(self):
self.window.clear_right_pane() self.window.clear_right_pane()
Label(self.frame, text="Player country").grid(row=0, column=0) # Header
Radiobutton(self.frame, text="USA", variable=self.selected_country, value=0).grid(row=1, column=0) head = Frame(self.frame, **STYLES["header"])
Radiobutton(self.frame, text="Russia", variable=self.selected_country, value=1).grid(row=2, column=0) head.grid(row=0, column=0, sticky=NSEW)
Label(head, text="Start a new game", **STYLES["title"]).grid()
Label(self.frame, text="Terrain").grid(row=0, column=1) # Body
Radiobutton(self.frame, text="Caucasus", variable=self.selected_terrain, value=0).grid(row=1, column=1) body = Frame(self.frame, **STYLES["body"])
Radiobutton(self.frame, text="Nevada", variable=self.selected_terrain, value=1).grid(row=2, column=1) body.grid(row=1, column=0, sticky=NSEW)
Radiobutton(self.frame, text="Persian Gulf", variable=self.selected_terrain, value=2).grid(row=3, column=1)
Label(self.frame, text="Options").grid(row=1, column=2) # Country Selection
Checkbutton(self.frame, text="SAMs", variable=self.sams).grid(row=1, column=2) country = LabelFrame(body, text="Player Side", **STYLES["label-frame"])
Checkbutton(self.frame, text="Mid game", variable=self.midgame).grid(row=2, column=2) country.grid(row=0, column=0, sticky=NW, padx=5)
Radiobutton(country, variable=self.selected_country, value=0, **STYLES["radiobutton"]).grid(row=0, column=0,
sticky=W)
Label(country, text="USA", **STYLES["widget"]).grid(row=0, column=1, sticky=W)
Radiobutton(country, variable=self.selected_country, value=1, **STYLES["radiobutton"]).grid(row=1, column=0,
sticky=W)
Label(country, text="Russia", **STYLES["widget"]).grid(row=1, column=1, sticky=W)
Label(self.frame, text="Multiplier").grid(row=0, column=3) # Terrain Selection
Entry(self.frame, textvariable=self.multiplier).grid(row=1, column=3) terrain = LabelFrame(body, text="Terrain", **STYLES["label-frame"])
terrain.grid(row=0, column=1, sticky=N, padx=5)
Button(self.frame, text="Proceed", command=self.proceed).grid(row=5, column=0, columnspan=4) Radiobutton(terrain, variable=self.selected_terrain, value=0, **STYLES["radiobutton"]) \
.grid(row=0, column=0, sticky=W)
Label(terrain, text="Caucasus", **STYLES["widget"]).grid(row=0, column=1, sticky=W)
self.create_label_image(terrain, "terrain_caucasus.gif").grid(row=0, column=2, padx=5)
Radiobutton(terrain, variable=self.selected_terrain, value=1, **STYLES["radiobutton"]) \
.grid(row=1, column=0, sticky=W)
Label(terrain, text="Nevada", **STYLES["widget"]).grid(row=1, column=1, sticky=W)
self.create_label_image(terrain, "terrain_nevada.gif").grid(row=1, column=2, padx=5)
Radiobutton(terrain, variable=self.selected_terrain, value=2, **STYLES["radiobutton"]) \
.grid(row=2, column=0, sticky=W)
Label(terrain, text="Persian Gulf", **STYLES["widget"]).grid(row=2, column=1, sticky=W)
self.create_label_image(terrain, "terrain_pg.gif").grid(row=2, column=2, padx=5)
Label(terrain, text="Currently strike missions are only\navailable for a number of airports only in Caucasus", **STYLES["widget"]) \
.grid(row=3, column=0, columnspan=3, sticky=W)
# Misc Options
options = LabelFrame(body, text="Misc Options", **STYLES["label-frame"])
options.grid(row=0, column=2, sticky=NE, padx=5)
Checkbutton(options, variable=self.sams, **STYLES["radiobutton"]).grid(row=0, column=0, sticky=W)
Label(options, text="SAMs", **STYLES["widget"]).grid(row=0, column=1, sticky=W)
Checkbutton(options, variable=self.midgame, **STYLES["radiobutton"]).grid(row=1, column=0, sticky=W)
Label(options, text="Mid Game", **STYLES["widget"]).grid(row=1, column=1, sticky=W)
Label(options, text="Multiplier", **STYLES["widget"]).grid(row=2, column=0, sticky=W)
Entry(options, textvariable=self.multiplier).grid(row=2, column=1, sticky=W)
# Footer with Proceed Button
footer = Frame(self.frame, **STYLES["header"])
footer.grid(row=2, sticky=N + E + W)
Button(footer, text="Proceed", command=self.proceed, **STYLES["btn-primary"]).grid(row=0, column=0, sticky=SE,
padx=5, pady=5)
@staticmethod
def create_label_image(parent, image):
im = PhotoImage(file=os.path.join("resources", "ui", image))
label = Label(parent, image=im)
label.image = im
return label
def proceed(self): def proceed(self):
self.callback(self.player_country_name, self.callback(self.player_country_name,

View File

@@ -50,11 +50,12 @@ class OverviewCanvas:
title = cp.name title = cp.name
font = ("Helvetica", 10) font = ("Helvetica", 10)
id = self.canvas.create_text(coords[0]+1, coords[1]+1, text=title, fill='white', font=font)
self.canvas.tag_bind(id, "<Button-1>", self.display(cp))
id = self.canvas.create_text(coords[0], coords[1], text=title, font=font) id = self.canvas.create_text(coords[0], coords[1], text=title, font=font)
self.canvas.tag_bind(id, "<Button-1>", self.display(cp)) self.canvas.tag_bind(id, "<Button-1>", self.display(cp))
id = self.canvas.create_text(coords[0]+1, coords[1]+1, text=title, fill='white', font=font)
self.canvas.tag_bind(id, "<Button-1>", self.display(cp))
def _player_color(self): def _player_color(self):
return self.game.player == "USA" and "blue" or "red" return self.game.player == "USA" and "blue" or "red"
@@ -80,6 +81,7 @@ class OverviewCanvas:
if cp.captured and not connected_cp.captured and Conflict.has_frontline_between(cp, connected_cp): if cp.captured and not connected_cp.captured and Conflict.has_frontline_between(cp, connected_cp):
frontline_pos, heading, distance = Conflict.frontline_vector(cp, connected_cp, self.game.theater) frontline_pos, heading, distance = Conflict.frontline_vector(cp, connected_cp, self.game.theater)
distance = max(distance, 1000)
start_coords = self.transform_point(frontline_pos, treshold=10) start_coords = self.transform_point(frontline_pos, treshold=10)
end_coords = self.transform_point(frontline_pos.point_from_heading(heading, distance), treshold=60) end_coords = self.transform_point(frontline_pos.point_from_heading(heading, distance), treshold=60)
@@ -97,7 +99,7 @@ class OverviewCanvas:
color = self._enemy_color() color = self._enemy_color()
cp_id = self.canvas.create_arc((coords[0] - arc_size/2, coords[1] - arc_size/2), cp_id = self.canvas.create_arc((coords[0] - arc_size/2, coords[1] - arc_size/2),
(coords[0]+arc_size/2, coords[1]+arc_size/2), (coords[0] + arc_size/2, coords[1] + arc_size/2),
fill=color, fill=color,
style=PIESLICE, style=PIESLICE,
start=start, start=start,
@@ -116,7 +118,8 @@ class OverviewCanvas:
self.create_cp_title((coords[0] + arc_size/4, coords[1] + arc_size/4), cp) self.create_cp_title((coords[0] + arc_size/4, coords[1] + arc_size/4), cp)
units_title = "{}/{}/{}".format(cp.base.total_planes, cp.base.total_armor, cp.base.total_aa) units_title = "{}/{}/{}".format(cp.base.total_planes, cp.base.total_armor, cp.base.total_aa)
self.canvas.create_text(coords[0], coords[1] - arc_size / 1.5, text=units_title, font=("Helvetica", 10)) self.canvas.create_text(coords[0]+1, coords[1] - arc_size / 1.5 +1, text=units_title, font=("Helvetica", 8), fill=color)
self.canvas.create_text(coords[0], coords[1] - arc_size / 1.5, text=units_title, font=("Helvetica", 8), fill="white")
def display(self, cp: ControlPoint): def display(self, cp: ControlPoint):
def action(_): def action(_):

45
ui/styles.py Normal file
View File

@@ -0,0 +1,45 @@
# Style for UI
# Padding
PADDING_X = 5
PADDING_Y = 5
# Colors
FG_COLOR = "white"
FG_COLOR_LIGHT = "#dddddd"
BG_COLOR = "#4E5760"
GREEN = "#699245"
YELLOW = "#BF9A46"
RED = "#D0232E"
BG_TITLE_COLOR = "#2D3E50"
# Fonts
FONT_FAMILY = "Trebuchet MS"
DEFAULT_FONT = (FONT_FAMILY, 8)
ITALIC = (FONT_FAMILY, 8, "italic")
BOLD_FONT = (FONT_FAMILY, 10, "bold italic")
TITLE_FONT = (FONT_FAMILY, 16, "bold italic")
# List of styles
STYLES = {}
STYLES["label-frame"] = {"font": BOLD_FONT, "bg": BG_COLOR, "fg": FG_COLOR}
STYLES["frame-wrapper"] = {"bg": BG_COLOR, "relief":"sunken"}
STYLES["body"] = {"bg": BG_COLOR, "padx": 25, "pady": 35}
STYLES["strong"] = {"font": BOLD_FONT, "bg": BG_TITLE_COLOR, "fg": FG_COLOR}
STYLES["strong-grey"] = {"font": BOLD_FONT, "bg": BG_TITLE_COLOR, "fg": FG_COLOR_LIGHT}
STYLES["mission-preview"] = {"font": BOLD_FONT, "bg": YELLOW, "fg": FG_COLOR}
STYLES["widget"] = {"bg": BG_COLOR, "fg": FG_COLOR, "padx": PADDING_X, "pady": PADDING_Y, "font": DEFAULT_FONT}
STYLES["italic"] = {"bg": BG_COLOR, "fg": FG_COLOR, "padx": PADDING_X, "pady": PADDING_Y, "font": ITALIC}
STYLES["radiobutton"] = {"bg": BG_COLOR, "fg": "black", "padx": PADDING_X, "pady": PADDING_Y, "font": DEFAULT_FONT,
"activebackground": BG_COLOR, "highlightbackground": BG_COLOR, "selectcolor": "white"}
STYLES["title"] = {"bg": BG_TITLE_COLOR, "fg": FG_COLOR, "padx": PADDING_X, "pady": PADDING_Y, "font": TITLE_FONT}
STYLES["title-green"] = {"bg": GREEN, "fg": FG_COLOR, "padx": PADDING_X, "pady": PADDING_Y, "font": TITLE_FONT}
STYLES["title-red"] = {"bg": RED, "fg": FG_COLOR, "padx": PADDING_X, "pady": PADDING_Y, "font": TITLE_FONT}
STYLES["header"] = {"bg": BG_TITLE_COLOR}
STYLES["btn-primary"] = {"bg": GREEN, "fg": FG_COLOR, "padx": PADDING_X, "pady": 2, "font": DEFAULT_FONT}
STYLES["btn-danger"] = {"bg": RED, "fg": FG_COLOR, "padx": PADDING_X, "pady": 2, "font": DEFAULT_FONT}
STYLES["btn-warning"] = {"bg": YELLOW, "fg": FG_COLOR, "padx": PADDING_X, "pady": 2, "font": DEFAULT_FONT}

View File

@@ -1,6 +1,6 @@
from tkinter import * from tkinter import *
from game.game import * from game.game import *
from .styles import BG_COLOR,BG_TITLE_COLOR
class Window: class Window:
image = None image = None
@@ -9,21 +9,24 @@ class Window:
def __init__(self): def __init__(self):
self.tk = Tk() self.tk = Tk()
self.tk.title("DCS Liberation")
self.tk.iconbitmap("icon.ico")
self.tk.resizable(True, True)
self.tk.grid_columnconfigure(0, weight=1) self.tk.grid_columnconfigure(0, weight=1)
self.tk.grid_rowconfigure(0, weight=1) self.tk.grid_rowconfigure(0, weight=1)
self.frame = Frame(self.tk) self.frame = Frame(self.tk, bg=BG_COLOR)
self.frame.grid(column=0, row=0, sticky=NSEW) self.frame.grid(column=0, row=0, sticky=NSEW)
self.frame.grid_columnconfigure(0, minsize=300) self.frame.grid_columnconfigure(0)
self.frame.grid_columnconfigure(1, minsize=400) self.frame.grid_columnconfigure(1)
self.frame.grid_columnconfigure(0, weight=0) self.frame.grid_columnconfigure(0, weight=0)
self.frame.grid_columnconfigure(1, weight=1) self.frame.grid_columnconfigure(1, weight=1)
self.frame.grid_rowconfigure(0, weight=1) self.frame.grid_rowconfigure(0, weight=1)
self.left_pane = Frame(self.frame) self.left_pane = Frame(self.frame, bg=BG_TITLE_COLOR)
self.left_pane.grid(row=0, column=0, sticky=NSEW) self.left_pane.grid(row=0, column=0, sticky=NSEW)
self.right_pane = Frame(self.frame) self.right_pane = Frame(self.frame, bg=BG_COLOR)
self.right_pane.grid(row=0, column=1, sticky=NSEW) self.right_pane.grid(row=0, column=1, sticky=NSEW)
self.tk.focus() self.tk.focus()

View File

@@ -59,14 +59,59 @@ def parse_mutliplayer_debriefing(contents: str):
class Debriefing: class Debriefing:
def __init__(self, dead_units): def __init__(self, dead_units, dead_objects):
self.destroyed_units = {} # type: typing.Dict[str, typing.Dict[UnitType, int]] self.destroyed_units = {} # type: typing.Dict[str, typing.Dict[UnitType, int]]
self.alive_units = {} # type: typing.Dict[str, typing.Dict[UnitType, int]] self.alive_units = {} # type: typing.Dict[str, typing.Dict[UnitType, int]]
self.destroyed_objects = [] # type: typing.List[str]
self._dead_units = dead_units self._dead_units = dead_units
self._dead_objects = dead_objects
@classmethod @classmethod
def parse(cls, path: str): def parse(cls, path: str):
dead_units = {}
dead_objects = []
def append_dead_unit(country_id, unit_type):
nonlocal dead_units
if country_id not in dead_units:
dead_units[country_id] = {}
if unit_type not in dead_units[country_id]:
dead_units[country_id][unit_type] = 0
dead_units[country_id][unit_type] += 1
def append_dead_object(object_mission_id_str):
nonlocal dead_objects
object_mission_id = int(object_mission_id_str)
if object_mission_id in dead_objects:
logging.info("debriefing: failed to append_dead_object {}: already exists!".format(object_mission_id))
return
dead_objects.append(object_mission_id)
def parse_dead_unit(event):
try:
components = event["initiator"].split("|")
category, country_id, group_id, unit_type = components[0], int(components[1]), int(components[2]), db.unit_type_from_name(components[3])
if unit_type is None:
logging.info("Skipped {} due to no unit type".format(event))
return
if category == "unit":
append_dead_unit(country_id, unit_type)
else:
logging.info("Skipped {} due to category".format(event))
except Exception as e:
logging.error(e)
def parse_dead_object(event):
try:
append_dead_object(event["initiatorMissionID"])
except Exception as e:
logging.error(e)
with open(path, "r") as f: with open(path, "r") as f:
table_string = f.read() table_string = f.read()
try: try:
@@ -75,36 +120,18 @@ class Debriefing:
table = parse_mutliplayer_debriefing(table_string) table = parse_mutliplayer_debriefing(table_string)
events = table.get("debriefing", {}).get("events", {}) events = table.get("debriefing", {}).get("events", {})
dead_units = {}
for event in events.values(): for event in events.values():
event_type = event.get("type", None) event_type = event.get("type", None)
if event_type != "crash" and event_type != "dead": if event_type in ["crash", "dead"]:
continue object_initiator = event["initiator"] in ["SKLAD_CRUSH", "SKLADCDESTR", "TEC_A_CRUSH", "BAK_CRUSH"]
defense_initiator = event["initiator"].startswith("defense|")
try: if object_initiator or defense_initiator:
components = event["initiator"].split("|") parse_dead_object(event)
category, country_id, group_id, unit_type = components[0], int(components[1]), int(components[2]), db.unit_type_from_name(components[3]) else:
if unit_type is None: parse_dead_unit(event)
logging.info("Skipped due to no unit type")
continue
if category != "unit": return Debriefing(dead_units, dead_objects)
logging.info("Skipped due to category")
continue
except Exception as e:
logging.error(e)
continue
if country_id not in dead_units:
dead_units[country_id] = {}
if unit_type not in dead_units[country_id]:
dead_units[country_id][unit_type] = 0
dead_units[country_id][unit_type] += 1
return Debriefing(dead_units)
def calculate_units(self, mission: Mission, player_name: str, enemy_name: str): def calculate_units(self, mission: Mission, player_name: str, enemy_name: str):
def count_groups(groups: typing.List[UnitType]) -> typing.Dict[UnitType, int]: def count_groups(groups: typing.List[UnitType]) -> typing.Dict[UnitType, int]:
@@ -142,6 +169,12 @@ class Debriefing:
enemy.name: {k: v - self.destroyed_units[enemy.name].get(k, 0) for k, v in enemy_units.items()}, enemy.name: {k: v - self.destroyed_units[enemy.name].get(k, 0) for k, v in enemy_units.items()},
} }
for mission_id in self._dead_objects:
for group in mission.country(enemy.name).static_group + mission.country(enemy.name).vehicle_group:
if mission_id in [x.id for x in group.units]:
logging.info("debriefing: connected id {} to group {}".format(mission_id, str(group.name)))
self.destroyed_objects.append(str(group.name))
def debriefing_directory_location() -> str: def debriefing_directory_location() -> str:
return os.path.join(base_path(), "liberation_debriefings") return os.path.join(base_path(), "liberation_debriefings")

View File

@@ -6,11 +6,7 @@ from io import StringIO
from tkinter import * from tkinter import *
from tkinter.scrolledtext import * from tkinter.scrolledtext import *
if "-stdout" in sys.argv: _version_string = None
logging.basicConfig(stream=sys.stdout, level=logging.INFO)
else:
log_stream = StringIO()
logging.basicConfig(stream=log_stream, level=logging.INFO)
def _error_prompt(): def _error_prompt():
@@ -29,5 +25,16 @@ def _handle_exception(self, exception: BaseException, *args):
_error_prompt() _error_prompt()
Tk.report_callback_exception = _handle_exception def setup_version_string(str):
logging.info("DCS Libration 1.3 RC2") global _version_string
_version_string = str
if "--stdout" in sys.argv:
logging.basicConfig(stream=sys.stdout, level=logging.INFO)
else:
log_stream = StringIO()
logging.basicConfig(stream=log_stream, level=logging.INFO)
Tk.report_callback_exception = _handle_exception
logging.info("DCS Libration {}".format(_version_string))

View File

@@ -2,6 +2,7 @@ import logging
import typing import typing
import pickle import pickle
import os import os
import sys
import shutil import shutil
_user_folder = None # type: str _user_folder = None # type: str
@@ -17,7 +18,7 @@ def base_path() -> str:
assert _user_folder assert _user_folder
openbeta_path = os.path.join(_user_folder, "Saved Games", "DCS.openbeta") openbeta_path = os.path.join(_user_folder, "Saved Games", "DCS.openbeta")
if os.path.exists(openbeta_path): if "--force-stable-DCS" not in sys.argv and os.path.exists(openbeta_path):
return openbeta_path return openbeta_path
else: else:
return os.path.join(_user_folder, "Saved Games", "DCS") return os.path.join(_user_folder, "Saved Games", "DCS")
@@ -43,11 +44,8 @@ def restore_game():
if not _save_file_exists(): if not _save_file_exists():
return None return None
try: with open(_save_file(), "rb") as f:
with open(_save_file(), "rb") as f: return pickle.load(f)
return pickle.load(f)
except Exception as e:
raise e
def save_game(game) -> bool: def save_game(game) -> bool: