melee / ranged effects
[gemrb.git] / gemrb / core / Store.h
blob905c9f4c32c38ba4938a9c8c0d1029f38eddc436
1 /* GemRB - Infinity Engine Emulator
2 * Copyright (C) 2003 The GemRB Project
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 /**
22 * @file Store.h
23 * Declares Store, class describing shops, temples and pubs, etc.
24 * @author The GemRB Project
28 #ifndef STORE_H
29 #define STORE_H
31 #include "exports.h"
32 #include "globals.h"
33 #include "ie_types.h"
35 #include <vector>
37 //bah!
38 class CREItem;
39 class Trigger;
41 typedef enum StoreType { STT_STORE=0, STT_TAVERN=1, STT_INN=2, STT_TEMPLE=3,
42 STT_BG2CONT=4, STT_IWD2CONT=5 } StoreType;
44 typedef enum StoreActionType { STA_BUYSELL=0, STA_IDENTIFY=1, STA_STEAL=2,
45 STA_CURE=3, STA_DONATE=4, STA_DRINK=5, STA_ROOMRENT=6, STA_OPTIONAL=0x80} StoreActionType;
47 #define IE_STORE_BUY 1
48 #define IE_STORE_SELL 2
49 #define IE_STORE_ID 4
50 #define IE_STORE_STEAL 8
51 #define IE_STORE_DONATE 16 //gemrb extension
52 #define IE_STORE_CURE 32
53 #define IE_STORE_DRINK 64
54 #define IE_STORE_SELECT 0x40 //valid when these flags used as store action
55 #define IE_STORE_RENT 128 //gemrb extension
56 #define IE_STORE_QUALITY 0x600 //2 bits
57 #define IE_STORE_FENCE 0x2000 //
58 #define IE_STORE_RECHARGE 0x4000 //gemrb extension, if set, store won't recharge
61 /**
62 * @struct STOItem
63 * Item in a store, together with available amount etc.
65 struct STOItem {
66 ieResRef ItemResRef;
67 ieWord PurchasedAmount;
68 ieWord Usages[CHARGE_COUNTERS];
69 ieDword Flags;
70 // 2 cached values from associated item. LEAVE IT SIGNED!
71 int Weight;
72 int StackAmount;
73 ieDword AmountInStock;
74 ieDwordSigned InfiniteSupply;
75 // V1.1
76 Trigger *trigger;
77 //ieDword TriggerRef; use infinitesupply
78 char unknown2[56];
82 /**
83 * @struct STODrink
84 * Kind of drink in a pub, with its associated rumour and price
87 struct STODrink {
88 ieResRef RumourResRef;
89 ieStrRef DrinkName;
90 ieDword Price;
91 ieDword Strength;
95 /**
96 * @struct STOCure
97 * Kind of cure available in a temple, with its associated price
100 struct STOCure {
101 ieResRef CureResRef;
102 ieDword Price;
106 * @class Store
107 * Class describing shops, temples, pubs, etc.
110 class GEM_EXPORT Store {
111 public:
112 Store();
113 ~Store();
115 std::vector< STOItem*> items;
116 STODrink* drinks;
117 STOCure* cures;
118 ieDword* purchased_categories;
120 ieResRef Name;
121 ieDword Type;
122 ieStrRef StoreName;
123 ieDword Flags;
124 ieDword SellMarkup;
125 ieDword BuyMarkup;
126 ieDword DepreciationRate;
127 ieWord StealFailureChance;
128 ieWord Capacity;
129 char unknown[8];
130 ieDword PurchasedCategoriesOffset;
131 ieDword PurchasedCategoriesCount;
132 ieDword ItemsOffset;
133 //don't use this value directly, use GetRealStockSize
134 ieDword ItemsCount;
135 ieDword Lore;
136 ieDword IDPrice;
137 ieResRef RumoursTavern;
138 ieDword DrinksOffset;
139 ieDword DrinksCount;
140 ieResRef RumoursTemple;
141 ieDword AvailableRooms;
142 ieDword RoomPrices[4];
143 ieDword CuresOffset;
144 ieDword CuresCount;
145 bool HasTriggers;
146 char unknown2[36];
148 // IWD2 only
149 char unknown3[80];
151 int version;
152 // the scripting name of the owner
153 ieDword StoreOwnerID;
155 public: //queries
156 int AcceptableItemType(ieDword type, ieDword invflags, bool pc) const;
157 STOCure *GetCure(unsigned int idx) const;
158 STODrink *GetDrink(unsigned int idx) const;
159 STOItem *GetItem(unsigned int idx);
160 /** Evaluates item availability triggers */
161 int GetRealStockSize();
162 /** Recharges item */
163 void RechargeItem(CREItem *item);
164 /** Adds a new item to the store (selling) */
165 void AddItem(CREItem* item);
166 void RemoveItem(unsigned int idx);
167 /** Returns index of item */
168 unsigned int FindItem(const ieResRef item, bool usetrigger) const;
169 const char *GetOwner() const;
170 ieDword GetOwnerID() const;
171 void SetOwnerID(ieDword owner);
172 private:
173 /** Finds a mergeable item in the stock, if exact is set, it checks for usage counts too */
174 STOItem *FindItem(CREItem *item, bool exact);
175 bool IsItemAvailable(unsigned int slot) const;
178 #endif // ! STORE_H