SuperTuxKart
Loading...
Searching...
No Matches
kart_properties.hpp
1//
2// SuperTuxKart - a fun racing game with go-kart
3// Copyright (C) 2006-2015 SuperTuxKart-Team
4//
5// This program is free software; you can redistribute it and/or
6// modify it under the terms of the GNU General Public License
7// as published by the Free Software Foundation; either version 3
8// of the License, or (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with this program; if not, write to the Free Software
17// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19#ifndef HEADER_KART_PROPERTIES_HPP
20#define HEADER_KART_PROPERTIES_HPP
21
22#include <memory>
23#include <string>
24#include <vector>
25
26#include <SColor.h>
27#include <irrString.h>
28namespace irr
29{
30 namespace video { class ITexture; }
31}
32using namespace irr;
33
34#include "io/xml_node.hpp"
35#include "race/race_manager.hpp"
36#include "utils/interpolation_array.hpp"
37#include "utils/vec3.hpp"
38
40class AIProperties;
43class KartModel;
44class Material;
45namespace GE { class GERenderInfo; }
46class XMLNode;
47
48
60{
61private:
63 std::string m_root, m_root_absolute_path;
64
69 std::shared_ptr<AIProperties> m_ai_properties[RaceManager::DIFFICULTY_COUNT];
70
73
76
79 video::ITexture *m_minimap_icon;
80
84 mutable std::shared_ptr<KartModel> m_kart_model;
85
87 std::vector<std::string> m_groups;
88
90 static float UNDEFINED;
91
94
95 // SFX files
96 // ---------------
97 std::vector<int> m_custom_sfx_id;
99 // Display and gui
100 // ---------------
101 std::string m_name;
103 std::string m_ident;
105 std::string m_icon_file;
108 std::string m_shadow_file;
117 video::SColor m_color;
125 std::shared_ptr<AbstractCharacteristic> m_characteristic;
127 std::shared_ptr<CombinedCharacteristic> m_combined_characteristic;
129 std::shared_ptr<CachedCharacteristic> m_cached_characteristic;
130
131 // Physic properties
132 // -----------------
136
145
150
151 bool m_is_addon;
152
154 std::string m_kart_type;
155
157 std::string m_wheel_filename[4];
158
161
163 std::string m_engine_sfx_type;
164
165 std::string m_skid_sound;
166
167 // bullet physics data
168 // -------------------
169 float m_friction_slip;
170
173
174public:
181 enum TerrainImpulseType {IMPULSE_NONE, IMPULSE_NORMAL,
182 IMPULSE_TO_DRIVELINE};
183private:
184 TerrainImpulseType m_terrain_impulse_type;
185
188
192
195
198
199 void load (const std::string &filename,
200 const std::string &node);
201 void combineCharacteristics(HandicapLevel h);
202
203 void setWheelBase(float kart_length)
204 {
205 // The longer the kart,the bigger its turn radius if using an identical
206 // wheel base, exactly proportionally to its length.
207 // The wheel base is used to compensate this
208 // We divide by 1.425 to have a default turn radius which conforms
209 // closely (+-0,1%) with the specifications in kart_characteristics.xml
210 m_wheel_base = fabsf(kart_length / 1.425f);
211 }
212
213 void handleOnDemandLoadTexture();
214public:
216 static std::string getHandicapAsString(HandicapLevel h);
217
218 KartProperties (const std::string &filename="");
220 void copyForPlayer (const KartProperties *source,
221 HandicapLevel h = HANDICAP_NONE);
222 void adjustForOnlineAddonKart(const KartProperties* source);
223 void updateForOnlineKart(const std::string& id, const Vec3& gravity_shift,
224 float kart_length)
225 {
226 m_ident = id;
227 m_gravity_center_shift = gravity_shift;
228 setWheelBase(kart_length);
229 }
230 void copyFrom (const KartProperties *source);
231 void getAllData (const XMLNode * root);
232 void checkAllSet (const std::string &filename);
233 bool isInGroup (const std::string &group) const;
234 bool operator<(const KartProperties &other) const;
235
236 // ------------------------------------------------------------------------
237 void initKartWithDifferentType(const std::string& type)
238 {
239 m_kart_type = type;
240 combineCharacteristics(HANDICAP_NONE);
241 }
242 // ------------------------------------------------------------------------
245 // ------------------------------------------------------------------------
251
252 // ------------------------------------------------------------------------
255
256 // ------------------------------------------------------------------------
258 video::ITexture *getMinimapIcon () const {return m_minimap_icon; }
259
260 // ------------------------------------------------------------------------
261 KartModel* getKartModelCopy(std::shared_ptr<GE::GERenderInfo> ri=nullptr) const;
262 // ------------------------------------------------------------------------
265 const KartModel& getMasterKartModel() const {return *m_kart_model; }
266 // ------------------------------------------------------------------------
267 void setHatMeshName(const std::string &hat_name);
268 // ------------------------------------------------------------------------
269 core::stringw getName() const;
270 // ------------------------------------------------------------------------
271 const std::string getNonTranslatedName() const {return m_name;}
272
273 // ------------------------------------------------------------------------
275 const std::string& getIdent () const {return m_ident; }
276
277 // ------------------------------------------------------------------------
279 const std::string& getKartType () const { return m_kart_type; }
280
281 // ------------------------------------------------------------------------
284
285 // ------------------------------------------------------------------------
287 const std::string& getAbsoluteIconFile() const { return m_icon_file; }
288
289 // ------------------------------------------------------------------------
291 const int getCustomSfxId (int type)
292 const {return m_custom_sfx_id[type]; }
293
294 // ------------------------------------------------------------------------
296 int getVersion () const {return m_version; }
297
298 // ------------------------------------------------------------------------
300 const video::SColor &getColor () const {return m_color; }
301
302 // ------------------------------------------------------------------------
305 int getShape () const {return m_shape; }
306
307 // ------------------------------------------------------------------------
309 const std::vector<std::string>&
310 getGroups () const {return m_groups; }
311
312 // ------------------------------------------------------------------------
314 const std::string& getEngineSfxType () const {return m_engine_sfx_type;}
315 // ------------------------------------------------------------------------
317 const std::string& getSkidSound () const {return m_skid_sound; }
318
319 // Bullet physics get functions
320 //-----------------------------
322 float getFrictionSlip () const {return m_friction_slip; }
323
324 // ------------------------------------------------------------------------
326 float getWheelBase () const {return m_wheel_base; }
327
328 // ------------------------------------------------------------------------
332
333 // ------------------------------------------------------------------------
338
339 // ------------------------------------------------------------------------
343 { return m_terrain_impulse_type; }
344 // ------------------------------------------------------------------------
348
349 // ------------------------------------------------------------------------
352
353 // ------------------------------------------------------------------------
355 float getRestitution(float speed) const { return m_restitution.get(speed);}
356
357 // ------------------------------------------------------------------------
360 {
361 return m_ai_properties[RaceManager::get()->getDifficulty()].get();
362 } // getAIProperties
363
364 // ------------------------------------------------------------------------
366 const std::string& getKartDir () const {return m_root; }
367
368 // ------------------------------------------------------------------------
370 const Vec3 &getBevelFactor() const { return m_bevel_factor; }
371 // ------------------------------------------------------------------------
377 const float getPhysicalWheelPosition() const
378 {
380 } // getPhysicalWheelPosition
381
382 // ------------------------------------------------------------------------
383 float getAccelerationEfficiency() const;
384 // ------------------------------------------------------------------------
389 { return m_nitro_min_consumption; }
390 // ------------------------------------------------------------------------
391 bool isAddon() const { return m_is_addon; }
392
393 // Script-generated content generated by tools/create_kart_properties.py defs
394 // Please don't change the following tag. It will be automatically detected
395 // by the script and replace the contained content.
396 // To update the code, use tools/update_characteristics.py
397 /* <characteristics-start kpdefs> */
398
399 float getSuspensionStiffness() const;
400 float getSuspensionRest() const;
401 float getSuspensionTravel() const;
402 bool getSuspensionExpSpringResponse() const;
403 float getSuspensionMaxForce() const;
404
405 float getStabilityRollInfluence() const;
406 float getStabilityChassisLinearDamping() const;
407 float getStabilityChassisAngularDamping() const;
408 float getStabilityDownwardImpulseFactor() const;
409 float getStabilityTrackConnectionAccel() const;
410 std::vector<float> getStabilityAngularFactor() const;
411 float getStabilitySmoothFlyingImpulse() const;
412
413 InterpolationArray getTurnRadius() const;
414 float getTurnTimeResetSteer() const;
415 InterpolationArray getTurnTimeFullSteer() const;
416
417 float getEnginePower() const;
418 float getEngineMaxSpeed() const;
419 float getEngineGenericMaxSpeed() const;
420 float getEngineBrakeFactor() const;
421 float getEngineBrakeTimeIncrease() const;
422 float getEngineMaxSpeedReverseRatio() const;
423
424 std::vector<float> getGearSwitchRatio() const;
425 std::vector<float> getGearPowerIncrease() const;
426
427 float getMass() const;
428
429 float getWheelsDampingRelaxation() const;
430 float getWheelsDampingCompression() const;
431
432 float getJumpAnimationTime() const;
433
434 float getLeanMax() const;
435 float getLeanSpeed() const;
436
437 float getAnvilDuration() const;
438 float getAnvilWeight() const;
439 float getAnvilSpeedFactor() const;
440
441 float getParachuteFriction() const;
442 float getParachuteDuration() const;
443 float getParachuteDurationOther() const;
444 float getParachuteDurationRankMult() const;
445 float getParachuteDurationSpeedMult() const;
446 float getParachuteLboundFraction() const;
447 float getParachuteUboundFraction() const;
448 float getParachuteMaxSpeed() const;
449
450 float getFrictionKartFriction() const;
451
452 float getBubblegumDuration() const;
453 float getBubblegumSpeedFraction() const;
454 float getBubblegumTorque() const;
455 float getBubblegumFadeInTime() const;
456 float getBubblegumShieldDuration() const;
457
458 float getZipperDuration() const;
459 float getZipperForce() const;
460 float getZipperSpeedGain() const;
461 float getZipperMaxSpeedIncrease() const;
462 float getZipperFadeOutTime() const;
463
464 float getSwatterDuration() const;
465 float getSwatterDistance() const;
466 float getSwatterSquashDuration() const;
467 float getSwatterSquashSlowdown() const;
468
469 float getPlungerBandMaxLength() const;
470 float getPlungerBandForce() const;
471 float getPlungerBandDuration() const;
472 float getPlungerBandSpeedIncrease() const;
473 float getPlungerBandFadeOutTime() const;
474 float getPlungerInFaceTime() const;
475
476 std::vector<float> getStartupTime() const;
477 std::vector<float> getStartupBoost() const;
478
479 float getRescueDuration() const;
480 float getRescueVertOffset() const;
481 float getRescueHeight() const;
482
483 float getExplosionDuration() const;
484 float getExplosionRadius() const;
485 float getExplosionInvulnerabilityTime() const;
486
487 float getNitroDuration() const;
488 float getNitroEngineForce() const;
489 float getNitroEngineMult() const;
490 float getNitroConsumption() const;
491 float getNitroSmallContainer() const;
492 float getNitroBigContainer() const;
493 float getNitroMaxSpeedIncrease() const;
494 float getNitroFadeOutTime() const;
495 float getNitroMax() const;
496
497 float getSlipstreamDurationFactor() const;
498 float getSlipstreamBaseSpeed() const;
499 float getSlipstreamLength() const;
500 float getSlipstreamWidth() const;
501 float getSlipstreamInnerFactor() const;
502 float getSlipstreamMinCollectTime() const;
503 float getSlipstreamMaxCollectTime() const;
504 float getSlipstreamAddPower() const;
505 float getSlipstreamMinSpeed() const;
506 float getSlipstreamMaxSpeedIncrease() const;
507 float getSlipstreamFadeOutTime() const;
508
509 float getSkidIncrease() const;
510 float getSkidDecrease() const;
511 float getSkidMax() const;
512 float getSkidTimeTillMax() const;
513 float getSkidVisual() const;
514 float getSkidVisualTime() const;
515 float getSkidRevertVisualTime() const;
516 float getSkidMinSpeed() const;
517 std::vector<float> getSkidTimeTillBonus() const;
518 std::vector<float> getSkidBonusSpeed() const;
519 std::vector<float> getSkidBonusTime() const;
520 std::vector<float> getSkidBonusForce() const;
521 float getSkidPhysicalJumpTime() const;
522 float getSkidGraphicalJumpTime() const;
523 float getSkidPostSkidRotateFactor() const;
524 float getSkidReduceTurnMin() const;
525 float getSkidReduceTurnMax() const;
526 bool getSkidEnabled() const;
527
528 /* <characteristics-end kpdefs> */
529
530 LEAK_CHECK()
531}; // KartProperties
532
533#endif
534
A simple class that stores all AI related properties.
Definition: ai_properties.hpp:40
Characteristics are the properties of a kart that influence gameplay mechanics.
Definition: abstract_characteristic.hpp:43
Definition: cached_characteristic.hpp:27
Definition: combined_characteristic.hpp:27
This class manages a set of (x_i,y_i) points, x_i must be sorted.
Definition: interpolation_array.hpp:32
float get(float x) const
Returns the interpolated Y value for a given x.
Definition: interpolation_array.hpp:101
This class stores a 3D kart model.
Definition: kart_model.hpp:168
This class stores the properties of a kart.
Definition: kart_properties.hpp:60
std::string m_wheel_filename[4]
Filename of the wheel models.
Definition: kart_properties.hpp:157
float m_collision_impulse_time
How long the collision impulse should be applied.
Definition: kart_properties.hpp:194
float m_wheel_base
Wheel base of the kart.
Definition: kart_properties.hpp:160
~KartProperties()
Destructor, dereferences the kart model.
Definition: kart_properties.cpp:120
float getCollisionImpulse() const
Returns the (artificial) collision impulse this kart will apply to another kart in case of a non-fron...
Definition: kart_properties.hpp:347
const video::SColor & getColor() const
Returns the dot color to use for this kart in the race gui.
Definition: kart_properties.hpp:300
const std::string & getEngineSfxType() const
Returns the engine type (used to change sfx depending on kart size).
Definition: kart_properties.hpp:314
int getShape() const
Returns the number of edges for the polygon used to draw the dot of this kart on the mini map of the ...
Definition: kart_properties.hpp:305
Vec3 m_bevel_factor
If != 0 a bevelled box shape is used by using a point cloud as a collision shape.
Definition: kart_properties.hpp:135
const std::string & getSkidSound() const
Returns the skid sound.
Definition: kart_properties.hpp:317
void getAllData(const XMLNode *root)
Actually reads in the data from the xml file.
Definition: kart_properties.cpp:453
const AIProperties * getAIPropertiesForDifficulty() const
Returns a pointer to the AI properties.
Definition: kart_properties.hpp:359
std::string m_root
Base directory for this kart.
Definition: kart_properties.hpp:63
int8_t getNitroMinConsumptionTicks() const
Returns minimum time during which nitro is consumed when pressing nitro key, to prevent using nitro i...
Definition: kart_properties.hpp:388
std::string m_ident
The computer readable-name of the kart driver.
Definition: kart_properties.hpp:103
std::shared_ptr< CachedCharacteristic > m_cached_characteristic
The cached combined characteristics.
Definition: kart_properties.hpp:129
core::stringw getName() const
Returns the name of this kart.
Definition: kart_properties.cpp:719
KartModel * getKartModelCopy(std::shared_ptr< GE::GERenderInfo > ri=nullptr) const
Returns a pointer to the KartModel object.
Definition: kart_properties.cpp:385
Material * m_icon_material
The absolute path of the icon texture to use.
Definition: kart_properties.hpp:72
void copyForPlayer(const KartProperties *source, HandicapLevel h=HANDICAP_NONE)
Copies this KartProperties to another one.
Definition: kart_properties.cpp:145
int m_shape
Number of vertices in polygon when drawing the dot on the mini map.
Definition: kart_properties.hpp:119
std::string m_icon_file
Filename of icon that represents the kart in the statusbar and the character select screen.
Definition: kart_properties.hpp:105
video::ITexture * m_minimap_icon
The texture to use in the minimap.
Definition: kart_properties.hpp:79
std::string m_shadow_file
Filename of the image file that contains the shadow for this kart.
Definition: kart_properties.hpp:108
Material * m_shadow_material
The texture with the shadow.
Definition: kart_properties.hpp:116
float m_physical_wheel_position
The position of the physical wheel is a weighted average of the two ends of the beveled shape.
Definition: kart_properties.hpp:144
video::ITexture * getMinimapIcon() const
Returns the texture to use in the minimap, or NULL if not defined.
Definition: kart_properties.hpp:258
const std::string & getIdent() const
Returns the internal identifier of this kart.
Definition: kart_properties.hpp:275
const float getPhysicalWheelPosition() const
Returns position of the physical wheel is a weighted average of the two ends of the beveled shape.
Definition: kart_properties.hpp:377
void load(const std::string &filename, const std::string &node)
Loads the kart properties from a file.
Definition: kart_properties.cpp:218
void copyFrom(const KartProperties *source)
Copies this KartProperties to another one.
Definition: kart_properties.cpp:171
video::SColor m_color
Color the represents the kart in the status bar and on the track-view.
Definition: kart_properties.hpp:117
void checkAllSet(const std::string &filename)
Checks if all necessary physics values are indeed defines.
Definition: kart_properties.cpp:634
const std::string & getKartDir() const
Returns the full path where the files for this kart are stored.
Definition: kart_properties.hpp:366
float getWheelBase() const
Returns the wheel base (distance front to rear axis).
Definition: kart_properties.hpp:326
TerrainImpulseType getTerrainImpulseType() const
Returns what kind of impulse STK should use in case of a kart-track collision.
Definition: kart_properties.hpp:342
std::shared_ptr< AIProperties > m_ai_properties[RaceManager::DIFFICULTY_COUNT]
AI Properties for this kart, as a separate object in order to reduce dependencies (and therefore comp...
Definition: kart_properties.hpp:69
Vec3 m_gravity_center_shift
Shift of center of gravity.
Definition: kart_properties.hpp:172
std::shared_ptr< CombinedCharacteristic > m_combined_characteristic
The base characteristics combined with the characteristics of this kart.
Definition: kart_properties.hpp:127
const AbstractCharacteristic * getCombinedCharacteristic() const
Returns the characteristics for this kart combined with the base characteristic.
Definition: kart_properties.cpp:678
const int getCustomSfxId(int type) const
Returns custom sound effects for this kart.
Definition: kart_properties.hpp:291
const AbstractCharacteristic * getCharacteristic() const
Returns the characteristics for this kart.
Definition: kart_properties.cpp:672
float getCollisionImpulseTime() const
Returns how long the collision impulse should be applied.
Definition: kart_properties.hpp:351
const std::vector< std::string > & getGroups() const
Returns the list of groups this kart belongs to.
Definition: kart_properties.hpp:310
float getRestitution(float speed) const
Returns the restitution factor for this kart.
Definition: kart_properties.hpp:355
const std::string & getAbsoluteIconFile() const
Returns the absolute path of the icon file of this kart.
Definition: kart_properties.hpp:287
int8_t m_nitro_min_consumption
Minimum time during which nitro is consumed when pressing the nitro key (to prevent using in very sma...
Definition: kart_properties.hpp:149
float m_collision_impulse
An additiojnal artificial impulse that pushes two karts in a side-side collision away from each other...
Definition: kart_properties.hpp:191
std::vector< int > m_custom_sfx_id
Vector of custom SFX ids.
Definition: kart_properties.hpp:97
std::string m_name
The human readable Name of the kart driver.
Definition: kart_properties.hpp:101
std::shared_ptr< AbstractCharacteristic > m_characteristic
The physical, item, etc.
Definition: kart_properties.hpp:125
float m_collision_terrain_impulse
An additional impulse to push a kart away if it hits terrain.
Definition: kart_properties.hpp:187
std::string m_kart_type
Type of the kart (for the properties)
Definition: kart_properties.hpp:154
static float UNDEFINED
Dummy value to detect unset properties.
Definition: kart_properties.hpp:90
static std::string getHandicapAsString(HandicapLevel h)
Returns the string representation of a handicap level.
Definition: kart_properties.cpp:57
const std::string & getKartType() const
Returns the type of this kart.
Definition: kart_properties.hpp:279
float m_shadow_x_offset
X offset of the shadow plane for this kart.
Definition: kart_properties.hpp:112
float getCollisionTerrainImpulse() const
Returns an artificial impulse to push karts away from the terrain it hits.
Definition: kart_properties.hpp:336
void setHatMeshName(const std::string &hat_name)
Sets the name of a mesh to be used for this kart.
Definition: kart_properties.cpp:394
std::string m_engine_sfx_type
Engine sound effect.
Definition: kart_properties.hpp:163
const Vec3 & getGravityCenterShift() const
Returns a shift of the center of mass (lowering the center of mass makes the karts more stable.
Definition: kart_properties.hpp:331
float getFrictionSlip() const
Returns friction slip.
Definition: kart_properties.hpp:322
Material * getShadowMaterial() const
Returns the shadow texture to use.
Definition: kart_properties.hpp:283
float m_shadow_scale
Scale of the shadow plane for this kart.
Definition: kart_properties.hpp:110
float getAccelerationEfficiency() const
This function returns a weighted average of engine power divide by mass for use as a single number su...
Definition: kart_properties.cpp:693
InterpolationArray m_restitution
Restitution depending on speed.
Definition: kart_properties.hpp:197
std::string m_minimap_icon_file
The minimap icon file.
Definition: kart_properties.hpp:75
TerrainImpulseType
STK can add an impulse to push karts away from the track in case of a kart-track collision.
Definition: kart_properties.hpp:181
int getVersion() const
Returns the version of the .kart file.
Definition: kart_properties.hpp:296
int m_version
Version of the .kart file.
Definition: kart_properties.hpp:93
const Vec3 & getBevelFactor() const
Returns the bevel factor (!=0 indicates to use a bevelled box).
Definition: kart_properties.hpp:370
std::vector< std::string > m_groups
List of all groups the kart belongs to.
Definition: kart_properties.hpp:87
float m_shadow_z_offset
Z offset of the shadow plane for this kart.
Definition: kart_properties.hpp:114
Material * getIconMaterial() const
Returns the material for the kart icons.
Definition: kart_properties.hpp:254
std::shared_ptr< KartModel > m_kart_model
The kart model and wheels.
Definition: kart_properties.hpp:84
void adjustForOnlineAddonKart(const KartProperties *source)
Change the graphical properties (icon, shadow..) for addon kart using in online mode.
Definition: kart_properties.cpp:405
const KartModel & getMasterKartModel() const
Returns a pointer to the main KartModel object.
Definition: kart_properties.hpp:265
Definition: material.hpp:48
Difficulty getDifficulty() const
Returns the difficulty.
Definition: race_manager.hpp:597
A wrapper around bullets btVector3 to include conventient conversion functions (e....
Definition: vec3.hpp:35
utility class used to parse XML files
Definition: xml_node.hpp:48
HandicapLevel
Handicap per player.
Definition: remote_kart_info.hpp:42