]>
Commit | Line | Data |
---|---|---|
e0d3cb09 | 1 | #ifndef __GS__TYPES_H__\r |
2 | #define __GS__TYPES_H__\r | |
3 | \r | |
4 | #include <string>\r | |
5 | using std::string;\r | |
6 | #include <GameServ/GameServException.h>\r | |
7 | using GameServ::Exceptions::GameServException;\r | |
8 | \r | |
fadef98f | 9 | #include <ctime>\r |
10 | #include <boost/random/linear_congruential.hpp>\r | |
11 | #include <boost/random/uniform_int.hpp>\r | |
12 | #include <boost/random/uniform_real.hpp>\r | |
13 | #include <boost/random/variate_generator.hpp>\r | |
14 | // Sun CC doesn't handle boost::iterator_adaptor yet\r | |
15 | #if !defined(__SUNPRO_CC) || (__SUNPRO_CC > 0x530)\r | |
16 | #include <boost/generator_iterator.hpp>\r | |
17 | #endif\r | |
18 | \r | |
19 | #ifdef BOOST_NO_STDC_NAMESPACE\r | |
20 | namespace std {\r | |
21 | using ::time;\r | |
22 | }\r | |
23 | #endif\r | |
24 | \r | |
25 | // This is a typedef for a random number generator.\r | |
26 | // Try boost::mt19937 or boost::ecuyer1988 instead of boost::minstd_rand\r | |
27 | typedef boost::minstd_rand base_generator_type;\r | |
28 | \r | |
29 | \r | |
e0d3cb09 | 30 | namespace GameServ \r |
31 | { \r | |
32 | namespace Types\r | |
33 | {\r | |
2a8a990d | 34 | \r |
35 | //! Holds the exceptions related to types and their conversions\r | |
36 | namespace Exceptions\r | |
37 | {\r | |
38 | //! Generic type exception possibly due to conversion or improper usage\r | |
39 | class TypeException : public GameServException\r | |
40 | {\r | |
41 | public:\r | |
42 | TypeException(const string &ErrorMsg, const char *pFilename, int SourceLine);\r | |
43 | TypeException(const string &ErrorMsg);\r | |
44 | TypeException(void);\r | |
45 | };\r | |
e0d3cb09 | 46 | }\r |
47 | \r | |
48 | class ItemTypes\r | |
49 | {\r | |
50 | public:\r | |
51 | //! Logical ItemType enumerator\r | |
52 | enum ItemType \r | |
53 | { \r | |
54 | Weapon, Armor, Potion, NOTYPE\r | |
55 | };\r | |
56 | \r | |
57 | //! Get the name of an item type\r | |
58 | static string GetName(ItemType itemtype);\r | |
59 | \r | |
60 | //! Parse the name and return the enumeration value\r | |
61 | static ItemType Parse(const string &itemtype);\r | |
62 | \r | |
63 | private:\r | |
64 | //! Internal struct to hold type information statically in a table\r | |
65 | typedef struct itemtypeinfo\r | |
66 | {\r | |
67 | ItemTypes::ItemType itemtype; //!< The ItemType enumeration value\r | |
cce88913 | 68 | string name; //!< The Name of the type\r |
e0d3cb09 | 69 | } itemtypeinfo;\r |
70 | \r | |
71 | static const itemtypeinfo mItemTypeInfoTable[];\r | |
72 | \r | |
73 | }; // ItemTypes class\r | |
cce88913 | 74 | \r |
1134c368 | 75 | class ObjectTypes\r |
76 | {\r | |
77 | public:\r | |
78 | //! Logical ObjectType enumerator\r | |
79 | enum ObjectType \r | |
80 | { \r | |
81 | Player, Item, Level, Master, Monster\r | |
82 | };\r | |
83 | \r | |
84 | //! Get the name of an object type\r | |
85 | static string GetName(ObjectType objecttype);\r | |
86 | \r | |
87 | //! Parse the name and return the enumeration value\r | |
88 | static ObjectType Parse(const string &objecttype);\r | |
89 | \r | |
90 | private:\r | |
91 | //! Internal struct to hold type information statically in a table\r | |
92 | typedef struct objecttypeinfo\r | |
93 | {\r | |
94 | ObjectTypes::ObjectType objecttype; //!< The ObjectType enumeration value\r | |
95 | string name; //!< The Name of the type\r | |
96 | } objecttypeinfo;\r | |
97 | \r | |
98 | static const objecttypeinfo mObjectTypeInfoTable[];\r | |
99 | \r | |
100 | }; // ObjectTypes class\r | |
101 | \r | |
cce88913 | 102 | class Modifiers\r |
103 | {\r | |
104 | public:\r | |
105 | //! Logical Modifer enumerator\r | |
106 | enum Modifier\r | |
107 | {\r | |
23f6e925 | 108 | strength, defense, maxhealth, health, forestfights, playerfights, gold, bank\r |
cce88913 | 109 | };\r |
110 | \r | |
111 | //! Get the name of a modifier\r | |
112 | static string GetName(Modifier modifier);\r | |
113 | \r | |
114 | //! Parse the name and return the modifier enumeration value\r | |
115 | static Modifier Parse(const string &modifier);\r | |
116 | private:\r | |
117 | typedef struct modifierinfo\r | |
118 | {\r | |
119 | Modifiers::Modifier modifier; //!< The modifier enumeration value\r | |
120 | string name; //!< The name of the modifier\r | |
121 | } modifierinfo;\r | |
122 | static const modifierinfo mModifierInfoTable[];\r | |
123 | }; // Modifiers class\r | |
3d5a42ee | 124 | \r |
fadef98f | 125 | template <class T>\r |
3d5a42ee | 126 | class Range\r |
127 | {\r | |
128 | public:\r | |
fadef98f | 129 | \r |
130 | Range()\r | |
131 | {\r | |
132 | }\r | |
133 | \r | |
134 | Range(const T &high, const T &low)\r | |
135 | {\r | |
136 | mHigh = high;\r | |
137 | mLow = low;\r | |
138 | }\r | |
139 | \r | |
140 | ~Range()\r | |
141 | {\r | |
142 | }\r | |
3d5a42ee | 143 | \r |
144 | //! Generate a random number within the range\r | |
fadef98f | 145 | T Random()\r |
146 | {\r | |
147 | static base_generator_type generator(static_cast<T>(std::time(0)));\r | |
148 | if (mLow == mHigh)\r | |
149 | {\r | |
150 | return mLow;\r | |
151 | }\r | |
152 | else\r | |
153 | {\r | |
154 | boost::uniform_int<> uni_dist(mLow, mHigh);\r | |
155 | boost::variate_generator<base_generator_type&, boost::uniform_int<> > uni(generator, uni_dist);\r | |
156 | mLastRandom = uni();\r | |
157 | return mLastRandom;\r | |
158 | }\r | |
159 | }\r | |
3d5a42ee | 160 | \r |
161 | //! Property get - High\r | |
fadef98f | 162 | T High(void) const\r |
163 | {\r | |
164 | return mHigh;\r | |
165 | }\r | |
3d5a42ee | 166 | \r |
167 | //! Property set - High\r | |
fadef98f | 168 | void High(const T &value)\r |
169 | {\r | |
170 | if (value >= mLow)\r | |
171 | {\r | |
172 | mHigh = value;\r | |
173 | }\r | |
174 | }\r | |
3d5a42ee | 175 | \r |
176 | //! Property get - Low\r | |
fadef98f | 177 | T Low(void) const\r |
178 | {\r | |
179 | return mLow;\r | |
180 | }\r | |
3d5a42ee | 181 | \r |
182 | //! Property set - Low\r | |
fadef98f | 183 | void Low(const T &value)\r |
184 | {\r | |
185 | if (value <= mHigh)\r | |
186 | {\r | |
187 | mLow = value;\r | |
188 | }\r | |
189 | }\r | |
1134c368 | 190 | \r |
191 | //! Property get - Last random number to be generated\r | |
fadef98f | 192 | T LastRandom(void) const\r |
193 | {\r | |
194 | return mLastRandom;\r | |
195 | }\r | |
3d5a42ee | 196 | \r |
197 | private:\r | |
fadef98f | 198 | T mHigh;\r |
199 | T mLow;\r | |
200 | T mLastRandom;\r | |
3d5a42ee | 201 | };\r |
cce88913 | 202 | } \r |
e0d3cb09 | 203 | }\r |
204 | #endif |