1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597
|
/*
===========================================================================
Return to Castle Wolfenstein single player GPL Source Code
Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company.
This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”).
RTCW SP 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 SP 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 SP Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the RTCW SP 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 SP 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_players.c
*
* desc: handle the media and animation for player entities
*
*/
static char text[100000];
#include "cg_local.h"
#define SWING_RIGHT 1
#define SWING_LEFT 2
char *cg_customSoundNames[MAX_CUSTOM_SOUNDS] = {
"*death1.wav",
"*death2.wav",
"*death3.wav",
"*jump1.wav",
"*pain25_1.wav",
"*pain50_1.wav",
"*pain75_1.wav",
"*pain100_1.wav",
"*falling1.wav",
"*gasp.wav",
"*drown.wav",
"*fall1.wav",
"*fall2.wav",
"*taunt.wav",
"*exert1.wav",
"*exert2.wav",
"*exert3.wav",
};
/*
================
CG_EntOnFire
================
*/
qboolean CG_EntOnFire( centity_t *cent ) {
return ( ( cent->currentState.onFireStart < cg.time ) &&
( cent->currentState.onFireEnd > cg.time ) );
}
/*
================
CG_IsCrouchingAnim
================
*/
qboolean CG_IsCrouchingAnim( clientInfo_t *ci, int animNum ) {
animation_t *anim;
// FIXME: make compatible with new scripting
animNum &= ~ANIM_TOGGLEBIT;
//
anim = BG_GetAnimationForIndex( ci->clientNum, animNum );
//
if ( anim->movetype & ( ( 1 << ANIM_MT_IDLECR ) | ( 1 << ANIM_MT_WALKCR ) | ( 1 << ANIM_MT_WALKCRBK ) ) ) {
return qtrue;
}
//
return qfalse;
}
/*
================
CG_CustomSound
================
*/
sfxHandle_t CG_CustomSound( int clientNum, const char *soundName ) {
clientInfo_t *ci;
int i;
if ( soundName[0] != '*' ) {
return trap_S_RegisterSound( soundName );
}
if ( clientNum < 0 || clientNum >= MAX_CLIENTS ) {
clientNum = 0;
}
ci = &cgs.clientinfo[ clientNum ];
for ( i = 0 ; i < MAX_CUSTOM_SOUNDS && cg_customSoundNames[i] ; i++ ) {
if ( !Q_stricmp( soundName, cg_customSoundNames[i] ) ) {
return ci->sounds[i];
}
}
CG_Error( "Unknown custom sound: %s", soundName );
return 0;
}
/*
=============================================================================
CLIENT INFO
=============================================================================
*/
/*
======================
CG_ParseGibModels
Read a configuration file containing gib models for use with this character
======================
*/
static qboolean CG_ParseGibModels( const char *filename, clientInfo_t *ci ) {
char *text_p;
int len;
int i;
char *token;
fileHandle_t f;
memset( ci->gibModels, 0, sizeof( ci->gibModels ) );
// load the file
len = trap_FS_FOpenFile( filename, &f, FS_READ );
if ( len <= 0 ) {
return qfalse;
}
if ( len >= sizeof( text ) - 1 ) {
CG_Printf( "File %s too long\n", filename );
trap_FS_FCloseFile( f );
return qfalse;
}
trap_FS_Read( text, len, f );
text[len] = 0;
trap_FS_FCloseFile( f );
// parse the text
text_p = text;
for ( i = 0; i < MAX_GIB_MODELS; i++ ) {
token = COM_Parse( &text_p );
if ( !token[0] ) {
break;
}
// cache this model
ci->gibModels[i] = trap_R_RegisterModel( token );
}
return qtrue;
}
/*
==================
CG_CalcMoveSpeeds
==================
*/
void CG_CalcMoveSpeeds( clientInfo_t *ci ) {
char *tags[2] = {"tag_footleft", "tag_footright"};
vec3_t oldPos[2];
refEntity_t refent;
animation_t *anim;
int i, j, k;
float totalSpeed;
int numSpeed;
int low, numSteps, lastFirst, thisFirst;
qboolean isStrafe;
orientation_t o[2];
refent.hModel = ci->legsModel;
for ( i = 0, anim = ci->modelInfo->animations; i < ci->modelInfo->numAnimations; i++, anim++ ) {
if ( anim->moveSpeed == 0 ) {
continue;
}
totalSpeed = 0;
numSpeed = 0;
numSteps = 0;
isStrafe = qfalse;
if ( strstr( anim->name, "strafe" ) ) {
isStrafe = qtrue;
}
// first, get the end frame positions, since thats where we loop from
refent.frame = anim->firstFrame + anim->numFrames - 1;
refent.oldframe = refent.frame;
// for each foot
for ( k = 0; k < 2; k++ ) {
if ( trap_R_LerpTag( &o[k], &refent, tags[k], 0 ) < 0 ) {
CG_Error( "CG_CalcMoveSpeeds: unable to find tag %s, cannot calculate movespeed", tags[k] );
}
}
// save the positions
for ( k = 0; k < 2; k++ ) {
VectorCopy( o[k].origin, oldPos[k] );
}
//
// set the numSteps
if ( !isStrafe ) {
if ( o[0].origin[0] > o[1].origin[0] ) {
thisFirst = 0;
} else { thisFirst = 1;}
} else {
if ( o[0].origin[1] > o[1].origin[1] ) {
thisFirst = 0;
} else { thisFirst = 1;}
}
lastFirst = thisFirst;
// for each frame
for ( j = 0; j < anim->numFrames; j++ ) {
refent.frame = anim->firstFrame + j;
refent.oldframe = refent.frame;
// for each foot
for ( k = 0; k < 2; k++ ) {
if ( trap_R_LerpTag( &o[k], &refent, tags[k], 0 ) < 0 ) {
CG_Error( "CG_CalcMoveSpeeds: unable to find tag %s, cannot calculate movespeed", tags[k] );
}
}
// find the contact foot
if ( anim->flags & ANIMFL_LADDERANIM ) {
if ( o[0].origin[0] > o[1].origin[0] ) {
low = 0;
} else {
low = 1;
}
totalSpeed += fabs( oldPos[low][2] - o[low].origin[2] );
} else {
if ( o[0].origin[2] < o[1].origin[2] ) {
low = 0;
} else {
low = 1;
}
if ( !isStrafe ) {
totalSpeed += fabs( oldPos[low][0] - o[low].origin[0] );
} else {
totalSpeed += fabs( oldPos[low][1] - o[low].origin[1] );
}
//
// set the numSteps
if ( !isStrafe ) {
if ( o[0].origin[0] > o[1].origin[0] ) {
thisFirst = 0;
} else { thisFirst = 1;}
} else {
if ( o[0].origin[1] > o[1].origin[1] ) {
thisFirst = 0;
} else { thisFirst = 1;}
}
// if they have changed, record the step
if ( lastFirst != thisFirst ) {
numSteps++;
lastFirst = thisFirst;
}
}
numSpeed++;
// save the positions
for ( k = 0; k < 2; k++ ) {
VectorCopy( o[k].origin, oldPos[k] );
}
}
// record the speed
if ( anim->moveSpeed < 0 ) { // use the auto calculations
anim->moveSpeed = (int)( ( totalSpeed / numSpeed ) * 1000.0 / anim->frameLerp );
}
// set the stepGap
if ( !numSteps ) {
numSteps = 2;
}
if ( numSteps % 2 ) {
numSteps++; // round it up if odd number of steps
}
anim->stepGap = ( 0.5 * ( (float)anim->moveSpeed * (float)anim->duration / 1000.0 ) );
anim->stepGap /= ( numSteps / 2 ); // in case there are more than 2 steps in animation
if ( isStrafe ) {
anim->stepGap *= 1.3; // HACK
}
}
if ( cgs.localServer ) {
CG_SendMoveSpeed( ci->modelInfo->animations, ci->modelInfo->numAnimations, ci->modelInfo->modelname );
}
}
/*
======================
CG_ParseAnimationFiles
Read in all the configuration and script files for this model.
======================
*/
#if 0 // RF, this entire function not used anymore, since we now grab all this stuff from the server
static qboolean CG_ParseAnimationFiles( const char *modelname, clientInfo_t *ci, int client ) {
char filename[MAX_QPATH];
fileHandle_t f;
int len;
// set the name of the model in the modelinfo structure
Q_strncpyz( ci->modelInfo->modelname, modelname, sizeof( ci->modelInfo->modelname ) );
// load the cfg file
Com_sprintf( filename, sizeof( filename ), "models/players/%s/wolfanim.cfg", modelname );
len = trap_FS_FOpenFile( filename, &f, FS_READ );
if ( len <= 0 ) {
return qfalse;
}
if ( len >= sizeof( text ) - 1 ) {
CG_Printf( "File %s too long\n", filename );
trap_FS_FCloseFile( f );
return qfalse;
}
trap_FS_Read( text, len, f );
text[len] = 0;
trap_FS_FCloseFile( f );
// parse the text
BG_AnimParseAnimConfig( ci->modelInfo, filename, text );
if ( ci->isSkeletal != ci->modelInfo->isSkeletal ) {
CG_Error( "Mis-match in %s, loaded skeletal model, but file does not specify SKELETAL\n", filename );
}
// calc movespeed values if required
CG_CalcMoveSpeeds( ci );
// load the script file
Com_sprintf( filename, sizeof( filename ), "models/players/%s/wolfanim.script", modelname );
len = trap_FS_FOpenFile( filename, &f, FS_READ );
if ( len <= 0 ) {
if ( ci->modelInfo->version > 1 ) {
return qfalse;
}
// try loading the default script for old legacy models
Com_sprintf( filename, sizeof( filename ), "models/players/default.script", modelname );
len = trap_FS_FOpenFile( filename, &f, FS_READ );
if ( len <= 0 ) {
return qfalse;
}
}
if ( len >= sizeof( text ) - 1 ) {
CG_Printf( "File %s too long\n", filename );
trap_FS_FCloseFile( f );
return qfalse;
}
trap_FS_Read( text, len, f );
text[len] = 0;
trap_FS_FCloseFile( f );
// parse the text
BG_AnimParseAnimScript( ci->modelInfo, &cgs.animScriptData, ci->clientNum, filename, text );
return qtrue;
}
#endif
/*
==========================
CG_RegisterClientSkin
==========================
*/
//----(SA) modified this for head separation
static qboolean CG_RegisterClientSkin( clientInfo_t *ci, const char *modelName, const char *skinName ) {
char filename[MAX_QPATH];
// RF, try and register the new "body_*.skin" file for skeletal animation
Com_sprintf( filename, sizeof( filename ), "models/players/%s/body_%s.skin", modelName, skinName );
ci->legsSkin = trap_R_RegisterSkin( filename );
if ( ci->legsSkin ) { // skeletal model
ci->torsoSkin = ci->legsSkin;
return qtrue;
}
Com_sprintf( filename, sizeof( filename ), "models/players/%s/lower_%s.skin", modelName, skinName );
ci->legsSkin = trap_R_RegisterSkin( filename );
Com_sprintf( filename, sizeof( filename ), "models/players/%s/upper_%s.skin", modelName, skinName );
ci->torsoSkin = trap_R_RegisterSkin( filename );
if ( !ci->legsSkin || !ci->torsoSkin ) {
return qfalse;
}
return qtrue;
}
/*
==============
CG_RegisterClientHeadSkin
==============
*/
static qboolean CG_RegisterClientHeadSkin( clientInfo_t *ci, const char *modelName, const char *hSkinName ) {
char filename[MAX_QPATH];
Com_sprintf( filename, sizeof( filename ), "models/players/%s/head_%s.skin", modelName, hSkinName );
ci->headSkin = trap_R_RegisterSkin( filename );
if ( !ci->headSkin ) {
return qfalse;
}
return qtrue;
}
//----(SA) end
//----(SA) added
/*
==============
CG_RegisterAcc
==============
*/
static qboolean CG_RegisterAcc( clientInfo_t *ci, const char *modelName, const char *skinName, int *model, int *skin ) {
char namefromskin[MAX_QPATH];
char filename[MAX_QPATH];
if ( !model || !skin ) {
return qfalse;
}
// FIXME: have the check the last 4 chars rather than strstr()
if ( !strstr( skinName, ".md3" ) ) { // try to find a skin in the acc folder that matches
*skin = trap_R_RegisterSkin( va( "%s/%s.skin", modelName, skinName ) );
if ( *skin ) {
if ( trap_R_GetSkinModel( *skin, "md3_part", &namefromskin[0] ) ) {
Com_sprintf( filename, sizeof( filename ), "%s/acc/%s", modelName, namefromskin );
// NOTE: FIXME: this will currently only work with accessories in the <modelName>/acc directory.
// It will have to strip the directory off the end and then use the remaining
// path in order to work for arbitrary sub-directories.
// Com_sprintf( filename, sizeof( filename ), "%s/%s/%s.md3", modelName, <accpath>, namefromskin );
} else {
Com_sprintf( filename, sizeof( filename ), "%s/%s.md3", modelName, skinName );
}
} else {
Com_sprintf( filename, sizeof( filename ), "%s/%s.md3", modelName, skinName );
}
} else { // the skin wants a straight model
Com_sprintf( filename, sizeof( filename ), "%s/%s", modelName, skinName );
}
*model = trap_R_RegisterModel( filename );
if ( *model ) {
return qtrue;
}
return qfalse;
}
//----(SA) end
/*
=============
CG_ParseAnimationFiles
Used for demo playback, copied from G_ParseAnimationFiles.
=============
*/
qboolean CG_ParseAnimationFiles( char *modelname, animModelInfo_t *modelInfo, int clientNum ) {
char filename[MAX_QPATH];
fileHandle_t f;
int len;
// set the name of the model in the modelinfo structure
Q_strncpyz( modelInfo->modelname, modelname, sizeof( modelInfo->modelname ) );
// load the cfg file
Com_sprintf( filename, sizeof( filename ), "models/players/%s/wolfanim.cfg", modelname );
len = trap_FS_FOpenFile( filename, &f, FS_READ );
if ( len <= 0 ) {
CG_Printf( "CG_ParseAnimationFiles(): file '%s' not found\n", filename ); //----(SA) added
return qfalse;
}
if ( len >= sizeof( text ) - 1 ) {
CG_Printf( "File %s too long\n", filename );
return qfalse;
}
trap_FS_Read( text, len, f );
text[len] = 0;
trap_FS_FCloseFile( f );
// parse the text
BG_AnimParseAnimConfig( modelInfo, filename, text );
// load the script file
Com_sprintf( filename, sizeof( filename ), "models/players/%s/wolfanim.script", modelname );
len = trap_FS_FOpenFile( filename, &f, FS_READ );
if ( len <= 0 ) {
if ( modelInfo->version > 1 ) {
return qfalse;
}
// try loading the default script for old legacy models
Com_sprintf( filename, sizeof( filename ), "models/players/default.script" );
len = trap_FS_FOpenFile( filename, &f, FS_READ );
if ( len <= 0 ) {
return qfalse;
}
}
if ( len >= sizeof( text ) - 1 ) {
CG_Printf( "File %s too long\n", filename );
return qfalse;
}
trap_FS_Read( text, len, f );
text[len] = 0;
trap_FS_FCloseFile( f );
// parse the text
BG_AnimParseAnimScript( modelInfo, &cgs.animScriptData, clientNum, filename, text );
return qtrue;
}
/*
==================
CG_CheckForExistingModelInfo
If this player model has already been parsed, then use the existing information.
Otherwise, set the modelInfo pointer to the first free slot.
returns qtrue if existing model found, qfalse otherwise
==================
*/
extern animScriptData_t *globalScriptData;
static animModelInfo_t cgModelInfo[MAX_ANIMSCRIPT_MODELS];
qboolean CG_CheckForExistingModelInfo( clientInfo_t *ci, char *modelName, animModelInfo_t **modelInfo ) {
int i;
animModelInfo_t *trav; // *firstFree=NULL; // TTimo: unused
globalScriptData = &cgs.animScriptData;
for ( i = 0; i < MAX_ANIMSCRIPT_MODELS; i++ ) {
trav = cgs.animScriptData.modelInfo[i];
if ( trav && trav->modelname[0] ) {
// this model is used, so check if it's a match
if ( !Q_stricmp( trav->modelname, modelName ) ) {
// found a match, use this modelinfo
*modelInfo = trav;
cgs.animScriptData.clientModels[ci->clientNum] = i + 1;
return qtrue;
}
} else {
// if we fell down to here, then we have found a free slot
cgs.animScriptData.clientModels[ci->clientNum] = i + 1;
// request it from the server (game module)
if ( !trap_GetModelInfo( ci->clientNum, modelName, &cgs.animScriptData.modelInfo[i] ) ) {
memset( &cgModelInfo[i], 0, sizeof ( animModelInfo_t ) );
cgs.animScriptData.modelInfo[i] = &cgModelInfo[i];
// manually load for demos
if ( !CG_ParseAnimationFiles( modelName, cgs.animScriptData.modelInfo[i], ci->clientNum ) ) {
CG_Error( "Failed to load animation scripts for model %s\n", modelName );
}
}
// success
*modelInfo = cgs.animScriptData.modelInfo[i];
// calc movespeed/footstep values
CG_CalcMoveSpeeds( ci );
return qfalse; // we need to cache all the assets for this character
}
}
CG_Error( "unable to find a free modelinfo slot, cannot continue\n" );
// qfalse signifies that we need to parse the information from the script files
return qfalse;
}
/*
==========================
CG_RegisterClientModelname
==========================
*/
//----(SA) modified this for head separation
static qboolean CG_RegisterClientModelname( clientInfo_t *ci, const char *modelName, const char *skinName ) {
char namefromskin[MAX_QPATH];
char filename[MAX_QPATH];
char name[MAX_QPATH];
int i;
// if any skins failed to load, return failure
//----(SA) modified this for head separation
if ( !CG_RegisterClientSkin( ci, modelName, skinName ) ) {
Com_Printf( "Failed to load skin file: %s/%s\n", modelName, skinName );
return qfalse;
}
// load cmodels before models so filecache works
if ( trap_R_GetSkinModel( ci->legsSkin, "md3_part", &namefromskin[0] ) ) {
Com_sprintf( filename, sizeof( filename ), "models/players/%s/%s", modelName, namefromskin );
ci->legsModel = trap_R_RegisterModel( filename );
} else { // try skeletal model
Com_sprintf( filename, sizeof( filename ), "models/players/%s/body.mds", modelName );
ci->legsModel = trap_R_RegisterModel( filename );
if ( !ci->legsModel ) { // revert to mesh animation
Com_sprintf( filename, sizeof( filename ), "models/players/%s/lower.md3", modelName );
ci->legsModel = trap_R_RegisterModel( filename );
} else { // found skeletal model
ci->isSkeletal = qtrue;
ci->torsoModel = ci->legsModel;
}
}
if ( !ci->isSkeletal ) {
if ( !ci->legsModel ) {
Com_Printf( "Failed to load legs model file %s\n", filename );
return qfalse;
}
if ( trap_R_GetSkinModel( ci->torsoSkin, "md3_part", &namefromskin[0] ) ) {
Com_sprintf( filename, sizeof( filename ), "models/players/%s/%s", modelName, namefromskin );
} else {
Com_sprintf( filename, sizeof( filename ), "models/players/%s/upper.md3", modelName );
}
ci->torsoModel = trap_R_RegisterModel( filename );
if ( !ci->torsoModel ) {
Com_Printf( "Failed to load torso model file %s\n", filename );
return qfalse;
}
}
//----(SA) testing
{
char scaleString[MAX_QPATH];
char *string_p;
char *scaleToken;
qboolean badscale = qfalse;
string_p = scaleString;
if ( trap_R_GetSkinModel( ci->legsSkin, "playerscale", &scaleString[0] ) ) {
scaleToken = COM_Parse( &string_p );
if ( !scaleToken ) {
badscale = qtrue; // and drop to "if(badscale)" below
} else
{
ci->playermodelScale[0] = atof( scaleToken );
scaleToken = COM_Parse( &string_p );
if ( !scaleToken ) {
badscale = qtrue; // and drop to "if(badscale)" below
} else
{
ci->playermodelScale[1] = atof( scaleToken );
scaleToken = COM_Parse( &string_p );
if ( !scaleToken ) {
badscale = qtrue; // and drop to "if(badscale)" below
} else
{
ci->playermodelScale[2] = atof( scaleToken );
}
}
}
}
if ( badscale ) {
ci->playermodelScale[0] =
ci->playermodelScale[1] =
ci->playermodelScale[2] = 0.0f;
}
}
//----(SA) end
// try all the accessories
if ( trap_R_GetSkinModel( ci->legsSkin, "md3_beltr", &namefromskin[0] ) ) {
CG_RegisterAcc( ci, va( "models/players/%s", modelName ), namefromskin, &ci->accModels[ACC_BELT_LEFT], &ci->accSkins[ACC_BELT_LEFT] );
}
if ( trap_R_GetSkinModel( ci->legsSkin, "md3_beltl", &namefromskin[0] ) ) {
CG_RegisterAcc( ci, va( "models/players/%s", modelName ), namefromskin, &ci->accModels[ACC_BELT_RIGHT], &ci->accSkins[ACC_BELT_RIGHT] );
}
if ( trap_R_GetSkinModel( ci->torsoSkin, "md3_belt", &namefromskin[0] ) ) {
CG_RegisterAcc( ci, va( "models/players/%s", modelName ), namefromskin, &ci->accModels[ACC_BELT], &ci->accSkins[ACC_BELT] );
}
if ( trap_R_GetSkinModel( ci->torsoSkin, "md3_back", &namefromskin[0] ) ) {
CG_RegisterAcc( ci, va( "models/players/%s", modelName ), namefromskin, &ci->accModels[ACC_BACK], &ci->accSkins[ACC_BACK] );
}
if ( trap_R_GetSkinModel( ci->torsoSkin, "md3_weapon", &namefromskin[0] ) ) {
CG_RegisterAcc( ci, va( "models/players/%s", modelName ), namefromskin, &ci->accModels[ACC_WEAPON], &ci->accSkins[ACC_WEAPON] );
}
if ( trap_R_GetSkinModel( ci->torsoSkin, "md3_weapon2", &namefromskin[0] ) ) {
CG_RegisterAcc( ci, va( "models/players/%s", modelName ), namefromskin, &ci->accModels[ACC_WEAPON2], &ci->accSkins[ACC_WEAPON2] );
}
//----(SA) added
// try anim script parts
for ( i = 0; i < 8; i++ ) {
if ( trap_R_GetSkinModel( ci->torsoSkin, va( "md3_animscript%d", i ), &namefromskin[0] ) ) {
CG_RegisterAcc( ci, va( "models/players/%s", modelName ), namefromskin, &ci->partModels[ACC_WEAPON], &ci->partSkins[ACC_WEAPON] );
}
}
//----(SA) end
// look for this model in the list of models already opened
if ( !CG_CheckForExistingModelInfo( ci, (char *)modelName, &ci->modelInfo ) ) {
/*
if ( !CG_ParseAnimationFiles( modelName, ci, ci->clientNum ) ) {
Com_Printf( "Failed to load animation file %s\n", filename );
return qfalse;
}
*/
// special case, only cache certain shaders/models for certain characters
if ( !Q_strcasecmp( (char *)modelName, "zombie" ) ) {
cgs.media.zombieSpiritWallShader = trap_R_RegisterShader( "zombieDeathWindTrail" );
cgs.media.zombieSpiritTrailShader = trap_R_RegisterShader( "zombieSpiritTrail" );
cgs.media.zombieSpiritSkullShader = trap_R_RegisterShader( "zombieSpiritSkull" );
//cgs.media.zombieDeathDustShader = trap_R_RegisterShader( "zombieDeathDust" );
//cgs.media.zombieBodyFadeShader = trap_R_RegisterShader( "zombieBodyFade" );
//cgs.media.zombieHeadFadeShader = trap_R_RegisterShader( "zombieHeadFade" );
cgs.media.skeletonSkinShader = trap_R_RegisterShader( "skeletonSkin" );
cgs.media.skeletonLegsModel = trap_R_RegisterModel( "models/players/skel/lower.md3" );
cgs.media.skeletonLegsSkin = trap_R_RegisterSkin( "models/players/skel/lower_default.skin" );
cgs.media.skeletonTorsoModel = trap_R_RegisterModel( "models/players/skel/upper.md3" );
cgs.media.skeletonTorsoSkin = trap_R_RegisterSkin( "models/players/skel/upper_default.skin" );
cgs.media.skeletonHeadModel = trap_R_RegisterModel( "models/players/skel/head.md3" );
cgs.media.skeletonHeadSkin = trap_R_RegisterSkin( "models/players/skel/head_default.skin" );
cgs.media.zombieSpiritSound = trap_S_RegisterSound( "sound/zombie/attack/spirit_start.wav" );
cgs.media.zombieDeathSound = trap_S_RegisterSound( "sound/world/ceramicbreak.wav" ); // Zombie Gib
cgs.media.spiritSkullModel = trap_R_RegisterModel( "models/mapobjects/skull/skul2t.md3" );
CG_RegisterWeapon( WP_GAUNTLET );
} else if ( !Q_strcasecmp( (char *)modelName, "beast" ) ) {
cgs.media.helgaSpiritSkullShader = trap_R_RegisterShader( "helgaSpiritGhost" );
cgs.media.helgaSpiritTrailShader = trap_R_RegisterShader( "helgaSpiritTrail" );
cgs.media.helgaGhostModel = trap_R_RegisterModel( "models/players/beast/ghost.md3" );
cgs.media.helgaSpiritLoopSound = trap_S_RegisterSound( "sound/beast/tortured_souls_loop.wav" );
cgs.media.helgaSpiritSound = CG_SoundScriptPrecache( "helgaSpiritStartSound" );
cgs.media.helgaGaspSound = CG_SoundScriptPrecache( "helgaSpiritGasp" );
} else if ( !Q_strcasecmp( (char *)modelName, "loper" ) ) {
//cgs.media.loperGroundChargeShader = trap_R_RegisterShader( "loperGroundCharge" );
} else if ( !Q_strcasecmp( (char *)modelName, "protosoldier" ) ) {
cgs.media.protoArmorBreak = CG_SoundScriptPrecache( "Protosoldier_loseArmor" );
cgs.media.protoArmor[0] = trap_R_RegisterModel( "models/players/protosoldier/armor/nodam_chest.md3" );
cgs.media.protoArmor[1] = trap_R_RegisterModel( "models/players/protosoldier/armor/nodam_lftcalf.md3" );
cgs.media.protoArmor[2] = trap_R_RegisterModel( "models/players/protosoldier/armor/nodam_lftforarm.md3" );
cgs.media.protoArmor[3] = trap_R_RegisterModel( "models/players/protosoldier/armor/nodam_lftshoulder.md3" );
cgs.media.protoArmor[4] = trap_R_RegisterModel( "models/players/protosoldier/armor/nodam_lftthigh.md3" );
cgs.media.protoArmor[5] = trap_R_RegisterModel( "models/players/protosoldier/armor/nodam_rtcalf.md3" );
cgs.media.protoArmor[6] = trap_R_RegisterModel( "models/players/protosoldier/armor/nodam_rtforarm.md3" );
cgs.media.protoArmor[7] = trap_R_RegisterModel( "models/players/protosoldier/armor/nodam_rtshoulder.md3" );
cgs.media.protoArmor[8] = trap_R_RegisterModel( "models/players/protosoldier/armor/nodam_rtthigh.md3" );
cgs.media.protoArmor[9] = trap_R_RegisterModel( "models/players/protosoldier/armor/dam_chest1.md3" );
cgs.media.protoArmor[10] = trap_R_RegisterModel( "models/players/protosoldier/armor/dam_lftcalf1.md3" );
cgs.media.protoArmor[11] = trap_R_RegisterModel( "models/players/protosoldier/armor/dam_lftforarm1.md3" );
cgs.media.protoArmor[12] = trap_R_RegisterModel( "models/players/protosoldier/armor/dam_lftshoulder1.md3" );
cgs.media.protoArmor[13] = trap_R_RegisterModel( "models/players/protosoldier/armor/dam_lftthigh1.md3" );
cgs.media.protoArmor[14] = trap_R_RegisterModel( "models/players/protosoldier/armor/dam_rtcalf1.md3" );
cgs.media.protoArmor[15] = trap_R_RegisterModel( "models/players/protosoldier/armor/dam_rtforarm1.md3" );
cgs.media.protoArmor[16] = trap_R_RegisterModel( "models/players/protosoldier/armor/dam_rtshoulder1.md3" );
cgs.media.protoArmor[17] = trap_R_RegisterModel( "models/players/protosoldier/armor/dam_rtthigh1.md3" );
cgs.media.protoArmor[18] = trap_R_RegisterModel( "models/players/protosoldier/armor/dam_chest2.md3" );
cgs.media.protoArmor[19] = trap_R_RegisterModel( "models/players/protosoldier/armor/dam_lftcalf2.md3" );
cgs.media.protoArmor[20] = trap_R_RegisterModel( "models/players/protosoldier/armor/dam_lftforarm2.md3" );
cgs.media.protoArmor[21] = trap_R_RegisterModel( "models/players/protosoldier/armor/dam_lftshoulder2.md3" );
cgs.media.protoArmor[22] = trap_R_RegisterModel( "models/players/protosoldier/armor/dam_lftthigh2.md3" );
cgs.media.protoArmor[23] = trap_R_RegisterModel( "models/players/protosoldier/armor/dam_rtcalf2.md3" );
cgs.media.protoArmor[24] = trap_R_RegisterModel( "models/players/protosoldier/armor/dam_rtforarm2.md3" );
cgs.media.protoArmor[25] = trap_R_RegisterModel( "models/players/protosoldier/armor/dam_rtshoulder2.md3" );
cgs.media.protoArmor[26] = trap_R_RegisterModel( "models/players/protosoldier/armor/dam_rtthigh2.md3" );
} else if ( !Q_strcasecmp( (char *)modelName, "supersoldier" ) ) {
cgs.media.superArmorBreak = CG_SoundScriptPrecache( "Supersoldier_loseArmor" );
cgs.media.superArmor[0] = trap_R_RegisterModel( "models/players/supersoldier/armor/nodam_chest.md3" );
cgs.media.superArmor[1] = trap_R_RegisterModel( "models/players/supersoldier/armor/nodam_lftcalf.md3" );
cgs.media.superArmor[2] = trap_R_RegisterModel( "models/players/supersoldier/armor/nodam_lftforarm.md3" );
cgs.media.superArmor[3] = trap_R_RegisterModel( "models/players/supersoldier/armor/nodam_lftshoulder.md3" );
cgs.media.superArmor[4] = trap_R_RegisterModel( "models/players/supersoldier/armor/nodam_lftthigh.md3" );
cgs.media.superArmor[5] = trap_R_RegisterModel( "models/players/supersoldier/armor/nodam_rtcalf.md3" );
cgs.media.superArmor[6] = trap_R_RegisterModel( "models/players/supersoldier/armor/nodam_rtforarm.md3" );
cgs.media.superArmor[7] = trap_R_RegisterModel( "models/players/supersoldier/armor/nodam_rtshoulder.md3" );
cgs.media.superArmor[8] = trap_R_RegisterModel( "models/players/supersoldier/armor/nodam_rtthigh.md3" );
cgs.media.superArmor[9] = trap_R_RegisterModel( "models/players/supersoldier/armor/nodam_lftfoot.md3" );
cgs.media.superArmor[10] = trap_R_RegisterModel( "models/players/supersoldier/armor/nodam_rtfoot.md3" );
cgs.media.superArmor[11] = trap_R_RegisterModel( "models/players/supersoldier/armor/nodam_lftuparm.md3" );
cgs.media.superArmor[12] = trap_R_RegisterModel( "models/players/supersoldier/armor/nodam_rtuparm.md3" );
cgs.media.superArmor[13] = trap_R_RegisterModel( "models/players/supersoldier/armor/nodam_waist.md3" );
cgs.media.superArmor[14] = trap_R_RegisterModel( "models/players/supersoldier/armor/nodam_lftknee.md3" );
cgs.media.superArmor[15] = trap_R_RegisterModel( "models/players/supersoldier/armor/nodam_rtknee.md3" );
cgs.media.superArmor[16] = trap_R_RegisterModel( "models/players/supersoldier/armor/dam_chest1.md3" );
cgs.media.superArmor[17] = trap_R_RegisterModel( "models/players/supersoldier/armor/dam_lftcalf1.md3" );
cgs.media.superArmor[18] = trap_R_RegisterModel( "models/players/supersoldier/armor/dam_lftforarm1.md3" );
cgs.media.superArmor[19] = trap_R_RegisterModel( "models/players/supersoldier/armor/dam_lftshoulder1.md3" );
cgs.media.superArmor[20] = trap_R_RegisterModel( "models/players/supersoldier/armor/dam_lftthigh1.md3" );
cgs.media.superArmor[21] = trap_R_RegisterModel( "models/players/supersoldier/armor/dam_rtcalf1.md3" );
cgs.media.superArmor[22] = trap_R_RegisterModel( "models/players/supersoldier/armor/dam_rtforarm1.md3" );
cgs.media.superArmor[23] = trap_R_RegisterModel( "models/players/supersoldier/armor/dam_rtshoulder1.md3" );
cgs.media.superArmor[24] = trap_R_RegisterModel( "models/players/supersoldier/armor/dam_rtthigh1.md3" );
cgs.media.superArmor[25] = trap_R_RegisterModel( "models/players/supersoldier/armor/dam_lftfoot1.md3" );
cgs.media.superArmor[26] = trap_R_RegisterModel( "models/players/supersoldier/armor/dam_rtfoot1.md3" );
cgs.media.superArmor[27] = trap_R_RegisterModel( "models/players/supersoldier/armor/dam_lftuparm1.md3" );
cgs.media.superArmor[28] = trap_R_RegisterModel( "models/players/supersoldier/armor/dam_rtuparm1.md3" );
cgs.media.superArmor[29] = trap_R_RegisterModel( "models/players/supersoldier/armor/dam_waist1.md3" );
cgs.media.superArmor[30] = 0;
cgs.media.superArmor[31] = 0;
cgs.media.superArmor[32] = trap_R_RegisterModel( "models/players/supersoldier/armor/dam_chest2.md3" );
cgs.media.superArmor[33] = trap_R_RegisterModel( "models/players/supersoldier/armor/dam_lftcalf2.md3" );
cgs.media.superArmor[34] = trap_R_RegisterModel( "models/players/supersoldier/armor/dam_lftforarm2.md3" );
cgs.media.superArmor[35] = trap_R_RegisterModel( "models/players/supersoldier/armor/dam_lftshoulder2.md3" );
cgs.media.superArmor[36] = trap_R_RegisterModel( "models/players/supersoldier/armor/dam_lftthigh2.md3" );
cgs.media.superArmor[37] = trap_R_RegisterModel( "models/players/supersoldier/armor/dam_rtcalf2.md3" );
cgs.media.superArmor[38] = trap_R_RegisterModel( "models/players/supersoldier/armor/dam_rtforarm2.md3" );
cgs.media.superArmor[39] = trap_R_RegisterModel( "models/players/supersoldier/armor/dam_rtshoulder2.md3" );
cgs.media.superArmor[30] = trap_R_RegisterModel( "models/players/supersoldier/armor/dam_rtthigh2.md3" );
cgs.media.superArmor[31] = trap_R_RegisterModel( "models/players/supersoldier/armor/dam_lftfoot2.md3" );
cgs.media.superArmor[32] = trap_R_RegisterModel( "models/players/supersoldier/armor/dam_rtfoot2.md3" );
cgs.media.superArmor[33] = trap_R_RegisterModel( "models/players/supersoldier/armor/dam_lftuparm2.md3" );
cgs.media.superArmor[44] = trap_R_RegisterModel( "models/players/supersoldier/armor/dam_rtuparm2.md3" );
cgs.media.superArmor[45] = trap_R_RegisterModel( "models/players/supersoldier/armor/dam_waist2.md3" );
cgs.media.superArmor[46] = 0;
cgs.media.superArmor[47] = 0;
/*
super has that proto doesn't...
dam_chest3 attached to tag_chest
dam_lftfoot1
dam_lftfoot2
nodam_lftfoot attached to tag_footleft
dam_rtfoot1
dam_rtfoot2
nodam_rtfoot attached to tag_footright
dam_lftuparm1
dam_lftuparm2
nodam_lftuparm attached to tag_sholeft
dam_rtuparm1
dam_rtuparm2
nodam_rtuparm attached to tag_shoright
dam_waist1
dam_waist2
nodam_waist attached to tag_torso
nodam_lftknee attached to tag_calfleft
nodam_rtknee attached to tag_calfright
*/
} else if ( !Q_strcasecmp( (char *)modelName, "dark" ) ) {
cgs.media.superArmorBreak = CG_SoundScriptPrecache( "Supersoldier_loseArmor" );
cgs.media.superArmor[0] = trap_R_RegisterModel( "models/players/dark/armor/nodam_chest.md3" );
cgs.media.superArmor[1] = trap_R_RegisterModel( "models/players/dark/armor/nodam_lftcalf.md3" );
cgs.media.superArmor[2] = trap_R_RegisterModel( "models/players/dark/armor/nodam_lftforarm.md3" );
cgs.media.superArmor[3] = trap_R_RegisterModel( "models/players/dark/armor/nodam_lftshoulder.md3" );
cgs.media.superArmor[4] = trap_R_RegisterModel( "models/players/dark/armor/nodam_lftthigh.md3" );
cgs.media.superArmor[5] = trap_R_RegisterModel( "models/players/dark/armor/nodam_rtcalf.md3" );
cgs.media.superArmor[6] = trap_R_RegisterModel( "models/players/dark/armor/nodam_rtforarm.md3" );
cgs.media.superArmor[7] = trap_R_RegisterModel( "models/players/dark/armor/nodam_rtshoulder.md3" );
cgs.media.superArmor[8] = trap_R_RegisterModel( "models/players/dark/armor/nodam_rtthigh.md3" );
cgs.media.superArmor[9] = trap_R_RegisterModel( "models/players/dark/armor/nodam_lftfoot.md3" );
cgs.media.superArmor[10] = trap_R_RegisterModel( "models/players/dark/armor/nodam_rtfoot.md3" );
cgs.media.superArmor[11] = trap_R_RegisterModel( "models/players/dark/armor/nodam_lftuparm.md3" );
cgs.media.superArmor[12] = trap_R_RegisterModel( "models/players/dark/armor/nodam_rtuparm.md3" );
cgs.media.superArmor[13] = trap_R_RegisterModel( "models/players/dark/armor/nodam_waist.md3" );
cgs.media.superArmor[14] = trap_R_RegisterModel( "models/players/dark/armor/nodam_lftknee.md3" );
cgs.media.superArmor[15] = trap_R_RegisterModel( "models/players/dark/armor/nodam_rtknee.md3" );
cgs.media.superArmor[16] = trap_R_RegisterModel( "models/players/dark/armor/dam_chest1.md3" );
cgs.media.superArmor[17] = trap_R_RegisterModel( "models/players/dark/armor/dam_lftcalf1.md3" );
cgs.media.superArmor[18] = trap_R_RegisterModel( "models/players/dark/armor/dam_lftforarm1.md3" );
cgs.media.superArmor[19] = trap_R_RegisterModel( "models/players/dark/armor/dam_lftshoulder1.md3" );
cgs.media.superArmor[20] = trap_R_RegisterModel( "models/players/dark/armor/dam_lftthigh1.md3" );
cgs.media.superArmor[21] = trap_R_RegisterModel( "models/players/dark/armor/dam_rtcalf1.md3" );
cgs.media.superArmor[22] = trap_R_RegisterModel( "models/players/dark/armor/dam_rtforarm1.md3" );
cgs.media.superArmor[23] = trap_R_RegisterModel( "models/players/dark/armor/dam_rtshoulder1.md3" );
cgs.media.superArmor[24] = trap_R_RegisterModel( "models/players/dark/armor/dam_rtthigh1.md3" );
cgs.media.superArmor[25] = trap_R_RegisterModel( "models/players/dark/armor/dam_lftfoot1.md3" );
cgs.media.superArmor[26] = trap_R_RegisterModel( "models/players/dark/armor/dam_rtfoot1.md3" );
cgs.media.superArmor[27] = trap_R_RegisterModel( "models/players/dark/armor/dam_lftuparm1.md3" );
cgs.media.superArmor[28] = trap_R_RegisterModel( "models/players/dark/armor/dam_rtuparm1.md3" );
cgs.media.superArmor[29] = trap_R_RegisterModel( "models/players/dark/armor/dam_waist1.md3" );
cgs.media.superArmor[30] = 0;
cgs.media.superArmor[31] = 0;
cgs.media.superArmor[32] = trap_R_RegisterModel( "models/players/dark/armor/dam_chest2.md3" );
cgs.media.superArmor[33] = trap_R_RegisterModel( "models/players/dark/armor/dam_lftcalf2.md3" );
cgs.media.superArmor[34] = trap_R_RegisterModel( "models/players/dark/armor/dam_lftforarm2.md3" );
cgs.media.superArmor[35] = trap_R_RegisterModel( "models/players/dark/armor/dam_lftshoulder2.md3" );
cgs.media.superArmor[36] = trap_R_RegisterModel( "models/players/dark/armor/dam_lftthigh2.md3" );
cgs.media.superArmor[37] = trap_R_RegisterModel( "models/players/dark/armor/dam_rtcalf2.md3" );
cgs.media.superArmor[38] = trap_R_RegisterModel( "models/players/dark/armor/dam_rtforarm2.md3" );
cgs.media.superArmor[39] = trap_R_RegisterModel( "models/players/dark/armor/dam_rtshoulder2.md3" );
cgs.media.superArmor[30] = trap_R_RegisterModel( "models/players/dark/armor/dam_rtthigh2.md3" );
cgs.media.superArmor[31] = trap_R_RegisterModel( "models/players/dark/armor/dam_lftfoot2.md3" );
cgs.media.superArmor[32] = trap_R_RegisterModel( "models/players/dark/armor/dam_rtfoot2.md3" );
cgs.media.superArmor[33] = trap_R_RegisterModel( "models/players/dark/armor/dam_lftuparm2.md3" );
cgs.media.superArmor[44] = trap_R_RegisterModel( "models/players/dark/armor/dam_rtuparm2.md3" );
cgs.media.superArmor[45] = trap_R_RegisterModel( "models/players/dark/armor/dam_waist2.md3" );
cgs.media.superArmor[46] = 0;
cgs.media.superArmor[47] = 0;
} else if ( !Q_strcasecmp( (char *)modelName, "heinrich" ) ) {
cgs.media.heinrichArmorBreak = CG_SoundScriptPrecache( "Heinrich_loseArmor" );
// RF, these are also used by supersoldier "spirits" in end map
cgs.media.ssSpiritSkullModel = trap_R_RegisterModel( "models/players/supersoldier/ssghost.md3" );
cgs.media.zombieSpiritTrailShader = trap_R_RegisterShader( "zombieSpiritTrail" );
cgs.media.helgaGaspSound = CG_SoundScriptPrecache( "helgaSpiritGasp" );
cgs.media.debrisHitSound = trap_S_RegisterSound( "sound/world/debris_hit.wav" );
cgs.media.heinrichArmor[0] = trap_R_RegisterModel( "models/players/heinrich/armor/nodam_chest.md3" );
cgs.media.heinrichArmor[1] = trap_R_RegisterModel( "models/players/heinrich/armor/nodam_lftcalf.md3" );
cgs.media.heinrichArmor[2] = trap_R_RegisterModel( "models/players/heinrich/armor/nodam_lftforarm.md3" );
cgs.media.heinrichArmor[3] = trap_R_RegisterModel( "models/players/heinrich/armor/nodam_lftshoulder.md3" );
cgs.media.heinrichArmor[4] = trap_R_RegisterModel( "models/players/heinrich/armor/nodam_lftthigh.md3" );
cgs.media.heinrichArmor[5] = trap_R_RegisterModel( "models/players/heinrich/armor/nodam_rtcalf.md3" );
cgs.media.heinrichArmor[6] = trap_R_RegisterModel( "models/players/heinrich/armor/nodam_rtforarm.md3" );
cgs.media.heinrichArmor[7] = trap_R_RegisterModel( "models/players/heinrich/armor/nodam_rtshoulder.md3" );
cgs.media.heinrichArmor[8] = trap_R_RegisterModel( "models/players/heinrich/armor/nodam_rtthigh.md3" );
cgs.media.heinrichArmor[9] = trap_R_RegisterModel( "models/players/heinrich/armor/nodam_lftfoot.md3" );
cgs.media.heinrichArmor[10] = trap_R_RegisterModel( "models/players/heinrich/armor/nodam_rtfoot.md3" );
cgs.media.heinrichArmor[11] = trap_R_RegisterModel( "models/players/heinrich/armor/nodam_lftuparm.md3" );
cgs.media.heinrichArmor[12] = trap_R_RegisterModel( "models/players/heinrich/armor/nodam_rtuparm.md3" );
cgs.media.heinrichArmor[13] = trap_R_RegisterModel( "models/players/heinrich/armor/nodam_waist.md3" );
cgs.media.heinrichArmor[14] = trap_R_RegisterModel( "models/players/heinrich/armor/nodam_lftknee.md3" );
cgs.media.heinrichArmor[15] = trap_R_RegisterModel( "models/players/heinrich/armor/nodam_rtknee.md3" );
cgs.media.heinrichArmor[16] = trap_R_RegisterModel( "models/players/heinrich/armor/nodam_lftelbow.md3" );
cgs.media.heinrichArmor[17] = trap_R_RegisterModel( "models/players/heinrich/armor/nodam_rtelbow.md3" );
cgs.media.heinrichArmor[18] = trap_R_RegisterModel( "models/players/heinrich/armor/nodam_lfthip.md3" );
cgs.media.heinrichArmor[19] = trap_R_RegisterModel( "models/players/heinrich/armor/nodam_rthip.md3" );
cgs.media.heinrichArmor[20] = trap_R_RegisterModel( "models/players/heinrich/armor/nodam_lftshin.md3" );
cgs.media.heinrichArmor[21] = trap_R_RegisterModel( "models/players/heinrich/armor/nodam_rtshin.md3" );
cgs.media.heinrichArmor[22] = trap_R_RegisterModel( "models/players/heinrich/armor/dam_chest1.md3" );
cgs.media.heinrichArmor[23] = trap_R_RegisterModel( "models/players/heinrich/armor/dam_lftcalf1.md3" );
cgs.media.heinrichArmor[24] = trap_R_RegisterModel( "models/players/heinrich/armor/dam_lftforarm1.md3" );
cgs.media.heinrichArmor[25] = trap_R_RegisterModel( "models/players/heinrich/armor/dam_lftshoulder1.md3" );
cgs.media.heinrichArmor[26] = trap_R_RegisterModel( "models/players/heinrich/armor/dam_lftthigh1.md3" );
cgs.media.heinrichArmor[27] = trap_R_RegisterModel( "models/players/heinrich/armor/dam_rtcalf1.md3" );
cgs.media.heinrichArmor[28] = trap_R_RegisterModel( "models/players/heinrich/armor/dam_rtforarm1.md3" );
cgs.media.heinrichArmor[29] = trap_R_RegisterModel( "models/players/heinrich/armor/dam_rtshoulder1.md3" );
cgs.media.heinrichArmor[30] = trap_R_RegisterModel( "models/players/heinrich/armor/dam_rtthigh1.md3" );
cgs.media.heinrichArmor[31] = trap_R_RegisterModel( "models/players/heinrich/armor/dam_lftfoot1.md3" );
cgs.media.heinrichArmor[32] = trap_R_RegisterModel( "models/players/heinrich/armor/dam_rtfoot1.md3" );
cgs.media.heinrichArmor[33] = trap_R_RegisterModel( "models/players/heinrich/armor/dam_lftuparm1.md3" );
cgs.media.heinrichArmor[34] = trap_R_RegisterModel( "models/players/heinrich/armor/dam_rtuparm1.md3" );
cgs.media.heinrichArmor[35] = trap_R_RegisterModel( "models/players/heinrich/armor/dam_waist1.md3" );
cgs.media.heinrichArmor[36] = trap_R_RegisterModel( "models/players/heinrich/armor/dam_lftknee1.md3" );
cgs.media.heinrichArmor[37] = trap_R_RegisterModel( "models/players/heinrich/armor/dam_rtknee1.md3" );
cgs.media.heinrichArmor[38] = trap_R_RegisterModel( "models/players/heinrich/armor/dam_lftelbow1.md3" );
cgs.media.heinrichArmor[39] = trap_R_RegisterModel( "models/players/heinrich/armor/dam_rtelbow1.md3" );
cgs.media.heinrichArmor[40] = trap_R_RegisterModel( "models/players/heinrich/armor/dam_lfthip1.md3" );
cgs.media.heinrichArmor[41] = trap_R_RegisterModel( "models/players/heinrich/armor/dam_rthip1.md3" );
cgs.media.heinrichArmor[42] = 0;
cgs.media.heinrichArmor[43] = 0;
cgs.media.heinrichArmor[44] = trap_R_RegisterModel( "models/players/heinrich/armor/dam_chest2.md3" );
cgs.media.heinrichArmor[45] = trap_R_RegisterModel( "models/players/heinrich/armor/dam_lftcalf2.md3" );
cgs.media.heinrichArmor[46] = trap_R_RegisterModel( "models/players/heinrich/armor/dam_lftforarm2.md3" );
cgs.media.heinrichArmor[47] = trap_R_RegisterModel( "models/players/heinrich/armor/dam_lftshoulder2.md3" );
cgs.media.heinrichArmor[48] = trap_R_RegisterModel( "models/players/heinrich/armor/dam_lftthigh2.md3" );
cgs.media.heinrichArmor[49] = trap_R_RegisterModel( "models/players/heinrich/armor/dam_rtcalf2.md3" );
cgs.media.heinrichArmor[50] = trap_R_RegisterModel( "models/players/heinrich/armor/dam_rtforarm2.md3" );
cgs.media.heinrichArmor[51] = trap_R_RegisterModel( "models/players/heinrich/armor/dam_rtshoulder2.md3" );
cgs.media.heinrichArmor[52] = trap_R_RegisterModel( "models/players/heinrich/armor/dam_rtthigh2.md3" );
cgs.media.heinrichArmor[43] = trap_R_RegisterModel( "models/players/heinrich/armor/dam_lftfoot2.md3" );
cgs.media.heinrichArmor[54] = trap_R_RegisterModel( "models/players/heinrich/armor/dam_rtfoot2.md3" );
cgs.media.heinrichArmor[55] = trap_R_RegisterModel( "models/players/heinrich/armor/dam_lftuparm2.md3" );
cgs.media.heinrichArmor[56] = trap_R_RegisterModel( "models/players/heinrich/armor/dam_rtuparm2.md3" );
cgs.media.heinrichArmor[57] = trap_R_RegisterModel( "models/players/heinrich/armor/dam_waist2.md3" );
cgs.media.heinrichArmor[58] = trap_R_RegisterModel( "models/players/heinrich/armor/dam_lftknee2.md3" );
cgs.media.heinrichArmor[59] = trap_R_RegisterModel( "models/players/heinrich/armor/dam_rtknee2.md3" );
cgs.media.heinrichArmor[60] = trap_R_RegisterModel( "models/players/heinrich/armor/dam_lftelbow2.md3" );
cgs.media.heinrichArmor[61] = trap_R_RegisterModel( "models/players/heinrich/armor/dam_rtelbow2.md3" );
cgs.media.heinrichArmor[62] = trap_R_RegisterModel( "models/players/heinrich/armor/dam_lfthip2.md3" );
cgs.media.heinrichArmor[63] = trap_R_RegisterModel( "models/players/heinrich/armor/dam_rthip2.md3" );
cgs.media.heinrichArmor[64] = 0;
cgs.media.heinrichArmor[65] = 0;
/*
heinrich has that ss doesn't...
dam_lftelbow
dam_lftelbow1
dam_lftelbow2 attached to tag_sholeft
nodam_rtelbow
dam_rtelbow1
dam_rtelbow2 attached to tag_shoright
nodam_lfthip
dam_lfthip1
dam_lfthip2
dam_lfthip3 attached to tag_legleft
nodam_rthip
dam_rthip1
dam_rthip2
dam_rthip3 attached to tag_legright
nodam_lftshin attached to tag_calfleft
nodam_rtshin attached to tag_calfright
*/
}
//----(SA) end
// end special AI model loading
// -------- FOOTSTEP SOUNDS ---------
// load model specific footsteps
// FIXME: this should be moved over to per model scripts or animation scripting
if ( !Q_strcasecmp( (char *)modelName, "eliteguard" ) ) {
// ELITEGUARD
for ( i = 0; i < 4; i++ ) {
Com_sprintf( name, sizeof( name ), "sound/player/footsteps/eliteguard/step%i.wav", i + 1 );
cgs.media.footsteps[FOOTSTEP_ELITE_STEP][i] = trap_S_RegisterSound( name );
Com_sprintf( name, sizeof( name ), "sound/player/footsteps/eliteguard/clank%i.wav", i + 1 );
cgs.media.footsteps[FOOTSTEP_ELITE_METAL][i] = trap_S_RegisterSound( name );
// Com_sprintf (name, sizeof(name), "sound/player/footsteps/eliteguard/roof%i.wav", i+1);
// cgs.media.footsteps[FOOTSTEP_ELITE_ROOF][i] = trap_S_RegisterSound (name);
Com_sprintf( name, sizeof( name ), "sound/player/footsteps/eliteguard/wood%i.wav", i + 1 );
cgs.media.footsteps[FOOTSTEP_ELITE_WOOD][i] = trap_S_RegisterSound( name );
Com_sprintf( name, sizeof( name ), "sound/player/footsteps/eliteguard/gravel%i.wav", i + 1 );
cgs.media.footsteps[FOOTSTEP_ELITE_GRAVEL][i] = trap_S_RegisterSound( name );
}
} else if ( !Q_strcasecmp( (char *)modelName, "protosoldier" ) ) {
// ProtoSoldier
for ( i = 0; i < 4; i++ ) {
Com_sprintf( name, sizeof( name ), "sound/player/footsteps/protosoldier/step%i.wav", i + 1 );
cgs.media.footsteps[FOOTSTEP_PROTOSOLDIER_STEP][i] = trap_S_RegisterSound( name );
Com_sprintf( name, sizeof( name ), "sound/player/footsteps/protosoldier/clank%i.wav", i + 1 );
cgs.media.footsteps[FOOTSTEP_PROTOSOLDIER_METAL][i] = trap_S_RegisterSound( name );
Com_sprintf( name, sizeof( name ), "sound/player/footsteps/protosoldier/grass%i.wav", i + 1 );
cgs.media.footsteps[FOOTSTEP_PROTOSOLDIER_GRASS][i] = trap_S_RegisterSound( name );
Com_sprintf( name, sizeof( name ), "sound/player/footsteps/protosoldier/gravel%i.wav", i + 1 );
cgs.media.footsteps[FOOTSTEP_PROTOSOLDIER_GRAVEL][i] = trap_S_RegisterSound( name );
Com_sprintf( name, sizeof( name ), "sound/player/footsteps/protosoldier/wood%i.wav", i + 1 );
cgs.media.footsteps[FOOTSTEP_PROTOSOLDIER_WOOD][i] = trap_S_RegisterSound( name );
}
} else if ( !Q_strcasecmp( (char *)modelName, "supersoldier" ) ) {
// SuperSoldier/HEINRICH
for ( i = 0; i < 4; i++ ) {
Com_sprintf( name, sizeof( name ), "sound/player/footsteps/supersoldier/step%i.wav", i + 1 );
cgs.media.footsteps[FOOTSTEP_SUPERSOLDIER_STEP][i] = trap_S_RegisterSound( name );
Com_sprintf( name, sizeof( name ), "sound/player/footsteps/supersoldier/clank%i.wav", i + 1 );
cgs.media.footsteps[FOOTSTEP_SUPERSOLDIER_METAL][i] = trap_S_RegisterSound( name );
Com_sprintf( name, sizeof( name ), "sound/player/footsteps/supersoldier/grass%i.wav", i + 1 );
cgs.media.footsteps[FOOTSTEP_SUPERSOLDIER_GRASS][i] = trap_S_RegisterSound( name );
Com_sprintf( name, sizeof( name ), "sound/player/footsteps/supersoldier/gravel%i.wav", i + 1 );
cgs.media.footsteps[FOOTSTEP_SUPERSOLDIER_GRAVEL][i] = trap_S_RegisterSound( name );
Com_sprintf( name, sizeof( name ), "sound/player/footsteps/supersoldier/wood%i.wav", i + 1 );
cgs.media.footsteps[FOOTSTEP_SUPERSOLDIER_WOOD][i] = trap_S_RegisterSound( name );
}
}
// Heinrich special
else if ( !Q_strcasecmp( (char *)modelName, "heinrich" ) ) {
// SuperSoldier/HEINRICH
for ( i = 0; i < 4; i++ ) {
Com_sprintf( name, sizeof( name ), "sound/player/footsteps/heinrich/step%i.wav", i + 1 );
cgs.media.footsteps[FOOTSTEP_HEINRICH][i] = trap_S_RegisterSound( name );
}
} else if ( !Q_strcasecmp( (char *)modelName, "loper" ) ) {
// Loper
for ( i = 0; i < 4; i++ ) {
Com_sprintf( name, sizeof( name ), "sound/player/footsteps/loper/clank%i.wav", i + 1 );
cgs.media.footsteps[FOOTSTEP_LOPER_METAL][i] = trap_S_RegisterSound( name );
Com_sprintf( name, sizeof( name ), "sound/player/footsteps/loper/step%i.wav", i + 1 );
cgs.media.footsteps[FOOTSTEP_LOPER_STEP][i] = trap_S_RegisterSound( name );
Com_sprintf( name, sizeof( name ), "sound/player/footsteps/loper/wood%i.wav", i + 1 );
cgs.media.footsteps[FOOTSTEP_LOPER_WOOD][i] = trap_S_RegisterSound( name );
}
} else if ( !Q_strcasecmp( (char *)modelName, "zombie" ) ) {
// Zombie
for ( i = 0; i < 4; i++ ) {
Com_sprintf( name, sizeof( name ), "sound/player/footsteps/zombie/gravel%i.wav", i + 1 );
cgs.media.footsteps[FOOTSTEP_ZOMBIE_GRAVEL][i] = trap_S_RegisterSound( name );
Com_sprintf( name, sizeof( name ), "sound/player/footsteps/zombie/step%i.wav", i + 1 );
cgs.media.footsteps[FOOTSTEP_ZOMBIE_STEP][i] = trap_S_RegisterSound( name );
Com_sprintf( name, sizeof( name ), "sound/player/footsteps/zombie/wood%i.wav", i + 1 );
cgs.media.footsteps[FOOTSTEP_ZOMBIE_WOOD][i] = trap_S_RegisterSound( name );
}
} else if ( !Q_strcasecmp( (char *)modelName, "beast" ) ) {
// Helga Boss
cgs.media.footsteps[FOOTSTEP_BEAST][0] = CG_SoundScriptPrecache( "beastStep" ); // just precache the sound script
}
}
// whoops! this stuff would never get set if it found one existing already!!
if ( !Q_strcasecmp( (char *)modelName, "loper" ) ) {
ci->partModels[8] = trap_R_RegisterModel( va( "models/players/%s/spinner.md3", modelName ) );
} else if ( !Q_strcasecmp( (char *)modelName, "sealoper" ) ) {
ci->partModels[8] = trap_R_RegisterModel( va( "models/players/%s/spinner.md3", modelName ) );
}
return qtrue;
}
/*
==============
CG_RegisterClientHeadname
==============
*/
static qboolean CG_RegisterClientHeadname( clientInfo_t *ci, const char *modelName, const char *hSkinName ) {
char namefromskin[MAX_QPATH];
char filename[MAX_QPATH];
int i;
if ( !CG_RegisterClientHeadSkin( ci, modelName, hSkinName ) ) {
Com_Printf( "Failed to load head skin file: %s/head_%s.skin\n", modelName, hSkinName ); //----(SA)
return qfalse;
}
if ( trap_R_GetSkinModel( ci->headSkin, "md3_part", &namefromskin[0] ) ) {
Com_sprintf( filename, sizeof( filename ), "models/players/%s/%s", modelName, namefromskin );
} else {
Com_sprintf( filename, sizeof( filename ), "models/players/%s/head.md3", modelName );
}
ci->headModel = trap_R_RegisterModel( filename );
if ( !ci->headModel ) {
Com_Printf( "Failed to load head model file %s\n", filename ); //----(SA)
return qfalse;
}
if ( trap_R_GetSkinModel( ci->headSkin, "md3_hat", &namefromskin[0] ) ) {
CG_RegisterAcc( ci, va( "models/players/%s", modelName ), namefromskin, &ci->accModels[ACC_HAT], &ci->accSkins[ACC_HAT] );
}
for ( i = 0; i < ACC_NUM_MOUTH - 1; i++ ) {
if ( trap_R_GetSkinModel( ci->headSkin, va( "md3_hat%d", 2 + i ), &namefromskin[0] ) ) {
CG_RegisterAcc( ci, va( "models/players/%s", modelName ), namefromskin, &ci->accModels[ACC_MOUTH2 + i], &ci->accSkins[ACC_MOUTH2 + i] );
}
}
return qtrue;
}
/*
====================
CG_ColorFromString
====================
*/
static void CG_ColorFromString( const char *v, vec3_t color ) {
int val;
VectorClear( color );
val = atoi( v );
if ( val < 1 || val > 7 ) {
VectorSet( color, 1, 1, 1 );
return;
}
if ( val & 1 ) {
color[2] = 1.0f;
}
if ( val & 2 ) {
color[1] = 1.0f;
}
if ( val & 4 ) {
color[0] = 1.0f;
}
}
/*
===================
CG_LoadClientInfo
Load it now, taking the disk hits.
This will usually be deferred to a safe time
===================
*/
void CG_LoadClientInfo( int clientNum, clientInfo_t *ci ) {
const char *dir, *fallback;
int i;
const char *s;
int headfail = 0;
char filename[MAX_QPATH];
//----(SA) modified this for head separation
// load the head first (since if the head loads but there is a problem with something in the lower
// body, you will want to default the model back to a default and want the head to match)
//
if ( !CG_RegisterClientHeadname( ci, ci->modelName, ci->hSkinName ) ) {
if ( cg_buildScript.integer ) {
CG_Error( "CG_RegisterClientHeadname( %s, %s ) failed. setting default", ci->modelName, ci->hSkinName );
}
// fall back to default head
if ( !CG_RegisterClientHeadname( ci, ci->modelName, "default" ) ) {
headfail = 1;
if ( cg_buildScript.integer ) {
CG_Error( "head model/skin (%s/default) failed to register", ci->modelName ); //----(SA)
}
}
}
if ( headfail || !CG_RegisterClientModelname( ci, ci->modelName, ci->skinName ) ) {
if ( cg_buildScript.integer ) {
CG_Error( "CG_RegisterClientModelname( %s, %s ) failed", ci->modelName, ci->skinName );
}
// fall back
if ( cgs.gametype >= GT_TEAM ) {
// keep skin name but set default model
if ( !CG_RegisterClientModelname( ci, DEFAULT_MODEL, ci->skinName ) ) {
CG_Error( "DEFAULT_MODEL / skin (%s/%s) failed to register", DEFAULT_MODEL, ci->skinName );
}
} else if ( cgs.gametype == GT_SINGLE_PLAYER && !headfail ) {
// try to keep the model but default the skin (so you can tell bad guys from good)
if ( !CG_RegisterClientModelname( ci, ci->modelName, "default" ) ) {
CG_Error( "DEFAULT_MODEL (%s/default) failed to register", ci->modelName );
}
} else {
// go totally default
if ( !CG_RegisterClientModelname( ci, DEFAULT_MODEL, "default" ) ) {
CG_Error( "DEFAULT_MODEL (%s/default) failed to register", DEFAULT_MODEL );
}
// fall back to default head
if ( !CG_RegisterClientHeadname( ci, DEFAULT_MODEL, "default" ) ) {
CG_Error( "model/ DEFAULT_HEAD / skin (%s/default) failed to register", DEFAULT_HEAD );
}
}
}
//----(SA) end
// sounds
dir = ci->modelName;
fallback = DEFAULT_MODEL;
for ( i = 0 ; i < MAX_CUSTOM_SOUNDS ; i++ ) {
s = cg_customSoundNames[i];
if ( !s ) {
break;
}
ci->sounds[i] = trap_S_RegisterSound( va( "sound/player/%s/%s", dir, s + 1 ) );
if ( !ci->sounds[i] ) {
ci->sounds[i] = trap_S_RegisterSound( va( "sound/player/%s/%s", fallback, s + 1 ) );
}
}
// load the gibs
Com_sprintf( filename, sizeof( filename ), "models/players/%s/gibs.cfg", dir );
if ( !CG_ParseGibModels( filename, ci ) ) {
// n/mind.. gib code will automatically fall back to old gibs
}
ci->deferred = qfalse;
// reset any existing players and bodies, because they might be in bad
// frames for this new model
for ( i = 0 ; i < MAX_GENTITIES ; i++ ) {
if ( cg_entities[i].currentState.clientNum == clientNum
&& cg_entities[i].currentState.eType == ET_PLAYER ) {
CG_ResetPlayerEntity( &cg_entities[i] );
}
}
}
/*
======================
CG_CopyClientInfoModel
======================
*/
static void CG_CopyClientInfoModel( clientInfo_t *from, clientInfo_t *to ) {
VectorCopy( from->playermodelScale, to->playermodelScale );
to->legsModel = from->legsModel;
to->legsSkin = from->legsSkin;
to->torsoModel = from->torsoModel;
to->torsoSkin = from->torsoSkin;
to->headModel = from->headModel;
to->headSkin = from->headSkin;
to->isSkeletal = from->isSkeletal;
to->modelIcon = from->modelIcon;
//----(SA)
memcpy( to->accModels, from->accModels, sizeof( to->accModels ) );
memcpy( to->accSkins, from->accSkins, sizeof( to->accSkins ) );
memcpy( to->partModels, from->partModels, sizeof( to->partModels ) );
// memcpy( to->partSkins, from->partSkins, sizeof( to->partSkins ) );
//----(SA) end
memcpy( to->sounds, from->sounds, sizeof( to->sounds ) );
// Ridah
memcpy( to->gibModels, from->gibModels, sizeof( to->gibModels ) );
// done.
// copy the modelInfo
to->modelInfo = from->modelInfo;
cgs.animScriptData.clientModels[ to->clientNum ] = cgs.animScriptData.clientModels[ from->clientNum ];
}
/*
======================
CG_ScanForExistingClientInfo
======================
*/
static qboolean CG_ScanForExistingClientInfo( clientInfo_t *ci ) {
int i;
clientInfo_t *match;
for ( i = 0 ; i < cgs.maxclients ; i++ ) {
match = &cgs.clientinfo[ i ];
if ( !match->infoValid ) {
continue;
}
if ( match->deferred ) {
continue;
}
//----(SA) added checks for same head. FIXME: soon this will be more efficient than just looking for a complete character (body/head) match.
if (
!Q_stricmp( ci->modelName, match->modelName )
&& !Q_stricmp( ci->skinName, match->skinName )
&& !Q_stricmp( ci->hSkinName, match->hSkinName )
) {
//----(SA) done
// this clientinfo is identical, so use its handles
ci->deferred = qfalse;
CG_CopyClientInfoModel( match, ci );
return qtrue;
}
}
// nothing matches, so defer the load
return qfalse;
}
/*
======================
CG_SetDeferredClientInfo
We aren't going to load it now, so grab some other
client's info to use until we have some spare time.
======================
*/
static void CG_SetDeferredClientInfo( int clientNum, clientInfo_t *ci ) {
int i;
clientInfo_t *match;
// if we are in teamplay, only grab a model if the skin is correct
if ( cgs.gametype >= GT_TEAM ) {
for ( i = 0 ; i < cgs.maxclients ; i++ ) {
match = &cgs.clientinfo[ i ];
if ( !match->infoValid ) {
continue;
}
if ( Q_stricmp( ci->skinName, match->skinName ) ) {
continue;
}
ci->deferred = qtrue;
CG_CopyClientInfoModel( match, ci );
return;
}
// load the full model, because we don't ever want to show
// an improper team skin. This will cause a hitch for the first
// player, when the second enters. Combat shouldn't be going on
// yet, so it shouldn't matter
CG_LoadClientInfo( clientNum, ci );
return;
}
// find the first valid clientinfo and grab its stuff
for ( i = 0 ; i < cgs.maxclients ; i++ ) {
match = &cgs.clientinfo[ i ];
if ( !match->infoValid ) {
continue;
}
ci->deferred = qtrue;
CG_CopyClientInfoModel( match, ci );
return;
}
// we should never get here...
CG_Printf( "CG_SetDeferredClientInfo: no valid clients!\n" );
CG_LoadClientInfo( clientNum, ci );
}
/*
======================
CG_NewClientInfo
======================
*/
void CG_NewClientInfo( int clientNum ) {
clientInfo_t *ci;
clientInfo_t newInfo;
const char *configstring;
const char *v;
char *slash;
ci = &cgs.clientinfo[clientNum];
configstring = CG_ConfigString( clientNum + CS_PLAYERS );
if ( !configstring[0] ) {
memset( ci, 0, sizeof( *ci ) );
return; // player just left
}
// build into a temp buffer so the defer checks can use
// the old value
memset( &newInfo, 0, sizeof( newInfo ) );
newInfo.clientNum = clientNum;
// isolate the player's name
v = Info_ValueForKey( configstring, "n" );
Q_strncpyz( newInfo.name, v, sizeof( newInfo.name ) );
// colors
v = Info_ValueForKey( configstring, "c1" );
CG_ColorFromString( v, newInfo.color );
newInfo.c1RGBA[0] = 255 * newInfo.color[0];
newInfo.c1RGBA[1] = 255 * newInfo.color[1];
newInfo.c1RGBA[2] = 255 * newInfo.color[2];
newInfo.c1RGBA[3] = 255;
// bot skill
v = Info_ValueForKey( configstring, "skill" );
newInfo.botSkill = atoi( v );
// handicap
v = Info_ValueForKey( configstring, "hc" );
newInfo.handicap = atoi( v );
// wins
v = Info_ValueForKey( configstring, "w" );
newInfo.wins = atoi( v );
// losses
v = Info_ValueForKey( configstring, "l" );
newInfo.losses = atoi( v );
// team
v = Info_ValueForKey( configstring, "t" );
newInfo.team = atoi( v );
//----(SA) modified this for head separation
// (SA) note to Ryan: The problem I see with having the model set for cg_forceModel in the game (g_forcemodel)
// is that it was initally there for a performance/fairness thing so you can connect to a
// server and not use other players goofy models or whatever. We should still have some simple
// client-side thing for defaulting all models to one particular player model or something. (did that make sense?)
// head
v = Info_ValueForKey( configstring, "head" );
/* RF, disabled this, not needed anymore
if ( cg_forceModel.integer ) {
char modelStr[MAX_QPATH];
// forcemodel makes everyone use a single model
// to prevent load hitches
trap_Cvar_VariableStringBuffer( "head", modelStr, sizeof( modelStr ) );
Q_strncpyz( newInfo.hSkinName, modelStr, sizeof( newInfo.hSkinName ) );
} else {
*/
Q_strncpyz( newInfo.hSkinName, v, sizeof( newInfo.hSkinName ) );
// }
//----(SA) modified this for head separation
// model
v = Info_ValueForKey( configstring, "model" );
/* RF, disabled this, not needed anymore
if ( cg_forceModel.integer ) {
// forcemodel makes everyone use a single model
// to prevent load hitches
char modelStr[MAX_QPATH];
char *skin;
trap_Cvar_VariableStringBuffer( "model", modelStr, sizeof( modelStr ) );
if ( ( skin = strchr( modelStr, '/' ) ) == NULL ) {
skin = "default";
} else {
*skin++ = 0;
}
Q_strncpyz( newInfo.skinName, skin, sizeof( newInfo.skinName ) );
Q_strncpyz( newInfo.modelName, modelStr, sizeof( newInfo.modelName ) );
if ( cgs.gametype >= GT_TEAM ) {
// keep skin name
slash = strchr( v, '/' );
if ( slash ) {
Q_strncpyz( newInfo.skinName, slash + 1, sizeof( newInfo.skinName ) );
}
}
} else {
*/
Q_strncpyz( newInfo.modelName, v, sizeof( newInfo.modelName ) );
slash = strchr( newInfo.modelName, '/' );
if ( !slash ) {
// modelName did not include a skin name
Q_strncpyz( newInfo.skinName, "default", sizeof( newInfo.skinName ) );
} else {
Q_strncpyz( newInfo.skinName, slash + 1, sizeof( newInfo.skinName ) );
// truncate modelName
*slash = 0;
}
// }
//----(SA) modify \/ to differentiate for head models/skins as well
// scan for an existing clientinfo that matches this modelname
// so we can avoid loading checks if possible
if ( !CG_ScanForExistingClientInfo( &newInfo ) ) {
qboolean forceDefer;
// RF, disabled this, we can't have this happening in Wolf. If there is not enough memory,
// then we have a leak or havent allocated enough hunk
forceDefer = qfalse;
// forceDefer = trap_MemoryRemaining() < 4000000;
// if we are defering loads, just have it pick the first valid
// if ( forceDefer || ( cg_deferPlayers.integer && !cg_buildScript.integer && !cg.loading ) ) {
// very temporary! do not defer any players just yet
// we need to get ai's to be non-deferred players before we can
// do this (SA)
if ( forceDefer ) {
// keep whatever they had if it won't violate team skins
if ( ci->infoValid &&
( cgs.gametype < GT_TEAM || !Q_stricmp( newInfo.skinName, ci->skinName ) ) ) {
CG_CopyClientInfoModel( ci, &newInfo );
newInfo.deferred = qtrue;
} else {
// use whatever is available
CG_SetDeferredClientInfo( clientNum, &newInfo );
}
// if we are low on memory, leave them with this model
if ( forceDefer ) {
CG_Printf( "Memory is low. Using deferred model.\n" );
newInfo.deferred = qfalse;
}
} else {
CG_LoadClientInfo( clientNum, &newInfo );
}
}
// replace whatever was there with the new one
newInfo.infoValid = qtrue;
*ci = newInfo;
}
/*
======================
CG_LoadDeferredPlayers
Called each frame when a player is dead
and the scoreboard is up
so deferred players can be loaded
======================
*/
void CG_LoadDeferredPlayers( void ) {
int i;
clientInfo_t *ci;
// scan for a deferred player to load
for ( i = 0, ci = cgs.clientinfo ; i < cgs.maxclients ; i++, ci++ ) {
if ( ci->infoValid && ci->deferred ) {
// if we are low on memory, leave it deferred
if ( trap_MemoryRemaining() < 4000000 ) {
CG_Printf( "Memory is low. Using deferred model.\n" );
ci->deferred = qfalse;
continue;
}
CG_LoadClientInfo( i, ci );
}
}
}
/*
=============================================================================
PLAYER ANIMATION
=============================================================================
*/
/*
===============
CG_SetLerpFrameAnimation
may include ANIM_TOGGLEBIT
===============
*/
static void CG_SetLerpFrameAnimation( clientInfo_t *ci, lerpFrame_t *lf, int newAnimation ) {
animation_t *anim;
if ( !ci->modelInfo ) {
return;
}
lf->animationNumber = newAnimation;
newAnimation &= ~ANIM_TOGGLEBIT;
if ( newAnimation < 0 || newAnimation >= ci->modelInfo->numAnimations ) {
CG_Error( "Bad animation number (CG_SLFA): %i", newAnimation );
}
anim = &ci->modelInfo->animations[ newAnimation ];
lf->animation = anim;
lf->animationTime = lf->frameTime + anim->initialLerp;
if ( cg_debugAnim.integer == 1 ) { // DHM - Nerve :: extra debug info
CG_Printf( "Anim: %i, %s\n", newAnimation, ci->modelInfo->animations[newAnimation].name );
}
}
/*
===============
CG_RunLerpFrame
Sets cg.snap, cg.oldFrame, and cg.backlerp
cg.time should be between oldFrameTime and frameTime after exit
===============
*/
void CG_RunLerpFrame( clientInfo_t *ci, lerpFrame_t *lf, int newAnimation, float speedScale ) {
int f;
animation_t *anim;
// debugging tool to get no animations
if ( cg_animSpeed.integer == 0 ) {
lf->oldFrame = lf->frame = lf->backlerp = 0;
return;
}
// see if the animation sequence is switching
if ( ci && ( newAnimation != lf->animationNumber || !lf->animation ) ) { //----(SA) modified
CG_SetLerpFrameAnimation( ci, lf, newAnimation );
}
// if we have passed the current frame, move it to
// oldFrame and calculate a new frame
if ( cg.time >= lf->frameTime ) {
lf->oldFrame = lf->frame;
lf->oldFrameTime = lf->frameTime;
// get the next frame based on the animation
anim = lf->animation;
if ( !anim )
return;
if ( !anim->frameLerp ) {
return; // shouldn't happen
}
if ( cg.time < lf->animationTime ) {
lf->frameTime = lf->animationTime; // initial lerp
} else {
lf->frameTime = lf->oldFrameTime + anim->frameLerp;
}
f = ( lf->frameTime - lf->animationTime ) / anim->frameLerp;
f *= speedScale; // adjust for haste, etc
if ( f >= anim->numFrames ) {
f -= anim->numFrames;
if ( anim->loopFrames ) {
f %= anim->loopFrames;
f += anim->numFrames - anim->loopFrames;
} else {
f = anim->numFrames - 1;
// the animation is stuck at the end, so it
// can immediately transition to another sequence
lf->frameTime = cg.time;
}
}
lf->frame = anim->firstFrame + f;
if ( cg.time > lf->frameTime ) {
lf->frameTime = cg.time;
if ( cg_debugAnim.integer ) {
CG_Printf( "Clamp lf->frameTime\n" );
}
}
}
if ( lf->frameTime > cg.time + 200 ) {
lf->frameTime = cg.time;
}
if ( lf->oldFrameTime > cg.time ) {
lf->oldFrameTime = cg.time;
}
// calculate current lerp value
if ( lf->frameTime == lf->oldFrameTime ) {
lf->backlerp = 0;
} else {
lf->backlerp = 1.0 - (float)( cg.time - lf->oldFrameTime ) / ( lf->frameTime - lf->oldFrameTime );
}
}
/*
===============
CG_ClearLerpFrame
===============
*/
static void CG_ClearLerpFrame( clientInfo_t *ci, lerpFrame_t *lf, int animationNumber ) {
lf->frameTime = lf->oldFrameTime = cg.time;
CG_SetLerpFrameAnimation( ci, lf, animationNumber );
if ( lf->animation ) {
lf->oldFrame = lf->frame = lf->animation->firstFrame;
}
}
//------------------------------------------------------------------------------
// Ridah, variable speed animations
/*
===============
CG_SetLerpFrameAnimationRate
may include ANIM_TOGGLEBIT
===============
*/
void CG_SetLerpFrameAnimationRate( centity_t *cent, clientInfo_t *ci, lerpFrame_t *lf, int newAnimation ) {
animation_t *anim, *oldanim;
int transitionMin = -1, oldAnimNum;
qboolean firstAnim = qfalse;
if ( !ci->modelInfo ) {
return;
}
oldanim = lf->animation;
oldAnimNum = lf->animationNumber;
if ( !lf->animation ) {
firstAnim = qtrue;
}
lf->animationNumber = newAnimation;
newAnimation &= ~ANIM_TOGGLEBIT;
if ( newAnimation < 0 || newAnimation >= ci->modelInfo->numAnimations ) {
CG_Error( "Bad animation number (CG_SLFAR): %i", newAnimation );
}
anim = &ci->modelInfo->animations[ newAnimation ];
lf->animation = anim;
lf->animationTime = lf->frameTime + anim->initialLerp;
if ( !( anim->flags & ANIMFL_FIRINGANIM ) || ( lf != ¢->pe.torso ) ) {
if ( ( lf == ¢->pe.legs ) && ( CG_IsCrouchingAnim( ci, newAnimation ) != CG_IsCrouchingAnim( ci, oldAnimNum ) ) ) {
if ( anim->moveSpeed || ( anim->movetype & ( ( 1 << ANIM_MT_TURNLEFT ) | ( 1 << ANIM_MT_TURNRIGHT ) ) ) ) { // if unknown movetype, go there faster
transitionMin = lf->frameTime + 200; // slowly raise/drop
} else {
transitionMin = lf->frameTime + 350; // slowly raise/drop
}
} else if ( anim->moveSpeed ) {
transitionMin = lf->frameTime + 120; // always do some lerping (?)
} else { // not moving, so take your time
transitionMin = lf->frameTime + 170; // always do some lerping (?)
}
if ( oldanim && oldanim->animBlend ) { //transitionMin < lf->frameTime + oldanim->animBlend) {
transitionMin = lf->frameTime + oldanim->animBlend;
lf->animationTime = transitionMin;
} else {
// slow down transitions according to speed
if ( anim->moveSpeed && lf->animSpeedScale < 1.0 ) {
lf->animationTime += anim->initialLerp;
}
if ( lf->animationTime < transitionMin ) {
lf->animationTime = transitionMin;
}
}
}
// if first anim, go immediately
if ( firstAnim ) {
lf->frameTime = cg.time - 1;
lf->animationTime = cg.time - 1;
lf->frame = anim->firstFrame;
}
// if death frame, move straight to last frame
if ( cent->currentState.eFlags & EF_DEATH_FRAME ) {
lf->frameTime = cg.time - 1;
lf->animationTime = cg.time - 1;
lf->frame = anim->firstFrame + anim->numFrames - 1;
lf->oldFrame = lf->frame;
lf->oldAnimationNumber = lf->animationNumber;
}
if ( cg_debugAnim.integer == 1 ) { // DHM - Nerve :: extra debug info
CG_Printf( "Anim: %i, %s\n", newAnimation, ci->modelInfo->animations[newAnimation].name );
}
}
/*
===============
CG_RunLerpFrameRate
Sets cg.snap, cg.oldFrame, and cg.backlerp
cg.time should be between oldFrameTime and frameTime after exit
===============
*/
void CG_RunLerpFrameRate( clientInfo_t *ci, lerpFrame_t *lf, int newAnimation, centity_t *cent, int recursion ) {
int f;
animation_t *anim, *oldAnim;
animation_t *otherAnim = NULL;
qboolean isLadderAnim;
#define ANIM_SCALEMAX_LOW 1.1
#define ANIM_SCALEMAX_HIGH 1.6
#define ANIM_SPEEDMAX_LOW 100
#define ANIM_SPEEDMAX_HIGH 20
// debugging tool to get no animations
if ( cg_animSpeed.integer == 0 ) {
lf->oldFrame = lf->frame = lf->backlerp = 0;
return;
}
isLadderAnim = lf->animation && ( lf->animation->flags & ANIMFL_LADDERANIM );
oldAnim = lf->animation;
// see if the animation sequence is switching
if ( newAnimation != lf->animationNumber || !lf->animation ) {
#if 0
#ifdef _DEBUG // RF, debugging anims
//if ( cent->currentState.number == 3 )
CG_Printf( "(%i) %s anim change on %s: %s -> %s\n", cg.time, ci->modelInfo->modelname, ( lf == ¢->pe.legs ? "LEGS" : "TORSO" ), lf->animation->name, ci->modelInfo->animations[newAnimation & ~( 1 << 9 )].name );
#endif
#endif
CG_SetLerpFrameAnimationRate( cent, ci, lf, newAnimation );
}
// Ridah, make sure the animation speed is updated when possible
anim = lf->animation;
// check for forcing last frame
if ( cent->currentState.eFlags & EF_FORCE_END_FRAME ) {
lf->frame = anim->firstFrame + anim->numFrames - 1;
lf->oldFrame = lf->frame;
lf->backlerp = 0;
return;
}
if ( anim->moveSpeed && lf->oldFrameSnapshotTime ) {
float moveSpeed;
// calculate the speed at which we moved over the last frame
if ( cg.latestSnapshotTime != lf->oldFrameSnapshotTime && cg.nextSnap ) {
if ( cent->currentState.number == cg.snap->ps.clientNum ) {
if ( isLadderAnim ) { // only use Z axis for speed
lf->oldFramePos[0] = cent->lerpOrigin[0];
lf->oldFramePos[1] = cent->lerpOrigin[1];
} else { // only use x/y axis
lf->oldFramePos[2] = cent->lerpOrigin[2];
}
moveSpeed = Distance( cent->lerpOrigin, lf->oldFramePos ) / ( (float)( cg.time - lf->oldFrameTime ) / 1000.0 );
} else {
if ( isLadderAnim ) { // only use Z axis for speed
lf->oldFramePos[0] = cent->currentState.pos.trBase[0];
lf->oldFramePos[1] = cent->currentState.pos.trBase[1];
}
if ( cg.snap != cg.nextSnap ) {
moveSpeed = Distance( cent->currentState.pos.trBase, cent->nextState.pos.trBase ) / ( (float)( cg.nextSnap->serverTime - cg.snap->serverTime ) / 1000.0 );
} else {
moveSpeed = 0;
}
}
//
// convert it to a factor of this animation's movespeed
lf->animSpeedScale = moveSpeed / (float)anim->moveSpeed;
lf->oldFrameSnapshotTime = cg.latestSnapshotTime;
}
} else {
// move at normal speed
lf->animSpeedScale = 1.0;
lf->oldFrameSnapshotTime = cg.latestSnapshotTime;
}
// adjust with manual setting (pain anims)
lf->animSpeedScale *= cent->pe.animSpeed;
// if we have passed the current frame, move it to
// oldFrame and calculate a new frame
if ( cg.time >= lf->frameTime ) {
lf->oldFrame = lf->frame;
lf->oldFrameTime = lf->frameTime;
VectorCopy( cent->lerpOrigin, lf->oldFramePos );
// restrict the speed range
if ( lf->animSpeedScale < 0.25 ) { // if it's too slow, then a really slow spped, combined with a sudden take-off, can leave them playing a really slow frame while they a moving really fast
if ( lf->animSpeedScale < 0.01 && isLadderAnim ) {
lf->animSpeedScale = 0.0;
} else {
lf->animSpeedScale = 0.25;
}
} else if ( lf->animSpeedScale > ANIM_SCALEMAX_LOW ) {
if ( !( anim->flags & ANIMFL_LADDERANIM ) ) {
// allow slower anims to speed up more than faster anims
if ( anim->moveSpeed > ANIM_SPEEDMAX_LOW ) {
lf->animSpeedScale = ANIM_SCALEMAX_LOW;
} else if ( anim->moveSpeed < ANIM_SPEEDMAX_HIGH ) {
if ( lf->animSpeedScale > ANIM_SCALEMAX_HIGH ) {
lf->animSpeedScale = ANIM_SCALEMAX_HIGH;
}
} else {
lf->animSpeedScale = ANIM_SCALEMAX_HIGH - ( ANIM_SCALEMAX_HIGH - ANIM_SCALEMAX_LOW ) * (float)( anim->moveSpeed - ANIM_SPEEDMAX_HIGH ) / (float)( ANIM_SPEEDMAX_LOW - ANIM_SPEEDMAX_HIGH );
}
} else if ( lf->animSpeedScale > 4.0 ) {
lf->animSpeedScale = 4.0;
}
}
if ( lf == ¢->pe.legs ) {
otherAnim = cent->pe.torso.animation;
} else if ( lf == ¢->pe.torso ) {
otherAnim = cent->pe.legs.animation;
}
// get the next frame based on the animation
if ( !lf->animSpeedScale ) {
// stopped on the ladder, so stay on the same frame
f = lf->frame - anim->firstFrame;
lf->frameTime += anim->frameLerp; // don't wait too long before starting to move again
} else if ( lf->oldAnimationNumber != lf->animationNumber &&
( !anim->moveSpeed || lf->oldFrame < anim->firstFrame || lf->oldFrame >= anim->firstFrame + anim->numFrames ) ) { // Ridah, added this so walking frames don't always get reset to 0, which can happen in the middle of a walking anim, which looks wierd
lf->frameTime = lf->animationTime; // initial lerp
if ( oldAnim && anim->moveSpeed ) { // keep locomotions going continuously
f = ( lf->frame - oldAnim->firstFrame ) + 1;
while ( f < 0 ) {
f += anim->numFrames;
}
} else {
f = 0;
}
} else if ( ( lf == ¢->pe.legs ) && otherAnim && !( anim->flags & ANIMFL_FIRINGANIM ) && ( ( lf->animationNumber & ~ANIM_TOGGLEBIT ) == ( cent->pe.torso.animationNumber & ~ANIM_TOGGLEBIT ) ) && ( !anim->moveSpeed ) ) {
// legs should synch with torso
f = cent->pe.torso.frame - otherAnim->firstFrame;
if ( f >= anim->numFrames || f < 0 ) {
f = 0; // wait at the start for the legs to catch up (assuming they are still in an old anim)
}
lf->frameTime = cent->pe.torso.frameTime;
} else if ( ( lf == ¢->pe.torso ) && otherAnim && !( anim->flags & ANIMFL_FIRINGANIM ) && ( ( lf->animationNumber & ~ANIM_TOGGLEBIT ) == ( cent->pe.legs.animationNumber & ~ANIM_TOGGLEBIT ) ) && ( otherAnim->moveSpeed ) ) {
// torso needs to sync with legs
f = cent->pe.legs.frame - otherAnim->firstFrame;
if ( f >= anim->numFrames || f < 0 ) {
f = 0; // wait at the start for the legs to catch up (assuming they are still in an old anim)
}
lf->frameTime = cent->pe.legs.frameTime;
} else {
#if 0
lf->frameTime = lf->oldFrameTime + (int)( (float)anim->frameLerp * ( 1.0 / lf->animSpeedScale ) );
if ( lf->frameTime < cg.time ) {
lf->frameTime = cg.time;
}
// check for skipping frames (eg. death anims play in slo-mo if low framerate)
if ( cg.time > lf->frameTime && !anim->moveSpeed ) {
f = ( lf->frame - anim->firstFrame ) + 1 + ( cg.time - lf->frameTime ) / anim->frameLerp;
} else {
f = ( lf->frame - anim->firstFrame ) + 1;
}
#else
if ( anim->moveSpeed || lf->frameTime + 1000 < cg.time ) {
lf->frameTime = lf->oldFrameTime + (int)( (float)anim->frameLerp * ( 1.0 / lf->animSpeedScale ) );
f = ( lf->frame - anim->firstFrame ) + 1;
/* if (lf->frameTime < cg.time) {
lf->frameTime = cg.time;
}
*/
while ( lf->frameTime < cg.time ) {
lf->frameTime += (int)( (float)anim->frameLerp * ( 1.0 / lf->animSpeedScale ) );
f++;
while ( f >= anim->numFrames )
f -= anim->numFrames;
}
} else { // skip frames as required
f = lf->frame - anim->firstFrame;
if ( f < 0 ) {
f = 0;
}
while ( lf->frameTime < cg.time ) {
lf->frameTime += (int)anim->frameLerp;
f++; // f is allowed to go over anim->numFrame, since it gets adjusted later
}
}
#endif
if ( f < 0 ) {
f = 0;
}
}
//f = ( lf->frameTime - lf->animationTime ) / anim->frameLerp;
if ( f >= anim->numFrames ) {
f -= anim->numFrames;
if ( anim->loopFrames ) {
f %= anim->loopFrames;
f += anim->numFrames - anim->loopFrames;
} else {
f = anim->numFrames - 1;
// the animation is stuck at the end, so it
// can immediately transition to another sequence
lf->frameTime = cg.time;
}
}
lf->frame = anim->firstFrame + f;
if ( cg.time > lf->frameTime ) {
// disabled, causes bad jolting when oldFrame is updated incorrectly
#if 0
// Ridah, run the frame again until we move ahead of the current time, fixes walking speeds for zombie
if ( recursion > MAX_LERPFRAME_RECURSION ) {
lf->frameTime = cg.time;
} else {
CG_RunLerpFrameRate( ci, lf, newAnimation, cent, recursion + 1 );
}
#endif
lf->frameTime = cg.time;
#if 0
if ( cg_debugAnim.integer ) {
CG_Printf( "Clamp lf->frameTime\n" );
}
#endif
}
lf->oldAnimationNumber = lf->animationNumber;
}
if ( lf->oldFrameTime > cg.time ) {
lf->oldFrameTime = cg.time;
}
// calculate current lerp value
if ( lf->frameTime == lf->oldFrameTime ) {
lf->backlerp = 0;
} else {
lf->backlerp = 1.0 - (float)( cg.time - lf->oldFrameTime ) / ( lf->frameTime - lf->oldFrameTime );
}
}
/*
===============
CG_ClearLerpFrameRate
===============
*/
void CG_ClearLerpFrameRate( clientInfo_t *ci, lerpFrame_t *lf, int animationNumber, centity_t *cent ) {
lf->frameTime = lf->oldFrameTime = cg.time;
CG_SetLerpFrameAnimationRate( cent, ci, lf, animationNumber );
if ( lf->animation ) {
lf->oldFrame = lf->frame = lf->animation->firstFrame;
}
}
// done.
//------------------------------------------------------------------------------
/*
===============
CG_PlayerAnimation
===============
*/
static void CG_PlayerAnimation( centity_t *cent, int *legsOld, int *legs, float *legsBackLerp,
int *torsoOld, int *torso, float *torsoBackLerp ) {
clientInfo_t *ci;
int clientNum;
int animIndex, tempIndex;
clientNum = cent->currentState.clientNum;
if ( cg_noPlayerAnims.integer ) {
*legsOld = *legs = *torsoOld = *torso = 0;
return;
}
ci = &cgs.clientinfo[ clientNum ];
// default to whatever the legs are currently doing
animIndex = cent->currentState.legsAnim;
// do the shuffle turn frames locally
if ( !( cent->currentState.eFlags & ( EF_DEAD | EF_NO_TURN_ANIM ) ) && cent->pe.legs.yawing ) {
//CG_Printf("turn: %i\n", cg.time );
tempIndex = BG_GetAnimScriptAnimation( clientNum, cent->currentState.aiState, ( cent->pe.legs.yawing == SWING_RIGHT ? ANIM_MT_TURNRIGHT : ANIM_MT_TURNLEFT ) );
if ( tempIndex > -1 ) {
animIndex = tempIndex;
}
}
// run the animation
CG_RunLerpFrameRate( ci, ¢->pe.legs, animIndex, cent, 0 );
*legsOld = cent->pe.legs.oldFrame;
*legs = cent->pe.legs.frame;
*legsBackLerp = cent->pe.legs.backlerp;
CG_RunLerpFrameRate( ci, ¢->pe.torso, cent->currentState.torsoAnim, cent, 0 );
*torsoOld = cent->pe.torso.oldFrame;
*torso = cent->pe.torso.frame;
*torsoBackLerp = cent->pe.torso.backlerp;
}
/*
=============================================================================
PLAYER ANGLES
=============================================================================
*/
/*
==================
CG_SwingAngles
==================
*/
static void CG_SwingAngles( float destination, float swingTolerance, float clampTolerance,
float speed, float *angle, qboolean *swinging ) {
float swing;
float move;
float scale;
if ( !*swinging ) {
// see if a swing should be started
swing = AngleSubtract( *angle, destination );
if ( swing > swingTolerance || swing < -swingTolerance ) {
*swinging = qtrue;
}
}
if ( !*swinging ) {
return;
}
// modify the speed depending on the delta
// so it doesn't seem so linear
swing = AngleSubtract( destination, *angle );
scale = fabs( swing );
scale *= 0.05;
if ( scale < 0.5 ) {
scale = 0.5;
}
// swing towards the destination angle
if ( swing >= 0 ) {
move = cg.frametime * scale * speed;
if ( move >= swing ) {
move = swing;
*swinging = qfalse;
} else {
*swinging = SWING_LEFT; // left
}
*angle = AngleMod( *angle + move );
} else if ( swing < 0 ) {
move = cg.frametime * scale * -speed;
if ( move <= swing ) {
move = swing;
*swinging = qfalse;
} else {
*swinging = SWING_RIGHT; // right
}
*angle = AngleMod( *angle + move );
}
// clamp to no more than tolerance
swing = AngleSubtract( destination, *angle );
if ( swing > clampTolerance ) {
*angle = AngleMod( destination - ( clampTolerance - 1 ) );
} else if ( swing < -clampTolerance ) {
*angle = AngleMod( destination + ( clampTolerance - 1 ) );
}
}
/*
=================
CG_AddPainTwitch
=================
*/
static void CG_AddPainTwitch( centity_t *cent, vec3_t torsoAngles ) {
int t;
float f;
int duration;
float direction;
if ( !cent->pe.animSpeed ) {
// we need to inititialize this stuff
cent->pe.painAnimLegs = -1;
cent->pe.painAnimTorso = -1;
cent->pe.animSpeed = 1.0;
}
if ( cent->currentState.eFlags & EF_DEAD ) {
cent->pe.painAnimLegs = -1;
cent->pe.painAnimTorso = -1;
cent->pe.animSpeed = 1.0;
return;
}
// special pain anims for AI
if ( cent->currentState.aiChar ) {
if ( cent->pe.painAnimTorso >= 0 ) {
animation_t *anim;
clientInfo_t *ci;
ci = &cgs.clientinfo[ cent->currentState.number ];
anim = &ci->modelInfo->animations[ cent->pe.painAnimTorso ];
// play the current animation
if ( cent->pe.torso.frame != cent->pe.torso.oldFrame || cent->pe.torso.frame != anim->firstFrame + anim->numFrames - 1 ) {
if ( cent->pe.painAnimLegs >= 0 ) {
cent->currentState.legsAnim = cent->pe.painAnimLegs;
}
cent->currentState.torsoAnim = cent->pe.painAnimTorso;
} else { // end it
cent->pe.painAnimLegs = -1;
cent->pe.painAnimTorso = -1;
cent->pe.animSpeed = 1.0;
}
}
return;
}
if ( cent->pe.painDuration ) {
duration = cent->pe.painDuration;
} else {
duration = PAIN_TWITCH_TIME;
}
direction = (float)duration * 0.085;
if ( direction > 30 ) {
direction = 30;
}
if ( direction < 10 ) {
direction = 10;
}
direction *= (float)( cent->pe.painDirection * 2 ) - 1;
t = cg.time - cent->pe.painTime;
if ( t >= duration ) {
return;
}
if ( cent->currentState.clientNum && cgs.gametype == GT_SINGLE_PLAYER ) {
#define FADEIN_RATIO 0.25
#define FADEOUT_RATIO ( 1.0 - FADEIN_RATIO )
f = (float)t / duration;
if ( f < FADEIN_RATIO ) {
torsoAngles[ROLL] += ( 0.5 * direction * ( f * ( 1.0 / FADEIN_RATIO ) ) );
torsoAngles[PITCH] -= ( fabs( direction ) * ( f * ( 1.0 / FADEIN_RATIO ) ) );
torsoAngles[YAW] += ( direction * ( f * ( 1.0 / FADEIN_RATIO ) ) );
} else {
torsoAngles[ROLL] += ( 0.5 * direction * ( 1.0 - ( f - FADEIN_RATIO ) ) * ( 1.0 / FADEOUT_RATIO ) );
torsoAngles[PITCH] -= ( fabs( direction ) * ( 1.0 - ( f - FADEIN_RATIO ) ) * ( 1.0 / FADEOUT_RATIO ) );
torsoAngles[YAW] += ( direction * ( 1.0 - ( f - FADEIN_RATIO ) ) * ( 1.0 / FADEOUT_RATIO ) );
}
} else { // fast, Q3 style
f = 1.0 - (float)t / duration;
if ( cent->pe.painDirection ) {
torsoAngles[ROLL] += 20 * f;
} else {
torsoAngles[ROLL] -= 20 * f;
}
}
}
/*
================
CG_IdleHeadMovement
================
*/
static void CG_IdleHeadMovement( centity_t *cent, const vec3_t torsoAngles, vec3_t headAngles ) {
const float angleSpeedMax = 60;
const float angleSpeedAccel = 40;
//const float diffThreshold = 50; // don't yaw from torso beyond this in any axis
const float diffRandMax = 30;
const float stopTime = 3000;
int i;
if ( ( cent->currentState.eFlags & EF_DEAD ) || !( cent->currentState.eFlags & EF_HEADLOOK ) ) {
// center
VectorClear( cent->pe.headLookIdeal );
cent->pe.headLookStopTime = 0;
cent->pe.headLookSpeed = 100; // hurry back to normal
} else if ( !cent->pe.headLookSpeedMax && cent->pe.headLookStopTime < cg.time ) {
// need new ideal angles
VectorSet( cent->pe.headLookIdeal,
diffRandMax * ( -0.25 + crandom() ) * 0.25, // pitch
diffRandMax * crandom(), // yaw
0 ); // roll
cent->pe.headLookSpeedMax = angleSpeedMax; // * (0.5 + 0.5*random());
cent->pe.headLookStopTime = cg.time - 1;
}
// move towards ideal position
if ( cent->pe.headLookStopTime < cg.time && !VectorCompare( cent->pe.headLookIdeal, cent->pe.headLookOffset ) ) {
// slow down as we get closer
if ( fabs( cent->pe.headLookOffset[YAW] - cent->pe.headLookIdeal[YAW] ) < angleSpeedMax * 1.2 ) {
cent->pe.headLookSpeedMax = angleSpeedMax * ( 0.1 + 0.9 * ( fabs( cent->pe.headLookOffset[YAW] - cent->pe.headLookIdeal[YAW] ) / ( angleSpeedMax * 1.2 ) ) );
}
// accelerate angle speed
if ( cent->pe.headLookSpeed < cent->pe.headLookSpeedMax ) {
cent->pe.headLookSpeed += angleSpeedAccel * ( 0.001 * cg.frametime );
if ( cent->pe.headLookSpeed > cent->pe.headLookSpeedMax ) {
cent->pe.headLookSpeed = cent->pe.headLookSpeedMax;
}
} else if ( cent->pe.headLookSpeed > cent->pe.headLookSpeedMax ) {
cent->pe.headLookSpeed -= angleSpeedAccel * ( 0.001 * cg.frametime );
if ( cent->pe.headLookSpeed < cent->pe.headLookSpeedMax ) {
cent->pe.headLookSpeed = cent->pe.headLookSpeedMax;
}
}
// move towards the ideal angles
for ( i = 0; i < 3; i++ ) {
if ( cent->pe.headLookOffset[i] < cent->pe.headLookIdeal[i] ) {
cent->pe.headLookOffset[i] += cent->pe.headLookSpeed * 0.001 * cg.frametime;
if ( cent->pe.headLookOffset[i] > cent->pe.headLookIdeal[i] ) {
cent->pe.headLookOffset[i] = cent->pe.headLookIdeal[i];
}
} else if ( cent->pe.headLookOffset[i] > cent->pe.headLookIdeal[i] ) {
cent->pe.headLookOffset[i] -= cent->pe.headLookSpeed * 0.001 * cg.frametime;
if ( cent->pe.headLookOffset[i] < cent->pe.headLookIdeal[i] ) {
cent->pe.headLookOffset[i] = cent->pe.headLookIdeal[i];
}
}
}
// if we made it, stop here for a bit
if ( VectorCompare( cent->pe.headLookIdeal, cent->pe.headLookOffset ) ) {
cent->pe.headLookStopTime = cg.time + (int)( stopTime * ( 0.5 + 0.5 * random() ) );
}
// randomly choose a new destination before reaching ideal angles
if ( cent->pe.headLookStopTime % 2 && rand() % ( cg.time - cent->pe.headLookStopTime ) > 700 ) {
cent->pe.headLookSpeedMax = 0;
}
} else {
cent->pe.headLookSpeedMax = 0;
cent->pe.headLookSpeed = 0; // accelerate when resuming idle movement
}
/*
// make sure these angles don't place us too far from the torso angles
for (i=0; i<3; i++) {
if (fabs(cent->pe.headLookOffset[i] + headAngles[i] - torsoAngles[i]) > diffThreshold) {
if (cent->pe.headLookOffset[i] + headAngles[i] - torsoAngles[i] > 0)
cent->pe.headLookOffset[i] = diffThreshold - (headAngles[i] - torsoAngles[i]);
else
cent->pe.headLookOffset[i] = -diffThreshold - (headAngles[i] - torsoAngles[i]);
}
}
*/
// finally, add the headLookOffset to the head angles
VectorAdd( headAngles, cent->pe.headLookOffset, headAngles );
}
/*
===============
CG_PlayerAngles
Handles seperate torso motion
legs pivot based on direction of movement
head always looks exactly at cent->lerpAngles
if motion < 20 degrees, show in head only
if < 45 degrees, also show in torso
===============
*/
static void CG_PlayerAngles( centity_t *cent, vec3_t legs[3], vec3_t torso[3], vec3_t head[3] ) {
vec3_t legsAngles, torsoAngles, headAngles;
float dest;
// static int movementOffsets[8] = { 0, 22, 45, -22, 0, 22, -45, -22 }; // TTimo: unused
vec3_t velocity;
float speed;
float clampTolerance;
int legsSet;
clientInfo_t *ci;
ci = &cgs.clientinfo[ cent->currentState.number ];
// special case (female zombie while climbing wall)
if ( cent->currentState.eFlags & EF_FORCED_ANGLES ) {
// torso & legs parts should turn to face the given angles
VectorCopy( cent->lerpAngles, legsAngles );
AnglesToAxis( legsAngles, legs );
AnglesToAxis( vec3_origin, torso );
AnglesToAxis( vec3_origin, head );
return;
}
legsSet = cent->currentState.legsAnim & ~ANIM_TOGGLEBIT;
VectorCopy( cent->lerpAngles, headAngles );
headAngles[YAW] = AngleMod( headAngles[YAW] );
VectorClear( legsAngles );
VectorClear( torsoAngles );
// --------- yaw -------------
// allow yaw to drift a bit, unless these conditions don't allow them
if ( !( BG_GetConditionValue( cent->currentState.number, ANIM_COND_MOVETYPE, qfalse ) & ( ( 1 << ANIM_MT_IDLE ) | ( 1 << ANIM_MT_IDLECR ) ) )/*
|| (BG_GetConditionValue( cent->currentState.number, ANIM_COND_MOVETYPE, qfalse ) & ((1<<ANIM_MT_STRAFELEFT) | (1<<ANIM_MT_STRAFERIGHT)) )*/) {
// always point all in the same direction
cent->pe.torso.yawing = qtrue; // always center
cent->pe.torso.pitching = qtrue; // always center
cent->pe.legs.yawing = qtrue; // always center
// if firing, make sure torso and head are always aligned
} else if ( BG_GetConditionValue( cent->currentState.number, ANIM_COND_FIRING, qtrue ) ) {
cent->pe.torso.yawing = qtrue; // always center
cent->pe.torso.pitching = qtrue; // always center
}
// adjust legs for movement dir
if ( cent->currentState.eFlags & EF_DEAD ) {
// don't let dead bodies twitch
legsAngles[YAW] = headAngles[YAW];
torsoAngles[YAW] = headAngles[YAW];
} else {
legsAngles[YAW] = headAngles[YAW] + cent->currentState.angles2[YAW];
if ( cent->currentState.eFlags & EF_NOSWINGANGLES ) {
legsAngles[YAW] = torsoAngles[YAW] = headAngles[YAW]; // always face firing direction
clampTolerance = 40;
} else if ( !( cent->currentState.eFlags & EF_FIRING ) && !( cent->currentState.eFlags & EF_RECENTLY_FIRING ) ) {
torsoAngles[YAW] = headAngles[YAW] + 0.35 * cent->currentState.angles2[YAW];
clampTolerance = 60;
} else { // must be firing
torsoAngles[YAW] = headAngles[YAW]; // always face firing direction
clampTolerance = 40;
}
// torso
if ( !cent->pe.torso.yawing ) {
CG_SwingAngles( torsoAngles[YAW], 30, clampTolerance, 0.5 * cg_swingSpeed.value, ¢->pe.torso.yawAngle, ¢->pe.torso.yawing );
} else if ( !( cent->currentState.eFlags & EF_FIRING ) && !( cent->currentState.eFlags & EF_RECENTLY_FIRING ) ) {
// not firing
CG_SwingAngles( torsoAngles[YAW], 0, clampTolerance, 0.5 * cg_swingSpeed.value, ¢->pe.torso.yawAngle, ¢->pe.torso.yawing );
} else { // firing
CG_SwingAngles( torsoAngles[YAW], 0, clampTolerance, 4.0 * cg_swingSpeed.value, ¢->pe.torso.yawAngle, ¢->pe.torso.yawing );
}
// if the legs are yawing (facing heading direction), allow them to rotate a bit, so we don't keep calling
// the legs_turn animation while an AI is firing, and therefore his angles will be randomizing according to their accuracy
clampTolerance = 90;
if ( BG_GetConditionValue( ci->clientNum, ANIM_COND_MOVETYPE, qfalse ) & ( 1 << ANIM_MT_IDLE ) ) {
if ( cent->pe.legs.yawing ) {
CG_SwingAngles( legsAngles[YAW], 0, clampTolerance, 0.75 * cg_swingSpeed.value, ¢->pe.legs.yawAngle, ¢->pe.legs.yawing );
} else {
cent->pe.legs.yawing = qfalse; // set it if they really need to swing
CG_SwingAngles( legsAngles[YAW], 50, clampTolerance, 0.75 * cg_swingSpeed.value, ¢->pe.legs.yawAngle, ¢->pe.legs.yawing );
}
} else
//if ( BG_GetConditionValue( ci->clientNum, ANIM_COND_MOVETYPE, qfalse ) & ((1<<ANIM_MT_STRAFERIGHT)|(1<<ANIM_MT_STRAFELEFT)) )
if ( strstr( BG_GetAnimString( ci->clientNum, legsSet ), "strafe" ) ) {
cent->pe.legs.yawing = qfalse; // set it if they really need to swing
legsAngles[YAW] = headAngles[YAW];
CG_SwingAngles( legsAngles[YAW], 0, clampTolerance, cg_swingSpeed.value, ¢->pe.legs.yawAngle, ¢->pe.legs.yawing );
} else
if ( cent->pe.legs.yawing ) {
CG_SwingAngles( legsAngles[YAW], 0, clampTolerance, cg_swingSpeed.value, ¢->pe.legs.yawAngle, ¢->pe.legs.yawing );
} else
{
CG_SwingAngles( legsAngles[YAW], 50, clampTolerance, cg_swingSpeed.value, ¢->pe.legs.yawAngle, ¢->pe.legs.yawing );
}
torsoAngles[YAW] = cent->pe.torso.yawAngle;
legsAngles[YAW] = cent->pe.legs.yawAngle;
}
// --------- pitch -------------
// only show a fraction of the pitch angle in the torso
if ( headAngles[PITCH] > 180 ) {
dest = ( -360 + headAngles[PITCH] ) * 0.75;
} else {
dest = headAngles[PITCH] * 0.75;
}
CG_SwingAngles( dest, 15, 30, 0.1, ¢->pe.torso.pitchAngle, ¢->pe.torso.pitching );
torsoAngles[PITCH] = cent->pe.torso.pitchAngle;
// --------- roll -------------
// lean towards the direction of travel
VectorCopy( cent->currentState.pos.trDelta, velocity );
speed = VectorNormalize( velocity );
if ( speed ) {
vec3_t axis[3];
float side;
speed *= 0.05;
AnglesToAxis( legsAngles, axis );
side = speed * DotProduct( velocity, axis[1] );
legsAngles[ROLL] -= side;
side = speed * DotProduct( velocity, axis[0] );
legsAngles[PITCH] += side;
}
// pain twitch
CG_AddPainTwitch( cent, torsoAngles );
// RF, add the head movement if flag is set for looking around
CG_IdleHeadMovement( cent, torsoAngles, headAngles );
// pull the angles back out of the hierarchial chain
AnglesSubtract( headAngles, torsoAngles, headAngles );
AnglesSubtract( torsoAngles, legsAngles, torsoAngles );
AnglesToAxis( legsAngles, legs );
AnglesToAxis( torsoAngles, torso );
AnglesToAxis( headAngles, head );
}
//==========================================================================
/*
===============
CG_HasteTrail
===============
*/
static void CG_HasteTrail( centity_t *cent ) {
localEntity_t *smoke;
vec3_t origin;
if ( cent->trailTime > cg.time ) {
return;
}
cent->trailTime += 100;
if ( cent->trailTime < cg.time ) {
cent->trailTime = cg.time;
}
VectorCopy( cent->lerpOrigin, origin );
origin[2] -= 16;
smoke = CG_SmokePuff( origin, vec3_origin,
8,
1, 1, 1, 1,
500,
cg.time,
0,
0,
cgs.media.hastePuffShader );
// use the optimized local entity add
smoke->leType = LE_SCALE_FADE;
}
//----(SA) added and modified from missionpack
/*
===============
CG_BreathPuffs
===============
*/
static void CG_BreathPuffs( centity_t *cent, refEntity_t *head ) {
clientInfo_t *ci;
vec3_t up, forward;
int contents;
vec3_t mang, morg, maxis[3]; //, mang;
ci = &cgs.clientinfo[ cent->currentState.number ];
if ( !cg_enableBreath.integer ) {
return;
}
if ( cent->currentState.number == cg.snap->ps.clientNum && !cg.renderingThirdPerson ) {
return;
}
if ( cent->currentState.eFlags & EF_DEAD ) {
return;
}
// allow cg_enableBreath to force everyone to have breath
if ( cg_enableBreath.integer == 1 ) {
if ( !( cent->currentState.eFlags & EF_BREATH ) ) {
return;
}
}
contents = CG_PointContents( head->origin, 0 );
if ( contents & ( CONTENTS_WATER | CONTENTS_SLIME | CONTENTS_LAVA ) ) {
return;
}
if ( ci->breathPuffTime > cg.time ) {
return;
}
CG_GetOriginForTag( cent, head, "tag_mouth", 0, morg, maxis );
AxisToAngles( maxis, mang );
AngleVectors( mang, forward, NULL, up );
//push the origin out a tad so it's not right in the guys face (tad==4)
VectorMA( morg, 4, forward, morg );
forward[0] = up[0] * 8 + forward[0] * 5;
forward[1] = up[1] * 8 + forward[1] * 5;
forward[2] = up[2] * 8 + forward[2] * 5;
CG_SmokePuff( morg, forward, 4, 1, 1, 1, 0.5f, 2000, cg.time, cg.time + 400, 0, cgs.media.shotgunSmokePuffShader );
ci->breathPuffTime = cg.time + 3000 + random() * 1000;
}
//----(SA) end
/*
===============
CG_TrailItem
===============
*/
static void CG_TrailItem( centity_t *cent, qhandle_t hModel ) {
refEntity_t ent;
vec3_t angles;
vec3_t axis[3];
VectorCopy( cent->lerpAngles, angles );
angles[PITCH] = 0;
angles[ROLL] = 0;
AnglesToAxis( angles, axis );
memset( &ent, 0, sizeof( ent ) );
// DHM - Nerve :: adjusted values
VectorMA( cent->lerpOrigin, -4, axis[0], ent.origin );
ent.origin[2] += 36;
VectorScale( cg.autoAxis[0], 0.75, ent.axis[0] );
VectorScale( cg.autoAxis[1], 0.75, ent.axis[1] );
VectorScale( cg.autoAxis[2], 0.75, ent.axis[2] );
ent.hModel = hModel;
trap_R_AddRefEntityToScene( &ent );
}
/*
===============
CG_PlayerPowerups
===============
*/
static void CG_PlayerPowerups( centity_t *cent ) {
int powerups;
if ( cent->pe.teslaDamagedTime > cg.time - 400 ) {
trap_R_AddLightToScene( cent->lerpOrigin, 128 + 128 * sin( cg.time * cg.time ), 0.2, 0.6, 1, 0 );
}
// RF, AI don't use these effects, they are generally added manually by the game
if ( cent->currentState.aiChar ) {
return;
}
//----(SA) test stuff leave in, but comment out
// if(cg_forceModel.integer) {
// vec3_t orig, forward, li;
// trace_t trace;
//
// AngleVectors(cg.refdefViewAngles, forward, NULL, NULL);
// VectorNormalize(forward); // just in case
// VectorCopy(cent->lerpOrigin, orig);
// orig[2]+=cg.predictedPlayerState.viewheight;
// VectorMA(orig, 1000, forward, li);
// CG_Trace(&trace, orig, NULL, NULL, li, -1, MASK_SHOT);
// VectorMA(trace.endpos, -5, forward, li);
// trap_R_AddLightToScene( li, 100 + 100*trace.fraction, 1, 1, 1, 1 );
// }
//----(SA) end
powerups = cent->currentState.powerups;
if ( !powerups ) {
return;
}
// quad gives a dlight
if ( powerups & ( 1 << PW_QUAD ) ) {
trap_R_AddLightToScene( cent->lerpOrigin, 200 + ( rand() & 31 ), 0.2, 0.2, 1, 0 );
}
// flight plays a looped sound
// if ( powerups & ( 1 << PW_FLIGHT ) ) {
// CG_S_AddLoopingSound( cent->currentState.number, cent->lerpOrigin, vec3_origin, cgs.media.flightSound, 255 );
// }
// redflag
if ( powerups & ( 1 << PW_REDFLAG ) ) {
CG_TrailItem( cent, cgs.media.redFlagModel );
trap_R_AddLightToScene( cent->lerpOrigin, 200 + ( rand() & 31 ), 1, 0.2, 0.2, 0 );
}
// blueflag
if ( powerups & ( 1 << PW_BLUEFLAG ) ) {
CG_TrailItem( cent, cgs.media.blueFlagModel );
trap_R_AddLightToScene( cent->lerpOrigin, 200 + ( rand() & 31 ), 0.2, 0.2, 1, 0 );
}
// haste leaves smoke trails
if ( powerups & ( 1 << PW_HASTE ) ) {
CG_HasteTrail( cent );
}
}
/*
===============
CG_PlayerFloatSprite
Float a sprite over the player's head
DHM - Nerve :: added height parameter
===============
*/
static void CG_PlayerFloatSprite( centity_t *cent, qhandle_t shader, int height ) {
int rf;
refEntity_t ent;
if ( cent->currentState.number == cg.snap->ps.clientNum && !cg.renderingThirdPerson ) {
rf = RF_THIRD_PERSON; // only show in mirrors
} else {
rf = 0;
}
memset( &ent, 0, sizeof( ent ) );
VectorCopy( cent->lerpOrigin, ent.origin );
ent.origin[2] += height; // DHM - Nerve :: was '48'
ent.reType = RT_SPRITE;
ent.customShader = shader;
ent.radius = 10;
ent.renderfx = rf;
ent.shaderRGBA[0] = 255;
ent.shaderRGBA[1] = 255;
ent.shaderRGBA[2] = 255;
ent.shaderRGBA[3] = 255;
trap_R_AddRefEntityToScene( &ent );
}
/*
===============
CG_PlayerSprites
Float sprites over the player's head
===============
*/
static void CG_PlayerSprites( centity_t *cent ) {
int team;
if ( cg_showAIState.integer && cent->currentState.aiChar ) {
CG_PlayerFloatSprite( cent, cgs.media.aiStateShaders[cent->currentState.aiState], 48 );
return;
}
if ( cent->currentState.eFlags & EF_CONNECTION ) {
CG_PlayerFloatSprite( cent, cgs.media.connectionShader, 48 );
return;
}
team = cgs.clientinfo[ cent->currentState.clientNum ].team;
// DHM - Nerve :: If this client is a medic, draw a 'revive' icon over
// dead players that are not in limbo yet.
if ( cgs.gametype == GT_WOLF && ( cent->currentState.eFlags & EF_DEAD )
&& cent->currentState.number == cent->currentState.clientNum
&& cg.snap->ps.stats[ STAT_PLAYER_CLASS ] == PC_MEDIC
&& cg.snap->ps.persistant[PERS_TEAM] == team ) {
// CG_PlayerFloatSprite( cent, cgs.media.medicReviveShader, 8 ); //----(SA) commented out from MP
return;
}
// DHM - Nerve :: not using, gives away position if chatting to coordinate attack
// if ( cent->currentState.eFlags & EF_TALK ) {
// CG_PlayerFloatSprite( cent, cgs.media.balloonShader, 48 );
// return;
// }
//----(SA) commented out
// if ( cent->currentState.eFlags & EF_AWARD_IMPRESSIVE ) {
// CG_PlayerFloatSprite( cent, cgs.media.medalImpressive, 48 );
// return;
// }
//----(SA) commented out
// if ( cent->currentState.eFlags & EF_AWARD_EXCELLENT ) {
// CG_PlayerFloatSprite( cent, cgs.media.medalExcellent, 48 );
// return;
// }
//----(SA) commented out
// if ( cent->currentState.eFlags & EF_AWARD_GAUNTLET ) {
// CG_PlayerFloatSprite( cent, cgs.media.medalGauntlet, 48 );
// return;
// }
// DHM - Nerve :: Not using friendly sprites in GT_WOLF
if ( cgs.gametype != GT_WOLF && cgs.gametype >= GT_TEAM &&
!( cent->currentState.eFlags & EF_DEAD ) &&
cg.snap->ps.persistant[PERS_TEAM] == team ) {
CG_PlayerFloatSprite( cent, cgs.media.friendShader, 48 );
return;
}
}
/*
===============
CG_PlayerShadow
Returns the Z component of the surface being shadowed
should it return a full plane instead of a Z?
===============
*/
#define SHADOW_DISTANCE 64
#define ZOFS 6.0
#define SHADOW_MIN_DIST 250.0
#define SHADOW_MAX_DIST 512.0
typedef struct {
char *tagname;
float size;
float maxdist;
float maxalpha;
qhandle_t shader;
} shadowPart_t;
static qboolean CG_PlayerShadow( centity_t *cent, float *shadowPlane ) {
vec3_t end;
trace_t trace;
float alpha, dist, distfade, scale, dot;
int tagIndex, subIndex;
vec3_t origin, angles, axis[3];
shadowPart_t shadowParts[] = {
{"tag_footleft", 10, 4, 0.5, 0},
{"tag_footright", 10, 4, 0.5, 0},
{"tag_torso", 18, 96, 0.4, 0},
{NULL, 0}
};
shadowParts[0].shader = cgs.media.shadowFootShader; //DAJ pulled out of initliization
shadowParts[1].shader = cgs.media.shadowFootShader;
shadowParts[2].shader = cgs.media.shadowTorsoShader;
*shadowPlane = 0;
if ( cg_shadows.integer == 0 ) {
return qfalse;
}
// no shadows when invisible
if ( cent->currentState.powerups & ( 1 << PW_INVIS ) ) {
return qfalse;
}
// send a trace down from the player to the ground
VectorCopy( cent->lerpOrigin, end );
end[2] -= SHADOW_DISTANCE;
trap_CM_BoxTrace( &trace, cent->lerpOrigin, end, NULL, NULL, 0, MASK_PLAYERSOLID );
// no shadow if too high
if ( trace.fraction == 1.0 ) {
return qfalse;
}
*shadowPlane = trace.endpos[2] + 1;
if ( cg_shadows.integer != 1 ) { // no mark for stencil or projection shadows
return qtrue;
}
// no shadows when dead
if ( cent->currentState.eFlags & EF_DEAD ) {
return qfalse;
}
if ( cg.snap && cent->currentState.number != cg.snap->ps.clientNum ) {
// scale shadow according to bounding box size
scale = ( cent->currentState.solid & 255 );
scale /= 18.0;
} else {
scale = 1.0;
}
// fade the shadow out with height
alpha = 1.0 - trace.fraction;
// if zooming, dont draw shadows if we're not looking in their direction
if ( cg.predictedPlayerState.eFlags & EF_ZOOMING ) {
VectorSubtract( cent->lerpOrigin, cg.refdef.vieworg, end );
VectorNormalize( end );
dot = DotProduct( cg.refdef.viewaxis[0], end );
if ( dot < 0.96 ) {
return qfalse;
} else if ( dot < 0.98 ) {
alpha *= ( dot - 0.94 ) / ( 0.97 - 0.94 );
}
}
// if the torso is below the ground, dont draw shadows
if ( CG_GetOriginForTag( cent, ¢->pe.legsRefEnt, "tag_torso", 0, origin, axis ) ) {
if ( origin[2] - cent->lerpOrigin[2] < -26 ) {
return qfalse;
}
}
// add the mark as a temporary, so it goes directly to the renderer
// without taking a spot in the cg_marks array
dist = VectorDistance( cent->lerpOrigin, cg.refdef.vieworg );
if ( dist > SHADOW_MIN_DIST ) {
if ( dist < SHADOW_MAX_DIST ) {
distfade = ( dist - SHADOW_MIN_DIST ) / ( SHADOW_MAX_DIST - SHADOW_MIN_DIST );
} else {
if ( dist > SHADOW_MAX_DIST * 2 ) {
return qfalse;
} else { // fade out
distfade = 1.0 - ( ( dist - SHADOW_MAX_DIST ) / SHADOW_MAX_DIST );
}
}
alpha *= distfade;
CG_ImpactMark( cgs.media.shadowTorsoShader, trace.endpos, trace.plane.normal,
0, alpha,alpha,alpha,1, qfalse, 18 * scale, qtrue, -1 );
} else {
distfade = 0.0;
}
if ( dist < SHADOW_MAX_DIST ) { // show more detail
// now add shadows for the various body parts
for ( tagIndex = 0; shadowParts[tagIndex].tagname; tagIndex++ ) {
// grab each tag with this name
for ( subIndex = 0; ( subIndex = CG_GetOriginForTag( cent, ¢->pe.legsRefEnt, shadowParts[tagIndex].tagname, subIndex, origin, axis ) ) >= 0; subIndex++ ) {
// move the shadow center forward
VectorMA( origin, 4, axis[0], origin );
// project it onto the shadow plane
if ( origin[2] < *shadowPlane ) {
origin[2] = *shadowPlane;
}
alpha = 1.0 - ( ( origin[2] - ( *shadowPlane + ZOFS ) ) / shadowParts[tagIndex].maxdist );
if ( alpha < 0 ) {
continue;
}
if ( alpha > shadowParts[tagIndex].maxalpha ) {
alpha = shadowParts[tagIndex].maxalpha;
}
alpha *= ( 1.0 - distfade );
origin[2] = *shadowPlane;
AxisToAngles( axis, angles );
CG_ImpactMark( shadowParts[tagIndex].shader, origin, trace.plane.normal,
angles[YAW] /*cent->pe.legs.yawAngle*/, alpha,alpha,alpha,1, qfalse, shadowParts[tagIndex].size * scale, qtrue, -1 );
}
}
}
return qtrue;
}
/*
===============
CG_PlayerSplash
Draw a mark at the water surface
===============
*/
static void CG_PlayerSplash( centity_t *cent ) {
vec3_t start, end;
trace_t trace;
int contents;
polyVert_t verts[4];
if ( !cg_shadows.integer ) {
return;
}
VectorCopy( cent->lerpOrigin, end );
end[2] -= 24;
// if the feet aren't in liquid, don't make a mark
// this won't handle moving water brushes, but they wouldn't draw right anyway...
contents = CG_PointContents( end, 0 );
if ( !( contents & ( CONTENTS_WATER | CONTENTS_SLIME | CONTENTS_LAVA ) ) ) {
return;
}
VectorCopy( cent->lerpOrigin, start );
start[2] += 32;
// if the head isn't out of liquid, don't make a mark
contents = CG_PointContents( start, 0 );
if ( contents & ( CONTENTS_SOLID | CONTENTS_WATER | CONTENTS_SLIME | CONTENTS_LAVA ) ) {
return;
}
// trace down to find the surface
trap_CM_BoxTrace( &trace, start, end, NULL, NULL, 0, ( CONTENTS_WATER | CONTENTS_SLIME | CONTENTS_LAVA ) );
if ( trace.fraction == 1.0 ) {
return;
}
// create a mark polygon
VectorCopy( trace.endpos, verts[0].xyz );
verts[0].xyz[0] -= 32;
verts[0].xyz[1] -= 32;
verts[0].st[0] = 0;
verts[0].st[1] = 0;
verts[0].modulate[0] = 255;
verts[0].modulate[1] = 255;
verts[0].modulate[2] = 255;
verts[0].modulate[3] = 255;
VectorCopy( trace.endpos, verts[1].xyz );
verts[1].xyz[0] -= 32;
verts[1].xyz[1] += 32;
verts[1].st[0] = 0;
verts[1].st[1] = 1;
verts[1].modulate[0] = 255;
verts[1].modulate[1] = 255;
verts[1].modulate[2] = 255;
verts[1].modulate[3] = 255;
VectorCopy( trace.endpos, verts[2].xyz );
verts[2].xyz[0] += 32;
verts[2].xyz[1] += 32;
verts[2].st[0] = 1;
verts[2].st[1] = 1;
verts[2].modulate[0] = 255;
verts[2].modulate[1] = 255;
verts[2].modulate[2] = 255;
verts[2].modulate[3] = 255;
VectorCopy( trace.endpos, verts[3].xyz );
verts[3].xyz[0] += 32;
verts[3].xyz[1] -= 32;
verts[3].st[0] = 1;
verts[3].st[1] = 0;
verts[3].modulate[0] = 255;
verts[3].modulate[1] = 255;
verts[3].modulate[2] = 255;
verts[3].modulate[3] = 255;
trap_R_AddPolyToScene( cgs.media.wakeMarkShader, 4, verts );
}
//==========================================================================
// Zombie Effects
/*
==============
CG_SpawnZombieSpirit
==============
*/
void CG_SpawnZombieSpirit( vec3_t origin, vec3_t vel, int trailHead, int ownerNum, refEntity_t *oldrefent, int trailLife, int idealWidth ) {
localEntity_t *le;
refEntity_t *re;
le = CG_AllocLocalEntity();
re = &le->refEntity;
*re = *oldrefent;
le->leType = LE_ZOMBIE_SPIRIT;
le->startTime = cg.time - 5000; // set it back so we dont fade it in like the "end" spirits
le->endTime = cg.time + 5000;
le->pos.trType = TR_LINEAR;
le->pos.trTime = cg.time;
VectorCopy( origin, le->pos.trBase );
VectorCopy( vel, le->pos.trDelta );
le->effectWidth = trailLife;
le->radius = idealWidth;
le->lastTrailTime = cg.time;
le->headJuncIndex = trailHead;
le->loopingSound = cgs.media.zombieSpiritLoopSound;
le->ownerNum = ownerNum;
re->fadeStartTime = le->endTime - 2000;
re->fadeEndTime = le->endTime;
}
/*
==============
CG_AddZombieSpiritEffect
==============
*/
void CG_AddZombieSpiritEffect( centity_t *cent ) {
const int trailLife = 600;
const float idealWidth = 14.0;
const int fadeInTime = 1200;
const int fadeOutTime = 2000;
const int minRotationTime = 3000;
const int maxRotationTime = 4000;
const int minRadiusCycleTime = 2400;
const int maxRadiusCycleTime = 2900;
const int zCycleTime = 3000;
const float minDist = 16;
const float maxDist = 40;
const float fadeDist = 4;
const int sndIntervalMin = 300;
const int sndIntervalMax = 1400;
const int sndDelay = 0;
//const int sndDuration = 99999;//1500; // TTimo: init
const int step = 50;
int i, t;
vec3_t v,p[MAX_ZOMBIE_SPIRITS], ang;
float fadeRatio, alpha, radius;
int rotationTime, radiusCycleTime;
trace_t trace;
refEntity_t refent;
qboolean active = qfalse;
static int lastSpiritRelease;
if ( cent->currentState.aiChar != AICHAR_ZOMBIE ) {
return;
}
// sanity check the server time to make sure we don't start the effect
// to early, whilst reloading a savegame or something
if ( cg.time < cent->currentState.effect1Time ) {
return;
}
if ( cent->currentState.eFlags & EF_MONSTER_EFFECT ) {
if ( !cent->pe.cueZombieSpirit ) {
// starting a new effect
cent->pe.cueZombieSpirit = qtrue;
cent->pe.zombieSpiritStartTime = cent->currentState.effect1Time;
cent->pe.lastZombieSpirit = cg.time;
cent->pe.nextZombieSpiritSound = cg.time + sndDelay;
for ( i = 0; i < MAX_ZOMBIE_SPIRITS; i++ ) {
cent->pe.zombieSpiritTrailHead[i] = -1;
cent->pe.zombieSpiritRotationTimes[i] = minRotationTime + ( random() * ( maxRotationTime - minRotationTime ) );
cent->pe.zombieSpiritRadiusCycleTimes[i] = minRadiusCycleTime + ( random() * ( maxRadiusCycleTime - minRadiusCycleTime ) );
cent->pe.zombieSpiritStartTimes[i] = cent->currentState.effect1Time;
}
}
cent->pe.zombieSpiritEndTime = cg.time;
} else {
// if running another effect, dont mess with its variables
if ( cent->currentState.eFlags & EF_MONSTER_EFFECT3 || cent->currentState.effect1Time < cent->currentState.effect3Time ) {
return;
}
if ( !cent->pe.zombieSpiritEndTime ) {
return;
}
// clear the flag, and let the effect fade itself out
cent->pe.cueZombieSpirit = qfalse;
}
for ( t = cent->pe.lastZombieSpirit + step; t <= cg.time; t += step ) {
// add the spirits
for ( i = 0; i < MAX_ZOMBIE_SPIRITS; i++ ) {
if ( cent->pe.zombieSpiritTrailHead[i] < -1 ) {
// spirit has gone, create a new one
cent->pe.zombieSpiritTrailHead[i] = -1;
cent->pe.zombieSpiritRotationTimes[i] = minRotationTime + ( random() * ( maxRotationTime - minRotationTime ) );
cent->pe.zombieSpiritRadiusCycleTimes[i] = minRadiusCycleTime + ( random() * ( maxRadiusCycleTime - minRadiusCycleTime ) );
cent->pe.zombieSpiritStartTimes[i] = cg.time - step;
}
fadeRatio = (float)( cg.time - cent->pe.zombieSpiritStartTimes[i] ) / (float)fadeInTime;
if ( fadeRatio < 0.0 ) {
fadeRatio = 0.0;
}
if ( fadeRatio > 1.0 ) {
fadeRatio = 1.0;
}
if ( cent->pe.cueZombieSpirit ) {
alpha = fadeRatio;
} else {
alpha = 1.0 - ( (float)( cg.time - cent->pe.zombieSpiritEndTime ) / (float)fadeOutTime );
fadeRatio = alpha;
if ( alpha < 0.0 ) {
cent->pe.zombieSpiritTrailHead[i] = -2; // kill it
continue;
}
}
active = qtrue; // we have an active spirit, so continue effect
alpha *= 0.3;
if ( cent->pe.cueZombieSpirit ) {
rotationTime = cent->pe.zombieSpiritRotationTimes[i];
radiusCycleTime = cent->pe.zombieSpiritRadiusCycleTimes[i];
radius = ( minDist + sin( M_PI * 2 * (float)( (float)( (int)( t + ( (float)( radiusCycleTime * i ) / MAX_ZOMBIE_SPIRITS ) ) % radiusCycleTime ) / (float)radiusCycleTime ) ) * ( maxDist - minDist ) );
// get the position
v[0] = ( 0.5 + 0.5 * fadeRatio ) * sin( M_PI * 2 * (float)( (float)( (int)( t + ( (float)( rotationTime * i ) / MAX_ZOMBIE_SPIRITS ) ) % rotationTime ) / (float)rotationTime ) ) * radius;
v[1] = ( 0.5 + 0.5 * fadeRatio ) * cos( M_PI * 2 * (float)( (float)( (int)( t + ( (float)( rotationTime * i ) / MAX_ZOMBIE_SPIRITS ) ) % rotationTime ) / (float)rotationTime ) ) * radius;
v[2] = 12 + 36 * ( 0.5 + 0.5 * fadeRatio ) * sin( M_PI * 2 * (float)( (float)( (int)( t + ( (float)( zCycleTime * i ) / MAX_ZOMBIE_SPIRITS ) ) % zCycleTime ) / (float)zCycleTime ) );
v[2] -= ( 1.0 - fadeRatio ) * 32;
VectorAdd( cent->lerpOrigin, v, p[i] );
} else {
// expand the radius, if it enters world geometry, kill it
rotationTime = cent->pe.zombieSpiritRotationTimes[i];
radiusCycleTime = cent->pe.zombieSpiritRadiusCycleTimes[i];
radius = pow( 1.0 - fadeRatio, 2 ) * fadeDist + ( 1.0 - pow( 1.0 - fadeRatio, 2 ) ) * ( minDist + sin( M_PI * 2 * (float)( (float)( (int)( t + ( (float)( radiusCycleTime * i ) / MAX_ZOMBIE_SPIRITS ) ) % radiusCycleTime ) / (float)radiusCycleTime ) ) * ( maxDist - minDist ) );
// get the position
v[0] = sin( M_PI * 2 * (float)( (float)( (int)( t + ( (float)( rotationTime * i ) / MAX_ZOMBIE_SPIRITS ) ) % rotationTime ) / (float)rotationTime ) ) * radius;
v[1] = cos( M_PI * 2 * (float)( (float)( (int)( t + ( (float)( rotationTime * i ) / MAX_ZOMBIE_SPIRITS ) ) % rotationTime ) / (float)rotationTime ) ) * radius;
v[2] = 12 + 36 * sin( M_PI * 2 * (float)( (float)( (int)( t + ( (float)( zCycleTime * i ) / MAX_ZOMBIE_SPIRITS ) ) % zCycleTime ) / (float)zCycleTime ) );
v[2] -= ( 1.0 - fadeRatio ) * 32;
VectorAdd( cent->lerpOrigin, v, p[i] );
// check for sinking into geometry
trap_CM_BoxTrace( &trace, p[i], p[i], NULL, NULL, 0, MASK_SOLID );
// if we hit something, clip the velocity, but maintain speed
if ( trace.startsolid ) {
cent->pe.zombieSpiritTrailHead[i] = -2; // kill it
continue;
}
}
VectorSubtract( p[i], cent->pe.zombieSpiritPos[i], cent->pe.zombieSpiritDir[i] );
cent->pe.zombieSpiritSpeed[i] = 1000.0 / step * VectorNormalize( cent->pe.zombieSpiritDir[i] );
VectorCopy( p[i], cent->pe.zombieSpiritPos[i] );
cent->pe.zombieSpiritTrailHead[i] = CG_AddTrailJunc( cent->pe.zombieSpiritTrailHead[i],
cgs.media.zombieSpiritTrailShader,
t,
STYPE_STRETCH,
p[i],
trailLife * 2,
alpha,
0.0,
( 0.5 + 0.5 * fadeRatio ) * idealWidth,
0,
TJFL_NOCULL,
colorWhite,
colorWhite,
1.0, 1 );
}
cent->pe.lastZombieSpirit = t;
if ( !active ) { // effect has gone
cent->pe.zombieSpiritEndTime = 0;
}
}
// add the skull at the head of the spirits
memset( &refent, 0, sizeof( refent ) );
refent.hModel = cgs.media.spiritSkullModel;
refent.backlerp = 0;
refent.renderfx = RF_NOSHADOW | RF_MINLIGHT; //----(SA)
refent.customShader = cgs.media.zombieSpiritSkullShader;
refent.reType = RT_MODEL;
for ( i = 0; i < MAX_ZOMBIE_SPIRITS; i++ ) {
if ( cent->pe.zombieSpiritTrailHead[i] < -1 ) {
continue; // spirit has gone
}
fadeRatio = (float)( cg.time - cent->pe.zombieSpiritStartTimes[i] ) / (float)fadeInTime;
if ( fadeRatio < 0.0 ) {
fadeRatio = 0.0;
}
if ( fadeRatio > 1.0 ) {
fadeRatio = 1.0;
}
if ( cent->pe.cueZombieSpirit ) {
alpha = fadeRatio;
} else {
alpha = 1.0 - ( (float)( cg.time - cent->pe.zombieSpiritEndTime ) / (float)fadeOutTime );
fadeRatio = alpha;
if ( alpha < 0.0 ) {
cent->pe.zombieSpiritTrailHead[i] = -2; // kill it
continue;
}
}
refent.shaderRGBA[3] = (byte)( 0.5 * alpha * 255.0 );
VectorCopy( cent->pe.zombieSpiritPos[i], refent.origin );
// HACK!!! skull model is back-to-front, need to fix
VectorInverse( cent->pe.zombieSpiritDir[i] );
vectoangles( cent->pe.zombieSpiritDir[i], ang );
VectorInverse( cent->pe.zombieSpiritDir[i] );
AnglesToAxis( ang, refent.axis );
// create the non-normalized axis so we can size it
refent.nonNormalizedAxes = qtrue;
for ( t = 0; t < 3; t++ ) {
VectorNormalize( refent.axis[t] );
VectorScale( refent.axis[t], 0.35, refent.axis[t] );
}
//
// add the sound
CG_S_AddLoopingSound( cent->currentState.number, cent->lerpOrigin, vec3_origin, cgs.media.zombieSpiritLoopSound, fadeRatio );
//
// if this spirit is in a good position to be released and head to the enemy, then release it
if ( fadeRatio == 1.0 && ( lastSpiritRelease > cg.time || ( lastSpiritRelease < cg.time - 2000 ) ) ) {
VectorSubtract( cent->currentState.origin2, refent.origin, v );
VectorNormalize( v );
if ( DotProduct( cent->pe.zombieSpiritDir[i], v ) > 0.6 || ( cent->currentState.eFlags & EF_DEAD ) ) {
// check for sinking into geometry
trap_CM_BoxTrace( &trace, refent.origin, refent.origin, NULL, NULL, 0, MASK_SOLID );
// if we hit something, don't release it yet
if ( !trace.startsolid ) {
if ( cent->pe.zombieSpiritSpeed[i] < 300 ) {
cent->pe.zombieSpiritSpeed[i] = 300;
}
VectorScale( cent->pe.zombieSpiritDir[i], cent->pe.zombieSpiritSpeed[i], v );
CG_SpawnZombieSpirit( refent.origin, v, cent->pe.zombieSpiritTrailHead[i], cent->currentState.number, &refent, trailLife, idealWidth );
lastSpiritRelease = cg.time;
cent->pe.zombieSpiritTrailHead[i] = -2; // kill this version of it
continue;
}
}
}
//
// if we didn't kill it, draw it
trap_R_AddRefEntityToScene( &refent );
}
if ( cg.time > cent->pe.nextZombieSpiritSound && cent->pe.cueZombieSpirit ) { //&& (cg.time < cent->pe.zombieSpiritStartTime + sndDuration)) {
// spawn a new sound
trap_S_StartSound( cent->lerpOrigin, -1, CHAN_AUTO, cgs.media.zombieSpiritSound );
cent->pe.nextZombieSpiritSound = cg.time + sndIntervalMin + (int)( (float)( sndIntervalMax - sndIntervalMin ) * random() );
}
// add a negative light around us
fadeRatio = (float)( cg.time - cent->pe.zombieSpiritStartTime ) / (float)fadeInTime;
if ( fadeRatio < 0.0 ) {
fadeRatio = 0.0;
}
if ( fadeRatio > 1.0 ) {
fadeRatio = 1.0;
}
if ( !cent->pe.cueZombieSpirit ) {
alpha = 1.0 - ( (float)( cg.time - cent->pe.zombieSpiritEndTime ) / (float)fadeOutTime );
fadeRatio = alpha;
if ( alpha < 0.0 ) {
cent->pe.zombieSpiritEndTime = 0; // stop the effect
return;
}
}
fadeRatio *= 0.7;
trap_R_AddLightToScene( cent->lerpOrigin, 300.0, 1.0 * fadeRatio, 1.0 * fadeRatio, 1.0 * fadeRatio, 10 );
}
/*
==============
CG_SpawnZombieBat
==============
*/
void CG_SpawnZombieBat( centity_t *cent, refEntity_t *oldrefent ) {
localEntity_t *le;
refEntity_t *re;
le = CG_AllocLocalEntity();
re = &le->refEntity;
*re = *oldrefent;
le->leType = LE_ZOMBIE_BAT;
le->startTime = cg.time;
le->endTime = le->startTime + 6000; // TODO: some kind of effect when the bat "burns up"
le->pos.trType = TR_LINEAR;
le->pos.trTime = cg.time;
CG_PositionEntityOnTag( re, ¢->pe.headRefEnt, "tag_mouth", 0, NULL );
VectorCopy( re->origin, le->pos.trBase );
VectorScale( re->axis[0], 150 + 50 * random(), le->pos.trDelta );
//le->effectWidth = trailLife;
//le->radius = idealWidth;
le->lastTrailTime = cg.time;
//le->headJuncIndex = trailHead;
le->loopingSound = cgs.media.batsFlyingLoopSound;
le->ownerNum = cent->currentState.number;
re->fadeStartTime = le->endTime - 2000;
re->fadeEndTime = le->endTime;
}
/*
==============
CG_AddZombieFlameEffect
==============
*/
void CG_AddZombieFlameEffect( centity_t *cent ) {
//const float flameRadius = ZOMBIE_FLAME_RADIUS*2; // TTimo: unused
const int fadeInTime = 500;
const int fadeOutTime = 0;
// TTimo: unused
/*
const int spawnIntervalMin = 300;
const int spawnIntervalMax = 1200;
const int sndIntervalMin = 300;
const int sndIntervalMax = 1400;
*/
const int sndDelay = 0;
// const int sndDuration = 99999; // TTimo: unused
// const int step = 50; // TTimo: unused
vec3_t morg, maxis[3], mang;
float alpha, fadeRatio;
// qboolean active=qfalse; // TTimo: unused
if ( cent->currentState.aiChar != AICHAR_ZOMBIE ) {
return;
}
if ( cent->currentState.eFlags & EF_DEAD ) {
return;
}
if ( !IS_FLAMING_ZOMBIE( cent->currentState ) ) {
return;
}
if ( cent->currentState.time > cg.time ) { // doing short burst
return;
}
if ( ( cent->currentState.eFlags & EF_MONSTER_EFFECT3 ) && ( cg.time > cent->currentState.effect3Time ) ) {
if ( !cent->pe.cueZombieSpirit ) {
// starting a new effect
cent->pe.cueZombieSpirit = qtrue;
cent->pe.zombieSpiritStartTime = cent->currentState.effect3Time;
cent->pe.lastZombieSpirit = cg.time;
cent->pe.nextZombieSpiritSound = cg.time + sndDelay;
}
cent->pe.zombieSpiritEndTime = cg.time + fadeOutTime;
} else {
// if running another effect, dont mess with its variables
if ( cent->currentState.eFlags & EF_MONSTER_EFFECT || cent->currentState.effect1Time > cent->currentState.effect3Time ) {
CG_FireFlameChunks( cent, morg, mang, 0.05, qfalse, 0 );
return;
}
if ( cent->pe.zombieSpiritEndTime < cg.time ) {
CG_FireFlameChunks( cent, morg, mang, 0.05, qfalse, 0 );
return;
}
// clear the flag, and let the effect fade itself out
cent->pe.cueZombieSpirit = qfalse;
}
// expand the flame dlight
fadeRatio = (float)( cg.time - cent->pe.zombieSpiritStartTime ) / (float)fadeInTime;
if ( fadeRatio < 0.0 ) {
fadeRatio = 0.0;
}
if ( fadeRatio > 1.0 ) {
fadeRatio = 1.0;
}
if ( !cent->pe.cueZombieSpirit ) {
alpha = ( (float)( cent->pe.zombieSpiritEndTime - cg.time ) / (float)fadeOutTime );
fadeRatio = alpha;
if ( alpha < 0.0 ) {
cent->pe.zombieSpiritEndTime = 0; // stop the effect
CG_FireFlameChunks( cent, morg, mang, 0.1, qfalse, 0 );
return;
}
}
if ( fadeRatio >= 1.0 ) {
CG_GetOriginForTag( cent, ¢->pe.headRefEnt, "tag_mouth", 0, morg, maxis );
AxisToAngles( maxis, mang );
CG_FireFlameChunks( cent, morg, mang, ZOMBIE_FLAME_SCALE, qtrue, 0 );
CG_S_AddLoopingSound( cent->currentState.number, cent->lerpOrigin, vec3_origin, cgs.media.flameSound, 50 );
}
}
/*
==============
CG_AddZombieFlameEffect
==============
*/
void CG_AddZombieFlameShort( centity_t *cent ) {
vec3_t morg, maxis[3], mang;
if ( cent->currentState.aiChar != AICHAR_ZOMBIE ) {
return;
}
if ( cent->currentState.eFlags & EF_DEAD ) {
return;
}
if ( !IS_FLAMING_ZOMBIE( cent->currentState ) ) {
return;
}
if ( cent->currentState.time < cg.time ) {
return;
}
CG_GetOriginForTag( cent, ¢->pe.headRefEnt, "tag_mouth", 0, morg, maxis );
AxisToAngles( maxis, mang );
// shoot this only in bursts
if ( ( cg.time + cent->currentState.number * 100 ) % 1000 > 200 ) {
CG_FireFlameChunks( cent, morg, cent->lerpAngles, 0.1, qfalse, 0 );
return;
}
CG_FireFlameChunks( cent, morg, cent->lerpAngles, 0.4, 2, 0 );
CG_S_AddLoopingSound( cent->currentState.number, cent->lerpOrigin, vec3_origin, cgs.media.flameSound, 50 );
}
//==========================================================================
/*
===============
LoperLightningEffect
If loper is alive, a constant lightning effect surrounds him
===============
*/
void CG_AddLoperLightningEffect( centity_t *cent ) {
#define LOPER_LIGHTNING_POINT_TIMEOUT 200
#define LOPER_LIGHTNING_MAX_DIST 360
#define LOPER_LIGHTNING_NORMAL_DIST 80
#define LOPER_MAX_POINT_TESTS 10
#define LOPER_MAX_POINT_TESTS_PERFRAME 20
int i, j, pointTests = 0;
vec3_t testPos, tagPos, c, v;
trace_t tr;
float maxDist;
int numPoints;
float colTake;
if ( cent->currentState.aiChar != AICHAR_LOPER ) {
return;
}
if ( !cent->currentValid ) {
return;
}
if ( cent->currentState.eFlags & EF_DEAD ) {
return;
}
if ( !cent->pe.legsRefEnt.hModel ) {
return;
}
if ( cent->currentState.eFlags & EF_MONSTER_EFFECT3 ) {
maxDist = LOPER_LIGHTNING_MAX_DIST;
numPoints = MAX_LOPER_LIGHTNING_POINTS;
} else {
maxDist = LOPER_LIGHTNING_NORMAL_DIST;
numPoints = MAX_LOPER_LIGHTNING_POINTS / 3;
}
CG_GetOriginForTag( cent, ¢->pe.legsRefEnt, "tag_spinner", 0, tagPos, NULL );
// show a dlight
// color
colTake = 0.8 - fabs( sin( cg.time ) ) * 0.3;
c[0] = 1.0 - colTake;
c[1] = 1.0 - 0.7 * colTake;
c[2] = 1.0; //c[1] + 0.2;
if ( c[2] > 1.0 ) {
c[2] = 1.0;
}
//VectorScale( c, alpha, c );
// add the light
trap_R_AddLightToScene( tagPos, LOPER_LIGHTNING_NORMAL_DIST * ( 2.5 + ( 1.0 + sin( cg.time ) ) / 4.0 ), c[0], c[1], c[2], 1 );
for ( i = 0; i < numPoints; i++ ) {
// if this point has timed out, find a new spot
if ( ( cent->currentState.eFlags & EF_MONSTER_EFFECT ) &&
( ( !cent->pe.lightningTimes[i] ) ||
( cent->pe.lightningTimes[i] > cg.time ) ||
( cent->pe.lightningTimes[i] < cg.time - 50 ) ||
( VectorDistance( cent->lerpOrigin, cent->pe.lightningPoints[i] ) > maxDist ) ) ) {
// attacking the player
VectorSet( testPos, 12 * crandom(),
12 * crandom(),
32 * crandom() );
VectorAdd( testPos, cg.snap->ps.origin, testPos );
cent->pe.lightningTimes[i] = cg.time - rand() % ( LOPER_LIGHTNING_POINT_TIMEOUT / 2 );
VectorCopy( testPos, cent->pe.lightningPoints[i] );
// play a zap sound
if ( cent->pe.lightningSoundTime < cg.time - 100 ) {
trap_S_StartSound( testPos, ENTITYNUM_WORLD, CHAN_AUTO, cgs.media.lightningZap /*cgs.media.lightningSounds[rand()%3]*/ );
cent->pe.lightningSoundTime = cg.time;
}
} else if ( ( !cent->pe.lightningTimes[i] ) ||
( cent->pe.lightningTimes[i] > cg.time ) ||
( cent->pe.lightningTimes[i] < cg.time - LOPER_LIGHTNING_POINT_TIMEOUT ) ||
( VectorDistance( cent->lerpOrigin, cent->pe.lightningPoints[i] ) > maxDist ) ) {
if ( cent->currentState.groundEntityNum == ENTITYNUM_NONE ) {
continue; // must be on the ground
}
// find a new spot
for ( j = 0; j < LOPER_MAX_POINT_TESTS; j++ ) {
VectorSet( testPos, maxDist * crandom(),
maxDist * crandom(),
maxDist * ( crandom() - 0.5 ) );
VectorAdd( testPos, cent->lerpOrigin, testPos );
// try a trace to find a world collision
CG_Trace( &tr, cent->lerpOrigin, NULL, NULL, testPos, cent->currentState.number, MASK_SOLID );
if ( tr.fraction < 1 && tr.entityNum == ENTITYNUM_WORLD ) {
// found a valid spot!
cent->pe.lightningTimes[i] = cg.time - rand() % ( LOPER_LIGHTNING_POINT_TIMEOUT / 2 );
VectorCopy( tr.endpos, cent->pe.lightningPoints[i] );
// play a zap sound
if ( cent->pe.lightningSoundTime < cg.time - 100 ) {
// HACK, move ths sound away from the viewpos, to simulate lower volume
VectorSubtract( testPos, cg.refdef.vieworg, v );
VectorMA( cg.refdef.vieworg, 3.0, v, v );
trap_S_StartSound( v, ENTITYNUM_WORLD, CHAN_AUTO, cgs.media.lightningSounds[rand() % 3] );
cent->pe.lightningSoundTime = cg.time;
}
break;
}
if ( pointTests++ > LOPER_MAX_POINT_TESTS_PERFRAME ) {
j = LOPER_MAX_POINT_TESTS;
continue;
}
}
if ( j == LOPER_MAX_POINT_TESTS ) {
continue; // just don't draw this point
}
}
//
// we have a valid lightning point, so draw it
// sanity check though to make sure it's valid
if ( VectorDistance( cent->lerpOrigin, cent->pe.lightningPoints[i] ) <= maxDist ) {
CG_DynamicLightningBolt( cgs.media.lightningBoltShader, tagPos, cent->pe.lightningPoints[i], 1, 25 + 12.0 * random(), ( cent->currentState.eFlags & EF_MONSTER_EFFECT ) == 0, 1.0, 0, i * i * 2 );
}
}
}
/*
===============
LoperGroundEffect
Electrical charge applied to ground through torso
===============
*/
void CG_AddLoperGroundEffect( centity_t *cent ) {
#define LOPER_GROUNDCHARGE_INTERVAL 30
#define LOPER_GROUNDCHARGE_DURATION 100
#define LOPER_GROUNDCHARGE_FADEOUT 400
#define LOPER_GROUNDCHARGE_RADIUS 150
vec3_t org, c;
//static vec3_t up = {0,0,1}; // TTimo: unused
float colTake;
int duration;
float alpha, lightAlpha = 0.0f; // TTimo: init
if ( cent->currentState.aiChar != AICHAR_LOPER ) {
return;
}
if ( !cent->currentValid ) {
return;
}
if ( cent->currentState.eFlags & EF_DEAD ) {
return;
}
if ( !cent->pe.legsRefEnt.hModel ) {
return;
}
if ( !( cent->currentState.eFlags & EF_MONSTER_EFFECT3 ) ) {
if ( !cent->pe.loperGroundValidTime ) {
alpha = 0.0;
} else {
// alpha for lightning mark
duration = LOPER_GROUNDCHARGE_FADEOUT - ( cg.time - cent->pe.loperGroundValidTime );
if ( duration <= 0 ) {
cent->pe.loperGroundValidTime = 0;
}
alpha = (float)duration / (float)LOPER_GROUNDCHARGE_FADEOUT;
if ( alpha < 0 ) {
alpha = 0;
}
// light lives on a bit after the last lightning mark is spawned
lightAlpha = (float)( duration + LOPER_GROUNDCHARGE_DURATION ) / (float)( LOPER_GROUNDCHARGE_FADEOUT + LOPER_GROUNDCHARGE_DURATION );
if ( lightAlpha < 0 ) {
lightAlpha = 0;
}
}
} else {
cent->pe.loperGroundValidTime = cg.time;
alpha = 1.0;
lightAlpha = 1.0;
}
if ( !lightAlpha ) {
cent->pe.loperGroundValidTime = 0;
return;
}
// show a dlight
// color
colTake = 0.8 - fabs( sin( cg.time ) ) * 0.3;
c[0] = 1.0 - colTake;
c[1] = 1.0 - 0.8 * colTake;
c[2] = 1.0; //c[1] + 0.2;
if ( c[2] > 1.0 ) {
c[2] = 1.0;
}
VectorScale( c, alpha, c );
// add the light
trap_R_AddLightToScene( cent->lerpOrigin, LOPER_GROUNDCHARGE_RADIUS * ( 3.0 + 2.0 * ( 1.0 + sin( 0.001 * ( ( cg.time ) % ( 1000 * ( 2 + cent->currentState.number ) ) ) ) ) / 2.0 ), c[0], c[1], c[2], 1 );
//trap_R_AddLightToScene( cent->lerpOrigin, LOPER_GROUNDCHARGE_RADIUS*(2.0 + 1.0*(1.0+cos(0.001343*((cg.time)%(1000*(2+cent->currentState.number)))))/2.0), c[0], c[1], c[2], 0 );
if ( !alpha ) {
return;
}
// create a fading mark at intervals
if ( cent->pe.loperLastGroundChargeTime < cg.time - LOPER_GROUNDCHARGE_INTERVAL ) {
// org
VectorCopy( cent->lerpOrigin, org );
org[2] -= 20;
// color
if ( cent->pe.loperGroundChargeToggle ^= 1 ) {
// random blue
colTake = 0.5 + random() * 0.5;
c[0] = 1.0 - colTake;
c[1] = 1.0 - /*(0.5 + 0.5*random())**/ colTake;
c[2] = c[1] + 0.2;
if ( c[2] > 1.0 ) {
c[2] = 1.0;
}
} else {
VectorSet( c, 1,1,1 );
}
// draw the mark
//CG_ImpactMark( cgs.media.loperGroundChargeShader, org, up, random()*360, c[0], c[1], c[2], alpha, qtrue, (0.5+0.5*random())*LOPER_GROUNDCHARGE_RADIUS, qfalse, LOPER_GROUNDCHARGE_DURATION );
cent->pe.loperLastGroundChargeTime = cg.time;
// make a new sound
VectorSet( org, org[0] + crandom() * 256, org[1] + crandom() * 256, org[2] + crandom() * 256 );
trap_S_StartSound( org, ENTITYNUM_WORLD, CHAN_AUTO, cgs.media.lightningZap );
}
}
//==========================================================================
/*
==============
CG_SpawnHelgaSpirit
==============
*/
void CG_SpawnHelgaSpirit( vec3_t origin, vec3_t vel, int trailHead, int ownerNum, refEntity_t *oldrefent, int trailLife, int idealWidth ) {
localEntity_t *le;
refEntity_t *re;
le = CG_AllocLocalEntity();
re = &le->refEntity;
*re = *oldrefent;
le->leType = LE_HELGA_SPIRIT;
le->startTime = cg.time - 5000; // set it back so we dont fade it in like the "end" spirits
le->endTime = cg.time + 5000;
le->pos.trType = TR_LINEAR;
le->pos.trTime = cg.time;
VectorCopy( origin, le->pos.trBase );
VectorCopy( vel, le->pos.trDelta );
le->effectWidth = trailLife;
le->radius = idealWidth;
le->lastTrailTime = cg.time;
le->headJuncIndex = trailHead;
le->loopingSound = cgs.media.helgaSpiritLoopSound;
le->ownerNum = ownerNum;
re->fadeStartTime = le->endTime - 2000;
re->fadeEndTime = le->endTime;
re->shaderTime = cg.time;
}
/*
==============
CG_AddHelgaSpiritEffect
==============
*/
void CG_AddHelgaSpiritEffect( centity_t *cent ) {
const int trailLife = 600;
const float idealWidth = 30.0;
const int fadeInTime = 2000;
const int fadeOutTime = 2000;
const int minRotationTime = 6000;
const int maxRotationTime = 10000;
const int minRadiusCycleTime = 2400;
const int maxRadiusCycleTime = 2900;
const int zCycleTime = 3000;
const float minDist = 50;
const float maxDist = 100;
const float fadeDist = 4;
const int sndIntervalMin = 300;
const int sndIntervalMax = 1400;
const int sndDelay = 0;
//const int sndDuration = 99999;//1500; // TTimo: unused
const int step = 25;
int i, t;
vec3_t v,p[MAX_ZOMBIE_SPIRITS], ang;
float fadeRatio, alpha, radius;
int rotationTime, radiusCycleTime;
trace_t trace;
refEntity_t refent;
static int lastSpiritRelease;
qboolean active = qfalse;
if ( cent->currentState.aiChar != AICHAR_HELGA ) {
return;
}
// sanity check the server time to make sure we don't start the effect
// to early, whilst reloading a savegame or something
if ( cg.time < cent->currentState.effect1Time ) {
return;
}
if ( cent->currentState.eFlags & EF_MONSTER_EFFECT ) {
if ( !cent->pe.cueZombieSpirit ) {
// starting a new effect
cent->pe.cueZombieSpirit = qtrue;
cent->pe.zombieSpiritStartTime = cent->currentState.effect1Time;
cent->pe.lastZombieSpirit = cg.time;
cent->pe.nextZombieSpiritSound = cg.time + sndDelay;
for ( i = 0; i < MAX_ZOMBIE_SPIRITS; i++ ) {
cent->pe.zombieSpiritTrailHead[i] = -1;
cent->pe.zombieSpiritRotationTimes[i] = minRotationTime + ( random() * ( maxRotationTime - minRotationTime ) );
cent->pe.zombieSpiritRadiusCycleTimes[i] = minRadiusCycleTime + ( random() * ( maxRadiusCycleTime - minRadiusCycleTime ) );
cent->pe.zombieSpiritStartTimes[i] = cent->currentState.effect1Time;
}
}
cent->pe.zombieSpiritEndTime = cg.time;
} else {
// if running another effect, dont mess with its variables
if ( cent->currentState.eFlags & EF_MONSTER_EFFECT3 || cent->currentState.effect1Time < cent->currentState.effect3Time ) {
return;
}
if ( !cent->pe.zombieSpiritEndTime ) {
return;
}
// clear the flag, and let the effect fade itself out
cent->pe.cueZombieSpirit = qfalse;
}
for ( t = cent->pe.lastZombieSpirit + step; t <= cg.time; t += step ) {
// add the spirits
for ( i = 0; i < MAX_ZOMBIE_SPIRITS; i++ ) {
if ( cent->pe.zombieSpiritTrailHead[i] < -1 ) {
// spirit has gone, create a new one
cent->pe.zombieSpiritTrailHead[i] = -1;
cent->pe.zombieSpiritRotationTimes[i] = minRotationTime + ( random() * ( maxRotationTime - minRotationTime ) );
cent->pe.zombieSpiritRadiusCycleTimes[i] = minRadiusCycleTime + ( random() * ( maxRadiusCycleTime - minRadiusCycleTime ) );
cent->pe.zombieSpiritStartTimes[i] = cg.time - step;
}
fadeRatio = (float)( cg.time - cent->pe.zombieSpiritStartTimes[i] ) / (float)fadeInTime;
if ( fadeRatio < 0.0 ) {
fadeRatio = 0.0;
}
if ( fadeRatio > 1.0 ) {
fadeRatio = 1.0;
}
if ( cent->pe.cueZombieSpirit ) {
alpha = fadeRatio;
} else {
alpha = 1.0 - ( (float)( cg.time - cent->pe.zombieSpiritEndTime ) / (float)fadeOutTime );
fadeRatio = alpha;
if ( alpha < 0.0 ) {
cent->pe.zombieSpiritTrailHead[i] = -2; // kill it
continue;
}
}
active = qtrue; // we have an active spirit, so continue effect
alpha *= 0.3;
if ( cent->pe.cueZombieSpirit ) {
rotationTime = cent->pe.zombieSpiritRotationTimes[i];
radiusCycleTime = cent->pe.zombieSpiritRadiusCycleTimes[i];
radius = ( minDist + sin( M_PI * 2 * (float)( (float)( (int)( t + ( (float)( radiusCycleTime * i ) / MAX_ZOMBIE_SPIRITS ) ) % radiusCycleTime ) / (float)radiusCycleTime ) ) * ( maxDist - minDist ) );
// get the position
v[0] = ( 0.5 + 0.5 * fadeRatio ) * sin( M_PI * 2 * (float)( (float)( (int)( t + ( (float)( rotationTime * i ) / MAX_ZOMBIE_SPIRITS ) ) % rotationTime ) / (float)rotationTime ) ) * radius;
v[1] = ( 0.5 + 0.5 * fadeRatio ) * cos( M_PI * 2 * (float)( (float)( (int)( t + ( (float)( rotationTime * i ) / MAX_ZOMBIE_SPIRITS ) ) % rotationTime ) / (float)rotationTime ) ) * radius;
v[2] = 12 + 36 * ( 0.5 + 0.5 * fadeRatio ) * sin( M_PI * 2 * (float)( (float)( (int)( t + ( (float)( zCycleTime * i ) / MAX_ZOMBIE_SPIRITS ) ) % zCycleTime ) / (float)zCycleTime ) );
v[2] -= ( 1.0 - fadeRatio ) * 32;
VectorAdd( cent->lerpOrigin, v, p[i] );
} else {
// expand the radius, if it enters world geometry, kill it
rotationTime = cent->pe.zombieSpiritRotationTimes[i];
radiusCycleTime = cent->pe.zombieSpiritRadiusCycleTimes[i];
radius = pow( 1.0 - fadeRatio, 2 ) * fadeDist + ( 1.0 - pow( 1.0 - fadeRatio, 2 ) ) * ( minDist + sin( M_PI * 2 * (float)( (float)( (int)( t + ( (float)( radiusCycleTime * i ) / MAX_ZOMBIE_SPIRITS ) ) % radiusCycleTime ) / (float)radiusCycleTime ) ) * ( maxDist - minDist ) );
// get the position
v[0] = sin( M_PI * 2 * (float)( (float)( (int)( t + ( (float)( rotationTime * i ) / MAX_ZOMBIE_SPIRITS ) ) % rotationTime ) / (float)rotationTime ) ) * radius;
v[1] = cos( M_PI * 2 * (float)( (float)( (int)( t + ( (float)( rotationTime * i ) / MAX_ZOMBIE_SPIRITS ) ) % rotationTime ) / (float)rotationTime ) ) * radius;
v[2] = 12 + 36 * sin( M_PI * 2 * (float)( (float)( (int)( t + ( (float)( zCycleTime * i ) / MAX_ZOMBIE_SPIRITS ) ) % zCycleTime ) / (float)zCycleTime ) );
v[2] -= ( 1.0 - fadeRatio ) * 32;
VectorAdd( cent->lerpOrigin, v, p[i] );
// check for sinking into geometry
trap_CM_BoxTrace( &trace, p[i], p[i], NULL, NULL, 0, MASK_SOLID );
// if we hit something, clip the velocity, but maintain speed
if ( trace.startsolid ) {
cent->pe.zombieSpiritTrailHead[i] = -2; // kill it
continue;
}
}
VectorSubtract( p[i], cent->pe.zombieSpiritPos[i], cent->pe.zombieSpiritDir[i] );
cent->pe.zombieSpiritSpeed[i] = 1000.0 / step * VectorNormalize( cent->pe.zombieSpiritDir[i] );
VectorCopy( p[i], cent->pe.zombieSpiritPos[i] );
cent->pe.zombieSpiritTrailHead[i] = CG_AddTrailJunc( cent->pe.zombieSpiritTrailHead[i],
cgs.media.zombieSpiritTrailShader,
t,
STYPE_STRETCH,
p[i],
trailLife * 2,
alpha,
0.0,
( 0.5 + 0.5 * fadeRatio ) * idealWidth,
0,
TJFL_NOCULL,
colorWhite,
colorWhite,
1.0, 1 );
}
cent->pe.lastZombieSpirit = t;
if ( !active ) { // effect has gone
cent->pe.zombieSpiritEndTime = 0;
}
}
// add the skull at the head of the spirits
memset( &refent, 0, sizeof( refent ) );
refent.hModel = cgs.media.helgaGhostModel;
refent.backlerp = 0;
refent.renderfx = RF_NOSHADOW | RF_MINLIGHT; //----(SA)
refent.customShader = cgs.media.helgaSpiritSkullShader;
refent.reType = RT_MODEL;
for ( i = 0; i < MAX_ZOMBIE_SPIRITS; i++ ) {
if ( cent->pe.zombieSpiritTrailHead[i] < -1 ) {
continue; // spirit has gone
}
fadeRatio = (float)( cg.time - cent->pe.zombieSpiritStartTimes[i] ) / (float)fadeInTime;
if ( fadeRatio < 0.0 ) {
fadeRatio = 0.0;
}
if ( fadeRatio > 1.0 ) {
fadeRatio = 1.0;
}
if ( cent->pe.cueZombieSpirit ) {
alpha = fadeRatio;
} else {
alpha = 1.0 - ( (float)( cg.time - cent->pe.zombieSpiritEndTime ) / (float)fadeOutTime );
fadeRatio = alpha;
if ( alpha < 0.0 ) {
cent->pe.zombieSpiritTrailHead[i] = -2; // kill it
continue;
}
}
refent.shaderRGBA[3] = (byte)( 0.5 * alpha * 255.0 );
VectorCopy( cent->pe.zombieSpiritPos[i], refent.origin );
// HACK!!! skull model is back-to-front, need to fix
//VectorInverse(cent->pe.zombieSpiritDir[i]);
vectoangles( cent->pe.zombieSpiritDir[i], ang );
//VectorInverse(cent->pe.zombieSpiritDir[i]);
AnglesToAxis( ang, refent.axis );
/* // create the non-normalized axis so we can size it
refent.nonNormalizedAxes = qtrue;
for (t=0; t<3; t++) {
VectorNormalize( refent.axis[t] );
VectorScale( refent.axis[t], 0.35, refent.axis[t] );
}
*/ //
// add the sound
CG_S_AddLoopingSound( -1, cent->lerpOrigin, vec3_origin, cgs.media.helgaSpiritLoopSound, fadeRatio );
//
// if this spirit is in a good position to be released and head to the enemy, then release it
if ( fadeRatio == 1.0 && ( lastSpiritRelease > cg.time || ( lastSpiritRelease < cg.time - 1000 ) ) ) {
VectorSubtract( cent->currentState.origin2, refent.origin, v );
VectorNormalize( v );
if ( DotProduct( cent->pe.zombieSpiritDir[i], v ) > 0.4 || ( cent->currentState.eFlags & EF_DEAD ) ) {
// check for sinking into geometry
trap_CM_BoxTrace( &trace, refent.origin, refent.origin, NULL, NULL, 0, MASK_SOLID );
// if we hit something, don't release it yet
if ( !trace.startsolid ) {
if ( cent->pe.zombieSpiritSpeed[i] < 300 ) {
cent->pe.zombieSpiritSpeed[i] = 300;
}
VectorScale( cent->pe.zombieSpiritDir[i], cent->pe.zombieSpiritSpeed[i], v );
CG_SpawnHelgaSpirit( refent.origin, v, cent->pe.zombieSpiritTrailHead[i], cent->currentState.number, &refent, trailLife, idealWidth );
lastSpiritRelease = cg.time;
cent->pe.zombieSpiritTrailHead[i] = -2; // kill this version of it
continue;
}
}
}
//
// if we didn't kill it, draw it
trap_R_AddRefEntityToScene( &refent );
}
if ( cg.time > cent->pe.nextZombieSpiritSound && cent->pe.cueZombieSpirit ) { //&& (cg.time < cent->pe.zombieSpiritStartTime + sndDuration)) {
// spawn a new sound
//trap_S_StartSound( cent->lerpOrigin, -1, CHAN_AUTO, cgs.media.helgaSpiritSound );
CG_SoundPlayIndexedScript( cgs.media.helgaSpiritSound, NULL, cent->currentState.number );
cent->pe.nextZombieSpiritSound = cg.time + sndIntervalMin + (int)( (float)( sndIntervalMax - sndIntervalMin ) * random() );
}
// add a negative light around us
fadeRatio = (float)( cg.time - cent->pe.zombieSpiritStartTime ) / (float)fadeInTime;
if ( fadeRatio < 0.0 ) {
fadeRatio = 0.0;
}
if ( fadeRatio > 1.0 ) {
fadeRatio = 1.0;
}
if ( !cent->pe.cueZombieSpirit ) {
alpha = 1.0 - ( (float)( cg.time - cent->pe.zombieSpiritEndTime ) / (float)fadeOutTime );
fadeRatio = alpha;
if ( alpha < 0.0 ) {
cent->pe.zombieSpiritEndTime = 0; // stop the effect
return;
}
}
fadeRatio *= 0.7;
trap_R_AddLightToScene( cent->lerpOrigin, 500.0, 1.0 * fadeRatio, 1.0 * fadeRatio, 1.0 * fadeRatio, 10 );
}
//==========================================================================
/*
===============
CG_AddRefEntityWithPowerups
Adds a piece with modifications or duplications for powerups
Also called by CG_Missile for quad rockets, but nobody can tell...
===============
*/
void CG_AddRefEntityWithPowerups( refEntity_t *ent, int powerups, int team, entityState_t *es, const vec3_t fireRiseDir ) {
centity_t *cent;
refEntity_t backupRefEnt; //, parentEnt;
qboolean onFire = qfalse;
float alpha = 0.0;
cent = &cg_entities[es->number];
ent->entityNum = es->number;
if ( cent->pe.forceLOD ) {
ent->reFlags |= REFLAG_FORCE_LOD;
}
// RF, if in camera mode, force a full lod, since we are in a controlled environment
if ( cg.cameraMode ) {
ent->reFlags |= REFLAG_FULL_LOD;
}
//----(SA) testing
//----(SA) disabling
// if( cent->currentState.eFlags & EF_DEAD ) {
// ent->reFlags |= REFLAG_DEAD_LOD;
// }
//----(SA) end
backupRefEnt = *ent;
if ( powerups & ( 1 << PW_INVIS ) ) {
ent->customShader = cgs.media.invisShader;
trap_R_AddRefEntityToScene( ent );
#if 0
// -------------------------------
// Zombie effects
//
} else if ( es->aiChar == AICHAR_ZOMBIE ) {
// Zombie needs special processing, to remove the bits of flesh that have been torn away
if ( ent->hModel == cent->pe.torsoRefEnt.hModel ) {
//ent->reFlags = REFLAG_ZOMBIEFX;
ent->shaderTime = 0;
} else if ( ent->hModel == cent->pe.legsRefEnt.hModel ) {
//ent->reFlags = REFLAG_ZOMBIEFX2; // ref needs to know this is the legs
ent->shaderTime = 0;
}
// first, check for portal spawning
if ( es->time2 ) {
if ( es->time2 < cg.time ) {
return; // not ready yet
}
// fade in the skeleton, skin should "compose" (reverse decomposition)
alpha = (float)( cg.time - es->time2 ) / PORTAL_ZOMBIE_SPAWNTIME;
if ( alpha > 1 ) {
alpha = 1;
}
// skeleton fades in towards end of effect
if ( alpha < 0.5 ) {
ent->shaderRGBA[3] = 0;
} else { ent->shaderRGBA[3] = ( unsigned char )( ( alpha - 0.5 ) * 2.0 * 255 );}
//
ent->shaderTime = 0.001 * ( 1.0 - alpha ) * ZOMBIEFX_FADEOUT_TIME;
if ( ent->hModel == cent->pe.headRefEnt.hModel ) {
//ent->reFlags = REFLAG_ZOMBIEFX;
ent->customShader = cgs.media.zombieHeadFadeShader;
}
trap_R_AddRefEntityToScene( ent );
// add flaming effect
onFire = qtrue;
alpha *= 0.5;
} else {
// if the Zombie is dead, the skin should decompose
ent->shaderRGBA[3] = 255;
if ( es->eFlags & EF_MONSTER_EFFECT2 &&
cent->currentState.effect2Time < cg.time ) { // Ridah, Zombie death effect
if ( ent->hModel == cent->pe.headRefEnt.hModel ) {
//ent->reFlags = REFLAG_ZOMBIEFX;
ent->customShader = cgs.media.zombieHeadFadeShader;
}
ent->shaderTime = 0.001 * ( cg.time - cent->currentState.effect2Time );
trap_R_AddRefEntityToScene( ent );
/*
// skeleton: add legs and head parts
if (ent->hModel == cent->pe.legsRefEnt.hModel) {
ent->skinNum = 0;
ent->reFlags = 0;
ent->customShader = cgs.media.skeletonSkinShader;
// legs
ent->hModel = cgs.media.skeletonLegsModel;
trap_R_AddRefEntityToScene( ent );
// torso (just get this so we can place the head correctly)
parentEnt = *ent;
CG_PositionEntityOnTag( ent, &parentEnt, parentEnt.hModel, "tag_torso", NULL );
ent->hModel = cgs.media.skeletonTorsoModel;
// head
parentEnt = *ent;
CG_PositionEntityOnTag( ent, &parentEnt, parentEnt.hModel, "tag_head", NULL );
ent->hModel = cgs.media.skeletonHeadModel;
trap_R_AddRefEntityToScene( ent );
}
*/
} else { // show it normally
trap_R_AddRefEntityToScene( ent );
}
}
// restore previous state
*ent = backupRefEnt;
#endif
/*
} else if (es->eFlags & EF_MONSTER_EFFECT2 && es->aiChar == AICHAR_ZOMBIE &&
cent->currentState.effect2Time < cg.time) { // Ridah, Zombie death effect
const int fadeRiseTime = 4000;
if (cent->pe.zombieDeathFadeStart < cg.time && ent->hModel == cent->pe.legsRefEnt.hModel) {
// add the skeleton models starting with the legs
ent->fadeEndTime = 0;
ent->fadeStartTime = 0;
ent->skinNum = 0;
// legs
ent->hModel = cgs.media.skeletonLegsModel;
ent->customSkin = cgs.media.skeletonLegsSkin;
trap_R_AddRefEntityToScene( ent );
// torso
parentEnt = *ent;
CG_PositionEntityOnTag( ent, &parentEnt, parentEnt.hModel, "tag_torso", NULL );
ent->hModel = cgs.media.skeletonTorsoModel;
ent->customSkin = cgs.media.skeletonTorsoSkin;
trap_R_AddRefEntityToScene( ent );
// head
parentEnt = *ent;
CG_PositionEntityOnTag( ent, &parentEnt, parentEnt.hModel, "tag_head", NULL );
ent->hModel = cgs.media.skeletonHeadModel;
ent->customSkin = cgs.media.skeletonHeadSkin;
trap_R_AddRefEntityToScene( ent );
// restore previous state
*ent = backupRefEnt;
}
if (cent->pe.zombieDeathFadeEnd + fadeRiseTime > cg.time) {
// slowly fade the zombie "skin" out, revealing the skeleton underneath
//VectorSubtract( ent->origin, cg.snap->ps.origin, ent->fireRiseDir );
//VectorNegate( ent->axis[0], ent->fireRiseDir );
VectorNormalize2( ent->axis[0], ent->fireRiseDir );
if (cent->pe.zombieDeathFadeEnd > cg.time) {
// the zombie has hard-edged alpha blending on it's body texture by default
// so we need to override that for smooth fading
if (ent->hModel == cent->pe.legsRefEnt.hModel ||
ent->hModel == cent->pe.torsoRefEnt.hModel) {
ent->customShader = cgs.media.zombieBodyFadeShader;
} else if (ent->hModel == cent->pe.headRefEnt.hModel) {
ent->customShader = cgs.media.zombieHeadFadeShader;
}
// fade the alpha from 0 -> 255 as the time goes, which will fade from front to back
if (cent->pe.zombieDeathFadeStart > cg.time) {
ent->shaderRGBA[3] = 128;
} else {
ent->shaderRGBA[3] = 128 - (unsigned char)(128.0*pow(((float)(cg.time - cent->pe.zombieDeathFadeStart) / (float)(cent->pe.zombieDeathFadeEnd - cent->pe.zombieDeathFadeStart)), 2));
}
ent->shaderTime = 1.0;
trap_R_AddRefEntityToScene( ent );
}
}
*/
// -------------------------------
} else {
if ( CG_EntOnFire( &cg_entities[es->number] ) ) {
ent->reFlags |= REFLAG_FORCE_LOD;
}
trap_R_AddRefEntityToScene( ent );
if ( powerups & ( 1 << PW_QUAD ) ) {
if ( team == TEAM_RED ) {
ent->customShader = cgs.media.redQuadShader;
} else {
ent->customShader = cgs.media.quadShader;
}
trap_R_AddRefEntityToScene( ent );
}
if ( powerups & ( 1 << PW_REGEN ) ) {
if ( ( ( cg.time / 100 ) % 10 ) == 1 ) {
ent->customShader = cgs.media.regenShader;
trap_R_AddRefEntityToScene( ent );
}
}
if ( powerups & ( 1 << PW_BATTLESUIT ) ) {
ent->customShader = cgs.media.battleSuitShader;
trap_R_AddRefEntityToScene( ent );
}
}
if ( !onFire && CG_EntOnFire( &cg_entities[es->number] ) ) {
onFire = qtrue;
// set the alpha
alpha = ( cg.time - es->onFireStart ) / 1500.0;
if ( alpha > 1.0 ) {
alpha = ( es->onFireEnd - cg.time ) / 1500.0;
if ( alpha > 1.0 ) {
alpha = 1.0;
}
}
}
// Flaming zombie always shows a little fire
if ( !es->time2 && alpha < 1.0 && ( cent->currentState.aiChar == AICHAR_ZOMBIE ) && IS_FLAMING_ZOMBIE( cent->currentState ) /*&& !(cent->currentState.eFlags & EF_DEAD)*/ ) {
onFire = qtrue;
// set the alpha
alpha = 1.0;
}
if ( onFire ) {
if ( alpha < 0.0 ) {
alpha = 0.0;
}
ent->shaderRGBA[3] = ( unsigned char )( 255.0 * alpha );
VectorCopy( fireRiseDir, ent->fireRiseDir );
if ( VectorCompare( ent->fireRiseDir, vec3_origin ) ) {
VectorSet( ent->fireRiseDir, 0, 0, 1 );
}
/*
if (ent->fireRiseDir[2] > 0)
ent->fireRiseDir[2] *= -1;
ent->customShader = cgs.media.dripWetShader2;
trap_R_AddRefEntityToScene( ent );
ent->customShader = cgs.media.dripWetShader;
trap_R_AddRefEntityToScene( ent );
VectorCopy( fireRiseDir, ent->fireRiseDir );
*/
ent->customShader = cgs.media.onFireShader;
trap_R_AddRefEntityToScene( ent );
ent->customShader = cgs.media.onFireShader2;
trap_R_AddRefEntityToScene( ent );
if ( ent->hModel == cent->pe.legsRefEnt.hModel ) {
CG_S_AddLoopingSound( es->number, ent->origin, vec3_origin, cgs.media.flameCrackSound, (int)( 40.0 * alpha ) );
}
}
// tesla effect
if ( cg_entities[es->number].pe.teslaDamagedTime > cg.time - 400 ) {
float alpha;
alpha = ( 400.0 - (float)( cg.time - cg_entities[es->number].pe.teslaDamagedTime ) ) / 400.0;
ent->shaderRGBA[0] = ( unsigned char )( 50.0 * alpha );
ent->shaderRGBA[1] = ( unsigned char )( 130.0 * alpha );
ent->shaderRGBA[2] = ( unsigned char )( 255.0 * alpha );
if ( ( cg.time / 50 ) % ( 2 + ( cg.time % 2 ) ) == 0 ) {
ent->customShader = cgs.media.teslaAltDamageEffectShader;
} else {
ent->customShader = cgs.media.teslaDamageEffectShader;
}
trap_R_AddRefEntityToScene( ent );
}
*ent = backupRefEnt;
}
char *vtosf( const vec3_t v ) {
static int index;
static char str[8][64];
char *s;
// use an array so that multiple vtos won't collide
s = str[index];
index = ( index + 1 ) & 7;
Com_sprintf( s, 64, "(%f %f %f)", v[0], v[1], v[2] );
return s;
}
#define SPINNER_SPEED 0.3f
/*
==============
CG_SpinnerSpinAngle
==============
*/
static float CG_SpinnerSpinAngle( centity_t *cent ) {
int delta;
if ( cent->currentState.eFlags & EF_DEAD ) { // don't spin for dead loper (TODO: spindown, or blow off parts rather than just stopping)
return cent->pe.spinnerAngle;
}
delta = cg.time - cent->pe.spinnerTime;
return -( cent->pe.spinnerAngle + delta * SPINNER_SPEED );
}
/*
==============
CG_AddFireLight
==============
*/
static void CG_AddFireLight( centity_t *cent ) {
return;
/* OPTIMIZATION, TOO MANY DLIGHTS WHEN FIRE IS AROUND
entityState_t *es;
float alpha;
if (CG_EntOnFire(&cg_entities[cent->currentState.number])) {
es = ¢->currentState;
// set the alpha
alpha = (cg.time - es->onFireStart) / 1500.0;
if (alpha > 1.0) {
alpha = (es->onFireEnd - cg.time) / 1500.0;
if (alpha > 1.0) {
alpha = 1.0;
}
}
if (alpha <= 0.0) return;
trap_R_AddLightToScene( cent->lerpOrigin, 128 + 128*alpha, 1.000000*alpha, 0.603922*alpha, 0.207843*alpha, 0 );
}
*/
}
/*
===============
CG_AnimPlayerConditions
predict, or calculate condition for this entity, if it is not the local client
===============
*/
void CG_AnimPlayerConditions( centity_t *cent ) {
entityState_t *es;
if ( cg.snap && cg.snap->ps.clientNum == cent->currentState.number && !cg.renderingThirdPerson ) {
return;
}
es = ¢->currentState;
// WEAPON
BG_UpdateConditionValue( es->clientNum, ANIM_COND_WEAPON, es->weapon, qtrue );
// MOUNTED
if ( es->eFlags & EF_MG42_ACTIVE ) {
BG_UpdateConditionValue( es->clientNum, ANIM_COND_MOUNTED, MOUNTED_MG42, qtrue );
} else {
BG_UpdateConditionValue( es->clientNum, ANIM_COND_MOUNTED, MOUNTED_UNUSED, qtrue );
}
// UNDERHAND
BG_UpdateConditionValue( es->clientNum, ANIM_COND_UNDERHAND, cent->lerpAngles[0] > 0, qtrue );
if ( es->eFlags & EF_CROUCHING ) {
BG_UpdateConditionValue( es->clientNum, ANIM_COND_CROUCHING, qtrue, qtrue );
} else {
BG_UpdateConditionValue( es->clientNum, ANIM_COND_CROUCHING, qfalse, qtrue );
}
if ( es->eFlags & EF_FIRING ) {
BG_UpdateConditionValue( es->clientNum, ANIM_COND_FIRING, qtrue, qtrue );
} else {
BG_UpdateConditionValue( es->clientNum, ANIM_COND_FIRING, qfalse, qtrue );
}
// RF, changed this since we dont need to be careful about bandwidth anymore, and this method
// is much more accurate
if ( cent->currentState.animMovetype ) {
BG_UpdateConditionValue( es->clientNum, ANIM_COND_MOVETYPE, cent->currentState.animMovetype, qtrue );
}
}
void CG_DeadSink( centity_t *cent ) {
if ( cent->currentState.aiChar != AICHAR_WARZOMBIE ) {
return;
}
if ( !( cent->currentState.eFlags & EF_DEAD ) ) {
return;
}
if ( !cent->currentState.effect3Time ) {
return;
}
if ( cent->currentState.effect3Time >= cg.time ) {
return;
}
// sink
cent->lerpOrigin[2] -= DEAD_SINK_DEPTH * ( (float)( cg.time - cent->currentState.effect3Time ) / DEAD_SINK_DURATION );
}
/*
===============
CG_Player
===============
*/
void CG_Player( centity_t *cent ) {
int i;
clientInfo_t *ci;
refEntity_t legs;
refEntity_t torso;
refEntity_t head;
refEntity_t acc;
vec3_t lightorigin;
int clientNum;
int renderfx;
qboolean shadow;
float shadowPlane;
float gumsflappin = 0; // talking amplitude
centity_t *cgsnap;
cgsnap = &cg_entities[cg.snap->ps.clientNum];
shadow = qfalse; // gjd added to make sure it was initialized
shadowPlane = 0.0; // ditto
// if set to invisible, skip
if ( cent->currentState.eFlags & EF_NODRAW ) {
return;
}
// the client number is stored in clientNum. It can't be derived
// from the entity number, because a single client may have
// multiple corpses on the level using the same clientinfo
clientNum = cent->currentState.clientNum;
if ( clientNum < 0 || clientNum >= MAX_CLIENTS ) {
CG_Error( "Bad clientNum on player entity" );
}
ci = &cgs.clientinfo[ clientNum ];
//----(SA) we need to not see the player in the camera
// if (cg.cameraMode && clientNum == cg.snap->ps.clientNum) {
// return;
// }
//----(SA) end
// it is possible to see corpses from disconnected players that may
// not have valid clientinfo
if ( !ci->infoValid ) {
return;
}
// check time
if ( cent->pe.lastTime > cg.time ) {
CG_ResetPlayerEntity( cent );
}
cent->pe.lastTime = cg.time;
memset( &legs, 0, sizeof( legs ) );
memset( &torso, 0, sizeof( torso ) );
memset( &head, 0, sizeof( head ) );
memset( &acc, 0, sizeof( acc ) );
// get the rotation information
CG_PlayerAngles( cent, legs.axis, torso.axis, head.axis );
//----(SA) added
// setting the legs axis should pass the scale down through the other parts/tags/etc.
// and will need to be 'undone' for the weapon
if ( ci->playermodelScale[0] ) {
VectorScale( legs.axis[0], ci->playermodelScale[0], legs.axis[0] );
VectorScale( legs.axis[1], ci->playermodelScale[1], legs.axis[1] );
VectorScale( legs.axis[2], ci->playermodelScale[2], legs.axis[2] );
legs.nonNormalizedAxes = qtrue;
torso.nonNormalizedAxes = qtrue;
head.nonNormalizedAxes = qtrue;
}
//----(SA) end
// copy the torso rotation to the accessories
AxisCopy( torso.axis, acc.axis );
// calculate client-side conditions
CG_AnimPlayerConditions( cent );
// get the animation state (after rotation, to allow feet shuffle)
CG_PlayerAnimation( cent, &legs.oldframe, &legs.frame, &legs.backlerp,
&torso.oldframe, &torso.frame, &torso.backlerp );
// add powerups floating behind the player
CG_PlayerPowerups( cent );
// add the talk baloon or disconnect icon
CG_PlayerSprites( cent );
// add a water splash if partially in and out of water
CG_PlayerSplash( cent );
// get the player model information
renderfx = 0;
if ( cent->currentState.number == cg.snap->ps.clientNum && !cg.renderingThirdPerson ) {
renderfx = RF_THIRD_PERSON; // only draw in mirrors
}
// draw the player in cameras
// if ( cg.cameraMode ) {
// renderfx &= ~RF_THIRD_PERSON;
// }
if ( cg_shadows.integer == 3 && shadow ) {
renderfx |= RF_SHADOW_PLANE;
}
renderfx |= RF_LIGHTING_ORIGIN; // use the same origin for all
// set renderfx for accessories
acc.renderfx = renderfx;
// CG_Printf( "%i cl_org: %s\n", clientNum, vtosf( cent->lerpOrigin ) );
VectorCopy( cent->lerpOrigin, lightorigin );
lightorigin[2] += 31 + (float)cg_drawFPGun.integer;
// dead sink?
CG_DeadSink( cent );
//
// add special monster effects here
//
CG_AddZombieSpiritEffect( cent );
CG_AddZombieFlameEffect( cent );
CG_AddZombieFlameShort( cent );
CG_AddLoperLightningEffect( cent );
CG_AddLoperGroundEffect( cent );
CG_AddHelgaSpiritEffect( cent );
//
// add dynamic lights, and other misc effects
//
CG_AddFireLight( cent );
//
// add the legs
//
legs.hModel = ci->legsModel;
legs.customSkin = ci->legsSkin;
VectorCopy( cent->lerpOrigin, legs.origin );
if ( ci->playermodelScale[0] != 0 ) { // player scaled, adjust for the (-24) offset of player legs origin to ground
legs.origin[2] -= 24.0f * ( 1.0f - ci->playermodelScale[2] );
}
VectorCopy( lightorigin, legs.lightingOrigin );
legs.shadowPlane = shadowPlane;
legs.renderfx = renderfx;
VectorCopy( legs.origin, legs.oldorigin ); // don't positionally lerp at all
if ( !ci->isSkeletal ) {
CG_AddRefEntityWithPowerups( &legs, cent->currentState.powerups, ci->team, ¢->currentState, cent->fireRiseDir );
}
cent->pe.legsRefEnt = legs;
// if the model failed, allow the default nullmodel to be displayed
if ( !legs.hModel ) {
return;
}
// (SA) only need to set this once...
VectorCopy( lightorigin, acc.lightingOrigin );
//
// add the torso
//
torso.hModel = ci->torsoModel;
if ( !torso.hModel ) {
return;
}
torso.customSkin = ci->torsoSkin;
VectorCopy( lightorigin, torso.lightingOrigin );
//----(SA) check for ladder and if you're on it, don't allow torso model rotation (so the body climbs aligned with the ladder)
//----(SA) also taking care of the Loper's interesting heirarchy (his upper body is effectively the same as a weapon_hand.md3. it keeps things connected, but has no geometry)
if ( !ci->isSkeletal ) {
if ( ( cgsnap == cent && ( cg.snap->ps.pm_flags & PMF_LADDER ) ) || ( cent->currentState.aiChar == AICHAR_LOPER ) ) {
CG_PositionEntityOnTag( &torso, &legs, "tag_torso", 0, NULL );
} else {
CG_PositionRotatedEntityOnTag( &torso, &legs, "tag_torso" );
}
} else { // just clear out the angles
if ( ( cgsnap == cent && ( cg.snap->ps.pm_flags & PMF_LADDER ) ) || ( cent->currentState.aiChar == AICHAR_LOPER ) ) {
memcpy( torso.axis, legs.axis, sizeof( torso.axis ) );
}
}
torso.shadowPlane = shadowPlane;
torso.renderfx = renderfx;
if ( !ci->isSkeletal ) {
CG_AddRefEntityWithPowerups( &torso, cent->currentState.powerups, ci->team, ¢->currentState, cent->fireRiseDir );
} else { // SKELETAL ANIMATION
// skeletal models combine the legs and torso, so we must build a compiled refEntity_t
legs.torsoFrame = torso.frame;
legs.oldTorsoFrame = torso.oldframe;
memcpy( legs.torsoAxis, torso.axis, sizeof( torso.axis ) );
legs.torsoBacklerp = torso.backlerp;
CG_AddRefEntityWithPowerups( &legs, cent->currentState.powerups, ci->team, ¢->currentState, cent->fireRiseDir );
cent->pe.legsRefEnt = legs;
torso = legs; // so tag calls use the correct values
}
cent->pe.torsoRefEnt = torso;
// if ( cent->currentState.eFlags & EF_DEAD) {
// if(cent->currentState.eFlags & EF_HEADSHOT)
// // dead guy with no head
// return;
// }
//
// add the head
//
head.hModel = ci->headModel;
if ( !head.hModel ) {
return;
}
head.customSkin = ci->headSkin;
VectorCopy( lightorigin, head.lightingOrigin );
CG_PositionRotatedEntityOnTag( &head, &torso, "tag_head" );
head.shadowPlane = shadowPlane;
head.renderfx = renderfx;
// Ridah, talking animations
if ( !( cent->currentState.eFlags & EF_DEAD ) ) {
#define HEAD_EMOTION_SUBTYPES 8 // closed, A, O, I, E
int talk_frame; //, subtype;
qboolean closed;
#define NUM_EMOTIONS 2 // 0 neutral, 1 happy, 2 angry
int emotion = 0; // this should default to the entity's current emotion
gumsflappin = (float)trap_S_GetVoiceAmplitude( clientNum );
talk_frame = (int)floor( ( HEAD_EMOTION_SUBTYPES - 1 ) * ( gumsflappin / 256.0 ) );
// add the current frame to the total, so when it comes to pick a new frame, we choose the average
// of those we missed over the last frame
cent->pe.head.animationTime += talk_frame;
cent->pe.head.animationNumber++;
// if we are starting a talk after idling, hurry up the animation
if ( ( cent->pe.head.frameTime > cg.time + 30 ) && cent->pe.head.animationTime && !( ( cent->pe.head.frame - ci->modelInfo->headAnims[0].firstFrame ) % HEAD_EMOTION_SUBTYPES ) && !( ( cent->pe.head.oldFrame - ci->modelInfo->headAnims[0].firstFrame ) % HEAD_EMOTION_SUBTYPES ) ) {
cent->pe.head.frameTime = cg.time + 30;
}
if ( cent->pe.head.frameTime < cg.time ) { // set the new frame
cent->pe.head.oldFrame = cent->pe.head.frame;
cent->pe.head.oldFrameTime = cent->pe.head.frameTime;
if ( cent->pe.head.animationTime ) {
talk_frame = (int)( (float)cent->pe.head.animationTime / (float)cent->pe.head.animationNumber );
//subtype = rand()%HEAD_EMOTION_SUBTYPES;
emotion = rand() % NUM_EMOTIONS; // this helps animate the mouth more realistically while talking
switch ( cent->currentState.aiChar ) {
case AICHAR_ZOMBIE:
case AICHAR_LOPER:
talk_frame = (int)( (float)talk_frame * 1.2 );
closed = qfalse;
break;
default:
// randomly set it back to 0 amplitude to simulate certain synonyms pronounced with a closed mouth
closed = ( ( rand() % 5 ) == 0 ) && ( talk_frame < ( HEAD_EMOTION_SUBTYPES - 1 ) );
}
if ( closed ) {
talk_frame -= rand() % ( HEAD_EMOTION_SUBTYPES / 2 );
if ( talk_frame < 0 ) {
talk_frame = 0;
}
}
if ( talk_frame >= HEAD_EMOTION_SUBTYPES ) {
talk_frame = HEAD_EMOTION_SUBTYPES - 1;
}
cent->pe.head.frame = emotion * HEAD_EMOTION_SUBTYPES + talk_frame; //ci->modelInfo->headAnims[emotion*HEAD_EMOTION_SUBTYPES].firstFrame + talk_frame;
cent->pe.head.frameTime = cg.time + 80 + rand() % 40; // interpolate for smoother animation vs latency
//CG_Printf("%i head: frame %i, oldframe %i, nextframetime %i\n", cg.time, cent->pe.head.frame, cent->pe.head.oldFrame, cent->pe.head.frameTime );
//if (closed)
// cent->pe.head.frameTime += 30; // slow it down a bit
} else {
#if 0
// debugging, play all the frames and display the frame numbers
if ( ++cent->pe.head.frame > ( ci->headAnims[( NUM_EMOTIONS - 1 ) * HEAD_EMOTION_SUBTYPES + HEAD_EMOTION_SUBTYPES - 1].firstFrame ) ) {
cent->pe.head.frame = ci->headAnims[0].firstFrame;
}
cent->pe.head.frameTime = cg.time + 2000;
CG_Printf( "%d - %d\n", cent->currentState.number, cent->pe.head.oldFrame );
#else
while ( ( emotion = rand() % NUM_EMOTIONS ) == 1 ) ; // don't use happy emotion
if ( ( cent->pe.head.frame - ci->modelInfo->headAnims[0].firstFrame ) % HEAD_EMOTION_SUBTYPES ) {
cent->pe.head.frame = ci->modelInfo->headAnims[emotion * HEAD_EMOTION_SUBTYPES].firstFrame;
cent->pe.head.frameTime = cg.time + 150;
} else { // mouth is currently closed
cent->pe.head.frame = ci->modelInfo->headAnims[emotion * HEAD_EMOTION_SUBTYPES].firstFrame;
cent->pe.head.frameTime = cent->pe.head.frameTime + 1000 + rand() % 2000;
if ( cent->pe.head.frameTime < cg.time ) {
cent->pe.head.frameTime = cg.time + 1000;
}
}
#endif
}
cent->pe.head.animationTime = 0;
cent->pe.head.animationNumber = 0;
}
head.frame = cent->pe.head.frame;
head.oldframe = cent->pe.head.oldFrame;
head.backlerp = 1.0 - (float)( cg.time - cent->pe.head.oldFrameTime ) / ( cent->pe.head.frameTime - cent->pe.head.oldFrameTime );
} else { // dead
head.frame = 0;
head.oldframe = 0;
head.backlerp = 0.0;
}
// done.
// set blinking flag
if ( cent->currentState.eFlags & EF_DEAD ) {
// dead guy, eyes closed.
head.renderfx |= RF_BLINK;
} else if ( ci->blinkTime <= cg.time ) {
head.renderfx |= RF_BLINK;
if ( ci->blinkTime <= ( cg.time - cg_blinktime.integer ) ) {
ci->blinkTime = cg.time + 500 + random() * 4000;
// blink more often when talking
if ( gumsflappin >= 0 ) {
ci->blinkTime = max( cg.time, ci->blinkTime - 1000 );
}
}
}
CG_AddRefEntityWithPowerups( &head, cent->currentState.powerups, ci->team, ¢->currentState, cent->fireRiseDir );
cent->pe.headRefEnt = head;
// add the shadow
CG_PlayerShadow( cent, &shadowPlane );
// set the shadowplane for accessories
acc.shadowPlane = shadowPlane;
CG_BreathPuffs( cent, &head );
//
// add the gun / barrel / flash
//
CG_AddPlayerWeapon( &torso, NULL, cent );
cent->lastWeaponClientFrame = cg.clientFrame;
//
// add binoculars (if it's not the player)
//
if ( ( cent->currentState.clientNum != cg.snap->ps.clientNum ) &&
cent->currentState.eFlags & EF_ZOOMING ) {
acc.hModel = cgs.media.thirdPersonBinocModel;
CG_PositionEntityOnTag( &acc, &torso, "tag_weapon", 0, NULL );
CG_AddRefEntityWithPowerups( &acc, cent->currentState.powerups, ci->team, ¢->currentState, cent->fireRiseDir );
}
if ( ( cent->currentState.clientNum != cg.snap->ps.clientNum ) &&
cent->currentState.eFlags & EF_CIG ) {
acc.hModel = cgs.media.cigModel;
CG_PositionEntityOnTag( &acc, &torso, "tag_weapon2", 0, NULL );
CG_AddRefEntityWithPowerups( &acc, cent->currentState.powerups, ci->team, ¢->currentState, cent->fireRiseDir );
// smoke
if ( !cg_paused.integer ) { // don't add while paused
if ( !( rand() % 3 ) ) {
CG_ParticleImpactSmokePuffExtended( cgs.media.smokeParticleShader, acc.origin, tv( 0,0,1 ), 1, 1000, 6, 4, 10, 0.15f );
}
}
}
//
// add player specific models
//
if ( cent->currentState.aiChar == AICHAR_LOPER ) {
if ( ci->partModels[8] ) {
vec3_t angles;
acc.hModel = ci->partModels[8];
VectorClear( angles );
angles[YAW] = CG_SpinnerSpinAngle( cent );
AnglesToAxis( angles, acc.axis );
CG_PositionRotatedEntityOnTag( &acc, &legs, "tag_spinner" );
CG_AddRefEntityWithPowerups( &acc, cent->currentState.powerups, ci->team, ¢->currentState, cent->fireRiseDir );
}
}
//----(SA) modified
else if ( cent->currentState.aiChar == AICHAR_PROTOSOLDIER ||
cent->currentState.aiChar == AICHAR_SUPERSOLDIER ||
cent->currentState.aiChar == AICHAR_HEINRICH ) {
char *protoTags[] = { "tag_chest",
"tag_calfleft",
"tag_armleft",
"tag_back",
"tag_legleft",
"tag_calfright",
"tag_armright",
"tag_back",
"tag_legright"};
char *ssTags[] = { "tag_chest",
"tag_calfleft",
"tag_armleft",
"tag_back",
"tag_legleft",
"tag_calfright",
"tag_armright",
"tag_back",
"tag_legright",
"tag_footleft",
"tag_footright",
"tag_sholeft",
"tag_shoright",
"tag_torso",
"tag_calfleft",
"tag_calfright"};
char *heinrichTags[] = {"tag_chest",
"tag_calfleft",
"tag_armleft",
"tag_back",
"tag_legleft",
"tag_calfright",
"tag_armright",
"tag_back",
"tag_legright",
"tag_footleft",
"tag_footright",
"tag_sholeft",
"tag_shoright",
"tag_torso",
"tag_legleft",
"tag_legright",
"tag_sholeft",
"tag_shoright",
"tag_legleft",
"tag_legright",
"tag_legleft",
"tag_legright"};
// TTimo: init
int totalparts = 0, dynamicparts = 0, protoParts = 9, superParts = 16, heinrichParts = 22;
char **tags = NULL;
qhandle_t *models = NULL;
int dmgbits = 16; // 32/2;
if ( cent->currentState.aiChar == AICHAR_PROTOSOLDIER ) {
tags = &protoTags[0];
models = &cgs.media.protoArmor[0];
dynamicparts = totalparts = protoParts;
} else if ( cent->currentState.aiChar == AICHAR_SUPERSOLDIER ) {
tags = &ssTags[0];
models = &cgs.media.superArmor[0];
dynamicparts = 14; // the other two stay permanent
totalparts = superParts;
} else if ( cent->currentState.aiChar == AICHAR_HEINRICH ) {
tags = &heinrichTags[0];
models = &cgs.media.heinrichArmor[0];
dynamicparts = 20; // will get kicked down to 16
totalparts = heinrichParts;
}
if ( dynamicparts > dmgbits ) {
dynamicparts = dmgbits;
}
for ( i = 0; i < totalparts; i++ ) {
if ( ( i >= dynamicparts ) || ( !( cent->currentState.dmgFlags & ( 1 << i ) ) ) ) { // ones beyond 16 just draw the good part
acc.hModel = models[i];
} else {
if ( cent->currentState.dmgFlags & ( 1 << ( i + totalparts ) ) ) {
acc.hModel = models[i + totalparts];
} else {
acc.hModel = models[i + ( 2 * totalparts )];
}
}
if ( !acc.hModel ) {
continue;
}
CG_PositionEntityOnTag( &acc, &torso, tags[i], 0, NULL );
if ( cent->currentState.aiChar == AICHAR_PROTOSOLDIER && !( cent->currentState.eFlags & EF_DEAD ) ) {
if ( acc.hModel != models[i] ) {
vec3_t dir;
int mynum;
VectorSubtract( acc.origin, cent->currentState.pos.trBase, dir );
dir[2] += 20;
VectorNormalize( dir );
mynum = ( rand() % 100 );
if ( mynum < 2 ) {
CG_AddBulletParticles( acc.origin, dir, 30, 10 * mynum, 3, 300.0f );
}
}
}
CG_AddRefEntityWithPowerups( &acc, cent->currentState.powerups, ci->team, ¢->currentState, cent->fireRiseDir );
}
} else if ( cent->currentState.aiChar == AICHAR_WARZOMBIE &&
( !Q_strcasecmp( (char *)ci->modelInfo->modelname, "dark" ) ) ) {
// TTimo: unused
/*
char *tags[] = { "tag_armleft",
"tag_armright",
"tag_back",
"tag_back",
"tag_calfleft",
"tag_calfleft",
"tag_calfright",
"tag_calfright",
"tag_chest",
"tag_chest",
"tag_footleft",
"tag_footright",
"tag_legleft",
"tag_sholeft",
"tag_shoright",
"tag_torso"
};
*/
// TTimo: unused
/*
int parts[] = { 34,
38,
0,
19,
0,
14,
21,
15,
16,
0,
0,
32,
0,
33,
0,
45
};
*/
// char *parts[] = { "dam_lftforarm2",// 34
// "dam_rtforarm2",//38
// "dam_rtshoulder",
// "dam_lftshoulder1",//19
// "dam_lftcalf",
// "nodam_lftknee",//14
// "dam_rtcalf1",//21
// "nodam_rtknee",//15
// "dam_chest1",//16
// "dam_chest3",
// "dam_lftfoot",
// "dam_rtfoot2",//32
// "dam_lftthigh",
// "dam_lftuparm2",//33
// "dam_rtuparm",
// "dam_waist2"//45
// };
// do not turn on unless asked for
/*
for(i=0;i<16;i++) {
acc.hModel = cgs.media.superArmor[parts[i]];
CG_PositionEntityOnTag( &acc, &torso, tags[i], 0, NULL);
CG_AddRefEntityWithPowerups( &acc, cent->currentState.powerups, ci->team, ¢->currentState, cent->fireRiseDir );
}
*/
//
}
//#if 1
#ifdef TEST_HEADLIGHT
// used for testing spotlights.
// this just puts one in the mouth of every other player so you can
// get a good read of how well the various elements of spots are working
// if(cent->currentState.number != cg.predictedPlayerState.clientNum)
{
vec3_t morg, viewDir;
// vec4_t color = {1,1,1,0.1f};
vec4_t color = {0.7,0.7,0.7,0.1f};
CG_GetOriginForTag( cent, &head, "tag_mouth", 0, morg, NULL );
AngleVectors( cent->lerpAngles, viewDir, NULL, NULL );
CG_Spotlight( cent, color, morg, viewDir, 12, 512, 2, 5, SL_TRACEWORLDONLY | SL_NOCORE | SL_LOCKUV ); // SL_NOTRACE
// color[0] = 1;
// color[1] = 1;
// color[2] = 1;
color[3] = 0.1f;
CG_Spotlight( cent, color, morg, viewDir, 12, 512, 1.5, 2, SL_TRACEWORLDONLY | SL_NOCORE | SL_NODLIGHT | SL_LOCKUV ); // SL_NOTRACE
}
#endif
//
// add accessories
//
for ( i = ACC_BELT_LEFT; i < ACC_MAX; i++ ) {
if ( !( ci->accModels[i] ) ) {
continue;
}
// first 8 can be hidden by animation scripts
if ( i < 8 ) {
if ( cg.snap->ps.accHideBits & ( 1 << i ) ) {
continue;
}
}
acc.hModel = ci->accModels[i]; // set the model
if ( ci->accSkins[i] ) {
acc.customSkin = ci->accSkins[i]; // and the skin if there is one
}
switch ( i ) {
case ACC_BELT_LEFT:
CG_PositionEntityOnTag( &acc, &legs, "tag_bright", 0, NULL );
break;
case ACC_BELT_RIGHT:
CG_PositionEntityOnTag( &acc, &legs, "tag_bleft", 0, NULL );
break;
case ACC_BELT:
CG_PositionEntityOnTag( &acc, &torso, "tag_ubelt", 0, NULL );
break;
case ACC_BACK:
CG_PositionEntityOnTag( &acc, &torso, "tag_back", 0, NULL );
break;
case ACC_HAT: //hat
if ( cent->currentState.eFlags & EF_HEADSHOT ) {
continue;
}
case ACC_MOUTH2: // hat2
case ACC_MOUTH3: // hat3
CG_PositionEntityOnTag( &acc, &head, "tag_mouth", 0, NULL );
break;
// weapon and weapon2
// these are used by characters who have permanent weapons attached to their character in the skin
case ACC_WEAPON: // weap
CG_PositionEntityOnTag( &acc, &torso, "tag_weapon", 0, NULL );
break;
case ACC_WEAPON2: // weap2
CG_PositionEntityOnTag( &acc, &torso, "tag_weapon2", 0, NULL );
break;
default:
continue;
}
CG_AddRefEntityWithPowerups( &acc, cent->currentState.powerups, ci->team, ¢->currentState, cent->fireRiseDir );
}
for ( i = 0; i < 8; i++ ) {
if ( !( ci->partModels[i] ) ) {
continue;
}
// first 8 can be hidden by animation scripts
if ( !( cg.snap->ps.accShowBits & ( 1 << i ) ) ) {
continue;
}
acc.hModel = ci->partModels[i]; // set the model
if ( ci->partSkins[i] ) {
acc.customSkin = ci->partSkins[i]; // and the skin if there is one
}
CG_PositionEntityOnTag( &acc, &legs, va( "tag_animscript%d", i ), 0, NULL );
CG_AddRefEntityWithPowerups( &acc, cent->currentState.powerups, ci->team, ¢->currentState, cent->fireRiseDir );
}
}
//=====================================================================
extern void CG_ClearWeapLerpFrame( clientInfo_t *ci, lerpFrame_t *lf, int animationNumber );
/*
===============
CG_ResetPlayerEntity
A player just came into view or teleported, so reset all animation info
===============
*/
void CG_ResetPlayerEntity( centity_t *cent ) {
cent->errorTime = -99999; // guarantee no error decay added
cent->extrapolated = qfalse;
if ( !( cent->currentState.eFlags & EF_DEAD ) ) {
CG_ClearLerpFrameRate( &cgs.clientinfo[ cent->currentState.clientNum ], ¢->pe.legs, cent->currentState.legsAnim, cent );
CG_ClearLerpFrame( &cgs.clientinfo[ cent->currentState.clientNum ], ¢->pe.torso, cent->currentState.torsoAnim );
memset( ¢->pe.legs, 0, sizeof( cent->pe.legs ) );
cent->pe.legs.yawAngle = cent->nextState.apos.trBase[YAW]; //cent->rawAngles[YAW];
cent->pe.legs.yawing = qfalse;
cent->pe.legs.pitchAngle = cent->nextState.apos.trBase[PITCH];
cent->pe.legs.pitching = qfalse;
memset( ¢->pe.torso, 0, sizeof( cent->pe.torso ) );
cent->pe.torso.yawAngle = cent->nextState.apos.trBase[YAW]; //cent->rawAngles[YAW];
cent->pe.torso.yawing = qfalse;
cent->pe.torso.pitchAngle = cent->nextState.apos.trBase[PITCH]; //cent->rawAngles[PITCH];
cent->pe.torso.pitching = qfalse;
}
BG_EvaluateTrajectory( ¢->currentState.pos, cg.time, cent->lerpOrigin );
BG_EvaluateTrajectory( ¢->currentState.apos, cg.time, cent->lerpAngles );
VectorCopy( cent->lerpOrigin, cent->rawOrigin );
VectorCopy( cent->lerpAngles, cent->rawAngles );
if ( cg_debugPosition.integer ) {
CG_Printf( "%i ResetPlayerEntity yaw=%f\n", cent->currentState.number, cent->pe.torso.yawAngle );
}
cent->pe.painAnimLegs = -1;
cent->pe.painAnimTorso = -1;
cent->pe.animSpeed = 1.0;
}
void CG_GetBleedOrigin( vec3_t head_origin, vec3_t torso_origin, vec3_t legs_origin, int fleshEntityNum ) {
clientInfo_t *ci;
refEntity_t legs;
refEntity_t torso;
refEntity_t head;
centity_t *cent, backupCent;
ci = &cgs.clientinfo[ fleshEntityNum ];
cent = &cg_entities [ fleshEntityNum ];
backupCent = *cent;
if ( !ci->infoValid ) {
return;
}
memset( &legs, 0, sizeof( legs ) );
memset( &torso, 0, sizeof( torso ) );
memset( &head, 0, sizeof( head ) );
CG_PlayerAngles( cent, legs.axis, torso.axis, head.axis );
CG_PlayerAnimation( cent, &legs.oldframe, &legs.frame, &legs.backlerp,
&torso.oldframe, &torso.frame, &torso.backlerp );
legs.hModel = ci->legsModel;
VectorCopy( cent->lerpOrigin, legs.origin );
VectorCopy( legs.origin, legs.oldorigin );
// Ridah, restore the cent so we don't interfere with animation timings
*cent = backupCent;
if ( !legs.hModel ) {
return;
}
torso.hModel = ci->torsoModel;
if ( !torso.hModel ) {
return;
}
head.hModel = ci->headModel;
if ( !head.hModel ) {
return;
}
CG_PositionRotatedEntityOnTag( &torso, &legs, "tag_torso" );
CG_PositionRotatedEntityOnTag( &head, &torso, "tag_head" );
VectorCopy( head.origin, head_origin );
VectorCopy( torso.origin, torso_origin );
VectorCopy( legs.origin, legs_origin );
}
/*
===============
CG_GetTag
===============
*/
qboolean CG_GetTag( int clientNum, char *tagname, orientation_t *or ) {
clientInfo_t *ci;
centity_t *cent;
refEntity_t *refent;
vec3_t tempAxis[3];
vec3_t org;
int i;
ci = &cgs.clientinfo[ clientNum ];
if ( !ci->isSkeletal ) {
return qfalse; // only skeletal models supported
}
if ( cg.snap && clientNum == cg.snap->ps.clientNum && cg.renderingThirdPerson ) {
cent = &cg.predictedPlayerEntity;
} else {
cent = &cg_entities[ci->clientNum];
if ( !cent->currentValid ) {
return qfalse; // not currently in PVS
}
}
refent = ¢->pe.legsRefEnt;
if ( trap_R_LerpTag( or, refent, tagname, 0 ) < 0 ) {
return qfalse;
}
VectorCopy( refent->origin, org );
for ( i = 0 ; i < 3 ; i++ ) {
VectorMA( org, or->origin[i], refent->axis[i], org );
}
VectorCopy( org, or->origin );
// rotate with entity
MatrixMultiply( refent->axis, or->axis, tempAxis );
memcpy( or->axis, tempAxis, sizeof( vec3_t ) * 3 );
return qtrue;
}
/*
===============
CG_GetWeaponTag
===============
*/
qboolean CG_GetWeaponTag( int clientNum, char *tagname, orientation_t *or ) {
clientInfo_t *ci;
centity_t *cent;
refEntity_t *refent;
vec3_t tempAxis[3];
vec3_t org;
int i;
ci = &cgs.clientinfo[ clientNum ];
if ( !ci->isSkeletal ) {
return qfalse; // only skeletal models supported
}
if ( cg.snap && clientNum == cg.snap->ps.clientNum && cg.renderingThirdPerson ) {
cent = &cg.predictedPlayerEntity;
} else {
cent = &cg_entities[ci->clientNum];
if ( !cent->currentValid ) {
return qfalse; // not currently in PVS
}
}
if ( cent->pe.gunRefEntFrame < cg.clientFrame - 1 ) {
return qfalse;
}
refent = ¢->pe.gunRefEnt;
if ( trap_R_LerpTag( or, refent, tagname, 0 ) < 0 ) {
return qfalse;
}
VectorCopy( refent->origin, org );
for ( i = 0 ; i < 3 ; i++ ) {
VectorMA( org, or->origin[i], refent->axis[i], org );
}
VectorCopy( org, or->origin );
// rotate with entity
MatrixMultiply( refent->axis, or->axis, tempAxis );
memcpy( or->axis, tempAxis, sizeof( vec3_t ) * 3 );
return qtrue;
}
|