[8e2649]: gemrb / core / Scriptable / Scriptable.cpp  Maximize  Restore  History

Download this file

2112 lines (1875 with data), 52.9 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
/* GemRB - Infinity Engine Emulator
* Copyright (C) 2003-2005 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.
*
*/
#include "Scriptable/Scriptable.h"
#include "win32def.h"
#include "strrefs.h"
#include "ie_cursors.h"
#include "Audio.h"
#include "DisplayMessage.h"
#include "Game.h"
#include "GameData.h"
#include "Interface.h"
#include "Item.h"
#include "Font.h"
#include "Map.h"
#include "Projectile.h"
#include "Spell.h"
#include "SpriteCover.h"
#include "TileMap.h"
#include "Video.h"
#include "GameScript/GSUtils.h"
#include "GameScript/Matching.h" // MatchActor
#include "GUI/GameControl.h"
//#include "GUI/Window.h"
#include "Scriptable/InfoPoint.h"
#include <cassert>
#include <cmath>
#define YESNO(x) ( (x)?"Yes":"No")
// we start this at a non-zero value to make debugging easier
static ieDword globalActorCounter = 10000;
/***********************
* Scriptable Class *
***********************/
Scriptable::Scriptable(ScriptableType type)
{
Type = type;
for (int i = 0; i < MAX_SCRIPTS; i++) {
Scripts[i] = NULL;
}
overHeadText = NULL;
overHeadTextPos.empty();
textDisplaying = 0;
timeStartDisplaying = 0;
scriptName[0] = 0;
LastAttacker = 0;
LastCommander = 0;
LastProtector = 0;
LastProtectee = 0;
LastTargetedBy = 0;
LastHitter = 0;
LastHelp = 0;
LastTrigger = 0;
LastSeen = 0;
LastTalker = 0;
LastHeard = 0;
LastSummoner = 0;
LastFollowed = 0;
LastMarked = 0;
LastMarkedSpell = 0;
DialogName = 0;
CurrentAction = NULL;
CurrentActionState = 0;
CurrentActionTarget = 0;
CurrentActionInterruptable = true;
CurrentActionTicks = 0;
UnselectableTimer = 0;
Ticks = 0;
AdjustedTicks = 0;
ScriptTicks = 0;
IdleTicks = 0;
AuraTicks = 100;
TriggerCountdown = 0;
Dialog[0] = 0;
globalID = ++globalActorCounter;
WaitCounter = 0;
if (Type == ST_ACTOR) {
InternalFlags = IF_VISIBLE | IF_USEDSAVE;
} else {
InternalFlags = IF_ACTIVE | IF_VISIBLE | IF_NOINT;
}
area = 0;
Pos.x = 0;
Pos.y = 0;
LastSpellOnMe = 0xffffffff;
SpellHeader = -1;
SpellResRef[0] = 0;
LastTarget = 0;
LastTargetPos.empty();
InterruptCasting = false;
locals = new Variables();
locals->SetType( GEM_VARIABLES_INT );
locals->ParseKey( 1 );
InitTriggers();
AddTrigger(TriggerEntry(trigger_oncreation));
memset( script_timers,0, sizeof(script_timers));
}
Scriptable::~Scriptable(void)
{
if (CurrentAction) {
ReleaseCurrentAction();
}
ClearActions();
for (int i = 0; i < MAX_SCRIPTS; i++) {
if (Scripts[i]) {
delete( Scripts[i] );
}
}
if (overHeadText) {
core->FreeString( overHeadText );
}
if (locals) {
delete( locals );
}
}
void Scriptable::SetScriptName(const char* text)
{
//if (text && text[0]) { //this leaves some uninitialized bytes
//lets hope this won't break anything
if (text) {
strnspccpy( scriptName, text, 32 );
}
}
/** Gets the DeathVariable */
const char* Scriptable::GetScriptName(void) const
{
return scriptName;
}
void Scriptable::SetDialog(const char *resref) {
if (gamedata->Exists(resref, IE_DLG_CLASS_ID) ) {
strnuprcpy(Dialog, resref, 8);
}
}
Map* Scriptable::GetCurrentArea() const
{
//this could be NULL, always check it
return area;
}
void Scriptable::SetMap(Map *map)
{
if (map && (map->GetCurrentArea()!=map)) {
//a map always points to itself (if it is a real map)
error("Scriptable", "Invalid map set!\n");
}
area = map;
}
//ai is nonzero if this is an actor currently in the party
//if the script level is AI_SCRIPT_LEVEL, then we need to
//load an AI script (.bs) instead of (.bcs)
void Scriptable::SetScript(const ieResRef aScript, int idx, bool ai)
{
if (idx >= MAX_SCRIPTS) {
error("Scriptable", "Invalid script index!\n");
}
if (Scripts[idx]) {
delete Scripts[idx];
}
Scripts[idx] = NULL;
// NONE is an 'invalid' script name, never used seriously
// This hack is to prevent flooding of the console
if (aScript[0] && stricmp(aScript, "NONE") ) {
if (idx!=AI_SCRIPT_LEVEL) ai = false;
Scripts[idx] = new GameScript( aScript, this, idx, ai );
}
}
void Scriptable::SetScript(int index, GameScript* script)
{
if (index >= MAX_SCRIPTS) {
printMessage("Scriptable","Invalid script index!\n",LIGHT_RED);
return;
}
if (Scripts[index] ) {
delete Scripts[index];
}
Scripts[index] = script;
}
void Scriptable::SetSpellResRef(ieResRef resref) {
strnuprcpy(SpellResRef, resref, 8);
}
void Scriptable::DisplayHeadText(const char* text)
{
if (overHeadText) {
core->FreeString( overHeadText );
}
overHeadText = (char *) text;
overHeadTextPos.empty();
if (text) {
timeStartDisplaying = core->GetGame()->Ticks;
textDisplaying = 1;
}
else {
timeStartDisplaying = 0;
textDisplaying = 0;
}
}
/* 'fix' the current overhead text in the current position */
void Scriptable::FixHeadTextPos()
{
overHeadTextPos = Pos;
}
#define MAX_DELAY 6000
static const Color black={0,0,0,0};
void Scriptable::DrawOverheadText(const Region &screen)
{
unsigned long time = core->GetGame()->Ticks;
Palette *palette = NULL;
if (!textDisplaying)
return;
time -= timeStartDisplaying;
Font* font = core->GetFont( 1 );
if (time >= MAX_DELAY) {
textDisplaying = 0;
return;
} else {
time = (MAX_DELAY-time)/10;
if (time<256) {
const Color overHeadColor = {time,time,time,time};
palette = core->CreatePalette(overHeadColor, black);
}
}
int cs = 100;
if (Type == ST_ACTOR) {
cs = ((Selectable *) this)->size*50;
}
short x, y;
if (overHeadTextPos.isempty()) {
x = Pos.x;
y = Pos.y;
} else {
x = overHeadTextPos.x;
y = overHeadTextPos.y;
}
Region rgn( x-100+screen.x, y - cs + screen.y, 200, 400 );
font->Print( rgn, ( unsigned char * ) overHeadText,
palette?palette:core->InfoTextPalette, IE_FONT_ALIGN_CENTER | IE_FONT_ALIGN_TOP, false );
gamedata->FreePalette(palette);
}
void Scriptable::ImmediateEvent()
{
InternalFlags |= IF_FORCEUPDATE;
}
bool Scriptable::IsPC() const
{
if(Type == ST_ACTOR) {
if (((Actor *) this)->GetStat(IE_EA) <= EA_CHARMED) {
return true;
}
}
return false;
}
void Scriptable::Update()
{
Ticks++;
AdjustedTicks++;
AuraTicks++;
Actor *act = NULL;
if (Type == ST_ACTOR) {
act = (Actor *) this;
}
if (UnselectableTimer) {
UnselectableTimer--;
if (!UnselectableTimer) {
if (act) {
act->SetCircleSize();
}
}
}
TickScripting();
ProcessActions();
InterruptCasting = false;
}
void Scriptable::TickScripting()
{
// Stagger script updates.
if (Ticks % 16 != globalID % 16)
return;
ieDword actorState = 0;
if (Type == ST_ACTOR)
actorState = ((Actor *)this)->Modified[IE_STATE_ID];
// Dead actors only get one chance to run a new script.
if ( (InternalFlags& (IF_REALLYDIED|IF_JUSTDIED))==IF_REALLYDIED)
return;
ScriptTicks++;
// If no action is running, we've had triggers set recently or we haven't checked recently, do a script update.
bool needsUpdate = (!CurrentAction) || (TriggerCountdown > 0) || (IdleTicks > 15);
// Also do a script update if one was forced..
if (InternalFlags & IF_FORCEUPDATE) {
needsUpdate = true;
InternalFlags &= ~IF_FORCEUPDATE;
}
// TODO: force for all on-screen actors
// Charmed actors don't get frequent updates.
if ((actorState & STATE_CHARMED) && (IdleTicks < 5))
needsUpdate = false;
if (!needsUpdate) {
IdleTicks++;
return;
}
if (triggers.size())
TriggerCountdown = 5;
IdleTicks = 0;
InternalFlags &= ~IF_JUSTDIED;
if (TriggerCountdown > 0)
TriggerCountdown--;
// TODO: set TriggerCountdown once we have real triggers
ExecuteScript(MAX_SCRIPTS);
}
void Scriptable::ExecuteScript(int scriptCount)
{
// area scripts still run for at least the current area, in bg1 (see ar2631, confirmed by testing)
// but not in bg2 (kill Abazigal in ar6005)
if (core->GetGameControl()->GetScreenFlags()&SF_CUTSCENE) {
if (! (core->HasFeature(GF_CUTSCENE_AREASCRIPTS) && Type == ST_AREA)) {
return;
}
}
// Don't abort if there is a running non-interruptable action.
if ((InternalFlags & IF_NOINT) && (CurrentAction || GetNextAction())) {
return;
}
if (!CurrentActionInterruptable) {
// sanity check
if (!CurrentAction && !GetNextAction())
abort();
return;
}
bool changed = false;
// if party AI is disabled, don't run non-override scripts
if (Type == ST_ACTOR && ((Actor *) this)->InParty && (core->GetGame()->ControlStatus & CS_PARTY_AI))
scriptCount = 1;
// TODO: hardcoded action hacks
if (Type == ST_ACTOR) {
//TODO: add stuff here that overrides actions (like Panic, etc)
changed |= ((Actor *) this)->OverrideActions();
}
bool continuing = false, done = false;
for (scriptlevel = 0;scriptlevel<scriptCount;scriptlevel++) {
GameScript *Script = Scripts[scriptlevel];
if (Script) {
changed |= Script->Update(&continuing, &done);
}
/* scripts are not concurrent, see WAITPC override script for example */
if (done) break;
}
if (changed)
InitTriggers();
if (Type == ST_ACTOR) {
//TODO: add stuff here about idle actions
((Actor *) this)->IdleActions(CurrentAction!=NULL);
}
}
void Scriptable::AddAction(Action* aC)
{
if (!aC) {
print( "[GameScript]: NULL action encountered for %s!\n",scriptName );
return;
}
InternalFlags|=IF_ACTIVE;
aC->IncRef();
if (actionflags[aC->actionID] & AF_SCRIPTLEVEL) {
aC->int0Parameter = scriptlevel;
}
// attempt to handle 'instant' actions, from instant.ids, which run immediately
// when added if the action queue is empty, even on actors which are Held/etc
// FIXME: area check hack until fuzzie fixes scripts here
if (!CurrentAction && !GetNextAction() && area) {
if (actionflags[aC->actionID] & AF_INSTANT) {
CurrentAction = aC;
GameScript::ExecuteAction( this, CurrentAction );
return;
}
}
actionQueue.push_back( aC );
}
void Scriptable::AddActionInFront(Action* aC)
{
if (!aC) {
print( "[GameScript]: NULL action encountered for %s!\n",scriptName );
return;
}
InternalFlags|=IF_ACTIVE;
actionQueue.push_front( aC );
aC->IncRef();
}
Action* Scriptable::GetNextAction() const
{
if (actionQueue.size() == 0) {
return NULL;
}
return actionQueue.front();
}
Action* Scriptable::PopNextAction()
{
if (actionQueue.size() == 0) {
return NULL;
}
Action* aC = actionQueue.front();
actionQueue.pop_front();
return aC;
}
void Scriptable::ClearActions()
{
ReleaseCurrentAction();
for (unsigned int i = 0; i < actionQueue.size(); i++) {
Action* aC = actionQueue.front();
actionQueue.pop_front();
aC->Release();
}
actionQueue.clear();
WaitCounter = 0;
LastTarget = 0;
if (Type == ST_ACTOR) {
Interrupt();
} else {
NoInterrupt();
}
}
void Scriptable::ReleaseCurrentAction()
{
if (CurrentAction) {
CurrentAction->Release();
CurrentAction = NULL;
}
CurrentActionState = 0;
CurrentActionTarget = 0;
CurrentActionInterruptable = true;
CurrentActionTicks = 0;
}
void Scriptable::ProcessActions()
{
if (WaitCounter) {
WaitCounter--;
if (WaitCounter) return;
}
int lastAction = -1;
while (true) {
CurrentActionInterruptable = true;
if (!CurrentAction) {
if (! (CurrentActionTicks == 0 && CurrentActionState == 0)) {
print("Last action: %d\n", lastAction);
}
assert(CurrentActionTicks == 0 && CurrentActionState == 0);
CurrentAction = PopNextAction();
} else {
CurrentActionTicks++;
}
if (!CurrentAction) {
ClearActions();
lastAction = -1;
break;
}
lastAction = CurrentAction->actionID;
GameScript::ExecuteAction( this, CurrentAction );
//break execution in case of a Wait flag
if (WaitCounter) {
break;
}
//break execution in case of blocking action
if (CurrentAction) {
break;
}
//break execution in case of movement
//we should not actually break here, or else fix waypoints
if (InMove()) {
break;
}
}
// FIXME
/*if (InternalFlags&IF_IDLE) {
Deactivate();
}*/
}
bool Scriptable::InMove() const
{
if (Type!=ST_ACTOR) {
return false;
}
Movable *me = (Movable *) this;
return me->GetNextStep()!=NULL;
}
void Scriptable::SetWait(unsigned long time)
{
WaitCounter = time;
}
unsigned long Scriptable::GetWait() const
{
return WaitCounter;
}
void Scriptable::LeaveDialog()
{
AddTrigger(TriggerEntry(trigger_wasindialog));
}
void Scriptable::Hide()
{
InternalFlags &=~(IF_VISIBLE);
}
void Scriptable::Unhide()
{
InternalFlags |= IF_VISIBLE;
}
void Scriptable::Interrupt()
{
InternalFlags &= ~IF_NOINT;
}
void Scriptable::NoInterrupt()
{
InternalFlags |= IF_NOINT;
}
//also turning off the idle flag so it won't run continuously
void Scriptable::Deactivate()
{
InternalFlags &=~(IF_ACTIVE|IF_IDLE);
}
//turning off the not interruptable flag, actions should reenable it themselves
//also turning off the idle flag
//heh, no, i wonder why did i touch the interruptable flag here
void Scriptable::Activate()
{
InternalFlags |= IF_ACTIVE;
InternalFlags &= ~IF_IDLE;
}
void Scriptable::PartyRested()
{
//InternalFlags |=IF_PARTYRESTED;
AddTrigger(TriggerEntry(trigger_partyrested));
}
ieDword Scriptable::GetInternalFlag()
{
return InternalFlags;
}
void Scriptable::InitTriggers()
{
triggers.clear();
}
void Scriptable::AddTrigger(TriggerEntry trigger)
{
triggers.push_back(trigger);
ImmediateEvent();
assert(trigger.triggerID < MAX_TRIGGERS);
if (triggerflags[trigger.triggerID] & TF_SAVED)
LastTrigger = trigger.param1;
}
bool Scriptable::MatchTrigger(unsigned short id, ieDword param) {
for (std::list<TriggerEntry>::iterator m = triggers.begin(); m != triggers.end (); m++) {
TriggerEntry &trigger = *m;
if (trigger.triggerID != id)
continue;
if (param && trigger.param1 != param)
continue;
return true;
}
return false;
}
bool Scriptable::MatchTriggerWithObject(unsigned short id, class Object *obj, ieDword param) {
for (std::list<TriggerEntry>::iterator m = triggers.begin(); m != triggers.end (); m++) {
TriggerEntry &trigger = *m;
if (trigger.triggerID != id)
continue;
if (param && trigger.param2 != param)
continue;
if (!MatchActor(this, trigger.param1, obj))
continue;
return true;
}
return false;
}
const TriggerEntry *Scriptable::GetMatchingTrigger(unsigned short id, unsigned int notflags) {
for (std::list<TriggerEntry>::iterator m = triggers.begin(); m != triggers.end (); m++) {
TriggerEntry &trigger = *m;
if (trigger.triggerID != id)
continue;
if (notflags & trigger.flags)
continue;
return &*m;
}
return NULL;
}
void Scriptable::CreateProjectile(const ieResRef SpellResRef, ieDword tgt, int level, bool fake)
{
Spell* spl = gamedata->GetSpell( SpellResRef );
Actor *caster = NULL;
//PST has a weird effect, called Enoll Eva's duplication
//it creates every projectile of the affected actor twice
int projectileCount = 1;
if (Type == ST_ACTOR) {
caster = (Actor *) this;
caster->CureInvisibility();
if (spl->Flags&SF_HOSTILE) {
caster->CureSanctuary();
}
// check if a wild surge ordered us to replicate the projectile
projectileCount = caster->wildSurgeMods.num_castings;
if (!projectileCount) {
projectileCount = 1;
}
}
if (core->HasFeature(GF_PST_STATE_FLAGS) && (Type == ST_ACTOR)) {
if (caster->GetStat(IE_STATE_ID)&STATE_EE_DUPL) {
//seriously, wild surges and EE in the same game?
//anyway, it would be too many duplications
projectileCount = 2;
}
}
while(projectileCount --) {
Projectile *pro = NULL;
// jump through hoops to skip applying selftargetting spells to the caster
// if we'll be changing the target
int tct = 0;
if (caster) {
tct = caster->wildSurgeMods.target_change_type;
}
if (!caster || !tct || tct == WSTC_ADDTYPE || !caster->wildSurgeMods.projectile_id) {
pro = spl->GetProjectile(this, SpellHeader, level, LastTargetPos);
if (!pro) {
return;
}
pro->SetCaster(GetGlobalID(), level);
}
Point origin = Pos;
if (Type == ST_TRIGGER || Type == ST_PROXIMITY) {
// try and make projectiles start from the right trap position
// see the traps in the duergar/assassin battle in bg2 dungeon
// see also function below - maybe we should fix Pos instead
origin = ((InfoPoint *)this)->TrapLaunch;
}
if (caster) {
// check for target (type) change
int count, i;
Actor *newact = NULL;
SPLExtHeader *seh = NULL;
Effect *fx = NULL;
switch (caster->wildSurgeMods.target_change_type) {
case WSTC_SETTYPE:
seh = &spl->ext_headers[SpellHeader];
for (i=0; i < seh->FeatureCount; i++) {
seh->features[i].Target = caster->wildSurgeMods.target_type;
}
// we need to fetch the projectile, so the effect queue is created
// (skipped above)
pro = spl->GetProjectile(this, SpellHeader, level, LastTargetPos);
pro->SetCaster(GetGlobalID(), level);
break;
case WSTC_ADDTYPE:
// TODO: unhardcode to allow for mixing all the target types
// caster gets selftargetting fx when the projectile is fetched above
seh = &spl->ext_headers[SpellHeader];
for (i=0; i < seh->FeatureCount; i++) {
if (seh->features[i].Target == FX_TARGET_SELF) {
seh->features[i].Target = caster->wildSurgeMods.target_type;
} else {
// also apply to the caster
fx = seh->features+i;
core->ApplyEffect(fx, caster, caster);
}
}
// we need to refetch the projectile, so the effect queue is created
pro = spl->GetProjectile(this, SpellHeader, level, LastTargetPos);
pro->SetCaster(GetGlobalID(), level);
break;
case WSTC_RANDOMIZE:
count = area->GetActorCount(false);
newact = area->GetActor(core->Roll(1,count,-1), false);
if (count > 1 && newact == caster) {
while (newact == caster) {
newact = area->GetActor(core->Roll(1,count,-1), false);
}
}
if (tgt) {
LastTarget = newact->GetGlobalID();
LastTargetPos = newact->Pos;
} else {
// no better idea; I wonder if the original randomized point targets at all
LastTargetPos = newact->Pos;
}
// make it also work for self-targetting spells:
// change the payload or this was all in vain
seh = &spl->ext_headers[SpellHeader];
for (i=0; i < seh->FeatureCount; i++) {
if (seh->features[i].Target == FX_TARGET_SELF) {
seh->features[i].Target = FX_TARGET_PRESET;
}
}
// we need to fetch the projectile, so the effect queue is created
// (skipped above)
pro = spl->GetProjectile(this, SpellHeader, level, LastTargetPos);
pro->SetCaster(GetGlobalID(), level);
break;
default: //0 - do nothing
break;
}
// apply the saving throw mod
if (caster->wildSurgeMods.saving_throw_mod) {
seh = &spl->ext_headers[SpellHeader];
for (i=0; i < seh->FeatureCount; i++) {
seh->features[i].SavingThrowBonus += caster->wildSurgeMods.saving_throw_mod;
}
}
// change the projectile
if (caster->wildSurgeMods.projectile_id) {
spl->ext_headers[SpellHeader].ProjectileAnimation = caster->wildSurgeMods.projectile_id;
// make it also work for self-targetting spells:
// change the payload or this was all in vain
seh = &spl->ext_headers[SpellHeader];
for (i=0; i < seh->FeatureCount; i++) {
if (seh->features[i].Target == FX_TARGET_SELF) {
seh->features[i].Target = FX_TARGET_PRESET;
}
}
// we need to refetch the projectile, so the new one is used
pro = spl->GetProjectile(this, SpellHeader, level, LastTargetPos);
pro->SetCaster(GetGlobalID(), level);
}
// check for the speed mod
if (caster->wildSurgeMods.projectile_speed_mod) {
pro->Speed = (pro->Speed * caster->wildSurgeMods.projectile_speed_mod) / 100;
if (!pro->Speed) {
pro->Speed = 1;
}
}
}
if (tgt) {
area->AddProjectile(pro, origin, tgt, fake);
} else {
area->AddProjectile(pro, origin, LastTargetPos);
}
}
ieDword spellnum=ResolveSpellNumber( SpellResRef );
if (spellnum!=0xffffffff) {
area->SeeSpellCast(this, spellnum);
// caster - Casts spellname : target OR
// caster - spellname : target (repeating spells)
Scriptable *target = NULL;
if (tgt) {
target = area->GetActorByGlobalID(tgt);
if (!target) {
target=core->GetGame()->GetActorByGlobalID(tgt);
}
}
char* spell = core->GetString(spl->SpellName);
if (stricmp(spell, "") && Type == ST_ACTOR) {
char* msg = core->GetString(displaymsg->GetStringReference(STR_ACTION_CAST), 0);
char *tmp;
if (target) {
tmp = (char *) malloc(strlen(msg)+strlen(spell)+strlen(target->GetName(-1))+5);
sprintf(tmp, "%s %s : %s", msg, spell, target->GetName(-1));
} else {
tmp = (char *) malloc(strlen(spell)+strlen(GetName(-1))+4);
sprintf(tmp, "%s : %s", spell, GetName(-1));
}
displaymsg->DisplayStringName(tmp, DMC_WHITE, this);
core->FreeString(msg);
free(tmp);
}
core->FreeString(spell);
}
// only trigger the autopause when in combat or buffing gets very annoying
if (core->GetGame()->CombatCounter) {
core->Autopause(AP_SPELLCAST, this);
}
gamedata->FreeSpell(spl, SpellResRef, false);
}
void Scriptable::CastSpellPointEnd(int level)
{
Actor *caster = NULL;
if (Type == ST_ACTOR) {
caster = ((Actor *) this);
caster->SetStance(IE_ANI_CONJURE);
if (level == 0) {
Spell* spl = gamedata->GetSpell(SpellResRef); // this was checked before we got here
Actor *actor = NULL;
if (Type == ST_ACTOR) {
actor = (Actor *) this;
level = actor->GetCasterLevel(spl->SpellType);
}
gamedata->FreeSpell(spl, SpellResRef, false);
}
}
if (SpellHeader == -1) {
LastTargetPos.empty();
return;
}
if (LastTargetPos.isempty()) {
SpellHeader = -1;
return;
}
if (!SpellResRef[0]) {
return;
}
CreateProjectile(SpellResRef, 0, level, false);
SpellHeader = -1;
SpellResRef[0] = 0;
LastTarget = 0;
LastTargetPos.empty();
if (caster) {
memset(&(caster->wildSurgeMods), 0, sizeof(caster->wildSurgeMods));
}
}
void Scriptable::CastSpellEnd(int level)
{
Actor *caster = NULL;
if (Type == ST_ACTOR) {
caster = ((Actor *) this);
caster->SetStance(IE_ANI_CONJURE);
if (level == 0) {
Spell* spl = gamedata->GetSpell(SpellResRef); // this was checked before we got here
Actor *actor = NULL;
if (Type == ST_ACTOR) {
actor = (Actor *) this;
level = actor->GetCasterLevel(spl->SpellType);
}
gamedata->FreeSpell(spl, SpellResRef, false);
}
}
if (SpellHeader == -1) {
LastTarget = 0;
return;
}
if (!LastTarget) {
SpellHeader = -1;
return;
}
if (!SpellResRef[0]) {
return;
}
//if the projectile doesn't need to follow the target, then use the target position
CreateProjectile(SpellResRef, LastTarget, level, GetSpellDistance(SpellResRef, this)==0xffffffff);
SpellHeader = -1;
SpellResRef[0] = 0;
LastTarget = 0;
LastTargetPos.empty();
if (caster) {
memset(&(caster->wildSurgeMods), 0, sizeof(caster->wildSurgeMods));
}
}
// check for input sanity and good casting conditions
int Scriptable::CanCast(const ieResRef SpellResRef) {
Spell* spl = gamedata->GetSpell(SpellResRef);
if (!spl) {
SpellHeader = -1;
printMessage("Scriptable", "Spell not found, aborting cast!\n", LIGHT_RED);
return 0;
}
// check for area dead magic
// tob AR3004 is a dead magic area, but using a script with personal dead magic
if (area->GetInternalFlag()&AF_DEADMAGIC) {
// TODO: display fizzling animation
displaymsg->DisplayConstantStringName(STR_DEADMAGIC_FAIL, DMC_WHITE, this);
return 0;
}
if (spl->Flags&SF_NOT_INDOORS && !(area->AreaType&AT_OUTDOOR)) {
displaymsg->DisplayConstantStringName(STR_INDOOR_FAIL, DMC_WHITE, this);
return 0;
}
// various individual checks
if (Type == ST_ACTOR) {
Actor *actor = (Actor *) this;
// check for silence
// only a handful of spells don't have a verbal component -
// the original hardcoded vocalize and a few more
// we (also) ignore nonmagic spells
if (actor->Modified[IE_STATE_ID] & STATE_SILENCED) {
if (!(core->GetSpecialSpell(spl->Name)&SP_SILENCE) && !(spl->Flags&SF_HLA)) {
printMessage("Scriptable", "Tried to cast while silenced!\n", YELLOW);
return 0;
}
}
// check for personal dead magic
if (actor->Modified[IE_DEADMAGIC]) {
// TODO: display fizzling animation
displaymsg->DisplayConstantStringName(STR_DEADMAGIC_FAIL, DMC_WHITE, this);
return 0;
}
// check for miscast magic and similar
ieDword roll = actor->LuckyRoll(1, 100, 0, 0);
bool failed = false;
switch(spl->SpellType)
{
case IE_SPL_PRIEST:
if (actor->Modified[IE_SPELLFAILUREPRIEST] >= roll) {
failed = true;
}
break;
case IE_SPL_WIZARD:
if (actor->Modified[IE_SPELLFAILUREMAGE] >= roll) {
failed = true;
}
break;
case IE_SPL_INNATE:
if (actor->Modified[IE_SPELLFAILUREINNATE] >= roll) {
failed = true;
}
break;
}
if (failed) {
// TODO: display fizzling animation
displaymsg->DisplayConstantStringName(STR_MISCASTMAGIC, DMC_WHITE, this);
return 0;
}
}
return 1;
}
//set target as point
//if spell needs to be depleted, do it
//if spell is illegal stop casting
int Scriptable::CastSpellPoint( const Point &target, bool deplete, bool instant, bool nointerrupt )
{
LastTarget = 0;
LastTargetPos.empty();
Actor *actor = NULL;
if (Type == ST_ACTOR) {
actor = (Actor *) this;
if (actor->HandleCastingStance(SpellResRef, deplete) ) {
printMessage("Scriptable", "Spell not known or memorized, aborting cast!\n", LIGHT_RED);
return -1;
}
}
if(!nointerrupt && !CanCast(SpellResRef)) {
SpellResRef[0] = 0;
if (actor) {
actor->SetStance(IE_ANI_READY);
}
return -1;
}
LastTargetPos = target;
if(!CheckWildSurge()) {
return -1;
}
return SpellCast(instant);
}
//set target as actor (if target isn't actor, use its position)
//if spell needs to be depleted, do it
//if spell is illegal stop casting
int Scriptable::CastSpell( Scriptable* target, bool deplete, bool instant, bool nointerrupt )
{
LastTarget = 0;
LastTargetPos.empty();
Actor *actor = NULL;
if (Type == ST_ACTOR) {
actor = (Actor *) this;
if (actor->HandleCastingStance(SpellResRef, deplete) ) {
printMessage("Scriptable", "Spell not known or memorized, aborting cast!\n", LIGHT_RED);
return -1;
}
}
assert(target);
if(!nointerrupt && !CanCast(SpellResRef)) {
SpellResRef[0] = 0;
if (actor) {
actor->SetStance(IE_ANI_READY);
}
return -1;
}
LastTargetPos = target->Pos;
if (target->Type==ST_ACTOR) {
LastTarget = target->GetGlobalID();
}
if(!CheckWildSurge()) {
return -1;
}
return SpellCast(instant);
}
static EffectRef fx_force_surge_modifier_ref = { "ForceSurgeModifier", -1 };
//start spellcasting (common part)
int Scriptable::SpellCast(bool instant)
{
Spell* spl = gamedata->GetSpell(SpellResRef); // this was checked before we got here
Actor *actor = NULL;
int level = 0;
if (Type == ST_ACTOR) {
actor = (Actor *) this;
//The ext. index is here to calculate the casting time
level = actor->GetCasterLevel(spl->SpellType);
SpellHeader = spl->GetHeaderIndexFromLevel(level);
} else {
SpellHeader = 0;
}
SPLExtHeader *header = spl->GetExtHeader(SpellHeader);
int casting_time = (int)header->CastingTime;
// how does this work for non-actors exactly?
if (actor) {
// The mental speed effect can shorten or lengthen the casting time.
casting_time -= (int)actor->Modified[IE_MENTALSPEED];
// maybe also add a random lucky roll as for weapon speed / initiative
if (casting_time < 0) {
casting_time = 0;
} else if (casting_time > 10) {
casting_time = 10;
}
}
// this is a guess which seems approximately right so far (same as in the bg2 manual, except that it may be a combat round instead)
int duration = (casting_time*core->Time.round_size) / 10;
if (instant) {
duration = 0;
}
if (actor) {
//cfb
EffectQueue *fxqueue = spl->GetEffectBlock(this, this->Pos, -1, level);
fxqueue->SetOwner(actor);
if (!(actor->Modified[IE_AVATARREMOVAL] || instant)) {
spl->AddCastingGlow(fxqueue, duration, actor->Modified[IE_SEX]);
}
fxqueue->AddAllEffects(actor, actor->Pos);
delete fxqueue;
actor->WMLevelMod = 0;
if (actor->Modified[IE_FORCESURGE] == 1) {
// affects only the next spell cast, but since the timing is permanent,
// we have to remove it manually
actor->fxqueue.RemoveAllEffectsWithParam(fx_force_surge_modifier_ref, 1);
}
actor->ResetCommentTime();
}
gamedata->FreeSpell(spl, SpellResRef, false);
return duration;
}
// Anyone with some wildness has 5% chance of getting a wild surge when casting,
// but most innates are excluded, due to being nonmagic.
// A d100 roll is made, some stat boni are added, then either:
// 1. the spell is cast normally (score of 100 or more)
// 2. one or more wild surges happen and something else is cast
// 2.1. this can loop, since some surges cause rerolls
static EffectRef fx_chaosshield_ref = { "ChaosShieldModifier", -1 };
int Scriptable::CheckWildSurge()
{
//no need to check for 3rd ed rules, because surgemod or forcesurge need to be nonzero to get a surge
if (Type != ST_ACTOR) {
return 1;
}
if (core->InCutSceneMode()) {
return 1;
}
Actor *caster = (Actor *) this;
int roll = core->Roll(1, 100, 0);
if ((roll <= 5 && caster->Modified[IE_SURGEMOD]) || caster->Modified[IE_FORCESURGE]) {
ieResRef OldSpellResRef;
memcpy(OldSpellResRef, SpellResRef, sizeof(OldSpellResRef));
Spell *spl = gamedata->GetSpell( OldSpellResRef ); // this was checked before we got here
// ignore non-magic "spells"
if (!(spl->Flags&(SF_HLA|SF_TRIGGER) )) {
int check = roll + caster->GetCasterLevel(spl->SpellType) + caster->Modified[IE_SURGEMOD];
if (caster->Modified[IE_CHAOSSHIELD]) {
//avert the surge and decrease the chaos shield counter
check = 0;
caster->fxqueue.DecreaseParam1OfEffect(fx_chaosshield_ref,1);
displaymsg->DisplayConstantStringName(STR_CHAOSSHIELD,DMC_LIGHTGREY,caster);
}
// hundred or more means a normal cast; same for negative values (for absurd antisurge modifiers)
if ((check > 0) && (check < 100) ) {
// display feedback: Wild Surge: bla bla
char *s1 = core->GetString(displaymsg->GetStringReference(STR_WILDSURGE), 0);
char *s2 = core->GetString(core->SurgeSpells[check-1].message, 0);
char *s3 = (char *) malloc(strlen(s1)+strlen(s2)+2);
sprintf(s3, "%s %s", s1, s2);
core->FreeString(s1);
core->FreeString(s2);
displaymsg->DisplayStringName(s3, DMC_WHITE, this);
free(s3);
// lookup the spell in the "check" row of wildmag.2da
ieResRef surgeSpellRef;
memset(surgeSpellRef, 0, sizeof(surgeSpellRef));
strncpy(surgeSpellRef, core->SurgeSpells[check-1].spell, 8);
if (!gamedata->Exists(surgeSpellRef, IE_SPL_CLASS_ID)) {
// handle the hardcoded cases - they'll also fail here
if (!HandleHardcodedSurge(surgeSpellRef, spl, caster)) {
//free the spell handle because we need to return
gamedata->FreeSpell(spl, OldSpellResRef, false);
return 0;
}
} else {
// finally change the spell
// the hardcoded bunch does it on its own when needed
strncpy(SpellResRef, surgeSpellRef, 8);
}
}
}
//free the spell handle
gamedata->FreeSpell(spl, OldSpellResRef, false);
}
return 1;
}
bool Scriptable::HandleHardcodedSurge(ieResRef surgeSpellRef, Spell *spl, Actor *caster)
{
// format: ID or ID.param1 or +SPELLREF
int types = caster->spellbook.GetTypes();
int lvl = spl->SpellLevel-1;
int count, i, tmp, tmp2, tmp3;
Scriptable *target = NULL;
Point targetpos(-1, -1);
ieResRef newspl;
int level = caster->GetCasterLevel(spl->SpellType);
switch (surgeSpellRef[0]) {
case '+': // cast normally, but also cast SPELLREF first
core->ApplySpell(surgeSpellRef+1, caster, caster, level);
break;
case '0': // cast spell param1 times
strtok(surgeSpellRef,".");
count = strtol(strtok(NULL,"."), NULL, 0);
caster->wildSurgeMods.num_castings = count;
break;
case '1': // change projectile (id) to param1
strtok(surgeSpellRef,".");
count = strtol(strtok(NULL,"."), NULL, 0);
caster->wildSurgeMods.projectile_id = count;
break;
case '2': // also target target type param1
strtok(surgeSpellRef,".");
count = strtol(strtok(NULL,"."), NULL, 0);
caster->wildSurgeMods.target_type = count;
caster->wildSurgeMods.target_change_type = WSTC_ADDTYPE;
break;
case '3': // (wild surge) roll param1 more times
strtok(surgeSpellRef,".");
count = strtol(strtok(NULL,"."), NULL, 0);
// force surge and then cast
// force the surge roll to be < 100, so we cast a spell from the surge table
tmp = caster->Modified[IE_FORCESURGE];
tmp2 = caster->Modified[IE_SURGEMOD];
tmp3 = caster->WMLevelMod; // also save caster level; the original didn't reroll the bonus
caster->Modified[IE_FORCESURGE] = 7;
caster->Modified[IE_SURGEMOD] = - caster->GetCasterLevel(spl->SpellType); // nulify the bonus
if (LastTarget) {
target = area->GetActorByGlobalID(LastTarget);
if (!target) {
target = core->GetGame()->GetActorByGlobalID(LastTarget);
}
}
if (!LastTargetPos.isempty()) {
targetpos = LastTargetPos;
} else if (target) {
targetpos = target->Pos;
}
// SpellResRef still contains the original spell and we need to keep it that way
// as any of the rerolls could result in a "spell cast normally" (non-surge)
for (i=0; i<count; i++) {
if (target) {
caster->CastSpell(target, false, true);
strncpy(newspl, SpellResRef, 8);
caster->WMLevelMod = tmp3;
caster->CastSpellEnd(level);
} else {
caster->CastSpellPoint(targetpos, false, true);
strncpy(newspl, SpellResRef, 8);
caster->WMLevelMod = tmp3;
caster->CastSpellPointEnd(level);
}
// reset the ref, since CastSpell*End destroyed it
strncpy(SpellResRef, newspl, 8);
}
caster->Modified[IE_FORCESURGE] = tmp;
caster->Modified[IE_SURGEMOD] = tmp2;
break;
case '4': // change the target type to param1
strtok(surgeSpellRef,".");
count = strtol(strtok(NULL,"."), NULL, 0);
caster->wildSurgeMods.target_type = count;
caster->wildSurgeMods.target_change_type = WSTC_SETTYPE;
break;
case '5': // change the target to a random actor
caster->wildSurgeMods.target_change_type = WSTC_RANDOMIZE;
break;
case '6': // change saving throw (+param1)
strtok(surgeSpellRef,".");
count = strtol(strtok(NULL,"."), NULL, 0);
caster->wildSurgeMods.saving_throw_mod = count;
break;
case '7': // random spell of the same level (FIXME: make an effect out of this?)
// change this if we ever want the surges to respect the original type
for (i=0; i<types; i++) {
unsigned int spellCount = caster->spellbook.GetKnownSpellsCount(i, lvl);
if (!spellCount) continue;
int id = core->Roll(1, spellCount, -1);
CREKnownSpell *ck = caster->spellbook.GetKnownSpell(i, lvl, id);
if (ck) {
strncpy(SpellResRef, ck->SpellResRef, 8);
break;
}
}
break;
case '8': // set projectile speed to param1 %
strtok(surgeSpellRef,".");
count = strtol(strtok(NULL,"."), NULL, 0);
caster->wildSurgeMods.projectile_speed_mod = count;
break;
default:
SpellHeader = -1;
SpellResRef[0] = 0;
printMessage("Scriptable", "New spell not found, aborting cast mid-surge!\n", LIGHT_RED);
caster->SetStance(IE_ANI_READY);
return false;
}
return true;
}
bool Scriptable::AuraPolluted()
{
if (Type != ST_ACTOR) {
return false;
}
// aura pollution happens automatically
// aura cleansing the usual and magical way
if (AuraTicks >= core->Time.attack_round_size) {
AuraTicks = -1;
return false;
} else if (CurrentActionTicks == 0 && AuraTicks != 1 && Type == ST_ACTOR) {
Actor *act = (Actor *) this;
if (act->GetStat(IE_AURACLEANSING)) {
AuraTicks = -1;
displaymsg->DisplayConstantStringName(STR_AURACLEANSED, DMC_WHITE, this);
return false;
}
}
if (AuraTicks > 0) {
// sorry, you'll have to recover first
return true;
}
return false;
}
bool Scriptable::TimerActive(ieDword ID)
{
if (ID>=MAX_TIMER) {
return false;
}
if (script_timers[ID]) {
return true;
}
return false;
}
bool Scriptable::TimerExpired(ieDword ID)
{
if (ID>=MAX_TIMER) {
return false;
}
if (script_timers[ID] && script_timers[ID] < core->GetGame()->GameTime) {
// expired timers become inactive after being checked
script_timers[ID] = 0;
return true;
}
return false;
}
void Scriptable::StartTimer(ieDword ID, ieDword expiration)
{
if (ID>=MAX_TIMER) {
printMessage("Scriptable", "Timer id %d exceeded MAX_TIMER %d\n", RED,
ID, MAX_TIMER);
return;
}
script_timers[ID]= core->GetGame()->GameTime + expiration*AI_UPDATE_TIME;
}
/********************
* Selectable Class *
********************/
Selectable::Selectable(ScriptableType type)
: Scriptable( type )
{
Selected = false;
Over = false;
size = 0;
cover = NULL;
circleBitmap[0] = NULL;
circleBitmap[1] = NULL;
}
void Selectable::SetSpriteCover(SpriteCover* c)
{
delete cover;
cover = c;
}
Selectable::~Selectable(void)
{
delete cover;
}
void Selectable::SetBBox(const Region &newBBox)
{
BBox = newBBox;
}
void Selectable::DrawCircle(const Region &vp)
{
/* BG2 colours ground circles as follows:
dark green for unselected party members
bright green for selected party members
flashing green/white for a party member the mouse is over
bright red for enemies
yellow for panicked actors
flashing red/white for enemies the mouse is over
flashing cyan/white for neutrals the mouse is over
*/
if (size<=0) {
return;
}
Color mix;
Color* col = &selectedColor;
Sprite2D* sprite = circleBitmap[0];
if (Selected) {
sprite = circleBitmap[1];
} else if (Over) {
//doing a time dependent flashing of colors
//if it is too fast, increase the 6 to 7
unsigned long step;
step = GetTickCount();
step = tp_steps [(step >> 6) & 7];
mix.a = overColor.a;
mix.r = (overColor.r*step+selectedColor.r*(8-step))/8;
mix.g = (overColor.g*step+selectedColor.g*(8-step))/8;
mix.b = (overColor.b*step+selectedColor.b*(8-step))/8;
col = &mix;
} else if (IsPC()) {
col = &overColor;
}
if (sprite) {
core->GetVideoDriver()->BlitSprite( sprite, Pos.x - vp.x, Pos.y - vp.y, true );
} else {
// for size >= 2, radii are (size-1)*16, (size-1)*12
// for size == 1, radii are 12, 9
int csize = (size - 1) * 4;
if (csize < 4) csize = 3;
core->GetVideoDriver()->DrawEllipse( (ieWord) (Pos.x - vp.x), (ieWord) (Pos.y - vp.y),
(ieWord) (csize * 4), (ieWord) (csize * 3), *col );
}
}
// Check if P is over our ground circle
bool Selectable::IsOver(const Point &P) const
{
int csize = size;
if (csize < 2) csize = 2;
int dx = P.x - Pos.x;
int dy = P.y - Pos.y;
// check rectangle first
if (dx < -(csize-1)*16 || dx > (csize-1)*16) return false;
if (dy < -(csize-1)*12 || dy > (csize-1)*12) return false;
// then check ellipse
int r = 9*dx*dx + 16*dy*dy; // 48^2 * ( (dx/16)^2 + (dy/12)^2 )
return (r <= 48*48*(csize-1)*(csize-1));
}
bool Selectable::IsSelected() const
{
return Selected == 1;
}
void Selectable::SetOver(bool over)
{
Over = over;
}
//don't call this function after rendering the cover and before the
//blitting of the sprite or bad things will happen :)
void Selectable::Select(int Value)
{
if (Selected!=0x80 || Value!=1) {
Selected = (ieWord) Value;
}
//forcing regeneration of the cover
SetSpriteCover(NULL);
}
void Selectable::SetCircle(int circlesize, const Color &color, Sprite2D* normal_circle, Sprite2D* selected_circle)
{
size = circlesize;
selectedColor = color;
overColor.r = color.r >> 1;
overColor.g = color.g >> 1;
overColor.b = color.b >> 1;
overColor.a = color.a;
circleBitmap[0] = normal_circle;
circleBitmap[1] = selected_circle;
}
//used for creatures
int Selectable::WantDither()
{
//if dithering is disabled globally, don't do it
if (core->FogOfWar&FOG_DITHERSPRITES) {
return 0;
}
//if actor is dead, dither it if polygon wants
if (Selected&0x80) {
return 1;
}
//if actor is selected dither it
if (Selected) {
return 2;
}
return 1;
}
/***********************
* Highlightable Class *
***********************/
Highlightable::Highlightable(ScriptableType type)
: Scriptable( type )
{
outline = NULL;
Highlight = false;
Cursor = IE_CURSOR_NORMAL;
KeyResRef[0] = 0;
EnterWav[0] = 0;
}
Highlightable::~Highlightable(void)
{
if (outline) {
delete( outline );
}
}
bool Highlightable::IsOver(const Point &Pos) const
{
if (!outline) {
return false;
}
return outline->PointIn( Pos );
}
void Highlightable::DrawOutline() const
{
if (!outline) {
return;
}
core->GetVideoDriver()->DrawPolyline( outline, outlineColor, true );
}
void Highlightable::SetCursor(unsigned char CursorIndex)
{
Cursor = CursorIndex;
}
//trap that will fire now
bool Highlightable::TriggerTrap(int /*skill*/, ieDword ID)
{
if (!Trapped) {
return false;
}
//actually this could be script name[0]
if (!Scripts[0] && !EnterWav[0]) {
return false;
}
AddTrigger(TriggerEntry(trigger_entered, ID));
if (!TrapResets()) {
Trapped = false;
}
return true;
}
bool Highlightable::TryUnlock(Actor *actor, bool removekey) {
const char *Key = GetKey();
Actor *haskey = NULL;
if (Key && actor->InParty) {
Game *game = core->GetGame();
//allow unlock when the key is on any partymember
for (int idx = 0; idx < game->GetPartySize(false); idx++) {
Actor *pc = game->FindPC(idx + 1);
if (!pc) continue;
if (pc->inventory.HasItem(Key,0) ) {
haskey = pc;
break;
}
}
} else if (Key) {
//actor is not in party, check only actor
if (actor->inventory.HasItem(Key,0) ) {
haskey = actor;
}
}
if (!haskey) {
return false;
}
if (removekey) {
CREItem *item = NULL;
haskey->inventory.RemoveItem(Key,0,&item);
//the item should always be existing!!!
if (item) {
delete item;
}
}
return true;
}
//detect this trap, using a skill, skill could be set to 256 for 'sure'
//skill is the all around modified trap detection skill
//a trapdetectiondifficulty of 100 means impossible detection short of a spell
void Highlightable::DetectTrap(int skill)
{
if (!CanDetectTrap()) return;
if (!Scripts[0]) return;
if ((skill>=100) && (skill!=256) ) skill = 100;
if (skill/2+core->Roll(1,skill/2,0)>TrapDetectionDiff) {
SetTrapDetected(1); //probably could be set to the player #?
}
}
bool Highlightable::PossibleToSeeTrap() const
{
return CanDetectTrap();
}
/*****************
* Movable Class *
*****************/
Movable::Movable(ScriptableType type)
: Selectable( type )
{
Destination = Pos;
Orientation = 0;
NewOrientation = 0;
StanceID = 0;
path = NULL;
step = NULL;
timeStartStep = 0;
lastFrame = NULL;
Area[0] = 0;
AttackMovements[0] = 100;
AttackMovements[1] = 0;
AttackMovements[2] = 0;
}
Movable::~Movable(void)
{
if (path) {
ClearPath();
}
}
int Movable::GetPathLength()
{
PathNode *node = GetNextStep(0);
if (!node) return 0;
int i = 0;
while (node->Next) {
i++;
node = node->Next;
}
return i;
}
PathNode *Movable::GetNextStep(int x)
{
if (!step) {
DoStep((unsigned int) ~0);
}
PathNode *node = step;
while(node && x--) {
node = node->Next;
}
return node;
}
Point Movable::GetMostLikelyPosition()
{
if (!path) {
return Pos;
}
//actually, sometimes middle path would be better, if
//we stand in Destination already
int halfway = GetPathLength()/2;
PathNode *node = GetNextStep(halfway);
if (node) {
return Point((ieWord) ((node->x*16)+8), (ieWord) ((node->y*12)+6) );
}
return Destination;
}
void Movable::SetStance(unsigned int arg)
{
//don't modify stance from dead back to anything if the actor is dead
if ((StanceID==IE_ANI_TWITCH || StanceID==IE_ANI_DIE) && (arg!=IE_ANI_TWITCH) ) {
if (GetInternalFlag()&IF_REALLYDIED) {
printMessage("Movable","Stance overridden by death\n", YELLOW);
return;
}
}
if (StanceID == IE_ANI_CONJURE && StanceID != arg && Type ==ST_ACTOR) {
Actor *caster = (Actor *) this;
if (caster->casting_sound) {
caster->casting_sound->Stop();
caster->casting_sound.release();
}
}
if (arg<MAX_ANIMS) {
StanceID=(unsigned char) arg;
if (StanceID == IE_ANI_ATTACK) {
// Set stance to a random attack animation
int random = rand()%100;
if (random < AttackMovements[0]) {
StanceID = IE_ANI_ATTACK_BACKSLASH;
} else if (random < AttackMovements[0] + AttackMovements[1]) {
StanceID = IE_ANI_ATTACK_SLASH;
} else {
StanceID = IE_ANI_ATTACK_JAB;
}
}
} else {
StanceID=IE_ANI_AWAKE; //
print("Tried to set invalid stance id (%u)\n", arg);
}
}
void Movable::SetAttackMoveChances(ieWord *amc)
{
AttackMovements[0]=amc[0];
AttackMovements[1]=amc[1];
AttackMovements[2]=amc[2];
}
//this could be used for WingBuffet as well
void Movable::MoveLine(int steps, int Pass, ieDword orient)
{
//remove previous path
ClearPath();
if (!steps)
return;
Point p = Pos;
p.x/=16;
p.y/=14;
path = area->GetLine( p, steps, orient, Pass );
}
void AdjustPositionTowards(Point &Pos, ieDword time_diff, unsigned int walk_speed, short srcx, short srcy, short destx, short desty) {
if (destx > srcx)
Pos.x += ( unsigned short )
( ( ( ( ( destx * 16 ) + 8 ) - Pos.x ) * ( time_diff ) ) / walk_speed );
else
Pos.x -= ( unsigned short )
( ( ( Pos.x - ( ( destx * 16 ) + 8 ) ) * ( time_diff ) ) / walk_speed );
if (desty > srcy)
Pos.y += ( unsigned short )
( ( ( ( ( desty * 12 ) + 6 ) - Pos.y ) * ( time_diff ) ) / walk_speed );
else
Pos.y -= ( unsigned short )
( ( ( Pos.y - ( ( desty * 12 ) + 6 ) ) * ( time_diff ) ) / walk_speed );
}
unsigned char Movable::GetNextFace()
{
//slow turning
if (timeStartStep==core->GetGame()->Ticks) {
return Orientation;
}
if (Orientation != NewOrientation) {
if ( ( (NewOrientation-Orientation) & (MAX_ORIENT-1) ) <= MAX_ORIENT/2) {
Orientation++;
} else {
Orientation--;
}
Orientation = Orientation&(MAX_ORIENT-1);
}
return Orientation;
}
// returns whether we made all pending steps (so, false if we must be called again this tick)
// we can't just do them all here because the caller might have to update searchmap etc
bool Movable::DoStep(unsigned int walk_speed, ieDword time)
{
if (!path) {
return true;
}
if (!time) time = core->GetGame()->Ticks;
if (!walk_speed) {
// zero speed: no movement
timeStartStep = time;
StanceID = IE_ANI_READY;
return true;
}
if (!step) {
step = path;
timeStartStep = time;
} else if (step->Next && (( time - timeStartStep ) >= walk_speed)) {
//print("[New Step] : Orientation = %d\n", step->orient);
step = step->Next;
timeStartStep = timeStartStep + walk_speed;
}
SetOrientation (step->orient, true);
StanceID = IE_ANI_WALK;
if ((Type == ST_ACTOR) && (InternalFlags & IF_RUNNING)) {
StanceID = IE_ANI_RUN;
}
Pos.x = ( step->x * 16 ) + 8;
Pos.y = ( step->y * 12 ) + 6;
if (!step->Next) {
// we reached our destination, we are done
ClearPath();
NewOrientation = Orientation;
//since clearpath no longer sets currentaction to NULL
//we set it here
//no we don't, action is responsible for releasing itself
//ReleaseCurrentAction();
return true;
}
if (( time - timeStartStep ) >= walk_speed) {
// we didn't finish all pending steps, yet
return false;
}
AdjustPositionTowards(Pos, time - timeStartStep, walk_speed, step->x, step->y, step->Next->x, step->Next->y);
return true;
}
void Movable::AddWayPoint(const Point &Des)
{
if (!path) {
WalkTo(Des);
return;
}
Destination = Des;
//it is tempting to use 'step' here, as it could
//be about half of the current path already
PathNode *endNode = path;
while(endNode->Next) {
endNode = endNode->Next;
}
Point p(endNode->x, endNode->y);
area->ClearSearchMapFor(this);
PathNode *path2 = area->FindPath( p, Des, size );
endNode->Next = path2;
//probably it is wise to connect it both ways?
path2->Parent = endNode;
}
void Movable::FixPosition()
{
if (Type!=ST_ACTOR) {
return;
}
Actor *actor = (Actor *) this;
if (actor->GetStat(IE_DONOTJUMP)&DNJ_BIRD ) {
return;
}
//before fixposition, you should remove own shadow
area->ClearSearchMapFor(this);
Pos.x/=16;
Pos.y/=12;
GetCurrentArea()->AdjustPosition(Pos);
Pos.x=Pos.x*16+8;
Pos.y=Pos.y*12+6;
}
void Movable::WalkTo(const Point &Des, int distance)
{
Point from;
// maybe caller should be responsible for this
if ((Des.x/16 == Pos.x/16) && (Des.y/12 == Pos.y/12)) {
ClearPath();
return;
}
// the prev_step stuff is a naive attempt to allow re-pathing while moving
PathNode *prev_step = NULL;
unsigned char old_stance = StanceID;
if (step && step->Next) {
// don't interrupt in the middle of a step; path from the next one
prev_step = new PathNode(*step);
from.x = ( step->Next->x * 16 ) + 8;
from.y = ( step->Next->y * 12 ) + 6;
}
ClearPath();
if (!prev_step) {
FixPosition();
from = Pos;
}
area->ClearSearchMapFor(this);
if (distance) {
path = area->FindPathNear( from, Des, size, distance );
} else {
path = area->FindPath( from, Des, size, distance );
}
//ClearPath sets destination, so Destination must be set after it
//also we should set Destination only if there is a walkable path
if (path) {
Destination = Des;
if (prev_step) {
// we want to smoothly continue, please
// this all needs more thought! but it seems to work okay
StanceID = old_stance;
if (path->Next) {
// this is a terrible hack to make up for the
// pathfinder orienting the first node wrong
// should be fixed in pathfinder and not here!
Point next, follow;
next.x = path->x; next.y = path->y;
follow.x = path->Next->x;
follow.y = path->Next->y;
path->orient = GetOrient(follow, next);
}
// then put the prev_step at the beginning of the path
prev_step->Next = path;
path->Parent = prev_step;
path = prev_step;
step = path;
}
} else {
// pathing failed
if (prev_step) {
delete( prev_step );
FixPosition();
}
}
}
void Movable::RunAwayFrom(const Point &Des, int PathLength, int flags)
{
ClearPath();
area->ClearSearchMapFor(this);
path = area->RunAway( Pos, Des, size, PathLength, flags );
}
void Movable::RandomWalk(bool can_stop, bool run)
{
if (path) {
return;
}
//if not continous random walk, then stops for a while
if (can_stop && (rand()&3) ) {
SetWait((rand()&7)+7);
return;
}
if (run) {
InternalFlags|=IF_RUNNING;
}
//the commenting-out of the clear search map call was removed in 0.4.0
//if you want to put it back for some reason, check
//if the searchmap is not eaten up
area->ClearSearchMapFor(this);
Point p = Pos;
//selecting points around a circle's edge around actor (didn't work better)
//int x = core->Roll(1,100,-50);
//p.x+=x;
//p.y+=(int) sqrt(100-x*x);
//selecting points in a square around actor
p.x+=core->Roll(1,50,-25);
p.y+=core->Roll(1,50,-25);
//the 5th parameter is controlling the orientation of the actor
//0 - back away, 1 - face direction
path = area->RunAway( Pos, p, size, 50, 1 );
}
void Movable::MoveTo(const Point &Des)
{
area->ClearSearchMapFor(this);
Pos = Des;
Destination = Des;
if (BlocksSearchMap()) {
area->BlockSearchMap( Pos, size, IsPC()?PATH_MAP_PC:PATH_MAP_NPC);
}
}
void Movable::ClearPath()
{
//this is to make sure attackers come to us
//make sure ClearPath doesn't screw Destination (in the rare cases Destination
//is set before ClearPath
Destination = Pos;
if (StanceID==IE_ANI_WALK || StanceID==IE_ANI_RUN) {
StanceID = IE_ANI_AWAKE;
}
InternalFlags&=~IF_NORETICLE;
PathNode* thisNode = path;
while (thisNode) {
PathNode* nextNode = thisNode->Next;
delete( thisNode );
thisNode = nextNode;
}
path = NULL;
step = NULL;
//don't call ReleaseCurrentAction
}
/**********************
* Tiled Object Class *
**********************/
TileObject::TileObject()
{
opentiles = NULL;
opencount = 0;
closedtiles = NULL;
closedcount = 0;
Flags = 0;
}
TileObject::~TileObject()
{
if (opentiles) {
free( opentiles );
}
if (closedtiles) {
free( closedtiles );
}
}
void TileObject::SetOpenTiles(unsigned short* Tiles, int cnt)
{
if (opentiles) {
free( opentiles );
}
opentiles = Tiles;
opencount = cnt;
}
void TileObject::SetClosedTiles(unsigned short* Tiles, int cnt)
{
if (closedtiles) {
free( closedtiles );
}
closedtiles = Tiles;
closedcount = cnt;
}

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

Sign up for the SourceForge newsletter:





No, thanks