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.28 by root, Sun Jul 1 05:00:19 2007 UTC vs.
Revision 1.40 by root, Mon Oct 12 14:00:59 2009 UTC

1/* 1/*
2 * This file is part of Crossfire TRT, the Roguelike Realtime MORPG. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team 4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2001,2007 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2001,2007 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
7 * 7 *
8 * Crossfire TRT is free software: you can redistribute it and/or modify 8 * Deliantra is free software: you can redistribute it and/or modify it under
9 * it under the terms of the GNU General Public License as published by 9 * the terms of the Affero GNU General Public License as published by the
10 * the Free Software Foundation, either version 3 of the License, or 10 * Free Software Foundation, either version 3 of the License, or (at your
11 * (at your 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 GNU General Public License 18 * You should have received a copy of the Affero GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. 19 * and the GNU General Public License along with this program. If not, see
20 * <http://www.gnu.org/licenses/>.
20 * 21 *
21 * The authors can be reached via e-mail to <crossfire@schmorp.de> 22 * The authors can be reached via e-mail to <support@deliantra.net>
22 */ 23 */
23 24
24#include <global.h> 25#include <global.h>
25#include <living.h> 26#include <living.h>
26#include <spells.h> 27#include <spells.h>
38 39
39 ob = GET_MAP_OB (map, x, y); 40 ob = GET_MAP_OB (map, x, y);
40 while (ob) 41 while (ob)
41 { 42 {
42 /* if ob is not a marking rune or floor, then check special cases */ 43 /* if ob is not a marking rune or floor, then check special cases */
43 if (strcmp (ob->arch->archname, "rune_mark") && ob->type != FLOOR) 44 if (ob->arch->archname != shstr_rune_mark && ob->type != FLOOR)
44 { 45 {
45 switch (tmp->type) 46 switch (tmp->type)
46 { 47 {
47 case SIGN: 48 case SIGN:
48 case MAGIC_EAR: 49 case MAGIC_EAR:
49 /* Allow signs and magic ears to be built on books */ 50 /* Allow signs and magic ears to be built on books */
50 if (ob->type != BOOK) 51 if (ob->type != BOOK)
51 {
52 return 0;
53 }
54 break;
55 case BUTTON:
56 case DETECTOR:
57 case PEDESTAL:
58 case CF_HANDLE:
59 /* Allow buttons and levers to be built under gates */
60 if (ob->type != GATE && ob->type != DOOR)
61 {
62 return 0;
63 }
64 break;
65 default:
66 return 0; 52 return 0;
53 break;
54 case BUTTON:
55 case DETECTOR:
56 case PEDESTAL:
57 case CF_HANDLE:
58 /* Allow buttons and levers to be built under gates */
59 if (ob->type != GATE && ob->type != DOOR)
60 return 0;
61 break;
62 default:
63 return 0;
67 } 64 }
68 } 65 }
66
69 ob = ob->above; 67 ob = ob->above;
70 } 68 }
71 return 1; 69 return 1;
72} 70}
73 71
83 rune = GET_MAP_OB (map, x, y); 81 rune = GET_MAP_OB (map, x, y);
84 while (rune) 82 while (rune)
85 { 83 {
86 next = rune->above; 84 next = rune->above;
87 85
88 if ((rune->type == SIGN) && (!strcmp (rune->arch->archname, "rune_mark"))) 86 if (rune->type == SIGN && rune->arch->archname == shstr_rune_mark)
89 rune->destroy (); 87 rune->destroy ();
90 88
91 rune = next; 89 rune = next;
92 } 90 }
93} 91}
97 * \param map: map for which to find a value 95 * \param map: map for which to find a value
98 * \return 'connected' value with no item, or -1 if failure. 96 * \return 'connected' value with no item, or -1 if failure.
99 * 97 *
100 * Tries 1000 random values, then returns -1. 98 * Tries 1000 random values, then returns -1.
101 */ 99 */
102int 100static shstr_tmp
103find_unused_connected_value (maptile *map) 101find_unused_connected_value (maptile *map)
104{ 102{
105 int connected = 0; 103 for (int i = 1000; --i; )
106 int itest = 0;
107 oblinkpt *obp;
108
109 while (itest++ < 1000)
110 {
111 connected = 1 + rand () % 20000;
112 for (obp = map->buttons; obp && (obp->value != connected); obp = obp->next);
113
114 if (!obp)
115 return connected;
116 } 104 {
105 char buf[64];
117 106
118 return -1; 107 snprintf (buf, sizeof (buf), "built-%x", rndm (0xf0000000U) + 0x10000000U);
119}
120 108
109 shstr id (buf);
110
111 if (!map->find_link (id))
112 return id;
113 }
114
115 return shstr_tmp ();
116}
121 117
122/** 118/**
123 * Helper function for door/button/connected item building. 119 * Helper function for door/button/connected item building.
124 * 120 *
125 * Will search the specified spot for a marking rune. 121 * Will search the specified spot for a marking rune.
127 * Else, searches a force in op's inventory matching the map's name 123 * Else, searches a force in op's inventory matching the map's name
128 * and the rune's text. 124 * and the rune's text.
129 * If found, returns the connection value associated 125 * If found, returns the connection value associated
130 * else searches a new connection value, and adds the force to the player. 126 * else searches a new connection value, and adds the force to the player.
131 */ 127 */
132int 128static shstr_tmp
133find_or_create_connection_for_map (object *pl, short x, short y, object *rune) 129find_or_create_connection_for_map (object *pl, short x, short y, object *rune)
134{ 130{
135 object *force; 131 object *force;
136 int connected;
137 132
138 if (!rune) 133 if (!rune)
139 rune = get_connection_rune (pl, x, y); 134 rune = get_connection_rune (pl, x, y);
140 135
141 if (!rune) 136 if (!rune)
142 { 137 {
143 new_draw_info (NDI_UNIQUE, 0, pl, "You need to put a marking rune with the group name."); 138 new_draw_info (NDI_UNIQUE, 0, pl, "You need to put a marking rune with the group name.");
144 return -1; 139 return shstr_tmp ();
145 } 140 }
146 141
147 /* Now, find force in player's inventory */ 142 /* Now, find force in player's inventory */
148 force = pl->inv; 143 force = pl->inv;
149 while (force 144 while (force
153 148
154 if (!force) 149 if (!force)
155 /* No force, need to create & insert one */ 150 /* No force, need to create & insert one */
156 { 151 {
157 /* Find unused value */ 152 /* Find unused value */
158 connected = find_unused_connected_value (pl->map); 153 shstr_tmp id = find_unused_connected_value (pl->map);
159 if (connected == -1) 154
155 if (!id)
160 { 156 {
161 new_draw_info (NDI_UNIQUE, 0, pl, "Could not create more groups."); 157 new_draw_info (NDI_UNIQUE, 0, pl, "Could not create more groups.");
162 return -1; 158 return shstr_tmp ();
163 } 159 }
164 160
165 force = get_archetype (FORCE_NAME); 161 force = get_archetype (FORCE_NAME);
166 force->slaying = pl->map->path; 162 force->slaying = pl->map->path;
167 force->msg = rune->msg; 163 force->msg = rune->msg;
168 force->path_attuned = connected; 164 force->race = id;
169 force->set_speed (0); 165 force->set_speed (0);
166
170 insert_ob_in_ob (force, pl); 167 insert_ob_in_ob (force, pl);
171 168
172 return connected; 169 return id;
173 } 170 }
174 171
175 /* Found the force, everything's easy. */ 172 /* Found the force, everything's easy. */
176 return force->path_attuned; 173 return force->race;
177} 174}
178 175
179/** 176/**
180 * Returns the marking rune on the square, for purposes of building connections 177 * Returns the marking rune on the square, for purposes of building connections
181 */ 178 */
182object * 179object *
183get_connection_rune (object *pl, short x, short y) 180get_connection_rune (object *pl, short x, short y)
184{ 181{
185 object *rune;
186
187 rune = GET_MAP_OB (pl->map, x, y); 182 object *rune = GET_MAP_OB (pl->map, x, y);
183
188 while (rune && ((rune->type != SIGN) || (strcmp (rune->arch->archname, "rune_mark")))) 184 while (rune && (rune->type != SIGN || rune->arch->archname != shstr_rune_mark))
189 rune = rune->above; 185 rune = rune->above;
186
190 return rune; 187 return rune;
191} 188}
192 189
193/** 190/**
194 * Returns the book/scroll on the current square, for purposes of building 191 * Returns the book/scroll on the current square, for purposes of building
195 */ 192 */
196object * 193object *
197get_msg_book (object *pl, short x, short y) 194get_msg_book (object *pl, short x, short y)
198{ 195{
199 object *book;
200
201 book = GET_MAP_OB (pl->map, x, y); 196 object *book = GET_MAP_OB (pl->map, x, y);
197
202 while (book && (book->type != BOOK)) 198 while (book && (book->type != BOOK))
203 book = book->above; 199 book = book->above;
200
204 return book; 201 return book;
205} 202}
206 203
207/** 204/**
208 * Returns first item of type BUILDABLE_WALL. 205 * Returns first item of type BUILDABLE_WALL.
209 */ 206 */
210object * 207object *
211get_wall (maptile *map, int x, int y) 208get_wall (maptile *map, int x, int y)
212{ 209{
213 object *wall;
214
215 wall = GET_MAP_OB (map, x, y); 210 object *wall = GET_MAP_OB (map, x, y);
211
216 while (wall && (BUILDABLE_WALL != wall->type)) 212 while (wall && (BUILDABLE_WALL != wall->type))
217 wall = wall->above; 213 wall = wall->above;
218 214
219 return wall; 215 return wall;
220} 216}
231 * Note: x & y must be valid map coordinates. 227 * Note: x & y must be valid map coordinates.
232 */ 228 */
233void 229void
234fix_walls (maptile *map, int x, int y) 230fix_walls (maptile *map, int x, int y)
235{ 231{
236 object *wall;
237 char archetype[MAX_BUF]; 232 char archetype[MAX_BUF];
238 char *underscore; 233 char *underscore;
239 struct archetype *new_arch; 234 struct archetype *new_arch;
240 235
241
242 /* First, find the wall on that spot */ 236 /* First, find the wall on that spot */
243 wall = get_wall (map, x, y); 237 object *wall = get_wall (map, x, y);
244 if (!wall) 238 if (!wall)
245 /* Nothing -> bail out */ 239 /* Nothing -> bail out */
246 return; 240 return;
247 241
248 /* Find base name */ 242 /* Find base name */
411 floor_removed = 1; 405 floor_removed = 1;
412 } 406 }
413 else 407 else
414 { 408 {
415 if (floor_removed) 409 if (floor_removed)
410 {
411 /* This is the first item that was above the floor */
416 above_floor = tmp; 412 above_floor = tmp;
413 floor_removed = 0;
414 }
417 } 415 }
418 416
419 tmp = above; 417 tmp = above;
420 } 418 }
421 } 419 }
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
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
584 object *tmp; 582 object *tmp;
585 struct archetype *arch; 583 struct archetype *arch;
586 int insert_flag; 584 int insert_flag;
587 object *floor; 585 object *floor;
588 object *con_rune; 586 object *con_rune;
589 int connected;
590 587
591 /* Find floor */ 588 /* Find floor */
592 floor = GET_MAP_OB (pl->map, x, y); 589 floor = GET_MAP_OB (pl->map, x, y);
593 if (!floor) 590 if (!floor)
594 { 591 {
609 if (!arch) 606 if (!arch)
610 return; 607 return;
611 608
612 tmp = arch_to_object (arch); 609 tmp = arch_to_object (arch);
613 610
614 if ((floor->above) && (!can_build_over (pl->map, tmp, x, y))) 611 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 */ 612 /* Floor has something on top that interferes with building */
616 { 613 {
617 new_draw_info (NDI_UNIQUE, 0, pl, "You can't build here."); 614 new_draw_info (NDI_UNIQUE, 0, pl, "You can't build here.");
618 return; 615 return;
619 } 616 }
620 617
621 SET_FLAG (tmp, FLAG_IS_BUILDABLE); 618 SET_FLAG (tmp, FLAG_IS_BUILDABLE);
622 SET_FLAG (tmp, FLAG_NO_PICK); 619 SET_FLAG (tmp, FLAG_NO_PICK);
623 620
624 /* 621 /*
625 * This doesn't work on non unique maps. pedestals under floor will not be saved... 622 * Str 1 is a flag that the item [pedestal] should go below the floor.
626 insert_flag = ( item->stats.Str == 1 ) ? INS_BELOW_ORIGINATOR : INS_ABOVE_FLOOR_ONLY; 623 * Items under the floor on non-unique maps will not be saved,
624 * so make the item itself unique in this situation.
627 */ 625 */
628 insert_flag = INS_ABOVE_FLOOR_ONLY; 626 insert_flag = ( item->stats.Str == 1 ) ? INS_BELOW_ORIGINATOR : INS_ABOVE_FLOOR_ONLY;
627 if (insert_flag == INS_BELOW_ORIGINATOR && !pl->map->no_reset)
628 SET_FLAG (tmp, FLAG_UNIQUE);
629 629
630 connected = 0; 630 shstr_tmp connected;
631
631 switch (tmp->type) 632 switch (tmp->type)
632 { 633 {
633 case DOOR: 634 case DOOR:
634 case GATE: 635 case GATE:
635 case BUTTON: 636 case BUTTON:
636 case DETECTOR: 637 case DETECTOR:
637 case TIMED_GATE: 638 case TIMED_GATE:
638 case PEDESTAL: 639 case PEDESTAL:
639 case CF_HANDLE: 640 case CF_HANDLE:
640 case MAGIC_EAR: 641 case MAGIC_EAR:
641 case SIGN: 642 case SIGN:
642 /* Signs don't need a connection, but but magic mouths do. */ 643 /* Signs don't need a connection, but but magic mouths do. */
643 if (tmp->type == SIGN && strcmp (tmp->arch->archname, "magic_mouth")) 644 if (tmp->type == SIGN && tmp->arch->archname != shstr_magic_mouth)
644 break; 645 break;
646
645 con_rune = get_connection_rune (pl, x, y); 647 con_rune = get_connection_rune (pl, x, y);
646 connected = find_or_create_connection_for_map (pl, x, y, con_rune); 648 connected = find_or_create_connection_for_map (pl, x, y, con_rune);
647 if (connected == -1) 649 if (!connected)
648 { 650 {
649 /* Player already informed of failure by the previous function */ 651 /* Player already informed of failure by the previous function */
650 tmp->destroy (); 652 tmp->destroy ();
651 return; 653 return;
652 } 654 }
655
653 /* Remove marking rune */ 656 /* Remove marking rune */
654 con_rune->destroy (); 657 con_rune->destroy ();
655 } 658 }
656 659
657 /* For magic mouths/ears, and signs, take the msg from a book of scroll */ 660 /* For magic mouths/ears, and signs, take the msg from a book of scroll */
658 if ((tmp->type == SIGN) || (tmp->type == MAGIC_EAR)) 661 if ((tmp->type == SIGN) || (tmp->type == MAGIC_EAR))
659 { 662 {
663 return; 666 return;
664 } 667 }
665 } 668 }
666 669
667 insert_ob_in_map_at (tmp, pl->map, floor, insert_flag, x, y); 670 insert_ob_in_map_at (tmp, pl->map, floor, insert_flag, x, y);
668 if (connected != 0) 671 if (connected)
669 add_button_link (tmp, pl->map, connected); 672 tmp->add_link (pl->map, connected);
670 673
671 new_draw_info_format (NDI_UNIQUE, 0, pl, "You build the %s", query_name (tmp)); 674 new_draw_info_format (NDI_UNIQUE, 0, pl, "You build the %s", query_name (tmp));
672 decrease_ob_nr (item, 1); 675 item->decrease ();
673} 676}
674 677
675/** 678/**
676 * Item remover. 679 * Item remover.
677 * 680 *
767 } 770 }
768 771
769 tmp2 = find_marked_object (pl); 772 tmp2 = find_marked_object (pl);
770 while (tmp) 773 while (tmp)
771 { 774 {
772 if (!QUERY_FLAG (tmp, FLAG_IS_BUILDABLE) && ((tmp->type != SIGN) || (strcmp (tmp->arch->archname, "rune_mark")))) 775 if (!QUERY_FLAG (tmp, FLAG_IS_BUILDABLE) && (tmp->type != SIGN || tmp->arch->archname != shstr_rune_mark))
773 { 776 {
774 /* The item building function already has it's own special 777 /* The item building function already has it's own special
775 * checks for this 778 * checks for this
776 */ 779 */
777 if ((!tmp2) || (tmp2->subtype != ST_MAT_ITEM)) 780 if ((!tmp2) || (tmp2->subtype != ST_MAT_ITEM))
860 tmp->msg = book->msg; 863 tmp->msg = book->msg;
861 864
862 if (tmp->invisible) 865 if (tmp->invisible)
863 { 866 {
864 if (book->custom_name != NULL) 867 if (book->custom_name != NULL)
865 {
866 snprintf (buf, sizeof (buf), "talking %s", &book->custom_name); 868 snprintf (buf, sizeof (buf), "talking %s", &book->custom_name);
867 }
868 else 869 else
869 {
870 snprintf (buf, sizeof (buf), "talking %s", &book->name); 870 snprintf (buf, sizeof (buf), "talking %s", &book->name);
871 } 871
872 tmp->name = buf; 872 tmp->name = buf;
873 873
874 if (book->name_pl != NULL) 874 if (book->name_pl != NULL)
875 { 875 {
876 snprintf (buf2, sizeof (buf2), "talking %s", &book->name_pl); 876 snprintf (buf2, sizeof (buf2), "talking %s", &book->name_pl);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines