added missing assets; convoy strike event
@ -5,5 +5,6 @@ from .intercept import *
|
||||
from .baseattack import *
|
||||
from .navalintercept import *
|
||||
from .insurgentattack import *
|
||||
from .convoystrike import *
|
||||
from .infantrytransport import *
|
||||
from .strike import *
|
||||
|
||||
79
game/event/convoystrike.py
Normal file
@ -0,0 +1,79 @@
|
||||
import math
|
||||
import random
|
||||
|
||||
from dcs.task import *
|
||||
|
||||
from game import *
|
||||
from game.event import *
|
||||
from game.event.frontlineattack import FrontlineAttackEvent
|
||||
|
||||
from .event import *
|
||||
from game.operation.convoystrike import ConvoyStrikeOperation
|
||||
|
||||
TRANSPORT_COUNT = 4, 6
|
||||
DEFENDERS_AMOUNT_FACTOR = 4
|
||||
|
||||
|
||||
class ConvoyStrikeEvent(Event):
|
||||
SUCCESS_FACTOR = 0.7
|
||||
STRENGTH_INFLUENCE = 0.25
|
||||
|
||||
targets = None # type: db.ArmorDict
|
||||
|
||||
@property
|
||||
def threat_description(self):
|
||||
return ""
|
||||
|
||||
@property
|
||||
def tasks(self):
|
||||
return [CAS]
|
||||
|
||||
def flight_name(self, for_task: typing.Type[Task]) -> str:
|
||||
if for_task == CAS:
|
||||
return "Strike flight"
|
||||
|
||||
def __str__(self):
|
||||
return "Convoy Strike"
|
||||
|
||||
def skip(self):
|
||||
self.to_cp.base.affect_strength(-self.STRENGTH_INFLUENCE)
|
||||
|
||||
def commit(self, debriefing: Debriefing):
|
||||
super(ConvoyStrikeEvent, self).commit(debriefing)
|
||||
|
||||
if self.from_cp.captured:
|
||||
if self.is_successfull(debriefing):
|
||||
self.to_cp.base.affect_strength(-self.STRENGTH_INFLUENCE)
|
||||
else:
|
||||
if self.is_successfull(debriefing):
|
||||
self.from_cp.base.affect_strength(-self.STRENGTH_INFLUENCE)
|
||||
|
||||
def is_successfull(self, debriefing: Debriefing):
|
||||
killed_units = sum([v for k, v in debriefing.destroyed_units[self.defender_name].items() if db.unit_task(k) in [PinpointStrike, Reconnaissance]])
|
||||
all_units = sum(self.targets.values())
|
||||
attackers_success = (float(killed_units) / (all_units + 0.01)) > self.SUCCESS_FACTOR
|
||||
if self.from_cp.captured:
|
||||
return attackers_success
|
||||
else:
|
||||
return not attackers_success
|
||||
|
||||
def player_attacking(self, flights: db.TaskForceDict):
|
||||
assert CAS in flights and len(flights) == 1, "Invalid flights"
|
||||
|
||||
convoy_unittype = db.find_unittype(Reconnaissance, self.defender_name)[0]
|
||||
defense_unittype = db.find_unittype(PinpointStrike, self.defender_name)[0]
|
||||
|
||||
defenders_count = int(math.ceil(self.from_cp.base.strength * self.from_cp.importance * DEFENDERS_AMOUNT_FACTOR))
|
||||
self.targets = {convoy_unittype: random.randrange(*TRANSPORT_COUNT),
|
||||
defense_unittype: defenders_count, }
|
||||
|
||||
op = ConvoyStrikeOperation(game=self.game,
|
||||
attacker_name=self.attacker_name,
|
||||
defender_name=self.defender_name,
|
||||
from_cp=self.from_cp,
|
||||
departure_cp=self.departure_cp,
|
||||
to_cp=self.to_cp)
|
||||
op.setup(target=self.targets,
|
||||
strikegroup=flights[CAS])
|
||||
|
||||
self.operation = op
|
||||
@ -39,7 +39,7 @@ class InsurgentAttackEvent(Event):
|
||||
killed_units = sum([v for k, v in debriefing.destroyed_units[self.attacker_name].items() if db.unit_task(k) == PinpointStrike])
|
||||
all_units = sum(self.targets.values())
|
||||
attackers_success = (float(killed_units) / (all_units + 0.01)) > self.SUCCESS_FACTOR
|
||||
if self.departure_cp.captured:
|
||||
if self.from_cp.captured:
|
||||
return attackers_success
|
||||
else:
|
||||
return not attackers_success
|
||||
|
||||
@ -56,6 +56,7 @@ EVENT_PROBABILITIES = {
|
||||
|
||||
# events randomly present; only for the player
|
||||
InfantryTransportEvent: [25, 0],
|
||||
ConvoyStrikeEvent: [25, 0],
|
||||
|
||||
# events conditionally present; for both enemy and player
|
||||
BaseAttackEvent: [100, 9],
|
||||
@ -164,7 +165,7 @@ class Game:
|
||||
def _generate_events(self):
|
||||
for player_cp, enemy_cp in self.theater.conflicts(True):
|
||||
for event_class, (player_probability, enemy_probability) in EVENT_PROBABILITIES.items():
|
||||
if event_class in [FrontlineAttackEvent, FrontlinePatrolEvent, InfantryTransportEvent]:
|
||||
if event_class in [FrontlineAttackEvent, FrontlinePatrolEvent, InfantryTransportEvent, ConvoyStrikeEvent]:
|
||||
# skip events requiring frontline
|
||||
if not Conflict.has_frontline_between(player_cp, enemy_cp):
|
||||
continue
|
||||
|
||||
46
game/operation/convoystrike.py
Normal file
@ -0,0 +1,46 @@
|
||||
from game.db import assigned_units_split
|
||||
|
||||
from .operation import *
|
||||
|
||||
|
||||
class ConvoyStrikeOperation(Operation):
|
||||
strikegroup = None # type: db.AssignedUnitsDict
|
||||
target = None # type: db.ArmorDict
|
||||
|
||||
def setup(self,
|
||||
target: db.ArmorDict,
|
||||
strikegroup: db.AssignedUnitsDict):
|
||||
self.strikegroup = strikegroup
|
||||
self.target = target
|
||||
|
||||
def prepare(self, terrain: Terrain, is_quick: bool):
|
||||
super(ConvoyStrikeOperation, self).prepare(terrain, is_quick)
|
||||
|
||||
conflict = Conflict.convoy_strike_conflict(
|
||||
attacker=self.current_mission.country(self.attacker_name),
|
||||
defender=self.current_mission.country(self.defender_name),
|
||||
from_cp=self.from_cp,
|
||||
to_cp=self.to_cp,
|
||||
theater=self.game.theater
|
||||
)
|
||||
|
||||
self.initialize(mission=self.current_mission,
|
||||
conflict=conflict)
|
||||
|
||||
def generate(self):
|
||||
planes_flights = {k: v for k, v in self.strikegroup.items() if k in plane_map.values()}
|
||||
self.airgen.generate_cas_strikegroup(*assigned_units_split(planes_flights), at=self.attackers_starting_position)
|
||||
|
||||
heli_flights = {k: v for k, v in self.strikegroup.items() if k in helicopters.helicopter_map.values()}
|
||||
if heli_flights:
|
||||
self.briefinggen.append_frequency("FARP + Heli flights", "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=len(planes_flights) == 0)
|
||||
|
||||
self.armorgen.generate_convoy(self.target)
|
||||
|
||||
self.briefinggen.append_waypoint("TARGET")
|
||||
super(ConvoyStrikeOperation, self).generate()
|
||||
16
gen/armor.py
@ -36,7 +36,7 @@ class ArmorConflictGenerator:
|
||||
|
||||
return point.random_point_within(distance, self.conflict.size * SPREAD_DISTANCE_SIZE_FACTOR)
|
||||
|
||||
def _generate_group(self, side: Country, unit: VehicleType, count: int, at: Point, to: Point = None):
|
||||
def _generate_group(self, side: Country, unit: VehicleType, count: int, at: Point, to: Point = None, move_formation: PointAction = PointAction.OffRoad):
|
||||
for c in range(count):
|
||||
logging.info("armorgen: {} for {}".format(unit, side.id))
|
||||
group = self.m.vehicle_group(
|
||||
@ -45,7 +45,7 @@ class ArmorConflictGenerator:
|
||||
unit,
|
||||
position=self._group_point(at),
|
||||
group_size=1,
|
||||
move_formation=PointAction.OffRoad)
|
||||
move_formation=move_formation)
|
||||
|
||||
vehicle: Vehicle = group.units[0]
|
||||
vehicle.player_can_drive = True
|
||||
@ -53,7 +53,7 @@ class ArmorConflictGenerator:
|
||||
if not to:
|
||||
to = self.conflict.position.point_from_heading(0, 500)
|
||||
|
||||
wayp = group.add_waypoint(self._group_point(to))
|
||||
wayp = group.add_waypoint(self._group_point(to), move_formation=move_formation)
|
||||
wayp.tasks = []
|
||||
|
||||
def _generate_fight_at(self, attackers: db.ArmorDict, defenders: db.ArmorDict, position: Point):
|
||||
@ -109,6 +109,16 @@ class ArmorConflictGenerator:
|
||||
random.randint(0, self.conflict.distance))
|
||||
self._generate_fight_at(attacker_group_dict, target_group_dict, position)
|
||||
|
||||
def generate_convoy(self, units: db.ArmorDict):
|
||||
for type, count in units.items():
|
||||
self._generate_group(
|
||||
side=self.conflict.defenders_side,
|
||||
unit=type,
|
||||
count=count,
|
||||
at=self.conflict.ground_defenders_location,
|
||||
to=self.conflict.position,
|
||||
move_formation=PointAction.OnRoad)
|
||||
|
||||
def generate_passengers(self, count: int):
|
||||
unit_type = random.choice(db.find_unittype(Nothing, self.conflict.attackers_side.name))
|
||||
|
||||
|
||||
@ -321,6 +321,31 @@ class Conflict:
|
||||
air_defenders_location=position.point_from_heading(heading, AIR_DISTANCE),
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def convoy_strike_conflict(cls, attacker: Country, defender: Country, from_cp: ControlPoint, to_cp: ControlPoint, theater: ConflictTheater):
|
||||
frontline_position, frontline_heading, frontline_length = Conflict.frontline_vector(from_cp, to_cp, theater)
|
||||
if not frontline_position:
|
||||
assert False
|
||||
|
||||
heading = _heading_sum(frontline_heading, +45)
|
||||
starting_position = Conflict._find_ground_position(frontline_position.point_from_heading(heading, 15000),
|
||||
GROUND_INTERCEPT_SPREAD,
|
||||
_opposite_heading(heading), theater)
|
||||
destination_position = frontline_position
|
||||
|
||||
return cls(
|
||||
position=destination_position,
|
||||
theater=theater,
|
||||
from_cp=from_cp,
|
||||
to_cp=to_cp,
|
||||
attackers_side=attacker,
|
||||
defenders_side=defender,
|
||||
ground_attackers_location=None,
|
||||
ground_defenders_location=starting_position,
|
||||
air_attackers_location=starting_position.point_from_heading(_opposite_heading(heading), AIR_DISTANCE),
|
||||
air_defenders_location=starting_position.point_from_heading(heading, AIR_DISTANCE),
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def frontline_cas_conflict(cls, attacker: Country, defender: Country, from_cp: ControlPoint, to_cp: ControlPoint, theater: ConflictTheater):
|
||||
assert cls.has_frontline_between(from_cp, to_cp)
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import os
|
||||
import sys
|
||||
import dcs
|
||||
|
||||
from game import db
|
||||
|
||||
BIN
resources/ui/events/air_intercept.png
Normal file
|
After Width: | Height: | Size: 3.2 KiB |
BIN
resources/ui/events/attack.PNG
Normal file
|
After Width: | Height: | Size: 637 B |
BIN
resources/ui/events/capture.PNG
Normal file
|
After Width: | Height: | Size: 697 B |
BIN
resources/ui/events/convoy.png
Normal file
|
After Width: | Height: | Size: 804 B |
BIN
resources/ui/events/delivery.PNG
Normal file
|
After Width: | Height: | Size: 1.2 KiB |
BIN
resources/ui/events/infantry.PNG
Normal file
|
After Width: | Height: | Size: 910 B |
BIN
resources/ui/events/insurgent_attack.PNG
Normal file
|
After Width: | Height: | Size: 824 B |
BIN
resources/ui/events/naval_intercept.PNG
Normal file
|
After Width: | Height: | Size: 688 B |
BIN
resources/ui/events/strike.PNG
Normal file
|
After Width: | Height: | Size: 1.1 KiB |
@ -162,6 +162,7 @@ class OverviewCanvas:
|
||||
FrontlineAttackEvent: "attack",
|
||||
InfantryTransportEvent: "infantry",
|
||||
InsurgentAttackEvent: "insurgent_attack",
|
||||
ConvoyStrikeEvent: "convoy",
|
||||
InterceptEvent: "air_intercept",
|
||||
NavalInterceptEvent: "naval_intercept",
|
||||
StrikeEvent: "strike",
|
||||
@ -486,7 +487,7 @@ class OverviewCanvas:
|
||||
label_to_draw = None
|
||||
for event in self.game.events:
|
||||
location = event.location
|
||||
if isinstance(event, FrontlinePatrolEvent) or isinstance(event, FrontlineAttackEvent):
|
||||
if type(event) in [FrontlineAttackEvent, FrontlinePatrolEvent, ConvoyStrikeEvent]:
|
||||
location = self._frontline_center(event.from_cp, event.to_cp)
|
||||
|
||||
rect = _location_to_rect(location)
|
||||
|
||||