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.60 by root, Wed Apr 14 21:36:32 2010 UTC vs.
Revision 1.72 by root, Sat Sep 16 22:17:42 2017 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,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
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
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 */
338 new_arch = archetype::find (archetype); 324 new_arch = archetype::find (archetype);
339 325
340 if (!new_arch) 326 if (!new_arch)
341 return; 327 return;
342 328
343 /* Now delete current wall, and insert new one 329 /* Now delete current wall, and insert new one
344 * 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
345 */ 331 */
346 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
347 333
348 wall->destroy (); 334 wall->destroy ();
374 char message[MAX_BUF]; 360 char message[MAX_BUF];
375 361
376 sprintf (message, "You change the floor to better suit your tastes."); 362 sprintf (message, "You change the floor to better suit your tastes.");
377 363
378 /* 364 /*
379 * Now the building part... 365 * Now the building part...
380 * First, remove wall(s) and floor(s) at position x, y 366 * First, remove wall(s) and floor(s) at position x, y
381 */ 367 */
382 above_floor = NULL; 368 above_floor = NULL;
383 new_wall = NULL; 369 new_wall = NULL;
384 floor_removed = 0; 370 floor_removed = 0;
434 * 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
435 * Since building, you can have: blocking view / floor / wall / nothing 421 * Since building, you can have: blocking view / floor / wall / nothing
436 */ 422 */
437 for (i = 1; i <= 8; i++) 423 for (i = 1; i <= 8; i++)
438 { 424 {
439 xt = x + freearr_x[i]; 425 xt = x + DIRX (i);
440 yt = y + freearr_y[i]; 426 yt = y + DIRY (i);
441 tmp = GET_MAP_OB (pl->map, xt, yt); 427 tmp = GET_MAP_OB (pl->map, xt, yt);
442 if (!tmp) 428 if (!tmp)
443 { 429 {
444 /* Must insert floor & wall */ 430 /* Must insert floor & wall */
445 tmp = new_floor->instance (); 431 tmp = new_floor->instance ();
661apply_builder_remove (object *pl, int dir) 647apply_builder_remove (object *pl, int dir)
662{ 648{
663 object *item; 649 object *item;
664 int x, y; 650 int x, y;
665 651
666 x = pl->x + freearr_x[dir]; 652 x = pl->x + DIRX (dir);
667 y = pl->y + freearr_y[dir]; 653 y = pl->y + DIRY (dir);
668 654
669 /* Check square */ 655 /* Check square */
670 item = GET_MAP_OB (pl->map, x, y); 656 item = GET_MAP_OB (pl->map, x, y);
671 if (!item) 657 if (!item)
672 { 658 {
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 */
695static void
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 ("You can't build there, there is a block in the way.");
708 return;
709 }
710
711 if (IS_FLOOR (tmp))
712 {
713 floor = tmp;
714 floor_exists = true;
715
716 if (floor->arch->archname == shstr_quad_open_space)
717 open_space = floor;
718 else if (!floor->flag [FLAG_IS_QUAD])
719 {
720 pl->failmsg ("You can't build there, the floor is not suited.");
721 return;
722 }
723 }
724
725 tmp = tmp->above;
726 }
727
728 if (open_space)
729 {
730 if (!material->slaying)
731 {
732 pl->failmsg (
733 "The floor is open and you can't fill it with that material."
734 "H<Use another material to fill the ceiling.>"
735 );
736 return;
737 }
738
739 replace_open_space_floor (open_space, material);
740 pl->contr->fire_on = 0; // TODO: stopgap, do not add more than one per keypress
741 return;
742 }
743 else if (floor)
744 {
745
746 maptile *upper_floor = pos.m->tile_available (TILE_UP);
747 if (!upper_floor)
748 {
749 pl->failmsg ("Whoops, you can't see the ceiling.. H<You may try again.>");
750 return;
751 }
752
753 mapxy above_pos (upper_floor, pos.x, pos.y);
754 if (!above_pos.normalise ())
755 {
756 pl->failmsg ("Whoops, you can't access the ceiling. H<You may try again.>");
757 return;
758 }
759
760 mapspace &above_ms = above_pos.ms ();
761 for (object *quad_obj = above_ms.top; quad_obj; quad_obj = quad_obj->below)
762 {
763 if (quad_obj->arch->archname == shstr_quad_open_space)
764 {
765 if (!material->slaying)
766 {
767 pl->failmsg ("The ceiling is open and you can't fill it with that material."
768 "H<Use another material to fill the ceiling.>");
769 return;
770 }
771
772 replace_open_space_floor (quad_obj, material);
773 break;
774 }
775 }
776
777 if (material->destroyed ())
778 {
779 pl->failmsg ("You don't have enough build material to build a wall here.");
780 return;
781 }
782
783 object *quad_wall = material->other_arch->instance ();
784 material->decrease ();
785
786 insert_ob_in_map_at (quad_wall, floor->map, 0,
787 INS_ABOVE_FLOOR_ONLY, floor->x, floor->y);
788 }
789 else
790 pl->failmsg ("You can't build a quad block here.");
791}
792
695/** 793/**
696 * Global building function 794 * Global building function
697 * 795 *
698 * This is the general map building function. Called when the player 'fires' a builder 796 * This is the general map building function. Called when the player 'fires' a builder
699 * or remover object. 797 * or remover object.
700 */ 798 */
701void 799void
702apply_map_builder (object *pl, int dir) 800apply_map_builder (object *pl, int dir)
703{ 801{
704 int x, y;
705
706 if (!pl->type == PLAYER) 802 if (!pl->type == PLAYER)
707 return; 803 return;
708 804
709 /*if ( !player->map->unique )
710 {
711 new_draw_info( NDI_UNIQUE, 0, player, "You can't build outside a unique map." );
712 return;
713 } */
714
715 if (dir == 0) 805 if (dir == 0)
716 { 806 {
717 new_draw_info (NDI_UNIQUE, 0, pl, "You can't build or destroy under yourself."); 807 new_draw_info (NDI_UNIQUE, 0, pl, "You can't build or destroy under yourself.");
718 return; 808 return;
719 } 809 }
720 810
721 x = pl->x + freearr_x[dir]; 811 mapxy pos (pl); pos.move (dir);
722 y = pl->y + freearr_y[dir];
723 812
724 if ((1 > x) || (1 > y) || ((pl->map->width - 2) < x) || ((pl->map->height - 2) < y)) 813 if (!pos.normalise ())
725 { 814 {
726 new_draw_info (NDI_UNIQUE, 0, pl, "Can't build on map edge..."); 815 pl->failmsg ("You can't build here. H<There is nothing in this direction.>");
727 return; 816 return;
728 } 817 }
729 818
730 /* 819 /*
731 * Check specified square 820 * Check specified square
732 * The square must have only buildable items 821 * The square must have only buildable items
733 * Exception: marking runes are all right, 822 * Exception: marking runes are all right,
734 * since they are used for special things like connecting doors / buttons 823 * since they are used for special things like connecting doors / buttons
735 */ 824 */
736 825
737 object *tmp = GET_MAP_OB (pl->map, x, y);
738 if (!tmp)
739 {
740 /* Nothing, meaning player is standing next to an undefined square... */
741 LOG (llevError, "apply_map_builder: undefined square at (%d, %d, %s)\n", x, y, &pl->map->path);
742 new_draw_info (NDI_UNIQUE, 0, pl, "You'd better not build here, it looks weird.");
743 return;
744 }
745
746 object *builder = pl->contr->ranged_ob; 826 object *builder = pl->contr->ranged_ob;
747 827
748 object *tmp2 = pl->mark (); 828 object *tmp2 = pl->mark ();
749 829
750 while (tmp) 830 object *tmp = 0;
831 for (tmp = pos.ms ().bot; tmp; tmp = tmp->above)
751 { 832 {
833 if (!tmp->flag [FLAG_IS_BUILDABLE]
752 if (!tmp->flag [FLAG_IS_BUILDABLE] && (tmp->type != SIGN || tmp->arch->archname != shstr_rune_mark)) 834 && (tmp->type != SIGN || tmp->arch->archname != shstr_rune_mark))
753 { 835 {
754 /* The item building function already has it's own special 836 /* The item building function already has it's own special
755 * checks for this 837 * checks for this. And so does the quad building function.
756 */ 838 */
757 if (!tmp2 || tmp2->subtype != ST_MAT_ITEM) 839 if (!tmp2 || (tmp2->subtype != ST_MAT_ITEM && tmp2->subtype != ST_MAT_QUAD))
758 { 840 {
759 if (!INVOKE_PLAYER (BUILD, pl->contr, ARG_OBJECT (builder), ARG_MAP (pl->map), ARG_INT (x), ARG_INT (y), ARG_INT (0))) 841 if (!INVOKE_PLAYER (BUILD, pl->contr, ARG_OBJECT (builder),
842 ARG_MAP (pl->map),
843 ARG_INT (pos.y), ARG_INT (pos.y),
844 ARG_INT (0)))
760 new_draw_info (NDI_UNIQUE, 0, pl, "You can't build here."); 845 new_draw_info (NDI_UNIQUE, 0, pl, "You can't build here.");
761 846
762 return; 847 return;
763 } 848 }
764 } 849 }
765
766 tmp = tmp->above;
767 } 850 }
768 851
769 /* Now we know the square is ok */ 852 /* Now we know the square is ok */
770 if (INVOKE_PLAYER (BUILD, pl->contr, ARG_OBJECT (builder), ARG_MAP (pl->map), ARG_INT (x), ARG_INT (y), ARG_INT (1))) 853 if (INVOKE_PLAYER (BUILD, pl->contr, ARG_OBJECT (builder),
854 ARG_MAP (pl->map), ARG_INT (pos.x), ARG_INT (pos.y), ARG_INT (1)))
771 return; 855 return;
772 856
773 if (builder->subtype == ST_BD_REMOVE) 857 if (builder->subtype == ST_BD_REMOVE)
774 /* Remover -> call specific function and bail out */ 858 /* Remover -> call specific function and bail out */
775 { 859 {
797 } 881 }
798 882
799 switch (tmp->subtype) 883 switch (tmp->subtype)
800 { 884 {
801 case ST_MAT_FLOOR: 885 case ST_MAT_FLOOR:
802 apply_builder_floor (pl, tmp, x, y); 886 apply_builder_floor (pl, tmp, pos.x, pos.y);
803 return; 887 return;
804 888
805 case ST_MAT_WALL: 889 case ST_MAT_WALL:
806 apply_builder_wall (pl, tmp, x, y); 890 apply_builder_wall (pl, tmp, pos.x, pos.y);
807 return; 891 return;
808 892
809 case ST_MAT_ITEM: 893 case ST_MAT_ITEM:
810 apply_builder_item (pl, tmp, x, y); 894 apply_builder_item (pl, tmp, pos.x, pos.y);
895 return;
896
897 case ST_MAT_QUAD:
898 apply_builder_quad (pl, tmp, pos);
811 return; 899 return;
812 900
813 default: 901 default:
814 new_draw_info (NDI_UNIQUE, 0, pl, "Don't know how to apply this material, sorry."); 902 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); 903 LOG (llevError, "apply_map_builder: invalid material subtype %d\n", tmp->subtype);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines