Reuse unreachable cache opening regions
This commit is contained in:
@@ -25,6 +25,7 @@ class CacheItemsStates:
|
||||
self.failed_transfer_slots = set()
|
||||
self.pending_transfer = None
|
||||
self.transferred_to_labeled_chest = False
|
||||
self.bad_openings = set()
|
||||
self.is_labeled_container = False
|
||||
self.container_item_ids = None
|
||||
|
||||
@@ -52,8 +53,23 @@ class CacheItemsStates:
|
||||
'trapped chests:', self.trapped_chests)
|
||||
self.state = self.choose_trapped_chest
|
||||
|
||||
def _opening_in_bad_region(self, world, opening):
|
||||
opening = tuple(opening)
|
||||
if opening in self.bad_openings:
|
||||
return True
|
||||
if not self.bad_openings:
|
||||
return False
|
||||
nearest = min(self.bad_openings,
|
||||
key=lambda bad: utils.phyp(opening, bad))
|
||||
if (world.path_to_place(opening, nearest) and
|
||||
world.path_to_place(nearest, opening)):
|
||||
self.bad_openings.add(opening)
|
||||
return True
|
||||
return False
|
||||
|
||||
def choose_trapped_chest(self):
|
||||
print('Choosing a labeled or trapped chest...')
|
||||
self.bad_openings = set()
|
||||
w = self.g.world
|
||||
p = utils.pint(self.g.pos)
|
||||
|
||||
@@ -70,15 +86,19 @@ class CacheItemsStates:
|
||||
self.container_item_ids = container['item_ids']
|
||||
self.is_labeled_container = True
|
||||
for opening in w.find_cache_openings(self.area, p):
|
||||
navpath = w.path_to_place(p, opening['position'])
|
||||
opening_position = tuple(opening['position'])
|
||||
if self._opening_in_bad_region(w, opening_position):
|
||||
continue
|
||||
navpath = w.path_to_place(p, opening_position)
|
||||
if navpath:
|
||||
print('Going to labeled chest', container['labels'],
|
||||
self.area)
|
||||
self.opening = opening['position']
|
||||
self.opening = opening_position
|
||||
self.open_interaction = opening
|
||||
self.g.path = navpath
|
||||
self.state = self.going_to_trapped_chest
|
||||
return
|
||||
self.bad_openings.add(opening_position)
|
||||
print('No path to labeled chest', self.area)
|
||||
|
||||
if not len(self.trapped_chests):
|
||||
@@ -98,14 +118,18 @@ class CacheItemsStates:
|
||||
self.area = chest
|
||||
|
||||
for opening in w.find_cache_openings(chest, p):
|
||||
navpath = w.path_to_place(p, opening['position'])
|
||||
opening_position = tuple(opening['position'])
|
||||
if self._opening_in_bad_region(w, opening_position):
|
||||
continue
|
||||
navpath = w.path_to_place(p, opening_position)
|
||||
if navpath:
|
||||
print('navpath to trapped chest:', navpath)
|
||||
self.opening = opening['position']
|
||||
self.opening = opening_position
|
||||
self.open_interaction = opening
|
||||
self.g.path = navpath
|
||||
self.state = self.going_to_trapped_chest
|
||||
return
|
||||
self.bad_openings.add(opening_position)
|
||||
|
||||
self.trapped_chests.pop(0)
|
||||
time.sleep(0.1)
|
||||
@@ -148,12 +172,17 @@ class CacheItemsStates:
|
||||
self.area = area
|
||||
openings = w.find_cache_openings(self.area, p)
|
||||
|
||||
self.bad_openings = set()
|
||||
for opening in openings:
|
||||
navpath = w.path_to_place(p, opening['position'])
|
||||
opening_position = tuple(opening['position'])
|
||||
if self._opening_in_bad_region(w, opening_position):
|
||||
continue
|
||||
navpath = w.path_to_place(p, opening_position)
|
||||
if navpath:
|
||||
self.opening = opening['position']
|
||||
self.opening = opening_position
|
||||
self.open_interaction = opening
|
||||
break
|
||||
self.bad_openings.add(opening_position)
|
||||
else: # for
|
||||
print('Unable to get to cache area', self.area)
|
||||
self.bad_areas.append(self.area)
|
||||
|
||||
Reference in New Issue
Block a user