Commit 97df0065 authored by Thomas Kolb's avatar Thomas Kolb
Browse files

More accurate dynamic food generation

parent 49f9d6ff
......@@ -257,15 +257,14 @@ std::shared_ptr<Bot> Field::getBotByDatabaseId(int id)
void Field::createDynamicFood(real_t totalValue, const Vector2D &center, real_t radius,
const std::shared_ptr<Bot> &hunter)
{
// create at least 1 food item
std::size_t count = 1 + totalValue / config::FOOD_SIZE_MEAN;
real_t remainingValue = totalValue;
for(std::size_t i = 0; i < count; i++) {
while(remainingValue > 0) {
real_t value;
if(totalValue >= config::FOOD_SIZE_MEAN) {
if(remainingValue > config::FOOD_SIZE_MEAN) {
value = (*m_foodSizeDistribution)(*m_rndGen);
} else {
value = totalValue;
value = remainingValue;
}
real_t rndRadius = radius * (*m_simple0To1Distribution)(*m_rndGen);
......@@ -279,6 +278,8 @@ void Field::createDynamicFood(real_t totalValue, const Vector2D &center, real_t
Food food {false, pos, value, hunter};
m_updateTracker->foodSpawned(food);
m_foodMap.addElement(food);
remainingValue -= value;
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment