1 | /* |
1 | /* |
2 | CrossFire, A Multiplayer game for X-windows |
2 | * CrossFire, A Multiplayer game |
3 | |
3 | * |
|
|
4 | * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team |
4 | Copyright (C) 2001 Mark Wedel & Crossfire Development Team |
5 | * Copyright (C) 2001 Mark Wedel & Crossfire Development Team |
5 | Copyright (C) 1992 Frank Tore Johansen |
6 | * Copyright (C) 1992 Frank Tore Johansen |
6 | |
7 | * |
7 | This program is free software; you can redistribute it and/or modify |
8 | * This program is free software; you can redistribute it and/or modify |
8 | it under the terms of the GNU General Public License as published by |
9 | * it under the terms of the GNU General Public License as published by |
9 | the Free Software Foundation; either version 2 of the License, or |
10 | * the Free Software Foundation; either version 2 of the License, or |
10 | (at your option) any later version. |
11 | * (at your option) any later version. |
11 | |
12 | * |
12 | 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, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
16 | |
17 | * |
17 | You should have received a copy of the GNU General Public License |
18 | * You should have received a copy of the GNU General Public License |
18 | along with this program; if not, write to the Free Software |
19 | * along with this program; if not, write to the Free Software |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | |
21 | * |
21 | The authors can be reached via e-mail at <crossfire@schmorp.de> |
22 | * The authors can be reached via e-mail at <crossfire@schmorp.de> |
22 | */ |
23 | */ |
23 | |
24 | |
24 | /* placing treasure in maps, where appropriate. */ |
25 | /* placing treasure in maps, where appropriate. */ |
25 | |
|
|
26 | |
|
|
27 | |
26 | |
28 | #include <global.h> |
27 | #include <global.h> |
29 | #include <random_map.h> |
28 | #include <random_map.h> |
30 | #include <rproto.h> |
29 | #include <rproto.h> |
31 | |
30 | |
… | |
… | |
42 | #define LAST_OPTION 64 /* set this to the last real option, for random */ |
41 | #define LAST_OPTION 64 /* set this to the last real option, for random */ |
43 | |
42 | |
44 | #define NO_PASS_DOORS 0 |
43 | #define NO_PASS_DOORS 0 |
45 | #define PASS_DOORS 1 |
44 | #define PASS_DOORS 1 |
46 | |
45 | |
|
|
46 | /* a macro to get a strongly centered random distribution, |
|
|
47 | from 0 to x, centered at x/2 */ |
|
|
48 | static int |
|
|
49 | bc_random (int x) |
|
|
50 | { |
|
|
51 | return (rndm (x) + rndm (x) + rndm (x)) / 3; |
|
|
52 | } |
47 | |
53 | |
48 | /* returns true if square x,y has P_NO_PASS set, which is true for walls |
54 | /* returns true if square x,y has P_NO_PASS set, which is true for walls |
49 | * and doors but not monsters. |
55 | * and doors but not monsters. |
50 | * This function is not map tile aware. |
56 | * This function is not map tile aware. |
51 | */ |
57 | */ |
52 | |
|
|
53 | int |
58 | int |
54 | wall_blocked (maptile *m, int x, int y) |
59 | wall_blocked (maptile *m, int x, int y) |
55 | { |
60 | { |
56 | int r; |
|
|
57 | |
|
|
58 | if (OUT_OF_REAL_MAP (m, x, y)) |
61 | if (OUT_OF_REAL_MAP (m, x, y)) |
59 | return 1; |
62 | return 1; |
|
|
63 | |
60 | r = GET_MAP_MOVE_BLOCK (m, x, y) & ~MOVE_BLOCK_DEFAULT; |
64 | int r = GET_MAP_MOVE_BLOCK (m, x, y) & ~MOVE_BLOCK_DEFAULT; |
61 | return r; |
65 | return r; |
62 | } |
66 | } |
63 | |
67 | |
64 | /* place treasures in the map, given the |
68 | /* place treasures in the map, given the |
65 | map, (required) |
69 | map, (required) |
66 | layout, (required) |
70 | layout, (required) |
67 | treasure style (may be empty or NULL, or "none" to cause no treasure.) |
71 | treasure style (may be empty or NULL, or "none" to cause no treasure.) |
68 | treasureoptions (may be 0 for random choices or positive) |
72 | treasureoptions (may be 0 for random choices or positive) |
69 | */ |
73 | */ |
70 | |
|
|
71 | void |
74 | void |
72 | place_treasure (maptile *map, char **layout, char *treasure_style, int treasureoptions, RMParms * RP) |
75 | place_treasure (maptile *map, char **layout, char *treasure_style, int treasureoptions, random_map_params *RP) |
73 | { |
76 | { |
74 | char styledirname[256]; |
77 | char styledirname[1024]; |
75 | char stylefilepath[256]; |
78 | char stylefilepath[1024]; |
76 | maptile *style_map = 0; |
79 | maptile *style_map = 0; |
77 | int num_treasures; |
80 | int num_treasures; |
78 | |
81 | |
79 | /* bail out if treasure isn't wanted. */ |
82 | /* bail out if treasure isn't wanted. */ |
80 | if (treasure_style) |
83 | if (treasure_style) |
81 | if (!strcmp (treasure_style, "none")) |
84 | if (!strcmp (treasure_style, "none")) |
82 | return; |
85 | return; |
|
|
86 | |
83 | if (treasureoptions <= 0) |
87 | if (treasureoptions <= 0) |
84 | treasureoptions = RANDOM () % (2 * LAST_OPTION); |
88 | treasureoptions = rndm (2 * LAST_OPTION); |
85 | |
89 | |
86 | /* filter out the mutually exclusive options */ |
90 | /* filter out the mutually exclusive options */ |
87 | if ((treasureoptions & RICH) && (treasureoptions & SPARSE)) |
91 | if ((treasureoptions & RICH) && (treasureoptions & SPARSE)) |
88 | { |
92 | { |
89 | if (RANDOM () % 2) |
93 | if (rndm (2)) |
90 | treasureoptions -= 1; |
94 | treasureoptions -= 1; |
91 | else |
95 | else |
92 | treasureoptions -= 2; |
96 | treasureoptions -= 2; |
93 | } |
97 | } |
94 | |
98 | |
95 | /* pick the number of treasures */ |
99 | /* pick the number of treasures */ |
96 | if (treasureoptions & SPARSE) |
100 | if (treasureoptions & SPARSE) |
97 | num_treasures = BC_RANDOM (RP->total_map_hp / 600 + RP->difficulty / 2 + 1); |
101 | num_treasures = bc_random (RP->total_map_hp / 600 + RP->difficulty / 2 + 1); |
98 | else if (treasureoptions & RICH) |
102 | else if (treasureoptions & RICH) |
99 | num_treasures = BC_RANDOM (RP->total_map_hp / 150 + 2 * RP->difficulty + 1); |
103 | num_treasures = bc_random (RP->total_map_hp / 150 + 2 * RP->difficulty + 1); |
100 | else |
104 | else |
101 | num_treasures = BC_RANDOM (RP->total_map_hp / 300 + RP->difficulty + 1); |
105 | num_treasures = bc_random (RP->total_map_hp / 300 + RP->difficulty + 1); |
102 | |
106 | |
103 | if (num_treasures <= 0) |
107 | if (num_treasures <= 0) |
104 | return; |
108 | return; |
105 | |
109 | |
106 | /* get the style map */ |
110 | /* get the style map */ |
107 | sprintf (styledirname, "%s", "/styles/treasurestyles"); |
111 | sprintf (styledirname, "%s", "/styles/treasurestyles"); |
108 | sprintf (stylefilepath, "%s/%s", styledirname, treasure_style); |
112 | sprintf (stylefilepath, "%s/%s", styledirname, treasure_style); |
109 | style_map = find_style (styledirname, treasure_style, -1); |
113 | style_map = find_style (styledirname, treasure_style, -1); |
110 | |
114 | |
|
|
115 | if (!style_map) |
|
|
116 | { |
|
|
117 | LOG (llevError, "unable to load style map %s %s.\n", styledirname, treasure_style); |
|
|
118 | return; |
|
|
119 | } |
|
|
120 | |
111 | /* all the treasure at one spot in the map. */ |
121 | /* all the treasure at one spot in the map. */ |
112 | if (treasureoptions & CONCENTRATED) |
122 | if (treasureoptions & CONCENTRATED) |
113 | { |
123 | { |
114 | |
124 | |
115 | /* map_layout_style global, and is previously set */ |
125 | /* map_layout_style global, and is previously set */ |
116 | switch (RP->map_layout_style) |
126 | switch (RP->map_layout_style) |
117 | { |
127 | { |
118 | case ONION_LAYOUT: |
128 | case LAYOUT_ONION: |
119 | case SPIRAL_LAYOUT: |
129 | case LAYOUT_SPIRAL: |
120 | case SQUARE_SPIRAL_LAYOUT: |
130 | case LAYOUT_SQUARE_SPIRAL: |
121 | { |
131 | { |
122 | int i, j; |
132 | int i, j; |
123 | |
133 | |
124 | /* search the onion for C's or '>', and put treasure there. */ |
134 | /* search the onion for C's or '>', and put treasure there. */ |
125 | for (i = 0; i < RP->Xsize; i++) |
135 | for (i = 0; i < RP->Xsize; i++) |
126 | { |
136 | { |
127 | for (j = 0; j < RP->Ysize; j++) |
137 | for (j = 0; j < RP->Ysize; j++) |
128 | { |
138 | { |
129 | if (layout[i][j] == 'C' || layout[i][j] == '>') |
139 | if (layout[i][j] == 'C' || layout[i][j] == '>') |
130 | { |
140 | { |
131 | int tdiv = RP->symmetry_used; |
141 | int tdiv = RP->symmetry_used; |
132 | object **doorlist; |
142 | object **doorlist; |
133 | object *chest; |
143 | object *chest; |
134 | |
144 | |
135 | if (tdiv == 3) |
145 | if (tdiv == 3) |
136 | tdiv = 2; /* this symmetry uses a divisor of 2 */ |
146 | tdiv = 2; /* this symmetry uses a divisor of 2 */ |
137 | /* don't put a chest on an exit. */ |
147 | /* don't put a chest on an exit. */ |
138 | chest = place_chest (treasureoptions, i, j, map, style_map, num_treasures / tdiv, RP); |
148 | chest = place_chest (treasureoptions, i, j, map, style_map, num_treasures / tdiv, RP); |
139 | if (!chest) |
149 | if (!chest) |
140 | continue; /* if no chest was placed NEXT */ |
150 | continue; /* if no chest was placed NEXT */ |
141 | if (treasureoptions & (DOORED | HIDDEN)) |
151 | if (treasureoptions & (DOORED | HIDDEN)) |
142 | { |
152 | { |
143 | doorlist = find_doors_in_room (map, i, j, RP); |
153 | doorlist = find_doors_in_room (map, i, j, RP); |
144 | lock_and_hide_doors (doorlist, map, treasureoptions, RP); |
154 | lock_and_hide_doors (doorlist, map, treasureoptions, RP); |
145 | free (doorlist); |
155 | free (doorlist); |
146 | } |
156 | } |
147 | } |
157 | } |
148 | } |
158 | } |
149 | } |
159 | } |
150 | break; |
160 | break; |
151 | } |
161 | } |
152 | default: |
162 | default: |
153 | { |
163 | { |
154 | int i, j, tries; |
164 | int i, j, tries; |
155 | object *chest; |
165 | object *chest; |
156 | object **doorlist; |
166 | object **doorlist; |
157 | |
167 | |
158 | i = j = -1; |
168 | i = j = -1; |
159 | tries = 0; |
169 | tries = 0; |
160 | while (i == -1 && tries < 100) |
170 | while (i == -1 && tries < 100) |
161 | { |
171 | { |
162 | i = RANDOM () % (RP->Xsize - 2) + 1; |
172 | i = rndm (RP->Xsize - 2) + 1; |
163 | j = RANDOM () % (RP->Ysize - 2) + 1; |
173 | j = rndm (RP->Ysize - 2) + 1; |
164 | find_enclosed_spot (map, &i, &j, RP); |
174 | find_enclosed_spot (map, &i, &j, RP); |
165 | if (wall_blocked (map, i, j)) |
175 | if (wall_blocked (map, i, j)) |
166 | i = -1; |
176 | i = -1; |
167 | tries++; |
177 | tries++; |
168 | } |
178 | } |
169 | chest = place_chest (treasureoptions, i, j, map, style_map, num_treasures, RP); |
179 | chest = place_chest (treasureoptions, i, j, map, style_map, num_treasures, RP); |
170 | if (!chest) |
180 | if (!chest) |
171 | return; |
181 | return; |
172 | i = chest->x; |
182 | i = chest->x; |
173 | j = chest->y; |
183 | j = chest->y; |
174 | if (treasureoptions & (DOORED | HIDDEN)) |
184 | if (treasureoptions & (DOORED | HIDDEN)) |
175 | { |
185 | { |
176 | doorlist = surround_by_doors (map, layout, i, j, treasureoptions); |
186 | doorlist = surround_by_doors (map, layout, i, j, treasureoptions); |
177 | lock_and_hide_doors (doorlist, map, treasureoptions, RP); |
187 | lock_and_hide_doors (doorlist, map, treasureoptions, RP); |
178 | free (doorlist); |
188 | free (doorlist); |
179 | } |
189 | } |
180 | } |
190 | } |
181 | } |
191 | } |
182 | } |
192 | } |
183 | else |
193 | else |
184 | { /* DIFFUSE treasure layout */ |
194 | { /* DIFFUSE treasure layout */ |
185 | int ti, i, j; |
195 | int ti, i, j; |
186 | |
196 | |
187 | for (ti = 0; ti < num_treasures; ti++) |
197 | for (ti = 0; ti < num_treasures; ti++) |
188 | { |
198 | { |
189 | i = RANDOM () % (RP->Xsize - 2) + 1; |
199 | i = rndm (RP->Xsize - 2) + 1; |
190 | j = RANDOM () % (RP->Ysize - 2) + 1; |
200 | j = rndm (RP->Ysize - 2) + 1; |
191 | place_chest (treasureoptions, i, j, map, style_map, 1, RP); |
201 | place_chest (treasureoptions, i, j, map, style_map, 1, RP); |
192 | } |
202 | } |
193 | } |
203 | } |
194 | } |
204 | } |
195 | |
|
|
196 | |
|
|
197 | |
205 | |
198 | /* put a chest into the map, near x and y, with the treasure style |
206 | /* put a chest into the map, near x and y, with the treasure style |
199 | determined (may be null, or may be a treasure list from lib/treasures, |
207 | determined (may be null, or may be a treasure list from lib/treasures, |
200 | if the global variable "treasurestyle" is set to that treasure list's name */ |
208 | if the global variable "treasurestyle" is set to that treasure list's name */ |
201 | |
209 | |
202 | object * |
210 | object * |
203 | place_chest (int treasureoptions, int x, int y, maptile *map, maptile *style_map, int n_treasures, RMParms * RP) |
211 | place_chest (int treasureoptions, int x, int y, maptile *map, maptile *style_map, int n_treasures, random_map_params *RP) |
204 | { |
212 | { |
205 | object *the_chest; |
213 | object *the_chest; |
206 | int i, xl, yl; |
214 | int i, xl, yl; |
207 | |
215 | |
208 | the_chest = get_archetype ("chest"); /* was "chest_2" */ |
216 | the_chest = get_archetype ("chest"); /* was "chest_2" */ |
… | |
… | |
212 | if (i == -1) |
220 | if (i == -1) |
213 | { |
221 | { |
214 | the_chest->destroy (); |
222 | the_chest->destroy (); |
215 | return NULL; |
223 | return NULL; |
216 | } |
224 | } |
|
|
225 | |
217 | xl = x + freearr_x[i]; |
226 | xl = x + freearr_x[i]; |
218 | yl = y + freearr_y[i]; |
227 | yl = y + freearr_y[i]; |
219 | |
228 | |
220 | /* if the placement is blocked, return a fail. */ |
229 | /* if the placement is blocked, return a fail. */ |
221 | if (wall_blocked (map, xl, yl)) |
230 | if (wall_blocked (map, xl, yl)) |
222 | return 0; |
231 | return 0; |
223 | |
|
|
224 | |
232 | |
225 | /* put the treasures in the chest. */ |
233 | /* put the treasures in the chest. */ |
226 | /* if(style_map) { */ |
234 | /* if(style_map) { */ |
227 | #if 0 /* don't use treasure style maps for now! */ |
235 | #if 0 /* don't use treasure style maps for now! */ |
228 | int ti; |
236 | int ti; |
… | |
… | |
231 | treasurelist *tlist = find_treasurelist (RP->treasurestyle); |
239 | treasurelist *tlist = find_treasurelist (RP->treasurestyle); |
232 | |
240 | |
233 | if (tlist != NULL) |
241 | if (tlist != NULL) |
234 | for (ti = 0; ti < n_treasures; ti++) |
242 | for (ti = 0; ti < n_treasures; ti++) |
235 | { /* use the treasure list */ |
243 | { /* use the treasure list */ |
236 | object *new_treasure = pick_random_object (style_map); |
244 | object *new_treasure = style_map->pick_random_object (); |
237 | |
245 | |
238 | insert_ob_in_ob (arch_to_object (new_treasure->arch), the_chest); |
246 | insert_ob_in_ob (arch_to_object (new_treasure->arch), the_chest); |
239 | } |
247 | } |
240 | else |
248 | else |
241 | { /* use the style map */ |
249 | { /* use the style map */ |
242 | the_chest->randomitems = tlist; |
250 | the_chest->randomitems = tlist; |
243 | the_chest->stats.hp = n_treasures; |
251 | the_chest->stats.hp = n_treasures; |
244 | } |
252 | } |
245 | #endif |
253 | #endif |
246 | else |
|
|
247 | { /* neither style_map no treasure list given */ |
254 | { /* neither style_map no treasure list given */ |
248 | treasurelist *tlist = find_treasurelist ("chest"); |
255 | treasurelist *tlist = find_treasurelist ("chest"); |
249 | |
256 | |
250 | the_chest->randomitems = tlist; |
257 | the_chest->randomitems = tlist; |
251 | the_chest->stats.hp = n_treasures; |
258 | the_chest->stats.hp = n_treasures; |
… | |
… | |
257 | maptile *trap_map = find_style ("/styles/trapstyles", "traps", -1); |
264 | maptile *trap_map = find_style ("/styles/trapstyles", "traps", -1); |
258 | object *the_trap; |
265 | object *the_trap; |
259 | |
266 | |
260 | if (trap_map) |
267 | if (trap_map) |
261 | { |
268 | { |
262 | the_trap = pick_random_object (trap_map); |
269 | the_trap = trap_map->pick_random_object (); |
263 | the_trap->stats.Cha = 10 + RP->difficulty; |
270 | the_trap->stats.Cha = 10 + RP->difficulty; |
264 | the_trap->level = BC_RANDOM ((3 * RP->difficulty) / 2); |
271 | the_trap->level = bc_random ((3 * RP->difficulty) / 2); |
265 | if (the_trap) |
272 | if (the_trap) |
266 | { |
273 | { |
267 | object *new_trap; |
274 | object *new_trap; |
268 | |
275 | |
269 | new_trap = arch_to_object (the_trap->arch); |
276 | new_trap = arch_to_object (the_trap->arch); |
… | |
… | |
276 | } |
283 | } |
277 | |
284 | |
278 | /* set the chest lock code, and call the keyplacer routine with |
285 | /* set the chest lock code, and call the keyplacer routine with |
279 | the lockcode. It's not worth bothering to lock the chest if |
286 | the lockcode. It's not worth bothering to lock the chest if |
280 | there's only 1 treasure.... */ |
287 | there's only 1 treasure.... */ |
281 | |
|
|
282 | if ((treasureoptions & KEYREQUIRED) && n_treasures > 1) |
288 | if ((treasureoptions & KEYREQUIRED) && n_treasures > 1) |
283 | { |
289 | { |
284 | char keybuf[256]; |
290 | char keybuf[1024]; |
285 | |
291 | |
286 | sprintf (keybuf, "%d", (int) RANDOM ()); |
292 | sprintf (keybuf, "%d", rndm (1000000000)); |
287 | the_chest->slaying = keybuf; |
293 | the_chest->slaying = keybuf; |
288 | keyplace (map, x, y, keybuf, PASS_DOORS, 1, RP); |
294 | keyplace (map, x, y, keybuf, PASS_DOORS, 1, RP); |
289 | } |
295 | } |
290 | |
296 | |
291 | /* actually place the chest. */ |
297 | /* actually place the chest. */ |
… | |
… | |
297 | |
303 | |
298 | |
304 | |
299 | /* finds the closest monster and returns him, regardless of doors |
305 | /* finds the closest monster and returns him, regardless of doors |
300 | or walls */ |
306 | or walls */ |
301 | object * |
307 | object * |
302 | find_closest_monster (maptile *map, int x, int y, RMParms * RP) |
308 | find_closest_monster (maptile *map, int x, int y, random_map_params *RP) |
303 | { |
309 | { |
304 | int i; |
310 | int i; |
305 | |
311 | |
306 | for (i = 0; i < SIZEOFFREE; i++) |
312 | for (i = 0; i < SIZEOFFREE; i++) |
307 | { |
313 | { |
… | |
… | |
334 | it will place 2-4 keys regardless of what nkeys is provided nkeys > 1. |
340 | it will place 2-4 keys regardless of what nkeys is provided nkeys > 1. |
335 | |
341 | |
336 | The idea is that you call keyplace on x,y where a door is, and it'll make |
342 | The idea is that you call keyplace on x,y where a door is, and it'll make |
337 | sure a key is placed on both sides of the door. |
343 | sure a key is placed on both sides of the door. |
338 | */ |
344 | */ |
339 | |
|
|
340 | int |
345 | int |
341 | keyplace (maptile *map, int x, int y, char *keycode, int door_flag, int n_keys, RMParms * RP) |
346 | keyplace (maptile *map, int x, int y, char *keycode, int door_flag, int n_keys, random_map_params *RP) |
342 | { |
347 | { |
343 | int i, j; |
348 | int i, j; |
344 | int kx, ky; |
349 | int kx = 0, ky = 0; |
345 | object *the_keymaster; /* the monster that gets the key. */ |
350 | object *the_keymaster; /* the monster that gets the key. */ |
346 | object *the_key; |
351 | object *the_key; |
347 | |
352 | |
348 | /* get a key and set its keycode */ |
353 | /* get a key and set its keycode */ |
349 | the_key = get_archetype ("key2"); |
354 | the_key = get_archetype ("key2"); |
… | |
… | |
351 | |
356 | |
352 | if (door_flag == PASS_DOORS) |
357 | if (door_flag == PASS_DOORS) |
353 | { |
358 | { |
354 | int tries = 0; |
359 | int tries = 0; |
355 | |
360 | |
356 | the_keymaster = NULL; |
361 | the_keymaster = 0; |
357 | while (tries < 15 && the_keymaster == NULL) |
362 | while (tries < 15 && !the_keymaster) |
358 | { |
363 | { |
359 | i = (RANDOM () % (RP->Xsize - 2)) + 1; |
364 | i = rndm (RP->Xsize - 2) + 1; |
360 | j = (RANDOM () % (RP->Ysize - 2)) + 1; |
365 | j = rndm (RP->Ysize - 2) + 1; |
361 | tries++; |
366 | tries++; |
362 | the_keymaster = find_closest_monster (map, i, j, RP); |
367 | the_keymaster = find_closest_monster (map, i, j, RP); |
363 | } |
368 | } |
|
|
369 | |
364 | /* if we don't find a good keymaster, drop the key on the ground. */ |
370 | /* if we don't find a good keymaster, drop the key on the ground. */ |
365 | if (the_keymaster == NULL) |
371 | if (!the_keymaster) |
366 | { |
372 | { |
367 | int freeindex; |
373 | int freeindex; |
368 | |
374 | |
369 | freeindex = -1; |
375 | freeindex = -1; |
370 | for (tries = 0; tries < 15 && freeindex == -1; tries++) |
376 | for (tries = 0; tries < 15 && freeindex == -1; tries++) |
371 | { |
377 | { |
372 | kx = (RANDOM () % (RP->Xsize - 2)) + 1; |
378 | kx = rndm (RP->Xsize - 2) + 1; |
373 | ky = (RANDOM () % (RP->Ysize - 2)) + 1; |
379 | ky = rndm (RP->Ysize - 2) + 1; |
374 | freeindex = find_first_free_spot (the_key, map, kx, ky); |
380 | freeindex = find_free_spot (the_key, map, kx, ky, 1, SIZEOFFREE1 + 1); |
375 | } |
381 | } |
|
|
382 | |
|
|
383 | // can freeindex ever be < 0? |
376 | if (freeindex != -1) |
384 | if (freeindex >= 0) |
377 | { |
385 | { |
378 | kx += freearr_x[freeindex]; |
386 | kx += freearr_x [freeindex]; |
379 | ky += freearr_y[freeindex]; |
387 | ky += freearr_y [freeindex]; |
380 | } |
388 | } |
381 | } |
389 | } |
382 | } |
390 | } |
383 | else |
391 | else |
384 | { /* NO_PASS_DOORS --we have to work harder. */ |
392 | { /* NO_PASS_DOORS --we have to work harder. */ |
… | |
… | |
386 | NO_PASS_DOORS is set. */ |
394 | NO_PASS_DOORS is set. */ |
387 | if (n_keys == 1) |
395 | if (n_keys == 1) |
388 | { |
396 | { |
389 | if (wall_blocked (map, x, y)) |
397 | if (wall_blocked (map, x, y)) |
390 | return 0; |
398 | return 0; |
|
|
399 | |
391 | the_keymaster = find_monster_in_room (map, x, y, RP); |
400 | the_keymaster = find_monster_in_room (map, x, y, RP); |
392 | if (the_keymaster == NULL) /* if fail, find a spot to drop the key. */ |
401 | if (!the_keymaster) /* if fail, find a spot to drop the key. */ |
393 | find_spot_in_room (map, x, y, &kx, &ky, RP); |
402 | find_spot_in_room (map, x, y, &kx, &ky, RP); |
394 | } |
403 | } |
395 | else |
404 | else |
396 | { |
405 | { |
397 | int sum = 0; /* count how many keys we actually place */ |
406 | int sum = 0; /* count how many keys we actually place */ |
… | |
… | |
399 | /* I'm lazy, so just try to place in all 4 directions. */ |
408 | /* I'm lazy, so just try to place in all 4 directions. */ |
400 | sum += keyplace (map, x + 1, y, keycode, NO_PASS_DOORS, 1, RP); |
409 | sum += keyplace (map, x + 1, y, keycode, NO_PASS_DOORS, 1, RP); |
401 | sum += keyplace (map, x, y + 1, keycode, NO_PASS_DOORS, 1, RP); |
410 | sum += keyplace (map, x, y + 1, keycode, NO_PASS_DOORS, 1, RP); |
402 | sum += keyplace (map, x - 1, y, keycode, NO_PASS_DOORS, 1, RP); |
411 | sum += keyplace (map, x - 1, y, keycode, NO_PASS_DOORS, 1, RP); |
403 | sum += keyplace (map, x, y - 1, keycode, NO_PASS_DOORS, 1, RP); |
412 | sum += keyplace (map, x, y - 1, keycode, NO_PASS_DOORS, 1, RP); |
|
|
413 | |
404 | if (sum < 2) /* we might have made a disconnected map-place more keys. */ |
414 | if (sum < 2) /* we might have made a disconnected map-place more keys. */ |
405 | { /* diagnoally this time. */ |
415 | { /* diagonally this time. */ |
406 | keyplace (map, x + 1, y + 1, keycode, NO_PASS_DOORS, 1, RP); |
416 | keyplace (map, x + 1, y + 1, keycode, NO_PASS_DOORS, 1, RP); |
407 | keyplace (map, x + 1, y - 1, keycode, NO_PASS_DOORS, 1, RP); |
417 | keyplace (map, x + 1, y - 1, keycode, NO_PASS_DOORS, 1, RP); |
408 | keyplace (map, x - 1, y + 1, keycode, NO_PASS_DOORS, 1, RP); |
418 | keyplace (map, x - 1, y + 1, keycode, NO_PASS_DOORS, 1, RP); |
409 | keyplace (map, x - 1, y - 1, keycode, NO_PASS_DOORS, 1, RP); |
419 | keyplace (map, x - 1, y - 1, keycode, NO_PASS_DOORS, 1, RP); |
410 | } |
420 | } |
|
|
421 | |
411 | return 1; |
422 | return 1; |
412 | } |
423 | } |
413 | } |
424 | } |
414 | |
425 | |
415 | if (the_keymaster == NULL) |
426 | if (!the_keymaster) |
416 | { |
427 | { |
417 | the_key->x = kx; |
428 | the_key->x = kx; |
418 | the_key->y = ky; |
429 | the_key->y = ky; |
419 | insert_ob_in_map (the_key, map, NULL, 0); |
430 | insert_ob_in_map (the_key, map, NULL, 0); |
420 | return 1; |
431 | return 1; |
… | |
… | |
432 | |
443 | |
433 | /* a recursive routine which will return a monster, eventually,if there is one. |
444 | /* a recursive routine which will return a monster, eventually,if there is one. |
434 | it does a check-off on the layout, converting 0's to 1's */ |
445 | it does a check-off on the layout, converting 0's to 1's */ |
435 | |
446 | |
436 | object * |
447 | object * |
437 | find_monster_in_room_recursive (char **layout, maptile *map, int x, int y, RMParms * RP) |
448 | find_monster_in_room_recursive (char **layout, maptile *map, int x, int y, random_map_params *RP) |
438 | { |
449 | { |
439 | int i, j; |
450 | int i, j; |
440 | |
451 | |
441 | /* if we've found a monster already, leave */ |
452 | /* if we've found a monster already, leave */ |
442 | if (theMonsterToFind != NULL) |
453 | if (theMonsterToFind != NULL) |
… | |
… | |
465 | return theMonsterToFind; |
476 | return theMonsterToFind; |
466 | } |
477 | } |
467 | } |
478 | } |
468 | |
479 | |
469 | /* now search all the 8 squares around recursively for a monster,in random order */ |
480 | /* now search all the 8 squares around recursively for a monster,in random order */ |
470 | for (i = RANDOM () % 8, j = 0; j < 8 && theMonsterToFind == NULL; i++, j++) |
481 | for (i = rndm (8), j = 0; j < 8 && theMonsterToFind == NULL; i++, j++) |
471 | { |
482 | { |
472 | theMonsterToFind = find_monster_in_room_recursive (layout, map, x + freearr_x[i % 8 + 1], y + freearr_y[i % 8 + 1], RP); |
483 | theMonsterToFind = find_monster_in_room_recursive (layout, map, x + freearr_x[i % 8 + 1], y + freearr_y[i % 8 + 1], RP); |
473 | if (theMonsterToFind != NULL) |
484 | if (theMonsterToFind != NULL) |
474 | return theMonsterToFind; |
485 | return theMonsterToFind; |
475 | } |
486 | } |
… | |
… | |
479 | |
490 | |
480 | /* sets up some data structures: the _recursive form does the |
491 | /* sets up some data structures: the _recursive form does the |
481 | real work. */ |
492 | real work. */ |
482 | |
493 | |
483 | object * |
494 | object * |
484 | find_monster_in_room (maptile *map, int x, int y, RMParms * RP) |
495 | find_monster_in_room (maptile *map, int x, int y, random_map_params *RP) |
485 | { |
496 | { |
486 | char **layout2; |
497 | char **layout2; |
487 | int i, j; |
498 | int i, j; |
488 | |
499 | |
489 | theMonsterToFind = 0; |
500 | theMonsterToFind = 0; |
… | |
… | |
508 | free (layout2); |
519 | free (layout2); |
509 | |
520 | |
510 | return theMonsterToFind; |
521 | return theMonsterToFind; |
511 | } |
522 | } |
512 | |
523 | |
513 | |
|
|
514 | |
|
|
515 | |
|
|
516 | /* a datastructure needed by find_spot_in_room and find_spot_in_room_recursive */ |
524 | /* a datastructure needed by find_spot_in_room and find_spot_in_room_recursive */ |
517 | int *room_free_spots_x; |
525 | int *room_free_spots_x; |
518 | int *room_free_spots_y; |
526 | int *room_free_spots_y; |
519 | int number_of_free_spots_in_room; |
527 | int number_of_free_spots_in_room; |
520 | |
528 | |
521 | /* the workhorse routine, which finds the free spots in a room: |
529 | /* the workhorse routine, which finds the free spots in a room: |
522 | a datastructure of free points is set up, and a position chosen from |
530 | a datastructure of free points is set up, and a position chosen from |
523 | that datastructure. */ |
531 | that datastructure. */ |
524 | |
|
|
525 | void |
532 | void |
526 | find_spot_in_room_recursive (char **layout, int x, int y, RMParms * RP) |
533 | find_spot_in_room_recursive (char **layout, int x, int y, random_map_params *RP) |
527 | { |
534 | { |
528 | int i, j; |
535 | int i, j; |
529 | |
536 | |
530 | /* bounds check x and y */ |
537 | /* bounds check x and y */ |
531 | if (!(x >= 0 && y >= 0 && x < RP->Xsize && y < RP->Ysize)) |
538 | if (!(x >= 0 && y >= 0 && x < RP->Xsize && y < RP->Ysize)) |
… | |
… | |
540 | /* check off this point */ |
547 | /* check off this point */ |
541 | layout[x][y] = 1; |
548 | layout[x][y] = 1; |
542 | room_free_spots_x[number_of_free_spots_in_room] = x; |
549 | room_free_spots_x[number_of_free_spots_in_room] = x; |
543 | room_free_spots_y[number_of_free_spots_in_room] = y; |
550 | room_free_spots_y[number_of_free_spots_in_room] = y; |
544 | number_of_free_spots_in_room++; |
551 | number_of_free_spots_in_room++; |
|
|
552 | |
545 | /* now search all the 8 squares around recursively for free spots,in random order */ |
553 | /* now search all the 8 squares around recursively for free spots,in random order */ |
546 | for (i = RANDOM () % 8, j = 0; j < 8 && theMonsterToFind == NULL; i++, j++) |
554 | for (i = rndm (8), j = 0; j < 8 && theMonsterToFind == NULL; i++, j++) |
547 | { |
|
|
548 | find_spot_in_room_recursive (layout, x + freearr_x[i % 8 + 1], y + freearr_y[i % 8 + 1], RP); |
555 | find_spot_in_room_recursive (layout, x + freearr_x[i % 8 + 1], y + freearr_y[i % 8 + 1], RP); |
549 | } |
|
|
550 | |
556 | |
551 | } |
557 | } |
552 | |
558 | |
553 | /* find a random non-blocked spot in this room to drop a key. */ |
559 | /* find a random non-blocked spot in this room to drop a key. */ |
554 | void |
560 | void |
555 | find_spot_in_room (maptile *map, int x, int y, int *kx, int *ky, RMParms * RP) |
561 | find_spot_in_room (maptile *map, int x, int y, int *kx, int *ky, random_map_params *RP) |
556 | { |
562 | { |
557 | char **layout2; |
563 | char **layout2; |
558 | int i, j; |
564 | int i, j; |
559 | |
565 | |
560 | number_of_free_spots_in_room = 0; |
566 | number_of_free_spots_in_room = 0; |
… | |
… | |
565 | /* allocate and copy the layout, converting C to 0. */ |
571 | /* allocate and copy the layout, converting C to 0. */ |
566 | for (i = 0; i < RP->Xsize; i++) |
572 | for (i = 0; i < RP->Xsize; i++) |
567 | { |
573 | { |
568 | layout2[i] = (char *) calloc (sizeof (char), RP->Ysize); |
574 | layout2[i] = (char *) calloc (sizeof (char), RP->Ysize); |
569 | for (j = 0; j < RP->Ysize; j++) |
575 | for (j = 0; j < RP->Ysize; j++) |
570 | { |
|
|
571 | if (wall_blocked (map, i, j)) |
576 | if (wall_blocked (map, i, j)) |
572 | layout2[i][j] = '#'; |
577 | layout2[i][j] = '#'; |
573 | } |
|
|
574 | } |
578 | } |
575 | |
579 | |
576 | /* setup num_free_spots and room_free_spots */ |
580 | /* setup num_free_spots and room_free_spots */ |
577 | find_spot_in_room_recursive (layout2, x, y, RP); |
581 | find_spot_in_room_recursive (layout2, x, y, RP); |
578 | |
582 | |
579 | if (number_of_free_spots_in_room > 0) |
583 | if (number_of_free_spots_in_room > 0) |
580 | { |
584 | { |
581 | i = RANDOM () % number_of_free_spots_in_room; |
585 | i = rndm (number_of_free_spots_in_room); |
582 | *kx = room_free_spots_x[i]; |
586 | *kx = room_free_spots_x[i]; |
583 | *ky = room_free_spots_y[i]; |
587 | *ky = room_free_spots_y[i]; |
584 | } |
588 | } |
585 | |
589 | |
586 | /* deallocate the temp. layout */ |
590 | /* deallocate the temp. layout */ |
587 | for (i = 0; i < RP->Xsize; i++) |
591 | for (i = 0; i < RP->Xsize; i++) |
588 | { |
|
|
589 | free (layout2[i]); |
592 | free (layout2[i]); |
590 | } |
593 | |
591 | free (layout2); |
594 | free (layout2); |
592 | free (room_free_spots_x); |
595 | free (room_free_spots_x); |
593 | free (room_free_spots_y); |
596 | free (room_free_spots_y); |
594 | } |
597 | } |
595 | |
598 | |
596 | |
599 | |
597 | /* searches the map for a spot with walls around it. The more |
600 | /* searches the map for a spot with walls around it. The more |
598 | walls the better, but it'll settle for 1 wall, or even 0, but |
601 | walls the better, but it'll settle for 1 wall, or even 0, but |
599 | it'll return 0 if no FREE spots are found.*/ |
602 | it'll return 0 if no FREE spots are found.*/ |
600 | |
|
|
601 | void |
603 | void |
602 | find_enclosed_spot (maptile *map, int *cx, int *cy, RMParms * RP) |
604 | find_enclosed_spot (maptile *map, int *cx, int *cy, random_map_params *RP) |
603 | { |
605 | { |
604 | int x, y; |
606 | int x, y; |
605 | int i; |
607 | int i; |
606 | |
608 | |
607 | x = *cx; |
609 | x = *cx; |
… | |
… | |
656 | *cy = ly; |
658 | *cy = ly; |
657 | return; |
659 | return; |
658 | } |
660 | } |
659 | } |
661 | } |
660 | /* give up and return the closest free spot. */ |
662 | /* give up and return the closest free spot. */ |
661 | i = find_first_free_spot (&archetype::find ("chest")->clone, map, x, y); |
663 | i = find_free_spot (&archetype::find ("chest")->clone, map, x, y, 1, SIZEOFFREE1 + 1); |
662 | if (i != -1 && i <= SIZEOFFREE1) |
664 | |
|
|
665 | if (i != -1) |
663 | { |
666 | { |
664 | *cx = x + freearr_x[i]; |
667 | *cx = x + freearr_x[i]; |
665 | *cy = y + freearr_y[i]; |
668 | *cy = y + freearr_y[i]; |
666 | return; |
669 | } |
|
|
670 | else |
667 | } |
671 | { |
668 | /* indicate failure */ |
672 | /* indicate failure */ |
|
|
673 | *cx = -1; |
669 | *cx = *cy = -1; |
674 | *cy = -1; |
|
|
675 | } |
670 | } |
676 | } |
671 | |
|
|
672 | |
677 | |
673 | void |
678 | void |
674 | remove_monsters (int x, int y, maptile *map) |
679 | remove_monsters (int x, int y, maptile *map) |
675 | { |
680 | { |
676 | object *tmp; |
681 | object *tmp; |
677 | |
682 | |
678 | for (tmp = GET_MAP_OB (map, x, y); tmp != NULL; tmp = tmp->above) |
683 | for (tmp = GET_MAP_OB (map, x, y); tmp; tmp = tmp->above) |
679 | if (QUERY_FLAG (tmp, FLAG_ALIVE)) |
684 | if (QUERY_FLAG (tmp, FLAG_ALIVE)) |
680 | { |
685 | { |
681 | if (tmp->head) |
686 | if (tmp->head) |
682 | tmp = tmp->head; |
687 | tmp = tmp->head; |
683 | tmp->remove (); |
688 | tmp->remove (); |
… | |
… | |
686 | if (tmp == NULL) |
691 | if (tmp == NULL) |
687 | break; |
692 | break; |
688 | }; |
693 | }; |
689 | } |
694 | } |
690 | |
695 | |
691 | |
|
|
692 | /* surrounds the point x,y by doors, so as to enclose something, like |
696 | /* surrounds the point x,y by doors, so as to enclose something, like |
693 | a chest. It only goes as far as the 8 squares surrounding, and |
697 | a chest. It only goes as far as the 8 squares surrounding, and |
694 | it'll remove any monsters it finds.*/ |
698 | it'll remove any monsters it finds.*/ |
695 | |
|
|
696 | object ** |
699 | object ** |
697 | surround_by_doors (maptile *map, char **layout, int x, int y, int opts) |
700 | surround_by_doors (maptile *map, char **layout, int x, int y, int opts) |
698 | { |
701 | { |
699 | int i; |
702 | int i; |
700 | char *doors[2]; |
703 | char *doors[2]; |
… | |
… | |
717 | /* place doors in all the 8 adjacent unblocked squares. */ |
720 | /* place doors in all the 8 adjacent unblocked squares. */ |
718 | for (i = 1; i < 9; i++) |
721 | for (i = 1; i < 9; i++) |
719 | { |
722 | { |
720 | int x1 = x + freearr_x[i], y1 = y + freearr_y[i]; |
723 | int x1 = x + freearr_x[i], y1 = y + freearr_y[i]; |
721 | |
724 | |
722 | if (!wall_blocked (map, x1, y1) || layout[x1][y1] == '>') |
725 | if (!wall_blocked (map, x1, y1) && layout[x1][y1] == '>') |
723 | { /* place a door */ |
726 | { /* place a door */ |
|
|
727 | remove_monsters (x1, y1, map); |
|
|
728 | |
724 | object *new_door = get_archetype ((freearr_x[i] == 0) ? doors[1] : doors[0]); |
729 | object *new_door = get_archetype (freearr_x[i] == 0 ? doors[1] : doors[0]); |
725 | |
730 | map->insert (new_door, x1, y1); |
726 | new_door->x = x + freearr_x[i]; |
|
|
727 | new_door->y = y + freearr_y[i]; |
|
|
728 | remove_monsters (new_door->x, new_door->y, map); |
|
|
729 | insert_ob_in_map (new_door, map, NULL, 0); |
|
|
730 | doorlist[ndoors_made] = new_door; |
731 | doorlist[ndoors_made] = new_door; |
731 | ndoors_made++; |
732 | ndoors_made++; |
732 | } |
733 | } |
733 | } |
734 | } |
|
|
735 | |
734 | return doorlist; |
736 | return doorlist; |
735 | } |
737 | } |
736 | |
738 | |
737 | |
739 | |
738 | /* returns the first door in this square, or NULL if there isn't a door. */ |
740 | /* returns the first door in this square, or NULL if there isn't a door. */ |
… | |
… | |
748 | } |
750 | } |
749 | |
751 | |
750 | |
752 | |
751 | /* the workhorse routine, which finds the doors in a room */ |
753 | /* the workhorse routine, which finds the doors in a room */ |
752 | void |
754 | void |
753 | find_doors_in_room_recursive (char **layout, maptile *map, int x, int y, object **doorlist, int *ndoors, RMParms * RP) |
755 | find_doors_in_room_recursive (char **layout, maptile *map, int x, int y, object **doorlist, int *ndoors, random_map_params *RP) |
754 | { |
756 | { |
755 | int i, j; |
757 | int i, j; |
756 | object *door; |
758 | object *door; |
757 | |
759 | |
758 | /* bounds check x and y */ |
760 | /* bounds check x and y */ |
… | |
… | |
766 | /* check off this point */ |
768 | /* check off this point */ |
767 | if (layout[x][y] == '#') |
769 | if (layout[x][y] == '#') |
768 | { /* there could be a door here */ |
770 | { /* there could be a door here */ |
769 | layout[x][y] = 1; |
771 | layout[x][y] = 1; |
770 | door = door_in_square (map, x, y); |
772 | door = door_in_square (map, x, y); |
771 | if (door != NULL) |
773 | if (door) |
772 | { |
774 | { |
773 | doorlist[*ndoors] = door; |
775 | doorlist[*ndoors] = door; |
774 | if (*ndoors > 254) /* eek! out of memory */ |
776 | if (*ndoors > 1022) /* eek! out of memory */ |
775 | { |
777 | { |
776 | LOG (llevError, "find_doors_in_room_recursive:Too many doors for memory allocated!\n"); |
778 | LOG (llevError, "find_doors_in_room_recursive:Too many doors for memory allocated!\n"); |
777 | return; |
779 | return; |
778 | } |
780 | } |
|
|
781 | |
779 | *ndoors = *ndoors + 1; |
782 | *ndoors = *ndoors + 1; |
780 | } |
783 | } |
781 | } |
784 | } |
782 | else |
785 | else |
783 | { |
786 | { |
784 | layout[x][y] = 1; |
787 | layout[x][y] = 1; |
|
|
788 | |
785 | /* now search all the 8 squares around recursively for free spots,in random order */ |
789 | /* now search all the 8 squares around recursively for free spots,in random order */ |
786 | for (i = RANDOM () % 8, j = 0; j < 8 && theMonsterToFind == NULL; i++, j++) |
790 | for (i = rndm (8), j = 0; j < 8 && !theMonsterToFind; i++, j++) |
787 | { |
791 | find_doors_in_room_recursive (layout, map, |
788 | find_doors_in_room_recursive (layout, map, x + freearr_x[i % 8 + 1], y + freearr_y[i % 8 + 1], doorlist, ndoors, RP); |
792 | x + freearr_x[i % 8 + 1], y + freearr_y[i % 8 + 1], |
789 | } |
793 | doorlist, ndoors, RP); |
790 | } |
794 | } |
791 | } |
795 | } |
792 | |
796 | |
793 | /* find a random non-blocked spot in this room to drop a key. */ |
797 | /* find a random non-blocked spot in this room to drop a key. */ |
794 | object ** |
798 | object ** |
795 | find_doors_in_room (maptile *map, int x, int y, RMParms * RP) |
799 | find_doors_in_room (maptile *map, int x, int y, random_map_params *RP) |
796 | { |
800 | { |
797 | char **layout2; |
801 | char **layout2; |
798 | object **doorlist; |
802 | object **doorlist; |
799 | int i, j; |
803 | int i, j; |
800 | int ndoors = 0; |
804 | int ndoors = 0; |
801 | |
805 | |
802 | doorlist = (object **) calloc (sizeof (int), 256); |
806 | doorlist = (object **) calloc (sizeof (int), 1024); |
803 | |
|
|
804 | |
807 | |
805 | layout2 = (char **) calloc (sizeof (char *), RP->Xsize); |
808 | layout2 = (char **) calloc (sizeof (char *), RP->Xsize); |
806 | /* allocate and copy the layout, converting C to 0. */ |
809 | /* allocate and copy the layout, converting C to 0. */ |
807 | for (i = 0; i < RP->Xsize; i++) |
810 | for (i = 0; i < RP->Xsize; i++) |
808 | { |
811 | { |
… | |
… | |
817 | /* setup num_free_spots and room_free_spots */ |
820 | /* setup num_free_spots and room_free_spots */ |
818 | find_doors_in_room_recursive (layout2, map, x, y, doorlist, &ndoors, RP); |
821 | find_doors_in_room_recursive (layout2, map, x, y, doorlist, &ndoors, RP); |
819 | |
822 | |
820 | /* deallocate the temp. layout */ |
823 | /* deallocate the temp. layout */ |
821 | for (i = 0; i < RP->Xsize; i++) |
824 | for (i = 0; i < RP->Xsize; i++) |
822 | { |
|
|
823 | free (layout2[i]); |
825 | free (layout2[i]); |
824 | } |
826 | |
825 | free (layout2); |
827 | free (layout2); |
826 | return doorlist; |
828 | return doorlist; |
827 | } |
829 | } |
828 | |
830 | |
829 | |
831 | |
830 | |
832 | |
831 | /* locks and/or hides all the doors in doorlist, or does nothing if |
833 | /* locks and/or hides all the doors in doorlist, or does nothing if |
832 | opts doesn't say to lock/hide doors. */ |
834 | opts doesn't say to lock/hide doors. */ |
833 | |
835 | |
834 | void |
836 | void |
835 | lock_and_hide_doors (object **doorlist, maptile *map, int opts, RMParms * RP) |
837 | lock_and_hide_doors (object **doorlist, maptile *map, int opts, random_map_params *RP) |
836 | { |
838 | { |
837 | object *door; |
839 | object *door; |
838 | int i; |
840 | int i; |
839 | |
841 | |
840 | /* lock the doors and hide the keys. */ |
842 | /* lock the doors and hide the keys. */ |
… | |
… | |
842 | if (opts & DOORED) |
844 | if (opts & DOORED) |
843 | { |
845 | { |
844 | for (i = 0, door = doorlist[0]; doorlist[i] != NULL; i++) |
846 | for (i = 0, door = doorlist[0]; doorlist[i] != NULL; i++) |
845 | { |
847 | { |
846 | object *new_door = get_archetype ("locked_door1"); |
848 | object *new_door = get_archetype ("locked_door1"); |
847 | char keybuf[256]; |
849 | char keybuf[1024]; |
848 | |
850 | |
849 | door = doorlist[i]; |
851 | door = doorlist[i]; |
850 | new_door->face = door->face; |
852 | new_door->face = door->face; |
851 | new_door->x = door->x; |
853 | new_door->x = door->x; |
852 | new_door->y = door->y; |
854 | new_door->y = door->y; |
853 | door->remove (); |
855 | door->remove (); |
854 | door->destroy (); |
856 | door->destroy (); |
855 | doorlist[i] = new_door; |
857 | doorlist[i] = new_door; |
856 | insert_ob_in_map (new_door, map, NULL, 0); |
858 | insert_ob_in_map (new_door, map, NULL, 0); |
857 | sprintf (keybuf, "%d", (int) RANDOM ()); |
859 | sprintf (keybuf, "%d", rndm (1000000000)); |
858 | new_door->slaying = keybuf; |
860 | new_door->slaying = keybuf; |
859 | keyplace (map, new_door->x, new_door->y, keybuf, NO_PASS_DOORS, 2, RP); |
861 | keyplace (map, new_door->x, new_door->y, keybuf, NO_PASS_DOORS, 2, RP); |
860 | } |
862 | } |
861 | } |
863 | } |
862 | |
864 | |