]>
git.zerfleddert.de Git - micropolis/blob - src/sim/g_setup.c
61204fe81b9f0b1670a6772797d8da541097a8e4
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.
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.
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/>.
21 * ADDITIONAL TERMS per GNU GPL Section 7
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.
29 * Any propagation or conveyance of this program must include this
30 * copyright notice and these terms.
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.
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.
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
65 #define SIM_SMTILE 385
66 #define SIM_BWTILE 386
67 #define SIM_GSMTILE 388
68 #define SIM_LGTILE 544
71 #define gray25_width 16
72 #define gray25_height 16
73 static unsigned char gray25_bits
[] = {
93 #define gray50_width 16
94 #define gray50_height 16
95 static unsigned char gray50_bits
[] = {
115 #define gray75_width 16
116 #define gray75_height 16
117 static unsigned char gray75_bits
[] = {
136 #define vert_width 16
137 #define vert_height 16
138 static unsigned char vert_bits
[] = {
158 #define horiz_width 16
159 #define horiz_height 16
160 static unsigned char horiz_bits
[] = {
180 #define diag_width 16
181 #define diag_height 16
182 static unsigned char diag_bits
[] = {
202 Ptr
MickGetHexa(short theID
)
206 theData
= GetResource("hexa", theID
);
207 return ((Ptr
)*theData
);
212 GetObjectXpms(XDisplay
*xd
, int id
, int frames
)
215 Pixmap
*pixmaps
= (Pixmap
*)ckalloc(2 * frames
* sizeof (Pixmap
));
216 XpmAttributes attributes
;
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
;
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
),
229 &pixmaps
[i
+ i
], &pixmaps
[i
+ i
+ 1],
232 "Uh oh, Micropolis couldn't read the pixmap file \"%s\".\n",
234 sim_exit(1); // Just sets tkMustExit and ExitReturn
242 GetPixmaps(XDisplay
*xd
)
244 if (xd
->gray25_stipple
== None
) {
246 XCreatePixmapFromBitmapData(xd
->dpy
, xd
->root
,
247 gray25_bits
, gray25_width
, gray25_height
,
250 XCreatePixmapFromBitmapData(xd
->dpy
, xd
->root
,
251 gray50_bits
, gray50_width
, gray50_height
,
254 XCreatePixmapFromBitmapData(xd
->dpy
, xd
->root
,
255 gray75_bits
, gray75_width
, gray75_height
,
258 XCreatePixmapFromBitmapData(xd
->dpy
, xd
->root
,
259 vert_bits
, vert_width
, vert_height
,
262 XCreatePixmapFromBitmapData(xd
->dpy
, xd
->root
,
263 horiz_bits
, horiz_width
, horiz_height
,
266 XCreatePixmapFromBitmapData(xd
->dpy
, xd
->root
,
267 diag_bits
, diag_width
, diag_height
,
271 if (xd
->objects
== NULL
) {
274 xd
->objects
= pm
= (Pixmap
**)ckalloc(OBJN
* sizeof (Pixmap
*));
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);
289 GetViewTiles(SimView
*view
)
292 XpmAttributes attributes
;
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
;
299 if (view
->class == Editor_Class
) {
301 sprintf(name
, "%s/images/%s", HomeDir
,
302 view
->x
->color
? "tiles.xpm" : "tilesbw.xpm");
304 switch (view
->type
) {
307 if (view
->x
->big_tile_image
== NULL
) {
308 if (XpmReadFileToImage(view
->x
->dpy
, name
,
309 &view
->x
->big_tile_image
, NULL
,
312 "Uh oh, Micropolis couldn't read the pixmap file \"%s\".\n",
314 sim_exit(1); // Just sets tkMustExit and ExitReturn
318 view
->bigtiles
= (unsigned char *)view
->x
->big_tile_image
->data
;
322 if (view
->x
->big_tile_pixmap
== None
) {
323 if (XpmReadFileToPixmap(view
->x
->dpy
,
324 RootWindowOfScreen(view
->x
->screen
),
326 &view
->x
->big_tile_pixmap
, NULL
,
329 "Uh oh, Micropolis couldn't read the pixmap file \"%s\".\n",
331 sim_exit(1); // Just sets tkMustExit and ExitReturn
339 } else if (view
->class == Map_Class
) {
341 if (view
->x
->small_tile_image
== NULL
) {
342 if (view
->x
->color
) {
344 sprintf(name
, "%s/images/%s", HomeDir
, "tilessm.xpm");
345 if (XpmReadFileToImage(view
->x
->dpy
, name
,
346 &view
->x
->small_tile_image
, NULL
,
349 "Uh oh, Micropolis couldn't read the pixmap file \"%s\".\n",
351 sim_exit(1); // Just sets tkMustExit and ExitReturn
357 view
->x
->small_tile_image
=
358 XCreateImage(view
->x
->dpy
, view
->x
->visual
, 8,
360 0, (char *)MickGetHexa(SIM_GSMTILE
),
361 4, 3 * TILE_COUNT
, 8, 4);
367 unsigned char *from
, *to
;
368 int pixelBytes
= view
->pixel_bytes
;
369 int rowBytes
= view
->x
->small_tile_image
->bytes_per_line
;
371 if (pixelBytes
== 0) {
372 /* handle the case of monochrome display (8 bit map) */
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
;
381 switch (pixelBytes
) {
384 for (tile
= 0; tile
< TILE_COUNT
; tile
++) {
385 for (y
= 0; y
< 3; y
++) {
386 for (x
= 0; x
< 4; x
++) {
390 for (x
= 0; x
< 4; x
++) {
397 for (tile
= 0; tile
< TILE_COUNT
; tile
++) {
398 for (y
= 0; y
< 3; y
++) {
399 for (x
= 0; x
< 4; x
++) {
404 for (x
= 0; x
< 4; x
++) {
413 for (tile
= 0; tile
< TILE_COUNT
; tile
++) {
414 for (y
= 0; y
< 3; y
++) {
415 for (x
= 0; x
< 4; x
++) {
419 if (pixelBytes
== 4) {
424 for (x
= 0; x
< 4; x
++) {
428 if (pixelBytes
== 4) {
436 assert(0); /* Undefined depth */