1 | |
|
|
2 | /* |
1 | /* |
3 | * static char *rcsid_image_c = |
|
|
4 | * "$Id: image.C,v 1.6 2006/09/10 16:00:23 root Exp $"; |
|
|
5 | */ |
|
|
6 | |
|
|
7 | /* |
|
|
8 | CrossFire, A Multiplayer game for X-windows |
2 | * CrossFire, A Multiplayer game for X-windows |
9 | |
3 | * |
|
|
4 | * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team |
10 | Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
5 | * Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
11 | Copyright (C) 1992 Frank Tore Johansen |
6 | * Copyright (C) 1992 Frank Tore Johansen |
12 | |
7 | * |
13 | 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 |
14 | 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 |
15 | the Free Software Foundation; either version 2 of the License, or |
10 | * the Free Software Foundation; either version 2 of the License, or |
16 | (at your option) any later version. |
11 | * (at your option) any later version. |
17 | |
12 | * |
18 | 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, |
19 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
21 | GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
22 | |
17 | * |
23 | 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 |
24 | along with this program; if not, write to the Free Software |
19 | * along with this program; if not, write to the Free Software |
25 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
26 | |
21 | * |
27 | The maintainer of this code can be reached at crossfire-devel@real-time.com |
22 | * The maintainer of this code can be reached at <crossfire@schmorp.de> |
28 | */ |
23 | */ |
29 | |
24 | |
30 | |
25 | |
31 | #include <global.h> |
26 | #include <global.h> |
32 | #include <stdio.h> |
27 | #include <stdio.h> |
33 | |
28 | |
… | |
… | |
117 | static int |
112 | static int |
118 | compar (const struct bmappair *a, const struct bmappair *b) |
113 | compar (const struct bmappair *a, const struct bmappair *b) |
119 | { |
114 | { |
120 | return strcmp (a->name, b->name); |
115 | return strcmp (a->name, b->name); |
121 | } |
116 | } |
|
|
117 | |
122 | static int |
118 | static int |
123 | compar_smooth (const struct smoothing *a, const struct smoothing *b) |
119 | compar_smooth (const struct smoothing *a, const struct smoothing *b) |
124 | { |
120 | { |
125 | if (a->id < b->id) |
121 | if (a->id < b->id) |
126 | return -1; |
122 | return -1; |
127 | if (b->id < a->id) |
123 | if (b->id < a->id) |
128 | return 1; |
124 | return 1; |
129 | return 0; |
125 | return 0; |
130 | } |
126 | } |
131 | |
127 | |
132 | |
|
|
133 | /* |
128 | /* |
134 | * Returns the matching color in the coloralias if found, |
129 | * Returns the matching color in the coloralias if found, |
135 | * 0 otherwise. Note that 0 will actually be black, so there is no |
130 | * 0 otherwise. Note that 0 will actually be black, so there is no |
136 | * way the calling function can tell if an error occurred or not |
131 | * way the calling function can tell if an error occurred or not |
137 | */ |
132 | */ |
138 | |
|
|
139 | static uint8 |
133 | static uint8 |
140 | find_color (const char *name) |
134 | find_color (const char *name) |
141 | { |
135 | { |
142 | uint8 i; |
136 | uint8 i; |
143 | |
137 | |
… | |
… | |
149 | } |
143 | } |
150 | |
144 | |
151 | /* This reads the lib/faces file, getting color and visibility information. |
145 | /* This reads the lib/faces file, getting color and visibility information. |
152 | * it is called by ReadBmapNames. |
146 | * it is called by ReadBmapNames. |
153 | */ |
147 | */ |
154 | |
|
|
155 | static void |
148 | static void |
156 | ReadFaceData (void) |
149 | ReadFaceData (void) |
157 | { |
150 | { |
158 | char buf[MAX_BUF], *cp; |
151 | char buf[MAX_BUF], *cp; |
159 | New_Face *on_face = NULL; |
152 | New_Face *on_face = NULL; |
160 | FILE *fp; |
153 | FILE *fp; |
161 | |
154 | |
162 | sprintf (buf, "%s/faces", settings.datadir); |
155 | sprintf (buf, "%s/faces", settings.datadir); |
163 | LOG (llevDebug, "Reading faces from %s...", buf); |
156 | LOG (llevDebug, "Reading faces from %s...\n", buf); |
164 | if ((fp = fopen (buf, "r")) == NULL) |
157 | if ((fp = fopen (buf, "r")) == NULL) |
165 | { |
158 | { |
166 | LOG (llevError, "Cannot open faces file %s: %s\n", buf, strerror (errno)); |
159 | LOG (llevError, "Cannot open faces file %s: %s\n", buf, strerror (errno)); |
167 | exit (-1); |
160 | exit (-1); |
168 | } |
161 | } |
… | |
… | |
222 | on_face->magicmap |= FACE_FLOOR; |
215 | on_face->magicmap |= FACE_FLOOR; |
223 | } |
216 | } |
224 | else |
217 | else |
225 | LOG (llevDebug, "Got unknown line in faces file: %s\n", buf); |
218 | LOG (llevDebug, "Got unknown line in faces file: %s\n", buf); |
226 | } |
219 | } |
|
|
220 | |
227 | LOG (llevDebug, "done\n"); |
221 | LOG (llevDebug, "done\n"); |
228 | fclose (fp); |
222 | fclose (fp); |
229 | } |
223 | } |
230 | |
224 | |
231 | /* This reads the bmaps file to get all the bitmap names and |
225 | /* This reads the bmaps file to get all the bitmap names and |
232 | * stuff. It only needs to be done once, because it is player |
226 | * stuff. It only needs to be done once, because it is player |
233 | * independent (ie, what display the person is on will not make a |
227 | * independent (ie, what display the person is on will not make a |
234 | * difference.) |
228 | * difference.) |
235 | */ |
229 | */ |
236 | |
|
|
237 | void |
230 | void |
238 | ReadBmapNames (void) |
231 | ReadBmapNames (void) |
239 | { |
232 | { |
240 | char buf[MAX_BUF], *p, *q; |
233 | char buf[MAX_BUF], *p, *q; |
241 | FILE *fp; |
234 | FILE *fp; |
242 | int value, nrofbmaps = 0, i; |
235 | int value, nrofbmaps = 0, i; |
243 | size_t l; |
236 | size_t l; |
244 | |
237 | |
245 | bmaps_checksum = 0; |
238 | bmaps_checksum = 0; |
246 | sprintf (buf, "%s/bmaps", settings.datadir); |
239 | sprintf (buf, "%s/bmaps", settings.datadir); |
247 | LOG (llevDebug, "Reading bmaps from %s...", buf); |
240 | LOG (llevDebug, "Reading bmaps from %s...\n", buf); |
248 | if ((fp = fopen (buf, "r")) == NULL) |
241 | if ((fp = fopen (buf, "r")) == NULL) |
249 | { |
242 | { |
250 | LOG (llevError, "Cannot open bmaps file %s: %s\n", buf, strerror (errno)); |
243 | LOG (llevError, "Cannot open bmaps file %s: %s\n", buf, strerror (errno)); |
251 | exit (-1); |
244 | exit (-1); |
252 | } |
245 | } |
… | |
… | |
270 | { |
263 | { |
271 | LOG (llevDebug, "Warning, syntax error: %s\n", buf); |
264 | LOG (llevDebug, "Warning, syntax error: %s\n", buf); |
272 | continue; |
265 | continue; |
273 | } |
266 | } |
274 | value = atoi (p); |
267 | value = atoi (p); |
275 | xbm[nroffiles].name = strdup_local (q); |
268 | xbm[nroffiles].name = strdup (q); |
276 | |
269 | |
277 | /* We need to calculate the checksum of the bmaps file |
270 | /* We need to calculate the checksum of the bmaps file |
278 | * name->number mapping to send to the client. This does not |
271 | * name->number mapping to send to the client. This does not |
279 | * need to match what sum or other utility may come up with - |
272 | * need to match what sum or other utility may come up with - |
280 | * as long as we get the same results on the same real file |
273 | * as long as we get the same results on the same real file |
… | |
… | |
393 | FILE *fp; |
386 | FILE *fp; |
394 | int smoothcount = 0; |
387 | int smoothcount = 0; |
395 | |
388 | |
396 | bmaps_checksum = 0; |
389 | bmaps_checksum = 0; |
397 | sprintf (buf, "%s/smooth", settings.datadir); |
390 | sprintf (buf, "%s/smooth", settings.datadir); |
398 | LOG (llevDebug, "Reading smooth from %s...", buf); |
391 | LOG (llevDebug, "Reading smooth from %s...\n", buf); |
399 | if ((fp = fopen (buf, "r")) == NULL) |
392 | if ((fp = fopen (buf, "r")) == NULL) |
400 | { |
393 | { |
401 | LOG (llevError, "Cannot open smooth file %s: %s\n", strerror (errno)); |
394 | LOG (llevError, "Cannot open smooth file %s: %s\n", strerror (errno)); |
402 | exit (-1); |
395 | exit (-1); |
403 | } |
396 | } |