summaryrefslogtreecommitdiff
path: root/src/game-server/attributemanager.h
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/game-server/attributemanager.h
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/game-server/attributemanager.h')
-rw-r--r--src/game-server/attributemanager.h38
1 files changed, 28 insertions, 10 deletions
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];