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