SuperTuxKart
Public Types | Public Member Functions | Private Attributes | List of all members
Attachment Class Reference

This objects is permanently available in a kart and stores information about addons. More...

#include <attachment.hpp>

Inheritance diagram for Attachment:
Inheritance graph
[legend]

Public Types

enum  AttachmentType {
  ATTACH_FIRST = 0, ATTACH_PARACHUTE = 0, ATTACH_ANVIL = 1, ATTACH_BOMB = 2,
  ATTACH_SWATTER, ATTACH_NOLOKS_SWATTER, ATTACH_SWATTER_ANIM, ATTACH_BUBBLEGUM_SHIELD,
  ATTACH_NOLOK_BUBBLEGUM_SHIELD, ATTACH_MAX, ATTACH_NOTHING
}
 

Public Member Functions

 Attachment (AbstractKart *kart)
 Initialises the attachment each kart has.
 
 ~Attachment ()
 Removes the attachment object. More...
 
void clear ()
 Removes any attachement currently on the kart. More...
 
void hitBanana (ItemState *item)
 Selects the new attachment. More...
 
void updateGraphics (float dt)
 
void update (int ticks)
 
void handleCollisionWithKart (AbstractKart *other)
 Updates the attachments in case of a kart-kart collision. More...
 
void set (AttachmentType type, int ticks, AbstractKart *previous_kart=NULL, bool set_by_rewind_parachute=false)
 Sets the attachment a kart has. More...
 
void rewindTo (BareNetworkString *buffer)
 Called from the kart rewinder when resetting to a certain state. More...
 
void saveState (BareNetworkString *buffer) const
 Saves the attachment state. More...
 
void set (AttachmentType type)
 Sets the type of the attachment, but keeps the old time left value. More...
 
AttachmentType getType () const
 Returns the type of this attachment. More...
 
int16_t getTicksLeft () const
 Returns how much time (in ticks) is left before this attachment is removed. More...
 
void setTicksLeft (int16_t t)
 Sets how long this attachment will remain attached. More...
 
AbstractKartgetPreviousOwner () const
 Returns the previous owner of this attachment, used in bombs that are being passed between karts. More...
 
float weightAdjust () const
 Returns additional weight for the kart. More...
 
scene::IAnimatedMeshSceneNode * getNode ()
 Return the currently associated scene node (used by e.g the swatter)
 
void reset ()
 

Private Attributes

AttachmentType m_type
 Attachment type. More...
 
AttachmentType m_graphical_type
 Graphical Attachment type (comparing in updateGraphics). More...
 
AbstractKartm_kart
 Kart the attachment is attached to. More...
 
int16_t m_ticks_left
 Time left till attachment expires. More...
 
int16_t m_initial_speed
 For parachutes only, stored in cm/s for networking. More...
 
int m_scaling_end_ticks
 For zoom-in animation.
 
scene::IAnimatedMeshSceneNode * m_node
 Scene node of the attachment, which will be attached to the kart's scene node. More...
 
AbstractKartm_previous_owner
 Used by bombs so that it's not passed back to previous owner. More...
 
AttachmentPluginm_plugin
 An optional attachment - additional functionality can be implemented for certain attachments. More...
 
SFXBasem_bomb_sound
 Ticking sound for the bomb.
 
SFXBasem_bubble_explode_sound
 Sound for exploding bubble gum shield.
 

Detailed Description

This objects is permanently available in a kart and stores information about addons.

If a kart has no attachment, this object will have the attachment type ATTACH_NOTHING. This way other tests for attachment in STK do not have to additionally test if there is an attachment, all tests for a type will always be valid. Certain attachments need additional coding, this is supported by a 'plugin' mechanism: This attachment will forward certain calls to (see attachment_pluging abstract class). Compared to normal subclassing (i.e. replacing the attachment object each time an attachment changes) this has less overhead (since the attachment class always creates a scene node).

Constructor & Destructor Documentation

◆ ~Attachment()

Attachment::~Attachment ( )

Removes the attachment object.

It removes the scene node used to display the attachment, and stops any sfx from being played.

Member Function Documentation

◆ clear()

void Attachment::clear ( )

Removes any attachement currently on the kart.

As for the anvil attachment, takes care of resetting the owner kart's physics structures to account for the updated mass.

◆ getPreviousOwner()

AbstractKart* Attachment::getPreviousOwner ( ) const
inline

Returns the previous owner of this attachment, used in bombs that are being passed between karts.

◆ getTicksLeft()

int16_t Attachment::getTicksLeft ( ) const
inline

Returns how much time (in ticks) is left before this attachment is removed.

◆ getType()

AttachmentType Attachment::getType ( ) const
inline

Returns the type of this attachment.

◆ handleCollisionWithKart()

void Attachment::handleCollisionWithKart ( AbstractKart other)

Updates the attachments in case of a kart-kart collision.

This must only be called for one of the karts in the collision, since it will update the attachment for both karts.

Parameters
otherPointer to the other kart hit.

◆ hitBanana()

void Attachment::hitBanana ( ItemState item_state)

Selects the new attachment.

In order to simplify synchronisation with the server, the new item is based on the current world time.

Parameters
itemThe item that was collected.

◆ rewindTo()

void Attachment::rewindTo ( BareNetworkString buffer)

Called from the kart rewinder when resetting to a certain state.

Parameters
bufferThe kart rewinder's buffer with the attachment state next.

◆ saveState()

void Attachment::saveState ( BareNetworkString buffer) const

Saves the attachment state.

Called as part of the kart saving its state.

Parameters
bufferThe kart rewinder's state buffer.

◆ set() [1/2]

void Attachment::set ( AttachmentType  type,
int  ticks,
AbstractKart current_kart = NULL,
bool  set_by_rewind_parachute = false 
)

Sets the attachment a kart has.

This will also handle animation to be played, e.g. when a swatter replaces a bomb.

Parameters
typeThe type of the new attachment.
timeHow long this attachment should stay with the kart.
current_kartThe kart from which an attachment is transferred. This is currently used for the bomb (to avoid that a bomb can be passed back to the previous owner). NULL if a no previous owner exists.

◆ set() [2/2]

void Attachment::set ( AttachmentType  type)
inline

Sets the type of the attachment, but keeps the old time left value.

◆ setTicksLeft()

void Attachment::setTicksLeft ( int16_t  t)
inline

Sets how long this attachment will remain attached.

◆ weightAdjust()

float Attachment::weightAdjust ( ) const

Returns additional weight for the kart.

Return the additional weight of the attachment (some attachments slow karts down by also making them heavier).

Member Data Documentation

◆ m_graphical_type

AttachmentType Attachment::m_graphical_type
private

Graphical Attachment type (comparing in updateGraphics).

◆ m_initial_speed

int16_t Attachment::m_initial_speed
private

For parachutes only, stored in cm/s for networking.

◆ m_kart

AbstractKart* Attachment::m_kart
private

Kart the attachment is attached to.

◆ m_node

scene::IAnimatedMeshSceneNode* Attachment::m_node
private

Scene node of the attachment, which will be attached to the kart's scene node.

◆ m_plugin

AttachmentPlugin* Attachment::m_plugin
private

An optional attachment - additional functionality can be implemented for certain attachments.

◆ m_previous_owner

AbstractKart* Attachment::m_previous_owner
private

Used by bombs so that it's not passed back to previous owner.

◆ m_ticks_left

int16_t Attachment::m_ticks_left
private

Time left till attachment expires.

◆ m_type

AttachmentType Attachment::m_type
private

Attachment type.


The documentation for this class was generated from the following files: