new options, landmaps, mission settings generation update & frontlike smokes generation

This commit is contained in:
Vasyl Horbachenko
2018-06-16 21:04:01 +03:00
parent 92e5514e8d
commit e54e548bdd
25 changed files with 344 additions and 41 deletions

View File

@@ -127,7 +127,6 @@ class Base:
def commit_losses(self, units_lost: typing.Dict[typing.Any, int]):
for unit_type, count in units_lost.items():
target_array = None
if unit_type in self.aircraft:
target_array = self.aircraft
elif unit_type in self.armor:
@@ -164,3 +163,7 @@ class Base:
def assemble_defense(self, factor: float) -> typing.Dict[Armor, int]:
return self._find_best_armor(CAP, math.ceil(self.total_armor * factor * self.strength))
def assemble_aa(self) -> typing.Dict[AirDefence, int]:
count = int(self.total_aa * (self.strength > 0.2 and self.strength or 0))
return self._find_best_unit(self.aa, AirDefence, count)

View File

@@ -1,6 +1,7 @@
from dcs.terrain import caucasus
from dcs import mapping
from .landmap import *
from .conflicttheater import *
from .base import *
@@ -10,6 +11,13 @@ class CaucasusTheater(ConflictTheater):
overview_image = "caumap.gif"
reference_points = {(-317948.32727306, 635639.37385346): (282.5, 319),
(-355692.3067714, 617269.96285781): (269, 352), }
landmap_poly = load_poly("resources\\caulandmap.p")
daytime_map = {
"dawn": (6, 9),
"day": (9, 18),
"dusk": (18, 21),
"night": (0, 5),
}
soganlug = ControlPoint.from_airport(caucasus.Soganlug, ALL_RADIALS, SIZE_SMALL, IMPORTANCE_LOW)
kutaisi = ControlPoint.from_airport(caucasus.Kutaisi, ALL_RADIALS, SIZE_SMALL, IMPORTANCE_LOW)
@@ -32,7 +40,7 @@ class CaucasusTheater(ConflictTheater):
mineralnye = ControlPoint.from_airport(caucasus.Mineralnye_Vody, ALL_RADIALS, SIZE_BIG, IMPORTANCE_MEDIUM)
mozdok = ControlPoint.from_airport(caucasus.Mozdok, ALL_RADIALS, SIZE_BIG, IMPORTANCE_MEDIUM)
carrier_1 = ControlPoint.carrier("Carrier", mapping.Point(-355810.6875, 516399.1875))
carrier_1 = ControlPoint.carrier("Carrier", mapping.Point(-305810.6875, 406399.1875))
def __init__(self):
super(CaucasusTheater, self).__init__()
@@ -63,3 +71,9 @@ class CaucasusTheater(ConflictTheater):
self.carrier_1.captured = True
self.soganlug.captured = True
self.sukhumi.captured = True
self.gudauta.base.strength = 0.5
self.kobuleti.captured = True
self.batumi.base.strength = 0.15

View File

@@ -3,6 +3,7 @@ import itertools
import dcs
from .landmap import ray_tracing
from .controlpoint import *
SIZE_TINY = 150
@@ -31,6 +32,8 @@ class ConflictTheater:
controlpoints = None # type: typing.Collection[ControlPoint]
reference_points = None # type: typing.Dict
overview_image = None # type: str
landmap_poly = None
daytime_map = None # type: typing.Dict[str, typing.Tuple[int, int]]
def __init__(self):
self.controlpoints = []
@@ -41,6 +44,15 @@ class ConflictTheater:
self.controlpoints.append(point)
def is_on_land(self, point: Point) -> bool:
if not self.landmap_poly:
return True
for poly in self.landmap_poly:
return ray_tracing(point.x, point.y, poly)
return False
def player_points(self) -> typing.Collection[ControlPoint]:
return [point for point in self.controlpoints if point.captured]

24
theater/landmap.py Normal file
View File

