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.5 by root, Sun Sep 10 15:59:57 2006 UTC vs.
Revision 1.34 by root, Mon Sep 29 10:20:49 2008 UTC

1
2/* 1/*
3 * static char *rcsid_build_map = 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
4 * "$Id: build_map.C,v 1.5 2006/09/10 15:59:57 root Exp $"; 3 *
5 */ 4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
6
7/*
8 CrossFire, A Multiplayer game for X-windows
9
10 Copyright (C) 2001 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2001,2007 Mark Wedel & Crossfire Development Team
11 Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
12 7 *
13 This program is free software; you can redistribute it and/or modify 8 * Deliantra is free software: you can redistribute it and/or modify
14 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
15 the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version. 11 * (at your option) any later version.
17 12 *
18 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,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details. 16 * GNU General Public License for more details.
22 17 *
23 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
24 along with this program; if not, write to the Free Software 19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 *
26 21 * The authors can be reached via e-mail to <support@deliantra.net>
27 The authors can be reached via e-mail to crossfire-devel@real-time.com
28*/ 22 */
29 23
30#include <global.h> 24#include <global.h>
31#include <living.h> 25#include <living.h>
32#include <spells.h> 26#include <spells.h>
33#include <skills.h> 27#include <skills.h>
36 30
37/** 31/**
38 * Check if objects on a square interfere with building 32 * Check if objects on a square interfere with building
39 */ 33 */
40int 34int
41can_build_over (mapstruct *map, object *tmp, short x, short y) 35can_build_over (maptile *map, object *tmp, short x, short y)
42{ 36{
43 object *ob; 37 object *ob;
44 38
45 ob = GET_MAP_OB (map, x, y); 39 ob = GET_MAP_OB (map, x, y);
46 while (ob) 40 while (ob)
47 { 41 {
48 /* 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 */
49 if (strcmp (ob->arch->name, "rune_mark") && ob->type != FLOOR) 43 if (strcmp (ob->arch->archname, "rune_mark") && ob->type != FLOOR)
50 { 44 {
51 switch (tmp->type) 45 switch (tmp->type)
52 { 46 {
53 case SIGN: 47 case SIGN:
54 case MAGIC_EAR: 48 case MAGIC_EAR:
79 73
80/** 74/**
81 * Erases marking runes at specified location 75 * Erases marking runes at specified location
82 */ 76 */
83void 77void
84remove_marking_runes (mapstruct *map, short x, short y) 78remove_marking_runes (maptile *map, short x, short y)
85{ 79{
86 object *rune; 80 object *rune;
87 object *next; 81 object *next;
88 82
89 rune = GET_MAP_OB (map, x, y); 83 rune = GET_MAP_OB (map, x, y);
90 while (rune) 84 while (rune)
91 { 85 {
92 next = rune->above; 86 next = rune->above;
87
93 if ((rune->type == SIGN) && (!strcmp (rune->arch->name, "rune_mark"))) 88 if (rune->type == SIGN && !strcmp (rune->arch->archname, "rune_mark"))
94 { 89 rune->destroy (true);
95 remove_ob (rune); 90
96 free_object (rune);
97 }
98 rune = next; 91 rune = next;
99 } 92 }
100} 93}
101 94
102/** 95/**
105 * \return 'connected' value with no item, or -1 if failure. 98 * \return 'connected' value with no item, or -1 if failure.
106 * 99 *
107 * Tries 1000 random values, then returns -1. 100 * Tries 1000 random values, then returns -1.
108 */ 101 */
109int 102int
110find_unused_connected_value (mapstruct *map) 103find_unused_connected_value (maptile *map)
111{ 104{
112 int connected = 0; 105 int connected = 0;
113 int itest = 0; 106 int itest = 0;
114 oblinkpt *obp; 107 oblinkpt *obp;
115 108
116 while (itest++ < 1000) 109 while (itest++ < 1000)
117 { 110 {
118 connected = 1 + rand () % 20000; 111 connected = rndm (0x20000000UL) + 0x60000000UL;
112
119 for (obp = map->buttons; obp && (obp->value != connected); obp = obp->next); 113 for (obp = map->buttons; obp && (obp->value != connected); obp = obp->next)
114 ;
120 115
121 if (!obp) 116 if (!obp)
122 return connected; 117 return connected;
123 } 118 }
124 119
125 return -1; 120 return -1;
126} 121}
127
128 122
129/** 123/**
130 * Helper function for door/button/connected item building. 124 * Helper function for door/button/connected item building.
131 * 125 *
132 * Will search the specified spot for a marking rune. 126 * Will search the specified spot for a marking rune.
152 } 146 }
153 147
154 /* Now, find force in player's inventory */ 148 /* Now, find force in player's inventory */
155 force = pl->inv; 149 force = pl->inv;
156 while (force 150 while (force
157 && ((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
158 || (strcmp (force->msg, rune->msg)))) 152 || force->msg != rune->msg))
159 force = force->below; 153 force = force->below;
160 154
161 if (!force) 155 if (!force)
162 /* No force, need to create & insert one */ 156 /* No force, need to create & insert one */
163 { 157 {
168 new_draw_info (NDI_UNIQUE, 0, pl, "Could not create more groups."); 162 new_draw_info (NDI_UNIQUE, 0, pl, "Could not create more groups.");
169 return -1; 163 return -1;
170 } 164 }
171 165
172 force = get_archetype (FORCE_NAME); 166 force = get_archetype (FORCE_NAME);
173 force->speed = 0;
174 update_ob_speed (force);
175 force->slaying = pl->map->path; 167 force->slaying = pl->map->path;
176 force->msg = rune->msg; 168 force->msg = rune->msg;
177 force->path_attuned = connected; 169 force->path_attuned = connected;
170 force->set_speed (0);
178 insert_ob_in_ob (force, pl); 171 insert_ob_in_ob (force, pl);
179 172
180 return connected; 173 return connected;
181 } 174 }
182 175
188 * 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
189 */ 182 */
190object * 183object *
191get_connection_rune (object *pl, short x, short y) 184get_connection_rune (object *pl, short x, short y)
192{ 185{
193 object *rune;
194
195 rune = GET_MAP_OB (pl->map, x, y); 186 object *rune = GET_MAP_OB (pl->map, x, y);
187
196 while (rune && ((rune->type != SIGN) || (strcmp (rune->arch->name, "rune_mark")))) 188 while (rune && ((rune->type != SIGN) || (strcmp (rune->arch->archname, "rune_mark"))))
197 rune = rune->above; 189 rune = rune->above;
190
198 return rune; 191 return rune;
199} 192}
200 193
201/** 194/**
202 * 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
203 */ 196 */
204object * 197object *
205get_msg_book (object *pl, short x, short y) 198get_msg_book (object *pl, short x, short y)
206{ 199{
207 object *book;
208
209 book = GET_MAP_OB (pl->map, x, y); 200 object *book = GET_MAP_OB (pl->map, x, y);
201
210 while (book && (book->type != BOOK)) 202 while (book && (book->type != BOOK))
211 book = book->above; 203 book = book->above;
204
212 return book; 205 return book;
213} 206}
214 207
215/** 208/**
216 * Returns first item of type WALL. 209 * Returns first item of type BUILDABLE_WALL.
217 */ 210 */
218object * 211object *
219get_wall (mapstruct *map, int x, int y) 212get_wall (maptile *map, int x, int y)
220{ 213{
221 object *wall;
222
223 wall = GET_MAP_OB (map, x, y); 214 object *wall = GET_MAP_OB (map, x, y);
215
224 while (wall && (WALL != wall->type)) 216 while (wall && (BUILDABLE_WALL != wall->type))
225 wall = wall->above; 217 wall = wall->above;
226 218
227 return wall; 219 return wall;
228} 220}
229 221
237 * Basically it ensures the correct wall is put where needed. 229 * Basically it ensures the correct wall is put where needed.
238 * 230 *
239 * Note: x & y must be valid map coordinates. 231 * Note: x & y must be valid map coordinates.
240 */ 232 */
241void 233void
242fix_walls (mapstruct *map, int x, int y) 234fix_walls (maptile *map, int x, int y)
243{ 235{
244 int connect;
245 object *wall;
246 char archetype[MAX_BUF]; 236 char archetype[MAX_BUF];
247 char *underscore; 237 char *underscore;
248 uint32 old_flags[4];
249 struct archetype *new_arch; 238 struct archetype *new_arch;
250 int flag;
251 239
252 /* First, find the wall on that spot */ 240 /* First, find the wall on that spot */
253 wall = get_wall (map, x, y); 241 object *wall = get_wall (map, x, y);
254 if (!wall) 242 if (!wall)
255 /* Nothing -> bail out */ 243 /* Nothing -> bail out */
256 return; 244 return;
257 245
258 /* Find base name */ 246 /* Find base name */
259 strcpy (archetype, wall->arch->name); 247 assign (archetype, wall->arch->archname);
260 underscore = strchr (archetype, '_'); 248 underscore = strchr (archetype, '_');
261 249
250 /* search for the first _ before a number */
251 while (underscore && !isdigit (*(underscore + 1)))
252 underscore = strchr (underscore + 1, '_');
253
262 if (!underscore || (!isdigit (*(underscore + 1)))) 254 if (!underscore || !isdigit (*(underscore + 1)))
263 /* Not in a format we can change, bail out */ 255 /* Not in a format we can change, bail out */
264 return; 256 return;
265 257
266 underscore++; 258 underscore++;
267 *underscore = '\0'; 259 *underscore = '\0';
268 260
269 connect = 0; 261 int connect = 0;
270 262
271 if ((x > 0) && get_wall (map, x - 1, y)) 263 if ((x > 0) && get_wall (map, x - 1, y))
272 connect |= 1; 264 connect |= 1;
273 if ((x < MAP_WIDTH (map) - 1) && get_wall (map, x + 1, y)) 265 if ((x < map->width - 1) && get_wall (map, x + 1, y))
274 connect |= 2; 266 connect |= 2;
275 267
276 if ((y > 0) && get_wall (map, x, y - 1)) 268 if ((y > 0) && get_wall (map, x, y - 1))
277 connect |= 4; 269 connect |= 4;
278 270
279 if ((y < MAP_HEIGHT (map) - 1) && get_wall (map, x, y + 1)) 271 if ((y < map->height - 1) && get_wall (map, x, y + 1))
280 connect |= 8; 272 connect |= 8;
281 273
282 switch (connect) 274 switch (connect)
283 { 275 {
284 case 0: 276 case 0:
349 341
350 /* 342 /*
351 * Before anything, make sure the archetype does exist... 343 * Before anything, make sure the archetype does exist...
352 * If not, prolly an error... 344 * If not, prolly an error...
353 */ 345 */
354 new_arch = find_archetype (archetype); 346 new_arch = archetype::find (archetype);
355 347
356 if (!new_arch) 348 if (!new_arch)
357 return; 349 return;
358 350
359 /* Now delete current wall, and insert new one 351 /* Now delete current wall, and insert new one
360 * 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
361 */ 353 */
362 for (flag = 0; flag < 4; flag++) 354 object::flags_t old_flags = wall->flag; // elmex: this is where C++ pays off
363 old_flags[flag] = wall->flags[flag]; 355
364 remove_ob (wall); 356 wall->destroy (true);
365 free_object (wall);
366 357
367 wall = arch_to_object (new_arch); 358 wall = arch_to_object (new_arch);
368 wall->type = WALL; 359 wall->type = BUILDABLE_WALL;
369 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);
370 for (flag = 0; flag < 4; flag++)
371 wall->flags[flag] = old_flags[flag]; 361 wall->flag = old_flags;
372} 362}
373 363
374/** 364/**
375 * \brief Floor building function 365 * \brief Floor building function
376 * 366 *
404 if (tmp) 394 if (tmp)
405 { 395 {
406 while (tmp) 396 while (tmp)
407 { 397 {
408 above = tmp->above; 398 above = tmp->above;
409 if (WALL == tmp->type) 399 if (BUILDABLE_WALL == tmp->type)
410 { 400 {
411 /* 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 */
412 new_wall = tmp->arch; 402 new_wall = tmp->arch;
413 remove_ob (tmp); 403 tmp->destroy (true);
414 free_object (tmp);
415 sprintf (message, "You destroy the wall and redo the floor."); 404 sprintf (message, "You destroy the wall and redo the floor.");
416 } 405 }
417 else if ((FLOOR == tmp->type) || (QUERY_FLAG (tmp, FLAG_IS_FLOOR))) 406 else if ((FLOOR == tmp->type) || (QUERY_FLAG (tmp, FLAG_IS_FLOOR)))
418 { 407 {
419 remove_ob (tmp); 408 tmp->destroy (true);
420 free_object (tmp);
421 floor_removed = 1; 409 floor_removed = 1;
422 } 410 }
423 else 411 else
424 { 412 {
425 if (floor_removed) 413 if (floor_removed)
429 tmp = above; 417 tmp = above;
430 } 418 }
431 } 419 }
432 420
433 /* Now insert our floor */ 421 /* Now insert our floor */
434 new_floor = find_archetype (material->slaying); 422 new_floor = archetype::find (material->slaying);
435 if (!new_floor) 423 if (!new_floor)
436 { 424 {
437 /* Not found, log & bail out */ 425 /* Not found, log & bail out */
438 LOG (llevError, "apply_builder_floor: unable to find archetype %s.\n", &material->slaying); 426 LOG (llevError, "apply_builder_floor: unable to find archetype %s.\n", &material->slaying);
439 return; 427 return;
467 /* Insert wall if exists. Note: if it doesn't, the map is weird... */ 455 /* Insert wall if exists. Note: if it doesn't, the map is weird... */
468 if (new_wall) 456 if (new_wall)
469 { 457 {
470 tmp = arch_to_object (new_wall); 458 tmp = arch_to_object (new_wall);
471 SET_FLAG (tmp, FLAG_IS_BUILDABLE); 459 SET_FLAG (tmp, FLAG_IS_BUILDABLE);
472 tmp->type = WALL; 460 tmp->type = BUILDABLE_WALL;
473 insert_ob_in_map_at (tmp, pl->map, 0, 0, xt, yt); 461 insert_ob_in_map_at (tmp, pl->map, 0, 0, xt, yt);
474 } 462 }
475 } 463 }
476 } 464 }
477 465
485 if (!OUT_OF_REAL_MAP (pl->map, xt, yt)) 473 if (!OUT_OF_REAL_MAP (pl->map, xt, yt))
486 fix_walls (pl->map, xt, yt); 474 fix_walls (pl->map, xt, yt);
487 } 475 }
488 476
489 /* Now remove raw item from inventory */ 477 /* Now remove raw item from inventory */
490 decrease_ob (material); 478 material->decrease ();
491 479
492 /* And tell player about the fix */ 480 /* And tell player about the fix */
493 new_draw_info (NDI_UNIQUE, 0, pl, message); 481 new_draw_info (NDI_UNIQUE, 0, pl, message);
482}
483
484/**
485 * Wall radius fix function
486 */
487void fix_walls_around (maptile *map, int x, int y)
488{
489 for (int xt = x - 1; xt <= x + 1; xt++)
490 for (int yt = y - 1; yt <= y + 1; yt++)
491 {
492 if (OUT_OF_REAL_MAP (map, xt, yt))
493 continue;
494
495 fix_walls (map, xt, yt);
496 }
494} 497}
495 498
496/** 499/**
497 * Wall building function 500 * Wall building function
498 * 501 *
514 /* Grab existing wall, if any */ 517 /* Grab existing wall, if any */
515 current_wall = NULL; 518 current_wall = NULL;
516 tmp = GET_MAP_OB (pl->map, x, y); 519 tmp = GET_MAP_OB (pl->map, x, y);
517 while (tmp && !current_wall) 520 while (tmp && !current_wall)
518 { 521 {
519 if (WALL == tmp->type) 522 if (BUILDABLE_WALL == tmp->type)
520 current_wall = tmp; 523 current_wall = tmp;
521 524
522 tmp = tmp->above; 525 tmp = tmp->above;
523 } 526 }
524 527
525 /* Find the raw wall in inventory */ 528 /* Find the raw wall in inventory */
526 sprintf (message, "You build a wall."); 529 sprintf (message, "You build a wall.");
527 530
528 /* Now we can actually insert the wall */ 531 /* Now we can actually insert the wall */
529 new_wall = find_archetype (material->slaying); 532 new_wall = archetype::find (material->slaying);
530 if (!new_wall) 533 if (!new_wall)
531 { 534 {
532 LOG (llevError, "apply_builder_wall: unable to find archetype %s\n", &material->slaying); 535 LOG (llevError, "apply_builder_wall: unable to find archetype %s\n", &material->slaying);
533 return; 536 return;
534 } 537 }
535 538
536 tmp = arch_to_object (new_wall); 539 tmp = arch_to_object (new_wall);
537 tmp->type = WALL; 540 tmp->type = BUILDABLE_WALL;
538 SET_FLAG (tmp, FLAG_IS_BUILDABLE); 541 SET_FLAG (tmp, FLAG_IS_BUILDABLE);
539 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);
540 543
541 /* If existing wall, remove it, no need to fix other walls */ 544 /* If existing wall, remove it, no need to fix other walls */
542 if (current_wall) 545 if (current_wall)
543 { 546 {
544 remove_ob (current_wall); 547 current_wall->destroy (true);
545 free_object (current_wall);
546 fix_walls (pl->map, x, y); 548 fix_walls (pl->map, x, y);
547 sprintf (message, "You redecorate the wall to better suit your tastes."); 549 sprintf (message, "You redecorate the wall to better suit your tastes.");
548 } 550 }
549 else 551 else
550 { 552 {
558 fix_walls (pl->map, xt, yt); 560 fix_walls (pl->map, xt, yt);
559 } 561 }
560 } 562 }
561 563
562 /* Now remove item from inventory */ 564 /* Now remove item from inventory */
563 decrease_ob (material); 565 material->decrease ();
564 566
565 /* And tell player what happened */ 567 /* And tell player what happened */
566 new_draw_info (NDI_UNIQUE, 0, pl, message); 568 new_draw_info (NDI_UNIQUE, 0, pl, message);
567} 569}
568 570
599 { 601 {
600 new_draw_info (NDI_UNIQUE, 0, pl, "This square has no floor, you can't build here."); 602 new_draw_info (NDI_UNIQUE, 0, pl, "This square has no floor, you can't build here.");
601 return; 603 return;
602 } 604 }
603 /* Create item, set flag, insert in map */ 605 /* Create item, set flag, insert in map */
604 arch = find_archetype (item->slaying); 606 arch = archetype::find (item->slaying);
605 if (!arch) 607 if (!arch)
606 return; 608 return;
607 609
608 tmp = arch_to_object (arch); 610 tmp = arch_to_object (arch);
609 611
610 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)))
611 /* Floor has something on top that interferes with building */ 613 /* Floor has something on top that interferes with building */
612 { 614 {
613 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.");
614 return; 616 return;
615 } 617 }
634 case PEDESTAL: 636 case PEDESTAL:
635 case CF_HANDLE: 637 case CF_HANDLE:
636 case MAGIC_EAR: 638 case MAGIC_EAR:
637 case SIGN: 639 case SIGN:
638 /* Signs don't need a connection, but but magic mouths do. */ 640 /* Signs don't need a connection, but but magic mouths do. */
639 if (tmp->type == SIGN && strcmp (tmp->arch->name, "magic_mouth")) 641 if (tmp->type == SIGN && strcmp (tmp->arch->archname, "magic_mouth"))
640 break; 642 break;
643
641 con_rune = get_connection_rune (pl, x, y); 644 con_rune = get_connection_rune (pl, x, y);
642 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);
643 if (connected == -1) 646 if (connected == -1)
644 { 647 {
645 /* Player already informed of failure by the previous function */ 648 /* Player already informed of failure by the previous function */
646 free_object (tmp); 649 tmp->destroy (true);
647 return; 650 return;
648 } 651 }
652
649 /* Remove marking rune */ 653 /* Remove marking rune */
650 remove_ob (con_rune); 654 con_rune->destroy (true);
651 free_object (con_rune);
652 } 655 }
653 656
654 /* 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 */
655 if ((tmp->type == SIGN) || (tmp->type == MAGIC_EAR)) 658 if ((tmp->type == SIGN) || (tmp->type == MAGIC_EAR))
656 { 659 {
657 if (adjust_sign_msg (pl, x, y, tmp) == -1) 660 if (adjust_sign_msg (pl, x, y, tmp) == -1)
658 { 661 {
659 free_object (tmp); 662 tmp->destroy (true);
660 return; 663 return;
661 } 664 }
662 } 665 }
663 666
664 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);
665 if (connected != 0) 668 if (connected != 0)
666 add_button_link (tmp, pl->map, connected); 669 add_button_link (tmp, pl->map, connected);
667 670
668 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));
669 decrease_ob_nr (item, 1); 672 item->decrease ();
670} 673}
671 674
672/** 675/**
673 * Item remover. 676 * Item remover.
674 * 677 *
687 item = GET_MAP_OB (pl->map, x, y); 690 item = GET_MAP_OB (pl->map, x, y);
688 if (!item) 691 if (!item)
689 { 692 {
690 /* Should not happen with previous tests, but we never know */ 693 /* Should not happen with previous tests, but we never know */
691 new_draw_info (NDI_UNIQUE, 0, pl, "Invalid square."); 694 new_draw_info (NDI_UNIQUE, 0, pl, "Invalid square.");
692 LOG (llevError, "apply_builder_remove: (null) square at (%d, %d, %s)\n", x, y, pl->map->path); 695 LOG (llevError, "apply_builder_remove: (null) square at (%d, %d, %s)\n", x, y, &pl->map->path);
693 return; 696 return;
694 } 697 }
695 698
696 if (item->type == FLOOR || QUERY_FLAG (item, FLAG_IS_FLOOR)) 699 if (item->type == FLOOR || QUERY_FLAG (item, FLAG_IS_FLOOR))
697 item = item->above; 700 item = item->above;
698 701
699 if (!item) 702 if (!item)
700 {
701 new_draw_info (NDI_UNIQUE, 0, pl, "Nothing to remove."); 703 new_draw_info (NDI_UNIQUE, 0, pl, "Nothing to remove.");
702 return; 704 else if (item->type == BUILDABLE_WALL)
703 }
704
705 /* Now remove object, with special cases (buttons & such) */
706 switch (item->type)
707 {
708 case WALL:
709 new_draw_info (NDI_UNIQUE, 0, pl, "Can't remove a wall with that, build a floor."); 705 new_draw_info (NDI_UNIQUE, 0, pl, "Can't remove a wall with that, build a floor.");
710 return; 706 else if (!item->flag [FLAG_IS_BUILDABLE])
711 707 new_draw_info_format (NDI_UNIQUE, 0, pl, "You can't remove the %s, it's not buildable!", query_name (item));
712 case DOOR: 708 else
713 case BUTTON: 709 {
714 case GATE:
715 case TIMED_GATE:
716 case DETECTOR:
717 case PEDESTAL:
718 case CF_HANDLE:
719 case MAGIC_EAR:
720 case SIGN:
721 /* Special case: must unconnect */
722 if (QUERY_FLAG (item, FLAG_IS_LINKED))
723 remove_button_link (item);
724
725 /* Fall through */
726
727 default:
728 /* Remove generic item */
729 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));
730 remove_ob (item); 711 item->destroy (true);
731 free_object (item);
732 } 712 }
733} 713}
734 714
735/** 715/**
736 * Global building function 716 * Global building function
762 } 742 }
763 743
764 x = pl->x + freearr_x[dir]; 744 x = pl->x + freearr_x[dir];
765 y = pl->y + freearr_y[dir]; 745 y = pl->y + freearr_y[dir];
766 746
767 if ((1 > x) || (1 > y) || ((MAP_WIDTH (pl->map) - 2) < x) || ((MAP_HEIGHT (pl->map) - 2) < y)) 747 if ((1 > x) || (1 > y) || ((pl->map->width - 2) < x) || ((pl->map->height - 2) < y))
768 { 748 {
769 new_draw_info (NDI_UNIQUE, 0, pl, "Can't build on map edge..."); 749 new_draw_info (NDI_UNIQUE, 0, pl, "Can't build on map edge...");
770 return; 750 return;
771 } 751 }
772 752
779 759
780 tmp = GET_MAP_OB (pl->map, x, y); 760 tmp = GET_MAP_OB (pl->map, x, y);
781 if (!tmp) 761 if (!tmp)
782 { 762 {
783 /* Nothing, meaning player is standing next to an undefined square... */ 763 /* Nothing, meaning player is standing next to an undefined square... */
784 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);
785 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.");
786 return; 766 return;
787 } 767 }
768
788 tmp2 = find_marked_object (pl); 769 tmp2 = find_marked_object (pl);
789 while (tmp) 770 while (tmp)
790 { 771 {
791 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"))))
792 { 773 {
793 /* The item building function already has it's own special 774 /* The item building function already has it's own special
794 * checks for this 775 * checks for this
795 */ 776 */
796 if ((!tmp2) || (tmp2->subtype != ST_MAT_ITEM)) 777 if ((!tmp2) || (tmp2->subtype != ST_MAT_ITEM))
801 } 782 }
802 tmp = tmp->above; 783 tmp = tmp->above;
803 } 784 }
804 785
805 /* Now we know the square is ok */ 786 /* Now we know the square is ok */
806 builder = pl->contr->ranges[range_builder]; 787 builder = pl->contr->ranged_ob;
807 788
808 if (builder->subtype == ST_BD_REMOVE) 789 if (builder->subtype == ST_BD_REMOVE)
809 /* Remover -> call specific function and bail out */ 790 /* Remover -> call specific function and bail out */
810 { 791 {
811 apply_builder_remove (pl, dir); 792 apply_builder_remove (pl, dir);
879 tmp->msg = book->msg; 860 tmp->msg = book->msg;
880 861
881 if (tmp->invisible) 862 if (tmp->invisible)
882 { 863 {
883 if (book->custom_name != NULL) 864 if (book->custom_name != NULL)
884 {
885 snprintf (buf, sizeof (buf), "talking %s", &book->custom_name); 865 snprintf (buf, sizeof (buf), "talking %s", &book->custom_name);
886 }
887 else 866 else
888 {
889 snprintf (buf, sizeof (buf), "talking %s", &book->name); 867 snprintf (buf, sizeof (buf), "talking %s", &book->name);
890 } 868
891 tmp->name = buf; 869 tmp->name = buf;
892 870
893 if (book->name_pl != NULL) 871 if (book->name_pl != NULL)
894 { 872 {
895 snprintf (buf2, sizeof (buf2), "talking %s", &book->name_pl); 873 snprintf (buf2, sizeof (buf2), "talking %s", &book->name_pl);
897 } 875 }
898 876
899 tmp->face = book->face; 877 tmp->face = book->face;
900 tmp->invisible = 0; 878 tmp->invisible = 0;
901 } 879 }
902 remove_ob (book); 880
903 free_object (book); 881 book->destroy (true);
904 return 0; 882 return 0;
905} 883}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines