]> jfr.im git - irc/gameservirc.git/commitdiff
Added a Range class to the Types namespace, and shelled out some basic MonsterGO...
authorkainazzzo <redacted>
Thu, 17 Sep 2009 18:02:49 +0000 (18:02 +0000)
committerkainazzzo <redacted>
Thu, 17 Sep 2009 18:02:49 +0000 (18:02 +0000)
testdriver/main.cpp will change a lot to test various parts of the library.

git-svn-id: https://svn.code.sf.net/p/gameservirc/code/trunk@525 bc333340-6410-0410-a689-9d09f3c113fa

gameserv-2.0/libgameservcore/include/GameServ/Types.h
gameserv-2.0/libgameservcore/src/Types.cpp
gameserv-2.0/libgameservgldl/include/GameServ/GameLayer/GameObjects/LevelGO.h [new file with mode: 0644]
gameserv-2.0/libgameservgldl/include/GameServ/GameLayer/GameObjects/MasterGO.h [new file with mode: 0644]
gameserv-2.0/libgameservgldl/include/GameServ/GameLayer/GameObjects/MonsterGO.h [new file with mode: 0644]
gameserv-2.0/libgameservgldl/libgameservgldl.vcproj
gameserv-2.0/libgameservgldl/src/GameLayer/GameObjects/LevelGO.cpp [new file with mode: 0644]
gameserv-2.0/libgameservgldl/src/GameLayer/GameObjects/MasterGO.cpp [new file with mode: 0644]
gameserv-2.0/libgameservgldl/src/GameLayer/GameObjects/MonsterGO.cpp [new file with mode: 0644]
gameserv-2.0/testdriver/main.cpp

index 6e200fc278156d7509abc12225732485387241d4..ef6229efef4de12d30c665e1cd9a4a4079e5b596 100644 (file)
@@ -6,6 +6,16 @@ using std::string;
 #include <GameServ/GameServException.h>\r
 using GameServ::Exceptions::GameServException;\r
 \r
+\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
+\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
 namespace GameServ \r
 {              \r
        namespace Types\r
@@ -73,6 +83,33 @@ namespace GameServ
                        } modifierinfo;\r
                        static const modifierinfo mModifierInfoTable[];\r
                }; // Modifiers class\r
+\r
+               class Range\r
+               {\r
+               public:\r
+                       Range(const unsigned int &high, const unsigned int &low);\r
+                       ~Range();\r
+\r
+                       //! Generate a random number within the range\r
+                       unsigned int Random();\r
+\r
+                       //! Property get - High\r
+                       unsigned int High(void) const;\r
+                       \r
+                       //! Property set - High\r
+                       void High(const unsigned int &value);\r
+\r
+                       //! Property get - Low\r
+                       unsigned int Low(void) const;\r
+\r
+                       //! Property set - Low\r
+                       void Low(const unsigned int &value);\r
+                       \r
+               private:\r
+                       unsigned int mHigh;\r
+                       unsigned int mLow;\r
+                       base_generator_type generator;\r
+               };\r
        } \r
 }\r
 #endif
\ No newline at end of file
index e657b472e3537f36ab2674ca70156e967727a1b3..0c23771a3bef49ebd1bed61288ed055ef4c9f64b 100644 (file)
@@ -1,6 +1,7 @@
 #include <GameServ/Types.h>\r
 using GameServ::Types::ItemTypes;\r
 using GameServ::Types::Modifiers;\r
+using GameServ::Types::Range;\r
 using GameServ::Types::Exceptions::TypeException;\r
 \r
 #include <string>\r
@@ -14,6 +15,23 @@ using std::exception;
 using boost::format;\r
 using boost::str;\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
+\r
 TypeException::TypeException(const string &ErrorMsg, const char *pFilename, int SourceLine)\r
 : GameServException(ErrorMsg, pFilename, SourceLine)\r
 { }\r
