Generate helipads as neutral objects, so they do not interfer with base capture trigger

This commit is contained in:
Khopa 2021-06-10 23:18:41 +02:00
parent 1b9ac088e4
commit adad88681e
3 changed files with 35 additions and 7 deletions

View File

@ -4,9 +4,10 @@ import random
import sys import sys
from datetime import date, datetime, timedelta from datetime import date, datetime, timedelta
from enum import Enum from enum import Enum
from typing import Any, Dict, List, Iterator from typing import Any, Dict, List
from dcs.action import Coalition from dcs.action import Coalition
from dcs.countries import Switzerland, UnitedNationsPeacekeepers, USAFAggressors
from dcs.mapping import Point from dcs.mapping import Point
from dcs.task import CAP, CAS, PinpointStrike from dcs.task import CAP, CAS, PinpointStrike
from dcs.vehicles import AirDefence from dcs.vehicles import AirDefence
@ -16,7 +17,6 @@ from game import db
from game.inventory import GlobalAircraftInventory from game.inventory import GlobalAircraftInventory
from game.models.game_stats import GameStats from game.models.game_stats import GameStats
from game.plugins import LuaPluginManager from game.plugins import LuaPluginManager
from game.theater.theatergroundobject import MissileSiteGroundObject
from gen.ato import AirTaskingOrder from gen.ato import AirTaskingOrder
from gen.conflictgen import Conflict from gen.conflictgen import Conflict
from gen.flights.ai_flight_planner import CoalitionMissionPlanner from gen.flights.ai_flight_planner import CoalitionMissionPlanner
@ -34,7 +34,7 @@ from .navmesh import NavMesh
from .procurement import AircraftProcurementRequest, ProcurementAi from .procurement import AircraftProcurementRequest, ProcurementAi
from .profiling import logged_duration from .profiling import logged_duration
from .settings import Settings, AutoAtoBehavior from .settings import Settings, AutoAtoBehavior
from .squadrons import Pilot, AirWing from .squadrons import AirWing
from .theater import ConflictTheater from .theater import ConflictTheater
from .theater.bullseye import Bullseye from .theater.bullseye import Bullseye
from .theater.transitnetwork import TransitNetwork, TransitNetworkBuilder from .theater.transitnetwork import TransitNetwork, TransitNetworkBuilder
@ -208,6 +208,17 @@ class Game:
def enemy_faction(self) -> Faction: def enemy_faction(self) -> Faction:
return db.FACTIONS[self.enemy_name] return db.FACTIONS[self.enemy_name]
@property
def neutral_country(self):
"""Return the best fitting country that can be used as neutral faction in the generated mission"""
countries_in_use = [self.player_country, self.enemy_country]
if UnitedNationsPeacekeepers not in countries_in_use:
return UnitedNationsPeacekeepers
elif Switzerland.name not in countries_in_use:
return Switzerland
else:
return USAFAggressors
def faction_for(self, player: bool) -> Faction: def faction_for(self, player: bool) -> Faction:
if player: if player:
return self.player_faction return self.player_faction

View File

@ -16,7 +16,7 @@ from dcs.triggers import TriggerStart
from game.plugins import LuaPluginManager from game.plugins import LuaPluginManager
from game.theater.theatergroundobject import TheaterGroundObject from game.theater.theatergroundobject import TheaterGroundObject
from gen import Conflict, FlightType, VisualGenerator from gen import Conflict, FlightType, VisualGenerator, Bullseye
from gen.aircraft import AIRCRAFT_DATA, AircraftConflictGenerator, FlightData from gen.aircraft import AIRCRAFT_DATA, AircraftConflictGenerator, FlightData
from gen.airfields import AIRFIELD_DATA from gen.airfields import AIRFIELD_DATA
from gen.airsupportgen import AirSupport, AirSupportConflictGenerator from gen.airsupportgen import AirSupport, AirSupportConflictGenerator
@ -114,9 +114,13 @@ class Operation:
cls.current_mission.coalition["red"] = Coalition( cls.current_mission.coalition["red"] = Coalition(
"red", bullseye=cls.game.red_bullseye.to_pydcs() "red", bullseye=cls.game.red_bullseye.to_pydcs()
) )
cls.current_mission.coalition["neutrals"] = Coalition(
"neutrals", bullseye=Bullseye(Point(0, 0)).to_pydcs()
)
p_country = cls.game.player_country p_country = cls.game.player_country
e_country = cls.game.enemy_country e_country = cls.game.enemy_country
cls.current_mission.coalition["blue"].add_country( cls.current_mission.coalition["blue"].add_country(
country_dict[db.country_id_from_name(p_country)]() country_dict[db.country_id_from_name(p_country)]()
) )
@ -124,6 +128,16 @@ class Operation:
country_dict[db.country_id_from_name(e_country)]() country_dict[db.country_id_from_name(e_country)]()
) )
belligerents = [
db.country_id_from_name(p_country),
db.country_id_from_name(e_country),
]
for country in country_dict.keys():
if country not in belligerents:
cls.current_mission.coalition["neutrals"].add_country(
country_dict[country]()
)
@classmethod @classmethod
def inject_lua_trigger(cls, contents: str, comment: str) -> None: def inject_lua_trigger(cls, contents: str, comment: str) -> None:
trigger = TriggerStart(comment=comment) trigger = TriggerStart(comment=comment)

View File

@ -584,19 +584,22 @@ class HelipadGenerator:
country_name = self.game.enemy_country country_name = self.game.enemy_country
country = self.m.country(country_name) country = self.m.country(country_name)
# Note : Helipad are generated as neutral object in order not to interfer with capture triggers
neutral_country = self.m.country(self.game.neutral_country.name)
for i, helipad in enumerate(self.cp.helipads): for i, helipad in enumerate(self.cp.helipads):
name = self.cp.name + "_helipad_" + str(i) name = self.cp.name + "_helipad_" + str(i)
logging.info("Generating helipad : " + name) logging.info("Generating helipad : " + name)
pad = SingleHeliPad(name=(name + "_unit")) pad = SingleHeliPad(name=name)
pad.position = Point(helipad.x, helipad.y) pad.position = Point(helipad.x, helipad.y)
pad.heading = helipad.heading pad.heading = helipad.heading
# pad.heliport_frequency = self.radio_registry.alloc_uhf() TODO : alloc radio & callsign
sg = unitgroup.StaticGroup(self.m.next_group_id(), name) sg = unitgroup.StaticGroup(self.m.next_group_id(), name)
sg.add_unit(pad) sg.add_unit(pad)
sp = StaticPoint() sp = StaticPoint()
sp.position = pad.position sp.position = pad.position
sg.add_point(sp) sg.add_point(sp)
country.add_static_group(sg) neutral_country.add_static_group(sg)
helipad.static_unit = sg helipad.static_unit = sg
helipad.occupied = False helipad.occupied = False