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.21 by root, Sun Jan 14 23:35:04 2007 UTC vs.
Revision 1.32 by root, Sat May 12 18:14:48 2007 UTC

1/* 1/*
2 CrossFire, A Multiplayer game for X-windows 2 * CrossFire, A Multiplayer game
3 3 *
4 Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team 4 * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team
5 Copyright (C) 2002 Mark Wedel & Crossfire Development Team 5 * Copyright (C) 2002 Mark Wedel & Crossfire Development Team
6 Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (C) 1992 Frank Tore Johansen
7 7 *
8 This program is free software; you can redistribute it and/or modify 8 * This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version. 11 * (at your 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 GNU General Public License
19 along with this program; if not, write to the Free Software 19 * along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 21 *
22 The authors can be reached via e-mail at <crossfire@schmorp.de> 22 * The authors can be reached via e-mail at <crossfire@schmorp.de>
23*/ 23 */
24 24
25#include <global.h> 25#include <global.h>
26#include <sproto.h> 26#include <sproto.h>
27#include <spells.h> 27#include <spells.h>
28#include <skills.h> 28#include <skills.h>
85 * target enemy - this code below makes sure the enemy is something 85 * target enemy - this code below makes sure the enemy is something
86 * that should be attacked. My guess is that the arrow hits 86 * that should be attacked. My guess is that the arrow hits
87 * the creature/owner, and so the creature then takes that 87 * the creature/owner, and so the creature then takes that
88 * as the enemy to attack. 88 * as the enemy to attack.
89 */ 89 */
90 else if (!QUERY_FLAG (npc->enemy, FLAG_MONSTER) && 90 else if (!QUERY_FLAG (npc->enemy, FLAG_MONSTER)
91 !QUERY_FLAG (npc->enemy, FLAG_GENERATOR) && npc->enemy->type != PLAYER && npc->enemy->type != GOLEM) 91 && !QUERY_FLAG (npc->enemy, FLAG_GENERATOR)
92 && npc->enemy->type != PLAYER
93 && npc->enemy->type != GOLEM)
92 npc->enemy = NULL; 94 npc->enemy = NULL;
93 95
94 } 96 }
95 return can_detect_enemy (npc, npc->enemy, rv) ? npc->enemy : NULL; 97 return can_detect_enemy (npc, npc->enemy, rv) ? npc->enemy : NULL;
96} 98}
278 int i; 280 int i;
279 281
280 /* Give up to 15 chances for a monster to move randomly */ 282 /* Give up to 15 chances for a monster to move randomly */
281 for (i = 0; i < 15; i++) 283 for (i = 0; i < 15; i++)
282 { 284 {
283 if (move_object (op, RANDOM () % 8 + 1)) 285 if (move_object (op, rndm (8) + 1))
284 return 1; 286 return 1;
285 } 287 }
286 return 0; 288 return 0;
287} 289}
288 290
357 } 359 }
358 360
359 /* this should probably get modified by many more values. 361 /* this should probably get modified by many more values.
360 * (eg, creatures resistance to fear, level, etc. ) 362 * (eg, creatures resistance to fear, level, etc. )
361 */ 363 */
362 if (QUERY_FLAG (op, FLAG_SCARED) && !(RANDOM () % 20)) 364 if (QUERY_FLAG (op, FLAG_SCARED) && !(rndm (20)))
363 { 365 {
364 CLEAR_FLAG (op, FLAG_SCARED); /* Time to regain some "guts"... */ 366 CLEAR_FLAG (op, FLAG_SCARED); /* Time to regain some "guts"... */
365 } 367 }
366 368
367 if (INVOKE_OBJECT (MONSTER_MOVE, op, ARG_OBJECT (op->enemy))) 369 if (INVOKE_OBJECT (MONSTER_MOVE, op, ARG_OBJECT (op->enemy)))
446 } /* stand still */ 448 } /* stand still */
447 return 0; 449 return 0;
448 } /* no enemy */ 450 } /* no enemy */
449 451
450 /* We have an enemy. Block immediately below is for pets */ 452 /* We have an enemy. Block immediately below is for pets */
451 if ((op->attack_movement & HI4) == PETMOVE && (owner = op->owner) != NULL && !on_same_map (op, owner)) 453 if ((op->attack_movement & HI4) == PETMOVE
454 && (owner = op->owner) != NULL
455 && !on_same_map (op, owner)
456 && !owner->flag [FLAG_REMOVED])
452 return follow_owner (op, owner); 457 return follow_owner (op, owner);
453 458
454 /* doppleganger code to change monster facing to that of the nearest 459 /* doppleganger code to change monster facing to that of the nearest
455 * player. Hmm. The code is here, but no monster in the current 460 * player. Hmm. The code is here, but no monster in the current
456 * arch set uses it. 461 * arch set uses it.
475 if (!QUERY_FLAG (op, FLAG_SCARED)) 480 if (!QUERY_FLAG (op, FLAG_SCARED))
476 { 481 {
477 rv_vector rv1; 482 rv_vector rv1;
478 483
479 /* now we test every part of an object .... this is a real ugly piece of code */ 484 /* now we test every part of an object .... this is a real ugly piece of code */
480 for (part = op; part != NULL; part = part->more) 485 for (part = op; part; part = part->more)
481 { 486 {
482 get_rangevector (part, enemy, &rv1, 0x1); 487 get_rangevector (part, enemy, &rv1, 0x1);
483 dir = rv1.direction; 488 dir = rv1.direction;
484 489
485 /* hm, not sure about this part - in original was a scared flag here too 490 /* hm, not sure about this part - in original was a scared flag here too
486 * but that we test above... so can be old code here 491 * but that we test above... so can be old code here
487 */ 492 */
488 if (QUERY_FLAG (op, FLAG_RUN_AWAY)) 493 if (QUERY_FLAG (op, FLAG_RUN_AWAY))
489 dir = absdir (dir + 4); 494 dir = absdir (dir + 4);
495
490 if (QUERY_FLAG (op, FLAG_CONFUSED)) 496 if (QUERY_FLAG (op, FLAG_CONFUSED))
491 dir = absdir (dir + RANDOM () % 3 + RANDOM () % 3 - 2); 497 dir = absdir (dir + rndm (3) + rndm (3) - 2);
492 498
493 if (QUERY_FLAG (op, FLAG_CAST_SPELL) && !(RANDOM () % 3)) 499 if (QUERY_FLAG (op, FLAG_CAST_SPELL) && !(rndm (3)))
494 {
495 if (monster_cast_spell (op, part, enemy, dir, &rv1)) 500 if (monster_cast_spell (op, part, enemy, dir, &rv1))
496 return 0; 501 return 0;
497 }
498 502
499 if (QUERY_FLAG (op, FLAG_READY_SCROLL) && !(RANDOM () % 3)) 503 if (QUERY_FLAG (op, FLAG_READY_SCROLL) && !(rndm (3)))
500 {
501 if (monster_use_scroll (op, part, enemy, dir, &rv1)) 504 if (monster_use_scroll (op, part, enemy, dir, &rv1))
502 return 0; 505 return 0;
503 }
504 506
505 if (QUERY_FLAG (op, FLAG_READY_RANGE) && !(RANDOM () % 3)) 507 if (QUERY_FLAG (op, FLAG_READY_RANGE) && !(rndm (3)))
506 {
507 if (monster_use_range (op, part, enemy, dir)) 508 if (monster_use_range (op, part, enemy, dir))
508 return 0; 509 return 0;
509 } 510
510 if (QUERY_FLAG (op, FLAG_READY_SKILL) && !(RANDOM () % 3)) 511 if (QUERY_FLAG (op, FLAG_READY_SKILL) && !(rndm (3)))
511 {
512 if (monster_use_skill (op, rv.part, enemy, rv.direction)) 512 if (monster_use_skill (op, rv.part, enemy, rv.direction))
513 return 0; 513 return 0;
514 } 514
515 if (QUERY_FLAG (op, FLAG_READY_BOW) && !(RANDOM () % 2)) 515 if (QUERY_FLAG (op, FLAG_READY_BOW) && !(rndm (2)))
516 {
517 if (monster_use_bow (op, part, enemy, dir)) 516 if (monster_use_bow (op, part, enemy, dir))
518 return 0; 517 return 0;
519 }
520 } /* for processing of all parts */ 518 } /* for processing of all parts */
521 } /* If not scared */ 519 } /* If not scared */
522 520
523 521
524 part = rv.part; 522 part = rv.part;
526 524
527 if (QUERY_FLAG (op, FLAG_SCARED) || QUERY_FLAG (op, FLAG_RUN_AWAY)) 525 if (QUERY_FLAG (op, FLAG_SCARED) || QUERY_FLAG (op, FLAG_RUN_AWAY))
528 dir = absdir (dir + 4); 526 dir = absdir (dir + 4);
529 527
530 if (QUERY_FLAG (op, FLAG_CONFUSED)) 528 if (QUERY_FLAG (op, FLAG_CONFUSED))
531 dir = absdir (dir + RANDOM () % 3 + RANDOM () % 3 - 2); 529 dir = absdir (dir + rndm (3) + rndm (3) - 2);
532 530
533 pre_att_dir = dir; /* remember the original direction */ 531 pre_att_dir = dir; /* remember the original direction */
534 532
535 if ((op->attack_movement & LO4) && !QUERY_FLAG (op, FLAG_SCARED)) 533 if ((op->attack_movement & LO4) && !QUERY_FLAG (op, FLAG_SCARED))
536 { 534 {
668can_hit (object *ob1, object *ob2, rv_vector * rv) 666can_hit (object *ob1, object *ob2, rv_vector * rv)
669{ 667{
670 object *more; 668 object *more;
671 rv_vector rv1; 669 rv_vector rv1;
672 670
673 if (QUERY_FLAG (ob1, FLAG_CONFUSED) && !(RANDOM () % 3)) 671 if (QUERY_FLAG (ob1, FLAG_CONFUSED) && !(rndm (3)))
674 return 0; 672 return 0;
675 673
676 if (abs (rv->distance_x) < 2 && abs (rv->distance_y) < 2) 674 if (abs (rv->distance_x) < 2 && abs (rv->distance_y) < 2)
677 return 1; 675 return 1;
678 676
787 return 0; /* Might hit owner with spell */ 785 return 0; /* Might hit owner with spell */
788 } 786 }
789 } 787 }
790 788
791 if (QUERY_FLAG (head, FLAG_CONFUSED)) 789 if (QUERY_FLAG (head, FLAG_CONFUSED))
792 dir = absdir (dir + RANDOM () % 3 + RANDOM () % 3 - 2); 790 dir = absdir (dir + rndm (3) + rndm (3) - 2);
793 791
794 /* If the monster hasn't already chosen a spell, choose one 792 /* If the monster hasn't already chosen a spell, choose one
795 * I'm not sure if it really make sense to pre-select spells (events 793 * I'm not sure if it really make sense to pre-select spells (events
796 * could be different by the time the monster goes again). 794 * could be different by the time the monster goes again).
797 */ 795 */
864 return 0; /* Might hit owner with spell */ 862 return 0; /* Might hit owner with spell */
865 } 863 }
866 } 864 }
867 865
868 if (QUERY_FLAG (head, FLAG_CONFUSED)) 866 if (QUERY_FLAG (head, FLAG_CONFUSED))
869 dir = absdir (dir + RANDOM () % 3 + RANDOM () % 3 - 2); 867 dir = absdir (dir + rndm (3) + rndm (3) - 2);
870 868
871 for (scroll = head->inv; scroll; scroll = scroll->below) 869 for (scroll = head->inv; scroll; scroll = scroll->below)
872 if (scroll->type == SCROLL && monster_should_cast_spell (head, scroll->inv)) 870 if (scroll->type == SCROLL && monster_should_cast_spell (head, scroll->inv))
873 break; 871 break;
874 872
896 * The skills we are treating here are all but those. -b.t. 894 * The skills we are treating here are all but those. -b.t.
897 * 895 *
898 * At the moment this is only useful for throwing, perhaps for 896 * At the moment this is only useful for throwing, perhaps for
899 * stealing. TODO: This should be more integrated in the game. -MT, 25.11.01 897 * stealing. TODO: This should be more integrated in the game. -MT, 25.11.01
900 */ 898 */
901
902int 899int
903monster_use_skill (object *head, object *part, object *pl, int dir) 900monster_use_skill (object *head, object *part, object *pl, int dir)
904{ 901{
905 object *skill, *owner; 902 object *skill, *owner;
906 903
912 int dir2 = find_dir_2 (head->x - owner->x, head->y - owner->y); 909 int dir2 = find_dir_2 (head->x - owner->x, head->y - owner->y);
913 910
914 if (dirdiff (dir, dir2) < 1) 911 if (dirdiff (dir, dir2) < 1)
915 return 0; /* Might hit owner with skill -thrown rocks for example ? */ 912 return 0; /* Might hit owner with skill -thrown rocks for example ? */
916 } 913 }
914
917 if (QUERY_FLAG (head, FLAG_CONFUSED)) 915 if (QUERY_FLAG (head, FLAG_CONFUSED))
918 dir = absdir (dir + RANDOM () % 3 + RANDOM () % 3 - 2); 916 dir = absdir (dir + rndm (3) + rndm (3) - 2);
919 917
920 /* skill selection - monster will use the next unused skill. 918 /* skill selection - monster will use the next unused skill.
921 * well...the following scenario will allow the monster to 919 * well...the following scenario will allow the monster to
922 * toggle between 2 skills. One day it would be nice to make 920 * toggle between 2 skills. One day it would be nice to make
923 * more skills available to monsters. 921 * more skills available to monsters.
924 */ 922 */
925
926 for (skill = head->inv; skill != NULL; skill = skill->below) 923 for (skill = head->inv; skill; skill = skill->below)
927 if (skill->type == SKILL && skill != head->chosen_skill) 924 if (skill->type == SKILL && skill != head->chosen_skill)
928 { 925 {
929 head->chosen_skill = skill; 926 head->chosen_skill = skill;
930 break; 927 break;
931 } 928 }
934 { 931 {
935 LOG (llevDebug, "Error: Monster %s (%d) has FLAG_READY_SKILL without skill.\n", &head->name, head->count); 932 LOG (llevDebug, "Error: Monster %s (%d) has FLAG_READY_SKILL without skill.\n", &head->name, head->count);
936 CLEAR_FLAG (head, FLAG_READY_SKILL); 933 CLEAR_FLAG (head, FLAG_READY_SKILL);
937 return 0; 934 return 0;
938 } 935 }
936
939 /* use skill */ 937 /* use skill */
940 return do_skill (head, part, head->chosen_skill, dir, NULL); 938 return do_skill (head, part, head->chosen_skill, dir, NULL);
941} 939}
942 940
943/* Monster will use a ranged spell attack. */ 941/* Monster will use a ranged spell attack. */
944
945int 942int
946monster_use_range (object *head, object *part, object *pl, int dir) 943monster_use_range (object *head, object *part, object *pl, int dir)
947{ 944{
948 object *wand, *owner; 945 object *wand, *owner;
949 int at_least_one = 0; 946 int at_least_one = 0;
956 int dir2 = find_dir_2 (head->x - owner->x, head->y - owner->y); 953 int dir2 = find_dir_2 (head->x - owner->x, head->y - owner->y);
957 954
958 if (dirdiff (dir, dir2) < 2) 955 if (dirdiff (dir, dir2) < 2)
959 return 0; /* Might hit owner with spell */ 956 return 0; /* Might hit owner with spell */
960 } 957 }
958
961 if (QUERY_FLAG (head, FLAG_CONFUSED)) 959 if (QUERY_FLAG (head, FLAG_CONFUSED))
962 dir = absdir (dir + RANDOM () % 3 + RANDOM () % 3 - 2); 960 dir = absdir (dir + rndm (3) + rndm (3) - 2);
963 961
964 for (wand = head->inv; wand != NULL; wand = wand->below) 962 for (wand = head->inv; wand; wand = wand->below)
965 { 963 {
966 if (wand->type == WAND) 964 if (wand->type == WAND)
967 { 965 {
968 /* Found a wand, let's see if it has charges left */ 966 /* Found a wand, let's see if it has charges left */
969 at_least_one = 1; 967 at_least_one = 1;
1004 } 1002 }
1005 1003
1006 if (at_least_one) 1004 if (at_least_one)
1007 return 0; 1005 return 0;
1008 1006
1009 LOG (llevError, "Error: Monster %s (%d) HAS_READY_RANG() without wand/horn/rod.\n", &head->name, head->count); 1007 LOG (llevError, "Error: Monster %s (%d) HAS_READY_RANGE() without wand/horn/rod.\n", &head->name, head->count);
1010 CLEAR_FLAG (head, FLAG_READY_RANGE); 1008 CLEAR_FLAG (head, FLAG_READY_RANGE);
1011 return 0; 1009 return 0;
1012} 1010}
1013 1011
1014int 1012int
1016{ 1014{
1017 object *owner; 1015 object *owner;
1018 1016
1019 if (!(dir = path_to_player (part, pl, 0))) 1017 if (!(dir = path_to_player (part, pl, 0)))
1020 return 0; 1018 return 0;
1019
1021 if (QUERY_FLAG (head, FLAG_CONFUSED)) 1020 if (QUERY_FLAG (head, FLAG_CONFUSED))
1022 dir = absdir (dir + RANDOM () % 3 + RANDOM () % 3 - 2); 1021 dir = absdir (dir + rndm (3) + rndm (3) - 2);
1023 1022
1024 if (QUERY_FLAG (head, FLAG_FRIENDLY) && (owner = head->owner) != NULL) 1023 if (QUERY_FLAG (head, FLAG_FRIENDLY) && (owner = head->owner) != NULL)
1025 { 1024 {
1026 int dir2 = find_dir_2 (head->x - owner->x, head->y - owner->y); 1025 int dir2 = find_dir_2 (head->x - owner->x, head->y - owner->y);
1027 1026
1033 return fire_bow (head, part, NULL, dir, 0, part->x, part->y); 1032 return fire_bow (head, part, NULL, dir, 0, part->x, part->y);
1034 1033
1035} 1034}
1036 1035
1037/* Checks if putting on 'item' will make 'who' do more 1036/* Checks if putting on 'item' will make 'who' do more
1038 * damage. This is a very simplistic check - also checking things 1037 * damage. This is a very simplistic check - also checking things
1039 * like speed and ac are also relevant. 1038 * like speed and ac are also relevant.
1040 * 1039 *
1041 * return true if item is a better object. 1040 * return true if item is a better object.
1042 */ 1041 */
1043
1044int 1042int
1045check_good_weapon (object *who, object *item) 1043check_good_weapon (object *who, object *item)
1046{ 1044{
1047 object *other_weap; 1045 object *other_weap;
1048 int val = 0, i; 1046 int val = 0, i;
1049 1047
1050 for (other_weap = who->inv; other_weap != NULL; other_weap = other_weap->below) 1048 for (other_weap = who->inv; other_weap; other_weap = other_weap->below)
1051 if (other_weap->type == item->type && QUERY_FLAG (other_weap, FLAG_APPLIED)) 1049 if (other_weap->type == item->type && QUERY_FLAG (other_weap, FLAG_APPLIED))
1052 break; 1050 break;
1053 1051
1054 if (other_weap == NULL) /* No other weapons */ 1052 if (!other_weap) /* No other weapons */
1055 return 1; 1053 return 1;
1056 1054
1057 /* Rather than go through and apply the new one, and see if it is 1055 /* Rather than go through and apply the new one, and see if it is
1058 * better, just do some simple checks 1056 * better, just do some simple checks
1059 * Put some multipliers for things that hvae several effects, 1057 * Put some multipliers for things that hvae several effects,
1064 val += (item->magic - other_weap->magic) * 3; 1062 val += (item->magic - other_weap->magic) * 3;
1065 /* Monsters don't really get benefits from things like regen rates 1063 /* Monsters don't really get benefits from things like regen rates
1066 * from items. But the bonus for their stats are very important. 1064 * from items. But the bonus for their stats are very important.
1067 */ 1065 */
1068 for (i = 0; i < NUM_STATS; i++) 1066 for (i = 0; i < NUM_STATS; i++)
1069 val += (get_attr_value (&item->stats, i) - get_attr_value (&other_weap->stats, i)) * 2; 1067 val += item->stats.stat (i) - other_weap->stats.stat (i) * 2;
1070 1068
1071 if (val > 0) 1069 if (val > 0)
1072 return 1; 1070 return 1;
1073 else 1071 else
1074 return 0; 1072 return 0;
1075
1076} 1073}
1077 1074
1078int 1075int
1079check_good_armour (object *who, object *item) 1076check_good_armour (object *who, object *item)
1080{ 1077{
1081 object *other_armour; 1078 object *other_armour;
1082 int val = 0, i; 1079 int val = 0, i;
1083 1080
1084 for (other_armour = who->inv; other_armour != NULL; other_armour = other_armour->below) 1081 for (other_armour = who->inv; other_armour; other_armour = other_armour->below)
1085 if (other_armour->type == item->type && QUERY_FLAG (other_armour, FLAG_APPLIED)) 1082 if (other_armour->type == item->type && QUERY_FLAG (other_armour, FLAG_APPLIED))
1086 break; 1083 break;
1087 1084
1088 if (other_armour == NULL) /* No other armour, use the new */ 1085 if (other_armour == NULL) /* No other armour, use the new */
1089 return 1; 1086 return 1;
1111 1108
1112 if (val > 0) 1109 if (val > 0)
1113 return 1; 1110 return 1;
1114 else 1111 else
1115 return 0; 1112 return 0;
1116
1117} 1113}
1118 1114
1119/* 1115/*
1120 * monster_check_pickup(): checks for items that monster can pick up. 1116 * monster_check_pickup(): checks for items that monster can pick up.
1121 * 1117 *
1129 * This function was seen be continueing looping at one point (tmp->below 1125 * This function was seen be continueing looping at one point (tmp->below
1130 * became a recursive loop. It may be better to call monster_check_apply 1126 * became a recursive loop. It may be better to call monster_check_apply
1131 * after we pick everything up, since that function may call others which 1127 * after we pick everything up, since that function may call others which
1132 * affect stacking on this space. 1128 * affect stacking on this space.
1133 */ 1129 */
1134
1135void 1130void
1136monster_check_pickup (object *monster) 1131monster_check_pickup (object *monster)
1137{ 1132{
1138 object *tmp, *next; 1133 object *tmp, *next;
1139 1134
1158 * monster_can_pick(): If the monster is interested in picking up 1153 * monster_can_pick(): If the monster is interested in picking up
1159 * the item, then return 0. Otherwise 0. 1154 * the item, then return 0. Otherwise 0.
1160 * Instead of pick_up, flags for "greed", etc, should be used. 1155 * Instead of pick_up, flags for "greed", etc, should be used.
1161 * I've already utilized flags for bows, wands, rings, etc, etc. -Frank. 1156 * I've already utilized flags for bows, wands, rings, etc, etc. -Frank.
1162 */ 1157 */
1163
1164int 1158int
1165monster_can_pick (object *monster, object *item) 1159monster_can_pick (object *monster, object *item)
1166{ 1160{
1167 int flag = 0; 1161 int flag = 0;
1168 int i; 1162 int i;
1226 case BOW: 1220 case BOW:
1227 case ARROW: 1221 case ARROW:
1228 flag = QUERY_FLAG (monster, FLAG_USE_BOW); 1222 flag = QUERY_FLAG (monster, FLAG_USE_BOW);
1229 break; 1223 break;
1230 } 1224 }
1225
1231 /* Simplistic check - if the monster has a location to equip it, he will 1226 /* Simplistic check - if the monster has a location to equip it, he will
1232 * pick it up. Note that this doesn't handle cases where an item may 1227 * pick it up. Note that this doesn't handle cases where an item may
1233 * use several locations. 1228 * use several locations.
1234 */ 1229 */
1235 for (i = 0; i < NUM_BODY_LOCATIONS; i++) 1230 for (i = 0; i < NUM_BODY_LOCATIONS; i++)
1236 { 1231 {
1237 if (monster->body_info[i] && item->body_info[i]) 1232 if (monster->slot[i].info && item->slot[i].info)
1238 { 1233 {
1239 flag = 1; 1234 flag = 1;
1240 break; 1235 break;
1241 } 1236 }
1242 } 1237 }
1250 * monster_apply_below(): 1245 * monster_apply_below():
1251 * Vick's (vick@bern.docs.uu.se) @921107 -> If a monster who's 1246 * Vick's (vick@bern.docs.uu.se) @921107 -> If a monster who's
1252 * eager to apply things, encounters something apply-able, 1247 * eager to apply things, encounters something apply-able,
1253 * then make him apply it 1248 * then make him apply it
1254 */ 1249 */
1255
1256void 1250void
1257monster_apply_below (object *monster) 1251monster_apply_below (object *monster)
1258{ 1252{
1259 object *tmp, *next; 1253 object *tmp, *next;
1260 1254
1287 * a pointer to that object is returned, so it can be dropped. 1281 * a pointer to that object is returned, so it can be dropped.
1288 * (so that other monsters can pick it up and use it) 1282 * (so that other monsters can pick it up and use it)
1289 * Note that as things are now, monsters never drop something - 1283 * Note that as things are now, monsters never drop something -
1290 * they can pick up all that they can use. 1284 * they can pick up all that they can use.
1291 */ 1285 */
1292
1293/* Sept 96, fixed this so skills will be readied -b.t.*/ 1286/* Sept 96, fixed this so skills will be readied -b.t.*/
1294
1295void 1287void
1296monster_check_apply (object *mon, object *item) 1288monster_check_apply (object *mon, object *item)
1297{ 1289{
1298
1299 int flag = 0; 1290 int flag = 0;
1300 1291
1301 if (item->type == SPELLBOOK && mon->arch != NULL && (QUERY_FLAG ((&mon->arch->clone), FLAG_CAST_SPELL))) 1292 if (item->type == SPELLBOOK && mon->arch && (QUERY_FLAG ((&mon->arch->clone), FLAG_CAST_SPELL)))
1302 { 1293 {
1303 SET_FLAG (mon, FLAG_CAST_SPELL); 1294 SET_FLAG (mon, FLAG_CAST_SPELL);
1304 return; 1295 return;
1305 } 1296 }
1306 1297
1315 if (QUERY_FLAG (mon, FLAG_USE_BOW) && item->type == ARROW) 1306 if (QUERY_FLAG (mon, FLAG_USE_BOW) && item->type == ARROW)
1316 { 1307 {
1317 /* Check for the right kind of bow */ 1308 /* Check for the right kind of bow */
1318 object *bow; 1309 object *bow;
1319 1310
1320 for (bow = mon->inv; bow != NULL; bow = bow->below) 1311 for (bow = mon->inv; bow; bow = bow->below)
1321 if (bow->type == BOW && bow->race == item->race) 1312 if (bow->type == BOW && bow->race == item->race)
1322 { 1313 {
1323 SET_FLAG (mon, FLAG_READY_BOW); 1314 SET_FLAG (mon, FLAG_READY_BOW);
1324 LOG (llevMonster, "Found correct bow for arrows.\n"); 1315 LOG (llevMonster, "Found correct bow for arrows.\n");
1325 return; /* nothing more to do for arrows */ 1316 return; /* nothing more to do for arrows */
1377 */ 1368 */
1378 SET_FLAG (mon, FLAG_READY_SKILL); 1369 SET_FLAG (mon, FLAG_READY_SKILL);
1379 return; 1370 return;
1380 } 1371 }
1381 1372
1382
1383 /* if we don't match one of the above types, return now. 1373 /* if we don't match one of the above types, return now.
1384 * can_apply_object will say that we can apply things like flesh, 1374 * can_apply_object will say that we can apply things like flesh,
1385 * bolts, and whatever else, because it only checks against the 1375 * bolts, and whatever else, because it only checks against the
1386 * body_info locations. 1376 * body_info locations.
1387 */ 1377 */
1398 /* should only be applying this item, not unapplying it. 1388 /* should only be applying this item, not unapplying it.
1399 * also, ignore status of curse so they can take off old armour. 1389 * also, ignore status of curse so they can take off old armour.
1400 * monsters have some advantages after all. 1390 * monsters have some advantages after all.
1401 */ 1391 */
1402 manual_apply (mon, item, AP_APPLY | AP_IGNORE_CURSE); 1392 manual_apply (mon, item, AP_APPLY | AP_IGNORE_CURSE);
1403
1404 return;
1405} 1393}
1406 1394
1407void 1395void
1408npc_call_help (object *op) 1396npc_call_help (object *op)
1409{ 1397{
1427 if (QUERY_FLAG (npc, FLAG_ALIVE) && QUERY_FLAG (npc, FLAG_UNAGGRESSIVE)) 1415 if (QUERY_FLAG (npc, FLAG_ALIVE) && QUERY_FLAG (npc, FLAG_UNAGGRESSIVE))
1428 npc->enemy = op->enemy; 1416 npc->enemy = op->enemy;
1429 } 1417 }
1430} 1418}
1431 1419
1432
1433int 1420int
1434dist_att (int dir, object *ob, object *enemy, object *part, rv_vector * rv) 1421dist_att (int dir, object *ob, object *enemy, object *part, rv_vector * rv)
1435{ 1422{
1436
1437 if (can_hit (part, enemy, rv)) 1423 if (can_hit (part, enemy, rv))
1438 return dir; 1424 return dir;
1439 if (rv->distance < 10) 1425 if (rv->distance < 10)
1440 return absdir (dir + 4); 1426 return absdir (dir + 4);
1441 else if (rv->distance > 18) 1427 else if (rv->distance > 18)
1442 return dir; 1428 return dir;
1429
1443 return 0; 1430 return 0;
1444} 1431}
1445 1432
1446int 1433int
1447run_att (int dir, object *ob, object *enemy, object *part, rv_vector * rv) 1434run_att (int dir, object *ob, object *enemy, object *part, rv_vector * rv)
1448{ 1435{
1449
1450 if ((can_hit (part, enemy, rv) && ob->move_status < 20) || ob->move_status < 20) 1436 if ((can_hit (part, enemy, rv) && ob->move_status < 20) || ob->move_status < 20)
1451 { 1437 {
1452 ob->move_status++; 1438 ob->move_status++;
1453 return (dir); 1439 return (dir);
1454 } 1440 }
1455 else if (ob->move_status > 20) 1441 else if (ob->move_status > 20)
1456 ob->move_status = 0; 1442 ob->move_status = 0;
1443
1457 return absdir (dir + 4); 1444 return absdir (dir + 4);
1458} 1445}
1459 1446
1460int 1447int
1461hitrun_att (int dir, object *ob, object *enemy) 1448hitrun_att (int dir, object *ob, object *enemy)
1464 return dir; 1451 return dir;
1465 else if (ob->move_status < 50) 1452 else if (ob->move_status < 50)
1466 return absdir (dir + 4); 1453 return absdir (dir + 4);
1467 else 1454 else
1468 ob->move_status = 0; 1455 ob->move_status = 0;
1456
1469 return absdir (dir + 4); 1457 return absdir (dir + 4);
1470} 1458}
1471 1459
1472int 1460int
1473wait_att (int dir, object *ob, object *enemy, object *part, rv_vector * rv) 1461wait_att (int dir, object *ob, object *enemy, object *part, rv_vector * rv)
1482 return 0; 1470 return 0;
1483 else if (ob->move_status < 10) 1471 else if (ob->move_status < 10)
1484 return dir; 1472 return dir;
1485 else if (ob->move_status < 15) 1473 else if (ob->move_status < 15)
1486 return absdir (dir + 4); 1474 return absdir (dir + 4);
1475
1487 ob->move_status = 0; 1476 ob->move_status = 0;
1488 return 0; 1477 return 0;
1489} 1478}
1490 1479
1491int 1480int
1499 * at least one map has this set, and whatever the map contains, the 1488 * at least one map has this set, and whatever the map contains, the
1500 * server should try to be resilant enough to avoid the problem 1489 * server should try to be resilant enough to avoid the problem
1501 */ 1490 */
1502 if (ob->stats.maxhp && (ob->stats.hp * 100) / ob->stats.maxhp < ob->run_away) 1491 if (ob->stats.maxhp && (ob->stats.hp * 100) / ob->stats.maxhp < ob->run_away)
1503 return absdir (dir + 4); 1492 return absdir (dir + 4);
1493
1504 return dist_att (dir, ob, enemy, part, rv); 1494 return dist_att (dir, ob, enemy, part, rv);
1505} 1495}
1506 1496
1507int 1497int
1508wait_att2 (int dir, object *ob, object *enemy, object *part, rv_vector * rv) 1498wait_att2 (int dir, object *ob, object *enemy, object *part, rv_vector * rv)
1509{ 1499{
1510 if (rv->distance < 9) 1500 if (rv->distance < 9)
1511 return absdir (dir + 4); 1501 return absdir (dir + 4);
1502
1512 return 0; 1503 return 0;
1513} 1504}
1514 1505
1515void 1506void
1516circ1_move (object *ob) 1507circ1_move (object *ob)
1517{ 1508{
1518 static int circle[12] = { 3, 3, 4, 5, 5, 6, 7, 7, 8, 1, 1, 2 }; 1509 static int circle[12] = { 3, 3, 4, 5, 5, 6, 7, 7, 8, 1, 1, 2 };
1510
1519 if (++ob->move_status > 11) 1511 if (++ob->move_status > 11)
1520 ob->move_status = 0; 1512 ob->move_status = 0;
1513
1521 if (!(move_object (ob, circle[ob->move_status]))) 1514 if (!(move_object (ob, circle[ob->move_status])))
1522 (void) move_object (ob, RANDOM () % 8 + 1); 1515 move_object (ob, rndm (8) + 1);
1523} 1516}
1524 1517
1525void 1518void
1526circ2_move (object *ob) 1519circ2_move (object *ob)
1527{ 1520{
1528 static int circle[20] = { 3, 3, 3, 4, 4, 5, 5, 5, 6, 6, 7, 7, 7, 8, 8, 1, 1, 1, 2, 2 }; 1521 static int circle[20] = { 3, 3, 3, 4, 4, 5, 5, 5, 6, 6, 7, 7, 7, 8, 8, 1, 1, 1, 2, 2 };
1522
1529 if (++ob->move_status > 19) 1523 if (++ob->move_status > 19)
1530 ob->move_status = 0; 1524 ob->move_status = 0;
1525
1531 if (!(move_object (ob, circle[ob->move_status]))) 1526 if (!(move_object (ob, circle[ob->move_status])))
1532 (void) move_object (ob, RANDOM () % 8 + 1); 1527 move_object (ob, rndm (8) + 1);
1533} 1528}
1534 1529
1535void 1530void
1536pace_movev (object *ob) 1531pace_movev (object *ob)
1537{ 1532{
1538 if (ob->move_status++ > 6) 1533 if (ob->move_status++ > 6)
1539 ob->move_status = 0; 1534 ob->move_status = 0;
1535
1540 if (ob->move_status < 4) 1536 if (ob->move_status < 4)
1541 (void) move_object (ob, 5); 1537 move_object (ob, 5);
1542 else 1538 else
1543 (void) move_object (ob, 1); 1539 move_object (ob, 1);
1544} 1540}
1545 1541
1546void 1542void
1547pace_moveh (object *ob) 1543pace_moveh (object *ob)
1548{ 1544{
1549 if (ob->move_status++ > 6) 1545 if (ob->move_status++ > 6)
1550 ob->move_status = 0; 1546 ob->move_status = 0;
1547
1551 if (ob->move_status < 4) 1548 if (ob->move_status < 4)
1552 (void) move_object (ob, 3); 1549 move_object (ob, 3);
1553 else 1550 else
1554 (void) move_object (ob, 7); 1551 move_object (ob, 7);
1555} 1552}
1556 1553
1557void 1554void
1558pace2_movev (object *ob) 1555pace2_movev (object *ob)
1559{ 1556{
1560 if (ob->move_status++ > 16) 1557 if (ob->move_status++ > 16)
1561 ob->move_status = 0; 1558 ob->move_status = 0;
1559
1562 if (ob->move_status < 6) 1560 if (ob->move_status < 6)
1563 (void) move_object (ob, 5); 1561 move_object (ob, 5);
1564 else if (ob->move_status < 8) 1562 else if (ob->move_status < 8)
1565 return; 1563 return;
1566 else if (ob->move_status < 13) 1564 else if (ob->move_status < 13)
1567 (void) move_object (ob, 1); 1565 move_object (ob, 1);
1568 else 1566 else
1569 return; 1567 return;
1570} 1568}
1571 1569
1572void 1570void
1573pace2_moveh (object *ob) 1571pace2_moveh (object *ob)
1574{ 1572{
1575 if (ob->move_status++ > 16) 1573 if (ob->move_status++ > 16)
1576 ob->move_status = 0; 1574 ob->move_status = 0;
1575
1577 if (ob->move_status < 6) 1576 if (ob->move_status < 6)
1578 (void) move_object (ob, 3); 1577 move_object (ob, 3);
1579 else if (ob->move_status < 8) 1578 else if (ob->move_status < 8)
1580 return; 1579 return;
1581 else if (ob->move_status < 13) 1580 else if (ob->move_status < 13)
1582 (void) move_object (ob, 7); 1581 move_object (ob, 7);
1583 else 1582 else
1584 return; 1583 return;
1585} 1584}
1586 1585
1587void 1586void
1588rand_move (object *ob) 1587rand_move (object *ob)
1589{ 1588{
1590 int i; 1589 int i;
1591 1590
1592 if (ob->move_status < 1 || ob->move_status > 8 || !(move_object (ob, ob->move_status || !(RANDOM () % 9)))) 1591 if (ob->move_status < 1 || ob->move_status > 8 || !(move_object (ob, ob->move_status || !(rndm (9)))))
1593 for (i = 0; i < 5; i++) 1592 for (i = 0; i < 5; i++)
1594 if (move_object (ob, ob->move_status = RANDOM () % 8 + 1)) 1593 if (move_object (ob, ob->move_status = rndm (8) + 1))
1595 return; 1594 return;
1596} 1595}
1597 1596
1598void 1597void
1599check_earthwalls (object *op, maptile *m, int x, int y) 1598check_earthwalls (object *op, maptile *m, int x, int y)
1630 * monsters to throw things like chairs and other pieces of 1629 * monsters to throw things like chairs and other pieces of
1631 * furniture, even if they are not good throwable objects. 1630 * furniture, even if they are not good throwable objects.
1632 * Probably better to have the monster throw a throwable object 1631 * Probably better to have the monster throw a throwable object
1633 * first, then throw any non equipped weapon. 1632 * first, then throw any non equipped weapon.
1634 */ 1633 */
1635
1636object * 1634object *
1637find_mon_throw_ob (object *op) 1635find_mon_throw_ob (object *op)
1638{ 1636{
1639 object *tmp = NULL; 1637 object *tmp = NULL;
1640 1638
1644 tmp = op; 1642 tmp = op;
1645 1643
1646 /* New throw code: look through the inventory. Grap the first legal is_thrown 1644 /* New throw code: look through the inventory. Grap the first legal is_thrown
1647 * marked item and throw it to the enemy. 1645 * marked item and throw it to the enemy.
1648 */ 1646 */
1649
1650 for (tmp = op->inv; tmp; tmp = tmp->below) 1647 for (tmp = op->inv; tmp; tmp = tmp->below)
1651 { 1648 {
1652
1653 /* Can't throw invisible objects or items that are applied */ 1649 /* Can't throw invisible objects or items that are applied */
1654 if (tmp->invisible || QUERY_FLAG (tmp, FLAG_APPLIED)) 1650 if (tmp->invisible || QUERY_FLAG (tmp, FLAG_APPLIED))
1655 continue; 1651 continue;
1656 1652
1657 if (QUERY_FLAG (tmp, FLAG_IS_THROWN)) 1653 if (QUERY_FLAG (tmp, FLAG_IS_THROWN))
1780 /* ah, we are within range, detected? take cases */ 1776 /* ah, we are within range, detected? take cases */
1781 if (!enemy->invisible) /* enemy in dark squares... are seen! */ 1777 if (!enemy->invisible) /* enemy in dark squares... are seen! */
1782 return 1; 1778 return 1;
1783 1779
1784 /* hidden or low-quality invisible */ 1780 /* hidden or low-quality invisible */
1785 if (enemy->hide && (rv->distance <= 1) && (RANDOM () % 100 <= hide_discovery)) 1781 if (enemy->hide && (rv->distance <= 1) && (rndm (100) <= hide_discovery))
1786 { 1782 {
1787 make_visible (enemy); 1783 make_visible (enemy);
1788 /* inform players of new status */ 1784 /* inform players of new status */
1789 if (enemy->type == PLAYER && player_can_view (enemy, op)) 1785 if (enemy->type == PLAYER && player_can_view (enemy, op))
1790 new_draw_info_format (NDI_UNIQUE, 0, enemy, "You are discovered by %s!", &op->name); 1786 new_draw_info_format (NDI_UNIQUE, 0, enemy, "You are discovered by %s!", &op->name);
1797 * do something to you. Decreasing the duration of invisible 1793 * do something to you. Decreasing the duration of invisible
1798 * doesn't make a lot of sense IMO, as a bunch of stupid creatures 1794 * doesn't make a lot of sense IMO, as a bunch of stupid creatures
1799 * can then basically negate the spell. The spell isn't negated - 1795 * can then basically negate the spell. The spell isn't negated -
1800 * they just know where you are! 1796 * they just know where you are!
1801 */ 1797 */
1802 if ((RANDOM () % 50) <= hide_discovery) 1798 if ((rndm (50)) <= hide_discovery)
1803 { 1799 {
1804 if (enemy->type == PLAYER) 1800 if (enemy->type == PLAYER)
1805 { 1801 {
1806 new_draw_info_format (NDI_UNIQUE, 0, enemy, "You see %s noticing your position.", query_name (op)); 1802 new_draw_info_format (NDI_UNIQUE, 0, enemy, "You see %s noticing your position.", query_name (op));
1807 } 1803 }
1817/* determine if op stands in a lighted square. This is not a very 1813/* determine if op stands in a lighted square. This is not a very
1818 * intellegent algorithm. For one thing, we ignore los here, SO it 1814 * intellegent algorithm. For one thing, we ignore los here, SO it
1819 * is possible for a bright light to illuminate a player on the 1815 * is possible for a bright light to illuminate a player on the
1820 * other side of a wall (!). 1816 * other side of a wall (!).
1821 */ 1817 */
1822
1823int 1818int
1824stand_in_light (object *op) 1819stand_in_light (object *op)
1825{ 1820{
1826 sint16 nx, ny; 1821 sint16 nx, ny;
1827 maptile *m; 1822 maptile *m;
1828 1823
1829
1830 if (!op) 1824 if (!op)
1831 return 0; 1825 return 0;
1826
1832 if (op->glow_radius > 0) 1827 if (op->glow_radius > 0)
1833 return 1; 1828 return 1;
1834 1829
1835 if (op->map) 1830 if (op->map)
1836 { 1831 {
1837 int x, y, x1, y1; 1832 int x, y, x1, y1;
1838
1839
1840 1833
1841 /* Check the spaces with the max light radius to see if any of them 1834 /* Check the spaces with the max light radius to see if any of them
1842 * have lights, and if any of them light the player enough, then return 1. 1835 * have lights, and if any of them light the player enough, then return 1.
1843 */ 1836 */
1844 for (x = op->x - MAX_LIGHT_RADII; x <= op->x + MAX_LIGHT_RADII; x++) 1837 for (x = op->x - MAX_LIGHT_RADII; x <= op->x + MAX_LIGHT_RADII; x++)
1857 if (isqrt (x1 + y1) < GET_MAP_LIGHT (m, nx, ny)) 1850 if (isqrt (x1 + y1) < GET_MAP_LIGHT (m, nx, ny))
1858 return 1; 1851 return 1;
1859 } 1852 }
1860 } 1853 }
1861 } 1854 }
1855
1862 return 0; 1856 return 0;
1863} 1857}
1864
1865 1858
1866/* assuming no walls/barriers, lets check to see if its *possible* 1859/* assuming no walls/barriers, lets check to see if its *possible*
1867 * to see an enemy. Note, "detection" is different from "seeing". 1860 * to see an enemy. Note, "detection" is different from "seeing".
1868 * See can_detect_enemy() for more details. -b.t. 1861 * See can_detect_enemy() for more details. -b.t.
1869 * return 0 if can't be seen, 1 if can be 1862 * return 0 if can't be seen, 1 if can be
1870 */ 1863 */
1871
1872int 1864int
1873can_see_enemy (object *op, object *enemy) 1865can_see_enemy (object *op, object *enemy)
1874{ 1866{
1875 object *looker = op->head ? op->head : op; 1867 object *looker = op->head ? op->head : op;
1876 1868

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines