1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634
|
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*
* Based on the original sources
* Faery Tale II -- The Halls of the Dead
* (c) 1993-1996 The Wyrmkeep Entertainment Co.
*/
#include "common/debug.h"
#include "saga2/saga2.h"
#include "saga2/detection.h"
#include "saga2/dispnode.h"
#include "saga2/tile.h"
#include "saga2/motion.h"
#include "saga2/task.h"
#include "saga2/assign.h"
#include "saga2/setup.h"
#include "saga2/stimtype.h"
#include "saga2/band.h"
#include "saga2/sensor.h"
#include "saga2/weapons.h"
#include "saga2/localize.h"
#include "saga2/intrface.h"
#include "saga2/contain.h"
#include "saga2/combat.h"
// Include files needed for SAGA script dispatch
#include "saga2/script.h"
#include "saga2/methods.r" // generated by SAGA
namespace Saga2 {
/* ===================================================================== *
Externals
* ===================================================================== */
extern uint8 identityColors[256];
extern hResContext *listRes; // object list resource handle
extern int16 actorLimboCount;
bool unstickObject(GameObject *obj);
extern ObjectSoundFXs *objectSoundFXTable; // the global object sound effects table
#if DEBUG
extern bool massAndBulkCount;
#endif
/* ===================================================================== *
ActorProto member functions
* ===================================================================== */
//-----------------------------------------------------------------------
// Return a bit mask indicating the properties of this object type
uint16 ActorProto::containmentSet() {
// All actors may also be weapons (indicating natural attacks)
return ProtoObj::containmentSet() | kIsWeapon;
}
//-----------------------------------------------------------------------
// Determine if the specified object can be contained by this object
bool ActorProto::canContain(ObjectID dObj, ObjectID item) {
assert(isActor(dObj));
assert(isObject(item) || isActor(item));
GameObject *itemPtr = GameObject::objectAddress(item);
// Actors can contain any object, except worlds and other actors
return isObject(item)
&& ((itemPtr->containmentSet() & ProtoObj::kIsIntangible) == 0
|| itemPtr->possessor() == dObj);
}
//-----------------------------------------------------------------------
// Determine if the specified object can be contained by this object at
// the specified slot
bool ActorProto::canContainAt(
ObjectID dObj,
ObjectID item,
const TilePoint &) {
assert(isActor(dObj));
assert(isObject(item) || isActor(item));
GameObject *itemPtr = GameObject::objectAddress(item);
// Actors can contain any object, except worlds and other actors
// REM: must add test to determine if specified slot is valid.
return isObject(item)
&& ((itemPtr->containmentSet() & ProtoObj::kIsIntangible) == 0
|| itemPtr->possessor() == dObj);
}
weaponID ActorProto::getWeaponID() {
return weaponDamage;
}
//-----------------------------------------------------------------------
// use this actor
bool ActorProto::useAction(ObjectID dObj, ObjectID enactor) {
assert(isActor(dObj));
Actor *a = (Actor *)GameObject::objectAddress(dObj);
if (a->isDead())
return ((PhysicalContainerProto *)this)->PhysicalContainerProto::useAction(dObj, enactor);
return false;
}
//-----------------------------------------------------------------------
// Determine if this actor can be opened
bool ActorProto::canOpen(ObjectID dObj, ObjectID) {
assert(isActor(dObj));
return ((Actor *)GameObject::objectAddress(dObj))->isDead();
}
//-----------------------------------------------------------------------
// open this actor
// Kludge!
extern int16 openMindType;
bool ActorProto::openAction(ObjectID dObj, ObjectID) {
assert(isActor(dObj));
ContainerNode *cn;
GameObject *dObjPtr = GameObject::objectAddress(dObj);
assert(!dObjPtr->isOpen() && !dObjPtr->isLocked());
cn = CreateContainerNode(dObj, false, openMindType);
cn->markForShow(); // Deferred open
dObjPtr->_data.objectFlags |= kObjectOpen; // Set open bit;
return true;
}
//-----------------------------------------------------------------------
// close this actor
bool ActorProto::closeAction(ObjectID dObj, ObjectID) {
assert(isActor(dObj));
GameObject *dObjPtr = GameObject::objectAddress(dObj);
ContainerNode *cn = g_vm->_cnm->find(dObj, ContainerNode::kDeadType);
assert(dObjPtr->isOpen());
assert(cn);
// Delete the container (lazy delete)
cn->markForDelete();
// Clear open bit
dObjPtr->_data.objectFlags &= ~kObjectOpen;
return true;
}
//-----------------------------------------------------------------------
bool ActorProto::strikeAction(
ObjectID dObj,
ObjectID enactor,
ObjectID item) {
assert(isActor(dObj));
assert(isActor(enactor));
assert(isObject(item) || isActor(item));
Actor *a = (Actor *)GameObject::objectAddress(enactor);
ActorAttributes *effStats = a->getStats();
GameObject *itemPtr = GameObject::objectAddress(item);
ObjectSoundFXs *soundFXs;
Location al = Location(a->getLocation(), a->IDParent());
if (itemPtr->acceptStrike(enactor, dObj, effStats->getSkillLevel(kSkillIDBludgeon)))
return true;
soundFXs = &objectSoundFXTable[soundFXClass];
makeCombatSound(soundFXs->soundFXMissed, al);
return false;
}
bool ActorProto::damageAction(
ObjectID dObj,
ObjectID enactor,
ObjectID target) {
assert(isActor(dObj));
assert(isActor(enactor));
assert(isObject(target) || isActor(target));
Actor *a = (Actor *)GameObject::objectAddress(enactor);
ActorAttributes *effStats = a->getStats();
WeaponStuff *ws = &getWeapon(getWeaponID());
GameObject *targetPtr = GameObject::objectAddress(target);
uint8 damageSoundID;
Location al = Location(a->getLocation(), a->IDParent());
damageSoundID = targetPtr->proto()->getDamageSound(
objectSoundFXTable[soundFXClass]);
if (damageSoundID != 0)
makeCombatSound(damageSoundID, al);
ws->implement(
a,
GameObject::objectAddress(target),
GameObject::objectAddress(dObj),
effStats->getSkillLevel(kSkillIDBrawn));
return true;
}
//-----------------------------------------------------------------------
// Routine that is called when an object is dragged & dropped
// onto an actor.
bool ActorProto::acceptDropAction(
ObjectID dObj, // object dropped on
ObjectID enactor, // person doing dropping
ObjectID droppedID, // ID of dropped object
int count) {
assert(isActor(dObj));
Actor *a = (Actor *)GameObject::objectAddress(dObj);
GameObject *droppedObj = GameObject::objectAddress(droppedID);
if (a->isDead()) {
a->dropInventoryObject(droppedObj, count);
return true;
}
Location newLoc;
uint16 dropType;
// For now, we'll just drop the object into the actor's
// inventory.
//
// REM: We might want to arrange the inventory item in a
// semi-sensible way, like putting the new item at the
// head of the list. (Do this by changing the newLoc coord
// fields...)
//
// REM: We might want to ask the object how it feels about
// being given to an actor...
// NOTE: Added check so that dropping an object on an actor who
// already has the object will do nothing.
if (droppedObj->IDParent() == dObj) return true;
dropType = droppedObj->containmentSet();
scriptResult result;
scriptCallFrame scf;
scf.invokedObject = dObj;
scf.enactor = enactor;
scf.directObject = droppedID;
scf.indirectObject = dObj;
if (dropType & kIsIntangible) {
// Set up the arguments we want to pass to the script
scf.value = droppedObj->proto()->lockType + kSenseIdeaGreeting;
// Invoke the script...
if (dropType & kIsConcept) {
runObjectMethod(dObj, Method_Actor_onTalkTo, scf);
} else if (dropType & kIsPsych) {
// What to do???
} else if (dropType & (kIsSpell | kIsSkill)) {
// What to do???
// Cast the spell on the actor?
}
} else {
scf.value = count;
result = runObjectMethod(dObj, Method_Actor_onReceive, scf);
if (result == kScriptResultFinished
&& scf.returnVal != kActionResultNotDone)
return scf.returnVal == kActionResultSuccess;
// Place the object in the actor's inventory (if possible)
if (!a->placeObject(enactor, droppedID, true, count))
a->dropInventoryObject(droppedObj, count);
}
return true;
}
//-----------------------------------------------------------------------
// Call the actor's "greet" script.
bool ActorProto::greetActor(
ObjectID dObj, // object dropped on
ObjectID enactor) { // person doing dropping
assert(isActor(dObj));
scriptCallFrame scf;
scf.invokedObject = dObj;
scf.enactor = enactor;
scf.directObject = Nothing;
scf.indirectObject = Nothing;
scf.value = kSenseIdeaGreeting;
return runObjectMethod(dObj, Method_Actor_onTalkTo, scf);
}
//-----------------------------------------------------------------------
// cause damage directly
bool ActorProto::acceptDamageAction(
ObjectID dObj,
ObjectID enactor,
int8 absDamage,
effectDamageTypes dType,
int8 dice,
uint8 sides,
int8) {
assert(isActor(dObj));
assert(isObject(enactor) || isActor(enactor));
int8 pdm = 0; //=perDieMod+(resistant ? -2 : 0);
int16 damageScore = 0;
Actor *a = (Actor *)GameObject::objectAddress(dObj);
Actor *enactorPtr;
int16 &vitality = a->_effectiveStats.vitality;
bool resistant = a->resists((effectResistTypes) dType);
PlayerActorID pID;
if (!a->isImmuneTo((effectImmuneTypes) dType)) {
damageScore = absDamage;
if (dice)
for (int d = 0; d < ABS(dice); d++)
damageScore += (g_vm->_rnd->getRandomNumber(sides - 1) + pdm + 1) * (dice > 0 ? 1 : -1);
}
if (damageScore > 0 && resistant)
damageScore /= 2;
if (damageScore > 0 && isMagicDamage(dType) && makeSavingThrow())
damageScore /= 2;
if (damageScore < 0)
return acceptHealing(dObj, enactor, -damageScore);
// Apply applicable armor adjustments
if (dType == kDamageImpact
|| dType == kDamageSlash
|| dType == kDamageProjectile) {
ArmorAttributes armorAttribs;
a->totalArmorAttributes(armorAttribs);
damageScore /= armorAttribs.damageDivider;
damageScore = MAX(damageScore - armorAttribs.damageAbsorbtion, 0);
}
if (damageScore == 0) return false;
if (isActor(enactor))
enactorPtr = (Actor *)GameObject::objectAddress(enactor);
else {
ObjectID possessorID;
possessorID = GameObject::objectAddress(enactor)->possessor();
enactorPtr = possessorID != Nothing
? (Actor *)GameObject::objectAddress(possessorID)
: nullptr;
}
if (vitality > 0) {
Location al = Location(a->getLocation(), a->IDParent());
if (gruntStyle > 0
&& ((flags & ResourceObjectPrototype::kObjPropNoSurface)
|| (damageScore > 2 && (int16)g_vm->_rnd->getRandomNumber(vitality - 1) < (damageScore * 2))))
makeGruntSound(gruntStyle, al);
if (enactorPtr != nullptr) {
enactorPtr->handleSuccessfulStrike(
a,
damageScore < vitality ? damageScore : vitality);
}
// If we've just lost all vitality, we're dead, else make a
// morale check
if (damageScore >= vitality) {
MotionTask::die(*a);
AddFactionTally(a->_faction, kFactionNumKills, 1);
if (enactorPtr != nullptr)
enactorPtr->handleSuccessfulKill(a);
} else
a->handleDamageTaken(damageScore);
vitality -= damageScore;
if (actorToPlayerID(a, pID)) {
updateBrotherControls(pID);
if (vitality > 0) {
int16 baseVitality,
oldVitality;
baseVitality = a->getBaseStats()->vitality;
oldVitality = vitality + damageScore;
if (baseVitality >= vitality * 3
&& baseVitality < oldVitality * 3) {
StatusMsg(WOUNDED_STATUS, a->objName());
} else if (baseVitality * 2 >= vitality * 3
&& baseVitality * 2 < oldVitality * 3) {
StatusMsg(HURT_STATUS, a->objName());
}
}
}
WriteStatusF(5, "Damage: %d", damageScore);
}
return true;
}
//-----------------------------------------------------------------------
// cause healing directly
bool ActorProto::acceptHealingAction(
ObjectID dObj,
ObjectID,
int8 healing) {
assert(isActor(dObj));
Actor *a = (Actor *)GameObject::objectAddress(dObj);
int16 &vitality = a->_effectiveStats.vitality;
int16 maxVitality = (a->getBaseStats())->vitality;
PlayerActorID pID;
if (vitality > 0 && !a->hasEffect(kActorDiseased)) {
// If we've just lost all vitality, we're dead, else make a
// morale check
vitality += healing;
vitality = clamp(0, vitality, maxVitality);
if (actorToPlayerID(a, pID))
updateBrotherControls(pID);
WriteStatusF(5, "Healing: %d", healing);
} else
return false;
return true;
}
//-----------------------------------------------------------------------
// Accept strike from an object (allows this actor to cause damage to
// the striking object).
bool ActorProto::acceptStrikeAction(
ObjectID dObj,
ObjectID enactor,
ObjectID strikingObj,
uint8 skillIndex) {
assert(isActor(dObj));
assert(isActor(enactor));
const int toHitBase = 100;
const int avgHitChance = toHitBase / 2;
const int skillScalingFactor =
(avgHitChance
+ ActorAttributes::kSkillLevels - 1)
/ ActorAttributes::kSkillLevels;
const int dodgingBonus = 10;
Actor *a = (Actor *)GameObject::objectAddress(dObj);
ActorAttributes *effStats = a->getStats();
GameObject *weapon = GameObject::objectAddress(strikingObj);
assert(weapon->proto()->containmentSet() & ProtoObj::kIsWeapon);
Actor *enactorPtr = (Actor *)GameObject::objectAddress(enactor);
ArmorAttributes armorAttribs;
uint8 hitChance;
if (a->isDead())
return weapon->damage(enactor, dObj);
a->handleOffensiveAct((Actor *)GameObject::objectAddress(enactor));
// Sum up the armor attributes
a->totalArmorAttributes(armorAttribs);
// Determine "to hit" percentage
hitChance = avgHitChance
+ ((int)skillIndex
- (int)effStats->getSkillLevel(kSkillIDAgility))
* skillScalingFactor;
// Factor in armor bonus
hitChance -= armorAttribs.defenseBonus;
// Factor in dodging bonus if any
if (a->_moveTask != nullptr && a->_moveTask->isDodging(enactorPtr))
hitChance -= dodgingBonus;
hitChance = MAX<uint8>(hitChance, 5);
// Randomly determine hit success
if (g_vm->_rnd->getRandomNumber(toHitBase - 1) < hitChance) {
// Hit has succeeded
GameObject *blockingObj = a->blockingObject(enactorPtr);
bool blocked = false;
// Test for block success
if (blockingObj != nullptr) {
hitChance = avgHitChance
+ ((int)skillIndex
- (int)blockingObj->proto()->getSkillValue(dObj))
* skillScalingFactor;
if (g_vm->_rnd->getRandomNumber(toHitBase - 1) >= hitChance) {
// The shield was hit
blockingObj->acceptStrike(
enactor,
strikingObj,
skillIndex);
blocked = true;
// Cause skill growth
blockingObj->proto()->applySkillGrowth(dObj, 5);
}
}
if (!blocked) {
// The strike got through
weapon->damage(enactor, dObj);
// Notify the attacker of a successful strike
enactorPtr->handleSuccessfulStrike(weapon);
if (!a->isDead()) {
int16 pmass = a->proto()->mass;
if (pmass <= 100 || (int16)g_vm->_rnd->getRandomNumber(155) >= pmass - 100) {
if (g_vm->_rnd->getRandomNumber(7) == 0)
MotionTask::fallDown(*a, *enactorPtr);
else
MotionTask::acceptHit(*a, *enactorPtr);
}
}
}
return true;
} else {
// This actor has dodged the blow, apply agility growth
PlayerActorID playerID;
if (actorIDToPlayerID(dObj, playerID)) {
PlayerActor *player = getPlayerActorAddress(playerID);
player->skillAdvance(kSkillIDAgility, 1);
}
}
return false;
}
//-----------------------------------------------------------------------
// Insert another object into this object at the specified slot
bool ActorProto::acceptInsertionAtAction(
ObjectID dObj,
ObjectID,
ObjectID item,
const TilePoint &where,
int16 num) {
enum {
notInUse,
heldInLeftHand,
heldInRightHand,
worn
} inUseType;
int wornWhere = 0;
assert(isActor(dObj));
assert(isObject(item));
GameObject *dObjPtr = GameObject::objectAddress(dObj);
Actor *a = (Actor *)dObjPtr;
GameObject *itemPtr = GameObject::objectAddress(item);
GameObject *extractedObj = nullptr;
Location oldLoc(itemPtr->getLocation(), itemPtr->IDParent());
bool result;
// Split the merged object if needed.
if (itemPtr->isMergeable() // If mergeable
&& num < itemPtr->getExtra()) { // And not dropping whole pile
if (num == 0) return false; // If mergeing zero, then do nothing
extractedObj = itemPtr->extractMerged(itemPtr->getExtra() - num);
if (extractedObj == nullptr)
return false;
extractedObj->move(oldLoc);
}
// Determine if this object is simply being moved within this actor
if (oldLoc._context == dObj) {
// Determine if and where the object is in use by this actor
if (a->_leftHandObject == item)
inUseType = heldInLeftHand;
else if (a->_rightHandObject == item)
inUseType = heldInRightHand;
else {
int i;
inUseType = notInUse;
for (i = 0; i < ARMOR_COUNT; i++) {
if (a->_armorObjects[i] == item) {
inUseType = worn;
wornWhere = i;
break;
}
}
}
} else
inUseType = notInUse;
// Do the deed
itemPtr->move(Location(0, 0, 0, ImportantLimbo));
if (dObjPtr->canFitBulkwise(itemPtr)
&& dObjPtr->canFitMasswise(itemPtr)) {
itemPtr->move(Location(where, dObj));
result = true;
} else {
itemPtr->move(oldLoc);
if (extractedObj != nullptr)
GameObject::mergeWith(extractedObj, itemPtr, extractedObj->getExtra());
result = false;
}
// Re-equip the item if necessary
if (inUseType != notInUse) {
switch (inUseType) {
case heldInLeftHand:
a->holdInLeftHand(item);
break;
case heldInRightHand:
a->holdInRightHand(item);
break;
case worn:
a->wear(item, wornWhere);
break;
default:
break;
}
}
return result;
}
//-----------------------------------------------------------------------
// Initiate a natural attack motion
void ActorProto::initiateAttack(ObjectID attacker, ObjectID target) {
assert(isActor(attacker));
assert(isObject(target) || isActor(target));
Actor *attackerPtr = (Actor *)GameObject::objectAddress(attacker);
GameObject *targetPtr = GameObject::objectAddress(target);
// Start the attack motion
if (attackerPtr->_appearance != nullptr) {
if (attackerPtr->isActionAvailable(kActionSwingHigh))
MotionTask::oneHandedSwing(*attackerPtr, *targetPtr);
else if (attackerPtr->isActionAvailable(kActionTwoHandSwingHigh))
MotionTask::twoHandedSwing(*attackerPtr, *targetPtr);
} else
MotionTask::oneHandedSwing(*attackerPtr, *targetPtr);
}
//-----------------------------------------------------------------------
// Given an object sound effect record, which sound should be made
// when this object is damaged
uint8 ActorProto::getDamageSound(const ObjectSoundFXs &soundFXs) {
return !(flags & ResourceObjectPrototype::kObjPropNoSurface)
? !(flags & ResourceObjectPrototype::kObjPropHardSurface)
? soundFXs.soundFXHitFlesh
: soundFXs.soundFXHitHard
: 0;
}
//-----------------------------------------------------------------------
// Do the background processing, if needed, for this object.
void ActorProto::doBackgroundUpdate(GameObject *obj) {
// get the ID for this object
ObjectID actorID = obj->thisID();
// find out if this object is an actor
if (isActor(actorID)) {
// get a pointer to that actor
GameObject *actorObj = GameObject::objectAddress(actorID);
Actor *a = (Actor *)actorObj;
if (!a->isActivated()) {
// If this is a temporary actor waiting for expiration,
// then decrement the expiration counter and possibly
// delete the actor
if ((a->_flags & Actor::kAFTemporary) || a->isDead()) {
if (a->_deactivationCounter <= 0) {
a->deleteObjectRecursive();
return;
} else a->_deactivationCounter--;
} else {
// If the actor has failed morale there is a random
// chance of him regaining his courage
if ((a->_flags & Actor::kAFAfraid) && g_vm->_rnd->getRandomNumber(127) == 0)
a->_flags &= ~Actor::kAFAfraid;
}
}
// execute that actor's vitality update function
((Actor *)actorObj)->vitalityUpdate();
// do any updates directly related only to the brothers
if (isPlayerActor(actorID)) {
switch (actorID) {
case ActorBaseID + FTA_JULIAN:
g_vm->_playerList[FTA_JULIAN]->recoveryUpdate();
break;
case ActorBaseID + FTA_PHILIP:
g_vm->_playerList[FTA_PHILIP]->recoveryUpdate();
break;
case ActorBaseID + FTA_KEVIN:
g_vm->_playerList[FTA_KEVIN]->recoveryUpdate();
break;
default:
// no action
break;
}
}
}
// check for other updates
ProtoObj::doBackgroundUpdate(obj);
}
// ------------------------------------------------------------------------
// Cause the user's associated skill to grow
void ActorProto::applySkillGrowth(ObjectID enactor, uint8 points) {
assert(isActor(enactor));
PlayerActorID playerID;
if (actorIDToPlayerID(enactor, playerID)) {
PlayerActor *player = getPlayerActorAddress(playerID);
player->skillAdvance(kSkillIDBludgeon, points);
if (g_vm->_rnd->getRandomNumber(1))
player->skillAdvance(kSkillIDBrawn, points);
}
}
// ------------------------------------------------------------------------
bool ActorProto::canFitBulkwise(GameObject *container, GameObject *obj) {
#if DEBUG
if (massAndBulkCount)
#endif
{
uint16 maxBulk = container->bulkCapacity();
uint16 totalBulk = container->totalContainedBulk();
return totalBulk + obj->totalBulk() <= maxBulk;
}
#if DEBUG
return true;
#endif
}
// ------------------------------------------------------------------------
bool ActorProto::canFitMasswise(GameObject *container, GameObject *obj) {
assert(isActor(container));
#if DEBUG
if (massAndBulkCount)
#endif
{
Actor *a = (Actor *)container;
// get the maxium amount of weight this character should be able to carry
uint16 cmaxCapacity = container->massCapacity();
uint16 totalMass = a->totalContainedMass();
return totalMass + obj->totalMass() <= cmaxCapacity;
}
#if DEBUG
return true;
#endif
}
// ------------------------------------------------------------------------
// Return the maximum mass capacity for the specified container
uint16 ActorProto::massCapacity(GameObject *container) {
assert(isActor(container));
Actor *a = (Actor *)container;
ActorAttributes *effStats = a->getStats();
return kBaseCarryingCapacity
+ effStats->getSkillLevel(kSkillIDBrawn)
* kCarryingCapacityBonusPerBrawn;
}
// ------------------------------------------------------------------------
// Return the maximum bulk capacity for the specified container
uint16 ActorProto::bulkCapacity(GameObject *) {
return bulk * 4;
}
/* ===================================================================== *
ActorArchive struct
* ===================================================================== */
// This data structure is used in the creation of an actor archive. It
// includes all of the fixed size data fields which must be preserved in
// a save file without any of the overhead such as a base class or virtual
// member functions. Some of the Actor data members, such as moveTask
// currentTask and currentTransaction, are omitted because the links
// to these other objects will archived with their respective 'Task' object.
// Also, the assignment member was not included because it is a complex
// variable sized data structure which will be asked to archive itself.
struct ActorArchive {
uint8 faction;
uint8 colorScheme;
int32 appearanceID;
int8 attitude,
mood;
uint8 disposition;
Direction currentFacing;
int16 tetherLocU;
int16 tetherLocV;
int16 tetherDist;
ObjectID leftHandObject,
rightHandObject;
uint16 knowledge[16];
uint16 schedule;
uint8 conversationMemory[4];
uint8 currentAnimation,
currentPose,
animationFlags;
uint8 flags;
ActorPose poseInfo;
int16 cycleCount;
int16 kludgeCount;
uint32 enchantmentFlags;
uint8 currentGoal,
deactivationCounter;
ActorAttributes effectiveStats;
uint8 actionCounter;
uint16 effectiveResistance;
uint16 effectiveImmunity;
int16 recPointsPerUpdate; // fractional vitality recovery
int16 currentRecoveryPoints;
ObjectID leaderID;
BandID followersID;
ObjectID _armorObjects[ARMOR_COUNT];
ObjectID currentTargetID;
int16 scriptVar[kActorScriptVars];
};
/* ===================================================================== *
Actor member functions
* ===================================================================== */
//-----------------------------------------------------------------------
// Initialize all fields in the actor structure to neutral values.
void Actor::init(
int16 protoIndex,
uint16 nameIndex,
uint16 scriptIndex,
int32 appearanceNum,
uint8 colorSchemeIndex,
uint8 factionNum,
uint8 initFlags) {
debugC(1, kDebugActors, "Actor init flags: %d, permanent: %d", initFlags, initFlags & kActorPermanent);
// Fixup the prototype pointer to point to an actor prototype
_prototype = (ProtoObj *)g_vm->_actorProtos[protoIndex];
// Initialize object fields
// nameIndex = 0;
setNameIndex(nameIndex);
setScript(scriptIndex);
_data.parentID = _data.siblingID = _data.childID = Nothing;
_data.objectFlags = 0;
_data.massCount = 0;
_data.currentTAG = NoActiveItem;
_data.hitPoints = 0;
// Initialize actor field
_faction = factionNum;
_colorScheme = colorSchemeIndex;
_appearanceID = appearanceNum;
_attitude = 0;
_mood = 0;
_disposition = 0;
_currentFacing = kDirDown;
_tetherLocU = 0;
_tetherLocV = 0;
_tetherDist = 0;
_leftHandObject = Nothing;
_rightHandObject = Nothing;
_schedule = 0;
for (uint i = 0; i < ARRAYSIZE(_knowledge); ++i)
_knowledge[i] = 0;
// Initialize the rest of the data members
for (uint i = 0; i < ARRAYSIZE(_conversationMemory); ++i)
_conversationMemory[i] = 0;
_currentAnimation = kActionStand;
_currentPose = 0;
_animationFlags = 0;
_flags = 0;
if (!(initFlags & kActorPermanent))
_flags |= kAFTemporary;
_poseInfo.flags = 0;
_poseInfo.actorFrameIndex = 0;
_poseInfo.actorFrameBank = 0;
_poseInfo.leftObjectIndex = 0;
_poseInfo.rightObjectIndex = 0;
_poseInfo.leftObjectOffset.x = _poseInfo.leftObjectOffset.y = 0;
_poseInfo.rightObjectOffset.x = _poseInfo.rightObjectOffset.y = 0;
_appearance = nullptr;
_cycleCount = 0;
_kludgeCount = 0;
_moveTask = nullptr;
_enchantmentFlags = 0L;
_curTask = nullptr;
_currentGoal = kActorGoalFollowAssignment;
_deactivationCounter = 0;
_assignment = nullptr;
_effectiveStats = ((ActorProto *)_prototype)->baseStats;
_effectiveStats.vitality = MAX<int16>(_effectiveStats.vitality, 1);
_actionCounter = 0;
_effectiveResistance = 0;
_effectiveImmunity = 0;
_recPointsPerUpdate = BASE_REC_RATE;
_currentRecoveryPoints = 0;
_leader = nullptr;
_followers = nullptr;
_followersID = NoBand;
for (int i = 0; i < ARMOR_COUNT; i++)
_armorObjects[i] = Nothing;
_currentTarget = nullptr;
for (int i = 0; i < kActorScriptVars; i++)
_scriptVar[i] = 0;
evalActorEnchantments(this);
}
//-----------------------------------------------------------------------
// Actor constructor -- copies the resource fields and simply NULL's most
// of the rest of the data members
Actor::Actor() {
_prototype = nullptr;
_faction = 0;
_colorScheme = 0;
_appearanceID = 0;
_attitude = 0;
_mood = 0;
_disposition = 0;
_currentFacing = 0;
_tetherLocU = 0;
_tetherLocV = 0;
_tetherDist = 0;
_leftHandObject = 0;
_rightHandObject = 0;
_schedule = 0;
for (uint i = 0; i < ARRAYSIZE(_knowledge); ++i)
_knowledge[i] = 0;
// Initialize the rest of the data members
for (uint i = 0; i < ARRAYSIZE(_conversationMemory); ++i)
_conversationMemory[i] = 0;
_currentAnimation = kActionStand;
_currentPose = 0;
_animationFlags = 0;
_flags = 0;
_poseInfo.flags = 0;
_poseInfo.actorFrameIndex = 0;
_poseInfo.actorFrameBank = 0;
_poseInfo.leftObjectIndex = 0;
_poseInfo.rightObjectIndex = 0;
_poseInfo.leftObjectOffset.x = _poseInfo.leftObjectOffset.y = 0;
_poseInfo.rightObjectOffset.x = _poseInfo.rightObjectOffset.y = 0;
_appearance = nullptr;
_cycleCount = 0;
_kludgeCount = 0;
_moveTask = nullptr;
_enchantmentFlags = 0L;
_curTask = nullptr;
_currentGoal = kActorGoalFollowAssignment;
_deactivationCounter = 0;
_assignment = nullptr;
memset(&_effectiveStats, 0, sizeof(_effectiveStats));
_effectiveStats.vitality = MAX<uint16>(_effectiveStats.vitality, 1);
_actionCounter = 0;
_effectiveResistance = 0;
_effectiveImmunity = 0;
_recPointsPerUpdate = BASE_REC_RATE;
_currentRecoveryPoints = 0;
_leader = nullptr;
_leaderID = Nothing;
_followers = nullptr;
_followersID = NoBand;
for (int i = 0; i < ARMOR_COUNT; i++)
_armorObjects[i] = Nothing;
_currentTarget = nullptr;
_currentTargetID = Nothing;
for (int i = 0; i < kActorScriptVars; i++)
_scriptVar[i] = 0;
}
Actor::Actor(const ResourceActor &res) : GameObject(res) {
// Fixup the prototype pointer to point to an actor prototype
_prototype = _prototype != nullptr
? (ProtoObj *)g_vm->_actorProtos[getProtoNum()]
: nullptr;
// Copy the resource fields
_faction = res.faction;
_colorScheme = res.colorScheme;
_appearanceID = res.appearanceID;
_attitude = res.attitude;
_mood = res.mood;
_disposition = res.disposition;
_currentFacing = res.currentFacing;
_tetherLocU = res.tetherLocU;
_tetherLocV = res.tetherLocV;
_tetherDist = res.tetherDist;
_leftHandObject = res.leftHandObject;
_rightHandObject = res.rightHandObject;
_schedule = res.schedule;
memcpy(&_knowledge, &res.knowledge, sizeof(_knowledge));
// Initialize the rest of the data members
for (uint i = 0; i < ARRAYSIZE(_conversationMemory); ++i)
_conversationMemory[i] = 0;
_currentAnimation = kActionStand;
_currentPose = 0;
_animationFlags = 0;
_flags = 0;
_poseInfo.flags = 0;
_poseInfo.actorFrameIndex = 0;
_poseInfo.actorFrameBank = 0;
_poseInfo.leftObjectIndex = 0;
_poseInfo.rightObjectIndex = 0;
_poseInfo.leftObjectOffset.x = _poseInfo.leftObjectOffset.y = 0;
_poseInfo.rightObjectOffset.x = _poseInfo.rightObjectOffset.y = 0;
_appearance = nullptr;
_cycleCount = 0;
_kludgeCount = 0;
_moveTask = nullptr;
_enchantmentFlags = 0L;
_curTask = nullptr;
_currentGoal = kActorGoalFollowAssignment;
_deactivationCounter = 0;
_assignment = nullptr;
if (_prototype)
_effectiveStats = ((ActorProto *)_prototype)->baseStats;
_effectiveStats.vitality = MAX<uint16>(_effectiveStats.vitality, 1);
_actionCounter = 0;
_effectiveResistance = 0;
_effectiveImmunity = 0;
_recPointsPerUpdate = BASE_REC_RATE;
_currentRecoveryPoints = 0;
_leader = nullptr;
_leaderID = Nothing;
_followers = nullptr;
_followersID = NoBand;
for (int i = 0; i < ARMOR_COUNT; i++)
_armorObjects[i] = Nothing;
_currentTarget = nullptr;
_currentTargetID = Nothing;
for (int i = 0; i < kActorScriptVars; i++)
_scriptVar[i] = 0;
evalActorEnchantments(this);
}
Actor::Actor(Common::InSaveFile *in) : GameObject(in) {
// Fixup the prototype pointer to point to an actor prototype
_prototype = _prototype != nullptr
? (ProtoObj *)g_vm->_actorProtos[getProtoNum()]
: nullptr;
_faction = in->readByte();
_colorScheme = in->readByte();
_appearanceID = in->readSint32BE();
_attitude = in->readSByte();
_mood = in->readSByte();
_disposition = in->readByte();
_currentFacing = in->readByte();
_tetherLocU = in->readSint16LE();
_tetherLocV = in->readSint16LE();
_tetherDist = in->readSint16LE();
_leftHandObject = in->readUint16LE();
_rightHandObject = in->readUint16LE();
for (int i = 0; i < ARRAYSIZE(_knowledge); ++i)
_knowledge[i] = in->readUint16LE();
_schedule = in->readUint16LE();
for (int i = 0; i < ARRAYSIZE(_conversationMemory); ++i)
_conversationMemory[i] = in->readByte();
_currentAnimation = in->readByte();
_currentPose = in->readByte();
_animationFlags = in->readByte();
_flags = in->readByte();
_poseInfo.load(in);
_cycleCount = in->readSint16LE();
_kludgeCount = in->readSint16LE();
_enchantmentFlags = in->readUint32LE();
_currentGoal = in->readByte();
_deactivationCounter = in->readByte();
_effectiveStats.read(in);
_actionCounter = in->readByte();
_effectiveResistance = in->readUint16LE();
_effectiveImmunity = in->readUint16LE();
_recPointsPerUpdate = in->readSint16LE();
_currentRecoveryPoints = in->readUint16LE();
_leaderID = in->readUint16LE();
_leader = nullptr;
_followersID = in->readSint16LE();
_followers = nullptr;
for (int i = 0; i < ARRAYSIZE(_armorObjects); ++i)
_armorObjects[i] = in->readUint16LE();
_currentTargetID = in->readUint16LE();
_currentTarget = nullptr;
for (int i = 0; i < ARRAYSIZE(_scriptVar); ++i)
_scriptVar[i] = in->readSint16LE();
if (_flags & kAFHasAssignment) {
readAssignment(this, in);
} else {
_assignment = nullptr;
}
_appearance = nullptr;
_moveTask = nullptr;
_curTask = nullptr;
debugC(4, kDebugSaveload, "... _faction = %d", _faction);
debugC(4, kDebugSaveload, "... _colorScheme = %d", _colorScheme);
debugC(4, kDebugSaveload, "... _appearanceID = %d", _appearanceID);
debugC(4, kDebugSaveload, "... _attitude = %d", _attitude);
debugC(4, kDebugSaveload, "... _mood = %d", _mood);
debugC(4, kDebugSaveload, "... _disposition = %d", _disposition);
debugC(4, kDebugSaveload, "... _currentFacing = %d", _currentFacing);
debugC(4, kDebugSaveload, "... _tetherLocU = %d", _tetherLocU);
debugC(4, kDebugSaveload, "... _tetherLocV = %d", _tetherLocV);
debugC(4, kDebugSaveload, "... _tetherDist = %d", _tetherDist);
debugC(4, kDebugSaveload, "... _leftHandObject = %d", _leftHandObject);
debugC(4, kDebugSaveload, "... _rightHandObject = %d", _rightHandObject);
// debugC(4, kDebugSaveload, "... knowledge = %d", knowledge);
debugC(4, kDebugSaveload, "... _schedule = %d", _schedule);
// debugC(4, kDebugSaveload, "... conversationMemory = %d", conversationMemory);
debugC(4, kDebugSaveload, "... _currentAnimation = %d", _currentAnimation);
debugC(4, kDebugSaveload, "... _currentPose = %d", _currentPose);
debugC(4, kDebugSaveload, "... _animationFlags = %d", _animationFlags);
debugC(4, kDebugSaveload, "... _flags = %d", _flags);
// debugC(4, kDebugSaveload, "... out = %d", out);
debugC(4, kDebugSaveload, "... _cycleCount = %d", _cycleCount);
debugC(4, kDebugSaveload, "... _kludgeCount = %d", _kludgeCount);
debugC(4, kDebugSaveload, "... _enchantmentFlags = %d", _enchantmentFlags);
debugC(4, kDebugSaveload, "... _currentGoal = %d", _currentGoal);
debugC(4, kDebugSaveload, "... _deactivationCounter = %d", _deactivationCounter);
// debugC(4, kDebugSaveload, "... out = %d", out);
debugC(4, kDebugSaveload, "... _actionCounter = %d", _actionCounter);
debugC(4, kDebugSaveload, "... _effectiveResistance = %d", _effectiveResistance);
debugC(4, kDebugSaveload, "... _effectiveImmunity = %d", _effectiveImmunity);
debugC(4, kDebugSaveload, "... _recPointsPerUpdate = %d", _recPointsPerUpdate);
debugC(4, kDebugSaveload, "... _currentRecoveryPoints = %d", _currentRecoveryPoints);
debugC(4, kDebugSaveload, "... _leaderID = %d", _leaderID);
debugC(4, kDebugSaveload, "... _followersID = %d", _followersID);
// debugC(4, kDebugSaveload, "... armorObjects = %d", armorObjects);
debugC(4, kDebugSaveload, "... _currentTargetID = %d", _currentTargetID);
// debugC(4, kDebugSaveload, "... scriptVar = %d", scriptVar);
}
//-----------------------------------------------------------------------
// Destructor
Actor::~Actor() {
if (_appearance != nullptr) ReleaseActorAppearance(_appearance);
if (getAssignment())
delete getAssignment();
}
//-----------------------------------------------------------------------
// Return the number of bytes needed to archive this actor
int32 Actor::archiveSize() {
int32 size = GameObject::archiveSize();
size += sizeof(ActorArchive);
if (_flags & kAFHasAssignment)
size += assignmentArchiveSize(this);
return size;
}
void Actor::write(Common::MemoryWriteStreamDynamic *out) {
ProtoObj *holdProto = _prototype;
debugC(3, kDebugSaveload, "Saving actor %d", thisID());
// Modify the protoype temporarily so the GameObject::write()
// will store the index correctly
if (_prototype != nullptr)
_prototype = g_vm->_objectProtos[getProtoNum()];
GameObject::write(out, false);
// Restore the prototype pointer
_prototype = holdProto;
out->writeByte(_faction);
out->writeByte(_colorScheme);
out->writeSint32BE(_appearanceID);
out->writeSByte(_attitude);
out->writeSByte(_mood);
out->writeByte(_disposition);
out->writeByte(_currentFacing);
out->writeSint16LE(_tetherLocU);
out->writeSint16LE(_tetherLocV);
out->writeSint16LE(_tetherDist);
out->writeUint16LE(_leftHandObject);
out->writeUint16LE(_rightHandObject);
out->write(_knowledge, sizeof(_knowledge));
out->writeUint16LE(_schedule);
out->write(_conversationMemory, sizeof(_conversationMemory));
out->writeByte(_currentAnimation);
out->writeByte(_currentPose);
out->writeByte(_animationFlags);
out->writeByte(_flags);
_poseInfo.write(out);
out->writeSint16LE(_cycleCount);
out->writeSint16LE(_kludgeCount);
out->writeUint32LE(_enchantmentFlags);
out->writeByte(_currentGoal);
out->writeByte(_deactivationCounter);
_effectiveStats.write(out);
out->writeByte(_actionCounter);
out->writeUint16LE(_effectiveResistance);
out->writeUint16LE(_effectiveImmunity);
out->writeSint16LE(_recPointsPerUpdate);
out->writeUint16LE(_currentRecoveryPoints);
_leaderID = (_leader != nullptr) ? _leader->thisID() : Nothing;
out->writeUint16LE(_leaderID);
_followersID = (_followers != nullptr) ? getBandID(_followers) : NoBand;
out->writeSint16LE(_followersID);
out->write(_armorObjects, ARMOR_COUNT * 2);
_currentTargetID = _currentTarget != nullptr ? _currentTarget->thisID() : Nothing;
out->writeUint16LE(_currentTargetID);
out->write(_scriptVar, sizeof(_scriptVar));
if (_flags & kAFHasAssignment)
writeAssignment(this, out);
debugC(4, kDebugSaveload, "... _faction = %d", _faction);
debugC(4, kDebugSaveload, "... _colorScheme = %d", _colorScheme);
debugC(4, kDebugSaveload, "... _appearanceID = %d", _appearanceID);
debugC(4, kDebugSaveload, "... _attitude = %d", _attitude);
debugC(4, kDebugSaveload, "... _mood = %d", _mood);
debugC(4, kDebugSaveload, "... _disposition = %d", _disposition);
debugC(4, kDebugSaveload, "... _currentFacing = %d", _currentFacing);
debugC(4, kDebugSaveload, "... _tetherLocU = %d", _tetherLocU);
debugC(4, kDebugSaveload, "... _tetherLocV = %d", _tetherLocV);
debugC(4, kDebugSaveload, "... _tetherDist = %d", _tetherDist);
debugC(4, kDebugSaveload, "... _leftHandObject = %d", _leftHandObject);
debugC(4, kDebugSaveload, "... _rightHandObject = %d", _rightHandObject);
// debugC(4, kDebugSaveload, "... knowledge = %d", knowledge);
debugC(4, kDebugSaveload, "... _schedule = %d", _schedule);
// debugC(4, kDebugSaveload, "... conversationMemory = %d", conversationMemory);
debugC(4, kDebugSaveload, "... _currentAnimation = %d", _currentAnimation);
debugC(4, kDebugSaveload, "... _currentPose = %d", _currentPose);
debugC(4, kDebugSaveload, "... _animationFlags = %d", _animationFlags);
debugC(4, kDebugSaveload, "... _flags = %d", _flags);
// debugC(4, kDebugSaveload, "... out = %d", out);
debugC(4, kDebugSaveload, "... _cycleCount = %d", _cycleCount);
debugC(4, kDebugSaveload, "... _kludgeCount = %d", _kludgeCount);
debugC(4, kDebugSaveload, "... _enchantmentFlags = %d", _enchantmentFlags);
debugC(4, kDebugSaveload, "... _currentGoal = %d", _currentGoal);
debugC(4, kDebugSaveload, "... _deactivationCounter = %d", _deactivationCounter);
// debugC(4, kDebugSaveload, "... out = %d", out);
debugC(4, kDebugSaveload, "... _actionCounter = %d", _actionCounter);
debugC(4, kDebugSaveload, "... _effectiveResistance = %d", _effectiveResistance);
debugC(4, kDebugSaveload, "... _effectiveImmunity = %d", _effectiveImmunity);
debugC(4, kDebugSaveload, "... _recPointsPerUpdate = %d", _recPointsPerUpdate);
debugC(4, kDebugSaveload, "... _currentRecoveryPoints = %d", _currentRecoveryPoints);
debugC(4, kDebugSaveload, "... _leaderID = %d", _leader != nullptr ? _leader->thisID() : Nothing);
debugC(4, kDebugSaveload, "... _followersID = %d", _followers != nullptr ? getBandID(_followers) : NoBand);
// debugC(4, kDebugSaveload, "... armorObjects = %d", armorObjects);
debugC(4, kDebugSaveload, "... _currentTargetID = %d", _currentTarget != nullptr ? _currentTarget->thisID() : Nothing);
// debugC(4, kDebugSaveload, "... scriptVar = %d", scriptVar);
}
//-----------------------------------------------------------------------
// Return a newly created actor
Actor *Actor::newActor(
int16 protoNum,
uint16 nameIndex,
uint16 scriptIndex,
int32 appearanceNum,
uint8 colorSchemeIndex,
uint8 factionNum,
uint8 initFlags) {
GameObject *limbo = objectAddress(ActorLimbo);
Actor *a = nullptr;
debugC(2, kDebugActors, "Actor::newActor(protoNum = %d, nameIndex = %d, scriptIndex = %d, appearanceNum = %d, colorSchemeIndex = %d, factionNum = %d, initFlags = %d)",
protoNum, nameIndex, scriptIndex, appearanceNum, colorSchemeIndex, factionNum, initFlags);
if (limbo->IDChild() == Nothing) {
int16 i;
// Search actor list for first scavangable actor
for (i = kPlayerActors; i < kActorCount; i++) {
a = g_vm->_act->_actorList[i];
if ((a->_flags & kAFTemporary)
&& !a->isActivated()
&& isWorld(a->IDParent()))
break;
}
// REM: If things start getting really tight, we can
// start recycling common objects...
if (i >= kActorCount)
return nullptr;
} else {
actorLimboCount--;
a = (Actor *)limbo->child();
}
if (!a)
return nullptr;
a->setLocation(Location(0, 0, 0, Nothing));
a->init(
protoNum,
nameIndex,
scriptIndex,
appearanceNum,
colorSchemeIndex,
factionNum,
initFlags);
if (a->_flags & kAFTemporary) {
incTempActorCount(protoNum);
debugC(1, kDebugActors, "Actors: Created temp actor %d (%s) new count:%d", a->thisID() - 32768, a->objName(), getTempActorCount(protoNum));
}
return a;
}
//-----------------------------------------------------------------------
// Delete this actor
void Actor::deleteActor() {
if (_flags & kAFTemporary) {
uint16 protoNum = getProtoNum();
decTempActorCount(protoNum);
debugC(1, kDebugActors, "Actors: Deleting temp actor %d (%s) new count:%d", thisID() - 32768, objName(), getTempActorCount(protoNum));
}
// Kill task
if (_curTask != nullptr) {
_curTask->abortTask();
delete _curTask;
_curTask = nullptr;
}
// Kill motion task
if (_moveTask != nullptr)
_moveTask->remove();
// If banded, remove from band
if (_leader != nullptr) {
assert(isActor(_leader));
_leader->removeFollower(this);
_leader = nullptr;
} else if (_followers != nullptr) {
int16 i;
for (i = 0; i < _followers->size(); i++) {
Actor *follower = (*_followers)[i];
follower->_leader = nullptr;
follower->evaluateNeeds();
}
delete _followers;
_followers = nullptr;
}
// Place in limbo
if (!(_data.objectFlags & kObjectNoRecycle)) {
append(ActorLimbo);
actorLimboCount++;
}
}
//-----------------------------------------------------------------------
// Cause the actor to stop his current motion task is he is interruptable
void Actor::stopMoving() {
if (_moveTask != nullptr && isInterruptable())
_moveTask->remove();
}
//-----------------------------------------------------------------------
// Cause this actor to die
void Actor::die() {
if (!isDead()) return;
ObjectID dObj = thisID();
scriptCallFrame scf;
PlayerActorID playerID;
scf.invokedObject = dObj;
scf.enactor = dObj;
scf.directObject = dObj;
scf.indirectObject = Nothing;
scf.value = 0;
runObjectMethod(dObj, Method_Actor_onDie, scf);
// Kill task
if (_curTask != nullptr) {
_curTask->abortTask();
delete _curTask;
_curTask = nullptr;
}
// Kill motion task
if (_moveTask != nullptr)
_moveTask->remove();
// If banded, remove from band
if (_leader != nullptr) {
assert(isActor(_leader));
_leader->removeFollower(this);
_leader = nullptr;
}
if (actorToPlayerID(this, playerID))
handlePlayerActorDeath(playerID);
}
//-----------------------------------------------------------------------
// Cause this actor to come back to life
void Actor::imNotQuiteDead() {
if (isDead()) {
PlayerActorID pID;
_effectiveStats.vitality = 1;
if (actorToPlayerID(this, pID))
updateBrotherControls(pID);
evaluateNeeds();
}
}
//-----------------------------------------------------------------------
// Cuase the actor to re-assess his/her vitality
void Actor::vitalityUpdate() {
// If we're dead, don't heal
if (isDead()) return;
// get the base stats for this actor
ActorAttributes *baseStats = getBaseStats();
// first find out if this actor is wounded
if (_effectiveStats.vitality < baseStats->vitality) {
// whole vitality number goes here
int16 recover;
int16 fractionRecover;
// get the whole number first
recover = _recPointsPerUpdate / kRecPointsPerVitality;
// get the fraction
fractionRecover = _recPointsPerUpdate % kRecPointsPerVitality;
// if there is an overrun
if (_currentRecoveryPoints + fractionRecover > kRecPointsPerVitality) {
// add the overrun to the whole number
recover++;
_currentRecoveryPoints = (_currentRecoveryPoints + fractionRecover) - kRecPointsPerVitality;
} else {
_currentRecoveryPoints += fractionRecover;
}
if (_effectiveStats.vitality + recover >=
baseStats->vitality) {
_effectiveStats.vitality = baseStats->vitality;
} else {
_effectiveStats.vitality += recover;
//WriteStatusF( 5, " Healed: %d, rec: %d, part: %d ", effectiveStats.vitality,
// recover, currentRecoveryPoints );
}
}
}
//-----------------------------------------------------------------------
// Perform actor specific activation tasks
void Actor::activateActor() {
debugC(1, kDebugActors, "Actors: Activated %d (%s)", thisID() - 32768, objName());
evaluateNeeds();
}
//-----------------------------------------------------------------------
// Perfrom actor specific deactivation tasks
void Actor::deactivateActor() {
debugC(1, kDebugActors, "Actors: De-activated %d (%s)", thisID() - 32768, objName());
// Kill task
if (_curTask != nullptr) {
_curTask->abortTask();
delete _curTask;
_curTask = nullptr;
}
// Kill motion task
if (_moveTask != nullptr)
_moveTask->remove();
// If banded, remove from band
if (_leader != nullptr) {
assert(isActor(_leader));
_leader->removeFollower(this);
_leader = nullptr;
}
// Temporary actors get deleted upon deactivation
if ((_flags & kAFTemporary) || isDead()) {
_deactivationCounter = 10; // actor lasts for 50 seconds
}
}
//-----------------------------------------------------------------------
// Delobotomize this actor
void Actor::delobotomize() {
if (!(_flags & kAFLobotomized)) return;
ObjectID dObj = thisID();
scriptCallFrame scf;
_flags &= ~kAFLobotomized;
scf.invokedObject = dObj;
scf.enactor = dObj;
scf.directObject = dObj;
scf.indirectObject = Nothing;
scf.value = 0;
runObjectMethod(dObj, Method_Actor_onDelobotomize, scf);
evaluateNeeds();
}
//-----------------------------------------------------------------------
// Lobotomize this actor
void Actor::lobotomize() {
if (_flags & kAFLobotomized) return;
ObjectID dObj = thisID();
scriptCallFrame scf;
// Kill task
if (_curTask != nullptr) {
_curTask->abortTask();
delete _curTask;
_curTask = nullptr;
}
// Kill motion task
if (_moveTask != nullptr)
_moveTask->remove();
_flags |= kAFLobotomized;
scf.invokedObject = dObj;
scf.enactor = dObj;
scf.directObject = dObj;
scf.indirectObject = Nothing;
scf.value = 0;
runObjectMethod(dObj, Method_Actor_onLobotomize, scf);
}
//-----------------------------------------------------------------------
// Return a pointer to the base stats for this actor. If this actor
// is a non-player actor, the base stats are in the prototype. If this
// actor is a player actor, the base stats are in the PlayerActor
// structure.
ActorAttributes *Actor::getBaseStats() {
if (_disposition < kDispositionPlayer)
return &((ActorProto *)_prototype)->baseStats;
else
return &g_vm->_playerList[_disposition - kDispositionPlayer]->_baseStats;
}
//-----------------------------------------------------------------------
// Return the racial base enchantment flags. If this actor
// is a non-player actor, the base stats are in the prototype.
uint32 Actor::getBaseEnchantmentEffects() {
//if ( disposition < kDispositionPlayer )
return ((ActorProto *)_prototype)->baseEffectFlags;
}
//-----------------------------------------------------------------------
// Return the object base resistance flags. If this actor
// is a non-player actor, the base stats are in the prototype.
uint16 Actor::getBaseResistance() {
//if ( disposition < kDispositionPlayer )
return ((ActorProto *)_prototype)->resistance;
}
//-----------------------------------------------------------------------
// Return the object base immunity flags. If this actor
// is a non-player actor, the base stats are in the prototype.
uint16 Actor::getBaseImmunity() {
//if ( disposition < kDispositionPlayer )
return ((ActorProto *)_prototype)->immunity;
}
//-----------------------------------------------------------------------
// Return the base recovery rate
uint16 Actor::getBaseRecovery() {
return BASE_REC_RATE;
}
//-----------------------------------------------------------------------
// Determine if specified point is within actor's reach
bool Actor::inReach(const TilePoint &tp) {
return inRange(tp, kDefaultReach);
}
//-----------------------------------------------------------------------
// Determine if specified point is within an objects use range
bool Actor::inUseRange(const TilePoint &tp, GameObject *obj) {
uint16 range = obj->proto()->maximumRange;
return inRange(tp, MAX(range, (uint16)kDefaultReach));
}
//-----------------------------------------------------------------------
// Determine if actor is immobile (i.e. can't walk)
bool Actor::isImmobile() {
return isDead()
|| hasEffect(kActorImmobile)
|| hasEffect(kActorAsleep)
|| hasEffect(kActorParalyzed);
}
//-----------------------------------------------------------------------
// Return a pointer to this actor's currently readied offensive object
GameObject *Actor::offensiveObject() {
if (_rightHandObject != Nothing) {
assert(isObject(_rightHandObject));
GameObject *obj = GameObject::objectAddress(_rightHandObject);
// Any object in an actor's right hand should be a weapon
assert(obj->containmentSet() & ProtoObj::kIsWeapon);
return obj;
}
if (_leftHandObject != Nothing) {
assert(isObject(_leftHandObject));
GameObject *obj = GameObject::objectAddress(_leftHandObject);
if (obj->containmentSet() & ProtoObj::kIsWeapon)
return obj;
}
// If not carrying a weapon attack with self
return this;
}
//-----------------------------------------------------------------------
// Returns pointers to this actor's readied primary defensive object
// and optionally their scondary defensive object
void Actor::defensiveObject(GameObject **priPtr, GameObject **secPtr) {
assert(priPtr != nullptr);
GameObject *leftHandObjPtr,
*rightHandObjPtr,
*primary = nullptr,
*secondary = nullptr;
// Get a pointer to the left hand object
leftHandObjPtr = _leftHandObject != Nothing
? (assert(isObject(_leftHandObject))
, GameObject::objectAddress(_leftHandObject))
: nullptr;
// Get a pointer to the right hand object
rightHandObjPtr = _rightHandObject != Nothing
? (assert(isObject(_rightHandObject))
, GameObject::objectAddress(_rightHandObject))
: nullptr;
if (leftHandObjPtr != nullptr) {
GameObject **rightHandObjDest;
if (leftHandObjPtr->proto()->canBlock()) {
// Left hand object is primary. Right hand object may be
// secondary
primary = leftHandObjPtr;
rightHandObjDest = &secondary;
} else
// Right hand object may be primary
rightHandObjDest = &primary;
if (rightHandObjPtr != nullptr && rightHandObjPtr->proto()->canBlock())
// Right hand object is defensive
*rightHandObjDest = rightHandObjPtr;
} else {
if (rightHandObjPtr != nullptr && rightHandObjPtr->proto()->canBlock())
// Right hand object is primary defensive object
primary = rightHandObjPtr;
}
// Return the primary pointer
*priPtr = primary;
// Return the secondary pointer
if (secPtr != nullptr) *secPtr = secondary;
}
//-----------------------------------------------------------------------
// Returns a pointer to the object with which this actor is currently
// blocking, if any
GameObject *Actor::blockingObject(Actor *attacker) {
return _moveTask != nullptr
? _moveTask->blockingObject(attacker)
: nullptr;
}
//-----------------------------------------------------------------------
// Return the total used armor attributes
void Actor::totalArmorAttributes(ArmorAttributes &armorAttribs) {
int i;
ProtoObj *thisProto = proto();
// Plug in actor's natural values
armorAttribs.damageAbsorbtion = thisProto->damageAbsorbtion;
armorAttribs.damageDivider = MAX<uint8>(thisProto->damageDivider, 1);
armorAttribs.defenseBonus = thisProto->defenseBonus;
// Accumulate values for all armor objects
for (i = 0; i < ARMOR_COUNT; i++) {
if (_armorObjects[i] != Nothing) {
ProtoObj *armorProto = GameObject::protoAddress(_armorObjects[i]);
assert(armorProto != nullptr);
armorAttribs.damageAbsorbtion += armorProto->damageAbsorbtion;
if (armorProto->damageDivider != 0)
armorAttribs.damageDivider *= armorProto->damageDivider;
armorAttribs.defenseBonus += armorProto->defenseBonus;
}
}
}
//-----------------------------------------------------------------------
// Determine if specified point is within actor's attack range
bool Actor::inAttackRange(const TilePoint &tp) {
GameObject *weapon = offensiveObject();
uint16 range = weapon != nullptr ? weapon->proto()->maximumRange : 0;
return inRange(tp, MAX(range, (uint16)kDefaultReach));
}
//-----------------------------------------------------------------------
// Initiate an attack upon a specified target
void Actor::attack(GameObject *target) {
GameObject *weapon = offensiveObject();
if (weapon != nullptr)
weapon->proto()->initiateAttack(thisID(), target->thisID());
}
//-----------------------------------------------------------------------
// Stop all attacks on a specified target
void Actor::stopAttack(GameObject *target) {
if (_moveTask && _moveTask->isAttack() && _moveTask->_targetObj == target)
_moveTask->finishAttack();
}
//-----------------------------------------------------------------------
// Determine if this actor can block an attack
bool Actor::canDefend() {
if (isDead()) return false;
// Look at left hand object, generally the defensive object
if (_leftHandObject != Nothing) {
GameObject *obj = GameObject::objectAddress(_leftHandObject);
if (obj->proto()->canBlock()) return true;
}
// Look at right hand object, generally the offensive object
if (_rightHandObject != Nothing) {
GameObject *obj = GameObject::objectAddress(_rightHandObject);
if (obj->proto()->canBlock()) return true;
}
return false;
}
//-----------------------------------------------------------------------
// Return a numeric value which roughly estimates this actor's
// offensive strength
int16 Actor::offenseScore() {
// REM: at this time this calculation is somewhat arbitrary
int16 score = 0;
GameObject *weapon = offensiveObject();
if (weapon != nullptr) {
ProtoObj *proto = weapon->proto();
score += proto->weaponDamage + (proto->maximumRange / kTileUVSize);
}
// Add average mana
score += (_effectiveStats.redMana
+ _effectiveStats.orangeMana
+ _effectiveStats.yellowMana
+ _effectiveStats.greenMana
+ _effectiveStats.blueMana
+ _effectiveStats.violetMana)
/ 6;
score += _effectiveStats.spellcraft + _effectiveStats.brawn;
return score;
}
//-----------------------------------------------------------------------
// Return a numeric value which roughly estimates this actor's
// defensive strength
int16 Actor::defenseScore() {
// REM: at this time this calculation is somewhat arbitrary
int16 score = 0;
GameObject *shield;
ArmorAttributes armorAttribs;
defensiveObject(&shield);
if (shield != nullptr) {
ProtoObj *proto = shield->proto();
score += proto->defenseBonus;
}
totalArmorAttributes(armorAttribs);
score += (armorAttribs.defenseBonus + armorAttribs.damageAbsorbtion)
* armorAttribs.damageDivider;
score += _effectiveStats.agility + _effectiveStats.vitality;
return score;
}
//-----------------------------------------------------------------------
// Return the sprite color translation table based upon the actor's
// color scheme
void Actor::getColorTranslation(ColorTable map) {
// If actor has color table loaded, then calculate the
// translation table.
if (_appearance
&& _appearance->_schemeList) {
buildColorTable(map,
_appearance->_schemeList->_schemes[_colorScheme]->bank,
11);
} else memcpy(map, identityColors, 256);
}
//-----------------------------------------------------------------------
// Set the current animation sequence for the actor.
//
// Each time the nextAnimationFrame() is called, it will increment
// to the next frame in the sequence.
int16 Actor::setAction(int16 newState, int16 flags) {
ActorAnimation *anim;
int16 numPoses = 0;
// Refresh the handles
// RLockHandle( appearance->animations );
// RUnlockHandle( appearance->animations );
if (_appearance == nullptr) return 0;
// If this animation has no frames, then return false
anim = _appearance->animation(newState);
if (anim)
numPoses = anim->count[_currentFacing];
if (numPoses <= 0) return 0;
// Set up the animation
_currentAnimation = newState;
_animationFlags = flags;
// If they haven't set the "no reset" flag, then
if (!(flags & kAnimateNoRestart)) {
if (flags & kAnimateReverse) _currentPose = numPoses - 1;
else _currentPose = 0;
} else {
_currentPose = clamp(0, _currentPose, numPoses - 1);
}
return numPoses;
}
//-----------------------------------------------------------------------
// returns true if the action is available in the current direction.
//
bool Actor::isActionAvailable(int16 newState, bool anyDir) {
ActorAnimation *anim;
// Refresh the handles
// RLockHandle( appearance->animations );
// RUnlockHandle( appearance->animations );
if (_appearance == nullptr)
return false;
// If this animation has no frames, then return false
anim = _appearance->animation(newState);
if (anim == nullptr)
return false;
if (anyDir) {
for (int i = 0; i < kNumPoseFacings; i++) {
if (anim->count[i] > 0) return true;
}
} else {
if (anim->count[_currentFacing] > 0) return true;
}
return false;
}
//-----------------------------------------------------------------------
// Return the number of animation frames in the specified action for the
// specified direction
int16 Actor::animationFrames(int16 actionType, Direction dir) {
if (_appearance == nullptr)
return 0;
ActorAnimation *anim;
anim = _appearance->animation(actionType);
if (!anim)
return 0;
return anim->count[dir];
}
//-----------------------------------------------------------------------
// Update the current animation sequence to the next frame.
// Returns true if the animation sequence has finished.
bool Actor::nextAnimationFrame() {
ActorAnimation *anim;
int16 numPoses;
// Refresh the handles
// RLockHandle( appearance->animations );
// RUnlockHandle( appearance->animations );
if (_appearance == nullptr) {
if (_animationFlags & kAnimateOnHold) {
return false;
} else if (_animationFlags & kAnimateRepeat) {
_animationFlags |= kAnimateOnHold;
return false;
} else {
_animationFlags |= kAnimateFinished;
return true;
}
} else _animationFlags &= ~kAnimateOnHold;
// Get the number of frames in the animation
anim = _appearance->animation(_currentAnimation);
numPoses = anim->count[_currentFacing];
if (numPoses <= 0) {
_animationFlags |= kAnimateFinished;
return true; // no poses, return DONE
}
// If the sprite could not be displayed because it has not
// been loaded, then don't update the animation state --
// wait until the sprite gets loaded, and then continue
// with the action.
if (_animationFlags & kAnimateNotLoaded) return false;
// If the animation has reached the last frame, then exit.
if (_animationFlags & kAnimateFinished) return true;
if (_animationFlags & kAnimateRandom) {
// Select a random frame from the series.
_currentPose = g_vm->_rnd->getRandomNumber(numPoses - 1);
} else if (_animationFlags & kAnimateReverse) {
// Note that the logic for forward repeats is slightly
// different for reverse repeats. Specifically, the
// "alternate" flag is always checked when going forward,
// but it's only checked when going backwards if the repeat
// flag is also set. This means that an "alternate" with
// no "repeat" will ping-pong exactly once.
if (_currentPose > 0) {
_currentPose--;
// Check if this is the last frame
if (_currentPose <= 0 && !(_animationFlags & kAnimateRepeat)) {
_animationFlags |= kAnimateFinished;
}
} else if (_animationFlags & kAnimateRepeat) {
// If we're repeating, check for a back & forth,
// or for a wraparound. Also checks for case of
// a degenerate series (1 frame only)
if (_animationFlags & kAnimateAlternate) {
_animationFlags &= ~kAnimateReverse;
_currentPose = MIN(1, numPoses - 1);
} else {
_currentPose = numPoses - 1;
}
}
} else {
if (_currentPose < numPoses - 1) {
// Increment the pose number
_currentPose++;
// Check if this is the last frame
if (_currentPose >= numPoses - 1 &&
!(_animationFlags & (kAnimateAlternate | kAnimateRepeat)))
_animationFlags |= kAnimateFinished;
} else if (_animationFlags & kAnimateAlternate) {
// At the end of the sequence, reverse direction
_animationFlags |= kAnimateReverse;
_currentPose = MAX(_currentPose - 1, 0);
} else if (_animationFlags & kAnimateRepeat) {
// Wrap back to beginning
_currentPose = 0;
} else //If Last Frame And Not Animate Repeat or Alternate
_animationFlags |= kAnimateFinished;
}
return false;
}
//-----------------------------------------------------------------------
// Drop the all of the actor's inventory
void Actor::dropInventory() {
GameObject *obj,
*nextObj;
for (obj = _data.childID != Nothing
? GameObject::objectAddress(_data.childID)
: nullptr;
obj != nullptr;
obj = nextObj) {
nextObj = obj->IDNext() != Nothing
? GameObject::objectAddress(obj->IDNext())
: nullptr;
// Delete intangible objects and drop tangible objects
if (obj->containmentSet() & ProtoObj::kIsIntangible)
obj->deleteObjectRecursive();
else
dropInventoryObject(obj, obj->isMergeable() ? obj->getExtra() : 1);
}
}
//-----------------------------------------------------------------------
// Place an object into this actor's right or left hand
void Actor::holdInRightHand(ObjectID objID) {
assert(isObject(objID));
_rightHandObject = objID;
if (isPlayerActor(this))
g_vm->_cnm->setUpdate(thisID());
evalActorEnchantments(this);
}
void Actor::holdInLeftHand(ObjectID objID) {
assert(isObject(objID));
_leftHandObject = objID;
if (isPlayerActor(this))
g_vm->_cnm->setUpdate(thisID());
evalActorEnchantments(this);
}
//-----------------------------------------------------------------------
// Wear a piece of armor
void Actor::wear(ObjectID objID, uint8 where) {
assert(where < ARMOR_COUNT);
PlayerActorID playerID;
#if DEBUG
if (objID != Nothing) {
assert(isObject(objID));
GameObject *obj = GameObject::objectAddress(objID);
assert(obj->proto()->containmentSet() & ProtoObj::kIsArmor);
}
#endif
_armorObjects[where] = objID;
if (isPlayerActor(this))
g_vm->_cnm->setUpdate(thisID());
evalActorEnchantments(this);
if (actorToPlayerID(this, playerID)) {
updateBrotherArmor(playerID);
}
}
//-----------------------------------------------------------------------
// Called when the actor is on the display list and has no motion task.
void Actor::updateAppearance(int32) {
// static uint16 count;
// count++;
if (isDead() || !isActivated() || (_flags & kAFLobotomized)) return;
#if DEBUG*0
WriteStatusF(4, "Wait Count %d Attitude %d", cycleCount, attitude);
#endif
#if DEBUG*0
extern void ShowObjectSection(GameObject * obj);
if (this != getCenterActor())
if (lineOfSight(getCenterActor(), this, kTerrainSurface))
ShowObjectSection(this);
#endif
if (_appearance) {
if (animationFrames(kActionStand, _currentFacing) == 1) {
if (_flags & kAFFightStance) {
GameObject *weapon = offensiveObject();
if (weapon == this) weapon = nullptr;
if (weapon != nullptr) {
ProtoObj *weaponProto = weapon->proto();
setAction(weaponProto->fightStanceAction(thisID()), 0);
} else {
if (isActionAvailable(kActionSwingHigh))
setAction(kActionSwingHigh, 0);
else
setAction(kActionTwoHandSwingHigh, 0);
}
_cycleCount = 0;
} else {
if (_cycleCount > 0) { //If In Wait State Between Wait Animation
_cycleCount--;
setAction(kActionStand, 0); //Just stand still
} else { // Wait Animation
if (_cycleCount == 0) { //If Just Starting Wait Animation
_cycleCount--;
switch (_attitude) { //Emotion And Character Type
//Currently Attitude Not Set So Always Hits Zero
case 0:
//Returns True If Successful No Checking Yet
setAvailableAction(kActionWaitAgressive,
kActionWaitImpatient,
kActionWaitFriendly,
kActionStand); // This is default
break;
case 1:
setAvailableAction(kActionWaitImpatient,
kActionWaitFriendly,
kActionWaitAgressive,
kActionStand);
break;
case 2:
setAvailableAction(kActionWaitFriendly,
kActionWaitImpatient,
kActionWaitAgressive,
kActionStand);
}
} else //Assume -1
if (nextAnimationFrame())//If Last Frame In Wait Animation
_cycleCount = g_vm->_rnd->getRandomNumber(19);
}
}
} else {
if (_currentAnimation != kActionStand
|| (_animationFlags & kAnimateRepeat) == 0)
setAction(kActionStand, kAnimateRepeat);
else
nextAnimationFrame();
}
}// End if (appearance)
}
bool Actor::setAvailableAction(int16 action1, int16 action2, int16 action3, int16 actiondefault) {
if (setAction(action1, 0))
return true;
if (setAction(action2, 0))
return true;
if (setAction(action3, 0))
return true;
if (setAction(actiondefault, 0))
return true;
return false;
}
//-----------------------------------------------------------------------
// Set a new goal for this actor
void Actor::setGoal(uint8 newGoal) {
if (_currentGoal != newGoal) {
if (_curTask != nullptr) {
_curTask->abortTask();
delete _curTask;
_curTask = nullptr;
}
_currentGoal = newGoal;
}
}
//-----------------------------------------------------------------------
// Reevaluate actor's built-in needs
void Actor::evaluateNeeds() {
if (!isDead()
&& isActivated()
&& !(_flags & kAFLobotomized)) {
if (_disposition >= kDispositionPlayer) {
if (g_vm->_act->_combatBehaviorEnabled) {
SenseInfo info;
if (canSenseActorProperty(
info,
kMaxSenseRange,
kActorPropIDEnemy)
|| canSenseActorPropertyIndirectly(
info,
kMaxSenseRange,
kActorPropIDEnemy)) {
PlayerActorID playerID = _disposition - kDispositionPlayer;
if (isAggressive(playerID))
setGoal(kActorGoalAttackEnemy);
else {
if (_leader != nullptr && inBandingRange())
setGoal(kActorGoalAvoidEnemies);
else
setGoal(kActorGoalPreserveSelf);
}
} else if (_leader != nullptr && inBandingRange()) {
setGoal(kActorGoalFollowLeader);
} else {
setGoal(kActorGoalFollowAssignment);
}
} else if (_leader != nullptr && inBandingRange()) {
setGoal(kActorGoalFollowLeader);
} else {
setGoal(kActorGoalFollowAssignment);
}
} else {
if (_disposition == kDispositionEnemy
&& _appearance != nullptr
&& !hasEffect(kActorNotDefenseless)) {
GameObject *obj;
bool foundWeapon = false;
ContainerIterator iter(this);
while (iter.next(&obj) != Nothing) {
ProtoObj *proto = obj->proto();
if ((proto->containmentSet() & ProtoObj::kIsWeapon)
&& isActionAvailable(proto->fightStanceAction(thisID()))) {
foundWeapon = true;
break;
}
}
if (!foundWeapon
&& (isActionAvailable(kActionSwingHigh)
|| isActionAvailable(kActionTwoHandSwingHigh)))
foundWeapon = true;
if (!foundWeapon)
_flags |= kAFAfraid;
}
if (_flags & kAFAfraid || hasEffect(kActorFear) || hasEffect(kActorRepelUndead)) {
setGoal(kActorGoalPreserveSelf);
} else if (_leader != nullptr && inBandingRange()) {
setGoal(_leader->evaluateFollowerNeeds(this));
} else {
SenseInfo info;
if (_disposition == kDispositionEnemy
&& (getAssignment() == nullptr
|| canSenseProtaganist(
info,
kMaxSenseRange)
|| canSenseProtaganistIndirectly(
info,
kMaxSenseRange))) {
setGoal(kActorGoalAttackEnemy);
} else {
setGoal(kActorGoalFollowAssignment);
}
}
}
}
}
void Actor::updateState() {
// The actor should not be set permanently uninterruptable when
// the actor does not have a motion task
assert(isMoving() || _actionCounter != maxuint8);
GameObject::updateState();
if (_flags & kAFLobotomized)
return;
// Update the action counter
if (_actionCounter != 0 && _actionCounter != maxuint8)
_actionCounter--;
if (_appearance != nullptr
&& isDead()
&& isInterruptable()
&& (_moveTask == nullptr
|| _moveTask->_motionType != MotionTask::kMotionTypeDie)) {
int16 deadState = isActionAvailable(kActionDead)
? kActionDead
: isActionAvailable(kActionDie)
? kActionDie
: kActionStand;
if (_currentAnimation != deadState)
MotionTask::die(*this);
return;
}
if (!isDead()) {
if (this == getCenterActor()) return;
if (_flags & kAFSpecialAttack) {
_flags &= ~kAFSpecialAttack;
if (_currentTarget != nullptr) {
scriptCallFrame scf;
ObjectID dObj = thisID();
scf.invokedObject = dObj;
scf.enactor = dObj;
scf.directObject = dObj;
scf.indirectObject = _currentTarget->thisID();
scf.value = 0;
runObjectMethod(dObj, Method_Actor_onSpecialAttack, scf);
// If this actor is now deactivated or lobotomized
// return immediately
if (isDead() || !isActivated() || (_flags & kAFLobotomized))
return;
}
}
switch (_currentGoal) {
case kActorGoalFollowAssignment: {
ActorAssignment *assign = getAssignment();
// Iterate until there is no assignment, or the current
// assignment is valid
while (assign != nullptr && !assign->isValid()) {
g_vm->_act->_updatesViaScript++;
scriptCallFrame scf;
ObjectID dObj = thisID();
delete assign;
// Notify the scripts that the assignment has ended
scf.invokedObject = dObj;
scf.enactor = dObj;
scf.directObject = dObj;
scf.indirectObject = Nothing;
scf.value = 0;
runObjectMethod(dObj, Method_Actor_onEndAssignment, scf);
// If this actor is now deactivated or kAFLobotomized
// return immediately
if (isDead() || !isActivated() || (_flags & kAFLobotomized))
return;
// Re-get the assignment
assign = getAssignment();
}
// If there is no assignment at this point, call the
// schedule to setup a new assignment.
if (assign == nullptr && _schedule != 0) {
g_vm->_act->_updatesViaScript++;
assert(_curTask == nullptr);
scriptCallFrame scf;
scf.invokedObject = Nothing;
scf.enactor = Nothing;
scf.directObject = thisID();
scf.indirectObject = Nothing;
scf.value = 0;
runScript(_schedule, scf);
// Re-get the assignment
assign = getAssignment();
}
// Have the assignment create a new task
if (assign != nullptr && _curTask == nullptr)
_curTask = assign->createTask();
}
break;
case kActorGoalPreserveSelf:
if (_leader != nullptr || _followers != nullptr)
disband();
if (_curTask == nullptr) {
if ((_curTask = newTaskStack(this)) != nullptr) {
Task *task = new GoAwayFromActorTask(
_curTask,
ActorPropertyTarget(
_disposition == kDispositionEnemy
? kActorPropIDPlayerActor
: kActorPropIDEnemy),
true);
if (task != nullptr)
_curTask->setTask(task);
else {
delete _curTask;
_curTask = nullptr;
}
}
}
break;
case kActorGoalAttackEnemy:
if (_curTask == nullptr) {
if ((_curTask = newTaskStack(this)) != nullptr) {
uint8 disp = _leader != nullptr
? _leader->_disposition
: _disposition;
Task *task = new HuntToKillTask(
_curTask,
ActorPropertyTarget(
disp == kDispositionEnemy
? kActorPropIDPlayerActor
: kActorPropIDEnemy));
if (task != nullptr)
_curTask->setTask(task);
else {
delete _curTask;
_curTask = nullptr;
}
}
}
break;
case kActorGoalFollowLeader:
assert(isActor(_leader));
assert(_followers == nullptr);
if (_curTask == nullptr)
_curTask = _leader->createFollowerTask(this);
break;
case kActorGoalAvoidEnemies:
assert(isActor(_leader));
assert(_followers == nullptr);
if (_curTask == nullptr) {
if ((_curTask = newTaskStack(this)) != nullptr) {
Task *task = new BandAndAvoidEnemiesTask(_curTask);
if (task != nullptr)
_curTask->setTask(task);
else {
delete _curTask;
_curTask = nullptr;
}
}
}
}
}
}
//-----------------------------------------------------------------------
// This routine is used to notify the actor that a task has ended. The
// actor should handle the situation appropriately
void Actor::handleTaskCompletion(TaskResult result) {
// The task is done, get rid of it
delete _curTask;
_curTask = nullptr;
switch (_currentGoal) {
case kActorGoalFollowAssignment: {
ActorAssignment *assign = getAssignment();
// If we've gotten to this point, there had better be an
// assignment, or something is amiss
assert(assign != nullptr);
// Notify the assignment
assign->handleTaskCompletion(result);
}
break;
}
}
//-----------------------------------------------------------------------
// This function will cause the actor to react to an offensive act
void Actor::handleOffensiveAct(Actor *attacker) {
ObjectID dObj = thisID();
scriptCallFrame scf;
scf.invokedObject = dObj;
scf.enactor = dObj;
scf.directObject = dObj;
scf.indirectObject = attacker->thisID();
scf.value = 0;
runObjectMethod(dObj, Method_Actor_onAttacked, scf);
if (_disposition == kDispositionFriendly) {
if (attacker->_disposition >= kDispositionPlayer) {
_disposition = kDispositionEnemy;
evaluateNeeds();
}
}
}
//-----------------------------------------------------------------------
// This function will cause the actor to react appropriately to taking
// damage.
void Actor::handleDamageTaken(uint8 damage) {
uint8 combatBehavior = ((ActorProto *)_prototype)->combatBehavior;
if (combatBehavior == kBehaviorHungry) return;
if (offensiveObject() == this
&& !isActionAvailable(kActionSwingHigh)
&& !isActionAvailable(kActionTwoHandSwingHigh)
&& !hasEffect(kActorNotDefenseless)) {
_flags |= kAFAfraid;
return;
}
if (combatBehavior != kBehaviorHungry
&& (_flags & kAFTemporary)
&& !hasEffect(kActorFear)
&& !hasEffect(kActorRepelUndead)) {
if (_flags & kAFAfraid) {
// Let's give monsters a small chance of regaining their courage
if ((uint16)g_vm->_rnd->getRandomNumber(0xffff) <= 0x3fff)
_flags &= ~kAFAfraid;
} else {
int16 i,
fellowBandMembers,
vitality = _effectiveStats.vitality;
uint32 moraleBase = ((int32)damage << 16) / vitality,
bonus = 0;
// Adjustment added by Talin to globally reduce the amount of cowardice
// in the game. I may reduce it further depending on playtesting.
moraleBase /= 3;
// Adjust morale base according to the combat behavior
if (combatBehavior == kBehaviorCowardly)
moraleBase += moraleBase / 2;
else if (combatBehavior == kBehaviorBerserk)
moraleBase -= moraleBase / 2;
// Determine how many fellow band members this actor has.
if (_leader != nullptr)
fellowBandMembers = _leader->_followers->size();
else if (_followers != nullptr)
fellowBandMembers = _followers->size();
else
fellowBandMembers = 0;
// REM: this calculation can be done via a lookup table
for (i = 0; i < fellowBandMembers; i++)
bonus += ((1 << 16) - bonus) >> 4;
// Adjust the morale base to acount for the number of fellow band
// members
moraleBase -= bonus * moraleBase >> 16;
// Test this actor's morale
if ((uint16)g_vm->_rnd->getRandomNumber(0xffff) <= moraleBase)
_flags |= kAFAfraid;
}
}
}
//-----------------------------------------------------------------------
// This function is called when this actor successfully causes damage
// to another actor.
void Actor::handleSuccessfulStrike(Actor *target, int8 damage) {
PlayerActorID playerID;
if (actorToPlayerID(this, playerID)) {
PlayerActor *player = getPlayerActorAddress(playerID);
int16 ratio;
// If it's a weak monster, then reduce amount of vitality advanced.
// If we are twice as vital, then get half the exp's. If we are three times
// as vital, get 1/3 the exp. etc.
ratio = clamp(1, getBaseStats()->vitality / target->getBaseStats()->vitality, 4);
player->vitalityAdvance(damage / ratio);
}
}
//-----------------------------------------------------------------------
// This function is called when this actor successfully kills another
// actor.
void Actor::handleSuccessfulKill(Actor *target) {
PlayerActorID playerID;
if (this != target && actorToPlayerID(this, playerID)) {
const char vowels[] = "AEIOU";
PlayerActor *player = getPlayerActorAddress(playerID);
int16 ratio;
int16 points = target->getBaseStats()->vitality;
const char *monsterName = target->objName();
const char *aStr;
// If it's a weak monster, then reduce amount of vitality advanced.
// If we are twice as vital, then get half the exp's. If we are three times
// as vital, get 1/3 the exp. etc.
ratio = clamp(1, getBaseStats()->vitality / points, 4);
player->vitalityAdvance(points / ratio);
aStr = target->getNameIndex() == 0
? strchr(vowels, toupper(monsterName[0])) == nullptr
? "a "
: "an "
: "";
StatusMsg("%s has killed %s%s.", objName(), aStr, monsterName);
}
}
//-----------------------------------------------------------------------
// Determine if this actor can block a blow from the specified relative
// direction with the specified defensive object.
bool Actor::canBlockWith(GameObject *defenseObj, Direction relativeDir) {
assert(defenseObj->proto()->canBlock());
assert(relativeDir < 8);
// Assuming that the actor may increment or decrement their facing
// to block, these masks represent the possible relative facings
// based upon the current relative facing
const uint8 dirMaskArray[8] = {
0x83, // 10000011
0x07, // 00000111
0x0E, // 00001110
0x1C, // 00011100
0x38, // 00111000
0x70, // 01110000
0xE0, // 11100000
0xC1 // 11000001
};
return (defenseObj->proto()->defenseDirMask()
& dirMaskArray[relativeDir])
!= 0;
}
//-----------------------------------------------------------------------
// This function is called to notify this actor of an impending attack
void Actor::evaluateMeleeAttack(Actor *attacker) {
if (isInterruptable() && !isDead()) {
Direction relativeDir;
GameObject *defenseObj,
*primary,
*secondary;
bool canBlockWithPrimary;
// Compute the attacker's direction relative to this actor's
// facing
relativeDir = ((attacker->_data.location - _data.location).quickDir()
- _currentFacing) & 0x7;
// Get pointers to this actors primary and secondary defensive
// objects
defensiveObject(&primary, &secondary);
canBlockWithPrimary = primary != nullptr
&& canBlockWith(primary, relativeDir);
if (canBlockWithPrimary) {
bool canBlockWithSecondary;
canBlockWithSecondary = secondary != nullptr
&& canBlockWith(
secondary,
relativeDir);
if (canBlockWithSecondary) {
// If we can block with either primary or secondary
// there is a 25% chance of using the secondary
defenseObj = (g_vm->_rnd->getRandomNumber(3) != 0) ? primary : secondary;
} else {
// The primary defensive object will be used
defenseObj = primary;
}
} else
defenseObj = nullptr;
if (defenseObj != nullptr) {
// Start a defensive motion
defenseObj->proto()->initiateDefense(
defenseObj->thisID(),
thisID(),
attacker->thisID());
} else {
if (isActionAvailable(kActionJumpUp))
MotionTask::dodge(*this, *attacker);
}
}
}
//-----------------------------------------------------------------------
// Cause this actor to accept another actor as his leader. If the actor
// has followers, this will band those followers to the new leader as
// well.
void Actor::bandWith(Actor *newLeader) {
assert(_leader == nullptr);
// If the actor we're banding with is not the leader, then band
// with his leader
if (newLeader->_leader != nullptr) {
newLeader = newLeader->_leader;
assert(newLeader->_leader == nullptr);
}
// If this actor himself does not have followers then its really
// simple, otherwise we need to band all of this actor's followers
// with the new leader.
if (_followers == nullptr) {
if (newLeader->addFollower(this)) _leader = newLeader;
} else {
int16 i,
oldFollowerCount = _followers->size();
Actor **oldFollowers = new Actor * [oldFollowerCount];
if (oldFollowers != nullptr) {
// Copy the list followers
for (i = 0; i < oldFollowerCount; i++) {
oldFollowers[i] = (*_followers)[i];
assert(oldFollowers[i]->_leader == this);
}
// Disband all of the old followers
for (i = 0; i < oldFollowerCount; i++)
oldFollowers[i]->disband();
assert(_followers == nullptr);
// Add this actor and all of the old followers to the new
// leader's followers.
if (newLeader->addFollower(this)) {
_leader = newLeader;
for (i = 0; i < oldFollowerCount; i++)
oldFollowers[i]->bandWith(newLeader);
}
delete [] oldFollowers;
}
}
evaluateNeeds();
}
//-----------------------------------------------------------------------
// Simply causes this actor to be removed from his current band.
void Actor::disband() {
if (_leader != nullptr) {
_leader->removeFollower(this);
_leader = nullptr;
evaluateNeeds();
} else if (_followers != nullptr) {
int16 i;
for (i = 0; i < _followers->size(); i++) {
Actor *follower = (*_followers)[i];
follower->_leader = nullptr;
follower->evaluateNeeds();
}
delete _followers;
_followers = nullptr;
}
}
//-----------------------------------------------------------------------
// Add the specified actor to the list of this actor's followers.
bool Actor::addFollower(Actor *newBandMember) {
// The new band member should not be a leader of another band or
// a follower of another leader
assert(newBandMember->_leader == nullptr);
assert(newBandMember->_followers == nullptr);
// Allocate a new band, if needed
if (_followers == nullptr && (_followers = new Band(this)) == nullptr)
return false;
return _followers->add(newBandMember);
}
//-----------------------------------------------------------------------
// Remove the specified actor from this actor's list of followers.
void Actor::removeFollower(Actor *bandMember) {
assert(bandMember->_leader == this);
assert(_followers != nullptr);
int16 i;
_followers->remove(bandMember);
if (_followers->size() == 0) {
delete _followers;
_followers = nullptr;
} else {
uint16 moraleBonus = 0;
for (i = 0; i < _followers->size(); i++)
moraleBonus += ((1 << 16) - moraleBonus) >> 4;
for (i = 0; i < _followers->size(); i++) {
Actor *follower = (*_followers)[i];
ActorProto *proto = (ActorProto *)follower->_prototype;
uint8 combatBehavior = proto->combatBehavior;
if (follower->_currentGoal == kActorGoalAttackEnemy
&& combatBehavior != kBehaviorHungry) {
uint32 moraleBase;
moraleBase = combatBehavior == kBehaviorCowardly
? (1 << 16) / 4
: combatBehavior == kBehaviorSmart
? (1 << 16) / 8
: (1 << 16) / 16;
moraleBase -= moraleBase * moraleBonus >> 16;
if ((uint16)g_vm->_rnd->getRandomNumber(0xffff) <= moraleBase)
follower->_flags |= kAFAfraid;
}
}
}
}
//-----------------------------------------------------------------------
// Create a task for a follower of this actor. This is called when a
// follower has no task.
TaskStack *Actor::createFollowerTask(Actor *bandMember) {
assert(bandMember->_leader == this);
TaskStack *ts = nullptr;
if ((ts = newTaskStack(bandMember)) != nullptr) {
Task *task = new BandTask(ts);
if (task != nullptr)
ts->setTask(task);
else {
delete ts;
ts = nullptr;
}
}
return ts;
}
//-----------------------------------------------------------------------
// Evaluate a follower's needs and give him an approriate goal.
uint8 Actor::evaluateFollowerNeeds(Actor *follower) {
assert(follower->_leader == this);
SenseInfo info;
if ((_disposition == kDispositionEnemy
&& follower->canSenseProtaganist(info, kMaxSenseRange))
|| (_disposition >= kDispositionPlayer
&& follower->canSenseActorProperty(
info,
kMaxSenseRange,
kActorPropIDEnemy)))
return kActorGoalAttackEnemy;
return kActorGoalFollowLeader;
}
// Returns 0 if not moving, 1 if path being calculated,
// 2 if path being followed.
int Actor::pathFindState() {
if (_moveTask == nullptr)
return 0;
if (_moveTask->_pathFindTask)
return 1;
return 2;
}
//-----------------------------------------------------------------------
// Add knowledge package to actor
bool Actor::addKnowledge(uint16 kID) {
for (int i = 0; i < ARRAYSIZE(_knowledge); i++) {
if (_knowledge[i] == 0) {
_knowledge[i] = kID;
return true;
}
}
return false;
}
//-----------------------------------------------------------------------
// Remove knowledge package from actor
bool Actor::removeKnowledge(uint16 kID) {
for (int i = 0; i < ARRAYSIZE(_knowledge); i++) {
if (_knowledge[i] == kID) {
_knowledge[i] = 0;
return true;
}
}
return false;
}
//-----------------------------------------------------------------------
// Remove all knowledge package from actor
void Actor::clearKnowledge() {
for (int i = 0; i < ARRAYSIZE(_knowledge); i++) {
_knowledge[i] = 0;
}
}
//-----------------------------------------------------------------------
// Called to evaluate actor knowledge
void Actor::useKnowledge(scriptCallFrame &scf) {
uint16 bestResponsePri = 0,
bestResponseClass = 0,
bestResponseCode = 0;
// First, search for the class with the best response
for (int i = 0; i < ARRAYSIZE(_knowledge); i++) {
if (_knowledge[i]) {
scriptResult res;
// Run the script to eval the response of this
// knowledge package
res = runMethod(_knowledge[i],
kBuiltinAbstract,
0,
Method_KnowledgePackage_evalResponse,
scf);
// If script ran OK, then look at result
if (res == kScriptResultFinished) {
// break up return code into priority and
// response code
int16 pri = scf.returnVal >> 8,
response = scf.returnVal & 0xff;
if (pri > 0) {
// Add a bit of jitter to response
pri += g_vm->_rnd->getRandomNumber(3);
if (pri > bestResponsePri) {
bestResponsePri = pri;
bestResponseClass = _knowledge[i];
bestResponseCode = response;
}
}
}
}
}
// Then, callback whichever one responded best
if (bestResponsePri > 0) {
// Run the script to eval the response of this
// knowledge package
scf.responseType = bestResponseCode;
runMethod(bestResponseClass,
kBuiltinAbstract,
0,
Method_KnowledgePackage_executeResponse,
scf);
} else {
scf.returnVal = kActionResultNotDone;
}
}
//-----------------------------------------------------------------------
// Polling function to determine if any of this actor's followers can
// sense a protagonist within a specified range
bool Actor::canSenseProtaganistIndirectly(SenseInfo &info, int16 range) {
if (_followers != nullptr) {
int i;
for (i = 0; i < _followers->size(); i++) {
if ((*_followers)[i]->canSenseProtaganist(info, range))
return true;
}
}
return false;
}
//-----------------------------------------------------------------------
// Polling function to determine if any of this actor's followers can
// sense a specific actor within a specified range
bool Actor::canSenseSpecificActorIndirectly(
SenseInfo &info,
int16 range,
Actor *a) {
if (_followers != nullptr) {
int i;
for (i = 0; i < _followers->size(); i++) {
if ((*_followers)[i]->canSenseSpecificActor(info, range, a))
return true;
}
}
return false;
}
//-----------------------------------------------------------------------
// Polling function to determine if any of this actor's followers can
// sense a specific object within a specified range
bool Actor::canSenseSpecificObjectIndirectly(
SenseInfo &info,
int16 range,
ObjectID obj) {
if (_followers != nullptr) {
int i;
for (i = 0; i < _followers->size(); i++) {
if ((*_followers)[i]->canSenseSpecificObject(info, range, obj))
return true;
}
}
return false;
}
//-----------------------------------------------------------------------
// Polling function to determine if any of this actor's followers can
// sense an actor with a specified property within a specified range
bool Actor::canSenseActorPropertyIndirectly(
SenseInfo &info,
int16 range,
ActorPropertyID prop) {
if (_followers != nullptr) {
int i;
for (i = 0; i < _followers->size(); i++) {
if ((*_followers)[i]->canSenseActorProperty(info, range, prop))
return true;
}
}
return false;
}
//-----------------------------------------------------------------------
// Polling function to determine if any of this actor's followers can
// sense an object with a specified property within a specified range
bool Actor::canSenseObjectPropertyIndirectly(
SenseInfo &info,
int16 range,
ObjectPropertyID prop) {
if (_followers != nullptr) {
int i;
for (i = 0; i < _followers->size(); i++) {
if ((*_followers)[i]->canSenseObjectProperty(info, range, prop))
return true;
}
}
return false;
}
//-----------------------------------------------------------------------
// Mana check - spell casting uses this to check whether an actor
// has enough mana to cast a spell & to remove that mana if
// it's there
#define NO_MONSTER_MANA 1
bool Actor::takeMana(ActorManaID i, int8 dMana) {
#if NO_MONSTER_MANA
if (!isPlayerActor(this))
return true;
#endif
assert(i >= kManaIDRed && i <= kManaIDViolet);
if ((&_effectiveStats.redMana)[i] < dMana)
return false;
(&_effectiveStats.redMana)[i] -= dMana;
updateIndicators();
return true;
}
bool Actor::hasMana(ActorManaID i, int8 dMana) {
#if NO_MONSTER_MANA
if (!isPlayerActor(this))
return true;
#endif
assert(i >= kManaIDRed && i <= kManaIDViolet);
if ((&_effectiveStats.redMana)[i] < dMana)
return false;
return true;
}
//-----------------------------------------------------------------------
// Saving throw funcion
bool Actor::makeSavingThrow() {
return false;
}
//-------------------------------------------------------------------
// Determine if the actors are currently initialized
bool areActorsInitialized() {
return g_vm->_act->_actorList.size() > 0;
}
int16 GetRandomBetween(int start, int end) {
return g_vm->_rnd->getRandomNumberRng(start, end - 1);
}
void updateActorStates() {
// TODO: updateActorStates() for Dino
if (g_vm->getGameId() == GID_DINO)
return;
if (g_vm->_act->_actorStatesPaused) return;
int32 actorIndex = g_vm->_act->_baseActorIndex = (g_vm->_act->_baseActorIndex + 1) & ActorManager::kEvalRateMask;
while (actorIndex < kActorCount) {
Actor *a = g_vm->_act->_actorList[actorIndex];
if (isWorld(a->IDParent()))
a->evaluateNeeds();
actorIndex += ActorManager::kEvalRate;
}
g_vm->_act->_updatesViaScript = 0;
for (actorIndex = 0; actorIndex < kActorCount; actorIndex++) {
Actor *a = g_vm->_act->_actorList[actorIndex];
if (isWorld(a->IDParent()) && a->isActivated())
a->updateState();
}
}
//-------------------------------------------------------------------
void pauseActorStates() {
g_vm->_act->_actorStatesPaused = true;
}
//-------------------------------------------------------------------
void resumeActorStates() {
g_vm->_act->_actorStatesPaused = false;
}
//-------------------------------------------------------------------
void setCombatBehavior(bool enabled) {
PlayerActor *player = nullptr;
LivingPlayerActorIterator iter;
g_vm->_act->_combatBehaviorEnabled = enabled;
for (player = iter.first(); player != nullptr; player = iter.next())
player->getActor()->evaluateNeeds();
}
//-------------------------------------------------------------------
// Initialize the actor list
ResourceActor::ResourceActor(Common::SeekableReadStream *stream) : ResourceGameObject(stream) {
faction = stream->readByte();
colorScheme = stream->readByte();
appearanceID = stream->readSint32BE();
attitude = stream->readSByte();
mood = stream->readSByte();
disposition = stream->readByte();
currentFacing = stream->readByte();
tetherLocU = stream->readSint16LE();
tetherLocV = stream->readSint16LE();
tetherDist = stream->readSint16LE();
leftHandObject = stream->readUint16LE();
rightHandObject = stream->readUint16LE();
for (int i = 0; i < 16; ++i) {
knowledge[i] = stream->readUint16LE();
}
schedule = stream->readUint16LE();
for (int i = 0; i < 18; ++i) { // padding bytes = not necessary?
reserved[i] = stream->readByte();
}
}
void initActors() {
// Load actors
int i, resourceActorCount;
Common::Array<ResourceActor> resourceActorList;
Common::SeekableReadStream *stream;
const int resourceActorSize = 91; // size of the packed struct
resourceActorCount = listRes->size(kActorListID)
/ resourceActorSize;
if (resourceActorCount < 1)
error("Unable to load Actors");
if ((stream = loadResourceToStream(listRes, kActorListID, "res actor list")) == nullptr)
error("Unable to load Actors");
// Read the resource actors
for (int k = 0; k < resourceActorCount; ++k) {
ResourceActor res(stream);
resourceActorList.push_back(res);
}
delete stream;
if (g_vm->getGameId() == GID_DINO) {
warning("TODO: initActors() for Dino");
return;
}
for (i = 0; i < resourceActorCount; i++) {
// Initialize the actors with the resource data
Actor *a = new Actor(resourceActorList[i]);
a->_index = i + ActorBaseID;
g_vm->_act->_actorList.push_back(a);
}
// Place all of the extra actors in actor limbo
for (; i < kActorCount; i++) {
Actor *a = new Actor;
a->_index = i + ActorBaseID;
g_vm->_act->_actorList.push_back(a);
}
g_vm->_act->_actorList[0]->_disposition = kDispositionPlayer + 0;
g_vm->_act->_actorList[1]->_disposition = kDispositionPlayer + 1;
g_vm->_act->_actorList[2]->_disposition = kDispositionPlayer + 2;
}
void saveActors(Common::OutSaveFile *outS) {
debugC(2, kDebugSaveload, "Saving actors");
outS->write("ACTR", 4);
CHUNK_BEGIN;
out->writeSint16LE(kActorCount);
debugC(3, kDebugSaveload, "... kActorCount = %d", kActorCount);
for (int i = 0; i < kActorCount; ++i)
g_vm->_act->_actorList[i]->write(out);
CHUNK_END;
}
void loadActors(Common::InSaveFile *in) {
debugC(2, kDebugSaveload, "Loading actors");
// Read in the actor count
in->readSint16LE();
debugC(3, kDebugSaveload, "... kActorCount = %d", kActorCount);
for (int i = 0; i < kActorCount; i++) {
debugC(3, kDebugSaveload, "Loading actor %d", i + ActorBaseID);
// Initilize actors with archive data
Actor *a = new Actor(in);
a->_index = i + ActorBaseID;
g_vm->_act->_actorList.push_back(a);
}
for (int i = 0; i < kActorCount; ++i) {
Actor *a = g_vm->_act->_actorList[i];
a->_leader = a->_leaderID != Nothing
? (Actor *)GameObject::objectAddress(a->_leaderID)
: nullptr;
a->_followers = a->_followersID != NoBand
? getBandAddress(a->_followersID)
: nullptr;
a->_currentTarget = a->_currentTargetID != Nothing
? GameObject::objectAddress(a->_currentTargetID)
: nullptr;
}
}
//-------------------------------------------------------------------
// Cleanup the actor list
void cleanupActors() {
if (g_vm->_act->_actorList.size() > 0) {
for (int i = 0; i < kActorCount; i++)
delete g_vm->_act->_actorList[i];
g_vm->_act->_actorList.clear();
}
}
/* ============================================================================ *
Actor faction tallies
* ============================================================================ */
int16 AddFactionTally(int faction, enum factionTallyTypes act, int amt) {
#if DEBUG
if (faction >= kMaxFactions)
error("Scripter: Tell Talin to increase kMaxFactions!\n");
assert(faction >= 0);
assert(act >= 0);
assert(act < kFactionNumColumns);
#endif
/*
// If faction attitude counts get to big then down-scale all of them
// in proportion.
if ( g_vm->_act->_factionTable[faction][act] + amt > maxint16 )
{
for (int i = 0; i < kFactionNumColumns; i++)
g_vm->_act->_factionTable[faction][i] >>= 1;
}
// Otherwise, if it doesn;t underflow, then add it in.
if ( g_vm->_act->_factionTable[faction][act] + amt > minint16 )
{
g_vm->_act->_factionTable[faction][act] += amt;
}
*/
g_vm->_act->_factionTable[faction][act] = clamp(minint16,
g_vm->_act->_factionTable[faction][act] + amt,
maxint16);
return g_vm->_act->_factionTable[faction][act];
}
// Get the attitude a particular faction has for a char.
int16 GetFactionTally(int faction, enum factionTallyTypes act) {
#if DEBUG
if (faction >= kMaxFactions)
error("Scripter: Tell Talin to increase kMaxFactions!\n");
assert(faction >= 0);
assert(act >= 0);
assert(act < kFactionNumColumns);
#endif
return g_vm->_act->_factionTable[faction][act];
}
//-------------------------------------------------------------------
// Initialize the faction tally table
void initFactionTallies() {
memset(&g_vm->_act->_factionTable, 0, sizeof(g_vm->_act->_factionTable));
}
void saveFactionTallies(Common::OutSaveFile *outS) {
debugC(2, kDebugSaveload, "Saving Faction Tallies");
outS->write("FACT", 4);
CHUNK_BEGIN;
for (int i = 0; i < kMaxFactions; ++i) {
for (int j = 0; j < kFactionNumColumns; ++j)
out->writeSint16LE(g_vm->_act->_factionTable[i][j]);
}
CHUNK_END;
}
void loadFactionTallies(Common::InSaveFile *in) {
debugC(2, kDebugSaveload, "Loading Faction Tallies");
for (int i = 0; i < kMaxFactions; ++i) {
for (int j = 0; j < kFactionNumColumns; ++j)
g_vm->_act->_factionTable[i][j] = in->readSint16LE();
}
}
}
|