summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHuynh Tran <nthuynh75@gmail.com>2005-06-29 10:28:36 +0000
committerHuynh Tran <nthuynh75@gmail.com>2005-06-29 10:28:36 +0000
commita5aee1322f498537f8de83123099bbfcb2e3a969 (patch)
tree979fa915c3fe5af122bb566fcca4850c63a9f311 /src
parent666447da2b65d55bc60ded978dfa92b40f9e3c24 (diff)
downloadmanaserv-a5aee1322f498537f8de83123099bbfcb2e3a969.tar.gz
manaserv-a5aee1322f498537f8de83123099bbfcb2e3a969.tar.bz2
manaserv-a5aee1322f498537f8de83123099bbfcb2e3a969.tar.xz
manaserv-a5aee1322f498537f8de83123099bbfcb2e3a969.zip
Fixed memory leak and set conditional stats updates.
Diffstat (limited to 'src')
-rw-r--r--src/account.cpp21
-rw-r--r--src/being.cpp9
-rw-r--r--src/dalstorage.cpp9
-rw-r--r--src/object.cpp7
-rw-r--r--src/object.h5
5 files changed, 34 insertions, 17 deletions
diff --git a/src/account.cpp b/src/account.cpp
index ed2c358e..97b723a0 100644
--- a/src/account.cpp
+++ b/src/account.cpp
@@ -70,18 +70,15 @@ Account::Account(const std::string& name,
Account::~Account(void)
throw()
{
- // we do not delete the Beings here because Storage keeps
- // a list of Beings as well and the destructor of Storage
- // takes care about it.
-
- /*
- *for (Beings::iterator it = mCharacters.begin();
- * it != mCharacters.end();
- * ++it)
- *{
- * delete (*it);
- *}
- */
+ for (Beings::iterator it = mCharacters.begin();
+ it != mCharacters.end();
+ ++it)
+ {
+ if (*it != 0) {
+ delete (*it);
+ *it = 0;
+ }
+ }
}
diff --git a/src/being.cpp b/src/being.cpp
index e6be76b3..d3df77f5 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -123,6 +123,7 @@ void
Being::setStrength(const unsigned short strength)
{
mRawStats.strength = strength;
+ mNeedUpdate = true;
}
@@ -143,6 +144,7 @@ void
Being::setAgility(const unsigned short agility)
{
mRawStats.agility = agility;
+ mNeedUpdate = true;
}
@@ -163,6 +165,7 @@ void
Being::setVitality(const unsigned short vitality)
{
mRawStats.vitality = vitality;
+ mNeedUpdate = true;
}
@@ -183,6 +186,7 @@ void
Being::setIntelligence(const unsigned short intelligence)
{
mRawStats.intelligence = intelligence;
+ mNeedUpdate = true;
}
@@ -205,6 +209,7 @@ void
Being::setDexterity(const unsigned short dexterity)
{
mRawStats.dexterity = dexterity;
+ mNeedUpdate = true;
}
@@ -225,6 +230,7 @@ void
Being::setLuck(const unsigned short luck)
{
mRawStats.luck = luck;
+ mNeedUpdate = true;
}
@@ -245,6 +251,7 @@ void
Being::setRawStatistics(const RawStatistics& stats)
{
mRawStats = stats;
+ mNeedUpdate = true;
}
@@ -271,6 +278,8 @@ Being::update(void)
mStats.magic = 10 + mRawStats.intelligence;
mStats.accuracy = 50 + mRawStats.dexterity;
mStats.speed = mRawStats.dexterity;
+
+ mNeedUpdate = false;
}
diff --git a/src/dalstorage.cpp b/src/dalstorage.cpp
index 7821e515..1970ed75 100644
--- a/src/dalstorage.cpp
+++ b/src/dalstorage.cpp
@@ -62,7 +62,9 @@ DALStorage::~DALStorage()
it != mAccounts.end();
++it)
{
- delete it->first;
+ if (it->first != 0) {
+ delete it->first;
+ }
}
// clean up characters.
@@ -70,7 +72,10 @@ DALStorage::~DALStorage()
it != mCharacters.end();
++it)
{
- delete (*it);
+ if (*it != 0) {
+ delete (*it);
+ *it = 0;
+ }
}
}
diff --git a/src/object.cpp b/src/object.cpp
index e8dd18ca..2418f086 100644
--- a/src/object.cpp
+++ b/src/object.cpp
@@ -33,7 +33,8 @@ namespace tmwserv
*/
Object::Object(void)
: mX(0),
- mY(0)
+ mY(0),
+ mNeedUpdate(false)
{
mStats.health = 0;
mStats.attack = 0;
@@ -110,6 +111,10 @@ Object::setStatistics(const Statistics& stats)
Statistics&
Object::getStatistics(void)
{
+ if (mNeedUpdate) {
+ update();
+ }
+
return mStats;
}
diff --git a/src/object.h b/src/object.h
index a696ea51..efd7a275 100644
--- a/src/object.h
+++ b/src/object.h
@@ -133,11 +133,12 @@ class Object
protected:
Statistics mStats; /**< stats modifiers or computed stats */
+ bool mNeedUpdate; /**< update() must be invoked if true */
private:
- unsigned int mX; /**< x coordinate */
- unsigned int mY; /**< y coordinate */
+ unsigned int mX; /**< x coordinate */
+ unsigned int mY; /**< y coordinate */
};