1 // ============================================================================
2 // Artsoft Retro-Game Library
3 // ----------------------------------------------------------------------------
4 // (c) 1995-2014 by Artsoft Entertainment
7 // https://www.artsoft.org/
8 // ----------------------------------------------------------------------------
10 // ============================================================================
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)
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)
47 #define TYPE_GHOSTED (1 << 24)
48 #define TYPE_QUERY (1 << 25)
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)
56 // derived values for setup file handling
57 #define TYPE_BOOLEAN_STYLE (TYPE_BOOLEAN | \
62 // derived values for setup screen
63 #define TYPE_VALUE (TYPE_BOOLEAN_STYLE | \
74 #define TYPE_SKIP_ENTRY (TYPE_EMPTY | \
81 #define TYPE_ENTER (TYPE_ENTER_SCREEN | \
85 #define TYPE_LEAVE (TYPE_LEAVE_SCREEN | \
89 #define TYPE_ENTER_OR_LEAVE (TYPE_ENTER | TYPE_LEAVE)
98 // some definitions for list and hash handling
99 typedef struct SetupFileList SetupFileList;
100 typedef struct hashtable SetupFileHash;
102 #define BEGIN_HASH_ITERATION(hash, itr) \
103 if (hash != NULL && hashtable_count(hash) > 0) \
105 struct hashtable_itr *itr = hashtable_iterator(hash); \
108 #define HASH_ITERATION_TOKEN(itr) ((char *)hashtable_iterator_key(itr))
109 #define HASH_ITERATION_VALUE(itr) ((char *)hashtable_iterator_value(itr))
111 #define END_HASH_ITERATION(hash, itr) \
112 } while (hashtable_iterator_advance(itr)); \
117 // sort priorities of special tree entries
118 #define LEVELCLASS_TOP 0
119 #define LEVELCLASS_PARENT 1
120 #define LEVELCLASS_LAST_PLAYED_LEVEL 2
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
142 #define LEVELCLASS_PREDEFINED_START LEVELCLASS_TUTORIAL_START
143 #define LEVELCLASS_PREDEFINED_END LEVELCLASS_SB_END
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
155 #define LEVELCLASS_UNDEFINED 999
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)
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)
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
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
214 #define ARTWORKCLASS_UNDEFINED 999
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)
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)
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 : \
243 ((ti)->level_group ? 0 : 100))
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 : \
251 #define TREE_SORTING(ti) \
252 (TREE_TYPE_IS_DIR((ti)->type) ? TREE_SORTING_DIR(ti) : \
255 #define TREE_COLOR(ti, active) \
256 (TREE_TYPE_IS_DIR((ti)->type) ? TREE_COLOR_DIR(ti, active) : \
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);
296 void MarkTapeDirectoryUploadsAsComplete(char *);
297 void MarkTapeDirectoryUploadsAsIncomplete(char *);
298 boolean CheckTapeDirectoryUploadsComplete(char *);
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 *);
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 *,
328 void sortTreeInfo(TreeInfo **);
329 void freeTreeInfo(TreeInfo *);
330 TreeInfo *addTopTreeInfoNode(TreeInfo *);
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 *);
344 void createDirectory(char *, char *);
345 void InitMainUserDataDirectory(void);
346 void InitUserDataDirectory(void);
347 void SetFilePermissions(char *, int);
349 void fprintFileHeader(FILE *, char *);
350 int getFileVersionFromCookieString(const char *);
351 boolean checkCookieString(const char *, const char *);
353 char *getFormattedSetupEntry(char *, char *);
355 boolean getTokenValueFromSetupLine(char *, char **, char **);
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 *);
364 SetupFileHash *newSetupFileHash(void);
365 void freeSetupFileHash(SetupFileHash *);
366 char *getHashEntry(SetupFileHash *, char *);
367 void setHashEntry(SetupFileHash *, char *, char *);
368 char *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);
374 unsigned int get_hash_from_key(void *);
375 int hash_keys_are_equal(void *, void *);
377 int GetZipFileTreeType(char *);
378 char *ExtractZipFileIntoDirectory(char *, char *, int);
380 boolean AdjustGraphicsForEMC(void);
381 boolean AdjustSoundsForEMC(void);
383 void SetCurrentArtwork(int);
384 void ChangeCurrentArtworkIfNeeded(int);
386 void LoadLevelInfo(void);
387 void LoadArtworkInfo(void);
388 void LoadLevelArtworkInfo(void);
390 char *getArtworkIdentifierForUserLevelSet(int);
391 TreeInfo *getArtworkTreeInfoForUserLevelSet(int);
392 boolean checkIfCustomArtworkExistsForCurrentLevelSet(void);
393 void AddUserLevelSetToLevelInfo(char *);
394 void AddTreeSetToTreeInfo(TreeInfo *, char *, char *, int);
395 boolean UpdateUserLevelSet(char *, char *, char *, int);
396 boolean CreateUserLevelSet(char *, char *, char *, int, boolean);
398 void UpdateLastPlayedLevels_TreeInfo(void);
399 void StoreLastPlayedLevels(TreeInfo *);
400 void ForcedStoreLastPlayedLevels(TreeInfo *);
401 void RestoreLastPlayedLevels(TreeInfo **);
402 boolean CheckLastPlayedLevels(void);
404 void LoadLevelSetup_LastSeries(void);
405 void SaveLevelSetup_LastSeries(void);
406 void SaveLevelSetup_LastSeries_Deactivate(void);
407 void LoadLevelSetup_SeriesInfo(void);
408 void SaveLevelSetup_SeriesInfo(void);
410 int LevelStats_getPlayed(int);
411 int LevelStats_getSolved(int);
412 void LevelStats_setPlayed(int, int);
413 void LevelStats_setSolved(int, int);
414 void LevelStats_incPlayed(int);
415 void LevelStats_incSolved(int);
417 void LoadUserSetup(void);
418 void SaveUserSetup(void);