#include <GameServ/GameServException.h>\r
using GameServ::Exceptions::GameServException;\r
\r
+#include <ctime>\r
+#include <boost/random/linear_congruential.hpp>\r
+#include <boost/random/uniform_int.hpp>\r
+#include <boost/random/uniform_real.hpp>\r
+#include <boost/random/variate_generator.hpp>\r
+// Sun CC doesn't handle boost::iterator_adaptor yet\r
+#if !defined(__SUNPRO_CC) || (__SUNPRO_CC > 0x530)\r
+#include <boost/generator_iterator.hpp>\r
+#endif\r
+\r
+#ifdef BOOST_NO_STDC_NAMESPACE\r
+namespace std {\r
+ using ::time;\r
+}\r
+#endif\r
+\r
+// This is a typedef for a random number generator.\r
+// Try boost::mt19937 or boost::ecuyer1988 instead of boost::minstd_rand\r
+typedef boost::minstd_rand base_generator_type;\r
+\r
+\r
namespace GameServ \r
{ \r
namespace Types\r
\r
}; // ItemTypes class\r
\r
+ class ObjectTypes\r
+ {\r
+ public:\r
+ //! Logical ObjectType enumerator\r
+ enum ObjectType \r
+ { \r
+ Player, Item, Level, Master, Monster\r
+ };\r
+\r
+ //! Get the name of an object type\r
+ static string GetName(ObjectType objecttype);\r
+\r
+ //! Parse the name and return the enumeration value\r
+ static ObjectType Parse(const string &objecttype);\r
+\r
+ private:\r
+ //! Internal struct to hold type information statically in a table\r
+ typedef struct objecttypeinfo\r
+ {\r
+ ObjectTypes::ObjectType objecttype; //!< The ObjectType enumeration value\r
+ string name; //!< The Name of the type\r
+ } objecttypeinfo;\r
+\r
+ static const objecttypeinfo mObjectTypeInfoTable[];\r
+\r
+ }; // ObjectTypes class\r
+\r
class Modifiers\r
{\r
public:\r
static const modifierinfo mModifierInfoTable[];\r
}; // Modifiers class\r
\r
+ template <class T>\r
class Range\r
{\r
public:\r
- Range();\r
- Range(const int &high, const int &low);\r
- ~Range();\r
+\r
+ Range()\r
+ {\r
+ }\r
+\r
+ Range(const T &high, const T &low)\r
+ {\r
+ mHigh = high;\r
+ mLow = low;\r
+ }\r
+\r
+ ~Range()\r
+ {\r
+ }\r
\r
//! Generate a random number within the range\r
- int Random();\r
+ T Random()\r
+ {\r
+ static base_generator_type generator(static_cast<T>(std::time(0)));\r
+ if (mLow == mHigh)\r
+ {\r
+ return mLow;\r
+ }\r
+ else\r
+ {\r
+ boost::uniform_int<> uni_dist(mLow, mHigh);\r
+ boost::variate_generator<base_generator_type&, boost::uniform_int<> > uni(generator, uni_dist);\r
+ mLastRandom = uni();\r
+ return mLastRandom;\r
+ }\r
+ }\r
\r
//! Property get - High\r
- int High(void) const;\r
+ T High(void) const\r
+ {\r
+ return mHigh;\r
+ }\r
\r
//! Property set - High\r
- void High(const int &value);\r
+ void High(const T &value)\r
+ {\r
+ if (value >= mLow)\r
+ {\r
+ mHigh = value;\r
+ }\r
+ }\r
\r
//! Property get - Low\r
- int Low(void) const;\r
+ T Low(void) const\r
+ {\r
+ return mLow;\r
+ }\r
\r
//! Property set - Low\r
- void Low(const int &value);\r
+ void Low(const T &value)\r
+ {\r
+ if (value <= mHigh)\r
+ {\r
+ mLow = value;\r
+ }\r
+ }\r
+\r
+ //! Property get - Last random number to be generated\r
+ T LastRandom(void) const\r
+ {\r
+ return mLastRandom;\r
+ }\r
\r
private:\r
- int mHigh;\r
- int mLow;\r
+ T mHigh;\r
+ T mLow;\r
+ T mLastRandom;\r
};\r
} \r
}\r