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.37 by root, Thu Jan 8 03:03:24 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}
98 * \param map: map for which to find a value 97 * \param map: map for which to find a value
99 * \return 'connected' value with no item, or -1 if failure. 98 * \return 'connected' value with no item, or -1 if failure.
100 * 99 *
101 * Tries 1000 random values, then returns -1. 100 * Tries 1000 random values, then returns -1.
102 */ 101 */
103int 102static shstr_tmp
104find_unused_connected_value (maptile *map) 103find_unused_connected_value (maptile *map)
105{ 104{
106 int connected = 0; 105 for (int i = 1000; --i; )
107 int itest = 0;
108 oblinkpt *obp;
109
110 while (itest++ < 1000)
111 {
112 connected = 1 + rand () % 20000;
113 for (obp = map->buttons; obp && (obp->value != connected); obp = obp->next);
114
115 if (!obp)
116 return connected;
117 } 106 {
107 char buf[64];
118 108
119 return -1; 109 snprintf (buf, sizeof (buf), "built-%x", rndm (0xf0000000U) + 0x10000000U);
120}
121 110
111 shstr id (buf);
112
113 if (!map->find_link (id))
114 return id;
115 }
116
117 return shstr_tmp ();
118}
122 119
123/** 120/**
124 * Helper function for door/button/connected item building. 121 * Helper function for door/button/connected item building.
125 * 122 *
126 * Will search the specified spot for a marking rune. 123 * Will search the specified spot for a marking rune.
128 * Else, searches a force in op's inventory matching the map's name 125 * Else, searches a force in op's inventory matching the map's name
129 * and the rune's text. 126 * and the rune's text.
130 * If found, returns the connection value associated 127 * If found, returns the connection value associated
131 * else searches a new connection value, and adds the force to the player. 128 * else searches a new connection value, and adds the force to the player.
132 */ 129 */
133int 130static shstr_tmp
134find_or_create_connection_for_map (object *pl, short x, short y, object *rune) 131find_or_create_connection_for_map (object *pl, short x, short y, object *rune)
135{ 132{
136 object *force; 133 object *force;
137 int connected;
138 134
139 if (!rune) 135 if (!rune)
140 rune = get_connection_rune (pl, x, y); 136 rune = get_connection_rune (pl, x, y);
141 137
142 if (!rune) 138 if (!rune)
143 { 139 {
144 new_draw_info (NDI_UNIQUE, 0, pl, "You need to put a marking rune with the group name."); 140 new_draw_info (NDI_UNIQUE, 0, pl, "You need to put a marking rune with the group name.");
145 return -1; 141 return shstr_tmp ();
146 } 142 }
147 143
148 /* Now, find force in player's inventory */ 144 /* Now, find force in player's inventory */
149 force = pl->inv; 145 force = pl->inv;
150 while (force 146 while (force
154 150
155 if (!force) 151 if (!force)
156 /* No force, need to create & insert one */ 152 /* No force, need to create & insert one */
157 { 153 {
158 /* Find unused value */ 154 /* Find unused value */
159 connected = find_unused_connected_value (pl->map); 155 shstr_tmp id = find_unused_connected_value (pl->map);
160 if (connected == -1) 156
157 if (!id)
161 { 158 {
162 new_draw_info (NDI_UNIQUE, 0, pl, "Could not create more groups."); 159 new_draw_info (NDI_UNIQUE, 0, pl, "Could not create more groups.");
163 return -1; 160 return shstr_tmp ();
164 } 161 }
165 162
166 force = get_archetype (FORCE_NAME); 163 force = get_archetype (FORCE_NAME);
167 force->slaying = pl->map->path; 164 force->slaying = pl->map->path;
168 force->msg = rune->msg; 165 force->msg = rune->msg;
169 force->path_attuned = connected; 166 force->race = id;
170 force->set_speed (0); 167 force->set_speed (0);
168
171 insert_ob_in_ob (force, pl); 169 insert_ob_in_ob (force, pl);
172 170
173 return connected; 171 return id;
174 } 172 }
175 173
176 /* Found the force, everything's easy. */ 174 /* Found the force, everything's easy. */
177 return force->path_attuned; 175 return force->race;
178} 176}
179 177
180/** 178/**
181 * Returns the marking rune on the square, for purposes of building connections 179 * Returns the marking rune on the square, for purposes of building connections
182 */ 180 */
183object * 181object *
184get_connection_rune (object *pl, short x, short y) 182get_connection_rune (object *pl, short x, short y)
185{ 183{
186 object *rune;
187
188 rune = GET_MAP_OB (pl->map, x, y); 184 object *rune = GET_MAP_OB (pl->map, x, y);
185
189 while (rune && ((rune->type != SIGN) || (strcmp (rune->arch->name, "rune_mark")))) 186 while (rune && (rune->type != SIGN || rune->arch->archname != shstr_rune_mark))
190 rune = rune->above; 187 rune = rune->above;
188
191 return rune; 189 return rune;
192} 190}
193 191
194/** 192/**
195 * Returns the book/scroll on the current square, for purposes of building 193 * Returns the book/scroll on the current square, for purposes of building
196 */ 194 */
197object * 195object *
198get_msg_book (object *pl, short x, short y) 196get_msg_book (object *pl, short x, short y)
199{ 197{
200 object *book;
201
202 book = GET_MAP_OB (pl->map, x, y); 198 object *book = GET_MAP_OB (pl->map, x, y);
199
203 while (book && (book->type != BOOK)) 200 while (book && (book->type != BOOK))
204 book = book->above; 201 book = book->above;
202
205 return book; 203 return book;
206} 204}
207 205
208/** 206/**
209 * Returns first item of type BUILDABLE_WALL. 207 * Returns first item of type BUILDABLE_WALL.
210 */ 208 */
211object * 209object *
212get_wall (maptile *map, int x, int y) 210get_wall (maptile *map, int x, int y)
213{ 211{
214 object *wall;
215
216 wall = GET_MAP_OB (map, x, y); 212 object *wall = GET_MAP_OB (map, x, y);
213
217 while (wall && (BUILDABLE_WALL != wall->type)) 214 while (wall && (BUILDABLE_WALL != wall->type))
218 wall = wall->above; 215 wall = wall->above;
219 216
220 return wall; 217 return wall;
221} 218}
232 * Note: x & y must be valid map coordinates. 229 * Note: x & y must be valid map coordinates.
233 */ 230 */
234void 231void
235fix_walls (maptile *map, int x, int y) 232fix_walls (maptile *map, int x, int y)
236{ 233{
237 object *wall;
238 char archetype[MAX_BUF]; 234 char archetype[MAX_BUF];
239 char *underscore; 235 char *underscore;
240 struct archetype *new_arch; 236 struct archetype *new_arch;
241 237
242
243 /* First, find the wall on that spot */ 238 /* First, find the wall on that spot */
244 wall = get_wall (map, x, y); 239 object *wall = get_wall (map, x, y);
245 if (!wall) 240 if (!wall)
246 /* Nothing -> bail out */ 241 /* Nothing -> bail out */
247 return; 242 return;
248 243
249 /* Find base name */ 244 /* Find base name */
250 assign (archetype, wall->arch->name); 245 assign (archetype, wall->arch->archname);
251 underscore = strchr (archetype, '_'); 246 underscore = strchr (archetype, '_');
252 247
253 /* search for the first _ before a number */ 248 /* search for the first _ before a number */
254 while (underscore && !isdigit (*(underscore + 1))) 249 while (underscore && !isdigit (*(underscore + 1)))
255 underscore = strchr (underscore + 1, '_'); 250 underscore = strchr (underscore + 1, '_');
476 if (!OUT_OF_REAL_MAP (pl->map, xt, yt)) 471 if (!OUT_OF_REAL_MAP (pl->map, xt, yt))
477 fix_walls (pl->map, xt, yt); 472 fix_walls (pl->map, xt, yt);
478 } 473 }
479 474
480 /* Now remove raw item from inventory */ 475 /* Now remove raw item from inventory */
481 decrease_ob (material); 476 material->decrease ();
482 477
483 /* And tell player about the fix */ 478 /* And tell player about the fix */
484 new_draw_info (NDI_UNIQUE, 0, pl, message); 479 new_draw_info (NDI_UNIQUE, 0, pl, message);
485} 480}
486 481
563 fix_walls (pl->map, xt, yt); 558 fix_walls (pl->map, xt, yt);
564 } 559 }
565 } 560 }
566 561
567 /* Now remove item from inventory */ 562 /* Now remove item from inventory */
568 decrease_ob (material); 563 material->decrease ();
569 564
570 /* And tell player what happened */ 565 /* And tell player what happened */
571 new_draw_info (NDI_UNIQUE, 0, pl, message); 566 new_draw_info (NDI_UNIQUE, 0, pl, message);
572} 567}
573 568
585 object *tmp; 580 object *tmp;
586 struct archetype *arch; 581 struct archetype *arch;
587 int insert_flag; 582 int insert_flag;
588 object *floor; 583 object *floor;
589 object *con_rune; 584 object *con_rune;
590 int connected;
591 585
592 /* Find floor */ 586 /* Find floor */
593 floor = GET_MAP_OB (pl->map, x, y); 587 floor = GET_MAP_OB (pl->map, x, y);
594 if (!floor) 588 if (!floor)
595 { 589 {
610 if (!arch) 604 if (!arch)
611 return; 605 return;
612 606
613 tmp = arch_to_object (arch); 607 tmp = arch_to_object (arch);
614 608
615 if ((floor->above) && (!can_build_over (pl->map, tmp, x, y))) 609 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 */ 610 /* Floor has something on top that interferes with building */
617 { 611 {
618 new_draw_info (NDI_UNIQUE, 0, pl, "You can't build here."); 612 new_draw_info (NDI_UNIQUE, 0, pl, "You can't build here.");
619 return; 613 return;
620 } 614 }
626 * This doesn't work on non unique maps. pedestals under floor will not be saved... 620 * This doesn't work on non unique maps. pedestals under floor will not be saved...
627 insert_flag = ( item->stats.Str == 1 ) ? INS_BELOW_ORIGINATOR : INS_ABOVE_FLOOR_ONLY; 621 insert_flag = ( item->stats.Str == 1 ) ? INS_BELOW_ORIGINATOR : INS_ABOVE_FLOOR_ONLY;
628 */ 622 */
629 insert_flag = INS_ABOVE_FLOOR_ONLY; 623 insert_flag = INS_ABOVE_FLOOR_ONLY;
630 624
631 connected = 0; 625 shstr_tmp connected;
626
632 switch (tmp->type) 627 switch (tmp->type)
633 { 628 {
634 case DOOR: 629 case DOOR:
635 case GATE: 630 case GATE:
636 case BUTTON: 631 case BUTTON:
637 case DETECTOR: 632 case DETECTOR:
638 case TIMED_GATE: 633 case TIMED_GATE:
639 case PEDESTAL: 634 case PEDESTAL:
640 case CF_HANDLE: 635 case CF_HANDLE:
641 case MAGIC_EAR: 636 case MAGIC_EAR:
642 case SIGN: 637 case SIGN:
643 /* Signs don't need a connection, but but magic mouths do. */ 638 /* Signs don't need a connection, but but magic mouths do. */
644 if (tmp->type == SIGN && strcmp (tmp->arch->name, "magic_mouth")) 639 if (tmp->type == SIGN && tmp->arch->archname != shstr_magic_mouth)
645 break; 640 break;
641
646 con_rune = get_connection_rune (pl, x, y); 642 con_rune = get_connection_rune (pl, x, y);
647 connected = find_or_create_connection_for_map (pl, x, y, con_rune); 643 connected = find_or_create_connection_for_map (pl, x, y, con_rune);
648 if (connected == -1) 644 if (!connected)
649 { 645 {
650 /* Player already informed of failure by the previous function */ 646 /* Player already informed of failure by the previous function */
651 tmp->destroy (); 647 tmp->destroy ();
652 return; 648 return;
653 } 649 }
650
654 /* Remove marking rune */ 651 /* Remove marking rune */
655 con_rune->destroy (); 652 con_rune->destroy ();
656 } 653 }
657 654
658 /* For magic mouths/ears, and signs, take the msg from a book of scroll */ 655 /* For magic mouths/ears, and signs, take the msg from a book of scroll */
659 if ((tmp->type == SIGN) || (tmp->type == MAGIC_EAR)) 656 if ((tmp->type == SIGN) || (tmp->type == MAGIC_EAR))
660 { 657 {
664 return; 661 return;
665 } 662 }
666 } 663 }
667 664
668 insert_ob_in_map_at (tmp, pl->map, floor, insert_flag, x, y); 665 insert_ob_in_map_at (tmp, pl->map, floor, insert_flag, x, y);
669 if (connected != 0) 666 if (connected)
670 add_button_link (tmp, pl->map, connected); 667 tmp->add_link (pl->map, connected);
671 668
672 new_draw_info_format (NDI_UNIQUE, 0, pl, "You build the %s", query_name (tmp)); 669 new_draw_info_format (NDI_UNIQUE, 0, pl, "You build the %s", query_name (tmp));
673 decrease_ob_nr (item, 1); 670 item->decrease ();
674} 671}
675 672
676/** 673/**
677 * Item remover. 674 * Item remover.
678 * 675 *
764 /* Nothing, meaning player is standing next to an undefined square... */ 761 /* 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); 762 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."); 763 new_draw_info (NDI_UNIQUE, 0, pl, "You'd better not build here, it looks weird.");
767 return; 764 return;
768 } 765 }
766
769 tmp2 = find_marked_object (pl); 767 tmp2 = find_marked_object (pl);
770 while (tmp) 768 while (tmp)
771 { 769 {
772 if (!QUERY_FLAG (tmp, FLAG_IS_BUILDABLE) && ((tmp->type != SIGN) || (strcmp (tmp->arch->name, "rune_mark")))) 770 if (!QUERY_FLAG (tmp, FLAG_IS_BUILDABLE) && (tmp->type != SIGN || tmp->arch->archname != shstr_rune_mark))
773 { 771 {
774 /* The item building function already has it's own special 772 /* The item building function already has it's own special
775 * checks for this 773 * checks for this
776 */ 774 */
777 if ((!tmp2) || (tmp2->subtype != ST_MAT_ITEM)) 775 if ((!tmp2) || (tmp2->subtype != ST_MAT_ITEM))
782 } 780 }
783 tmp = tmp->above; 781 tmp = tmp->above;
784 } 782 }
785 783
786 /* Now we know the square is ok */ 784 /* Now we know the square is ok */
787 builder = pl->contr->ranges[range_builder]; 785 builder = pl->contr->ranged_ob;
788 786
789 if (builder->subtype == ST_BD_REMOVE) 787 if (builder->subtype == ST_BD_REMOVE)
790 /* Remover -> call specific function and bail out */ 788 /* Remover -> call specific function and bail out */
791 { 789 {
792 apply_builder_remove (pl, dir); 790 apply_builder_remove (pl, dir);
860 tmp->msg = book->msg; 858 tmp->msg = book->msg;
861 859
862 if (tmp->invisible) 860 if (tmp->invisible)
863 { 861 {
864 if (book->custom_name != NULL) 862 if (book->custom_name != NULL)
865 {
866 snprintf (buf, sizeof (buf), "talking %s", &book->custom_name); 863 snprintf (buf, sizeof (buf), "talking %s", &book->custom_name);
867 }
868 else 864 else
869 {
870 snprintf (buf, sizeof (buf), "talking %s", &book->name); 865 snprintf (buf, sizeof (buf), "talking %s", &book->name);
871 } 866
872 tmp->name = buf; 867 tmp->name = buf;
873 868
874 if (book->name_pl != NULL) 869 if (book->name_pl != NULL)
875 { 870 {
876 snprintf (buf2, sizeof (buf2), "talking %s", &book->name_pl); 871 snprintf (buf2, sizeof (buf2), "talking %s", &book->name_pl);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines