GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/progs/manaplus/actions/move.cpp Lines: 1 118 0.8 %
Date: 2017-11-29 Branches: 0 100 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/move.h"
22
23
#include "game.h"
24
25
#include "actions/actiondef.h"
26
#include "actions/pets.h"
27
28
#include "being/crazymoves.h"
29
#include "being/localplayer.h"
30
31
#include "enums/being/beingdirection.h"
32
33
#include "gui/windows/socialwindow.h"
34
#include "gui/windows/npcdialog.h"
35
#include "gui/windows/outfitwindow.h"
36
37
#include "gui/popups/popupmenu.h"
38
39
#include "input/inputactionoperators.h"
40
41
#include "net/playerhandler.h"
42
43
#include "debug.h"
44
45
namespace Actions
46
{
47
48
static bool closeMoveNpcDialog(bool focus)
49
{
50
    NpcDialog *const dialog = NpcDialog::getActive();
51
    if (dialog != nullptr)
52
    {
53
        if (dialog->isCloseState() != 0)
54
        {
55
            dialog->closeDialog();
56
            return true;
57
        }
58
        else if (focus)
59
        {
60
            dialog->refocus();
61
        }
62
    }
63
    return false;
64
}
65
66
impHandler(moveUp)
67
{
68
    if (inputManager.isActionActive(InputAction::EMOTE))
69
        return directUp(event);
70
    else if (inputManager.isActionActive(InputAction::PET_EMOTE))
71
        return petDirectUp(event);
72
    else if (inputManager.isActionActive(InputAction::STOP_ATTACK))
73
        return petMoveUp(event);
74
    else if (!localPlayer->canMove())
75
        return directUp(event);
76
    if (popupMenu->isPopupVisible())
77
    {
78
        popupMenu->moveUp();
79
        return true;
80
    }
81
    return closeMoveNpcDialog(false);
82
}
83
84
impHandler(moveDown)
85
{
86
    if (inputManager.isActionActive(InputAction::EMOTE))
87
        return directDown(event);
88
    else if (inputManager.isActionActive(InputAction::PET_EMOTE))
89
        return petDirectDown(event);
90
    else if (inputManager.isActionActive(InputAction::STOP_ATTACK))
91
        return petMoveDown(event);
92
    else if (!localPlayer->canMove())
93
        return directDown(event);
94
    if (popupMenu->isPopupVisible())
95
    {
96
        popupMenu->moveDown();
97
        return true;
98
    }
99
    return closeMoveNpcDialog(false);
100
}
101
102
impHandler(moveLeft)
103
{
104
    if (outfitWindow != nullptr &&
105
        inputManager.isActionActive(InputAction::WEAR_OUTFIT))
106
    {
107
        outfitWindow->wearPreviousOutfit();
108
        if (Game::instance() != nullptr)
109
            Game::instance()->setValidSpeed();
110
        return true;
111
    }
112
    if (inputManager.isActionActive(InputAction::EMOTE))
113
        return directLeft(event);
114
    else if (inputManager.isActionActive(InputAction::PET_EMOTE))
115
        return petDirectLeft(event);
116
    else if (inputManager.isActionActive(InputAction::STOP_ATTACK))
117
        return petMoveLeft(event);
118
    else if (!localPlayer->canMove())
119
        return directLeft(event);
120
    return closeMoveNpcDialog(false);
121
}
122
123
impHandler(moveRight)
124
{
125
    if (outfitWindow != nullptr &&
126
        inputManager.isActionActive(InputAction::WEAR_OUTFIT))
127
    {
128
        outfitWindow->wearNextOutfit();
129
        if (Game::instance() != nullptr)
130
            Game::instance()->setValidSpeed();
131
        return true;
132
    }
133
    if (inputManager.isActionActive(InputAction::EMOTE))
134
        return directRight(event);
135
    else if (inputManager.isActionActive(InputAction::PET_EMOTE))
136
        return petDirectRight(event);
137
    else if (inputManager.isActionActive(InputAction::STOP_ATTACK))
138
        return petMoveRight(event);
139
    else if (!localPlayer->canMove())
140
        return directRight(event);
141
    return closeMoveNpcDialog(false);
142
}
143
144
impHandler(moveForward)
145
{
146
    if (inputManager.isActionActive(InputAction::EMOTE))
147
        return directRight(event);
148
    return closeMoveNpcDialog(false);
149
}
150
151
impHandler(moveToPoint)
152
{
153
    const int num = event.action - InputAction::MOVE_TO_POINT_1;
154
    if ((socialWindow != nullptr) && num >= 0)
155
    {
156
        socialWindow->selectPortal(num);
157
        return true;
158
    }
159
160
    return false;
161
}
162
163
impHandler0(crazyMoves)
164
{
165
    if (localPlayer != nullptr)
166
    {
167
        ::crazyMoves->crazyMove();
168
        return true;
169
    }
170
    return false;
171
}
172
173
impHandler0(moveToTarget)
174
{
175
    if (localPlayer != nullptr &&
176
        !inputManager.isActionActive(InputAction::TARGET_ATTACK) &&
177
        !inputManager.isActionActive(InputAction::ATTACK))
178
    {
179
        localPlayer->moveToTarget();
180
        return true;
181
    }
182
    return false;
183
}
184
185
impHandler0(moveToHome)
186
{
187
    if (localPlayer != nullptr &&
188
        !inputManager.isActionActive(InputAction::TARGET_ATTACK) &&
189
        !inputManager.isActionActive(InputAction::ATTACK))
190
    {
191
        localPlayer->moveToHome();
192
        if (Game::instance() != nullptr)
193
            Game::instance()->setValidSpeed();
194
        return true;
195
    }
196
    return false;
197
}
198
199
impHandler0(directUp)
200
{
201
    if (localPlayer != nullptr)
202
    {
203
        if (localPlayer->getDirection() != BeingDirection::UP)
204
        {
205
//            if (PacketLimiter::limitPackets(PacketType::PACKET_DIRECTION))
206
            {
207
                localPlayer->setDirection(BeingDirection::UP);
208
                if (playerHandler != nullptr)
209
                    playerHandler->setDirection(BeingDirection::UP);
210
            }
211
        }
212
        return true;
213
    }
214
    return false;
215
}
216
217
impHandler0(directDown)
218
{
219
    if (localPlayer != nullptr)
220
    {
221
        if (localPlayer->getDirection() != BeingDirection::DOWN)
222
        {
223
//            if (PacketLimiter::limitPackets(PacketType::PACKET_DIRECTION))
224
            {
225
                localPlayer->setDirection(BeingDirection::DOWN);
226
                if (playerHandler != nullptr)
227
                {
228
                    playerHandler->setDirection(
229
                        BeingDirection::DOWN);
230
                }
231
            }
232
        }
233
        return true;
234
    }
235
    return false;
236
}
237
238
impHandler0(directLeft)
239
{
240
    if (localPlayer != nullptr)
241
    {
242
        if (localPlayer->getDirection() != BeingDirection::LEFT)
243
        {
244
//            if (PacketLimiter::limitPackets(PacketType::PACKET_DIRECTION))
245
            {
246
                localPlayer->setDirection(BeingDirection::LEFT);
247
                if (playerHandler != nullptr)
248
                {
249
                    playerHandler->setDirection(
250
                        BeingDirection::LEFT);
251
                }
252
            }
253
        }
254
        return true;
255
    }
256
    return false;
257
}
258
259
impHandler0(directRight)
260
{
261
    if (localPlayer != nullptr)
262
    {
263
        if (localPlayer->getDirection() != BeingDirection::RIGHT)
264
        {
265
//            if (PacketLimiter::limitPackets(PacketType::PACKET_DIRECTION))
266
            {
267
                localPlayer->setDirection(BeingDirection::RIGHT);
268
                if (playerHandler != nullptr)
269
                {
270
                    playerHandler->setDirection(
271
                        BeingDirection::RIGHT);
272
                }
273
            }
274
        }
275
        return true;
276
    }
277
    return false;
278
}
279
280
4
}  // namespace Actions