~ubuntu-branches/ubuntu/trusty/manaplus/trusty-proposed

« back to all changes in this revision

Viewing changes to src/being/localplayer.h

  • Committer: Package Import Robot
  • Author(s): Patrick Matthäi
  • Date: 2013-09-17 10:35:51 UTC
  • mfrom: (1.1.10)
  • Revision ID: package-import@ubuntu.com-20130917103551-az7p3nz9jgxwqjfn
Tags: 1.3.9.15-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  The ManaPlus Client
 
3
 *  Copyright (C) 2004-2009  The Mana World Development Team
 
4
 *  Copyright (C) 2009-2010  The Mana Developers
 
5
 *  Copyright (C) 2011-2013  The ManaPlus Developers
 
6
 *
 
7
 *  This file is part of The ManaPlus Client.
 
8
 *
 
9
 *  This program is free software; you can redistribute it and/or modify
 
10
 *  it under the terms of the GNU General Public License as published by
 
11
 *  the Free Software Foundation; either version 2 of the License, or
 
12
 *  any later version.
 
13
 *
 
14
 *  This program is distributed in the hope that it will be useful,
 
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
 *  GNU General Public License for more details.
 
18
 *
 
19
 *  You should have received a copy of the GNU General Public License
 
20
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
21
 */
 
22
 
 
23
#ifndef BEING_LOCALPLAYER_H
 
24
#define BEING_LOCALPLAYER_H
 
25
 
 
26
#include "depricatedlistener.h"
 
27
 
 
28
#include "being/actorspritelistener.h"
 
29
#include "being/being.h"
 
30
 
 
31
#include "gui/userpalette.h"
 
32
 
 
33
#include <guichan/actionlistener.hpp>
 
34
 
 
35
#include <vector>
 
36
 
 
37
#include "localconsts.h"
 
38
 
 
39
class ChatTab;
 
40
class FloorItem;
 
41
class Map;
 
42
class OkDialog;
 
43
 
 
44
class AwayListener final : public gcn::ActionListener
 
45
{
 
46
    public:
 
47
        void action(const gcn::ActionEvent &event) override;
 
48
};
 
49
 
 
50
/**
 
51
 * Reasons an item can fail to be picked up.
 
52
 */
 
53
enum
 
54
{
 
55
    PICKUP_OKAY = 0,
 
56
    PICKUP_BAD_ITEM,
 
57
    PICKUP_TOO_HEAVY,
 
58
    PICKUP_TOO_FAR,
 
59
    PICKUP_INV_FULL,
 
60
    PICKUP_STACK_FULL,
 
61
    PICKUP_DROP_STEAL
 
62
};
 
63
 
 
64
/**
 
65
 * The local player character.
 
66
 */
 
67
class LocalPlayer final : public Being,
 
68
                          public ActorSpriteListener,
 
69
                          public DepricatedListener
 
