… | |
… | |
197 | /* we check our old enemy. */ |
197 | /* we check our old enemy. */ |
198 | if (!(tmp = check_enemy (npc, rv))) |
198 | if (!(tmp = check_enemy (npc, rv))) |
199 | { |
199 | { |
200 | if (attacker) /* if we have an attacker, check him */ |
200 | if (attacker) /* if we have an attacker, check him */ |
201 | { |
201 | { |
202 | /* TODO: thats not finished */ |
202 | /* TODO: that's not finished */ |
203 | /* we don't want a fight evil vs evil or good against non evil */ |
203 | /* we don't want a fight evil vs evil or good against non evil */ |
204 | |
204 | |
205 | if (QUERY_FLAG (npc, FLAG_NEUTRAL) || QUERY_FLAG (attacker, FLAG_NEUTRAL) || /* neutral */ |
205 | if (QUERY_FLAG (npc, FLAG_NEUTRAL) || QUERY_FLAG (attacker, FLAG_NEUTRAL) || /* neutral */ |
206 | (QUERY_FLAG (npc, FLAG_FRIENDLY) && QUERY_FLAG (attacker, FLAG_FRIENDLY)) || |
206 | (QUERY_FLAG (npc, FLAG_FRIENDLY) && QUERY_FLAG (attacker, FLAG_FRIENDLY)) || |
207 | (!QUERY_FLAG (npc, FLAG_FRIENDLY) && (!QUERY_FLAG (attacker, FLAG_FRIENDLY) && attacker->type != PLAYER))) |
207 | (!QUERY_FLAG (npc, FLAG_FRIENDLY) && (!QUERY_FLAG (attacker, FLAG_FRIENDLY) && attacker->type != PLAYER))) |
208 | CLEAR_FLAG (npc, FLAG_SLEEP); /* skip it, but lets wakeup */ |
208 | CLEAR_FLAG (npc, FLAG_SLEEP); /* skip it, but lets wakeup */ |
209 | else if (on_same_map (npc, attacker)) /* thats the only thing we must know... */ |
209 | else if (on_same_map (npc, attacker)) /* that's the only thing we must know... */ |
210 | { |
210 | { |
211 | CLEAR_FLAG (npc, FLAG_SLEEP); /* well, NOW we really should wake up! */ |
211 | CLEAR_FLAG (npc, FLAG_SLEEP); /* well, NOW we really should wake up! */ |
212 | npc->enemy = attacker; |
212 | npc->enemy = attacker; |
213 | return attacker; /* yes, we face our attacker! */ |
213 | return attacker; /* yes, we face our attacker! */ |
214 | } |
214 | } |
… | |
… | |
273 | } |
273 | } |
274 | |
274 | |
275 | int |
275 | int |
276 | move_randomly (object *op) |
276 | move_randomly (object *op) |
277 | { |
277 | { |
278 | int i; |
|
|
279 | |
|
|
280 | /* Give up to 15 chances for a monster to move randomly */ |
278 | /* Give up to 15 chances for a monster to move randomly */ |
281 | for (i = 0; i < 15; i++) |
279 | for (int i = 0; i < 15; i++) |
282 | { |
|
|
283 | if (move_object (op, rndm (8) + 1)) |
280 | if (move_object (op, rndm (8) + 1)) |
284 | return 1; |
281 | return 1; |
285 | } |
282 | |
286 | return 0; |
283 | return 0; |
287 | } |
284 | } |
288 | |
285 | |
289 | /* |
286 | /* |
290 | * Move-monster returns 1 if the object has been freed, otherwise 0. |
287 | * Move-monster returns 1 if the object has been freed, otherwise 0. |
… | |
… | |
313 | enemy->attacked_by = op; /* our ptr */ |
310 | enemy->attacked_by = op; /* our ptr */ |
314 | |
311 | |
315 | /* generate hp, if applicable */ |
312 | /* generate hp, if applicable */ |
316 | if (op->stats.Con > 0 && op->stats.hp < op->stats.maxhp) |
313 | if (op->stats.Con > 0 && op->stats.hp < op->stats.maxhp) |
317 | { |
314 | { |
318 | |
|
|
319 | /* last heal is in funny units. Dividing by speed puts |
315 | /* last heal is in funny units. Dividing by speed puts |
320 | * the regeneration rate on a basis of time instead of |
316 | * the regeneration rate on a basis of time instead of |
321 | * #moves the monster makes. The scaling by 8 is |
317 | * #moves the monster makes. The scaling by 8 is |
322 | * to capture 8th's of a hp fraction regens |
318 | * to capture 8th's of a hp fraction regens |
323 | * |
319 | * |
… | |
… | |
338 | } |
334 | } |
339 | |
335 | |
340 | /* generate sp, if applicable */ |
336 | /* generate sp, if applicable */ |
341 | if (op->stats.Pow > 0 && op->stats.sp < op->stats.maxsp) |
337 | if (op->stats.Pow > 0 && op->stats.sp < op->stats.maxsp) |
342 | { |
338 | { |
343 | |
|
|
344 | /* last_sp is in funny units. Dividing by speed puts |
339 | /* last_sp is in funny units. Dividing by speed puts |
345 | * the regeneration rate on a basis of time instead of |
340 | * the regeneration rate on a basis of time instead of |
346 | * #moves the monster makes. The scaling by 8 is |
341 | * #moves the monster makes. The scaling by 8 is |
347 | * to capture 8th's of a sp fraction regens |
342 | * to capture 8th's of a sp fraction regens |
348 | * |
343 | * |
… | |
… | |
357 | |
352 | |
358 | /* this should probably get modified by many more values. |
353 | /* this should probably get modified by many more values. |
359 | * (eg, creatures resistance to fear, level, etc. ) |
354 | * (eg, creatures resistance to fear, level, etc. ) |
360 | */ |
355 | */ |
361 | if (QUERY_FLAG (op, FLAG_SCARED) && !(rndm (20))) |
356 | if (QUERY_FLAG (op, FLAG_SCARED) && !(rndm (20))) |
362 | { |
|
|
363 | CLEAR_FLAG (op, FLAG_SCARED); /* Time to regain some "guts"... */ |
357 | CLEAR_FLAG (op, FLAG_SCARED); /* Time to regain some "guts"... */ |
364 | } |
|
|
365 | |
358 | |
366 | if (INVOKE_OBJECT (MONSTER_MOVE, op, ARG_OBJECT (op->enemy))) |
359 | if (INVOKE_OBJECT (MONSTER_MOVE, op, ARG_OBJECT (op->enemy))) |
367 | return QUERY_FLAG (op, FLAG_FREED); |
360 | return QUERY_FLAG (op, FLAG_FREED); |
368 | |
361 | |
369 | if (QUERY_FLAG (op, FLAG_SLEEP) || QUERY_FLAG (op, FLAG_BLIND) || |
362 | if (QUERY_FLAG (op, FLAG_SLEEP) || QUERY_FLAG (op, FLAG_BLIND) || |
370 | ((op->map->darkness > 0) && !QUERY_FLAG (op, FLAG_SEE_IN_DARK) && !QUERY_FLAG (op, FLAG_SEE_INVISIBLE))) |
363 | ((op->map->darkness > 0) && !QUERY_FLAG (op, FLAG_SEE_IN_DARK) && !QUERY_FLAG (op, FLAG_SEE_INVISIBLE))) |
371 | { |
|
|
372 | if (!check_wakeup (op, enemy, &rv)) |
364 | if (!check_wakeup (op, enemy, &rv)) |
373 | return 0; |
365 | return 0; |
374 | } |
|
|
375 | |
366 | |
376 | /* check if monster pops out of hidden spot */ |
367 | /* check if monster pops out of hidden spot */ |
377 | if (op->flag [FLAG_HIDDEN]) |
368 | if (op->flag [FLAG_HIDDEN]) |
378 | do_hidden_move (op); |
369 | do_hidden_move (op); |
379 | |
370 | |
… | |
… | |
399 | { |
390 | { |
400 | if (op->attack_movement & HI4) |
391 | if (op->attack_movement & HI4) |
401 | { |
392 | { |
402 | switch (op->attack_movement & HI4) |
393 | switch (op->attack_movement & HI4) |
403 | { |
394 | { |
404 | case (PETMOVE): |
395 | case (PETMOVE): |
405 | pet_move (op); |
396 | pet_move (op); |
406 | break; |
397 | break; |
407 | |
398 | |
408 | case (CIRCLE1): |
399 | case (CIRCLE1): |
409 | circ1_move (op); |
400 | circ1_move (op); |
410 | break; |
401 | break; |
411 | |
402 | |
412 | case (CIRCLE2): |
403 | case (CIRCLE2): |
413 | circ2_move (op); |
404 | circ2_move (op); |
414 | break; |
405 | break; |
415 | |
406 | |
416 | case (PACEV): |
407 | case (PACEV): |
417 | pace_movev (op); |
408 | pace_movev (op); |
418 | break; |
409 | break; |
419 | |
410 | |
420 | case (PACEH): |
411 | case (PACEH): |
421 | pace_moveh (op); |
412 | pace_moveh (op); |
422 | break; |
413 | break; |
423 | |
414 | |
424 | case (PACEV2): |
415 | case (PACEV2): |
425 | pace2_movev (op); |
416 | pace2_movev (op); |
426 | break; |
417 | break; |
427 | |
418 | |
428 | case (PACEH2): |
419 | case (PACEH2): |
429 | pace2_moveh (op); |
420 | pace2_moveh (op); |
430 | break; |
421 | break; |
431 | |
422 | |
432 | case (RANDO): |
423 | case (RANDO): |
433 | rand_move (op); |
424 | rand_move (op); |
434 | break; |
425 | break; |
435 | |
426 | |
436 | case (RANDO2): |
427 | case (RANDO2): |
437 | move_randomly (op); |
428 | move_randomly (op); |
438 | break; |
429 | break; |
439 | } |
430 | } |
|
|
431 | |
440 | return 0; |
432 | return 0; |
441 | } |
433 | } |
442 | else if (QUERY_FLAG (op, FLAG_RANDOM_MOVE)) |
434 | else if (QUERY_FLAG (op, FLAG_RANDOM_MOVE)) |
443 | (void) move_randomly (op); |
435 | move_randomly (op); |
444 | |
|
|
445 | } /* stand still */ |
436 | } /* stand still */ |
|
|
437 | |
446 | return 0; |
438 | return 0; |
447 | } /* no enemy */ |
439 | } /* no enemy */ |
448 | |
440 | |
449 | /* We have an enemy. Block immediately below is for pets */ |
441 | /* We have an enemy. Block immediately below is for pets */ |
450 | if ((op->attack_movement & HI4) == PETMOVE |
442 | if ((op->attack_movement & HI4) == PETMOVE |
… | |
… | |
529 | |
521 | |
530 | if ((op->attack_movement & LO4) && !QUERY_FLAG (op, FLAG_SCARED)) |
522 | if ((op->attack_movement & LO4) && !QUERY_FLAG (op, FLAG_SCARED)) |
531 | { |
523 | { |
532 | switch (op->attack_movement & LO4) |
524 | switch (op->attack_movement & LO4) |
533 | { |
525 | { |
534 | case DISTATT: |
526 | case DISTATT: |
535 | dir = dist_att (dir, op, enemy, part, &rv); |
527 | dir = dist_att (dir, op, enemy, part, &rv); |
536 | break; |
528 | break; |
537 | |
529 | |
538 | case RUNATT: |
530 | case RUNATT: |
539 | dir = run_att (dir, op, enemy, part, &rv); |
531 | dir = run_att (dir, op, enemy, part, &rv); |
540 | break; |
532 | break; |
541 | |
533 | |
542 | case HITRUN: |
534 | case HITRUN: |
543 | dir = hitrun_att (dir, op, enemy); |
535 | dir = hitrun_att (dir, op, enemy); |
544 | break; |
536 | break; |
545 | |
537 | |
546 | case WAITATT: |
538 | case WAITATT: |
547 | dir = wait_att (dir, op, enemy, part, &rv); |
539 | dir = wait_att (dir, op, enemy, part, &rv); |
548 | break; |
540 | break; |
549 | |
541 | |
550 | case RUSH: /* default - monster normally moves towards player */ |
542 | case RUSH: /* default - monster normally moves towards player */ |
551 | case ALLRUN: |
543 | case ALLRUN: |
552 | break; |
544 | break; |
553 | |
545 | |
554 | case DISTHIT: |
546 | case DISTHIT: |
555 | dir = disthit_att (dir, op, enemy, part, &rv); |
547 | dir = disthit_att (dir, op, enemy, part, &rv); |
556 | break; |
548 | break; |
557 | |
549 | |
558 | case WAIT2: |
550 | case WAIT2: |
559 | dir = wait_att2 (dir, op, enemy, part, &rv); |
551 | dir = wait_att2 (dir, op, enemy, part, &rv); |
560 | break; |
552 | break; |
561 | |
553 | |
562 | default: |
554 | default: |
563 | LOG (llevDebug, "Illegal low mon-move: %d\n", op->attack_movement & LO4); |
555 | LOG (llevDebug, "Illegal low mon-move: %d\n", op->attack_movement & LO4); |
564 | } |
556 | } |
565 | } |
557 | } |
566 | |
558 | |
567 | if (!dir) |
559 | if (!dir) |
568 | return 0; |
560 | return 0; |
… | |
… | |
578 | return 0; |
570 | return 0; |
579 | } |
571 | } |
580 | |
572 | |
581 | if (QUERY_FLAG (op, FLAG_SCARED) || !can_hit (part, enemy, &rv) || QUERY_FLAG (op, FLAG_RUN_AWAY)) |
573 | if (QUERY_FLAG (op, FLAG_SCARED) || !can_hit (part, enemy, &rv) || QUERY_FLAG (op, FLAG_RUN_AWAY)) |
582 | { |
574 | { |
583 | |
|
|
584 | /* Try move around corners if !close */ |
575 | /* Try move around corners if !close */ |
585 | int maxdiff = (QUERY_FLAG (op, FLAG_ONLY_ATTACK) || RANDOM () & 1) ? 1 : 2; |
576 | int maxdiff = (QUERY_FLAG (op, FLAG_ONLY_ATTACK) || RANDOM () & 1) ? 1 : 2; |
586 | |
577 | |
587 | for (diff = 1; diff <= maxdiff; diff++) |
578 | for (diff = 1; diff <= maxdiff; diff++) |
588 | { |
579 | { |
… | |
… | |
638 | * still be pretty nasty. |
629 | * still be pretty nasty. |
639 | */ |
630 | */ |
640 | if (QUERY_FLAG (op, FLAG_RUN_AWAY)) |
631 | if (QUERY_FLAG (op, FLAG_RUN_AWAY)) |
641 | { |
632 | { |
642 | part->stats.wc += 10; |
633 | part->stats.wc += 10; |
643 | (void) skill_attack (enemy, part, 0, NULL, NULL); |
634 | skill_attack (enemy, part, 0, NULL, NULL); |
644 | part->stats.wc -= 10; |
635 | part->stats.wc -= 10; |
645 | } |
636 | } |
646 | else |
637 | else |
647 | (void) skill_attack (enemy, part, 0, NULL, NULL); |
638 | skill_attack (enemy, part, 0, NULL, NULL); |
648 | } /* if monster is in attack range */ |
639 | } /* if monster is in attack range */ |
649 | |
640 | |
650 | if (QUERY_FLAG (part, FLAG_FREED)) /* Might be freed by ghost-attack or hit-back */ |
641 | if (QUERY_FLAG (part, FLAG_FREED)) /* Might be freed by ghost-attack or hit-back */ |
651 | return 1; |
642 | return 1; |
652 | |
643 | |
… | |
… | |
678 | { |
669 | { |
679 | get_rangevector (ob1, more, &rv1, 0); |
670 | get_rangevector (ob1, more, &rv1, 0); |
680 | if (abs (rv1.distance_x) < 2 && abs (rv1.distance_y) < 2) |
671 | if (abs (rv1.distance_x) < 2 && abs (rv1.distance_y) < 2) |
681 | return 1; |
672 | return 1; |
682 | } |
673 | } |
|
|
674 | |
683 | return 0; |
675 | return 0; |
684 | |
|
|
685 | } |
676 | } |
686 | |
677 | |
687 | /* Returns 1 is monster should cast spell sp at an enemy |
678 | /* Returns 1 is monster should cast spell sp at an enemy |
688 | * Returns 0 if the monster should not cast this spell. |
679 | * Returns 0 if the monster should not cast this spell. |
689 | * |
680 | * |
… | |
… | |
707 | spell_ob->subtype == SP_EXPLOSION || spell_ob->subtype == SP_CONE || |
698 | spell_ob->subtype == SP_EXPLOSION || spell_ob->subtype == SP_CONE || |
708 | spell_ob->subtype == SP_BOMB || spell_ob->subtype == SP_SMITE || |
699 | spell_ob->subtype == SP_BOMB || spell_ob->subtype == SP_SMITE || |
709 | spell_ob->subtype == SP_MAGIC_MISSILE || spell_ob->subtype == SP_SUMMON_GOLEM || |
700 | spell_ob->subtype == SP_MAGIC_MISSILE || spell_ob->subtype == SP_SUMMON_GOLEM || |
710 | spell_ob->subtype == SP_MAGIC_WALL || spell_ob->subtype == SP_SUMMON_MONSTER || |
701 | spell_ob->subtype == SP_MAGIC_WALL || spell_ob->subtype == SP_SUMMON_MONSTER || |
711 | spell_ob->subtype == SP_MOVING_BALL || spell_ob->subtype == SP_SWARM || spell_ob->subtype == SP_INVISIBLE) |
702 | spell_ob->subtype == SP_MOVING_BALL || spell_ob->subtype == SP_SWARM || spell_ob->subtype == SP_INVISIBLE) |
712 | |
|
|
713 | return 1; |
703 | return 1; |
714 | |
704 | |
715 | return 0; |
705 | return 0; |
716 | } |
706 | } |
717 | |
|
|
718 | |
707 | |
719 | #define MAX_KNOWN_SPELLS 20 |
708 | #define MAX_KNOWN_SPELLS 20 |
720 | |
709 | |
721 | /* Returns a randomly selected spell. This logic is still |
710 | /* Returns a randomly selected spell. This logic is still |
722 | * less than ideal. This code also only seems to deal with |
711 | * less than ideal. This code also only seems to deal with |
… | |
… | |
725 | */ |
714 | */ |
726 | object * |
715 | object * |
727 | monster_choose_random_spell (object *monster) |
716 | monster_choose_random_spell (object *monster) |
728 | { |
717 | { |
729 | object *altern[MAX_KNOWN_SPELLS]; |
718 | object *altern[MAX_KNOWN_SPELLS]; |
730 | object *tmp; |
|
|
731 | int i = 0; |
719 | int i = 0; |
732 | |
720 | |
733 | for (tmp = monster->inv; tmp != NULL; tmp = tmp->below) |
721 | for (object *tmp = monster->inv; tmp; tmp = tmp->below) |
734 | if (tmp->type == SPELLBOOK || tmp->type == SPELL) |
722 | if (tmp->type == SPELLBOOK || tmp->type == SPELL) |
735 | { |
723 | { |
736 | /* Check and see if it's actually a useful spell. |
724 | /* Check and see if it's actually a useful spell. |
737 | * If its a spellbook, the spell is actually the inventory item. |
725 | * If its a spellbook, the spell is actually the inventory item. |
738 | * if it is a spell, then it is just the object itself. |
726 | * if it is a spell, then it is just the object itself. |
739 | */ |
727 | */ |
740 | if (monster_should_cast_spell (monster, (tmp->type == SPELLBOOK) ? tmp->inv : tmp)) |
728 | if (monster_should_cast_spell (monster, (tmp->type == SPELLBOOK) ? tmp->inv : tmp)) |
741 | { |
729 | { |
742 | altern[i++] = tmp; |
730 | altern [i++] = tmp; |
|
|
731 | |
743 | if (i == MAX_KNOWN_SPELLS) |
732 | if (i == MAX_KNOWN_SPELLS) |
744 | break; |
733 | break; |
745 | } |
734 | } |
746 | } |
735 | } |
747 | if (!i) |
736 | |
748 | return NULL; |
737 | return i ? altern [rndm (i)] : 0; |
749 | return altern[RANDOM () % i]; |
|
|
750 | } |
738 | } |
751 | |
739 | |
752 | /* This checks to see if the monster should cast a spell/ability. |
740 | /* This checks to see if the monster should cast a spell/ability. |
753 | * it returns true if the monster casts a spell, 0 if he doesn't. |
741 | * it returns true if the monster casts a spell, 0 if he doesn't. |
754 | * head is the head of the monster. |
742 | * head is the head of the monster. |
755 | * part is the part of the monster we are checking against. |
743 | * part is the part of the monster we are checking against. |
756 | * pl is the target. |
744 | * pl is the target. |
757 | * dir is the direction to case. |
745 | * dir is the direction to case. |
758 | * rv is the vector which describes where the enemy is. |
746 | * rv is the vector which describes where the enemy is. |
759 | */ |
747 | */ |
760 | |
|
|
761 | int |
748 | int |
762 | monster_cast_spell (object *head, object *part, object *pl, int dir, rv_vector * rv) |
749 | monster_cast_spell (object *head, object *part, object *pl, int dir, rv_vector * rv) |
763 | { |
750 | { |
764 | object *spell_item; |
751 | object *spell_item; |
765 | object *owner; |
752 | object *owner; |
… | |
… | |
776 | |
763 | |
777 | if (QUERY_FLAG (head, FLAG_FRIENDLY) && (owner = head->owner) != NULL) |
764 | if (QUERY_FLAG (head, FLAG_FRIENDLY) && (owner = head->owner) != NULL) |
778 | { |
765 | { |
779 | get_rangevector (head, owner, &rv1, 0x1); |
766 | get_rangevector (head, owner, &rv1, 0x1); |
780 | if (dirdiff (dir, rv1.direction) < 2) |
767 | if (dirdiff (dir, rv1.direction) < 2) |
781 | { |
|
|
782 | return 0; /* Might hit owner with spell */ |
768 | return 0; /* Might hit owner with spell */ |
783 | } |
|
|
784 | } |
769 | } |
785 | |
770 | |
786 | if (QUERY_FLAG (head, FLAG_CONFUSED)) |
771 | if (QUERY_FLAG (head, FLAG_CONFUSED)) |
787 | dir = absdir (dir + rndm (3) + rndm (3) - 2); |
772 | dir = absdir (dir + rndm (3) + rndm (3) - 2); |
788 | |
773 | |
… | |
… | |
796 | { |
781 | { |
797 | LOG (llevMonster, "Turned off spells in %s\n", &head->name); |
782 | LOG (llevMonster, "Turned off spells in %s\n", &head->name); |
798 | CLEAR_FLAG (head, FLAG_CAST_SPELL); /* Will be turned on when picking up book */ |
783 | CLEAR_FLAG (head, FLAG_CAST_SPELL); /* Will be turned on when picking up book */ |
799 | return 0; |
784 | return 0; |
800 | } |
785 | } |
|
|
786 | |
801 | if (spell_item->type == SPELLBOOK) |
787 | if (spell_item->type == SPELLBOOK) |
802 | { |
788 | { |
803 | if (!spell_item->inv) |
789 | if (!spell_item->inv) |
804 | { |
790 | { |
805 | LOG (llevError, "spellbook %s does not contain a spell?\n", &spell_item->name); |
791 | LOG (llevError, "spellbook %s does not contain a spell?\n", &spell_item->name); |
806 | return 0; |
792 | return 0; |
807 | } |
793 | } |
|
|
794 | |
808 | spell_item = spell_item->inv; |
795 | spell_item = spell_item->inv; |
809 | } |
796 | } |
810 | } |
797 | } |
811 | else |
798 | else |
812 | spell_item = head->spellitem; |
799 | spell_item = head->spellitem; |
… | |
… | |
831 | /* set this to null, so next time monster will choose something different */ |
818 | /* set this to null, so next time monster will choose something different */ |
832 | head->spellitem = NULL; |
819 | head->spellitem = NULL; |
833 | |
820 | |
834 | return cast_spell (part, part, dir, spell_item, NULL); |
821 | return cast_spell (part, part, dir, spell_item, NULL); |
835 | } |
822 | } |
836 | |
|
|
837 | |
823 | |
838 | int |
824 | int |
839 | monster_use_scroll (object *head, object *part, object *pl, int dir, rv_vector * rv) |
825 | monster_use_scroll (object *head, object *part, object *pl, int dir, rv_vector * rv) |
840 | { |
826 | { |
841 | object *scroll; |
827 | object *scroll; |
… | |
… | |
1233 | } |
1219 | } |
1234 | } |
1220 | } |
1235 | |
1221 | |
1236 | if (((!(monster->pick_up & 32)) && flag) || ((monster->pick_up & 32) && (!flag))) |
1222 | if (((!(monster->pick_up & 32)) && flag) || ((monster->pick_up & 32) && (!flag))) |
1237 | return 1; |
1223 | return 1; |
|
|
1224 | |
1238 | return 0; |
1225 | return 0; |
1239 | } |
1226 | } |
1240 | |
1227 | |
1241 | /* |
1228 | /* |
1242 | * monster_apply_below(): |
1229 | * monster_apply_below(): |
… | |
… | |
1417 | int |
1404 | int |
1418 | dist_att (int dir, object *ob, object *enemy, object *part, rv_vector * rv) |
1405 | dist_att (int dir, object *ob, object *enemy, object *part, rv_vector * rv) |
1419 | { |
1406 | { |
1420 | if (can_hit (part, enemy, rv)) |
1407 | if (can_hit (part, enemy, rv)) |
1421 | return dir; |
1408 | return dir; |
|
|
1409 | |
1422 | if (rv->distance < 10) |
1410 | if (rv->distance < 10) |
1423 | return absdir (dir + 4); |
1411 | return absdir (dir + 4); |
1424 | else if (rv->distance > 18) |
1412 | else if (rv->distance > 18) |
1425 | return dir; |
1413 | return dir; |
1426 | |
1414 | |
… | |
… | |
1581 | } |
1569 | } |
1582 | |
1570 | |
1583 | void |
1571 | void |
1584 | rand_move (object *ob) |
1572 | rand_move (object *ob) |
1585 | { |
1573 | { |
1586 | int i; |
|
|
1587 | |
|
|
1588 | if (ob->move_status < 1 || ob->move_status > 8 || !(move_object (ob, ob->move_status || !(rndm (9))))) |
1574 | if (ob->move_status < 1 || ob->move_status > 8 || !(move_object (ob, ob->move_status || !(rndm (9))))) |
1589 | for (i = 0; i < 5; i++) |
1575 | for (int i = 0; i < 5; i++) |
1590 | if (move_object (ob, ob->move_status = rndm (8) + 1)) |
1576 | if (move_object (ob, ob->move_status = rndm (8) + 1)) |
1591 | return; |
1577 | return; |
1592 | } |
1578 | } |
1593 | |
1579 | |
1594 | void |
1580 | void |
1595 | check_earthwalls (object *op, maptile *m, int x, int y) |
1581 | check_earthwalls (object *op, maptile *m, int x, int y) |
1596 | { |
1582 | { |
1597 | object *tmp; |
|
|
1598 | |
|
|
1599 | for (tmp = GET_MAP_OB (m, x, y); tmp != NULL; tmp = tmp->above) |
1583 | for (object *tmp = GET_MAP_OB (m, x, y); tmp; tmp = tmp->above) |
1600 | { |
|
|
1601 | if (tmp->type == EARTHWALL) |
1584 | if (tmp->type == EARTHWALL) |
1602 | { |
1585 | { |
1603 | hit_player (tmp, op->stats.dam, op, AT_PHYSICAL, 1); |
1586 | hit_player (tmp, op->stats.dam, op, AT_PHYSICAL, 1); |
1604 | return; |
1587 | return; |
1605 | } |
1588 | } |
1606 | } |
|
|
1607 | } |
1589 | } |
1608 | |
1590 | |
1609 | void |
1591 | void |
1610 | check_doors (object *op, maptile *m, int x, int y) |
1592 | check_doors (object *op, maptile *m, int x, int y) |
1611 | { |
1593 | { |
1612 | object *tmp; |
|
|
1613 | |
|
|
1614 | for (tmp = GET_MAP_OB (m, x, y); tmp != NULL; tmp = tmp->above) |
1594 | for (object *tmp = GET_MAP_OB (m, x, y); tmp; tmp = tmp->above) |
1615 | { |
|
|
1616 | if (tmp->type == DOOR) |
1595 | if (tmp->type == DOOR) |
1617 | { |
1596 | { |
1618 | hit_player (tmp, 1000, op, AT_PHYSICAL, 1); |
1597 | hit_player (tmp, 1000, op, AT_PHYSICAL, 1); |
1619 | return; |
1598 | return; |
1620 | } |
1599 | } |
1621 | } |
|
|
1622 | } |
1600 | } |
1623 | |
1601 | |
1624 | /* find_mon_throw_ob() - modeled on find_throw_ob |
1602 | /* find_mon_throw_ob() - modeled on find_throw_ob |
1625 | * This is probably overly simplistic as it is now - We want |
1603 | * This is probably overly simplistic as it is now - We want |
1626 | * monsters to throw things like chairs and other pieces of |
1604 | * monsters to throw things like chairs and other pieces of |
… | |
… | |
1682 | return 0; |
1660 | return 0; |
1683 | |
1661 | |
1684 | get_rangevector (op, enemy, rv, 0); |
1662 | get_rangevector (op, enemy, rv, 0); |
1685 | |
1663 | |
1686 | /* Monsters always ignore the DM */ |
1664 | /* Monsters always ignore the DM */ |
1687 | if ((op->type != PLAYER) && QUERY_FLAG (enemy, FLAG_WIZ)) |
1665 | if (op->type != PLAYER && QUERY_FLAG (enemy, FLAG_WIZ)) |
1688 | return 0; |
1666 | return 0; |
1689 | |
1667 | |
1690 | /* simple check. Should probably put some range checks in here. */ |
1668 | /* simple check. Should probably put some range checks in here. */ |
1691 | if (can_see_enemy (op, enemy)) |
1669 | if (can_see_enemy (op, enemy)) |
1692 | return 1; |
1670 | return 1; |
… | |
… | |
1816 | * other side of a wall (!). |
1794 | * other side of a wall (!). |
1817 | */ |
1795 | */ |
1818 | int |
1796 | int |
1819 | stand_in_light (object *op) |
1797 | stand_in_light (object *op) |
1820 | { |
1798 | { |
1821 | if (!op) |
1799 | if (op) |
1822 | return 0; |
1800 | { |
1823 | |
|
|
1824 | if (op->glow_radius > 0) |
1801 | if (op->glow_radius > 0) |
1825 | return 1; |
1802 | return 1; |
1826 | |
1803 | |
1827 | if (op->map) |
1804 | if (op->map) |
1828 | { |
1805 | unordered_mapwalk (op, -MAX_LIGHT_RADIUS, -MAX_LIGHT_RADIUS, MAX_LIGHT_RADIUS, MAX_LIGHT_RADIUS) |
|
|
1806 | { |
1829 | /* Check the spaces with the max light radius to see if any of them |
1807 | /* Check the spaces with the max light radius to see if any of them |
1830 | * have lights, and if any of them light the player enough, then return 1. |
1808 | * have lights, and if any of them light the player enough, then return 1. |
1831 | */ |
|
|
1832 | for (int x = op->x - MAX_LIGHT_RADII; x <= op->x + MAX_LIGHT_RADII; x++) |
|
|
1833 | { |
|
|
1834 | for (int y = op->y - MAX_LIGHT_RADII; y <= op->y + MAX_LIGHT_RADII; y++) |
|
|
1835 | { |
1809 | */ |
1836 | maptile *m = op->map; |
1810 | int light = m->at (nx, ny).light; |
1837 | sint16 nx = x; |
|
|
1838 | sint16 ny = y; |
|
|
1839 | |
1811 | |
1840 | if (xy_normalise (m, nx, ny)) |
1812 | if (expect_false (light > 0) && idistance (dx, dy) <= light) |
1841 | if (idistance (x - op->x, y - op->y) < m->at (nx, ny).light) |
|
|
1842 | return 1; |
1813 | return 1; |
1843 | } |
1814 | } |
1844 | } |
|
|
1845 | } |
1815 | } |
1846 | |
1816 | |
1847 | return 0; |
1817 | return 0; |
1848 | } |
1818 | } |
1849 | |
1819 | |