SuperTuxKart
abstract_kart.hpp
1 //
2 // SuperTuxKart - a fun racing game with go-kart
3 // Copyright (C) 2012-2015 Joerg Henrichs
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_ABSTRACT_KART_HPP
20 #define HEADER_ABSTRACT_KART_HPP
21 
22 #include <memory>
23 
24 #include "items/powerup_manager.hpp"
25 #include "karts/moveable.hpp"
26 #include "karts/controller/kart_control.hpp"
27 #include "race/race_manager.hpp"
28 
29 namespace irr
30 {
31  namespace scene
32  {
33  class IDummyTransformationSceneNode;
34  }
35 }
36 
38 class Attachment;
39 class btKart;
40 class btQuaternion;
41 class Controller;
42 class Item;
43 class ItemState;
44 class KartGFX;
45 class KartModel;
46 class KartProperties;
47 class Material;
48 class Powerup;
49 class RenderInfo;
50 class SFXBuffer;
51 class Skidding;
52 class SlipStream;
53 class Stars;
54 class TerrainInfo;
55 
56 
61 class AbstractKart : public Moveable
62 {
63 private:
67  float m_kart_width;
74 
76  unsigned int m_world_kart_id;
77 
79  core::stringw m_name;
80 
81  // ------------------------------------------------------------------------
82  void loadKartProperties(const std::string& new_ident,
83  HandicapLevel handicap,
84  std::shared_ptr<RenderInfo> ri);
85 protected:
86  btTransform m_starting_transform;
87 
88  int m_live_join_util;
89 
91  std::unique_ptr<KartProperties> m_kart_properties;
92 
95 
99  std::unique_ptr<KartModel> m_kart_model;
100 
102  std::unique_ptr<Attachment> m_attachment;
103 
106 
109 
111  irr::scene::IDummyTransformationSceneNode *m_wheel_box;
112 public:
113  AbstractKart(const std::string& ident,
114  int world_kart_id,
115  int position, const btTransform& init_transform,
116  HandicapLevel handicap,
117  std::shared_ptr<RenderInfo> ri);
118  virtual ~AbstractKart();
119  // ------------------------------------------------------------------------
121  const core::stringw& getName() const { return m_name; }
122  // ------------------------------------------------------------------------
123  virtual void reset();
124  virtual void init(RaceManager::KartType type) = 0;
125  // ========================================================================
126  // Functions related to controlling the kart
127  // ------------------------------------------------------------------------
129  virtual float getSteerPercent() const { return m_controls.getSteer(); }
130  // ------------------------------------------------------------------------
132  KartControl& getControls() { return m_controls; }
133  // ------------------------------------------------------------------------
135  const KartControl& getControls() const { return m_controls; }
136 
137  // ========================================================================
138  // Access to the kart properties.
139  // ------------------------------------------------------------------------
142  { return m_kart_properties.get(); }
143  // ========================================================================
145  virtual void changeKart(const std::string& new_ident,
146  HandicapLevel handicap,
147  std::shared_ptr<RenderInfo> ri);
148  // ========================================================================
149  // Access to the handicap.
150  // ------------------------------------------------------------------------
152  const HandicapLevel getHandicap() const { return m_handicap; }
153  // ------------------------------------------------------------------------
155  void setHandicap(const HandicapLevel h) { m_handicap=h; }
156 
157  // ------------------------------------------------------------------------
160  virtual const std::string& getIdent() const;
161  // ------------------------------------------------------------------------
164  virtual float getMaxSteerAngle () const = 0;
165  // ------------------------------------------------------------------------
168  virtual float getSpeedForTurnRadius(float radius) const = 0;
169  // ------------------------------------------------------------------------
173  virtual float getTimeFullSteer(float steer) const = 0;
174 
175  // ========================================================================
176  // Attachment related functions.
177  // ------------------------------------------------------------------------
179  const Attachment* getAttachment() const {return m_attachment.get(); }
180  // ------------------------------------------------------------------------
182  Attachment* getAttachment() {return m_attachment.get(); }
183 
184  // ========================================================================
185  // Access to the graphical kart model.
186  // ------------------------------------------------------------------------
188  KartModel* getKartModel() const { return m_kart_model.get(); }
189  // ------------------------------------------------------------------------
191  float getKartLength() const { return m_kart_length; }
192  // ------------------------------------------------------------------------
194  float getKartHeight() const { return m_kart_height; }
195  // ------------------------------------------------------------------------
197  float getKartWidth() const {return m_kart_width; }
198  // ------------------------------------------------------------------------
200  float getHighestPoint() const { return m_kart_highest_point; }
201  // ------------------------------------------------------------------------
206  virtual void kartIsInRestNow();
207 
208  // ------------------------------------------------------------------------
211  virtual float getTimeForDistance(float distance);
212  // ------------------------------------------------------------------------
214  bool isWheeless() const;
215  // ------------------------------------------------------------------------
218  virtual const Vec3& getFrontXYZ() const = 0;
219  // ------------------------------------------------------------------------
223  const Vec3& getWheelGraphicsPosition(int i) const
224  {assert(i>=0 && i<4); return m_wheel_graphics_position[i];}
225 
226  // ========================================================================
227  // Emergency animation related functions.
228  // ------------------------------------------------------------------------
231  AbstractKartAnimation *getKartAnimation() { return m_kart_animation; }
232  // ------------------------------------------------------------------------
233  const AbstractKartAnimation *getKartAnimation() const
234  { return m_kart_animation; }
235  // ------------------------------------------------------------------------
237  virtual void setKartAnimation(AbstractKartAnimation *ka);
238  // ------------------------------------------------------------------------
239 
240  // ------------------------------------------------------------------------
241  // ------------------------------------------------------------------------
243  unsigned int getWorldKartId() const { return m_world_kart_id; }
244  // ------------------------------------------------------------------------
249  virtual void setController(Controller *controller) = 0;
250  // ------------------------------------------------------------------------
252  virtual Controller* getController() = 0;
253  // ------------------------------------------------------------------------
255  virtual const Controller* getController() const = 0;
256  // ------------------------------------------------------------------------
259  virtual const Skidding *getSkidding() const = 0;
260  // ------------------------------------------------------------------------
261  virtual RaceManager::KartType getType() const = 0;
262  // ------------------------------------------------------------------------
265  virtual Skidding *getSkidding() = 0;
266  // ------------------------------------------------------------------------
268  virtual bool isEliminated() const = 0;
269  // ------------------------------------------------------------------------
271  virtual void eliminate() = 0;
272  // ------------------------------------------------------------------------
273  virtual void finishedRace(float time, bool from_server=false) = 0;
274  // ------------------------------------------------------------------------
276  virtual float getFinishTime() const = 0;
277  // ------------------------------------------------------------------------
279  virtual int getBlockedByPlungerTicks() const = 0;
280  // ------------------------------------------------------------------------
283  virtual void blockViewWithPlunger() = 0;
284  // ------------------------------------------------------------------------
286  virtual bool isSquashed() const = 0;
287  // ------------------------------------------------------------------------
293  virtual bool setSquash(float time, float slowdown) = 0;
294  // ------------------------------------------------------------------------
296  virtual void unsetSquash() = 0;
297  // ------------------------------------------------------------------------
301  virtual float getSpeed() const = 0;
302  // ------------------------------------------------------------------------
305  virtual float getCurrentMaxSpeed() const = 0;
306  // ------------------------------------------------------------------------
310  virtual int getSpeedIncreaseTicksLeft(unsigned int category) const = 0;
311 
312  // ------------------------------------------------------------------------
316  virtual void setBoostAI(bool boosted) = 0;
317 
318  // ------------------------------------------------------------------------
321  virtual bool getBoostAI() const = 0;
322 
323  // ------------------------------------------------------------------------
324 
332  virtual void increaseMaxSpeed(unsigned int category, float add_speed,
333  float engine_force, int duration,
334  int fade_out_time) = 0;
335 
336  // ----------------------------------------------------------------------------
348  virtual void instantSpeedIncrease(unsigned int category, float add_max_speed,
349  float speed_boost, float engine_force,
350  int duration, int fade_out_time) = 0;
351 
352  // ------------------------------------------------------------------------
357  virtual void setSlowdown(unsigned int category, float max_speed_fraction,
358  int fade_in_time) = 0;
359  // ------------------------------------------------------------------------
361  virtual float getEnergy() const = 0;
362  // ------------------------------------------------------------------------
366  virtual void collectedItem(ItemState *item_state) = 0;
367  // ------------------------------------------------------------------------
369  virtual int getPosition() const = 0;
370  // ------------------------------------------------------------------------
372  virtual void setPosition(int p) = 0;
373  // ------------------------------------------------------------------------
375  virtual int getInitialPosition() const = 0;
376  // ------------------------------------------------------------------------
378  virtual bool isOnGround() const = 0;
379  // ------------------------------------------------------------------------
381  virtual const SlipStream* getSlipstream() const = 0;
382  // ------------------------------------------------------------------------
384  virtual SlipStream* getSlipstream() = 0;
385  // ------------------------------------------------------------------------
387  virtual void setSlipstreamEffect(float f) = 0;
388  // ------------------------------------------------------------------------
390  virtual void beep() = 0;
391  // ------------------------------------------------------------------------
396  virtual bool playCustomSFX(unsigned int type) = 0;
397  // ------------------------------------------------------------------------
399  virtual void showZipperFire() = 0;
400  // ------------------------------------------------------------------------
405  virtual void handleZipper(const Material *m=NULL,
406  bool play_sound=false) = 0;
407  // ------------------------------------------------------------------------
409  virtual bool hasFinishedRace() const = 0;
410  // ------------------------------------------------------------------------
411  virtual void setEnergy(float val) = 0;
412  // ------------------------------------------------------------------------
416  virtual bool isOnMinNitroTime() const = 0;
417  // ------------------------------------------------------------------------
419  virtual const Material *getMaterial() const = 0;
420  // ------------------------------------------------------------------------
423  virtual const Material *getLastMaterial() const = 0;
424  // ------------------------------------------------------------------------
426  virtual const Powerup *getPowerup() const = 0;
427  // ------------------------------------------------------------------------
429  virtual Powerup *getPowerup() = 0;
430  // ------------------------------------------------------------------------
432  virtual PowerupManager::PowerupType getLastUsedPowerup() = 0;
433  // ------------------------------------------------------------------------
435  virtual int getNumPowerup() const = 0;
436  // ------------------------------------------------------------------------
438  virtual KartGFX* getKartGFX() = 0;
439  // ------------------------------------------------------------------------
440  virtual void setPowerup (PowerupManager::PowerupType t, int n) = 0;
441  // ------------------------------------------------------------------------
443  virtual btKart* getVehicle() const = 0;
444  // ------------------------------------------------------------------------
445  virtual btQuaternion getVisualRotation() const = 0;
446  // ------------------------------------------------------------------------
448  virtual bool isInRest() const = 0;
449  // ------------------------------------------------------------------------
452  virtual void startEngineSFX() = 0;
453  // ------------------------------------------------------------------------
457  virtual void adjustSpeed(float f) = 0;
458  // ------------------------------------------------------------------------
461  virtual void setSpeed(float s) = 0;
462  // ------------------------------------------------------------------------
464  virtual bool isInvulnerable() const = 0;
465  // ------------------------------------------------------------------------
466  virtual void setInvulnerableTicks(int ticks) = 0;
467  // ------------------------------------------------------------------------
469  virtual bool isShielded() const = 0;
470  // ------------------------------------------------------------------------
471  virtual void setShieldTime(float t) = 0;
472  // ------------------------------------------------------------------------
473  virtual float getShieldTime() const = 0;
474  // ------------------------------------------------------------------------
476  virtual void decreaseShieldTime() = 0;
477  // ------------------------------------------------------------------------
478 
480  virtual void showStarEffect(float t) = 0;
481  // ------------------------------------------------------------------------
483  virtual const TerrainInfo *getTerrainInfo() const = 0;
484  // ------------------------------------------------------------------------
489  virtual void crashed(AbstractKart *k, bool update_attachments) = 0;
490  // ------------------------------------------------------------------------
491  virtual void crashed(const Material *m, const Vec3 &normal) = 0;
492  // ------------------------------------------------------------------------
495  virtual const Vec3& getNormal() const = 0;
496  // ------------------------------------------------------------------------
498  virtual const Vec3& getPreviousXYZ() const = 0;
499  // ------------------------------------------------------------------------
501  virtual const Vec3& getRecentPreviousXYZ() const = 0;
502  // ------------------------------------------------------------------------
504  virtual const float getRecentPreviousXYZTime() const = 0;
505  // ------------------------------------------------------------------------
507  virtual float getHoT() const = 0;
508  // ------------------------------------------------------------------------
510  virtual float getTerrainPitch(float heading) const = 0;
511  // -------------------------------------------------------------------------
515  virtual btTransform getAlignedTransform(const float customPitch=-1) = 0;
516  // -------------------------------------------------------------------------
519  virtual void setOnScreenText(const core::stringw& text) = 0;
520  // ------------------------------------------------------------------------
522  virtual bool getRaceResult() const = 0;
523  // ------------------------------------------------------------------------
525  virtual bool isGhostKart() const = 0;
526  // ------------------------------------------------------------------------
528  virtual bool isJumping() const = 0;
529  // ------------------------------------------------------------------------
530  virtual void playSound(SFXBuffer* buffer) = 0;
531  // ------------------------------------------------------------------------
532  virtual bool isVisible() const = 0;
533  // ------------------------------------------------------------------------
534  virtual void makeKartRest();
535  // ------------------------------------------------------------------------
536  virtual void setStartupBoost(float val) = 0;
537  // ------------------------------------------------------------------------
538  virtual float getStartupBoost() const = 0;
539  // ------------------------------------------------------------------------
540  virtual float getStartupBoostFromStartTicks(int ticks) const = 0;
541  // ------------------------------------------------------------------------
542  virtual Stars* getStarsEffect() const = 0;
543  // ------------------------------------------------------------------------
544  int getLiveJoinUntilTicks() const { return m_live_join_util; }
545  // ------------------------------------------------------------------------
546  void setLiveJoinKart(int util_ticks) { m_live_join_util = util_ticks; }
547  // ------------------------------------------------------------------------
550  virtual int getNetworkConfirmedFinishTicks() const = 0;
551 }; // AbstractKart
552 
553 
554 #endif
555 
556 /* EOF */
unsigned int m_world_kart_id
Index of kart in world.
Definition: abstract_kart.hpp:76
HandicapLevel
Handicap per player.
Definition: remote_kart_info.hpp:39
Definition: kart_gfx.hpp:39
This is the base class for kart controller - that can be a player or a a robot.
Definition: controller.hpp:45
std::unique_ptr< Attachment > m_attachment
Handles the attachment the kart might have.
Definition: abstract_kart.hpp:102
std::unique_ptr< KartModel > m_kart_model
This stores a copy of the kart model.
Definition: abstract_kart.hpp:99
unsigned int getWorldKartId() const
Returns the index of this kart in world.
Definition: abstract_kart.hpp:243
rayCast vehicle, very special constraint that turn a rigidbody into a vehicle.
Definition: btKart.hpp:31
const Vec3 * m_wheel_graphics_position
The position of all four wheels in the 3d model.
Definition: abstract_kart.hpp:73
virtual float getSteerPercent() const
Returns the current steering value for this kart.
Definition: abstract_kart.hpp:129
A wrapper around bullets btVector3 to include conventient conversion functions (e.g.
Definition: vec3.hpp:34
const core::stringw & getName() const
Returns a name to be displayed for this kart.
Definition: abstract_kart.hpp:121
const Vec3 & getWheelGraphicsPosition(int i) const
Returns the position of a wheel relative to the kart.
Definition: abstract_kart.hpp:223
float getKartLength() const
Returns the length of the kart.
Definition: abstract_kart.hpp:191
This objects is permanently available in a kart and stores information about addons.
Definition: attachment.hpp:51
void changeKart(int idKart, std::string *new_id)
Gets the maximum speed (velocity) a kart can reach.
Definition: script_kart.cpp:144
HandicapLevel m_handicap
The handicap level of this kart.
Definition: abstract_kart.hpp:94
KartType
Different kart types: A local player, a player connected via network, an AI kart, the leader kart (cu...
Definition: race_manager.hpp:241
Definition: three_d_animation.hpp:32
irr::scene::IDummyTransformationSceneNode * m_wheel_box
Node between wheels and kart.
Definition: abstract_kart.hpp:111
float m_kart_width
Width of the kart, copy of the data from KartModel.
Definition: abstract_kart.hpp:67
float getHighestPoint() const
Returns the highest point of the kart (coordinate on up axis)
Definition: abstract_kart.hpp:200
const HandicapLevel getHandicap() const
Returns the handicap of this kart.
Definition: abstract_kart.hpp:152
The buffer (data) for one kind of sound effects.
Definition: sfx_buffer.hpp:43
AbstractKartAnimation * getKartAnimation()
Returns a kart animation (if any), or NULL if currently no kart animation is being shown...
Definition: abstract_kart.hpp:231
float getKartWidth() const
Returns the width of the kart.
Definition: abstract_kart.hpp:197
float getKartHeight() const
Returns the height of the kart.
Definition: abstract_kart.hpp:194
KartModel * getKartModel() const
Returns this kart&#39;s kart model.
Definition: abstract_kart.hpp:188
const Attachment * getAttachment() const
Returns the current attachment.
Definition: abstract_kart.hpp:179
AbstractKartAnimation * m_kart_animation
A kart animation object to handle rescue, explosion etc.
Definition: abstract_kart.hpp:108
Definition: powerup.hpp:37
KartControl m_controls
The kart controls (e.g.
Definition: abstract_kart.hpp:105
void playSound(const std::string *sound_name)
Plays a sound by name.
Definition: script_audio.cpp:43
Definition: skidding.hpp:39
Definition: kart_control.hpp:29
const KartControl & getControls() const
Returns all controls of this kart - const version.
Definition: abstract_kart.hpp:135
KartControl & getControls()
Returns all controls of this kart.
Definition: abstract_kart.hpp:132
Definition: item.hpp:323
This class stores information about the triangle that&#39;s under an object, i.e.
Definition: terrain_info.hpp:31
This class is used to display rotating stars around a kart&#39;s head.
Definition: stars.hpp:40
This class stores a 3D kart model.
Definition: kart_model.hpp:167
core::stringw m_name
Name of the kart with translation.
Definition: abstract_kart.hpp:79
float m_kart_highest_point
Coordinate on up axis.
Definition: abstract_kart.hpp:71
float m_kart_height
Height of the kart, copy of the data from KartModel.
Definition: abstract_kart.hpp:69
Definition: material.hpp:47
This class stores the properties of a kart.
Definition: kart_properties.hpp:59
void setHandicap(const HandicapLevel h)
Sets the handicap.
Definition: abstract_kart.hpp:155
const KartProperties * getKartProperties() const
Returns the kart properties of this kart.
Definition: abstract_kart.hpp:141
float getSteer() const
Returns the current steering value in [-1, 1].
Definition: kart_control.hpp:128
Definition: render_info.hpp:27
std::unique_ptr< KartProperties > m_kart_properties
The kart properties.
Definition: abstract_kart.hpp:91
Definition: moveable.hpp:44
The base class for all kart animation, like rescue, explosion, or cannon.
Definition: abstract_kart_animation.hpp:59
float m_kart_length
Length of the kart, copy of the data from KartModel.
Definition: abstract_kart.hpp:65
Contains the state information of an item, i.e.
Definition: item.hpp:52
An abstract interface for the actual karts.
Definition: abstract_kart.hpp:61
Attachment * getAttachment()
Returns the current attachment, non-const version.
Definition: abstract_kart.hpp:182
Definition: slip_stream.hpp:47