70
{
 
71
    public:
 
72
        /**
 
73
         * Constructor.
 
74
         */
 
75
        explicit LocalPlayer(const int id = 65535, const int subtype = 0);
 
76
 
 
77
        A_DELETE_COPY(LocalPlayer)
 
78
 
 
79
        /**
 
80
         * Destructor.
 
81
         */
 
82
        ~LocalPlayer();
 
83
 
 
84
        virtual void logic() override;
 
85
 
 
86
        void slowLogic();
 
87
 
 
88
        virtual void setAction(const Action &action,
 
89
                               const int attackType = 0) override;
 
90
 
 
91
        /**
 
92
         * Compute the next pathnode location when walking using keyboard.
 
93
         * used by nextTile().
 
94
         */
 
95
        Position getNextWalkPosition(const unsigned char dir)
 
96
                                     const A_WARN_UNUSED;
 
97
 
 
98
        /**
 
99
         * Adds a new tile to the path when walking.
 
100
         * @note Eathena
 
101
         * Also, when specified, it picks up an item at the end of a path
 
102
         * or attack target.
 
103
         */
 
104
        virtual void nextTile() override
 
105
        { nextTile(0); }
 
106
 
 
107
        virtual void nextTile(unsigned char dir);
 
108
 
 
109
        bool pickUp(FloorItem *const item);
 
110
 
 
111
        /**
 
112
         * Called when an ActorSprite has been destroyed.
 
113
         * @param actorSprite the ActorSprite being destroyed.
 
114
         */
 
115
        void actorSpriteDestroyed(const ActorSprite &actorSprite) override;
 
116
 
 
117
        /**
 
118
         * Gets the attack range.
 
119
         */
 
120
        int getAttackRange() const A_WARN_UNUSED;
 
121
 
 
122
        int getAttackRange2() const A_WARN_UNUSED;
 
123
 
 
124
        void attack(Being *const target = nullptr, const bool keep = false,
 
125
                    const bool dontChangeEquipment = false);
 
126
 
 
127
        void attack2(Being *const target = nullptr, const bool keep = false,
 
128
                     const bool dontChangeEquipment = false);
 
129
 
 
130
        void setGMLevel(const int level);
 
131
 
 
132
        int getGMLevel() const A_WARN_UNUSED
 
133
        { return mGMLevel; }
 
134
 
 
135
        void stopAttack(const bool keepAttack = false);
 
136
 
 
137
        void untarget();
 
138
 
 
139
        /**
 
140
         * Returns the current target of the player. Returns 0 if no being is
 
141
         * currently targeted.
 
142
         */
 
143
        Being *getTarget() const A_WARN_UNUSED;
 
144
 
 
145
        /**
 
146
         * Sets the target being of the player.
 
147
         */
 
148
        void setTarget(Being *const target);
 
149
 
 
150
        /**
 
151
         * Sets a new destination for this being to walk to.
 
152
         */
 
153
        virtual void setDestination(const int x, const int y);
 
154
 
 
155
        /**
 
156
         * Sets a new direction to keep walking in.
 
157
         */
 
158
        void setWalkingDir(const unsigned char dir);
 
159
 
 
160
        /**
 
161
         * Gets the walking direction
 
162
         */
 
163
        unsigned char getWalkingDir() const A_WARN_UNUSED
 
164
        { return mWalkingDir; }
 
165
 
 
166
        /**
 
167
         * Sets going to being to attack
 
168
         */
 
169
        void setGotoTarget(Being *const target);
 
170
 
 
171
        /**
 
172
         * Returns whether the target is in range to attack
 
173
         */
 
174
        bool withinAttackRange(const Being *const target,
 
175
                               const bool fixDistance = false,
 
176
                               const int addRange = 0) const A_WARN_UNUSED;
 
177
 
 
178
        /**
 
179
         * Stops the player dead in his tracks
 
180
         */
 
181
        void stopWalking(const bool sendToServer = true);
 
182
 
 
183
        bool toggleSit() const;
 
184
 
 
185
        bool updateSit() const;
 
186
 
 
187
        static bool emote(const uint8_t emotion);
 
188
 
 
189
        /**
 
190
         * Shows item pickup notifications.
 
191
         */
 
192
        void pickedUp(const ItemInfo &itemInfo, const int amount,
 
193
                      const unsigned char color, const int floorItemId,
 
194
                      const unsigned char fail);
 
195
 
 
196
        int getLevel() const override A_WARN_UNUSED;
 
197
 
 
198
        /** Tells that the path has been set by mouse. */
 
199
        void pathSetByMouse()
 
200
        { mPathSetByMouse = true; }
 
201
 
 
202
        /** Tells if the path has been set by mouse. */
 
203
        bool isPathSetByMouse() const A_WARN_UNUSED
 
204
        { return mPathSetByMouse; }
 
205
 
 
206
        int getInvertDirection() const A_WARN_UNUSED
 
207
        { return mInvertDirection; }
 
208
 
 
209
        void setInvertDirection(const int n)
 
210
        { mInvertDirection = n; }
 
211
 
 
212
        void invertDirection();
 
213
 
 
214
        int getAttackWeaponType() const A_WARN_UNUSED
 
215
        { return mAttackWeaponType; }
 
216
 
 
217
        int getAttackType() const A_WARN_UNUSED
 
218
        { return mAttackType; }
 
219
 
 
220
        int getFollowMode() const A_WARN_UNUSED
 
221
        { return mFollowMode; }
 
222
 
 
223
        int getImitationMode() const A_WARN_UNUSED
 
224
        { return mImitationMode; }
 
225
 
 
226
        void changeAttackWeaponType();
 
227
 
 
228
        void changeAttackType();
 
229
 
 
230
        void changeFollowMode();
 
231
 
 
232
        void changeImitationMode();
 
233
 
 
234
        void changePickUpType();
 
235
 
 
236
        int getCrazyMoveType() const A_WARN_UNUSED
 
237
        { return mCrazyMoveType; }
 
238
 
 
239
        int getPickUpType() const A_WARN_UNUSED
 
240
        { return mPickUpType; }
 
241
 
 
242
        int getQuickDropCounter() const A_WARN_UNUSED
 
243
        { return mQuickDropCounter; }
 
244
 
 
245
        void setQuickDropCounter(const int n);
 
246
 
 
247
        void changeQuickDropCounter();
 
248
 
 
249
        int getMoveState() const A_WARN_UNUSED
 
250
        { return mMoveState; }
 
251
 
 
252
        void setMoveState(const int n)
 
253
        { mMoveState = n; }
 
254
 
 
255
        void switchMagicAttack();
 
256
 
 
257
        void switchPvpAttack();
 
258
 
 
259
        int getMagicAttackType() const A_WARN_UNUSED
 
260
        { return mMagicAttackType; }
 
261
 
 
262
        int getPvpAttackType() const A_WARN_UNUSED
 
263
        { return mPvpAttackType; }
 
264
 
 
265
        int getMoveToTargetType() const A_WARN_UNUSED
 
266
        { return mMoveToTargetType; }
 
267
 
 
268
        int getDisableGameModifiers() const A_WARN_UNUSED
 
269
        { return mDisableGameModifiers; }
 
270
 
 
271
        std::string getPingTime() const A_WARN_UNUSED;
 
272
 
 
273
        void tryPingRequest();
 
274
 
 
275
        void changeMoveToTargetType();
 
276
 
 
277
        void switchGameModifiers();
 
278
 
 
279
        void magicAttack() const;
 
280
 
 
281
        void specialMove(const unsigned char direction);
 
282
 
 
283
        void moveByDirection(const unsigned char dir);
 
284
 
 
285
        bool pickUpItems(int pickUpType = 0);
 
286
 
 
287
        void changeCrazyMoveType();
 
288
 
 
289
        void crazyMove();
 
290
 
 
291
        void moveTo(const int x, const int y);
 
292
 
 
293
        void move(const int dX, const int dY);
 
294
 
 
295
        void moveToTarget(int dist = -1);
 
296
 
 
297
        void moveToHome();
 
298
 
 
299
        void debugMsg(const std::string &str) const;
 
300
 
 
301
        bool isReachable(Being *const being,
 
302
                         const int maxCost = 0) A_WARN_UNUSED;
 
303
 
 
304
        bool isReachable(const int x, const int y,
 
305
                         const bool allowCollision) const A_WARN_UNUSED;
 
306
 
 
307
        void setHome();
 
308
 
 
309
        void pingRequest();
 
310
 
 
311
        void pingResponse();
 
312
 
 
313
        void changeAwayMode();
 
314
 
 
315
        void setAway(const std::string &message);
 
316
 
 
317
        void setPseudoAway(const std::string &message);
 
318
 
 
319
        bool getAway() const A_WARN_UNUSED
 
320
        { return mAwayMode; }
 
321
 
 
322
        bool getPseudoAway() const A_WARN_UNUSED
 
323
        { return mPseudoAwayMode; }
 
324
 
 
325
        void setHalfAway(const bool n)
 
326
        { mInactive = n; }
 
327
 
 
328
        bool getHalfAway() const A_WARN_UNUSED
 
329
        { return mInactive; }
 
330
 
 
331
        void afkRespond(ChatTab *const tab, const std::string &nick);
 
332
 
 
333
        bool navigateTo(const int x, const int y);
 
334
 
 
335
        void navigateTo(const Being *const being);
 
336
 
 
337
        void navigateClean();
 
338
 
 
339
        void imitateEmote(const Being *const being,
 
340
                          const unsigned char emote) const;
 
341
 
 
342
        void imitateAction(const Being *const being,
 
343
                           const Being::Action &action);
 
344
 
 
345
        void imitateDirection(const Being *const being,
 
346
                              const unsigned char dir);
 
347
 
 
348
        void imitateOutfit(Being *const player, const int sprite = -1) const;
 
349
 
 
350
        void followMoveTo(const Being *const being, const int x, const int y);
 
351
 
 
352
        void followMoveTo(const Being *const being, const int x1, const int y1,
 
353
                          const int x2, const int y2);
 
354
 
 
355
        bool allowAction() A_WARN_UNUSED;
 
356
 
 
357
        void setRealPos(const int x, const int y);
 
358
 
 
359
        bool isServerBuggy() const A_WARN_UNUSED
 
360
        { return mIsServerBuggy; }
 
361
 
 
362
        void fixPos(const int maxDist = 1);
 
363
 
 
364
        /**
 
365
         * Sets the map the being is on
 
366
         */
 
367
        void setMap(Map *const map);
 
368
 
 
369
        void addMessageToQueue(const std::string &message,
 
370
                               const int color = UserPalette::EXP_INFO);
 
371
 
 
372
        /**
 
373
         * Called when a option (set with config.addListener()) is changed
 
374
         */
 
375
        void optionChanged(const std::string &value) override;
 
376
 
 
377
        void processEvent(Channels channel,
 
378
                          const DepricatedEvent &event) override;
 
379
 
 
380
        /**
 
381
         * set a following player.
 
382
         */
 
383
        void setFollow(const std::string &player);
 
384
 
 
385
        /**
 
386
         * set an imitation player.
 
387
         */
 
388
        void setImitate(const std::string &player);
 
389
 
 
390
        /**
 
391
         * setting the next destination of the following, in case of warp
 
392
         */
 
393
        void setNextDest(const int x, const int y);
 
394
 
 
395
        int getNextDestX() const A_WARN_UNUSED
 
396
        { return mNextDestX; }
 
397
 
 
398
        int getNextDestY() const A_WARN_UNUSED
 
399
        { return mNextDestY; }
 
400
 
 
401
        void respawn();
 
402
 
 
403
        const FloorItem *getPickUpTarget() const A_WARN_UNUSED
 
404
        { return mPickUpTarget; }
 
405
 
 
406
        void unSetPickUpTarget()
 
407
        { mPickUpTarget = nullptr; }
 
408
 
 
409
        /**
 
410
         * Stop following a player.
 
411
         */
 
412
        void cancelFollow();
 
413
 
 
414
        /**
 
415
         * Get the playername followed by the current player.
 
416
         */
 
417
        const std::string &getFollow() const A_WARN_UNUSED
 
418
        { return mPlayerFollowed; }
 
419
 
 
420
        /**
 
421
         * Get the playername imitated by the current player.
 
422
         */
 
423
        const std::string &getImitate() const A_WARN_UNUSED
 
424
        { return mPlayerImitated; }
 
425
 
 
426
        /**
 
427
         * Tells the engine whether to check
 
428
         * if the Player Name is to be displayed.
 
429
         */
 
430
        void setCheckNameSetting(const bool checked)
 
431
        { mUpdateName = checked; }
 
432
 
 
433
        /**
 
434
         * Gets if the engine has to check
 
435
         * if the Player Name is to be displayed.
 
436
         */
 
437
        bool getCheckNameSetting() const A_WARN_UNUSED
 
438
        { return mUpdateName; }
 
439
 
 
440
        void fixAttackTarget();
 
441
 
 
442
        void updateNavigateList();
 
443
 
 
444
        int getPathLength(const Being *const being) const A_WARN_UNUSED;
 
445
 
 
446
        void targetMoved() const;
 
447
 
 
448
        void setLastHitFrom(const std::string &n)
 
449
        { mLastHitFrom = n; }
 
450
 
 
451
        void waitFor(const std::string &nick);
 
452
 
 
453
        void checkNewName(Being *const being);
 
454
 
 
455
        void resetYellowBar();
 
456
 
 
457
        unsigned char getWalkMask() const override A_WARN_UNUSED;
 
458
 
 
459
        void saveHomes();
 
460
 
 
461
        void removeHome();
 
462
 
 
463
        void stopAdvert();
 
464
 
 
465
        bool checAttackPermissions(const Being *const target)
 
466
                                   const A_WARN_UNUSED;
 
467
 
 
468
        void updateStatus() const;
 
469
 
 
470
        void setTestParticle(const std::string &fileName,
 
471
                             bool updateHash = true);
 
472
 
 
473
        std::string getInvertDirectionString();
 
474
 
 
475
        std::string getCrazyMoveTypeString();
 
476
 
 
477
        std::string getMoveToTargetTypeString();
 
478
 
 
479
        std::string getFollowModeString();
 
480
 
 
481
        std::string getAttackWeaponTypeString();
 
482
 
 
483
        std::string getAttackTypeString();
 
484
 
 
485
        std::string getQuickDropCounterString();
 
486
 
 
487
        std::string getPickUpTypeString();
 
488
 
 
489
        std::string getDebugPathString() const;
 
490
 
 
491
        std::string getMagicAttackString();
 
492
 
 
493
        std::string getPvpAttackString();
 
494
 
 
495
        std::string getImitationModeString();
 
496
 
 
497
        std::string getAwayModeString();
 
498
 
 
499
        std::string getCameraModeString() const;
 
500
 
 
501
        std::string getGameModifiersString();
 
502
 
 
503
    protected:
 
504
        void updateCoords() override;
 
505
 
 
506
 
 
507
        virtual void handleStatusEffect(StatusEffect *const effect,
 
508
                                        const int effectId);
 
509
 
 
510
        void startWalking(const unsigned char dir);
 
511
 
 
512
        void changeEquipmentBeforeAttack(const Being *const target) const;
 
513
 
 
514
        static void tryMagic(const std::string &spell, const int baseMagic,
 
515
                             const int schoolMagic, const int mana);
 
516
 
 
517
        const char *getVarItem(const char *const *const arr,
 
518
                               const unsigned index,
 
519
                               const unsigned sz) const A_WARN_UNUSED;
 
520
 
 
521
        void changeMode(unsigned *const var, const unsigned limit,
 
522
                        const char *const conf,
 
523
                        std::string (LocalPlayer::*const func)(),
 
524
                        const unsigned def = 0,
 
525
                        const bool save = true);
 
526
 
 
527
        void crazyMove1();
 
528
        void crazyMove2();
 
529
        void crazyMove3();
 
530
        void crazyMove4();
 
531
        void crazyMove5();
 
532
        void crazyMove6();
 
533
        void crazyMove7();
 
534
        void crazyMove8();
 
535
        void crazyMove9();
 
536
        void crazyMoveA();
 
537
 
 
538
        void loadHomes();
 
539
 
 
540
        int mGMLevel;
 
541
 
 
542
        // move type
 
543
        unsigned int mInvertDirection;
 
544
        // crazy move type
 
545
        unsigned int mCrazyMoveType;
 
546
        // crazy move state
 
547
        unsigned int mCrazyMoveState;
 
548
        // attack weapon type
 
549
        unsigned int mAttackWeaponType;
 
550
        // quick drop counter
 
551
        unsigned int mQuickDropCounter;
 
552
        // move state. used if mInvertDirection == 2
 
553
        unsigned int mMoveState;
 
554
        // pick up type 1x1, normal aka 2x1, forward aka 2x3, 3x3, 3x3 + 1
 
555
        unsigned int mPickUpType;
 
556
        // magic attack type
 
557
        unsigned int mMagicAttackType;
 
558
        // pvp attack type
 
559
        unsigned int mPvpAttackType;
 
560
        // type how move to target
 
561
        unsigned int mMoveToTargetType;
 
562
        unsigned int mAttackType;
 
563
        unsigned int mFollowMode;
 
564
        unsigned int mImitationMode;
 
565
 
 
566
        int mLastTargetX;
 
567
        int mLastTargetY;
 
568
 
 
569
        std::map<std::string, Vector> mHomes;
 
570
 
 
571
        Being *mTarget;
 
572
 
 
573
        /** Follow system **/
 
574
        std::string mPlayerFollowed;
 
575
        std::string mPlayerImitated;
 
576
        int mNextDestX;
 
577
        int mNextDestY;
 
578
 
 
579
        FloorItem *mPickUpTarget;
 
580
 
 
581
        int mLastAction;      // Time stamp of the last action, -1 if none.
 
582
 
 
583
        std::vector<int> mStatusEffectIcons;
 
584
 
 
585
        int mLocalWalkTime;  // Timestamp used to control keyboard walk
 
586
                             // messages flooding
 
587
 
 
588
        typedef std::pair<std::string, int> MessagePair;
 
589
        /** Queued messages*/
 
590
        std::list<MessagePair> mMessages;
 
591
        int mMessageTime;
 
592
        AwayListener *mAwayListener;
 
593
        OkDialog *mAwayDialog;
 
594
 
 
595
        int mPingSendTick;
 
596
        int mPingTime;
 
597
        int mAfkTime;
 
598
        int mActivityTime;
 
599
        int mNavigateX;
 
600
        int mNavigateY;
 
601
        int mNavigateId;
 
602
        int mCrossX;
 
603
        int mCrossY;
 
604
        int mOldX;
 
605
        int mOldY;
 
606
        int mOldTileX;
 
607
        int mOldTileY;
 
608
        Path mNavigatePath;
 
609
 
 
610
        std::string mLastHitFrom;
 
611
        std::string mWaitFor;
 
612
        int mAdvertTime;
 
613
        Particle *mTestParticle;
 
614
        std::string mTestParticleName;
 
615
        int mTestParticleTime;
 
616
        unsigned long mTestParticleHash;
 
617
        unsigned char mWalkingDir;  // The direction the player is walking in.
 
618
        /** Whether or not the name settings have changed */
 
619
        bool mUpdateName;
 
620
        bool mBlockAdvert;
 
621
        bool mTargetDeadPlayers;
 
622
        bool mServerAttack;
 
623
        bool mEnableAdvert;
 
624
        bool mTradebot;
 
625
        bool mTargetOnlyReachable;
 
626
        bool mDisableGameModifiers;
 
627
        bool mIsServerBuggy;
 
628
        bool mSyncPlayerMove;
 
629
        bool mDrawPath;
 
630
        bool mAttackMoving;
 
631
        bool mAttackNext;
 
632
        bool mShowJobExp;
 
633
        bool mNextStep;
 
634
        // temporary disable crazy moves in moves
 
635
        bool mDisableCrazyMove;
 
636
        bool mGoingToTarget;
 
637
        // Whether or not to continue to attack
 
638
        bool mKeepAttacking;
 
639
        // Tells if the path was set using mouse
 
640
        bool mPathSetByMouse;
 
641
        bool mWaitPing;
 
642
        bool mAwayMode;
 
643
        bool mPseudoAwayMode;
 
644
        bool mShowNavigePath;
 
645
};
 
646
 
 
647
extern LocalPlayer *player_node;
 
648
 
 
649
#endif  // BEING_LOCALPLAYER_H