summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-07-10 22:17:23 +0300
committerAndrei Karas <akaras@inbox.ru>2013-07-10 23:13:13 +0300
commit68f5e88eb44ed76facaa7e56cd7641b762f7ca60 (patch)
tree3df1918042695308e806f09d00093f7b435e7e9d /src
parent82de3bbe7580f65bf808c4fd48706fa9e0512a65 (diff)
downloadmanaverse-68f5e88eb44ed76facaa7e56cd7641b762f7ca60.tar.gz
manaverse-68f5e88eb44ed76facaa7e56cd7641b762f7ca60.tar.bz2
manaverse-68f5e88eb44ed76facaa7e56cd7641b762f7ca60.tar.xz
manaverse-68f5e88eb44ed76facaa7e56cd7641b762f7ca60.zip
dehardcode death messages.
add deadmessages.xml for death messages.
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/Makefile.am2
-rw-r--r--src/client.cpp3
-rw-r--r--src/defaults.cpp1
-rw-r--r--src/net/ea/playerhandler.cpp84
-rw-r--r--src/resources/deaddb.cpp81
-rw-r--r--src/resources/deaddb.h49
7 files changed, 141 insertions, 81 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index ebb55e132..1edd97ca1 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -440,6 +440,8 @@ SET(SRCS
resources/colordb.h
resources/cursor.cpp
resources/cursor.h
+ resources/deaddb.cpp
+ resources/deaddb.h
resources/dye.cpp
resources/dye.h
resources/dyecolor.h
diff --git a/src/Makefile.am b/src/Makefile.am
index fb379d024..ddb7f6800 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -441,6 +441,8 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \
resources/colordb.h \
resources/cursor.cpp \
resources/cursor.h \
+ resources/deaddb.cpp \
+ resources/deaddb.h \
resources/dye.cpp \
resources/dye.h \
resources/dyecolor.h \
diff --git a/src/client.cpp b/src/client.cpp
index cee32ae80..74abd5f7d 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -82,6 +82,7 @@
#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"
@@ -769,6 +770,7 @@ void Client::gameClear()
// Unload XML databases
CharDB::unload();
+ DeadDB::unload();
ColorDB::unload();
SoundDB::unload();
EmoteDB::unload();
@@ -1458,6 +1460,7 @@ int Client::gameExec()
// Load XML databases
CharDB::load();
+ DeadDB::load();
PaletteDB::load();
ColorDB::load();
SoundDB::load();
diff --git a/src/defaults.cpp b/src/defaults.cpp
index 5562a37aa..b5a3a410b 100644
--- a/src/defaults.cpp
+++ b/src/defaults.cpp
@@ -455,6 +455,7 @@ DefaultsData* getPathsDefaults()
AddDEF("monstersFile", "monsters.xml");
AddDEF("mapsRemapFile", "maps/remap.xml");
AddDEF("mapsFile", "maps.xml");
+ AddDEF("deadMessagesFile", "deadmessages.xml");
return configData;
}
diff --git a/src/net/ea/playerhandler.cpp b/src/net/ea/playerhandler.cpp
index 446766b56..2d477ad4a 100644
--- a/src/net/ea/playerhandler.cpp
+++ b/src/net/ea/playerhandler.cpp
@@ -35,6 +35,8 @@
#include "gui/statuswindow.h"
#include "gui/viewport.h"
+#include "resources/deaddb.h"
+
#include "net/npchandler.h"
#include "net/ea/eaprotocol.h"
@@ -86,86 +88,6 @@ namespace
} // anonymous namespace
-static const char *randomDeathMessage()
-{
- static const char *const deadMsg[] =
- {
- // TRANSLATORS: death message
- N_("You are dead."),
- // TRANSLATORS: death message
- N_("We regret to inform you that your character was killed in "
- "battle."),
- // TRANSLATORS: death message
- N_("You are not that alive anymore."),
- // TRANSLATORS: death message
- N_("The cold hands of the grim reaper are grabbing for your soul."),
- // TRANSLATORS: death message
- N_("Game Over!"),
- // TRANSLATORS: death message
- N_("Insert coin to continue."),
- // TRANSLATORS: death message
- N_("No, kids. Your character did not really die. It... "
- "err... went to a better place."),
- // TRANSLATORS: death message
- N_("Your plan of breaking your enemies weapon by "
- "bashing it with your throat failed."),
- // TRANSLATORS: death message
- N_("I guess this did not run too well."),
- // NetHack reference:
- // TRANSLATORS: death message
- N_("Do you want your possessions identified?"),
- // Secret of Mana reference:
- // TRANSLATORS: death message
- N_("Sadly, no trace of you was ever found..."),
- // Final Fantasy VI reference:
- // TRANSLATORS: death message
- N_("Annihilated."),
- // Earthbound reference:
- // TRANSLATORS: death message
- N_("Looks like you got your head handed to you."),
- // Leisure Suit Larry 1 reference:
- // TRANSLATORS: death message
- N_("You screwed up again, dump your body down the tubes "
- "and get you another one."),
- // Monty Python references (Dead Parrot sketch mostly):
- // TRANSLATORS: death message
- N_("You're not dead yet. You're just resting."),
- // TRANSLATORS: death message
- N_("You are no more."),
- // TRANSLATORS: death message
- N_("You have ceased to be."),
- // TRANSLATORS: death message
- N_("You've expired and gone to meet your maker."),
- // TRANSLATORS: death message
- N_("You're a stiff."),
- // TRANSLATORS: death message
- N_("Bereft of life, you rest in peace."),
- // TRANSLATORS: death message
- N_("If you weren't so animated, you'd be pushing up the daisies."),
- // TRANSLATORS: death message
- N_("Your metabolic processes are now history."),
- // TRANSLATORS: death message
- N_("You're off the twig."),
- // TRANSLATORS: death message
- N_("You've kicked the bucket."),
- // TRANSLATORS: death message
- N_("You've shuffled off your mortal coil, run down the "
- "curtain and joined the bleedin' choir invisibile."),
- // TRANSLATORS: death message
- N_("You are an ex-player."),
- // TRANSLATORS: death message
- N_("You're pining for the fjords.")
- };
-
- const int sz = sizeof(deadMsg);
- if (!sz)
- return gettext(deadMsg[0]);
-
- const int random = static_cast<int>(rand() % (sz
- / sizeof(deadMsg[0])));
- return gettext(deadMsg[random]);
-}
-
namespace Ea
{
@@ -468,7 +390,7 @@ void PlayerHandler::processPlayerStatUpdate1(Net::MessageIn &msg) const
{
// TRANSLATORS: message header
deathNotice = new OkDialog(_("Message"),
- randomDeathMessage(), DIALOG_OK, false);
+ DeadDB::getRandomString(), DIALOG_OK, false);
deathNotice->addActionListener(&deathListener);
if (player_node->getCurrentAction() != Being::DEAD)
{
diff --git a/src/resources/deaddb.cpp b/src/resources/deaddb.cpp
new file mode 100644
index 000000000..abfb511ff
--- /dev/null
+++ b/src/resources/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 <http://www.gnu.org/licenses/>.
+ */
+
+#include "resources/deaddb.h"
+
+#include "configuration.h"
+#include "logger.h"
+
+#include "utils/translation/podict.h"
+
+#include "debug.h"
+
+namespace
+{
+ bool mLoaded = false;
+ std::vector<std::string> 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<const char*>(
+ 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
new file mode 100644
index 000000000..eb39e864a
--- /dev/null
+++ b/src/resources/deaddb.h
@@ -0,0 +1,49 @@
+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef RESOURCES_DEADDB_H
+#define RESOURCES_DEADDB_H
+
+#include <map>
+#include <string>
+
+#include "utils/xml.h"
+
+#include <vector>
+
+/**
+ * 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