ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/monster.C
(Generate patch)

Comparing deliantra/server/server/monster.C (file contents):
Revision 1.84 by root, Sat Apr 10 04:42:44 2010 UTC vs.
Revision 1.85 by root, Sun Apr 11 00:34:06 2010 UTC

65 if (npc->enemy) 65 if (npc->enemy)
66 { 66 {
67 /* I broke these if's apart to better be able to see what 67 /* I broke these if's apart to better be able to see what
68 * the grouping checks are. Code is the same. 68 * the grouping checks are. Code is the same.
69 */ 69 */
70 if (QUERY_FLAG (npc->enemy, FLAG_REMOVED) || 70 if (npc->enemy->flag [FLAG_REMOVED] ||
71 QUERY_FLAG (npc->enemy, FLAG_FREED) || 71 npc->enemy->flag [FLAG_FREED] ||
72 !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 || npc->flag [FLAG_NEUTRAL] || npc->enemy->flag [FLAG_NEUTRAL])
73 npc->enemy = 0; 73 npc->enemy = 0;
74 74
75 else if (QUERY_FLAG (npc, FLAG_FRIENDLY) && ((QUERY_FLAG (npc->enemy, FLAG_FRIENDLY) 75 else if (npc->flag [FLAG_FRIENDLY] && ((npc->enemy->flag [FLAG_FRIENDLY]
76 && !(should_arena_attack (npc, npc->owner, npc->enemy))) 76 && !(should_arena_attack (npc, npc->owner, npc->enemy)))
77 || ((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)))
78 || npc->enemy == npc->owner)) 78 || npc->enemy == npc->owner))
79 npc->enemy = 0; 79 npc->enemy = 0;
80 80
81 81
82 else if (!QUERY_FLAG (npc, FLAG_FRIENDLY) && (!QUERY_FLAG (npc->enemy, FLAG_FRIENDLY) && npc->enemy->type != PLAYER)) 82 else if (!npc->flag [FLAG_FRIENDLY] && (!npc->enemy->flag [FLAG_FRIENDLY] && npc->enemy->type != PLAYER))
83 npc->enemy = 0; 83 npc->enemy = 0;
84 84
85 /* 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
86 * target enemy - this code below makes sure the enemy is something 86 * target enemy - this code below makes sure the enemy is something
87 * that should be attacked. My guess is that the arrow hits 87 * that should be attacked. My guess is that the arrow hits
88 * the creature/owner, and so the creature then takes that 88 * the creature/owner, and so the creature then takes that
89 * as the enemy to attack. 89 * as the enemy to attack.
90 */ 90 */
91 else if (!QUERY_FLAG (npc->enemy, FLAG_MONSTER) 91 else if (!npc->enemy->flag [FLAG_MONSTER]
92 && !QUERY_FLAG (npc->enemy, FLAG_GENERATOR) 92 && !npc->enemy->flag [FLAG_GENERATOR]
93 && npc->enemy->type != PLAYER 93 && npc->enemy->type != PLAYER
94 && npc->enemy->type != GOLEM) 94 && npc->enemy->type != GOLEM)
95 npc->enemy = 0; 95 npc->enemy = 0;
96 } 96 }
97 97
162 162
163 attacker = npc->attacked_by; /* save this for later use. This can be a attacker. */ 163 attacker = npc->attacked_by; /* save this for later use. This can be a attacker. */
164 npc->attacked_by = 0; /* always clear the attacker entry */ 164 npc->attacked_by = 0; /* always clear the attacker entry */
165 165
166 /* if we berserk, we don't care about others - we attack all we can find */ 166 /* if we berserk, we don't care about others - we attack all we can find */
167 if (QUERY_FLAG (npc, FLAG_BERSERK)) 167 if (npc->flag [FLAG_BERSERK])
168 { 168 {
169 tmp = find_nearest_living_creature (npc); 169 tmp = find_nearest_living_creature (npc);
170 170
171 if (tmp) 171 if (tmp)
172 get_rangevector (npc, tmp, rv, 0); 172 get_rangevector (npc, tmp, rv, 0);
201 if (attacker) /* if we have an attacker, check him */ 201 if (attacker) /* if we have an attacker, check him */
202 { 202 {
203 /* TODO: that's not finished */ 203 /* TODO: that's not finished */
204 /* we don't want a fight evil vs evil or good against non evil */ 204 /* we don't want a fight evil vs evil or good against non evil */
205 205
206 if (QUERY_FLAG (npc, FLAG_NEUTRAL) || QUERY_FLAG (attacker, FLAG_NEUTRAL) || /* neutral */ 206 if (npc->flag [FLAG_NEUTRAL] || attacker->flag [FLAG_NEUTRAL] || /* neutral */
207 (QUERY_FLAG (npc, FLAG_FRIENDLY) && QUERY_FLAG (attacker, FLAG_FRIENDLY)) || 207 (npc->flag [FLAG_FRIENDLY] && attacker->flag [FLAG_FRIENDLY]) ||
208 (!QUERY_FLAG (npc, FLAG_FRIENDLY) && (!QUERY_FLAG (attacker, FLAG_FRIENDLY) && attacker->type != PLAYER))) 208 (!npc->flag [FLAG_FRIENDLY] && (!attacker->flag [FLAG_FRIENDLY] && attacker->type != PLAYER)))
209 CLEAR_FLAG (npc, FLAG_SLEEP); /* skip it, but lets wakeup */ 209 npc->clr_flag (FLAG_SLEEP); /* skip it, but lets wakeup */
210 else if (on_same_map (npc, attacker)) /* that's the only thing we must know... */ 210 else if (on_same_map (npc, attacker)) /* that's the only thing we must know... */
211 { 211 {
212 CLEAR_FLAG (npc, FLAG_SLEEP); /* well, NOW we really should wake up! */ 212 npc->clr_flag (FLAG_SLEEP); /* well, NOW we really should wake up! */
213 npc->enemy = attacker; 213 npc->enemy = attacker;
214 return attacker; /* yes, we face our attacker! */ 214 return attacker; /* yes, we face our attacker! */
215 } 215 }
216 } 216 }
217 217
218 /* we have no legal enemy or attacker, so we try to target a new one */ 218 /* we have no legal enemy or attacker, so we try to target a new one */
219 if (!QUERY_FLAG (npc, FLAG_UNAGGRESSIVE) && !QUERY_FLAG (npc, FLAG_FRIENDLY) && !QUERY_FLAG (npc, FLAG_NEUTRAL)) 219 if (!npc->flag [FLAG_UNAGGRESSIVE] && !npc->flag [FLAG_FRIENDLY] && !npc->flag [FLAG_NEUTRAL])
220 { 220 {
221 npc->enemy = get_nearest_player (npc); 221 npc->enemy = get_nearest_player (npc);
222 if (npc->enemy) 222 if (npc->enemy)
223 tmp = check_enemy (npc, rv); 223 tmp = check_enemy (npc, rv);
224 } 224 }
265 /* 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
266 * for that. 266 * for that.
267 */ 267 */
268 if (rv->distance <= radius) 268 if (rv->distance <= radius)
269 { 269 {
270 CLEAR_FLAG (op, FLAG_SLEEP); 270 op->clr_flag (FLAG_SLEEP);
271 return 1; 271 return 1;
272 } 272 }
273 273
274 return 0; 274 return 0;
275} 275}
298 int i; 298 int i;
299 299
300 if (!can_pick (monster, item)) 300 if (!can_pick (monster, item))
301 return 0; 301 return 0;
302 302
303 if (QUERY_FLAG (item, FLAG_UNPAID)) 303 if (item->flag [FLAG_UNPAID])
304 return 0; 304 return 0;
305 305
306 if (monster->pick_up & 64) /* All */ 306 if (monster->pick_up & 64) /* All */
307 flag = 1; 307 flag = 1;
308 308
317 case FOOD: 317 case FOOD:
318 flag = monster->pick_up & 4; 318 flag = monster->pick_up & 4;
319 break; 319 break;
320 320
321 case WEAPON: 321 case WEAPON:
322 flag = (monster->pick_up & 8) || QUERY_FLAG (monster, FLAG_USE_WEAPON); 322 flag = (monster->pick_up & 8) || monster->flag [FLAG_USE_WEAPON];
323 break; 323 break;
324 324
325 case ARMOUR: 325 case ARMOUR:
326 case SHIELD: 326 case SHIELD:
327 case HELMET: 327 case HELMET:
328 case BOOTS: 328 case BOOTS:
329 case GLOVES: 329 case GLOVES:
330 case GIRDLE: 330 case GIRDLE:
331 flag = (monster->pick_up & 16) || QUERY_FLAG (monster, FLAG_USE_ARMOUR); 331 flag = (monster->pick_up & 16) || monster->flag [FLAG_USE_ARMOUR];
332 break; 332 break;
333 333
334 case SKILL: 334 case SKILL:
335 flag = QUERY_FLAG (monster, FLAG_CAN_USE_SKILL); 335 flag = monster->flag [FLAG_CAN_USE_SKILL];
336 break; 336 break;
337 337
338 case RING: 338 case RING:
339 flag = QUERY_FLAG (monster, FLAG_USE_RING); 339 flag = monster->flag [FLAG_USE_RING];
340 break; 340 break;
341 341
342 case WAND: 342 case WAND:
343 case HORN: 343 case HORN:
344 case ROD: 344 case ROD:
345 flag = QUERY_FLAG (monster, FLAG_USE_RANGE); 345 flag = monster->flag [FLAG_USE_RANGE];
346 break; 346 break;
347 347
348 case SPELLBOOK: 348 case SPELLBOOK:
349 flag = monster->arch && QUERY_FLAG (monster->arch, FLAG_CAST_SPELL); 349 flag = monster->arch && monster->arch->flag [FLAG_CAST_SPELL];
350 break; 350 break;
351 351
352 case SCROLL: 352 case SCROLL:
353 flag = QUERY_FLAG (monster, FLAG_USE_SCROLL); 353 flag = monster->flag [FLAG_USE_SCROLL];
354 break; 354 break;
355 355
356 case BOW: 356 case BOW:
357 case ARROW: 357 case ARROW:
358 flag = QUERY_FLAG (monster, FLAG_USE_BOW); 358 flag = monster->flag [FLAG_USE_BOW];
359 break; 359 break;
360 } 360 }
361 361
362 /* Simplistic check - if the monster has a location to equip it, he will 362 /* Simplistic check - if the monster has a location to equip it, he will
363 * pick it up. Note that this doesn't handle cases where an item may 363 * pick it up. Note that this doesn't handle cases where an item may
442 if (monster->will_apply & 2) 442 if (monster->will_apply & 2)
443 monster->apply (tmp); 443 monster->apply (tmp);
444 break; 444 break;
445 445
446 } 446 }
447 if (QUERY_FLAG (tmp, FLAG_IS_FLOOR)) 447 if (tmp->flag [FLAG_IS_FLOOR])
448 break; 448 break;
449 } 449 }
450} 450}
451 451
452/* Returns 1 is monster should cast spell sp at an enemy 452/* Returns 1 is monster should cast spell sp at an enemy
489{ 489{
490 object *other_weap; 490 object *other_weap;
491 int val = 0, i; 491 int val = 0, i;
492 492
493 for (other_weap = who->inv; other_weap; other_weap = other_weap->below) 493 for (other_weap = who->inv; other_weap; other_weap = other_weap->below)
494 if (other_weap->type == item->type && QUERY_FLAG (other_weap, FLAG_APPLIED)) 494 if (other_weap->type == item->type && other_weap->flag [FLAG_APPLIED])
495 break; 495 break;
496 496
497 if (!other_weap) /* No other weapons */ 497 if (!other_weap) /* No other weapons */
498 return 1; 498 return 1;
499 499
522{ 522{
523 object *other_armour; 523 object *other_armour;
524 int val = 0, i; 524 int val = 0, i;
525 525
526 for (other_armour = who->inv; other_armour; other_armour = other_armour->below) 526 for (other_armour = who->inv; other_armour; other_armour = other_armour->below)
527 if (other_armour->type == item->type && QUERY_FLAG (other_armour, FLAG_APPLIED)) 527 if (other_armour->type == item->type && other_armour->flag [FLAG_APPLIED])
528 break; 528 break;
529 529
530 if (other_armour == NULL) /* No other armour, use the new */ 530 if (other_armour == NULL) /* No other armour, use the new */
531 return 1; 531 return 1;
532 532
570void 570void
571monster_check_apply (object *mon, object *item) 571monster_check_apply (object *mon, object *item)
572{ 572{
573 int flag = 0; 573 int flag = 0;
574 574
575 if (item->type == SPELLBOOK && mon->arch && (QUERY_FLAG (mon->arch, FLAG_CAST_SPELL))) 575 if (item->type == SPELLBOOK && mon->arch && (mon->arch->flag [FLAG_CAST_SPELL]))
576 { 576 {
577 SET_FLAG (mon, FLAG_CAST_SPELL); 577 mon->set_flag (FLAG_CAST_SPELL);
578 return; 578 return;
579 } 579 }
580 580
581 /* If for some reason, this item is already applied, no more work to do */ 581 /* If for some reason, this item is already applied, no more work to do */
582 if (QUERY_FLAG (item, FLAG_APPLIED)) 582 if (item->flag [FLAG_APPLIED])
583 return; 583 return;
584 584
585 /* Might be better not to do this - if the monster can fire a bow, 585 /* Might be better not to do this - if the monster can fire a bow,
586 * it is possible in his wanderings, he will find one to use. In 586 * it is possible in his wanderings, he will find one to use. In
587 * which case, it would be nice to have ammo for it. 587 * which case, it would be nice to have ammo for it.
588 */ 588 */
589 if (QUERY_FLAG (mon, FLAG_USE_BOW) && item->type == ARROW) 589 if (mon->flag [FLAG_USE_BOW] && item->type == ARROW)
590 { 590 {
591 /* Check for the right kind of bow */ 591 /* Check for the right kind of bow */
592 object *bow; 592 object *bow;
593 593
594 for (bow = mon->inv; bow; bow = bow->below) 594 for (bow = mon->inv; bow; bow = bow->below)
595 if (bow->type == BOW && bow->race == item->race) 595 if (bow->type == BOW && bow->race == item->race)
596 { 596 {
597 SET_FLAG (mon, FLAG_READY_BOW); 597 mon->set_flag (FLAG_READY_BOW);
598 LOG (llevMonster, "Found correct bow for arrows.\n"); 598 LOG (llevMonster, "Found correct bow for arrows.\n");
599 return; /* nothing more to do for arrows */ 599 return; /* nothing more to do for arrows */
600 } 600 }
601 } 601 }
602 602
603 if (item->type == TREASURE && mon->will_apply & WILL_APPLY_TREASURE) 603 if (item->type == TREASURE && mon->will_apply & WILL_APPLY_TREASURE)
604 flag = 1; 604 flag = 1;
605 /* Eating food gets hp back */ 605 /* Eating food gets hp back */
606 else if (item->type == FOOD && mon->will_apply & WILL_APPLY_FOOD) 606 else if (item->type == FOOD && mon->will_apply & WILL_APPLY_FOOD)
607 flag = 1; 607 flag = 1;
608 else if (item->type == SCROLL && QUERY_FLAG (mon, FLAG_USE_SCROLL)) 608 else if (item->type == SCROLL && mon->flag [FLAG_USE_SCROLL])
609 { 609 {
610 if (!item->inv) 610 if (!item->inv)
611 LOG (llevDebug, "Monster %d having scroll %d with empty inventory!", mon->count, item->count); 611 LOG (llevDebug, "Monster %d having scroll %d with empty inventory!", mon->count, item->count);
612 else if (monster_should_cast_spell (mon, item->inv)) 612 else if (monster_should_cast_spell (mon, item->inv))
613 SET_FLAG (mon, FLAG_READY_SCROLL); 613 mon->set_flag (FLAG_READY_SCROLL);
614 /* Don't use it right now */ 614 /* Don't use it right now */
615 return; 615 return;
616 } 616 }
617 else if (item->type == WEAPON) 617 else if (item->type == WEAPON)
618 flag = check_good_weapon (mon, item); 618 flag = check_good_weapon (mon, item);
626 /* We never really 'ready' the wand/rod/horn, because that would mean the 626 /* We never really 'ready' the wand/rod/horn, because that would mean the
627 * weapon would get undone. 627 * weapon would get undone.
628 */ 628 */
629 if (!(can_apply_object (mon, item) & CAN_APPLY_NOT_MASK)) 629 if (!(can_apply_object (mon, item) & CAN_APPLY_NOT_MASK))
630 { 630 {
631 SET_FLAG (mon, FLAG_READY_RANGE); 631 mon->set_flag (FLAG_READY_RANGE);
632 SET_FLAG (item, FLAG_APPLIED); 632 item->set_flag (FLAG_APPLIED);
633 } 633 }
634 return; 634 return;
635 } 635 }
636 else if (item->type == BOW) 636 else if (item->type == BOW)
637 { 637 {
638 /* We never really 'ready' the bow, because that would mean the 638 /* We never really 'ready' the bow, because that would mean the
639 * weapon would get undone. 639 * weapon would get undone.
640 */ 640 */
641 if (!(can_apply_object (mon, item) & CAN_APPLY_NOT_MASK)) 641 if (!(can_apply_object (mon, item) & CAN_APPLY_NOT_MASK))
642 SET_FLAG (mon, FLAG_READY_BOW); 642 mon->set_flag (FLAG_READY_BOW);
643 return; 643 return;
644 } 644 }
645 else if (item->type == SKILL) 645 else if (item->type == SKILL)
646 { 646 {
647 /* 647 /*
648 * skills are specials: monsters must have the 'FLAG_READY_SKILL' flag set, 648 * skills are specials: monsters must have the 'FLAG_READY_SKILL' flag set,
649 * else they can't use the skill... 649 * else they can't use the skill...
650 * Skills also don't need to get applied, so return now. 650 * Skills also don't need to get applied, so return now.
651 */ 651 */
652 SET_FLAG (mon, FLAG_READY_SKILL); 652 mon->set_flag (FLAG_READY_SKILL);
653 return; 653 return;
654 } 654 }
655 655
656 /* if we don't match one of the above types, return now. 656 /* if we don't match one of the above types, return now.
657 * can_apply_object will say that we can apply things like flesh, 657 * can_apply_object will say that we can apply things like flesh,
679can_hit (object *ob1, object *ob2, rv_vector * rv) 679can_hit (object *ob1, object *ob2, rv_vector * rv)
680{ 680{
681 object *more; 681 object *more;
682 rv_vector rv1; 682 rv_vector rv1;
683 683
684 if (QUERY_FLAG (ob1, FLAG_CONFUSED) && !(rndm (3))) 684 if (ob1->flag [FLAG_CONFUSED] && !(rndm (3)))
685 return 0; 685 return 0;
686 686
687 if (abs (rv->distance_x) < 2 && abs (rv->distance_y) < 2) 687 if (abs (rv->distance_x) < 2 && abs (rv->distance_y) < 2)
688 return 1; 688 return 1;
689 689
923 * other monsters) 923 * other monsters)
924 */ 924 */
925 if (!(dir = path_to_player (part, pl, 0))) 925 if (!(dir = path_to_player (part, pl, 0)))
926 return 0; 926 return 0;
927 927
928 if (QUERY_FLAG (head, FLAG_FRIENDLY) && (owner = head->owner) != NULL) 928 if (head->flag [FLAG_FRIENDLY] && (owner = head->owner) != NULL)
929 { 929 {
930 get_rangevector (head, owner, &rv1, 0x1); 930 get_rangevector (head, owner, &rv1, 0x1);
931 if (dirdiff (dir, rv1.direction) < 2) 931 if (dirdiff (dir, rv1.direction) < 2)
932 return 0; /* Might hit owner with spell */ 932 return 0; /* Might hit owner with spell */
933 } 933 }
934 934
935 if (QUERY_FLAG (head, FLAG_CONFUSED)) 935 if (head->flag [FLAG_CONFUSED])
936 dir = absdir (dir + rndm (3) + rndm (3) - 2); 936 dir = absdir (dir + rndm (3) + rndm (3) - 2);
937 937
938 /* If the monster hasn't already chosen a spell, choose one 938 /* If the monster hasn't already chosen a spell, choose one
939 * I'm not sure if it really make sense to pre-select spells (events 939 * I'm not sure if it really make sense to pre-select spells (events
940 * could be different by the time the monster goes again). 940 * could be different by the time the monster goes again).
942 if (head->spellitem == NULL) 942 if (head->spellitem == NULL)
943 { 943 {
944 if ((spell_item = monster_choose_random_spell (head)) == NULL) 944 if ((spell_item = monster_choose_random_spell (head)) == NULL)
945 { 945 {
946 LOG (llevMonster, "Turned off spells in %s\n", &head->name); 946 LOG (llevMonster, "Turned off spells in %s\n", &head->name);
947 CLEAR_FLAG (head, FLAG_CAST_SPELL); /* Will be turned on when picking up book */ 947 head->clr_flag (FLAG_CAST_SPELL); /* Will be turned on when picking up book */
948 return 0; 948 return 0;
949 } 949 }
950 950
951 if (spell_item->type == SPELLBOOK) 951 if (spell_item->type == SPELLBOOK)
952 { 952 {
999 * other monsters) 999 * other monsters)
1000 */ 1000 */
1001 if (!(dir = path_to_player (part, pl, 0))) 1001 if (!(dir = path_to_player (part, pl, 0)))
1002 return 0; 1002 return 0;
1003 1003
1004 if (QUERY_FLAG (head, FLAG_FRIENDLY) && (owner = head->owner) != NULL) 1004 if (head->flag [FLAG_FRIENDLY] && (owner = head->owner) != NULL)
1005 { 1005 {
1006 get_rangevector (head, owner, &rv1, 0x1); 1006 get_rangevector (head, owner, &rv1, 0x1);
1007 if (dirdiff (dir, rv1.direction) < 2) 1007 if (dirdiff (dir, rv1.direction) < 2)
1008 { 1008 {
1009 return 0; /* Might hit owner with spell */ 1009 return 0; /* Might hit owner with spell */
1010 } 1010 }
1011 } 1011 }
1012 1012
1013 if (QUERY_FLAG (head, FLAG_CONFUSED)) 1013 if (head->flag [FLAG_CONFUSED])
1014 dir = absdir (dir + rndm (3) + rndm (3) - 2); 1014 dir = absdir (dir + rndm (3) + rndm (3) - 2);
1015 1015
1016 for (scroll = head->inv; scroll; scroll = scroll->below) 1016 for (scroll = head->inv; scroll; scroll = scroll->below)
1017 if (scroll->type == SCROLL && monster_should_cast_spell (head, scroll->inv)) 1017 if (scroll->type == SCROLL && monster_should_cast_spell (head, scroll->inv))
1018 break; 1018 break;
1019 1019
1020 /* Used up all his scrolls, so nothing do to */ 1020 /* Used up all his scrolls, so nothing do to */
1021 if (!scroll) 1021 if (!scroll)
1022 { 1022 {
1023 CLEAR_FLAG (head, FLAG_READY_SCROLL); 1023 head->clr_flag (FLAG_READY_SCROLL);
1024 return 0; 1024 return 0;
1025 } 1025 }
1026 1026
1027 /* Spell should be cast on caster (ie, heal, strength) */ 1027 /* Spell should be cast on caster (ie, heal, strength) */
1028 if (scroll->inv->range == 0) 1028 if (scroll->inv->range == 0)
1049 object *skill, *owner; 1049 object *skill, *owner;
1050 1050
1051 if (!(dir = path_to_player (part, pl, 0))) 1051 if (!(dir = path_to_player (part, pl, 0)))
1052 return 0; 1052 return 0;
1053 1053
1054 if (QUERY_FLAG (head, FLAG_FRIENDLY) && (owner = head->owner) != NULL) 1054 if (head->flag [FLAG_FRIENDLY] && (owner = head->owner) != NULL)
1055 { 1055 {
1056 int dir2 = find_dir_2 (head->x - owner->x, head->y - owner->y); 1056 int dir2 = find_dir_2 (head->x - owner->x, head->y - owner->y);
1057 1057
1058 if (dirdiff (dir, dir2) < 1) 1058 if (dirdiff (dir, dir2) < 1)
1059 return 0; /* Might hit owner with skill -thrown rocks for example ? */ 1059 return 0; /* Might hit owner with skill -thrown rocks for example ? */
1060 } 1060 }
1061 1061
1062 if (QUERY_FLAG (head, FLAG_CONFUSED)) 1062 if (head->flag [FLAG_CONFUSED])
1063 dir = absdir (dir + rndm (3) + rndm (3) - 2); 1063 dir = absdir (dir + rndm (3) + rndm (3) - 2);
1064 1064
1065 object *new_skill = 0; 1065 object *new_skill = 0;
1066 1066
1067 // skill selection - monster will use the last unused skill 1067 // skill selection - monster will use the last unused skill
1073 if (new_skill) 1073 if (new_skill)
1074 splay (head->chosen_skill = new_skill); 1074 splay (head->chosen_skill = new_skill);
1075 else if (!head->chosen_skill) 1075 else if (!head->chosen_skill)
1076 { 1076 {
1077 LOG (llevDebug, "Error: Monster %s (%d) has FLAG_READY_SKILL without skill.\n", &head->name, head->count); 1077 LOG (llevDebug, "Error: Monster %s (%d) has FLAG_READY_SKILL without skill.\n", &head->name, head->count);
1078 CLEAR_FLAG (head, FLAG_READY_SKILL); 1078 head->clr_flag (FLAG_READY_SKILL);
1079 return 0; 1079 return 0;
1080 } 1080 }
1081 1081
1082 /* use skill */ 1082 /* use skill */
1083 return do_skill (head, part, head->chosen_skill, dir, NULL); 1083 return do_skill (head, part, head->chosen_skill, dir, NULL);
1091 int at_least_one = 0; 1091 int at_least_one = 0;
1092 1092
1093 if (!(dir = path_to_player (part, pl, 0))) 1093 if (!(dir = path_to_player (part, pl, 0)))
1094 return 0; 1094 return 0;
1095 1095
1096 if (QUERY_FLAG (head, FLAG_FRIENDLY) && (owner = head->owner) != NULL) 1096 if (head->flag [FLAG_FRIENDLY] && (owner = head->owner) != NULL)
1097 { 1097 {
1098 int dir2 = find_dir_2 (head->x - owner->x, head->y - owner->y); 1098 int dir2 = find_dir_2 (head->x - owner->x, head->y - owner->y);
1099 1099
1100 if (dirdiff (dir, dir2) < 2) 1100 if (dirdiff (dir, dir2) < 2)
1101 return 0; /* Might hit owner with spell */ 1101 return 0; /* Might hit owner with spell */
1102 } 1102 }
1103 1103
1104 if (QUERY_FLAG (head, FLAG_CONFUSED)) 1104 if (head->flag [FLAG_CONFUSED])
1105 dir = absdir (dir + rndm (3) + rndm (3) - 2); 1105 dir = absdir (dir + rndm (3) + rndm (3) - 2);
1106 1106
1107 for (wand = head->inv; wand; wand = wand->below) 1107 for (wand = head->inv; wand; wand = wand->below)
1108 { 1108 {
1109 if (wand->type == WAND) 1109 if (wand->type == WAND)
1117 1117
1118 if (!(--wand->stats.food)) 1118 if (!(--wand->stats.food))
1119 { 1119 {
1120 if (wand->arch) 1120 if (wand->arch)
1121 { 1121 {
1122 CLEAR_FLAG (wand, FLAG_ANIMATE); 1122 wand->clr_flag (FLAG_ANIMATE);
1123 wand->face = wand->arch->face; 1123 wand->face = wand->arch->face;
1124 wand->set_speed (0); 1124 wand->set_speed (0);
1125 } 1125 }
1126 } 1126 }
1127 /* Success */ 1127 /* Success */
1148 1148
1149 if (at_least_one) 1149 if (at_least_one)
1150 return 0; 1150 return 0;
1151 1151
1152 LOG (llevError, "Error: Monster %s (%d) HAS_READY_RANGE() without wand/horn/rod.\n", &head->name, head->count); 1152 LOG (llevError, "Error: Monster %s (%d) HAS_READY_RANGE() without wand/horn/rod.\n", &head->name, head->count);
1153 CLEAR_FLAG (head, FLAG_READY_RANGE); 1153 head->clr_flag (FLAG_READY_RANGE);
1154 return 0; 1154 return 0;
1155} 1155}
1156 1156
1157static int 1157static int
1158monster_use_bow (object *head, object *part, object *pl, int dir) 1158monster_use_bow (object *head, object *part, object *pl, int dir)
1160 object *owner; 1160 object *owner;
1161 1161
1162 if (!(dir = path_to_player (part, pl, 0))) 1162 if (!(dir = path_to_player (part, pl, 0)))
1163 return 0; 1163 return 0;
1164 1164
1165 if (QUERY_FLAG (head, FLAG_CONFUSED)) 1165 if (head->flag [FLAG_CONFUSED])
1166 dir = absdir (dir + rndm (3) + rndm (3) - 2); 1166 dir = absdir (dir + rndm (3) + rndm (3) - 2);
1167 1167
1168 if (QUERY_FLAG (head, FLAG_FRIENDLY) && (owner = head->owner) != NULL) 1168 if (head->flag [FLAG_FRIENDLY] && (owner = head->owner) != NULL)
1169 { 1169 {
1170 int dir2 = find_dir_2 (head->x - owner->x, head->y - owner->y); 1170 int dir2 = find_dir_2 (head->x - owner->x, head->y - owner->y);
1171 1171
1172 if (dirdiff (dir, dir2) < 1) 1172 if (dirdiff (dir, dir2) < 1)
1173 return 0; /* Might hit owner with arrow */ 1173 return 0; /* Might hit owner with arrow */
1188 /* If nothing alive on this space, no need to search the space. */ 1188 /* If nothing alive on this space, no need to search the space. */
1189 if (!(ms.flags () & P_IS_ALIVE)) 1189 if (!(ms.flags () & P_IS_ALIVE))
1190 continue; 1190 continue;
1191 1191
1192 for (object *npc = ms.bot; npc; npc = npc->above) 1192 for (object *npc = ms.bot; npc; npc = npc->above)
1193 if (QUERY_FLAG (npc, FLAG_ALIVE) && QUERY_FLAG (npc, FLAG_UNAGGRESSIVE)) 1193 if (npc->flag [FLAG_ALIVE] && npc->flag [FLAG_UNAGGRESSIVE])
1194 npc->enemy = op->enemy; 1194 npc->enemy = op->enemy;
1195 } 1195 }
1196} 1196}
1197 1197
1198void 1198void
1238 * marked item and throw it to the enemy. 1238 * marked item and throw it to the enemy.
1239 */ 1239 */
1240 for (tmp = op->inv; tmp; tmp = tmp->below) 1240 for (tmp = op->inv; tmp; tmp = tmp->below)
1241 { 1241 {
1242 /* Can't throw invisible objects or items that are applied */ 1242 /* Can't throw invisible objects or items that are applied */
1243 if (tmp->invisible || QUERY_FLAG (tmp, FLAG_APPLIED)) 1243 if (tmp->invisible || tmp->flag [FLAG_APPLIED])
1244 continue; 1244 continue;
1245 1245
1246 if (QUERY_FLAG (tmp, FLAG_IS_THROWN)) 1246 if (tmp->flag [FLAG_IS_THROWN])
1247 break; 1247 break;
1248 1248
1249 } 1249 }
1250 1250
1251#ifdef DEBUG_THROW 1251#ifdef DEBUG_THROW
1273 1273
1274 /* for target facing, we copy this value here for fast access */ 1274 /* for target facing, we copy this value here for fast access */
1275 if (oph->head) /* force update the head - one arch one pic */ 1275 if (oph->head) /* force update the head - one arch one pic */
1276 oph = oph->head; 1276 oph = oph->head;
1277 1277
1278 if (QUERY_FLAG (op, FLAG_NO_ATTACK)) /* we never ever attack */ 1278 if (op->flag [FLAG_NO_ATTACK]) /* we never ever attack */
1279 enemy = op->enemy = NULL; 1279 enemy = op->enemy = NULL;
1280 else if ((enemy = find_enemy (op, &rv))) 1280 else if ((enemy = find_enemy (op, &rv)))
1281 /* we have an enemy, just tell him we want him dead */ 1281 /* we have an enemy, just tell him we want him dead */
1282 enemy->attacked_by = op; /* our ptr */ 1282 enemy->attacked_by = op; /* our ptr */
1283 1283
1313 } 1313 }
1314 1314
1315 /* this should probably get modified by many more values. 1315 /* this should probably get modified by many more values.
1316 * (eg, creatures resistance to fear, level, etc. ) 1316 * (eg, creatures resistance to fear, level, etc. )
1317 */ 1317 */
1318 if (QUERY_FLAG (op, FLAG_SCARED) && !(rndm (20))) 1318 if (op->flag [FLAG_SCARED] && !(rndm (20)))
1319 CLEAR_FLAG (op, FLAG_SCARED); /* Time to regain some "guts"... */ 1319 op->clr_flag (FLAG_SCARED); /* Time to regain some "guts"... */
1320 1320
1321 if (INVOKE_OBJECT (MONSTER_MOVE, op, ARG_OBJECT (op->enemy))) 1321 if (INVOKE_OBJECT (MONSTER_MOVE, op, ARG_OBJECT (op->enemy)))
1322 return QUERY_FLAG (op, FLAG_FREED); 1322 return op->flag [FLAG_FREED];
1323 1323
1324 if (QUERY_FLAG (op, FLAG_SLEEP) || QUERY_FLAG (op, FLAG_BLIND) || 1324 if (op->flag [FLAG_SLEEP] || op->flag [FLAG_BLIND] ||
1325 ((op->map->darklevel () > 0) && !QUERY_FLAG (op, FLAG_SEE_IN_DARK) && !QUERY_FLAG (op, FLAG_SEE_INVISIBLE))) 1325 ((op->map->darklevel () > 0) && !op->flag [FLAG_SEE_IN_DARK] && !op->flag [FLAG_SEE_INVISIBLE]))
1326 if (!check_wakeup (op, enemy, &rv)) 1326 if (!check_wakeup (op, enemy, &rv))
1327 return 0; 1327 return 0;
1328 1328
1329 /* check if monster pops out of hidden spot */ 1329 /* check if monster pops out of hidden spot */
1330 if (op->flag [FLAG_HIDDEN]) 1330 if (op->flag [FLAG_HIDDEN])
1337 monster_apply_below (op); /* Check for items to apply below */ 1337 monster_apply_below (op); /* Check for items to apply below */
1338 1338
1339 /* If we don't have an enemy, do special movement or the like */ 1339 /* If we don't have an enemy, do special movement or the like */
1340 if (!enemy) 1340 if (!enemy)
1341 { 1341 {
1342 if (QUERY_FLAG (op, FLAG_ONLY_ATTACK)) 1342 if (op->flag [FLAG_ONLY_ATTACK])
1343 { 1343 {
1344 op->drop_and_destroy (); 1344 op->drop_and_destroy ();
1345 return 1; 1345 return 1;
1346 } 1346 }
1347 1347
1348 /* Probably really a bug for a creature to have both 1348 /* Probably really a bug for a creature to have both
1349 * stand still and a movement type set. 1349 * stand still and a movement type set.
1350 */ 1350 */
1351 if (!QUERY_FLAG (op, FLAG_STAND_STILL)) 1351 if (!op->flag [FLAG_STAND_STILL])
1352 { 1352 {
1353 if (op->attack_movement & HI4) 1353 if (op->attack_movement & HI4)
1354 { 1354 {
1355 switch (op->attack_movement & HI4) 1355 switch (op->attack_movement & HI4)
1356 { 1356 {
1391 break; 1391 break;
1392 } 1392 }
1393 1393
1394 return 0; 1394 return 0;
1395 } 1395 }
1396 else if (QUERY_FLAG (op, FLAG_RANDOM_MOVE)) 1396 else if (op->flag [FLAG_RANDOM_MOVE])
1397 move_randomly (op); 1397 move_randomly (op);
1398 } /* stand still */ 1398 } /* stand still */
1399 1399
1400 return 0; 1400 return 0;
1401 } /* no enemy */ 1401 } /* no enemy */
1426 1426
1427 /* Move the check for scared up here - if the monster was scared, 1427 /* Move the check for scared up here - if the monster was scared,
1428 * we were not doing any of the logic below, so might as well save 1428 * we were not doing any of the logic below, so might as well save
1429 * a few cpu cycles. 1429 * a few cpu cycles.
1430 */ 1430 */
1431 if (!QUERY_FLAG (op, FLAG_SCARED)) 1431 if (!op->flag [FLAG_SCARED])
1432 { 1432 {
1433 rv_vector rv1; 1433 rv_vector rv1;
1434 1434
1435 /* now we test every part of an object .... this is a real ugly piece of code */ 1435 /* now we test every part of an object .... this is a real ugly piece of code */
1436 for (part = op; part; part = part->more) 1436 for (part = op; part; part = part->more)
1439 dir = rv1.direction; 1439 dir = rv1.direction;
1440 1440
1441 /* hm, not sure about this part - in original was a scared flag here too 1441 /* hm, not sure about this part - in original was a scared flag here too
1442 * but that we test above... so can be old code here 1442 * but that we test above... so can be old code here
1443 */ 1443 */
1444 if (QUERY_FLAG (op, FLAG_RUN_AWAY)) 1444 if (op->flag [FLAG_RUN_AWAY])
1445 dir = absdir (dir + 4); 1445 dir = absdir (dir + 4);
1446 1446
1447 if (QUERY_FLAG (op, FLAG_CONFUSED)) 1447 if (op->flag [FLAG_CONFUSED])
1448 dir = absdir (dir + rndm (3) + rndm (3) - 2); 1448 dir = absdir (dir + rndm (3) + rndm (3) - 2);
1449 1449
1450 if (QUERY_FLAG (op, FLAG_CAST_SPELL) && !(rndm (3))) 1450 if (op->flag [FLAG_CAST_SPELL] && !(rndm (3)))
1451 if (monster_cast_spell (op, part, enemy, dir, &rv1)) 1451 if (monster_cast_spell (op, part, enemy, dir, &rv1))
1452 return 0; 1452 return 0;
1453 1453
1454 if (QUERY_FLAG (op, FLAG_READY_SCROLL) && !(rndm (3))) 1454 if (op->flag [FLAG_READY_SCROLL] && !(rndm (3)))
1455 if (monster_use_scroll (op, part, enemy, dir, &rv1)) 1455 if (monster_use_scroll (op, part, enemy, dir, &rv1))
1456 return 0; 1456 return 0;
1457 1457
1458 if (QUERY_FLAG (op, FLAG_READY_RANGE) && !(rndm (3))) 1458 if (op->flag [FLAG_READY_RANGE] && !(rndm (3)))
1459 if (monster_use_range (op, part, enemy, dir)) 1459 if (monster_use_range (op, part, enemy, dir))
1460 return 0; 1460 return 0;
1461 1461
1462 if (QUERY_FLAG (op, FLAG_READY_SKILL) && !(rndm (3))) 1462 if (op->flag [FLAG_READY_SKILL] && !(rndm (3)))
1463 if (monster_use_skill (op, rv.part, enemy, rv.direction)) 1463 if (monster_use_skill (op, rv.part, enemy, rv.direction))
1464 return 0; 1464 return 0;
1465 1465
1466 if (QUERY_FLAG (op, FLAG_READY_BOW) && !(rndm (2))) 1466 if (op->flag [FLAG_READY_BOW] && !(rndm (2)))
1467 if (monster_use_bow (op, part, enemy, dir)) 1467 if (monster_use_bow (op, part, enemy, dir))
1468 return 0; 1468 return 0;
1469 } /* for processing of all parts */ 1469 } /* for processing of all parts */
1470 } /* If not scared */ 1470 } /* If not scared */
1471 1471
1518 } 1518 }
1519 } 1519 }
1520 1520
1521//+GPL 1521//+GPL
1522 1522
1523 if (QUERY_FLAG (op, FLAG_SCARED) || QUERY_FLAG (op, FLAG_RUN_AWAY)) 1523 if (op->flag [FLAG_SCARED] || op->flag [FLAG_RUN_AWAY])
1524 dir = absdir (dir + 4); 1524 dir = absdir (dir + 4);
1525 1525
1526 if (QUERY_FLAG (op, FLAG_CONFUSED)) 1526 if (op->flag [FLAG_CONFUSED])
1527 dir = absdir (dir + rndm (3) + rndm (3) - 2); 1527 dir = absdir (dir + rndm (3) + rndm (3) - 2);
1528 1528
1529 pre_att_dir = dir; /* remember the original direction */ 1529 pre_att_dir = dir; /* remember the original direction */
1530 1530
1531 if ((op->attack_movement & LO4) && !QUERY_FLAG (op, FLAG_SCARED)) 1531 if ((op->attack_movement & LO4) && !op->flag [FLAG_SCARED])
1532 { 1532 {
1533 switch (op->attack_movement & LO4) 1533 switch (op->attack_movement & LO4)
1534 { 1534 {
1535 case DISTATT: 1535 case DISTATT:
1536 dir = dist_att (dir, op, enemy, part, &rv); 1536 dir = dist_att (dir, op, enemy, part, &rv);
1566 } 1566 }
1567 1567
1568 if (!dir) 1568 if (!dir)
1569 return 0; 1569 return 0;
1570 1570
1571 if (!QUERY_FLAG (op, FLAG_STAND_STILL)) 1571 if (!op->flag [FLAG_STAND_STILL])
1572 { 1572 {
1573 if (op->move (dir)) /* Can the monster move directly toward player? */ 1573 if (op->move (dir)) /* Can the monster move directly toward player? */
1574 { 1574 {
1575 /* elmex: Turn our monster after it moved if it has DISTATT attack */ 1575 /* elmex: Turn our monster after it moved if it has DISTATT attack */
1576 if ((op->attack_movement & LO4) == DISTATT) 1576 if ((op->attack_movement & LO4) == DISTATT)
1577 op->direction = pre_att_dir; 1577 op->direction = pre_att_dir;
1578 1578
1579 return 0; 1579 return 0;
1580 } 1580 }
1581 1581
1582 if (QUERY_FLAG (op, FLAG_SCARED) || !can_hit (part, enemy, &rv) || QUERY_FLAG (op, FLAG_RUN_AWAY)) 1582 if (op->flag [FLAG_SCARED] || !can_hit (part, enemy, &rv) || op->flag [FLAG_RUN_AWAY])
1583 { 1583 {
1584 /* Try move around corners if !close */ 1584 /* Try move around corners if !close */
1585 int maxdiff = (QUERY_FLAG (op, FLAG_ONLY_ATTACK) || rndm (2)) ? 1 : 2; 1585 int maxdiff = (op->flag [FLAG_ONLY_ATTACK] || rndm (2)) ? 1 : 2;
1586 1586
1587 for (diff = 1; diff <= maxdiff; diff++) 1587 for (diff = 1; diff <= maxdiff; diff++)
1588 { 1588 {
1589 /* try different detours */ 1589 /* try different detours */
1590 int m = 1 - rndm (2) * 2; /* Try left or right first? */ 1590 int m = 1 - rndm (2) * 2; /* Try left or right first? */
1601 1601
1602 /* 1602 /*
1603 * Eneq(@csd.uu.se): Patch to make RUN_AWAY or SCARED monsters move a random 1603 * Eneq(@csd.uu.se): Patch to make RUN_AWAY or SCARED monsters move a random
1604 * direction if they can't move away. 1604 * direction if they can't move away.
1605 */ 1605 */
1606 if (!QUERY_FLAG (op, FLAG_ONLY_ATTACK) && (QUERY_FLAG (op, FLAG_RUN_AWAY) || QUERY_FLAG (op, FLAG_SCARED))) 1606 if (!op->flag [FLAG_ONLY_ATTACK] && (op->flag [FLAG_RUN_AWAY] || op->flag [FLAG_SCARED]))
1607 if (move_randomly (op)) 1607 if (move_randomly (op))
1608 return 0; 1608 return 0;
1609 1609
1610 /* 1610 /*
1611 * Try giving the monster a new enemy - the player that is closest 1611 * Try giving the monster a new enemy - the player that is closest
1616 * are two players flanking the monster at close distance, but which 1616 * are two players flanking the monster at close distance, but which
1617 * the monster can't get to, and a third one at a far distance that 1617 * the monster can't get to, and a third one at a far distance that
1618 * the monster could get to - as it is, the monster won't look at that 1618 * the monster could get to - as it is, the monster won't look at that
1619 * third one. 1619 * third one.
1620 */ 1620 */
1621 if (!QUERY_FLAG (op, FLAG_FRIENDLY) && enemy == op->enemy) 1621 if (!op->flag [FLAG_FRIENDLY] && enemy == op->enemy)
1622 { 1622 {
1623 object *nearest_player = get_nearest_player (op); 1623 object *nearest_player = get_nearest_player (op);
1624 1624
1625 if (nearest_player && nearest_player != enemy && !can_hit (part, enemy, &rv)) 1625 if (nearest_player && nearest_player != enemy && !can_hit (part, enemy, &rv))
1626 { 1626 {
1627 op->enemy = 0; 1627 op->enemy = 0;
1628 enemy = nearest_player; 1628 enemy = nearest_player;
1629 } 1629 }
1630 } 1630 }
1631 1631
1632 if (!QUERY_FLAG (op, FLAG_SCARED) && can_hit (part, enemy, &rv)) 1632 if (!op->flag [FLAG_SCARED] && can_hit (part, enemy, &rv))
1633 { 1633 {
1634 /* The adjustement to wc that was here before looked totally bogus - 1634 /* The adjustement to wc that was here before looked totally bogus -
1635 * since wc can in fact get negative, that would mean by adding 1635 * since wc can in fact get negative, that would mean by adding
1636 * the current wc, the creature gets better? Instead, just 1636 * the current wc, the creature gets better? Instead, just
1637 * add a fixed amount - nasty creatures that are runny away should 1637 * add a fixed amount - nasty creatures that are runny away should
1638 * still be pretty nasty. 1638 * still be pretty nasty.
1639 */ 1639 */
1640 if (QUERY_FLAG (op, FLAG_RUN_AWAY)) 1640 if (op->flag [FLAG_RUN_AWAY])
1641 { 1641 {
1642 part->stats.wc += 10; 1642 part->stats.wc += 10;
1643 skill_attack (enemy, part, 0, NULL, NULL); 1643 skill_attack (enemy, part, 0, NULL, NULL);
1644 part->stats.wc -= 10; 1644 part->stats.wc -= 10;
1645 } 1645 }
1646 else 1646 else
1647 skill_attack (enemy, part, 0, NULL, NULL); 1647 skill_attack (enemy, part, 0, NULL, NULL);
1648 } /* if monster is in attack range */ 1648 } /* if monster is in attack range */
1649 1649
1650 if (QUERY_FLAG (part, FLAG_FREED)) /* Might be freed by ghost-attack or hit-back */ 1650 if (part->flag [FLAG_FREED]) /* Might be freed by ghost-attack or hit-back */
1651 return 1; 1651 return 1;
1652 1652
1653 if (QUERY_FLAG (op, FLAG_ONLY_ATTACK)) 1653 if (op->flag [FLAG_ONLY_ATTACK])
1654 { 1654 {
1655 op->drop_and_destroy (); 1655 op->drop_and_destroy ();
1656 return 1; 1656 return 1;
1657 } 1657 }
1658 1658
1680 return 0; 1680 return 0;
1681 1681
1682 get_rangevector (op, enemy, rv, 0); 1682 get_rangevector (op, enemy, rv, 0);
1683 1683
1684 /* Monsters always ignore the DM */ 1684 /* Monsters always ignore the DM */
1685 if (!op->is_player () && QUERY_FLAG (enemy, FLAG_WIZ)) 1685 if (!op->is_player () && enemy->flag [FLAG_WIZ])
1686 return 0; 1686 return 0;
1687 1687
1688 /* simple check. Should probably put some range checks in here. */ 1688 /* simple check. Should probably put some range checks in here. */
1689 if (can_see_enemy (op, enemy)) 1689 if (can_see_enemy (op, enemy))
1690 return 1; 1690 return 1;
1731 hide_discovery += bonus * 5; 1731 hide_discovery += bonus * 5;
1732 } /* else creature has modifiers for hiding */ 1732 } /* else creature has modifiers for hiding */
1733 1733
1734 /* Radii stealth adjustment. Only if you are stealthy 1734 /* Radii stealth adjustment. Only if you are stealthy
1735 * will you be able to sneak up closer to creatures */ 1735 * will you be able to sneak up closer to creatures */
1736 if (QUERY_FLAG (enemy, FLAG_STEALTH)) 1736 if (enemy->flag [FLAG_STEALTH])
1737 { 1737 {
1738 radius /= 2; 1738 radius /= 2;
1739 hide_discovery /= 3; 1739 hide_discovery /= 3;
1740 } 1740 }
1741 1741
1743 if (!stand_in_light (enemy)) 1743 if (!stand_in_light (enemy))
1744 { 1744 {
1745 /* on dark maps body heat can help indicate location with infravision 1745 /* on dark maps body heat can help indicate location with infravision
1746 * undead don't have body heat, so no benefit detecting them. 1746 * undead don't have body heat, so no benefit detecting them.
1747 */ 1747 */
1748 if (QUERY_FLAG (op, FLAG_SEE_IN_DARK) && !is_true_undead (enemy)) 1748 if (op->flag [FLAG_SEE_IN_DARK] && !is_true_undead (enemy))
1749 radius += op->map->darklevel () / 2; 1749 radius += op->map->darklevel () / 2;
1750 else 1750 else
1751 radius -= op->map->darklevel () / 2; 1751 radius -= op->map->darklevel () / 2;
1752 1752
1753 /* op next to a monster (and not in complete darkness) 1753 /* op next to a monster (and not in complete darkness)
1854can_see_enemy (object *op, object *enemy) 1854can_see_enemy (object *op, object *enemy)
1855{ 1855{
1856 object *looker = op->head ? op->head : op; 1856 object *looker = op->head ? op->head : op;
1857 1857
1858 /* safety */ 1858 /* safety */
1859 if (!looker || !enemy || !QUERY_FLAG (looker, FLAG_ALIVE)) 1859 if (!looker || !enemy || !looker->flag [FLAG_ALIVE])
1860 return 0; 1860 return 0;
1861 1861
1862 /* we dont give a full treatment of xrays here (shorter range than normal, 1862 /* we dont give a full treatment of xrays here (shorter range than normal,
1863 * see through walls). Should we change the code elsewhere to make you 1863 * see through walls). Should we change the code elsewhere to make you
1864 * blind even if you can xray? 1864 * blind even if you can xray?
1865 */ 1865 */
1866 if (QUERY_FLAG (looker, FLAG_BLIND) && !QUERY_FLAG (looker, FLAG_XRAYS)) 1866 if (looker->flag [FLAG_BLIND] && !looker->flag [FLAG_XRAYS])
1867 return 0; 1867 return 0;
1868 1868
1869 /* checking for invisible things */ 1869 /* checking for invisible things */
1870 if (enemy->invisible) 1870 if (enemy->invisible)
1871 { 1871 {
1888 1888
1889 /* Invisible enemy. Break apart the check for invis undead/invis looker 1889 /* Invisible enemy. Break apart the check for invis undead/invis looker
1890 * into more simple checks - the QUERY_FLAG doesn't return 1/0 values, 1890 * into more simple checks - the QUERY_FLAG doesn't return 1/0 values,
1891 * and making it a conditional makes the code pretty ugly. 1891 * and making it a conditional makes the code pretty ugly.
1892 */ 1892 */
1893 if (!QUERY_FLAG (looker, FLAG_SEE_INVISIBLE)) 1893 if (!looker->flag [FLAG_SEE_INVISIBLE])
1894 if (makes_invisible_to (enemy, looker)) 1894 if (makes_invisible_to (enemy, looker))
1895 return 0; 1895 return 0;
1896 } 1896 }
1897 else if (looker->is_player ()) /* for players, a (possible) shortcut */ 1897 else if (looker->is_player ()) /* for players, a (possible) shortcut */
1898 if (player_can_view (looker, enemy)) 1898 if (player_can_view (looker, enemy))
1906 * only relevant for tiled maps, but it is possible that the 1906 * only relevant for tiled maps, but it is possible that the
1907 * enemy is on a bright map and the looker on a dark - in that 1907 * enemy is on a bright map and the looker on a dark - in that
1908 * case, the looker can still see the enemy 1908 * case, the looker can still see the enemy
1909 */ 1909 */
1910 if (!stand_in_light (enemy) 1910 if (!stand_in_light (enemy)
1911 && (!QUERY_FLAG (looker, FLAG_SEE_IN_DARK) || !is_true_undead (looker) || !QUERY_FLAG (looker, FLAG_XRAYS))) 1911 && (!looker->flag [FLAG_SEE_IN_DARK] || !is_true_undead (looker) || !looker->flag [FLAG_XRAYS]))
1912 return 0; 1912 return 0;
1913 1913
1914 return 1; 1914 return 1;
1915} 1915}
1916 1916

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines