… | |
… | |
82 | |
82 | |
83 | rune = GET_MAP_OB (map, x, y); |
83 | rune = GET_MAP_OB (map, x, y); |
84 | while (rune) |
84 | while (rune) |
85 | { |
85 | { |
86 | next = rune->above; |
86 | next = rune->above; |
|
|
87 | |
87 | if ((rune->type == SIGN) && (!strcmp (rune->arch->name, "rune_mark"))) |
88 | if ((rune->type == SIGN) && (!strcmp (rune->arch->name, "rune_mark"))) |
88 | { |
|
|
89 | rune->remove (); |
|
|
90 | rune->destroy (0); |
89 | rune->destroy (); |
91 | } |
90 | |
92 | rune = next; |
91 | rune = next; |
93 | } |
92 | } |
94 | } |
93 | } |
95 | |
94 | |
96 | /** |
95 | /** |
… | |
… | |
162 | new_draw_info (NDI_UNIQUE, 0, pl, "Could not create more groups."); |
161 | new_draw_info (NDI_UNIQUE, 0, pl, "Could not create more groups."); |
163 | return -1; |
162 | return -1; |
164 | } |
163 | } |
165 | |
164 | |
166 | force = get_archetype (FORCE_NAME); |
165 | force = get_archetype (FORCE_NAME); |
167 | force->speed = 0; |
|
|
168 | update_ob_speed (force); |
|
|
169 | force->slaying = pl->map->path; |
166 | force->slaying = pl->map->path; |
170 | force->msg = rune->msg; |
167 | force->msg = rune->msg; |
171 | force->path_attuned = connected; |
168 | force->path_attuned = connected; |
|
|
169 | force->set_speed (0); |
172 | insert_ob_in_ob (force, pl); |
170 | insert_ob_in_ob (force, pl); |
173 | |
171 | |
174 | return connected; |
172 | return connected; |
175 | } |
173 | } |
176 | |
174 | |
… | |
… | |
205 | book = book->above; |
203 | book = book->above; |
206 | return book; |
204 | return book; |
207 | } |
205 | } |
208 | |
206 | |
209 | /** |
207 | /** |
210 | * Returns first item of type WALL. |
208 | * Returns first item of type BUILDABLE_WALL. |
211 | */ |
209 | */ |
212 | object * |
210 | object * |
213 | get_wall (maptile *map, int x, int y) |
211 | get_wall (maptile *map, int x, int y) |
214 | { |
212 | { |
215 | object *wall; |
213 | object *wall; |
216 | |
214 | |
217 | wall = GET_MAP_OB (map, x, y); |
215 | wall = GET_MAP_OB (map, x, y); |
218 | while (wall && (WALL != wall->type)) |
216 | while (wall && (BUILDABLE_WALL != wall->type)) |
219 | wall = wall->above; |
217 | wall = wall->above; |
220 | |
218 | |
221 | return wall; |
219 | return wall; |
222 | } |
220 | } |
223 | |
221 | |
… | |
… | |
233 | * Note: x & y must be valid map coordinates. |
231 | * Note: x & y must be valid map coordinates. |
234 | */ |
232 | */ |
235 | void |
233 | void |
236 | fix_walls (maptile *map, int x, int y) |
234 | fix_walls (maptile *map, int x, int y) |
237 | { |
235 | { |
238 | int connect; |
|
|
239 | object *wall; |
236 | object *wall; |
240 | char archetype[MAX_BUF]; |
237 | char archetype[MAX_BUF]; |
241 | char *underscore; |
238 | char *underscore; |
242 | uint32 old_flags[4]; |
|
|
243 | struct archetype *new_arch; |
239 | struct archetype *new_arch; |
244 | int flag; |
|
|
245 | |
240 | |
246 | |
241 | |
247 | /* First, find the wall on that spot */ |
242 | /* First, find the wall on that spot */ |
248 | wall = get_wall (map, x, y); |
243 | wall = get_wall (map, x, y); |
249 | if (!wall) |
244 | if (!wall) |
… | |
… | |
263 | return; |
258 | return; |
264 | |
259 | |
265 | underscore++; |
260 | underscore++; |
266 | *underscore = '\0'; |
261 | *underscore = '\0'; |
267 | |
262 | |
268 | connect = 0; |
263 | int connect = 0; |
269 | |
264 | |
270 | if ((x > 0) && get_wall (map, x - 1, y)) |
265 | if ((x > 0) && get_wall (map, x - 1, y)) |
271 | connect |= 1; |
266 | connect |= 1; |
272 | if ((x < MAP_WIDTH (map) - 1) && get_wall (map, x + 1, y)) |
267 | if ((x < map->width - 1) && get_wall (map, x + 1, y)) |
273 | connect |= 2; |
268 | connect |= 2; |
274 | |
269 | |
275 | if ((y > 0) && get_wall (map, x, y - 1)) |
270 | if ((y > 0) && get_wall (map, x, y - 1)) |
276 | connect |= 4; |
271 | connect |= 4; |
277 | |
272 | |
278 | if ((y < MAP_HEIGHT (map) - 1) && get_wall (map, x, y + 1)) |
273 | if ((y < map->height - 1) && get_wall (map, x, y + 1)) |
279 | connect |= 8; |
274 | connect |= 8; |
280 | |
275 | |
281 | switch (connect) |
276 | switch (connect) |
282 | { |
277 | { |
283 | case 0: |
278 | case 0: |
… | |
… | |
356 | return; |
351 | return; |
357 | |
352 | |
358 | /* Now delete current wall, and insert new one |
353 | /* Now delete current wall, and insert new one |
359 | * We save flags to avoid any trouble with buildable/non buildable, and so on |
354 | * We save flags to avoid any trouble with buildable/non buildable, and so on |
360 | */ |
355 | */ |
361 | for (flag = 0; flag < 4; flag++) |
356 | object::flags_t old_flags = wall->flag; // elmex: this is where C++ pays off |
362 | old_flags[flag] = wall->flags[flag]; |
357 | |
363 | wall->remove (); |
|
|
364 | wall->destroy (0); |
358 | wall->destroy (); |
365 | |
359 | |
366 | wall = arch_to_object (new_arch); |
360 | wall = arch_to_object (new_arch); |
367 | wall->type = WALL; |
361 | wall->type = BUILDABLE_WALL; |
368 | insert_ob_in_map_at (wall, map, NULL, INS_ABOVE_FLOOR_ONLY, x, y); |
362 | insert_ob_in_map_at (wall, map, NULL, INS_ABOVE_FLOOR_ONLY, x, y); |
369 | for (flag = 0; flag < 4; flag++) |
|
|
370 | wall->flags[flag] = old_flags[flag]; |
363 | wall->flag = old_flags; |
371 | } |
364 | } |
372 | |
365 | |
373 | /** |
366 | /** |
374 | * \brief Floor building function |
367 | * \brief Floor building function |
375 | * |
368 | * |
… | |
… | |
403 | if (tmp) |
396 | if (tmp) |
404 | { |
397 | { |
405 | while (tmp) |
398 | while (tmp) |
406 | { |
399 | { |
407 | above = tmp->above; |
400 | above = tmp->above; |
408 | if (WALL == tmp->type) |
401 | if (BUILDABLE_WALL == tmp->type) |
409 | { |
402 | { |
410 | /* There was a wall, remove it & keep its archetype to make new walls */ |
403 | /* There was a wall, remove it & keep its archetype to make new walls */ |
411 | new_wall = tmp->arch; |
404 | new_wall = tmp->arch; |
412 | tmp->remove (); |
|
|
413 | tmp->destroy (0); |
405 | tmp->destroy (); |
414 | sprintf (message, "You destroy the wall and redo the floor."); |
406 | sprintf (message, "You destroy the wall and redo the floor."); |
415 | } |
407 | } |
416 | else if ((FLOOR == tmp->type) || (QUERY_FLAG (tmp, FLAG_IS_FLOOR))) |
408 | else if ((FLOOR == tmp->type) || (QUERY_FLAG (tmp, FLAG_IS_FLOOR))) |
417 | { |
409 | { |
418 | tmp->remove (); |
|
|
419 | tmp->destroy (0); |
410 | tmp->destroy (); |
420 | floor_removed = 1; |
411 | floor_removed = 1; |
421 | } |
412 | } |
422 | else |
413 | else |
423 | { |
414 | { |
424 | if (floor_removed) |
415 | if (floor_removed) |
… | |
… | |
466 | /* Insert wall if exists. Note: if it doesn't, the map is weird... */ |
457 | /* Insert wall if exists. Note: if it doesn't, the map is weird... */ |
467 | if (new_wall) |
458 | if (new_wall) |
468 | { |
459 | { |
469 | tmp = arch_to_object (new_wall); |
460 | tmp = arch_to_object (new_wall); |
470 | SET_FLAG (tmp, FLAG_IS_BUILDABLE); |
461 | SET_FLAG (tmp, FLAG_IS_BUILDABLE); |
471 | tmp->type = WALL; |
462 | tmp->type = BUILDABLE_WALL; |
472 | insert_ob_in_map_at (tmp, pl->map, 0, 0, xt, yt); |
463 | insert_ob_in_map_at (tmp, pl->map, 0, 0, xt, yt); |
473 | } |
464 | } |
474 | } |
465 | } |
475 | } |
466 | } |
476 | |
467 | |
… | |
… | |
528 | /* Grab existing wall, if any */ |
519 | /* Grab existing wall, if any */ |
529 | current_wall = NULL; |
520 | current_wall = NULL; |
530 | tmp = GET_MAP_OB (pl->map, x, y); |
521 | tmp = GET_MAP_OB (pl->map, x, y); |
531 | while (tmp && !current_wall) |
522 | while (tmp && !current_wall) |
532 | { |
523 | { |
533 | if (WALL == tmp->type) |
524 | if (BUILDABLE_WALL == tmp->type) |
534 | current_wall = tmp; |
525 | current_wall = tmp; |
535 | |
526 | |
536 | tmp = tmp->above; |
527 | tmp = tmp->above; |
537 | } |
528 | } |
538 | |
529 | |
… | |
… | |
546 | LOG (llevError, "apply_builder_wall: unable to find archetype %s\n", &material->slaying); |
537 | LOG (llevError, "apply_builder_wall: unable to find archetype %s\n", &material->slaying); |
547 | return; |
538 | return; |
548 | } |
539 | } |
549 | |
540 | |
550 | tmp = arch_to_object (new_wall); |
541 | tmp = arch_to_object (new_wall); |
551 | tmp->type = WALL; |
542 | tmp->type = BUILDABLE_WALL; |
552 | SET_FLAG (tmp, FLAG_IS_BUILDABLE); |
543 | SET_FLAG (tmp, FLAG_IS_BUILDABLE); |
553 | insert_ob_in_map_at (tmp, pl->map, 0, INS_ABOVE_FLOOR_ONLY, x, y); |
544 | insert_ob_in_map_at (tmp, pl->map, 0, INS_ABOVE_FLOOR_ONLY, x, y); |
554 | |
545 | |
555 | /* If existing wall, remove it, no need to fix other walls */ |
546 | /* If existing wall, remove it, no need to fix other walls */ |
556 | if (current_wall) |
547 | if (current_wall) |
557 | { |
548 | { |
558 | current_wall->remove (); |
|
|
559 | current_wall->destroy (0); |
549 | current_wall->destroy (); |
560 | fix_walls (pl->map, x, y); |
550 | fix_walls (pl->map, x, y); |
561 | sprintf (message, "You redecorate the wall to better suit your tastes."); |
551 | sprintf (message, "You redecorate the wall to better suit your tastes."); |
562 | } |
552 | } |
563 | else |
553 | else |
564 | { |
554 | { |
… | |
… | |
655 | con_rune = get_connection_rune (pl, x, y); |
645 | con_rune = get_connection_rune (pl, x, y); |
656 | connected = find_or_create_connection_for_map (pl, x, y, con_rune); |
646 | connected = find_or_create_connection_for_map (pl, x, y, con_rune); |
657 | if (connected == -1) |
647 | if (connected == -1) |
658 | { |
648 | { |
659 | /* Player already informed of failure by the previous function */ |
649 | /* Player already informed of failure by the previous function */ |
660 | tmp->destroy (0); |
650 | tmp->destroy (); |
661 | return; |
651 | return; |
662 | } |
652 | } |
663 | /* Remove marking rune */ |
653 | /* Remove marking rune */ |
664 | con_rune->remove (); |
|
|
665 | con_rune->destroy (0); |
654 | con_rune->destroy (); |
666 | } |
655 | } |
667 | |
656 | |
668 | /* For magic mouths/ears, and signs, take the msg from a book of scroll */ |
657 | /* For magic mouths/ears, and signs, take the msg from a book of scroll */ |
669 | if ((tmp->type == SIGN) || (tmp->type == MAGIC_EAR)) |
658 | if ((tmp->type == SIGN) || (tmp->type == MAGIC_EAR)) |
670 | { |
659 | { |
671 | if (adjust_sign_msg (pl, x, y, tmp) == -1) |
660 | if (adjust_sign_msg (pl, x, y, tmp) == -1) |
672 | { |
661 | { |
673 | tmp->destroy (0); |
662 | tmp->destroy (); |
674 | return; |
663 | return; |
675 | } |
664 | } |
676 | } |
665 | } |
677 | |
666 | |
678 | insert_ob_in_map_at (tmp, pl->map, floor, insert_flag, x, y); |
667 | insert_ob_in_map_at (tmp, pl->map, floor, insert_flag, x, y); |
… | |
… | |
709 | |
698 | |
710 | if (item->type == FLOOR || QUERY_FLAG (item, FLAG_IS_FLOOR)) |
699 | if (item->type == FLOOR || QUERY_FLAG (item, FLAG_IS_FLOOR)) |
711 | item = item->above; |
700 | item = item->above; |
712 | |
701 | |
713 | if (!item) |
702 | if (!item) |
714 | { |
|
|
715 | new_draw_info (NDI_UNIQUE, 0, pl, "Nothing to remove."); |
703 | new_draw_info (NDI_UNIQUE, 0, pl, "Nothing to remove."); |
716 | return; |
704 | else if (item->type == BUILDABLE_WALL) |
717 | } |
|
|
718 | |
|
|
719 | /* Now remove object, with special cases (buttons & such) */ |
|
|
720 | switch (item->type) |
|
|
721 | { |
|
|
722 | case WALL: |
|
|
723 | new_draw_info (NDI_UNIQUE, 0, pl, "Can't remove a wall with that, build a floor."); |
705 | new_draw_info (NDI_UNIQUE, 0, pl, "Can't remove a wall with that, build a floor."); |
724 | return; |
706 | else if (!item->flag [FLAG_IS_BUILDABLE]) |
725 | |
707 | new_draw_info_format (NDI_UNIQUE, 0, pl, "You can't remove the %s, it's not buildable!", query_name (item)); |
726 | case DOOR: |
708 | else |
727 | case BUTTON: |
709 | { |
728 | case GATE: |
|
|
729 | case TIMED_GATE: |
|
|
730 | case DETECTOR: |
|
|
731 | case PEDESTAL: |
|
|
732 | case CF_HANDLE: |
|
|
733 | case MAGIC_EAR: |
|
|
734 | case SIGN: |
|
|
735 | /* Special case: must unconnect */ |
|
|
736 | if (QUERY_FLAG (item, FLAG_IS_LINKED)) |
|
|
737 | remove_button_link (item); |
|
|
738 | |
|
|
739 | /* Fall through */ |
|
|
740 | |
|
|
741 | default: |
|
|
742 | /* Remove generic item */ |
|
|
743 | new_draw_info_format (NDI_UNIQUE, 0, pl, "You remove the %s", query_name (item)); |
710 | new_draw_info_format (NDI_UNIQUE, 0, pl, "You remove the %s", query_name (item)); |
744 | item->remove (); |
|
|
745 | item->destroy (0); |
711 | item->destroy (); |
746 | } |
712 | } |
747 | } |
713 | } |
748 | |
714 | |
749 | /** |
715 | /** |
750 | * Global building function |
716 | * Global building function |
… | |
… | |
776 | } |
742 | } |
777 | |
743 | |
778 | x = pl->x + freearr_x[dir]; |
744 | x = pl->x + freearr_x[dir]; |
779 | y = pl->y + freearr_y[dir]; |
745 | y = pl->y + freearr_y[dir]; |
780 | |
746 | |
781 | if ((1 > x) || (1 > y) || ((MAP_WIDTH (pl->map) - 2) < x) || ((MAP_HEIGHT (pl->map) - 2) < y)) |
747 | if ((1 > x) || (1 > y) || ((pl->map->width - 2) < x) || ((pl->map->height - 2) < y)) |
782 | { |
748 | { |
783 | new_draw_info (NDI_UNIQUE, 0, pl, "Can't build on map edge..."); |
749 | new_draw_info (NDI_UNIQUE, 0, pl, "Can't build on map edge..."); |
784 | return; |
750 | return; |
785 | } |
751 | } |
786 | |
752 | |
… | |
… | |
911 | } |
877 | } |
912 | |
878 | |
913 | tmp->face = book->face; |
879 | tmp->face = book->face; |
914 | tmp->invisible = 0; |
880 | tmp->invisible = 0; |
915 | } |
881 | } |
916 | book->remove (); |
882 | |
917 | book->destroy (0); |
883 | book->destroy (); |
918 | return 0; |
884 | return 0; |
919 | } |
885 | } |