1 | /* |
1 | /* |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2001 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2001 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992 Frank Tore Johansen |
6 | * Copyright (©) 1992 Frank Tore Johansen |
7 | * |
7 | * |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
9 | * the terms of the Affero GNU General Public License as published by the |
9 | * the terms of the Affero GNU General Public License as published by the |
… | |
… | |
324 | new_arch = archetype::find (archetype); |
324 | new_arch = archetype::find (archetype); |
325 | |
325 | |
326 | if (!new_arch) |
326 | if (!new_arch) |
327 | return; |
327 | return; |
328 | |
328 | |
329 | /* Now delete current wall, and insert new one |
329 | /* Now delete current wall, and insert new one |
330 | * We save flags to avoid any trouble with buildable/non buildable, and so on |
330 | * We save flags to avoid any trouble with buildable/non buildable, and so on |
331 | */ |
331 | */ |
332 | object::flags_t old_flags = wall->flag; // elmex: this is where C++ pays off |
332 | object::flags_t old_flags = wall->flag; // elmex: this is where C++ pays off |
333 | |
333 | |
334 | wall->destroy (); |
334 | wall->destroy (); |
… | |
… | |
360 | char message[MAX_BUF]; |
360 | char message[MAX_BUF]; |
361 | |
361 | |
362 | sprintf (message, "You change the floor to better suit your tastes."); |
362 | sprintf (message, "You change the floor to better suit your tastes."); |
363 | |
363 | |
364 | /* |
364 | /* |
365 | * Now the building part... |
365 | * Now the building part... |
366 | * First, remove wall(s) and floor(s) at position x, y |
366 | * First, remove wall(s) and floor(s) at position x, y |
367 | */ |
367 | */ |
368 | above_floor = NULL; |
368 | above_floor = NULL; |
369 | new_wall = NULL; |
369 | new_wall = NULL; |
370 | floor_removed = 0; |
370 | floor_removed = 0; |
… | |
… | |
420 | * Next step: make sure there are either walls or floors around the new square |
420 | * Next step: make sure there are either walls or floors around the new square |
421 | * Since building, you can have: blocking view / floor / wall / nothing |
421 | * Since building, you can have: blocking view / floor / wall / nothing |
422 | */ |
422 | */ |
423 | for (i = 1; i <= 8; i++) |
423 | for (i = 1; i <= 8; i++) |
424 | { |
424 | { |
425 | xt = x + freearr_x[i]; |
425 | xt = x + DIRX (i); |
426 | yt = y + freearr_y[i]; |
426 | yt = y + DIRY (i); |
427 | tmp = GET_MAP_OB (pl->map, xt, yt); |
427 | tmp = GET_MAP_OB (pl->map, xt, yt); |
428 | if (!tmp) |
428 | if (!tmp) |
429 | { |
429 | { |
430 | /* Must insert floor & wall */ |
430 | /* Must insert floor & wall */ |
431 | tmp = new_floor->instance (); |
431 | tmp = new_floor->instance (); |
… | |
… | |
647 | apply_builder_remove (object *pl, int dir) |
647 | apply_builder_remove (object *pl, int dir) |
648 | { |
648 | { |
649 | object *item; |
649 | object *item; |
650 | int x, y; |
650 | int x, y; |
651 | |
651 | |
652 | x = pl->x + freearr_x[dir]; |
652 | x = pl->x + DIRX (dir); |
653 | y = pl->y + freearr_y[dir]; |
653 | y = pl->y + DIRY (dir); |
654 | |
654 | |
655 | /* Check square */ |
655 | /* Check square */ |
656 | item = GET_MAP_OB (pl->map, x, y); |
656 | item = GET_MAP_OB (pl->map, x, y); |
657 | if (!item) |
657 | if (!item) |
658 | { |
658 | { |
… | |
… | |
690 | } |
690 | } |
691 | |
691 | |
692 | /** |
692 | /** |
693 | * Quad building. |
693 | * Quad building. |
694 | */ |
694 | */ |
695 | void |
695 | static void |
696 | apply_builder_quad (object *pl, object *material, mapxy &pos) |
696 | apply_builder_quad (object *pl, object *material, mapxy &pos) |
697 | { |
697 | { |
698 | object *open_space = 0; |
698 | object *open_space = 0; |
699 | object *floor = 0; |
699 | object *floor = 0; |
700 | |
700 | |
… | |
… | |
702 | bool floor_exists = false; |
702 | bool floor_exists = false; |
703 | while (tmp) |
703 | while (tmp) |
704 | { |
704 | { |
705 | if (floor_exists && tmp->flag [FLAG_IS_QUAD]) |
705 | if (floor_exists && tmp->flag [FLAG_IS_QUAD]) |
706 | { |
706 | { |
707 | pl->failmsg ( |
|
|
708 | "You can't build there, there is a block in the way."); |
707 | pl->failmsg ("You can't build there, there is a block in the way."); |
709 | return; |
708 | return; |
710 | } |
709 | } |
711 | |
710 | |
712 | if (IS_FLOOR (tmp)) |
711 | if (IS_FLOOR (tmp)) |
713 | { |
712 | { |
714 | floor = tmp; |
713 | floor = tmp; |
715 | floor_exists = true; |
714 | floor_exists = true; |
716 | |
715 | |
717 | if (floor->arch->archname == shstr_quad_open_space) |
716 | if (floor->arch->archname == shstr_quad_open_space) |
718 | { |
|
|
719 | open_space = floor; |
717 | open_space = floor; |
720 | } |
|
|
721 | else if (!floor->flag [FLAG_IS_QUAD]) |
718 | else if (!floor->flag [FLAG_IS_QUAD]) |
722 | { |
719 | { |
723 | pl->failmsg ( |
|
|
724 | "You can't build there, the floor is not suited."); |
720 | pl->failmsg ("You can't build there, the floor is not suited."); |
725 | return; |
721 | return; |
726 | } |
722 | } |
727 | } |
723 | } |
728 | |
724 | |
729 | tmp = tmp->above; |
725 | tmp = tmp->above; |
… | |
… | |
733 | { |
729 | { |
734 | if (!material->slaying) |
730 | if (!material->slaying) |
735 | { |
731 | { |
736 | pl->failmsg ( |
732 | pl->failmsg ( |
737 | "The floor is open and you can't fill it with that material." |
733 | "The floor is open and you can't fill it with that material." |
738 | "H<Use another material to fill the ceiling.>"); |
734 | "H<Use another material to fill the ceiling.>" |
|
|
735 | ); |
739 | return; |
736 | return; |
740 | } |
737 | } |
741 | |
738 | |
742 | replace_open_space_floor (open_space, material); |
739 | replace_open_space_floor (open_space, material); |
743 | pl->contr->fire_on = 0; // TODO: stopgap, do not add more than one per keypress |
740 | pl->contr->fire_on = 0; // TODO: stopgap, do not add more than one per keypress |
… | |
… | |
747 | { |
744 | { |
748 | |
745 | |
749 | maptile *upper_floor = pos.m->tile_available (TILE_UP); |
746 | maptile *upper_floor = pos.m->tile_available (TILE_UP); |
750 | if (!upper_floor) |
747 | if (!upper_floor) |
751 | { |
748 | { |
752 | pl->failmsg ( |
|
|
753 | "Whoops, you can't see the ceiling.. H<You may try again.>"); |
749 | pl->failmsg ("Whoops, you can't see the ceiling.. H<You may try again.>"); |
754 | return; |
750 | return; |
755 | } |
751 | } |
756 | |
752 | |
757 | mapxy above_pos (upper_floor, pos.x, pos.y); |
753 | mapxy above_pos (upper_floor, pos.x, pos.y); |
758 | if (!above_pos.normalise ()) |
754 | if (!above_pos.normalise ()) |
759 | { |
755 | { |
760 | pl->failmsg ( |
|
|
761 | "Whoops, you can't access the ceiling. H<You may try again.>"); |
756 | pl->failmsg ("Whoops, you can't access the ceiling. H<You may try again.>"); |
762 | return; |
757 | return; |
763 | } |
758 | } |
764 | |
759 | |
765 | mapspace &above_ms = above_pos.ms (); |
760 | mapspace &above_ms = above_pos.ms (); |
766 | for (object *quad_obj = above_ms.top; quad_obj; quad_obj = quad_obj->below) |
761 | for (object *quad_obj = above_ms.top; quad_obj; quad_obj = quad_obj->below) |
767 | { |
762 | { |
768 | if (quad_obj->arch->archname == shstr_quad_open_space) |
763 | if (quad_obj->arch->archname == shstr_quad_open_space) |
769 | { |
764 | { |
770 | if (!material->slaying) |
765 | if (!material->slaying) |
771 | { |
766 | { |
772 | pl->failmsg ( |
|
|
773 | "The ceiling is open and you can't fill it with that material." |
767 | pl->failmsg ("The ceiling is open and you can't fill it with that material." |
774 | "H<Use another material to fill the ceiling.>"); |
768 | "H<Use another material to fill the ceiling.>"); |
775 | return; |
769 | return; |
776 | } |
770 | } |
777 | |
771 | |
778 | replace_open_space_floor (quad_obj, material); |
772 | replace_open_space_floor (quad_obj, material); |
… | |
… | |
780 | } |
774 | } |
781 | } |
775 | } |
782 | |
776 | |
783 | if (material->destroyed ()) |
777 | if (material->destroyed ()) |
784 | { |
778 | { |
785 | pl->failmsg ( |
|
|
786 | "You don't have enough build material to build a wall here."); |
779 | pl->failmsg ("You don't have enough build material to build a wall here."); |
787 | return; |
780 | return; |
788 | } |
781 | } |
789 | |
782 | |
790 | object *quad_wall = material->other_arch->instance (); |
783 | object *quad_wall = material->other_arch->instance (); |
791 | material->decrease (); |
784 | material->decrease (); |
792 | |
785 | |
793 | insert_ob_in_map_at (quad_wall, floor->map, 0, |
786 | insert_ob_in_map_at (quad_wall, floor->map, 0, |
794 | INS_ABOVE_FLOOR_ONLY, floor->x, floor->y); |
787 | INS_ABOVE_FLOOR_ONLY, floor->x, floor->y); |
795 | } |
788 | } |
796 | else |
789 | else |
797 | { |
|
|
798 | pl->failmsg ("You can't build a quad block here."); |
790 | pl->failmsg ("You can't build a quad block here."); |
799 | } |
|
|
800 | } |
791 | } |
801 | |
792 | |
802 | /** |
793 | /** |
803 | * Global building function |
794 | * Global building function |
804 | * |
795 | * |