… | |
… | |
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 | /*First count numer of objects in inv */ |
|
|
113 | for (op = gen->inv; op; op = op->below) |
|
|
114 | qty++; |
|
|
115 | if (!qty) |
|
|
116 | { |
|
|
117 | LOG (llevError, "Generator (%s) has no inventory in generate_monster_inv?\n", &gen->name); |
|
|
118 | return; /*No inventory */ |
|
|
119 | } |
|
|
120 | qty = rndm (0, qty - 1); |
|
|
121 | for (op = gen->inv; qty; qty--) |
|
|
122 | op = op->below; |
|
|
123 | i = find_free_spot (op, gen->map, gen->x, gen->y, 1, 9); |
|
|
124 | if (i == -1) |
|
|
125 | return; |
|
|
126 | head = object_create_clone (op); |
|
|
127 | CLEAR_FLAG (head, FLAG_IS_A_TEMPLATE); |
|
|
128 | unflag_inv (head, FLAG_IS_A_TEMPLATE); |
|
|
129 | if (rndm (0, 9)) |
|
|
130 | generate_artifact (head, gen->map->difficulty); |
|
|
131 | insert_ob_in_map_at (head, gen->map, gen, 0, gen->x + freearr_x[i], gen->y + freearr_y[i]); |
|
|
132 | if (QUERY_FLAG (head, FLAG_FREED)) |
|
|
133 | return; |
|
|
134 | if (head->has_random_items ()) |
|
|
135 | create_treasure (head->randomitems, head, GT_APPLY, gen->map->difficulty, 0); |
|
|
136 | } |
|
|
137 | |
|
|
138 | void |
|
|
139 | generate_monster_arch (object *gen) |
|
|
140 | { |
|
|
141 | int i; |
|
|
142 | object *op, *head = NULL, *prev = NULL; |
|
|
143 | archetype *at = gen->other_arch; |
|
|
144 | |
|
|
145 | if (!gen->other_arch) |
|
|
146 | return; |
|
|
147 | |
|
|
148 | /* Code below assumes the generator is on a map, as it tries |
|
|
149 | * to place the monster on the map. So if the generator |
|
|
150 | * isn't on a map, complain and exit. |
|
|
151 | */ |
|
|
152 | if (!gen->map) |
95 | if (!gen->map) |
153 | return; |
96 | return; |
154 | |
97 | |
155 | i = find_free_spot (&at->clone, gen->map, gen->x, gen->y, 1, 9); |
|
|
156 | if (i == -1) |
|
|
157 | return; |
|
|
158 | |
|
|
159 | while (at) |
|
|
160 | { |
|
|
161 | op = arch_to_object (at); |
|
|
162 | op->x = gen->x + freearr_x[i] + at->clone.x; |
|
|
163 | op->y = gen->y + freearr_y[i] + at->clone.y; |
|
|
164 | |
|
|
165 | if (head) |
|
|
166 | op->head = head, prev->more = op; |
|
|
167 | |
|
|
168 | if (rndm (0, 9)) |
|
|
169 | generate_artifact (op, gen->map->difficulty); |
|
|
170 | |
|
|
171 | insert_ob_in_map (op, gen->map, gen, 0); |
|
|
172 | if (QUERY_FLAG (op, FLAG_FREED)) |
|
|
173 | return; |
|
|
174 | |
|
|
175 | if (op->has_random_items ()) |
|
|
176 | create_treasure (op->randomitems, op, GT_APPLY, gen->map->difficulty, 0); |
|
|
177 | |
|
|
178 | if (head == NULL) |
|
|
179 | head = op; |
|
|
180 | |
|
|
181 | prev = op; |
|
|
182 | at = at->more; |
|
|
183 | } |
|
|
184 | } |
|
|
185 | |
|
|
186 | void |
|
|
187 | generate_monster (object *gen) |
|
|
188 | { |
|
|
189 | |
|
|
190 | if (GENERATE_SPEED (gen) && rndm (0, GENERATE_SPEED (gen) - 1)) |
98 | if (GENERATE_SPEED (gen) && rndm (0, GENERATE_SPEED (gen) - 1)) |
191 | return; |
99 | return; |
192 | |
100 | |
|
|
101 | object *op; |
|
|
102 | |
193 | if (QUERY_FLAG (gen, FLAG_CONTENT_ON_GEN)) |
103 | if (QUERY_FLAG (gen, FLAG_CONTENT_ON_GEN)) |
194 | 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 | } |
195 | else |
120 | else |
196 | 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 | } |
197 | |
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 (); |
198 | } |
147 | } |
199 | |
148 | |
200 | void |
149 | void |
201 | remove_force (object *op) |
150 | remove_force (object *op) |
202 | { |
151 | { |
… | |
… | |
271 | } |
220 | } |
272 | |
221 | |
273 | |
222 | |
274 | void |
223 | void |
275 | move_gate (object *op) |
224 | move_gate (object *op) |
276 | { /* 1 = going down, 0 = goind up */ |
225 | { /* 1 = going down, 0 = going up */ |
277 | object *tmp; |
226 | object *tmp; |
278 | |
227 | |
279 | 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)) |
280 | { |
229 | { |
281 | 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)); |
… | |
… | |
353 | */ |
302 | */ |
354 | if ((int) op->stats.wc >= NUM_ANIMATIONS (op) / 2) |
303 | if ((int) op->stats.wc >= NUM_ANIMATIONS (op) / 2) |
355 | { |
304 | { |
356 | /* Halfway or further, check blocks */ |
305 | /* Halfway or further, check blocks */ |
357 | /* First, get the top object on the square. */ |
306 | /* First, get the top object on the square. */ |
358 | for (tmp = op->above; tmp != NULL && tmp->above != NULL; tmp = tmp->above); |
307 | for (tmp = op->above; tmp && tmp->above; tmp = tmp->above) |
|
|
308 | ; |
359 | |
309 | |
360 | if (tmp != NULL) |
310 | if (tmp) |
361 | { |
311 | { |
362 | if (QUERY_FLAG (tmp, FLAG_ALIVE)) |
312 | if (QUERY_FLAG (tmp, FLAG_ALIVE)) |
363 | { |
313 | { |
364 | 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 | |
365 | if (tmp->type == PLAYER) |
316 | if (tmp->type == PLAYER) |
366 | 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); |
367 | } |
318 | } |
368 | else |
319 | else |
369 | /* If the object is not alive, and the object either can |
320 | /* If the object is not alive, and the object either can |
… | |
… | |
684 | } |
635 | } |
685 | } |
636 | } |
686 | |
637 | |
687 | /* Move an arrow along its course. op is the arrow or thrown object. |
638 | /* Move an arrow along its course. op is the arrow or thrown object. |
688 | */ |
639 | */ |
689 | |
|
|
690 | void |
640 | void |
691 | move_arrow (object *op) |
641 | move_arrow (object *op) |
692 | { |
642 | { |
693 | object *tmp; |
643 | object *tmp; |
694 | sint16 new_x, new_y; |
644 | sint16 new_x, new_y; |
… | |
… | |
768 | if (QUERY_FLAG (tmp, FLAG_REFL_MISSILE) && (rndm (0, 99)) < (90 - op->level / 10)) |
718 | if (QUERY_FLAG (tmp, FLAG_REFL_MISSILE) && (rndm (0, 99)) < (90 - op->level / 10)) |
769 | { |
719 | { |
770 | int number = op->face; |
720 | int number = op->face; |
771 | |
721 | |
772 | op->direction = absdir (op->direction + 4); |
722 | op->direction = absdir (op->direction + 4); |
773 | op->state = 0; |
723 | update_turn_face (op); |
774 | |
|
|
775 | if (GET_ANIM_ID (op)) |
|
|
776 | { |
|
|
777 | number += 4; |
|
|
778 | |
|
|
779 | if (number > GET_ANIMATION (op, 8)) |
|
|
780 | number -= 8; |
|
|
781 | |
|
|
782 | op->face = number; |
|
|
783 | } |
|
|
784 | |
|
|
785 | was_reflected = 1; /* skip normal movement calculations */ |
724 | was_reflected = 1; /* skip normal movement calculations */ |
786 | } |
725 | } |
787 | else |
726 | else |
788 | { |
727 | { |
789 | /* Attack the object. */ |
728 | /* Attack the object. */ |