]> jfr.im git - irc/gameservirc.git/blame - gameserv-2.0/libgameservcore/src/Types.cpp
Changed all references of HP to Health
[irc/gameservirc.git] / gameserv-2.0 / libgameservcore / src / Types.cpp
CommitLineData
e0d3cb09 1#include <GameServ/Types.h>\r
2using GameServ::Types::ItemTypes;\r
cce88913 3using GameServ::Types::Modifiers;\r
e0d3cb09 4using GameServ::Types::Exceptions::TypeException;\r
5\r
6#include <string>\r
7using std::string;\r
8\r
9\r
10using std::exception;\r
11\r
12#include <boost/format.hpp>\r
13#include <boost/algorithm/string.hpp>\r
14using boost::format;\r
15using boost::str;\r
16\r
cce88913 17TypeException::TypeException(const string &ErrorMsg, const char *pFilename, int SourceLine)\r
18: GameServException(ErrorMsg, pFilename, SourceLine)\r
19{ }\r
20\r
21TypeException::TypeException(const string &ErrorMsg)\r
22: GameServException(ErrorMsg)\r
23{ }\r
24 \r
25TypeException::TypeException(void)\r
26: GameServException("Type Exception occurred either do to conversion or improper type usage.", __FILE__, __LINE__)\r
27{ }\r
e0d3cb09 28\r
29const ItemTypes::itemtypeinfo ItemTypes::mItemTypeInfoTable[] =\r
30{\r
31 { Weapon, "Weapon" }, { Armor, "Armor" }, { Potion, "Potion"}\r
32}; // mItemTypeInfoTable[]\r
33\r
34string ItemTypes::GetName(ItemTypes::ItemType itemtype)\r
35{\r
36 for (unsigned int i = 0; i < sizeof(mItemTypeInfoTable) / sizeof(itemtypeinfo); i++)\r
37 {\r
38 if (mItemTypeInfoTable[i].itemtype == itemtype)\r
39 {\r
cce88913 40 return mItemTypeInfoTable[i].name;\r
e0d3cb09 41 }\r
42 }\r
43\r
44 // This should never happen because an enumeration is passed, but in the case where a user\r
45 // may attempt an invalid integer cast, it provides protection\r
46 throw TypeException(str(format("No item type found for %1% enumeration value") % itemtype).c_str());\r
cce88913 47}\r
48\r
49ItemTypes::ItemType ItemTypes::Parse(const string &itemtype)\r
50{\r
51 for (unsigned int i = 0; i < sizeof(mItemTypeInfoTable) / sizeof(itemtypeinfo); i++)\r
52 {\r
53 if (mItemTypeInfoTable[i].name == itemtype)\r
54 {\r
55 return mItemTypeInfoTable[i].itemtype;\r
56 }\r
57 }\r
58 return ItemTypes::NOTYPE;\r
59}\r
60\r
61const Modifiers::modifierinfo Modifiers::mModifierInfoTable[] =\r
62{\r
23f6e925 63 { strength, "Strength"}, { defense, "Defense" }, { maxhealth, "MaxHealth" }, { health, "Health" }, { forestfights, "Forest Fights" },\r
cce88913 64 { playerfights, "Player Fights" }, { gold, "Gold" }, { bank, "Bank" }\r
65};\r
66\r
67string Modifiers::GetName(Modifiers::Modifier modifier)\r
68{\r
69 for (unsigned int i = 0; i < sizeof(mModifierInfoTable) / sizeof(modifierinfo); i++)\r
70 {\r
71 if (mModifierInfoTable[i].modifier == modifier)\r
72 {\r
73 return mModifierInfoTable[i].name;\r
74 }\r
75 }\r
76\r
77 // This should never happen because an enumeration is passed, but in the case where a user\r
78 // may attempt an invalid integer cast, it provides protection\r
79 throw TypeException(str(format("No item type found for %1% enumeration value") % modifier).c_str());\r
80}\r
81\r
82Modifiers::Modifier Modifiers::Parse(const string &modifier)\r
83{\r
84 for (unsigned int i = 0; i < sizeof(mModifierInfoTable) / sizeof(modifierinfo); i++)\r
85 {\r
86 if (mModifierInfoTable[i].name == modifier)\r
87 {\r
88 return mModifierInfoTable[i].modifier;\r
89 }\r
90 }\r
91\r
92 throw TypeException(str(format("No modifier enumeration found for %1%") % modifier), __FILE__, __LINE__);\r
e0d3cb09 93}