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

Private Attributes

AttachmentType m_type
 Attachment type.
 
AttachmentType m_graphical_type
 Graphical Attachment type (comparing in updateGraphics).
 
AbstractKartm_kart
 Kart the attachment is attached to.
 
int16_t m_ticks_left
 Time left till attachment expires.
 
int16_t m_initial_speed
 For parachutes only, stored in cm/s for networking.
 
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.
 
AbstractKartm_previous_owner
 Used by bombs so that it's not passed back to previous owner.
 
AttachmentPluginm_plugin
 An optional attachment - additional functionality can be implemented for certain attachments.
 
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.

◆ 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()

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.

◆ 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).


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