Mana
Loading...
Searching...
No Matches
npcdb.cpp
Go to the documentation of this file.
1/*
2 * The Mana Client
3 * Copyright (C) 2008-2009 The Mana World Development Team
4 * Copyright (C) 2009-2013 The Mana Developers
5 *
6 * This file is part of The Mana 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/npcdb.h"
23
24#include "log.h"
25
26#include "resources/beinginfo.h"
27
28#include "utils/dtor.h"
29#include "utils/xml.h"
30
31namespace
32{
33 std::map<int, BeingInfo *> mNPCInfos;
34 bool mLoaded = false;
35}
36
37
39{
40 if (mLoaded)
41 unload();
42}
43
44void NPCDB::readNPCNode(XML::Node node, const std::string &filename)
45{
46 int id = node.getProperty("id", 0);
47 if (id == 0)
48 {
49 Log::info("NPC Database: NPC with missing ID in %s", filename.c_str());
50 return;
51 }
52
53 auto *currentInfo = new BeingInfo;
54
55 currentInfo->setTargetCursorSize(node.getProperty("targetCursor", "medium"));
56 currentInfo->setHoverCursor(node.getProperty("hoverCursor", "talk"));
57
58 currentInfo->targetSelection = node.getProperty("targetSelection", true);
59
60 SpriteDisplay &display = currentInfo->display;
61 for (auto spriteNode : node.children())
62 {
63 if (spriteNode.name() == "sprite")
64 {
65 SpriteReference &currentSprite = display.sprites.emplace_back();
66 currentSprite.sprite = spriteNode.textContent();
67 currentSprite.variant = spriteNode.getProperty("variant", 0);
68 }
69 else if (spriteNode.name() == "particlefx")
70 {
71 display.particles.emplace_back(spriteNode.textContent());
72 }
73 }
74
75 mNPCInfos[id] = currentInfo;
76}
77
79{
80 mLoaded = true;
81}
82
84{
85 delete_all(mNPCInfos);
86 mNPCInfos.clear();
87
88 mLoaded = false;
89}
90
92{
93 auto i = mNPCInfos.find(id);
94
95 if (i == mNPCInfos.end())
96 {
97 Log::info("NPCDB: Warning, unknown NPC ID %d requested", id);
98 return BeingInfo::Unknown;
99 }
100
101 return i->second;
102}
Holds information about a certain type of monster.
Definition beinginfo.h:59
static BeingInfo * Unknown
Definition beinginfo.h:61
void setTargetCursorSize(const std::string &size)
Definition beinginfo.cpp:71
int getProperty(const char *name, int def) const
Definition xml.h:144
Children children() const
Definition xml.h:97
void delete_all(Container &c)
Definition dtor.h:46
void info(const char *log_text,...) LOG_PRINTF_ATTR
void unload()
Definition npcdb.cpp:83
void checkStatus()
Definition npcdb.cpp:78
BeingInfo * get(int id)
Definition npcdb.cpp:91
void init()
Definition npcdb.cpp:38
void readNPCNode(XML::Node node, const std::string &filename)
Definition npcdb.cpp:44
std::vector< SpriteReference > sprites
Definition spritedef.h:44
std::vector< std::string > particles
Definition spritedef.h:45
std::string sprite
Definition spritedef.h:37