ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/monster.C
(Generate patch)

Comparing deliantra/server/server/monster.C (file contents):
Revision 1.55 by root, Sat Dec 27 07:50:05 2008 UTC vs.
Revision 1.59 by root, Sun Dec 28 10:05:42 2008 UTC

236{ 236{
237 /* Trim work - if no enemy, no need to do anything below */ 237 /* Trim work - if no enemy, no need to do anything below */
238 if (!enemy) 238 if (!enemy)
239 return 0; 239 return 0;
240 240
241 if (!op->flag [FLAG_SLEEP])
242 return 1;
243
241 int radius = max (op->stats.Wis, MIN_MON_RADIUS); 244 int radius = max (op->stats.Wis, MIN_MON_RADIUS);
242 245
243 if (op->flag [FLAG_BLIND]) 246 if (op->flag [FLAG_BLIND])
244 /* blinded monsters can only find nearby objects to attack */ 247 /* blinded monsters can only find nearby objects to attack */
245 radius = MIN_MON_RADIUS; 248 radius = MIN_MON_RADIUS;
251 * and has an enemy. If the enemy has no carried light (or isnt 254 * and has an enemy. If the enemy has no carried light (or isnt
252 * glowing!) then the monster has trouble finding the enemy. 255 * glowing!) then the monster has trouble finding the enemy.
253 * Remember we already checked to see if the monster can see in 256 * Remember we already checked to see if the monster can see in
254 * the dark. */ 257 * the dark. */
255 radius = min (radius, MIN_MON_RADIUS + MAX_DARKNESS - op->map->darklevel ()); 258 radius = min (radius, MIN_MON_RADIUS + MAX_DARKNESS - op->map->darklevel ());
256 else if (!op->flag [FLAG_SLEEP])
257 return 1;
258 259
259 if (enemy->flag [FLAG_STEALTH]) 260 if (enemy->flag [FLAG_STEALTH])
260 radius = radius / 2 + 1; 261 radius = radius / 2 + 1;
261 262
262 /* enemy should already be on this map, so don't really need to check 263 /* enemy should already be on this map, so don't really need to check
507 } /* If not scared */ 508 } /* If not scared */
508 509
509 part = rv.part; 510 part = rv.part;
510 dir = rv.direction; 511 dir = rv.direction;
511 512
512#if DEVEL 513 // if the enemy is a player, we have los. if los says we
514 // can directly reach the player, we do not deviate.
515 // for non-players, we never deviate
516 if (enemy->contr && enemy->contr->darkness_at (op->map, op->x, op->y) == LOS_BLOCKED)
517 {
513 int sdir = 0; 518 int sdir = 0;
514 519
515 for (int dir = 1; dir <= 8; ++dir) 520 for (int ndir = 1; ndir <= 8; ++ndir)
516 { 521 {
517 mapxy pos (op); pos.move (dir); 522 mapxy pos (op); pos.move (ndir);
523
518 if (pos.normalise ()) 524 if (pos.normalise ())
519 {
520 mapspace &ms = pos.ms ();
521
522 if (ms.smell > op->ms ().smell)
523 { 525 {
526 mapspace &ms = pos.ms ();
527
528 if (ms.smell > op->ms ().smell)
529 {
524 printf ("%s: found smell, following it, apparently (%d, %d)\n",& op->name,op->ms().smell,ms.smell);//D 530 //printf ("%s: found smell, following it, apparently (%d, %d)\n",& op->name,op->ms().smell,ms.smell);//D
525 op->ms ().smell = ms.smell - 1; 531 op->ms ().smell = ms.smell - 1; // smarter: tell others
526 sdir = dir; 532 sdir = ndir;
527 533
528 // perturbing the path might let the monster lose track, 534 // perturbing the path might let the monster lose track,
529 // but it will also wide the actual path, spreading information 535 // but it will also widen the actual path, spreading information
530 if (!rndm (20)) 536 if (!rndm (20)) // even smarter, deviate and spread?
531 sdir += absdir (1 - rndm (2) * 2); 537 sdir += absdir (1 - rndm (2) * 2);
538 }
532 } 539 }
533 } 540 }
534 }
535 541
536 if (sdir) 542 if (sdir)
537 dir = sdir; 543 dir = sdir;
538 else 544 else if (op->ms ().smell)
545 {
539 // no better smell found, so assume the player jumped, and erase this smell 546 // no better smell found, so assume the player jumped, and erase this smell
540 {if (op->ms ().smell) printf ("erasing smell %d\n", op->ms ().smell);//D 547 //printf ("erasing smell %d\n", op->ms ().smell);//D
541 ordered_mapwalk_begin (op, -1, -1, 1, 1) 548 ordered_mapwalk_begin (op, -1, -1, 1, 1)
542 if (m) 549 if (m)
543 m->at (nx, ny).smell = 0; 550 m->at (nx, ny).smell = 0;
544 ordered_mapwalk_end 551 ordered_mapwalk_end
552 }
545 }//D 553 }
546
547#endif
548 554
549 if (QUERY_FLAG (op, FLAG_SCARED) || QUERY_FLAG (op, FLAG_RUN_AWAY)) 555 if (QUERY_FLAG (op, FLAG_SCARED) || QUERY_FLAG (op, FLAG_RUN_AWAY))
550 dir = absdir (dir + 4); 556 dir = absdir (dir + 4);
551 557
552 if (QUERY_FLAG (op, FLAG_CONFUSED)) 558 if (QUERY_FLAG (op, FLAG_CONFUSED))
1682 * Returns 0 if enemy can not be detected, 1 if it is detected 1688 * Returns 0 if enemy can not be detected, 1 if it is detected
1683 */ 1689 */
1684int 1690int
1685can_detect_enemy (object *op, object *enemy, rv_vector * rv) 1691can_detect_enemy (object *op, object *enemy, rv_vector * rv)
1686{ 1692{
1687 int radius = MIN_MON_RADIUS, hide_discovery;
1688
1689 /* null detection for any of these condtions always */ 1693 /* null detection for any of these condtions always */
1690 if (!op || !enemy || !op->map || !enemy->map) 1694 if (!op || !enemy || !op->map || !enemy->map)
1691 return 0; 1695 return 0;
1692 1696
1693 /* If the monster (op) has no way to get to the enemy, do nothing */ 1697 /* If the monster (op) has no way to get to the enemy, do nothing */
1695 return 0; 1699 return 0;
1696 1700
1697 get_rangevector (op, enemy, rv, 0); 1701 get_rangevector (op, enemy, rv, 0);
1698 1702
1699 /* Monsters always ignore the DM */ 1703 /* Monsters always ignore the DM */
1700 if (op->type != PLAYER && QUERY_FLAG (enemy, FLAG_WIZ)) 1704 if (!op->is_player () && QUERY_FLAG (enemy, FLAG_WIZ))
1701 return 0; 1705 return 0;
1702 1706
1703 /* simple check. Should probably put some range checks in here. */ 1707 /* simple check. Should probably put some range checks in here. */
1704 if (can_see_enemy (op, enemy)) 1708 if (can_see_enemy (op, enemy))
1705 return 1; 1709 return 1;
1706 1710
1707 /* The rest of this is for monsters. Players are on their own for 1711 /* The rest of this is for monsters. Players are on their own for
1708 * finding enemies! 1712 * finding enemies!
1709 */ 1713 */
1710 if (op->type == PLAYER) 1714 if (op->is_player ())
1711 return 0; 1715 return 0;
1712 1716
1713 /* Quality invisible? Bah, we wont see them w/o SEE_INVISIBLE 1717 /* Quality invisible? Bah, we wont see them w/o SEE_INVISIBLE
1714 * flag (which was already checked) in can_see_enmy (). Lets get out of here 1718 * flag (which was already checked) in can_see_enemy (). Lets get out of here
1715 */ 1719 */
1716 if (enemy->invisible && (!enemy->contr || (!enemy->contr->tmp_invis && !enemy->contr->hidden))) 1720 if (enemy->invisible && (!enemy->contr || (!enemy->contr->tmp_invis && !enemy->contr->hidden)))
1717 return 0; 1721 return 0;
1718 1722
1723 int radius = MIN_MON_RADIUS;
1724
1719 /* use this for invis also */ 1725 /* use this for invis also */
1720 hide_discovery = op->stats.Int / 5; 1726 int hide_discovery = op->stats.Int / 5;
1721 1727
1722 /* Determine Detection radii */ 1728 /* Determine Detection radii */
1723 if (!enemy->flag [FLAG_HIDDEN]) /* to detect non-hidden (eg dark/invis enemy) */ 1729 if (!enemy->flag [FLAG_HIDDEN]) /* to detect non-hidden (eg dark/invis enemy) */
1724 radius = max (MIN_MON_RADIUS, op->stats.Wis / 5 + 1); 1730 radius = max (MIN_MON_RADIUS, op->stats.Wis / 3 + 1);
1725 else 1731 else
1726 { /* a level/INT/Dex adjustment for hiding */ 1732 { /* a level/INT/Dex adjustment for hiding */
1727 int bonus = op->level / 2 + op->stats.Int / 5; 1733 int bonus = op->level / 2 + op->stats.Int / 5;
1728 1734
1729 if (enemy->is_player ()) 1735 if (enemy->is_player ())
1751 radius /= 2; 1757 radius /= 2;
1752 hide_discovery /= 3; 1758 hide_discovery /= 3;
1753 } 1759 }
1754 1760
1755 /* Radii adjustment for enemy standing in the dark */ 1761 /* Radii adjustment for enemy standing in the dark */
1756 if (op->map->darklevel () > 0 && !stand_in_light (enemy)) 1762 if (!stand_in_light (enemy))
1757 { 1763 {
1758 /* on dark maps body heat can help indicate location with infravision 1764 /* on dark maps body heat can help indicate location with infravision
1759 * undead don't have body heat, so no benefit detecting them. 1765 * undead don't have body heat, so no benefit detecting them.
1760 */ 1766 */
1761 if (QUERY_FLAG (op, FLAG_SEE_IN_DARK) && !is_true_undead (enemy)) 1767 if (QUERY_FLAG (op, FLAG_SEE_IN_DARK) && !is_true_undead (enemy))
1764 radius -= op->map->darklevel () / 2; 1770 radius -= op->map->darklevel () / 2;
1765 1771
1766 /* op next to a monster (and not in complete darkness) 1772 /* op next to a monster (and not in complete darkness)
1767 * the monster should have a chance to see you. 1773 * the monster should have a chance to see you.
1768 */ 1774 */
1769 if (radius < MIN_MON_RADIUS && op->map->darklevel () < 5 && rv->distance <= 1) 1775 if (radius < MIN_MON_RADIUS && op->map->darklevel () < MAX_DARKNESS && rv->distance <= 1)
1770 radius = MIN_MON_RADIUS; 1776 radius = MIN_MON_RADIUS;
1771 } /* if on dark map */ 1777 } /* if on dark map */
1772 1778
1773 /* Lets not worry about monsters that have incredible detection 1779 /* Lets not worry about monsters that have incredible detection
1774 * radii, we only need to worry here about things the player can 1780 * radii, we only need to worry here about things the player can
1822 /* Wasn't detected above, so still hidden */ 1828 /* Wasn't detected above, so still hidden */
1823 return 0; 1829 return 0;
1824} 1830}
1825 1831
1826/* determine if op stands in a lighted square. This is not a very 1832/* determine if op stands in a lighted square. This is not a very
1827 * intellegent algorithm. For one thing, we ignore los here, SO it 1833 * intelligent algorithm. For one thing, we ignore los here, SO it
1828 * is possible for a bright light to illuminate a player on the 1834 * is possible for a bright light to illuminate a player on the
1829 * other side of a wall (!). 1835 * other side of a wall (!).
1830 */ 1836 */
1831int 1837int
1832stand_in_light (object *op) 1838stand_in_light (object *op)
1833{ 1839{
1834 if (op) 1840 if (op)
1835 { 1841 {
1842 if (!op->is_on_map ())
1843 return 0;
1844
1845 if (op->map->darklevel () <= 0)
1846 return 1;
1847
1836 if (op->glow_radius > 0) 1848 if (op->glow_radius > 0)
1837 return 1; 1849 return 1;
1838 1850
1839 if (op->map) 1851 if (op->map)
1840 unordered_mapwalk (op, -MAX_LIGHT_RADIUS, -MAX_LIGHT_RADIUS, MAX_LIGHT_RADIUS, MAX_LIGHT_RADIUS) 1852 unordered_mapwalk (op, -MAX_LIGHT_RADIUS, -MAX_LIGHT_RADIUS, MAX_LIGHT_RADIUS, MAX_LIGHT_RADIUS)
1912 * we care about the enemy maps status, not the looker. 1924 * we care about the enemy maps status, not the looker.
1913 * only relevant for tiled maps, but it is possible that the 1925 * only relevant for tiled maps, but it is possible that the
1914 * enemy is on a bright map and the looker on a dark - in that 1926 * enemy is on a bright map and the looker on a dark - in that
1915 * case, the looker can still see the enemy 1927 * case, the looker can still see the enemy
1916 */ 1928 */
1917 if (enemy->map->darklevel () > 0
1918 && !stand_in_light (enemy) 1929 if (!stand_in_light (enemy)
1919 && (!QUERY_FLAG (looker, FLAG_SEE_IN_DARK) || !is_true_undead (looker) || !QUERY_FLAG (looker, FLAG_XRAYS))) 1930 && (!QUERY_FLAG (looker, FLAG_SEE_IN_DARK) || !is_true_undead (looker) || !QUERY_FLAG (looker, FLAG_XRAYS)))
1920 return 0; 1931 return 0;
1921 1932
1922 return 1; 1933 return 1;
1923} 1934}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines