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