X-Git-Url: https://jfr.im/git/irc/gameservirc.git/blobdiff_plain/e0d3cb09ee3cbd32ea2e6c6b4a981e46d7878259..9920617b5f77fa9d420300fdc9bfe5357938eecf:/gameserv-2.0/libgameservcore/include/GameServ/Types.h diff --git a/gameserv-2.0/libgameservcore/include/GameServ/Types.h b/gameserv-2.0/libgameservcore/include/GameServ/Types.h index 8459938..de0fab2 100644 --- a/gameserv-2.0/libgameservcore/include/GameServ/Types.h +++ b/gameserv-2.0/libgameservcore/include/GameServ/Types.h @@ -6,22 +6,43 @@ using std::string; #include using GameServ::Exceptions::GameServException; +#include +#include +#include +#include +#include +// Sun CC doesn't handle boost::iterator_adaptor yet +#if !defined(__SUNPRO_CC) || (__SUNPRO_CC > 0x530) +#include +#endif + +#ifdef BOOST_NO_STDC_NAMESPACE +namespace std { + using ::time; +} +#endif + +// This is a typedef for a random number generator. +// Try boost::mt19937 or boost::ecuyer1988 instead of boost::minstd_rand +typedef boost::minstd_rand base_generator_type; + + namespace GameServ { namespace Types { - - //! 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); - }; + + //! 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); + }; } class ItemTypes @@ -44,12 +65,140 @@ namespace GameServ typedef struct itemtypeinfo { ItemTypes::ItemType itemtype; //!< The ItemType enumeration value - const char *name; //!< The Name of the type + string name; //!< The Name of the type } itemtypeinfo; static const itemtypeinfo mItemTypeInfoTable[]; }; // ItemTypes class - } + + class ObjectTypes + { + public: + //! Logical ObjectType enumerator + enum ObjectType + { + Player, Item, Level, Master, Monster + }; + + //! Get the name of an object type + static string GetName(ObjectType objecttype); + + //! Parse the name and return the enumeration value + static ObjectType Parse(const string &objecttype); + + private: + //! Internal struct to hold type information statically in a table + typedef struct objecttypeinfo + { + ObjectTypes::ObjectType objecttype; //!< The ObjectType enumeration value + string name; //!< The Name of the type + } objecttypeinfo; + + static const objecttypeinfo mObjectTypeInfoTable[]; + + }; // ObjectTypes class + + class Modifiers + { + public: + //! Logical Modifer enumerator + enum Modifier + { + strength, defense, maxhealth, health, forestfights, playerfights, gold, bank + }; + + //! Get the name of a modifier + static string GetName(Modifier modifier); + + //! Parse the name and return the modifier enumeration value + static Modifier Parse(const string &modifier); + private: + typedef struct modifierinfo + { + Modifiers::Modifier modifier; //!< The modifier enumeration value + string name; //!< The name of the modifier + } modifierinfo; + static const modifierinfo mModifierInfoTable[]; + }; // Modifiers class + + template + class Range + { + public: + + Range() + { + } + + Range(const T &high, const T &low) + { + mHigh = high; + mLow = low; + } + + ~Range() + { + } + + //! Generate a random number within the range + T Random() + { + static base_generator_type generator(static_cast(std::time(0))); + if (mLow == mHigh) + { + return mLow; + } + else + { + boost::uniform_int<> uni_dist(mLow, mHigh); + boost::variate_generator > uni(generator, uni_dist); + mLastRandom = uni(); + return mLastRandom; + } + } + + //! Property get - High + T High(void) const + { + return mHigh; + } + + //! Property set - High + void High(const T &value) + { + if (value >= mLow) + { + mHigh = value; + } + } + + //! Property get - Low + T Low(void) const + { + return mLow; + } + + //! Property set - Low + void Low(const T &value) + { + if (value <= mHigh) + { + mLow = value; + } + } + + //! Property get - Last random number to be generated + T LastRandom(void) const + { + return mLastRandom; + } + + private: + T mHigh; + T mLow; + T mLastRandom; + }; + } } #endif \ No newline at end of file