renamed alot of types; hope this will not break the game
[k8-i-v-a-n.git] / src / game / proto.h
blobc5d36d434d14b9425210a284317144c41ba50ba8
1 /*
3 * Iter Vehemens ad Necem (IVAN)
4 * Copyright (C) Timo Kiviluoto
5 * Released under the GNU General
6 * Public License
8 * See LICENSING which should be included
9 * along with this file for more details
12 #ifndef __PROTO_H__
13 #define __PROTO_H__
15 #include <map>
16 #include <vector>
18 #include "ivandef.h"
19 #include "fesave.h"
20 #include "festring.h"
23 class character;
24 class item;
25 class material;
26 class god;
27 template <class type> class databasecreator;
28 struct itemdatabase;
31 typedef std::map<festring, sLong> valuemap;
32 typedef std::vector<item*> itemvector;
33 typedef std::vector<itemvector> itemvectorvector;
34 typedef std::vector<character*> charactervector;
35 typedef std::vector<material*> materialvector;
38 template <class type> class protocontainer {
39 public:
40 friend class protosystem;
41 friend class databasecreator<type>;
42 typedef typename type::prototype prototype;
43 static int Add(prototype*);
44 static const prototype* GetProto(int I) { return GetProtoData()[I]; }
45 static int SearchCodeName(cfestring&);
46 static cchar* GetMainClassID() { return GetProtoData()[1]->GetClassID(); }
47 static int GetSize() { return GetSizeRef(); }
48 private:
49 static prototype**& GetProtoData();
50 static valuemap& GetCodeNameMap();
51 static int& GetSizeRef();
55 template <class type> inline int protocontainer<type>::Add (prototype *Proto) {
56 if (!GetSize()) (GetProtoData() = new prototype*[1024])[GetSizeRef()++] = 0;
57 int Index = GetSizeRef()++;
58 GetProtoData()[Index] = Proto;
59 std::pair<festring, sLong> Pair(Proto->GetClassID(), Index);
60 GetCodeNameMap().insert(Pair);
61 return Index;
65 template <class type> inline int protocontainer<type>::SearchCodeName (cfestring &Name) {
66 valuemap::iterator I = GetCodeNameMap().find(Name);
67 return I != GetCodeNameMap().end() ? I->second : 0;
71 class protosystem {
72 public:
73 static character* BalancedCreateMonster();
74 static item* BalancedCreateItem(sLong = 0, sLong = MAX_PRICE, sLong = ANY_CATEGORY, int = 0, int = 0, int = 0, truth = false);
75 static character* CreateMonster(int = 1, int = 999999, int = 0);
76 static character* CreateMonster(cfestring&, int = 0, truth = true);
77 static item* CreateItem(cfestring&, truth = true);
78 static material* CreateMaterial(cfestring&, sLong = 0, truth = true);
79 static void CreateEveryNormalEnemy(charactervector&);
80 #ifdef WIZARD
81 static void CreateEveryCharacter(charactervector&);
82 static void CreateEveryItem(itemvectorvector&);
83 static void CreateEveryMaterial(std::vector<material*>&);
84 #endif
85 static void Initialize();
86 static void InitCharacterDataBaseFlags();
87 static void SaveCharacterDataBaseFlags(outputfile&);
88 static void LoadCharacterDataBaseFlags(inputfile&);
89 static void CreateEverySeenCharacter(charactervector&);
90 static void CreateEveryMaterial(std::vector<material*>&, const god*, ccharacter*);
91 private:
92 static itemdatabase** ItemConfigData;
93 static int ItemConfigDataSize;
94 static itemdatabase** ItemCategoryData[ITEM_CATEGORIES];
95 static int ItemCategorySize[ITEM_CATEGORIES];
96 static sLong ItemCategoryPossibility[ITEM_CATEGORIES];
97 static sLong TotalItemPossibility;
101 template <class type> inline outputfile &operator << (outputfile &SaveFile, const type *Class) {
102 if (Class) Class->Save(SaveFile); else SaveFile << uShort(0);
103 return SaveFile;
107 template <class type> inline inputfile &operator >> (inputfile &SaveFile, type *&Class) {
108 uShort Type = 0;
109 SaveFile >> Type;
110 Class = Type ? protocontainer<type>::GetProto(Type)->SpawnAndLoad(SaveFile) : 0;
111 return SaveFile;
115 #endif