cleanup of BD style game elements in level editor
[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 //                  https://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_TEXT_INPUT                 (1 << 19)
42 #define TYPE_EMPTY                      (1 << 20)
43 #define TYPE_SKIPPABLE                  (1 << 21)
44 #define TYPE_KEYTEXT                    (1 << 22)
45 #define TYPE_HEADLINE                   (1 << 23)
46
47 #define TYPE_GHOSTED                    (1 << 24)
48 #define TYPE_QUERY                      (1 << 25)
49
50 // additional values for internal purposes
51 #define TYPE_BITFIELD                   (1 << 26)
52 #define TYPE_CONTENT                    (1 << 27)
53 #define TYPE_ELEMENT_LIST               (1 << 28)
54 #define TYPE_CONTENT_LIST               (1 << 29)
55
56 // derived values for setup file handling
57 #define TYPE_BOOLEAN_STYLE              (TYPE_BOOLEAN | \
58                                          TYPE_SWITCH  | \
59                                          TYPE_YES_NO  | \
60                                          TYPE_ECS_AGA )
61
62 // derived values for setup screen
63 #define TYPE_VALUE                      (TYPE_BOOLEAN_STYLE     | \
64                                          TYPE_SWITCH3           | \
65                                          TYPE_YES_NO_AUTO       | \
66                                          TYPE_KEY               | \
67                                          TYPE_KEY_X11           | \
68                                          TYPE_INTEGER           | \
69                                          TYPE_STRING            | \
70                                          TYPE_PLAYER            | \
71                                          TYPE_ELEMENT           | \
72                                          TYPE_GRAPHIC)
73
74 #define TYPE_SKIP_ENTRY                 (TYPE_EMPTY             | \
75                                          TYPE_SKIPPABLE         | \
76                                          TYPE_KEY               | \
77                                          TYPE_STRING            | \
78                                          TYPE_HEADLINE          | \
79                                          TYPE_GHOSTED)
80
81 #define TYPE_ENTER                      (TYPE_ENTER_SCREEN      | \
82                                          TYPE_ENTER_MENU        | \
83                                          TYPE_ENTER_LIST)
84
85 #define TYPE_LEAVE                      (TYPE_LEAVE_SCREEN      | \
86                                          TYPE_LEAVE_MENU        | \
87                                          TYPE_LEAVE_LIST)
88
89 #define TYPE_ENTER_OR_LEAVE             (TYPE_ENTER | TYPE_LEAVE)
90
91 struct TokenInfo
92 {
93   int type;
94   void *value;
95   char *text;
96 };
97
98 // some definitions for list and hash handling
99 typedef struct SetupFileList SetupFileList;
100 typedef struct hashtable     SetupFileHash;
101
102 #define BEGIN_HASH_ITERATION(hash, itr)                         \
103   if (hash != NULL && hashtable_count(hash) > 0)                \
104   {                                                             \
105     struct hashtable_itr *itr = hashtable_iterator(hash);       \
106     do {                                                        \
107
108 #define HASH_ITERATION_TOKEN(itr)       ((char *)hashtable_iterator_key(itr))
109 #define HASH_ITERATION_VALUE(itr)       ((char *)hashtable_iterator_value(itr))
110
111 #define END_HASH_ITERATION(hash, itr)                           \
112     } while (hashtable_iterator_advance(itr));                  \
113     free(itr);                                                  \
114   }                                                             \
115
116
117 // sort priorities of special tree entries
118 #define LEVELCLASS_TOP                  0
119 #define LEVELCLASS_PARENT               1
120 #define LEVELCLASS_LAST_PLAYED_LEVEL    2
121
122 // sort priorities of level series (also used as level series classes)
123 #define LEVELCLASS_TUTORIAL_START       10
124 #define LEVELCLASS_TUTORIAL_END         99
125 #define LEVELCLASS_CLASSICS_START       100
126 #define LEVELCLASS_CLASSICS_END         199
127 #define LEVELCLASS_CONTRIB_START        200
128 #define LEVELCLASS_CONTRIB_END          299
129 #define LEVELCLASS_PRIVATE_START        300
130 #define LEVELCLASS_PRIVATE_END          399
131 #define LEVELCLASS_BD_START             400
132 #define LEVELCLASS_BD_END               499
133 #define LEVELCLASS_EM_START             500
134 #define LEVELCLASS_EM_END               599
135 #define LEVELCLASS_SP_START             600
136 #define LEVELCLASS_SP_END               699
137 #define LEVELCLASS_DX_START             700
138 #define LEVELCLASS_DX_END               799
139 #define LEVELCLASS_SB_START             800
140 #define LEVELCLASS_SB_END               899
141
142 #define LEVELCLASS_PREDEFINED_START     LEVELCLASS_TUTORIAL_START
143 #define LEVELCLASS_PREDEFINED_END       LEVELCLASS_SB_END
144
145 #define LEVELCLASS_TUTORIAL             LEVELCLASS_TUTORIAL_START
146 #define LEVELCLASS_CLASSICS             LEVELCLASS_CLASSICS_START
147 #define LEVELCLASS_CONTRIB              LEVELCLASS_CONTRIB_START
148 #define LEVELCLASS_PRIVATE              LEVELCLASS_PRIVATE_START
149 #define LEVELCLASS_BD                   LEVELCLASS_BD_START
150 #define LEVELCLASS_EM                   LEVELCLASS_EM_START
151 #define LEVELCLASS_SP                   LEVELCLASS_SP_START
152 #define LEVELCLASS_DX                   LEVELCLASS_DX_START
153 #define LEVELCLASS_SB                   LEVELCLASS_SB_START
154
155 #define LEVELCLASS_UNDEFINED            999
156
157 #define IS_LEVELCLASS_TUTORIAL(p)                                       \
158         ((p)->sort_priority >= LEVELCLASS_TUTORIAL_START &&             \
159          (p)->sort_priority <= LEVELCLASS_TUTORIAL_END)
160 #define IS_LEVELCLASS_CLASSICS(p)                                       \
161         ((p)->sort_priority >= LEVELCLASS_CLASSICS_START &&             \
162          (p)->sort_priority <= LEVELCLASS_CLASSICS_END)
163 #define IS_LEVELCLASS_CONTRIB(p)                                        \
164         ((p)->sort_priority >= LEVELCLASS_CONTRIB_START &&              \
165          (p)->sort_priority <= LEVELCLASS_CONTRIB_END)
166 #define IS_LEVELCLASS_PRIVATE(p)                                        \
167         ((p)->sort_priority >= LEVELCLASS_PRIVATE_START &&              \
168          (p)->sort_priority <= LEVELCLASS_PRIVATE_END)
169 #define IS_LEVELCLASS_BD(p)                                             \
170         ((p)->sort_priority >= LEVELCLASS_BD_START &&                   \
171          (p)->sort_priority <= LEVELCLASS_BD_END)
172 #define IS_LEVELCLASS_EM(p)                                             \
173         ((p)->sort_priority >= LEVELCLASS_EM_START &&                   \
174          (p)->sort_priority <= LEVELCLASS_EM_END)
175 #define IS_LEVELCLASS_SP(p)                                             \
176         ((p)->sort_priority >= LEVELCLASS_SP_START &&                   \
177          (p)->sort_priority <= LEVELCLASS_SP_END)
178 #define IS_LEVELCLASS_DX(p)                                             \
179         ((p)->sort_priority >= LEVELCLASS_DX_START &&                   \
180          (p)->sort_priority <= LEVELCLASS_DX_END)
181 #define IS_LEVELCLASS_SB(p)                                             \
182         ((p)->sort_priority >= LEVELCLASS_SB_START &&                   \
183          (p)->sort_priority <= LEVELCLASS_SB_END)
184 #define IS_LEVELCLASS_UNDEFINED(p)                                      \
185         ((p)->sort_priority < LEVELCLASS_PREDEFINED_START ||            \
186          (p)->sort_priority > LEVELCLASS_PREDEFINED_END)
187
188 #define LEVELCLASS(n)   (IS_LEVELCLASS_TUTORIAL(n) ? LEVELCLASS_TUTORIAL : \
189                          IS_LEVELCLASS_CLASSICS(n) ? LEVELCLASS_CLASSICS : \
190                          IS_LEVELCLASS_CONTRIB(n) ? LEVELCLASS_CONTRIB :   \
191                          IS_LEVELCLASS_PRIVATE(n) ? LEVELCLASS_PRIVATE :   \
192                          IS_LEVELCLASS_BD(n) ? LEVELCLASS_BD :             \
193                          IS_LEVELCLASS_EM(n) ? LEVELCLASS_EM :             \
194                          IS_LEVELCLASS_SP(n) ? LEVELCLASS_SP :             \
195                          IS_LEVELCLASS_DX(n) ? LEVELCLASS_DX :             \
196                          IS_LEVELCLASS_SB(n) ? LEVELCLASS_SB :             \
197                          LEVELCLASS_UNDEFINED)
198
199 // sort priorities of artwork
200 #define ARTWORKCLASS_CLASSICS_START     100
201 #define ARTWORKCLASS_CLASSICS_END       199
202 #define ARTWORKCLASS_CONTRIB_START      200
203 #define ARTWORKCLASS_CONTRIB_END        299
204 #define ARTWORKCLASS_PRIVATE_START      300
205 #define ARTWORKCLASS_PRIVATE_END        399
206 #define ARTWORKCLASS_LEVEL_START        400
207 #define ARTWORKCLASS_LEVEL_END          499
208
209 #define ARTWORKCLASS_CLASSICS           ARTWORKCLASS_CLASSICS_START
210 #define ARTWORKCLASS_CONTRIB            ARTWORKCLASS_CONTRIB_START
211 #define ARTWORKCLASS_PRIVATE            ARTWORKCLASS_PRIVATE_START
212 #define ARTWORKCLASS_LEVEL              ARTWORKCLASS_LEVEL_START
213
214 #define ARTWORKCLASS_UNDEFINED          999
215
216 #define IS_ARTWORKCLASS_CLASSICS(p)                                     \
217         ((p)->sort_priority >= ARTWORKCLASS_CLASSICS_START &&           \
218          (p)->sort_priority <= ARTWORKCLASS_CLASSICS_END)
219 #define IS_ARTWORKCLASS_CONTRIB(p)                                      \
220         ((p)->sort_priority >= ARTWORKCLASS_CONTRIB_START &&            \
221          (p)->sort_priority <= ARTWORKCLASS_CONTRIB_END)
222 #define IS_ARTWORKCLASS_PRIVATE(p)                                      \
223         ((p)->sort_priority >= ARTWORKCLASS_PRIVATE_START &&            \
224          (p)->sort_priority <= ARTWORKCLASS_PRIVATE_END)
225 #define IS_ARTWORKCLASS_LEVEL(p)                                        \
226         ((p)->sort_priority >= ARTWORKCLASS_LEVEL_START &&              \
227          (p)->sort_priority <= ARTWORKCLASS_LEVEL_END)
228
229 #define ARTWORKCLASS(n) (IS_ARTWORKCLASS_CLASSICS(n) ? ARTWORKCLASS_CLASSICS :\
230                          IS_ARTWORKCLASS_CONTRIB(n) ? ARTWORKCLASS_CONTRIB :  \
231                          IS_ARTWORKCLASS_PRIVATE(n) ? ARTWORKCLASS_PRIVATE :  \
232                          IS_ARTWORKCLASS_LEVEL(n) ? ARTWORKCLASS_LEVEL :      \
233                          ARTWORKCLASS_UNDEFINED)
234
235 #define TREE_SORTING_DIR(ti)                                            \
236         (((ti)->parent_link                                ? 0 :        \
237           (ti)->in_user_dir                                ? 4 * 200 :  \
238           (ti)->sort_priority >= LEVELCLASS_CLASSICS_START ? 3 * 200 +  \
239           (ti)->sort_priority % 100 :                                   \
240           (ti)->sort_priority >= LEVELCLASS_TUTORIAL_START ? 2 * 200 +  \
241           (ti)->sort_priority % 100 :                                   \
242           1 * 200) +                                                    \
243          ((ti)->level_group ? 0 : 100))
244
245 #define TREE_COLOR_DIR(ti, active)                                      \
246         ((active)                       ? FC_YELLOW :                   \
247          TREE_SORTING(ti) / 200 == 4    ? FC_GREEN :                    \
248          TREE_SORTING(ti) / 200 == 2    ? FC_BLUE :                     \
249          FC_RED)
250
251 #define TREE_SORTING(ti)                                                \
252         (TREE_TYPE_IS_DIR((ti)->type) ? TREE_SORTING_DIR(ti) :          \
253          (ti)->sort_priority)
254
255 #define TREE_COLOR(ti, active)                                          \
256         (TREE_TYPE_IS_DIR((ti)->type) ? TREE_COLOR_DIR(ti, active) :    \
257          (ti)->color)
258
259
260 char *getUserGraphicsDir(void);
261 char *getUserSoundsDir(void);
262 char *getUserMusicDir(void);
263 char *setLevelArtworkDir(TreeInfo *);
264 char *getProgramMainDataPath(char *, char *);
265 char *getProgramConfigFilename(char *);
266 char *getTapeFilename(int);
267 char *getTemporaryTapeFilename(void);
268 char *getDefaultSolutionTapeFilename(int);
269 char *getSokobanSolutionTapeFilename(int);
270 char *getSolutionTapeFilename(int);
271 char *getScoreFilename(int);
272 char *getScoreCacheFilename(int);
273 char *getScoreTapeBasename(char *);
274 char *getScoreTapeFilename(char *, int);
275 char *getScoreCacheTapeFilename(char *, int);
276 char *getSetupFilename(void);
277 char *getDefaultSetupFilename(void);
278 char *getPlatformSetupFilename(void);
279 char *getEditorSetupFilename(void);
280 char *getHelpAnimFilename(void);
281 char *getHelpTextFilename(void);
282 char *getLevelSetInfoFilename(int);
283 char *getLevelSetTitleMessageFilename(int, boolean);
284 char *getCreditsFilename(int, boolean);
285 char *getProgramInfoFilename(int);
286 char *getImageFilename(char *);
287 char *getCustomImageFilename(char *);
288 char *getCustomSoundFilename(char *);
289 char *getCustomMusicFilename(char *);
290 char *getCustomArtworkFilename(char *, int);
291 char *getCustomArtworkConfigFilename(int);
292 char *getCustomArtworkLevelConfigFilename(int);
293 char *getCustomMusicDirectory(void);
294 char *getCustomMusicDirectory_NoConf(void);
295
296 void MarkTapeDirectoryUploadsAsComplete(char *);
297 void MarkTapeDirectoryUploadsAsIncomplete(char *);
298 boolean CheckTapeDirectoryUploadsComplete(char *);
299
300 void InitMissingFileHash(void);
301 void InitTapeDirectory(char *);
302 void InitScoreDirectory(char *);
303 void InitScoreCacheDirectory(char *);
304 void InitScoreTapeDirectory(char *, int);
305 void InitScoreCacheTapeDirectory(char *, int);
306 void InitUserLevelDirectory(char *);
307 void InitNetworkLevelDirectory(char *);
308 void InitLevelSetupDirectory(char *);
309
310 TreeInfo *newTreeInfo(void);
311 TreeInfo *newTreeInfo_setDefaults(int);
312 void pushTreeInfo(TreeInfo **, TreeInfo *);
313 void removeTreeInfo(TreeInfo **);
314 int numTreeInfo(TreeInfo *);
315 boolean validLevelSeries(TreeInfo *);
316 TreeInfo *getValidLevelSeries(TreeInfo *, TreeInfo *);
317 TreeInfo *getFirstValidTreeInfoEntry(TreeInfo *);
318 TreeInfo *getNextValidTreeInfoEntry(TreeInfo *);
319 TreeInfo *getTreeInfoFirstGroupEntry(TreeInfo *);
320 int numTreeInfoInGroup(TreeInfo *);
321 int getPosFromTreeInfo(TreeInfo *);
322 TreeInfo *getTreeInfoFromPos(TreeInfo *, int);
323 TreeInfo *getTreeInfoFromIdentifier(TreeInfo *, char *);
324 int dumpTreeInfo(TreeInfo *, int);
325 void sortTreeInfoBySortFunction(TreeInfo **,
326                                 int (*compare_function)(const void *,
327                                                         const void *));
328 void sortTreeInfo(TreeInfo **);
329 void freeTreeInfo(TreeInfo *);
330 TreeInfo *addTopTreeInfoNode(TreeInfo *);
331
332 char *getHomeDir(void);
333 char *getPersonalDataDir(void);
334 char *getMainUserGameDataDir(void);
335 char *getUserGameDataDir(void);
336 char *getSetupDir(void);
337 char *getLevelDirFromTreeInfo(TreeInfo *);
338 char *getUserLevelDir(char *);
339 char *getNetworkLevelDir(char *);
340 char *getCurrentLevelDir(void);
341 char *getNewUserLevelSubdir(void);
342 char *getTapeDir(char *);
343
344 void createDirectory(char *, char *);
345 void InitMainUserDataDirectory(void);
346 void InitUserDataDirectory(void);
347 void SetFilePermissions(char *, int);
348
349 void fprintFileHeader(FILE *, char *);
350 int getFileVersionFromCookieString(const char *);
351 boolean checkCookieString(const char *, const char *);
352
353 char *getFormattedSetupEntry(char *, char *);
354
355 boolean getTokenValueFromSetupLine(char *, char **, char **);
356
357 SetupFileList *newSetupFileList(char *, char *);
358 void freeSetupFileList(SetupFileList *);
359 char *getListEntry(SetupFileList *, char *);
360 SetupFileList *setListEntry(SetupFileList *, char *, char *);
361 SetupFileList *addListEntry(SetupFileList *, char *, char *);
362 SetupFileList *loadSetupFileList(char *);
363
364 SetupFileHash *newSetupFileHash(void);
365 void freeSetupFileHash(SetupFileHash *);
366 char *getHashEntry(SetupFileHash *, char *);
367 void setHashEntry(SetupFileHash *, char *, char *);
368 void removeHashEntry(SetupFileHash *, char *);
369 SetupFileHash *loadSetupFileHash(char *);
370 void setSetupInfo(struct TokenInfo *, int, char *);
371 char *getSetupValue(int, void *);
372 char *getSetupLine(struct TokenInfo *, char *, int);
373
374 unsigned int get_hash_from_string(void *);
375 unsigned int get_hash_from_integer(void *);
376 int hash_key_strings_are_equal(void *, void *);
377 int hash_key_integers_are_equal(void *, void *);
378
379 int GetZipFileTreeType(char *);
380 char *ExtractZipFileIntoDirectory(char *, char *, int);
381
382 boolean AdjustGraphicsForEMC(void);
383 boolean AdjustSoundsForEMC(void);
384
385 void SetCurrentArtwork(int);
386 void ChangeCurrentArtworkIfNeeded(int);
387
388 void LoadLevelInfo(void);
389 void LoadArtworkInfo(void);
390 void LoadLevelArtworkInfo(void);
391
392 char *getArtworkIdentifierForUserLevelSet(int);
393 TreeInfo *getArtworkTreeInfoForUserLevelSet(int);
394 boolean checkIfCustomArtworkExistsForCurrentLevelSet(void);
395 void AddUserLevelSetToLevelInfo(char *);
396 void AddTreeSetToTreeInfo(TreeInfo *, char *, char *, int);
397 boolean UpdateUserLevelSet(char *, char *, char *, int);
398 boolean CreateUserLevelSet(char *, char *, char *, int, boolean);
399
400 void UpdateLastPlayedLevels_TreeInfo(void);
401 void StoreLastPlayedLevels(TreeInfo *);
402 void ForcedStoreLastPlayedLevels(TreeInfo *);
403 void RestoreLastPlayedLevels(TreeInfo **);
404 boolean CheckLastPlayedLevels(void);
405
406 void LoadLevelSetup_LastSeries(void);
407 void SaveLevelSetup_LastSeries(void);
408 void SaveLevelSetup_LastSeries_Deactivate(void);
409 void LoadLevelSetup_SeriesInfo(void);
410 void SaveLevelSetup_SeriesInfo(void);
411
412 int LevelStats_getPlayed(int);
413 int LevelStats_getSolved(int);
414 void LevelStats_setPlayed(int, int);
415 void LevelStats_setSolved(int, int);
416 void LevelStats_incPlayed(int);
417 void LevelStats_incSolved(int);
418
419 void LoadUserSetup(void);
420 void SaveUserSetup(void);
421
422 #endif // MISC_H