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,2008 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 it |
8 | * Deliantra is free software: you can redistribute it and/or modify |
9 | * under the terms of the GNU General Public License as published by the Free |
9 | * it under the terms of the GNU General Public License as published by |
10 | * Software Foundation; either version 2 of the License, or (at your option) |
10 | * the Free Software Foundation, either version 3 of the License, or |
11 | * 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, but |
13 | * This program is distributed in the hope that it will be useful, |
14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * 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 along |
18 | * You should have received a copy of the GNU General Public License |
19 | * with Crossfire TRT; if not, write to the Free Software Foundation, Inc. 51 |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
20 | * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
|
21 | * |
20 | * |
22 | * 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> |
23 | */ |
22 | */ |
24 | |
23 | |
25 | #include <global.h> |
24 | #include <global.h> |
26 | #include <sproto.h> |
25 | #include <sproto.h> |
27 | #include <spells.h> |
26 | #include <spells.h> |
… | |
… | |
92 | && npc->enemy->type != PLAYER |
91 | && npc->enemy->type != PLAYER |
93 | && npc->enemy->type != GOLEM) |
92 | && npc->enemy->type != GOLEM) |
94 | npc->enemy = NULL; |
93 | npc->enemy = NULL; |
95 | |
94 | |
96 | } |
95 | } |
|
|
96 | |
97 | return can_detect_enemy (npc, npc->enemy, rv) ? npc->enemy : NULL; |
97 | return can_detect_enemy (npc, npc->enemy, rv) ? npc->enemy : NULL; |
98 | } |
98 | } |
99 | |
99 | |
100 | /* Returns the nearest living creature (monster or generator). |
100 | /* Returns the nearest living creature (monster or generator). |
101 | * Modified to deal with tiled maps properly. |
101 | * Modified to deal with tiled maps properly. |
… | |
… | |
167 | { |
167 | { |
168 | tmp = find_nearest_living_creature (npc); |
168 | tmp = find_nearest_living_creature (npc); |
169 | |
169 | |
170 | if (tmp) |
170 | if (tmp) |
171 | get_rangevector (npc, tmp, rv, 0); |
171 | get_rangevector (npc, tmp, rv, 0); |
|
|
172 | |
172 | return tmp; |
173 | return tmp; |
173 | } |
174 | } |
174 | |
175 | |
175 | /* Here is the main enemy selection. |
176 | /* Here is the main enemy selection. |
176 | * We want this: if there is an enemy, attack him until its not possible or |
177 | * We want this: if there is an enemy, attack him until its not possible or |
… | |
… | |
371 | if (!check_wakeup (op, enemy, &rv)) |
372 | if (!check_wakeup (op, enemy, &rv)) |
372 | return 0; |
373 | return 0; |
373 | } |
374 | } |
374 | |
375 | |
375 | /* check if monster pops out of hidden spot */ |
376 | /* check if monster pops out of hidden spot */ |
376 | if (op->hide) |
377 | if (op->flag [FLAG_HIDDEN]) |
377 | do_hidden_move (op); |
378 | do_hidden_move (op); |
378 | |
379 | |
379 | if (op->pick_up) |
380 | if (op->pick_up) |
380 | monster_check_pickup (op); |
381 | monster_check_pickup (op); |
381 | |
382 | |
… | |
… | |
385 | /* If we don't have an enemy, do special movement or the like */ |
386 | /* If we don't have an enemy, do special movement or the like */ |
386 | if (!enemy) |
387 | if (!enemy) |
387 | { |
388 | { |
388 | if (QUERY_FLAG (op, FLAG_ONLY_ATTACK)) |
389 | if (QUERY_FLAG (op, FLAG_ONLY_ATTACK)) |
389 | { |
390 | { |
390 | op->destroy (); |
391 | op->drop_and_destroy (); |
391 | return 1; |
392 | return 1; |
392 | } |
393 | } |
393 | |
394 | |
394 | /* Probably really a bug for a creature to have both |
395 | /* Probably really a bug for a creature to have both |
395 | * stand still and a movement type set. |
396 | * stand still and a movement type set. |
… | |
… | |
649 | if (QUERY_FLAG (part, FLAG_FREED)) /* Might be freed by ghost-attack or hit-back */ |
650 | if (QUERY_FLAG (part, FLAG_FREED)) /* Might be freed by ghost-attack or hit-back */ |
650 | return 1; |
651 | return 1; |
651 | |
652 | |
652 | if (QUERY_FLAG (op, FLAG_ONLY_ATTACK)) |
653 | if (QUERY_FLAG (op, FLAG_ONLY_ATTACK)) |
653 | { |
654 | { |
654 | op->remove (); |
|
|
655 | op->destroy (); |
655 | op->drop_and_destroy (); |
656 | return 1; |
656 | return 1; |
657 | } |
657 | } |
|
|
658 | |
658 | return 0; |
659 | return 0; |
659 | } |
660 | } |
660 | |
661 | |
661 | int |
662 | int |
662 | can_hit (object *ob1, object *ob2, rv_vector * rv) |
663 | can_hit (object *ob1, object *ob2, rv_vector * rv) |
… | |
… | |
1665 | * properly. I also so odd code in place that checked for x distance |
1666 | * properly. I also so odd code in place that checked for x distance |
1666 | * OR y distance being within some range - that seemed wrong - both should |
1667 | * OR y distance being within some range - that seemed wrong - both should |
1667 | * be within the valid range. MSW 2001-08-05 |
1668 | * be within the valid range. MSW 2001-08-05 |
1668 | * Returns 0 if enemy can not be detected, 1 if it is detected |
1669 | * Returns 0 if enemy can not be detected, 1 if it is detected |
1669 | */ |
1670 | */ |
1670 | |
|
|
1671 | int |
1671 | int |
1672 | can_detect_enemy (object *op, object *enemy, rv_vector * rv) |
1672 | can_detect_enemy (object *op, object *enemy, rv_vector * rv) |
1673 | { |
1673 | { |
1674 | int radius = MIN_MON_RADIUS, hide_discovery; |
1674 | int radius = MIN_MON_RADIUS, hide_discovery; |
1675 | |
1675 | |
… | |
… | |
1705 | |
1705 | |
1706 | /* use this for invis also */ |
1706 | /* use this for invis also */ |
1707 | hide_discovery = op->stats.Int / 5; |
1707 | hide_discovery = op->stats.Int / 5; |
1708 | |
1708 | |
1709 | /* Determine Detection radii */ |
1709 | /* Determine Detection radii */ |
1710 | if (!enemy->hide) /* to detect non-hidden (eg dark/invis enemy) */ |
1710 | if (!enemy->flag [FLAG_HIDDEN]) /* to detect non-hidden (eg dark/invis enemy) */ |
1711 | radius = (op->stats.Wis / 5) + 1 > MIN_MON_RADIUS ? (op->stats.Wis / 5) + 1 : MIN_MON_RADIUS; |
1711 | radius = max (MIN_MON_RADIUS, op->stats.Wis / 5 + 1); |
1712 | else |
1712 | else |
1713 | { /* a level/INT/Dex adjustment for hiding */ |
1713 | { /* a level/INT/Dex adjustment for hiding */ |
1714 | object *sk_hide; |
|
|
1715 | int bonus = (op->level / 2) + (op->stats.Int / 5); |
1714 | int bonus = op->level / 2 + op->stats.Int / 5; |
1716 | |
1715 | |
1717 | if (enemy->type == PLAYER) |
1716 | if (enemy->type == PLAYER) |
1718 | { |
1717 | { |
1719 | if ((sk_hide = find_skill_by_number (enemy, SK_HIDING))) |
1718 | if (object *sk_hide = find_skill_by_number (enemy, SK_HIDING)) |
1720 | bonus -= sk_hide->level; |
1719 | bonus -= sk_hide->level; |
1721 | else |
1720 | else |
1722 | { |
1721 | { |
1723 | LOG (llevError, "can_detect_enemy() got hidden player w/o hiding skill!\n"); |
1722 | LOG (llevError, "can_detect_enemy() got hidden player w/o hiding skill!\n"); |
1724 | make_visible (enemy); |
1723 | make_visible (enemy); |
… | |
… | |
1733 | } /* else creature has modifiers for hiding */ |
1732 | } /* else creature has modifiers for hiding */ |
1734 | |
1733 | |
1735 | /* Radii stealth adjustment. Only if you are stealthy |
1734 | /* Radii stealth adjustment. Only if you are stealthy |
1736 | * will you be able to sneak up closer to creatures */ |
1735 | * will you be able to sneak up closer to creatures */ |
1737 | if (QUERY_FLAG (enemy, FLAG_STEALTH)) |
1736 | if (QUERY_FLAG (enemy, FLAG_STEALTH)) |
1738 | radius = radius / 2, hide_discovery = hide_discovery / 3; |
1737 | { |
|
|
1738 | radius /= 2; |
|
|
1739 | hide_discovery /= 3; |
|
|
1740 | } |
1739 | |
1741 | |
1740 | /* Radii adjustment for enemy standing in the dark */ |
1742 | /* Radii adjustment for enemy standing in the dark */ |
1741 | if (op->map->darkness > 0 && !stand_in_light (enemy)) |
1743 | if (op->map->darkness > 0 && !stand_in_light (enemy)) |
1742 | { |
1744 | { |
1743 | /* on dark maps body heat can help indicate location with infravision |
1745 | /* on dark maps body heat can help indicate location with infravision |
… | |
… | |
1761 | * may have for their map - in that way, creatures at the edge will |
1763 | * may have for their map - in that way, creatures at the edge will |
1762 | * do something. Note that the distance field in the |
1764 | * do something. Note that the distance field in the |
1763 | * vector is real distance, so in theory this should be 18 to |
1765 | * vector is real distance, so in theory this should be 18 to |
1764 | * find that. |
1766 | * find that. |
1765 | */ |
1767 | */ |
1766 | if (radius > 13) |
1768 | // note that the above reasoning was utter bullshit even at the time it was written |
1767 | radius = 13; |
1769 | // we use 25, lets see if we have the cpu time for it |
|
|
1770 | radius = min (25, radius); |
1768 | |
1771 | |
1769 | /* Enemy in range! Now test for detection */ |
1772 | /* Enemy in range! Now test for detection */ |
1770 | if ((int) rv->distance <= radius) |
1773 | if (rv->distance <= radius) |
1771 | { |
1774 | { |
1772 | /* ah, we are within range, detected? take cases */ |
1775 | /* ah, we are within range, detected? take cases */ |
1773 | if (!enemy->invisible) /* enemy in dark squares... are seen! */ |
1776 | if (!enemy->invisible) /* enemy in dark squares... are seen! */ |
1774 | return 1; |
1777 | return 1; |
1775 | |
1778 | |
1776 | /* hidden or low-quality invisible */ |
1779 | /* hidden or low-quality invisible */ |
1777 | if (enemy->hide && (rv->distance <= 1) && (rndm (100) <= hide_discovery)) |
1780 | if (enemy->flag [FLAG_HIDDEN] && rv->distance <= 1 && rndm (100) <= hide_discovery) |
1778 | { |
1781 | { |
1779 | make_visible (enemy); |
1782 | make_visible (enemy); |
|
|
1783 | |
1780 | /* inform players of new status */ |
1784 | /* inform players of new status */ |
1781 | if (enemy->type == PLAYER && player_can_view (enemy, op)) |
1785 | if (enemy->type == PLAYER && player_can_view (enemy, op)) |
1782 | new_draw_info_format (NDI_UNIQUE, 0, enemy, "You are discovered by %s!", &op->name); |
1786 | new_draw_info_format (NDI_UNIQUE, 0, enemy, "You are discovered by %s!", &op->name); |
|
|
1787 | |
1783 | return 1; /* detected enemy */ |
1788 | return 1; /* detected enemy */ |
1784 | } |
1789 | } |
1785 | else if (enemy->invisible) |
1790 | else if (enemy->invisible) |
1786 | { |
1791 | { |
1787 | /* Change this around - instead of negating the invisible, just |
1792 | /* Change this around - instead of negating the invisible, just |
1788 | * return true so that the mosnter that managed to detect you can |
1793 | * return true so that the monster that managed to detect you can |
1789 | * do something to you. Decreasing the duration of invisible |
1794 | * do something to you. Decreasing the duration of invisible |
1790 | * doesn't make a lot of sense IMO, as a bunch of stupid creatures |
1795 | * doesn't make a lot of sense IMO, as a bunch of stupid creatures |
1791 | * can then basically negate the spell. The spell isn't negated - |
1796 | * can then basically negate the spell. The spell isn't negated - |
1792 | * they just know where you are! |
1797 | * they just know where you are! |
1793 | */ |
1798 | */ |
1794 | if ((rndm (50)) <= hide_discovery) |
1799 | if (rndm (50) <= hide_discovery) |
1795 | { |
1800 | { |
1796 | if (enemy->type == PLAYER) |
1801 | if (enemy->type == PLAYER) |
1797 | { |
|
|
1798 | new_draw_info_format (NDI_UNIQUE, 0, enemy, "You see %s noticing your position.", query_name (op)); |
1802 | new_draw_info_format (NDI_UNIQUE, 0, enemy, "You see %s noticing your position.", query_name (op)); |
1799 | } |
1803 | |
1800 | return 1; |
1804 | return 1; |
1801 | } |
1805 | } |
1802 | } |
1806 | } |
1803 | } /* within range */ |
1807 | } /* within range */ |
1804 | |
1808 | |
… | |
… | |
1812 | * other side of a wall (!). |
1816 | * other side of a wall (!). |
1813 | */ |
1817 | */ |
1814 | int |
1818 | int |
1815 | stand_in_light (object *op) |
1819 | stand_in_light (object *op) |
1816 | { |
1820 | { |
1817 | sint16 nx, ny; |
|
|
1818 | maptile *m; |
|
|
1819 | |
|
|
1820 | if (!op) |
1821 | if (!op) |
1821 | return 0; |
1822 | return 0; |
1822 | |
1823 | |
1823 | if (op->glow_radius > 0) |
1824 | if (op->glow_radius > 0) |
1824 | return 1; |
1825 | return 1; |
1825 | |
1826 | |
1826 | if (op->map) |
1827 | if (op->map) |
1827 | { |
1828 | { |
1828 | int x, y, x1, y1; |
|
|
1829 | |
|
|
1830 | /* Check the spaces with the max light radius to see if any of them |
1829 | /* Check the spaces with the max light radius to see if any of them |
1831 | * have lights, and if any of them light the player enough, then return 1. |
1830 | * have lights, and if any of them light the player enough, then return 1. |
1832 | */ |
1831 | */ |
1833 | for (x = op->x - MAX_LIGHT_RADII; x <= op->x + MAX_LIGHT_RADII; x++) |
1832 | for (int x = op->x - MAX_LIGHT_RADII; x <= op->x + MAX_LIGHT_RADII; x++) |
1834 | { |
1833 | { |
1835 | for (y = op->y - MAX_LIGHT_RADII; y <= op->y + MAX_LIGHT_RADII; y++) |
1834 | for (int y = op->y - MAX_LIGHT_RADII; y <= op->y + MAX_LIGHT_RADII; y++) |
1836 | { |
1835 | { |
1837 | m = op->map; |
1836 | maptile *m = op->map; |
1838 | nx = x; |
1837 | sint16 nx = x; |
1839 | ny = y; |
1838 | sint16 ny = y; |
1840 | |
1839 | |
1841 | if (get_map_flags (m, &m, nx, ny, &nx, &ny) & P_OUT_OF_MAP) |
1840 | if (xy_normalise (m, nx, ny)) |
1842 | continue; |
1841 | if (idistance (x - op->x, y - op->y) < m->at (nx, ny).light) |
1843 | |
|
|
1844 | x1 = abs (x - op->x) * abs (x - op->x); |
|
|
1845 | y1 = abs (y - op->y) * abs (y - op->y); |
|
|
1846 | if (isqrt (x1 + y1) < GET_MAP_LIGHT (m, nx, ny)) |
|
|
1847 | return 1; |
1842 | return 1; |
1848 | } |
1843 | } |
1849 | } |
1844 | } |
1850 | } |
1845 | } |
1851 | |
1846 | |
1852 | return 0; |
1847 | return 0; |
… | |
… | |
1880 | * However,if you carry any source of light, then the hidden |
1875 | * However,if you carry any source of light, then the hidden |
1881 | * creature is seeable (and stupid) */ |
1876 | * creature is seeable (and stupid) */ |
1882 | |
1877 | |
1883 | if (has_carried_lights (enemy)) |
1878 | if (has_carried_lights (enemy)) |
1884 | { |
1879 | { |
1885 | if (enemy->hide) |
1880 | if (enemy->flag [FLAG_HIDDEN]) |
1886 | { |
1881 | { |
1887 | make_visible (enemy); |
1882 | make_visible (enemy); |
1888 | new_draw_info (NDI_UNIQUE, 0, enemy, "Your light reveals your hiding spot!"); |
1883 | new_draw_info (NDI_UNIQUE, 0, enemy, "Your light reveals your hiding spot!"); |
1889 | } |
1884 | } |
|
|
1885 | |
1890 | return 1; |
1886 | return 1; |
1891 | } |
1887 | } |
1892 | else if (enemy->hide) |
1888 | else if (enemy->flag [FLAG_HIDDEN]) |
1893 | return 0; |
1889 | return 0; |
1894 | |
1890 | |
1895 | /* Invisible enemy. Break apart the check for invis undead/invis looker |
1891 | /* Invisible enemy. Break apart the check for invis undead/invis looker |
1896 | * into more simple checks - the QUERY_FLAG doesn't return 1/0 values, |
1892 | * into more simple checks - the QUERY_FLAG doesn't return 1/0 values, |
1897 | * and making it a conditional makes the code pretty ugly. |
1893 | * and making it a conditional makes the code pretty ugly. |
1898 | */ |
1894 | */ |
1899 | if (!QUERY_FLAG (looker, FLAG_SEE_INVISIBLE)) |
1895 | if (!QUERY_FLAG (looker, FLAG_SEE_INVISIBLE)) |
1900 | { |
|
|
1901 | if (makes_invisible_to (enemy, looker)) |
1896 | if (makes_invisible_to (enemy, looker)) |
1902 | return 0; |
1897 | return 0; |
1903 | } |
|
|
1904 | } |
1898 | } |
1905 | else if (looker->type == PLAYER) /* for players, a (possible) shortcut */ |
1899 | else if (looker->type == PLAYER) /* for players, a (possible) shortcut */ |
1906 | if (player_can_view (looker, enemy)) |
1900 | if (player_can_view (looker, enemy)) |
1907 | return 1; |
1901 | return 1; |
1908 | |
1902 | |
… | |
… | |
1919 | && (!QUERY_FLAG (looker, FLAG_SEE_IN_DARK) || !is_true_undead (looker) || !QUERY_FLAG (looker, FLAG_XRAYS))) |
1913 | && (!QUERY_FLAG (looker, FLAG_SEE_IN_DARK) || !is_true_undead (looker) || !QUERY_FLAG (looker, FLAG_XRAYS))) |
1920 | return 0; |
1914 | return 0; |
1921 | |
1915 | |
1922 | return 1; |
1916 | return 1; |
1923 | } |
1917 | } |
|
|
1918 | |