GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/resources/db/weaponsdb.cpp Lines: 11 27 40.7 %
Date: 2021-03-17 Branches: 2 22 9.1 %

Line Branch Exec Source
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
{
33
1
    WeaponsInfos mBows;
34
1
    WeaponsInfos mSwords;
35
1
    WeaponsInfos mShields;
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,
48
        SkipError_false);
49
}
50
51
void WeaponsDB::load()
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
63
204
void WeaponsDB::unload()
64
{
65
204
    logger->log1("Unloading weapon database...");
66
67
204
    mBows.clear();
68
204
    mSwords.clear();
69
204
    mShields.clear();
70
204
    mLoaded = false;
71
204
}
72
73
const WeaponsInfos &WeaponsDB::getBows()
74
{
75
    return mBows;
76
}
77
78
const WeaponsInfos &WeaponsDB::getSwords()
79
{
80
    return mSwords;
81
}
82
83
const WeaponsInfos &WeaponsDB::getShields()
84
{
85
    return mShields;
86

3
}