| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
#include "global.h" |
| 15 |
|
| 16 |
#include <stdlib.h> |
| 17 |
#include <string.h> |
| 18 |
|
| 19 |
#include "random_map.h" |
| 20 |
#include "rproto.h" |
| 21 |
#include "sproto.h" |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
void find_in_layout(int mode, char target, int *fx, int *fy, char **layout, RMParms *RP) |
| 48 |
{ |
| 49 |
int M; |
| 50 |
int i, j; |
| 51 |
|
| 52 |
*fx = -1; |
| 53 |
*fy = -1; |
| 54 |
|
| 55 |
|
| 56 |
if (mode < 1 || mode > 4) { |
| 57 |
M = RANDOM()%4+1; |
| 58 |
} else { |
| 59 |
M = mode; |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
switch (M) { |
| 66 |
case 1: { |
| 67 |
for (i = 1; i < RP->Xsize; i++) |
| 68 |
for (j = 1; j < RP->Ysize; j++) { |
| 69 |
if (layout[i][j] == target) { |
| 70 |
*fx = i; |
| 71 |
*fy = j; |
| 72 |
return; |
| 73 |
} |
| 74 |
} |
| 75 |
break; |
| 76 |
} |
| 77 |
|
| 78 |
case 2: { |
| 79 |
for (i = RP->Xsize-2; i > 0; i--) |
| 80 |
for (j = 1; j < RP->Ysize-1; j++) { |
| 81 |
if (layout[i][j] == target) { |
| 82 |
*fx = i; |
| 83 |
*fy = j; |
| 84 |
return; |
| 85 |
} |
| 86 |
} |
| 87 |
break; |
| 88 |
} |
| 89 |
|
| 90 |
case 3: { |
| 91 |
for (i = 1; i < RP->Xsize-1; i++) |
| 92 |
for (j = RP->Ysize-2; j > 0; j--) { |
| 93 |
if (layout[i][j] == target) { |
| 94 |
*fx = i; |
| 95 |
*fy = j; |
| 96 |
return; |
| 97 |
} |
| 98 |
} |
| 99 |
break; |
| 100 |
} |
| 101 |
|
| 102 |
case 4: { |
| 103 |
for (i = RP->Xsize-2; i > 0; i--) |
| 104 |
for (j = RP->Ysize-2; j > 0; j--) { |
| 105 |
if (layout[i][j] == target) { |
| 106 |
*fx = i; |
| 107 |
*fy = j; |
| 108 |
return; |
| 109 |
} |
| 110 |
} |
| 111 |
break; |
| 112 |
} |
| 113 |
} |
| 114 |
} |
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
void place_exits(mapstruct *map, char **maze, char *exitstyle, int orientation, RMParms *RP) |
| 145 |
{ |
| 146 |
char styledirname[256]; |
| 147 |
mapstruct *style_map_down = NULL; |
| 148 |
mapstruct *style_map_up = NULL; |
| 149 |
object *the_exit_down; |
| 150 |
object *the_exit_up; |
| 151 |
object *random_sign; |
| 152 |
char buf[512]; |
| 153 |
int cx = -1, cy = -1; |
| 154 |
int upx = -1, upy = -1; |
| 155 |
int downx = -1, downy = -1; |
| 156 |
int final_map_exit = 1; |
| 157 |
int i, j; |
| 158 |
|
| 159 |
if (strstr(RP->exit_on_final_map, "no")) { |
| 160 |
final_map_exit = 0; |
| 161 |
} |
| 162 |
|
| 163 |
if (orientation == 0) { |
| 164 |
orientation = RANDOM()%6+1; |
| 165 |
} |
| 166 |
|
| 167 |
switch (orientation) { |
| 168 |
case 1: { |
| 169 |
snprintf(styledirname, sizeof(styledirname), "/styles/exitstyles/up"); |
| 170 |
style_map_up = find_style(styledirname, exitstyle, -1); |
| 171 |
snprintf(styledirname, sizeof(styledirname), "/styles/exitstyles/down"); |
| 172 |
style_map_down = find_style(styledirname, exitstyle, -1); |
| 173 |
break; |
| 174 |
} |
| 175 |
|
| 176 |
case 2: { |
| 177 |
snprintf(styledirname, sizeof(styledirname), "/styles/exitstyles/down"); |
| 178 |
style_map_up = find_style(styledirname, exitstyle, -1); |
| 179 |
snprintf(styledirname, sizeof(styledirname), "/styles/exitstyles/up"); |
| 180 |
style_map_down = find_style(styledirname, exitstyle, -1); |
| 181 |
break; |
| 182 |
} |
| 183 |
|
| 184 |
default: { |
| 185 |
snprintf(styledirname, sizeof(styledirname), "/styles/exitstyles/generic"); |
| 186 |
style_map_up = find_style(styledirname, exitstyle, -1); |
| 187 |
style_map_down = style_map_up; |
| 188 |
break; |
| 189 |
} |
| 190 |
} |
| 191 |
|
| 192 |
if (style_map_up == NULL) { |
| 193 |
archetype *exit_arch = find_archetype("exit"); |
| 194 |
if (exit_arch == NULL) { |
| 195 |
return; |
| 196 |
} |
| 197 |
the_exit_up = arch_to_object(exit_arch); |
| 198 |
} else { |
| 199 |
object *tmp; |
| 200 |
|
| 201 |
tmp = pick_random_object(style_map_up); |
| 202 |
the_exit_up = arch_to_object(tmp->arch); |
| 203 |
} |
| 204 |
|
| 205 |
|
| 206 |
if (RP->dungeon_level < RP->dungeon_depth || RP->final_map[0] != 0) |
| 207 |
if (RP->dungeon_level >= RP->dungeon_depth && RP->final_exit_archetype[0] != 0) { |
| 208 |
archetype *arch = find_archetype(RP->final_exit_archetype); |
| 209 |
if (arch == NULL) { |
| 210 |
return; |
| 211 |
} |
| 212 |
the_exit_down = arch_to_object(arch); |
| 213 |
} else if (style_map_down == NULL) { |
| 214 |
archetype *arch = find_archetype("exit"); |
| 215 |
if (arch == NULL) { |
| 216 |
return; |
| 217 |
} |
| 218 |
the_exit_down = arch_to_object(arch); |
| 219 |
} else { |
| 220 |
object *tmp; |
| 221 |
|
| 222 |
tmp = pick_random_object(style_map_down); |
| 223 |
the_exit_down = arch_to_object(tmp->arch); |
| 224 |
} |
| 225 |
else { |
| 226 |
the_exit_down = NULL; |
| 227 |
} |
| 228 |
|
| 229 |
|
| 230 |
the_exit_up->stats.hp = RP->origin_x; |
| 231 |
the_exit_up->stats.sp = RP->origin_y; |
| 232 |
the_exit_up->slaying = add_string(RP->origin_map); |
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
find_in_layout(0, '<', &upx, &upy, maze, RP); |
| 237 |
|
| 238 |
|
| 239 |
find_in_layout(0, 'C', &cx, &cy, maze, RP); |
| 240 |
|
| 241 |
|
| 242 |
if (upx == -1 && cx != -1) { |
| 243 |
if (cx > RP->Xsize/2) { |
| 244 |
upx = 1; |
| 245 |
} else { |
| 246 |
upx = RP->Xsize-2; |
| 247 |
} |
| 248 |
if (cy > RP->Ysize/2) { |
| 249 |
upy = 1; |
| 250 |
} else { |
| 251 |
upy = RP->Ysize-2; |
| 252 |
} |
| 253 |
|
| 254 |
|
| 255 |
if (upx == 1 && upy == 1) { |
| 256 |
find_in_layout(1, 0, &upx, &upy, maze, RP); |
| 257 |
} else if (upx == 1 && upy > 1) { |
| 258 |
find_in_layout(3, 0, &upx, &upy, maze, RP); |
| 259 |
} else if (upx > 1 && upy == 1) { |
| 260 |
find_in_layout(2, 0, &upx, &upy, maze, RP); |
| 261 |
} else if (upx > 1 && upy > 1) { |
| 262 |
find_in_layout(4, 0, &upx, &upy, maze, RP); |
| 263 |
} |
| 264 |
} |
| 265 |
|
| 266 |
|
| 267 |
if (upx == -1) { |
| 268 |
find_in_layout(0, 0, &upx, &upy, maze, RP); |
| 269 |
} |
| 270 |
|
| 271 |
|
| 272 |
for (j = 1; j < 9; j++) { |
| 273 |
if (!wall_blocked(map, upx+freearr_x[j], upy+freearr_y[j])) { |
| 274 |
random_sign = create_archetype("sign"); |
| 275 |
|
| 276 |
snprintf(buf, sizeof(buf), "This is a random map.\nLevel: %d\n", (RP->dungeon_level)-1); |
| 277 |
object_set_msg(random_sign, buf); |
| 278 |
object_insert_in_map_at(random_sign, map, NULL, 0, upx+freearr_x[j], upy+freearr_y[j]); |
| 279 |
} |
| 280 |
} |
| 281 |
|
| 282 |
the_exit_up->move_block = MOVE_ALL; |
| 283 |
|
| 284 |
object_insert_in_map_at(the_exit_up, map, NULL, 0, upx, upy); |
| 285 |
maze[upx][upy] = '<'; |
| 286 |
|
| 287 |
|
| 288 |
MAP_ENTER_X(map) = upx; |
| 289 |
MAP_ENTER_Y(map) = upy; |
| 290 |
|
| 291 |
|
| 292 |
find_in_layout(0, '>', &downx, &downy, maze, RP); |
| 293 |
|
| 294 |
if (downx == -1) { |
| 295 |
downx = cx; |
| 296 |
downy = cy; |
| 297 |
} |
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
if (downx == -1) { |
| 302 |
if (upx > RP->Xsize/2) { |
| 303 |
downx = 1; |
| 304 |
} else { |
| 305 |
downx = RP->Xsize-2; |
| 306 |
} |
| 307 |
if (upy > RP->Ysize/2) { |
| 308 |
downy = 1; |
| 309 |
} else { |
| 310 |
downy = RP->Ysize-2; |
| 311 |
} |
| 312 |
|
| 313 |
|
| 314 |
if (downx == 1 && downy == 1) { |
| 315 |
find_in_layout(1, 0, &downx, &downy, maze, RP); |
| 316 |
} else if (downx == 1 && downy > 1) { |
| 317 |
find_in_layout(3, 0, &downx, &downy, maze, RP); |
| 318 |
} else if (downx > 1 && downy == 1) { |
| 319 |
find_in_layout(2, 0, &downx, &downy, maze, RP); |
| 320 |
} else if (downx > 1 && downy > 1) { |
| 321 |
find_in_layout(4, 0, &downx, &downy, maze, RP); |
| 322 |
} |
| 323 |
} |
| 324 |
|
| 325 |
if (downx == -1) { |
| 326 |
find_in_layout(0, 0, &downx, &downy, maze, RP); |
| 327 |
} |
| 328 |
if (the_exit_down) { |
| 329 |
char *buf; |
| 330 |
|
| 331 |
i = object_find_first_free_spot(the_exit_down, map, downx, downy); |
| 332 |
RP->origin_x = downx+freearr_x[i]; |
| 333 |
RP->origin_y = downy+freearr_y[i]; |
| 334 |
buf = stringbuffer_finish(write_map_parameters_to_string(RP)); |
| 335 |
object_set_msg(the_exit_down, buf); |
| 336 |
free(buf); |
| 337 |
|
| 338 |
if (RP->dungeon_level >= RP->dungeon_depth && RP->final_map[0] != 0) { |
| 339 |
|
| 340 |
mapstruct *new_map; |
| 341 |
object *the_exit_back = arch_to_object(the_exit_up->arch); |
| 342 |
|
| 343 |
|
| 344 |
if ((new_map = ready_map_name(RP->final_map, 0)) == NULL) { |
| 345 |
return; |
| 346 |
} |
| 347 |
|
| 348 |
the_exit_down->slaying = add_string(RP->final_map); |
| 349 |
EXIT_X(the_exit_down) = MAP_ENTER_X(new_map); |
| 350 |
EXIT_Y(the_exit_down) = MAP_ENTER_Y(new_map); |
| 351 |
strncpy(new_map->path, RP->final_map, sizeof(new_map->path)); |
| 352 |
|
| 353 |
FOR_MAP_PREPARE(new_map, MAP_ENTER_X(new_map), MAP_ENTER_Y(new_map), tmp) |
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
if (tmp->type == EXIT && EXIT_PATH(tmp) && !strncmp(EXIT_PATH(tmp), "/random/", 8)) { |
| 360 |
object_remove(tmp); |
| 361 |
object_free_drop_inventory(tmp); |
| 362 |
break; |
| 363 |
} |
| 364 |
FOR_MAP_FINISH(); |
| 365 |
|
| 366 |
if (final_map_exit == 1) { |
| 367 |
|
| 368 |
the_exit_back->slaying = add_string(map->path); |
| 369 |
the_exit_back->stats.hp = downx+freearr_x[i]; |
| 370 |
the_exit_back->stats.sp = downy+freearr_y[i]; |
| 371 |
object_insert_in_map_at(the_exit_back, new_map, NULL, 0, MAP_ENTER_X(new_map), MAP_ENTER_Y(new_map)); |
| 372 |
} |
| 373 |
|
| 374 |
set_map_timeout(new_map); |
| 375 |
} else { |
| 376 |
the_exit_down->slaying = add_string("/!"); |
| 377 |
} |
| 378 |
|
| 379 |
|
| 380 |
the_exit_down->move_block = MOVE_ALL; |
| 381 |
object_insert_in_map_at(the_exit_down, map, NULL, 0, downx+freearr_x[i], downy+freearr_y[i]); |
| 382 |
maze[the_exit_down->x][the_exit_down->y] = '>'; |
| 383 |
} |
| 384 |
} |
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
void unblock_exits(mapstruct *map, char **maze, RMParms *RP) |
| 398 |
{ |
| 399 |
int i = 0, j = 0; |
| 400 |
|
| 401 |
for (i = 0; i < RP->Xsize; i++) |
| 402 |
for (j = 0; j < RP->Ysize; j++) |
| 403 |
if (maze[i][j] == '>' || maze[i][j] == '<') { |
| 404 |
FOR_MAP_PREPARE(map, i, j, walk) { |
| 405 |
if (walk->move_block == MOVE_ALL && walk->type != LOCKED_DOOR) { |
| 406 |
walk->move_block = MOVE_BLOCK_DEFAULT; |
| 407 |
object_update(walk, UP_OBJ_CHANGE); |
| 408 |
} |
| 409 |
} |
| 410 |
FOR_MAP_FINISH(); |
| 411 |
} |
| 412 |
} |