summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHuynh Tran <nthuynh75@gmail.com>2005-06-29 08:43:55 +0000
committerHuynh Tran <nthuynh75@gmail.com>2005-06-29 08:43:55 +0000
commit202b03b2ad1160e119b74f7f50ded8de7464c40f (patch)
treeadd2ea0bc0a61ba121fd9dbc83a5d224ba672cd5
parentf83980082a8ee69b1356f58159867e1313ebf868 (diff)
downloadmanaserv-202b03b2ad1160e119b74f7f50ded8de7464c40f.tar.gz
manaserv-202b03b2ad1160e119b74f7f50ded8de7464c40f.tar.bz2
manaserv-202b03b2ad1160e119b74f7f50ded8de7464c40f.tar.xz
manaserv-202b03b2ad1160e119b74f7f50ded8de7464c40f.zip
Fixed bugs, added new accessors and mutators to Object and Being, sync'd the rest of the code to take into account the changes.
-rw-r--r--src/Makefile.am8
-rw-r--r--src/account.h2
-rw-r--r--src/being.cpp277
-rw-r--r--src/being.h296
-rw-r--r--src/dalstorage.cpp113
-rw-r--r--src/defines.h36
-rw-r--r--src/object.cpp131
-rw-r--r--src/object.h175
-rw-r--r--src/storage.h1
-rw-r--r--src/tests/Makefile.am1
-rw-r--r--src/tests/testaccount.cpp25
-rw-r--r--src/tests/testaccount.h2
-rw-r--r--src/tests/teststorage.cpp55
13 files changed, 936 insertions, 186 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index a649b984..f15ee464 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -4,6 +4,8 @@
bin_PROGRAMS = tmwserv
tmwserv_SOURCES = main.cpp \
+ configuration.h \
+ configuration.cpp \
accounthandler.h \
accounthandler.cpp \
connectionhandler.h \
@@ -32,6 +34,8 @@ tmwserv_SOURCES = main.cpp \
account.cpp \
object.h \
object.cpp \
+ being.h \
+ being.cpp \
dalstorage.h \
dalstorage.cpp \
dal/dalexcept.h \
@@ -46,9 +50,7 @@ tmwserv_SOURCES = main.cpp \
utils/cipher.h \
utils/cipher.cpp \
utils/logger.h \
- utils/logger.cpp \
- configuration.h \
- configuration.cpp
+ utils/logger.cpp
if BUILD_MYSQL
tmwserv_SOURCES += dal/mysqldataprovider.h \
diff --git a/src/account.h b/src/account.h
index 3eee1d5e..0291b780 100644
--- a/src/account.h
+++ b/src/account.h
@@ -28,7 +28,7 @@
#include <string>
#include <vector>
-#include "defines.h"
+#include "being.h"
namespace tmwserv
diff --git a/src/being.cpp b/src/being.cpp
new file mode 100644
index 00000000..e6be76b3
--- /dev/null
+++ b/src/being.cpp
@@ -0,0 +1,277 @@
+/*
+ * The Mana World Server
+ * Copyright 2004 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * The Mana World is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or any later version.
+ *
+ * The Mana World is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with The Mana World; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id$
+ */
+
+
+#include "being.h"
+
+
+namespace tmwserv
+{
+
+
+/**
+ * Constructor.
+ */
+Being::Being(const std::string& name,
+ const Genders gender,
+ const unsigned short level,
+ const unsigned int money,
+ const RawStatistics& stats)
+ : mName(name),
+ mGender(gender),
+ mLevel(level),
+ mMoney(money),
+ mRawStats(stats)
+{
+ // NOOP
+}
+
+
+/**
+ * Destructor.
+ */
+Being::~Being(void)
+ throw()
+{
+ // NOOP
+}
+
+
+/**
+ * Get the name.
+ */
+const std::string&
+Being::getName(void) const
+{
+ return mName;
+}
+
+
+/**
+ * Get the gender.
+ */
+Genders
+Being::getGender(void) const
+{
+ return mGender;
+}
+
+
+/**
+ * Set the level.
+ */
+void
+Being::setLevel(const unsigned short level)
+{
+ mLevel = level;
+}
+
+
+/**
+ * Get the level.
+ */
+unsigned short
+Being::getLevel(void) const
+{
+ return mLevel;
+}
+
+
+/**
+ * Set the money.
+ */
+void
+Being::setMoney(const unsigned int amount)
+{
+ mMoney = amount;
+}
+
+
+/**
+ * Get the amount of money.
+ */
+unsigned int
+Being::getMoney(void) const
+{
+ return mMoney;
+}
+
+
+/**
+ * Set the strength.
+ */
+void
+Being::setStrength(const unsigned short strength)
+{
+ mRawStats.strength = strength;
+}
+
+
+/**
+ * Get the strength.
+ */
+unsigned short
+Being::getStrength(void) const
+{
+ return mRawStats.strength;
+}
+
+
+/**
+ * Set the agility.
+ */
+void
+Being::setAgility(const unsigned short agility)
+{
+ mRawStats.agility = agility;
+}
+
+
+/**
+ * Get the agility.
+ */
+unsigned short
+Being::getAgility(void) const
+{
+ return mRawStats.agility;
+}
+
+
+/**
+ * Set the vitality.
+ */
+void
+Being::setVitality(const unsigned short vitality)
+{
+ mRawStats.vitality = vitality;
+}
+
+
+/**
+ * Get the vitality.
+ */
+unsigned short
+Being::getVitality(void) const
+{
+ return mRawStats.vitality;
+}
+
+
+/**
+ * Set the intelligence.
+ */
+void
+Being::setIntelligence(const unsigned short intelligence)
+{
+ mRawStats.intelligence = intelligence;
+}
+
+
+/**
+* Get the intelligence.
+*
+* @return the intelligence.
+*/
+unsigned short
+Being::getIntelligence(void) const
+{
+ return mRawStats.intelligence;
+}
+
+
+/**
+ * Set the dexterity.
+ */
+void
+Being::setDexterity(const unsigned short dexterity)
+{
+ mRawStats.dexterity = dexterity;
+}
+
+
+/**
+ * Get the dexterity.
+ */
+unsigned short
+Being::getDexterity(void) const
+{
+ return mRawStats.dexterity;
+}
+
+
+/**
+ * Set the luck.
+ */
+void
+Being::setLuck(const unsigned short luck)
+{
+ mRawStats.luck = luck;
+}
+
+
+/**
+ * Get the luck.
+ */
+unsigned short
+Being::getLuck(void) const
+{
+ return mRawStats.luck;
+}
+
+
+/**
+ * Set the raw statistics.
+ */
+void
+Being::setRawStatistics(const RawStatistics& stats)
+{
+ mRawStats = stats;
+}
+
+
+/**
+ * Get the raw statistics.
+ */
+RawStatistics&
+Being::getRawStatistics(void)
+{
+ return mRawStats;
+}
+
+
+/**
+ * Update the internal status.
+ */
+void
+Being::update(void)
+{
+ // computed stats.
+ mStats.health = 20 + (20 * mRawStats.vitality);
+ mStats.attack = 10 + mRawStats.strength;
+ mStats.defense = 10 + mRawStats.strength;
+ mStats.magic = 10 + mRawStats.intelligence;
+ mStats.accuracy = 50 + mRawStats.dexterity;
+ mStats.speed = mRawStats.dexterity;
+}
+
+
+} // namespace tmwserv
diff --git a/src/being.h b/src/being.h
new file mode 100644
index 00000000..577ec31e
--- /dev/null
+++ b/src/being.h
@@ -0,0 +1,296 @@
+/*
+ * The Mana World Server
+ * Copyright 2004 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * The Mana World is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or any later version.
+ *
+ * The Mana World is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with The Mana World; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id$
+ */
+
+
+#ifndef _TMWSERV_BEING_H_
+#define _TMWSERV_BEING_H_
+
+
+#include <string>
+#include <vector>
+
+#include "defines.h"
+#include "object.h"
+
+
+namespace tmwserv
+{
+
+
+/**
+ * Structure type for the raw statistics of a Being.
+ */
+struct RawStatistics
+{
+ unsigned short strength;
+ unsigned short agility;
+ unsigned short vitality;
+ unsigned short intelligence;
+ unsigned short dexterity;
+ unsigned short luck;
+};
+
+
+/**
+ * Generic Being (living object).
+ * Used for players & monsters (all animated objects).
+ */
+class Being: public Object
+{
+ public:
+ /**
+ * Constructor.
+ */
+ Being(const std::string& name,
+ const Genders gender,
+ const unsigned short level,
+ const unsigned int money,
+ const RawStatistics& stats);
+
+
+ /**
+ * Destructor.
+ */
+ ~Being(void)
+ throw();
+
+
+ /**
+ * Get the name.
+ *
+ * @return the name.
+ */
+ const std::string&
+ getName(void) const;
+
+
+ /**
+ * Get the gender.
+ *
+ * @return the gender.
+ */
+ Genders
+ getGender(void) const;
+
+
+ /**
+ * Set the level.
+ *
+ * @param level the new level.
+ */
+ void
+ setLevel(const unsigned short level);
+
+
+ /**
+ * Get the level.
+ *
+ * @return the level.
+ */
+ unsigned short
+ getLevel(void) const;
+
+
+ /**
+ * Set the money.
+ *
+ * @param amount the new amount.
+ */
+ void
+ setMoney(const unsigned int amount);
+
+
+ /**
+ * Get the amount of money.
+ *
+ * @return the amount of money.
+ */
+ unsigned int
+ getMoney(void) const;
+
+
+ /**
+ * Set the strength.
+ *
+ * @param strength the new strength.
+ */
+ void
+ setStrength(const unsigned short strength);
+
+
+ /**
+ * Get the strength.
+ *
+ * @return the strength.
+ */
+ unsigned short
+ getStrength(void) const;
+
+
+ /**
+ * Set the agility.
+ *
+ * @param agility the new agility.
+ */
+ void
+ setAgility(const unsigned short agility);
+
+
+ /**
+ * Get the agility.
+ *
+ * @return the agility.
+ */
+ unsigned short
+ getAgility(void) const;
+
+
+ /**
+ * Set the vitality.
+ *
+ * @param vitality the new vitality.
+ */
+ void
+ setVitality(const unsigned short vitality);
+
+
+ /**
+ * Get the vitality.
+ *
+ * @return the vitality.
+ */
+ unsigned short
+ getVitality(void) const;
+
+
+ /**
+ * Set the intelligence.
+ *
+ * @param intelligence the new intelligence.
+ */
+ void
+ setIntelligence(const unsigned short intelligence);
+
+
+ /**
+ * Get the intelligence.
+ *
+ * @return the intelligence.
+ */
+ unsigned short
+ getIntelligence(void) const;
+
+
+ /**
+ * Set the dexterity.
+ *
+ * @param dexterity the new dexterity.
+ */
+ void
+ setDexterity(const unsigned short dexterity);
+
+
+ /**
+ * Get the dexterity.
+ *
+ * @return the dexterity.
+ */
+ unsigned short
+ getDexterity(void) const;
+
+
+ /**
+ * Set the luck.
+ *
+ * @param luck the new luck.
+ */
+ void
+ setLuck(const unsigned short luck);
+
+
+ /**
+ * Get the luck.
+ *
+ * @return the luck.
+ */
+ unsigned short
+ getLuck(void) const;
+
+
+ /**
+ * Set the raw statistics.
+ *
+ * @param stats the new raw statistics.
+ */
+ void
+ setRawStatistics(const RawStatistics& stats);
+
+
+ /**
+ * Get the raw statistics.
+ *
+ * @return the raw statistics.
+ */
+ RawStatistics&
+ getRawStatistics(void);
+
+
+ /**
+ * Update the internal status.
+ */
+ void
+ update(void);
+
+
+ private:
+ /**
+ * Copy constructor.
+ */
+ Being(const Being& rhs);
+
+
+ /**
+ * Assignment operator.
+ */
+ Being&
+ operator=(const Being& rhs);
+
+
+ private:
+ std::string mName; /**< name of the being */
+ Genders mGender; /**< gender of the being */
+ unsigned short mLevel; /**< level of the being */
+ unsigned int mMoney; /**< wealth of the being */
+ RawStatistics mRawStats; /**< raw stats of the being */
+};
+
+
+/**
+ * Type definition for a list of Beings.
+ */
+typedef std::vector<Being*> Beings;
+
+
+} // namespace tmwserv
+
+
+#endif // _TMWSERV_BEING_H_
diff --git a/src/dalstorage.cpp b/src/dalstorage.cpp
index b66e25a3..7821e515 100644
--- a/src/dalstorage.cpp
+++ b/src/dalstorage.cpp
@@ -202,7 +202,11 @@ DALStorage::getAccount(const std::string& userName)
// specialize the string_to functor to convert
// a string to an unsigned int.
- string_to<unsigned int> toUint;
+ string_to<unsigned short> toUint;
+
+ // specialize the string_to functor to convert
+ // a string to an unsigned short.
+ string_to<unsigned short> toUshort;
// add the new Account to the list.
AccountInfo ai;
@@ -222,16 +226,41 @@ DALStorage::getAccount(const std::string& userName)
Beings beings;
for (unsigned int i = 0; i < charInfo.rows(); ++i) {
+ RawStatistics stats = {
+ toUshort(charInfo(i, 9)), // strength
+ toUshort(charInfo(i, 10)), // agility
+ toUshort(charInfo(i, 11)), // vitality
+ toUshort(charInfo(i, 12)), // intelligence
+ toUshort(charInfo(i, 13)), // dexterity
+ toUshort(charInfo(i, 14)) // luck
+ };
+
+ // convert the integer value read from database
+ // to an enum because C++ does not allow implicit
+ // conversion from an integer to an enum.
+ unsigned short value = toUshort(charInfo(i, 3));
+ Genders gender;
+ switch (value)
+ {
+ case 0:
+ gender = GENDER_MALE;
+ break;
+
+ case 1:
+ gender = GENDER_FEMALE;
+ break;
+
+ default:
+ gender = GENDER_UNKNOWN;
+ break;
+ };
+
Being* being =
- new Being(charInfo(i, 2), // name
- toUint(charInfo(i, 3)), // gender
- toUint(charInfo(i, 4)), // level
- toUint(charInfo(i, 5)), // money
- toUint(charInfo(i, 9)), // strength
- toUint(charInfo(i, 10)), // agility
- toUint(charInfo(i, 11)), // vitality
- toUint(charInfo(i, 13)), // dexterity
- toUint(charInfo(i, 14)) // luck
+ new Being(charInfo(i, 2), // name
+ gender, // gender
+ toUshort(charInfo(i, 4)), // level
+ toUint(charInfo(i, 5)), // money
+ stats
);
mCharacters.push_back(being);
@@ -442,17 +471,27 @@ DALStorage::_addAccount(const Account* account)
Beings::const_iterator it = characters.begin();
Beings::const_iterator it_end = characters.end();
for (; it != it_end; ++it) {
- // TODO: location on the map & statistics & inventories.
+ RawStatistics& stats = (*it)->getRawStatistics();
std::ostringstream sql3;
- sql3 << "insert into " << CHARACTERS_TBL_NAME << " values (null, '"
- << account->getName() << "', '"
+ sql3 << "insert into " << CHARACTERS_TBL_NAME << " values (null, "
+ << (account_it->second).id << ", '"
<< (*it)->getName() << "', '"
<< (*it)->getGender() << "', "
<< (*it)->getLevel() << ", "
<< (*it)->getMoney() << ", "
- << "0, 0, 0, 0, 0, 0, 0, 0, 0"
+ << (*it)->getX() << ", "
+ << (*it)->getY() << ", "
+ << "0, " // TODO: map id
+ << stats.strength << ", "
+ << stats.agility << ", "
+ << stats.vitality << ", "
+ << stats.intelligence << ", "
+ << stats.dexterity << ", "
+ << stats.luck
<< ");";
mDb->execSql(sql3.str());
+
+ // TODO: inventories.
}
}
@@ -514,29 +553,51 @@ DALStorage::_updAccount(const Account* account)
<< " where name = '" << (*it)->getName() << "';";
const RecordSet& charInfo = mDb->execSql(sql2.str());
- // TODO: location on the map & statistics & inventories.
+ RawStatistics& stats = (*it)->getRawStatistics();
+
std::ostringstream sql3;
if (charInfo.rows() == 0) {
sql3 << "insert into " << CHARACTERS_TBL_NAME
- << " values (null, '"
- << account->getName() << "', '"
- << (*it)->getName() << "', '"
- << (*it)->getGender() << "', "
+ << " values (null, "
+ << (account_it->second).id << ", '"
+ << (*it)->getName() << "', "
+ << (*it)->getGender() << ", "
<< (*it)->getLevel() << ", "
<< (*it)->getMoney() << ", "
- << "0, 0, 0, 0, 0, 0, 0, 0, 0"
- << ");";
+ << (*it)->getX() << ", "
+ << (*it)->getY() << ", "
+ << "0, " // TODO: map id
+ << stats.strength << ", "
+ << stats.agility << ", "
+ << stats.vitality << ", "
+ << stats.intelligence << ", "
+ << stats.dexterity << ", "
+ << stats.luck << ");";
}
else {
sql3 << "update " << CHARACTERS_TBL_NAME
<< " set name = '" << (*it)->getName() << "', "
- << " gender = '" << (*it)->getGender() << "', "
- << " level = '" << (*it)->getLevel() << "', "
- << " money = '" << (*it)->getMoney() << "' "
- << "where user_id = '" << (account_it->second).id
- << "';";
+ << " gender = " << (*it)->getGender() << ", "
+ << " level = " << (*it)->getLevel() << ", "
+ << " money = " << (*it)->getMoney() << ", "
+ << " x = " << (*it)->getX() << ", "
+ << " y = " << (*it)->getY() << ", "
+ << " map_id = 0, " // TODO: map id
+ << " str = " << stats.strength << ", "
+ << " agi = " << stats.agility << ", "
+ << " vit = " << stats.vitality << ", "
+#ifdef MYSQL_SUPPORT
+ << " `int` = " << stats.intelligence << ", "
+#else
+ << " int = " << stats.intelligence << ", "
+#endif
+ << " dex = " << stats.dexterity << ", "
+ << " luck = " << stats.luck
+ << " where id = " << charInfo(0, 0) << ";";
}
mDb->execSql(sql3.str());
+
+ // TODO: inventories.
}
}
diff --git a/src/defines.h b/src/defines.h
index ff670b86..2f84c806 100644
--- a/src/defines.h
+++ b/src/defines.h
@@ -4,29 +4,27 @@
*
* This file is part of The Mana World.
*
- * The Mana World is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
+ * The Mana World is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or any later version.
*
- * The Mana World is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
+ * The Mana World is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
*
- * You should have received a copy of the GNU General Public License
- * along with The Mana World; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * You should have received a copy of the GNU General Public License along
+ * with The Mana World; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* $Id$
*/
-#ifndef _TMW_SERVER_DEFINES_
-#define _TMW_SERVER_DEFINES_
-#include <string>
-#include "object.h"
-
+#ifndef _TMWSERV_DEFINES_H_
+#define _TMWSERV_DEFINES_H_
+
+
/**
* Enumeration type for account levels.
*
@@ -46,6 +44,7 @@ typedef enum {
AL_RESTRICTED // User rights have been restricted
} AccountLevels;
+
/**
* Enumeration type for the player genders.
*/
@@ -54,5 +53,6 @@ typedef enum {
GENDER_FEMALE,
GENDER_UNKNOWN
} Genders;
-
-#endif
+
+
+#endif // _TMWSERV_DEFINES_H_
diff --git a/src/object.cpp b/src/object.cpp
index f67bae05..e8dd18ca 100644
--- a/src/object.cpp
+++ b/src/object.cpp
@@ -4,59 +4,114 @@
*
* This file is part of The Mana World.
*
- * The Mana World is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
+ * The Mana World is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or any later version.
*
- * The Mana World is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
+ * The Mana World is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
*
- * You should have received a copy of the GNU General Public License
- * along with The Mana World; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * You should have received a copy of the GNU General Public License along
+ * with The Mana World; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* $Id$
*/
+
#include "object.h"
-Being::Being(const std::string &bName, unsigned int bGender,
- unsigned int bLevel, unsigned int bMoney,
- unsigned int bStrength, unsigned int bAgility,
- unsigned int bVitality, unsigned int bDexterity,
- unsigned int bLuck):
- name(bName),
- gender(bGender),
- level(bLevel),
- money(bMoney),
- strength(bStrength),
- agility(bAgility),
- vitality(bVitality),
- dexterity(bDexterity),
- luck(bLuck)
+
+namespace tmwserv
+{
+
+
+/**
+ * Default constructor.
+ */
+Object::Object(void)
+ : mX(0),
+ mY(0)
+{
+ mStats.health = 0;
+ mStats.attack = 0;
+ mStats.defense = 0;
+ mStats.magic = 0;
+ mStats.accuracy = 0;
+ mStats.speed = 0;
+}
+
+
+/**
+ * Destructor.
+ */
+Object::~Object(void)
+ throw()
{
- //std::cout << "New being create with name \"" + name + "\"" << std::endl;
+ // NOOP
}
-void Being::update()
+
+/**
+ * Set the x coordinate.
+ */
+void
+Object::setX(unsigned int x)
{
- //Generate statistics
- stats.health = 20 + (20 * vitality);
- stats.attack = 10 + strength;
- stats.defense = 10 + strength;
- stats.magic = 10 + intelligence;
- stats.accuracy = 50 + dexterity;
- stats.speed = dexterity;
+ mX = x;
+}
- //Update scipt
-#ifdef SCRIPT_SUPPORT
- script->update();
-#endif
+
+/**
+ * Get the x coordinate.
+ */
+unsigned int
+Object::getX(void) const
+{
+ return mX;
}
+/**
+ * Set the y coordinate.
+ */
+void
+Object::setY(unsigned int y)
+{
+ mY = y;
+}
+
+
+/**
+ * Get the y coordinate.
+ */
+unsigned int
+Object::getY(void) const
+{
+ return mY;
+}
+
+
+/**
+ * Set the statistics.
+ */
+void
+Object::setStatistics(const Statistics& stats)
+{
+ mStats = stats;
+}
+
+
+/**
+ * Get the statistics.
+ */
+Statistics&
+Object::getStatistics(void)
+{
+ return mStats;
+}
+} // namespace tmwserv
diff --git a/src/object.h b/src/object.h
index bba3af3e..a696ea51 100644
--- a/src/object.h
+++ b/src/object.h
@@ -4,33 +4,40 @@
*
* This file is part of The Mana World.
*
- * The Mana World is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
+ * The Mana World is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or any later version.
*
- * The Mana World is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
+ * The Mana World is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
*
- * You should have received a copy of the GNU General Public License
- * along with The Mana World; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * You should have received a copy of the GNU General Public License along
+ * with The Mana World; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* $Id$
*/
-#ifndef OBJECT_H
-#define OBJECT_H
+#ifndef _TMWSERV_OBJECT_H_
+#define _TMWSERV_OBJECT_H_
-#include <iostream>
-#include <vector>
-#include "script.h"
-//Usable Statistics Definition (not unsigned to allow for negative; used for
-//summative statistics)
+namespace tmwserv
+{
+
+
+/**
+ * Structure type for the statistics.
+ *
+ * Notes:
+ * - the structure can be used to define stats modifiers (i.e. how an
+ * object would modify the stats of a being when it is equipped) or
+ * computed stats of a being.
+ * - the attributes are not unsigned to allow negative values.
+ */
struct Statistics
{
int health;
@@ -41,84 +48,100 @@ struct Statistics
int speed;
};
-/*
- * Generic In-Game Object Definition
- * Base class for in-game objects
+
+/**
+ * Generic in-game object definition.
+ * Base class for in-game objects.
*/
class Object
{
- int x;
- int y;
- public:
- virtual ~Object() { }
- virtual void update() = 0;
-};
+ public:
+ /**
+ * Default constructor.
+ */
+ Object(void);
-/*
- * Generic Being (Living Object)
- * Used for Player & Monster (all animate objects)
- */
-class Being : public Object
-{
- //Being name
- std::string name;
- //Being gender
- unsigned int gender;
+ /**
+ * Destructor.
+ */
+ virtual
+ ~Object(void)
+ throw();
+
+
+ /**
+ * Set the x coordinate.
+ *
+ * @param x the new x coordinate.
+ */
+ void
+ setX(unsigned int x);
+
+
+ /**
+ * Get the x coordinate.
+ *
+ * @return the x coordinate.
+ */
+ unsigned int
+ getX(void) const;
+
- //Being level
- unsigned int level;
+ /**
+ * Set the y coordinate.
+ *
+ * @param y the new y coordinate.
+ */
+ void
+ setY(unsigned int y);
- //Being money
- unsigned int money;
- //Being statistics
- unsigned int strength;
- unsigned int agility;
- unsigned int vitality;
- unsigned int intelligence;
- unsigned int dexterity;
- unsigned int luck;
+ /**
+ * Get the y coordinate.
+ *
+ * @return the y coordinate.
+ */
+ unsigned int
+ getY(void) const;
- //Derived statistics (derived from above)
- Statistics stats;
- //Being inventory/equiped items
- //Inventory inventory;
- //Equipment equipment;
+ /**
+ * Set the statistics.
+ *
+ * @param stats the statistics.
+ */
+ void
+ setStatistics(const Statistics& stats);
-#ifdef SCRIPT_SUPPORT
- Script *script;
-#endif
- // disable default constructor (we don't want uninitialized Being's)
+ /**
+ * Get the statistics.
+ *
+ * @return the statistics.
+ */
+ Statistics&
+ getStatistics(void);
- public:
- Being() { };
- Being(const std::string &bName, unsigned int bGender,
- unsigned int bLevel, unsigned int bMoney,
- unsigned int bStrength, unsigned int bAgility,
- unsigned int bVitality, unsigned int bDexterity,
- unsigned int bLuck);
+ /**
+ * Update the internal status.
+ */
+ virtual void
+ update(void) = 0;
- virtual ~Being() { } //empty definition
- //update
- void update();
+ protected:
+ Statistics mStats; /**< stats modifiers or computed stats */
- //accessors
- const std::string& getName() { return name; }
- unsigned int getGender() { return gender; }
- unsigned int getLevel() { return level; }
- unsigned int getMoney() { return money; }
- //Get statistics information
- const Statistics& getStatistics() { return stats; }
+ private:
+ unsigned int mX; /**< x coordinate */
+ unsigned int mY; /**< y coordinate */
};
-typedef std::vector<Being*> Beings;
+} // namespace tmwserv
-#endif
+#endif // _TMWSERV_OBJECT_H_
diff --git a/src/storage.h b/src/storage.h
index 4c6310d6..6b8fdc44 100644
--- a/src/storage.h
+++ b/src/storage.h
@@ -27,7 +27,6 @@
#include <map>
-#include "object.h"
#include "account.h"
diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am
index c8f53d06..aaf3af82 100644
--- a/src/tests/Makefile.am
+++ b/src/tests/Makefile.am
@@ -28,6 +28,7 @@ tmwserv_test_LDADD = ../tmwserv-account.o \
../tmwserv-dataproviderfactory.o \
../tmwserv-logger.o \
../tmwserv-object.o \
+ ../tmwserv-being.o \
../tmwserv-recordset.o \
../tmwserv-storage.o
diff --git a/src/tests/testaccount.cpp b/src/tests/testaccount.cpp
index a086ef62..814aaa29 100644
--- a/src/tests/testaccount.cpp
+++ b/src/tests/testaccount.cpp
@@ -37,9 +37,18 @@ using namespace tmwserv;
void
AccountTest::setUp(void)
{
- Being* sam = new Being("sam", 1, 1, 1, 1, 1, 1, 1, 1);
- Being* merry = new Being("merry", 1, 1, 1, 1, 1, 1, 1, 1);
- Being* pippin = new Being("pippin", 1, 1, 1, 1, 1, 1, 1, 1);
+ //RawStatistics stats;
+ //stats.strength = 1;
+ //stats.agility = 1;
+ //stats.vitality = 1;
+ //stats.intelligence = 1;
+ //stats.dexterity = 1;
+ //stats.luck = 1;
+ const RawStatistics stats = {1, 1, 1, 1, 1, 1};
+
+ Being* sam = new Being("sam", GENDER_MALE, 0, 0, stats);
+ Being* merry = new Being("merry", GENDER_MALE, 0, 0, stats);
+ Being* pippin = new Being("pippin", GENDER_MALE, 0, 0, stats);
mCharacters.push_back(sam);
mCharacters.push_back(merry);
mCharacters.push_back(pippin);
@@ -124,7 +133,15 @@ AccountTest::testCreate2(void)
void
AccountTest::testAddCharacter1(void)
{
- Being* bilbo = new Being("bilbo", 1, 1, 1, 1, 1, 1, 1, 1);
+ RawStatistics stats;
+ stats.strength = 1;
+ stats.agility = 1;
+ stats.vitality = 1;
+ stats.intelligence = 1;
+ stats.dexterity = 1;
+ stats.luck = 1;
+
+ Being* bilbo = new Being("bilbo", GENDER_MALE, 0, 0, stats);
mAccount->addCharacter(bilbo);
diff --git a/src/tests/testaccount.h b/src/tests/testaccount.h
index fc2363c6..06a60bfc 100644
--- a/src/tests/testaccount.h
+++ b/src/tests/testaccount.h
@@ -109,7 +109,7 @@ class AccountTest: public CppUnit::TestFixture
private:
tmwserv::Account* mAccount; /**< the default account */
- Beings mCharacters; /**< a list of beings */
+ tmwserv::Beings mCharacters; /**< a list of beings */
};
diff --git a/src/tests/teststorage.cpp b/src/tests/teststorage.cpp
index 6836bc56..7a7cb7fd 100644
--- a/src/tests/teststorage.cpp
+++ b/src/tests/teststorage.cpp
@@ -37,6 +37,7 @@
#include <physfs.h>
#include "../utils/cipher.h"
+#include "../utils/functors.h"
#include "../dalstoragesql.h"
#include "../storage.h"
#include "teststorage.h"
@@ -218,10 +219,18 @@ StorageTest::testAddAccount2(void)
}
// prepare new account.
+ RawStatistics stats;
+ stats.strength = 1;
+ stats.agility = 1;
+ stats.vitality = 1;
+ stats.intelligence = 1;
+ stats.dexterity = 1;
+ stats.luck = 1;
+
const std::string sam1("sam1");
const std::string sam2("sam2");
- Being* b1 = new Being(sam1, 1, 1, 1, 1, 1, 1, 1, 1);
- Being* b2 = new Being(sam2, 1, 1, 1, 1, 1, 1, 1, 1);
+ Being* b1 = new Being(sam1, GENDER_MALE, 0, 0, stats);
+ Being* b2 = new Being(sam2, GENDER_MALE, 0, 0, stats);
Beings characters;
characters.push_back(b1);
characters.push_back(b2);
@@ -268,9 +277,7 @@ StorageTest::testAddAccount2(void)
sql = "select * from ";
sql += CHARACTERS_TBL_NAME;
- sql += " where user_id = '";
- sql += sam;
- sql += "';";
+ sql += " where user_id = 4;";
db->execSql(sql);
@@ -315,10 +322,18 @@ StorageTest::testUpdAccount1(void)
Account* account = myStorage.getAccount(name);
// create new characters.
+ RawStatistics stats;
+ stats.strength = 1;
+ stats.agility = 1;
+ stats.vitality = 1;
+ stats.intelligence = 1;
+ stats.dexterity = 1;
+ stats.luck = 1;
+
const std::string sam1("sam1");
const std::string sam2("sam2");
- Being* b1 = new Being(sam1, 1, 1, 1, 1, 1, 1, 1, 1);
- Being* b2 = new Being(sam2, 1, 1, 1, 1, 1, 1, 1, 1);
+ Being* b1 = new Being(sam1, GENDER_MALE, 0, 0, stats);
+ Being* b2 = new Being(sam2, GENDER_MALE, 0, 0, stats);
// add the characters to the account.
account->addCharacter(b1);
@@ -360,9 +375,7 @@ StorageTest::testUpdAccount1(void)
sql = "select * from ";
sql += CHARACTERS_TBL_NAME;
- sql += " where user_id = '";
- sql += frodo;
- sql += "';";
+ sql += " where user_id = 1;";
db->execSql(sql);
@@ -408,10 +421,18 @@ StorageTest::testUpdAccount2(void)
Account* account = myStorage.getAccount(name);
// create new characters.
+ RawStatistics stats;
+ stats.strength = 1;
+ stats.agility = 1;
+ stats.vitality = 1;
+ stats.intelligence = 1;
+ stats.dexterity = 1;
+ stats.luck = 1;
+
const std::string sam1("sam1");
const std::string sam2("sam2");
- Being* b1 = new Being(sam1, 1, 1, 1, 1, 1, 1, 1, 1);
- Being* b2 = new Being(sam2, 1, 1, 1, 1, 1, 1, 1, 1);
+ Being* b1 = new Being(sam1, GENDER_MALE, 0, 0, stats);
+ Being* b2 = new Being(sam2, GENDER_MALE, 0, 0, stats);
// add the characters to the account.
account->addCharacter(b1);
@@ -426,7 +447,7 @@ StorageTest::testUpdAccount2(void)
account->setPassword(newPassword);
// change the strength of the first character.
- // TODO: at the moment, there are no mutators defined for the Being class.
+ b1->setStrength(10);
// update the database.
myStorage.flush();
@@ -467,9 +488,7 @@ StorageTest::testUpdAccount2(void)
sql = "select * from ";
sql += CHARACTERS_TBL_NAME;
- sql += " where user_id = '";
- sql += frodo;
- sql += "';";
+ sql += " where user_id = 1;";
db->execSql(sql);
@@ -478,8 +497,8 @@ StorageTest::testUpdAccount2(void)
CPPUNIT_ASSERT_EQUAL(sam1, rs(0, "name"));
CPPUNIT_ASSERT_EQUAL(sam2, rs(1, "name"));
- // TODO: when the mutators are implemented for the Being class,
- // check the strength of the first character.
+ string_to<unsigned short> toUshort;
+ CPPUNIT_ASSERT_EQUAL((unsigned short) 10, toUshort(rs(0, "str")));
db->disconnect();
}