1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284
|
/*
===========================================================================
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.
===========================================================================
*/
/*
* name: cg_ents.c
*
* desc: present snapshot entities, happens every single frame
*
*/
#include "cg_local.h"
///////////////////////
extern int propellerModel;
///////////////////////
/*
======================
CG_PositionEntityOnTag
Modifies the entities position and axis by the given
tag location
======================
*/
void CG_PositionEntityOnTag( refEntity_t *entity, const refEntity_t *parent,
char *tagName, int startIndex, vec3_t *offset ) {
int i;
orientation_t lerped;
// lerp the tag
trap_R_LerpTag( &lerped, parent, tagName, startIndex );
// FIXME: allow origin offsets along tag? //----(SA) Yes! Adding.
VectorCopy( parent->origin, entity->origin );
if ( offset ) {
VectorAdd( lerped.origin, *offset, lerped.origin );
}
//----(SA) end
for ( i = 0 ; i < 3 ; i++ ) {
VectorMA( entity->origin, lerped.origin[i], parent->axis[i], entity->origin );
}
// had to cast away the const to avoid compiler problems...
MatrixMultiply( lerped.axis, ( (refEntity_t *)parent )->axis, entity->axis );
// Ridah, not sure why this was here.. causes jittery torso animation, since the torso might have
// different frame/oldFrame
//entity->backlerp = parent->backlerp;
}
/*
======================
CG_PositionRotatedEntityOnTag
Modifies the entities position and axis by the given
tag location
======================
*/
void CG_PositionRotatedEntityOnTag( refEntity_t *entity, const refEntity_t *parent,
char *tagName ) {
int i;
orientation_t lerped;
vec3_t tempAxis[3];
//AxisClear( entity->axis );
// lerp the tag
trap_R_LerpTag( &lerped, parent, tagName, 0 );
// FIXME: allow origin offsets along tag?
VectorCopy( parent->origin, entity->origin );
for ( i = 0 ; i < 3 ; i++ ) {
VectorMA( entity->origin, lerped.origin[i], parent->axis[i], entity->origin );
}
// had to cast away the const to avoid compiler problems...
MatrixMultiply( entity->axis, lerped.axis, tempAxis );
MatrixMultiply( tempAxis, ( (refEntity_t *)parent )->axis, entity->axis );
}
//----(SA) added
/*
==============
CG_LoseArmor
maybe better in cg_localents.c
==============
*/
void CG_LoseArmor( centity_t *cent, int index ) {
}
/*
==============
CG_AttachedPartChange
==============
*/
void CG_AttachedPartChange( centity_t *cent ) {
}
//----(SA) end
/*
==========================================================================
FUNCTIONS CALLED EACH FRAME
==========================================================================
*/
/*
======================
CG_SetEntitySoundPosition
Also called by event processing code
======================
*/
void CG_SetEntitySoundPosition( centity_t *cent ) {
if ( cent->currentState.solid == SOLID_BMODEL ) {
vec3_t origin;
float *v;
v = cgs.inlineModelMidpoints[ cent->currentState.modelindex ];
VectorAdd( cent->lerpOrigin, v, origin );
trap_S_UpdateEntityPosition( cent->currentState.number, origin );
} else {
trap_S_UpdateEntityPosition( cent->currentState.number, cent->lerpOrigin );
}
}
#define LS_FRAMETIME 100 // (ms) cycle through lightstyle characters at 10fps
/*
==============
CG_SetDlightIntensity
==============
*/
void CG_AddLightstyle( centity_t *cent ) {
float lightval;
int cl;
int r, g, b;
int stringlength;
float offset;
int otime;
int lastch, nextch;
if ( cent->dl_stylestring[0] == '\0' ) {
return;
}
otime = cg.time - cent->dl_time;
stringlength = strlen( cent->dl_stylestring );
// it's been a long time since you were updated, lets assume a reset
if ( otime > 2 * LS_FRAMETIME ) {
otime = 0;
cent->dl_frame = cent->dl_oldframe = 0;
cent->dl_backlerp = 0;
}
cent->dl_time = cg.time;
offset = ( (float)otime ) / LS_FRAMETIME;
cent->dl_backlerp += offset;
if ( cent->dl_backlerp > 1 ) { // we're moving on to the next frame
cent->dl_oldframe = cent->dl_oldframe + (int)cent->dl_backlerp;
cent->dl_frame = cent->dl_oldframe + 1;
if ( cent->dl_oldframe >= stringlength ) {
cent->dl_oldframe = ( cent->dl_oldframe ) % stringlength;
if ( cent->dl_oldframe < 3 && cent->dl_sound ) { // < 3 so if an alarm comes back into the pvs it will only start a sound if it's going to be closely synced with the light, otherwise wait till the next cycle
trap_S_StartSound( NULL, cent->currentState.number, CHAN_AUTO, cgs.gameSounds[cent->dl_sound] );
}
}
if ( cent->dl_frame >= stringlength ) {
cent->dl_frame = ( cent->dl_frame ) % stringlength;
}
cent->dl_backlerp = cent->dl_backlerp - (int)cent->dl_backlerp;
}
lastch = cent->dl_stylestring[cent->dl_oldframe] - 'a';
nextch = cent->dl_stylestring[cent->dl_frame] - 'a';
lightval = ( lastch * ( 1.0 - cent->dl_backlerp ) ) + ( nextch * cent->dl_backlerp );
lightval = ( lightval * ( 1000.0f / 24.0f ) ) - 200.0f; // they want 'm' as the "middle" value as 300
lightval = max( 0.0f, lightval );
lightval = min( 1000.0f, lightval );
cl = cent->currentState.constantLight;
r = cl & 255;
g = ( cl >> 8 ) & 255;
b = ( cl >> 16 ) & 255;
trap_R_AddLightToScene( cent->lerpOrigin, lightval, (float)r / 255.0f, (float)g / 255.0f, (float)b / 255.0f, 0 ); // overdraw forced to 0 for now
}
void CG_GetWindVector( vec3_t dir ); // JPW NERVE
/*
==================
CG_EntityEffects
Add continuous entity effects, like local entity emission and lighting
==================
*/
static void CG_EntityEffects( centity_t *cent ) {
static vec3_t dir;
// update sound origins
CG_SetEntitySoundPosition( cent );
// add loop sound
if ( cent->currentState.loopSound ) {
//----(SA) hmm, the above (CG_SetEntitySoundPosition()) sets s_entityPosition[entityNum] with a valid
// location, but the looping sound for a bmodel will never get it since that sound is
// started with the lerpOriging right here. \/ \/ How do looping sounds ever work for bmodels?
// Or have they always been broken and we just never used them?
if ( cent->currentState.eType == ET_SPEAKER ) {
/*if(cent->currentState.density == 1) { // NO_PVS
CG_S_AddRealLoopingSound( cent->currentState.number, cent->lerpOrigin, vec3_origin, cgs.gameSounds[ cent->currentState.loopSound ] );
}
else*/if ( cent->currentState.dmgFlags ) { // range is set
CG_S_AddRangedLoopingSound( cent->currentState.number, cent->lerpOrigin, vec3_origin, cgs.gameSounds[ cent->currentState.loopSound ], cent->currentState.dmgFlags );
} else {
CG_S_AddLoopingSound( cent->currentState.number, cent->lerpOrigin, vec3_origin, cgs.gameSounds[ cent->currentState.loopSound ], 255 );
}
} else if ( cent->currentState.solid == SOLID_BMODEL ) {
vec3_t origin;
float *v;
v = cgs.inlineModelMidpoints[ cent->currentState.modelindex ];
VectorAdd( cent->lerpOrigin, v, origin );
CG_S_AddLoopingSound( cent->currentState.number, origin, vec3_origin, cgs.gameSounds[ cent->currentState.loopSound ], 255 );
} else {
CG_S_AddLoopingSound( cent->currentState.number, cent->lerpOrigin, vec3_origin, cgs.gameSounds[ cent->currentState.loopSound ], 255 );
}
} /*else {
// stop NO_PVS speakers if they've been turned off
if(cent->currentState.eType == ET_SPEAKER) {
if(cent->currentState.density == 1) {
trap_S_StopLoopingSound(cent->currentState.number);
}
}
}*/
// constant light glow
if ( cent->currentState.constantLight ) {
int cl;
float i, r, g, b;
if ( cent->dl_stylestring[0] != 0 ) { // it's probably a dlight
CG_AddLightstyle( cent );
} else
{
cl = cent->currentState.constantLight;
r = (float) (cl & 0xFF) / 255.0;
g = (float) ((cl >> 8) & 0xFF) / 255.0;
b = (float) ((cl >> 16) & 0xFF) / 255.0;
i = (float) ((cl >> 24) & 0xFF) * 4.0;
trap_R_AddLightToScene(cent->lerpOrigin, i, r, g, b, 0);
}
}
// Ridah, flaming sounds
if ( CG_EntOnFire( cent ) ) {
// play a flame blow sound when moving
CG_S_AddLoopingSound( cent->currentState.number, cent->lerpOrigin, vec3_origin, cgs.media.flameBlowSound, (int)( 255.0 * ( 1.0 - fabs( cent->fireRiseDir[2] ) ) ) );
// play a burning sound when not moving
CG_S_AddLoopingSound( cent->currentState.number, cent->lerpOrigin, vec3_origin, cgs.media.flameSound, (int)( 0.3 * 255.0 * ( pow( cent->fireRiseDir[2],2 ) ) ) );
}
// DHM - Nerve :: If EF_SMOKING is set, emit smoke
if ( cgs.gametype >= GT_WOLF && cent->currentState.eFlags & EF_SMOKING ) {
float rnd = random();
if ( cent->lastTrailTime < cg.time ) {
cent->lastTrailTime = cg.time + 100;
// JPW NERVE -- use wind vector for smoke
CG_GetWindVector( dir );
VectorScale( dir,20,dir ); // was 75, before that 55
if ( dir[2] < 10 ) {
dir[2] += 10;
}
// dir[0] = crandom() * 10;
// dir[1] = crandom() * 10;
// dir[2] = 10 + rnd * 30;
// jpw
CG_SmokePuff( cent->lerpOrigin, dir, 15 + ( random() * 10 ),
0.3 + rnd, 0.3 + rnd, 0.3 + rnd, 0.4, 1500 + ( rand() % 500 ),
cg.time, cg.time + 500, 0, cgs.media.smokePuffShader );
}
}
// dhm - end
// JPW NERVE same thing but for smoking barrels instead of nasty server-side effect from single player
if ( cgs.gametype >= GT_WOLF && cent->currentState.eFlags & EF_SMOKINGBLACK ) {
float rnd = random();
if ( cent->lastTrailTime < cg.time ) {
cent->lastTrailTime = cg.time + 75;
CG_GetWindVector( dir );
VectorScale( dir,50,dir ); // was 75, before that 55
if ( dir[2] < 50 ) {
dir[2] += 50;
}
CG_SmokePuff( cent->lerpOrigin, dir, 40 + random() * 70, //40+(rnd*40),
rnd * 0.1, rnd * 0.1, rnd * 0.1, 1, 2800 + ( rand() % 4000 ), //2500+(random()*1500),
cg.time, 0, 0, cgs.media.smokePuffShader );
}
}
// jpw
}
/*
==================
CG_General
==================
*/
static void CG_General( centity_t *cent ) {
refEntity_t ent;
entityState_t *s1;
s1 = ¢->currentState;
// if set to invisible, skip
if ( !s1->modelindex ) {
return;
}
memset( &ent, 0, sizeof( ent ) );
// set frame
ent.frame = s1->frame;
ent.oldframe = ent.frame;
ent.backlerp = 0;
if ( ent.frame ) {
ent.oldframe -= 1;
ent.backlerp = 1 - cg.frameInterpolation;
if ( cent->currentState.time ) {
ent.fadeStartTime = cent->currentState.time;
ent.fadeEndTime = cent->currentState.time2;
}
}
VectorCopy( cent->lerpOrigin, ent.origin );
VectorCopy( cent->lerpOrigin, ent.oldorigin );
ent.hModel = cgs.gameModels[s1->modelindex];
// player model
if ( s1->number == cg.snap->ps.clientNum ) {
ent.renderfx |= RF_THIRD_PERSON; // only draw from mirrors
}
if ( cent->currentState.eType == ET_MG42_BARREL ) {
// grab angles from first person user or self if not
// ATVI Wolfenstein Misc #469 - don't track until viewlocked
if ( cent->currentState.otherEntityNum == cg.snap->ps.clientNum && cg.snap->ps.viewlocked ) {
AnglesToAxis( cg.predictedPlayerState.viewangles, ent.axis );
} else {
AnglesToAxis( cent->lerpAngles, ent.axis );
}
} else {
// convert angles to axis
AnglesToAxis( cent->lerpAngles, ent.axis );
}
// scale gamemodels
if ( cent->currentState.eType == ET_GAMEMODEL ) {
VectorScale( ent.axis[0], cent->currentState.angles2[0], ent.axis[0] );
VectorScale( ent.axis[1], cent->currentState.angles2[1], ent.axis[1] );
VectorScale( ent.axis[2], cent->currentState.angles2[2], ent.axis[2] );
ent.nonNormalizedAxes = qtrue;
//----(SA) testing
if ( cent->currentState.apos.trType ) {
ent.reFlags |= REFLAG_ORIENT_LOD;
}
//----(SA) end
}
// add to refresh list
trap_R_AddRefEntityToScene( &ent );
memcpy( ¢->refEnt, &ent, sizeof( refEntity_t ) );
}
/*
==================
CG_Speaker
Speaker entities can automatically play sounds
==================
*/
static void CG_Speaker( centity_t *cent ) {
if ( !cent->currentState.clientNum ) { // FIXME: use something other than clientNum...
return; // not auto triggering
}
if ( cg.time < cent->miscTime ) {
return;
}
trap_S_StartSound( NULL, cent->currentState.number, CHAN_ITEM, cgs.gameSounds[cent->currentState.eventParm] );
// ent->s.frame = ent->wait * 10;
// ent->s.clientNum = ent->random * 10;
cent->miscTime = cg.time + cent->currentState.frame * 100 + cent->currentState.clientNum * 100 * crandom();
}
/*
==============
CG_DrawHoldableSelect
This, of course, will all change when we've got a hud, but for now it makes the holdable items usable and not bad looking
==============
*/
void CG_DrawHoldableSelect( void ) {
/*
int bits;
int count;
int amount;
int i, x, y, w;
float *color;
char *name;
gitem_t *item;
// don't display if dead
if ( cg.predictedPlayerState.stats[STAT_HEALTH] <= 0 ) {
return;
}
color = CG_FadeColor( cg.holdableSelectTime, HOLDABLE_SELECT_TIME );
if ( !color ) {
return;
}
trap_R_SetColor( color );
// showing select clears pickup item display, but not the blend blob
cg.itemPickupTime = 0;
//----(SA) removed
// count the number of holdables owned
bits = cg.snap->ps.stats[ STAT_HOLDABLE_ITEM ];
count = 0;
for ( i = 1 ; i <= HI_BOOK3; i++ ) {
if ( bits & ( 1 << i ) ) {
if ( cg.predictedPlayerState.holdable[i] ) { // don't show ones we're out of
count++;
}
}
}
if ( !count ) {
return;
}
x = 320 - count * 20;
y = 380;
for ( i = 1 ; i <= HI_BOOK3 ; i++ ) {
if ( !( bits & ( 1 << i ) ) ) {
continue;
}
amount = cg.predictedPlayerState.holdable[i];
if ( !amount ) {
continue;
}
item = BG_FindItemForHoldable( i );
if ( !item ) {
continue;
}
CG_RegisterItemVisuals( item - bg_itemlist );
// draw icon
if ( i == HI_WINE ) {
// wine icons have three stages since each bottle has three uses (as opposed to others so far where there's only 1 use)
int wine = amount;
if ( wine > 3 ) {
wine = 3;
}
CG_DrawPic( x, y, 32, 32, cg_items[item - bg_itemlist].icons[ 2 - ( wine - 1 ) ] ) ;
} else {
CG_DrawPic( x, y, 32, 32, cg_items[item - bg_itemlist].icons[0] );
}
// draw remaining uses if there's more than one
if ( amount > 1 ) {
CG_DrawBigStringColor( x, y + 34, va( "%d", amount ), color );
}
// draw selection marker
if ( i == cg.holdableSelect ) {
CG_DrawPic( x - 4, y - 4, 40, 40, cgs.media.selectShader );
}
x += 40;
}
// draw the selected name
if ( cg.holdableSelect ) {
item = BG_FindItemForHoldable( cg.holdableSelect );
if ( item ) {
name = item->pickup_name;
if ( name ) {
//----(SA) trying smaller text
// w = CG_DrawStrlen( name ) * BIGCHAR_WIDTH;
w = CG_DrawStrlen( name ) * 10;
x = ( SCREEN_WIDTH - w ) / 2;
// CG_DrawBigStringColor(x, y - 22, name, color);
CG_DrawStringExt2( x, y + 60, name, color, qfalse, qtrue, 10, 10, 0 );
}
}
}
trap_R_SetColor( NULL );
*/
}
/*
==============
CG_NextItem_f
==============
*/
void CG_NextItem_f( void ) {
/*
int i;
int original, next;
if ( !cg.snap ) {
return;
}
if ( cg.snap->ps.pm_flags & PMF_FOLLOW ) {
return;
}
cg.holdableSelectTime = cg.time;
cg.weaponSelectTime = 0; // (SA) clear weapon selection drawing
next = original = cg.holdableSelect;
for ( i = 0 ; i < HI_NUM_HOLDABLE ; i++ ) {
next++;
if ( next == HI_NUM_HOLDABLE ) {
next = 0;
}
if ( cg.predictedPlayerState.holdable[next] ) { //----(SA)
break;
}
}
if ( i == HI_NUM_HOLDABLE ) {
next = original;
}
cg.holdableSelect = next;
*/
}
/*
==============
CG_PrevItem_f
==============
*/
void CG_PrevItem_f( void ) {
/*
int i;
int original, next;
if ( !cg.snap ) {
return;
}
if ( cg.snap->ps.pm_flags & PMF_FOLLOW ) {
return;
}
cg.weaponSelectTime = 0; // (SA) clear weapon selection drawing
cg.holdableSelectTime = cg.time;
next = original = cg.holdableSelect;
for ( i = 0 ; i < HI_NUM_HOLDABLE ; i++ ) {
next--;
if ( next == -1 ) {
next = HI_NUM_HOLDABLE - 1;
}
if ( cg.predictedPlayerState.holdable[next] ) { //----(SA)
break;
}
}
if ( i == HI_NUM_HOLDABLE ) {
next = original;
}
cg.holdableSelect = next;
*/
}
/*
==============
CG_Item_f
==============
*/
void CG_Item_f( void ) {
//int num;
//num = atoi( CG_Argv( 1 ) );
//cg.holdableSelectTime = cg.time;
//CG_Printf( "Item set to: %d\n", num );
}
//----(SA) added
/*
==============
CG_HoldableUsedupChange
==============
*/
void CG_HoldableUsedupChange( void ) {
int holding;
holding = cg.holdableSelect;
CG_NextItem_f();
if ( cg.holdableSelect == holding ) { // nothing else to go to
cg.holdableSelect = 0;
cg.weaponSelectTime = 0;
return;
}
}
//----(SA) end
qboolean CG_PlayerSeesItem( playerState_t *ps, entityState_t *item, int atTime, int itemType ) {
vec3_t vorigin, eorigin, viewa, dir;
float dot, dist, foo;
trace_t tr;
BG_EvaluateTrajectory( &item->pos, atTime, eorigin );
VectorCopy( ps->origin, vorigin );
vorigin[2] += ps->viewheight; // get the view loc up to the viewheight
// eorigin[2] += 8; // and subtract the item's offset (that is used to place it on the ground)
VectorSubtract( vorigin, eorigin, dir );
dist = VectorNormalize( dir ); // dir is now the direction from the item to the player
if ( dist > 255 ) {
return qfalse; // only run the remaining stuff on items that are close enough
}
// (SA) FIXME: do this without AngleVectors.
// It'd be nice if the angle vectors for the player
// have already been figured at this point and I can
// just pick them up. (if anybody is storing this somewhere,
// for the current frame please let me know so I don't
// have to do redundant calcs)
AngleVectors( ps->viewangles, viewa, 0, 0 );
dot = DotProduct( viewa, dir );
// give more range based on distance (the hit area is wider when closer)
// foo = -0.94f - (dist/255.0f) * 0.057f; // (ranging from -0.94 to -0.997) (it happened to be a pretty good range)
foo = -0.94f - ( dist * ( 1.0f / 255.0f ) ) * 0.057f; // (ranging from -0.94 to -0.997) (it happened to be a pretty good range)
/// Com_Printf("test: if(%f > %f) return qfalse (dot > foo)\n", dot, foo);
if ( dot > foo ) {
return qfalse;
}
// (SA) okay, everything else is okay, so do a bloody trace. (so coronas on treasure doesn't show through walls) <sigh>
if ( itemType == IT_TREASURE ) {
CG_Trace( &tr, vorigin, NULL, NULL, eorigin, -1, MASK_SOLID );
if ( tr.fraction != 1 ) {
return qfalse;
}
}
return qtrue;
}
/*
==================
CG_Item
==================
*/
static void CG_Item( centity_t *cent ) {
refEntity_t ent;
entityState_t *es;
gitem_t *item;
qboolean hasStand, highlight;
float highlightFadeScale = 1.0f;
es = ¢->currentState;
hasStand = qfalse;
highlight = qfalse;
// (item index is stored in es->modelindex for item)
if ( es->modelindex >= bg_numItems ) {
CG_Error( "Bad item index %i on entity", es->modelindex );
}
// if set to invisible, skip
if ( !es->modelindex || ( es->eFlags & EF_NODRAW ) ) {
return;
}
item = &bg_itemlist[ es->modelindex ];
if ( cg_simpleItems.integer && item->giType != IT_TEAM ) {
memset( &ent, 0, sizeof( ent ) );
ent.reType = RT_SPRITE;
VectorCopy( cent->lerpOrigin, ent.origin );
ent.radius = 14;
ent.customShader = cg_items[es->modelindex].icons[0];
ent.shaderRGBA[0] = 255;
ent.shaderRGBA[1] = 255;
ent.shaderRGBA[2] = 255;
ent.shaderRGBA[3] = 255;
trap_R_AddRefEntityToScene( &ent );
return;
}
memset( &ent, 0, sizeof( ent ) );
ent.nonNormalizedAxes = qfalse;
if ( item->giType == IT_WEAPON ) {
weaponInfo_t *weaponInfo = &cg_weapons[item->giTag];
if ( weaponInfo->standModel ) {
hasStand = qtrue;
}
if ( hasStand ) { // first try to put the weapon on it's 'stand'
refEntity_t stand;
memset( &stand, 0, sizeof( stand ) );
stand.hModel = weaponInfo->standModel;
if ( es->eFlags & EF_SPINNING ) {
if ( es->groundEntityNum == -1 || !es->groundEntityNum ) { // (SA) spinning with a stand will spin the stand and the attached weap (only when in the air)
VectorCopy( cg.autoAnglesSlow, cent->lerpAngles );
VectorCopy( cg.autoAnglesSlow, cent->lastLerpAngles );
} else {
VectorCopy( cent->lastLerpAngles, cent->lerpAngles ); // make a tossed weapon sit on the ground in a position that matches how it was yawed
}
}
AnglesToAxis( cent->lerpAngles, stand.axis );
VectorCopy( cent->lerpOrigin, stand.origin );
// scale the stand to match the weapon scale ( the weapon will also be scaled inside CG_PositionEntityOnTag() )
VectorScale( stand.axis[0], 1.5, stand.axis[0] );
VectorScale( stand.axis[1], 1.5, stand.axis[1] );
VectorScale( stand.axis[2], 1.5, stand.axis[2] );
//----(SA) modified
if ( cent->currentState.frame ) {
CG_PositionEntityOnTag( &ent, &stand, va( "tag_stand%d", cent->currentState.frame ), 0, NULL );
} else {
CG_PositionEntityOnTag( &ent, &stand, "tag_stand", 0, NULL );
}
//----(SA) end
VectorCopy( ent.origin, ent.oldorigin );
ent.nonNormalizedAxes = qtrue;
} else { // then default to laying it on it's side
if ( !cg_items[es->modelindex].models[2] ) {
cent->lerpAngles[2] += 90;
}
AnglesToAxis( cent->lerpAngles, ent.axis );
// increase the size of the weapons when they are presented as items
VectorScale( ent.axis[0], 1.5, ent.axis[0] );
VectorScale( ent.axis[1], 1.5, ent.axis[1] );
VectorScale( ent.axis[2], 1.5, ent.axis[2] );
ent.nonNormalizedAxes = qtrue;
VectorCopy( cent->lerpOrigin, ent.origin );
VectorCopy( cent->lerpOrigin, ent.oldorigin );
if ( es->eFlags & EF_SPINNING ) { // spinning will override the angles set by a stand
if ( es->groundEntityNum == -1 || !es->groundEntityNum ) { // (SA) spinning with a stand will spin the stand and the attached weap (only when in the air)
VectorCopy( cg.autoAnglesSlow, cent->lerpAngles );
VectorCopy( cg.autoAnglesSlow, cent->lastLerpAngles );
} else {
VectorCopy( cent->lastLerpAngles, cent->lerpAngles ); // make a tossed weapon sit on the ground in a position that matches how it was yawed
}
}
}
} else {
AnglesToAxis( cent->lerpAngles, ent.axis );
VectorCopy( cent->lerpOrigin, ent.origin );
VectorCopy( cent->lerpOrigin, ent.oldorigin );
if ( es->eFlags & EF_SPINNING ) { // spinning will override the angles set by a stand
VectorCopy( cg.autoAnglesSlow, cent->lerpAngles );
AxisCopy( cg.autoAxisSlow, ent.axis );
}
}
if ( es->modelindex2 ) { // modelindex2 was specified for the ent, meaning it probably has an alternate model (as opposed to the one in the itemlist)
// try to load it first, and if it fails, default to the itemlist model
ent.hModel = cgs.gameModels[ es->modelindex2 ];
} else {
if ( item->giType == IT_WEAPON && cg_items[es->modelindex].models[2] ) { // check if there's a specific model for weapon pickup placement
ent.hModel = cg_items[es->modelindex].models[2];
} else if ( item->giType == IT_HEALTH || item->giType == IT_AMMO || item->giType == IT_POWERUP ) {
if ( es->density < ( 1 << 9 ) ) { // (10 bits of data transmission for density)
ent.hModel = cg_items[es->modelindex].models[es->density]; // multi-state powerups store their state in 'density'
} else {
ent.hModel = cg_items[es->modelindex].models[0];
}
} else {
ent.hModel = cg_items[es->modelindex].models[0];
}
}
//----(SA) find midpoint for highlight corona.
// Can't do it when item is registered since it wouldn't know about replacement model
if ( !( cent->usehighlightOrigin ) ) {
vec3_t mins, maxs, offset;
int i;
trap_R_ModelBounds( ent.hModel, mins, maxs ); // get bounds
for ( i = 0 ; i < 3 ; i++ ) {
offset[i] = mins[i] + 0.5 * ( maxs[i] - mins[i] ); // find object-space center
}
VectorCopy( cent->lerpOrigin, cent->highlightOrigin ); // set 'midpoint' to origin
for ( i = 0 ; i < 3 ; i++ ) { // adjust midpoint by offset and orientation
cent->highlightOrigin[i] += offset[0] * ent.axis[0][i] +
offset[1] * ent.axis[1][i] +
offset[2] * ent.axis[2][i];
}
cent->usehighlightOrigin = qtrue;
}
// items without glow textures need to keep a minimum light value so they are always visible
// if ( ( item->giType == IT_WEAPON ) || ( item->giType == IT_ARMOR ) ) {
ent.renderfx |= RF_MINLIGHT;
// }
// highlighting items the player looks at
if ( cg_drawCrosshairPickups.integer ) {
if ( cg_drawCrosshairPickups.integer == 2 ) { // '2' is 'force highlights'
highlight = qtrue;
}
if ( CG_PlayerSeesItem( &cg.predictedPlayerState, es, cg.time, item->giType ) ) {
highlight = qtrue;
if ( item->giType == IT_TREASURE ) {
trap_R_AddCoronaToScene( cent->highlightOrigin, 1, 0.85, 0.5, 2, cent->currentState.number, qtrue ); //----(SA) add corona to treasure
}
} else {
if ( item->giType == IT_TREASURE ) {
trap_R_AddCoronaToScene( cent->highlightOrigin, 1, 0.85, 0.5, 2, cent->currentState.number, qfalse ); //----(SA) "empty corona" for proper fades
}
}
//----(SA) added fixed item highlight fading
if ( highlight ) {
if ( !cent->highlighted ) {
cent->highlighted = qtrue;
cent->highlightTime = cg.time;
}
ent.hilightIntensity = ( ( cg.time - cent->highlightTime ) / 250.0f ) * highlightFadeScale; // .25 sec to brighten up
} else {
if ( cent->highlighted ) {
cent->highlighted = qfalse;
cent->highlightTime = cg.time;
}
ent.hilightIntensity = 1.0f - ( ( cg.time - cent->highlightTime ) / 1000.0f ) * highlightFadeScale; // 1 sec to dim down (diff in time causes problems if you quickly flip to/away from looking at the item)
}
if ( ent.hilightIntensity < 0.25f ) { // leave a minlight
ent.hilightIntensity = 0.25f;
}
if ( ent.hilightIntensity > 1 ) {
ent.hilightIntensity = 1.0;
}
}
//----(SA) end
// add to refresh list
trap_R_AddRefEntityToScene( &ent );
}
//============================================================================
/*
===============
CG_Smoker
===============
*/
static void CG_Smoker( centity_t *cent ) {
// this ent has some special setting up
// time = speed
// time2 = duration
// angles2[0] = start_size
// angles2[1] = end_size
// angles2[2] = wait
// dl_intensity = health
// constantLight = delay
// origin2 = normal to emit particles along
if ( cg.time - cent->highlightTime > cent->currentState.constantLight ) {
// FIXME: make this framerate independant?
cent->highlightTime = cg.time; // fire a particle this frame
if ( cent->currentState.density == 3 ) { // cannon
CG_ParticleSmoke( cgs.media.smokePuffShaderdirty, cent );
} else if ( !( cent->currentState.density ) ) {
CG_ParticleSmoke( cgs.media.smokePuffShader, cent );
} else {
CG_ParticleSmoke( cgs.media.smokePuffShader, cent );
}
}
cent->lastTrailTime = cg.time; // time we were last received at the client
}
/*
===============
CG_Missile
===============
*/
extern void CG_RocketTrail( centity_t *ent, const weaponInfo_t *wi );
static void CG_Missile( centity_t *cent ) {
refEntity_t ent;
entityState_t *s1;
const weaponInfo_t *weapon;
s1 = ¢->currentState;
if ( s1->weapon >= WP_NUM_WEAPONS ) {
s1->weapon = 0;
}
weapon = &cg_weapons[s1->weapon];
// calculate the axis
VectorCopy( s1->angles, cent->lerpAngles );
// add trails
if ( cent->currentState.eType == ET_FP_PARTS
|| cent->currentState.eType == ET_FIRE_COLUMN
|| cent->currentState.eType == ET_FIRE_COLUMN_SMOKE
|| cent->currentState.eType == ET_RAMJET ) {
CG_RocketTrail( cent, NULL );
} else if ( weapon->missileTrailFunc ) {
weapon->missileTrailFunc( cent, weapon );
}
// add dynamic light
if ( weapon->missileDlight ) {
trap_R_AddLightToScene( cent->lerpOrigin, weapon->missileDlight,
weapon->missileDlightColor[0], weapon->missileDlightColor[1], weapon->missileDlightColor[2], 0 );
}
//----(SA) whoops, didn't mean to check it in with the missile flare
// add missile sound
if ( weapon->missileSound ) {
vec3_t velocity;
BG_EvaluateTrajectoryDelta( ¢->currentState.pos, cg.time, velocity );
CG_S_AddLoopingSound( cent->currentState.number, cent->lerpOrigin, velocity, weapon->missileSound, 255 );
}
// DHM - Nerve :: Don't tick until armed
if ( cgs.gametype >= GT_WOLF && cent->currentState.weapon == WP_DYNAMITE ) {
if ( cent->currentState.teamNum < 4 ) {
vec3_t velocity;
BG_EvaluateTrajectoryDelta( ¢->currentState.pos, cg.time, velocity );
CG_S_AddLoopingSound( cent->currentState.number, cent->lerpOrigin, velocity, weapon->spindownSound, 255 );
}
}
// create the render entity
memset( &ent, 0, sizeof( ent ) );
VectorCopy( cent->lerpOrigin, ent.origin );
VectorCopy( cent->lerpOrigin, ent.oldorigin );
//----(SA) removed plasma gun code as sp5 is taking that spot
// flicker between two skins
ent.skinNum = cg.clientFrame & 1;
if ( cent->currentState.eType == ET_FP_PARTS ) {
ent.hModel = cgs.gameModels[cent->currentState.modelindex];
} else if ( cent->currentState.eType == ET_EXPLO_PART ) {
ent.hModel = cgs.gameModels[cent->currentState.modelindex];
} else if ( cent->currentState.eType == ET_FLAMEBARREL ) {
ent.hModel = cgs.media.flamebarrel;
} else if ( cent->currentState.eType == ET_FIRE_COLUMN || cent->currentState.eType == ET_FIRE_COLUMN_SMOKE ) {
// it may have a model sometime in the future
ent.hModel = 0;
} else if ( cent->currentState.eType == ET_RAMJET ) {
ent.hModel = 0;
}
// ent.hModel = cgs.gameModels[cent->currentState.modelindex];
else {
ent.hModel = weapon->missileModel;
}
ent.renderfx = weapon->missileRenderfx | RF_NOSHADOW;
// convert direction of travel into axis
if ( VectorNormalize2( s1->pos.trDelta, ent.axis[0] ) == 0 ) {
ent.axis[0][2] = 1;
}
// spin as it moves
if ( s1->pos.trType != TR_STATIONARY ) {
RotateAroundDirection( ent.axis, cg.time / 4 );
} else {
RotateAroundDirection( ent.axis, s1->time );
}
// Rafael
// Added this since it may be a propExlosion
if ( ent.hModel ) {
// add to refresh list, possibly with quad glow
CG_AddRefEntityWithPowerups( &ent, s1->powerups, TEAM_FREE, s1, vec3_origin );
}
}
/*
===============
CG_Bat
RF, a bat now is actually a spirit
===============
*/
static void CG_Bat( centity_t *cent ) {
CG_ParticleBat( cent );
CG_S_AddLoopingSound( cent->currentState.number, cent->lerpOrigin, vec3_origin, cgs.media.batsFlyingLoopSound, 5 );
}
static animation_t grabberAnims[6];
static animation_t footlockerAnims[3];
static animation_t multi_flagpoleAnims[9];
typedef struct {
char *name; // for QVM this cannot be char name[MAX_QPATH];
int firstFrame;
int numFrames;
int loopFrames; // 0 to numFrames
int frameLerp; // msec between frames
int initialLerp; // msec to get to first frame
int moveSpeed;
int animBlend; // take this long to blend to next anim
//
// derived
//
int duration;
int nameHash;
int flags;
int movetype;
} animationInline_t;
static void CG_InlineAnimToFullAnim( const animationInline_t *inl, animation_t *anim ) {
Com_Memset( anim, 0, sizeof ( animation_t ) );
anim->firstFrame = inl->firstFrame;
anim->numFrames = inl->numFrames;
anim->loopFrames = inl->loopFrames;
anim->frameLerp = inl->frameLerp;
anim->initialLerp = inl->initialLerp;
}
//----(SA) animation_t struct changed, so changes are to keep this working
static animationInline_t grabberAnimsInline[6] = {
{"", 0, 6, 6, 1000 / 5, 1000 / 5 }, // (main idle)
{"", 5, 21, 21, 1000 / 7, 1000 / 7 }, // (random idle)
{"", 25, 11, 0, 1000 / 15, 1000 / 15 }, // (attack big swipe)
{"", 35, 16, 0, 1000 / 15, 1000 / 15 }, // (attack small swipe)
{"", 50, 16, 0, 1000 / 15, 1000 / 15 }, // (attack grab)
{"", 66, 1, 0, 1000 / 15, 1000 / 15 } // (starting position)
};
//----(SA) added
static animationInline_t footlockerAnimsInline[3] = {
{"", 0, 1, 1, 1000 / 5, 1000 / 5 }, // (main idle)
{"", 0, 5, 5, 1000 / 5, 1000 / 5 }, // (lock rattle)
{"", 5, 6, 0, 1000 / 5, 1000 / 5 } // (break open)
};
//----(SA) end
// DHM - Nerve :: capture and hold flag
static animationInline_t multi_flagpoleAnimsInline[9] = {
{"", 0, 1, 0, 1000 / 15, 1000 / 15 }, // (no flags, idle)
{"", 0, 15, 0, 1000 / 15, 1000 / 15 }, // (axis flag rising)
{"", 490, 15, 0, 1000 / 15, 1000 / 15 }, // (american flag rising)
{"", 20, 211, 211, 1000 / 15, 1000 / 15 }, // (axis flag raised)
{"", 255, 211, 211, 1000 / 15, 1000 / 15 }, // (american flag raised)
{"", 235, 15, 0, 1000 / 15, 1000 / 15 }, // (axis switching to american)
{"", 470, 15, 0, 1000 / 15, 1000 / 15 }, // (american switching to axis)
{"", 510, 15, 0, 1000 / 15, 1000 / 15 }, // (axis flag falling)
{"", 530, 15, 0, 1000 / 15, 1000 / 15 } // (american flag falling)
};
// dhm - end
/*
===============
CG_InitTrapAnimations
===============
*/
void CG_InitTrapAnimations( void ) {
int i;
for ( i = 0; i < ARRAY_LEN(grabberAnims); i++ ) {
CG_InlineAnimToFullAnim( &grabberAnimsInline[i], &grabberAnims[i] );
}
for ( i = 0; i < ARRAY_LEN(footlockerAnims); i++ ) {
CG_InlineAnimToFullAnim( &footlockerAnimsInline[i], &footlockerAnims[i] );
}
for ( i = 0; i < ARRAY_LEN(multi_flagpoleAnims); i++ ) {
CG_InlineAnimToFullAnim( &multi_flagpoleAnimsInline[i], &multi_flagpoleAnims[i] );
}
}
extern void CG_RunLerpFrame( clientInfo_t *ci, lerpFrame_t *lf, int newAnimation, float speedScale );
/*
==============
CG_TrapSetAnim
==============
*/
static void CG_TrapSetAnim( centity_t *cent, lerpFrame_t *lf, int newAnim ) {
// transition animation
lf->animationNumber = cent->currentState.frame;
if ( 0 ) {
lf->animation = &grabberAnims[cent->currentState.frame];
} else {
lf->animation = &footlockerAnims[cent->currentState.frame];
}
// DHM - Nerve :: teamNum specifies which set of animations to use (only 1 exists right now)
if ( cgs.gametype >= GT_WOLF ) {
switch ( cent->currentState.teamNum ) {
case 1:
lf->animation = &multi_flagpoleAnims[ cent->currentState.frame ];
break;
default:
// Keep what was set above
break;
}
}
// dhm - end
lf->animationTime = lf->frameTime + lf->animation->initialLerp;
}
/*
==============
CG_Trap
// TODO: change from 'trap' to something else. 'trap' is a misnomer. it's actually used for other stuff too
==============
*/
static void CG_Trap( centity_t *cent ) {
refEntity_t ent;
entityState_t *cs;
lerpFrame_t *traplf;
memset( &ent, 0, sizeof( ent ) );
cs = ¢->currentState;
traplf = ¢->lerpFrame;
// initial setup
if ( !traplf->oldFrameTime ) {
traplf->frameTime =
traplf->oldFrameTime = cg.time;
CG_TrapSetAnim( cent, traplf, cs->frame );
traplf->frame =
traplf->oldFrame = traplf->animation->firstFrame;
}
// transition to new anim if requested
if ( ( traplf->animationNumber != cs->frame ) || !traplf->animation ) {
CG_TrapSetAnim( cent, traplf, cs->frame );
}
CG_RunLerpFrame( NULL, traplf, 0, 1 ); // use existing lerp code rather than re-writing
ent.frame = traplf->frame;
ent.oldframe = traplf->oldFrame;
ent.backlerp = traplf->backlerp;
VectorCopy( cent->lerpOrigin, ent.origin );
VectorCopy( cent->lerpOrigin, ent.oldorigin );
ent.hModel = cgs.gameModels[cs->modelindex];
AnglesToAxis( cent->lerpAngles, ent.axis );
trap_R_AddRefEntityToScene( &ent );
memcpy( ¢->refEnt, &ent, sizeof( refEntity_t ) );
}
//----(SA) end
/*
==============
CG_Corona
==============
*/
static void CG_Corona( centity_t *cent ) {
trace_t tr;
int r, g, b;
int dli;
qboolean visible = qfalse,
behind = qfalse,
toofar = qfalse;
float dot, dist;
vec3_t dir;
if ( cg_coronas.integer == 0 ) { // if set to '0' no coronas
return;
}
dli = cent->currentState.dl_intensity;
r = dli & 255;
g = ( dli >> 8 ) & 255;
b = ( dli >> 16 ) & 255;
// only coronas that are in your PVS are being added
VectorSubtract( cg.refdef.vieworg, cent->lerpOrigin, dir );
dist = VectorNormalize2( dir, dir );
if ( dist > cg_coronafardist.integer ) { // performance variable cg_coronafardist will keep down super long traces
toofar = qtrue;
}
dot = DotProduct( dir, cg.refdef.viewaxis[0] );
if ( dot >= -0.6 ) { // assumes ~90 deg fov (SA) changed value to 0.6 (screen corner at 90 fov)
behind = qtrue; // use the dot to at least do trivial removal of those behind you.
}
// yeah, I could calc side planes to clip against, but would that be worth it? (much better than dumb dot>= thing?)
// CG_Printf("dot: %f\n", dot);
if ( cg_coronas.integer == 2 ) { // if set to '2' trace everything
behind = qfalse;
toofar = qfalse;
}
if ( !behind && !toofar ) {
CG_Trace( &tr, cg.refdef.vieworg, NULL, NULL, cent->lerpOrigin, -1, MASK_SOLID | CONTENTS_BODY ); // added blockage by players. not sure how this is going to be since this is their bb, not their model (too much blockage)
if ( tr.fraction == 1 ) {
visible = qtrue;
}
trap_R_AddCoronaToScene( cent->lerpOrigin, (float)r / 255.0f, (float)g / 255.0f, (float)b / 255.0f, (float)cent->currentState.density / 255.0f, cent->currentState.number, visible );
}
}
/*
==============
CG_Efx
==============
*/
static void CG_Efx( centity_t *cent ) {
int i;
float rnd;
trace_t trace;
vec3_t perpvec;
vec3_t stickPoint;
float movePerUpdate;
if ( cent->currentState.eType == ET_EF_TESLA ) {
rnd = cent->currentState.angles2[0];
for ( i = 0; i < MAX_TESLA_BOLTS; i++ ) {
if ( cent->boltTimes[i] < cg.time ) {
VectorSet( cent->boltLocs[i], crandom(), crandom(), crandom() );
VectorNormalize2( cent->boltLocs[i], cent->boltLocs[i] );
VectorMA( cent->currentState.origin2, rnd, cent->boltLocs[i], cent->boltLocs[i] );
cent->boltTimes[i] = cg.time + rand() % cent->currentState.time2; // hold this position for ~1 second ('stickytime' value is stored in .time2)
// cut the bolt short if it collides w/ something
CG_Trace( &trace, cent->currentState.origin, NULL, NULL, cent->boltLocs[i], -1, MASK_SOLID | CONTENTS_BODY );
if ( trace.fraction < 1 ) {
// take damage
if ( trace.entityNum != ENTITYNUM_WORLD ) {
// CG_ClientDamage(trace.entityNum, cent->currentState.number, CLDMG_TESLA);
// cg_entities[trace.entityNum].pe.teslaDamagedTime = cg.time;
}
VectorCopy( trace.endpos, cent->boltLocs[i] );
// store perpendicular vector so end can 'crawl'
PerpendicularVector( perpvec, trace.plane.normal );
RotatePointAroundVector( stickPoint, trace.plane.normal, perpvec, crandom() * 360 );
// scale it so it won't move too far with bolts that have long boltTimer's
movePerUpdate = 1.0f / (float)( cent->boltTimes[i] - cg.time );
// move a max of 64 away from the 'original' target location
VectorScale( stickPoint, movePerUpdate * trace.fraction * 64.0f, cent->boltCrawlDirs[i] );
} else {
VectorSet( cent->boltCrawlDirs[i], 0, 0, 0 );
}
}
}
for ( i = 0; i < MAX_TESLA_BOLTS; i++ ) {
if ( cent->boltCrawlDirs[0] ) {
VectorMA( cent->boltLocs[i], cent->boltTimes[i] - cg.time, cent->boltCrawlDirs[i], perpvec );
} else {
VectorCopy( cent->boltLocs[i], perpvec );
}
CG_DynamicLightningBolt( cgs.media.lightningBoltShader, // shader
cent->currentState.origin, // start
perpvec, // end
cent->currentState.density, // numBolts
cent->currentState.frame, // maxWidth
qtrue, // fade
1.0, // startAlpha
0, // recursion
i * i * 2 ); // randseed
}
// add dlight
if ( cent->currentState.dl_intensity ) {
int r, g, b;
int dli;
int randomness = cent->currentState.time2;
if ( ( cg.time / 50 ) % ( randomness + ( cg.time % randomness ) ) == 0 ) {
dli = cent->currentState.dl_intensity;
r = dli & 255;
g = ( dli >> 8 ) & 255;
b = ( dli >> 16 ) & 255;
trap_R_AddLightToScene( cent->currentState.origin, cent->currentState.time, (float)r / 255.0f, (float)g / 255.0f, (float)b / 255.0f, 0 );
}
}
} else if ( cent->currentState.eType == ET_EF_SPOTLIGHT ) {
vec3_t targetpos, normalized_direction, direction;
float dist, fov = 90;
vec4_t color = {1, 1, 1, .1};
int splinetarget = 0;
char *cs;
VectorCopy( cent->currentState.origin2, targetpos );
splinetarget = cent->overheatTime;
if ( !splinetarget ) {
cs = (char *)CG_ConfigString( CS_SPLINES + cent->currentState.density );
cent->overheatTime = splinetarget = CG_LoadCamera( va( "cameras/%s.camera", cs ) );
if ( splinetarget != -1 ) {
trap_startCamera( splinetarget, cg.time );
}
} else {
vec3_t angles;
if ( splinetarget != -1 ) {
if ( trap_getCameraInfo( splinetarget, cg.time, &targetpos, &angles, &fov ) ) {
} else { // loop
trap_startCamera( splinetarget, cg.time );
trap_getCameraInfo( splinetarget, cg.time, &targetpos, &angles, &fov );
}
}
}
normalized_direction[0] = direction[0] = targetpos[0] - cent->currentState.origin[0];
normalized_direction[1] = direction[1] = targetpos[1] - cent->currentState.origin[1];
normalized_direction[2] = direction[2] = targetpos[2] - cent->currentState.origin[2];
dist = VectorNormalize( normalized_direction );
if ( dist == 0 ) {
return;
}
CG_Spotlight( cent, color, cent->currentState.origin, normalized_direction, 999, 2048, 10, fov, 0 );
}
}
//----(SA) adding func_explosive
/*
===============
CG_Explosive
This is currently almost exactly the same as CG_Mover
It's split out so that any changes or experiments are
unattached to anything else.
===============
*/
static void CG_Explosive( centity_t *cent ) {
refEntity_t ent;
entityState_t *s1;
s1 = ¢->currentState;
// create the render entity
memset( &ent, 0, sizeof( ent ) );
// VectorCopy( cent->lerpOrigin, ent.origin);
VectorCopy( cent->lerpOrigin, ent.oldorigin );
// VectorCopy( ent.origin, cent->lerpOrigin);
AnglesToAxis( cent->lerpAngles, ent.axis );
ent.renderfx = RF_NOSHADOW;
// get the model, either as a bmodel or a modelindex
if ( s1->solid == SOLID_BMODEL ) {
ent.hModel = cgs.inlineDrawModel[s1->modelindex];
} else {
ent.hModel = cgs.gameModels[s1->modelindex];
}
// add to refresh list
// trap_R_AddRefEntityToScene(&ent);
// add the secondary model
if ( s1->modelindex2 ) {
ent.skinNum = 0;
ent.hModel = cgs.gameModels[s1->modelindex2];
trap_R_AddRefEntityToScene( &ent );
} else {
trap_R_AddRefEntityToScene( &ent );
}
}
//----(SA) done
// declaration for add bullet particles (might as well stick this one in a .h file I think)
extern void CG_AddBulletParticles( vec3_t origin, vec3_t dir, int speed, int duration, int count, float randScale );
/*
===============
CG_Mover
===============
*/
static void CG_Mover( centity_t *cent ) {
refEntity_t ent;
entityState_t *s1;
s1 = ¢->currentState;
// create the render entity
memset( &ent, 0, sizeof( ent ) );
VectorCopy( cent->lerpOrigin, ent.origin );
VectorCopy( cent->lerpOrigin, ent.oldorigin );
AnglesToAxis( cent->lerpAngles, ent.axis );
ent.renderfx = RF_NOSHADOW;
// flicker between two skins (FIXME?)
ent.skinNum = 0;
// get the model, either as a bmodel or a modelindex
if ( s1->solid == SOLID_BMODEL ) {
ent.hModel = cgs.inlineDrawModel[s1->modelindex];
} else {
ent.hModel = cgs.gameModels[s1->modelindex];
}
// Rafael
// testing for mike to get movers to scale
if ( cent->currentState.density == ET_MOVERSCALED ) {
VectorScale( ent.axis[0], cent->currentState.angles2[0], ent.axis[0] );
VectorScale( ent.axis[1], cent->currentState.angles2[1], ent.axis[1] );
VectorScale( ent.axis[2], cent->currentState.angles2[2], ent.axis[2] );
ent.nonNormalizedAxes = qtrue;
}
//----(SA) added
if ( cent->currentState.eType == ET_ALARMBOX ) {
ent.renderfx |= RF_MINLIGHT;
}
//----(SA) end
// add the secondary model
if ( s1->modelindex2 ) {
ent.skinNum = 0;
ent.hModel = cgs.gameModels[s1->modelindex2];
ent.frame = s1->frame;
trap_R_AddRefEntityToScene( &ent );
memcpy( ¢->refEnt, &ent, sizeof( refEntity_t ) );
} else {
trap_R_AddRefEntityToScene( &ent );
}
// add propeller and sfx to me109
if ( cent->currentState.density == 7 || cent->currentState.density == 8 ) {
refEntity_t propeller;
vec3_t angles;
memset( &propeller, 0, sizeof( propeller ) );
VectorCopy( ent.lightingOrigin, propeller.lightingOrigin );
propeller.shadowPlane = ent.shadowPlane;
propeller.renderfx = ent.renderfx;
propeller.hModel = propellerModel;
angles[PITCH] = cg.time % 16;
AnglesToAxis( angles, propeller.axis );
CG_PositionRotatedEntityOnTag( &propeller, &ent, "tag_prop" );
trap_R_AddRefEntityToScene( &propeller );
if ( cent->currentState.density == 8 ) {
refEntity_t flash;
vec3_t angles;
angles[YAW] = 90;
angles[ROLL] = random() * 90;
memset( &flash, 0, sizeof( flash ) );
flash.renderfx = ent.shadowPlane;
//flash.hModel = cgs.media.mg42muzzleflash;
flash.hModel = cgs.media.planemuzzleflash;
AnglesToAxis( angles, flash.axis );
CG_PositionRotatedEntityOnTag( &flash, &ent, "tag_gun1" );
trap_R_AddRefEntityToScene( &flash );
trap_R_AddLightToScene( flash.origin, 200 + ( rand() & 31 ),1.0, 0.6, 0.23, 0 );
memset( &flash, 0, sizeof( flash ) );
flash.renderfx = ent.shadowPlane;
//flash.hModel = cgs.media.mg42muzzleflash;
flash.hModel = cgs.media.planemuzzleflash;
AnglesToAxis( angles, flash.axis );
CG_PositionRotatedEntityOnTag( &flash, &ent, "tag_gun02" );
trap_R_AddRefEntityToScene( &flash );
trap_R_AddLightToScene( flash.origin, 200 + ( rand() & 31 ),1.0, 0.6, 0.23, 0 );
}
}
// alarm box spark effects
if ( cent->currentState.eType == ET_ALARMBOX ) {
if ( cent->currentState.frame == 2 ) { // i'm dead
if ( rand() % 50 == 1 ) {
vec3_t angNorm; // normalized angles
VectorNormalize2( cent->lerpAngles, angNorm );
// (origin, dir, speed, duration, count, 'randscale')
CG_AddBulletParticles( cent->lerpOrigin, angNorm, 2, 800, 4, 16.0f );
trap_S_StartSound( NULL, cent->currentState.number, CHAN_AUTO, cgs.media.sparkSounds[0] );
}
}
}
}
/*
===============
CG_Beam
Also called as an event
===============
*/
void CG_Beam( centity_t *cent ) {
refEntity_t ent;
entityState_t *s1;
s1 = ¢->currentState;
// create the render entity
memset( &ent, 0, sizeof( ent ) );
VectorCopy( s1->pos.trBase, ent.origin );
VectorCopy( s1->origin2, ent.oldorigin );
AxisClear( ent.axis );
ent.reType = RT_BEAM;
ent.renderfx = RF_NOSHADOW;
// add to refresh list
trap_R_AddRefEntityToScene( &ent );
}
/*
===============
CG_Portal
===============
*/
static void CG_Portal( centity_t *cent ) {
refEntity_t ent;
entityState_t *s1;
s1 = ¢->currentState;
// create the render entity
memset( &ent, 0, sizeof( ent ) );
VectorCopy( cent->lerpOrigin, ent.origin );
VectorCopy( s1->origin2, ent.oldorigin );
ByteToDir( s1->eventParm, ent.axis[0] );
PerpendicularVector( ent.axis[1], ent.axis[0] );
// negating this tends to get the directions like they want
// we really should have a camera roll value
VectorSubtract( vec3_origin, ent.axis[1], ent.axis[1] );
CrossProduct( ent.axis[0], ent.axis[1], ent.axis[2] );
ent.reType = RT_PORTALSURFACE;
ent.frame = s1->frame; // rotation speed
ent.skinNum = s1->clientNum / 256.0 * 360; // roll offset
// add to refresh list
trap_R_AddRefEntityToScene( &ent );
}
/*
===============
CG_Prop
===============
*/
static void CG_Prop( centity_t *cent ) {
refEntity_t ent;
entityState_t *s1;
vec3_t angles;
float scale;
s1 = ¢->currentState;
// create the render entity
memset( &ent, 0, sizeof( ent ) );
if ( cg.renderingThirdPerson ) {
VectorCopy( cent->lerpOrigin, ent.origin );
VectorCopy( cent->lerpOrigin, ent.oldorigin );
ent.frame = s1->frame;
ent.oldframe = ent.frame;
ent.backlerp = 0;
} else
{
VectorCopy( cg.refdef.vieworg, ent.origin );
VectorCopy( cg.refdefViewAngles, angles );
if ( cg.bobcycle & 1 ) {
scale = -cg.xyspeed;
} else {
scale = cg.xyspeed;
}
// modify angles from bobbing
angles[ROLL] += scale * cg.bobfracsin * 0.005;
angles[YAW] += scale * cg.bobfracsin * 0.01;
angles[PITCH] += cg.xyspeed * cg.bobfracsin * 0.005;
VectorCopy( angles, cent->lerpAngles );
ent.frame = s1->frame;
ent.oldframe = ent.frame;
ent.backlerp = 0;
if ( cent->currentState.density ) {
ent.frame = s1->frame + cent->currentState.density;
ent.oldframe = ent.frame - 1;
ent.backlerp = 1 - cg.frameInterpolation;
ent.renderfx = RF_DEPTHHACK | RF_FIRST_PERSON;
//CG_Printf ("frame %d oldframe %d\n", ent.frame, ent.oldframe);
} else if ( ent.frame ) {
ent.oldframe -= 1;
ent.backlerp = 1 - cg.frameInterpolation;
} else
{
ent.renderfx = RF_DEPTHHACK | RF_FIRST_PERSON;
}
}
AnglesToAxis( cent->lerpAngles, ent.axis );
ent.renderfx |= RF_NOSHADOW;
// flicker between two skins (FIXME?)
ent.skinNum = ( cg.time >> 6 ) & 1;
// get the model, either as a bmodel or a modelindex
if ( s1->solid == SOLID_BMODEL ) {
ent.hModel = cgs.inlineDrawModel[s1->modelindex];
} else {
ent.hModel = cgs.gameModels[s1->modelindex];
}
// add the secondary model
if ( s1->modelindex2 ) {
ent.skinNum = 0;
ent.hModel = cgs.gameModels[s1->modelindex2];
ent.frame = s1->frame;
trap_R_AddRefEntityToScene( &ent );
memcpy( ¢->refEnt, &ent, sizeof( refEntity_t ) );
} else {
trap_R_AddRefEntityToScene( &ent );
}
}
/*
================
CG_CreateRotationMatrix
================
*/
void CG_CreateRotationMatrix(vec3_t angles, vec3_t matrix[3]) {
AngleVectors(angles, matrix[0], matrix[1], matrix[2]);
VectorInverse(matrix[1]);
}
/*
================
CG_TransposeMatrix
================
*/
void CG_TransposeMatrix(vec3_t matrix[3], vec3_t transpose[3]) {
int i, j;
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
transpose[i][j] = matrix[j][i];
}
}
}
/*
================
CG_RotatePoint
================
*/
void CG_RotatePoint(vec3_t point, vec3_t matrix[3]) {
vec3_t tvec;
VectorCopy(point, tvec);
point[0] = DotProduct(matrix[0], tvec);
point[1] = DotProduct(matrix[1], tvec);
point[2] = DotProduct(matrix[2], tvec);
}
/*
=========================
CG_AdjustPositionForMover
Also called by client movement prediction code
=========================
*/
void CG_AdjustPositionForMover(const vec3_t in, int moverNum, int fromTime, int toTime, vec3_t out, vec3_t angles_in, vec3_t angles_out) {
centity_t *cent;
vec3_t oldOrigin, origin, deltaOrigin;
vec3_t oldAngles, angles, deltaAngles;
vec3_t matrix[3], transpose[3];
vec3_t org, org2, move2;
// if ( outDeltaAngles ) {
// VectorClear( outDeltaAngles );
// }
if ( moverNum <= 0 || moverNum >= ENTITYNUM_MAX_NORMAL ) {
VectorCopy( in, out );
VectorCopy(angles_in, angles_out);
return;
}
cent = &cg_entities[ moverNum ];
if ( cent->currentState.eType != ET_MOVER ) {
VectorCopy( in, out );
VectorCopy(angles_in, angles_out);
return;
}
BG_EvaluateTrajectory( ¢->currentState.pos, fromTime, oldOrigin );
BG_EvaluateTrajectory( ¢->currentState.apos, fromTime, oldAngles );
BG_EvaluateTrajectory( ¢->currentState.pos, toTime, origin );
BG_EvaluateTrajectory( ¢->currentState.apos, toTime, angles );
VectorSubtract( origin, oldOrigin, deltaOrigin );
VectorSubtract( angles, oldAngles, deltaAngles );
// origin change when on a rotating object
CG_CreateRotationMatrix( deltaAngles, transpose );
CG_TransposeMatrix( transpose, matrix );
VectorSubtract( in, oldOrigin, org );
VectorCopy( org, org2 );
CG_RotatePoint( org2, matrix );
VectorSubtract( org2, org, move2 );
VectorAdd( deltaOrigin, move2, deltaOrigin );
VectorAdd( in, deltaOrigin, out );
// if ( outDeltaAngles ) {
// VectorCopy( deltaAngles, outDeltaAngles );
// }
VectorAdd( angles_in, deltaAngles, angles_out );
}
/*
=============================
CG_InterpolateEntityPosition
=============================
*/
static void CG_InterpolateEntityPosition( centity_t *cent ) {
vec3_t current, next;
float f;
// it would be an internal error to find an entity that interpolates without
// a snapshot ahead of the current one
if ( cg.nextSnap == NULL ) {
// DHM - Nerve :: FIXME? There are some cases when in Limbo mode during a map restart
// that were tripping this error.
//CG_Error( "CG_InterpolateEntityPosition: cg.nextSnap == NULL" );
//CG_Printf("CG_InterpolateEntityPosition: cg.nextSnap == NULL");
return;
}
f = cg.frameInterpolation;
// this will linearize a sine or parabolic curve, but it is important
// to not extrapolate player positions if more recent data is available
BG_EvaluateTrajectory( ¢->currentState.pos, cg.snap->serverTime, current );
BG_EvaluateTrajectory( ¢->nextState.pos, cg.nextSnap->serverTime, next );
cent->lerpOrigin[0] = current[0] + f * ( next[0] - current[0] );
cent->lerpOrigin[1] = current[1] + f * ( next[1] - current[1] );
cent->lerpOrigin[2] = current[2] + f * ( next[2] - current[2] );
BG_EvaluateTrajectory( ¢->currentState.apos, cg.snap->serverTime, current );
BG_EvaluateTrajectory( ¢->nextState.apos, cg.nextSnap->serverTime, next );
cent->lerpAngles[0] = LerpAngle( current[0], next[0], f );
cent->lerpAngles[1] = LerpAngle( current[1], next[1], f );
cent->lerpAngles[2] = LerpAngle( current[2], next[2], f );
}
/*
===============
CG_CalcEntityLerpPositions
===============
*/
static void CG_CalcEntityLerpPositions( centity_t *cent ) {
if ( cent->interpolate && cent->currentState.pos.trType == TR_INTERPOLATE ) {
CG_InterpolateEntityPosition( cent );
return;
}
// NERVE - SMF - fix for jittery clients in multiplayer
if ( cgs.gametype != GT_SINGLE_PLAYER ) {
// first see if we can interpolate between two snaps for
// linear extrapolated clients
if ( cent->interpolate && cent->currentState.pos.trType == TR_LINEAR_STOP &&
cent->currentState.number < MAX_CLIENTS ) {
CG_InterpolateEntityPosition( cent );
return;
}
}
// -NERVE - SMF
// just use the current frame and evaluate as best we can
BG_EvaluateTrajectory( ¢->currentState.pos, cg.time, cent->lerpOrigin );
BG_EvaluateTrajectory( ¢->currentState.apos, cg.time, cent->lerpAngles );
// adjust for riding a mover if it wasn't rolled into the predicted
// player state
if ( cent != &cg.predictedPlayerEntity ) {
CG_AdjustPositionForMover( cent->lerpOrigin, cent->currentState.groundEntityNum,
cg.snap->serverTime, cg.time, cent->lerpOrigin, cent->lerpAngles, cent->lerpAngles);
}
}
/*
===============
CG_ProcessEntity
===============
*/
static void CG_ProcessEntity( centity_t *cent ) {
switch ( cent->currentState.eType ) {
default:
CG_Error( "Bad entity type: %i", cent->currentState.eType );
break;
case ET_CONCUSSIVE_TRIGGER:
case ET_CAMERA:
case ET_INVISIBLE:
case ET_PUSH_TRIGGER:
case ET_TELEPORT_TRIGGER:
case ET_OID_TRIGGER:
case ET_AI_EFFECT:
case ET_EXPLOSIVE_INDICATOR: // NERVE - SMF
break;
case ET_SPEAKER:
CG_Speaker( cent );
break;
case ET_GAMEMODEL:
if ( !cg_drawGamemodels.integer ) {
break;
}
case ET_MG42_BARREL:
case ET_FOOTLOCKER:
case ET_GENERAL:
CG_General( cent );
break;
case ET_CORPSE:
case ET_PLAYER:
CG_Player( cent );
break;
case ET_ITEM:
CG_Item( cent );
break;
case ET_MISSILE:
case ET_FLAMEBARREL:
case ET_FP_PARTS:
case ET_FIRE_COLUMN:
case ET_FIRE_COLUMN_SMOKE:
case ET_EXPLO_PART:
case ET_RAMJET:
CG_Missile( cent );
break;
case ET_EF_TESLA:
case ET_EF_SPOTLIGHT:
case ET_EFFECT3:
CG_Efx( cent );
break;
case ET_EXPLOSIVE:
CG_Explosive( cent );
break;
case ET_TRAP:
CG_Trap( cent );
break;
case ET_ALARMBOX:
case ET_MOVER:
CG_Mover( cent );
break;
case ET_PROP:
CG_Prop( cent );
break;
case ET_BEAM:
CG_Beam( cent );
break;
case ET_PORTAL:
CG_Portal( cent );
break;
case ET_CORONA:
CG_Corona( cent );
break;
case ET_BAT:
CG_Bat( cent );
break;
case ET_SMOKER:
CG_Smoker( cent );
break;
}
}
/*
===============
CG_AddCEntity
===============
*/
static void CG_AddCEntity( centity_t *cent ) {
// event-only entities will have been dealt with already
if ( cent->currentState.eType >= ET_EVENTS ) {
return;
}
cent->processedFrame = cg.clientFrame;
// calculate the current origin
CG_CalcEntityLerpPositions( cent );
// add automatic effects
CG_EntityEffects( cent );
// call the appropriate function which will add this entity to the view accordingly
CG_ProcessEntity( cent );
}
/*
==================
CG_AddEntityToTag
==================
*/
static void CG_AddEntityToTag( centity_t *cent ) {
entityState_t *s1;
centity_t *centParent;
entityState_t *sParent;
refEntity_t ent;
char *cs, *token = NULL;
int i, pi;
vec3_t ang;
memset( &ent, 0, sizeof( ent ) );
// event-only entities will have been dealt with already
if ( cent->currentState.eType >= ET_EVENTS ) {
return;
}
if ( cent->processedFrame == cg.clientFrame ) {
// already processed this frame
return;
}
// calculate the current origin
CG_CalcEntityLerpPositions( cent );
s1 = ¢->currentState;
// find us in the list of tagged entities
sParent = NULL;
centParent = NULL;
for ( i = CS_TAGCONNECTS + 1; i < CS_TAGCONNECTS + MAX_TAGCONNECTS; i++ ) { // NOTE: +1 since G_FindConfigStringIndex() starts at index 1 rather than 0 (not sure why)
cs = (char *)CG_ConfigString( i );
token = COM_Parse( &cs );
if ( !token[0] ) {
break;
}
if ( atoi( token ) == s1->number ) {
token = COM_Parse( &cs );
if ( !token[0] ) {
CG_Error( "CG_EntityTagConnected: missing parameter in configstring" );
}
pi = atoi( token );
if ( pi < 0 || pi >= MAX_GENTITIES ) {
CG_Error( "CG_EntityTagConnected: parent out of range" );
}
centParent = &cg_entities[pi];
sParent = &( cg_entities[pi].currentState );
token = COM_Parse( &cs );
if ( !token[0] ) {
CG_Error( "CG_EntityTagConnected: missing parameter in configstring" );
}
// NOTE: token is now the tag name to attach to
break;
}
}
if ( !sParent ) {
CG_Error( "CG_EntityTagConnected: unable to find configstring to perform connection" );
}
// if parent isn't visible, then don't draw us
if ( !centParent->currentValid ) {
return;
}
// make sure all parents are added first
if ( centParent->processedFrame != cg.clientFrame ) {
if ( sParent->eFlags & EF_TAGCONNECT ) {
CG_AddEntityToTag( centParent );
}
}
// if there was a higher ranking parent not added to the scene, then don't add us
if ( centParent->processedFrame != cg.clientFrame ) {
return;
}
cent->processedFrame = cg.clientFrame;
// start with default axis
AnglesToAxis( vec3_origin, ent.axis );
// get the tag position from parent
CG_PositionEntityOnTag( &ent, ¢Parent->refEnt, token, 0, NULL );
VectorCopy( ent.origin, cent->lerpOrigin );
// we need to add the child's angles to the tag angles
if ( !cent->currentState.density ) { // this entity should rotate with it's parent, but can turn around using it's own angles
AxisToAngles( ent.axis, ang );
VectorAdd( cent->lerpAngles, ang, cent->lerpAngles );
} else { // face our angles exactly
BG_EvaluateTrajectory( ¢->currentState.apos, cg.time, cent->lerpAngles );
}
// add automatic effects
CG_EntityEffects( cent );
// call the appropriate function which will add this entity to the view accordingly
CG_ProcessEntity( cent );
}
/*
===============
CG_AddPacketEntities
===============
*/
void CG_AddPacketEntities( void ) {
int num;
centity_t *cent;
playerState_t *ps;
//int clcount;
// set cg.frameInterpolation
if ( cg.nextSnap ) {
int delta;
delta = ( cg.nextSnap->serverTime - cg.snap->serverTime );
if ( delta == 0 ) {
cg.frameInterpolation = 0;
} else {
cg.frameInterpolation = (float)( cg.time - cg.snap->serverTime ) / delta;
}
} else {
cg.frameInterpolation = 0; // actually, it should never be used, because
// no entities should be marked as interpolating
}
// the auto-rotating items will all have the same axis
cg.autoAnglesSlow[0] = 0;
cg.autoAnglesSlow[1] = ( cg.time & 4095 ) * 360 / 4095.0;
cg.autoAnglesSlow[2] = 0;
cg.autoAngles[0] = 0;
cg.autoAngles[1] = ( cg.time & 2047 ) * 360 / 2048.0;
cg.autoAngles[2] = 0;
cg.autoAnglesFast[0] = 0;
cg.autoAnglesFast[1] = ( cg.time & 1023 ) * 360 / 1024.0f;
cg.autoAnglesFast[2] = 0;
AnglesToAxis( cg.autoAnglesSlow, cg.autoAxisSlow );
AnglesToAxis( cg.autoAngles, cg.autoAxis );
AnglesToAxis( cg.autoAnglesFast, cg.autoAxisFast );
// generate and add the entity from the playerstate
ps = &cg.predictedPlayerState;
BG_PlayerStateToEntityState( ps, &cg.predictedPlayerEntity.currentState, qfalse );
CG_AddCEntity( &cg.predictedPlayerEntity );
// lerp the non-predicted value for lightning gun origins
CG_CalcEntityLerpPositions( &cg_entities[ cg.snap->ps.clientNum ] );
// add each entity sent over by the server
// NON TAG-CONNECTED ENTITIES
for ( num = 0 ; num < cg.snap->numEntities ; num++ ) {
cent = &cg_entities[ cg.snap->entities[ num ].number ];
if ( !( cent->currentState.eFlags & EF_TAGCONNECT ) ) {
CG_AddCEntity( cent );
}
}
// TAG-CONNECTED ENTITIES (connected to NON TAG-CONNECTED ENTITIES)
for ( num = 0 ; num < cg.snap->numEntities ; num++ ) {
cent = &cg_entities[ cg.snap->entities[ num ].number ];
if ( cent->currentState.eFlags & EF_TAGCONNECT ) {
CG_AddEntityToTag( cent );
}
}
// Ridah, add the flamethrower sounds
CG_UpdateFlamethrowerSounds();
}
|