From f513868a135c1af288ff13ba2fcfdd6a5dc70a19 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 30 Sep 2013 20:36:56 +0300 Subject: move db files into db directory. --- Android.mk | 1 + src/CMakeLists.txt | 48 +- src/Makefile.am | 48 +- src/being/being.cpp | 13 +- src/client.cpp | 29 +- src/commands.cpp | 3 +- src/emoteshortcut.cpp | 2 +- src/flooritem.cpp | 3 +- src/game.cpp | 3 +- src/gui/widgets/emoteshortcutcontainer.h | 2 +- src/gui/widgets/itemlinkhandler.cpp | 2 +- src/gui/widgets/tabs/chattab.cpp | 3 +- src/gui/windows/charcreatedialog.cpp | 7 +- src/gui/windows/inventorywindow.cpp | 2 +- src/gui/windows/npcdialog.cpp | 5 +- src/gui/windows/textcommandeditor.cpp | 3 +- src/item.h | 2 +- src/net/ea/beinghandler.cpp | 3 +- src/net/ea/charserverhandler.cpp | 2 +- src/net/ea/playerhandler.cpp | 2 +- src/net/eathena/beinghandler.cpp | 3 +- src/net/eathena/charserverhandler.cpp | 3 +- src/net/tmwa/beinghandler.cpp | 3 +- src/net/tmwa/charserverhandler.cpp | 3 +- src/notifymanager.cpp | 2 +- src/resources/avatardb.cpp | 121 ----- src/resources/avatardb.h | 39 -- src/resources/beinginfo.h | 3 +- src/resources/chardb.cpp | 155 ------ src/resources/chardb.h | 68 --- src/resources/colordb.cpp | 200 ------- src/resources/colordb.h | 88 --- src/resources/db/avatardb.cpp | 121 +++++ src/resources/db/avatardb.h | 39 ++ src/resources/db/chardb.cpp | 155 ++++++ src/resources/db/chardb.h | 68 +++ src/resources/db/colordb.cpp | 200 +++++++ src/resources/db/colordb.h | 88 +++ src/resources/db/deaddb.cpp | 81 +++ src/resources/db/deaddb.h | 44 ++ src/resources/db/emotedb.cpp | 257 +++++++++ src/resources/db/emotedb.h | 87 +++ src/resources/db/itemdb.cpp | 889 +++++++++++++++++++++++++++++++ src/resources/db/itemdb.h | 75 +++ src/resources/db/mapdb.cpp | 176 ++++++ src/resources/db/mapdb.h | 78 +++ src/resources/db/monsterdb.cpp | 273 ++++++++++ src/resources/db/monsterdb.h | 46 ++ src/resources/db/npcdb.cpp | 158 ++++++ src/resources/db/npcdb.h | 50 ++ src/resources/db/palettedb.cpp | 108 ++++ src/resources/db/palettedb.h | 39 ++ src/resources/db/petdb.cpp | 137 +++++ src/resources/db/petdb.h | 39 ++ src/resources/db/sounddb.cpp | 79 +++ src/resources/db/sounddb.h | 37 ++ src/resources/deaddb.cpp | 81 --- src/resources/deaddb.h | 44 -- src/resources/dye.cpp | 2 +- src/resources/emotedb.cpp | 257 --------- src/resources/emotedb.h | 87 --- src/resources/itemdb.cpp | 889 ------------------------------- src/resources/itemdb.h | 75 --- src/resources/iteminfo.cpp | 2 +- src/resources/iteminfo.h | 2 +- src/resources/mapdb.cpp | 176 ------ src/resources/mapdb.h | 78 --- src/resources/mapreader.cpp | 3 +- src/resources/monsterdb.cpp | 273 ---------- src/resources/monsterdb.h | 46 -- src/resources/npcdb.cpp | 158 ------ src/resources/npcdb.h | 50 -- src/resources/palettedb.cpp | 108 ---- src/resources/palettedb.h | 39 -- src/resources/petdb.cpp | 137 ----- src/resources/petdb.h | 39 -- src/resources/sounddb.cpp | 79 --- src/resources/sounddb.h | 37 -- src/textcommand.cpp | 3 +- 79 files changed, 3439 insertions(+), 3421 deletions(-) delete mode 100644 src/resources/avatardb.cpp delete mode 100644 src/resources/avatardb.h delete mode 100644 src/resources/chardb.cpp delete mode 100644 src/resources/chardb.h delete mode 100644 src/resources/colordb.cpp delete mode 100644 src/resources/colordb.h create mode 100644 src/resources/db/avatardb.cpp create mode 100644 src/resources/db/avatardb.h create mode 100644 src/resources/db/chardb.cpp create mode 100644 src/resources/db/chardb.h create mode 100644 src/resources/db/colordb.cpp create mode 100644 src/resources/db/colordb.h create mode 100644 src/resources/db/deaddb.cpp create mode 100644 src/resources/db/deaddb.h create mode 100644 src/resources/db/emotedb.cpp create mode 100644 src/resources/db/emotedb.h create mode 100644 src/resources/db/itemdb.cpp create mode 100644 src/resources/db/itemdb.h create mode 100644 src/resources/db/mapdb.cpp create mode 100644 src/resources/db/mapdb.h create mode 100644 src/resources/db/monsterdb.cpp create mode 100644 src/resources/db/monsterdb.h create mode 100644 src/resources/db/npcdb.cpp create mode 100644 src/resources/db/npcdb.h create mode 100644 src/resources/db/palettedb.cpp create mode 100644 src/resources/db/palettedb.h create mode 100644 src/resources/db/petdb.cpp create mode 100644 src/resources/db/petdb.h create mode 100644 src/resources/db/sounddb.cpp create mode 100644 src/resources/db/sounddb.h delete mode 100644 src/resources/deaddb.cpp delete mode 100644 src/resources/deaddb.h delete mode 100644 src/resources/emotedb.cpp delete mode 100644 src/resources/emotedb.h delete mode 100644 src/resources/itemdb.cpp delete mode 100644 src/resources/itemdb.h delete mode 100644 src/resources/mapdb.cpp delete mode 100644 src/resources/mapdb.h delete mode 100644 src/resources/monsterdb.cpp delete mode 100644 src/resources/monsterdb.h delete mode 100644 src/resources/npcdb.cpp delete mode 100644 src/resources/npcdb.h delete mode 100644 src/resources/palettedb.cpp delete mode 100644 src/resources/palettedb.h delete mode 100644 src/resources/petdb.cpp delete mode 100644 src/resources/petdb.h delete mode 100644 src/resources/sounddb.cpp delete mode 100644 src/resources/sounddb.h diff --git a/Android.mk b/Android.mk index 964b135a7..7ba556d38 100644 --- a/Android.mk +++ b/Android.mk @@ -48,6 +48,7 @@ LOCAL_SRC_FILES := $(SDL_PATH)/src/main/android/SDL_android_main.c \ $(wildcard $(LOCAL_PATH)/src/particle/*.cpp) \ $(wildcard $(LOCAL_PATH)/src/render/*.cpp) \ $(wildcard $(LOCAL_PATH)/src/resources/*.cpp) \ + $(wildcard $(LOCAL_PATH)/src/resources/db/*.cpp) \ $(wildcard $(LOCAL_PATH)/src/test/*.cpp) \ $(wildcard $(LOCAL_PATH)/src/utils/*.cpp) \ $(wildcard $(LOCAL_PATH)/src/utils/translation/*.cpp) \ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index de76d6fe2..711702d6f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -438,25 +438,25 @@ SET(SRCS resources/animation.h resources/atlasmanager.cpp resources/atlasmanager.h - resources/avatardb.cpp - resources/avatardb.h + resources/db/avatardb.cpp + resources/db/avatardb.h resources/beingcommon.cpp resources/beingcommon.h resources/beinginfo.cpp resources/beinginfo.h - resources/chardb.cpp - resources/chardb.h - resources/colordb.cpp - resources/colordb.h + resources/db/chardb.cpp + resources/db/chardb.h + resources/db/colordb.cpp + resources/db/colordb.h resources/cursor.cpp resources/cursor.h - resources/deaddb.cpp - resources/deaddb.h + resources/db/deaddb.cpp + resources/db/deaddb.h resources/dye.cpp resources/dye.h resources/dyecolor.h - resources/emotedb.cpp - resources/emotedb.h + resources/db/emotedb.cpp + resources/db/emotedb.h resources/fboinfo.h resources/image.cpp resources/image.h @@ -466,24 +466,24 @@ SET(SRCS resources/imageset.cpp resources/imagewriter.cpp resources/imagewriter.h - resources/itemdb.cpp - resources/itemdb.h + resources/db/itemdb.cpp + resources/db/itemdb.h resources/iteminfo.h resources/iteminfo.cpp - resources/mapdb.cpp - resources/mapdb.h + resources/db/mapdb.cpp + resources/db/mapdb.h resources/mapreader.cpp resources/mapreader.h - resources/monsterdb.cpp - resources/monsterdb.h - resources/npcdb.cpp - resources/npcdb.h + resources/db/monsterdb.cpp + resources/db/monsterdb.h + resources/db/npcdb.cpp + resources/db/npcdb.h resources/openglimagehelper.cpp resources/openglimagehelper.h - resources/palettedb.cpp - resources/palettedb.h - resources/petdb.cpp - resources/petdb.h + resources/db/palettedb.cpp + resources/db/palettedb.h + resources/db/petdb.cpp + resources/db/petdb.h resources/resource.cpp resources/resource.h resources/resourcemanager.cpp @@ -496,8 +496,8 @@ SET(SRCS resources/sdlimagehelper.h resources/sdlmusic.cpp resources/sdlmusic.h - resources/sounddb.cpp - resources/sounddb.h + resources/db/sounddb.cpp + resources/db/sounddb.h resources/soundeffect.cpp resources/soundeffect.h resources/soundinfo.h diff --git a/src/Makefile.am b/src/Makefile.am index 185f92b25..7d6bc1147 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -449,25 +449,25 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \ resources/animation.h \ resources/atlasmanager.cpp \ resources/atlasmanager.h \ - resources/avatardb.cpp \ - resources/avatardb.h \ + resources/db/avatardb.cpp \ + resources/db/avatardb.h \ resources/beingcommon.cpp \ resources/beingcommon.h \ resources/beinginfo.cpp \ resources/beinginfo.h \ - resources/chardb.cpp \ - resources/chardb.h \ - resources/colordb.cpp \ - resources/colordb.h \ + resources/db/chardb.cpp \ + resources/db/chardb.h \ + resources/db/colordb.cpp \ + resources/db/colordb.h \ resources/cursor.cpp \ resources/cursor.h \ - resources/deaddb.cpp \ - resources/deaddb.h \ + resources/db/deaddb.cpp \ + resources/db/deaddb.h \ resources/dye.cpp \ resources/dye.h \ resources/dyecolor.h \ - resources/emotedb.cpp \ - resources/emotedb.h \ + resources/db/emotedb.cpp \ + resources/db/emotedb.h \ resources/fboinfo.h \ resources/image.cpp \ resources/image.h \ @@ -477,24 +477,24 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \ resources/imageset.cpp \ resources/imagewriter.cpp \ resources/imagewriter.h \ - resources/itemdb.cpp \ - resources/itemdb.h \ + resources/db/itemdb.cpp \ + resources/db/itemdb.h \ resources/iteminfo.h \ resources/iteminfo.cpp \ - resources/mapdb.cpp \ - resources/mapdb.h \ + resources/db/mapdb.cpp \ + resources/db/mapdb.h \ resources/mapreader.cpp \ resources/mapreader.h \ - resources/monsterdb.cpp \ - resources/monsterdb.h \ - resources/npcdb.cpp \ - resources/npcdb.h \ + resources/db/monsterdb.cpp \ + resources/db/monsterdb.h \ + resources/db/npcdb.cpp \ + resources/db/npcdb.h \ resources/openglimagehelper.cpp \ resources/openglimagehelper.h \ - resources/palettedb.cpp \ - resources/palettedb.h \ - resources/petdb.cpp \ - resources/petdb.h \ + resources/db/palettedb.cpp \ + resources/db/palettedb.h \ + resources/db/petdb.cpp \ + resources/db/petdb.h \ resources/resource.cpp \ resources/resource.h \ resources/resourcemanager.cpp \ @@ -507,8 +507,8 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \ resources/sdlimagehelper.h \ resources/sdlmusic.cpp \ resources/sdlmusic.h \ - resources/sounddb.cpp \ - resources/sounddb.h \ + resources/db/sounddb.cpp \ + resources/db/sounddb.h \ resources/soundeffect.cpp \ resources/soundeffect.h \ resources/soundinfo.h \ diff --git a/src/being/being.cpp b/src/being/being.cpp index 8da4cf5b5..683661420 100644 --- a/src/being/being.cpp +++ b/src/being/being.cpp @@ -52,15 +52,16 @@ #include "net/npchandler.h" #include "net/playerhandler.h" -#include "resources/avatardb.h" -#include "resources/emotedb.h" -#include "resources/itemdb.h" #include "resources/iteminfo.h" -#include "resources/monsterdb.h" -#include "resources/npcdb.h" -#include "resources/petdb.h" #include "resources/resourcemanager.h" +#include "resources/db/avatardb.h" +#include "resources/db/emotedb.h" +#include "resources/db/itemdb.h" +#include "resources/db/monsterdb.h" +#include "resources/db/npcdb.h" +#include "resources/db/petdb.h" + #include "gui/widgets/skilldata.h" #include "gui/widgets/skillinfo.h" diff --git a/src/client.cpp b/src/client.cpp index fb58c313a..c2b0ad8fb 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -82,25 +82,26 @@ #include "net/net.h" #include "net/partyhandler.h" -#include "resources/avatardb.h" -#include "resources/chardb.h" -#include "resources/colordb.h" -#include "resources/deaddb.h" -#include "resources/emotedb.h" #include "resources/imagehelper.h" #include "resources/openglimagehelper.h" -#include "resources/palettedb.h" #include "resources/surfaceimagehelper.h" -#include "resources/sounddb.h" -#include "resources/itemdb.h" -#include "resources/mapdb.h" -#include "resources/monsterdb.h" +#include "resources/resourcemanager.h" + +#include "resources/db/avatardb.h" +#include "resources/db/chardb.h" +#include "resources/db/colordb.h" +#include "resources/db/deaddb.h" +#include "resources/db/emotedb.h" +#include "resources/db/sounddb.h" +#include "resources/db/itemdb.h" +#include "resources/db/mapdb.h" +#include "resources/db/monsterdb.h" +#include "resources/db/npcdb.h" #ifdef MANASERV_SUPPORT -#include "resources/specialdb.h" +#include "resources/db/specialdb.h" #endif -#include "resources/npcdb.h" -#include "resources/petdb.h" -#include "resources/resourcemanager.h" +#include "resources/db/palettedb.h" +#include "resources/db/petdb.h" #include "utils/cpu.h" #include "utils/files.h" diff --git a/src/commands.cpp b/src/commands.cpp index b3e4b4817..727bb036c 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -69,10 +69,11 @@ #include "resources/subimage.h" #endif -#include "resources/itemdb.h" #include "resources/iteminfo.h" #include "resources/resourcemanager.h" +#include "resources/db/itemdb.h" + #include "utils/gettext.h" #include "utils/process.h" diff --git a/src/emoteshortcut.cpp b/src/emoteshortcut.cpp index 8fce70aed..2bd8e37d6 100644 --- a/src/emoteshortcut.cpp +++ b/src/emoteshortcut.cpp @@ -25,7 +25,7 @@ #include "being/localplayer.h" -#include "resources/emotedb.h" +#include "resources/db/emotedb.h" #include "debug.h" diff --git a/src/flooritem.cpp b/src/flooritem.cpp index 75fa30fdb..c5a07a74d 100644 --- a/src/flooritem.cpp +++ b/src/flooritem.cpp @@ -31,9 +31,10 @@ #include "gui/sdlfont.h" #include "gui/userpalette.h" -#include "resources/itemdb.h" #include "resources/iteminfo.h" +#include "resources/db/itemdb.h" + #include "debug.h" FloorItem::FloorItem(const int id, const int itemId, const int x, const int y, diff --git a/src/game.cpp b/src/game.cpp index 88d46b296..f0b42223c 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -93,10 +93,11 @@ #include "net/packetcounters.h" #include "resources/imagewriter.h" -#include "resources/mapdb.h" #include "resources/mapreader.h" #include "resources/resourcemanager.h" +#include "resources/db/mapdb.h" + #include "utils/gettext.h" #include "utils/langs.h" #include "utils/mkdir.h" diff --git a/src/gui/widgets/emoteshortcutcontainer.h b/src/gui/widgets/emoteshortcutcontainer.h index 7ec5badb6..71ce562db 100644 --- a/src/gui/widgets/emoteshortcutcontainer.h +++ b/src/gui/widgets/emoteshortcutcontainer.h @@ -24,7 +24,7 @@ #include "gui/widgets/shortcutcontainer.h" -#include "resources/emotedb.h" +#include "resources/db/emotedb.h" #include diff --git a/src/gui/widgets/itemlinkhandler.cpp b/src/gui/widgets/itemlinkhandler.cpp index 572e4dbf2..804177a0a 100644 --- a/src/gui/widgets/itemlinkhandler.cpp +++ b/src/gui/widgets/itemlinkhandler.cpp @@ -33,7 +33,7 @@ #include "utils/process.h" #include "utils/stringutils.h" -#include "resources/itemdb.h" +#include "resources/db/itemdb.h" #include diff --git a/src/gui/widgets/tabs/chattab.cpp b/src/gui/widgets/tabs/chattab.cpp index 2c0628581..b7f8a1a44 100644 --- a/src/gui/widgets/tabs/chattab.cpp +++ b/src/gui/widgets/tabs/chattab.cpp @@ -41,7 +41,8 @@ #include "net/net.h" #include "resources/iteminfo.h" -#include "resources/itemdb.h" + +#include "resources/db/itemdb.h" #include "utils/gettext.h" diff --git a/src/gui/windows/charcreatedialog.cpp b/src/gui/windows/charcreatedialog.cpp index 53f1a5bce..3916a1ece 100644 --- a/src/gui/windows/charcreatedialog.cpp +++ b/src/gui/windows/charcreatedialog.cpp @@ -38,11 +38,12 @@ #include "net/net.h" -#include "resources/chardb.h" -#include "resources/colordb.h" -#include "resources/itemdb.h" #include "resources/iteminfo.h" +#include "resources/db/chardb.h" +#include "resources/db/colordb.h" +#include "resources/db/itemdb.h" + #include "utils/gettext.h" #include "debug.h" diff --git a/src/gui/windows/inventorywindow.cpp b/src/gui/windows/inventorywindow.cpp index 5c0b71edc..50d40dfbc 100644 --- a/src/gui/windows/inventorywindow.cpp +++ b/src/gui/windows/inventorywindow.cpp @@ -56,7 +56,7 @@ #include "net/inventoryhandler.h" #include "net/net.h" -#include "resources/itemdb.h" +#include "resources/db/itemdb.h" #include "utils/gettext.h" diff --git a/src/gui/windows/npcdialog.cpp b/src/gui/windows/npcdialog.cpp index 6e546ef61..ea5813084 100644 --- a/src/gui/windows/npcdialog.cpp +++ b/src/gui/windows/npcdialog.cpp @@ -48,10 +48,11 @@ #include "gui/widgets/playerbox.h" #include "gui/widgets/scrollarea.h" -#include "resources/avatardb.h" -#include "resources/npcdb.h" #include "resources/resourcemanager.h" +#include "resources/db/avatardb.h" +#include "resources/db/npcdb.h" + #include "net/net.h" #include "net/npchandler.h" diff --git a/src/gui/windows/textcommandeditor.cpp b/src/gui/windows/textcommandeditor.cpp index 1b4fb3440..e7bd8eb2c 100644 --- a/src/gui/windows/textcommandeditor.cpp +++ b/src/gui/windows/textcommandeditor.cpp @@ -36,9 +36,10 @@ #include "utils/gettext.h" -#include "resources/itemdb.h" #include "resources/iteminfo.h" +#include "resources/db/itemdb.h" + #include "debug.h" class IconsModal final : public gcn::ListModel diff --git a/src/item.h b/src/item.h index b9939c6e1..ceec48ebc 100644 --- a/src/item.h +++ b/src/item.h @@ -23,7 +23,7 @@ #ifndef ITEM_H #define ITEM_H -#include "resources/itemdb.h" +#include "resources/db/itemdb.h" #include diff --git a/src/net/ea/beinghandler.cpp b/src/net/ea/beinghandler.cpp index 956f4d20b..3392905f5 100644 --- a/src/net/ea/beinghandler.cpp +++ b/src/net/ea/beinghandler.cpp @@ -47,9 +47,10 @@ #include "gui/windows/outfitwindow.h" -#include "resources/itemdb.h" #include "resources/iteminfo.h" +#include "resources/db/itemdb.h" + #include "debug.h" namespace Ea diff --git a/src/net/ea/charserverhandler.cpp b/src/net/ea/charserverhandler.cpp index 4caa6ac3b..b59c2b536 100644 --- a/src/net/ea/charserverhandler.cpp +++ b/src/net/ea/charserverhandler.cpp @@ -38,7 +38,7 @@ #include "utils/dtor.h" #include "utils/gettext.h" -#include "resources/chardb.h" +#include "resources/db/chardb.h" #include "debug.h" diff --git a/src/net/ea/playerhandler.cpp b/src/net/ea/playerhandler.cpp index 03e62f45e..31359ae37 100644 --- a/src/net/ea/playerhandler.cpp +++ b/src/net/ea/playerhandler.cpp @@ -39,7 +39,7 @@ #include "gui/windows/skilldialog.h" #include "gui/windows/statuswindow.h" -#include "resources/deaddb.h" +#include "resources/db/deaddb.h" #include "net/net.h" diff --git a/src/net/eathena/beinghandler.cpp b/src/net/eathena/beinghandler.cpp index f136abfeb..685f19f16 100644 --- a/src/net/eathena/beinghandler.cpp +++ b/src/net/eathena/beinghandler.cpp @@ -40,9 +40,10 @@ #include "net/eathena/messageout.h" #include "net/eathena/protocol.h" -#include "resources/itemdb.h" #include "resources/iteminfo.h" +#include "resources/db/itemdb.h" + #include "debug.h" extern Net::BeingHandler *beingHandler; diff --git a/src/net/eathena/charserverhandler.cpp b/src/net/eathena/charserverhandler.cpp index 72b416319..d65b77144 100644 --- a/src/net/eathena/charserverhandler.cpp +++ b/src/net/eathena/charserverhandler.cpp @@ -33,9 +33,10 @@ #include "net/eathena/network.h" #include "net/eathena/protocol.h" -#include "resources/itemdb.h" #include "resources/iteminfo.h" +#include "resources/db/itemdb.h" + #include "utils/dtor.h" #include "debug.h" diff --git a/src/net/tmwa/beinghandler.cpp b/src/net/tmwa/beinghandler.cpp index c4ff7014f..cc72a3148 100644 --- a/src/net/tmwa/beinghandler.cpp +++ b/src/net/tmwa/beinghandler.cpp @@ -34,9 +34,10 @@ #include "net/tmwa/messageout.h" #include "net/tmwa/protocol.h" -#include "resources/itemdb.h" #include "resources/iteminfo.h" +#include "resources/db/itemdb.h" + #include "debug.h" extern Net::BeingHandler *beingHandler; diff --git a/src/net/tmwa/charserverhandler.cpp b/src/net/tmwa/charserverhandler.cpp index 584ec0c38..c20ac2513 100644 --- a/src/net/tmwa/charserverhandler.cpp +++ b/src/net/tmwa/charserverhandler.cpp @@ -33,9 +33,10 @@ #include "net/tmwa/network.h" #include "net/tmwa/protocol.h" -#include "resources/itemdb.h" #include "resources/iteminfo.h" +#include "resources/db/itemdb.h" + #include "utils/dtor.h" #include "debug.h" diff --git a/src/notifymanager.cpp b/src/notifymanager.cpp index 270df1872..94471d96a 100644 --- a/src/notifymanager.cpp +++ b/src/notifymanager.cpp @@ -32,7 +32,7 @@ #include "net/net.h" #include "net/partyhandler.h" -#include "resources/sounddb.h" +#include "resources/db/sounddb.h" namespace NotifyManager { diff --git a/src/resources/avatardb.cpp b/src/resources/avatardb.cpp deleted file mode 100644 index 2275f3576..000000000 --- a/src/resources/avatardb.cpp +++ /dev/null @@ -1,121 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2004-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011-2013 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 . - */ - -#include "resources/avatardb.h" - -#include "logger.h" - -#include "resources/beinginfo.h" - -#include "utils/dtor.h" -#include "utils/gettext.h" - -#include "configuration.h" - -#include "debug.h" - -namespace -{ - BeingInfos mAvatarInfos; - bool mLoaded = false; -} - -void AvatarDB::load() -{ - if (mLoaded) - unload(); - - XML::Document doc(paths.getStringValue("avatarsFile")); - const XmlNodePtr rootNode = doc.rootNode(); - - if (!rootNode || !xmlNameEqual(rootNode, "avatars")) - { - logger->log("Avatars Database: Error while loading %s!", - paths.getStringValue("avatarsFile").c_str()); - mLoaded = true; - return; - } - - for_each_xml_child_node(avatarNode, rootNode) - { - if (!xmlNameEqual(avatarNode, "avatar")) - continue; - - BeingInfo *const currentInfo = new BeingInfo; - - currentInfo->setName(XML::langProperty( - // TRANSLATORS: unknown info name - avatarNode, "name", _("unnamed"))); - - currentInfo->setTargetOffsetX(XML::getProperty(avatarNode, - "targetOffsetX", 0)); - - currentInfo->setTargetOffsetY(XML::getProperty(avatarNode, - "targetOffsetY", 0)); - - currentInfo->setWidth(XML::getProperty(avatarNode, - "width", 0)); - currentInfo->setHeight(XML::getProperty(avatarNode, - "height", 0)); - - SpriteDisplay display; - - // iterate s and s - for_each_xml_child_node(spriteNode, avatarNode) - { - if (xmlNameEqual(spriteNode, "sprite")) - { - if (!spriteNode->xmlChildrenNode) - continue; - - SpriteReference *const currentSprite = new SpriteReference; - currentSprite->sprite = reinterpret_cast( - spriteNode->xmlChildrenNode->content); - - currentSprite->variant = XML::getProperty( - spriteNode, "variant", 0); - display.sprites.push_back(currentSprite); - } - } - currentInfo->setDisplay(display); - - mAvatarInfos[XML::getProperty(avatarNode, "id", 0)] = currentInfo; - } - - mLoaded = true; -} - -void AvatarDB::unload() -{ - delete_all(mAvatarInfos); - mAvatarInfos.clear(); - mLoaded = false; -} - -BeingInfo *AvatarDB::get(const int id) -{ - BeingInfoIterator i = mAvatarInfos.find(id); - if (i == mAvatarInfos.end()) - return BeingInfo::unknown; - else - return i->second; -} diff --git a/src/resources/avatardb.h b/src/resources/avatardb.h deleted file mode 100644 index e5af78ff7..000000000 --- a/src/resources/avatardb.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2004-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011-2013 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 . - */ - -#ifndef RESOURCES_AVATARDB_H -#define RESOURCES_AVATARDB_H - -#include "localconsts.h" - -class BeingInfo; - -namespace AvatarDB -{ - void load(); - - void unload(); - - BeingInfo *get(const int id) A_WARN_UNUSED; -} - -#endif // RESOURCES_AVATARDB_H diff --git a/src/resources/beinginfo.h b/src/resources/beinginfo.h index d465dfa64..3d00471da 100644 --- a/src/resources/beinginfo.h +++ b/src/resources/beinginfo.h @@ -25,10 +25,11 @@ #include "being/actorsprite.h" -#include "resources/colordb.h" #include "resources/cursor.h" #include "resources/soundinfo.h" +#include "resources/db/colordb.h" + #include struct Attack final diff --git a/src/resources/chardb.cpp b/src/resources/chardb.cpp deleted file mode 100644 index 280ed6787..000000000 --- a/src/resources/chardb.cpp +++ /dev/null @@ -1,155 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2008 Aethyra Development Team - * Copyright (C) 2011-2013 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 . - */ - -#include "resources/chardb.h" - -#include "configuration.h" -#include "logger.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; - unsigned mMinLook = 0; - unsigned mMaxLook = 0; - std::vector mDefaultItems; -} // namespace - -void CharDB::load() -{ - if (mLoaded) - unload(); - - XML::Document *doc = new XML::Document( - paths.getStringValue("charCreationFile")); - const XmlNodePtr root = doc->rootNode(); - - if (!root || !xmlNameEqual(root, "chars")) - { - logger->log("CharDB: Failed to parse %s.", - paths.getStringValue("charCreationFile").c_str()); - delete doc; - return; - } - - for_each_xml_child_node(node, root) - { - if (xmlNameEqual(node, "haircolor")) - { - loadMinMax(node, &mMinHairColor, &mMaxHairColor); - } - else if (xmlNameEqual(node, "hairstyle")) - { - loadMinMax(node, &mMinHairStyle, &mMaxHairStyle); - } - else if (xmlNameEqual(node, "look")) - { - loadMinMax(node, &mMinLook, &mMaxLook); - } - else if (xmlNameEqual(node, "stat")) - { - loadMinMax(node, &mMinStat, &mMaxStat); - mSumStat = XML::getProperty(node, "sum", 0); - } - else if (xmlNameEqual(node, "item")) - { - const int id = XML::getProperty(node, "id", 0); - if (id > 0) - mDefaultItems.push_back(id); - } - } - - delete doc; - - mLoaded = true; -} - -void CharDB::loadMinMax(const XmlNodePtr node, - unsigned *const min, unsigned *const 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; -} - -unsigned CharDB::getMinLook() -{ - return mMinLook; -} - -unsigned CharDB::getMaxLook() -{ - return mMaxLook; -} - -const std::vector &CharDB::getDefaultItems() -{ - return mDefaultItems; -} diff --git a/src/resources/chardb.h b/src/resources/chardb.h deleted file mode 100644 index 3072d41ff..000000000 --- a/src/resources/chardb.h +++ /dev/null @@ -1,68 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2008 Aethyra Development Team - * Copyright (C) 2011-2013 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 . - */ - -#ifndef RESOURCES_CHARDB_H -#define RESOURCES_CHARDB_H - -#include "utils/xml.h" - -#include - -/** - * Char information database. - */ -namespace CharDB -{ - /** - * Loads the chars data. - */ - void load(); - - /** - * Clear the chars data - */ - void unload(); - - void loadMinMax(const XmlNodePtr node, - unsigned *const min, unsigned *const max); - - unsigned getMinHairColor() A_WARN_UNUSED; - - unsigned getMaxHairColor() A_WARN_UNUSED; - - unsigned getMinHairStyle() A_WARN_UNUSED; - - unsigned getMaxHairStyle() A_WARN_UNUSED; - - unsigned getMinStat() A_WARN_UNUSED; - - unsigned getMaxStat() A_WARN_UNUSED; - - unsigned getSumStat() A_WARN_UNUSED; - - unsigned getMinLook() A_WARN_UNUSED; - - unsigned getMaxLook() A_WARN_UNUSED; - - const std::vector &getDefaultItems() A_WARN_UNUSED; -} // namespace CharDB - -#endif // RESOURCES_CHARDB_H diff --git a/src/resources/colordb.cpp b/src/resources/colordb.cpp deleted file mode 100644 index d947a6523..000000000 --- a/src/resources/colordb.cpp +++ /dev/null @@ -1,200 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2008 Aethyra Development Team - * Copyright (C) 2011-2013 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 . - */ - -#include "resources/colordb.h" - -#include "client.h" -#include "configuration.h" -#include "logger.h" - -#include "utils/xml.h" - -#include "debug.h" - -namespace -{ - int mHairColorsSize = 0; - bool mLoaded = false; - std::string mFail("#ffffff"); - ColorDB::ColorLists mColorLists; -} - -void ColorDB::load() -{ - if (mLoaded) - unload(); - - loadHair(); - if (serverVersion >= 1) - loadColorLists(); - - const ColorListsIterator it = mColorLists.find("hair"); - if (it != mColorLists.end()) - mHairColorsSize = static_cast((*it).second.size()); - else - mHairColorsSize = 0; -} - -void ColorDB::loadHair() -{ - std::map colors; - const ColorListsIterator it = mColorLists.find("hair"); - - if (it != mColorLists.end()) - colors = it->second; - - XML::Document *doc = new XML::Document( - paths.getStringValue("hairColorFile")); - XmlNodePtr root = doc->rootNode(); - bool hairXml = true; - - if (!root || !xmlNameEqual(root, "colors")) - { - logger->log("Trying to fall back on " - + paths.getStringValue("hairColorFile2")); - - hairXml = false; - - delete doc; - doc = new XML::Document(paths.getStringValue("hairColorFile2")); - root = doc->rootNode(); - - if (!root || !xmlNameEqual(root, "colors")) - { - logger->log1("ColorDB: Failed to find any color files."); - colors[0] = ItemColor(0, "", ""); - mLoaded = true; - - delete doc; - - return; - } - } - - for_each_xml_child_node(node, root) - { - if (xmlNameEqual(node, "color")) - { - const int id = XML::getProperty(node, "id", 0); - - if (colors.find(id) != colors.end()) - logger->log("ColorDB: Redefinition of dye ID %d", id); - - colors[id] = ItemColor(id, XML::langProperty(node, "name", ""), - XML::getProperty(node, hairXml ? "value" : "dye", "#FFFFFF")); - } - } - - delete doc; - - mColorLists["hair"] = colors; - mLoaded = true; -} - -void ColorDB::loadColorLists() -{ - XML::Document *doc = new XML::Document( - paths.getStringValue("itemColorsFile")); - const XmlNodePtr root = doc->rootNode(); - if (!root) - { - delete doc; - return; - } - - for_each_xml_child_node(node, root) - { - if (xmlNameEqual(node, "list")) - { - const std::string name = XML::getProperty(node, "name", ""); - if (name.empty()) - continue; - - std::map colors; - const ColorListsIterator it = mColorLists.find(name); - - if (it != mColorLists.end()) - colors = it->second; - - for_each_xml_child_node(colorNode, node) - { - if (xmlNameEqual(colorNode, "color")) - { - ItemColor c(XML::getProperty(colorNode, "id", -1), - XML::langProperty(colorNode, "name", ""), - XML::getProperty(colorNode, "value", "")); - if (c.id > -1) - colors[c.id] = c; - } - } - mColorLists[name] = colors; - } - } - delete doc; -} - -void ColorDB::unload() -{ - logger->log1("Unloading color database..."); - - mColorLists.clear(); - mLoaded = false; -} - -std::string &ColorDB::getHairColorName(const int id) -{ - if (!mLoaded) - load(); - - const ColorListsIterator it = mColorLists.find("hair"); - if (it == mColorLists.end()) - { - logger->log1("ColorDB: Error, hair colors list empty"); - return mFail; - } - - const ColorIterator i = (*it).second.find(id); - - if (i == (*it).second.end()) - { - logger->log("ColorDB: Error, unknown dye ID# %d", id); - return mFail; - } - else - { - return i->second.name; - } -} - -int ColorDB::getHairSize() -{ - return mHairColorsSize; -} - -const std::map - *ColorDB::getColorsList(const std::string &name) -{ - const ColorListsIterator it = mColorLists.find(name); - - if (it != mColorLists.end()) - return &it->second; - return nullptr; -} diff --git a/src/resources/colordb.h b/src/resources/colordb.h deleted file mode 100644 index 3eec3625d..000000000 --- a/src/resources/colordb.h +++ /dev/null @@ -1,88 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2008 Aethyra Development Team - * Copyright (C) 2011-2013 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 . - */ - -#ifndef RESOURCES_COLORDB_H -#define RESOURCES_COLORDB_H - -#include -#include - -#include "localconsts.h" - -/** - * Color information database. - */ -namespace ColorDB -{ - class ItemColor final - { - public: - ItemColor(): - id(0), - name(), - color() - { } - - ItemColor(const int id0, const std::string &name0, - const std::string &color0) : - id(id0), - name(name0), - color(color0) - { - } - - int id; - std::string name; - std::string color; - }; - - /** - * Loads the color data from colors.xml. - */ - void load(); - - /** - * Loads the color data from colors.xml. - */ - void loadHair(); - - void loadColorLists(); - - /** - * Clear the color data - */ - void unload(); - - std::string &getHairColorName(const int id) A_WARN_UNUSED; - - int getHairSize() A_WARN_UNUSED; - - const std::map *getColorsList(const std::string - &name) A_WARN_UNUSED; - - // Color DB - typedef std::map Colors; - typedef Colors::iterator ColorIterator; - typedef std::map > ColorLists; - typedef ColorLists::iterator ColorListsIterator; -} // namespace ColorDB - -#endif // RESOURCES_COLORDB_H diff --git a/src/resources/db/avatardb.cpp b/src/resources/db/avatardb.cpp new file mode 100644 index 000000000..516234928 --- /dev/null +++ b/src/resources/db/avatardb.cpp @@ -0,0 +1,121 @@ +/* + * The ManaPlus Client + * Copyright (C) 2004-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011-2013 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 . + */ + +#include "resources/db/avatardb.h" + +#include "logger.h" + +#include "resources/beinginfo.h" + +#include "utils/dtor.h" +#include "utils/gettext.h" + +#include "configuration.h" + +#include "debug.h" + +namespace +{ + BeingInfos mAvatarInfos; + bool mLoaded = false; +} + +void AvatarDB::load() +{ + if (mLoaded) + unload(); + + XML::Document doc(paths.getStringValue("avatarsFile")); + const XmlNodePtr rootNode = doc.rootNode(); + + if (!rootNode || !xmlNameEqual(rootNode, "avatars")) + { + logger->log("Avatars Database: Error while loading %s!", + paths.getStringValue("avatarsFile").c_str()); + mLoaded = true; + return; + } + + for_each_xml_child_node(avatarNode, rootNode) + { + if (!xmlNameEqual(avatarNode, "avatar")) + continue; + + BeingInfo *const currentInfo = new BeingInfo; + + currentInfo->setName(XML::langProperty( + // TRANSLATORS: unknown info name + avatarNode, "name", _("unnamed"))); + + currentInfo->setTargetOffsetX(XML::getProperty(avatarNode, + "targetOffsetX", 0)); + + currentInfo->setTargetOffsetY(XML::getProperty(avatarNode, + "targetOffsetY", 0)); + + currentInfo->setWidth(XML::getProperty(avatarNode, + "width", 0)); + currentInfo->setHeight(XML::getProperty(avatarNode, + "height", 0)); + + SpriteDisplay display; + + // iterate s and s + for_each_xml_child_node(spriteNode, avatarNode) + { + if (xmlNameEqual(spriteNode, "sprite")) + { + if (!spriteNode->xmlChildrenNode) + continue; + + SpriteReference *const currentSprite = new SpriteReference; + currentSprite->sprite = reinterpret_cast( + spriteNode->xmlChildrenNode->content); + + currentSprite->variant = XML::getProperty( + spriteNode, "variant", 0); + display.sprites.push_back(currentSprite); + } + } + currentInfo->setDisplay(display); + + mAvatarInfos[XML::getProperty(avatarNode, "id", 0)] = currentInfo; + } + + mLoaded = true; +} + +void AvatarDB::unload() +{ + delete_all(mAvatarInfos); + mAvatarInfos.clear(); + mLoaded = false; +} + +BeingInfo *AvatarDB::get(const int id) +{ + BeingInfoIterator i = mAvatarInfos.find(id); + if (i == mAvatarInfos.end()) + return BeingInfo::unknown; + else + return i->second; +} diff --git a/src/resources/db/avatardb.h b/src/resources/db/avatardb.h new file mode 100644 index 000000000..e5af78ff7 --- /dev/null +++ b/src/resources/db/avatardb.h @@ -0,0 +1,39 @@ +/* + * The ManaPlus Client + * Copyright (C) 2004-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011-2013 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 . + */ + +#ifndef RESOURCES_AVATARDB_H +#define RESOURCES_AVATARDB_H + +#include "localconsts.h" + +class BeingInfo; + +namespace AvatarDB +{ + void load(); + + void unload(); + + BeingInfo *get(const int id) A_WARN_UNUSED; +} + +#endif // RESOURCES_AVATARDB_H diff --git a/src/resources/db/chardb.cpp b/src/resources/db/chardb.cpp new file mode 100644 index 000000000..1c2e0ec82 --- /dev/null +++ b/src/resources/db/chardb.cpp @@ -0,0 +1,155 @@ +/* + * The ManaPlus Client + * Copyright (C) 2008 Aethyra Development Team + * Copyright (C) 2011-2013 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 . + */ + +#include "resources/db/chardb.h" + +#include "configuration.h" +#include "logger.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; + unsigned mMinLook = 0; + unsigned mMaxLook = 0; + std::vector mDefaultItems; +} // namespace + +void CharDB::load() +{ + if (mLoaded) + unload(); + + XML::Document *doc = new XML::Document( + paths.getStringValue("charCreationFile")); + const XmlNodePtr root = doc->rootNode(); + + if (!root || !xmlNameEqual(root, "chars")) + { + logger->log("CharDB: Failed to parse %s.", + paths.getStringValue("charCreationFile").c_str()); + delete doc; + return; + } + + for_each_xml_child_node(node, root) + { + if (xmlNameEqual(node, "haircolor")) + { + loadMinMax(node, &mMinHairColor, &mMaxHairColor); + } + else if (xmlNameEqual(node, "hairstyle")) + { + loadMinMax(node, &mMinHairStyle, &mMaxHairStyle); + } + else if (xmlNameEqual(node, "look")) + { + loadMinMax(node, &mMinLook, &mMaxLook); + } + else if (xmlNameEqual(node, "stat")) + { + loadMinMax(node, &mMinStat, &mMaxStat); + mSumStat = XML::getProperty(node, "sum", 0); + } + else if (xmlNameEqual(node, "item")) + { + const int id = XML::getProperty(node, "id", 0); + if (id > 0) + mDefaultItems.push_back(id); + } + } + + delete doc; + + mLoaded = true; +} + +void CharDB::loadMinMax(const XmlNodePtr node, + unsigned *const min, unsigned *const 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; +} + +unsigned CharDB::getMinLook() +{ + return mMinLook; +} + +unsigned CharDB::getMaxLook() +{ + return mMaxLook; +} + +const std::vector &CharDB::getDefaultItems() +{ + return mDefaultItems; +} diff --git a/src/resources/db/chardb.h b/src/resources/db/chardb.h new file mode 100644 index 000000000..3072d41ff --- /dev/null +++ b/src/resources/db/chardb.h @@ -0,0 +1,68 @@ +/* + * The ManaPlus Client + * Copyright (C) 2008 Aethyra Development Team + * Copyright (C) 2011-2013 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 . + */ + +#ifndef RESOURCES_CHARDB_H +#define RESOURCES_CHARDB_H + +#include "utils/xml.h" + +#include + +/** + * Char information database. + */ +namespace CharDB +{ + /** + * Loads the chars data. + */ + void load(); + + /** + * Clear the chars data + */ + void unload(); + + void loadMinMax(const XmlNodePtr node, + unsigned *const min, unsigned *const max); + + unsigned getMinHairColor() A_WARN_UNUSED; + + unsigned getMaxHairColor() A_WARN_UNUSED; + + unsigned getMinHairStyle() A_WARN_UNUSED; + + unsigned getMaxHairStyle() A_WARN_UNUSED; + + unsigned getMinStat() A_WARN_UNUSED; + + unsigned getMaxStat() A_WARN_UNUSED; + + unsigned getSumStat() A_WARN_UNUSED; + + unsigned getMinLook() A_WARN_UNUSED; + + unsigned getMaxLook() A_WARN_UNUSED; + + const std::vector &getDefaultItems() A_WARN_UNUSED; +} // namespace CharDB + +#endif // RESOURCES_CHARDB_H diff --git a/src/resources/db/colordb.cpp b/src/resources/db/colordb.cpp new file mode 100644 index 000000000..0e81ff1c0 --- /dev/null +++ b/src/resources/db/colordb.cpp @@ -0,0 +1,200 @@ +/* + * The ManaPlus Client + * Copyright (C) 2008 Aethyra Development Team + * Copyright (C) 2011-2013 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 . + */ + +#include "resources/db/colordb.h" + +#include "client.h" +#include "configuration.h" +#include "logger.h" + +#include "utils/xml.h" + +#include "debug.h" + +namespace +{ + int mHairColorsSize = 0; + bool mLoaded = false; + std::string mFail("#ffffff"); + ColorDB::ColorLists mColorLists; +} + +void ColorDB::load() +{ + if (mLoaded) + unload(); + + loadHair(); + if (serverVersion >= 1) + loadColorLists(); + + const ColorListsIterator it = mColorLists.find("hair"); + if (it != mColorLists.end()) + mHairColorsSize = static_cast((*it).second.size()); + else + mHairColorsSize = 0; +} + +void ColorDB::loadHair() +{ + std::map colors; + const ColorListsIterator it = mColorLists.find("hair"); + + if (it != mColorLists.end()) + colors = it->second; + + XML::Document *doc = new XML::Document( + paths.getStringValue("hairColorFile")); + XmlNodePtr root = doc->rootNode(); + bool hairXml = true; + + if (!root || !xmlNameEqual(root, "colors")) + { + logger->log("Trying to fall back on " + + paths.getStringValue("hairColorFile2")); + + hairXml = false; + + delete doc; + doc = new XML::Document(paths.getStringValue("hairColorFile2")); + root = doc->rootNode(); + + if (!root || !xmlNameEqual(root, "colors")) + { + logger->log1("ColorDB: Failed to find any color files."); + colors[0] = ItemColor(0, "", ""); + mLoaded = true; + + delete doc; + + return; + } + } + + for_each_xml_child_node(node, root) + { + if (xmlNameEqual(node, "color")) + { + const int id = XML::getProperty(node, "id", 0); + + if (colors.find(id) != colors.end()) + logger->log("ColorDB: Redefinition of dye ID %d", id); + + colors[id] = ItemColor(id, XML::langProperty(node, "name", ""), + XML::getProperty(node, hairXml ? "value" : "dye", "#FFFFFF")); + } + } + + delete doc; + + mColorLists["hair"] = colors; + mLoaded = true; +} + +void ColorDB::loadColorLists() +{ + XML::Document *doc = new XML::Document( + paths.getStringValue("itemColorsFile")); + const XmlNodePtr root = doc->rootNode(); + if (!root) + { + delete doc; + return; + } + + for_each_xml_child_node(node, root) + { + if (xmlNameEqual(node, "list")) + { + const std::string name = XML::getProperty(node, "name", ""); + if (name.empty()) + continue; + + std::map colors; + const ColorListsIterator it = mColorLists.find(name); + + if (it != mColorLists.end()) + colors = it->second; + + for_each_xml_child_node(colorNode, node) + { + if (xmlNameEqual(colorNode, "color")) + { + ItemColor c(XML::getProperty(colorNode, "id", -1), + XML::langProperty(colorNode, "name", ""), + XML::getProperty(colorNode, "value", "")); + if (c.id > -1) + colors[c.id] = c; + } + } + mColorLists[name] = colors; + } + } + delete doc; +} + +void ColorDB::unload() +{ + logger->log1("Unloading color database..."); + + mColorLists.clear(); + mLoaded = false; +} + +std::string &ColorDB::getHairColorName(const int id) +{ + if (!mLoaded) + load(); + + const ColorListsIterator it = mColorLists.find("hair"); + if (it == mColorLists.end()) + { + logger->log1("ColorDB: Error, hair colors list empty"); + return mFail; + } + + const ColorIterator i = (*it).second.find(id); + + if (i == (*it).second.end()) + { + logger->log("ColorDB: Error, unknown dye ID# %d", id); + return mFail; + } + else + { + return i->second.name; + } +} + +int ColorDB::getHairSize() +{ + return mHairColorsSize; +} + +const std::map + *ColorDB::getColorsList(const std::string &name) +{ + const ColorListsIterator it = mColorLists.find(name); + + if (it != mColorLists.end()) + return &it->second; + return nullptr; +} diff --git a/src/resources/db/colordb.h b/src/resources/db/colordb.h new file mode 100644 index 000000000..3eec3625d --- /dev/null +++ b/src/resources/db/colordb.h @@ -0,0 +1,88 @@ +/* + * The ManaPlus Client + * Copyright (C) 2008 Aethyra Development Team + * Copyright (C) 2011-2013 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 . + */ + +#ifndef RESOURCES_COLORDB_H +#define RESOURCES_COLORDB_H + +#include +#include + +#include "localconsts.h" + +/** + * Color information database. + */ +namespace ColorDB +{ + class ItemColor final + { + public: + ItemColor(): + id(0), + name(), + color() + { } + + ItemColor(const int id0, const std::string &name0, + const std::string &color0) : + id(id0), + name(name0), + color(color0) + { + } + + int id; + std::string name; + std::string color; + }; + + /** + * Loads the color data from colors.xml. + */ + void load(); + + /** + * Loads the color data from colors.xml. + */ + void loadHair(); + + void loadColorLists(); + + /** + * Clear the color data + */ + void unload(); + + std::string &getHairColorName(const int id) A_WARN_UNUSED; + + int getHairSize() A_WARN_UNUSED; + + const std::map *getColorsList(const std::string + &name) A_WARN_UNUSED; + + // Color DB + typedef std::map Colors; + typedef Colors::iterator ColorIterator; + typedef std::map > ColorLists; + typedef ColorLists::iterator ColorListsIterator; +} // namespace ColorDB + +#endif // RESOURCES_COLORDB_H diff --git a/src/resources/db/deaddb.cpp b/src/resources/db/deaddb.cpp new file mode 100644 index 000000000..fa418ee3e --- /dev/null +++ b/src/resources/db/deaddb.cpp @@ -0,0 +1,81 @@ +/* + * The ManaPlus Client + * Copyright (C) 2011-2013 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 . + */ + +#include "resources/db/deaddb.h" + +#include "configuration.h" +#include "logger.h" + +#include "utils/translation/podict.h" + +#include "debug.h" + +namespace +{ + bool mLoaded = false; + std::vector mMessages; +} // namespace + +void DeadDB::load() +{ + if (mLoaded) + unload(); + + XML::Document *doc = new XML::Document( + paths.getStringValue("deadMessagesFile")); + const XmlNodePtr root = doc->rootNode(); + + if (!root || !xmlNameEqual(root, "messages")) + { + logger->log("DeadDB: Failed to parse %s.", + paths.getStringValue("deadMessagesFile").c_str()); + delete doc; + return; + } + + for_each_xml_child_node(node, root) + { + if (xmlNameEqual(node, "message")) + { + const char *const data = reinterpret_cast( + xmlNodeGetContent(node)); + if (!data || !*data) + continue; + mMessages.push_back(data); + } + } + + delete doc; + mLoaded = true; +} + +void DeadDB::unload() +{ + mMessages.clear(); + mLoaded = false; +} + +std::string DeadDB::getRandomString() +{ + const int sz = mMessages.size(); + if (!sz) + return std::string(); + return translator->getStr(mMessages[rand() % sz]); +} diff --git a/src/resources/db/deaddb.h b/src/resources/db/deaddb.h new file mode 100644 index 000000000..a0f6c7b9b --- /dev/null +++ b/src/resources/db/deaddb.h @@ -0,0 +1,44 @@ +/* + * The ManaPlus Client + * Copyright (C) 2011-2013 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 . + */ + +#ifndef RESOURCES_DEADDB_H +#define RESOURCES_DEADDB_H + +#include + +/** + * Char information database. + */ +namespace DeadDB +{ + /** + * Loads the chars data. + */ + void load(); + + /** + * Clear the chars data + */ + void unload(); + + std::string getRandomString(); +} // namespace DeadDB + +#endif // RESOURCES_DEADDB_H diff --git a/src/resources/db/emotedb.cpp b/src/resources/db/emotedb.cpp new file mode 100644 index 000000000..21a3aa0c6 --- /dev/null +++ b/src/resources/db/emotedb.cpp @@ -0,0 +1,257 @@ +/* + * Emote database + * Copyright (C) 2009 Aethyra Development Team + * Copyright (C) 2011-2013 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 . + */ + +#include "resources/db/emotedb.h" + +#include "animatedsprite.h" +#include "client.h" +#include "logger.h" + +#include "configuration.h" + +#include "debug.h" + +namespace +{ + EmoteInfos mEmoteInfos; + EmoteToEmote mEmotesAlt; + EmoteInfo mUnknown; + bool mLoaded = false; + int mLastEmote = 0; +} + +void EmoteDB::load() +{ + if (mLoaded) + unload(); + + mLastEmote = 0; + + EmoteSprite *const unknownSprite = new EmoteSprite; + unknownSprite->sprite = AnimatedSprite::load( + paths.getStringValue("spriteErrorFile")); + unknownSprite->name = "unknown"; + mUnknown.sprites.push_back(unknownSprite); + + logger->log1("Initializing emote database..."); + + XML::Document doc(paths.getStringValue("emotesFile")); + XmlNodePtr rootNode = doc.rootNode(); + + if (!rootNode || !xmlNameEqual(rootNode, "emotes")) + { + logger->log("Emote Database: Error while loading %s!", + paths.getStringValue("emotesFile").c_str()); + return; + } + + // iterate s + for_each_xml_child_node(emoteNode, rootNode) + { + if (!xmlNameEqual(emoteNode, "emote")) + continue; + + const int id = XML::getProperty(emoteNode, "id", -1); + // skip hight images + if (id > 19 || (client->isTmw() && id > 13)) + continue; + + if (id == -1) + { + logger->log("Emote Database: Emote with missing ID in %s!", + paths.getStringValue("emotesFile").c_str()); + continue; + } + + EmoteInfo *const currentInfo = new EmoteInfo; + currentInfo->time = XML::getProperty(emoteNode, "time", 500); + + for_each_xml_child_node(spriteNode, emoteNode) + { + if (!spriteNode->xmlChildrenNode) + continue; + + if (xmlNameEqual(spriteNode, "sprite")) + { + EmoteSprite *const currentSprite = new EmoteSprite; + currentSprite->sprite = AnimatedSprite::load( + paths.getStringValue("sprites").append(std::string( + reinterpret_cast( + spriteNode->xmlChildrenNode->content))), + XML::getProperty(spriteNode, "variant", 0)); + currentSprite->name = XML::langProperty( + spriteNode, "name", ""); + currentInfo->sprites.push_back(currentSprite); + } + else if (xmlNameEqual(spriteNode, "particlefx")) + { + currentInfo->particles.push_back(reinterpret_cast( + spriteNode->xmlChildrenNode->content)); + } + } + mEmoteInfos[id] = currentInfo; + if (id > mLastEmote) + mLastEmote = id; + } + + XML::Document doc2("graphics/sprites/manaplus_emotes.xml"); + rootNode = doc2.rootNode(); + + if (!rootNode || !xmlNameEqual(rootNode, "emotes")) + { + logger->log1("Emote Database: Error while loading" + " manaplus_emotes.xml!"); + return; + } + + // iterate s + for_each_xml_child_node(emoteNode, rootNode) + { + if (!xmlNameEqual(emoteNode, "emote")) + continue; + + const int id = XML::getProperty(emoteNode, "id", -1); + if (id == -1) + { + logger->log1("Emote Database: Emote with missing ID in " + "manaplus_emotes.xml!"); + continue; + } + const int altId = XML::getProperty(emoteNode, "altid", -1); + + EmoteInfo *const currentInfo = new EmoteInfo; + currentInfo->time = XML::getProperty(emoteNode, "time", 500); + + for_each_xml_child_node(spriteNode, emoteNode) + { + if (!spriteNode->xmlChildrenNode) + continue; + + if (xmlNameEqual(spriteNode, "sprite")) + { + EmoteSprite *const currentSprite = new EmoteSprite; + currentSprite->sprite = AnimatedSprite::load( + paths.getStringValue("sprites").append(std::string( + reinterpret_cast( + spriteNode->xmlChildrenNode->content))), + XML::getProperty(spriteNode, "variant", 0)); + currentSprite->name = XML::langProperty( + spriteNode, "name", ""); + currentInfo->sprites.push_back(currentSprite); + } + else if (xmlNameEqual(spriteNode, "particlefx")) + { + currentInfo->particles.push_back(reinterpret_cast( + spriteNode->xmlChildrenNode->content)); + } + } + mEmoteInfos[id] = currentInfo; + if (altId != -1) + mEmotesAlt[altId] = id; + + if (id > mLastEmote) + mLastEmote = id; + } + + mLoaded = true; +} + +void EmoteDB::unload() +{ + FOR_EACH (EmoteInfos::const_iterator, i, mEmoteInfos) + { + if (i->second) + { + std::list &sprites = i->second->sprites; + while (!sprites.empty()) + { + delete sprites.front()->sprite; + delete sprites.front(); + sprites.pop_front(); + } + delete i->second; + } + } + + mEmoteInfos.clear(); + + std::list &sprites = mUnknown.sprites; + while (!sprites.empty()) + { + delete sprites.front()->sprite; + delete sprites.front(); + sprites.pop_front(); + } + + mLoaded = false; +} + +const EmoteInfo *EmoteDB::get(const int id, const bool allowNull) +{ + const EmoteInfos::const_iterator i = mEmoteInfos.find(id); + + if (i == mEmoteInfos.end()) + { + if (allowNull) + return nullptr; + logger->log("EmoteDB: Warning, unknown emote ID %d requested", id); + return &mUnknown; + } + else + { + return i->second; + } +} + +const EmoteInfo *EmoteDB::get2(int id, const bool allowNull) +{ + const EmoteToEmote::const_iterator it = mEmotesAlt.find(id); + if (it != mEmotesAlt.end()) + id = (*it).second; + + const EmoteInfos::const_iterator i = mEmoteInfos.find(id); + + if (i == mEmoteInfos.end()) + { + if (allowNull) + return nullptr; + logger->log("EmoteDB: Warning, unknown emote ID %d requested", id); + return &mUnknown; + } + else + { + return i->second; + } +} + +const EmoteSprite *EmoteDB::getSprite(const int id, const bool allowNull) +{ + const EmoteInfo *const info = get(id, allowNull); + if (!info) + return nullptr; + + return info->sprites.front(); +} + +const int &EmoteDB::getLast() +{ + return mLastEmote; +} diff --git a/src/resources/db/emotedb.h b/src/resources/db/emotedb.h new file mode 100644 index 000000000..b0b232653 --- /dev/null +++ b/src/resources/db/emotedb.h @@ -0,0 +1,87 @@ +/* + * Emote database + * Copyright (C) 2009 Aethyra Development Team + * Copyright (C) 2011-2013 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 . + */ + +#ifndef RESOURCES_EMOTEDB_H +#define RESOURCES_EMOTEDB_H + +#include "utils/stringvector.h" + +#include +#include + +#include "localconsts.h" + +class AnimatedSprite; + +struct EmoteSprite final +{ + EmoteSprite() : + sprite(nullptr), + name() + { } + + A_DELETE_COPY(EmoteSprite) + + const AnimatedSprite *sprite; + std::string name; +}; + +struct EmoteInfo final +{ + EmoteInfo() : + sprites(), + particles(), + time(400) + { } + + A_DELETE_COPY(EmoteInfo) + + std::list sprites; + StringVect particles; + int time; +}; + +typedef std::map EmoteInfos; +typedef std::map EmoteToEmote; + +/** + * Emote information database. + */ +namespace EmoteDB +{ + void load(); + + void unload(); + + const EmoteInfo *get(const int id, + const bool allowNull = false) A_WARN_UNUSED; + + const EmoteInfo *get2(int id, const bool allowNull = false) A_WARN_UNUSED; + + const EmoteSprite *getSprite(const int id, const bool allowNull = false) + A_WARN_UNUSED; + + const int &getLast() A_WARN_UNUSED; + + typedef EmoteInfos::iterator EmoteInfosIterator; +} // namespace EmoteDB + +#endif // RESOURCES_EMOTEDB_H diff --git a/src/resources/db/itemdb.cpp b/src/resources/db/itemdb.cpp new file mode 100644 index 000000000..eeae4cfec --- /dev/null +++ b/src/resources/db/itemdb.cpp @@ -0,0 +1,889 @@ +/* + * The ManaPlus Client + * Copyright (C) 2004-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011-2013 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 . + */ + +#include "resources/db/itemdb.h" + +#include "client.h" +#include "configuration.h" +#include "logger.h" + +#include "resources/iteminfo.h" + +#include "utils/dtor.h" +#include "utils/gettext.h" + +#include "debug.h" + +namespace +{ + ItemDB::ItemInfos mItemInfos; + ItemDB::NamedItemInfos mNamedItemInfos; + ItemInfo *mUnknown; + bool mLoaded = false; + StringVect mTagNames; + std::map mTags; +} + +// Forward declarations +static void loadSpriteRef(ItemInfo *const itemInfo, const XmlNodePtr node); +static void loadSoundRef(ItemInfo *const itemInfo, const XmlNodePtr node); +static void loadFloorSprite(SpriteDisplay *const display, + const XmlNodePtr node); +static void loadReplaceSprite(ItemInfo *const itemInfo, + const XmlNodePtr replaceNode); +static void loadOrderSprite(ItemInfo *const itemInfo, const XmlNodePtr node, + const bool drawAfter); +static int parseSpriteName(const std::string &name); +static int parseDirectionName(const std::string &name); + +namespace +{ + struct FieldType + { + const char *name; + const char *description; + const bool sign; + }; + + static const FieldType fields[] = + { + // TRANSLATORS: item info label + { "attack", N_("Attack %s"), true }, + // TRANSLATORS: item info label + { "defense", N_("Defense %s"), true }, + // TRANSLATORS: item info label + { "hp", N_("HP %s"), true }, + // TRANSLATORS: item info label + { "mp", N_("MP %s"), true }, + // TRANSLATORS: item info label + { "level", N_("Level %s"), false } + }; +} // namespace + +static std::vector extraStats; + +void ItemDB::setStatsList(const std::vector &stats) +{ + extraStats = stats; +} + +static ItemType itemTypeFromString(const std::string &name) +{ + if (name == "generic" || name == "other") + { + return ITEM_UNUSABLE; + } + else if (name == "usable") + { + return ITEM_USABLE; + } + else if (name == "equip-1hand") + { + return ITEM_EQUIPMENT_ONE_HAND_WEAPON; + } + else if (name == "equip-2hand") + { + return ITEM_EQUIPMENT_TWO_HANDS_WEAPON; + } + else if (name == "equip-torso") + { + return ITEM_EQUIPMENT_TORSO; + } + else if (name == "equip-arms") + { + return ITEM_EQUIPMENT_ARMS; + } + else if (name == "equip-head") + { + return ITEM_EQUIPMENT_HEAD; + } + else if (name == "equip-legs") + { + return ITEM_EQUIPMENT_LEGS; + } + else if (name == "equip-shield") + { + return ITEM_EQUIPMENT_SHIELD; + } + else if (name == "equip-ring") + { + return ITEM_EQUIPMENT_RING; + } + else if (name == "equip-charm") + { + return ITEM_EQUIPMENT_CHARM; + } + else if (name == "equip-necklace" || name == "equip-neck") + { + return ITEM_EQUIPMENT_NECKLACE; + } + else if (name == "equip-feet") + { + return ITEM_EQUIPMENT_FEET; + } + else if (name == "equip-ammo") + { + return ITEM_EQUIPMENT_AMMO; + } + else if (name == "racesprite") + { + return ITEM_SPRITE_RACE; + } + else if (name == "hairsprite") + { + return ITEM_SPRITE_HAIR; + } + else + { + logger->log("Unknown item type: " + name); + return ITEM_UNUSABLE; + } +} + +void ItemDB::load() +{ + if (mLoaded) + unload(); + + int tagNum = 0; + logger->log1("Initializing item database..."); + + mTags.clear(); + mTagNames.clear(); + mTagNames.push_back("All"); + mTagNames.push_back("Usable"); + mTagNames.push_back("Unusable"); + mTagNames.push_back("Equipment"); + mTags["All"] = tagNum ++; + mTags["Usable"] = tagNum ++; + mTags["Unusable"] = tagNum ++; + mTags["Equipment"] = tagNum ++; + + mUnknown = new ItemInfo; + // TRANSLATORS: item name + mUnknown->setName(_("Unknown item")); + mUnknown->setDisplay(SpriteDisplay()); + std::string errFile = paths.getStringValue("spriteErrorFile"); + mUnknown->setSprite(errFile, GENDER_MALE, 0); + mUnknown->setSprite(errFile, GENDER_FEMALE, 0); + mUnknown->setSprite(errFile, GENDER_OTHER, 0); + mUnknown->addTag(mTags["All"]); + loadXmlFile(paths.getStringValue("itemsFile"), tagNum); +} + +void ItemDB::loadXmlFile(const std::string &fileName, int &tagNum) +{ + XML::Document doc(fileName); + const XmlNodePtr rootNode = doc.rootNode(); + + if (!rootNode || !xmlNameEqual(rootNode, "items")) + { + logger->log("ItemDB: Error while loading %s!", fileName.c_str()); + mLoaded = true; + return; + } + + for_each_xml_child_node(node, rootNode) + { + if (xmlNameEqual(node, "include")) + { + const std::string name = XML::getProperty(node, "name", ""); + if (!name.empty()) + loadXmlFile(name, tagNum); + continue; + } + if (!xmlNameEqual(node, "item")) + continue; + + const int id = XML::getProperty(node, "id", 0); + + if (id == 0) + { + logger->log("ItemDB: Invalid or missing item ID in %s!", + fileName.c_str()); + continue; + } + else if (mItemInfos.find(id) != mItemInfos.end()) + { + logger->log("ItemDB: Redefinition of item ID %d", id); + } + + const std::string typeStr = XML::getProperty(node, "type", "other"); + const int weight = XML::getProperty(node, "weight", 0); + const int view = XML::getProperty(node, "view", 0); + + std::string name = XML::langProperty(node, "name", ""); + std::string image = XML::getProperty(node, "image", ""); + std::string floor = XML::getProperty(node, "floor", ""); + std::string description = XML::langProperty(node, "description", ""); + std::string attackAction = XML::getProperty(node, "attack-action", ""); + std::string skyAttackAction = XML::getProperty( + node, "skyattack-action", ""); + std::string waterAttackAction = XML::getProperty( + node, "waterattack-action", ""); + std::string drawBefore = XML::getProperty(node, "drawBefore", ""); + std::string drawAfter = XML::getProperty(node, "drawAfter", ""); + const int pet = XML::getProperty(node, "pet", 0); + const int maxFloorOffset = XML::getIntProperty( + node, "maxFloorOffset", 32, 0, 32); + std::string colors; + if (serverVersion >= 1) + { + colors = XML::getProperty(node, "colors", ""); + + // check for empty hair palete + if (colors.empty() && id <= -1 && id > -100) + colors = "hair"; + } + else + { + if (id <= -1 && id > -100) + colors = "hair"; + else + colors.clear(); + } + + std::string tags[3]; + tags[0] = XML::getProperty(node, "tag", + XML::getProperty(node, "tag1", "")); + tags[1] = XML::getProperty(node, "tag2", ""); + tags[2] = XML::getProperty(node, "tag3", ""); + + const int drawPriority = XML::getProperty(node, "drawPriority", 0); + + const int attackRange = XML::getProperty(node, "attack-range", 0); + std::string missileParticle = XML::getProperty( + node, "missile-particle", ""); + const int hitEffectId = XML::getProperty(node, "hit-effect-id", + paths.getIntValue("hitEffectId")); + const int criticalEffectId = XML::getProperty( + node, "critical-hit-effect-id", + paths.getIntValue("criticalHitEffectId")); + const int missEffectId = XML::getProperty(node, "miss-effect-id", + paths.getIntValue("missEffectId")); + + SpriteDisplay display; + display.image = image; + if (floor != "") + display.floor = floor; + else + display.floor = image; + + ItemInfo *const itemInfo = new ItemInfo; + itemInfo->setId(id); + // TRANSLATORS: item info name + itemInfo->setName(name.empty() ? _("unnamed") : name); + itemInfo->setDescription(description); + itemInfo->setType(itemTypeFromString(typeStr)); + itemInfo->addTag(mTags["All"]); + itemInfo->setPet(pet); + itemInfo->setProtected(XML::getBoolProperty( + node, "sellProtected", false)); + + switch (itemInfo->getType()) + { + case ITEM_USABLE: + itemInfo->addTag(mTags["Usable"]); + break; + case ITEM_UNUSABLE: + itemInfo->addTag(mTags["Unusable"]); + break; + default: + case ITEM_EQUIPMENT_ONE_HAND_WEAPON: + case ITEM_EQUIPMENT_TWO_HANDS_WEAPON: + case ITEM_EQUIPMENT_TORSO: + case ITEM_EQUIPMENT_ARMS: + case ITEM_EQUIPMENT_HEAD: + case ITEM_EQUIPMENT_LEGS: + case ITEM_EQUIPMENT_SHIELD: + case ITEM_EQUIPMENT_RING: + case ITEM_EQUIPMENT_NECKLACE: + case ITEM_EQUIPMENT_FEET: + case ITEM_EQUIPMENT_AMMO: + case ITEM_EQUIPMENT_CHARM: + case ITEM_SPRITE_RACE: + case ITEM_SPRITE_HAIR: + itemInfo->addTag(mTags["Equipment"]); + break; + } + for (int f = 0; f < 3; f++) + { + if (tags[f] != "") + { + if (mTags.find(tags[f]) == mTags.end()) + { + mTagNames.push_back(tags[f]); + mTags[tags[f]] = tagNum ++; + } + itemInfo->addTag(mTags[tags[f]]); + } + } + + itemInfo->setView(view); + itemInfo->setWeight(weight); + itemInfo->setAttackAction(attackAction); + itemInfo->setSkyAttackAction(skyAttackAction); + itemInfo->setWaterAttackAction(waterAttackAction); + itemInfo->setAttackRange(attackRange); + itemInfo->setMissileParticleFile(missileParticle); + itemInfo->setHitEffectId(hitEffectId); + itemInfo->setCriticalHitEffectId(criticalEffectId); + itemInfo->setMissEffectId(missEffectId); + itemInfo->setDrawBefore(-1, parseSpriteName(drawBefore)); + itemInfo->setDrawAfter(-1, parseSpriteName(drawAfter)); + itemInfo->setDrawPriority(-1, drawPriority); + itemInfo->setColorsList(colors); + itemInfo->setMaxFloorOffset(maxFloorOffset); + itemInfo->setPickupCursor(XML::getProperty( + node, "pickupCursor", "pickup")); + + std::string effect; + for (size_t i = 0; i < sizeof(fields) / sizeof(fields[0]); ++ i) + { + std::string value = XML::getProperty(node, fields[i].name, ""); + if (value.empty()) + continue; + if (!effect.empty()) + effect.append(" / "); + if (fields[i].sign && isDigit(value)) + value = "+" + value; + effect.append(strprintf(gettext(fields[i].description), + value.c_str())); + } + FOR_EACH (std::vector::const_iterator, it, extraStats) + { + std::string value = XML::getProperty( + node, it->tag.c_str(), ""); + if (value.empty()) + continue; + if (!effect.empty()) + effect.append(" / "); + if (isDigit(value)) + value = "+" + value; + effect.append(strprintf(it->format.c_str(), value.c_str())); + } + std::string temp = XML::langProperty(node, "effect", ""); + if (!effect.empty() && !temp.empty()) + effect.append(" / "); + effect.append(temp); + itemInfo->setEffect(effect); + + for_each_xml_child_node(itemChild, node) + { + if (xmlNameEqual(itemChild, "sprite")) + { + std::string attackParticle = XML::getProperty( + itemChild, "particle-effect", ""); + itemInfo->setParticleEffect(attackParticle); + + loadSpriteRef(itemInfo, itemChild); + } + else if (xmlNameEqual(itemChild, "sound")) + { + loadSoundRef(itemInfo, itemChild); + } + else if (xmlNameEqual(itemChild, "floor")) + { + loadFloorSprite(&display, itemChild); + } + else if (xmlNameEqual(itemChild, "replace")) + { + loadReplaceSprite(itemInfo, itemChild); + } + else if (xmlNameEqual(itemChild, "drawAfter")) + { + loadOrderSprite(itemInfo, itemChild, true); + } + else if (xmlNameEqual(itemChild, "drawBefore")) + { + loadOrderSprite(itemInfo, itemChild, false); + } + } + +/* + logger->log("start dump item: %d", id); + if (itemInfo->isRemoveSprites()) + { + for (int f = 0; f < 10; f ++) + { + logger->log("dir: %d", f); + SpriteToItemMap *const spriteToItems + = itemInfo->getSpriteToItemReplaceMap(f); + if (!spriteToItems) + { + logger->log("null"); + continue; + } + for (SpriteToItemMapCIter itr = spriteToItems->begin(), + itr_end = spriteToItems->end(); itr != itr_end; ++ itr) + { + const int remSprite = itr->first; + const std::map &itemReplacer = itr->second; + logger->log("sprite: %d", remSprite); + + for (std::map::const_iterator + repIt = itemReplacer.begin(), + repIt_end = itemReplacer.end(); + repIt != repIt_end; ++ repIt) + { + logger->log("from %d to %d", repIt->first, + repIt->second); + } + } + } + } + + logger->log("--------------------------------"); + logger->log("end dump item"); +*/ + + itemInfo->setDisplay(display); + + mItemInfos[id] = itemInfo; + if (!name.empty()) + { + temp = normalize(name); + + const NamedItemInfos::const_iterator + itr = mNamedItemInfos.find(temp); + if (itr == mNamedItemInfos.end()) + { + mNamedItemInfos[temp] = itemInfo; + } + else + { + logger->log("ItemDB: Duplicate name of item found item %d", + id); + } + } + + if (!attackAction.empty()) + { + if (attackRange == 0) + { + logger->log("ItemDB: Missing attack range from weapon %i!", + id); + } + } + +#define CHECK_PARAM(param, error_value) \ + if (param == error_value) \ + logger->log("ItemDB: Missing " #param " attribute for item %i!", \ + id) + + if (id >= 0 && typeStr != "other") + { + CHECK_PARAM(name, ""); + CHECK_PARAM(description, ""); + CHECK_PARAM(image, ""); + } +#undef CHECK_PARAM + } + + mLoaded = true; +} + +const StringVect &ItemDB::getTags() +{ + return mTagNames; +} + +int ItemDB::getTagId(const std::string &tagName) +{ + return mTags[tagName]; +} + +void ItemDB::unload() +{ + logger->log1("Unloading item database..."); + + delete mUnknown; + mUnknown = nullptr; + + delete_all(mItemInfos); + mItemInfos.clear(); + mNamedItemInfos.clear(); + mTags.clear(); + mTagNames.clear(); + mLoaded = false; +} + +bool ItemDB::exists(const int id) +{ + if (!mLoaded) + return false; + + const ItemInfos::const_iterator i = mItemInfos.find(id); + return i != mItemInfos.end(); +} + +const ItemInfo &ItemDB::get(const int id) +{ + if (!mLoaded) + load(); + + const ItemInfos::const_iterator i = mItemInfos.find(id); + + if (i == mItemInfos.end()) + { + logger->log("ItemDB: Warning, unknown item ID# %d", id); + return *mUnknown; + } + + return *(i->second); +} + +const ItemInfo &ItemDB::get(const std::string &name) +{ + if (!mLoaded) + load(); + + const NamedItemInfos::const_iterator i = mNamedItemInfos.find( + normalize(name)); + + if (i == mNamedItemInfos.end()) + { + if (!name.empty()) + { + logger->log("ItemDB: Warning, unknown item name \"%s\"", + name.c_str()); + } + return *mUnknown; + } + + return *(i->second); +} + +const ItemDB::ItemInfos &ItemDB::getItemInfos() +{ + return mItemInfos; +} + +int parseSpriteName(const std::string &name) +{ + int id = -1; + if (name == "shoes" || name == "boot" || name == "boots") + { + id = 1; + } + else if (name == "bottomclothes" || name == "bottom" || name == "pants") + { + id = 2; + } + else if (name == "topclothes" || name == "top" + || name == "torso" || name == "body") + { + id = 3; + } + else if (name == "misc1") + { + id = 4; + } + else if (name == "misc2" || name == "scarf" || name == "scarfs") + { + id = 5; + } + else if (name == "hair") + { + id = 6; + } + else if (name == "hat" || name == "hats") + { + id = 7; + } + else if (name == "wings") + { + id = 8; + } + else if (name == "glove" || name == "gloves") + { + id = 9; + } + else if (name == "weapon" || name == "weapons") + { + id = 10; + } + else if (name == "shield" || name == "shields") + { + id = 11; + } + else if (name == "amulet" || name == "amulets") + { + id = 12; + } + else if (name == "ring" || name == "rings") + { + id = 13; + } + + return id; +} + +int parseDirectionName(const std::string &name) +{ + int id = -1; + if (name == "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") + { + 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; + } + // hack for died action. + else if (name == "died") + { + id = 9; + } + + return id; +} + +void loadSpriteRef(ItemInfo *const itemInfo, const XmlNodePtr node) +{ + const std::string gender = XML::getProperty(node, "gender", "unisex"); + const std::string filename = reinterpret_cast( + node->xmlChildrenNode->content); + + const int race = XML::getProperty(node, "race", 0); + if (gender == "male" || gender == "unisex") + itemInfo->setSprite(filename, GENDER_MALE, race); + if (gender == "female" || gender == "unisex") + itemInfo->setSprite(filename, GENDER_FEMALE, race); + if (gender == "other" || gender == "unisex") + itemInfo->setSprite(filename, GENDER_OTHER, race); +} + +void loadSoundRef(ItemInfo *const itemInfo, const XmlNodePtr node) +{ + const std::string event = XML::getProperty(node, "event", ""); + const std::string filename = reinterpret_cast( + node->xmlChildrenNode->content); + const int delay = XML::getProperty(node, "delay", 0); + + if (event == "hit") + { + itemInfo->addSound(SOUND_EVENT_HIT, filename, delay); + } + else if (event == "strike" || event == "miss") + { + itemInfo->addSound(SOUND_EVENT_MISS, filename, delay); + } + else + { + logger->log("ItemDB: Ignoring unknown sound event '%s'", + event.c_str()); + } +} + +void loadFloorSprite(SpriteDisplay *const display, const XmlNodePtr floorNode) +{ + for_each_xml_child_node(spriteNode, floorNode) + { + if (xmlNameEqual(spriteNode, "sprite")) + { + SpriteReference *const currentSprite = new SpriteReference; + currentSprite->sprite = reinterpret_cast( + spriteNode->xmlChildrenNode->content); + currentSprite->variant + = XML::getProperty(spriteNode, "variant", 0); + display->sprites.push_back(currentSprite); + } + else if (xmlNameEqual(spriteNode, "particlefx")) + { + display->particles.push_back(reinterpret_cast( + spriteNode->xmlChildrenNode->content)); + } + } +} + +void loadReplaceSprite(ItemInfo *const itemInfo, const XmlNodePtr replaceNode) +{ + const std::string removeSprite = XML::getProperty( + replaceNode, "sprite", ""); + const int direction = parseDirectionName(XML::getProperty( + replaceNode, "direction", "all")); + + itemInfo->setRemoveSprites(); + + switch (direction) + { + case -1: + { + for (int f = 0; f < 10; f ++) + { + std::map *const mapList + = itemInfo->addReplaceSprite( + parseSpriteName(removeSprite), f); + if (!mapList) + continue; + for_each_xml_child_node(itemNode, replaceNode) + { + if (xmlNameEqual(itemNode, "item")) + { + const int from = XML::getProperty(itemNode, "from", 0); + const int to = XML::getProperty(itemNode, "to", 1); + + (*mapList)[from] = to; + } + } + } + break; + } + case -2: + { + itemInfo->addReplaceSprite(parseSpriteName( + removeSprite), DIRECTION_DOWN); + itemInfo->addReplaceSprite(parseSpriteName( + removeSprite), DIRECTION_DOWNLEFT); + itemInfo->addReplaceSprite(parseSpriteName( + removeSprite), DIRECTION_DOWNRIGHT); + + for_each_xml_child_node(itemNode, replaceNode) + { + if (xmlNameEqual(itemNode, "item")) + { + const int from = XML::getProperty(itemNode, "from", 0); + const int to = XML::getProperty(itemNode, "to", 1); + std::map *mapList = itemInfo->addReplaceSprite( + parseSpriteName(removeSprite), DIRECTION_DOWN); + if (mapList) + (*mapList)[from] = to; + + mapList = itemInfo->addReplaceSprite(parseSpriteName( + removeSprite), DIRECTION_DOWNLEFT); + if (mapList) + (*mapList)[from] = to; + + mapList = itemInfo->addReplaceSprite(parseSpriteName( + removeSprite), DIRECTION_DOWNRIGHT); + if (mapList) + (*mapList)[from] = to; + } + } + break; + } + case -3: + { + itemInfo->addReplaceSprite(parseSpriteName( + removeSprite), DIRECTION_UP); + itemInfo->addReplaceSprite(parseSpriteName( + removeSprite), DIRECTION_UPLEFT); + itemInfo->addReplaceSprite(parseSpriteName( + removeSprite), DIRECTION_UPRIGHT); + + for_each_xml_child_node(itemNode, replaceNode) + { + if (xmlNameEqual(itemNode, "item")) + { + const int from = XML::getProperty(itemNode, "from", 0); + const int to = XML::getProperty(itemNode, "to", 1); + std::map *mapList = itemInfo->addReplaceSprite( + parseSpriteName(removeSprite), DIRECTION_UP); + if (mapList) + (*mapList)[from] = to; + + mapList = itemInfo->addReplaceSprite(parseSpriteName( + removeSprite), DIRECTION_UPLEFT); + if (mapList) + (*mapList)[from] = to; + + mapList = itemInfo->addReplaceSprite(parseSpriteName( + removeSprite), DIRECTION_UPRIGHT); + if (mapList) + (*mapList)[from] = to; + } + } + break; + } + default: + { + std::map *const mapList = itemInfo->addReplaceSprite( + parseSpriteName(removeSprite), direction); + if (!mapList) + return; + for_each_xml_child_node(itemNode, replaceNode) + { + if (xmlNameEqual(itemNode, "item")) + { + const int from = XML::getProperty(itemNode, "from", 0); + const int to = XML::getProperty(itemNode, "to", 1); + (*mapList)[from] = to; + } + } + break; + } + } +} + +void loadOrderSprite(ItemInfo *const itemInfo, const XmlNodePtr node, + const bool drawAfter) +{ + const int sprite = parseSpriteName(XML::getProperty(node, "name", "")); + const int priority = XML::getProperty(node, "priority", 0); + + const int direction = parseDirectionName(XML::getProperty( + node, "direction", "all")); + if (drawAfter) + itemInfo->setDrawAfter(direction, sprite); + else + itemInfo->setDrawBefore(direction, sprite); + itemInfo->setDrawPriority(direction, priority); +} diff --git a/src/resources/db/itemdb.h b/src/resources/db/itemdb.h new file mode 100644 index 000000000..1a5a4cce8 --- /dev/null +++ b/src/resources/db/itemdb.h @@ -0,0 +1,75 @@ +/* + * The ManaPlus Client + * Copyright (C) 2004-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011-2013 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 . + */ + +#ifndef RESOURCES_ITEMDB_H +#define RESOURCES_ITEMDB_H + +#include "utils/stringvector.h" + +#include + +#include "localconsts.h" + +class ItemInfo; + +/** + * Item information database. + */ +namespace ItemDB +{ + void load(); + + void unload(); + + void loadXmlFile(const std::string &fileName, int &tagNum); + + const StringVect &getTags(); + + bool exists(const int id) A_WARN_UNUSED; + + const ItemInfo &get(const int id) A_WARN_UNUSED; + const ItemInfo &get(const std::string &name) A_WARN_UNUSED; + + // Items database + typedef std::map ItemInfos; + typedef std::map NamedItemInfos; + + const std::map &getItemInfos(); + + int getTagId(const std::string &tagName) A_WARN_UNUSED; + + struct Stat + { + Stat(const std::string &tag0, + const std::string &format0) : + tag(tag0), + format(format0) + {} + + std::string tag; + std::string format; + }; + + void setStatsList(const std::vector &stats); +} // namespace ItemDB + +#endif // RESOURCES_ITEMDB_H diff --git a/src/resources/db/mapdb.cpp b/src/resources/db/mapdb.cpp new file mode 100644 index 000000000..13aac3032 --- /dev/null +++ b/src/resources/db/mapdb.cpp @@ -0,0 +1,176 @@ +/* + * Color database + * Copyright (C) 2008 Aethyra Development Team + * Copyright (C) 2011-2013 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 . + */ + +#include "resources/db/mapdb.h" + +#include "configuration.h" +#include "logger.h" + +#include "debug.h" + +namespace +{ + bool mLoaded = false; + MapDB::Maps mMaps; + MapDB::MapInfos mInfos; + MapDB::Atlases mAtlases; +} + +namespace MapDB +{ + void readMap(XmlNodePtr node); + void readAtlas(XmlNodePtr node); +} + +void MapDB::load() +{ + if (mLoaded) + unload(); + + loadRemap(); + loadInfo(); + mLoaded = true; +} + +void MapDB::loadRemap() +{ + XML::Document *const doc = new XML::Document( + paths.getStringValue("mapsRemapFile")); + + const XmlNodePtr root = doc->rootNode(); + if (!root) + { + delete doc; + return; + } + + for_each_xml_child_node(node, root) + { + if (xmlNameEqual(node, "map")) + { + const std::string name = XML::getProperty(node, "name", ""); + if (name.empty()) + continue; + + const std::string value = XML::getProperty(node, "value", ""); + if (value.empty()) + continue; + + mMaps[name] = value; + } + } + + delete doc; +} + +void MapDB::readMap(XmlNodePtr node) +{ + const std::string map = XML::getProperty(node, "name", ""); + if (map.empty()) + return; + + for_each_xml_child_node(childNode, node) + { + if (xmlNameEqual(childNode, "atlas")) + { + const std::string atlas = XML::getProperty(childNode, "name", ""); + if (atlas.empty()) + continue; + mInfos[map].atlas = atlas; + } + } +} + +void MapDB::readAtlas(XmlNodePtr node) +{ + const std::string atlas = XML::getProperty(node, "name", ""); + if (atlas.empty()) + return; + for_each_xml_child_node(childNode, node) + { + if (xmlNameEqual(childNode, "file")) + { + const std::string file = XML::getProperty(childNode, "name", ""); + if (file.empty()) + continue; + mAtlases[atlas].push_back(file); + } + } + if (atlas != "all") + { + const AtlasCIter &allAtlas = mAtlases.find("all"); + if (allAtlas != mAtlases.end()) + { + FOR_EACH (StringVectCIter, it, (*allAtlas).second) + mAtlases[atlas].push_back(*it); + } + } +} + +void MapDB::loadInfo() +{ + XML::Document *doc = new XML::Document(paths.getStringValue("mapsFile")); + const XmlNodePtr root = doc->rootNode(); + if (!root) + { + delete doc; + return; + } + + for_each_xml_child_node(node, root) + { + if (xmlNameEqual(node, "map")) + readMap(node); + else if (xmlNameEqual(node, "atlas")) + readAtlas(node); + } + delete doc; +} + +void MapDB::unload() +{ + logger->log1("Unloading map database..."); + + mMaps.clear(); + mLoaded = false; +} + +const std::string MapDB::getMapName(const std::string &name) +{ + const MapIterator it = mMaps.find(name); + + if (it != mMaps.end()) + return it->second; + return name; +} + +const MapDB::MapInfo *MapDB::getMapAtlas(const std::string &name) +{ + const MapInfoIter it = mInfos.find(name); + if (it == mInfos.end()) + return nullptr; + MapInfo *const info = &(*it).second; + const AtlasCIter it2 = mAtlases.find(info->atlas); + if (it2 == mAtlases.end()) + return nullptr; + info->files = &((*it2).second); + return info; +} diff --git a/src/resources/db/mapdb.h b/src/resources/db/mapdb.h new file mode 100644 index 000000000..9e0407f66 --- /dev/null +++ b/src/resources/db/mapdb.h @@ -0,0 +1,78 @@ +/* + * Color database + * Copyright (C) 2008 Aethyra Development Team + * Copyright (C) 2011-2013 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 . + */ + +#ifndef RESOURCES_MAPDB_H +#define RESOURCES_MAPDB_H + +#include "utils/stringvector.h" + +#include + +#include "localconsts.h" + +/** + * Color information database. + */ +namespace MapDB +{ + struct MapInfo + { + MapInfo() : + atlas(), + files(nullptr) + { + } + + std::string atlas; + const StringVect *files; + }; + + /** + * Loads the map remap data from maps\remap.xml. + */ + void load(); + + void loadRemap(); + + void loadInfo(); + + /** + * Clear the remap data + */ + void unload(); + + const std::string getMapName(const std::string &name) A_WARN_UNUSED; + + const MapInfo *getMapAtlas(const std::string &name) A_WARN_UNUSED; + + // Maps DB + typedef std::map Maps; + typedef Maps::iterator MapIterator; + // map to infos map + typedef std::map MapInfos; + typedef MapInfos::iterator MapInfoIter; + // atlas to files map + typedef std::map Atlases; + typedef Atlases::iterator AtlasIter; + typedef Atlases::const_iterator AtlasCIter; +} // namespace MapDB + +#endif // RESOURCES_MAPDB_H diff --git a/src/resources/db/monsterdb.cpp b/src/resources/db/monsterdb.cpp new file mode 100644 index 000000000..502c9cc2c --- /dev/null +++ b/src/resources/db/monsterdb.cpp @@ -0,0 +1,273 @@ +/* + * The ManaPlus Client + * Copyright (C) 2004-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011-2013 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 . + */ + +#include "resources/db/monsterdb.h" + +#include "logger.h" + +#include "resources/beingcommon.h" +#include "resources/beinginfo.h" + +#include "utils/dtor.h" +#include "utils/gettext.h" + +#include "configuration.h" + +#include "debug.h" + +static const unsigned int OLD_TMWATHENA_OFFSET = 1002; + +namespace +{ + BeingInfos mMonsterInfos; + bool mLoaded = false; +} + +void MonsterDB::load() +{ + if (mLoaded) + unload(); + + logger->log1("Initializing monster database..."); + loadXmlFile(paths.getStringValue("monstersFile")); + mLoaded = true; +} + +void MonsterDB::loadXmlFile(const std::string &fileName) +{ + XML::Document doc(fileName); + const XmlNodePtr rootNode = doc.rootNode(); + + if (!rootNode || !xmlNameEqual(rootNode, "monsters")) + { + logger->log("Monster Database: Error while loading %s!", + paths.getStringValue("monstersFile").c_str()); + mLoaded = true; + return; + } + +#ifdef MANASERV_SUPPORT + const int offset = XML::getProperty(rootNode, "offset", + Net::getNetworkType() != ServerInfo::MANASERV + ? OLD_TMWATHENA_OFFSET : 0); +#else + const int offset = XML::getProperty(rootNode, + "offset", OLD_TMWATHENA_OFFSET); +#endif + + // iterate s + for_each_xml_child_node(monsterNode, rootNode) + { + if (xmlNameEqual(monsterNode, "include")) + { + const std::string name = XML::getProperty(monsterNode, "name", ""); + if (!name.empty()) + loadXmlFile(name); + continue; + } + if (!xmlNameEqual(monsterNode, "monster")) + continue; + + BeingInfo *const currentInfo = new BeingInfo; + + currentInfo->setWalkMask(Map::BLOCKMASK_WALL + | Map::BLOCKMASK_CHARACTER | Map::BLOCKMASK_MONSTER); + currentInfo->setBlockType(Map::BLOCKTYPE_MONSTER); + + currentInfo->setName(XML::langProperty( + // TRANSLATORS: unknown info name + monsterNode, "name", _("unnamed"))); + + BeingCommon::readBasicAttributes(currentInfo, monsterNode, "attack"); + + currentInfo->setMaxHP(XML::getProperty(monsterNode, "maxHP", 0)); + + currentInfo->setDeadSortOffsetY(XML::getProperty( + monsterNode, "deadSortOffsetY", 31)); + + currentInfo->setColorsList(XML::getProperty(monsterNode, + "colors", "")); + + unsigned char block = 0; + std::string walkStr = XML::getProperty( + monsterNode, "walkType", "walk"); + if (walkStr == "walk") + block = Map::BLOCKMASK_WATER | Map::BLOCKMASK_AIR; + else if (walkStr == "fly") + block = 0; + else if (walkStr == "swim") + block = Map::BLOCKMASK_GROUND | Map::BLOCKMASK_AIR; + else if (walkStr == "walkswim" || walkStr == "swimwalk") + block = Map::BLOCKMASK_AIR; + + currentInfo->setWalkMask(static_cast( + Map::BLOCKMASK_WALL | block)); + + if (currentInfo->getMaxHP()) + currentInfo->setStaticMaxHP(true); + + SpriteDisplay display; + + // iterate s and s + for_each_xml_child_node(spriteNode, monsterNode) + { + if (xmlNameEqual(spriteNode, "sprite")) + { + if (!spriteNode->xmlChildrenNode) + continue; + + SpriteReference *const currentSprite = new SpriteReference; + currentSprite->sprite = reinterpret_cast( + spriteNode->xmlChildrenNode->content); + + currentSprite->variant = XML::getProperty( + spriteNode, "variant", 0); + display.sprites.push_back(currentSprite); + } + else if (xmlNameEqual(spriteNode, "sound")) + { + if (!spriteNode->xmlChildrenNode) + continue; + + const std::string event = XML::getProperty( + spriteNode, "event", ""); + const int delay = XML::getProperty( + spriteNode, "delay", 0); + const char *filename; + filename = reinterpret_cast( + spriteNode->xmlChildrenNode->content); + + if (event == "hit") + { + currentInfo->addSound(SOUND_EVENT_HIT, filename, delay); + } + else if (event == "miss") + { + currentInfo->addSound(SOUND_EVENT_MISS, filename, delay); + } + else if (event == "hurt") + { + currentInfo->addSound(SOUND_EVENT_HURT, filename, delay); + } + else if (event == "die") + { + currentInfo->addSound(SOUND_EVENT_DIE, filename, delay); + } + else if (event == "move") + { + currentInfo->addSound(SOUND_EVENT_MOVE, filename, delay); + } + else if (event == "sit") + { + currentInfo->addSound(SOUND_EVENT_SIT, filename, delay); + } + else if (event == "sittop") + { + currentInfo->addSound(SOUND_EVENT_SITTOP, filename, delay); + } + else if (event == "spawn") + { + currentInfo->addSound(SOUND_EVENT_SPAWN, filename, delay); + } + else + { + logger->log("MonsterDB: Warning, sound effect %s for " + "unknown event %s of monster %s", + filename, event.c_str(), + currentInfo->getName().c_str()); + } + } + else if (xmlNameEqual(spriteNode, "attack")) + { + const int id = XML::getProperty(spriteNode, "id", 0); + const int effectId = XML::getProperty( + spriteNode, "effect-id", paths.getIntValue("effectId")); + const int hitEffectId = XML::getProperty(spriteNode, + "hit-effect-id", paths.getIntValue("hitEffectId")); + const int criticalHitEffectId = XML::getProperty(spriteNode, + "critical-hit-effect-id", + paths.getIntValue("criticalHitEffectId")); + const int missEffectId = XML::getProperty(spriteNode, + "miss-effect-id", paths.getIntValue("missEffectId")); + + const std::string spriteAction = XML::getProperty( + spriteNode, "action", "attack"); + const std::string skySpriteAction = XML::getProperty( + spriteNode, "skyaction", "skyattack"); + const std::string waterSpriteAction = XML::getProperty( + spriteNode, "wateraction", "waterattack"); + + const std::string missileParticle = XML::getProperty( + spriteNode, "missile-particle", ""); + + currentInfo->addAttack(id, spriteAction, skySpriteAction, + waterSpriteAction, effectId, hitEffectId, + criticalHitEffectId, missEffectId, missileParticle); + } + else if (xmlNameEqual(spriteNode, "particlefx")) + { + if (!spriteNode->xmlChildrenNode) + continue; + + display.particles.push_back(reinterpret_cast( + spriteNode->xmlChildrenNode->content)); + } + } + currentInfo->setDisplay(display); + + mMonsterInfos[XML::getProperty( + monsterNode, "id", 0) + offset] = currentInfo; + } +} + +void MonsterDB::unload() +{ + delete_all(mMonsterInfos); + mMonsterInfos.clear(); + + mLoaded = false; +} + + +BeingInfo *MonsterDB::get(const int id) +{ + BeingInfoIterator i = mMonsterInfos.find(id); + + if (i == mMonsterInfos.end()) + { + i = mMonsterInfos.find(id + OLD_TMWATHENA_OFFSET); + if (i == mMonsterInfos.end()) + { + logger->log("MonsterDB: Warning, unknown monster ID %d requested", + id); + return BeingInfo::unknown; + } + else + { + return i->second; + } + } + else + { + return i->second; + } +} diff --git a/src/resources/db/monsterdb.h b/src/resources/db/monsterdb.h new file mode 100644 index 000000000..426228388 --- /dev/null +++ b/src/resources/db/monsterdb.h @@ -0,0 +1,46 @@ +/* + * The ManaPlus Client + * Copyright (C) 2004-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011-2013 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 . + */ + +#ifndef RESOURCES_MONSTERDB_H +#define RESOURCES_MONSTERDB_H + +#include "localconsts.h" + +#include + +class BeingInfo; + +/** + * Monster information database. + */ +namespace MonsterDB +{ + void load(); + + void unload(); + + void loadXmlFile(const std::string &fileName); + + BeingInfo *get(const int id) A_WARN_UNUSED; +} + +#endif // RESOURCES_MONSTERDB_H diff --git a/src/resources/db/npcdb.cpp b/src/resources/db/npcdb.cpp new file mode 100644 index 000000000..922b2e8ee --- /dev/null +++ b/src/resources/db/npcdb.cpp @@ -0,0 +1,158 @@ +/* + * The ManaPlus Client + * Copyright (C) 2008-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011-2013 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 . + */ + +#include "resources/db/npcdb.h" + +#include "logger.h" + +#include "resources/beingcommon.h" +#include "resources/beinginfo.h" + +#include "utils/dtor.h" +#include "configuration.h" + +#include "debug.h" + +namespace +{ + BeingInfos mNPCInfos; + bool mLoaded = false; +} + +extern int serverVersion; + +void NPCDB::load() +{ + if (mLoaded) + unload(); + + logger->log1("Initializing NPC database..."); + + loadXmlFile(paths.getStringValue("npcsFile")); + mLoaded = true; +} + +void NPCDB::loadXmlFile(const std::string &fileName) +{ + XML::Document doc(fileName); + const XmlNodePtr rootNode = doc.rootNode(); + + if (!rootNode || !xmlNameEqual(rootNode, "npcs")) + { + logger->log("NPC Database: Error while loading %s!", + paths.getStringValue("npcsFile").c_str()); + mLoaded = true; + return; + } + + // iterate s + for_each_xml_child_node(npcNode, rootNode) + { + if (xmlNameEqual(npcNode, "include")) + { + const std::string name = XML::getProperty(npcNode, "name", ""); + if (!name.empty()) + loadXmlFile(name); + continue; + } + + if (!xmlNameEqual(npcNode, "npc")) + continue; + + const int id = XML::getProperty(npcNode, "id", 0); + if (id == 0) + { + logger->log("NPC Database: NPC with missing ID in %s!", + paths.getStringValue("npcsFile").c_str()); + continue; + } + + BeingInfo *const currentInfo = new BeingInfo; + + currentInfo->setTargetSelection(XML::getBoolProperty(npcNode, + "targetSelection", true)); + + BeingCommon::readBasicAttributes(currentInfo, npcNode, "talk"); + + currentInfo->setDeadSortOffsetY(XML::getProperty(npcNode, + "deadSortOffsetY", 31)); + + currentInfo->setAvatarId(static_cast(XML::getProperty( + npcNode, "avatar", 0))); + + SpriteDisplay display; + for_each_xml_child_node(spriteNode, npcNode) + { + if (!spriteNode->xmlChildrenNode) + continue; + + if (xmlNameEqual(spriteNode, "sprite")) + { + SpriteReference *const currentSprite = new SpriteReference; + currentSprite->sprite = reinterpret_cast( + spriteNode->xmlChildrenNode->content); + currentSprite->variant = + XML::getProperty(spriteNode, "variant", 0); + display.sprites.push_back(currentSprite); + } + else if (xmlNameEqual(spriteNode, "particlefx")) + { + display.particles.push_back(reinterpret_cast( + spriteNode->xmlChildrenNode->content)); + } + } + + currentInfo->setDisplay(display); + mNPCInfos[id] = currentInfo; + } +} + +void NPCDB::unload() +{ + delete_all(mNPCInfos); + mNPCInfos.clear(); + + mLoaded = false; +} + +BeingInfo *NPCDB::get(const int id) +{ + const BeingInfoIterator i = mNPCInfos.find(id); + + if (i == mNPCInfos.end()) + { + logger->log("NPCDB: Warning, unknown NPC ID %d requested", id); + return BeingInfo::unknown; + } + else + { + return i->second; + } +} + +uint16_t NPCDB::getAvatarFor(const int id) +{ + const BeingInfo *const info = get(id); + if (!info) + return 0; + return info->getAvatarId(); +} diff --git a/src/resources/db/npcdb.h b/src/resources/db/npcdb.h new file mode 100644 index 000000000..9614c2052 --- /dev/null +++ b/src/resources/db/npcdb.h @@ -0,0 +1,50 @@ +/* + * The ManaPlus Client + * Copyright (C) 2008-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011-2013 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 . + */ + +#ifndef RESOURCES_NPCDB_H +#define RESOURCES_NPCDB_H + +#include + +#include + +#include "localconsts.h" + +class BeingInfo; + +/** + * NPC information database. + */ +namespace NPCDB +{ + void load(); + + void unload(); + + BeingInfo *get(const int id) A_WARN_UNUSED; + + uint16_t getAvatarFor(const int id); + + void loadXmlFile(const std::string &fileName); +} // namespace NPCDB + +#endif // RESOURCES_NPCDB_H diff --git a/src/resources/db/palettedb.cpp b/src/resources/db/palettedb.cpp new file mode 100644 index 000000000..91c3b1e34 --- /dev/null +++ b/src/resources/db/palettedb.cpp @@ -0,0 +1,108 @@ +/* + * The ManaPlus Client + * Copyright (C) 2013 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 . + */ + +#include "resources/db/palettedb.h" + +#include "logger.h" + +#include "resources/dyecolor.h" +#include "resources/resourcemanager.h" + +#include + +#include "debug.h" + +namespace +{ + bool mLoaded = false; + std::map mColors; + DyeColor mEmpty(0, 0, 0, 0); +} + +void PaletteDB::load() +{ + if (mLoaded) + unload(); + + loadPalette(); +} + +void PaletteDB::loadPalette() +{ + mLoaded = true; + StringVect lines; + ResourceManager::loadTextFile("palette.gpl", lines); + StringVectCIter it = lines.begin(); + if (it == lines.end()) + { + logger->log("missing GIMP palette file"); + return; + } + if (*it != "GIMP Palette") + { + logger->log("wrong GIMP palette file"); + return; + } + ++ it; + // skip header + while (it != lines.end()) + { + const std::string line = *it; + if (!line.empty() && line[0] == '#') + break; + ++ it; + } + + char name[101]; + + // process colors and ignore commets + while (it != lines.end()) + { + const std::string line = *it; + ++ it; + + if (line.empty() || line[0] == '#') + continue; + + unsigned int r; + unsigned int g; + unsigned int b; + + if (sscanf(line.c_str(), "%10u %10u %10u\t%100s", + &r, &g, &b, name) == 4) + { + mColors[name] = DyeColor(r, g, b); + } + } +} + +void PaletteDB::unload() +{ + mColors.clear(); +} + +const DyeColor &PaletteDB::getColor(const std::string &name) +{ + std::map::const_iterator it = mColors.find(name); + if (it != mColors.end()) + return (*it).second; + else + return mEmpty; +} diff --git a/src/resources/db/palettedb.h b/src/resources/db/palettedb.h new file mode 100644 index 000000000..307178693 --- /dev/null +++ b/src/resources/db/palettedb.h @@ -0,0 +1,39 @@ +/* + * The ManaPlus Client + * Copyright (C) 2013 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 . + */ + +#ifndef RESOURCES_PALETTEDB_H +#define RESOURCES_PALETTEDB_H + +#include "localconsts.h" + +#include + +struct DyeColor; + +namespace PaletteDB +{ + void load(); + void unload(); + void loadPalette(); + const DyeColor &getColor(const std::string &name); + +} // namespace PaletteDB + +#endif // RESOURCES_PALETTEDB_H diff --git a/src/resources/db/petdb.cpp b/src/resources/db/petdb.cpp new file mode 100644 index 000000000..169c8ee39 --- /dev/null +++ b/src/resources/db/petdb.cpp @@ -0,0 +1,137 @@ +/* + * The ManaPlus Client + * Copyright (C) 2008-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011-2013 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 . + */ + +#include "resources/db/petdb.h" + +#include "logger.h" + +#include "resources/beingcommon.h" +#include "resources/beinginfo.h" + +#include "utils/dtor.h" +#include "configuration.h" + +#include "debug.h" + +namespace +{ + BeingInfos mPETInfos; + bool mLoaded = false; +} + +extern int serverVersion; + +void PETDB::load() +{ + if (mLoaded) + unload(); + + logger->log1("Initializing PET database..."); + + XML::Document doc(paths.getStringValue("petsFile")); + const XmlNodePtr rootNode = doc.rootNode(); + + if (!rootNode || !xmlNameEqual(rootNode, "pets")) + { + logger->log("PET Database: Error while loading %s!", + paths.getStringValue("petsFile").c_str()); + mLoaded = true; + return; + } + + // iterate s + for_each_xml_child_node(petNode, rootNode) + { + if (!xmlNameEqual(petNode, "pet")) + continue; + + const int id = XML::getProperty(petNode, "id", 0); + if (id == 0) + { + logger->log("PET Database: PET with missing ID in %s!", + paths.getStringValue("petsFile").c_str()); + continue; + } + + BeingInfo *const currentInfo = new BeingInfo; + + currentInfo->setTargetSelection(XML::getBoolProperty(petNode, + "targetSelection", false)); + + BeingCommon::readBasicAttributes(currentInfo, petNode, "talk"); + + currentInfo->setDeadSortOffsetY(XML::getProperty(petNode, + "deadSortOffsetY", 31)); + + SpriteDisplay display; + for_each_xml_child_node(spriteNode, petNode) + { + if (!spriteNode->xmlChildrenNode) + continue; + + if (xmlNameEqual(spriteNode, "sprite")) + { + SpriteReference *const currentSprite = new SpriteReference; + currentSprite->sprite = reinterpret_cast( + spriteNode->xmlChildrenNode->content); + currentSprite->variant = + XML::getProperty(spriteNode, "variant", 0); + display.sprites.push_back(currentSprite); + } + else if (xmlNameEqual(spriteNode, "particlefx")) + { + std::string particlefx = reinterpret_cast( + spriteNode->xmlChildrenNode->content); + display.particles.push_back(particlefx); + } + } + + currentInfo->setDisplay(display); + + mPETInfos[id] = currentInfo; + } + + mLoaded = true; +} + +void PETDB::unload() +{ + delete_all(mPETInfos); + mPETInfos.clear(); + + mLoaded = false; +} + +BeingInfo *PETDB::get(const int id) +{ + const BeingInfoIterator i = mPETInfos.find(id); + + if (i == mPETInfos.end()) + { + logger->log("PETDB: Warning, unknown PET ID %d requested", id); + return BeingInfo::unknown; + } + else + { + return i->second; + } +} diff --git a/src/resources/db/petdb.h b/src/resources/db/petdb.h new file mode 100644 index 000000000..d5e4b5613 --- /dev/null +++ b/src/resources/db/petdb.h @@ -0,0 +1,39 @@ +/* + * The ManaPlus Client + * Copyright (C) 2008-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011-2013 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 . + */ + +#ifndef RESOURCES_PETDB_H +#define RESOURCES_PETDB_H + +#include "localconsts.h" + +class BeingInfo; + +namespace PETDB +{ + void load(); + + void unload(); + + BeingInfo *get(const int id) A_WARN_UNUSED; +} + +#endif // RESOURCES_PETDB_H diff --git a/src/resources/db/sounddb.cpp b/src/resources/db/sounddb.cpp new file mode 100644 index 000000000..f1e0ff93c --- /dev/null +++ b/src/resources/db/sounddb.cpp @@ -0,0 +1,79 @@ +/* + * The ManaPlus Client + * Copyright (C) 2013 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 . + */ + +#include "resources/db/sounddb.h" + +#include "configuration.h" +#include "notifications.h" +#include "notifymanager.h" + +#include "utils/xml.h" + +#include "debug.h" + +namespace +{ + std::string mDefault; + std::vector mSounds; +} + +void SoundDB::load() +{ + unload(); + + XML::Document *doc = new XML::Document(paths.getStringValue("soundsFile")); + const XmlNodePtr root = doc->rootNode(); + + if (!root || !xmlNameEqual(root, "sounds")) + { + delete doc; + return; + } + + for_each_xml_child_node(node, root) + { + if (xmlNameEqual(node, "sound")) + { + const std::string name = XML::getProperty(node, "name", ""); + const int id = NotifyManager::getIndexBySound(name); + if (id) + { + const std::string value = XML::getProperty(node, "value", ""); + mSounds[id] = value; + } + } + } + + delete doc; +} + +void SoundDB::unload() +{ + mSounds.resize(NotifyManager::TYPE_END); + for (int f = 0; f < NotifyManager::TYPE_END; f ++) + mSounds[f] = ""; +} + +std::string &SoundDB::getSound(const int id) +{ + if (id < 0 || id >= NotifyManager::TYPE_END) + return mDefault; + return mSounds[id]; +} diff --git a/src/resources/db/sounddb.h b/src/resources/db/sounddb.h new file mode 100644 index 000000000..356cd4e13 --- /dev/null +++ b/src/resources/db/sounddb.h @@ -0,0 +1,37 @@ +/* + * The ManaPlus Client + * Copyright (C) 2013 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 . + */ + +#ifndef RESOURCES_SOUNDDB_H +#define RESOURCES_SOUNDDB_H + +#include + +#include "localconsts.h" + +namespace SoundDB +{ + void load(); + + void unload(); + + std::string &getSound(const int id); +} + +#endif // RESOURCES_SOUNDDB_H diff --git a/src/resources/deaddb.cpp b/src/resources/deaddb.cpp deleted file mode 100644 index abfb511ff..000000000 --- a/src/resources/deaddb.cpp +++ /dev/null @@ -1,81 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2011-2013 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 . - */ - -#include "resources/deaddb.h" - -#include "configuration.h" -#include "logger.h" - -#include "utils/translation/podict.h" - -#include "debug.h" - -namespace -{ - bool mLoaded = false; - std::vector mMessages; -} // namespace - -void DeadDB::load() -{ - if (mLoaded) - unload(); - - XML::Document *doc = new XML::Document( - paths.getStringValue("deadMessagesFile")); - const XmlNodePtr root = doc->rootNode(); - - if (!root || !xmlNameEqual(root, "messages")) - { - logger->log("DeadDB: Failed to parse %s.", - paths.getStringValue("deadMessagesFile").c_str()); - delete doc; - return; - } - - for_each_xml_child_node(node, root) - { - if (xmlNameEqual(node, "message")) - { - const char *const data = reinterpret_cast( - xmlNodeGetContent(node)); - if (!data || !*data) - continue; - mMessages.push_back(data); - } - } - - delete doc; - mLoaded = true; -} - -void DeadDB::unload() -{ - mMessages.clear(); - mLoaded = false; -} - -std::string DeadDB::getRandomString() -{ - const int sz = mMessages.size(); - if (!sz) - return std::string(); - return translator->getStr(mMessages[rand() % sz]); -} diff --git a/src/resources/deaddb.h b/src/resources/deaddb.h deleted file mode 100644 index a0f6c7b9b..000000000 --- a/src/resources/deaddb.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2011-2013 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 . - */ - -#ifndef RESOURCES_DEADDB_H -#define RESOURCES_DEADDB_H - -#include - -/** - * Char information database. - */ -namespace DeadDB -{ - /** - * Loads the chars data. - */ - void load(); - - /** - * Clear the chars data - */ - void unload(); - - std::string getRandomString(); -} // namespace DeadDB - -#endif // RESOURCES_DEADDB_H diff --git a/src/resources/dye.cpp b/src/resources/dye.cpp index 7889d24aa..873c2a8fe 100644 --- a/src/resources/dye.cpp +++ b/src/resources/dye.cpp @@ -24,7 +24,7 @@ #include "logger.h" -#include "resources/palettedb.h" +#include "resources/db/palettedb.h" #include #include diff --git a/src/resources/emotedb.cpp b/src/resources/emotedb.cpp deleted file mode 100644 index 9a0c086bc..000000000 --- a/src/resources/emotedb.cpp +++ /dev/null @@ -1,257 +0,0 @@ -/* - * Emote database - * Copyright (C) 2009 Aethyra Development Team - * Copyright (C) 2011-2013 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 . - */ - -#include "resources/emotedb.h" - -#include "animatedsprite.h" -#include "client.h" -#include "logger.h" - -#include "configuration.h" - -#include "debug.h" - -namespace -{ - EmoteInfos mEmoteInfos; - EmoteToEmote mEmotesAlt; - EmoteInfo mUnknown; - bool mLoaded = false; - int mLastEmote = 0; -} - -void EmoteDB::load() -{ - if (mLoaded) - unload(); - - mLastEmote = 0; - - EmoteSprite *const unknownSprite = new EmoteSprite; - unknownSprite->sprite = AnimatedSprite::load( - paths.getStringValue("spriteErrorFile")); - unknownSprite->name = "unknown"; - mUnknown.sprites.push_back(unknownSprite); - - logger->log1("Initializing emote database..."); - - XML::Document doc(paths.getStringValue("emotesFile")); - XmlNodePtr rootNode = doc.rootNode(); - - if (!rootNode || !xmlNameEqual(rootNode, "emotes")) - { - logger->log("Emote Database: Error while loading %s!", - paths.getStringValue("emotesFile").c_str()); - return; - } - - // iterate s - for_each_xml_child_node(emoteNode, rootNode) - { - if (!xmlNameEqual(emoteNode, "emote")) - continue; - - const int id = XML::getProperty(emoteNode, "id", -1); - // skip hight images - if (id > 19 || (client->isTmw() && id > 13)) - continue; - - if (id == -1) - { - logger->log("Emote Database: Emote with missing ID in %s!", - paths.getStringValue("emotesFile").c_str()); - continue; - } - - EmoteInfo *const currentInfo = new EmoteInfo; - currentInfo->time = XML::getProperty(emoteNode, "time", 500); - - for_each_xml_child_node(spriteNode, emoteNode) - { - if (!spriteNode->xmlChildrenNode) - continue; - - if (xmlNameEqual(spriteNode, "sprite")) - { - EmoteSprite *const currentSprite = new EmoteSprite; - currentSprite->sprite = AnimatedSprite::load( - paths.getStringValue("sprites").append(std::string( - reinterpret_cast( - spriteNode->xmlChildrenNode->content))), - XML::getProperty(spriteNode, "variant", 0)); - currentSprite->name = XML::langProperty( - spriteNode, "name", ""); - currentInfo->sprites.push_back(currentSprite); - } - else if (xmlNameEqual(spriteNode, "particlefx")) - { - currentInfo->particles.push_back(reinterpret_cast( - spriteNode->xmlChildrenNode->content)); - } - } - mEmoteInfos[id] = currentInfo; - if (id > mLastEmote) - mLastEmote = id; - } - - XML::Document doc2("graphics/sprites/manaplus_emotes.xml"); - rootNode = doc2.rootNode(); - - if (!rootNode || !xmlNameEqual(rootNode, "emotes")) - { - logger->log1("Emote Database: Error while loading" - " manaplus_emotes.xml!"); - return; - } - - // iterate s - for_each_xml_child_node(emoteNode, rootNode) - { - if (!xmlNameEqual(emoteNode, "emote")) - continue; - - const int id = XML::getProperty(emoteNode, "id", -1); - if (id == -1) - { - logger->log1("Emote Database: Emote with missing ID in " - "manaplus_emotes.xml!"); - continue; - } - const int altId = XML::getProperty(emoteNode, "altid", -1); - - EmoteInfo *const currentInfo = new EmoteInfo; - currentInfo->time = XML::getProperty(emoteNode, "time", 500); - - for_each_xml_child_node(spriteNode, emoteNode) - { - if (!spriteNode->xmlChildrenNode) - continue; - - if (xmlNameEqual(spriteNode, "sprite")) - { - EmoteSprite *const currentSprite = new EmoteSprite; - currentSprite->sprite = AnimatedSprite::load( - paths.getStringValue("sprites").append(std::string( - reinterpret_cast( - spriteNode->xmlChildrenNode->content))), - XML::getProperty(spriteNode, "variant", 0)); - currentSprite->name = XML::langProperty( - spriteNode, "name", ""); - currentInfo->sprites.push_back(currentSprite); - } - else if (xmlNameEqual(spriteNode, "particlefx")) - { - currentInfo->particles.push_back(reinterpret_cast( - spriteNode->xmlChildrenNode->content)); - } - } - mEmoteInfos[id] = currentInfo; - if (altId != -1) - mEmotesAlt[altId] = id; - - if (id > mLastEmote) - mLastEmote = id; - } - - mLoaded = true; -} - -void EmoteDB::unload() -{ - FOR_EACH (EmoteInfos::const_iterator, i, mEmoteInfos) - { - if (i->second) - { - std::list &sprites = i->second->sprites; - while (!sprites.empty()) - { - delete sprites.front()->sprite; - delete sprites.front(); - sprites.pop_front(); - } - delete i->second; - } - } - - mEmoteInfos.clear(); - - std::list &sprites = mUnknown.sprites; - while (!sprites.empty()) - { - delete sprites.front()->sprite; - delete sprites.front(); - sprites.pop_front(); - } - - mLoaded = false; -} - -const EmoteInfo *EmoteDB::get(const int id, const bool allowNull) -{ - const EmoteInfos::const_iterator i = mEmoteInfos.find(id); - - if (i == mEmoteInfos.end()) - { - if (allowNull) - return nullptr; - logger->log("EmoteDB: Warning, unknown emote ID %d requested", id); - return &mUnknown; - } - else - { - return i->second; - } -} - -const EmoteInfo *EmoteDB::get2(int id, const bool allowNull) -{ - const EmoteToEmote::const_iterator it = mEmotesAlt.find(id); - if (it != mEmotesAlt.end()) - id = (*it).second; - - const EmoteInfos::const_iterator i = mEmoteInfos.find(id); - - if (i == mEmoteInfos.end()) - { - if (allowNull) - return nullptr; - logger->log("EmoteDB: Warning, unknown emote ID %d requested", id); - return &mUnknown; - } - else - { - return i->second; - } -} - -const EmoteSprite *EmoteDB::getSprite(const int id, const bool allowNull) -{ - const EmoteInfo *const info = get(id, allowNull); - if (!info) - return nullptr; - - return info->sprites.front(); -} - -const int &EmoteDB::getLast() -{ - return mLastEmote; -} diff --git a/src/resources/emotedb.h b/src/resources/emotedb.h deleted file mode 100644 index b0b232653..000000000 --- a/src/resources/emotedb.h +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Emote database - * Copyright (C) 2009 Aethyra Development Team - * Copyright (C) 2011-2013 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 . - */ - -#ifndef RESOURCES_EMOTEDB_H -#define RESOURCES_EMOTEDB_H - -#include "utils/stringvector.h" - -#include -#include - -#include "localconsts.h" - -class AnimatedSprite; - -struct EmoteSprite final -{ - EmoteSprite() : - sprite(nullptr), - name() - { } - - A_DELETE_COPY(EmoteSprite) - - const AnimatedSprite *sprite; - std::string name; -}; - -struct EmoteInfo final -{ - EmoteInfo() : - sprites(), - particles(), - time(400) - { } - - A_DELETE_COPY(EmoteInfo) - - std::list sprites; - StringVect particles; - int time; -}; - -typedef std::map EmoteInfos; -typedef std::map EmoteToEmote; - -/** - * Emote information database. - */ -namespace EmoteDB -{ - void load(); - - void unload(); - - const EmoteInfo *get(const int id, - const bool allowNull = false) A_WARN_UNUSED; - - const EmoteInfo *get2(int id, const bool allowNull = false) A_WARN_UNUSED; - - const EmoteSprite *getSprite(const int id, const bool allowNull = false) - A_WARN_UNUSED; - - const int &getLast() A_WARN_UNUSED; - - typedef EmoteInfos::iterator EmoteInfosIterator; -} // namespace EmoteDB - -#endif // RESOURCES_EMOTEDB_H diff --git a/src/resources/itemdb.cpp b/src/resources/itemdb.cpp deleted file mode 100644 index 513ec6488..000000000 --- a/src/resources/itemdb.cpp +++ /dev/null @@ -1,889 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2004-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011-2013 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 . - */ - -#include "resources/itemdb.h" - -#include "client.h" -#include "configuration.h" -#include "logger.h" - -#include "resources/iteminfo.h" - -#include "utils/dtor.h" -#include "utils/gettext.h" - -#include "debug.h" - -namespace -{ - ItemDB::ItemInfos mItemInfos; - ItemDB::NamedItemInfos mNamedItemInfos; - ItemInfo *mUnknown; - bool mLoaded = false; - StringVect mTagNames; - std::map mTags; -} - -// Forward declarations -static void loadSpriteRef(ItemInfo *const itemInfo, const XmlNodePtr node); -static void loadSoundRef(ItemInfo *const itemInfo, const XmlNodePtr node); -static void loadFloorSprite(SpriteDisplay *const display, - const XmlNodePtr node); -static void loadReplaceSprite(ItemInfo *const itemInfo, - const XmlNodePtr replaceNode); -static void loadOrderSprite(ItemInfo *const itemInfo, const XmlNodePtr node, - const bool drawAfter); -static int parseSpriteName(const std::string &name); -static int parseDirectionName(const std::string &name); - -namespace -{ - struct FieldType - { - const char *name; - const char *description; - const bool sign; - }; - - static const FieldType fields[] = - { - // TRANSLATORS: item info label - { "attack", N_("Attack %s"), true }, - // TRANSLATORS: item info label - { "defense", N_("Defense %s"), true }, - // TRANSLATORS: item info label - { "hp", N_("HP %s"), true }, - // TRANSLATORS: item info label - { "mp", N_("MP %s"), true }, - // TRANSLATORS: item info label - { "level", N_("Level %s"), false } - }; -} // namespace - -static std::vector extraStats; - -void ItemDB::setStatsList(const std::vector &stats) -{ - extraStats = stats; -} - -static ItemType itemTypeFromString(const std::string &name) -{ - if (name == "generic" || name == "other") - { - return ITEM_UNUSABLE; - } - else if (name == "usable") - { - return ITEM_USABLE; - } - else if (name == "equip-1hand") - { - return ITEM_EQUIPMENT_ONE_HAND_WEAPON; - } - else if (name == "equip-2hand") - { - return ITEM_EQUIPMENT_TWO_HANDS_WEAPON; - } - else if (name == "equip-torso") - { - return ITEM_EQUIPMENT_TORSO; - } - else if (name == "equip-arms") - { - return ITEM_EQUIPMENT_ARMS; - } - else if (name == "equip-head") - { - return ITEM_EQUIPMENT_HEAD; - } - else if (name == "equip-legs") - { - return ITEM_EQUIPMENT_LEGS; - } - else if (name == "equip-shield") - { - return ITEM_EQUIPMENT_SHIELD; - } - else if (name == "equip-ring") - { - return ITEM_EQUIPMENT_RING; - } - else if (name == "equip-charm") - { - return ITEM_EQUIPMENT_CHARM; - } - else if (name == "equip-necklace" || name == "equip-neck") - { - return ITEM_EQUIPMENT_NECKLACE; - } - else if (name == "equip-feet") - { - return ITEM_EQUIPMENT_FEET; - } - else if (name == "equip-ammo") - { - return ITEM_EQUIPMENT_AMMO; - } - else if (name == "racesprite") - { - return ITEM_SPRITE_RACE; - } - else if (name == "hairsprite") - { - return ITEM_SPRITE_HAIR; - } - else - { - logger->log("Unknown item type: " + name); - return ITEM_UNUSABLE; - } -} - -void ItemDB::load() -{ - if (mLoaded) - unload(); - - int tagNum = 0; - logger->log1("Initializing item database..."); - - mTags.clear(); - mTagNames.clear(); - mTagNames.push_back("All"); - mTagNames.push_back("Usable"); - mTagNames.push_back("Unusable"); - mTagNames.push_back("Equipment"); - mTags["All"] = tagNum ++; - mTags["Usable"] = tagNum ++; - mTags["Unusable"] = tagNum ++; - mTags["Equipment"] = tagNum ++; - - mUnknown = new ItemInfo; - // TRANSLATORS: item name - mUnknown->setName(_("Unknown item")); - mUnknown->setDisplay(SpriteDisplay()); - std::string errFile = paths.getStringValue("spriteErrorFile"); - mUnknown->setSprite(errFile, GENDER_MALE, 0); - mUnknown->setSprite(errFile, GENDER_FEMALE, 0); - mUnknown->setSprite(errFile, GENDER_OTHER, 0); - mUnknown->addTag(mTags["All"]); - loadXmlFile(paths.getStringValue("itemsFile"), tagNum); -} - -void ItemDB::loadXmlFile(const std::string &fileName, int &tagNum) -{ - XML::Document doc(fileName); - const XmlNodePtr rootNode = doc.rootNode(); - - if (!rootNode || !xmlNameEqual(rootNode, "items")) - { - logger->log("ItemDB: Error while loading %s!", fileName.c_str()); - mLoaded = true; - return; - } - - for_each_xml_child_node(node, rootNode) - { - if (xmlNameEqual(node, "include")) - { - const std::string name = XML::getProperty(node, "name", ""); - if (!name.empty()) - loadXmlFile(name, tagNum); - continue; - } - if (!xmlNameEqual(node, "item")) - continue; - - const int id = XML::getProperty(node, "id", 0); - - if (id == 0) - { - logger->log("ItemDB: Invalid or missing item ID in %s!", - fileName.c_str()); - continue; - } - else if (mItemInfos.find(id) != mItemInfos.end()) - { - logger->log("ItemDB: Redefinition of item ID %d", id); - } - - const std::string typeStr = XML::getProperty(node, "type", "other"); - const int weight = XML::getProperty(node, "weight", 0); - const int view = XML::getProperty(node, "view", 0); - - std::string name = XML::langProperty(node, "name", ""); - std::string image = XML::getProperty(node, "image", ""); - std::string floor = XML::getProperty(node, "floor", ""); - std::string description = XML::langProperty(node, "description", ""); - std::string attackAction = XML::getProperty(node, "attack-action", ""); - std::string skyAttackAction = XML::getProperty( - node, "skyattack-action", ""); - std::string waterAttackAction = XML::getProperty( - node, "waterattack-action", ""); - std::string drawBefore = XML::getProperty(node, "drawBefore", ""); - std::string drawAfter = XML::getProperty(node, "drawAfter", ""); - const int pet = XML::getProperty(node, "pet", 0); - const int maxFloorOffset = XML::getIntProperty( - node, "maxFloorOffset", 32, 0, 32); - std::string colors; - if (serverVersion >= 1) - { - colors = XML::getProperty(node, "colors", ""); - - // check for empty hair palete - if (colors.empty() && id <= -1 && id > -100) - colors = "hair"; - } - else - { - if (id <= -1 && id > -100) - colors = "hair"; - else - colors.clear(); - } - - std::string tags[3]; - tags[0] = XML::getProperty(node, "tag", - XML::getProperty(node, "tag1", "")); - tags[1] = XML::getProperty(node, "tag2", ""); - tags[2] = XML::getProperty(node, "tag3", ""); - - const int drawPriority = XML::getProperty(node, "drawPriority", 0); - - const int attackRange = XML::getProperty(node, "attack-range", 0); - std::string missileParticle = XML::getProperty( - node, "missile-particle", ""); - const int hitEffectId = XML::getProperty(node, "hit-effect-id", - paths.getIntValue("hitEffectId")); - const int criticalEffectId = XML::getProperty( - node, "critical-hit-effect-id", - paths.getIntValue("criticalHitEffectId")); - const int missEffectId = XML::getProperty(node, "miss-effect-id", - paths.getIntValue("missEffectId")); - - SpriteDisplay display; - display.image = image; - if (floor != "") - display.floor = floor; - else - display.floor = image; - - ItemInfo *const itemInfo = new ItemInfo; - itemInfo->setId(id); - // TRANSLATORS: item info name - itemInfo->setName(name.empty() ? _("unnamed") : name); - itemInfo->setDescription(description); - itemInfo->setType(itemTypeFromString(typeStr)); - itemInfo->addTag(mTags["All"]); - itemInfo->setPet(pet); - itemInfo->setProtected(XML::getBoolProperty( - node, "sellProtected", false)); - - switch (itemInfo->getType()) - { - case ITEM_USABLE: - itemInfo->addTag(mTags["Usable"]); - break; - case ITEM_UNUSABLE: - itemInfo->addTag(mTags["Unusable"]); - break; - default: - case ITEM_EQUIPMENT_ONE_HAND_WEAPON: - case ITEM_EQUIPMENT_TWO_HANDS_WEAPON: - case ITEM_EQUIPMENT_TORSO: - case ITEM_EQUIPMENT_ARMS: - case ITEM_EQUIPMENT_HEAD: - case ITEM_EQUIPMENT_LEGS: - case ITEM_EQUIPMENT_SHIELD: - case ITEM_EQUIPMENT_RING: - case ITEM_EQUIPMENT_NECKLACE: - case ITEM_EQUIPMENT_FEET: - case ITEM_EQUIPMENT_AMMO: - case ITEM_EQUIPMENT_CHARM: - case ITEM_SPRITE_RACE: - case ITEM_SPRITE_HAIR: - itemInfo->addTag(mTags["Equipment"]); - break; - } - for (int f = 0; f < 3; f++) - { - if (tags[f] != "") - { - if (mTags.find(tags[f]) == mTags.end()) - { - mTagNames.push_back(tags[f]); - mTags[tags[f]] = tagNum ++; - } - itemInfo->addTag(mTags[tags[f]]); - } - } - - itemInfo->setView(view); - itemInfo->setWeight(weight); - itemInfo->setAttackAction(attackAction); - itemInfo->setSkyAttackAction(skyAttackAction); - itemInfo->setWaterAttackAction(waterAttackAction); - itemInfo->setAttackRange(attackRange); - itemInfo->setMissileParticleFile(missileParticle); - itemInfo->setHitEffectId(hitEffectId); - itemInfo->setCriticalHitEffectId(criticalEffectId); - itemInfo->setMissEffectId(missEffectId); - itemInfo->setDrawBefore(-1, parseSpriteName(drawBefore)); - itemInfo->setDrawAfter(-1, parseSpriteName(drawAfter)); - itemInfo->setDrawPriority(-1, drawPriority); - itemInfo->setColorsList(colors); - itemInfo->setMaxFloorOffset(maxFloorOffset); - itemInfo->setPickupCursor(XML::getProperty( - node, "pickupCursor", "pickup")); - - std::string effect; - for (size_t i = 0; i < sizeof(fields) / sizeof(fields[0]); ++ i) - { - std::string value = XML::getProperty(node, fields[i].name, ""); - if (value.empty()) - continue; - if (!effect.empty()) - effect.append(" / "); - if (fields[i].sign && isDigit(value)) - value = "+" + value; - effect.append(strprintf(gettext(fields[i].description), - value.c_str())); - } - FOR_EACH (std::vector::const_iterator, it, extraStats) - { - std::string value = XML::getProperty( - node, it->tag.c_str(), ""); - if (value.empty()) - continue; - if (!effect.empty()) - effect.append(" / "); - if (isDigit(value)) - value = "+" + value; - effect.append(strprintf(it->format.c_str(), value.c_str())); - } - std::string temp = XML::langProperty(node, "effect", ""); - if (!effect.empty() && !temp.empty()) - effect.append(" / "); - effect.append(temp); - itemInfo->setEffect(effect); - - for_each_xml_child_node(itemChild, node) - { - if (xmlNameEqual(itemChild, "sprite")) - { - std::string attackParticle = XML::getProperty( - itemChild, "particle-effect", ""); - itemInfo->setParticleEffect(attackParticle); - - loadSpriteRef(itemInfo, itemChild); - } - else if (xmlNameEqual(itemChild, "sound")) - { - loadSoundRef(itemInfo, itemChild); - } - else if (xmlNameEqual(itemChild, "floor")) - { - loadFloorSprite(&display, itemChild); - } - else if (xmlNameEqual(itemChild, "replace")) - { - loadReplaceSprite(itemInfo, itemChild); - } - else if (xmlNameEqual(itemChild, "drawAfter")) - { - loadOrderSprite(itemInfo, itemChild, true); - } - else if (xmlNameEqual(itemChild, "drawBefore")) - { - loadOrderSprite(itemInfo, itemChild, false); - } - } - -/* - logger->log("start dump item: %d", id); - if (itemInfo->isRemoveSprites()) - { - for (int f = 0; f < 10; f ++) - { - logger->log("dir: %d", f); - SpriteToItemMap *const spriteToItems - = itemInfo->getSpriteToItemReplaceMap(f); - if (!spriteToItems) - { - logger->log("null"); - continue; - } - for (SpriteToItemMapCIter itr = spriteToItems->begin(), - itr_end = spriteToItems->end(); itr != itr_end; ++ itr) - { - const int remSprite = itr->first; - const std::map &itemReplacer = itr->second; - logger->log("sprite: %d", remSprite); - - for (std::map::const_iterator - repIt = itemReplacer.begin(), - repIt_end = itemReplacer.end(); - repIt != repIt_end; ++ repIt) - { - logger->log("from %d to %d", repIt->first, - repIt->second); - } - } - } - } - - logger->log("--------------------------------"); - logger->log("end dump item"); -*/ - - itemInfo->setDisplay(display); - - mItemInfos[id] = itemInfo; - if (!name.empty()) - { - temp = normalize(name); - - const NamedItemInfos::const_iterator - itr = mNamedItemInfos.find(temp); - if (itr == mNamedItemInfos.end()) - { - mNamedItemInfos[temp] = itemInfo; - } - else - { - logger->log("ItemDB: Duplicate name of item found item %d", - id); - } - } - - if (!attackAction.empty()) - { - if (attackRange == 0) - { - logger->log("ItemDB: Missing attack range from weapon %i!", - id); - } - } - -#define CHECK_PARAM(param, error_value) \ - if (param == error_value) \ - logger->log("ItemDB: Missing " #param " attribute for item %i!", \ - id) - - if (id >= 0 && typeStr != "other") - { - CHECK_PARAM(name, ""); - CHECK_PARAM(description, ""); - CHECK_PARAM(image, ""); - } -#undef CHECK_PARAM - } - - mLoaded = true; -} - -const StringVect &ItemDB::getTags() -{ - return mTagNames; -} - -int ItemDB::getTagId(const std::string &tagName) -{ - return mTags[tagName]; -} - -void ItemDB::unload() -{ - logger->log1("Unloading item database..."); - - delete mUnknown; - mUnknown = nullptr; - - delete_all(mItemInfos); - mItemInfos.clear(); - mNamedItemInfos.clear(); - mTags.clear(); - mTagNames.clear(); - mLoaded = false; -} - -bool ItemDB::exists(const int id) -{ - if (!mLoaded) - return false; - - const ItemInfos::const_iterator i = mItemInfos.find(id); - return i != mItemInfos.end(); -} - -const ItemInfo &ItemDB::get(const int id) -{ - if (!mLoaded) - load(); - - const ItemInfos::const_iterator i = mItemInfos.find(id); - - if (i == mItemInfos.end()) - { - logger->log("ItemDB: Warning, unknown item ID# %d", id); - return *mUnknown; - } - - return *(i->second); -} - -const ItemInfo &ItemDB::get(const std::string &name) -{ - if (!mLoaded) - load(); - - const NamedItemInfos::const_iterator i = mNamedItemInfos.find( - normalize(name)); - - if (i == mNamedItemInfos.end()) - { - if (!name.empty()) - { - logger->log("ItemDB: Warning, unknown item name \"%s\"", - name.c_str()); - } - return *mUnknown; - } - - return *(i->second); -} - -const ItemDB::ItemInfos &ItemDB::getItemInfos() -{ - return mItemInfos; -} - -int parseSpriteName(const std::string &name) -{ - int id = -1; - if (name == "shoes" || name == "boot" || name == "boots") - { - id = 1; - } - else if (name == "bottomclothes" || name == "bottom" || name == "pants") - { - id = 2; - } - else if (name == "topclothes" || name == "top" - || name == "torso" || name == "body") - { - id = 3; - } - else if (name == "misc1") - { - id = 4; - } - else if (name == "misc2" || name == "scarf" || name == "scarfs") - { - id = 5; - } - else if (name == "hair") - { - id = 6; - } - else if (name == "hat" || name == "hats") - { - id = 7; - } - else if (name == "wings") - { - id = 8; - } - else if (name == "glove" || name == "gloves") - { - id = 9; - } - else if (name == "weapon" || name == "weapons") - { - id = 10; - } - else if (name == "shield" || name == "shields") - { - id = 11; - } - else if (name == "amulet" || name == "amulets") - { - id = 12; - } - else if (name == "ring" || name == "rings") - { - id = 13; - } - - return id; -} - -int parseDirectionName(const std::string &name) -{ - int id = -1; - if (name == "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") - { - 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; - } - // hack for died action. - else if (name == "died") - { - id = 9; - } - - return id; -} - -void loadSpriteRef(ItemInfo *const itemInfo, const XmlNodePtr node) -{ - const std::string gender = XML::getProperty(node, "gender", "unisex"); - const std::string filename = reinterpret_cast( - node->xmlChildrenNode->content); - - const int race = XML::getProperty(node, "race", 0); - if (gender == "male" || gender == "unisex") - itemInfo->setSprite(filename, GENDER_MALE, race); - if (gender == "female" || gender == "unisex") - itemInfo->setSprite(filename, GENDER_FEMALE, race); - if (gender == "other" || gender == "unisex") - itemInfo->setSprite(filename, GENDER_OTHER, race); -} - -void loadSoundRef(ItemInfo *const itemInfo, const XmlNodePtr node) -{ - const std::string event = XML::getProperty(node, "event", ""); - const std::string filename = reinterpret_cast( - node->xmlChildrenNode->content); - const int delay = XML::getProperty(node, "delay", 0); - - if (event == "hit") - { - itemInfo->addSound(SOUND_EVENT_HIT, filename, delay); - } - else if (event == "strike" || event == "miss") - { - itemInfo->addSound(SOUND_EVENT_MISS, filename, delay); - } - else - { - logger->log("ItemDB: Ignoring unknown sound event '%s'", - event.c_str()); - } -} - -void loadFloorSprite(SpriteDisplay *const display, const XmlNodePtr floorNode) -{ - for_each_xml_child_node(spriteNode, floorNode) - { - if (xmlNameEqual(spriteNode, "sprite")) - { - SpriteReference *const currentSprite = new SpriteReference; - currentSprite->sprite = reinterpret_cast( - spriteNode->xmlChildrenNode->content); - currentSprite->variant - = XML::getProperty(spriteNode, "variant", 0); - display->sprites.push_back(currentSprite); - } - else if (xmlNameEqual(spriteNode, "particlefx")) - { - display->particles.push_back(reinterpret_cast( - spriteNode->xmlChildrenNode->content)); - } - } -} - -void loadReplaceSprite(ItemInfo *const itemInfo, const XmlNodePtr replaceNode) -{ - const std::string removeSprite = XML::getProperty( - replaceNode, "sprite", ""); - const int direction = parseDirectionName(XML::getProperty( - replaceNode, "direction", "all")); - - itemInfo->setRemoveSprites(); - - switch (direction) - { - case -1: - { - for (int f = 0; f < 10; f ++) - { - std::map *const mapList - = itemInfo->addReplaceSprite( - parseSpriteName(removeSprite), f); - if (!mapList) - continue; - for_each_xml_child_node(itemNode, replaceNode) - { - if (xmlNameEqual(itemNode, "item")) - { - const int from = XML::getProperty(itemNode, "from", 0); - const int to = XML::getProperty(itemNode, "to", 1); - - (*mapList)[from] = to; - } - } - } - break; - } - case -2: - { - itemInfo->addReplaceSprite(parseSpriteName( - removeSprite), DIRECTION_DOWN); - itemInfo->addReplaceSprite(parseSpriteName( - removeSprite), DIRECTION_DOWNLEFT); - itemInfo->addReplaceSprite(parseSpriteName( - removeSprite), DIRECTION_DOWNRIGHT); - - for_each_xml_child_node(itemNode, replaceNode) - { - if (xmlNameEqual(itemNode, "item")) - { - const int from = XML::getProperty(itemNode, "from", 0); - const int to = XML::getProperty(itemNode, "to", 1); - std::map *mapList = itemInfo->addReplaceSprite( - parseSpriteName(removeSprite), DIRECTION_DOWN); - if (mapList) - (*mapList)[from] = to; - - mapList = itemInfo->addReplaceSprite(parseSpriteName( - removeSprite), DIRECTION_DOWNLEFT); - if (mapList) - (*mapList)[from] = to; - - mapList = itemInfo->addReplaceSprite(parseSpriteName( - removeSprite), DIRECTION_DOWNRIGHT); - if (mapList) - (*mapList)[from] = to; - } - } - break; - } - case -3: - { - itemInfo->addReplaceSprite(parseSpriteName( - removeSprite), DIRECTION_UP); - itemInfo->addReplaceSprite(parseSpriteName( - removeSprite), DIRECTION_UPLEFT); - itemInfo->addReplaceSprite(parseSpriteName( - removeSprite), DIRECTION_UPRIGHT); - - for_each_xml_child_node(itemNode, replaceNode) - { - if (xmlNameEqual(itemNode, "item")) - { - const int from = XML::getProperty(itemNode, "from", 0); - const int to = XML::getProperty(itemNode, "to", 1); - std::map *mapList = itemInfo->addReplaceSprite( - parseSpriteName(removeSprite), DIRECTION_UP); - if (mapList) - (*mapList)[from] = to; - - mapList = itemInfo->addReplaceSprite(parseSpriteName( - removeSprite), DIRECTION_UPLEFT); - if (mapList) - (*mapList)[from] = to; - - mapList = itemInfo->addReplaceSprite(parseSpriteName( - removeSprite), DIRECTION_UPRIGHT); - if (mapList) - (*mapList)[from] = to; - } - } - break; - } - default: - { - std::map *const mapList = itemInfo->addReplaceSprite( - parseSpriteName(removeSprite), direction); - if (!mapList) - return; - for_each_xml_child_node(itemNode, replaceNode) - { - if (xmlNameEqual(itemNode, "item")) - { - const int from = XML::getProperty(itemNode, "from", 0); - const int to = XML::getProperty(itemNode, "to", 1); - (*mapList)[from] = to; - } - } - break; - } - } -} - -void loadOrderSprite(ItemInfo *const itemInfo, const XmlNodePtr node, - const bool drawAfter) -{ - const int sprite = parseSpriteName(XML::getProperty(node, "name", "")); - const int priority = XML::getProperty(node, "priority", 0); - - const int direction = parseDirectionName(XML::getProperty( - node, "direction", "all")); - if (drawAfter) - itemInfo->setDrawAfter(direction, sprite); - else - itemInfo->setDrawBefore(direction, sprite); - itemInfo->setDrawPriority(direction, priority); -} diff --git a/src/resources/itemdb.h b/src/resources/itemdb.h deleted file mode 100644 index 1a5a4cce8..000000000 --- a/src/resources/itemdb.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2004-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011-2013 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 . - */ - -#ifndef RESOURCES_ITEMDB_H -#define RESOURCES_ITEMDB_H - -#include "utils/stringvector.h" - -#include - -#include "localconsts.h" - -class ItemInfo; - -/** - * Item information database. - */ -namespace ItemDB -{ - void load(); - - void unload(); - - void loadXmlFile(const std::string &fileName, int &tagNum); - - const StringVect &getTags(); - - bool exists(const int id) A_WARN_UNUSED; - - const ItemInfo &get(const int id) A_WARN_UNUSED; - const ItemInfo &get(const std::string &name) A_WARN_UNUSED; - - // Items database - typedef std::map ItemInfos; - typedef std::map NamedItemInfos; - - const std::map &getItemInfos(); - - int getTagId(const std::string &tagName) A_WARN_UNUSED; - - struct Stat - { - Stat(const std::string &tag0, - const std::string &format0) : - tag(tag0), - format(format0) - {} - - std::string tag; - std::string format; - }; - - void setStatsList(const std::vector &stats); -} // namespace ItemDB - -#endif // RESOURCES_ITEMDB_H diff --git a/src/resources/iteminfo.cpp b/src/resources/iteminfo.cpp index dd86e3196..eb8014f3e 100644 --- a/src/resources/iteminfo.cpp +++ b/src/resources/iteminfo.cpp @@ -22,7 +22,7 @@ #include "resources/iteminfo.h" -#include "resources/itemdb.h" +#include "resources/db/itemdb.h" #include "configuration.h" diff --git a/src/resources/iteminfo.h b/src/resources/iteminfo.h index 71a6119af..b386e51f7 100644 --- a/src/resources/iteminfo.h +++ b/src/resources/iteminfo.h @@ -25,7 +25,7 @@ #include "being/being.h" -#include "resources/colordb.h" +#include "resources/db/colordb.h" #include diff --git a/src/resources/mapdb.cpp b/src/resources/mapdb.cpp deleted file mode 100644 index 61ebe6d17..000000000 --- a/src/resources/mapdb.cpp +++ /dev/null @@ -1,176 +0,0 @@ -/* - * Color database - * Copyright (C) 2008 Aethyra Development Team - * Copyright (C) 2011-2013 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 . - */ - -#include "resources/mapdb.h" - -#include "configuration.h" -#include "logger.h" - -#include "debug.h" - -namespace -{ - bool mLoaded = false; - MapDB::Maps mMaps; - MapDB::MapInfos mInfos; - MapDB::Atlases mAtlases; -} - -namespace MapDB -{ - void readMap(XmlNodePtr node); - void readAtlas(XmlNodePtr node); -} - -void MapDB::load() -{ - if (mLoaded) - unload(); - - loadRemap(); - loadInfo(); - mLoaded = true; -} - -void MapDB::loadRemap() -{ - XML::Document *const doc = new XML::Document( - paths.getStringValue("mapsRemapFile")); - - const XmlNodePtr root = doc->rootNode(); - if (!root) - { - delete doc; - return; - } - - for_each_xml_child_node(node, root) - { - if (xmlNameEqual(node, "map")) - { - const std::string name = XML::getProperty(node, "name", ""); - if (name.empty()) - continue; - - const std::string value = XML::getProperty(node, "value", ""); - if (value.empty()) - continue; - - mMaps[name] = value; - } - } - - delete doc; -} - -void MapDB::readMap(XmlNodePtr node) -{ - const std::string map = XML::getProperty(node, "name", ""); - if (map.empty()) - return; - - for_each_xml_child_node(childNode, node) - { - if (xmlNameEqual(childNode, "atlas")) - { - const std::string atlas = XML::getProperty(childNode, "name", ""); - if (atlas.empty()) - continue; - mInfos[map].atlas = atlas; - } - } -} - -void MapDB::readAtlas(XmlNodePtr node) -{ - const std::string atlas = XML::getProperty(node, "name", ""); - if (atlas.empty()) - return; - for_each_xml_child_node(childNode, node) - { - if (xmlNameEqual(childNode, "file")) - { - const std::string file = XML::getProperty(childNode, "name", ""); - if (file.empty()) - continue; - mAtlases[atlas].push_back(file); - } - } - if (atlas != "all") - { - const AtlasCIter &allAtlas = mAtlases.find("all"); - if (allAtlas != mAtlases.end()) - { - FOR_EACH (StringVectCIter, it, (*allAtlas).second) - mAtlases[atlas].push_back(*it); - } - } -} - -void MapDB::loadInfo() -{ - XML::Document *doc = new XML::Document(paths.getStringValue("mapsFile")); - const XmlNodePtr root = doc->rootNode(); - if (!root) - { - delete doc; - return; - } - - for_each_xml_child_node(node, root) - { - if (xmlNameEqual(node, "map")) - readMap(node); - else if (xmlNameEqual(node, "atlas")) - readAtlas(node); - } - delete doc; -} - -void MapDB::unload() -{ - logger->log1("Unloading map database..."); - - mMaps.clear(); - mLoaded = false; -} - -const std::string MapDB::getMapName(const std::string &name) -{ - const MapIterator it = mMaps.find(name); - - if (it != mMaps.end()) - return it->second; - return name; -} - -const MapDB::MapInfo *MapDB::getMapAtlas(const std::string &name) -{ - const MapInfoIter it = mInfos.find(name); - if (it == mInfos.end()) - return nullptr; - MapInfo *const info = &(*it).second; - const AtlasCIter it2 = mAtlases.find(info->atlas); - if (it2 == mAtlases.end()) - return nullptr; - info->files = &((*it2).second); - return info; -} diff --git a/src/resources/mapdb.h b/src/resources/mapdb.h deleted file mode 100644 index 9e0407f66..000000000 --- a/src/resources/mapdb.h +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Color database - * Copyright (C) 2008 Aethyra Development Team - * Copyright (C) 2011-2013 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 . - */ - -#ifndef RESOURCES_MAPDB_H -#define RESOURCES_MAPDB_H - -#include "utils/stringvector.h" - -#include - -#include "localconsts.h" - -/** - * Color information database. - */ -namespace MapDB -{ - struct MapInfo - { - MapInfo() : - atlas(), - files(nullptr) - { - } - - std::string atlas; - const StringVect *files; - }; - - /** - * Loads the map remap data from maps\remap.xml. - */ - void load(); - - void loadRemap(); - - void loadInfo(); - - /** - * Clear the remap data - */ - void unload(); - - const std::string getMapName(const std::string &name) A_WARN_UNUSED; - - const MapInfo *getMapAtlas(const std::string &name) A_WARN_UNUSED; - - // Maps DB - typedef std::map Maps; - typedef Maps::iterator MapIterator; - // map to infos map - typedef std::map MapInfos; - typedef MapInfos::iterator MapInfoIter; - // atlas to files map - typedef std::map Atlases; - typedef Atlases::iterator AtlasIter; - typedef Atlases::const_iterator AtlasCIter; -} // namespace MapDB - -#endif // RESOURCES_MAPDB_H diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp index 5b21acb02..4097acb89 100644 --- a/src/resources/mapreader.cpp +++ b/src/resources/mapreader.cpp @@ -31,9 +31,10 @@ #include "resources/animation.h" #include "resources/image.h" -#include "resources/mapdb.h" #include "resources/resourcemanager.h" +#include "resources/db/mapdb.h" + #include "utils/base64.h" #include diff --git a/src/resources/monsterdb.cpp b/src/resources/monsterdb.cpp deleted file mode 100644 index e900c426f..000000000 --- a/src/resources/monsterdb.cpp +++ /dev/null @@ -1,273 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2004-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011-2013 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 . - */ - -#include "resources/monsterdb.h" - -#include "logger.h" - -#include "resources/beingcommon.h" -#include "resources/beinginfo.h" - -#include "utils/dtor.h" -#include "utils/gettext.h" - -#include "configuration.h" - -#include "debug.h" - -static const unsigned int OLD_TMWATHENA_OFFSET = 1002; - -namespace -{ - BeingInfos mMonsterInfos; - bool mLoaded = false; -} - -void MonsterDB::load() -{ - if (mLoaded) - unload(); - - logger->log1("Initializing monster database..."); - loadXmlFile(paths.getStringValue("monstersFile")); - mLoaded = true; -} - -void MonsterDB::loadXmlFile(const std::string &fileName) -{ - XML::Document doc(fileName); - const XmlNodePtr rootNode = doc.rootNode(); - - if (!rootNode || !xmlNameEqual(rootNode, "monsters")) - { - logger->log("Monster Database: Error while loading %s!", - paths.getStringValue("monstersFile").c_str()); - mLoaded = true; - return; - } - -#ifdef MANASERV_SUPPORT - const int offset = XML::getProperty(rootNode, "offset", - Net::getNetworkType() != ServerInfo::MANASERV - ? OLD_TMWATHENA_OFFSET : 0); -#else - const int offset = XML::getProperty(rootNode, - "offset", OLD_TMWATHENA_OFFSET); -#endif - - // iterate s - for_each_xml_child_node(monsterNode, rootNode) - { - if (xmlNameEqual(monsterNode, "include")) - { - const std::string name = XML::getProperty(monsterNode, "name", ""); - if (!name.empty()) - loadXmlFile(name); - continue; - } - if (!xmlNameEqual(monsterNode, "monster")) - continue; - - BeingInfo *const currentInfo = new BeingInfo; - - currentInfo->setWalkMask(Map::BLOCKMASK_WALL - | Map::BLOCKMASK_CHARACTER | Map::BLOCKMASK_MONSTER); - currentInfo->setBlockType(Map::BLOCKTYPE_MONSTER); - - currentInfo->setName(XML::langProperty( - // TRANSLATORS: unknown info name - monsterNode, "name", _("unnamed"))); - - BeingCommon::readBasicAttributes(currentInfo, monsterNode, "attack"); - - currentInfo->setMaxHP(XML::getProperty(monsterNode, "maxHP", 0)); - - currentInfo->setDeadSortOffsetY(XML::getProperty( - monsterNode, "deadSortOffsetY", 31)); - - currentInfo->setColorsList(XML::getProperty(monsterNode, - "colors", "")); - - unsigned char block = 0; - std::string walkStr = XML::getProperty( - monsterNode, "walkType", "walk"); - if (walkStr == "walk") - block = Map::BLOCKMASK_WATER | Map::BLOCKMASK_AIR; - else if (walkStr == "fly") - block = 0; - else if (walkStr == "swim") - block = Map::BLOCKMASK_GROUND | Map::BLOCKMASK_AIR; - else if (walkStr == "walkswim" || walkStr == "swimwalk") - block = Map::BLOCKMASK_AIR; - - currentInfo->setWalkMask(static_cast( - Map::BLOCKMASK_WALL | block)); - - if (currentInfo->getMaxHP()) - currentInfo->setStaticMaxHP(true); - - SpriteDisplay display; - - // iterate s and s - for_each_xml_child_node(spriteNode, monsterNode) - { - if (xmlNameEqual(spriteNode, "sprite")) - { - if (!spriteNode->xmlChildrenNode) - continue; - - SpriteReference *const currentSprite = new SpriteReference; - currentSprite->sprite = reinterpret_cast( - spriteNode->xmlChildrenNode->content); - - currentSprite->variant = XML::getProperty( - spriteNode, "variant", 0); - display.sprites.push_back(currentSprite); - } - else if (xmlNameEqual(spriteNode, "sound")) - { - if (!spriteNode->xmlChildrenNode) - continue; - - const std::string event = XML::getProperty( - spriteNode, "event", ""); - const int delay = XML::getProperty( - spriteNode, "delay", 0); - const char *filename; - filename = reinterpret_cast( - spriteNode->xmlChildrenNode->content); - - if (event == "hit") - { - currentInfo->addSound(SOUND_EVENT_HIT, filename, delay); - } - else if (event == "miss") - { - currentInfo->addSound(SOUND_EVENT_MISS, filename, delay); - } - else if (event == "hurt") - { - currentInfo->addSound(SOUND_EVENT_HURT, filename, delay); - } - else if (event == "die") - { - currentInfo->addSound(SOUND_EVENT_DIE, filename, delay); - } - else if (event == "move") - { - currentInfo->addSound(SOUND_EVENT_MOVE, filename, delay); - } - else if (event == "sit") - { - currentInfo->addSound(SOUND_EVENT_SIT, filename, delay); - } - else if (event == "sittop") - { - currentInfo->addSound(SOUND_EVENT_SITTOP, filename, delay); - } - else if (event == "spawn") - { - currentInfo->addSound(SOUND_EVENT_SPAWN, filename, delay); - } - else - { - logger->log("MonsterDB: Warning, sound effect %s for " - "unknown event %s of monster %s", - filename, event.c_str(), - currentInfo->getName().c_str()); - } - } - else if (xmlNameEqual(spriteNode, "attack")) - { - const int id = XML::getProperty(spriteNode, "id", 0); - const int effectId = XML::getProperty( - spriteNode, "effect-id", paths.getIntValue("effectId")); - const int hitEffectId = XML::getProperty(spriteNode, - "hit-effect-id", paths.getIntValue("hitEffectId")); - const int criticalHitEffectId = XML::getProperty(spriteNode, - "critical-hit-effect-id", - paths.getIntValue("criticalHitEffectId")); - const int missEffectId = XML::getProperty(spriteNode, - "miss-effect-id", paths.getIntValue("missEffectId")); - - const std::string spriteAction = XML::getProperty( - spriteNode, "action", "attack"); - const std::string skySpriteAction = XML::getProperty( - spriteNode, "skyaction", "skyattack"); - const std::string waterSpriteAction = XML::getProperty( - spriteNode, "wateraction", "waterattack"); - - const std::string missileParticle = XML::getProperty( - spriteNode, "missile-particle", ""); - - currentInfo->addAttack(id, spriteAction, skySpriteAction, - waterSpriteAction, effectId, hitEffectId, - criticalHitEffectId, missEffectId, missileParticle); - } - else if (xmlNameEqual(spriteNode, "particlefx")) - { - if (!spriteNode->xmlChildrenNode) - continue; - - display.particles.push_back(reinterpret_cast( - spriteNode->xmlChildrenNode->content)); - } - } - currentInfo->setDisplay(display); - - mMonsterInfos[XML::getProperty( - monsterNode, "id", 0) + offset] = currentInfo; - } -} - -void MonsterDB::unload() -{ - delete_all(mMonsterInfos); - mMonsterInfos.clear(); - - mLoaded = false; -} - - -BeingInfo *MonsterDB::get(const int id) -{ - BeingInfoIterator i = mMonsterInfos.find(id); - - if (i == mMonsterInfos.end()) - { - i = mMonsterInfos.find(id + OLD_TMWATHENA_OFFSET); - if (i == mMonsterInfos.end()) - { - logger->log("MonsterDB: Warning, unknown monster ID %d requested", - id); - return BeingInfo::unknown; - } - else - { - return i->second; - } - } - else - { - return i->second; - } -} diff --git a/src/resources/monsterdb.h b/src/resources/monsterdb.h deleted file mode 100644 index 426228388..000000000 --- a/src/resources/monsterdb.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2004-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011-2013 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 . - */ - -#ifndef RESOURCES_MONSTERDB_H -#define RESOURCES_MONSTERDB_H - -#include "localconsts.h" - -#include - -class BeingInfo; - -/** - * Monster information database. - */ -namespace MonsterDB -{ - void load(); - - void unload(); - - void loadXmlFile(const std::string &fileName); - - BeingInfo *get(const int id) A_WARN_UNUSED; -} - -#endif // RESOURCES_MONSTERDB_H diff --git a/src/resources/npcdb.cpp b/src/resources/npcdb.cpp deleted file mode 100644 index f9d9295d6..000000000 --- a/src/resources/npcdb.cpp +++ /dev/null @@ -1,158 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2008-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011-2013 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 . - */ - -#include "resources/npcdb.h" - -#include "logger.h" - -#include "resources/beingcommon.h" -#include "resources/beinginfo.h" - -#include "utils/dtor.h" -#include "configuration.h" - -#include "debug.h" - -namespace -{ - BeingInfos mNPCInfos; - bool mLoaded = false; -} - -extern int serverVersion; - -void NPCDB::load() -{ - if (mLoaded) - unload(); - - logger->log1("Initializing NPC database..."); - - loadXmlFile(paths.getStringValue("npcsFile")); - mLoaded = true; -} - -void NPCDB::loadXmlFile(const std::string &fileName) -{ - XML::Document doc(fileName); - const XmlNodePtr rootNode = doc.rootNode(); - - if (!rootNode || !xmlNameEqual(rootNode, "npcs")) - { - logger->log("NPC Database: Error while loading %s!", - paths.getStringValue("npcsFile").c_str()); - mLoaded = true; - return; - } - - // iterate s - for_each_xml_child_node(npcNode, rootNode) - { - if (xmlNameEqual(npcNode, "include")) - { - const std::string name = XML::getProperty(npcNode, "name", ""); - if (!name.empty()) - loadXmlFile(name); - continue; - } - - if (!xmlNameEqual(npcNode, "npc")) - continue; - - const int id = XML::getProperty(npcNode, "id", 0); - if (id == 0) - { - logger->log("NPC Database: NPC with missing ID in %s!", - paths.getStringValue("npcsFile").c_str()); - continue; - } - - BeingInfo *const currentInfo = new BeingInfo; - - currentInfo->setTargetSelection(XML::getBoolProperty(npcNode, - "targetSelection", true)); - - BeingCommon::readBasicAttributes(currentInfo, npcNode, "talk"); - - currentInfo->setDeadSortOffsetY(XML::getProperty(npcNode, - "deadSortOffsetY", 31)); - - currentInfo->setAvatarId(static_cast(XML::getProperty( - npcNode, "avatar", 0))); - - SpriteDisplay display; - for_each_xml_child_node(spriteNode, npcNode) - { - if (!spriteNode->xmlChildrenNode) - continue; - - if (xmlNameEqual(spriteNode, "sprite")) - { - SpriteReference *const currentSprite = new SpriteReference; - currentSprite->sprite = reinterpret_cast( - spriteNode->xmlChildrenNode->content); - currentSprite->variant = - XML::getProperty(spriteNode, "variant", 0); - display.sprites.push_back(currentSprite); - } - else if (xmlNameEqual(spriteNode, "particlefx")) - { - display.particles.push_back(reinterpret_cast( - spriteNode->xmlChildrenNode->content)); - } - } - - currentInfo->setDisplay(display); - mNPCInfos[id] = currentInfo; - } -} - -void NPCDB::unload() -{ - delete_all(mNPCInfos); - mNPCInfos.clear(); - - mLoaded = false; -} - -BeingInfo *NPCDB::get(const int id) -{ - const BeingInfoIterator i = mNPCInfos.find(id); - - if (i == mNPCInfos.end()) - { - logger->log("NPCDB: Warning, unknown NPC ID %d requested", id); - return BeingInfo::unknown; - } - else - { - return i->second; - } -} - -uint16_t NPCDB::getAvatarFor(const int id) -{ - const BeingInfo *const info = get(id); - if (!info) - return 0; - return info->getAvatarId(); -} diff --git a/src/resources/npcdb.h b/src/resources/npcdb.h deleted file mode 100644 index 9614c2052..000000000 --- a/src/resources/npcdb.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2008-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011-2013 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 . - */ - -#ifndef RESOURCES_NPCDB_H -#define RESOURCES_NPCDB_H - -#include - -#include - -#include "localconsts.h" - -class BeingInfo; - -/** - * NPC information database. - */ -namespace NPCDB -{ - void load(); - - void unload(); - - BeingInfo *get(const int id) A_WARN_UNUSED; - - uint16_t getAvatarFor(const int id); - - void loadXmlFile(const std::string &fileName); -} // namespace NPCDB - -#endif // RESOURCES_NPCDB_H diff --git a/src/resources/palettedb.cpp b/src/resources/palettedb.cpp deleted file mode 100644 index 1219601ce..000000000 --- a/src/resources/palettedb.cpp +++ /dev/null @@ -1,108 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2013 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 . - */ - -#include "resources/palettedb.h" - -#include "logger.h" - -#include "resources/dyecolor.h" -#include "resources/resourcemanager.h" - -#include - -#include "debug.h" - -namespace -{ - bool mLoaded = false; - std::map mColors; - DyeColor mEmpty(0, 0, 0, 0); -} - -void PaletteDB::load() -{ - if (mLoaded) - unload(); - - loadPalette(); -} - -void PaletteDB::loadPalette() -{ - mLoaded = true; - StringVect lines; - ResourceManager::loadTextFile("palette.gpl", lines); - StringVectCIter it = lines.begin(); - if (it == lines.end()) - { - logger->log("missing GIMP palette file"); - return; - } - if (*it != "GIMP Palette") - { - logger->log("wrong GIMP palette file"); - return; - } - ++ it; - // skip header - while (it != lines.end()) - { - const std::string line = *it; - if (!line.empty() && line[0] == '#') - break; - ++ it; - } - - char name[101]; - - // process colors and ignore commets - while (it != lines.end()) - { - const std::string line = *it; - ++ it; - - if (line.empty() || line[0] == '#') - continue; - - unsigned int r; - unsigned int g; - unsigned int b; - - if (sscanf(line.c_str(), "%10u %10u %10u\t%100s", - &r, &g, &b, name) == 4) - { - mColors[name] = DyeColor(r, g, b); - } - } -} - -void PaletteDB::unload() -{ - mColors.clear(); -} - -const DyeColor &PaletteDB::getColor(const std::string &name) -{ - std::map::const_iterator it = mColors.find(name); - if (it != mColors.end()) - return (*it).second; - else - return mEmpty; -} diff --git a/src/resources/palettedb.h b/src/resources/palettedb.h deleted file mode 100644 index 307178693..000000000 --- a/src/resources/palettedb.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2013 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 . - */ - -#ifndef RESOURCES_PALETTEDB_H -#define RESOURCES_PALETTEDB_H - -#include "localconsts.h" - -#include - -struct DyeColor; - -namespace PaletteDB -{ - void load(); - void unload(); - void loadPalette(); - const DyeColor &getColor(const std::string &name); - -} // namespace PaletteDB - -#endif // RESOURCES_PALETTEDB_H diff --git a/src/resources/petdb.cpp b/src/resources/petdb.cpp deleted file mode 100644 index a85480e7b..000000000 --- a/src/resources/petdb.cpp +++ /dev/null @@ -1,137 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2008-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011-2013 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 . - */ - -#include "resources/petdb.h" - -#include "logger.h" - -#include "resources/beingcommon.h" -#include "resources/beinginfo.h" - -#include "utils/dtor.h" -#include "configuration.h" - -#include "debug.h" - -namespace -{ - BeingInfos mPETInfos; - bool mLoaded = false; -} - -extern int serverVersion; - -void PETDB::load() -{ - if (mLoaded) - unload(); - - logger->log1("Initializing PET database..."); - - XML::Document doc(paths.getStringValue("petsFile")); - const XmlNodePtr rootNode = doc.rootNode(); - - if (!rootNode || !xmlNameEqual(rootNode, "pets")) - { - logger->log("PET Database: Error while loading %s!", - paths.getStringValue("petsFile").c_str()); - mLoaded = true; - return; - } - - // iterate s - for_each_xml_child_node(petNode, rootNode) - { - if (!xmlNameEqual(petNode, "pet")) - continue; - - const int id = XML::getProperty(petNode, "id", 0); - if (id == 0) - { - logger->log("PET Database: PET with missing ID in %s!", - paths.getStringValue("petsFile").c_str()); - continue; - } - - BeingInfo *const currentInfo = new BeingInfo; - - currentInfo->setTargetSelection(XML::getBoolProperty(petNode, - "targetSelection", false)); - - BeingCommon::readBasicAttributes(currentInfo, petNode, "talk"); - - currentInfo->setDeadSortOffsetY(XML::getProperty(petNode, - "deadSortOffsetY", 31)); - - SpriteDisplay display; - for_each_xml_child_node(spriteNode, petNode) - { - if (!spriteNode->xmlChildrenNode) - continue; - - if (xmlNameEqual(spriteNode, "sprite")) - { - SpriteReference *const currentSprite = new SpriteReference; - currentSprite->sprite = reinterpret_cast( - spriteNode->xmlChildrenNode->content); - currentSprite->variant = - XML::getProperty(spriteNode, "variant", 0); - display.sprites.push_back(currentSprite); - } - else if (xmlNameEqual(spriteNode, "particlefx")) - { - std::string particlefx = reinterpret_cast( - spriteNode->xmlChildrenNode->content); - display.particles.push_back(particlefx); - } - } - - currentInfo->setDisplay(display); - - mPETInfos[id] = currentInfo; - } - - mLoaded = true; -} - -void PETDB::unload() -{ - delete_all(mPETInfos); - mPETInfos.clear(); - - mLoaded = false; -} - -BeingInfo *PETDB::get(const int id) -{ - const BeingInfoIterator i = mPETInfos.find(id); - - if (i == mPETInfos.end()) - { - logger->log("PETDB: Warning, unknown PET ID %d requested", id); - return BeingInfo::unknown; - } - else - { - return i->second; - } -} diff --git a/src/resources/petdb.h b/src/resources/petdb.h deleted file mode 100644 index d5e4b5613..000000000 --- a/src/resources/petdb.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2008-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011-2013 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 . - */ - -#ifndef RESOURCES_PETDB_H -#define RESOURCES_PETDB_H - -#include "localconsts.h" - -class BeingInfo; - -namespace PETDB -{ - void load(); - - void unload(); - - BeingInfo *get(const int id) A_WARN_UNUSED; -} - -#endif // RESOURCES_PETDB_H diff --git a/src/resources/sounddb.cpp b/src/resources/sounddb.cpp deleted file mode 100644 index 7b0d078e1..000000000 --- a/src/resources/sounddb.cpp +++ /dev/null @@ -1,79 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2013 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 . - */ - -#include "resources/sounddb.h" - -#include "configuration.h" -#include "notifications.h" -#include "notifymanager.h" - -#include "utils/xml.h" - -#include "debug.h" - -namespace -{ - std::string mDefault; - std::vector mSounds; -} - -void SoundDB::load() -{ - unload(); - - XML::Document *doc = new XML::Document(paths.getStringValue("soundsFile")); - const XmlNodePtr root = doc->rootNode(); - - if (!root || !xmlNameEqual(root, "sounds")) - { - delete doc; - return; - } - - for_each_xml_child_node(node, root) - { - if (xmlNameEqual(node, "sound")) - { - const std::string name = XML::getProperty(node, "name", ""); - const int id = NotifyManager::getIndexBySound(name); - if (id) - { - const std::string value = XML::getProperty(node, "value", ""); - mSounds[id] = value; - } - } - } - - delete doc; -} - -void SoundDB::unload() -{ - mSounds.resize(NotifyManager::TYPE_END); - for (int f = 0; f < NotifyManager::TYPE_END; f ++) - mSounds[f] = ""; -} - -std::string &SoundDB::getSound(const int id) -{ - if (id < 0 || id >= NotifyManager::TYPE_END) - return mDefault; - return mSounds[id]; -} diff --git a/src/resources/sounddb.h b/src/resources/sounddb.h deleted file mode 100644 index 356cd4e13..000000000 --- a/src/resources/sounddb.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2013 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 . - */ - -#ifndef RESOURCES_SOUNDDB_H -#define RESOURCES_SOUNDDB_H - -#include - -#include "localconsts.h" - -namespace SoundDB -{ - void load(); - - void unload(); - - std::string &getSound(const int id); -} - -#endif // RESOURCES_SOUNDDB_H diff --git a/src/textcommand.cpp b/src/textcommand.cpp index 8747c4d57..1aa2e8381 100644 --- a/src/textcommand.cpp +++ b/src/textcommand.cpp @@ -27,10 +27,11 @@ #include "gui/theme.h" #include "resources/image.h" -#include "resources/itemdb.h" #include "resources/iteminfo.h" #include "resources/resourcemanager.h" +#include "resources/db/itemdb.h" + #include "debug.h" TextCommand::TextCommand(const unsigned int id, const std::string &symbol, -- cgit v1.2.3-70-g09d2