… | |
… | |
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 | */ |
… | |
… | |
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: |
… | |
… | |
641 | if (tmp->type == SIGN && tmp->arch->archname != shstr_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 (); |
647 | tmp->destroy (); |
650 | return; |
648 | return; |
651 | } |
649 | } |
… | |
… | |
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 | |