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.24 by root, Mon Feb 5 02:07:40 2007 UTC vs.
Revision 1.36 by root, Thu Jan 1 11:41:17 2009 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 (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team 4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (C) 2001 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2001,2007 Mark Wedel & Crossfire Development Team
6 * Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
7 * 7 *
8 * This program is free software; you can redistribute it and/or modify 8 * Deliantra is free software: you can redistribute it and/or modify
9 * 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
10 * the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version. 11 * (at your 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 GNU General Public License 18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software 19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * 20 *
22 * The authors can be reached via e-mail to <crossfire@schmorp.de> 21 * The authors can be reached via e-mail to <support@deliantra.net>
23 */ 22 */
24 23
25#include <global.h> 24#include <global.h>
26#include <living.h> 25#include <living.h>
27#include <spells.h> 26#include <spells.h>
39 38
40 ob = GET_MAP_OB (map, x, y); 39 ob = GET_MAP_OB (map, x, y);
41 while (ob) 40 while (ob)
42 { 41 {
43 /* 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 */
44 if (strcmp (ob->arch->name, "rune_mark") && ob->type != FLOOR) 43 if (ob->arch->archname != shstr_rune_mark && ob->type != FLOOR)
45 { 44 {
46 switch (tmp->type) 45 switch (tmp->type)
47 { 46 {
48 case SIGN: 47 case SIGN:
49 case MAGIC_EAR: 48 case MAGIC_EAR:
84 rune = GET_MAP_OB (map, x, y); 83 rune = GET_MAP_OB (map, x, y);
85 while (rune) 84 while (rune)
86 { 85 {
87 next = rune->above; 86 next = rune->above;
88 87
89 if ((rune->type == SIGN) && (!strcmp (rune->arch->name, "rune_mark"))) 88 if (rune->type == SIGN && rune->arch->archname == shstr_rune_mark)
90 rune->destroy (); 89 rune->destroy ();
91 90
92 rune = next; 91 rune = next;
93 } 92 }
94} 93}
107 int itest = 0; 106 int itest = 0;
108 oblinkpt *obp; 107 oblinkpt *obp;
109 108
110 while (itest++ < 1000) 109 while (itest++ < 1000)
111 { 110 {
112 connected = 1 + rand () % 20000; 111 connected = rndm (0x20000000UL) + 0x60000000UL;
112
113 for (obp = map->buttons; obp && (obp->value != connected); obp = obp->next); 113 for (obp = map->buttons; obp && (obp->value != connected); obp = obp->next)
114 ;
114 115
115 if (!obp) 116 if (!obp)
116 return connected; 117 return connected;
117 } 118 }
118 119
119 return -1; 120 return -1;
120} 121}
121
122 122
123/** 123/**
124 * Helper function for door/button/connected item building. 124 * Helper function for door/button/connected item building.
125 * 125 *
126 * Will search the specified spot for a marking rune. 126 * Will search the specified spot for a marking rune.
181 * 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
182 */ 182 */
183object * 183object *
184get_connection_rune (object *pl, short x, short y) 184get_connection_rune (object *pl, short x, short y)
185{ 185{
186 object *rune;
187
188 rune = GET_MAP_OB (pl->map, x, y); 186 object *rune = GET_MAP_OB (pl->map, x, y);
187
189 while (rune && ((rune->type != SIGN) || (strcmp (rune->arch->name, "rune_mark")))) 188 while (rune && (rune->type != SIGN || rune->arch->archname != shstr_rune_mark))
190 rune = rune->above; 189 rune = rune->above;
190
191 return rune; 191 return rune;
192} 192}
193 193
194/** 194/**
195 * 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
196 */ 196 */
197object * 197object *
198get_msg_book (object *pl, short x, short y) 198get_msg_book (object *pl, short x, short y)
199{ 199{
200 object *book;
201
202 book = GET_MAP_OB (pl->map, x, y); 200 object *book = GET_MAP_OB (pl->map, x, y);
201
203 while (book && (book->type != BOOK)) 202 while (book && (book->type != BOOK))
204 book = book->above; 203 book = book->above;
204
205 return book; 205 return book;
206} 206}
207 207
208/** 208/**
209 * Returns first item of type BUILDABLE_WALL. 209 * Returns first item of type BUILDABLE_WALL.
210 */ 210 */
211object * 211object *
212get_wall (maptile *map, int x, int y) 212get_wall (maptile *map, int x, int y)
213{ 213{
214 object *wall;
215
216 wall = GET_MAP_OB (map, x, y); 214 object *wall = GET_MAP_OB (map, x, y);
215
217 while (wall && (BUILDABLE_WALL != wall->type)) 216 while (wall && (BUILDABLE_WALL != wall->type))
218 wall = wall->above; 217 wall = wall->above;
219 218
220 return wall; 219 return wall;
221} 220}
232 * Note: x & y must be valid map coordinates. 231 * Note: x & y must be valid map coordinates.
233 */ 232 */
234void 233void
235fix_walls (maptile *map, int x, int y) 234fix_walls (maptile *map, int x, int y)
236{ 235{
237 object *wall;
238 char archetype[MAX_BUF]; 236 char archetype[MAX_BUF];
239 char *underscore; 237 char *underscore;
240 struct archetype *new_arch; 238 struct archetype *new_arch;
241 239
242
243 /* First, find the wall on that spot */ 240 /* First, find the wall on that spot */
244 wall = get_wall (map, x, y); 241 object *wall = get_wall (map, x, y);
245 if (!wall) 242 if (!wall)
246 /* Nothing -> bail out */ 243 /* Nothing -> bail out */
247 return; 244 return;
248 245
249 /* Find base name */ 246 /* Find base name */
250 assign (archetype, wall->arch->name); 247 assign (archetype, wall->arch->archname);
251 underscore = strchr (archetype, '_'); 248 underscore = strchr (archetype, '_');
252 249
253 /* search for the first _ before a number */ 250 /* search for the first _ before a number */
254 while (underscore && !isdigit (*(underscore + 1))) 251 while (underscore && !isdigit (*(underscore + 1)))
255 underscore = strchr (underscore + 1, '_'); 252 underscore = strchr (underscore + 1, '_');
476 if (!OUT_OF_REAL_MAP (pl->map, xt, yt)) 473 if (!OUT_OF_REAL_MAP (pl->map, xt, yt))
477 fix_walls (pl->map, xt, yt); 474 fix_walls (pl->map, xt, yt);
478 } 475 }
479 476
480 /* Now remove raw item from inventory */ 477 /* Now remove raw item from inventory */
481 decrease_ob (material); 478 material->decrease ();
482 479
483 /* And tell player about the fix */ 480 /* And tell player about the fix */
484 new_draw_info (NDI_UNIQUE, 0, pl, message); 481 new_draw_info (NDI_UNIQUE, 0, pl, message);
485} 482}
486 483
563 fix_walls (pl->map, xt, yt); 560 fix_walls (pl->map, xt, yt);
564 } 561 }
565 } 562 }
566 563
567 /* Now remove item from inventory */ 564 /* Now remove item from inventory */
568 decrease_ob (material); 565 material->decrease ();
569 566
570 /* And tell player what happened */ 567 /* And tell player what happened */
571 new_draw_info (NDI_UNIQUE, 0, pl, message); 568 new_draw_info (NDI_UNIQUE, 0, pl, message);
572} 569}
573 570
610 if (!arch) 607 if (!arch)
611 return; 608 return;
612 609
613 tmp = arch_to_object (arch); 610 tmp = arch_to_object (arch);
614 611
615 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)))
616 /* Floor has something on top that interferes with building */ 613 /* Floor has something on top that interferes with building */
617 { 614 {
618 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.");
619 return; 616 return;
620 } 617 }
629 insert_flag = INS_ABOVE_FLOOR_ONLY; 626 insert_flag = INS_ABOVE_FLOOR_ONLY;
630 627
631 connected = 0; 628 connected = 0;
632 switch (tmp->type) 629 switch (tmp->type)
633 { 630 {
634 case DOOR: 631 case DOOR:
635 case GATE: 632 case GATE:
636 case BUTTON: 633 case BUTTON:
637 case DETECTOR: 634 case DETECTOR:
638 case TIMED_GATE: 635 case TIMED_GATE:
639 case PEDESTAL: 636 case PEDESTAL:
640 case CF_HANDLE: 637 case CF_HANDLE:
641 case MAGIC_EAR: 638 case MAGIC_EAR:
642 case SIGN: 639 case SIGN:
643 /* Signs don't need a connection, but but magic mouths do. */ 640 /* Signs don't need a connection, but but magic mouths do. */
644 if (tmp->type == SIGN && strcmp (tmp->arch->name, "magic_mouth")) 641 if (tmp->type == SIGN && tmp->arch->archname != shstr_magic_mouth)
645 break; 642 break;
643
646 con_rune = get_connection_rune (pl, x, y); 644 con_rune = get_connection_rune (pl, x, y);
647 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);
648 if (connected == -1) 646 if (connected == -1)
649 { 647 {
650 /* Player already informed of failure by the previous function */ 648 /* Player already informed of failure by the previous function */
651 tmp->destroy (); 649 tmp->destroy ();
652 return; 650 return;
653 } 651 }
652
654 /* Remove marking rune */ 653 /* Remove marking rune */
655 con_rune->destroy (); 654 con_rune->destroy ();
656 } 655 }
657 656
658 /* 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 */
659 if ((tmp->type == SIGN) || (tmp->type == MAGIC_EAR)) 658 if ((tmp->type == SIGN) || (tmp->type == MAGIC_EAR))
660 { 659 {
668 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);
669 if (connected != 0) 668 if (connected != 0)
670 add_button_link (tmp, pl->map, connected); 669 add_button_link (tmp, pl->map, connected);
671 670
672 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));
673 decrease_ob_nr (item, 1); 672 item->decrease ();
674} 673}
675 674
676/** 675/**
677 * Item remover. 676 * Item remover.
678 * 677 *
764 /* Nothing, meaning player is standing next to an undefined square... */ 763 /* Nothing, meaning player is standing next to an undefined square... */
765 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);
766 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.");
767 return; 766 return;
768 } 767 }
768
769 tmp2 = find_marked_object (pl); 769 tmp2 = find_marked_object (pl);
770 while (tmp) 770 while (tmp)
771 { 771 {
772 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 || tmp->arch->archname != shstr_rune_mark))
773 { 773 {
774 /* The item building function already has it's own special 774 /* The item building function already has it's own special
775 * checks for this 775 * checks for this
776 */ 776 */
777 if ((!tmp2) || (tmp2->subtype != ST_MAT_ITEM)) 777 if ((!tmp2) || (tmp2->subtype != ST_MAT_ITEM))
782 } 782 }
783 tmp = tmp->above; 783 tmp = tmp->above;
784 } 784 }
785 785
786 /* Now we know the square is ok */ 786 /* Now we know the square is ok */
787 builder = pl->contr->ranges[range_builder]; 787 builder = pl->contr->ranged_ob;
788 788
789 if (builder->subtype == ST_BD_REMOVE) 789 if (builder->subtype == ST_BD_REMOVE)
790 /* Remover -> call specific function and bail out */ 790 /* Remover -> call specific function and bail out */
791 { 791 {
792 apply_builder_remove (pl, dir); 792 apply_builder_remove (pl, dir);
860 tmp->msg = book->msg; 860 tmp->msg = book->msg;
861 861
862 if (tmp->invisible) 862 if (tmp->invisible)
863 { 863 {
864 if (book->custom_name != NULL) 864 if (book->custom_name != NULL)
865 {
866 snprintf (buf, sizeof (buf), "talking %s", &book->custom_name); 865 snprintf (buf, sizeof (buf), "talking %s", &book->custom_name);
867 }
868 else 866 else
869 {
870 snprintf (buf, sizeof (buf), "talking %s", &book->name); 867 snprintf (buf, sizeof (buf), "talking %s", &book->name);
871 } 868
872 tmp->name = buf; 869 tmp->name = buf;
873 870
874 if (book->name_pl != NULL) 871 if (book->name_pl != NULL)
875 { 872 {
876 snprintf (buf2, sizeof (buf2), "talking %s", &book->name_pl); 873 snprintf (buf2, sizeof (buf2), "talking %s", &book->name_pl);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines