File indexing completed on 2024-10-13 03:43:42
0001 /* 0002 SPDX-FileCopyrightText: 2009 Ian Wadham <iandw.au@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef KGRRULEBOOK_H 0008 #define KGRRULEBOOK_H 0009 0010 #include "kgrglobals.h" 0011 0012 #include <QObject> 0013 0014 #include "kgoldrunner_debug.h" 0015 0016 class KGrLevelGrid; 0017 0018 class KGrRuleBook : public QObject 0019 { 0020 Q_OBJECT 0021 public: 0022 explicit KGrRuleBook (QObject * parent); 0023 ~KGrRuleBook() override; 0024 0025 bool variableTiming() const { return mVariableTiming; } 0026 bool alwaysCollectNugget() const { return mAlwaysCollectNugget; } 0027 bool runThruHole() const { return mRunThruHole; } 0028 bool reappearAtTop() const { return mReappearAtTop; } 0029 int reappearRow() const { return mReappearRow; } 0030 int pointsPerCell() const { return mPointsPerCell; } 0031 bool turnAnywhere() const { return mTurnAnywhere; } 0032 bool enemiesShowGold() const { return mEnemiesShowGold; } 0033 0034 void setTiming (const int enemyCount = 0); 0035 0036 inline void getHeroTimes (int & runTime, int & fallTime, 0037 int & enemyFallTime, int & trapTime) { 0038 runTime = times.hwalk; fallTime = times.hfall; 0039 enemyFallTime = times.efall; trapTime = times.ecaptive; } 0040 0041 inline char getEnemyTimes (int & runTime, int & fallTime, int & trapTime) { 0042 runTime = times.ewalk; fallTime = times.efall; 0043 trapTime = times.ecaptive; 0044 return mRules; } 0045 0046 inline void getDigTimes (int & digTime, int & digCounter) { 0047 digTime = 200; digCounter = times.hole; } 0048 0049 virtual Direction findBestWay (const int eI, const int eJ, 0050 const int hI, const int hJ, 0051 KGrLevelGrid * pGrid, 0052 bool leftRightSearch = true) = 0; 0053 0054 protected: 0055 typedef struct { 0056 int hwalk; 0057 int hfall; 0058 int ewalk; 0059 int efall; 0060 int ecaptive; 0061 int hole; 0062 } Timing; 0063 0064 char mRules; ///< The type of rules and enemy search method. 0065 0066 bool mVariableTiming; ///< More enemies imply less speed. 0067 bool mAlwaysCollectNugget; ///< Enemies always collect nuggets. 0068 bool mRunThruHole; ///< Enemy can run L/R through dug hole. 0069 bool mReappearAtTop; ///< Enemies reborn at top of screen. 0070 int mReappearRow; ///< Row where enemies reappear. 0071 int mPointsPerCell; ///< Number of points in each grid-cell. 0072 bool mTurnAnywhere; ///< Can change direction anywhere in grid-cell. 0073 bool mEnemiesShowGold; ///< Enemies show when they are carrying gold. 0074 0075 Timing times; 0076 KGrLevelGrid * grid; 0077 }; 0078 0079 0080 class KGrTraditionalRules : public KGrRuleBook 0081 { 0082 Q_OBJECT 0083 public: 0084 explicit KGrTraditionalRules (QObject * parent); 0085 ~KGrTraditionalRules() override; 0086 0087 Direction findBestWay (const int eI, const int eJ, 0088 const int hI, const int hJ, 0089 KGrLevelGrid * pGrid, 0090 bool leftRightSearch = true) override; 0091 0092 private: 0093 Direction searchUp (int eI, int eJ, int hJ); 0094 Direction searchDown (int eI, int eJ, int hJ); 0095 Direction getHero (int eI, int eJ, int hI); 0096 0097 int distanceUp (int x, int y, int deltah); 0098 int distanceDown (int x, int y, int deltah); 0099 bool searchOK (int direction, int x, int y); 0100 int canWalkLR (int direction, int x, int y); 0101 bool willNotFall (int x, int y); 0102 }; 0103 0104 0105 class KGrKGoldrunnerRules : public KGrRuleBook 0106 { 0107 Q_OBJECT 0108 public: 0109 explicit KGrKGoldrunnerRules (QObject * parent); 0110 ~KGrKGoldrunnerRules() override; 0111 0112 Direction findBestWay (const int eI, const int eJ, 0113 const int hI, const int hJ, 0114 KGrLevelGrid * pGrid, 0115 bool leftRightSearch = true) override; 0116 0117 private: 0118 Direction findWayUp (const int eI, const int eJ); 0119 Direction findWayDown (const int eI, const int eJ); 0120 Direction findWayLeft (const int eI, const int eJ); 0121 Direction findWayRight (const int eI, const int eJ); 0122 }; 0123 0124 0125 class KGrScavengerRules : public KGrRuleBook 0126 { 0127 Q_OBJECT 0128 public: 0129 explicit KGrScavengerRules (QObject * parent); 0130 ~KGrScavengerRules() override; 0131 0132 Direction findBestWay (const int eI, const int eJ, 0133 const int hI, const int hJ, 0134 KGrLevelGrid * pGrid, 0135 bool leftRightSearch = true) override; 0136 }; 0137 0138 #endif // KGRRULEBOOK_H