summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/Makefile.am2
-rw-r--r--src/client.cpp5
-rw-r--r--src/gui/charcreatedialog.cpp19
-rw-r--r--src/gui/charcreatedialog.h5
-rw-r--r--src/net/ea/charserverhandler.cpp14
-rw-r--r--src/resources/chardb.cpp129
-rw-r--r--src/resources/chardb.h62
8 files changed, 234 insertions, 4 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index aa568fa1d..d281151e2 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -399,6 +399,8 @@ SET(SRCS
resources/animation.h
resources/beinginfo.cpp
resources/beinginfo.h
+ resources/chardb.cpp
+ resources/chardb.h
resources/colordb.cpp
resources/colordb.h
resources/dye.cpp
diff --git a/src/Makefile.am b/src/Makefile.am
index 9823ff934..fce320166 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -404,6 +404,8 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \
resources/animation.h \
resources/beinginfo.cpp \
resources/beinginfo.h \
+ resources/chardb.cpp \
+ resources/chardb.h \
resources/colordb.cpp \
resources/colordb.h \
resources/dye.cpp \
diff --git a/src/client.cpp b/src/client.cpp
index 7de58368c..d8bb747fb 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -85,6 +85,7 @@
#include "net/worldinfo.h"
#include "resources/beinginfo.h"
+#include "resources/chardb.h"
#include "resources/colordb.h"
#include "resources/emotedb.h"
#include "resources/image.h"
@@ -368,6 +369,8 @@ Client::Client(const Options &options):
Image::setEnableAlpha(config.getFloatValue("guialpha") != 1.0f);
#endif
+ resman->addToSearchPath(PKG_DATADIR "data/perserver/default", false);
+
#if defined __APPLE__
CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(mainBundle);
@@ -649,6 +652,7 @@ Client::~Client()
SDL_RemoveTimer(mSecondsCounterId);
// Unload XML databases
+ CharDB::unload();
ColorDB::unload();
EmoteDB::unload();
ItemDB::unload();
@@ -1111,6 +1115,7 @@ int Client::exec()
Mana::Event::trigger(CHANNEL_CLIENT, evt2);
// Load XML databases
+ CharDB::load();
ColorDB::load();
MapDB::load();
ItemDB::load();
diff --git a/src/gui/charcreatedialog.cpp b/src/gui/charcreatedialog.cpp
index 42435f036..c20cfab95 100644
--- a/src/gui/charcreatedialog.cpp
+++ b/src/gui/charcreatedialog.cpp
@@ -44,6 +44,7 @@
#include "net/messageout.h"
#include "net/net.h"
+#include "resources/chardb.h"
#include "resources/colordb.h"
#include "resources/itemdb.h"
@@ -66,10 +67,18 @@ CharCreateDialog::CharCreateDialog(CharSelectDialog *parent, int slot):
mPlayer = new Being(0, ActorSprite::PLAYER, mRace, nullptr);
mPlayer->setGender(GENDER_MALE);
- int numberOfHairColors = ColorDB::getHairSize();
+ maxHairColor = CharDB::getMaxHairColor();
+ minHairColor = CharDB::getMinHairColor();
+ if (!maxHairColor)
+ maxHairColor = ColorDB::getHairSize();
- mHairStyle = rand() % mPlayer->getNumOfHairstyles();
- mHairColor = rand() % numberOfHairColors;
+ maxHairStyle = CharDB::getMaxHairStyle();
+ minHairStyle = CharDB::getMinHairStyle();
+ if (!maxHairStyle)
+ maxHairStyle = mPlayer->getNumOfHairstyles();
+
+ mHairStyle = (rand() % maxHairStyle) + minHairStyle;
+ mHairColor = (rand() % maxHairColor) + minHairColor;
updateHair();
mNameField = new TextField("");
@@ -408,10 +417,14 @@ void CharCreateDialog::updateHair()
mHairStyle %= Being::getNumOfHairstyles();
if (mHairStyle < 0)
mHairStyle += Being::getNumOfHairstyles();
+ if (mHairStyle < minHairStyle || mHairStyle > maxHairStyle)
+ mHairStyle = minHairStyle;
mHairColor %= ColorDB::getHairSize();
if (mHairColor < 0)
mHairColor += ColorDB::getHairSize();
+ if (mHairColor < minHairColor || mHairColor > maxHairColor)
+ mHairColor = minHairColor;
mPlayer->setSprite(Net::getCharHandler()->hairSprite(),
mHairStyle * -1, ColorDB::getHairColor(mHairColor));
diff --git a/src/gui/charcreatedialog.h b/src/gui/charcreatedialog.h
index 2f0f83513..c7010d6b1 100644
--- a/src/gui/charcreatedialog.h
+++ b/src/gui/charcreatedialog.h
@@ -124,6 +124,11 @@ class CharCreateDialog : public Window, public gcn::ActionListener
int mRace;
int mSlot;
+
+ unsigned maxHairColor;
+ unsigned minHairColor;
+ unsigned maxHairStyle;
+ unsigned minHairStyle;
};
#endif // CHAR_CREATE_DIALOG_H
diff --git a/src/net/ea/charserverhandler.cpp b/src/net/ea/charserverhandler.cpp
index 0c01959f2..d71236496 100644
--- a/src/net/ea/charserverhandler.cpp
+++ b/src/net/ea/charserverhandler.cpp
@@ -35,6 +35,8 @@
#include "utils/gettext.h"
+#include "resources/chardb.h"
+
#include "debug.h"
extern Net::CharHandler *charHandler;
@@ -70,7 +72,17 @@ void CharServerHandler::setCharCreateDialog(CharCreateDialog *window)
const Token &token =
static_cast<LoginHandler*>(Net::getLoginHandler())->getToken();
- mCharCreateDialog->setAttributes(attributes, 30, 1, 9);
+ int minStat = CharDB::getMinStat();
+ if (!minStat)
+ minStat = 1;
+ int maxStat = CharDB::getMaxStat();
+ if (!maxStat)
+ maxStat = 9;
+ int sumStat = CharDB::getSumStat();
+ if (!sumStat)
+ sumStat = 30;
+
+ mCharCreateDialog->setAttributes(attributes, sumStat, minStat, maxStat);
mCharCreateDialog->setFixedGender(true, token.sex);
}
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