| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
#include "global.h" |
| 24 |
|
| 25 |
#include <ctype.h> |
| 26 |
#include <stdlib.h> |
| 27 |
#include <string.h> |
| 28 |
|
| 29 |
#include "living.h" |
| 30 |
#include "skills.h" |
| 31 |
#include "spells.h" |
| 32 |
#include "sproto.h" |
| 33 |
#include "tod.h" |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
static int can_build_over(struct mapdef *map, object *new_item, short x, short y) { |
| 49 |
FOR_MAP_PREPARE(map, x, y, tmp) { |
| 50 |
object *ob; |
| 51 |
|
| 52 |
ob = HEAD(tmp); |
| 53 |
if (strcmp(ob->arch->name, "rune_mark") == 0) |
| 54 |
|
| 55 |
continue; |
| 56 |
|
| 57 |
if (QUERY_FLAG(ob, FLAG_IS_BUILDABLE)) |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
continue; |
| 62 |
|
| 63 |
switch (new_item->type) { |
| 64 |
case SIGN: |
| 65 |
case MAGIC_EAR: |
| 66 |
|
| 67 |
if (ob->type != BOOK) |
| 68 |
return 0; |
| 69 |
break; |
| 70 |
|
| 71 |
case BUTTON: |
| 72 |
case DETECTOR: |
| 73 |
case PEDESTAL: |
| 74 |
case CF_HANDLE: |
| 75 |
|
| 76 |
if (ob->type != GATE && ob->type != DOOR) |
| 77 |
return 0; |
| 78 |
break; |
| 79 |
|
| 80 |
default: |
| 81 |
return 0; |
| 82 |
} |
| 83 |
} FOR_MAP_FINISH(); |
| 84 |
|
| 85 |
|
| 86 |
if (new_item->more) |
| 87 |
return can_build_over(map, new_item->more, x+new_item->more->arch->clone.x-new_item->arch->clone.x, y+new_item->more->arch->clone.y-new_item->arch->clone.y); |
| 88 |
|
| 89 |
return 1; |
| 90 |
} |
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
static object *get_connection_rune(object *pl, short x, short y) { |
| 104 |
FOR_MAP_PREPARE(pl->map, x, y, rune) |
| 105 |
if (rune->type == SIGN && strcmp(rune->arch->name, "rune_mark") == 0) |
| 106 |
return rune; |
| 107 |
FOR_MAP_FINISH(); |
| 108 |
return NULL; |
| 109 |
} |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
static object *get_msg_book(object *pl, short x, short y) { |
| 123 |
FOR_MAP_PREPARE(pl->map, x, y, book) |
| 124 |
if (book->type == BOOK) |
| 125 |
return book; |
| 126 |
FOR_MAP_FINISH(); |
| 127 |
return NULL; |
| 128 |
} |
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
static object *get_wall(struct mapdef *map, int x, int y) { |
| 143 |
FOR_MAP_PREPARE(map, x, y, wall) |
| 144 |
if (wall->type == WALL) |
| 145 |
return wall; |
| 146 |
FOR_MAP_FINISH(); |
| 147 |
return NULL; |
| 148 |
} |
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
static void remove_marking_runes(struct mapdef *map, short x, short y) { |
| 159 |
FOR_MAP_PREPARE(map, x, y, rune) { |
| 160 |
if ((rune->type == SIGN) && (!strcmp(rune->arch->name, "rune_mark"))) { |
| 161 |
object_remove(rune); |
| 162 |
object_free_drop_inventory(rune); |
| 163 |
} |
| 164 |
} FOR_MAP_FINISH(); |
| 165 |
} |
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
static int adjust_sign_msg(object *pl, short x, short y, object *tmp) { |
| 185 |
object *book; |
| 186 |
char buf[MAX_BUF]; |
| 187 |
char buf2[MAX_BUF]; |
| 188 |
|
| 189 |
book = get_msg_book(pl, x, y); |
| 190 |
if (!book) { |
| 191 |
draw_ext_info(NDI_UNIQUE, 0, pl, MSG_TYPE_APPLY, MSG_TYPE_APPLY_BUILD, |
| 192 |
"You need to put a book or scroll with the message."); |
| 193 |
return -1; |
| 194 |
} |
| 195 |
|
| 196 |
object_set_msg(tmp, book->msg); |
| 197 |
|
| 198 |
if (tmp->invisible) { |
| 199 |
if (book->custom_name != NULL) { |
| 200 |
snprintf(buf, sizeof(buf), "talking %s", book->custom_name); |
| 201 |
} else { |
| 202 |
snprintf(buf, sizeof(buf), "talking %s", book->name); |
| 203 |
} |
| 204 |
if (tmp->name) |
| 205 |
free_string(tmp->name); |
| 206 |
tmp->name = add_string(buf); |
| 207 |
|
| 208 |
if (book->name_pl != NULL) { |
| 209 |
snprintf(buf2, sizeof(buf2), "talking %s", book->name_pl); |
| 210 |
if (tmp->name_pl) |
| 211 |
free_string(tmp->name_pl); |
| 212 |
tmp->name_pl = add_string(buf2); |
| 213 |
} |
| 214 |
|
| 215 |
tmp->face = book->face; |
| 216 |
tmp->invisible = 0; |
| 217 |
} |
| 218 |
object_remove(book); |
| 219 |
object_free_drop_inventory(book); |
| 220 |
return 0; |
| 221 |
} |
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
static int find_unused_connected_value(struct mapdef *map) { |
| 234 |
int connected = 0; |
| 235 |
int itest = 0; |
| 236 |
oblinkpt *obp; |
| 237 |
|
| 238 |
while (itest++ < 1000) { |
| 239 |
connected = 1+rand()%20000; |
| 240 |
for (obp = map->buttons; obp && (obp->value != connected); obp = obp->next) |
| 241 |
; |
| 242 |
|
| 243 |
if (!obp) |
| 244 |
return connected; |
| 245 |
} |
| 246 |
|
| 247 |
return -1; |
| 248 |
} |
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
static int find_or_create_connection_for_map(object *pl, short x, short y, object *rune) { |
| 272 |
object *force; |
| 273 |
int connected; |
| 274 |
|
| 275 |
if (!rune) |
| 276 |
rune = get_connection_rune(pl, x, y); |
| 277 |
|
| 278 |
if (!rune || !rune->msg) { |
| 279 |
draw_ext_info(NDI_UNIQUE, 0, pl, MSG_TYPE_APPLY, MSG_TYPE_APPLY_BUILD, |
| 280 |
"You need to put a marking rune with the group name."); |
| 281 |
return -1; |
| 282 |
} |
| 283 |
|
| 284 |
|
| 285 |
force = NULL; |
| 286 |
FOR_INV_PREPARE(pl, tmp) { |
| 287 |
if (tmp->type == FORCE |
| 288 |
&& tmp->slaying != NULL && strcmp(tmp->slaying, pl->map->path) == 0 |
| 289 |
&& tmp->msg != NULL && tmp->msg == rune->msg) { |
| 290 |
force = tmp; |
| 291 |
break; |
| 292 |
} |
| 293 |
} FOR_INV_FINISH(); |
| 294 |
|
| 295 |
if (!force) { |
| 296 |
|
| 297 |
|
| 298 |
connected = find_unused_connected_value(pl->map); |
| 299 |
if (connected == -1) { |
| 300 |
draw_ext_info(NDI_UNIQUE, 0, pl, MSG_TYPE_APPLY, MSG_TYPE_APPLY_BUILD, |
| 301 |
"Could not create more groups."); |
| 302 |
return -1; |
| 303 |
} |
| 304 |
|
| 305 |
force = create_archetype(FORCE_NAME); |
| 306 |
force->speed = 0; |
| 307 |
object_update_speed(force); |
| 308 |
force->slaying = add_string(pl->map->path); |
| 309 |
object_set_msg(force, rune->msg); |
| 310 |
force->path_attuned = connected; |
| 311 |
object_insert_in_ob(force, pl); |
| 312 |
|
| 313 |
return connected; |
| 314 |
} |
| 315 |
|
| 316 |
|
| 317 |
return force->path_attuned; |
| 318 |
} |
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
static void fix_walls(struct mapdef *map, int x, int y) { |
| 336 |
int connect; |
| 337 |
object *wall; |
| 338 |
char archetype[MAX_BUF]; |
| 339 |
char *underscore; |
| 340 |
uint32_t old_flags[4]; |
| 341 |
struct archt *new_arch; |
| 342 |
int flag; |
| 343 |
int len; |
| 344 |
int has_window; |
| 345 |
|
| 346 |
|
| 347 |
wall = get_wall(map, x, y); |
| 348 |
if (!wall) |
| 349 |
|
| 350 |
return; |
| 351 |
|
| 352 |
|
| 353 |
strncpy(archetype, wall->arch->name, sizeof(archetype)); |
| 354 |
archetype[sizeof(archetype)-1] = '\0'; |
| 355 |
underscore = strchr(archetype, '_'); |
| 356 |
if (!underscore) |
| 357 |
|
| 358 |
return; |
| 359 |
has_window = 0; |
| 360 |
if (!strcmp(underscore+1, "win1")) |
| 361 |
has_window = 1; |
| 362 |
else if (!strcmp(underscore+1, "win2")) |
| 363 |
has_window = 1; |
| 364 |
else if (!isdigit(*(underscore+1))) |
| 365 |
return; |
| 366 |
|
| 367 |
underscore++; |
| 368 |
*underscore = '\0'; |
| 369 |
len = sizeof(archetype)-strlen(archetype)-2; |
| 370 |
|
| 371 |
connect = 0; |
| 372 |
|
| 373 |
if ((x > 0) && get_wall(map, x-1, y)) |
| 374 |
connect |= 1; |
| 375 |
if ((x < MAP_WIDTH(map)-1) && get_wall(map, x+1, y)) |
| 376 |
connect |= 2; |
| 377 |
if ((y > 0) && get_wall(map, x, y-1)) |
| 378 |
connect |= 4; |
| 379 |
if ((y < MAP_HEIGHT(map)-1) && get_wall(map, x, y+1)) |
| 380 |
connect |= 8; |
| 381 |
|
| 382 |
switch (connect) { |
| 383 |
case 0: |
| 384 |
strncat(archetype, "0", len); |
| 385 |
break; |
| 386 |
|
| 387 |
case 1: |
| 388 |
strncat(archetype, "1_3", len); |
| 389 |
break; |
| 390 |
|
| 391 |
case 2: |
| 392 |
strncat(archetype, "1_4", len); |
| 393 |
break; |
| 394 |
|
| 395 |
case 3: |
| 396 |
if (has_window) { |
| 397 |
strncat(archetype, "win2", len); |
| 398 |
} else { |
| 399 |
strncat(archetype, "2_1_2", len); |
| 400 |
} |
| 401 |
break; |
| 402 |
|
| 403 |
case 4: |
| 404 |
strncat(archetype, "1_2", len); |
| 405 |
break; |
| 406 |
|
| 407 |
case 5: |
| 408 |
strncat(archetype, "2_2_4", len); |
| 409 |
break; |
| 410 |
|
| 411 |
case 6: |
| 412 |
strncat(archetype, "2_2_1", len); |
| 413 |
break; |
| 414 |
|
| 415 |
case 7: |
| 416 |
strncat(archetype, "3_1", len); |
| 417 |
break; |
| 418 |
|
| 419 |
case 8: |
| 420 |
strncat(archetype, "1_1", len); |
| 421 |
break; |
| 422 |
|
| 423 |
case 9: |
| 424 |
strncat(archetype, "2_2_3", len); |
| 425 |
break; |
| 426 |
|
| 427 |
case 10: |
| 428 |
strncat(archetype, "2_2_2", len); |
| 429 |
break; |
| 430 |
|
| 431 |
case 11: |
| 432 |
strncat(archetype, "3_3", len); |
| 433 |
break; |
| 434 |
|
| 435 |
case 12: |
| 436 |
if (has_window) { |
| 437 |
strncat(archetype, "win1", len); |
| 438 |
} else { |
| 439 |
strncat(archetype, "2_1_1", len); |
| 440 |
} |
| 441 |
break; |
| 442 |
|
| 443 |
case 13: |
| 444 |
strncat(archetype, "3_4", len); |
| 445 |
break; |
| 446 |
|
| 447 |
case 14: |
| 448 |
strncat(archetype, "3_2", len); |
| 449 |
break; |
| 450 |
|
| 451 |
case 15: |
| 452 |
strncat(archetype, "4", len); |
| 453 |
break; |
| 454 |
} |
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
if (!strncmp(archetype, wall->arch->name, sizeof(archetype))) |
| 460 |
return; |
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
new_arch = find_archetype(archetype); |
| 467 |
if (!new_arch) |
| 468 |
return; |
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
for (flag = 0; flag < 4; flag++) |
| 474 |
old_flags[flag] = wall->flags[flag]; |
| 475 |
object_remove(wall); |
| 476 |
object_free_drop_inventory(wall); |
| 477 |
|
| 478 |
wall = arch_to_object(new_arch); |
| 479 |
wall->type = WALL; |
| 480 |
object_insert_in_map_at(wall, map, NULL, INS_ABOVE_FLOOR_ONLY, x, y); |
| 481 |
for (flag = 0; flag < 4; flag++) |
| 482 |
wall->flags[flag] = old_flags[flag]; |
| 483 |
} |
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
static int apply_builder_floor(object *pl, object *new_floor, short x, short y) { |
| 507 |
object *above_floor; |
| 508 |
object *floor; |
| 509 |
struct archt *new_wall; |
| 510 |
int i, xt, yt, wall_removed; |
| 511 |
char message[MAX_BUF]; |
| 512 |
|
| 513 |
snprintf(message, sizeof(message), "You change the floor to better suit your tastes."); |
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
above_floor = NULL; |
| 520 |
floor = NULL; |
| 521 |
new_wall = NULL; |
| 522 |
wall_removed = 0; |
| 523 |
FOR_MAP_PREPARE(pl->map, x, y, tmp) { |
| 524 |
if (WALL == tmp->type) { |
| 525 |
|
| 526 |
new_wall = tmp->arch; |
| 527 |
object_remove(tmp); |
| 528 |
object_free_drop_inventory(tmp); |
| 529 |
snprintf(message, sizeof(message), "You destroy the wall and redo the floor."); |
| 530 |
wall_removed = 1; |
| 531 |
if (floor != NULL) { |
| 532 |
object_remove(floor); |
| 533 |
object_free_drop_inventory(floor); |
| 534 |
floor = NULL; |
| 535 |
} |
| 536 |
} else if ((FLOOR == tmp->type) || (QUERY_FLAG(tmp, FLAG_IS_FLOOR))) { |
| 537 |
floor = tmp; |
| 538 |
} else { |
| 539 |
if (floor != NULL) |
| 540 |
above_floor = tmp; |
| 541 |
} |
| 542 |
} FOR_MAP_FINISH(); |
| 543 |
|
| 544 |
if (wall_removed == 0 && floor != NULL) { |
| 545 |
if (floor->arch == new_floor->arch) { |
| 546 |
draw_ext_info(NDI_UNIQUE, 0, pl, MSG_TYPE_APPLY, MSG_TYPE_APPLY_BUILD, "You feel too lazy to redo the exact same floor."); |
| 547 |
object_free_drop_inventory(new_floor); |
| 548 |
return 0; |
| 549 |
} |
| 550 |
} |
| 551 |
|
| 552 |
SET_FLAG(new_floor, FLAG_UNIQUE); |
| 553 |
SET_FLAG(new_floor, FLAG_IS_FLOOR); |
| 554 |
new_floor->type = FLOOR; |
| 555 |
object_insert_in_map_at(new_floor, pl->map, above_floor, above_floor ? INS_BELOW_ORIGINATOR : INS_ON_TOP, x, y); |
| 556 |
|
| 557 |
|
| 558 |
if (floor) { |
| 559 |
object_remove(floor); |
| 560 |
object_free_drop_inventory(floor); |
| 561 |
floor = NULL; |
| 562 |
} |
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
for (i = 1; i <= 8; i++) { |
| 569 |
object *tmp; |
| 570 |
|
| 571 |
xt = x+freearr_x[i]; |
| 572 |
yt = y+freearr_y[i]; |
| 573 |
tmp = GET_MAP_OB(pl->map, xt, yt); |
| 574 |
if (!tmp) { |
| 575 |
|
| 576 |
|
| 577 |
tmp = arch_to_object(new_floor->arch); |
| 578 |
|
| 579 |
SET_FLAG(tmp, FLAG_UNIQUE); |
| 580 |
SET_FLAG(tmp, FLAG_IS_BUILDABLE); |
| 581 |
tmp->type = FLOOR; |
| 582 |
object_insert_in_map_at(tmp, pl->map, NULL, 0, xt, yt); |
| 583 |
|
| 584 |
if (new_wall) { |
| 585 |
tmp = arch_to_object(new_wall); |
| 586 |
SET_FLAG(tmp, FLAG_IS_BUILDABLE); |
| 587 |
tmp->type = WALL; |
| 588 |
object_insert_in_map_at(tmp, pl->map, NULL, 0, xt, yt); |
| 589 |
} |
| 590 |
} |
| 591 |
} |
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
for (xt = x-2; xt <= x+2; xt++) |
| 599 |
for (yt = y-2; yt <= y+2; yt++) { |
| 600 |
if (!OUT_OF_REAL_MAP(pl->map, xt, yt)) |
| 601 |
fix_walls(pl->map, xt, yt); |
| 602 |
} |
| 603 |
|
| 604 |
|
| 605 |
draw_ext_info(NDI_UNIQUE, 0, pl, MSG_TYPE_APPLY, MSG_TYPE_APPLY_BUILD, message); |
| 606 |
return 1; |
| 607 |
} |
| 608 |
|
| 609 |
|
| 610 |
|
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
|
| 624 |
|
| 625 |
|
| 626 |
static int apply_builder_wall(object *pl, object *new_wall, short x, short y) { |
| 627 |
object *current_wall; |
| 628 |
char message[MAX_BUF]; |
| 629 |
|
| 630 |
remove_marking_runes(pl->map, x, y); |
| 631 |
|
| 632 |
current_wall = get_wall(pl->map, x, y); |
| 633 |
|
| 634 |
if (current_wall) { |
| 635 |
char current_basename[MAX_BUF]; |
| 636 |
char new_basename[MAX_BUF]; |
| 637 |
char *underscore; |
| 638 |
|
| 639 |
|
| 640 |
strncpy(current_basename, current_wall->arch->name, sizeof(current_basename)); |
| 641 |
current_basename[sizeof(current_basename)-1] = '\0'; |
| 642 |
underscore = strchr(current_basename, '_'); |
| 643 |
if (underscore && isdigit(*(underscore+1))) { |
| 644 |
underscore++; |
| 645 |
*underscore = '\0'; |
| 646 |
} |
| 647 |
strncpy(new_basename, new_wall->arch->name, sizeof(new_basename)); |
| 648 |
new_basename[sizeof(new_basename)-1] = '\0'; |
| 649 |
underscore = strchr(new_basename, '_'); |
| 650 |
if (underscore && isdigit(*(underscore+1))) { |
| 651 |
underscore++; |
| 652 |
*underscore = '\0'; |
| 653 |
} |
| 654 |
if (!strncmp(current_basename, new_basename, sizeof(new_basename))) { |
| 655 |
draw_ext_info(NDI_UNIQUE, 0, pl, MSG_TYPE_APPLY, MSG_TYPE_APPLY_BUILD, "You feel too lazy to redo the exact same wall."); |
| 656 |
object_free_drop_inventory(new_wall); |
| 657 |
return 0; |
| 658 |
} |
| 659 |
} |
| 660 |
|
| 661 |
snprintf(message, sizeof(message), "You build a wall."); |
| 662 |
new_wall->type = WALL; |
| 663 |
|
| 664 |
if (current_wall) { |
| 665 |
|
| 666 |
object_remove(current_wall); |
| 667 |
object_free_drop_inventory(current_wall); |
| 668 |
object_insert_in_map_at(new_wall, pl->map, NULL, INS_ABOVE_FLOOR_ONLY, x, y); |
| 669 |
fix_walls(pl->map, x, y); |
| 670 |
snprintf(message, sizeof(message), "You redecorate the wall to better suit your tastes."); |
| 671 |
} else { |
| 672 |
int xt, yt; |
| 673 |
|
| 674 |
|
| 675 |
object_insert_in_map_at(new_wall, pl->map, NULL, INS_ABOVE_FLOOR_ONLY, x, y); |
| 676 |
for (xt = x-1; xt <= x+1; xt++) |
| 677 |
for (yt = y-1; yt <= y+1; yt++) { |
| 678 |
if (OUT_OF_REAL_MAP(pl->map, xt, yt)) |
| 679 |
continue; |
| 680 |
|
| 681 |
fix_walls(pl->map, xt, yt); |
| 682 |
} |
| 683 |
} |
| 684 |
|
| 685 |
|
| 686 |
draw_ext_info(NDI_UNIQUE, 0, pl, MSG_TYPE_APPLY, MSG_TYPE_APPLY_BUILD, message); |
| 687 |
return 1; |
| 688 |
} |
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
|
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
|
| 702 |
|
| 703 |
|
| 704 |
|
| 705 |
|
| 706 |
static int apply_builder_window(object *pl, object *new_wall_win, short x, short y) { |
| 707 |
object *current_wall; |
| 708 |
char archetype[MAX_BUF]; |
| 709 |
struct archt *new_arch; |
| 710 |
object *window; |
| 711 |
uint32_t old_flags[4]; |
| 712 |
int flag; |
| 713 |
|
| 714 |
|
| 715 |
object_free_drop_inventory(new_wall_win); |
| 716 |
|
| 717 |
current_wall = get_wall(pl->map, x, y); |
| 718 |
|
| 719 |
if (current_wall) { |
| 720 |
char *underscore; |
| 721 |
|
| 722 |
strncpy(archetype, current_wall->arch->name, sizeof(archetype)); |
| 723 |
archetype[sizeof(archetype)-1] = '\0'; |
| 724 |
underscore = strchr(archetype, '_'); |
| 725 |
if (underscore) { |
| 726 |
underscore++; |
| 727 |
|
| 728 |
if (!strcmp(underscore, "win1") |
| 729 |
|| !strcmp(underscore, "win2")) { |
| 730 |
draw_ext_info(NDI_UNIQUE, 0, pl, MSG_TYPE_APPLY, MSG_TYPE_APPLY_BUILD, "You feel too lazy to redo the window."); |
| 731 |
return 0; |
| 732 |
} |
| 733 |
if (!strcmp(underscore, "2_1_1")) |
| 734 |
strcpy(underscore, "win1"); |
| 735 |
else if (!strcmp(underscore, "2_1_2")) |
| 736 |
strcpy(underscore, "win2"); |
| 737 |
else { |
| 738 |
|
| 739 |
draw_ext_info(NDI_UNIQUE, 0, pl, MSG_TYPE_APPLY, MSG_TYPE_APPLY_BUILD, "You cannot build a window in that wall."); |
| 740 |
return 0; |
| 741 |
} |
| 742 |
} |
| 743 |
} else { |
| 744 |
draw_ext_info(NDI_UNIQUE, 0, pl, MSG_TYPE_APPLY, MSG_TYPE_APPLY_BUILD, |
| 745 |
"There is no wall there."); |
| 746 |
return 0; |
| 747 |
} |
| 748 |
|
| 749 |
new_arch = find_archetype(archetype); |
| 750 |
if (!new_arch) { |
| 751 |
|
| 752 |
draw_ext_info(NDI_UNIQUE, 0, pl, MSG_TYPE_APPLY, MSG_TYPE_APPLY_BUILD, "You cannot build a window in that wall."); |
| 753 |
return 0; |
| 754 |
} |
| 755 |
|
| 756 |
|
| 757 |
|
| 758 |
|
| 759 |
for (flag = 0; flag < 4; flag++) |
| 760 |
old_flags[flag] = current_wall->flags[flag]; |
| 761 |
object_remove(current_wall); |
| 762 |
object_free_drop_inventory(current_wall); |
| 763 |
|
| 764 |
window = arch_to_object(new_arch); |
| 765 |
window->type = WALL; |
| 766 |
object_insert_in_map_at(window, pl->map, NULL, INS_ABOVE_FLOOR_ONLY, x, y); |
| 767 |
for (flag = 0; flag < 4; flag++) |
| 768 |
window->flags[flag] = old_flags[flag]; |
| 769 |
|
| 770 |
|
| 771 |
draw_ext_info(NDI_UNIQUE, 0, pl, MSG_TYPE_APPLY, MSG_TYPE_APPLY_BUILD, "You build a window in the wall."); |
| 772 |
return 1; |
| 773 |
} |
| 774 |
|
| 775 |
|
| 776 |
|
| 777 |
|
| 778 |
|
| 779 |
|
| 780 |
|
| 781 |
|
| 782 |
|
| 783 |
|
| 784 |
|
| 785 |
|
| 786 |
|
| 787 |
|
| 788 |
|
| 789 |
|
| 790 |
|
| 791 |
|
| 792 |
|
| 793 |
|
| 794 |
|
| 795 |
|
| 796 |
static int apply_builder_item(object *pl, object *new_item, short x, short y) { |
| 797 |
int insert_flag; |
| 798 |
object *floor; |
| 799 |
object *con_rune; |
| 800 |
int connected; |
| 801 |
char name[MAX_BUF]; |
| 802 |
|
| 803 |
|
| 804 |
floor = GET_MAP_OB(pl->map, x, y); |
| 805 |
if (!floor) { |
| 806 |
draw_ext_info(NDI_UNIQUE, 0, pl, MSG_TYPE_APPLY, MSG_TYPE_APPLY_BUILD, "Invalid square."); |
| 807 |
object_free_drop_inventory(new_item); |
| 808 |
return 0; |
| 809 |
} |
| 810 |
|
| 811 |
FOR_OB_AND_ABOVE_PREPARE(floor) |
| 812 |
if (floor->type == FLOOR || QUERY_FLAG(floor, FLAG_IS_FLOOR)) |
| 813 |
break; |
| 814 |
FOR_OB_AND_ABOVE_FINISH(); |
| 815 |
if (!floor) { |
| 816 |
draw_ext_info(NDI_UNIQUE, 0, pl, MSG_TYPE_APPLY, MSG_TYPE_APPLY_BUILD, |
| 817 |
"This square has no floor, you can't build here."); |
| 818 |
object_free_drop_inventory(new_item); |
| 819 |
return 0; |
| 820 |
} |
| 821 |
|
| 822 |
SET_FLAG(new_item, FLAG_NO_PICK); |
| 823 |
|
| 824 |
|
| 825 |
|
| 826 |
|
| 827 |
|
| 828 |
insert_flag = INS_ABOVE_FLOOR_ONLY; |
| 829 |
|
| 830 |
connected = 0; |
| 831 |
con_rune = NULL; |
| 832 |
switch (new_item->type) { |
| 833 |
case DOOR: |
| 834 |
case GATE: |
| 835 |
case BUTTON: |
| 836 |
case DETECTOR: |
| 837 |
case TIMED_GATE: |
| 838 |
case PEDESTAL: |
| 839 |
case CF_HANDLE: |
| 840 |
case MAGIC_EAR: |
| 841 |
case SIGN: |
| 842 |
|
| 843 |
if (new_item->type == SIGN && strcmp(new_item->arch->name, "magic_mouth")) |
| 844 |
break; |
| 845 |
con_rune = get_connection_rune(pl, x, y); |
| 846 |
connected = find_or_create_connection_for_map(pl, x, y, con_rune); |
| 847 |
if (connected == -1) { |
| 848 |
|
| 849 |
object_free_drop_inventory(new_item); |
| 850 |
return 0; |
| 851 |
} |
| 852 |
} |
| 853 |
|
| 854 |
|
| 855 |
if ((new_item->type == SIGN) || (new_item->type == MAGIC_EAR)) { |
| 856 |
if (adjust_sign_msg(pl, x, y, new_item) == -1) { |
| 857 |
object_free_drop_inventory(new_item); |
| 858 |
return 0; |
| 859 |
} |
| 860 |
} |
| 861 |
|
| 862 |
if (con_rune != NULL) { |
| 863 |
|
| 864 |
object_remove(con_rune); |
| 865 |
object_free_drop_inventory(con_rune); |
| 866 |
} |
| 867 |
|
| 868 |
object_insert_in_map_at(new_item, pl->map, floor, insert_flag, x, y); |
| 869 |
if (connected != 0) |
| 870 |
add_button_link(new_item, pl->map, connected); |
| 871 |
|
| 872 |
query_name(new_item, name, MAX_BUF); |
| 873 |
draw_ext_info_format(NDI_UNIQUE, 0, pl, MSG_TYPE_APPLY, MSG_TYPE_APPLY_BUILD, |
| 874 |
"You build the %s", |
| 875 |
name); |
| 876 |
return 1; |
| 877 |
} |
| 878 |
|
| 879 |
|
| 880 |
|
| 881 |
|
| 882 |
|
| 883 |
|
| 884 |
|
| 885 |
|
| 886 |
|
| 887 |
|
| 888 |
|
| 889 |
void apply_builder_remove(object *pl, int dir) { |
| 890 |
object *item; |
| 891 |
short x, y; |
| 892 |
char name[MAX_BUF]; |
| 893 |
|
| 894 |
x = pl->x+freearr_x[dir]; |
| 895 |
y = pl->y+freearr_y[dir]; |
| 896 |
|
| 897 |
|
| 898 |
item = GET_MAP_OB(pl->map, x, y); |
| 899 |
if (!item) { |
| 900 |
|
| 901 |
draw_ext_info(NDI_UNIQUE, 0, pl, MSG_TYPE_APPLY, MSG_TYPE_APPLY_BUILD, |
| 902 |
"Invalid square."); |
| 903 |
LOG(llevError, "apply_builder_remove: (null) square at (%d, %d, %s)\n", x, y, pl->map->path); |
| 904 |
return; |
| 905 |
} |
| 906 |
|
| 907 |
if (item->type == FLOOR || QUERY_FLAG(item, FLAG_IS_FLOOR)) |
| 908 |
item = item->above; |
| 909 |
|
| 910 |
if (!item) { |
| 911 |
draw_ext_info(NDI_UNIQUE, 0, pl, MSG_TYPE_APPLY, MSG_TYPE_APPLY_BUILD, |
| 912 |
"Nothing to remove."); |
| 913 |
return; |
| 914 |
} |
| 915 |
|
| 916 |
|
| 917 |
switch (item->type) { |
| 918 |
case WALL: |
| 919 |
draw_ext_info(NDI_UNIQUE, 0, pl, MSG_TYPE_APPLY, MSG_TYPE_APPLY_BUILD, |
| 920 |
"Can't remove a wall with that, build a floor."); |
| 921 |
return; |
| 922 |
|
| 923 |
case DOOR: |
| 924 |
case BUTTON: |
| 925 |
case GATE: |
| 926 |
case TIMED_GATE: |
| 927 |
case DETECTOR: |
| 928 |
case PEDESTAL: |
| 929 |
case CF_HANDLE: |
| 930 |
case MAGIC_EAR: |
| 931 |
case SIGN: |
| 932 |
|
| 933 |
if (QUERY_FLAG(item, FLAG_IS_LINKED)) |
| 934 |
remove_button_link(item); |
| 935 |
|
| 936 |
|
| 937 |
default: |
| 938 |
|
| 939 |
query_name(item, name, MAX_BUF); |
| 940 |
draw_ext_info_format(NDI_UNIQUE, 0, pl, MSG_TYPE_APPLY, MSG_TYPE_APPLY_BUILD, |
| 941 |
"You remove the %s", |
| 942 |
name); |
| 943 |
object_remove(item); |
| 944 |
object_free_drop_inventory(item); |
| 945 |
} |
| 946 |
} |
| 947 |
|
| 948 |
|
| 949 |
|
| 950 |
|
| 951 |
|
| 952 |
|
| 953 |
|
| 954 |
|
| 955 |
|
| 956 |
|
| 957 |
|
| 958 |
|
| 959 |
void apply_map_builder(object *pl, int dir) { |
| 960 |
object *builder; |
| 961 |
object *tmp; |
| 962 |
short x, y; |
| 963 |
|
| 964 |
if (!IS_PLAYER(pl)) |
| 965 |
return; |
| 966 |
|
| 967 |
if (dir == 0) { |
| 968 |
draw_ext_info(NDI_UNIQUE, 0, pl, MSG_TYPE_APPLY, MSG_TYPE_APPLY_BUILD, |
| 969 |
"You can't build or destroy under yourself."); |
| 970 |
return; |
| 971 |
} |
| 972 |
|
| 973 |
x = pl->x+freearr_x[dir]; |
| 974 |
y = pl->y+freearr_y[dir]; |
| 975 |
|
| 976 |
if ((1 > x) || (1 > y) |
| 977 |
|| ((MAP_WIDTH(pl->map)-2) < x) || ((MAP_HEIGHT(pl->map)-2) < y)) { |
| 978 |
draw_ext_info(NDI_UNIQUE, 0, pl, MSG_TYPE_APPLY, MSG_TYPE_APPLY_BUILD, |
| 979 |
"Can't build on map edge."); |
| 980 |
return; |
| 981 |
} |
| 982 |
|
| 983 |
|
| 984 |
|
| 985 |
|
| 986 |
|
| 987 |
|
| 988 |
|
| 989 |
|
| 990 |
tmp = GET_MAP_OB(pl->map, x, y); |
| 991 |
if (!tmp) { |
| 992 |
|
| 993 |
LOG(llevError, "apply_map_builder: undefined square at (%d, %d, %s)\n", x, y, pl->map->path); |
| 994 |
draw_ext_info(NDI_UNIQUE, 0, pl, MSG_TYPE_APPLY, MSG_TYPE_APPLY_BUILD, |
| 995 |
"You'd better not build here, it looks weird."); |
| 996 |
return; |
| 997 |
} |
| 998 |
|
| 999 |
builder = pl->contr->ranges[range_builder]; |
| 1000 |
|
| 1001 |
if (builder->subtype != ST_BD_BUILD) { |
| 1002 |
FOR_OB_AND_ABOVE_PREPARE(tmp) |
| 1003 |
if (!QUERY_FLAG(tmp, FLAG_IS_BUILDABLE) |
| 1004 |
&& ((tmp->type != SIGN) || (strcmp(tmp->arch->name, "rune_mark")))) { |
| 1005 |
draw_ext_info(NDI_UNIQUE, 0, pl, MSG_TYPE_APPLY, MSG_TYPE_APPLY_BUILD, |
| 1006 |
"You can't build here."); |
| 1007 |
return; |
| 1008 |
} |
| 1009 |
FOR_OB_AND_ABOVE_FINISH(); |
| 1010 |
} |
| 1011 |
|
| 1012 |
|
| 1013 |
|
| 1014 |
if (builder->subtype == ST_BD_REMOVE) { |
| 1015 |
|
| 1016 |
apply_builder_remove(pl, dir); |
| 1017 |
return; |
| 1018 |
} |
| 1019 |
|
| 1020 |
if (builder->subtype == ST_BD_BUILD) { |
| 1021 |
object *material; |
| 1022 |
struct archt *new_arch; |
| 1023 |
object *new_item; |
| 1024 |
int built = 0; |
| 1025 |
|
| 1026 |
|
| 1027 |
|
| 1028 |
material = find_marked_object(pl); |
| 1029 |
if (!material) { |
| 1030 |
draw_ext_info(NDI_UNIQUE, 0, pl, MSG_TYPE_APPLY, MSG_TYPE_APPLY_BUILD, |
| 1031 |
"You need to mark raw materials to use."); |
| 1032 |
return; |
| 1033 |
} |
| 1034 |
|
| 1035 |
if (material->type != MATERIAL) { |
| 1036 |
draw_ext_info(NDI_UNIQUE, 0, pl, MSG_TYPE_APPLY, MSG_TYPE_APPLY_BUILD, |
| 1037 |
"You can't use the marked item to build."); |
| 1038 |
return; |
| 1039 |
} |
| 1040 |
|
| 1041 |
|
| 1042 |
if (QUERY_FLAG(material, FLAG_UNPAID)) { |
| 1043 |
draw_ext_info(NDI_UNIQUE, 0, pl, MSG_TYPE_APPLY, MSG_TYPE_APPLY_BUILD, "You should pay for it first."); |
| 1044 |
return; |
| 1045 |
} |
| 1046 |
|
| 1047 |
|
| 1048 |
new_arch = find_archetype(material->slaying); |
| 1049 |
if (!new_arch) { |
| 1050 |
draw_ext_info(NDI_UNIQUE, 0, pl, MSG_TYPE_APPLY, MSG_TYPE_APPLY_BUILD, |
| 1051 |
"You can't use this strange material."); |
| 1052 |
LOG(llevError, "apply_map_builder: unable to find archetype %s\n", material->slaying); |
| 1053 |
return; |
| 1054 |
} |
| 1055 |
new_item = object_create_arch(new_arch); |
| 1056 |
SET_FLAG(new_item, FLAG_IS_BUILDABLE); |
| 1057 |
|
| 1058 |
if (!can_build_over(pl->map, new_item, x, y)) { |
| 1059 |
draw_ext_info(NDI_UNIQUE, 0, pl, MSG_TYPE_APPLY, MSG_TYPE_APPLY_BUILD, |
| 1060 |
"You can't build here."); |
| 1061 |
return; |
| 1062 |
} |
| 1063 |
|
| 1064 |
|
| 1065 |
switch (material->subtype) { |
| 1066 |
case ST_MAT_FLOOR: |
| 1067 |
built = apply_builder_floor(pl, new_item, x, y); |
| 1068 |
break; |
| 1069 |
|
| 1070 |
case ST_MAT_WALL: |
| 1071 |
built = apply_builder_wall(pl, new_item, x, y); |
| 1072 |
break; |
| 1073 |
|
| 1074 |
case ST_MAT_ITEM: |
| 1075 |
built = apply_builder_item(pl, new_item, x, y); |
| 1076 |
break; |
| 1077 |
|
| 1078 |
case ST_MAT_WINDOW: |
| 1079 |
built = apply_builder_window(pl, new_item, x, y); |
| 1080 |
break; |
| 1081 |
|
| 1082 |
default: |
| 1083 |
draw_ext_info(NDI_UNIQUE, 0, pl, MSG_TYPE_APPLY, MSG_TYPE_APPLY_BUILD, |
| 1084 |
"Don't know how to apply this material, sorry."); |
| 1085 |
LOG(llevError, "apply_map_builder: invalid material subtype %d\n", material->subtype); |
| 1086 |
break; |
| 1087 |
} |
| 1088 |
if (built) |
| 1089 |
object_decrease_nrof_by_one(material); |
| 1090 |
return; |
| 1091 |
} |
| 1092 |
|
| 1093 |
|
| 1094 |
draw_ext_info(NDI_UNIQUE, 0, pl, MSG_TYPE_APPLY, MSG_TYPE_APPLY_BUILD, |
| 1095 |
"Don't know how to apply this tool, sorry."); |
| 1096 |
LOG(llevError, "apply_map_builder: invalid builder subtype %d\n", builder->subtype); |
| 1097 |
} |