Fix order of grabbing supplies and checking barrels
This commit is contained in:
		
							
								
								
									
										1
									
								
								game.py
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								game.py
									
									
									
									
									
								
							| @@ -75,6 +75,7 @@ class MCWorld: | |||||||
|                 continue |                 continue | ||||||
|             if distance and utils.phyp(center, block) > distance: |             if distance and utils.phyp(center, block) > distance: | ||||||
|                 continue |                 continue | ||||||
|  |             if block not in result: | ||||||
|                 result.append(block) |                 result.append(block) | ||||||
|  |  | ||||||
|         result.sort(key=lambda x: utils.phyp(center, x)) |         result.sort(key=lambda x: utils.phyp(center, x)) | ||||||
|   | |||||||
							
								
								
									
										93
									
								
								jobs.py
									
									
									
									
									
								
							
							
						
						
									
										93
									
								
								jobs.py
									
									
									
									
									
								
							| @@ -743,7 +743,7 @@ class SleepWithBedStates: | |||||||
|  |  | ||||||
|         self.beds = [] |         self.beds = [] | ||||||
|         for bed in result: |         for bed in result: | ||||||
|             if bed not in self.beds and bed not in self.bad_beds: |             if bed not in self.bad_beds: | ||||||
|                 self.beds.append(bed) |                 self.beds.append(bed) | ||||||
|  |  | ||||||
|         print('Found:', self.beds) |         print('Found:', self.beds) | ||||||
| @@ -1121,6 +1121,8 @@ class GrabSuppliesStates: | |||||||
|         return None |         return None | ||||||
|  |  | ||||||
|     def init(self): |     def init(self): | ||||||
|  |         self.checked_barrels = [] | ||||||
|  |  | ||||||
|         if self.supplies: |         if self.supplies: | ||||||
|             self.state = self.check_supplies |             self.state = self.check_supplies | ||||||
|         else: |         else: | ||||||
| @@ -1128,33 +1130,22 @@ class GrabSuppliesStates: | |||||||
|             self.state = self.cleanup |             self.state = self.cleanup | ||||||
|  |  | ||||||
|     def check_supplies(self): |     def check_supplies(self): | ||||||
|          |         # check if we need to grab anything | ||||||
|         # TODO: only visit each barrel once |  | ||||||
|         # switch the supplies and barrels steps |  | ||||||
|  |  | ||||||
|         for items, limits in self.supplies.items(): |         for items, limits in self.supplies.items(): | ||||||
|             minimum, maximum = limits |             minimum, maximum = limits | ||||||
|             print('Checking items:', items) |             print('Checking items:', items) | ||||||
|             num_items = self.g.game.count_items(items) |             num_items = self.g.game.count_items(items) | ||||||
|             print('Have:', num_items) |             print('Have:', num_items) | ||||||
|  |  | ||||||
|             if items in self.checked_supplies: |  | ||||||
|                 print('Already checked, skipping') |  | ||||||
|                 continue |  | ||||||
|  |  | ||||||
|             if num_items >= minimum: |             if num_items >= minimum: | ||||||
|                 print('Have enough, skipping') |                 print('Have enough, skipping') | ||||||
|                 continue |                 continue | ||||||
|  |  | ||||||
|             self.target_items = items |             print('Need at least one item') | ||||||
|             self.checked_supplies.append(items) |  | ||||||
|             self.maximum_items = maximum |  | ||||||
|             self.count = 0 |  | ||||||
|             self.state = self.find_barrels |             self.state = self.find_barrels | ||||||
|             return |             return | ||||||
|  |  | ||||||
|         self.checked_supplies = [] |         print('Aborting, dont need any supplies') | ||||||
|         print('Aborting, don\'t need any more supplies') |  | ||||||
|         self.state = self.cleanup |         self.state = self.cleanup | ||||||
|  |  | ||||||
|     def find_barrels(self): |     def find_barrels(self): | ||||||
| @@ -1168,16 +1159,26 @@ class GrabSuppliesStates: | |||||||
|  |  | ||||||
|     def choose_barrel(self): |     def choose_barrel(self): | ||||||
|         print('Choosing a barrel...') |         print('Choosing a barrel...') | ||||||
|  |         for barrel in self.barrels: | ||||||
|  |             if barrel in self.checked_barrels: | ||||||
|  |                 continue | ||||||
|  |             if barrel in self.bad_barrels: | ||||||
|  |                 continue | ||||||
|  |  | ||||||
|  |             self.barrel = barrel | ||||||
|  |             self.state = self.path_to_barrel | ||||||
|  |             return | ||||||
|  |  | ||||||
|  |         print('No barrels') | ||||||
|  |         self.state = self.cleanup | ||||||
|  |  | ||||||
|  |     def path_to_barrel(self): | ||||||
|  |         print('Finding path to barrel') | ||||||
|         w = self.g.world |         w = self.g.world | ||||||
|         p = utils.pint(self.g.pos) |         p = utils.pint(self.g.pos) | ||||||
|         c = self.g.chunks |         c = self.g.chunks | ||||||
|  |  | ||||||
|         if not len(self.barrels): |         barrel = self.barrel | ||||||
|             print('No barrels') |  | ||||||
|             self.state = self.no_more_barrels |  | ||||||
|             return |  | ||||||
|  |  | ||||||
|         barrel = self.barrels[0] |  | ||||||
|  |  | ||||||
|         tmp = c.get_block_at(*barrel) |         tmp = c.get_block_at(*barrel) | ||||||
|         c.set_block_at(*barrel, blocks.AIR) |         c.set_block_at(*barrel, blocks.AIR) | ||||||
| @@ -1189,11 +1190,15 @@ class GrabSuppliesStates: | |||||||
|         if navpath: |         if navpath: | ||||||
|             self.g.path = navpath[:-1] |             self.g.path = navpath[:-1] | ||||||
|             self.opening = self.g.path[-1] |             self.opening = self.g.path[-1] | ||||||
|  |             self.checked_barrels.append(barrel) | ||||||
|             self.area = barrel |             self.area = barrel | ||||||
|             self.state = self.going_to_barrel |             self.state = self.going_to_barrel | ||||||
|  |             self.checked_supplies = [] | ||||||
|             return |             return | ||||||
|         else: |         else: | ||||||
|             self.barrels.pop(0) |             print('No path, blacklisting barrel') | ||||||
|  |             self.bad_barrels.append(barrel) | ||||||
|  |             self.state = self.choose_barrel | ||||||
|  |  | ||||||
|     def going_to_barrel(self): |     def going_to_barrel(self): | ||||||
|         if utils.pint(self.g.pos) == self.opening: |         if utils.pint(self.g.pos) == self.opening: | ||||||
| @@ -1207,11 +1212,38 @@ class GrabSuppliesStates: | |||||||
|         self.state = self.wait |         self.state = self.wait | ||||||
|  |  | ||||||
|     def wait(self): |     def wait(self): | ||||||
|         # wait for server to send us barrel contents |         # wait for server to send us inventory contents | ||||||
|         if self.wait_time > 0: |         if self.wait_time > 0: | ||||||
|             self.wait_time -= utils.TICK |             self.wait_time -= utils.TICK | ||||||
|         else: |         else: | ||||||
|  |             self.state = self.choose_items | ||||||
|  |  | ||||||
|  |     def choose_items(self): | ||||||
|  |         print('Selecting next item') | ||||||
|  |         for items, limits in self.supplies.items(): | ||||||
|  |             minimum, maximum = limits | ||||||
|  |             print('Checking items:', items) | ||||||
|  |             num_items = self.g.game.count_items(items) | ||||||
|  |             print('Have:', num_items) | ||||||
|  |  | ||||||
|  |             if num_items >= minimum: | ||||||
|  |                 print('Have enough, skipping') | ||||||
|  |                 continue | ||||||
|  |  | ||||||
|  |             if items in self.checked_supplies: | ||||||
|  |                 print('Already checked, skipping') | ||||||
|  |                 continue | ||||||
|  |  | ||||||
|  |             print('Need some') | ||||||
|  |             self.checked_supplies.append(items) | ||||||
|  |             self.target_items = items | ||||||
|  |             self.maximum_items = maximum | ||||||
|  |             self.count = 0 | ||||||
|             self.state = self.grab_items |             self.state = self.grab_items | ||||||
|  |             return | ||||||
|  |  | ||||||
|  |         print('Aborting, dont need any more supplies') | ||||||
|  |         self.state = self.close_barrel | ||||||
|  |  | ||||||
|     def grab_items(self): |     def grab_items(self): | ||||||
|         if self.g.item_lock: return |         if self.g.item_lock: return | ||||||
| @@ -1251,8 +1283,9 @@ class GrabSuppliesStates: | |||||||
|             self.g.game.click_window(slot_num, 0, 1, slot) |             self.g.game.click_window(slot_num, 0, 1, slot) | ||||||
|             return |             return | ||||||
|  |  | ||||||
|         print('Nothing left to move') |         print('None left to move') | ||||||
|         self.state = self.close_barrel |         self.wait_time = 0.25 | ||||||
|  |         self.state = self.wait | ||||||
|  |  | ||||||
|     def close_barrel(self): |     def close_barrel(self): | ||||||
|         print('Closing barrel') |         print('Closing barrel') | ||||||
| @@ -1261,9 +1294,6 @@ class GrabSuppliesStates: | |||||||
|         self.barrels.pop(0) |         self.barrels.pop(0) | ||||||
|         self.state = self.choose_barrel |         self.state = self.choose_barrel | ||||||
|  |  | ||||||
|     def no_more_barrels(self): |  | ||||||
|         self.state = self.check_supplies |  | ||||||
|  |  | ||||||
|     def cleanup(self): |     def cleanup(self): | ||||||
|         self.state = self.done |         self.state = self.done | ||||||
|  |  | ||||||
| @@ -1275,14 +1305,15 @@ class GrabSuppliesStates: | |||||||
|         self.g = global_state |         self.g = global_state | ||||||
|         self.state = self.idle |         self.state = self.idle | ||||||
|  |  | ||||||
|         self.checked_supplies = [] |  | ||||||
|         self.supplies = {} |         self.supplies = {} | ||||||
|         self.barrels = [] |         self.barrels = [] | ||||||
|  |         self.checked_barrels = [] | ||||||
|  |         self.bad_barrels = [] | ||||||
|  |         self.barrel = None | ||||||
|  |         self.checked_supplies = [] | ||||||
|         self.target_items = None |         self.target_items = None | ||||||
|         self.maximum_items = 0 |         self.maximum_items = 0 | ||||||
|         self.count = 0 |         self.count = 0 | ||||||
|  |  | ||||||
|         self.area = None |         self.area = None | ||||||
|         self.opening = None |         self.opening = None | ||||||
|         self.wait_time = 0 |         self.wait_time = 0 | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user