@@ -860,4 +860,38 @@ BOOST_FIXTURE_TEST_CASE(SinkShipLoosesCargo, ShipAndHarborsReadyFixture<1>)
860860 BOOST_TEST (player.GetInventory ()[Job::Woodcutter] == numWoodcutters - 1 );
861861}
862862
863+ BOOST_FIXTURE_TEST_CASE (RemoveShipsOnDefeat, ShipAndHarborsReadyFixture<2 >)
864+ {
865+ const GamePlayer& player = world.GetPlayer (curPlayer);
866+ const noShip& ship = *player.GetShipByID (0 );
867+
868+ const auto & harbors = player.GetBuildingRegister ().GetHarbors ();
869+ BOOST_TEST_REQUIRE (harbors.size () >= 2u );
870+ nobHarborBuilding& harbor1 = *harbors.front ();
871+ nobHarborBuilding& harbor2 = **(++harbors.begin ());
872+
873+ // Transport something
874+ BOOST_TEST_REQUIRE (harbor1.OrderJob (Job::Woodcutter, harbor2, false ));
875+ BOOST_TEST_REQUIRE (harbor1.OrderWare (GoodType::Wood, harbor2));
876+
877+ RTTR_EXEC_TILL (90 , ship.IsLoading ());
878+ RTTR_EXEC_TILL (200 , ship.IsMoving ());
879+ const auto numWood = ship.GetWares ().size ();
880+ const auto numWoodcutters = ship.GetFigures ().size ();
881+ BOOST_TEST (numWood == 1u );
882+ BOOST_TEST (numWoodcutters == 1u );
883+
884+ const auto shipPos = ship.GetPos ();
885+ BOOST_TEST_REQUIRE (player.GetNumShips () == 1u );
886+ BOOST_TEST_REQUIRE (world.GetFigures (shipPos).size () == 1u );
887+ BOOST_TEST_REQUIRE (dynamic_cast <noShip*>(&world.GetFigures (shipPos).front ()));
888+ const auto warehouses = player.GetBuildingRegister ().GetStorehouses (); // Copy for iteration
889+ for (const auto * bld : warehouses)
890+ world.DestroyBuilding (bld->GetPos (), curPlayer);
891+ RTTR_SKIP_GFS (1 ); // Handle delayed destruction
892+ BOOST_TEST (player.IsDefeated ());
893+ BOOST_TEST (player.GetNumShips () == 0u );
894+ BOOST_TEST (world.GetFigures (shipPos).size () == 0u );
895+ }
896+
863897BOOST_AUTO_TEST_SUITE_END ()
0 commit comments