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.11 by root, Tue Dec 12 20:53:03 2006 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 (©) 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 (ob->arch->archname != shstr_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:
82 82
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 if ((rune->type == SIGN) && (!strcmp (rune->arch->name, "rune_mark"))) 88 if (rune->type == SIGN && rune->arch->archname == shstr_rune_mark)
88 {
89 rune->remove ();
90 rune->destroy (0); 89 rune->destroy ();
91 } 90
92 rune = next; 91 rune = next;
93 } 92 }
94} 93}
95 94
96/** 95/**
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
151 && ((force->type != FORCE) || (!force->slaying) || (strcmp (force->slaying, pl->map->path)) || (!force->msg) 147 && ((force->type != FORCE) || !force->slaying || force->slaying != pl->map->path || !force->msg
152 || (strcmp (force->msg, rune->msg)))) 148 || force->msg != rune->msg))
153 force = force->below; 149 force = force->below;
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->speed = 0;
168 update_ob_speed (force);
169 force->slaying = pl->map->path; 164 force->slaying = pl->map->path;
170 force->msg = rune->msg; 165 force->msg = rune->msg;
171 force->path_attuned = connected; 166 force->race = id;
167 force->set_speed (0);
168
172 insert_ob_in_ob (force, pl); 169 insert_ob_in_ob (force, pl);
173 170
174 return connected; 171 return id;
175 } 172 }
176 173
177 /* Found the force, everything's easy. */ 174 /* Found the force, everything's easy. */
178 return force->path_attuned; 175 return force->race;
179} 176}
180 177
181/** 178/**
182 * 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
183 */ 180 */
184object * 181object *
185get_connection_rune (object *pl, short x, short y) 182get_connection_rune (object *pl, short x, short y)
186{ 183{
187 object *rune;
188
189 rune = GET_MAP_OB (pl->map, x, y); 184 object *rune = GET_MAP_OB (pl->map, x, y);
185
190 while (rune && ((rune->type != SIGN) || (strcmp (rune->arch->name, "rune_mark")))) 186 while (rune && (rune->type != SIGN || rune->arch->archname != shstr_rune_mark))
191 rune = rune->above; 187 rune = rune->above;
188
192 return rune; 189 return rune;
193} 190}
194 191
195/** 192/**
196 * 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
197 */ 194 */
198object * 195object *
199get_msg_book (object *pl, short x, short y) 196get_msg_book (object *pl, short x, short y)
200{ 197{
201 object *book;
202
203 book = GET_MAP_OB (pl->map, x, y); 198 object *book = GET_MAP_OB (pl->map, x, y);
199
204 while (book && (book->type != BOOK)) 200 while (book && (book->type != BOOK))
205 book = book->above; 201 book = book->above;
202
206 return book; 203 return book;
207} 204}
208 205
209/** 206/**
210 * Returns first item of type WALL. 207 * Returns first item of type BUILDABLE_WALL.
211 */ 208 */
212object * 209object *
213get_wall (maptile *map, int x, int y) 210get_wall (maptile *map, int x, int y)
214{ 211{
215 object *wall;
216
217 wall = GET_MAP_OB (map, x, y); 212 object *wall = GET_MAP_OB (map, x, y);
213
218 while (wall && (WALL != wall->type)) 214 while (wall && (BUILDABLE_WALL != wall->type))
219 wall = wall->above; 215 wall = wall->above;
220 216
221 return wall; 217 return wall;
222} 218}
223 219
233 * Note: x & y must be valid map coordinates. 229 * Note: x & y must be valid map coordinates.
234 */ 230 */
235void 231void
236fix_walls (maptile *map, int x, int y) 232fix_walls (maptile *map, int x, int y)
237{ 233{
238 int connect;
239 object *wall;
240 char archetype[MAX_BUF]; 234 char archetype[MAX_BUF];
241 char *underscore; 235 char *underscore;
242 uint32 old_flags[4];
243 struct archetype *new_arch; 236 struct archetype *new_arch;
244 int flag;
245
246 237
247 /* First, find the wall on that spot */ 238 /* First, find the wall on that spot */
248 wall = get_wall (map, x, y); 239 object *wall = get_wall (map, x, y);
249 if (!wall) 240 if (!wall)
250 /* Nothing -> bail out */ 241 /* Nothing -> bail out */
251 return; 242 return;
252 243
253 /* Find base name */ 244 /* Find base name */
254 strcpy (archetype, wall->arch->name); 245 assign (archetype, wall->arch->archname);
255 underscore = strchr (archetype, '_'); 246 underscore = strchr (archetype, '_');
256 247
257 /* search for the first _ before a number */ 248 /* search for the first _ before a number */
258 while (underscore && !isdigit (*(underscore + 1))) 249 while (underscore && !isdigit (*(underscore + 1)))
259 underscore = strchr (underscore + 1, '_'); 250 underscore = strchr (underscore + 1, '_');
263 return; 254 return;
264 255
265 underscore++; 256 underscore++;
266 *underscore = '\0'; 257 *underscore = '\0';
267 258
268 connect = 0; 259 int connect = 0;
269 260
270 if ((x > 0) && get_wall (map, x - 1, y)) 261 if ((x > 0) && get_wall (map, x - 1, y))
271 connect |= 1; 262 connect |= 1;
272 if ((x < MAP_WIDTH (map) - 1) && get_wall (map, x + 1, y)) 263 if ((x < map->width - 1) && get_wall (map, x + 1, y))
273 connect |= 2; 264 connect |= 2;
274 265
275 if ((y > 0) && get_wall (map, x, y - 1)) 266 if ((y > 0) && get_wall (map, x, y - 1))
276 connect |= 4; 267 connect |= 4;
277 268
278 if ((y < MAP_HEIGHT (map) - 1) && get_wall (map, x, y + 1)) 269 if ((y < map->height - 1) && get_wall (map, x, y + 1))
279 connect |= 8; 270 connect |= 8;
280 271
281 switch (connect) 272 switch (connect)
282 { 273 {
283 case 0: 274 case 0:
356 return; 347 return;
357 348
358 /* Now delete current wall, and insert new one 349 /* Now delete current wall, and insert new one
359 * We save flags to avoid any trouble with buildable/non buildable, and so on 350 * We save flags to avoid any trouble with buildable/non buildable, and so on
360 */ 351 */
361 for (flag = 0; flag < 4; flag++) 352 object::flags_t old_flags = wall->flag; // elmex: this is where C++ pays off
362 old_flags[flag] = wall->flags[flag]; 353
363 wall->remove ();
364 wall->destroy (0); 354 wall->destroy ();
365 355
366 wall = arch_to_object (new_arch); 356 wall = arch_to_object (new_arch);
367 wall->type = WALL; 357 wall->type = BUILDABLE_WALL;
368 insert_ob_in_map_at (wall, map, NULL, INS_ABOVE_FLOOR_ONLY, x, y); 358 insert_ob_in_map_at (wall, map, NULL, INS_ABOVE_FLOOR_ONLY, x, y);
369 for (flag = 0; flag < 4; flag++)
370 wall->flags[flag] = old_flags[flag]; 359 wall->flag = old_flags;
371} 360}
372 361
373/** 362/**
374 * \brief Floor building function 363 * \brief Floor building function
375 * 364 *
403 if (tmp) 392 if (tmp)
404 { 393 {
405 while (tmp) 394 while (tmp)
406 { 395 {
407 above = tmp->above; 396 above = tmp->above;
408 if (WALL == tmp->type) 397 if (BUILDABLE_WALL == tmp->type)
409 { 398 {
410 /* There was a wall, remove it & keep its archetype to make new walls */ 399 /* There was a wall, remove it & keep its archetype to make new walls */
411 new_wall = tmp->arch; 400 new_wall = tmp->arch;
412 tmp->remove ();
413 tmp->destroy (0); 401 tmp->destroy ();
414 sprintf (message, "You destroy the wall and redo the floor."); 402 sprintf (message, "You destroy the wall and redo the floor.");
415 } 403 }
416 else if ((FLOOR == tmp->type) || (QUERY_FLAG (tmp, FLAG_IS_FLOOR))) 404 else if ((FLOOR == tmp->type) || (QUERY_FLAG (tmp, FLAG_IS_FLOOR)))
417 { 405 {
418 tmp->remove ();
419 tmp->destroy (0); 406 tmp->destroy ();
420 floor_removed = 1; 407 floor_removed = 1;
421 } 408 }
422 else 409 else
423 { 410 {
424 if (floor_removed) 411 if (floor_removed)
466 /* Insert wall if exists. Note: if it doesn't, the map is weird... */ 453 /* Insert wall if exists. Note: if it doesn't, the map is weird... */
467 if (new_wall) 454 if (new_wall)
468 { 455 {
469 tmp = arch_to_object (new_wall); 456 tmp = arch_to_object (new_wall);
470 SET_FLAG (tmp, FLAG_IS_BUILDABLE); 457 SET_FLAG (tmp, FLAG_IS_BUILDABLE);
471 tmp->type = WALL; 458 tmp->type = BUILDABLE_WALL;
472 insert_ob_in_map_at (tmp, pl->map, 0, 0, xt, yt); 459 insert_ob_in_map_at (tmp, pl->map, 0, 0, xt, yt);
473 } 460 }
474 } 461 }
475 } 462 }
476 463
484 if (!OUT_OF_REAL_MAP (pl->map, xt, yt)) 471 if (!OUT_OF_REAL_MAP (pl->map, xt, yt))
485 fix_walls (pl->map, xt, yt); 472 fix_walls (pl->map, xt, yt);
486 } 473 }
487 474
488 /* Now remove raw item from inventory */ 475 /* Now remove raw item from inventory */
489 decrease_ob (material); 476 material->decrease ();
490 477
491 /* And tell player about the fix */ 478 /* And tell player about the fix */
492 new_draw_info (NDI_UNIQUE, 0, pl, message); 479 new_draw_info (NDI_UNIQUE, 0, pl, message);
493} 480}
494 481
528 /* Grab existing wall, if any */ 515 /* Grab existing wall, if any */
529 current_wall = NULL; 516 current_wall = NULL;
530 tmp = GET_MAP_OB (pl->map, x, y); 517 tmp = GET_MAP_OB (pl->map, x, y);
531 while (tmp && !current_wall) 518 while (tmp && !current_wall)
532 { 519 {
533 if (WALL == tmp->type) 520 if (BUILDABLE_WALL == tmp->type)
534 current_wall = tmp; 521 current_wall = tmp;
535 522
536 tmp = tmp->above; 523 tmp = tmp->above;
537 } 524 }
538 525
546 LOG (llevError, "apply_builder_wall: unable to find archetype %s\n", &material->slaying); 533 LOG (llevError, "apply_builder_wall: unable to find archetype %s\n", &material->slaying);
547 return; 534 return;
548 } 535 }
549 536
550 tmp = arch_to_object (new_wall); 537 tmp = arch_to_object (new_wall);
551 tmp->type = WALL; 538 tmp->type = BUILDABLE_WALL;
552 SET_FLAG (tmp, FLAG_IS_BUILDABLE); 539 SET_FLAG (tmp, FLAG_IS_BUILDABLE);
553 insert_ob_in_map_at (tmp, pl->map, 0, INS_ABOVE_FLOOR_ONLY, x, y); 540 insert_ob_in_map_at (tmp, pl->map, 0, INS_ABOVE_FLOOR_ONLY, x, y);
554 541
555 /* If existing wall, remove it, no need to fix other walls */ 542 /* If existing wall, remove it, no need to fix other walls */
556 if (current_wall) 543 if (current_wall)
557 { 544 {
558 current_wall->remove ();
559 current_wall->destroy (0); 545 current_wall->destroy ();
560 fix_walls (pl->map, x, y); 546 fix_walls (pl->map, x, y);
561 sprintf (message, "You redecorate the wall to better suit your tastes."); 547 sprintf (message, "You redecorate the wall to better suit your tastes.");
562 } 548 }
563 else 549 else
564 { 550 {
572 fix_walls (pl->map, xt, yt); 558 fix_walls (pl->map, xt, yt);
573 } 559 }
574 } 560 }
575 561
576 /* Now remove item from inventory */ 562 /* Now remove item from inventory */
577 decrease_ob (material); 563 material->decrease ();
578 564
579 /* And tell player what happened */ 565 /* And tell player what happened */
580 new_draw_info (NDI_UNIQUE, 0, pl, message); 566 new_draw_info (NDI_UNIQUE, 0, pl, message);
581} 567}
582 568
594 object *tmp; 580 object *tmp;
595 struct archetype *arch; 581 struct archetype *arch;
596 int insert_flag; 582 int insert_flag;
597 object *floor; 583 object *floor;
598 object *con_rune; 584 object *con_rune;
599 int connected;
600 585
601 /* Find floor */ 586 /* Find floor */
602 floor = GET_MAP_OB (pl->map, x, y); 587 floor = GET_MAP_OB (pl->map, x, y);
603 if (!floor) 588 if (!floor)
604 { 589 {
619 if (!arch) 604 if (!arch)
620 return; 605 return;
621 606
622 tmp = arch_to_object (arch); 607 tmp = arch_to_object (arch);
623 608
624 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)))
625 /* Floor has something on top that interferes with building */ 610 /* Floor has something on top that interferes with building */
626 { 611 {
627 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.");
628 return; 613 return;
629 } 614 }
635 * 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...
636 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;
637 */ 622 */
638 insert_flag = INS_ABOVE_FLOOR_ONLY; 623 insert_flag = INS_ABOVE_FLOOR_ONLY;
639 624
640 connected = 0; 625 shstr_tmp connected;
626
641 switch (tmp->type) 627 switch (tmp->type)
642 { 628 {
643 case DOOR: 629 case DOOR:
644 case GATE: 630 case GATE:
645 case BUTTON: 631 case BUTTON:
646 case DETECTOR: 632 case DETECTOR:
647 case TIMED_GATE: 633 case TIMED_GATE:
648 case PEDESTAL: 634 case PEDESTAL:
649 case CF_HANDLE: 635 case CF_HANDLE:
650 case MAGIC_EAR: 636 case MAGIC_EAR:
651 case SIGN: 637 case SIGN:
652 /* Signs don't need a connection, but but magic mouths do. */ 638 /* Signs don't need a connection, but but magic mouths do. */
653 if (tmp->type == SIGN && strcmp (tmp->arch->name, "magic_mouth")) 639 if (tmp->type == SIGN && tmp->arch->archname != shstr_magic_mouth)
654 break; 640 break;
641
655 con_rune = get_connection_rune (pl, x, y); 642 con_rune = get_connection_rune (pl, x, y);
656 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);
657 if (connected == -1) 644 if (!connected)
658 { 645 {
659 /* Player already informed of failure by the previous function */ 646 /* Player already informed of failure by the previous function */
660 tmp->destroy (0); 647 tmp->destroy ();
661 return; 648 return;
662 } 649 }
650
663 /* Remove marking rune */ 651 /* Remove marking rune */
664 con_rune->remove ();
665 con_rune->destroy (0); 652 con_rune->destroy ();
666 } 653 }
667 654
668 /* 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 */
669 if ((tmp->type == SIGN) || (tmp->type == MAGIC_EAR)) 656 if ((tmp->type == SIGN) || (tmp->type == MAGIC_EAR))
670 { 657 {
671 if (adjust_sign_msg (pl, x, y, tmp) == -1) 658 if (adjust_sign_msg (pl, x, y, tmp) == -1)
672 { 659 {
673 tmp->destroy (0); 660 tmp->destroy ();
674 return; 661 return;
675 } 662 }
676 } 663 }
677 664
678 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);
679 if (connected != 0) 666 if (connected)
680 add_button_link (tmp, pl->map, connected); 667 tmp->add_link (pl->map, connected);
681 668
682 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));
683 decrease_ob_nr (item, 1); 670 item->decrease ();
684} 671}
685 672
686/** 673/**
687 * Item remover. 674 * Item remover.
688 * 675 *
701 item = GET_MAP_OB (pl->map, x, y); 688 item = GET_MAP_OB (pl->map, x, y);
702 if (!item) 689 if (!item)
703 { 690 {
704 /* Should not happen with previous tests, but we never know */ 691 /* Should not happen with previous tests, but we never know */
705 new_draw_info (NDI_UNIQUE, 0, pl, "Invalid square."); 692 new_draw_info (NDI_UNIQUE, 0, pl, "Invalid square.");
706 LOG (llevError, "apply_builder_remove: (null) square at (%d, %d, %s)\n", x, y, pl->map->path); 693 LOG (llevError, "apply_builder_remove: (null) square at (%d, %d, %s)\n", x, y, &pl->map->path);
707 return; 694 return;
708 } 695 }
709 696
710 if (item->type == FLOOR || QUERY_FLAG (item, FLAG_IS_FLOOR)) 697 if (item->type == FLOOR || QUERY_FLAG (item, FLAG_IS_FLOOR))
711 item = item->above; 698 item = item->above;
712 699
713 if (!item) 700 if (!item)
714 {
715 new_draw_info (NDI_UNIQUE, 0, pl, "Nothing to remove."); 701 new_draw_info (NDI_UNIQUE, 0, pl, "Nothing to remove.");
716 return; 702 else if (item->type == BUILDABLE_WALL)
717 }
718
719 /* Now remove object, with special cases (buttons & such) */
720 switch (item->type)
721 {
722 case WALL:
723 new_draw_info (NDI_UNIQUE, 0, pl, "Can't remove a wall with that, build a floor."); 703 new_draw_info (NDI_UNIQUE, 0, pl, "Can't remove a wall with that, build a floor.");
724 return; 704 else if (!item->flag [FLAG_IS_BUILDABLE])
725 705 new_draw_info_format (NDI_UNIQUE, 0, pl, "You can't remove the %s, it's not buildable!", query_name (item));
726 case DOOR: 706 else
727 case BUTTON: 707 {
728 case GATE:
729 case TIMED_GATE:
730 case DETECTOR:
731 case PEDESTAL:
732 case CF_HANDLE:
733 case MAGIC_EAR:
734 case SIGN:
735 /* Special case: must unconnect */
736 if (QUERY_FLAG (item, FLAG_IS_LINKED))
737 remove_button_link (item);
738
739 /* Fall through */
740
741 default:
742 /* Remove generic item */
743 new_draw_info_format (NDI_UNIQUE, 0, pl, "You remove the %s", query_name (item)); 708 new_draw_info_format (NDI_UNIQUE, 0, pl, "You remove the %s", query_name (item));
744 item->remove ();
745 item->destroy (0); 709 item->destroy ();
746 } 710 }
747} 711}
748 712
749/** 713/**
750 * Global building function 714 * Global building function
776 } 740 }
777 741
778 x = pl->x + freearr_x[dir]; 742 x = pl->x + freearr_x[dir];
779 y = pl->y + freearr_y[dir]; 743 y = pl->y + freearr_y[dir];
780 744
781 if ((1 > x) || (1 > y) || ((MAP_WIDTH (pl->map) - 2) < x) || ((MAP_HEIGHT (pl->map) - 2) < y)) 745 if ((1 > x) || (1 > y) || ((pl->map->width - 2) < x) || ((pl->map->height - 2) < y))
782 { 746 {
783 new_draw_info (NDI_UNIQUE, 0, pl, "Can't build on map edge..."); 747 new_draw_info (NDI_UNIQUE, 0, pl, "Can't build on map edge...");
784 return; 748 return;
785 } 749 }
786 750
793 757
794 tmp = GET_MAP_OB (pl->map, x, y); 758 tmp = GET_MAP_OB (pl->map, x, y);
795 if (!tmp) 759 if (!tmp)
796 { 760 {
797 /* Nothing, meaning player is standing next to an undefined square... */ 761 /* Nothing, meaning player is standing next to an undefined square... */
798 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);
799 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.");
800 return; 764 return;
801 } 765 }
766
802 tmp2 = find_marked_object (pl); 767 tmp2 = find_marked_object (pl);
803 while (tmp) 768 while (tmp)
804 { 769 {
805 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))
806 { 771 {
807 /* The item building function already has it's own special 772 /* The item building function already has it's own special
808 * checks for this 773 * checks for this
809 */ 774 */
810 if ((!tmp2) || (tmp2->subtype != ST_MAT_ITEM)) 775 if ((!tmp2) || (tmp2->subtype != ST_MAT_ITEM))
815 } 780 }
816 tmp = tmp->above; 781 tmp = tmp->above;
817 } 782 }
818 783
819 /* Now we know the square is ok */ 784 /* Now we know the square is ok */
820 builder = pl->contr->ranges[range_builder]; 785 builder = pl->contr->ranged_ob;
821 786
822 if (builder->subtype == ST_BD_REMOVE) 787 if (builder->subtype == ST_BD_REMOVE)
823 /* Remover -> call specific function and bail out */ 788 /* Remover -> call specific function and bail out */
824 { 789 {
825 apply_builder_remove (pl, dir); 790 apply_builder_remove (pl, dir);
893 tmp->msg = book->msg; 858 tmp->msg = book->msg;
894 859
895 if (tmp->invisible) 860 if (tmp->invisible)
896 { 861 {
897 if (book->custom_name != NULL) 862 if (book->custom_name != NULL)
898 {
899 snprintf (buf, sizeof (buf), "talking %s", &book->custom_name); 863 snprintf (buf, sizeof (buf), "talking %s", &book->custom_name);
900 }
901 else 864 else
902 {
903 snprintf (buf, sizeof (buf), "talking %s", &book->name); 865 snprintf (buf, sizeof (buf), "talking %s", &book->name);
904 } 866
905 tmp->name = buf; 867 tmp->name = buf;
906 868
907 if (book->name_pl != NULL) 869 if (book->name_pl != NULL)
908 { 870 {
909 snprintf (buf2, sizeof (buf2), "talking %s", &book->name_pl); 871 snprintf (buf2, sizeof (buf2), "talking %s", &book->name_pl);
911 } 873 }
912 874
913 tmp->face = book->face; 875 tmp->face = book->face;
914 tmp->invisible = 0; 876 tmp->invisible = 0;
915 } 877 }
916 book->remove (); 878
917 book->destroy (0); 879 book->destroy ();
918 return 0; 880 return 0;
919} 881}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines