… | |
… | |
91 | && npc->enemy->type != PLAYER |
91 | && npc->enemy->type != PLAYER |
92 | && npc->enemy->type != GOLEM) |
92 | && npc->enemy->type != GOLEM) |
93 | npc->enemy = NULL; |
93 | npc->enemy = NULL; |
94 | |
94 | |
95 | } |
95 | } |
|
|
96 | |
96 | return can_detect_enemy (npc, npc->enemy, rv) ? npc->enemy : NULL; |
97 | return can_detect_enemy (npc, npc->enemy, rv) ? npc->enemy : NULL; |
97 | } |
98 | } |
98 | |
99 | |
99 | /* Returns the nearest living creature (monster or generator). |
100 | /* Returns the nearest living creature (monster or generator). |
100 | * Modified to deal with tiled maps properly. |
101 | * Modified to deal with tiled maps properly. |
… | |
… | |
166 | { |
167 | { |
167 | tmp = find_nearest_living_creature (npc); |
168 | tmp = find_nearest_living_creature (npc); |
168 | |
169 | |
169 | if (tmp) |
170 | if (tmp) |
170 | get_rangevector (npc, tmp, rv, 0); |
171 | get_rangevector (npc, tmp, rv, 0); |
|
|
172 | |
171 | return tmp; |
173 | return tmp; |
172 | } |
174 | } |
173 | |
175 | |
174 | /* Here is the main enemy selection. |
176 | /* Here is the main enemy selection. |
175 | * 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 |
… | |
… | |
1664 | * 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 |
1665 | * 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 |
1666 | * be within the valid range. MSW 2001-08-05 |
1668 | * be within the valid range. MSW 2001-08-05 |
1667 | * 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 |
1668 | */ |
1670 | */ |
1669 | |
|
|
1670 | int |
1671 | int |
1671 | can_detect_enemy (object *op, object *enemy, rv_vector * rv) |
1672 | can_detect_enemy (object *op, object *enemy, rv_vector * rv) |
1672 | { |
1673 | { |
1673 | int radius = MIN_MON_RADIUS, hide_discovery; |
1674 | int radius = MIN_MON_RADIUS, hide_discovery; |
1674 | |
1675 | |
… | |
… | |
1705 | /* use this for invis also */ |
1706 | /* use this for invis also */ |
1706 | hide_discovery = op->stats.Int / 5; |
1707 | hide_discovery = op->stats.Int / 5; |
1707 | |
1708 | |
1708 | /* Determine Detection radii */ |
1709 | /* Determine Detection radii */ |
1709 | if (!enemy->hide) /* to detect non-hidden (eg dark/invis enemy) */ |
1710 | if (!enemy->hide) /* to detect non-hidden (eg dark/invis enemy) */ |
1710 | 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); |
1711 | else |
1712 | else |
1712 | { /* a level/INT/Dex adjustment for hiding */ |
1713 | { /* a level/INT/Dex adjustment for hiding */ |
1713 | object *sk_hide; |
|
|
1714 | int bonus = (op->level / 2) + (op->stats.Int / 5); |
1714 | int bonus = op->level / 2 + op->stats.Int / 5; |
1715 | |
1715 | |
1716 | if (enemy->type == PLAYER) |
1716 | if (enemy->type == PLAYER) |
1717 | { |
1717 | { |
1718 | if ((sk_hide = find_skill_by_number (enemy, SK_HIDING))) |
1718 | if (object *sk_hide = find_skill_by_number (enemy, SK_HIDING)) |
1719 | bonus -= sk_hide->level; |
1719 | bonus -= sk_hide->level; |
1720 | else |
1720 | else |
1721 | { |
1721 | { |
1722 | 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"); |
1723 | make_visible (enemy); |
1723 | make_visible (enemy); |
… | |
… | |
1732 | } /* else creature has modifiers for hiding */ |
1732 | } /* else creature has modifiers for hiding */ |
1733 | |
1733 | |
1734 | /* Radii stealth adjustment. Only if you are stealthy |
1734 | /* Radii stealth adjustment. Only if you are stealthy |
1735 | * will you be able to sneak up closer to creatures */ |
1735 | * will you be able to sneak up closer to creatures */ |
1736 | if (QUERY_FLAG (enemy, FLAG_STEALTH)) |
1736 | if (QUERY_FLAG (enemy, FLAG_STEALTH)) |
1737 | radius = radius / 2, hide_discovery = hide_discovery / 3; |
1737 | { |
|
|
1738 | radius /= 2; |
|
|
1739 | hide_discovery /= 3; |
|
|
1740 | } |
1738 | |
1741 | |
1739 | /* Radii adjustment for enemy standing in the dark */ |
1742 | /* Radii adjustment for enemy standing in the dark */ |
1740 | if (op->map->darkness > 0 && !stand_in_light (enemy)) |
1743 | if (op->map->darkness > 0 && !stand_in_light (enemy)) |
1741 | { |
1744 | { |
1742 | /* on dark maps body heat can help indicate location with infravision |
1745 | /* on dark maps body heat can help indicate location with infravision |
… | |
… | |
1760 | * 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 |
1761 | * do something. Note that the distance field in the |
1764 | * do something. Note that the distance field in the |
1762 | * 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 |
1763 | * find that. |
1766 | * find that. |
1764 | */ |
1767 | */ |
1765 | if (radius > 13) |
1768 | // note that the above reasoning was utter bullshit even at the time it was written |
1766 | radius = 13; |
1769 | // we use 25, lets see if we have the cpu time for it |
|
|
1770 | radius = min (25, radius); |
1767 | |
1771 | |
1768 | /* Enemy in range! Now test for detection */ |
1772 | /* Enemy in range! Now test for detection */ |
1769 | if ((int) rv->distance <= radius) |
1773 | if (rv->distance <= radius) |
1770 | { |
1774 | { |
1771 | /* ah, we are within range, detected? take cases */ |
1775 | /* ah, we are within range, detected? take cases */ |
1772 | if (!enemy->invisible) /* enemy in dark squares... are seen! */ |
1776 | if (!enemy->invisible) /* enemy in dark squares... are seen! */ |
1773 | return 1; |
1777 | return 1; |
1774 | |
1778 | |
1775 | /* hidden or low-quality invisible */ |
1779 | /* hidden or low-quality invisible */ |
1776 | if (enemy->hide && (rv->distance <= 1) && (rndm (100) <= hide_discovery)) |
1780 | if (enemy->hide && rv->distance <= 1 && rndm (100) <= hide_discovery) |
1777 | { |
1781 | { |
1778 | make_visible (enemy); |
1782 | make_visible (enemy); |
|
|
1783 | |
1779 | /* inform players of new status */ |
1784 | /* inform players of new status */ |
1780 | if (enemy->type == PLAYER && player_can_view (enemy, op)) |
1785 | if (enemy->type == PLAYER && player_can_view (enemy, op)) |
1781 | 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 | |
1782 | return 1; /* detected enemy */ |
1788 | return 1; /* detected enemy */ |
1783 | } |
1789 | } |
1784 | else if (enemy->invisible) |
1790 | else if (enemy->invisible) |
1785 | { |
1791 | { |
1786 | /* Change this around - instead of negating the invisible, just |
1792 | /* Change this around - instead of negating the invisible, just |
1787 | * 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 |
1788 | * do something to you. Decreasing the duration of invisible |
1794 | * do something to you. Decreasing the duration of invisible |
1789 | * 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 |
1790 | * can then basically negate the spell. The spell isn't negated - |
1796 | * can then basically negate the spell. The spell isn't negated - |
1791 | * they just know where you are! |
1797 | * they just know where you are! |
1792 | */ |
1798 | */ |
1793 | if ((rndm (50)) <= hide_discovery) |
1799 | if (rndm (50) <= hide_discovery) |
1794 | { |
1800 | { |
1795 | if (enemy->type == PLAYER) |
1801 | if (enemy->type == PLAYER) |
1796 | { |
|
|
1797 | 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)); |
1798 | } |
1803 | |
1799 | return 1; |
1804 | return 1; |
1800 | } |
1805 | } |
1801 | } |
1806 | } |
1802 | } /* within range */ |
1807 | } /* within range */ |
1803 | |
1808 | |
… | |
… | |
1811 | * other side of a wall (!). |
1816 | * other side of a wall (!). |
1812 | */ |
1817 | */ |
1813 | int |
1818 | int |
1814 | stand_in_light (object *op) |
1819 | stand_in_light (object *op) |
1815 | { |
1820 | { |
1816 | sint16 nx, ny; |
|
|
1817 | maptile *m; |
|
|
1818 | |
|
|
1819 | if (!op) |
1821 | if (!op) |
1820 | return 0; |
1822 | return 0; |
1821 | |
1823 | |
1822 | if (op->glow_radius > 0) |
1824 | if (op->glow_radius > 0) |
1823 | return 1; |
1825 | return 1; |
1824 | |
1826 | |
1825 | if (op->map) |
1827 | if (op->map) |
1826 | { |
1828 | { |
1827 | int x, y, x1, y1; |
|
|
1828 | |
|
|
1829 | /* 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 |
1830 | * 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. |
1831 | */ |
1831 | */ |
1832 | 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++) |
1833 | { |
1833 | { |
1834 | 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++) |
1835 | { |
1835 | { |
1836 | m = op->map; |
1836 | maptile *m = op->map; |
1837 | nx = x; |
1837 | sint16 nx = x; |
1838 | ny = y; |
1838 | sint16 ny = y; |
1839 | |
1839 | |
1840 | if (get_map_flags (m, &m, nx, ny, &nx, &ny) & P_OUT_OF_MAP) |
1840 | if (xy_normalise (m, nx, ny)) |
1841 | continue; |
1841 | if (idistance (x - op->x, y - op->y) < m->at (nx, ny).light) |
1842 | |
|
|
1843 | x1 = abs (x - op->x) * abs (x - op->x); |
|
|
1844 | y1 = abs (y - op->y) * abs (y - op->y); |
|
|
1845 | if (isqrt (x1 + y1) < GET_MAP_LIGHT (m, nx, ny)) |
|
|
1846 | return 1; |
1842 | return 1; |
1847 | } |
1843 | } |
1848 | } |
1844 | } |
1849 | } |
1845 | } |
1850 | |
1846 | |
1851 | return 0; |
1847 | return 0; |