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:
parent
f1bd14c5b5
commit
61b56e7352
@ -89,37 +89,57 @@ KartStatsWidget::KartStatsWidget(core::recti area, const int player_id,
|
|||||||
void KartStatsWidget::setValues(const KartProperties* props,
|
void KartStatsWidget::setValues(const KartProperties* props,
|
||||||
PerPlayerDifficulty d)
|
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
|
// 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();
|
RaceManager::Difficulty previous_difficulty = race_manager->getDifficulty();
|
||||||
race_manager->setDifficulty(RaceManager::DIFFICULTY_HARD);
|
race_manager->setDifficulty(RaceManager::DIFFICULTY_BEST);
|
||||||
KartProperties kp_computed;
|
KartProperties kp_computed;
|
||||||
kp_computed.copyForPlayer(props, d);
|
kp_computed.copyForPlayer(props, d);
|
||||||
for (SkillLevelWidget* skills : m_skills)
|
for (SkillLevelWidget* skills : m_skills)
|
||||||
skills->setVisible(true);
|
skills->setVisible(true);
|
||||||
|
|
||||||
// Scale the values so they look better
|
// Scale the values so they look better
|
||||||
// The scaling factor and offset were found by trial and error.
|
// A value of 100 takes the whole bar width, including borders.
|
||||||
// It should look nice and you should be able to see the difference between
|
// So values should be in the 0-99 range
|
||||||
// different masses or velocities.
|
|
||||||
|
// The base mass is of 350 ; 350/3.89 ~= 90
|
||||||
m_skills[SKILL_MASS]->setValue((int)
|
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(
|
m_skills[SKILL_MASS]->setIcon(irr::core::stringc(
|
||||||
file_manager->getAsset(FileManager::GUI, "mass.png").c_str()));
|
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)
|
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(
|
m_skills[SKILL_SPEED]->setIcon(irr::core::stringc(
|
||||||
file_manager->getAsset(FileManager::GUI, "speed.png").c_str()));
|
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_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));
|
// The acceleration depend on power and mass, and it changes depending on speed
|
||||||
m_skills[SKILL_POWER]->setIcon(irr::core::stringc(
|
// 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()));
|
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);
|
race_manager->setDifficulty(previous_difficulty);
|
||||||
} // setValues
|
} // setValues
|
||||||
|
@ -65,7 +65,8 @@ namespace GUIEngine
|
|||||||
{
|
{
|
||||||
SKILL_MASS,
|
SKILL_MASS,
|
||||||
SKILL_SPEED,
|
SKILL_SPEED,
|
||||||
SKILL_POWER,
|
SKILL_ACCELERATION,
|
||||||
|
SKILL_NITRO_EFFICIENCY,
|
||||||
SKILL_COUNT
|
SKILL_COUNT
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -552,15 +552,32 @@ bool KartProperties::isInGroup(const std::string &group) const
|
|||||||
} // isInGroups
|
} // 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();
|
std::vector<float> gear_power_increase = m_combined_characteristic->getGearPowerIncrease();
|
||||||
float power = m_combined_characteristic->getEnginePower();
|
std::vector<float> gear_switch_ratio = m_combined_characteristic->getGearSwitchRatio();
|
||||||
for (unsigned int i = 0; i < gear_power_increase.size(); ++i)
|
int current_gear = 0;
|
||||||
sum += gear_power_increase[i] * power;
|
float sum = 0;
|
||||||
return sum / gear_power_increase.size();
|
float base_accel = m_combined_characteristic->getEnginePower()
|
||||||
} // getAvgPower
|
/ 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
|
// Script-generated content generated by tools/create_kart_properties.py getter
|
||||||
@ -1220,3 +1237,4 @@ bool KartProperties::getSkidEnabled() const
|
|||||||
} // getSkidEnabled
|
} // getSkidEnabled
|
||||||
|
|
||||||
/* <characteristics-end kpgetter> */
|
/* <characteristics-end kpgetter> */
|
||||||
|
|
||||||
|
@ -367,7 +367,7 @@ public:
|
|||||||
} // getPhysicalWheelPosition
|
} // getPhysicalWheelPosition
|
||||||
|
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
float getAvgPower() const;
|
float getAccelerationEfficiency() const;
|
||||||
|
|
||||||
|
|
||||||
// Script-generated content generated by tools/create_kart_properties.py defs
|
// Script-generated content generated by tools/create_kart_properties.py defs
|
||||||
@ -518,3 +518,4 @@ public:
|
|||||||
}; // KartProperties
|
}; // KartProperties
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user