GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/resources/beingcommon.cpp Lines: 0 114 0.0 %
Date: 2017-11-29 Branches: 0 170 0.0 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2013-2017  The ManaPlus Developers
4
 *
5
 *  This file is part of The ManaPlus 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/beingcommon.h"
22
23
#include "configuration.h"
24
#include "logger.h"
25
26
#include "enums/resources/map/blockmask.h"
27
28
#include "utils/cast.h"
29
30
#include "resources/beinginfo.h"
31
32
#include "resources/sprite/spritereference.h"
33
34
#include "debug.h"
35
36
void BeingCommon::readBasicAttributes(BeingInfo *const info,
37
                                      XmlNodePtrConst node,
38
                                      const std::string &hoverCursor)
39
{
40
    info->setTargetCursorSize(XML::getProperty(node,
41
        "targetCursor", "medium"));
42
43
    info->setHoverCursor(XML::getProperty(node, "hoverCursor", hoverCursor));
44
45
    info->setTargetOffsetX(XML::getProperty(node, "targetOffsetX", 0));
46
    info->setTargetOffsetY(XML::getProperty(node, "targetOffsetY", 0));
47
48
    info->setNameOffsetX(XML::getProperty(node, "nameOffsetX", 0));
49
    info->setNameOffsetY(XML::getProperty(node, "nameOffsetY", 0));
50
    info->setSortOffsetY(XML::getProperty(node, "sortOffsetY", 0));
51
52
    info->setHpBarOffsetX(XML::getProperty(node, "hpBarOffsetX", 0));
53
    info->setHpBarOffsetY(XML::getProperty(node, "hpBarOffsetY", 0));
54
55
    info->setQuickActionEffectId(XML::getProperty(node,
56
        "quickActionEffect", -1));
57
}
58
59
void BeingCommon::readWalkingAttributes(BeingInfo *const info,
60
                                        XmlNodePtrConst node,
61
                                        const int moreBlockFlags)
62
{
63
    uint8_t block = 0;
64
    std::string walkStr = XML::getProperty(
65
        node, "walkType", "walk");
66
67
    const uint8_t allFlags = CAST_U8(
68
        BlockMask::GROUND |
69
        BlockMask::WALL |
70
        BlockMask::WATER |
71
        BlockMask::AIR |
72
        moreBlockFlags);
73
    StringVect tokens;
74
    splitToStringVector(tokens, walkStr, ',');
75
    FOR_EACH (StringVectCIter, it, tokens)
76
    {
77
        if (walkStr == "walk" || walkStr == "ground")
78
            block |= BlockMask::GROUND;
79
        else if (walkStr == "fly" || walkStr == "air")
80
            block |= BlockMask::GROUND | BlockMask::WATER | BlockMask::AIR;
81
        else if (walkStr == "all")
82
            block |= allFlags;
83
        else if (walkStr == "wall")
84
            block |= BlockMask::WALL;
85
        else if (walkStr == "monsterwall")
86
            block |= BlockMask::MONSTERWALL;
87
        else if (walkStr == "swim" || walkStr == "water")
88
            block |= BlockMask::WATER;
89
        else if (walkStr == "walkswim" || walkStr == "swimwalk")  // legacy
90
            block |= BlockMask::GROUND | BlockMask::WATER;
91
    }
92
    info->setBlockWalkMask(CAST_U8(block ^ allFlags));
93
}
94
95
void BeingCommon::readAiAttributes(BeingInfo *const info,
96
                                   XmlNodePtrConst node)
97
{
98
    info->setStartFollowDist(XML::getProperty(node,
99
        "startFollowDistance", 3));
100
    info->setFollowDist(XML::getProperty(node,
101
        "followDistance", 0));
102
    info->setWarpDist(XML::getProperty(node,
103
        "warpDistance", 11));
104
105
    info->setTargetOffsetX(XML::getProperty(node,
106
        "offsetX", 0));
107
    info->setTargetOffsetY(XML::getProperty(node,
108
        "offsetY", 1));
109
    info->setSitOffsetX(XML::getProperty(node,
110
        "sitOffsetX", 0));
111
    info->setSitOffsetY(XML::getProperty(node,
112
        "sitOffsetY", 1));
113
    info->setMoveOffsetX(XML::getProperty(node,
114
        "moveOffsetX", 0));
115
    info->setMoveOffsetY(XML::getProperty(node,
116
        "moveOffsetY", 1));
117
    info->setDeadOffsetX(XML::getProperty(node,
118
        "deadOffsetX", 0));
119
    info->setDeadOffsetY(XML::getProperty(node,
120
        "deadOffsetY", 1));
121
    info->setAttackOffsetX(XML::getProperty(node,
122
        "attackOffsetX", info->getTargetOffsetX()));
123
    info->setAttackOffsetY(XML::getProperty(node,
124
        "attackOffsetY", info->getTargetOffsetY()));
125
126
    info->setThinkTime(XML::getProperty(node,
127
        "thinkTime", 500) / 10);
128
129
    info->setDirectionType(XML::getProperty(node,
130
        "directionType", 1));
131
    info->setSitDirectionType(XML::getProperty(node,
132
        "sitDirectionType", 1));
133
    info->setDeadDirectionType(XML::getProperty(node,
134
        "deadDirectionType", 1));
135
    info->setAttackDirectionType(XML::getProperty(node,
136
        "attackDirectionType", 4));
137
}
138
139
bool BeingCommon::readObjectNodes(XmlNodePtrConst &spriteNode,
140
                                  SpriteDisplay &display,
141
                                  BeingInfo *const currentInfo,
142
                                  const std::string &dbName)
