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.27 by root, Mon Apr 30 04:25:30 2007 UTC

1/* 1/*
2 CrossFire, A Multiplayer game for X-windows 2 * CrossFire, A Multiplayer game for X-windows
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.
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);
490 if (QUERY_FLAG (op, FLAG_CONFUSED)) 495 if (QUERY_FLAG (op, FLAG_CONFUSED))
491 dir = absdir (dir + RANDOM () % 3 + RANDOM () % 3 - 2); 496 dir = absdir (dir + rndm (3) + rndm (3) - 2);
492 497
493 if (QUERY_FLAG (op, FLAG_CAST_SPELL) && !(RANDOM () % 3)) 498 if (QUERY_FLAG (op, FLAG_CAST_SPELL) && !(rndm (3)))
494 { 499 {
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 } 502 }
498 503
499 if (QUERY_FLAG (op, FLAG_READY_SCROLL) && !(RANDOM () % 3)) 504 if (QUERY_FLAG (op, FLAG_READY_SCROLL) && !(rndm (3)))
500 { 505 {
501 if (monster_use_scroll (op, part, enemy, dir, &rv1)) 506 if (monster_use_scroll (op, part, enemy, dir, &rv1))
502 return 0; 507 return 0;
503 } 508 }
504 509
505 if (QUERY_FLAG (op, FLAG_READY_RANGE) && !(RANDOM () % 3)) 510 if (QUERY_FLAG (op, FLAG_READY_RANGE) && !(rndm (3)))
506 { 511 {
507 if (monster_use_range (op, part, enemy, dir)) 512 if (monster_use_range (op, part, enemy, dir))
508 return 0; 513 return 0;
509 } 514 }
510 if (QUERY_FLAG (op, FLAG_READY_SKILL) && !(RANDOM () % 3)) 515 if (QUERY_FLAG (op, FLAG_READY_SKILL) && !(rndm (3)))
511 { 516 {
512 if (monster_use_skill (op, rv.part, enemy, rv.direction)) 517 if (monster_use_skill (op, rv.part, enemy, rv.direction))
513 return 0; 518 return 0;
514 } 519 }
515 if (QUERY_FLAG (op, FLAG_READY_BOW) && !(RANDOM () % 2)) 520 if (QUERY_FLAG (op, FLAG_READY_BOW) && !(rndm (2)))
516 { 521 {
517 if (monster_use_bow (op, part, enemy, dir)) 522 if (monster_use_bow (op, part, enemy, dir))
518 return 0; 523 return 0;
519 } 524 }
520 } /* for processing of all parts */ 525 } /* for processing of all parts */
526 531
527 if (QUERY_FLAG (op, FLAG_SCARED) || QUERY_FLAG (op, FLAG_RUN_AWAY)) 532 if (QUERY_FLAG (op, FLAG_SCARED) || QUERY_FLAG (op, FLAG_RUN_AWAY))
528 dir = absdir (dir + 4); 533 dir = absdir (dir + 4);
529 534
530 if (QUERY_FLAG (op, FLAG_CONFUSED)) 535 if (QUERY_FLAG (op, FLAG_CONFUSED))
531 dir = absdir (dir + RANDOM () % 3 + RANDOM () % 3 - 2); 536 dir = absdir (dir + rndm (3) + rndm (3) - 2);
532 537
533 pre_att_dir = dir; /* remember the original direction */ 538 pre_att_dir = dir; /* remember the original direction */
534 539
535 if ((op->attack_movement & LO4) && !QUERY_FLAG (op, FLAG_SCARED)) 540 if ((op->attack_movement & LO4) && !QUERY_FLAG (op, FLAG_SCARED))
536 { 541 {
668can_hit (object *ob1, object *ob2, rv_vector * rv) 673can_hit (object *ob1, object *ob2, rv_vector * rv)
669{ 674{
670 object *more; 675 object *more;
671 rv_vector rv1; 676 rv_vector rv1;
672 677
673 if (QUERY_FLAG (ob1, FLAG_CONFUSED) && !(RANDOM () % 3)) 678 if (QUERY_FLAG (ob1, FLAG_CONFUSED) && !(rndm (3)))
674 return 0; 679 return 0;
675 680
676 if (abs (rv->distance_x) < 2 && abs (rv->distance_y) < 2) 681 if (abs (rv->distance_x) < 2 && abs (rv->distance_y) < 2)
677 return 1; 682 return 1;
678 683
787 return 0; /* Might hit owner with spell */ 792 return 0; /* Might hit owner with spell */
788 } 793 }
789 } 794 }
790 795
791 if (QUERY_FLAG (head, FLAG_CONFUSED)) 796 if (QUERY_FLAG (head, FLAG_CONFUSED))
792 dir = absdir (dir + RANDOM () % 3 + RANDOM () % 3 - 2); 797 dir = absdir (dir + rndm (3) + rndm (3) - 2);
793 798
794 /* If the monster hasn't already chosen a spell, choose one 799 /* 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 800 * 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). 801 * could be different by the time the monster goes again).
797 */ 802 */
864 return 0; /* Might hit owner with spell */ 869 return 0; /* Might hit owner with spell */
865 } 870 }
866 } 871 }
867 872
868 if (QUERY_FLAG (head, FLAG_CONFUSED)) 873 if (QUERY_FLAG (head, FLAG_CONFUSED))
869 dir = absdir (dir + RANDOM () % 3 + RANDOM () % 3 - 2); 874 dir = absdir (dir + rndm (3) + rndm (3) - 2);
870 875
871 for (scroll = head->inv; scroll; scroll = scroll->below) 876 for (scroll = head->inv; scroll; scroll = scroll->below)
872 if (scroll->type == SCROLL && monster_should_cast_spell (head, scroll->inv)) 877 if (scroll->type == SCROLL && monster_should_cast_spell (head, scroll->inv))
873 break; 878 break;
874 879
896 * The skills we are treating here are all but those. -b.t. 901 * The skills we are treating here are all but those. -b.t.
897 * 902 *
898 * At the moment this is only useful for throwing, perhaps for 903 * 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 904 * stealing. TODO: This should be more integrated in the game. -MT, 25.11.01
900 */ 905 */
901
902int 906int
903monster_use_skill (object *head, object *part, object *pl, int dir) 907monster_use_skill (object *head, object *part, object *pl, int dir)
904{ 908{
905 object *skill, *owner; 909 object *skill, *owner;
906 910
912 int dir2 = find_dir_2 (head->x - owner->x, head->y - owner->y); 916 int dir2 = find_dir_2 (head->x - owner->x, head->y - owner->y);
913 917
914 if (dirdiff (dir, dir2) < 1) 918 if (dirdiff (dir, dir2) < 1)
915 return 0; /* Might hit owner with skill -thrown rocks for example ? */ 919 return 0; /* Might hit owner with skill -thrown rocks for example ? */
916 } 920 }
921
917 if (QUERY_FLAG (head, FLAG_CONFUSED)) 922 if (QUERY_FLAG (head, FLAG_CONFUSED))
918 dir = absdir (dir + RANDOM () % 3 + RANDOM () % 3 - 2); 923 dir = absdir (dir + rndm (3) + rndm (3) - 2);
919 924
920 /* skill selection - monster will use the next unused skill. 925 /* skill selection - monster will use the next unused skill.
921 * well...the following scenario will allow the monster to 926 * well...the following scenario will allow the monster to
922 * toggle between 2 skills. One day it would be nice to make 927 * toggle between 2 skills. One day it would be nice to make
923 * more skills available to monsters. 928 * more skills available to monsters.
924 */ 929 */
925 930
926 for (skill = head->inv; skill != NULL; skill = skill->below) 931 for (skill = head->inv; skill; skill = skill->below)
927 if (skill->type == SKILL && skill != head->chosen_skill) 932 if (skill->type == SKILL && skill != head->chosen_skill)
928 { 933 {
929 head->chosen_skill = skill; 934 head->chosen_skill = skill;
930 break; 935 break;
931 } 936 }
934 { 939 {
935 LOG (llevDebug, "Error: Monster %s (%d) has FLAG_READY_SKILL without skill.\n", &head->name, head->count); 940 LOG (llevDebug, "Error: Monster %s (%d) has FLAG_READY_SKILL without skill.\n", &head->name, head->count);
936 CLEAR_FLAG (head, FLAG_READY_SKILL); 941 CLEAR_FLAG (head, FLAG_READY_SKILL);
937 return 0; 942 return 0;
938 } 943 }
944
939 /* use skill */ 945 /* use skill */
940 return do_skill (head, part, head->chosen_skill, dir, NULL); 946 return do_skill (head, part, head->chosen_skill, dir, NULL);
941} 947}
942 948
943/* Monster will use a ranged spell attack. */ 949/* Monster will use a ranged spell attack. */
944
945int 950int
946monster_use_range (object *head, object *part, object *pl, int dir) 951monster_use_range (object *head, object *part, object *pl, int dir)
947{ 952{
948 object *wand, *owner; 953 object *wand, *owner;
949 int at_least_one = 0; 954 int at_least_one = 0;
957 962
958 if (dirdiff (dir, dir2) < 2) 963 if (dirdiff (dir, dir2) < 2)
959 return 0; /* Might hit owner with spell */ 964 return 0; /* Might hit owner with spell */
960 } 965 }
961 if (QUERY_FLAG (head, FLAG_CONFUSED)) 966 if (QUERY_FLAG (head, FLAG_CONFUSED))
962 dir = absdir (dir + RANDOM () % 3 + RANDOM () % 3 - 2); 967 dir = absdir (dir + rndm (3) + rndm (3) - 2);
963 968
964 for (wand = head->inv; wand != NULL; wand = wand->below) 969 for (wand = head->inv; wand; wand = wand->below)
965 { 970 {
966 if (wand->type == WAND) 971 if (wand->type == WAND)
967 { 972 {
968 /* Found a wand, let's see if it has charges left */ 973 /* Found a wand, let's see if it has charges left */
969 at_least_one = 1; 974 at_least_one = 1;
1017 object *owner; 1022 object *owner;
1018 1023
1019 if (!(dir = path_to_player (part, pl, 0))) 1024 if (!(dir = path_to_player (part, pl, 0)))
1020 return 0; 1025 return 0;
1021 if (QUERY_FLAG (head, FLAG_CONFUSED)) 1026 if (QUERY_FLAG (head, FLAG_CONFUSED))
1022 dir = absdir (dir + RANDOM () % 3 + RANDOM () % 3 - 2); 1027 dir = absdir (dir + rndm (3) + rndm (3) - 2);
1023 1028
1024 if (QUERY_FLAG (head, FLAG_FRIENDLY) && (owner = head->owner) != NULL) 1029 if (QUERY_FLAG (head, FLAG_FRIENDLY) && (owner = head->owner) != NULL)
1025 { 1030 {
1026 int dir2 = find_dir_2 (head->x - owner->x, head->y - owner->y); 1031 int dir2 = find_dir_2 (head->x - owner->x, head->y - owner->y);
1027 1032
1070 1075
1071 if (val > 0) 1076 if (val > 0)
1072 return 1; 1077 return 1;
1073 else 1078 else
1074 return 0; 1079 return 0;
1075
1076} 1080}
1077 1081
1078int 1082int
1079check_good_armour (object *who, object *item) 1083check_good_armour (object *who, object *item)
1080{ 1084{
1111 1115
1112 if (val > 0) 1116 if (val > 0)
1113 return 1; 1117 return 1;
1114 else 1118 else
1115 return 0; 1119 return 0;
1116
1117} 1120}
1118 1121
1119/* 1122/*
1120 * monster_check_pickup(): checks for items that monster can pick up. 1123 * monster_check_pickup(): checks for items that monster can pick up.
1121 * 1124 *
1129 * This function was seen be continueing looping at one point (tmp->below 1132 * 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 1133 * 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 1134 * after we pick everything up, since that function may call others which
1132 * affect stacking on this space. 1135 * affect stacking on this space.
1133 */ 1136 */
1134
1135void 1137void
1136monster_check_pickup (object *monster) 1138monster_check_pickup (object *monster)
1137{ 1139{
1138 object *tmp, *next; 1140 object *tmp, *next;
1139 1141
1158 * monster_can_pick(): If the monster is interested in picking up 1160 * monster_can_pick(): If the monster is interested in picking up
1159 * the item, then return 0. Otherwise 0. 1161 * the item, then return 0. Otherwise 0.
1160 * Instead of pick_up, flags for "greed", etc, should be used. 1162 * Instead of pick_up, flags for "greed", etc, should be used.
1161 * I've already utilized flags for bows, wands, rings, etc, etc. -Frank. 1163 * I've already utilized flags for bows, wands, rings, etc, etc. -Frank.
1162 */ 1164 */
1163
1164int 1165int
1165monster_can_pick (object *monster, object *item) 1166monster_can_pick (object *monster, object *item)
1166{ 1167{
1167 int flag = 0; 1168 int flag = 0;
1168 int i; 1169 int i;
1226 case BOW: 1227 case BOW:
1227 case ARROW: 1228 case ARROW:
1228 flag = QUERY_FLAG (monster, FLAG_USE_BOW); 1229 flag = QUERY_FLAG (monster, FLAG_USE_BOW);
1229 break; 1230 break;
1230 } 1231 }
1232
1231 /* Simplistic check - if the monster has a location to equip it, he will 1233 /* 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 1234 * pick it up. Note that this doesn't handle cases where an item may
1233 * use several locations. 1235 * use several locations.
1234 */ 1236 */
1235 for (i = 0; i < NUM_BODY_LOCATIONS; i++) 1237 for (i = 0; i < NUM_BODY_LOCATIONS; i++)
1250 * monster_apply_below(): 1252 * monster_apply_below():
1251 * Vick's (vick@bern.docs.uu.se) @921107 -> If a monster who's 1253 * Vick's (vick@bern.docs.uu.se) @921107 -> If a monster who's
1252 * eager to apply things, encounters something apply-able, 1254 * eager to apply things, encounters something apply-able,
1253 * then make him apply it 1255 * then make him apply it
1254 */ 1256 */
1255
1256void 1257void
1257monster_apply_below (object *monster) 1258monster_apply_below (object *monster)
1258{ 1259{
1259 object *tmp, *next; 1260 object *tmp, *next;
1260 1261
1287 * a pointer to that object is returned, so it can be dropped. 1288 * a pointer to that object is returned, so it can be dropped.
1288 * (so that other monsters can pick it up and use it) 1289 * (so that other monsters can pick it up and use it)
1289 * Note that as things are now, monsters never drop something - 1290 * Note that as things are now, monsters never drop something -
1290 * they can pick up all that they can use. 1291 * they can pick up all that they can use.
1291 */ 1292 */
1292
1293/* Sept 96, fixed this so skills will be readied -b.t.*/ 1293/* Sept 96, fixed this so skills will be readied -b.t.*/
1294
1295void 1294void
1296monster_check_apply (object *mon, object *item) 1295monster_check_apply (object *mon, object *item)
1297{ 1296{
1298
1299 int flag = 0; 1297 int flag = 0;
1300 1298
1301 if (item->type == SPELLBOOK && mon->arch != NULL && (QUERY_FLAG ((&mon->arch->clone), FLAG_CAST_SPELL))) 1299 if (item->type == SPELLBOOK && mon->arch && (QUERY_FLAG ((&mon->arch->clone), FLAG_CAST_SPELL)))
1302 { 1300 {
1303 SET_FLAG (mon, FLAG_CAST_SPELL); 1301 SET_FLAG (mon, FLAG_CAST_SPELL);
1304 return; 1302 return;
1305 } 1303 }
1306 1304
1315 if (QUERY_FLAG (mon, FLAG_USE_BOW) && item->type == ARROW) 1313 if (QUERY_FLAG (mon, FLAG_USE_BOW) && item->type == ARROW)
1316 { 1314 {
1317 /* Check for the right kind of bow */ 1315 /* Check for the right kind of bow */
1318 object *bow; 1316 object *bow;
1319 1317
1320 for (bow = mon->inv; bow != NULL; bow = bow->below) 1318 for (bow = mon->inv; bow; bow = bow->below)
1321 if (bow->type == BOW && bow->race == item->race) 1319 if (bow->type == BOW && bow->race == item->race)
1322 { 1320 {
1323 SET_FLAG (mon, FLAG_READY_BOW); 1321 SET_FLAG (mon, FLAG_READY_BOW);
1324 LOG (llevMonster, "Found correct bow for arrows.\n"); 1322 LOG (llevMonster, "Found correct bow for arrows.\n");
1325 return; /* nothing more to do for arrows */ 1323 return; /* nothing more to do for arrows */
1377 */ 1375 */
1378 SET_FLAG (mon, FLAG_READY_SKILL); 1376 SET_FLAG (mon, FLAG_READY_SKILL);
1379 return; 1377 return;
1380 } 1378 }
1381 1379
1382
1383 /* if we don't match one of the above types, return now. 1380 /* 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, 1381 * can_apply_object will say that we can apply things like flesh,
1385 * bolts, and whatever else, because it only checks against the 1382 * bolts, and whatever else, because it only checks against the
1386 * body_info locations. 1383 * body_info locations.
1387 */ 1384 */
1398 /* should only be applying this item, not unapplying it. 1395 /* should only be applying this item, not unapplying it.
1399 * also, ignore status of curse so they can take off old armour. 1396 * also, ignore status of curse so they can take off old armour.
1400 * monsters have some advantages after all. 1397 * monsters have some advantages after all.
1401 */ 1398 */
1402 manual_apply (mon, item, AP_APPLY | AP_IGNORE_CURSE); 1399 manual_apply (mon, item, AP_APPLY | AP_IGNORE_CURSE);
1403
1404 return;
1405} 1400}
1406 1401
1407void 1402void
1408npc_call_help (object *op) 1403npc_call_help (object *op)
1409{ 1404{
1427 if (QUERY_FLAG (npc, FLAG_ALIVE) && QUERY_FLAG (npc, FLAG_UNAGGRESSIVE)) 1422 if (QUERY_FLAG (npc, FLAG_ALIVE) && QUERY_FLAG (npc, FLAG_UNAGGRESSIVE))
1428 npc->enemy = op->enemy; 1423 npc->enemy = op->enemy;
1429 } 1424 }
1430} 1425}
1431 1426
1432
1433int 1427int
1434dist_att (int dir, object *ob, object *enemy, object *part, rv_vector * rv) 1428dist_att (int dir, object *ob, object *enemy, object *part, rv_vector * rv)
1435{ 1429{
1436
1437 if (can_hit (part, enemy, rv)) 1430 if (can_hit (part, enemy, rv))
1438 return dir; 1431 return dir;
1439 if (rv->distance < 10) 1432 if (rv->distance < 10)
1440 return absdir (dir + 4); 1433 return absdir (dir + 4);
1441 else if (rv->distance > 18) 1434 else if (rv->distance > 18)
1442 return dir; 1435 return dir;
1436
1443 return 0; 1437 return 0;
1444} 1438}
1445 1439
1446int 1440int
1447run_att (int dir, object *ob, object *enemy, object *part, rv_vector * rv) 1441run_att (int dir, object *ob, object *enemy, object *part, rv_vector * rv)
1448{ 1442{
1449
1450 if ((can_hit (part, enemy, rv) && ob->move_status < 20) || ob->move_status < 20) 1443 if ((can_hit (part, enemy, rv) && ob->move_status < 20) || ob->move_status < 20)
1451 { 1444 {
1452 ob->move_status++; 1445 ob->move_status++;
1453 return (dir); 1446 return (dir);
1454 } 1447 }
1455 else if (ob->move_status > 20) 1448 else if (ob->move_status > 20)
1456 ob->move_status = 0; 1449 ob->move_status = 0;
1450
1457 return absdir (dir + 4); 1451 return absdir (dir + 4);
1458} 1452}
1459 1453
1460int 1454int
1461hitrun_att (int dir, object *ob, object *enemy) 1455hitrun_att (int dir, object *ob, object *enemy)
1464 return dir; 1458 return dir;
1465 else if (ob->move_status < 50) 1459 else if (ob->move_status < 50)
1466 return absdir (dir + 4); 1460 return absdir (dir + 4);
1467 else 1461 else
1468 ob->move_status = 0; 1462 ob->move_status = 0;
1463
1469 return absdir (dir + 4); 1464 return absdir (dir + 4);
1470} 1465}
1471 1466
1472int 1467int
1473wait_att (int dir, object *ob, object *enemy, object *part, rv_vector * rv) 1468wait_att (int dir, object *ob, object *enemy, object *part, rv_vector * rv)
1482 return 0; 1477 return 0;
1483 else if (ob->move_status < 10) 1478 else if (ob->move_status < 10)
1484 return dir; 1479 return dir;
1485 else if (ob->move_status < 15) 1480 else if (ob->move_status < 15)
1486 return absdir (dir + 4); 1481 return absdir (dir + 4);
1482
1487 ob->move_status = 0; 1483 ob->move_status = 0;
1488 return 0; 1484 return 0;
1489} 1485}
1490 1486
1491int 1487int
1499 * at least one map has this set, and whatever the map contains, the 1495 * 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 1496 * server should try to be resilant enough to avoid the problem
1501 */ 1497 */
1502 if (ob->stats.maxhp && (ob->stats.hp * 100) / ob->stats.maxhp < ob->run_away) 1498 if (ob->stats.maxhp && (ob->stats.hp * 100) / ob->stats.maxhp < ob->run_away)
1503 return absdir (dir + 4); 1499 return absdir (dir + 4);
1500
1504 return dist_att (dir, ob, enemy, part, rv); 1501 return dist_att (dir, ob, enemy, part, rv);
1505} 1502}
1506 1503
1507int 1504int
1508wait_att2 (int dir, object *ob, object *enemy, object *part, rv_vector * rv) 1505wait_att2 (int dir, object *ob, object *enemy, object *part, rv_vector * rv)
1509{ 1506{
1510 if (rv->distance < 9) 1507 if (rv->distance < 9)
1511 return absdir (dir + 4); 1508 return absdir (dir + 4);
1509
1512 return 0; 1510 return 0;
1513} 1511}
1514 1512
1515void 1513void
1516circ1_move (object *ob) 1514circ1_move (object *ob)
1517{ 1515{
1518 static int circle[12] = { 3, 3, 4, 5, 5, 6, 7, 7, 8, 1, 1, 2 }; 1516 static int circle[12] = { 3, 3, 4, 5, 5, 6, 7, 7, 8, 1, 1, 2 };
1517
1519 if (++ob->move_status > 11) 1518 if (++ob->move_status > 11)
1520 ob->move_status = 0; 1519 ob->move_status = 0;
1520
1521 if (!(move_object (ob, circle[ob->move_status]))) 1521 if (!(move_object (ob, circle[ob->move_status])))
1522 (void) move_object (ob, RANDOM () % 8 + 1); 1522 move_object (ob, rndm (8) + 1);
1523} 1523}
1524 1524
1525void 1525void
1526circ2_move (object *ob) 1526circ2_move (object *ob)
1527{ 1527{
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 }; 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 };
1529
1529 if (++ob->move_status > 19) 1530 if (++ob->move_status > 19)
1530 ob->move_status = 0; 1531 ob->move_status = 0;
1532
1531 if (!(move_object (ob, circle[ob->move_status]))) 1533 if (!(move_object (ob, circle[ob->move_status])))
1532 (void) move_object (ob, RANDOM () % 8 + 1); 1534 move_object (ob, rndm (8) + 1);
1533} 1535}
1534 1536
1535void 1537void
1536pace_movev (object *ob) 1538pace_movev (object *ob)
1537{ 1539{
1538 if (ob->move_status++ > 6) 1540 if (ob->move_status++ > 6)
1539 ob->move_status = 0; 1541 ob->move_status = 0;
1542
1540 if (ob->move_status < 4) 1543 if (ob->move_status < 4)
1541 (void) move_object (ob, 5); 1544 move_object (ob, 5);
1542 else 1545 else
1543 (void) move_object (ob, 1); 1546 move_object (ob, 1);
1544} 1547}
1545 1548
1546void 1549void
1547pace_moveh (object *ob) 1550pace_moveh (object *ob)
1548{ 1551{
1549 if (ob->move_status++ > 6) 1552 if (ob->move_status++ > 6)
1550 ob->move_status = 0; 1553 ob->move_status = 0;
1554
1551 if (ob->move_status < 4) 1555 if (ob->move_status < 4)
1552 (void) move_object (ob, 3); 1556 move_object (ob, 3);
1553 else 1557 else
1554 (void) move_object (ob, 7); 1558 move_object (ob, 7);
1555} 1559}
1556 1560
1557void 1561void
1558pace2_movev (object *ob) 1562pace2_movev (object *ob)
1559{ 1563{
1560 if (ob->move_status++ > 16) 1564 if (ob->move_status++ > 16)
1561 ob->move_status = 0; 1565 ob->move_status = 0;
1566
1562 if (ob->move_status < 6) 1567 if (ob->move_status < 6)
1563 (void) move_object (ob, 5); 1568 move_object (ob, 5);
1564 else if (ob->move_status < 8) 1569 else if (ob->move_status < 8)
1565 return; 1570 return;
1566 else if (ob->move_status < 13) 1571 else if (ob->move_status < 13)
1567 (void) move_object (ob, 1); 1572 move_object (ob, 1);
1568 else 1573 else
1569 return; 1574 return;
1570} 1575}
1571 1576
1572void 1577void
1573pace2_moveh (object *ob) 1578pace2_moveh (object *ob)
1574{ 1579{
1575 if (ob->move_status++ > 16) 1580 if (ob->move_status++ > 16)
1576 ob->move_status = 0; 1581 ob->move_status = 0;
1582
1577 if (ob->move_status < 6) 1583 if (ob->move_status < 6)
1578 (void) move_object (ob, 3); 1584 move_object (ob, 3);
1579 else if (ob->move_status < 8) 1585 else if (ob->move_status < 8)
1580 return; 1586 return;
1581 else if (ob->move_status < 13) 1587 else if (ob->move_status < 13)
1582 (void) move_object (ob, 7); 1588 move_object (ob, 7);
1583 else 1589 else
1584 return; 1590 return;
1585} 1591}
1586 1592
1587void 1593void
1588rand_move (object *ob) 1594rand_move (object *ob)
1589{ 1595{
1590 int i; 1596 int i;
1591 1597
1592 if (ob->move_status < 1 || ob->move_status > 8 || !(move_object (ob, ob->move_status || !(RANDOM () % 9)))) 1598 if (ob->move_status < 1 || ob->move_status > 8 || !(move_object (ob, ob->move_status || !(rndm (9)))))
1593 for (i = 0; i < 5; i++) 1599 for (i = 0; i < 5; i++)
1594 if (move_object (ob, ob->move_status = RANDOM () % 8 + 1)) 1600 if (move_object (ob, ob->move_status = rndm (8) + 1))
1595 return; 1601 return;
1596} 1602}
1597 1603
1598void 1604void
1599check_earthwalls (object *op, maptile *m, int x, int y) 1605check_earthwalls (object *op, maptile *m, int x, int y)
1630 * monsters to throw things like chairs and other pieces of 1636 * monsters to throw things like chairs and other pieces of
1631 * furniture, even if they are not good throwable objects. 1637 * furniture, even if they are not good throwable objects.
1632 * Probably better to have the monster throw a throwable object 1638 * Probably better to have the monster throw a throwable object
1633 * first, then throw any non equipped weapon. 1639 * first, then throw any non equipped weapon.
1634 */ 1640 */
1635
1636object * 1641object *
1637find_mon_throw_ob (object *op) 1642find_mon_throw_ob (object *op)
1638{ 1643{
1639 object *tmp = NULL; 1644 object *tmp = NULL;
1640 1645
1644 tmp = op; 1649 tmp = op;
1645 1650
1646 /* New throw code: look through the inventory. Grap the first legal is_thrown 1651 /* New throw code: look through the inventory. Grap the first legal is_thrown
1647 * marked item and throw it to the enemy. 1652 * marked item and throw it to the enemy.
1648 */ 1653 */
1649
1650 for (tmp = op->inv; tmp; tmp = tmp->below) 1654 for (tmp = op->inv; tmp; tmp = tmp->below)
1651 { 1655 {
1652
1653 /* Can't throw invisible objects or items that are applied */ 1656 /* Can't throw invisible objects or items that are applied */
1654 if (tmp->invisible || QUERY_FLAG (tmp, FLAG_APPLIED)) 1657 if (tmp->invisible || QUERY_FLAG (tmp, FLAG_APPLIED))
1655 continue; 1658 continue;
1656 1659
1657 if (QUERY_FLAG (tmp, FLAG_IS_THROWN)) 1660 if (QUERY_FLAG (tmp, FLAG_IS_THROWN))
1780 /* ah, we are within range, detected? take cases */ 1783 /* ah, we are within range, detected? take cases */
1781 if (!enemy->invisible) /* enemy in dark squares... are seen! */ 1784 if (!enemy->invisible) /* enemy in dark squares... are seen! */
1782 return 1; 1785 return 1;
1783 1786
1784 /* hidden or low-quality invisible */ 1787 /* hidden or low-quality invisible */
1785 if (enemy->hide && (rv->distance <= 1) && (RANDOM () % 100 <= hide_discovery)) 1788 if (enemy->hide && (rv->distance <= 1) && (rndm (100) <= hide_discovery))
1786 { 1789 {
1787 make_visible (enemy); 1790 make_visible (enemy);
1788 /* inform players of new status */ 1791 /* inform players of new status */
1789 if (enemy->type == PLAYER && player_can_view (enemy, op)) 1792 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); 1793 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 1800 * do something to you. Decreasing the duration of invisible
1798 * doesn't make a lot of sense IMO, as a bunch of stupid creatures 1801 * 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 - 1802 * can then basically negate the spell. The spell isn't negated -
1800 * they just know where you are! 1803 * they just know where you are!
1801 */ 1804 */
1802 if ((RANDOM () % 50) <= hide_discovery) 1805 if ((rndm (50)) <= hide_discovery)
1803 { 1806 {
1804 if (enemy->type == PLAYER) 1807 if (enemy->type == PLAYER)
1805 { 1808 {
1806 new_draw_info_format (NDI_UNIQUE, 0, enemy, "You see %s noticing your position.", query_name (op)); 1809 new_draw_info_format (NDI_UNIQUE, 0, enemy, "You see %s noticing your position.", query_name (op));
1807 } 1810 }
1817/* determine if op stands in a lighted square. This is not a very 1820/* 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 1821 * intellegent algorithm. For one thing, we ignore los here, SO it
1819 * is possible for a bright light to illuminate a player on the 1822 * is possible for a bright light to illuminate a player on the
1820 * other side of a wall (!). 1823 * other side of a wall (!).
1821 */ 1824 */
1822
1823int 1825int
1824stand_in_light (object *op) 1826stand_in_light (object *op)
1825{ 1827{
1826 sint16 nx, ny; 1828 sint16 nx, ny;
1827 maptile *m; 1829 maptile *m;
1828 1830
1829
1830 if (!op) 1831 if (!op)
1831 return 0; 1832 return 0;
1833
1832 if (op->glow_radius > 0) 1834 if (op->glow_radius > 0)
1833 return 1; 1835 return 1;
1834 1836
1835 if (op->map) 1837 if (op->map)
1836 { 1838 {
1837 int x, y, x1, y1; 1839 int x, y, x1, y1;
1838
1839
1840 1840
1841 /* Check the spaces with the max light radius to see if any of them 1841 /* 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. 1842 * have lights, and if any of them light the player enough, then return 1.
1843 */ 1843 */
1844 for (x = op->x - MAX_LIGHT_RADII; x <= op->x + MAX_LIGHT_RADII; x++) 1844 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)) 1857 if (isqrt (x1 + y1) < GET_MAP_LIGHT (m, nx, ny))
1858 return 1; 1858 return 1;
1859 } 1859 }
1860 } 1860 }
1861 } 1861 }
1862
1862 return 0; 1863 return 0;
1863} 1864}
1864
1865 1865
1866/* assuming no walls/barriers, lets check to see if its *possible* 1866/* assuming no walls/barriers, lets check to see if its *possible*
1867 * to see an enemy. Note, "detection" is different from "seeing". 1867 * to see an enemy. Note, "detection" is different from "seeing".
1868 * See can_detect_enemy() for more details. -b.t. 1868 * See can_detect_enemy() for more details. -b.t.
1869 * return 0 if can't be seen, 1 if can be 1869 * return 0 if can't be seen, 1 if can be
1870 */ 1870 */
1871
1872int 1871int
1873can_see_enemy (object *op, object *enemy) 1872can_see_enemy (object *op, object *enemy)
1874{ 1873{
1875 object *looker = op->head ? op->head : op; 1874 object *looker = op->head ? op->head : op;
1876 1875

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines