Port sand gathering to 26.3
This commit is contained in:
1 parent
f28269f71c
commit
3e8b95c895
9 files changed
+424
-158
No files matched your search
+33
-6
@@ -160,6 +160,31 @@ class World:
|
||||
center, directive['position']))
|
||||
return result
|
||||
|
||||
def find_sand_origins(self, center, bot_name, distance=200):
|
||||
"""Find signs addressed to this bot that designate a sand origin."""
|
||||
bot_name = str(bot_name).casefold()
|
||||
group_name = (bot_name[:-1] if len(bot_name) > 1 and
|
||||
bot_name[-1] in '123' else None)
|
||||
addresses = {bot_name}
|
||||
if group_name:
|
||||
addresses.add(group_name)
|
||||
|
||||
result = []
|
||||
for sign in self.find_signs(center, distance):
|
||||
text = ' '.join(
|
||||
line for line in sign['lines'] if line.strip()).casefold()
|
||||
tokens = re.findall(r'[a-z0-9_]+', text)
|
||||
if (len(tokens) < 3 or tokens[0] not in addresses or
|
||||
tokens[1:3] != ['sand', 'origin']):
|
||||
continue
|
||||
result.append({
|
||||
'position': tuple(sign['position']),
|
||||
'side': sign['side'],
|
||||
'lines': sign['lines'],
|
||||
})
|
||||
result.sort(key=lambda sign: utils.phyp(center, sign['position']))
|
||||
return result
|
||||
|
||||
def find_safety_signs(self, center, bot_name, distance=80):
|
||||
"""Find nearby signs addressed to this bot that mark safe refuges."""
|
||||
bot_name = str(bot_name).casefold()
|
||||
@@ -790,7 +815,7 @@ class World:
|
||||
return safe_sand
|
||||
|
||||
def check_sand_slice(self, center):
|
||||
# checks if a 5x5x1 slice has sand in it
|
||||
# Check whether a 3x3x1 sand section contains a safe block.
|
||||
for i in range(9):
|
||||
s = utils.padd(center, utils.spiral(i))
|
||||
if self.block_at(*s) != blocks.SAND:
|
||||
@@ -810,11 +835,13 @@ class World:
|
||||
|
||||
return False
|
||||
|
||||
def find_sand_slice(self, center, distance, y_limit=0, bad_slices=[], prev_layer=0):
|
||||
# returns the centre coord of the next 5x5x1 slice that still has
|
||||
# diggable sand in it. lower slices are only valid if there's an
|
||||
# adjacent slice farther at the same level. this should ensure an
|
||||
# upside down pyramid gets excavated so the edges are still climbable
|
||||
def find_sand_slice(self, center, distance, y_limit=0,
|
||||
bad_slices=None, prev_layer=0):
|
||||
# Return the centre of the next 3x3x1 section with diggable sand.
|
||||
# Lower slices are only valid if there's an adjacent slice farther at
|
||||
# the same level. This keeps the excavation edges climbable.
|
||||
if bad_slices is None:
|
||||
bad_slices = ()
|
||||
for v in count(prev_layer):
|
||||
peak = utils.padd(center, (0, 10-v, 0))
|
||||
|
||||
|
||||
Reference in new issue
Block a user