@@ -40,20 +40,6 @@ struct UninitializedWorldCreator
4040 bool operator ()(GameWorldBase&) { return true ; }
4141};
4242
43- struct LoadWorldFromFileCreator : MapTestFixture
44- {
45- std::vector<MapPoint> hqs;
46-
47- explicit LoadWorldFromFileCreator (MapExtent) {}
48- bool operator ()(GameWorldBase& world)
49- {
50- MapLoader loader (world);
51- BOOST_TEST_REQUIRE (loader.Load (testMapPath));
52- for (unsigned i = 0 ; i < world.GetNumPlayers (); i++)
53- hqs.push_back (loader.GetHQPos (i));
54- return true ;
55- }
56- };
5743struct LoadWorldAndS2MapCreator : MapTestFixture
5844{
5945 libsiedler2::ArchivItem_Map map;
@@ -72,7 +58,6 @@ struct LoadWorldAndS2MapCreator : MapTestFixture
7258};
7359
7460using WorldLoadedWithS2MapFixture = WorldFixture<LoadWorldAndS2MapCreator>;
75- using WorldLoaded1PFixture = WorldFixture<LoadWorldFromFileCreator, 1 >;
7661using WorldFixtureEmpty1P = WorldFixture<CreateEmptyWorld, 1 >;
7762} // namespace
7863
@@ -133,12 +118,52 @@ BOOST_FIXTURE_TEST_CASE(SameBQasInS2, WorldLoadedWithS2MapFixture)
133118 }
134119}
135120
136- BOOST_FIXTURE_TEST_CASE (HQPlacement, WorldLoaded1PFixture )
121+ BOOST_AUTO_TEST_CASE (HQPlacement)
137122{
138- GamePlayer& player = world.GetPlayer (0 );
139- BOOST_TEST_REQUIRE (player.isUsed ());
140- BOOST_TEST_REQUIRE (worldCreator.hqs [0 ].isValid ());
141- BOOST_TEST_REQUIRE (world.GetNO (worldCreator.hqs [0 ])->GetGOT () == GO_Type::NobHq);
123+ constexpr auto numPlayers = 4u ;
124+
125+ std::vector<MapPoint> hqsOriginalMap, hqsShuffledMap, hqsOriginalWorld, hqsShuffledWorld;
126+ for (const bool randStartPos : {false , true })
127+ {
128+ BOOST_TEST_INFO_SCOPE (" Random: " << randStartPos);
129+ WorldFixtureBase fixture (numPlayers);
130+ fixture.ggs .randomStartPosition = randStartPos;
131+ auto & world = fixture.world ;
132+ MapLoader loader (world);
133+ BOOST_TEST_REQUIRE (loader.Load (testMapPath));
134+ auto & hqsMap = randStartPos ? hqsShuffledMap : hqsOriginalMap;
135+ auto & hqsWorld = randStartPos ? hqsShuffledWorld : hqsOriginalWorld;
136+ hqsWorld.resize (world.GetNumPlayers ());
137+ for (unsigned i = 0 ; i < world.GetNumPlayers (); i++)
138+ {
139+ BOOST_TEST_INFO_SCOPE (" Player: " << i);
140+ GamePlayer& player = world.GetPlayer (i);
141+ BOOST_TEST_REQUIRE (player.isUsed ());
142+
143+ auto hqPos = loader.GetOriginalHQPos (i);
144+ BOOST_TEST_REQUIRE (hqPos.isValid ());
145+ BOOST_TEST (!helpers::contains (hqsMap, hqPos)); // Unique position
146+ hqsMap.push_back (hqPos);
147+ BOOST_TEST (world.GetNO (hqPos)->GetGOT () == GO_Type::NobHq);
148+
149+ hqPos = world.GetPlayer (i).GetHQPos ();
150+ BOOST_TEST_REQUIRE (hqPos.isValid ());
151+ BOOST_TEST (!helpers::contains (hqsWorld, hqPos)); // Unique position
152+ hqsWorld[i] = hqPos;
153+ }
154+ }
155+ BOOST_TEST (hqsOriginalMap.size () == numPlayers);
156+ BOOST_TEST (hqsShuffledMap.size () == numPlayers);
157+ // The loader stores the HQ positions read from the map
158+ BOOST_TEST (hqsShuffledMap == hqsOriginalMap);
159+ // When shuffled the positions should have changed
160+ BOOST_TEST (hqsShuffledWorld != hqsOriginalWorld);
161+ helpers::sort (hqsOriginalMap, MapPointLess{});
162+ helpers::sort (hqsShuffledWorld, MapPointLess{});
163+ helpers::sort (hqsOriginalWorld, MapPointLess{});
164+ // But the same positions should be used just in different order
165+ BOOST_TEST (hqsOriginalMap == hqsOriginalWorld);
166+ BOOST_TEST (hqsShuffledWorld == hqsOriginalWorld);
142167}
143168
144169BOOST_FIXTURE_TEST_CASE (CloseHarborSpots, WorldFixture<UninitializedWorldCreator>)
0 commit comments