… | |
… | |
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) |
… | |
… | |
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, const 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 | int num_treasures; |
199 | int num_treasures; |
200 | |
200 | |
201 | /* bail out if treasure isn't wanted. */ |
201 | /* bail out if treasure isn't wanted. */ |
202 | if (treasure_style) |
202 | if (treasure_style) |
… | |
… | |
250 | /* search the onion for C's or '>', and put treasure there. */ |
250 | /* search the onion for C's or '>', and put treasure there. */ |
251 | for (i = 0; i < RP->Xsize; i++) |
251 | for (i = 0; i < RP->Xsize; i++) |
252 | { |
252 | { |
253 | for (j = 0; j < RP->Ysize; j++) |
253 | for (j = 0; j < RP->Ysize; j++) |
254 | { |
254 | { |
255 | if (layout[i][j] == 'C' || layout[i][j] == '>') |
255 | if (maze[i][j] == 'C' || maze[i][j] == '>') |
256 | { |
256 | { |
257 | int tdiv = RP->symmetry_used; |
257 | int tdiv = RP->symmetry_used; |
258 | object *chest; |
258 | object *chest; |
259 | |
259 | |
260 | if (tdiv == 3) |
260 | if (tdiv == 3) |
… | |
… | |
305 | |
305 | |
306 | i = chest->x; |
306 | i = chest->x; |
307 | j = chest->y; |
307 | j = chest->y; |
308 | if (treasureoptions & (DOORED | HIDDEN)) |
308 | if (treasureoptions & (DOORED | HIDDEN)) |
309 | { |
309 | { |
310 | doorlist = surround_by_doors (map, layout, i, j, treasureoptions); |
310 | doorlist = surround_by_doors (map, maze, i, j, treasureoptions); |
311 | lock_and_hide_doors (doorlist, map, treasureoptions, RP); |
311 | lock_and_hide_doors (doorlist, map, treasureoptions, RP); |
312 | free (doorlist); |
312 | free (doorlist); |
313 | } |
313 | } |
314 | } |
314 | } |
315 | } |
315 | } |
316 | } |
316 | } |
317 | else |
317 | else |
318 | { /* DIFFUSE treasure layout */ |
318 | { /* DIFFUSE treasure maze */ |
319 | int ti, i, j; |
319 | int ti, i, j; |
320 | |
320 | |
321 | for (ti = 0; ti < num_treasures; ti++) |
321 | for (ti = 0; ti < num_treasures; ti++) |
322 | { |
322 | { |
323 | i = rmg_rndm (RP->Xsize - 2) + 1; |
323 | i = rmg_rndm (RP->Xsize - 2) + 1; |
… | |
… | |
447 | /* 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. */ |
448 | |
448 | |
449 | static object *theMonsterToFind; |
449 | static object *theMonsterToFind; |
450 | |
450 | |
451 | /* 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. |
452 | 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 */ |
453 | static object * |
453 | static object * |
454 | 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) |
455 | { |
455 | { |
456 | int i, j; |
456 | int i, j; |
457 | |
457 | |
458 | /* if we've found a monster already, leave */ |
458 | /* if we've found a monster already, leave */ |
459 | if (theMonsterToFind != NULL) |
459 | if (theMonsterToFind != NULL) |
… | |
… | |
462 | /* bounds check x and y */ |
462 | /* bounds check x and y */ |
463 | if (!(x >= 0 && y >= 0 && x < RP->Xsize && y < RP->Ysize)) |
463 | if (!(x >= 0 && y >= 0 && x < RP->Xsize && y < RP->Ysize)) |
464 | return theMonsterToFind; |
464 | return theMonsterToFind; |
465 | |
465 | |
466 | /* if the square is blocked or searched already, leave */ |
466 | /* if the square is blocked or searched already, leave */ |
467 | if (layout[x][y] != 0) |
467 | if (maze[x][y] != 0) |
468 | return theMonsterToFind; /* might be NULL, that's fine. */ |
468 | return theMonsterToFind; /* might be NULL, that's fine. */ |
469 | |
469 | |
470 | /* check the current square for a monster. If there is one, |
470 | /* check the current square for a monster. If there is one, |
471 | set theMonsterToFind and return it. */ |
471 | set theMonsterToFind and return it. */ |
472 | layout[x][y] = 1; |
472 | maze[x][y] = 1; |
473 | if (GET_MAP_FLAGS (map, x, y) & P_IS_ALIVE) |
473 | if (GET_MAP_FLAGS (map, x, y) & P_IS_ALIVE) |
474 | { |
474 | { |
475 | object *the_monster = GET_MAP_OB (map, x, y); |
475 | object *the_monster = GET_MAP_OB (map, x, y); |
476 | |
476 | |
477 | /* check off this point */ |
477 | /* check off this point */ |
… | |
… | |
484 | } |
484 | } |
485 | |
485 | |
486 | /* 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 */ |
487 | 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++) |
488 | { |
488 | { |
489 | 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); |
490 | if (theMonsterToFind != NULL) |
490 | if (theMonsterToFind != NULL) |
491 | return theMonsterToFind; |
491 | return theMonsterToFind; |
492 | } |
492 | } |
493 | |
493 | |
494 | return theMonsterToFind; |
494 | return theMonsterToFind; |
… | |
… | |
497 | /* sets up some data structures: the _recursive form does the |
497 | /* sets up some data structures: the _recursive form does the |
498 | real work. */ |
498 | real work. */ |
499 | static object * |
499 | static object * |
500 | 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) |
501 | { |
501 | { |
502 | Layout layout2 (map->width, map->height); |
502 | layout layout2 (map->width, map->height); |
503 | |
503 | |
504 | // find walls |
504 | // find walls |
505 | for (int i = 0; i < layout2.w; i++) |
505 | for (int i = 0; i < layout2.w; i++) |
506 | for (int j = 0; j < layout2.h; j++) |
506 | for (int j = 0; j < layout2.h; j++) |
507 | layout2[i][j] = wall_blocked (map, i, j) ? '#' : 0; |
507 | layout2[i][j] = wall_blocked (map, i, j) ? '#' : 0; |
… | |
… | |
519 | |
519 | |
520 | /* the workhorse routine, which finds the free spots in a room: |
520 | /* the workhorse routine, which finds the free spots in a room: |
521 | 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 |
522 | that datastructure. */ |
522 | that datastructure. */ |
523 | static void |
523 | static void |
524 | 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) |
525 | { |
525 | { |
526 | int i, j; |
526 | int i, j; |
527 | |
527 | |
528 | /* bounds check x and y */ |
528 | /* bounds check x and y */ |
529 | if (!(x >= 0 && y >= 0 && x < RP->Xsize && y < RP->Ysize)) |
529 | if (!(x >= 0 && y >= 0 && x < RP->Xsize && y < RP->Ysize)) |
530 | return; |
530 | return; |
531 | |
531 | |
532 | /* if the square is blocked or searched already, leave */ |
532 | /* if the square is blocked or searched already, leave */ |
533 | if (layout[x][y] != 0) |
533 | if (maze[x][y] != 0) |
534 | return; |
534 | return; |
535 | |
535 | |
536 | /* 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. |
537 | set theMonsterToFind and return it. */ |
537 | set theMonsterToFind and return it. */ |
538 | /* check off this point */ |
538 | /* check off this point */ |
539 | layout[x][y] = 1; |
539 | maze[x][y] = 1; |
540 | room_free_spots_x[number_of_free_spots_in_room] = x; |
540 | room_free_spots_x[number_of_free_spots_in_room] = x; |
541 | room_free_spots_y[number_of_free_spots_in_room] = y; |
541 | room_free_spots_y[number_of_free_spots_in_room] = y; |
542 | number_of_free_spots_in_room++; |
542 | number_of_free_spots_in_room++; |
543 | |
543 | |
544 | /* 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 */ |
545 | 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++) |
546 | 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); |
547 | |
547 | |
548 | } |
548 | } |
549 | |
549 | |
550 | /* 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. */ |
551 | static void |
551 | static void |
… | |
… | |
557 | number_of_free_spots_in_room = 0; |
557 | number_of_free_spots_in_room = 0; |
558 | 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); |
559 | 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); |
560 | |
560 | |
561 | layout2 = (char **) calloc (sizeof (char *), RP->Xsize); |
561 | layout2 = (char **) calloc (sizeof (char *), RP->Xsize); |
562 | /* allocate and copy the layout, converting C to 0. */ |
562 | /* allocate and copy the maze, converting C to 0. */ |
563 | for (i = 0; i < RP->Xsize; i++) |
563 | for (i = 0; i < RP->Xsize; i++) |
564 | { |
564 | { |
565 | layout2[i] = (char *) calloc (sizeof (char), RP->Ysize); |
565 | layout2[i] = (char *) calloc (sizeof (char), RP->Ysize); |
566 | for (j = 0; j < RP->Ysize; j++) |
566 | for (j = 0; j < RP->Ysize; j++) |
567 | if (wall_blocked (map, i, j)) |
567 | if (wall_blocked (map, i, j)) |
… | |
… | |
576 | i = rmg_rndm (number_of_free_spots_in_room); |
576 | i = rmg_rndm (number_of_free_spots_in_room); |
577 | *kx = room_free_spots_x[i]; |
577 | *kx = room_free_spots_x[i]; |
578 | *ky = room_free_spots_y[i]; |
578 | *ky = room_free_spots_y[i]; |
579 | } |
579 | } |
580 | |
580 | |
581 | /* deallocate the temp. layout */ |
581 | /* deallocate the temp. maze */ |
582 | for (i = 0; i < RP->Xsize; i++) |
582 | for (i = 0; i < RP->Xsize; i++) |
583 | free (layout2[i]); |
583 | free (layout2[i]); |
584 | |
584 | |
585 | free (layout2); |
585 | free (layout2); |
586 | free (room_free_spots_x); |
586 | free (room_free_spots_x); |
… | |
… | |
682 | |
682 | |
683 | /* 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 |
684 | 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 |
685 | it'll remove any monsters it finds.*/ |
685 | it'll remove any monsters it finds.*/ |
686 | static object ** |
686 | static object ** |
687 | 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) |
688 | { |
688 | { |
689 | int i; |
689 | int i; |
690 | const char *doors[2]; |
690 | const char *doors[2]; |
691 | object **doorlist; |
691 | object **doorlist; |
692 | int ndoors_made = 0; |
692 | int ndoors_made = 0; |
… | |
… | |
707 | /* place doors in all the 8 adjacent unblocked squares. */ |
707 | /* place doors in all the 8 adjacent unblocked squares. */ |
708 | for (i = 1; i < 9; i++) |
708 | for (i = 1; i < 9; i++) |
709 | { |
709 | { |
710 | int x1 = x + freearr_x[i], y1 = y + freearr_y[i]; |
710 | int x1 = x + freearr_x[i], y1 = y + freearr_y[i]; |
711 | |
711 | |
712 | if (!wall_blocked (map, x1, y1) && layout[x1][y1] == '>') |
712 | if (!wall_blocked (map, x1, y1) && maze[x1][y1] == '>') |
713 | { /* place a door */ |
713 | { /* place a door */ |
714 | remove_monsters (x1, y1, map); |
714 | remove_monsters (x1, y1, map); |
715 | |
715 | |
716 | 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]); |
717 | map->insert (new_door, x1, y1); |
717 | map->insert (new_door, x1, y1); |
… | |
… | |
734 | return NULL; |
734 | return NULL; |
735 | } |
735 | } |
736 | |
736 | |
737 | /* the workhorse routine, which finds the doors in a room */ |
737 | /* the workhorse routine, which finds the doors in a room */ |
738 | static void |
738 | static void |
739 | 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) |
740 | { |
740 | { |
741 | int i, j; |
741 | int i, j; |
742 | object *door; |
742 | object *door; |
743 | |
743 | |
744 | /* bounds check x and y */ |
744 | /* bounds check x and y */ |
745 | if (!(x >= 0 && y >= 0 && x < RP->Xsize && y < RP->Ysize)) |
745 | if (!(x >= 0 && y >= 0 && x < RP->Xsize && y < RP->Ysize)) |
746 | return; |
746 | return; |
747 | |
747 | |
748 | /* if the square is blocked or searched already, leave */ |
748 | /* if the square is blocked or searched already, leave */ |
749 | if (layout[x][y] == 1) |
749 | if (maze[x][y] == 1) |
750 | return; |
750 | return; |
751 | |
751 | |
752 | /* check off this point */ |
752 | /* check off this point */ |
753 | if (layout[x][y] == '#') |
753 | if (maze[x][y] == '#') |
754 | { /* there could be a door here */ |
754 | { /* there could be a door here */ |
755 | layout[x][y] = 1; |
755 | maze[x][y] = 1; |
756 | door = door_in_square (map, x, y); |
756 | door = door_in_square (map, x, y); |
757 | if (door) |
757 | if (door) |
758 | { |
758 | { |
759 | doorlist[*ndoors] = door; |
759 | doorlist[*ndoors] = door; |
760 | |
760 | |
… | |
… | |
767 | *ndoors = *ndoors + 1; |
767 | *ndoors = *ndoors + 1; |
768 | } |
768 | } |
769 | } |
769 | } |
770 | else |
770 | else |
771 | { |
771 | { |
772 | layout[x][y] = 1; |
772 | maze[x][y] = 1; |
773 | |
773 | |
774 | /* 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 */ |
775 | 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++) |
776 | find_doors_in_room_recursive (layout, map, |
776 | find_doors_in_room_recursive (maze, map, |
777 | 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], |
778 | doorlist, ndoors, RP); |
778 | doorlist, ndoors, RP); |
779 | } |
779 | } |
780 | } |
780 | } |
781 | |
781 | |
… | |
… | |
786 | int i, j; |
786 | int i, j; |
787 | int ndoors = 0; |
787 | int ndoors = 0; |
788 | |
788 | |
789 | object **doorlist = (object **)calloc (sizeof (int), 1024); |
789 | object **doorlist = (object **)calloc (sizeof (int), 1024); |
790 | |
790 | |
791 | Layout layout2 (RP->Xsize, RP->Ysize); |
791 | layout layout2 (RP->Xsize, RP->Ysize); |
792 | layout2.clear (); |
792 | layout2.clear (); |
793 | |
793 | |
794 | /* allocate and copy the layout, converting C to 0. */ |
794 | /* allocate and copy the maze, converting C to 0. */ |
795 | for (i = 0; i < RP->Xsize; i++) |
795 | for (i = 0; i < RP->Xsize; i++) |
796 | for (j = 0; j < RP->Ysize; j++) |
796 | for (j = 0; j < RP->Ysize; j++) |
797 | layout2[i][j] = wall_blocked (map, i, j) ? '#' : 0; |
797 | layout2[i][j] = wall_blocked (map, i, j) ? '#' : 0; |
798 | |
798 | |
799 | /* setup num_free_spots and room_free_spots */ |
799 | /* setup num_free_spots and room_free_spots */ |