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.26 by root, Tue Apr 24 12:32:16 2007 UTC vs.
Revision 1.27 by root, Mon Apr 30 04:25:30 2007 UTC

901 * 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.
902 * 902 *
903 * At the moment this is only useful for throwing, perhaps for 903 * At the moment this is only useful for throwing, perhaps for
904 * 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
905 */ 905 */
906
907int 906int
908monster_use_skill (object *head, object *part, object *pl, int dir) 907monster_use_skill (object *head, object *part, object *pl, int dir)
909{ 908{
910 object *skill, *owner; 909 object *skill, *owner;
911 910
917 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);
918 917
919 if (dirdiff (dir, dir2) < 1) 918 if (dirdiff (dir, dir2) < 1)
920 return 0; /* Might hit owner with skill -thrown rocks for example ? */ 919 return 0; /* Might hit owner with skill -thrown rocks for example ? */
921 } 920 }
921
922 if (QUERY_FLAG (head, FLAG_CONFUSED)) 922 if (QUERY_FLAG (head, FLAG_CONFUSED))
923 dir = absdir (dir + rndm (3) + rndm (3) - 2); 923 dir = absdir (dir + rndm (3) + rndm (3) - 2);
924 924
925 /* skill selection - monster will use the next unused skill. 925 /* skill selection - monster will use the next unused skill.
926 * well...the following scenario will allow the monster to 926 * well...the following scenario will allow the monster to
927 * 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
928 * more skills available to monsters. 928 * more skills available to monsters.
929 */ 929 */
930 930
931 for (skill = head->inv; skill != NULL; skill = skill->below) 931 for (skill = head->inv; skill; skill = skill->below)
932 if (skill->type == SKILL && skill != head->chosen_skill) 932 if (skill->type == SKILL && skill != head->chosen_skill)
933 { 933 {
934 head->chosen_skill = skill; 934 head->chosen_skill = skill;
935 break; 935 break;
936 } 936 }
939 { 939 {
940 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);
941 CLEAR_FLAG (head, FLAG_READY_SKILL); 941 CLEAR_FLAG (head, FLAG_READY_SKILL);
942 return 0; 942 return 0;
943 } 943 }
944
944 /* use skill */ 945 /* use skill */
945 return do_skill (head, part, head->chosen_skill, dir, NULL); 946 return do_skill (head, part, head->chosen_skill, dir, NULL);
946} 947}
947 948
948/* Monster will use a ranged spell attack. */ 949/* Monster will use a ranged spell attack. */
949
950int 950int
951monster_use_range (object *head, object *part, object *pl, int dir) 951monster_use_range (object *head, object *part, object *pl, int dir)
952{ 952{
953 object *wand, *owner; 953 object *wand, *owner;
954 int at_least_one = 0; 954 int at_least_one = 0;
964 return 0; /* Might hit owner with spell */ 964 return 0; /* Might hit owner with spell */
965 } 965 }
966 if (QUERY_FLAG (head, FLAG_CONFUSED)) 966 if (QUERY_FLAG (head, FLAG_CONFUSED))
967 dir = absdir (dir + rndm (3) + rndm (3) - 2); 967 dir = absdir (dir + rndm (3) + rndm (3) - 2);
968 968
969 for (wand = head->inv; wand != NULL; wand = wand->below) 969 for (wand = head->inv; wand; wand = wand->below)
970 { 970 {
971 if (wand->type == WAND) 971 if (wand->type == WAND)
972 { 972 {
973 /* Found a wand, let's see if it has charges left */ 973 /* Found a wand, let's see if it has charges left */
974 at_least_one = 1; 974 at_least_one = 1;
1075 1075
1076 if (val > 0) 1076 if (val > 0)
1077 return 1; 1077 return 1;
1078 else 1078 else
1079 return 0; 1079 return 0;
1080
1081} 1080}
1082 1081
1083int 1082int
1084check_good_armour (object *who, object *item) 1083check_good_armour (object *who, object *item)
1085{ 1084{
1116 1115
1117 if (val > 0) 1116 if (val > 0)
1118 return 1; 1117 return 1;
1119 else 1118 else
1120 return 0; 1119 return 0;
1121
1122} 1120}
1123 1121
1124/* 1122/*
1125 * monster_check_pickup(): checks for items that monster can pick up. 1123 * monster_check_pickup(): checks for items that monster can pick up.
1126 * 1124 *
1134 * 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
1135 * 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
1136 * 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
1137 * affect stacking on this space. 1135 * affect stacking on this space.
1138 */ 1136 */
1139
1140void 1137void
1141monster_check_pickup (object *monster) 1138monster_check_pickup (object *monster)
1142{ 1139{
1143 object *tmp, *next; 1140 object *tmp, *next;
1144 1141
1163 * monster_can_pick(): If the monster is interested in picking up 1160 * monster_can_pick(): If the monster is interested in picking up
1164 * the item, then return 0. Otherwise 0. 1161 * the item, then return 0. Otherwise 0.
1165 * Instead of pick_up, flags for "greed", etc, should be used. 1162 * Instead of pick_up, flags for "greed", etc, should be used.
1166 * 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.
1167 */ 1164 */
1168
1169int 1165int
1170monster_can_pick (object *monster, object *item) 1166monster_can_pick (object *monster, object *item)
1171{ 1167{
1172 int flag = 0; 1168 int flag = 0;
1173 int i; 1169 int i;
1231 case BOW: 1227 case BOW:
1232 case ARROW: 1228 case ARROW:
1233 flag = QUERY_FLAG (monster, FLAG_USE_BOW); 1229 flag = QUERY_FLAG (monster, FLAG_USE_BOW);
1234 break; 1230 break;
1235 } 1231 }
1232
1236 /* 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
1237 * 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
1238 * use several locations. 1235 * use several locations.
1239 */ 1236 */
1240 for (i = 0; i < NUM_BODY_LOCATIONS; i++) 1237 for (i = 0; i < NUM_BODY_LOCATIONS; i++)
1255 * monster_apply_below(): 1252 * monster_apply_below():
1256 * 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
1257 * eager to apply things, encounters something apply-able, 1254 * eager to apply things, encounters something apply-able,
1258 * then make him apply it 1255 * then make him apply it
1259 */ 1256 */
1260
1261void 1257void
1262monster_apply_below (object *monster) 1258monster_apply_below (object *monster)
1263{ 1259{
1264 object *tmp, *next; 1260 object *tmp, *next;
1265 1261
1292 * 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.
1293 * (so that other monsters can pick it up and use it) 1289 * (so that other monsters can pick it up and use it)
1294 * Note that as things are now, monsters never drop something - 1290 * Note that as things are now, monsters never drop something -
1295 * they can pick up all that they can use. 1291 * they can pick up all that they can use.
1296 */ 1292 */
1297
1298/* Sept 96, fixed this so skills will be readied -b.t.*/ 1293/* Sept 96, fixed this so skills will be readied -b.t.*/
1299
1300void 1294void
1301monster_check_apply (object *mon, object *item) 1295monster_check_apply (object *mon, object *item)
1302{ 1296{
1303
1304 int flag = 0; 1297 int flag = 0;
1305 1298
1306 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)))
1307 { 1300 {
1308 SET_FLAG (mon, FLAG_CAST_SPELL); 1301 SET_FLAG (mon, FLAG_CAST_SPELL);
1309 return; 1302 return;
1310 } 1303 }
1311 1304
1320 if (QUERY_FLAG (mon, FLAG_USE_BOW) && item->type == ARROW) 1313 if (QUERY_FLAG (mon, FLAG_USE_BOW) && item->type == ARROW)
1321 { 1314 {
1322 /* Check for the right kind of bow */ 1315 /* Check for the right kind of bow */
1323 object *bow; 1316 object *bow;
1324 1317
1325 for (bow = mon->inv; bow != NULL; bow = bow->below) 1318 for (bow = mon->inv; bow; bow = bow->below)
1326 if (bow->type == BOW && bow->race == item->race) 1319 if (bow->type == BOW && bow->race == item->race)
1327 { 1320 {
1328 SET_FLAG (mon, FLAG_READY_BOW); 1321 SET_FLAG (mon, FLAG_READY_BOW);
1329 LOG (llevMonster, "Found correct bow for arrows.\n"); 1322 LOG (llevMonster, "Found correct bow for arrows.\n");
1330 return; /* nothing more to do for arrows */ 1323 return; /* nothing more to do for arrows */
1382 */ 1375 */
1383 SET_FLAG (mon, FLAG_READY_SKILL); 1376 SET_FLAG (mon, FLAG_READY_SKILL);
1384 return; 1377 return;
1385 } 1378 }
1386 1379
1387
1388 /* 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.
1389 * 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,
1390 * bolts, and whatever else, because it only checks against the 1382 * bolts, and whatever else, because it only checks against the
1391 * body_info locations. 1383 * body_info locations.
1392 */ 1384 */
1403 /* should only be applying this item, not unapplying it. 1395 /* should only be applying this item, not unapplying it.
1404 * 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.
1405 * monsters have some advantages after all. 1397 * monsters have some advantages after all.
1406 */ 1398 */
1407 manual_apply (mon, item, AP_APPLY | AP_IGNORE_CURSE); 1399 manual_apply (mon, item, AP_APPLY | AP_IGNORE_CURSE);
1408
1409 return;
1410} 1400}
1411 1401
1412void 1402void
1413npc_call_help (object *op) 1403npc_call_help (object *op)
1414{ 1404{
1432 if (QUERY_FLAG (npc, FLAG_ALIVE) && QUERY_FLAG (npc, FLAG_UNAGGRESSIVE)) 1422 if (QUERY_FLAG (npc, FLAG_ALIVE) && QUERY_FLAG (npc, FLAG_UNAGGRESSIVE))
1433 npc->enemy = op->enemy; 1423 npc->enemy = op->enemy;
1434 } 1424 }
1435} 1425}
1436 1426
1437
1438int 1427int
1439dist_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)
1440{ 1429{
1441
1442 if (can_hit (part, enemy, rv)) 1430 if (can_hit (part, enemy, rv))
1443 return dir; 1431 return dir;
1444 if (rv->distance < 10) 1432 if (rv->distance < 10)
1445 return absdir (dir + 4); 1433 return absdir (dir + 4);
1446 else if (rv->distance > 18) 1434 else if (rv->distance > 18)
1447 return dir; 1435 return dir;
1436
1448 return 0; 1437 return 0;
1449} 1438}
1450 1439
1451int 1440int
1452run_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)
1453{ 1442{
1454
1455 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)
1456 { 1444 {
1457 ob->move_status++; 1445 ob->move_status++;
1458 return (dir); 1446 return (dir);
1459 } 1447 }
1460 else if (ob->move_status > 20) 1448 else if (ob->move_status > 20)
1461 ob->move_status = 0; 1449 ob->move_status = 0;
1450
1462 return absdir (dir + 4); 1451 return absdir (dir + 4);
1463} 1452}
1464 1453
1465int 1454int
1466hitrun_att (int dir, object *ob, object *enemy) 1455hitrun_att (int dir, object *ob, object *enemy)
1469 return dir; 1458 return dir;
1470 else if (ob->move_status < 50) 1459 else if (ob->move_status < 50)
1471 return absdir (dir + 4); 1460 return absdir (dir + 4);
1472 else 1461 else
1473 ob->move_status = 0; 1462 ob->move_status = 0;
1463
1474 return absdir (dir + 4); 1464 return absdir (dir + 4);
1475} 1465}
1476 1466
1477int 1467int
1478wait_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)
1487 return 0; 1477 return 0;
1488 else if (ob->move_status < 10) 1478 else if (ob->move_status < 10)
1489 return dir; 1479 return dir;
1490 else if (ob->move_status < 15) 1480 else if (ob->move_status < 15)
1491 return absdir (dir + 4); 1481 return absdir (dir + 4);
1482
1492 ob->move_status = 0; 1483 ob->move_status = 0;
1493 return 0; 1484 return 0;
1494} 1485}
1495 1486
1496int 1487int
1504 * 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
1505 * server should try to be resilant enough to avoid the problem 1496 * server should try to be resilant enough to avoid the problem
1506 */ 1497 */
1507 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)
1508 return absdir (dir + 4); 1499 return absdir (dir + 4);
1500
1509 return dist_att (dir, ob, enemy, part, rv); 1501 return dist_att (dir, ob, enemy, part, rv);
1510} 1502}
1511 1503
1512int 1504int
1513wait_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)
1514{ 1506{
1515 if (rv->distance < 9) 1507 if (rv->distance < 9)
1516 return absdir (dir + 4); 1508 return absdir (dir + 4);
1509
1517 return 0; 1510 return 0;
1518} 1511}
1519 1512
1520void 1513void
1521circ1_move (object *ob) 1514circ1_move (object *ob)
1522{ 1515{
1523 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
1524 if (++ob->move_status > 11) 1518 if (++ob->move_status > 11)
1525 ob->move_status = 0; 1519 ob->move_status = 0;
1520
1526 if (!(move_object (ob, circle[ob->move_status]))) 1521 if (!(move_object (ob, circle[ob->move_status])))
1527 (void) move_object (ob, rndm (8) + 1); 1522 move_object (ob, rndm (8) + 1);
1528} 1523}
1529 1524
1530void 1525void
1531circ2_move (object *ob) 1526circ2_move (object *ob)
1532{ 1527{
1533 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
1534 if (++ob->move_status > 19) 1530 if (++ob->move_status > 19)
1535 ob->move_status = 0; 1531 ob->move_status = 0;
1532
1536 if (!(move_object (ob, circle[ob->move_status]))) 1533 if (!(move_object (ob, circle[ob->move_status])))
1537 (void) move_object (ob, rndm (8) + 1); 1534 move_object (ob, rndm (8) + 1);
1538} 1535}
1539 1536
1540void 1537void
1541pace_movev (object *ob) 1538pace_movev (object *ob)
1542{ 1539{
1543 if (ob->move_status++ > 6) 1540 if (ob->move_status++ > 6)
1544 ob->move_status = 0; 1541 ob->move_status = 0;
1542
1545 if (ob->move_status < 4) 1543 if (ob->move_status < 4)
1546 (void) move_object (ob, 5); 1544 move_object (ob, 5);
1547 else 1545 else
1548 (void) move_object (ob, 1); 1546 move_object (ob, 1);
1549} 1547}
1550 1548
1551void 1549void
1552pace_moveh (object *ob) 1550pace_moveh (object *ob)
1553{ 1551{
1554 if (ob->move_status++ > 6) 1552 if (ob->move_status++ > 6)
1555 ob->move_status = 0; 1553 ob->move_status = 0;
1554
1556 if (ob->move_status < 4) 1555 if (ob->move_status < 4)
1557 (void) move_object (ob, 3); 1556 move_object (ob, 3);
1558 else 1557 else
1559 (void) move_object (ob, 7); 1558 move_object (ob, 7);
1560} 1559}
1561 1560
1562void 1561void
1563pace2_movev (object *ob) 1562pace2_movev (object *ob)
1564{ 1563{
1565 if (ob->move_status++ > 16) 1564 if (ob->move_status++ > 16)
1566 ob->move_status = 0; 1565 ob->move_status = 0;
1566
1567 if (ob->move_status < 6) 1567 if (ob->move_status < 6)
1568 (void) move_object (ob, 5); 1568 move_object (ob, 5);
1569 else if (ob->move_status < 8) 1569 else if (ob->move_status < 8)
1570 return; 1570 return;
1571 else if (ob->move_status < 13) 1571 else if (ob->move_status < 13)
1572 (void) move_object (ob, 1); 1572 move_object (ob, 1);
1573 else 1573 else
1574 return; 1574 return;
1575} 1575}
1576 1576
1577void 1577void
1578pace2_moveh (object *ob) 1578pace2_moveh (object *ob)
1579{ 1579{
1580 if (ob->move_status++ > 16) 1580 if (ob->move_status++ > 16)
1581 ob->move_status = 0; 1581 ob->move_status = 0;
1582
1582 if (ob->move_status < 6) 1583 if (ob->move_status < 6)
1583 (void) move_object (ob, 3); 1584 move_object (ob, 3);
1584 else if (ob->move_status < 8) 1585 else if (ob->move_status < 8)
1585 return; 1586 return;
1586 else if (ob->move_status < 13) 1587 else if (ob->move_status < 13)
1587 (void) move_object (ob, 7); 1588 move_object (ob, 7);
1588 else 1589 else
1589 return; 1590 return;
1590} 1591}
1591 1592
1592void 1593void
1635 * monsters to throw things like chairs and other pieces of 1636 * monsters to throw things like chairs and other pieces of
1636 * furniture, even if they are not good throwable objects. 1637 * furniture, even if they are not good throwable objects.
1637 * Probably better to have the monster throw a throwable object 1638 * Probably better to have the monster throw a throwable object
1638 * first, then throw any non equipped weapon. 1639 * first, then throw any non equipped weapon.
1639 */ 1640 */
1640
1641object * 1641object *
1642find_mon_throw_ob (object *op) 1642find_mon_throw_ob (object *op)
1643{ 1643{
1644 object *tmp = NULL; 1644 object *tmp = NULL;
1645 1645
1820/* 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
1821 * intellegent algorithm. For one thing, we ignore los here, SO it 1821 * intellegent algorithm. For one thing, we ignore los here, SO it
1822 * 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
1823 * other side of a wall (!). 1823 * other side of a wall (!).
1824 */ 1824 */
1825
1826int 1825int
1827stand_in_light (object *op) 1826stand_in_light (object *op)
1828{ 1827{
1829 sint16 nx, ny; 1828 sint16 nx, ny;
1830 maptile *m; 1829 maptile *m;
1831 1830
1832
1833 if (!op) 1831 if (!op)
1834 return 0; 1832 return 0;
1833
1835 if (op->glow_radius > 0) 1834 if (op->glow_radius > 0)
1836 return 1; 1835 return 1;
1837 1836
1838 if (op->map) 1837 if (op->map)
1839 { 1838 {
1840 int x, y, x1, y1; 1839 int x, y, x1, y1;
1841
1842
1843 1840
1844 /* 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
1845 * 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.
1846 */ 1843 */
1847 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++)
1860 if (isqrt (x1 + y1) < GET_MAP_LIGHT (m, nx, ny)) 1857 if (isqrt (x1 + y1) < GET_MAP_LIGHT (m, nx, ny))
1861 return 1; 1858 return 1;
1862 } 1859 }
1863 } 1860 }
1864 } 1861 }
1862
1865 return 0; 1863 return 0;
1866} 1864}
1867
1868 1865
1869/* assuming no walls/barriers, lets check to see if its *possible* 1866/* assuming no walls/barriers, lets check to see if its *possible*
1870 * to see an enemy. Note, "detection" is different from "seeing". 1867 * to see an enemy. Note, "detection" is different from "seeing".
1871 * See can_detect_enemy() for more details. -b.t. 1868 * See can_detect_enemy() for more details. -b.t.
1872 * return 0 if can't be seen, 1 if can be 1869 * return 0 if can't be seen, 1 if can be
1873 */ 1870 */
1874
1875int 1871int
1876can_see_enemy (object *op, object *enemy) 1872can_see_enemy (object *op, object *enemy)
1877{ 1873{
1878 object *looker = op->head ? op->head : op; 1874 object *looker = op->head ? op->head : op;
1879 1875

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines