1111#include " RttrForeachPt.h"
1212#include " addons/const_addons.h"
1313#include " ai/AIEvents.h"
14+ #include " ai/random.h"
1415#include " boost/filesystem/fstream.hpp"
1516#include " buildings/noBuildingSite.h"
1617#include " buildings/nobHarborBuilding.h"
2627#include " notifications/RoadNote.h"
2728#include " notifications/ShipNote.h"
2829#include " pathfinding/PathConditionRoad.h"
29- #include " random/Random.h"
3030#include " nodeObjs/noAnimal.h"
3131#include " nodeObjs/noFlag.h"
3232#include " nodeObjs/noShip.h"
4040#include < algorithm>
4141#include < array>
4242#include < memory>
43- #include < random>
4443#include < stdexcept>
4544#include < type_traits>
4645
@@ -345,7 +344,7 @@ void AIPlayerJH::PlanNewBuildings(const unsigned gf)
345344 DistributeGoodsByBlocking (GoodType::Boards, 30 );
346345 DistributeGoodsByBlocking (GoodType::Stones, 50 );
347346 // go to the picked random warehouse and try to build around it
348- int randomStore = RANDOM. Rand ( RANDOM_CONTEXT2 (playerId) , storehouses.size ());
347+ int randomStore = AI::randomValue< int >( 0 , storehouses.size ());
349348 auto it = storehouses.begin ();
350349 std::advance (it, randomStore);
351350 const MapPoint whPos = (*it)->GetPos ();
@@ -366,7 +365,7 @@ void AIPlayerJH::PlanNewBuildings(const unsigned gf)
366365 const std::list<nobMilitary*>& militaryBuildings = aii.GetMilitaryBuildings ();
367366 if (militaryBuildings.empty ())
368367 return ;
369- int randomMiliBld = RANDOM. Rand ( RANDOM_CONTEXT2 (playerId) , militaryBuildings.size ());
368+ int randomMiliBld = AI::randomValue< int >( 0 , militaryBuildings.size ());
370369 auto it2 = militaryBuildings.begin ();
371370 std::advance (it2, randomMiliBld);
372371 MapPoint bldPos = (*it2)->GetPos ();
@@ -1210,7 +1209,7 @@ void AIPlayerJH::HandleExpedition(const noShip* ship)
12101209 aii.FoundColony (ship);
12111210 else
12121211 {
1213- const unsigned offset = RANDOM. Rand ( RANDOM_CONTEXT2 (playerId) , helpers::MaxEnumValue_v<ShipDirection>);
1212+ const unsigned offset = AI::randomValue< unsigned >( 0 , helpers::MaxEnumValue_v<ShipDirection>);
12141213 for (auto dir : helpers::EnumRange<ShipDirection>{})
12151214 {
12161215 dir = ShipDirection ((rttr::enum_cast (dir) + offset) % helpers::MaxEnumValue_v<ShipDirection>);
@@ -1255,7 +1254,7 @@ void AIPlayerJH::HandleTreeChopped(const MapPoint pt)
12551254
12561255 UpdateNodesAround (pt, 3 );
12571256
1258- if (RANDOM. Rand ( RANDOM_CONTEXT2 (playerId) , 2 ) == 0 )
1257+ if (AI::randomValue< int >( 0 , 2 ) == 0 )
12591258 AddMilitaryBuildJob (pt);
12601259 else // if (random % 12 == 0)
12611260 AddBuildJob (BuildingType::Woodcutter, pt);
@@ -1537,7 +1536,7 @@ void AIPlayerJH::TryToAttack()
15371536 // We skip the current building with a probability of limit/numMilBlds
15381537 // -> For twice the number of blds as the limit we will most likely skip every 2nd building
15391538 // This way we check roughly (at most) limit buildings but avoid any preference for one building over an other
1540- if (static_cast <unsigned >(RANDOM. Rand ( RANDOM_CONTEXT2 (playerId), static_cast < int >( numMilBlds)) ) > limit)
1539+ if (AI::randomValue <unsigned >(0 , numMilBlds) > limit)
15411540 continue ;
15421541
15431542 if (milBld->GetFrontierDistance () == FrontierDistance::Far) // inland building? -> skip it
@@ -1570,7 +1569,7 @@ void AIPlayerJH::TryToAttack()
15701569
15711570 // shuffle everything but headquarters and harbors without any troops in them
15721571 std::shuffle (potentialTargets.begin () + hq_or_harbor_without_soldiers, potentialTargets.end (),
1573- std::mt19937 (RANDOM. Rand ( RANDOM_CONTEXT2 (playerId) , 2048 )));
1572+ std::mt19937 (AI::randomValue< unsigned >( 0 , 2048 )));
15741573
15751574 // check for each potential attacking target the number of available attacking soldiers
15761575 for (const nobBaseMilitary* target : potentialTargets)
@@ -1704,9 +1703,7 @@ void AIPlayerJH::TrySeaAttack()
17041703 unsigned skip = 0 ;
17051704 if (searcharoundharborspots.size () > 15 )
17061705 skip =
1707- std::max<int >(
1708- RANDOM.Rand (RANDOM_CONTEXT2 (playerId), static_cast <int >(searcharoundharborspots.size () / 15 + 1 ) * 15 ), 1 )
1709- - 1 ;
1706+ std::max<int >(AI::randomValue<int >(0 , static_cast <int >(searcharoundharborspots.size () / 15 + 1 ) * 15 ), 1 ) - 1 ;
17101707 for (unsigned i = skip; i < searcharoundharborspots.size () && limit > 0 ; i++)
17111708 {
17121709 limit--;
0 commit comments