… | |
… | |
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 (true); |
89 | rune->destroy (); |
90 | |
90 | |
91 | rune = next; |
91 | rune = next; |
92 | } |
92 | } |
93 | } |
93 | } |
94 | |
94 | |
… | |
… | |
97 | * \param map: map for which to find a value |
97 | * \param map: map for which to find a value |
98 | * \return 'connected' value with no item, or -1 if failure. |
98 | * \return 'connected' value with no item, or -1 if failure. |
99 | * |
99 | * |
100 | * Tries 1000 random values, then returns -1. |
100 | * Tries 1000 random values, then returns -1. |
101 | */ |
101 | */ |
102 | int |
102 | static shstr_tmp |
103 | find_unused_connected_value (maptile *map) |
103 | find_unused_connected_value (maptile *map) |
104 | { |
104 | { |
105 | int connected = 0; |
105 | 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 | } |
106 | { |
|
|
107 | char buf[64]; |
119 | |
108 | |
120 | return -1; |
109 | snprintf (buf, sizeof (buf), "built-%x", rndm (0xf0000000U) + 0x10000000U); |
|
|
110 | |
|
|
111 | shstr id (buf); |
|
|
112 | |
|
|
113 | if (!map->find_link (id)) |
|
|
114 | return id; |
|
|
115 | } |
|
|
116 | |
|
|
117 | return shstr_tmp (); |
121 | } |
118 | } |
122 | |
119 | |
123 | /** |
120 | /** |
124 | * Helper function for door/button/connected item building. |
121 | * Helper function for door/button/connected item building. |
125 | * |
122 | * |
… | |
… | |
128 | * Else, searches a force in op's inventory matching the map's name |
125 | * Else, searches a force in op's inventory matching the map's name |
129 | * and the rune's text. |
126 | * and the rune's text. |
130 | * If found, returns the connection value associated |
127 | * If found, returns the connection value associated |
131 | * else searches a new connection value, and adds the force to the player. |
128 | * else searches a new connection value, and adds the force to the player. |
132 | */ |
129 | */ |
133 | int |
130 | static shstr_tmp |
134 | find_or_create_connection_for_map (object *pl, short x, short y, object *rune) |
131 | find_or_create_connection_for_map (object *pl, short x, short y, object *rune) |
135 | { |
132 | { |
136 | object *force; |
133 | object *force; |
137 | int connected; |
|
|
138 | |
134 | |
139 | if (!rune) |
135 | if (!rune) |
140 | rune = get_connection_rune (pl, x, y); |
136 | rune = get_connection_rune (pl, x, y); |
141 | |
137 | |
142 | if (!rune) |
138 | if (!rune) |
143 | { |
139 | { |
144 | new_draw_info (NDI_UNIQUE, 0, pl, "You need to put a marking rune with the group name."); |
140 | new_draw_info (NDI_UNIQUE, 0, pl, "You need to put a marking rune with the group name."); |
145 | return -1; |
141 | return shstr_tmp (); |
146 | } |
142 | } |
147 | |
143 | |
148 | /* Now, find force in player's inventory */ |
144 | /* Now, find force in player's inventory */ |
149 | force = pl->inv; |
145 | force = pl->inv; |
150 | while (force |
146 | while (force |
… | |
… | |
154 | |
150 | |
155 | if (!force) |
151 | if (!force) |
156 | /* No force, need to create & insert one */ |
152 | /* No force, need to create & insert one */ |
157 | { |
153 | { |
158 | /* Find unused value */ |
154 | /* Find unused value */ |
159 | connected = find_unused_connected_value (pl->map); |
155 | shstr_tmp id = find_unused_connected_value (pl->map); |
160 | if (connected == -1) |
156 | |
|
|
157 | if (!id) |
161 | { |
158 | { |
162 | new_draw_info (NDI_UNIQUE, 0, pl, "Could not create more groups."); |
159 | new_draw_info (NDI_UNIQUE, 0, pl, "Could not create more groups."); |
163 | return -1; |
160 | return shstr_tmp (); |
164 | } |
161 | } |
165 | |
162 | |
166 | force = get_archetype (FORCE_NAME); |
163 | force = get_archetype (FORCE_NAME); |
167 | force->slaying = pl->map->path; |
164 | force->slaying = pl->map->path; |
168 | force->msg = rune->msg; |
165 | force->msg = rune->msg; |
169 | force->path_attuned = connected; |
166 | force->race = id; |
170 | force->set_speed (0); |
167 | force->set_speed (0); |
|
|
168 | |
171 | insert_ob_in_ob (force, pl); |
169 | insert_ob_in_ob (force, pl); |
172 | |
170 | |
173 | return connected; |
171 | return id; |
174 | } |
172 | } |
175 | |
173 | |
176 | /* Found the force, everything's easy. */ |
174 | /* Found the force, everything's easy. */ |
177 | return force->path_attuned; |
175 | return force->race; |
178 | } |
176 | } |
179 | |
177 | |
180 | /** |
178 | /** |
181 | * Returns the marking rune on the square, for purposes of building connections |
179 | * Returns the marking rune on the square, for purposes of building connections |
182 | */ |
180 | */ |
183 | object * |
181 | object * |
184 | get_connection_rune (object *pl, short x, short y) |
182 | get_connection_rune (object *pl, short x, short y) |
185 | { |
183 | { |
186 | object *rune = GET_MAP_OB (pl->map, x, y); |
184 | object *rune = GET_MAP_OB (pl->map, x, y); |
187 | |
185 | |
188 | while (rune && ((rune->type != SIGN) || (strcmp (rune->arch->archname, "rune_mark")))) |
186 | while (rune && (rune->type != SIGN || rune->arch->archname != shstr_rune_mark)) |
189 | rune = rune->above; |
187 | rune = rune->above; |
190 | |
188 | |
191 | return rune; |
189 | return rune; |
192 | } |
190 | } |
193 | |
191 | |
… | |
… | |
351 | /* Now delete current wall, and insert new one |
349 | /* Now delete current wall, and insert new one |
352 | * We save flags to avoid any trouble with buildable/non buildable, and so on |
350 | * We save flags to avoid any trouble with buildable/non buildable, and so on |
353 | */ |
351 | */ |
354 | object::flags_t old_flags = wall->flag; // elmex: this is where C++ pays off |
352 | object::flags_t old_flags = wall->flag; // elmex: this is where C++ pays off |
355 | |
353 | |
356 | wall->destroy (true); |
354 | wall->destroy (); |
357 | |
355 | |
358 | wall = arch_to_object (new_arch); |
356 | wall = arch_to_object (new_arch); |
359 | wall->type = BUILDABLE_WALL; |
357 | wall->type = BUILDABLE_WALL; |
360 | insert_ob_in_map_at (wall, map, NULL, INS_ABOVE_FLOOR_ONLY, x, y); |
358 | insert_ob_in_map_at (wall, map, NULL, INS_ABOVE_FLOOR_ONLY, x, y); |
361 | wall->flag = old_flags; |
359 | wall->flag = old_flags; |
… | |
… | |
398 | above = tmp->above; |
396 | above = tmp->above; |
399 | if (BUILDABLE_WALL == tmp->type) |
397 | if (BUILDABLE_WALL == tmp->type) |
400 | { |
398 | { |
401 | /* There was a wall, remove it & keep its archetype to make new walls */ |
399 | /* There was a wall, remove it & keep its archetype to make new walls */ |
402 | new_wall = tmp->arch; |
400 | new_wall = tmp->arch; |
403 | tmp->destroy (true); |
401 | tmp->destroy (); |
404 | sprintf (message, "You destroy the wall and redo the floor."); |
402 | sprintf (message, "You destroy the wall and redo the floor."); |
405 | } |
403 | } |
406 | else if ((FLOOR == tmp->type) || (QUERY_FLAG (tmp, FLAG_IS_FLOOR))) |
404 | else if ((FLOOR == tmp->type) || (QUERY_FLAG (tmp, FLAG_IS_FLOOR))) |
407 | { |
405 | { |
408 | tmp->destroy (true); |
406 | tmp->destroy (); |
409 | floor_removed = 1; |
407 | floor_removed = 1; |
410 | } |
408 | } |
411 | else |
409 | else |
412 | { |
410 | { |
413 | if (floor_removed) |
411 | if (floor_removed) |
… | |
… | |
542 | insert_ob_in_map_at (tmp, pl->map, 0, INS_ABOVE_FLOOR_ONLY, x, y); |
540 | insert_ob_in_map_at (tmp, pl->map, 0, INS_ABOVE_FLOOR_ONLY, x, y); |
543 | |
541 | |
544 | /* If existing wall, remove it, no need to fix other walls */ |
542 | /* If existing wall, remove it, no need to fix other walls */ |
545 | if (current_wall) |
543 | if (current_wall) |
546 | { |
544 | { |
547 | current_wall->destroy (true); |
545 | current_wall->destroy (); |
548 | fix_walls (pl->map, x, y); |
546 | fix_walls (pl->map, x, y); |
549 | sprintf (message, "You redecorate the wall to better suit your tastes."); |
547 | sprintf (message, "You redecorate the wall to better suit your tastes."); |
550 | } |
548 | } |
551 | else |
549 | else |
552 | { |
550 | { |
… | |
… | |
582 | object *tmp; |
580 | object *tmp; |
583 | struct archetype *arch; |
581 | struct archetype *arch; |
584 | int insert_flag; |
582 | int insert_flag; |
585 | object *floor; |
583 | object *floor; |
586 | object *con_rune; |
584 | object *con_rune; |
587 | int connected; |
|
|
588 | |
585 | |
589 | /* Find floor */ |
586 | /* Find floor */ |
590 | floor = GET_MAP_OB (pl->map, x, y); |
587 | floor = GET_MAP_OB (pl->map, x, y); |
591 | if (!floor) |
588 | if (!floor) |
592 | { |
589 | { |
… | |
… | |
623 | * This doesn't work on non unique maps. pedestals under floor will not be saved... |
620 | * This doesn't work on non unique maps. pedestals under floor will not be saved... |
624 | insert_flag = ( item->stats.Str == 1 ) ? INS_BELOW_ORIGINATOR : INS_ABOVE_FLOOR_ONLY; |
621 | insert_flag = ( item->stats.Str == 1 ) ? INS_BELOW_ORIGINATOR : INS_ABOVE_FLOOR_ONLY; |
625 | */ |
622 | */ |
626 | insert_flag = INS_ABOVE_FLOOR_ONLY; |
623 | insert_flag = INS_ABOVE_FLOOR_ONLY; |
627 | |
624 | |
628 | connected = 0; |
625 | shstr_tmp connected; |
|
|
626 | |
629 | switch (tmp->type) |
627 | switch (tmp->type) |
630 | { |
628 | { |
631 | case DOOR: |
629 | case DOOR: |
632 | case GATE: |
630 | case GATE: |
633 | case BUTTON: |
631 | case BUTTON: |
634 | case DETECTOR: |
632 | case DETECTOR: |
635 | case TIMED_GATE: |
633 | case TIMED_GATE: |
636 | case PEDESTAL: |
634 | case PEDESTAL: |
637 | case CF_HANDLE: |
635 | case CF_HANDLE: |
638 | case MAGIC_EAR: |
636 | case MAGIC_EAR: |
639 | case SIGN: |
637 | case SIGN: |
640 | /* Signs don't need a connection, but but magic mouths do. */ |
638 | /* Signs don't need a connection, but but magic mouths do. */ |
641 | if (tmp->type == SIGN && strcmp (tmp->arch->archname, "magic_mouth")) |
639 | if (tmp->type == SIGN && tmp->arch->archname != shstr_magic_mouth) |
642 | break; |
640 | break; |
643 | |
641 | |
644 | con_rune = get_connection_rune (pl, x, y); |
642 | con_rune = get_connection_rune (pl, x, y); |
645 | connected = find_or_create_connection_for_map (pl, x, y, con_rune); |
643 | connected = find_or_create_connection_for_map (pl, x, y, con_rune); |
646 | if (connected == -1) |
644 | if (!connected) |
647 | { |
645 | { |
648 | /* Player already informed of failure by the previous function */ |
646 | /* Player already informed of failure by the previous function */ |
649 | tmp->destroy (true); |
647 | tmp->destroy (); |
650 | return; |
648 | return; |
651 | } |
649 | } |
652 | |
650 | |
653 | /* Remove marking rune */ |
651 | /* Remove marking rune */ |
654 | con_rune->destroy (true); |
652 | con_rune->destroy (); |
655 | } |
653 | } |
656 | |
654 | |
657 | /* For magic mouths/ears, and signs, take the msg from a book of scroll */ |
655 | /* For magic mouths/ears, and signs, take the msg from a book of scroll */ |
658 | if ((tmp->type == SIGN) || (tmp->type == MAGIC_EAR)) |
656 | if ((tmp->type == SIGN) || (tmp->type == MAGIC_EAR)) |
659 | { |
657 | { |
660 | if (adjust_sign_msg (pl, x, y, tmp) == -1) |
658 | if (adjust_sign_msg (pl, x, y, tmp) == -1) |
661 | { |
659 | { |
662 | tmp->destroy (true); |
660 | tmp->destroy (); |
663 | return; |
661 | return; |
664 | } |
662 | } |
665 | } |
663 | } |
666 | |
664 | |
667 | insert_ob_in_map_at (tmp, pl->map, floor, insert_flag, x, y); |
665 | insert_ob_in_map_at (tmp, pl->map, floor, insert_flag, x, y); |
668 | if (connected != 0) |
666 | if (connected) |
669 | add_button_link (tmp, pl->map, connected); |
667 | tmp->add_link (pl->map, connected); |
670 | |
668 | |
671 | new_draw_info_format (NDI_UNIQUE, 0, pl, "You build the %s", query_name (tmp)); |
669 | new_draw_info_format (NDI_UNIQUE, 0, pl, "You build the %s", query_name (tmp)); |
672 | item->decrease (); |
670 | item->decrease (); |
673 | } |
671 | } |
674 | |
672 | |
… | |
… | |
706 | else if (!item->flag [FLAG_IS_BUILDABLE]) |
704 | 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)); |
705 | new_draw_info_format (NDI_UNIQUE, 0, pl, "You can't remove the %s, it's not buildable!", query_name (item)); |
708 | else |
706 | else |
709 | { |
707 | { |
710 | new_draw_info_format (NDI_UNIQUE, 0, pl, "You remove the %s", query_name (item)); |
708 | new_draw_info_format (NDI_UNIQUE, 0, pl, "You remove the %s", query_name (item)); |
711 | item->destroy (true); |
709 | item->destroy (); |
712 | } |
710 | } |
713 | } |
711 | } |
714 | |
712 | |
715 | /** |
713 | /** |
716 | * Global building function |
714 | * Global building function |
… | |
… | |
767 | } |
765 | } |
768 | |
766 | |
769 | tmp2 = find_marked_object (pl); |
767 | tmp2 = find_marked_object (pl); |
770 | while (tmp) |
768 | while (tmp) |
771 | { |
769 | { |
772 | if (!QUERY_FLAG (tmp, FLAG_IS_BUILDABLE) && ((tmp->type != SIGN) || (strcmp (tmp->arch->archname, "rune_mark")))) |
770 | if (!QUERY_FLAG (tmp, FLAG_IS_BUILDABLE) && (tmp->type != SIGN || tmp->arch->archname != shstr_rune_mark)) |
773 | { |
771 | { |
774 | /* The item building function already has it's own special |
772 | /* The item building function already has it's own special |
775 | * checks for this |
773 | * checks for this |
776 | */ |
774 | */ |
777 | if ((!tmp2) || (tmp2->subtype != ST_MAT_ITEM)) |
775 | if ((!tmp2) || (tmp2->subtype != ST_MAT_ITEM)) |
… | |
… | |
876 | |
874 | |
877 | tmp->face = book->face; |
875 | tmp->face = book->face; |
878 | tmp->invisible = 0; |
876 | tmp->invisible = 0; |
879 | } |
877 | } |
880 | |
878 | |
881 | book->destroy (true); |
879 | book->destroy (); |
882 | return 0; |
880 | return 0; |
883 | } |
881 | } |