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.57 by root, Sun Dec 28 06:59:27 2008 UTC vs.
Revision 1.70 by root, Mon Oct 12 21:27:55 2009 UTC

3 * 3 *
4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
7 * 7 *
8 * Deliantra is free software: you can redistribute it and/or modify 8 * Deliantra is free software: you can redistribute it and/or modify it under
9 * it under the terms of the GNU General Public License as published by 9 * the terms of the Affero GNU General Public License as published by the
10 * the Free Software Foundation, either version 3 of the License, or 10 * Free Software Foundation, either version 3 of the License, or (at your
11 * (at your option) any later version. 11 * option) any later version.
12 * 12 *
13 * This program is distributed in the hope that it will be useful, 13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details. 16 * GNU General Public License for more details.
17 * 17 *
18 * You should have received a copy of the GNU General Public License 18 * You should have received a copy of the Affero GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. 19 * and the GNU General Public License along with this program. If not, see
20 * <http://www.gnu.org/licenses/>.
20 * 21 *
21 * The authors can be reached via e-mail to <support@deliantra.net> 22 * The authors can be reached via e-mail to <support@deliantra.net>
22 */ 23 */
23 24
24#include <global.h> 25#include <global.h>
46 npc->enemy = NULL; 47 npc->enemy = NULL;
47 else if (npc->enemy == NULL) 48 else if (npc->enemy == NULL)
48 npc->enemy = npc->owner->enemy; 49 npc->enemy = npc->owner->enemy;
49 } 50 }
50 51
51 /* periodically, a monster mayu change its target. Also, if the object 52 /* periodically, a monster may change its target. Also, if the object
52 * has been destroyed, etc, clear the enemy. 53 * has been destroyed, etc, clear the enemy.
53 * TODO: this should be changed, because it invokes to attack forced or 54 * TODO: this should be changed, because it invokes to attack forced or
54 * attacked monsters to leave the attacker alone, before it is destroyed 55 * attacked monsters to leave the attacker alone, before it is destroyed
55 */ 56 */
56 /* i had removed the random target leave, this invokes problems with friendly 57 /* 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 58 * objects, getting attacked and defending herself - they don't try to attack
58 * again then but perhaps get attack on and on 59 * 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 60 * If we include a aggravated flag in , we can handle evil vs evil and good vs good
60 * too. */ 61 * too. */
61 62
65 * the grouping checks are. Code is the same. 66 * the grouping checks are. Code is the same.
66 */ 67 */
67 if (QUERY_FLAG (npc->enemy, FLAG_REMOVED) || 68 if (QUERY_FLAG (npc->enemy, FLAG_REMOVED) ||
68 QUERY_FLAG (npc->enemy, FLAG_FREED) || 69 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)) 70 !on_same_map (npc, npc->enemy) || npc == npc->enemy || QUERY_FLAG (npc, FLAG_NEUTRAL) || QUERY_FLAG (npc->enemy, FLAG_NEUTRAL))
70 npc->enemy = NULL; 71 npc->enemy = 0;
71 72
72 else if (QUERY_FLAG (npc, FLAG_FRIENDLY) && ((QUERY_FLAG (npc->enemy, FLAG_FRIENDLY) 73 else if (QUERY_FLAG (npc, FLAG_FRIENDLY) && ((QUERY_FLAG (npc->enemy, FLAG_FRIENDLY)
73 && !(should_arena_attack (npc, npc->owner, npc->enemy))) 74 && !(should_arena_attack (npc, npc->owner, npc->enemy)))
74 || ((npc->enemy->type == PLAYER) && !(should_arena_attack (npc, npc->owner, npc->enemy))) 75 || ((npc->enemy->type == PLAYER) && !(should_arena_attack (npc, npc->owner, npc->enemy)))
75 || npc->enemy == npc->owner)) 76 || npc->enemy == npc->owner))
76 npc->enemy = NULL; 77 npc->enemy = 0;
77 78
78 79
79 else if (!QUERY_FLAG (npc, FLAG_FRIENDLY) && (!QUERY_FLAG (npc->enemy, FLAG_FRIENDLY) && npc->enemy->type != PLAYER)) 80 else if (!QUERY_FLAG (npc, FLAG_FRIENDLY) && (!QUERY_FLAG (npc->enemy, FLAG_FRIENDLY) && npc->enemy->type != PLAYER))
80 npc->enemy = NULL; 81 npc->enemy = 0;
81 82
82 /* I've noticed that pets could sometimes get an arrow as the 83 /* I've noticed that pets could sometimes get an arrow as the
83 * target enemy - this code below makes sure the enemy is something 84 * target enemy - this code below makes sure the enemy is something
84 * that should be attacked. My guess is that the arrow hits 85 * that should be attacked. My guess is that the arrow hits
85 * the creature/owner, and so the creature then takes that 86 * the creature/owner, and so the creature then takes that
87 */ 88 */
88 else if (!QUERY_FLAG (npc->enemy, FLAG_MONSTER) 89 else if (!QUERY_FLAG (npc->enemy, FLAG_MONSTER)
89 && !QUERY_FLAG (npc->enemy, FLAG_GENERATOR) 90 && !QUERY_FLAG (npc->enemy, FLAG_GENERATOR)
90 && npc->enemy->type != PLAYER 91 && npc->enemy->type != PLAYER
91 && npc->enemy->type != GOLEM) 92 && npc->enemy->type != GOLEM)
92 npc->enemy = NULL; 93 npc->enemy = 0;
93
94 } 94 }
95 95
96 return can_detect_enemy (npc, npc->enemy, rv) ? npc->enemy : NULL; 96 return can_detect_enemy (npc, npc->enemy, rv) ? npc->enemy : 0;
97} 97}
98 98
99/* Returns the nearest living creature (monster or generator). 99/* Returns the nearest living creature (monster or generator).
100 * Modified to deal with tiled maps properly. 100 * Modified to deal with tiled maps properly.
101 * Also fixed logic so that monsters in the lower directions were more 101 * Also fixed logic so that monsters in the lower directions were more
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
389 { 390 {
390 if (op->attack_movement & HI4) 391 if (op->attack_movement & HI4)
391 { 392 {
392 switch (op->attack_movement & HI4) 393 switch (op->attack_movement & HI4)
393 { 394 {
394 case (PETMOVE): 395 case PETMOVE:
395 pet_move (op); 396 pet_move (op);
396 break; 397 break;
397 398
398 case (CIRCLE1): 399 case CIRCLE1:
399 circ1_move (op); 400 circ1_move (op);
400 break; 401 break;
401 402
402 case (CIRCLE2): 403 case CIRCLE2:
403 circ2_move (op); 404 circ2_move (op);
404 break; 405 break;
405 406
406 case (PACEV): 407 case PACEV:
407 pace_movev (op); 408 pace_movev (op);
408 break; 409 break;
409 410
410 case (PACEH): 411 case PACEH:
411 pace_moveh (op); 412 pace_moveh (op);
412 break; 413 break;
413 414
414 case (PACEV2): 415 case PACEV2:
415 pace2_movev (op); 416 pace2_movev (op);
416 break; 417 break;
417 418
418 case (PACEH2): 419 case PACEH2:
419 pace2_moveh (op); 420 pace2_moveh (op);
420 break; 421 break;
421 422
422 case (RANDO): 423 case RANDO:
423 rand_move (op); 424 rand_move (op);
424 break; 425 break;
425 426
426 case (RANDO2): 427 case RANDO2:
427 move_randomly (op); 428 move_randomly (op);
428 break; 429 break;
429 } 430 }
430 431
431 return 0; 432 return 0;
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
510 dir = rv.direction; 511 dir = rv.direction;
511 512
512 // 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
513 // can directly reach the player, we do not deviate. 514 // can directly reach the player, we do not deviate.
514 // for non-players, we never deviate 515 // for non-players, we never deviate
516 if (op->stats.Wis >= 8
515 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)
516 { 518 {
517 int sdir = 0; 519 int sdir = 0;
520 uint32_t &smell = op->ms ().smell;
518 521
519 for (int ndir = 1; ndir <= 8; ++ndir) 522 for (int ndir = 1; ndir <= 8; ++ndir)
520 { 523 {
521 mapxy pos (op); pos.move (ndir); 524 mapxy pos (op); pos.move (ndir);
522 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
533 if (op->stats.Wis >= 10)
530 op->ms ().smell = ms.smell - 1; // smarter: tell others 534 smell = ms.smell - 1; // smarter: tell others
535
531 sdir = ndir; 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 widen the actual path, spreading information 539 // but it will also widen the actual path, spreading information
535 if (!rndm (20)) // even smarter, deviate and spread? 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 if (op->ms ().smell) 548 else if (smell)
544 { 549 {
545 // 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
546 //printf ("erasing smell %d\n", op->ms ().smell);//D 551 //printf ("erasing smell %d\n", op->ms ().smell);//D
547 ordered_mapwalk_begin (op, -1, -1, 1, 1) 552 unordered_mapwalk (op, -1, -1, 1, 1)
548 if (m)
549 m->at (nx, ny).smell = 0; 553 m->at (nx, ny).smell = 0;
550 ordered_mapwalk_end
551 } 554 }
552 } 555 }
553 556
554 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))
555 dir = absdir (dir + 4); 558 dir = absdir (dir + 4);
703 return 1; 706 return 1;
704 707
705 /* check all the parts of ob2 - just because we can't get to 708 /* check all the parts of ob2 - just because we can't get to
706 * its head doesn't mean we don't want to pound its feet 709 * its head doesn't mean we don't want to pound its feet
707 */ 710 */
708 for (more = ob2->more; more != NULL; more = more->more) 711 for (more = ob2->more; more; more = more->more)
709 { 712 {
710 get_rangevector (ob1, more, &rv1, 0); 713 get_rangevector (ob1, more, &rv1, 0);
711 if (abs (rv1.distance_x) < 2 && abs (rv1.distance_y) < 2) 714 if (abs (rv1.distance_x) < 2 && abs (rv1.distance_y) < 2)
712 return 1; 715 return 1;
713 } 716 }
1194 flag = 1; 1197 flag = 1;
1195 1198
1196 else 1199 else
1197 switch (item->type) 1200 switch (item->type)
1198 { 1201 {
1199 case MONEY: 1202 case MONEY:
1200 case GEM: 1203 case GEM:
1201 flag = monster->pick_up & 2; 1204 flag = monster->pick_up & 2;
1202 break; 1205 break;
1203 1206
1204 case FOOD: 1207 case FOOD:
1205 flag = monster->pick_up & 4; 1208 flag = monster->pick_up & 4;
1206 break; 1209 break;
1207 1210
1208 case WEAPON: 1211 case WEAPON:
1209 flag = (monster->pick_up & 8) || QUERY_FLAG (monster, FLAG_USE_WEAPON); 1212 flag = (monster->pick_up & 8) || QUERY_FLAG (monster, FLAG_USE_WEAPON);
1210 break; 1213 break;
1211 1214
1212 case ARMOUR: 1215 case ARMOUR:
1213 case SHIELD: 1216 case SHIELD:
1214 case HELMET: 1217 case HELMET:
1215 case BOOTS: 1218 case BOOTS:
1216 case GLOVES: 1219 case GLOVES:
1217 case GIRDLE: 1220 case GIRDLE:
1218 flag = (monster->pick_up & 16) || QUERY_FLAG (monster, FLAG_USE_ARMOUR); 1221 flag = (monster->pick_up & 16) || QUERY_FLAG (monster, FLAG_USE_ARMOUR);
1219 break; 1222 break;
1220 1223
1221 case SKILL: 1224 case SKILL:
1222 flag = QUERY_FLAG (monster, FLAG_CAN_USE_SKILL); 1225 flag = QUERY_FLAG (monster, FLAG_CAN_USE_SKILL);
1223 break; 1226 break;
1224 1227
1225 case RING: 1228 case RING:
1226 flag = QUERY_FLAG (monster, FLAG_USE_RING); 1229 flag = QUERY_FLAG (monster, FLAG_USE_RING);
1227 break; 1230 break;
1228 1231
1229 case WAND: 1232 case WAND:
1230 case HORN: 1233 case HORN:
1231 case ROD: 1234 case ROD:
1232 flag = QUERY_FLAG (monster, FLAG_USE_RANGE); 1235 flag = QUERY_FLAG (monster, FLAG_USE_RANGE);
1233 break; 1236 break;
1234 1237
1235 case SPELLBOOK: 1238 case SPELLBOOK:
1236 flag = monster->arch && QUERY_FLAG (monster->arch, FLAG_CAST_SPELL); 1239 flag = monster->arch && QUERY_FLAG (monster->arch, FLAG_CAST_SPELL);
1237 break; 1240 break;
1238 1241
1239 case SCROLL: 1242 case SCROLL:
1240 flag = QUERY_FLAG (monster, FLAG_USE_SCROLL); 1243 flag = QUERY_FLAG (monster, FLAG_USE_SCROLL);
1241 break; 1244 break;
1242 1245
1243 case BOW: 1246 case BOW:
1244 case ARROW: 1247 case ARROW:
1245 flag = QUERY_FLAG (monster, FLAG_USE_BOW); 1248 flag = QUERY_FLAG (monster, FLAG_USE_BOW);
1246 break; 1249 break;
1247 } 1250 }
1248 1251
1249 /* Simplistic check - if the monster has a location to equip it, he will 1252 /* Simplistic check - if the monster has a location to equip it, he will
1250 * pick it up. Note that this doesn't handle cases where an item may 1253 * pick it up. Note that this doesn't handle cases where an item may
1251 * use several locations. 1254 * use several locations.
1279 for (tmp = monster->below; tmp != NULL; tmp = next) 1282 for (tmp = monster->below; tmp != NULL; tmp = next)
1280 { 1283 {
1281 next = tmp->below; 1284 next = tmp->below;
1282 switch (tmp->type) 1285 switch (tmp->type)
1283 { 1286 {
1284 case CF_HANDLE: 1287 case T_HANDLE:
1285 case TRIGGER: 1288 case TRIGGER:
1286 if (monster->will_apply & 1) 1289 if (monster->will_apply & 1)
1287 manual_apply (monster, tmp, 0); 1290 manual_apply (monster, tmp, 0);
1288 break; 1291 break;
1289 1292
1417} 1420}
1418 1421
1419void 1422void
1420npc_call_help (object *op) 1423npc_call_help (object *op)
1421{ 1424{
1422 int x, y, mflags; 1425 unordered_mapwalk (op, -7, -7, 7, 7)
1423 object *npc;
1424 sint16 sx, sy;
1425 maptile *m;
1426
1427 for (x = -3; x < 4; x++)
1428 for (y = -3; y < 4; y++)
1429 { 1426 {
1430 m = op->map; 1427 mapspace &ms = m->at (nx, ny);
1431 sx = op->x + x; 1428
1432 sy = op->y + y;
1433 mflags = get_map_flags (m, &m, sx, sy, &sx, &sy);
1434 /* 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. */
1435 if ((mflags & P_OUT_OF_MAP) || !(mflags & P_IS_ALIVE)) 1430 if (!(ms.flags () & P_IS_ALIVE))
1436 continue; 1431 continue;
1437 1432
1438 for (npc = GET_MAP_OB (m, sx, sy); npc != NULL; npc = npc->above) 1433 for (object *npc = ms.bot; npc; npc = npc->above)
1439 if (QUERY_FLAG (npc, FLAG_ALIVE) && QUERY_FLAG (npc, FLAG_UNAGGRESSIVE)) 1434 if (QUERY_FLAG (npc, FLAG_ALIVE) && QUERY_FLAG (npc, FLAG_UNAGGRESSIVE))
1440 npc->enemy = op->enemy; 1435 npc->enemy = op->enemy;
1441 } 1436 }
1442} 1437}
1443 1438
1444int 1439int
1445dist_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)
1446{ 1441{
1447 if (can_hit (part, enemy, rv)) 1442 if (can_hit (part, enemy, rv))
1448 return dir; 1443 return dir;
1449 1444
1450 if (rv->distance < 10) 1445 if (rv->distance < 10)
1454 1449
1455 return 0; 1450 return 0;
1456} 1451}
1457 1452
1458int 1453int
1459run_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)
1460{ 1455{
1461 if ((can_hit (part, enemy, rv) && ob->move_status < 20) || ob->move_status < 20) 1456 if (can_hit (part, enemy, rv))
1462 {
1463 ob->move_status++;
1464 return (dir); 1457 return dir;
1465 } 1458 else
1466 else if (ob->move_status > 20)
1467 ob->move_status = 0;
1468
1469 return absdir (dir + 4); 1459 return absdir (dir + 4);
1470} 1460}
1471 1461
1472int 1462int
1473hitrun_att (int dir, object *ob, object *enemy) 1463hitrun_att (int dir, object *ob, object *enemy)
1474{ 1464{
1483} 1473}
1484 1474
1485int 1475int
1486wait_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)
1487{ 1477{
1488
1489 int inrange = can_hit (part, enemy, rv); 1478 int inrange = can_hit (part, enemy, rv);
1490 1479
1491 if (ob->move_status || inrange) 1480 if (ob->move_status || inrange)
1492 ob->move_status++; 1481 ob->move_status++;
1493 1482
1503} 1492}
1504 1493
1505int 1494int
1506disthit_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)
1507{ 1496{
1508
1509 /* The logic below here looked plain wrong before. Basically, what should 1497 /* The logic below here looked plain wrong before. Basically, what should
1510 * 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,
1511 * the creature should run away (dir+4) 1499 * the creature should run away (dir+4)
1512 * 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
1513 * 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
1514 * server should try to be resilant enough to avoid the problem 1502 * server should try to be resilant enough to avoid the problem
1515 */ 1503 */
1516 if (ob->stats.maxhp && (ob->stats.hp * 100) / ob->stats.maxhp < ob->run_away) 1504 if (ob->stats.hp * 100 < ob->stats.maxhp * ob->run_away)
1517 return absdir (dir + 4); 1505 return absdir (dir + 4);
1518 1506
1519 return dist_att (dir, ob, enemy, part, rv); 1507 return dist_att (dir, ob, enemy, part, rv);
1520} 1508}
1521 1509
1687 * 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
1688 */ 1676 */
1689int 1677int
1690can_detect_enemy (object *op, object *enemy, rv_vector * rv) 1678can_detect_enemy (object *op, object *enemy, rv_vector * rv)
1691{ 1679{
1692 int radius = MIN_MON_RADIUS, hide_discovery;
1693
1694 /* null detection for any of these condtions always */ 1680 /* null detection for any of these condtions always */
1695 if (!op || !enemy || !op->map || !enemy->map) 1681 if (!op || !enemy || !op->map || !enemy->map)
1696 return 0; 1682 return 0;
1697 1683
1698 /* 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 */
1700 return 0; 1686 return 0;
1701 1687
1702 get_rangevector (op, enemy, rv, 0); 1688 get_rangevector (op, enemy, rv, 0);
1703 1689
1704 /* Monsters always ignore the DM */ 1690 /* Monsters always ignore the DM */
1705 if (op->type != PLAYER && QUERY_FLAG (enemy, FLAG_WIZ)) 1691 if (!op->is_player () && QUERY_FLAG (enemy, FLAG_WIZ))
1706 return 0; 1692 return 0;
1707 1693
1708 /* simple check. Should probably put some range checks in here. */ 1694 /* simple check. Should probably put some range checks in here. */
1709 if (can_see_enemy (op, enemy)) 1695 if (can_see_enemy (op, enemy))
1710 return 1; 1696 return 1;
1711 1697
1712 /* 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
1713 * finding enemies! 1699 * finding enemies!
1714 */ 1700 */
1715 if (op->type == PLAYER) 1701 if (op->is_player ())
1716 return 0; 1702 return 0;
1717 1703
1718 /* Quality invisible? Bah, we wont see them w/o SEE_INVISIBLE 1704 /* Quality invisible? Bah, we wont see them w/o SEE_INVISIBLE
1719 * 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
1720 */ 1706 */
1721 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)))
1722 return 0; 1708 return 0;
1723 1709
1710 int radius = MIN_MON_RADIUS;
1711
1724 /* use this for invis also */ 1712 /* use this for invis also */
1725 hide_discovery = op->stats.Int / 5; 1713 int hide_discovery = op->stats.Int / 5;
1726 1714
1727 /* Determine Detection radii */ 1715 /* Determine Detection radii */
1728 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) */
1729 radius = max (MIN_MON_RADIUS, op->stats.Wis / 5 + 1); 1717 radius = max (MIN_MON_RADIUS, op->stats.Wis / 3 + 1);
1730 else 1718 else
1731 { /* a level/INT/Dex adjustment for hiding */ 1719 { /* a level/INT/Dex adjustment for hiding */
1732 int bonus = op->level / 2 + op->stats.Int / 5; 1720 int bonus = op->level / 2 + op->stats.Int / 5;
1733 1721
1734 if (enemy->is_player ()) 1722 if (enemy->is_player ())
1756 radius /= 2; 1744 radius /= 2;
1757 hide_discovery /= 3; 1745 hide_discovery /= 3;
1758 } 1746 }
1759 1747
1760 /* Radii adjustment for enemy standing in the dark */ 1748 /* Radii adjustment for enemy standing in the dark */
1761 if (op->map->darklevel () > 0 && !stand_in_light (enemy)) 1749 if (!stand_in_light (enemy))
1762 { 1750 {
1763 /* on dark maps body heat can help indicate location with infravision 1751 /* on dark maps body heat can help indicate location with infravision
1764 * undead don't have body heat, so no benefit detecting them. 1752 * undead don't have body heat, so no benefit detecting them.
1765 */ 1753 */
1766 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))
1769 radius -= op->map->darklevel () / 2; 1757 radius -= op->map->darklevel () / 2;
1770 1758
1771 /* op next to a monster (and not in complete darkness) 1759 /* op next to a monster (and not in complete darkness)
1772 * the monster should have a chance to see you. 1760 * the monster should have a chance to see you.
1773 */ 1761 */
1774 if (radius < MIN_MON_RADIUS && op->map->darklevel () < 5 && rv->distance <= 1) 1762 if (radius < MIN_MON_RADIUS && op->map->darklevel () < MAX_DARKNESS && rv->distance <= 1)
1775 radius = MIN_MON_RADIUS; 1763 radius = MIN_MON_RADIUS;
1776 } /* if on dark map */ 1764 } /* if on dark map */
1777 1765
1778 /* Lets not worry about monsters that have incredible detection 1766 /* Lets not worry about monsters that have incredible detection
1779 * 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
1827 /* Wasn't detected above, so still hidden */ 1815 /* Wasn't detected above, so still hidden */
1828 return 0; 1816 return 0;
1829} 1817}
1830 1818
1831/* 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
1832 * intellegent algorithm. For one thing, we ignore los here, SO it 1820 * intelligent algorithm. For one thing, we ignore los here, SO it
1833 * 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
1834 * other side of a wall (!). 1822 * other side of a wall (!).
1835 */ 1823 */
1836int 1824int
1837stand_in_light (object *op) 1825stand_in_light (object *op)
1838{ 1826{
1839 if (op) 1827 if (op)
1840 { 1828 {
1829 if (!op->is_on_map ())
1830 return 0;
1831
1832 if (op->map->darklevel () <= 0)
1833 return 1;
1834
1841 if (op->glow_radius > 0) 1835 if (op->glow_radius > 0)
1842 return 1; 1836 return 1;
1843 1837
1844 if (op->map) 1838 if (op->map)
1845 unordered_mapwalk (op, -MAX_LIGHT_RADIUS, -MAX_LIGHT_RADIUS, MAX_LIGHT_RADIUS, MAX_LIGHT_RADIUS) 1839 unordered_mapwalk (op, -MAX_LIGHT_RADIUS, -MAX_LIGHT_RADIUS, MAX_LIGHT_RADIUS, MAX_LIGHT_RADIUS)
1883 { 1877 {
1884 /* HIDDEN ENEMY. by definition, you can't see hidden stuff! 1878 /* HIDDEN ENEMY. by definition, you can't see hidden stuff!
1885 * However,if you carry any source of light, then the hidden 1879 * However,if you carry any source of light, then the hidden
1886 * creature is seeable (and stupid) */ 1880 * creature is seeable (and stupid) */
1887 1881
1888 if (has_carried_lights (enemy)) 1882 if (enemy->has_carried_lights ())
1889 { 1883 {
1890 if (enemy->flag [FLAG_HIDDEN]) 1884 if (enemy->flag [FLAG_HIDDEN])
1891 { 1885 {
1892 make_visible (enemy); 1886 make_visible (enemy);
1893 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!");
1917 * we care about the enemy maps status, not the looker. 1911 * we care about the enemy maps status, not the looker.
1918 * only relevant for tiled maps, but it is possible that the 1912 * only relevant for tiled maps, but it is possible that the
1919 * 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
1920 * case, the looker can still see the enemy 1914 * case, the looker can still see the enemy
1921 */ 1915 */
1922 if (enemy->map->darklevel () > 0
1923 && !stand_in_light (enemy) 1916 if (!stand_in_light (enemy)
1924 && (!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)))
1925 return 0; 1918 return 0;
1926 1919
1927 return 1; 1920 return 1;
1928} 1921}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines