… | |
… | |
118 | } |
118 | } |
119 | |
119 | |
120 | /* all the treasure at one spot in the map. */ |
120 | /* all the treasure at one spot in the map. */ |
121 | if (treasureoptions & CONCENTRATED) |
121 | if (treasureoptions & CONCENTRATED) |
122 | { |
122 | { |
123 | |
|
|
124 | /* map_layout_style global, and is previously set */ |
123 | /* map_layout_style global, and is previously set */ |
125 | switch (RP->map_layout_style) |
124 | switch (RP->map_layout_style) |
126 | { |
125 | { |
127 | case LAYOUT_ONION: |
126 | case LAYOUT_ONION: |
128 | case LAYOUT_SPIRAL: |
127 | case LAYOUT_SPIRAL: |
… | |
… | |
140 | int tdiv = RP->symmetry_used; |
139 | int tdiv = RP->symmetry_used; |
141 | object *chest; |
140 | object *chest; |
142 | |
141 | |
143 | if (tdiv == 3) |
142 | if (tdiv == 3) |
144 | tdiv = 2; /* this symmetry uses a divisor of 2 */ |
143 | tdiv = 2; /* this symmetry uses a divisor of 2 */ |
|
|
144 | |
145 | /* don't put a chest on an exit. */ |
145 | /* don't put a chest on an exit. */ |
146 | chest = place_chest (treasureoptions, i, j, map, style_map, num_treasures / tdiv, RP); |
146 | chest = place_chest (treasureoptions, i, j, map, style_map, num_treasures / tdiv, RP); |
147 | |
147 | |
148 | if (!chest) |
148 | if (!chest) |
149 | continue; /* if no chest was placed NEXT */ |
149 | continue; /* if no chest was placed NEXT */ |
… | |
… | |
157 | } |
157 | } |
158 | } |
158 | } |
159 | } |
159 | } |
160 | break; |
160 | break; |
161 | } |
161 | } |
|
|
162 | |
162 | default: |
163 | default: |
163 | { |
164 | { |
164 | int i, j, tries; |
165 | int i, j, tries; |
165 | object *chest; |
166 | object *chest; |
166 | object **doorlist; |
167 | object **doorlist; |
… | |
… | |
170 | while (i == -1 && tries < 100) |
171 | while (i == -1 && tries < 100) |
171 | { |
172 | { |
172 | i = rndm (RP->Xsize - 2) + 1; |
173 | i = rndm (RP->Xsize - 2) + 1; |
173 | j = rndm (RP->Ysize - 2) + 1; |
174 | j = rndm (RP->Ysize - 2) + 1; |
174 | find_enclosed_spot (map, &i, &j, RP); |
175 | find_enclosed_spot (map, &i, &j, RP); |
|
|
176 | |
175 | if (wall_blocked (map, i, j)) |
177 | if (wall_blocked (map, i, j)) |
176 | i = -1; |
178 | i = -1; |
|
|
179 | |
177 | tries++; |
180 | tries++; |
178 | } |
181 | } |
|
|
182 | |
179 | chest = place_chest (treasureoptions, i, j, map, style_map, num_treasures, RP); |
183 | chest = place_chest (treasureoptions, i, j, map, style_map, num_treasures, RP); |
|
|
184 | |
180 | if (!chest) |
185 | if (!chest) |
181 | return; |
186 | return; |
|
|
187 | |
182 | i = chest->x; |
188 | i = chest->x; |
183 | j = chest->y; |
189 | j = chest->y; |
184 | if (treasureoptions & (DOORED | HIDDEN)) |
190 | if (treasureoptions & (DOORED | HIDDEN)) |
185 | { |
191 | { |
186 | doorlist = surround_by_doors (map, layout, i, j, treasureoptions); |
192 | doorlist = surround_by_doors (map, layout, i, j, treasureoptions); |
… | |
… | |
204 | } |
210 | } |
205 | |
211 | |
206 | /* put a chest into the map, near x and y, with the treasure style |
212 | /* put a chest into the map, near x and y, with the treasure style |
207 | determined (may be null, or may be a treasure list from lib/treasures, |
213 | determined (may be null, or may be a treasure list from lib/treasures, |
208 | if the global variable "treasurestyle" is set to that treasure list's name */ |
214 | if the global variable "treasurestyle" is set to that treasure list's name */ |
209 | |
|
|
210 | object * |
215 | object * |
211 | place_chest (int treasureoptions, int x, int y, maptile *map, maptile *style_map, int n_treasures, random_map_params *RP) |
216 | place_chest (int treasureoptions, int x, int y, maptile *map, maptile *style_map, int n_treasures, random_map_params *RP) |
212 | { |
217 | { |
213 | object *the_chest; |
218 | object *the_chest; |
214 | int i, xl, yl; |
219 | int i, xl, yl; |
… | |
… | |
260 | |
265 | |
261 | /* stick a trap in the chest if required */ |
266 | /* stick a trap in the chest if required */ |
262 | if (treasureoptions & TRAPPED) |
267 | if (treasureoptions & TRAPPED) |
263 | { |
268 | { |
264 | maptile *trap_map = find_style ("/styles/trapstyles", "traps", -1); |
269 | maptile *trap_map = find_style ("/styles/trapstyles", "traps", -1); |
265 | object *the_trap; |
|
|
266 | |
270 | |
267 | if (trap_map) |
271 | if (trap_map) |
268 | { |
272 | { |
269 | the_trap = trap_map->pick_random_object (); |
273 | object *the_trap = trap_map->pick_random_object (); |
|
|
274 | |
270 | the_trap->stats.Cha = 10 + RP->difficulty; |
275 | the_trap->stats.Cha = 10 + RP->difficulty; |
271 | the_trap->level = bc_random ((3 * RP->difficulty) / 2); |
276 | the_trap->level = bc_random ((3 * RP->difficulty) / 2); |
|
|
277 | |
272 | if (the_trap) |
278 | if (the_trap) |
273 | { |
279 | { |
274 | object *new_trap; |
280 | object *new_trap = the_trap->arch->instance ();//TODO: why not clone? |
275 | |
281 | |
276 | new_trap = arch_to_object (the_trap->arch); |
|
|
277 | new_trap->copy_to (the_trap); |
|
|
278 | new_trap->x = x; |
282 | new_trap->x = x; |
279 | new_trap->y = y; |
283 | new_trap->y = y; |
280 | insert_ob_in_ob (new_trap, the_chest); |
284 | insert_ob_in_ob (new_trap, the_chest); |
281 | } |
285 | } |
282 | } |
286 | } |
… | |
… | |
482 | { |
486 | { |
483 | theMonsterToFind = find_monster_in_room_recursive (layout, map, x + freearr_x[i % 8 + 1], y + freearr_y[i % 8 + 1], RP); |
487 | theMonsterToFind = find_monster_in_room_recursive (layout, map, x + freearr_x[i % 8 + 1], y + freearr_y[i % 8 + 1], RP); |
484 | if (theMonsterToFind != NULL) |
488 | if (theMonsterToFind != NULL) |
485 | return theMonsterToFind; |
489 | return theMonsterToFind; |
486 | } |
490 | } |
|
|
491 | |
487 | return theMonsterToFind; |
492 | return theMonsterToFind; |
488 | } |
493 | } |
489 | |
|
|
490 | |
494 | |
491 | /* sets up some data structures: the _recursive form does the |
495 | /* sets up some data structures: the _recursive form does the |
492 | real work. */ |
496 | real work. */ |
493 | |
|
|
494 | object * |
497 | object * |
495 | find_monster_in_room (maptile *map, int x, int y, random_map_params *RP) |
498 | find_monster_in_room (maptile *map, int x, int y, random_map_params *RP) |
496 | { |
499 | { |
497 | char **layout2; |
500 | Layout layout2 (RP); |
498 | int i, j; |
501 | |
|
|
502 | layout2->clear (); |
|
|
503 | |
|
|
504 | /* allocate and copy the layout, converting C to 0. */ |
|
|
505 | for (int i = 0; i < layout2->w; i++) |
|
|
506 | for (int j = 0; j < layout2->h; j++) |
|
|
507 | if (wall_blocked (map, i, j)) |
|
|
508 | layout2[i][j] = '#'; |
499 | |
509 | |
500 | theMonsterToFind = 0; |
510 | theMonsterToFind = 0; |
501 | layout2 = (char **) calloc (sizeof (char *), RP->Xsize); |
|
|
502 | /* allocate and copy the layout, converting C to 0. */ |
|
|
503 | for (i = 0; i < RP->Xsize; i++) |
|
|
504 | { |
|
|
505 | layout2[i] = (char *) calloc (sizeof (char), RP->Ysize); |
|
|
506 | for (j = 0; j < RP->Ysize; j++) |
|
|
507 | if (wall_blocked (map, i, j)) |
|
|
508 | layout2[i][j] = '#'; |
|
|
509 | } |
|
|
510 | |
|
|
511 | theMonsterToFind = find_monster_in_room_recursive (layout2, map, x, y, RP); |
511 | theMonsterToFind = find_monster_in_room_recursive (layout2, map, x, y, RP); |
512 | |
512 | |
513 | /* deallocate the temp. layout */ |
513 | layout2.free (); |
514 | for (i = 0; i < RP->Xsize; i++) |
|
|
515 | free (layout2[i]); |
|
|
516 | |
|
|
517 | free (layout2); |
|
|
518 | |
514 | |
519 | return theMonsterToFind; |
515 | return theMonsterToFind; |
520 | } |
516 | } |
521 | |
517 | |
522 | /* a datastructure needed by find_spot_in_room and find_spot_in_room_recursive */ |
518 | /* a datastructure needed by find_spot_in_room and find_spot_in_room_recursive */ |
… | |
… | |
797 | find_doors_in_room (maptile *map, int x, int y, random_map_params *RP) |
793 | find_doors_in_room (maptile *map, int x, int y, random_map_params *RP) |
798 | { |
794 | { |
799 | int i, j; |
795 | int i, j; |
800 | int ndoors = 0; |
796 | int ndoors = 0; |
801 | |
797 | |
802 | object **doorlist = (object **) calloc (sizeof (int), 1024); |
798 | object **doorlist = (object **)calloc (sizeof (int), 1024); |
803 | |
799 | |
804 | MazeData layout2 (RP->Xsize, RP->Ysize); |
800 | LayoutData layout2 (RP->Xsize, RP->Ysize); |
|
|
801 | layout2.clear (); |
805 | |
802 | |
806 | /* allocate and copy the layout, converting C to 0. */ |
803 | /* allocate and copy the layout, converting C to 0. */ |
807 | for (i = 0; i < RP->Xsize; i++) |
804 | for (i = 0; i < RP->Xsize; i++) |
808 | for (j = 0; j < RP->Ysize; j++) |
805 | for (j = 0; j < RP->Ysize; j++) |
809 | if (wall_blocked (map, i, j)) |
806 | layout2[i][j] = wall_blocked (map, i, j) ? '#' : 0; |
810 | layout2[i][j] = '#'; |
|
|
811 | |
807 | |
812 | /* setup num_free_spots and room_free_spots */ |
808 | /* setup num_free_spots and room_free_spots */ |
813 | find_doors_in_room_recursive (layout2, map, x, y, doorlist, &ndoors, RP); |
809 | find_doors_in_room_recursive (layout2, map, x, y, doorlist, &ndoors, RP); |
814 | |
810 | |
815 | return doorlist; |
811 | return doorlist; |
… | |
… | |
859 | { |
855 | { |
860 | retrofit_joined_wall (map, door->x - 1, door->y, 0, RP); |
856 | retrofit_joined_wall (map, door->x - 1, door->y, 0, RP); |
861 | retrofit_joined_wall (map, door->x + 1, door->y, 0, RP); |
857 | retrofit_joined_wall (map, door->x + 1, door->y, 0, RP); |
862 | retrofit_joined_wall (map, door->x, door->y - 1, 0, RP); |
858 | retrofit_joined_wall (map, door->x, door->y - 1, 0, RP); |
863 | retrofit_joined_wall (map, door->x, door->y + 1, 0, RP); |
859 | retrofit_joined_wall (map, door->x, door->y + 1, 0, RP); |
|
|
860 | |
864 | door->face = wallface->face; |
861 | door->face = wallface->face; |
|
|
862 | |
865 | if (!QUERY_FLAG (wallface, FLAG_REMOVED)) |
863 | if (!QUERY_FLAG (wallface, FLAG_REMOVED)) |
866 | wallface->remove (); |
864 | wallface->remove (); |
|
|
865 | |
867 | wallface->destroy (); |
866 | wallface->destroy (); |
868 | } |
867 | } |
869 | } |
868 | } |
870 | } |
869 | } |
871 | } |
870 | } |