1 /*
2     SPDX-FileCopyrightText: 2003 Marco Krüger <grisuji@gmx.de>
3     SPDX-FileCopyrightText: 2003 Ian Wadham <iandw.au@gmail.com>
4     SPDX-FileCopyrightText: 2009 Ian Wadham <iandw.au@gmail.com>
5 
6     SPDX-License-Identifier: GPL-2.0-or-later
7 */
8 
9 #ifndef KGRGLOBALS_H
10 #define KGRGLOBALS_H
11 
12 #include <QByteArray>
13 #include <QString>
14 
15 enum Owner {SYSTEM, USER};
16 
17 const char FREE      = ' ';
18 const char ENEMY     = 'E';
19 const char HENEMY    = 'a'; // NEW - 2/1/09
20 const char HERO      = 'R';
21 const char CONCRETE  = 'X';
22 const char BRICK     = 'M';
23 const char FBRICK    = 'F';
24 const char HLADDER   = 'Z';
25 const char LADDER    = 'H';
26 const char NUGGET    = 'N';
27 const char FLASHING  = 'b'; // NEW - 2/1/09
28 const char BAR       = 'T';
29 const char HOLE      = 'O';
30 const char USEDHOLE  = 'U';
31 
32 const char BACKDROP  = '0';
33 
34 const char EDIT_HINT = '1';
35 const char EDIT_TEST = '2';
36 
37 const int  FIELDWIDTH   = 28;
38 const int  FIELDHEIGHT  = 20;
39 
40 const int STEP = 4;
41 const int gameCycle = 4;		// Animation frames per playfield tile.
42 const int graphicsCycle = 8;		// Animation frames per running cycle.
43 
44 // Keyboard action codes
45 enum KBAction		{KB_UP, KB_DOWN, KB_LEFT, KB_RIGHT,
46                          KB_DIGLEFT, KB_DIGRIGHT, KB_STOP};
47 
48 // Action codes when selecting a level or game for play, editing or replay.
49 enum SelectAction	{SL_START, SL_ANY, SL_CREATE, SL_UPDATE, SL_SAVE,
50                          SL_MOVE, SL_DELETE, SL_CR_GAME, SL_UPD_GAME,
51                          SL_REPLAY, SL_SOLVE, SL_SAVE_SOLUTION, SL_NONE};
52 
53 /// Codes for the rules of the selected game and level.
54 const char TraditionalRules = 'T';
55 const char KGoldrunnerRules = 'K';
56 const char ScavengerRules   = 'S';
57 
58 // Codes and array indices for the sounds of the game.
59 enum {GoldSound, StepSound, ClimbSound, FallSound, DigSound, LadderSound,
60       DeathSound, CompletedSound, VictorySound, GameOverSound, NumSounds};
61 
62 /// Centralized message functions: implementations in kgrdialog.cpp.
63 class QWidget;
64 class KGrMessage
65 {
66 public:
67     static void information (QWidget * parent, const QString & caption,
68                              const QString & text,
69                              const QString & dontShowAgain = QString());
70     static int  warning     (QWidget * parent, const QString & caption,
71                              const QString & text, const QString & label0,
72                              const QString & label1,
73                              const QString & label2 = QString());
74 };
75 
76 /// KGrGameData structure: contains attributes of a KGoldrunner game.
77 class KGrGameData
78 {
79 public:
80     Owner       owner;		///< Owner of the game: "System" or "User".
81     int         nLevels;	///< Number of levels in the game.
82     char        rules;		///< Game's rules: KGoldrunner or Traditional.
83     bool        digWhileFalling;///< If all levels allow "dig while falling".
84     QString     prefix;		///< Game's filename prefix.
85     char        skill;		///< Game's skill: Tutorial, Normal or Champion.
86     int         width;		///< Width of grid, in cells.
87     int         height;		///< Height of grid, in cells.
88     QString     name;		///< Name of game (translated, if System game).
89     QByteArray  about;		///< Optional info about game (untranslated).
90 };
91 
92 /// KGrLevelData structure: contains attributes of a KGoldrunner level.
93 class KGrLevelData
94 {
95 public:
96     int         level;		///< Level number.
97     int         width;		///< Width of grid, in cells.
98     int         height;		///< Height of grid, in cells.
99     QByteArray  layout;		///< Codes for the level layout (mandatory).
100     QByteArray  name;		///< Level name (optional).
101     QByteArray  hint;		///< Level hint (optional).
102     bool        digWhileFalling;///< If this one level has "dig while falling".
103 };
104 
105 /// KGrRecording structure: contains a record of play in a KGoldrunner level.
106 class KGrRecording
107 {
108 public:
109     QString        dateTime;    ///< Date+time of recording (UTC in ISO format).
110     Owner          owner;	///< Original owner, at time of recording.
111     char           rules;	///< Rules that applied at time of recording.
112     QString        prefix;	///< Game's filename prefix.
113     QString        gameName;	///< Name of the game (translated at rec time).
114     int            level;	///< Level number (at time of recording).
115     int            width;	///< Width of grid, in cells (at rec time).
116     int            height;	///< Height of grid, in cells (at rec time).
117     QByteArray     layout;	///< Codes for the level layout (at rec time).
118     QString        levelName;	///< Name of the level (translated at rec time).
119     QString        hint;	///< Hint (translated at recording time).
120     bool           digWhileFalling; ///< If this level has "dig while falling".
121     long           lives;	///< Number of lives at start of level.
122     long           score;	///< Score at start of level.
123     int            speed;	///< Speed of game during recording (normal=10).
124     int            controlMode;	///< Control mode during recording (mouse, etc).
125     int            keyOption;  	///< Click/hold option for keyboard mode.
126     QByteArray     content;	///< The encoded recording of play.
127     QByteArray     draws;	///< The random numbers used during play.
128 };
129 
130 // Offsets used to encode keystrokes, control modes and speeds in a recording.
131 // Allow space for 16 direction and digging codes, 12 control modes, 4 keyboard
132 // click/hold option codes, 16 special actions and 30 speeds.  We actually have
133 // (as at July 2010) 12 direction and digging codes, control modes from 2 to 4,
134 // two keyboard options, one special action (code 6) and speeds ranging from
135 // 2 to 20.
136 
137 #define DIRECTION_CODE 0x80
138 #define MODE_CODE      0x90
139 #define KEY_OPT_CODE   0x9c
140 #define ACTION_CODE    0xa0
141 #define SPEED_CODE     0xe0
142 #define END_CODE       0xff
143 
144 enum GameAction    {NEW, NEXT_LEVEL, LOAD, SAVE_GAME, PAUSE, HIGH_SCORE,
145                     KILL_HERO, HINT,
146                     DEMO, SOLVE, SAVE_SOLUTION,
147                     INSTANT_REPLAY, REPLAY_LAST, REPLAY_ANY};
148 
149 enum EditAction    {CREATE_LEVEL, EDIT_ANY, SAVE_EDITS, MOVE_LEVEL,
150                     DELETE_LEVEL, CREATE_GAME,  EDIT_GAME};
151 
152 enum Setting       {PLAY_SOUNDS,			// Sound effects on/off.
153                     STARTUP_DEMO,			// Starting demo on/off.
154                     MOUSE, KEYBOARD, LAPTOP,		// Game-control modes.
155                     CLICK_KEY, HOLD_KEY, 		// Key-control method.
156                     NORMAL_SPEED, BEGINNER_SPEED,	// Preset game-speeds.
157                     CHAMPION_SPEED,
158                     INC_SPEED, DEC_SPEED,		// Adjustments of speed.
159                     PLAY_STEPS};			// Footsteps on/off.
160 
161 const int  ConcreteWall = 1;
162 
163 typedef char    DirectionFlag;
164 typedef char    AccessFlag;
165 typedef char    Flags;
166 
167 enum  Direction    {STAND, RIGHT, LEFT, UP, DOWN, nDirections,
168                     DIG_RIGHT = nDirections, DIG_LEFT, NO_DIRECTION,
169                     UP_LEFT, DOWN_LEFT, UP_RIGHT, DOWN_RIGHT, EndDirection};
170 
171 const DirectionFlag dFlag [nDirections] = {
172                 0x10,		// Can stand.
173                 0x1,		// Can go right.
174                 0x2,		// Can go left.
175                 0x4,		// Can go up.
176                 0x8};		// Can go down.
177 
178 const AccessFlag ENTERABLE = 0x20;
179 
180 enum  Axis {X, Y, nAxes};
181 
182 const int movement [EndDirection][nAxes] = {
183                 { 0,  0},	// Standing still.
184                 {+1,  0},	// Movement right.
185                 {-1,  0},	// Movement left.
186                 { 0, -1},	// Movement up.
187                 { 0, +1},	// Movement down.
188                 { 0,  0},	// Dig right (placeholder).
189                 { 0,  0},	// Dig left (placeholder).
190                 { 0,  0},	// No direction (placeholder).
191                 {-1, -1},	// Up and left (with hold-key option).
192                 {-1, +1},	// Down and left (with hold-key option).
193                 {+1, -1},	// Up and right (with hold-key option).
194                 {+1, +1}};	// Down and right (with hold-key option).
195 
196 enum AnimationType {
197                 RUN_R,      RUN_L,
198                 CLIMB_R,    CLIMB_L,
199                 CLIMB_U,    CLIMB_D,
200                 FALL_R,     FALL_L,
201                 OPEN_BRICK, CLOSE_BRICK, nAnimationTypes};
202 
203 const AnimationType aType [nDirections] = {
204                 FALL_L, RUN_R, RUN_L, CLIMB_U, CLIMB_D};
205 
206 enum  DebugCodes {
207                 DO_STEP, BUG_FIX, LOGGING, S_POSNS, S_HERO, S_OBJ,
208                 ENEMY_0, ENEMY_1, ENEMY_2, ENEMY_3, ENEMY_4, ENEMY_5, ENEMY_6};
209 
210 const int TickTime = 20;
211 
212 enum  HeroStatus {
213                 NORMAL, WON_LEVEL, DEAD, UNEXPECTED_END};
214 
215 #endif // KGRGLOBALS_H
216