Improvements to kart selection stats bars (#3371)

* Compute acceleration efficiency instead of raw engine power

* Improve kart stats display

* Fix conflict resolution error

* Fix conflict resolution error
This commit is contained in:
Alayan-stk-2 2018-08-07 02:50:07 +02:00 committed by auriamg
parent f1bd14c5b5
commit 61b56e7352
4 changed files with 62 additions and 22 deletions

View File

@ -89,37 +89,57 @@ KartStatsWidget::KartStatsWidget(core::recti area, const int player_id,
void KartStatsWidget::setValues(const KartProperties* props,
PerPlayerDifficulty d)
{
// Use kart properties computed for "hard" difficulty to show the user, so
// Use kart properties computed for best difficulty to show the user, so
// that properties don't change according to the the last used difficulty
// (And because this code uses arbitrary scaling factors to make them look
// nice and the arbitrary factors were optimised for hard difficulty)
RaceManager::Difficulty previous_difficulty = race_manager->getDifficulty();
race_manager->setDifficulty(RaceManager::DIFFICULTY_HARD);
race_manager->setDifficulty(RaceManager::DIFFICULTY_BEST);
KartProperties kp_computed;
kp_computed.copyForPlayer(props, d);
for (SkillLevelWidget* skills : m_skills)
skills->setVisible(true);
// Scale the values so they look better
// The scaling factor and offset were found by trial and error.
// It should look nice and you should be able to see the difference between
// different masses or velocities.
// A value of 100 takes the whole bar width, including borders.
// So values should be in the 0-99 range
// The base mass is of 350 ; 350/3.89 ~= 90
m_skills[SKILL_MASS]->setValue((int)
((kp_computed.getCombinedCharacteristic()->getMass() - 20) / 4));
(kp_computed.getCombinedCharacteristic()->getMass()/3.89f));
m_skills[SKILL_MASS]->setIcon(irr::core::stringc(
file_manager->getAsset(FileManager::GUI, "mass.png").c_str()));
m_skills[SKILL_MASS]->m_properties[PROP_ID] = StringUtils::insertValues("@p%i_mass", m_player_id);
m_skills[SKILL_MASS]->m_properties[PROP_ID] = StringUtils::insertValues("@p%i_mass", m_player_id);
m_skills[SKILL_MASS]->m_iconbutton->setTooltip( _("Mass") );
// The base speed is of 25
// Here we are not fully proportional, because small differences matter more
m_skills[SKILL_SPEED]->setValue((int)
((kp_computed.getCombinedCharacteristic()->getEngineMaxSpeed() - 15) * 6));
((kp_computed.getCombinedCharacteristic()->getEngineMaxSpeed() - 20) * 15));
m_skills[SKILL_SPEED]->setIcon(irr::core::stringc(
file_manager->getAsset(FileManager::GUI, "speed.png").c_str()));
m_skills[SKILL_SPEED]->m_properties[PROP_ID] = StringUtils::insertValues("@p%i_speed", m_player_id);
m_skills[SKILL_SPEED]->m_iconbutton->setTooltip( _("Maximum speed") );
m_skills[SKILL_POWER]->setValue((int)((kp_computed.getAvgPower() - 30) / 20));
m_skills[SKILL_POWER]->setIcon(irr::core::stringc(
// The acceleration depend on power and mass, and it changes depending on speed
// We call a function which gives us a single number to represent it
// power/mass gives numbers in the 1-10 range, so we multiply it by 10.
m_skills[SKILL_ACCELERATION]->setValue((int)(kp_computed.getAccelerationEfficiency()*10));
m_skills[SKILL_ACCELERATION]->setIcon(irr::core::stringc(
file_manager->getAsset(FileManager::GUI, "power.png").c_str()));
m_skills[SKILL_POWER]->m_properties[PROP_ID] = StringUtils::insertValues("@p%i_power", m_player_id);
m_skills[SKILL_ACCELERATION]->m_properties[PROP_ID] =
StringUtils::insertValues("@p%i_acceleration", m_player_id);
m_skills[SKILL_ACCELERATION]->m_iconbutton->setTooltip( _("Acceleration") );
// The base nitro consumption is 1, higher for heavier karts.
// Nitro efficiency is hence 90/nitro_consumption
m_skills[SKILL_NITRO_EFFICIENCY]->setValue((int)
(90.0f/kp_computed.getCombinedCharacteristic()->getNitroConsumption()));
m_skills[SKILL_NITRO_EFFICIENCY]->setIcon(irr::core::stringc(
file_manager->getAsset(FileManager::GUI, "nitro.png").c_str()));
m_skills[SKILL_NITRO_EFFICIENCY]->m_properties[PROP_ID] =
StringUtils::insertValues("@p%i_nitro_efficiency", m_player_id);
m_skills[SKILL_NITRO_EFFICIENCY]->m_iconbutton->setTooltip( _("Nitro efficiency") );
race_manager->setDifficulty(previous_difficulty);
} // setValues

View File

@ -65,7 +65,8 @@ namespace GUIEngine
{
SKILL_MASS,
SKILL_SPEED,
SKILL_POWER,
SKILL_ACCELERATION,
SKILL_NITRO_EFFICIENCY,
SKILL_COUNT
};

View File

@ -552,15 +552,32 @@ bool KartProperties::isInGroup(const std::string &group) const
} // isInGroups
// ----------------------------------------------------------------------------
float KartProperties::getAvgPower() const
/** This function returns a weighted average of engine power divide by mass
* for use as a single number summing-up acceleration's efficiency,
* e.g. for use in kart selection. */
float KartProperties::getAccelerationEfficiency() const
{
float sum = 0;
std::vector<float> gear_power_increase = m_combined_characteristic->getGearPowerIncrease();
float power = m_combined_characteristic->getEnginePower();
for (unsigned int i = 0; i < gear_power_increase.size(); ++i)
sum += gear_power_increase[i] * power;
return sum / gear_power_increase.size();
} // getAvgPower
std::vector<float> gear_switch_ratio = m_combined_characteristic->getGearSwitchRatio();
int current_gear = 0;
float sum = 0;
float base_accel = m_combined_characteristic->getEnginePower()
/ m_combined_characteristic->getMass();
// We evaluate acceleration at increments of 0.01x max speed
// up to 1,1x max speed.
// Acceleration at low speeds is made to matter more
for (unsigned int i = 1; i<=110; i++)
{
sum += gear_power_increase[current_gear] * base_accel * (150-i);
if (i/100 >= gear_switch_ratio[current_gear] &&
(current_gear+1 < gear_power_increase.size() ))
current_gear++;
}
// 10395 is the sum of the (150-i) factors
return (sum / 10395);
} // getAccelerationEfficiency
// ----------------------------------------------------------------------------
// Script-generated content generated by tools/create_kart_properties.py getter
@ -1220,3 +1237,4 @@ bool KartProperties::getSkidEnabled() const
} // getSkidEnabled
/* <characteristics-end kpgetter> */

View File

@ -367,7 +367,7 @@ public:
} // getPhysicalWheelPosition
// ------------------------------------------------------------------------
float getAvgPower() const;
float getAccelerationEfficiency() const;
// Script-generated content generated by tools/create_kart_properties.py defs
@ -518,3 +518,4 @@ public:
}; // KartProperties
#endif