diff --git a/game/utils.py b/game/utils.py index 772db9a9..0355fbb2 100644 --- a/game/utils.py +++ b/game/utils.py @@ -54,4 +54,4 @@ def heading_sum(h, a) -> int: return h def opposite_heading(h): - return h+180 \ No newline at end of file + return heading_sum(h, 180) \ No newline at end of file diff --git a/gen/armor.py b/gen/armor.py index cb8ec008..448ceb50 100644 --- a/gen/armor.py +++ b/gen/armor.py @@ -112,12 +112,13 @@ class GroundConflictGenerator: ] ) - def _group_point(self, point: Point) -> Point: + @staticmethod + def _group_point(point: Point, base_distance) -> Point: distance = random.randint( - int(self.conflict.size * SPREAD_DISTANCE_FACTOR[0]), - int(self.conflict.size * SPREAD_DISTANCE_FACTOR[1]), + int(base_distance * SPREAD_DISTANCE_FACTOR[0]), + int(base_distance * SPREAD_DISTANCE_FACTOR[1]), ) - return point.random_point_within(distance, self.conflict.size * SPREAD_DISTANCE_SIZE_FACTOR) + return point.random_point_within(distance, base_distance * SPREAD_DISTANCE_SIZE_FACTOR) def generate(self): position = Conflict.frontline_position(self.conflict.from_cp, self.conflict.to_cp, self.game.theater) @@ -495,7 +496,8 @@ class GroundConflictGenerator: group.units[0], len(group.units), final_position, - heading=opposite_heading(spawn_heading) + distance_from_frontline, + heading=opposite_heading(spawn_heading), ) if is_player: g.set_skill(self.game.settings.player_skill) @@ -514,8 +516,9 @@ class GroundConflictGenerator: unit: VehicleType, count: int, at: Point, + distance_from_frontline, move_formation: PointAction = PointAction.OffRoad, - heading=0 + heading=0, ) -> VehicleGroup: if side == self.conflict.attackers_country: @@ -527,7 +530,7 @@ class GroundConflictGenerator: group = self.mission.vehicle_group( side, namegen.next_unit_name(side, cp.id, unit), unit, - position=self._group_point(at), + position=self._group_point(at, distance_from_frontline), group_size=count, heading=heading, move_formation=move_formation) diff --git a/gen/conflictgen.py b/gen/conflictgen.py index 9bf49f31..161d14ca 100644 --- a/gen/conflictgen.py +++ b/gen/conflictgen.py @@ -82,24 +82,21 @@ class Conflict: @classmethod def extend_ground_position(cls, initial: Point, max_distance: int, heading: int, theater: ConflictTheater) -> Point: - """Finds a valid ground position in one heading from an initial point""" + """Finds the first intersection with an exclusion zone in one heading from an initial point up to max_distance""" pos = initial for distance in range(0, int(max_distance), 100): - if not theater.is_on_land(pos): - return pos pos = initial.point_from_heading(heading, distance) - if theater.is_on_land(pos): - return pos - logging.error("Didn't find ground position ({})!".format(initial)) - return initial + if not theater.is_on_land(pos): + return initial.point_from_heading(heading, distance - 100) + return pos @classmethod def find_ground_position(cls, initial: Point, max_distance: int, heading: int, theater: ConflictTheater) -> Point: - """Finds the nearest ground position along a provided heading and it's inverse""" + """Finds the nearest valid ground position along a provided heading and it's inverse""" pos = initial + if theater.is_on_land(pos): + return pos for distance in range(0, int(max_distance), 100): - if theater.is_on_land(pos): - return pos pos = initial.point_from_heading(heading, distance) if theater.is_on_land(pos): return pos diff --git a/gen/visualgen.py b/gen/visualgen.py index 97dbaa40..e03da467 100644 --- a/gen/visualgen.py +++ b/gen/visualgen.py @@ -103,15 +103,12 @@ class VisualGenerator: if from_cp.is_global or to_cp.is_global: continue - frontline = Conflict.frontline_position(from_cp, to_cp, self.game.theater) - if not frontline: + plane_start, heading, distance = Conflict.frontline_vector(from_cp, to_cp, self.game.theater) + if not plane_start: continue - point, heading = frontline - plane_start = point.point_from_heading(turn_heading(heading, 90), FRONTLINE_LENGTH / 2) - - for offset in range(0, FRONTLINE_LENGTH, FRONT_SMOKE_SPACING): - position = plane_start.point_from_heading(turn_heading(heading, - 90), offset) + for offset in range(0, distance, FRONT_SMOKE_SPACING): + position = plane_start.point_from_heading(heading, offset) for k, v in FRONT_SMOKE_TYPE_CHANCES.items(): if random.randint(0, 100) <= k: