1 // ============================================================================
2 // Artsoft Retro-Game Library
3 // ----------------------------------------------------------------------------
4 // (c) 1995-2014 by Artsoft Entertainment
7 // http://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_ELEMENT (1 << 10)
31 #define TYPE_GRAPHIC (1 << 11)
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)
43 #define TYPE_GHOSTED (1 << 20)
44 #define TYPE_QUERY (1 << 21)
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)
52 /* derived values for setup file handling */
53 #define TYPE_BOOLEAN_STYLE (TYPE_BOOLEAN | \
58 /* derived values for setup screen */
59 #define TYPE_VALUE (TYPE_BOOLEAN_STYLE | \
69 #define TYPE_SKIP_ENTRY (TYPE_EMPTY | \
74 #define TYPE_ENTER (TYPE_ENTER_SCREEN | \
78 #define TYPE_LEAVE (TYPE_LEAVE_SCREEN | \
82 #define TYPE_ENTER_OR_LEAVE (TYPE_ENTER | TYPE_LEAVE)
84 /* cookie token for file identifier and version number */
85 #define TOKEN_STR_FILE_IDENTIFIER "file_identifier"
94 /* some definitions for list and hash handling */
95 typedef struct SetupFileList SetupFileList;
96 typedef struct hashtable SetupFileHash;
98 #define BEGIN_HASH_ITERATION(hash, itr) \
99 if (hash != NULL && hashtable_count(hash) > 0) \
101 struct hashtable_itr *itr = hashtable_iterator(hash); \
104 #define HASH_ITERATION_TOKEN(itr) ((char *)hashtable_iterator_key(itr))
105 #define HASH_ITERATION_VALUE(itr) ((char *)hashtable_iterator_value(itr))
107 #define END_HASH_ITERATION(hash, itr) \
108 } while (hashtable_iterator_advance(itr)); \
113 /* sort priorities of level series (also used as level series classes) */
114 #define LEVELCLASS_TUTORIAL_START 10
115 #define LEVELCLASS_TUTORIAL_END 99
116 #define LEVELCLASS_CLASSICS_START 100
117 #define LEVELCLASS_CLASSICS_END 199
118 #define LEVELCLASS_CONTRIB_START 200
119 #define LEVELCLASS_CONTRIB_END 299
120 #define LEVELCLASS_PRIVATE_START 300
121 #define LEVELCLASS_PRIVATE_END 399
122 #define LEVELCLASS_BD_START 400
123 #define LEVELCLASS_BD_END 499
124 #define LEVELCLASS_EM_START 500
125 #define LEVELCLASS_EM_END 599
126 #define LEVELCLASS_SP_START 600
127 #define LEVELCLASS_SP_END 699
128 #define LEVELCLASS_DX_START 700
129 #define LEVELCLASS_DX_END 799
130 #define LEVELCLASS_SB_START 800
131 #define LEVELCLASS_SB_END 899
133 #define LEVELCLASS_PREDEFINED_START LEVELCLASS_TUTORIAL_START
134 #define LEVELCLASS_PREDEFINED_END LEVELCLASS_SB_END
136 #define LEVELCLASS_TUTORIAL LEVELCLASS_TUTORIAL_START
137 #define LEVELCLASS_CLASSICS LEVELCLASS_CLASSICS_START
138 #define LEVELCLASS_CONTRIB LEVELCLASS_CONTRIB_START
139 #define LEVELCLASS_PRIVATE LEVELCLASS_PRIVATE_START
140 #define LEVELCLASS_BD LEVELCLASS_BD_START
141 #define LEVELCLASS_EM LEVELCLASS_EM_START
142 #define LEVELCLASS_SP LEVELCLASS_SP_START
143 #define LEVELCLASS_DX LEVELCLASS_DX_START
144 #define LEVELCLASS_SB LEVELCLASS_SB_START
146 #define LEVELCLASS_UNDEFINED 999
148 #define IS_LEVELCLASS_TUTORIAL(p) \
149 ((p)->sort_priority >= LEVELCLASS_TUTORIAL_START && \
150 (p)->sort_priority <= LEVELCLASS_TUTORIAL_END)
151 #define IS_LEVELCLASS_CLASSICS(p) \
152 ((p)->sort_priority >= LEVELCLASS_CLASSICS_START && \
153 (p)->sort_priority <= LEVELCLASS_CLASSICS_END)
154 #define IS_LEVELCLASS_CONTRIB(p) \
155 ((p)->sort_priority >= LEVELCLASS_CONTRIB_START && \
156 (p)->sort_priority <= LEVELCLASS_CONTRIB_END)
157 #define IS_LEVELCLASS_PRIVATE(p) \
158 ((p)->sort_priority >= LEVELCLASS_PRIVATE_START && \
159 (p)->sort_priority <= LEVELCLASS_PRIVATE_END)
160 #define IS_LEVELCLASS_BD(p) \
161 ((p)->sort_priority >= LEVELCLASS_BD_START && \
162 (p)->sort_priority <= LEVELCLASS_BD_END)
163 #define IS_LEVELCLASS_EM(p) \
164 ((p)->sort_priority >= LEVELCLASS_EM_START && \
165 (p)->sort_priority <= LEVELCLASS_EM_END)
166 #define IS_LEVELCLASS_SP(p) \
167 ((p)->sort_priority >= LEVELCLASS_SP_START && \
168 (p)->sort_priority <= LEVELCLASS_SP_END)
169 #define IS_LEVELCLASS_DX(p) \
170 ((p)->sort_priority >= LEVELCLASS_DX_START && \
171 (p)->sort_priority <= LEVELCLASS_DX_END)
172 #define IS_LEVELCLASS_SB(p) \
173 ((p)->sort_priority >= LEVELCLASS_SB_START && \
174 (p)->sort_priority <= LEVELCLASS_SB_END)
175 #define IS_LEVELCLASS_UNDEFINED(p) \
176 ((p)->sort_priority < LEVELCLASS_PREDEFINED_START || \
177 (p)->sort_priority > LEVELCLASS_PREDEFINED_END)
179 #define LEVELCLASS(n) (IS_LEVELCLASS_TUTORIAL(n) ? LEVELCLASS_TUTORIAL : \
180 IS_LEVELCLASS_CLASSICS(n) ? LEVELCLASS_CLASSICS : \
181 IS_LEVELCLASS_CONTRIB(n) ? LEVELCLASS_CONTRIB : \
182 IS_LEVELCLASS_PRIVATE(n) ? LEVELCLASS_PRIVATE : \
183 IS_LEVELCLASS_BD(n) ? LEVELCLASS_BD : \
184 IS_LEVELCLASS_EM(n) ? LEVELCLASS_EM : \
185 IS_LEVELCLASS_SP(n) ? LEVELCLASS_SP : \
186 IS_LEVELCLASS_DX(n) ? LEVELCLASS_DX : \
187 IS_LEVELCLASS_SB(n) ? LEVELCLASS_SB : \
188 LEVELCLASS_UNDEFINED)
190 /* sort priorities of artwork */
191 #define ARTWORKCLASS_CLASSICS_START 100
192 #define ARTWORKCLASS_CLASSICS_END 199
193 #define ARTWORKCLASS_CONTRIB_START 200
194 #define ARTWORKCLASS_CONTRIB_END 299
195 #define ARTWORKCLASS_PRIVATE_START 300
196 #define ARTWORKCLASS_PRIVATE_END 399
197 #define ARTWORKCLASS_LEVEL_START 400
198 #define ARTWORKCLASS_LEVEL_END 499
200 #define ARTWORKCLASS_CLASSICS ARTWORKCLASS_CLASSICS_START
201 #define ARTWORKCLASS_CONTRIB ARTWORKCLASS_CONTRIB_START
202 #define ARTWORKCLASS_PRIVATE ARTWORKCLASS_PRIVATE_START
203 #define ARTWORKCLASS_LEVEL ARTWORKCLASS_LEVEL_START
205 #define ARTWORKCLASS_UNDEFINED 999
207 #define IS_ARTWORKCLASS_CLASSICS(p) \
208 ((p)->sort_priority >= ARTWORKCLASS_CLASSICS_START && \
209 (p)->sort_priority <= ARTWORKCLASS_CLASSICS_END)
210 #define IS_ARTWORKCLASS_CONTRIB(p) \
211 ((p)->sort_priority >= ARTWORKCLASS_CONTRIB_START && \
212 (p)->sort_priority <= ARTWORKCLASS_CONTRIB_END)
213 #define IS_ARTWORKCLASS_PRIVATE(p) \
214 ((p)->sort_priority >= ARTWORKCLASS_PRIVATE_START && \
215 (p)->sort_priority <= ARTWORKCLASS_PRIVATE_END)
216 #define IS_ARTWORKCLASS_LEVEL(p) \
217 ((p)->sort_priority >= ARTWORKCLASS_LEVEL_START && \
218 (p)->sort_priority <= ARTWORKCLASS_LEVEL_END)
220 #define ARTWORKCLASS(n) (IS_ARTWORKCLASS_CLASSICS(n) ? ARTWORKCLASS_CLASSICS :\
221 IS_ARTWORKCLASS_CONTRIB(n) ? ARTWORKCLASS_CONTRIB : \
222 IS_ARTWORKCLASS_PRIVATE(n) ? ARTWORKCLASS_PRIVATE : \
223 IS_ARTWORKCLASS_LEVEL(n) ? ARTWORKCLASS_LEVEL : \
224 ARTWORKCLASS_UNDEFINED)
227 char *setLevelArtworkDir(TreeInfo *);
228 char *getTapeFilename(int);
229 char *getSolutionTapeFilename(int);
230 char *getScoreFilename(int);
231 char *getSetupFilename(void);
232 char *getEditorSetupFilename(void);
233 char *getHelpAnimFilename(void);
234 char *getHelpTextFilename(void);
235 char *getLevelSetInfoFilename(void);
236 char *getLevelSetTitleMessageFilename(int, boolean);
237 char *getImageFilename(char *);
238 char *getCustomImageFilename(char *);
239 char *getCustomSoundFilename(char *);
240 char *getCustomMusicFilename(char *);
241 char *getCustomArtworkFilename(char *, int);
242 char *getCustomArtworkConfigFilename(int);
243 char *getCustomArtworkLevelConfigFilename(int);
244 char *getCustomMusicDirectory(void);
246 void InitTapeDirectory(char *);
247 void InitScoreDirectory(char *);
248 void InitUserLevelDirectory(char *);
249 void InitLevelSetupDirectory(char *);
251 TreeInfo *newTreeInfo();
252 TreeInfo *newTreeInfo_setDefaults(int);
253 void pushTreeInfo(TreeInfo **, TreeInfo *);
254 int numTreeInfo(TreeInfo *);
255 boolean validLevelSeries(TreeInfo *);
256 TreeInfo *getFirstValidTreeInfoEntry(TreeInfo *);
257 TreeInfo *getTreeInfoFirstGroupEntry(TreeInfo *);
258 int numTreeInfoInGroup(TreeInfo *);
259 int posTreeInfo(TreeInfo *);
260 TreeInfo *getTreeInfoFromPos(TreeInfo *, int);
261 TreeInfo *getTreeInfoFromIdentifier(TreeInfo *, char *);
262 void dumpTreeInfo(TreeInfo *, int);
263 void sortTreeInfoBySortFunction(TreeInfo **,
264 int (*compare_function)(const void *,
266 void sortTreeInfo(TreeInfo **);
267 void freeTreeInfo(TreeInfo *);
269 char *getHomeDir(void);
270 char *getCommonDataDir(void);
271 char *getPersonalDataDir(void);
272 char *getUserGameDataDir(void);
273 char *getSetupDir(void);
274 char *getCurrentLevelDir(void);
276 void updateUserGameDataDir(void);
278 void createDirectory(char *, char *, int);
279 void InitUserDataDirectory(void);
280 void SetFilePermissions(char *, int);
282 char *getCookie(char *);
283 int getFileVersionFromCookieString(const char *);
284 boolean checkCookieString(const char *, const char *);
286 char *getFormattedSetupEntry(char *, char *);
288 boolean getTokenValueFromSetupLine(char *, char **, char **);
290 SetupFileList *newSetupFileList(char *, char *);
291 void freeSetupFileList(SetupFileList *);
292 char *getListEntry(SetupFileList *, char *);
293 SetupFileList *setListEntry(SetupFileList *, char *, char *);
294 SetupFileList *addListEntry(SetupFileList *, char *, char *);
295 SetupFileList *loadSetupFileList(char *);
297 SetupFileHash *newSetupFileHash();
298 void freeSetupFileHash(SetupFileHash *);
299 char *getHashEntry(SetupFileHash *, char *);
300 void setHashEntry(SetupFileHash *, char *, char *);
301 char *removeHashEntry(SetupFileHash *, char *);
302 SetupFileHash *loadSetupFileHash(char *);
303 void checkSetupFileHashIdentifier(SetupFileHash *, char *, char *);
304 void setSetupInfo(struct TokenInfo *, int, char *);
305 char *getSetupValue(int, void *);
306 char *getSetupLine(struct TokenInfo *, char *, int);
308 unsigned int get_hash_from_key(void *);
310 boolean AdjustGraphicsForEMC();
312 void LoadLevelInfo(void);
313 void LoadArtworkInfo(void);
314 void LoadLevelArtworkInfo(void);
316 void LoadLevelSetup_LastSeries(void);
317 void SaveLevelSetup_LastSeries(void);
318 void SaveLevelSetup_LastSeries_Deactivate();
319 void LoadLevelSetup_SeriesInfo(void);
320 void SaveLevelSetup_SeriesInfo(void);
322 int LevelStats_getPlayed(int);
323 int LevelStats_getSolved(int);
324 void LevelStats_setPlayed(int, int);
325 void LevelStats_setSolved(int, int);
326 void LevelStats_incPlayed(int);
327 void LevelStats_incSolved(int);