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
|
/*
===========================================================================
Return to Castle Wolfenstein multiplayer GPL Source Code
Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company.
This file is part of the Return to Castle Wolfenstein multiplayer GPL Source Code (“RTCW MP Source Code”).
RTCW MP Source Code is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
RTCW MP Source Code 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 RTCW MP Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the RTCW MP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW MP Source Code. If not, please request a copy in writing from id Software at the address below.
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
//===========================================================================
// bg_animation.c
//
// Incorporates several elements related to the new flexible animation system.
//
// This includes scripting elements, support routines for new animation set
// reference system and other bits and pieces.
//
//===========================================================================
#include "../qcommon/q_shared.h"
#include "bg_public.h"
// JPW NERVE -- added because I need to check single/multiplayer instances and branch accordingly
#ifdef CGAMEDLL
extern vmCvar_t cg_gameType;
#endif
#ifdef GAMEDLL
extern vmCvar_t g_gametype;
#endif
// debug defines, to prevent doing costly string cvar lookups
//#define DBGANIMS
//#define DBGANIMEVENTS
// this is used globally within this file to reduce redundant params
static animScriptData_t *globalScriptData = NULL;
#define MAX_ANIM_DEFINES 16
static char *globalFilename; // to prevent redundant params
static int parseClient;
// these are used globally during script parsing
static int numDefines[NUM_ANIM_CONDITIONS];
static char defineStrings[10000]; // stores the actual strings
static int defineStringsOffset;
static animStringItem_t defineStr[NUM_ANIM_CONDITIONS][MAX_ANIM_DEFINES];
static int defineBits[NUM_ANIM_CONDITIONS][MAX_ANIM_DEFINES][2];
static scriptAnimMoveTypes_t parseMovetype;
static int parseEvent;
animStringItem_t weaponStrings[WP_NUM_WEAPONS];
qboolean weaponStringsInited = qfalse;
animStringItem_t animStateStr[] =
{
{"RELAXED", -1},
{"QUERY", -1},
{"ALERT", -1},
{"COMBAT", -1},
{NULL, -1},
};
static animStringItem_t animMoveTypesStr[] =
{
{"** UNUSED **", -1},
{"IDLE", -1},
{"IDLECR", -1},
{"WALK", -1},
{"WALKBK", -1},
{"WALKCR", -1},
{"WALKCRBK", -1},
{"RUN", -1},
{"RUNBK", -1},
{"SWIM", -1},
{"SWIMBK", -1},
{"STRAFERIGHT", -1},
{"STRAFELEFT", -1},
{"TURNRIGHT", -1},
{"TURNLEFT", -1},
{"CLIMBUP", -1},
{"CLIMBDOWN", -1},
{"FALLEN", -1}, // DHM - Nerve :: dead, before limbo
{NULL, -1},
};
static animStringItem_t animEventTypesStr[] =
{
{"PAIN", -1},
{"DEATH", -1},
{"FIREWEAPON", -1},
{"JUMP", -1},
{"JUMPBK", -1},
{"LAND", -1},
{"DROPWEAPON", -1},
{"RAISEWEAPON", -1},
{"CLIMBMOUNT", -1},
{"CLIMBDISMOUNT", -1},
{"RELOAD", -1},
{"PICKUPGRENADE", -1},
{"KICKGRENADE", -1},
{"QUERY", -1},
{"INFORM_FRIENDLY_OF_ENEMY", -1},
{"KICK", -1},
{"REVIVE", -1},
{"FIRSTSIGHT", -1},
{"ROLL", -1},
{"FLIP", -1},
{"DIVE", -1},
{"PRONE_TO_CROUCH", -1},
{"BULLETIMPACT", -1},
{"INSPECTSOUND", -1},
{NULL, -1},
};
animStringItem_t animBodyPartsStr[] =
{
{"** UNUSED **", -1},
{"LEGS", -1},
{"TORSO", -1},
{"BOTH", -1},
{NULL, -1},
};
//------------------------------------------------------------
// conditions
static animStringItem_t animConditionPositionsStr[] =
{
{"** UNUSED **", -1},
{"BEHIND", -1},
{"INFRONT", -1},
{"RIGHT", -1},
{"LEFT", -1},
{NULL, -1},
};
static animStringItem_t animConditionMountedStr[] =
{
{"** UNUSED **", -1},
{"MG42", -1},
{NULL, -1},
};
static animStringItem_t animConditionLeaningStr[] =
{
{"** UNUSED **", -1},
{"RIGHT", -1},
{"LEFT", -1},
{NULL, -1},
};
// !!! NOTE: this must be kept in sync with the tag names in ai_cast_characters.c
static animStringItem_t animConditionImpactPointsStr[] =
{
{"** UNUSED **", -1},
{"HEAD", -1},
{"CHEST", -1},
{"GUT", -1},
{"GROIN", -1},
{"SHOULDER_RIGHT", -1},
{"SHOULDER_LEFT", -1},
{"KNEE_RIGHT", -1},
{"KNEE_LEFT", -1},
{NULL, -1},
};
// !!! NOTE: this must be kept in sync with the teams in ai_cast.h
static animStringItem_t animEnemyTeamsStr[] =
{
{"NAZI", -1},
{"ALLIES", -1},
{"MONSTER", -1},
{"SPARE1", -1},
{"SPARE2", -1},
{"SPARE3", -1},
{"SPARE4", -1},
{"NEUTRAL", -1}
};
static animStringItem_t animHealthLevelStr[] =
{
{"1", -1},
{"2", -1},
{"3", -1},
};
typedef enum
{
ANIM_CONDTYPE_BITFLAGS,
ANIM_CONDTYPE_VALUE,
NUM_ANIM_CONDTYPES
} animScriptConditionTypes_t;
typedef struct
{
animScriptConditionTypes_t type;
animStringItem_t *values;
} animConditionTable_t;
static animStringItem_t animConditionsStr[] =
{
{"WEAPONS", -1},
{"ENEMY_POSITION", -1},
{"ENEMY_WEAPON", -1},
{"UNDERWATER", -1},
{"MOUNTED", -1},
{"MOVETYPE", -1},
{"UNDERHAND", -1},
{"LEANING", -1},
{"IMPACT_POINT", -1},
{"CROUCHING", -1},
{"STUNNED", -1},
{"FIRING", -1},
{"SHORT_REACTION", -1},
{"ENEMY_TEAM", -1},
{"PARACHUTE", -1},
{"CHARGING", -1},
{"SECONDLIFE", -1},
{"HEALTH_LEVEL", -1},
{NULL, -1},
};
static animConditionTable_t animConditionsTable[NUM_ANIM_CONDITIONS] =
{
{ANIM_CONDTYPE_BITFLAGS, weaponStrings},
{ANIM_CONDTYPE_BITFLAGS, animConditionPositionsStr},
{ANIM_CONDTYPE_BITFLAGS, weaponStrings},
{ANIM_CONDTYPE_VALUE, NULL},
{ANIM_CONDTYPE_VALUE, animConditionMountedStr},
{ANIM_CONDTYPE_BITFLAGS, animMoveTypesStr},
{ANIM_CONDTYPE_VALUE, NULL},
{ANIM_CONDTYPE_VALUE, animConditionLeaningStr},
{ANIM_CONDTYPE_VALUE, animConditionImpactPointsStr},
{ANIM_CONDTYPE_VALUE, NULL},
{ANIM_CONDTYPE_VALUE, NULL},
{ANIM_CONDTYPE_VALUE, NULL},
{ANIM_CONDTYPE_VALUE, NULL},
{ANIM_CONDTYPE_VALUE, animEnemyTeamsStr},
{ANIM_CONDTYPE_VALUE, NULL},
{ANIM_CONDTYPE_VALUE, NULL},
{ANIM_CONDTYPE_VALUE, NULL},
{ANIM_CONDTYPE_VALUE, animHealthLevelStr},
};
//------------------------------------------------------------
/*
================
return a hash value for the given string
================
*/
static long BG_StringHashValue( const char *fname ) {
int i;
long hash;
char letter;
hash = 0;
i = 0;
while ( fname[i] != '\0' ) {
letter = tolower( fname[i] );
hash += (long)( letter ) * ( i + 119 );
i++;
}
if ( hash == -1 ) {
hash = 0; // never return -1
}
return hash;
}
/*
=================
BG_AnimParseError
=================
*/
void QDECL BG_AnimParseError( const char *msg, ... ) {
va_list argptr;
char text[1024];
va_start( argptr, msg );
Q_vsnprintf( text, sizeof( text ), msg, argptr );
va_end( argptr );
if ( globalFilename ) {
Com_Error( ERR_DROP, "%s: (%s, line %i)", text, globalFilename, COM_GetCurrentParseLine() + 1 );
} else {
Com_Error( ERR_DROP, "%s", text );
}
}
/*
=================
BG_ModelInfoForClient
=================
*/
animModelInfo_t *BG_ModelInfoForClient( int client ) {
if ( !globalScriptData ) {
BG_AnimParseError( "BG_ModelInfoForClient: NULL globalScriptData" );
}
//
if ( !globalScriptData->clientModels[client] ) {
BG_AnimParseError( "BG_ModelInfoForClient: client %i has no modelinfo", client );
}
//
return &globalScriptData->modelInfo[globalScriptData->clientModels[client] - 1];
}
/*
=================
BG_ModelInfoForModelname
=================
*/
animModelInfo_t *BG_ModelInfoForModelname( char *modelname ) {
int i;
animModelInfo_t *modelInfo;
//
if ( !globalScriptData ) {
BG_AnimParseError( "BG_ModelInfoForModelname: NULL globalScriptData" );
}
//
for ( i = 0, modelInfo = globalScriptData->modelInfo; i < MAX_ANIMSCRIPT_MODELS; i++, modelInfo++ ) {
if ( !modelInfo->modelname[0] ) {
continue;
}
if ( !Q_stricmp( modelname, modelInfo->modelname ) ) {
return modelInfo;
}
}
//
return NULL;
}
/*
=================
BG_AnimationIndexForString
=================
*/
int BG_AnimationIndexForString( char *string, int client ) {
int i, hash;
animation_t *anim;
animModelInfo_t *modelInfo;
modelInfo = BG_ModelInfoForClient( client );
hash = BG_StringHashValue( string );
for ( i = 0, anim = modelInfo->animations; i < modelInfo->numAnimations; i++, anim++ ) {
if ( ( hash == anim->nameHash ) && !Q_stricmp( string, anim->name ) ) {
// found a match
return i;
}
}
// no match found
BG_AnimParseError( "BG_AnimationIndexForString: unknown index '%s' for model '%s'", string, modelInfo->modelname );
return -1; // shutup compiler
}
/*
=================
BG_AnimationForString
=================
*/
animation_t *BG_AnimationForString( char *string, animModelInfo_t *modelInfo ) {
int i, hash;
animation_t *anim;
hash = BG_StringHashValue( string );
for ( i = 0, anim = modelInfo->animations; i < modelInfo->numAnimations; i++, anim++ ) {
if ( ( hash == anim->nameHash ) && !Q_stricmp( string, anim->name ) ) {
// found a match
return anim;
}
}
// no match found
Com_Error( ERR_DROP, "BG_AnimationForString: unknown animation '%s' for model '%s'", string, modelInfo->modelname );
return NULL; // shutup compiler
}
/*
=================
BG_IndexForString
errors out if no match found
=================
*/
int BG_IndexForString( char *token, animStringItem_t *strings, qboolean allowFail ) {
int i, hash;
animStringItem_t *strav;
hash = BG_StringHashValue( token );
for ( i = 0, strav = strings; strav->string; strav++, i++ ) {
if ( strav->hash == -1 ) {
strav->hash = BG_StringHashValue( strav->string );
}
if ( ( hash == strav->hash ) && !Q_stricmp( token, strav->string ) ) {
// found a match
return i;
}
}
// no match found
if ( !allowFail ) {
BG_AnimParseError( "BG_IndexForString: unknown token '%s'", token );
}
//
return -1;
}
/*
===============
BG_CopyStringIntoBuffer
===============
*/
char *BG_CopyStringIntoBuffer( char *string, char *buffer, int bufSize, int *offset ) {
char *pch;
// check for overloaded buffer
if ( *offset + strlen( string ) + 1 >= bufSize ) {
BG_AnimParseError( "BG_CopyStringIntoBuffer: out of buffer space" );
}
pch = &buffer[*offset];
// safe to do a strcpy since we've already checked for overrun
strcpy( pch, string );
// move the offset along
*offset += strlen( string ) + 1;
return pch;
}
/*
============
BG_InitWeaponStrings
Builds the list of weapon names from the item list. This is done here rather
than hardcoded to ease the process of modifying the weapons.
============
*/
void BG_InitWeaponStrings( void ) {
int i;
gitem_t *item;
memset( weaponStrings, 0, sizeof( weaponStrings ) );
for ( i = 0; i < WP_NUM_WEAPONS; i++ ) {
// find this weapon in the itemslist, and extract the name
for ( item = bg_itemlist + 1; item->classname; item++ ) {
if ( item->giType == IT_WEAPON && item->giTag == i ) {
// found a match
weaponStrings[i].string = item->pickup_name;
weaponStrings[i].hash = BG_StringHashValue( weaponStrings[i].string );
break;
}
}
if ( !item->classname ) {
weaponStrings[i].string = "(unknown)";
weaponStrings[i].hash = BG_StringHashValue( weaponStrings[i].string );
}
}
weaponStringsInited = qtrue;
}
/*
============
BG_AnimParseAnimConfig
returns qfalse if error, qtrue otherwise
============
*/
qboolean BG_AnimParseAnimConfig( animModelInfo_t *animModelInfo, const char *filename, const char *input ) {
char *text_p, *token;
animation_t *animations;
headAnimation_t *headAnims;
int i, fps, skip = -1;
if ( !weaponStringsInited ) {
BG_InitWeaponStrings();
}
globalFilename = (char *)filename;
animations = animModelInfo->animations;
animModelInfo->numAnimations = 0;
headAnims = animModelInfo->headAnims;
text_p = (char *)input;
COM_BeginParseSession( "BG_AnimParseAnimConfig" );
animModelInfo->footsteps = FOOTSTEP_NORMAL;
VectorClear( animModelInfo->headOffset );
animModelInfo->gender = GENDER_MALE;
animModelInfo->isSkeletal = qfalse;
animModelInfo->version = 0;
// read optional parameters
while ( 1 ) {
token = COM_Parse( &text_p );
if ( !token[0] ) {
break;
}
if ( !Q_stricmp( token, "footsteps" ) ) {
token = COM_Parse( &text_p );
if ( !token[0] ) {
break;
}
if ( !Q_stricmp( token, "default" ) || !Q_stricmp( token, "normal" ) ) {
animModelInfo->footsteps = FOOTSTEP_NORMAL;
} else if ( !Q_stricmp( token, "boot" ) ) {
animModelInfo->footsteps = FOOTSTEP_BOOT;
} else if ( !Q_stricmp( token, "flesh" ) ) {
animModelInfo->footsteps = FOOTSTEP_FLESH;
} else if ( !Q_stricmp( token, "mech" ) ) {
animModelInfo->footsteps = FOOTSTEP_MECH;
} else if ( !Q_stricmp( token, "energy" ) ) {
animModelInfo->footsteps = FOOTSTEP_ENERGY;
} else {
BG_AnimParseError( "Bad footsteps parm '%s'\n", token );
}
continue;
} else if ( !Q_stricmp( token, "headoffset" ) ) {
for ( i = 0 ; i < 3 ; i++ ) {
token = COM_Parse( &text_p );
if ( !token[0] ) {
break;
}
animModelInfo->headOffset[i] = atof( token );
}
continue;
} else if ( !Q_stricmp( token, "sex" ) ) {
token = COM_Parse( &text_p );
if ( !token[0] ) {
break;
}
if ( token[0] == 'f' || token[0] == 'F' ) {
animModelInfo->gender = GENDER_FEMALE;
} else if ( token[0] == 'n' || token[0] == 'N' ) {
animModelInfo->gender = GENDER_NEUTER;
} else {
animModelInfo->gender = GENDER_MALE;
}
continue;
} else if ( !Q_stricmp( token, "version" ) ) {
token = COM_Parse( &text_p );
if ( !token[0] ) {
break;
}
animModelInfo->version = atoi( token );
continue;
} else if ( !Q_stricmp( token, "skeletal" ) ) {
animModelInfo->isSkeletal = qtrue;
continue;
}
if ( animModelInfo->version < 2 ) {
// if it is a number, start parsing animations
if ( token[0] >= '0' && token[0] <= '9' ) {
text_p -= strlen( token ); // unget the token
break;
}
}
// STARTANIMS marks the start of the animations
if ( !Q_stricmp( token, "STARTANIMS" ) ) {
break;
}
BG_AnimParseError( "unknown token '%s'", token );
}
// read information for each frame
for ( i = 0 ; ( animModelInfo->version > 1 ) || ( i < MAX_ANIMATIONS ) ; i++ ) {
token = COM_Parse( &text_p );
if ( !token[0] ) {
break;
}
if ( animModelInfo->version > 1 ) { // includes animation names at start of each line
if ( !Q_stricmp( token, "ENDANIMS" ) ) { // end of animations
break;
}
Q_strncpyz( animations[i].name, token, sizeof( animations[i].name ) );
// convert to all lower case
Q_strlwr( animations[i].name );
//
token = COM_ParseExt( &text_p, qfalse );
if ( !token[0] ) {
BG_AnimParseError( "end of file without ENDANIMS" );
break;
}
} else {
// just set it to the equivalent animStrings[]
Q_strncpyz( animations[i].name, animStrings[i], sizeof( animations[i].name ) );
// convert to all lower case
Q_strlwr( animations[i].name );
}
animations[i].firstFrame = atoi( token );
if ( !animModelInfo->isSkeletal ) { // skeletal models dont require adjustment
// leg only frames are adjusted to not count the upper body only frames
if ( i == LEGS_WALKCR ) {
skip = animations[LEGS_WALKCR].firstFrame - animations[TORSO_GESTURE].firstFrame;
}
if ( i >= LEGS_WALKCR ) {
animations[i].firstFrame -= skip;
}
}
token = COM_ParseExt( &text_p, qfalse );
if ( !token[0] ) {
BG_AnimParseError( "end of file without ENDANIMS" );
break;
}
animations[i].numFrames = atoi( token );
token = COM_ParseExt( &text_p, qfalse );
if ( !token[0] ) {
BG_AnimParseError( "end of file without ENDANIMS: line %i", COM_GetCurrentParseLine() + 1 );
break;
}
animations[i].loopFrames = atoi( token );
token = COM_ParseExt( &text_p, qfalse );
if ( !token[0] ) {
BG_AnimParseError( "end of file without ENDANIMS: line %i", COM_GetCurrentParseLine() + 1 );
break;
}
fps = atof( token );
if ( fps == 0 ) {
fps = 1;
}
animations[i].frameLerp = 1000 / fps;
animations[i].initialLerp = 1000 / fps;
// movespeed
token = COM_ParseExt( &text_p, qfalse );
if ( !token[0] ) {
BG_AnimParseError( "end of file without ENDANIMS" );
break;
}
animations[i].moveSpeed = atoi( token );
// animation blending
token = COM_ParseExt( &text_p, qfalse ); // must be on same line
if ( !token[0] ) {
animations[i].animBlend = 0;
} else {
animations[i].animBlend = atoi( token );
}
// calculate the duration
animations[i].duration = animations[i].initialLerp
+ animations[i].frameLerp * animations[i].numFrames
+ animations[i].animBlend;
// get the nameHash
animations[i].nameHash = BG_StringHashValue( animations[i].name );
if ( !Q_strncmp( animations[i].name, "climb", 5 ) ) {
animations[i].flags |= ANIMFL_LADDERANIM;
}
if ( strstr( animations[i].name, "firing" ) ) {
animations[i].flags |= ANIMFL_FIRINGANIM;
animations[i].initialLerp = 40;
}
}
animModelInfo->numAnimations = i;
if ( animModelInfo->version < 2 && i != MAX_ANIMATIONS ) {
BG_AnimParseError( "Incorrect number of animations" );
return qfalse;
}
// check for head anims
token = COM_Parse( &text_p );
if ( token && token[0] ) {
if ( animModelInfo->version < 2 || !Q_stricmp( token, "HEADFRAMES" ) ) {
// read information for each head frame
for ( i = 0 ; i < MAX_HEAD_ANIMS ; i++ ) {
token = COM_Parse( &text_p );
if ( !token[0] ) {
break;
}
if ( animModelInfo->version > 1 ) { // includes animation names at start of each line
// just throw this information away, not required for head
token = COM_ParseExt( &text_p, qfalse );
if ( !token[0] ) {
break;
}
}
if ( !i ) {
skip = atoi( token );
}
headAnims[i].firstFrame = atoi( token );
// modify according to last frame of the main animations, since the head is totally seperate
headAnims[i].firstFrame -= animations[MAX_ANIMATIONS - 1].firstFrame + animations[MAX_ANIMATIONS - 1].numFrames + skip;
token = COM_ParseExt( &text_p, qfalse );
if ( !token[0] ) {
break;
}
headAnims[i].numFrames = atoi( token );
// skip the movespeed
COM_ParseExt( &text_p, qfalse );
}
animModelInfo->numHeadAnims = i;
if ( i != MAX_HEAD_ANIMS ) {
BG_AnimParseError( "Incorrect number of head frames" );
return qfalse;
}
}
}
return qtrue;
}
/*
=================
BG_ParseConditionBits
convert the string into a single int containing bit flags, stopping at a ',' or end of line
=================
*/
#define RESULT_SIZE 2
void BG_ParseConditionBits( char **text_pp, animStringItem_t *stringTable, int condIndex, int result[RESULT_SIZE] ) {
qboolean endFlag = qfalse;
int indexFound;
int tempBits[2];
char currentString[MAX_QPATH];
qboolean minus = qfalse;
char *token;
currentString[0] = '\0';
memset( result, 0, sizeof( result[0] ) * RESULT_SIZE );
memset( tempBits, 0, sizeof( tempBits ) );
while ( !endFlag ) {
token = COM_ParseExt( text_pp, qfalse );
if ( !token[0] ) {
COM_RestoreParseSession( text_pp ); // go back to the previous token
endFlag = qtrue; // done parsing indexes
if ( !strlen( currentString ) ) {
break;
}
}
if ( !Q_stricmp( token, "," ) ) {
endFlag = qtrue; // end of indexes
}
if ( !Q_stricmp( token, "none" ) ) { // first bit is always the "unused" bit
COM_BitSet( result, 0 );
continue;
}
if ( !Q_stricmp( token, "none," ) ) { // first bit is always the "unused" bit
COM_BitSet( result, 0 );
endFlag = qtrue; // end of indexes
continue;
}
if ( !Q_stricmp( token, "NOT" ) ) {
token = "MINUS"; // NOT is equivalent to MINUS
}
if ( !endFlag && Q_stricmp( token, "AND" ) && Q_stricmp( token, "MINUS" ) ) { // must be a index
// check for a comma (end of indexes)
if ( token[strlen( token ) - 1] == ',' ) {
endFlag = qtrue;
token[strlen( token ) - 1] = '\0';
}
// append this to the currentString
if ( strlen( currentString ) ) {
Q_strcat( currentString, sizeof( currentString ), " " );
}
Q_strcat( currentString, sizeof( currentString ), token );
}
if ( !Q_stricmp( token, "AND" ) || !Q_stricmp( token, "MINUS" ) || endFlag ) {
// process the currentString
if ( !strlen( currentString ) ) {
if ( endFlag ) {
BG_AnimParseError( "BG_AnimParseAnimScript: unexpected end of condition" );
} else {
// check for minus indexes to follow
if ( !Q_stricmp( token, "MINUS" ) ) {
minus = qtrue;
continue;
}
BG_AnimParseError( "BG_AnimParseAnimScript: unexpected '%s'", token );
}
}
if ( !Q_stricmp( currentString, "all" ) ) {
tempBits[0] = ~0x0;
tempBits[1] = ~0x0;
} else {
// first check this string with our defines
indexFound = BG_IndexForString( currentString, defineStr[condIndex], qtrue );
if ( indexFound >= 0 ) {
// we have precalculated the bitflags for the defines
tempBits[0] = defineBits[condIndex][indexFound][0];
tempBits[1] = defineBits[condIndex][indexFound][1];
} else {
// convert the string into an index
indexFound = BG_IndexForString( currentString, stringTable, qfalse );
// convert the index into a bitflag
COM_BitSet( tempBits, indexFound );
}
}
// perform operation
if ( minus ) { // subtract
result[0] &= ~tempBits[0];
result[1] &= ~tempBits[1];
} else { // add
result[0] |= tempBits[0];
result[1] |= tempBits[1];
}
// clear the currentString
currentString[0] = '\0';
// check for minus indexes to follow
if ( !Q_stricmp( token, "MINUS" ) ) {
minus = qtrue;
}
}
}
}
/*
=================
BG_ParseConditions
returns qtrue if everything went ok, error drops otherwise
=================
*/
qboolean BG_ParseConditions( char **text_pp, animScriptItem_t *scriptItem ) {
int conditionIndex, conditionValue[2];
char *token;
conditionValue[0] = 0;
conditionValue[1] = 0;
while ( 1 ) {
token = COM_ParseExt( text_pp, qfalse );
if ( !token[0] ) {
break;
}
// special case, "default" has no conditions
if ( !Q_stricmp( token, "default" ) ) {
return qtrue;
}
conditionIndex = BG_IndexForString( token, animConditionsStr, qfalse );
switch ( animConditionsTable[conditionIndex].type ) {
case ANIM_CONDTYPE_BITFLAGS:
BG_ParseConditionBits( text_pp, animConditionsTable[conditionIndex].values, conditionIndex, conditionValue );
break;
case ANIM_CONDTYPE_VALUE:
if ( animConditionsTable[conditionIndex].values ) {
token = COM_ParseExt( text_pp, qfalse );
if ( !token[0] ) {
BG_AnimParseError( "BG_AnimParseAnimScript: expected condition value, found end of line" ); // RF modification
break;
}
// check for a comma (condition divider)
if ( token[strlen( token ) - 1] == ',' ) {
token[strlen( token ) - 1] = '\0';
}
conditionValue[0] = BG_IndexForString( token, animConditionsTable[conditionIndex].values, qfalse );
} else {
conditionValue[0] = 1; // not used, just check for a positive condition
}
break;
default: // TTimo gcc: NUM_ANIM_CONDTYPES not handled in switch
break;
}
// now append this condition to the item
scriptItem->conditions[scriptItem->numConditions].index = conditionIndex;
scriptItem->conditions[scriptItem->numConditions].value[0] = conditionValue[0];
scriptItem->conditions[scriptItem->numConditions].value[1] = conditionValue[1];
scriptItem->numConditions++;
}
if ( scriptItem->numConditions == 0 ) {
BG_AnimParseError( "BG_ParseConditions: no conditions found" ); // RF mod
}
return qtrue;
}
/*
=================
BG_ParseCommands
=================
*/
void BG_ParseCommands( char **input, animScriptItem_t *scriptItem, animModelInfo_t *modelInfo, animScriptData_t *scriptData ) {
char *token;
// TTimo gcc: might be used uninitialized
animScriptCommand_t *command = NULL;
int partIndex = 0;
while ( 1 ) {
// parse the body part
token = COM_ParseExt( input, ( partIndex < 1 ) );
if ( !token[0] ) {
break;
}
if ( !Q_stricmp( token, "}" ) ) {
// unget the bracket and get out of here
*input -= strlen( token );
break;
}
// new command?
if ( partIndex == 0 ) {
// have we exceeded the maximum number of commands?
if ( scriptItem->numCommands >= MAX_ANIMSCRIPT_ANIMCOMMANDS ) {
BG_AnimParseError( "BG_ParseCommands: exceeded maximum number of animations (%i)", MAX_ANIMSCRIPT_ANIMCOMMANDS );
}
command = &scriptItem->commands[scriptItem->numCommands++];
memset( command, 0, sizeof( *command ) );
}
command->bodyPart[partIndex] = BG_IndexForString( token, animBodyPartsStr, qtrue );
if ( command->bodyPart[partIndex] > 0 ) {
// parse the animation
token = COM_ParseExt( input, qfalse );
if ( !token[0] ) {
BG_AnimParseError( "BG_ParseCommands: expected animation" );
}
command->animIndex[partIndex] = BG_AnimationIndexForString( token, parseClient );
command->animDuration[partIndex] = modelInfo->animations[command->animIndex[partIndex]].duration;
// if this is a locomotion, set the movetype of the animation so we can reverse engineer the movetype from the animation, on the client
if ( parseMovetype != ANIM_MT_UNUSED && command->bodyPart[partIndex] != ANIM_BP_TORSO ) {
modelInfo->animations[command->animIndex[partIndex]].movetype |= ( 1 << parseMovetype );
}
// if this is a fireweapon event, then this is a firing animation
if ( parseEvent == ANIM_ET_FIREWEAPON ) {
modelInfo->animations[command->animIndex[partIndex]].flags |= ANIMFL_FIRINGANIM;
modelInfo->animations[command->animIndex[partIndex]].initialLerp = 40;
}
// check for a duration for this animation instance
token = COM_ParseExt( input, qfalse );
if ( token && token[0] ) {
if ( !Q_stricmp( token, "duration" ) ) {
// read the duration
token = COM_ParseExt( input, qfalse );
if ( !token[0] ) {
BG_AnimParseError( "BG_ParseCommands: expected duration value" );
break;
}
command->animDuration[partIndex] = atoi( token );
} else { // unget the token
COM_RestoreParseSession( input );
}
} else {
COM_RestoreParseSession( input );
}
if ( command->bodyPart[partIndex] != ANIM_BP_BOTH && partIndex++ < 1 ) {
continue; // allow parsing of another bodypart
}
} else {
// unget the token
*input -= strlen( token );
}
// parse optional parameters (sounds, etc)
while ( 1 ) {
token = COM_ParseExt( input, qfalse );
if ( !token[0] ) {
break;
}
if ( !Q_stricmp( token, "sound" ) ) {
token = COM_ParseExt( input, qfalse );
if ( !token[0] ) {
BG_AnimParseError( "BG_ParseCommands: expected sound" );
break;
}
// NOTE: only sound script are supported at this stage
if ( strstr( token, ".wav" ) ) {
BG_AnimParseError( "BG_ParseCommands: wav files not supported, only sound scripts" ); // RF mod
}
command->soundIndex = globalScriptData->soundIndex( token );
} else {
// unknown??
BG_AnimParseError( "BG_ParseCommands: unknown parameter '%s'", token );
}
}
partIndex = 0;
}
}
/*
=================
BG_AnimParseAnimScript
Parse the animation script for this model, converting it into run-time structures
=================
*/
typedef enum
{
PARSEMODE_DEFINES,
PARSEMODE_ANIMATION,
PARSEMODE_CANNED_ANIMATIONS,
PARSEMODE_STATECHANGES,
PARSEMODE_EVENTS
} animScriptParseMode_t;
static animStringItem_t animParseModesStr[] =
{
{"defines", -1},
{"animations", -1},
{"canned_animations", -1},
{"statechanges", -1},
{"events", -1},
{NULL, -1},
};
void BG_AnimParseAnimScript( animModelInfo_t *modelInfo, animScriptData_t *scriptData, int client, char *filename, char *input ) {
#define MAX_INDENT_LEVELS 3
char *text_p, *token;
animScriptParseMode_t parseMode;
animScript_t *currentScript;
animScriptItem_t tempScriptItem;
// TTimo gcc: might be used unitialized
animScriptItem_t *currentScriptItem = NULL;
int indexes[MAX_INDENT_LEVELS], indentLevel, oldState, newParseMode;
int i, defineType;
// the scriptData passed into here must be the one this binary is using
globalScriptData = scriptData;
// current client being parsed
parseClient = client;
// start at the defines
parseMode = PARSEMODE_DEFINES;
// record which modelInfo this client is using
scriptData->clientModels[client] = 1 + (int)( modelInfo - scriptData->modelInfo );
// init the global defines
globalFilename = filename;
memset( defineStr, 0, sizeof( defineStr ) );
memset( defineStrings, 0, sizeof( defineStrings ) );
memset( numDefines, 0, sizeof( numDefines ) );
defineStringsOffset = 0;
for ( i = 0; i < MAX_INDENT_LEVELS; i++ )
indexes[i] = -1;
indentLevel = 0;
currentScript = NULL;
text_p = input;
COM_BeginParseSession( "BG_AnimParseAnimScript" );
// read in the weapon defines
while ( 1 ) {
token = COM_Parse( &text_p );
if ( !token[0] ) {
if ( indentLevel ) {
BG_AnimParseError( "BG_AnimParseAnimScript: unexpected end of file: %s", token );
}
break;
}
// check for a new section
newParseMode = BG_IndexForString( token, animParseModesStr, qtrue );
if ( newParseMode >= 0 ) {
if ( indentLevel ) {
BG_AnimParseError( "BG_AnimParseAnimScript: unexpected '%s'", token ); // RF mod
}
parseMode = newParseMode;
parseMovetype = ANIM_MT_UNUSED;
parseEvent = -1;
continue;
}
switch ( parseMode ) {
case PARSEMODE_DEFINES:
if ( !Q_stricmp( token, "set" ) ) {
// read in the define type
token = COM_ParseExt( &text_p, qfalse );
if ( !token[0] ) {
BG_AnimParseError( "BG_AnimParseAnimScript: expected condition type string" ); // RF mod
}
defineType = BG_IndexForString( token, animConditionsStr, qfalse );
// read in the define
token = COM_ParseExt( &text_p, qfalse );
if ( !token[0] ) {
BG_AnimParseError( "BG_AnimParseAnimScript: expected condition define string" ); // RF mod
}
// copy the define to the strings list
defineStr[defineType][numDefines[defineType]].string = BG_CopyStringIntoBuffer( token, defineStrings, sizeof( defineStrings ), &defineStringsOffset );
defineStr[defineType][numDefines[defineType]].hash = BG_StringHashValue( defineStr[defineType][numDefines[defineType]].string );
// expecting an =
token = COM_ParseExt( &text_p, qfalse );
if ( !token[0] ) {
BG_AnimParseError( "BG_AnimParseAnimScript: expected '=', found end of line" ); // RF mod
}
if ( Q_stricmp( token, "=" ) ) {
BG_AnimParseError( "BG_AnimParseAnimScript: expected '=', found '%s'", token ); // RF mod
}
// parse the bits
BG_ParseConditionBits( &text_p, animConditionsTable[defineType].values, defineType, defineBits[defineType][numDefines[defineType]] );
numDefines[defineType]++;
// copy the weapon defines over to the enemy_weapon defines
memcpy( &defineStr[ANIM_COND_ENEMY_WEAPON][0], &defineStr[ANIM_COND_WEAPON][0], sizeof( animStringItem_t ) * MAX_ANIM_DEFINES );
memcpy( &defineBits[ANIM_COND_ENEMY_WEAPON][0], &defineBits[ANIM_COND_WEAPON][0], sizeof( defineBits[ANIM_COND_ENEMY_WEAPON][0] ) * MAX_ANIM_DEFINES );
numDefines[ANIM_COND_ENEMY_WEAPON] = numDefines[ANIM_COND_WEAPON];
}
break;
case PARSEMODE_ANIMATION:
case PARSEMODE_CANNED_ANIMATIONS:
if ( !Q_stricmp( token, "{" ) ) {
// about to increment indent level, check that we have enough information to do this
if ( indentLevel >= MAX_INDENT_LEVELS ) { // too many indentations
BG_AnimParseError( "BG_AnimParseAnimScript: unexpected '%s'", token ); // RF mod
}
if ( indexes[indentLevel] < 0 ) { // we havent found out what this new group is yet
BG_AnimParseError( "BG_AnimParseAnimScript: unexpected '%s'", token ); // RF mod
}
//
indentLevel++;
} else if ( !Q_stricmp( token, "}" ) ) {
// reduce the indentLevel
indentLevel--;
if ( indentLevel < 0 ) {
BG_AnimParseError( "BG_AnimParseAnimScript: unexpected '%s'", token ); // RF mod
}
if ( indentLevel == 1 ) {
currentScript = NULL;
}
// make sure we read a new index before next indent
indexes[indentLevel] = -1;
} else if ( indentLevel == 0 && ( indexes[indentLevel] < 0 ) ) {
if ( Q_stricmp( token, "state" ) ) {
BG_AnimParseError( "BG_AnimParseAnimScript: expected 'state'" ); // RF mod
}
// read in the state type
token = COM_ParseExt( &text_p, qfalse );
if ( !token[0] ) {
BG_AnimParseError( "BG_AnimParseAnimScript: expected state type" ); // RF mod
}
indexes[indentLevel] = BG_IndexForString( token, animStateStr, qfalse );
//----(SA) // RF mod
// check for the open bracket
token = COM_ParseExt( &text_p, qtrue );
if ( !token[0] || Q_stricmp( token, "{" ) ) {
BG_AnimParseError( "BG_AnimParseAnimScript: expected '{'" );
}
indentLevel++;
//----(SA) // RF mod
} else if ( ( indentLevel == 1 ) && ( indexes[indentLevel] < 0 ) ) {
// we are expecting a movement type
indexes[indentLevel] = BG_IndexForString( token, animMoveTypesStr, qfalse );
if ( parseMode == PARSEMODE_ANIMATION ) {
currentScript = &modelInfo->scriptAnims[indexes[0]][indexes[1]];
parseMovetype = indexes[1];
} else if ( parseMode == PARSEMODE_CANNED_ANIMATIONS ) {
currentScript = &modelInfo->scriptCannedAnims[indexes[0]][indexes[1]];
}
memset( currentScript, 0, sizeof( *currentScript ) );
} else if ( ( indentLevel == 2 ) && ( indexes[indentLevel] < 0 ) ) {
// we are expecting a condition specifier
// move the text_p backwards so we can read in the last token again
text_p -= strlen( token );
// sanity check that
if ( Q_strncmp( text_p, token, strlen( token ) ) ) {
// this should never happen, just here to check that this operation is correct before code goes live
BG_AnimParseError( "BG_AnimParseAnimScript: internal error" );
}
//
memset( &tempScriptItem, 0, sizeof( tempScriptItem ) );
indexes[indentLevel] = BG_ParseConditions( &text_p, &tempScriptItem );
// do we have enough room in this script for another item?
if ( currentScript->numItems >= MAX_ANIMSCRIPT_ITEMS ) {
BG_AnimParseError( "BG_AnimParseAnimScript: exceeded maximum items per script (%i)", MAX_ANIMSCRIPT_ITEMS ); // RF mod
}
// are there enough items left in the global list?
if ( modelInfo->numScriptItems >= MAX_ANIMSCRIPT_ITEMS_PER_MODEL ) {
BG_AnimParseError( "BG_AnimParseAnimScript: exceeded maximum global items (%i)", MAX_ANIMSCRIPT_ITEMS_PER_MODEL ); // RF mod
}
// it was parsed ok, so grab an item from the global list to use
currentScript->items[currentScript->numItems] = &modelInfo->scriptItems[ modelInfo->numScriptItems++ ];
currentScriptItem = currentScript->items[currentScript->numItems];
currentScript->numItems++;
// copy the data across from the temp script item
*currentScriptItem = tempScriptItem;
} else if ( indentLevel == 3 ) {
// we are reading the commands, so parse this line as if it were a command
// move the text_p backwards so we can read in the last token again
text_p -= strlen( token );
// sanity check that
if ( Q_strncmp( text_p, token, strlen( token ) ) ) {
// this should never happen, just here to check that this operation is correct before code goes live
BG_AnimParseError( "BG_AnimParseAnimScript: internal error" );
}
//
BG_ParseCommands( &text_p, currentScriptItem, modelInfo, scriptData );
} else {
// huh ??
BG_AnimParseError( "BG_AnimParseAnimScript: unexpected '%s'", token ); // RF mod
}
break;
case PARSEMODE_STATECHANGES:
case PARSEMODE_EVENTS:
if ( !Q_stricmp( token, "{" ) ) {
// about to increment indent level, check that we have enough information to do this
if ( indentLevel >= MAX_INDENT_LEVELS ) { // too many indentations
BG_AnimParseError( "BG_AnimParseAnimScript: unexpected '%s'", token ); // RF mod
}
if ( indexes[indentLevel] < 0 ) { // we havent found out what this new group is yet
BG_AnimParseError( "BG_AnimParseAnimScript: unexpected '%s'", token ); // RF mod
}
//
indentLevel++;
} else if ( !Q_stricmp( token, "}" ) ) {
// reduce the indentLevel
indentLevel--;
if ( indentLevel < 0 ) {
BG_AnimParseError( "BG_AnimParseAnimScript: unexpected '%s'", token ); // RF mod
}
if ( indentLevel == 0 ) {
currentScript = NULL;
}
// make sure we read a new index before next indent
indexes[indentLevel] = -1;
} else if ( indentLevel == 0 && ( indexes[indentLevel] < 0 ) ) {
if ( parseMode == PARSEMODE_STATECHANGES ) {
if ( Q_stricmp( token, "statechange" ) ) {
BG_AnimParseError( "BG_AnimParseAnimScript: expected 'statechange', got '%s'", token ); // RF mod
}
// read in the old state type
token = COM_ParseExt( &text_p, qfalse );
if ( !token[0] ) {
BG_AnimParseError( "BG_AnimParseAnimScript: expected <state type>" ); // RF mod
}
oldState = BG_IndexForString( token, animStateStr, qfalse );
// read in the new state type
token = COM_ParseExt( &text_p, qfalse );
if ( !token[0] ) {
BG_AnimParseError( "BG_AnimParseAnimScript: expected <state type>" ); // RF mod
}
indexes[indentLevel] = BG_IndexForString( token, animStateStr, qfalse );
currentScript = &modelInfo->scriptStateChange[oldState][indexes[indentLevel]];
//----(SA) // RF mod
// check for the open bracket
token = COM_ParseExt( &text_p, qtrue );
if ( !token[0] || Q_stricmp( token, "{" ) ) {
BG_AnimParseError( "BG_AnimParseAnimScript: expected '{'" );
}
indentLevel++;
//----(SA) // RF mod
} else {
// read in the event type
indexes[indentLevel] = BG_IndexForString( token, animEventTypesStr, qfalse );
currentScript = &modelInfo->scriptEvents[indexes[0]];
parseEvent = indexes[indentLevel];
}
memset( currentScript, 0, sizeof( *currentScript ) );
} else if ( ( indentLevel == 1 ) && ( indexes[indentLevel] < 0 ) ) {
// we are expecting a condition specifier
// move the text_p backwards so we can read in the last token again
text_p -= strlen( token );
// sanity check that
if ( Q_strncmp( text_p, token, strlen( token ) ) ) {
// this should never happen, just here to check that this operation is correct before code goes live
BG_AnimParseError( "BG_AnimParseAnimScript: internal error" );
}
//
memset( &tempScriptItem, 0, sizeof( tempScriptItem ) );
indexes[indentLevel] = BG_ParseConditions( &text_p, &tempScriptItem );
// do we have enough room in this script for another item?
if ( currentScript->numItems >= MAX_ANIMSCRIPT_ITEMS ) {
BG_AnimParseError( "BG_AnimParseAnimScript: exceeded maximum items per script (%i)", MAX_ANIMSCRIPT_ITEMS ); // RF mod
}
// are there enough items left in the global list?
if ( modelInfo->numScriptItems >= MAX_ANIMSCRIPT_ITEMS_PER_MODEL ) {
BG_AnimParseError( "BG_AnimParseAnimScript: exceeded maximum global items (%i)", MAX_ANIMSCRIPT_ITEMS_PER_MODEL ); // RF mod
}
// it was parsed ok, so grab an item from the global list to use
currentScript->items[currentScript->numItems] = &modelInfo->scriptItems[ modelInfo->numScriptItems++ ];
currentScriptItem = currentScript->items[currentScript->numItems];
currentScript->numItems++;
// copy the data across from the temp script item
*currentScriptItem = tempScriptItem;
} else if ( indentLevel == 2 ) {
// we are reading the commands, so parse this line as if it were a command
// move the text_p backwards so we can read in the last token again
text_p -= strlen( token );
// sanity check that
if ( Q_strncmp( text_p, token, strlen( token ) ) ) {
// this should never happen, just here to check that this operation is correct before code goes live
BG_AnimParseError( "BG_AnimParseAnimScript: internal error" );
}
//
BG_ParseCommands( &text_p, currentScriptItem, modelInfo, scriptData );
} else {
// huh ??
BG_AnimParseError( "BG_AnimParseAnimScript: unexpected '%s'", token ); // RF mod
}
}
}
globalFilename = NULL;
}
//------------------------------------------------------------------------
//
// run-time gameplay functions, these are called during gameplay, so they must be
// cpu efficient.
//
/*
===============
BG_EvaluateConditions
returns qfalse if the set of conditions fails, qtrue otherwise
===============
*/
qboolean BG_EvaluateConditions( int client, animScriptItem_t *scriptItem ) {
int i;
animScriptCondition_t *cond;
for ( i = 0, cond = scriptItem->conditions; i < scriptItem->numConditions; i++, cond++ )
{
switch ( animConditionsTable[cond->index].type ) {
case ANIM_CONDTYPE_BITFLAGS:
if ( !( globalScriptData->clientConditions[client][cond->index][0] & cond->value[0] ) &&
!( globalScriptData->clientConditions[client][cond->index][1] & cond->value[1] ) ) {
return qfalse;
}
break;
case ANIM_CONDTYPE_VALUE:
if ( !( globalScriptData->clientConditions[client][cond->index][0] == cond->value[0] ) ) {
return qfalse;
}
break;
default: // TTimo NUM_ANIM_CONDTYPES not handled
break;
}
}
//
// all conditions must have passed
return qtrue;
}
/*
===============
BG_FirstValidItem
scroll through the script items, returning the first script found to pass all conditions
returns NULL if no match found
===============
*/
animScriptItem_t *BG_FirstValidItem( int client, animScript_t *script ) {
animScriptItem_t **ppScriptItem;
int i;
for ( i = 0, ppScriptItem = script->items; i < script->numItems; i++, ppScriptItem++ )
{
if ( BG_EvaluateConditions( client, *ppScriptItem ) ) {
return *ppScriptItem;
}
}
//
return NULL;
}
/*
===============
BG_PlayAnim
===============
*/
int BG_PlayAnim( playerState_t *ps, int animNum, animBodyPart_t bodyPart, int forceDuration, qboolean setTimer, qboolean isContinue, qboolean force ) {
int duration;
qboolean wasSet = qfalse;
animModelInfo_t *modelInfo;
modelInfo = BG_ModelInfoForClient( ps->clientNum );
if ( forceDuration ) {
duration = forceDuration;
} else {
duration = modelInfo->animations[animNum].duration + 50; // account for lerping between anims
}
switch ( bodyPart ) {
case ANIM_BP_BOTH:
case ANIM_BP_LEGS:
if ( ( ps->legsTimer < 50 ) || force ) {
if ( !isContinue || !( ( ps->legsAnim & ~ANIM_TOGGLEBIT ) == animNum ) ) {
wasSet = qtrue;
ps->legsAnim = ( ( ps->legsAnim & ANIM_TOGGLEBIT ) ^ ANIM_TOGGLEBIT ) | animNum;
if ( setTimer ) {
ps->legsTimer = duration;
}
} else if ( setTimer && modelInfo->animations[animNum].loopFrames ) {
ps->legsTimer = duration;
}
}
if ( bodyPart == ANIM_BP_LEGS ) {
break;
}
case ANIM_BP_TORSO:
if ( ( ps->torsoTimer < 50 ) || force ) {
if ( !isContinue || !( ( ps->torsoAnim & ~ANIM_TOGGLEBIT ) == animNum ) ) {
ps->torsoAnim = ( ( ps->torsoAnim & ANIM_TOGGLEBIT ) ^ ANIM_TOGGLEBIT ) | animNum;
if ( setTimer ) {
ps->torsoTimer = duration;
}
} else if ( setTimer && modelInfo->animations[animNum].loopFrames ) {
ps->torsoTimer = duration;
}
}
break;
default: // TTimo default ANIM_BP_UNUSED NUM_ANIM_BODYPARTS not handled
break;
}
if ( !wasSet ) {
return -1;
}
return duration;
}
/*
===============
BG_PlayAnimName
===============
*/
int BG_PlayAnimName( playerState_t *ps, char *animName, animBodyPart_t bodyPart, qboolean setTimer, qboolean isContinue, qboolean force ) {
return BG_PlayAnim( ps, BG_AnimationIndexForString( animName, ps->clientNum ), bodyPart, 0, setTimer, isContinue, force );
}
/*
===============
BG_ExecuteCommand
returns the duration of the animation, -1 if no anim was set
===============
*/
int BG_ExecuteCommand( playerState_t *ps, animScriptCommand_t *scriptCommand, qboolean setTimer, qboolean isContinue, qboolean force ) {
int duration = -1;
qboolean playedLegsAnim = qfalse;
if ( scriptCommand->bodyPart[0] ) {
duration = scriptCommand->animDuration[0] + 50;
// FIXME: how to sync torso/legs anims accounting for transition blends, etc
if ( scriptCommand->bodyPart[0] == ANIM_BP_BOTH || scriptCommand->bodyPart[0] == ANIM_BP_LEGS ) {
playedLegsAnim = ( BG_PlayAnim( ps, scriptCommand->animIndex[0], scriptCommand->bodyPart[0], duration, setTimer, isContinue, force ) > -1 );
} else {
BG_PlayAnim( ps, scriptCommand->animIndex[0], scriptCommand->bodyPart[0], duration, setTimer, isContinue, force );
}
}
if ( scriptCommand->bodyPart[1] ) {
duration = scriptCommand->animDuration[0] + 50;
// FIXME: how to sync torso/legs anims accounting for transition blends, etc
// just play the animation for the torso
if ( scriptCommand->bodyPart[1] == ANIM_BP_BOTH || scriptCommand->bodyPart[1] == ANIM_BP_LEGS ) {
playedLegsAnim = ( BG_PlayAnim( ps, scriptCommand->animIndex[1], scriptCommand->bodyPart[1], duration, setTimer, isContinue, force ) > -1 );
} else {
BG_PlayAnim( ps, scriptCommand->animIndex[1], scriptCommand->bodyPart[1], duration, setTimer, isContinue, force );
}
}
if ( scriptCommand->soundIndex ) {
globalScriptData->playSound( scriptCommand->soundIndex, ps->origin, ps->clientNum );
}
if ( !playedLegsAnim ) {
return -1;
}
return duration;
}
/*
================
BG_AnimScriptAnimation
runs the normal locomotive animations
returns 1 if an animation was set, -1 if no animation was found, 0 otherwise
================
*/
int BG_AnimScriptAnimation( playerState_t *ps, aistateEnum_t state, scriptAnimMoveTypes_t movetype, qboolean isContinue ) {
animModelInfo_t *modelInfo = NULL;
animScript_t *script = NULL;
animScriptItem_t *scriptItem = NULL;
animScriptCommand_t *scriptCommand = NULL;
// DHM - Nerve :: Allow fallen movetype while dead
if ( ps->eFlags & EF_DEAD && movetype != ANIM_MT_FALLEN ) {
return -1;
}
modelInfo = BG_ModelInfoForClient( ps->clientNum );
#ifdef DBGANIMS
if ( ps->clientNum ) {
Com_Printf( "script anim: cl %i, mt %s, ", ps->clientNum, animMoveTypesStr[movetype] );
}
#endif
// try finding a match in all states below the given state
while ( !scriptItem && state >= 0 ) {
script = &modelInfo->scriptAnims[ state ][ movetype ];
if ( !script->numItems ) {
state--;
continue;
}
// find the first script item, that passes all the conditions for this event
scriptItem = BG_FirstValidItem( ps->clientNum, script );
if ( !scriptItem ) {
state--;
continue;
}
}
//
if ( !scriptItem ) {
#ifdef DBGANIMS
if ( ps->clientNum ) {
Com_Printf( "no valid conditions\n" );
}
#endif
return -1;
}
// save this as our current movetype
BG_UpdateConditionValue( ps->clientNum, ANIM_COND_MOVETYPE, movetype, qtrue );
// pick the correct animation for this character (animations must be constant for each character, otherwise they'll constantly change)
scriptCommand = &scriptItem->commands[ ps->clientNum % scriptItem->numCommands ];
#ifdef DBGANIMS
if ( scriptCommand->bodyPart[0] ) {
if ( ps->clientNum ) {
Com_Printf( "anim0 (%s): %s", animBodyPartsStr[scriptCommand->bodyPart[0]].string, modelInfo->animations[scriptCommand->animIndex[0]].name );
}
}
if ( scriptCommand->bodyPart[1] ) {
if ( ps->clientNum ) {
Com_Printf( "anim1 (%s): %s", animBodyPartsStr[scriptCommand->bodyPart[1]].string, modelInfo->animations[scriptCommand->animIndex[1]].name );
}
}
if ( ps->clientNum ) {
Com_Printf( "\n" );
}
#endif
// run it
return ( BG_ExecuteCommand( ps, scriptCommand, qfalse, isContinue, qfalse ) != -1 );
}
/*
================
BG_AnimScriptCannedAnimation
uses the current movetype for this client to play a canned animation
returns the duration in milliseconds that this model should be paused. -1 if no anim found
================
*/
int BG_AnimScriptCannedAnimation( playerState_t *ps, aistateEnum_t state ) {
animModelInfo_t *modelInfo;
animScript_t *script;
animScriptItem_t *scriptItem;
animScriptCommand_t *scriptCommand;
scriptAnimMoveTypes_t movetype;
if ( ps->eFlags & EF_DEAD ) {
return -1;
}
movetype = globalScriptData->clientConditions[ ps->clientNum ][ ANIM_COND_MOVETYPE ][0];
if ( !movetype ) { // no valid movetype yet for this client
return -1;
}
//
modelInfo = BG_ModelInfoForClient( ps->clientNum );
script = &modelInfo->scriptCannedAnims[ state ][ movetype ];
if ( !script->numItems ) {
return -1;
}
// find the first script item, that passes all the conditions for this event
scriptItem = BG_FirstValidItem( ps->clientNum, script );
if ( !scriptItem ) {
return -1;
}
// pick a random command
scriptCommand = &scriptItem->commands[ rand() % scriptItem->numCommands ];
// run it
return BG_ExecuteCommand( ps, scriptCommand, qtrue, qfalse, qfalse );
}
/*
================
BG_AnimScriptStateChange
returns the duration in milliseconds that this model should be paused. -1 if no anim found
================
*/
int BG_AnimScriptStateChange( playerState_t *ps, aistateEnum_t newState, aistateEnum_t oldState ) {
animModelInfo_t *modelInfo;
animScript_t *script;
animScriptItem_t *scriptItem;
animScriptCommand_t *scriptCommand;
if ( ps->eFlags & EF_DEAD ) {
return -1;
}
modelInfo = BG_ModelInfoForClient( ps->clientNum );
script = &modelInfo->scriptStateChange[ oldState ][ newState ];
if ( !script->numItems ) {
return -1;
}
// find the first script item, that passes all the conditions for this event
scriptItem = BG_FirstValidItem( ps->clientNum, script );
if ( !scriptItem ) {
return -1;
}
// pick a random command
scriptCommand = &scriptItem->commands[ rand() % scriptItem->numCommands ];
// run it
return BG_ExecuteCommand( ps, scriptCommand, qtrue, qfalse, qfalse );
}
/*
================
BG_AnimScriptEvent
returns the duration in milliseconds that this model should be paused. -1 if no event found
================
*/
int BG_AnimScriptEvent( playerState_t *ps, scriptAnimEventTypes_t event, qboolean isContinue, qboolean force ) {
animModelInfo_t *modelInfo;
animScript_t *script;
animScriptItem_t *scriptItem;
animScriptCommand_t *scriptCommand;
if ( event != ANIM_ET_DEATH && ps->eFlags & EF_DEAD ) {
return -1;
}
#ifdef DBGANIMEVENTS
Com_Printf( "script event: cl %i, ev %s, ", ps->clientNum, animEventTypesStr[event] );
#endif
modelInfo = BG_ModelInfoForClient( ps->clientNum );
script = &modelInfo->scriptEvents[ event ];
if ( !script->numItems ) {
#ifdef DBGANIMEVENTS
Com_Printf( "no entry\n" );
#endif
return -1;
}
// find the first script item, that passes all the conditions for this event
scriptItem = BG_FirstValidItem( ps->clientNum, script );
if ( !scriptItem ) {
#ifdef DBGANIMEVENTS
Com_Printf( "no valid conditions\n" );
#endif
return -1;
}
// pick a random command
scriptCommand = &scriptItem->commands[ rand() % scriptItem->numCommands ];
#ifdef DBGANIMEVENTS
if ( scriptCommand->bodyPart[0] ) {
Com_Printf( "anim0 (%s): %s", animBodyPartsStr[scriptCommand->bodyPart[0]].string, modelInfo->animations[scriptCommand->animIndex[0]].name );
}
if ( scriptCommand->bodyPart[1] ) {
Com_Printf( "anim1 (%s): %s", animBodyPartsStr[scriptCommand->bodyPart[1]].string, modelInfo->animations[scriptCommand->animIndex[1]].name );
}
Com_Printf( "\n" );
#endif
// run it
return BG_ExecuteCommand( ps, scriptCommand, qtrue, isContinue, force );
}
/*
===============
BG_ValidAnimScript
returns qtrue if the given client has animation scripts
===============
*/
qboolean BG_ValidAnimScript( int clientNum ) {
if ( !globalScriptData->clientModels[clientNum] ) {
return qfalse;
}
//
if ( !globalScriptData->modelInfo[ globalScriptData->clientModels[clientNum] ].numScriptItems ) {
return qfalse;
}
//
return qtrue;
}
/*
===============
BG_GetAnimString
===============
*/
char *BG_GetAnimString( int client, int anim ) {
animModelInfo_t *modelinfo = BG_ModelInfoForClient( client );
//
if ( anim >= modelinfo->numAnimations ) {
BG_AnimParseError( "BG_GetAnimString: anim index is out of range" );
}
//
return modelinfo->animations[anim].name;
}
/*
==============
BG_UpdateConditionValue
==============
*/
void BG_UpdateConditionValue( int client, int condition, int value, qboolean checkConversion ) {
if ( checkConversion ) {
// we may need to convert to bitflags
if ( animConditionsTable[condition].type == ANIM_CONDTYPE_BITFLAGS ) {
// DHM - Nerve :: We want to set the ScriptData to the explicit value passed in.
// COM_BitSet will OR values on top of each other, so clear it first.
globalScriptData->clientConditions[client][condition][0] = 0;
globalScriptData->clientConditions[client][condition][1] = 0;
// dhm - end
COM_BitSet( globalScriptData->clientConditions[client][condition], value );
return;
}
}
globalScriptData->clientConditions[client][condition][0] = value;
}
/*
==============
BG_GetConditionValue
==============
*/
int BG_GetConditionValue( int client, int condition, qboolean checkConversion ) {
int value, i;
// TTimo gcc: assignment makes integer from pointer without a cast
value = (intptr_t)globalScriptData->clientConditions[client][condition];
if ( checkConversion ) {
// we may need to convert to a value
if ( animConditionsTable[condition].type == ANIM_CONDTYPE_BITFLAGS ) {
//if (!value)
// return 0;
for ( i = 0; i < 8 * sizeof( globalScriptData->clientConditions[0][0] ); i++ ) {
if ( COM_BitCheck( globalScriptData->clientConditions[client][condition], i ) ) {
return i;
}
}
// nothing found
return 0;
//BG_AnimParseError( "BG_GetConditionValue: internal error" );
}
}
return value;
}
/*
================
BG_GetAnimScriptAnimation
returns the locomotion animation index, -1 if no animation was found, 0 otherwise
================
*/
int BG_GetAnimScriptAnimation( int client, aistateEnum_t state, scriptAnimMoveTypes_t movetype ) {
animModelInfo_t *modelInfo;
animScript_t *script;
animScriptItem_t *scriptItem = NULL;
animScriptCommand_t *scriptCommand;
modelInfo = BG_ModelInfoForClient( client );
// try finding a match in all states below the given state
while ( !scriptItem && state >= 0 ) {
script = &modelInfo->scriptAnims[ state ][ movetype ];
if ( !script->numItems ) {
state--;
continue;
}
// find the first script item, that passes all the conditions for this event
scriptItem = BG_FirstValidItem( client, script );
if ( !scriptItem ) {
state--;
continue;
}
}
//
if ( !scriptItem ) {
return -1;
}
// pick the correct animation for this character (animations must be constant for each character, otherwise they'll constantly change)
scriptCommand = &scriptItem->commands[ client % scriptItem->numCommands ];
if ( !scriptCommand->bodyPart[0] ) {
return -1;
}
// return the animation
return scriptCommand->animIndex[0];
}
/*
================
BG_GetAnimScriptEvent
returns the animation index for this event
================
*/
int BG_GetAnimScriptEvent( playerState_t *ps, scriptAnimEventTypes_t event ) {
animModelInfo_t *modelInfo;
animScript_t *script;
animScriptItem_t *scriptItem;
animScriptCommand_t *scriptCommand;
if ( event != ANIM_ET_DEATH && ps->eFlags & EF_DEAD ) {
return -1;
}
modelInfo = BG_ModelInfoForClient( ps->clientNum );
script = &modelInfo->scriptEvents[ event ];
if ( !script->numItems ) {
return -1;
}
// find the first script item, that passes all the conditions for this event
scriptItem = BG_FirstValidItem( ps->clientNum, script );
if ( !scriptItem ) {
return -1;
}
// pick a random command
scriptCommand = &scriptItem->commands[ rand() % scriptItem->numCommands ];
// return the animation
return scriptCommand->animIndex[0];
}
/*
===============
BG_GetAnimationForIndex
returns the animation_t for the given index
===============
*/
animation_t *BG_GetAnimationForIndex( int client, int index ) {
animModelInfo_t *modelInfo;
modelInfo = BG_ModelInfoForClient( client );
if ( index < 0 || index >= modelInfo->numAnimations ) {
Com_Error( ERR_DROP, "BG_GetAnimationForIndex: index out of bounds" );
}
return &modelInfo->animations[index];
}
/*
=================
BG_AnimUpdatePlayerStateConditions
=================
*/
void BG_AnimUpdatePlayerStateConditions( pmove_t *pmove ) {
playerState_t *ps = pmove->ps;
// WEAPON
if ( ps->eFlags & EF_ZOOMING ) {
BG_UpdateConditionValue( ps->clientNum, ANIM_COND_WEAPON, WP_BINOCULARS, qtrue );
} else {
BG_UpdateConditionValue( ps->clientNum, ANIM_COND_WEAPON, ps->weapon, qtrue );
}
// MOUNTED
if ( ps->eFlags & EF_MG42_ACTIVE ) {
BG_UpdateConditionValue( ps->clientNum, ANIM_COND_MOUNTED, MOUNTED_MG42, qtrue );
} else {
BG_UpdateConditionValue( ps->clientNum, ANIM_COND_MOUNTED, MOUNTED_UNUSED, qtrue );
}
// UNDERHAND
BG_UpdateConditionValue( ps->clientNum, ANIM_COND_UNDERHAND, ps->viewangles[0] > 0, qtrue );
if ( ps->viewheight == ps->crouchViewHeight ) {
ps->eFlags |= EF_CROUCHING;
} else {
ps->eFlags &= ~EF_CROUCHING;
}
if ( pmove->cmd.buttons & BUTTON_ATTACK ) {
BG_UpdateConditionValue( ps->clientNum, ANIM_COND_FIRING, qtrue, qtrue );
} else {
BG_UpdateConditionValue( ps->clientNum, ANIM_COND_FIRING, qfalse, qtrue );
}
}
|