Commit 254054ed authored by Hubert Denkmair's avatar Hubert Denkmair
Browse files

Merge branch 'patch/improved_food_dropping' into 'dev'

Patch/improved food dropping

See merge request GPN18Programmierspiel/gameserver!17
parents 86d3a088 4991c53f
......@@ -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;
}
}
......
......@@ -208,7 +208,12 @@ void Snake::dropFood(float_t value)
Vector2D dropOffset = (m_segments.end() - 1)->pos() - (m_segments.end() - 2)->pos();
Vector2D dropPos = (m_segments.end() - 1)->pos() + dropOffset.normalized() * 5;
m_field->createDynamicFood(value * config::SNAKE_CONVERSION_FACTOR, dropPos, m_segmentRadius, nullptr);
m_foodToDrop += value * config::SNAKE_CONVERSION_FACTOR;
if(m_foodToDrop >= config::FOOD_SIZE_MEAN) {
m_field->createDynamicFood(m_foodToDrop, dropPos, m_segmentRadius, nullptr);
m_foodToDrop = 0;
}
m_mass -= value;
if(m_mass < 1e-6) {
......
......@@ -51,6 +51,8 @@ class Snake
real_t m_boostedLastMove = false; //!< Track if the snake boosted during the last move
real_t m_foodToDrop = 0;
/*!
* Updates the length of m_segments and calculates the current m_segmentRadius
*/
......
......@@ -46,7 +46,7 @@ namespace config {
static const real_t SNAKE_CONSUME_RANGE = 2.0;
// Part of Snake's mass to drop in every frame the boost is on.
static const real_t SNAKE_BOOST_LOSS_FACTOR = 1e-3;
static const real_t SNAKE_BOOST_LOSS_FACTOR = 5e-3;
// Mass below which Snake dies through starvation
static const real_t SNAKE_SELF_KILL_MASS_THESHOLD = 1.0;
......
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