]> jfr.im git - irc/gameservirc.git/blobdiff - gameserv-2.0/libgameservcore/include/GameServ/Types.h
I implemented a mock forest driver and found a problem in using the singleton design...
[irc/gameservirc.git] / gameserv-2.0 / libgameservcore / include / GameServ / Types.h
index 845993810076457e5b765bbfc5fb087bcbcc313d..de0fab22f7bec9ef24843919bc967db1ce77a6cd 100644 (file)
@@ -6,22 +6,43 @@ using std::string;
 #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
-
-               //! Holds the exceptions related to types and their conversions
-               namespace Exceptions
-               {
-                       //! Generic type exception possibly due to conversion or improper usage
-                       class TypeException : public GameServException
-                       {
-                       public:
-                               TypeException(const string &ErrorMsg, const char *pFilename, int SourceLine);
-                               TypeException(const string &ErrorMsg);
-                               TypeException(void);
-                       };
+\r
+               //! Holds the exceptions related to types and their conversions\r
+               namespace Exceptions\r
+               {\r
+                       //! Generic type exception possibly due to conversion or improper usage\r
+                       class TypeException : public GameServException\r
+                       {\r
+                       public:\r
+                               TypeException(const string &ErrorMsg, const char *pFilename, int SourceLine);\r
+                               TypeException(const string &ErrorMsg);\r
+                               TypeException(void);\r
+                       };\r
                }\r
 \r
                class ItemTypes\r
@@ -44,12 +65,140 @@ namespace GameServ
                        typedef struct itemtypeinfo\r
                        {\r
                                ItemTypes::ItemType itemtype;   //!< The ItemType enumeration value\r
-                               const char *name;                               //!< The Name of the type\r
+                               string name;                            //!< The Name of the type\r
                        } itemtypeinfo;\r
 \r
                        static const itemtypeinfo mItemTypeInfoTable[];\r
 \r
                }; // ItemTypes class\r
-       }\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
+                       //! Logical Modifer enumerator\r
+                       enum Modifier\r
+                       {\r
+                               strength, defense, maxhealth, health, forestfights, playerfights, gold, bank\r
+                       };\r
+\r
+                       //! Get the name of a modifier\r
+                       static string GetName(Modifier modifier);\r
+\r
+                       //! Parse the name and return the modifier enumeration value\r
+                       static Modifier Parse(const string &modifier);\r
+               private:\r
+                       typedef struct modifierinfo\r
+                       {\r
+                               Modifiers::Modifier modifier; //!< The modifier enumeration value\r
+                               string name; //!< The name of the modifier\r
+                       } modifierinfo;\r
+                       static const modifierinfo mModifierInfoTable[];\r
+               }; // Modifiers class\r
+\r
+               template <class T>\r
+               class Range\r
+               {\r
+               public:\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
+                       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
+                       T High(void) const\r
+                       {\r
+                               return mHigh;\r
+                       }\r
+                       \r
+                       //! Property set - High\r
+                       void High(const T &value)\r
+                       {\r
+                               if (value >= mLow)\r
+                               {\r
+                                       mHigh = value;\r
+                               }\r
+                       }\r
+\r
+                       //! Property get - Low\r
+                       T Low(void) const\r
+                       {\r
+                               return mLow;\r
+                       }\r
+\r
+                       //! Property set - Low\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
+                       T mHigh;\r
+                       T mLow;\r
+                       T mLastRandom;\r
+               };\r
+       } \r
 }\r
 #endif
\ No newline at end of file