1 /***********************************************************
2 * Artsoft Retro-Game Library *
3 *----------------------------------------------------------*
4 * (c) 1994-2002 Artsoft Entertainment *
6 * Detmolder Strasse 189 *
9 * e-mail: info@artsoft.org *
10 *----------------------------------------------------------*
12 ***********************************************************/
21 /* values for setup file handling */
22 #define TYPE_BOOLEAN (1 << 0)
23 #define TYPE_SWITCH (1 << 1)
24 #define TYPE_YES_NO (1 << 2)
25 #define TYPE_KEY (1 << 3)
26 #define TYPE_KEY_X11 (1 << 4)
27 #define TYPE_INTEGER (1 << 5)
28 #define TYPE_STRING (1 << 6)
29 #define TYPE_TOKEN (1 << 7)
31 #define TYPE_BOOLEAN_STYLE (TYPE_BOOLEAN | \
35 /* additional values for setup screen */
36 #define TYPE_ENTER_MENU (1 << 8)
37 #define TYPE_LEAVE_MENU (1 << 9)
38 #define TYPE_EMPTY (1 << 10)
39 #define TYPE_KEYTEXT (1 << 11)
41 #define TYPE_GHOSTED (1 << 12)
42 #define TYPE_QUERY (1 << 13)
44 #define TYPE_VALUE (TYPE_BOOLEAN_STYLE | \
51 #define TYPE_SKIP_ENTRY (TYPE_EMPTY | \
55 #define TYPE_ENTER_OR_LEAVE_MENU (TYPE_ENTER_MENU | \
58 /* cookie token for file identifier and version number */
59 #define TOKEN_STR_FILE_IDENTIFIER "file_identifier"
68 /* some definitions for list and hash handling */
69 typedef struct SetupFileList SetupFileList;
70 typedef struct hashtable SetupFileHash;
72 #define BEGIN_HASH_ITERATION(hash, itr) \
73 if (hash != NULL && hashtable_count(hash) > 0) \
75 struct hashtable_itr *itr = hashtable_iterator(hash); \
78 #define HASH_ITERATION_TOKEN(itr) ((char *)hashtable_iterator_key(itr))
79 #define HASH_ITERATION_VALUE(itr) ((char *)hashtable_iterator_value(itr))
81 #define END_HASH_ITERATION(hash, itr) \
82 } while (hashtable_iterator_advance(itr)); \
87 /* sort priorities of level series (also used as level series classes) */
88 #define LEVELCLASS_TUTORIAL_START 10
89 #define LEVELCLASS_TUTORIAL_END 99
90 #define LEVELCLASS_CLASSICS_START 100
91 #define LEVELCLASS_CLASSICS_END 199
92 #define LEVELCLASS_CONTRIBUTION_START 200
93 #define LEVELCLASS_CONTRIBUTION_END 299
94 #define LEVELCLASS_USER_START 300
95 #define LEVELCLASS_USER_END 399
96 #define LEVELCLASS_BD_START 400
97 #define LEVELCLASS_BD_END 499
98 #define LEVELCLASS_EM_START 500
99 #define LEVELCLASS_EM_END 599
100 #define LEVELCLASS_SP_START 600
101 #define LEVELCLASS_SP_END 699
102 #define LEVELCLASS_DX_START 700
103 #define LEVELCLASS_DX_END 799
105 #define LEVELCLASS_TUTORIAL LEVELCLASS_TUTORIAL_START
106 #define LEVELCLASS_CLASSICS LEVELCLASS_CLASSICS_START
107 #define LEVELCLASS_CONTRIBUTION LEVELCLASS_CONTRIBUTION_START
108 #define LEVELCLASS_USER LEVELCLASS_USER_START
109 #define LEVELCLASS_BD LEVELCLASS_BD_START
110 #define LEVELCLASS_EM LEVELCLASS_EM_START
111 #define LEVELCLASS_SP LEVELCLASS_SP_START
112 #define LEVELCLASS_DX LEVELCLASS_DX_START
114 #define LEVELCLASS_UNDEFINED 999
116 #define IS_LEVELCLASS_TUTORIAL(p) \
117 ((p)->sort_priority >= LEVELCLASS_TUTORIAL_START && \
118 (p)->sort_priority <= LEVELCLASS_TUTORIAL_END)
119 #define IS_LEVELCLASS_CLASSICS(p) \
120 ((p)->sort_priority >= LEVELCLASS_CLASSICS_START && \
121 (p)->sort_priority <= LEVELCLASS_CLASSICS_END)
122 #define IS_LEVELCLASS_CONTRIBUTION(p) \
123 ((p)->sort_priority >= LEVELCLASS_CONTRIBUTION_START && \
124 (p)->sort_priority <= LEVELCLASS_CONTRIBUTION_END)
125 #define IS_LEVELCLASS_USER(p) \
126 ((p)->sort_priority >= LEVELCLASS_USER_START && \
127 (p)->sort_priority <= LEVELCLASS_USER_END)
128 #define IS_LEVELCLASS_BD(p) \
129 ((p)->sort_priority >= LEVELCLASS_BD_START && \
130 (p)->sort_priority <= LEVELCLASS_BD_END)
131 #define IS_LEVELCLASS_EM(p) \
132 ((p)->sort_priority >= LEVELCLASS_EM_START && \
133 (p)->sort_priority <= LEVELCLASS_EM_END)
134 #define IS_LEVELCLASS_SP(p) \
135 ((p)->sort_priority >= LEVELCLASS_SP_START && \
136 (p)->sort_priority <= LEVELCLASS_SP_END)
137 #define IS_LEVELCLASS_DX(p) \
138 ((p)->sort_priority >= LEVELCLASS_DX_START && \
139 (p)->sort_priority <= LEVELCLASS_DX_END)
141 #define LEVELCLASS(n) (IS_LEVELCLASS_TUTORIAL(n) ? LEVELCLASS_TUTORIAL : \
142 IS_LEVELCLASS_CLASSICS(n) ? LEVELCLASS_CLASSICS : \
143 IS_LEVELCLASS_CONTRIBUTION(n) ? LEVELCLASS_CONTRIBUTION : \
144 IS_LEVELCLASS_USER(n) ? LEVELCLASS_USER : \
145 IS_LEVELCLASS_BD(n) ? LEVELCLASS_BD : \
146 IS_LEVELCLASS_EM(n) ? LEVELCLASS_EM : \
147 IS_LEVELCLASS_SP(n) ? LEVELCLASS_SP : \
148 IS_LEVELCLASS_DX(n) ? LEVELCLASS_DX : \
149 LEVELCLASS_UNDEFINED)
151 /* sort priorities of artwork */
152 #define ARTWORKCLASS_CLASSICS_START 100
153 #define ARTWORKCLASS_CLASSICS_END 199
154 #define ARTWORKCLASS_CONTRIBUTION_START 200
155 #define ARTWORKCLASS_CONTRIBUTION_END 299
156 #define ARTWORKCLASS_LEVEL_START 300
157 #define ARTWORKCLASS_LEVEL_END 399
158 #define ARTWORKCLASS_USER_START 400
159 #define ARTWORKCLASS_USER_END 499
161 #define ARTWORKCLASS_CLASSICS ARTWORKCLASS_CLASSICS_START
162 #define ARTWORKCLASS_CONTRIBUTION ARTWORKCLASS_CONTRIBUTION_START
163 #define ARTWORKCLASS_LEVEL ARTWORKCLASS_LEVEL_START
164 #define ARTWORKCLASS_USER ARTWORKCLASS_USER_START
166 #define ARTWORKCLASS_UNDEFINED 999
168 #define IS_ARTWORKCLASS_CLASSICS(p) \
169 ((p)->sort_priority >= ARTWORKCLASS_CLASSICS_START && \
170 (p)->sort_priority <= ARTWORKCLASS_CLASSICS_END)
171 #define IS_ARTWORKCLASS_CONTRIBUTION(p) \
172 ((p)->sort_priority >= ARTWORKCLASS_CONTRIBUTION_START && \
173 (p)->sort_priority <= ARTWORKCLASS_CONTRIBUTION_END)
174 #define IS_ARTWORKCLASS_LEVEL(p) \
175 ((p)->sort_priority >= ARTWORKCLASS_LEVEL_START && \
176 (p)->sort_priority <= ARTWORKCLASS_LEVEL_END)
177 #define IS_ARTWORKCLASS_USER(p) \
178 ((p)->sort_priority >= ARTWORKCLASS_USER_START && \
179 (p)->sort_priority <= ARTWORKCLASS_USER_END)
181 #define ARTWORKCLASS(n) (IS_ARTWORKCLASS_CLASSICS(n) ? ARTWORKCLASS_CLASSICS :\
182 IS_ARTWORKCLASS_CONTRIBUTION(n) ? ARTWORKCLASS_CONTRIBUTION : \
183 IS_ARTWORKCLASS_LEVEL(n) ? ARTWORKCLASS_LEVEL : \
184 IS_ARTWORKCLASS_USER(n) ? ARTWORKCLASS_USER : \
185 ARTWORKCLASS_UNDEFINED)
188 char *setLevelArtworkDir(TreeInfo *);
189 char *getLevelFilename(int);
190 char *getTapeFilename(int);
191 char *getScoreFilename(int);
192 char *getSetupFilename(void);
193 char *getImageFilename(char *);
194 char *getCustomImageFilename(char *);
195 char *getCustomSoundFilename(char *);
196 char *getCustomArtworkFilename(char *, int);
197 char *getCustomArtworkConfigFilename(int);
198 char *getCustomArtworkLevelConfigFilename(int);
199 char *getCustomMusicDirectory(void);
201 void InitTapeDirectory(char *);
202 void InitScoreDirectory(char *);
203 void InitUserLevelDirectory(char *);
204 void InitLevelSetupDirectory(char *);
206 TreeInfo *newTreeInfo();
207 void pushTreeInfo(TreeInfo **, TreeInfo *);
208 int numTreeInfo(TreeInfo *);
209 boolean validLevelSeries(TreeInfo *);
210 TreeInfo *getFirstValidTreeInfoEntry(TreeInfo *);
211 TreeInfo *getTreeInfoFirstGroupEntry(TreeInfo *);
212 int numTreeInfoInGroup(TreeInfo *);
213 int posTreeInfo(TreeInfo *);
214 TreeInfo *getTreeInfoFromPos(TreeInfo *, int);
215 TreeInfo *getTreeInfoFromIdentifier(TreeInfo *, char *);
216 void dumpTreeInfo(TreeInfo *, int);
217 void sortTreeInfo(TreeInfo **,
218 int (*compare_function)(const void *, const void *));
220 char *getUserDataDir(void);
221 char *getCommonDataDir(void);
222 char *getSetupDir(void);
223 void createDirectory(char *, char *, int);
224 void InitUserDataDirectory(void);
225 void SetFilePermissions(char *, int);
227 char *getCookie(char *);
228 int getFileVersionFromCookieString(const char *);
229 boolean checkCookieString(const char *, const char *);
231 char *getFormattedSetupEntry(char *, char *);
233 struct SetupFileList *newSetupFileList(char *, char *);
234 void freeSetupFileList(struct SetupFileList *);
235 char *getListEntry(struct SetupFileList *, char *);
236 void setListEntry(struct SetupFileList *, char *, char *);
237 SetupFileList *loadSetupFileList(char *);
239 SetupFileHash *newSetupFileHash();
240 void freeSetupFileHash(SetupFileHash *);
241 char *getHashEntry(SetupFileHash *, char *);
242 void setHashEntry(SetupFileHash *, char *, char *);
243 SetupFileHash *loadSetupFileHash(char *);
244 void checkSetupFileHashIdentifier(SetupFileHash *, char *);
245 void setSetupInfo(struct TokenInfo *, int, char *);
246 char *getSetupValue(int, void *);
247 char *getSetupLine(struct TokenInfo *, char *, int);
249 void LoadLevelInfo(void);
250 void LoadArtworkInfo(void);
251 void LoadLevelArtworkInfo(void);
253 void LoadLevelSetup_LastSeries(void);
254 void SaveLevelSetup_LastSeries(void);
255 void LoadLevelSetup_SeriesInfo(void);
256 void SaveLevelSetup_SeriesInfo(void);