Change characteristics to characteristic and add player characteristics

This commit is contained in:
Flakebi 2015-07-10 00:36:50 +02:00
parent cb797c3145
commit a305b357a3
13 changed files with 526 additions and 492 deletions

View File

@ -1,5 +1,6 @@
<?xml version="1.0"?>
<kart-properties>
<characteristics>
<characteristic name="base">
<!-- ********** Physics ********** -->
<!-- Suspension
@ -289,4 +290,23 @@
<slipstream length="10" width="2" collect-time="2" use-time="5"
add-power="3" min-speed="10" max-speed-increase="5"
duration="1" fade-out-time="2" />
</kart-properties>
</characteristic>
<!-- Per-player settings/handicaps (or boosts) -->
<player-characteristics>
<characteristic name="normal" />
<characteristic name="handicap">
<engine brake-factor="*0.8" brake-time-increase="*0.85" max-speed-reverse-ratio="*0.8" />
<bubblegum duration="*1.5" speed-fraction="*1.5" torque="*1.5" />
<zipper duration="*0.8" force="*0.8" speed-gain="*0.8" max-speed-increase="*0.8" />
<swatter duration="*0.8" squash-duration="*1.5" squash-slowdown="*1.8" />
<plunger band-max-length="*0.8" band-speed-increase="*0.8" in-face-time="*1.3" />
<startup time="*0.8 0.8" boost="*0.8 0.8" />
<rescue duration="*1.5" />
<explosion duration="*1.3" invulnerability-time="*0.7" />
<nitro engine-force="*0.8" consumption="*1.1" max-speed-increase="*0.9" max="*0.8" />
<slipstream length="*0.8" width="*0.8" collect-time="*1.5" use-time="*0.8"
add-power="*0.8" min-speed="*0.8" max-speed-increase="*0.9" duration="*0.8" />
</characteristic>
</player-characteristics>
</characteristics>

View File

@ -36,8 +36,11 @@ class InterpolationArray;
*
* The documentation of these properties can be found in
* the kart_characteristics.xml file.
* Large parts of this file are generated by tools/create_kart_properties.py.
* Please don't change the generated code here, instead change the script,
* regenerate the code and overwrite the whole generated part with the result.
*/
class AbstractCharacteristics
class AbstractCharacteristic
{
public:
union Value
@ -200,7 +203,7 @@ private:
//SkiddingProperties *m_skidding;
public:
AbstractCharacteristics();
AbstractCharacteristic();
virtual const SkiddingProperties* getSkiddingProperties() const;

View File

@ -33,6 +33,7 @@ namespace irr
}
}
class AbstractCharacteristics;
class AbstractKartAnimation;
class Attachment;
class btKart;
@ -74,6 +75,8 @@ protected:
/** The per-player difficulty. */
const PlayerDifficulty *m_difficulty;
/** The combined properties of the kart and the player. */
const AbstractCharacteristics *m_characteristics;
/** This stores a copy of the kart model. It has to be a copy
* since otherwise incosistencies can happen if the same kart

View File

@ -16,18 +16,18 @@
// 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/cached_characteristics.hpp"
#include "karts/cached_characteristic.hpp"
#include "utils/interpolation_array.hpp"
CachedCharacteristics::CachedCharacteristics(const AbstractCharacteristics *origin) :
CachedCharacteristic::CachedCharacteristic(const AbstractCharacteristic *origin) :
m_values(CHARACTERISTIC_COUNT),
m_origin(origin)
{
updateSource();
}
CachedCharacteristics::~CachedCharacteristics()
CachedCharacteristic::~CachedCharacteristic()
{
// Delete all not-null values
for (int i = 0; i < CHARACTERISTIC_COUNT; i++)
@ -52,7 +52,7 @@ CachedCharacteristics::~CachedCharacteristics()
}
}
void CachedCharacteristics::updateSource()
void CachedCharacteristic::updateSource()
{
for (int i = 0; i < CHARACTERISTIC_COUNT; i++)
{
@ -142,12 +142,12 @@ void CachedCharacteristics::updateSource()
}
}
const SkiddingProperties* CachedCharacteristics::getSkiddingProperties() const
const SkiddingProperties* CachedCharacteristic::getSkiddingProperties() const
{
return m_origin->getSkiddingProperties();
}
void CachedCharacteristics::process(CharacteristicType type, Value value, bool *is_set) const
void CachedCharacteristic::process(CharacteristicType type, Value value, bool *is_set) const
{
void *v = m_values[type].content;
if (v)

View File

@ -19,9 +19,9 @@
#ifndef HEADER_CACHED_CHARACTERISTICS_HPP
#define HEADER_CACHED_CHARACTERISTICS_HPP
#include "karts/abstract_characteristics.hpp"
#include "karts/abstract_characteristic.hpp"
class CachedCharacteristics : public AbstractCharacteristics
class CachedCharacteristic : public AbstractCharacteristic
{
private:
/** Used to store a value. */
@ -37,12 +37,12 @@ private:
std::vector<SaveValue> m_values;
/** The characteristics that hold the original values. */
const AbstractCharacteristics *m_origin;
const AbstractCharacteristic *m_origin;
public:
CachedCharacteristics(const AbstractCharacteristics *origin);
CachedCharacteristics(const CachedCharacteristics &characteristics) = delete;
virtual ~CachedCharacteristics();
CachedCharacteristic(const AbstractCharacteristic *origin);
CachedCharacteristic(const CachedCharacteristic &characteristics) = delete;
virtual ~CachedCharacteristic();
/** Fetches all cached values from the original source. */
void updateSource();

View File

@ -16,16 +16,16 @@
// 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/combined_characteristics.hpp"
#include "karts/combined_characteristic.hpp"
void CombinedCharacteristics::addCharacteristic(const AbstractCharacteristics *characteristic)
void CombinedCharacteristic::addCharacteristic(const AbstractCharacteristic *characteristic)
{
m_childs.push_back(characteristic);
}
const SkiddingProperties* CombinedCharacteristics::getSkiddingProperties() const
const SkiddingProperties* CombinedCharacteristic::getSkiddingProperties() const
{
for (const AbstractCharacteristics *characteristic : m_childs)
for (const AbstractCharacteristic *characteristic : m_childs)
{
const SkiddingProperties *skid = characteristic->getSkiddingProperties();
if (skid)
@ -34,9 +34,9 @@ const SkiddingProperties* CombinedCharacteristics::getSkiddingProperties() const
return nullptr;
}
void CombinedCharacteristics::process(CharacteristicType type, Value value, bool *is_set) const
void CombinedCharacteristic::process(CharacteristicType type, Value value, bool *is_set) const
{
for (const AbstractCharacteristics *characteristic : m_childs)
for (const AbstractCharacteristic *characteristic : m_childs)
characteristic->process(type, value, is_set);
}

View File

@ -19,15 +19,15 @@
#ifndef HEADER_COMBINDED_CHARACTERISTICS_HPP
#define HEADER_COMBINDED_CHARACTERISTICS_HPP
#include "karts/abstract_characteristics.hpp"
#include "karts/abstract_characteristic.hpp"
class CombinedCharacteristics : public AbstractCharacteristics
class CombinedCharacteristic : public AbstractCharacteristic
{
private:
std::vector<const AbstractCharacteristics*> m_childs;
std::vector<const AbstractCharacteristic*> m_childs;
public:
void addCharacteristic(const AbstractCharacteristics *characteristic);
void addCharacteristic(const AbstractCharacteristic *characteristic);
virtual const SkiddingProperties* getSkiddingProperties() const;
virtual void process(CharacteristicType type, Value value, bool *is_set) const;

View File

@ -27,6 +27,7 @@
#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 "utils/log.hpp"
#include "utils/string_utils.hpp"

View File

@ -22,12 +22,14 @@
#include "utils/ptr_vector.hpp"
#include <map>
#include <memory>
#include "network/remote_kart_info.hpp"
#include "utils/no_copy.hpp"
#define ALL_KART_GROUPS_ID "all"
class AbstractCharacteristic;
class KartProperties;
/**
@ -58,6 +60,11 @@ 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_kart_characteristics;
std::vector<std::unique_ptr<AbstractCharacteristic> > m_player_characteristics;
protected:
typedef PtrVector<KartProperties> KartPropertiesVector;

View File

@ -24,7 +24,7 @@
#include "io/xml_node.hpp"
XmlCharacteristics::XmlCharacteristics(const XMLNode *node) :
XmlCharacteristic::XmlCharacteristic(const XMLNode *node) :
m_values(CHARACTERISTIC_COUNT),
m_skidding(nullptr)
{
@ -32,12 +32,12 @@ XmlCharacteristics::XmlCharacteristics(const XMLNode *node) :
load(node);
}
const SkiddingProperties* XmlCharacteristics::getSkiddingProperties() const
const SkiddingProperties* XmlCharacteristic::getSkiddingProperties() const
{
return m_skidding;
}
void XmlCharacteristics::process(CharacteristicType type, Value value, bool *is_set) const
void XmlCharacteristic::process(CharacteristicType type, Value value, bool *is_set) const
{
switch (getType(type))
{
@ -52,7 +52,7 @@ void XmlCharacteristics::process(CharacteristicType type, Value value, bool *is_
{
if (processors.size() != value.fv->size())
{
Log::error("XmlCharacteristics::process",
Log::error("XmlCharacteristic::process",
"FloatVectors have different sizes for %s",
getName(type).c_str());
break;
@ -74,7 +74,7 @@ void XmlCharacteristics::process(CharacteristicType type, Value value, bool *is_
if (!*is_set)
{
Log::error("XmlCharacteristics::process", "Can't process %s",
Log::error("XmlCharacteristic::process", "Can't process %s",
getName(type).c_str());
value.fv->clear();
break;
@ -91,7 +91,7 @@ void XmlCharacteristics::process(CharacteristicType type, Value value, bool *is_
{
if (processors.size() != value.fv->size())
{
Log::error("XmlCharacteristics::process",
Log::error("XmlCharacteristic::process",
"InterpolationArrays have different sizes for %s",
getName(type).c_str());
break;
@ -103,13 +103,13 @@ void XmlCharacteristics::process(CharacteristicType type, Value value, bool *is_
{
std::vector<std::string> pair = StringUtils::split(*it, ':');
if (pair.size() != 2)
Log::error("XmlCharacteristics::process",
Log::error("XmlCharacteristic::process",
"Can't process %s: Wrong format", getName(type).c_str());
else
{
float x;
if (!StringUtils::fromString(pair[0], x))
Log::error("XmlCharacteristics::process",
Log::error("XmlCharacteristic::process",
"Can't process %s: Not a float", getName(type).c_str());
else
{
@ -126,7 +126,7 @@ void XmlCharacteristics::process(CharacteristicType type, Value value, bool *is_
}
}
if (!found)
Log::error("XmlCharacteristics::process",
Log::error("XmlCharacteristic::process",
"Can't find the %f in %s", x,
getName(type).c_str());
}
@ -141,13 +141,13 @@ void XmlCharacteristics::process(CharacteristicType type, Value value, bool *is_
{
std::vector<std::string> pair = StringUtils::split(*it,':');
if (pair.size() != 2)
Log::error("XmlCharacteristics::process",
Log::error("XmlCharacteristic::process",
"Can't process %s: Wrong format", getName(type).c_str());
else
{
float x;
if (!StringUtils::fromString(pair[0], x))
Log::error("XmlCharacteristics::process",
Log::error("XmlCharacteristic::process",
"Can't process %s: Not a float", getName(type).c_str());
else
{
@ -156,7 +156,7 @@ void XmlCharacteristics::process(CharacteristicType type, Value value, bool *is_
processFloat(pair[1], &val, is_set);
if (!*is_set)
{
Log::error("XmlCharacteristics::process", "Can't process %s",
Log::error("XmlCharacteristic::process", "Can't process %s",
getName(type).c_str());
value.ia->clear();
break;
@ -171,7 +171,7 @@ void XmlCharacteristics::process(CharacteristicType type, Value value, bool *is_
}
}
void XmlCharacteristics::processFloat(const std::string &processor, float *value, bool *is_set)
void XmlCharacteristic::processFloat(const std::string &processor, float *value, bool *is_set)
{
// Split the string by operators
static const std::string operators = "*/+-";
@ -189,7 +189,7 @@ void XmlCharacteristics::processFloat(const std::string &processor, float *value
if (parts.empty())
{
Log::error("XmlCharacteristics::processFloat", "no content to process");
Log::error("XmlCharacteristic::processFloat", "no content to process");
return;
}
@ -201,7 +201,7 @@ void XmlCharacteristics::processFloat(const std::string &processor, float *value
{
if (!*is_set)
{
Log::error("XmlCharacteristics::processFloat", "x is unknown");
Log::error("XmlCharacteristic::processFloat", "x is unknown");
return;
}
else
@ -217,7 +217,7 @@ void XmlCharacteristics::processFloat(const std::string &processor, float *value
val = x;
else if (!StringUtils::fromString(parts[index], val))
{
Log::fatal("XmlCharacteristics::processFloat",
Log::fatal("XmlCharacteristic::processFloat",
"Can't process %s: Not a float", parts[index].c_str());
return;
}
@ -230,13 +230,13 @@ void XmlCharacteristics::processFloat(const std::string &processor, float *value
else if (operations[index - 1] == "-")
*value -= val;
else
Log::fatal("XmlCharacteristics::processFloat",
Log::fatal("XmlCharacteristic::processFloat",
"Unknown operator (%s)", operations[index - 1].c_str());
}
*is_set = true;
}
void XmlCharacteristics::load(const XMLNode *node)
void XmlCharacteristic::load(const XMLNode *node)
{
// Script-generated content
if (const XMLNode *sub_node = node->getNode("Suspension"))

View File

@ -19,13 +19,13 @@
#ifndef HEADER_XML_CHARACTERISTICS_HPP
#define HEADER_XML_CHARACTERISTICS_HPP
#include "karts/abstract_characteristics.hpp"
#include "karts/abstract_characteristic.hpp"
#include <string>
class XMLNode;
class XmlCharacteristics : public AbstractCharacteristics
class XmlCharacteristic : public AbstractCharacteristic
{
private:
/** The computation that was read from an xml file */
@ -33,7 +33,7 @@ private:
SkiddingProperties *m_skidding;
public:
XmlCharacteristics(const XMLNode *node = nullptr);
XmlCharacteristic(const XMLNode *node = nullptr);
virtual const SkiddingProperties* getSkiddingProperties() const;
virtual void process(CharacteristicType type, Value value, bool *is_set) const;

View File

@ -172,13 +172,13 @@ def main():
typeC = m.typeC
result = "result"
print("""{3} AbstractCharacteristics::get{1}() const
print("""{3} AbstractCharacteristic::get{1}() const
{{
{0} result;
bool is_set = false;
process({2}, &result, &is_set);
if (!is_set)
Log::fatal("AbstractCharacteristics", "Can't get characteristic %s", getName({2}).c_str());
Log::fatal("AbstractCharacteristic", "Can't get characteristic %s", getName({2}).c_str());
return {4};
}}
""".format(m.typeC, nameTitle, nameUnderscore.upper(), typeC, result))