mirror of
https://github.com/LmeSzinc/AzurLaneAutoScript.git
synced 2025-01-08 12:07:36 +08:00
Fix: Avoid turning_optimize in event maps
This commit is contained in:
parent
3740ab7164
commit
edbbc7b8cb
@ -12,7 +12,7 @@ class Config:
|
||||
# Disabled because having errors
|
||||
MAP_SWIPE_PREDICT_WITH_SEA_GRIDS = False
|
||||
# Ambushes can be avoid by having more DDs.
|
||||
MAP_WALK_OPTIMIZE = False
|
||||
MAP_WALK_TURNING_OPTIMIZE = False
|
||||
|
||||
|
||||
class CampaignBase(CampaignBase_):
|
||||
|
@ -13,7 +13,7 @@ MASK_MAP_UI_W15 = Mask(file='./assets/mask/MASK_MAP_UI_W15.png')
|
||||
|
||||
class Config:
|
||||
# Ambushes can be avoid by having more DDs.
|
||||
MAP_WALK_OPTIMIZE = False
|
||||
MAP_WALK_TURNING_OPTIMIZE = False
|
||||
MAP_HAS_MYSTERY = False
|
||||
MAP_ENEMY_TEMPLATE = ['Light', 'Main', 'Carrier', 'CarrierSpecial']
|
||||
INTERNAL_LINES_FIND_PEAKS_PARAMETERS = {
|
||||
|
@ -182,7 +182,7 @@ class ManualConfig:
|
||||
# Use the green arrow on current fleet to decide if fleet arrived a certain grid
|
||||
MAP_WALK_USE_CURRENT_FLEET = False
|
||||
# Optimize walk path, reducing ambushes
|
||||
MAP_WALK_OPTIMIZE = True
|
||||
MAP_WALK_TURNING_OPTIMIZE = True
|
||||
# Optimize swipe path, reducing swipes turn info clicks.
|
||||
MAP_SWIPE_OPTIMIZE = True
|
||||
# Swipe after boss appear. Could avoid map detection error when camera is on edge.
|
||||
|
@ -467,23 +467,27 @@ class Fleet(Camera, AmbushHandler):
|
||||
if result == 'nothing' and expected == 'combat':
|
||||
raise MapEnemyMoved
|
||||
|
||||
def goto(self, location, optimize=None, expected=''):
|
||||
def goto(self, location, expected='', step_optimize=None, turning_optimize=None):
|
||||
"""
|
||||
Args:
|
||||
location (tuple, str, GridInfo): Destination.
|
||||
optimize (bool): Optimize walk path, reducing ambushes.
|
||||
If None, loads MAP_WALK_OPTIMIZE
|
||||
expected (str): Expected result on destination grid, such as 'combat', 'combat_siren', 'mystery'.
|
||||
Will give a waring if arrive with unexpected result.
|
||||
step_optimize (bool): True to walk in fleet step
|
||||
turning_optimize (bool): True to optimize route to reduce ambushes
|
||||
"""
|
||||
location = location_ensure(location)
|
||||
if optimize is None:
|
||||
optimize = self.config.MAP_WALK_OPTIMIZE
|
||||
if step_optimize is None:
|
||||
step_optimize = self.config.MAP_HAS_FLEET_STEP
|
||||
if self.config.MAP_HAS_PORTAL or self.config.MAP_HAS_MAZE:
|
||||
step_optimize = True
|
||||
if turning_optimize is None:
|
||||
turning_optimize = self.config.MAP_HAS_AMBUSH
|
||||
|
||||
# self.device.sleep(1000)
|
||||
if optimize and (self.config.MAP_HAS_AMBUSH or self.config.MAP_HAS_FLEET_STEP or self.config.MAP_HAS_PORTAL
|
||||
or self.config.MAP_HAS_MAZE):
|
||||
nodes = self.map.find_path(location, step=self.fleet_step)
|
||||
if step_optimize or turning_optimize:
|
||||
step = self.fleet_step if step_optimize else 0
|
||||
nodes = self.map.find_path(location, step=step, turning_optimize=turning_optimize)
|
||||
for node in nodes:
|
||||
if self.maze_active_on(node):
|
||||
logger.info(f'Maze is active on {location2node(node)}, bouncing to wait')
|
||||
@ -499,7 +503,7 @@ class Fleet(Camera, AmbushHandler):
|
||||
logger.warning('Map walk error.')
|
||||
self.predict()
|
||||
self.ensure_edge_insight()
|
||||
nodes_ = self.map.find_path(node, step=1)
|
||||
nodes_ = self.map.find_path(node, step=1, turning_optimize=False)
|
||||
for node_ in nodes_:
|
||||
self._goto(node_, expected=expected if node == nodes[-1] else '')
|
||||
else:
|
||||
|
@ -604,11 +604,12 @@ class CampaignMap:
|
||||
|
||||
return res
|
||||
|
||||
def _find_route_node(self, route, step=0):
|
||||
def _find_route_node(self, route, step=0, turning_optimize=False):
|
||||
"""
|
||||
Args:
|
||||
route (list[tuple]): list of grids.
|
||||
step (int): Fleet step in event map. Default to 0.
|
||||
turning_optimize: (bool): True to optimize route to reduce ambushes
|
||||
|
||||
Returns:
|
||||
list[tuple]: list of walking node.
|
||||
@ -617,23 +618,30 @@ class CampaignMap:
|
||||
MAP_7_2._find_route_node([(2, 2), (3, 2), (4, 2), (5, 2), (6, 2), (6, 1), (7, 1)])
|
||||
[(6, 2), (7, 1)]
|
||||
"""
|
||||
res = []
|
||||
diff = np.abs(np.diff(route, axis=0))
|
||||
turning = np.diff(diff, axis=0)[:, 0]
|
||||
indexes = np.where(turning == -1)[0] + 1
|
||||
for index in indexes:
|
||||
if not self[route[index]].is_fleet:
|
||||
res.append(index)
|
||||
else:
|
||||
logger.info(f'Path_node_avoid: {self[route[index]]}')
|
||||
if (index > 1) and (index - 1 not in indexes):
|
||||
res.append(index - 1)
|
||||
if (index < len(route) - 2) and (index + 1 not in indexes):
|
||||
res.append(index + 1)
|
||||
res.append(len(route) - 1)
|
||||
# res = [6, 8]
|
||||
if step == 0:
|
||||
return [route[index] for index in res]
|
||||
if turning_optimize:
|
||||
res = []
|
||||
diff = np.abs(np.diff(route, axis=0))
|
||||
turning = np.diff(diff, axis=0)[:, 0]
|
||||
indexes = np.where(turning == -1)[0] + 1
|
||||
for index in indexes:
|
||||
if not self[route[index]].is_fleet:
|
||||
res.append(index)
|
||||
else:
|
||||
logger.info(f'Path_node_avoid: {self[route[index]]}')
|
||||
if (index > 1) and (index - 1 not in indexes):
|
||||
res.append(index - 1)
|
||||
if (index < len(route) - 2) and (index + 1 not in indexes):
|
||||
res.append(index + 1)
|
||||
res.append(len(route) - 1)
|
||||
# res = [4, 6]
|
||||
if step == 0:
|
||||
return [route[index] for index in res]
|
||||
else:
|
||||
if step == 0:
|
||||
return [route[-1]]
|
||||
# Index of the last node
|
||||
# res = [6]
|
||||
res = [max(len(route) - 1, 0)]
|
||||
|
||||
res.insert(0, 0)
|
||||
inserted = []
|
||||
@ -653,7 +661,7 @@ class CampaignMap:
|
||||
# res = [3, 6, 8]
|
||||
return [route[index] for index in res]
|
||||
|
||||
def find_path(self, location, step=0):
|
||||
def find_path(self, location, step=0, turning_optimize=False):
|
||||
location = location_ensure(location)
|
||||
|
||||
path = self._find_path(location)
|
||||
@ -676,7 +684,7 @@ class CampaignMap:
|
||||
if end - start == 1 and self[path[start]].is_portal and self[path[start]].portal_link == path[end]:
|
||||
continue
|
||||
local_path = path[start:end + 1]
|
||||
local_path = self._find_route_node(local_path, step=step)
|
||||
local_path = self._find_route_node(local_path, step=step, turning_optimize=turning_optimize)
|
||||
portal_path += local_path
|
||||
logger.info('Path: %s' % '[' + ', ' .join([location2node(grid) for grid in local_path]) + ']')
|
||||
path = portal_path
|
||||
|
Loading…
Reference in New Issue
Block a user