… | |
… | |
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 | { |
… | |
… | |
245 | return; |
194 | return; |
246 | } |
195 | } |
247 | |
196 | |
248 | if (op->stats.food == 1) |
197 | if (op->stats.food == 1) |
249 | { |
198 | { |
250 | /* need to remove the object before fix_player is called, else fix_player |
199 | /* need to unapply the object before update_stats is called, else fix_player |
251 | * will not do anything. |
200 | * will not do anything. |
252 | */ |
201 | */ |
253 | if (op->env->type == PLAYER) |
202 | if (op->env->type == PLAYER) |
254 | { |
203 | { |
255 | CLEAR_FLAG (op, FLAG_APPLIED); |
204 | CLEAR_FLAG (op, FLAG_APPLIED); |
… | |
… | |
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 |
… | |
… | |
455 | |
406 | |
456 | if (op->stats.hp) |
407 | if (op->stats.hp) |
457 | { |
408 | { |
458 | for (tmp2 = tmp->inv; tmp2; tmp2 = tmp2->below) |
409 | for (tmp2 = tmp->inv; tmp2; tmp2 = tmp2->below) |
459 | { |
410 | { |
460 | if (op->slaying && !strcmp (op->slaying, tmp->name)) |
411 | if (op->slaying && op->slaying == tmp->name) |
461 | detected = 1; |
412 | detected = 1; |
|
|
413 | |
462 | if (tmp2->type == FORCE && tmp2->slaying && !strcmp (tmp2->slaying, op->slaying)) |
414 | if (tmp2->type == FORCE && tmp2->slaying && tmp2->slaying == op->slaying) |
463 | detected = 1; |
415 | detected = 1; |
464 | } |
416 | } |
465 | } |
417 | } |
|
|
418 | |
466 | if (op->slaying && !strcmp (op->slaying, tmp->name)) |
419 | if (op->slaying && op->slaying == tmp->name) |
467 | { |
|
|
468 | detected = 1; |
420 | detected = 1; |
469 | } |
|
|
470 | else if (tmp->type == SPECIAL_KEY && tmp->slaying == op->slaying) |
421 | else if (tmp->type == SPECIAL_KEY && tmp->slaying == op->slaying) |
471 | detected = 1; |
422 | detected = 1; |
472 | } |
423 | } |
473 | |
424 | |
474 | /* the detector sets the button if detection is found */ |
425 | /* the detector sets the button if detection is found */ |
… | |
… | |
604 | void |
555 | void |
605 | fix_stopped_item (object *op, maptile *map, object *originator) |
556 | fix_stopped_item (object *op, maptile *map, object *originator) |
606 | { |
557 | { |
607 | if (map == NULL) |
558 | if (map == NULL) |
608 | return; |
559 | return; |
|
|
560 | |
609 | if (QUERY_FLAG (op, FLAG_REMOVED)) |
561 | if (QUERY_FLAG (op, FLAG_REMOVED)) |
610 | insert_ob_in_map (op, map, originator, 0); |
562 | insert_ob_in_map (op, map, originator, 0); |
611 | else if (op->type == ARROW) |
563 | else if (op->type == ARROW) |
612 | merge_ob (op, NULL); /* only some arrows actually need this */ |
564 | merge_ob (op, NULL); /* only some arrows actually need this */ |
613 | } |
565 | } |
614 | |
|
|
615 | |
566 | |
616 | object * |
567 | object * |
617 | fix_stopped_arrow (object *op) |
568 | fix_stopped_arrow (object *op) |
618 | { |
569 | { |
619 | if (rndm (0, 99) < op->stats.food) |
570 | if (rndm (0, 99) < op->stats.food) |
… | |
… | |
648 | op->stats.hp = 0; |
599 | op->stats.hp = 0; |
649 | op->stats.grace = 0; |
600 | op->stats.grace = 0; |
650 | op->level = 0; |
601 | op->level = 0; |
651 | op->face = op->arch->clone.face; |
602 | op->face = op->arch->clone.face; |
652 | op->owner = NULL; /* So that stopped arrows will be saved */ |
603 | op->owner = NULL; /* So that stopped arrows will be saved */ |
653 | update_object (op, UP_OBJ_FACE); |
604 | update_object (op, UP_OBJ_CHANGE); |
654 | return op; |
605 | return op; |
655 | } |
606 | } |
656 | |
607 | |
657 | /* stop_arrow() - what to do when a non-living flying object |
608 | /* stop_arrow() - what to do when a non-living flying object |
658 | * has to stop. Sept 96 - I added in thrown object code in |
609 | * has to stop. Sept 96 - I added in thrown object code in |
… | |
… | |
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; |
… | |
… | |
765 | * as below. (Note that for living creatures there is a small |
715 | * as below. (Note that for living creatures there is a small |
766 | * chance that reflect_missile fails.) |
716 | * chance that reflect_missile fails.) |
767 | */ |
717 | */ |
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->number; |
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 = &new_faces[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. */ |
… | |
… | |
1204 | return; |
1143 | return; |
1205 | } |
1144 | } |
1206 | |
1145 | |
1207 | if (op->above == NULL) |
1146 | if (op->above == NULL) |
1208 | return; |
1147 | return; |
|
|
1148 | |
1209 | for (tmp = op->above; tmp != NULL; tmp = tmp->above) |
1149 | for (tmp = op->above; tmp; tmp = tmp->above) |
1210 | { |
1150 | { |
1211 | if (strcmp (op->other_arch->name, tmp->arch->name) == 0) |
1151 | if (op->other_arch->name == tmp->arch->name) |
1212 | { |
1152 | { |
1213 | if (op->level <= 0) |
1153 | if (op->level <= 0) |
1214 | tmp->destroy (); |
1154 | tmp->destroy (); |
1215 | else |
1155 | else |
1216 | { |
1156 | { |
… | |
… | |
1307 | with a specific code as the slaying field. |
1247 | with a specific code as the slaying field. |
1308 | At that time, it writes the contents of its own message |
1248 | At that time, it writes the contents of its own message |
1309 | field to the player. The marker will decrement hp to |
1249 | field to the player. The marker will decrement hp to |
1310 | 0 and then delete itself every time it grants a mark. |
1250 | 0 and then delete itself every time it grants a mark. |
1311 | unless hp was zero to start with, in which case it is infinite.*/ |
1251 | unless hp was zero to start with, in which case it is infinite.*/ |
1312 | |
|
|
1313 | void |
1252 | void |
1314 | move_marker (object *op) |
1253 | move_marker (object *op) |
1315 | { |
1254 | { |
1316 | if (object *tmp = op->ms ().player ()) |
1255 | if (object *tmp = op->ms ().player ()) |
1317 | { |
1256 | { |
1318 | object *tmp2; |
1257 | object *tmp2; |
1319 | |
1258 | |
1320 | /* remove an old force with a slaying field == op->name */ |
1259 | /* remove an old force with a slaying field == op->name */ |
1321 | for (tmp2 = tmp->inv; tmp2; tmp2 = tmp2->below) |
1260 | for (tmp2 = tmp->inv; tmp2; tmp2 = tmp2->below) |
1322 | if (tmp2->type == FORCE && tmp2->slaying && !strcmp (tmp2->slaying, op->name)) |
1261 | if (tmp2->type == FORCE && tmp2->slaying && tmp2->slaying == op->name) |
1323 | { |
1262 | { |
1324 | tmp2->destroy (); |
1263 | tmp2->destroy (); |
1325 | break; |
1264 | break; |
1326 | } |
1265 | } |
1327 | |
1266 | |
1328 | /* cycle through his inventory to look for the MARK we want to |
1267 | /* cycle through his inventory to look for the MARK we want to |
1329 | * place |
1268 | * place |
1330 | */ |
1269 | */ |
1331 | for (tmp2 = tmp->inv; tmp2; tmp2 = tmp2->below) |
1270 | for (tmp2 = tmp->inv; tmp2; tmp2 = tmp2->below) |
1332 | if (tmp2->type == FORCE && tmp2->slaying && !strcmp (tmp2->slaying, op->slaying)) |
1271 | if (tmp2->type == FORCE && tmp2->slaying && tmp2->slaying == op->slaying) |
1333 | break; |
1272 | break; |
1334 | |
1273 | |
1335 | /* if we didn't find our own MARK */ |
1274 | /* if we didn't find our own MARK */ |
1336 | if (tmp2 == NULL) |
1275 | if (!tmp2) |
1337 | { |
1276 | { |
1338 | object *force = get_archetype (FORCE_NAME); |
1277 | object *force = get_archetype (FORCE_NAME); |
1339 | |
1278 | |
1340 | if (op->stats.food) |
1279 | if (op->stats.food) |
1341 | { |
1280 | { |