2626#include " notifications/RoadNote.h"
2727#include " notifications/ShipNote.h"
2828#include " pathfinding/PathConditionRoad.h"
29+ #include " random/Random.h"
2930#include " nodeObjs/noAnimal.h"
3031#include " nodeObjs/noFlag.h"
3132#include " nodeObjs/noShip.h"
@@ -344,7 +345,7 @@ void AIPlayerJH::PlanNewBuildings(const unsigned gf)
344345 DistributeGoodsByBlocking (GoodType::Boards, 30 );
345346 DistributeGoodsByBlocking (GoodType::Stones, 50 );
346347 // go to the picked random warehouse and try to build around it
347- int randomStore = rand () % ( storehouses.size ());
348+ int randomStore = RANDOM. Rand ( RANDOM_CONTEXT2 (playerId), storehouses.size ());
348349 auto it = storehouses.begin ();
349350 std::advance (it, randomStore);
350351 const MapPoint whPos = (*it)->GetPos ();
@@ -365,7 +366,7 @@ void AIPlayerJH::PlanNewBuildings(const unsigned gf)
365366 const std::list<nobMilitary*>& militaryBuildings = aii.GetMilitaryBuildings ();
366367 if (militaryBuildings.empty ())
367368 return ;
368- int randomMiliBld = rand () % militaryBuildings.size ();
369+ int randomMiliBld = RANDOM. Rand ( RANDOM_CONTEXT2 (playerId), militaryBuildings.size () );
369370 auto it2 = militaryBuildings.begin ();
370371 std::advance (it2, randomMiliBld);
371372 MapPoint bldPos = (*it2)->GetPos ();
@@ -1209,7 +1210,7 @@ void AIPlayerJH::HandleExpedition(const noShip* ship)
12091210 aii.FoundColony (ship);
12101211 else
12111212 {
1212- const unsigned offset = rand () % helpers::MaxEnumValue_v<ShipDirection>;
1213+ const unsigned offset = RANDOM. Rand ( RANDOM_CONTEXT2 (playerId), helpers::MaxEnumValue_v<ShipDirection>) ;
12131214 for (auto dir : helpers::EnumRange<ShipDirection>{})
12141215 {
12151216 dir = ShipDirection ((rttr::enum_cast (dir) + offset) % helpers::MaxEnumValue_v<ShipDirection>);
@@ -1254,9 +1255,7 @@ void AIPlayerJH::HandleTreeChopped(const MapPoint pt)
12541255
12551256 UpdateNodesAround (pt, 3 );
12561257
1257- int random = rand ();
1258-
1259- if (random % 2 == 0 )
1258+ if (RANDOM.Rand (RANDOM_CONTEXT2 (playerId), 2 ) == 0 )
12601259 AddMilitaryBuildJob (pt);
12611260 else // if (random % 12 == 0)
12621261 AddBuildJob (BuildingType::Woodcutter, pt);
@@ -1538,7 +1537,7 @@ void AIPlayerJH::TryToAttack()
15381537 // We skip the current building with a probability of limit/numMilBlds
15391538 // -> For twice the number of blds as the limit we will most likely skip every 2nd building
15401539 // This way we check roughly (at most) limit buildings but avoid any preference for one building over an other
1541- if (rand () % numMilBlds > limit)
1540+ if (static_cast < unsigned >(RANDOM. Rand ( RANDOM_CONTEXT2 (playerId), static_cast < int >( numMilBlds))) > limit)
15421541 continue ;
15431542
15441543 if (milBld->GetFrontierDistance () == FrontierDistance::Far) // inland building? -> skip it
@@ -1571,7 +1570,7 @@ void AIPlayerJH::TryToAttack()
15711570
15721571 // shuffle everything but headquarters and harbors without any troops in them
15731572 std::shuffle (potentialTargets.begin () + hq_or_harbor_without_soldiers, potentialTargets.end (),
1574- std::mt19937 (std::random_device ()( )));
1573+ std::mt19937 (RANDOM. Rand ( RANDOM_CONTEXT2 (playerId), 2048 )));
15751574
15761575 // check for each potential attacking target the number of available attacking soldiers
15771576 for (const nobBaseMilitary* target : potentialTargets)
@@ -1704,7 +1703,10 @@ void AIPlayerJH::TrySeaAttack()
17041703 unsigned limit = 15 ;
17051704 unsigned skip = 0 ;
17061705 if (searcharoundharborspots.size () > 15 )
1707- skip = std::max<int >(rand () % (searcharoundharborspots.size () / 15 + 1 ) * 15 , 1 ) - 1 ;
1706+ skip =
1707+ std::max<int >(
1708+ RANDOM.Rand (RANDOM_CONTEXT2 (playerId), static_cast <int >(searcharoundharborspots.size () / 15 + 1 ) * 15 ), 1 )
1709+ - 1 ;
17081710 for (unsigned i = skip; i < searcharoundharborspots.size () && limit > 0 ; i++)
17091711 {
17101712 limit--;
0 commit comments