SuperTuxKart
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>
28 namespace irr
29 {
30  namespace video { class ITexture; }
31 }
32 using 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 
40 class AIProperties;
43 class KartModel;
44 class Material;
45 class RenderInfo;
46 class XMLNode;
47 
48 
60 {
61 private:
63  std::string m_root;
64 
69  std::shared_ptr<AIProperties> m_ai_properties[RaceManager::DIFFICULTY_COUNT];
70 
73 
75  std::string m_minimap_icon_file;
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 
93  int m_version;
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;
119  int m_shape;
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 
174 public:
181  enum TerrainImpulseType {IMPULSE_NONE, IMPULSE_NORMAL,
182  IMPULSE_TO_DRIVELINE};
183 private:
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 public:
214  static std::string getHandicapAsString(HandicapLevel h);
215 
216  KartProperties (const std::string &filename="");
217  ~KartProperties ();
218  void copyForPlayer (const KartProperties *source,
219  HandicapLevel h = HANDICAP_NONE);
220  void adjustForOnlineAddonKart(const KartProperties* source);
221  void updateForOnlineKart(const std::string& id, const Vec3& gravity_shift,
222  float kart_length)
223  {
224  m_ident = id;
225  m_gravity_center_shift = gravity_shift;
226  setWheelBase(kart_length);
227  }
228  void copyFrom (const KartProperties *source);
229  void getAllData (const XMLNode * root);
230  void checkAllSet (const std::string &filename);
231  bool isInGroup (const std::string &group) const;
232  bool operator<(const KartProperties &other) const;
233 
234  // ------------------------------------------------------------------------
236  const AbstractCharacteristic* getCharacteristic() const;
237  // ------------------------------------------------------------------------
242  const AbstractCharacteristic* getCombinedCharacteristic() const;
243 
244  // ------------------------------------------------------------------------
246  Material* getIconMaterial () const {return m_icon_material; }
247 
248  // ------------------------------------------------------------------------
250  video::ITexture *getMinimapIcon () const {return m_minimap_icon; }
251 
252  // ------------------------------------------------------------------------
253  KartModel* getKartModelCopy(std::shared_ptr<RenderInfo> ri=nullptr) const;
254  // ------------------------------------------------------------------------
257  const KartModel& getMasterKartModel() const {return *m_kart_model; }
258  // ------------------------------------------------------------------------
259  void setHatMeshName(const std::string &hat_name);
260  // ------------------------------------------------------------------------
261  core::stringw getName() const;
262  // ------------------------------------------------------------------------
263  const std::string getNonTranslatedName() const {return m_name;}
264 
265  // ------------------------------------------------------------------------
267  const std::string& getIdent () const {return m_ident; }
268 
269  // ------------------------------------------------------------------------
271  const std::string& getKartType () const { return m_kart_type; }
272 
273  // ------------------------------------------------------------------------
275  Material* getShadowMaterial() const { return m_shadow_material; }
276 
277  // ------------------------------------------------------------------------
279  const std::string& getAbsoluteIconFile() const { return m_icon_file; }
280 
281  // ------------------------------------------------------------------------
283  const int getCustomSfxId (int type)
284  const {return m_custom_sfx_id[type]; }
285 
286  // ------------------------------------------------------------------------
288  int getVersion () const {return m_version; }
289 
290  // ------------------------------------------------------------------------
292  const video::SColor &getColor () const {return m_color; }
293 
294  // ------------------------------------------------------------------------
297  int getShape () const {return m_shape; }
298 
299  // ------------------------------------------------------------------------
301  const std::vector<std::string>&
302  getGroups () const {return m_groups; }
303 
304  // ------------------------------------------------------------------------
306  const std::string& getEngineSfxType () const {return m_engine_sfx_type;}
307  // ------------------------------------------------------------------------
309  const std::string& getSkidSound () const {return m_skid_sound; }
310 
311  // Bullet physics get functions
312  //-----------------------------
314  float getFrictionSlip () const {return m_friction_slip; }
315 
316  // ------------------------------------------------------------------------
318  float getWheelBase () const {return m_wheel_base; }
319 
320  // ------------------------------------------------------------------------
323  const Vec3&getGravityCenterShift() const {return m_gravity_center_shift; }
324 
325  // ------------------------------------------------------------------------
329  {return m_collision_terrain_impulse;}
330 
331  // ------------------------------------------------------------------------
335  { return m_terrain_impulse_type; }
336  // ------------------------------------------------------------------------
339  float getCollisionImpulse () const {return m_collision_impulse;}
340 
341  // ------------------------------------------------------------------------
343  float getCollisionImpulseTime() const { return m_collision_impulse_time;}
344 
345  // ------------------------------------------------------------------------
347  float getRestitution(float speed) const { return m_restitution.get(speed);}
348 
349  // ------------------------------------------------------------------------
352  {
353  return m_ai_properties[RaceManager::get()->getDifficulty()].get();
354  } // getAIProperties
355 
356  // ------------------------------------------------------------------------
358  const std::string& getKartDir () const {return m_root; }
359 
360  // ------------------------------------------------------------------------
362  const Vec3 &getBevelFactor() const { return m_bevel_factor; }
363  // ------------------------------------------------------------------------
369  const float getPhysicalWheelPosition() const
370  {
371  return m_physical_wheel_position;
372  } // getPhysicalWheelPosition
373 
374  // ------------------------------------------------------------------------
375  float getAccelerationEfficiency() const;
376  // ------------------------------------------------------------------------
381  { return m_nitro_min_consumption; }
382  // ------------------------------------------------------------------------
383  bool isAddon() const { return m_is_addon; }
384 
385  // Script-generated content generated by tools/create_kart_properties.py defs
386  // Please don't change the following tag. It will be automatically detected
387  // by the script and replace the contained content.
388  // To update the code, use tools/update_characteristics.py
389  /* <characteristics-start kpdefs> */
390 
391  float getSuspensionStiffness() const;
392  float getSuspensionRest() const;
393  float getSuspensionTravel() const;
394  bool getSuspensionExpSpringResponse() const;
395  float getSuspensionMaxForce() const;
396 
397  float getStabilityRollInfluence() const;
398  float getStabilityChassisLinearDamping() const;
399  float getStabilityChassisAngularDamping() const;
400  float getStabilityDownwardImpulseFactor() const;
401  float getStabilityTrackConnectionAccel() const;
402  std::vector<float> getStabilityAngularFactor() const;
403  float getStabilitySmoothFlyingImpulse() const;
404 
405  InterpolationArray getTurnRadius() const;
406  float getTurnTimeResetSteer() const;
407  InterpolationArray getTurnTimeFullSteer() const;
408 
409  float getEnginePower() const;
410  float getEngineMaxSpeed() const;
411  float getEngineGenericMaxSpeed() const;
412  float getEngineBrakeFactor() const;
413  float getEngineBrakeTimeIncrease() const;
414  float getEngineMaxSpeedReverseRatio() const;
415 
416  std::vector<float> getGearSwitchRatio() const;
417  std::vector<float> getGearPowerIncrease() const;
418 
419  float getMass() const;
420 
421  float getWheelsDampingRelaxation() const;
422  float getWheelsDampingCompression() const;
423 
424  float getJumpAnimationTime() const;
425 
426  float getLeanMax() const;
427  float getLeanSpeed() const;
428 
429  float getAnvilDuration() const;
430  float getAnvilWeight() const;
431  float getAnvilSpeedFactor() const;
432 
433  float getParachuteFriction() const;
434  float getParachuteDuration() const;
435  float getParachuteDurationOther() const;
436  float getParachuteDurationRankMult() const;
437  float getParachuteDurationSpeedMult() const;
438  float getParachuteLboundFraction() const;
439  float getParachuteUboundFraction() const;
440  float getParachuteMaxSpeed() const;
441 
442  float getFrictionKartFriction() const;
443 
444  float getBubblegumDuration() const;
445  float getBubblegumSpeedFraction() const;
446  float getBubblegumTorque() const;
447  float getBubblegumFadeInTime() const;
448  float getBubblegumShieldDuration() const;
449 
450  float getZipperDuration() const;
451  float getZipperForce() const;
452  float getZipperSpeedGain() const;
453  float getZipperMaxSpeedIncrease() const;
454  float getZipperFadeOutTime() const;
455 
456  float getSwatterDuration() const;
457  float getSwatterDistance() const;
458  float getSwatterSquashDuration() const;
459  float getSwatterSquashSlowdown() const;
460 
461  float getPlungerBandMaxLength() const;
462  float getPlungerBandForce() const;
463  float getPlungerBandDuration() const;
464  float getPlungerBandSpeedIncrease() const;
465  float getPlungerBandFadeOutTime() const;
466  float getPlungerInFaceTime() const;
467 
468  std::vector<float> getStartupTime() const;
469  std::vector<float> getStartupBoost() const;
470 
471  float getRescueDuration() const;
472  float getRescueVertOffset() const;
473  float getRescueHeight() const;
474 
475  float getExplosionDuration() const;
476  float getExplosionRadius() const;
477  float getExplosionInvulnerabilityTime() const;
478 
479  float getNitroDuration() const;
480  float getNitroEngineForce() const;
481  float getNitroEngineMult() const;
482  float getNitroConsumption() const;
483  float getNitroSmallContainer() const;
484  float getNitroBigContainer() const;
485  float getNitroMaxSpeedIncrease() const;
486  float getNitroFadeOutTime() const;
487  float getNitroMax() const;
488 
489  float getSlipstreamDurationFactor() const;
490  float getSlipstreamBaseSpeed() const;
491  float getSlipstreamLength() const;
492  float getSlipstreamWidth() const;
493  float getSlipstreamInnerFactor() const;
494  float getSlipstreamMinCollectTime() const;
495  float getSlipstreamMaxCollectTime() const;
496  float getSlipstreamAddPower() const;
497  float getSlipstreamMinSpeed() const;
498  float getSlipstreamMaxSpeedIncrease() const;
499  float getSlipstreamFadeOutTime() const;
500 
501  float getSkidIncrease() const;
502  float getSkidDecrease() const;
503  float getSkidMax() const;
504  float getSkidTimeTillMax() const;
505  float getSkidVisual() const;
506  float getSkidVisualTime() const;
507  float getSkidRevertVisualTime() const;
508  float getSkidMinSpeed() const;
509  std::vector<float> getSkidTimeTillBonus() const;
510  std::vector<float> getSkidBonusSpeed() const;
511  std::vector<float> getSkidBonusTime() const;
512  std::vector<float> getSkidBonusForce() const;
513  float getSkidPhysicalJumpTime() const;
514  float getSkidGraphicalJumpTime() const;
515  float getSkidPostSkidRotateFactor() const;
516  float getSkidReduceTurnMin() const;
517  float getSkidReduceTurnMax() const;
518  bool getSkidEnabled() const;
519 
520  /* <characteristics-end kpdefs> */
521 
522  LEAK_CHECK()
523 }; // KartProperties
524 
525 #endif
526 
std::string m_engine_sfx_type
Engine sound effect.
Definition: kart_properties.hpp:163
HandicapLevel
Handicap per player.
Definition: remote_kart_info.hpp:39
const std::string & getSkidSound() const
Returns the skid sound.
Definition: kart_properties.hpp:309
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
int getVersion() const
Returns the version of the .kart file.
Definition: kart_properties.hpp:288
float getFrictionSlip() const
Returns friction slip.
Definition: kart_properties.hpp:314
float m_wheel_base
Wheel base of the kart.
Definition: kart_properties.hpp:160
std::string m_root
Base directory for this kart.
Definition: kart_properties.hpp:63
A wrapper around bullets btVector3 to include conventient conversion functions (e.g.
Definition: vec3.hpp:34
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:380
Material * m_icon_material
The absolute path of the icon texture to use.
Definition: kart_properties.hpp:72
const std::string & getIdent() const
Returns the internal identifier of this kart.
Definition: kart_properties.hpp:267
int m_version
Version of the .kart file.
Definition: kart_properties.hpp:93
std::string m_ident
The computer readable-name of the kart driver.
Definition: kart_properties.hpp:103
float m_shadow_x_offset
X offset of the shadow plane for this kart.
Definition: kart_properties.hpp:112
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:297
video::ITexture * getMinimapIcon() const
Returns the texture to use in the minimap, or NULL if not defined.
Definition: kart_properties.hpp:250
const KartModel & getMasterKartModel() const
Returns a pointer to the main KartModel object.
Definition: kart_properties.hpp:257
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
Definition: three_d_animation.hpp:32
std::vector< std::string > m_groups
List of all groups the kart belongs to.
Definition: kart_properties.hpp:87
A simple class that stores all AI related properties.
Definition: ai_properties.hpp:39
Material * m_shadow_material
The texture with the shadow.
Definition: kart_properties.hpp:116
const AIProperties * getAIPropertiesForDifficulty() const
Returns a pointer to the AI properties.
Definition: kart_properties.hpp:351
Difficulty getDifficulty() const
Returns the difficulty.
Definition: race_manager.hpp:596
const std::string & getAbsoluteIconFile() const
Returns the absolute path of the icon file of this kart.
Definition: kart_properties.hpp:279
std::string m_kart_type
Type of the kart (for the properties)
Definition: kart_properties.hpp:154
const int getCustomSfxId(int type) const
Returns custom sound effects for this kart.
Definition: kart_properties.hpp:283
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:339
video::SColor m_color
Color the represents the kart in the status bar and on the track-view.
Definition: kart_properties.hpp:117
const std::vector< std::string > & getGroups() const
Returns the list of groups this kart belongs to.
Definition: kart_properties.hpp:302
Definition: cached_characteristic.hpp:26
float m_shadow_z_offset
Z offset of the shadow plane for this kart.
Definition: kart_properties.hpp:114
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
const std::string & getKartDir() const
Returns the full path where the files for this kart are stored.
Definition: kart_properties.hpp:358
int m_shape
Number of vertices in polygon when drawing the dot on the mini map.
Definition: kart_properties.hpp:119
float getCollisionTerrainImpulse() const
Returns an artificial impulse to push karts away from the terrain it hits.
Definition: kart_properties.hpp:328
std::shared_ptr< AbstractCharacteristic > m_characteristic
The physical, item, etc.
Definition: kart_properties.hpp:125
Characteristics are the properties of a kart that influence gameplay mechanics.
Definition: abstract_characteristic.hpp:42
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
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:369
This class stores a 3D kart model.
Definition: kart_model.hpp:167
float m_shadow_scale
Scale of the shadow plane for this kart.
Definition: kart_properties.hpp:110
This class manages a set of (x_i,y_i) points, x_i must be sorted.
Definition: interpolation_array.hpp:31
Definition: material.hpp:47
This class stores the properties of a kart.
Definition: kart_properties.hpp:59
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
Material * getShadowMaterial() const
Returns the shadow texture to use.
Definition: kart_properties.hpp:275
Vec3 m_gravity_center_shift
Shift of center of gravity.
Definition: kart_properties.hpp:172
std::vector< int > m_custom_sfx_id
Vector of custom SFX ids.
Definition: kart_properties.hpp:97
std::shared_ptr< KartModel > m_kart_model
The kart model and wheels.
Definition: kart_properties.hpp:84
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:323
Definition: combined_characteristic.hpp:26
float getWheelBase() const
Returns the wheel base (distance front to rear axis).
Definition: kart_properties.hpp:318
utility class used to parse XML files
Definition: xml_node.hpp:47
const Vec3 & getBevelFactor() const
Returns the bevel factor (!=0 indicates to use a bevelled box).
Definition: kart_properties.hpp:362
std::shared_ptr< CombinedCharacteristic > m_combined_characteristic
The base characteristics combined with the characteristics of this kart.
Definition: kart_properties.hpp:127
const std::string & getEngineSfxType() const
Returns the engine type (used to change sfx depending on kart size).
Definition: kart_properties.hpp:306
float m_collision_terrain_impulse
An additional impulse to push a kart away if it hits terrain.
Definition: kart_properties.hpp:187
Definition: render_info.hpp:27
Material * getIconMaterial() const
Returns the material for the kart icons.
Definition: kart_properties.hpp:246
float get(float x) const
Returns the interpolated Y value for a given x.
Definition: interpolation_array.hpp:101
float m_collision_impulse_time
How long the collision impulse should be applied.
Definition: kart_properties.hpp:194
const video::SColor & getColor() const
Returns the dot color to use for this kart in the race gui.
Definition: kart_properties.hpp:292
TerrainImpulseType getTerrainImpulseType() const
Returns what kind of impulse STK should use in case of a kart-track collision.
Definition: kart_properties.hpp:334
std::string m_name
The human readable Name of the kart driver.
Definition: kart_properties.hpp:101
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
static float UNDEFINED
Dummy value to detect unset properties.
Definition: kart_properties.hpp:90
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
const std::string & getKartType() const
Returns the type of this kart.
Definition: kart_properties.hpp:271
float getRestitution(float speed) const
Returns the restitution factor for this kart.
Definition: kart_properties.hpp:347
std::string m_minimap_icon_file
The minimap icon file.
Definition: kart_properties.hpp:75
std::shared_ptr< CachedCharacteristic > m_cached_characteristic
The cached combined characteristics.
Definition: kart_properties.hpp:129
float getCollisionImpulseTime() const
Returns how long the collision impulse should be applied.
Definition: kart_properties.hpp:343
InterpolationArray m_restitution
Restitution depending on speed.
Definition: kart_properties.hpp:197