]> 4ch.mooo.com Git - 16.git/blob - 16/roads/INITW.C
16_ca needs huge amounts of work and I should remember what needs to be done soon...
[16.git] / 16 / roads / INITW.C
1 #define INITW_C\r
2 \r
3 #include <stdlib.h>\r
4 #include <time.h>\r
5 #include "roads.h"\r
6 #include "tiles.h"\r
7 \r
8 extern int view_x, view_y;   /* VIEW AREA (UPPER LEFT CORNER) */\r
9 extern int viewpage;         /* CURRENTLY VIEWED PAGE */\r
10 extern int startup_vmode;    /* VIDEO MODE STARTUP SETTINGS, -1 IF NOT INIT */\r
11 \r
12 int far *topography;      /* BACKGROUND TILE LIST (ARRAY) */\r
13 int far *terrain;      /* FOREGROUND TILE LIST (ARRAY) */\r
14 int world_type=75;      /* TENDENCY TO GRASS */\r
15 int edgemode=1;         /* BLOCKY GRASS/DIRT OR EDGED? */\r
16 extern int frogmode;\r
17 \r
18 /*\r
19  *\r
20  * Loads the world foreground tile list with roads.\r
21  *\r
22  */\r
23 void init_foreground(void)\r
24 {\r
25     register int x, tile, fails;\r
26 \r
27         /* INITIALIZE FOREGROUND */\r
28     for (x=0; x<WORLD_TILES_TOTAL; x++)\r
29         terrain[x]=EMPTY_TILE; /* FILL WITH EMPTY TILES */\r
30 \r
31     create_roads (); /* LAY DOWN SOME ROADS */\r
32 \r
33         /* ADD RANDOM TERRAIN */\r
34     for (x=0; x<random(MAX_TERRAIN-MIN_TERRAIN)+MIN_TERRAIN; x++)\r
35     {\r
36         fails=0;\r
37 \r
38             /* ATTEMPT TO PLACE TERRAIN -- QUIT ON EXCESSIVE FAILURE */\r
39         do {\r
40             tile=random(WORLD_TILES_TOTAL);\r
41             fails++;\r
42         } while (terrain[tile]!=EMPTY_TILE && fails<MAX_FAILS);\r
43 \r
44         if (fails<MAX_FAILS)\r
45         {\r
46             switch (random(12)+1)\r
47             {\r
48                 case 1: terrain[tile]=OBJ_SIGN;     break;\r
49                 case 2: terrain[tile]=OBJ_FIRST_GEM+random(OBJ_TOTAL_GEM); break;\r
50                 case 3: terrain[tile]=ANM_URANIUM;  break;\r
51                 case 4:\r
52                 case 5: terrain[tile]=ANM_FIRE;     break;\r
53                 case 6: if (random(100)<50) terrain[tile]=ANM_WATER1;\r
54                         else terrain[tile]=ANM_WATER2;  break;\r
55                 case 7: terrain[tile]=OBJ_ROCK1;    break;\r
56                 case 8: terrain[tile]=OBJ_ROCK2;    break;\r
57                 case 9: terrain[tile]=OBJ_ROCK3;    break;\r
58                 case 10:\r
59                 case 11:\r
60                 case 12: terrain[tile]=OBJ_BUSHES;  break;\r
61             }\r
62         }\r
63 \r
64         else break;\r
65     }\r
66 \r
67     frogmode=3;\r
68 }\r
69 \r
70 /*\r
71  *\r
72  * Loads the world background tile list with grassy tiles.\r
73  *\r
74  */\r
75 void init_background(void)\r
76 {\r
77     register int x, y, landtype_left, landtype_up, landtype_here;\r
78 \r
79         /* INITIALIZE BACKGROUND BY RANDOMLY PICKING TILES */\r
80 \r
81     /* DO FIRST TILE */\r
82     topography[0]=random(NUM_LAND_TILES)+FIRST_LAND_TILE;\r
83 \r
84     /* DO FIRST ROW */\r
85     for (x=1; x<WORLD_WIDTH; x++)\r
86     {\r
87         landtype_left=isdirt(topography[x-1]);\r
88         landtype_here=landtype_left;\r
89         if (random(100)>=CHANCE_LAND_GROUPING) /* NO GROUPING */\r
90         {\r
91             if (random(100)>=world_type) landtype_here=1;\r
92             else landtype_here=0;\r
93         }\r
94 \r
95         if (landtype_here==0) topography[x]=\r
96             random (NUM_GRASS_TILES)+FIRST_GRASS_TILE;   /* GRASS */\r
97         else topography[x]=\r
98             random (NUM_DIRT_TILES)+FIRST_DIRT_TILE;     /* DIRT */\r
99     }\r
100 \r
101     /* DO FIRST COLUMN */\r
102     for (y=1; y<WORLD_HEIGHT; y++)\r
103     {\r
104         landtype_up=isdirt(topography[WORLD_TILE(0,y-1)]);\r
105         landtype_here=landtype_up;\r
106                 if (random(100)>=CHANCE_LAND_GROUPING) /* NO GROUPING */\r
107         {\r
108             if (random(100)>=world_type) landtype_here=1;\r
109             else landtype_here=0;\r
110         }\r
111 \r
112         if (landtype_here==0) topography[WORLD_TILE(0,y)]=\r
113             random (NUM_GRASS_TILES)+FIRST_GRASS_TILE;   /* GRASS */\r
114         else topography[WORLD_TILE(0,y)]=\r
115             random (NUM_DIRT_TILES)+FIRST_DIRT_TILE;     /* DIRT */\r
116     }\r
117 \r
118     /* DO SUBSEQUENT ROWS */\r
119     for (y=1; y<WORLD_HEIGHT; y++)\r
120     for (x=1; x<WORLD_WIDTH; x++)\r
121     {\r
122         landtype_left=isdirt(topography[WORLD_TILE(x-1,y)]);\r
123         landtype_up=isdirt(topography[WORLD_TILE(x,y-1)]);\r
124         landtype_here=landtype_left;\r
125 \r
126         if (random(100)>=CHANCE_LAND_GROUPING) /* UNGROUP */\r
127         {\r
128             if (random(100)>=world_type) landtype_here=1;\r
129             else landtype_here=0;\r
130         }\r
131         else if (random(2)) landtype_here=landtype_up;\r
132 \r
133         if (landtype_here==0) topography[WORLD_TILE(x,y)]=\r
134             random (NUM_GRASS_TILES)+FIRST_GRASS_TILE;   /* GRASS */\r
135         else topography[WORLD_TILE(x,y)]=\r
136             random (NUM_DIRT_TILES)+FIRST_DIRT_TILE;     /* DIRT */\r
137     }\r
138 \r
139     if (edgemode) add_dirt_edges ();\r
140 }\r
141 \r
142 /*\r
143  *\r
144  * Initializes background and foreground tile lists.\r
145  *\r
146  */\r
147 void init_world(void)\r
148 {\r
149     init_background();\r
150     init_foreground();\r
151     view_x=random(WORLD_WIDTH-VIEW_WIDTH);\r
152     view_y=random(WORLD_HEIGHT-VIEW_HEIGHT);\r
153 }\r