ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/build_map.C
Revision: 1.45
Committed: Fri Nov 6 13:03:34 2009 UTC (14 years, 6 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.44: +1 -1 lines
Log Message:
make effectively static symbols actually static, part 2

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