… | |
… | |
52 | |
52 | |
53 | static object * |
53 | static object * |
54 | gen_key (const shstr &keycode) |
54 | gen_key (const shstr &keycode) |
55 | { |
55 | { |
56 | /* get a key and set its keycode */ |
56 | /* get a key and set its keycode */ |
57 | object *key = archetype::get (shstr_key2); |
57 | object *key = archetype::get (shstr_key_random_map); |
58 | |
|
|
59 | key->slaying = keycode; |
58 | key->slaying = keycode; |
60 | key->stats.food = 100; |
|
|
61 | key->speed_left = -1.f; |
|
|
62 | key->flag [FLAG_IS_USED_UP] = true; |
|
|
63 | key->set_speed (1.f / 300.f); |
|
|
64 | |
|
|
65 | return key; |
59 | return key; |
66 | } |
60 | } |
67 | |
61 | |
68 | /* places keys in the map, preferably in something alive. |
62 | /* places keys in the map, preferably in something alive. |
69 | keycode is the key's code, |
63 | keycode is the key's code, |
… | |
… | |
79 | keyplace (maptile *map, int x, int y, const shstr &keycode, int door_flag, int n_keys, random_map_params *RP) |
73 | keyplace (maptile *map, int x, int y, const shstr &keycode, int door_flag, int n_keys, random_map_params *RP) |
80 | { |
74 | { |
81 | int i, j; |
75 | int i, j; |
82 | int kx = 0, ky = 0; |
76 | int kx = 0, ky = 0; |
83 | object *the_keymaster; /* the monster that gets the key. */ |
77 | object *the_keymaster; /* the monster that gets the key. */ |
|
|
78 | object *the_key = gen_key (keycode); |
84 | |
79 | |
85 | if (door_flag == PASS_DOORS) |
80 | if (door_flag == PASS_DOORS) |
86 | { |
81 | { |
87 | int tries = 0; |
82 | int tries = 0; |
88 | |
83 | |
… | |
… | |
103 | freeindex = -1; |
98 | freeindex = -1; |
104 | for (tries = 0; tries < 15 && freeindex == -1; tries++) |
99 | for (tries = 0; tries < 15 && freeindex == -1; tries++) |
105 | { |
100 | { |
106 | kx = rmg_rndm (RP->Xsize - 2) + 1; |
101 | kx = rmg_rndm (RP->Xsize - 2) + 1; |
107 | ky = rmg_rndm (RP->Ysize - 2) + 1; |
102 | ky = rmg_rndm (RP->Ysize - 2) + 1; |
108 | freeindex = find_free_spot (gen_key (keycode), map, kx, ky, 1, SIZEOFFREE1 + 1); |
103 | freeindex = find_free_spot (the_key, map, kx, ky, 1, SIZEOFFREE1 + 1); |
109 | } |
104 | } |
110 | |
105 | |
111 | // can freeindex ever be < 0? |
106 | // can freeindex ever be < 0? |
112 | if (freeindex >= 0) |
107 | if (freeindex >= 0) |
113 | { |
108 | { |
… | |
… | |
121 | /* don't try to keyplace if we're sitting on a blocked square and |
116 | /* don't try to keyplace if we're sitting on a blocked square and |
122 | NO_PASS_DOORS is set. */ |
117 | NO_PASS_DOORS is set. */ |
123 | if (n_keys == 1) |
118 | if (n_keys == 1) |
124 | { |
119 | { |
125 | if (wall_blocked (map, x, y)) |
120 | if (wall_blocked (map, x, y)) |
|
|
121 | { |
|
|
122 | the_key->destroy (); |
126 | return 0; |
123 | return 0; |
|
|
124 | } |
127 | |
125 | |
128 | the_keymaster = find_monster_in_room (map, x, y, RP); |
126 | the_keymaster = find_monster_in_room (map, x, y, RP); |
129 | if (!the_keymaster) /* if fail, find a spot to drop the key. */ |
127 | if (!the_keymaster) /* if fail, find a spot to drop the key. */ |
130 | find_spot_in_room (map, x, y, &kx, &ky, RP); |
128 | find_spot_in_room (map, x, y, &kx, &ky, RP); |
131 | } |
129 | } |
… | |
… | |
145 | keyplace (map, x + 1, y - 1, keycode, NO_PASS_DOORS, 1, RP); |
143 | 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); |
144 | 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); |
145 | keyplace (map, x - 1, y - 1, keycode, NO_PASS_DOORS, 1, RP); |
148 | } |
146 | } |
149 | |
147 | |
|
|
148 | the_key->destroy (); |
150 | return 1; |
149 | return 1; |
151 | } |
150 | } |
152 | } |
151 | } |
153 | |
152 | |
154 | object *the_key = gen_key (keycode); |
153 | LOG(llevError, "key %d,%d %p\n", the_keymaster ? the_keymaster->x : x, the_keymaster ? the_keymaster->y : y, the_keymaster+0);//D |
155 | |
|
|
156 | if (the_keymaster) |
154 | if (the_keymaster) |
157 | the_keymaster->head_ ()->insert (the_key); |
155 | the_keymaster->head_ ()->insert (the_key); |
158 | else |
156 | else |
159 | { |
157 | { |
160 | the_key->x = kx; |
158 | the_key->x = kx; |
… | |
… | |
825 | |
823 | |
826 | if (opts & DOORED) |
824 | if (opts & DOORED) |
827 | { |
825 | { |
828 | for (i = 0, door = doorlist[0]; doorlist[i] != NULL; i++) |
826 | for (i = 0, door = doorlist[0]; doorlist[i] != NULL; i++) |
829 | { |
827 | { |
830 | object *new_door = get_archetype ("locked_door1"); |
828 | object *new_door = get_archetype (shstr_locked_door1); |
831 | |
829 | |
832 | door = doorlist[i]; |
830 | door = doorlist[i]; |
833 | new_door->face = door->face; |
831 | new_door->face = door->face; |
834 | new_door->x = door->x; |
832 | new_door->x = door->x; |
835 | new_door->y = door->y; |
833 | new_door->y = door->y; |