143
{
144
    if (xmlNameEqual(spriteNode, "sprite"))
145
    {
146
        if (!XmlHaveChildContent(spriteNode))
147
            return true;
148
149
        SpriteReference *const currentSprite = new SpriteReference;
150
        currentSprite->sprite = XmlChildContent(spriteNode);
151
152
        currentSprite->variant = XML::getProperty(
153
            spriteNode, "variant", 0);
154
        display.sprites.push_back(currentSprite);
155
        return true;
156
    }
157
    else if (xmlNameEqual(spriteNode, "sound"))
158
    {
159
        if (!XmlHaveChildContent(spriteNode))
160
            return true;
161
162
        const std::string event = XML::getProperty(
163
            spriteNode, "event", "");
164
        const int delay = XML::getProperty(
165
            spriteNode, "delay", 0);
166
        const char *const filename = XmlChildContent(spriteNode);
167
168
        if (event == "hit")
169
        {
170
            currentInfo->addSound(ItemSoundEvent::HIT, filename, delay);
171
        }
172
        else if (event == "miss")
173
        {
174
            currentInfo->addSound(ItemSoundEvent::MISS, filename, delay);
175
        }
176
        else if (event == "hurt")
177
        {
178
            currentInfo->addSound(ItemSoundEvent::HURT, filename, delay);
179
        }
180
        else if (event == "die")
181
        {
182
            currentInfo->addSound(ItemSoundEvent::DIE, filename, delay);
183
        }
184
        else if (event == "move")
185
        {
186
            currentInfo->addSound(ItemSoundEvent::MOVE, filename, delay);
187
        }
188
        else if (event == "sit")
189
        {
190
            currentInfo->addSound(ItemSoundEvent::SIT, filename, delay);
191
        }
192
        else if (event == "sittop")
193
        {
194
            currentInfo->addSound(ItemSoundEvent::SITTOP, filename, delay);
195
        }
196
        else if (event == "spawn")
197
        {
198
            currentInfo->addSound(ItemSoundEvent::SPAWN, filename, delay);
199
        }
200
        else
201
        {
202
            logger->log((dbName + ": Warning, sound effect %s for "
203
                "unknown event %s of monster %s").c_str(),
204
                filename, event.c_str(),
205
                currentInfo->getName().c_str());
206
        }
207
        return true;
208
    }
209
    else if (xmlNameEqual(spriteNode, "attack"))
210
    {
211
        const int attackId = XML::getProperty(spriteNode, "id", 0);
212
        const int effectId = XML::getProperty(spriteNode, "effect-id",
213
            paths.getIntValue("effectId"));
214
        const int hitEffectId = XML::getProperty(spriteNode, "hit-effect-id",
215
            paths.getIntValue("hitEffectId"));
216
        const int criticalHitEffectId = XML::getProperty(spriteNode,
217
            "critical-hit-effect-id",
218
            paths.getIntValue("criticalHitEffectId"));
219
        const int missEffectId = XML::getProperty(spriteNode, "miss-effect-id",
220
            paths.getIntValue("missEffectId"));
221
222
        const std::string spriteAction = XML::getProperty(spriteNode, "action",
223
            "attack");
224
        const std::string skySpriteAction = XML::getProperty(spriteNode,
225
            "skyaction", "skyattack");
226
        const std::string waterSpriteAction = XML::getProperty(spriteNode,
227
            "wateraction", "waterattack");
228
        const std::string rideSpriteAction = XML::getProperty(spriteNode,
229
            "rideaction", "rideattack");
230
231
        const std::string missileParticle = XML::getProperty(spriteNode,
232
            "missile-particle", "");
233
234
        const float missileZ = XML::getFloatProperty(
235
            spriteNode, "missile-z", 32.0f);
236
        const int missileLifeTime = XML::getProperty(
237
            spriteNode, "missile-lifetime", 500);
238
        const float missileSpeed = XML::getFloatProperty(
239
            spriteNode, "missile-speed", 7.0f);
240
        const float missileDieDistance = XML::getFloatProperty(
241
            spriteNode, "missile-diedistance", 8.0f);
242
243
        currentInfo->addAttack(attackId,
244
            spriteAction,
245
            skySpriteAction,
246
            waterSpriteAction,
247
            rideSpriteAction,
248
            effectId,
249
            hitEffectId,
250
            criticalHitEffectId,
251
            missEffectId,
252
            missileParticle,
253
            missileZ,
254
            missileSpeed,
255
            missileDieDistance,
256
            missileLifeTime);
257
        return true;
258
    }
259
    else if (xmlNameEqual(spriteNode, "particlefx"))
260
    {
261
        if (!XmlHaveChildContent(spriteNode))
262
            return true;
263
264
        display.particles.push_back(XmlChildContent(spriteNode));
265
        return true;
266
    }
267
    return false;
268
}