… | |
… | |
87 | } |
87 | } |
88 | |
88 | |
89 | op->destroy (); |
89 | op->destroy (); |
90 | } |
90 | } |
91 | |
91 | |
92 | /* Will generate a monster according to content |
|
|
93 | * of generator. |
|
|
94 | */ |
|
|
95 | void |
92 | void |
96 | generate_monster_inv (object *gen) |
93 | generate_monster (object *gen) |
97 | { |
94 | { |
98 | int i; |
|
|
99 | object *op, *head = NULL; |
|
|
100 | |
|
|
101 | int qty = 0; |
|
|
102 | |
|
|
103 | /* Code below assumes the generator is on a map, as it tries |
|
|
104 | * to place the monster on the map. So if the generator |
|
|
105 | * isn't on a map, complain and exit. |
|
|
106 | */ |
|
|
107 | if (gen->map == NULL) |
|
|
108 | { |
|
|
109 | //LOG(llevError,"Generator (%s) not on a map?\n", gen->name); |
|
|
110 | return; |
|
|
111 | } |
|
|
112 | |
|
|
113 | /*First count numer of objects in inv */ |
|
|
114 | for (op = gen->inv; op; op = op->below) |
|
|
115 | qty++; |
|
|
116 | |
|
|
117 | if (!qty) |
|
|
118 | { |
|
|
119 | LOG (llevError, "Generator (%s) has no inventory in generate_monster_inv?\n", &gen->name); |
|
|
120 | return; /*No inventory */ |
|
|
121 | } |
|
|
122 | qty = rndm (0, qty - 1); |
|
|
123 | for (op = gen->inv; qty; qty--) |
|
|
124 | op = op->below; |
|
|
125 | |
|
|
126 | i = find_free_spot (op, gen->map, gen->x, gen->y, 1, 9); |
|
|
127 | if (i == -1) |
|
|
128 | return; |
|
|
129 | |
|
|
130 | head = object_create_clone (op); |
|
|
131 | CLEAR_FLAG (head, FLAG_IS_A_TEMPLATE); |
|
|
132 | unflag_inv (head, FLAG_IS_A_TEMPLATE); |
|
|
133 | if (rndm (0, 9)) |
|
|
134 | generate_artifact (head, gen->map->difficulty); |
|
|
135 | |
|
|
136 | insert_ob_in_map_at (head, gen->map, gen, 0, gen->x + freearr_x[i], gen->y + freearr_y[i]); |
|
|
137 | if (QUERY_FLAG (head, FLAG_FREED)) |
|
|
138 | return; |
|
|
139 | |
|
|
140 | if (head->has_random_items ()) |
|
|
141 | create_treasure (head->randomitems, head, GT_APPLY, gen->map->difficulty, 0); |
|
|
142 | } |
|
|
143 | |
|
|
144 | void |
|
|
145 | generate_monster_arch (object *gen) |
|
|
146 | { |
|
|
147 | int i; |
|
|
148 | object *op, *head = NULL, *prev = NULL; |
|
|
149 | archetype *at = gen->other_arch; |
|
|
150 | |
|
|
151 | if (!gen->other_arch) |
|
|
152 | return; |
|
|
153 | |
|
|
154 | /* Code below assumes the generator is on a map, as it tries |
|
|
155 | * to place the monster on the map. So if the generator |
|
|
156 | * isn't on a map, complain and exit. |
|
|
157 | */ |
|
|
158 | if (!gen->map) |
95 | if (!gen->map) |
159 | return; |
96 | return; |
160 | |
97 | |
161 | i = find_free_spot (&at->clone, gen->map, gen->x, gen->y, 1, 9); |
|
|
162 | if (i == -1) |
|
|
163 | return; |
|
|
164 | |
|
|
165 | while (at) |
|
|
166 | { |
|
|
167 | op = arch_to_object (at); |
|
|
168 | op->x = gen->x + freearr_x[i] + at->clone.x; |
|
|
169 | op->y = gen->y + freearr_y[i] + at->clone.y; |
|
|
170 | |
|
|
171 | if (head) |
|
|
172 | op->head = head, prev->more = op; |
|
|
173 | |
|
|
174 | if (rndm (0, 9)) |
|
|
175 | generate_artifact (op, gen->map->difficulty); |
|
|
176 | |
|
|
177 | insert_ob_in_map (op, gen->map, gen, 0); |
|
|
178 | if (QUERY_FLAG (op, FLAG_FREED)) |
|
|
179 | return; |
|
|
180 | |
|
|
181 | if (op->has_random_items ()) |
|
|
182 | create_treasure (op->randomitems, op, GT_APPLY, gen->map->difficulty, 0); |
|
|
183 | |
|
|
184 | if (head == NULL) |
|
|
185 | head = op; |
|
|
186 | |
|
|
187 | prev = op; |
|
|
188 | at = at->more; |
|
|
189 | } |
|
|
190 | } |
|
|
191 | |
|
|
192 | void |
|
|
193 | generate_monster (object *gen) |
|
|
194 | { |
|
|
195 | |
|
|
196 | if (GENERATE_SPEED (gen) && rndm (0, GENERATE_SPEED (gen) - 1)) |
98 | if (GENERATE_SPEED (gen) && rndm (0, GENERATE_SPEED (gen) - 1)) |
197 | return; |
99 | return; |
198 | |
100 | |
|
|
101 | object *op; |
|
|
102 | |
199 | if (QUERY_FLAG (gen, FLAG_CONTENT_ON_GEN)) |
103 | if (QUERY_FLAG (gen, FLAG_CONTENT_ON_GEN)) |
200 | generate_monster_inv (gen); |
104 | { |
|
|
105 | // either copy one item form the inventory... |
|
|
106 | if (!gen->inv) |
|
|
107 | return; |
|
|
108 | |
|
|
109 | // first select one item from the inventory |
|
|
110 | int index = 0; |
|
|
111 | for (object *tmp = gen->inv; tmp; tmp = tmp->below) |
|
|
112 | if (!rndm (++index)) |
|
|
113 | op = tmp; |
|
|
114 | |
|
|
115 | op = object_create_clone (op); |
|
|
116 | |
|
|
117 | CLEAR_FLAG (op, FLAG_IS_A_TEMPLATE); |
|
|
118 | unflag_inv (op, FLAG_IS_A_TEMPLATE); |
|
|
119 | } |
201 | else |
120 | else |
202 | generate_monster_arch (gen); |
121 | { |
|
|
122 | // ...or use other_arch |
|
|
123 | if (archetype *at = gen->other_arch) |
|
|
124 | op = arch_to_object (at); |
|
|
125 | else |
|
|
126 | return; |
|
|
127 | } |
203 | |
128 | |
|
|
129 | op->expand_tail (); |
|
|
130 | |
|
|
131 | int i = find_free_spot (op, gen->map, gen->x, gen->y, 1, 9); |
|
|
132 | if (i >= 0) |
|
|
133 | { |
|
|
134 | if (insert_ob_in_map_at (op, gen->map, gen, 0, gen->x + freearr_x[i], gen->y + freearr_y[i])) |
|
|
135 | { |
|
|
136 | if (rndm (0, 9)) |
|
|
137 | generate_artifact (op, gen->map->difficulty); |
|
|
138 | |
|
|
139 | if (op->has_random_items ()) |
|
|
140 | create_treasure (op->randomitems, op, GT_APPLY, gen->map->difficulty); |
|
|
141 | |
|
|
142 | return; |
|
|
143 | } |
|
|
144 | } |
|
|
145 | |
|
|
146 | op->destroy (); |
204 | } |
147 | } |
205 | |
148 | |
206 | void |
149 | void |
207 | remove_force (object *op) |
150 | remove_force (object *op) |
208 | { |
151 | { |
… | |
… | |
277 | } |
220 | } |
278 | |
221 | |
279 | |
222 | |
280 | void |
223 | void |
281 | move_gate (object *op) |
224 | move_gate (object *op) |
282 | { /* 1 = going down, 0 = goind up */ |
225 | { /* 1 = going down, 0 = going up */ |
283 | object *tmp; |
226 | object *tmp; |
284 | |
227 | |
285 | if (op->stats.wc < 0 || (int) op->stats.wc >= NUM_ANIMATIONS (op)) |
228 | if (op->stats.wc < 0 || (int) op->stats.wc >= NUM_ANIMATIONS (op)) |
286 | { |
229 | { |
287 | LOG (llevError, "Gate error: animation was %d, max=%d\n", op->stats.wc, NUM_ANIMATIONS (op)); |
230 | LOG (llevError, "Gate error: animation was %d, max=%d\n", op->stats.wc, NUM_ANIMATIONS (op)); |
… | |
… | |
359 | */ |
302 | */ |
360 | if ((int) op->stats.wc >= NUM_ANIMATIONS (op) / 2) |
303 | if ((int) op->stats.wc >= NUM_ANIMATIONS (op) / 2) |
361 | { |
304 | { |
362 | /* Halfway or further, check blocks */ |
305 | /* Halfway or further, check blocks */ |
363 | /* First, get the top object on the square. */ |
306 | /* First, get the top object on the square. */ |
364 | for (tmp = op->above; tmp != NULL && tmp->above != NULL; tmp = tmp->above); |
307 | for (tmp = op->above; tmp && tmp->above; tmp = tmp->above) |
|
|
308 | ; |
365 | |
309 | |
366 | if (tmp != NULL) |
310 | if (tmp) |
367 | { |
311 | { |
368 | if (QUERY_FLAG (tmp, FLAG_ALIVE)) |
312 | if (QUERY_FLAG (tmp, FLAG_ALIVE)) |
369 | { |
313 | { |
370 | hit_player (tmp, random_roll (1, op->stats.dam, tmp, PREFER_LOW), op, AT_PHYSICAL, 1); |
314 | hit_player (tmp, random_roll (0, op->stats.dam, tmp, PREFER_LOW), op, AT_PHYSICAL, 1); |
|
|
315 | |
371 | if (tmp->type == PLAYER) |
316 | if (tmp->type == PLAYER) |
372 | new_draw_info_format (NDI_UNIQUE, 0, tmp, "You are crushed by the %s!", &op->name); |
317 | new_draw_info_format (NDI_UNIQUE, 0, tmp, "You are crushed by the %s!", &op->name); |
373 | } |
318 | } |
374 | else |
319 | else |
375 | /* If the object is not alive, and the object either can |
320 | /* If the object is not alive, and the object either can |