… | |
… | |
24 | #include <global.h> |
24 | #include <global.h> |
25 | #include <random_map.h> |
25 | #include <random_map.h> |
26 | #include <sproto.h> |
26 | #include <sproto.h> |
27 | #include <rproto.h> |
27 | #include <rproto.h> |
28 | |
28 | |
29 | |
|
|
30 | /* find a character in the layout. fx and fy are pointers to |
29 | /* find a character in the layout. fx and fy are pointers to |
31 | where to find the char. fx,fy = -1 if not found. */ |
30 | where to find the char. fx,fy = -1 if not found. */ |
32 | void |
31 | void |
33 | find_in_layout (int mode, char target, int *fx, int *fy, char **layout, RMParms * RP) |
32 | find_in_layout (int mode, char target, int *fx, int *fy, char **layout, random_map_params * RP) |
34 | { |
33 | { |
35 | int M; |
34 | int M; |
36 | int i, j; |
35 | int i, j; |
37 | |
36 | |
38 | *fx = -1; |
37 | *fx = -1; |
… | |
… | |
106 | break; |
105 | break; |
107 | } |
106 | } |
108 | } |
107 | } |
109 | } |
108 | } |
110 | |
109 | |
111 | |
|
|
112 | |
|
|
113 | |
|
|
114 | |
|
|
115 | |
|
|
116 | /* orientation: 0 means random, |
110 | /* orientation: 0 means random, |
117 | 1 means descending dungeon |
111 | 1 means descending dungeon |
118 | 2 means ascending dungeon |
112 | 2 means ascending dungeon |
119 | 3 means rightward |
113 | 3 means rightward |
120 | 4 means leftward |
114 | 4 means leftward |
121 | 5 means northward |
115 | 5 means northward |
122 | 6 means southward |
116 | 6 means southward |
123 | */ |
117 | */ |
124 | |
|
|
125 | void |
118 | void |
126 | place_exits (maptile *map, char **maze, char *exitstyle, int orientation, RMParms * RP) |
119 | place_exits (maptile *map, char **maze, char *exitstyle, int orientation, random_map_params *RP) |
127 | { |
120 | { |
128 | char styledirname[256]; |
121 | char styledirname[256]; |
129 | maptile *style_map_down = 0; /* harder maze */ |
122 | maptile *style_map_down = 0; /* harder maze */ |
130 | maptile *style_map_up = 0; /* easier maze */ |
123 | maptile *style_map_up = 0; /* easier maze */ |
131 | object *the_exit_down; /* harder maze */ |
124 | object *the_exit_down; /* harder maze */ |
… | |
… | |
146 | if (orientation == 0) |
139 | if (orientation == 0) |
147 | orientation = RANDOM () % 6 + 1; |
140 | orientation = RANDOM () % 6 + 1; |
148 | |
141 | |
149 | switch (orientation) |
142 | switch (orientation) |
150 | { |
143 | { |
151 | case 1: |
144 | case 1: |
152 | { |
145 | { |
153 | sprintf (styledirname, "/styles/exitstyles/up"); |
146 | sprintf (styledirname, "/styles/exitstyles/up"); |
154 | style_map_up = find_style (styledirname, exitstyle, -1); |
147 | style_map_up = find_style (styledirname, exitstyle, -1); |
155 | sprintf (styledirname, "/styles/exitstyles/down"); |
148 | sprintf (styledirname, "/styles/exitstyles/down"); |
156 | style_map_down = find_style (styledirname, exitstyle, -1); |
149 | style_map_down = find_style (styledirname, exitstyle, -1); |
157 | break; |
150 | break; |
158 | } |
151 | } |
|
|
152 | |
159 | case 2: |
153 | case 2: |
160 | { |
154 | { |
161 | sprintf (styledirname, "/styles/exitstyles/down"); |
155 | sprintf (styledirname, "/styles/exitstyles/down"); |
162 | style_map_up = find_style (styledirname, exitstyle, -1); |
156 | style_map_up = find_style (styledirname, exitstyle, -1); |
163 | sprintf (styledirname, "/styles/exitstyles/up"); |
157 | sprintf (styledirname, "/styles/exitstyles/up"); |
164 | style_map_down = find_style (styledirname, exitstyle, -1); |
158 | style_map_down = find_style (styledirname, exitstyle, -1); |
165 | break; |
159 | break; |
166 | } |
160 | } |
|
|
161 | |
167 | default: |
162 | default: |
168 | { |
163 | { |
169 | sprintf (styledirname, "/styles/exitstyles/generic"); |
164 | sprintf (styledirname, "/styles/exitstyles/generic"); |
170 | style_map_up = find_style (styledirname, exitstyle, -1); |
165 | style_map_up = find_style (styledirname, exitstyle, -1); |
171 | style_map_down = style_map_up; |
166 | style_map_down = style_map_up; |
172 | break; |
167 | break; |
173 | } |
168 | } |
174 | } |
169 | } |
|
|
170 | |
175 | if (style_map_up == 0) |
171 | if (style_map_up == 0) |
176 | the_exit_up = arch_to_object (archetype::find ("exit")); |
172 | the_exit_up = arch_to_object (archetype::find ("exit")); |
177 | else |
173 | else |
178 | { |
174 | { |
179 | object *tmp; |
175 | object *tmp; |
… | |
… | |
197 | the_exit_down = 0; |
193 | the_exit_down = 0; |
198 | |
194 | |
199 | /* set up the up exit */ |
195 | /* set up the up exit */ |
200 | the_exit_up->stats.hp = RP->origin_x; |
196 | the_exit_up->stats.hp = RP->origin_x; |
201 | the_exit_up->stats.sp = RP->origin_y; |
197 | the_exit_up->stats.sp = RP->origin_y; |
202 | the_exit_up->slaying = RP->origin_map; |
198 | the_exit_up->slaying = RP->origin_map; |
203 | |
199 | |
204 | /* figure out where to put the entrance */ |
200 | /* figure out where to put the entrance */ |
205 | /* begin a logical block */ |
201 | /* begin a logical block */ |
206 | { |
202 | { |
207 | int i, j; |
203 | int i, j; |
… | |
… | |
262 | |
258 | |
263 | insert_ob_in_map (the_exit_up, map, NULL, 0); |
259 | insert_ob_in_map (the_exit_up, map, NULL, 0); |
264 | maze[the_exit_up->x][the_exit_up->y] = '<'; |
260 | maze[the_exit_up->x][the_exit_up->y] = '<'; |
265 | |
261 | |
266 | /* set the starting x,y for this map */ |
262 | /* set the starting x,y for this map */ |
267 | MAP_ENTER_X (map) = the_exit_up->x; |
263 | map->enter_x = the_exit_up->x; |
268 | MAP_ENTER_Y (map) = the_exit_up->y; |
264 | map->enter_y = the_exit_up->y; |
269 | |
265 | |
270 | /* first, look for a '>' character */ |
266 | /* first, look for a '>' character */ |
271 | find_in_layout (0, '>', &downx, &downy, maze, RP); |
267 | find_in_layout (0, '>', &downx, &downy, maze, RP); |
272 | /* if no > is found use C */ |
268 | /* if no > is found use C */ |
273 | if (downx == -1) |
269 | if (downx == -1) |
… | |
… | |
331 | /* give the final map a name */ |
327 | /* give the final map a name */ |
332 | sprintf (new_map_name, "%sfinal_map", RP->final_map); |
328 | sprintf (new_map_name, "%sfinal_map", RP->final_map); |
333 | /* set the exit down. */ |
329 | /* set the exit down. */ |
334 | #endif |
330 | #endif |
335 | /* load it */ |
331 | /* load it */ |
336 | if ((new_map = ready_map_name (RP->final_map, 0)) == NULL) |
332 | if (!(new_map = maptile::load_map_sync (RP->final_map))) |
337 | return; |
333 | return; |
338 | |
334 | |
339 | the_exit_down->slaying = RP->final_map; |
335 | the_exit_down->slaying = RP->final_map; |
340 | strcpy (new_map->path, RP->final_map); |
|
|
341 | |
336 | |
342 | for (tmp = GET_MAP_OB (new_map, MAP_ENTER_X (new_map), MAP_ENTER_Y (new_map)); tmp; tmp = tmp->above) |
337 | for (tmp = new_map->at (new_map->enter_x, new_map->enter_y).bot; tmp; tmp = tmp->above) |
343 | /* Remove exit back to previous random map. There should only be one |
338 | /* Remove exit back to previous random map. There should only be one |
344 | * which is why we break out. To try to process more than one |
339 | * which is why we break out. To try to process more than one |
345 | * would require keeping a 'next' pointer, ad free_object kills tmp, which |
340 | * would require keeping a 'next' pointer, ad free_object kills tmp, which |
346 | * breaks the for loop. |
341 | * breaks the for loop. |
347 | */ |
342 | */ |
348 | if (tmp->type == EXIT && EXIT_PATH (tmp) && !strncmp (EXIT_PATH (tmp), "/random/", 8)) |
343 | if (tmp->type == EXIT && EXIT_PATH (tmp) && !strncmp (EXIT_PATH (tmp), "/random/", 8)) |
349 | { |
344 | { |
350 | tmp->remove (); |
|
|
351 | tmp->destroy (); |
345 | tmp->destroy (); |
352 | break; |
346 | break; |
353 | } |
347 | } |
354 | |
348 | |
355 | if (final_map_exit == 1) |
349 | if (final_map_exit == 1) |
356 | { |
350 | { |
357 | /* setup the exit back */ |
351 | /* setup the exit back */ |
358 | the_exit_back->slaying = map->path; |
352 | the_exit_back->slaying = map->path; |
359 | the_exit_back->stats.hp = the_exit_down->x; |
353 | the_exit_back->stats.hp = the_exit_down->x; |
360 | the_exit_back->stats.sp = the_exit_down->y; |
354 | the_exit_back->stats.sp = the_exit_down->y; |
361 | the_exit_back->x = MAP_ENTER_X (new_map); |
355 | the_exit_back->x = new_map->enter_x; |
362 | the_exit_back->y = MAP_ENTER_Y (new_map); |
356 | the_exit_back->y = new_map->enter_y; |
363 | |
357 | |
364 | insert_ob_in_map (the_exit_back, new_map, NULL, 0); |
358 | insert_ob_in_map (the_exit_back, new_map, NULL, 0); |
365 | } |
359 | } |
366 | |
|
|
367 | set_map_timeout (new_map); /* So it gets swapped out */ |
|
|
368 | } |
360 | } |
369 | else |
361 | else |
370 | the_exit_down->slaying = "/!"; |
362 | the_exit_down->slaying = "/!"; |
371 | |
363 | |
372 | /* Block the exit so things don't get dumped on top of it. */ |
364 | /* Block the exit so things don't get dumped on top of it. */ |
… | |
… | |
376 | } |
368 | } |
377 | } |
369 | } |
378 | |
370 | |
379 | } |
371 | } |
380 | |
372 | |
381 | |
|
|
382 | |
|
|
383 | /* this function unblocks the exits. We blocked them to |
373 | /* this function unblocks the exits. We blocked them to |
384 | keep things from being dumped on them during the other |
374 | keep things from being dumped on them during the other |
385 | phases of random map generation. */ |
375 | phases of random map generation. */ |
386 | void |
376 | void |
387 | unblock_exits (maptile *map, char **maze, RMParms * RP) |
377 | unblock_exits (maptile *map, char **maze, random_map_params * RP) |
388 | { |
378 | { |
389 | int i = 0, j = 0; |
379 | int i = 0, j = 0; |
390 | object *walk; |
380 | object *walk; |
391 | |
381 | |
392 | for (i = 0; i < RP->Xsize; i++) |
382 | for (i = 0; i < RP->Xsize; i++) |