mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Add FOB capture
This commit is contained in:
parent
b0b9c1c8e6
commit
aea82e2266
@ -2,17 +2,34 @@ from __future__ import annotations
|
|||||||
|
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
from dcs.action import MarkToAll
|
from dcs.action import (
|
||||||
from dcs.condition import TimeAfter
|
MarkToAll,
|
||||||
|
SetFlag,
|
||||||
|
DoScript,
|
||||||
|
ClearFlag
|
||||||
|
)
|
||||||
|
from dcs.condition import (
|
||||||
|
TimeAfter,
|
||||||
|
AllOfCoalitionOutsideZone,
|
||||||
|
PartOfCoalitionInZone,
|
||||||
|
FlagIsFalse,
|
||||||
|
FlagIsTrue
|
||||||
|
)
|
||||||
|
from dcs.unitgroup import FlyingGroup
|
||||||
from dcs.mission import Mission
|
from dcs.mission import Mission
|
||||||
from dcs.task import Option
|
from dcs.task import Option
|
||||||
from dcs.translation import String
|
from dcs.translation import String
|
||||||
from dcs.triggers import Event, TriggerOnce
|
from dcs.triggers import (
|
||||||
|
Event,
|
||||||
|
TriggerOnce,
|
||||||
|
TriggerZone,
|
||||||
|
TriggerCondition,
|
||||||
|
)
|
||||||
from dcs.unit import Skill
|
from dcs.unit import Skill
|
||||||
|
|
||||||
from game.theater import Airfield
|
from game.theater import Airfield
|
||||||
from dcs.unitgroup import FlyingGroup
|
from game.theater.controlpoint import Fob
|
||||||
from .conflictgen import Conflict
|
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from game.game import Game
|
from game.game import Game
|
||||||
@ -39,6 +56,9 @@ class Silence(Option):
|
|||||||
|
|
||||||
|
|
||||||
class TriggersGenerator:
|
class TriggersGenerator:
|
||||||
|
capture_zone_types = (Fob, )
|
||||||
|
capture_zone_flag = 600
|
||||||
|
|
||||||
def __init__(self, mission: Mission, game: Game):
|
def __init__(self, mission: Mission, game: Game):
|
||||||
self.mission = mission
|
self.mission = mission
|
||||||
self.game = game
|
self.game = game
|
||||||
@ -111,6 +131,54 @@ class TriggersGenerator:
|
|||||||
added.append(ground_object.obj_name)
|
added.append(ground_object.obj_name)
|
||||||
self.mission.triggerrules.triggers.append(mark_trigger)
|
self.mission.triggerrules.triggers.append(mark_trigger)
|
||||||
|
|
||||||
|
def _generate_capture_triggers(self, player_coalition: str, enemy_coalition: str) -> None:
|
||||||
|
"""Creates a pair of triggers for each control point of `cls.capture_zone_types`.
|
||||||
|
One for the initial capture of a control point, and one if it is recaptured.
|
||||||
|
Directly appends to the global `base_capture_events` var declared by `dcs_libaration.lua`
|
||||||
|
"""
|
||||||
|
for cp in self.game.theater.controlpoints:
|
||||||
|
if isinstance(cp, self.capture_zone_types):
|
||||||
|
if cp.captured:
|
||||||
|
attacking_coalition = enemy_coalition
|
||||||
|
attack_coalition_int = 1 # 1 is the Event int for Red
|
||||||
|
defending_coalition = player_coalition
|
||||||
|
defend_coalition_int = 2 # 2 is the Event int for Blue
|
||||||
|
else:
|
||||||
|
attacking_coalition = player_coalition
|
||||||
|
attack_coalition_int = 2
|
||||||
|
defending_coalition = enemy_coalition
|
||||||
|
defend_coalition_int = 1
|
||||||
|
|
||||||
|
trigger_zone = self.mission.triggers.add_triggerzone(cp.position, radius=3000, hidden=False, name="CAPTURE")
|
||||||
|
flag = self.get_capture_zone_flag()
|
||||||
|
capture_trigger = TriggerCondition(Event.NoEvent, "Capture Trigger")
|
||||||
|
capture_trigger.add_condition(AllOfCoalitionOutsideZone(defending_coalition, trigger_zone.id))
|
||||||
|
capture_trigger.add_condition(PartOfCoalitionInZone(attacking_coalition, trigger_zone.id, unit_type="GROUND"))
|
||||||
|
capture_trigger.add_condition(FlagIsFalse(flag=flag))
|
||||||
|
script_string = String(
|
||||||
|
f'base_capture_events[#base_capture_events + 1] = "{cp.id}||{attack_coalition_int}||{cp.full_name}"'
|
||||||
|
)
|
||||||
|
capture_trigger.add_action(DoScript(
|
||||||
|
script_string
|
||||||
|
)
|
||||||
|
)
|
||||||
|
capture_trigger.add_action(SetFlag(flag=flag))
|
||||||
|
self.mission.triggerrules.triggers.append(capture_trigger)
|
||||||
|
|
||||||
|
recapture_trigger = TriggerCondition(Event.NoEvent, "Capture Trigger")
|
||||||
|
recapture_trigger.add_condition(AllOfCoalitionOutsideZone(attacking_coalition, trigger_zone.id))
|
||||||
|
recapture_trigger.add_condition(PartOfCoalitionInZone(defending_coalition, trigger_zone.id, unit_type="GROUND"))
|
||||||
|
recapture_trigger.add_condition(FlagIsTrue(flag=flag))
|
||||||
|
script_string = String(
|
||||||
|
f'base_capture_events[#base_capture_events + 1] = "{cp.id}||{defend_coalition_int}||{cp.full_name}"'
|
||||||
|
)
|
||||||
|
recapture_trigger.add_action(DoScript(
|
||||||
|
script_string
|
||||||
|
)
|
||||||
|
)
|
||||||
|
recapture_trigger.add_action(ClearFlag(flag=flag))
|
||||||
|
self.mission.triggerrules.triggers.append(recapture_trigger)
|
||||||
|
|
||||||
def generate(self):
|
def generate(self):
|
||||||
player_coalition = "blue"
|
player_coalition = "blue"
|
||||||
enemy_coalition = "red"
|
enemy_coalition = "red"
|
||||||
@ -124,4 +192,13 @@ class TriggersGenerator:
|
|||||||
self._set_skill(player_coalition, enemy_coalition)
|
self._set_skill(player_coalition, enemy_coalition)
|
||||||
self._set_allegiances(player_coalition, enemy_coalition)
|
self._set_allegiances(player_coalition, enemy_coalition)
|
||||||
self._gen_markers()
|
self._gen_markers()
|
||||||
|
self._generate_capture_triggers(player_coalition, enemy_coalition)
|
||||||
|
print("Test")
|
||||||
|
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_capture_zone_flag(cls):
|
||||||
|
flag = cls.capture_zone_flag
|
||||||
|
cls.capture_zone_flag += 1
|
||||||
|
return flag
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user