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.40 by root, Mon Oct 12 14:00:59 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 it under
8 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
9 the Free Software Foundation; either version 2 of the License, or 10 * Free Software Foundation, either version 3 of the License, or (at your
10 (at your option) any later version. 11 * 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 Affero GNU General Public License
18 along with this program; if not, write to the Free Software 19 * and the GNU General Public License along with this program. If not, see
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 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>
27#include <skills.h> 28#include <skills.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->name, "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
82 80
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;
85
87 if ((rune->type == SIGN) && (!strcmp (rune->arch->name, "rune_mark"))) 86 if (rune->type == SIGN && rune->arch->archname == shstr_rune_mark)
88 {
89 rune->remove ();
90 rune->destroy (0); 87 rune->destroy ();
91 } 88
92 rune = next; 89 rune = next;
93 } 90 }
94} 91}
95 92
96/** 93/**
98 * \param map: map for which to find a value 95 * \param map: map for which to find a value
99 * \return 'connected' value with no item, or -1 if failure. 96 * \return 'connected' value with no item, or -1 if failure.
100 * 97 *
101 * Tries 1000 random values, then returns -1. 98 * Tries 1000 random values, then returns -1.
102 */ 99 */
103int 100static shstr_tmp
104find_unused_connected_value (maptile *map) 101find_unused_connected_value (maptile *map)
105{ 102{
106 int connected = 0; 103 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 } 104 {
105 char buf[64];
118 106
119 return -1; 107 snprintf (buf, sizeof (buf), "built-%x", rndm (0xf0000000U) + 0x10000000U);
120}
121 108
109 shstr id (buf);
110
111 if (!map->find_link (id))
112 return id;
113 }
114
115 return shstr_tmp ();
116}
122 117
123/** 118/**
124 * Helper function for door/button/connected item building. 119 * Helper function for door/button/connected item building.
125 * 120 *
126 * Will search the specified spot for a marking rune. 121 * Will search the specified spot for a marking rune.
128 * 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
129 * and the rune's text. 124 * and the rune's text.
130 * If found, returns the connection value associated 125 * If found, returns the connection value associated
131 * 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.
132 */ 127 */
133int 128static shstr_tmp
134find_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)
135{ 130{
136 object *force; 131 object *force;
137 int connected;
138 132
139 if (!rune) 133 if (!rune)
140 rune = get_connection_rune (pl, x, y); 134 rune = get_connection_rune (pl, x, y);
141 135
142 if (!rune) 136 if (!rune)
143 { 137 {
144 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.");
145 return -1; 139 return shstr_tmp ();
146 } 140 }
147 141
148 /* Now, find force in player's inventory */ 142 /* Now, find force in player's inventory */
149 force = pl->inv; 143 force = pl->inv;
150 while (force 144 while (force
151 && ((force->type != FORCE) || (!force->slaying) || (strcmp (force->slaying, pl->map->path)) || (!force->msg) 145 && ((force->type != FORCE) || !force->slaying || force->slaying != pl->map->path || !force->msg
152 || (strcmp (force->msg, rune->msg)))) 146 || force->msg != rune->msg))
153 force = force->below; 147 force = force->below;
154 148
155 if (!force) 149 if (!force)
156 /* No force, need to create & insert one */ 150 /* No force, need to create & insert one */
157 { 151 {
158 /* Find unused value */ 152 /* Find unused value */
159 connected = find_unused_connected_value (pl->map); 153 shstr_tmp id = find_unused_connected_value (pl->map);
160 if (connected == -1) 154
155 if (!id)
161 { 156 {
162 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.");
163 return -1; 158 return shstr_tmp ();
164 } 159 }
165 160
166 force = get_archetype (FORCE_NAME); 161 force = get_archetype (FORCE_NAME);
167 force->speed = 0;
168 update_ob_speed (force);
169 force->slaying = pl->map->path; 162 force->slaying = pl->map->path;
170 force->msg = rune->msg; 163 force->msg = rune->msg;
171 force->path_attuned = connected; 164 force->race = id;
165 force->set_speed (0);
166
172 insert_ob_in_ob (force, pl); 167 insert_ob_in_ob (force, pl);
173 168
174 return connected; 169 return id;
175 } 170 }
176 171
177 /* Found the force, everything's easy. */ 172 /* Found the force, everything's easy. */
178 return force->path_attuned; 173 return force->race;
179} 174}
180 175
181/** 176/**
182 * 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
183 */ 178 */
184object * 179object *
185get_connection_rune (object *pl, short x, short y) 180get_connection_rune (object *pl, short x, short y)
186{ 181{
187 object *rune;
188
189 rune = GET_MAP_OB (pl->map, x, y); 182 object *rune = GET_MAP_OB (pl->map, x, y);
183
190 while (rune && ((rune->type != SIGN) || (strcmp (rune->arch->name, "rune_mark")))) 184 while (rune && (rune->type != SIGN || rune->arch->archname != shstr_rune_mark))
191 rune = rune->above; 185 rune = rune->above;
186
192 return rune; 187 return rune;
193} 188}
194 189
195/** 190/**
196 * 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
197 */ 192 */
198object * 193object *
199get_msg_book (object *pl, short x, short y) 194get_msg_book (object *pl, short x, short y)
200{ 195{
201 object *book;
202
203 book = GET_MAP_OB (pl->map, x, y); 196 object *book = GET_MAP_OB (pl->map, x, y);
197
204 while (book && (book->type != BOOK)) 198 while (book && (book->type != BOOK))
205 book = book->above; 199 book = book->above;
200
206 return book; 201 return book;
207} 202}
208 203
209/** 204/**
210 * Returns first item of type WALL. 205 * Returns first item of type BUILDABLE_WALL.
211 */ 206 */
212object * 207object *
213get_wall (maptile *map, int x, int y) 208get_wall (maptile *map, int x, int y)
214{ 209{
215 object *wall;
216
217 wall = GET_MAP_OB (map, x, y); 210 object *wall = GET_MAP_OB (map, x, y);
211
218 while (wall && (WALL != wall->type)) 212 while (wall && (BUILDABLE_WALL != wall->type))
219 wall = wall->above; 213 wall = wall->above;
220 214
221 return wall; 215 return wall;
222} 216}
223 217
233 * Note: x & y must be valid map coordinates. 227 * Note: x & y must be valid map coordinates.
234 */ 228 */
235void 229void
236fix_walls (maptile *map, int x, int y) 230fix_walls (maptile *map, int x, int y)
237{ 231{
238 int connect;
239 object *wall;
240 char archetype[MAX_BUF]; 232 char archetype[MAX_BUF];
241 char *underscore; 233 char *underscore;
242 uint32 old_flags[4];
243 struct archetype *new_arch; 234 struct archetype *new_arch;
244 int flag;
245
246 235
247 /* First, find the wall on that spot */ 236 /* First, find the wall on that spot */
248 wall = get_wall (map, x, y); 237 object *wall = get_wall (map, x, y);
249 if (!wall) 238 if (!wall)
250 /* Nothing -> bail out */ 239 /* Nothing -> bail out */
251 return; 240 return;
252 241
253 /* Find base name */ 242 /* Find base name */
254 strcpy (archetype, wall->arch->name); 243 assign (archetype, wall->arch->archname);
255 underscore = strchr (archetype, '_'); 244 underscore = strchr (archetype, '_');
256 245
257 /* search for the first _ before a number */ 246 /* search for the first _ before a number */
258 while (underscore && !isdigit (*(underscore + 1))) 247 while (underscore && !isdigit (*(underscore + 1)))
259 underscore = strchr (underscore + 1, '_'); 248 underscore = strchr (underscore + 1, '_');
263 return; 252 return;
264 253
265 underscore++; 254 underscore++;
266 *underscore = '\0'; 255 *underscore = '\0';
267 256
268 connect = 0; 257 int connect = 0;
269 258
270 if ((x > 0) && get_wall (map, x - 1, y)) 259 if ((x > 0) && get_wall (map, x - 1, y))
271 connect |= 1; 260 connect |= 1;
272 if ((x < MAP_WIDTH (map) - 1) && get_wall (map, x + 1, y)) 261 if ((x < map->width - 1) && get_wall (map, x + 1, y))
273 connect |= 2; 262 connect |= 2;
274 263
275 if ((y > 0) && get_wall (map, x, y - 1)) 264 if ((y > 0) && get_wall (map, x, y - 1))
276 connect |= 4; 265 connect |= 4;
277 266
278 if ((y < MAP_HEIGHT (map) - 1) && get_wall (map, x, y + 1)) 267 if ((y < map->height - 1) && get_wall (map, x, y + 1))
279 connect |= 8; 268 connect |= 8;
280 269
281 switch (connect) 270 switch (connect)
282 { 271 {
283 case 0: 272 case 0:
356 return; 345 return;
357 346
358 /* Now delete current wall, and insert new one 347 /* Now delete current wall, and insert new one
359 * We save flags to avoid any trouble with buildable/non buildable, and so on 348 * We save flags to avoid any trouble with buildable/non buildable, and so on
360 */ 349 */
361 for (flag = 0; flag < 4; flag++) 350 object::flags_t old_flags = wall->flag; // elmex: this is where C++ pays off
362 old_flags[flag] = wall->flags[flag]; 351
363 wall->remove ();
364 wall->destroy (0); 352 wall->destroy ();
365 353
366 wall = arch_to_object (new_arch); 354 wall = arch_to_object (new_arch);
367 wall->type = WALL; 355 wall->type = BUILDABLE_WALL;
368 insert_ob_in_map_at (wall, map, NULL, INS_ABOVE_FLOOR_ONLY, x, y); 356 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]; 357 wall->flag = old_flags;
371} 358}
372 359
373/** 360/**
374 * \brief Floor building function 361 * \brief Floor building function
375 * 362 *
403 if (tmp) 390 if (tmp)
404 { 391 {
405 while (tmp) 392 while (tmp)
406 { 393 {
407 above = tmp->above; 394 above = tmp->above;
408 if (WALL == tmp->type) 395 if (BUILDABLE_WALL == tmp->type)
409 { 396 {
410 /* There was a wall, remove it & keep its archetype to make new walls */ 397 /* There was a wall, remove it & keep its archetype to make new walls */
411 new_wall = tmp->arch; 398 new_wall = tmp->arch;
412 tmp->remove ();
413 tmp->destroy (0); 399 tmp->destroy ();
414 sprintf (message, "You destroy the wall and redo the floor."); 400 sprintf (message, "You destroy the wall and redo the floor.");
415 } 401 }
416 else if ((FLOOR == tmp->type) || (QUERY_FLAG (tmp, FLAG_IS_FLOOR))) 402 else if ((FLOOR == tmp->type) || (QUERY_FLAG (tmp, FLAG_IS_FLOOR)))
417 { 403 {
418 tmp->remove ();
419 tmp->destroy (0); 404 tmp->destroy ();
420 floor_removed = 1; 405 floor_removed = 1;
421 } 406 }
422 else 407 else
423 { 408 {
424 if (floor_removed) 409 if (floor_removed)
410 {
411 /* This is the first item that was above the floor */
425 above_floor = tmp; 412 above_floor = tmp;
413 floor_removed = 0;
414 }
426 } 415 }
427 416
428 tmp = above; 417 tmp = above;
429 } 418 }
430 } 419 }
466 /* 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... */
467 if (new_wall) 456 if (new_wall)
468 { 457 {
469 tmp = arch_to_object (new_wall); 458 tmp = arch_to_object (new_wall);
470 SET_FLAG (tmp, FLAG_IS_BUILDABLE); 459 SET_FLAG (tmp, FLAG_IS_BUILDABLE);
471 tmp->type = WALL; 460 tmp->type = BUILDABLE_WALL;
472 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);
473 } 462 }
474 } 463 }
475 } 464 }
476 465
484 if (!OUT_OF_REAL_MAP (pl->map, xt, yt)) 473 if (!OUT_OF_REAL_MAP (pl->map, xt, yt))
485 fix_walls (pl->map, xt, yt); 474 fix_walls (pl->map, xt, yt);
486 } 475 }
487 476
488 /* Now remove raw item from inventory */ 477 /* Now remove raw item from inventory */
489 decrease_ob (material); 478 material->decrease ();
490 479
491 /* And tell player about the fix */ 480 /* And tell player about the fix */
492 new_draw_info (NDI_UNIQUE, 0, pl, message); 481 new_draw_info (NDI_UNIQUE, 0, pl, message);
493} 482}
494 483
528 /* Grab existing wall, if any */ 517 /* Grab existing wall, if any */
529 current_wall = NULL; 518 current_wall = NULL;
530 tmp = GET_MAP_OB (pl->map, x, y); 519 tmp = GET_MAP_OB (pl->map, x, y);
531 while (tmp && !current_wall) 520 while (tmp && !current_wall)
532 { 521 {
533 if (WALL == tmp->type) 522 if (BUILDABLE_WALL == tmp->type)
534 current_wall = tmp; 523 current_wall = tmp;
535 524
536 tmp = tmp->above; 525 tmp = tmp->above;
537 } 526 }
538 527
546 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);
547 return; 536 return;
548 } 537 }
549 538
550 tmp = arch_to_object (new_wall); 539 tmp = arch_to_object (new_wall);
551 tmp->type = WALL; 540 tmp->type = BUILDABLE_WALL;
552 SET_FLAG (tmp, FLAG_IS_BUILDABLE); 541 SET_FLAG (tmp, FLAG_IS_BUILDABLE);
553 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);
554 543
555 /* If existing wall, remove it, no need to fix other walls */ 544 /* If existing wall, remove it, no need to fix other walls */
556 if (current_wall) 545 if (current_wall)
557 { 546 {
558 current_wall->remove ();
559 current_wall->destroy (0); 547 current_wall->destroy ();
560 fix_walls (pl->map, x, y); 548 fix_walls (pl->map, x, y);
561 sprintf (message, "You redecorate the wall to better suit your tastes."); 549 sprintf (message, "You redecorate the wall to better suit your tastes.");
562 } 550 }
563 else 551 else
564 { 552 {
572 fix_walls (pl->map, xt, yt); 560 fix_walls (pl->map, xt, yt);
573 } 561 }
574 } 562 }
575 563
576 /* Now remove item from inventory */ 564 /* Now remove item from inventory */
577 decrease_ob (material); 565 material->decrease ();
578 566
579 /* And tell player what happened */ 567 /* And tell player what happened */
580 new_draw_info (NDI_UNIQUE, 0, pl, message); 568 new_draw_info (NDI_UNIQUE, 0, pl, message);
581} 569}
582 570
594 object *tmp; 582 object *tmp;
595 struct archetype *arch; 583 struct archetype *arch;
596 int insert_flag; 584 int insert_flag;
597 object *floor; 585 object *floor;
598 object *con_rune; 586 object *con_rune;
599 int connected;
600 587
601 /* Find floor */ 588 /* Find floor */
602 floor = GET_MAP_OB (pl->map, x, y); 589 floor = GET_MAP_OB (pl->map, x, y);
603 if (!floor) 590 if (!floor)
604 { 591 {
619 if (!arch) 606 if (!arch)
620 return; 607 return;
621 608
622 tmp = arch_to_object (arch); 609 tmp = arch_to_object (arch);
623 610
624 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)))
625 /* Floor has something on top that interferes with building */ 612 /* Floor has something on top that interferes with building */
626 { 613 {
627 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.");
628 return; 615 return;
629 } 616 }
630 617
631 SET_FLAG (tmp, FLAG_IS_BUILDABLE); 618 SET_FLAG (tmp, FLAG_IS_BUILDABLE);
632 SET_FLAG (tmp, FLAG_NO_PICK); 619 SET_FLAG (tmp, FLAG_NO_PICK);
633 620
634 /* 621 /*
635 * 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.
636 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.
637 */ 625 */
638 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);
639 629
640 connected = 0; 630 shstr_tmp connected;
631
641 switch (tmp->type) 632 switch (tmp->type)
642 { 633 {
643 case DOOR: 634 case DOOR:
644 case GATE: 635 case GATE:
645 case BUTTON: 636 case BUTTON:
646 case DETECTOR: 637 case DETECTOR:
647 case TIMED_GATE: 638 case TIMED_GATE:
648 case PEDESTAL: 639 case PEDESTAL:
649 case CF_HANDLE: 640 case CF_HANDLE:
650 case MAGIC_EAR: 641 case MAGIC_EAR:
651 case SIGN: 642 case SIGN:
652 /* Signs don't need a connection, but but magic mouths do. */ 643 /* Signs don't need a connection, but but magic mouths do. */
653 if (tmp->type == SIGN && strcmp (tmp->arch->name, "magic_mouth")) 644 if (tmp->type == SIGN && tmp->arch->archname != shstr_magic_mouth)
654 break; 645 break;
646
655 con_rune = get_connection_rune (pl, x, y); 647 con_rune = get_connection_rune (pl, x, y);
656 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);
657 if (connected == -1) 649 if (!connected)
658 { 650 {
659 /* Player already informed of failure by the previous function */ 651 /* Player already informed of failure by the previous function */
660 tmp->destroy (0); 652 tmp->destroy ();
661 return; 653 return;
662 } 654 }
655
663 /* Remove marking rune */ 656 /* Remove marking rune */
664 con_rune->remove ();
665 con_rune->destroy (0); 657 con_rune->destroy ();
666 } 658 }
667 659
668 /* 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 */
669 if ((tmp->type == SIGN) || (tmp->type == MAGIC_EAR)) 661 if ((tmp->type == SIGN) || (tmp->type == MAGIC_EAR))
670 { 662 {
671 if (adjust_sign_msg (pl, x, y, tmp) == -1) 663 if (adjust_sign_msg (pl, x, y, tmp) == -1)
672 { 664 {
673 tmp->destroy (0); 665 tmp->destroy ();
674 return; 666 return;
675 } 667 }
676 } 668 }
677 669
678 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);
679 if (connected != 0) 671 if (connected)
680 add_button_link (tmp, pl->map, connected); 672 tmp->add_link (pl->map, connected);
681 673
682 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));
683 decrease_ob_nr (item, 1); 675 item->decrease ();
684} 676}
685 677
686/** 678/**
687 * Item remover. 679 * Item remover.
688 * 680 *
701 item = GET_MAP_OB (pl->map, x, y); 693 item = GET_MAP_OB (pl->map, x, y);
702 if (!item) 694 if (!item)
703 { 695 {
704 /* Should not happen with previous tests, but we never know */ 696 /* Should not happen with previous tests, but we never know */
705 new_draw_info (NDI_UNIQUE, 0, pl, "Invalid square."); 697 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); 698 LOG (llevError, "apply_builder_remove: (null) square at (%d, %d, %s)\n", x, y, &pl->map->path);
707 return; 699 return;
708 } 700 }
709 701
710 if (item->type == FLOOR || QUERY_FLAG (item, FLAG_IS_FLOOR)) 702 if (item->type == FLOOR || QUERY_FLAG (item, FLAG_IS_FLOOR))
711 item = item->above; 703 item = item->above;
712 704
713 if (!item) 705 if (!item)
714 {
715 new_draw_info (NDI_UNIQUE, 0, pl, "Nothing to remove."); 706 new_draw_info (NDI_UNIQUE, 0, pl, "Nothing to remove.");
716 return; 707 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."); 708 new_draw_info (NDI_UNIQUE, 0, pl, "Can't remove a wall with that, build a floor.");
724 return; 709 else if (!item->flag [FLAG_IS_BUILDABLE])
725 710 new_draw_info_format (NDI_UNIQUE, 0, pl, "You can't remove the %s, it's not buildable!", query_name (item));
726 case DOOR: 711 else
727 case BUTTON: 712 {
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)); 713 new_draw_info_format (NDI_UNIQUE, 0, pl, "You remove the %s", query_name (item));
744 item->remove ();
745 item->destroy (0); 714 item->destroy ();
746 } 715 }
747} 716}
748 717
749/** 718/**
750 * Global building function 719 * Global building function
776 } 745 }
777 746
778 x = pl->x + freearr_x[dir]; 747 x = pl->x + freearr_x[dir];
779 y = pl->y + freearr_y[dir]; 748 y = pl->y + freearr_y[dir];
780 749
781 if ((1 > x) || (1 > y) || ((MAP_WIDTH (pl->map) - 2) < x) || ((MAP_HEIGHT (pl->map) - 2) < y)) 750 if ((1 > x) || (1 > y) || ((pl->map->width - 2) < x) || ((pl->map->height - 2) < y))
782 { 751 {
783 new_draw_info (NDI_UNIQUE, 0, pl, "Can't build on map edge..."); 752 new_draw_info (NDI_UNIQUE, 0, pl, "Can't build on map edge...");
784 return; 753 return;
785 } 754 }
786 755
793 762
794 tmp = GET_MAP_OB (pl->map, x, y); 763 tmp = GET_MAP_OB (pl->map, x, y);
795 if (!tmp) 764 if (!tmp)
796 { 765 {
797 /* Nothing, meaning player is standing next to an undefined square... */ 766 /* 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); 767 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."); 768 new_draw_info (NDI_UNIQUE, 0, pl, "You'd better not build here, it looks weird.");
800 return; 769 return;
801 } 770 }
771
802 tmp2 = find_marked_object (pl); 772 tmp2 = find_marked_object (pl);
803 while (tmp) 773 while (tmp)
804 { 774 {
805 if (!QUERY_FLAG (tmp, FLAG_IS_BUILDABLE) && ((tmp->type != SIGN) || (strcmp (tmp->arch->name, "rune_mark")))) 775 if (!QUERY_FLAG (tmp, FLAG_IS_BUILDABLE) && (tmp->type != SIGN || tmp->arch->archname != shstr_rune_mark))
806 { 776 {
807 /* The item building function already has it's own special 777 /* The item building function already has it's own special
808 * checks for this 778 * checks for this
809 */ 779 */
810 if ((!tmp2) || (tmp2->subtype != ST_MAT_ITEM)) 780 if ((!tmp2) || (tmp2->subtype != ST_MAT_ITEM))
815 } 785 }
816 tmp = tmp->above; 786 tmp = tmp->above;
817 } 787 }
818 788
819 /* Now we know the square is ok */ 789 /* Now we know the square is ok */
820 builder = pl->contr->ranges[range_builder]; 790 builder = pl->contr->ranged_ob;
821 791
822 if (builder->subtype == ST_BD_REMOVE) 792 if (builder->subtype == ST_BD_REMOVE)
823 /* Remover -> call specific function and bail out */ 793 /* Remover -> call specific function and bail out */
824 { 794 {
825 apply_builder_remove (pl, dir); 795 apply_builder_remove (pl, dir);
893 tmp->msg = book->msg; 863 tmp->msg = book->msg;
894 864
895 if (tmp->invisible) 865 if (tmp->invisible)
896 { 866 {
897 if (book->custom_name != NULL) 867 if (book->custom_name != NULL)
898 {
899 snprintf (buf, sizeof (buf), "talking %s", &book->custom_name); 868 snprintf (buf, sizeof (buf), "talking %s", &book->custom_name);
900 }
901 else 869 else
902 {
903 snprintf (buf, sizeof (buf), "talking %s", &book->name); 870 snprintf (buf, sizeof (buf), "talking %s", &book->name);
904 } 871
905 tmp->name = buf; 872 tmp->name = buf;
906 873
907 if (book->name_pl != NULL) 874 if (book->name_pl != NULL)
908 { 875 {
909 snprintf (buf2, sizeof (buf2), "talking %s", &book->name_pl); 876 snprintf (buf2, sizeof (buf2), "talking %s", &book->name_pl);
911 } 878 }
912 879
913 tmp->face = book->face; 880 tmp->face = book->face;
914 tmp->invisible = 0; 881 tmp->invisible = 0;
915 } 882 }
916 book->remove (); 883
917 book->destroy (0); 884 book->destroy ();
918 return 0; 885 return 0;
919} 886}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines