SuperTuxKart
Loading...
Searching...
No Matches
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
26using namespace irr;
27
28namespace irr
29{
30 namespace scene { class IAnimatedMeshSceneNode; }
31}
32
33class AbstractKart;
35class ItemState;
36class SFXBase;
37
51class Attachment: public NoCopy
52{
53public:
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
78private:
80 AttachmentType m_type;
81
83 AttachmentType m_graphical_type;
84
87
89 int16_t m_ticks_left;
90
93
96
99 scene::IAnimatedMeshSceneNode
101
104
108
111
114
115public:
117 ~Attachment();
118 void clear();
119 void hitBanana(ItemState *item);
120 void updateGraphics(float dt);
121
122 void update(int ticks);
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 // ------------------------------------------------------------------------
147 // ------------------------------------------------------------------------
149 float weightAdjust() const;
150 // ------------------------------------------------------------------------
152 scene::IAnimatedMeshSceneNode* getNode() {return m_node;}
153 // ------------------------------------------------------------------------
154 void reset()
155 {
156 clear();
158 }
159
160}; // Attachment
161
162#endif
An abstract interface for the actual karts.
Definition: abstract_kart.hpp:62
This is the base class for a plugin into an attachment.
Definition: attachment_plugin.hpp:39
This objects is permanently available in a kart and stores information about addons.
Definition: attachment.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
void set(AttachmentType type)
Sets the type of the attachment, but keeps the old time left value.
Definition: attachment.hpp:132
AbstractKart * m_previous_owner
Used by bombs so that it's not passed back to previous owner.
Definition: attachment.hpp:103
void clear()
Removes any attachement currently on the kart.
Definition: attachment.cpp:179
scene::IAnimatedMeshSceneNode * getNode()
Return the currently associated scene node (used by e.g the swatter)
Definition: attachment.hpp:152
void rewindTo(BareNetworkString *buffer)
Called from the kart rewinder when resetting to a certain state.
Definition: attachment.cpp:222
void set(AttachmentType type, int ticks, AbstractKart *previous_kart=NULL, bool set_by_rewind_parachute=false)
Sets the attachment a kart has.
Definition: attachment.cpp:116
void saveState(BareNetworkString *buffer) const
Saves the attachment state.
Definition: attachment.cpp:196
SFXBase * m_bomb_sound
Ticking sound for the bomb.
Definition: attachment.hpp:110
AttachmentType getType() const
Returns the type of this attachment.
Definition: attachment.hpp:135
AttachmentType m_graphical_type
Graphical Attachment type (comparing in updateGraphics).
Definition: attachment.hpp:83
int16_t m_initial_speed
For parachutes only, stored in cm/s for networking.
Definition: attachment.hpp:92
AttachmentType m_type
Attachment type.
Definition: attachment.hpp:80
SFXBase * m_bubble_explode_sound
Sound for exploding bubble gum shield.
Definition: attachment.hpp:113
~Attachment()
Removes the attachment object.
Definition: attachment.cpp:87
int m_scaling_end_ticks
For zoom-in animation.
Definition: attachment.hpp:95
void hitBanana(ItemState *item)
Selects the new attachment.
Definition: attachment.cpp:270
AbstractKart * getPreviousOwner() const
Returns the previous owner of this attachment, used in bombs that are being passed between karts.
Definition: attachment.hpp:146
void handleCollisionWithKart(AbstractKart *other)
Updates the attachments in case of a kart-kart collision.
Definition: attachment.cpp:401
void setTicksLeft(int16_t t)
Sets how long this attachment will remain attached.
Definition: attachment.hpp:142
AttachmentPlugin * m_plugin
An optional attachment - additional functionality can be implemented for certain attachments.
Definition: attachment.hpp:107
float weightAdjust() const
Returns additional weight for the kart.
Definition: attachment.cpp:685
AbstractKart * m_kart
Kart the attachment is attached to.
Definition: attachment.hpp:86
int16_t getTicksLeft() const
Returns how much time (in ticks) is left before this attachment is removed.
Definition: attachment.hpp:139
int16_t m_ticks_left
Time left till attachment expires.
Definition: attachment.hpp:89
Describes a chain of 8-bit unsigned integers.
Definition: network_string.hpp:53
Contains the state information of an item, i.e.
Definition: item.hpp:53
Utility class, you can inherit from this class to disallow the assignment operator and copy construct...
Definition: no_copy.hpp:26
The base class for sound effects.
Definition: sfx_base.hpp:43
Declares the general types that are used by the network.