diff options
author | Erik Schilling <ablu.erikschilling@googlemail.com> | 2013-02-03 09:48:41 +0100 |
---|---|---|
committer | Erik Schilling <ablu.erikschilling@googlemail.com> | 2013-02-04 16:15:12 +0100 |
commit | a114390b372352383241816a29f9c35a368cd4f9 (patch) | |
tree | a99d25002b095ba1d125d97a53baee56be46037c | |
parent | 5ba4dbb62d8e5ef86dbd58803cd77268e13f48ce (diff) | |
download | manaserv-a114390b372352383241816a29f9c35a368cd4f9.tar.gz manaserv-a114390b372352383241816a29f9c35a368cd4f9.tar.bz2 manaserv-a114390b372352383241816a29f9c35a368cd4f9.tar.xz manaserv-a114390b372352383241816a29f9c35a368cd4f9.zip |
Random cleanup of attribute code
Did this during trying to understand the code
-rw-r--r-- | src/game-server/attribute.cpp | 11 | ||||
-rw-r--r-- | src/game-server/attributemanager.cpp | 34 | ||||
-rw-r--r-- | src/game-server/attributemanager.h | 2 |
3 files changed, 28 insertions, 19 deletions
diff --git a/src/game-server/attribute.cpp b/src/game-server/attribute.cpp index 3d0f5510..71e5d944 100644 --- a/src/game-server/attribute.cpp +++ b/src/game-server/attribute.cpp @@ -249,16 +249,17 @@ bool AttributeModifiersEffect::recalculateModifiedValue(double newPrevLayerValue bool Attribute::add(unsigned short duration, double value, - unsigned layer, int level) + unsigned layer, int id) { assert(mMods.size() > layer); - LOG_DEBUG("Adding modifier to attribute with duration " << duration << - ", value " << value << ", at layer " << layer << " with id " - << level); + LOG_DEBUG("Adding modifier to attribute with duration " << duration + << ", value " << value + << ", at layer " << layer + << " with id " << id); if (mMods.at(layer)->add(duration, value, (layer ? mMods.at(layer - 1)->getCachedModifiedValue() : mBase) - , level)) + , id)) { while (++layer < mMods.size()) { diff --git a/src/game-server/attributemanager.cpp b/src/game-server/attributemanager.cpp index 018de28e..42c2624d 100644 --- a/src/game-server/attributemanager.cpp +++ b/src/game-server/attributemanager.cpp @@ -144,13 +144,15 @@ void AttributeManager::readAttributeNode(xmlNodePtr attributeNode) return; } - mAttributeMap[id].modifiers = std::vector<AttributeModifier>(); - mAttributeMap[id].minimum = XML::getFloatProperty(attributeNode, "minimum", - std::numeric_limits<double>::min()); - mAttributeMap[id].maximum = XML::getFloatProperty(attributeNode, "maximum", - std::numeric_limits<double>::max()); - mAttributeMap[id].modifiable = XML::getBoolProperty(attributeNode, "modifiable", - false); + AttributeInfo &attribute = mAttributeMap[id]; + + attribute.modifiers = std::vector<AttributeModifier>(); + attribute.minimum = XML::getFloatProperty(attributeNode, "minimum", + std::numeric_limits<double>::min()); + attribute.maximum = XML::getFloatProperty(attributeNode, "maximum", + std::numeric_limits<double>::max()); + attribute.modifiable = XML::getBoolProperty(attributeNode, "modifiable", + false); for_each_xml_child_node(subNode, attributeNode) { @@ -171,22 +173,19 @@ void AttributeManager::readAttributeNode(xmlNodePtr attributeNode) } else if (scope == "CHARACTER") { - mAttributeScopes[CharacterScope][id] = - &mAttributeMap.at(id); + mAttributeScopes[CharacterScope][id] = &attribute; LOG_DEBUG("Attribute manager: attribute '" << id << "' added to default character scope."); } else if (scope == "MONSTER") { - mAttributeScopes[MonsterScope][id] = - &mAttributeMap.at(id); + mAttributeScopes[MonsterScope][id] = &attribute; LOG_DEBUG("Attribute manager: attribute '" << id << "' added to default monster scope."); } else if (scope == "BEING") { - mAttributeScopes[BeingScope][id] = - &mAttributeMap.at(id); + mAttributeScopes[BeingScope][id] = &attribute; LOG_DEBUG("Attribute manager: attribute '" << id << "' added to default being scope."); } @@ -250,6 +249,15 @@ void AttributeManager::readModifierNode(xmlNodePtr modifierNode, return; } + if (stackableType == NonStackable && effectType == Multiplicative) + { + LOG_WARN("Attribute manager: attribute '" << attributeId + << "' has a non sense modifier. " + << "Having NonStackable and Multiplicative makes no sense! " + << "Skipping modifier!"); + return; + } + mAttributeMap[attributeId].modifiers.push_back( AttributeModifier(stackableType, effectType)); diff --git a/src/game-server/attributemanager.h b/src/game-server/attributemanager.h index 63ebf643..1a55006c 100644 --- a/src/game-server/attributemanager.h +++ b/src/game-server/attributemanager.h @@ -94,7 +94,7 @@ class AttributeManager minimum(std::numeric_limits<double>::min()), maximum(std::numeric_limits<double>::max()), modifiable(false) - {} + {} /** The minimum and maximum permitted attribute values. */ double minimum; |