mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/4jcraft.git
synced 2026-05-29 18:34:55 +00:00
chore: format Minecraft.World
This commit is contained in:
@@ -1,72 +1,62 @@
|
||||
#include "../Platform/stdafx.h"
|
||||
#include "WeighedRandom.h"
|
||||
|
||||
int WeighedRandom::getTotalWeight(std::vector<WeighedRandomItem *> *items)
|
||||
{
|
||||
int WeighedRandom::getTotalWeight(std::vector<WeighedRandomItem*>* items) {
|
||||
int totalWeight = 0;
|
||||
for( AUTO_VAR(it, items->begin()); it != items->end(); it++ )
|
||||
{
|
||||
totalWeight += (*it)->randomWeight;
|
||||
}
|
||||
for (AUTO_VAR(it, items->begin()); it != items->end(); it++) {
|
||||
totalWeight += (*it)->randomWeight;
|
||||
}
|
||||
return totalWeight;
|
||||
}
|
||||
|
||||
WeighedRandomItem *WeighedRandom::getRandomItem(Random *random, std::vector<WeighedRandomItem *> *items, int totalWeight)
|
||||
{
|
||||
if (totalWeight <= 0)
|
||||
{
|
||||
WeighedRandomItem* WeighedRandom::getRandomItem(
|
||||
Random* random, std::vector<WeighedRandomItem*>* items, int totalWeight) {
|
||||
if (totalWeight <= 0) {
|
||||
__debugbreak();
|
||||
}
|
||||
|
||||
int selection = random->nextInt(totalWeight);
|
||||
int selection = random->nextInt(totalWeight);
|
||||
|
||||
for( AUTO_VAR(it, items->begin()); it != items->end(); it++ )
|
||||
{
|
||||
selection -= (*it)->randomWeight;
|
||||
if (selection < 0)
|
||||
{
|
||||
for (AUTO_VAR(it, items->begin()); it != items->end(); it++) {
|
||||
selection -= (*it)->randomWeight;
|
||||
if (selection < 0) {
|
||||
return *it;
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
WeighedRandomItem *WeighedRandom::getRandomItem(Random *random, std::vector<WeighedRandomItem *> *items)
|
||||
{
|
||||
return getRandomItem(random, items, getTotalWeight(items));
|
||||
WeighedRandomItem* WeighedRandom::getRandomItem(
|
||||
Random* random, std::vector<WeighedRandomItem*>* items) {
|
||||
return getRandomItem(random, items, getTotalWeight(items));
|
||||
}
|
||||
|
||||
int WeighedRandom::getTotalWeight(WeighedRandomItemArray items)
|
||||
{
|
||||
int WeighedRandom::getTotalWeight(WeighedRandomItemArray items) {
|
||||
int totalWeight = 0;
|
||||
for( unsigned int i = 0; i < items.length; i++ )
|
||||
{
|
||||
for (unsigned int i = 0; i < items.length; i++) {
|
||||
totalWeight += items[i]->randomWeight;
|
||||
}
|
||||
return totalWeight;
|
||||
}
|
||||
|
||||
WeighedRandomItem *WeighedRandom::getRandomItem(Random *random, WeighedRandomItemArray items, int totalWeight)
|
||||
{
|
||||
if (totalWeight <= 0)
|
||||
{
|
||||
WeighedRandomItem* WeighedRandom::getRandomItem(Random* random,
|
||||
WeighedRandomItemArray items,
|
||||
int totalWeight) {
|
||||
if (totalWeight <= 0) {
|
||||
__debugbreak();
|
||||
}
|
||||
|
||||
int selection = random->nextInt(totalWeight);
|
||||
for( unsigned int i = 0; i < items.length; i++ )
|
||||
{
|
||||
selection -= items[i]->randomWeight;
|
||||
if (selection < 0)
|
||||
{
|
||||
for (unsigned int i = 0; i < items.length; i++) {
|
||||
selection -= items[i]->randomWeight;
|
||||
if (selection < 0) {
|
||||
return items[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
WeighedRandomItem *WeighedRandom::getRandomItem(Random *random, WeighedRandomItemArray items)
|
||||
{
|
||||
return getRandomItem(random, items, getTotalWeight(items));
|
||||
WeighedRandomItem* WeighedRandom::getRandomItem(Random* random,
|
||||
WeighedRandomItemArray items) {
|
||||
return getRandomItem(random, items, getTotalWeight(items));
|
||||
}
|
||||
Reference in New Issue
Block a user