ShopItem Class Reference

#include <shopitem.h>

Inheritance diagram for ShopItem:

Item

List of all members.


Detailed Description

Represents an item in a shop inventory.

It can store quantity and inventory indices of duplicate entries in the shop as well.

Definition at line 33 of file shopitem.h.


Public Member Functions

 ShopItem (int inventoryIndex, int id, int quantity, int price)
 Constructor.
 ShopItem (int id, int price)
 Constructor.
 ~ShopItem ()
 Destructor.
void addDuplicate (int inventoryIndex, int quantity)
 Add a duplicate.
void addDuplicate ()
 Add a duplicate.
int getCurrentQuantity () const
 Gets the quantity of the currently topmost duplicate.
int getCurrentInvIndex () const
 Gets the inventory index of the currently topmost duplicate.
int sellCurrentDuplicate (int quantity)
 Reduces the quantity of the topmost duplicate by the specified amount.
int getPrice () const
 Gets the price of the item.
const std::string & getDisplayName () const
 Gets the display name for the item in the shop list.

Protected Attributes

int mPrice
std::string mDisplayName
std::stack< DuplicateItem * > mDuplicates

Classes

struct  DuplicateItem
 Struct to keep track of duplicates. More...

Constructor & Destructor Documentation

ShopItem::ShopItem ( int  inventoryIndex,
int  id,
int  quantity,
int  price 
)

Constructor.

Creates a new ShopItem.

Parameters:
inventoryIndex the inventory index of the item
id the id of the item
quantity number of available copies of the item
price price of the item

Definition at line 28 of file shopitem.cpp.

ShopItem::ShopItem ( int  id,
int  price 
)

Constructor.

Creates a new ShopItem. Inventory index will be set to -1 and quantity to 0.

Parameters:
id the id of the item
price price of the item

Definition at line 39 of file shopitem.cpp.

ShopItem::~ShopItem (  ) 

Destructor.

Clear all remaining duplicates on Object destruction.

Definition at line 47 of file shopitem.cpp.


Member Function Documentation

void ShopItem::addDuplicate ( int  inventoryIndex,
int  quantity 
)

Add a duplicate.

Id and price will be taken from this item.

Parameters:
inventoryIndex the inventory index of the item
quantity number of available copies of the item

Definition at line 57 of file shopitem.cpp.

void ShopItem::addDuplicate (  ) 

Add a duplicate.

Id and price will be taken from this item. Needed for compatibility with ShopDuplicateItems (see) class documentation).

Definition at line 66 of file shopitem.cpp.

int ShopItem::getCurrentQuantity (  )  const [inline]

Gets the quantity of the currently topmost duplicate.

Returns:
the quantity of the currently topmost duplicate

Definition at line 80 of file shopitem.h.

int ShopItem::getCurrentInvIndex (  )  const [inline]

Gets the inventory index of the currently topmost duplicate.

Returns:
the inventory index of the currently topmost duplicate

Definition at line 90 of file shopitem.h.

int ShopItem::sellCurrentDuplicate ( int  quantity  ) 

Reduces the quantity of the topmost duplicate by the specified amount.

Also reduces the total quantity of this DuplicateItem. Empty duplicates are automatically removed.

If the amount is bigger than the quantity of the current topmost, only sell as much as possible. Returns the amount actually sold (do not ignore the return value!)

Returns:
the amount, that actually was sold.

Definition at line 74 of file shopitem.cpp.

int ShopItem::getPrice (  )  const [inline]

Gets the price of the item.

Returns:
the price of the item

Definition at line 114 of file shopitem.h.

const std::string& ShopItem::getDisplayName (  )  const [inline]

Gets the display name for the item in the shop list.

Returns:
the display name for the item in the shop list

Definition at line 122 of file shopitem.h.


Member Data Documentation

int ShopItem::mPrice [protected]

Definition at line 126 of file shopitem.h.

std::string ShopItem::mDisplayName [protected]

Definition at line 127 of file shopitem.h.

std::stack<DuplicateItem*> ShopItem::mDuplicates [protected]

Definition at line 136 of file shopitem.h.


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

Generated on Sun Apr 26 17:30:44 2009 for The Mana World by  doxygen 1.5.5