ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/build_map.C
Revision: 1.41
Committed: Mon Oct 12 21:27:55 2009 UTC (14 years, 8 months ago) by root
Content type: text/plain
Branch: MAIN
CVS Tags: rel-2_82
Changes since 1.40: +2 -2 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 /*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 *
4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2001,2007 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen
7 *
8 * Deliantra is free software: you can redistribute it and/or modify it under
9 * the terms of the Affero GNU General Public License as published by the
10 * Free Software Foundation, either version 3 of the License, or (at your
11 * option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the Affero GNU General Public License
19 * and the GNU General Public License along with this program. If not, see
20 * <http://www.gnu.org/licenses/>.
21 *
22 * The authors can be reached via e-mail to <support@deliantra.net>
23 */
24
25 #include <global.h>
26 #include <living.h>
27 #include <spells.h>
28 #include <skills.h>
29 #include <tod.h>
30 #include <sproto.h>
31
32 /**
33 * Check if objects on a square interfere with building
34 */
35 int
36 can_build_over (maptile *map, object *tmp, short x, short y)
37 {
38 object *ob;
39
40 ob = GET_MAP_OB (map, x, y);
41 while (ob)
42 {
43 /* if ob is not a marking rune or floor, then check special cases */
44 if (ob->arch->archname != shstr_rune_mark && ob->type != FLOOR)
45 {
46 switch (tmp->type)
47 {
48 case SIGN:
49 case MAGIC_EAR:
50 /* Allow signs and magic ears to be built on books */
51 if (ob->type != BOOK)
52 return 0;
53 break;
54 case BUTTON:
55 case DETECTOR:
56 case PEDESTAL:
57 case T_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;
64 }
65 }
66
67 ob = ob->above;
68 }
69 return 1;
70 }
71
72 /**
73 * Erases marking runes at specified location
74 */
75 void
76 remove_marking_runes (maptile *map, short x, short y)
77 {
78 object *rune;
79 object *next;
80
81 rune = GET_MAP_OB (map, x, y);
82 while (rune)
83 {
84 next = rune->above;
85
86 if (rune->type == SIGN && rune->arch->archname == shstr_rune_mark)
87 rune->destroy ();
88
89 rune = next;
90 }
91 }
92
93 /**
94 * Returns an unused value for 'connected'.
95 * \param map: map for which to find a value
96 * \return 'connected' value with no item, or -1 if failure.
97 *
98 * Tries 1000 random values, then returns -1.
99 */
100 static shstr_tmp
101 find_unused_connected_value (maptile *map)
102 {
103 for (int i = 1000; --i; )
104 {
105 char buf[64];
106
107 snprintf (buf, sizeof (buf), "built-%x", rndm (0xf0000000U) + 0x10000000U);
108
109 shstr id (buf);
110
111 if (!map->find_link (id))
112 return id;
113 }
114
115 return shstr_tmp ();
116 }
117
118 /**
119 * Helper function for door/button/connected item building.
120 *
121 * Will search the specified spot for a marking rune.
122 * If not found, returns -1
123 * Else, searches a force in op's inventory matching the map's name
124 * and the rune's text.
125 * If found, returns the connection value associated
126 * else searches a new connection value, and adds the force to the player.
127 */
128 static shstr_tmp
129 find_or_create_connection_for_map (object *pl, short x, short y, object *rune)
130 {
131 object *force;
132
133 if (!rune)
134 rune = get_connection_rune (pl, x, y);
135
136 if (!rune)
137 {
138 new_draw_info (NDI_UNIQUE, 0, pl, "You need to put a marking rune with the group name.");
139 return shstr_tmp ();
140 }
141
142 /* Now, find force in player's inventory */
143 force = pl->inv;
144 while (force
145 && ((force->type != FORCE) || !force->slaying || force->slaying != pl->map->path || !force->msg
146 || force->msg != rune->msg))
147 force = force->below;
148
149 if (!force)
150 /* No force, need to create & insert one */
151 {
152 /* Find unused value */
153 shstr_tmp id = find_unused_connected_value (pl->map);
154
155 if (!id)
156 {
157 new_draw_info (NDI_UNIQUE, 0, pl, "Could not create more groups.");
158 return shstr_tmp ();
159 }
160
161 force = get_archetype (FORCE_NAME);
162 force->slaying = pl->map->path;
163 force->msg = rune->msg;
164 force->race = id;
165 force->set_speed (0);
166
167 insert_ob_in_ob (force, pl);
168
169 return id;
170 }
171
172 /* Found the force, everything's easy. */
173 return force->race;
174 }
175
176 /**
177 * Returns the marking rune on the square, for purposes of building connections
178 */
179 object *
180 get_connection_rune (object *pl, short x, short y)
181 {
182 object *rune = GET_MAP_OB (pl->map, x, y);
183
184 while (rune && (rune->type != SIGN || rune->arch->archname != shstr_rune_mark))
185 rune = rune->above;
186
187 return rune;
188 }
189
190 /**
191 * Returns the book/scroll on the current square, for purposes of building
192 */
193 object *
194 get_msg_book (object *pl, short x, short y)
195 {
196 object *book = GET_MAP_OB (pl->map, x, y);
197
198 while (book && (book->type != BOOK))
199 book = book->above;
200
201 return book;
202 }
203
204 /**
205 * Returns first item of type BUILDABLE_WALL.
206 */
207 object *
208 get_wall (maptile *map, int x, int y)
209 {
210 object *wall = GET_MAP_OB (map, x, y);
211
212 while (wall && (BUILDABLE_WALL != wall->type))
213 wall = wall->above;
214
215 return wall;
216 }
217
218 /**
219 * Fixes walls around specified spot
220 *
221 * \param map is the map
222 * \param x
223 * \param y are the position to fix
224 *
225 * Basically it ensures the correct wall is put where needed.
226 *
227 * Note: x & y must be valid map coordinates.
228 */
229 void
230 fix_walls (maptile *map, int x, int y)
231 {
232 char archetype[MAX_BUF];
233 char *underscore;
234 struct archetype *new_arch;
235
236 /* First, find the wall on that spot */
237 object *wall = get_wall (map, x, y);
238 if (!wall)
239 /* Nothing -> bail out */
240 return;
241
242 /* Find base name */
243 assign (archetype, wall->arch->archname);
244 underscore = strchr (archetype, '_');
245
246 /* search for the first _ before a number */
247 while (underscore && !isdigit (*(underscore + 1)))
248 underscore = strchr (underscore + 1, '_');
249
250 if (!underscore || !isdigit (*(underscore + 1)))
251 /* Not in a format we can change, bail out */
252 return;
253
254 underscore++;
255 *underscore = '\0';
256
257 int connect = 0;
258
259 if ((x > 0) && get_wall (map, x - 1, y))
260 connect |= 1;
261 if ((x < map->width - 1) && get_wall (map, x + 1, y))
262 connect |= 2;
263
264 if ((y > 0) && get_wall (map, x, y - 1))
265 connect |= 4;
266
267 if ((y < map->height - 1) && get_wall (map, x, y + 1))
268 connect |= 8;
269
270 switch (connect)
271 {
272 case 0:
273 strcat (archetype, "0");
274
275 break;
276 case 1:
277 strcat (archetype, "1_3");
278
279 break;
280 case 2:
281 strcat (archetype, "1_4");
282
283 break;
284 case 3:
285 strcat (archetype, "2_1_2");
286
287 break;
288 case 4:
289 strcat (archetype, "1_2");
290
291 break;
292 case 5:
293 strcat (archetype, "2_2_4");
294
295 break;
296 case 6:
297 strcat (archetype, "2_2_1");
298
299 break;
300 case 7:
301 strcat (archetype, "3_1");
302
303 break;
304 case 8:
305 strcat (archetype, "1_1");
306
307 break;
308 case 9:
309 strcat (archetype, "2_2_3");
310
311 break;
312 case 10:
313 strcat (archetype, "2_2_2");
314
315 break;
316 case 11:
317 strcat (archetype, "3_3");
318
319 break;
320 case 12:
321 strcat (archetype, "2_1_1");
322
323 break;
324 case 13:
325 strcat (archetype, "3_4");
326
327 break;
328 case 14:
329 strcat (archetype, "3_2");
330
331 break;
332 case 15:
333 strcat (archetype, "4");
334
335 break;
336 }
337
338 /*
339 * Before anything, make sure the archetype does exist...
340 * If not, prolly an error...
341 */
342 new_arch = archetype::find (archetype);
343
344 if (!new_arch)
345 return;
346
347 /* Now delete current wall, and insert new one
348 * We save flags to avoid any trouble with buildable/non buildable, and so on
349 */
350 object::flags_t old_flags = wall->flag; // elmex: this is where C++ pays off
351
352 wall->destroy ();
353
354 wall = arch_to_object (new_arch);
355 wall->type = BUILDABLE_WALL;
356 insert_ob_in_map_at (wall, map, NULL, INS_ABOVE_FLOOR_ONLY, x, y);
357 wall->flag = old_flags;
358 }
359
360 /**
361 * \brief Floor building function
362 *
363 * Floors can be build:
364 * - on existing floors, with or without a detector/button
365 * - on an existing wall, with or without a floor under it
366 *
367 * Note: this function will inconditionally change squares around (x, y)
368 * so don't call it with x == 0 for instance!
369 */
370 void
371 apply_builder_floor (object *pl, object *material, short x, short y)
372 {
373 object *tmp, *above;
374 object *above_floor; /* Item above floor, if any */
375 struct archetype *new_floor;
376 struct archetype *new_wall;
377 int i, xt, yt, floor_removed;
378 char message[MAX_BUF];
379
380 sprintf (message, "You change the floor to better suit your tastes.");
381
382 /*
383 * Now the building part...
384 * First, remove wall(s) and floor(s) at position x, y
385 */
386 above_floor = NULL;
387 new_wall = NULL;
388 floor_removed = 0;
389 tmp = GET_MAP_OB (pl->map, x, y);
390 if (tmp)
391 {
392 while (tmp)
393 {
394 above = tmp->above;
395 if (BUILDABLE_WALL == tmp->type)
396 {
397 /* There was a wall, remove it & keep its archetype to make new walls */
398 new_wall = tmp->arch;
399 tmp->destroy ();
400 sprintf (message, "You destroy the wall and redo the floor.");
401 }
402 else if ((FLOOR == tmp->type) || (QUERY_FLAG (tmp, FLAG_IS_FLOOR)))
403 {
404 tmp->destroy ();
405 floor_removed = 1;
406 }
407 else
408 {
409 if (floor_removed)
410 {
411 /* This is the first item that was above the floor */
412 above_floor = tmp;
413 floor_removed = 0;
414 }
415 }
416
417 tmp = above;
418 }
419 }
420
421 /* Now insert our floor */
422 new_floor = archetype::find (material->slaying);
423 if (!new_floor)
424 {
425 /* Not found, log & bail out */
426 LOG (llevError, "apply_builder_floor: unable to find archetype %s.\n", &material->slaying);
427 return;
428 }
429
430 tmp = arch_to_object (new_floor);
431 SET_FLAG (tmp, FLAG_IS_BUILDABLE);
432 SET_FLAG (tmp, FLAG_UNIQUE);
433 SET_FLAG (tmp, FLAG_IS_FLOOR);
434 tmp->type = FLOOR;
435 insert_ob_in_map_at (tmp, pl->map, above_floor, above_floor ? INS_BELOW_ORIGINATOR : INS_ON_TOP, x, y);
436
437 /*
438 * Next step: make sure there are either walls or floors around the new square
439 * Since building, you can have: blocking view / floor / wall / nothing
440 */
441 for (i = 1; i <= 8; i++)
442 {
443 xt = x + freearr_x[i];
444 yt = y + freearr_y[i];
445 tmp = GET_MAP_OB (pl->map, xt, yt);
446 if (!tmp)
447 {
448 /* Must insert floor & wall */
449 tmp = arch_to_object (new_floor);
450 /* Better make the floor unique */
451 SET_FLAG (tmp, FLAG_UNIQUE);
452 SET_FLAG (tmp, FLAG_IS_BUILDABLE);
453 tmp->type = FLOOR;
454 insert_ob_in_map_at (tmp, pl->map, 0, 0, xt, yt);
455 /* Insert wall if exists. Note: if it doesn't, the map is weird... */
456 if (new_wall)
457 {
458 tmp = arch_to_object (new_wall);
459 SET_FLAG (tmp, FLAG_IS_BUILDABLE);
460 tmp->type = BUILDABLE_WALL;
461 insert_ob_in_map_at (tmp, pl->map, 0, 0, xt, yt);
462 }
463 }
464 }
465
466 /* Finally fixing walls to ensure nice continuous walls
467 * Note: 2 squares around are checked, because potentially we added walls around the building
468 * spot, so need to check that those new walls connect correctly
469 */
470 for (xt = x - 2; xt <= x + 2; xt++)
471 for (yt = y - 2; yt <= y + 2; yt++)
472 {
473 if (!OUT_OF_REAL_MAP (pl->map, xt, yt))
474 fix_walls (pl->map, xt, yt);
475 }
476
477 /* Now remove raw item from inventory */
478 material->decrease ();
479
480 /* And tell player about the fix */
481 new_draw_info (NDI_UNIQUE, 0, pl, message);
482 }
483
484 /**
485 * Wall radius fix function
486 */
487 void 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 }
497 }
498
499 /**
500 * Wall building function
501 *
502 * Walls can be build:
503 * - on a floor without anything else
504 * - on an existing wall, with or without a floor
505 */
506 void
507 apply_builder_wall (object *pl, object *material, short x, short y)
508 {
509 object *current_wall;
510 object *tmp;
511 int xt, yt;
512 struct archetype *new_wall;
513 char message[MAX_BUF];
514
515 remove_marking_runes (pl->map, x, y);
516
517 /* Grab existing wall, if any */
518 current_wall = NULL;
519 tmp = GET_MAP_OB (pl->map, x, y);
520 while (tmp && !current_wall)
521 {
522 if (BUILDABLE_WALL == tmp->type)
523 current_wall = tmp;
524
525 tmp = tmp->above;
526 }
527
528 /* Find the raw wall in inventory */
529 sprintf (message, "You build a wall.");
530
531 /* Now we can actually insert the wall */
532 new_wall = archetype::find (material->slaying);
533 if (!new_wall)
534 {
535 LOG (llevError, "apply_builder_wall: unable to find archetype %s\n", &material->slaying);
536 return;
537 }
538
539 tmp = arch_to_object (new_wall);
540 tmp->type = BUILDABLE_WALL;
541 SET_FLAG (tmp, FLAG_IS_BUILDABLE);
542 insert_ob_in_map_at (tmp, pl->map, 0, INS_ABOVE_FLOOR_ONLY, x, y);
543
544 /* If existing wall, remove it, no need to fix other walls */
545 if (current_wall)
546 {
547 current_wall->destroy ();
548 fix_walls (pl->map, x, y);
549 sprintf (message, "You redecorate the wall to better suit your tastes.");
550 }
551 else
552 {
553 /* Else fix all walls around */
554 for (xt = x - 1; xt <= x + 1; xt++)
555 for (yt = y - 1; yt <= y + 1; yt++)
556 {
557 if (OUT_OF_REAL_MAP (pl->map, xt, yt))
558 continue;
559
560 fix_walls (pl->map, xt, yt);
561 }
562 }
563
564 /* Now remove item from inventory */
565 material->decrease ();
566
567 /* And tell player what happened */
568 new_draw_info (NDI_UNIQUE, 0, pl, message);
569 }
570
571 /**
572 * Generic item builder.
573 *
574 * Item must be put on a square with a floor, you can have something under.
575 * Archetype of created object is item->slaying (raw material).
576 * Type of inserted item is tested for specific cases (doors & such).
577 * Item is inserted above the floor, unless Str == 1 (only for detectors i guess)
578 */
579 void
580 apply_builder_item (object *pl, object *item, short x, short y)
581 {
582 object *tmp;
583 struct archetype *arch;
584 int insert_flag;
585 object *floor;
586 object *con_rune;
587
588 /* Find floor */
589 floor = GET_MAP_OB (pl->map, x, y);
590 if (!floor)
591 {
592 new_draw_info (NDI_UNIQUE, 0, pl, "Invalid square.");
593 return;
594 }
595
596 while (floor && (floor->type != FLOOR) && (!QUERY_FLAG (floor, FLAG_IS_FLOOR)))
597 floor = floor->above;
598
599 if (!floor)
600 {
601 new_draw_info (NDI_UNIQUE, 0, pl, "This square has no floor, you can't build here.");
602 return;
603 }
604 /* Create item, set flag, insert in map */
605 arch = archetype::find (item->slaying);
606 if (!arch)
607 return;
608
609 tmp = arch_to_object (arch);
610
611 if (!floor->flag[FLAG_IS_BUILDABLE] || (floor->above) && (!can_build_over (pl->map, tmp, x, y)))
612 /* Floor has something on top that interferes with building */
613 {
614 new_draw_info (NDI_UNIQUE, 0, pl, "You can't build here.");
615 return;
616 }
617
618 SET_FLAG (tmp, FLAG_IS_BUILDABLE);
619 SET_FLAG (tmp, FLAG_NO_PICK);
620
621 /*
622 * Str 1 is a flag that the item [pedestal] should go below the floor.
623 * Items under the floor on non-unique maps will not be saved,
624 * so make the item itself unique in this situation.
625 */
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
630 shstr_tmp connected;
631
632 switch (tmp->type)
633 {
634 case DOOR:
635 case GATE:
636 case BUTTON:
637 case DETECTOR:
638 case TIMED_GATE:
639 case PEDESTAL:
640 case T_HANDLE:
641 case MAGIC_EAR:
642 case SIGN:
643 /* Signs don't need a connection, but but magic mouths do. */
644 if (tmp->type == SIGN && tmp->arch->archname != shstr_magic_mouth)
645 break;
646
647 con_rune = get_connection_rune (pl, x, y);
648 connected = find_or_create_connection_for_map (pl, x, y, con_rune);
649 if (!connected)
650 {
651 /* Player already informed of failure by the previous function */
652 tmp->destroy ();
653 return;
654 }
655
656 /* Remove marking rune */
657 con_rune->destroy ();
658 }
659
660 /* For magic mouths/ears, and signs, take the msg from a book of scroll */
661 if ((tmp->type == SIGN) || (tmp->type == MAGIC_EAR))
662 {
663 if (adjust_sign_msg (pl, x, y, tmp) == -1)
664 {
665 tmp->destroy ();
666 return;
667 }
668 }
669
670 insert_ob_in_map_at (tmp, pl->map, floor, insert_flag, x, y);
671 if (connected)
672 tmp->add_link (pl->map, connected);
673
674 new_draw_info_format (NDI_UNIQUE, 0, pl, "You build the %s", query_name (tmp));
675 item->decrease ();
676 }
677
678 /**
679 * Item remover.
680 *
681 * Removes first buildable item, either under or above the floor
682 */
683 void
684 apply_builder_remove (object *pl, int dir)
685 {
686 object *item;
687 short x, y;
688
689 x = pl->x + freearr_x[dir];
690 y = pl->y + freearr_y[dir];
691
692 /* Check square */
693 item = GET_MAP_OB (pl->map, x, y);
694 if (!item)
695 {
696 /* Should not happen with previous tests, but we never know */
697 new_draw_info (NDI_UNIQUE, 0, pl, "Invalid square.");
698 LOG (llevError, "apply_builder_remove: (null) square at (%d, %d, %s)\n", x, y, &pl->map->path);
699 return;
700 }
701
702 if (item->type == FLOOR || QUERY_FLAG (item, FLAG_IS_FLOOR))
703 item = item->above;
704
705 if (!item)
706 new_draw_info (NDI_UNIQUE, 0, pl, "Nothing to remove.");
707 else if (item->type == BUILDABLE_WALL)
708 new_draw_info (NDI_UNIQUE, 0, pl, "Can't remove a wall with that, build a floor.");
709 else if (!item->flag [FLAG_IS_BUILDABLE])
710 new_draw_info_format (NDI_UNIQUE, 0, pl, "You can't remove the %s, it's not buildable!", query_name (item));
711 else
712 {
713 new_draw_info_format (NDI_UNIQUE, 0, pl, "You remove the %s", query_name (item));
714 item->destroy ();
715 }
716 }
717
718 /**
719 * Global building function
720 *
721 * This is the general map building function. Called when the player 'fires' a builder
722 * or remover object.
723 */
724 void
725 apply_map_builder (object *pl, int dir)
726 {
727 object *builder;
728 object *tmp;
729 object *tmp2;
730 short x, y;
731
732 if (!pl->type == PLAYER)
733 return;
734
735 /*if ( !player->map->unique )
736 {
737 new_draw_info( NDI_UNIQUE, 0, player, "You can't build outside a unique map." );
738 return;
739 } */
740
741 if (dir == 0)
742 {
743 new_draw_info (NDI_UNIQUE, 0, pl, "You can't build or destroy under yourself.");
744 return;
745 }
746
747 x = pl->x + freearr_x[dir];
748 y = pl->y + freearr_y[dir];
749
750 if ((1 > x) || (1 > y) || ((pl->map->width - 2) < x) || ((pl->map->height - 2) < y))
751 {
752 new_draw_info (NDI_UNIQUE, 0, pl, "Can't build on map edge...");
753 return;
754 }
755
756 /*
757 * Check specified square
758 * The square must have only buildable items
759 * Exception: marking runes are all right,
760 * since they are used for special things like connecting doors / buttons
761 */
762
763 tmp = GET_MAP_OB (pl->map, x, y);
764 if (!tmp)
765 {
766 /* Nothing, meaning player is standing next to an undefined square... */
767 LOG (llevError, "apply_map_builder: undefined square at (%d, %d, %s)\n", x, y, &pl->map->path);
768 new_draw_info (NDI_UNIQUE, 0, pl, "You'd better not build here, it looks weird.");
769 return;
770 }
771
772 tmp2 = find_marked_object (pl);
773 while (tmp)
774 {
775 if (!QUERY_FLAG (tmp, FLAG_IS_BUILDABLE) && (tmp->type != SIGN || tmp->arch->archname != shstr_rune_mark))
776 {
777 /* The item building function already has it's own special
778 * checks for this
779 */
780 if ((!tmp2) || (tmp2->subtype != ST_MAT_ITEM))
781 {
782 new_draw_info (NDI_UNIQUE, 0, pl, "You can't build here.");
783 return;
784 }
785 }
786 tmp = tmp->above;
787 }
788
789 /* Now we know the square is ok */
790 builder = pl->contr->ranged_ob;
791
792 if (builder->subtype == ST_BD_REMOVE)
793 /* Remover -> call specific function and bail out */
794 {
795 apply_builder_remove (pl, dir);
796 return;
797 }
798
799 if (builder->subtype == ST_BD_BUILD)
800 /*
801 * Builder.
802 * Find marked item to build, call specific function
803 */
804 {
805 tmp = tmp2;
806 if (!tmp)
807 {
808 new_draw_info (NDI_UNIQUE, 0, pl, "You need to mark raw materials to use.");
809 return;
810 }
811
812 if (tmp->type != MATERIAL)
813 {
814 new_draw_info (NDI_UNIQUE, 0, pl, "You can't use the marked item to build.");
815 return;
816 }
817
818 switch (tmp->subtype)
819 {
820 case ST_MAT_FLOOR:
821 apply_builder_floor (pl, tmp, x, y);
822 return;
823
824 case ST_MAT_WALL:
825 apply_builder_wall (pl, tmp, x, y);
826 return;
827
828 case ST_MAT_ITEM:
829 apply_builder_item (pl, tmp, x, y);
830 return;
831
832 default:
833 new_draw_info (NDI_UNIQUE, 0, pl, "Don't know how to apply this material, sorry.");
834 LOG (llevError, "apply_map_builder: invalid material subtype %d\n", tmp->subtype);
835 return;
836 }
837 }
838
839 /* Here, it means the builder has an invalid type */
840 new_draw_info (NDI_UNIQUE, 0, pl, "Don't know how to apply this tool, sorry.");
841 LOG (llevError, "apply_map_builder: invalid builder subtype %d\n", builder->subtype);
842 }
843
844 /**
845 * Make the built object inherit the msg of books that are used with it.
846 * For objects already invisible (i.e. magic mouths & ears), also make it
847 * it inherit the face and the name with "talking " prepended.
848 */
849 int
850 adjust_sign_msg (object *pl, short x, short y, object *tmp)
851 {
852 object *book;
853 char buf[MAX_BUF];
854 char buf2[MAX_BUF];
855
856 book = get_msg_book (pl, x, y);
857 if (!book)
858 {
859 new_draw_info (NDI_UNIQUE, 0, pl, "You need to put a book or scroll with the message.");
860 return -1;
861 }
862
863 tmp->msg = book->msg;
864
865 if (tmp->invisible)
866 {
867 if (book->custom_name != NULL)
868 snprintf (buf, sizeof (buf), "talking %s", &book->custom_name);
869 else
870 snprintf (buf, sizeof (buf), "talking %s", &book->name);
871
872 tmp->name = buf;
873
874 if (book->name_pl != NULL)
875 {
876 snprintf (buf2, sizeof (buf2), "talking %s", &book->name_pl);
877 tmp->name_pl = buf2;
878 }
879
880 tmp->face = book->face;
881 tmp->invisible = 0;
882 }
883
884 book->destroy ();
885 return 0;
886 }