summaryrefslogtreecommitdiff
path: root/src/being
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2015-05-29 21:42:33 +0300
committerAndrei Karas <akaras@inbox.ru>2015-05-29 22:43:38 +0300
commit3411edb5d3ae07d247421e4b8f7936a22b7b4027 (patch)
tree63685d0979938a42a62b3f0a880663bb06f4e8ca /src/being
parent390e5da0f9ecc4407aa7d4bcba1af5730db56271 (diff)
downloadmanaverse-3411edb5d3ae07d247421e4b8f7936a22b7b4027.tar.gz
manaverse-3411edb5d3ae07d247421e4b8f7936a22b7b4027.tar.bz2
manaverse-3411edb5d3ae07d247421e4b8f7936a22b7b4027.tar.xz
manaverse-3411edb5d3ae07d247421e4b8f7936a22b7b4027.zip
Convert Attributes enum into strong typed enum.
Diffstat (limited to 'src/being')
-rw-r--r--src/being/localplayer.cpp4
-rw-r--r--src/being/localplayer.h4
-rw-r--r--src/being/playerinfo.cpp29
-rw-r--r--src/being/playerinfo.h37
4 files changed, 42 insertions, 32 deletions
diff --git a/src/being/localplayer.cpp b/src/being/localplayer.cpp
index 58b25630e..1374eefab 100644
--- a/src/being/localplayer.cpp
+++ b/src/being/localplayer.cpp
@@ -1117,7 +1117,7 @@ void LocalPlayer::addSpMessage(const int change)
}
}
-void LocalPlayer::statChanged(const int id,
+void LocalPlayer::statChanged(const AttributesT id,
const int oldVal1,
const int oldVal2)
{
@@ -1136,7 +1136,7 @@ void LocalPlayer::statChanged(const int id,
addJobMessage(change);
}
-void LocalPlayer::attributeChanged(const int id,
+void LocalPlayer::attributeChanged(const AttributesT id,
const int oldVal,
const int newVal)
{
diff --git a/src/being/localplayer.h b/src/being/localplayer.h
index 093b188c4..84089984e 100644
--- a/src/being/localplayer.h
+++ b/src/being/localplayer.h
@@ -392,11 +392,11 @@ class LocalPlayer final : public Being,
int getLastAttackY() const override final
{ return mTarget ? mTarget->getTileY() : mLastAttackY; }
- void attributeChanged(const int id,
+ void attributeChanged(const AttributesT id,
const int oldVal,
const int newVal) override final;
- void statChanged(const int id,
+ void statChanged(const AttributesT id,
const int oldVal1,
const int oldVal2) override final;
diff --git a/src/being/playerinfo.cpp b/src/being/playerinfo.cpp
index f11b6fe82..c86200219 100644
--- a/src/being/playerinfo.cpp
+++ b/src/being/playerinfo.cpp
@@ -33,8 +33,6 @@
#include "being/petinfo.h"
#endif
-#include "enums/being/attributes.h"
-
#include "gui/windows/inventorywindow.h"
#include "gui/windows/npcdialog.h"
@@ -72,29 +70,32 @@ std::set<int> mProtectedItems;
// --- Triggers ---------------------------------------------------------------
-void triggerAttr(const int id, const int old)
+void triggerAttr(const AttributesT id,
+ const int old)
{
AttributeListener::distributeEvent(id, old,
mData.mAttributes.find(id)->second);
}
-void triggerStat(const int id, const int old1, const int old2)
+void triggerStat(const AttributesT id,
+ const int old1,
+ const int old2)
{
StatListener::distributeEvent(id, old1, old2);
}
// --- Attributes -------------------------------------------------------------
-int getAttribute(const int id)
+int getAttribute(const AttributesT id)
{
- const IntMap::const_iterator it = mData.mAttributes.find(id);
+ const AtrIntMap::const_iterator it = mData.mAttributes.find(id);
if (it != mData.mAttributes.end())
return it->second;
else
return 0;
}
-void setAttribute(const int id,
+void setAttribute(const AttributesT id,
const int value,
const Notify notify)
{
@@ -120,7 +121,7 @@ void setSkillLevel(const int id, const int value)
// --- Stats ------------------------------------------------------------------
-int getStatBase(const int id)
+int getStatBase(const AttributesT id)
{
const StatMap::const_iterator it = mData.mStats.find(id);
if (it != mData.mStats.end())
@@ -129,7 +130,7 @@ int getStatBase(const int id)
return 0;
}
-void setStatBase(const int id, const int value, const Notify notify)
+void setStatBase(const AttributesT id, const int value, const Notify notify)
{
const int old = mData.mStats[id].base;
mData.mStats[id].base = value;
@@ -137,7 +138,7 @@ void setStatBase(const int id, const int value, const Notify notify)
triggerStat(id, old, 0);
}
-int getStatMod(const int id)
+int getStatMod(const AttributesT id)
{
const StatMap::const_iterator it = mData.mStats.find(id);
if (it != mData.mStats.end())
@@ -146,7 +147,7 @@ int getStatMod(const int id)
return 0;
}
-void setStatMod(const int id, const int value, const Notify notify)
+void setStatMod(const AttributesT id, const int value, const Notify notify)
{
const int old = mData.mStats[id].mod;
mData.mStats[id].mod = value;
@@ -154,7 +155,7 @@ void setStatMod(const int id, const int value, const Notify notify)
triggerStat(id, old, 0);
}
-int getStatEffective(const int id)
+int getStatEffective(const AttributesT id)
{
const StatMap::const_iterator it = mData.mStats.find(id);
if (it != mData.mStats.end())
@@ -163,7 +164,7 @@ int getStatEffective(const int id)
return 0;
}
-const std::pair<int, int> getStatExperience(const int id)
+const std::pair<int, int> getStatExperience(const AttributesT id)
{
const StatMap::const_iterator it = mData.mStats.find(id);
int a, b;
@@ -180,7 +181,7 @@ const std::pair<int, int> getStatExperience(const int id)
return std::pair<int, int>(a, b);
}
-void setStatExperience(const int id,
+void setStatExperience(const AttributesT id,
const int have,
const int need,
const Notify notify)
diff --git a/src/being/playerinfo.h b/src/being/playerinfo.h
index ee963a5eb..d16bd6474 100644
--- a/src/being/playerinfo.h
+++ b/src/being/playerinfo.h
@@ -27,6 +27,8 @@
#include "enums/guildpositionflags.h"
#include "enums/state.h"
+#include "enums/being/attributes.h"
+
#include "enums/simpletypes/beingid.h"
#include "enums/simpletypes/keep.h"
#include "enums/simpletypes/notify.h"
@@ -50,7 +52,8 @@ struct Stat final
};
typedef std::map<int, int> IntMap;
-typedef std::map<int, Stat> StatMap;
+typedef std::map<Attributes, int> AtrIntMap;
+typedef std::map<Attributes, Stat> StatMap;
/**
* Backend for core player information.
@@ -64,7 +67,7 @@ struct PlayerInfoBackend final
{
}
- IntMap mAttributes;
+ AtrIntMap mAttributes;
StatMap mStats;
IntMap mSkills;
};
@@ -89,12 +92,12 @@ namespace PlayerInfo
/**
* Returns the value of the given attribute.
*/
- int getAttribute(const int id) A_WARN_UNUSED;
+ int getAttribute(const AttributesT id) A_WARN_UNUSED;
/**
* Changes the value of the given attribute.
*/
- void setAttribute(const int id, const int value,
+ void setAttribute(const AttributesT id, const int value,
const Notify notify = Notify_true);
int getSkillLevel(const int id) A_WARN_UNUSED;
@@ -106,45 +109,48 @@ namespace PlayerInfo
/**
* Returns the base value of the given stat.
*/
- int getStatBase(const int id) A_WARN_UNUSED;
+ int getStatBase(const AttributesT id) A_WARN_UNUSED;
/**
* Changes the base value of the given stat.
*/
- void setStatBase(const int id, const int value,
+ void setStatBase(const AttributesT id,
+ const int value,
const Notify notify = Notify_true);
/**
* Returns the modifier for the given stat.
*/
- int getStatMod(const int id) A_WARN_UNUSED;
+ int getStatMod(const AttributesT id) A_WARN_UNUSED;
/**
* Changes the modifier for the given stat.
*/
- void setStatMod(const int id, const int value,
+ void setStatMod(const AttributesT id,
+ const int value,
const Notify notify = Notify_true);
/**
* Returns the current effective value of the given stat. Effective is base
* + mod
*/
- int getStatEffective(const int id) A_WARN_UNUSED;
+ int getStatEffective(const AttributesT id) A_WARN_UNUSED;
/**
* Changes the level of the given stat.
*/
- void setStatLevel(int id, int value, Notify notify = Notify_true);
+ void setStatLevel(AttributesT id, int value, Notify notify = Notify_true);
/**
* Returns the experience of the given stat.
*/
- const std::pair<int, int> getStatExperience(const int id) A_WARN_UNUSED;
+ const std::pair<int, int> getStatExperience(const AttributesT id)
+ A_WARN_UNUSED;
/**
* Changes the experience of the given stat.
*/
- void setStatExperience(const int id,
+ void setStatExperience(const AttributesT id,
const int have,
const int need,
const Notify notify = Notify_true);
@@ -223,9 +229,12 @@ namespace PlayerInfo
void stateChange(const State state);
- void triggerAttr(const int id, const int old);
+ void triggerAttr(const AttributesT id,
+ const int old);
- void triggerStat(const int id, const int old1, const int old2);
+ void triggerStat(const AttributesT id,
+ const int old1,
+ const int old2);
void setEquipmentBackend(Equipment::Backend *const backend);