ManaPlus
weaponsdb.cpp
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2014-2019 The ManaPlus Developers
4  * Copyright (C) 2019-2021 Andrei Karas
5  *
6  * This file is part of The ManaPlus Client.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
22 #include "resources/db/weaponsdb.h"
23 
24 #include "configuration.h"
25 #include "logger.h"
26 
27 #include "utils/xmlutils.h"
28 
29 #include "debug.h"
30 
31 namespace
32 {
36  bool mLoaded = false;
37 } // namespace
38 
39 static void loadDB(const std::string &name,
40  WeaponsInfos &arr)
41 {
42  readXmlIntVector(paths.getStringValue("weaponsFile"),
43  "weapons",
44  name,
45  "item",
46  "id",
47  arr,
49 }
50 
52 {
53  if (mLoaded)
54  unload();
55 
56  logger->log1("Initializing weapon database...");
57 
58  loadDB("swords", mSwords);
59  loadDB("bows", mBows);
60  loadDB("shields", mShields);
61 }
62 
64 {
65  logger->log1("Unloading weapon database...");
66 
67  mBows.clear();
68  mSwords.clear();
69  mShields.clear();
70  mLoaded = false;
71 }
72 
74 {
75  return mBows;
76 }
77 
79 {
80  return mSwords;
81 }
82 
84 {
85  return mShields;
86 }
std::string getStringValue(const std::string &key) const
void log1(const char *const log_text)
Definition: logger.cpp:238
Configuration paths
Logger * logger
Definition: logger.cpp:89
void unload()
Definition: net.cpp:180
void load()
Definition: weaponsdb.cpp:51
void unload()
Definition: weaponsdb.cpp:63
const WeaponsInfos & getShields()
Definition: weaponsdb.cpp:83
const WeaponsInfos & getSwords()
Definition: weaponsdb.cpp:78
const WeaponsInfos & getBows()
Definition: weaponsdb.cpp:73
const bool SkipError_false
Definition: skiperror.h:30
static void loadDB(const std::string &name, WeaponsInfos &arr)
Definition: weaponsdb.cpp:39
std::vector< int > WeaponsInfos
Definition: weaponsdb.h:29
void readXmlIntVector(const std::string &fileName, const std::string &rootName, const std::string &sectionName, const std::string &itemName, const std::string &attributeName, std::vector< int > &arr, const SkipError skipError)
Definition: xmlutils.cpp:30