Fix odd frontline unit spawns

* Modfied frontline vector to ensure start point stays outside of
  exclusion zone.  (Previously it could be up to 100m inside)

* Change randomization in offset distance from frontline to be based
  on a percentage of the unit type's fixed offset instead of the
  width of frontline.
  (Prevents units from being far from their expected distance from
  frontline)

* Change visualgen to use the same frontline vector calculation as the
  unit spawns
This commit is contained in:
walterroach 2020-11-28 18:43:32 -06:00
parent 55573bf40a
commit 29b894f8b0
4 changed files with 22 additions and 25 deletions

View File

@ -54,4 +54,4 @@ def heading_sum(h, a) -> int:
return h
def opposite_heading(h):
return h+180
return heading_sum(h, 180)

View File

@ -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)

View File

@ -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

View File

@ -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: