naval intercept operation; package refactoring

This commit is contained in:
Vasyl Horbachenko
2018-06-18 23:57:02 +03:00
parent 3e2f3c6f89
commit e2dbaa100f
33 changed files with 974 additions and 602 deletions

View File

@@ -0,0 +1,3 @@
from .controlpoint import *
from .conflicttheater import *
from .base import *

View File

@@ -88,13 +88,6 @@ class Base:
total_scrambled += PLANES_IN_GROUP
yield total_scrambled < total_planes and PLANES_IN_GROUP or total_planes - total_scrambled
def _group_sizes_for(self, target: ControlPoint) -> typing.List[int]:
total_planes = target.importance * PLANES_IMPORTANCE_FACTOR
total_scrambled = 0
for _ in range(math.ceil(total_planes / PLANES_IN_GROUP)):
total_scrambled += PLANES_IN_GROUP
yield PLANES_IN_GROUP and total_scrambled < total_planes or total_planes - total_scrambled
def append_commision_points(self, for_type, points: float) -> int:
self.commision_points[for_type] = self.commision_points.get(for_type, 0) + points
points = self.commision_points[for_type]

View File

@@ -2,9 +2,10 @@ import typing
import itertools
import dcs
from dcs.mapping import Point
from .landmap import ray_tracing
from .controlpoint import *
from .controlpoint import ControlPoint
SIZE_TINY = 150
SIZE_SMALL = 600

View File

@@ -5,8 +5,6 @@ from dcs.mapping import *
from dcs.country import *
from dcs.terrain import Airport
from gen.conflictgen import Conflict
class ControlPoint:
connected_points = [] # type: typing.List[ControlPoint]
@@ -47,6 +45,16 @@ class ControlPoint:
def is_global(self):
return not self.connected_points
@property
def sea_radials(self) -> typing.Collection[int]:
# TODO: fix imports
all_radials = [0, 45, 90, 135, 180, 225, 270, 315, ]
result = []
for r in all_radials:
if r not in self.radials:
result.append(r)
return result
def connect(self, to):
self.connected_points.append(to)
@@ -64,15 +72,3 @@ class ControlPoint:
return closest_radial
def conflict_attack(self, from_cp, attacker: Country, defender: Country) -> Conflict:
attack_radial = self.find_radial(self.position.heading_between_point(from_cp.position))
defense_radial = self.find_radial(from_cp.position.heading_between_point(self.position), ignored_radial=attack_radial)
pos = self.position.point_from_heading(0, 1000)
return Conflict.capture_conflict(attacker=attacker,
attack_heading=attack_radial,
defender=defender,
defense_heading=defense_radial,
position=pos,
size=self.size,
radials=self.radials)

View File

@@ -2,8 +2,11 @@ import pickle
def load_poly(filename: str):
with open(filename, "rb") as f:
return pickle.load(f)
try:
with open(filename, "rb") as f:
return pickle.load(f)
except:
return None
def ray_tracing(x, y, poly):