@@ -0,0 +1,24 @@
import pickle
def load_poly(filename: str):
with open(filename, "rb") as f:
return pickle.load(f)
def ray_tracing(x, y, poly):
n = len(poly)
inside = False
xints = 0.0
p1x, p1y = poly[0]
for i in range(n+1):
p2x, p2y = poly[i % n]
if y > min(p1y, p2y):
if y <= max(p1y, p2y):
if x <= max(p1x, p2x):
if p1y != p2y:
xints = (y-p1y)*(p2x-p1x)/(p2y-p1y)+p1x
if p1x == p2x or x <= xints:
inside = not inside
p1x, p1y = p2x, p2y
return inside

View File

@@ -10,6 +10,12 @@ class NevadaTheater(ConflictTheater):
overview_image = "nevada.gif"
reference_points = {(nevada.Mina_Airport_3Q0.position.x, nevada.Mina_Airport_3Q0.position.y): (45, -360),
(nevada.Laughlin_Airport.position.x, nevada.Laughlin_Airport.position.y): (440, 80), }
daytime_map = {
"dawn": (4, 6),
"day": (6, 17),
"dusk": (17, 19),
"night": (0, 5),
}
mina = ControlPoint.from_airport(nevada.Mina_Airport_3Q0, ALL_RADIALS, SIZE_SMALL, IMPORTANCE_LOW)
tonopah = ControlPoint.from_airport(nevada.Tonopah_Airport, ALL_RADIALS, SIZE_SMALL, IMPORTANCE_LOW)
@@ -45,3 +51,5 @@ class NevadaTheater(ConflictTheater):
self.add_controlpoint(self.laughlin, connected_to=[self.jean, self.las_vegas])
self.mina.captured = True
self.pahute_mesa.captured = True
self.groom_lake.captured = True

View File

@@ -3,6 +3,7 @@ from dcs import mapping
from .conflicttheater import *
from .base import *
from .landmap import load_poly
class PersianGulfTheater(ConflictTheater):
@@ -10,6 +11,13 @@ class PersianGulfTheater(ConflictTheater):
overview_image = "persiangulf.gif"
reference_points = {(persiangulf.Sir_Abu_Nuayr.position.x, persiangulf.Sir_Abu_Nuayr.position.y): (351, 115),
(persiangulf.Sirri_Island.position.x, persiangulf.Sirri_Island.position.y): (389, 22), }
landmap_poly = load_poly("resources\\gulflandmap.p")
daytime_map = {
"dawn": (5, 7),
"day": (7, 17),
"dusk": (17, 19),
"night": (0, 5),
}
al_dhafra = ControlPoint.from_airport(persiangulf.Al_Dhafra_AB, ALL_RADIALS, SIZE_BIG, IMPORTANCE_LOW)
al_maktoum = ControlPoint.from_airport(persiangulf.Al_Maktoum_Intl, ALL_RADIALS, SIZE_BIG, IMPORTANCE_LOW)

View File

@@ -1,11 +1,20 @@
import math
from theater.base import *
from theater.conflicttheater import *
UNIT_VARIETY = 3
UNIT_AMOUNT_FACTOR = 16
COUNT_BY_TASK = {
CAP: 12,
FighterSweep: 16,
CAS: 8,
AirDefence: 0.5,
}
def generate_initial(theater: ConflictTheater, enemy: str):
def generate_initial(theater: ConflictTheater, enemy: str, sams: bool):
for cp in theater.enemy_points():
if cp.captured:
continue
@@ -15,10 +24,14 @@ def generate_initial(theater: ConflictTheater, enemy: str):
assert cp.importance >= IMPORTANCE_LOW, "invalid importance {}".format(cp.importance)
importance_factor = (cp.importance - IMPORTANCE_LOW) / (IMPORTANCE_HIGH - IMPORTANCE_LOW)
variety = int(UNIT_VARIETY + UNIT_VARIETY * importance_factor / 2)
variety = int(UNIT_VARIETY)
unittypes = db.choose_units(task, importance_factor, variety, enemy)
count = max(int(importance_factor * UNIT_AMOUNT_FACTOR), 1)
if not sams:
unittypes = [x for x in unittypes if x not in db.SAM_BAN]
count = max(COUNT_BY_TASK[task] * importance_factor, 1)
count_per_type = max(int(float(count) / len(unittypes)), 1)
for unit_type in unittypes:
print("{} - {} {}".format(cp.name, db.unit_type_name(unit_type), count_per_type))
cp.base.commision_units({unit_type: count_per_type})