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.20 by root, Sat Dec 30 10:16:11 2006 UTC vs.
Revision 1.34 by root, Mon Sep 29 10:20:49 2008 UTC

1/* 1/*
2 CrossFire, A Multiplayer game for X-windows 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 3 *
4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
4 Copyright (C) 2001 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2001,2007 Mark Wedel & Crossfire Development Team
5 Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
6 7 *
7 This program is free software; you can redistribute it and/or modify 8 * Deliantra is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version. 11 * (at your option) any later version.
11 12 *
12 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,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details. 16 * GNU General Public License for more details.
16 17 *
17 You should have received a copy of the GNU General Public License 18 * You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software 19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 *
20 21 * The authors can be reached via e-mail to <support@deliantra.net>
21 The authors can be reached via e-mail to <crossfire@schmorp.de>
22*/ 22 */
23 23
24#include <global.h> 24#include <global.h>
25#include <living.h> 25#include <living.h>
26#include <spells.h> 26#include <spells.h>
27#include <skills.h> 27#include <skills.h>
38 38
39 ob = GET_MAP_OB (map, x, y); 39 ob = GET_MAP_OB (map, x, y);
40 while (ob) 40 while (ob)
41 { 41 {
42 /* if ob is not a marking rune or floor, then check special cases */ 42 /* if ob is not a marking rune or floor, then check special cases */
43 if (strcmp (ob->arch->name, "rune_mark") && ob->type != FLOOR) 43 if (strcmp (ob->arch->archname, "rune_mark") && ob->type != FLOOR)
44 { 44 {
45 switch (tmp->type) 45 switch (tmp->type)
46 { 46 {
47 case SIGN: 47 case SIGN:
48 case MAGIC_EAR: 48 case MAGIC_EAR:
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
88 if ((rune->type == SIGN) && (!strcmp (rune->arch->name, "rune_mark"))) 88 if (rune->type == SIGN && !strcmp (rune->arch->archname, "rune_mark"))
89 rune->destroy (); 89 rune->destroy (true);
90 90
91 rune = next; 91 rune = next;
92 } 92 }
93} 93}
94 94
106 int itest = 0; 106 int itest = 0;
107 oblinkpt *obp; 107 oblinkpt *obp;
108 108
109 while (itest++ < 1000) 109 while (itest++ < 1000)
110 { 110 {
111 connected = 1 + rand () % 20000; 111 connected = rndm (0x20000000UL) + 0x60000000UL;
112
112 for (obp = map->buttons; obp && (obp->value != connected); obp = obp->next); 113 for (obp = map->buttons; obp && (obp->value != connected); obp = obp->next)
114 ;
113 115
114 if (!obp) 116 if (!obp)
115 return connected; 117 return connected;
116 } 118 }
117 119
118 return -1; 120 return -1;
119} 121}
120
121 122
122/** 123/**
123 * Helper function for door/button/connected item building. 124 * Helper function for door/button/connected item building.
124 * 125 *
125 * Will search the specified spot for a marking rune. 126 * Will search the specified spot for a marking rune.
145 } 146 }
146 147
147 /* Now, find force in player's inventory */ 148 /* Now, find force in player's inventory */
148 force = pl->inv; 149 force = pl->inv;
149 while (force 150 while (force
150 && ((force->type != FORCE) || (!force->slaying) || (strcmp (force->slaying, pl->map->path)) || (!force->msg) 151 && ((force->type != FORCE) || !force->slaying || force->slaying != pl->map->path || !force->msg
151 || (strcmp (force->msg, rune->msg)))) 152 || force->msg != rune->msg))
152 force = force->below; 153 force = force->below;
153 154
154 if (!force) 155 if (!force)
155 /* No force, need to create & insert one */ 156 /* No force, need to create & insert one */
156 { 157 {
180 * Returns the marking rune on the square, for purposes of building connections 181 * Returns the marking rune on the square, for purposes of building connections
181 */ 182 */
182object * 183object *
183get_connection_rune (object *pl, short x, short y) 184get_connection_rune (object *pl, short x, short y)
184{ 185{
185 object *rune;
186
187 rune = GET_MAP_OB (pl->map, x, y); 186 object *rune = GET_MAP_OB (pl->map, x, y);
187
188 while (rune && ((rune->type != SIGN) || (strcmp (rune->arch->name, "rune_mark")))) 188 while (rune && ((rune->type != SIGN) || (strcmp (rune->arch->archname, "rune_mark"))))
189 rune = rune->above; 189 rune = rune->above;
190
190 return rune; 191 return rune;
191} 192}
192 193
193/** 194/**
194 * Returns the book/scroll on the current square, for purposes of building 195 * Returns the book/scroll on the current square, for purposes of building
195 */ 196 */
196object * 197object *
197get_msg_book (object *pl, short x, short y) 198get_msg_book (object *pl, short x, short y)
198{ 199{
199 object *book;
200
201 book = GET_MAP_OB (pl->map, x, y); 200 object *book = GET_MAP_OB (pl->map, x, y);
201
202 while (book && (book->type != BOOK)) 202 while (book && (book->type != BOOK))
203 book = book->above; 203 book = book->above;
204
204 return book; 205 return book;
205} 206}
206 207
207/** 208/**
208 * Returns first item of type BUILDABLE_WALL. 209 * Returns first item of type BUILDABLE_WALL.
209 */ 210 */
210object * 211object *
211get_wall (maptile *map, int x, int y) 212get_wall (maptile *map, int x, int y)
212{ 213{
213 object *wall;
214
215 wall = GET_MAP_OB (map, x, y); 214 object *wall = GET_MAP_OB (map, x, y);
215
216 while (wall && (BUILDABLE_WALL != wall->type)) 216 while (wall && (BUILDABLE_WALL != wall->type))
217 wall = wall->above; 217 wall = wall->above;
218 218
219 return wall; 219 return wall;
220} 220}
231 * Note: x & y must be valid map coordinates. 231 * Note: x & y must be valid map coordinates.
232 */ 232 */
233void 233void
234fix_walls (maptile *map, int x, int y) 234fix_walls (maptile *map, int x, int y)
235{ 235{
236 object *wall;
237 char archetype[MAX_BUF]; 236 char archetype[MAX_BUF];
238 char *underscore; 237 char *underscore;
239 struct archetype *new_arch; 238 struct archetype *new_arch;
240 239
241
242 /* First, find the wall on that spot */ 240 /* First, find the wall on that spot */
243 wall = get_wall (map, x, y); 241 object *wall = get_wall (map, x, y);
244 if (!wall) 242 if (!wall)
245 /* Nothing -> bail out */ 243 /* Nothing -> bail out */
246 return; 244 return;
247 245
248 /* Find base name */ 246 /* Find base name */
249 strcpy (archetype, wall->arch->name); 247 assign (archetype, wall->arch->archname);
250 underscore = strchr (archetype, '_'); 248 underscore = strchr (archetype, '_');
251 249
252 /* search for the first _ before a number */ 250 /* search for the first _ before a number */
253 while (underscore && !isdigit (*(underscore + 1))) 251 while (underscore && !isdigit (*(underscore + 1)))
254 underscore = strchr (underscore + 1, '_'); 252 underscore = strchr (underscore + 1, '_');
353 /* Now delete current wall, and insert new one 351 /* Now delete current wall, and insert new one
354 * We save flags to avoid any trouble with buildable/non buildable, and so on 352 * We save flags to avoid any trouble with buildable/non buildable, and so on
355 */ 353 */
356 object::flags_t old_flags = wall->flag; // elmex: this is where C++ pays off 354 object::flags_t old_flags = wall->flag; // elmex: this is where C++ pays off
357 355
358 wall->destroy (); 356 wall->destroy (true);
359 357
360 wall = arch_to_object (new_arch); 358 wall = arch_to_object (new_arch);
361 wall->type = BUILDABLE_WALL; 359 wall->type = BUILDABLE_WALL;
362 insert_ob_in_map_at (wall, map, NULL, INS_ABOVE_FLOOR_ONLY, x, y); 360 insert_ob_in_map_at (wall, map, NULL, INS_ABOVE_FLOOR_ONLY, x, y);
363 wall->flag = old_flags; 361 wall->flag = old_flags;
400 above = tmp->above; 398 above = tmp->above;
401 if (BUILDABLE_WALL == tmp->type) 399 if (BUILDABLE_WALL == tmp->type)
402 { 400 {
403 /* There was a wall, remove it & keep its archetype to make new walls */ 401 /* There was a wall, remove it & keep its archetype to make new walls */
404 new_wall = tmp->arch; 402 new_wall = tmp->arch;
405 tmp->destroy (); 403 tmp->destroy (true);
406 sprintf (message, "You destroy the wall and redo the floor."); 404 sprintf (message, "You destroy the wall and redo the floor.");
407 } 405 }
408 else if ((FLOOR == tmp->type) || (QUERY_FLAG (tmp, FLAG_IS_FLOOR))) 406 else if ((FLOOR == tmp->type) || (QUERY_FLAG (tmp, FLAG_IS_FLOOR)))
409 { 407 {
410 tmp->destroy (); 408 tmp->destroy (true);
411 floor_removed = 1; 409 floor_removed = 1;
412 } 410 }
413 else 411 else
414 { 412 {
415 if (floor_removed) 413 if (floor_removed)
475 if (!OUT_OF_REAL_MAP (pl->map, xt, yt)) 473 if (!OUT_OF_REAL_MAP (pl->map, xt, yt))
476 fix_walls (pl->map, xt, yt); 474 fix_walls (pl->map, xt, yt);
477 } 475 }
478 476
479 /* Now remove raw item from inventory */ 477 /* Now remove raw item from inventory */
480 decrease_ob (material); 478 material->decrease ();
481 479
482 /* And tell player about the fix */ 480 /* And tell player about the fix */
483 new_draw_info (NDI_UNIQUE, 0, pl, message); 481 new_draw_info (NDI_UNIQUE, 0, pl, message);
484} 482}
485 483
544 insert_ob_in_map_at (tmp, pl->map, 0, INS_ABOVE_FLOOR_ONLY, x, y); 542 insert_ob_in_map_at (tmp, pl->map, 0, INS_ABOVE_FLOOR_ONLY, x, y);
545 543
546 /* If existing wall, remove it, no need to fix other walls */ 544 /* If existing wall, remove it, no need to fix other walls */
547 if (current_wall) 545 if (current_wall)
548 { 546 {
549 current_wall->destroy (); 547 current_wall->destroy (true);
550 fix_walls (pl->map, x, y); 548 fix_walls (pl->map, x, y);
551 sprintf (message, "You redecorate the wall to better suit your tastes."); 549 sprintf (message, "You redecorate the wall to better suit your tastes.");
552 } 550 }
553 else 551 else
554 { 552 {
562 fix_walls (pl->map, xt, yt); 560 fix_walls (pl->map, xt, yt);
563 } 561 }
564 } 562 }
565 563
566 /* Now remove item from inventory */ 564 /* Now remove item from inventory */
567 decrease_ob (material); 565 material->decrease ();
568 566
569 /* And tell player what happened */ 567 /* And tell player what happened */
570 new_draw_info (NDI_UNIQUE, 0, pl, message); 568 new_draw_info (NDI_UNIQUE, 0, pl, message);
571} 569}
572 570
609 if (!arch) 607 if (!arch)
610 return; 608 return;
611 609
612 tmp = arch_to_object (arch); 610 tmp = arch_to_object (arch);
613 611
614 if ((floor->above) && (!can_build_over (pl->map, tmp, x, y))) 612 if (!floor->flag[FLAG_IS_BUILDABLE] || (floor->above) && (!can_build_over (pl->map, tmp, x, y)))
615 /* Floor has something on top that interferes with building */ 613 /* Floor has something on top that interferes with building */
616 { 614 {
617 new_draw_info (NDI_UNIQUE, 0, pl, "You can't build here."); 615 new_draw_info (NDI_UNIQUE, 0, pl, "You can't build here.");
618 return; 616 return;
619 } 617 }
638 case PEDESTAL: 636 case PEDESTAL:
639 case CF_HANDLE: 637 case CF_HANDLE:
640 case MAGIC_EAR: 638 case MAGIC_EAR:
641 case SIGN: 639 case SIGN:
642 /* Signs don't need a connection, but but magic mouths do. */ 640 /* Signs don't need a connection, but but magic mouths do. */
643 if (tmp->type == SIGN && strcmp (tmp->arch->name, "magic_mouth")) 641 if (tmp->type == SIGN && strcmp (tmp->arch->archname, "magic_mouth"))
644 break; 642 break;
643
645 con_rune = get_connection_rune (pl, x, y); 644 con_rune = get_connection_rune (pl, x, y);
646 connected = find_or_create_connection_for_map (pl, x, y, con_rune); 645 connected = find_or_create_connection_for_map (pl, x, y, con_rune);
647 if (connected == -1) 646 if (connected == -1)
648 { 647 {
649 /* Player already informed of failure by the previous function */ 648 /* Player already informed of failure by the previous function */
650 tmp->destroy (); 649 tmp->destroy (true);
651 return; 650 return;
652 } 651 }
652
653 /* Remove marking rune */ 653 /* Remove marking rune */
654 con_rune->destroy (); 654 con_rune->destroy (true);
655 } 655 }
656 656
657 /* 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 */
658 if ((tmp->type == SIGN) || (tmp->type == MAGIC_EAR)) 658 if ((tmp->type == SIGN) || (tmp->type == MAGIC_EAR))
659 { 659 {
660 if (adjust_sign_msg (pl, x, y, tmp) == -1) 660 if (adjust_sign_msg (pl, x, y, tmp) == -1)
661 { 661 {
662 tmp->destroy (); 662 tmp->destroy (true);
663 return; 663 return;
664 } 664 }
665 } 665 }
666 666
667 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);
668 if (connected != 0) 668 if (connected != 0)
669 add_button_link (tmp, pl->map, connected); 669 add_button_link (tmp, pl->map, connected);
670 670
671 new_draw_info_format (NDI_UNIQUE, 0, pl, "You build the %s", query_name (tmp)); 671 new_draw_info_format (NDI_UNIQUE, 0, pl, "You build the %s", query_name (tmp));
672 decrease_ob_nr (item, 1); 672 item->decrease ();
673} 673}
674 674
675/** 675/**
676 * Item remover. 676 * Item remover.
677 * 677 *
706 else if (!item->flag [FLAG_IS_BUILDABLE]) 706 else if (!item->flag [FLAG_IS_BUILDABLE])
707 new_draw_info_format (NDI_UNIQUE, 0, pl, "You can't remove the %s, it's not buildable!", query_name (item)); 707 new_draw_info_format (NDI_UNIQUE, 0, pl, "You can't remove the %s, it's not buildable!", query_name (item));
708 else 708 else
709 { 709 {
710 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));
711 item->destroy (); 711 item->destroy (true);
712 } 712 }
713} 713}
714 714
715/** 715/**
716 * Global building function 716 * Global building function
763 /* Nothing, meaning player is standing next to an undefined square... */ 763 /* Nothing, meaning player is standing next to an undefined square... */
764 LOG (llevError, "apply_map_builder: undefined square at (%d, %d, %s)\n", x, y, &pl->map->path); 764 LOG (llevError, "apply_map_builder: undefined square at (%d, %d, %s)\n", x, y, &pl->map->path);
765 new_draw_info (NDI_UNIQUE, 0, pl, "You'd better not build here, it looks weird."); 765 new_draw_info (NDI_UNIQUE, 0, pl, "You'd better not build here, it looks weird.");
766 return; 766 return;
767 } 767 }
768
768 tmp2 = find_marked_object (pl); 769 tmp2 = find_marked_object (pl);
769 while (tmp) 770 while (tmp)
770 { 771 {
771 if (!QUERY_FLAG (tmp, FLAG_IS_BUILDABLE) && ((tmp->type != SIGN) || (strcmp (tmp->arch->name, "rune_mark")))) 772 if (!QUERY_FLAG (tmp, FLAG_IS_BUILDABLE) && ((tmp->type != SIGN) || (strcmp (tmp->arch->archname, "rune_mark"))))
772 { 773 {
773 /* The item building function already has it's own special 774 /* The item building function already has it's own special
774 * checks for this 775 * checks for this
775 */ 776 */
776 if ((!tmp2) || (tmp2->subtype != ST_MAT_ITEM)) 777 if ((!tmp2) || (tmp2->subtype != ST_MAT_ITEM))
781 } 782 }
782 tmp = tmp->above; 783 tmp = tmp->above;
783 } 784 }
784 785
785 /* Now we know the square is ok */ 786 /* Now we know the square is ok */
786 builder = pl->contr->ranges[range_builder]; 787 builder = pl->contr->ranged_ob;
787 788
788 if (builder->subtype == ST_BD_REMOVE) 789 if (builder->subtype == ST_BD_REMOVE)
789 /* Remover -> call specific function and bail out */ 790 /* Remover -> call specific function and bail out */
790 { 791 {
791 apply_builder_remove (pl, dir); 792 apply_builder_remove (pl, dir);
859 tmp->msg = book->msg; 860 tmp->msg = book->msg;
860 861
861 if (tmp->invisible) 862 if (tmp->invisible)
862 { 863 {
863 if (book->custom_name != NULL) 864 if (book->custom_name != NULL)
864 {
865 snprintf (buf, sizeof (buf), "talking %s", &book->custom_name); 865 snprintf (buf, sizeof (buf), "talking %s", &book->custom_name);
866 }
867 else 866 else
868 {
869 snprintf (buf, sizeof (buf), "talking %s", &book->name); 867 snprintf (buf, sizeof (buf), "talking %s", &book->name);
870 } 868
871 tmp->name = buf; 869 tmp->name = buf;
872 870
873 if (book->name_pl != NULL) 871 if (book->name_pl != NULL)
874 { 872 {
875 snprintf (buf2, sizeof (buf2), "talking %s", &book->name_pl); 873 snprintf (buf2, sizeof (buf2), "talking %s", &book->name_pl);
878 876
879 tmp->face = book->face; 877 tmp->face = book->face;
880 tmp->invisible = 0; 878 tmp->invisible = 0;
881 } 879 }
882 880
883 book->destroy (); 881 book->destroy (true);
884 return 0; 882 return 0;
885} 883}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines