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
|
/* ScummVM - Scumm Interpreter
* Copyright (C) 2004-2005 The ScummVM project
*
* The ReInherit Engine is (C)2000-2003 by Daniel Balsom.
*
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Header$
*
*/
#include "saga/saga.h"
#include "saga/gfx.h"
#include "saga/console.h"
#include "saga/rscfile_mod.h"
#include "saga/script.h"
#include "saga/sndres.h"
#include "saga/sprite.h"
#include "saga/font.h"
#include "saga/sound.h"
#include "saga/scene.h"
#include "saga/isomap.h"
#include "saga/actor.h"
#include "saga/itedata.h"
#include "saga/stream.h"
#include "saga/interface.h"
#include "saga/events.h"
#include "saga/objectmap.h"
#include "common/config-manager.h"
namespace Saga {
static int commonObjectCompare(const CommonObjectDataPointer& obj1, const CommonObjectDataPointer& obj2) {
int p1 = obj1->location.y - obj1->location.z;
int p2 = obj2->location.y - obj2->location.z;
if (p1 == p2)
return 0;
if (p1 < p2)
return -1;
return 1;
}
static int tileCommonObjectCompare(const CommonObjectDataPointer& obj1, const CommonObjectDataPointer& obj2) {
int p1 = -obj1->location.u() - obj1->location.v() - obj1->location.z;
int p2 = -obj2->location.u() - obj2->location.v() - obj2->location.z;
//TODO: for kObjNotFlat obj Height*3 of sprite should be added to p1 and p2
//if (validObjId(obj1->id)) {
if (p1 == p2)
return 0;
if (p1 < p2)
return -1;
return 1;
}
// Lookup table to convert 8 cardinal directions to 4
static const int actorDirectectionsLUT[8] = {
ACTOR_DIRECTION_BACK, // kDirUp
ACTOR_DIRECTION_RIGHT, // kDirUpRight
ACTOR_DIRECTION_RIGHT, // kDirRight
ACTOR_DIRECTION_RIGHT, // kDirDownRight
ACTOR_DIRECTION_FORWARD,// kDirDown
ACTOR_DIRECTION_LEFT, // kDirDownLeft
ACTOR_DIRECTION_LEFT, // kDirLeft
ACTOR_DIRECTION_LEFT, // kDirUpLeft
};
static const PathDirectionData pathDirectionLUT[8][3] = {
{ { 0, 0, -1 }, { 7, -1, -1 }, { 4, 1, -1 } },
{ { 1, 1, 0 }, { 4, 1, -1 }, { 5, 1, 1 } },
{ { 2, 0, 1 }, { 5, 1, 1 }, { 6, -1, 1 } },
{ { 3, -1, 0 }, { 6, -1, 1 }, { 7, -1, -1 } },
{ { 0, 0, -1 }, { 1, 1, 0 }, { 4, 1, -1 } },
{ { 1, 1, 0 }, { 2, 0, 1 }, { 5, 1, 1 } },
{ { 2, 0, 1 }, { 3, -1, 0 }, { 6, -1, 1 } },
{ { 3, -1, 0 }, { 0, 0, -1 }, { 7, -1, -1 } }
};
static const int pathDirectionLUT2[8][2] = {
{ 0, -1 },
{ 1, 0 },
{ 0, 1 },
{ -1, 0 },
{ 1, -1 },
{ 1, 1 },
{ -1, 1 },
{ -1, -1 }
};
static const int angleLUT[16][2] = {
{ 0, -256 },
{ 98, -237 },
{ 181, -181 },
{ 237, -98 },
{ 256, 0 },
{ 237, 98 },
{ 181, 181 },
{ 98, 237 },
{ 0, 256 },
{ -98, 237 },
{ -181, 181 },
{ -237, 98 },
{ -256, 0 },
{ -237, -98 },
{ -181, -181 },
{ -98, -237 }
};
static const int directionLUT[8][2] = {
{ 0 * 2, -2 * 2 },
{ 2 * 2, -1 * 2 },
{ 3 * 2, 0 * 2 },
{ 2 * 2, 1 * 2 },
{ 0 * 2, 2 * 2 },
{ -2 * 2, 1 * 2 },
{ -4 * 2, 0 * 2 },
{ -2 * 2, -1 * 2 }
};
static const int tileDirectionLUT[8][2] = {
{ 1, 1 },
{ 2, 0 },
{ 1, -1 },
{ 0, -2 },
{ -1, -1 },
{ -2, 0 },
{ -1, 1 },
{ 0, 2 }
};
struct DragonMove {
uint16 baseFrame;
int16 offset[4][2];
};
static const DragonMove dragonMoveTable[12] = {
{ 0, { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 } } },
{ 0, { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 } } },
{ 0, { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 } } },
{ 0, { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 } } },
{ 28, { { -0, 0 }, { -1, 6 }, { -5, 11 }, { -10, 15 } } },
{ 56, { { 0, 0 }, { 1, 6 }, { 5, 11 }, { 10, 15 } } },
{ 40, { { 0, 0 }, { 6, 1 }, { 11, 5 }, { 15, 10 } } },
{ 44, { { 0, 0 }, { 6, -1 }, { 11, -5 }, { 15, -10 } } },
{ 32, { { -0, -0 }, { -6, -1 }, { -11, -5 }, { -15, -10 } } },
{ 52, { { -0, 0 }, { -6, 1 }, { -11, 5 }, { -15, 10 } } },
{ 36, { { 0, -0 }, { 1, -6 }, { 5, -11 }, { 10, -15 } } },
{ 48, { { -0, -0 }, { -1, -6 }, { -5, -11 }, { -10, -15 } } }
};
Actor::Actor(SagaEngine *vm) : _vm(vm) {
int i;
int result;
byte *stringsPointer;
size_t stringsLength;
ActorData *actor;
ObjectData *obj;
debug(9, "Actor::Actor()");
_handleActionDiv = 15;
_actors = NULL;
_actorsCount = 0;
_objs = NULL;
_objsCount = 0;
#ifdef ACTOR_DEBUG
_debugPoints = NULL;
_debugPointsAlloced = _debugPointsCount = 0;
#endif
_pathNodeList = _newPathNodeList = NULL;
_pathList = NULL;
_pathDirectionList = NULL;
_pathListAlloced = _pathNodeListAlloced = _newPathNodeListAlloced = 0;
_pathListIndex = _pathNodeListIndex = _newPathNodeListIndex = -1;
_pathDirectionListCount = 0;
_pathDirectionListAlloced = 0;
_centerActor = _protagonist = NULL;
_protagState = 0;
_lastTickMsec = 0;
_yCellCount = _vm->getSceneHeight();
_xCellCount = _vm->getDisplayWidth();
_pathCell = (int8 *)malloc(_yCellCount * _xCellCount * sizeof(*_pathCell));
_pathRect.left = 0;
_pathRect.right = _vm->getDisplayWidth();
_pathRect.top = _vm->getDisplayInfo().pathStartY;
_pathRect.bottom = _vm->getSceneHeight();
if (_vm->getGameType() == GType_ITE) {
// Get actor resource file context
_actorContext = _vm->getFileContext(GAME_RESOURCEFILE, 0);
if (_actorContext == NULL) {
error("Actor::Actor(): Couldn't load actor module resource context.");
}
result = RSC_LoadResource(_actorContext, _vm->getResourceDescription()->actorsStringsResourceId, &stringsPointer, &stringsLength);
if ((result != SUCCESS) || (stringsLength == 0)) {
error("Error loading strings list resource");
}
_vm->loadStrings(_actorsStrings, stringsPointer, stringsLength);
RSC_FreeResource(stringsPointer);
} else {
// TODO
}
if (_vm->getGameType() == GType_ITE) {
_actorsCount = ITE_ACTORCOUNT;
_actors = (ActorData **)malloc(_actorsCount * sizeof(*_actors));
for (i = 0; i < _actorsCount; i++) {
actor = _actors[i] = new ActorData();
actor->id = actorIndexToId(i);
actor->index = i;
debug(9, "init actor id=%d index=%d", actor->id, actor->index);
actor->nameIndex = ITE_ActorTable[i].nameIndex;
actor->scriptEntrypointNumber = ITE_ActorTable[i].scriptEntrypointNumber;
actor->spriteListResourceId = ITE_ActorTable[i].spriteListResourceId;
actor->frameListResourceId = ITE_ActorTable[i].frameListResourceId;
actor->speechColor = ITE_ActorTable[i].speechColor;
actor->sceneNumber = ITE_ActorTable[i].sceneIndex;
actor->flags = ITE_ActorTable[i].flags;
actor->currentAction = ITE_ActorTable[i].currentAction;
actor->facingDirection = ITE_ActorTable[i].facingDirection;
actor->actionDirection = ITE_ActorTable[i].actionDirection;
actor->location.x = ITE_ActorTable[i].x;
actor->location.y = ITE_ActorTable[i].y;
actor->location.z = ITE_ActorTable[i].z;
actor->disabled = !loadActorResources(actor);
if (actor->disabled) {
warning("Disabling actor Id=%d index=%d", actor->id, actor->index);
}
}
_objsCount = ITE_OBJECTCOUNT;
_objs = (ObjectData **)malloc(_objsCount * sizeof(*_objs));
for (i = 0; i < _objsCount; i++) {
obj = _objs[i] = new ObjectData();
obj->id = objIndexToId(i);
obj->index = i;
debug(9, "init obj id=%d index=%d", obj->id, obj->index);
obj->nameIndex = ITE_ObjectTable[i].nameIndex;
obj->scriptEntrypointNumber = ITE_ObjectTable[i].scriptEntrypointNumber;
obj->spriteListResourceId = ITE_ObjectTable[i].spriteListResourceId;
obj->sceneNumber = ITE_ObjectTable[i].sceneIndex;
obj->interactBits = ITE_ObjectTable[i].interactBits;
obj->location.x = ITE_ObjectTable[i].x;
obj->location.y = ITE_ObjectTable[i].y;
obj->location.z = ITE_ObjectTable[i].z;
}
} else {
// TODO. This is causing problems for SYMBIAN os as it does n't like a static class here
ActorData dummyActor;
dummyActor.frames = NULL;
dummyActor.walkStepsPoints = NULL;
_protagonist = &dummyActor;
}
_dragonHunt = true;
}
Actor::~Actor() {
int i;
ActorData *actor;
ObjectData *obj;
debug(9, "Actor::~Actor()");
#ifdef ACTOR_DEBUG
free(_debugPoints);
#endif
free(_pathDirectionList);
free(_pathNodeList);
free(_newPathNodeList);
free(_pathList);
free(_pathCell);
_actorsStrings.freeMem();
//release resources
for (i = 0; i < _actorsCount; i++) {
actor = _actors[i];
delete actor;
}
free(_actors);
for (i = 0; i < _objsCount; i++) {
obj = _objs[i];
delete obj;
}
free(_objs);
}
bool Actor::loadActorResources(ActorData *actor) {
byte *resourcePointer;
size_t resourceLength;
int framesCount;
ActorFrameSequence *framesPointer;
int lastFrame;
int i, orient;
int resourceId;
if (actor->frameListResourceId == 0) {
warning("Frame List ID = 0 for actor index %d", actor->index);
return true;
}
debug(9, "Loading frame resource id %d", actor->frameListResourceId);
if (RSC_LoadResource(_actorContext, actor->frameListResourceId, &resourcePointer, &resourceLength) != SUCCESS) {
warning("Couldn't load sprite action index resource");
return false;
}
framesCount = resourceLength / 16;
debug(9, "Frame resource contains %d frames", framesCount);
framesPointer = (ActorFrameSequence *)malloc(sizeof(ActorFrameSequence) * framesCount);
if (framesPointer == NULL) {
memoryError("Actor::loadActorResources");
}
MemoryReadStreamEndian readS(resourcePointer, resourceLength, IS_BIG_ENDIAN);
lastFrame = 0;
for (i = 0; i < framesCount; i++) {
for (orient = 0; orient < ACTOR_DIRECTIONS_COUNT; orient++) {
// Load all four orientations
framesPointer[i].directions[orient].frameIndex = readS.readUint16();
framesPointer[i].directions[orient].frameCount = readS.readSint16();
if (framesPointer[i].directions[orient].frameCount < 0)
warning("frameCount < 0", framesPointer[i].directions[orient].frameCount);
if (framesPointer[i].directions[orient].frameIndex > lastFrame) {
lastFrame = framesPointer[i].directions[orient].frameIndex;
}
}
}
RSC_FreeResource(resourcePointer);
actor->frames = framesPointer;
actor->framesCount = framesCount;
resourceId = actor->spriteListResourceId;
debug(9, "Loading sprite resource id %d", resourceId);
if (_vm->_sprite->loadList(resourceId, actor->spriteList) != SUCCESS) {
warning("loadActorResources: Unable to load sprite list");
return false;
}
i = actor->spriteList.spriteCount;
if ((actor->flags & kExtended)) {
while ((lastFrame >= actor->spriteList.spriteCount)) {
resourceId++;
debug(9, "Appending to sprite list %d", resourceId);
if (_vm->_sprite->loadList(resourceId, actor->spriteList) != SUCCESS) {
warning("Unable append sprite list");
return false;
}
}
}
return true;
}
void Actor::takeExit(uint16 actorId, const HitZone *hitZone) {
ActorData *actor;
actor = getActor(actorId);
actor->lastZone = NULL;
_vm->_scene->changeScene(hitZone->getSceneNumber(), hitZone->getActorsEntrance(), kTransitionNoFade);
_vm->_script->setNoPendingVerb();
}
void Actor::stepZoneAction(ActorData *actor, const HitZone *hitZone, bool exit, bool stopped) {
EVENT event;
if (actor != _protagonist) {
return;
}
if (((hitZone->getFlags() & kHitZoneTerminus) && !stopped) || (!(hitZone->getFlags() & kHitZoneTerminus) && stopped)) {
return;
}
if (!exit) {
if (hitZone->getFlags() & kHitZoneAutoWalk) {
actor->currentAction = kActionWalkDir;
actor->actionDirection = actor->facingDirection = hitZone->getDirection();
actor->walkFrameSequence = kFrameWalk;
return;
}
} else if (!(hitZone->getFlags() & kHitZoneAutoWalk)) {
return;
}
if (hitZone->getFlags() & kHitZoneExit) {
takeExit(actor->id, hitZone);
} else if (hitZone->getScriptNumber() > 0) {
event.type = ONESHOT_EVENT;
event.code = SCRIPT_EVENT;
event.op = EVENT_EXEC_NONBLOCKING;
event.time = 0;
event.param = _vm->_scene->getScriptModuleNumber(); // module number
event.param2 = hitZone->getScriptNumber(); // script entry point number
event.param3 = kVerbEnter; // Action
event.param4 = ID_NOTHING; // Object
event.param5 = ID_NOTHING; // With Object
event.param6 = ID_PROTAG; // Actor
_vm->_events->queue(&event);
}
}
void Actor::realLocation(Location &location, uint16 objectId, uint16 walkFlags) {
int angle;
int distance;
ActorData *actor;
ObjectData *obj;
debug (8, "Actor::realLocation objectId=%i", objectId);
if (walkFlags & kWalkUseAngle) {
if (_vm->_scene->getFlags() & kSceneFlagISO) {
angle = (location.x + 2) & 15;
distance = location.y;
location.u() = (angleLUT[angle][0] * distance) >> 8;
location.v() = (angleLUT[angle][1] * distance) >> 8;
} else {
angle = location.x & 15;
distance = location.y;
location.x = (angleLUT[angle][0] * distance) >> 6;
location.y = (angleLUT[angle][1] * distance) >> 6;
}
}
if (objectId != ID_NOTHING) {
if (validActorId(objectId)) {
actor = getActor(objectId);
location.addXY(actor->location);
} else if (validObjId(objectId)) {
obj = getObj(objectId);
location.addXY(obj->location);
}
}
}
void Actor::actorFaceTowardsPoint(uint16 actorId, const Location &toLocation) {
ActorData *actor;
Location delta;
//debug (8, "Actor::actorFaceTowardsPoint actorId=%i", actorId);
actor = getActor(actorId);
toLocation.delta(actor->location, delta);
if (_vm->_scene->getFlags() & kSceneFlagISO) {
if (delta.u() > 0) {
actor->facingDirection = (delta.v() > 0) ? kDirUp : kDirRight;
} else {
actor->facingDirection = (delta.v() > 0) ? kDirLeft : kDirDown;
}
} else {
if (ABS(delta.y) > ABS(delta.x * 2)) {
actor->facingDirection = (delta.y > 0) ? kDirDown : kDirUp;
} else {
actor->facingDirection = (delta.x > 0) ? kDirRight : kDirLeft;
}
}
}
void Actor::actorFaceTowardsObject(uint16 actorId, uint16 objectId) {
ActorData *actor;
ObjectData *obj;
if (validActorId(objectId)) {
actor = getActor(objectId);
actorFaceTowardsPoint(actorId, actor->location);
} else if (validObjId(objectId)) {
obj = getObj(objectId);
actorFaceTowardsPoint(actorId, obj->location);
}
}
ObjectData *Actor::getObj(uint16 objId) {
ObjectData *obj;
if (!validObjId(objId))
error("Actor::getObj Wrong objId 0x%X", objId);
obj = _objs[objIdToIndex(objId)];
if (obj->disabled)
error("Actor::getObj disabled objId 0x%X", objId);
return obj;
}
ActorData *Actor::getActor(uint16 actorId) {
ActorData *actor;
if (!validActorId(actorId)) {
warning("Actor::getActor Wrong actorId 0x%X", actorId);
assert(0);
}
if (actorId == ID_PROTAG) {
if (_protagonist == NULL) {
error("_protagonist == NULL");
}
return _protagonist;
}
actor = _actors[actorIdToIndex(actorId)];
if (actor->disabled)
error("Actor::getActor disabled actorId 0x%X", actorId);
return actor;
}
bool Actor::validFollowerLocation(const Location &location) {
Point point;
location.toScreenPointXY(point);
if ((point.x < 5) || (point.x >= _vm->getDisplayWidth() - 5) ||
(point.y < 0) || (point.y > _vm->getSceneHeight())) {
return false;
}
return (_vm->_scene->canWalk(point));
}
void Actor::setProtagState(int state) {
_protagState = state;
}
void Actor::updateActorsScene(int actorsEntrance) {
int i, j;
int followerDirection;
ActorData *actor;
Location tempLocation;
Location possibleLocation;
Point delta;
const SceneEntry *sceneEntry;
if (_vm->getGameType() == GType_IHNM) {
warning("Actors aren't implemented for IHNM yet");
return;
}
if (_vm->_scene->currentSceneNumber() == 0) {
error("Actor::updateActorsScene _vm->_scene->currentSceneNumber() == 0");
}
_vm->_sound->stopVoice();
_activeSpeech.stringsCount = 0;
_activeSpeech.playing = false;
_protagonist = NULL;
for (i = 0; i < _actorsCount; i++) {
actor = _actors[i];
actor->inScene = false;
if (actor->disabled) {
continue;
}
if ((actor->flags & (kProtagonist | kFollower)) || (i == 0)) {
if (actor->flags & kProtagonist) {
actor->finalTarget = actor->location;
_centerActor = _protagonist = actor;
} else if (_vm->_scene->currentSceneResourceId() == RID_ITE_OVERMAP_SCENE) {
continue;
}
actor->sceneNumber = _vm->_scene->currentSceneNumber();
}
if (actor->sceneNumber == _vm->_scene->currentSceneNumber()) {
actor->inScene = true;
actor->actionCycle = (_vm->_rnd.getRandomNumber(7) & 0x7) * 4; // 1/8th chance
}
}
assert(_protagonist);
if ((actorsEntrance >= 0) && (_vm->_scene->_entryList.entryListCount > 0)) {
if (_vm->_scene->_entryList.entryListCount <= actorsEntrance) {
actorsEntrance = 0; //OCEAN bug
}
sceneEntry = _vm->_scene->_entryList.getEntry(actorsEntrance);
if (_vm->_scene->getFlags() & kSceneFlagISO) {
_protagonist->location = sceneEntry->location;
} else {
_protagonist->location.x = sceneEntry->location.x * ACTOR_LMULT;
_protagonist->location.y = sceneEntry->location.y * ACTOR_LMULT;
_protagonist->location.z = sceneEntry->location.z * ACTOR_LMULT;
}
_protagonist->facingDirection = _protagonist->actionDirection = sceneEntry->facing;
}
_protagonist->currentAction = kActionWait;
if (_vm->_scene->getFlags() & kSceneFlagISO) {
//nothing?
} else {
_vm->_scene->initDoorsState(); //TODO: move to _scene
}
followerDirection = _protagonist->facingDirection + 3;
calcScreenPosition(_protagonist);
for (i = 0; i < _actorsCount; i++) {
actor = _actors[i];
if (actor->flags & (kFollower)) {
actor->facingDirection = actor->actionDirection = _protagonist->facingDirection;
actor->currentAction = kActionWait;
actor->walkStepsCount = actor->walkStepIndex = 0;
actor->location.z = _protagonist->location.z;
if (_vm->_scene->getFlags() & kSceneFlagISO) {
_vm->_isoMap->placeOnTileMap(_protagonist->location, actor->location, 3, followerDirection & 0x07);
} else {
followerDirection &= 0x07;
possibleLocation = _protagonist->location;
delta.x = directionLUT[followerDirection][0];
delta.y = directionLUT[followerDirection][1];
for (j = 0; j < 30; j++) {
tempLocation = possibleLocation;
tempLocation.x += delta.x;
tempLocation.y += delta.y;
if (validFollowerLocation( tempLocation)) {
possibleLocation = tempLocation;
} else {
tempLocation = possibleLocation;
tempLocation.x += delta.x;
if (validFollowerLocation( tempLocation)) {
possibleLocation = tempLocation;
} else {
tempLocation = possibleLocation;
tempLocation.y += delta.y;
if (validFollowerLocation( tempLocation)) {
possibleLocation = tempLocation;
} else {
break;
}
}
}
}
actor->location = possibleLocation;
}
followerDirection += 2;
}
}
handleActions(0, true);
if (_vm->_scene->getFlags() & kSceneFlagISO) {
_vm->_isoMap->adjustScroll(true);
}
}
ActorFrameRange *Actor::getActorFrameRange(uint16 actorId, int frameType) {
ActorData *actor;
int fourDirection;
actor = getActor(actorId);
if (actor->disabled)
error("Actor::getActorFrameRange Wrong actorId 0x%X", actorId);
if (frameType >= actor->framesCount)
error("Actor::getActorFrameRange Wrong frameType 0x%X actorId 0x%X", frameType, actorId);
if ((actor->facingDirection < kDirUp) || (actor->facingDirection > kDirUpLeft))
error("Actor::getActorFrameRange Wrong direction 0x%X actorId 0x%X", actor->facingDirection, actorId);
fourDirection = actorDirectectionsLUT[actor->facingDirection];
return &actor->frames[frameType].directions[fourDirection];
}
void Actor::handleSpeech(int msec) {
int stringLength;
int sampleLength;
bool removeFirst;
int i;
int talkspeed;
ActorData *actor;
int width, height, height2;
Point posPoint;
if (_activeSpeech.playing) {
_activeSpeech.playingTime -= msec;
stringLength = strlen(_activeSpeech.strings[0]);
removeFirst = false;
if (_activeSpeech.playingTime <= 0) {
if (_activeSpeech.speechFlags & kSpeakSlow) {
_activeSpeech.slowModeCharIndex++;
if (_activeSpeech.slowModeCharIndex >= stringLength)
removeFirst = true;
} else {
removeFirst = true;
}
_activeSpeech.playing = false;
if (_activeSpeech.actorIds[0] != 0) {
actor = getActor(_activeSpeech.actorIds[0]);
if (!(_activeSpeech.speechFlags & kSpeakNoAnimate)) {
actor->currentAction = kActionWait;
}
}
}
if (removeFirst) {
for (i = 1; i < _activeSpeech.stringsCount; i++) {
_activeSpeech.strings[i - 1] = _activeSpeech.strings[i];
}
_activeSpeech.stringsCount--;
}
if (_vm->_script->_skipSpeeches) {
_activeSpeech.stringsCount = 0;
_vm->_script->wakeUpThreads(kWaitTypeSpeech);
return;
}
if (_activeSpeech.stringsCount == 0) {
_vm->_script->wakeUpThreadsDelayed(kWaitTypeSpeech, ticksToMSec(kScriptTimeTicksPerSecond / 3));
}
return;
}
if (_vm->_script->_skipSpeeches) {
_activeSpeech.stringsCount = 0;
_vm->_script->wakeUpThreads(kWaitTypeSpeech);
}
if (_activeSpeech.stringsCount == 0) {
return;
}
stringLength = strlen(_activeSpeech.strings[0]);
talkspeed = ConfMan.getInt("talkspeed");
if (_activeSpeech.speechFlags & kSpeakSlow) {
if (_activeSpeech.slowModeCharIndex >= stringLength)
error("Wrong string index");
warning("Slow string encountered!");
_activeSpeech.playingTime = 10 * talkspeed;
// 10 - fix it
} else {
sampleLength = _vm->_sndRes->getVoiceLength(_activeSpeech.sampleResourceId); //fixme - too fast
if (sampleLength < 0) {
_activeSpeech.playingTime = stringLength * talkspeed;
} else {
_activeSpeech.playingTime = sampleLength;
}
}
if (_activeSpeech.sampleResourceId != -1) {
_vm->_sndRes->playVoice(_activeSpeech.sampleResourceId);
_activeSpeech.sampleResourceId++;
}
if (_activeSpeech.actorIds[0] != 0) {
actor = getActor(_activeSpeech.actorIds[0]);
if (!(_activeSpeech.speechFlags & kSpeakNoAnimate)) {
actor->currentAction = kActionSpeak;
actor->actionCycle = _vm->_rnd.getRandomNumber(63);
}
}
if (_activeSpeech.actorsCount == 1) {
width = _activeSpeech.speechBox.width();
height = _vm->_font->getHeight(kMediumFont, _activeSpeech.strings[0], width - 2, _activeSpeech.getFontFlags(0)) + 1;
if (height > 40 && width < _vm->getDisplayWidth() - 100) {
width = _vm->getDisplayWidth() - 100;
height = _vm->_font->getHeight(kMediumFont, _activeSpeech.strings[0], width - 2, _activeSpeech.getFontFlags(0)) + 1;
}
_activeSpeech.speechBox.setWidth(width);
if (_activeSpeech.actorIds[0] != 0) {
actor = getActor(_activeSpeech.actorIds[0]);
_activeSpeech.speechBox.setHeight(height);
if (_activeSpeech.speechBox.right > _vm->getDisplayWidth() - 10) {
_activeSpeech.drawRect.left = _vm->getDisplayWidth() - 10 - width;
} else {
_activeSpeech.drawRect.left = _activeSpeech.speechBox.left;
}
height2 = actor->screenPosition.y - 50;
_activeSpeech.speechBox.top = _activeSpeech.drawRect.top = MAX(10, (height2 - height) / 2);
} else {
_activeSpeech.drawRect.left = _activeSpeech.speechBox.left;
_activeSpeech.drawRect.top = _activeSpeech.speechBox.top + (_activeSpeech.speechBox.height() - height) / 2;
}
_activeSpeech.drawRect.setWidth(width);
_activeSpeech.drawRect.setHeight(height);
}
_activeSpeech.playing = true;
}
void Actor::handleActions(int msec, bool setup) {
int i;
ActorData *actor;
ActorFrameRange *frameRange;
int state;
int speed;
int32 framesLeft;
Location delta;
Location addDelta;
int hitZoneIndex;
const HitZone *hitZone;
Point hitPoint;
Location pickLocation;
for (i = 0; i < _actorsCount; i++) {
actor = _actors[i];
if (!actor->inScene)
continue;
if ((_vm->getGameType() == GType_ITE) && (i == ACTOR_DRAGON_INDEX)) {
moveDragon(actor);
continue;
}
/* if (actor->index == 2)
debug(9, "Action: %d Flags: %x", actor->currentAction, actor->flags);*/
switch (actor->currentAction) {
case kActionWait:
if (!setup && (actor->flags & kFollower)) {
followProtagonist(actor);
if (actor->currentAction != kActionWait)
break;
}
if (actor->targetObject != ID_NOTHING) {
actorFaceTowardsObject(actor->id, actor->targetObject);
}
if (actor->flags & kCycle) {
frameRange = getActorFrameRange(actor->id, kFrameStand);
if (frameRange->frameCount > 0) {
actor->actionCycle++;
actor->actionCycle = (actor->actionCycle) % frameRange->frameCount;
} else {
actor->actionCycle = 0;
}
actor->frameNumber = frameRange->frameIndex + actor->actionCycle;
break;
}
if ((actor->actionCycle & 3) == 0) {
actor->cycleWrap(100);
frameRange = getActorFrameRange(actor->id, kFrameWait);
if ((frameRange->frameCount < 1 || actor->actionCycle > 33))
frameRange = getActorFrameRange(actor->id, kFrameStand);
if (frameRange->frameCount) {
actor->frameNumber = frameRange->frameIndex + (uint16)_vm->_rnd.getRandomNumber(frameRange->frameCount - 1);
} else {
actor->frameNumber = frameRange->frameIndex;
}
}
actor->actionCycle++;
break;
case kActionWalkToPoint:
case kActionWalkToLink:
if (_vm->_scene->getFlags() & kSceneFlagISO) {
actor->partialTarget.delta(actor->location, delta);
while ((delta.u() == 0) && (delta.v() == 0)) {
if ((actor == _protagonist) && (_vm->mouseButtonPressed())) {
_vm->_isoMap->screenPointToTileCoords(_vm->mousePos(), pickLocation);
if (!actorWalkTo(_protagonist->id, pickLocation)) {
break;
}
} else if (!_vm->_isoMap->nextTileTarget(actor) && !actorEndWalk(actor->id, true)) {
break;
}
actor->partialTarget.delta(actor->location, delta);
actor->partialTarget.z = 0;
}
if (actor->flags & kFastest) {
speed = 8;
} else if (actor->flags & kFaster) {
speed = 6;
} else {
speed = 4;
}
if (_vm->_scene->currentSceneResourceId() == RID_ITE_OVERMAP_SCENE) {
speed = 2;
}
if ((actor->actionDirection == 2) || (actor->actionDirection == 6)) {
speed = speed / 2;
}
if (ABS(delta.v()) > ABS(delta.u())) {
addDelta.v() = clamp( -speed, delta.v(), speed );
if (addDelta.v() == delta.v()) {
addDelta.u() = delta.u();
} else {
addDelta.u() = delta.u() * addDelta.v();
addDelta.u() += (addDelta.u() > 0) ? (delta.v() / 2) : (-delta.v() / 2);
addDelta.u() /= delta.v();
}
} else {
addDelta.u() = clamp( -speed, delta.u(), speed );
if (addDelta.u() == delta.u()) {
addDelta.v() = delta.v();
} else {
addDelta.v() = delta.v() * addDelta.u();
addDelta.v() += (addDelta.v() > 0) ? (delta.u() / 2) : (-delta.u() / 2);
addDelta.v() /= delta.u();
}
}
actor->location.add(addDelta);
} else {
actor->partialTarget.delta(actor->location, delta);
while ((delta.x == 0) && (delta.y == 0)) {
if (actor->walkStepIndex >= actor->walkStepsCount) {
actorEndWalk(actor->id, true);
break;
}
actor->partialTarget.fromScreenPoint(actor->walkStepsPoints[actor->walkStepIndex++]);
if (actor->partialTarget.x > 224 * 2 * ACTOR_LMULT) {
actor->partialTarget.x -= 256 * 2 * ACTOR_LMULT;
}
actor->partialTarget.delta(actor->location, delta);
if (ABS(delta.y) > ABS(delta.x)) {
actor->actionDirection = delta.y > 0 ? kDirDown : kDirUp;
} else {
actor->actionDirection = delta.x > 0 ? kDirRight : kDirLeft;
}
}
speed = (ACTOR_LMULT * 2 * actor->screenScale + 63) / 256;
if (speed < 1) {
speed = 1;
}
if ((actor->actionDirection == kDirUp) || (actor->actionDirection == kDirDown)) {
addDelta.y = clamp(-speed, delta.y, speed);
if (addDelta.y == delta.y) {
addDelta.x = delta.x;
} else {
addDelta.x = delta.x * addDelta.y;
addDelta.x += (addDelta.x > 0) ? (delta.y / 2) : (-delta.y / 2);
addDelta.x /= delta.y;
actor->facingDirection = actor->actionDirection;
}
} else {
addDelta.x = clamp(-2 * speed, delta.x, 2 * speed);
if (addDelta.x == delta.x) {
addDelta.y = delta.y;
} else {
addDelta.y = delta.y * addDelta.x;
addDelta.y += (addDelta.y > 0) ? (delta.x / 2) : (-delta.x / 2);
addDelta.y /= delta.x;
actor->facingDirection = actor->actionDirection;
}
}
actor->location.add(addDelta);
}
if (actor->actorFlags & kActorBackwards) {
actor->facingDirection = (actor->actionDirection + 4) & 7;
actor->actionCycle--;
} else {
actor->actionCycle++;
}
frameRange = getActorFrameRange(actor->id, actor->walkFrameSequence);
if (actor->actionCycle < 0) {
actor->actionCycle = frameRange->frameCount - 1;
} else if (actor->actionCycle >= frameRange->frameCount) {
actor->actionCycle = 0;
}
actor->frameNumber = frameRange->frameIndex + actor->actionCycle;
break;
case kActionWalkDir:
if (_vm->_scene->getFlags() & kSceneFlagISO) {
actor->location.u() += tileDirectionLUT[actor->actionDirection][0];
actor->location.v() += tileDirectionLUT[actor->actionDirection][1];
frameRange = getActorFrameRange(actor->id, actor->walkFrameSequence);
actor->actionCycle++;
actor->cycleWrap(frameRange->frameCount);
actor->frameNumber = frameRange->frameIndex + actor->actionCycle;
} else {
actor->location.x += directionLUT[actor->actionDirection][0] * 2;
actor->location.y += directionLUT[actor->actionDirection][1] * 2;
frameRange = getActorFrameRange(actor->id, actor->walkFrameSequence);
actor->actionCycle++;
actor->cycleWrap(frameRange->frameCount);
actor->frameNumber = frameRange->frameIndex + actor->actionCycle;
}
break;
case kActionSpeak:
actor->actionCycle++;
actor->cycleWrap(64);
frameRange = getActorFrameRange(actor->id, kFrameGesture);
if (actor->actionCycle >= frameRange->frameCount) {
if (actor->actionCycle & 1)
break;
frameRange = getActorFrameRange(actor->id, kFrameSpeak);
state = (uint16)_vm->_rnd.getRandomNumber(frameRange->frameCount);
if (state == 0) {
frameRange = getActorFrameRange(actor->id, kFrameStand);
} else {
state--;
}
} else {
state = actor->actionCycle;
}
actor->frameNumber = frameRange->frameIndex + state;
break;
case kActionAccept:
case kActionStoop:
break;
case kActionCycleFrames:
case kActionPongFrames:
if (actor->cycleTimeCount > 0) {
actor->cycleTimeCount--;
break;
}
actor->cycleTimeCount = actor->cycleDelay;
actor->actionCycle++;
frameRange = getActorFrameRange(actor->id, actor->cycleFrameSequence);
if (actor->currentAction == kActionPongFrames) {
if (actor->actionCycle >= frameRange->frameCount * 2 - 2) {
if (actor->actorFlags & kActorContinuous) {
actor->actionCycle = 0;
} else {
actor->currentAction = kActionFreeze;
break;
}
}
state = actor->actionCycle;
if (state >= frameRange->frameCount) {
state = frameRange->frameCount * 2 - 2 - state;
}
} else {
if (actor->actionCycle >= frameRange->frameCount) {
if (actor->actorFlags & kActorContinuous) {
actor->actionCycle = 0;
} else {
actor->currentAction = kActionFreeze;
break;
}
}
state = actor->actionCycle;
}
if (frameRange->frameCount && (actor->actorFlags & kActorRandom)) {
state = _vm->_rnd.getRandomNumber(frameRange->frameCount - 1);
}
if (actor->actorFlags & kActorBackwards) {
actor->frameNumber = frameRange->frameIndex + frameRange->frameCount - 1 - state;
} else {
actor->frameNumber = frameRange->frameIndex + state;
}
break;
case kActionFall:
if (actor->actionCycle > 0) {
framesLeft = actor->actionCycle--;
actor->finalTarget.delta(actor->location, delta);
delta.x /= framesLeft;
delta.y /= framesLeft;
actor->location.addXY(delta);
actor->fallVelocity += actor->fallAcceleration;
actor->fallPosition += actor->fallVelocity;
actor->location.z = actor->fallPosition >> 4;
} else {
actor->location = actor->finalTarget;
actor->currentAction = kActionFreeze;
_vm->_script->wakeUpActorThread(kWaitTypeWalk, actor);
}
break;
case kActionClimb:
actor->cycleDelay++;
if (actor->cycleDelay & 3) {
break;
}
if (actor->location.z >= actor->finalTarget.z + ACTOR_CLIMB_SPEED) {
actor->location.z -= ACTOR_CLIMB_SPEED;
actor->actionCycle--;
} else if (actor->location.z <= actor->finalTarget.z - ACTOR_CLIMB_SPEED) {
actor->location.z += ACTOR_CLIMB_SPEED;
actor->actionCycle++;
} else {
actor->location.z = actor->finalTarget.z;
actor->currentAction = kActionFreeze;
_vm->_script->wakeUpActorThread(kWaitTypeWalk, actor);
}
frameRange = getActorFrameRange(actor->id, actor->cycleFrameSequence);
if (actor->actionCycle < 0) {
actor->actionCycle = frameRange->frameCount - 1;
}
actor->cycleWrap(frameRange->frameCount);
actor->frameNumber = frameRange->frameIndex + actor->actionCycle;
break;
}
if ((actor->currentAction >= kActionWalkToPoint) && (actor->currentAction <= kActionWalkDir)) {
hitZone = NULL;
if (_vm->_scene->getFlags() & kSceneFlagISO) {
actor->location.toScreenPointUV(hitPoint);
} else {
actor->location.toScreenPointXY(hitPoint);
}
hitZoneIndex = _vm->_scene->_actionMap->hitTest(hitPoint);
if (hitZoneIndex != -1) {
hitZone = _vm->_scene->_actionMap->getHitZone(hitZoneIndex);
}
if (hitZone != actor->lastZone) {
if (actor->lastZone)
stepZoneAction( actor, actor->lastZone, true, false);
actor->lastZone = hitZone;
if (hitZone)
stepZoneAction( actor, hitZone, false, false);
}
}
}
}
void Actor::direct(int msec) {
if (_vm->_scene->_entryList.entryListCount == 0) {
return;
}
if (_vm->_interface->_statusTextInput) {
return;
}
// FIXME: HACK. This should be turned into cycle event.
_lastTickMsec += msec;
if (_lastTickMsec > 1000 / _handleActionDiv) {
_lastTickMsec = 0;
//process actions
handleActions(msec, false);
}
//process speech
handleSpeech(msec);
}
bool Actor::calcScreenPosition(CommonObjectData *commonObjectData) {
int beginSlope, endSlope, middle;
bool result;
if (_vm->_scene->getFlags() & kSceneFlagISO) {
_vm->_isoMap->tileCoordsToScreenPoint(commonObjectData->location, commonObjectData->screenPosition);
commonObjectData->screenScale = 256;
} else {
middle = _vm->getSceneHeight() - commonObjectData->location.y / ACTOR_LMULT;
_vm->_scene->getSlopes(beginSlope, endSlope);
commonObjectData->screenDepth = (14 * middle) / endSlope + 1;
if (middle <= beginSlope) {
commonObjectData->screenScale = 256;
} else if (middle >= endSlope) {
commonObjectData->screenScale = 1;
} else {
middle -= beginSlope;
endSlope -= beginSlope;
commonObjectData->screenScale = 256 - (middle * 256) / endSlope;
}
commonObjectData->location.toScreenPointXYZ(commonObjectData->screenPosition);
}
result = commonObjectData->screenPosition.x > -64 &&
commonObjectData->screenPosition.x < _vm->getDisplayWidth() + 64 &&
commonObjectData->screenPosition.y > -64 &&
commonObjectData->screenPosition.y < _vm->getSceneHeight() + 64;
return result;
}
uint16 Actor::hitTest(const Point &testPoint, bool skipProtagonist) {
// We can only interact with objects or actors that are inside the
// scene area. While this is usually the entire upper part of the
// screen, it could also be an inset. Note that other kinds of hit
// areas may be outside the inset, and that those are still perfectly
// fine to interact with. For example, the door entrance at the glass
// makers's house in ITE's ferret village.
if (!_vm->_scene->getSceneClip().contains(testPoint))
return ID_NOTHING;
CommonObjectOrderList::iterator drawOrderIterator;
CommonObjectDataPointer drawObject;
int frameNumber;
SpriteList *spriteList;
createDrawOrderList();
for (drawOrderIterator = _drawOrderList.begin(); drawOrderIterator != _drawOrderList.end(); ++drawOrderIterator) {
drawObject = drawOrderIterator.operator*();
if (skipProtagonist && (drawObject == _protagonist)) {
continue;
}
if (!getSpriteParams(drawObject, frameNumber, spriteList)) {
continue;
}
if (_vm->_sprite->hitTest(*spriteList, frameNumber, drawObject->screenPosition, drawObject->screenScale, testPoint)) {
return drawObject->id;
}
}
return ID_NOTHING;
}
void Actor::createDrawOrderList() {
int i;
ActorData *actor;
ObjectData *obj;
CommonObjectOrderList::CompareFunction compareFunction;
if (_vm->_scene->getFlags() & kSceneFlagISO) {
compareFunction = &tileCommonObjectCompare;
} else {
compareFunction = &commonObjectCompare;
}
_drawOrderList.clear();
for (i = 0; i < _actorsCount; i++) {
actor = _actors[i];
if (!actor->inScene)
continue;
if (calcScreenPosition(actor)) {
_drawOrderList.pushBack(actor, compareFunction);
}
}
for (i = 0; i < _objsCount; i++) {
obj = _objs[i];
if (obj->disabled)
continue;
if (obj->sceneNumber != _vm->_scene->currentSceneNumber())
continue;
if (calcScreenPosition(obj)) {
_drawOrderList.pushBack(obj, compareFunction);
}
}
}
bool Actor::getSpriteParams(CommonObjectData *commonObjectData, int &frameNumber, SpriteList *&spriteList) {
if (_vm->_scene->currentSceneResourceId() == RID_ITE_OVERMAP_SCENE) {
if (!(commonObjectData->flags & kProtagonist)){
// warning("not protagonist");
return false;
}
frameNumber = 8;
spriteList = &_vm->_sprite->_mainSprites;
} else if (validActorId(commonObjectData->id)) {
spriteList = &((ActorData *)commonObjectData)->spriteList;
frameNumber = ((ActorData *)commonObjectData)->frameNumber;
} else if (validObjId(commonObjectData->id)) {
spriteList = &_vm->_sprite->_mainSprites;
frameNumber = commonObjectData->spriteListResourceId;
}
if ((frameNumber < 0) || (spriteList->spriteCount <= frameNumber)) {
warning("Actor::getSpriteParams frameNumber invalid for object id 0x%X", commonObjectData->id);
return false;
}
return true;
}
void Actor::drawActors() {
if (_vm->_scene->currentSceneNumber() <= 0) {
return;
}
if (_vm->_scene->_entryList.entryListCount == 0) {
return;
}
CommonObjectOrderList::iterator drawOrderIterator;
CommonObjectDataPointer drawObject;
int frameNumber;
SpriteList *spriteList;
Surface *backBuffer;
backBuffer = _vm->_gfx->getBackBuffer();
createDrawOrderList();
for (drawOrderIterator = _drawOrderList.begin(); drawOrderIterator != _drawOrderList.end(); ++drawOrderIterator) {
drawObject = drawOrderIterator.operator*();
if (!getSpriteParams(drawObject, frameNumber, spriteList)) {
continue;
}
if (_vm->_scene->getFlags() & kSceneFlagISO) {
_vm->_isoMap->drawSprite(backBuffer, *spriteList, frameNumber, drawObject->location, drawObject->screenPosition, drawObject->screenScale);
} else {
_vm->_sprite->drawOccluded(backBuffer, _vm->_scene->getSceneClip(),*spriteList, frameNumber, drawObject->screenPosition, drawObject->screenScale, drawObject->screenDepth);
}
}
drawSpeech();
}
void Actor::drawSpeech(void) {
if (!isSpeaking() || !_activeSpeech.playing || _vm->_script->_skipSpeeches)
return;
int i;
Point textPoint;
ActorData *actor;
int width, height;
char oneChar[2];
oneChar[1] = 0;
const char *outputString;
Surface *backBuffer;
backBuffer = _vm->_gfx->getBackBuffer();
if (_activeSpeech.speechFlags & kSpeakSlow) {
outputString = oneChar;
oneChar[0] = _activeSpeech.strings[0][_activeSpeech.slowModeCharIndex];
} else {
outputString = _activeSpeech.strings[0];
}
if (_activeSpeech.actorsCount > 1) {
height = _vm->_font->getHeight(kMediumFont);
width = _vm->_font->getStringWidth(kMediumFont, _activeSpeech.strings[0], 0, kFontNormal);
for (i = 0; i < _activeSpeech.actorsCount; i++) {
actor = getActor(_activeSpeech.actorIds[i]);
calcScreenPosition(actor);
textPoint.x = clamp( 10, actor->screenPosition.x - width / 2, _vm->getDisplayWidth() - 10 - width);
textPoint.y = clamp( 10, actor->screenPosition.y - 58, _vm->getSceneHeight() - 10 - height);
_vm->_font->textDraw(kMediumFont, backBuffer, _activeSpeech.strings[0], textPoint,
_activeSpeech.speechColor[i], _activeSpeech.outlineColor[i], _activeSpeech.getFontFlags(i));
}
} else {
_vm->_font->textDrawRect(kMediumFont, backBuffer, _activeSpeech.strings[0], _activeSpeech.drawRect, _activeSpeech.speechColor[0],
_activeSpeech.outlineColor[0], _activeSpeech.getFontFlags(0));
}
}
bool Actor::followProtagonist(ActorData *actor) {
Location protagonistLocation;
Location newLocation;
Location delta;
int protagonistBGMaskType;
Point prefer1;
Point prefer2;
Point prefer3;
int16 prefU;
int16 prefV;
int16 newU;
int16 newV;
assert(_protagonist);
actor->flags &= ~(kFaster | kFastest);
protagonistLocation = _protagonist->location;
calcScreenPosition(_protagonist);
if (_vm->_scene->getFlags() & kSceneFlagISO) {
prefU = 60;
prefV = 60;
actor->location.delta(protagonistLocation, delta);
if (actor->id == actorIndexToId(2)) {
prefU = prefV = 48;
}
if ((delta.u() > prefU) || (delta.u() < -prefU) || (delta.v() > prefV) || (delta.v() < -prefV)) {
if ((delta.u() > prefU * 2) || (delta.u() < -prefU * 2) || (delta.v() > prefV * 2) || (delta.v() < -prefV * 2)) {
actor->flags |= kFaster;
if ((delta.u() > prefU * 3) || (delta.u() < -prefU*3) || (delta.v() > prefV * 3) || (delta.v() < -prefV * 3)) {
actor->flags |= kFastest;
}
}
prefU /= 2;
prefV /= 2;
newU = clamp( -prefU, delta.u(), prefU ) + protagonistLocation.u();
newV = clamp( -prefV, delta.v(), prefV ) + protagonistLocation.v();
newLocation.u() = newU + _vm->_rnd.getRandomNumber(prefU - 1) - prefU / 2;
newLocation.v() = newV + _vm->_rnd.getRandomNumber(prefV - 1) - prefV / 2;
newLocation.z = 0;
return actorWalkTo(actor->id, newLocation);
}
} else {
prefer1.x = (100 * _protagonist->screenScale) >> 8;
prefer1.y = (50 * _protagonist->screenScale) >> 8;
if (_protagonist->currentAction == kActionWalkDir) {
prefer1.x /= 2;
}
if (prefer1.x < 8) {
prefer1.x = 8;
}
if (prefer1.y < 8) {
prefer1.y = 8;
}
prefer2.x = prefer1.x * 2;
prefer2.y = prefer1.y * 2;
prefer3.x = prefer1.x + prefer1.x / 2;
prefer3.y = prefer1.y + prefer1.y / 2;
actor->location.delta(protagonistLocation, delta);
protagonistBGMaskType = 0;
if (_vm->_scene->isBGMaskPresent() && _vm->_scene->validBGMaskPoint(_protagonist->screenPosition)) {
protagonistBGMaskType = _vm->_scene->getBGMaskType(_protagonist->screenPosition);
}
if ((_vm->_rnd.getRandomNumber(7) & 0x7) == 0) // 1/8th chance
actor->actorFlags &= ~kActorNoFollow;
if (actor->actorFlags & kActorNoFollow) {
return false;
}
if ((delta.x > prefer2.x) || (delta.x < -prefer2.x) ||
(delta.y > prefer2.y) || (delta.y < -prefer2.y) ||
((_protagonist->currentAction == kActionWait) &&
(delta.x * 2 < prefer1.x) && (delta.x * 2 > -prefer1.x) &&
(delta.y < prefer1.y) && (delta.y > -prefer1.y))) {
if (ABS(delta.x) > ABS(delta.y)) {
delta.x = (delta.x > 0) ? prefer3.x : -prefer3.x;
newLocation.x = delta.x + protagonistLocation.x;
newLocation.y = clamp(-prefer2.y, delta.y, prefer2.y) + protagonistLocation.y;
} else {
delta.y = (delta.y > 0) ? prefer3.y : -prefer3.y;
newLocation.x = clamp(-prefer2.x, delta.x, prefer2.x) + protagonistLocation.x;
newLocation.y = delta.y + protagonistLocation.y;
}
newLocation.z = 0;
if (protagonistBGMaskType != 3) {
newLocation.x += _vm->_rnd.getRandomNumber(prefer1.x - 1) - prefer1.x / 2;
newLocation.y += _vm->_rnd.getRandomNumber(prefer1.y - 1) - prefer1.y / 2;
}
newLocation.x = clamp(-31*4, newLocation.x, (_vm->getDisplayWidth() + 31) * 4); //fixme
return actorWalkTo(actor->id, newLocation);
}
}
return false;
}
bool Actor::actorEndWalk(uint16 actorId, bool recurse) {
bool walkMore = false;
ActorData *actor;
const HitZone *hitZone;
int hitZoneIndex;
Point testPoint;
actor = getActor(actorId);
actor->actorFlags &= ~kActorBackwards;
if (actor->location.distance(actor->finalTarget) > 8 && (actor->flags & kProtagonist) && recurse && !(actor->actorFlags & kActorNoCollide)) {
actor->actorFlags |= kActorNoCollide;
return actorWalkTo(actorId, actor->finalTarget);
}
actor->currentAction = kActionWait;
if (actor->actorFlags & kActorFinalFace) {
actor->facingDirection = actor->actionDirection = (actor->actorFlags >> 6) & 0x07; //?
}
actor->actorFlags &= ~(kActorNoCollide | kActorCollided | kActorFinalFace | kActorFacingMask);
actor->flags &= ~(kFaster | kFastest);
if (actor == _protagonist) {
_vm->_script->wakeUpActorThread(kWaitTypeWalk, actor);
if (_vm->_script->_pendingVerb == kVerbWalkTo) {
actor->location.toScreenPointUV(testPoint);
hitZoneIndex = _vm->_scene->_actionMap->hitTest(testPoint);
if (hitZoneIndex != -1) {
hitZone = _vm->_scene->_actionMap->getHitZone(hitZoneIndex);
stepZoneAction(actor, hitZone, false, true);
} else {
_vm->_script->setNoPendingVerb();
}
} else if (_vm->_script->_pendingVerb != kVerbNone) {
_vm->_script->doVerb();
}
} else {
if (recurse && (actor->flags & kFollower))
walkMore = followProtagonist(actor);
_vm->_script->wakeUpActorThread(kWaitTypeWalk, actor);
}
return walkMore;
}
bool Actor::actorWalkTo(uint16 actorId, const Location &toLocation) {
ActorData *actor;
ActorData *anotherActor;
int i;
Rect testBox;
Rect testBox2;
Point anotherActorScreenPosition;
Point collision;
Point pointFrom, pointTo, pointBest, pointAdd;
Point delta, bestDelta;
Point tempPoint;
bool extraStartNode;
bool extraEndNode;
actor = getActor(actorId);
if (actor == _protagonist) {
_vm->_scene->setDoorState(2, 0xff);
_vm->_scene->setDoorState(3, 0);
} else {
_vm->_scene->setDoorState(2, 0);
_vm->_scene->setDoorState(3, 0xff);
}
if (_vm->_scene->getFlags() & kSceneFlagISO) {
if ((_vm->getGameType() == GType_ITE) && (actor->index == ACTOR_DRAGON_INDEX)) {
return false;
}
actor->finalTarget = toLocation;
actor->walkStepsCount = 0;
_vm->_isoMap->findTilePath(actor, actor->location, toLocation);
if ((actor->walkStepsCount == 0) && (actor->flags & kProtagonist)) {
actor->actorFlags |= kActorNoCollide;
_vm->_isoMap->findTilePath(actor, actor->location, toLocation);
}
actor->walkStepIndex = 0;
if (_vm->_isoMap->nextTileTarget(actor)) {
actor->currentAction = kActionWalkToPoint;
actor->walkFrameSequence = kFrameWalk;
} else {
actorEndWalk( actorId, false);
return false;
}
} else {
actor->location.toScreenPointXY(pointFrom);
pointFrom.x &= ~1;
extraStartNode = _vm->_scene->offscreenPath(pointFrom);
toLocation.toScreenPointXY(pointTo);
pointTo.x &= ~1;
extraEndNode = _vm->_scene->offscreenPath(pointTo);
if (_vm->_scene->isBGMaskPresent()) {
if ((((actor->currentAction >= kActionWalkToPoint) &&
(actor->currentAction <= kActionWalkDir)) || (actor == _protagonist)) &&
!_vm->_scene->canWalk(pointFrom)) {
for (i = 1; i < 8; i++) {
pointAdd = pointFrom;
pointAdd.y += i;
if (_vm->_scene->canWalk(pointAdd)) {
pointFrom = pointAdd;
break;
}
pointAdd = pointFrom;
pointAdd.y -= i;
if (_vm->_scene->canWalk(pointAdd)) {
pointFrom = pointAdd;
break;
}
pointAdd = pointFrom;
pointAdd.x += i;
if (_vm->_scene->canWalk(pointAdd)) {
pointFrom = pointAdd;
break;
}
pointAdd = pointFrom;
pointAdd.x -= i;
if (_vm->_scene->canWalk(pointAdd)) {
pointFrom = pointAdd;
break;
}
}
}
if (!(actor->actorFlags & kActorNoCollide)) {
collision.x = ACTOR_COLLISION_WIDTH * actor->screenScale / (256 * 2);
collision.y = ACTOR_COLLISION_HEIGHT * actor->screenScale / (256 * 2);
_barrierCount = 0;
for (i = 0; (i < _actorsCount) && (_barrierCount < ACTOR_BARRIERS_MAX); i++) {
anotherActor = _actors[i];
if (!anotherActor->inScene) continue;
if (anotherActor == actor ) continue;
anotherActorScreenPosition = anotherActor->screenPosition;
testBox.left = (anotherActorScreenPosition.x - collision.x) & ~1;
testBox.right = (anotherActorScreenPosition.x + collision.x) & ~1 + 1;
testBox.top = anotherActorScreenPosition.y - collision.y;
testBox.bottom = anotherActorScreenPosition.y + collision.y + 1;
testBox2 = testBox;
testBox2.right += 2;
testBox2.left -= 2;
testBox2.top -= 1;
testBox2.bottom += 1;
if (testBox2.contains(pointFrom)) {
if (pointFrom.x > anotherActorScreenPosition.x + 4) {
testBox.right = pointFrom.x - 1;
} else if (pointFrom.x < anotherActorScreenPosition.x - 4) {
testBox.left = pointFrom.x + 2;
} else if (pointFrom.y > anotherActorScreenPosition.y) {
testBox.bottom = pointFrom.y;
} else {
testBox.top = pointFrom.y + 1 ;
}
}
if ((testBox.width() > 0) && (testBox.height() > 0)) {
_barrierList[_barrierCount++] = testBox;
}
}
}
pointBest = pointTo;
actor->walkStepsCount = 0;
findActorPath(actor, pointFrom, pointTo);
if (actor->walkStepsCount == 0) {
error("actor->walkStepsCount == 0");
}
if (extraStartNode) {
actor->walkStepIndex = 0;
} else {
actor->walkStepIndex = 1;
}
if (extraEndNode) {
toLocation.toScreenPointXY(tempPoint);
actor->walkStepsCount--;
actor->addWalkStepPoint(tempPoint);
}
pointBest = actor->walkStepsPoints[actor->walkStepsCount - 1];
delta.x = ABS(pointFrom.x - pointTo.x);
delta.y = ABS(pointFrom.y - pointTo.y);
bestDelta.x = ABS(pointBest.x - pointTo.x);
bestDelta.y = ABS(pointBest.y - pointTo.y);
if (delta.x + delta.y <= bestDelta.x + bestDelta.y && (actor->flags & kFollower)) {
actor->actorFlags |= kActorNoFollow;
}
if (pointBest == pointFrom) {
actor->walkStepsCount = 0;
}
} else {
actor->walkStepsCount = 0;
actor->addWalkStepPoint(pointTo);
actor->walkStepIndex = 0;
}
actor->partialTarget = actor->location;
actor->finalTarget = toLocation;
if (actor->walkStepsCount == 0) {
actorEndWalk(actorId, false);
return false;
} else {
if (actor->flags & kProtagonist) {
_actors[1]->actorFlags &= ~kActorNoFollow; // TODO: mark all actors with kFollower flag, not only 1 and 2
_actors[2]->actorFlags &= ~kActorNoFollow;
}
actor->currentAction = (actor->walkStepsCount >= ACTOR_MAX_STEPS_COUNT) ? kActionWalkToLink : kActionWalkToPoint;
actor->walkFrameSequence = kFrameWalk;
}
}
return true;
}
void Actor::actorSpeech(uint16 actorId, const char **strings, int stringsCount, int sampleResourceId, int speechFlags) {
ActorData *actor;
int i;
int16 dist;
if (_vm->getGameType() == GType_IHNM) {
warning("Actors aren't implemented for IHNM yet");
return;
}
actor = getActor(actorId);
calcScreenPosition(actor);
for (i = 0; i < stringsCount; i++) {
_activeSpeech.strings[i] = strings[i];
}
_activeSpeech.stringsCount = stringsCount;
_activeSpeech.speechFlags = speechFlags;
_activeSpeech.actorsCount = 1;
_activeSpeech.actorIds[0] = actorId;
_activeSpeech.speechColor[0] = actor->speechColor;
_activeSpeech.outlineColor[0] = kITEColorBlack;
_activeSpeech.sampleResourceId = sampleResourceId;
_activeSpeech.playing = false;
_activeSpeech.slowModeCharIndex = 0;
dist = MIN(actor->screenPosition.x - 10, _vm->getDisplayWidth() - 10 - actor->screenPosition.x );
dist = clamp( 60, dist, 150 );
_activeSpeech.speechBox.left = actor->screenPosition.x - dist;
_activeSpeech.speechBox.right = actor->screenPosition.x + dist;
if (_activeSpeech.speechBox.left < 10) {
_activeSpeech.speechBox.right += 10 - _activeSpeech.speechBox.left;
_activeSpeech.speechBox.left = 10;
}
if (_activeSpeech.speechBox.right > _vm->getDisplayWidth() - 10) {
_activeSpeech.speechBox.left -= _activeSpeech.speechBox.right - _vm->getDisplayWidth() - 10;
_activeSpeech.speechBox.right = _vm->getDisplayWidth() - 10;
}
}
void Actor::nonActorSpeech(const Common::Rect &box, const char **strings, int stringsCount, int sampleResourceId, int speechFlags) {
int i;
_vm->_script->wakeUpThreads(kWaitTypeSpeech);
for (i = 0; i < stringsCount; i++) {
_activeSpeech.strings[i] = strings[i];
}
_activeSpeech.stringsCount = stringsCount;
_activeSpeech.speechFlags = speechFlags;
_activeSpeech.actorsCount = 1;
_activeSpeech.actorIds[0] = 0;
_activeSpeech.sampleResourceId = sampleResourceId;
_activeSpeech.playing = false;
_activeSpeech.slowModeCharIndex = 0;
_activeSpeech.speechBox = box;
}
void Actor::simulSpeech(const char *string, uint16 *actorIds, int actorIdsCount, int speechFlags, int sampleResourceId) {
int i;
if (_vm->getGameType() == GType_IHNM) {
warning("Actors aren't implemented for IHNM yet");
return;
}
for (i = 0; i < actorIdsCount; i++) {
ActorData *actor;
actor = getActor(actorIds[i]);
_activeSpeech.actorIds[i] = actorIds[i];
_activeSpeech.speechColor[i] = actor->speechColor;
_activeSpeech.outlineColor[i] = 0; // disable outline
}
_activeSpeech.actorsCount = actorIdsCount;
_activeSpeech.strings[0] = string;
_activeSpeech.stringsCount = 1;
_activeSpeech.speechFlags = speechFlags;
_activeSpeech.sampleResourceId = sampleResourceId;
_activeSpeech.playing = false;
_activeSpeech.slowModeCharIndex = 0;
// caller should call thread->wait(kWaitTypeSpeech) by itself
}
void Actor::abortAllSpeeches() {
abortSpeech();
if (_vm->_script->_abortEnabled)
_vm->_script->_skipSpeeches = true;
for (int i = 0; i < 10; i++)
_vm->_script->executeThreads(0);
}
void Actor::abortSpeech() {
_vm->_sound->stopVoice();
_activeSpeech.playingTime = 0;
}
void Actor::moveDragon(ActorData *actor) {
int16 dir0, dir1, dir2, dir3;
int16 moveType;
EVENT event;
const DragonMove *dragonMove;
if ((actor->actionCycle < 0) ||
((actor->actionCycle == 0) && (actor->dragonMoveType >= ACTOR_DRAGON_TURN_MOVES))) {
moveType = kDragonMoveInvalid;
if (actor->location.distance(_protagonist->location) < 24) {
if (_dragonHunt && (_protagonist->currentAction != kActionFall)) {
event.type = ONESHOT_EVENT;
event.code = SCRIPT_EVENT;
event.op = EVENT_EXEC_NONBLOCKING;
event.time = 0;
event.param = _vm->_scene->getScriptModuleNumber(); // module number
event.param2 = ACTOR_EXP_KNOCK_RIF; // script entry point number
event.param3 = -1; // Action
event.param4 = -1; // Object
event.param5 = -1; // With Object
event.param6 = -1; // Actor
_vm->_events->queue(&event);
_dragonHunt = false;
}
} else {
_dragonHunt = true;
}
if (actor->walkStepIndex + 2 > actor->walkStepsCount) {
_vm->_isoMap->findDragonTilePath(actor, actor->location, _protagonist->location, actor->actionDirection);
if (actor->walkStepsCount == 0) {
_vm->_isoMap->findDragonTilePath(actor, actor->location, _protagonist->location, 0);
}
if (actor->walkStepsCount < 2) {
return;
}
actor->partialTarget = actor->location;
actor->finalTarget = _protagonist->location;
actor->walkStepIndex = 0;
}
dir0 = actor->actionDirection;
dir1 = actor->tileDirections[actor->walkStepIndex++];
dir2 = actor->tileDirections[actor->walkStepIndex];
dir3 = actor->tileDirections[actor->walkStepIndex + 1];
if (dir0 != dir1){
actor->actionDirection = dir0 = dir1;
}
actor->location = actor->partialTarget;
if ((dir1 != dir2) && (dir1 == dir3)) {
switch (dir1) {
case kDirUpLeft:
actor->partialTarget.v() += 16;
moveType = kDragonMoveUpLeft;
break;
case kDirDownLeft:
actor->partialTarget.u() -= 16;
moveType = kDragonMoveDownLeft;
break;
case kDirDownRight:
actor->partialTarget.v() -= 16;
moveType = kDragonMoveDownRight;
break;
case kDirUpRight:
actor->partialTarget.u() += 16;
moveType = kDragonMoveUpRight;
break;
}
switch (dir2) {
case kDirUpLeft:
actor->partialTarget.v() += 16;
break;
case kDirDownLeft:
actor->partialTarget.u() -= 16;
break;
case kDirDownRight:
actor->partialTarget.v() -= 16;
break;
case kDirUpRight:
actor->partialTarget.u() += 16;
break;
}
actor->walkStepIndex++;
} else {
switch (dir1) {
case kDirUpLeft:
actor->partialTarget.v() += 16;
switch (dir2) {
case kDirDownLeft:
moveType = kDragonMoveUpLeft_Left;
actor->partialTarget.u() -= 16;
break;
case kDirUpLeft:
moveType = kDragonMoveUpLeft;
break;
case kDirUpRight:
actor->partialTarget.u() += 16;
moveType = kDragonMoveUpLeft_Right;
break;
default:
actor->actionDirection = dir1;
actor->walkStepsCount = 0;
break;
}
break;
case kDirDownLeft:
actor->partialTarget.u() -= 16;
switch (dir2) {
case kDirDownRight:
moveType = kDragonMoveDownLeft_Left;
actor->partialTarget.v() -= 16;
break;
case kDirDownLeft:
moveType = kDragonMoveDownLeft;
break;
case kDirUpLeft:
moveType = kDragonMoveDownLeft_Right;
actor->partialTarget.v() += 16;
break;
default:
actor->actionDirection = dir1;
actor->walkStepsCount = 0;
break;
}
break;
case kDirDownRight:
actor->partialTarget.v() -= 16;
switch (dir2) {
case kDirUpRight:
moveType = kDragonMoveDownRight_Left;
actor->partialTarget.u() += 16;
break;
case kDirDownRight:
moveType = kDragonMoveDownRight;
break;
case kDirDownLeft:
moveType = kDragonMoveDownRight_Right;
actor->partialTarget.u() -= 16;
break;
default:
actor->actionDirection = dir1;
actor->walkStepsCount = 0;
break;
}
break;
case kDirUpRight:
actor->partialTarget.u() += 16;
switch (dir2) {
case kDirUpLeft:
moveType = kDragonMoveUpRight_Left;
actor->partialTarget.v() += 16;
break;
case kDirUpRight:
moveType = kDragonMoveUpRight;
break;
case kDirDownRight:
moveType = kDragonMoveUpRight_Right;
actor->partialTarget.v() -= 16;
break;
default:
actor->actionDirection = dir1;
actor->walkStepsCount = 0;
break;
}
break;
default:
actor->actionDirection = dir1;
actor->walkStepsCount = 0;
break;
}
}
actor->dragonMoveType = moveType;
if (moveType >= ACTOR_DRAGON_TURN_MOVES) {
actor->dragonStepCycle = 0;
actor->actionCycle = 4;
actor->walkStepIndex++;
} else {
actor->actionCycle = 4;
}
}
actor->actionCycle--;
if ((actor->walkStepsCount < 1) || (actor->actionCycle < 0)) {
return;
}
if (actor->dragonMoveType < ACTOR_DRAGON_TURN_MOVES) {
actor->dragonStepCycle++;
if (actor->dragonStepCycle >= 7) {
actor->dragonStepCycle = 0;
}
actor->dragonBaseFrame = actor->dragonMoveType * 7;
if (actor->location.u() > actor->partialTarget.u() + 3) {
actor->location.u() -= 4;
} else if (actor->location.u() < actor->partialTarget.u() - 3) {
actor->location.u() += 4;
} else {
actor->location.u() = actor->partialTarget.u();
}
if (actor->location.v() > actor->partialTarget.v() + 3) {
actor->location.v() -= 4;
} else if (actor->location.v() < actor->partialTarget.v() - 3) {
actor->location.v() += 4;
} else {
actor->location.v() = actor->partialTarget.v();
}
} else {
dragonMove = &dragonMoveTable[actor->dragonMoveType];
actor->dragonBaseFrame = dragonMove->baseFrame;
actor->location.u() = actor->partialTarget.u() - dragonMove->offset[actor->actionCycle][0];
actor->location.v() = actor->partialTarget.v() - dragonMove->offset[actor->actionCycle][1];
actor->dragonStepCycle++;
if (actor->dragonStepCycle >= 3) {
actor->dragonStepCycle = 3;
}
}
actor->frameNumber = actor->dragonBaseFrame + actor->dragonStepCycle;
}
void Actor::findActorPath(ActorData *actor, const Point &fromPoint, const Point &toPoint) {
Point iteratorPoint;
Point bestPoint;
int maskType;
int i;
Rect intersect;
#ifdef ACTOR_DEBUG
_debugPointsCount = 0;
#endif
actor->walkStepsCount = 0;
if (fromPoint == toPoint) {
actor->addWalkStepPoint(toPoint);
return;
}
for (iteratorPoint.y = 0; iteratorPoint.y < _yCellCount; iteratorPoint.y++) {
for (iteratorPoint.x = 0; iteratorPoint.x < _xCellCount; iteratorPoint.x++) {
if (_vm->_scene->validBGMaskPoint(iteratorPoint)) {
maskType = _vm->_scene->getBGMaskType(iteratorPoint);
setPathCell(iteratorPoint, _vm->_scene->getDoorState(maskType) ? kPathCellBarrier : kPathCellEmpty);
} else {
setPathCell(iteratorPoint, kPathCellBarrier);
}
}
}
for (i = 0; i < _barrierCount; i++) {
intersect.left = MAX(_pathRect.left, _barrierList[i].left);
intersect.top = MAX(_pathRect.top, _barrierList[i].top);
intersect.right = MIN(_pathRect.right, _barrierList[i].right);
intersect.bottom = MIN(_pathRect.bottom, _barrierList[i].bottom);
for (iteratorPoint.y = intersect.top; iteratorPoint.y < intersect.bottom; iteratorPoint.y++) {
for (iteratorPoint.x = intersect.left; iteratorPoint.x < intersect.right; iteratorPoint.x++) {
setPathCell(iteratorPoint, kPathCellBarrier);
}
}
}
#ifdef ACTOR_DEBUG
for (iteratorPoint.y = 0; iteratorPoint.y < _yCellCount; iteratorPoint.y++) {
for (iteratorPoint.x = 0; iteratorPoint.x < _xCellCount; iteratorPoint.x++) {
if (getPathCell(iteratorPoint) == kPathCellBarrier) {
addDebugPoint(iteratorPoint, 24);
}
}
}
#endif
if (scanPathLine(fromPoint, toPoint)) {
actor->addWalkStepPoint(fromPoint);
actor->addWalkStepPoint(toPoint);
return;
}
i = fillPathArray(fromPoint, toPoint, bestPoint);
if (fromPoint == bestPoint) {
actor->addWalkStepPoint(bestPoint);
return;
}
if (i == 0) {
error("fillPathArray returns zero");
}
setActorPath(actor, fromPoint, bestPoint);
}
bool Actor::scanPathLine(const Point &point1, const Point &point2) {
Point point;
Point delta;
bool interchange = false;
Point fDelta;
int errterm;
int s1;
int s2;
int i;
point = point1;
delta.x = ABS(point1.x - point2.x);
delta.y = ABS(point1.y - point2.y);
s1 = integerCompare(point2.x, point1.x);
s2 = integerCompare(point2.y, point1.y);
if (delta.y > delta.x) {
SWAP(delta.y, delta.x);
interchange = true;
}
fDelta.x = delta.x * 2;
fDelta.y = delta.y * 2;
errterm = fDelta.y - delta.x;
for (i = 0; i < delta.x; i++) {
while (errterm >= 0) {
if (interchange) {
point.x += s1;
} else {
point.y += s2;
}
errterm -= fDelta.x;
}
if (interchange)
point.y += s2;
else
point.x += s1;
errterm += fDelta.y;
if (!validPathCellPoint(point)) {
return false;
}
if (getPathCell(point) == kPathCellBarrier) {
return false;
}
}
return true;
}
int Actor::fillPathArray(const Point &fromPoint, const Point &toPoint, Point &bestPoint) {
int bestRating;
int currentRating;
int i;
Point bestPath;
int pointCounter;
int startDirection;
PathDirectionData *pathDirection;
PathDirectionData *newPathDirection;
const PathDirectionData *samplePathDirection;
Point nextPoint;
int directionCount;
_pathDirectionListCount = 0;
pointCounter = 0;
bestRating = quickDistance(fromPoint, toPoint);
bestPath = fromPoint;
for (startDirection = 0; startDirection < 4; startDirection++) {
newPathDirection = addPathDirectionListData();
newPathDirection->x = fromPoint.x;
newPathDirection->y = fromPoint.y;
newPathDirection->direction = startDirection;
}
if (validPathCellPoint(fromPoint)) {
setPathCell(fromPoint, kDirUp);
#ifdef ACTOR_DEBUG
addDebugPoint(fromPoint, 24+36);
#endif
}
i = 0;
do {
pathDirection = &_pathDirectionList[i];
for (directionCount = 0; directionCount < 3; directionCount++) {
samplePathDirection = &pathDirectionLUT[pathDirection->direction][directionCount];
nextPoint.x = samplePathDirection->x + pathDirection->x;
nextPoint.y = samplePathDirection->y + pathDirection->y;
if (!validPathCellPoint(nextPoint)) {
continue;
}
if (getPathCell(nextPoint) != kPathCellEmpty) {
continue;
}
setPathCell(nextPoint, samplePathDirection->direction);
#ifdef ACTOR_DEBUG
addDebugPoint(nextPoint, samplePathDirection->direction + 96);
#endif
newPathDirection = addPathDirectionListData();
newPathDirection->x = nextPoint.x;
newPathDirection->y = nextPoint.y;
newPathDirection->direction = samplePathDirection->direction;
++pointCounter;
if (nextPoint == toPoint) {
bestPoint = toPoint;
return pointCounter;
}
currentRating = quickDistance(nextPoint, toPoint);
if (currentRating < bestRating) {
bestRating = currentRating;
bestPath = nextPoint;
}
pathDirection = &_pathDirectionList[i];
}
++i;
} while (i < _pathDirectionListCount);
bestPoint = bestPath;
return pointCounter;
}
void Actor::setActorPath(ActorData *actor, const Point &fromPoint, const Point &toPoint) {
Point nextPoint;
int8 direction;
int i;
_pathListIndex = -1;
addPathListPoint(toPoint);
nextPoint = toPoint;
while ( !(nextPoint == fromPoint)) {
direction = getPathCell(nextPoint);
if ((direction < 0) || (direction >= 8)) {
error("Actor::setActorPath error direction 0x%X", direction);
}
nextPoint.x -= pathDirectionLUT2[direction][0];
nextPoint.y -= pathDirectionLUT2[direction][1];
addPathListPoint(nextPoint);
#ifdef ACTOR_DEBUG
addDebugPoint(nextPoint, 0x8a);
#endif
}
pathToNode();
removeNodes();
nodeToPath();
removePathPoints();
for (i = 0; i <= _pathNodeListIndex; i++) {
actor->addWalkStepPoint(_pathNodeList[i].point);
}
}
void Actor::pathToNode() {
Point point1, point2, delta;
int direction;
int i;
Point *point;
point= &_pathList[_pathListIndex];
direction = 0;
_pathNodeListIndex = -1;
addPathNodeListPoint(*point);
for (i = _pathListIndex; i > 0; i--) {
point1 = *point;
--point;
point2 = *point;
if (direction == 0) {
delta.x = integerCompare(point2.x, point1.x);
delta.y = integerCompare(point2.y, point1.y);
direction++;
}
if ((point1.x + delta.x != point2.x) || (point1.y + delta.y != point2.y)) {
addPathNodeListPoint(point1);
direction--;
i++;
point++;
}
}
addPathNodeListPoint(*_pathList);
}
int pathLine(Point *pointList, const Point &point1, const Point &point2) {
Point point;
Point delta;
Point tempPoint;
int s1;
int s2;
bool interchange = false;
int errterm;
int i;
delta.x = abs(point2.x - point1.x);
delta.y = abs(point2.y - point1.y);
point = point1;
s1 = integerCompare(point2.x, point1.x);
s2 = integerCompare(point2.y, point1.y);
if (delta.y > delta.x) {
SWAP(delta.y, delta.x);
interchange = true;
}
tempPoint.x = delta.x * 2;
tempPoint.y = delta.y * 2;
errterm = tempPoint.y - delta.x;
for (i = 0; i < delta.x; i++) {
while (errterm >= 0) {
if (interchange) {
point.x += s1;
} else {
point.y += s2;
}
errterm -= tempPoint.x;
}
if (interchange) {
point.y += s2;
} else {
point.x += s1;
}
errterm += tempPoint.y;
pointList[i] = point;
}
return delta.x;
}
void Actor::nodeToPath() {
int i;
Point point1, point2;
PathNode *node;
Point *point;
for (i = 0, point = _pathList; i < _pathListAlloced; i++, point++) {
point->x = point->y = PATH_NODE_EMPTY;
}
_pathListIndex = 1;
_pathList[0] = _pathNodeList[0].point;
_pathNodeList[0].link = 0;
for (i = 0, node = _pathNodeList; i < _pathNodeListIndex; i++) {
point1 = node->point;
node++;
point2 = node->point;
_pathListIndex += pathLine(&_pathList[_pathListIndex], point1, point2);
node->link = _pathListIndex - 1;
}
_pathListIndex--;
_pathNodeList[_pathNodeListIndex].link = _pathListIndex;
}
void Actor::removeNodes() {
int i, j, k;
PathNode *iNode, *jNode, *kNode, *fNode;
fNode = &_pathNodeList[_pathNodeListIndex];
if (scanPathLine(_pathNodeList[0].point, fNode->point)) {
_pathNodeList[1] = *fNode;
_pathNodeListIndex = 1;
}
if (_pathNodeListIndex < 4) {
return;
}
for (i = _pathNodeListIndex - 1, iNode = fNode-1; i > 1 ; i--, iNode--) {
if (iNode->point.x == PATH_NODE_EMPTY) {
continue;
}
if (scanPathLine(_pathNodeList[0].point, iNode->point)) {
for (j = 1, jNode = _pathNodeList + 1; j < i; j++, jNode++) {
jNode->point.x = PATH_NODE_EMPTY;
}
}
}
for (i = 1, iNode = _pathNodeList + 1; i < _pathNodeListIndex - 1; i++, iNode++) {
if (iNode->point.x == PATH_NODE_EMPTY) {
continue;
}
if (scanPathLine(fNode->point, iNode->point)) {
for (j = i + 1, jNode = iNode + 1; j < _pathNodeListIndex; j++, jNode++) {
jNode->point.x = PATH_NODE_EMPTY;
}
}
}
condenseNodeList();
for (i = 1, iNode = _pathNodeList + 1; i < _pathNodeListIndex - 1; i++, iNode++) {
if (iNode->point.x == PATH_NODE_EMPTY) {
continue;
}
for (j = i + 2, jNode = iNode + 2; j < _pathNodeListIndex; j++, jNode++) {
if (jNode->point.x == PATH_NODE_EMPTY) {
continue;
}
if (scanPathLine(iNode->point, jNode->point)) {
for (k = i + 1,kNode = iNode + 1; k < j; k++, kNode++) {
kNode->point.x = PATH_NODE_EMPTY;
}
}
}
}
condenseNodeList();
}
void Actor::condenseNodeList() {
int i, j, count;
PathNode *iNode, *jNode;
count = _pathNodeListIndex;
for (i = 1, iNode = _pathNodeList + 1; i < _pathNodeListIndex; i++, iNode++) {
if (iNode->point.x == PATH_NODE_EMPTY) {
j = i + 1;
jNode = iNode + 1;
while ( jNode->point.x == PATH_NODE_EMPTY ) {
j++;
jNode++;
}
*iNode = *jNode;
count = i;
jNode->point.x = PATH_NODE_EMPTY;
if (j == _pathNodeListIndex) {
break;
}
}
}
_pathNodeListIndex = count;
}
void Actor::removePathPoints() {
int i, j, k, l;
PathNode *node;
int start;
int end;
Point point1, point2;
if (_pathNodeListIndex < 2)
return;
_newPathNodeListIndex = -1;
addNewPathNodeListPoint(_pathNodeList[0]);
for (i = 1, node = _pathNodeList + 1; i < _pathNodeListIndex; i++, node++) {
addNewPathNodeListPoint(*node);
for (j = 5; j > 0; j--) {
start = node->link - j;
end = node->link + j;
if (start < 0 || end > _pathListIndex) {
continue;
}
point1 = _pathList[start];
point2 = _pathList[end];
if ((point1.x == PATH_NODE_EMPTY) || (point2.x == PATH_NODE_EMPTY)) {
continue;
}
if (scanPathLine(point1, point2)) {
for (l = 1; l <= _newPathNodeListIndex; l++) {
if (start <= _newPathNodeList[l].link) {
_newPathNodeListIndex = l;
_newPathNodeList[_newPathNodeListIndex].point = point1;
_newPathNodeList[_newPathNodeListIndex].link = start;
incrementNewPathNodeListIndex();
break;
}
}
_newPathNodeList[_newPathNodeListIndex].point = point2;
_newPathNodeList[_newPathNodeListIndex].link = end;
for (k = start + 1; k < end; k++) {
_pathList[k].x = PATH_NODE_EMPTY;
}
break;
}
}
}
addNewPathNodeListPoint(_pathNodeList[_pathNodeListIndex]);
for (i = 0, j = 0; i <= _newPathNodeListIndex; i++) {
if (_newPathNodeListIndex == i || (_newPathNodeList[i].point != _newPathNodeList[i+1].point)) {
_pathNodeList[j++] = _newPathNodeList[i];
}
}
_pathNodeListIndex = j - 1;
}
void Actor::drawPathTest() {
#ifdef ACTOR_DEBUG
int i;
Surface *surface;
surface = _vm->_gfx->getBackBuffer();
if (_debugPoints == NULL) {
return;
}
for (i = 0; i < _debugPointsCount; i++) {
*((byte *)surface->pixels + (_debugPoints[i].point.y * surface->pitch) + _debugPoints[i].point.x) = _debugPoints[i].color;
}
#endif
}
void Actor::saveState(Common::OutSaveFile *out) {
uint16 i;
out->writeSint16LE(getProtagState());
for (i = 0; i < _actorsCount; i++) {
ActorData *a = _actors[i];
a->saveState(out);
}
for (i = 0; i < _objsCount; i++) {
ObjectData *o = _objs[i];
o->saveState(out);
}
}
void Actor::loadState(Common::InSaveFile *in) {
int32 i;
setProtagState(in->readSint16LE());
for (i = 0; i < _actorsCount; i++) {
ActorData *a = _actors[i];
a->loadState(in);
}
for (i = 0; i < _objsCount; i++) {
ObjectData *o = _objs[i];
o->loadState(in);
}
}
// Console wrappers - must be safe to run
void Actor::cmdActorWalkTo(int argc, const char **argv) {
uint16 actorId = (uint16) atoi(argv[1]);
Location location;
Point movePoint;
movePoint.x = atoi(argv[2]);
movePoint.y = atoi(argv[3]);
location.fromScreenPoint(movePoint);
if (!validActorId(actorId)) {
_vm->_console->DebugPrintf("Actor::cmActorWalkTo Invalid actorId 0x%X.\n", actorId);
return;
}
actorWalkTo(actorId, location);
}
} // End of namespace Saga
|