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