Add 3D BFS iterator
This commit is contained in:
@@ -385,20 +385,16 @@ class SleepWithBedStates:
|
||||
w = self.g.world
|
||||
p = utils.pint(self.g.pos)
|
||||
|
||||
areas = w.find_bed_areas(p, 100)
|
||||
print('Found areas:', areas)
|
||||
|
||||
if len(areas):
|
||||
while areas[0] in self.bad_areas:
|
||||
areas.pop(0)
|
||||
self.area = areas[0]
|
||||
elif self.last_area:
|
||||
self.area = self.last_area
|
||||
else:
|
||||
print('Unable to find area, and no last area')
|
||||
for area in w.find_bed_areas(p, 100):
|
||||
print('Found area:', area)
|
||||
if area not in self.bad_areas:
|
||||
break
|
||||
else: # for
|
||||
print('Unable to find area')
|
||||
self.state = self.cleanup
|
||||
return
|
||||
|
||||
self.area = area
|
||||
openings = w.find_bed_openings(self.area)
|
||||
|
||||
for o in openings:
|
||||
@@ -413,7 +409,6 @@ class SleepWithBedStates:
|
||||
|
||||
self.g.path = navpath
|
||||
self.state = self.going_to_area
|
||||
self.last_area = self.area
|
||||
|
||||
def going_to_area(self):
|
||||
if utils.pint(self.g.pos) == self.opening:
|
||||
@@ -479,7 +474,6 @@ class SleepWithBedStates:
|
||||
self.area = None
|
||||
self.opening = None
|
||||
self.bad_areas = []
|
||||
self.last_area = None
|
||||
self.wait_time = 0
|
||||
|
||||
def run(self):
|
||||
@@ -491,8 +485,11 @@ class CacheItemsStates:
|
||||
return None
|
||||
|
||||
def init(self):
|
||||
self.skip_slots = []
|
||||
self.skip_items = []
|
||||
|
||||
num_stacks = len([x for x in self.g.inv.values() if x.present])
|
||||
print('inventory amount:', num_stacks)
|
||||
print('Inventory amount:', num_stacks)
|
||||
if num_stacks >= 27:
|
||||
self.state = self.find_cache_spot
|
||||
else:
|
||||
@@ -504,20 +501,16 @@ class CacheItemsStates:
|
||||
w = self.g.world
|
||||
p = utils.pint(self.g.pos)
|
||||
|
||||
areas = w.find_cache_areas(p, 100)
|
||||
print('Found areas:', areas)
|
||||
|
||||
if len(areas):
|
||||
while areas[0] in self.bad_areas:
|
||||
areas.pop(0)
|
||||
self.area = areas[0]
|
||||
elif self.last_area:
|
||||
self.area = self.last_area
|
||||
else:
|
||||
print('Unable to find area, and no last area')
|
||||
for area in w.find_cache_areas(p, 100):
|
||||
print('Found area:', area)
|
||||
if area not in self.bad_areas:
|
||||
break
|
||||
else: # for
|
||||
print('Unable to find area')
|
||||
self.state = self.cleanup
|
||||
return
|
||||
|
||||
self.area = area
|
||||
openings = w.find_cache_openings(self.area)
|
||||
|
||||
for o in openings:
|
||||
@@ -532,7 +525,6 @@ class CacheItemsStates:
|
||||
|
||||
self.g.path = navpath
|
||||
self.state = self.going_to_area
|
||||
self.last_area = self.area
|
||||
|
||||
def going_to_area(self):
|
||||
if utils.pint(self.g.pos) == self.opening:
|
||||
@@ -571,6 +563,8 @@ class CacheItemsStates:
|
||||
w_info = data.WINDOWS[w.data.window_type]
|
||||
w_inventory_slots = w_info.inventory
|
||||
|
||||
slot_list = []
|
||||
|
||||
for slot_num in w_inventory_slots:
|
||||
if slot_num not in w.contents:
|
||||
continue
|
||||
@@ -580,14 +574,25 @@ class CacheItemsStates:
|
||||
if not slot.present:
|
||||
continue
|
||||
|
||||
if slot.item_id in items.USEFUL_ITEMS:
|
||||
if slot.item_id in self.needed_items:
|
||||
continue
|
||||
|
||||
if slot_num in self.skip_slots:
|
||||
continue
|
||||
|
||||
slot_list.append((slot_num, slot))
|
||||
|
||||
slot_list.sort(key=lambda x: x[1].item_count, reverse=True)
|
||||
|
||||
for slot_num, slot in slot_list:
|
||||
if slot.item_id in self.wanted_items and slot.item_id not in self.skip_items:
|
||||
print('skipping wanted item', slot)
|
||||
self.skip_slots.append(slot_num)
|
||||
self.skip_items.append(slot.item_id)
|
||||
continue
|
||||
|
||||
print('moving', slot)
|
||||
|
||||
#inv_slot_num = slot_num - w_info.slot_diff
|
||||
#self.g.inv.pop(inv_slot_num, None)
|
||||
|
||||
self.g.item_lock = True
|
||||
self.g.game.click_window(slot_num, 0, 1, slot)
|
||||
return
|
||||
@@ -613,10 +618,17 @@ class CacheItemsStates:
|
||||
self.g = global_state
|
||||
self.state = self.idle
|
||||
|
||||
# keep all needed items
|
||||
self.needed_items = items.NEEDED_ITEMS
|
||||
# keep one stack of wanted items
|
||||
self.wanted_items = items.WANTED_ITEMS
|
||||
|
||||
self.skip_slots = []
|
||||
self.skip_items = []
|
||||
|
||||
self.area = None
|
||||
self.opening = None
|
||||
self.bad_areas = []
|
||||
self.last_area = None
|
||||
self.wait_time = 0
|
||||
|
||||
def run(self):
|
||||
@@ -681,19 +693,16 @@ class PlantTreeStates:
|
||||
w = self.g.world
|
||||
p = utils.pint(self.g.pos)
|
||||
|
||||
areas = w.find_cache_areas(p, 20)
|
||||
print('Found areas:', areas)
|
||||
|
||||
try:
|
||||
while areas[0] in self.bad_areas:
|
||||
areas.pop(0)
|
||||
self.area = areas[0]
|
||||
except IndexError:
|
||||
print('No good areas left, aborting.')
|
||||
self.bad_areas = []
|
||||
for area in w.find_cache_areas(p, 20):
|
||||
print('Found area:', area)
|
||||
if area not in self.bad_areas:
|
||||
break
|
||||
else: # for
|
||||
print('Unable to find area')
|
||||
self.state = self.cleanup
|
||||
return
|
||||
|
||||
self.area = area
|
||||
navpath = w.path_to_place(p, self.area)
|
||||
|
||||
if not navpath:
|
||||
@@ -803,6 +812,16 @@ class JobStates:
|
||||
def idle(self):
|
||||
return None
|
||||
|
||||
def cache_items(self):
|
||||
s1 = self.cache_items_states
|
||||
|
||||
if s1.state == s1.idle:
|
||||
s1.state = s1.init
|
||||
elif s1.state == s1.done:
|
||||
self.state = self.idle
|
||||
|
||||
s1.run()
|
||||
|
||||
def find_gapple(self):
|
||||
s1 = self.find_gapple_states
|
||||
|
||||
|
||||
Reference in New Issue
Block a user