… | |
… | |
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 |
|
|
513 | // if the enemy is a player, we have los. if los says we |
512 | // if the enemy is a player, we have los. if los says we |
514 | // can directly reach the player, we do not deviate. |
513 | // can directly reach the player, we do not deviate. |
515 | // for non-players, we never deviate |
514 | // for non-players, we never deviate |
|
|
515 | if (op->stats.Wis >= 8 |
516 | if (enemy->contr && enemy->contr->darkness_at (op->map, op->x, op->y) == LOS_BLOCKED) |
516 | && enemy->contr && enemy->contr->darkness_at (op->map, op->x, op->y) == LOS_BLOCKED) |
517 | { |
517 | { |
518 | int sdir = 0; |
518 | int sdir = 0; |
|
|
519 | uint32_t &smell = op->ms ().smell; |
519 | |
520 | |
520 | for (int dir = 1; dir <= 8; ++dir) |
521 | for (int ndir = 1; ndir <= 8; ++ndir) |
521 | { |
522 | { |
522 | mapxy pos (op); pos.move (dir); |
523 | mapxy pos (op); pos.move (ndir); |
|
|
524 | |
523 | if (pos.normalise ()) |
525 | if (pos.normalise ()) |
524 | { |
526 | { |
525 | mapspace &ms = pos.ms (); |
527 | mapspace &ms = pos.ms (); |
526 | |
528 | |
527 | if (ms.smell > op->ms ().smell) |
529 | if (ms.smell > smell) |
528 | { |
530 | { |
529 | 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 |
530 | op->ms ().smell = ms.smell - 1; |
532 | if (op->stats.Wis >= 10) |
|
|
533 | smell = ms.smell - 1; // smarter: tell others |
|
|
534 | |
531 | sdir = dir; |
535 | sdir = ndir; |
532 | |
536 | |
533 | // perturbing the path might let the monster lose track, |
537 | // perturbing the path might let the monster lose track, |
534 | // but it will also wide the actual path, spreading information |
538 | // but it will also widen the actual path, spreading information |
535 | if (!rndm (20)) |
539 | if (op->stats.Wis >= 15 && !rndm (20)) // even smarter, deviate and spread? |
536 | sdir += absdir (1 - rndm (2) * 2); |
540 | sdir = absdir (sdir + 1 - rndm (2) * 2); |
537 | } |
541 | } |
538 | } |
542 | } |
539 | } |
543 | } |
540 | |
544 | |
541 | if (sdir) |
545 | if (sdir) |
542 | dir = sdir; |
546 | dir = sdir; |
543 | else |
547 | else if (smell) |
|
|
548 | { |
544 | // 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 |
545 | {if (op->ms ().smell) printf ("erasing smell %d\n", op->ms ().smell);//D |
550 | //printf ("erasing smell %d\n", op->ms ().smell);//D |
546 | ordered_mapwalk_begin (op, -1, -1, 1, 1) |
551 | unordered_mapwalk (op, -1, -1, 1, 1) |
547 | if (m) |
|
|
548 | m->at (nx, ny).smell = 0; |
552 | m->at (nx, ny).smell = 0; |
549 | ordered_mapwalk_end |
|
|
550 | }//D |
553 | } |
551 | } |
554 | } |
552 | |
|
|
553 | #endif |
|
|
554 | |
555 | |
555 | 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)) |
556 | dir = absdir (dir + 4); |
557 | dir = absdir (dir + 4); |
557 | |
558 | |
558 | if (QUERY_FLAG (op, FLAG_CONFUSED)) |
559 | if (QUERY_FLAG (op, FLAG_CONFUSED)) |
… | |
… | |
704 | return 1; |
705 | return 1; |
705 | |
706 | |
706 | /* 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 |
707 | * 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 |
708 | */ |
709 | */ |
709 | for (more = ob2->more; more != NULL; more = more->more) |
710 | for (more = ob2->more; more; more = more->more) |
710 | { |
711 | { |
711 | get_rangevector (ob1, more, &rv1, 0); |
712 | get_rangevector (ob1, more, &rv1, 0); |
712 | if (abs (rv1.distance_x) < 2 && abs (rv1.distance_y) < 2) |
713 | if (abs (rv1.distance_x) < 2 && abs (rv1.distance_y) < 2) |
713 | return 1; |
714 | return 1; |
714 | } |
715 | } |
… | |
… | |
1195 | flag = 1; |
1196 | flag = 1; |
1196 | |
1197 | |
1197 | else |
1198 | else |
1198 | switch (item->type) |
1199 | switch (item->type) |
1199 | { |
1200 | { |
1200 | case MONEY: |
1201 | case MONEY: |
1201 | case GEM: |
1202 | case GEM: |
1202 | flag = monster->pick_up & 2; |
1203 | flag = monster->pick_up & 2; |
1203 | break; |
1204 | break; |
1204 | |
1205 | |
1205 | case FOOD: |
1206 | case FOOD: |
1206 | flag = monster->pick_up & 4; |
1207 | flag = monster->pick_up & 4; |
1207 | break; |
1208 | break; |
1208 | |
1209 | |
1209 | case WEAPON: |
1210 | case WEAPON: |
1210 | flag = (monster->pick_up & 8) || QUERY_FLAG (monster, FLAG_USE_WEAPON); |
1211 | flag = (monster->pick_up & 8) || QUERY_FLAG (monster, FLAG_USE_WEAPON); |
1211 | break; |
1212 | break; |
1212 | |
1213 | |
1213 | case ARMOUR: |
1214 | case ARMOUR: |
1214 | case SHIELD: |
1215 | case SHIELD: |
1215 | case HELMET: |
1216 | case HELMET: |
1216 | case BOOTS: |
1217 | case BOOTS: |
1217 | case GLOVES: |
1218 | case GLOVES: |
1218 | case GIRDLE: |
1219 | case GIRDLE: |
1219 | flag = (monster->pick_up & 16) || QUERY_FLAG (monster, FLAG_USE_ARMOUR); |
1220 | flag = (monster->pick_up & 16) || QUERY_FLAG (monster, FLAG_USE_ARMOUR); |
1220 | break; |
1221 | break; |
1221 | |
1222 | |
1222 | case SKILL: |
1223 | case SKILL: |
1223 | flag = QUERY_FLAG (monster, FLAG_CAN_USE_SKILL); |
1224 | flag = QUERY_FLAG (monster, FLAG_CAN_USE_SKILL); |
1224 | break; |
1225 | break; |
1225 | |
1226 | |
1226 | case RING: |
1227 | case RING: |
1227 | flag = QUERY_FLAG (monster, FLAG_USE_RING); |
1228 | flag = QUERY_FLAG (monster, FLAG_USE_RING); |
1228 | break; |
1229 | break; |
1229 | |
1230 | |
1230 | case WAND: |
1231 | case WAND: |
1231 | case HORN: |
1232 | case HORN: |
1232 | case ROD: |
1233 | case ROD: |
1233 | flag = QUERY_FLAG (monster, FLAG_USE_RANGE); |
1234 | flag = QUERY_FLAG (monster, FLAG_USE_RANGE); |
1234 | break; |
1235 | break; |
1235 | |
1236 | |
1236 | case SPELLBOOK: |
1237 | case SPELLBOOK: |
1237 | flag = monster->arch && QUERY_FLAG (monster->arch, FLAG_CAST_SPELL); |
1238 | flag = monster->arch && QUERY_FLAG (monster->arch, FLAG_CAST_SPELL); |
1238 | break; |
1239 | break; |
1239 | |
1240 | |
1240 | case SCROLL: |
1241 | case SCROLL: |
1241 | flag = QUERY_FLAG (monster, FLAG_USE_SCROLL); |
1242 | flag = QUERY_FLAG (monster, FLAG_USE_SCROLL); |
1242 | break; |
1243 | break; |
1243 | |
1244 | |
1244 | case BOW: |
1245 | case BOW: |
1245 | case ARROW: |
1246 | case ARROW: |
1246 | flag = QUERY_FLAG (monster, FLAG_USE_BOW); |
1247 | flag = QUERY_FLAG (monster, FLAG_USE_BOW); |
1247 | break; |
1248 | break; |
1248 | } |
1249 | } |
1249 | |
1250 | |
1250 | /* 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 |
1251 | * 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 |
1252 | * use several locations. |
1253 | * use several locations. |
… | |
… | |
1418 | } |
1419 | } |
1419 | |
1420 | |
1420 | void |
1421 | void |
1421 | npc_call_help (object *op) |
1422 | npc_call_help (object *op) |
1422 | { |
1423 | { |
1423 | int x, y, mflags; |
1424 | unordered_mapwalk (op, -7, -7, 7, 7) |
1424 | object *npc; |
|
|
1425 | sint16 sx, sy; |
|
|
1426 | maptile *m; |
|
|
1427 | |
|
|
1428 | for (x = -3; x < 4; x++) |
|
|
1429 | for (y = -3; y < 4; y++) |
|
|
1430 | { |
1425 | { |
1431 | m = op->map; |
1426 | mapspace &ms = m->at (nx, ny); |
1432 | sx = op->x + x; |
1427 | |
1433 | sy = op->y + y; |
|
|
1434 | mflags = get_map_flags (m, &m, sx, sy, &sx, &sy); |
|
|
1435 | /* 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. */ |
1436 | if ((mflags & P_OUT_OF_MAP) || !(mflags & P_IS_ALIVE)) |
1429 | if (!(ms.flags () & P_IS_ALIVE)) |
1437 | continue; |
1430 | continue; |
1438 | |
1431 | |
1439 | for (npc = GET_MAP_OB (m, sx, sy); npc != NULL; npc = npc->above) |
1432 | for (object *npc = ms.bot; npc; npc = npc->above) |
1440 | if (QUERY_FLAG (npc, FLAG_ALIVE) && QUERY_FLAG (npc, FLAG_UNAGGRESSIVE)) |
1433 | if (QUERY_FLAG (npc, FLAG_ALIVE) && QUERY_FLAG (npc, FLAG_UNAGGRESSIVE)) |
1441 | npc->enemy = op->enemy; |
1434 | npc->enemy = op->enemy; |
1442 | } |
1435 | } |
1443 | } |
1436 | } |
1444 | |
1437 | |
1445 | int |
1438 | int |
1446 | dist_att (int dir, object *ob, object *enemy, object *part, rv_vector * rv) |
1439 | dist_att (int dir, object *ob, object *enemy, object *part, rv_vector *rv) |
1447 | { |
1440 | { |
1448 | if (can_hit (part, enemy, rv)) |
1441 | if (can_hit (part, enemy, rv)) |
1449 | return dir; |
1442 | return dir; |
1450 | |
1443 | |
1451 | if (rv->distance < 10) |
1444 | if (rv->distance < 10) |
… | |
… | |
1455 | |
1448 | |
1456 | return 0; |
1449 | return 0; |
1457 | } |
1450 | } |
1458 | |
1451 | |
1459 | int |
1452 | int |
1460 | run_att (int dir, object *ob, object *enemy, object *part, rv_vector * rv) |
1453 | run_att (int dir, object *ob, object *enemy, object *part, rv_vector *rv) |
1461 | { |
1454 | { |
1462 | if ((can_hit (part, enemy, rv) && ob->move_status < 20) || ob->move_status < 20) |
1455 | if (can_hit (part, enemy, rv)) |
1463 | { |
|
|
1464 | ob->move_status++; |
|
|
1465 | return (dir); |
1456 | return dir; |
1466 | } |
1457 | else |
1467 | else if (ob->move_status > 20) |
|
|
1468 | ob->move_status = 0; |
|
|
1469 | |
|
|
1470 | return absdir (dir + 4); |
1458 | return absdir (dir + 4); |
1471 | } |
1459 | } |
1472 | |
1460 | |
1473 | int |
1461 | int |
1474 | hitrun_att (int dir, object *ob, object *enemy) |
1462 | hitrun_att (int dir, object *ob, object *enemy) |
1475 | { |
1463 | { |
… | |
… | |
1484 | } |
1472 | } |
1485 | |
1473 | |
1486 | int |
1474 | int |
1487 | wait_att (int dir, object *ob, object *enemy, object *part, rv_vector * rv) |
1475 | wait_att (int dir, object *ob, object *enemy, object *part, rv_vector * rv) |
1488 | { |
1476 | { |
1489 | |
|
|
1490 | int inrange = can_hit (part, enemy, rv); |
1477 | int inrange = can_hit (part, enemy, rv); |
1491 | |
1478 | |
1492 | if (ob->move_status || inrange) |
1479 | if (ob->move_status || inrange) |
1493 | ob->move_status++; |
1480 | ob->move_status++; |
1494 | |
1481 | |
… | |
… | |
1504 | } |
1491 | } |
1505 | |
1492 | |
1506 | int |
1493 | int |
1507 | disthit_att (int dir, object *ob, object *enemy, object *part, rv_vector * rv) |
1494 | disthit_att (int dir, object *ob, object *enemy, object *part, rv_vector * rv) |
1508 | { |
1495 | { |
1509 | |
|
|
1510 | /* The logic below here looked plain wrong before. Basically, what should |
1496 | /* The logic below here looked plain wrong before. Basically, what should |
1511 | * 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, |
1512 | * the creature should run away (dir+4) |
1498 | * the creature should run away (dir+4) |
1513 | * 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 |
1514 | * 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 |
1515 | * server should try to be resilant enough to avoid the problem |
1501 | * server should try to be resilant enough to avoid the problem |
1516 | */ |
1502 | */ |
1517 | 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) |
1518 | return absdir (dir + 4); |
1504 | return absdir (dir + 4); |
1519 | |
1505 | |
1520 | return dist_att (dir, ob, enemy, part, rv); |
1506 | return dist_att (dir, ob, enemy, part, rv); |
1521 | } |
1507 | } |
1522 | |
1508 | |
… | |
… | |
1688 | * 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 |
1689 | */ |
1675 | */ |
1690 | int |
1676 | int |
1691 | can_detect_enemy (object *op, object *enemy, rv_vector * rv) |
1677 | can_detect_enemy (object *op, object *enemy, rv_vector * rv) |
1692 | { |
1678 | { |
1693 | int radius = MIN_MON_RADIUS, hide_discovery; |
|
|
1694 | |
|
|
1695 | /* null detection for any of these condtions always */ |
1679 | /* null detection for any of these condtions always */ |
1696 | if (!op || !enemy || !op->map || !enemy->map) |
1680 | if (!op || !enemy || !op->map || !enemy->map) |
1697 | return 0; |
1681 | return 0; |
1698 | |
1682 | |
1699 | /* 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 */ |
… | |
… | |
1701 | return 0; |
1685 | return 0; |
1702 | |
1686 | |
1703 | get_rangevector (op, enemy, rv, 0); |
1687 | get_rangevector (op, enemy, rv, 0); |
1704 | |
1688 | |
1705 | /* Monsters always ignore the DM */ |
1689 | /* Monsters always ignore the DM */ |
1706 | if (op->type != PLAYER && QUERY_FLAG (enemy, FLAG_WIZ)) |
1690 | if (!op->is_player () && QUERY_FLAG (enemy, FLAG_WIZ)) |
1707 | return 0; |
1691 | return 0; |
1708 | |
1692 | |
1709 | /* simple check. Should probably put some range checks in here. */ |
1693 | /* simple check. Should probably put some range checks in here. */ |
1710 | if (can_see_enemy (op, enemy)) |
1694 | if (can_see_enemy (op, enemy)) |
1711 | return 1; |
1695 | return 1; |
1712 | |
1696 | |
1713 | /* 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 |
1714 | * finding enemies! |
1698 | * finding enemies! |
1715 | */ |
1699 | */ |
1716 | if (op->type == PLAYER) |
1700 | if (op->is_player ()) |
1717 | return 0; |
1701 | return 0; |
1718 | |
1702 | |
1719 | /* Quality invisible? Bah, we wont see them w/o SEE_INVISIBLE |
1703 | /* 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 |
1704 | * flag (which was already checked) in can_see_enemy (). Lets get out of here |
1721 | */ |
1705 | */ |
1722 | 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))) |
1723 | return 0; |
1707 | return 0; |
1724 | |
1708 | |
|
|
1709 | int radius = MIN_MON_RADIUS; |
|
|
1710 | |
1725 | /* use this for invis also */ |
1711 | /* use this for invis also */ |
1726 | hide_discovery = op->stats.Int / 5; |
1712 | int hide_discovery = op->stats.Int / 5; |
1727 | |
1713 | |
1728 | /* Determine Detection radii */ |
1714 | /* Determine Detection radii */ |
1729 | 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) */ |
1730 | radius = max (MIN_MON_RADIUS, op->stats.Wis / 5 + 1); |
1716 | radius = max (MIN_MON_RADIUS, op->stats.Wis / 3 + 1); |
1731 | else |
1717 | else |
1732 | { /* a level/INT/Dex adjustment for hiding */ |
1718 | { /* a level/INT/Dex adjustment for hiding */ |
1733 | int bonus = op->level / 2 + op->stats.Int / 5; |
1719 | int bonus = op->level / 2 + op->stats.Int / 5; |
1734 | |
1720 | |
1735 | if (enemy->is_player ()) |
1721 | if (enemy->is_player ()) |
… | |
… | |
1757 | radius /= 2; |
1743 | radius /= 2; |
1758 | hide_discovery /= 3; |
1744 | hide_discovery /= 3; |
1759 | } |
1745 | } |
1760 | |
1746 | |
1761 | /* Radii adjustment for enemy standing in the dark */ |
1747 | /* Radii adjustment for enemy standing in the dark */ |
1762 | if (op->map->darklevel () > 0 && !stand_in_light (enemy)) |
1748 | if (!stand_in_light (enemy)) |
1763 | { |
1749 | { |
1764 | /* on dark maps body heat can help indicate location with infravision |
1750 | /* on dark maps body heat can help indicate location with infravision |
1765 | * undead don't have body heat, so no benefit detecting them. |
1751 | * undead don't have body heat, so no benefit detecting them. |
1766 | */ |
1752 | */ |
1767 | 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)) |
… | |
… | |
1770 | radius -= op->map->darklevel () / 2; |
1756 | radius -= op->map->darklevel () / 2; |
1771 | |
1757 | |
1772 | /* op next to a monster (and not in complete darkness) |
1758 | /* op next to a monster (and not in complete darkness) |
1773 | * the monster should have a chance to see you. |
1759 | * the monster should have a chance to see you. |
1774 | */ |
1760 | */ |
1775 | 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) |
1776 | radius = MIN_MON_RADIUS; |
1762 | radius = MIN_MON_RADIUS; |
1777 | } /* if on dark map */ |
1763 | } /* if on dark map */ |
1778 | |
1764 | |
1779 | /* Lets not worry about monsters that have incredible detection |
1765 | /* Lets not worry about monsters that have incredible detection |
1780 | * 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 |
… | |
… | |
1828 | /* Wasn't detected above, so still hidden */ |
1814 | /* Wasn't detected above, so still hidden */ |
1829 | return 0; |
1815 | return 0; |
1830 | } |
1816 | } |
1831 | |
1817 | |
1832 | /* 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 |
1833 | * intellegent algorithm. For one thing, we ignore los here, SO it |
1819 | * intelligent algorithm. For one thing, we ignore los here, SO it |
1834 | * 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 |
1835 | * other side of a wall (!). |
1821 | * other side of a wall (!). |
1836 | */ |
1822 | */ |
1837 | int |
1823 | int |
1838 | stand_in_light (object *op) |
1824 | stand_in_light (object *op) |
1839 | { |
1825 | { |
1840 | if (op) |
1826 | if (op) |
1841 | { |
1827 | { |
|
|
1828 | if (!op->is_on_map ()) |
|
|
1829 | return 0; |
|
|
1830 | |
|
|
1831 | if (op->map->darklevel () <= 0) |
|
|
1832 | return 1; |
|
|
1833 | |
1842 | if (op->glow_radius > 0) |
1834 | if (op->glow_radius > 0) |
1843 | return 1; |
1835 | return 1; |
1844 | |
1836 | |
1845 | if (op->map) |
1837 | if (op->map) |
1846 | 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) |
… | |
… | |
1884 | { |
1876 | { |
1885 | /* HIDDEN ENEMY. by definition, you can't see hidden stuff! |
1877 | /* HIDDEN ENEMY. by definition, you can't see hidden stuff! |
1886 | * However,if you carry any source of light, then the hidden |
1878 | * However,if you carry any source of light, then the hidden |
1887 | * creature is seeable (and stupid) */ |
1879 | * creature is seeable (and stupid) */ |
1888 | |
1880 | |
1889 | if (has_carried_lights (enemy)) |
1881 | if (enemy->has_carried_lights ()) |
1890 | { |
1882 | { |
1891 | if (enemy->flag [FLAG_HIDDEN]) |
1883 | if (enemy->flag [FLAG_HIDDEN]) |
1892 | { |
1884 | { |
1893 | make_visible (enemy); |
1885 | make_visible (enemy); |
1894 | 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!"); |
… | |
… | |
1918 | * we care about the enemy maps status, not the looker. |
1910 | * we care about the enemy maps status, not the looker. |
1919 | * only relevant for tiled maps, but it is possible that the |
1911 | * 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 |
1912 | * enemy is on a bright map and the looker on a dark - in that |
1921 | * case, the looker can still see the enemy |
1913 | * case, the looker can still see the enemy |
1922 | */ |
1914 | */ |
1923 | if (enemy->map->darklevel () > 0 |
|
|
1924 | && !stand_in_light (enemy) |
1915 | if (!stand_in_light (enemy) |
1925 | && (!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))) |
1926 | return 0; |
1917 | return 0; |
1927 | |
1918 | |
1928 | return 1; |
1919 | return 1; |
1929 | } |
1920 | } |