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.57 by elmex, Tue Apr 13 18:10:54 2010 UTC vs.
Revision 1.66 by root, Tue Jan 3 11:25:36 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 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
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
222 { 222 {
223 new_draw_info (NDI_UNIQUE, 0, pl, "You need to put a book or scroll with the message."); 223 new_draw_info (NDI_UNIQUE, 0, pl, "You need to put a book or scroll with the message.");
224 return -1; 224 return -1;
225 } 225 }
226 226
227 if (tmp->type == MAGIC_EAR)
228 {
229 snprintf (buf, sizeof (buf), "@match %s", &(book->msg));
230 tmp->msg = buf;
231 }
232 else
227 tmp->msg = book->msg; 233 tmp->msg = book->msg;
228 234
229 if (tmp->invisible) 235 if (tmp->invisible)
230 { 236 {
231 if (book->custom_name) 237 if (book->custom_name)
232 snprintf (buf, sizeof (buf), "talking %s", &book->custom_name); 238 snprintf (buf, sizeof (buf), "talking %s", &book->custom_name);
307 if (x > 0 && get_wall (map, x - 1, y)) connect |= 1; 313 if (x > 0 && get_wall (map, x - 1, y)) connect |= 1;
308 if (x < map->width - 1 && get_wall (map, x + 1, y)) connect |= 2; 314 if (x < map->width - 1 && get_wall (map, x + 1, y)) connect |= 2;
309 if (y > 0 && get_wall (map, x, y - 1)) connect |= 4; 315 if (y > 0 && get_wall (map, x, y - 1)) connect |= 4;
310 if (y < map->height - 1 && get_wall (map, x, y + 1)) connect |= 8; 316 if (y < map->height - 1 && get_wall (map, x, y + 1)) connect |= 8;
311 317
312 // one bit per dir, 1 left, 2 right, 4 up, 8 down
313 static const char *walltype[16] = {
314 "0",
315 "1_3",
316 "1_4",
317 "2_1_2",
318 "1_2",
319 "2_2_4",
320 "2_2_1",
321 "3_1",
322 "1_1",
323 "2_2_3",
324 "2_2_2",
325 "3_3",
326 "2_1_1",
327 "3_4",
328 "3_2",
329 "4"
330 };
331
332 strcat (archetype, walltype [connect]); 318 strcat (archetype, wall_suffix [connect]);
333 319
334 /* 320 /*
335 * Before anything, make sure the archetype does exist... 321 * Before anything, make sure the archetype does exist...
336 * If not, prolly an error... 322 * If not, prolly an error...
337 */ 323 */
690 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));
691 item->destroy (); 677 item->destroy ();
692 } 678 }
693} 679}
694 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
695/** 802/**
696 * Global building function 803 * Global building function
697 * 804 *
698 * 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
699 * or remover object. 806 * or remover object.
700 */ 807 */
701void 808void
702apply_map_builder (object *pl, int dir) 809apply_map_builder (object *pl, int dir)
703{ 810{
704 object *builder = 0;
705 object *tmp = 0;
706 object *tmp2 = 0;
707 int x, y;
708
709 if (!pl->type == PLAYER) 811 if (!pl->type == PLAYER)
710 return; 812 return;
711 813
712 /*if ( !player->map->unique )
713 {
714 new_draw_info( NDI_UNIQUE, 0, player, "You can't build outside a unique map." );
715 return;
716 } */
717
718 if (dir == 0) 814 if (dir == 0)
719 { 815 {
720 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.");
721 return; 817 return;
722 } 818 }
723 819
724 x = pl->x + freearr_x[dir]; 820 mapxy pos (pl); pos.move (dir);
725 y = pl->y + freearr_y[dir];
726 821
727 if ((1 > x) || (1 > y) || ((pl->map->width - 2) < x) || ((pl->map->height - 2) < y)) 822 if (!pos.normalise ())
728 { 823 {
729 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.>");
730 return; 825 return;
731 } 826 }
732 827
733 /* 828 /*
734 * Check specified square 829 * Check specified square
735 * The square must have only buildable items 830 * The square must have only buildable items
736 * Exception: marking runes are all right, 831 * Exception: marking runes are all right,
737 * since they are used for special things like connecting doors / buttons 832 * since they are used for special things like connecting doors / buttons
738 */ 833 */
739 834
740 tmp = GET_MAP_OB (pl->map, x, y); 835 object *builder = pl->contr->ranged_ob;
741 if (!tmp) 836
742 { 837 object *tmp2 = pl->mark ();
743 /* Nothing, meaning player is standing next to an undefined square... */ 838
744 LOG (llevError, "apply_map_builder: undefined square at (%d, %d, %s)\n", x, y, &pl->map->path); 839 mapspace &ms = pos.ms ();
745 new_draw_info (NDI_UNIQUE, 0, pl, "You'd better not build here, it looks weird."); 840
746 return; 841 object *tmp = 0;
842 for (tmp = pos.ms ().bot; tmp; tmp = tmp->above)
747 } 843 {
748 844 if (!tmp->flag [FLAG_IS_BUILDABLE]
749 if (INVOKE_PLAYER (BUILD, pl->contr, ARG_OBJECT (builder), ARG_MAP (pl->map), ARG_INT (x), ARG_INT (y)))
750 return;
751
752 tmp2 = find_marked_object (pl);
753 while (tmp)
754 {
755 if (!tmp->flag [FLAG_IS_BUILDABLE] && (tmp->type != SIGN || tmp->arch->archname != shstr_rune_mark)) 845 && (tmp->type != SIGN || tmp->arch->archname != shstr_rune_mark))
756 { 846 {
757 /* The item building function already has it's own special 847 /* The item building function already has it's own special
758 * checks for this 848 * checks for this. And so does the quad building function.
759 */ 849 */
760 if (!tmp2 || tmp2->subtype != ST_MAT_ITEM) 850 if (!tmp2 || (tmp2->subtype != ST_MAT_ITEM && tmp2->subtype != ST_MAT_QUAD))
761 { 851 {
852 if (!INVOKE_PLAYER (BUILD, pl->contr, ARG_OBJECT (builder),
853 ARG_MAP (pl->map),
854 ARG_INT (pos.y), ARG_INT (pos.y),
855 ARG_INT (0)))
762 new_draw_info (NDI_UNIQUE, 0, pl, "You can't build here."); 856 new_draw_info (NDI_UNIQUE, 0, pl, "You can't build here.");
857
763 return; 858 return;
764 } 859 }
765 } 860 }
766
767 tmp = tmp->above;
768 } 861 }
769 862
770 /* Now we know the square is ok */ 863 /* Now we know the square is ok */
771 builder = pl->contr->ranged_ob; 864 if (INVOKE_PLAYER (BUILD, pl->contr, ARG_OBJECT (builder),
865 ARG_MAP (pl->map), ARG_INT (pos.x), ARG_INT (pos.y), ARG_INT (1)))
866 return;
772 867
773 if (builder->subtype == ST_BD_REMOVE) 868 if (builder->subtype == ST_BD_REMOVE)
774 /* Remover -> call specific function and bail out */ 869 /* Remover -> call specific function and bail out */
775 { 870 {
776 apply_builder_remove (pl, dir); 871 apply_builder_remove (pl, dir);
797 } 892 }
798 893
799 switch (tmp->subtype) 894 switch (tmp->subtype)
800 { 895 {
801 case ST_MAT_FLOOR: 896 case ST_MAT_FLOOR:
802 apply_builder_floor (pl, tmp, x, y); 897 apply_builder_floor (pl, tmp, pos.x, pos.y);
803 return; 898 return;
804 899
805 case ST_MAT_WALL: 900 case ST_MAT_WALL:
806 apply_builder_wall (pl, tmp, x, y); 901 apply_builder_wall (pl, tmp, pos.x, pos.y);
807 return; 902 return;
808 903
809 case ST_MAT_ITEM: 904 case ST_MAT_ITEM:
810 apply_builder_item (pl, tmp, x, y); 905 apply_builder_item (pl, tmp, pos.x, pos.y);
906 return;
907
908 case ST_MAT_QUAD:
909 apply_builder_quad (pl, tmp, pos);
811 return; 910 return;
812 911
813 default: 912 default:
814 new_draw_info (NDI_UNIQUE, 0, pl, "Don't know how to apply this material, sorry."); 913 new_draw_info (NDI_UNIQUE, 0, pl, "Don't know how to apply this material, sorry.");
815 LOG (llevError, "apply_map_builder: invalid material subtype %d\n", tmp->subtype); 914 LOG (llevError, "apply_map_builder: invalid material subtype %d\n", tmp->subtype);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines