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.56 by root, Sat Dec 27 08:41:44 2008 UTC vs.
Revision 1.62 by root, Thu Jan 1 16:05:13 2009 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
446 447
447 /* doppleganger code to change monster facing to that of the nearest 448 /* doppleganger code to change monster facing to that of the nearest
448 * player. Hmm. The code is here, but no monster in the current 449 * player. Hmm. The code is here, but no monster in the current
449 * arch set uses it. 450 * arch set uses it.
450 */ 451 */
451 if (op->race && strcmp (op->race, "doppleganger") == 0) 452 if (op->race == shstr_doppleganger)
452 { 453 {
453 op->face = enemy->face; 454 op->face = enemy->face;
454 op->name = enemy->name; 455 op->name = enemy->name;
455 } 456 }
456 457
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 513 // if the enemy is a player, we have los. if los says we
514 // can directly reach the player, we do not deviate. 514 // can directly reach the player, we do not deviate.
515 // for non-players, we never deviate 515 // for non-players, we never deviate
516 if (op->stats.Wis >= 8
516 if (enemy->contr && enemy->contr->darkness_at (op->map, op->x, op->y) == LOS_BLOCKED) 517 && enemy->contr && enemy->contr->darkness_at (op->map, op->x, op->y) == LOS_BLOCKED)
517 { 518 {
518 int sdir = 0; 519 int sdir = 0;
520 uint32_t &smell = op->ms ().smell;
519 521
520 for (int dir = 1; dir <= 8; ++dir) 522 for (int ndir = 1; ndir <= 8; ++ndir)
521 { 523 {
522 mapxy pos (op); pos.move (dir); 524 mapxy pos (op); pos.move (ndir);
525
523 if (pos.normalise ()) 526 if (pos.normalise ())
524 { 527 {
525 mapspace &ms = pos.ms (); 528 mapspace &ms = pos.ms ();
526 529
527 if (ms.smell > op->ms ().smell) 530 if (ms.smell > smell)
528 { 531 {
529 printf ("%s: found smell, following it, apparently (%d, %d)\n",& op->name,op->ms().smell,ms.smell);//D 532 //printf ("%s: found smell, following it, apparently (%d, %d)\n",& op->name,op->ms().smell,ms.smell);//D
530 op->ms ().smell = ms.smell - 1; 533 if (op->stats.Wis >= 10)
534 smell = ms.smell - 1; // smarter: tell others
535
531 sdir = dir; 536 sdir = ndir;
532 537
533 // perturbing the path might let the monster lose track, 538 // perturbing the path might let the monster lose track,
534 // but it will also wide the actual path, spreading information 539 // but it will also widen the actual path, spreading information
535 if (!rndm (20)) 540 if (op->stats.Wis >= 15 && !rndm (20)) // even smarter, deviate and spread?
536 sdir += absdir (1 - rndm (2) * 2); 541 sdir = absdir (sdir + 1 - rndm (2) * 2);
537 } 542 }
538 } 543 }
539 } 544 }
540 545
541 if (sdir) 546 if (sdir)
542 dir = sdir; 547 dir = sdir;
543 else 548 else if (smell)
549 {
544 // no better smell found, so assume the player jumped, and erase this smell 550 // no better smell found, so assume the player jumped, and erase this smell
545 {if (op->ms ().smell) printf ("erasing smell %d\n", op->ms ().smell);//D 551 //printf ("erasing smell %d\n", op->ms ().smell);//D
546 ordered_mapwalk_begin (op, -1, -1, 1, 1) 552 unordered_mapwalk (op, -1, -1, 1, 1)
547 if (m)
548 m->at (nx, ny).smell = 0; 553 m->at (nx, ny).smell = 0;
549 ordered_mapwalk_end
550 }//D 554 }
551 } 555 }
552
553#endif
554 556
555 if (QUERY_FLAG (op, FLAG_SCARED) || QUERY_FLAG (op, FLAG_RUN_AWAY)) 557 if (QUERY_FLAG (op, FLAG_SCARED) || QUERY_FLAG (op, FLAG_RUN_AWAY))
556 dir = absdir (dir + 4); 558 dir = absdir (dir + 4);
557 559
558 if (QUERY_FLAG (op, FLAG_CONFUSED)) 560 if (QUERY_FLAG (op, FLAG_CONFUSED))
1688 * Returns 0 if enemy can not be detected, 1 if it is detected 1690 * Returns 0 if enemy can not be detected, 1 if it is detected
1689 */ 1691 */
1690int 1692int
1691can_detect_enemy (object *op, object *enemy, rv_vector * rv) 1693can_detect_enemy (object *op, object *enemy, rv_vector * rv)
1692{ 1694{
1693 int radius = MIN_MON_RADIUS, hide_discovery;
1694
1695 /* null detection for any of these condtions always */ 1695 /* null detection for any of these condtions always */
1696 if (!op || !enemy || !op->map || !enemy->map) 1696 if (!op || !enemy || !op->map || !enemy->map)
1697 return 0; 1697 return 0;
1698 1698
1699 /* If the monster (op) has no way to get to the enemy, do nothing */ 1699 /* If the monster (op) has no way to get to the enemy, do nothing */
1701 return 0; 1701 return 0;
1702 1702
1703 get_rangevector (op, enemy, rv, 0); 1703 get_rangevector (op, enemy, rv, 0);
1704 1704
1705 /* Monsters always ignore the DM */ 1705 /* Monsters always ignore the DM */
1706 if (op->type != PLAYER && QUERY_FLAG (enemy, FLAG_WIZ)) 1706 if (!op->is_player () && QUERY_FLAG (enemy, FLAG_WIZ))
1707 return 0; 1707 return 0;
1708 1708
1709 /* simple check. Should probably put some range checks in here. */ 1709 /* simple check. Should probably put some range checks in here. */
1710 if (can_see_enemy (op, enemy)) 1710 if (can_see_enemy (op, enemy))
1711 return 1; 1711 return 1;
1712 1712
1713 /* The rest of this is for monsters. Players are on their own for 1713 /* The rest of this is for monsters. Players are on their own for
1714 * finding enemies! 1714 * finding enemies!
1715 */ 1715 */
1716 if (op->type == PLAYER) 1716 if (op->is_player ())
1717 return 0; 1717 return 0;
1718 1718
1719 /* Quality invisible? Bah, we wont see them w/o SEE_INVISIBLE 1719 /* Quality invisible? Bah, we wont see them w/o SEE_INVISIBLE
1720 * flag (which was already checked) in can_see_enmy (). Lets get out of here 1720 * flag (which was already checked) in can_see_enemy (). Lets get out of here
1721 */ 1721 */
1722 if (enemy->invisible && (!enemy->contr || (!enemy->contr->tmp_invis && !enemy->contr->hidden))) 1722 if (enemy->invisible && (!enemy->contr || (!enemy->contr->tmp_invis && !enemy->contr->hidden)))
1723 return 0; 1723 return 0;
1724 1724
1725 int radius = MIN_MON_RADIUS;
1726
1725 /* use this for invis also */ 1727 /* use this for invis also */
1726 hide_discovery = op->stats.Int / 5; 1728 int hide_discovery = op->stats.Int / 5;
1727 1729
1728 /* Determine Detection radii */ 1730 /* Determine Detection radii */
1729 if (!enemy->flag [FLAG_HIDDEN]) /* to detect non-hidden (eg dark/invis enemy) */ 1731 if (!enemy->flag [FLAG_HIDDEN]) /* to detect non-hidden (eg dark/invis enemy) */
1730 radius = max (MIN_MON_RADIUS, op->stats.Wis / 5 + 1); 1732 radius = max (MIN_MON_RADIUS, op->stats.Wis / 3 + 1);
1731 else 1733 else
1732 { /* a level/INT/Dex adjustment for hiding */ 1734 { /* a level/INT/Dex adjustment for hiding */
1733 int bonus = op->level / 2 + op->stats.Int / 5; 1735 int bonus = op->level / 2 + op->stats.Int / 5;
1734 1736
1735 if (enemy->is_player ()) 1737 if (enemy->is_player ())
1757 radius /= 2; 1759 radius /= 2;
1758 hide_discovery /= 3; 1760 hide_discovery /= 3;
1759 } 1761 }
1760 1762
1761 /* Radii adjustment for enemy standing in the dark */ 1763 /* Radii adjustment for enemy standing in the dark */
1762 if (op->map->darklevel () > 0 && !stand_in_light (enemy)) 1764 if (!stand_in_light (enemy))
1763 { 1765 {
1764 /* on dark maps body heat can help indicate location with infravision 1766 /* on dark maps body heat can help indicate location with infravision
1765 * undead don't have body heat, so no benefit detecting them. 1767 * undead don't have body heat, so no benefit detecting them.
1766 */ 1768 */
1767 if (QUERY_FLAG (op, FLAG_SEE_IN_DARK) && !is_true_undead (enemy)) 1769 if (QUERY_FLAG (op, FLAG_SEE_IN_DARK) && !is_true_undead (enemy))
1770 radius -= op->map->darklevel () / 2; 1772 radius -= op->map->darklevel () / 2;
1771 1773
1772 /* op next to a monster (and not in complete darkness) 1774 /* op next to a monster (and not in complete darkness)
1773 * the monster should have a chance to see you. 1775 * the monster should have a chance to see you.
1774 */ 1776 */
1775 if (radius < MIN_MON_RADIUS && op->map->darklevel () < 5 && rv->distance <= 1) 1777 if (radius < MIN_MON_RADIUS && op->map->darklevel () < MAX_DARKNESS && rv->distance <= 1)
1776 radius = MIN_MON_RADIUS; 1778 radius = MIN_MON_RADIUS;
1777 } /* if on dark map */ 1779 } /* if on dark map */
1778 1780
1779 /* Lets not worry about monsters that have incredible detection 1781 /* Lets not worry about monsters that have incredible detection
1780 * radii, we only need to worry here about things the player can 1782 * radii, we only need to worry here about things the player can
1828 /* Wasn't detected above, so still hidden */ 1830 /* Wasn't detected above, so still hidden */
1829 return 0; 1831 return 0;
1830} 1832}
1831 1833
1832/* determine if op stands in a lighted square. This is not a very 1834/* determine if op stands in a lighted square. This is not a very
1833 * intellegent algorithm. For one thing, we ignore los here, SO it 1835 * intelligent algorithm. For one thing, we ignore los here, SO it
1834 * is possible for a bright light to illuminate a player on the 1836 * is possible for a bright light to illuminate a player on the
1835 * other side of a wall (!). 1837 * other side of a wall (!).
1836 */ 1838 */
1837int 1839int
1838stand_in_light (object *op) 1840stand_in_light (object *op)
1839{ 1841{
1840 if (op) 1842 if (op)
1841 { 1843 {
1844 if (!op->is_on_map ())
1845 return 0;
1846
1847 if (op->map->darklevel () <= 0)
1848 return 1;
1849
1842 if (op->glow_radius > 0) 1850 if (op->glow_radius > 0)
1843 return 1; 1851 return 1;
1844 1852
1845 if (op->map) 1853 if (op->map)
1846 unordered_mapwalk (op, -MAX_LIGHT_RADIUS, -MAX_LIGHT_RADIUS, MAX_LIGHT_RADIUS, MAX_LIGHT_RADIUS) 1854 unordered_mapwalk (op, -MAX_LIGHT_RADIUS, -MAX_LIGHT_RADIUS, MAX_LIGHT_RADIUS, MAX_LIGHT_RADIUS)
1918 * we care about the enemy maps status, not the looker. 1926 * we care about the enemy maps status, not the looker.
1919 * only relevant for tiled maps, but it is possible that the 1927 * only relevant for tiled maps, but it is possible that the
1920 * enemy is on a bright map and the looker on a dark - in that 1928 * enemy is on a bright map and the looker on a dark - in that
1921 * case, the looker can still see the enemy 1929 * case, the looker can still see the enemy
1922 */ 1930 */
1923 if (enemy->map->darklevel () > 0
1924 && !stand_in_light (enemy) 1931 if (!stand_in_light (enemy)
1925 && (!QUERY_FLAG (looker, FLAG_SEE_IN_DARK) || !is_true_undead (looker) || !QUERY_FLAG (looker, FLAG_XRAYS))) 1932 && (!QUERY_FLAG (looker, FLAG_SEE_IN_DARK) || !is_true_undead (looker) || !QUERY_FLAG (looker, FLAG_XRAYS)))
1926 return 0; 1933 return 0;
1927 1934
1928 return 1; 1935 return 1;
1929} 1936}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines