]>
cvs.zerfleddert.de Git - micropolis/blob - src/sim/w_con.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
64 void _FixSingle(int x
, int y
, short *TileAdrPtr
);
65 void _FixZone(int x
, int y
, short *TileAdrPtr
);
66 int _LayDoze(int x
, int y
, short *TileAdrPtr
);
67 int _LayRoad(int x
, int y
, short *TileAdrPtr
);
68 int _LayRail(int x
, int y
, short *TileAdrPtr
);
69 int _LayWire(int x
, int y
, short *TileAdrPtr
);
72 short _RoadTable
[16] = {
79 short _RailTable
[16] = {
86 short _WireTable
[16] = {
94 #define NeutralizeRoad(Tile) \
95 if (((Tile &= LOMASK) >= 64) && \
96 ((Tile & LOMASK) <= 207)) { \
97 Tile = (Tile & 0x000F) + 64; \
101 /* comefrom: check3Border check4Border check5Border processWand */
103 ConnecTile(short x
, short y
, short *TileAdrPtr
, short Command
)
108 /* make sure the array subscripts are in bounds */
109 if (!TestBounds(x
, y
)) {
114 if ((Command
>= 2) && (Command
<= 4)) {
116 if ((autoBulldoze
!= 0) &&
118 ((Tile
= (*TileAdrPtr
)) & BULLBIT
)) {
119 NeutralizeRoad(Tile
);
120 /* Maybe this should check BULLBIT instead of checking tile values? */
121 if (((Tile
>= TINYEXP
) && (Tile
<= LASTTINYEXP
)) ||
122 ((Tile
< 64) && (Tile
!= 0))) {
131 case 0: /* Fix zone */
132 _FixZone(x
, y
, TileAdrPtr
);
135 case 1: /* Doze zone */
136 result
= _LayDoze(x
, y
, TileAdrPtr
);
137 _FixZone(x
, y
, TileAdrPtr
);
140 case 2: /* Lay Road */
141 result
= _LayRoad(x
, y
, TileAdrPtr
);
142 _FixZone(x
, y
, TileAdrPtr
);
145 case 3: /* Lay Rail */
146 result
= _LayRail(x
, y
, TileAdrPtr
);
147 _FixZone(x
, y
, TileAdrPtr
);
150 case 4: /* Lay Wire */
151 result
= _LayWire(x
, y
, TileAdrPtr
);
152 _FixZone(x
, y
, TileAdrPtr
);
160 /* comefrom: ConnecTile */
162 _LayDoze(int x
, int y
, short *TileAdrPtr
)
167 return -2; /* no mas dinero. */
170 Tile
= (*TileAdrPtr
);
172 if (!(Tile
& BULLBIT
)) {
173 return 0; /* Check dozeable bit. */
176 NeutralizeRoad(Tile
);
194 case VRAIL
: /* Dozing over water, replace with water. */
195 (*TileAdrPtr
) = RIVER
;
198 default: /* Dozing on land, replace with land. Simple, eh? */
199 (*TileAdrPtr
) = DIRT
;
203 Spend(1); /* Costs $1.00....*/
208 /* comefrom: ConnecTile */
210 _LayRoad(int x
, int y
, short *TileAdrPtr
)
215 if (TotalFunds
< 10) {
219 Tile
= (*TileAdrPtr
) & LOMASK
;
224 (*TileAdrPtr
) = ROADS
| BULLBIT
| BURNBIT
;
227 case RIVER
: /* Road on Water */
229 case CHANNEL
: /* Check how to build bridges, if possible. */
230 if (TotalFunds
< 50) {
236 if (x
< (WORLD_X
- 1)) {
237 Tile
= TileAdrPtr
[WORLD_Y
];
238 NeutralizeRoad(Tile
);
239 if ((Tile
== VRAILROAD
) ||
242 (Tile
<= HROADPOWER
))) {
243 (*TileAdrPtr
) = HBRIDGE
| BULLBIT
;
249 Tile
= TileAdrPtr
[-WORLD_Y
];
250 NeutralizeRoad(Tile
);
251 if ((Tile
== VRAILROAD
) ||
254 (Tile
<= INTERSECTION
))) {
255 (*TileAdrPtr
) = HBRIDGE
| BULLBIT
;
260 if (y
< (WORLD_Y
- 1)) {
261 Tile
= TileAdrPtr
[1];
262 NeutralizeRoad(Tile
);
263 if ((Tile
== HRAILROAD
) ||
264 (Tile
== VROADPOWER
) ||
265 ((Tile
>= VBRIDGE
) &&
266 (Tile
<= INTERSECTION
))) {
267 (*TileAdrPtr
) = VBRIDGE
| BULLBIT
;
273 Tile
= TileAdrPtr
[-1];
274 NeutralizeRoad(Tile
);
275 if ((Tile
== HRAILROAD
) ||
276 (Tile
== VROADPOWER
) ||
277 ((Tile
>= VBRIDGE
) &&
278 (Tile
<= INTERSECTION
))) {
279 (*TileAdrPtr
) = VBRIDGE
| BULLBIT
;
284 /* Can't do road... */
287 case LHPOWER
: /* Road on power */
288 (*TileAdrPtr
) = VROADPOWER
| CONDBIT
| BURNBIT
| BULLBIT
;
291 case LVPOWER
: /* Road on power #2 */
292 (*TileAdrPtr
) = HROADPOWER
| CONDBIT
| BURNBIT
| BULLBIT
;
295 case LHRAIL
: /* Road on rail */
296 (*TileAdrPtr
) = HRAILROAD
| BURNBIT
| BULLBIT
;
299 case LVRAIL
: /* Road on rail #2 */
300 (*TileAdrPtr
) = VRAILROAD
| BURNBIT
| BULLBIT
;
303 default: /* Can't do road */
314 /* comefrom: ConnecTile */
316 _LayRail(int x
, int y
, short *TileAdrPtr
)
321 if (TotalFunds
< 20) {
325 Tile
= (*TileAdrPtr
) & LOMASK
;
326 NeutralizeRoad(Tile
);
329 case 0: /* Rail on Dirt */
330 (*TileAdrPtr
) = 226 | BULLBIT
| BURNBIT
;
333 case 2: /* Rail on Water */
335 case 4: /* Check how to build underwater tunnel, if possible. */
336 if (TotalFunds
< 100) {
341 if (x
< (WORLD_X
- 1)) {
342 Tile
= TileAdrPtr
[WORLD_Y
];
343 NeutralizeRoad(Tile
);
344 if ((Tile
== 221) || (Tile
== 224) || ((Tile
>= 226) && (Tile
<= 237))) {
345 (*TileAdrPtr
) = 224 | BULLBIT
;
351 Tile
= TileAdrPtr
[-WORLD_Y
];
352 NeutralizeRoad(Tile
);
353 if ((Tile
== 221) || (Tile
== 224) || ((Tile
> 225) && (Tile
< 238))) {
354 (*TileAdrPtr
) = 224 | BULLBIT
;
359 if (y
< (WORLD_Y
- 1)) {
360 Tile
= TileAdrPtr
[1];
361 NeutralizeRoad(Tile
);
362 if ((Tile
== 222) || (Tile
== 238) || ((Tile
> 224) && (Tile
< 237))) {
363 (*TileAdrPtr
) = 225 | BULLBIT
;
369 Tile
= TileAdrPtr
[-1];
370 NeutralizeRoad(Tile
);
371 if ((Tile
== 222) || (Tile
== 238) || ((Tile
> 224) && (Tile
< 237))) {
372 (*TileAdrPtr
) = 225 | BULLBIT
;
377 /* Can't do rail... */
380 case 210: /* Rail on power */
381 (*TileAdrPtr
) = 222 | CONDBIT
| BURNBIT
| BULLBIT
;
384 case 211: /* Rail on power #2 */
385 (*TileAdrPtr
) = 221 | CONDBIT
| BURNBIT
| BULLBIT
;
388 case 66: /* Rail on road */
389 (*TileAdrPtr
) = 238 | BURNBIT
| BULLBIT
;
392 case 67: /* Rail on road #2 */
393 (*TileAdrPtr
) = 237 | BURNBIT
| BULLBIT
;
396 default: /* Can't do rail */
405 /* comefrom: ConnecTile */
407 _LayWire(int x
, int y
, short *TileAdrPtr
)
412 if (TotalFunds
< 5) {
416 Tile
= (*TileAdrPtr
) & LOMASK
;
417 NeutralizeRoad(Tile
);
420 case 0: /* Wire on Dirt */
421 (*TileAdrPtr
) = 210 | CONDBIT
| BURNBIT
| BULLBIT
;
424 case 2: /* Wire on Water */
426 case 4: /* Check how to lay underwater wire, if possible. */
431 if (x
< (WORLD_X
- 1)) {
432 Tile
= TileAdrPtr
[WORLD_Y
];
433 if (Tile
& CONDBIT
) {
434 NeutralizeRoad(Tile
);
435 if ((Tile
!= 77) && (Tile
!= 221) && (Tile
!= 208)) {
436 (*TileAdrPtr
) = 209 | CONDBIT
| BULLBIT
;
443 Tile
= TileAdrPtr
[-WORLD_Y
];
444 if (Tile
& CONDBIT
) {
445 NeutralizeRoad(Tile
);
446 if ((Tile
!= 77) && (Tile
!= 221) && (Tile
!= 208)) {
447 (*TileAdrPtr
) = 209 | CONDBIT
| BULLBIT
;
453 if (y
< (WORLD_Y
- 1)) {
454 Tile
= TileAdrPtr
[1];
455 if (Tile
& CONDBIT
) {
456 NeutralizeRoad(Tile
);
457 if ((Tile
!= 78) && (Tile
!= 222) && (Tile
!= 209)) {
458 (*TileAdrPtr
) = 208 | CONDBIT
| BULLBIT
;
465 Tile
= TileAdrPtr
[-1];
466 if (Tile
& CONDBIT
) {
467 NeutralizeRoad(Tile
);
468 if ((Tile
!= 78) && (Tile
!= 222) && (Tile
!= 209)) {
469 (*TileAdrPtr
) = 208 | CONDBIT
| BULLBIT
;
475 /* Can't do wire... */
478 case 66: /* Wire on Road */
479 (*TileAdrPtr
) = 77 | CONDBIT
| BURNBIT
| BULLBIT
;
482 case 67: /* Wire on Road #2 */
483 (*TileAdrPtr
) = 78 | CONDBIT
| BURNBIT
| BULLBIT
;
486 case 226: /* Wire on rail */
487 (*TileAdrPtr
) = 221 | CONDBIT
| BURNBIT
| BULLBIT
;
490 case 227: /* Wire on rail #2 */
491 (*TileAdrPtr
) = 222 | CONDBIT
| BURNBIT
| BULLBIT
;
494 default: /* Can't do wire */
503 /* comefrom: ConnecTile */
505 _FixZone(int x
, int y
, short *TileAdrPtr
)
507 _FixSingle(x
,y
, &TileAdrPtr
[0]);
510 _FixSingle(x
, y
-1, &TileAdrPtr
[-1]);
513 if (x
< (WORLD_X
- 1)) {
514 _FixSingle(x
+1, y
, &TileAdrPtr
[WORLD_Y
]);
517 if (y
< (WORLD_Y
- 1)) {
518 _FixSingle(x
, y
+1, &TileAdrPtr
[1]);
522 _FixSingle(x
-1, y
, &TileAdrPtr
[-WORLD_Y
]);
528 /* comefrom: _FixZone */
530 _FixSingle(int x
, int y
, short *TileAdrPtr
)
535 Tile
= (*TileAdrPtr
) & LOMASK
;
536 NeutralizeRoad(Tile
);
537 if ((Tile
>= 66) && (Tile
<= 76)) { /* Cleanup Road */
540 Tile
= TileAdrPtr
[-1];
541 NeutralizeRoad(Tile
);
542 if (((Tile
== 237) || ((Tile
>= 64) && (Tile
<= 78))) &&
543 (Tile
!= 77) && (Tile
!= 238) && (Tile
!= 64))
547 if (x
< (WORLD_X
- 1)) {
548 Tile
= TileAdrPtr
[WORLD_Y
];
549 NeutralizeRoad(Tile
);
550 if (((Tile
== 238) || ((Tile
>= 64) && (Tile
<= 78))) &&
551 (Tile
!= 78) && (Tile
!= 237) && (Tile
!= 65))
555 if (y
< (WORLD_Y
- 1)) {
556 Tile
= TileAdrPtr
[1];
557 NeutralizeRoad(Tile
);
558 if (((Tile
== 237) || ((Tile
>= 64) && (Tile
<= 78))) &&
559 (Tile
!= 77) && (Tile
!= 238) && (Tile
!= 64))
564 Tile
= TileAdrPtr
[-WORLD_Y
];
565 NeutralizeRoad(Tile
);
566 if (((Tile
== 238) || ((Tile
>= 64) && (Tile
<= 78))) &&
567 (Tile
!= 78) && (Tile
!= 237) && (Tile
!= 65))
571 (*TileAdrPtr
) = _RoadTable
[adjTile
] | BULLBIT
| BURNBIT
;
575 if ((Tile
>= 226) && (Tile
<= 236)) { /* Cleanup Rail */
578 Tile
= TileAdrPtr
[-1];
579 NeutralizeRoad(Tile
);
580 if ((Tile
>= 221) && (Tile
<= 238) &&
581 (Tile
!= 221) && (Tile
!= 237) && (Tile
!= 224))
585 if (x
< (WORLD_X
- 1)) {
586 Tile
= TileAdrPtr
[WORLD_Y
];
587 NeutralizeRoad(Tile
);
588 if ((Tile
>= 221) && (Tile
<= 238) &&
589 (Tile
!= 222) && (Tile
!= 238) && (Tile
!= 225))
593 if (y
< (WORLD_Y
- 1)) {
594 Tile
= TileAdrPtr
[1];
595 NeutralizeRoad(Tile
);
596 if ((Tile
>= 221) && (Tile
<= 238) &&
597 (Tile
!= 221) && (Tile
!= 237) && (Tile
!= 224))
602 Tile
= TileAdrPtr
[-WORLD_Y
];
603 NeutralizeRoad(Tile
);
604 if ((Tile
>= 221) && (Tile
<= 238) &&
605 (Tile
!= 222) && (Tile
!= 238) && (Tile
!= 225))
609 (*TileAdrPtr
) = _RailTable
[adjTile
] | BULLBIT
| BURNBIT
;
613 if ((Tile
>= 210) && (Tile
<= 220)) { /* Cleanup Wire */
616 Tile
= TileAdrPtr
[-1];
617 if (Tile
& CONDBIT
) {
618 NeutralizeRoad(Tile
);
619 if ((Tile
!= 209) && (Tile
!= 78) && (Tile
!= 222))
624 if (x
< (WORLD_X
- 1)) {
625 Tile
= TileAdrPtr
[WORLD_Y
];
626 if (Tile
& CONDBIT
) {
627 NeutralizeRoad(Tile
);
628 if ((Tile
!= 208) && (Tile
!= 77) && (Tile
!= 221))
633 if (y
< (WORLD_Y
- 1)) {
634 Tile
= TileAdrPtr
[1];
635 if (Tile
& CONDBIT
) {
636 NeutralizeRoad(Tile
);
637 if ((Tile
!= 209) && (Tile
!= 78) && (Tile
!= 222))
643 Tile
= TileAdrPtr
[-WORLD_Y
];
644 if (Tile
& CONDBIT
) {
645 NeutralizeRoad(Tile
);
646 if ((Tile
!= 208) && (Tile
!= 77) && (Tile
!= 221))
651 (*TileAdrPtr
) = _WireTable
[adjTile
] | BULLBIT
| BURNBIT
| CONDBIT
;