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 | * |
… | |
… | |
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 | } |
… | |
… | |
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 + rndm (3) + rndm (3) - 2); |
497 | dir = absdir (dir + rndm (3) + rndm (3) - 2); |
492 | |
498 | |
493 | if (QUERY_FLAG (op, FLAG_CAST_SPELL) && !(rndm (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) && !(rndm (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) && !(rndm (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) && !(rndm (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) && !(rndm (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; |
… | |
… | |
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 | |
|
|
902 | int |
899 | int |
903 | monster_use_skill (object *head, object *part, object *pl, int dir) |
900 | monster_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 + rndm (3) + rndm (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 | |
|
|
945 | int |
942 | int |
946 | monster_use_range (object *head, object *part, object *pl, int dir) |
943 | monster_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 + rndm (3) + rndm (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 | |
1014 | int |
1012 | int |
… | |
… | |
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 + rndm (3) + rndm (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 | { |
… | |
… | |
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 | |
|
|
1044 | int |
1042 | int |
1045 | check_good_weapon (object *who, object *item) |
1043 | check_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 | |
1078 | int |
1075 | int |
1079 | check_good_armour (object *who, object *item) |
1076 | check_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 | |
|
|
1135 | void |
1130 | void |
1136 | monster_check_pickup (object *monster) |
1131 | monster_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 | |
|
|
1164 | int |
1158 | int |
1165 | monster_can_pick (object *monster, object *item) |
1159 | monster_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 | |
|
|
1256 | void |
1250 | void |
1257 | monster_apply_below (object *monster) |
1251 | monster_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 | |
|
|
1295 | void |
1287 | void |
1296 | monster_check_apply (object *mon, object *item) |
1288 | monster_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 | |
1407 | void |
1395 | void |
1408 | npc_call_help (object *op) |
1396 | npc_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 | |
|
|
1433 | int |
1420 | int |
1434 | dist_att (int dir, object *ob, object *enemy, object *part, rv_vector * rv) |
1421 | dist_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 | |
1446 | int |
1433 | int |
1447 | run_att (int dir, object *ob, object *enemy, object *part, rv_vector * rv) |
1434 | run_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 | |
1460 | int |
1447 | int |
1461 | hitrun_att (int dir, object *ob, object *enemy) |
1448 | hitrun_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 | |
1472 | int |
1460 | int |
1473 | wait_att (int dir, object *ob, object *enemy, object *part, rv_vector * rv) |
1461 | wait_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 | |
1491 | int |
1480 | int |
… | |
… | |
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 | |
1507 | int |
1497 | int |
1508 | wait_att2 (int dir, object *ob, object *enemy, object *part, rv_vector * rv) |
1498 | wait_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 | |
1515 | void |
1506 | void |
1516 | circ1_move (object *ob) |
1507 | circ1_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, rndm (8) + 1); |
1515 | move_object (ob, rndm (8) + 1); |
1523 | } |
1516 | } |
1524 | |
1517 | |
1525 | void |
1518 | void |
1526 | circ2_move (object *ob) |
1519 | circ2_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, rndm (8) + 1); |
1527 | move_object (ob, rndm (8) + 1); |
1533 | } |
1528 | } |
1534 | |
1529 | |
1535 | void |
1530 | void |
1536 | pace_movev (object *ob) |
1531 | pace_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 | |
1546 | void |
1542 | void |
1547 | pace_moveh (object *ob) |
1543 | pace_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 | |
1557 | void |
1554 | void |
1558 | pace2_movev (object *ob) |
1555 | pace2_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 | |
1572 | void |
1570 | void |
1573 | pace2_moveh (object *ob) |
1571 | pace2_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 | |
1587 | void |
1586 | void |
… | |
… | |
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 | |
|
|
1636 | object * |
1634 | object * |
1637 | find_mon_throw_ob (object *op) |
1635 | find_mon_throw_ob (object *op) |
1638 | { |
1636 | { |
1639 | object *tmp = NULL; |
1637 | object *tmp = NULL; |
1640 | |
1638 | |
… | |
… | |
1815 | /* 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 |
1816 | * intellegent algorithm. For one thing, we ignore los here, SO it |
1814 | * intellegent algorithm. For one thing, we ignore los here, SO it |
1817 | * 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 |
1818 | * other side of a wall (!). |
1816 | * other side of a wall (!). |
1819 | */ |
1817 | */ |
1820 | |
|
|
1821 | int |
1818 | int |
1822 | stand_in_light (object *op) |
1819 | stand_in_light (object *op) |
1823 | { |
1820 | { |
1824 | sint16 nx, ny; |
1821 | sint16 nx, ny; |
1825 | maptile *m; |
1822 | maptile *m; |
1826 | |
1823 | |
1827 | |
|
|
1828 | if (!op) |
1824 | if (!op) |
1829 | return 0; |
1825 | return 0; |
|
|
1826 | |
1830 | if (op->glow_radius > 0) |
1827 | if (op->glow_radius > 0) |
1831 | return 1; |
1828 | return 1; |
1832 | |
1829 | |
1833 | if (op->map) |
1830 | if (op->map) |
1834 | { |
1831 | { |
1835 | int x, y, x1, y1; |
1832 | int x, y, x1, y1; |
1836 | |
|
|
1837 | |
|
|
1838 | |
1833 | |
1839 | /* 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 |
1840 | * 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. |
1841 | */ |
1836 | */ |
1842 | 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++) |
… | |
… | |
1855 | if (isqrt (x1 + y1) < GET_MAP_LIGHT (m, nx, ny)) |
1850 | if (isqrt (x1 + y1) < GET_MAP_LIGHT (m, nx, ny)) |
1856 | return 1; |
1851 | return 1; |
1857 | } |
1852 | } |
1858 | } |
1853 | } |
1859 | } |
1854 | } |
|
|
1855 | |
1860 | return 0; |
1856 | return 0; |
1861 | } |
1857 | } |
1862 | |
|
|
1863 | |
1858 | |
1864 | /* assuming no walls/barriers, lets check to see if its *possible* |
1859 | /* assuming no walls/barriers, lets check to see if its *possible* |
1865 | * to see an enemy. Note, "detection" is different from "seeing". |
1860 | * to see an enemy. Note, "detection" is different from "seeing". |
1866 | * See can_detect_enemy() for more details. -b.t. |
1861 | * See can_detect_enemy() for more details. -b.t. |
1867 | * return 0 if can't be seen, 1 if can be |
1862 | * return 0 if can't be seen, 1 if can be |
1868 | */ |
1863 | */ |
1869 | |
|
|
1870 | int |
1864 | int |
1871 | can_see_enemy (object *op, object *enemy) |
1865 | can_see_enemy (object *op, object *enemy) |
1872 | { |
1866 | { |
1873 | object *looker = op->head ? op->head : op; |
1867 | object *looker = op->head ? op->head : op; |
1874 | |
1868 | |