… | |
… | |
486 | { |
486 | { |
487 | theMonsterToFind = find_monster_in_room_recursive (layout, map, x + freearr_x[i % 8 + 1], y + freearr_y[i % 8 + 1], RP); |
487 | theMonsterToFind = find_monster_in_room_recursive (layout, map, x + freearr_x[i % 8 + 1], y + freearr_y[i % 8 + 1], RP); |
488 | if (theMonsterToFind != NULL) |
488 | if (theMonsterToFind != NULL) |
489 | return theMonsterToFind; |
489 | return theMonsterToFind; |
490 | } |
490 | } |
|
|
491 | |
491 | return theMonsterToFind; |
492 | return theMonsterToFind; |
492 | } |
493 | } |
493 | |
|
|
494 | |
494 | |
495 | /* sets up some data structures: the _recursive form does the |
495 | /* sets up some data structures: the _recursive form does the |
496 | real work. */ |
496 | real work. */ |
497 | |
|
|
498 | object * |
497 | object * |
499 | find_monster_in_room (maptile *map, int x, int y, random_map_params *RP) |
498 | find_monster_in_room (maptile *map, int x, int y, random_map_params *RP) |
500 | { |
499 | { |
501 | char **layout2; |
500 | Layout layout2 (RP); |
502 | int i, j; |
501 | |
|
|
502 | layout2->clear (); |
|
|
503 | |
|
|
504 | /* allocate and copy the layout, converting C to 0. */ |
|
|
505 | for (int i = 0; i < layout2->w; i++) |
|
|
506 | for (int j = 0; j < layout2->h; j++) |
|
|
507 | if (wall_blocked (map, i, j)) |
|
|
508 | layout2[i][j] = '#'; |
503 | |
509 | |
504 | theMonsterToFind = 0; |
510 | theMonsterToFind = 0; |
505 | layout2 = (char **) calloc (sizeof (char *), RP->Xsize); |
|
|
506 | /* allocate and copy the layout, converting C to 0. */ |
|
|
507 | for (i = 0; i < RP->Xsize; i++) |
|
|
508 | { |
|
|
509 | layout2[i] = (char *) calloc (sizeof (char), RP->Ysize); |
|
|
510 | for (j = 0; j < RP->Ysize; j++) |
|
|
511 | if (wall_blocked (map, i, j)) |
|
|
512 | layout2[i][j] = '#'; |
|
|
513 | } |
|
|
514 | |
|
|
515 | theMonsterToFind = find_monster_in_room_recursive (layout2, map, x, y, RP); |
511 | theMonsterToFind = find_monster_in_room_recursive (layout2, map, x, y, RP); |
516 | |
512 | |
517 | /* deallocate the temp. layout */ |
513 | layout2.free (); |
518 | for (i = 0; i < RP->Xsize; i++) |
|
|
519 | free (layout2[i]); |
|
|
520 | |
|
|
521 | free (layout2); |
|
|
522 | |
514 | |
523 | return theMonsterToFind; |
515 | return theMonsterToFind; |
524 | } |
516 | } |
525 | |
517 | |
526 | /* a datastructure needed by find_spot_in_room and find_spot_in_room_recursive */ |
518 | /* a datastructure needed by find_spot_in_room and find_spot_in_room_recursive */ |
… | |
… | |
803 | int i, j; |
795 | int i, j; |
804 | int ndoors = 0; |
796 | int ndoors = 0; |
805 | |
797 | |
806 | object **doorlist = (object **)calloc (sizeof (int), 1024); |
798 | object **doorlist = (object **)calloc (sizeof (int), 1024); |
807 | |
799 | |
808 | MazeData layout2 (RP->Xsize, RP->Ysize); |
800 | LayoutData layout2 (RP->Xsize, RP->Ysize); |
|
|
801 | layout2.clear (); |
809 | |
802 | |
810 | /* allocate and copy the layout, converting C to 0. */ |
803 | /* allocate and copy the layout, converting C to 0. */ |
811 | for (i = 0; i < RP->Xsize; i++) |
804 | for (i = 0; i < RP->Xsize; i++) |
812 | for (j = 0; j < RP->Ysize; j++) |
805 | for (j = 0; j < RP->Ysize; j++) |
813 | if (wall_blocked (map, i, j)) |
806 | layout2[i][j] = wall_blocked (map, i, j) ? '#' : 0; |
814 | layout2[i][j] = '#'; |
|
|
815 | |
807 | |
816 | /* setup num_free_spots and room_free_spots */ |
808 | /* setup num_free_spots and room_free_spots */ |
817 | find_doors_in_room_recursive (layout2, map, x, y, doorlist, &ndoors, RP); |
809 | find_doors_in_room_recursive (layout2, map, x, y, doorlist, &ndoors, RP); |
818 | |
810 | |
819 | return doorlist; |
811 | return doorlist; |
… | |
… | |
863 | { |
855 | { |
864 | retrofit_joined_wall (map, door->x - 1, door->y, 0, RP); |
856 | retrofit_joined_wall (map, door->x - 1, door->y, 0, RP); |
865 | retrofit_joined_wall (map, door->x + 1, door->y, 0, RP); |
857 | retrofit_joined_wall (map, door->x + 1, door->y, 0, RP); |
866 | retrofit_joined_wall (map, door->x, door->y - 1, 0, RP); |
858 | retrofit_joined_wall (map, door->x, door->y - 1, 0, RP); |
867 | retrofit_joined_wall (map, door->x, door->y + 1, 0, RP); |
859 | retrofit_joined_wall (map, door->x, door->y + 1, 0, RP); |
|
|
860 | |
868 | door->face = wallface->face; |
861 | door->face = wallface->face; |
|
|
862 | |
869 | if (!QUERY_FLAG (wallface, FLAG_REMOVED)) |
863 | if (!QUERY_FLAG (wallface, FLAG_REMOVED)) |
870 | wallface->remove (); |
864 | wallface->remove (); |
|
|
865 | |
871 | wallface->destroy (); |
866 | wallface->destroy (); |
872 | } |
867 | } |
873 | } |
868 | } |
874 | } |
869 | } |
875 | } |
870 | } |