Changed helipad generation structure as to not impact "Game" object, as suggested by Dan.

This commit is contained in:
Khopa
2021-08-07 01:05:57 +02:00
parent 5412487178
commit 5e715daded
6 changed files with 44 additions and 82 deletions

View File

@@ -9,6 +9,7 @@ from __future__ import annotations
import logging
import random
from collections import defaultdict
from typing import (
Dict,
Iterator,
@@ -587,6 +588,7 @@ class HelipadGenerator:
self.game = game
self.radio_registry = radio_registry
self.tacan_registry = tacan_registry
self.helipads: list[StaticGroup] = []
def generate(self) -> None:
@@ -595,7 +597,7 @@ class HelipadGenerator:
country = self.m.country(self.game.coalition_for(self.cp.captured).country_name)
for i, helipad in enumerate(self.cp.helipads):
name = self.cp.name + "_helipad_" + str(i)
logging.info("Generating helipad : " + name)
logging.info("Generating helipad static : " + name)
pad = InvisibleFARP(name=name)
pad.position = Point(helipad.x, helipad.y)
pad.heading = helipad.heading.degrees
@@ -606,8 +608,7 @@ class HelipadGenerator:
sg.add_point(sp)
neutral_country.add_static_group(sg)
helipad.static_unit = sg
helipad.occupied = False
self.helipads.append(sg)
# Generate a FARP Ammo and Fuel stack for each pad
self.m.static_group(
@@ -652,13 +653,18 @@ class GroundObjectsGenerator:
self.unit_map = unit_map
self.icls_alloc = iter(range(1, 21))
self.runways: Dict[str, RunwayData] = {}
self.helipads: dict[ControlPoint, list[StaticGroup]] = defaultdict(list)
def generate(self) -> None:
for cp in self.game.theater.controlpoints:
country = self.m.country(self.game.coalition_for(cp.captured).country_name)
HelipadGenerator(
# Generate helipads
helipad_gen = HelipadGenerator(
self.m, cp, self.game, self.radio_registry, self.tacan_registry
).generate()
)
helipad_gen.generate()
self.helipads[cp] = helipad_gen.helipads
for ground_object in cp.ground_objects:
generator: GenericGroundObjectGenerator[Any]