mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
anti AA strike WIP
This commit is contained in:
parent
584045f60d
commit
e6ccc3ceea
87
game/event/antiaastrike.py
Normal file
87
game/event/antiaastrike.py
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
import math
|
||||||
|
import random
|
||||||
|
|
||||||
|
from dcs.task import *
|
||||||
|
|
||||||
|
from game import *
|
||||||
|
from game.event import *
|
||||||
|
from game.operation.antiaastrike import AntiAAStrikeOperation
|
||||||
|
from userdata.debriefing import Debriefing
|
||||||
|
|
||||||
|
|
||||||
|
class AntiAAStrikeEvent(Event):
|
||||||
|
BONUS_BASE = 3
|
||||||
|
TARGET_AMOUNT_MAX = 2
|
||||||
|
STRENGTH_INFLUENCE = 0.3
|
||||||
|
SUCCESS_TARGETS_HIT_PERCENTAGE = 0.5
|
||||||
|
|
||||||
|
targets = None # type: db.ArmorDict
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return "Anti-AA strike from {} at {}".format(self.from_cp, self.to_cp)
|
||||||
|
|
||||||
|
def is_successfull(self, debriefing: Debriefing):
|
||||||
|
total_targets = sum(self.targets.values())
|
||||||
|
destroyed_targets = 0
|
||||||
|
for unit, count in debriefing.destroyed_units[self.defender_name].items():
|
||||||
|
if unit in self.targets:
|
||||||
|
destroyed_targets += count
|
||||||
|
|
||||||
|
if self.from_cp.captured:
|
||||||
|
return math.ceil(float(destroyed_targets) / total_targets) >= self.SUCCESS_TARGETS_HIT_PERCENTAGE
|
||||||
|
else:
|
||||||
|
return math.ceil(float(destroyed_targets) / total_targets) < self.SUCCESS_TARGETS_HIT_PERCENTAGE
|
||||||
|
|
||||||
|
def commit(self, debriefing: Debriefing):
|
||||||
|
super(AntiAAStrikeEvent, self).commit(debriefing)
|
||||||
|
|
||||||
|
if self.from_cp.captured:
|
||||||
|
if self.is_successfull(debriefing):
|
||||||
|
self.to_cp.base.affect_strength(-self.STRENGTH_INFLUENCE)
|
||||||
|
else:
|
||||||
|
self.to_cp.base.affect_strength(+self.STRENGTH_INFLUENCE)
|
||||||
|
else:
|
||||||
|
if self.is_successfull(debriefing):
|
||||||
|
self.from_cp.base.affect_strength(-self.STRENGTH_INFLUENCE)
|
||||||
|
else:
|
||||||
|
self.to_cp.base.affect_strength(-self.STRENGTH_INFLUENCE)
|
||||||
|
|
||||||
|
def skip(self):
|
||||||
|
if self.to_cp.captured:
|
||||||
|
self.to_cp.base.affect_strength(-0.1)
|
||||||
|
|
||||||
|
def player_attacking(self, strikegroup: db.PlaneDict, clients: db.PlaneDict):
|
||||||
|
self.targets = self.to_cp.base.assemble_aa()
|
||||||
|
|
||||||
|
op = AntiAAStrikeOperation(game=self.game,
|
||||||
|
attacker_name=self.attacker_name,
|
||||||
|
defender_name=self.defender_name,
|
||||||
|
attacker_clients=clients,
|
||||||
|
defender_clients={},
|
||||||
|
from_cp=self.from_cp,
|
||||||
|
to_cp=self.to_cp)
|
||||||
|
op.setup(target=self.targets,
|
||||||
|
strikegroup=strikegroup,
|
||||||
|
interceptors={})
|
||||||
|
|
||||||
|
self.operation = op
|
||||||
|
|
||||||
|
def player_defending(self, interceptors: db.PlaneDict, clients: db.PlaneDict):
|
||||||
|
self.targets = self.to_cp.base.assemble_aa()
|
||||||
|
|
||||||
|
op = AntiAAStrikeOperation(
|
||||||
|
self.game,
|
||||||
|
attacker_name=self.attacker_name,
|
||||||
|
defender_name=self.defender_name,
|
||||||
|
attacker_clients={},
|
||||||
|
defender_clients=clients,
|
||||||
|
from_cp=self.from_cp,
|
||||||
|
to_cp=self.to_cp
|
||||||
|
)
|
||||||
|
|
||||||
|
strikegroup = self.from_cp.base.scramble_cas()
|
||||||
|
op.setup(target=self.targets,
|
||||||
|
strikegroup=strikegroup,
|
||||||
|
interceptors=interceptors)
|
||||||
|
|
||||||
|
self.operation = op
|
||||||
54
game/operation/antiaastrike.py
Normal file
54
game/operation/antiaastrike.py
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
from dcs.terrain import Terrain
|
||||||
|
|
||||||
|
from game import db
|
||||||
|
from gen.armor import *
|
||||||
|
from gen.aircraft import *
|
||||||
|
from gen.aaa import *
|
||||||
|
from gen.shipgen import *
|
||||||
|
from gen.settingsgen import *
|
||||||
|
from gen.awacsgen import *
|
||||||
|
from gen.visualgen import *
|
||||||
|
from gen.conflictgen import Conflict
|
||||||
|
|
||||||
|
from .operation import Operation
|
||||||
|
|
||||||
|
|
||||||
|
class AntiAAStrikeOperation(Operation):
|
||||||
|
strikegroup = None # type: db.PlaneDict
|
||||||
|
interceptors = None # type: db.PlaneDict
|
||||||
|
target = None # type: db.ArmorDict
|
||||||
|
|
||||||
|
def setup(self,
|
||||||
|
target: db.ArmorDict,
|
||||||
|
strikegroup: db.PlaneDict,
|
||||||
|
interceptors: db.PlaneDict):
|
||||||
|
self.strikegroup = strikegroup
|
||||||
|
self.interceptors = interceptors
|
||||||
|
self.target = target
|
||||||
|
|
||||||
|
def prepare(self, terrain: Terrain, is_quick: bool):
|
||||||
|
super(AntiAAStrikeOperation, self).prepare(terrain, is_quick)
|
||||||
|
if self.defender_name == self.game.player:
|
||||||
|
self.attackers_starting_position = None
|
||||||
|
self.defenders_starting_position = None
|
||||||
|
|
||||||
|
conflict = Conflict.ground_intercept_conflict(
|
||||||
|
attacker=self.mission.country(self.attacker_name),
|
||||||
|
defender=self.mission.country(self.defender_name),
|
||||||
|
heading=self.to_cp.position.heading_between_point(self.from_cp.position),
|
||||||
|
from_cp=self.from_cp,
|
||||||
|
to_cp=self.to_cp,
|
||||||
|
theater=self.game.theater
|
||||||
|
)
|
||||||
|
|
||||||
|
self.initialize(mission=self.mission,
|
||||||
|
conflict=conflict)
|
||||||
|
|
||||||
|
def generate(self):
|
||||||
|
self.airgen.generate_cas_strikegroup(self.strikegroup, clients=self.attacker_clients, at=self.attackers_starting_position)
|
||||||
|
|
||||||
|
if self.interceptors:
|
||||||
|
self.airgen.generate_defense(self.interceptors, clients=self.defender_clients, at=self.defenders_starting_position)
|
||||||
|
|
||||||
|
self.armorgen.generate({}, self.target)
|
||||||
|
super(AntiAAStrikeOperation, self).generate()
|
||||||
Loading…
x
Reference in New Issue
Block a user