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