@@ -90,4 +108,44 @@ Modifiers::Modifier Modifiers::Parse(const string &modifier)
        }\r
 \r
        throw TypeException(str(format("No modifier enumeration found for %1%") % modifier), __FILE__, __LINE__);\r
+}\r
+\r
+Range::Range(const unsigned int &high, const unsigned int &low)\r
+{\r
+       mHigh = high;\r
+       mLow = low;\r
+       generator.seed(static_cast<unsigned int>(std::time(0)));\r
+}\r
+\r
+Range::~Range()\r
+{\r
+}\r
+\r
+void Range::High(const unsigned int &value)\r
+{\r
+       if (mHigh > mLow)\r
+               mHigh = value;\r
+}\r
+\r
+unsigned int Range::High(void) const\r
+{\r
+       return mHigh;\r
+}\r
+\r
+void Range::Low(const unsigned int &value)\r
+{\r
+       if (mLow < mHigh)\r
+               mLow = value;\r
+}\r
+\r
+unsigned int Range::Low(void) const\r
+{\r
+       return mLow;\r
+}\r
+\r
+unsigned int Range::Random()\r
+{\r
+       boost::uniform_int<> uni_dist(mHigh, mLow);\r
+       boost::variate_generator<base_generator_type&, boost::uniform_int<> > uni(generator, uni_dist);\r
+       return static_cast<unsigned int>(uni());\r
 }
\ No newline at end of file
diff --git a/gameserv-2.0/libgameservgldl/include/GameServ/GameLayer/GameObjects/LevelGO.h b/gameserv-2.0/libgameservgldl/include/GameServ/GameLayer/GameObjects/LevelGO.h
new file mode 100644 (file)
index 0000000..cd9234a
--- /dev/null
@@ -0,0 +1,41 @@
+#ifndef __GS__LEVEL_H__\r
+#define __GS__LEVEL_H__\r
+#include <GameServ/GameLayer/GameObjects/GameObject.h>\r
+using GameServ::GameLayer::GameObjects::GameObject;\r
+#include <GameServ/GameLayer/GameObjects/MasterGO.h>\r
+using GameServ::GameLayer::GameObjects::MasterGO;\r
+#include <GameServ/GameLayer/GameObjects/MonsterGO.h>\r
+using GameServ::GameLayer::GameObjects::MonsterGO;\r
+\r
+#include <string>\r
+using std::string;\r
+#include <vector>\r
+using std::vector;\r
+\r
+#include <boost/smart_ptr/shared_ptr.hpp>\r
+using boost::shared_ptr;\r
+\r
+namespace GameServ { namespace GameLayer { namespace GameObjects\r
+{\r
+       class LevelGO : public GameObject\r
+       {\r
+       public:\r
+\r
+               LevelGO();\r
+               LevelGO(const string &Id);\r
+\r
+               virtual ~LevelGO();\r
+\r
+               bool operator==(const LevelGO &right) const;\r
+               bool operator!=(const LevelGO &right) const;\r
+\r
+               virtual LevelGO *Clone(void) const;\r
+\r
+       private:\r
+\r
+               vector< shared_ptr<MonsterGO> > mspMonsters;\r
+               shared_ptr<MasterGO> mspMaster;\r
+               \r
+       };\r
+}}} // GameServ::GameLayer::GameObjects\r
+#endif
\ No newline at end of file
diff --git a/gameserv-2.0/libgameservgldl/include/GameServ/GameLayer/GameObjects/MasterGO.h b/gameserv-2.0/libgameservgldl/include/GameServ/GameLayer/GameObjects/MasterGO.h
new file mode 100644 (file)
index 0000000..c174457
--- /dev/null
@@ -0,0 +1,78 @@
+#ifndef __GS__MASTER_H__\r
+#define __GS__MASTER_H__\r
+#include <GameServ/GameLayer/GameObjects/GameObject.h>\r
+using GameServ::GameLayer::GameObjects::GameObject;\r
+\r
+#include <string>\r
+using std::string;\r
+\r
+namespace GameServ { namespace GameLayer { namespace GameObjects\r
+{\r
+       class MasterGO : public GameObject\r
+       {\r
+       public:\r
+\r
+               MasterGO();\r
+               MasterGO(const string &Id);\r
+\r
+               virtual ~MasterGO();\r
+\r
+               //! Property get - Name\r
+               string Name(void) const;\r
+               //! Property set - Name\r
+               void Name(const string &value);\r
+\r
+               //! Property get - Gold\r
+               unsigned long int Gold(void) const;\r
+               //! Property set - Gold\r
+               void Gold(const unsigned long int &value);\r
+\r
+               //! Property get - Health\r
+               int Health(void) const;\r
+               //! Property set - Health\r
+               void Health(const int &value);\r
+\r
+               //! Property get - Max Health\r
+               int MaxHealth(void) const;\r
+               //! Property set - Max Health\r
+               void MaxHealth(const int &value);\r
+\r
+               //! Property get - Strength\r
+               int Strength(void) const;\r
+               //! Property set - Strength\r
+               void Strength(const int &value);\r
+\r
+               //! Property get - Defense\r
+               int Defense(void) const;\r
+               //! Property set - Defense\r
+               void Defense(const int &value);\r
+\r
+               //! Property get - Weapon Name\r
+               string WeaponName(void) const;\r
+\r
+               //! Property set - Weapon Name\r
+               void WeaponName(const string &value);\r
+\r
+               //! Property get - Death Cry\r
+               string DeathCry(void) const;\r
+\r
+               //! Property set - Death Cry\r
+               void DeathCry(const string &value);\r
+\r
+               bool operator==(const MasterGO &right) const;\r
+               bool operator!=(const MasterGO &right) const;\r
+\r
+               virtual MasterGO *Clone(void) const;\r
+\r
+       private:\r
+               string mName;\r
+               unsigned long int mGold;\r
+               int mHealth;\r
+               int mMaxHealth;\r
+               int mStrength;\r
+               int mDefense;\r
+               string mWeaponName;\r
+               string mDeathCry;\r
+       };\r
+}}} // GameServ::GameLayer::GameObjects\r
+#endif
\ No newline at end of file
diff --git a/gameserv-2.0/libgameservgldl/include/GameServ/GameLayer/GameObjects/MonsterGO.h b/gameserv-2.0/libgameservgldl/include/GameServ/GameLayer/GameObjects/MonsterGO.h
new file mode 100644 (file)
index 0000000..feecfcc
--- /dev/null
@@ -0,0 +1,78 @@
+#ifndef __GS__MONSTER_H__\r
+#define __GS__MONSTER_H__\r
+#include <GameServ/GameLayer/GameObjects/GameObject.h>\r
+using GameServ::GameLayer::GameObjects::GameObject;\r
+\r
+#include <string>\r
+using std::string;\r
+\r
+namespace GameServ { namespace GameLayer { namespace GameObjects\r
+{\r
+       class MonsterGO : public GameObject\r
+       {\r
+       public:\r
+\r
+               MonsterGO();\r
+               MonsterGO(const string &Id);\r
+\r
+               virtual ~MonsterGO();\r
+\r
+               //! Property get - Name\r
+               string Name(void) const;\r
+               //! Property set - Name\r
+               void Name(const string &value);\r
+\r
+               //! Property get - Gold\r
+               unsigned long int Gold(void) const;\r
+               //! Property set - Gold\r
+               void Gold(const unsigned long int &value);\r
+\r
+               //! Property get - Health\r
+               int Health(void) const;\r
+               //! Property set - Health\r
+               void Health(const int &value);\r
+\r
+               //! Property get - Max Health\r
+               int MaxHealth(void) const;\r
+               //! Property set - Max Health\r
+               void MaxHealth(const int &value);\r
+\r
+               //! Property get - Strength\r
+               int Strength(void) const;\r
+               //! Property set - Strength\r
+               void Strength(const int &value);\r
+\r
+               //! Property get - Defense\r
+               int Defense(void) const;\r
+               //! Property set - Defense\r
+               void Defense(const int &value);\r
+\r
+               //! Property get - Weapon Name\r
+               string WeaponName(void) const;\r
+\r
+               //! Property set - Weapon Name\r
+               void WeaponName(const string &value);\r
+\r
+               //! Property get - Death Cry\r
+               string DeathCry(void) const;\r
+\r
+               //! Property set - Death Cry\r
+               void DeathCry(const string &value);\r
+\r
+               bool operator==(const MonsterGO &right) const;\r
+               bool operator!=(const MonsterGO &right) const;\r
+\r
+               virtual MonsterGO *Clone(void) const;\r
+\r
+       private:\r
+               string mName;\r
+               unsigned long int mGold;\r
+               int mHealth;\r
+               int mMaxHealth;\r
+               int mStrength;\r
+               int mDefense;\r
+               string mWeaponName;\r
+               string mDeathCry;\r
+       };\r
+}}} // GameServ::GameLayer::GameObjects\r
+#endif
\ No newline at end of file
index c46cf04f5b749f5005a31574a9ea6522d86aebe9..80bf7831b6b2562dfba14df7fbde4b6d9dd37bf8 100644 (file)
                                        RelativePath=".\include\GameServ\GameLayer\GameObjects\ItemGO.h"\r
                                        >\r
                                </File>\r
