00001
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef _ITEMFACTORY_H
00024 #define _ITEMFACTORY_H
00025
00026 #include <string>
00027 #include <vector>
00028 #include <map>
00029 #include <Utility.h>
00030 #include "IPersist.h"
00031 #include "cstring.h"
00032
00033 class SmallHandler;
00034
00035
00036
00037
00038
00039
00040
00041
00043 struct ITEM {
00044 ITEM(const std::string& n,const std::string& p,const std::string& w);
00045 ITEM(const std::string& n,const std::string& p,const std::string& w,short ph,short ma,long am);
00046 std::string GetDescription()
00047 {
00048 std::string str;
00049 if (m_amount == 1)
00050 {
00051 str = m_name;
00052 }
00053 else
00054 {
00055 str = Utility::l2string(m_amount) + " " + m_plural;
00056 }
00057 if (m_vecno > 0)
00058 {
00059 str += " (" + Utility::l2string(m_vecno) + ")";
00060 }
00061 return str;
00062 }
00063 size_t m_vecno;
00064 cstring m_name;
00065 cstring m_plural;
00066 std::string m_wield_position;
00067 short m_physical;
00068 short m_magical;
00069 long m_amount;
00070 };
00071 typedef std::vector<ITEM *> item_v;
00072
00073 class SmallSocket;
00074
00076 class ItemFactory
00077 {
00078 public:
00079 ItemFactory(SmallHandler&);
00080 ~ItemFactory();
00081
00082 ITEM *CreateRandomItem();
00083 ITEM *CreateGold(long amount);
00084 void Spawn();
00085 void ShowNamesAt(SmallSocket *p,int x,int y,const std::string& prefix = "");
00086
00087 SmallHandler& Handler() { return m_handler; }
00088 item_v& GetItems(int x,int y) { return m_items[x][y]; }
00089 size_t NumberOfItems();
00090
00091 void Merge(item_v&,ITEM *);
00092
00093 private:
00094 SmallHandler& m_handler;
00095 std::map<int, std::map<int, item_v> > m_items;
00096 };
00097
00098
00099
00100
00101 #endif // _ITEMFACTORY_H