Fix: Enemy detection

- Log shows 'E' and wrong prediction is_siren, because attributes are kept to the next detection
- Fix missing predict also
- Fix log show DEFAULT_BUTTON for the entrance of campaign
This commit is contained in:
LmeSzinc 2020-05-31 02:49:06 +08:00
parent 589419ea91
commit 83508b94d3
4 changed files with 20 additions and 17 deletions

View File

@ -66,7 +66,10 @@ class CampaignUI(UI, CampaignOcr):
if name not in self.stage_entrance:
logger.warning(f'Stage not found: {name}')
raise CampaignNameError
return self.stage_entrance[name]
entrance = self.stage_entrance[name]
entrance.name = name
return entrance
def ensure_campaign_ui(self, name, mode='normal'):
"""

View File

@ -211,3 +211,16 @@ class GridInfo:
self.is_current_fleet = False
self.is_submarine = False
self.is_cleared = False
def covered_grid(self):
"""Relative coordinate of the covered grid.
Returns:
list[tuple]:
"""
if self.is_current_fleet:
return [(0, -1), (0, -2)]
if self.is_fleet or self.is_siren or self.is_mystery:
return [(0, -1)]
return []

View File

@ -104,6 +104,7 @@ class Grids(Perspective):
image = self._image_clear_ui(image)
self.image = image
for grid in self:
grid.reset()
grid.image = image
def _image_clear_ui(self, image):

View File

@ -408,14 +408,7 @@ class CampaignMap:
missing[attr] -= 1
for grid in self:
if not grid.is_fleet and not grid.is_mystery and not grid.is_siren:
continue
cover = [(0, -1)]
if grid.is_current_fleet:
cover.append((0, -2))
for upper in cover:
for upper in grid.covered_grid():
upper = tuple(np.array(grid.location) + upper)
if upper in self:
upper = self[upper]
@ -451,14 +444,7 @@ class CampaignMap:
# predict
for grid in self:
if not grid.is_fleet and not grid.is_mystery:
continue
cover = [(0, -1)]
if grid.is_current_fleet:
cover.append((0, -2))
for upper in cover:
for upper in grid.covered_grid():
upper = tuple(np.array(grid.location) + upper)
if upper in self:
upper = self[upper]