summaryrefslogtreecommitdiff
path: root/src/resources
diff options
context:
space:
mode:
Diffstat (limited to 'src/resources')
-rw-r--r--src/resources/action.cpp3
-rw-r--r--src/resources/action.h7
-rw-r--r--src/resources/chardb.cpp129
-rw-r--r--src/resources/chardb.h62
-rw-r--r--src/resources/colordb.cpp1
-rw-r--r--src/resources/colordb.h1
-rw-r--r--src/resources/itemdb.cpp30
-rw-r--r--src/resources/itemdb.h6
-rw-r--r--src/resources/mapreader.h6
-rw-r--r--src/resources/spritedef.cpp105
-rw-r--r--src/resources/spritedef.h15
11 files changed, 320 insertions, 45 deletions
diff --git a/src/resources/action.cpp b/src/resources/action.cpp
index c2af3ff9b..f940bffcb 100644
--- a/src/resources/action.cpp
+++ b/src/resources/action.cpp
@@ -29,7 +29,8 @@
#include "debug.h"
-Action::Action()
+Action::Action() :
+ mNumber(100)
{
}
diff --git a/src/resources/action.h b/src/resources/action.h
index 05b326d8f..9ab6f98d5 100644
--- a/src/resources/action.h
+++ b/src/resources/action.h
@@ -43,10 +43,17 @@ class Action
Animation *getAnimation(int direction) const;
+ unsigned getNumber()
+ { return mNumber; }
+
+ void setNumber(unsigned n)
+ { mNumber = n; }
+
protected:
typedef std::map<int, Animation*> Animations;
typedef Animations::iterator AnimationIterator;
Animations mAnimations;
+ unsigned mNumber;
};
#endif
diff --git a/src/resources/chardb.cpp b/src/resources/chardb.cpp
new file mode 100644
index 000000000..d944f280e
--- /dev/null
+++ b/src/resources/chardb.cpp
@@ -0,0 +1,129 @@
+/*
+ * Color database
+ * Copyright (C) 2008 Aethyra Development Team
+ * Copyright (C) 2011 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "resources/chardb.h"
+
+#include "client.h"
+#include "logger.h"
+
+#include "utils/xml.h"
+
+#include <libxml/tree.h>
+
+#include "debug.h"
+
+namespace
+{
+ bool mLoaded = false;
+ unsigned mMinHairColor = 0;
+ unsigned mMaxHairColor = 0;
+ unsigned mMinHairStyle = 0;
+ unsigned mMaxHairStyle = 0;
+ unsigned mMinStat = 0;
+ unsigned mMaxStat = 0;
+ unsigned mSumStat = 0;
+}
+
+void CharDB::load()
+{
+ if (mLoaded)
+ unload();
+
+ XML::Document *doc = new XML::Document("charcreation.xml");
+ xmlNodePtr root = doc->rootNode();
+
+ if (!root || !xmlStrEqual(root->name, BAD_CAST "chars"))
+ {
+ logger->log1("CharDB: Failed to parse charcreation.xml.");
+
+ delete doc;
+ return;
+ }
+
+ for_each_xml_child_node(node, root)
+ {
+ if (xmlStrEqual(node->name, BAD_CAST "haircolor"))
+ {
+ loadMinMax(node, &mMinHairColor, &mMaxHairColor);
+ }
+ else if (xmlStrEqual(node->name, BAD_CAST "hairstyle"))
+ {
+ loadMinMax(node, &mMinHairStyle, &mMaxHairStyle);
+ }
+ else if (xmlStrEqual(node->name, BAD_CAST "stat"))
+ {
+ loadMinMax(node, &mMinStat, &mMaxStat);
+ mSumStat = XML::getProperty(node, "sum", 0);
+ }
+ }
+
+ delete doc;
+
+ mLoaded = true;
+}
+
+void CharDB::loadMinMax(xmlNodePtr node, unsigned *min, unsigned *max)
+{
+ *min = XML::getProperty(node, "min", 1);
+ *max = XML::getProperty(node, "max", 10);
+}
+
+void CharDB::unload()
+{
+ logger->log1("Unloading chars database...");
+
+ mLoaded = false;
+}
+
+unsigned CharDB::getMinHairColor()
+{
+ return mMinHairColor;
+}
+
+unsigned CharDB::getMaxHairColor()
+{
+ return mMaxHairColor;
+}
+
+unsigned CharDB::getMinHairStyle()
+{
+ return mMinHairStyle;
+}
+
+unsigned CharDB::getMaxHairStyle()
+{
+ return mMaxHairStyle;
+}
+
+unsigned CharDB::getMinStat()
+{
+ return mMinStat;
+}
+
+unsigned CharDB::getMaxStat()
+{
+ return mMaxStat;
+}
+
+unsigned CharDB::getSumStat()
+{
+ return mSumStat;
+}
diff --git a/src/resources/chardb.h b/src/resources/chardb.h
new file mode 100644
index 000000000..769dedb56
--- /dev/null
+++ b/src/resources/chardb.h
@@ -0,0 +1,62 @@
+/*
+ * Color database
+ * Copyright (C) 2008 Aethyra Development Team
+ * Copyright (C) 2011 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef CHARDB_MANAGER_H
+#define CHARDB_MANAGER_H
+
+#include <map>
+#include <string>
+
+#include <libxml/tree.h>
+
+/**
+ * Char information database.
+ */
+namespace CharDB
+{
+ /**
+ * Loads the chars data.
+ */
+ void load();
+
+ /**
+ * Clear the chars data
+ */
+ void unload();
+
+ void loadMinMax(xmlNodePtr node, unsigned *min, unsigned *max);
+
+ unsigned getMinHairColor();
+
+ unsigned getMaxHairColor();
+
+ unsigned getMinHairStyle();
+
+ unsigned getMaxHairStyle();
+
+ unsigned getMinStat();
+
+ unsigned getMaxStat();
+
+ unsigned getSumStat();
+}
+
+#endif
diff --git a/src/resources/colordb.cpp b/src/resources/colordb.cpp
index 225abef91..3b8c9d573 100644
--- a/src/resources/colordb.cpp
+++ b/src/resources/colordb.cpp
@@ -1,6 +1,7 @@
/*
* Color database
* Copyright (C) 2008 Aethyra Development Team
+ * Copyright (C) 2011 The ManaPlus Developers
*
* This file is part of The ManaPlus Client.
*
diff --git a/src/resources/colordb.h b/src/resources/colordb.h
index 83bff57da..f4cc88a59 100644
--- a/src/resources/colordb.h
+++ b/src/resources/colordb.h
@@ -1,6 +1,7 @@
/*
* Color database
* Copyright (C) 2008 Aethyra Development Team
+ * Copyright (C) 2011 The ManaPlus Developers
*
* This file is part of The ManaPlus Client.
*
diff --git a/src/resources/itemdb.cpp b/src/resources/itemdb.cpp
index 3e53dd6e7..2911fa06f 100644
--- a/src/resources/itemdb.cpp
+++ b/src/resources/itemdb.cpp
@@ -546,25 +546,51 @@ int parseDirectionName(std::string name)
{
int id = -1;
if (name == "down")
- id = DIRECTION_DOWN;
+ {
+ if (serverVersion > 0)
+ id = DIRECTION_DOWN;
+ else
+ id = -2;
+ }
else if (name == "downleft" || name == "leftdown")
+ {
id = DIRECTION_DOWNLEFT;
+ }
else if (name == "left")
+ {
id = DIRECTION_LEFT;
+ }
else if (name == "upleft" || name == "leftup")
+ {
id = DIRECTION_UPLEFT;
+ }
else if (name == "up")
- id = DIRECTION_UP;
+ {
+ if (serverVersion > 0)
+ id = DIRECTION_UP;
+ else
+ id = -3;
+ }
else if (name == "upright" || name == "rightup")
+ {
id = DIRECTION_UPRIGHT;
+ }
else if (name == "right")
+ {
id = DIRECTION_RIGHT;
+ }
else if (name == "downright" || name == "rightdown")
+ {
id = DIRECTION_DOWNRIGHT;
+ }
else if (name == "downall")
+ {
id = -2;
+ }
else if (name == "upall")
+ {
id = -3;
+ }
return id;
}
diff --git a/src/resources/itemdb.h b/src/resources/itemdb.h
index c20961eff..71f0a490e 100644
--- a/src/resources/itemdb.h
+++ b/src/resources/itemdb.h
@@ -28,12 +28,6 @@
#include <map>
#include <string>
-#ifdef __GNUC__
-#define A_UNUSED __attribute__ ((unused))
-#else
-#define A_UNUSED
-#endif
-
class ItemInfo;
/**
diff --git a/src/resources/mapreader.h b/src/resources/mapreader.h
index b10f35d89..c15a83b6f 100644
--- a/src/resources/mapreader.h
+++ b/src/resources/mapreader.h
@@ -27,12 +27,6 @@
#include <string>
-#ifdef __GNUC__
-#define A_UNUSED __attribute__ ((unused))
-#else
-#define A_UNUSED
-#endif
-
class Map;
class Properties;
class Tileset;
diff --git a/src/resources/spritedef.cpp b/src/resources/spritedef.cpp
index 3e2aac785..32d18b6b8 100644
--- a/src/resources/spritedef.cpp
+++ b/src/resources/spritedef.cpp
@@ -35,23 +35,44 @@
#include "utils/xml.h"
-#include <set>
-
#include "debug.h"
SpriteReference *SpriteReference::Empty = nullptr;
-Action *SpriteDef::getAction(std::string action) const
+Action *SpriteDef::getAction(std::string action, unsigned num) const
{
- Actions::const_iterator i = mActions.find(action);
+ Actions::const_iterator i = mActions.find(num);
+ if (i == mActions.end() && num != 100)
+ i = mActions.find(100);
- if (i == mActions.end())
+ if (i == mActions.end() || !(*i).second)
+ return nullptr;
+
+ ActionMap::const_iterator it = ((*i).second)->find(action);
+
+ if (it == ((*i).second)->end())
{
logger->log("Warning: no action \"%s\" defined!", action.c_str());
return nullptr;
}
- return i->second;
+ return (*it).second;
+}
+
+unsigned SpriteDef::findNumber(unsigned num) const
+{
+ unsigned min = 101;
+ Actions::const_iterator it = mActions.begin();
+ Actions::const_iterator it_end = mActions.end();
+ for (; it != it_end; ++ it)
+ {
+ unsigned n = (*it).first;
+ if (n >= num && n < min)
+ min = n;
+ }
+ if (min == 101)
+ return 0;
+ return min;
}
SpriteDef *SpriteDef::load(const std::string &animationFile, int variant)
@@ -77,6 +98,7 @@ SpriteDef *SpriteDef::load(const std::string &animationFile, int variant)
}
SpriteDef *def = new SpriteDef;
+ def->mProcessedFiles.insert(animationFile);
def->loadSprite(rootNode, variant, palettes);
def->substituteActions();
return def;
@@ -84,11 +106,19 @@ SpriteDef *SpriteDef::load(const std::string &animationFile, int variant)
void SpriteDef::substituteAction(std::string complete, std::string with)
{
- if (mActions.find(complete) == mActions.end())
+ Actions::const_iterator it = mActions.begin();
+ Actions::const_iterator it_end = mActions.end();
+ for (; it != it_end; ++ it)
{
- Actions::const_iterator i = mActions.find(with);
- if (i != mActions.end())
- mActions[complete] = i->second;
+ ActionMap *d = (*it).second;
+ if (!d)
+ continue;
+ if (d->find(complete) == d->end())
+ {
+ ActionMap::iterator i = d->find(with);
+ if (i != d->end())
+ (*d)[complete] = i->second;
+ }
}
}
@@ -162,12 +192,13 @@ void SpriteDef::loadAction(xmlNodePtr node, int variant_offset)
{
const std::string actionName = XML::getProperty(node, "name", "");
const std::string imageSetName = XML::getProperty(node, "imageset", "");
+ const unsigned hp = XML::getProperty(node, "hp", 100);
ImageSetIterator si = mImageSets.find(imageSetName);
if (si == mImageSets.end())
{
logger->log("Warning: imageset \"%s\" not defined in %s",
- imageSetName.c_str(), getIdPath().c_str());
+ imageSetName.c_str(), getIdPath().c_str());
return;
}
ImageSet *imageSet = si->second;
@@ -175,19 +206,21 @@ void SpriteDef::loadAction(xmlNodePtr node, int variant_offset)
if (actionName == SpriteAction::INVALID)
{
logger->log("Warning: Unknown action \"%s\" defined in %s",
- actionName.c_str(), getIdPath().c_str());
+ actionName.c_str(), getIdPath().c_str());
return;
}
Action *action = new Action;
- mActions[actionName] = action;
+ action->setNumber(hp);
+ addAction(hp, actionName, action);
// dirty hack to fix bad resources in tmw server
if (actionName == "attack_stab")
- mActions["attack"] = action;
+ addAction(hp, "attack", action);
// When first action set it as default direction
- if (mActions.size() == 1)
- mActions[SpriteAction::DEFAULT] = action;
+ Actions::const_iterator i = mActions.find(hp);
+ if ((*i).second->size() == 1)
+ addAction(hp, SpriteAction::DEFAULT, action);
// Load animations
for_each_xml_child_node(animationNode, node)
@@ -280,7 +313,7 @@ void SpriteDef::loadAnimation(xmlNodePtr animationNode,
if (!img)
{
logger->log("No image at index %d",
- pos + variant_offset);
+ pos + variant_offset);
pos ++;
continue;
}
@@ -317,14 +350,21 @@ void SpriteDef::loadAnimation(xmlNodePtr animationNode,
void SpriteDef::includeSprite(xmlNodePtr includeNode)
{
- // TODO: Perform circular dependency check, since it's easy to crash the
- // client this way.
- const std::string filename = XML::getProperty(includeNode, "file", "");
+ std::string filename = XML::getProperty(includeNode, "file", "");
if (filename.empty())
return;
+ filename = paths.getStringValue("sprites") + filename;
+
+ if (mProcessedFiles.find(filename) != mProcessedFiles.end())
+ {
+ logger->log("Error, Tried to include %s which already is included.",
+ filename.c_str());
+ return;
+ }
+ mProcessedFiles.insert(filename);
- XML::Document doc(paths.getStringValue("sprites") + filename);
+ XML::Document doc(filename);
xmlNodePtr rootNode = doc.rootNode();
if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "sprite"))
@@ -339,14 +379,18 @@ void SpriteDef::includeSprite(xmlNodePtr includeNode)
SpriteDef::~SpriteDef()
{
// Actions are shared, so ensure they are deleted only once.
- std::set< Action * > actions;
- for (Actions::const_iterator i = mActions.begin(),
+ std::set<Action*> actions;
+ for (Actions::iterator i = mActions.begin(),
i_end = mActions.end(); i != i_end; ++i)
{
- actions.insert(i->second);
+ ActionMap::iterator it = (*i).second->begin();
+ ActionMap::iterator it_end = (*i).second->end();
+ for (; it != it_end; ++ it)
+ actions.insert(it->second);
+ delete (*i).second;
}
- for (std::set< Action * >::const_iterator i = actions.begin(),
+ for (std::set<Action*>::const_iterator i = actions.begin(),
i_end = actions.end(); i != i_end; ++i)
{
delete *i;
@@ -355,7 +399,7 @@ SpriteDef::~SpriteDef()
mActions.clear();
for (ImageSetIterator i = mImageSets.begin();
- i != mImageSets.end(); ++i)
+ i != mImageSets.end(); ++i)
{
if (i->second)
{
@@ -388,3 +432,12 @@ SpriteDirection SpriteDef::makeSpriteDirection(const std::string &direction)
else
return DIRECTION_INVALID;
}
+
+void SpriteDef::addAction(unsigned hp, std::string name, Action *action)
+{
+ Actions::const_iterator i = mActions.find(hp);
+ if (i == mActions.end())
+ mActions[hp] = new ActionMap();
+
+ (*mActions[hp])[name] = action;
+}
diff --git a/src/resources/spritedef.h b/src/resources/spritedef.h
index b2939fca1..3aa6369dd 100644
--- a/src/resources/spritedef.h
+++ b/src/resources/spritedef.h
@@ -29,6 +29,7 @@
#include <list>
#include <map>
+#include <set>
#include <string>
#include <vector>
@@ -117,7 +118,9 @@ class SpriteDef : public Resource
/**
* Returns the specified action.
*/
- Action *getAction(std::string action) const;
+ Action *getAction(std::string action, unsigned num) const;
+
+ unsigned findNumber(unsigned num) const;
/**
* Converts a string into a SpriteDirection enum.
@@ -125,11 +128,14 @@ class SpriteDef : public Resource
static SpriteDirection
makeSpriteDirection(const std::string &direction);
+ void addAction(unsigned hp, std::string name, Action *action);
+
private:
/**
* Constructor.
*/
- SpriteDef() {}
+ SpriteDef()
+ { }
/**
* Destructor.
@@ -177,11 +183,12 @@ class SpriteDef : public Resource
typedef std::map<std::string, ImageSet*> ImageSets;
typedef ImageSets::iterator ImageSetIterator;
-
- typedef std::map<std::string, Action*> Actions;
+ typedef std::map<std::string, Action*> ActionMap;
+ typedef std::map<unsigned, ActionMap*> Actions;
ImageSets mImageSets;
Actions mActions;
+ std::set<std::string> mProcessedFiles;
};
#endif // SPRITEDEF_H