Operation refactor cleanup

Fix bug in closest cp algorithm
This commit is contained in:
walterroach 2020-11-23 22:27:12 -06:00
parent 967574820f
commit 34a7a37409
4 changed files with 7 additions and 7 deletions

View File

@ -8,7 +8,7 @@ if TYPE_CHECKING:
class AirWarEvent(Event): class AirWarEvent(Event):
"""An Event centered on the overall Air War""" """Event handler for the air battle"""
def __str__(self): def __str__(self):
return "Frontline attack" return "AirWar"

View File

@ -38,7 +38,6 @@ class Event:
location = None # type: Point location = None # type: Point
from_cp = None # type: ControlPoint from_cp = None # type: ControlPoint
to_cp = None # type: ControlPoint to_cp = None # type: ControlPoint
operation = Operation
difficulty = 1 # type: int difficulty = 1 # type: int
BONUS_BASE = 5 BONUS_BASE = 5
@ -62,9 +61,9 @@ class Event:
return int(math.log(self.to_cp.importance + 1, DIFFICULTY_LOG_BASE) * self.BONUS_BASE) return int(math.log(self.to_cp.importance + 1, DIFFICULTY_LOG_BASE) * self.BONUS_BASE)
def generate(self) -> UnitMap: def generate(self) -> UnitMap:
self.operation.prepare(self.game) Operation.prepare(self.game)
unit_map = self.operation.generate() unit_map = Operation.generate()
self.operation.current_mission.save( Operation.current_mission.save(
persistency.mission_path_for("liberation_nextturn.miz")) persistency.mission_path_for("liberation_nextturn.miz"))
return unit_map return unit_map

View File

@ -193,7 +193,7 @@ class Game:
if isinstance(event, Event): if isinstance(event, Event):
return event and event.attacker_name and event.attacker_name == self.player_name return event and event.attacker_name and event.attacker_name == self.player_name
else: else:
raise RuntimeError(f"{event} was passed when an expected") raise RuntimeError(f"{event} was passed when an Event type was expected")
def on_load(self) -> None: def on_load(self) -> None:
LuaPluginManager.load_settings(self.settings) LuaPluginManager.load_settings(self.settings)

View File

@ -485,6 +485,7 @@ class ConflictTheater:
dist = cp.position.distance_to_point(control_point.position) dist = cp.position.distance_to_point(control_point.position)
if not closest_distance: if not closest_distance:
closest_distance = dist closest_distance = dist
distances[cp.id] = dist
if dist < closest_distance: if dist < closest_distance:
distances[cp.id] = dist distances[cp.id] = dist
closest_cp_id = min(distances, key=distances.get) # type: ignore closest_cp_id = min(distances, key=distances.get) # type: ignore