fixed score of some game elements when reading native DC2 levels
[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 level series (also used as level series classes)
118 #define LEVELCLASS_TUTORIAL_START       10
119 #define LEVELCLASS_TUTORIAL_END         99
120 #define LEVELCLASS_CLASSICS_START       100
121 #define LEVELCLASS_CLASSICS_END         199
122 #define LEVELCLASS_CONTRIB_START        200
123 #define LEVELCLASS_CONTRIB_END          299
124 #define LEVELCLASS_PRIVATE_START        300
125 #define LEVELCLASS_PRIVATE_END          399
126 #define LEVELCLASS_BD_START             400
127 #define LEVELCLASS_BD_END               499
128 #define LEVELCLASS_EM_START             500
129 #define LEVELCLASS_EM_END               599
130 #define LEVELCLASS_SP_START             600
131 #define LEVELCLASS_SP_END               699
132 #define LEVELCLASS_DX_START             700
133 #define LEVELCLASS_DX_END               799
134 #define LEVELCLASS_SB_START             800
135 #define LEVELCLASS_SB_END               899
136
137 #define LEVELCLASS_PREDEFINED_START     LEVELCLASS_TUTORIAL_START
138 #define LEVELCLASS_PREDEFINED_END       LEVELCLASS_SB_END
139
140 #define LEVELCLASS_TUTORIAL             LEVELCLASS_TUTORIAL_START
141 #define LEVELCLASS_CLASSICS             LEVELCLASS_CLASSICS_START
142 #define LEVELCLASS_CONTRIB              LEVELCLASS_CONTRIB_START
143 #define LEVELCLASS_PRIVATE              LEVELCLASS_PRIVATE_START
144 #define LEVELCLASS_BD                   LEVELCLASS_BD_START
145 #define LEVELCLASS_EM                   LEVELCLASS_EM_START
146 #define LEVELCLASS_SP                   LEVELCLASS_SP_START
147 #define LEVELCLASS_DX                   LEVELCLASS_DX_START
148 #define LEVELCLASS_SB                   LEVELCLASS_SB_START
149
150 #define LEVELCLASS_UNDEFINED            999
151
152 #define IS_LEVELCLASS_TUTORIAL(p)                                       \
153         ((p)->sort_priority >= LEVELCLASS_TUTORIAL_START &&             \
154          (p)->sort_priority <= LEVELCLASS_TUTORIAL_END)
155 #define IS_LEVELCLASS_CLASSICS(p)                                       \
156         ((p)->sort_priority >= LEVELCLASS_CLASSICS_START &&             \
157          (p)->sort_priority <= LEVELCLASS_CLASSICS_END)
158 #define IS_LEVELCLASS_CONTRIB(p)                                        \
159         ((p)->sort_priority >= LEVELCLASS_CONTRIB_START &&              \
160          (p)->sort_priority <= LEVELCLASS_CONTRIB_END)
161 #define IS_LEVELCLASS_PRIVATE(p)                                        \
162         ((p)->sort_priority >= LEVELCLASS_PRIVATE_START &&              \
163          (p)->sort_priority <= LEVELCLASS_PRIVATE_END)
164 #define IS_LEVELCLASS_BD(p)                                             \
165         ((p)->sort_priority >= LEVELCLASS_BD_START &&                   \
166          (p)->sort_priority <= LEVELCLASS_BD_END)
167 #define IS_LEVELCLASS_EM(p)                                             \
168         ((p)->sort_priority >= LEVELCLASS_EM_START &&                   \
169          (p)->sort_priority <= LEVELCLASS_EM_END)
170 #define IS_LEVELCLASS_SP(p)                                             \
171         ((p)->sort_priority >= LEVELCLASS_SP_START &&                   \
172          (p)->sort_priority <= LEVELCLASS_SP_END)
173 #define IS_LEVELCLASS_DX(p)                                             \
174         ((p)->sort_priority >= LEVELCLASS_DX_START &&                   \
175          (p)->sort_priority <= LEVELCLASS_DX_END)
176 #define IS_LEVELCLASS_SB(p)                                             \
177         ((p)->sort_priority >= LEVELCLASS_SB_START &&                   \
178          (p)->sort_priority <= LEVELCLASS_SB_END)
179 #define IS_LEVELCLASS_UNDEFINED(p)                                      \
180         ((p)->sort_priority < LEVELCLASS_PREDEFINED_START ||            \
181          (p)->sort_priority > LEVELCLASS_PREDEFINED_END)
182
183 #define LEVELCLASS(n)   (IS_LEVELCLASS_TUTORIAL(n) ? LEVELCLASS_TUTORIAL : \
184                          IS_LEVELCLASS_CLASSICS(n) ? LEVELCLASS_CLASSICS : \
185                          IS_LEVELCLASS_CONTRIB(n) ? LEVELCLASS_CONTRIB :   \
186                          IS_LEVELCLASS_PRIVATE(n) ? LEVELCLASS_PRIVATE :   \
187                          IS_LEVELCLASS_BD(n) ? LEVELCLASS_BD :             \
188                          IS_LEVELCLASS_EM(n) ? LEVELCLASS_EM :             \
189                          IS_LEVELCLASS_SP(n) ? LEVELCLASS_SP :             \
190                          IS_LEVELCLASS_DX(n) ? LEVELCLASS_DX :             \
191                          IS_LEVELCLASS_SB(n) ? LEVELCLASS_SB :             \
192                          LEVELCLASS_UNDEFINED)
193
194 // sort priorities of artwork
195 #define ARTWORKCLASS_CLASSICS_START     100
196 #define ARTWORKCLASS_CLASSICS_END       199
197 #define ARTWORKCLASS_CONTRIB_START      200
198 #define ARTWORKCLASS_CONTRIB_END        299
199 #define ARTWORKCLASS_PRIVATE_START      300
200 #define ARTWORKCLASS_PRIVATE_END        399
201 #define ARTWORKCLASS_LEVEL_START        400
202 #define ARTWORKCLASS_LEVEL_END          499
203
204 #define ARTWORKCLASS_CLASSICS           ARTWORKCLASS_CLASSICS_START
205 #define ARTWORKCLASS_CONTRIB            ARTWORKCLASS_CONTRIB_START
206 #define ARTWORKCLASS_PRIVATE            ARTWORKCLASS_PRIVATE_START
207 #define ARTWORKCLASS_LEVEL              ARTWORKCLASS_LEVEL_START
208
209 #define ARTWORKCLASS_UNDEFINED          999
210
211 #define IS_ARTWORKCLASS_CLASSICS(p)                                     \
212         ((p)->sort_priority >= ARTWORKCLASS_CLASSICS_START &&           \
213          (p)->sort_priority <= ARTWORKCLASS_CLASSICS_END)
214 #define IS_ARTWORKCLASS_CONTRIB(p)                                      \
215         ((p)->sort_priority >= ARTWORKCLASS_CONTRIB_START &&            \
216          (p)->sort_priority <= ARTWORKCLASS_CONTRIB_END)
217 #define IS_ARTWORKCLASS_PRIVATE(p)                                      \
218         ((p)->sort_priority >= ARTWORKCLASS_PRIVATE_START &&            \
219          (p)->sort_priority <= ARTWORKCLASS_PRIVATE_END)
220 #define IS_ARTWORKCLASS_LEVEL(p)                                        \
221         ((p)->sort_priority >= ARTWORKCLASS_LEVEL_START &&              \
222          (p)->sort_priority <= ARTWORKCLASS_LEVEL_END)
223
224 #define ARTWORKCLASS(n) (IS_ARTWORKCLASS_CLASSICS(n) ? ARTWORKCLASS_CLASSICS :\
225                          IS_ARTWORKCLASS_CONTRIB(n) ? ARTWORKCLASS_CONTRIB :  \
226                          IS_ARTWORKCLASS_PRIVATE(n) ? ARTWORKCLASS_PRIVATE :  \
227                          IS_ARTWORKCLASS_LEVEL(n) ? ARTWORKCLASS_LEVEL :      \
228                          ARTWORKCLASS_UNDEFINED)
229
230
231 char *getUserGraphicsDir(void);
232 char *getUserSoundsDir(void);
233 char *getUserMusicDir(void);
234 char *setLevelArtworkDir(TreeInfo *);
235 char *getProgramMainDataPath(char *, char *);
236 char *getProgramConfigFilename(char *);
237 char *getTapeFilename(int);
238 char *getSolutionTapeFilename(int);
239 char *getScoreFilename(int);
240 char *getSetupFilename(void);
241 char *getDefaultSetupFilename(void);
242 char *getEditorSetupFilename(void);
243 char *getHelpAnimFilename(void);
244 char *getHelpTextFilename(void);
245 char *getLevelSetInfoFilename(void);
246 char *getLevelSetTitleMessageFilename(int, boolean);
247 char *getImageFilename(char *);
248 char *getCustomImageFilename(char *);
249 char *getCustomSoundFilename(char *);
250 char *getCustomMusicFilename(char *);
251 char *getCustomArtworkFilename(char *, int);
252 char *getCustomArtworkConfigFilename(int);
253 char *getCustomArtworkLevelConfigFilename(int);
254 char *getCustomMusicDirectory(void);
255
256 void InitTapeDirectory(char *);
257 void InitScoreDirectory(char *);
258 void InitUserLevelDirectory(char *);
259 void InitNetworkLevelDirectory(char *);
260 void InitLevelSetupDirectory(char *);
261
262 TreeInfo *newTreeInfo(void);
263 TreeInfo *newTreeInfo_setDefaults(int);
264 void pushTreeInfo(TreeInfo **, TreeInfo *);
265 int numTreeInfo(TreeInfo *);
266 boolean validLevelSeries(TreeInfo *);
267 TreeInfo *getFirstValidTreeInfoEntry(TreeInfo *);
268 TreeInfo *getTreeInfoFirstGroupEntry(TreeInfo *);
269 int numTreeInfoInGroup(TreeInfo *);
270 int posTreeInfo(TreeInfo *);
271 TreeInfo *getTreeInfoFromPos(TreeInfo *, int);
272 TreeInfo *getTreeInfoFromIdentifier(TreeInfo *, char *);
273 void dumpTreeInfo(TreeInfo *, int);
274 void sortTreeInfoBySortFunction(TreeInfo **,
275                                 int (*compare_function)(const void *,
276                                                         const void *));
277 void sortTreeInfo(TreeInfo **);
278 void freeTreeInfo(TreeInfo *);
279
280 char *getHomeDir(void);
281 char *getCommonDataDir(void);
282 char *getPersonalDataDir(void);
283 char *getUserGameDataDir(void);
284 char *getSetupDir(void);
285 char *getLevelDirFromTreeInfo(TreeInfo *);
286 char *getUserLevelDir(char *);
287 char *getNetworkLevelDir(char *);
288 char *getCurrentLevelDir(void);
289 char *getNewUserLevelSubdir(void);
290
291 void createDirectory(char *, char *, int);
292 void InitUserDataDirectory(void);
293 void SetFilePermissions(char *, int);
294
295 char *getCookie(char *);
296 void fprintFileHeader(FILE *, char *);
297 int getFileVersionFromCookieString(const char *);
298 boolean checkCookieString(const char *, const char *);
299
300 char *getFormattedSetupEntry(char *, char *);
301
302 boolean getTokenValueFromSetupLine(char *, char **, char **);
303
304 SetupFileList *newSetupFileList(char *, char *);
305 void freeSetupFileList(SetupFileList *);
306 char *getListEntry(SetupFileList *, char *);
307 SetupFileList *setListEntry(SetupFileList *, char *, char *);
308 SetupFileList *addListEntry(SetupFileList *, char *, char *);
309 SetupFileList *loadSetupFileList(char *);
310
311 SetupFileHash *newSetupFileHash(void);
312 void freeSetupFileHash(SetupFileHash *);
313 char *getHashEntry(SetupFileHash *, char *);
314 void setHashEntry(SetupFileHash *, char *, char *);
315 char *removeHashEntry(SetupFileHash *, char *);
316 SetupFileHash *loadSetupFileHash(char *);
317 void setSetupInfo(struct TokenInfo *, int, char *);
318 char *getSetupValue(int, void *);
319 char *getSetupLine(struct TokenInfo *, char *, int);
320
321 unsigned int get_hash_from_key(void *);
322
323 int GetZipFileTreeType(char *);
324 char *ExtractZipFileIntoDirectory(char *, char *, int);
325
326 boolean AdjustGraphicsForEMC(void);
327 boolean AdjustSoundsForEMC(void);
328
329 void LoadLevelInfo(void);
330 void LoadArtworkInfo(void);
331 void LoadLevelArtworkInfo(void);
332
333 char *getArtworkIdentifierForUserLevelSet(int);
334 TreeInfo *getArtworkTreeInfoForUserLevelSet(int);
335 boolean checkIfCustomArtworkExistsForCurrentLevelSet(void);
336 void AddUserLevelSetToLevelInfo(char *);
337 void AddTreeSetToTreeInfo(TreeInfo *, char *, char *, int);
338 boolean UpdateUserLevelSet(char *, char *, char *, int);
339 boolean CreateUserLevelSet(char *, char *, char *, int, boolean);
340
341 void LoadLevelSetup_LastSeries(void);
342 void SaveLevelSetup_LastSeries(void);
343 void SaveLevelSetup_LastSeries_Deactivate(void);
344 void LoadLevelSetup_SeriesInfo(void);
345 void SaveLevelSetup_SeriesInfo(void);
346
347 int LevelStats_getPlayed(int);
348 int LevelStats_getSolved(int);
349 void LevelStats_setPlayed(int, int);
350 void LevelStats_setSolved(int, int);
351 void LevelStats_incPlayed(int);
352 void LevelStats_incSolved(int);
353
354 #endif // MISC_H