mirror of
https://github.com/dcs-liberation/dcs_liberation.git
synced 2025-11-10 14:22:26 +00:00
Compare commits
32 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
397f9a58cb | ||
|
|
4fc766a524 | ||
|
|
3f8b5c6c00 | ||
|
|
ce43be0d67 | ||
|
|
ff08888385 | ||
|
|
6b96410ea4 | ||
|
|
f21bd10f09 | ||
|
|
07b35f8ee1 | ||
|
|
251435ae0b | ||
|
|
b81bf90319 | ||
|
|
d6b1b8665d | ||
|
|
64bd3e6a52 | ||
|
|
520a0f91fd | ||
|
|
0015667829 | ||
|
|
35a7da2816 | ||
|
|
5bbf3fc49f | ||
|
|
7a8dfeb819 | ||
|
|
e28a24c875 | ||
|
|
823c6a6137 | ||
|
|
2cbe63f162 | ||
|
|
93d0746d3e | ||
|
|
8cb7c7378f | ||
|
|
3500c85e8d | ||
|
|
c699567c73 | ||
|
|
056c397e68 | ||
|
|
8431c7745d | ||
|
|
edf9efddf9 | ||
|
|
03fc17fae6 | ||
|
|
6fb342a42c | ||
|
|
262347f8c8 | ||
|
|
1176b92073 | ||
|
|
afb084ebf8 |
@@ -43,7 +43,7 @@ def is_version_compatible(save_version):
|
||||
if current_version_components == save_version_components:
|
||||
return True
|
||||
|
||||
if save_version == "1.4_rc1":
|
||||
if save_version in ["1.4_rc1", "1.4_rc2", "1.4_rc3"]:
|
||||
return False
|
||||
|
||||
if current_version_components[:2] == save_version_components[:2]:
|
||||
@@ -70,7 +70,8 @@ try:
|
||||
for i in range(0, int(len(conflicttheater.controlpoints) / 2)):
|
||||
conflicttheater.controlpoints[i].captured = True
|
||||
|
||||
start_generator.generate_initial(conflicttheater, enemy_name, sams, multiplier)
|
||||
start_generator.generate_inital_units(conflicttheater, enemy_name, sams, multiplier)
|
||||
start_generator.generate_groundobjects(conflicttheater)
|
||||
game = Game(player_name=player_name,
|
||||
enemy_name=enemy_name,
|
||||
theater=conflicttheater)
|
||||
|
||||
@@ -76,6 +76,7 @@ PRICES = {
|
||||
S_3B_Tanker: 13,
|
||||
IL_78M: 13,
|
||||
KC_135: 13,
|
||||
KC130: 13,
|
||||
|
||||
A_50: 8,
|
||||
E_3A: 8,
|
||||
@@ -172,6 +173,7 @@ UNIT_BY_TASK = {
|
||||
Refueling: [
|
||||
IL_78M,
|
||||
KC_135,
|
||||
KC130,
|
||||
],
|
||||
|
||||
AWACS: [E_3A, A_50, ],
|
||||
@@ -297,6 +299,7 @@ UNIT_BY_COUNTRY = {
|
||||
AV8BNA,
|
||||
|
||||
KC_135,
|
||||
KC130,
|
||||
S_3B_Tanker,
|
||||
C_130,
|
||||
E_3A,
|
||||
@@ -340,6 +343,10 @@ PLANE_PAYLOAD_OVERRIDES = {
|
||||
CAP: "AIM-120*4,AIM-9*2,AIM-7*2,Fuel",
|
||||
},
|
||||
|
||||
Su_25T: {
|
||||
CAS: "APU-8 Vikhr-M*2,Kh-25ML,R-73*2,SPPU-22*2,Mercury LLTV Pod,MPS-410",
|
||||
},
|
||||
|
||||
Su_33: {
|
||||
CAP: "R-73*4,R-27R*2,R-27ER*6",
|
||||
},
|
||||
@@ -364,6 +371,7 @@ PLANE_PAYLOAD_OVERRIDES = {
|
||||
|
||||
M_2000C: {
|
||||
CAP: "Combat Air Patrol",
|
||||
GroundAttack: "MK-82S Heavy Strike",
|
||||
},
|
||||
|
||||
MiG_21Bis: {
|
||||
|
||||
@@ -87,7 +87,7 @@ class BaseAttackEvent(Event):
|
||||
|
||||
op.setup(cas=flights[CAS],
|
||||
escort=flights[CAP],
|
||||
attack=flights[PinpointStrike],
|
||||
attack=unitdict_from(flights[PinpointStrike]),
|
||||
intercept=assigned_units_from(defenders),
|
||||
defense=self.to_cp.base.armor,
|
||||
aa=self.to_cp.base.assemble_aa())
|
||||
|
||||
@@ -3,6 +3,7 @@ import logging
|
||||
|
||||
from dcs.unittype import UnitType
|
||||
from dcs.task import *
|
||||
from dcs.vehicles import AirDefence
|
||||
from dcs.unittype import UnitType
|
||||
|
||||
from game import *
|
||||
@@ -20,6 +21,7 @@ class Event:
|
||||
silent = False
|
||||
informational = False
|
||||
is_awacs_enabled = False
|
||||
ca_slots = 0
|
||||
operation = None # type: Operation
|
||||
difficulty = 1 # type: int
|
||||
game = None # type: Game
|
||||
@@ -73,6 +75,7 @@ class Event:
|
||||
|
||||
def generate(self):
|
||||
self.operation.is_awacs_enabled = self.is_awacs_enabled
|
||||
self.operation.ca_slots = self.ca_slots
|
||||
|
||||
self.operation.prepare(self.game.theater.terrain, is_quick=False)
|
||||
self.operation.generate()
|
||||
@@ -99,18 +102,16 @@ class Event:
|
||||
|
||||
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)
|
||||
if ground_object.is_dead:
|
||||
continue
|
||||
|
||||
remove_ids.reverse()
|
||||
for i in remove_ids:
|
||||
del cp.ground_objects[i]
|
||||
if ground_object.matches_string_identifier(object_identifier):
|
||||
logging.info("cp {} killing ground object {}".format(cp, ground_object.string_identifier))
|
||||
cp.ground_objects[i].is_dead = True
|
||||
|
||||
def skip(self):
|
||||
pass
|
||||
|
||||
@@ -8,7 +8,7 @@ class FrontlineAttackEvent(Event):
|
||||
TARGET_AMOUNT_FACTOR = 0.5
|
||||
ATTACKER_AMOUNT_FACTOR = 0.4
|
||||
ATTACKER_DEFENDER_FACTOR = 0.7
|
||||
STRENGTH_INFLUENCE = 0.2
|
||||
STRENGTH_INFLUENCE = 0.3
|
||||
SUCCESS_FACTOR = 1.5
|
||||
|
||||
defenders = None # type: db.ArmorDict
|
||||
|
||||
@@ -5,7 +5,7 @@ from userdata.debriefing import Debriefing
|
||||
|
||||
class FrontlinePatrolEvent(Event):
|
||||
ESCORT_FACTOR = 0.5
|
||||
STRENGTH_INFLUENCE = 0.2
|
||||
STRENGTH_INFLUENCE = 0.3
|
||||
SUCCESS_FACTOR = 0.8
|
||||
|
||||
cas = None # type: db.PlaneDict
|
||||
@@ -70,7 +70,7 @@ class FrontlinePatrolEvent(Event):
|
||||
op.setup(cas=assigned_units_from(self.cas),
|
||||
escort=assigned_units_from(self.escort),
|
||||
interceptors=flights[CAP],
|
||||
armor_attackers=db.unitdict_restrict_count(dict_from_flight(flights[PinpointStrike]), sum(defenders.values())),
|
||||
armor_attackers=db.unitdict_restrict_count(db.unitdict_from(flights[PinpointStrike]), sum(defenders.values())),
|
||||
armor_defenders=defenders)
|
||||
|
||||
self.operation = op
|
||||
|
||||
@@ -5,7 +5,7 @@ from .event import *
|
||||
|
||||
class StrikeEvent(Event):
|
||||
STRENGTH_INFLUENCE = 0.0
|
||||
SINGLE_OBJECT_STRENGTH_INFLUENCE = 0.03
|
||||
SINGLE_OBJECT_STRENGTH_INFLUENCE = 0.05
|
||||
|
||||
def __str__(self):
|
||||
return "Strike"
|
||||
@@ -39,6 +39,7 @@ class StrikeEvent(Event):
|
||||
|
||||
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):
|
||||
|
||||
134
game/game.py
134
game/game.py
@@ -25,7 +25,7 @@ COMMISION_LIMITS_FACTORS = {
|
||||
|
||||
COMMISION_AMOUNTS_SCALE = 1.5
|
||||
COMMISION_AMOUNTS_FACTORS = {
|
||||
PinpointStrike: 6,
|
||||
PinpointStrike: 3,
|
||||
CAS: 1,
|
||||
CAP: 2,
|
||||
AirDefence: 0.3,
|
||||
@@ -33,30 +33,39 @@ COMMISION_AMOUNTS_FACTORS = {
|
||||
|
||||
PLAYER_INTERCEPT_GLOBAL_PROBABILITY_BASE = 30
|
||||
PLAYER_INTERCEPT_GLOBAL_PROBABILITY_LOG = 2
|
||||
PLAYER_BASEATTACK_THRESHOLD = 0.2
|
||||
PLAYER_BASEATTACK_THRESHOLD = 0.4
|
||||
|
||||
"""
|
||||
Various events probabilities. First key is player probabilty, second is enemy probability.
|
||||
For the enemy events, only 1 event of each type could be generated for a turn.
|
||||
|
||||
Events:
|
||||
* CaptureEvent - capture base
|
||||
* BaseAttackEvent - capture base
|
||||
* InterceptEvent - air intercept
|
||||
* FrontlineAttack - frontline attack
|
||||
* GroundAttackEvent - destroy insurgents
|
||||
* FrontlineAttackEvent - frontline attack
|
||||
* FrontlineCAPEvent - frontline attack
|
||||
* NavalInterceptEvent - naval intercept
|
||||
* AntiAAStrikeEvent - anti-AA strike
|
||||
* StrikeEvent - strike event
|
||||
* InfantryTransportEvent - helicopter infantry transport
|
||||
"""
|
||||
EVENT_PROBABILITIES = {
|
||||
BaseAttackEvent: [100, 10],
|
||||
# events always present; only for the player
|
||||
FrontlineAttackEvent: [100, 0],
|
||||
FrontlinePatrolEvent: [100, 0],
|
||||
StrikeEvent: [100, 0],
|
||||
InterceptEvent: [25, 10],
|
||||
InsurgentAttackEvent: [0, 10],
|
||||
NavalInterceptEvent: [25, 10],
|
||||
|
||||
# events randomly present; only for the player
|
||||
InfantryTransportEvent: [25, 0],
|
||||
|
||||
# events conditionally present; for both enemy and player
|
||||
BaseAttackEvent: [100, 5],
|
||||
|
||||
# events randomly present; for both enemy and player
|
||||
InterceptEvent: [25, 5],
|
||||
NavalInterceptEvent: [25, 5],
|
||||
|
||||
# events randomly present; only for the enemy
|
||||
InsurgentAttackEvent: [0, 4],
|
||||
}
|
||||
|
||||
# amount of strength player bases recover for the turn
|
||||
@@ -107,55 +116,82 @@ class Game:
|
||||
game=self))
|
||||
break
|
||||
|
||||
def _generate_events(self):
|
||||
enemy_cap_generated = False
|
||||
enemy_generated_types = []
|
||||
def _generate_player_event(self, event_class, player_cp, enemy_cp):
|
||||
if event_class == NavalInterceptEvent and enemy_cp.radials == LAND:
|
||||
# skip naval events for non-coastal CPs
|
||||
return
|
||||
|
||||
if event_class == BaseAttackEvent and enemy_cp.base.strength > PLAYER_BASEATTACK_THRESHOLD:
|
||||
# skip base attack events for CPs yet too strong
|
||||
return
|
||||
|
||||
if event_class == StrikeEvent and not enemy_cp.ground_objects:
|
||||
# skip strikes in case of no targets
|
||||
return
|
||||
|
||||
self.events.append(event_class(self.player, self.enemy, player_cp, enemy_cp, self))
|
||||
|
||||
def _generate_enemy_event(self, event_class, player_cp, enemy_cp):
|
||||
if event_class in [type(x) for x in self.events if not self.is_player_attack(x)]:
|
||||
# skip already generated enemy event types
|
||||
return
|
||||
|
||||
if player_cp in self.ignored_cps:
|
||||
# skip attacks against ignored CPs (for example just captured ones)
|
||||
return
|
||||
|
||||
if enemy_cp.base.total_planes == 0:
|
||||
# skip event if there's no planes on the base
|
||||
return
|
||||
|
||||
if player_cp.is_global:
|
||||
# skip carriers
|
||||
return
|
||||
|
||||
if event_class == NavalInterceptEvent:
|
||||
if player_cp.radials == LAND:
|
||||
# skip naval events for non-coastal CPs
|
||||
return
|
||||
elif event_class == StrikeEvent:
|
||||
if not player_cp.ground_objects:
|
||||
# skip strikes if there's no ground objects
|
||||
return
|
||||
elif event_class == BaseAttackEvent:
|
||||
if BaseAttackEvent in [type(x) for x in self.events]:
|
||||
# skip base attack event if there's another one going on
|
||||
return
|
||||
|
||||
if enemy_cp.base.total_armor == 0:
|
||||
# skip base attack if there's no armor
|
||||
return
|
||||
|
||||
if player_cp.base.strength > PLAYER_BASEATTACK_THRESHOLD:
|
||||
# skip base attack if strength is too high
|
||||
return
|
||||
|
||||
self.events.append(event_class(self.enemy, self.player, enemy_cp, player_cp, self))
|
||||
|
||||
def _generate_events(self):
|
||||
for player_cp, enemy_cp in self.theater.conflicts(True):
|
||||
if player_cp.is_global or enemy_cp.is_global:
|
||||
if enemy_cp.is_global:
|
||||
continue
|
||||
|
||||
for event_class, (player_probability, enemy_probability) in EVENT_PROBABILITIES.items():
|
||||
if event_class == FrontlineAttackEvent or event_class == InfantryTransportEvent or event_class == FrontlinePatrolEvent:
|
||||
if event_class in [FrontlineAttackEvent, FrontlinePatrolEvent, InfantryTransportEvent]:
|
||||
# skip events requiring frontline
|
||||
if not Conflict.has_frontline_between(player_cp, enemy_cp):
|
||||
continue
|
||||
|
||||
if player_cp.is_global:
|
||||
# skip events requiring ground CP
|
||||
if event_class not in [InterceptEvent, StrikeEvent, NavalInterceptEvent]:
|
||||
continue
|
||||
|
||||
if player_probability == 100 or self._roll(player_probability, player_cp.base.strength):
|
||||
if event_class == NavalInterceptEvent and enemy_cp.radials == LAND:
|
||||
pass
|
||||
else:
|
||||
if event_class == BaseAttackEvent and enemy_cp.base.strength > PLAYER_BASEATTACK_THRESHOLD:
|
||||
pass
|
||||
else:
|
||||
if event_class == StrikeEvent and not enemy_cp.ground_objects:
|
||||
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:
|
||||
continue
|
||||
self._generate_player_event(event_class, player_cp, enemy_cp)
|
||||
|
||||
if player_cp in self.ignored_cps:
|
||||
continue
|
||||
|
||||
if enemy_cp.base.total_planes == 0:
|
||||
continue
|
||||
|
||||
if event_class == NavalInterceptEvent:
|
||||
if player_cp.radials == LAND:
|
||||
continue
|
||||
elif event_class == StrikeEvent:
|
||||
if not player_cp.ground_objects:
|
||||
continue
|
||||
elif event_class == BaseAttackEvent:
|
||||
if enemy_cap_generated:
|
||||
continue
|
||||
if enemy_cp.base.total_armor == 0:
|
||||
continue
|
||||
enemy_cap_generated = True
|
||||
|
||||
enemy_generated_types.append(event_class)
|
||||
self.events.append(event_class(self.enemy, self.player, enemy_cp, player_cp, self))
|
||||
if enemy_probability == 100 or self._roll(enemy_probability, enemy_cp.base.strength):
|
||||
self._generate_enemy_event(event_class, player_cp, enemy_cp)
|
||||
|
||||
def commision_unit_types(self, cp: ControlPoint, for_task: Task) -> typing.Collection[UnitType]:
|
||||
importance_factor = (cp.importance - IMPORTANCE_LOW) / (IMPORTANCE_HIGH - IMPORTANCE_LOW)
|
||||
|
||||
@@ -59,5 +59,11 @@ class BaseAttackOperation(Operation):
|
||||
|
||||
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."
|
||||
|
||||
if self.game.player == self.attacker_name:
|
||||
self.briefinggen.append_waypoint("TARGET")
|
||||
else:
|
||||
pass
|
||||
|
||||
super(BaseAttackOperation, self).generate()
|
||||
|
||||
|
||||
@@ -47,8 +47,12 @@ class FrontlineAttackOperation(Operation):
|
||||
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.airgen.generate_cas_strikegroup(*assigned_units_split(dict),
|
||||
at=farp,
|
||||
escort=len(planes_flights) == 0)
|
||||
|
||||
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."
|
||||
self.briefinggen.append_waypoint("CAS AREA IP")
|
||||
self.briefinggen.append_waypoint("CAS AREA EGRESS")
|
||||
super(FrontlineAttackOperation, self).generate()
|
||||
|
||||
@@ -51,4 +51,6 @@ class FrontlinePatrolOperation(Operation):
|
||||
|
||||
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."
|
||||
self.briefinggen.append_waypoint("CAP AREA IP")
|
||||
self.briefinggen.append_waypoint("CAP AREA EGRESS")
|
||||
super(FrontlinePatrolOperation, self).generate()
|
||||
|
||||
@@ -36,6 +36,7 @@ class InfantryTransportOperation(Operation):
|
||||
|
||||
self.briefinggen.title = "Infantry transport"
|
||||
self.briefinggen.description = "Helicopter operation to transport infantry troops from the base to the front line. Lowers target strength"
|
||||
self.briefinggen.append_waypoint("DROP POINT")
|
||||
|
||||
# TODO: horrible, horrible hack
|
||||
# this will disable vehicle activation triggers,
|
||||
|
||||
@@ -28,10 +28,11 @@ class InsurgentAttackOperation(Operation):
|
||||
conflict=conflict)
|
||||
|
||||
def generate(self):
|
||||
self.airgen.generate_defense(*assigned_units_split(self.strikegroup), at=self.defenders_starting_position)
|
||||
self.airgen.generate_defenders_cas(*assigned_units_split(self.strikegroup), at=self.defenders_starting_position)
|
||||
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."
|
||||
self.briefinggen.append_waypoint("TARGET")
|
||||
|
||||
super(InsurgentAttackOperation, self).generate()
|
||||
|
||||
@@ -56,7 +56,14 @@ class InterceptOperation(Operation):
|
||||
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"
|
||||
|
||||
if self.game.player == self.attacker_name:
|
||||
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.briefinggen.append_waypoint("TARGET")
|
||||
for unit_type, count in self.transport.items():
|
||||
self.briefinggen.append_target("{} ({})".format(db.unit_type_name(unit_type), count))
|
||||
else:
|
||||
self.briefinggen.description = "Escort friendly supply transport aircraft. Operation will be considered failed if most of the targets are destroyed, lowering CP strength as a result"
|
||||
|
||||
super(InterceptOperation, self).generate()
|
||||
|
||||
|
||||
@@ -48,7 +48,13 @@ class NavalInterceptionOperation(Operation):
|
||||
)
|
||||
|
||||
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."
|
||||
if self.game.player == self.attacker_name:
|
||||
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."
|
||||
for unit_type, count in self.targets.items():
|
||||
self.briefinggen.append_target("{} ({})".format(db.unit_type_name(unit_type), count))
|
||||
else:
|
||||
self.briefinggen.description = "Protect supply transport ships."
|
||||
self.briefinggen.append_waypoint("TARGET")
|
||||
|
||||
super(NavalInterceptionOperation, self).generate()
|
||||
|
||||
|
||||
@@ -4,6 +4,8 @@ from userdata.debriefing import *
|
||||
|
||||
from gen import *
|
||||
|
||||
TANKER_CALLSIGNS = ["Texaco", "Arco", "Shell"]
|
||||
|
||||
|
||||
class Operation:
|
||||
attackers_starting_position = None # type: db.StartingPosition
|
||||
@@ -27,6 +29,7 @@ class Operation:
|
||||
trigger_radius = TRIGGER_RADIUS_MEDIUM
|
||||
is_quick = None
|
||||
is_awacs_enabled = False
|
||||
ca_slots = 0
|
||||
|
||||
def __init__(self,
|
||||
game,
|
||||
@@ -50,7 +53,6 @@ class Operation:
|
||||
def initialize(self, mission: Mission, conflict: Conflict):
|
||||
self.mission = mission
|
||||
self.conflict = conflict
|
||||
|
||||
self.armorgen = ArmorConflictGenerator(mission, conflict)
|
||||
self.airgen = AircraftConflictGenerator(mission, conflict, self.game.settings)
|
||||
self.aagen = AAConflictGenerator(mission, conflict)
|
||||
@@ -86,9 +88,18 @@ class Operation:
|
||||
|
||||
# air support
|
||||
self.airsupportgen.generate(self.is_awacs_enabled)
|
||||
self.briefinggen.append_frequency("Tanker", "10X/240 MHz FM")
|
||||
for i, tanker_type in enumerate(self.airsupportgen.generated_tankers):
|
||||
self.briefinggen.append_frequency("Tanker {} ({})".format(TANKER_CALLSIGNS[i], tanker_type), "{}X/{} MHz AM".format(97+i, 130+i))
|
||||
|
||||
if self.is_awacs_enabled:
|
||||
self.briefinggen.append_frequency("AWACS", "244 MHz FM")
|
||||
self.briefinggen.append_frequency("AWACS", "133 MHz AM")
|
||||
|
||||
# combined arms
|
||||
self.mission.groundControl.pilot_can_control_vehicles = self.ca_slots > 0
|
||||
if self.game.player in [country.name for country in self.mission.coalition["blue"].countries.values()]:
|
||||
self.mission.groundControl.blue_tactical_commander = self.ca_slots
|
||||
else:
|
||||
self.mission.groundControl.red_tactical_commander = self.ca_slots
|
||||
|
||||
# ground infrastructure
|
||||
self.groundobjectgen.generate()
|
||||
@@ -112,7 +123,7 @@ class Operation:
|
||||
self.envgen.load(self.environment_settings)
|
||||
|
||||
# main frequencies
|
||||
self.briefinggen.append_frequency("Flight", "251 MHz FM")
|
||||
self.briefinggen.append_frequency("Flight", "251 MHz AM")
|
||||
if self.conflict.from_cp.is_global or self.conflict.to_cp.is_global:
|
||||
self.briefinggen.append_frequency("Carrier", "20X/ICLS CHAN1")
|
||||
|
||||
|
||||
@@ -35,7 +35,18 @@ class StrikeOperation(Operation):
|
||||
conflict=conflict)
|
||||
|
||||
def generate(self):
|
||||
targets = [] # type: typing.List[typing.Tuple[str, Point]]
|
||||
for global_cp in self.game.theater.controlpoints:
|
||||
if not global_cp.is_global:
|
||||
continue
|
||||
|
||||
ship = self.shipgen.generate_carrier(type=db.find_unittype(Carriage, self.game.player)[0],
|
||||
country=self.game.player,
|
||||
at=global_cp.at)
|
||||
|
||||
if global_cp == self.from_cp and not self.is_quick:
|
||||
self.attackers_starting_position = ship
|
||||
|
||||
targets = [] # type: typing.List[typing.Tuple[str, str, Point]]
|
||||
category_counters = {} # type: typing.Dict[str, int]
|
||||
processed_groups = []
|
||||
for object in self.to_cp.ground_objects:
|
||||
@@ -43,20 +54,31 @@ class StrikeOperation(Operation):
|
||||
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.append((str(object), markpoint_name, object.position))
|
||||
|
||||
targets.sort(key=lambda x: self.from_cp.position.distance_to_point(x[1]))
|
||||
targets.sort(key=lambda x: self.from_cp.position.distance_to_point(x[2]))
|
||||
|
||||
self.airgen.generate_ground_attack_strikegroup(*assigned_units_split(self.strikegroup),
|
||||
targets=targets,
|
||||
for (name, markpoint_name, _) in targets:
|
||||
self.briefinggen.append_waypoint("TARGET {} (TP {})".format(str(name), markpoint_name))
|
||||
|
||||
planes_flights = {k: v for k, v in self.strikegroup.items() if k in plane_map.values()}
|
||||
self.airgen.generate_ground_attack_strikegroup(*assigned_units_split(planes_flights),
|
||||
targets=[(mp, pos) for (n, mp, pos) in targets],
|
||||
at=self.attackers_starting_position)
|
||||
|
||||
self.airgen.generate_attackers_escort(*assigned_units_split(self.escort), 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_ground_attack_strikegroup(*assigned_units_split(dict),
|
||||
targets=[(mp, pos) for (n, mp, pos) in targets],
|
||||
at=farp,
|
||||
escort=len(planes_flights) == 0)
|
||||
|
||||
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"
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
class Settings:
|
||||
player_skill = "Good"
|
||||
enemy_skill = "Average"
|
||||
enemy_vehicle_skill = "Average"
|
||||
only_player_takeoff = True
|
||||
night_disabled = False
|
||||
multiplier = 1
|
||||
|
||||
@@ -4,7 +4,7 @@ from .naming import *
|
||||
from dcs.mission import *
|
||||
|
||||
DISTANCE_FACTOR = 0.5, 1
|
||||
EXTRA_AA_MIN_DISTANCE = 35000
|
||||
EXTRA_AA_MIN_DISTANCE = 50000
|
||||
EXTRA_AA_MAX_DISTANCE = 150000
|
||||
EXTRA_AA_POSITION_FROM_CP = 550
|
||||
|
||||
@@ -59,6 +59,9 @@ class ExtraAAConflictGenerator:
|
||||
if cp.position.distance_to_point(self.conflict.from_cp.position) < EXTRA_AA_MIN_DISTANCE:
|
||||
continue
|
||||
|
||||
if cp.position.distance_to_point(self.conflict.to_cp.position) < EXTRA_AA_MIN_DISTANCE:
|
||||
continue
|
||||
|
||||
if cp.position.distance_to_point(self.conflict.position) > EXTRA_AA_MAX_DISTANCE:
|
||||
continue
|
||||
|
||||
|
||||
@@ -449,10 +449,7 @@ class AircraftConflictGenerator:
|
||||
at=at and at or self._group_point(self.conflict.air_attackers_location))
|
||||
|
||||
group.task = CAP.name
|
||||
|
||||
heading = group.position.heading_between_point(self.conflict.position)
|
||||
initial_wayp = group.add_waypoint(group.position.point_from_heading(heading, WORKAROUND_WAYP_DIST), INTERCEPTION_ALT, INTERCEPTION_AIRSPEED)
|
||||
initial_wayp.tasks.append(EngageTargets(max_distance=INTERCEPT_MAX_DISTANCE))
|
||||
group.points[0].tasks.append(EngageTargets(max_distance=INTERCEPT_MAX_DISTANCE))
|
||||
|
||||
wayp = group.add_waypoint(self.conflict.position, WARM_START_ALTITUDE, INTERCEPTION_AIRSPEED)
|
||||
wayp.tasks.append(EngageTargets(max_distance=INTERCEPT_MAX_DISTANCE))
|
||||
|
||||
@@ -9,36 +9,46 @@ from dcs.task import *
|
||||
from dcs.terrain.terrain import NoParkingSlotError
|
||||
|
||||
TANKER_DISTANCE = 15000
|
||||
TANKER_ALT = 10000
|
||||
TANKER_ALT = 6000
|
||||
TANKER_HEADING_OFFSET = 45
|
||||
|
||||
AWACS_DISTANCE = 150000
|
||||
AWACS_ALT = 10000
|
||||
AWACS_ALT = 15000
|
||||
|
||||
|
||||
class AirSupportConflictGenerator:
|
||||
generated_tankers = None # type: typing.List[str]
|
||||
|
||||
def __init__(self, mission: Mission, conflict: Conflict, game):
|
||||
self.mission = mission
|
||||
self.conflict = conflict
|
||||
self.game = game
|
||||
self.generated_tankers = []
|
||||
|
||||
@classmethod
|
||||
def support_tasks(cls) -> typing.Collection[typing.Type[MainTask]]:
|
||||
return [Refueling, AWACS]
|
||||
|
||||
def generate(self, is_awacs_enabled):
|
||||
player_cp = self.conflict.from_cp if self.conflict.from_cp.captured else self.conflict.to_cp
|
||||
tanker_unit = db.find_unittype(Refueling, self.conflict.attackers_side.name)[0]
|
||||
tanker_heading = self.conflict.to_cp.position.heading_between_point(self.conflict.from_cp.position)
|
||||
tanker_position = player_cp.position.point_from_heading(tanker_heading, TANKER_DISTANCE)
|
||||
tanker_group = self.mission.refuel_flight(
|
||||
country=self.mission.country(self.game.player),
|
||||
name=namegen.next_tanker_name(self.mission.country(self.game.player)),
|
||||
airport=None,
|
||||
plane_type=tanker_unit,
|
||||
position=tanker_position,
|
||||
altitude=TANKER_ALT,
|
||||
frequency=240,
|
||||
start_type=StartType.Warm,
|
||||
tacanchannel="99X",
|
||||
)
|
||||
|
||||
tanker_group.points[0].tasks.append(ActivateBeaconCommand(channel=10, unit_id=tanker_group.id, aa=False))
|
||||
for i, tanker_unit_type in enumerate(db.find_unittype(Refueling, self.conflict.attackers_side.name)):
|
||||
self.generated_tankers.append(db.unit_type_name(tanker_unit_type))
|
||||
tanker_heading = self.conflict.to_cp.position.heading_between_point(self.conflict.from_cp.position) + TANKER_HEADING_OFFSET * i
|
||||
tanker_position = player_cp.position.point_from_heading(tanker_heading, TANKER_DISTANCE)
|
||||
tanker_group = self.mission.refuel_flight(
|
||||
country=self.mission.country(self.game.player),
|
||||
name=namegen.next_tanker_name(self.mission.country(self.game.player)),
|
||||
airport=None,
|
||||
plane_type=tanker_unit_type,
|
||||
position=tanker_position,
|
||||
altitude=TANKER_ALT,
|
||||
frequency=130 + i,
|
||||
start_type=StartType.Warm,
|
||||
tacanchannel="{}X".format(97 + i),
|
||||
)
|
||||
|
||||
tanker_group.points[0].tasks.append(ActivateBeaconCommand(channel=97 + i, unit_id=tanker_group.id, aa=False))
|
||||
|
||||
if is_awacs_enabled:
|
||||
awacs_unit = db.find_unittype(AWACS, self.conflict.attackers_side.name)[0]
|
||||
@@ -49,6 +59,6 @@ class AirSupportConflictGenerator:
|
||||
altitude=AWACS_ALT,
|
||||
airport=None,
|
||||
position=self.conflict.position.random_point_within(AWACS_DISTANCE, AWACS_DISTANCE),
|
||||
frequency=244,
|
||||
frequency=133,
|
||||
start_type=StartType.Warm,
|
||||
)
|
||||
|
||||
@@ -45,6 +45,9 @@ class ArmorConflictGenerator:
|
||||
group_size=1,
|
||||
move_formation=PointAction.OffRoad)
|
||||
|
||||
vehicle: Vehicle = group.units[0]
|
||||
vehicle.player_can_drive = True
|
||||
|
||||
if not to:
|
||||
to = self.conflict.position.point_from_heading(0, 500)
|
||||
|
||||
@@ -100,10 +103,8 @@ class ArmorConflictGenerator:
|
||||
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):
|
||||
padding = FRONTLINE_CAS_PADDING if FRONTLINE_CAS_PADDING < self.conflict.distance else 0
|
||||
|
||||
position = self.conflict.position.point_from_heading(self.conflict.heading,
|
||||
random.randint(padding, int(self.conflict.distance - padding)))
|
||||
random.randint(0, self.conflict.distance))
|
||||
self._generate_fight_at(attacker_group_dict, target_group_dict, position)
|
||||
|
||||
def generate_passengers(self, count: int):
|
||||
|
||||
@@ -12,6 +12,7 @@ class BriefingGenerator:
|
||||
title = "" # type: str
|
||||
description = "" # type: str
|
||||
targets = None # type: typing.List[typing.Tuple[str, str]]
|
||||
waypoints = None # type: typing.List[str]
|
||||
|
||||
def __init__(self, mission: Mission, conflict: Conflict, game):
|
||||
self.m = mission
|
||||
@@ -20,6 +21,7 @@ class BriefingGenerator:
|
||||
|
||||
self.freqs = []
|
||||
self.targets = []
|
||||
self.waypoints = []
|
||||
|
||||
def append_frequency(self, name: str, frequency: str):
|
||||
self.freqs.append((name, frequency))
|
||||
@@ -27,7 +29,14 @@ class BriefingGenerator:
|
||||
def append_target(self, description: str, markpoint: str = None):
|
||||
self.targets.append((description, markpoint))
|
||||
|
||||
def append_waypoint(self, description: str):
|
||||
self.waypoints.append(description)
|
||||
|
||||
def generate(self):
|
||||
self.waypoints.insert(0, "INITIAL")
|
||||
self.waypoints.append("RTB")
|
||||
self.waypoints.append("RTB Landing")
|
||||
|
||||
description = ""
|
||||
|
||||
if self.title:
|
||||
@@ -43,7 +52,12 @@ class BriefingGenerator:
|
||||
|
||||
if self.targets:
|
||||
description += "\n\nTARGETS:"
|
||||
for name, tp in self.targets:
|
||||
description += "\n{} {}".format(name, "(TP {})".format(tp) if tp else "")
|
||||
for i, (name, tp) in enumerate(self.targets):
|
||||
description += "\n#{} {} {}".format(i+1, name, "(TP {})".format(tp) if tp else "")
|
||||
|
||||
if self.waypoints:
|
||||
description += "\n\nWAYPOINTS:"
|
||||
for i, descr in enumerate(self.waypoints):
|
||||
description += "\n#{}: {}".format(i, descr)
|
||||
|
||||
self.m.set_description_text(description)
|
||||
|
||||
@@ -28,6 +28,8 @@ CAP_CAS_DISTANCE = 10000, 120000
|
||||
|
||||
GROUND_INTERCEPT_SPREAD = 5000
|
||||
GROUND_DISTANCE_FACTOR = 1
|
||||
GROUND_DISTANCE = 4000
|
||||
|
||||
GROUND_ATTACK_DISTANCE = 25000, 13000
|
||||
|
||||
TRANSPORT_FRONTLINE_DIST = 1800
|
||||
@@ -128,19 +130,22 @@ class Conflict:
|
||||
return self.to_cp.size * GROUND_DISTANCE_FACTOR
|
||||
|
||||
def find_insertion_point(self, other_point: Point) -> Point:
|
||||
dx = self.position.x - self.tail.x
|
||||
dy = self.position.y - self.tail.y
|
||||
dr2 = float(dx ** 2 + dy ** 2)
|
||||
if self.is_vector:
|
||||
dx = self.position.x - self.tail.x
|
||||
dy = self.position.y - self.tail.y
|
||||
dr2 = float(dx ** 2 + dy ** 2)
|
||||
|
||||
lerp = ((other_point.x - self.tail.x) * dx + (other_point.y - self.tail.y) * dy) / dr2
|
||||
if lerp < 0:
|
||||
lerp = 0
|
||||
elif lerp > 1:
|
||||
lerp = 1
|
||||
lerp = ((other_point.x - self.tail.x) * dx + (other_point.y - self.tail.y) * dy) / dr2
|
||||
if lerp < 0:
|
||||
lerp = 0
|
||||
elif lerp > 1:
|
||||
lerp = 1
|
||||
|
||||
x = lerp * dx + self.tail.x
|
||||
y = lerp * dy + self.tail.y
|
||||
return Point(x, y)
|
||||
x = lerp * dx + self.tail.x
|
||||
y = lerp * dy + self.tail.y
|
||||
return Point(x, y)
|
||||
else:
|
||||
return self.position
|
||||
|
||||
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)
|
||||
@@ -150,14 +155,28 @@ class Conflict:
|
||||
return from_cp.has_frontline and to_cp.has_frontline
|
||||
|
||||
@classmethod
|
||||
def frontline_position(cls, from_cp: ControlPoint, to_cp: ControlPoint) -> typing.Tuple[Point, int]:
|
||||
distance = max(from_cp.position.distance_to_point(to_cp.position) * FRONTLINE_DISTANCE_STRENGTH_FACTOR * to_cp.base.strength, FRONTLINE_MIN_CP_DISTANCE)
|
||||
heading = to_cp.position.heading_between_point(from_cp.position)
|
||||
return to_cp.position.point_from_heading(heading, distance), heading
|
||||
def frontline_position(cls, theater: ConflictTheater, from_cp: ControlPoint, to_cp: ControlPoint) -> typing.Optional[typing.Tuple[Point, int]]:
|
||||
attack_heading = from_cp.position.heading_between_point(to_cp.position)
|
||||
attack_distance = from_cp.position.distance_to_point(to_cp.position)
|
||||
middle_point = from_cp.position.point_from_heading(attack_heading, attack_distance / 2)
|
||||
|
||||
strength_delta = (from_cp.base.strength - to_cp.base.strength) / 1.0
|
||||
position = middle_point.point_from_heading(attack_heading, strength_delta * attack_distance / 2 - FRONTLINE_MIN_CP_DISTANCE)
|
||||
ground_position = cls._find_ground_position(position, attack_distance / 2 - FRONTLINE_MIN_CP_DISTANCE, attack_heading, theater)
|
||||
if ground_position:
|
||||
return ground_position, _opposite_heading(attack_heading)
|
||||
else:
|
||||
logging.warning("Coudn't find frontline position between {} and {}!".format(from_cp, to_cp))
|
||||
return position, _opposite_heading(attack_heading)
|
||||
|
||||
|
||||
@classmethod
|
||||
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)
|
||||
def frontline_vector(cls, from_cp: ControlPoint, to_cp: ControlPoint, theater: ConflictTheater) -> typing.Optional[typing.Tuple[Point, int, int]]:
|
||||
frontline = cls.frontline_position(theater, from_cp, to_cp)
|
||||
if not frontline:
|
||||
return None
|
||||
|
||||
center_position, heading = frontline
|
||||
left_position, right_position = None, None
|
||||
|
||||
if not theater.is_on_land(center_position):
|
||||
@@ -170,7 +189,6 @@ class Conflict:
|
||||
if pos:
|
||||
left_position = pos
|
||||
center_position = pos
|
||||
print("{} - {} {}".format(from_cp, to_cp, center_position))
|
||||
|
||||
if left_position is None:
|
||||
left_position = cls._extend_ground_position(center_position, int(FRONTLINE_LENGTH/2), _heading_sum(heading, -90), theater)
|
||||
@@ -211,12 +229,12 @@ class Conflict:
|
||||
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
|
||||
distance = GROUND_DISTANCE
|
||||
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)
|
||||
attackers_location = Conflict._find_ground_position(attackers_location, distance * 2, attack_heading, 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)
|
||||
defenders_location = position.point_from_heading(defense_heading, 0)
|
||||
defenders_location = Conflict._find_ground_position(defenders_location, distance * 2, defense_heading, theater)
|
||||
|
||||
return cls(
|
||||
position=position,
|
||||
@@ -394,7 +412,7 @@ class Conflict:
|
||||
|
||||
@classmethod
|
||||
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(theater, from_cp, to_cp)
|
||||
initial_dest = frontline_position.point_from_heading(heading, TRANSPORT_FRONTLINE_DIST)
|
||||
dest = cls._find_ground_position(initial_dest, from_cp.position.distance_to_point(to_cp.position) / 3, heading, theater)
|
||||
if not dest:
|
||||
|
||||
@@ -30,9 +30,9 @@ RANDOM_TIME = {
|
||||
|
||||
RANDOM_WEATHER = {
|
||||
1: 0, # heavy rain
|
||||
2: 10, # rain
|
||||
3: 20, # dynamic
|
||||
4: 30, # clear
|
||||
2: 5, # rain
|
||||
3: 15, # dynamic
|
||||
4: 40, # clear
|
||||
5: 100, # random
|
||||
}
|
||||
|
||||
@@ -49,7 +49,8 @@ class EnviromentGenerator:
|
||||
self.game = game
|
||||
|
||||
def _gen_random_time(self):
|
||||
start_time = datetime.fromtimestamp(1527206400)
|
||||
start_time = datetime.strptime('May 25 2018 12:00AM', '%b %d %Y %I:%M%p')
|
||||
|
||||
time_range = None
|
||||
for k, v in RANDOM_TIME.items():
|
||||
if self.game.settings.night_disabled and k == "night":
|
||||
@@ -60,6 +61,11 @@ class EnviromentGenerator:
|
||||
break
|
||||
|
||||
start_time += timedelta(hours=random.randint(*time_range))
|
||||
logging.info("time - {}, slot - {}, night skipped - {}".format(
|
||||
str(start_time),
|
||||
str(time_range),
|
||||
self.game.settings.night_disabled))
|
||||
|
||||
self.mission.start_time = start_time
|
||||
|
||||
def _gen_random_weather(self):
|
||||
@@ -85,7 +91,7 @@ class EnviromentGenerator:
|
||||
self.mission.weather.clouds_thickness = random.randint(*WEATHER_CLOUD_THICKNESS)
|
||||
|
||||
wind_direction = random.randint(0, 360)
|
||||
wind_speed = random.randint(0, 13)
|
||||
wind_speed = random.randint(0, 4)
|
||||
self.mission.weather.wind_at_ground = Wind(wind_direction, wind_speed)
|
||||
self.mission.weather.wind_at_2000 = Wind(wind_direction, wind_speed * 2)
|
||||
self.mission.weather.wind_at_8000 = Wind(wind_direction, wind_speed * 3)
|
||||
|
||||
@@ -8,17 +8,7 @@ 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],
|
||||
}
|
||||
AA_CP_MIN_DISTANCE = 40000
|
||||
|
||||
|
||||
class GroundObjectsGenerator:
|
||||
@@ -30,11 +20,15 @@ class GroundObjectsGenerator:
|
||||
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)):
|
||||
if self.conflict.is_vector:
|
||||
center = self.conflict.center
|
||||
heading = self.conflict.heading - 90
|
||||
position = self.conflict.find_ground_position(self.conflict.center.point_from_heading(heading, FARP_FRONTLINE_DISTANCE), heading)
|
||||
else:
|
||||
center, heading = self.conflict.frontline_position(self.conflict.theater, self.conflict.from_cp, self.conflict.to_cp)
|
||||
heading -= 90
|
||||
|
||||
position = self.conflict.find_ground_position(center.point_from_heading(heading, FARP_FRONTLINE_DISTANCE), heading)
|
||||
for i, _ in enumerate(range(0, number_of_units, self.FARP_CAPACITY)):
|
||||
position = position.point_from_heading(0, i * 275)
|
||||
|
||||
yield self.m.farp(
|
||||
@@ -53,7 +47,13 @@ class GroundObjectsGenerator:
|
||||
cp = self.conflict.from_cp
|
||||
|
||||
for ground_object in cp.ground_objects:
|
||||
if ground_object.category == "defense":
|
||||
if ground_object.dcs_identifier == "AA":
|
||||
if ground_object.position.distance_to_point(self.conflict.from_cp.position) < AA_CP_MIN_DISTANCE:
|
||||
continue
|
||||
|
||||
if ground_object.is_dead:
|
||||
continue
|
||||
|
||||
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)
|
||||
|
||||
@@ -62,17 +62,27 @@ class GroundObjectsGenerator:
|
||||
name=ground_object.string_identifier,
|
||||
_type=unit_type,
|
||||
position=ground_object.position,
|
||||
heading=ground_object.heading
|
||||
heading=ground_object.heading,
|
||||
)
|
||||
|
||||
logging.info("generated defense object identifier {} with mission id {}".format(group.name, group.id))
|
||||
else:
|
||||
if ground_object.dcs_identifier in warehouse_map:
|
||||
static_type = warehouse_map[ground_object.dcs_identifier]
|
||||
else:
|
||||
static_type = fortification_map[ground_object.dcs_identifier]
|
||||
|
||||
if not static_type:
|
||||
print("Didn't find {} in static _map(s)!".format(ground_object.dcs_identifier))
|
||||
continue
|
||||
|
||||
group = self.m.static_group(
|
||||
country=side,
|
||||
name=ground_object.string_identifier,
|
||||
_type=random.choice(CATEGORY_MAPPING[ground_object.category]),
|
||||
_type=static_type,
|
||||
position=ground_object.position,
|
||||
heading=ground_object.heading
|
||||
heading=ground_object.heading,
|
||||
dead=ground_object.is_dead,
|
||||
)
|
||||
|
||||
logging.info("generated object identifier {} with mission id {}".format(group.name, group.id))
|
||||
logging.info("generated {}object identifier {} with mission id {}".format("dead " if ground_object.is_dead else "", group.name, group.id))
|
||||
|
||||
@@ -12,16 +12,18 @@ from dcs.action import *
|
||||
|
||||
from game import db
|
||||
from theater import *
|
||||
from gen.airsupportgen import AirSupportConflictGenerator
|
||||
from gen import *
|
||||
|
||||
PUSH_TRIGGER_SIZE = 3000
|
||||
PUSH_TRIGGER_ACTIVATION_AGL = 100
|
||||
|
||||
REGROUP_ZONE_DISTANCE = 12000
|
||||
REGROUP_ALT = 5000
|
||||
|
||||
TRIGGER_WAYPOINT_OFFSET = 2
|
||||
TRIGGER_MIN_DISTANCE_FROM_START = 10000
|
||||
TRIGGER_RADIUS_MINIMUM = 25000
|
||||
TRIGGER_RADIUS_MINIMUM = 20000
|
||||
|
||||
TRIGGER_RADIUS_SMALL = 30000
|
||||
TRIGGER_RADIUS_MEDIUM = 100000
|
||||
@@ -79,37 +81,41 @@ class TriggersGenerator:
|
||||
if player_cp.position.distance_to_point(group.position) > PUSH_TRIGGER_SIZE * 3:
|
||||
continue
|
||||
|
||||
regroup_heading = self.conflict.to_cp.position.heading_between_point(player_cp.position)
|
||||
|
||||
pos1 = group.position.point_from_heading(regroup_heading, REGROUP_ZONE_DISTANCE)
|
||||
pos2 = group.position.point_from_heading(regroup_heading, REGROUP_ZONE_DISTANCE+5000)
|
||||
w1 = group.add_waypoint(pos1, REGROUP_ALT)
|
||||
w2 = group.add_waypoint(pos2, REGROUP_ALT)
|
||||
|
||||
group.points.remove(w1)
|
||||
group.points.remove(w2)
|
||||
|
||||
group.points.insert(1, w2)
|
||||
group.points.insert(1, w1)
|
||||
|
||||
w1.tasks.append(Silence(True))
|
||||
|
||||
switch_waypoint_task = ControlledTask(SwitchWaypoint(from_waypoint=3, to_waypoint=2))
|
||||
switch_waypoint_task.start_if_user_flag(1, False)
|
||||
w2.tasks.append(switch_waypoint_task)
|
||||
group.points[3].tasks.append(Silence(False))
|
||||
|
||||
group.add_trigger_action(SwitchWaypoint(to_waypoint=4))
|
||||
push_by_trigger.append(group)
|
||||
|
||||
push_trigger_zone = self.mission.triggers.add_triggerzone(player_cp.position, PUSH_TRIGGER_SIZE, name="Push zone")
|
||||
if not group.units[0].is_human():
|
||||
regroup_heading = self.conflict.to_cp.position.heading_between_point(player_cp.position)
|
||||
|
||||
pos1 = group.position.point_from_heading(regroup_heading, REGROUP_ZONE_DISTANCE)
|
||||
pos2 = group.position.point_from_heading(regroup_heading, REGROUP_ZONE_DISTANCE+5000)
|
||||
w1 = group.add_waypoint(pos1, REGROUP_ALT)
|
||||
w2 = group.add_waypoint(pos2, REGROUP_ALT)
|
||||
|
||||
group.points.remove(w1)
|
||||
group.points.remove(w2)
|
||||
|
||||
group.points.insert(1, w2)
|
||||
group.points.insert(1, w1)
|
||||
|
||||
w1.tasks.append(Silence(True))
|
||||
|
||||
switch_waypoint_task = ControlledTask(SwitchWaypoint(from_waypoint=3, to_waypoint=2))
|
||||
switch_waypoint_task.start_if_user_flag(1, False)
|
||||
w2.tasks.append(switch_waypoint_task)
|
||||
group.points[3].tasks.append(Silence(False))
|
||||
|
||||
group.add_trigger_action(SwitchWaypoint(to_waypoint=4))
|
||||
|
||||
push_trigger = TriggerOnce(Event.NoEvent, "Push trigger")
|
||||
|
||||
for group in push_by_trigger:
|
||||
push_trigger.add_condition(AllOfGroupOutsideZone(group.id, push_trigger_zone.id))
|
||||
push_trigger.add_action(AITaskPush(group.id, 1))
|
||||
for unit in group.units:
|
||||
push_trigger.add_condition(UnitAltitudeHigherAGL(unit.id, PUSH_TRIGGER_ACTIVATION_AGL))
|
||||
|
||||
message_string = self.mission.string("Task force is in the air, proceed with the objective (activate waypoint 3).")
|
||||
if not group.units[0].is_human():
|
||||
push_trigger.add_action(AITaskPush(group.id, 1))
|
||||
|
||||
message_string = self.mission.string("Task force is in the air, proceed with the objective.")
|
||||
push_trigger.add_action(MessageToAll(message_string, clearview=True))
|
||||
push_trigger.add_action(SetFlagValue())
|
||||
|
||||
@@ -124,9 +130,9 @@ class TriggersGenerator:
|
||||
def _set_skill(self, player_coalition: str, enemy_coalition: str):
|
||||
for coalition_name, coalition in self.mission.coalition.items():
|
||||
if coalition_name == player_coalition:
|
||||
skill_level = self.game.settings.player_skill
|
||||
skill_level = self.game.settings.player_skill, self.game.settings.player_skill
|
||||
elif coalition_name == enemy_coalition:
|
||||
skill_level = self.game.settings.enemy_skill
|
||||
skill_level = self.game.settings.enemy_skill, self.game.settings.enemy_vehicle_skill
|
||||
else:
|
||||
continue
|
||||
|
||||
@@ -134,10 +140,10 @@ class TriggersGenerator:
|
||||
for plane_group in country.plane_group:
|
||||
for plane_unit in plane_group.units:
|
||||
if plane_unit.skill != Skill.Client and plane_unit.skill != Skill.Player:
|
||||
plane_unit.skill = Skill(skill_level)
|
||||
plane_unit.skill = Skill(skill_level[0])
|
||||
|
||||
for vehicle_group in country.vehicle_group:
|
||||
vehicle_group.set_skill(Skill(skill_level))
|
||||
vehicle_group.set_skill(Skill(skill_level[1]))
|
||||
|
||||
def generate(self, player_cp: ControlPoint, is_quick: bool, activation_trigger_radius: int, awacs_enabled: bool):
|
||||
player_coalition = self.game.player == "USA" and "blue" or "red"
|
||||
|
||||
@@ -98,7 +98,14 @@ class VisualGenerator:
|
||||
|
||||
def _generate_frontline_smokes(self):
|
||||
for from_cp, to_cp in self.game.theater.conflicts():
|
||||
point, heading = Conflict.frontline_position(from_cp, to_cp)
|
||||
if from_cp.is_global or to_cp.is_global:
|
||||
continue
|
||||
|
||||
frontline = Conflict.frontline_position(self.game.theater, from_cp, to_cp)
|
||||
if not frontline:
|
||||
continue
|
||||
|
||||
point, heading = frontline
|
||||
plane_start = point.point_from_heading(turn_heading(heading, 90), FRONTLINE_LENGTH / 2)
|
||||
|
||||
for offset in range(0, FRONTLINE_LENGTH, FRONT_SMOKE_SPACING):
|
||||
|
||||
Binary file not shown.
Binary file not shown.
BIN
resources/groundobject_templates.p
Normal file
BIN
resources/groundobject_templates.p
Normal file
Binary file not shown.
Binary file not shown.
BIN
resources/nevlandmap.p
Normal file
BIN
resources/nevlandmap.p
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
38
resources/tools/generate_example_groundobjects.py
Normal file
38
resources/tools/generate_example_groundobjects.py
Normal file
@@ -0,0 +1,38 @@
|
||||
import typing
|
||||
|
||||
from dcs.mission import *
|
||||
from dcs.terrain import *
|
||||
|
||||
from theater.nevada import *
|
||||
from theater.persiangulf import *
|
||||
from theater.caucasus import *
|
||||
from theater.controlpoint import *
|
||||
|
||||
def find_ground_location(near, theater, max, min) -> typing.Optional[Point]:
|
||||
for _ in range(500):
|
||||
p = near.random_point_within(max, min)
|
||||
if theater.is_on_land(p):
|
||||
return p
|
||||
|
||||
return None
|
||||
|
||||
|
||||
mission = Mission(Nevada())
|
||||
theater = NevadaTheater()
|
||||
|
||||
for cp in theater.enemy_points():
|
||||
for _ in range(0, random.randrange(3, 6)):
|
||||
p = find_ground_location(cp.position, theater, 120000, 5000)
|
||||
if not p:
|
||||
print("Didn't find ground location for {}".format(cp))
|
||||
continue
|
||||
|
||||
mission.flight_group_inflight(
|
||||
mission.country("USA"),
|
||||
"",
|
||||
A_10C,
|
||||
p,
|
||||
10000
|
||||
)
|
||||
|
||||
mission.save("resources/tools/ground_objects_example.miz")
|
||||
50
resources/tools/generate_groundobject_templates.py
Normal file
50
resources/tools/generate_groundobject_templates.py
Normal file
@@ -0,0 +1,50 @@
|
||||
import pickle
|
||||
import typing
|
||||
|
||||
from dcs.mission import Mission
|
||||
from dcs.mapping import Point
|
||||
from dcs.unit import *
|
||||
from dcs.statics import warehouse_map, fortification_map
|
||||
|
||||
|
||||
def load_templates():
|
||||
temp_mis = Mission()
|
||||
temp_mis.load_file("resources/tools/groundobject_templates.miz")
|
||||
|
||||
groups = {} # type: typing.Dict[str, typing.Dict[int, typing.List[Static]]]
|
||||
|
||||
for static_group in temp_mis.country("USA").static_group:
|
||||
for static in static_group.units:
|
||||
static_name = str(static.name).split()[0]
|
||||
tpl_name, tpl_idx = static_name[:-1], int(static_name[-1])
|
||||
|
||||
groups[tpl_name] = groups.get(tpl_name, {})
|
||||
groups[tpl_name][tpl_idx] = groups[tpl_name].get(tpl_idx, [])
|
||||
groups[tpl_name][tpl_idx].append(static)
|
||||
|
||||
tpls = {name: {idx: [] for idx in groups[name].keys()} for name in groups.keys()}
|
||||
for category_name, category_groups in groups.items():
|
||||
for idx, static_groups in category_groups.items():
|
||||
dist = -1
|
||||
a, b = None, None
|
||||
for aa in static_groups:
|
||||
for bb in static_groups:
|
||||
if aa.position.distance_to_point(bb.position) > dist:
|
||||
dist = aa.position.distance_to_point(bb.position)
|
||||
a = aa
|
||||
b = bb
|
||||
|
||||
center = a.position.point_from_heading(a.position.heading_between_point(b.position), dist / 2)
|
||||
for static in static_groups:
|
||||
tpls[category_name][idx].append({
|
||||
"type": static.type,
|
||||
"offset": Point(center.x - static.position.x, center.y - static.position.y),
|
||||
"heading": static.heading,
|
||||
})
|
||||
|
||||
tpls["aa"] = {0: [{"type": "AA", "offset": Point(0, 0), "heading": 0}]}
|
||||
return tpls
|
||||
|
||||
|
||||
with open("resources/groundobject_templates.p", "wb") as f:
|
||||
pickle.dump(load_templates(), f)
|
||||
@@ -1,86 +1,108 @@
|
||||
import pickle
|
||||
import typing
|
||||
|
||||
from game import db
|
||||
from gen.groundobjectsgen import TheaterGroundObject
|
||||
from dcs.mission import Mission
|
||||
from dcs.mapping import Point
|
||||
from dcs.terrain import *
|
||||
from dcs.unitgroup import VehicleGroup, StaticGroup
|
||||
from dcs import vehicles
|
||||
from dcs.unit import *
|
||||
from dcs.statics import warehouse_map, fortification_map
|
||||
|
||||
from game import db
|
||||
from gen.groundobjectsgen import TheaterGroundObject
|
||||
from theater.caucasus import CaucasusTheater
|
||||
from theater.persiangulf import PersianGulfTheater
|
||||
from theater.nevada import NevadaTheater
|
||||
|
||||
m = Mission()
|
||||
m.load_file("./cau_groundobjects.miz")
|
||||
m.load_file("resources/tools/cau_groundobjects.miz")
|
||||
|
||||
result = {}
|
||||
result_by_groups = {} # type: typing.Dict[int, TheaterGroundObject]
|
||||
cp_counters = {}
|
||||
ids_counters = {}
|
||||
group_id_counter = 0
|
||||
previous_group_id = None
|
||||
if isinstance(m.terrain, Caucasus):
|
||||
theater = CaucasusTheater(load_ground_objects=False)
|
||||
elif isinstance(m.terrain, PersianGulf):
|
||||
theater = PersianGulfTheater(load_ground_objects=False)
|
||||
elif isinstance(m.terrain, Nevada):
|
||||
theater = NevadaTheater(load_ground_objects=False)
|
||||
else:
|
||||
assert False
|
||||
|
||||
|
||||
def append_group(cp_id, category, group_id, object_id, position, heading):
|
||||
global result
|
||||
global result_by_groups
|
||||
def closest_cp(location: Point) -> (int, float):
|
||||
global theater
|
||||
min_distance, min_cp = None, None
|
||||
|
||||
ground_object = TheaterGroundObject(category, cp_id, group_id, object_id, position, heading)
|
||||
for cp in theater.controlpoints:
|
||||
if not min_distance or location.distance_to_point(cp.position) < min_distance:
|
||||
min_distance = location.distance_to_point(cp.position)
|
||||
min_cp = cp.id
|
||||
|
||||
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)
|
||||
assert min_cp is not None
|
||||
return min_cp
|
||||
|
||||
|
||||
def parse_name(name: str) -> typing.Tuple:
|
||||
args = str(name.split()[0]).split("|")
|
||||
if __name__ == "__main__":
|
||||
theater_objects = []
|
||||
|
||||
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]
|
||||
for group in m.country("Russia").static_group + m.country("Russia").vehicle_group:
|
||||
for unit in group.units:
|
||||
theater_object = TheaterGroundObject()
|
||||
theater_object.object_id = len(theater_objects) + 1
|
||||
|
||||
return args[0], int(args[1]), int(args[2])
|
||||
theater_object.position = unit.position
|
||||
theater_object.heading = unit.heading
|
||||
|
||||
if isinstance(unit, Vehicle) and unit.type in vehicles.AirDefence.__dict__.values():
|
||||
theater_object.dcs_identifier = "AA"
|
||||
else:
|
||||
theater_object.dcs_identifier = unit.type
|
||||
|
||||
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
|
||||
assert theater_object.dcs_identifier
|
||||
assert theater_object.object_id
|
||||
|
||||
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
|
||||
theater_objects.append(theater_object)
|
||||
|
||||
append_group(cp_id, category, group_id, object_id, group.position, group.units[0].heading)
|
||||
group_ids = 1
|
||||
for object_a in theater_objects:
|
||||
for object_b in theater_objects:
|
||||
if object_a.position.distance_to_point(object_b.position) < 2000:
|
||||
if object_a.group_id and object_b.group_id:
|
||||
continue
|
||||
elif object_a.group_id:
|
||||
object_b.group_id = object_a.group_id
|
||||
object_b.cp_id = object_a.cp_id
|
||||
elif object_b.group_id:
|
||||
object_a.group_id = object_b.group_id
|
||||
object_a.cp_id = object_b.cp_id
|
||||
else:
|
||||
object_a.group_id = group_ids
|
||||
object_b.group_id = group_ids
|
||||
object_a.cp_id = closest_cp(object_a.position)
|
||||
object_b.cp_id = object_a.cp_id
|
||||
group_ids += 1
|
||||
|
||||
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
|
||||
assert object_a.cp_id == object_b.cp_id, "Object {} and {} are placed in group with different airports!".format(object_a.string_identifier, object_b.string_identifier)
|
||||
|
||||
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))
|
||||
for a in theater_objects:
|
||||
if not a.group_id:
|
||||
a.group_id = group_ids
|
||||
a.cp_id = closest_cp(a.position)
|
||||
group_ids += 1
|
||||
|
||||
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("resources/cau_groundobjects.p", "wb") as f:
|
||||
result = {}
|
||||
for theater_object in theater_objects:
|
||||
assert theater_object.cp_id
|
||||
assert theater_object.group_id
|
||||
assert theater_object.object_id
|
||||
|
||||
if theater_object.cp_id not in result:
|
||||
result[theater_object.cp_id] = []
|
||||
result[theater_object.cp_id].append(theater_object)
|
||||
|
||||
with open("../cau_groundobjects.p", "wb") as f:
|
||||
pickle.dump(result, f)
|
||||
print("Total {} objects".format(len(theater_objects)))
|
||||
for cp_id, objects in result.items():
|
||||
print("{}: total {} objects".format(m.terrain.airport_by_id(cp_id), len(objects)))
|
||||
|
||||
pickle.dump(result, f)
|
||||
|
||||
|
||||
@@ -1,14 +1,26 @@
|
||||
import pickle
|
||||
|
||||
from dcs.mission import Mission
|
||||
from dcs.planes import A_10C
|
||||
|
||||
for terrain in ["cau", "gulf"]:
|
||||
for terrain in ["cau", "gulf", "nev"]:
|
||||
m = Mission()
|
||||
m.load_file("./{}_terrain.miz".format(terrain))
|
||||
|
||||
landmap = []
|
||||
inclusion_zones = []
|
||||
exclusion_zones = []
|
||||
for plane_group in m.country("USA").plane_group:
|
||||
landmap.append([(x.position.x, x.position.y) for x in plane_group.points])
|
||||
zone = [(x.position.x, x.position.y) for x in plane_group.points]
|
||||
|
||||
if terrain == "cau" and inclusion_zones:
|
||||
# legacy
|
||||
exclusion_zones.append(zone)
|
||||
else:
|
||||
if plane_group.units[0].type == "F-15C":
|
||||
exclusion_zones.append(zone)
|
||||
else:
|
||||
inclusion_zones.append(zone)
|
||||
|
||||
with open("../{}landmap.p".format(terrain), "wb") as f:
|
||||
pickle.dump(landmap, f)
|
||||
print(len(inclusion_zones), len(exclusion_zones))
|
||||
pickle.dump((inclusion_zones, exclusion_zones), f)
|
||||
|
||||
BIN
resources/tools/groundobject_templates.miz
Normal file
BIN
resources/tools/groundobject_templates.miz
Normal file
Binary file not shown.
Binary file not shown.
@@ -43,7 +43,7 @@ def _mk_archieve():
|
||||
return
|
||||
|
||||
archieve = ZipFile(path, "w")
|
||||
archieve.writestr("start.bat", "py.exe __init__.py \"%UserProfile%\" \"{}\"".format(VERSION))
|
||||
archieve.writestr("start.bat", "py.exe __init__.py \"%UserProfile%\\Saved Games\" \"{}\"".format(VERSION))
|
||||
_zip_dir(archieve, ".")
|
||||
os.chdir("submodules\\dcs")
|
||||
_zip_dir(archieve, "dcs")
|
||||
|
||||
BIN
resources/tools/nev_terrain.miz
Normal file
BIN
resources/tools/nev_terrain.miz
Normal file
Binary file not shown.
Submodule submodules/dcs updated: e2f8478c4e...54eab60f22
@@ -1,3 +1,3 @@
|
||||
from .controlpoint import *
|
||||
from .conflicttheater import *
|
||||
from .base import *
|
||||
from .base import *
|
||||
|
||||
@@ -3,18 +3,20 @@ import typing
|
||||
import math
|
||||
import itertools
|
||||
|
||||
from game import db
|
||||
from theater.controlpoint import ControlPoint
|
||||
|
||||
from dcs.planes import *
|
||||
from dcs.vehicles import *
|
||||
from dcs.task import *
|
||||
|
||||
from game import db
|
||||
|
||||
STRENGTH_AA_ASSEMBLE_MIN = 0.2
|
||||
PLANES_SCRAMBLE_MIN_BASE = 4
|
||||
PLANES_SCRAMBLE_MAX_BASE = 8
|
||||
PLANES_SCRAMBLE_FACTOR = 0.6
|
||||
|
||||
BASE_MAX_STRENGTH = 1
|
||||
BASE_MIN_STRENGTH = 0
|
||||
|
||||
|
||||
class Base:
|
||||
aircraft = {} # type: typing.Dict[PlaneType, int]
|
||||
@@ -125,9 +127,11 @@ class Base:
|
||||
elif unit_type in self.aa:
|
||||
target_array = self.aa
|
||||
else:
|
||||
print("Base didn't find event type {}".format(unit_type))
|
||||
continue
|
||||
|
||||
if unit_type not in target_array:
|
||||
print("Base didn't find event type {}".format(unit_type))
|
||||
continue
|
||||
|
||||
target_array[unit_type] = max(target_array[unit_type] - count, 0)
|
||||
@@ -136,10 +140,10 @@ class Base:
|
||||
|
||||
def affect_strength(self, amount):
|
||||
self.strength += amount
|
||||
if self.strength > 1:
|
||||
self.strength = 1
|
||||
elif self.strength < 0:
|
||||
self.strength = 0.001
|
||||
if self.strength > BASE_MAX_STRENGTH:
|
||||
self.strength = BASE_MAX_STRENGTH
|
||||
elif self.strength <= 0:
|
||||
self.strength = BASE_MIN_STRENGTH
|
||||
|
||||
def scramble_count(self, multiplier: float, task: Task = None) -> int:
|
||||
if task:
|
||||
|
||||
@@ -11,13 +11,13 @@ from .base import *
|
||||
class CaucasusTheater(ConflictTheater):
|
||||
terrain = caucasus.Caucasus()
|
||||
overview_image = "caumap.gif"
|
||||
reference_points = {(-317948.32727306, 635639.37385346): (282.5, 319),
|
||||
(-355692.3067714, 617269.96285781): (269, 352), }
|
||||
reference_points = {(-317948.32727306, 635639.37385346): (278.5, 319),
|
||||
(-355692.3067714, 617269.96285781): (263, 352), }
|
||||
landmap = load_landmap("resources\\caulandmap.p")
|
||||
daytime_map = {
|
||||
"dawn": (6, 9),
|
||||
"day": (9, 18),
|
||||
"dusk": (18, 21),
|
||||
"dusk": (18, 20),
|
||||
"night": (0, 5),
|
||||
}
|
||||
|
||||
@@ -44,9 +44,12 @@ class CaucasusTheater(ConflictTheater):
|
||||
|
||||
carrier_1 = ControlPoint.carrier("Carrier", mapping.Point(-305810.6875, 406399.1875))
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self, load_ground_objects=True):
|
||||
super(CaucasusTheater, self).__init__()
|
||||
|
||||
self.soganlug.frontline_offset = 0.5
|
||||
self.soganlug.base.strength = 1
|
||||
|
||||
self.add_controlpoint(self.soganlug, connected_to=[self.kutaisi, self.beslan])
|
||||
self.add_controlpoint(self.beslan, connected_to=[self.soganlug, self.mozdok, self.nalchik])
|
||||
self.add_controlpoint(self.nalchik, connected_to=[self.beslan, self.mozdok, self.mineralnye])
|
||||
@@ -73,10 +76,7 @@ class CaucasusTheater(ConflictTheater):
|
||||
self.carrier_1.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] = []):
|
||||
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)
|
||||
|
||||
@@ -18,6 +18,8 @@ IMPORTANCE_LOW = 1
|
||||
IMPORTANCE_MEDIUM = 1.2
|
||||
IMPORTANCE_HIGH = 1.4
|
||||
|
||||
GLOBAL_CP_CONFLICT_DISTANCE_MIN = 340000
|
||||
|
||||
"""
|
||||
ALL_RADIALS = [0, 45, 90, 135, 180, 225, 270, 315, ]
|
||||
COAST_NS_E = [45, 90, 135, ]
|
||||
@@ -58,31 +60,36 @@ class ConflictTheater:
|
||||
def __init__(self):
|
||||
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] = []):
|
||||
for connected_point in connected_to:
|
||||
point.connect(to=connected_point)
|
||||
|
||||
self.controlpoints.append(point)
|
||||
|
||||
def is_in_sea(self, point: Point) -> bool:
|
||||
if not self.landmap:
|
||||
return False
|
||||
|
||||
for inclusion_zone in self.landmap[0]:
|
||||
if poly_contains(point.x, point.y, inclusion_zone):
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
def is_on_land(self, point: Point) -> bool:
|
||||
if not self.landmap:
|
||||
return True
|
||||
|
||||
# check first poly (main land poly)
|
||||
if not poly_contains(point.x, point.y, self.landmap[0]):
|
||||
is_point_included = False
|
||||
for inclusion_zone in self.landmap[0]:
|
||||
if poly_contains(point.x, point.y, inclusion_zone):
|
||||
is_point_included = True
|
||||
|
||||
if not is_point_included:
|
||||
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
|
||||
for exclusion_zone in self.landmap[1]:
|
||||
if poly_contains(point.x, point.y, exclusion_zone):
|
||||
return False
|
||||
|
||||
return True
|
||||
@@ -95,5 +102,9 @@ class ConflictTheater:
|
||||
for connected_point in [x for x in cp.connected_points if x.captured != from_player]:
|
||||
yield (cp, connected_point)
|
||||
|
||||
for global_cp in [x for x in self.controlpoints if x.is_global and x.captured == from_player]:
|
||||
if global_cp.position.distance_to_point(connected_point.position) < GLOBAL_CP_CONFLICT_DISTANCE_MIN:
|
||||
yield (global_cp, connected_point)
|
||||
|
||||
def enemy_points(self) -> typing.Collection[ControlPoint]:
|
||||
return [point for point in self.controlpoints if not point.captured]
|
||||
|
||||
@@ -9,16 +9,21 @@ from .theatergroundobject import TheaterGroundObject
|
||||
|
||||
|
||||
class ControlPoint:
|
||||
connected_points = None # type: typing.List[ControlPoint]
|
||||
ground_objects = None # type: typing.Collection[TheaterGroundObject]
|
||||
position = None # type: Point
|
||||
captured = False
|
||||
has_frontline = True
|
||||
id = 0
|
||||
position = None # type: Point
|
||||
name = None # type: str
|
||||
full_name = None # type: str
|
||||
base = None # type: theater.base.Base
|
||||
at = None # type: db.StartPosition
|
||||
|
||||
def __init__(self, id: int, name: str, position: Point, at, radials: typing.Collection[int], size: int, importance: int, has_frontline=True):
|
||||
connected_points = None # type: typing.List[ControlPoint]
|
||||
ground_objects = None # type: typing.List[TheaterGroundObject]
|
||||
|
||||
captured = False
|
||||
has_frontline = True
|
||||
frontline_offset = 0.0
|
||||
|
||||
def __init__(self, id: int, name: str, position: Point, at, radials: typing.Collection[int], size: int, importance: float, has_frontline=True):
|
||||
import theater.base
|
||||
|
||||
self.id = id
|
||||
@@ -37,14 +42,14 @@ class ControlPoint:
|
||||
self.base = theater.base.Base()
|
||||
|
||||
@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: float, has_frontline=True):
|
||||
assert airport
|
||||
return cls(airport.id, airport.name, airport.position, airport, radials, size, importance, has_frontline)
|
||||
|
||||
@classmethod
|
||||
def carrier(cls, name: str, at: Point):
|
||||
import theater.conflicttheater
|
||||
return cls(0, 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, has_frontline=False)
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import pickle
|
||||
import typing
|
||||
|
||||
Landmap = typing.Collection[typing.Collection[typing.Tuple[float, float]]]
|
||||
Zone = typing.Collection[typing.Tuple[float, float]]
|
||||
Landmap = typing.Tuple[typing.Collection[Zone], typing.Collection[Zone]]
|
||||
|
||||
|
||||
def load_landmap(filename: str) -> Landmap:
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
from dcs.terrain import nevada
|
||||
from dcs import mapping
|
||||
|
||||
from .landmap import *
|
||||
from .conflicttheater import *
|
||||
from .base import *
|
||||
|
||||
@@ -10,10 +11,11 @@ class NevadaTheater(ConflictTheater):
|
||||
overview_image = "nevada.gif"
|
||||
reference_points = {(nevada.Mina_Airport_3Q0.position.x, nevada.Mina_Airport_3Q0.position.y): (45, -360),
|
||||
(nevada.Laughlin_Airport.position.x, nevada.Laughlin_Airport.position.y): (440, 80), }
|
||||
landmap = load_landmap("resources\\nev_landmap.p")
|
||||
daytime_map = {
|
||||
"dawn": (4, 6),
|
||||
"day": (6, 17),
|
||||
"dusk": (17, 19),
|
||||
"dusk": (17, 18),
|
||||
"night": (0, 5),
|
||||
}
|
||||
|
||||
|
||||
@@ -19,31 +19,32 @@ class PersianGulfTheater(ConflictTheater):
|
||||
"night": (0, 5),
|
||||
}
|
||||
|
||||
al_dhafra = ControlPoint.from_airport(persiangulf.Al_Dhafra_AB, LAND, SIZE_BIG, IMPORTANCE_HIGH)
|
||||
al_maktoum = ControlPoint.from_airport(persiangulf.Al_Maktoum_Intl, LAND, SIZE_BIG, IMPORTANCE_HIGH)
|
||||
al_minhad = ControlPoint.from_airport(persiangulf.Al_Minhad_AB, LAND, SIZE_REGULAR, IMPORTANCE_HIGH)
|
||||
sir_abu_nuayr = ControlPoint.from_airport(persiangulf.Sir_Abu_Nuayr, [0, 330], SIZE_SMALL, 1.3, has_frontline=False)
|
||||
al_dhafra = ControlPoint.from_airport(persiangulf.Al_Dhafra_AB, LAND, SIZE_BIG, IMPORTANCE_LOW)
|
||||
al_maktoum = ControlPoint.from_airport(persiangulf.Al_Maktoum_Intl, LAND, SIZE_BIG, IMPORTANCE_LOW)
|
||||
al_minhad = ControlPoint.from_airport(persiangulf.Al_Minhad_AB, LAND, SIZE_REGULAR, 1.1)
|
||||
sir_abu_nuayr = ControlPoint.from_airport(persiangulf.Sir_Abu_Nuayr, [0, 330], SIZE_SMALL, 1.1, has_frontline=False)
|
||||
|
||||
dubai = ControlPoint.from_airport(persiangulf.Dubai_Intl, COAST_DL_E, SIZE_LARGE, IMPORTANCE_HIGH)
|
||||
sharjah = ControlPoint.from_airport(persiangulf.Sharjah_Intl, LAND, SIZE_BIG, 1.3)
|
||||
fujairah = ControlPoint.from_airport(persiangulf.Fujairah_Intl, COAST_V_W, SIZE_REGULAR, IMPORTANCE_HIGH)
|
||||
khasab = ControlPoint.from_airport(persiangulf.Khasab, LAND, SIZE_SMALL, IMPORTANCE_HIGH)
|
||||
dubai = ControlPoint.from_airport(persiangulf.Dubai_Intl, COAST_DL_E, SIZE_LARGE, IMPORTANCE_MEDIUM)
|
||||
sharjah = ControlPoint.from_airport(persiangulf.Sharjah_Intl, LAND, SIZE_BIG, 1.0)
|
||||
fujairah = ControlPoint.from_airport(persiangulf.Fujairah_Intl, COAST_V_W, SIZE_REGULAR, 1.0)
|
||||
khasab = ControlPoint.from_airport(persiangulf.Khasab, LAND, SIZE_SMALL, IMPORTANCE_MEDIUM)
|
||||
|
||||
sirri = ControlPoint.from_airport(persiangulf.Sirri_Island, COAST_DL_W, SIZE_REGULAR, IMPORTANCE_LOW, has_frontline=False)
|
||||
abu_musa = ControlPoint.from_airport(persiangulf.Abu_Musa_Island_Airport, LAND, SIZE_SMALL, IMPORTANCE_MEDIUM, has_frontline=False)
|
||||
tunb_island = ControlPoint.from_airport(persiangulf.Tunb_Island_AFB, [0, 270, 330], IMPORTANCE_LOW, 1.1, has_frontline=False)
|
||||
tunb_kochak = ControlPoint.from_airport(persiangulf.Tunb_Kochak, [135, 180], SIZE_SMALL, 1.2, has_frontline=False)
|
||||
tunb_island = ControlPoint.from_airport(persiangulf.Tunb_Island_AFB, [0, 270, 330], SIZE_SMALL, IMPORTANCE_MEDIUM, has_frontline=False)
|
||||
tunb_kochak = ControlPoint.from_airport(persiangulf.Tunb_Kochak, [135, 180], SIZE_SMALL, 1.1, has_frontline=False)
|
||||
|
||||
bandar_lengeh = ControlPoint.from_airport(persiangulf.Bandar_Lengeh, [270, 315, 0, 45], SIZE_SMALL, 1.1)
|
||||
qeshm = ControlPoint.from_airport(persiangulf.Qeshm_Island, [270, 315, 0, 45, 90, 135, 180], SIZE_SMALL, 1.2, has_frontline=False)
|
||||
bandar_lengeh = ControlPoint.from_airport(persiangulf.Bandar_Lengeh, [270, 315, 0, 45], SIZE_SMALL, IMPORTANCE_HIGH)
|
||||
qeshm = ControlPoint.from_airport(persiangulf.Qeshm_Island, [270, 315, 0, 45, 90, 135, 180], SIZE_SMALL, 1.1, has_frontline=False)
|
||||
|
||||
havadarya = ControlPoint.from_airport(persiangulf.Havadarya, COAST_DL_W, SIZE_REGULAR, 1.1)
|
||||
bandar_abbas = ControlPoint.from_airport(persiangulf.Bandar_Abbas_Intl, LAND, SIZE_BIG, 1.2)
|
||||
lar = ControlPoint.from_airport(persiangulf.Lar_Airbase, LAND, SIZE_REGULAR, IMPORTANCE_LOW)
|
||||
shiraz = ControlPoint.from_airport(persiangulf.Shiraz_International_Airport, LAND, SIZE_BIG, IMPORTANCE_LOW)
|
||||
kerman = ControlPoint.from_airport(persiangulf.Kerman_Airport, LAND, SIZE_BIG, IMPORTANCE_LOW)
|
||||
havadarya = ControlPoint.from_airport(persiangulf.Havadarya, COAST_DL_W, SIZE_REGULAR, IMPORTANCE_HIGH)
|
||||
bandar_abbas = ControlPoint.from_airport(persiangulf.Bandar_Abbas_Intl, LAND, SIZE_BIG, IMPORTANCE_HIGH)
|
||||
lar = ControlPoint.from_airport(persiangulf.Lar_Airbase, LAND, SIZE_REGULAR, IMPORTANCE_HIGH)
|
||||
shiraz = ControlPoint.from_airport(persiangulf.Shiraz_International_Airport, LAND, SIZE_BIG, IMPORTANCE_HIGH)
|
||||
kerman = ControlPoint.from_airport(persiangulf.Kerman_Airport, LAND, SIZE_BIG, IMPORTANCE_HIGH)
|
||||
|
||||
west_carrier = ControlPoint.carrier("East carrier", Point(-100531.972946, 60939.275818))
|
||||
west_carrier = ControlPoint.carrier("West carrier", Point(-69043.813952358, -159916.65947136))
|
||||
east_carrier = ControlPoint.carrier("East carrier", Point(59514.324335475, 28165.517980635))
|
||||
|
||||
def __init__(self):
|
||||
super(PersianGulfTheater, self).__init__()
|
||||
@@ -71,18 +72,9 @@ class PersianGulfTheater(ConflictTheater):
|
||||
self.add_controlpoint(self.havadarya, connected_to=[self.lar, self.qeshm, self.bandar_abbas])
|
||||
self.add_controlpoint(self.bandar_abbas, connected_to=[self.havadarya])
|
||||
|
||||
self.add_controlpoint(self.east_carrier)
|
||||
self.add_controlpoint(self.west_carrier)
|
||||
|
||||
self.west_carrier.captured = True
|
||||
self.kerman.captured = True
|
||||
|
||||
"""
|
||||
Mid game:
|
||||
self.al_maktoum.captured = True
|
||||
self.al_minhad.captured = True
|
||||
self.dubai.captured = True
|
||||
self.sharjah.captured = True
|
||||
self.fujairah.captured = True
|
||||
self.khasab.captured = True
|
||||
self.sir_abu_nuayr.captured = True
|
||||
"""
|
||||
self.east_carrier.captured = True
|
||||
self.al_dhafra.captured = True
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
import math
|
||||
import pickle
|
||||
import random
|
||||
import typing
|
||||
|
||||
from theater.base import *
|
||||
from theater.conflicttheater import *
|
||||
@@ -15,7 +18,7 @@ COUNT_BY_TASK = {
|
||||
}
|
||||
|
||||
|
||||
def generate_initial(theater: ConflictTheater, enemy: str, sams: bool, multiplier: float):
|
||||
def generate_inital_units(theater: ConflictTheater, enemy: str, sams: bool, multiplier: float):
|
||||
for cp in theater.enemy_points():
|
||||
if cp.captured:
|
||||
continue
|
||||
@@ -37,3 +40,68 @@ def generate_initial(theater: ConflictTheater, enemy: str, sams: bool, multiplie
|
||||
for unit_type in unittypes:
|
||||
logging.info("{} - {} {}".format(cp.name, db.unit_type_name(unit_type), count_per_type))
|
||||
cp.base.commision_units({unit_type: count_per_type})
|
||||
|
||||
|
||||
def generate_groundobjects(theater: ConflictTheater):
|
||||
with open("resources/groundobject_templates.p", "rb") as f:
|
||||
tpls = pickle.load(f)
|
||||
|
||||
def find_location(on_ground, near, theater, min, max) -> typing.Optional[Point]:
|
||||
point = None
|
||||
for _ in range(1000):
|
||||
p = near.random_point_within(max, min)
|
||||
if on_ground and theater.is_on_land(p):
|
||||
point = p
|
||||
elif not on_ground and theater.is_in_sea(p):
|
||||
point = p
|
||||
|
||||
if point:
|
||||
for angle in range(0, 360, 45):
|
||||
p = point.point_from_heading(angle, 2500)
|
||||
if on_ground and not theater.is_on_land(p):
|
||||
point = None
|
||||
break
|
||||
elif not on_ground and not theater.is_in_sea(p):
|
||||
point = None
|
||||
break
|
||||
|
||||
if point:
|
||||
return point
|
||||
|
||||
return None
|
||||
|
||||
group_id = 0
|
||||
for cp in theater.enemy_points():
|
||||
for _ in range(0, random.randrange(3, 6)):
|
||||
available_categories = list(tpls) + ["aa", "aa", "aa"]
|
||||
tpl_category = random.choice(available_categories)
|
||||
|
||||
tpl = random.choice(list(tpls[tpl_category].values()))
|
||||
|
||||
point = find_location(tpl_category != "oil", cp.position, theater, 15000, 80000)
|
||||
|
||||
if point is None:
|
||||
print("Couldn't find point for {}".format(cp))
|
||||
continue
|
||||
|
||||
dist = point.distance_to_point(cp.position)
|
||||
for another_cp in theater.enemy_points():
|
||||
if another_cp.position.distance_to_point(point) < dist:
|
||||
cp = another_cp
|
||||
|
||||
group_id += 1
|
||||
object_id = 0
|
||||
|
||||
for object in tpl:
|
||||
object_id += 1
|
||||
|
||||
g = TheaterGroundObject()
|
||||
g.group_id = group_id
|
||||
g.object_id = object_id
|
||||
g.cp_id = cp.id
|
||||
|
||||
g.dcs_identifier = object["type"]
|
||||
g.heading = object["heading"]
|
||||
g.position = Point(point.x + object["offset"].x, point.y + object["offset"].y)
|
||||
|
||||
cp.ground_objects.append(g)
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
import typing
|
||||
|
||||
from dcs.mapping import Point
|
||||
from dcs.statics import *
|
||||
|
||||
NAME_BY_CATEGORY = {
|
||||
"power": "Power plant",
|
||||
"ammo": "Ammo depot",
|
||||
"fuel": "Fuel depot",
|
||||
"defense": "AA Defense Site",
|
||||
"aa": "AA Defense Site",
|
||||
"warehouse": "Warehouse",
|
||||
"farp": "FARP",
|
||||
"fob": "FOB",
|
||||
"factory": "Factory",
|
||||
"comms": "Comms. tower",
|
||||
"oil": "Oil platform"
|
||||
}
|
||||
@@ -17,29 +20,47 @@ ABBREV_NAME = {
|
||||
"power": "PLANT",
|
||||
"ammo": "AMMO",
|
||||
"fuel": "FUEL",
|
||||
"defense": "AA",
|
||||
"aa": "AA",
|
||||
"warehouse": "WARE",
|
||||
"farp": "FARP",
|
||||
"fob": "FOB",
|
||||
"factory": "FACTORY",
|
||||
"comms": "COMMST",
|
||||
"oil": "OILP"
|
||||
}
|
||||
|
||||
|
||||
CATEGORY_MAP = {
|
||||
"aa": ["AA"],
|
||||
"power": ["Workshop A", "Electric power box", "Garage small A"],
|
||||
"warehouse": ["Warehouse", "Hangar A"],
|
||||
"fuel": ["Tank", "Tank 2", "Tank 3", "Fuel tank"],
|
||||
"ammo": [".Ammunition depot", "Hangar B"],
|
||||
"farp": ["FARP Tent", "FARP Ammo Dump Coating", "FARP Fuel Depot", "FARP Command Post", "FARP CP Blindage"],
|
||||
"fob": ["Bunker 2", "Bunker 1", "Garage small B", ".Command Center", "Barracks 2"],
|
||||
"factory": ["Tech combine", "Tech hangar A"],
|
||||
"comms": ["TV tower", "Comms tower M"],
|
||||
"oil": ["Oil platform"],
|
||||
}
|
||||
|
||||
|
||||
class TheaterGroundObject:
|
||||
object_id = 0
|
||||
cp_id = 0
|
||||
group_id = 0
|
||||
object_id = 0
|
||||
|
||||
dcs_identifier = None # type: str
|
||||
is_dead = False
|
||||
|
||||
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 category(self) -> str:
|
||||
for k, v in CATEGORY_MAP.items():
|
||||
if self.dcs_identifier in v:
|
||||
return k
|
||||
assert False, "Identifier not found in mapping: {}".format(self.dcs_identifier)
|
||||
|
||||
@property
|
||||
def string_identifier(self):
|
||||
|
||||
@@ -18,53 +18,60 @@ class BaseMenu(Menu):
|
||||
|
||||
def display(self):
|
||||
self.window.clear_right_pane()
|
||||
row = 0
|
||||
|
||||
def purchase_row(unit_type, unit_price):
|
||||
nonlocal row
|
||||
|
||||
existing_units = self.base.total_units_of_type(unit_type)
|
||||
scheduled_units = self.event.units.get(unit_type, 0)
|
||||
|
||||
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), **STYLES["widget"])
|
||||
label.grid(column=1, row=row)
|
||||
self.bought_amount_labels[unit_type] = label
|
||||
|
||||
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), **STYLES["btn-primary"]).grid(column=3, row=row, padx=(10,0))
|
||||
Button(self.frame, text="-", command=self.sell(unit_type), **STYLES["btn-warning"]).grid(column=4, row=row, padx=(10,5))
|
||||
row += 1
|
||||
|
||||
units = {
|
||||
PinpointStrike: db.find_unittype(PinpointStrike, self.game.player),
|
||||
Embarking: db.find_unittype(Embarking, self.game.player),
|
||||
CAS: db.find_unittype(CAS, self.game.player),
|
||||
CAP: db.find_unittype(CAP, self.game.player),
|
||||
Embarking: db.find_unittype(Embarking, self.game.player),
|
||||
AirDefence: db.find_unittype(AirDefence, self.game.player),
|
||||
CAS: db.find_unittype(CAS, self.game.player),
|
||||
PinpointStrike: db.find_unittype(PinpointStrike, self.game.player),
|
||||
}
|
||||
|
||||
# Header
|
||||
head = Frame(self.frame, **STYLES["header"])
|
||||
head.grid(row=row, column=0, columnspan=5, sticky=NSEW, pady=5)
|
||||
head.grid(row=0, column=0, columnspan=99, 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)
|
||||
Button(self.frame, text="Back", command=self.dismiss, **STYLES["btn-primary"]).grid(column=4, row=row, padx=(0,15), pady=(0,5))
|
||||
row += 1
|
||||
self.budget_label.grid(row=1, sticky=W)
|
||||
Button(self.frame, text="Back", command=self.dismiss, **STYLES["btn-primary"]).grid(column=9, row=1, padx=(0,15), pady=(0,5))
|
||||
|
||||
for task_type, units in units.items():
|
||||
Label(self.frame, text="{}".format(db.task_name(task_type)), **STYLES["strong"]).grid(row=row, columnspan=5, sticky=NSEW); row += 1
|
||||
tasks = list(units.keys())
|
||||
tasks_per_column = 3
|
||||
|
||||
units = list(set(units))
|
||||
units.sort(key=lambda x: db.PRICES[x])
|
||||
for unit_type in units:
|
||||
purchase_row(unit_type, db.PRICES[unit_type])
|
||||
column = 0
|
||||
for i, tasks_column in [(i, tasks[idx:idx+tasks_per_column]) for i, idx in enumerate(range(0, len(tasks), tasks_per_column))]:
|
||||
row = 2
|
||||
|
||||
def purchase_row(unit_type, unit_price):
|
||||
nonlocal row
|
||||
nonlocal column
|
||||
|
||||
existing_units = self.base.total_units_of_type(unit_type)
|
||||
scheduled_units = self.event.units.get(unit_type, 0)
|
||||
|
||||
Label(self.frame, text="{}".format(db.unit_type_name(unit_type)), **STYLES["widget"]).grid(row=row, column=column, sticky=W)
|
||||
|
||||
label = Label(self.frame, text="({}) ".format(existing_units), **STYLES["widget"])
|
||||
label.grid(column=column + 1, row=row)
|
||||
self.bought_amount_labels[unit_type] = label
|
||||
|
||||
Label(self.frame, text="{}m".format(unit_price), **STYLES["widget"]).grid(column=column + 2, row=row, sticky=E)
|
||||
Button(self.frame, text="+", command=self.buy(unit_type), **STYLES["btn-primary"]).grid(column=column + 3, row=row, padx=(10,0))
|
||||
Button(self.frame, text="-", command=self.sell(unit_type), **STYLES["btn-warning"]).grid(column=column + 4, row=row, padx=(10,5))
|
||||
row += 1
|
||||
|
||||
for task_type in tasks_column:
|
||||
Label(self.frame, text="{}".format(db.task_name(task_type)), **STYLES["strong"]).grid(row=row, column=column, columnspan=5, sticky=NSEW)
|
||||
row += 1
|
||||
|
||||
units_column = list(set(units[task_type]))
|
||||
units_column.sort(key=lambda x: db.PRICES[x])
|
||||
for unit_type in units_column:
|
||||
purchase_row(unit_type, db.PRICES[unit_type])
|
||||
|
||||
column += 5
|
||||
|
||||
def dismiss(self):
|
||||
if sum([x for x in self.event.units.values()]) == 0:
|
||||
|
||||
@@ -4,6 +4,7 @@ from tkinter import *
|
||||
from tkinter.ttk import *
|
||||
from .styles import STYLES
|
||||
|
||||
from userdata.logging import ShowLogsException
|
||||
from ui.window import *
|
||||
|
||||
|
||||
@@ -17,6 +18,9 @@ class ConfigurationMenu(Menu):
|
||||
self.enemy_skill_var = StringVar()
|
||||
self.enemy_skill_var.set(self.game.settings.enemy_skill)
|
||||
|
||||
self.enemy_vehicle_var = StringVar()
|
||||
self.enemy_vehicle_var.set(self.game.settings.enemy_vehicle_skill)
|
||||
|
||||
self.takeoff_var = BooleanVar()
|
||||
self.takeoff_var.set(self.game.settings.only_player_takeoff)
|
||||
|
||||
@@ -29,6 +33,7 @@ class ConfigurationMenu(Menu):
|
||||
def dismiss(self):
|
||||
self.game.settings.player_skill = self.player_skill_var.get()
|
||||
self.game.settings.enemy_skill = self.enemy_skill_var.get()
|
||||
self.game.settings.enemy_vehicle_skill = self.enemy_vehicle_var.get()
|
||||
self.game.settings.only_player_takeoff = self.takeoff_var.get()
|
||||
self.game.settings.night_disabled = self.night_var.get()
|
||||
self.game.settings.cold_start = self.cold_start_var.get()
|
||||
@@ -39,43 +44,64 @@ class ConfigurationMenu(Menu):
|
||||
|
||||
# Header
|
||||
head = Frame(self.frame, **STYLES["header"])
|
||||
head.grid(row=0, column=0, columnspan=2, sticky=NSEW)
|
||||
Label(head, text="Configuration", **STYLES["title"]).grid()
|
||||
head.grid(row=0, column=0, sticky=NSEW)
|
||||
head.grid_columnconfigure(0, weight=100)
|
||||
Label(head, text="Configuration", **STYLES["title"]).grid(row=0, sticky=W)
|
||||
Button(head, text="Back", command=self.dismiss, **STYLES["btn-primary"]).grid(row=0, column=1, sticky=E)
|
||||
|
||||
# Body
|
||||
body = Frame(self.frame, **STYLES["body"])
|
||||
body.grid(row=1, column=0, sticky=NSEW)
|
||||
row = 0
|
||||
|
||||
Label(body, text="Player coalition skill", **STYLES["widget"]).grid(row=0, column=0, sticky=W)
|
||||
Label(body, text="Enemy coalition skill", **STYLES["widget"]).grid(row=1, column=0, sticky=W)
|
||||
|
||||
Label(body, text="Player coalition skill", **STYLES["widget"]).grid(row=row, column=0, sticky=W)
|
||||
p_skill = OptionMenu(body, self.player_skill_var, "Average", "Good", "High", "Excellent")
|
||||
p_skill.grid(row=0, column=1, sticky=E, pady=5)
|
||||
p_skill.grid(row=row, column=1, sticky=E, pady=5)
|
||||
p_skill.configure(**STYLES["btn-primary"])
|
||||
row += 1
|
||||
|
||||
Label(body, text="Enemy coalition skill", **STYLES["widget"]).grid(row=row, column=0, sticky=W)
|
||||
e_skill = OptionMenu(body, self.enemy_skill_var, "Average", "Good", "High", "Excellent")
|
||||
e_skill.grid(row=1, column=1, sticky=E)
|
||||
e_skill.grid(row=row, column=1, sticky=E)
|
||||
e_skill.configure(**STYLES["btn-primary"])
|
||||
row += 1
|
||||
|
||||
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)
|
||||
Label(body, text="Enemy AA and vehicle skill", **STYLES["widget"]).grid(row=row, column=0, sticky=W)
|
||||
e_skill = OptionMenu(body, self.enemy_vehicle_var, "Average", "Good", "High", "Excellent")
|
||||
e_skill.grid(row=row, column=1, sticky=E)
|
||||
e_skill.configure(**STYLES["btn-primary"])
|
||||
row += 1
|
||||
|
||||
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)
|
||||
Label(body, text="Aircraft cold start", **STYLES["widget"]).grid(row=row, column=0, sticky=W)
|
||||
Checkbutton(body, variable=self.cold_start_var, **STYLES["radiobutton"]).grid(row=row, column=1, sticky=E)
|
||||
row += 1
|
||||
|
||||
Button(body, text="Back", command=self.dismiss, **STYLES["btn-primary"]).grid(row=5, column=1, sticky=E, pady=30)
|
||||
Label(body, text="Takeoff only for player group", **STYLES["widget"]).grid(row=row, column=0, sticky=W)
|
||||
Checkbutton(body, variable=self.takeoff_var, **STYLES["radiobutton"]).grid(row=row, column=1, sticky=E)
|
||||
row += 1
|
||||
|
||||
Label(body, text="Contributors: ", **STYLES["widget"]).grid(row=6, column=0, sticky=W)
|
||||
Label(body, text="Disable night missions", **STYLES["widget"]).grid(row=row, column=0, sticky=W)
|
||||
Checkbutton(body, variable=self.night_var, **STYLES["radiobutton"]).grid(row=row, column=1, sticky=E)
|
||||
row += 1
|
||||
|
||||
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)
|
||||
Button(body, text="Display logs", command=self.display_logs, **STYLES["btn-primary"]).grid(row=row, column=1, sticky=E, pady=30)
|
||||
row += 1
|
||||
|
||||
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)
|
||||
Label(body, text="Contributors: ", **STYLES["strong"]).grid(row=row, column=0, columnspan=2, sticky=EW)
|
||||
row += 1
|
||||
|
||||
Button(body, text="Cheat +200m", command=self.cheat_money, **STYLES["btn-danger"]).grid(row=10, column=1, pady=30)
|
||||
Label(body, text="shdwp - author, maintainer", **STYLES["widget"]).grid(row=row, column=0, sticky=W)
|
||||
Button(body, text="[github]", command=lambda: webbrowser.open_new_tab("http://github.com/shdwp"), **STYLES["widget"]).grid(row=row, column=1, sticky=E)
|
||||
row += 1
|
||||
|
||||
Label(body, text="Khopa - contributions", **STYLES["widget"]).grid(row=row, column=0, sticky=W)
|
||||
Button(body, text="[github]", command=lambda: webbrowser.open_new_tab("http://github.com/Khopa"), **STYLES["widget"]).grid(row=row, column=1, sticky=E)
|
||||
row += 1
|
||||
|
||||
Button(body, text="Cheat +200m", command=self.cheat_money, **STYLES["btn-danger"]).grid(row=row, column=1, pady=30)
|
||||
|
||||
def display_logs(self):
|
||||
raise ShowLogsException()
|
||||
|
||||
def cheat_money(self):
|
||||
self.game.budget += 200
|
||||
|
||||
@@ -9,7 +9,7 @@ from .styles import STYLES, RED
|
||||
|
||||
class EventMenu(Menu):
|
||||
scramble_entries = None # type: typing.Dict[typing.Type[Task], typing.Dict[typing.Type[UnitType], typing.Tuple[Entry, Entry]]]
|
||||
|
||||
ca_slot_entry = None # type: Entry
|
||||
error_label = None # type: Label
|
||||
awacs = None # type: IntVar
|
||||
|
||||
@@ -69,15 +69,11 @@ class EventMenu(Menu):
|
||||
|
||||
row += 1
|
||||
|
||||
threat_descr = self.event.threat_description
|
||||
if threat_descr:
|
||||
threat_descr = "Approx. {}".format(threat_descr)
|
||||
|
||||
# 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)
|
||||
Label(self.frame, text="{}".format(self.event), **STYLES["mission-preview"]).grid(row=row, column=0, columnspan=5, sticky=S+EW, padx=5, pady=5)
|
||||
row += 1
|
||||
|
||||
Label(self.frame, text="Amount", **STYLES["widget"]).grid(row=row, column=1, columnspan=2)
|
||||
@@ -100,8 +96,15 @@ class EventMenu(Menu):
|
||||
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)
|
||||
Label(self.frame, text="AWACS ({}m)".format(AWACS_BUDGET_COST), **STYLES["widget"]).grid(row=row, column=0, sticky=W, pady=5)
|
||||
Checkbutton(self.frame, var=self.awacs, state=awacs_enabled, **STYLES["radiobutton"]).grid(row=row, column=4, sticky=E)
|
||||
row += 1
|
||||
|
||||
Label(self.frame, text="Combined Arms Slots", **STYLES["widget"]).grid(row=row, sticky=W)
|
||||
self.ca_slot_entry = Entry(self.frame, width=2)
|
||||
self.ca_slot_entry.insert(0, "0")
|
||||
self.ca_slot_entry.grid(column=3, row=row, sticky=E, padx=5)
|
||||
Button(self.frame, text="+", command=self.add_ca_slot, **STYLES["btn-primary"]).grid(column=4, row=row, padx=5, sticky=W)
|
||||
row += 1
|
||||
|
||||
header("Ready?")
|
||||
@@ -124,6 +127,12 @@ class EventMenu(Menu):
|
||||
|
||||
return action
|
||||
|
||||
def add_ca_slot(self):
|
||||
value = self.ca_slot_entry.get()
|
||||
amount = int(value and value or "0")
|
||||
self.ca_slot_entry.delete(0, END)
|
||||
self.ca_slot_entry.insert(0, str(amount+1))
|
||||
|
||||
def client_one(self, task: typing.Type[Task], unit_type: UnitType) -> typing.Callable:
|
||||
def action():
|
||||
entry = self.scramble_entries[task][unit_type][1] # type: Entry
|
||||
@@ -140,6 +149,13 @@ class EventMenu(Menu):
|
||||
else:
|
||||
self.event.is_awacs_enabled = False
|
||||
|
||||
ca_slot_entry_value = self.ca_slot_entry.get()
|
||||
try:
|
||||
ca_slots = int(ca_slot_entry_value and ca_slot_entry_value or "0")
|
||||
except:
|
||||
ca_slots = 0
|
||||
self.event.ca_slots = ca_slots
|
||||
|
||||
flights = {k: {} for k in self.event.tasks} # type: db.TaskForceDict
|
||||
units_scramble_counts = {} # type: typing.Dict[typing.Type[UnitType], int]
|
||||
tasks_scramble_counts = {} # type: typing.Dict[typing.Type[Task], int]
|
||||
|
||||
@@ -118,7 +118,7 @@ class EventResultsMenu(Menu):
|
||||
|
||||
def simulate_result(self, player_factor: float, enemy_factor: float):
|
||||
def action():
|
||||
debriefing = Debriefing({}, [])
|
||||
debriefing = Debriefing({})
|
||||
|
||||
def count(country: Country) -> typing.Dict[UnitType, int]:
|
||||
result = {}
|
||||
|
||||
@@ -20,69 +20,87 @@ class MainMenu(Menu):
|
||||
self.upd.update()
|
||||
|
||||
self.frame = self.window.right_pane
|
||||
self.frame.columnconfigure(0, weight=1)
|
||||
self.frame.rowconfigure(0, weight=1)
|
||||
self.frame.rowconfigure(0, weight=0)
|
||||
self.frame.rowconfigure(1, weight=1)
|
||||
|
||||
def display(self):
|
||||
persistency.save_game(self.game)
|
||||
|
||||
self.window.clear_right_pane()
|
||||
self.upd.update()
|
||||
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)
|
||||
Button(header, text="Configuration", command=self.configuration_menu, **STYLES["btn-primary"]).grid(column=0, row=0, sticky=NW)
|
||||
Label(header, text="Budget: {}m (+{}m)".format(self.game.budget, self.game.budget_reward_amount), **STYLES["strong"]).grid(column=1, row=0, sticky=N+EW, padx=50)
|
||||
Button(header, text="Pass turn", command=self.pass_turn, **STYLES["btn-primary"]).grid(column=2, row=0, sticky=NE)
|
||||
header.grid(column=0, row=0, sticky=N+EW)
|
||||
|
||||
body = LabelFrame(self.frame, **STYLES["body"])
|
||||
body.grid(column=0, row=1, sticky=NSEW)
|
||||
content = Frame(self.frame, **STYLES["body"])
|
||||
content.grid(column=0, row=1, sticky=NSEW)
|
||||
column = 0
|
||||
row = 0
|
||||
|
||||
def label(text):
|
||||
nonlocal row, body
|
||||
frame = LabelFrame(body, **STYLES["label-frame"])
|
||||
frame.grid(row=row, sticky=NSEW, columnspan=2)
|
||||
frame.grid(row=row, sticky=N+EW, columnspan=2)
|
||||
Label(frame, text=text, **STYLES["widget"]).grid(row=row, sticky=NS)
|
||||
row += 1
|
||||
|
||||
def event_button(event):
|
||||
nonlocal row, body
|
||||
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 "",
|
||||
frame.grid(row=row, sticky=N+EW)
|
||||
Message(frame, text="{}".format(
|
||||
event
|
||||
), aspect=1600, **STYLES["widget"]).grid(column=0, row=0, sticky=NSEW)
|
||||
), aspect=1600, **STYLES["widget"]).grid(column=0, row=0, sticky=N+EW)
|
||||
Button(body, text=">", command=self.start_event(event), **STYLES["btn-primary"]).grid(column=1, row=row, sticky=E)
|
||||
row += 1
|
||||
|
||||
def destination_header(text, pady=0):
|
||||
def departure_header(text, style="strong"):
|
||||
nonlocal row, body
|
||||
Label(body, text=text, **STYLES["strong"]).grid(column=0, columnspan=2, row=row, sticky=N+EW, pady=(pady,0)); row += 1
|
||||
Label(body, text=text, **STYLES[style]).grid(column=0, columnspan=2, row=row, sticky=N+EW, pady=(0, 5))
|
||||
row += 1
|
||||
|
||||
def destination_header(text):
|
||||
nonlocal row, body
|
||||
Label(body, text=text, **STYLES["substrong"]).grid(column=0, columnspan=2, row=row, sticky=N+EW)
|
||||
row += 1
|
||||
|
||||
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.informational and 2 or (self.game.is_player_attack(x) and 1 or 0))
|
||||
events.sort(key=lambda x: x.informational and 1 or (self.game.is_player_attack(x) and 2 or 0))
|
||||
|
||||
destination = None
|
||||
deliveries = False
|
||||
departure = None
|
||||
|
||||
for event in events:
|
||||
if event.informational:
|
||||
new_departure = "Deliveries"
|
||||
elif not self.game.is_player_attack(event):
|
||||
new_departure = "Enemy attack"
|
||||
else:
|
||||
new_departure = event.from_cp.name
|
||||
|
||||
if new_departure != departure:
|
||||
body = Frame(content, **STYLES["body"])
|
||||
body.grid(column=column, row=1, sticky=N+EW)
|
||||
row = 0
|
||||
column += 1
|
||||
|
||||
departure = new_departure
|
||||
departure_header(new_departure, style="strong" if self.game.is_player_attack(event) else "supstrong")
|
||||
destination = None
|
||||
|
||||
if not event.informational:
|
||||
if self.game.is_player_attack(event):
|
||||
new_destination = "From {} to {}".format(event.from_cp.name, event.to_cp.name)
|
||||
else:
|
||||
new_destination = "Enemy attack"
|
||||
new_destination = "At {}".format(event.to_cp.name)
|
||||
if destination != new_destination:
|
||||
destination_header(new_destination)
|
||||
destination = new_destination
|
||||
|
||||
if event.informational:
|
||||
if not deliveries:
|
||||
deliveries = True
|
||||
destination_header("Deliveries", 15)
|
||||
label(str(event))
|
||||
else:
|
||||
event_button(event)
|
||||
|
||||
@@ -67,6 +67,14 @@ class OverviewCanvas:
|
||||
self.canvas.create_image((self.image.width()/2, self.image.height()/2), image=self.image)
|
||||
|
||||
for cp in self.game.theater.controlpoints:
|
||||
for ground_object in cp.ground_objects:
|
||||
x, y = self.transform_point(ground_object.position)
|
||||
self.canvas.create_text(x,
|
||||
y,
|
||||
text=".",
|
||||
fill="black" if ground_object.is_dead else self._enemy_color(),
|
||||
font=("Helvetica", 18))
|
||||
|
||||
coords = self.transform_point(cp.position)
|
||||
for connected_cp in cp.connected_points:
|
||||
connected_coords = self.transform_point(connected_cp.position)
|
||||
@@ -80,8 +88,15 @@ class OverviewCanvas:
|
||||
self.canvas.create_line((coords[0], coords[1], connected_coords[0], connected_coords[1]), width=2, fill=color)
|
||||
|
||||
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)
|
||||
distance = max(distance, 1000)
|
||||
frontline = Conflict.frontline_vector(cp, connected_cp, self.game.theater)
|
||||
if not frontline:
|
||||
continue
|
||||
|
||||
frontline_pos, heading, distance = frontline
|
||||
if distance < 10000:
|
||||
frontline_pos = frontline_pos.point_from_heading(heading + 180, 5000)
|
||||
distance = 10000
|
||||
|
||||
start_coords = self.transform_point(frontline_pos, treshold=10)
|
||||
end_coords = self.transform_point(frontline_pos.point_from_heading(heading, distance), treshold=60)
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ GREEN = "#699245"
|
||||
YELLOW = "#BF9A46"
|
||||
RED = "#D0232E"
|
||||
BG_TITLE_COLOR = "#2D3E50"
|
||||
BG_SUBTITLE_COLOR = "#3E4F61"
|
||||
|
||||
# Fonts
|
||||
FONT_FAMILY = "Trebuchet MS"
|
||||
@@ -25,8 +26,10 @@ 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["body"] = {"bg": BG_COLOR, "padx": 10, "pady": 10}
|
||||
STYLES["strong"] = {"font": BOLD_FONT, "bg": BG_TITLE_COLOR, "fg": FG_COLOR}
|
||||
STYLES["substrong"] = {"font": BOLD_FONT, "bg": BG_SUBTITLE_COLOR, "fg": FG_COLOR}
|
||||
STYLES["supstrong"] = {"font": BOLD_FONT, "bg": RED, "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}
|
||||
@@ -39,6 +42,7 @@ STYLES["title"] = {"bg": BG_TITLE_COLOR, "fg": FG_COLOR, "padx": PADDING_X, "pad
|
||||
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["subheader"] = {"bg": BG_SUBTITLE_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}
|
||||
|
||||
@@ -11,7 +11,7 @@ class Window:
|
||||
self.tk = Tk()
|
||||
self.tk.title("DCS Liberation")
|
||||
self.tk.iconbitmap("icon.ico")
|
||||
self.tk.resizable(True, True)
|
||||
self.tk.resizable(False, False)
|
||||
self.tk.grid_columnconfigure(0, weight=1)
|
||||
self.tk.grid_rowconfigure(0, weight=1)
|
||||
|
||||
@@ -32,6 +32,10 @@ class Window:
|
||||
self.tk.focus()
|
||||
|
||||
def clear_right_pane(self):
|
||||
for i in range(100):
|
||||
self.right_pane.grid_columnconfigure(1, weight=0)
|
||||
self.right_pane.grid_rowconfigure(1, weight=0)
|
||||
|
||||
for x in self.right_pane.winfo_children():
|
||||
x.grid_remove()
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ from dcs.unit import UnitType
|
||||
from game import db
|
||||
|
||||
from .persistency import base_path
|
||||
from theater.theatergroundobject import CATEGORY_MAP
|
||||
|
||||
DEBRIEFING_LOG_EXTENSION = "log"
|
||||
|
||||
@@ -59,52 +60,25 @@ def parse_mutliplayer_debriefing(contents: str):
|
||||
|
||||
|
||||
class Debriefing:
|
||||
def __init__(self, dead_units, dead_objects):
|
||||
def __init__(self, dead_units):
|
||||
self.destroyed_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_objects = dead_objects
|
||||
|
||||
@classmethod
|
||||
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
|
||||
dead_units = []
|
||||
|
||||
def append_dead_object(object_mission_id_str):
|
||||
nonlocal dead_objects
|
||||
nonlocal dead_units
|
||||
object_mission_id = int(object_mission_id_str)
|
||||
if object_mission_id in dead_objects:
|
||||
if object_mission_id in dead_units:
|
||||
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)
|
||||
dead_units.append(object_mission_id)
|
||||
|
||||
def parse_dead_object(event):
|
||||
try:
|
||||
@@ -123,22 +97,24 @@ class Debriefing:
|
||||
for event in events.values():
|
||||
event_type = event.get("type", None)
|
||||
if event_type in ["crash", "dead"]:
|
||||
object_initiator = event["initiator"] in ["SKLAD_CRUSH", "SKLADCDESTR", "TEC_A_CRUSH", "BAK_CRUSH"]
|
||||
defense_initiator = event["initiator"].startswith("defense|")
|
||||
parse_dead_object(event)
|
||||
|
||||
if object_initiator or defense_initiator:
|
||||
"""
|
||||
initiator_components = event["initiator"].split("|")
|
||||
|
||||
if initiator_components[0] in CATEGORY_MAP:
|
||||
parse_dead_object(event)
|
||||
else:
|
||||
parse_dead_unit(event)
|
||||
"""
|
||||
|
||||
return Debriefing(dead_units, dead_objects)
|
||||
return Debriefing(dead_units)
|
||||
|
||||
def calculate_units(self, mission: Mission, player_name: str, enemy_name: str):
|
||||
def count_groups(groups: typing.List[UnitType]) -> typing.Dict[UnitType, int]:
|
||||
result = {}
|
||||
for group in groups:
|
||||
for unit in group.units:
|
||||
unit_type = None
|
||||
if isinstance(unit, Vehicle):
|
||||
unit_type = vehicle_map[unit.type]
|
||||
elif isinstance(unit, Ship):
|
||||
@@ -160,21 +136,40 @@ class Debriefing:
|
||||
enemy_units = count_groups(enemy.plane_group + enemy.vehicle_group + enemy.ship_group)
|
||||
|
||||
self.destroyed_units = {
|
||||
player.name: self._dead_units.get(player.id, {}),
|
||||
enemy.name: self._dead_units.get(enemy.id, {}),
|
||||
player.name: {},
|
||||
enemy.name: {},
|
||||
}
|
||||
|
||||
all_groups = {
|
||||
player.name: player.plane_group + player.helicopter_group + player.vehicle_group + player.ship_group,
|
||||
enemy.name: enemy.plane_group + enemy.helicopter_group + enemy.vehicle_group + enemy.ship_group,
|
||||
}
|
||||
|
||||
static_groups = enemy.static_group
|
||||
|
||||
for country_name, country_groups in all_groups.items():
|
||||
for group in country_groups:
|
||||
for unit in group.units:
|
||||
if unit.id in self._dead_units:
|
||||
logging.info("debriefing: found dead unit {} ({})".format(str(unit.name), unit.id))
|
||||
unit_klass = db.unit_type_from_name(unit.type)
|
||||
self.destroyed_units[country_name][unit_klass] = self.destroyed_units[country_name].get(unit_klass, 0) + 1
|
||||
self._dead_units.remove(unit.id)
|
||||
|
||||
for group in static_groups:
|
||||
identifier = group.units[0].id
|
||||
if identifier in self._dead_units:
|
||||
logging.info("debriefing: found dead static {} ({})".format(str(group.name), identifier))
|
||||
self.destroyed_objects.append(str(group.name))
|
||||
self._dead_units.remove(identifier)
|
||||
|
||||
logging.info("debriefing: unsatistied ids: {}".format(self._dead_units))
|
||||
|
||||
self.alive_units = {
|
||||
player.name: {k: v - self.destroyed_units[player.name].get(k, 0) for k, v in player_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:
|
||||
return os.path.join(base_path(), "liberation_debriefings")
|
||||
|
||||
@@ -9,9 +9,14 @@ from tkinter.scrolledtext import *
|
||||
_version_string = None
|
||||
|
||||
|
||||
def _error_prompt():
|
||||
class ShowLogsException(Exception):
|
||||
pass
|
||||
|
||||
|
||||
def _error_prompt(oops=True):
|
||||
tk = Tk()
|
||||
Label(tk, text="Oops, something went wrong.").grid(row=0)
|
||||
if oops:
|
||||
Label(tk, text="Oops, something went wrong.").grid(row=0)
|
||||
Label(tk, text="Please send following text to the developer:").grid(row=1)
|
||||
|
||||
text = ScrolledText(tk)
|
||||
@@ -22,7 +27,7 @@ def _error_prompt():
|
||||
|
||||
def _handle_exception(self, exception: BaseException, *args):
|
||||
logging.exception(exception)
|
||||
_error_prompt()
|
||||
_error_prompt(isinstance(exception, ShowLogsException))
|
||||
|
||||
|
||||
def setup_version_string(str):
|
||||
|
||||
@@ -17,11 +17,11 @@ def base_path() -> str:
|
||||
global _user_folder
|
||||
assert _user_folder
|
||||
|
||||
openbeta_path = os.path.join(_user_folder, "Saved Games", "DCS.openbeta")
|
||||
openbeta_path = os.path.join(_user_folder, "DCS.openbeta")
|
||||
if "--force-stable-DCS" not in sys.argv and os.path.exists(openbeta_path):
|
||||
return openbeta_path
|
||||
else:
|
||||
return os.path.join(_user_folder, "Saved Games", "DCS")
|
||||
return os.path.join(_user_folder, "DCS")
|
||||
|
||||
|
||||
def _save_file() -> str:
|
||||
|
||||
Reference in New Issue
Block a user