summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2011-03-19 13:53:03 +0100
committerThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2011-03-20 15:09:43 +0100
commit318cb3a18ac4aa906b18ffd170bf0b1033c62d33 (patch)
tree066e8bdde6e930ce7d8a267dbc2e5774a235863d /src
parent6c4f42e1b11a0713fa59fcf85e45a24eee5da0f0 (diff)
downloadmanaserv-318cb3a18ac4aa906b18ffd170bf0b1033c62d33.tar.gz
manaserv-318cb3a18ac4aa906b18ffd170bf0b1033c62d33.tar.bz2
manaserv-318cb3a18ac4aa906b18ffd170bf0b1033c62d33.tar.xz
manaserv-318cb3a18ac4aa906b18ffd170bf0b1033c62d33.zip
Introduced ModifierLocation struct
Easier to understand than a std::pair<unsigned int, unsigned int>, or functions like getTagFromInfo(unsigned int, unsigned int), which does not make clear what that "info" actually is. Now it's simply getTag(const ModifierLocation &location), documenting itself and also allowing the name to be shorter. Reviewed-by: Freeyorp
Diffstat (limited to 'src')
-rw-r--r--src/game-server/attributemanager.cpp22
-rw-r--r--src/game-server/attributemanager.h38
-rw-r--r--src/game-server/itemmanager.cpp6
3 files changed, 41 insertions, 25 deletions
diff --git a/src/game-server/attributemanager.cpp b/src/game-server/attributemanager.cpp
index c51054c1..6cbdae9f 100644
--- a/src/game-server/attributemanager.cpp
+++ b/src/game-server/attributemanager.cpp
@@ -54,7 +54,7 @@ void AttributeManager::reload()
j != i->second.second.end();
++j)
{
- tag = getTagFromInfo(i->first, lCount);
+ tag = getTag(ModifierLocation(i->first, lCount));
std::string end = tag ? "tag of '" + (*tag) + "'." : "no tag.";
LOG_DEBUG(" stackableType: " << j->stackableType
<< ", effectType: " << j->effectType << ", and " << end);
@@ -68,14 +68,14 @@ void AttributeManager::reload()
for (TagMap::const_iterator i = mTagMap.begin(), i_end = mTagMap.end();
i != i_end; ++i)
{
- LOG_DEBUG("Tag '" << i->first << "': '" << i->second.first << "', '"
- << i->second.second << "'.");
+ LOG_DEBUG("Tag '" << i->first << "': '" << i->second.attributeId
+ << "', '" << i->second.layer << "'.");
}
LOG_INFO("Loaded '" << mTagMap.size() << "' modifier tags.");
}
-const std::vector<struct AttributeInfoType> *AttributeManager::getAttributeInfo(unsigned int id) const
+const std::vector<struct AttributeInfoType> *AttributeManager::getAttributeInfo(int id) const
{
AttributeMap::const_iterator ret = mAttributeMap.find(id);
if (ret == mAttributeMap.end())
@@ -88,7 +88,7 @@ const AttributeScope &AttributeManager::getAttributeScope(ScopeType type) const
return mAttributeScopes[type];
}
-bool AttributeManager::isAttributeDirectlyModifiable(unsigned int id) const
+bool AttributeManager::isAttributeDirectlyModifiable(int id) const
{
AttributeMap::const_iterator ret = mAttributeMap.find(id);
if (ret == mAttributeMap.end())
@@ -96,18 +96,16 @@ bool AttributeManager::isAttributeDirectlyModifiable(unsigned int id) const
return ret->second.first;
}
-// { attribute id, layer }
-std::pair<unsigned int,unsigned int> AttributeManager::getInfoFromTag(const std::string &tag) const
+ModifierLocation AttributeManager::getLocation(const std::string &tag) const
{
return mTagMap.at(tag);
}
-const std::string *AttributeManager::getTagFromInfo(unsigned int attribute,
- unsigned int layer) const
+const std::string *AttributeManager::getTag(const ModifierLocation &location) const
{
for (TagMap::const_iterator it = mTagMap.begin(),
it_end = mTagMap.end(); it != it_end; ++it)
- if (it->second.first == attribute && it->second.second == layer)
+ if (it->second == location)
return &it->first;
return 0;
}
@@ -255,7 +253,7 @@ void AttributeManager::readModifierNode(xmlNodePtr modifierNode,
if (!tag.empty())
{
const int layer = mAttributeMap[attributeId].second.size() - 1;
- mTagMap.insert(std::make_pair(tag, std::make_pair(attributeId,
- layer)));
+ mTagMap.insert(std::make_pair(tag, ModifierLocation(attributeId,
+ layer)));
}
}
diff --git a/src/game-server/attributemanager.h b/src/game-server/attributemanager.h
index a26fd6a4..c4843c3a 100644
--- a/src/game-server/attributemanager.h
+++ b/src/game-server/attributemanager.h
@@ -36,7 +36,25 @@ enum ScopeType
MaxScope
};
-typedef std::map< int, std::vector<struct AttributeInfoType> * > AttributeScope;
+typedef std::map<int, std::vector<struct AttributeInfoType> *> AttributeScope;
+
+/**
+ * Identifies a modifier by the attribute id that it applies to and its layer
+ * index in the stack of modifiers for that attribute.
+ */
+struct ModifierLocation
+{
+ int attributeId;
+ int layer;
+
+ ModifierLocation(int attributeId, int layer)
+ : attributeId(attributeId)
+ , layer(layer)
+ {}
+
+ bool operator==(const ModifierLocation &other) const
+ { return attributeId == other.attributeId && layer == other.layer; }
+};
class AttributeManager
{
@@ -55,15 +73,15 @@ class AttributeManager
*/
void reload();
- const std::vector<struct AttributeInfoType> *getAttributeInfo(unsigned int) const;
+ const std::vector<struct AttributeInfoType> *getAttributeInfo(int id) const;
const AttributeScope &getAttributeScope(ScopeType) const;
- bool isAttributeDirectlyModifiable(unsigned int) const;
+ bool isAttributeDirectlyModifiable(int id) const;
- std::pair<unsigned int,unsigned int> getInfoFromTag(const std::string &) const;
+ ModifierLocation getLocation(const std::string &tag) const;
- const std::string *getTagFromInfo(unsigned int, unsigned int) const;
+ const std::string *getTag(const ModifierLocation &location) const;
private:
void readAttributesFile();
@@ -71,14 +89,14 @@ class AttributeManager
void readModifierNode(xmlNodePtr modifierNode, int attributeId);
// modifiable, { stackable type, effect type }[]
- typedef std::pair< bool,
+ typedef std::pair<bool,
std::vector<struct AttributeInfoType> > AttributeInfoMap;
// Attribute id -> { modifiable, { stackable type, effect type }[] }
- typedef std::map< int, AttributeInfoMap > AttributeMap;
- // tag name -> { attribute id, layer }
- typedef std::map< std::string,
- std::pair<unsigned int, unsigned int> > TagMap;
+ typedef std::map<int, AttributeInfoMap> AttributeMap;
+
+ /** Maps tag names to specific modifiers. */
+ typedef std::map<std::string, ModifierLocation> TagMap;
// being type id -> (*{ stackable type, effect type })[]
AttributeScope mAttributeScopes[MaxScope];
diff --git a/src/game-server/itemmanager.cpp b/src/game-server/itemmanager.cpp
index ecf9555a..3e7c673a 100644
--- a/src/game-server/itemmanager.cpp
+++ b/src/game-server/itemmanager.cpp
@@ -269,10 +269,10 @@ void ItemManager::reload()
unsigned int duration = XML::getProperty(effectnode,
"duration",
0);
- std::pair<unsigned int, unsigned int> info = attributeManager->getInfoFromTag(tag);
+ ModifierLocation location = attributeManager->getLocation(tag);
double value = XML::getFloatProperty(effectnode, "value", 0.0);
- item->addEffect(new ItemEffectAttrMod(info.first,
- info.second,
+ item->addEffect(new ItemEffectAttrMod(location.attributeId,
+ location.layer,
value, id,
duration),
triggerTypes.first, triggerTypes.second);