1 | /* |
1 | /* |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2002 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
6 | * Copyright (©) 1992 Frank Tore Johansen |
7 | * |
7 | * |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
9 | * the terms of the Affero GNU General Public License as published by the |
9 | * the terms of the Affero GNU General Public License as published by the |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
11 | * option) any later version. |
11 | * option) any later version. |
… | |
… | |
277 | static int |
277 | static int |
278 | move_randomly (object *op) |
278 | move_randomly (object *op) |
279 | { |
279 | { |
280 | /* Give up to 15 chances for a monster to move randomly */ |
280 | /* Give up to 15 chances for a monster to move randomly */ |
281 | for (int i = 0; i < 15; i++) |
281 | for (int i = 0; i < 15; i++) |
282 | if (move_object (op, rndm (8) + 1)) |
282 | if (op->move (rndm (8) + 1)) |
283 | return 1; |
283 | return 1; |
284 | |
284 | |
285 | return 0; |
285 | return 0; |
286 | } |
286 | } |
287 | |
287 | |
… | |
… | |
786 | static int circle[12] = { 3, 3, 4, 5, 5, 6, 7, 7, 8, 1, 1, 2 }; |
786 | static int circle[12] = { 3, 3, 4, 5, 5, 6, 7, 7, 8, 1, 1, 2 }; |
787 | |
787 | |
788 | if (++ob->move_status > 11) |
788 | if (++ob->move_status > 11) |
789 | ob->move_status = 0; |
789 | ob->move_status = 0; |
790 | |
790 | |
791 | if (!(move_object (ob, circle[ob->move_status]))) |
791 | if (!(ob->move (circle[ob->move_status]))) |
792 | move_object (ob, rndm (8) + 1); |
792 | ob->move (rndm (8) + 1); |
793 | } |
793 | } |
794 | |
794 | |
795 | static void |
795 | static void |
796 | circ2_move (object *ob) |
796 | circ2_move (object *ob) |
797 | { |
797 | { |
798 | static int circle[20] = { 3, 3, 3, 4, 4, 5, 5, 5, 6, 6, 7, 7, 7, 8, 8, 1, 1, 1, 2, 2 }; |
798 | static int circle[20] = { 3, 3, 3, 4, 4, 5, 5, 5, 6, 6, 7, 7, 7, 8, 8, 1, 1, 1, 2, 2 }; |
799 | |
799 | |
800 | if (++ob->move_status > 19) |
800 | if (++ob->move_status > 19) |
801 | ob->move_status = 0; |
801 | ob->move_status = 0; |
802 | |
802 | |
803 | if (!(move_object (ob, circle[ob->move_status]))) |
803 | if (!(ob->move (circle[ob->move_status]))) |
804 | move_object (ob, rndm (8) + 1); |
804 | ob->move (rndm (8) + 1); |
805 | } |
805 | } |
806 | |
806 | |
807 | static void |
807 | static void |
808 | pace_movev (object *ob) |
808 | pace_movev (object *ob) |
809 | { |
809 | { |
810 | if (ob->move_status++ > 6) |
810 | if (ob->move_status++ > 6) |
811 | ob->move_status = 0; |
811 | ob->move_status = 0; |
812 | |
812 | |
813 | if (ob->move_status < 4) |
813 | if (ob->move_status < 4) |
814 | move_object (ob, 5); |
814 | ob->move (5); |
815 | else |
815 | else |
816 | move_object (ob, 1); |
816 | ob->move (1); |
817 | } |
817 | } |
818 | |
818 | |
819 | static void |
819 | static void |
820 | pace_moveh (object *ob) |
820 | pace_moveh (object *ob) |
821 | { |
821 | { |
822 | if (ob->move_status++ > 6) |
822 | if (ob->move_status++ > 6) |
823 | ob->move_status = 0; |
823 | ob->move_status = 0; |
824 | |
824 | |
825 | if (ob->move_status < 4) |
825 | if (ob->move_status < 4) |
826 | move_object (ob, 3); |
826 | ob->move (3); |
827 | else |
827 | else |
828 | move_object (ob, 7); |
828 | ob->move (7); |
829 | } |
829 | } |
830 | |
830 | |
831 | static void |
831 | static void |
832 | pace2_movev (object *ob) |
832 | pace2_movev (object *ob) |
833 | { |
833 | { |
834 | if (ob->move_status++ > 16) |
834 | if (ob->move_status++ > 16) |
835 | ob->move_status = 0; |
835 | ob->move_status = 0; |
836 | |
836 | |
837 | if (ob->move_status < 6) |
837 | if (ob->move_status < 6) |
838 | move_object (ob, 5); |
838 | ob->move (5); |
839 | else if (ob->move_status < 8) |
839 | else if (ob->move_status < 8) |
840 | return; |
840 | return; |
841 | else if (ob->move_status < 13) |
841 | else if (ob->move_status < 13) |
842 | move_object (ob, 1); |
842 | ob->move (1); |
843 | else |
843 | else |
844 | return; |
844 | return; |
845 | } |
845 | } |
846 | |
846 | |
847 | static void |
847 | static void |
… | |
… | |
849 | { |
849 | { |
850 | if (ob->move_status++ > 16) |
850 | if (ob->move_status++ > 16) |
851 | ob->move_status = 0; |
851 | ob->move_status = 0; |
852 | |
852 | |
853 | if (ob->move_status < 6) |
853 | if (ob->move_status < 6) |
854 | move_object (ob, 3); |
854 | ob->move (3); |
855 | else if (ob->move_status < 8) |
855 | else if (ob->move_status < 8) |
856 | return; |
856 | return; |
857 | else if (ob->move_status < 13) |
857 | else if (ob->move_status < 13) |
858 | move_object (ob, 7); |
858 | ob->move (7); |
859 | else |
859 | else |
860 | return; |
860 | return; |
861 | } |
861 | } |
862 | |
862 | |
863 | static void |
863 | static void |
864 | rand_move (object *ob) |
864 | rand_move (object *ob) |
865 | { |
865 | { |
866 | if (ob->move_status < 1 || ob->move_status > 8 || !(move_object (ob, ob->move_status || !(rndm (9))))) |
866 | if (ob->move_status < 1 || ob->move_status > 8 || !(ob->move (ob->move_status || !(rndm (9))))) |
867 | for (int i = 0; i < 5; i++) |
867 | for (int i = 0; i < 5; i++) |
868 | if (move_object (ob, ob->move_status = rndm (8) + 1)) |
868 | if (ob->move (ob->move_status = rndm (8) + 1)) |
869 | return; |
869 | return; |
870 | } |
870 | } |
871 | |
871 | |
872 | #define MAX_KNOWN_SPELLS 20 |
872 | #define MAX_KNOWN_SPELLS 20 |
873 | |
873 | |
… | |
… | |
1060 | } |
1060 | } |
1061 | |
1061 | |
1062 | if (QUERY_FLAG (head, FLAG_CONFUSED)) |
1062 | if (QUERY_FLAG (head, FLAG_CONFUSED)) |
1063 | dir = absdir (dir + rndm (3) + rndm (3) - 2); |
1063 | dir = absdir (dir + rndm (3) + rndm (3) - 2); |
1064 | |
1064 | |
|
|
1065 | object *new_skill = 0; |
|
|
1066 | |
1065 | /* skill selection - monster will use the next unused skill. |
1067 | // skill selection - monster will use the last unused skill |
1066 | * well...the following scenario will allow the monster to |
1068 | // and rotate, eventually cycling through all skills. |
1067 | * toggle between 2 skills. One day it would be nice to make |
|
|
1068 | * more skills available to monsters. |
|
|
1069 | */ |
|
|
1070 | for (skill = head->inv; skill; skill = skill->below) |
1069 | for (skill = head->inv; skill; skill = skill->below) |
1071 | if (skill->type == SKILL && skill != head->chosen_skill) |
1070 | if (skill->type == SKILL && skill != head->chosen_skill) |
1072 | { |
1071 | new_skill = skill; |
|
|
1072 | |
|
|
1073 | if (new_skill) |
1073 | head->chosen_skill = skill; |
1074 | splay (head->chosen_skill = new_skill); |
1074 | break; |
|
|
1075 | } |
|
|
1076 | |
|
|
1077 | if (!skill && !head->chosen_skill) |
1075 | else if (!head->chosen_skill) |
1078 | { |
1076 | { |
1079 | LOG (llevDebug, "Error: Monster %s (%d) has FLAG_READY_SKILL without skill.\n", &head->name, head->count); |
1077 | LOG (llevDebug, "Error: Monster %s (%d) has FLAG_READY_SKILL without skill.\n", &head->name, head->count); |
1080 | CLEAR_FLAG (head, FLAG_READY_SKILL); |
1078 | CLEAR_FLAG (head, FLAG_READY_SKILL); |
1081 | return 0; |
1079 | return 0; |
1082 | } |
1080 | } |
… | |
… | |
1580 | if (!dir) |
1578 | if (!dir) |
1581 | return 0; |
1579 | return 0; |
1582 | |
1580 | |
1583 | if (!QUERY_FLAG (op, FLAG_STAND_STILL)) |
1581 | if (!QUERY_FLAG (op, FLAG_STAND_STILL)) |
1584 | { |
1582 | { |
1585 | if (move_object (op, dir)) /* Can the monster move directly toward player? */ |
1583 | if (op->move (dir)) /* Can the monster move directly toward player? */ |
1586 | { |
1584 | { |
1587 | /* elmex: Turn our monster after it moved if it has DISTATT attack */ |
1585 | /* elmex: Turn our monster after it moved if it has DISTATT attack */ |
1588 | if ((op->attack_movement & LO4) == DISTATT) |
1586 | if ((op->attack_movement & LO4) == DISTATT) |
1589 | op->direction = pre_att_dir; |
1587 | op->direction = pre_att_dir; |
1590 | |
1588 | |
… | |
… | |
1599 | for (diff = 1; diff <= maxdiff; diff++) |
1597 | for (diff = 1; diff <= maxdiff; diff++) |
1600 | { |
1598 | { |
1601 | /* try different detours */ |
1599 | /* try different detours */ |
1602 | int m = 1 - rndm (2) * 2; /* Try left or right first? */ |
1600 | int m = 1 - rndm (2) * 2; /* Try left or right first? */ |
1603 | |
1601 | |
1604 | if (move_object (op, absdir (dir + diff * m)) || move_object (op, absdir (dir - diff * m))) |
1602 | if (op->move (absdir (dir + diff * m)) || op->move (absdir (dir - diff * m))) |
1605 | return 0; |
1603 | return 0; |
1606 | } |
1604 | } |
1607 | } |
1605 | } |
1608 | } /* if monster is not standing still */ |
1606 | } /* if monster is not standing still */ |
1609 | |
1607 | |