ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/build_map.C
Revision: 1.36
Committed: Thu Jan 1 11:41:17 2009 UTC (15 years, 4 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.35: +27 -27 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
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your 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 GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 *
21 * The authors can be reached via e-mail to <support@deliantra.net>
22 */
23
24 #include <global.h>
25 #include <living.h>
26 #include <spells.h>
27 #include <skills.h>
28 #include <tod.h>
29 #include <sproto.h>
30
31 /**
32 * Check if objects on a square interfere with building
33 */
34 int
35 can_build_over (maptile *map, object *tmp, short x, short y)
36 {
37 object *ob;
38
39 ob = GET_MAP_OB (map, x, y);
40 while (ob)
41 {
42 /* if ob is not a marking rune or floor, then check special cases */
43 if (ob->arch->archname != shstr_rune_mark && ob->type != FLOOR)
44 {
45 switch (tmp->type)
46 {
47 case SIGN:
48 case MAGIC_EAR:
49 /* Allow signs and magic ears to be built on books */
50 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;
67 }
68 }
69 ob = ob->above;
70 }
71 return 1;
72 }
73
74 /**
75 * Erases marking runes at specified location
76 */
77 void
78 remove_marking_runes (maptile *map, short x, short y)
79 {
80 object *rune;
81 object *next;
82
83 rune = GET_MAP_OB (map, x, y);
84 while (rune)
85 {
86 next = rune->above;
87
88 if (rune->type == SIGN && rune->arch->archname == shstr_rune_mark)
89 rune->destroy ();
90
91 rune = next;
92 }
93 }
94
95 /**
96 * Returns an unused value for 'connected'.
97 * \param map: map for which to find a value
98 * \return 'connected' value with no item, or -1 if failure.
99 *
100 * Tries 1000 random values, then returns -1.
101 */
102 int
103 find_unused_connected_value (maptile *map)
104 {
105 int connected = 0;
106 int itest = 0;
107 oblinkpt *obp;
108
109 while (itest++ < 1000)
110 {
111 connected = rndm (0x20000000UL) + 0x60000000UL;
112
113 for (obp = map->buttons; obp && (obp->value != connected); obp = obp->next)
114 ;
115
116 if (!obp)
117 return connected;
118 }
119
120 return -1;
121 }
122
123 /**
124 * Helper function for door/button/connected item building.
125 *
126 * Will search the specified spot for a marking rune.
127 * If not found, returns -1
128 * Else, searches a force in op's inventory matching the map's name
129 * and the rune's text.
130 * If found, returns the connection value associated
131 * else searches a new connection value, and adds the force to the player.
132 */
133 int
134 find_or_create_connection_for_map (object *pl, short x, short y, object *rune)
135 {
136 object *force;
137 int connected;
138
139 if (!rune)
140 rune = get_connection_rune (pl, x, y);
141
142 if (!rune)
143 {
144 new_draw_info (NDI_UNIQUE, 0, pl, "You need to put a marking rune with the group name.");
145 return -1;
146 }
147
148 /* Now, find force in player's inventory */
149 force = pl->inv;
150 while (force
151 && ((force->type != FORCE) || !force->slaying || force->slaying != pl->map->path || !force->msg
152 || force->msg != rune->msg))
153 force = force->below;
154
155 if (!force)
156 /* No force, need to create & insert one */
157 {
158 /* Find unused value */
159 connected = find_unused_connected_value (pl->map);
160 if (connected == -1)
161 {
162 new_draw_info (NDI_UNIQUE, 0, pl, "Could not create more groups.");
163 return -1;
164 }
165
166 force = get_archetype (FORCE_NAME);
167 force->slaying = pl->map->path;
168 force->msg = rune->msg;
169 force->path_attuned = connected;
170 force->set_speed (0);
171 insert_ob_in_ob (force, pl);
172
173 return connected;
174 }
175
176 /* Found the force, everything's easy. */
177 return force->path_attuned;
178 }
179
180 /**
181 * Returns the marking rune on the square, for purposes of building connections
182 */
183 object *
184 get_connection_rune (object *pl, short x, short y)
185 {
186 object *rune = GET_MAP_OB (pl->map, x, y);
187
188 while (rune && (rune->type != SIGN || rune->arch->archname != shstr_rune_mark))
189 rune = rune->above;
190
191 return rune;
192 }
193
194 /**
195 * Returns the book/scroll on the current square, for purposes of building
196 */
197 object *
198 get_msg_book (object *pl, short x, short y)
199 {
200 object *book = GET_MAP_OB (pl->map, x, y);
201
202 while (book && (book->type != BOOK))
203 book = book->above;
204
205 return book;
206 }
207
208 /**
209 * Returns first item of type BUILDABLE_WALL.
210 */
211 object *
212 get_wall (maptile *map, int x, int y)
213 {
214 object *wall = GET_MAP_OB (map, x, y);
215
216 while (wall && (BUILDABLE_WALL != wall->type))
217 wall = wall->above;
218
219 return wall;
220 }
221
222 /**
223 * Fixes walls around specified spot
224 *
225 * \param map is the map
226 * \param x
227 * \param y are the position to fix
228 *
229 * Basically it ensures the correct wall is put where needed.
230 *
231 * Note: x & y must be valid map coordinates.
232 */
233 void
234 fix_walls (maptile *map, int x, int y)
235 {
236 char archetype[MAX_BUF];
237 char *underscore;
238 struct archetype *new_arch;
239
240 /* First, find the wall on that spot */
241 object *wall = get_wall (map, x, y);
242 if (!wall)
243 /* Nothing -> bail out */
244 return;
245
246 /* Find base name */
247 assign (archetype, wall->arch->archname);
248 underscore = strchr (archetype, '_');
249
250 /* search for the first _ before a number */
251 while (underscore && !isdigit (*(underscore + 1)))
252 underscore = strchr (underscore + 1, '_');
253
254 if (!underscore || !isdigit (*(underscore + 1)))
255 /* Not in a format we can change, bail out */
256 return;
257
258 underscore++;
259 *underscore = '\0';
260
261 int connect = 0;
262
263 if ((x > 0) && get_wall (map, x - 1, y))
264 connect |= 1;
265 if ((x < map->width - 1) && get_wall (map, x + 1, y))
266 connect |= 2;
267
268 if ((y > 0) && get_wall (map, x, y - 1))
269 connect |= 4;
270
271 if ((y < map->height - 1) && get_wall (map, x, y + 1))
272 connect |= 8;
273
274 switch (connect)
275 {
276 case 0:
277 strcat (archetype, "0");
278
279 break;
280 case 1:
281 strcat (archetype, "1_3");
282
283 break;
284 case 2:
285 strcat (archetype, "1_4");
286
287 break;
288 case 3:
289 strcat (archetype, "2_1_2");
290
291 break;
292 case 4:
293 strcat (archetype, "1_2");
294
295 break;
296 case 5:
297 strcat (archetype, "2_2_4");
298
299 break;
300 case 6:
301 strcat (archetype, "2_2_1");
302
303 break;
304 case 7:
305 strcat (archetype, "3_1");
306
307 break;
308 case 8:
309 strcat (archetype, "1_1");
310
311 break;
312 case 9:
313 strcat (archetype, "2_2_3");
314
315 break;
316 case 10:
317 strcat (archetype, "2_2_2");
318
319 break;
320 case 11:
321 strcat (archetype, "3_3");
322
323 break;
324 case 12:
325 strcat (archetype, "2_1_1");
326
327 break;
328 case 13:
329 strcat (archetype, "3_4");
330
331 break;
332 case 14:
333 strcat (archetype, "3_2");
334
335 break;
336 case 15:
337 strcat (archetype, "4");
338
339 break;
340 }
341
342 /*
343 * Before anything, make sure the archetype does exist...
344 * If not, prolly an error...
345 */
346 new_arch = archetype::find (archetype);
347
348 if (!new_arch)
349 return;
350
351 /* Now delete current wall, and insert new one
352 * We save flags to avoid any trouble with buildable/non buildable, and so on
353 */
354 object::flags_t old_flags = wall->flag; // elmex: this is where C++ pays off
355
356 wall->destroy ();
357
358 wall = arch_to_object (new_arch);
359 wall->type = BUILDABLE_WALL;
360 insert_ob_in_map_at (wall, map, NULL, INS_ABOVE_FLOOR_ONLY, x, y);
361 wall->flag = old_flags;
362 }
363
364 /**
365 * \brief Floor building function
366 *
367 * Floors can be build:
368 * - on existing floors, with or without a detector/button
369 * - on an existing wall, with or without a floor under it
370 *
371 * Note: this function will inconditionally change squares around (x, y)
372 * so don't call it with x == 0 for instance!
373 */
374 void
375 apply_builder_floor (object *pl, object *material, short x, short y)
376 {
377 object *tmp, *above;
378 object *above_floor; /* Item above floor, if any */
379 struct archetype *new_floor;
380 struct archetype *new_wall;
381 int i, xt, yt, floor_removed;
382 char message[MAX_BUF];
383
384 sprintf (message, "You change the floor to better suit your tastes.");
385
386 /*
387 * Now the building part...
388 * First, remove wall(s) and floor(s) at position x, y
389 */
390 above_floor = NULL;
391 new_wall = NULL;
392 floor_removed = 0;
393 tmp = GET_MAP_OB (pl->map, x, y);
394 if (tmp)
395 {
396 while (tmp)
397 {
398 above = tmp->above;
399 if (BUILDABLE_WALL == tmp->type)
400 {
401 /* There was a wall, remove it & keep its archetype to make new walls */
402 new_wall = tmp->arch;
403 tmp->destroy ();
404 sprintf (message, "You destroy the wall and redo the floor.");
405 }
406 else if ((FLOOR == tmp->type) || (QUERY_FLAG (tmp, FLAG_IS_FLOOR)))
407 {
408 tmp->destroy ();
409 floor_removed = 1;
410 }
411 else
412 {
413 if (floor_removed)
414 above_floor = tmp;
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 int connected;
588
589 /* Find floor */
590 floor = GET_MAP_OB (pl->map, x, y);
591 if (!floor)
592 {
593 new_draw_info (NDI_UNIQUE, 0, pl, "Invalid square.");
594 return;
595 }
596
597 while (floor && (floor->type != FLOOR) && (!QUERY_FLAG (floor, FLAG_IS_FLOOR)))
598 floor = floor->above;
599
600 if (!floor)
601 {
602 new_draw_info (NDI_UNIQUE, 0, pl, "This square has no floor, you can't build here.");
603 return;
604 }
605 /* Create item, set flag, insert in map */
606 arch = archetype::find (item->slaying);
607 if (!arch)
608 return;
609
610 tmp = arch_to_object (arch);
611
612 if (!floor->flag[FLAG_IS_BUILDABLE] || (floor->above) && (!can_build_over (pl->map, tmp, x, y)))
613 /* Floor has something on top that interferes with building */
614 {
615 new_draw_info (NDI_UNIQUE, 0, pl, "You can't build here.");
616 return;
617 }
618
619 SET_FLAG (tmp, FLAG_IS_BUILDABLE);
620 SET_FLAG (tmp, FLAG_NO_PICK);
621
622 /*
623 * This doesn't work on non unique maps. pedestals under floor will not be saved...
624 insert_flag = ( item->stats.Str == 1 ) ? INS_BELOW_ORIGINATOR : INS_ABOVE_FLOOR_ONLY;
625 */
626 insert_flag = INS_ABOVE_FLOOR_ONLY;
627
628 connected = 0;
629 switch (tmp->type)
630 {
631 case DOOR:
632 case GATE:
633 case BUTTON:
634 case DETECTOR:
635 case TIMED_GATE:
636 case PEDESTAL:
637 case CF_HANDLE:
638 case MAGIC_EAR:
639 case SIGN:
640 /* Signs don't need a connection, but but magic mouths do. */
641 if (tmp->type == SIGN && tmp->arch->archname != shstr_magic_mouth)
642 break;
643
644 con_rune = get_connection_rune (pl, x, y);
645 connected = find_or_create_connection_for_map (pl, x, y, con_rune);
646 if (connected == -1)
647 {
648 /* Player already informed of failure by the previous function */
649 tmp->destroy ();
650 return;
651 }
652
653 /* Remove marking rune */
654 con_rune->destroy ();
655 }
656
657 /* For magic mouths/ears, and signs, take the msg from a book of scroll */
658 if ((tmp->type == SIGN) || (tmp->type == MAGIC_EAR))
659 {
660 if (adjust_sign_msg (pl, x, y, tmp) == -1)
661 {
662 tmp->destroy ();
663 return;
664 }
665 }
666
667 insert_ob_in_map_at (tmp, pl->map, floor, insert_flag, x, y);
668 if (connected != 0)
669 add_button_link (tmp, pl->map, connected);
670
671 new_draw_info_format (NDI_UNIQUE, 0, pl, "You build the %s", query_name (tmp));
672 item->decrease ();
673 }
674
675 /**
676 * Item remover.
677 *
678 * Removes first buildable item, either under or above the floor
679 */
680 void
681 apply_builder_remove (object *pl, int dir)
682 {
683 object *item;
684 short x, y;
685
686 x = pl->x + freearr_x[dir];
687 y = pl->y + freearr_y[dir];
688
689 /* Check square */
690 item = GET_MAP_OB (pl->map, x, y);
691 if (!item)
692 {
693 /* Should not happen with previous tests, but we never know */
694 new_draw_info (NDI_UNIQUE, 0, pl, "Invalid square.");
695 LOG (llevError, "apply_builder_remove: (null) square at (%d, %d, %s)\n", x, y, &pl->map->path);
696 return;
697 }
698
699 if (item->type == FLOOR || QUERY_FLAG (item, FLAG_IS_FLOOR))
700 item = item->above;
701
702 if (!item)
703 new_draw_info (NDI_UNIQUE, 0, pl, "Nothing to remove.");
704 else if (item->type == BUILDABLE_WALL)
705 new_draw_info (NDI_UNIQUE, 0, pl, "Can't remove a wall with that, build a floor.");
706 else if (!item->flag [FLAG_IS_BUILDABLE])
707 new_draw_info_format (NDI_UNIQUE, 0, pl, "You can't remove the %s, it's not buildable!", query_name (item));
708 else
709 {
710 new_draw_info_format (NDI_UNIQUE, 0, pl, "You remove the %s", query_name (item));
711 item->destroy ();
712 }
713 }
714
715 /**
716 * Global building function
717 *
718 * This is the general map building function. Called when the player 'fires' a builder
719 * or remover object.
720 */
721 void
722 apply_map_builder (object *pl, int dir)
723 {
724 object *builder;
725 object *tmp;
726 object *tmp2;
727 short x, y;
728
729 if (!pl->type == PLAYER)
730 return;
731
732 /*if ( !player->map->unique )
733 {
734 new_draw_info( NDI_UNIQUE, 0, player, "You can't build outside a unique map." );
735 return;
736 } */
737
738 if (dir == 0)
739 {
740 new_draw_info (NDI_UNIQUE, 0, pl, "You can't build or destroy under yourself.");
741 return;
742 }
743
744 x = pl->x + freearr_x[dir];
745 y = pl->y + freearr_y[dir];
746
747 if ((1 > x) || (1 > y) || ((pl->map->width - 2) < x) || ((pl->map->height - 2) < y))
748 {
749 new_draw_info (NDI_UNIQUE, 0, pl, "Can't build on map edge...");
750 return;
751 }
752
753 /*
754 * Check specified square
755 * The square must have only buildable items
756 * Exception: marking runes are all right,
757 * since they are used for special things like connecting doors / buttons
758 */
759
760 tmp = GET_MAP_OB (pl->map, x, y);
761 if (!tmp)
762 {
763 /* Nothing, meaning player is standing next to an undefined square... */
764 LOG (llevError, "apply_map_builder: undefined square at (%d, %d, %s)\n", x, y, &pl->map->path);
765 new_draw_info (NDI_UNIQUE, 0, pl, "You'd better not build here, it looks weird.");
766 return;
767 }
768
769 tmp2 = find_marked_object (pl);
770 while (tmp)
771 {
772 if (!QUERY_FLAG (tmp, FLAG_IS_BUILDABLE) && (tmp->type != SIGN || tmp->arch->archname != shstr_rune_mark))
773 {
774 /* The item building function already has it's own special
775 * checks for this
776 */
777 if ((!tmp2) || (tmp2->subtype != ST_MAT_ITEM))
778 {
779 new_draw_info (NDI_UNIQUE, 0, pl, "You can't build here.");
780 return;
781 }
782 }
783 tmp = tmp->above;
784 }
785
786 /* Now we know the square is ok */
787 builder = pl->contr->ranged_ob;
788
789 if (builder->subtype == ST_BD_REMOVE)
790 /* Remover -> call specific function and bail out */
791 {
792 apply_builder_remove (pl, dir);
793 return;
794 }
795
796 if (builder->subtype == ST_BD_BUILD)
797 /*
798 * Builder.
799 * Find marked item to build, call specific function
800 */
801 {
802 tmp = tmp2;
803 if (!tmp)
804 {
805 new_draw_info (NDI_UNIQUE, 0, pl, "You need to mark raw materials to use.");
806 return;
807 }
808
809 if (tmp->type != MATERIAL)
810 {
811 new_draw_info (NDI_UNIQUE, 0, pl, "You can't use the marked item to build.");
812 return;
813 }
814
815 switch (tmp->subtype)
816 {
817 case ST_MAT_FLOOR:
818 apply_builder_floor (pl, tmp, x, y);
819 return;
820
821 case ST_MAT_WALL:
822 apply_builder_wall (pl, tmp, x, y);
823 return;
824
825 case ST_MAT_ITEM:
826 apply_builder_item (pl, tmp, x, y);
827 return;
828
829 default:
830 new_draw_info (NDI_UNIQUE, 0, pl, "Don't know how to apply this material, sorry.");
831 LOG (llevError, "apply_map_builder: invalid material subtype %d\n", tmp->subtype);
832 return;
833 }
834 }
835
836 /* Here, it means the builder has an invalid type */
837 new_draw_info (NDI_UNIQUE, 0, pl, "Don't know how to apply this tool, sorry.");
838 LOG (llevError, "apply_map_builder: invalid builder subtype %d\n", builder->subtype);
839 }
840
841 /**
842 * Make the built object inherit the msg of books that are used with it.
843 * For objects already invisible (i.e. magic mouths & ears), also make it
844 * it inherit the face and the name with "talking " prepended.
845 */
846 int
847 adjust_sign_msg (object *pl, short x, short y, object *tmp)
848 {
849 object *book;
850 char buf[MAX_BUF];
851 char buf2[MAX_BUF];
852
853 book = get_msg_book (pl, x, y);
854 if (!book)
855 {
856 new_draw_info (NDI_UNIQUE, 0, pl, "You need to put a book or scroll with the message.");
857 return -1;
858 }
859
860 tmp->msg = book->msg;
861
862 if (tmp->invisible)
863 {
864 if (book->custom_name != NULL)
865 snprintf (buf, sizeof (buf), "talking %s", &book->custom_name);
866 else
867 snprintf (buf, sizeof (buf), "talking %s", &book->name);
868
869 tmp->name = buf;
870
871 if (book->name_pl != NULL)
872 {
873 snprintf (buf2, sizeof (buf2), "talking %s", &book->name_pl);
874 tmp->name_pl = buf2;
875 }
876
877 tmp->face = book->face;
878 tmp->invisible = 0;
879 }
880
881 book->destroy ();
882 return 0;
883 }