1 | /* |
1 | /* |
2 | * This file is part of Crossfire TRT, the Roguelike Realtime MORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team |
4 | * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2001,2007 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2001,2007 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
7 | * |
7 | * |
8 | * Crossfire TRT is free software: you can redistribute it and/or modify |
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 |
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 |
10 | * the Free Software Foundation, either version 3 of the License, or |
11 | * (at your option) any later version. |
11 | * (at your option) any later version. |
12 | * |
12 | * |
13 | * This program is distributed in the hope that it will be useful, |
13 | * This program is distributed in the hope that it will be useful, |
… | |
… | |
16 | * GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
17 | * |
17 | * |
18 | * You should have received a copy of the GNU General Public License |
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/>. |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
20 | * |
20 | * |
21 | * The authors can be reached via e-mail to <crossfire@schmorp.de> |
21 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | */ |
22 | */ |
23 | |
23 | |
24 | #include <global.h> |
24 | #include <global.h> |
25 | #include <living.h> |
25 | #include <living.h> |
26 | #include <spells.h> |
26 | #include <spells.h> |
… | |
… | |
38 | |
38 | |
39 | ob = GET_MAP_OB (map, x, y); |
39 | ob = GET_MAP_OB (map, x, y); |
40 | while (ob) |
40 | while (ob) |
41 | { |
41 | { |
42 | /* if ob is not a marking rune or floor, then check special cases */ |
42 | /* if ob is not a marking rune or floor, then check special cases */ |
43 | if (strcmp (ob->arch->archname, "rune_mark") && ob->type != FLOOR) |
43 | if (ob->arch->archname != shstr_rune_mark && ob->type != FLOOR) |
44 | { |
44 | { |
45 | switch (tmp->type) |
45 | switch (tmp->type) |
46 | { |
46 | { |
47 | case SIGN: |
47 | case SIGN: |
48 | case MAGIC_EAR: |
48 | case MAGIC_EAR: |
… | |
… | |
83 | rune = GET_MAP_OB (map, x, y); |
83 | rune = GET_MAP_OB (map, x, y); |
84 | while (rune) |
84 | while (rune) |
85 | { |
85 | { |
86 | next = rune->above; |
86 | next = rune->above; |
87 | |
87 | |
88 | if ((rune->type == SIGN) && (!strcmp (rune->arch->archname, "rune_mark"))) |
88 | if (rune->type == SIGN && rune->arch->archname == shstr_rune_mark) |
89 | rune->destroy (); |
89 | rune->destroy (); |
90 | |
90 | |
91 | rune = next; |
91 | rune = next; |
92 | } |
92 | } |
93 | } |
93 | } |
… | |
… | |
106 | int itest = 0; |
106 | int itest = 0; |
107 | oblinkpt *obp; |
107 | oblinkpt *obp; |
108 | |
108 | |
109 | while (itest++ < 1000) |
109 | while (itest++ < 1000) |
110 | { |
110 | { |
111 | connected = 1 + rand () % 20000; |
111 | connected = rndm (0x20000000UL) + 0x60000000UL; |
|
|
112 | |
112 | for (obp = map->buttons; obp && (obp->value != connected); obp = obp->next); |
113 | for (obp = map->buttons; obp && (obp->value != connected); obp = obp->next) |
|
|
114 | ; |
113 | |
115 | |
114 | if (!obp) |
116 | if (!obp) |
115 | return connected; |
117 | return connected; |
116 | } |
118 | } |
117 | |
119 | |
118 | return -1; |
120 | return -1; |
119 | } |
121 | } |
120 | |
|
|
121 | |
122 | |
122 | /** |
123 | /** |
123 | * Helper function for door/button/connected item building. |
124 | * Helper function for door/button/connected item building. |
124 | * |
125 | * |
125 | * Will search the specified spot for a marking rune. |
126 | * Will search the specified spot for a marking rune. |
… | |
… | |
180 | * Returns the marking rune on the square, for purposes of building connections |
181 | * Returns the marking rune on the square, for purposes of building connections |
181 | */ |
182 | */ |
182 | object * |
183 | object * |
183 | get_connection_rune (object *pl, short x, short y) |
184 | get_connection_rune (object *pl, short x, short y) |
184 | { |
185 | { |
185 | object *rune; |
|
|
186 | |
|
|
187 | rune = GET_MAP_OB (pl->map, x, y); |
186 | object *rune = GET_MAP_OB (pl->map, x, y); |
|
|
187 | |
188 | while (rune && ((rune->type != SIGN) || (strcmp (rune->arch->archname, "rune_mark")))) |
188 | while (rune && (rune->type != SIGN || rune->arch->archname != shstr_rune_mark)) |
189 | rune = rune->above; |
189 | rune = rune->above; |
|
|
190 | |
190 | return rune; |
191 | return rune; |
191 | } |
192 | } |
192 | |
193 | |
193 | /** |
194 | /** |
194 | * Returns the book/scroll on the current square, for purposes of building |
195 | * Returns the book/scroll on the current square, for purposes of building |
195 | */ |
196 | */ |
196 | object * |
197 | object * |
197 | get_msg_book (object *pl, short x, short y) |
198 | get_msg_book (object *pl, short x, short y) |
198 | { |
199 | { |
199 | object *book; |
|
|
200 | |
|
|
201 | book = GET_MAP_OB (pl->map, x, y); |
200 | object *book = GET_MAP_OB (pl->map, x, y); |
|
|
201 | |
202 | while (book && (book->type != BOOK)) |
202 | while (book && (book->type != BOOK)) |
203 | book = book->above; |
203 | book = book->above; |
|
|
204 | |
204 | return book; |
205 | return book; |
205 | } |
206 | } |
206 | |
207 | |
207 | /** |
208 | /** |
208 | * Returns first item of type BUILDABLE_WALL. |
209 | * Returns first item of type BUILDABLE_WALL. |
209 | */ |
210 | */ |
210 | object * |
211 | object * |
211 | get_wall (maptile *map, int x, int y) |
212 | get_wall (maptile *map, int x, int y) |
212 | { |
213 | { |
213 | object *wall; |
|
|
214 | |
|
|
215 | wall = GET_MAP_OB (map, x, y); |
214 | object *wall = GET_MAP_OB (map, x, y); |
|
|
215 | |
216 | while (wall && (BUILDABLE_WALL != wall->type)) |
216 | while (wall && (BUILDABLE_WALL != wall->type)) |
217 | wall = wall->above; |
217 | wall = wall->above; |
218 | |
218 | |
219 | return wall; |
219 | return wall; |
220 | } |
220 | } |
… | |
… | |
231 | * Note: x & y must be valid map coordinates. |
231 | * Note: x & y must be valid map coordinates. |
232 | */ |
232 | */ |
233 | void |
233 | void |
234 | fix_walls (maptile *map, int x, int y) |
234 | fix_walls (maptile *map, int x, int y) |
235 | { |
235 | { |
236 | object *wall; |
|
|
237 | char archetype[MAX_BUF]; |
236 | char archetype[MAX_BUF]; |
238 | char *underscore; |
237 | char *underscore; |
239 | struct archetype *new_arch; |
238 | struct archetype *new_arch; |
240 | |
239 | |
241 | |
|
|
242 | /* First, find the wall on that spot */ |
240 | /* First, find the wall on that spot */ |
243 | wall = get_wall (map, x, y); |
241 | object *wall = get_wall (map, x, y); |
244 | if (!wall) |
242 | if (!wall) |
245 | /* Nothing -> bail out */ |
243 | /* Nothing -> bail out */ |
246 | return; |
244 | return; |
247 | |
245 | |
248 | /* Find base name */ |
246 | /* Find base name */ |
… | |
… | |
475 | if (!OUT_OF_REAL_MAP (pl->map, xt, yt)) |
473 | if (!OUT_OF_REAL_MAP (pl->map, xt, yt)) |
476 | fix_walls (pl->map, xt, yt); |
474 | fix_walls (pl->map, xt, yt); |
477 | } |
475 | } |
478 | |
476 | |
479 | /* Now remove raw item from inventory */ |
477 | /* Now remove raw item from inventory */ |
480 | decrease_ob (material); |
478 | material->decrease (); |
481 | |
479 | |
482 | /* And tell player about the fix */ |
480 | /* And tell player about the fix */ |
483 | new_draw_info (NDI_UNIQUE, 0, pl, message); |
481 | new_draw_info (NDI_UNIQUE, 0, pl, message); |
484 | } |
482 | } |
485 | |
483 | |
… | |
… | |
562 | fix_walls (pl->map, xt, yt); |
560 | fix_walls (pl->map, xt, yt); |
563 | } |
561 | } |
564 | } |
562 | } |
565 | |
563 | |
566 | /* Now remove item from inventory */ |
564 | /* Now remove item from inventory */ |
567 | decrease_ob (material); |
565 | material->decrease (); |
568 | |
566 | |
569 | /* And tell player what happened */ |
567 | /* And tell player what happened */ |
570 | new_draw_info (NDI_UNIQUE, 0, pl, message); |
568 | new_draw_info (NDI_UNIQUE, 0, pl, message); |
571 | } |
569 | } |
572 | |
570 | |
… | |
… | |
609 | if (!arch) |
607 | if (!arch) |
610 | return; |
608 | return; |
611 | |
609 | |
612 | tmp = arch_to_object (arch); |
610 | tmp = arch_to_object (arch); |
613 | |
611 | |
614 | if ((floor->above) && (!can_build_over (pl->map, tmp, x, y))) |
612 | if (!floor->flag[FLAG_IS_BUILDABLE] || (floor->above) && (!can_build_over (pl->map, tmp, x, y))) |
615 | /* Floor has something on top that interferes with building */ |
613 | /* Floor has something on top that interferes with building */ |
616 | { |
614 | { |
617 | new_draw_info (NDI_UNIQUE, 0, pl, "You can't build here."); |
615 | new_draw_info (NDI_UNIQUE, 0, pl, "You can't build here."); |
618 | return; |
616 | return; |
619 | } |
617 | } |
… | |
… | |
628 | insert_flag = INS_ABOVE_FLOOR_ONLY; |
626 | insert_flag = INS_ABOVE_FLOOR_ONLY; |
629 | |
627 | |
630 | connected = 0; |
628 | connected = 0; |
631 | switch (tmp->type) |
629 | switch (tmp->type) |
632 | { |
630 | { |
633 | case DOOR: |
631 | case DOOR: |
634 | case GATE: |
632 | case GATE: |
635 | case BUTTON: |
633 | case BUTTON: |
636 | case DETECTOR: |
634 | case DETECTOR: |
637 | case TIMED_GATE: |
635 | case TIMED_GATE: |
638 | case PEDESTAL: |
636 | case PEDESTAL: |
639 | case CF_HANDLE: |
637 | case CF_HANDLE: |
640 | case MAGIC_EAR: |
638 | case MAGIC_EAR: |
641 | case SIGN: |
639 | case SIGN: |
642 | /* Signs don't need a connection, but but magic mouths do. */ |
640 | /* Signs don't need a connection, but but magic mouths do. */ |
643 | if (tmp->type == SIGN && strcmp (tmp->arch->archname, "magic_mouth")) |
641 | if (tmp->type == SIGN && tmp->arch->archname != shstr_magic_mouth) |
644 | break; |
642 | break; |
|
|
643 | |
645 | con_rune = get_connection_rune (pl, x, y); |
644 | con_rune = get_connection_rune (pl, x, y); |
646 | connected = find_or_create_connection_for_map (pl, x, y, con_rune); |
645 | connected = find_or_create_connection_for_map (pl, x, y, con_rune); |
647 | if (connected == -1) |
646 | if (connected == -1) |
648 | { |
647 | { |
649 | /* Player already informed of failure by the previous function */ |
648 | /* Player already informed of failure by the previous function */ |
650 | tmp->destroy (); |
649 | tmp->destroy (); |
651 | return; |
650 | return; |
652 | } |
651 | } |
|
|
652 | |
653 | /* Remove marking rune */ |
653 | /* Remove marking rune */ |
654 | con_rune->destroy (); |
654 | con_rune->destroy (); |
655 | } |
655 | } |
656 | |
656 | |
657 | /* For magic mouths/ears, and signs, take the msg from a book of scroll */ |
657 | /* For magic mouths/ears, and signs, take the msg from a book of scroll */ |
658 | if ((tmp->type == SIGN) || (tmp->type == MAGIC_EAR)) |
658 | if ((tmp->type == SIGN) || (tmp->type == MAGIC_EAR)) |
659 | { |
659 | { |
… | |
… | |
667 | insert_ob_in_map_at (tmp, pl->map, floor, insert_flag, x, y); |
667 | insert_ob_in_map_at (tmp, pl->map, floor, insert_flag, x, y); |
668 | if (connected != 0) |
668 | if (connected != 0) |
669 | add_button_link (tmp, pl->map, connected); |
669 | add_button_link (tmp, pl->map, connected); |
670 | |
670 | |
671 | new_draw_info_format (NDI_UNIQUE, 0, pl, "You build the %s", query_name (tmp)); |
671 | new_draw_info_format (NDI_UNIQUE, 0, pl, "You build the %s", query_name (tmp)); |
672 | decrease_ob_nr (item, 1); |
672 | item->decrease (); |
673 | } |
673 | } |
674 | |
674 | |
675 | /** |
675 | /** |
676 | * Item remover. |
676 | * Item remover. |
677 | * |
677 | * |
… | |
… | |
767 | } |
767 | } |
768 | |
768 | |
769 | tmp2 = find_marked_object (pl); |
769 | tmp2 = find_marked_object (pl); |
770 | while (tmp) |
770 | while (tmp) |
771 | { |
771 | { |
772 | if (!QUERY_FLAG (tmp, FLAG_IS_BUILDABLE) && ((tmp->type != SIGN) || (strcmp (tmp->arch->archname, "rune_mark")))) |
772 | if (!QUERY_FLAG (tmp, FLAG_IS_BUILDABLE) && (tmp->type != SIGN || tmp->arch->archname != shstr_rune_mark)) |
773 | { |
773 | { |
774 | /* The item building function already has it's own special |
774 | /* The item building function already has it's own special |
775 | * checks for this |
775 | * checks for this |
776 | */ |
776 | */ |
777 | if ((!tmp2) || (tmp2->subtype != ST_MAT_ITEM)) |
777 | if ((!tmp2) || (tmp2->subtype != ST_MAT_ITEM)) |
… | |
… | |
860 | tmp->msg = book->msg; |
860 | tmp->msg = book->msg; |
861 | |
861 | |
862 | if (tmp->invisible) |
862 | if (tmp->invisible) |
863 | { |
863 | { |
864 | if (book->custom_name != NULL) |
864 | if (book->custom_name != NULL) |
865 | { |
|
|
866 | snprintf (buf, sizeof (buf), "talking %s", &book->custom_name); |
865 | snprintf (buf, sizeof (buf), "talking %s", &book->custom_name); |
867 | } |
|
|
868 | else |
866 | else |
869 | { |
|
|
870 | snprintf (buf, sizeof (buf), "talking %s", &book->name); |
867 | snprintf (buf, sizeof (buf), "talking %s", &book->name); |
871 | } |
868 | |
872 | tmp->name = buf; |
869 | tmp->name = buf; |
873 | |
870 | |
874 | if (book->name_pl != NULL) |
871 | if (book->name_pl != NULL) |
875 | { |
872 | { |
876 | snprintf (buf2, sizeof (buf2), "talking %s", &book->name_pl); |
873 | snprintf (buf2, sizeof (buf2), "talking %s", &book->name_pl); |