]> git.zerfleddert.de Git - micropolis/blob - src/sim/g_setup.c
61204fe81b9f0b1670a6772797d8da541097a8e4
[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 unsigned 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 unsigned 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 unsigned 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 unsigned 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 unsigned 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 unsigned 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 GetPixmaps(XDisplay *xd)
243 {
244 if (xd->gray25_stipple == None) {
245 xd->gray25_stipple =
246 XCreatePixmapFromBitmapData(xd->dpy, xd->root,
247 gray25_bits, gray25_width, gray25_height,
248 1, 0, 1);
249 xd->gray50_stipple =
250 XCreatePixmapFromBitmapData(xd->dpy, xd->root,
251 gray50_bits, gray50_width, gray50_height,
252 1, 0, 1);
253 xd->gray75_stipple =
254 XCreatePixmapFromBitmapData(xd->dpy, xd->root,
255 gray75_bits, gray75_width, gray75_height,
256 1, 0, 1);
257 xd->vert_stipple =
258 XCreatePixmapFromBitmapData(xd->dpy, xd->root,
259 vert_bits, vert_width, vert_height,
260 1, 0, 1);
261 xd->horiz_stipple =
262 XCreatePixmapFromBitmapData(xd->dpy, xd->root,
263 horiz_bits, horiz_width, horiz_height,
264 1, 0, 1);
265 xd->diag_stipple =
266 XCreatePixmapFromBitmapData(xd->dpy, xd->root,
267 diag_bits, diag_width, diag_height,
268 1, 0, 1);
269 }
270
271 if (xd->objects == NULL) {
272 Pixmap **pm;
273
274 xd->objects = pm = (Pixmap **)ckalloc(OBJN * sizeof (Pixmap *));
275
276 pm[0] = NULL; /* no object number 0 */
277 pm[TRA] = GetObjectXpms(xd, TRA, 5);
278 pm[COP] = GetObjectXpms(xd, COP, 8);
279 pm[AIR] = GetObjectXpms(xd, AIR, 11);
280 pm[SHI] = GetObjectXpms(xd, SHI, 8);
281 pm[GOD] = GetObjectXpms(xd, GOD, 16);
282 pm[TOR] = GetObjectXpms(xd, TOR, 3);
283 pm[EXP] = GetObjectXpms(xd, EXP, 6);
284 pm[BUS] = GetObjectXpms(xd, BUS, 4);
285 }
286 }
287
288
289 GetViewTiles(SimView *view)
290 {
291 char name[256];
292 XpmAttributes attributes;
293
294 attributes.visual = Tk_DefaultVisual(view->x->screen);
295 attributes.colormap = Tk_DefaultColormap(view->x->screen);
296 attributes.depth = Tk_DefaultDepth(view->x->screen);
297 attributes.valuemask = XpmVisual | XpmColormap | XpmDepth;
298
299 if (view->class == Editor_Class) {
300
301 sprintf(name, "%s/images/%s", HomeDir,
302 view->x->color ? "tiles.xpm" : "tilesbw.xpm");
303
304 switch (view->type) {
305
306 case X_Mem_View:
307 if (view->x->big_tile_image == NULL) {
308 if (XpmReadFileToImage(view->x->dpy, name,
309 &view->x->big_tile_image, NULL,
310 &attributes) < 0) {
311 fprintf(stderr,
312 "Uh oh, Micropolis couldn't read the pixmap file \"%s\".\n",
313 name);
314 sim_exit(1); // Just sets tkMustExit and ExitReturn
315 return;
316 }
317 }
318 view->bigtiles = (unsigned char *)view->x->big_tile_image->data;
319 break;
320
321 case X_Wire_View:
322 if (view->x->big_tile_pixmap == None) {
323 if (XpmReadFileToPixmap(view->x->dpy,
324 RootWindowOfScreen(view->x->screen),
325 name,
326 &view->x->big_tile_pixmap, NULL,
327 &attributes) < 0) {
328 fprintf(stderr,
329 "Uh oh, Micropolis couldn't read the pixmap file \"%s\".\n",
330 name);
331 sim_exit(1); // Just sets tkMustExit and ExitReturn
332 return;
333 }
334 }
335 break;
336
337 }
338
339 } else if (view->class == Map_Class) {
340
341 if (view->x->small_tile_image == NULL) {
342 if (view->x->color) {
343
344 sprintf(name, "%s/images/%s", HomeDir, "tilessm.xpm");
345 if (XpmReadFileToImage(view->x->dpy, name,
346 &view->x->small_tile_image, NULL,
347 &attributes) < 0) {
348 fprintf(stderr,
349 "Uh oh, Micropolis couldn't read the pixmap file \"%s\".\n",
350 name);
351 sim_exit(1); // Just sets tkMustExit and ExitReturn
352 return;
353 }
354
355 } else {
356
357 view->x->small_tile_image =
358 XCreateImage(view->x->dpy, view->x->visual, 8,
359 ZPixmap,
360 0, (char *)MickGetHexa(SIM_GSMTILE),
361 4, 3 * TILE_COUNT, 8, 4);
362
363 }
364 }
365
366 { int x, y, b, tile;
367 unsigned char *from, *to;
368 int pixelBytes = view->pixel_bytes;
369 int rowBytes = view->x->small_tile_image->bytes_per_line;
370
371 if (pixelBytes == 0) {
372 /* handle the case of monochrome display (8 bit map) */
373 pixelBytes = 1;
374 }
375
376 /* from is 4 pixels wide per 3 pixel wide tile */
377 from = (unsigned char *)view->x->small_tile_image->data;
378 to = (unsigned char *)ckalloc(4 * 4 * TILE_COUNT * pixelBytes);
379 view->smalltiles = to;
380
381 switch (pixelBytes) {
382
383 case 1:
384 for (tile = 0; tile < TILE_COUNT; tile++) {
385 for (y = 0; y < 3; y++) {
386 for (x = 0; x < 4; x++) {
387 *to++ = *from++;
388 }
389 }
390 for (x = 0; x < 4; x++) {
391 *to++ = 0;
392 }
393 }
394 break;
395
396 case 2:
397 for (tile = 0; tile < TILE_COUNT; tile++) {
398 for (y = 0; y < 3; y++) {
399 for (x = 0; x < 4; x++) {
400 *to++ = *from++;
401 *to++ = *from++;
402 }
403 }
404 for (x = 0; x < 4; x++) {
405 *to++ = 0;
406 *to++ = 0;
407 }
408 }
409 break;
410
411 case 3:
412 case 4:
413 for (tile = 0; tile < TILE_COUNT; tile++) {
414 for (y = 0; y < 3; y++) {
415 for (x = 0; x < 4; x++) {
416 *to++ = *from++;
417 *to++ = *from++;
418 *to++ = *from++;
419 if (pixelBytes == 4) {
420 *to++ = *from++;
421 }
422 }
423 }
424 for (x = 0; x < 4; x++) {
425 *to++ = 0;
426 *to++ = 0;
427 *to++ = 0;
428 if (pixelBytes == 4) {
429 *to++ = 0;
430 }
431 }
432 }
433 break;
434
435 default:
436 assert(0); /* Undefined depth */
437 break;
438
439 }
440
441 }
442 }
443 }
Impressum, Datenschutz