From a114390b372352383241816a29f9c35a368cd4f9 Mon Sep 17 00:00:00 2001 From: Erik Schilling Date: Sun, 3 Feb 2013 09:48:41 +0100 Subject: Random cleanup of attribute code Did this during trying to understand the code --- src/game-server/attribute.cpp | 11 ++++++----- src/game-server/attributemanager.cpp | 34 +++++++++++++++++++++------------- src/game-server/attributemanager.h | 2 +- 3 files changed, 28 insertions(+), 19 deletions(-) (limited to 'src') 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(); - mAttributeMap[id].minimum = XML::getFloatProperty(attributeNode, "minimum", - std::numeric_limits::min()); - mAttributeMap[id].maximum = XML::getFloatProperty(attributeNode, "maximum", - std::numeric_limits::max()); - mAttributeMap[id].modifiable = XML::getBoolProperty(attributeNode, "modifiable", - false); + AttributeInfo &attribute = mAttributeMap[id]; + + attribute.modifiers = std::vector(); + attribute.minimum = XML::getFloatProperty(attributeNode, "minimum", + std::numeric_limits::min()); + attribute.maximum = XML::getFloatProperty(attributeNode, "maximum", + std::numeric_limits::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::min()), maximum(std::numeric_limits::max()), modifiable(false) - {} + {} /** The minimum and maximum permitted attribute values. */ double minimum; -- cgit v1.2.3-70-g09d2