… | |
… | |
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); |
… | |
… | |
604 | void |
553 | void |
605 | fix_stopped_item (object *op, maptile *map, object *originator) |
554 | fix_stopped_item (object *op, maptile *map, object *originator) |
606 | { |
555 | { |
607 | if (map == NULL) |
556 | if (map == NULL) |
608 | return; |
557 | return; |
|
|
558 | |
609 | if (QUERY_FLAG (op, FLAG_REMOVED)) |
559 | if (QUERY_FLAG (op, FLAG_REMOVED)) |
610 | insert_ob_in_map (op, map, originator, 0); |
560 | insert_ob_in_map (op, map, originator, 0); |
611 | else if (op->type == ARROW) |
561 | else if (op->type == ARROW) |
612 | merge_ob (op, NULL); /* only some arrows actually need this */ |
562 | merge_ob (op, NULL); /* only some arrows actually need this */ |
613 | } |
563 | } |
614 | |
|
|
615 | |
564 | |
616 | object * |
565 | object * |
617 | fix_stopped_arrow (object *op) |
566 | fix_stopped_arrow (object *op) |
618 | { |
567 | { |
619 | if (rndm (0, 99) < op->stats.food) |
568 | if (rndm (0, 99) < op->stats.food) |
… | |
… | |
648 | op->stats.hp = 0; |
597 | op->stats.hp = 0; |
649 | op->stats.grace = 0; |
598 | op->stats.grace = 0; |
650 | op->level = 0; |
599 | op->level = 0; |
651 | op->face = op->arch->clone.face; |
600 | op->face = op->arch->clone.face; |
652 | op->owner = NULL; /* So that stopped arrows will be saved */ |
601 | op->owner = NULL; /* So that stopped arrows will be saved */ |
653 | update_object (op, UP_OBJ_FACE); |
602 | update_object (op, UP_OBJ_CHANGE); |
654 | return op; |
603 | return op; |
655 | } |
604 | } |
656 | |
605 | |
657 | /* stop_arrow() - what to do when a non-living flying object |
606 | /* stop_arrow() - what to do when a non-living flying object |
658 | * has to stop. Sept 96 - I added in thrown object code in |
607 | * has to stop. Sept 96 - I added in thrown object code in |
… | |
… | |
684 | } |
633 | } |
685 | } |
634 | } |
686 | |
635 | |
687 | /* Move an arrow along its course. op is the arrow or thrown object. |
636 | /* Move an arrow along its course. op is the arrow or thrown object. |
688 | */ |
637 | */ |
689 | |
|
|
690 | void |
638 | void |
691 | move_arrow (object *op) |
639 | move_arrow (object *op) |
692 | { |
640 | { |
693 | object *tmp; |
641 | object *tmp; |
694 | sint16 new_x, new_y; |
642 | sint16 new_x, new_y; |
… | |
… | |
765 | * as below. (Note that for living creatures there is a small |
713 | * as below. (Note that for living creatures there is a small |
766 | * chance that reflect_missile fails.) |
714 | * chance that reflect_missile fails.) |
767 | */ |
715 | */ |
768 | if (QUERY_FLAG (tmp, FLAG_REFL_MISSILE) && (rndm (0, 99)) < (90 - op->level / 10)) |
716 | if (QUERY_FLAG (tmp, FLAG_REFL_MISSILE) && (rndm (0, 99)) < (90 - op->level / 10)) |
769 | { |
717 | { |
770 | int number = op->face->number; |
718 | int number = op->face; |
771 | |
719 | |
772 | op->direction = absdir (op->direction + 4); |
720 | op->direction = absdir (op->direction + 4); |
773 | op->state = 0; |
721 | 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 */ |
722 | was_reflected = 1; /* skip normal movement calculations */ |
786 | } |
723 | } |
787 | else |
724 | else |
788 | { |
725 | { |
789 | /* Attack the object. */ |
726 | /* Attack the object. */ |