[7f4ce8]: gemrb / plugins / Core / Actor.cpp  Maximize  Restore  History

Download this file

4341 lines (3916 with data), 110.5 kB

   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
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
/* GemRB - Infinity Engine Emulator
* Copyright (C) 2003 The GemRB Project
*
* 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 2
* 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, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* $Id$
*
*/
#include "../../includes/win32def.h"
#include <cassert>
#include "TableMgr.h"
#include "ResourceMgr.h"
#include "Audio.h" //pst (react to death sounds)
#include "Actor.h"
#include "Interface.h"
#include "../../includes/strrefs.h"
#include "../../includes/overlays.h"
#include "Item.h"
#include "Spell.h"
#include "Projectile.h"
#include "Game.h"
#include "GameScript.h"
#include "ScriptEngine.h"
#include "GSUtils.h" //needed for DisplayStringCore
#include "Video.h"
#include "damages.h"
#include "ProjectileServer.h"
extern Interface* core;
#ifdef WIN32
extern HANDLE hConsole;
#endif
static const Color green = {
0x00, 0xff, 0x00, 0xff
};
static const Color red = {
0xff, 0x00, 0x00, 0xff
};
static const Color yellow = {
0xff, 0xff, 0x00, 0xff
};
static const Color cyan = {
0x00, 0xff, 0xff, 0xff
};
static const Color magenta = {
0xff, 0x00, 0xff, 0xff
};
static int sharexp = SX_DIVIDE;
static int classcount = -1;
static char **clericspelltables = NULL;
static char **druidspelltables = NULL;
static char **wizardspelltables = NULL;
static int *turnlevels = NULL;
static int *xpbonus = NULL;
static int xpbonustypes = -1;
static int xpbonuslevels = -1;
static int FistRows = -1;
typedef ieResRef FistResType[MAX_LEVEL+1];
static FistResType *fistres = NULL;
static ieResRef DefaultFist = {"FIST"};
//item usability array
struct ItemUseType {
ieResRef table; //which table contains the stat usability flags
ieByte stat; //which actor stat we talk about
ieByte mcol; //which column should be matched against the stat
ieByte vcol; //which column has the bit value for it
ieByte which; //which item dword should be used (1 = kit)
};
static ItemUseType *itemuse = NULL;
static int usecount = -1;
//item animation override array
struct ItemAnimType {
ieResRef itemname;
ieByte animation;
};
static ItemAnimType *itemanim = NULL;
static int animcount = -1;
static int fiststat = IE_CLASS;
//conversion for 3rd ed
static int isclass[11]={0,0,0,0,0,0,0,0,0,0,0};
#define ISBARBARIAN 0
#define ISBARD 1
#define ISCLERIC 2
#define ISDRUID 3
#define ISFIGHTER 4
#define ISMONK 5
#define ISPALADIN 6
#define ISRANGER 7
#define ISROGUE 8
#define ISSORCERER 9
#define ISWIZARD 10
static const int levelslots[11]={IE_LEVELFIGHTER,IE_LEVELMAGE,IE_LEVELTHIEF,
IE_LEVELBARBARIAN,IE_LEVELBARD,IE_LEVELCLERIC,IE_LEVELDRUID,IE_LEVELMONK,
IE_LEVELPALADIN,IE_LEVELRANGER,IE_LEVELSORCEROR};
//stat values are 0-255, so a byte is enough
static ieByte featstats[MAX_FEATS]={0
};
static ActionButtonRow *GUIBTDefaults = NULL; //qslots row count
ActionButtonRow DefaultButtons = {ACT_TALK, ACT_WEAPON1, ACT_WEAPON2,
ACT_NONE, ACT_NONE, ACT_NONE, ACT_NONE, ACT_NONE, ACT_NONE, ACT_NONE,
ACT_NONE, ACT_INNATE};
static int QslotTranslation = FALSE;
static int DeathOnZeroStat = TRUE;
static ieDword TranslucentShadows = 0;
static int ProjectileSize = 0; //the size of the projectile immunity bitfield (dwords)
static const char iwd2gemrb[32] = {
0,0,20,2,22,25,0,14,
15,23,13,0,1,24,8,21,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0
};
static const char gemrb2iwd[32] = {
11,12,3,71,72,73,0,0, //0
14,80,83,82,81,10,7,8, //8
0,0,0,0,2,15,4,9, //16
13,5,0,0,0,0,0,0 //24
};
//letters for char sound resolution bg1/bg2
static char csound[VCONST_COUNT];
static void InitActorTables();
#define DAMAGE_LEVELS 19
#define ATTACKROLL 20
#define SAVEROLL 20
#define DEFAULTAC 10
static ieResRef d_main[DAMAGE_LEVELS] = {
//slot 0 is not used in the original engine
"BLOODCR","BLOODS","BLOODM","BLOODL", //blood
"SPFIRIMP","SPFIRIMP","SPFIRIMP", //fire
"SPSHKIMP","SPSHKIMP","SPSHKIMP", //spark
"SPFIRIMP","SPFIRIMP","SPFIRIMP", //ice
"SHACID","SHACID","SHACID", //acid
"SPDUSTY2","SPDUSTY2","SPDUSTY2" //disintegrate
};
static ieResRef d_splash[DAMAGE_LEVELS] = {
"","","","",
"SPBURN","SPBURN","SPBURN", //flames
"SPSPARKS","SPSPARKS","SPSPARKS", //sparks
"","","",
};
#define BLOOD_GRADIENT 19
#define FIRE_GRADIENT 19
#define ICE_GRADIENT 71
#define STONE_GRADIENT 93
static int d_gradient[DAMAGE_LEVELS] = {
BLOOD_GRADIENT,BLOOD_GRADIENT,BLOOD_GRADIENT,BLOOD_GRADIENT,
FIRE_GRADIENT,FIRE_GRADIENT,FIRE_GRADIENT,
-1,-1,-1,
ICE_GRADIENT,ICE_GRADIENT,ICE_GRADIENT,
-1,-1,-1,
-1,-1,-1
};
static ieResRef hc_overlays[OVERLAY_COUNT]={"SANCTRY","SPENTACI","SPMAGGLO","SPSHIELD",
"GREASED","WEBENTD","MINORGLB","","","","","","","","","","","","","","",
"","","","SPTURNI2","SPTURNI","","","","","",""};
static ieDword hc_locations=0x2ba80030;
static int *mxsplwis = NULL;
static int spllevels;
//for every game except IWD2 we need to reverse TOHIT
static int ReverseToHit=TRUE;
static int CheckAbilities=FALSE;
//internal flags for calculating to hit
#define WEAPON_FIST 0
#define WEAPON_MELEE 1
#define WEAPON_RANGED 2
#define WEAPON_STYLEMASK 15
#define WEAPON_LEFTHAND 16
#define WEAPON_USESTRENGTH 32
void ReleaseMemoryActor()
{
if (mxsplwis) {
//calloc'd x*y integer matrix
free (mxsplwis);
mxsplwis = NULL;
}
if (fistres) {
delete [] fistres;
fistres = NULL;
}
if (itemuse) {
delete [] itemuse;
itemuse = NULL;
}
if (itemanim) {
delete [] itemanim;
itemanim = NULL;
}
FistRows = -1;
}
Actor::Actor()
: Movable( ST_ACTOR )
{
int i;
for (i = 0; i < MAX_STATS; i++) {
BaseStats[i] = 0;
Modified[i] = 0;
}
SmallPortrait[0] = 0;
LargePortrait[0] = 0;
anims = NULL;
ShieldRef[0]=0;
HelmetRef[0]=0;
WeaponRef[0]=0;
for (i = 0; i < EXTRA_ACTORCOVERS; ++i)
extraCovers[i] = NULL;
LongName = NULL;
ShortName = NULL;
LongStrRef = (ieStrRef) -1;
ShortStrRef = (ieStrRef) -1;
LastProtected = 0;
LastFollowed = 0;
LastCommander = 0;
LastHelp = 0;
LastSeen = 0;
LastMarked = 0;
LastHeard = 0;
PCStats = NULL;
LastCommand = 0; //used by order
LastShout = 0; //used by heard
LastDamage = 0;
LastDamageType = 0;
HotKey = 0;
attackcount = 0;
initiative = 0;
InTrap = 0;
PathTries = 0;
inventory.SetInventoryType(INVENTORY_CREATURE);
fxqueue.SetOwner( this );
inventory.SetOwner( this );
if (classcount<0) {
//This block is executed only once, when the first actor is loaded
InitActorTables();
TranslucentShadows = 0;
core->GetDictionary()->Lookup("Translucent Shadows", TranslucentShadows);
//get the needed size to store projectile immunity bitflags in Dwords
ProjectileSize = (core->GetProjectileServer()->GetHighestProjectileNumber()+31)/32;
//allowing 1024 bits (1024 projectiles ought to be enough for everybody)
//the rest of the projectiles would still work, but couldn't be resisted
if (ProjectileSize>32) {
ProjectileSize=32;
}
}
projectileImmunity = (ieDword *) calloc(ProjectileSize,sizeof(ieDword));
TalkCount = 0;
InteractCount = 0; //numtimesinteracted depends on this
appearance = 0xffffff; //might be important for created creatures
version = 0;
//these are used only in iwd2 so we have to default them
for(i=0;i<7;i++) {
BaseStats[IE_HATEDRACE2+i]=0xff;
}
//this one is saved only for PC's
ModalState = 0;
//set it to a neutral value
ModalSpell[0] = '*';
//this one is saved, but not loaded?
localID = globalID = 0;
}
Actor::~Actor(void)
{
unsigned int i;
if (anims) {
delete( anims );
}
core->FreeString( LongName );
core->FreeString( ShortName );
if (PCStats) {
delete PCStats;
}
for (i = 0; i < vvcOverlays.size(); i++) {
if (vvcOverlays[i]) {
delete vvcOverlays[i];
vvcOverlays[i] = NULL;
}
}
for (i = 0; i < vvcShields.size(); i++) {
if (vvcShields[i]) {
delete vvcShields[i];
vvcShields[i] = NULL;
}
}
for (i = 0; i < EXTRA_ACTORCOVERS; i++)
delete extraCovers[i];
free(projectileImmunity);
}
void Actor::SetFistStat(ieDword stat)
{
fiststat = stat;
}
void Actor::SetDefaultActions(int qslot, ieByte slot1, ieByte slot2, ieByte slot3)
{
QslotTranslation=qslot;
DefaultButtons[0]=slot1;
DefaultButtons[1]=slot2;
DefaultButtons[2]=slot3;
}
void Actor::SetText(const char* ptr, unsigned char type)
{
size_t len = strlen( ptr ) + 1;
//32 is the maximum possible length of the actor name in the original games
if (len>32) len=33;
if (type!=2) {
LongName = ( char * ) realloc( LongName, len );
memcpy( LongName, ptr, len );
}
if (type!=1) {
ShortName = ( char * ) realloc( ShortName, len );
memcpy( ShortName, ptr, len );
}
}
void Actor::SetText(int strref, unsigned char type)
{
if (type!=2) {
if (LongName) free(LongName);
LongName = core->GetString( strref );
}
if (type!=1) {
if (ShortName) free(ShortName);
ShortName = core->GetString( strref );
}
}
void Actor::SetAnimationID(unsigned int AnimID)
{
//if the palette is locked, then it will be transferred to the new animation
Palette *recover = NULL;
if (anims) {
if (anims->lockPalette) {
recover = anims->palette[PAL_MAIN];
}
// Take ownership so the palette won't be deleted
if (recover) {
recover->IncRef();
}
delete( anims );
}
//hacking PST no palette
if (core->HasFeature(GF_ONE_BYTE_ANIMID) ) {
if ((AnimID&0xf000)==0xe000) {
if (BaseStats[IE_COLORCOUNT]) {
printMessage("Actor"," ",YELLOW);
printf("Animation ID %x is supposed to be real colored (no recoloring), patched creature\n", AnimID);
}
BaseStats[IE_COLORCOUNT]=0;
}
}
anims = new CharAnimations( AnimID&0xffff, BaseStats[IE_ARMOR_TYPE]);
if(anims->ResRef[0] == 0) {
delete anims;
anims = NULL;
printMessage("Actor", " ",LIGHT_RED);
printf("Missing animation for %s\n",LongName);
return;
}
anims->SetOffhandRef(ShieldRef);
anims->SetHelmetRef(HelmetRef);
anims->SetWeaponRef(WeaponRef);
//if we have a recovery palette, then set it back
assert(anims->palette[PAL_MAIN] == 0);
anims->palette[PAL_MAIN] = recover;
if (recover) {
anims->lockPalette = true;
}
//bird animations are not hindered by searchmap
//only animtype==7 (bird) uses this feature
//this is a hardcoded hack, but works for all engine type
if (anims->GetAnimType()!=IE_ANI_BIRD) {
BaseStats[IE_DONOTJUMP]=0;
} else {
BaseStats[IE_DONOTJUMP]=DNJ_BIRD;
}
SetCircleSize();
anims->SetColors(BaseStats+IE_COLORS);
}
CharAnimations* Actor::GetAnims()
{
return anims;
}
/** Returns a Stat value (Base Value + Mod) */
ieDword Actor::GetStat(unsigned int StatIndex) const
{
if (StatIndex >= MAX_STATS) {
return 0xdadadada;
}
return Modified[StatIndex];
}
void Actor::SetCircleSize()
{
const Color *color;
int color_index;
if (!anims)
return;
if (UnselectableTimer) {
color = &magenta;
color_index = 4;
} else if (Modified[IE_STATE_ID] & STATE_PANIC) {
color = &yellow;
color_index = 5;
} else {
switch (Modified[IE_EA]) {
case EA_PC:
case EA_FAMILIAR:
case EA_ALLY:
case EA_CONTROLLED:
case EA_CHARMED:
case EA_EVILBUTGREEN:
case EA_GOODCUTOFF:
color = &green;
color_index = 0;
break;
case EA_ENEMY:
case EA_GOODBUTRED:
case EA_EVILCUTOFF:
color = &red;
color_index = 1;
break;
default:
color = &cyan;
color_index = 2;
break;
}
}
int csize = anims->GetCircleSize() - 1;
if (csize >= MAX_CIRCLE_SIZE)
csize = MAX_CIRCLE_SIZE - 1;
SetCircle( anims->GetCircleSize(), *color, core->GroundCircles[csize][color_index], core->GroundCircles[csize][(color_index == 0) ? 3 : color_index] );
}
void ApplyClab(Actor *actor, const char *clab, int level)
{
AutoTable table(clab);
if (table) {
int row = table->GetRowCount();
for(int i=0;i<level;i++) {
for (int j=0;j<row;j++) {
const char *res = table->QueryField(j,i);
if (!memcmp(res,"AP_",3)) {
core->ApplySpell(res+2, actor, actor, 0);
}
else if (!memcmp(res,"GA_",3)) {
actor->LearnSpell(res+2, 0);
}
else if (!memcmp(res,"FA_",3)) {//iwd2 only
int x=atoi(res+3);
core->DisplayStringName(x,0xffffff,actor,0);
}
else if (!memcmp(res,"FS_",3)) {//iwd2? (song?)
int x=atoi(res+3);
core->DisplayStringName(x,0xffffff,actor,0);
}
else if (!memcmp(res,"RA_",3)) {//iwd2
int x=atoi(res+3);
core->DisplayStringName(x,0xffffff,actor,0);
}
}
}
}
}
#define BG2_KITMASK 0xc000ffff
#define KIT_BARBARIAN 0x40000000
#define KIT_BASECLASS 0x4000
//applies a kit on the character (only bg2)
bool Actor::ApplyKit(ieDword Value)
{
//get current unmodified level (i guess)
int level = GetXPLevel(false);
AutoTable table("kitlist");
if (table) {
ieDword row;
//find row by unusability
row = table->GetRowCount();
while (row) {
row--;
ieDword Unusability = (ieDword) strtol(table->QueryField(row, 6),NULL,0);
if (Value == Unusability) {
goto found_row;
}
}
//if it wasn't found, try the bg2 kit format
if ((Value&BG2_KITMASK)==KIT_BARBARIAN) {
row = (Value>>16)&0xfff;
}
//cannot find kit
if (table->GetRowCount()>=row) {
return false;
}
found_row:
ieDword cls = (ieDword) atoi(table->QueryField(row, 7));
if (cls!=BaseStats[IE_CLASS]) {
//cannot apply kit, because the class doesn't fit
return false;
}
const char *clab = table->QueryField(row, 4);
ApplyClab(this, clab, level);
}
return true;
}
//call this when morale or moralebreak changed
//cannot use old or new value, because it is called two ways
void pcf_morale (Actor *actor, ieDword /*oldValue*/, ieDword /*newValue*/)
{
if (actor->Modified[IE_MORALE]<=actor->Modified[IE_MORALEBREAK] ) {
actor->Panic();
}
//for new colour
actor->SetCircleSize();
}
void pcf_ea (Actor *actor, ieDword /*oldValue*/, ieDword /*newValue*/)
{
actor->SetCircleSize();
}
//this is a good place to recalculate level up stuff
void pcf_level (Actor *actor, ieDword /*oldValue*/, ieDword /*newValue*/)
{
ieDword sum =
actor->BaseStats[IE_LEVELFIGHTER]+
actor->BaseStats[IE_LEVELMAGE]+
actor->BaseStats[IE_LEVELTHIEF]+
actor->BaseStats[IE_LEVELBARBARIAN]+
actor->BaseStats[IE_LEVELBARD]+
actor->BaseStats[IE_LEVELCLERIC]+
actor->BaseStats[IE_LEVELDRUID]+
actor->BaseStats[IE_LEVELMONK]+
actor->BaseStats[IE_LEVELPALADIN]+
actor->BaseStats[IE_LEVELRANGER]+
actor->BaseStats[IE_LEVELSORCEROR];
actor->SetBase(IE_CLASSLEVELSUM,sum);
//this will be called anyway
//actor->SetupFist();
}
void pcf_class (Actor *actor, ieDword /*oldValue*/, ieDword /*newValue*/)
{
actor->InitButtons(actor->Modified[IE_CLASS]);
}
void pcf_animid(Actor *actor, ieDword /*oldValue*/, ieDword newValue)
{
actor->SetAnimationID(newValue);
}
static const ieDword fullwhite[7]={ICE_GRADIENT,ICE_GRADIENT,ICE_GRADIENT,ICE_GRADIENT,ICE_GRADIENT,ICE_GRADIENT,ICE_GRADIENT};
static const ieDword fullstone[7]={STONE_GRADIENT,STONE_GRADIENT,STONE_GRADIENT,STONE_GRADIENT,STONE_GRADIENT,STONE_GRADIENT,STONE_GRADIENT};
void pcf_state(Actor *actor, ieDword /*oldValue*/, ieDword State)
{
if (actor->InParty) {
core->SetEventFlag(EF_PORTRAIT);
}
if (State & STATE_PETRIFIED) {
actor->SetLockedPalette(fullstone);
return;
}
if (State & STATE_FROZEN) {
actor->SetLockedPalette(fullwhite);
return;
}
actor->UnlockPalette();
}
//changes based on extended state bits, right now it is only the seven eyes
//animation (used in how/iwd2)
void pcf_extstate(Actor *actor, ieDword oldValue, ieDword State)
{
if ((oldValue^State)&EXTSTATE_SEVEN_EYES) {
ieDword mask = EXTSTATE_EYE_MIND;
int eyeCount = 7;
for (int i=0;i<7;i++)
{
if (State&mask) eyeCount--;
mask<<=1;
}
ScriptedAnimation *sca = actor->FindOverlay(OV_SEVENEYES);
if (sca) {
sca->SetOrientation(eyeCount);
}
sca = actor->FindOverlay(OV_SEVENEYES2);
if (sca) {
sca->SetOrientation(eyeCount);
}
}
}
void pcf_hitpoint(Actor *actor, ieDword /*oldValue*/, ieDword hp)
{
if ((signed) actor->BaseStats[IE_HITPOINTS]>(signed) actor->Modified[IE_MAXHITPOINTS]) {
actor->BaseStats[IE_HITPOINTS]=actor->Modified[IE_MAXHITPOINTS];
}
if ((signed) hp>(signed) actor->Modified[IE_MAXHITPOINTS]) {
hp=actor->Modified[IE_MAXHITPOINTS];
}
if ((signed) hp<(signed) actor->Modified[IE_MINHITPOINTS]) {
hp=actor->Modified[IE_MINHITPOINTS];
}
if ((signed) hp<=0) {
actor->Die(NULL);
}
actor->Modified[IE_HITPOINTS]=hp;
if (actor->InParty) {
core->SetEventFlag(EF_PORTRAIT);
}
}
void pcf_maxhitpoint(Actor *actor, ieDword /*oldValue*/, ieDword hp)
{
if ((signed) hp<(signed) actor->Modified[IE_HITPOINTS]) {
actor->Modified[IE_HITPOINTS]=hp;
//passing 0 because it is ignored anyway
pcf_hitpoint(actor, 0, hp);
}
if (actor->InParty) {
core->SetEventFlag(EF_PORTRAIT);
}
}
void pcf_minhitpoint(Actor *actor, ieDword /*oldValue*/, ieDword hp)
{
if ((signed) hp>(signed) actor->Modified[IE_HITPOINTS]) {
actor->Modified[IE_HITPOINTS]=hp;
//passing 0 because it is ignored anyway
pcf_hitpoint(actor, 0, hp);
}
}
void pcf_stat(Actor *actor, ieDword newValue, ieDword stat)
{
if ((signed) newValue<=0) {
if (DeathOnZeroStat) {
actor->Die(NULL);
} else {
actor->Modified[stat]=1;
}
}
if (actor->InParty) {
core->SetEventFlag(EF_PORTRAIT);
}
}
void pcf_stat_str(Actor *actor, ieDword /*oldValue*/, ieDword newValue)
{
pcf_stat(actor, newValue, IE_STR);
}
void pcf_stat_int(Actor *actor, ieDword /*oldValue*/, ieDword newValue)
{
pcf_stat(actor, newValue, IE_INT);
}
void pcf_stat_wis(Actor *actor, ieDword /*oldValue*/, ieDword newValue)
{
pcf_stat(actor, newValue, IE_WIS);
}
void pcf_stat_dex(Actor *actor, ieDword /*oldValue*/, ieDword newValue)
{
pcf_stat(actor, newValue, IE_DEX);
}
void pcf_stat_con(Actor *actor, ieDword /*oldValue*/, ieDword newValue)
{
pcf_stat(actor, newValue, IE_CON);
pcf_hitpoint(actor, 0, actor->Modified[IE_HITPOINTS]);
}
void pcf_stat_cha(Actor *actor, ieDword /*oldValue*/, ieDword newValue)
{
pcf_stat(actor, newValue, IE_CHR);
}
void pcf_gold(Actor *actor, ieDword /*oldValue*/, ieDword /*newValue*/)
{
//this function will make a party member automatically donate their
//gold to the party pool, not the same as in the original engine
if (actor->InParty) {
Game *game = core->GetGame();
game->AddGold ( actor->BaseStats[IE_GOLD] );
actor->BaseStats[IE_GOLD]=0;
}
}
static void handle_overlay(Actor *actor, ieDword idx)
{
if (actor->FindOverlay(idx))
return;
ieDword flag = hc_locations&(1<<idx);
ScriptedAnimation *sca = gamedata->GetScriptedAnimation(hc_overlays[idx], false);
if (sca) {
if (flag) {
sca->ZPos=-1;
}
actor->AddVVCell(sca);
}
}
//de/activates the entangle overlay
void pcf_entangle(Actor *actor, ieDword oldValue, ieDword newValue)
{
if (newValue&1) {
handle_overlay(actor, OV_ENTANGLE);
}
if (oldValue&1) {
actor->RemoveVVCell(hc_overlays[OV_ENTANGLE], true);
}
}
//de/activates the sanctuary overlay
//the sanctuary vvc draws the globe half transparent
void pcf_sanctuary(Actor *actor, ieDword oldValue, ieDword newValue)
{
ieDword changed = newValue^oldValue;
ieDword mask = 1;
for (int i=0;i<32;i++) {
if (changed&mask) {
if (newValue&mask) {
handle_overlay(actor, i);
} else {
actor->RemoveVVCell(hc_overlays[i], true);
}
}
mask<<=1;
}
}
//de/activates the prot from missiles overlay
void pcf_shieldglobe(Actor *actor, ieDword oldValue, ieDword newValue)
{
if (newValue&1) {
handle_overlay(actor, OV_SHIELDGLOBE);
return;
}
if (oldValue&1) {
actor->RemoveVVCell(hc_overlays[OV_SHIELDGLOBE], true);
}
}
//de/activates the globe of invul. overlay
void pcf_minorglobe(Actor *actor, ieDword oldValue, ieDword newValue)
{
if (newValue&1) {
handle_overlay(actor, OV_MINORGLOBE);
return;
}
if (oldValue&1) {
actor->RemoveVVCell(hc_overlays[OV_MINORGLOBE], true);
}
}
//de/activates the grease background
void pcf_grease(Actor *actor, ieDword oldValue, ieDword newValue)
{
if (newValue&1) {
handle_overlay(actor, OV_GREASE);
return;
}
if (oldValue&1) {
actor->RemoveVVCell(hc_overlays[OV_GREASE], true);
}
}
//de/activates the web overlay
//the web effect also immobilizes the actor!
void pcf_web(Actor *actor, ieDword oldValue, ieDword newValue)
{
if (newValue&1) {
handle_overlay(actor, OV_WEB);
return;
}
if (oldValue&1) {
actor->RemoveVVCell(hc_overlays[OV_WEB], true);
}
}
//de/activates the spell bounce background
void pcf_bounce(Actor *actor, ieDword oldValue, ieDword newValue)
{
if (newValue&1) {
handle_overlay(actor, OV_BOUNCE);
return;
}
if (oldValue&1) {
//it seems we have to remove it abruptly
actor->RemoveVVCell(hc_overlays[OV_BOUNCE], false);
}
}
//no separate values (changes are permanent)
void pcf_fatigue(Actor *actor, ieDword /*oldValue*/, ieDword newValue)
{
actor->BaseStats[IE_FATIGUE]=newValue;
}
//no separate values (changes are permanent)
void pcf_intoxication(Actor *actor, ieDword /*oldValue*/, ieDword newValue)
{
actor->BaseStats[IE_INTOXICATION]=newValue;
}
void pcf_color(Actor *actor, ieDword /*oldValue*/, ieDword /*newValue*/)
{
CharAnimations *anims = actor->GetAnims();
if (anims) {
anims->SetColors(actor->Modified+IE_COLORS);
}
}
void pcf_armorlevel(Actor *actor, ieDword /*oldValue*/, ieDword newValue)
{
CharAnimations *anims = actor->GetAnims();
if (anims) {
anims->SetArmourLevel(newValue);
}
}
static int maximum_values[256]={
32767,32767,20,100,100,100,100,25,5,25,25,25,25,25,100,100,//0f
100,100,100,100,100,100,100,100,100,200,200,200,200,200,100,100,//1f
200,200,MAX_LEVEL,255,25,100,25,25,25,25,25,999999999,999999999,999999999,25,25,//2f
200,255,200,100,100,200,200,25,5,100,1,1,100,1,1,1,//3f
1,1,1,1,MAX_LEVEL,MAX_LEVEL,1,9999,25,100,100,255,1,20,20,25,//4f
25,1,1,255,25,25,255,255,25,5,5,5,5,5,5,5,//5f
5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,//6f
5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,//7f
5,5,5,5,5,5,5,100,100,100,255,5,5,255,1,1,//8f
1,25,25,30,1,1,1,25,-1,100,100,1,255,255,255,255,//9f
255,255,255,255,255,255,20,255,255,1,20,255,999999999,999999999,1,1,//af
999999999,999999999,0,0,10,0,0,0,0,0,0,0,0,0,0,0,//bf
0,0,0,0,0,0,0,25,25,255,255,255,255,65535,-1,-1,//cf - 207
-1,-1,-1,-1,-1,-1,-1,-1,MAX_LEVEL,255,65535,3,255,255,255,255,//df - 223
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,//ef - 239
MAX_LEVEL,MAX_LEVEL,MAX_LEVEL,MAX_LEVEL, MAX_LEVEL,MAX_LEVEL,MAX_LEVEL,MAX_LEVEL, //0xf7 - 247
MAX_LEVEL,MAX_LEVEL,MAX_LEVEL,MAX_LEVEL, 255,65535,65535,15//ff
};
typedef void (*PostChangeFunctionType)(Actor *actor, ieDword oldValue, ieDword newValue);
static PostChangeFunctionType post_change_functions[256]={
pcf_hitpoint, pcf_maxhitpoint, NULL, NULL, NULL, NULL, NULL, NULL,
NULL,NULL,NULL,NULL, NULL, NULL, NULL, NULL, //0f
NULL,NULL,NULL,NULL, NULL, NULL, NULL, NULL,
NULL,NULL,NULL,NULL, NULL, NULL, pcf_fatigue, pcf_intoxication, //1f
NULL,NULL,pcf_level,NULL, pcf_stat_str, NULL, pcf_stat_int, pcf_stat_wis,
pcf_stat_dex,pcf_stat_con,pcf_stat_cha,NULL, NULL, pcf_gold, pcf_morale, NULL, //2f
NULL,NULL,NULL,NULL, NULL, NULL, NULL, NULL,
NULL,NULL,NULL,NULL, NULL, NULL, pcf_entangle, pcf_sanctuary, //3f
pcf_minorglobe, pcf_shieldglobe, pcf_grease, pcf_web, pcf_level, pcf_level, NULL, NULL,
NULL,NULL,NULL,NULL, NULL, NULL, NULL, NULL, //4f
NULL,NULL,NULL,pcf_minhitpoint, NULL, NULL, NULL, NULL,
NULL,NULL,NULL,NULL, NULL, NULL, NULL, NULL, //5f
NULL,NULL,NULL,NULL, NULL, NULL, NULL, NULL,
NULL,NULL,NULL,NULL, NULL, NULL, NULL, NULL, //6f
NULL,NULL,NULL,NULL, NULL, NULL, NULL, NULL,
NULL,NULL,NULL,NULL, NULL, NULL, NULL, NULL, //7f
NULL,NULL,NULL,NULL, NULL, NULL, NULL, NULL,
NULL,NULL,NULL,NULL, NULL, NULL, NULL, NULL, //8f
NULL,NULL,NULL,NULL, NULL, NULL, NULL, NULL,
NULL,NULL,NULL,NULL, NULL, NULL, NULL, NULL, //9f
NULL,NULL,NULL,NULL, NULL, NULL, NULL, NULL,
NULL,NULL,NULL,NULL, NULL, NULL, NULL, NULL, //af
NULL,NULL,NULL,NULL, pcf_morale, pcf_bounce, NULL, NULL,
NULL,NULL,NULL,NULL, NULL, NULL, NULL, NULL, //bf
NULL,NULL,NULL,NULL, NULL, NULL, NULL, NULL,
NULL,NULL,NULL,NULL, NULL, pcf_animid,pcf_state, pcf_extstate, //cf
pcf_color,pcf_color,pcf_color,pcf_color, pcf_color, pcf_color, pcf_color, NULL,
NULL,NULL,NULL,pcf_armorlevel, NULL, NULL, NULL, NULL, //df
NULL,NULL,NULL,NULL, NULL, NULL, NULL, NULL,
pcf_class,NULL,pcf_ea,NULL, NULL, NULL, NULL, NULL, //ef
pcf_level,pcf_level,pcf_level,pcf_level, pcf_level, pcf_level, pcf_level, pcf_level,
NULL,NULL,NULL,NULL, NULL, NULL, NULL, NULL //ff
};
/** call this from ~Interface() */
void Actor::ReleaseMemory()
{
int i;
if (classcount>=0) {
if (clericspelltables) {
for (i=0;i<classcount;i++) {
if (clericspelltables[i]) {
free (clericspelltables[i]);
}
}
free(clericspelltables);
clericspelltables=NULL;
}
if (druidspelltables) {
for (i=0;i<classcount;i++) {
if (druidspelltables[i]) {
free (druidspelltables[i]);
}
}
free(druidspelltables);
druidspelltables=NULL;
}
if (wizardspelltables) {
for (i=0;i<classcount;i++) {
if (wizardspelltables[i]) {
free(wizardspelltables[i]);
}
}
free(wizardspelltables);
wizardspelltables=NULL;
}
if (turnlevels) {
free(turnlevels);
turnlevels=NULL;
}
if (xpbonus) {
free(xpbonus);
xpbonus=NULL;
xpbonuslevels = -1;
xpbonustypes = -1;
}
}
if (GUIBTDefaults) {
free (GUIBTDefaults);
GUIBTDefaults=NULL;
}
classcount = -1;
}
#define COL_HATERACE 0 //ranger type racial enemy
#define COL_CLERIC_SPELL 1 //cleric spells
#define COL_MAGE_SPELL 2 //mage spells
#define COL_STARTXP 3 //starting xp
#define COL_BARD_SKILL 4 //bard skills
#define COL_THIEF_SKILL 5 //thief skills
#define COL_MAIN 0
#define COL_SPARKS 1
#define COL_GRADIENT 2
static void InitActorTables()
{
int i, j;
if (core->HasFeature(GF_CHALLENGERATING)) {
sharexp=SX_DIVIDE|SX_CR;
} else {
sharexp=SX_DIVIDE;
}
ReverseToHit = core->HasFeature(GF_REVERSE_TOHIT);
CheckAbilities = core->HasFeature(GF_CHECK_ABILITIES);
DeathOnZeroStat = core->HasFeature(GF_DEATH_ON_ZERO_STAT);
//this table lists various level based xp bonuses
AutoTable tm("xpbonus");
if (tm) {
xpbonustypes = tm->GetRowCount();
if (xpbonustypes == 0) {
xpbonuslevels = 0;
} else {
xpbonuslevels = tm->GetColumnCount(0);
xpbonus = (int *) calloc(xpbonuslevels*xpbonustypes, sizeof(int));
for (i = 0; i<xpbonustypes; i++) {
for(j = 0; j<xpbonuslevels; j++) {
xpbonus[i*xpbonuslevels+j] = atoi(tm->QueryField(i,j));
}
}
}
} else {
xpbonustypes = 0;
xpbonuslevels = 0;
}
//this table lists skill groups assigned to classes
//it is theoretically possible to create hybrid classes
tm.load("clskills");
if (tm) {
classcount = tm->GetRowCount();
memset (isclass,0,sizeof(isclass));
clericspelltables = (char **) calloc(classcount, sizeof(char*));
druidspelltables = (char **) calloc(classcount, sizeof(char*));
wizardspelltables = (char **) calloc(classcount, sizeof(char*));
turnlevels = (int *) calloc(classcount, sizeof(int));
ieDword bitmask = 1;
for(i = 0; i<classcount; i++) {
const char *field;
int turnlevel = atoi(tm->QueryField( i, 7));
turnlevels[i]=turnlevel;
field = tm->QueryField( i, 9 );
if (field[0]!='*') {
isclass[ISRANGER] |= bitmask;
}
field = tm->QueryField( i, 0 );
if (field[0]!='*') {
isclass[ISDRUID] |= bitmask;
druidspelltables[i]=strdup(field);
}
field = tm->QueryField( i, 1 );
if (field[0]!='*') {
isclass[ISCLERIC] |= bitmask;
clericspelltables[i]=strdup(field);
}
field = tm->QueryField( i, 2 );
if (field[0]!='*') {
isclass[ISWIZARD] |= bitmask;
wizardspelltables[i]=strdup(field);
}
field = tm->QueryField( i, 4 );
if (field[0]!='*') {
isclass[ISBARD] |= bitmask;
}
field = tm->QueryField( i, 6 );
if (field[0]!='*') {
isclass[ISPALADIN] |= bitmask;
}
field = tm->QueryField( i, 7 );
if (atoi(field)==2) {
isclass[ISSORCERER] |= bitmask;
}
bitmask <<=1;
}
} else {
classcount = 0; //well
}
i = core->GetMaximumAbility();
maximum_values[IE_STR]=i;
maximum_values[IE_INT]=i;
maximum_values[IE_DEX]=i;
maximum_values[IE_CON]=i;
maximum_values[IE_CHR]=i;
maximum_values[IE_WIS]=i;
if (ReverseToHit) {
//all games except iwd2
maximum_values[IE_ARMORCLASS]=20;
} else {
//iwd2
maximum_values[IE_ARMORCLASS]=199;
}
//initializing the vvc resource references
tm.load("damage");
if (tm) {
for (i=0;i<DAMAGE_LEVELS;i++) {
const char *tmp = tm->QueryField( i, COL_MAIN );
strnlwrcpy(d_main[i], tmp, 8);
if (d_main[i][0]=='*') {
d_main[i][0]=0;
}
tmp = tm->QueryField( i, COL_SPARKS );
strnlwrcpy(d_splash[i], tmp, 8);
if (d_splash[i][0]=='*') {
d_splash[i][0]=0;
}
tmp = tm->QueryField( i, COL_GRADIENT );
d_gradient[i]=atoi(tmp);
}
}
tm.load("overlay");
if (tm) {
ieDword mask = 1;
for (i=0;i<OVERLAY_COUNT;i++) {
const char *tmp = tm->QueryField( i, 0 );
strnlwrcpy(hc_overlays[i], tmp, 8);
if (atoi(tm->QueryField( i, 1))) {
hc_locations|=mask;
}
mask<<=1;
}
}
//csound for bg1/bg2
memset(csound,0,sizeof(csound));
if (!core->HasFeature(GF_SOUNDFOLDERS)) {
tm.load("csound");
if (tm) {
for(i=0;i<VCONST_COUNT;i++) {
const char *tmp = tm->QueryField( i, 0 );
if (tmp[0]!='*') {
csound[i]=tmp[0];
}
}
}
}
tm.load("qslots");
GUIBTDefaults = (ActionButtonRow *) calloc( classcount,sizeof(ActionButtonRow) );
for (i = 0; i < classcount; i++) {
memcpy(GUIBTDefaults+i, &DefaultButtons, sizeof(ActionButtonRow));
if (tm) {
for (int j=0;j<MAX_QSLOTS;j++) {
GUIBTDefaults[i][j+3]=(ieByte) atoi( tm->QueryField(i,j) );
}
}
}
tm.load("itemuse");
if (tm) {
usecount = tm->GetRowCount();
itemuse = new ItemUseType[usecount];
for (i = 0; i < usecount; i++) {
itemuse[i].stat = (ieByte) atoi( tm->QueryField(i,0) );
strnlwrcpy(itemuse[i].table, tm->QueryField(i,1),8 );
itemuse[i].mcol = (ieByte) atoi( tm->QueryField(i,2) );
itemuse[i].vcol = (ieByte) atoi( tm->QueryField(i,3) );
itemuse[i].which = (ieByte) atoi( tm->QueryField(i,4) );
//limiting it to 0 or 1 to avoid crashes
if (itemuse[i].which!=1) {
itemuse[i].which=0;
}
}
}
tm.load("itemanim");
if (tm) {
animcount = tm->GetRowCount();
itemanim = new ItemAnimType[animcount];
for (i = 0; i < animcount; i++) {
strnlwrcpy(itemanim[i].itemname, tm->QueryField(i,0),8 );
itemanim[i].animation = (ieByte) atoi( tm->QueryField(i,1) );
}
}
tm.load("mxsplwis");
if (tm) {
spllevels = tm->GetColumnCount(0);
int max = core->GetMaximumAbility();
mxsplwis = (int *) calloc(max*spllevels, sizeof(int));
for (i = 0; i < spllevels; i++) {
for(int j = 0; j < max; j++) {
int k = atoi(tm->GetRowName(j))-1;
if (k>=0 && k<max) {
mxsplwis[k*spllevels+i]=atoi(tm->QueryField(j,i));
}
}
}
}
tm.load("featreq");
if (tm) {
unsigned int tmp;
for(i=0;i<MAX_FEATS;i++) {
//we need the MULTIPLE column only
//it stores the FEAT_* stat index, and could be taken multiple
//times
tmp = core->TranslateStat(tm->QueryField(i,0));
if (tmp>=MAX_STATS) {
printMessage("Actor","Invalid stat value in featreq.2da",YELLOW);
}
featstats[i] = (ieByte) tmp;
}
}
}
void Actor::SetLockedPalette(const ieDword *gradients)
{
if (!anims) return; //cannot apply it (yet)
anims->LockPalette(gradients);
}
void Actor::UnlockPalette()
{
if (!anims) return;
anims->lockPalette=false;
anims->SetColors(Modified+IE_COLORS);
}
void Actor::AddAnimation(const ieResRef resource, int gradient, int height, int flags)
{
ScriptedAnimation *sca = gamedata->GetScriptedAnimation(resource, false);
if (!sca)
return;
sca->ZPos=height;
if (flags&AA_PLAYONCE) {
sca->PlayOnce();
}
if (flags&&AA_BLEND) {
//pst anims need this?
sca->SetBlend();
}
if (gradient!=-1) {
sca->SetPalette(gradient, 4);
}
AddVVCell(sca);
}
void Actor::PlayDamageAnimation(int type)
{
int i;
switch(type) {
case 0: case 1: case 2: case 3: //blood
i = (int) GetStat(IE_ANIMATION_ID)>>16;
if (!i) i = d_gradient[type];
AddAnimation(d_main[type], i, 0, AA_PLAYONCE);
break;
case 4: case 5: case 6: case 7: //fire
AddAnimation(d_main[type], d_gradient[type], 0, AA_PLAYONCE);
for(i=DL_FIRE;i<=type;i++) {
AddAnimation(d_splash[i], d_gradient[i], 0, AA_PLAYONCE);
}
break;
case 8: case 9: case 10: //electricity
AddAnimation(d_main[type], d_gradient[type], 0, AA_PLAYONCE);
for(i=DL_ELECTRICITY;i<=type;i++) {
AddAnimation(d_splash[i], d_gradient[i], 0, AA_PLAYONCE);
}
break;
case 11: case 12: case 13://cold
AddAnimation(d_main[type], d_gradient[type], 0, AA_PLAYONCE);
break;
case 14: case 15: case 16://acid
AddAnimation(d_main[type], d_gradient[type], 0, AA_PLAYONCE);
break;
case 17: case 18: case 19://disintegrate
AddAnimation(d_main[type], d_gradient[type], 0, AA_PLAYONCE);
break;
}
}
bool Actor::SetStat(unsigned int StatIndex, ieDword Value, int pcf)
{
if (StatIndex >= MAX_STATS) {
return false;
}
if ( (signed) Value<-100) {
Value = (ieDword) -100;
}
else {
if ( maximum_values[StatIndex]>0) {
if ( (signed) Value>maximum_values[StatIndex]) {
Value = (ieDword) maximum_values[StatIndex];
}
}
}
unsigned int previous = Modified[StatIndex];
if (Modified[StatIndex]!=Value) {
Modified[StatIndex] = Value;
if (pcf) {
PostChangeFunctionType f = post_change_functions[StatIndex];
if (f) (*f)(this, previous, Value);
}
}
return true;
}
int Actor::GetMod(unsigned int StatIndex)
{
if (StatIndex >= MAX_STATS) {
return 0xdadadada;
}
return (signed) Modified[StatIndex] - (signed) BaseStats[StatIndex];
}
/** Returns a Stat Base Value */
ieDword Actor::GetBase(unsigned int StatIndex)
{
if (StatIndex >= MAX_STATS) {
return 0xffff;
}
return BaseStats[StatIndex];
}
/** Sets a Stat Base Value */
/** If required, modify the modified value and run the pcf function */
bool Actor::SetBase(unsigned int StatIndex, ieDword Value)
{
if (StatIndex >= MAX_STATS) {
return false;
}
ieDword diff = Modified[StatIndex]-BaseStats[StatIndex];
//maximize the base stat
if ( maximum_values[StatIndex]>0) {
if ( (signed) Value>maximum_values[StatIndex]) {
Value = (ieDword) maximum_values[StatIndex];
}
}
BaseStats[StatIndex] = Value;
//if already initialized, then the modified stats
//might need to run the post change function (stat change can kill actor)
SetStat (StatIndex, Value+diff, InternalFlags&IF_INITIALIZED);
return true;
}
bool Actor::SetBaseNoPCF(unsigned int StatIndex, ieDword Value)
{
if (StatIndex >= MAX_STATS) {
return false;
}
ieDword diff = Modified[StatIndex]-BaseStats[StatIndex];
//maximize the base stat
if ( maximum_values[StatIndex]>0) {
if ( (signed) Value>maximum_values[StatIndex]) {
Value = (ieDword) maximum_values[StatIndex];
}
}
BaseStats[StatIndex] = Value;
//if already initialized, then the modified stats
//might need to run the post change function (stat change can kill actor)
SetStat (StatIndex, Value+diff, 0);
return true;
}
bool Actor::SetBaseBit(unsigned int StatIndex, ieDword Value, bool setreset)
{
if (StatIndex >= MAX_STATS) {
return false;
}
if (setreset) {
BaseStats[StatIndex] |= Value;
} else {
BaseStats[StatIndex] &= ~Value;
}
//if already initialized, then the modified stats
//need to run the post change function (stat change can kill actor)
if (setreset) {
SetStat (StatIndex, Modified[StatIndex]|Value, InternalFlags&IF_INITIALIZED);
} else {
SetStat (StatIndex, Modified[StatIndex]&~Value, InternalFlags&IF_INITIALIZED);
}
return true;
}
const unsigned char *Actor::GetStateString()
{
if (!PCStats) {
return NULL;
}
ieByte *tmp = PCStats->PortraitIconString;
ieWord *Icons = PCStats->PortraitIcons;
int j=0;
for (int i=0;i<MAX_PORTRAIT_ICONS;i++) {
if (!(Icons[i]&0xff00)) {
tmp[j++]=(ieByte) ((Icons[i]&0xff)+66);
}
}
tmp[j]=0;
return tmp;
}
void Actor::AddPortraitIcon(ieByte icon)
{
if (!PCStats) {
return;
}
ieWord *Icons = PCStats->PortraitIcons;
for(int i=0;i<MAX_PORTRAIT_ICONS;i++) {
if (Icons[i]==0xffff) {
Icons[i]=icon;
return;
}
if (icon == (Icons[i]&0xff)) {
return;
}
}
}
void Actor::DisablePortraitIcon(ieByte icon)
{
if (!PCStats) {
return;
}
ieWord *Icons = PCStats->PortraitIcons;
int i;
for(i=0;i<MAX_PORTRAIT_ICONS;i++) {
if (icon == (Icons[i]&0xff)) {
Icons[i]=0xff00|icon;
return;
}
}
}
/** call this after load, to apply effects */
void Actor::RefreshEffects(EffectQueue *fx)
{
ieDword previous[MAX_STATS];
//put all special cleanup calls here
if (PCStats) {
memset( PCStats->PortraitIcons, -1, sizeof(PCStats->PortraitIcons) );
}
CharAnimations* anims = GetAnims();
if (anims) {
unsigned int location;
for (location = 0; location < 32; ++location) {
anims->ColorMods[location].type = RGBModifier::NONE;
anims->ColorMods[location].speed = 0;
}
}
spellbook.ClearBonus();
memset(applyWhenHittingMelee,0,sizeof(ieResRef));
memset(applyWhenHittingRanged,0,sizeof(ieResRef));
memset(applyWhenNearLiving,0,sizeof(ieResRef));
memset(applyWhen50Damage,0,sizeof(ieResRef));
memset(applyWhen90Damage,0,sizeof(ieResRef));
memset(applyWhenEnemySighted,0,sizeof(ieResRef));
memset(applyWhenPoisoned,0,sizeof(ieResRef));
memset(applyWhenHelpless,0,sizeof(ieResRef));
memset(applyWhenAttacked,0,sizeof(ieResRef));
memset(applyWhenBeingHit,0,sizeof(ieResRef));
memset(projectileImmunity,0,ProjectileSize*sizeof(ieDword));
//initialize base stats
bool first = !(InternalFlags&IF_INITIALIZED);
if (first) {
InternalFlags|=IF_INITIALIZED;
} else {
memcpy( previous, Modified, MAX_STATS * sizeof( ieDword ) );
}
memcpy( Modified, BaseStats, MAX_STATS * sizeof( ieDword ) );
if (fx) {
fx->SetOwner(this);
fx->AddAllEffects(this, Pos);
delete fx;
//copy back the original stats, because the effects
//will be reapplied in ApplyAllEffects again
memcpy( Modified, BaseStats, MAX_STATS * sizeof( ieDword ) );
//also clear the spell bonuses just given, they will be
//recalculated below again
spellbook.ClearBonus();
}
fxqueue.ApplyAllEffects( this );
//calculate hp bonus
int bonus;
// warrior (fighter, barbarian, ranger, or paladin) or not
// TODO: for multiclassed characters we look at all classes and use the best
// TODO: for dualclassed characters we take the best only if both are active
if (Modified[IE_CLASS]==2) {
bonus = core->GetConstitutionBonus(STAT_CON_HP_WARRIOR,Modified[IE_CON]);
} else {
bonus = core->GetConstitutionBonus(STAT_CON_HP_NORMAL,Modified[IE_CON]);
}
bonus *= GetXPLevel( true );
//morale recovery every xth AI cycle
int mrec = GetStat(IE_MORALERECOVERYTIME);
if (mrec) {
if (!(core->GetGame()->GameTime%mrec)) {
NewBase(IE_MORALE,1,MOD_ADDITIVE);
}
}
if (bonus<0 && (Modified[IE_MAXHITPOINTS]+bonus)<=0) {
bonus=1-Modified[IE_MAXHITPOINTS];
}
Modified[IE_MAXHITPOINTS]+=bonus;
Modified[IE_HITPOINTS]+=bonus;
for (unsigned int i=0;i<MAX_STATS;i++) {
if (first ) {
PostChangeFunctionType f = post_change_functions[i];
if (f) {
(*f)(this, first?0:previous[i], Modified[i]);
}
} else
if (Modified[i]!=previous[i]) {
PostChangeFunctionType f = post_change_functions[i];
if (f) {
(*f)(this, first?0:previous[i], Modified[i]);
}
}
}
//add wisdom bonus spells
if (!spellbook.IsIWDSpellBook() && mxsplwis) {
int level = Modified[IE_WIS];
if (level--) {
spellbook.BonusSpells(IE_SPELL_TYPE_PRIEST, spllevels, mxsplwis+spllevels*level);
}
}
}
void Actor::RollSaves()
{
if (InternalFlags&IF_USEDSAVE) {
SavingThrow[0]=(ieByte) core->Roll(1,SAVEROLL,0);
SavingThrow[1]=(ieByte) core->Roll(1,SAVEROLL,0);
SavingThrow[2]=(ieByte) core->Roll(1,SAVEROLL,0);
SavingThrow[3]=(ieByte) core->Roll(1,SAVEROLL,0);
SavingThrow[4]=(ieByte) core->Roll(1,SAVEROLL,0);
InternalFlags&=~IF_USEDSAVE;
}
}
/** returns true if actor made the save against saving throw type */
bool Actor::GetSavingThrow(ieDword type, int modifier)
{
assert(type<5);
InternalFlags|=IF_USEDSAVE;
int ret = SavingThrow[type];
if (ret == 1) return false;
if (ret == SAVEROLL) return true;
ret += modifier;
return ret > (int) GetStat(IE_SAVEVSDEATH+type);
}
/** implements a generic opcode function, modify modified stats
returns the change
*/
int Actor::NewStat(unsigned int StatIndex, ieDword ModifierValue, ieDword ModifierType)
{
int oldmod = Modified[StatIndex];
switch (ModifierType) {
case MOD_ADDITIVE:
//flat point modifier
SetStat(StatIndex, Modified[StatIndex]+ModifierValue, 0);
break;
case MOD_ABSOLUTE:
//straight stat change
SetStat(StatIndex, ModifierValue, 0);
break;
case MOD_PERCENT:
//percentile
SetStat(StatIndex, BaseStats[StatIndex] * ModifierValue / 100, 0);
break;
}
return Modified[StatIndex] - oldmod;
}
int Actor::NewBase(unsigned int StatIndex, ieDword ModifierValue, ieDword ModifierType)
{
int oldmod = BaseStats[StatIndex];
switch (ModifierType) {
case MOD_ADDITIVE:
//flat point modifier
SetBase(StatIndex, BaseStats[StatIndex]+ModifierValue);
break;
case MOD_ABSOLUTE:
//straight stat change
SetBase(StatIndex, ModifierValue);
break;
case MOD_PERCENT:
//percentile
SetBase(StatIndex, BaseStats[StatIndex] * ModifierValue / 100);
break;
}
return BaseStats[StatIndex] - oldmod;
}
inline int CountElements(const char *s, char separator)
{
int ret = 1;
while(*s) {
if (*s==separator) ret++;
s++;
}
return ret;
}
void Actor::Interact(int type)
{
int start;
int count;
switch(type) {
case I_INSULT: start=VB_INSULT; count=3; break;
case I_COMPLIMENT: start=VB_COMPLIMENT; count=3; break;
case I_SPECIAL: start=VB_SPECIAL; count=3; break;
default:
return;
}
count=rand()%count;
while(count && StrRefs[start+count]!=0xffff) count--;
if(count>=0) {
DisplayStringCore(this, start+count, DS_CONSOLE|DS_CONST );
}
}
void Actor::Response(int type)
{
int start;
int count;
switch(type) {
case I_INSULT: start=VB_RESP_INS; count=3; break;
case I_COMPLIMENT: start=VB_RESP_COMP; count=3; break;
default:
return;
}
count=rand()%count;
while(count && StrRefs[start+count]!=0xffff) count--;
if(count>=0) {
DisplayStringCore(this, start+count, DS_CONSOLE|DS_CONST );
}
}
void Actor::ReactToDeath(const char * deadname)
{
AutoTable tm("death");
if (!tm) return;
// lookup value based on died's scriptingname and ours
// if value is 0 - use reactdeath
// if value is 1 - use reactspecial
// if value is string - use playsound instead (pst)
const char *value = tm->QueryField (scriptName, deadname);
switch (value[0]) {
case '0':
DisplayStringCore(this, VB_REACT, DS_CONSOLE|DS_CONST );
break;
case '1':
DisplayStringCore(this, VB_REACT_S, DS_CONSOLE|DS_CONST );
break;
default:
{
int count = CountElements(value,',');
if (count<=0) break;
count = core->Roll(1,count,-1);
ieResRef resref;
while(count--) {
while(*value && *value!=',') value++;
if (*value==',') value++;
}
strncpy(resref, value, 8);
for(count=0;count<8 && resref[count]!=',';count++) {};
resref[count]=0;
ieDword len = core->GetAudioDrv()->Play( resref );
ieDword counter = ( AI_UPDATE_TIME * len ) / 1000;
if (counter != 0)
SetWait( counter );
break;
}
}
}
//call this only from gui selects
void Actor::SelectActor()
{
DisplayStringCore(this, VB_SELECT, DS_CONSOLE|DS_CONST );
}
void Actor::Panic()
{
if (GetStat(IE_STATE_ID)&STATE_PANIC) {
//already in panic
return;
}
SetBaseBit(IE_STATE_ID, STATE_PANIC, true);
DisplayStringCore(this, VB_PANIC, DS_CONSOLE|DS_CONST );
}
void Actor::SetMCFlag(ieDword arg, int op)
{
ieDword tmp = BaseStats[IE_MC_FLAGS];
switch (op) {
case BM_SET: tmp = arg; break;
case BM_OR: tmp |= arg; break;
case BM_NAND: tmp &= ~arg; break;
case BM_XOR: tmp ^= arg; break;
case BM_AND: tmp &= arg; break;
}
SetBase(IE_MC_FLAGS, tmp);
}
void Actor::DialogInterrupt()
{
//if dialoginterrupt was set, no verbal constant
if ( Modified[IE_MC_FLAGS]&MC_NO_TALK)
return;
/* this part is unsure */
if (Modified[IE_EA]>=EA_EVILCUTOFF) {
DisplayStringCore(this, VB_HOSTILE, DS_CONSOLE|DS_CONST );
} else {
DisplayStringCore(this, VB_DIALOG, DS_CONSOLE|DS_CONST );
}
}
static EffectRef fx_cure_sleep_ref={"Cure:Sleep",NULL,-1};
void Actor::GetHit()
{
SetStance( IE_ANI_DAMAGE );
DisplayStringCore(this, VB_DAMAGE, DS_CONSOLE|DS_CONST );
if (Modified[IE_STATE_ID]&STATE_SLEEP) {
if (Modified[IE_EXTSTATE_ID]&EXTSTATE_NO_WAKEUP) {
return;
}
Effect *fx = EffectQueue::CreateEffect(fx_cure_sleep_ref, 0, 0, FX_DURATION_INSTANT_PERMANENT);
fxqueue.AddEffect(fx);
}
}
bool Actor::HandleCastingStance(const ieResRef SpellResRef, bool deplete)
{
if (deplete) {
if (! spellbook.HaveSpell( SpellResRef, HS_DEPLETE )) {
SetStance(IE_ANI_READY);
return true;
}
}
SetStance(IE_ANI_CAST);
return false;
}
//returns actual damage
int Actor::Damage(int damage, int damagetype, Actor *hitter)
{
//add lastdamagetype up
LastDamageType|=damagetype;
LastHitter=hitter->GetID();
//recalculate damage based on resistances and difficulty level
//the lower 2 bits are actually modifier types
switch(damagetype&3)
{
case MOD_ADDITIVE:
damage = -NewBase(IE_HITPOINTS, (ieDword) -damage, MOD_ADDITIVE);
break;
case MOD_ABSOLUTE:
damage = -NewBase(IE_HITPOINTS, (ieDword) damage, MOD_ABSOLUTE);
break;
case MOD_PERCENT:
damage = -NewBase(IE_HITPOINTS, (ieDword) damage, MOD_PERCENT);
break;
default:
//this shouldn't happen
printMessage("Actor","Invalid damagetype!\n",RED);
return 0;
}
LastDamage=damage;
InternalFlags|=IF_ACTIVE;
int chp = (signed) Modified[IE_HITPOINTS];
int damagelevel = 3;
if (damage<5) {
damagelevel = 1;
} else if (damage<10) {
damagelevel = 2;
} else {
NewBase(IE_MORALE, (ieDword) -1, MOD_ADDITIVE);
if (chp<-10) {
damagelevel = 0; //chunky death
}
else {
damagelevel = 3;
}
}
GetHit();
if (damagetype & (DAMAGE_FIRE|DAMAGE_MAGICFIRE) ) {
PlayDamageAnimation(DL_FIRE+damagelevel);
} else if (damagetype & (DAMAGE_COLD|DAMAGE_MAGICCOLD) ) {
PlayDamageAnimation(DL_COLD+damagelevel);
} else if (damagetype & (DAMAGE_ELECTRICITY) ) {
PlayDamageAnimation(DL_ELECTRICITY+damagelevel);
} else if (damagetype & (DAMAGE_ACID) ) {
PlayDamageAnimation(DL_ACID+damagelevel);
} else if (damagetype & (DAMAGE_MAGIC) ) {
PlayDamageAnimation(DL_DISINTEGRATE+damagelevel);
} else {
PlayDamageAnimation(damagelevel);
}
printMessage("Actor"," ",GREEN);
printf("%d damage taken.\n", LastDamage);
if (InParty) {
if (chp<(signed) Modified[IE_MAXHITPOINTS]/10) {
core->Autopause(AP_WOUNDED);
}
if (damage>0) {
core->Autopause(AP_HIT);
}
}
return damage;
}
void Actor::DebugDump()
{
unsigned int i;
printf( "Debugdump of Actor %s:\n", LongName );
printf ("Scripts:");
for (i = 0; i < MAX_SCRIPTS; i++) {
const char* poi = "<none>";
if (Scripts[i] && Scripts[i]->script) {
poi = Scripts[i]->GetName();
}
printf( " %.8s", poi );
}
printf( "\nArea: %.8s ", Area );
printf( "Dialog: %.8s\n", Dialog );
printf( "Global ID: %d Local ID: %d\n", globalID, localID);
printf( "Script name:%.32s\n", scriptName );
printf( "TalkCount: %d ", TalkCount );
printf( "PartySlot: %d\n", InParty );
printf( "Allegiance: %d current allegiance:%d\n", BaseStats[IE_EA], Modified[IE_EA] );
printf( "Class: %d current class:%d\n", BaseStats[IE_CLASS], Modified[IE_CLASS] );
printf( "Race: %d current race:%d\n", BaseStats[IE_RACE], Modified[IE_RACE] );
printf( "Gender: %d current gender:%d\n", BaseStats[IE_SEX], Modified[IE_SEX] );
printf( "Specifics: %d current specifics:%d\n", BaseStats[IE_SPECIFIC], Modified[IE_SPECIFIC] );
printf( "Alignment: %x current alignment:%x\n", BaseStats[IE_ALIGNMENT], Modified[IE_ALIGNMENT] );
printf( "Morale: %d current morale:%d\n", BaseStats[IE_MORALE], Modified[IE_MORALE] );
printf( "Moralebreak:%d Morale recovery:%d\n", Modified[IE_MORALEBREAK], Modified[IE_MORALERECOVERYTIME] );
printf( "Visualrange:%d (Explorer: %d)\n", Modified[IE_VISUALRANGE], Modified[IE_EXPLORE] );
printf( "HP: %d current HP:%d\n", BaseStats[IE_HITPOINTS], Modified[IE_HITPOINTS] );
printf( "Mod[IE_ANIMATION_ID]: 0x%04X\n", Modified[IE_ANIMATION_ID] );
printf( "Colors: ");
if (core->HasFeature(GF_ONE_BYTE_ANIMID) ) {
for(i=0;i<Modified[IE_COLORCOUNT];i++) {
printf(" %d", Modified[IE_COLORS+i]);
}
}
else {
for(i=0;i<7;i++) {
printf(" %d", Modified[IE_COLORS+i]);
}
}
printf ("\nAnimate ID: %x\n", Modified[IE_ANIMATION_ID]);
printf( "WaitCounter: %d\n", (int) GetWait());
printf( "LastTarget: %d %s\n", LastTarget, GetActorNameByID(LastTarget));
printf( "LastTalked: %d %s\n", LastTalkedTo, GetActorNameByID(LastTalkedTo));
inventory.dump();
spellbook.dump();
fxqueue.dump();
}
const char* Actor::GetActorNameByID(ieDword ID) const
{
Actor *actor = GetCurrentArea()->GetActorByGlobalID(ID);
if (!actor) {
return "<NULL>";
}
return actor->GetScriptName();
}
void Actor::SetMap(Map *map, ieWord LID, ieWord GID)
{
bool effinit=false;
if (!GetCurrentArea()) {
//we had no area yet
effinit = true;
}
Scriptable::SetMap(map); //now we have an area
localID = LID;
globalID = GID;
//These functions are called once when the actor is first put in
//the area. It already has all the items (including fist) at this
//time and it is safe to call effects.
//This hack is to delay the equipping effects until the actor has
//an area (and the game object is also existing)
if (effinit) {
int SlotCount = inventory.GetSlotCount();
for (int Slot = 0; Slot<SlotCount;Slot++) {
int slottype = core->QuerySlotEffects( Slot );
switch (slottype) {
case SLOT_EFFECT_NONE:
case SLOT_EFFECT_MELEE:
break;
default:
inventory.EquipItem( Slot );
break;
}
}
//We need to convert this to signed 16 bits, because
//it is actually a 16 bit number. The high word could
//be anything. It is signed to have the correct math
//when adding it to the base slot (SLOT_WEAPON) in
//case of quivers. (weird IE magic)
inventory.SetEquippedSlot( (ieWordSigned) Equipped );
}
}
void Actor::SetPosition(Point &position, int jump, int radius)
{
PathTries = 0;
ClearPath();
Point p;
p.x = position.x/16;
p.y = position.y/12;
if (jump && !(Modified[IE_DONOTJUMP] & DNJ_FIT) && size ) {
GetCurrentArea()->AdjustPosition( p, radius );
}
p.x = p.x * 16 + 8;
p.y = p.y * 12 + 6;
MoveTo( p );
}
/* this is returning the level of the character for xp calculations
and the average level for dual/multiclass (rounded up),
also with iwd2's 3rd ed rules, this is why it is a separate function */
ieDword Actor::GetXPLevel(int modified) const
{
const ieDword *stats;
if (modified) {
stats = Modified;
}
else {
stats = BaseStats;
}
float classcount = 0;
float average = 0;
if (core->HasFeature(GF_IWD2_SCRIPTNAME)) {
// iwd2
for (int i=0; i < 11; i++) {
if (stats[levelslots[i]] > 0) classcount++;
}
average = stats[IE_CLASSLEVELSUM] / classcount + 0.5;
}
else {
int levels[3]={stats[IE_LEVEL], stats[IE_LEVEL2], stats[IE_LEVEL3]};
average = levels[0];
classcount = 1;
if (IsDualClassed()) {
// dualclassed
if (levels[1] > 0) {
classcount++;
average += levels[1];
}
}
else {
if (IsMultiClassed()) {
if (levels[1] > 0) {
classcount++;
average += levels[1];
}
// TODO: rather deduce the number of classes from the name
if (levels[2] > 0 && (levels[0]-levels[2]) < 5) { //HACK for jaheira (starts as 6-7-1)
classcount++;
average += levels[2];
}
} // else single class
}
average = average / classcount + 0.5;
}
return ieDword(average);
}
/** maybe this would be more useful if we calculate with the strength too
*/
int Actor::GetEncumbrance()
{
return inventory.GetWeight();
}
//receive turning
void Actor::Turn(Scriptable *cleric, ieDword turnlevel)
{
//this is safely hardcoded i guess
if (Modified[IE_GENERAL]!=GEN_UNDEAD) {
return;
}
//determine if we see the cleric (distance)
//determine alignment (if equals, then no turning)
//determine panic or destruction
//we get the modified level
if (turnlevel>GetXPLevel(true)) {
Die(cleric);
} else {
Panic();
}
}
void Actor::Resurrect()
{
if (!(Modified[IE_STATE_ID ] & STATE_DEAD)) {
return;
}
InternalFlags&=IF_FROMGAME; //keep these flags (what about IF_INITIALIZED)
InternalFlags|=IF_ACTIVE|IF_VISIBLE; //set these flags
SetBase(IE_STATE_ID, 0);
SetBase(IE_MORALE, 10);
SetBase(IE_HITPOINTS, BaseStats[IE_MAXHITPOINTS]);
ClearActions();
ClearPath();
SetStance(IE_ANI_EMERGE);
//clear effects?
}
void Actor::Die(Scriptable *killer)
{
if (InternalFlags&IF_REALLYDIED) {
return; //can die only once
}
int minhp=Modified[IE_MINHITPOINTS];
if (minhp) { //can't die
SetBase(IE_HITPOINTS, minhp);
return;
}
//Can't simply set Selected to false, game has its own little list
Game *game = core->GetGame();
game->SelectActor(this, false, SELECT_NORMAL);
game->OutAttack(GetID());
ClearPath();
SetModal( 0 );
DisplayStringCore(this, VB_DIE, DS_CONSOLE|DS_CONST );
//JUSTDIED will be removed when the Die() trigger executed
//otherwise it is the same as REALLYDIED
InternalFlags|=IF_REALLYDIED|IF_JUSTDIED;
SetStance( IE_ANI_DIE );
if (InParty) {
game->PartyMemberDied(this);
core->Autopause(AP_DEAD);
} else {
Actor *act=NULL;
if (!killer) {
killer = area->GetActorByGlobalID(LastHitter);
}
if (killer) {
if (killer->Type==ST_ACTOR) {
act = (Actor *) killer;
}
}
if (act && act->InParty) {
//adjust kill statistics here
PCStatsStruct *stat = act->PCStats;
if (stat) {
stat->NotifyKill(Modified[IE_XPVALUE], ShortStrRef);
}
InternalFlags|=IF_GIVEXP;
}
}
//a plot critical creature has died (iwd2)
if (BaseStats[IE_MC_FLAGS]&MC_PLOT_CRITICAL) {
core->GetGUIScriptEngine()->RunFunction("DeathWindowPlot", false);
}
//ensure that the scripts of the actor will run as soon as possible
ImmediateEvent();
}
void Actor::SetPersistent(int partyslot)
{
InParty = (ieByte) partyslot;
InternalFlags|=IF_FROMGAME;
//if an actor is coming from a game, it should have these too
CreateStats();
}
void Actor::DestroySelf()
{
InternalFlags|=IF_CLEANUP;
}
bool Actor::CheckOnDeath()
{
if (InternalFlags&IF_CLEANUP) {
return true;
}
if (InternalFlags&IF_JUSTDIED) {
if (GetNextAction()) {
return false; //actor is currently dying, let him die first
}
}
if (!(InternalFlags&IF_REALLYDIED) ) {
return false;
}
//don't mess with the already deceased
if (BaseStats[IE_STATE_ID]&STATE_DEAD) {
return false;
}
//we need to check animID here, if it has not played the death
//sequence yet, then we could return now
ClearActions();
//missed the opportunity of Died()
InternalFlags&=~IF_JUSTDIED;
Game *game = core->GetGame();
if (InternalFlags&IF_GIVEXP) {
//give experience to party
game->ShareXP(Modified[IE_XPVALUE], sharexp );
//handle reputation here
}
if (KillVar[0]) {
ieDword value = 0;
if (core->HasFeature(GF_HAS_KAPUTZ) ) {
game->kaputz->Lookup(KillVar, value);
game->kaputz->SetAt(KillVar, value+1);
} else {
game->locals->Lookup(KillVar, value);
game->locals->SetAt(KillVar, value+1);
}
}
if (scriptName[0]) {
ieVariable varname;
ieDword value = 0;
if (core->HasFeature(GF_HAS_KAPUTZ) ) {
snprintf(varname, 32, "%s_DEAD", scriptName);
game->kaputz->Lookup(varname, value);
game->kaputz->SetAt(varname, value+1);
} else {
snprintf(varname, 32, "SPRITE_IS_DEAD%s", scriptName);
game->locals->Lookup(varname, value);
game->locals->SetAt(varname, value+1);
}
}
DropItem("",0);
//remove all effects that are not 'permanent after death' here
//permanent after death type is 9
SetBaseBit(IE_STATE_ID, STATE_DEAD, true);
if (Modified[IE_MC_FLAGS]&MC_REMOVE_CORPSE) return true;
if (Modified[IE_MC_FLAGS]&MC_KEEP_CORPSE) return false;
//if chunked death, then return true
if (LastDamageType&DAMAGE_CHUNKING) {
//play chunky animation
//chunks are projectiles
return true;
}
return false;
}
/* this will create a heap at location, and transfer the item(s) */
void Actor::DropItem(const ieResRef resref, unsigned int flags)
{
if (inventory.DropItemAtLocation( resref, flags, area, Pos )) {
ReinitQuickSlots();
}
}
void Actor::DropItem(int slot , unsigned int flags)
{
if (inventory.DropItemAtLocation( slot, flags, area, Pos )) {
ReinitQuickSlots();
}
}
/** returns quick item data */
/** if header==-1 which is a 'use quickitem' action */
/** if header is set, then which is the absolute slot index, */
/** and header is the header index */
void Actor::GetItemSlotInfo(ItemExtHeader *item, int which, int header)
{
ieWord idx;
ieWord headerindex;
memset(item, 0, sizeof(ItemExtHeader) );
if (header<0) {
if (!PCStats) return; //not a player character
PCStats->GetSlotAndIndex(which,idx,headerindex);
if (headerindex==0xffff) return; //headerindex is invalid
} else {
idx=(ieWord) which;
headerindex=(ieWord) header;
}
const CREItem *slot = inventory.GetSlotItem(idx);
if (!slot) return; //quick item slot is empty
Item *itm = gamedata->GetItem(slot->ItemResRef);
if (!itm) return; //quick item slot contains invalid item resref
ITMExtHeader *ext_header = itm->GetExtHeader(headerindex);
//item has no extended header, or header index is wrong
if (!ext_header) return;
memcpy(item->itemname, slot->ItemResRef, sizeof(ieResRef) );
item->slot = idx;
item->headerindex = headerindex;
memcpy(&(item->AttackType), &(ext_header->AttackType),
((char *) &(item->itemname)) -((char *) &(item->AttackType)) );
if (headerindex>=CHARGE_COUNTERS) {
item->Charges=0;
} else {
item->Charges=slot->Usages[headerindex];
}
gamedata->FreeItem(itm,slot->ItemResRef, false);
}
void Actor::ReinitQuickSlots()
{
if (!PCStats) {
return;
}
// Note: (wjp, 20061226)
// This function needs some rethinking.
// It tries to satisfy two things at the moment:
// Fill quickslots when they are empty and an item is placed in the
// inventory slot corresponding to the quickslot
// Reset quickslots when an item is removed
// Currently, it resets all slots when items are removed,
// but it only refills the ACT_QSLOTn slots, not the ACT_WEAPONx slots.
//
// Refilling a weapon slot is possible, but essentially duplicates a lot
// of code from Inventory::EquipItem() which performs the same steps for
// the Inventory::Equipped slot.
// Hopefully, weapons/arrows are never added to inventory slots without
// EquipItem being called.
int i=sizeof(PCStats->QSlots);
while (i--) {
int slot;
int which;
if (i<0) which = ACT_WEAPON4+i+1;
else which = PCStats->QSlots[i];
switch (which) {
case ACT_WEAPON1:
case ACT_WEAPON2:
case ACT_WEAPON3:
case ACT_WEAPON4:
CheckWeaponQuickSlot(which-ACT_WEAPON1);
slot = 0;
break;
//WARNING:this cannot be condensed, because the symbols don't come in order!!!
case ACT_QSLOT1: slot = inventory.GetQuickSlot(); break;
case ACT_QSLOT2: slot = inventory.GetQuickSlot()+1; break;
case ACT_QSLOT3: slot = inventory.GetQuickSlot()+2; break;
case ACT_QSLOT4: slot = inventory.GetQuickSlot()+3; break;
case ACT_QSLOT5: slot = inventory.GetQuickSlot()+4; break;
default:
slot = 0;
}
if (!slot) continue;
//if magic items are equipped the equipping info doesn't change
//(afaik)
// Note: we're now in the QSLOTn case
// If slot is empty, reset quickslot to 0xffff/0xffff
if (!inventory.HasItemInSlot("", slot)) {
SetupQuickSlot(which, 0xffff, 0xffff);
} else {
ieWord idx;
ieWord headerindex;
PCStats->GetSlotAndIndex(which,idx,headerindex);
if (idx != slot || headerindex == 0xffff) {
// If slot just became filled, set it to filled
SetupQuickSlot(which,slot,0);
}
}
}
//these are always present
CheckWeaponQuickSlot(0);
CheckWeaponQuickSlot(1);
//disabling quick weapon slots for certain classes
for(i=0;i<2;i++) {
int which = ACT_WEAPON3+i;
// Assuming that ACT_WEAPON3 and 4 are always in the first two spots
if (PCStats->QSlots[i]!=which) {
SetupQuickSlot(which, 0xffff, 0xffff);
}
}
}
void Actor::CheckWeaponQuickSlot(unsigned int which)
{
if (!PCStats) return;
bool empty = false;
// If current quickweaponslot doesn't contain an item, reset it to fist
int slot = PCStats->QuickWeaponSlots[which];
int header = PCStats->QuickWeaponHeaders[which];
if (!inventory.HasItemInSlot("", slot) || header == 0xffff) {
empty = true;
} else {
// If current quickweaponslot contains ammo, and bow not found, reset
if (core->QuerySlotEffects(slot) == SLOT_EFFECT_MISSILE) {
const CREItem *slotitm = inventory.GetSlotItem(slot);
assert(slotitm);
Item *itm = gamedata->GetItem(slotitm->ItemResRef);
assert(itm);
ITMExtHeader *ext_header = itm->GetExtHeader(header);
if (ext_header) {
int type = ext_header->ProjectileQualifier;
int weaponslot = inventory.FindTypedRangedWeapon(type);
if (weaponslot == inventory.GetFistSlot()) {
empty = true;
}
} else {
empty = true;
}
gamedata->FreeItem(itm,slotitm->ItemResRef, false);
}
}
if (empty)
SetupQuickSlot(ACT_WEAPON1+which, inventory.GetFistSlot(), 0);
}
void Actor::SetupQuickSlot(unsigned int which, int slot, int headerindex)
{
if (!PCStats) return;
PCStats->InitQuickSlot(which, (ieWord) slot, (ieWord) headerindex);
}
bool Actor::ValidTarget(int ga_flags) const
{
if (Immobile()) return false;
//scripts can still see this type of actor
if (ga_flags&GA_NO_HIDDEN) {
if (Modified[IE_AVATARREMOVAL]) return false;
}
if (ga_flags&GA_NO_ALLY) {
if(InParty) return false;
if(Modified[IE_EA]<=EA_GOODCUTOFF) return false;
}
if (ga_flags&GA_NO_ENEMY) {
if(!InParty && (Modified[IE_EA]>=EA_EVILCUTOFF) ) return false;
}
if (ga_flags&GA_NO_NEUTRAL) {
if(!InParty && (Modified[IE_EA]<EA_EVILCUTOFF) ) return false;
}
switch(ga_flags&GA_ACTION) {
case GA_PICK:
if (Modified[IE_STATE_ID] & STATE_CANTSTEAL) return false;
break;
case GA_TALK:
//can't talk to dead
if (Modified[IE_STATE_ID] & STATE_CANTLISTEN) return false;
//can't talk to hostile
if (Modified[IE_EA]>=EA_EVILCUTOFF) return false;
break;
}
if (ga_flags&GA_NO_DEAD) {
if (InternalFlags&IF_JUSTDIED) return false;
if (Modified[IE_STATE_ID] & STATE_DEAD) return false;
}
if (ga_flags&GA_SELECT) {
if (UnselectableTimer) return false;
}
return true;
}
//returns true if it won't be destroyed with an area
//in this case it shouldn't be saved with the area either
//it will be saved in the savegame
bool Actor::Persistent() const
{
if (InParty) return true;
if (InternalFlags&IF_FROMGAME) return true;
return false;
}
//this is a reimplementation of cheatkey a/s of bg2
//cycling through animation/stance
// a - get next animation, s - get next stance
void Actor::GetNextAnimation()
{
int RowNum = anims->AvatarsRowNum - 1;
if (RowNum<0)
RowNum = CharAnimations::GetAvatarsCount() - 1;
int NewAnimID = CharAnimations::GetAvatarStruct(RowNum)->AnimID;
printf ("AnimID: %04X\n", NewAnimID);
SetBase( IE_ANIMATION_ID, NewAnimID);
//SetAnimationID ( NewAnimID );
}
void Actor::GetPrevAnimation()
{
int RowNum = anims->AvatarsRowNum + 1;
if (RowNum>=CharAnimations::GetAvatarsCount() )
RowNum = 0;
int NewAnimID = CharAnimations::GetAvatarStruct(RowNum)->AnimID;
printf ("AnimID: %04X\n", NewAnimID);
SetBase( IE_ANIMATION_ID, NewAnimID);
//SetAnimationID ( NewAnimID );
}
//slot is the projectile slot
//This will return the projectile item.
int Actor::GetRangedWeapon(ITMExtHeader *&which, WeaponInfo *wi) const
{
//EquippedSlot is the projectile. To get the weapon, use inventory.GetUsedWeapon()
unsigned int slot = inventory.GetEquippedSlot();
const CREItem *wield = inventory.GetSlotItem(slot);
if (!wield) {
return 0;
}
Item *item = gamedata->GetItem(wield->ItemResRef);
if (!item) {
return 0;
}
if (wi) {
wi->enchantment = item->Enchantment;
wi->itemflags = wield->Flags;
}
which = item->GetWeaponHeader(true);
gamedata->FreeItem(item, wield->ItemResRef, false);
return 1;
}
//returns weapon header currently used (bow in case of bow+arrow)
//if range is nonzero, then the returned header is valid
unsigned int Actor::GetWeapon(ITMExtHeader *&which, WeaponInfo *wi, bool leftorright)
{
const CREItem *wield = inventory.GetUsedWeapon(leftorright);
if (!wield) {
return 0;
}
Item *item = gamedata->GetItem(wield->ItemResRef);
if (!item) {
return 0;
}
if (wi) {
wi->enchantment = item->Enchantment;
wi->itemflags = wield->Flags;
}
//select first weapon header
which = item->GetWeaponHeader(GetAttackStyle() == WEAPON_RANGED);
//make sure we use 'false' in this freeitem
//so 'which' won't point into invalid memory
gamedata->FreeItem(item, wield->ItemResRef, false);
if (!which) {
return 0;
}
if (which->Location!=ITEM_LOC_WEAPON) {
return 0;
}
return which->Range+1;
}
void Actor::GetNextStance()
{
static int Stance = IE_ANI_AWAKE;
if (--Stance < 0) Stance = MAX_ANIMS-1;
printf ("StanceID: %d\n", Stance);
SetStance( Stance );
}
int Actor::LearnSpell(const ieResRef spellname, ieDword flags)
{
if (spellbook.HaveSpell(spellname, 0) ) {
return LSR_KNOWN;
}
Spell *spell = gamedata->GetSpell(spellname);
if (!spell) {
return LSR_INVALID; //not existent spell
}
if (flags & LS_STATS) {
// chance to learn roll
if (core->Roll(1,100,0) > core->GetIntelligenceBonus(0, GetStat(IE_INT))) {
return LSR_FAILED;
}
}
int explev = spellbook.LearnSpell(spell, flags&LS_MEMO);
int tmp = spell->SpellNameIdentified;
if (flags&LS_LEARN) {
core->GetTokenDictionary()->SetAt("SPECIALABILITYNAME", core->GetString(tmp));
switch (spell->SpellType) {
case IE_SPL_INNATE:
tmp = STR_GOTABILITY;
break;
case IE_SPL_SONG:
tmp = STR_GOTSONG;
break;
default:
tmp = STR_GOTSPELL;
break;
}
} else tmp = 0;
gamedata->FreeSpell(spell, spellname, false);
if (!explev) {
return LSR_INVALID;
}
if (tmp) {
core->DisplayConstantStringName(tmp, 0xbcefbc, this);
}
if (flags&LS_ADDXP) {
AddExperience(XP_LEARNSPELL, explev);
}
return LSR_OK;
}
const char *Actor::GetDialog(int flags) const
{
if (!flags) {
return Dialog;
}
if (Modified[IE_EA]>=EA_EVILCUTOFF) {
return NULL;
}
if ( (InternalFlags & IF_NOINT) && CurrentAction) {
if (flags>1) {
core->DisplayConstantString(STR_TARGETBUSY,0xff0000);
}
return NULL;
}
return Dialog;
}
void Actor::CreateStats()
{
if (!PCStats) {
PCStats = new PCStatsStruct();
}
}
const char* Actor::GetScript(int ScriptIndex) const
{
return Scripts[ScriptIndex]->GetName();
}
void Actor::SetModal(ieDword newstate)
{
switch(newstate) {
case MS_NONE:
break;
case MS_BATTLESONG:
break;
case MS_DETECTTRAPS:
break;
case MS_STEALTH:
break;
case MS_TURNUNDEAD:
break;
default:
return;
}
//come here only if success
ModalState = newstate;
}
//this is just a stub function for now, attackstyle could be melee/ranged
//even spells got this attack style
int Actor::GetAttackStyle()
{
int effect = core->QuerySlotEffects(inventory.GetEquippedSlot()) ;
if (effect == SLOT_EFFECT_MISSILE) return WEAPON_RANGED ;
return WEAPON_MELEE ;
}
void Actor::SetTarget( Scriptable *target)
{
if (target->Type==ST_ACTOR) {
Actor *tar = (Actor *) target;
LastTarget = tar->GetID();
tar->LastAttacker = GetID();
//we tell the game object that this creature
//must be added to the list of combatants
core->GetGame()->InAttack(tar->LastAttacker);
}
SetOrientation( GetOrient( target->Pos, Pos ), false );
SetWait( 1 );
}
//in case of LastTarget = 0
void Actor::StopAttack()
{
SetStance(IE_ANI_READY);
core->GetGame()->OutAttack(GetID());
InternalFlags|=IF_TARGETGONE; //this is for the trigger!
if (InParty) {
core->Autopause(AP_NOTARGET);
}
}
int Actor::Immobile() const
{
if (GetStat(IE_CASTERHOLD)) {
return 1;
}
if (GetStat(IE_HELD)) {
return 1;
}
return 0;
}
//calculate how many attacks will be performed
//in the next round
//only called when Game thinks we are in attack
//so it is safe to do cleanup here (it will be called only once)
void Actor::InitRound(ieDword gameTime, bool secondround)
{
attackcount = 0;
if (InternalFlags&IF_STOPATTACK) {
core->GetGame()->OutAttack(GetID());
return;
}
if (!LastTarget) {
StopAttack();
return;
}
//if held or disabled, etc, then cannot continue attacking
ieDword state = GetStat(IE_STATE_ID);
if (state&STATE_CANTMOVE) {
return;
}
if (Immobile()) {
return;
}
SetStance(AttackStance) ;
//last chance to disable attacking
//
attackcount = GetStat(IE_NUMBEROFATTACKS);
if (secondround) {
attackcount++;
}
attackcount/=2;
//d10
int tmp = core->Roll(1, 10, 0);// GetStat(IE_WEAPONSPEED)-GetStat(IE_PHYSICALSPEED) );
if (state & STATE_SLOWED) tmp <<= 1;
if (state & STATE_HASTED) tmp >>= 1;
if (tmp<0) tmp=0;
else if (tmp>0x10) tmp=0x10;
initiative = (ieDword) (gameTime+tmp*ROUND_SIZE);
}
int Actor::GetToHit(int bonus, ieDword Flags)
{
int tohit = GetStat(IE_TOHIT);
if (ReverseToHit) {
tohit = ATTACKROLL-tohit;
}
tohit += bonus;
if (Flags&WEAPON_LEFTHAND) {
tohit += GetStat(IE_HITBONUSLEFT);
} else {
tohit += GetStat(IE_HITBONUSRIGHT);
}
//get attack style (melee or ranged)
switch(Flags&WEAPON_STYLEMASK) {
case WEAPON_MELEE:
tohit += GetStat(IE_MELEEHIT);
break;
case WEAPON_FIST:
tohit += GetStat(IE_FISTHIT);
break;
case WEAPON_RANGED:
tohit += GetStat(IE_MISSILEHITBONUS);
//add dexterity bonus
break;
}
//add strength bonus if we need
if (Flags&WEAPON_USESTRENGTH) {
tohit += core->GetStrengthBonus(0,GetStat(IE_STR), GetStat(IE_STREXTRA) );
}
return tohit;
}
void Actor::PerformAttack(ieDword gameTime)
{
//apply the modal effect on the beginning of each round
if ((gameTime%ROUND_SIZE==0) && ModalState) {
if (!ModalSpell[0]) {
printMessage("Actor","Modal Spell Effect was not set!\n", YELLOW);
ModalSpell[0]='*';
} else if(ModalSpell[0]!='*') {
core->ApplySpell(ModalSpell, this, this, 0);
}
}
if (!attackcount) {
if (initiative) {
if (InParty) {
core->Autopause(AP_ENDROUND);
}
initiative = 0;
}
return;
}
if (initiative>gameTime) {
return;
}
attackcount--;
if (InternalFlags&IF_STOPATTACK) {
core->GetGame()->OutAttack(GetID());
return;
}
if (!LastTarget) {
StopAttack();
return;
}
//get target
Actor *target = area->GetActorByGlobalID(LastTarget);
if (target && (target->GetStat(IE_STATE_ID)&STATE_DEAD)) {
target = NULL;
}
if (!target) {
LastTarget = 0;
return;
}
//which hand is used
bool leftorright = (bool) (attackcount&1);
WeaponInfo wi;
ITMExtHeader *header;
//can't reach target, zero range shouldn't be allowed
//Don't forget to take size of the opponents into account
if ((GetWeapon(header, &wi, leftorright)*10+(size + target->size)*5)<PersonalDistance(this, target)) {
return;
}
ieDword Flags;
ITMExtHeader *rangedheader = NULL;
ITMExtHeader *hittingheader = header;
int THACOBonus = header->THAC0Bonus ;
int DamageBonus = header->DamageBonus ;
switch(header->AttackType) {
case ITEM_AT_MELEE:
Flags = WEAPON_MELEE;
break;
case ITEM_AT_PROJECTILE: //throwing weapon
Flags = WEAPON_RANGED;
break;
case ITEM_AT_BOW:
if (!GetRangedWeapon(rangedheader, NULL)) {
//out of ammo event
//try to refill
SetStance(IE_ANI_READY);
return;
}
Flags = WEAPON_RANGED ;
//The bow can give some bonuses, but the core attack is made by the arrow.
hittingheader = rangedheader ;
THACOBonus += rangedheader->THAC0Bonus ;
DamageBonus+= rangedheader->DamageBonus ;
break;
default:
//item is unsuitable for fight
SetStance(IE_ANI_READY);
return;
}//melee or ranged
if (leftorright) Flags|=WEAPON_LEFTHAND;
//this flag is set by the bow in case of projectile launcher.
if (header->RechargeFlags&IE_ITEM_USESTRENGTH) Flags|=WEAPON_USESTRENGTH;
//second parameter is left or right hand flag
int tohit = GetToHit(THACOBonus, Flags);
int roll = core->Roll(1,ATTACKROLL,0);
if (roll==1) {
DisplayStringCore(this, VB_CRITMISS, DS_CONSOLE|DS_CONST );
//critical failure
return;
}
//damage type is?
//modify defense with damage type
ieDword damagetype = hittingheader->DamageType;
printMessage("Attack"," ",GREEN);
int damage = core->Roll(hittingheader->DiceThrown, hittingheader->DiceSides, DamageBonus);
printf("Damage %dd%d%+d = %d\n",hittingheader->DiceThrown, hittingheader->DiceSides, DamageBonus, damage);
int damageluck = (int) GetStat(IE_DAMAGELUCK);
if (damage<damageluck) {
damage = damageluck;
}
if (roll>=ATTACKROLL-(int) GetStat(IE_CRITICALHITBONUS) ) {
//critical success
DisplayStringCore(this, VB_CRITHIT, DS_CONSOLE|DS_CONST );
DealDamage (target, damage, damagetype, &wi, true);
return;
}
tohit += roll;
//get target's defense against attack
int defense = target->GetStat(IE_ARMORCLASS);
defense += core->GetDexterityBonus(STAT_DEX_AC, target->GetStat(IE_DEX) );
if (ReverseToHit) {
defense = DEFAULTAC - defense;
}
if (tohit<defense) {
//hit failed
return;
}
DealDamage (target, damage, damagetype, &wi, false);
}
static const int weapon_damagetype[] = {DAMAGE_CRUSHING, DAMAGE_PIERCING,
DAMAGE_CRUSHING, DAMAGE_SLASHING, DAMAGE_MISSILE, DAMAGE_STUNNING};
static EffectRef fx_stoneskin_ref={"StoneSkinModifier",NULL,-1};
static EffectRef fx_stoneskin2_ref={"StoneSkin2Modifier",NULL,-1};
static EffectRef fx_mirrorimage_ref={"MirrorImageModifier",NULL,-1};
static EffectRef fx_aegis_ref={"Aegis",NULL,-1};
void Actor::DealDamage(Actor *target, int damage, int damagetype, WeaponInfo *wi, bool critical)
{
int stoneskins = target->Modified[IE_STONESKINS];
if (stoneskins) {
target->fxqueue.DecreaseParam1OfEffect(fx_stoneskin_ref, 1);
target->fxqueue.DecreaseParam1OfEffect(fx_aegis_ref, 1);
target->Modified[IE_STONESKINS]--;
return;
}
stoneskins = target->Modified[IE_STONESKINSGOLEM];
if (stoneskins) {
target->fxqueue.DecreaseParam1OfEffect(fx_stoneskin2_ref, 1);
target->Modified[IE_STONESKINSGOLEM]--;
return;
}
int mirrorimages = target->Modified[IE_MIRRORIMAGES];
if (mirrorimages) {
if (core->Roll(1,mirrorimages+1,0)!=1) {
target->fxqueue.DecreaseParam1OfEffect(fx_mirrorimage_ref, 1);
target->Modified[IE_MIRRORIMAGES]--;
return;
}
}
if (target->fxqueue.WeaponImmunity(wi->enchantment, wi->itemflags)) {
damage = 0;
}
if (damage<0) damage = 0;
//check casting failure
if (!damage) {
DisplayStringCore(this, VB_TIMMUNE, DS_CONSOLE|DS_CONST );
return;
}
if (critical) {
//a critical surely raises the morale?
NewBase(IE_MORALE, 1, MOD_ADDITIVE);
int head = inventory.GetHeadSlot();
if ((head!=-1) && target->inventory.HasItemInSlot("",(ieDword) head)) {
//critical hit is averted by helmet
core->DisplayConstantString(STR_NO_CRITICAL,0xffffff);
} else {
damage <<=1; //critical damage is always double?
core->timer->SetScreenShake(2,2,2);
}
}
ieDword tmp = target->Modified[IE_MINHITPOINTS];
if (damagetype>5) {
//hack for nonlethal damage (this round only)
target->Modified[IE_MINHITPOINTS]=1;
damagetype = 0;
}
target->Damage(damage, weapon_damagetype[damagetype], this);
target->Modified[IE_MINHITPOINTS]=tmp;
}
//idx could be: 0-6, 16-22, 32-38, 48-54
//the colors are stored in 7 dwords
//maybe it would be simpler to store them in 28 bytes (without using stats?)
void Actor::SetColor( ieDword idx, ieDword grd)
{
ieByte gradient = (ieByte) (grd&255);
ieByte index = (ieByte) (idx&15);
ieByte shift = (ieByte) (idx/16);
ieDword value;
//invalid value, would crash original IE
if (index>6) {
return;
}
if (shift == 15) {
value = 0;
for (index=0;index<4;index++) {
value |= gradient<<=8;
}
for (index=0;index<7;index++) {
Modified[IE_COLORS+index] = value;
}
} else {
//invalid value, would crash original IE
if (shift>3) {
return;
}
shift *= 8;
value = gradient << shift;
value |= Modified[IE_COLORS+index] & ~(255<<shift);
Modified[IE_COLORS+index] = value;
}
}
void Actor::SetColorMod( ieDword location, RGBModifier::Type type, int speed,
unsigned char r, unsigned char g, unsigned char b,
int phase)
{
CharAnimations* ca = GetAnims();
if (!ca) return;
if (location == 0xff) {
ca->GlobalColorMod.type = type;
ca->GlobalColorMod.speed = speed;
ca->GlobalColorMod.rgb.r = r;
ca->GlobalColorMod.rgb.g = g;
ca->GlobalColorMod.rgb.b = b;
ca->GlobalColorMod.rgb.a = 0;
if (phase >= 0)
ca->GlobalColorMod.phase = phase;
else {
if (ca->GlobalColorMod.phase > 2*speed)
ca->GlobalColorMod.phase=0;
}
return;
}
//00xx0yyy-->000xxyyy
if (location&0xffffffc8) return; //invalid location
location = (location &7) | ((location>>1)&0x18);
ca->ColorMods[location].type = type;
ca->ColorMods[location].speed = speed;
ca->ColorMods[location].rgb.r = r;
ca->ColorMods[location].rgb.g = g;
ca->ColorMods[location].rgb.b = b;
ca->ColorMods[location].rgb.a = 0;
if (phase >= 0)
ca->ColorMods[location].phase = phase;
else {
if (ca->ColorMods[location].phase > 2*speed)
ca->ColorMods[location].phase = 0;
}
}
void Actor::SetLeader(Actor *actor, int xoffset, int yoffset)
{
LastFollowed = actor->GetID();
FollowOffset.x = xoffset;
FollowOffset.y = yoffset;
}
//if days == 0, it means full healing
void Actor::Heal(int days)
{
if (days) {
SetBase(IE_HITPOINTS, BaseStats[IE_HITPOINTS]+days*2);
} else {
SetBase(IE_HITPOINTS, BaseStats[IE_MAXHITPOINTS]);
}
}
//this function should handle dual classing and multi classing
void Actor::AddExperience(int exp)
{
SetBase(IE_XP,BaseStats[IE_XP]+exp);
}
void Actor::AddExperience(int type, int level)
{
if (type>=xpbonustypes) {
return;
}
unsigned int l = (unsigned int) (level - 1);
if (l>=(unsigned int) xpbonuslevels) {
l=xpbonuslevels-1;
}
int xp = xpbonus[type*xpbonuslevels+l];
AddExperience(xp);
core->DisplayConstantStringValue(STR_GOTXP, 0xbcefbc, (ieDword) xp);
}
bool Actor::Schedule(ieDword gametime)
{
if (!(InternalFlags&IF_VISIBLE) ) {
return false;
}
//check for schedule
ieDword bit = 1<<((gametime/ROUND_SIZE)%7200/300);
if (appearance & bit) {
return true;
}
return false;
}
void Actor::NewPath()
{
PathTries++;
Point tmp = Destination;
ClearPath();
if (PathTries>10) {
return;
}
Movable::WalkTo(tmp, size );
}
void Actor::SetInTrap(ieDword setreset)
{
InTrap = setreset;
if (setreset) {
InternalFlags |= IF_INTRAP;
} else {
InternalFlags &= ~IF_INTRAP;
}
}
void Actor::SetRunFlags(ieDword flags)
{
InternalFlags &= ~IF_RUNFLAGS;
InternalFlags |= (flags & IF_RUNFLAGS);
}
void Actor::WalkTo(Point &Des, ieDword flags, int MinDistance)
{
PathTries = 0;
if (InternalFlags&IF_REALLYDIED) {
return;
}
SetRunFlags(flags);
// is this true???
if (Des.x==-2 && Des.y==-2) {
Point p((ieWord) Modified[IE_SAVEDXPOS], (ieWord) Modified[IE_SAVEDYPOS] );
Movable::WalkTo(p, MinDistance);
} else {
Movable::WalkTo(Des, MinDistance);
}
}
//there is a similar function in Map for stationary vvcs
void Actor::DrawVideocells(Region &screen, vvcVector &vvcCells, Color &tint)
{
Map* area = GetCurrentArea();
for (unsigned int i = 0; i < vvcCells.size(); i++) {
ScriptedAnimation* vvc = vvcCells[i];
/* we don't allow holes anymore
if (!vvc)
continue;
*/
// actually this is better be drawn by the vvc
bool endReached = vvc->Draw(screen, Pos, tint, area, WantDither(), GetOrientation());
if (endReached) {
delete vvc;
vvcCells.erase(vvcCells.begin()+i);
continue;
}
}
}
void Actor::DrawActorSprite(Region &screen, int cx, int cy, Region& bbox,
SpriteCover*& newsc, Animation** anims,
unsigned char Face, Color& tint)
{
CharAnimations* ca = GetAnims();
int PartCount = ca->GetTotalPartCount();
Video* video = core->GetVideoDriver();
Region vp = video->GetViewport();
// display current frames in the right order
const int* zOrder = ca->GetZOrder(Face);
for (int part = 0; part < PartCount; ++part) {
int partnum = part;
if (zOrder) partnum = zOrder[part];
Animation* anim = anims[partnum];
Sprite2D* nextFrame = 0;
if (anim)
nextFrame = anim->GetFrame(anim->GetCurrentFrame());
if (nextFrame && bbox.InsideRegion( vp ) ) {
if (!newsc || !newsc->Covers(cx, cy, nextFrame->XPos, nextFrame->YPos, nextFrame->Width, nextFrame->Height)) {
// the first anim contains the animarea for
// the entire multi-part animation
newsc = area->BuildSpriteCover(cx,
cy, -anims[0]->animArea.x,
-anims[0]->animArea.y,
anims[0]->animArea.w,
anims[0]->animArea.h, WantDither() );
}
assert(newsc->Covers(cx, cy, nextFrame->XPos, nextFrame->YPos, nextFrame->Width, nextFrame->Height));
unsigned int flags = TranslucentShadows ? BLIT_TRANSSHADOW : 0;
if (!ca->lockPalette) flags|=BLIT_TINTED;
video->BlitGameSprite( nextFrame, cx + screen.x, cy + screen.y,
flags, tint, newsc, ca->GetPartPalette(partnum), &screen);
}
}
}
static const int OrientdX[16] = { 0, -4, -7, -9, -10, -9, -7, -4, 0, 4, 7, 9, 10, 9, 7, 4 };
static const int OrientdY[16] = { 10, 9, 7, 4, 0, -4, -7, -9, -10, -9, -7, -4, 0, 4, 7, 9 };
static const unsigned int MirrorImageLocation[8] = { 4, 12, 8, 0, 6, 14, 10, 2 };
static const unsigned int MirrorImageZOrder[8] = { 2, 4, 6, 0, 1, 7, 5, 3 };
void Actor::Draw(Region &screen)
{
Map* area = GetCurrentArea();
int cx = Pos.x;
int cy = Pos.y;
int explored = Modified[IE_DONOTJUMP]&DNJ_UNHINDERED;
//check the deactivation condition only if needed
//this fixes dead actors disappearing from fog of war (they should be permanently visible)
if ((!area->IsVisible( Pos, explored) || (InternalFlags&IF_REALLYDIED) ) && (InternalFlags&IF_ACTIVE) ) {
// if ((!area->IsVisible( Pos, explored) || (InternalFlags&IF_JUSTDIED) ) && (InternalFlags&IF_ACTIVE) ) {
//finding an excuse why we don't hybernate the actor
if (Modified[IE_ENABLEOFFSCREENAI])
return;
if (LastTarget) //currently attacking someone
return;
if (CurrentAction)
return;
if (GetNextStep())
return;
if (GetNextAction())
return;
if (GetWait()) //would never stop waiting
return;
//turning actor inactive if there is no action next turn
InternalFlags|=IF_IDLE;
}
if (InTrap) {
area->ClearTrap(this, InTrap-1);
}
//visual feedback
CharAnimations* ca = GetAnims();
if (!ca)
return;
//explored or visibilitymap (bird animations are visible in fog)
//0 means opaque
int NoCircle = Modified[IE_NOCIRCLE];
int Trans = Modified[IE_TRANSLUCENT];
if (Trans>255) {
Trans=255;
}
//iwd has this flag saved in the creature
if (Modified[IE_AVATARREMOVAL]) {
Trans = 255;
NoCircle = 1;
}
int Frozen = Immobile();
int State = Modified[IE_STATE_ID];
if (State&STATE_DEAD) {
NoCircle = 1;
}
if (State&STATE_STILL) {
Frozen = 1;
}
//adjust invisibility for enemies
if (Modified[IE_EA]>EA_GOODCUTOFF) {
if (State&STATE_INVISIBLE) {
Trans = 256;
}
}
//can't move this, because there is permanent blur state where
//there is no effect (just state bit)
if ((State&STATE_BLUR) && Trans < 128) {
Trans = 128;
}
Color tint = area->LightMap->GetPixel( cx / 16, cy / 12);
tint.a = (ieByte) (255-Trans);
//don't use cy for area map access beyond this point
cy-=area->HeightMap->GetPixelIndex( cx / 16, cy / 12);
//draw videocells under the actor
DrawVideocells(screen, vvcShields, tint);
Video* video = core->GetVideoDriver();
Region vp = video->GetViewport();
if (NoCircle==0) {
DrawCircle(vp);
DrawTargetPoint(vp);
}
unsigned char StanceID = GetStance();
unsigned char Face = GetNextFace();
Animation** anims = ca->GetAnimation( StanceID, Face );
if (anims) {
// update bounding box and such
int PartCount = ca->GetTotalPartCount();
Sprite2D* nextFrame = 0;
nextFrame = anims[0]->GetFrame(anims[0]->GetCurrentFrame());
//make actor unselectable and unselected when it is not moving
//dead, petriefied, frozen, paralysed etc.
if (Frozen) {
if (Selected!=0x80) {
Selected = 0x80;
core->GetGame()->SelectActor(this, false, SELECT_NORMAL);
}
}
if (nextFrame && lastFrame != nextFrame) {
Region newBBox;
if (PartCount == 1) {
newBBox.x = cx - nextFrame->XPos;
newBBox.w = nextFrame->Width;
newBBox.y = cy - nextFrame->YPos;
newBBox.h = nextFrame->Height;
} else {
// FIXME: currently using the animarea instead
// of the real bounding box of this (multi-part) frame.
// Shouldn't matter much, though. (wjp)
newBBox.x = cx + anims[0]->animArea.x;
newBBox.y = cy + anims[0]->animArea.y;
newBBox.w = anims[0]->animArea.w;
newBBox.h = anims[0]->animArea.h;
}
lastFrame = nextFrame;
SetBBox( newBBox );
}
// Drawing the actor:
// * mirror images:
// Drawn without transparency, unless fully invisible.
// Order: W, E, N, S, NW, SE, NE, SW
// Uses extraCovers 3-10
// * blurred copies (3 of them)
// Drawn with transparency.
// distance between copies depends on IE_MOVEMENTRATE
// TODO: actually, the direction is the real movement direction,
// not the (rounded) direction given Face
// Uses extraCovers 0-2
// * actor itself
// Uses main spritecover
//
//comments by Avenger:
// currently we don't have a real direction, but the orientation field
// could be used with higher granularity. When we need the face value
// it could be divided so it will become a 0-15 number.
//
SpriteCover *sc = 0, *newsc = 0;
int blurx = cx;
int blury = cy;
int blurdx = (OrientdX[Face]*(int)Modified[IE_MOVEMENTRATE])/20;
int blurdy = (OrientdY[Face]*(int)Modified[IE_MOVEMENTRATE])/20;
Color mirrortint = tint;
//mirror images are also half transparent when invis
//if (mirrortint.a > 0) mirrortint.a = 255;
int i;
// mirror images behind the actor
for (i = 0; i < 4; ++i) {
unsigned int m = MirrorImageZOrder[i];
if (m < Modified[IE_MIRRORIMAGES]) {
Region sbbox = BBox;
int dir = MirrorImageLocation[m];
int icx = cx + 3*OrientdX[dir];
int icy = cy + 3*OrientdY[dir];
Point iPos(icx, icy);
if (area->GetBlocked(iPos) & (PATH_MAP_PASSABLE|PATH_MAP_ACTOR)) {
sbbox.x += 3*OrientdX[dir];
sbbox.y += 3*OrientdY[dir];
newsc = sc = extraCovers[3+m];
DrawActorSprite(screen, icx, icy, sbbox, newsc,
anims, Face, mirrortint);
if (newsc != sc) {
delete sc;
extraCovers[3+m] = newsc;
}
}
} else {
delete extraCovers[3+m];
extraCovers[3+m] = NULL;
}
}
// blur sprites behind the actor
if (State & STATE_BLUR) {
if (Face < 4 || Face >= 12) {
Region sbbox = BBox;
sbbox.x -= 4*blurdx; sbbox.y -= 4*blurdy;
blurx -= 4*blurdx; blury -= 4*blurdy;
for (i = 0; i < 3; ++i) {
sbbox.x += blurdx; sbbox.y += blurdy;
blurx += blurdx; blury += blurdy;
newsc = sc = extraCovers[i];
DrawActorSprite(screen, blurx, blury, sbbox, newsc,
anims, Face, tint);
if (newsc != sc) {
delete sc;
extraCovers[i] = newsc;
}
}
}
}
// actor itself
newsc = sc = GetSpriteCover();
DrawActorSprite(screen, cx, cy, BBox, newsc, anims, Face, tint);
if (newsc != sc) SetSpriteCover(newsc);
// blur sprites in front of the actor
if (State & STATE_BLUR) {
if (Face >= 4 && Face < 12) {
Region sbbox = BBox;
for (i = 0; i < 3; ++i) {
sbbox.x -= blurdx; sbbox.y -= blurdy;
blurx -= blurdx; blury -= blurdy;
newsc = sc = extraCovers[i];
DrawActorSprite(screen, blurx, blury, sbbox, newsc,
anims, Face, tint);
if (newsc != sc) {
delete sc;
extraCovers[i] = newsc;
}
}
}
}
// mirror images in front of the actor
for (i = 4; i < 8; ++i) {
unsigned int m = MirrorImageZOrder[i];
if (m < Modified[IE_MIRRORIMAGES]) {
Region sbbox = BBox;
int dir = MirrorImageLocation[m];
int icx = cx + 3*OrientdX[dir];
int icy = cy + 3*OrientdY[dir];
Point iPos(icx, icy);
if (area->GetBlocked(iPos) & (PATH_MAP_PASSABLE|PATH_MAP_ACTOR)) {
sbbox.x += 3*OrientdX[dir];
sbbox.y += 3*OrientdY[dir];
newsc = sc = extraCovers[3+m];
DrawActorSprite(screen, icx, icy, sbbox, newsc,
anims, Face, mirrortint);
if (newsc != sc) {
delete sc;
extraCovers[3+m] = newsc;
}
}
} else {
delete extraCovers[3+m];
extraCovers[3+m] = NULL;
}
}
// advance animations one frame (in sync)
if (Frozen)
anims[0]->LastFrame();
else
anims[0]->NextFrame();
for (int part = 1; part < PartCount; ++part) {
if (anims[part])
anims[part]->GetSyncedNextFrame(anims[0]);
}
if (anims[0]->endReached) {
if (HandleActorStance() ) {
anims[0]->endReached = false;
}
}
ca->PulseRGBModifiers();
}
//draw videocells over the actor
DrawVideocells(screen, vvcOverlays, tint);
//text feedback
DrawOverheadText(screen);
}
/* Handling automatic stance changes */
bool Actor::HandleActorStance()
{
CharAnimations* ca = GetAnims();
int StanceID = GetStance();
if (ca->autoSwitchOnEnd) {
int nextstance = ca->nextStanceID;
/*
if (nextstance == IE_ANI_READY) {
if (!core->GetGame()->CombatCounter) {
nextstance = IE_ANI_AWAKE;
}
}
*/
SetStance( nextstance );
ca->autoSwitchOnEnd = false;
return true;
}
int x = rand()%1000;
if ((StanceID==IE_ANI_AWAKE) && !x ) {
SetStance( IE_ANI_HEAD_TURN );
return true;
}
if ((StanceID==IE_ANI_READY) && !GetNextAction()) {
SetStance( IE_ANI_AWAKE );
return true;
}
if (StanceID == IE_ANI_ATTACK || StanceID == IE_ANI_ATTACK_JAB ||
StanceID == IE_ANI_ATTACK_SLASH || StanceID == IE_ANI_ATTACK_BACKSLASH ||
StanceID == IE_ANI_SHOOT)
{
SetStance( AttackStance );
return true;
}
return false;
}
void Actor::GetSoundFrom2DA(ieResRef Sound, unsigned int index)
{
if (!anims) return;
AutoTable tab(anims->ResRef);
if (!tab)
return;
switch (index) {
case VB_ATTACK:
index = 0;
break;
case VB_DAMAGE:
index = 8;
break;
case VB_DIE:
index = 10;
break;
case VB_SELECT:
index = 36+rand()%4;
break;
}
strnlwrcpy(Sound, tab->QueryField (index, 0), 8);
}
void Actor::GetSoundFromINI(ieResRef Sound, unsigned int index)
{
const char *resource = "";
char section[12];
unsigned int animid=BaseStats[IE_ANIMATION_ID];
if(core->HasFeature(GF_ONE_BYTE_ANIMID)) {
animid&=0xff;
}
snprintf(section,10,"%d", animid);
switch(index) {
case VB_ATTACK:
resource = core->GetResDataINI()->GetKeyAsString(section, "at1sound","");
break;
case VB_DAMAGE:
resource = core->GetResDataINI()->GetKeyAsString(section, "hitsound","");
break;
case VB_DIE:
resource = core->GetResDataINI()->GetKeyAsString(section, "dfbsound","");
break;
case VB_SELECT:
break;
}
int count = CountElements(resource,',');
if (count<=0) return;
count = core->Roll(1,count,-1);
while(count--) {
while(*resource && *resource!=',') resource++;
if (*resource==',') resource++;
}
strncpy(Sound, resource, 8);
for(count=0;count<8 && Sound[count]!=',';count++) {};
Sound[count]=0;
}
void Actor::ResolveStringConstant(ieResRef Sound, unsigned int index)
{
//resolving soundset (bg1/bg2 style)
if (PCStats && PCStats->SoundSet[0]&& csound[index]) {
snprintf(Sound, sizeof(ieResRef), "%s%c", PCStats->SoundSet, csound[index]);
return;
}
Sound[0]=0;
if (core->HasFeature(GF_RESDATA_INI)) {
GetSoundFromINI(Sound, index);
} else {
GetSoundFrom2DA(Sound, index);
}
}
void Actor::SetActionButtonRow(ActionButtonRow &ar)
{
for(int i=0;i<MAX_QSLOTS;i++) {
ieByte tmp = ar[i+3];
if (QslotTranslation) {
tmp=gemrb2iwd[tmp];
}
PCStats->QSlots[i]=tmp;
}
}
//the first 3 buttons are untouched by this function
void Actor::GetActionButtonRow(ActionButtonRow &ar)
{
if (PCStats->QSlots[0]==0xff) {
InitButtons(GetStat(IE_CLASS));
}
for(int i=0;i<GUIBT_COUNT-3;i++) {
ieByte tmp=PCStats->QSlots[i];
if (QslotTranslation) {
if (tmp>=90) { //quick weapons
tmp=16+tmp%10;
} else if (tmp>=80) { //quick items
tmp=9+tmp%10;
} else if (tmp>=70) { //quick spells
tmp=3+tmp%10;
} else {
tmp=iwd2gemrb[tmp];
}
}
ar[i+3]=tmp;
}
memcpy(ar,DefaultButtons,3*sizeof(ieByte) );
}
void Actor::SetSoundFolder(const char *soundset)
{
if (core->HasFeature(GF_SOUNDFOLDERS)) {
char filepath[_MAX_PATH];
strnlwrcpy(PCStats->SoundFolder, soundset, 32);
PathJoin(filepath,core->GamePath,"sounds",PCStats->SoundFolder,0);
char *fp = FindInDir(filepath, "?????01", true);
if (fp) {
fp[5] = 0;
} else {
fp = FindInDir(filepath, "????01", true);
if (fp) {
fp[4] = 0;
}
}
if (fp) {
strnlwrcpy(PCStats->SoundSet, fp, 6);
free(fp);
}
} else {
strnlwrcpy(PCStats->SoundSet, soundset, 6);
PCStats->SoundFolder[0]=0;
}
}
bool Actor::HasVVCCell(const ieResRef resource)
{
int j = true;
vvcVector *vvcCells=&vvcShields;
retry:
size_t i=vvcCells->size();
while (i--) {
ScriptedAnimation *vvc = (*vvcCells)[i];
if (vvc == NULL) {
continue;
}
if ( strnicmp(vvc->ResName, resource, 8) == 0) {
return true;
}
}
vvcCells=&vvcOverlays;
if (j) { j = false; goto retry; }
return false;
}
void Actor::RemoveVVCell(const ieResRef resource, bool graceful)
{
bool j = true;
vvcVector *vvcCells=&vvcShields;
retry:
size_t i=vvcCells->size();
while (i--) {
ScriptedAnimation *vvc = (*vvcCells)[i];
if (vvc == NULL) {
continue;
}
if ( strnicmp(vvc->ResName, resource, 8) == 0) {
if (graceful) {
vvc->SetPhase(P_RELEASE);
} else {
delete vvc;
vvcCells->erase(vvcCells->begin()+i);
}
}
}
vvcCells=&vvcOverlays;
if (j) { j = false; goto retry; }
}
//this is a faster version of hasvvccell, because it knows where to look
//for the overlay, it also returns the vvc for further manipulation
//use this for the seven eyes overlay
ScriptedAnimation *Actor::FindOverlay(int index)
{
vvcVector *vvcCells;
if (index>31) return NULL;
if (hc_locations&(1<<index)) vvcCells=&vvcShields;
else vvcCells=&vvcOverlays;
const char *resRef = hc_overlays[index];
size_t i=vvcCells->size();
while (i--) {
ScriptedAnimation *vvc = (*vvcCells)[i];
if (vvc == NULL) {
continue;
}
if ( strnicmp(vvc->ResName, resRef, 8) == 0) {
return vvc;
}
}
return NULL;
}
void Actor::AddVVCell(ScriptedAnimation* vvc)
{
vvcVector *vvcCells;
//if the vvc was not created, don't try to add it
if (!vvc) {
return;
}
if (vvc->ZPos<0) {
vvcCells=&vvcShields;
} else {
vvcCells=&vvcOverlays;
}
size_t i=vvcCells->size();
while (i--) {
if ((*vvcCells)[i] == NULL) {
(*vvcCells)[i] = vvc;
return;
}
}
vvcCells->push_back( vvc );
}
//returns restored spell level
int Actor::RestoreSpellLevel(ieDword maxlevel, ieDword type)
{
int typemask;
switch (type) {
case 0: //allow only mage
typemask = ~2;
break;
case 1: //allow only cleric
typemask = ~1;
break;
default:
//allow any (including innates)
typemask = ~0;
}
for (int i=maxlevel;i>0;i--) {
CREMemorizedSpell *cms = spellbook.FindUnchargedSpell(typemask, maxlevel);
if (cms) {
spellbook.ChargeSpell(cms);
return i;
}
}
return 0;
}
//replenishes spells, cures fatigue
void Actor::Rest(int hours)
{
if (hours) {
//do remove effects
int remaining = hours*10;
//removes hours*10 fatigue points
NewStat (IE_FATIGUE, -remaining, MOD_ADDITIVE);
NewStat (IE_INTOXICATION, -remaining, MOD_ADDITIVE);
//restore hours*10 spell levels
//rememorization starts with the lower spell levels?
inventory.ChargeAllItems (remaining);
for (int level = 1; level<16; level++) {
if (level<remaining) {
break;
}
while (remaining>0) {
remaining -= RestoreSpellLevel(level,0);
}
}
} else {
SetBase (IE_FATIGUE, 0);
SetBase (IE_INTOXICATION, 0);
inventory.ChargeAllItems (0);
spellbook.ChargeAllSpells ();
}
}
//returns the actual slot from the quickslot
int Actor::GetQuickSlot(int slot)
{
assert(slot<8);
if (inventory.HasItemInSlot("",inventory.GetMagicSlot())) {
return inventory.GetMagicSlot();
}
if (!PCStats) {
return slot+inventory.GetWeaponSlot();
}
return PCStats->QuickWeaponSlots[slot];
}
//marks the quickslot as equipped
int Actor::SetEquippedQuickSlot(int slot)
{
//creatures and such
if (PCStats) {
slot = PCStats->QuickWeaponSlots[slot]-inventory.GetWeaponSlot();
}
if (inventory.SetEquippedSlot(slot)) {
return 0;
}
return STR_MAGICWEAPON;
}
//if target is a non living scriptable, then we simply shoot for its position
//the fx should get a NULL target, and handle itself by using the position
//(shouldn't crash when target is NULL)
bool Actor::UseItemPoint(ieDword slot, ieDword header, Point &target, bool silent)
{
CREItem *item = inventory.GetSlotItem(slot);
if (!item)
return false;
Item *itm = gamedata->GetItem(item->ItemResRef);
if (!itm) return false; //quick item slot contains invalid item resref
//item is depleted for today
if(itm->UseCharge(item->Usages, header, false)==CHG_DAY) {
return false;
}
Projectile *pro = itm->GetProjectile(slot, header);
ChargeItem(slot, header, item, itm, silent);
gamedata->FreeItem(itm,item->ItemResRef, false);
if (pro) {
pro->SetCaster(globalID);
GetCurrentArea()->AddProjectile(pro, Pos, target);
return true;
}
return false;
}
bool Actor::UseItem(ieDword slot, ieDword header, Scriptable* target, bool silent)
{
if (target->Type!=ST_ACTOR) {
return UseItemPoint(slot, header, target->Pos, silent);
}
Actor *tar = (Actor *) target;
CREItem *item = inventory.GetSlotItem(slot);
if (!item)
return false;
Item *itm = gamedata->GetItem(item->ItemResRef);
if (!itm) return false; //quick item slot contains invalid item resref
//item is depleted for today
if(itm->UseCharge(item->Usages, header, false)==CHG_DAY) {
return false;
}
Projectile *pro = itm->GetProjectile(slot, header);
ChargeItem(slot, header, item, itm, silent);
gamedata->FreeItem(itm,item->ItemResRef, false);
if (pro) {
pro->SetCaster(globalID);
GetCurrentArea()->AddProjectile(pro, Pos, tar->globalID);
return true;
}
return false;
}
void Actor::ChargeItem(ieDword slot, ieDword header, CREItem *item, Item *itm, bool silent)
{
if (!itm) {
item = inventory.GetSlotItem(slot);
if (!item)
return;
itm = gamedata->GetItem(item->ItemResRef);
}
if (!itm) return; //quick item slot contains invalid item resref
if (InParty) {
core->SetEventFlag( EF_ACTION );
}
if (!silent) {
ieByte stance = AttackStance;
for (int i=0;i<animcount;i++) {
if ( strnicmp(item->ItemResRef, itemanim[i].itemname, 8) == 0) {
stance = itemanim[i].animation;
}
}
if (stance!=0xff) {
SetStance(stance);
//play only one cycle of animations
anims->nextStanceID=IE_ANI_READY;
anims->autoSwitchOnEnd=true;
}
}
switch(itm->UseCharge(item->Usages, header, true)) {
case CHG_DAY:
break;
case CHG_NOSOUND: //remove item
inventory.BreakItemSlot(slot);
break;
case CHG_BREAK: //both
if (!silent) {
core->PlaySound(DS_ITEM_GONE);
}
inventory.BreakItemSlot(slot);
break;
default: //don't do anything
break;
}
}
int Actor::IsReverseToHit()
{
return ReverseToHit;
}
void Actor::InitButtons(ieDword cls)
{
if (!PCStats) {
return;
}
ActionButtonRow myrow;
if ((int) cls >= classcount) {
memcpy(&myrow, &DefaultButtons, sizeof(ActionButtonRow));
} else {
memcpy(&myrow, GUIBTDefaults+cls, sizeof(ActionButtonRow));
}
SetActionButtonRow(myrow);
}
void Actor::SetFeat(unsigned int feat, int mode)
{
if (feat>=MAX_FEATS) {
return;
}
ieDword mask = 1<<(feat&31);
ieDword idx = feat>>5;
switch (mode) {
case BM_SET: case BM_OR:
BaseStats[IE_FEATS1+idx]|=mask;
break;
case BM_NAND:
BaseStats[IE_FEATS1+idx]&=~mask;
break;
case BM_XOR:
BaseStats[IE_FEATS1+idx]^=mask;
break;
}
}
void Actor::SetUsedWeapon(const char* AnimationType, ieWord* MeleeAnimation, int wt)
{
memcpy(WeaponRef, AnimationType, sizeof(WeaponRef) );
if (wt != -1) WeaponType = wt;
if (!anims)
return;
anims->SetWeaponRef(AnimationType);
anims->SetWeaponType(WeaponType);
SetAttackMoveChances(MeleeAnimation);
if (InParty) {
//update the paperdoll weapon animation
core->SetEventFlag(EF_UPDATEANIM);
}
ITMExtHeader *header ;
GetWeapon(header, NULL) ;
if(header && header->AttackType == ITEM_AT_BOW) {
AttackStance = IE_ANI_SHOOT ;
return ;
}
AttackStance = IE_ANI_ATTACK;
}
void Actor::SetUsedShield(const char* AnimationType, int wt)
{
memcpy(ShieldRef, AnimationType, sizeof(ShieldRef) );
if (wt != -1) WeaponType = wt;
if (AnimationType[0] == ' ' || AnimationType[0] == 0)
if (WeaponType == IE_ANI_WEAPON_2W)
WeaponType = IE_ANI_WEAPON_1H;
if (!anims)
return;
anims->SetOffhandRef(AnimationType);
anims->SetWeaponType(WeaponType);
if (InParty) {
//update the paperdoll weapon animation
core->SetEventFlag(EF_UPDATEANIM);
}
}
void Actor::SetUsedHelmet(const char* AnimationType)
{
memcpy(HelmetRef, AnimationType, sizeof(HelmetRef) );
if (!anims)
return;
anims->SetHelmetRef(AnimationType);
if (InParty) {
//update the paperdoll weapon animation
core->SetEventFlag(EF_UPDATEANIM);
}
}
//set up stuff here, like attack number, turn undead level
//and similar derived stats that change with level
void Actor::SetupFist()
{
int slot = core->QuerySlot( 0 );
assert (core->QuerySlotEffects(slot)==SLOT_EFFECT_FIST);
int row = GetBase(fiststat);
int col = GetXPLevel(false);
if (FistRows<0) {
FistRows=0;
AutoTable fist("fistweap");
if (fist) {
//default value
strnlwrcpy( DefaultFist, fist->QueryField( (unsigned int) -1), 8);
FistRows = fist->GetRowCount();
fistres = new FistResType[FistRows];
for (int i=0;i<FistRows;i++) {
int maxcol = fist->GetColumnCount(i)-1;
for (int cols = 0;cols<MAX_LEVEL;cols++) {
strnlwrcpy( fistres[i][cols], fist->QueryField( i, cols>maxcol?maxcol:cols ), 8);
}
*(int *) fistres[i] = atoi(fist->GetRowName( i));
}
}
}
if (col>MAX_LEVEL) col=MAX_LEVEL;
if (col<1) col=1;
const char *ItemResRef = DefaultFist;
for (int i = 0;i<FistRows;i++) {
if (*(int *) fistres[i] == row) {
ItemResRef = fistres[i][col];
}
}
inventory.SetSlotItemRes(ItemResRef, slot);
}
static ieDword ResolveTableValue(const char *resref, ieDword stat, ieDword mcol, ieDword vcol) {
long ret = 0;
//don't close this table, it can mess with the guiscripts
int table = gamedata->LoadTable(resref);
TableMgr *tm = gamedata->GetTable(table);
if (tm) {
unsigned int row;
if (mcol == 0xff) {
row = stat;
} else {
row = tm->FindTableValue(mcol, stat);
if (row==0xffffffff) {
return 0;
}
}
if (valid_number(tm->QueryField(row, vcol), ret)) {
return (ieDword) ret;
}
}
return 0;
}
int Actor::CheckUsability(Item *item) const
{
ieDword itembits[2]={item->UsabilityBitmask, item->KitUsability};
for (int i=0;i<usecount;i++) {
ieDword itemvalue = itembits[itemuse[i].which];
ieDword stat = GetStat(itemuse[i].stat);
ieDword mcol = itemuse[i].mcol;
//here comes an unavoidable hackety hack because of bg2
//feel free to solve this logic without a goto
if (itemuse[i].stat==IE_KIT) {
if ((stat&BG2_KITMASK)==KIT_BARBARIAN) {
stat = (stat>>16)&0xfff;
if (stat) {
goto resolve_stat;
} else {
stat = KIT_BASECLASS;
}
}
} else {
resolve_stat:
stat = ResolveTableValue(itemuse[i].table, stat, mcol, itemuse[i].vcol);
}
if (stat&itemvalue) {
return STR_CANNOT_USE_ITEM;
}
}
return 0;
}
//checks usability only
int Actor::Unusable(Item *item) const
{
if (!GetStat(IE_CANUSEANYITEM)) {
return CheckUsability(item);
}
if (!CheckAbilities) {
return 0;
}
if (item->MinLevel>GetXPLevel(true)) {
return 1;
}
if (item->MinStrength>GetStat(IE_STR)) {
return 1;
}
if (item->MinStrength==18) {
if (GetStat(IE_STR==18)) {
if (item->MinStrengthBonus>GetStat(IE_STREXTRA)) {
return 1;
}
}
}
if (item->MinIntelligence>GetStat(IE_INT)) {
return 1;
}
if (item->MinDexterity>GetStat(IE_DEX)) {
return 1;
}
if (item->MinWisdom>GetStat(IE_WIS)) {
return 1;
}
if (item->MinConstitution>GetStat(IE_CON)) {
return 1;
}
if (item->MinCharisma>GetStat(IE_CHR)) {
return 1;
}
//note, weapon proficiencies shouldn't be checked here
//missing proficiency causes only attack penalty
return 0;
}
//full palette will be shaded in gradient color
void Actor::SetGradient(ieDword gradient)
{
gradient |= (gradient <<16);
gradient |= (gradient <<8);
for(int i=0;i<7;i++) {
Modified[IE_COLORS+i]=gradient;
}
}
//sets one bit of the sanctuary stat (used for overlays)
void Actor::SetOverlay(unsigned int overlay)
{
if (overlay>=32) return;
Modified[IE_SANCTUARY]|=1<<overlay;
}
//returns true if spell state is already set or illegal
bool Actor::SetSpellState(unsigned int spellstate)
{
if (spellstate>=192) return true;
unsigned int pos = IE_SPLSTATE_ID1+(spellstate>>5);
unsigned int bit = 1<<(spellstate&31);
if (Modified[pos]&bit) return true;
Modified[pos]|=bit;
return false;
}
//returns true if spell state is already set
bool Actor::HasSpellState(unsigned int spellstate)
{
if (spellstate>=192) return false;
unsigned int pos = IE_SPLSTATE_ID1+(spellstate>>5);
unsigned int bit = 1<<(spellstate&31);
if (Modified[pos]&bit) return true;
return false;
}
//returns the numeric value of a feat, different from HasFeat
//for multiple feats
int Actor::GetFeat(unsigned int feat) const
{
if (feat>=MAX_FEATS) {
return -1;
}
if (Modified[IE_FEATS1+(feat>>5)]&(1<<(feat&31)) ) {
//return the numeric stat value, instead of the boolean
if (featstats[feat]) {
return Modified[featstats[feat]];
}
return 1;
}
return 0;
}
//returns true if the feat exists
bool Actor::HasFeat(unsigned int featindex) const
{
if (featindex>=MAX_FEATS) return false;
unsigned int pos = IE_FEATS1+(featindex>>5);
unsigned int bit = 1<<(featindex&31);
if (Modified[pos]&bit) return true;
return false;
}
ieDword Actor::ImmuneToProjectile(ieDword projectile) const
{
int idx;
idx = projectile/32;
if (idx>ProjectileSize) {
return 0;
}
return projectileImmunity[idx]&(1<<(projectile&31));
}
void Actor::AddProjectileImmunity(ieDword projectile)
{
projectileImmunity[projectile/32]|=1<<(projectile&31);
}
//2nd edition rules
void Actor::CreateDerivedStatsBG()
{
int i;
int turnundeadlevel = 0;
int levels[3]={BaseStats[IE_LEVEL],BaseStats[IE_LEVEL2],BaseStats[IE_LEVEL3]};
int classid = BaseStats[IE_CLASS];
int slot = 0;
//this works only for PC classes
if (classid<32) {
for (i=0;i<11;i++) {
//this is not good for multiclassing yet
if ((1<<classid)&isclass[i]) {
BaseStats[levelslots[i]]=levels[slot];
slot++;
}
}
//recalculate all level based changes
pcf_level(this,0,0);
if (isclass[ISCLERIC]&(1<<classid)) {
turnundeadlevel = BaseStats[IE_LEVELCLERIC]+1-turnlevels[classid];
if (turnundeadlevel<0) turnundeadlevel=0;
}
else if (isclass[ISPALADIN]&(1<<classid)) {
turnundeadlevel = BaseStats[IE_LEVELPALADIN]+1-turnlevels[classid];
if (turnundeadlevel<0) turnundeadlevel=0;
} else {
turnundeadlevel = 0;
}
}
ieDword backstabdamagemultiplier=BaseStats[IE_LEVELTHIEF];
if (backstabdamagemultiplier) {
backstabdamagemultiplier=backstabdamagemultiplier+3/4;
if (backstabdamagemultiplier>7) backstabdamagemultiplier=7;
}
BaseStats[IE_TURNUNDEADLEVEL]=turnundeadlevel;
BaseStats[IE_BACKSTABDAMAGEMULTIPLIER]=backstabdamagemultiplier;
BaseStats[IE_LAYONHANDSAMOUNT]=BaseStats[IE_LEVELPALADIN]*2;
}
//3rd edition rules
void Actor::CreateDerivedStatsIWD2()
{
int i;
int turnundeadlevel = 0;
ieDword backstabdamagemultiplier = (BaseStats[IE_LEVELTHIEF]+1)/2;
int layonhandsamount = (int) BaseStats[IE_LEVELPALADIN];
if (layonhandsamount) {
layonhandsamount *= BaseStats[IE_CHR]/2-5;
if (layonhandsamount<1) layonhandsamount = 1;
}
for (i=0;i<11;i++) {
int tmp;
if (turnlevels[i+1]) {
tmp = BaseStats[IE_LEVELBARBARIAN+i]+1-turnlevels[i+1];
if (tmp<0) tmp=0;
if (tmp>turnundeadlevel) turnundeadlevel=tmp;
}
}
BaseStats[IE_TURNUNDEADLEVEL]=turnundeadlevel;
BaseStats[IE_BACKSTABDAMAGEMULTIPLIER]=backstabdamagemultiplier;
BaseStats[IE_LAYONHANDSAMOUNT]=(ieDword) layonhandsamount;
}
void Actor::CreateDerivedStats()
{
if (core->HasFeature(GF_IWD2_SCRIPTNAME)) {
CreateDerivedStatsIWD2();
} else {
CreateDerivedStatsBG();
}
AutoTable tm("classes");
if (tm) {
// currently we need only the MULTI value
strcpy(multiclass, tm->QueryField(tm->FindTableValue(5, BaseStats[IE_CLASS]), 4));
}
}
/* Checks if the actor is multiclassed (the MULTI column is positive) */
bool Actor::IsMultiClassed() const
{
long multi2;
return (valid_number(multiclass, multi2) && multi2 > 0);
}
/* Checks if the actor is dualclassed */
bool Actor::IsDualClassed() const
{
return (Modified[IE_MC_FLAGS] & MC_WAS_ANY) > 0;
}
Actor *Actor::CopySelf() const
{
Actor *newActor = new Actor();
newActor->SetText(GetName(0),0);
newActor->SetText(GetName(1),1);
memcpy(newActor->BaseStats, BaseStats, sizeof(BaseStats) );
//IF_INITIALIZED shouldn't be set here, yet
newActor->SetMCFlag(MC_EXPORTABLE, BM_NAND);
//the creature importer does this too
memcpy(newActor->Modified,newActor->BaseStats, sizeof(Modified) );
//copy the running effects
EffectQueue *newFXQueue = fxqueue.CopySelf();
area->AddActor(newActor);
newActor->Pos.x = Pos.x;
newActor->Pos.y = Pos.y;
newActor->Destination.x = Destination.x;
newActor->Destination.y = Destination.y;
newActor->SetOrientation(GetOrientation(),0);
//and apply them
newActor->RefreshEffects(newFXQueue);
return newActor;
}

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks