Load and combine characteristics
This commit is contained in:
parent
0ecc76090b
commit
eb19bf571e
@ -1,4 +1,11 @@
|
||||
<?xml version="1.0"?>
|
||||
<!-- Format
|
||||
ATTENTION: - is a special case if it is the first character of a number-
|
||||
string. It means that the number is negative and NOT that the following
|
||||
float will be substracted from the base value. So if x = 10 and the string
|
||||
"-5" is processed, the result will be -5 and not the same as "x-5", which
|
||||
would result in 10 - 5 = 5.
|
||||
-->
|
||||
<characteristics>
|
||||
<characteristic name="base">
|
||||
<!-- ********** Physics ********** -->
|
||||
@ -58,23 +65,24 @@
|
||||
time-reset-steer="0.1" />
|
||||
|
||||
<!-- Speed and acceleration
|
||||
power and max-speed (in m/s) have 3 values, one for low, medium, and hard.
|
||||
power: The power of the kart
|
||||
max-speed: The base maximum speed of the kart in m/s
|
||||
brake-factor: Value used when braking.
|
||||
brake-time-increase: The brake force is multiplied by
|
||||
(1+brake_time*brake_time_increase - i.e. the longer the brake was
|
||||
(1 + brake_time) * brake_time_increase - i.e. the longer the brake was
|
||||
pressed, the harder the kart will brake.
|
||||
max-speed-reverse-ratio is the percentage of max speed for reverse gear.
|
||||
-->
|
||||
<engine power="450 475 500 510" max-speed="17 21 23 25" brake-factor="11.0"
|
||||
<engine power="475" max-speed="21" brake-factor="11.0"
|
||||
brake-time-increase="6" max-speed-reverse-ratio="0.3" />
|
||||
|
||||
<!-- Simulated gears
|
||||
speed what gear is selected, e.g. 0.25 means that if the speed is
|
||||
switch-ratio defines at what ratio of the maximum
|
||||
bigger or equal to 0.25 x maxSpeed then use gear 1, 0.5 means if
|
||||
speed what gear is selected, e.g. 0.25 means that if the speed is
|
||||
bigger or equal to 0.25 * maxSpeed then use gear 1, 0.5 means if
|
||||
the speed is bigger or equal to 0.5 x maxSpeed then gear 2.
|
||||
gear-power-increase contains the increase in max power (to simulate
|
||||
different gears), e.g. 2.5 as first entry means: 2.5*maxPower in gear 1
|
||||
different gears), e.g. 2.5 as first entry means: 2.5 * maxPower in gear 1
|
||||
| first | second | third | . -->
|
||||
<gear switch-ratio="0.25 0.7 1.0" power-increase="2.2 1.7 1.3" />
|
||||
|
||||
@ -292,6 +300,22 @@
|
||||
duration="1" fade-out-time="2" />
|
||||
</characteristic>
|
||||
|
||||
<!-- The different difficulties (like easy, medium, hard) -->
|
||||
<difficulties>
|
||||
<characteristic name="easy">
|
||||
<engine power="450" max-speed="17" />
|
||||
</characteristic>
|
||||
<characteristic name="medium">
|
||||
</characteristic>
|
||||
<characteristic name="hard">
|
||||
<engine power="500" max-speed="23" />
|
||||
</characteristic>
|
||||
<characteristic name="best">
|
||||
<engine power="510" max-speed="25" />
|
||||
</characteristic>
|
||||
</difficulties>
|
||||
|
||||
<!-- The different kart types, that can be specified in the kart.xml file -->
|
||||
<kart-types>
|
||||
<characteristic name="light">
|
||||
<turn turn-radius="0:3.0 10:10.0 25:20.0 45:40.0"
|
||||
|
@ -403,6 +403,7 @@ void STKConfig::getAllData(const XMLNode * root)
|
||||
const XMLNode* type = child_node->getNode(i);
|
||||
m_player_difficulties[i] = new PlayerDifficulty();
|
||||
m_player_difficulties[i]->getAllData(type);
|
||||
m_player_difficulties[i]->setDifficulty((PerPlayerDifficulty) i);
|
||||
}
|
||||
} // getAllData
|
||||
|
||||
|
@ -200,10 +200,11 @@ private:
|
||||
/** The skididing properties for this kart, as a separate object in order
|
||||
* to reduce dependencies (and therefore compile time) when changing
|
||||
* any skidding property. */
|
||||
//SkiddingProperties *m_skidding;
|
||||
//TODO SkiddingProperties *m_skidding;
|
||||
|
||||
public:
|
||||
AbstractCharacteristic();
|
||||
virtual ~AbstractCharacteristic() {}
|
||||
|
||||
virtual const SkiddingProperties* getSkiddingProperties() const;
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include "karts/abstract_kart.hpp"
|
||||
|
||||
#include "items/powerup.hpp"
|
||||
#include "karts/combined_characteristic.hpp"
|
||||
#include "karts/abstract_kart_animation.hpp"
|
||||
#include "karts/kart_model.hpp"
|
||||
#include "karts/kart_properties.hpp"
|
||||
@ -57,6 +58,19 @@ AbstractKart::AbstractKart(const std::string& ident,
|
||||
m_kart_length = m_kart_model->getLength();
|
||||
m_kart_highest_point = m_kart_model->getHighestPoint();
|
||||
m_wheel_graphics_position = m_kart_model->getWheelsGraphicsPosition();
|
||||
|
||||
// Combine the characteristics for this player
|
||||
m_characteristic.reset(new CombinedCharacteristic());
|
||||
m_characteristic->addCharacteristic(kart_properties_manager->
|
||||
getBaseCharacteristic());
|
||||
m_characteristic->addCharacteristic(kart_properties_manager->
|
||||
getDifficultyCharacteristic(race_manager->getDifficultyAsString(
|
||||
race_manager->getDifficulty())));
|
||||
m_characteristic->addCharacteristic(kart_properties_manager->
|
||||
getKartTypeCharacteristic(m_kart_properties->getKartType()));
|
||||
m_characteristic->addCharacteristic(kart_properties_manager->
|
||||
getPlayerCharacteristic(m_difficulty->getIdent()));
|
||||
m_characteristic->addCharacteristic(m_kart_properties->getCharacteristic());
|
||||
} // AbstractKart
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -78,6 +92,12 @@ void AbstractKart::reset()
|
||||
}
|
||||
} // reset
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
const AbstractCharacteristic* AbstractKart::getCharacteristic() const
|
||||
{
|
||||
return &(*m_characteristic);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Returns a name to be displayed for this kart. */
|
||||
core::stringw AbstractKart::getName() const
|
||||
|
@ -19,6 +19,8 @@
|
||||
#ifndef HEADER_ABSTRACT_KART_HPP
|
||||
#define HEADER_ABSTRACT_KART_HPP
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "items/powerup_manager.hpp"
|
||||
#include "karts/moveable.hpp"
|
||||
#include "karts/controller/kart_control.hpp"
|
||||
@ -33,11 +35,12 @@ namespace irr
|
||||
}
|
||||
}
|
||||
|
||||
class AbstractCharacteristics;
|
||||
class AbstractCharacteristic;
|
||||
class AbstractKartAnimation;
|
||||
class Attachment;
|
||||
class btKart;
|
||||
class btQuaternion;
|
||||
class CombinedCharacteristic;
|
||||
class Controller;
|
||||
class Item;
|
||||
class KartModel;
|
||||
@ -75,8 +78,8 @@ protected:
|
||||
|
||||
/** The per-player difficulty. */
|
||||
const PlayerDifficulty *m_difficulty;
|
||||
/** The combined properties of the kart and the player. */
|
||||
const AbstractCharacteristics *m_characteristics;
|
||||
/** The combined properties of the kart, the player, etc. */
|
||||
std::unique_ptr<CombinedCharacteristic> m_characteristic;
|
||||
|
||||
/** This stores a copy of the kart model. It has to be a copy
|
||||
* since otherwise incosistencies can happen if the same kart
|
||||
@ -127,6 +130,9 @@ public:
|
||||
// ------------------------------------------------------------------------
|
||||
/** Sets the kart properties. */
|
||||
void setKartProperties(const KartProperties *kp) { m_kart_properties=kp; }
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the characteristics of this kart. */
|
||||
const AbstractCharacteristic* getCharacteristic() const;
|
||||
|
||||
// ========================================================================
|
||||
// Access to the per-player difficulty.
|
||||
|
@ -38,6 +38,7 @@
|
||||
#include "graphics/stk_text_billboard.hpp"
|
||||
#include "graphics/stars.hpp"
|
||||
#include "guiengine/scalable_font.hpp"
|
||||
#include "karts/abstract_characteristic.hpp"
|
||||
#include "karts/explosion_animation.hpp"
|
||||
#include "karts/kart_gfx.hpp"
|
||||
#include "karts/rescue_animation.hpp"
|
||||
@ -1753,8 +1754,7 @@ void Kart::updateNitro(float dt)
|
||||
m_max_speed->increaseMaxSpeed(MaxSpeed::MS_INCREASE_NITRO,
|
||||
m_kart_properties->getNitroMaxSpeedIncrease() *
|
||||
m_difficulty->getNitroMaxSpeedIncrease(),
|
||||
m_kart_properties->getNitroEngineForce() *
|
||||
m_difficulty->getNitroEngineForce(),
|
||||
getCharacteristic()->getNitroEngineForce(),
|
||||
m_kart_properties->getNitroDuration() *
|
||||
m_difficulty->getNitroDuration(),
|
||||
m_kart_properties->getNitroFadeOutTime() *
|
||||
|
@ -25,10 +25,12 @@
|
||||
#include "graphics/irr_driver.hpp"
|
||||
#include "graphics/material_manager.hpp"
|
||||
#include "io/file_manager.hpp"
|
||||
#include "karts/abstract_characteristic.hpp"
|
||||
#include "karts/combined_characteristic.hpp"
|
||||
#include "karts/controller/ai_properties.hpp"
|
||||
#include "karts/kart_model.hpp"
|
||||
#include "karts/kart_properties_manager.hpp"
|
||||
#include "karts/skidding_properties.hpp"
|
||||
#include "karts/xml_characteristic.hpp"
|
||||
#include "modes/world.hpp"
|
||||
#include "io/xml_node.hpp"
|
||||
#include "utils/constants.hpp"
|
||||
@ -162,6 +164,13 @@ void KartProperties::copyFrom(const KartProperties *source)
|
||||
assert(m_skidding_properties);
|
||||
*m_skidding_properties = *source->m_skidding_properties;
|
||||
|
||||
if (source->m_characteristic)
|
||||
{
|
||||
m_characteristic = new XmlCharacteristic();
|
||||
assert(m_characteristic);
|
||||
*m_characteristic = *source->m_characteristic;
|
||||
}
|
||||
|
||||
for(unsigned int i=0; i<RaceManager::DIFFICULTY_COUNT; i++)
|
||||
{
|
||||
m_ai_properties[i] = new AIProperties((RaceManager::Difficulty)i);
|
||||
@ -222,6 +231,7 @@ void KartProperties::load(const std::string &filename, const std::string &node)
|
||||
throw std::runtime_error(msg.str());
|
||||
}
|
||||
getAllData(root);
|
||||
m_characteristic = new XmlCharacteristic(root);
|
||||
}
|
||||
catch(std::exception& err)
|
||||
{
|
||||
@ -790,6 +800,12 @@ bool KartProperties::operator<(const KartProperties &other) const
|
||||
return true;
|
||||
} // operator<
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
const AbstractCharacteristic* KartProperties::getCharacteristic() const
|
||||
{
|
||||
return m_characteristic;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
bool KartProperties::isInGroup(const std::string &group) const
|
||||
{
|
||||
@ -825,4 +841,3 @@ const float KartProperties::getAvgPower() const
|
||||
return sum/m_gear_power_increase.size();
|
||||
} // getAvgPower
|
||||
|
||||
/* EOF */
|
||||
|
@ -41,6 +41,7 @@ class AbstractCharacteristic;
|
||||
class AIProperties;
|
||||
class Material;
|
||||
class SkiddingProperties;
|
||||
class XmlCharacteristic;
|
||||
class XMLNode;
|
||||
|
||||
/**
|
||||
@ -48,7 +49,7 @@ class XMLNode;
|
||||
* This includes size, name, identifier, physical properties etc.
|
||||
* It is atm also the base class for STKConfig, which stores the default values
|
||||
* for all physics constants.
|
||||
* Note that KartProperies is copied (when setting the default values from
|
||||
* Note that KartProperties is copied (when setting the default values from
|
||||
* stk_config.
|
||||
*
|
||||
* \ingroup karts
|
||||
@ -121,8 +122,10 @@ private:
|
||||
int m_shape; /**< Number of vertices in polygon when
|
||||
* drawing the dot on the mini map. */
|
||||
|
||||
/** The physical, item, etc. characteristics of this kart. */
|
||||
AbstractCharacteristic *m_characteristic;
|
||||
/** The physical, item, etc. characteristics of this kart that are loaded
|
||||
* from the xml file.
|
||||
*/
|
||||
XmlCharacteristic *m_characteristic;
|
||||
|
||||
// Physic properties
|
||||
// -----------------
|
||||
@ -418,6 +421,10 @@ public:
|
||||
bool isInGroup (const std::string &group) const;
|
||||
bool operator<(const KartProperties &other) const;
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the characteristics for this kart. */
|
||||
const AbstractCharacteristic* getCharacteristic() const;
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the (maximum) speed for a given turn radius.
|
||||
* \param radius The radius for which the speed needs to be computed. */
|
||||
@ -473,6 +480,10 @@ public:
|
||||
/** Returns the internal identifier of this kart. */
|
||||
const std::string& getIdent () const {return m_ident; }
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the type of this kart. */
|
||||
const std::string& getKartType () const { return m_kart_type; }
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the shadow texture to use. */
|
||||
video::ITexture *getShadowTexture() const {return m_shadow_texture; }
|
||||
|
@ -27,8 +27,8 @@
|
||||
#include "graphics/irr_driver.hpp"
|
||||
#include "guiengine/engine.hpp"
|
||||
#include "io/file_manager.hpp"
|
||||
#include "karts/abstract_characteristic.hpp"
|
||||
#include "karts/kart_properties.hpp"
|
||||
#include "karts/xml_characteristic.hpp"
|
||||
#include "utils/log.hpp"
|
||||
#include "utils/string_utils.hpp"
|
||||
|
||||
@ -176,12 +176,69 @@ void KartPropertiesManager::loadAllKarts(bool loading_icon)
|
||||
} // loadAllKarts
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Loads a single kart and (if not disabled) the oorresponding 3d model.
|
||||
/** Loads the characteristics from the characteristics config file.
|
||||
* \param root The xml node where the characteristics are stored.
|
||||
*/
|
||||
void KartPropertiesManager::loadCharacteristics(const XMLNode *root)
|
||||
{
|
||||
// Load base characteristics
|
||||
std::vector<XMLNode*> nodes;
|
||||
root->getNodes("characteristic", nodes);
|
||||
bool found = false;
|
||||
std::string name;
|
||||
for (std::vector<XMLNode*>::const_iterator baseNode = nodes.cbegin();
|
||||
baseNode != nodes.cend(); baseNode++)
|
||||
{
|
||||
(*baseNode)->get("name", &name);
|
||||
if (name == "base")
|
||||
{
|
||||
found = true;
|
||||
m_base_characteristic.reset(new XmlCharacteristic(*baseNode));
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found)
|
||||
Log::fatal("KartPropertiesManager", "Base characteristics not found");
|
||||
|
||||
// Load difficulties
|
||||
nodes.clear();
|
||||
root->getNode("difficulties")->getNodes("characteristic", nodes);
|
||||
for (std::vector<XMLNode*>::const_iterator type = nodes.cbegin();
|
||||
type != nodes.cend(); type++)
|
||||
{
|
||||
(*type)->get("name", &name);
|
||||
m_difficulty_characteristics.emplace(name,
|
||||
std::unique_ptr<AbstractCharacteristic>(new XmlCharacteristic(*type)));
|
||||
}
|
||||
// Load kart type characteristics
|
||||
nodes.clear();
|
||||
root->getNode("kart-types")->getNodes("characteristic", nodes);
|
||||
for (std::vector<XMLNode*>::const_iterator type = nodes.cbegin();
|
||||
type != nodes.cend(); type++)
|
||||
{
|
||||
(*type)->get("name", &name);
|
||||
m_kart_type_characteristics.emplace(name,
|
||||
std::unique_ptr<AbstractCharacteristic>(new XmlCharacteristic(*type)));
|
||||
}
|
||||
// Load player difficulties
|
||||
nodes.clear();
|
||||
root->getNode("player-characteristics")->getNodes("characteristic", nodes);
|
||||
for (std::vector<XMLNode*>::const_iterator type = nodes.cbegin();
|
||||
type != nodes.cend(); type++)
|
||||
{
|
||||
(*type)->get("name", &name);
|
||||
m_player_characteristics.emplace(name,
|
||||
std::unique_ptr<AbstractCharacteristic>(new XmlCharacteristic(*type)));
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Loads a single kart and (if not disabled) the corresponding 3d model.
|
||||
* \param filename Full path to the kart config file.
|
||||
*/
|
||||
bool KartPropertiesManager::loadKart(const std::string &dir)
|
||||
{
|
||||
std::string config_filename=dir+"/kart.xml";
|
||||
std::string config_filename = dir + "/kart.xml";
|
||||
if(!file_manager->fileExists(config_filename))
|
||||
return false;
|
||||
|
||||
@ -192,7 +249,7 @@ bool KartPropertiesManager::loadKart(const std::string &dir)
|
||||
}
|
||||
catch (std::runtime_error& err)
|
||||
{
|
||||
Log::error("[Kart_Properties_Manager]","Giving up loading '%s': %s",
|
||||
Log::error("[KartPropertiesManager]", "Giving up loading '%s': %s",
|
||||
config_filename.c_str(), err.what());
|
||||
return false;
|
||||
}
|
||||
@ -202,7 +259,7 @@ bool KartPropertiesManager::loadKart(const std::string &dir)
|
||||
if (kart_properties->getVersion() < stk_config->m_min_kart_version ||
|
||||
kart_properties->getVersion() > stk_config->m_max_kart_version)
|
||||
{
|
||||
Log::warn("[Kart_Properties_Manager]", "Warning: kart '%s' is not "
|
||||
Log::warn("[KartPropertiesManager]", "Warning: kart '%s' is not "
|
||||
"supported by this binary, ignored.",
|
||||
kart_properties->getIdent().c_str());
|
||||
delete kart_properties;
|
||||
@ -222,7 +279,7 @@ bool KartPropertiesManager::loadKart(const std::string &dir)
|
||||
}
|
||||
m_all_kart_dirs.push_back(dir);
|
||||
return true;
|
||||
} // loadKartData
|
||||
} // loadKart
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Sets the name of a mesh to use as a hat for all karts.
|
||||
@ -236,6 +293,36 @@ void KartPropertiesManager::setHatMeshName(const std::string &hat_name)
|
||||
}
|
||||
} // setHatMeshName
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
const AbstractCharacteristic* KartPropertiesManager::getDifficultyCharacteristic(const std::string &type) const
|
||||
{
|
||||
std::map<std::string, std::unique_ptr<AbstractCharacteristic> >::const_iterator
|
||||
it = m_difficulty_characteristics.find(type);
|
||||
if (it == m_difficulty_characteristics.cend())
|
||||
return nullptr;
|
||||
return &(*it->second);
|
||||
} // getDifficultyCharacteristic
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
const AbstractCharacteristic* KartPropertiesManager::getKartTypeCharacteristic(const std::string &type) const
|
||||
{
|
||||
std::map<std::string, std::unique_ptr<AbstractCharacteristic> >::const_iterator
|
||||
it = m_kart_type_characteristics.find(type);
|
||||
if (it == m_kart_type_characteristics.cend())
|
||||
return nullptr;
|
||||
return &(*it->second);
|
||||
} // getKartTypeCharacteristic
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
const AbstractCharacteristic* KartPropertiesManager::getPlayerCharacteristic(const std::string &type) const
|
||||
{
|
||||
std::map<std::string, std::unique_ptr<AbstractCharacteristic> >::const_iterator
|
||||
it = m_player_characteristics.find(type);
|
||||
if (it == m_player_characteristics.cend())
|
||||
return nullptr;
|
||||
return &(*it->second);
|
||||
} // getPlayerCharacteristic
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Returns index of the kart properties with the given ident.
|
||||
* \return Index of kart (between 0 and number of karts - 1).
|
||||
|
@ -31,6 +31,7 @@
|
||||
|
||||
class AbstractCharacteristic;
|
||||
class KartProperties;
|
||||
class XMLNode;
|
||||
|
||||
/**
|
||||
* \ingroup karts
|
||||
@ -60,9 +61,10 @@ private:
|
||||
* all clients or not. */
|
||||
std::vector<bool> m_kart_available;
|
||||
|
||||
std::unique_ptr<AbstractCharacteristic> m_base_characteristic;
|
||||
std::vector<std::unique_ptr<AbstractCharacteristic> > m_kart_type_characteristics;
|
||||
std::vector<std::unique_ptr<AbstractCharacteristic> > m_player_characteristics;
|
||||
std::unique_ptr<AbstractCharacteristic> m_base_characteristic;
|
||||
std::map<std::string, std::unique_ptr<AbstractCharacteristic> > m_difficulty_characteristics;
|
||||
std::map<std::string, std::unique_ptr<AbstractCharacteristic> > m_kart_type_characteristics;
|
||||
std::map<std::string, std::unique_ptr<AbstractCharacteristic> > m_player_characteristics;
|
||||
|
||||
protected:
|
||||
|
||||
@ -80,6 +82,7 @@ public:
|
||||
int getKartByGroup(const std::string& group,
|
||||
int i) const;
|
||||
|
||||
void loadCharacteristics (const XMLNode *root);
|
||||
bool loadKart (const std::string &dir);
|
||||
void loadAllKarts (bool loading_icon = true);
|
||||
void unloadAllKarts ();
|
||||
@ -95,6 +98,18 @@ public:
|
||||
std::vector<std::string> *ai_list);
|
||||
void setHatMeshName(const std::string &hat_name);
|
||||
// ------------------------------------------------------------------------
|
||||
/** Get the characteristic that holds the base values. */
|
||||
const AbstractCharacteristic* getBaseCharacteristic() const { return &(*m_base_characteristic); }
|
||||
// ------------------------------------------------------------------------
|
||||
/** Get a characteristic that holds the values for a certain difficulty. */
|
||||
const AbstractCharacteristic* getDifficultyCharacteristic(const std::string &type) const;
|
||||
// ------------------------------------------------------------------------
|
||||
/** Get a characteristic that holds the values for a kart type. */
|
||||
const AbstractCharacteristic* getKartTypeCharacteristic(const std::string &type) const;
|
||||
// ------------------------------------------------------------------------
|
||||
/** Get a characteristic that holds the values for a player difficulty. */
|
||||
const AbstractCharacteristic* getPlayerCharacteristic(const std::string &type) const;
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns a list of all groups. */
|
||||
const std::vector<std::string>& getAllGroups() const {return m_all_groups;}
|
||||
// ------------------------------------------------------------------------
|
||||
|
@ -28,7 +28,8 @@
|
||||
/**
|
||||
* The constructor initialises all values with default values.
|
||||
*/
|
||||
PlayerDifficulty::PlayerDifficulty(const std::string &filename)
|
||||
PlayerDifficulty::PlayerDifficulty(const std::string &filename) :
|
||||
m_difficulty(PLAYER_DIFFICULTY_NORMAL)
|
||||
{
|
||||
// Set all other values to undefined, so that it can later be tested
|
||||
// if everything is defined properly.
|
||||
|
@ -161,8 +161,10 @@ private:
|
||||
public:
|
||||
PlayerDifficulty (const std::string &filename="");
|
||||
~PlayerDifficulty ();
|
||||
void setDifficulty (PerPlayerDifficulty difficulty) { m_difficulty = difficulty; }
|
||||
PerPlayerDifficulty getDifficulty() const { return m_difficulty; }
|
||||
void getAllData (const XMLNode * root);
|
||||
std::string getIdent() const;
|
||||
std::string getIdent () const;
|
||||
float getStartupBoost () const;
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
@ -16,7 +16,7 @@
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
#include "karts/xml_characteristics.hpp"
|
||||
#include "karts/xml_characteristic.hpp"
|
||||
|
||||
#include "utils/interpolation_array.hpp"
|
||||
#include "utils/log.hpp"
|
||||
@ -25,18 +25,12 @@
|
||||
#include "io/xml_node.hpp"
|
||||
|
||||
XmlCharacteristic::XmlCharacteristic(const XMLNode *node) :
|
||||
m_values(CHARACTERISTIC_COUNT),
|
||||
m_skidding(nullptr)
|
||||
m_values(CHARACTERISTIC_COUNT)
|
||||
{
|
||||
if (node)
|
||||
load(node);
|
||||
}
|
||||
|
||||
const SkiddingProperties* XmlCharacteristic::getSkiddingProperties() const
|
||||
{
|
||||
return m_skidding;
|
||||
}
|
||||
|
||||
void XmlCharacteristic::process(CharacteristicType type, Value value, bool *is_set) const
|
||||
{
|
||||
switch (getType(type))
|
||||
@ -173,6 +167,10 @@ void XmlCharacteristic::process(CharacteristicType type, Value value, bool *is_s
|
||||
|
||||
void XmlCharacteristic::processFloat(const std::string &processor, float *value, bool *is_set)
|
||||
{
|
||||
if (processor.empty())
|
||||
// That value was not changed in this configuration
|
||||
return;
|
||||
|
||||
// Split the string by operators
|
||||
static const std::string operators = "*/+-";
|
||||
std::vector<std::string> parts;
|
||||
@ -187,12 +185,6 @@ void XmlCharacteristic::processFloat(const std::string &processor, float *value,
|
||||
}
|
||||
parts.push_back(processor.substr(pos));
|
||||
|
||||
if (parts.empty())
|
||||
{
|
||||
Log::error("XmlCharacteristic::processFloat", "no content to process");
|
||||
return;
|
||||
}
|
||||
|
||||
// Compute the result
|
||||
float x = *value;
|
||||
std::size_t index = 0;
|
||||
@ -204,12 +196,25 @@ void XmlCharacteristic::processFloat(const std::string &processor, float *value,
|
||||
Log::error("XmlCharacteristic::processFloat", "x is unknown");
|
||||
return;
|
||||
}
|
||||
// - is a special case: We don't take e.g. "-5" as relative, it
|
||||
// describes a negative number
|
||||
else if (operations[index] == "-")
|
||||
*value = 0;
|
||||
else
|
||||
{
|
||||
*value = x;
|
||||
index++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
float val;
|
||||
if (!StringUtils::fromString(parts[index], val))
|
||||
{
|
||||
Log::fatal("XmlCharacteristic::processFloat",
|
||||
"Can't parse %s: Not a float", parts[index].c_str());
|
||||
return;
|
||||
}
|
||||
*value = val;
|
||||
}
|
||||
index++;
|
||||
for (; index < parts.size(); index++)
|
||||
{
|
||||
float val;
|
||||
@ -239,7 +244,7 @@ void XmlCharacteristic::processFloat(const std::string &processor, float *value,
|
||||
void XmlCharacteristic::load(const XMLNode *node)
|
||||
{
|
||||
// Script-generated content
|
||||
if (const XMLNode *sub_node = node->getNode("Suspension"))
|
||||
if (const XMLNode *sub_node = node->getNode("suspension"))
|
||||
{
|
||||
sub_node->get("stiffness", &m_values[SUSPENSION_STIFFNESS]);
|
||||
sub_node->get("rest", &m_values[SUSPENSION_REST]);
|
||||
@ -248,7 +253,7 @@ void XmlCharacteristic::load(const XMLNode *node)
|
||||
sub_node->get("max-force", &m_values[SUSPENSION_MAX_FORCE]);
|
||||
}
|
||||
|
||||
if (const XMLNode *sub_node = node->getNode("Stability"))
|
||||
if (const XMLNode *sub_node = node->getNode("stability"))
|
||||
{
|
||||
sub_node->get("roll-influence", &m_values[STABILITY_ROLL_INFLUENCE]);
|
||||
sub_node->get("chassis-linear-damping", &m_values[STABILITY_CHASSIS_LINEAR_DAMPING]);
|
||||
@ -258,14 +263,14 @@ void XmlCharacteristic::load(const XMLNode *node)
|
||||
sub_node->get("smooth-flying-impulse", &m_values[STABILITY_SMOOTH_FLYING_IMPULSE]);
|
||||
}
|
||||
|
||||
if (const XMLNode *sub_node = node->getNode("Turn"))
|
||||
if (const XMLNode *sub_node = node->getNode("turn"))
|
||||
{
|
||||
sub_node->get("radius", &m_values[TURN_RADIUS]);
|
||||
sub_node->get("time-reset-steer", &m_values[TURN_TIME_RESET_STEER]);
|
||||
sub_node->get("time-full-steer", &m_values[TURN_TIME_FULL_STEER]);
|
||||
}
|
||||
|
||||
if (const XMLNode *sub_node = node->getNode("Engine"))
|
||||
if (const XMLNode *sub_node = node->getNode("engine"))
|
||||
{
|
||||
sub_node->get("power", &m_values[ENGINE_POWER]);
|
||||
sub_node->get("max-speed", &m_values[ENGINE_MAX_SPEED]);
|
||||
@ -274,7 +279,7 @@ void XmlCharacteristic::load(const XMLNode *node)
|
||||
sub_node->get("max-speed-reverse-ratio", &m_values[ENGINE_MAX_SPEED_REVERSE_RATIO]);
|
||||
}
|
||||
|
||||
if (const XMLNode *sub_node = node->getNode("Gear"))
|
||||
if (const XMLNode *sub_node = node->getNode("gear"))
|
||||
{
|
||||
sub_node->get("switch-ratio", &m_values[GEAR_SWITCH_RATIO]);
|
||||
sub_node->get("power-increase", &m_values[GEAR_POWER_INCREASE]);
|
||||
@ -285,7 +290,7 @@ void XmlCharacteristic::load(const XMLNode *node)
|
||||
sub_node->get("mass", &m_values[MASS]);
|
||||
}
|
||||
|
||||
if (const XMLNode *sub_node = node->getNode("Wheels"))
|
||||
if (const XMLNode *sub_node = node->getNode("wheels"))
|
||||
{
|
||||
sub_node->get("damping-relaxation", &m_values[WHEELS_DAMPING_RELAXATION]);
|
||||
sub_node->get("damping-compression", &m_values[WHEELS_DAMPING_COMPRESSION]);
|
||||
@ -293,32 +298,32 @@ void XmlCharacteristic::load(const XMLNode *node)
|
||||
sub_node->get("position", &m_values[WHEELS_POSITION]);
|
||||
}
|
||||
|
||||
if (const XMLNode *sub_node = node->getNode("Camera"))
|
||||
if (const XMLNode *sub_node = node->getNode("camera"))
|
||||
{
|
||||
sub_node->get("distance", &m_values[CAMERA_DISTANCE]);
|
||||
sub_node->get("forward-up-angle", &m_values[CAMERA_FORWARD_UP_ANGLE]);
|
||||
sub_node->get("backward-up-angle", &m_values[CAMERA_BACKWARD_UP_ANGLE]);
|
||||
}
|
||||
|
||||
if (const XMLNode *sub_node = node->getNode("Jump"))
|
||||
if (const XMLNode *sub_node = node->getNode("jump"))
|
||||
{
|
||||
sub_node->get("animation-time", &m_values[JUMP_ANIMATION_TIME]);
|
||||
}
|
||||
|
||||
if (const XMLNode *sub_node = node->getNode("Lean"))
|
||||
if (const XMLNode *sub_node = node->getNode("lean"))
|
||||
{
|
||||
sub_node->get("max", &m_values[LEAN_MAX]);
|
||||
sub_node->get("speed", &m_values[LEAN_SPEED]);
|
||||
}
|
||||
|
||||
if (const XMLNode *sub_node = node->getNode("Anvil"))
|
||||
if (const XMLNode *sub_node = node->getNode("anvil"))
|
||||
{
|
||||
sub_node->get("duration", &m_values[ANVIL_DURATION]);
|
||||
sub_node->get("weight", &m_values[ANVIL_WEIGHT]);
|
||||
sub_node->get("speed-factor", &m_values[ANVIL_SPEED_FACTOR]);
|
||||
}
|
||||
|
||||
if (const XMLNode *sub_node = node->getNode("Parachute"))
|
||||
if (const XMLNode *sub_node = node->getNode("parachute"))
|
||||
{
|
||||
sub_node->get("friction", &m_values[PARACHUTE_FRICTION]);
|
||||
sub_node->get("duration", &m_values[PARACHUTE_DURATION]);
|
||||
@ -328,7 +333,7 @@ void XmlCharacteristic::load(const XMLNode *node)
|
||||
sub_node->get("max-speed", &m_values[PARACHUTE_MAX_SPEED]);
|
||||
}
|
||||
|
||||
if (const XMLNode *sub_node = node->getNode("Bubblegum"))
|
||||
if (const XMLNode *sub_node = node->getNode("bubblegum"))
|
||||
{
|
||||
sub_node->get("duration", &m_values[BUBBLEGUM_DURATION]);
|
||||
sub_node->get("speed-fraction", &m_values[BUBBLEGUM_SPEED_FRACTION]);
|
||||
@ -337,7 +342,7 @@ void XmlCharacteristic::load(const XMLNode *node)
|
||||
sub_node->get("shield-duration", &m_values[BUBBLEGUM_SHIELD_DURATION]);
|
||||
}
|
||||
|
||||
if (const XMLNode *sub_node = node->getNode("Zipper"))
|
||||
if (const XMLNode *sub_node = node->getNode("zipper"))
|
||||
{
|
||||
sub_node->get("duration", &m_values[ZIPPER_DURATION]);
|
||||
sub_node->get("force", &m_values[ZIPPER_FORCE]);
|
||||
@ -346,7 +351,7 @@ void XmlCharacteristic::load(const XMLNode *node)
|
||||
sub_node->get("fade-out-time", &m_values[ZIPPER_FADE_OUT_TIME]);
|
||||
}
|
||||
|
||||
if (const XMLNode *sub_node = node->getNode("Swatter"))
|
||||
if (const XMLNode *sub_node = node->getNode("swatter"))
|
||||
{
|
||||
sub_node->get("duration", &m_values[SWATTER_DURATION]);
|
||||
sub_node->get("distance", &m_values[SWATTER_DISTANCE]);
|
||||
@ -354,7 +359,7 @@ void XmlCharacteristic::load(const XMLNode *node)
|
||||
sub_node->get("squash-slowdown", &m_values[SWATTER_SQUASH_SLOWDOWN]);
|
||||
}
|
||||
|
||||
if (const XMLNode *sub_node = node->getNode("Plunger"))
|
||||
if (const XMLNode *sub_node = node->getNode("plunger"))
|
||||
{
|
||||
sub_node->get("max-length", &m_values[PLUNGER_MAX_LENGTH]);
|
||||
sub_node->get("force", &m_values[PLUNGER_FORCE]);
|
||||
@ -364,27 +369,27 @@ void XmlCharacteristic::load(const XMLNode *node)
|
||||
sub_node->get("in-face-time", &m_values[PLUNGER_IN_FACE_TIME]);
|
||||
}
|
||||
|
||||
if (const XMLNode *sub_node = node->getNode("Startup"))
|
||||
if (const XMLNode *sub_node = node->getNode("startup"))
|
||||
{
|
||||
sub_node->get("time", &m_values[STARTUP_TIME]);
|
||||
sub_node->get("boost", &m_values[STARTUP_BOOST]);
|
||||
}
|
||||
|
||||
if (const XMLNode *sub_node = node->getNode("Rescue"))
|
||||
if (const XMLNode *sub_node = node->getNode("rescue"))
|
||||
{
|
||||
sub_node->get("duration", &m_values[RESCUE_DURATION]);
|
||||
sub_node->get("vert-offset", &m_values[RESCUE_VERT_OFFSET]);
|
||||
sub_node->get("height", &m_values[RESCUE_HEIGHT]);
|
||||
}
|
||||
|
||||
if (const XMLNode *sub_node = node->getNode("Explosion"))
|
||||
if (const XMLNode *sub_node = node->getNode("explosion"))
|
||||
{
|
||||
sub_node->get("duration", &m_values[EXPLOSION_DURATION]);
|
||||
sub_node->get("radius", &m_values[EXPLOSION_RADIUS]);
|
||||
sub_node->get("invulnerability-time", &m_values[EXPLOSION_INVULNERABILITY_TIME]);
|
||||
}
|
||||
|
||||
if (const XMLNode *sub_node = node->getNode("Nitro"))
|
||||
if (const XMLNode *sub_node = node->getNode("nitro"))
|
||||
{
|
||||
sub_node->get("duration", &m_values[NITRO_DURATION]);
|
||||
sub_node->get("engine-force", &m_values[NITRO_ENGINE_FORCE]);
|
||||
@ -396,7 +401,7 @@ void XmlCharacteristic::load(const XMLNode *node)
|
||||
sub_node->get("max", &m_values[NITRO_MAX]);
|
||||
}
|
||||
|
||||
if (const XMLNode *sub_node = node->getNode("Slipstream"))
|
||||
if (const XMLNode *sub_node = node->getNode("slipstream"))
|
||||
{
|
||||
sub_node->get("duration", &m_values[SLIPSTREAM_DURATION]);
|
||||
sub_node->get("length", &m_values[SLIPSTREAM_LENGTH]);
|
@ -30,12 +30,10 @@ class XmlCharacteristic : public AbstractCharacteristic
|
||||
private:
|
||||
/** The computation that was read from an xml file */
|
||||
std::vector<std::string> m_values;
|
||||
SkiddingProperties *m_skidding;
|
||||
|
||||
public:
|
||||
XmlCharacteristic(const XMLNode *node = nullptr);
|
||||
|
||||
virtual const SkiddingProperties* getSkiddingProperties() const;
|
||||
virtual void process(CharacteristicType type, Value value, bool *is_set) const;
|
||||
|
||||
void load(const XMLNode *node);
|
@ -1156,6 +1156,11 @@ void initRest()
|
||||
track_manager->addTrackSearchDir(
|
||||
file_manager->getAddonsFile("tracks/"));
|
||||
|
||||
{
|
||||
XMLNode characteristicsNode(file_manager->getAsset("kart_characteristics.xml"));
|
||||
kart_properties_manager->loadCharacteristics(&characteristicsNode);
|
||||
}
|
||||
|
||||
track_manager->loadTrackList();
|
||||
music_manager->addMusicToTracks();
|
||||
|
||||
|
@ -199,7 +199,7 @@ def main():
|
||||
elif task == "getXml":
|
||||
for g in groups:
|
||||
print(" if (const XMLNode *sub_node = node->getNode(\"{0}\"))\n {{".
|
||||
format(g.baseName))
|
||||
format(g.baseName.lower()))
|
||||
for m in g.members:
|
||||
nameUnderscore = joinSubName(g, m, False)
|
||||
nameMinus = "-".join(toList(m.name))
|
||||
|
Loading…
x
Reference in New Issue
Block a user