SuperTuxKart
attachment.hpp
1 //
2 // SuperTuxKart - a fun racing game with go-kart
3 // Copyright (C) 2006-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_ATTACHMENT_HPP
20 #define HEADER_ATTACHMENT_HPP
21 
22 #include "items/attachment_plugin.hpp"
23 #include "utils/no_copy.hpp"
24 #include "utils/types.hpp"
25 
26 using namespace irr;
27 
28 namespace irr
29 {
30  namespace scene { class IAnimatedMeshSceneNode; }
31 }
32 
33 class AbstractKart;
34 class BareNetworkString;
35 class ItemState;
36 class SFXBase;
37 
51 class Attachment: public NoCopy
52 {
53 public:
54  // Some loop in attachment.cpp depend on ATTACH_FIRST and ATTACH_MAX.
55  // So if new elements are added, make sure to add them in between those values.
56  // Also, please note that Attachment::Attachment relies on ATTACH_FIRST being 0.
57  enum AttachmentType
58  {
59  ATTACH_FIRST = 0,
60  // It is important that parachute, bomb and anvil stay in this order,
61  // since the attachment type is mapped to a random integer (and bomb
62  // must be last, since a bomb will not be given in battle mode).
63  ATTACH_PARACHUTE = 0,
64  ATTACH_ANVIL = 1,
65  ATTACH_BOMB = 2,
66  // End of fixed order attachments, the rest can be changed.
67  ATTACH_SWATTER,
68  // Note that the next 2 symbols are only used as an index into the mesh
69  // array; it will NEVER be actually assigned as an attachment type
70  ATTACH_NOLOKS_SWATTER,
71  ATTACH_SWATTER_ANIM,
72  ATTACH_BUBBLEGUM_SHIELD,
73  ATTACH_NOLOK_BUBBLEGUM_SHIELD,
74  ATTACH_MAX,
75  ATTACH_NOTHING
76  };
77 
78 private:
80  AttachmentType m_type;
81 
83  AttachmentType m_graphical_type;
84 
87 
89  int16_t m_ticks_left;
90 
92  int16_t m_initial_speed;
93 
96 
99  scene::IAnimatedMeshSceneNode
101 
104 
108 
111 
114 
115 public:
116  Attachment(AbstractKart* kart);
117  ~Attachment();
118  void clear();
119  void hitBanana(ItemState *item);
120  void updateGraphics(float dt);
121 
122  void update(int ticks);
123  void handleCollisionWithKart(AbstractKart *other);
124  void set (AttachmentType type, int ticks,
125  AbstractKart *previous_kart=NULL,
126  bool set_by_rewind_parachute = false);
127  void rewindTo(BareNetworkString *buffer);
128  void saveState(BareNetworkString *buffer) const;
129 
130  // ------------------------------------------------------------------------
132  void set (AttachmentType type) { set(type, m_ticks_left); }
133  // ------------------------------------------------------------------------
135  AttachmentType getType() const { return m_type; }
136  // ------------------------------------------------------------------------
139  int16_t getTicksLeft() const { return m_ticks_left; }
140  // ------------------------------------------------------------------------
142  void setTicksLeft(int16_t t) { m_ticks_left = t; }
143  // ------------------------------------------------------------------------
146  AbstractKart* getPreviousOwner() const { return m_previous_owner; }
147  // ------------------------------------------------------------------------
149  float weightAdjust() const;
150  // ------------------------------------------------------------------------
152  scene::IAnimatedMeshSceneNode* getNode() {return m_node;}
153  // ------------------------------------------------------------------------
154  void reset()
155  {
156  clear();
157  m_scaling_end_ticks = -1;
158  }
159 
160 }; // Attachment
161 
162 #endif
AttachmentType m_graphical_type
Graphical Attachment type (comparing in updateGraphics).
Definition: attachment.hpp:83
SFXBase * m_bubble_explode_sound
Sound for exploding bubble gum shield.
Definition: attachment.hpp:113
AttachmentPlugin * m_plugin
An optional attachment - additional functionality can be implemented for certain attachments.
Definition: attachment.hpp:107
This objects is permanently available in a kart and stores information about addons.
Definition: attachment.hpp:51
AttachmentType m_type
Attachment type.
Definition: attachment.hpp:80
int16_t m_ticks_left
Time left till attachment expires.
Definition: attachment.hpp:89
int16_t getTicksLeft() const
Returns how much time (in ticks) is left before this attachment is removed.
Definition: attachment.hpp:139
Definition: three_d_animation.hpp:32
scene::IAnimatedMeshSceneNode * getNode()
Return the currently associated scene node (used by e.g the swatter)
Definition: attachment.hpp:152
Declares the general types that are used by the network.
AbstractKart * m_previous_owner
Used by bombs so that it's not passed back to previous owner.
Definition: attachment.hpp:103
void setTicksLeft(int16_t t)
Sets how long this attachment will remain attached.
Definition: attachment.hpp:142
AbstractKart * getPreviousOwner() const
Returns the previous owner of this attachment, used in bombs that are being passed between karts...
Definition: attachment.hpp:146
AbstractKart * m_kart
Kart the attachment is attached to.
Definition: attachment.hpp:86
Utility class, you can inherit from this class to disallow the assignment operator and copy construct...
Definition: no_copy.hpp:25
AttachmentType getType() const
Returns the type of this attachment.
Definition: attachment.hpp:135
Describes a chain of 8-bit unsigned integers.
Definition: network_string.hpp:52
scene::IAnimatedMeshSceneNode * m_node
Scene node of the attachment, which will be attached to the kart's scene node.
Definition: attachment.hpp:100
int m_scaling_end_ticks
For zoom-in animation.
Definition: attachment.hpp:95
This is the base class for a plugin into an attachment.
Definition: attachment_plugin.hpp:38
The base class for sound effects.
Definition: sfx_base.hpp:42
int16_t m_initial_speed
For parachutes only, stored in cm/s for networking.
Definition: attachment.hpp:92
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
SFXBase * m_bomb_sound
Ticking sound for the bomb.
Definition: attachment.hpp:110