summaryrefslogtreecommitdiff
path: root/src/game-server
diff options
context:
space:
mode:
authorErik Schilling <ablu.erikschilling@googlemail.com>2013-05-19 11:40:50 +0200
committerErik Schilling <ablu.erikschilling@googlemail.com>2013-08-26 22:56:47 +0200
commit4d46079cd147e05513473860cb2e92fec0c31b8f (patch)
tree0f115a91debb6be766a174e8042ff800aff3a0ec /src/game-server
parent6d14024f3df86c05e94f2b4161faf8f5d97c2c0f (diff)
downloadmanaserv-4d46079cd147e05513473860cb2e92fec0c31b8f.tar.gz
manaserv-4d46079cd147e05513473860cb2e92fec0c31b8f.tar.bz2
manaserv-4d46079cd147e05513473860cb2e92fec0c31b8f.tar.xz
manaserv-4d46079cd147e05513473860cb2e92fec0c31b8f.zip
Allow names instead of ids for attributes + cleanup
I did not adapt the scripts yet since we need some special handling for the attributes which are required by the server directly. So you still have to use the ids for those. I will change that later. In the future I want to use the AttributeInfo class instead of the int id everywhere possible. So I did a small start on that too.
Diffstat (limited to 'src/game-server')
-rw-r--r--src/game-server/attribute.cpp8
-rw-r--r--src/game-server/attribute.h2
-rw-r--r--src/game-server/attributemanager.cpp126
-rw-r--r--src/game-server/attributemanager.h29
-rw-r--r--src/game-server/being.cpp37
-rw-r--r--src/game-server/being.h4
-rw-r--r--src/game-server/character.cpp14
-rw-r--r--src/game-server/character.h4
-rw-r--r--src/game-server/monster.cpp5
-rw-r--r--src/game-server/monster.h34
-rw-r--r--src/game-server/monstermanager.cpp96
11 files changed, 177 insertions, 182 deletions
diff --git a/src/game-server/attribute.cpp b/src/game-server/attribute.cpp
index f898b6e8..693c78dc 100644
--- a/src/game-server/attribute.cpp
+++ b/src/game-server/attribute.cpp
@@ -314,12 +314,12 @@ bool AttributeModifiersEffect::tick()
return ret;
}
-Attribute::Attribute(const AttributeManager::AttributeInfo &info):
+Attribute::Attribute(const AttributeManager::AttributeInfo *info):
mBase(0),
- mMinValue(info.minimum),
- mMaxValue(info.maximum)
+ mMinValue(info->minimum),
+ mMaxValue(info->maximum)
{
- const std::vector<AttributeModifier> &modifiers = info.modifiers;
+ const std::vector<AttributeModifier> &modifiers = info->modifiers;
LOG_DEBUG("Construction of new attribute with '" << modifiers.size()
<< "' layers.");
for (unsigned i = 0; i < modifiers.size(); ++i)
diff --git a/src/game-server/attribute.h b/src/game-server/attribute.h
index 2ac1378c..8ad357f7 100644
--- a/src/game-server/attribute.h
+++ b/src/game-server/attribute.h
@@ -138,7 +138,7 @@ class Attribute
, mMaxValue(0)
{throw;} // DEBUG; Find improper constructions
- Attribute(const AttributeManager::AttributeInfo &info);
+ Attribute(const AttributeManager::AttributeInfo *info);
~Attribute();
diff --git a/src/game-server/attributemanager.cpp b/src/game-server/attributemanager.cpp
index 4c551c5a..4c17d6a0 100644
--- a/src/game-server/attributemanager.cpp
+++ b/src/game-server/attributemanager.cpp
@@ -26,36 +26,56 @@
void AttributeManager::initialize()
{
- reload();
}
void AttributeManager::reload()
{
+ deinitialize();
+ initialize();
+}
+
+void AttributeManager::deinitialize()
+{
mTagMap.clear();
+
+ mAttributeNameMap.clear();
+ for (auto &it : mAttributeMap)
+ delete it.second;
mAttributeMap.clear();
+
for (unsigned i = 0; i < MaxScope; ++i)
mAttributeScopes[i].clear();
}
-const std::vector<AttributeModifier> *AttributeManager::getAttributeInfo(int id) const
+const AttributeManager::AttributeInfo *AttributeManager::getAttributeInfo(
+ int id) const
{
- AttributeMap::const_iterator ret = mAttributeMap.find(id);
+ auto ret = mAttributeMap.find(id);
if (ret == mAttributeMap.end())
return 0;
- return &ret->second.modifiers;
+ return ret->second;
}
-const AttributeManager::AttributeScope &AttributeManager::getAttributeScope(ScopeType type) const
+const AttributeManager::AttributeInfo *AttributeManager::getAttributeInfo(
+ const std::string &name) const
+{
+ if (mAttributeNameMap.contains(name))
+ return mAttributeNameMap.value(name);
+ return 0;
+}
+
+const std::map<int, AttributeManager::AttributeInfo *>
+&AttributeManager::getAttributeScope(ScopeType type) const
{
return mAttributeScopes[type];
}
bool AttributeManager::isAttributeDirectlyModifiable(int id) const
{
- AttributeMap::const_iterator ret = mAttributeMap.find(id);
+ auto ret = mAttributeMap.find(id);
if (ret == mAttributeMap.end())
return false;
- return ret->second.modifiable;
+ return ret->second->modifiable;
}
ModifierLocation AttributeManager::getLocation(const std::string &tag) const
@@ -68,10 +88,11 @@ ModifierLocation AttributeManager::getLocation(const std::string &tag) 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 == location)
- return &it->first;
+ for (auto &it : mTagMap)
+ {
+ if (it.second == location)
+ return &it.first;
+ }
return 0;
}
@@ -90,56 +111,65 @@ void AttributeManager::readAttributeNode(xmlNodePtr attributeNode)
return;
}
- AttributeInfo &attribute = mAttributeMap[id];
+ AttributeInfo *attribute = new AttributeInfo;
- attribute.modifiers = std::vector<AttributeModifier>();
- attribute.minimum = XML::getFloatProperty(attributeNode, "minimum",
+ attribute->id = id;
+ attribute->modifiers = std::vector<AttributeModifier>();
+ attribute->minimum = XML::getFloatProperty(attributeNode, "minimum",
std::numeric_limits<double>::min());
- attribute.maximum = XML::getFloatProperty(attributeNode, "maximum",
+ attribute->maximum = XML::getFloatProperty(attributeNode, "maximum",
std::numeric_limits<double>::max());
- attribute.modifiable = XML::getBoolProperty(attributeNode, "modifiable",
- false);
+ attribute->modifiable = XML::getBoolProperty(attributeNode, "modifiable",
+ false);
- for_each_xml_child_node(subNode, attributeNode)
+ std::string name = XML::getProperty(attributeNode, "name", std::string());
+ if (name.empty())
{
- if (xmlStrEqual(subNode->name, BAD_CAST "modifier"))
- {
- readModifierNode(subNode, id);
- }
+ LOG_WARN("Attribute manager: attribute '" << id
+ << "' does not have a name! Skipping...");
+ delete attribute;
+ return;
}
const std::string scope = utils::toUpper(
XML::getProperty(attributeNode, "scope", std::string()));
- if (scope.empty())
+ if (scope == "CHARACTER")
{
- // Give a warning unless scope has been explicitly set to "NONE"
- LOG_WARN("Attribute manager: attribute '" << id
- << "' has no default scope.");
- }
- else if (scope == "CHARACTER")
- {
- mAttributeScopes[CharacterScope][id] = &attribute;
+ mAttributeScopes[CharacterScope][id] = attribute;
LOG_DEBUG("Attribute manager: attribute '" << id
<< "' added to default character scope.");
}
else if (scope == "MONSTER")
{
- mAttributeScopes[MonsterScope][id] = &attribute;
+ mAttributeScopes[MonsterScope][id] = attribute;
LOG_DEBUG("Attribute manager: attribute '" << id
<< "' added to default monster scope.");
}
else if (scope == "BEING")
{
- mAttributeScopes[BeingScope][id] = &attribute;
+ mAttributeScopes[BeingScope][id] = attribute;
LOG_DEBUG("Attribute manager: attribute '" << id
<< "' added to default being scope.");
}
else
{
LOG_WARN("Attribute manager: attribute '" << id
- << "' has no scope.");
+ << "' has no (valid) scope. Skipping...");
+ delete attribute;
+ return;
+ }
+
+ for_each_xml_child_node(subNode, attributeNode)
+ {
+ if (xmlStrEqual(subNode->name, BAD_CAST "modifier"))
+ {
+ readModifierNode(subNode, id, attribute);
+ }
}
+
+ mAttributeMap[id] = attribute;
+ mAttributeNameMap[name] = attribute;
}
/**
@@ -153,19 +183,17 @@ void AttributeManager::checkStatus()
LOG_DEBUG("Additive is " << Additive << ", Multiplicative is " << Multiplicative << ".");
const std::string *tag;
unsigned count = 0;
- for (AttributeMap::const_iterator i = mAttributeMap.begin();
- i != mAttributeMap.end(); ++i)
+ for (auto &attributeIt : mAttributeMap)
{
unsigned lCount = 0;
- LOG_DEBUG(" "<<i->first<<" : ");
- for (std::vector<AttributeModifier>::const_iterator j =
- i->second.modifiers.begin();
- j != i->second.modifiers.end(); ++j)
+ LOG_DEBUG(" "<< attributeIt.first<<" : ");
+ for (auto &modifierIt : attributeIt.second->modifiers)
{
- tag = getTag(ModifierLocation(i->first, lCount));
+ tag = getTag(ModifierLocation(attributeIt.first, lCount));
std::string end = tag ? "tag of '" + (*tag) + "'." : "no tag.";
- LOG_DEBUG(" stackableType: " << j->stackableType
- << ", effectType: " << j->effectType << ", and " << end);
+ LOG_DEBUG(" stackableType: " << modifierIt.stackableType
+ << ", effectType: " << modifierIt.effectType << ", and "
+ << end);
++lCount;
++count;
}
@@ -173,18 +201,17 @@ void AttributeManager::checkStatus()
LOG_INFO("Loaded '" << mAttributeMap.size() << "' attributes with '"
<< count << "' modifier layers.");
- for (TagMap::const_iterator i = mTagMap.begin(), i_end = mTagMap.end();
- i != i_end; ++i)
+ for (auto &tagIt : mTagMap)
{
- LOG_DEBUG("Tag '" << i->first << "': '" << i->second.attributeId
- << "', '" << i->second.layer << "'.");
+ LOG_DEBUG("Tag '" << tagIt.first << "': '" << tagIt.second.attributeId
+ << "', '" << tagIt.second.layer << "'.");
}
LOG_INFO("Loaded '" << mTagMap.size() << "' modifier tags.");
}
void AttributeManager::readModifierNode(xmlNodePtr modifierNode,
- int attributeId)
+ int attributeId, AttributeInfo *info)
{
const std::string stackableTypeString = utils::toUpper(
XML::getProperty(modifierNode, "stacktype", std::string()));
@@ -245,13 +272,12 @@ void AttributeManager::readModifierNode(xmlNodePtr modifierNode,
return;
}
- mAttributeMap[attributeId].modifiers.push_back(
+ info->modifiers.push_back(
AttributeModifier(stackableType, effectType));
if (!tag.empty())
{
- const int layer =
- mAttributeMap[attributeId].modifiers.size() - 1;
+ const int layer = info->modifiers.size() - 1;
mTagMap.insert(std::make_pair(tag, ModifierLocation(attributeId,
layer)));
}
diff --git a/src/game-server/attributemanager.h b/src/game-server/attributemanager.h
index 9bc40e1f..2972cd77 100644
--- a/src/game-server/attributemanager.h
+++ b/src/game-server/attributemanager.h
@@ -26,6 +26,7 @@
#include <string>
#include <limits>
+#include "utils/string.h"
#include "utils/xml.h"
enum ScopeType
@@ -91,18 +92,21 @@ class AttributeManager
public:
struct AttributeInfo {
AttributeInfo():
+ id(0),
minimum(std::numeric_limits<double>::min()),
maximum(std::numeric_limits<double>::max()),
modifiable(false)
{}
+ int id;
+
/** The minimum and maximum permitted attribute values. */
double minimum;
double maximum;
/** Tells whether the base attribute is modifiable by the player */
bool modifiable;
/** Effect modifier type: stackability and modification type. */
- std::vector<struct AttributeModifier> modifiers;
+ std::vector<AttributeModifier> modifiers;
};
AttributeManager()
@@ -117,13 +121,12 @@ class AttributeManager
* Reloads attribute reference file.
*/
void reload();
+ void deinitialize();
- const std::vector<AttributeModifier> *getAttributeInfo(int id) const;
-
- // being type id -> (*{ stackable type, effect type })[]
- typedef std::map<int, AttributeInfo*> AttributeScope;
+ const AttributeInfo *getAttributeInfo(int id) const;
+ const AttributeInfo *getAttributeInfo(const std::string &name) const;
- const AttributeScope &getAttributeScope(ScopeType) const;
+ const std::map<int, AttributeInfo *> &getAttributeScope(ScopeType) const;
bool isAttributeDirectlyModifiable(int id) const;
@@ -136,17 +139,15 @@ class AttributeManager
void checkStatus();
private:
- void readModifierNode(xmlNodePtr modifierNode, int attributeId);
+ void readModifierNode(xmlNodePtr modifierNode, int attributeId,
+ AttributeInfo *info);
- // Attribute id -> { modifiable, min, max, { stackable type, effect type }[] }
- typedef std::map<int, AttributeInfo> AttributeMap;
+ std::map<int, AttributeInfo *> mAttributeScopes[MaxScope];
- /** Maps tag names to specific modifiers. */
- typedef std::map<std::string, ModifierLocation> TagMap;
+ std::map<int, AttributeInfo *> mAttributeMap;
+ utils::NameMap<AttributeInfo *> mAttributeNameMap;
- AttributeScope mAttributeScopes[MaxScope];
- AttributeMap mAttributeMap;
- TagMap mTagMap;
+ std::map<std::string, ModifierLocation> mTagMap;
};
extern AttributeManager *attributeManager;
diff --git a/src/game-server/being.cpp b/src/game-server/being.cpp
index 22ce30d4..b4feda9c 100644
--- a/src/game-server/being.cpp
+++ b/src/game-server/being.cpp
@@ -47,18 +47,21 @@ BeingComponent::BeingComponent(Entity &entity):
mDirection(DOWN),
mEmoteId(0)
{
- const AttributeManager::AttributeScope &attr = attributeManager->getAttributeScope(BeingScope);
- LOG_DEBUG("Being creation: initialisation of " << attr.size() << " attributes.");
- for (AttributeManager::AttributeScope::const_iterator it1 = attr.begin(),
- it1_end = attr.end();
- it1 != it1_end;
- ++it1)
+ auto &attributeScope = attributeManager->getAttributeScope(BeingScope);
+ LOG_DEBUG("Being creation: initialisation of " << attributeScope.size()
+ << " attributes.");
+ for (auto &attributeIt : attributeScope)
{
- if (mAttributes.count(it1->first))
- LOG_WARN("Redefinition of attribute '" << it1->first << "'!");
- LOG_DEBUG("Attempting to create attribute '" << it1->first << "'.");
- mAttributes.insert(std::make_pair(it1->first,
- Attribute(*it1->second)));
+ if (mAttributes.count(attributeIt.first))
+ {
+ LOG_WARN("Redefinition of attribute '"
+ << attributeIt.first << "'!");
+ }
+
+ LOG_DEBUG("Attempting to create attribute '"
+ << attributeIt.first << "'.");
+ mAttributes.insert(std::make_pair(attributeIt.first,
+ Attribute(attributeIt.second)));
}
clearDestination(entity);
@@ -341,8 +344,8 @@ void BeingComponent::setGender(BeingGender gender)
void BeingComponent::setAttribute(Entity &entity, unsigned id, double value)
{
- AttributeMap::iterator ret = mAttributes.find(id);
- if (ret == mAttributes.end())
+ auto attributeIt = mAttributes.find(id);
+ if (attributeIt == mAttributes.end())
{
/*
* The attribute does not yet exist, so we must attempt to create it.
@@ -354,16 +357,16 @@ void BeingComponent::setAttribute(Entity &entity, unsigned id, double value)
}
else
{
- ret->second.setBase(value);
+ attributeIt->second.setBase(value);
updateDerivedAttributes(entity, id);
}
}
-void BeingComponent::createAttribute(unsigned id, const AttributeManager::AttributeInfo
- &attributeInfo)
+void BeingComponent::createAttribute(unsigned id,
+ const AttributeManager::AttributeInfo *attributeInfo)
{
mAttributes.insert(std::pair<unsigned, Attribute>
- (id,Attribute(attributeInfo)));
+ (id, Attribute(attributeInfo)));
}
const Attribute *BeingComponent::getAttribute(unsigned id) const
diff --git a/src/game-server/being.h b/src/game-server/being.h
index aeb5697b..8e245a34 100644
--- a/src/game-server/being.h
+++ b/src/game-server/being.h
@@ -151,8 +151,8 @@ class BeingComponent : public Component
* @param id The id of the attribute
* @param attributeInfo The info that describes the attribute
*/
- void createAttribute(unsigned id, const AttributeManager::AttributeInfo
- &attributeInfo);
+ void createAttribute(unsigned id,
+ const AttributeManager::AttributeInfo *attributeInfo);
/**
* Gets an attribute or 0 if not existing.
diff --git a/src/game-server/character.cpp b/src/game-server/character.cpp
index 8831e501..a8d29625 100644
--- a/src/game-server/character.cpp
+++ b/src/game-server/character.cpp
@@ -89,13 +89,11 @@ CharacterComponent::CharacterComponent(Entity &entity, MessageIn &msg):
{
auto *beingComponent = entity.getComponent<BeingComponent>();
- const AttributeManager::AttributeScope &attributes =
- attributeManager->getAttributeScope(CharacterScope);
+ auto &attributeScope = attributeManager->getAttributeScope(CharacterScope);
LOG_DEBUG("Character creation: initialisation of "
- << attributes.size() << " attributes.");
- for (auto attributeScope : attributes)
- beingComponent->createAttribute(attributeScope.first,
- *attributeScope.second);
+ << attributeScope.size() << " attributes.");
+ for (auto &attributeIt : attributeScope)
+ beingComponent->createAttribute(attributeIt.first, attributeIt.second);
auto *actorComponent = entity.getComponent<ActorComponent>();
actorComponent->setWalkMask(Map::BLOCKMASK_WALL);
@@ -499,7 +497,7 @@ void CharacterComponent::levelup(Entity &entity)
}
AttribmodResponseCode CharacterComponent::useCharacterPoint(Entity &entity,
- size_t attribute)
+ int attribute)
{
auto *beingComponent = entity.getComponent<BeingComponent>();
@@ -517,7 +515,7 @@ AttribmodResponseCode CharacterComponent::useCharacterPoint(Entity &entity,
}
AttribmodResponseCode CharacterComponent::useCorrectionPoint(Entity &entity,
- size_t attribute)
+ int attribute)
{
auto *beingComponent = entity.getComponent<BeingComponent>();
diff --git a/src/game-server/character.h b/src/game-server/character.h
index 6f090aa6..b5d923e6 100644
--- a/src/game-server/character.h
+++ b/src/game-server/character.h
@@ -324,14 +324,14 @@ class CharacterComponent : public Component
* basic attribute
*/
AttribmodResponseCode useCharacterPoint(Entity &entity,
- size_t attribute);
+ int attribute);
/**
* Tries to use a correction point to reduce a
* basic attribute and regain a character point
*/
AttribmodResponseCode useCorrectionPoint(Entity &entity,
- size_t attribute);
+ int attribute);
void setCharacterPoints(int points) { mCharacterPoints = points; }
int getCharacterPoints() const { return mCharacterPoints; }
diff --git a/src/game-server/monster.cpp b/src/game-server/monster.cpp
index a40c24a4..30be1201 100644
--- a/src/game-server/monster.cpp
+++ b/src/game-server/monster.cpp
@@ -53,7 +53,7 @@ MonsterComponent::MonsterComponent(Entity &entity, MonsterClass *specy):
for (auto attrInfo : attributeManager->getAttributeScope(MonsterScope))
{
- beingComponent->createAttribute(attrInfo.first, *attrInfo.second);
+ beingComponent->createAttribute(attrInfo.first, attrInfo.second);
}
/*
@@ -71,7 +71,8 @@ MonsterComponent::MonsterComponent(Entity &entity, MonsterClass *specy):
double factor = 100 + (rand() % (mutation * 2)) - mutation;
attributeValue = attributeValue * factor / 100.0;
}
- beingComponent->setAttribute(entity, attribute.first, attributeValue);
+ beingComponent->setAttribute(entity, attribute.first->id,
+ attributeValue);
}
beingComponent->setGender(specy->getGender());
diff --git a/src/game-server/monster.h b/src/game-server/monster.h
index 434e170d..ae798efc 100644
--- a/src/game-server/monster.h
+++ b/src/game-server/monster.h
@@ -106,23 +106,11 @@ class MonsterClass
/**
* Sets a being base attribute.
*/
- void setAttribute(int attribute, double value)
- { mAttributes[attribute] = value; }
+ void setAttribute(const AttributeManager::AttributeInfo *attribute,
+ double value);
- /**
- * Returns a being base attribute.
- */
- double getAttribute(int attribute) const
- { return mAttributes.at(attribute); }
-
- /**
- * Returns whether the monster has got the attribute.
- */
- bool hasAttribute(int attribute) const
- { return (mAttributes.find(attribute) != mAttributes.end()); }
-
- const std::map<int, double> &getAttributes() const
- { return mAttributes; }
+ const std::map<const AttributeManager::AttributeInfo *, double>
+ &getAttributes() const;
/** Sets collision circle radius. */
void setSize(int size) { mSize = size; }
@@ -163,7 +151,7 @@ class MonsterClass
BeingGender mGender;
MonsterDrops mDrops;
- std::map<int, double> mAttributes; /**< Base attributes of the monster. */
+ std::map<const AttributeManager::AttributeInfo *, double> mAttributes;
std::set<AbilityManager::AbilityInfo *> mAbilities;
float mSpeed; /**< The monster class speed in tiles per second */
int mSize;
@@ -216,6 +204,18 @@ class MonsterComponent : public Component
Timeout mDecayTimeout;
};
+inline void MonsterClass::setAttribute(
+ const AttributeManager::AttributeInfo *attribute, double value)
+{
+ mAttributes[attribute] = value;
+}
+
+inline const std::map<const AttributeManager::AttributeInfo *, double>
+&MonsterClass::getAttributes() const
+{
+ return mAttributes;
+}
+
inline void MonsterClass::addAbility(AbilityManager::AbilityInfo *info)
{
mAbilities.insert(info);
diff --git a/src/game-server/monstermanager.cpp b/src/game-server/monstermanager.cpp
index fc9f06b9..0043cdb4 100644
--- a/src/game-server/monstermanager.cpp
+++ b/src/game-server/monstermanager.cpp
@@ -73,10 +73,10 @@ void MonsterManager::readMonsterNode(xmlNodePtr node, const std::string &filenam
if (!xmlStrEqual(node->name, BAD_CAST "monster"))
return;
- int id = XML::getProperty(node, "id", 0);
+ int monsterId = XML::getProperty(node, "id", 0);
std::string name = XML::getProperty(node, "name", std::string());
- if (id < 1)
+ if (monsterId < 1)
{
LOG_WARN("Monster Manager: Ignoring monster ("
<< name << ") without Id in "
@@ -84,29 +84,29 @@ void MonsterManager::readMonsterNode(xmlNodePtr node, const std::string &filenam
return;
}
- MonsterClasses::iterator i = mMonsterClasses.find(id);
+ MonsterClasses::iterator i = mMonsterClasses.find(monsterId);
if (i != mMonsterClasses.end())
{
LOG_WARN("Monster Manager: Ignoring duplicate definition of "
- "monster '" << id << "'!");
+ "monster '" << monsterId << "'!");
return;
}
- MonsterClass *monster = new MonsterClass(id);
- mMonsterClasses[id] = monster;
+ MonsterClass *monster = new MonsterClass(monsterId);
+ mMonsterClasses[monsterId] = monster;
if (!name.empty())
{
monster->setName(name);
if (mMonsterClassesByName.contains(name))
- LOG_WARN("Monster Manager: Name not unique for monster " << id);
+ LOG_WARN("Monster Manager: Name not unique for monster "
+ << monsterId);
else
mMonsterClassesByName.insert(name, monster);
}
MonsterDrops drops;
- bool attributesSet = false;
for_each_xml_child_node(subnode, node)
{
@@ -137,24 +137,7 @@ void MonsterManager::readMonsterNode(xmlNodePtr node, const std::string &filenam
}
else if (xmlStrEqual(subnode->name, BAD_CAST "attributes"))
{
- attributesSet = true;
-
- const int hp = XML::getProperty(subnode, "hp", -1);
- monster->setAttribute(ATTR_MAX_HP, hp);
- monster->setAttribute(ATTR_HP, hp);
-
- monster->setAttribute(ATTR_DODGE,
- XML::getProperty(subnode, "evade", -1));
- monster->setAttribute(ATTR_MAGIC_DODGE,
- XML::getProperty(subnode, "magic-evade", -1));
- monster->setAttribute(ATTR_ACCURACY,
- XML::getProperty(subnode, "hit", -1));
- monster->setAttribute(ATTR_DEFENSE,
- XML::getProperty(subnode, "physical-defence", -1));
- monster->setAttribute(ATTR_MAGIC_DEFENSE,
- XML::getProperty(subnode, "magical-defence", -1));
monster->setSize(XML::getProperty(subnode, "size", -1));
- float speed = (XML::getFloatProperty(subnode, "speed", -1.0f));
monster->setMutation(XML::getProperty(subnode, "mutation", 0));
std::string genderString = XML::getProperty(subnode, "gender",
std::string());
@@ -164,59 +147,48 @@ void MonsterManager::readMonsterNode(xmlNodePtr node, const std::string &filenam
if (monster->getMutation() > MAX_MUTATION)
{
LOG_WARN(filename
- << ": Mutation of monster Id:" << id << " more than "
- << MAX_MUTATION << "%. Defaulted to 0.");
+ << ": Mutation of monster Id:" << monsterId
+ << " more than " << MAX_MUTATION
+ << "%. Defaulted to 0.");
monster->setMutation(0);
}
- bool attributesComplete = true;
-
if (monster->getSize() == -1)
{
LOG_WARN(filename
- << ": No size set for monster Id:" << id << ". "
+ << ": No size set for monster Id:" << monsterId << ". "
<< "Defaulted to " << DEFAULT_MONSTER_SIZE
<< " pixels.");
monster->setSize(DEFAULT_MONSTER_SIZE);
- attributesComplete = false;
}
-
- if (speed == -1.0f)
+ }
+ else if (xmlStrEqual(subnode->name, BAD_CAST "attribute"))
+ {
+ std::string attributeIdString = XML::getProperty(subnode, "id",
+ std::string());
+ const AttributeManager::AttributeInfo *info;
+ if (utils::isNumeric(attributeIdString))
{
- LOG_WARN(filename
- << ": No speed set for monster Id:" << id << ". "
- << "Defaulted to " << DEFAULT_MONSTER_SPEED
- << " tiles/second.");
- speed = DEFAULT_MONSTER_SPEED;
- attributesComplete = false;
+ const int attributeId = utils::stringToInt(attributeIdString);
+ info = attributeManager->getAttributeInfo(attributeId);
}
- monster->setAttribute(ATTR_MOVE_SPEED_TPS, speed);
-
- if (!attributesComplete)
+ else
{
- LOG_WARN(filename
- << ": Attributes incomplete for monster Id:" << id
- << ". Defaults values may have been applied!");
+ info = attributeManager->getAttributeInfo(attributeIdString);
}
- }
- else if (xmlStrEqual(subnode->name, BAD_CAST "attribute"))
- {
- const int id = XML::getProperty(subnode, "id", 0);
- auto *attributeInfo = attributeManager->getAttributeInfo(id);
-
- if (!attributeInfo)
+ if (!info)
{
LOG_WARN(filename
- << ": Invalid attribute id " << id
- << " for monster Id: " << id
+ << ": Invalid attribute id " << attributeIdString
+ << " for monster Id: " << monsterId
<< ". Skipping!");
continue;
}
const double value = XML::getFloatProperty(subnode, "value", 0.0);
- monster->setAttribute(id, value);
+ monster->setAttribute(info, value);
}
else if (xmlStrEqual(subnode->name, BAD_CAST "ability"))
{
@@ -225,8 +197,8 @@ void MonsterManager::readMonsterNode(xmlNodePtr node, const std::string &filenam
AbilityManager::AbilityInfo *info = 0;
if (utils::isNumeric(idText))
{
- const int id = utils::stringToInt(idText);
- info = abilityManager->getAbilityInfo(id);
+ const int abilityId = utils::stringToInt(idText);
+ info = abilityManager->getAbilityInfo(abilityId);
}
else
{
@@ -237,7 +209,7 @@ void MonsterManager::readMonsterNode(xmlNodePtr node, const std::string &filenam
{
LOG_WARN(filename
<< ": Invalid ability id " << idText
- << " for monster id: " << id
+ << " for monster id: " << monsterId
<< " Skipping!");
continue;
}
@@ -253,16 +225,10 @@ void MonsterManager::readMonsterNode(xmlNodePtr node, const std::string &filenam
}
monster->setDrops(drops);
- if (!attributesSet)
- {
- LOG_WARN(filename
- << ": No attributes defined for monster Id:" << id
- << " (" << name << ")");
- }
if (monster->getExp() == -1)
{
LOG_WARN(filename
- << ": No experience defined for monster Id:" << id
+ << ": No experience defined for monster Id:" << monsterId
<< " (" << name << ")");
monster->setExp(0);
}