File indexing completed on 2024-12-01 06:51:05
0001 /* 0002 SPDX-FileCopyrightText: 2003 Marco Krüger <grisuji@gmx.de> 0003 SPDX-FileCopyrightText: 2003 Ian Wadham <iandw.au@gmail.com> 0004 SPDX-FileCopyrightText: 2009 Ian Wadham <iandw.au@gmail.com> 0005 0006 SPDX-License-Identifier: GPL-2.0-or-later 0007 */ 0008 0009 #ifndef KGRGLOBALS_H 0010 #define KGRGLOBALS_H 0011 0012 #include <QByteArray> 0013 #include <QString> 0014 0015 enum Owner {SYSTEM, USER}; 0016 0017 const char FREE = ' '; 0018 const char ENEMY = 'E'; 0019 const char HENEMY = 'a'; // NEW - 2/1/09 0020 const char HERO = 'R'; 0021 const char CONCRETE = 'X'; 0022 const char BRICK = 'M'; 0023 const char FBRICK = 'F'; 0024 const char HLADDER = 'Z'; 0025 const char LADDER = 'H'; 0026 const char NUGGET = 'N'; 0027 const char FLASHING = 'b'; // NEW - 2/1/09 0028 const char BAR = 'T'; 0029 const char HOLE = 'O'; 0030 const char USEDHOLE = 'U'; 0031 0032 const char BACKDROP = '0'; 0033 0034 const char EDIT_HINT = '1'; 0035 const char EDIT_TEST = '2'; 0036 0037 const int FIELDWIDTH = 28; 0038 const int FIELDHEIGHT = 20; 0039 0040 const int STEP = 4; 0041 const int gameCycle = 4; // Animation frames per playfield tile. 0042 const int graphicsCycle = 8; // Animation frames per running cycle. 0043 0044 // Keyboard action codes 0045 enum KBAction {KB_UP, KB_DOWN, KB_LEFT, KB_RIGHT, 0046 KB_DIGLEFT, KB_DIGRIGHT, KB_STOP}; 0047 0048 // Action codes when selecting a level or game for play, editing or replay. 0049 enum SelectAction {SL_START, SL_ANY, SL_CREATE, SL_UPDATE, SL_SAVE, 0050 SL_MOVE, SL_DELETE, SL_CR_GAME, SL_UPD_GAME, 0051 SL_REPLAY, SL_SOLVE, SL_SAVE_SOLUTION, SL_NONE}; 0052 0053 /// Codes for the rules of the selected game and level. 0054 const char TraditionalRules = 'T'; 0055 const char KGoldrunnerRules = 'K'; 0056 const char ScavengerRules = 'S'; 0057 0058 // Codes and array indices for the sounds of the game. 0059 enum {GoldSound, StepSound, ClimbSound, FallSound, DigSound, LadderSound, 0060 DeathSound, CompletedSound, VictorySound, GameOverSound, NumSounds}; 0061 0062 /// Centralized message functions: implementations in kgrdialog.cpp. 0063 class QWidget; 0064 class KGrMessage 0065 { 0066 public: 0067 static void information (QWidget * parent, const QString & caption, 0068 const QString & text, 0069 const QString & dontShowAgain = QString()); 0070 static int warning (QWidget * parent, const QString & caption, 0071 const QString & text, const QString & label0, 0072 const QString & label1, 0073 const QString & label2 = QString()); 0074 }; 0075 0076 /// KGrGameData structure: contains attributes of a KGoldrunner game. 0077 class KGrGameData 0078 { 0079 public: 0080 Owner owner; ///< Owner of the game: "System" or "User". 0081 int nLevels; ///< Number of levels in the game. 0082 char rules; ///< Game's rules: KGoldrunner or Traditional. 0083 bool digWhileFalling;///< If all levels allow "dig while falling". 0084 QString prefix; ///< Game's filename prefix. 0085 char skill; ///< Game's skill: Tutorial, Normal or Champion. 0086 int width; ///< Width of grid, in cells. 0087 int height; ///< Height of grid, in cells. 0088 QString name; ///< Name of game (translated, if System game). 0089 QByteArray about; ///< Optional info about game (untranslated). 0090 }; 0091 0092 /// KGrLevelData structure: contains attributes of a KGoldrunner level. 0093 class KGrLevelData 0094 { 0095 public: 0096 int level; ///< Level number. 0097 int width; ///< Width of grid, in cells. 0098 int height; ///< Height of grid, in cells. 0099 QByteArray layout; ///< Codes for the level layout (mandatory). 0100 QByteArray name; ///< Level name (optional). 0101 QByteArray hint; ///< Level hint (optional). 0102 bool digWhileFalling;///< If this one level has "dig while falling". 0103 }; 0104 0105 /// KGrRecording structure: contains a record of play in a KGoldrunner level. 0106 class KGrRecording 0107 { 0108 public: 0109 QString dateTime; ///< Date+time of recording (UTC in ISO format). 0110 Owner owner; ///< Original owner, at time of recording. 0111 char rules; ///< Rules that applied at time of recording. 0112 QString prefix; ///< Game's filename prefix. 0113 QString gameName; ///< Name of the game (translated at rec time). 0114 int level; ///< Level number (at time of recording). 0115 int width; ///< Width of grid, in cells (at rec time). 0116 int height; ///< Height of grid, in cells (at rec time). 0117 QByteArray layout; ///< Codes for the level layout (at rec time). 0118 QString levelName; ///< Name of the level (translated at rec time). 0119 QString hint; ///< Hint (translated at recording time). 0120 bool digWhileFalling; ///< If this level has "dig while falling". 0121 long lives; ///< Number of lives at start of level. 0122 long score; ///< Score at start of level. 0123 int speed; ///< Speed of game during recording (normal=10). 0124 int controlMode; ///< Control mode during recording (mouse, etc). 0125 int keyOption; ///< Click/hold option for keyboard mode. 0126 QByteArray content; ///< The encoded recording of play. 0127 QByteArray draws; ///< The random numbers used during play. 0128 }; 0129 0130 // Offsets used to encode keystrokes, control modes and speeds in a recording. 0131 // Allow space for 16 direction and digging codes, 12 control modes, 4 keyboard 0132 // click/hold option codes, 16 special actions and 30 speeds. We actually have 0133 // (as at July 2010) 12 direction and digging codes, control modes from 2 to 4, 0134 // two keyboard options, one special action (code 6) and speeds ranging from 0135 // 2 to 20. 0136 0137 #define DIRECTION_CODE 0x80 0138 #define MODE_CODE 0x90 0139 #define KEY_OPT_CODE 0x9c 0140 #define ACTION_CODE 0xa0 0141 #define SPEED_CODE 0xe0 0142 #define END_CODE 0xff 0143 0144 enum GameAction {NEW, NEXT_LEVEL, LOAD, SAVE_GAME, PAUSE, HIGH_SCORE, 0145 KILL_HERO, HINT, 0146 DEMO, SOLVE, SAVE_SOLUTION, 0147 INSTANT_REPLAY, REPLAY_LAST, REPLAY_ANY}; 0148 0149 enum EditAction {CREATE_LEVEL, EDIT_ANY, SAVE_EDITS, MOVE_LEVEL, 0150 DELETE_LEVEL, CREATE_GAME, EDIT_GAME}; 0151 0152 enum Setting {PLAY_SOUNDS, // Sound effects on/off. 0153 STARTUP_DEMO, // Starting demo on/off. 0154 MOUSE, KEYBOARD, LAPTOP, // Game-control modes. 0155 CLICK_KEY, HOLD_KEY, // Key-control method. 0156 NORMAL_SPEED, BEGINNER_SPEED, // Preset game-speeds. 0157 CHAMPION_SPEED, 0158 INC_SPEED, DEC_SPEED, // Adjustments of speed. 0159 PLAY_STEPS}; // Footsteps on/off. 0160 0161 const int ConcreteWall = 1; 0162 0163 typedef char DirectionFlag; 0164 typedef char AccessFlag; 0165 typedef char Flags; 0166 0167 enum Direction {STAND, RIGHT, LEFT, UP, DOWN, nDirections, 0168 DIG_RIGHT = nDirections, DIG_LEFT, NO_DIRECTION, 0169 UP_LEFT, DOWN_LEFT, UP_RIGHT, DOWN_RIGHT, EndDirection}; 0170 0171 const DirectionFlag dFlag [nDirections] = { 0172 0x10, // Can stand. 0173 0x1, // Can go right. 0174 0x2, // Can go left. 0175 0x4, // Can go up. 0176 0x8}; // Can go down. 0177 0178 const AccessFlag ENTERABLE = 0x20; 0179 0180 enum Axis {X, Y, nAxes}; 0181 0182 const int movement [EndDirection][nAxes] = { 0183 { 0, 0}, // Standing still. 0184 {+1, 0}, // Movement right. 0185 {-1, 0}, // Movement left. 0186 { 0, -1}, // Movement up. 0187 { 0, +1}, // Movement down. 0188 { 0, 0}, // Dig right (placeholder). 0189 { 0, 0}, // Dig left (placeholder). 0190 { 0, 0}, // No direction (placeholder). 0191 {-1, -1}, // Up and left (with hold-key option). 0192 {-1, +1}, // Down and left (with hold-key option). 0193 {+1, -1}, // Up and right (with hold-key option). 0194 {+1, +1}}; // Down and right (with hold-key option). 0195 0196 enum AnimationType { 0197 RUN_R, RUN_L, 0198 CLIMB_R, CLIMB_L, 0199 CLIMB_U, CLIMB_D, 0200 FALL_R, FALL_L, 0201 OPEN_BRICK, CLOSE_BRICK, nAnimationTypes}; 0202 0203 const AnimationType aType [nDirections] = { 0204 FALL_L, RUN_R, RUN_L, CLIMB_U, CLIMB_D}; 0205 0206 enum DebugCodes { 0207 DO_STEP, BUG_FIX, LOGGING, S_POSNS, S_HERO, S_OBJ, 0208 ENEMY_0, ENEMY_1, ENEMY_2, ENEMY_3, ENEMY_4, ENEMY_5, ENEMY_6}; 0209 0210 const int TickTime = 20; 0211 0212 enum HeroStatus { 0213 NORMAL, WON_LEVEL, DEAD, UNEXPECTED_END}; 0214 0215 #endif // KGRGLOBALS_H