| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
#include "global.h" |
| 20 |
|
| 21 |
#include <string.h> |
| 22 |
|
| 23 |
#include "random_map.h" |
| 24 |
#include "rproto.h" |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
int surround_check2(char **layout, int i, int j, int Xsize, int Ysize) |
| 44 |
{ |
| 45 |
int surround_index = 0; |
| 46 |
|
| 47 |
if ((i > 0) && (layout[i-1][j] == 'D' || layout[i-1][j] == '#')) { |
| 48 |
surround_index += 1; |
| 49 |
} |
| 50 |
if ((i < Xsize-1) && (layout[i+1][j] == 'D' || layout[i+1][j] == '#')) { |
| 51 |
surround_index += 2; |
| 52 |
} |
| 53 |
if ((j > 0) && (layout[i][j-1] == 'D' || layout[i][j-1] == '#')) { |
| 54 |
surround_index += 4; |
| 55 |
} |
| 56 |
if ((j < Ysize-1) && (layout[i][j+1] == 'D' || layout[i][j+1] == '#')) { |
| 57 |
surround_index += 8; |
| 58 |
} |
| 59 |
return surround_index; |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
void put_doors(mapstruct *the_map, char **maze, const char *doorstyle, RMParms *RP) |
| 74 |
{ |
| 75 |
int i, j; |
| 76 |
mapstruct *vdoors; |
| 77 |
mapstruct *hdoors; |
| 78 |
char doorpath[128]; |
| 79 |
|
| 80 |
if (!strcmp(doorstyle, "none")) { |
| 81 |
return; |
| 82 |
} |
| 83 |
vdoors = find_style("/styles/doorstyles", doorstyle, -1); |
| 84 |
if (vdoors) { |
| 85 |
hdoors = vdoors; |
| 86 |
} else { |
| 87 |
vdoors = find_style("/styles/doorstyles/vdoors", doorstyle, -1); |
| 88 |
if (!vdoors) { |
| 89 |
return; |
| 90 |
} |
| 91 |
snprintf(doorpath, sizeof(doorpath), "/styles/doorstyles/hdoors%s", strrchr(vdoors->path, '/')); |
| 92 |
hdoors = find_style(doorpath, NULL, -1); |
| 93 |
} |
| 94 |
|
| 95 |
for (i = 0; i < RP->Xsize; i++) |
| 96 |
for (j = 0; j < RP->Ysize; j++) { |
| 97 |
if (maze[i][j] == 'D') { |
| 98 |
int sindex; |
| 99 |
object *this_door, *new_door; |
| 100 |
|
| 101 |
sindex = surround_check2(maze, i, j, RP->Xsize, RP->Ysize); |
| 102 |
if (sindex == 3) { |
| 103 |
this_door = pick_random_object(hdoors); |
| 104 |
} else { |
| 105 |
this_door = pick_random_object(vdoors); |
| 106 |
} |
| 107 |
new_door = arch_to_object(this_door->arch); |
| 108 |
object_copy(this_door, new_door); |
| 109 |
object_insert_in_map_at(new_door, the_map, NULL, 0, i, j); |
| 110 |
} |
| 111 |
} |
| 112 |
} |