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