ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/build_map.C
(Generate patch)

Comparing deliantra/server/server/build_map.C (file contents):
Revision 1.63 by root, Sat Apr 23 04:56:54 2011 UTC vs.
Revision 1.68 by root, Mon Oct 29 23:55:55 2012 UTC

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 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012 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
10 * Free Software Foundation, either version 3 of the License, or (at your 10 * Free Software Foundation, either version 3 of the License, or (at your
11 * option) any later version. 11 * option) any later version.
12 * 12 *
13 * This program is distributed in the hope that it will be useful, 13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details. 16 * GNU General Public License for more details.
17 * 17 *
18 * You should have received a copy of the Affero GNU General Public License 18 * You should have received a copy of the Affero GNU General Public License
19 * and the GNU General Public License along with this program. If not, see 19 * and the GNU General Public License along with this program. If not, see
20 * <http://www.gnu.org/licenses/>. 20 * <http://www.gnu.org/licenses/>.
21 * 21 *
22 * The authors can be reached via e-mail to <support@deliantra.net> 22 * The authors can be reached via e-mail to <support@deliantra.net>
23 */ 23 */
24 24
25#include <global.h> 25#include <global.h>
26#include <living.h> 26#include <living.h>
174 { 174 {
175 new_draw_info (NDI_UNIQUE, 0, pl, "Could not create more groups."); 175 new_draw_info (NDI_UNIQUE, 0, pl, "Could not create more groups.");
176 return shstr_tmp (); 176 return shstr_tmp ();
177 } 177 }
178 178
179 force = get_archetype (FORCE_NAME); 179 force = archetype::get (FORCE_NAME);
180 force->slaying = pl->map->path; 180 force->slaying = pl->map->path;
181 force->msg = rune->msg; 181 force->msg = rune->msg;
182 force->race = id; 182 force->race = id;
183 force->set_speed (0); 183 force->set_speed (0);
184 184
676 new_draw_info_format (NDI_UNIQUE, 0, pl, "You remove the %s", query_name (item)); 676 new_draw_info_format (NDI_UNIQUE, 0, pl, "You remove the %s", query_name (item));
677 item->destroy (); 677 item->destroy ();
678 } 678 }
679} 679}
680 680
681
682static void
683replace_open_space_floor (object *os, object *material)
684{
685 object *new_floor = archetype::get (material->slaying);
686 insert_ob_in_map_at (new_floor, os->map, os,
687 INS_BELOW_ORIGINATOR, os->x, os->y);
688 os->destroy ();
689 material->decrease ();
690}
691
692/**
693 * Quad building.
694 */
695void
696apply_builder_quad (object *pl, object *material, mapxy &pos)
697{
698 object *open_space = 0;
699 object *floor = 0;
700
701 object *tmp = pos.ms ().bot;
702 bool floor_exists = false;
703 while (tmp)
704 {
705 if (floor_exists && tmp->flag [FLAG_IS_QUAD])
706 {
707 pl->failmsg (
708 "You can't build there, there is a block in the way.");
709 return;
710 }
711
712 if (IS_FLOOR (tmp))
713 {
714 floor = tmp;
715 floor_exists = true;
716
717 if (floor->arch->archname == shstr_quad_open_space)
718 {
719 open_space = floor;
720 }
721 else if (!floor->flag [FLAG_IS_QUAD])
722 {
723 pl->failmsg (
724 "You can't build there, the floor is not suited.");
725 return;
726 }
727 }
728
729 tmp = tmp->above;
730 }
731
732 if (open_space)
733 {
734 if (!material->slaying)
735 {
736 pl->failmsg (
737 "The floor is open and you can't fill it with that material."
738 "H<Use another material to fill the ceiling.>");
739 return;
740 }
741
742 replace_open_space_floor (open_space, material);
743 pl->contr->fire_on = 0; // TODO: stopgap, do not add more than one per keypress
744 return;
745 }
746 else if (floor)
747 {
748
749 maptile *upper_floor = pos.m->tile_available (TILE_UP);
750 if (!upper_floor)
751 {
752 pl->failmsg (
753 "Whoops, you can't see the ceiling.. H<You may try again.>");
754 return;
755 }
756
757 mapxy above_pos (upper_floor, pos.x, pos.y);
758 if (!above_pos.normalise ())
759 {
760 pl->failmsg (
761 "Whoops, you can't access the ceiling. H<You may try again.>");
762 return;
763 }
764
765 mapspace &above_ms = above_pos.ms ();
766 for (object *quad_obj = above_ms.top; quad_obj; quad_obj = quad_obj->below)
767 {
768 if (quad_obj->arch->archname == shstr_quad_open_space)
769 {
770 if (!material->slaying)
771 {
772 pl->failmsg (
773 "The ceiling is open and you can't fill it with that material."
774 "H<Use another material to fill the ceiling.>");
775 return;
776 }
777
778 replace_open_space_floor (quad_obj, material);
779 break;
780 }
781 }
782
783 if (material->destroyed ())
784 {
785 pl->failmsg (
786 "You don't have enough build material to build a wall here.");
787 return;
788 }
789
790 object *quad_wall = material->other_arch->instance ();
791 material->decrease ();
792
793 insert_ob_in_map_at (quad_wall, floor->map, 0,
794 INS_ABOVE_FLOOR_ONLY, floor->x, floor->y);
795 }
796 else
797 {
798 pl->failmsg ("You can't build a quad block here.");
799 }
800}
801
681/** 802/**
682 * Global building function 803 * Global building function
683 * 804 *
684 * This is the general map building function. Called when the player 'fires' a builder 805 * This is the general map building function. Called when the player 'fires' a builder
685 * or remover object. 806 * or remover object.
686 */ 807 */
687void 808void
688apply_map_builder (object *pl, int dir) 809apply_map_builder (object *pl, int dir)
689{ 810{
690 int x, y;
691
692 if (!pl->type == PLAYER) 811 if (!pl->type == PLAYER)
693 return; 812 return;
694 813
695 /*if ( !player->map->unique )
696 {
697 new_draw_info( NDI_UNIQUE, 0, player, "You can't build outside a unique map." );
698 return;
699 } */
700
701 if (dir == 0) 814 if (dir == 0)
702 { 815 {
703 new_draw_info (NDI_UNIQUE, 0, pl, "You can't build or destroy under yourself."); 816 new_draw_info (NDI_UNIQUE, 0, pl, "You can't build or destroy under yourself.");
704 return; 817 return;
705 } 818 }
706 819
707 x = pl->x + freearr_x[dir]; 820 mapxy pos (pl); pos.move (dir);
708 y = pl->y + freearr_y[dir];
709 821
710 if ((1 > x) || (1 > y) || ((pl->map->width - 2) < x) || ((pl->map->height - 2) < y)) 822 if (!pos.normalise ())
711 { 823 {
712 new_draw_info (NDI_UNIQUE, 0, pl, "Can't build on map edge..."); 824 pl->failmsg ("You can't build here. H<There is nothing in this direction.>");
713 return; 825 return;
714 } 826 }
715 827
716 /* 828 /*
717 * Check specified square 829 * Check specified square
718 * The square must have only buildable items 830 * The square must have only buildable items
719 * Exception: marking runes are all right, 831 * Exception: marking runes are all right,
720 * since they are used for special things like connecting doors / buttons 832 * since they are used for special things like connecting doors / buttons
721 */ 833 */
722 834
723 object *tmp = GET_MAP_OB (pl->map, x, y);
724 if (!tmp)
725 {
726 /* Nothing, meaning player is standing next to an undefined square... */
727 LOG (llevError, "apply_map_builder: undefined square at (%d, %d, %s)\n", x, y, &pl->map->path);
728 new_draw_info (NDI_UNIQUE, 0, pl, "You'd better not build here, it looks weird.");
729 return;
730 }
731
732 object *builder = pl->contr->ranged_ob; 835 object *builder = pl->contr->ranged_ob;
733 836
734 object *tmp2 = pl->mark (); 837 object *tmp2 = pl->mark ();
735 838
736 while (tmp) 839 object *tmp = 0;
840 for (tmp = pos.ms ().bot; tmp; tmp = tmp->above)
737 { 841 {
842 if (!tmp->flag [FLAG_IS_BUILDABLE]
738 if (!tmp->flag [FLAG_IS_BUILDABLE] && (tmp->type != SIGN || tmp->arch->archname != shstr_rune_mark)) 843 && (tmp->type != SIGN || tmp->arch->archname != shstr_rune_mark))
739 { 844 {
740 /* The item building function already has it's own special 845 /* The item building function already has it's own special
741 * checks for this 846 * checks for this. And so does the quad building function.
742 */ 847 */
743 if (!tmp2 || tmp2->subtype != ST_MAT_ITEM) 848 if (!tmp2 || (tmp2->subtype != ST_MAT_ITEM && tmp2->subtype != ST_MAT_QUAD))
744 { 849 {
745 if (!INVOKE_PLAYER (BUILD, pl->contr, ARG_OBJECT (builder), ARG_MAP (pl->map), ARG_INT (x), ARG_INT (y), ARG_INT (0))) 850 if (!INVOKE_PLAYER (BUILD, pl->contr, ARG_OBJECT (builder),
851 ARG_MAP (pl->map),
852 ARG_INT (pos.y), ARG_INT (pos.y),
853 ARG_INT (0)))
746 new_draw_info (NDI_UNIQUE, 0, pl, "You can't build here."); 854 new_draw_info (NDI_UNIQUE, 0, pl, "You can't build here.");
747 855
748 return; 856 return;
749 } 857 }
750 } 858 }
751
752 tmp = tmp->above;
753 } 859 }
754 860
755 /* Now we know the square is ok */ 861 /* Now we know the square is ok */
756 if (INVOKE_PLAYER (BUILD, pl->contr, ARG_OBJECT (builder), ARG_MAP (pl->map), ARG_INT (x), ARG_INT (y), ARG_INT (1))) 862 if (INVOKE_PLAYER (BUILD, pl->contr, ARG_OBJECT (builder),
863 ARG_MAP (pl->map), ARG_INT (pos.x), ARG_INT (pos.y), ARG_INT (1)))
757 return; 864 return;
758 865
759 if (builder->subtype == ST_BD_REMOVE) 866 if (builder->subtype == ST_BD_REMOVE)
760 /* Remover -> call specific function and bail out */ 867 /* Remover -> call specific function and bail out */
761 { 868 {
783 } 890 }
784 891
785 switch (tmp->subtype) 892 switch (tmp->subtype)
786 { 893 {
787 case ST_MAT_FLOOR: 894 case ST_MAT_FLOOR:
788 apply_builder_floor (pl, tmp, x, y); 895 apply_builder_floor (pl, tmp, pos.x, pos.y);
789 return; 896 return;
790 897
791 case ST_MAT_WALL: 898 case ST_MAT_WALL:
792 apply_builder_wall (pl, tmp, x, y); 899 apply_builder_wall (pl, tmp, pos.x, pos.y);
793 return; 900 return;
794 901
795 case ST_MAT_ITEM: 902 case ST_MAT_ITEM:
796 apply_builder_item (pl, tmp, x, y); 903 apply_builder_item (pl, tmp, pos.x, pos.y);
904 return;
905
906 case ST_MAT_QUAD:
907 apply_builder_quad (pl, tmp, pos);
797 return; 908 return;
798 909
799 default: 910 default:
800 new_draw_info (NDI_UNIQUE, 0, pl, "Don't know how to apply this material, sorry."); 911 new_draw_info (NDI_UNIQUE, 0, pl, "Don't know how to apply this material, sorry.");
801 LOG (llevError, "apply_map_builder: invalid material subtype %d\n", tmp->subtype); 912 LOG (llevError, "apply_map_builder: invalid material subtype %d\n", tmp->subtype);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines