]>
cvs.zerfleddert.de Git - micropolis/blob - src/sim/terrain/mapgener.c
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
63 /* Micropolis simulator code. Copyright 1988, 1989 Maxis, Will Wright */
79 static int XStart
, YStart
;
80 static int Dir
, LastDir
;
82 /* trash values for GRand() */
83 static int GRanArray
[5] = { 1018,4521,202,419,3 };
87 GRanArray
[0] = TickCount(); /* This is the only machine-specific call */
88 /* It inits GRand() w/ clockcount(long) */
90 if (!(GRand(10))) { /* 1 in 3 chance that island is generated */
94 ClearMap(); /* else make river map */
106 for (x
=0; x
<WORLD_X
; x
++)
107 for (y
=0; y
<WORLD_Y
; y
++)
117 for (x
=0; x
<WORLD_X
; x
++)
118 for (y
=0; y
<WORLD_Y
; y
++)
120 for (x
=5; x
<WORLD_X
-5; x
++)
121 for (y
=5; y
<WORLD_Y
-5; y
++)
123 for (x
=0; x
<WORLD_X
-5; x
+=2) {
125 MapY
= EGRand(RADIUS
);
127 MapY
= 90-EGRand(RADIUS
);
134 for (y
=0; y
<WORLD_Y
-5; y
+=2) {
136 MapX
= EGRand(RADIUS
);
138 MapX
= 110-EGRand(RADIUS
);
151 int Lim1
, Lim2
, t
, z
;
155 for (t
= 0; t
< Lim1
; t
++) {
159 for (z
= 0; z
< Lim2
; z
++) {
160 MapX
= x
- 6 + GRand(12);
161 MapY
= y
- 6 + GRand(12);
162 if (GRand(4)) SRivPlop();
170 XStart
= 40 + GRand(40);
171 YStart
= 33 + GRand(33);
178 int Amount
,x
,xloc
,yloc
;
180 Amount
= GRand(100)+50;
181 for (x
=0; x
<Amount
; x
++) {
184 TreeSplash(xloc
,yloc
);
190 near
TreeSplash(xloc
,yloc
)
194 register int xoff
, yoff
,z
;
199 for (z
=0; z
<Dis
; z
++) {
202 if (!(TestBounds(MapX
,MapY
))) return;
203 if (Map
[MapX
][MapY
] == 0) Map
[MapX
][MapY
] = WOODS
+ BLN
;
209 static int DX
[4] = {-1, 0, 1, 0};
210 static int DY
[4] = { 0, 1, 0,-1};
211 static int REdTab
[16] = { 13+BL
,13+BL
,17+BL
,15+BL
,5+BL
,2,19+BL
,
212 17+BL
,9+BL
,11+BL
,2,13+BL
,7+BL
,9+BL
,5+BL
,2};
213 int bitindex
, z
,Xtem
,Ytem
;
214 register int temp
,MapX
,MapY
;
216 for (MapX
= 0; MapX
< WORLD_X
; MapX
++)
217 for (MapY
= 0; MapY
< WORLD_Y
; MapY
++)
218 if (Map
[MapX
][MapY
] == REDGE
) {
220 for (z
=0; z
<4; z
++) {
221 bitindex
= bitindex
<< 1;
224 if (TestBounds(Xtem
, Ytem
))
225 if ( Map
[Xtem
][Ytem
]) bitindex
++;
227 temp
= REdTab
[bitindex
& 15];
228 if ((temp
!= 2) && (GRand(1))) temp
++;
229 Map
[MapX
][MapY
] = temp
;
235 static int DX
[4] = {-1, 0, 1, 0};
236 static int DY
[4] = { 0, 1, 0,-1};
237 static int TEdTab
[16] = {0,0,0,34,0,0,36,35,0,32,0,33,30,31,29,37};
238 int bitindex
, z
,Xtem
,Ytem
;
239 register int temp
,MapX
,MapY
;
241 for (MapX
= 0; MapX
< WORLD_X
; MapX
++)
242 for (MapY
= 0; MapY
< WORLD_Y
; MapY
++)
243 if ((Map
[MapX
][MapY
] & BLN
) == BLN
) {
245 for (z
=0; z
<4; z
++) {
246 bitindex
= bitindex
<< 1;
249 if (TestBounds(Xtem
, Ytem
))
250 if (Map
[Xtem
][Ytem
] & BN
) bitindex
++;
253 temp
= TEdTab
[bitindex
& 15];
258 Map
[MapX
][MapY
] = temp
+BLN
;
260 else Map
[MapX
][MapY
] = temp
;
272 LastDir
= LastDir
^ 4;
286 while (TestBounds (MapX
+4, MapY
+4)) {
288 if (GRand(10) > 4) Dir
++;
289 if (GRand(10) > 4) Dir
--;
290 if (!(GRand(10))) Dir
= LastDir
;
299 while (TestBounds (MapX
+3, MapY
+3)) {
301 if (GRand(10) > 5) Dir
++;
302 if (GRand(10) > 5) Dir
--;
303 if (!(GRand(12))) Dir
= LastDir
;
311 static int DirTab
[2][8] ={ { 0, 1, 1, 1, 0, -1, -1, -1},
312 {-1,-1, 0, 1, 1, 1, 0, -1} };
314 MapX
+= DirTab
[0][dir
];
315 MapY
+= DirTab
[1][dir
];
323 static int BRMatrix
[9][9] ={
332 {0,0,0,3,3,3,0,0,0} };
337 PutOnMap (BRMatrix
[y
][x
], x
, y
);
342 static int SRMatrix
[6][6] ={
353 PutOnMap (SRMatrix
[y
][x
], x
, y
);
356 near
PutOnMap (Mchar
, Xoff
, Yoff
)
357 int Mchar
, Xoff
, Yoff
;
359 register int Xloc
, Yloc
, temp
;
361 if (Mchar
== 0) return;
364 if (TestBounds (Xloc
, Yloc
) == FALSE
) return (FALSE
);
365 if (temp
= Map
[Xloc
][Yloc
]) {
368 if (Mchar
!= CHANNEL
)
370 if (temp
== CHANNEL
) return (FALSE
);
372 Map
[Xloc
][Yloc
] = Mchar
;
378 if ((( x
>= 0) && (x
< WORLD_X
)) && (( y
>= 0) && (y
< WORLD_Y
)))
392 if (z
< x
) return(z
);
396 #define RANMASK 32767
398 near
GRand(range
) /* stupid but works */
401 register x
, newv
, divisor
;
403 divisor
= RANMASK
/ (range
+1);
406 newv
+= (GRanArray
[x
] = GRanArray
[x
-1]);
408 x
= (newv
& RANMASK
) / divisor
;
409 if (x
> range
) return(range
);