3 * Iter Vehemens ad Necem (IVAN)
4 * Copyright (C) Timo Kiviluoto
5 * Released under the GNU General
8 * See LICENSING which should be included
9 * along with this file for more details
27 template <class type
> class databasecreator
;
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
{
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(); }
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
);
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;
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
&);
81 static void CreateEveryCharacter(charactervector
&);
82 static void CreateEveryItem(itemvectorvector
&);
83 static void CreateEveryMaterial(std::vector
<material
*>&);
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
*);
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);
107 template <class type
> inline inputfile
&operator >> (inputfile
&SaveFile
, type
*&Class
) {
110 Class
= Type
? protocontainer
<type
>::GetProto(Type
)->SpawnAndLoad(SaveFile
) : 0;