Mana
Loading...
Searching...
No Matches
abilitydb.cpp
Go to the documentation of this file.
1/*
2 * The Mana Client
3 * Copyright (C) 2010-2013 The Mana Developers
4 *
5 * This file is part of The Mana Client.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#include "resources/abilitydb.h"
22
23#include "log.h"
24
25#include "utils/dtor.h"
26
27#include <map>
28
29namespace
30{
31 std::map<int, AbilityInfo *> mAbilityInfos;
32 bool mLoaded = false;
33}
34
35static AbilityInfo::TargetMode targetModeFromString(const std::string& str)
36{
37 if (str == "being")
39 if (str == "point")
41 if (str == "direction")
43
44 Log::info("AbilityDB: Warning, unknown target mode \"%s\"", str.c_str() );
46}
47
48
50{
51 if (mLoaded)
52 unload();
53}
54
55void AbilityDB::readAbilityNode(XML::Node node, const std::string &filename)
56{
57 auto *info = new AbilityInfo();
58 int id = node.getProperty("id", 0);
59 info->id = id;
60 info->name = node.getProperty("name", std::string());
61 info->icon = node.getProperty("icon", std::string());
62 info->useAction = node.getProperty("useaction", std::string());
63
64 info->targetMode = targetModeFromString(node.getProperty("target", "being"));
65
66 info->rechargeable = node.getBoolProperty("rechargeable", true);
67 info->rechargeNeeded = 0;
68 info->rechargeCurrent = 0;
69
70 if (mAbilityInfos.find(id) != mAbilityInfos.end())
71 Log::info("AbilityDB: Duplicate ability ID %d in %s, ignoring", id, filename.c_str());
72 else
73 mAbilityInfos[id] = info;
74}
75
77{
78 mLoaded = true;
79}
80
82{
83 delete_all(mAbilityInfos);
84 mAbilityInfos.clear();
85
86 mLoaded = false;
87}
88
90{
91 auto i = mAbilityInfos.find(id);
92 if (i != mAbilityInfos.end())
93 return i->second;
94
95 return nullptr;
96}
97
98AbilityInfo *AbilityDB::find(std::string_view name)
99{
100 for (auto &[_, abilityInfo] : mAbilityInfos)
101 {
102 if (abilityInfo->name == name)
103 return abilityInfo;
104 }
105 return nullptr;
106}
int getProperty(const char *name, int def) const
Definition xml.h:144
bool getBoolProperty(const char *name, bool def) const
Definition xml.h:168
void delete_all(Container &c)
Definition dtor.h:46
#define _(s)
Definition gettext.h:38
void unload()
Definition abilitydb.cpp:81
AbilityInfo * find(std::string_view name)
Finds an ability by name.
Definition abilitydb.cpp:98
void checkStatus()
Definition abilitydb.cpp:76
void init()
Definition abilitydb.cpp:49
AbilityInfo * get(int id)
Gets the ability info for ID.
Definition abilitydb.cpp:89
void readAbilityNode(XML::Node node, const std::string &filename)
Definition abilitydb.cpp:55
void info(const char *log_text,...) LOG_PRINTF_ATTR
@ TARGET_DIRECTION
Definition abilitydb.h:32