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.68 by root, Fri Sep 25 19:09:20 2009 UTC

46 npc->enemy = NULL; 46 npc->enemy = NULL;
47 else if (npc->enemy == NULL) 47 else if (npc->enemy == NULL)
48 npc->enemy = npc->owner->enemy; 48 npc->enemy = npc->owner->enemy;
49 } 49 }
50 50
51 /* periodically, a monster mayu change its target. Also, if the object 51 /* periodically, a monster may change its target. Also, if the object
52 * has been destroyed, etc, clear the enemy. 52 * has been destroyed, etc, clear the enemy.
53 * TODO: this should be changed, because it invokes to attack forced or 53 * TODO: this should be changed, because it invokes to attack forced or
54 * attacked monsters to leave the attacker alone, before it is destroyed 54 * attacked monsters to leave the attacker alone, before it is destroyed
55 */ 55 */
56 /* i had removed the random target leave, this invokes problems with friendly 56 /* I had removed the random target leave, this invokes problems with friendly
57 * objects, getting attacked and defending herself - they don't try to attack 57 * objects, getting attacked and defending herself - they don't try to attack
58 * again then but perhaps get attack on and on 58 * again then but perhaps get attack on and on
59 * If we include a aggravated flag in , we can handle evil vs evil and good vs good 59 * If we include a aggravated flag in , we can handle evil vs evil and good vs good
60 * too. */ 60 * too. */
61 61
65 * the grouping checks are. Code is the same. 65 * the grouping checks are. Code is the same.
66 */ 66 */
67 if (QUERY_FLAG (npc->enemy, FLAG_REMOVED) || 67 if (QUERY_FLAG (npc->enemy, FLAG_REMOVED) ||
68 QUERY_FLAG (npc->enemy, FLAG_FREED) || 68 QUERY_FLAG (npc->enemy, FLAG_FREED) ||
69 !on_same_map (npc, npc->enemy) || npc == npc->enemy || QUERY_FLAG (npc, FLAG_NEUTRAL) || QUERY_FLAG (npc->enemy, FLAG_NEUTRAL)) 69 !on_same_map (npc, npc->enemy) || npc == npc->enemy || QUERY_FLAG (npc, FLAG_NEUTRAL) || QUERY_FLAG (npc->enemy, FLAG_NEUTRAL))
70 npc->enemy = NULL; 70 npc->enemy = 0;
71 71
72 else if (QUERY_FLAG (npc, FLAG_FRIENDLY) && ((QUERY_FLAG (npc->enemy, FLAG_FRIENDLY) 72 else if (QUERY_FLAG (npc, FLAG_FRIENDLY) && ((QUERY_FLAG (npc->enemy, FLAG_FRIENDLY)
73 && !(should_arena_attack (npc, npc->owner, npc->enemy))) 73 && !(should_arena_attack (npc, npc->owner, npc->enemy)))
74 || ((npc->enemy->type == PLAYER) && !(should_arena_attack (npc, npc->owner, npc->enemy))) 74 || ((npc->enemy->type == PLAYER) && !(should_arena_attack (npc, npc->owner, npc->enemy)))
75 || npc->enemy == npc->owner)) 75 || npc->enemy == npc->owner))
76 npc->enemy = NULL; 76 npc->enemy = 0;
77 77
78 78
79 else if (!QUERY_FLAG (npc, FLAG_FRIENDLY) && (!QUERY_FLAG (npc->enemy, FLAG_FRIENDLY) && npc->enemy->type != PLAYER)) 79 else if (!QUERY_FLAG (npc, FLAG_FRIENDLY) && (!QUERY_FLAG (npc->enemy, FLAG_FRIENDLY) && npc->enemy->type != PLAYER))
80 npc->enemy = NULL; 80 npc->enemy = 0;
81 81
82 /* I've noticed that pets could sometimes get an arrow as the 82 /* I've noticed that pets could sometimes get an arrow as the
83 * target enemy - this code below makes sure the enemy is something 83 * target enemy - this code below makes sure the enemy is something
84 * that should be attacked. My guess is that the arrow hits 84 * that should be attacked. My guess is that the arrow hits
85 * the creature/owner, and so the creature then takes that 85 * the creature/owner, and so the creature then takes that
87 */ 87 */
88 else if (!QUERY_FLAG (npc->enemy, FLAG_MONSTER) 88 else if (!QUERY_FLAG (npc->enemy, FLAG_MONSTER)
89 && !QUERY_FLAG (npc->enemy, FLAG_GENERATOR) 89 && !QUERY_FLAG (npc->enemy, FLAG_GENERATOR)
90 && npc->enemy->type != PLAYER 90 && npc->enemy->type != PLAYER
91 && npc->enemy->type != GOLEM) 91 && npc->enemy->type != GOLEM)
92 npc->enemy = NULL; 92 npc->enemy = 0;
93
94 } 93 }
95 94
96 return can_detect_enemy (npc, npc->enemy, rv) ? npc->enemy : NULL; 95 return can_detect_enemy (npc, npc->enemy, rv) ? npc->enemy : 0;
97} 96}
98 97
99/* Returns the nearest living creature (monster or generator). 98/* Returns the nearest living creature (monster or generator).
100 * Modified to deal with tiled maps properly. 99 * Modified to deal with tiled maps properly.
101 * Also fixed logic so that monsters in the lower directions were more 100 * Also fixed logic so that monsters in the lower directions were more
236{ 235{
237 /* Trim work - if no enemy, no need to do anything below */ 236 /* Trim work - if no enemy, no need to do anything below */
238 if (!enemy) 237 if (!enemy)
239 return 0; 238 return 0;
240 239
240 if (!op->flag [FLAG_SLEEP])
241 return 1;
242
241 int radius = max (op->stats.Wis, MIN_MON_RADIUS); 243 int radius = max (op->stats.Wis, MIN_MON_RADIUS);
242 244
243 if (op->flag [FLAG_BLIND]) 245 if (op->flag [FLAG_BLIND])
244 /* blinded monsters can only find nearby objects to attack */ 246 /* blinded monsters can only find nearby objects to attack */
245 radius = MIN_MON_RADIUS; 247 radius = MIN_MON_RADIUS;
251 * and has an enemy. If the enemy has no carried light (or isnt 253 * and has an enemy. If the enemy has no carried light (or isnt
252 * glowing!) then the monster has trouble finding the enemy. 254 * glowing!) then the monster has trouble finding the enemy.
253 * Remember we already checked to see if the monster can see in 255 * Remember we already checked to see if the monster can see in
254 * the dark. */ 256 * the dark. */
255 radius = min (radius, MIN_MON_RADIUS + MAX_DARKNESS - op->map->darklevel ()); 257 radius = min (radius, MIN_MON_RADIUS + MAX_DARKNESS - op->map->darklevel ());
256 else if (!op->flag [FLAG_SLEEP])
257 return 1;
258 258
259 if (enemy->flag [FLAG_STEALTH]) 259 if (enemy->flag [FLAG_STEALTH])
260 radius = radius / 2 + 1; 260 radius = radius / 2 + 1;
261 261
262 /* enemy should already be on this map, so don't really need to check 262 /* enemy should already be on this map, so don't really need to check
389 { 389 {
390 if (op->attack_movement & HI4) 390 if (op->attack_movement & HI4)
391 { 391 {
392 switch (op->attack_movement & HI4) 392 switch (op->attack_movement & HI4)
393 { 393 {
394 case (PETMOVE): 394 case PETMOVE:
395 pet_move (op); 395 pet_move (op);
396 break; 396 break;
397 397
398 case (CIRCLE1): 398 case CIRCLE1:
399 circ1_move (op); 399 circ1_move (op);
400 break; 400 break;
401 401
402 case (CIRCLE2): 402 case CIRCLE2:
403 circ2_move (op); 403 circ2_move (op);
404 break; 404 break;
405 405
406 case (PACEV): 406 case PACEV:
407 pace_movev (op); 407 pace_movev (op);
408 break; 408 break;
409 409
410 case (PACEH): 410 case PACEH:
411 pace_moveh (op); 411 pace_moveh (op);
412 break; 412 break;
413 413
414 case (PACEV2): 414 case PACEV2:
415 pace2_movev (op); 415 pace2_movev (op);
416 break; 416 break;
417 417
418 case (PACEH2): 418 case PACEH2:
419 pace2_moveh (op); 419 pace2_moveh (op);
420 break; 420 break;
421 421
422 case (RANDO): 422 case RANDO:
423 rand_move (op); 423 rand_move (op);
424 break; 424 break;
425 425
426 case (RANDO2): 426 case RANDO2:
427 move_randomly (op); 427 move_randomly (op);
428 break; 428 break;
429 } 429 }
430 430
431 return 0; 431 return 0;
446 446
447 /* doppleganger code to change monster facing to that of the nearest 447 /* doppleganger code to change monster facing to that of the nearest
448 * player. Hmm. The code is here, but no monster in the current 448 * player. Hmm. The code is here, but no monster in the current
449 * arch set uses it. 449 * arch set uses it.
450 */ 450 */
451 if (op->race && strcmp (op->race, "doppleganger") == 0) 451 if (op->race == shstr_doppleganger)
452 { 452 {
453 op->face = enemy->face; 453 op->face = enemy->face;
454 op->name = enemy->name; 454 op->name = enemy->name;
455 } 455 }
456 456
507 } /* If not scared */ 507 } /* If not scared */
508 508
509 part = rv.part; 509 part = rv.part;
510 dir = rv.direction; 510 dir = rv.direction;
511 511
512#if DEVEL 512 // if the enemy is a player, we have los. if los says we
513 // can directly reach the player, we do not deviate.
514 // for non-players, we never deviate
515 if (op->stats.Wis >= 8
516 && enemy->contr && enemy->contr->darkness_at (op->map, op->x, op->y) == LOS_BLOCKED)
517 {
513 int sdir = 0; 518 int sdir = 0;
519 uint32_t &smell = op->ms ().smell;
514 520
515 for (int dir = 1; dir <= 8; ++dir) 521 for (int ndir = 1; ndir <= 8; ++ndir)
516 { 522 {
517 mapxy pos (op); pos.move (dir); 523 mapxy pos (op); pos.move (ndir);
524
518 if (pos.normalise ()) 525 if (pos.normalise ())
519 {
520 mapspace &ms = pos.ms ();
521
522 if (ms.smell > op->ms ().smell)
523 { 526 {
527 mapspace &ms = pos.ms ();
528
529 if (ms.smell > smell)
530 {
524 printf ("%s: found smell, following it, apparently (%d, %d)\n",& op->name,op->ms().smell,ms.smell);//D 531 //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; 532 if (op->stats.Wis >= 10)
533 smell = ms.smell - 1; // smarter: tell others
534
526 sdir = dir; 535 sdir = ndir;
527 536
528 // perturbing the path might let the monster lose track, 537 // perturbing the path might let the monster lose track,
529 // but it will also wide the actual path, spreading information 538 // but it will also widen the actual path, spreading information
530 if (!rndm (20)) 539 if (op->stats.Wis >= 15 && !rndm (20)) // even smarter, deviate and spread?
531 sdir += absdir (1 - rndm (2) * 2); 540 sdir = absdir (sdir + 1 - rndm (2) * 2);
541 }
532 } 542 }
533 } 543 }
534 }
535 544
536 if (sdir) 545 if (sdir)
537 dir = sdir; 546 dir = sdir;
538 else 547 else if (smell)
548 {
539 // no better smell found, so assume the player jumped, and erase this smell 549 // 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 550 //printf ("erasing smell %d\n", op->ms ().smell);//D
541 ordered_mapwalk_begin (op, -1, -1, 1, 1) 551 unordered_mapwalk (op, -1, -1, 1, 1)
542 if (m)
543 m->at (nx, ny).smell = 0; 552 m->at (nx, ny).smell = 0;
544 ordered_mapwalk_end 553 }
545 }//D 554 }
546
547#endif
548 555
549 if (QUERY_FLAG (op, FLAG_SCARED) || QUERY_FLAG (op, FLAG_RUN_AWAY)) 556 if (QUERY_FLAG (op, FLAG_SCARED) || QUERY_FLAG (op, FLAG_RUN_AWAY))
550 dir = absdir (dir + 4); 557 dir = absdir (dir + 4);
551 558
552 if (QUERY_FLAG (op, FLAG_CONFUSED)) 559 if (QUERY_FLAG (op, FLAG_CONFUSED))
698 return 1; 705 return 1;
699 706
700 /* check all the parts of ob2 - just because we can't get to 707 /* check all the parts of ob2 - just because we can't get to
701 * its head doesn't mean we don't want to pound its feet 708 * its head doesn't mean we don't want to pound its feet
702 */ 709 */
703 for (more = ob2->more; more != NULL; more = more->more) 710 for (more = ob2->more; more; more = more->more)
704 { 711 {
705 get_rangevector (ob1, more, &rv1, 0); 712 get_rangevector (ob1, more, &rv1, 0);
706 if (abs (rv1.distance_x) < 2 && abs (rv1.distance_y) < 2) 713 if (abs (rv1.distance_x) < 2 && abs (rv1.distance_y) < 2)
707 return 1; 714 return 1;
708 } 715 }
1189 flag = 1; 1196 flag = 1;
1190 1197
1191 else 1198 else
1192 switch (item->type) 1199 switch (item->type)
1193 { 1200 {
1194 case MONEY: 1201 case MONEY:
1195 case GEM: 1202 case GEM:
1196 flag = monster->pick_up & 2; 1203 flag = monster->pick_up & 2;
1197 break; 1204 break;
1198 1205
1199 case FOOD: 1206 case FOOD:
1200 flag = monster->pick_up & 4; 1207 flag = monster->pick_up & 4;
1201 break; 1208 break;
1202 1209
1203 case WEAPON: 1210 case WEAPON:
1204 flag = (monster->pick_up & 8) || QUERY_FLAG (monster, FLAG_USE_WEAPON); 1211 flag = (monster->pick_up & 8) || QUERY_FLAG (monster, FLAG_USE_WEAPON);
1205 break; 1212 break;
1206 1213
1207 case ARMOUR: 1214 case ARMOUR:
1208 case SHIELD: 1215 case SHIELD:
1209 case HELMET: 1216 case HELMET:
1210 case BOOTS: 1217 case BOOTS:
1211 case GLOVES: 1218 case GLOVES:
1212 case GIRDLE: 1219 case GIRDLE:
1213 flag = (monster->pick_up & 16) || QUERY_FLAG (monster, FLAG_USE_ARMOUR); 1220 flag = (monster->pick_up & 16) || QUERY_FLAG (monster, FLAG_USE_ARMOUR);
1214 break; 1221 break;
1215 1222
1216 case SKILL: 1223 case SKILL:
1217 flag = QUERY_FLAG (monster, FLAG_CAN_USE_SKILL); 1224 flag = QUERY_FLAG (monster, FLAG_CAN_USE_SKILL);
1218 break; 1225 break;
1219 1226
1220 case RING: 1227 case RING:
1221 flag = QUERY_FLAG (monster, FLAG_USE_RING); 1228 flag = QUERY_FLAG (monster, FLAG_USE_RING);
1222 break; 1229 break;
1223 1230
1224 case WAND: 1231 case WAND:
1225 case HORN: 1232 case HORN:
1226 case ROD: 1233 case ROD:
1227 flag = QUERY_FLAG (monster, FLAG_USE_RANGE); 1234 flag = QUERY_FLAG (monster, FLAG_USE_RANGE);
1228 break; 1235 break;
1229 1236
1230 case SPELLBOOK: 1237 case SPELLBOOK:
1231 flag = monster->arch && QUERY_FLAG (monster->arch, FLAG_CAST_SPELL); 1238 flag = monster->arch && QUERY_FLAG (monster->arch, FLAG_CAST_SPELL);
1232 break; 1239 break;
1233 1240
1234 case SCROLL: 1241 case SCROLL:
1235 flag = QUERY_FLAG (monster, FLAG_USE_SCROLL); 1242 flag = QUERY_FLAG (monster, FLAG_USE_SCROLL);
1236 break; 1243 break;
1237 1244
1238 case BOW: 1245 case BOW:
1239 case ARROW: 1246 case ARROW:
1240 flag = QUERY_FLAG (monster, FLAG_USE_BOW); 1247 flag = QUERY_FLAG (monster, FLAG_USE_BOW);
1241 break; 1248 break;
1242 } 1249 }
1243 1250
1244 /* Simplistic check - if the monster has a location to equip it, he will 1251 /* Simplistic check - if the monster has a location to equip it, he will
1245 * pick it up. Note that this doesn't handle cases where an item may 1252 * pick it up. Note that this doesn't handle cases where an item may
1246 * use several locations. 1253 * use several locations.
1412} 1419}
1413 1420
1414void 1421void
1415npc_call_help (object *op) 1422npc_call_help (object *op)
1416{ 1423{
1417 int x, y, mflags; 1424 unordered_mapwalk (op, -7, -7, 7, 7)
1418 object *npc;
1419 sint16 sx, sy;
1420 maptile *m;
1421
1422 for (x = -3; x < 4; x++)
1423 for (y = -3; y < 4; y++)
1424 { 1425 {
1425 m = op->map; 1426 mapspace &ms = m->at (nx, ny);
1426 sx = op->x + x; 1427
1427 sy = op->y + y;
1428 mflags = get_map_flags (m, &m, sx, sy, &sx, &sy);
1429 /* If nothing alive on this space, no need to search the space. */ 1428 /* If nothing alive on this space, no need to search the space. */
1430 if ((mflags & P_OUT_OF_MAP) || !(mflags & P_IS_ALIVE)) 1429 if (!(ms.flags () & P_IS_ALIVE))
1431 continue; 1430 continue;
1432 1431
1433 for (npc = GET_MAP_OB (m, sx, sy); npc != NULL; npc = npc->above) 1432 for (object *npc = ms.bot; npc; npc = npc->above)
1434 if (QUERY_FLAG (npc, FLAG_ALIVE) && QUERY_FLAG (npc, FLAG_UNAGGRESSIVE)) 1433 if (QUERY_FLAG (npc, FLAG_ALIVE) && QUERY_FLAG (npc, FLAG_UNAGGRESSIVE))
1435 npc->enemy = op->enemy; 1434 npc->enemy = op->enemy;
1436 } 1435 }
1437} 1436}
1438 1437
1439int 1438int
1440dist_att (int dir, object *ob, object *enemy, object *part, rv_vector * rv) 1439dist_att (int dir, object *ob, object *enemy, object *part, rv_vector *rv)
1441{ 1440{
1442 if (can_hit (part, enemy, rv)) 1441 if (can_hit (part, enemy, rv))
1443 return dir; 1442 return dir;
1444 1443
1445 if (rv->distance < 10) 1444 if (rv->distance < 10)
1449 1448
1450 return 0; 1449 return 0;
1451} 1450}
1452 1451
1453int 1452int
1454run_att (int dir, object *ob, object *enemy, object *part, rv_vector * rv) 1453run_att (int dir, object *ob, object *enemy, object *part, rv_vector *rv)
1455{ 1454{
1456 if ((can_hit (part, enemy, rv) && ob->move_status < 20) || ob->move_status < 20) 1455 if (can_hit (part, enemy, rv))
1457 {
1458 ob->move_status++;
1459 return (dir); 1456 return dir;
1460 } 1457 else
1461 else if (ob->move_status > 20)
1462 ob->move_status = 0;
1463
1464 return absdir (dir + 4); 1458 return absdir (dir + 4);
1465} 1459}
1466 1460
1467int 1461int
1468hitrun_att (int dir, object *ob, object *enemy) 1462hitrun_att (int dir, object *ob, object *enemy)
1469{ 1463{
1478} 1472}
1479 1473
1480int 1474int
1481wait_att (int dir, object *ob, object *enemy, object *part, rv_vector * rv) 1475wait_att (int dir, object *ob, object *enemy, object *part, rv_vector * rv)
1482{ 1476{
1483
1484 int inrange = can_hit (part, enemy, rv); 1477 int inrange = can_hit (part, enemy, rv);
1485 1478
1486 if (ob->move_status || inrange) 1479 if (ob->move_status || inrange)
1487 ob->move_status++; 1480 ob->move_status++;
1488 1481
1498} 1491}
1499 1492
1500int 1493int
1501disthit_att (int dir, object *ob, object *enemy, object *part, rv_vector * rv) 1494disthit_att (int dir, object *ob, object *enemy, object *part, rv_vector * rv)
1502{ 1495{
1503
1504 /* The logic below here looked plain wrong before. Basically, what should 1496 /* The logic below here looked plain wrong before. Basically, what should
1505 * happen is that if the creatures hp percentage falls below run_away, 1497 * happen is that if the creatures hp percentage falls below run_away,
1506 * the creature should run away (dir+4) 1498 * the creature should run away (dir+4)
1507 * I think its wrong for a creature to have a zero maxhp value, but 1499 * I think its wrong for a creature to have a zero maxhp value, but
1508 * at least one map has this set, and whatever the map contains, the 1500 * at least one map has this set, and whatever the map contains, the
1509 * server should try to be resilant enough to avoid the problem 1501 * server should try to be resilant enough to avoid the problem
1510 */ 1502 */
1511 if (ob->stats.maxhp && (ob->stats.hp * 100) / ob->stats.maxhp < ob->run_away) 1503 if (ob->stats.hp * 100 < ob->stats.maxhp * ob->run_away)
1512 return absdir (dir + 4); 1504 return absdir (dir + 4);
1513 1505
1514 return dist_att (dir, ob, enemy, part, rv); 1506 return dist_att (dir, ob, enemy, part, rv);
1515} 1507}
1516 1508
1682 * Returns 0 if enemy can not be detected, 1 if it is detected 1674 * Returns 0 if enemy can not be detected, 1 if it is detected
1683 */ 1675 */
1684int 1676int
1685can_detect_enemy (object *op, object *enemy, rv_vector * rv) 1677can_detect_enemy (object *op, object *enemy, rv_vector * rv)
1686{ 1678{
1687 int radius = MIN_MON_RADIUS, hide_discovery;
1688
1689 /* null detection for any of these condtions always */ 1679 /* null detection for any of these condtions always */
1690 if (!op || !enemy || !op->map || !enemy->map) 1680 if (!op || !enemy || !op->map || !enemy->map)
1691 return 0; 1681 return 0;
1692 1682
1693 /* If the monster (op) has no way to get to the enemy, do nothing */ 1683 /* If the monster (op) has no way to get to the enemy, do nothing */
1695 return 0; 1685 return 0;
1696 1686
1697 get_rangevector (op, enemy, rv, 0); 1687 get_rangevector (op, enemy, rv, 0);
1698 1688
1699 /* Monsters always ignore the DM */ 1689 /* Monsters always ignore the DM */
1700 if (op->type != PLAYER && QUERY_FLAG (enemy, FLAG_WIZ)) 1690 if (!op->is_player () && QUERY_FLAG (enemy, FLAG_WIZ))
1701 return 0; 1691 return 0;
1702 1692
1703 /* simple check. Should probably put some range checks in here. */ 1693 /* simple check. Should probably put some range checks in here. */
1704 if (can_see_enemy (op, enemy)) 1694 if (can_see_enemy (op, enemy))
1705 return 1; 1695 return 1;
1706 1696
1707 /* The rest of this is for monsters. Players are on their own for 1697 /* The rest of this is for monsters. Players are on their own for
1708 * finding enemies! 1698 * finding enemies!
1709 */ 1699 */
1710 if (op->type == PLAYER) 1700 if (op->is_player ())
1711 return 0; 1701 return 0;
1712 1702
1713 /* Quality invisible? Bah, we wont see them w/o SEE_INVISIBLE 1703 /* 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 1704 * flag (which was already checked) in can_see_enemy (). Lets get out of here
1715 */ 1705 */
1716 if (enemy->invisible && (!enemy->contr || (!enemy->contr->tmp_invis && !enemy->contr->hidden))) 1706 if (enemy->invisible && (!enemy->contr || (!enemy->contr->tmp_invis && !enemy->contr->hidden)))
1717 return 0; 1707 return 0;
1718 1708
1709 int radius = MIN_MON_RADIUS;
1710
1719 /* use this for invis also */ 1711 /* use this for invis also */
1720 hide_discovery = op->stats.Int / 5; 1712 int hide_discovery = op->stats.Int / 5;
1721 1713
1722 /* Determine Detection radii */ 1714 /* Determine Detection radii */
1723 if (!enemy->flag [FLAG_HIDDEN]) /* to detect non-hidden (eg dark/invis enemy) */ 1715 if (!enemy->flag [FLAG_HIDDEN]) /* to detect non-hidden (eg dark/invis enemy) */
1724 radius = max (MIN_MON_RADIUS, op->stats.Wis / 5 + 1); 1716 radius = max (MIN_MON_RADIUS, op->stats.Wis / 3 + 1);
1725 else 1717 else
1726 { /* a level/INT/Dex adjustment for hiding */ 1718 { /* a level/INT/Dex adjustment for hiding */
1727 int bonus = op->level / 2 + op->stats.Int / 5; 1719 int bonus = op->level / 2 + op->stats.Int / 5;
1728 1720
1729 if (enemy->is_player ()) 1721 if (enemy->is_player ())
1751 radius /= 2; 1743 radius /= 2;
1752 hide_discovery /= 3; 1744 hide_discovery /= 3;
1753 } 1745 }
1754 1746
1755 /* Radii adjustment for enemy standing in the dark */ 1747 /* Radii adjustment for enemy standing in the dark */
1756 if (op->map->darklevel () > 0 && !stand_in_light (enemy)) 1748 if (!stand_in_light (enemy))
1757 { 1749 {
1758 /* on dark maps body heat can help indicate location with infravision 1750 /* on dark maps body heat can help indicate location with infravision
1759 * undead don't have body heat, so no benefit detecting them. 1751 * undead don't have body heat, so no benefit detecting them.
1760 */ 1752 */
1761 if (QUERY_FLAG (op, FLAG_SEE_IN_DARK) && !is_true_undead (enemy)) 1753 if (QUERY_FLAG (op, FLAG_SEE_IN_DARK) && !is_true_undead (enemy))
1764 radius -= op->map->darklevel () / 2; 1756 radius -= op->map->darklevel () / 2;
1765 1757
1766 /* op next to a monster (and not in complete darkness) 1758 /* op next to a monster (and not in complete darkness)
1767 * the monster should have a chance to see you. 1759 * the monster should have a chance to see you.
1768 */ 1760 */
1769 if (radius < MIN_MON_RADIUS && op->map->darklevel () < 5 && rv->distance <= 1) 1761 if (radius < MIN_MON_RADIUS && op->map->darklevel () < MAX_DARKNESS && rv->distance <= 1)
1770 radius = MIN_MON_RADIUS; 1762 radius = MIN_MON_RADIUS;
1771 } /* if on dark map */ 1763 } /* if on dark map */
1772 1764
1773 /* Lets not worry about monsters that have incredible detection 1765 /* Lets not worry about monsters that have incredible detection
1774 * radii, we only need to worry here about things the player can 1766 * radii, we only need to worry here about things the player can
1822 /* Wasn't detected above, so still hidden */ 1814 /* Wasn't detected above, so still hidden */
1823 return 0; 1815 return 0;
1824} 1816}
1825 1817
1826/* determine if op stands in a lighted square. This is not a very 1818/* 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 1819 * intelligent algorithm. For one thing, we ignore los here, SO it
1828 * is possible for a bright light to illuminate a player on the 1820 * is possible for a bright light to illuminate a player on the
1829 * other side of a wall (!). 1821 * other side of a wall (!).
1830 */ 1822 */
1831int 1823int
1832stand_in_light (object *op) 1824stand_in_light (object *op)
1833{ 1825{
1834 if (op) 1826 if (op)
1835 { 1827 {
1828 if (!op->is_on_map ())
1829 return 0;
1830
1831 if (op->map->darklevel () <= 0)
1832 return 1;
1833
1836 if (op->glow_radius > 0) 1834 if (op->glow_radius > 0)
1837 return 1; 1835 return 1;
1838 1836
1839 if (op->map) 1837 if (op->map)
1840 unordered_mapwalk (op, -MAX_LIGHT_RADIUS, -MAX_LIGHT_RADIUS, MAX_LIGHT_RADIUS, MAX_LIGHT_RADIUS) 1838 unordered_mapwalk (op, -MAX_LIGHT_RADIUS, -MAX_LIGHT_RADIUS, MAX_LIGHT_RADIUS, MAX_LIGHT_RADIUS)
1878 { 1876 {
1879 /* HIDDEN ENEMY. by definition, you can't see hidden stuff! 1877 /* HIDDEN ENEMY. by definition, you can't see hidden stuff!
1880 * However,if you carry any source of light, then the hidden 1878 * However,if you carry any source of light, then the hidden
1881 * creature is seeable (and stupid) */ 1879 * creature is seeable (and stupid) */
1882 1880
1883 if (has_carried_lights (enemy)) 1881 if (enemy->has_carried_lights ())
1884 { 1882 {
1885 if (enemy->flag [FLAG_HIDDEN]) 1883 if (enemy->flag [FLAG_HIDDEN])
1886 { 1884 {
1887 make_visible (enemy); 1885 make_visible (enemy);
1888 new_draw_info (NDI_UNIQUE, 0, enemy, "Your light reveals your hiding spot!"); 1886 new_draw_info (NDI_UNIQUE, 0, enemy, "Your light reveals your hiding spot!");
1912 * we care about the enemy maps status, not the looker. 1910 * we care about the enemy maps status, not the looker.
1913 * only relevant for tiled maps, but it is possible that the 1911 * 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 1912 * enemy is on a bright map and the looker on a dark - in that
1915 * case, the looker can still see the enemy 1913 * case, the looker can still see the enemy
1916 */ 1914 */
1917 if (enemy->map->darklevel () > 0
1918 && !stand_in_light (enemy) 1915 if (!stand_in_light (enemy)
1919 && (!QUERY_FLAG (looker, FLAG_SEE_IN_DARK) || !is_true_undead (looker) || !QUERY_FLAG (looker, FLAG_XRAYS))) 1916 && (!QUERY_FLAG (looker, FLAG_SEE_IN_DARK) || !is_true_undead (looker) || !QUERY_FLAG (looker, FLAG_XRAYS)))
1920 return 0; 1917 return 0;
1921 1918
1922 return 1; 1919 return 1;
1923} 1920}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines