ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/build_map.C
Revision: 1.8
Committed: Sat Sep 16 22:24:13 2006 UTC (17 years, 9 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.7: +5 -5 lines
Log Message:
mapstruct => maptile
removed many ytypedefs in favor of structure tags

File Contents

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