+                               <File\r
+                                       RelativePath=".\src\GameLayer\GameObjects\LevelGO.cpp"\r
+                                       >\r
+                               </File>\r
+                               <File\r
+                                       RelativePath=".\include\GameServ\GameLayer\GameObjects\LevelGO.h"\r
+                                       >\r
+                               </File>\r
+                               <File\r
+                                       RelativePath=".\src\GameLayer\GameObjects\MasterGO.cpp"\r
+                                       >\r
+                               </File>\r
+                               <File\r
+                                       RelativePath=".\include\GameServ\GameLayer\GameObjects\MasterGO.h"\r
+                                       >\r
+                               </File>\r
+                               <File\r
+                                       RelativePath=".\src\GameLayer\GameObjects\MonsterGO.cpp"\r
+                                       >\r
+                               </File>\r
+                               <File\r
+                                       RelativePath=".\include\GameServ\GameLayer\GameObjects\MonsterGO.h"\r
+                                       >\r
+                               </File>\r
                                <File\r
                                        RelativePath=".\src\GameLayer\GameObjects\PlayerGO.cpp"\r
                                        >\r
diff --git a/gameserv-2.0/libgameservgldl/src/GameLayer/GameObjects/LevelGO.cpp b/gameserv-2.0/libgameservgldl/src/GameLayer/GameObjects/LevelGO.cpp
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/gameserv-2.0/libgameservgldl/src/GameLayer/GameObjects/MasterGO.cpp b/gameserv-2.0/libgameservgldl/src/GameLayer/GameObjects/MasterGO.cpp
new file mode 100644 (file)
index 0000000..604fbe5
--- /dev/null
@@ -0,0 +1,123 @@
+#include <GameServ/GameLayer/GameObjects/GameObject.h>\r
+using GameServ::GameLayer::GameObjects::GameObject;\r
+#include <GameServ/GameLayer/GameObjects/MasterGO.h>\r
+using GameServ::GameLayer::GameObjects::MasterGO;\r
+\r
+#include <string>\r
+using std::string;\r
+\r
+MasterGO::MasterGO()\r
+{\r
+}\r
+\r
+MasterGO::MasterGO(const string &Id) : GameObject(Id)\r
+{\r
+}\r
+\r
+MasterGO::~MasterGO()\r
+{\r
+}\r
+\r
+MasterGO *MasterGO::Clone(void) const\r
+{\r
+       return new MasterGO(*this);\r
+}\r
+\r
+void MasterGO::Name(const string &value)\r
+{\r
+       assert(!value.empty());\r
+       mName = value;\r
+}\r
+\r
+string MasterGO::Name(void) const\r
+{\r
+       return mName;\r
+}\r
+\r
+void MasterGO::Strength(const int &value)\r
+{\r
+       assert(value > 0);\r
+       mStrength = value;\r
+}\r
+\r
+int MasterGO::Strength(void) const\r
+{\r
+       return mStrength;\r
+}\r
+\r
+void MasterGO::Defense(const int &value)\r
+{\r
+       assert(value > 0);\r
+       mDefense = value;\r
+}\r
+\r
+int MasterGO::Defense(void) const\r
+{\r
+       return mDefense;\r
+}\r
+\r
+void MasterGO::Gold(const unsigned long &value)\r
+{\r
+       mGold = value;\r
+}\r
+\r
+unsigned long MasterGO::Gold(void) const\r
+{\r
+       return mGold;\r
+}\r
+\r
+void MasterGO::Health(const int &value)\r
+{\r
+       mHealth = value;\r
+}\r
+\r
+int MasterGO::Health(void) const\r
+{\r
+       return mHealth;\r
+}\r
+\r
+void MasterGO::MaxHealth(const int &value)\r
+{\r
+       mMaxHealth = value;\r
+}\r
+\r
+int MasterGO::MaxHealth(void) const\r
+{\r
+       return mMaxHealth;\r
+}\r
+\r
+void MasterGO::WeaponName(const string &value)\r
+{\r
+       assert(!value.empty());\r
+       mWeaponName = value;\r
+}\r
+\r
+string MasterGO::WeaponName(void) const\r
+{\r
+       return mWeaponName;\r
+}\r
+\r
+void MasterGO::DeathCry(const string &value)\r
+{\r
+       assert(!value.empty());\r
+       mDeathCry = value;\r
+}\r
+\r
+string MasterGO::DeathCry(void) const\r
+{\r
+       return mDeathCry;\r
+}\r
+\r
+bool MasterGO::operator==(const MasterGO &right) const\r
+{\r
+       return mId == right.mId && mHealth == right.mHealth &&\r
+               mDefense == right.mDefense && mDeathCry == right.mDeathCry &&\r
+               mGold == right.mGold && mHealth == right.mHealth && \r
+               mMaxHealth == right.mMaxHealth && mName == right.mName &&\r
+               mStrength == right.mStrength && mWeaponName == right.mWeaponName;\r
+}\r
+\r
+bool MasterGO::operator!=(const MasterGO &right) const\r
+{\r
+       return (!(*this == right));\r
+}
\ No newline at end of file
diff --git a/gameserv-2.0/libgameservgldl/src/GameLayer/GameObjects/MonsterGO.cpp b/gameserv-2.0/libgameservgldl/src/GameLayer/GameObjects/MonsterGO.cpp
new file mode 100644 (file)
index 0000000..0edabd8
--- /dev/null
@@ -0,0 +1,123 @@
+#include <GameServ/GameLayer/GameObjects/GameObject.h>\r
+using GameServ::GameLayer::GameObjects::GameObject;\r
+#include <GameServ/GameLayer/GameObjects/MonsterGO.h>\r
+using GameServ::GameLayer::GameObjects::MonsterGO;\r
+\r
+#include <string>\r
+using std::string;\r
+\r
+MonsterGO::MonsterGO()\r
+{\r
+}\r
+\r
+MonsterGO::MonsterGO(const string &Id) : GameObject(Id)\r
+{\r
+}\r
+\r
+MonsterGO::~MonsterGO()\r
+{\r
+}\r
+\r
+MonsterGO *MonsterGO::Clone(void) const\r
+{\r
+       return new MonsterGO(*this);\r
+}\r
+\r
+void MonsterGO::Name(const string &value)\r
+{\r
+       assert(!value.empty());\r
+       mName = value;\r
+}\r
+\r
+string MonsterGO::Name(void) const\r
+{\r
+       return mName;\r
+}\r
+\r
+void MonsterGO::Strength(const int &value)\r
+{\r
+       assert(value > 0);\r
+       mStrength = value;\r
+}\r
+\r
+int MonsterGO::Strength(void) const\r
+{\r
+       return mStrength;\r
+}\r
+\r
+void MonsterGO::Defense(const int &value)\r
+{\r
+       assert(value > 0);\r
+       mDefense = value;\r
+}\r
+\r
+int MonsterGO::Defense(void) const\r
+{\r
+       return mDefense;\r
+}\r
+\r
+void MonsterGO::Gold(const unsigned long &value)\r
+{\r
+       mGold = value;\r
+}\r
+\r
+unsigned long MonsterGO::Gold(void) const\r
+{\r
+       return mGold;\r
+}\r
+\r
+void MonsterGO::Health(const int &value)\r
+{\r
+       mHealth = value;\r
+}\r
+\r
+int MonsterGO::Health(void) const\r
+{\r
+       return mHealth;\r
+}\r
+\r
+void MonsterGO::MaxHealth(const int &value)\r
+{\r
+       mMaxHealth = value;\r
+}\r
+\r
+int MonsterGO::MaxHealth(void) const\r
+{\r
+       return mMaxHealth;\r
+}\r
+\r
+void MonsterGO::WeaponName(const string &value)\r
+{\r
+       assert(!value.empty());\r
+       mWeaponName = value;\r
+}\r
+\r
+string MonsterGO::WeaponName(void) const\r
+{\r
+       return mWeaponName;\r
+}\r
+\r
+void MonsterGO::DeathCry(const string &value)\r
+{\r
+       assert(!value.empty());\r
+       mDeathCry = value;\r
+}\r
+\r
+string MonsterGO::DeathCry(void) const\r
+{\r
+       return mDeathCry;\r
+}\r
+\r
+bool MonsterGO::operator==(const MonsterGO &right) const\r
+{\r
+       return mId == right.mId && mHealth == right.mHealth &&\r
+               mDefense == right.mDefense && mDeathCry == right.mDeathCry &&\r
+               mGold == right.mGold && mHealth == right.mHealth && \r
+               mMaxHealth == right.mMaxHealth && mName == right.mName &&\r
+               mStrength == right.mStrength && mWeaponName == right.mWeaponName;\r
+}\r
+\r
+bool MonsterGO::operator!=(const MonsterGO &right) const\r
+{\r
+       return (!(*this == right));\r
+}
\ No newline at end of file
index 5c962a3d5d97f6ba08efd77c30b454fa68e0a0f5..11a31f2f7c59d564cb7070781758ff63a620d1e2 100644 (file)
@@ -8,15 +8,25 @@ using GameServ::GameLayer::PlayerGL;
 #include <GameServ/GameServException.h>\r
 using GameServ::Exceptions::GameServException;\r
 \r
+#include <GameServ/Types.h>\r
+using GameServ::Types::Range;\r
+\r
 int main()\r
 {\r
        try\r
        {\r
-               PlayerGL pgl;\r
+       /*      PlayerGL pgl;\r
                shared_ptr<PlayerGO> spPlayer = pgl.GetById("Kain");\r
                cout << spPlayer->Name() << endl;\r
                spPlayer->Name("Kainazzzo");\r
-               pgl.Insert(spPlayer);\r
+               pgl.Insert(spPlayer);*/\r
+\r
+               Range testrange(20, 100);\r
+\r
+               for (int x = 0; x < 100; x++)\r
+               {\r
+                       cout << testrange.Random() << endl;\r
+               }\r
        }\r
        catch (GameServException &e)\r
        {\r