ManaPlus
move.cpp
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2012-2019 The ManaPlus Developers
4  * Copyright (C) 2019-2021 Andrei Karas
5  *
6  * This file is part of The ManaPlus 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 "actions/move.h"
23 
24 #include "game.h"
25 
26 #include "actions/actiondef.h"
27 #include "actions/pets.h"
28 
29 #include "being/crazymoves.h"
30 #include "being/localplayer.h"
31 
33 
35 #include "gui/windows/npcdialog.h"
37 
38 #include "gui/popups/popupmenu.h"
39 
41 
42 #include "net/playerhandler.h"
43 
44 #include "debug.h"
45 
46 namespace Actions
47 {
48 
49 static bool closeMoveNpcDialog(bool focus)
50 {
51  NpcDialog *const dialog = NpcDialog::getActive();
52  if (dialog != nullptr)
53  {
54  if (dialog->isCloseState() != 0)
55  {
56  dialog->closeDialog();
57  return true;
58  }
59  else if (focus)
60  {
61  dialog->refocus();
62  }
63  }
64  return false;
65 }
66 
68 {
70  return directUp(event);
72  return petDirectUp(event);
74  return petMoveUp(event);
75  else if (!localPlayer->canMove())
76  return directUp(event);
78  {
79  popupMenu->moveUp();
80  return true;
81  }
82  return closeMoveNpcDialog(false);
83 }
84 
86 {
88  return directDown(event);
90  return petDirectDown(event);
92  return petMoveDown(event);
93  else if (!localPlayer->canMove())
94  return directDown(event);
96  {
98  return true;
99  }
100  return closeMoveNpcDialog(false);
101 }
102 
104 {
105  if (outfitWindow != nullptr &&
107  {
109  if (Game::instance() != nullptr)
111  return true;
112  }
114  return directLeft(event);
116  return petDirectLeft(event);
118  return petMoveLeft(event);
119  else if (!localPlayer->canMove())
120  return directLeft(event);
121  return closeMoveNpcDialog(false);
122 }
123 
125 {
126  if (outfitWindow != nullptr &&
128  {
130  if (Game::instance() != nullptr)
132  return true;
133  }
135  return directRight(event);
137  return petDirectRight(event);
139  return petMoveRight(event);
140  else if (!localPlayer->canMove())
141  return directRight(event);
142  return closeMoveNpcDialog(false);
143 }
144 
146 {
148  return directRight(event);
149  return closeMoveNpcDialog(false);
150 }
151 
153 {
154  const int num = event.action - InputAction::MOVE_TO_POINT_1;
155  if ((socialWindow != nullptr) && num >= 0)
156  {
158  return true;
159  }
160 
161  return false;
162 }
163 
165 {
166  if (localPlayer != nullptr)
167  {
168  ::crazyMoves->crazyMove();
169  return true;
170  }
171  return false;
172 }
173 
175 {
176  if (localPlayer != nullptr &&
179  {
181  return true;
182  }
183  return false;
184 }
185 
187 {
188  if (localPlayer != nullptr &&
191  {
193  if (Game::instance() != nullptr)
195  return true;
196  }
197  return false;
198 }
199 
201 {
202  if (localPlayer != nullptr)
203  {
205  {
206 // if (PacketLimiter::limitPackets(PacketType::PACKET_DIRECTION))
207  {
209  if (playerHandler != nullptr)
211  }
212  }
213  return true;
214  }
215  return false;
216 }
217 
219 {
220  if (localPlayer != nullptr)
221  {
223  {
224 // if (PacketLimiter::limitPackets(PacketType::PACKET_DIRECTION))
225  {
227  if (playerHandler != nullptr)
228  {
231  }
232  }
233  }
234  return true;
235  }
236  return false;
237 }
238 
240 {
241  if (localPlayer != nullptr)
242  {
244  {
245 // if (PacketLimiter::limitPackets(PacketType::PACKET_DIRECTION))
246  {
248  if (playerHandler != nullptr)
249  {
252  }
253  }
254  }
255  return true;
256  }
257  return false;
258 }
259 
261 {
262  if (localPlayer != nullptr)
263  {
265  {
266 // if (PacketLimiter::limitPackets(PacketType::PACKET_DIRECTION))
267  {
269  if (playerHandler != nullptr)
270  {
273  }
274  }
275  }
276  return true;
277  }
278  return false;
279 }
280 
281 } // namespace Actions
#define impHandler0(name)
Definition: actiondef.h:34
#define impHandler(name)
Definition: actiondef.h:33
virtual void setDirection(const uint8_t direction)
Definition: being.cpp:1690
uint8_t getDirection() const
Definition: being.h:494
static Game * instance()
Definition: game.h:82
void setValidSpeed()
Definition: game.cpp:1273
bool isActionActive(const InputActionT index) const
void moveToTarget(int dist)
void moveToHome()
bool canMove() const
virtual void setDirection(const unsigned char direction) const =0
static NpcDialog * getActive()
Definition: npcdialog.cpp:852
int isCloseState() const
Definition: npcdialog.h:228
void refocus()
Definition: npcdialog.cpp:741
void closeDialog()
Definition: npcdialog.cpp:665
void wearNextOutfit(const bool all)
void wearPreviousOutfit(const bool all)
void moveUp()
Definition: popupmenu.cpp:3620
void moveDown()
Definition: popupmenu.cpp:3625
bool isPopupVisible() const
Definition: popup.h:174
void selectPortal(const unsigned num)
InputManager inputManager
LocalPlayer * localPlayer
bool directLeft(InputEvent &event)
Definition: move.cpp:42
bool petDirectRight(InputEvent &event)
Definition: pets.cpp:43
bool moveDown(InputEvent &event)
Definition: move.cpp:32
static bool closeMoveNpcDialog(bool focus)
Definition: move.cpp:49
bool petMoveLeft(InputEvent &event)
Definition: pets.cpp:38
bool moveLeft(InputEvent &event)
Definition: move.cpp:33
bool directDown(InputEvent &event)
Definition: move.cpp:41
bool petMoveDown(InputEvent &event)
Definition: pets.cpp:37
bool moveToHome(InputEvent &event)
Definition: move.cpp:39
bool moveRight(InputEvent &event)
Definition: move.cpp:34
bool moveToTarget(InputEvent &event)
Definition: move.cpp:38
bool petDirectLeft(InputEvent &event)
Definition: pets.cpp:42
bool moveUp(InputEvent &event)
Definition: move.cpp:31
bool directUp(InputEvent &event)
Definition: move.cpp:40
bool moveToPoint(InputEvent &event)
Definition: move.cpp:36
bool crazyMoves(InputEvent &event)
Definition: move.cpp:37
bool petMoveUp(InputEvent &event)
Definition: pets.cpp:36
bool petDirectDown(InputEvent &event)
Definition: pets.cpp:41
bool petMoveRight(InputEvent &event)
Definition: pets.cpp:39
bool directRight(InputEvent &event)
Definition: move.cpp:43
bool moveForward(InputEvent &event)
Definition: move.cpp:35
bool petDirectUp(InputEvent &event)
Definition: pets.cpp:40
Net::PlayerHandler * playerHandler
Definition: net.cpp:96
OutfitWindow * outfitWindow
PopupMenu * popupMenu
Definition: popupmenu.cpp:103
SocialWindow * socialWindow