… | |
… | |
79 | keyplace (maptile *map, int x, int y, const shstr &keycode, int door_flag, int n_keys, random_map_params *RP) |
79 | keyplace (maptile *map, int x, int y, const shstr &keycode, int door_flag, int n_keys, random_map_params *RP) |
80 | { |
80 | { |
81 | int i, j; |
81 | int i, j; |
82 | int kx = 0, ky = 0; |
82 | int kx = 0, ky = 0; |
83 | object *the_keymaster; /* the monster that gets the key. */ |
83 | object *the_keymaster; /* the monster that gets the key. */ |
|
|
84 | object *the_key = gen_key (keycode); |
84 | |
85 | |
85 | if (door_flag == PASS_DOORS) |
86 | if (door_flag == PASS_DOORS) |
86 | { |
87 | { |
87 | int tries = 0; |
88 | int tries = 0; |
88 | |
89 | |
… | |
… | |
103 | freeindex = -1; |
104 | freeindex = -1; |
104 | for (tries = 0; tries < 15 && freeindex == -1; tries++) |
105 | for (tries = 0; tries < 15 && freeindex == -1; tries++) |
105 | { |
106 | { |
106 | kx = rmg_rndm (RP->Xsize - 2) + 1; |
107 | kx = rmg_rndm (RP->Xsize - 2) + 1; |
107 | ky = rmg_rndm (RP->Ysize - 2) + 1; |
108 | ky = rmg_rndm (RP->Ysize - 2) + 1; |
108 | freeindex = find_free_spot (gen_key (keycode), map, kx, ky, 1, SIZEOFFREE1 + 1); |
109 | freeindex = find_free_spot (the_key, map, kx, ky, 1, SIZEOFFREE1 + 1); |
109 | } |
110 | } |
110 | |
111 | |
111 | // can freeindex ever be < 0? |
112 | // can freeindex ever be < 0? |
112 | if (freeindex >= 0) |
113 | if (freeindex >= 0) |
113 | { |
114 | { |
… | |
… | |
121 | /* don't try to keyplace if we're sitting on a blocked square and |
122 | /* don't try to keyplace if we're sitting on a blocked square and |
122 | NO_PASS_DOORS is set. */ |
123 | NO_PASS_DOORS is set. */ |
123 | if (n_keys == 1) |
124 | if (n_keys == 1) |
124 | { |
125 | { |
125 | if (wall_blocked (map, x, y)) |
126 | if (wall_blocked (map, x, y)) |
|
|
127 | { |
|
|
128 | the_key->destroy (); |
126 | return 0; |
129 | return 0; |
|
|
130 | } |
127 | |
131 | |
128 | the_keymaster = find_monster_in_room (map, x, y, RP); |
132 | the_keymaster = find_monster_in_room (map, x, y, RP); |
129 | if (!the_keymaster) /* if fail, find a spot to drop the key. */ |
133 | if (!the_keymaster) /* if fail, find a spot to drop the key. */ |
130 | find_spot_in_room (map, x, y, &kx, &ky, RP); |
134 | find_spot_in_room (map, x, y, &kx, &ky, RP); |
131 | } |
135 | } |
… | |
… | |
145 | keyplace (map, x + 1, y - 1, keycode, NO_PASS_DOORS, 1, RP); |
149 | keyplace (map, x + 1, y - 1, keycode, NO_PASS_DOORS, 1, RP); |
146 | keyplace (map, x - 1, y + 1, keycode, NO_PASS_DOORS, 1, RP); |
150 | keyplace (map, x - 1, y + 1, keycode, NO_PASS_DOORS, 1, RP); |
147 | keyplace (map, x - 1, y - 1, keycode, NO_PASS_DOORS, 1, RP); |
151 | keyplace (map, x - 1, y - 1, keycode, NO_PASS_DOORS, 1, RP); |
148 | } |
152 | } |
149 | |
153 | |
|
|
154 | the_key->destroy (); |
150 | return 1; |
155 | return 1; |
151 | } |
156 | } |
152 | } |
157 | } |
153 | |
|
|
154 | object *the_key = gen_key (keycode); |
|
|
155 | |
158 | |
156 | if (the_keymaster) |
159 | if (the_keymaster) |
157 | the_keymaster->head_ ()->insert (the_key); |
160 | the_keymaster->head_ ()->insert (the_key); |
158 | else |
161 | else |
159 | { |
162 | { |