SuperTuxKart
Public Types | Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
ItemState Class Reference

Contains the state information of an item, i.e. More...

#include <item.hpp>

Inheritance diagram for ItemState:
Inheritance graph
[legend]

Public Types

enum  ItemType {
  ITEM_FIRST, ITEM_BONUS_BOX = ITEM_FIRST, ITEM_BANANA, ITEM_NITRO_BIG,
  ITEM_NITRO_SMALL, ITEM_BUBBLEGUM, ITEM_BUBBLEGUM_NOLOK, ITEM_EASTER_EGG,
  ITEM_LAST = ITEM_EASTER_EGG, ITEM_COUNT, ITEM_NONE
}
 The list of all items. More...
 

Public Member Functions

 ItemState (ItemType type, const AbstractKart *owner=NULL, int id=-1)
 Constructor. More...
 
 ItemState (const BareNetworkString &buffer)
 Constructor to restore item state at current ticks in client for live join.
 
void initItem (ItemType type, const Vec3 &xyz, const Vec3 &normal)
 Initialises an item. More...
 
void update (int ticks)
 Update the state of the item, called once per physics frame. More...
 
void setDisappearCounter ()
 Sets the disappear counter depending on type. More...
 
virtual void collected (const AbstractKart *kart)
 Called when the item is collected. More...
 
virtual void updateGraphics (float dt)
 Dummy implementation, causing an abort if it should be called to catch any errors early. More...
 
virtual bool hitKart (const Vec3 &xyz, const AbstractKart *kart=NULL) const
 
virtual int getGraphNode () const
 
virtual const Vec3getAvoidancePoint (bool left) const
 
virtual float getDistanceFromCenter () const
 
virtual void reset ()
 Resets an item to its start state. More...
 
virtual void switchTo (ItemType type)
 Switches an item to be of a different type. More...
 
