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

« back to all changes in this revision

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