| 1 |
/* |
| 2 |
* The Mana World |
| 3 |
* Copyright (C) 2004 The Mana World Development Team |
| 4 |
* |
| 5 |
* This file is part of The Mana World. |
| 6 |
* |
| 7 |
* This program is free software; you can redistribute it and/or modify |
| 8 |
* it under the terms of the GNU General Public License as published by |
| 9 |
* the Free Software Foundation; either version 2 of the License, or |
| 10 |
* any later version. |
| 11 |
* |
| 12 |
* This program is distributed in the hope that it will be useful, |
| 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
* GNU General Public License for more details. |
| 16 |
* |
| 17 |
* You should have received a copy of the GNU General Public License |
| 18 |
* along with this program; if not, write to the Free Software |
| 19 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 20 |
*/ |
| 21 |
|
| 22 |
#ifndef _SHOPITEM_H |
| 23 |
#define _SHOPITEM_H |
| 24 |
|
| 25 |
#include <stack> |
| 26 |
|
| 27 |
#include "item.h" |
| 28 |
|
| 29 |
/** |
| 30 |
* Represents an item in a shop inventory. It can store quantity and inventory |
| 31 |
* indices of duplicate entries in the shop as well. |
| 32 |
*/ |
| 33 |
class ShopItem : public Item |
| 34 |
{ |
| 35 |
public: |
| 36 |
/** |
| 37 |
* Constructor. Creates a new ShopItem. |
| 38 |
* |
| 39 |
* @param inventoryIndex the inventory index of the item |
| 40 |
* @param id the id of the item |
| 41 |
* @param quantity number of available copies of the item |
| 42 |
* @param price price of the item |
| 43 |
*/ |
| 44 |
ShopItem(int inventoryIndex, int id, int quantity, int price); |
| 45 |
|
| 46 |
/** |
| 47 |
* Constructor. Creates a new ShopItem. Inventory index will be set to |
| 48 |
* -1 and quantity to 0. |
| 49 |
* |
| 50 |
* @param id the id of the item |
| 51 |
* @param price price of the item |
| 52 |
*/ |
| 53 |
ShopItem(int id, int price); |
| 54 |
|
| 55 |
/** |
| 56 |
* Destructor. |
| 57 |
*/ |
| 58 |
~ShopItem(); |
| 59 |
|
| 60 |
/** |
| 61 |
* Add a duplicate. Id and price will be taken from this item. |
| 62 |
* |
| 63 |
* @param inventoryIndex the inventory index of the item |
| 64 |
* @param quantity number of available copies of the item |
| 65 |
*/ |
| 66 |
void addDuplicate(int inventoryIndex, int quantity); |
| 67 |
|
| 68 |
/** |
| 69 |
* Add a duplicate. Id and price will be taken from this item. |
| 70 |
* Needed for compatibility with ShopDuplicateItems (see) class |
| 71 |
* documentation). |
| 72 |
*/ |
| 73 |
void addDuplicate(); |
| 74 |
|
| 75 |
/** |
| 76 |
* Gets the quantity of the currently topmost duplicate. |
| 77 |
* |
| 78 |
* @return the quantity of the currently topmost duplicate |
| 79 |
*/ |
| 80 |
int getCurrentQuantity() const |
| 81 |
{ |
| 82 |
return mDuplicates.empty() ? 0 : mDuplicates.top()->quantity; |
| 83 |
} |
| 84 |
|
| 85 |
/** |
| 86 |
* Gets the inventory index of the currently topmost duplicate. |
| 87 |
* |
| 88 |
* @return the inventory index of the currently topmost duplicate |
| 89 |
*/ |
| 90 |
int getCurrentInvIndex() const |
| 91 |
{ |
| 92 |
return mDuplicates.empty() ? mInvIndex : |
| 93 |
mDuplicates.top()->inventoryIndex; |
| 94 |
} |
| 95 |
|
| 96 |
/** |
| 97 |
* Reduces the quantity of the topmost duplicate by the specified |
| 98 |
* amount. Also reduces the total quantity of this DuplicateItem. |
| 99 |
* Empty duplicates are automatically removed. |
| 100 |
* |
| 101 |
* If the amount is bigger than the quantity of the current topmost, |
| 102 |
* only sell as much as possible. Returns the amount actually sold (do |
| 103 |
* not ignore the return value!) |
| 104 |
* |
| 105 |
* @return the amount, that actually was sold. |
| 106 |
*/ |
| 107 |
int sellCurrentDuplicate(int quantity); |
| 108 |
|
| 109 |
/** |
| 110 |
* Gets the price of the item. |
| 111 |
* |
| 112 |
* @return the price of the item |
| 113 |
*/ |
| 114 |
int getPrice() const |
| 115 |
{ return mPrice; } |
| 116 |
|
| 117 |
/** |
| 118 |
* Gets the display name for the item in the shop list. |
| 119 |
* |
| 120 |
* @return the display name for the item in the shop list |
| 121 |
*/ |
| 122 |
const std::string &getDisplayName() const |
| 123 |
{ return mDisplayName; } |
| 124 |
|
| 125 |
protected: |
| 126 |
int mPrice; |
| 127 |
std::string mDisplayName; |
| 128 |
|
| 129 |
/** |
| 130 |
* Struct to keep track of duplicates. |
| 131 |
*/ |
| 132 |
typedef struct { |
| 133 |
int inventoryIndex; |
| 134 |
int quantity; |
| 135 |
} DuplicateItem; |
| 136 |
std::stack<DuplicateItem*> mDuplicates; /** <-- Stores duplicates */ |
| 137 |
}; |
| 138 |
|
| 139 |
#endif |