Move to new sign-based threat refuge system
This commit is contained in:
1 parent
038fc503f0
commit
586772cb3b
6 files changed
+418
-195
No files matched your search
+58
-1
@@ -159,6 +159,64 @@ class World:
|
||||
center, directive['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()
|
||||
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):
|
||||
lines = [line.strip() for line in sign['lines'] if line.strip()]
|
||||
if not lines:
|
||||
continue
|
||||
tokens = re.findall(r'[a-z0-9_]+', ' '.join(lines).casefold())
|
||||
if (len(tokens) < 2 or tokens[0] not in addresses or
|
||||
not {'safety', 'refuge'}.intersection(tokens[1:])):
|
||||
continue
|
||||
state_id = self.block_at(*sign['position'])
|
||||
result.append({
|
||||
'position': tuple(sign['position']),
|
||||
'side': sign['side'],
|
||||
'lines': sign['lines'],
|
||||
'normal': self._sign_text_normal(sign, state_id),
|
||||
})
|
||||
result.sort(key=lambda sign: utils.phyp(center, sign['position']))
|
||||
return result
|
||||
|
||||
def find_safety_openings(self, sign, radius=3):
|
||||
"""Return standable positions near a trusted refuge sign, front first."""
|
||||
sign_pos = tuple(sign['position'])
|
||||
normal_x, _, normal_z = sign['normal']
|
||||
if abs(normal_x) >= abs(normal_z):
|
||||
front = (1 if normal_x >= 0 else -1, 0, 0)
|
||||
else:
|
||||
front = (0, 0, 1 if normal_z >= 0 else -1)
|
||||
directions = (
|
||||
front,
|
||||
(front[2], 0, -front[0]),
|
||||
(-front[2], 0, front[0]),
|
||||
(-front[0], 0, -front[2]),
|
||||
)
|
||||
candidates = []
|
||||
for direction_rank, direction in enumerate(directions):
|
||||
for distance in range(1, radius + 1):
|
||||
for dy in (0, -1, 1):
|
||||
if utils.hypot(distance, dy) > radius:
|
||||
continue
|
||||
offset = tuple(component * distance
|
||||
for component in direction)
|
||||
position = utils.padd(
|
||||
sign_pos, (offset[0], dy, offset[2]))
|
||||
if self._cache_opening_standable(position):
|
||||
candidates.append((
|
||||
direction_rank, distance, abs(dy), position))
|
||||
candidates.sort()
|
||||
return [candidate[3] for candidate in candidates]
|
||||
|
||||
def find_throw_openings(self, sign, center, radius=3):
|
||||
"""Find standable, visible throw positions within radius of a sign."""
|
||||
sign_pos = tuple(sign['position'])
|
||||
@@ -366,7 +424,6 @@ class World:
|
||||
support_machines = (
|
||||
'grab_supplies_states', 'sleep_with_bed_states',
|
||||
'eat_food_states', 'cache_items_states',
|
||||
'check_threats_states',
|
||||
)
|
||||
if any(machine is getattr(job, name, None)
|
||||
for name in support_machines):
|
||||
|
||||
Reference in new issue
Block a user