1 | /* |
1 | /* |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2001,2007 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2001 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
6 | * Copyright (©) 1992 Frank Tore Johansen |
7 | * |
7 | * |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
9 | * the terms of the Affero GNU General Public License as published by the |
9 | * the terms of the Affero GNU General Public License as published by the |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
11 | * option) any later version. |
11 | * option) any later version. |
… | |
… | |
43 | #define NO_PASS_DOORS 0 |
43 | #define NO_PASS_DOORS 0 |
44 | #define PASS_DOORS 1 |
44 | #define PASS_DOORS 1 |
45 | |
45 | |
46 | static object *find_closest_monster (maptile *map, int x, int y, random_map_params *RP); |
46 | static object *find_closest_monster (maptile *map, int x, int y, random_map_params *RP); |
47 | static object *find_monster_in_room (maptile *map, int x, int y, random_map_params *RP); |
47 | static object *find_monster_in_room (maptile *map, int x, int y, random_map_params *RP); |
48 | static void find_spot_in_room_recursive (char **layout, int x, int y, random_map_params *RP); |
48 | static void find_spot_in_room_recursive (char **maze, int x, int y, random_map_params *RP); |
49 | static void find_spot_in_room (maptile *map, int x, int y, int *kx, int *ky, random_map_params *RP); |
49 | static void find_spot_in_room (maptile *map, int x, int y, int *kx, int *ky, random_map_params *RP); |
50 | static object *place_chest (int treasureoptions, int x, int y, maptile *map, maptile *style_map, int n_treasures, random_map_params *RP); |
50 | static object *place_chest (int treasureoptions, int x, int y, maptile *map, maptile *style_map, int n_treasures, random_map_params *RP); |
51 | static object **find_doors_in_room (maptile *map, int x, int y, random_map_params *RP); |
51 | static object **find_doors_in_room (maptile *map, int x, int y, random_map_params *RP); |
52 | static void lock_and_hide_doors (object **doorlist, maptile *map, int opts, random_map_params *RP); |
52 | static void lock_and_hide_doors (object **doorlist, maptile *map, int opts, random_map_params *RP); |
53 | static void find_enclosed_spot (maptile *map, int *cx, int *cy, random_map_params *RP); |
53 | static void find_enclosed_spot (maptile *map, int *cx, int *cy, random_map_params *RP); |
54 | static object **surround_by_doors (maptile *map, char **layout, int x, int y, int opts); |
54 | static object **surround_by_doors (maptile *map, char **maze, int x, int y, int opts); |
55 | |
55 | |
56 | /* a macro to get a strongly centered random distribution, |
56 | /* a macro to get a strongly centered random distribution, |
57 | from 0 to x, centered at x/2 */ |
57 | from 0 to x, centered at x/2 */ |
58 | static int |
58 | static int |
59 | bc_random (int x) |
59 | bc_random (int x) |
… | |
… | |
109 | freeindex = -1; |
109 | freeindex = -1; |
110 | for (tries = 0; tries < 15 && freeindex == -1; tries++) |
110 | for (tries = 0; tries < 15 && freeindex == -1; tries++) |
111 | { |
111 | { |
112 | kx = rmg_rndm (RP->Xsize - 2) + 1; |
112 | kx = rmg_rndm (RP->Xsize - 2) + 1; |
113 | ky = rmg_rndm (RP->Ysize - 2) + 1; |
113 | ky = rmg_rndm (RP->Ysize - 2) + 1; |
114 | freeindex = find_free_spot (the_key, map, kx, ky, 1, SIZEOFFREE1 + 1); |
114 | freeindex = rmg_find_free_spot (the_key, map, kx, ky, 1, SIZEOFFREE1 + 1); |
115 | } |
115 | } |
116 | |
116 | |
117 | // can freeindex ever be < 0? |
117 | // can freeindex ever be < 0? |
118 | if (freeindex >= 0) |
118 | if (freeindex >= 0) |
119 | { |
119 | { |
… | |
… | |
187 | return GET_MAP_MOVE_BLOCK (m, x, y) & MOVE_WALK; |
187 | return GET_MAP_MOVE_BLOCK (m, x, y) & MOVE_WALK; |
188 | } |
188 | } |
189 | |
189 | |
190 | /* place treasures in the map, given the |
190 | /* place treasures in the map, given the |
191 | map, (required) |
191 | map, (required) |
192 | layout, (required) |
192 | maze, (required) |
193 | treasure style (may be empty or NULL, or "none" to cause no treasure.) |
193 | treasure style (may be empty or NULL, or "none" to cause no treasure.) |
194 | treasureoptions (may be 0 for random choices or positive) |
194 | treasureoptions (may be 0 for random choices or positive) |
195 | */ |
195 | */ |
196 | void |
196 | void |
197 | place_treasure (maptile *map, char **layout, char *treasure_style, int treasureoptions, random_map_params *RP) |
197 | place_treasure (maptile *map, char **maze, const char *treasure_style, int treasureoptions, random_map_params *RP) |
198 | { |
198 | { |
199 | char styledirname[1024]; |
|
|
200 | char stylefilepath[1024]; |
|
|
201 | maptile *style_map = 0; |
|
|
202 | int num_treasures; |
199 | int num_treasures; |
203 | |
200 | |
204 | /* bail out if treasure isn't wanted. */ |
201 | /* bail out if treasure isn't wanted. */ |
205 | if (treasure_style) |
202 | if (treasure_style) |
206 | if (!strcmp (treasure_style, "none")) |
203 | if (!strcmp (treasure_style, "none")) |
… | |
… | |
228 | |
225 | |
229 | if (num_treasures <= 0) |
226 | if (num_treasures <= 0) |
230 | return; |
227 | return; |
231 | |
228 | |
232 | /* get the style map */ |
229 | /* get the style map */ |
233 | sprintf (styledirname, "%s", "/styles/treasurestyles"); |
230 | maptile *style_map = find_style ("/styles/treasurestyles", treasure_style, RP->difficulty); |
234 | sprintf (stylefilepath, "%s/%s", styledirname, treasure_style); |
|
|
235 | style_map = find_style (styledirname, treasure_style, -1); |
|
|
236 | |
231 | |
237 | if (!style_map) |
232 | if (!style_map) |
238 | { |
233 | { |
239 | LOG (llevError, "unable to load style map %s %s.\n", styledirname, treasure_style); |
234 | LOG (llevError, "unable to load style map %s %s.\n", "/styles/treasurestyles", treasure_style); |
240 | return; |
235 | return; |
241 | } |
236 | } |
242 | |
237 | |
243 | /* all the treasure at one spot in the map. */ |
238 | /* all the treasure at one spot in the map. */ |
244 | if (treasureoptions & CONCENTRATED) |
239 | if (treasureoptions & CONCENTRATED) |
… | |
… | |
255 | /* search the onion for C's or '>', and put treasure there. */ |
250 | /* search the onion for C's or '>', and put treasure there. */ |
256 | for (i = 0; i < RP->Xsize; i++) |
251 | for (i = 0; i < RP->Xsize; i++) |
257 | { |
252 | { |
258 | for (j = 0; j < RP->Ysize; j++) |
253 | for (j = 0; j < RP->Ysize; j++) |
259 | { |
254 | { |
260 | if (layout[i][j] == 'C' || layout[i][j] == '>') |
255 | if (maze[i][j] == 'C' || maze[i][j] == '>') |
261 | { |
256 | { |
262 | int tdiv = RP->symmetry_used; |
257 | int tdiv = RP->symmetry_used; |
263 | object *chest; |
258 | object *chest; |
264 | |
259 | |
265 | if (tdiv == 3) |
260 | if (tdiv == 3) |
… | |
… | |
310 | |
305 | |
311 | i = chest->x; |
306 | i = chest->x; |
312 | j = chest->y; |
307 | j = chest->y; |
313 | if (treasureoptions & (DOORED | HIDDEN)) |
308 | if (treasureoptions & (DOORED | HIDDEN)) |
314 | { |
309 | { |
315 | doorlist = surround_by_doors (map, layout, i, j, treasureoptions); |
310 | doorlist = surround_by_doors (map, maze, i, j, treasureoptions); |
316 | lock_and_hide_doors (doorlist, map, treasureoptions, RP); |
311 | lock_and_hide_doors (doorlist, map, treasureoptions, RP); |
317 | free (doorlist); |
312 | free (doorlist); |
318 | } |
313 | } |
319 | } |
314 | } |
320 | } |
315 | } |
321 | } |
316 | } |
322 | else |
317 | else |
323 | { /* DIFFUSE treasure layout */ |
318 | { /* DIFFUSE treasure maze */ |
324 | int ti, i, j; |
319 | int ti, i, j; |
325 | |
320 | |
326 | for (ti = 0; ti < num_treasures; ti++) |
321 | for (ti = 0; ti < num_treasures; ti++) |
327 | { |
322 | { |
328 | i = rmg_rndm (RP->Xsize - 2) + 1; |
323 | i = rmg_rndm (RP->Xsize - 2) + 1; |
… | |
… | |
384 | } |
379 | } |
385 | |
380 | |
386 | /* stick a trap in the chest if required */ |
381 | /* stick a trap in the chest if required */ |
387 | if (treasureoptions & TRAPPED) |
382 | if (treasureoptions & TRAPPED) |
388 | { |
383 | { |
389 | maptile *trap_map = find_style ("/styles/trapstyles", "traps", -1); |
384 | maptile *trap_map = find_style ("/styles/trapstyles", "traps", RP->difficulty); |
390 | |
385 | |
391 | if (trap_map) |
386 | if (trap_map) |
392 | { |
387 | { |
393 | object *the_trap = trap_map->pick_random_object (rmg_rndm); |
388 | object *the_trap = trap_map->pick_random_object (rmg_rndm); |
394 | |
389 | |
… | |
… | |
439 | /* don't bother searching this square unless the map says life exists. */ |
434 | /* don't bother searching this square unless the map says life exists. */ |
440 | if (GET_MAP_FLAGS (map, lx, ly) & P_IS_ALIVE) |
435 | if (GET_MAP_FLAGS (map, lx, ly) & P_IS_ALIVE) |
441 | { |
436 | { |
442 | object *the_monster = GET_MAP_OB (map, lx, ly); |
437 | object *the_monster = GET_MAP_OB (map, lx, ly); |
443 | |
438 | |
444 | for (; the_monster != NULL && (!QUERY_FLAG (the_monster, FLAG_MONSTER)); the_monster = the_monster->above); |
439 | for (; the_monster != NULL && (!the_monster->flag [FLAG_MONSTER]); the_monster = the_monster->above); |
445 | if (the_monster && QUERY_FLAG (the_monster, FLAG_MONSTER)) |
440 | if (the_monster && the_monster->flag [FLAG_MONSTER]) |
446 | return the_monster; |
441 | return the_monster; |
447 | } |
442 | } |
448 | } |
443 | } |
449 | return NULL; |
444 | return NULL; |
450 | } |
445 | } |
… | |
… | |
452 | /* both find_monster_in_room routines need to have access to this. */ |
447 | /* both find_monster_in_room routines need to have access to this. */ |
453 | |
448 | |
454 | static object *theMonsterToFind; |
449 | static object *theMonsterToFind; |
455 | |
450 | |
456 | /* a recursive routine which will return a monster, eventually,if there is one. |
451 | /* a recursive routine which will return a monster, eventually,if there is one. |
457 | it does a check-off on the layout, converting 0's to 1's */ |
452 | it does a check-off on the maze, converting 0's to 1's */ |
458 | static object * |
453 | static object * |
459 | find_monster_in_room_recursive (char **layout, maptile *map, int x, int y, random_map_params *RP) |
454 | find_monster_in_room_recursive (char **maze, maptile *map, int x, int y, random_map_params *RP) |
460 | { |
455 | { |
461 | int i, j; |
456 | int i, j; |
462 | |
457 | |
463 | /* if we've found a monster already, leave */ |
458 | /* if we've found a monster already, leave */ |
464 | if (theMonsterToFind != NULL) |
459 | if (theMonsterToFind != NULL) |
… | |
… | |
467 | /* bounds check x and y */ |
462 | /* bounds check x and y */ |
468 | if (!(x >= 0 && y >= 0 && x < RP->Xsize && y < RP->Ysize)) |
463 | if (!(x >= 0 && y >= 0 && x < RP->Xsize && y < RP->Ysize)) |
469 | return theMonsterToFind; |
464 | return theMonsterToFind; |
470 | |
465 | |
471 | /* if the square is blocked or searched already, leave */ |
466 | /* if the square is blocked or searched already, leave */ |
472 | if (layout[x][y] != 0) |
467 | if (maze[x][y] != 0) |
473 | return theMonsterToFind; /* might be NULL, that's fine. */ |
468 | return theMonsterToFind; /* might be NULL, that's fine. */ |
474 | |
469 | |
475 | /* check the current square for a monster. If there is one, |
470 | /* check the current square for a monster. If there is one, |
476 | set theMonsterToFind and return it. */ |
471 | set theMonsterToFind and return it. */ |
477 | layout[x][y] = 1; |
472 | maze[x][y] = 1; |
478 | if (GET_MAP_FLAGS (map, x, y) & P_IS_ALIVE) |
473 | if (GET_MAP_FLAGS (map, x, y) & P_IS_ALIVE) |
479 | { |
474 | { |
480 | object *the_monster = GET_MAP_OB (map, x, y); |
475 | object *the_monster = GET_MAP_OB (map, x, y); |
481 | |
476 | |
482 | /* check off this point */ |
477 | /* check off this point */ |
483 | for (; the_monster != NULL && (!QUERY_FLAG (the_monster, FLAG_ALIVE)); the_monster = the_monster->above); |
478 | for (; the_monster != NULL && (!the_monster->flag [FLAG_ALIVE]); the_monster = the_monster->above); |
484 | if (the_monster && QUERY_FLAG (the_monster, FLAG_ALIVE)) |
479 | if (the_monster && the_monster->flag [FLAG_ALIVE]) |
485 | { |
480 | { |
486 | theMonsterToFind = the_monster; |
481 | theMonsterToFind = the_monster; |
487 | return theMonsterToFind; |
482 | return theMonsterToFind; |
488 | } |
483 | } |
489 | } |
484 | } |
490 | |
485 | |
491 | /* now search all the 8 squares around recursively for a monster,in random order */ |
486 | /* now search all the 8 squares around recursively for a monster,in random order */ |
492 | for (i = rmg_rndm (8), j = 0; j < 8 && theMonsterToFind == NULL; i++, j++) |
487 | for (i = rmg_rndm (8), j = 0; j < 8 && theMonsterToFind == NULL; i++, j++) |
493 | { |
488 | { |
494 | theMonsterToFind = find_monster_in_room_recursive (layout, map, x + freearr_x[i % 8 + 1], y + freearr_y[i % 8 + 1], RP); |
489 | theMonsterToFind = find_monster_in_room_recursive (maze, map, x + freearr_x[i % 8 + 1], y + freearr_y[i % 8 + 1], RP); |
495 | if (theMonsterToFind != NULL) |
490 | if (theMonsterToFind != NULL) |
496 | return theMonsterToFind; |
491 | return theMonsterToFind; |
497 | } |
492 | } |
498 | |
493 | |
499 | return theMonsterToFind; |
494 | return theMonsterToFind; |
… | |
… | |
502 | /* sets up some data structures: the _recursive form does the |
497 | /* sets up some data structures: the _recursive form does the |
503 | real work. */ |
498 | real work. */ |
504 | static object * |
499 | static object * |
505 | find_monster_in_room (maptile *map, int x, int y, random_map_params *RP) |
500 | find_monster_in_room (maptile *map, int x, int y, random_map_params *RP) |
506 | { |
501 | { |
507 | Layout layout2 (RP); |
502 | layout layout2 (map->width, map->height); |
508 | |
503 | |
509 | layout2->clear (); |
504 | // find walls |
510 | |
|
|
511 | /* allocate and copy the layout, converting C to 0. */ |
|
|
512 | for (int i = 0; i < layout2->w; i++) |
505 | for (int i = 0; i < layout2.w; i++) |
513 | for (int j = 0; j < layout2->h; j++) |
506 | for (int j = 0; j < layout2.h; j++) |
514 | if (wall_blocked (map, i, j)) |
507 | layout2[i][j] = wall_blocked (map, i, j) ? '#' : 0; |
515 | layout2[i][j] = '#'; |
|
|
516 | |
508 | |
517 | theMonsterToFind = 0; |
509 | theMonsterToFind = 0; |
518 | theMonsterToFind = find_monster_in_room_recursive (layout2, map, x, y, RP); |
510 | theMonsterToFind = find_monster_in_room_recursive (layout2, map, x, y, RP); |
519 | |
|
|
520 | layout2.free (); |
|
|
521 | |
511 | |
522 | return theMonsterToFind; |
512 | return theMonsterToFind; |
523 | } |
513 | } |
524 | |
514 | |
525 | /* a datastructure needed by find_spot_in_room and find_spot_in_room_recursive */ |
515 | /* a datastructure needed by find_spot_in_room and find_spot_in_room_recursive */ |
… | |
… | |
529 | |
519 | |
530 | /* the workhorse routine, which finds the free spots in a room: |
520 | /* the workhorse routine, which finds the free spots in a room: |
531 | a datastructure of free points is set up, and a position chosen from |
521 | a datastructure of free points is set up, and a position chosen from |
532 | that datastructure. */ |
522 | that datastructure. */ |
533 | static void |
523 | static void |
534 | find_spot_in_room_recursive (char **layout, int x, int y, random_map_params *RP) |
524 | find_spot_in_room_recursive (char **maze, int x, int y, random_map_params *RP) |
535 | { |
525 | { |
536 | int i, j; |
526 | int i, j; |
537 | |
527 | |
538 | /* bounds check x and y */ |
528 | /* bounds check x and y */ |
539 | if (!(x >= 0 && y >= 0 && x < RP->Xsize && y < RP->Ysize)) |
529 | if (!(x >= 0 && y >= 0 && x < RP->Xsize && y < RP->Ysize)) |
540 | return; |
530 | return; |
541 | |
531 | |
542 | /* if the square is blocked or searched already, leave */ |
532 | /* if the square is blocked or searched already, leave */ |
543 | if (layout[x][y] != 0) |
533 | if (maze[x][y] != 0) |
544 | return; |
534 | return; |
545 | |
535 | |
546 | /* set the current square as checked, and add it to the list. |
536 | /* set the current square as checked, and add it to the list. |
547 | set theMonsterToFind and return it. */ |
537 | set theMonsterToFind and return it. */ |
548 | /* check off this point */ |
538 | /* check off this point */ |
549 | layout[x][y] = 1; |
539 | maze[x][y] = 1; |
550 | room_free_spots_x[number_of_free_spots_in_room] = x; |
540 | room_free_spots_x[number_of_free_spots_in_room] = x; |
551 | room_free_spots_y[number_of_free_spots_in_room] = y; |
541 | room_free_spots_y[number_of_free_spots_in_room] = y; |
552 | number_of_free_spots_in_room++; |
542 | number_of_free_spots_in_room++; |
553 | |
543 | |
554 | /* now search all the 8 squares around recursively for free spots,in random order */ |
544 | /* now search all the 8 squares around recursively for free spots,in random order */ |
555 | for (i = rmg_rndm (8), j = 0; j < 8 && theMonsterToFind == NULL; i++, j++) |
545 | for (i = rmg_rndm (8), j = 0; j < 8 && theMonsterToFind == NULL; i++, j++) |
556 | find_spot_in_room_recursive (layout, x + freearr_x[i % 8 + 1], y + freearr_y[i % 8 + 1], RP); |
546 | find_spot_in_room_recursive (maze, x + freearr_x[i % 8 + 1], y + freearr_y[i % 8 + 1], RP); |
557 | |
547 | |
558 | } |
548 | } |
559 | |
549 | |
560 | /* find a random non-blocked spot in this room to drop a key. */ |
550 | /* find a random non-blocked spot in this room to drop a key. */ |
561 | static void |
551 | static void |
… | |
… | |
567 | number_of_free_spots_in_room = 0; |
557 | number_of_free_spots_in_room = 0; |
568 | room_free_spots_x = (int *) calloc (sizeof (int), RP->Xsize * RP->Ysize); |
558 | room_free_spots_x = (int *) calloc (sizeof (int), RP->Xsize * RP->Ysize); |
569 | room_free_spots_y = (int *) calloc (sizeof (int), RP->Xsize * RP->Ysize); |
559 | room_free_spots_y = (int *) calloc (sizeof (int), RP->Xsize * RP->Ysize); |
570 | |
560 | |
571 | layout2 = (char **) calloc (sizeof (char *), RP->Xsize); |
561 | layout2 = (char **) calloc (sizeof (char *), RP->Xsize); |
572 | /* allocate and copy the layout, converting C to 0. */ |
562 | /* allocate and copy the maze, converting C to 0. */ |
573 | for (i = 0; i < RP->Xsize; i++) |
563 | for (i = 0; i < RP->Xsize; i++) |
574 | { |
564 | { |
575 | layout2[i] = (char *) calloc (sizeof (char), RP->Ysize); |
565 | layout2[i] = (char *) calloc (sizeof (char), RP->Ysize); |
576 | for (j = 0; j < RP->Ysize; j++) |
566 | for (j = 0; j < RP->Ysize; j++) |
577 | if (wall_blocked (map, i, j)) |
567 | if (wall_blocked (map, i, j)) |
… | |
… | |
586 | i = rmg_rndm (number_of_free_spots_in_room); |
576 | i = rmg_rndm (number_of_free_spots_in_room); |
587 | *kx = room_free_spots_x[i]; |
577 | *kx = room_free_spots_x[i]; |
588 | *ky = room_free_spots_y[i]; |
578 | *ky = room_free_spots_y[i]; |
589 | } |
579 | } |
590 | |
580 | |
591 | /* deallocate the temp. layout */ |
581 | /* deallocate the temp. maze */ |
592 | for (i = 0; i < RP->Xsize; i++) |
582 | for (i = 0; i < RP->Xsize; i++) |
593 | free (layout2[i]); |
583 | free (layout2[i]); |
594 | |
584 | |
595 | free (layout2); |
585 | free (layout2); |
596 | free (room_free_spots_x); |
586 | free (room_free_spots_x); |
… | |
… | |
614 | { |
604 | { |
615 | int lx, ly, sindex; |
605 | int lx, ly, sindex; |
616 | |
606 | |
617 | lx = x + freearr_x[i]; |
607 | lx = x + freearr_x[i]; |
618 | ly = y + freearr_y[i]; |
608 | ly = y + freearr_y[i]; |
619 | sindex = surround_flag3 (map, lx, ly, RP); |
609 | sindex = surround_flag3 (map, lx, ly); |
620 | /* if it's blocked on 3 sides, it's enclosed */ |
610 | /* if it's blocked on 3 sides, it's enclosed */ |
621 | if (sindex == 7 || sindex == 11 || sindex == 13 || sindex == 14) |
611 | if (sindex == 7 || sindex == 11 || sindex == 13 || sindex == 14) |
622 | { |
612 | { |
623 | *cx = lx; |
613 | *cx = lx; |
624 | *cy = ly; |
614 | *cy = ly; |
… | |
… | |
632 | { |
622 | { |
633 | int lx, ly, sindex; |
623 | int lx, ly, sindex; |
634 | |
624 | |
635 | lx = x + freearr_x[i]; |
625 | lx = x + freearr_x[i]; |
636 | ly = y + freearr_y[i]; |
626 | ly = y + freearr_y[i]; |
637 | sindex = surround_flag3 (map, lx, ly, RP); |
627 | sindex = surround_flag3 (map, lx, ly); |
638 | /* if it's blocked on 3 sides, it's enclosed */ |
628 | /* if it's blocked on 3 sides, it's enclosed */ |
639 | if (sindex == 3 || sindex == 5 || sindex == 9 || sindex == 6 || sindex == 10 || sindex == 12) |
629 | if (sindex == 3 || sindex == 5 || sindex == 9 || sindex == 6 || sindex == 10 || sindex == 12) |
640 | { |
630 | { |
641 | *cx = lx; |
631 | *cx = lx; |
642 | *cy = ly; |
632 | *cy = ly; |
… | |
… | |
649 | { |
639 | { |
650 | int lx, ly, sindex; |
640 | int lx, ly, sindex; |
651 | |
641 | |
652 | lx = x + freearr_x[i]; |
642 | lx = x + freearr_x[i]; |
653 | ly = y + freearr_y[i]; |
643 | ly = y + freearr_y[i]; |
654 | sindex = surround_flag3 (map, lx, ly, RP); |
644 | sindex = surround_flag3 (map, lx, ly); |
655 | /* if it's blocked on 3 sides, it's enclosed */ |
645 | /* if it's blocked on 3 sides, it's enclosed */ |
656 | if (sindex) |
646 | if (sindex) |
657 | { |
647 | { |
658 | *cx = lx; |
648 | *cx = lx; |
659 | *cy = ly; |
649 | *cy = ly; |
660 | return; |
650 | return; |
661 | } |
651 | } |
662 | } |
652 | } |
663 | /* give up and return the closest free spot. */ |
653 | /* give up and return the closest free spot. */ |
664 | i = find_free_spot (archetype::find (shstr_chest), map, x, y, 1, SIZEOFFREE1 + 1); |
654 | i = rmg_find_free_spot (archetype::find (shstr_chest), map, x, y, 1, SIZEOFFREE1 + 1); |
665 | |
655 | |
666 | if (i != -1) |
656 | if (i != -1) |
667 | { |
657 | { |
668 | *cx = x + freearr_x[i]; |
658 | *cx = x + freearr_x[i]; |
669 | *cy = y + freearr_y[i]; |
659 | *cy = y + freearr_y[i]; |
… | |
… | |
692 | |
682 | |
693 | /* surrounds the point x,y by doors, so as to enclose something, like |
683 | /* surrounds the point x,y by doors, so as to enclose something, like |
694 | a chest. It only goes as far as the 8 squares surrounding, and |
684 | a chest. It only goes as far as the 8 squares surrounding, and |
695 | it'll remove any monsters it finds.*/ |
685 | it'll remove any monsters it finds.*/ |
696 | static object ** |
686 | static object ** |
697 | surround_by_doors (maptile *map, char **layout, int x, int y, int opts) |
687 | surround_by_doors (maptile *map, char **maze, int x, int y, int opts) |
698 | { |
688 | { |
699 | int i; |
689 | int i; |
700 | const char *doors[2]; |
690 | const char *doors[2]; |
701 | object **doorlist; |
691 | object **doorlist; |
702 | int ndoors_made = 0; |
692 | int ndoors_made = 0; |
… | |
… | |
717 | /* place doors in all the 8 adjacent unblocked squares. */ |
707 | /* place doors in all the 8 adjacent unblocked squares. */ |
718 | for (i = 1; i < 9; i++) |
708 | for (i = 1; i < 9; i++) |
719 | { |
709 | { |
720 | int x1 = x + freearr_x[i], y1 = y + freearr_y[i]; |
710 | int x1 = x + freearr_x[i], y1 = y + freearr_y[i]; |
721 | |
711 | |
722 | if (!wall_blocked (map, x1, y1) && layout[x1][y1] == '>') |
712 | if (!wall_blocked (map, x1, y1) && maze[x1][y1] == '>') |
723 | { /* place a door */ |
713 | { /* place a door */ |
724 | remove_monsters (x1, y1, map); |
714 | remove_monsters (x1, y1, map); |
725 | |
715 | |
726 | object *new_door = get_archetype (freearr_x[i] == 0 ? doors[1] : doors[0]); |
716 | object *new_door = get_archetype (freearr_x[i] == 0 ? doors[1] : doors[0]); |
727 | map->insert (new_door, x1, y1); |
717 | map->insert (new_door, x1, y1); |
… | |
… | |
744 | return NULL; |
734 | return NULL; |
745 | } |
735 | } |
746 | |
736 | |
747 | /* the workhorse routine, which finds the doors in a room */ |
737 | /* the workhorse routine, which finds the doors in a room */ |
748 | static void |
738 | static void |
749 | find_doors_in_room_recursive (char **layout, maptile *map, int x, int y, object **doorlist, int *ndoors, random_map_params *RP) |
739 | find_doors_in_room_recursive (char **maze, maptile *map, int x, int y, object **doorlist, int *ndoors, random_map_params *RP) |
750 | { |
740 | { |
751 | int i, j; |
741 | int i, j; |
752 | object *door; |
742 | object *door; |
753 | |
743 | |
754 | /* bounds check x and y */ |
744 | /* bounds check x and y */ |
755 | if (!(x >= 0 && y >= 0 && x < RP->Xsize && y < RP->Ysize)) |
745 | if (!(x >= 0 && y >= 0 && x < RP->Xsize && y < RP->Ysize)) |
756 | return; |
746 | return; |
757 | |
747 | |
758 | /* if the square is blocked or searched already, leave */ |
748 | /* if the square is blocked or searched already, leave */ |
759 | if (layout[x][y] == 1) |
749 | if (maze[x][y] == 1) |
760 | return; |
750 | return; |
761 | |
751 | |
762 | /* check off this point */ |
752 | /* check off this point */ |
763 | if (layout[x][y] == '#') |
753 | if (maze[x][y] == '#') |
764 | { /* there could be a door here */ |
754 | { /* there could be a door here */ |
765 | layout[x][y] = 1; |
755 | maze[x][y] = 1; |
766 | door = door_in_square (map, x, y); |
756 | door = door_in_square (map, x, y); |
767 | if (door) |
757 | if (door) |
768 | { |
758 | { |
769 | doorlist[*ndoors] = door; |
759 | doorlist[*ndoors] = door; |
770 | |
760 | |
… | |
… | |
777 | *ndoors = *ndoors + 1; |
767 | *ndoors = *ndoors + 1; |
778 | } |
768 | } |
779 | } |
769 | } |
780 | else |
770 | else |
781 | { |
771 | { |
782 | layout[x][y] = 1; |
772 | maze[x][y] = 1; |
783 | |
773 | |
784 | /* now search all the 8 squares around recursively for free spots,in random order */ |
774 | /* now search all the 8 squares around recursively for free spots,in random order */ |
785 | for (i = rmg_rndm (8), j = 0; j < 8 && !theMonsterToFind; i++, j++) |
775 | for (i = rmg_rndm (8), j = 0; j < 8 && !theMonsterToFind; i++, j++) |
786 | find_doors_in_room_recursive (layout, map, |
776 | find_doors_in_room_recursive (maze, map, |
787 | x + freearr_x[i % 8 + 1], y + freearr_y[i % 8 + 1], |
777 | x + freearr_x[i % 8 + 1], y + freearr_y[i % 8 + 1], |
788 | doorlist, ndoors, RP); |
778 | doorlist, ndoors, RP); |
789 | } |
779 | } |
790 | } |
780 | } |
791 | |
781 | |
… | |
… | |
796 | int i, j; |
786 | int i, j; |
797 | int ndoors = 0; |
787 | int ndoors = 0; |
798 | |
788 | |
799 | object **doorlist = (object **)calloc (sizeof (int), 1024); |
789 | object **doorlist = (object **)calloc (sizeof (int), 1024); |
800 | |
790 | |
801 | LayoutData layout2 (RP->Xsize, RP->Ysize); |
791 | layout layout2 (RP->Xsize, RP->Ysize); |
802 | layout2.clear (); |
792 | layout2.clear (); |
803 | |
793 | |
804 | /* allocate and copy the layout, converting C to 0. */ |
794 | /* allocate and copy the maze, converting C to 0. */ |
805 | for (i = 0; i < RP->Xsize; i++) |
795 | for (i = 0; i < RP->Xsize; i++) |
806 | for (j = 0; j < RP->Ysize; j++) |
796 | for (j = 0; j < RP->Ysize; j++) |
807 | layout2[i][j] = wall_blocked (map, i, j) ? '#' : 0; |
797 | layout2[i][j] = wall_blocked (map, i, j) ? '#' : 0; |
808 | |
798 | |
809 | /* setup num_free_spots and room_free_spots */ |
799 | /* setup num_free_spots and room_free_spots */ |