virtual bool switchBack ()
 Returns true if this item was not actually switched (e.g. More...
 
bool isNegativeItem () const
 Returns if this item is negative, i.e. More...
 
void setTicksTillReturn (int t)
 Sets how long an item should be disabled. More...
 
int getTicksTillReturn () const
 Returns the time the item is disabled for. More...
 
bool isAvailable () const
 Returns true if this item is currently collected. More...
 
ItemType getType () const
 Returns the type of this item. More...
 
ItemType getGrahpicalType () const
 Returns the graphical type of this item should be using (takes nolok into account). More...
 
ItemType getOriginalType () const
 Returns the original type of this item. More...
 
void setItemId (unsigned int n)
 Sets the index of this item in the item manager list. More...
 
unsigned int getItemId () const
 Returns the index of this item in the item manager list. More...
 
bool isUsedUp () const
 Returns true if this item is used up and can be removed. More...
 
bool canBeUsedUp () const
 Returns true if this item can be used up, and therefore needs to be removed when the game is reset. More...
 
int getDeactivatedTicks () const
 Returns the number of ticks during which the item is deactivated (i.e. More...
 
void setDeactivatedTicks (int ticks)
 Sets the number of ticks during which the item is deactivated (i.e. More...
 
const AbstractKartgetPreviousOwner () const
 Returns the kart that dropped this item (or NULL if the item was not dropped by a kart. More...
 
void setXYZ (const Vec3 &xyz)
 
const Vec3getXYZ () const
 Returns the XYZ position of the item. More...
 
const Vec3 getNormal () const
 Returns the normal of the ItemState. More...
 
const btQuaternion & getOriginalRotation () const
 Returns the original rotation of the item. More...
 
void saveCompleteState (BareNetworkString *buffer) const
 Save item state at current ticks in server for live join.
 

Protected Member Functions

virtual void setType (ItemType type)
 
bool hitLine (const core::line3df &line, const AbstractKart *kart=NULL) const
 Returns true if the specified line segment would come close enough to this item so that this item would be collected. More...
 

Private Member Functions

 LEAK_CHECK ()
 

Private Attributes

ItemType m_type
 Item type. More...
 
ItemType m_original_type
 If the item is switched, this contains the original type. More...
 
int m_ticks_till_return
 Time till a collected item reappears. More...
 
int m_item_id
 Index in item_manager field. More...
 
int m_deactive_ticks
 Optionally if item was placed by a kart, a timer can be used to temporarly deactivate collision so a kart is not hit by its own item.
 
int m_used_up_counter
 Counts how often an item is used before it disappears. More...
 
Vec3 m_xyz
 The position of this ItemState. More...
 
btQuaternion m_original_rotation
 The original rotation of the item. More...
 
const AbstractKartm_previous_owner
 The 'owner' of the item, i.e. More...
 

Friends

class ItemManager
 
class NetworkItemManager
 
class SkiddingAI
 
class TestAI
 

Detailed Description

Contains the state information of an item, i.e.

all non-visual information only, which also can change (e.g. position and AI information is constant and therefore not stored here). This class is used as a base class for item and for networking to save item states.

Member Enumeration Documentation

◆ ItemType

The list of all items.

Important for the switch item function: bubblegum must be the last item (since bubble gum can't be switched with any other item, since it's a different objecct).

Enumerator
ITEM_EASTER_EGG 

For easter egg mode only.

Constructor & Destructor Documentation

◆ ItemState()

ItemState::ItemState ( ItemType  type,
const AbstractKart owner = NULL,
int  id = -1 
)

Constructor.

Parameters
typeType of the item.
ownerIf not NULL it is the kart that dropped this item; NULL indicates an item that's part of the track.
idIndex of this item in the array of all items.

Member Function Documentation

◆ canBeUsedUp()

bool ItemState::canBeUsedUp ( ) const
inline

Returns true if this item can be used up, and therefore needs to be removed when the game is reset.

◆ collected()

void ItemState::collected ( const AbstractKart kart)
virtual

Called when the item is collected.

Parameters
kartThe kart that collected the item.

Reimplemented in Item.

◆ getDeactivatedTicks()

int ItemState::getDeactivatedTicks ( ) const
inline

Returns the number of ticks during which the item is deactivated (i.e.

it was collected).

◆ getGrahpicalType()

Item::ItemType ItemState::getGrahpicalType ( ) const

Returns the graphical type of this item should be using (takes nolok into account).

◆ getItemId()

unsigned int ItemState::getItemId ( ) const
inline

Returns the index of this item in the item manager list.

◆ getNormal()

const Vec3 ItemState::getNormal ( ) const
inline

Returns the normal of the ItemState.

◆ getOriginalRotation()

const btQuaternion& ItemState::getOriginalRotation ( ) const
inline

Returns the original rotation of the item.

◆ getOriginalType()

ItemType ItemState::getOriginalType ( ) const
inline

Returns the original type of this item.

◆ getPreviousOwner()

const AbstractKart* ItemState::getPreviousOwner ( ) const
inline

Returns the kart that dropped this item (or NULL if the item was not dropped by a kart.

◆ getTicksTillReturn()

int ItemState::getTicksTillReturn ( ) const
inline

Returns the time the item is disabled for.

◆ getType()

ItemType ItemState::getType ( ) const
inline

Returns the type of this item.

◆ getXYZ()

const Vec3& ItemState::getXYZ ( ) const
inline

Returns the XYZ position of the item.

◆ hitLine()

bool ItemState::hitLine ( const core::line3df &  line,
const AbstractKart kart = NULL 
) const
inlineprotected

Returns true if the specified line segment would come close enough to this item so that this item would be collected.

Parameters
lineThe line segment which is tested if it is close enough to this item so that this item would be collected.

◆ initItem()

void ItemState::initItem ( ItemType  type,
const Vec3 xyz,
const Vec3 normal 
)

Initialises an item.

Parameters
typeType for this item.
xyzThe position for this item.
normalThe normal for this item.

◆ isAvailable()

bool ItemState::isAvailable ( ) const
inline

Returns true if this item is currently collected.

◆ isNegativeItem()

bool ItemState::isNegativeItem ( ) const
inline

Returns if this item is negative, i.e.

a banana or bubblegum.

◆ isUsedUp()

bool ItemState::isUsedUp ( ) const
inline

Returns true if this item is used up and can be removed.

◆ reset()

virtual void ItemState::reset ( )
inlinevirtual

Resets an item to its start state.

Reimplemented in Item.

◆ setDeactivatedTicks()

void ItemState::setDeactivatedTicks ( int  ticks)
inline

Sets the number of ticks during which the item is deactivated (i.e.

it was collected).

◆ setDisappearCounter()

void ItemState::setDisappearCounter ( )

Sets the disappear counter depending on type.

◆ setItemId()

void ItemState::setItemId ( unsigned int  n)
inline

Sets the index of this item in the item manager list.

◆ setTicksTillReturn()

void ItemState::setTicksTillReturn ( int  t)
inline

Sets how long an item should be disabled.

While item itself sets a default, this time is too short in case that a kart that has a bomb hits a banana: by the time the explosion animation is ended and the kart is back at its original position, the banana would be back again and therefore hit the kart again. See Attachment::hitBanana for more details.

Parameters
fTime till the item can be used again.

◆ switchBack()

virtual bool ItemState::switchBack ( )
inlinevirtual

Returns true if this item was not actually switched (e.g.

trigger etc)

Reimplemented in Item.

◆ switchTo()

virtual void ItemState::switchTo ( ItemType  type)
inlinevirtual

Switches an item to be of a different type.

Used for the switch powerup.

Parameters
typeNew type for this item.

◆ update()

void ItemState::update ( int  ticks)

Update the state of the item, called once per physics frame.

Parameters
ticksNumber of ticks to simulate. While this value is 1 when called during the normal game loop, during a rewind this value can be (much) larger than 1.

◆ updateGraphics()

virtual void ItemState::updateGraphics ( float  dt)
inlinevirtual

Dummy implementation, causing an abort if it should be called to catch any errors early.

Reimplemented in Item.

Member Data Documentation

◆ m_item_id

int ItemState::m_item_id
private

Index in item_manager field.

This field can also take on a negative value when used in the NetworkItemManager.

◆ m_original_rotation

btQuaternion ItemState::m_original_rotation
private

The original rotation of the item.

While this is technically a visual only value (atm, it could be used for collision detection), it is required to make sure a client can display items with the right normal (in case that a client would get a different (or no) normal from a raycast).

◆ m_original_type

ItemType ItemState::m_original_type
private

If the item is switched, this contains the original type.

It is ITEM_NONE if the item is not switched.

◆ m_previous_owner

const AbstractKart* ItemState::m_previous_owner
private

The 'owner' of the item, i.e.

the kart that dropped this item. Is NULL if the item is part of the track.

◆ m_ticks_till_return

int ItemState::m_ticks_till_return
private

Time till a collected item reappears.

When this value is <=0 this means that the item is availabe to be collected. When the value is

0 it means that the item is not available.

◆ m_type

ItemType ItemState::m_type
private

Item type.

◆ m_used_up_counter

int ItemState::m_used_up_counter
private

Counts how often an item is used before it disappears.

Used for bubble gum to make them disappear after a while. A value >0 indicates that the item still exists, =0 that the item can be deleted, and <0 that the item will never be deleted, i.e. it will always reappear after a while.

◆ m_xyz

Vec3 ItemState::m_xyz
private

The position of this ItemState.


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