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.48 by pippijn, Tue Dec 23 18:52:58 2008 UTC vs.
Revision 1.65 by root, Fri Sep 25 18:44:58 2009 UTC

35 * set to sane values. 35 * set to sane values.
36 */ 36 */
37object * 37object *
38check_enemy (object *npc, rv_vector * rv) 38check_enemy (object *npc, rv_vector * rv)
39{ 39{
40
41 /* if this is pet, let him attack the same enemy as his owner 40 /* if this is pet, let him attack the same enemy as his owner
42 * TODO: when there is no ower enemy, try to find a target, 41 * TODO: when there is no ower enemy, try to find a target,
43 * which CAN attack the owner. */ 42 * which CAN attack the owner. */
44 if ((npc->attack_movement & HI4) == PETMOVE) 43 if ((npc->attack_movement & HI4) == PETMOVE)
45 { 44 {
231 * Currently, this is only called from move_monster, and 230 * Currently, this is only called from move_monster, and
232 * if enemy is set, then so should be rv. 231 * if enemy is set, then so should be rv.
233 * returns 1 if the monster should wake up, 0 otherwise. 232 * returns 1 if the monster should wake up, 0 otherwise.
234 */ 233 */
235int 234int
236check_wakeup (object *op, object *enemy, rv_vector * rv) 235check_wakeup (object *op, object *enemy, rv_vector *rv)
237{ 236{
238 int radius = op->stats.Wis > MIN_MON_RADIUS ? op->stats.Wis : MIN_MON_RADIUS;
239
240 /* Trim work - if no enemy, no need to do anything below */ 237 /* Trim work - if no enemy, no need to do anything below */
241 if (!enemy) 238 if (!enemy)
242 return 0; 239 return 0;
243 240
241 if (!op->flag [FLAG_SLEEP])
242 return 1;
243
244 int radius = max (op->stats.Wis, MIN_MON_RADIUS);
245
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 if (QUERY_FLAG (op, FLAG_BLIND))
246 radius = MIN_MON_RADIUS; 248 radius = MIN_MON_RADIUS;
247 249 else if (op->map
250 && !enemy->invisible
251 && !stand_in_light (enemy)
252 && (!op->flag[FLAG_SEE_IN_DARK] || !op->flag [FLAG_SEE_INVISIBLE]))
248 /* This covers the situation where the monster is in the dark 253 /* This covers the situation where the monster is in the dark
249 * 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
250 * glowing!) then the monster has trouble finding the enemy. 255 * glowing!) then the monster has trouble finding the enemy.
251 * 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
252 * the dark. */ 257 * the dark. */
258 radius = min (radius, MIN_MON_RADIUS + MAX_DARKNESS - op->map->darklevel ());
253 259
254 else if (op->map && op->map->darkness > 0 && enemy && !enemy->invisible && 260 if (enemy->flag [FLAG_STEALTH])
255 !stand_in_light (enemy) && (!QUERY_FLAG (op, FLAG_SEE_IN_DARK) || !QUERY_FLAG (op, FLAG_SEE_INVISIBLE))) 261 radius = radius / 2 + 1;
256 {
257 int dark = radius / (op->map->darkness);
258
259 radius = (dark > MIN_MON_RADIUS) ? (dark + 1) : MIN_MON_RADIUS;
260 }
261 else if (!QUERY_FLAG (op, FLAG_SLEEP))
262 return 1;
263 262
264 /* 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
265 * for that. 264 * for that.
266 */ 265 */
267 if (rv->distance < (unsigned int) (QUERY_FLAG (enemy, FLAG_STEALTH) ? (radius / 2) + 1 : radius)) 266 if (rv->distance <= radius)
268 { 267 {
269 CLEAR_FLAG (op, FLAG_SLEEP); 268 CLEAR_FLAG (op, FLAG_SLEEP);
270 return 1; 269 return 1;
271 } 270 }
271
272 return 0; 272 return 0;
273} 273}
274 274
275int 275int
276move_randomly (object *op) 276move_randomly (object *op)
324 op->last_heal += (int) ((float) (8 * op->stats.Con) / FABS (op->speed)); 324 op->last_heal += (int) ((float) (8 * op->stats.Con) / FABS (op->speed));
325 op->stats.hp = MIN ((sint32) op->stats.hp + op->last_heal / 32, op->stats.maxhp); /* causes Con/4 hp/tick */ 325 op->stats.hp = MIN ((sint32) op->stats.hp + op->last_heal / 32, op->stats.maxhp); /* causes Con/4 hp/tick */
326 op->last_heal %= 32; 326 op->last_heal %= 32;
327 327
328 /* So if the monster has gained enough HP that they are no longer afraid */ 328 /* So if the monster has gained enough HP that they are no longer afraid */
329 if (QUERY_FLAG (op, FLAG_RUN_AWAY) && op->stats.hp >= (signed short) (((float) op->run_away / (float) 100) * (float) op->stats.maxhp)) 329 if (QUERY_FLAG (op, FLAG_RUN_AWAY) && op->stats.hp >= (signed short)(((float)op->run_away / 100.f) * (float)op->stats.maxhp))
330 CLEAR_FLAG (op, FLAG_RUN_AWAY); 330 CLEAR_FLAG (op, FLAG_RUN_AWAY);
331 331
332 if (op->stats.hp > op->stats.maxhp) 332 if (op->stats.hp > op->stats.maxhp)
333 op->stats.hp = op->stats.maxhp; 333 op->stats.hp = op->stats.maxhp;
334 } 334 }
335 335
336 /* generate sp, if applicable */ 336 /* generate sp, if applicable */
337 if (op->stats.Pow > 0 && op->stats.sp < op->stats.maxsp) 337 if (op->stats.Pow > 0 && op->stats.sp < op->stats.maxsp)
338 { 338 {
339 /* last_sp is in funny units. Dividing by speed puts 339 /* last_sp is in funny units. Dividing by speed puts
340 * the regeneration rate on a basis of time instead of 340 * the regeneration rate on a basis of time instead of
341 * #moves the monster makes. The scaling by 8 is 341 * #moves the monster makes. The scaling by 8 is
342 * to capture 8th's of a sp fraction regens 342 * to capture 8th's of a sp fraction regens
343 * 343 *
344 * Cast to sint32 before comparing to maxhp since otherwise an (sint16) 344 * Cast to sint32 before comparing to maxhp since otherwise an (sint16)
345 * overflow might produce monsters with negative sp. 345 * overflow might produce monsters with negative sp.
346 */ 346 */
347 347
348 op->last_sp += (int) ((float) (8 * op->stats.Pow) / FABS (op->speed)); 348 op->last_sp += (int) ((float) (8 * op->stats.Pow) / fabsf (op->speed));
349 op->stats.sp = MIN (op->stats.sp + op->last_sp / 128, op->stats.maxsp); /* causes Pow/16 sp/tick */ 349 op->stats.sp = min (op->stats.sp + op->last_sp / 128, op->stats.maxsp); /* causes Pow/16 sp/tick */
350 op->last_sp %= 128; 350 op->last_sp %= 128;
351 } 351 }
352 352
353 /* this should probably get modified by many more values. 353 /* this should probably get modified by many more values.
354 * (eg, creatures resistance to fear, level, etc. ) 354 * (eg, creatures resistance to fear, level, etc. )
358 358
359 if (INVOKE_OBJECT (MONSTER_MOVE, op, ARG_OBJECT (op->enemy))) 359 if (INVOKE_OBJECT (MONSTER_MOVE, op, ARG_OBJECT (op->enemy)))
360 return QUERY_FLAG (op, FLAG_FREED); 360 return QUERY_FLAG (op, FLAG_FREED);
361 361
362 if (QUERY_FLAG (op, FLAG_SLEEP) || QUERY_FLAG (op, FLAG_BLIND) || 362 if (QUERY_FLAG (op, FLAG_SLEEP) || QUERY_FLAG (op, FLAG_BLIND) ||
363 ((op->map->darkness > 0) && !QUERY_FLAG (op, FLAG_SEE_IN_DARK) && !QUERY_FLAG (op, FLAG_SEE_INVISIBLE))) 363 ((op->map->darklevel () > 0) && !QUERY_FLAG (op, FLAG_SEE_IN_DARK) && !QUERY_FLAG (op, FLAG_SEE_INVISIBLE)))
364 if (!check_wakeup (op, enemy, &rv)) 364 if (!check_wakeup (op, enemy, &rv))
365 return 0; 365 return 0;
366 366
367 /* check if monster pops out of hidden spot */ 367 /* check if monster pops out of hidden spot */
368 if (op->flag [FLAG_HIDDEN]) 368 if (op->flag [FLAG_HIDDEN])
390 { 390 {
391 if (op->attack_movement & HI4) 391 if (op->attack_movement & HI4)
392 { 392 {
393 switch (op->attack_movement & HI4) 393 switch (op->attack_movement & HI4)
394 { 394 {
395 case (PETMOVE): 395 case PETMOVE:
396 pet_move (op); 396 pet_move (op);
397 break; 397 break;
398 398
399 case (CIRCLE1): 399 case CIRCLE1:
400 circ1_move (op); 400 circ1_move (op);
401 break; 401 break;
402 402
403 case (CIRCLE2): 403 case CIRCLE2:
404 circ2_move (op); 404 circ2_move (op);
405 break; 405 break;
406 406
407 case (PACEV): 407 case PACEV:
408 pace_movev (op); 408 pace_movev (op);
409 break; 409 break;
410 410
411 case (PACEH): 411 case PACEH:
412 pace_moveh (op); 412 pace_moveh (op);
413 break; 413 break;
414 414
415 case (PACEV2): 415 case PACEV2:
416 pace2_movev (op); 416 pace2_movev (op);
417 break; 417 break;
418 418
419 case (PACEH2): 419 case PACEH2:
420 pace2_moveh (op); 420 pace2_moveh (op);
421 break; 421 break;
422 422
423 case (RANDO): 423 case RANDO:
424 rand_move (op); 424 rand_move (op);
425 break; 425 break;
426 426
427 case (RANDO2): 427 case RANDO2:
428 move_randomly (op); 428 move_randomly (op);
429 break; 429 break;
430 } 430 }
431 431
432 return 0; 432 return 0;
444 && !on_same_map (op, owner) 444 && !on_same_map (op, owner)
445 && !owner->flag [FLAG_REMOVED]) 445 && !owner->flag [FLAG_REMOVED])
446 return follow_owner (op, owner); 446 return follow_owner (op, owner);
447 447
448 /* doppleganger code to change monster facing to that of the nearest 448 /* doppleganger code to change monster facing to that of the nearest
449 * 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
450 * arch set uses it. 450 * arch set uses it.
451 */ 451 */
452 if ((op->race != NULL) && strcmp (op->race, "doppleganger") == 0) 452 if (op->race == shstr_doppleganger)
453 { 453 {
454 op->face = enemy->face; 454 op->face = enemy->face;
455 op->name = enemy->name; 455 op->name = enemy->name;
456 } 456 }
457 457
505 if (monster_use_bow (op, part, enemy, dir)) 505 if (monster_use_bow (op, part, enemy, dir))
506 return 0; 506 return 0;
507 } /* for processing of all parts */ 507 } /* for processing of all parts */
508 } /* If not scared */ 508 } /* If not scared */
509 509
510
511 part = rv.part; 510 part = rv.part;
512 dir = rv.direction; 511 dir = rv.direction;
512
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 (op->stats.Wis >= 8
517 && enemy->contr && enemy->contr->darkness_at (op->map, op->x, op->y) == LOS_BLOCKED)
518 {
519 int sdir = 0;
520 uint32_t &smell = op->ms ().smell;
521
522 for (int ndir = 1; ndir <= 8; ++ndir)
523 {
524 mapxy pos (op); pos.move (ndir);
525
526 if (pos.normalise ())
527 {
528 mapspace &ms = pos.ms ();
529
530 if (ms.smell > smell)
531 {
532 //printf ("%s: found smell, following it, apparently (%d, %d)\n",& op->name,op->ms().smell,ms.smell);//D
533 if (op->stats.Wis >= 10)
534 smell = ms.smell - 1; // smarter: tell others
535
536 sdir = ndir;
537
538 // perturbing the path might let the monster lose track,
539 // but it will also widen the actual path, spreading information
540 if (op->stats.Wis >= 15 && !rndm (20)) // even smarter, deviate and spread?
541 sdir = absdir (sdir + 1 - rndm (2) * 2);
542 }
543 }
544 }
545
546 if (sdir)
547 dir = sdir;
548 else if (smell)
549 {
550 // no better smell found, so assume the player jumped, and erase this smell
551 //printf ("erasing smell %d\n", op->ms ().smell);//D
552 unordered_mapwalk (op, -1, -1, 1, 1)
553 m->at (nx, ny).smell = 0;
554 }
555 }
513 556
514 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))
515 dir = absdir (dir + 4); 558 dir = absdir (dir + 4);
516 559
517 if (QUERY_FLAG (op, FLAG_CONFUSED)) 560 if (QUERY_FLAG (op, FLAG_CONFUSED))
571 } 614 }
572 615
573 if (QUERY_FLAG (op, FLAG_SCARED) || !can_hit (part, enemy, &rv) || QUERY_FLAG (op, FLAG_RUN_AWAY)) 616 if (QUERY_FLAG (op, FLAG_SCARED) || !can_hit (part, enemy, &rv) || QUERY_FLAG (op, FLAG_RUN_AWAY))
574 { 617 {
575 /* Try move around corners if !close */ 618 /* Try move around corners if !close */
576 int maxdiff = (QUERY_FLAG (op, FLAG_ONLY_ATTACK) || RANDOM () & 1) ? 1 : 2; 619 int maxdiff = (QUERY_FLAG (op, FLAG_ONLY_ATTACK) || rndm (2)) ? 1 : 2;
577 620
578 for (diff = 1; diff <= maxdiff; diff++) 621 for (diff = 1; diff <= maxdiff; diff++)
579 { 622 {
580 /* try different detours */ 623 /* try different detours */
581 int m = 1 - (RANDOM () & 2); /* Try left or right first? */ 624 int m = 1 - rndm (2) * 2; /* Try left or right first? */
582 625
583 if (move_object (op, absdir (dir + diff * m)) || move_object (op, absdir (dir - diff * m))) 626 if (move_object (op, absdir (dir + diff * m)) || move_object (op, absdir (dir - diff * m)))
584 return 0; 627 return 0;
585 } 628 }
586 } 629 }
613 { 656 {
614 object *nearest_player = get_nearest_player (op); 657 object *nearest_player = get_nearest_player (op);
615 658
616 if (nearest_player && nearest_player != enemy && !can_hit (part, enemy, &rv)) 659 if (nearest_player && nearest_player != enemy && !can_hit (part, enemy, &rv))
617 { 660 {
618 op->enemy = NULL; 661 op->enemy = 0;
619 enemy = nearest_player; 662 enemy = nearest_player;
620 } 663 }
621 } 664 }
622 665
623 if (!QUERY_FLAG (op, FLAG_SCARED) && can_hit (part, enemy, &rv)) 666 if (!QUERY_FLAG (op, FLAG_SCARED) && can_hit (part, enemy, &rv))
1377} 1420}
1378 1421
1379void 1422void
1380npc_call_help (object *op) 1423npc_call_help (object *op)
1381{ 1424{
1382 int x, y, mflags; 1425 unordered_mapwalk (op, -7, -7, 7, 7)
1383 object *npc;
1384 sint16 sx, sy;
1385 maptile *m;
1386
1387 for (x = -3; x < 4; x++)
1388 for (y = -3; y < 4; y++)
1389 { 1426 {
1390 m = op->map; 1427 mapspace &ms = m->at (nx, ny);
1391 sx = op->x + x; 1428
1392 sy = op->y + y;
1393 mflags = get_map_flags (m, &m, sx, sy, &sx, &sy);
1394 /* If nothing alive on this space, no need to search the space. */ 1429 /* If nothing alive on this space, no need to search the space. */
1395 if ((mflags & P_OUT_OF_MAP) || !(mflags & P_IS_ALIVE)) 1430 if (!(ms.flags () & P_IS_ALIVE))
1396 continue; 1431 continue;
1397 1432
1398 for (npc = GET_MAP_OB (m, sx, sy); npc != NULL; npc = npc->above) 1433 for (object *npc = ms.bot; npc; npc = npc->above)
1399 if (QUERY_FLAG (npc, FLAG_ALIVE) && QUERY_FLAG (npc, FLAG_UNAGGRESSIVE)) 1434 if (QUERY_FLAG (npc, FLAG_ALIVE) && QUERY_FLAG (npc, FLAG_UNAGGRESSIVE))
1400 npc->enemy = op->enemy; 1435 npc->enemy = op->enemy;
1401 } 1436 }
1402} 1437}
1403 1438
1404int 1439int
1405dist_att (int dir, object *ob, object *enemy, object *part, rv_vector * rv) 1440dist_att (int dir, object *ob, object *enemy, object *part, rv_vector *rv)
1406{ 1441{
1407 if (can_hit (part, enemy, rv)) 1442 if (can_hit (part, enemy, rv))
1408 return dir; 1443 return dir;
1409 1444
1410 if (rv->distance < 10) 1445 if (rv->distance < 10)
1414 1449
1415 return 0; 1450 return 0;
1416} 1451}
1417 1452
1418int 1453int
1419run_att (int dir, object *ob, object *enemy, object *part, rv_vector * rv) 1454run_att (int dir, object *ob, object *enemy, object *part, rv_vector *rv)
1420{ 1455{
1421 if ((can_hit (part, enemy, rv) && ob->move_status < 20) || ob->move_status < 20) 1456 if (can_hit (part, enemy, rv))
1422 {
1423 ob->move_status++;
1424 return (dir); 1457 return dir;
1425 } 1458 else
1426 else if (ob->move_status > 20)
1427 ob->move_status = 0;
1428
1429 return absdir (dir + 4); 1459 return absdir (dir + 4);
1430} 1460}
1431 1461
1432int 1462int
1433hitrun_att (int dir, object *ob, object *enemy) 1463hitrun_att (int dir, object *ob, object *enemy)
1434{ 1464{
1443} 1473}
1444 1474
1445int 1475int
1446wait_att (int dir, object *ob, object *enemy, object *part, rv_vector * rv) 1476wait_att (int dir, object *ob, object *enemy, object *part, rv_vector * rv)
1447{ 1477{
1448
1449 int inrange = can_hit (part, enemy, rv); 1478 int inrange = can_hit (part, enemy, rv);
1450 1479
1451 if (ob->move_status || inrange) 1480 if (ob->move_status || inrange)
1452 ob->move_status++; 1481 ob->move_status++;
1453 1482
1463} 1492}
1464 1493
1465int 1494int
1466disthit_att (int dir, object *ob, object *enemy, object *part, rv_vector * rv) 1495disthit_att (int dir, object *ob, object *enemy, object *part, rv_vector * rv)
1467{ 1496{
1468
1469 /* The logic below here looked plain wrong before. Basically, what should 1497 /* The logic below here looked plain wrong before. Basically, what should
1470 * happen is that if the creatures hp percentage falls below run_away, 1498 * happen is that if the creatures hp percentage falls below run_away,
1471 * the creature should run away (dir+4) 1499 * the creature should run away (dir+4)
1472 * I think its wrong for a creature to have a zero maxhp value, but 1500 * I think its wrong for a creature to have a zero maxhp value, but
1473 * at least one map has this set, and whatever the map contains, the 1501 * at least one map has this set, and whatever the map contains, the
1647 * Returns 0 if enemy can not be detected, 1 if it is detected 1675 * Returns 0 if enemy can not be detected, 1 if it is detected
1648 */ 1676 */
1649int 1677int
1650can_detect_enemy (object *op, object *enemy, rv_vector * rv) 1678can_detect_enemy (object *op, object *enemy, rv_vector * rv)
1651{ 1679{
1652 int radius = MIN_MON_RADIUS, hide_discovery;
1653
1654 /* null detection for any of these condtions always */ 1680 /* null detection for any of these condtions always */
1655 if (!op || !enemy || !op->map || !enemy->map) 1681 if (!op || !enemy || !op->map || !enemy->map)
1656 return 0; 1682 return 0;
1657 1683
1658 /* If the monster (op) has no way to get to the enemy, do nothing */ 1684 /* If the monster (op) has no way to get to the enemy, do nothing */
1660 return 0; 1686 return 0;
1661 1687
1662 get_rangevector (op, enemy, rv, 0); 1688 get_rangevector (op, enemy, rv, 0);
1663 1689
1664 /* Monsters always ignore the DM */ 1690 /* Monsters always ignore the DM */
1665 if (op->type != PLAYER && QUERY_FLAG (enemy, FLAG_WIZ)) 1691 if (!op->is_player () && QUERY_FLAG (enemy, FLAG_WIZ))
1666 return 0; 1692 return 0;
1667 1693
1668 /* simple check. Should probably put some range checks in here. */ 1694 /* simple check. Should probably put some range checks in here. */
1669 if (can_see_enemy (op, enemy)) 1695 if (can_see_enemy (op, enemy))
1670 return 1; 1696 return 1;
1671 1697
1672 /* The rest of this is for monsters. Players are on their own for 1698 /* The rest of this is for monsters. Players are on their own for
1673 * finding enemies! 1699 * finding enemies!
1674 */ 1700 */
1675 if (op->type == PLAYER) 1701 if (op->is_player ())
1676 return 0; 1702 return 0;
1677 1703
1678 /* Quality invisible? Bah, we wont see them w/o SEE_INVISIBLE 1704 /* Quality invisible? Bah, we wont see them w/o SEE_INVISIBLE
1679 * flag (which was already checked) in can_see_enmy (). Lets get out of here 1705 * flag (which was already checked) in can_see_enemy (). Lets get out of here
1680 */ 1706 */
1681 if (enemy->invisible && (!enemy->contr || (!enemy->contr->tmp_invis && !enemy->contr->hidden))) 1707 if (enemy->invisible && (!enemy->contr || (!enemy->contr->tmp_invis && !enemy->contr->hidden)))
1682 return 0; 1708 return 0;
1683 1709
1710 int radius = MIN_MON_RADIUS;
1711
1684 /* use this for invis also */ 1712 /* use this for invis also */
1685 hide_discovery = op->stats.Int / 5; 1713 int hide_discovery = op->stats.Int / 5;
1686 1714
1687 /* Determine Detection radii */ 1715 /* Determine Detection radii */
1688 if (!enemy->flag [FLAG_HIDDEN]) /* to detect non-hidden (eg dark/invis enemy) */ 1716 if (!enemy->flag [FLAG_HIDDEN]) /* to detect non-hidden (eg dark/invis enemy) */
1689 radius = max (MIN_MON_RADIUS, op->stats.Wis / 5 + 1); 1717 radius = max (MIN_MON_RADIUS, op->stats.Wis / 3 + 1);
1690 else 1718 else
1691 { /* a level/INT/Dex adjustment for hiding */ 1719 { /* a level/INT/Dex adjustment for hiding */
1692 int bonus = op->level / 2 + op->stats.Int / 5; 1720 int bonus = op->level / 2 + op->stats.Int / 5;
1693 1721
1694 if (enemy->type == PLAYER) 1722 if (enemy->is_player ())
1695 { 1723 {
1696 if (object *sk_hide = find_skill_by_number (enemy, SK_HIDING)) 1724 if (object *sk_hide = find_skill_by_number (enemy, SK_HIDING))
1697 bonus -= sk_hide->level; 1725 bonus -= sk_hide->level;
1698 else 1726 else
1699 { 1727 {
1716 radius /= 2; 1744 radius /= 2;
1717 hide_discovery /= 3; 1745 hide_discovery /= 3;
1718 } 1746 }
1719 1747
1720 /* Radii adjustment for enemy standing in the dark */ 1748 /* Radii adjustment for enemy standing in the dark */
1721 if (op->map->darkness > 0 && !stand_in_light (enemy)) 1749 if (!stand_in_light (enemy))
1722 { 1750 {
1723 /* on dark maps body heat can help indicate location with infravision 1751 /* on dark maps body heat can help indicate location with infravision
1724 * undead don't have body heat, so no benefit detecting them. 1752 * undead don't have body heat, so no benefit detecting them.
1725 */ 1753 */
1726 if (QUERY_FLAG (op, FLAG_SEE_IN_DARK) && !is_true_undead (enemy)) 1754 if (QUERY_FLAG (op, FLAG_SEE_IN_DARK) && !is_true_undead (enemy))
1727 radius += op->map->darkness / 2; 1755 radius += op->map->darklevel () / 2;
1728 else 1756 else
1729 radius -= op->map->darkness / 2; 1757 radius -= op->map->darklevel () / 2;
1730 1758
1731 /* op next to a monster (and not in complete darkness) 1759 /* op next to a monster (and not in complete darkness)
1732 * the monster should have a chance to see you. 1760 * the monster should have a chance to see you.
1733 */ 1761 */
1734 if (radius < MIN_MON_RADIUS && op->map->darkness < 5 && rv->distance <= 1) 1762 if (radius < MIN_MON_RADIUS && op->map->darklevel () < MAX_DARKNESS && rv->distance <= 1)
1735 radius = MIN_MON_RADIUS; 1763 radius = MIN_MON_RADIUS;
1736 } /* if on dark map */ 1764 } /* if on dark map */
1737 1765
1738 /* Lets not worry about monsters that have incredible detection 1766 /* Lets not worry about monsters that have incredible detection
1739 * radii, we only need to worry here about things the player can 1767 * radii, we only need to worry here about things the player can
1787 /* Wasn't detected above, so still hidden */ 1815 /* Wasn't detected above, so still hidden */
1788 return 0; 1816 return 0;
1789} 1817}
1790 1818
1791/* determine if op stands in a lighted square. This is not a very 1819/* determine if op stands in a lighted square. This is not a very
1792 * intellegent algorithm. For one thing, we ignore los here, SO it 1820 * intelligent algorithm. For one thing, we ignore los here, SO it
1793 * is possible for a bright light to illuminate a player on the 1821 * is possible for a bright light to illuminate a player on the
1794 * other side of a wall (!). 1822 * other side of a wall (!).
1795 */ 1823 */
1796int 1824int
1797stand_in_light (object *op) 1825stand_in_light (object *op)
1798{ 1826{
1799 if (!op) 1827 if (op)
1828 {
1829 if (!op->is_on_map ())
1800 return 0; 1830 return 0;
1801 1831
1832 if (op->map->darklevel () <= 0)
1833 return 1;
1834
1802 if (op->glow_radius > 0) 1835 if (op->glow_radius > 0)
1803 return 1; 1836 return 1;
1804 1837
1805 if (op->map) 1838 if (op->map)
1806 { 1839 unordered_mapwalk (op, -MAX_LIGHT_RADIUS, -MAX_LIGHT_RADIUS, MAX_LIGHT_RADIUS, MAX_LIGHT_RADIUS)
1840 {
1807 /* Check the spaces with the max light radius to see if any of them 1841 /* Check the spaces with the max light radius to see if any of them
1808 * have lights, and if any of them light the player enough, then return 1. 1842 * have lights, and if any of them light the player enough, then return 1.
1809 */
1810 for (int x = op->x - MAX_LIGHT_RADIUS; x <= op->x + MAX_LIGHT_RADIUS; x++)
1811 {
1812 for (int y = op->y - MAX_LIGHT_RADIUS; y <= op->y + MAX_LIGHT_RADIUS; y++)
1813 { 1843 */
1814 maptile *m = op->map; 1844 int light = m->at (nx, ny).light;
1815 sint16 nx = x;
1816 sint16 ny = y;
1817 1845
1818 if (xy_normalise (m, nx, ny)) 1846 if (expect_false (light > 0) && idistance (dx, dy) <= light)
1819 if (idistance (x - op->x, y - op->y) < m->at (nx, ny).light)
1820 return 1; 1847 return 1;
1821 } 1848 }
1822 }
1823 } 1849 }
1824 1850
1825 return 0; 1851 return 0;
1826} 1852}
1827 1853
1851 { 1877 {
1852 /* HIDDEN ENEMY. by definition, you can't see hidden stuff! 1878 /* HIDDEN ENEMY. by definition, you can't see hidden stuff!
1853 * However,if you carry any source of light, then the hidden 1879 * However,if you carry any source of light, then the hidden
1854 * creature is seeable (and stupid) */ 1880 * creature is seeable (and stupid) */
1855 1881
1856 if (has_carried_lights (enemy)) 1882 if (enemy->has_carried_lights ())
1857 { 1883 {
1858 if (enemy->flag [FLAG_HIDDEN]) 1884 if (enemy->flag [FLAG_HIDDEN])
1859 { 1885 {
1860 make_visible (enemy); 1886 make_visible (enemy);
1861 new_draw_info (NDI_UNIQUE, 0, enemy, "Your light reveals your hiding spot!"); 1887 new_draw_info (NDI_UNIQUE, 0, enemy, "Your light reveals your hiding spot!");
1864 return 1; 1890 return 1;
1865 } 1891 }
1866 else if (enemy->flag [FLAG_HIDDEN]) 1892 else if (enemy->flag [FLAG_HIDDEN])
1867 return 0; 1893 return 0;
1868 1894
1869 /* Invisible enemy. Break apart the check for invis undead/invis looker 1895 /* Invisible enemy. Break apart the check for invis undead/invis looker
1870 * into more simple checks - the QUERY_FLAG doesn't return 1/0 values, 1896 * into more simple checks - the QUERY_FLAG doesn't return 1/0 values,
1871 * and making it a conditional makes the code pretty ugly. 1897 * and making it a conditional makes the code pretty ugly.
1872 */ 1898 */
1873 if (!QUERY_FLAG (looker, FLAG_SEE_INVISIBLE)) 1899 if (!QUERY_FLAG (looker, FLAG_SEE_INVISIBLE))
1874 if (makes_invisible_to (enemy, looker)) 1900 if (makes_invisible_to (enemy, looker))
1875 return 0; 1901 return 0;
1876 } 1902 }
1877 else if (looker->type == PLAYER) /* for players, a (possible) shortcut */ 1903 else if (looker->is_player ()) /* for players, a (possible) shortcut */
1878 if (player_can_view (looker, enemy)) 1904 if (player_can_view (looker, enemy))
1879 return 1; 1905 return 1;
1880 1906
1881 /* ENEMY IN DARK MAP. Without infravision, the enemy is not seen 1907 /* ENEMY IN DARK MAP. Without infravision, the enemy is not seen
1882 * unless they carry a light or stand in light. Darkness doesnt 1908 * unless they carry a light or stand in light. Darkness doesnt
1885 * we care about the enemy maps status, not the looker. 1911 * we care about the enemy maps status, not the looker.
1886 * only relevant for tiled maps, but it is possible that the 1912 * only relevant for tiled maps, but it is possible that the
1887 * enemy is on a bright map and the looker on a dark - in that 1913 * enemy is on a bright map and the looker on a dark - in that
1888 * case, the looker can still see the enemy 1914 * case, the looker can still see the enemy
1889 */ 1915 */
1890 if (enemy->map->darkness > 0 && !stand_in_light (enemy) 1916 if (!stand_in_light (enemy)
1891 && (!QUERY_FLAG (looker, FLAG_SEE_IN_DARK) || !is_true_undead (looker) || !QUERY_FLAG (looker, FLAG_XRAYS))) 1917 && (!QUERY_FLAG (looker, FLAG_SEE_IN_DARK) || !is_true_undead (looker) || !QUERY_FLAG (looker, FLAG_XRAYS)))
1892 return 0; 1918 return 0;
1893 1919
1894 return 1; 1920 return 1;
1895} 1921}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines