00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00034 #include <global.h>
00035 #include <random_map.h>
00036 #include <rproto.h>
00037
00055 int surround_check2(char **layout, int i, int j, int Xsize, int Ysize) {
00056 int surround_index = 0;
00057
00058 if ((i > 0) && (layout[i-1][j] == 'D' || layout[i-1][j] == '#'))
00059 surround_index += 1;
00060 if ((i < Xsize-1) && (layout[i+1][j] == 'D' || layout[i+1][j] == '#'))
00061 surround_index += 2;
00062 if ((j > 0) && (layout[i][j-1] == 'D' || layout[i][j-1] == '#'))
00063 surround_index += 4;
00064 if ((j < Ysize-1) && (layout[i][j+1] == 'D' && layout[i][j+1] == '#'))
00065 surround_index += 8;
00066 return surround_index;
00067 }
00068
00080 void put_doors(mapstruct *the_map, char **maze, const char *doorstyle, RMParms *RP) {
00081 int i, j;
00082 mapstruct *vdoors;
00083 mapstruct *hdoors;
00084 char doorpath[128];
00085
00086 if (!strcmp(doorstyle, "none"))
00087 return;
00088 vdoors = find_style("/styles/doorstyles", doorstyle, -1);
00089 if (vdoors)
00090 hdoors = vdoors;
00091 else {
00092 vdoors = find_style("/styles/doorstyles/vdoors", doorstyle, -1);
00093 if (!vdoors)
00094 return;
00095 snprintf(doorpath, sizeof(doorpath), "/styles/doorstyles/hdoors%s", strrchr(vdoors->path, '/'));
00096 hdoors = find_style(doorpath, NULL, -1);
00097 }
00098
00099 for (i = 0; i < RP->Xsize; i++)
00100 for (j = 0; j < RP->Ysize; j++) {
00101 if (maze[i][j] == 'D') {
00102 int sindex;
00103 object *this_door, *new_door;
00104
00105 sindex = surround_check2(maze, i, j, RP->Xsize, RP->Ysize);
00106 if (sindex == 3)
00107 this_door = pick_random_object(hdoors);
00108 else
00109 this_door = pick_random_object(vdoors);
00110 new_door = arch_to_object(this_door->arch);
00111 copy_object(this_door, new_door);
00112 new_door->x = i;
00113 new_door->y = j;
00114 insert_ob_in_map(new_door, the_map, NULL, 0);
00115 }
00116 }
00117 }