1 | /* |
1 | /* |
2 | CrossFire, A Multiplayer game for X-windows |
2 | * CrossFire, A Multiplayer game |
3 | |
3 | * |
|
|
4 | * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team |
4 | Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
5 | * Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
5 | Copyright (C) 1992 Frank Tore Johansen |
6 | * Copyright (C) 1992 Frank Tore Johansen |
6 | |
7 | * |
7 | This program is free software; you can redistribute it and/or modify |
8 | * This program is free software; you can redistribute it and/or modify |
8 | it under the terms of the GNU General Public License as published by |
9 | * it under the terms of the GNU General Public License as published by |
9 | the Free Software Foundation; either version 2 of the License, or |
10 | * the Free Software Foundation; either version 2 of the License, or |
10 | (at your option) any later version. |
11 | * (at your option) any later version. |
11 | |
12 | * |
12 | This program is distributed in the hope that it will be useful, |
13 | * This program is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
16 | |
17 | * |
17 | You should have received a copy of the GNU General Public License |
18 | * You should have received a copy of the GNU General Public License |
18 | along with this program; if not, write to the Free Software |
19 | * along with this program; if not, write to the Free Software |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | |
21 | * |
21 | The maintainer of this code can be reached at <crossfire@schmorp.de> |
22 | * The maintainer of this code can be reached at <crossfire@schmorp.de> |
22 | */ |
23 | */ |
23 | |
24 | |
24 | |
25 | |
25 | #include <global.h> |
26 | #include <global.h> |
26 | #include <stdio.h> |
27 | #include <stdio.h> |
27 | |
28 | |
28 | New_Face *new_faces; |
29 | facetile *new_faces; |
29 | |
30 | |
30 | /* bmappair and xbm are used when looking for the image id numbers |
31 | /* bmappair and xbm are used when looking for the image id numbers |
31 | * of a face by name. xbm is sorted alphabetically so that bsearch |
32 | * of a face by name. xbm is sorted alphabetically so that bsearch |
32 | * can be used to quickly find the entry for a name. the number is |
33 | * can be used to quickly find the entry for a name. the number is |
33 | * then an index into the new_faces array. |
34 | * then an index into the new_faces array. |
… | |
… | |
43 | { |
44 | { |
44 | char *name; |
45 | char *name; |
45 | unsigned int number; |
46 | unsigned int number; |
46 | }; |
47 | }; |
47 | |
48 | |
48 | void free (bmappair *); // guard to catch free when delete should be used |
|
|
49 | |
|
|
50 | static struct bmappair *xbm = NULL; |
49 | static struct bmappair *xbm = NULL; |
51 | |
50 | |
52 | /* Following can just as easily be pointers, but |
|
|
53 | * it is easier to keep them like this. |
|
|
54 | */ |
|
|
55 | New_Face *blank_face, *dark_faces[3], *empty_face, *smooth_face; |
51 | facetile *blank_face, *dark_faces[3], *empty_face, *smooth_face; |
56 | |
|
|
57 | |
52 | |
58 | /* nroffiles is the actual number of bitmaps defined. |
53 | /* nroffiles is the actual number of bitmaps defined. |
59 | * nrofpixmaps is the number of bitmaps loaded. With |
54 | * nrofpixmaps is the number of bitmaps loaded. With |
60 | * the automatic generation of the bmaps file, this is now equal |
55 | * the automatic generation of the bmaps file, this is now equal |
61 | * to nroffiles. |
56 | * to nroffiles. |
… | |
… | |
69 | int nrofpixmaps = 0; |
64 | int nrofpixmaps = 0; |
70 | |
65 | |
71 | /** |
66 | /** |
72 | * id is the face to smooth, smooth is the 16x2 face used to smooth id. |
67 | * id is the face to smooth, smooth is the 16x2 face used to smooth id. |
73 | */ |
68 | */ |
74 | struct smoothing:zero_initialised |
69 | struct smoothing : zero_initialised |
75 | { |
70 | { |
76 | uint16 id; |
71 | uint16 id; |
77 | uint16 smooth; |
72 | uint16 smooth; |
78 | }; |
73 | }; |
79 | |
|
|
80 | void free (smoothing *); // guard to catch free when delete should be used |
|
|
81 | |
74 | |
82 | /** |
75 | /** |
83 | * Contains all defined smoothing entries. smooth is an array of nrofsmooth |
76 | * Contains all defined smoothing entries. smooth is an array of nrofsmooth |
84 | * entries. It is sorted by smooth[].id. |
77 | * entries. It is sorted by smooth[].id. |
85 | */ |
78 | */ |
… | |
… | |
111 | static int |
104 | static int |
112 | compar (const struct bmappair *a, const struct bmappair *b) |
105 | compar (const struct bmappair *a, const struct bmappair *b) |
113 | { |
106 | { |
114 | return strcmp (a->name, b->name); |
107 | return strcmp (a->name, b->name); |
115 | } |
108 | } |
|
|
109 | |
116 | static int |
110 | static int |
117 | compar_smooth (const struct smoothing *a, const struct smoothing *b) |
111 | compar_smooth (const struct smoothing *a, const struct smoothing *b) |
118 | { |
112 | { |
119 | if (a->id < b->id) |
113 | if (a->id < b->id) |
120 | return -1; |
114 | return -1; |
121 | if (b->id < a->id) |
115 | if (b->id < a->id) |
122 | return 1; |
116 | return 1; |
123 | return 0; |
117 | return 0; |
124 | } |
118 | } |
125 | |
119 | |
126 | |
|
|
127 | /* |
120 | /* |
128 | * Returns the matching color in the coloralias if found, |
121 | * Returns the matching color in the coloralias if found, |
129 | * 0 otherwise. Note that 0 will actually be black, so there is no |
122 | * 0 otherwise. Note that 0 will actually be black, so there is no |
130 | * way the calling function can tell if an error occurred or not |
123 | * way the calling function can tell if an error occurred or not |
131 | */ |
124 | */ |
132 | |
|
|
133 | static uint8 |
125 | static uint8 |
134 | find_color (const char *name) |
126 | find_color (const char *name) |
135 | { |
127 | { |
136 | uint8 i; |
128 | uint8 i; |
137 | |
129 | |
… | |
… | |
143 | } |
135 | } |
144 | |
136 | |
145 | /* This reads the lib/faces file, getting color and visibility information. |
137 | /* This reads the lib/faces file, getting color and visibility information. |
146 | * it is called by ReadBmapNames. |
138 | * it is called by ReadBmapNames. |
147 | */ |
139 | */ |
148 | |
|
|
149 | static void |
140 | static void |
150 | ReadFaceData (void) |
141 | ReadFaceData (void) |
151 | { |
142 | { |
152 | char buf[MAX_BUF], *cp; |
143 | char buf[MAX_BUF], *cp; |
153 | New_Face *on_face = NULL; |
144 | facetile *on_face = NULL; |
154 | FILE *fp; |
145 | FILE *fp; |
155 | |
146 | |
156 | sprintf (buf, "%s/faces", settings.datadir); |
147 | sprintf (buf, "%s/faces", settings.datadir); |
157 | LOG (llevDebug, "Reading faces from %s...\n", buf); |
148 | LOG (llevDebug, "Reading faces from %s...\n", buf); |
158 | if ((fp = fopen (buf, "r")) == NULL) |
149 | if ((fp = fopen (buf, "r")) == NULL) |
… | |
… | |
216 | on_face->magicmap |= FACE_FLOOR; |
207 | on_face->magicmap |= FACE_FLOOR; |
217 | } |
208 | } |
218 | else |
209 | else |
219 | LOG (llevDebug, "Got unknown line in faces file: %s\n", buf); |
210 | LOG (llevDebug, "Got unknown line in faces file: %s\n", buf); |
220 | } |
211 | } |
|
|
212 | |
221 | LOG (llevDebug, "done\n"); |
213 | LOG (llevDebug, "done\n"); |
222 | fclose (fp); |
214 | fclose (fp); |
223 | } |
215 | } |
224 | |
216 | |
225 | /* This reads the bmaps file to get all the bitmap names and |
217 | /* This reads the bmaps file to get all the bitmap names and |
226 | * stuff. It only needs to be done once, because it is player |
218 | * stuff. It only needs to be done once, because it is player |
227 | * independent (ie, what display the person is on will not make a |
219 | * independent (ie, what display the person is on will not make a |
228 | * difference.) |
220 | * difference.) |
229 | */ |
221 | */ |
230 | |
|
|
231 | void |
222 | void |
232 | ReadBmapNames (void) |
223 | ReadBmapNames (void) |
233 | { |
224 | { |
234 | char buf[MAX_BUF], *p, *q; |
225 | char buf[MAX_BUF], *p, *q; |
235 | FILE *fp; |
226 | FILE *fp; |
… | |
… | |
296 | } |
287 | } |
297 | fclose (fp); |
288 | fclose (fp); |
298 | |
289 | |
299 | LOG (llevDebug, "done (got %d/%d/%d)\n", nrofpixmaps, nrofbmaps, nroffiles); |
290 | LOG (llevDebug, "done (got %d/%d/%d)\n", nrofpixmaps, nrofbmaps, nroffiles); |
300 | |
291 | |
301 | new_faces = new New_Face[nrofpixmaps]; |
292 | new_faces = new facetile[nrofpixmaps]; |
302 | |
293 | |
303 | for (i = 0; i < nrofpixmaps; i++) |
294 | for (i = 0; i < nrofpixmaps; i++) |
304 | { |
295 | { |
305 | new_faces[i].name = ""; |
296 | new_faces[i].name = ""; |
306 | new_faces[i].number = i; |
297 | new_faces[i].number = i; |
307 | new_faces[i].visibility = 0; |
298 | new_faces[i].visibility = 0; |
308 | new_faces[i].magicmap = 255; |
299 | new_faces[i].magicmap = 255; |
309 | } |
300 | } |
|
|
301 | |
310 | for (i = 0; i < nroffiles; i++) |
302 | for (i = 0; i < nroffiles; i++) |
311 | { |
|
|
312 | new_faces[xbm[i].number].name = xbm[i].name; |
303 | new_faces[xbm[i].number].name = xbm[i].name; |
313 | } |
|
|
314 | |
304 | |
315 | // non-pod datatype, likely not allowed |
305 | // non-pod datatype, likely not allowed |
316 | qsort (xbm, nroffiles, sizeof (struct bmappair), (int (*)(const void *, const void *)) compar); |
306 | qsort (xbm, nroffiles, sizeof (struct bmappair), (int (*)(const void *, const void *)) compar); |
317 | |
307 | |
318 | ReadFaceData (); |
308 | ReadFaceData (); |