summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2014-02-27 12:48:21 +0300
committerAndrei Karas <akaras@inbox.ru>2014-02-27 12:48:21 +0300
commitb481cd74dfd1629ca7b045cde57562e752c49638 (patch)
treef96df5fd34ed5dba3a615d15fff69fb01903d9c0 /src
parentf91a3ef02da845393dc7df7cf6337d064a1feaa7 (diff)
downloadplus-b481cd74dfd1629ca7b045cde57562e752c49638.tar.gz
plus-b481cd74dfd1629ca7b045cde57562e752c49638.tar.bz2
plus-b481cd74dfd1629ca7b045cde57562e752c49638.tar.xz
plus-b481cd74dfd1629ca7b045cde57562e752c49638.zip
Dehardcode swords, shields and bows for auto switching weapons.
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/Makefile.am2
-rw-r--r--src/being/localplayer.cpp51
-rw-r--r--src/client.cpp3
-rw-r--r--src/resources/db/weaponsdb.cpp81
-rw-r--r--src/resources/db/weaponsdb.h45
6 files changed, 158 insertions, 26 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 6c9d82731..054ab4823 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -525,6 +525,8 @@ SET(SRCS
resources/sdlmusic.h
resources/db/sounddb.cpp
resources/db/sounddb.h
+ resources/db/weaponsdb.cpp
+ resources/db/weaponsdb.h
resources/soundeffect.cpp
resources/soundeffect.h
resources/soundinfo.h
diff --git a/src/Makefile.am b/src/Makefile.am
index e45a5397a..2b1eb4c68 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -624,6 +624,8 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \
resources/sdlmusic.h \
resources/db/sounddb.cpp \
resources/db/sounddb.h \
+ resources/db/weaponsdb.cpp \
+ resources/db/weaponsdb.h \
resources/soundeffect.cpp \
resources/soundeffect.h \
resources/soundinfo.h \
diff --git a/src/being/localplayer.cpp b/src/being/localplayer.cpp
index 2a3c5fa2f..0e7f8a9b0 100644
--- a/src/being/localplayer.cpp
+++ b/src/being/localplayer.cpp
@@ -67,6 +67,7 @@
#include "resources/iteminfo.h"
#include "resources/db/emotedb.h"
+#include "resources/db/weaponsdb.h"
#include "utils/gettext.h"
#include "utils/timer.h"
@@ -2337,23 +2338,14 @@ void LocalPlayer::changeEquipmentBeforeAttack(const Being *const target) const
// if attack distance for sword
if (allowSword)
{
- // finding sword
- item = inv->findItem(571, 0);
-
- if (!item)
- item = inv->findItem(570, 0);
-
- if (!item)
- item = inv->findItem(579, 0);
-
- if (!item)
- item = inv->findItem(867, 0);
-
- if (!item)
- item = inv->findItem(536, 0);
-
- if (!item)
- item = inv->findItem(758, 0);
+ // searching swords
+ const WeaponsInfos &swords = WeaponsDB::getSwords();
+ FOR_EACH (WeaponsInfosIter, it, swords)
+ {
+ item = inv->findItem(*it, 0);
+ if (item)
+ break;
+ }
// no swords
if (!item)
@@ -2366,10 +2358,14 @@ void LocalPlayer::changeEquipmentBeforeAttack(const Being *const target) const
// if need equip shield too
if (mAttackWeaponType == 3)
{
- // finding shield
- item = inv->findItem(601, 0);
- if (!item)
- item = inv->findItem(602, 0);
+ // searching shield
+ const WeaponsInfos &shields = WeaponsDB::getShields();
+ FOR_EACH (WeaponsInfosIter, it, shields)
+ {
+ item = inv->findItem(*it, 0);
+ if (item)
+ break;
+ }
if (item && !item->isEquipped())
PlayerInfo::equipItem(item, true);
}
@@ -2377,11 +2373,14 @@ void LocalPlayer::changeEquipmentBeforeAttack(const Being *const target) const
// big distance. allowed only bow
else
{
- // finding bow
- item = inv->findItem(545, 0);
-
- if (!item)
- item = inv->findItem(530, 0);
+ // searching bow
+ const WeaponsInfos &bows = WeaponsDB::getBows();
+ FOR_EACH (WeaponsInfosIter, it, bows)
+ {
+ item = inv->findItem(*it, 0);
+ if (item)
+ break;
+ }
// no bow
if (!item)
diff --git a/src/client.cpp b/src/client.cpp
index 1238e9b8d..990306fc1 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -108,6 +108,7 @@
#endif
#include "resources/db/palettedb.h"
#include "resources/db/petdb.h"
+#include "resources/db/weaponsdb.h"
#include "utils/base64.h"
#include "utils/cpu.h"
@@ -838,6 +839,7 @@ void Client::gameClear()
MonsterDB::unload();
NPCDB::unload();
AvatarDB::unload();
+ WeaponsDB::unload();
PaletteDB::unload();
PETDB::unload();
StatusEffect::unload();
@@ -1468,6 +1470,7 @@ int Client::gameExec()
SpecialDB::load();
#endif
AvatarDB::load();
+ WeaponsDB::load();
NPCDB::load();
PETDB::load();
EmoteDB::load();
diff --git a/src/resources/db/weaponsdb.cpp b/src/resources/db/weaponsdb.cpp
new file mode 100644
index 000000000..82892cc5f
--- /dev/null
+++ b/src/resources/db/weaponsdb.cpp
@@ -0,0 +1,81 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2014 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/db/weaponsdb.h"
+
+#include "logger.h"
+
+#include "utils/gettext.h"
+#include "utils/xmlutils.h"
+
+#include "configuration.h"
+
+#include "debug.h"
+
+namespace
+{
+ WeaponsInfos mBows;
+ WeaponsInfos mSwords;
+ WeaponsInfos mShields;
+ bool mLoaded = false;
+}
+
+static void loadDB(const std::string name, WeaponsInfos &arr)
+{
+ readXmlIntVector("weapons.xml",
+ "weapons",
+ name,
+ "item",
+ "id",
+ arr);
+}
+
+void WeaponsDB::load()
+{
+ if (mLoaded)
+ unload();
+
+ loadDB("swords", mSwords);
+ loadDB("bows", mBows);
+ loadDB("shields", mShields);
+}
+
+void WeaponsDB::unload()
+{
+ mBows.clear();
+ mSwords.clear();
+ mShields.clear();
+ mLoaded = false;
+}
+
+const WeaponsInfos &WeaponsDB::getBows()
+{
+ return mBows;
+}
+
+const WeaponsInfos &WeaponsDB::getSwords()
+{
+ return mSwords;
+}
+
+const WeaponsInfos &WeaponsDB::getShields()
+{
+ return mShields;
+}
diff --git a/src/resources/db/weaponsdb.h b/src/resources/db/weaponsdb.h
new file mode 100644
index 000000000..287237c48
--- /dev/null
+++ b/src/resources/db/weaponsdb.h
@@ -0,0 +1,45 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2014 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_DB_WEAPONSDB_H
+#define RESOURCES_DB_WEAPONSDB_H
+
+#include <string>
+#include <vector>
+
+#include "localconsts.h"
+
+typedef std::vector<int> WeaponsInfos;
+typedef WeaponsInfos::const_iterator WeaponsInfosIter;
+
+namespace WeaponsDB
+{
+ void load();
+
+ void unload();
+
+ const WeaponsInfos &getBows();
+
+ const WeaponsInfos &getSwords();
+
+ const WeaponsInfos &getShields();
+} // namespace WeaponsDB
+
+#endif // RESOURCES_DB_WEAPONSDB_H