| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
#include "global.h" |
| 15 |
|
| 16 |
#include <string.h> |
| 17 |
|
| 18 |
#include "random_map.h" |
| 19 |
#include "rproto.h" |
| 20 |
#include <assert.h> |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
int surround_flag(char **layout, int i, int j, RMParms *RP) |
| 41 |
{ |
| 42 |
int surround_index = 0; |
| 43 |
|
| 44 |
if ((i > 0) && layout[i-1][j] != 0) { |
| 45 |
surround_index |= 1; |
| 46 |
} |
| 47 |
if ((i < RP->Xsize-1) && layout[i+1][j] != 0) { |
| 48 |
surround_index |= 2; |
| 49 |
} |
| 50 |
if ((j > 0) && layout[i][j-1] != 0) { |
| 51 |
surround_index |= 4; |
| 52 |
} |
| 53 |
if ((j < RP->Ysize-1) && layout[i][j+1] != 0) { |
| 54 |
surround_index |= 8; |
| 55 |
} |
| 56 |
return surround_index; |
| 57 |
} |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
int surround_flag2(char **layout, int i, int j, RMParms *RP) |
| 78 |
{ |
| 79 |
int surround_index = 0; |
| 80 |
|
| 81 |
if ((i > 0) && layout[i-1][j] == '#') { |
| 82 |
surround_index |= 1; |
| 83 |
} |
| 84 |
if ((i < RP->Xsize-1) && layout[i+1][j] == '#') { |
| 85 |
surround_index |= 2; |
| 86 |
} |
| 87 |
if ((j > 0) && layout[i][j-1] == '#') { |
| 88 |
surround_index |= 4; |
| 89 |
} |
| 90 |
if ((j < RP->Ysize-1) && layout[i][j+1] == '#') { |
| 91 |
surround_index |= 8; |
| 92 |
} |
| 93 |
return surround_index; |
| 94 |
} |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
int surround_flag3(mapstruct *map, int i, int j, RMParms *RP) |
| 115 |
{ |
| 116 |
int surround_index = 0; |
| 117 |
|
| 118 |
if ((i > 0) && (GET_MAP_MOVE_BLOCK(map, i-1, j)&~MOVE_BLOCK_DEFAULT)) { |
| 119 |
surround_index |= 1; |
| 120 |
} |
| 121 |
if ((i < RP->Xsize-1) && (GET_MAP_MOVE_BLOCK(map, i+1, j)&~MOVE_BLOCK_DEFAULT)) { |
| 122 |
surround_index |= 2; |
| 123 |
} |
| 124 |
if ((j > 0) && (GET_MAP_MOVE_BLOCK(map, i, j-1)&~MOVE_BLOCK_DEFAULT)) { |
| 125 |
surround_index |= 4; |
| 126 |
} |
| 127 |
if ((j < RP->Ysize-1) && (GET_MAP_MOVE_BLOCK(map, i, j+1)&~MOVE_BLOCK_DEFAULT)) { |
| 128 |
surround_index |= 8; |
| 129 |
} |
| 130 |
|
| 131 |
return surround_index; |
| 132 |
} |
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
int surround_flag4(mapstruct *map, int i, int j, RMParms *RP) |
| 153 |
{ |
| 154 |
int surround_index = 0; |
| 155 |
|
| 156 |
if ((i > 0) && wall_blocked(map, i-1, j)) { |
| 157 |
surround_index |= 1; |
| 158 |
} |
| 159 |
if ((i < RP->Xsize-1) && wall_blocked(map, i+1, j)) { |
| 160 |
surround_index |= 2; |
| 161 |
} |
| 162 |
if ((j > 0) && wall_blocked(map, i, j-1)) { |
| 163 |
surround_index |= 4; |
| 164 |
} |
| 165 |
if ((j < RP->Ysize-1) && wall_blocked(map, i, j+1)) { |
| 166 |
surround_index |= 8; |
| 167 |
} |
| 168 |
|
| 169 |
return surround_index; |
| 170 |
} |
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
void make_map_walls(mapstruct *map, char **layout, char *w_style, RMParms *RP) |
| 185 |
{ |
| 186 |
mapstruct *style_map = NULL; |
| 187 |
object *the_wall; |
| 188 |
|
| 189 |
|
| 190 |
if (!strcmp(w_style, "none")) { |
| 191 |
return; |
| 192 |
} |
| 193 |
const char *styledirname = "/styles/wallstyles"; |
| 194 |
style_map = find_style(styledirname, w_style, -1); |
| 195 |
if (style_map == NULL) { |
| 196 |
return; |
| 197 |
} |
| 198 |
|
| 199 |
|
| 200 |
if ((the_wall = pick_random_object(style_map)) != NULL) { |
| 201 |
int i, j; |
| 202 |
char *cp; |
| 203 |
int joinedwalls = 0; |
| 204 |
object *thiswall; |
| 205 |
|
| 206 |
strlcpy(RP->wall_name, the_wall->arch->name, sizeof(RP->wall_name)); |
| 207 |
if ((cp = strchr(RP->wall_name, '_')) != NULL) { |
| 208 |
*cp = 0; |
| 209 |
joinedwalls = 1; |
| 210 |
} |
| 211 |
|
| 212 |
for (i = 0; i < RP->Xsize; i++) |
| 213 |
for (j = 0; j < RP->Ysize; j++) { |
| 214 |
if (layout[i][j] == '#') { |
| 215 |
if (joinedwalls) { |
| 216 |
thiswall = pick_joined_wall(the_wall, layout, i, j, RP); |
| 217 |
} else { |
| 218 |
thiswall = arch_to_object(the_wall->arch); |
| 219 |
} |
| 220 |
thiswall->move_block = MOVE_ALL; |
| 221 |
thiswall->move_allow = 0; |
| 222 |
object_insert_in_map_at(thiswall, map, thiswall, INS_NO_MERGE|INS_NO_WALK_ON, i, j); |
| 223 |
} |
| 224 |
} |
| 225 |
} |
| 226 |
} |
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
static const char* wall_join[16] = { |
| 233 |
"_0", "_1_3", "_1_4", "_2_1_2", |
| 234 |
"_1_2", "_2_2_4", "_2_2_1", "_3_1", |
| 235 |
"_1_1", "_2_2_3", "_2_2_2", "_3_3", |
| 236 |
"_2_1_1", "_3_4", "_3_2", "_4" |
| 237 |
}; |
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
object *pick_joined_wall(object *the_wall, char **layout, int i, int j, RMParms *RP) |
| 256 |
{ |
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
int surround_index = 0; |
| 262 |
int l; |
| 263 |
char wall_name[64]; |
| 264 |
archetype *wall_arch = NULL; |
| 265 |
|
| 266 |
strncpy(wall_name, the_wall->arch->name, sizeof(wall_name)); |
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
for (l = 0; l < 64; l++) { |
| 276 |
if (wall_name[l] == '_') { |
| 277 |
wall_name[l] = 0; |
| 278 |
break; |
| 279 |
} |
| 280 |
} |
| 281 |
|
| 282 |
surround_index = surround_flag2(layout, i, j, RP); |
| 283 |
assert(surround_index >= 0 && surround_index < 16); |
| 284 |
strcat(wall_name, wall_join[surround_index]); |
| 285 |
|
| 286 |
wall_arch = try_find_archetype(wall_name); |
| 287 |
if (wall_arch) { |
| 288 |
return arch_to_object(wall_arch); |
| 289 |
} else { |
| 290 |
return arch_to_object(the_wall->arch); |
| 291 |
} |
| 292 |
} |
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
object *retrofit_joined_wall(mapstruct *the_map, int i, int j, int insert_flag, RMParms *RP) |
| 315 |
{ |
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
int surround_index = 0; |
| 322 |
int l; |
| 323 |
object *the_wall = NULL; |
| 324 |
object *new_wall = NULL; |
| 325 |
archetype *wall_arch = NULL; |
| 326 |
|
| 327 |
|
| 328 |
FOR_MAP_PREPARE(the_map, i, j, tmp) |
| 329 |
if ((tmp->move_type&MOVE_WALK) && tmp->type != EXIT && tmp->type != TELEPORTER) { |
| 330 |
the_wall = tmp; |
| 331 |
break; |
| 332 |
} |
| 333 |
FOR_MAP_FINISH(); |
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
if (the_wall && (the_wall->type == DOOR || the_wall->type == LOCKED_DOOR)) { |
| 339 |
the_wall = NULL; |
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
if (insert_flag == 0) { |
| 344 |
return NULL; |
| 345 |
} |
| 346 |
} else if (the_wall == NULL) { |
| 347 |
return NULL; |
| 348 |
} |
| 349 |
|
| 350 |
|
| 351 |
for (l = 0; l < 64; l++) { |
| 352 |
if (RP->wall_name[l] == '_') { |
| 353 |
RP->wall_name[l] = 0; |
| 354 |
break; |
| 355 |
} |
| 356 |
} |
| 357 |
|
| 358 |
surround_index = surround_flag4(the_map, i, j, RP); |
| 359 |
assert(surround_index >= 0 && surround_index < 16); |
| 360 |
strcat(RP->wall_name, wall_join[surround_index]); |
| 361 |
wall_arch = try_find_archetype(RP->wall_name); |
| 362 |
if (wall_arch != NULL) { |
| 363 |
new_wall = arch_to_object(wall_arch); |
| 364 |
if (the_wall && the_wall->map) { |
| 365 |
object_remove(the_wall); |
| 366 |
object_free_drop_inventory(the_wall); |
| 367 |
} |
| 368 |
the_wall->move_block = MOVE_ALL; |
| 369 |
object_insert_in_map_at(new_wall, the_map, new_wall, INS_NO_MERGE|INS_NO_WALK_ON, i, j); |
| 370 |
} |
| 371 |
return new_wall; |
| 372 |
} |