]>
git.zerfleddert.de Git - micropolis/blob - src/sim/g_setup.c
8cd13bacef7e24add9b82ae36fcc3aac69a11b9c
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 char gray25_bits
[] = {
93 #define gray50_width 16
94 #define gray50_height 16
95 static char gray50_bits
[] = {
115 #define gray75_width 16
116 #define gray75_height 16
117 static char gray75_bits
[] = {
136 #define vert_width 16
137 #define vert_height 16
138 static char vert_bits
[] = {
158 #define horiz_width 16
159 #define horiz_height 16
160 static char horiz_bits
[] = {
180 #define diag_width 16
181 #define diag_height 16
182 static 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
243 GetPixmaps(XDisplay
*xd
)
245 if (xd
->gray25_stipple
== None
) {
247 XCreatePixmapFromBitmapData(xd
->dpy
, xd
->root
,
248 gray25_bits
, gray25_width
, gray25_height
,
251 XCreatePixmapFromBitmapData(xd
->dpy
, xd
->root
,
252 gray50_bits
, gray50_width
, gray50_height
,
255 XCreatePixmapFromBitmapData(xd
->dpy
, xd
->root
,
256 gray75_bits
, gray75_width
, gray75_height
,
259 XCreatePixmapFromBitmapData(xd
->dpy
, xd
->root
,
260 vert_bits
, vert_width
, vert_height
,
263 XCreatePixmapFromBitmapData(xd
->dpy
, xd
->root
,
264 horiz_bits
, horiz_width
, horiz_height
,
267 XCreatePixmapFromBitmapData(xd
->dpy
, xd
->root
,
268 diag_bits
, diag_width
, diag_height
,
272 if (xd
->objects
== NULL
) {
275 xd
->objects
= pm
= (Pixmap
**)ckalloc(OBJN
* sizeof (Pixmap
*));
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);
291 GetViewTiles(SimView
*view
)
294 XpmAttributes attributes
;
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
;
301 if (view
->class == Editor_Class
) {
303 sprintf(name
, "%s/images/%s", HomeDir
,
304 view
->x
->color
? "tiles.xpm" : "tilesbw.xpm");
306 switch (view
->type
) {
309 if (view
->x
->big_tile_image
== NULL
) {
310 if (XpmReadFileToImage(view
->x
->dpy
, name
,
311 &view
->x
->big_tile_image
, NULL
,
314 "Uh oh, Micropolis couldn't read the pixmap file \"%s\".\n",
316 sim_exit(1); // Just sets tkMustExit and ExitReturn
320 view
->bigtiles
= (unsigned char *)view
->x
->big_tile_image
->data
;
324 if (view
->x
->big_tile_pixmap
== None
) {
325 if (XpmReadFileToPixmap(view
->x
->dpy
,
326 RootWindowOfScreen(view
->x
->screen
),
328 &view
->x
->big_tile_pixmap
, NULL
,
331 "Uh oh, Micropolis couldn't read the pixmap file \"%s\".\n",
333 sim_exit(1); // Just sets tkMustExit and ExitReturn
341 } else if (view
->class == Map_Class
) {
343 if (view
->x
->small_tile_image
== NULL
) {
344 if (view
->x
->color
) {
346 sprintf(name
, "%s/images/%s", HomeDir
, "tilessm.xpm");
347 if (XpmReadFileToImage(view
->x
->dpy
, name
,
348 &view
->x
->small_tile_image
, NULL
,
351 "Uh oh, Micropolis couldn't read the pixmap file \"%s\".\n",
353 sim_exit(1); // Just sets tkMustExit and ExitReturn
359 view
->x
->small_tile_image
=
360 XCreateImage(view
->x
->dpy
, view
->x
->visual
, 8,
362 0, (char *)MickGetHexa(SIM_GSMTILE
),
363 4, 3 * TILE_COUNT
, 8, 4);
369 unsigned char *from
, *to
;
370 int pixelBytes
= view
->pixel_bytes
;
372 if (pixelBytes
== 0) {
373 /* handle the case of monochrome display (8 bit map) */
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
;
382 switch (pixelBytes
) {
385 for (tile
= 0; tile
< TILE_COUNT
; tile
++) {
386 for (y
= 0; y
< 3; y
++) {
387 for (x
= 0; x
< 4; x
++) {
391 for (x
= 0; x
< 4; x
++) {
398 for (tile
= 0; tile
< TILE_COUNT
; tile
++) {
399 for (y
= 0; y
< 3; y
++) {
400 for (x
= 0; x
< 4; x
++) {
405 for (x
= 0; x
< 4; x
++) {
414 for (tile
= 0; tile
< TILE_COUNT
; tile
++) {
415 for (y
= 0; y
< 3; y
++) {
416 for (x
= 0; x
< 4; x
++) {
420 if (pixelBytes
== 4) {
425 for (x
= 0; x
< 4; x
++) {
429 if (pixelBytes
== 4) {
437 assert(0); /* Undefined depth */