diff options
author | Andrei Karas <akaras@inbox.ru> | 2011-11-19 21:49:38 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2011-11-19 21:52:21 +0300 |
commit | 10cf52b5ab6a9e1bb8328d9859b11d885fd5eef9 (patch) | |
tree | 0bbedbb7883e08901d4a787cac2f2dc6902f1279 | |
parent | 7929cda3c6a65f8707b753e7190a4ca89891fd7e (diff) | |
download | manaplus-10cf52b5ab6a9e1bb8328d9859b11d885fd5eef9.tar.gz manaplus-10cf52b5ab6a9e1bb8328d9859b11d885fd5eef9.tar.bz2 manaplus-10cf52b5ab6a9e1bb8328d9859b11d885fd5eef9.tar.xz manaplus-10cf52b5ab6a9e1bb8328d9859b11d885fd5eef9.zip |
Add limits for creating chars (hair color, hair style, stats).
-rwxr-xr-x | configure.ac | 2 | ||||
-rw-r--r-- | data/CMakeLists.txt | 1 | ||||
-rw-r--r-- | data/Makefile.am | 2 | ||||
-rw-r--r-- | data/perserver/CMakeLists.txt | 1 | ||||
-rw-r--r-- | data/perserver/Makefile.am | 3 | ||||
-rw-r--r-- | data/perserver/default/CMakeLists.txt | 5 | ||||
-rw-r--r-- | data/perserver/default/Makefile.am | 8 | ||||
-rw-r--r-- | data/perserver/default/charcreation.xml | 9 | ||||
-rw-r--r-- | manaplus.cbp | 2 | ||||
-rw-r--r-- | packaging/windows/setup.nsi | 4 | ||||
-rw-r--r-- | src/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/client.cpp | 5 | ||||
-rw-r--r-- | src/gui/charcreatedialog.cpp | 19 | ||||
-rw-r--r-- | src/gui/charcreatedialog.h | 5 | ||||
-rw-r--r-- | src/net/ea/charserverhandler.cpp | 14 | ||||
-rw-r--r-- | src/resources/chardb.cpp | 129 | ||||
-rw-r--r-- | src/resources/chardb.h | 62 |
18 files changed, 270 insertions, 5 deletions
diff --git a/configure.ac b/configure.ac index 9f68bf2cb..26f448c8a 100755 --- a/configure.ac +++ b/configure.ac @@ -266,6 +266,8 @@ data/help/ru/Makefile data/help/ru/tips/Makefile data/help/tips/Makefile data/icons/Makefile +data/perserver/Makefile +data/perserver/default/Makefile docs/Makefile po/Makefile.in ]) diff --git a/data/CMakeLists.txt b/data/CMakeLists.txt index 968d926b3..0435f6e35 100644 --- a/data/CMakeLists.txt +++ b/data/CMakeLists.txt @@ -4,6 +4,7 @@ ADD_SUBDIRECTORY(fonts) ADD_SUBDIRECTORY(graphics) ADD_SUBDIRECTORY(help) ADD_SUBDIRECTORY(icons) +ADD_SUBDIRECTORY(perserver) ADD_SUBDIRECTORY(sfx) ADD_SUBDIRECTORY(themes) diff --git a/data/Makefile.am b/data/Makefile.am index 5531c610f..302f0feae 100644 --- a/data/Makefile.am +++ b/data/Makefile.am @@ -1,5 +1,5 @@ -SUBDIRS = fonts graphics help icons sfx themes +SUBDIRS = fonts graphics help icons perserver sfx themes EXTRA_DIST = CMakeLists.txt items.xsd diff --git a/data/perserver/CMakeLists.txt b/data/perserver/CMakeLists.txt new file mode 100644 index 000000000..8b86a84b0 --- /dev/null +++ b/data/perserver/CMakeLists.txt @@ -0,0 +1 @@ +ADD_SUBDIRECTORY(default) diff --git a/data/perserver/Makefile.am b/data/perserver/Makefile.am new file mode 100644 index 000000000..b754c27f8 --- /dev/null +++ b/data/perserver/Makefile.am @@ -0,0 +1,3 @@ +SUBDIRS = default + +EXTRA_DIST = CMakeLists.txt diff --git a/data/perserver/default/CMakeLists.txt b/data/perserver/default/CMakeLists.txt new file mode 100644 index 000000000..61bd98df1 --- /dev/null +++ b/data/perserver/default/CMakeLists.txt @@ -0,0 +1,5 @@ +SET (FILES + charcreation.xml + ) + +INSTALL(FILES ${FILES} DESTINATION ${DATA_DIR}/perserver/default) diff --git a/data/perserver/default/Makefile.am b/data/perserver/default/Makefile.am new file mode 100644 index 000000000..7ab87da67 --- /dev/null +++ b/data/perserver/default/Makefile.am @@ -0,0 +1,8 @@ +defaultdir = $(pkgdatadir)/data/perserver/default + +default_DATA = \ + charcreation.xml + +EXTRA_DIST = \ + $(default_DATA) \ + CMakeLists.txt diff --git a/data/perserver/default/charcreation.xml b/data/perserver/default/charcreation.xml new file mode 100644 index 000000000..a7cb1a091 --- /dev/null +++ b/data/perserver/default/charcreation.xml @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Author : 4144 +(C) ManaPlus Developers 2011. --> + +<chars> + <haircolor min="0" max="11" /> + <hairstyle min="0" max="19" /> + <stat min="1" max="9" sum="30" /> +</chars> diff --git a/manaplus.cbp b/manaplus.cbp index 3c39ed68b..26f3b7c5e 100644 --- a/manaplus.cbp +++ b/manaplus.cbp @@ -589,6 +589,8 @@ <Unit filename="src\resources\animation.h" />
<Unit filename="src\resources\beinginfo.cpp" />
<Unit filename="src\resources\beinginfo.h" />
+ <Unit filename="src\resources\chardb.cpp" />
+ <Unit filename="src\resources\chardb.h" />
<Unit filename="src\resources\colordb.cpp" />
<Unit filename="src\resources\colordb.h" />
<Unit filename="src\resources\dye.cpp" />
diff --git a/packaging/windows/setup.nsi b/packaging/windows/setup.nsi index baa7930a4..eb0e5ffe9 100644 --- a/packaging/windows/setup.nsi +++ b/packaging/windows/setup.nsi @@ -226,6 +226,8 @@ Section "Core files (required)" SecCore CreateDirectory "$INSTDIR\data\help\ru\tips" CreateDirectory "$INSTDIR\data\help\tips" CreateDirectory "$INSTDIR\data\icons" + CreateDirectory "$INSTDIR\data\perserver" + CreateDirectory "$INSTDIR\data\perserver\default" CreateDirectory "$INSTDIR\data\graphics\gui" CreateDirectory "$INSTDIR\data\graphics\images" CreateDirectory "$INSTDIR\data\graphics\sprites" @@ -317,6 +319,8 @@ Section "Core files (required)" SecCore File "${SRCDIR}\data\help\tips\*.jpg" SetOutPath "$INSTDIR\data\icons\" File "${SRCDIR}\data\icons\manaplus.ico" + SetOutPath "$INSTDIR\data\perserver\default\" + File "${SRCDIR}\data\perserver\default\*.xml" SetOutPath "$INSTDIR\docs" File "${SRCDIR}\docs\FAQ.txt" SectionEnd 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 |