]> git.zerfleddert.de Git - micropolis/blob - src/sim/g_setup.c
allow overriding $CC for tclx
[micropolis] / src / sim / g_setup.c
1 /* g_setup.c
2 *
3 * Micropolis, Unix Version. This game was released for the Unix platform
4 * in or about 1990 and has been modified for inclusion in the One Laptop
5 * Per Child program. Copyright (C) 1989 - 2007 Electronic Arts Inc. If
6 * you need assistance with this program, you may contact:
7 * http://wiki.laptop.org/go/Micropolis or email micropolis@laptop.org.
8 *
9 * This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or (at
12 * your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details. You should have received a
18 * copy of the GNU General Public License along with this program. If
19 * not, see <http://www.gnu.org/licenses/>.
20 *
21 * ADDITIONAL TERMS per GNU GPL Section 7
22 *
23 * No trademark or publicity rights are granted. This license does NOT
24 * give you any right, title or interest in the trademark SimCity or any
25 * other Electronic Arts trademark. You may not distribute any
26 * modification of this program using the trademark SimCity or claim any
27 * affliation or association with Electronic Arts Inc. or its employees.
28 *
29 * Any propagation or conveyance of this program must include this
30 * copyright notice and these terms.
31 *
32 * If you convey this program (or any modifications of it) and assume
33 * contractual liability for the program to recipients of it, you agree
34 * to indemnify Electronic Arts for any liability that those contractual
35 * assumptions impose on Electronic Arts.
36 *
37 * You may not misrepresent the origins of this program; modified
38 * versions of the program must be marked as such and not identified as
39 * the original program.
40 *
41 * This disclaimer supplements the one included in the General Public
42 * License. TO THE FULLEST EXTENT PERMISSIBLE UNDER APPLICABLE LAW, THIS
43 * PROGRAM IS PROVIDED TO YOU "AS IS," WITH ALL FAULTS, WITHOUT WARRANTY
44 * OF ANY KIND, AND YOUR USE IS AT YOUR SOLE RISK. THE ENTIRE RISK OF
45 * SATISFACTORY QUALITY AND PERFORMANCE RESIDES WITH YOU. ELECTRONIC ARTS
46 * DISCLAIMS ANY AND ALL EXPRESS, IMPLIED OR STATUTORY WARRANTIES,
47 * INCLUDING IMPLIED WARRANTIES OF MERCHANTABILITY, SATISFACTORY QUALITY,
48 * FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT OF THIRD PARTY
49 * RIGHTS, AND WARRANTIES (IF ANY) ARISING FROM A COURSE OF DEALING,
50 * USAGE, OR TRADE PRACTICE. ELECTRONIC ARTS DOES NOT WARRANT AGAINST
51 * INTERFERENCE WITH YOUR ENJOYMENT OF THE PROGRAM; THAT THE PROGRAM WILL
52 * MEET YOUR REQUIREMENTS; THAT OPERATION OF THE PROGRAM WILL BE
53 * UNINTERRUPTED OR ERROR-FREE, OR THAT THE PROGRAM WILL BE COMPATIBLE
54 * WITH THIRD PARTY SOFTWARE OR THAT ANY ERRORS IN THE PROGRAM WILL BE
55 * CORRECTED. NO ORAL OR WRITTEN ADVICE PROVIDED BY ELECTRONIC ARTS OR
56 * ANY AUTHORIZED REPRESENTATIVE SHALL CREATE A WARRANTY. SOME
57 * JURISDICTIONS DO NOT ALLOW THE EXCLUSION OF OR LIMITATIONS ON IMPLIED
58 * WARRANTIES OR THE LIMITATIONS ON THE APPLICABLE STATUTORY RIGHTS OF A
59 * CONSUMER, SO SOME OR ALL OF THE ABOVE EXCLUSIONS AND LIMITATIONS MAY
60 * NOT APPLY TO YOU.
61 */
62 #include "sim.h"
63
64
65 #define SIM_SMTILE 385
66 #define SIM_BWTILE 386
67 #define SIM_GSMTILE 388
68 #define SIM_LGTILE 544
69
70
71 #define gray25_width 16
72 #define gray25_height 16
73 static char gray25_bits[] = {
74 0x77, 0x77,
75 0xdd, 0xdd,
76 0x77, 0x77,
77 0xdd, 0xdd,
78 0x77, 0x77,
79 0xdd, 0xdd,
80 0x77, 0x77,
81 0xdd, 0xdd,
82 0x77, 0x77,
83 0xdd, 0xdd,
84 0x77, 0x77,
85 0xdd, 0xdd,
86 0x77, 0x77,
87 0xdd, 0xdd,
88 0x77, 0x77,
89 0xdd, 0xdd,
90 };
91
92
93 #define gray50_width 16
94 #define gray50_height 16
95 static char gray50_bits[] = {
96 0x55, 0x55,
97 0xaa, 0xaa,
98 0x55, 0x55,
99 0xaa, 0xaa,
100 0x55, 0x55,
101 0xaa, 0xaa,
102 0x55, 0x55,
103 0xaa, 0xaa,
104 0x55, 0x55,
105 0xaa, 0xaa,
106 0x55, 0x55,
107 0xaa, 0xaa,
108 0x55, 0x55,
109 0xaa, 0xaa,
110 0x55, 0x55,
111 0xaa, 0xaa,
112 };
113
114
115 #define gray75_width 16
116 #define gray75_height 16
117 static char gray75_bits[] = {
118 0x88, 0x88,
119 0x22, 0x22,
120 0x88, 0x88,
121 0x22, 0x22,
122 0x88, 0x88,
123 0x22, 0x22,
124 0x88, 0x88,
125 0x22, 0x22,
126 0x88, 0x88,
127 0x22, 0x22,
128 0x88, 0x88,
129 0x22, 0x22,
130 0x88, 0x88,
131 0x22, 0x22,
132 0x88, 0x88,
133 0x22, 0x22,
134 };
135
136 #define vert_width 16
137 #define vert_height 16
138 static char vert_bits[] = {
139 0xaa, 0xaa,
140 0xaa, 0xaa,
141 0xaa, 0xaa,
142 0xaa, 0xaa,
143 0xaa, 0xaa,
144 0xaa, 0xaa,
145 0xaa, 0xaa,
146 0xaa, 0xaa,
147 0xaa, 0xaa,
148 0xaa, 0xaa,
149 0xaa, 0xaa,
150 0xaa, 0xaa,
151 0xaa, 0xaa,
152 0xaa, 0xaa,
153 0xaa, 0xaa,
154 0xaa, 0xaa,
155 };
156
157
158 #define horiz_width 16
159 #define horiz_height 16
160 static char horiz_bits[] = {
161 0xff, 0xff,
162 0x00, 0x00,
163 0xff, 0xff,
164 0x00, 0x00,
165 0xff, 0xff,
166 0x00, 0x00,
167 0xff, 0xff,
168 0x00, 0x00,
169 0xff, 0xff,
170 0x00, 0x00,
171 0xff, 0xff,
172 0x00, 0x00,
173 0xff, 0xff,
174 0x00, 0x00,
175 0xff, 0xff,
176 0x00, 0x00,
177 };
178
179
180 #define diag_width 16
181 #define diag_height 16
182 static char diag_bits[] = {
183 0x55, 0x55,
184 0xee, 0xee,
185 0x55, 0x55,
186 0xba, 0xbb,
187 0x55, 0x55,
188 0xee, 0xee,
189 0x55, 0x55,
190 0xba, 0xbb,
191 0x55, 0x55,
192 0xee, 0xee,
193 0x55, 0x55,
194 0xba, 0xbb,
195 0x55, 0x55,
196 0xee, 0xee,
197 0x55, 0x55,
198 0xba, 0xbb,
199 };
200
201
202 Ptr MickGetHexa(short theID)
203 {
204 Handle theData;
205
206 theData = GetResource("hexa", theID);
207 return ((Ptr)*theData);
208 }
209
210
211 Pixmap *
212 GetObjectXpms(XDisplay *xd, int id, int frames)
213 {
214 int i;
215 Pixmap *pixmaps = (Pixmap *)ckalloc(2 * frames * sizeof (Pixmap));
216 XpmAttributes attributes;
217 char name[256];
218
219 attributes.visual = Tk_DefaultVisual(xd->screen);
220 attributes.colormap = Tk_DefaultColormap(xd->screen);
221 attributes.depth = Tk_DefaultDepth(xd->screen);
222 attributes.valuemask = XpmVisual | XpmColormap | XpmDepth;
223
224 for (i = 0; i < frames; i++) {
225 sprintf(name, "%s/images/obj%d-%d.xpm", HomeDir, id, i);
226 if (XpmReadFileToPixmap(xd->dpy,
227 RootWindowOfScreen(xd->screen),
228 name,
229 &pixmaps[i + i], &pixmaps[i + i + 1],
230 &attributes) < 0) {
231 fprintf(stderr,
232 "Uh oh, Micropolis couldn't read the pixmap file \"%s\".\n",
233 name);
234 sim_exit(1); // Just sets tkMustExit and ExitReturn
235 return NULL;
236 }
237 }
238 return (pixmaps);
239 }
240
241
242 void
243 GetPixmaps(XDisplay *xd)
244 {
245 if (xd->gray25_stipple == None) {
246 xd->gray25_stipple =
247 XCreatePixmapFromBitmapData(xd->dpy, xd->root,
248 gray25_bits, gray25_width, gray25_height,
249 1, 0, 1);
250 xd->gray50_stipple =
251 XCreatePixmapFromBitmapData(xd->dpy, xd->root,
252 gray50_bits, gray50_width, gray50_height,
253 1, 0, 1);
254 xd->gray75_stipple =
255 XCreatePixmapFromBitmapData(xd->dpy, xd->root,
256 gray75_bits, gray75_width, gray75_height,
257 1, 0, 1);
258 xd->vert_stipple =
259 XCreatePixmapFromBitmapData(xd->dpy, xd->root,
260 vert_bits, vert_width, vert_height,
261 1, 0, 1);
262 xd->horiz_stipple =
263 XCreatePixmapFromBitmapData(xd->dpy, xd->root,
264 horiz_bits, horiz_width, horiz_height,
265 1, 0, 1);
266 xd->diag_stipple =
267 XCreatePixmapFromBitmapData(xd->dpy, xd->root,
268 diag_bits, diag_width, diag_height,
269 1, 0, 1);
270 }
271
272 if (xd->objects == NULL) {
273 Pixmap **pm;
274
275 xd->objects = pm = (Pixmap **)ckalloc(OBJN * sizeof (Pixmap *));
276
277 pm[0] = NULL; /* no object number 0 */
278 pm[TRA] = GetObjectXpms(xd, TRA, 5);
279 pm[COP] = GetObjectXpms(xd, COP, 8);
280 pm[AIR] = GetObjectXpms(xd, AIR, 11);
281 pm[SHI] = GetObjectXpms(xd, SHI, 8);
282 pm[GOD] = GetObjectXpms(xd, GOD, 16);
283 pm[TOR] = GetObjectXpms(xd, TOR, 3);
284 pm[EXP] = GetObjectXpms(xd, EXP, 6);
285 pm[BUS] = GetObjectXpms(xd, BUS, 4);
286 }
287 }
288
289
290 void
291 GetViewTiles(SimView *view)
292 {
293 char name[256];
294 XpmAttributes attributes;
295
296 attributes.visual = Tk_DefaultVisual(view->x->screen);
297 attributes.colormap = Tk_DefaultColormap(view->x->screen);
298 attributes.depth = Tk_DefaultDepth(view->x->screen);
299 attributes.valuemask = XpmVisual | XpmColormap | XpmDepth;
300
301 if (view->class == Editor_Class) {
302
303 sprintf(name, "%s/images/%s", HomeDir,
304 view->x->color ? "tiles.xpm" : "tilesbw.xpm");
305
306 switch (view->type) {
307
308 case X_Mem_View:
309 if (view->x->big_tile_image == NULL) {
310 if (XpmReadFileToImage(view->x->dpy, name,
311 &view->x->big_tile_image, NULL,
312 &attributes) < 0) {
313 fprintf(stderr,
314 "Uh oh, Micropolis couldn't read the pixmap file \"%s\".\n",
315 name);
316 sim_exit(1); // Just sets tkMustExit and ExitReturn
317 return;
318 }
319 }
320 view->bigtiles = (unsigned char *)view->x->big_tile_image->data;
321 break;
322
323 case X_Wire_View:
324 if (view->x->big_tile_pixmap == None) {
325 if (XpmReadFileToPixmap(view->x->dpy,
326 RootWindowOfScreen(view->x->screen),
327 name,
328 &view->x->big_tile_pixmap, NULL,
329 &attributes) < 0) {
330 fprintf(stderr,
331 "Uh oh, Micropolis couldn't read the pixmap file \"%s\".\n",
332 name);
333 sim_exit(1); // Just sets tkMustExit and ExitReturn
334 return;
335 }
336 }
337 break;
338
339 }
340
341 } else if (view->class == Map_Class) {
342
343 if (view->x->small_tile_image == NULL) {
344 if (view->x->color) {
345
346 sprintf(name, "%s/images/%s", HomeDir, "tilessm.xpm");
347 if (XpmReadFileToImage(view->x->dpy, name,
348 &view->x->small_tile_image, NULL,
349 &attributes) < 0) {
350 fprintf(stderr,
351 "Uh oh, Micropolis couldn't read the pixmap file \"%s\".\n",
352 name);
353 sim_exit(1); // Just sets tkMustExit and ExitReturn
354 return;
355 }
356
357 } else {
358
359 view->x->small_tile_image =
360 XCreateImage(view->x->dpy, view->x->visual, 8,
361 ZPixmap,
362 0, (char *)MickGetHexa(SIM_GSMTILE),
363 4, 3 * TILE_COUNT, 8, 4);
364
365 }
366 }
367
368 { int x, y, tile;
369 unsigned char *from, *to;
370 int pixelBytes = view->pixel_bytes;
371
372 if (pixelBytes == 0) {
373 /* handle the case of monochrome display (8 bit map) */
374 pixelBytes = 1;
375 }
376
377 /* from is 4 pixels wide per 3 pixel wide tile */
378 from = (unsigned char *)view->x->small_tile_image->data;
379 to = (unsigned char *)ckalloc(4 * 4 * TILE_COUNT * pixelBytes);
380 view->smalltiles = to;
381
382 switch (pixelBytes) {
383
384 case 1:
385 for (tile = 0; tile < TILE_COUNT; tile++) {
386 for (y = 0; y < 3; y++) {
387 for (x = 0; x < 4; x++) {
388 *to++ = *from++;
389 }
390 }
391 for (x = 0; x < 4; x++) {
392 *to++ = 0;
393 }
394 }
395 break;
396
397 case 2:
398 for (tile = 0; tile < TILE_COUNT; tile++) {
399 for (y = 0; y < 3; y++) {
400 for (x = 0; x < 4; x++) {
401 *to++ = *from++;
402 *to++ = *from++;
403 }
404 }
405 for (x = 0; x < 4; x++) {
406 *to++ = 0;
407 *to++ = 0;
408 }
409 }
410 break;
411
412 case 3:
413 case 4:
414 for (tile = 0; tile < TILE_COUNT; tile++) {
415 for (y = 0; y < 3; y++) {
416 for (x = 0; x < 4; x++) {
417 *to++ = *from++;
418 *to++ = *from++;
419 *to++ = *from++;
420 if (pixelBytes == 4) {
421 *to++ = *from++;
422 }
423 }
424 }
425 for (x = 0; x < 4; x++) {
426 *to++ = 0;
427 *to++ = 0;
428 *to++ = 0;
429 if (pixelBytes == 4) {
430 *to++ = 0;
431 }
432 }
433 }
434 break;
435
436 default:
437 assert(0); /* Undefined depth */
438 break;
439
440 }
441
442 }
443 }
444 }
Impressum, Datenschutz