Roadbase and ground spawn support (#132)

* Roadbase and ground spawn support

Implemented support for roadbases and ground spawn slots at airfields and FOBs. The ground spawn slots can be inserted in campaigns by placing either an A-10A or an AJS37 at a runway or ramp. This will cause an invisible FARP, an ammo dump and a fuel dump to be placed (behind the slot in case of A-10A, to the side in case of AJS37) in the generated campaigns. The ground spawn slot can be used by human controlled aircraft in generated missions. Also allowed the use of the four-slot FARP and the single helipad in campaigns, in addition to the invisible FARP. The first waypoint of the placed aircraft will be the center of a Remove Statics trigger zone (which might or might not work in multiplayer due to a DCS limitation).

Also implemented three new options in settings:
 - AI fixed-wing aircraft can use roadbases / bases with only ground spawns
   - This setting will allow the AI to use the roadbases for flights and transfers. AI flights will air-start from these bases, since the AI in DCS is not currently able to take off from ground spawns.
 - Spawn trucks at ground spawns in airbases instead of FARP statics
 - Spawn trucks at ground spawns in roadbases instead of FARP statics
   - These settings will replace the FARP statics with refueler and ammo trucks at roadbases. Enabling them might have a negative performance impact.

* Modified calculate_parking_slots() so it now takes into account also helicopter slots on FARPs and also ground start slots (but only if the aircraft is flyable or the "AI fixed-wing aircraft can use roadbases / bases with only ground spawns" option is enabled in settings).

* Improved the way parking slots are communicated on the basemenu window.

* Refactored helipad and ground spawn appends to static methods _add_helipad and _add_ground_spawn in mizcampaignloader.py
Added missing changelog entries.
Fixed tgogenerator.py imports.
Cleaned up ParkingType() construction.

* Added test_control_point_parking for testing that the correct number of parking slots are returned for control point in test_controlpoint.py

* Added test_parking_type_from_squadron to test the correct ParkingType object is returned for a squadron of Viggens in test_controlpoint.py

* Added test_parking_type_from_aircraft to test the correct ParkingType object is returned for Viggen aircraft type in test_controlpoint.py

---------

Co-authored-by: Raffson <Raffson@users.noreply.github.com>
This commit is contained in:
MetalStormGhost
2023-06-19 00:02:08 +03:00
committed by GitHub
parent 5a71806651
commit e273e93012
25 changed files with 1234 additions and 174 deletions

View File

@@ -1,9 +1,24 @@
import pytest
from typing import Any
from dcs import Point
from dcs.planes import AJS37
from dcs.terrain.terrain import Airport
from game.ato.flighttype import FlightType
from game.theater.controlpoint import Airfield, Carrier, Lha, OffMapSpawn, Fob
from game.dcs.aircrafttype import AircraftType
from game.dcs.countries import country_with_name
from game.point_with_heading import PointWithHeading
from game.squadrons import Squadron
from game.squadrons.operatingbases import OperatingBases
from game.theater.controlpoint import (
Airfield,
Carrier,
Lha,
OffMapSpawn,
Fob,
ParkingType,
)
from game.utils import Heading
@pytest.fixture
@@ -117,3 +132,89 @@ def test_mission_types_enemy(mocker: Any) -> None:
off_map_spawn = OffMapSpawn(name="test", position=None, theater=None, starts_blue=True) # type: ignore
mission_types = list(off_map_spawn.mission_types(for_player=True))
assert len(mission_types) == 0
@pytest.fixture
def test_control_point_parking(mocker: Any) -> None:
"""
Test correct number of parking slots are returned for control point
"""
# Airfield
mocker.patch("game.theater.controlpoint.unclaimed_parking", return_value=10)
airport = Airport(None, None) # type: ignore
airport.name = "test" # required for Airfield.__init__
point = Point(0, 0, None) # type: ignore
control_point = Airfield(airport, theater=None, starts_blue=True) # type: ignore
parking_type_ground_start = ParkingType(
fixed_wing=False, fixed_wing_stol=True, rotary_wing=False
)
parking_type_rotary = ParkingType(
fixed_wing=False, fixed_wing_stol=False, rotary_wing=True
)
for x in range(10):
control_point.ground_spawns.append(
(
PointWithHeading.from_point(
point,
Heading.from_degrees(0),
),
point,
)
)
for x in range(20):
control_point.helipads.append(
PointWithHeading.from_point(
point,
Heading.from_degrees(0),
)
)
assert control_point.unclaimed_parking(parking_type_ground_start) == 10
assert control_point.unclaimed_parking(parking_type_rotary) == 20
@pytest.fixture
def test_parking_type_from_squadron(mocker: Any) -> None:
"""
Test correct ParkingType object returned for a squadron of Viggens
"""
mocker.patch(
"game.theater.controlpoint.parking_type.include_fixed_wing_stol",
return_value=True,
)
aircraft = next(AircraftType.for_dcs_type(AJS37))
squadron = Squadron(
name="test",
nickname=None,
country=country_with_name("Sweden"),
role="test",
aircraft=aircraft,
max_size=16,
livery=None,
primary_task=FlightType.STRIKE,
auto_assignable_mission_types=set(aircraft.iter_task_capabilities()),
operating_bases=OperatingBases.default_for_aircraft(aircraft),
female_pilot_percentage=0,
) # type: ignore
parking_type = ParkingType().from_squadron(squadron)
assert parking_type.include_rotary_wing == False
assert parking_type.include_fixed_wing == True
assert parking_type.include_fixed_wing_stol == True
@pytest.fixture
def test_parking_type_from_aircraft(mocker: Any) -> None:
"""
Test correct ParkingType object returned for Viggen aircraft type
"""
mocker.patch(
"game.theater.controlpoint.parking_type.include_fixed_wing_stol",
return_value=True,
)
aircraft = next(AircraftType.for_dcs_type(AJS37))
parking_type = ParkingType().from_aircraft(aircraft, False)
assert parking_type.include_rotary_wing == False
assert parking_type.include_fixed_wing == True
assert parking_type.include_fixed_wing_stol == True