GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/progs/manaplus/actions/target.cpp Lines: 1 24 4.2 %
Date: 2017-11-29 Branches: 0 18 0.0 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2012-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 "actions/target.h"
22
23
#include "actions/actiondef.h"
24
25
#include "being/localplayer.h"
26
27
#include "gui/popups/popupmenu.h"
28
29
#include "debug.h"
30
31
namespace Actions
32
{
33
34
static bool setTarget(const ActorTypeT type, const AllowSort allowSort)
35
{
36
    if (localPlayer != nullptr)
37
        return localPlayer->setNewTarget(type, allowSort) != nullptr;
38
    return false;
39
}
40
41
impHandler0(targetPlayer)
42
{
43
    return setTarget(ActorType::Player, AllowSort_true);
44
}
45
46
impHandler0(targetMonster)
47
{
48
    return setTarget(ActorType::Monster, AllowSort_true);
49
}
50
51
impHandler0(targetClosestMonster)
52
{
53
    return setTarget(ActorType::Monster, AllowSort_false);
54
}
55
56
impHandler0(targetNPC)
57
{
58
    return setTarget(ActorType::Npc, AllowSort_true);
59
}
60
61
impHandler0(targetMercenary)
62
{
63
    return setTarget(ActorType::Mercenary, AllowSort_true);
64
}
65
66
impHandler0(targetSkillUnit)
67
{
68
    return setTarget(ActorType::SkillUnit, AllowSort_true);
69
}
70
71
impHandler0(targetPet)
72
{
73
    return setTarget(ActorType::Pet, AllowSort_true);
74
}
75
76
impHandler0(contextMenu)
77
{
78
    if (localPlayer == nullptr)
79
        return false;
80
    const Being *const target = localPlayer->getTarget();
81
    if (target == nullptr)
82
        return true;
83
84
    popupMenu->showPopup(target->getPixelX(),
85
        target->getPixelY(),
86
        target);
87
    return true;
88
}
89
90
4
}  // namespace Actions