From 360d8eade0332f2c1aa5c205ca772cd506c35b26 Mon Sep 17 00:00:00 2001 From: peterbell10 Date: Tue, 13 Jun 2017 20:35:30 +0100 Subject: FastRandom rewrite (#3754) --- src/Blocks/BlockCrops.h | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'src/Blocks/BlockCrops.h') diff --git a/src/Blocks/BlockCrops.h b/src/Blocks/BlockCrops.h index 5ca264774..378505430 100644 --- a/src/Blocks/BlockCrops.h +++ b/src/Blocks/BlockCrops.h @@ -26,7 +26,7 @@ public: virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_Meta) override { - cFastRandom rand; + auto & rand = GetRandomProvider(); // If not fully grown, drop the "seed" of whatever is growing: if (a_Meta < RipeMeta) @@ -51,30 +51,30 @@ public: { case E_BLOCK_BEETROOTS: { - char SeedCount = static_cast(1 + (rand.NextInt(3) + rand.NextInt(3)) / 2); // [1 .. 3] with high preference of 2 - a_Pickups.push_back(cItem(E_ITEM_BEETROOT_SEEDS, SeedCount, 0)); - char BeetrootCount = static_cast(1 + (rand.NextInt(3) + rand.NextInt(3)) / 2); // [1 .. 3] with high preference of 2 - a_Pickups.push_back(cItem(E_ITEM_BEETROOT, BeetrootCount, 0)); + char SeedCount = 1 + ((rand.RandInt(2) + rand.RandInt(2)) / 2); // [1 .. 3] with high preference of 2 + a_Pickups.emplace_back(E_ITEM_BEETROOT_SEEDS, SeedCount, 0); + char BeetrootCount = 1 + ((rand.RandInt(2) + rand.RandInt(2)) / 2); // [1 .. 3] with high preference of 2 + a_Pickups.emplace_back(E_ITEM_BEETROOT, BeetrootCount, 0); break; } case E_BLOCK_CROPS: { - a_Pickups.push_back(cItem(E_ITEM_WHEAT, 1, 0)); - a_Pickups.push_back(cItem(E_ITEM_SEEDS, static_cast(1 + (rand.NextInt(3) + rand.NextInt(3)) / 2), 0)); // [1 .. 3] with high preference of 2 + a_Pickups.emplace_back(E_ITEM_WHEAT, 1, 0); + a_Pickups.emplace_back(E_ITEM_SEEDS, 1 + ((rand.RandInt(2) + rand.RandInt(2)) / 2), 0); // [1 .. 3] with high preference of 2 break; } case E_BLOCK_CARROTS: { - a_Pickups.push_back(cItem(E_ITEM_CARROT, static_cast(1 + (rand.NextInt(3) + rand.NextInt(3)) / 2), 0)); // [1 .. 3] with high preference of 2 + a_Pickups.emplace_back(E_ITEM_CARROT, 1 + ((rand.RandInt(2) + rand.RandInt(2)) / 2), 0); // [1 .. 3] with high preference of 2 break; } case E_BLOCK_POTATOES: { - a_Pickups.push_back(cItem(E_ITEM_POTATO, static_cast(1 + (rand.NextInt(3) + rand.NextInt(3)) / 2), 0)); // [1 .. 3] with high preference of 2 - if (rand.NextInt(21) == 0) + a_Pickups.emplace_back(E_ITEM_POTATO, 1 + ((rand.RandInt(2) + rand.RandInt(2)) / 2), 0); // [1 .. 3] with high preference of 2 + if (rand.RandBool(0.05)) { // With a 5% chance, drop a poisonous potato as well - a_Pickups.push_back(cItem(E_ITEM_POISONOUS_POTATO, 1, 0)); + a_Pickups.emplace_back(E_ITEM_POISONOUS_POTATO, 1, 0); } break; } -- cgit v1.2.3