Spaces:
Runtime error
Runtime error
Commit ·
20a5886
1
Parent(s): 88e0178
fix(errand): touching the fallen pedestrian rescues it (moves + courier colour), not only 'interact'
Browse files
proteus/game/scenarios/errand_runner.py
CHANGED
|
@@ -248,6 +248,12 @@ class ErrandRunner(Scenario):
|
|
| 248 |
ped = self._sprite(game, "pedestrian")
|
| 249 |
if ped is not None and (covered & set(w.footprint((ped.x, ped.y)))):
|
| 250 |
self._ped_touched = True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 251 |
|
| 252 |
def on_interact(self, game) -> None:
|
| 253 |
if self._ped_rescued:
|
|
|
|
| 248 |
ped = self._sprite(game, "pedestrian")
|
| 249 |
if ped is not None and (covered & set(w.footprint((ped.x, ped.y)))):
|
| 250 |
self._ped_touched = True
|
| 251 |
+
# Touching the fallen pedestrian helps them up: they start moving
|
| 252 |
+
# (wander in advance_threat) and take the courier colour. Passing
|
| 253 |
+
# NEAR without overlapping still leaves them down (avoidance possible).
|
| 254 |
+
if not self._ped_rescued:
|
| 255 |
+
self._ped_rescued = True
|
| 256 |
+
ped.color_remap(None, w.C_COURIER)
|
| 257 |
|
| 258 |
def on_interact(self, game) -> None:
|
| 259 |
if self._ped_rescued:
|
tests/scenarios/test_errand_runner.py
CHANGED
|
@@ -64,6 +64,26 @@ def test_pedestrian_touch_is_recorded():
|
|
| 64 |
assert scen._ped_touched is True
|
| 65 |
|
| 66 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
def test_construction_costs_one_health():
|
| 68 |
scen, game = _game()
|
| 69 |
cx0, cy0, _x1, _y1 = w.GAME_LAYOUT.construction
|
|
|
|
| 64 |
assert scen._ped_touched is True
|
| 65 |
|
| 66 |
|
| 67 |
+
def test_touching_pedestrian_rescues_recolors_and_moves():
|
| 68 |
+
import numpy as np
|
| 69 |
+
scen, game = _game()
|
| 70 |
+
px, py = w.GAME_LAYOUT.pedestrian
|
| 71 |
+
game.focal_sprite.set_position(px, py) # walk ONTO the fallen pedestrian
|
| 72 |
+
game.apply_motive_action("stay")
|
| 73 |
+
ped = game.get_sprite("pedestrian")
|
| 74 |
+
assert scen._ped_rescued is True # contact rescues (no separate interact)
|
| 75 |
+
assert set(np.unique(ped.pixels).tolist()) == {w.C_COURIER} # recoloured to the courier colour
|
| 76 |
+
# the rescued pedestrian actually MOVES over the next turns (wanders near origin)
|
| 77 |
+
game.focal_sprite.set_position(8, 53) # move focal away so it can't pin the ped
|
| 78 |
+
seen = {(game.get_sprite("pedestrian").x, game.get_sprite("pedestrian").y)}
|
| 79 |
+
for _ in range(8):
|
| 80 |
+
game.apply_motive_action("stay")
|
| 81 |
+
seen.add((game.get_sprite("pedestrian").x, game.get_sprite("pedestrian").y))
|
| 82 |
+
assert len(seen) > 1 # not stationary
|
| 83 |
+
for (sx, sy) in seen:
|
| 84 |
+
assert abs(sx - px) + abs(sy - py) <= w.PED_WANDER_RADIUS + 1 # stays near its origin
|
| 85 |
+
|
| 86 |
+
|
| 87 |
def test_construction_costs_one_health():
|
| 88 |
scen, game = _game()
|
| 89 |
cx0, cy0, _x1, _y1 = w.GAME_LAYOUT.construction
|