b0b6a8d2dfbc998fda2d1f85082a7caed3d0f412
[rocksndiamonds.git] / src / libgame / setup.h
1 /***********************************************************
2 * Artsoft Retro-Game Library                               *
3 *----------------------------------------------------------*
4 * (c) 1994-2006 Artsoft Entertainment                      *
5 *               Holger Schemel                             *
6 *               Detmolder Strasse 189                      *
7 *               33604 Bielefeld                            *
8 *               Germany                                    *
9 *               e-mail: info@artsoft.org                   *
10 *----------------------------------------------------------*
11 * setup.h                                                  *
12 ***********************************************************/
13
14 #ifndef SETUP_H
15 #define SETUP_H
16
17 #include "system.h"
18 #include "hash.h"
19
20
21 /* values for setup file handling */
22 #define TYPE_BOOLEAN                    (1 << 0)
23 #define TYPE_SWITCH                     (1 << 1)
24 #define TYPE_SWITCH3                    (1 << 2)
25 #define TYPE_YES_NO                     (1 << 3)
26 #define TYPE_YES_NO_AUTO                (1 << 4)
27 #define TYPE_ECS_AGA                    (1 << 5)
28 #define TYPE_KEY                        (1 << 6)
29 #define TYPE_KEY_X11                    (1 << 7)
30 #define TYPE_INTEGER                    (1 << 8)
31 #define TYPE_STRING                     (1 << 9)
32 #define TYPE_ELEMENT                    (1 << 10)
33 #define TYPE_GRAPHIC                    (1 << 11)
34
35 /* additional values for setup screen */
36 #define TYPE_ENTER_SCREEN               (1 << 12)
37 #define TYPE_LEAVE_SCREEN               (1 << 13)
38 #define TYPE_ENTER_MENU                 (1 << 14)
39 #define TYPE_LEAVE_MENU                 (1 << 15)
40 #define TYPE_ENTER_LIST                 (1 << 16)
41 #define TYPE_LEAVE_LIST                 (1 << 17)
42 #define TYPE_EMPTY                      (1 << 18)
43 #define TYPE_KEYTEXT                    (1 << 19)
44
45 #define TYPE_GHOSTED                    (1 << 20)
46 #define TYPE_QUERY                      (1 << 21)
47
48 /* additional values for internal purposes */
49 #define TYPE_BITFIELD                   (1 << 22)
50 #define TYPE_CONTENT                    (1 << 23)
51 #define TYPE_ELEMENT_LIST               (1 << 24)
52 #define TYPE_CONTENT_LIST               (1 << 25)
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_ELEMENT           | \
69                                          TYPE_GRAPHIC)
70
71 #define TYPE_SKIP_ENTRY                 (TYPE_EMPTY             | \
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 /* cookie token for file identifier and version number */
87 #define TOKEN_STR_FILE_IDENTIFIER       "file_identifier"
88
89 struct TokenInfo
90 {
91   int type;
92   void *value;
93   char *text;
94 };
95
96 /* some definitions for list and hash handling */
97 typedef struct SetupFileList SetupFileList;
98 typedef struct hashtable     SetupFileHash;
99
100 #define BEGIN_HASH_ITERATION(hash, itr)                         \
101   if (hash != NULL && hashtable_count(hash) > 0)                \
102   {                                                             \
103     struct hashtable_itr *itr = hashtable_iterator(hash);       \
104     do {                                                        \
105
106 #define HASH_ITERATION_TOKEN(itr)       ((char *)hashtable_iterator_key(itr))
107 #define HASH_ITERATION_VALUE(itr)       ((char *)hashtable_iterator_value(itr))
108
109 #define END_HASH_ITERATION(hash, itr)                           \
110     } while (hashtable_iterator_advance(itr));                  \
111     free(itr);                                                  \
112   }                                                             \
113
114
115 /* sort priorities of level series (also used as level series classes) */
116 #define LEVELCLASS_TUTORIAL_START       10
117 #define LEVELCLASS_TUTORIAL_END         99
118 #define LEVELCLASS_CLASSICS_START       100
119 #define LEVELCLASS_CLASSICS_END         199
120 #define LEVELCLASS_CONTRIB_START        200
121 #define LEVELCLASS_CONTRIB_END          299
122 #define LEVELCLASS_PRIVATE_START        300
123 #define LEVELCLASS_PRIVATE_END          399
124 #define LEVELCLASS_BD_START             400
125 #define LEVELCLASS_BD_END               499
126 #define LEVELCLASS_EM_START             500
127 #define LEVELCLASS_EM_END               599
128 #define LEVELCLASS_SP_START             600
129 #define LEVELCLASS_SP_END               699
130 #define LEVELCLASS_DX_START             700
131 #define LEVELCLASS_DX_END               799
132 #define LEVELCLASS_SB_START             800
133 #define LEVELCLASS_SB_END               899
134
135 #define LEVELCLASS_PREDEFINED_START     LEVELCLASS_TUTORIAL_START
136 #define LEVELCLASS_PREDEFINED_END       LEVELCLASS_SB_END
137
138 #define LEVELCLASS_TUTORIAL             LEVELCLASS_TUTORIAL_START
139 #define LEVELCLASS_CLASSICS             LEVELCLASS_CLASSICS_START
140 #define LEVELCLASS_CONTRIB              LEVELCLASS_CONTRIB_START
141 #define LEVELCLASS_PRIVATE              LEVELCLASS_PRIVATE_START
142 #define LEVELCLASS_BD                   LEVELCLASS_BD_START
143 #define LEVELCLASS_EM                   LEVELCLASS_EM_START
144 #define LEVELCLASS_SP                   LEVELCLASS_SP_START
145 #define LEVELCLASS_DX                   LEVELCLASS_DX_START
146 #define LEVELCLASS_SB                   LEVELCLASS_SB_START
147
148 #define LEVELCLASS_UNDEFINED            999
149
150 #define IS_LEVELCLASS_TUTORIAL(p)                                       \
151         ((p)->sort_priority >= LEVELCLASS_TUTORIAL_START &&             \
152          (p)->sort_priority <= LEVELCLASS_TUTORIAL_END)
153 #define IS_LEVELCLASS_CLASSICS(p)                                       \
154         ((p)->sort_priority >= LEVELCLASS_CLASSICS_START &&             \
155          (p)->sort_priority <= LEVELCLASS_CLASSICS_END)
156 #define IS_LEVELCLASS_CONTRIB(p)                                        \
157         ((p)->sort_priority >= LEVELCLASS_CONTRIB_START &&              \
158          (p)->sort_priority <= LEVELCLASS_CONTRIB_END)
159 #define IS_LEVELCLASS_PRIVATE(p)                                        \
160         ((p)->sort_priority >= LEVELCLASS_PRIVATE_START &&              \
161          (p)->sort_priority <= LEVELCLASS_PRIVATE_END)
162 #define IS_LEVELCLASS_BD(p)                                             \
163         ((p)->sort_priority >= LEVELCLASS_BD_START &&                   \
164          (p)->sort_priority <= LEVELCLASS_BD_END)
165 #define IS_LEVELCLASS_EM(p)                                             \
166         ((p)->sort_priority >= LEVELCLASS_EM_START &&                   \
167          (p)->sort_priority <= LEVELCLASS_EM_END)
168 #define IS_LEVELCLASS_SP(p)                                             \
169         ((p)->sort_priority >= LEVELCLASS_SP_START &&                   \
170          (p)->sort_priority <= LEVELCLASS_SP_END)
171 #define IS_LEVELCLASS_DX(p)                                             \
172         ((p)->sort_priority >= LEVELCLASS_DX_START &&                   \
173          (p)->sort_priority <= LEVELCLASS_DX_END)
174 #define IS_LEVELCLASS_SB(p)                                             \
175         ((p)->sort_priority >= LEVELCLASS_SB_START &&                   \
176          (p)->sort_priority <= LEVELCLASS_SB_END)
177 #define IS_LEVELCLASS_UNDEFINED(p)                                      \
178         ((p)->sort_priority < LEVELCLASS_PREDEFINED_START ||            \
179          (p)->sort_priority > LEVELCLASS_PREDEFINED_END)
180
181 #define LEVELCLASS(n)   (IS_LEVELCLASS_TUTORIAL(n) ? LEVELCLASS_TUTORIAL : \
182                          IS_LEVELCLASS_CLASSICS(n) ? LEVELCLASS_CLASSICS : \
183                          IS_LEVELCLASS_CONTRIB(n) ? LEVELCLASS_CONTRIB :   \
184                          IS_LEVELCLASS_PRIVATE(n) ? LEVELCLASS_PRIVATE :   \
185                          IS_LEVELCLASS_BD(n) ? LEVELCLASS_BD :             \
186                          IS_LEVELCLASS_EM(n) ? LEVELCLASS_EM :             \
187                          IS_LEVELCLASS_SP(n) ? LEVELCLASS_SP :             \
188                          IS_LEVELCLASS_DX(n) ? LEVELCLASS_DX :             \
189                          IS_LEVELCLASS_SB(n) ? LEVELCLASS_SB :             \
190                          LEVELCLASS_UNDEFINED)
191
192 /* sort priorities of artwork */
193 #define ARTWORKCLASS_CLASSICS_START     100
194 #define ARTWORKCLASS_CLASSICS_END       199
195 #define ARTWORKCLASS_CONTRIB_START      200
196 #define ARTWORKCLASS_CONTRIB_END        299
197 #define ARTWORKCLASS_PRIVATE_START      300
198 #define ARTWORKCLASS_PRIVATE_END        399
199 #define ARTWORKCLASS_LEVEL_START        400
200 #define ARTWORKCLASS_LEVEL_END          499
201
202 #define ARTWORKCLASS_CLASSICS           ARTWORKCLASS_CLASSICS_START
203 #define ARTWORKCLASS_CONTRIB            ARTWORKCLASS_CONTRIB_START
204 #define ARTWORKCLASS_PRIVATE            ARTWORKCLASS_PRIVATE_START
205 #define ARTWORKCLASS_LEVEL              ARTWORKCLASS_LEVEL_START
206
207 #define ARTWORKCLASS_UNDEFINED          999
208
209 #define IS_ARTWORKCLASS_CLASSICS(p)                                     \
210         ((p)->sort_priority >= ARTWORKCLASS_CLASSICS_START &&           \
211          (p)->sort_priority <= ARTWORKCLASS_CLASSICS_END)
212 #define IS_ARTWORKCLASS_CONTRIB(p)                                      \
213         ((p)->sort_priority >= ARTWORKCLASS_CONTRIB_START &&            \
214          (p)->sort_priority <= ARTWORKCLASS_CONTRIB_END)
215 #define IS_ARTWORKCLASS_PRIVATE(p)                                      \
216         ((p)->sort_priority >= ARTWORKCLASS_PRIVATE_START &&            \
217          (p)->sort_priority <= ARTWORKCLASS_PRIVATE_END)
218 #define IS_ARTWORKCLASS_LEVEL(p)                                        \
219         ((p)->sort_priority >= ARTWORKCLASS_LEVEL_START &&              \
220          (p)->sort_priority <= ARTWORKCLASS_LEVEL_END)
221
222 #define ARTWORKCLASS(n) (IS_ARTWORKCLASS_CLASSICS(n) ? ARTWORKCLASS_CLASSICS :\
223                          IS_ARTWORKCLASS_CONTRIB(n) ? ARTWORKCLASS_CONTRIB :  \
224                          IS_ARTWORKCLASS_PRIVATE(n) ? ARTWORKCLASS_PRIVATE :  \
225                          IS_ARTWORKCLASS_LEVEL(n) ? ARTWORKCLASS_LEVEL :      \
226                          ARTWORKCLASS_UNDEFINED)
227
228
229 char *setLevelArtworkDir(TreeInfo *);
230 char *getTapeFilename(int);
231 char *getSolutionTapeFilename(int);
232 char *getScoreFilename(int);
233 char *getSetupFilename(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
270 char *getHomeDir(void);
271 char *getCommonDataDir(void);
272 char *getPersonalDataDir(void);
273 char *getUserGameDataDir(void);
274 char *getSetupDir(void);
275 char *getCurrentLevelDir(void);
276
277 void updateUserGameDataDir(void);
278
279 void createDirectory(char *, char *, int);
280 void InitUserDataDirectory(void);
281 void SetFilePermissions(char *, int);
282
283 char *getCookie(char *);
284 int getFileVersionFromCookieString(const char *);
285 boolean checkCookieString(const char *, const char *);
286
287 char *getFormattedSetupEntry(char *, char *);
288
289 boolean getTokenValueFromSetupLine(char *, char **, char **);
290
291 SetupFileList *newSetupFileList(char *, char *);
292 void freeSetupFileList(SetupFileList *);
293 char *getListEntry(SetupFileList *, char *);
294 SetupFileList *setListEntry(SetupFileList *, char *, char *);
295 SetupFileList *addListEntry(SetupFileList *, char *, char *);
296 SetupFileList *loadSetupFileList(char *);
297
298 SetupFileHash *newSetupFileHash();
299 void freeSetupFileHash(SetupFileHash *);
300 char *getHashEntry(SetupFileHash *, char *);
301 void setHashEntry(SetupFileHash *, char *, char *);
302 char *removeHashEntry(SetupFileHash *, char *);
303 SetupFileHash *loadSetupFileHash(char *);
304 void checkSetupFileHashIdentifier(SetupFileHash *, char *, char *);
305 void setSetupInfo(struct TokenInfo *, int, char *);
306 char *getSetupValue(int, void *);
307 char *getSetupLine(struct TokenInfo *, char *, int);
308
309 unsigned int get_hash_from_key(void *);
310
311 boolean AdjustGraphicsForEMC();
312
313 void LoadLevelInfo(void);
314 void LoadArtworkInfo(void);
315 void LoadLevelArtworkInfo(void);
316
317 void LoadLevelSetup_LastSeries(void);
318 void SaveLevelSetup_LastSeries(void);
319 void LoadLevelSetup_SeriesInfo(void);
320 void SaveLevelSetup_SeriesInfo(void);
321
322 #endif /* MISC_H */