Previously destroyed units are added to the mission.

This commit is contained in:
Khopa
2020-07-25 18:46:10 +02:00
parent b34ede3795
commit d5fb1f62f5
9 changed files with 197 additions and 41 deletions

View File

@@ -1,7 +1,7 @@
from datetime import datetime, timedelta
from game.db import REWARDS, PLAYER_BUDGET_BASE, sys
from game.game_stats import GameStats
from game.models.game_stats import GameStats
from gen.flights.ai_flight_planner import FlightPlanner
from gen.ground_forces.ai_ground_planner import GroundPlanner
from .event import *
@@ -73,7 +73,8 @@ class Game:
self.informations = []
self.informations.append(Information("Game Start", "-" * 40, 0))
self.__culling_points = self.compute_conflicts_position()
self.__frontlineData = []
self.__destroyed_units = []
@property
def player_faction(self):
@@ -175,33 +176,6 @@ class Game:
else:
return event.name == self.player_name
# 1 = red, 2 = blue
def get_player_coalition_id(self):
if self.player_country in db.BLUEFOR_FACTIONS:
return 2
else:
return 1
def get_enemy_coalition_id(self):
if self.get_player_coalition_id() == 1:
return 2
else:
return 1
def get_player_color(self):
if self.get_player_coalition_id() == 1:
return "red"
else:
return "blue"
def get_enemy_color(self):
if self.get_player_coalition_id() == 1:
return "blue"
else:
return "red"
def pass_turn(self, no_action=False, ignored_cps: typing.Collection[ControlPoint] = None):
logging.info("Pass turn")
@@ -383,6 +357,12 @@ class Game:
return points
def add_destroyed_units(self, destroyed_unit_data):
self.__destroyed_units.append(destroyed_unit_data)
def get_destroyed_units(self):
return self.__destroyed_units
def position_culled(self, pos):
"""
Check if unit can be generated at given position depending on culling performance settings
@@ -397,3 +377,39 @@ class Game:
return False
return True
# 1 = red, 2 = blue
def get_player_coalition_id(self):
if self.player_country in db.BLUEFOR_FACTIONS:
return 2
else:
return 1
def get_enemy_coalition_id(self):
if self.get_player_coalition_id() == 1:
return 2
else:
return 1
def get_player_coalition(self):
if self.player_country in db.BLUEFOR_FACTIONS:
return dcs.action.Coalition.Blue
else:
return dcs.action.Coalition.Red
def get_enemy_coalition(self):
if self.player_country == 1:
return dcs.action.Coalition.Blue
else:
return dcs.action.Coalition.Red
def get_player_color(self):
if self.get_player_coalition_id() == 1:
return "red"
else:
return "blue"
def get_enemy_color(self):
if self.get_player_coalition_id() == 1:
return "blue"
else:
return "red"

View File

@@ -0,0 +1,14 @@
class DestroyedUnit:
"""
Store info about a destroyed unit
"""
x: int
y: int
name: str
def __init__(self, x , y, name):
self.x = x
self.y = y
self.name = name

View File

@@ -0,0 +1,13 @@
from theater import ControlPoint
class FrontlineData:
"""
This Data structure will store information about an existing frontline
"""
def __init__(self, from_cp:ControlPoint, to_cp: ControlPoint):
self.to_cp = to_cp
self.from_cp = from_cp
self.enemy_units_position = []
self.blue_units_position = []

View File

@@ -123,6 +123,21 @@ class Operation:
# Generate ground object first
self.groundobjectgen.generate()
# Generate destroyed units
for d in self.game.get_destroyed_units():
utype = db.unit_type_from_name(d["type"])
pos = Point(d["x"], d["z"])
if utype is not None and not self.game.position_culled(pos):
self.current_mission.static_group(
country=self.current_mission.country(self.game.player_country),
name="",
_type=utype,
hidden=True,
position=pos,
heading=d["orientation"],
dead=True,
)
# Air Support (Tanker & Awacs)
self.airsupportgen.generate(self.is_awacs_enabled)