]>
Commit | Line | Data |
---|---|---|
1 | #ifndef ITEM_H | |
2 | #define ITEM_H | |
3 | ||
4 | ||
5 | #include <string> | |
6 | #include "level.h" | |
7 | ||
8 | using namespace std; | |
9 | ||
10 | class Player; // Forward declaration | |
11 | enum type { WEAPON, ARMOR, POTION }; | |
12 | ||
13 | class item | |
14 | { | |
15 | public: | |
16 | item(); | |
17 | item(const char *name, long int p=0, int uses=1, long int identifier=0, int m1=0, int m2=0, int m3=0, int m4=0, int m5=0, int m6=0, int m7=0, int m8=0); | |
18 | item(string name, long int p=0, int uses=1, long int identifier=0, int m1=0, int m2=0, int m3=0, int m4=0, int m5=0, int m6=0, int m7=0, int m8=0); | |
19 | ||
20 | virtual ~item(); | |
21 | ||
22 | int uses() { return myuses; }; | |
23 | long int price() { return myprice; }; | |
24 | ||
25 | string getName () { return myname; }; | |
26 | ||
27 | virtual bool use(Player *p) = 0; | |
28 | virtual void undo(Player *p) = 0; | |
29 | virtual bool setData(char *datastr) = 0; | |
30 | ||
31 | type getType() {return mytype;}; | |
32 | void setType(type); | |
33 | long int getID() {return id;}; | |
34 | ||
35 | bool operator<(const item &right) const; | |
36 | bool operator>(const item &right) const; | |
37 | bool operator==(const item &right) const; | |
38 | bool operator!=(const item &right) const; | |
39 | item &operator=(const item &right); | |
40 | ||
41 | protected: | |
42 | string myname; // Name to use in game | |
43 | long int myprice; // How much does this item cost to buy (half to sell) | |
44 | int mymodifiers[8]; // Up to 8 different modifiers handled in the sub-classes | |
45 | int myuses; // How many times this item can be used by default | |
46 | long int id; // Unique identifier for the item | |
47 | type mytype; | |
48 | }; | |
49 | ||
50 | class itemContainer | |
51 | { | |
52 | public: | |
53 | itemContainer(); | |
54 | itemContainer(item *); | |
55 | itemContainer(const itemContainer &); | |
56 | ~itemContainer(); | |
57 | ||
58 | itemContainer &operator ++(); | |
59 | itemContainer operator ++(int); | |
60 | ||
61 | itemContainer &operator --(); | |
62 | itemContainer operator --(int); | |
63 | ||
64 | bool operator <(const itemContainer &right) const; | |
65 | bool operator >(const itemContainer &right) const; | |
66 | bool operator ==(const itemContainer &right) const; | |
67 | bool operator !=(const itemContainer &right) const; | |
68 | ||
69 | item *getItem() {return myitem;}; | |
70 | void setItem(item *); | |
71 | ||
72 | int getUses() { return myuses; }; | |
73 | void setUses(int); | |
74 | void use(Player *p); | |
75 | ||
76 | private: | |
77 | int myuses; // How many times this item can be used | |
78 | item *myitem; | |
79 | }; | |
80 | ||
81 | class weapon : public item | |
82 | { | |
83 | public: | |
84 | weapon() : item() {myname = "New Weapon";}; | |
85 | weapon(const char *name, int p=0, int uses = -1, long int identifier=0, int strength=0, int defense=0, int maxhp=0) : item(name, p, uses, strength, defense, maxhp){}; | |
86 | weapon(string name, int p=0, int uses = -1, long int identifier=0, int strength=0, int defense=0, int maxhp=0) : item(name, p, uses, strength, defense, maxhp){}; | |
87 | ~weapon(); | |
88 | ||
89 | bool setData(char *datastr); | |
90 | bool use(Player *p); | |
91 | void undo(Player *p); | |
92 | ||
93 | }; | |
94 | ||
95 | class armor : public item | |
96 | { | |
97 | public: | |
98 | armor() : item(){}; | |
99 | armor(const char *name, int p=0, int uses = -1, long int identifier=0, int strength=0, int defense=0, int maxhp=0) : item(name, p, uses, strength, defense, maxhp){}; | |
100 | armor(string name, int p=0, int uses = -1, long int identifier=0, int strength=0, int defense=0, int maxhp=0) : item(name, p, uses, strength, defense, maxhp){}; | |
101 | ~armor(); | |
102 | ||
103 | bool setData(char *datastr); | |
104 | bool use(Player *p); | |
105 | void undo(Player *p); | |
106 | }; | |
107 | ||
108 | class potion : public item | |
109 | { | |
110 | public: | |
111 | potion() : item(){}; | |
112 | potion(const char *name, int p=0, int uses = 1, long int identifier=0, int strength=0, int defense=0, int maxhp=0, int hp=0, int forest_fights=0, int player_fights=0, int gold=0, int bank=0) : item(name, p, uses, strength, defense, maxhp, hp, forest_fights, player_fights, gold, bank){}; | |
113 | potion(string name, int p=0, int uses = 1, long int identifier=0, int strength=0, int defense=0, int maxhp=0, int hp=0, int forest_fights=0, int player_fights=0, int gold=0, int bank=0) : item(name, p, uses, strength, defense, maxhp, hp, forest_fights, player_fights, gold, bank){}; | |
114 | ~potion(); | |
115 | ||
116 | bool setData(char *datastr); | |
117 | bool use(Player *p); | |
118 | void undo(Player *p); | |
119 | ||
120 | protected: | |
121 | range myranges[8]; | |
122 | }; | |
123 | ||
124 | class tavernItem | |
125 | { | |
126 | public: | |
127 | tavernItem(); | |
128 | tavernItem(item *, int); | |
129 | ||
130 | ||
131 | void setItem(item*); | |
132 | item *getItem() { return myItem; }; | |
133 | ||
134 | void setLevel(int); | |
135 | int getLevel() { return myLevel; }; | |
136 | ||
137 | bool visible(Player *); | |
138 | ||
139 | ||
140 | private: | |
141 | ||
142 | item *myItem; // The item this actually points to | |
143 | int myLevel; // The level the item shows up | |
144 | }; | |
145 | #endif |