kgrrulebook.h 5.57 KB
Newer Older
1
/****************************************************************************
2
 *    Copyright 2009  Ian Wadham <iandw.au@gmail.com>                       *
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
 *                                                                          *
 *    This program is free software; you can redistribute it and/or         *
 *    modify it under the terms of the GNU General Public License as        *
 *    published by the Free Software Foundation; either version 2 of        *
 *    the License, or (at your option) any later version.                   *
 *                                                                          *
 *    This program is distributed in the hope that it will be useful,       *
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *    GNU General Public License for more details.                          *
 *                                                                          *
 *    You should have received a copy of the GNU General Public License     *
 *    along with this program.  If not, see <http://www.gnu.org/licenses/>. *
 ****************************************************************************/

#ifndef KGRRULEBOOK_H
#define KGRRULEBOOK_H

21 22
#include "kgrglobals.h"

23
#include <QList>
24
#include <QObject>
25

Laurent Montel's avatar
Laurent Montel committed
26
#include "kgoldrunner_debug.h"
27 28 29 30 31 32 33 34 35 36

class KGrLevelGrid;

class KGrRuleBook : public QObject
{
    Q_OBJECT
public:
    KGrRuleBook (QObject * parent);
    virtual ~KGrRuleBook();

37
    bool variableTiming() const      { return mVariableTiming;      }
38 39 40 41 42 43
    bool alwaysCollectNugget() const { return mAlwaysCollectNugget; }
    bool runThruHole() const         { return mRunThruHole;         }
    bool reappearAtTop() const       { return mReappearAtTop;       }
    int  reappearRow() const         { return mReappearRow;         }
    int  pointsPerCell() const       { return mPointsPerCell;       }
    bool turnAnywhere() const        { return mTurnAnywhere;        }
44
    bool enemiesShowGold() const     { return mEnemiesShowGold;     }
45

46 47
    void        setTiming     (const int enemyCount = 0);

48 49 50 51
    inline void getHeroTimes  (int & runTime,       int & fallTime,
                               int & enemyFallTime, int & trapTime) {
                runTime       = times.hwalk; fallTime = times.hfall;
                enemyFallTime = times.efall; trapTime = times.ecaptive; }
52 53

    inline char getEnemyTimes (int & runTime, int & fallTime, int & trapTime) {
54 55
                runTime       = times.ewalk; fallTime = times.efall;
                trapTime      = times.ecaptive;
56 57
                return mRules; }

Ian Wadham's avatar
Ian Wadham committed
58 59 60
    inline void getDigTimes   (int & digTime, int & digCounter) {
                digTime = 200; digCounter = times.hole; }

61 62
    virtual Direction findBestWay (const int eI, const int eJ,
                                   const int hI, const int hJ,
63 64
                                   KGrLevelGrid * pGrid,
                                   bool leftRightSearch = true) = 0;
65 66

protected:
67 68 69 70 71 72 73 74 75
    typedef struct {
        int hwalk;
        int hfall;
        int ewalk;
        int efall;
        int ecaptive;
        int hole;
    } Timing;

76 77
    char mRules;		///< The type of rules and enemy search method.

78 79 80 81 82 83 84
    bool mVariableTiming;	///< More enemies imply less speed.
    bool mAlwaysCollectNugget;	///< Enemies always collect nuggets.
    bool mRunThruHole;		///< Enemy can run L/R through dug hole.
    bool mReappearAtTop;	///< Enemies reborn at top of screen.
    int  mReappearRow;		///< Row where enemies reappear.
    int  mPointsPerCell;	///< Number of points in each grid-cell.
    bool mTurnAnywhere;		///< Can change direction anywhere in grid-cell.
85
    bool mEnemiesShowGold;	///< Enemies show when they are carrying gold.
86 87

    Timing times;
88
    KGrLevelGrid * grid;
89 90 91 92 93 94 95 96 97 98
};


class KGrTraditionalRules : public KGrRuleBook
{
    Q_OBJECT
public:
    KGrTraditionalRules (QObject * parent);
    ~KGrTraditionalRules();

99 100
    Direction findBestWay  (const int eI, const int eJ,
                            const int hI, const int hJ,
101
                            KGrLevelGrid * pGrid,
Laurent Montel's avatar
Laurent Montel committed
102
                            bool leftRightSearch = true) Q_DECL_OVERRIDE;
103 104 105 106 107 108 109 110 111 112 113

private:
    Direction searchUp     (int eI, int eJ, int hJ);
    Direction searchDown   (int eI, int eJ, int hJ);
    Direction getHero      (int eI, int eJ, int hI);

    int       distanceUp   (int x,  int y,  int deltah);
    int       distanceDown (int x,  int y,  int deltah);
    bool      searchOK     (int direction,  int x, int y);
    int       canWalkLR    (int direction,  int x, int y);
    bool      willNotFall  (int x,  int y);
114 115 116 117 118 119 120 121 122 123
};


class KGrKGoldrunnerRules : public KGrRuleBook
{
    Q_OBJECT
public:
    KGrKGoldrunnerRules (QObject * parent);
    ~KGrKGoldrunnerRules();

124 125 126
    Direction findBestWay  (const int eI, const int eJ,
                            const int hI, const int hJ,
                            KGrLevelGrid * pGrid,
Laurent Montel's avatar
Laurent Montel committed
127
                            bool leftRightSearch = true) Q_DECL_OVERRIDE;
128 129 130 131 132 133

private:
    Direction findWayUp    (const int eI, const int eJ);
    Direction findWayDown  (const int eI, const int eJ);
    Direction findWayLeft  (const int eI, const int eJ);
    Direction findWayRight (const int eI, const int eJ);
134 135 136 137 138 139 140 141 142 143
};


class KGrScavengerRules : public KGrRuleBook
{
    Q_OBJECT
public:
    KGrScavengerRules (QObject * parent);
    ~KGrScavengerRules();

144 145
    Direction findBestWay (const int eI, const int eJ,
                           const int hI, const int hJ,
146
                           KGrLevelGrid * pGrid,
Laurent Montel's avatar
Laurent Montel committed
147
                           bool leftRightSearch = true) Q_DECL_OVERRIDE;
148 149 150
};

#endif // KGRRULEBOOK_H