diff options
author | peterbell10 <peterbell10@live.co.uk> | 2017-06-13 21:35:30 +0200 |
---|---|---|
committer | Lukas Pioch <lukas@zgow.de> | 2017-06-13 21:35:30 +0200 |
commit | 360d8eade0332f2c1aa5c205ca772cd506c35b26 (patch) | |
tree | 066fde557310742a39020bad9bc4aa2a5ef8d51a /src/World.cpp | |
parent | Corrected check for level of subcommand and fixed multiple levels not working (#3758) (diff) | |
download | cuberite-360d8eade0332f2c1aa5c205ca772cd506c35b26.tar cuberite-360d8eade0332f2c1aa5c205ca772cd506c35b26.tar.gz cuberite-360d8eade0332f2c1aa5c205ca772cd506c35b26.tar.bz2 cuberite-360d8eade0332f2c1aa5c205ca772cd506c35b26.tar.lz cuberite-360d8eade0332f2c1aa5c205ca772cd506c35b26.tar.xz cuberite-360d8eade0332f2c1aa5c205ca772cd506c35b26.tar.zst cuberite-360d8eade0332f2c1aa5c205ca772cd506c35b26.zip |
Diffstat (limited to '')
-rw-r--r-- | src/World.cpp | 64 |
1 files changed, 36 insertions, 28 deletions
diff --git a/src/World.cpp b/src/World.cpp index f396aad86..0fa719670 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -245,22 +245,20 @@ void cWorld::CastThunderbolt (int a_BlockX, int a_BlockY, int a_BlockZ) int cWorld::GetDefaultWeatherInterval(eWeather a_Weather) { + auto & Random = GetRandomProvider(); switch (a_Weather) { case eWeather_Sunny: { - auto dif = m_MaxSunnyTicks - m_MinSunnyTicks + 1; - return m_MinSunnyTicks + (m_TickRand.randInt() % dif); + return Random.RandInt(m_MinSunnyTicks, m_MaxSunnyTicks); } case eWeather_Rain: { - auto dif = m_MaxRainTicks - m_MinRainTicks + 1; - return m_MinRainTicks + (m_TickRand.randInt() % dif); + return Random.RandInt(m_MinRainTicks, m_MaxRainTicks); } case eWeather_ThunderStorm: { - auto dif = m_MaxThunderStormTicks - m_MinThunderStormTicks + 1; - return m_MinThunderStormTicks + (m_TickRand.randInt() % dif); + return Random.RandInt(m_MinThunderStormTicks, m_MaxThunderStormTicks); } } @@ -812,7 +810,7 @@ eWeather cWorld::ChooseNewWeather() case eWeather_Rain: { // 1 / 8 chance of turning into a thunderstorm - return ((m_TickRand.randInt() % 256) < 32) ? eWeather_ThunderStorm : eWeather_Sunny; + return GetRandomProvider().RandBool(0.125) ? eWeather_ThunderStorm : eWeather_Sunny; } } @@ -1074,7 +1072,7 @@ void cWorld::TickWeather(float a_Dt) if (m_Weather == eWeather_ThunderStorm) { // 0.5% chance per tick of thunderbolt - if (m_TickRand.randInt() % 199 == 0) + if (GetRandomProvider().RandBool(0.005)) { CastThunderbolt(0, 0, 0); // TODO: find random positions near players to cast thunderbolts. } @@ -1697,7 +1695,7 @@ void cWorld::GrowTreeImage(const sSetBlockVector & a_Blocks) bool cWorld::GrowRipePlant(int a_BlockX, int a_BlockY, int a_BlockZ, bool a_IsByBonemeal) { - cFastRandom random; + auto & random = GetRandomProvider(); BLOCKTYPE BlockType; NIBBLETYPE BlockMeta; GetBlockTypeMeta(a_BlockX, a_BlockY, a_BlockZ, BlockType, BlockMeta); @@ -1735,7 +1733,7 @@ bool cWorld::GrowRipePlant(int a_BlockX, int a_BlockY, int a_BlockZ, bool a_IsBy } else { - BlockMeta += random.NextInt(4) + 2; + BlockMeta += random.RandInt(2, 5); BlockMeta = std::min(BlockMeta, static_cast<NIBBLETYPE>(7)); } FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, BlockType, BlockMeta); @@ -1770,7 +1768,7 @@ bool cWorld::GrowRipePlant(int a_BlockX, int a_BlockY, int a_BlockZ, bool a_IsBy } else { - BlockMeta += random.NextInt(4) + 2; + BlockMeta += random.RandInt(2, 5); BlockMeta = std::min(BlockMeta, static_cast<NIBBLETYPE>(7)); } FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, BlockType, BlockMeta); @@ -1793,7 +1791,7 @@ bool cWorld::GrowRipePlant(int a_BlockX, int a_BlockY, int a_BlockZ, bool a_IsBy } else { - BlockMeta += random.NextInt(4) + 2; + BlockMeta += random.RandInt(2, 5); BlockMeta = std::min(BlockMeta, static_cast<NIBBLETYPE>(7)); } FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, BlockType, BlockMeta); @@ -1825,7 +1823,7 @@ bool cWorld::GrowRipePlant(int a_BlockX, int a_BlockY, int a_BlockZ, bool a_IsBy } else { - BlockMeta += random.NextInt(4) + 2; + BlockMeta += random.RandInt(2, 5); BlockMeta = std::min(BlockMeta, static_cast<NIBBLETYPE>(7)); } FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, BlockType, BlockMeta); @@ -1848,7 +1846,7 @@ bool cWorld::GrowRipePlant(int a_BlockX, int a_BlockY, int a_BlockZ, bool a_IsBy } else { - BlockMeta += random.NextInt(4) + 2; + BlockMeta += random.RandInt(2, 5); BlockMeta = std::min(BlockMeta, static_cast<NIBBLETYPE>(7)); } FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, BlockType, BlockMeta); @@ -1884,14 +1882,14 @@ bool cWorld::GrowRipePlant(int a_BlockX, int a_BlockY, int a_BlockZ, bool a_IsBy { ++GrowState; } - else if (random.NextInt(99) < 45) + else if (random.RandBool(0.45)) { ++GrowState; } FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, BlockType, static_cast<NIBBLETYPE>(GrowState << 3 | TypeMeta)); } - else if (random.NextInt(99) < 45) + else if (random.RandBool(0.45)) { GrowTreeFromSapling(a_BlockX, a_BlockY, a_BlockZ, BlockMeta); } @@ -1905,12 +1903,12 @@ bool cWorld::GrowRipePlant(int a_BlockX, int a_BlockY, int a_BlockZ, bool a_IsBy { return false; } - MTRand r1; + auto & r1 = GetRandomProvider(); for (int i = 0; i < 60; i++) { - int OfsX = static_cast<int>(r1.randInt(3) + r1.randInt(3) + r1.randInt(3) + r1.randInt(3)) / 2 - 3; - int OfsY = static_cast<int>(r1.randInt(3) + r1.randInt(3)) - 3; - int OfsZ = static_cast<int>(r1.randInt(3) + r1.randInt(3) + r1.randInt(3) + r1.randInt(3)) / 2 - 3; + int OfsX = (r1.RandInt(3) + r1.RandInt(3) + r1.RandInt(3) + r1.RandInt(3)) / 2 - 3; + int OfsY = r1.RandInt(3) + r1.RandInt(3) - 3; + int OfsZ = (r1.RandInt(3) + r1.RandInt(3) + r1.RandInt(3) + r1.RandInt(3)) / 2 - 3; BLOCKTYPE Ground = GetBlock(a_BlockX + OfsX, a_BlockY + OfsY, a_BlockZ + OfsZ); if (Ground != E_BLOCK_GRASS) { @@ -1923,7 +1921,7 @@ bool cWorld::GrowRipePlant(int a_BlockX, int a_BlockY, int a_BlockZ, bool a_IsBy } BLOCKTYPE SpawnType; NIBBLETYPE SpawnMeta = 0; - switch (r1.randInt(10)) + switch (r1.RandInt(10)) { case 0: SpawnType = E_BLOCK_YELLOW_FLOWER; break; case 1: SpawnType = E_BLOCK_RED_ROSE; break; @@ -2031,8 +2029,7 @@ int cWorld::GrowCactus(int a_BlockX, int a_BlockY, int a_BlockZ, int a_NumBlocks bool cWorld::GrowMelonPumpkin(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType) { - MTRand Rand; - return m_ChunkMap->GrowMelonPumpkin(a_BlockX, a_BlockY, a_BlockZ, a_BlockType, Rand); + return m_ChunkMap->GrowMelonPumpkin(a_BlockX, a_BlockY, a_BlockZ, a_BlockType); } @@ -2162,6 +2159,7 @@ bool cWorld::WriteBlockArea(cBlockArea & a_Area, int a_MinBlockX, int a_MinBlock void cWorld::SpawnItemPickups(const cItems & a_Pickups, double a_BlockX, double a_BlockY, double a_BlockZ, double a_FlyAwaySpeed, bool IsPlayerCreated) { + auto & Random = GetRandomProvider(); a_FlyAwaySpeed /= 100; // Pre-divide, so that we don't have to divide each time inside the loop for (cItems::const_iterator itr = a_Pickups.begin(); itr != a_Pickups.end(); ++itr) { @@ -2171,9 +2169,9 @@ void cWorld::SpawnItemPickups(const cItems & a_Pickups, double a_BlockX, double continue; } - float SpeedX = static_cast<float>(a_FlyAwaySpeed * (GetTickRandomNumber(10) - 5)); - float SpeedY = static_cast<float>(a_FlyAwaySpeed * GetTickRandomNumber(50)); - float SpeedZ = static_cast<float>(a_FlyAwaySpeed * (GetTickRandomNumber(10) - 5)); + float SpeedX = static_cast<float>(a_FlyAwaySpeed * Random.RandInt(-5, 5)); + float SpeedY = static_cast<float>(a_FlyAwaySpeed * Random.RandInt(50)); + float SpeedZ = static_cast<float>(a_FlyAwaySpeed * Random.RandInt(-5, 5)); cPickup * Pickup = new cPickup( a_BlockX, a_BlockY, a_BlockZ, @@ -2310,10 +2308,11 @@ UInt32 cWorld::SpawnPrimedTNT(double a_X, double a_Y, double a_Z, int a_FuseTick TNT = nullptr; return cEntity::INVALID_ID; } + auto & Random = GetRandomProvider(); TNT->SetSpeed( - a_InitialVelocityCoeff * (GetTickRandomNumber(2) - 1), /** -1, 0, 1 */ + a_InitialVelocityCoeff * Random.RandInt(-1, 1), a_InitialVelocityCoeff * 2, - a_InitialVelocityCoeff * (GetTickRandomNumber(2) - 1) + a_InitialVelocityCoeff * Random.RandInt(-1, 1) ); return TNT->GetUniqueID(); } @@ -3793,6 +3792,15 @@ UInt32 cWorld::CreateProjectile(double a_PosX, double a_PosY, double a_PosZ, cPr +int cWorld::GetTickRandomNumber(int a_Range) +{ + return GetRandomProvider().RandInt(a_Range); +} + + + + + void cWorld::TabCompleteUserName(const AString & a_Text, AStringVector & a_Results) { typedef std::pair<AString::size_type, AString> pair_t; |