summaryrefslogtreecommitdiff
path: root/src/game-server/being.cpp
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/being.cpp
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/being.cpp')
-rw-r--r--src/game-server/being.cpp37
1 files changed, 20 insertions, 17 deletions
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