1 | /* |
1 | /* |
2 | * This file is part of Crossfire TRT, the Roguelike Realtime MORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team |
4 | * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
7 | * |
7 | * |
8 | * Crossfire TRT is free software: you can redistribute it and/or modify |
8 | * Deliantra is free software: you can redistribute it and/or modify |
9 | * it under the terms of the GNU General Public License as published by |
9 | * it under the terms of the GNU General Public License as published by |
10 | * the Free Software Foundation, either version 3 of the License, or |
10 | * the Free Software Foundation, either version 3 of the License, or |
11 | * (at your option) any later version. |
11 | * (at your option) any later version. |
12 | * |
12 | * |
13 | * This program is distributed in the hope that it will be useful, |
13 | * This program is distributed in the hope that it will be useful, |
… | |
… | |
16 | * GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
17 | * |
17 | * |
18 | * You should have received a copy of the GNU General Public License |
18 | * You should have received a copy of the GNU General Public License |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
20 | * |
20 | * |
21 | * The authors can be reached via e-mail to <crossfire@schmorp.de> |
21 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | */ |
22 | */ |
23 | |
23 | |
24 | /* |
24 | /* |
25 | * Routines that is executed from objects based on their speed have been |
25 | * Routines that is executed from objects based on their speed have been |
26 | * collected in this file. |
26 | * collected in this file. |
… | |
… | |
34 | * so those will be removed shortly (in a cascade like fashion.) |
34 | * so those will be removed shortly (in a cascade like fashion.) |
35 | */ |
35 | */ |
36 | void |
36 | void |
37 | remove_door (object *op) |
37 | remove_door (object *op) |
38 | { |
38 | { |
|
|
39 | for (int i = 1; i < SIZEOFFREE1 + 1; i += 2) |
|
|
40 | { |
|
|
41 | object *tmp; |
|
|
42 | mapxy pos (op); |
|
|
43 | pos.move (i); |
|
|
44 | if (pos.normalise () |
|
|
45 | && (tmp = present (DOOR, pos.m, pos.x, pos.y))) |
|
|
46 | { |
|
|
47 | tmp->set_speed (0.1f); |
|
|
48 | tmp->speed_left = -0.2f; |
|
|
49 | } |
|
|
50 | } |
|
|
51 | |
|
|
52 | if (op->other_arch) |
|
|
53 | { |
|
|
54 | object *tmp = arch_to_object (op->other_arch); |
|
|
55 | tmp->x = op->x; |
|
|
56 | tmp->y = op->y; |
|
|
57 | tmp->map = op->map; |
|
|
58 | tmp->level = op->level; |
|
|
59 | insert_ob_in_map (tmp, op->map, op, 0); |
|
|
60 | } |
|
|
61 | |
|
|
62 | op->destroy (); |
|
|
63 | } |
|
|
64 | |
|
|
65 | void |
|
|
66 | remove_door2 (object *op) |
|
|
67 | { |
39 | int i; |
68 | int i; |
40 | object *tmp; |
69 | object *tmp; |
41 | |
70 | |
42 | for (i = 1; i < 9; i += 2) |
71 | for (i = 1; i < 9; i += 2) |
|
|
72 | { |
43 | if ((tmp = present (DOOR, op->map, op->x + freearr_x[i], op->y + freearr_y[i])) != NULL) |
73 | tmp = present (LOCKED_DOOR, op->map, op->x + freearr_x[i], op->y + freearr_y[i]); |
44 | { |
74 | if (tmp && tmp->slaying == op->slaying) |
|
|
75 | { /* same key both doors */ |
45 | tmp->set_speed (0.1f); |
76 | tmp->set_speed (0.1f); |
46 | tmp->speed_left = -0.2f; |
77 | tmp->speed_left = -0.2f; |
47 | } |
78 | } |
|
|
79 | } |
48 | |
80 | |
49 | if (op->other_arch) |
81 | if (op->other_arch) |
50 | { |
82 | { |
51 | tmp = arch_to_object (op->other_arch); |
83 | tmp = arch_to_object (op->other_arch); |
52 | tmp->x = op->x; |
84 | tmp->x = op->x; |
… | |
… | |
58 | |
90 | |
59 | op->destroy (); |
91 | op->destroy (); |
60 | } |
92 | } |
61 | |
93 | |
62 | void |
94 | void |
63 | remove_door2 (object *op) |
|
|
64 | { |
|
|
65 | int i; |
|
|
66 | object *tmp; |
|
|
67 | |
|
|
68 | for (i = 1; i < 9; i += 2) |
|
|
69 | { |
|
|
70 | tmp = present (LOCKED_DOOR, op->map, op->x + freearr_x[i], op->y + freearr_y[i]); |
|
|
71 | if (tmp && tmp->slaying == op->slaying) |
|
|
72 | { /* same key both doors */ |
|
|
73 | tmp->set_speed (0.1f); |
|
|
74 | tmp->speed_left = -0.2f; |
|
|
75 | } |
|
|
76 | } |
|
|
77 | |
|
|
78 | if (op->other_arch) |
|
|
79 | { |
|
|
80 | tmp = arch_to_object (op->other_arch); |
|
|
81 | tmp->x = op->x; |
|
|
82 | tmp->y = op->y; |
|
|
83 | tmp->map = op->map; |
|
|
84 | tmp->level = op->level; |
|
|
85 | insert_ob_in_map (tmp, op->map, op, 0); |
|
|
86 | } |
|
|
87 | |
|
|
88 | op->destroy (); |
|
|
89 | } |
|
|
90 | |
|
|
91 | void |
|
|
92 | generate_monster (object *gen) |
95 | generate_monster (object *gen) |
93 | { |
96 | { |
94 | if (!gen->map) |
97 | if (!gen->map) |
95 | return; |
98 | return; |
96 | |
99 | |
97 | if (GENERATE_SPEED (gen) && rndm (0, GENERATE_SPEED (gen) - 1)) |
100 | if (GENERATE_SPEED (gen) && rndm (0, GENERATE_SPEED (gen) - 1)) |
98 | return; |
101 | return; |
99 | |
102 | |
100 | object *op; |
103 | object *op; |
101 | int i; |
104 | int dir; |
102 | |
105 | |
103 | if (QUERY_FLAG (gen, FLAG_CONTENT_ON_GEN)) |
106 | if (QUERY_FLAG (gen, FLAG_CONTENT_ON_GEN)) |
104 | { |
107 | { |
105 | // either copy one item from the inventory... |
108 | // either copy one item from the inventory... |
106 | if (!gen->inv) |
109 | if (!gen->inv) |
… | |
… | |
110 | int index = 0; |
113 | int index = 0; |
111 | for (object *tmp = gen->inv; tmp; tmp = tmp->below) |
114 | for (object *tmp = gen->inv; tmp; tmp = tmp->below) |
112 | if (!rndm (++index)) |
115 | if (!rndm (++index)) |
113 | op = tmp; |
116 | op = tmp; |
114 | |
117 | |
115 | i = find_free_spot (op, gen->map, gen->x, gen->y, 1, 9); |
118 | dir = find_free_spot (op, gen->map, gen->x, gen->y, 1, SIZEOFFREE1 + 1); |
116 | if (i < 0) |
119 | if (dir < 0) |
117 | return; |
120 | return; |
118 | |
121 | |
119 | op = object_create_clone (op); |
122 | op = object_create_clone (op); |
120 | |
123 | |
121 | CLEAR_FLAG (op, FLAG_IS_A_TEMPLATE); |
124 | CLEAR_FLAG (op, FLAG_IS_A_TEMPLATE); |
122 | unflag_inv (op, FLAG_IS_A_TEMPLATE); |
125 | unflag_inv (op, FLAG_IS_A_TEMPLATE); |
123 | } |
126 | } |
124 | else if (gen->other_arch) |
127 | else if (gen->other_arch) |
125 | { |
128 | { |
126 | // ...or use other_arch |
129 | // ...or use other_arch |
127 | i = find_free_spot (gen->other_arch, gen->map, gen->x, gen->y, 1, 9); |
130 | dir = find_free_spot (gen->other_arch, gen->map, gen->x, gen->y, 1, SIZEOFFREE1 + 1); |
128 | if (i < 0) |
131 | if (dir < 0) |
129 | return; |
132 | return; |
130 | |
133 | |
131 | op = arch_to_object (gen->other_arch); |
134 | op = arch_to_object (gen->other_arch); |
132 | } |
135 | } |
133 | else |
136 | else |
134 | return; |
137 | return; |
135 | |
138 | |
136 | op->expand_tail (); |
139 | op->expand_tail (); |
137 | |
140 | |
138 | if (insert_ob_in_map_at (op, gen->map, gen, 0, gen->x + freearr_x[i], gen->y + freearr_y[i])) |
141 | mapxy pos (gen); pos.move (dir); |
|
|
142 | |
|
|
143 | if (pos.insert (op, gen)) |
139 | { |
144 | { |
140 | if (rndm (0, 9)) |
145 | if (rndm (0, 9)) |
141 | generate_artifact (op, gen->map->difficulty); |
146 | generate_artifact (op, gen->map->difficulty); |
142 | |
147 | |
143 | if (op->has_random_items ()) |
148 | if (op->has_random_items ()) |
… | |
… | |
295 | } |
300 | } |
296 | else |
301 | else |
297 | { /* The gate is still going up */ |
302 | { /* The gate is still going up */ |
298 | op->stats.wc++; |
303 | op->stats.wc++; |
299 | |
304 | |
300 | if ((int) op->stats.wc >= (NUM_ANIMATIONS (op))) |
305 | if (op->stats.wc >= NUM_ANIMATIONS (op)) |
301 | op->stats.wc = (signed char) NUM_ANIMATIONS (op) - 1; |
306 | op->stats.wc = NUM_ANIMATIONS (op) - 1; |
302 | |
307 | |
303 | /* If there is something on top of the gate, we try to roll it off. |
308 | /* If there is something on top of the gate, we try to roll it off. |
304 | * If a player/monster, we don't roll, we just hit them with damage |
309 | * If a player/monster, we don't roll, we just hit them with damage |
305 | */ |
310 | */ |
306 | if ((int) op->stats.wc >= NUM_ANIMATIONS (op) / 2) |
311 | if (op->stats.wc >= NUM_ANIMATIONS (op) / 2) |
307 | { |
312 | { |
308 | /* Halfway or further, check blocks */ |
313 | /* Halfway or further, check blocks */ |
309 | /* First, get the top object on the square. */ |
314 | /* First, get the top object on the square. */ |
310 | for (tmp = op->above; tmp && tmp->above; tmp = tmp->above) |
315 | for (tmp = op->above; tmp && tmp->above; tmp = tmp->above) |
311 | ; |
316 | ; |
… | |
… | |
325 | * off the gate. |
330 | * off the gate. |
326 | */ |
331 | */ |
327 | else if (!QUERY_FLAG (tmp, FLAG_ALIVE) && (!QUERY_FLAG (tmp, FLAG_NO_PICK) || QUERY_FLAG (tmp, FLAG_CAN_ROLL))) |
332 | else if (!QUERY_FLAG (tmp, FLAG_ALIVE) && (!QUERY_FLAG (tmp, FLAG_NO_PICK) || QUERY_FLAG (tmp, FLAG_CAN_ROLL))) |
328 | { |
333 | { |
329 | /* If it has speed, it should move itself, otherwise: */ |
334 | /* If it has speed, it should move itself, otherwise: */ |
330 | int i = find_free_spot (tmp, op->map, op->x, op->y, 1, 9); |
335 | int i = find_free_spot (tmp, op->map, op->x, op->y, 1, SIZEOFFREE1 + 1); |
331 | |
336 | |
332 | /* If there is a free spot, move the object someplace */ |
337 | /* If there is a free spot, move the object someplace */ |
333 | if (i != -1) |
338 | if (i > 0) |
334 | { |
339 | { |
|
|
340 | mapxy pos (tmp); |
|
|
341 | pos.move (i); |
|
|
342 | if (pos.normalise ()) |
335 | tmp->remove (); |
343 | tmp->move_to (pos); |
336 | tmp->x += freearr_x[i], tmp->y += freearr_y[i]; |
|
|
337 | insert_ob_in_map (tmp, op->map, op, 0); |
|
|
338 | } |
344 | } |
339 | } |
345 | } |
340 | } |
346 | } |
341 | |
347 | |
342 | /* See if there is still anything blocking the gate */ |
348 | /* See if there is still anything blocking the gate */ |
… | |
… | |
403 | int last = op->value; |
409 | int last = op->value; |
404 | int detected; |
410 | int detected; |
405 | |
411 | |
406 | detected = 0; |
412 | detected = 0; |
407 | |
413 | |
408 | for (tmp = GET_MAP_OB (op->map, op->x, op->y); tmp && !detected; tmp = tmp->above) |
414 | for (tmp = op->ms ().bot; tmp && !detected; tmp = tmp->above) |
409 | { |
415 | { |
410 | object *tmp2; |
416 | object *tmp2; |
411 | |
417 | |
412 | if (op->stats.hp) |
418 | if (op->stats.hp) |
413 | { |
419 | { |
… | |
… | |
455 | op->value = 1; |
461 | op->value = 1; |
456 | push_button (op); |
462 | push_button (op); |
457 | } |
463 | } |
458 | } |
464 | } |
459 | } |
465 | } |
460 | |
|
|
461 | |
466 | |
462 | void |
467 | void |
463 | animate_trigger (object *op) |
468 | animate_trigger (object *op) |
464 | { |
469 | { |
465 | if ((unsigned char) ++op->stats.wc >= NUM_ANIMATIONS (op)) |
470 | if ((unsigned char) ++op->stats.wc >= NUM_ANIMATIONS (op)) |
… | |
… | |
497 | |
502 | |
498 | SET_ANIMATION (op, op->stats.wc); |
503 | SET_ANIMATION (op, op->stats.wc); |
499 | update_object (op, UP_OBJ_FACE); |
504 | update_object (op, UP_OBJ_FACE); |
500 | return; |
505 | return; |
501 | } |
506 | } |
|
|
507 | |
502 | /* We're closing */ |
508 | /* We're closing */ |
503 | op->move_on = 0; |
509 | op->move_on = 0; |
504 | |
510 | |
505 | op->stats.wc++; |
511 | op->stats.wc++; |
506 | if ((int) op->stats.wc >= NUM_ANIMATIONS (op)) |
512 | if ((int) op->stats.wc >= NUM_ANIMATIONS (op)) |
… | |
… | |
647 | /* Move an arrow along its course. op is the arrow or thrown object. |
653 | /* Move an arrow along its course. op is the arrow or thrown object. |
648 | */ |
654 | */ |
649 | void |
655 | void |
650 | move_arrow (object *op) |
656 | move_arrow (object *op) |
651 | { |
657 | { |
652 | object *tmp; |
|
|
653 | sint16 new_x, new_y; |
|
|
654 | int was_reflected, mflags; |
658 | int was_reflected; |
655 | maptile *m; |
|
|
656 | |
659 | |
657 | if (op->map == NULL) |
660 | if (!op->map) |
658 | { |
661 | { |
659 | LOG (llevError, "BUG: Arrow had no map.\n"); |
662 | LOG (llevError, "BUG: Arrow had no map.\n"); |
660 | op->destroy (); |
663 | op->destroy (); |
661 | return; |
664 | return; |
662 | } |
665 | } |
… | |
… | |
692 | stop_arrow (op); |
695 | stop_arrow (op); |
693 | return; |
696 | return; |
694 | } |
697 | } |
695 | |
698 | |
696 | /* Calculate target map square */ |
699 | /* Calculate target map square */ |
697 | new_x = op->x + DIRX (op); |
|
|
698 | new_y = op->y + DIRY (op); |
|
|
699 | was_reflected = 0; |
700 | was_reflected = 0; |
700 | |
701 | |
701 | m = op->map; |
702 | mapxy pos (op); pos.move (op->direction); |
702 | mflags = get_map_flags (m, &m, new_x, new_y, &new_x, &new_y); |
|
|
703 | |
703 | |
704 | if (mflags & P_OUT_OF_MAP) |
704 | if (!pos.normalise ()) |
705 | { |
705 | { |
706 | stop_arrow (op); |
706 | stop_arrow (op); |
707 | return; |
707 | return; |
708 | } |
708 | } |
709 | |
709 | |
710 | /* only need to look for living creatures if this flag is set */ |
710 | /* only need to look for living creatures if this flag is set */ |
711 | if (mflags & P_IS_ALIVE) |
711 | if (pos->flags () & P_IS_ALIVE) |
712 | { |
712 | { |
713 | for (tmp = GET_MAP_OB (m, new_x, new_y); tmp != NULL; tmp = tmp->above) |
713 | object *tmp; |
|
|
714 | |
|
|
715 | for (tmp = pos->bot; tmp; tmp = tmp->above) |
714 | if (QUERY_FLAG (tmp, FLAG_ALIVE)) |
716 | if (QUERY_FLAG (tmp, FLAG_ALIVE)) |
715 | break; |
717 | break; |
716 | |
718 | |
717 | /* Not really fair, but don't let monsters hit themselves with |
719 | /* Not really fair, but don't let monsters hit themselves with |
718 | * their own arrow - this can be because they fire it then |
720 | * their own arrow - this can be because they fire it then |
… | |
… | |
741 | return; |
743 | return; |
742 | } |
744 | } |
743 | } /* if this is not hitting its owner */ |
745 | } /* if this is not hitting its owner */ |
744 | } /* if there is something alive on this space */ |
746 | } /* if there is something alive on this space */ |
745 | |
747 | |
746 | if (OB_TYPE_MOVE_BLOCK (op, GET_MAP_MOVE_BLOCK (m, new_x, new_y))) |
748 | if (OB_TYPE_MOVE_BLOCK (op, pos->move_block)) |
747 | { |
749 | { |
748 | int retry = 0; |
750 | int retry = 0; |
749 | |
751 | |
750 | /* if the object doesn't reflect, stop the arrow from moving |
752 | /* if the object doesn't reflect, stop the arrow from moving |
751 | * note that this code will now catch cases where a monster is |
753 | * note that this code will now catch cases where a monster is |
… | |
… | |
764 | if (op->direction & 1) |
766 | if (op->direction & 1) |
765 | { |
767 | { |
766 | op->direction = absdir (op->direction + 4); |
768 | op->direction = absdir (op->direction + 4); |
767 | retry = 1; |
769 | retry = 1; |
768 | } |
770 | } |
|
|
771 | |
769 | /* There were two blocks with identical code - |
772 | /* There were two blocks with identical code - |
770 | * use this retry here to make this one block |
773 | * use this retry here to make this one block |
771 | * that did the same thing. |
774 | * that did the same thing. |
772 | */ |
775 | */ |
773 | while (retry < 2) |
776 | while (retry < 2) |
774 | { |
777 | { |
775 | int left, right, mflags; |
|
|
776 | maptile *m1; |
|
|
777 | sint16 x1, y1; |
|
|
778 | |
|
|
779 | retry++; |
778 | retry++; |
780 | |
779 | |
781 | /* Need to check for P_OUT_OF_MAP: if the arrow is tavelling |
780 | /* Need to check for P_OUT_OF_MAP: if the arrow is travelling |
782 | * over a corner in a tiled map, it is possible that |
781 | * over a corner in a tiled map, it is possible that |
783 | * op->direction is within an adjacent map but either |
782 | * op->direction is within an adjacent map but either |
784 | * op->direction-1 or op->direction+1 does not exist. |
783 | * op->direction-1 or op->direction+1 does not exist. |
785 | */ |
784 | */ |
786 | mflags = get_map_flags (op->map, &m1, op->x + freearr_x[absdir (op->direction - 1)], |
785 | mapxy pos1 (pos); pos1.move (absdir (op->direction - 1)); |
787 | op->y + freearr_y[absdir (op->direction - 1)], &x1, &y1); |
786 | bool left = pos1.normalise () && OB_TYPE_MOVE_BLOCK (op, pos1->move_block); |
788 | left = (mflags & P_OUT_OF_MAP) ? 0 : OB_TYPE_MOVE_BLOCK (op, (GET_MAP_MOVE_BLOCK (m1, x1, y1))); |
|
|
789 | |
787 | |
790 | mflags = get_map_flags (op->map, &m1, op->x + freearr_x[absdir (op->direction + 1)], |
788 | mapxy pos2 (pos); pos2.move (absdir (op->direction + 1)); |
791 | op->y + freearr_y[absdir (op->direction + 1)], &x1, &y1); |
789 | bool right = pos2.normalise () && OB_TYPE_MOVE_BLOCK (op, pos2->move_block); |
792 | right = (mflags & P_OUT_OF_MAP) ? 0 : OB_TYPE_MOVE_BLOCK (op, (GET_MAP_MOVE_BLOCK (m1, x1, y1))); |
|
|
793 | |
790 | |
794 | if (left == right) |
791 | if (left == right) |
795 | op->direction = absdir (op->direction + 4); |
792 | op->direction = absdir (op->direction + 4); |
796 | else if (left) |
793 | else if (left) |
797 | op->direction = absdir (op->direction + 2); |
794 | op->direction = absdir (op->direction + 2); |
798 | else if (right) |
795 | else if (right) |
799 | op->direction = absdir (op->direction - 2); |
796 | op->direction = absdir (op->direction - 2); |
800 | |
797 | |
801 | mflags = get_map_flags (op->map, &m1, op->x + DIRX (op), op->y + DIRY (op), &x1, &y1); |
|
|
802 | |
|
|
803 | /* If this space is not out of the map and not blocked, valid space - |
798 | /* If this space is not out of the map and not blocked, valid space - |
804 | * don't need to retry again. |
799 | * don't need to retry again. |
805 | */ |
800 | */ |
806 | if (!(mflags & P_OUT_OF_MAP) && !OB_TYPE_MOVE_BLOCK (op, GET_MAP_MOVE_BLOCK (m1, x1, y1))) |
801 | mapxy pos3 (pos); pos3.move (op->direction); |
|
|
802 | if (pos3.normalise () && !OB_TYPE_MOVE_BLOCK (op, pos3->move_block)) |
807 | break; |
803 | break; |
808 | |
|
|
809 | } |
804 | } |
|
|
805 | |
810 | /* Couldn't find a direction to move the arrow to - just |
806 | /* Couldn't find a direction to move the arrow to - just |
811 | * top it from moving. |
807 | * stop it from moving. |
812 | */ |
808 | */ |
813 | if (retry == 2) |
809 | if (retry == 2) |
814 | { |
810 | { |
815 | stop_arrow (op); |
811 | stop_arrow (op); |
816 | return; |
812 | return; |
817 | } |
813 | } |
|
|
814 | |
818 | /* update object image for new facing */ |
815 | /* update object image for new facing */ |
819 | /* many thrown objects *don't* have more than one face */ |
816 | /* many thrown objects *don't* have more than one face */ |
820 | if (GET_ANIM_ID (op)) |
817 | if (GET_ANIM_ID (op)) |
821 | SET_ANIMATION (op, op->direction); |
818 | SET_ANIMATION (op, op->direction); |
822 | } /* object is reflected */ |
819 | } /* object is reflected */ |
823 | } /* object ran into a wall */ |
820 | } /* object ran into a wall */ |
824 | |
821 | |
825 | /* Move the arrow. */ |
|
|
826 | op->remove (); |
|
|
827 | op->x = new_x; |
|
|
828 | op->y = new_y; |
|
|
829 | |
|
|
830 | /* decrease the speed as it flies. 0.05 means a standard bow will shoot |
822 | /* decrease the speed as it flies. 0.05 means a standard bow will shoot |
831 | * about 17 squares. Tune as needed. |
823 | * about 17 squares. Tune as needed. |
832 | */ |
824 | */ |
833 | op->speed -= 0.05; |
825 | op->speed -= 0.05; |
834 | insert_ob_in_map (op, m, op, 0); |
|
|
835 | } |
|
|
836 | |
826 | |
837 | /* This routine doesnt seem to work for "inanimate" objects that |
827 | /* Move the arrow. */ |
838 | * are being carried, ie a held torch leaps from your hands!. |
828 | op->move_to (pos); |
839 | * Modified this routine to allow held objects. b.t. */ |
829 | } |
840 | |
830 | |
841 | void |
831 | void |
842 | change_object (object *op) |
832 | change_object (object *op) |
843 | { /* Doesn`t handle linked objs yet */ |
833 | { /* Doesn`t handle linked objs yet */ |
844 | int i, j; |
834 | int i, j; |
845 | |
835 | |
846 | if (op->other_arch == NULL) |
836 | if (!op->other_arch) |
847 | { |
837 | { |
848 | LOG (llevError, "Change object (%s) without other_arch error.\n", &op->name); |
838 | LOG (llevError, "Change object (%s) without other_arch error.\n", op->debug_desc ()); |
849 | return; |
839 | return; |
850 | } |
840 | } |
851 | |
841 | |
852 | /* In non-living items only change when food value is 0 */ |
842 | /* In non-living items only change when food value is 0 */ |
853 | if (!QUERY_FLAG (op, FLAG_ALIVE)) |
843 | if (!QUERY_FLAG (op, FLAG_ALIVE)) |
854 | { |
844 | { |
855 | if (op->stats.food-- > 0) |
845 | if (op->stats.food-- > 0) |
856 | return; |
846 | return; |
857 | else |
847 | |
858 | op->stats.food = 1; /* so 1 other_arch is made */ |
848 | op->stats.food = 1; /* so 1 other_arch is made */ |
859 | } |
849 | } |
860 | |
850 | |
861 | object *pl = op->in_player (); |
|
|
862 | object *env = op->env; |
851 | object *env = op->env; |
863 | |
852 | |
864 | op->remove (); |
853 | op->remove (); |
865 | for (i = 0; i < NROFNEWOBJS (op); i++) |
854 | for (i = 0; i < op->stats.food; i++) |
866 | { |
855 | { |
867 | object *tmp = arch_to_object (op->other_arch); |
856 | object *tmp = arch_to_object (op->other_arch); |
868 | |
857 | |
869 | if (op->type == LAMP) |
858 | if (op->type == LAMP) |
870 | tmp->stats.food = op->stats.food - 1; |
859 | tmp->stats.food = op->stats.food - 1; |
871 | |
860 | |
872 | tmp->stats.hp = op->stats.hp; /* The only variable it keeps. */ |
861 | tmp->stats.hp = op->stats.hp; /* The only variable it keeps. */ |
873 | if (env) |
862 | if (env) |
874 | { |
863 | { |
875 | tmp->x = env->x, tmp->y = env->y; |
|
|
876 | tmp = insert_ob_in_ob (tmp, env); |
864 | tmp = env->insert (tmp); |
877 | |
865 | |
878 | /* If this object is the players inventory, we need to tell the |
866 | /* If this object is the players inventory, we need to tell the |
879 | * client of the change. Insert_ob_in_map takes care of the |
867 | * client of the change. Insert_ob_in_map takes care of the |
880 | * updating the client, so we don't need to do that below. |
868 | * updating the client, so we don't need to do that below. |
881 | */ |
869 | */ |
882 | if (pl) |
870 | if (object *pl = op->in_player ()) |
883 | { |
871 | { |
884 | esrv_del_item (pl->contr, op->count); |
872 | esrv_del_item (pl->contr, op->count); |
885 | esrv_send_item (pl, tmp); |
873 | esrv_send_item (pl, tmp); |
886 | } |
874 | } |
887 | } |
875 | } |
888 | else |
876 | else |
889 | { |
877 | { |
890 | j = find_first_free_spot (tmp, op->map, op->x, op->y); |
878 | j = find_first_free_spot (tmp, op->map, op->x, op->y); |
891 | if (j == -1) /* No free spot */ |
879 | if (j < 0) /* No free spot */ |
892 | tmp->destroy (); |
880 | tmp->destroy (); |
893 | else |
881 | else |
894 | { |
882 | { |
895 | tmp->x = op->x + freearr_x[j], tmp->y = op->y + freearr_y[j]; |
883 | mapxy pos (op); pos.move (j); |
896 | insert_ob_in_map (tmp, op->map, op, 0); |
884 | |
|
|
885 | if (pos.normalise ()) |
|
|
886 | pos.insert (tmp, op); |
897 | } |
887 | } |
898 | } |
888 | } |
899 | } |
889 | } |
900 | |
890 | |
901 | op->destroy (); |
891 | op->destroy (); |
… | |
… | |
1219 | new_ob = object_create_arch (creator->other_arch); |
1209 | new_ob = object_create_arch (creator->other_arch); |
1220 | fix_generated_item (new_ob, creator, 0, 0, GT_MINIMAL); |
1210 | fix_generated_item (new_ob, creator, 0, 0, GT_MINIMAL); |
1221 | } |
1211 | } |
1222 | |
1212 | |
1223 | /* Make sure this multipart object fits */ |
1213 | /* Make sure this multipart object fits */ |
1224 | if (new_ob->arch->more && ob_blocked (new_ob, creator->map, creator->x, creator->y)) |
1214 | if (new_ob->arch->more && new_ob->blocked (creator->map, creator->x, creator->y)) |
1225 | { |
1215 | { |
1226 | new_ob->destroy (); |
1216 | new_ob->destroy (); |
1227 | return; |
1217 | return; |
1228 | } |
1218 | } |
1229 | |
1219 | |
… | |
… | |
1321 | if (QUERY_FLAG (op, FLAG_APPLIED)) |
1311 | if (QUERY_FLAG (op, FLAG_APPLIED)) |
1322 | remove_force (op); |
1312 | remove_force (op); |
1323 | else |
1313 | else |
1324 | { |
1314 | { |
1325 | /* If necessary, delete the item from the players inventory */ |
1315 | /* If necessary, delete the item from the players inventory */ |
1326 | object *pl = op->in_player (); |
1316 | if (object *pl = op->in_player ()) |
1327 | |
|
|
1328 | if (pl) |
|
|
1329 | esrv_del_item (pl->contr, op->count); |
1317 | esrv_del_item (pl->contr, op->count); |
1330 | |
1318 | |
1331 | op->remove (); |
1319 | op->remove (); |
1332 | |
1320 | |
1333 | if (QUERY_FLAG (op, FLAG_SEE_ANYWHERE)) |
1321 | if (QUERY_FLAG (op, FLAG_SEE_ANYWHERE)) |