Skip to content

Commit

Permalink
bugfix: a unit would not enter a building if the order was given from…
Browse files Browse the repository at this point in the history
… another square
  • Loading branch information
soundmud committed Jun 25, 2023
1 parent d880d54 commit c5169cc
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 12 deletions.
38 changes: 38 additions & 0 deletions soundrts/tests/test_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from soundrts.mapfile import Map
from soundrts.world import World
from soundrts.worldclient import DummyClient

tiny_map_str = """
square_width 12
nb_columns 2
nb_lines 1
nb_meadows_by_square 9
west_east_paths a1
nb_players_min 1
nb_players_max 1
player 10 10 a1 guardtower b1 peasant
"""


def test_enter_building_from_another_square():
w = World()
w.load_and_build_map(Map.from_string(tiny_map_str))
w.populate_map([DummyClient()])
p = w.players[0]
tower, unit = p.units

unit.take_default_order(tower.id)
assert unit.orders
assert tower.orders

w.update()
assert not unit.orders[0].is_complete
assert tower.orders[0].is_complete

for _ in range(100):
w.update()
if unit.is_inside:
break
assert unit.is_inside
11 changes: 0 additions & 11 deletions soundrts/tests/unittests/test_worldunit.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from unittest.mock import Mock, call

from soundrts.world import World
from soundrts.worldplayerbase import Player
from soundrts.worldroom import Square, Inside
from soundrts.worldunit import Unit

Expand Down Expand Up @@ -80,12 +78,3 @@ def test_counterattack_if_defensive_mode():
unit.counterattack(place)

unit.take_order.assert_not_called()


# def test_load():
# world = World([])
# player = Player(world, Mock())
# square = Square(world, 1, 1, 12)
# unit = Unit(player, square, 0, 0)
# transport = Unit(player, square, 0, 0)
# transport.load(unit)
10 changes: 9 additions & 1 deletion soundrts/worldorders.py
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,11 @@ def execute(self):
self.unit.hold(self.target)
self.mark_as_complete()
elif self.unit._near_enough(self.target):
try:
if self.target.have_enough_space(self.unit):
self.target.load(self.unit)
except AttributeError:
pass
self.mark_as_complete()
elif self.unit.is_idle:
self.move_to_or_fail(self.target)
Expand Down Expand Up @@ -1186,7 +1191,10 @@ def execute(self):
else:
self.mark_as_impossible()
elif self.unit.place != self.target.place:
self.move_to_or_fail(self.target.place)
if self.unit.speed:
self.move_to_or_fail(self.target.place)
else:
self.mark_as_complete()
else:
self.mark_as_complete()
self.unit.load(self.target)
Expand Down

0 comments on commit c5169cc

Please sign in to comment.