Logo
~Sockets~
~Examples~
~Contact~


ItemFactory.h

Go to the documentation of this file.
00001 
00006 /*
00007 Copyright (C) 2004  Anders Hedstrom
00008 
00009 This program is free software; you can redistribute it and/or
00010 modify it under the terms of the GNU General Public License
00011 as published by the Free Software Foundation; either version 2
00012 of the License, or (at your option) any later version.
00013 
00014 This program is distributed in the hope that it will be useful,
00015 but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 GNU General Public License for more details.
00018 
00019 You should have received a copy of the GNU General Public License
00020 along with this program; if not, write to the Free Software
00021 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
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 // item properties
00037 //  equip / wield position
00038 //  damage / defense physical
00039 //  damage / defense magical
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; // 'a sword'
00065                 cstring m_plural; // swords
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
Page, code, and content Copyright (C) 2006 by Anders Hedström
Generated on Mon Aug 29 20:21:47 2005 for C++ Sockets by  doxygen 1.4.4