1 /* ---------------------------------------------------------------------- *
2 * readpng.c
3 * This file is part of lincity (see COPYRIGHT for copyright information).
4 * ---------------------------------------------------------------------- */
5 #include <stdlib.h>
6 #include "png.h"
7 #include "malloc.h"
8 #include "lin-city.h"
9 #include "lctypes.h"
10 #include "lintypes.h"
11
12 /* Read a PNG file. You may want to return an error code if the read
13 * fails (depending upon the failure). There are two "prototypes" given
14 * here - one where we are given the filename, and we need to open the
15 * file, and the other where we are given an open file (possibly with
16 * some or all of the magic bytes read - see comments above).
17 */
18 #define ERROR -1
19 #define OK 0
20
21 /* Private functions */
22 static char*
23 load_png_graphic (short type, short group, char* id,
24 FILE* txt_fp,png_bytep *row_pointers,
25 png_uint_32 width, png_uint_32 height);
26
27 /* Let errors and warnings be handled by setjmp/longjmp */
28 void* user_error_ptr = 0;
29
user_error_fn(png_structp png_ptr,png_const_charp error_msg)30 void user_error_fn(png_structp png_ptr, png_const_charp error_msg)
31 {
32 }
33
user_warning_fn(png_structp png_ptr,png_const_charp warning_msg)34 void user_warning_fn(png_structp png_ptr, png_const_charp warning_msg)
35 {
36 }
37
38 int
load_png_graphics(char * txt_filename,char * png_filename)39 load_png_graphics (char *txt_filename, char *png_filename)
40 {
41 png_uint_32 row;
42 png_structp png_ptr;
43 png_infop info_ptr;
44 unsigned int sig_read = 0;
45 png_uint_32 width, height;
46 int bit_depth, color_type, interlace_type;
47 FILE *fp, *txt_fp;
48 png_bytep *row_pointers;
49
50 if ((fp = fopen(png_filename, "rb")) == NULL)
51 return (ERROR);
52
53 if ((txt_fp = fopen(txt_filename, "r")) == NULL)
54 return (ERROR);
55
56 /* Create and initialize the png_struct with the desired error handler
57 * functions. If you want to use the default stderr and longjump method,
58 * you can supply NULL for the last three parameters. We also supply the
59 * the compiler header file version, so that we know if the application
60 * was compiled with a compatible version of the library. REQUIRED
61 */
62 png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING,
63 (png_voidp) user_error_ptr, user_error_fn, user_warning_fn);
64
65 if (png_ptr == NULL) {
66 fclose(fp);
67 return (ERROR);
68 }
69
70 /* Allocate/initialize the memory for image information. REQUIRED. */
71 info_ptr = png_create_info_struct(png_ptr);
72 if (info_ptr == NULL) {
73 fclose(fp);
74 #if defined (commentout)
75 png_destroy_read_struct(&png_ptr, png_infopp_NULL, png_infopp_NULL);
76 #endif
77 png_destroy_read_struct(&png_ptr, NULL, NULL);
78 return (ERROR);
79 }
80
81 /* Set error handling if you are using the setjmp/longjmp method (this is
82 * the normal method of doing things with libpng). REQUIRED unless you
83 * set up your own error handlers in the png_create_read_struct() earlier.
84 */
85 if (setjmp(png_jmpbuf(png_ptr))) {
86 /* Free all of the memory associated with the png_ptr and info_ptr */
87 #if defined (commentout)
88 png_destroy_read_struct(&png_ptr, &info_ptr, png_infopp_NULL);
89 #endif
90 png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
91 fclose(fp);
92 /* If we get here, we had a problem reading the file */
93 return (ERROR);
94 }
95
96 /* Set up the input control if you are using standard C streams */
97 png_init_io(png_ptr, fp);
98
99 /* If we have already read some of the signature */
100 png_set_sig_bytes(png_ptr, sig_read);
101
102 /* OK, you're doing it the hard way, with the lower-level functions */
103 /* The call to png_read_info() gives us all of the information from the
104 * PNG file before the first IDAT (image data chunk). REQUIRED
105 */
106 png_read_info(png_ptr, info_ptr);
107
108 #if defined (commentout)
109 png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type,
110 &interlace_type, int_p_NULL, int_p_NULL);
111 #endif
112 png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type,
113 &interlace_type, NULL, NULL);
114
115 printf ("PNG Header: %d x %d, bd=%d, ct=%d\n", (int)height, (int)width,
116 bit_depth, color_type);
117
118 /* Set up the data transformations you want. Note that these are all
119 * optional. Only call them if you want/need them. Many of the
120 * transformations only work on specific types of images, and many
121 * are mutually exclusive.
122 */
123
124 /* tell libpng to strip 16 bit/color files down to 8 bits/color */
125 // png_set_strip_16(png_ptr);
126
127 /* Strip alpha bytes from the input data without combining with the
128 * background (not recommended).
129 */
130 // png_set_strip_alpha(png_ptr);
131
132 /* Extract multiple pixels with bit depths of 1, 2, and 4 from a single
133 * byte into separate bytes (useful for paletted and grayscale images).
134 */
135 // png_set_packing(png_ptr);
136
137 /* Change the order of packed pixels to least significant bit first
138 * (not useful if you are using png_set_packing). */
139 // png_set_packswap(png_ptr);
140
141 /* Require color fmt w/ palette */
142 if (color_type != PNG_COLOR_TYPE_PALETTE) {
143 printf ("Error - png image wasn't PNG_COLOR_TYPE_PALETTE\n");
144 /* Free all of the memory associated with the png_ptr and info_ptr */
145 #if defined (commentout)
146 png_destroy_read_struct(&png_ptr, &info_ptr, png_infopp_NULL);
147 #endif
148 png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
149 fclose(fp);
150 /* If we get here, we had a problem reading the file */
151 return (ERROR);
152 }
153
154 /* Require 1 byte per pixel */
155 if (bit_depth != 8) {
156 printf ("Error - png image wasn't bit_depth = 8\n");
157 /* Free all of the memory associated with the png_ptr and info_ptr */
158 #if defined (commentout)
159 png_destroy_read_struct(&png_ptr, &info_ptr, png_infopp_NULL);
160 #endif
161 png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
162 fclose(fp);
163 /* If we get here, we had a problem reading the file */
164 return (ERROR);
165 }
166
167 /* The easiest way to read the image: */
168 row_pointers = malloc (sizeof(void*)*height);
169 for (row = 0; row < height; row++) {
170 row_pointers[row] = png_malloc(png_ptr,
171 png_get_rowbytes(png_ptr, info_ptr));
172 }
173
174 png_read_image(png_ptr, row_pointers);
175
176 #if defined (commentout)
177 for (col = 0; col < 16; col++) {
178 printf (" %02x ",row_pointers[0][col]);
179 }
180 printf ("\n");
181
182 for (col = 0; col < 16; col++) {
183 printf ("%3d ",row_pointers[0][col]);
184 }
185 printf ("\n");
186 #endif
187
188 /* read rest of file, and get additional chunks in info_ptr - REQUIRED */
189 png_read_end(png_ptr, info_ptr);
190
191 /* close the png file */
192 fclose(fp);
193
194 /* get the icons out of the png */
195 #ifdef LG
196 #undef LG
197 #endif
198 #define LG(typ,grp,id) load_png_graphic(typ,grp,id,txt_fp,row_pointers,height,width)
199
200 LG(CST_GREEN,GROUP_BARE,LCT_GREEN_G);
201
202 LG(CST_FIRE_1,GROUP_FIRE,LCT_FIRE_1_G);
203 LG(CST_FIRE_2,GROUP_FIRE,LCT_FIRE_2_G);
204 LG(CST_FIRE_3,GROUP_FIRE,LCT_FIRE_3_G);
205 LG(CST_FIRE_4,GROUP_FIRE,LCT_FIRE_4_G);
206 LG(CST_FIRE_5,GROUP_FIRE,LCT_FIRE_5_G);
207
208 LG(CST_FIRE_DONE1,GROUP_FIRE,LCT_FIRE_DONE1_G);
209 LG(CST_FIRE_DONE2,GROUP_FIRE,LCT_FIRE_DONE2_G);
210 LG(CST_FIRE_DONE3,GROUP_FIRE,LCT_FIRE_DONE3_G);
211 LG(CST_FIRE_DONE4,GROUP_FIRE,LCT_FIRE_DONE4_G);
212
213 LG(CST_BURNT,GROUP_BURNT,LCT_BURNT_G);
214
215 LG(CST_PARKLAND_PLANE,GROUP_PARKLAND,LCT_PARKLAND_PLANE_G);
216 LG(CST_PARKLAND_LAKE,GROUP_PARKLAND,LCT_PARKLAND_LAKE_G);
217
218 LG(CST_POWERL_H_L,GROUP_POWER_LINE,LCT_POWERL_H_L_G);
219 LG(CST_POWERL_V_L,GROUP_POWER_LINE,LCT_POWERL_V_L_G);
220 LG(CST_POWERL_LD_L,GROUP_POWER_LINE,LCT_POWERL_LD_L_G);
221 LG(CST_POWERL_RD_L,GROUP_POWER_LINE,LCT_POWERL_RD_L_G);
222 LG(CST_POWERL_LU_L,GROUP_POWER_LINE,LCT_POWERL_LU_L_G);
223 LG(CST_POWERL_RU_L,GROUP_POWER_LINE,LCT_POWERL_RU_L_G);
224 LG(CST_POWERL_LDU_L,GROUP_POWER_LINE,LCT_POWERL_LDU_L_G);
225 LG(CST_POWERL_LDR_L,GROUP_POWER_LINE,LCT_POWERL_LDR_L_G);
226 LG(CST_POWERL_LUR_L,GROUP_POWER_LINE,LCT_POWERL_LUR_L_G);
227 LG(CST_POWERL_UDR_L,GROUP_POWER_LINE,LCT_POWERL_UDR_L_G);
228 LG(CST_POWERL_LUDR_L,GROUP_POWER_LINE,LCT_POWERL_LUDR_L_G);
229 LG(CST_POWERL_H_D,GROUP_POWER_LINE,LCT_POWERL_H_D_G);
230 LG(CST_POWERL_V_D,GROUP_POWER_LINE,LCT_POWERL_V_D_G);
231 LG(CST_POWERL_LD_D,GROUP_POWER_LINE,LCT_POWERL_LD_D_G);
232 LG(CST_POWERL_RD_D,GROUP_POWER_LINE,LCT_POWERL_RD_D_G);
233 LG(CST_POWERL_LU_D,GROUP_POWER_LINE,LCT_POWERL_LU_D_G);
234 LG(CST_POWERL_RU_D,GROUP_POWER_LINE,LCT_POWERL_RU_D_G);
235 LG(CST_POWERL_LDU_D,GROUP_POWER_LINE,LCT_POWERL_LDU_D_G);
236 LG(CST_POWERL_LDR_D,GROUP_POWER_LINE,LCT_POWERL_LDR_D_G);
237 LG(CST_POWERL_LUR_D,GROUP_POWER_LINE,LCT_POWERL_LUR_D_G);
238 LG(CST_POWERL_UDR_D,GROUP_POWER_LINE,LCT_POWERL_UDR_D_G);
239 LG(CST_POWERL_LUDR_D,GROUP_POWER_LINE,LCT_POWERL_LUDR_D_G);
240
241 LG(CST_RAIL_LR,GROUP_RAIL,LCT_RAIL_LR_G);
242 LG(CST_RAIL_LU,GROUP_RAIL,LCT_RAIL_LU_G);
243 LG(CST_RAIL_LD,GROUP_RAIL,LCT_RAIL_LD_G);
244 LG(CST_RAIL_UD,GROUP_RAIL,LCT_RAIL_UD_G);
245 LG(CST_RAIL_UR,GROUP_RAIL,LCT_RAIL_UR_G);
246 LG(CST_RAIL_DR,GROUP_RAIL,LCT_RAIL_DR_G);
247 LG(CST_RAIL_LUR,GROUP_RAIL,LCT_RAIL_LUR_G);
248 LG(CST_RAIL_LDR,GROUP_RAIL,LCT_RAIL_LDR_G);
249 LG(CST_RAIL_LUD,GROUP_RAIL,LCT_RAIL_LUD_G);
250 LG(CST_RAIL_UDR,GROUP_RAIL,LCT_RAIL_UDR_G);
251 LG(CST_RAIL_LUDR,GROUP_RAIL,LCT_RAIL_LUDR_G);
252
253 LG(CST_ROAD_LR,GROUP_ROAD,LCT_ROAD_LR_G);
254 LG(CST_ROAD_LU,GROUP_ROAD,LCT_ROAD_LU_G);
255 LG(CST_ROAD_LD,GROUP_ROAD,LCT_ROAD_LD_G);
256 LG(CST_ROAD_UD,GROUP_ROAD,LCT_ROAD_UD_G);
257 LG(CST_ROAD_UR,GROUP_ROAD,LCT_ROAD_UR_G);
258 LG(CST_ROAD_DR,GROUP_ROAD,LCT_ROAD_DR_G);
259 LG(CST_ROAD_LUR,GROUP_ROAD,LCT_ROAD_LUR_G);
260 LG(CST_ROAD_LDR,GROUP_ROAD,LCT_ROAD_LDR_G);
261 LG(CST_ROAD_LUD,GROUP_ROAD,LCT_ROAD_LUD_G);
262 LG(CST_ROAD_UDR,GROUP_ROAD,LCT_ROAD_UDR_G);
263 LG(CST_ROAD_LUDR,GROUP_ROAD,LCT_ROAD_LUDR_G);
264
265 LG(CST_TRACK_LR,GROUP_TRACK,LCT_TRACK_LR_G);
266 LG(CST_TRACK_LU,GROUP_TRACK,LCT_TRACK_LU_G);
267 LG(CST_TRACK_LD,GROUP_TRACK,LCT_TRACK_LD_G);
268 LG(CST_TRACK_UD,GROUP_TRACK,LCT_TRACK_UD_G);
269 LG(CST_TRACK_UR,GROUP_TRACK,LCT_TRACK_UR_G);
270 LG(CST_TRACK_DR,GROUP_TRACK,LCT_TRACK_DR_G);
271 LG(CST_TRACK_LUR,GROUP_TRACK,LCT_TRACK_LUR_G);
272 LG(CST_TRACK_LDR,GROUP_TRACK,LCT_TRACK_LDR_G);
273 LG(CST_TRACK_LUD,GROUP_TRACK,LCT_TRACK_LUD_G);
274 LG(CST_TRACK_UDR,GROUP_TRACK,LCT_TRACK_UDR_G);
275 LG(CST_TRACK_LUDR,GROUP_TRACK,LCT_TRACK_LUDR_G);
276
277 LG(CST_WATER,GROUP_WATER,LCT_WATER_G);
278 LG(CST_WATER_D,GROUP_WATER,LCT_WATER_D_G);
279 LG(CST_WATER_R,GROUP_WATER,LCT_WATER_R_G);
280 LG(CST_WATER_U,GROUP_WATER,LCT_WATER_U_G);
281 LG(CST_WATER_L,GROUP_WATER,LCT_WATER_L_G);
282 LG(CST_WATER_LR,GROUP_WATER,LCT_WATER_LR_G);
283 LG(CST_WATER_UD,GROUP_WATER,LCT_WATER_UD_G);
284 LG(CST_WATER_LD,GROUP_WATER,LCT_WATER_LD_G);
285 LG(CST_WATER_RD,GROUP_WATER,LCT_WATER_RD_G);
286 LG(CST_WATER_LU,GROUP_WATER,LCT_WATER_LU_G);
287 LG(CST_WATER_UR,GROUP_WATER,LCT_WATER_UR_G);
288 LG(CST_WATER_LUD,GROUP_WATER,LCT_WATER_LUD_G);
289 LG(CST_WATER_LRD,GROUP_WATER,LCT_WATER_LRD_G);
290 LG(CST_WATER_LUR,GROUP_WATER,LCT_WATER_LUR_G);
291 LG(CST_WATER_URD,GROUP_WATER,LCT_WATER_URD_G);
292 LG(CST_WATER_LURD,GROUP_WATER,LCT_WATER_LURD_G);
293
294 LG(CST_BLACKSMITH_0,GROUP_BLACKSMITH,LCT_BLACKSMITH_0_G);
295 LG(CST_BLACKSMITH_1,GROUP_BLACKSMITH,LCT_BLACKSMITH_1_G);
296 LG(CST_BLACKSMITH_2,GROUP_BLACKSMITH,LCT_BLACKSMITH_2_G);
297 LG(CST_BLACKSMITH_3,GROUP_BLACKSMITH,LCT_BLACKSMITH_3_G);
298 LG(CST_BLACKSMITH_4,GROUP_BLACKSMITH,LCT_BLACKSMITH_4_G);
299 LG(CST_BLACKSMITH_5,GROUP_BLACKSMITH,LCT_BLACKSMITH_5_G);
300 LG(CST_BLACKSMITH_6,GROUP_BLACKSMITH,LCT_BLACKSMITH_6_G);
301
302 LG(CST_CRICKET_1,GROUP_CRICKET,LCT_CRICKET_1_G);
303 LG(CST_CRICKET_2,GROUP_CRICKET,LCT_CRICKET_2_G);
304 LG(CST_CRICKET_3,GROUP_CRICKET,LCT_CRICKET_3_G);
305 LG(CST_CRICKET_4,GROUP_CRICKET,LCT_CRICKET_4_G);
306 LG(CST_CRICKET_5,GROUP_CRICKET,LCT_CRICKET_5_G);
307 LG(CST_CRICKET_6,GROUP_CRICKET,LCT_CRICKET_6_G);
308 LG(CST_CRICKET_7,GROUP_CRICKET,LCT_CRICKET_7_G);
309
310 LG(CST_FIRESTATION_1,GROUP_FIRESTATION,LCT_FIRESTATION_1_G);
311 LG(CST_FIRESTATION_2,GROUP_FIRESTATION,LCT_FIRESTATION_2_G);
312 LG(CST_FIRESTATION_3,GROUP_FIRESTATION,LCT_FIRESTATION_3_G);
313 LG(CST_FIRESTATION_4,GROUP_FIRESTATION,LCT_FIRESTATION_4_G);
314 LG(CST_FIRESTATION_5,GROUP_FIRESTATION,LCT_FIRESTATION_5_G);
315 LG(CST_FIRESTATION_6,GROUP_FIRESTATION,LCT_FIRESTATION_6_G);
316 LG(CST_FIRESTATION_7,GROUP_FIRESTATION,LCT_FIRESTATION_7_G);
317 LG(CST_FIRESTATION_8,GROUP_FIRESTATION,LCT_FIRESTATION_8_G);
318 LG(CST_FIRESTATION_9,GROUP_FIRESTATION,LCT_FIRESTATION_9_G);
319 LG(CST_FIRESTATION_10,GROUP_FIRESTATION,LCT_FIRESTATION_10_G);
320
321 LG(CST_HEALTH,GROUP_HEALTH,LCT_HEALTH_G);
322
323 LG(CST_MARKET_EMPTY,GROUP_MARKET,LCT_MARKET_EMPTY_G);
324 LG(CST_MARKET_LOW,GROUP_MARKET,LCT_MARKET_LOW_G);
325 LG(CST_MARKET_MED,GROUP_MARKET,LCT_MARKET_MED_G);
326 LG(CST_MARKET_FULL,GROUP_MARKET,LCT_MARKET_FULL_G);
327
328 LG(CST_MILL_0,GROUP_MILL,LCT_MILL_0_G);
329 LG(CST_MILL_1,GROUP_MILL,LCT_MILL_1_G);
330 LG(CST_MILL_2,GROUP_MILL,LCT_MILL_2_G);
331 LG(CST_MILL_3,GROUP_MILL,LCT_MILL_3_G);
332 LG(CST_MILL_4,GROUP_MILL,LCT_MILL_4_G);
333 LG(CST_MILL_5,GROUP_MILL,LCT_MILL_5_G);
334 LG(CST_MILL_6,GROUP_MILL,LCT_MILL_6_G);
335
336 LG(CST_MONUMENT_0,GROUP_MONUMENT,LCT_MONUMENT_0_G);
337 LG(CST_MONUMENT_1,GROUP_MONUMENT,LCT_MONUMENT_1_G);
338 LG(CST_MONUMENT_2,GROUP_MONUMENT,LCT_MONUMENT_2_G);
339 LG(CST_MONUMENT_3,GROUP_MONUMENT,LCT_MONUMENT_3_G);
340 LG(CST_MONUMENT_4,GROUP_MONUMENT,LCT_MONUMENT_4_G);
341 LG(CST_MONUMENT_5,GROUP_MONUMENT,LCT_MONUMENT_5_G);
342
343 LG(CST_POTTERY_0,GROUP_POTTERY,LCT_POTTERY_0_G);
344 LG(CST_POTTERY_1,GROUP_POTTERY,LCT_POTTERY_1_G);
345 LG(CST_POTTERY_2,GROUP_POTTERY,LCT_POTTERY_2_G);
346 LG(CST_POTTERY_3,GROUP_POTTERY,LCT_POTTERY_3_G);
347 LG(CST_POTTERY_4,GROUP_POTTERY,LCT_POTTERY_4_G);
348 LG(CST_POTTERY_5,GROUP_POTTERY,LCT_POTTERY_5_G);
349 LG(CST_POTTERY_6,GROUP_POTTERY,LCT_POTTERY_6_G);
350 LG(CST_POTTERY_7,GROUP_POTTERY,LCT_POTTERY_7_G);
351 LG(CST_POTTERY_8,GROUP_POTTERY,LCT_POTTERY_8_G);
352 LG(CST_POTTERY_9,GROUP_POTTERY,LCT_POTTERY_9_G);
353 LG(CST_POTTERY_10,GROUP_POTTERY,LCT_POTTERY_10_G);
354
355 LG(CST_RECYCLE,GROUP_RECYCLE,LCT_RECYCLE_G);
356
357 LG(CST_SCHOOL,GROUP_SCHOOL,LCT_SCHOOL_G);
358
359 LG(CST_SHANTY,GROUP_SHANTY,LCT_SHANTY_G);
360
361 LG(CST_SUBSTATION_R,GROUP_SUBSTATION,LCT_SUBSTATION_R_G);
362 LG(CST_SUBSTATION_G,GROUP_SUBSTATION,LCT_SUBSTATION_G_G);
363 LG(CST_SUBSTATION_RG,GROUP_SUBSTATION,LCT_SUBSTATION_RG_G);
364
365 LG(CST_WINDMILL_1_G,GROUP_WINDMILL,LCT_WINDMILL_1_G_G);
366 LG(CST_WINDMILL_2_G,GROUP_WINDMILL,LCT_WINDMILL_2_G_G);
367 LG(CST_WINDMILL_3_G,GROUP_WINDMILL,LCT_WINDMILL_3_G_G);
368 LG(CST_WINDMILL_1_RG,GROUP_WINDMILL,LCT_WINDMILL_1_RG_G);
369 LG(CST_WINDMILL_2_RG,GROUP_WINDMILL,LCT_WINDMILL_2_RG_G);
370 LG(CST_WINDMILL_3_RG,GROUP_WINDMILL,LCT_WINDMILL_3_RG_G);
371 LG(CST_WINDMILL_1_R,GROUP_WINDMILL,LCT_WINDMILL_1_R_G);
372 LG(CST_WINDMILL_2_R,GROUP_WINDMILL,LCT_WINDMILL_2_R_G);
373 LG(CST_WINDMILL_3_R,GROUP_WINDMILL,LCT_WINDMILL_3_R_G);
374 LG(CST_WINDMILL_1_W,GROUP_WINDMILL,LCT_WINDMILL_1_W_G);
375 LG(CST_WINDMILL_2_W,GROUP_WINDMILL,LCT_WINDMILL_2_W_G);
376 LG(CST_WINDMILL_3_W,GROUP_WINDMILL,LCT_WINDMILL_3_W_G);
377
378 LG(CST_INDUSTRY_L_C,GROUP_INDUSTRY_L,LCT_INDUSTRY_L_C_G);
379 LG(CST_INDUSTRY_L_Q1,GROUP_INDUSTRY_L,LCT_INDUSTRY_L_Q1_G);
380 LG(CST_INDUSTRY_L_Q2,GROUP_INDUSTRY_L,LCT_INDUSTRY_L_Q2_G);
381 LG(CST_INDUSTRY_L_Q3,GROUP_INDUSTRY_L,LCT_INDUSTRY_L_Q3_G);
382 LG(CST_INDUSTRY_L_Q4,GROUP_INDUSTRY_L,LCT_INDUSTRY_L_Q4_G);
383 LG(CST_INDUSTRY_L_L1,GROUP_INDUSTRY_L,LCT_INDUSTRY_L_L1_G);
384 LG(CST_INDUSTRY_L_L2,GROUP_INDUSTRY_L,LCT_INDUSTRY_L_L2_G);
385 LG(CST_INDUSTRY_L_L3,GROUP_INDUSTRY_L,LCT_INDUSTRY_L_L3_G);
386 LG(CST_INDUSTRY_L_L4,GROUP_INDUSTRY_L,LCT_INDUSTRY_L_L4_G);
387 LG(CST_INDUSTRY_L_M1,GROUP_INDUSTRY_L,LCT_INDUSTRY_L_M1_G);
388 LG(CST_INDUSTRY_L_M2,GROUP_INDUSTRY_L,LCT_INDUSTRY_L_M2_G);
389 LG(CST_INDUSTRY_L_M3,GROUP_INDUSTRY_L,LCT_INDUSTRY_L_M3_G);
390 LG(CST_INDUSTRY_L_M4,GROUP_INDUSTRY_L,LCT_INDUSTRY_L_M4_G);
391 LG(CST_INDUSTRY_L_H1,GROUP_INDUSTRY_L,LCT_INDUSTRY_L_H1_G);
392 LG(CST_INDUSTRY_L_H2,GROUP_INDUSTRY_L,LCT_INDUSTRY_L_H2_G);
393 LG(CST_INDUSTRY_L_H3,GROUP_INDUSTRY_L,LCT_INDUSTRY_L_H3_G);
394 LG(CST_INDUSTRY_L_H4,GROUP_INDUSTRY_L,LCT_INDUSTRY_L_H4_G);
395
396 LG(CST_RESIDENCE_LL,GROUP_RESIDENCE_LL,LCT_RESIDENCE_LL_G);
397 LG(CST_RESIDENCE_ML,GROUP_RESIDENCE_ML,LCT_RESIDENCE_ML_G);
398 LG(CST_RESIDENCE_HL,GROUP_RESIDENCE_HL,LCT_RESIDENCE_HL_G);
399 LG(CST_RESIDENCE_LH,GROUP_RESIDENCE_LH,LCT_RESIDENCE_LH_G);
400 LG(CST_RESIDENCE_MH,GROUP_RESIDENCE_MH,LCT_RESIDENCE_MH_G);
401 LG(CST_RESIDENCE_HH,GROUP_RESIDENCE_HH,LCT_RESIDENCE_HH_G);
402
403 LG(CST_UNIVERSITY,GROUP_UNIVERSITY,LCT_UNIVERSITY_G);
404
405 LG(CST_COALMINE_EMPTY,GROUP_COALMINE,LCT_COALMINE_EMPTY_G);
406 LG(CST_COALMINE_LOW,GROUP_COALMINE,LCT_COALMINE_LOW_G);
407 LG(CST_COALMINE_MED,GROUP_COALMINE,LCT_COALMINE_MED_G);
408 LG(CST_COALMINE_FULL,GROUP_COALMINE,LCT_COALMINE_FULL_G);
409
410 LG(CST_COMMUNE_1,GROUP_COMMUNE,LCT_COMMUNE_1_G);
411 LG(CST_COMMUNE_2,GROUP_COMMUNE,LCT_COMMUNE_2_G);
412 LG(CST_COMMUNE_3,GROUP_COMMUNE,LCT_COMMUNE_3_G);
413 LG(CST_COMMUNE_4,GROUP_COMMUNE,LCT_COMMUNE_4_G);
414 LG(CST_COMMUNE_5,GROUP_COMMUNE,LCT_COMMUNE_5_G);
415 LG(CST_COMMUNE_6,GROUP_COMMUNE,LCT_COMMUNE_6_G);
416 LG(CST_COMMUNE_7,GROUP_COMMUNE,LCT_COMMUNE_7_G);
417 LG(CST_COMMUNE_8,GROUP_COMMUNE,LCT_COMMUNE_8_G);
418 LG(CST_COMMUNE_9,GROUP_COMMUNE,LCT_COMMUNE_9_G);
419 LG(CST_COMMUNE_10,GROUP_COMMUNE,LCT_COMMUNE_10_G);
420 LG(CST_COMMUNE_11,GROUP_COMMUNE,LCT_COMMUNE_11_G);
421 LG(CST_COMMUNE_12,GROUP_COMMUNE,LCT_COMMUNE_12_G);
422 LG(CST_COMMUNE_13,GROUP_COMMUNE,LCT_COMMUNE_13_G);
423 LG(CST_COMMUNE_14,GROUP_COMMUNE,LCT_COMMUNE_14_G);
424
425 LG(CST_EX_PORT,GROUP_PORT,LCT_EX_PORT_G);
426
427 LG(CST_FARM_O0,GROUP_ORGANIC_FARM,LCT_FARM_O0_G);
428 LG(CST_FARM_O1,GROUP_ORGANIC_FARM,LCT_FARM_O1_G);
429 LG(CST_FARM_O2,GROUP_ORGANIC_FARM,LCT_FARM_O2_G);
430 LG(CST_FARM_O3,GROUP_ORGANIC_FARM,LCT_FARM_O3_G);
431 LG(CST_FARM_O4,GROUP_ORGANIC_FARM,LCT_FARM_O4_G);
432 LG(CST_FARM_O5,GROUP_ORGANIC_FARM,LCT_FARM_O5_G);
433 LG(CST_FARM_O6,GROUP_ORGANIC_FARM,LCT_FARM_O6_G);
434 LG(CST_FARM_O7,GROUP_ORGANIC_FARM,LCT_FARM_O7_G);
435 LG(CST_FARM_O8,GROUP_ORGANIC_FARM,LCT_FARM_O8_G);
436 LG(CST_FARM_O9,GROUP_ORGANIC_FARM,LCT_FARM_O9_G);
437 LG(CST_FARM_O10,GROUP_ORGANIC_FARM,LCT_FARM_O10_G);
438 LG(CST_FARM_O11,GROUP_ORGANIC_FARM,LCT_FARM_O11_G);
439 LG(CST_FARM_O12,GROUP_ORGANIC_FARM,LCT_FARM_O12_G);
440 LG(CST_FARM_O13,GROUP_ORGANIC_FARM,LCT_FARM_O13_G);
441 LG(CST_FARM_O14,GROUP_ORGANIC_FARM,LCT_FARM_O14_G);
442 LG(CST_FARM_O15,GROUP_ORGANIC_FARM,LCT_FARM_O15_G);
443 LG(CST_FARM_O16,GROUP_ORGANIC_FARM,LCT_FARM_O16_G);
444
445 LG(CST_INDUSTRY_H_C,GROUP_INDUSTRY_H,LCT_INDUSTRY_H_C_G);
446 LG(CST_INDUSTRY_H_L1,GROUP_INDUSTRY_H,LCT_INDUSTRY_H_L1_G);
447 LG(CST_INDUSTRY_H_L2,GROUP_INDUSTRY_H,LCT_INDUSTRY_H_L2_G);
448 LG(CST_INDUSTRY_H_L3,GROUP_INDUSTRY_H,LCT_INDUSTRY_H_L3_G);
449 LG(CST_INDUSTRY_H_L4,GROUP_INDUSTRY_H,LCT_INDUSTRY_H_L4_G);
450 LG(CST_INDUSTRY_H_L5,GROUP_INDUSTRY_H,LCT_INDUSTRY_H_L5_G);
451 LG(CST_INDUSTRY_H_L6,GROUP_INDUSTRY_H,LCT_INDUSTRY_H_L6_G);
452 LG(CST_INDUSTRY_H_L7,GROUP_INDUSTRY_H,LCT_INDUSTRY_H_L7_G);
453 LG(CST_INDUSTRY_H_L8,GROUP_INDUSTRY_H,LCT_INDUSTRY_H_L8_G);
454 LG(CST_INDUSTRY_H_M1,GROUP_INDUSTRY_H,LCT_INDUSTRY_H_M1_G);
455 LG(CST_INDUSTRY_H_M2,GROUP_INDUSTRY_H,LCT_INDUSTRY_H_M2_G);
456 LG(CST_INDUSTRY_H_M3,GROUP_INDUSTRY_H,LCT_INDUSTRY_H_M3_G);
457 LG(CST_INDUSTRY_H_M4,GROUP_INDUSTRY_H,LCT_INDUSTRY_H_M4_G);
458 LG(CST_INDUSTRY_H_M5,GROUP_INDUSTRY_H,LCT_INDUSTRY_H_M5_G);
459 LG(CST_INDUSTRY_H_M6,GROUP_INDUSTRY_H,LCT_INDUSTRY_H_M6_G);
460 LG(CST_INDUSTRY_H_M7,GROUP_INDUSTRY_H,LCT_INDUSTRY_H_M7_G);
461 LG(CST_INDUSTRY_H_M8,GROUP_INDUSTRY_H,LCT_INDUSTRY_H_M8_G);
462 LG(CST_INDUSTRY_H_H1,GROUP_INDUSTRY_H,LCT_INDUSTRY_H_H1_G);
463 LG(CST_INDUSTRY_H_H2,GROUP_INDUSTRY_H,LCT_INDUSTRY_H_H2_G);
464 LG(CST_INDUSTRY_H_H3,GROUP_INDUSTRY_H,LCT_INDUSTRY_H_H3_G);
465 LG(CST_INDUSTRY_H_H4,GROUP_INDUSTRY_H,LCT_INDUSTRY_H_H4_G);
466 LG(CST_INDUSTRY_H_H5,GROUP_INDUSTRY_H,LCT_INDUSTRY_H_H5_G);
467 LG(CST_INDUSTRY_H_H6,GROUP_INDUSTRY_H,LCT_INDUSTRY_H_H6_G);
468 LG(CST_INDUSTRY_H_H7,GROUP_INDUSTRY_H,LCT_INDUSTRY_H_H7_G);
469 LG(CST_INDUSTRY_H_H8,GROUP_INDUSTRY_H,LCT_INDUSTRY_H_H8_G);
470
471 LG(CST_OREMINE_1,GROUP_OREMINE,LCT_OREMINE_1_G);
472 LG(CST_OREMINE_2,GROUP_OREMINE,LCT_OREMINE_2_G);
473 LG(CST_OREMINE_3,GROUP_OREMINE,LCT_OREMINE_3_G);
474 LG(CST_OREMINE_4,GROUP_OREMINE,LCT_OREMINE_4_G);
475 LG(CST_OREMINE_5,GROUP_OREMINE,LCT_OREMINE_5_G);
476 LG(CST_OREMINE_6,GROUP_OREMINE,LCT_OREMINE_6_G);
477 LG(CST_OREMINE_7,GROUP_OREMINE,LCT_OREMINE_7_G);
478 LG(CST_OREMINE_8,GROUP_OREMINE,LCT_OREMINE_8_G);
479
480 LG(CST_POWERS_COAL_EMPTY,GROUP_COAL_POWER,LCT_POWERS_COAL_EMPTY_G);
481 LG(CST_POWERS_COAL_LOW,GROUP_COAL_POWER,LCT_POWERS_COAL_LOW_G);
482 LG(CST_POWERS_COAL_MED,GROUP_COAL_POWER,LCT_POWERS_COAL_MED_G);
483 LG(CST_POWERS_COAL_FULL,GROUP_COAL_POWER,LCT_POWERS_COAL_FULL_G);
484
485 LG(CST_POWERS_SOLAR,GROUP_SOLAR_POWER,LCT_POWERS_SOLAR_G);
486
487 LG(CST_ROCKET_1,GROUP_ROCKET,LCT_ROCKET_1_G);
488 LG(CST_ROCKET_2,GROUP_ROCKET,LCT_ROCKET_2_G);
489 LG(CST_ROCKET_3,GROUP_ROCKET,LCT_ROCKET_3_G);
490 LG(CST_ROCKET_4,GROUP_ROCKET,LCT_ROCKET_4_G);
491 LG(CST_ROCKET_5,GROUP_ROCKET,LCT_ROCKET_5_G);
492 LG(CST_ROCKET_6,GROUP_ROCKET,LCT_ROCKET_6_G);
493 LG(CST_ROCKET_7,GROUP_ROCKET,LCT_ROCKET_7_G);
494 LG(CST_ROCKET_FLOWN,GROUP_ROCKET,LCT_ROCKET_FLOWN_G);
495
496 LG(CST_TIP_0,GROUP_TIP,LCT_TIP_0_G);
497 LG(CST_TIP_1,GROUP_TIP,LCT_TIP_1_G);
498 LG(CST_TIP_2,GROUP_TIP,LCT_TIP_2_G);
499 LG(CST_TIP_3,GROUP_TIP,LCT_TIP_3_G);
500 LG(CST_TIP_4,GROUP_TIP,LCT_TIP_4_G);
501 LG(CST_TIP_5,GROUP_TIP,LCT_TIP_5_G);
502 LG(CST_TIP_6,GROUP_TIP,LCT_TIP_6_G);
503 LG(CST_TIP_7,GROUP_TIP,LCT_TIP_7_G);
504 LG(CST_TIP_8,GROUP_TIP,LCT_TIP_8_G);
505
506 // main_t
507 #undef LG
508
509 #if defined (commentout)
510 /* PROCESS IMAGE HERE */
511 while (!feof(txt_fp)) {
512 char buf[128];
513 char *fnp,*rip,*cip;
514 int ri,ci;
515
516 /* Get line from text file */
517 fgets (buf,128,txt_fp);
518
519 /* Tokenize */
520 fnp = strtok(buf," \t");
521 if (!fnp || *fnp == '#') continue;
522 if (*fnp == '@') break;
523 rip = strtok(NULL," \t");
524 if (!rip) continue;
525 cip = strtok(NULL," \t");
526 if (!cip) continue;
527 ri = atoi(rip);
528 ci = atoi(cip);
529
530 /* Copy icon */
531 if (!strcmp(fnp,LCT_GREEN_G)) {
532 int r,c;
533 char* p;
534 main_types[CST_GREEN].graphic=malloc(16*16);
535 p = main_types[CST_GREEN].graphic;
536 for (r=ri*16;r<ri*16+16;r++) {
537 for (c=ci*16;c<ci*16+16;c++) {
538 *p++ = row_pointers[r][c];
539 } }
540 }
541 }
542 #endif
543
544 /* Free the memory */
545 for (row = 0; row < height; row++) {
546 png_free(png_ptr, row_pointers[row]);
547 }
548 free(row_pointers);
549
550 /* clean up after the read, and free any memory allocated - REQUIRED */
551 #if defined (commentout)
552 png_destroy_read_struct(&png_ptr, &info_ptr, png_infopp_NULL);
553 #endif
554 png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
555
556 /* that's it */
557 return (OK);
558 }
559
560 static char*
load_png_graphic(short type,short group,char * id,FILE * txt_fp,png_bytep * row_pointers,png_uint_32 width,png_uint_32 height)561 load_png_graphic (short type, short group, char* id,
562 FILE* txt_fp,png_bytep *row_pointers,
563 png_uint_32 width, png_uint_32 height)
564 {
565 char buf[128];
566 char *fnp,*rip,*cip;
567 int ri,ci;
568 char *grphc = 0;
569
570 while (!feof(txt_fp)) {
571 /* Get line from text file */
572 fgets (buf,128,txt_fp);
573
574 /* Tokenize */
575 fnp = strtok(buf," \t");
576 if (!fnp || *fnp == '#') continue;
577 if (*fnp == '@') break;
578 rip = strtok(NULL," \t");
579 if (!rip) continue;
580 cip = strtok(NULL," \t");
581 if (!cip) continue;
582 ri = atoi(rip);
583 ci = atoi(cip);
584
585 /* Copy icon */
586 if (!strcmp(fnp,id)) {
587 int r,c;
588 int nr,nc;
589 char* p;
590 nr = nc = main_groups[group].size;
591 p = grphc = malloc(nr*16*nc*16);
592 if (!grphc) malloc_failure();
593 for (r=ri*16;r<(ri+nr)*16;r++) {
594 for (c=ci*16;c<(ci+nc)*16;c++) {
595 *p++ = row_pointers[r][c];
596 }
597 }
598 break;
599 } else {
600 fprintf (stderr,"Error, wrong id string");
601 exit(-1);
602 }
603 }
604
605 /* Set the main_type info */
606 if (grphc) {
607 main_types[type].group = group;
608 main_types[type].graphic = grphc;
609 } else {
610 fprintf (stderr,"Error, couldn't find id string");
611 exit(-1);
612 }
613 return 0;
614 }
615