added ignoring screen navigation events if text input gadgets are active
[rocksndiamonds.git] / src / libgame / setup.h
1 // ============================================================================
2 // Artsoft Retro-Game Library
3 // ----------------------------------------------------------------------------
4 // (c) 1995-2014 by Artsoft Entertainment
5 //                  Holger Schemel
6 //                  info@artsoft.org
7 //                  http://www.artsoft.org/
8 // ----------------------------------------------------------------------------
9 // setup.h
10 // ============================================================================
11
12 #ifndef SETUP_H
13 #define SETUP_H
14
15 #include "system.h"
16 #include "hash.h"
17
18
19 /* values for setup file handling */
20 #define TYPE_BOOLEAN                    (1 << 0)
21 #define TYPE_SWITCH                     (1 << 1)
22 #define TYPE_SWITCH3                    (1 << 2)
23 #define TYPE_YES_NO                     (1 << 3)
24 #define TYPE_YES_NO_AUTO                (1 << 4)
25 #define TYPE_ECS_AGA                    (1 << 5)
26 #define TYPE_KEY                        (1 << 6)
27 #define TYPE_KEY_X11                    (1 << 7)
28 #define TYPE_INTEGER                    (1 << 8)
29 #define TYPE_STRING                     (1 << 9)
30 #define TYPE_PLAYER                     (1 << 10)
31 #define TYPE_ELEMENT                    (1 << 11)
32 #define TYPE_GRAPHIC                    (1 << 12)
33
34 /* additional values for setup screen */
35 #define TYPE_ENTER_SCREEN               (1 << 13)
36 #define TYPE_LEAVE_SCREEN               (1 << 14)
37 #define TYPE_ENTER_MENU                 (1 << 15)
38 #define TYPE_LEAVE_MENU                 (1 << 16)
39 #define TYPE_ENTER_LIST                 (1 << 17)
40 #define TYPE_LEAVE_LIST                 (1 << 18)
41 #define TYPE_EMPTY                      (1 << 19)
42 #define TYPE_SKIPPABLE                  (1 << 20)
43 #define TYPE_KEYTEXT                    (1 << 21)
44
45 #define TYPE_GHOSTED                    (1 << 22)
46 #define TYPE_QUERY                      (1 << 23)
47
48 /* additional values for internal purposes */
49 #define TYPE_BITFIELD                   (1 << 24)
50 #define TYPE_CONTENT                    (1 << 25)
51 #define TYPE_ELEMENT_LIST               (1 << 26)
52 #define TYPE_CONTENT_LIST               (1 << 27)
53
54 /* derived values for setup file handling */
55 #define TYPE_BOOLEAN_STYLE              (TYPE_BOOLEAN | \
56                                          TYPE_SWITCH  | \
57                                          TYPE_YES_NO  | \
58                                          TYPE_ECS_AGA )
59
60 /* derived values for setup screen */
61 #define TYPE_VALUE                      (TYPE_BOOLEAN_STYLE     | \
62                                          TYPE_SWITCH3           | \
63                                          TYPE_YES_NO_AUTO       | \
64                                          TYPE_KEY               | \
65                                          TYPE_KEY_X11           | \
66                                          TYPE_INTEGER           | \
67                                          TYPE_STRING            | \
68                                          TYPE_PLAYER            | \
69                                          TYPE_ELEMENT           | \
70                                          TYPE_GRAPHIC)
71
72 #define TYPE_SKIP_ENTRY                 (TYPE_EMPTY             | \
73                                          TYPE_SKIPPABLE         | \
74                                          TYPE_KEY               | \
75                                          TYPE_STRING            | \
76                                          TYPE_GHOSTED)
77
78 #define TYPE_ENTER                      (TYPE_ENTER_SCREEN      | \
79                                          TYPE_ENTER_MENU        | \
80                                          TYPE_ENTER_LIST)
81
82 #define TYPE_LEAVE                      (TYPE_LEAVE_SCREEN      | \
83                                          TYPE_LEAVE_MENU        | \
84                                          TYPE_LEAVE_LIST)
85
86 #define TYPE_ENTER_OR_LEAVE             (TYPE_ENTER | TYPE_LEAVE)
87
88 struct TokenInfo
89 {
90   int type;
91   void *value;
92   char *text;
93 };
94
95 /* some definitions for list and hash handling */
96 typedef struct SetupFileList SetupFileList;
97 typedef struct hashtable     SetupFileHash;
98
99 #define BEGIN_HASH_ITERATION(hash, itr)                         \
100   if (hash != NULL && hashtable_count(hash) > 0)                \
101   {                                                             \
102     struct hashtable_itr *itr = hashtable_iterator(hash);       \
103     do {                                                        \
104
105 #define HASH_ITERATION_TOKEN(itr)       ((char *)hashtable_iterator_key(itr))
106 #define HASH_ITERATION_VALUE(itr)       ((char *)hashtable_iterator_value(itr))
107
108 #define END_HASH_ITERATION(hash, itr)                           \
109     } while (hashtable_iterator_advance(itr));                  \
110     free(itr);                                                  \
111   }                                                             \
112
113
114 /* sort priorities of level series (also used as level series classes) */
115 #define LEVELCLASS_TUTORIAL_START       10
116 #define LEVELCLASS_TUTORIAL_END         99
117 #define LEVELCLASS_CLASSICS_START       100
118 #define LEVELCLASS_CLASSICS_END         199
119 #define LEVELCLASS_CONTRIB_START        200
120 #define LEVELCLASS_CONTRIB_END          299
121 #define LEVELCLASS_PRIVATE_START        300
122 #define LEVELCLASS_PRIVATE_END          399
123 #define LEVELCLASS_BD_START             400
124 #define LEVELCLASS_BD_END               499
125 #define LEVELCLASS_EM_START             500
126 #define LEVELCLASS_EM_END               599
127 #define LEVELCLASS_SP_START             600
128 #define LEVELCLASS_SP_END               699
129 #define LEVELCLASS_DX_START             700
130 #define LEVELCLASS_DX_END               799
131 #define LEVELCLASS_SB_START             800
132 #define LEVELCLASS_SB_END               899
133
134 #define LEVELCLASS_PREDEFINED_START     LEVELCLASS_TUTORIAL_START
135 #define LEVELCLASS_PREDEFINED_END       LEVELCLASS_SB_END
136
137 #define LEVELCLASS_TUTORIAL             LEVELCLASS_TUTORIAL_START
138 #define LEVELCLASS_CLASSICS             LEVELCLASS_CLASSICS_START
139 #define LEVELCLASS_CONTRIB              LEVELCLASS_CONTRIB_START
140 #define LEVELCLASS_PRIVATE              LEVELCLASS_PRIVATE_START
141 #define LEVELCLASS_BD                   LEVELCLASS_BD_START
142 #define LEVELCLASS_EM                   LEVELCLASS_EM_START
143 #define LEVELCLASS_SP                   LEVELCLASS_SP_START
144 #define LEVELCLASS_DX                   LEVELCLASS_DX_START
145 #define LEVELCLASS_SB                   LEVELCLASS_SB_START
146
147 #define LEVELCLASS_UNDEFINED            999
148
149 #define IS_LEVELCLASS_TUTORIAL(p)                                       \
150         ((p)->sort_priority >= LEVELCLASS_TUTORIAL_START &&             \
151          (p)->sort_priority <= LEVELCLASS_TUTORIAL_END)
152 #define IS_LEVELCLASS_CLASSICS(p)                                       \
153         ((p)->sort_priority >= LEVELCLASS_CLASSICS_START &&             \
154          (p)->sort_priority <= LEVELCLASS_CLASSICS_END)
155 #define IS_LEVELCLASS_CONTRIB(p)                                        \
156         ((p)->sort_priority >= LEVELCLASS_CONTRIB_START &&              \
157          (p)->sort_priority <= LEVELCLASS_CONTRIB_END)
158 #define IS_LEVELCLASS_PRIVATE(p)                                        \
159         ((p)->sort_priority >= LEVELCLASS_PRIVATE_START &&              \
160          (p)->sort_priority <= LEVELCLASS_PRIVATE_END)
161 #define IS_LEVELCLASS_BD(p)                                             \
162         ((p)->sort_priority >= LEVELCLASS_BD_START &&                   \
163          (p)->sort_priority <= LEVELCLASS_BD_END)
164 #define IS_LEVELCLASS_EM(p)                                             \
165         ((p)->sort_priority >= LEVELCLASS_EM_START &&                   \
166          (p)->sort_priority <= LEVELCLASS_EM_END)
167 #define IS_LEVELCLASS_SP(p)                                             \
168         ((p)->sort_priority >= LEVELCLASS_SP_START &&                   \
169          (p)->sort_priority <= LEVELCLASS_SP_END)
170 #define IS_LEVELCLASS_DX(p)                                             \
171         ((p)->sort_priority >= LEVELCLASS_DX_START &&                   \
172          (p)->sort_priority <= LEVELCLASS_DX_END)
173 #define IS_LEVELCLASS_SB(p)                                             \
174         ((p)->sort_priority >= LEVELCLASS_SB_START &&                   \
175          (p)->sort_priority <= LEVELCLASS_SB_END)
176 #define IS_LEVELCLASS_UNDEFINED(p)                                      \
177         ((p)->sort_priority < LEVELCLASS_PREDEFINED_START ||            \
178          (p)->sort_priority > LEVELCLASS_PREDEFINED_END)
179
180 #define LEVELCLASS(n)   (IS_LEVELCLASS_TUTORIAL(n) ? LEVELCLASS_TUTORIAL : \
181                          IS_LEVELCLASS_CLASSICS(n) ? LEVELCLASS_CLASSICS : \
182                          IS_LEVELCLASS_CONTRIB(n) ? LEVELCLASS_CONTRIB :   \
183                          IS_LEVELCLASS_PRIVATE(n) ? LEVELCLASS_PRIVATE :   \
184                          IS_LEVELCLASS_BD(n) ? LEVELCLASS_BD :             \
185                          IS_LEVELCLASS_EM(n) ? LEVELCLASS_EM :             \
186                          IS_LEVELCLASS_SP(n) ? LEVELCLASS_SP :             \
187                          IS_LEVELCLASS_DX(n) ? LEVELCLASS_DX :             \
188                          IS_LEVELCLASS_SB(n) ? LEVELCLASS_SB :             \
189                          LEVELCLASS_UNDEFINED)
190
191 /* sort priorities of artwork */
192 #define ARTWORKCLASS_CLASSICS_START     100
193 #define ARTWORKCLASS_CLASSICS_END       199
194 #define ARTWORKCLASS_CONTRIB_START      200
195 #define ARTWORKCLASS_CONTRIB_END        299
196 #define ARTWORKCLASS_PRIVATE_START      300
197 #define ARTWORKCLASS_PRIVATE_END        399
198 #define ARTWORKCLASS_LEVEL_START        400
199 #define ARTWORKCLASS_LEVEL_END          499
200
201 #define ARTWORKCLASS_CLASSICS           ARTWORKCLASS_CLASSICS_START
202 #define ARTWORKCLASS_CONTRIB            ARTWORKCLASS_CONTRIB_START
203 #define ARTWORKCLASS_PRIVATE            ARTWORKCLASS_PRIVATE_START
204 #define ARTWORKCLASS_LEVEL              ARTWORKCLASS_LEVEL_START
205
206 #define ARTWORKCLASS_UNDEFINED          999
207
208 #define IS_ARTWORKCLASS_CLASSICS(p)                                     \
209         ((p)->sort_priority >= ARTWORKCLASS_CLASSICS_START &&           \
210          (p)->sort_priority <= ARTWORKCLASS_CLASSICS_END)
211 #define IS_ARTWORKCLASS_CONTRIB(p)                                      \
212         ((p)->sort_priority >= ARTWORKCLASS_CONTRIB_START &&            \
213          (p)->sort_priority <= ARTWORKCLASS_CONTRIB_END)
214 #define IS_ARTWORKCLASS_PRIVATE(p)                                      \
215         ((p)->sort_priority >= ARTWORKCLASS_PRIVATE_START &&            \
216          (p)->sort_priority <= ARTWORKCLASS_PRIVATE_END)
217 #define IS_ARTWORKCLASS_LEVEL(p)                                        \
218         ((p)->sort_priority >= ARTWORKCLASS_LEVEL_START &&              \
219          (p)->sort_priority <= ARTWORKCLASS_LEVEL_END)
220
221 #define ARTWORKCLASS(n) (IS_ARTWORKCLASS_CLASSICS(n) ? ARTWORKCLASS_CLASSICS :\
222                          IS_ARTWORKCLASS_CONTRIB(n) ? ARTWORKCLASS_CONTRIB :  \
223                          IS_ARTWORKCLASS_PRIVATE(n) ? ARTWORKCLASS_PRIVATE :  \
224                          IS_ARTWORKCLASS_LEVEL(n) ? ARTWORKCLASS_LEVEL :      \
225                          ARTWORKCLASS_UNDEFINED)
226
227
228 char *setLevelArtworkDir(TreeInfo *);
229 char *getProgramMainDataPath(char *, char *);
230 char *getProgramConfigFilename(char *);
231 char *getTapeFilename(int);
232 char *getSolutionTapeFilename(int);
233 char *getScoreFilename(int);
234 char *getSetupFilename(void);
235 char *getDefaultSetupFilename(void);
236 char *getEditorSetupFilename(void);
237 char *getHelpAnimFilename(void);
238 char *getHelpTextFilename(void);
239 char *getLevelSetInfoFilename(void);
240 char *getLevelSetTitleMessageFilename(int, boolean);
241 char *getImageFilename(char *);
242 char *getCustomImageFilename(char *);
243 char *getCustomSoundFilename(char *);
244 char *getCustomMusicFilename(char *);
245 char *getCustomArtworkFilename(char *, int);
246 char *getCustomArtworkConfigFilename(int);
247 char *getCustomArtworkLevelConfigFilename(int);
248 char *getCustomMusicDirectory(void);
249
250 void InitTapeDirectory(char *);
251 void InitScoreDirectory(char *);
252 void InitUserLevelDirectory(char *);
253 void InitNetworkLevelDirectory(char *);
254 void InitLevelSetupDirectory(char *);
255
256 TreeInfo *newTreeInfo(void);
257 TreeInfo *newTreeInfo_setDefaults(int);
258 void pushTreeInfo(TreeInfo **, TreeInfo *);
259 int numTreeInfo(TreeInfo *);
260 boolean validLevelSeries(TreeInfo *);
261 TreeInfo *getFirstValidTreeInfoEntry(TreeInfo *);
262 TreeInfo *getTreeInfoFirstGroupEntry(TreeInfo *);
263 int numTreeInfoInGroup(TreeInfo *);
264 int posTreeInfo(TreeInfo *);
265 TreeInfo *getTreeInfoFromPos(TreeInfo *, int);
266 TreeInfo *getTreeInfoFromIdentifier(TreeInfo *, char *);
267 void dumpTreeInfo(TreeInfo *, int);
268 void sortTreeInfoBySortFunction(TreeInfo **,
269                                 int (*compare_function)(const void *,
270                                                         const void *));
271 void sortTreeInfo(TreeInfo **);
272 void freeTreeInfo(TreeInfo *);
273
274 char *getHomeDir(void);
275 char *getCommonDataDir(void);
276 char *getPersonalDataDir(void);
277 char *getUserGameDataDir(void);
278 char *getSetupDir(void);
279 char *getUserLevelDir(char *);
280 char *getNetworkLevelDir(char *);
281 char *getCurrentLevelDir(void);
282 char *getNewUserLevelSubdir(void);
283
284 void createDirectory(char *, char *, int);
285 void InitUserDataDirectory(void);
286 void SetFilePermissions(char *, int);
287
288 char *getCookie(char *);
289 void fprintFileHeader(FILE *, char *);
290 int getFileVersionFromCookieString(const char *);
291 boolean checkCookieString(const char *, const char *);
292
293 char *getFormattedSetupEntry(char *, char *);
294
295 boolean getTokenValueFromSetupLine(char *, char **, char **);
296
297 SetupFileList *newSetupFileList(char *, char *);
298 void freeSetupFileList(SetupFileList *);
299 char *getListEntry(SetupFileList *, char *);
300 SetupFileList *setListEntry(SetupFileList *, char *, char *);
301 SetupFileList *addListEntry(SetupFileList *, char *, char *);
302 SetupFileList *loadSetupFileList(char *);
303
304 SetupFileHash *newSetupFileHash(void);
305 void freeSetupFileHash(SetupFileHash *);
306 char *getHashEntry(SetupFileHash *, char *);
307 void setHashEntry(SetupFileHash *, char *, char *);
308 char *removeHashEntry(SetupFileHash *, char *);
309 SetupFileHash *loadSetupFileHash(char *);
310 void setSetupInfo(struct TokenInfo *, int, char *);
311 char *getSetupValue(int, void *);
312 char *getSetupLine(struct TokenInfo *, char *, int);
313
314 unsigned int get_hash_from_key(void *);
315
316 boolean AdjustGraphicsForEMC(void);
317
318 void LoadLevelInfo(void);
319 void LoadArtworkInfo(void);
320 void LoadLevelArtworkInfo(void);
321
322 char *getArtworkIdentifierForUserLevelSet(int);
323 TreeInfo *getArtworkTreeInfoForUserLevelSet(int);
324 boolean checkIfCustomArtworkExistsForCurrentLevelSet(void);
325 void AddUserLevelSetToLevelInfo(char *);
326 boolean UpdateUserLevelSet(char *, char *, char *, int);
327 boolean CreateUserLevelSet(char *, char *, char *, int, boolean);
328
329 void LoadLevelSetup_LastSeries(void);
330 void SaveLevelSetup_LastSeries(void);
331 void SaveLevelSetup_LastSeries_Deactivate(void);
332 void LoadLevelSetup_SeriesInfo(void);
333 void SaveLevelSetup_SeriesInfo(void);
334
335 int LevelStats_getPlayed(int);
336 int LevelStats_getSolved(int);
337 void LevelStats_setPlayed(int, int);
338 void LevelStats_setSolved(int, int);
339 void LevelStats_incPlayed(int);
340 void LevelStats_incSolved(int);
341
342 #endif /* MISC_H */