… | |
… | |
3 | * |
3 | * |
4 | * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra 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 | * Deliantra is free software: you can redistribute it and/or modify |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
9 | * it under the terms of the GNU General Public License as published by |
9 | * the terms of the Affero GNU General Public License as published by the |
10 | * the Free Software Foundation, either version 3 of the License, or |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
11 | * (at your option) any later version. |
11 | * 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, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
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 Affero GNU General Public License |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 | * and the GNU General Public License along with this program. If not, see |
|
|
20 | * <http://www.gnu.org/licenses/>. |
20 | * |
21 | * |
21 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | */ |
23 | */ |
23 | |
24 | |
24 | #include <global.h> |
25 | #include <global.h> |
… | |
… | |
38 | |
39 | |
39 | ob = GET_MAP_OB (map, x, y); |
40 | ob = GET_MAP_OB (map, x, y); |
40 | while (ob) |
41 | while (ob) |
41 | { |
42 | { |
42 | /* if ob is not a marking rune or floor, then check special cases */ |
43 | /* if ob is not a marking rune or floor, then check special cases */ |
43 | if (strcmp (ob->arch->archname, "rune_mark") && ob->type != FLOOR) |
44 | if (ob->arch->archname != shstr_rune_mark && ob->type != FLOOR) |
44 | { |
45 | { |
45 | switch (tmp->type) |
46 | switch (tmp->type) |
46 | { |
47 | { |
47 | case SIGN: |
48 | case SIGN: |
48 | case MAGIC_EAR: |
49 | case MAGIC_EAR: |
49 | /* Allow signs and magic ears to be built on books */ |
50 | /* Allow signs and magic ears to be built on books */ |
50 | if (ob->type != BOOK) |
51 | 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; |
52 | return 0; |
|
|
53 | break; |
|
|
54 | case BUTTON: |
|
|
55 | case DETECTOR: |
|
|
56 | case PEDESTAL: |
|
|
57 | case CF_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; |
67 | } |
64 | } |
68 | } |
65 | } |
|
|
66 | |
69 | ob = ob->above; |
67 | ob = ob->above; |
70 | } |
68 | } |
71 | return 1; |
69 | return 1; |
72 | } |
70 | } |
73 | |
71 | |
… | |
… | |
83 | rune = GET_MAP_OB (map, x, y); |
81 | rune = GET_MAP_OB (map, x, y); |
84 | while (rune) |
82 | while (rune) |
85 | { |
83 | { |
86 | next = rune->above; |
84 | next = rune->above; |
87 | |
85 | |
88 | if (rune->type == SIGN && !strcmp (rune->arch->archname, "rune_mark")) |
86 | if (rune->type == SIGN && rune->arch->archname == shstr_rune_mark) |
89 | rune->destroy (true); |
87 | rune->destroy (); |
90 | |
88 | |
91 | rune = next; |
89 | rune = next; |
92 | } |
90 | } |
93 | } |
91 | } |
94 | |
92 | |
… | |
… | |
97 | * \param map: map for which to find a value |
95 | * \param map: map for which to find a value |
98 | * \return 'connected' value with no item, or -1 if failure. |
96 | * \return 'connected' value with no item, or -1 if failure. |
99 | * |
97 | * |
100 | * Tries 1000 random values, then returns -1. |
98 | * Tries 1000 random values, then returns -1. |
101 | */ |
99 | */ |
102 | int |
100 | static shstr_tmp |
103 | find_unused_connected_value (maptile *map) |
101 | find_unused_connected_value (maptile *map) |
104 | { |
102 | { |
105 | int connected = 0; |
103 | for (int i = 1000; --i; ) |
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 | } |
104 | { |
|
|
105 | char buf[64]; |
119 | |
106 | |
120 | return -1; |
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 (); |
121 | } |
116 | } |
122 | |
117 | |
123 | /** |
118 | /** |
124 | * Helper function for door/button/connected item building. |
119 | * Helper function for door/button/connected item building. |
125 | * |
120 | * |
… | |
… | |
128 | * Else, searches a force in op's inventory matching the map's name |
123 | * Else, searches a force in op's inventory matching the map's name |
129 | * and the rune's text. |
124 | * and the rune's text. |
130 | * If found, returns the connection value associated |
125 | * If found, returns the connection value associated |
131 | * else searches a new connection value, and adds the force to the player. |
126 | * else searches a new connection value, and adds the force to the player. |
132 | */ |
127 | */ |
133 | int |
128 | static shstr_tmp |
134 | find_or_create_connection_for_map (object *pl, short x, short y, object *rune) |
129 | find_or_create_connection_for_map (object *pl, short x, short y, object *rune) |
135 | { |
130 | { |
136 | object *force; |
131 | object *force; |
137 | int connected; |
|
|
138 | |
132 | |
139 | if (!rune) |
133 | if (!rune) |
140 | rune = get_connection_rune (pl, x, y); |
134 | rune = get_connection_rune (pl, x, y); |
141 | |
135 | |
142 | if (!rune) |
136 | if (!rune) |
143 | { |
137 | { |
144 | new_draw_info (NDI_UNIQUE, 0, pl, "You need to put a marking rune with the group name."); |
138 | new_draw_info (NDI_UNIQUE, 0, pl, "You need to put a marking rune with the group name."); |
145 | return -1; |
139 | return shstr_tmp (); |
146 | } |
140 | } |
147 | |
141 | |
148 | /* Now, find force in player's inventory */ |
142 | /* Now, find force in player's inventory */ |
149 | force = pl->inv; |
143 | force = pl->inv; |
150 | while (force |
144 | while (force |
… | |
… | |
154 | |
148 | |
155 | if (!force) |
149 | if (!force) |
156 | /* No force, need to create & insert one */ |
150 | /* No force, need to create & insert one */ |
157 | { |
151 | { |
158 | /* Find unused value */ |
152 | /* Find unused value */ |
159 | connected = find_unused_connected_value (pl->map); |
153 | shstr_tmp id = find_unused_connected_value (pl->map); |
160 | if (connected == -1) |
154 | |
|
|
155 | if (!id) |
161 | { |
156 | { |
162 | new_draw_info (NDI_UNIQUE, 0, pl, "Could not create more groups."); |
157 | new_draw_info (NDI_UNIQUE, 0, pl, "Could not create more groups."); |
163 | return -1; |
158 | return shstr_tmp (); |
164 | } |
159 | } |
165 | |
160 | |
166 | force = get_archetype (FORCE_NAME); |
161 | force = get_archetype (FORCE_NAME); |
167 | force->slaying = pl->map->path; |
162 | force->slaying = pl->map->path; |
168 | force->msg = rune->msg; |
163 | force->msg = rune->msg; |
169 | force->path_attuned = connected; |
164 | force->race = id; |
170 | force->set_speed (0); |
165 | force->set_speed (0); |
|
|
166 | |
171 | insert_ob_in_ob (force, pl); |
167 | insert_ob_in_ob (force, pl); |
172 | |
168 | |
173 | return connected; |
169 | return id; |
174 | } |
170 | } |
175 | |
171 | |
176 | /* Found the force, everything's easy. */ |
172 | /* Found the force, everything's easy. */ |
177 | return force->path_attuned; |
173 | return force->race; |
178 | } |
174 | } |
179 | |
175 | |
180 | /** |
176 | /** |
181 | * Returns the marking rune on the square, for purposes of building connections |
177 | * Returns the marking rune on the square, for purposes of building connections |
182 | */ |
178 | */ |
183 | object * |
179 | object * |
184 | get_connection_rune (object *pl, short x, short y) |
180 | get_connection_rune (object *pl, short x, short y) |
185 | { |
181 | { |
186 | object *rune = GET_MAP_OB (pl->map, x, y); |
182 | object *rune = GET_MAP_OB (pl->map, x, y); |
187 | |
183 | |
188 | while (rune && ((rune->type != SIGN) || (strcmp (rune->arch->archname, "rune_mark")))) |
184 | while (rune && (rune->type != SIGN || rune->arch->archname != shstr_rune_mark)) |
189 | rune = rune->above; |
185 | rune = rune->above; |
190 | |
186 | |
191 | return rune; |
187 | return rune; |
192 | } |
188 | } |
193 | |
189 | |
… | |
… | |
351 | /* Now delete current wall, and insert new one |
347 | /* Now delete current wall, and insert new one |
352 | * We save flags to avoid any trouble with buildable/non buildable, and so on |
348 | * We save flags to avoid any trouble with buildable/non buildable, and so on |
353 | */ |
349 | */ |
354 | object::flags_t old_flags = wall->flag; // elmex: this is where C++ pays off |
350 | object::flags_t old_flags = wall->flag; // elmex: this is where C++ pays off |
355 | |
351 | |
356 | wall->destroy (true); |
352 | wall->destroy (); |
357 | |
353 | |
358 | wall = arch_to_object (new_arch); |
354 | wall = arch_to_object (new_arch); |
359 | wall->type = BUILDABLE_WALL; |
355 | wall->type = BUILDABLE_WALL; |
360 | insert_ob_in_map_at (wall, map, NULL, INS_ABOVE_FLOOR_ONLY, x, y); |
356 | insert_ob_in_map_at (wall, map, NULL, INS_ABOVE_FLOOR_ONLY, x, y); |
361 | wall->flag = old_flags; |
357 | wall->flag = old_flags; |
… | |
… | |
398 | above = tmp->above; |
394 | above = tmp->above; |
399 | if (BUILDABLE_WALL == tmp->type) |
395 | if (BUILDABLE_WALL == tmp->type) |
400 | { |
396 | { |
401 | /* There was a wall, remove it & keep its archetype to make new walls */ |
397 | /* There was a wall, remove it & keep its archetype to make new walls */ |
402 | new_wall = tmp->arch; |
398 | new_wall = tmp->arch; |
403 | tmp->destroy (true); |
399 | tmp->destroy (); |
404 | sprintf (message, "You destroy the wall and redo the floor."); |
400 | sprintf (message, "You destroy the wall and redo the floor."); |
405 | } |
401 | } |
406 | else if ((FLOOR == tmp->type) || (QUERY_FLAG (tmp, FLAG_IS_FLOOR))) |
402 | else if ((FLOOR == tmp->type) || (QUERY_FLAG (tmp, FLAG_IS_FLOOR))) |
407 | { |
403 | { |
408 | tmp->destroy (true); |
404 | tmp->destroy (); |
409 | floor_removed = 1; |
405 | floor_removed = 1; |
410 | } |
406 | } |
411 | else |
407 | else |
412 | { |
408 | { |
413 | if (floor_removed) |
409 | if (floor_removed) |
|
|
410 | { |
|
|
411 | /* This is the first item that was above the floor */ |
414 | above_floor = tmp; |
412 | above_floor = tmp; |
|
|
413 | floor_removed = 0; |
|
|
414 | } |
415 | } |
415 | } |
416 | |
416 | |
417 | tmp = above; |
417 | tmp = above; |
418 | } |
418 | } |
419 | } |
419 | } |
… | |
… | |
542 | insert_ob_in_map_at (tmp, pl->map, 0, INS_ABOVE_FLOOR_ONLY, x, y); |
542 | insert_ob_in_map_at (tmp, pl->map, 0, INS_ABOVE_FLOOR_ONLY, x, y); |
543 | |
543 | |
544 | /* If existing wall, remove it, no need to fix other walls */ |
544 | /* If existing wall, remove it, no need to fix other walls */ |
545 | if (current_wall) |
545 | if (current_wall) |
546 | { |
546 | { |
547 | current_wall->destroy (true); |
547 | current_wall->destroy (); |
548 | fix_walls (pl->map, x, y); |
548 | fix_walls (pl->map, x, y); |
549 | sprintf (message, "You redecorate the wall to better suit your tastes."); |
549 | sprintf (message, "You redecorate the wall to better suit your tastes."); |
550 | } |
550 | } |
551 | else |
551 | else |
552 | { |
552 | { |
… | |
… | |
582 | object *tmp; |
582 | object *tmp; |
583 | struct archetype *arch; |
583 | struct archetype *arch; |
584 | int insert_flag; |
584 | int insert_flag; |
585 | object *floor; |
585 | object *floor; |
586 | object *con_rune; |
586 | object *con_rune; |
587 | int connected; |
|
|
588 | |
587 | |
589 | /* Find floor */ |
588 | /* Find floor */ |
590 | floor = GET_MAP_OB (pl->map, x, y); |
589 | floor = GET_MAP_OB (pl->map, x, y); |
591 | if (!floor) |
590 | if (!floor) |
592 | { |
591 | { |
… | |
… | |
618 | |
617 | |
619 | SET_FLAG (tmp, FLAG_IS_BUILDABLE); |
618 | SET_FLAG (tmp, FLAG_IS_BUILDABLE); |
620 | SET_FLAG (tmp, FLAG_NO_PICK); |
619 | SET_FLAG (tmp, FLAG_NO_PICK); |
621 | |
620 | |
622 | /* |
621 | /* |
623 | * This doesn't work on non unique maps. pedestals under floor will not be saved... |
622 | * Str 1 is a flag that the item [pedestal] should go below the floor. |
624 | insert_flag = ( item->stats.Str == 1 ) ? INS_BELOW_ORIGINATOR : INS_ABOVE_FLOOR_ONLY; |
623 | * Items under the floor on non-unique maps will not be saved, |
|
|
624 | * so make the item itself unique in this situation. |
625 | */ |
625 | */ |
626 | insert_flag = INS_ABOVE_FLOOR_ONLY; |
626 | insert_flag = ( item->stats.Str == 1 ) ? INS_BELOW_ORIGINATOR : INS_ABOVE_FLOOR_ONLY; |
|
|
627 | if (insert_flag == INS_BELOW_ORIGINATOR && !pl->map->no_reset) |
|
|
628 | SET_FLAG (tmp, FLAG_UNIQUE); |
627 | |
629 | |
628 | connected = 0; |
630 | shstr_tmp connected; |
|
|
631 | |
629 | switch (tmp->type) |
632 | switch (tmp->type) |
630 | { |
633 | { |
631 | case DOOR: |
634 | case DOOR: |
632 | case GATE: |
635 | case GATE: |
633 | case BUTTON: |
636 | case BUTTON: |
634 | case DETECTOR: |
637 | case DETECTOR: |
635 | case TIMED_GATE: |
638 | case TIMED_GATE: |
636 | case PEDESTAL: |
639 | case PEDESTAL: |
637 | case CF_HANDLE: |
640 | case CF_HANDLE: |
638 | case MAGIC_EAR: |
641 | case MAGIC_EAR: |
639 | case SIGN: |
642 | case SIGN: |
640 | /* Signs don't need a connection, but but magic mouths do. */ |
643 | /* Signs don't need a connection, but but magic mouths do. */ |
641 | if (tmp->type == SIGN && strcmp (tmp->arch->archname, "magic_mouth")) |
644 | if (tmp->type == SIGN && tmp->arch->archname != shstr_magic_mouth) |
642 | break; |
645 | break; |
643 | |
646 | |
644 | con_rune = get_connection_rune (pl, x, y); |
647 | con_rune = get_connection_rune (pl, x, y); |
645 | connected = find_or_create_connection_for_map (pl, x, y, con_rune); |
648 | connected = find_or_create_connection_for_map (pl, x, y, con_rune); |
646 | if (connected == -1) |
649 | if (!connected) |
647 | { |
650 | { |
648 | /* Player already informed of failure by the previous function */ |
651 | /* Player already informed of failure by the previous function */ |
649 | tmp->destroy (true); |
652 | tmp->destroy (); |
650 | return; |
653 | return; |
651 | } |
654 | } |
652 | |
655 | |
653 | /* Remove marking rune */ |
656 | /* Remove marking rune */ |
654 | con_rune->destroy (true); |
657 | con_rune->destroy (); |
655 | } |
658 | } |
656 | |
659 | |
657 | /* For magic mouths/ears, and signs, take the msg from a book of scroll */ |
660 | /* For magic mouths/ears, and signs, take the msg from a book of scroll */ |
658 | if ((tmp->type == SIGN) || (tmp->type == MAGIC_EAR)) |
661 | if ((tmp->type == SIGN) || (tmp->type == MAGIC_EAR)) |
659 | { |
662 | { |
660 | if (adjust_sign_msg (pl, x, y, tmp) == -1) |
663 | if (adjust_sign_msg (pl, x, y, tmp) == -1) |
661 | { |
664 | { |
662 | tmp->destroy (true); |
665 | tmp->destroy (); |
663 | return; |
666 | return; |
664 | } |
667 | } |
665 | } |
668 | } |
666 | |
669 | |
667 | insert_ob_in_map_at (tmp, pl->map, floor, insert_flag, x, y); |
670 | insert_ob_in_map_at (tmp, pl->map, floor, insert_flag, x, y); |
668 | if (connected != 0) |
671 | if (connected) |
669 | add_button_link (tmp, pl->map, connected); |
672 | tmp->add_link (pl->map, connected); |
670 | |
673 | |
671 | new_draw_info_format (NDI_UNIQUE, 0, pl, "You build the %s", query_name (tmp)); |
674 | new_draw_info_format (NDI_UNIQUE, 0, pl, "You build the %s", query_name (tmp)); |
672 | item->decrease (); |
675 | item->decrease (); |
673 | } |
676 | } |
674 | |
677 | |
… | |
… | |
706 | else if (!item->flag [FLAG_IS_BUILDABLE]) |
709 | 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)); |
710 | new_draw_info_format (NDI_UNIQUE, 0, pl, "You can't remove the %s, it's not buildable!", query_name (item)); |
708 | else |
711 | else |
709 | { |
712 | { |
710 | new_draw_info_format (NDI_UNIQUE, 0, pl, "You remove the %s", query_name (item)); |
713 | new_draw_info_format (NDI_UNIQUE, 0, pl, "You remove the %s", query_name (item)); |
711 | item->destroy (true); |
714 | item->destroy (); |
712 | } |
715 | } |
713 | } |
716 | } |
714 | |
717 | |
715 | /** |
718 | /** |
716 | * Global building function |
719 | * Global building function |
… | |
… | |
767 | } |
770 | } |
768 | |
771 | |
769 | tmp2 = find_marked_object (pl); |
772 | tmp2 = find_marked_object (pl); |
770 | while (tmp) |
773 | while (tmp) |
771 | { |
774 | { |
772 | if (!QUERY_FLAG (tmp, FLAG_IS_BUILDABLE) && ((tmp->type != SIGN) || (strcmp (tmp->arch->archname, "rune_mark")))) |
775 | if (!QUERY_FLAG (tmp, FLAG_IS_BUILDABLE) && (tmp->type != SIGN || tmp->arch->archname != shstr_rune_mark)) |
773 | { |
776 | { |
774 | /* The item building function already has it's own special |
777 | /* The item building function already has it's own special |
775 | * checks for this |
778 | * checks for this |
776 | */ |
779 | */ |
777 | if ((!tmp2) || (tmp2->subtype != ST_MAT_ITEM)) |
780 | if ((!tmp2) || (tmp2->subtype != ST_MAT_ITEM)) |
… | |
… | |
876 | |
879 | |
877 | tmp->face = book->face; |
880 | tmp->face = book->face; |
878 | tmp->invisible = 0; |
881 | tmp->invisible = 0; |
879 | } |
882 | } |
880 | |
883 | |
881 | book->destroy (true); |
884 | book->destroy (); |
882 | return 0; |
885 | return 0; |
883 | } |
886 | } |