distri for bonus

This commit is contained in:
Askou
2021-06-15 15:56:27 +02:00
parent 2c42af1c59
commit d795f36747
3 changed files with 26 additions and 21 deletions
+17 -4
View File
@@ -7,6 +7,8 @@
#include <Component/Bonus/PlayerBonusComponent.hpp>
#include "Component/Movable/MovableComponent.hpp"
#include "Bonus.hpp"
#include <map>
#include <random>
#include "Component/BombHolder/BombHolderComponent.hpp"
namespace BBM {
@@ -55,10 +57,21 @@ namespace BBM {
Bonus::BonusType Bonus::getRandomBonusType()
{
double rnd = static_cast<double>(std::rand()) / RAND_MAX;
static std::default_random_engine generator(time(nullptr));
std::map<BonusType, float> chanceValue = {
{NOTHING, 100.0f},
{SPEEDUP, 45.0f},
{BOMBSTOCK, 30.0f},
{EXPLOSIONINC, 15.0f},
{NOCLIP, 1.5f},
};
std::uniform_int_distribution<int> distribution(1,1000);
float value = (distribution(generator) / 10);
BonusType bonus = NOTHING;
if (rnd <= 0.8)
return (static_cast<BonusType>((std::rand() % NOCLIP) + 1));
return (NOTHING);
for (auto &chance : chanceValue)
if (chance.second > value)
bonus = chance.first;
return (bonus);
}
}