From 5bfb1a2c6ba2e5cd29f4be0a25410585e242e53e Mon Sep 17 00:00:00 2001 From: Flakebi Date: Sun, 12 Jul 2015 00:39:38 +0200 Subject: [PATCH] Fix some bugs --- data/kart_characteristics.xml | 34 +++++++++++---------- src/graphics/camera.cpp | 6 ++-- src/guiengine/widgets/kart_stats_widget.cpp | 6 ++-- src/karts/combined_characteristic.cpp | 5 +-- src/karts/kart_properties.cpp | 17 ++++++++++- src/karts/kart_properties.hpp | 3 ++ src/karts/kart_properties_manager.cpp | 2 ++ src/karts/xml_characteristic.cpp | 27 +++++++++------- src/states_screens/kart_selection.cpp | 3 +- 9 files changed, 65 insertions(+), 38 deletions(-) diff --git a/data/kart_characteristics.xml b/data/kart_characteristics.xml index 64449e202..7a5b54e23 100644 --- a/data/kart_characteristics.xml +++ b/data/kart_characteristics.xml @@ -7,6 +7,8 @@ would result in 10 - 5 = 5. --> + @@ -61,7 +63,7 @@ 0.5 * 0.25 + 0.5 * 0.15 = 0.2 ... which is overall the same time we had previously. --> - - + in-face-time="4.5" /> @@ -279,7 +283,7 @@ fade-out-time: Duration during which the increased maximum speed due to nitro fades out. max: How much nitro a kart can store. --> - - + + + - - - - - - + + @@ -324,7 +326,7 @@ - @@ -342,7 +344,7 @@ - + + - @@ -370,7 +373,6 @@ duration="0.7" fade-out-time="1.3" /> - diff --git a/src/graphics/camera.cpp b/src/graphics/camera.cpp index 66dcd4041..b412d2bfd 100644 --- a/src/graphics/camera.cpp +++ b/src/graphics/camera.cpp @@ -476,7 +476,7 @@ void Camera::getCameraSettings(float *above_kart, float *cam_angle, else { *above_kart = 0.75f; - *cam_angle = ch->getCameraForwardUpAngle(); + *cam_angle = ch->getCameraForwardUpAngle() * DEGREE_TO_RAD; *distance = -m_distance; } float steering = m_kart->getSteerPercent() @@ -491,7 +491,7 @@ void Camera::getCameraSettings(float *above_kart, float *cam_angle, case CM_REVERSE: // Same as CM_NORMAL except it looks backwards { *above_kart = 0.75f; - *cam_angle = ch->getCameraBackwardUpAngle(); + *cam_angle = ch->getCameraBackwardUpAngle() * DEGREE_TO_RAD; *sideway = 0; *distance = 2.0f*m_distance; *smoothing = false; @@ -824,7 +824,7 @@ void Camera::handleEndCamera(float dt) case EndCameraInformation::EC_AHEAD_OF_KART: { const AbstractCharacteristic *ch = m_kart->getCharacteristic(); - float cam_angle = ch->getCameraBackwardUpAngle(); + float cam_angle = ch->getCameraBackwardUpAngle() * DEGREE_TO_RAD; positionCamera(dt, /*above_kart*/0.75f, cam_angle, /*side_way*/0, diff --git a/src/guiengine/widgets/kart_stats_widget.cpp b/src/guiengine/widgets/kart_stats_widget.cpp index abe4bfaff..542c9d093 100644 --- a/src/guiengine/widgets/kart_stats_widget.cpp +++ b/src/guiengine/widgets/kart_stats_widget.cpp @@ -79,15 +79,15 @@ KartStatsWidget::KartStatsWidget(core::recti area, const int player_id, m_children.push_back(skill_bar); } - m_skills[SKILL_MASS]->setValue((int)(props->getCombinedCharacteristic()->getMass()/5)); + m_skills[SKILL_MASS]->setValue((int)(props->getCombinedCharacteristic()->getMass() / 5)); m_skills[SKILL_MASS]->setLabel(_("WEIGHT")); m_skills[SKILL_MASS]->m_properties[PROP_ID] = StringUtils::insertValues("@p%i_mass", m_player_id); - m_skills[SKILL_SPEED]->setValue((int)((props->getCombinedCharacteristic()->getEngineMaxSpeed()-20)*9)); + m_skills[SKILL_SPEED]->setValue((int)((props->getCombinedCharacteristic()->getEngineMaxSpeed() - 20) * 9)); m_skills[SKILL_SPEED]->setLabel(_("SPEED")); m_skills[SKILL_SPEED]->m_properties[PROP_ID] = StringUtils::insertValues("@p%i_speed", m_player_id); - m_skills[SKILL_POWER]->setValue((int)(props->getCombinedCharacteristic()->getEnginePower())); + m_skills[SKILL_POWER]->setValue((int)(props->getAvgPower())); m_skills[SKILL_POWER]->setLabel(_("POWER")); m_skills[SKILL_POWER]->m_properties[PROP_ID] = StringUtils::insertValues("@p%i_power", m_player_id); diff --git a/src/karts/combined_characteristic.cpp b/src/karts/combined_characteristic.cpp index 4b760c2c7..9a5ee2484 100644 --- a/src/karts/combined_characteristic.cpp +++ b/src/karts/combined_characteristic.cpp @@ -36,7 +36,8 @@ const SkiddingProperties* CombinedCharacteristic::getSkiddingProperties() const void CombinedCharacteristic::process(CharacteristicType type, Value value, bool *is_set) const { - for (const AbstractCharacteristic *characteristic : m_childs) - characteristic->process(type, value, is_set); + for (std::vector::const_iterator it = m_childs.cbegin(); + it != m_childs.cend(); it++) + (*it)->process(type, value, is_set); } diff --git a/src/karts/kart_properties.cpp b/src/karts/kart_properties.cpp index 0b4887318..6acac2f36 100644 --- a/src/karts/kart_properties.cpp +++ b/src/karts/kart_properties.cpp @@ -215,6 +215,8 @@ void KartProperties::load(const std::string &filename, const std::string &node) throw std::runtime_error(msg.str()); } getAllData(root); + if (m_characteristic) + delete m_characteristic; m_characteristic = new XmlCharacteristic(root); combineCharacteristics(); } @@ -317,6 +319,8 @@ void KartProperties::combineCharacteristics() m_combined_characteristic = new CombinedCharacteristic(); m_combined_characteristic->addCharacteristic(kart_properties_manager-> getBaseCharacteristic()); + m_combined_characteristic->addCharacteristic(kart_properties_manager-> + getKartTypeCharacteristic(m_kart_type)); m_combined_characteristic->addCharacteristic(m_characteristic); } // combineCharacteristics @@ -397,7 +401,7 @@ void KartProperties::getAllData(const XMLNode * root) } } - if(const XMLNode *turn_node = root->getNode("turn")) + if (const XMLNode *turn_node = root->getNode("turn")) { turn_node->get("turn-radius", &m_turn_angle_at_speed ); // For now store the turn radius in turn angle, the correct @@ -545,3 +549,14 @@ bool KartProperties::isInGroup(const std::string &group) const return std::find(m_groups.begin(), m_groups.end(), group) != m_groups.end(); } // isInGroups +// ---------------------------------------------------------------------------- +float KartProperties::getAvgPower() const +{ + float sum = 0; + std::vector gear_power_increase = m_combined_characteristic->getGearPowerIncrease(); + float max_speed = m_combined_characteristic->getEngineMaxSpeed(); + for (unsigned int i = 0; i < gear_power_increase.size(); ++i) + sum += gear_power_increase[i] * max_speed; + return sum / gear_power_increase.size(); +} // getAvgPower + diff --git a/src/karts/kart_properties.hpp b/src/karts/kart_properties.hpp index 48e7a688f..bf67f4dc8 100644 --- a/src/karts/kart_properties.hpp +++ b/src/karts/kart_properties.hpp @@ -453,6 +453,9 @@ public: { return m_physical_wheel_position; } // getPhysicalWheelPosition + + // ------------------------------------------------------------------------ + float getAvgPower() const; }; // KartProperties #endif diff --git a/src/karts/kart_properties_manager.cpp b/src/karts/kart_properties_manager.cpp index 4794c410c..a9eaa5b3c 100644 --- a/src/karts/kart_properties_manager.cpp +++ b/src/karts/kart_properties_manager.cpp @@ -219,6 +219,8 @@ void KartPropertiesManager::loadCharacteristics(const XMLNode *root) (*type)->get("name", &name); m_kart_type_characteristics.emplace(name, std::unique_ptr(new XmlCharacteristic(*type))); + XmlCharacteristic *c = (XmlCharacteristic*) &(*((--m_kart_type_characteristics.end())->second)); + c->getMass(); } // Load player difficulties nodes.clear(); diff --git a/src/karts/xml_characteristic.cpp b/src/karts/xml_characteristic.cpp index f17aaf477..ebb001920 100644 --- a/src/karts/xml_characteristic.cpp +++ b/src/karts/xml_characteristic.cpp @@ -88,15 +88,13 @@ void XmlCharacteristic::process(CharacteristicType type, Value value, bool *is_s { const std::vector processors = StringUtils::split(m_values[type], ' '); + // If the interpolation array should be completely replaced + // That has to happen when the format is not the same + bool shouldReplace = false; if (*is_set) { if (processors.size() != value.fv->size()) - { - Log::error("XmlCharacteristic::process", - "InterpolationArrays have different sizes for %s", - getName(type).c_str()); - break; - } + shouldReplace = true; else { for (std::vector::const_iterator it = processors.begin(); @@ -127,16 +125,23 @@ void XmlCharacteristic::process(CharacteristicType type, Value value, bool *is_s } } if (!found) - Log::error("XmlCharacteristic::process", - "Can't find the %f in %s", x, - getName(type).c_str()); + { + // The searched value was not found so we have + // a different format + shouldReplace = true; + break; + } } } } } - } - else + } else + // It's not yet set, so we will the current content + shouldReplace = true; + + if (shouldReplace) { + // Replace all values for (std::vector::const_iterator it = processors.begin(); it != processors.end(); it++) { diff --git a/src/states_screens/kart_selection.cpp b/src/states_screens/kart_selection.cpp index 0f36b9c68..e34becdfb 100644 --- a/src/states_screens/kart_selection.cpp +++ b/src/states_screens/kart_selection.cpp @@ -815,8 +815,7 @@ void KartSelectionScreen::updateKartStats(uint8_t widget_id, (kp->getCombinedCharacteristic()->getMass() / 5)); w->setValue(KartStatsWidget::SKILL_SPEED, (int) ((kp->getCombinedCharacteristic()->getEngineMaxSpeed() - 20) * 9)); - w->setValue(KartStatsWidget::SKILL_POWER, (int) - kp->getCombinedCharacteristic()->getEnginePower()); + w->setValue(KartStatsWidget::SKILL_POWER, (int) kp->getAvgPower()); w->update(0); } }