SuperTuxKart
Loading...
Searching...
No Matches
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.
 
 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.
 
void update (int ticks)
 Update the state of the item, called once per physics frame.
 
void setDisappearCounter ()
 Sets the disappear counter depending on type.
 
virtual void collected (const AbstractKart *kart)
 Called when the item is collected.
 
virtual void updateGraphics (float dt)
 Dummy implementation, causing an abort if it should be called to catch any errors early.
 
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.
 
virtual void switchTo (ItemType type)
 Switches an item to be of a different type.
 
virtual bool switchBack ()
 Returns true if this item was not actually switched (e.g.
 
bool isNegativeItem () const
 Returns if this item is negative, i.e.
 
void setTicksTillReturn (int t)
 Sets how long an item should be disabled.
 
int getTicksTillReturn () const
 Returns the time the item is disabled for.
 
bool isAvailable () const
 Returns true if this item is currently collected.
 
ItemType getType () const
 Returns the type of this item.
 
ItemType getGrahpicalType () const
 Returns the graphical type of this item should be using (takes nolok into account).
 
ItemType getOriginalType () const
 Returns the original type of this item.
 
void setItemId (unsigned int n)
 Sets the index of this item in the item manager list.
 
unsigned int getItemId () const
 Returns the index of this item in the item manager list.
 
bool isUsedUp () const
 Returns true if this item is used up and can be removed.
 
bool canBeUsedUp () const
 Returns true if this item can be used up, and therefore needs to be removed when the game is reset.
 
int getDeactivatedTicks () const
 Returns the number of ticks during which the item is deactivated (i.e.
 
void setDeactivatedTicks (int ticks)
 Sets the number of ticks during which the item is deactivated (i.e.
 
const AbstractKartgetPreviousOwner () const
 Returns the kart that dropped this item (or NULL if the item was not dropped by a kart.
 
void setXYZ (const Vec3 &xyz)
 
const Vec3getXYZ () const
 Returns the XYZ position of the item.
 
const Vec3 getNormal () const
 Returns the normal of the ItemState.
 
const btQuaternion & getOriginalRotation () const
 Returns the original rotation of the item.
 
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.
 

Private Member Functions

 LEAK_CHECK ()
 

Private Attributes

ItemType m_type
 Item type.
 
ItemType m_original_type
 If the item is switched, this contains the original type.
 
int m_ticks_till_return
 Time till a collected item reappears.
 
int m_item_id
 Index in item_manager field.
 
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.
 
Vec3 m_xyz
 The position of this ItemState.
 
btQuaternion m_original_rotation
 The original rotation of the item.
 
const AbstractKartm_previous_owner
 The 'owner' of the item, i.e.
 

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

◆ collected()

void ItemState::collected ( const AbstractKart kart)
virtual

Called when the item is collected.

Parameters
kartThe kart that collected the item.

Reimplemented in Item.

◆ getAvoidancePoint()

virtual const Vec3 * ItemState::getAvoidancePoint ( bool  left) const
inlinevirtual

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

◆ getDistanceFromCenter()

virtual float ItemState::getDistanceFromCenter ( ) const
inlinevirtual

Reimplemented in Item.

◆ getGraphNode()

virtual int ItemState::getGraphNode ( ) const
inlinevirtual

Reimplemented in Item.

◆ hitKart()

virtual bool ItemState::hitKart ( const Vec3 xyz,
const AbstractKart kart = NULL 
) const
inlinevirtual

Reimplemented in 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.

◆ isNegativeItem()

bool ItemState::isNegativeItem ( ) const
inline

Returns if this item is negative, i.e.

a banana or bubblegum.

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


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


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