Labyrinth
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
item.hpp
1 //////////////////////////////
2 //
3 // File: lxs/game/item.hpp
4 // Author: Maciej Kaminski
5 // E-mail: maciej.a.kaminski@gmail.com
6 // Website: maciejkaminski.pl
7 //
8 // File creation date: May 30 2014
9 // This file is part of Project Labyrinth
10 // This file is going to be released under terms of GNU GPL in near future
11 //
12 //////////////////////////////
13 
14 #ifndef __LXS_ITEM__
15 #define __LXS_ITEM__
16 #include <boost/shared_ptr.hpp>
17 #include <string>
18 #include <map>
19 #include <deque>
20 #include "lxs/coregraphics/primitives.hpp"
21 #include "lxs/coregraphics/model.hpp"
22 namespace LxS
23 {
24  namespace Game
25  {
26  class Map;
27  class GameObject;
28 
29  //! generic item class
30  class Item:public GameObject
31  {
32  std::string name;
33  float value;
34  int amount;
35  int weight;
36  protected:
37  //! for use in various "copy" constructors
38  void CopyBasicProperties(Item * i);
39  public:
40  enum {ITEM,SWORD,POTION,COIN};
41  //! default donstructor of new type of item
42  Item(Map * p) ;
43  //! "copy" constructir with pointer as a parameter
44  Item(Item * i);
45  //! return name of an item
46  const std::string& GetName();
47  //! detect collision (so that character can notice and pick up an item)
48  bool CollisionDetection(GameObject * cb, float _x, float _y, float _z) ;
49  //! set item's name (i.e. "Mighty sword of killing")
50  void SetName(const std::string _n);
51  //! how many of this item?
52  int GetAmount();
53  //!set amount of item (by default: 1)
54  void SetAmount(int a );
55  //! get monetary value (essential for barter engine)
56  float GetValue() ;
57  //! set monetary value
58  void SetValue(float a );
59  //! get weight (in pounds)
60  float GetWeight() ;
61  //! set weight (in pounds)
62  void SetWeight(float a );
63  //! return type of an item (ITEM,SWORD,POTION,COIN)
64  virtual int GetType() {return ITEM;}
65  };
66  //! melee weapon
67  class Sword: public Item
68  {
69  int damage;
70  public:
71  //! damage modifier of particular sword (die class)
72  int GetDamage() { return damage;}
73  //! set damage modifier(die class)
74  void SetDamage(int d) { damage=d;}
75  //! default ctor
76  Sword(Map*p):Item(p){}
77  //! "copy" constructor with pointer as a parameter
78  Sword(Sword*s);
79 
80  int GetType() {return SWORD;}
81  };
82  //! potion - can be consumed
83  class Potion: public Item
84  {
85  int health;
86  public:
87  //! how much health is restored upon drinking this potion (absolute value)
88  int GetHealth() { return health;}
89  //! set health modifier
90  void SetHealth(int d) { health=d;}
91  //! constructor of new potion for given map
92  Potion(Map*p):Item(p){}
93  //! "copy" constructor with pointer as a parameter
94  Potion(Potion*p);
95  int GetType() {return POTION;}
96 
97  };
98  //end of class Potion
99  //! all kinds of currency units
100  class Coin: public Item
101  {
102  public:
103  //! constructor of new coin with given amp
104  Coin(Map*p):Item(p){}
105  //! "copy" constructor with pointer as a parameter
106  Coin(Coin*c);
107  int GetType() {return COIN;}
108 
109  };
110  //end of class coin
111  //! catalogue of items
113  {
114  public:
115  //! internal data representation/ don't use it. it's made public only for
116  //! container-manipulating functions
117  typedef std::deque<Item* > ItemCatalogue_b;
118  private:
119  ItemCatalogue_b data;
120  public:
121  //! for container emulation
122  typedef ItemCatalogue_b::value_type value_type;
123  //! for container emulation
124  typedef ItemCatalogue_b::iterator iterator;
125  //! for iteration and container based algorithms, including BOOST_FOREACH
126  ItemCatalogue_b::iterator begin() {return data.begin();}
127  //! for iteration and container based algorithms, including BOOST_FOREACH
128  ItemCatalogue_b::iterator end() {return data.end();}
129 
130  //! for container emulation
131  typedef ItemCatalogue_b::const_iterator const_iterator;
132  //! for iteration and container based algorithms, including BOOST_FOREACH
133  ItemCatalogue_b::const_iterator begin()const {return data.begin();}
134  //! for iteration and container based algorithms, including BOOST_FOREACH
135  ItemCatalogue_b::const_iterator end() const {return data.end();}
136  //! Add item to a database
137  void AddItem(Item * i);
138  //!Return pointer to an item posessed by character' SHOULDN'T IT BE CONST?
139  Item* GetItem(const std::string & itemname);
140  //! create new copy of an item and returns it - good for setting up character sheets
141  Item* GetItemCopy(const std::string & itemname);
142  ~ItemCatalogue();
143  };
144  // end of class ItemCatalogue
145  }
146 }
147 
148 #endif