summaryrefslogtreecommitdiff
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
parent82de3bbe7580f65bf808c4fd48706fa9e0512a65 (diff)
downloadmv-68f5e88eb44ed76facaa7e56cd7641b762f7ca60.tar.gz
mv-68f5e88eb44ed76facaa7e56cd7641b762f7ca60.tar.bz2
mv-68f5e88eb44ed76facaa7e56cd7641b762f7ca60.tar.xz
mv-68f5e88eb44ed76facaa7e56cd7641b762f7ca60.zip
dehardcode death messages.
add deadmessages.xml for death messages.
-rw-r--r--data/perserver/default/CMakeLists.txt1
-rw-r--r--data/perserver/default/Makefile.am1
-rw-r--r--data/perserver/default/deadmessages.xml42
-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
10 files changed, 185 insertions, 81 deletions
diff --git a/data/perserver/default/CMakeLists.txt b/data/perserver/default/CMakeLists.txt
index 2d2ef8cdd..ed7e61e1e 100644
--- a/data/perserver/default/CMakeLists.txt
+++ b/data/perserver/default/CMakeLists.txt
@@ -1,6 +1,7 @@
SET (FILES
charcreation.xml
chatcommands.txt
+ deadmessages.xml
features.xml
gmcommands.txt
)
diff --git a/data/perserver/default/Makefile.am b/data/perserver/default/Makefile.am
index a263c4044..8a66984b8 100644
--- a/data/perserver/default/Makefile.am
+++ b/data/perserver/default/Makefile.am
@@ -3,6 +3,7 @@ defaultdir = $(pkgdatadir)/data/perserver/default
default_DATA = \
charcreation.xml \
chatcommands.txt \
+ deadmessages.xml \
features.xml \
gmcommands.txt
diff --git a/data/perserver/default/deadmessages.xml b/data/perserver/default/deadmessages.xml
new file mode 100644
index 000000000..057f7fcde
--- /dev/null
+++ b/data/perserver/default/deadmessages.xml
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Author : 4144
+(C) ManaPlus Developers 2013. -->
+<messages>
+ <its:rules xmlns:its="http://www.w3.org/2005/11/its" version="1.0">
+ <its:translateRule selector="//message" translate="yes"/>
+ </its:rules>
+
+ <message>You are dead.</message>
+ <message>We regret to inform you that your character was killed in battle.</message>
+ <message>You are not that alive anymore.</message>
+ <message>The cold hands of the grim reaper are grabbing for your soul.</message>
+ <message>Game Over!</message>
+ <message>Insert coin to continue.</message>
+ <message>No, kids. Your character did not really die. It... err... went to a better place.</message>
+ <message>Your plan of breaking your enemies weapon by bashing it with your throat failed.</message>
+ <message>I guess this did not run too well.</message>
+ // NetHack reference:
+ <message>Do you want your possessions identified?</message>
+ // Secret of Mana reference:
+ <message>Sadly, no trace of you was ever found...</message>
+ // Final Fantasy VI reference:
+ <message>Annihilated.</message>
+ // Earthbound reference:
+ <message>Looks like you got your head handed to you.</message>
+ // Leisure Suit Larry 1 reference:
+ <message>You screwed up again, dump your body down the tubes and get you another one.</message>
+ // Monty Python references (Dead Parrot sketch mostly):
+ <message>You're not dead yet. You're just resting.</message>
+ <message>You are no more.</message>
+ <message>You have ceased to be.</message>
+ <message>You've expired and gone to meet your maker.</message>
+ <message>You're a stiff.</message>
+ <message>Bereft of life, you rest in peace.</message>
+ <message>If you weren't so animated, you'd be pushing up the daisies.</message>
+ <message>Your metabolic processes are now history.</message>
+ <message>You're off the twig.</message>
+ <message>You've kicked the bucket.</message>
+ <message>You've shuffled off your mortal coil, run down the curtain and joined the bleedin' choir invisibile.</message>
+ <message>You are an ex-player.</message>
+ <message>You're pining for the fjords.</message>
+</messages>
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