]>
git.zerfleddert.de Git - micropolis/blob - src/sim/w_con.c
0d20c9a55ffe23dbd5c988e724c14195d13d505e
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 short _RoadTable
[16] = {
72 short _RailTable
[16] = {
79 short _WireTable
[16] = {
87 #define NeutralizeRoad(Tile) \
88 if (((Tile &= LOMASK) >= 64) && \
89 ((Tile & LOMASK) <= 207)) { \
90 Tile = (Tile & 0x000F) + 64; \
94 /* comefrom: check3Border check4Border check5Border processWand */
96 ConnecTile(short x
, short y
, short *TileAdrPtr
, short Command
)
101 /* make sure the array subscripts are in bounds */
102 if (!TestBounds(x
, y
)) {
107 if ((Command
>= 2) && (Command
<= 4)) {
109 if ((autoBulldoze
!= 0) &&
111 ((Tile
= (*TileAdrPtr
)) & BULLBIT
)) {
112 NeutralizeRoad(Tile
);
113 /* Maybe this should check BULLBIT instead of checking tile values? */
114 if (((Tile
>= TINYEXP
) && (Tile
<= LASTTINYEXP
)) ||
115 ((Tile
< 64) && (Tile
!= 0))) {
124 case 0: /* Fix zone */
125 _FixZone(x
, y
, TileAdrPtr
);
128 case 1: /* Doze zone */
129 result
= _LayDoze(x
, y
, TileAdrPtr
);
130 _FixZone(x
, y
, TileAdrPtr
);
133 case 2: /* Lay Road */
134 result
= _LayRoad(x
, y
, TileAdrPtr
);
135 _FixZone(x
, y
, TileAdrPtr
);
138 case 3: /* Lay Rail */
139 result
= _LayRail(x
, y
, TileAdrPtr
);
140 _FixZone(x
, y
, TileAdrPtr
);
143 case 4: /* Lay Wire */
144 result
= _LayWire(x
, y
, TileAdrPtr
);
145 _FixZone(x
, y
, TileAdrPtr
);
153 /* comefrom: ConnecTile */
155 _LayDoze(int x
, int y
, short *TileAdrPtr
)
160 return -2; /* no mas dinero. */
163 Tile
= (*TileAdrPtr
);
165 if (!(Tile
& BULLBIT
)) {
166 return 0; /* Check dozeable bit. */
169 NeutralizeRoad(Tile
);
187 case VRAIL
: /* Dozing over water, replace with water. */
188 (*TileAdrPtr
) = RIVER
;
191 default: /* Dozing on land, replace with land. Simple, eh? */
192 (*TileAdrPtr
) = DIRT
;
196 Spend(1); /* Costs $1.00....*/
201 /* comefrom: ConnecTile */
203 _LayRoad(int x
, int y
, short *TileAdrPtr
)
208 if (TotalFunds
< 10) {
212 Tile
= (*TileAdrPtr
) & LOMASK
;
217 (*TileAdrPtr
) = ROADS
| BULLBIT
| BURNBIT
;
220 case RIVER
: /* Road on Water */
222 case CHANNEL
: /* Check how to build bridges, if possible. */
223 if (TotalFunds
< 50) {
229 if (x
< (WORLD_X
- 1)) {
230 Tile
= TileAdrPtr
[WORLD_Y
];
231 NeutralizeRoad(Tile
);
232 if ((Tile
== VRAILROAD
) ||
235 (Tile
<= HROADPOWER
))) {
236 (*TileAdrPtr
) = HBRIDGE
| BULLBIT
;
242 Tile
= TileAdrPtr
[-WORLD_Y
];
243 NeutralizeRoad(Tile
);
244 if ((Tile
== VRAILROAD
) ||
247 (Tile
<= INTERSECTION
))) {
248 (*TileAdrPtr
) = HBRIDGE
| BULLBIT
;
253 if (y
< (WORLD_Y
- 1)) {
254 Tile
= TileAdrPtr
[1];
255 NeutralizeRoad(Tile
);
256 if ((Tile
== HRAILROAD
) ||
257 (Tile
== VROADPOWER
) ||
258 ((Tile
>= VBRIDGE
) &&
259 (Tile
<= INTERSECTION
))) {
260 (*TileAdrPtr
) = VBRIDGE
| BULLBIT
;
266 Tile
= TileAdrPtr
[-1];
267 NeutralizeRoad(Tile
);
268 if ((Tile
== HRAILROAD
) ||
269 (Tile
== VROADPOWER
) ||
270 ((Tile
>= VBRIDGE
) &&
271 (Tile
<= INTERSECTION
))) {
272 (*TileAdrPtr
) = VBRIDGE
| BULLBIT
;
277 /* Can't do road... */
280 case LHPOWER
: /* Road on power */
281 (*TileAdrPtr
) = VROADPOWER
| CONDBIT
| BURNBIT
| BULLBIT
;
284 case LVPOWER
: /* Road on power #2 */
285 (*TileAdrPtr
) = HROADPOWER
| CONDBIT
| BURNBIT
| BULLBIT
;
288 case LHRAIL
: /* Road on rail */
289 (*TileAdrPtr
) = HRAILROAD
| BURNBIT
| BULLBIT
;
292 case LVRAIL
: /* Road on rail #2 */
293 (*TileAdrPtr
) = VRAILROAD
| BURNBIT
| BULLBIT
;
296 default: /* Can't do road */
307 /* comefrom: ConnecTile */
309 _LayRail(int x
, int y
, short *TileAdrPtr
)
314 if (TotalFunds
< 20) {
318 Tile
= (*TileAdrPtr
) & LOMASK
;
319 NeutralizeRoad(Tile
);
322 case 0: /* Rail on Dirt */
323 (*TileAdrPtr
) = 226 | BULLBIT
| BURNBIT
;
326 case 2: /* Rail on Water */
328 case 4: /* Check how to build underwater tunnel, if possible. */
329 if (TotalFunds
< 100) {
334 if (x
< (WORLD_X
- 1)) {
335 Tile
= TileAdrPtr
[WORLD_Y
];
336 NeutralizeRoad(Tile
);
337 if ((Tile
== 221) || (Tile
== 224) || ((Tile
>= 226) && (Tile
<= 237))) {
338 (*TileAdrPtr
) = 224 | BULLBIT
;
344 Tile
= TileAdrPtr
[-WORLD_Y
];
345 NeutralizeRoad(Tile
);
346 if ((Tile
== 221) || (Tile
== 224) || ((Tile
> 225) && (Tile
< 238))) {
347 (*TileAdrPtr
) = 224 | BULLBIT
;
352 if (y
< (WORLD_Y
- 1)) {
353 Tile
= TileAdrPtr
[1];
354 NeutralizeRoad(Tile
);
355 if ((Tile
== 222) || (Tile
== 238) || ((Tile
> 224) && (Tile
< 237))) {
356 (*TileAdrPtr
) = 225 | BULLBIT
;
362 Tile
= TileAdrPtr
[-1];
363 NeutralizeRoad(Tile
);
364 if ((Tile
== 222) || (Tile
== 238) || ((Tile
> 224) && (Tile
< 237))) {
365 (*TileAdrPtr
) = 225 | BULLBIT
;
370 /* Can't do rail... */
373 case 210: /* Rail on power */
374 (*TileAdrPtr
) = 222 | CONDBIT
| BURNBIT
| BULLBIT
;
377 case 211: /* Rail on power #2 */
378 (*TileAdrPtr
) = 221 | CONDBIT
| BURNBIT
| BULLBIT
;
381 case 66: /* Rail on road */
382 (*TileAdrPtr
) = 238 | BURNBIT
| BULLBIT
;
385 case 67: /* Rail on road #2 */
386 (*TileAdrPtr
) = 237 | BURNBIT
| BULLBIT
;
389 default: /* Can't do rail */
398 /* comefrom: ConnecTile */
400 _LayWire(int x
, int y
, short *TileAdrPtr
)
405 if (TotalFunds
< 5) {
409 Tile
= (*TileAdrPtr
) & LOMASK
;
410 NeutralizeRoad(Tile
);
413 case 0: /* Wire on Dirt */
414 (*TileAdrPtr
) = 210 | CONDBIT
| BURNBIT
| BULLBIT
;
417 case 2: /* Wire on Water */
419 case 4: /* Check how to lay underwater wire, if possible. */
424 if (x
< (WORLD_X
- 1)) {
425 Tile
= TileAdrPtr
[WORLD_Y
];
426 if (Tile
& CONDBIT
) {
427 NeutralizeRoad(Tile
);
428 if ((Tile
!= 77) && (Tile
!= 221) && (Tile
!= 208)) {
429 (*TileAdrPtr
) = 209 | CONDBIT
| BULLBIT
;
436 Tile
= TileAdrPtr
[-WORLD_Y
];
437 if (Tile
& CONDBIT
) {
438 NeutralizeRoad(Tile
);
439 if ((Tile
!= 77) && (Tile
!= 221) && (Tile
!= 208)) {
440 (*TileAdrPtr
) = 209 | CONDBIT
| BULLBIT
;
446 if (y
< (WORLD_Y
- 1)) {
447 Tile
= TileAdrPtr
[1];
448 if (Tile
& CONDBIT
) {
449 NeutralizeRoad(Tile
);
450 if ((Tile
!= 78) && (Tile
!= 222) && (Tile
!= 209)) {
451 (*TileAdrPtr
) = 208 | CONDBIT
| BULLBIT
;
458 Tile
= TileAdrPtr
[-1];
459 if (Tile
& CONDBIT
) {
460 NeutralizeRoad(Tile
);
461 if ((Tile
!= 78) && (Tile
!= 222) && (Tile
!= 209)) {
462 (*TileAdrPtr
) = 208 | CONDBIT
| BULLBIT
;
468 /* Can't do wire... */
471 case 66: /* Wire on Road */
472 (*TileAdrPtr
) = 77 | CONDBIT
| BURNBIT
| BULLBIT
;
475 case 67: /* Wire on Road #2 */
476 (*TileAdrPtr
) = 78 | CONDBIT
| BURNBIT
| BULLBIT
;
479 case 226: /* Wire on rail */
480 (*TileAdrPtr
) = 221 | CONDBIT
| BURNBIT
| BULLBIT
;
483 case 227: /* Wire on rail #2 */
484 (*TileAdrPtr
) = 222 | CONDBIT
| BURNBIT
| BULLBIT
;
487 default: /* Can't do wire */
496 /* comefrom: ConnecTile */
497 _FixZone(int x
, int y
, short *TileAdrPtr
)
499 _FixSingle(x
,y
, &TileAdrPtr
[0]);
502 _FixSingle(x
, y
-1, &TileAdrPtr
[-1]);
505 if (x
< (WORLD_X
- 1)) {
506 _FixSingle(x
+1, y
, &TileAdrPtr
[WORLD_Y
]);
509 if (y
< (WORLD_Y
- 1)) {
510 _FixSingle(x
, y
+1, &TileAdrPtr
[1]);
514 _FixSingle(x
-1, y
, &TileAdrPtr
[-WORLD_Y
]);
520 /* comefrom: _FixZone */
521 _FixSingle(int x
, int y
, short *TileAdrPtr
)
526 Tile
= (*TileAdrPtr
) & LOMASK
;
527 NeutralizeRoad(Tile
);
528 if ((Tile
>= 66) && (Tile
<= 76)) { /* Cleanup Road */
531 Tile
= TileAdrPtr
[-1];
532 NeutralizeRoad(Tile
);
533 if (((Tile
== 237) || ((Tile
>= 64) && (Tile
<= 78))) &&
534 (Tile
!= 77) && (Tile
!= 238) && (Tile
!= 64))
538 if (x
< (WORLD_X
- 1)) {
539 Tile
= TileAdrPtr
[WORLD_Y
];
540 NeutralizeRoad(Tile
);
541 if (((Tile
== 238) || ((Tile
>= 64) && (Tile
<= 78))) &&
542 (Tile
!= 78) && (Tile
!= 237) && (Tile
!= 65))
546 if (y
< (WORLD_Y
- 1)) {
547 Tile
= TileAdrPtr
[1];
548 NeutralizeRoad(Tile
);
549 if (((Tile
== 237) || ((Tile
>= 64) && (Tile
<= 78))) &&
550 (Tile
!= 77) && (Tile
!= 238) && (Tile
!= 64))
555 Tile
= TileAdrPtr
[-WORLD_Y
];
556 NeutralizeRoad(Tile
);
557 if (((Tile
== 238) || ((Tile
>= 64) && (Tile
<= 78))) &&
558 (Tile
!= 78) && (Tile
!= 237) && (Tile
!= 65))
562 (*TileAdrPtr
) = _RoadTable
[adjTile
] | BULLBIT
| BURNBIT
;
566 if ((Tile
>= 226) && (Tile
<= 236)) { /* Cleanup Rail */
569 Tile
= TileAdrPtr
[-1];
570 NeutralizeRoad(Tile
);
571 if ((Tile
>= 221) && (Tile
<= 238) &&
572 (Tile
!= 221) && (Tile
!= 237) && (Tile
!= 224))
576 if (x
< (WORLD_X
- 1)) {
577 Tile
= TileAdrPtr
[WORLD_Y
];
578 NeutralizeRoad(Tile
);
579 if ((Tile
>= 221) && (Tile
<= 238) &&
580 (Tile
!= 222) && (Tile
!= 238) && (Tile
!= 225))
584 if (y
< (WORLD_Y
- 1)) {
585 Tile
= TileAdrPtr
[1];
586 NeutralizeRoad(Tile
);
587 if ((Tile
>= 221) && (Tile
<= 238) &&
588 (Tile
!= 221) && (Tile
!= 237) && (Tile
!= 224))
593 Tile
= TileAdrPtr
[-WORLD_Y
];
594 NeutralizeRoad(Tile
);
595 if ((Tile
>= 221) && (Tile
<= 238) &&
596 (Tile
!= 222) && (Tile
!= 238) && (Tile
!= 225))
600 (*TileAdrPtr
) = _RailTable
[adjTile
] | BULLBIT
| BURNBIT
;
604 if ((Tile
>= 210) && (Tile
<= 220)) { /* Cleanup Wire */
607 Tile
= TileAdrPtr
[-1];
608 if (Tile
& CONDBIT
) {
609 NeutralizeRoad(Tile
);
610 if ((Tile
!= 209) && (Tile
!= 78) && (Tile
!= 222))
615 if (x
< (WORLD_X
- 1)) {
616 Tile
= TileAdrPtr
[WORLD_Y
];
617 if (Tile
& CONDBIT
) {
618 NeutralizeRoad(Tile
);
619 if ((Tile
!= 208) && (Tile
!= 77) && (Tile
!= 221))
624 if (y
< (WORLD_Y
- 1)) {
625 Tile
= TileAdrPtr
[1];
626 if (Tile
& CONDBIT
) {
627 NeutralizeRoad(Tile
);
628 if ((Tile
!= 209) && (Tile
!= 78) && (Tile
!= 222))
634 Tile
= TileAdrPtr
[-WORLD_Y
];
635 if (Tile
& CONDBIT
) {
636 NeutralizeRoad(Tile
);
637 if ((Tile
!= 208) && (Tile
!= 77) && (Tile
!= 221))
642 (*TileAdrPtr
) = _WireTable
[adjTile
] | BULLBIT
| BURNBIT
| CONDBIT
;