… | |
… | |
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> |
… | |
… | |
35 | * set to sane values. |
36 | * set to sane values. |
36 | */ |
37 | */ |
37 | object * |
38 | object * |
38 | check_enemy (object *npc, rv_vector * rv) |
39 | check_enemy (object *npc, rv_vector * rv) |
39 | { |
40 | { |
40 | |
|
|
41 | /* if this is pet, let him attack the same enemy as his owner |
41 | /* 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, |
42 | * TODO: when there is no ower enemy, try to find a target, |
43 | * which CAN attack the owner. */ |
43 | * which CAN attack the owner. */ |
44 | if ((npc->attack_movement & HI4) == PETMOVE) |
44 | if ((npc->attack_movement & HI4) == PETMOVE) |
45 | { |
45 | { |
… | |
… | |
47 | npc->enemy = NULL; |
47 | npc->enemy = NULL; |
48 | else if (npc->enemy == NULL) |
48 | else if (npc->enemy == NULL) |
49 | npc->enemy = npc->owner->enemy; |
49 | npc->enemy = npc->owner->enemy; |
50 | } |
50 | } |
51 | |
51 | |
52 | /* periodically, a monster mayu change its target. Also, if the object |
52 | /* periodically, a monster may change its target. Also, if the object |
53 | * has been destroyed, etc, clear the enemy. |
53 | * has been destroyed, etc, clear the enemy. |
54 | * 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 |
55 | * attacked monsters to leave the attacker alone, before it is destroyed |
55 | * attacked monsters to leave the attacker alone, before it is destroyed |
56 | */ |
56 | */ |
57 | /* 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 |
58 | * 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 |
59 | * again then but perhaps get attack on and on |
59 | * again then but perhaps get attack on and on |
60 | * 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 |
61 | * too. */ |
61 | * too. */ |
62 | |
62 | |
… | |
… | |
66 | * the grouping checks are. Code is the same. |
66 | * the grouping checks are. Code is the same. |
67 | */ |
67 | */ |
68 | if (QUERY_FLAG (npc->enemy, FLAG_REMOVED) || |
68 | if (QUERY_FLAG (npc->enemy, FLAG_REMOVED) || |
69 | QUERY_FLAG (npc->enemy, FLAG_FREED) || |
69 | QUERY_FLAG (npc->enemy, FLAG_FREED) || |
70 | !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)) |
71 | npc->enemy = NULL; |
71 | npc->enemy = 0; |
72 | |
72 | |
73 | 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) |
74 | && !(should_arena_attack (npc, npc->owner, npc->enemy))) |
74 | && !(should_arena_attack (npc, npc->owner, npc->enemy))) |
75 | || ((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))) |
76 | || npc->enemy == npc->owner)) |
76 | || npc->enemy == npc->owner)) |
77 | npc->enemy = NULL; |
77 | npc->enemy = 0; |
78 | |
78 | |
79 | |
79 | |
80 | 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)) |
81 | npc->enemy = NULL; |
81 | npc->enemy = 0; |
82 | |
82 | |
83 | /* 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 |
84 | * target enemy - this code below makes sure the enemy is something |
84 | * target enemy - this code below makes sure the enemy is something |
85 | * that should be attacked. My guess is that the arrow hits |
85 | * that should be attacked. My guess is that the arrow hits |
86 | * the creature/owner, and so the creature then takes that |
86 | * the creature/owner, and so the creature then takes that |
… | |
… | |
88 | */ |
88 | */ |
89 | else if (!QUERY_FLAG (npc->enemy, FLAG_MONSTER) |
89 | else if (!QUERY_FLAG (npc->enemy, FLAG_MONSTER) |
90 | && !QUERY_FLAG (npc->enemy, FLAG_GENERATOR) |
90 | && !QUERY_FLAG (npc->enemy, FLAG_GENERATOR) |
91 | && npc->enemy->type != PLAYER |
91 | && npc->enemy->type != PLAYER |
92 | && npc->enemy->type != GOLEM) |
92 | && npc->enemy->type != GOLEM) |
93 | npc->enemy = NULL; |
93 | npc->enemy = 0; |
94 | |
|
|
95 | } |
94 | } |
96 | |
95 | |
97 | return can_detect_enemy (npc, npc->enemy, rv) ? npc->enemy : NULL; |
96 | return can_detect_enemy (npc, npc->enemy, rv) ? npc->enemy : 0; |
98 | } |
97 | } |
99 | |
98 | |
100 | /* Returns the nearest living creature (monster or generator). |
99 | /* Returns the nearest living creature (monster or generator). |
101 | * Modified to deal with tiled maps properly. |
100 | * Modified to deal with tiled maps properly. |
102 | * 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 |
… | |
… | |
237 | { |
236 | { |
238 | /* Trim work - if no enemy, no need to do anything below */ |
237 | /* Trim work - if no enemy, no need to do anything below */ |
239 | if (!enemy) |
238 | if (!enemy) |
240 | return 0; |
239 | return 0; |
241 | |
240 | |
|
|
241 | if (!op->flag [FLAG_SLEEP]) |
|
|
242 | return 1; |
|
|
243 | |
242 | int radius = max (op->stats.Wis, MIN_MON_RADIUS); |
244 | int radius = max (op->stats.Wis, MIN_MON_RADIUS); |
243 | |
245 | |
244 | if (op->flag [FLAG_BLIND]) |
246 | if (op->flag [FLAG_BLIND]) |
245 | /* blinded monsters can only find nearby objects to attack */ |
247 | /* blinded monsters can only find nearby objects to attack */ |
246 | radius = MIN_MON_RADIUS; |
248 | radius = MIN_MON_RADIUS; |
… | |
… | |
252 | * 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 |
253 | * glowing!) then the monster has trouble finding the enemy. |
255 | * glowing!) then the monster has trouble finding the enemy. |
254 | * 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 |
255 | * the dark. */ |
257 | * the dark. */ |
256 | radius = min (radius, MIN_MON_RADIUS + MAX_DARKNESS - op->map->darklevel ()); |
258 | radius = min (radius, MIN_MON_RADIUS + MAX_DARKNESS - op->map->darklevel ()); |
257 | else if (!op->flag [FLAG_SLEEP]) |
|
|
258 | return 1; |
|
|
259 | |
259 | |
260 | if (enemy->flag [FLAG_STEALTH]) |
260 | if (enemy->flag [FLAG_STEALTH]) |
261 | radius = radius / 2 + 1; |
261 | radius = radius / 2 + 1; |
262 | |
262 | |
263 | /* 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 |
… | |
… | |
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. ) |
… | |
… | |
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; |
… | |
… | |
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 && 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 | } |
… | |
… | |
663 | return 1; |
706 | return 1; |
664 | |
707 | |
665 | /* 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 |
666 | * 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 |
667 | */ |
710 | */ |
668 | for (more = ob2->more; more != NULL; more = more->more) |
711 | for (more = ob2->more; more; more = more->more) |
669 | { |
712 | { |
670 | get_rangevector (ob1, more, &rv1, 0); |
713 | get_rangevector (ob1, more, &rv1, 0); |
671 | if (abs (rv1.distance_x) < 2 && abs (rv1.distance_y) < 2) |
714 | if (abs (rv1.distance_x) < 2 && abs (rv1.distance_y) < 2) |
672 | return 1; |
715 | return 1; |
673 | } |
716 | } |
… | |
… | |
1154 | flag = 1; |
1197 | flag = 1; |
1155 | |
1198 | |
1156 | else |
1199 | else |
1157 | switch (item->type) |
1200 | switch (item->type) |
1158 | { |
1201 | { |
1159 | case MONEY: |
1202 | case MONEY: |
1160 | case GEM: |
1203 | case GEM: |
1161 | flag = monster->pick_up & 2; |
1204 | flag = monster->pick_up & 2; |
1162 | break; |
1205 | break; |
1163 | |
1206 | |
1164 | case FOOD: |
1207 | case FOOD: |
1165 | flag = monster->pick_up & 4; |
1208 | flag = monster->pick_up & 4; |
1166 | break; |
1209 | break; |
1167 | |
1210 | |
1168 | case WEAPON: |
1211 | case WEAPON: |
1169 | flag = (monster->pick_up & 8) || QUERY_FLAG (monster, FLAG_USE_WEAPON); |
1212 | flag = (monster->pick_up & 8) || QUERY_FLAG (monster, FLAG_USE_WEAPON); |
1170 | break; |
1213 | break; |
1171 | |
1214 | |
1172 | case ARMOUR: |
1215 | case ARMOUR: |
1173 | case SHIELD: |
1216 | case SHIELD: |
1174 | case HELMET: |
1217 | case HELMET: |
1175 | case BOOTS: |
1218 | case BOOTS: |
1176 | case GLOVES: |
1219 | case GLOVES: |
1177 | case GIRDLE: |
1220 | case GIRDLE: |
1178 | flag = (monster->pick_up & 16) || QUERY_FLAG (monster, FLAG_USE_ARMOUR); |
1221 | flag = (monster->pick_up & 16) || QUERY_FLAG (monster, FLAG_USE_ARMOUR); |
1179 | break; |
1222 | break; |
1180 | |
1223 | |
1181 | case SKILL: |
1224 | case SKILL: |
1182 | flag = QUERY_FLAG (monster, FLAG_CAN_USE_SKILL); |
1225 | flag = QUERY_FLAG (monster, FLAG_CAN_USE_SKILL); |
1183 | break; |
1226 | break; |
1184 | |
1227 | |
1185 | case RING: |
1228 | case RING: |
1186 | flag = QUERY_FLAG (monster, FLAG_USE_RING); |
1229 | flag = QUERY_FLAG (monster, FLAG_USE_RING); |
1187 | break; |
1230 | break; |
1188 | |
1231 | |
1189 | case WAND: |
1232 | case WAND: |
1190 | case HORN: |
1233 | case HORN: |
1191 | case ROD: |
1234 | case ROD: |
1192 | flag = QUERY_FLAG (monster, FLAG_USE_RANGE); |
1235 | flag = QUERY_FLAG (monster, FLAG_USE_RANGE); |
1193 | break; |
1236 | break; |
1194 | |
1237 | |
1195 | case SPELLBOOK: |
1238 | case SPELLBOOK: |
1196 | flag = monster->arch && QUERY_FLAG (monster->arch, FLAG_CAST_SPELL); |
1239 | flag = monster->arch && QUERY_FLAG (monster->arch, FLAG_CAST_SPELL); |
1197 | break; |
1240 | break; |
1198 | |
1241 | |
1199 | case SCROLL: |
1242 | case SCROLL: |
1200 | flag = QUERY_FLAG (monster, FLAG_USE_SCROLL); |
1243 | flag = QUERY_FLAG (monster, FLAG_USE_SCROLL); |
1201 | break; |
1244 | break; |
1202 | |
1245 | |
1203 | case BOW: |
1246 | case BOW: |
1204 | case ARROW: |
1247 | case ARROW: |
1205 | flag = QUERY_FLAG (monster, FLAG_USE_BOW); |
1248 | flag = QUERY_FLAG (monster, FLAG_USE_BOW); |
1206 | break; |
1249 | break; |
1207 | } |
1250 | } |
1208 | |
1251 | |
1209 | /* 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 |
1210 | * 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 |
1211 | * use several locations. |
1254 | * use several locations. |
… | |
… | |
1239 | for (tmp = monster->below; tmp != NULL; tmp = next) |
1282 | for (tmp = monster->below; tmp != NULL; tmp = next) |
1240 | { |
1283 | { |
1241 | next = tmp->below; |
1284 | next = tmp->below; |
1242 | switch (tmp->type) |
1285 | switch (tmp->type) |
1243 | { |
1286 | { |
1244 | case CF_HANDLE: |
1287 | case T_HANDLE: |
1245 | case TRIGGER: |
1288 | case TRIGGER: |
1246 | if (monster->will_apply & 1) |
1289 | if (monster->will_apply & 1) |
1247 | manual_apply (monster, tmp, 0); |
1290 | manual_apply (monster, tmp, 0); |
1248 | break; |
1291 | break; |
1249 | |
1292 | |
… | |
… | |
1377 | } |
1420 | } |
1378 | |
1421 | |
1379 | void |
1422 | void |
1380 | npc_call_help (object *op) |
1423 | npc_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 | |
1404 | int |
1439 | int |
1405 | dist_att (int dir, object *ob, object *enemy, object *part, rv_vector * rv) |
1440 | dist_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 | |
1418 | int |
1453 | int |
1419 | run_att (int dir, object *ob, object *enemy, object *part, rv_vector * rv) |
1454 | run_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 | |
1432 | int |
1462 | int |
1433 | hitrun_att (int dir, object *ob, object *enemy) |
1463 | hitrun_att (int dir, object *ob, object *enemy) |
1434 | { |
1464 | { |
… | |
… | |
1443 | } |
1473 | } |
1444 | |
1474 | |
1445 | int |
1475 | int |
1446 | wait_att (int dir, object *ob, object *enemy, object *part, rv_vector * rv) |
1476 | wait_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 | |
1465 | int |
1494 | int |
1466 | disthit_att (int dir, object *ob, object *enemy, object *part, rv_vector * rv) |
1495 | disthit_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 |
1474 | * server should try to be resilant enough to avoid the problem |
1502 | * server should try to be resilant enough to avoid the problem |
1475 | */ |
1503 | */ |
1476 | 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) |
1477 | return absdir (dir + 4); |
1505 | return absdir (dir + 4); |
1478 | |
1506 | |
1479 | return dist_att (dir, ob, enemy, part, rv); |
1507 | return dist_att (dir, ob, enemy, part, rv); |
1480 | } |
1508 | } |
1481 | |
1509 | |
… | |
… | |
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 | */ |
1649 | int |
1677 | int |
1650 | can_detect_enemy (object *op, object *enemy, rv_vector * rv) |
1678 | can_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->darklevel () > 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)) |
… | |
… | |
1729 | radius -= op->map->darklevel () / 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->darklevel () < 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 | */ |
1796 | int |
1824 | int |
1797 | stand_in_light (object *op) |
1825 | stand_in_light (object *op) |
1798 | { |
1826 | { |
1799 | if (op) |
1827 | if (op) |
1800 | { |
1828 | { |
|
|
1829 | if (!op->is_on_map ()) |
|
|
1830 | return 0; |
|
|
1831 | |
|
|
1832 | if (op->map->darklevel () <= 0) |
|
|
1833 | return 1; |
|
|
1834 | |
1801 | if (op->glow_radius > 0) |
1835 | if (op->glow_radius > 0) |
1802 | return 1; |
1836 | return 1; |
1803 | |
1837 | |
1804 | if (op->map) |
1838 | if (op->map) |
1805 | 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) |
… | |
… | |
1843 | { |
1877 | { |
1844 | /* HIDDEN ENEMY. by definition, you can't see hidden stuff! |
1878 | /* HIDDEN ENEMY. by definition, you can't see hidden stuff! |
1845 | * However,if you carry any source of light, then the hidden |
1879 | * However,if you carry any source of light, then the hidden |
1846 | * creature is seeable (and stupid) */ |
1880 | * creature is seeable (and stupid) */ |
1847 | |
1881 | |
1848 | if (has_carried_lights (enemy)) |
1882 | if (enemy->has_carried_lights ()) |
1849 | { |
1883 | { |
1850 | if (enemy->flag [FLAG_HIDDEN]) |
1884 | if (enemy->flag [FLAG_HIDDEN]) |
1851 | { |
1885 | { |
1852 | make_visible (enemy); |
1886 | make_visible (enemy); |
1853 | 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 | */ |
1898 | */ |
1865 | if (!QUERY_FLAG (looker, FLAG_SEE_INVISIBLE)) |
1899 | if (!QUERY_FLAG (looker, FLAG_SEE_INVISIBLE)) |
1866 | if (makes_invisible_to (enemy, looker)) |
1900 | if (makes_invisible_to (enemy, looker)) |
1867 | return 0; |
1901 | return 0; |
1868 | } |
1902 | } |
1869 | else if (looker->type == PLAYER) /* for players, a (possible) shortcut */ |
1903 | else if (looker->is_player ()) /* for players, a (possible) shortcut */ |
1870 | if (player_can_view (looker, enemy)) |
1904 | if (player_can_view (looker, enemy)) |
1871 | return 1; |
1905 | return 1; |
1872 | |
1906 | |
1873 | /* ENEMY IN DARK MAP. Without infravision, the enemy is not seen |
1907 | /* ENEMY IN DARK MAP. Without infravision, the enemy is not seen |
1874 | * unless they carry a light or stand in light. Darkness doesnt |
1908 | * unless they carry a light or stand in light. Darkness doesnt |
… | |
… | |
1877 | * we care about the enemy maps status, not the looker. |
1911 | * we care about the enemy maps status, not the looker. |
1878 | * only relevant for tiled maps, but it is possible that the |
1912 | * only relevant for tiled maps, but it is possible that the |
1879 | * 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 |
1880 | * case, the looker can still see the enemy |
1914 | * case, the looker can still see the enemy |
1881 | */ |
1915 | */ |
1882 | if (enemy->map->darklevel () > 0 |
|
|
1883 | && !stand_in_light (enemy) |
1916 | if (!stand_in_light (enemy) |
1884 | && (!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))) |
1885 | return 0; |
1918 | return 0; |
1886 | |
1919 | |
1887 | return 1; |
1920 | return 1; |
1888 | } |
1921 | } |