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 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 6147 6148 6149 6150 6151 6152 6153 6154 6155 6156 6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180 6181 6182 6183 6184 6185 6186 6187 6188 6189 6190 6191 6192 6193 6194 6195 6196 6197 6198 6199 6200 6201 6202 6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224 6225 6226 6227 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 6248 6249 6250 6251 6252 6253 6254 6255 6256 6257 6258 6259 6260 6261 6262 6263 6264 6265 6266 6267 6268 6269 6270 6271 6272 6273 6274 6275 6276 6277 6278 6279 6280 6281 6282 6283 6284 6285 6286 6287 6288 6289 6290 6291 6292 6293 6294 6295 6296 6297 6298 6299 6300 6301 6302 6303 6304 6305 6306 6307 6308 6309 6310 6311 6312 6313 6314 6315 6316 6317 6318 6319 6320 6321 6322 6323 6324 6325 6326 6327 6328 6329 6330 6331 6332 6333 6334 6335 6336 6337 6338 6339 6340 6341 6342 6343 6344 6345 6346 6347 6348 6349 6350 6351 6352 6353 6354 6355 6356 6357 6358 6359 6360 6361 6362 6363 6364 6365 6366 6367 6368 6369 6370 6371 6372 6373 6374 6375 6376 6377 6378 6379 6380 6381 6382 6383 6384 6385 6386 6387 6388 6389 6390 6391 6392 6393 6394 6395 6396 6397 6398 6399 6400 6401 6402 6403 6404 6405 6406 6407 6408 6409 6410 6411 6412 6413 6414 6415 6416 6417 6418 6419 6420 6421 6422 6423 6424 6425 6426 6427 6428 6429 6430 6431 6432 6433 6434 6435 6436 6437 6438 6439 6440 6441 6442 6443 6444 6445 6446 6447 6448 6449 6450 6451 6452 6453 6454 6455 6456 6457 6458 6459 6460 6461 6462 6463 6464 6465 6466 6467 6468 6469 6470 6471 6472 6473 6474 6475 6476 6477 6478 6479 6480 6481 6482 6483 6484 6485 6486 6487 6488 6489 6490 6491 6492 6493 6494 6495 6496 6497 6498 6499 6500 6501 6502 6503 6504 6505 6506 6507 6508 6509 6510 6511 6512 6513 6514 6515 6516 6517 6518 6519 6520 6521 6522 6523 6524 6525 6526 6527 6528 6529 6530 6531 6532 6533 6534 6535 6536 6537 6538 6539 6540 6541 6542 6543 6544 6545 6546 6547 6548 6549 6550 6551 6552 6553 6554 6555 6556 6557 6558 6559 6560 6561 6562 6563 6564 6565 6566 6567 6568 6569 6570 6571 6572 6573 6574 6575 6576 6577 6578 6579 6580 6581 6582 6583 6584 6585 6586 6587 6588 6589 6590 6591 6592 6593 6594 6595 6596 6597 6598 6599 6600 6601 6602 6603 6604 6605 6606 6607 6608 6609 6610 6611 6612 6613 6614 6615 6616 6617 6618 6619 6620 6621 6622 6623 6624 6625 6626 6627 6628 6629 6630 6631 6632 6633 6634 6635 6636 6637 6638 6639 6640 6641 6642 6643 6644 6645 6646 6647 6648 6649 6650 6651 6652 6653 6654 6655 6656 6657 6658 6659 6660 6661 6662 6663 6664 6665 6666 6667 6668 6669 6670 6671 6672 6673 6674 6675 6676 6677 6678 6679 6680 6681 6682 6683 6684 6685 6686 6687 6688 6689 6690 6691 6692 6693 6694 6695 6696 6697 6698 6699 6700 6701 6702 6703 6704 6705 6706 6707 6708 6709 6710 6711 6712 6713 6714 6715 6716 6717 6718 6719 6720 6721 6722 6723 6724 6725 6726 6727 6728 6729 6730 6731 6732 6733 6734 6735 6736 6737 6738 6739 6740 6741 6742 6743 6744 6745 6746 6747 6748 6749 6750 6751 6752 6753 6754 6755 6756 6757 6758 6759 6760 6761 6762 6763 6764 6765 6766 6767 6768 6769 6770 6771 6772 6773 6774 6775 6776 6777 6778 6779 6780 6781 6782 6783 6784 6785 6786 6787 6788 6789 6790 6791 6792 6793 6794 6795 6796 6797
|
/*
* Copyright (C) Volition, Inc. 1999. All rights reserved.
*
* All source code herein is the property of Volition, Inc. You may not sell
* or otherwise commercially exploit the source or things you created based on the
* source.
*
*/
#include "weapon/weapon.h"
#include "render/3d.h"
#include "object/object.h"
#include "ship/ship.h"
#include "fireball/fireballs.h"
#include "playerman/player.h"
#include "freespace2/freespace.h"
#include "radar/radar.h"
#include "globalincs/linklist.h"
#include "io/timer.h"
#include "gamesnd/gamesnd.h"
#include "cmeasure/cmeasure.h"
#include "math/staticrand.h"
#include "weapon/swarm.h"
#include "ship/shiphit.h"
#include "hud/hud.h"
#include "object/objcollide.h"
#include "ai/aibig.h"
#include "particle/particle.h"
#include "asteroid/asteroid.h"
#include "io/joy_ff.h"
#include "weapon/corkscrew.h"
#include "weapon/emp.h"
#include "localization/localize.h"
#include "weapon/flak.h"
#include "weapon/muzzleflash.h"
#include "cmdline/cmdline.h"
#include "graphics/grbatch.h"
#include "parse/parselo.h"
#include "radar/radarsetup.h"
#include "weapon/beam.h" // for BEAM_TYPE_? definitions
#include "iff_defs/iff_defs.h"
#include "network/multi.h"
#include "network/multimsgs.h"
#include "network/multiutil.h"
#include "parse/scripting.h"
#include "stats/scoring.h"
#include "mod_table/mod_table.h"
#ifndef NDEBUG
int Weapon_flyby_sound_enabled = 1;
DCF_BOOL( weapon_flyby, Weapon_flyby_sound_enabled )
#endif
static int Weapon_flyby_sound_timer;
weapon Weapons[MAX_WEAPONS];
weapon_info Weapon_info[MAX_WEAPON_TYPES];
#define MISSILE_OBJ_USED (1<<0) // flag used in missile_obj struct
#define MAX_MISSILE_OBJS MAX_WEAPONS // max number of missiles tracked in missile list
missile_obj Missile_objs[MAX_MISSILE_OBJS]; // array used to store missile object indexes
missile_obj Missile_obj_list; // head of linked list of missile_obj structs
//WEAPON SUBTYPE STUFF
char *Weapon_subtype_names[] = {
"Laser",
"Missile",
"Beam"
};
int Num_weapon_subtypes = sizeof(Weapon_subtype_names)/sizeof(char *);
flag_def_list Burst_fire_flags[] = {
{ "fast firing", WBF_FAST_FIRING, 0 },
{ "random length", WBF_RANDOM_LENGTH, 0 }
};
int Num_burst_fire_flags = sizeof(Burst_fire_flags)/sizeof(flag_def_list);
weapon_explosions Weapon_explosions;
SCP_vector<lod_checker> LOD_checker;
int Num_weapon_types = 0;
int Num_weapons = 0;
int Weapons_inited = 0;
int Weapon_expl_initted = 0;
int laser_model_inner = -1;
int laser_model_outer = -1;
int missile_model = -1;
int First_secondary_index = -1;
int Default_cmeasure_index = -1;
static int *used_weapons = NULL;
int Num_spawn_types = 0;
char **Spawn_names = NULL;
int Num_player_weapon_precedence; // Number of weapon types in Player_weapon_precedence
int Player_weapon_precedence[MAX_WEAPON_TYPES]; // Array of weapon types, precedence list for player weapon selection
// Used to avoid playing too many impact sounds in too short a time interval.
// This will elimate the odd "stereo" effect that occurs when two weapons impact at
// nearly the same time, like from a double laser (also saves sound channels!)
#define IMPACT_SOUND_DELTA 50 // in milliseconds
int Weapon_impact_timer; // timer, initialized at start of each mission
// energy suck defines
#define ESUCK_DEFAULT_WEAPON_REDUCE (10.0f)
#define ESUCK_DEFAULT_AFTERBURNER_REDUCE (10.0f)
// scale factor for supercaps taking damage from weapons which are not "supercap" weapons
#define SUPERCAP_DAMAGE_SCALE 0.25f
// scale factor for big ships getting hit by flak
#define FLAK_DAMAGE_SCALE 0.05f
//default time of a homing weapon to not home
#define HOMING_DEFAULT_FREE_FLIGHT_TIME 0.5f
// time delay between each swarm missile that is fired
#define SWARM_MISSILE_DELAY 150
// homing missiles have an extended lifetime so they don't appear to run out of gas before they can hit a moving target at extreme
// range. Check the comment in weapon_set_tracking_info() for more details
#define LOCKED_HOMING_EXTENDED_LIFE_FACTOR 1.2f
extern int compute_num_homing_objects(object *target_objp);
extern void fs2netd_add_table_validation(char *tblname);
weapon_explosions::weapon_explosions()
{
ExplosionInfo.clear();
}
int weapon_explosions::GetIndex(char *filename)
{
if ( filename == NULL ) {
Int3();
return -1;
}
for (size_t i = 0; i < ExplosionInfo.size(); i++) {
if ( !stricmp(ExplosionInfo[i].lod[0].filename, filename)) {
return (int)i;
}
}
return -1;
}
int weapon_explosions::Load(char *filename, int expected_lods)
{
char name_tmp[MAX_FILENAME_LEN] = "";
int bitmap_id = -1;
int nframes, nfps;
weapon_expl_info new_wei;
Assert( expected_lods <= MAX_WEAPON_EXPL_LOD );
//Check if it exists
int idx = GetIndex(filename);
if (idx != -1)
return idx;
new_wei.lod_count = 1;
strcpy_s(new_wei.lod[0].filename, filename);
new_wei.lod[0].bitmap_id = bm_load_animation(filename, &new_wei.lod[0].num_frames, &new_wei.lod[0].fps, NULL, 1);
if (new_wei.lod[0].bitmap_id < 0) {
Warning(LOCATION, "Weapon explosion '%s' does not have an LOD0 anim!", filename);
// if we don't have the first then it's only safe to assume that the rest are missing or not usable
return -1;
}
// 2 chars for the lod, 4 for the extension that gets added automatically
if ( (MAX_FILENAME_LEN - strlen(filename)) > 6 ) {
for (idx = 1; idx < expected_lods; idx++) {
sprintf(name_tmp, "%s_%d", filename, idx);
bitmap_id = bm_load_animation(name_tmp, &nframes, &nfps, NULL, 1);
if (bitmap_id > 0) {
strcpy_s(new_wei.lod[idx].filename, name_tmp);
new_wei.lod[idx].bitmap_id = bitmap_id;
new_wei.lod[idx].num_frames = nframes;
new_wei.lod[idx].fps = nfps;
new_wei.lod_count++;
} else {
break;
}
}
if (new_wei.lod_count != expected_lods)
Warning(LOCATION, "For '%s', %i of %i LODs are missing!", filename, expected_lods - new_wei.lod_count, expected_lods);
}
else {
Warning(LOCATION, "Filename '%s' is too long to have any LODs.", filename);
}
ExplosionInfo.push_back( new_wei );
return (int)(ExplosionInfo.size() - 1);
}
void weapon_explosions::PageIn(int idx)
{
int i;
if ( (idx < 0) || (idx >= (int)ExplosionInfo.size()) )
return;
weapon_expl_info *wei = &ExplosionInfo[idx];
for ( i = 0; i < wei->lod_count; i++ ) {
if ( wei->lod[i].bitmap_id >= 0 ) {
bm_page_in_xparent_texture( wei->lod[i].bitmap_id, wei->lod[i].num_frames );
}
}
}
int weapon_explosions::GetAnim(int weapon_expl_index, vec3d *pos, float size)
{
if ( (weapon_expl_index < 0) || (weapon_expl_index >= (int)ExplosionInfo.size()) )
return -1;
//Get our weapon expl for the day
weapon_expl_info *wei = &ExplosionInfo[weapon_expl_index];
if (wei->lod_count == 1)
return wei->lod[0].bitmap_id;
// now we have to do some work
vertex v;
int x, y, w, h, bm_size;
int must_stop = 0;
int best_lod = 1;
int behind = 0;
// start the frame
extern int G3_count;
if(!G3_count){
g3_start_frame(1);
must_stop = 1;
}
g3_set_view_matrix(&Eye_position, &Eye_matrix, Eye_fov);
// get extents of the rotated bitmap
g3_rotate_vertex(&v, pos);
// if vertex is behind, find size if in front, then drop down 1 LOD
if (v.codes & CC_BEHIND) {
float dist = vm_vec_dist_quick(&Eye_position, pos);
vec3d temp;
behind = 1;
vm_vec_scale_add(&temp, &Eye_position, &Eye_matrix.vec.fvec, dist);
g3_rotate_vertex(&v, &temp);
// if still behind, bail and go with default
if (v.codes & CC_BEHIND) {
behind = 0;
}
}
if (!g3_get_bitmap_dims(wei->lod[0].bitmap_id, &v, size, &x, &y, &w, &h, &bm_size)) {
if (Detail.hardware_textures == 4) {
// straight LOD
if(w <= bm_size/8){
best_lod = 3;
} else if(w <= bm_size/2){
best_lod = 2;
} else if(w <= 1.3f*bm_size){
best_lod = 1;
} else {
best_lod = 0;
}
} else {
// less aggressive LOD for lower detail settings
if(w <= bm_size/8){
best_lod = 3;
} else if(w <= bm_size/3){
best_lod = 2;
} else if(w <= (1.15f*bm_size)){
best_lod = 1;
} else {
best_lod = 0;
}
}
}
// if it's behind, bump up LOD by 1
if (behind)
best_lod++;
// end the frame
if (must_stop)
g3_end_frame();
best_lod = MIN(best_lod, wei->lod_count - 1);
Assert( (best_lod >= 0) && (best_lod < MAX_WEAPON_EXPL_LOD) );
return wei->lod[best_lod].bitmap_id;
}
void parse_weapon_expl_tbl(char *filename)
{
int rval;
uint i;
lod_checker lod_check;
// open localization
lcl_ext_open();
if ((rval = setjmp(parse_abort)) != 0) {
mprintf(("TABLES: Unable to parse '%s'! Error code = %i.\n", filename, rval));
lcl_ext_close();
return;
}
read_file_text(filename, CF_TYPE_TABLES);
reset_parse();
required_string("#Start");
while (required_string_either("#End","$Name:"))
{
memset( &lod_check, 0, sizeof(lod_checker) );
// base filename
required_string("$Name:");
stuff_string(lod_check.filename, F_NAME, MAX_FILENAME_LEN);
//Do we have an LOD num
if (optional_string("$LOD:"))
{
stuff_int(&lod_check.num_lods);
}
// only bother with this if we have 1 or more lods and less than max lods,
// otherwise the stardard level loading will take care of the different effects
if ( (lod_check.num_lods > 0) || (lod_check.num_lods < MAX_WEAPON_EXPL_LOD) ) {
// name check, update lod count if it already exists
for (i = 0; i < LOD_checker.size(); i++) {
if ( !stricmp(LOD_checker[i].filename, lod_check.filename) ) {
LOD_checker[i].num_lods = lod_check.num_lods;
}
}
// old entry not found, add new entry
if ( i == LOD_checker.size() ) {
LOD_checker.push_back(lod_check);
}
}
}
required_string("#End");
// close localization
lcl_ext_close();
}
/**
* Clear out the Missile_obj_list
*/
void missile_obj_list_init()
{
int i;
list_init(&Missile_obj_list);
for ( i = 0; i < MAX_MISSILE_OBJS; i++ ) {
Missile_objs[i].flags = 0;
}
}
/**
* Add a node from the Missile_obj_list.
* @note Only called from weapon_create()
*/
int missile_obj_list_add(int objnum)
{
int i;
for ( i = 0; i < MAX_MISSILE_OBJS; i++ ) {
if ( !(Missile_objs[i].flags & MISSILE_OBJ_USED) )
break;
}
if ( i == MAX_MISSILE_OBJS ) {
Error(LOCATION, "Fatal Error: Ran out of missile object nodes\n");
return -1;
}
Missile_objs[i].flags = 0;
Missile_objs[i].objnum = objnum;
list_append(&Missile_obj_list, &Missile_objs[i]);
Missile_objs[i].flags |= MISSILE_OBJ_USED;
return i;
}
/**
* Remove a node from the Missile_obj_list.
* @note Only called from weapon_delete()
*/
void missle_obj_list_remove(int index)
{
Assert(index >= 0 && index < MAX_MISSILE_OBJS);
list_remove(&Missile_obj_list, &Missile_objs[index]);
Missile_objs[index].flags = 0;
}
/**
* Called by the save/restore code to rebuild Missile_obj_list
*/
void missile_obj_list_rebuild()
{
object *objp;
missile_obj_list_init();
for ( objp = GET_FIRST(&obj_used_list); objp !=END_OF_LIST(&obj_used_list); objp = GET_NEXT(objp) ) {
if ( objp->type == OBJ_WEAPON && Weapon_info[Weapons[objp->instance].weapon_info_index].subtype == WP_MISSILE ) {
Weapons[objp->instance].missile_list_index = missile_obj_list_add(OBJ_INDEX(objp));
}
}
}
/**
* Called externally to generate an address from an index into
* the Missile_objs[] array
*/
missile_obj *missile_obj_return_address(int index)
{
Assert(index >= 0 && index < MAX_MISSILE_OBJS);
return &Missile_objs[index];
}
/**
* Return the index of Weapon_info[].name that is *name.
*/
int weapon_info_lookup(const char *name)
{
// bogus
if (name == NULL)
return -1;
for (int i=0; i<Num_weapon_types; i++)
if (!stricmp(name, Weapon_info[i].name))
return i;
return -1;
}
#define DEFAULT_WEAPON_SPAWN_COUNT 10
// Parse the weapon flags.
void parse_wi_flags(weapon_info *weaponp, int wi_flags, int wi_flags2, int wi_flags3)
{
const char *spawn_str = NOX("Spawn");
const size_t spawn_str_len = strlen(spawn_str);
//Make sure we HAVE flags :p
if(!optional_string("$Flags:"))
return;
char weapon_strings[MAX_WEAPON_FLAGS][NAME_LENGTH];
int num_strings;
num_strings = stuff_string_list(weapon_strings, MAX_WEAPON_FLAGS);
if (optional_string("+override")) {
// reseting the flag values if set to override the existing flags
weaponp->wi_flags = wi_flags;
weaponp->wi_flags2 = wi_flags2;
weaponp->wi_flags3 = wi_flags3;
}
bool set_pierce = false;
bool set_nopierce = false;
for (int i=0; i<num_strings; i++) {
if (!strnicmp(spawn_str, weapon_strings[i], 5))
{
if (weaponp->num_spawn_weapons_defined < MAX_SPAWN_TYPES_PER_WEAPON)
{
//We need more spawning slots
//allocate in slots of 10
if((Num_spawn_types % 10) == 0) {
Spawn_names = (char **)vm_realloc(Spawn_names, (Num_spawn_types + 10) * sizeof(*Spawn_names));
}
int skip_length, name_length;
char *temp_string;
temp_string = weapon_strings[i];
weaponp->wi_flags |= WIF_SPAWN;
weaponp->spawn_info[weaponp->num_spawn_weapons_defined].spawn_type = (short)Num_spawn_types;
skip_length = spawn_str_len + strspn(&temp_string[spawn_str_len], NOX(" \t"));
char *num_start = strchr(&temp_string[skip_length], ',');
if (num_start == NULL) {
weaponp->spawn_info[weaponp->num_spawn_weapons_defined].spawn_count = DEFAULT_WEAPON_SPAWN_COUNT;
name_length = 999;
} else {
weaponp->spawn_info[weaponp->num_spawn_weapons_defined].spawn_count = (short)atoi(num_start+1);
name_length = num_start - temp_string - skip_length;
}
weaponp->total_children_spawned += weaponp->spawn_info[weaponp->num_spawn_weapons_defined].spawn_count;
Spawn_names[Num_spawn_types] = vm_strndup( &weapon_strings[i][skip_length], name_length );
Num_spawn_types++;
weaponp->num_spawn_weapons_defined++;
} else {
Warning(LOCATION, "Illegal to have more than %d spawn types for one weapon.\nIgnoring weapon %s", MAX_SPAWN_TYPES_PER_WEAPON, weaponp->name);
}
} else if (!stricmp(NOX("Remote Detonate"), weapon_strings[i]))
weaponp->wi_flags |= WIF_REMOTE;
else if (!stricmp(NOX("Puncture"), weapon_strings[i]))
weaponp->wi_flags |= WIF_PUNCTURE;
else if (!stricmp(NOX("Big Ship"), weapon_strings[i]))
weaponp->wi_flags |= WIF_BIG_ONLY;
else if (!stricmp(NOX("Huge"), weapon_strings[i]))
weaponp->wi_flags |= WIF_HUGE;
else if (!stricmp(NOX("Bomber+"), weapon_strings[i]))
weaponp->wi_flags |= WIF_BOMBER_PLUS;
else if (!stricmp(NOX("child"), weapon_strings[i]))
weaponp->wi_flags |= WIF_CHILD;
else if (!stricmp(NOX("Bomb"), weapon_strings[i]))
weaponp->wi_flags |= WIF_BOMB;
else if (!stricmp(NOX("No Dumbfire"), weapon_strings[i]))
weaponp->wi_flags |= WIF_NO_DUMBFIRE;
else if (!stricmp(NOX("In tech database"), weapon_strings[i]))
weaponp->wi_flags |= WIF_IN_TECH_DATABASE;
else if (!stricmp(NOX("Player allowed"), weapon_strings[i]))
weaponp->wi_flags |= WIF_PLAYER_ALLOWED;
else if (!stricmp(NOX("Particle Spew"), weapon_strings[i]))
weaponp->wi_flags |= WIF_PARTICLE_SPEW;
else if (!stricmp(NOX("EMP"), weapon_strings[i]))
weaponp->wi_flags |= WIF_EMP;
else if (!stricmp(NOX("Esuck"), weapon_strings[i]))
weaponp->wi_flags |= WIF_ENERGY_SUCK;
else if (!stricmp(NOX("Flak"), weapon_strings[i]))
weaponp->wi_flags |= WIF_FLAK;
else if (!stricmp(NOX("Corkscrew"), weapon_strings[i]))
weaponp->wi_flags |= WIF_CORKSCREW;
else if (!stricmp(NOX("Shudder"), weapon_strings[i]))
weaponp->wi_flags |= WIF_SHUDDER;
else if (!stricmp(NOX("Electronics"), weapon_strings[i]))
weaponp->wi_flags |= WIF_ELECTRONICS;
else if (!stricmp(NOX("lockarm"), weapon_strings[i]))
weaponp->wi_flags |= WIF_LOCKARM;
else if (!stricmp(NOX("beam"), weapon_strings[i]))
{
weaponp->wi_flags |= WIF_BEAM;
// IMPORTANT: beams pierce shields by default :rolleyes: :p - Goober5000
weaponp->wi_flags2 |= WIF2_PIERCE_SHIELDS;
}
else if (!stricmp(NOX("stream"), weapon_strings[i]))
weaponp->wi_flags |= WIF_STREAM;
else if (!stricmp(NOX("supercap"), weapon_strings[i]))
weaponp->wi_flags |= WIF_SUPERCAP;
else if (!stricmp(NOX("countermeasure"), weapon_strings[i]))
weaponp->wi_flags |= WIF_CMEASURE;
else if (!stricmp(NOX("ballistic"), weapon_strings[i]))
weaponp->wi_flags2 |= WIF2_BALLISTIC;
else if (!stricmp(NOX("pierce shields"), weapon_strings[i]))
set_pierce = true;
else if (!stricmp(NOX("no pierce shields"), weapon_strings[i])) // only for beams
set_nopierce = true;
else if (!stricmp(NOX("local ssm"), weapon_strings[i]))
weaponp->wi_flags2 |= WIF2_LOCAL_SSM;
else if (!stricmp(NOX("tagged only"), weapon_strings[i]))
weaponp->wi_flags2 |= WIF2_TAGGED_ONLY;
else if (!stricmp(NOX("beam no whack"), weapon_strings[i]))
{
Warning(LOCATION, "The \"beam no whack\" flag has been deprecated. Set the beam's mass to 0 instead. This has been done for you.\n");
weaponp->mass = 0.0f;
}
else if (!stricmp(NOX("cycle"), weapon_strings[i]))
weaponp->wi_flags2 |= WIF2_CYCLE;
else if (!stricmp(NOX("small only"), weapon_strings[i]))
weaponp->wi_flags2 |= WIF2_SMALL_ONLY;
else if (!stricmp(NOX("same turret cooldown"), weapon_strings[i]))
weaponp->wi_flags2 |= WIF2_SAME_TURRET_COOLDOWN;
else if (!stricmp(NOX("apply no light"), weapon_strings[i]))
weaponp->wi_flags2 |= WIF2_MR_NO_LIGHTING;
else if (!stricmp(NOX("training"), weapon_strings[i]))
weaponp->wi_flags2 |= WIF2_TRAINING;
else if (!stricmp(NOX("smart spawn"), weapon_strings[i]))
weaponp->wi_flags2 |= WIF2_SMART_SPAWN;
else if (!stricmp(NOX("inherit parent target"), weapon_strings[i]))
weaponp->wi_flags2 |= WIF2_INHERIT_PARENT_TARGET;
else if (!stricmp(NOX("no emp kill"), weapon_strings[i]))
weaponp->wi_flags2 |= WIF2_NO_EMP_KILL;
else if (!stricmp(NOX("untargeted heat seeker"), weapon_strings[i]))
weaponp->wi_flags2 |= WIF2_UNTARGETED_HEAT_SEEKER;
else if (!stricmp(NOX("no radius doubling"), weapon_strings[i])) {
if (weaponp->wi_flags & WIF_BOMB) {
weaponp->wi_flags2 |= WIF2_HARD_TARGET_BOMB;
}
else {
Warning(LOCATION, "Weapon %s is not a bomb but has \"no radius doubling\" set. Ignoring this flag", weaponp->name);
}
}
else if (!stricmp(NOX("no subsystem homing"), weapon_strings[i]))
weaponp->wi_flags2 |= WIF2_NON_SUBSYS_HOMING;
else if (!stricmp(NOX("no lifeleft penalty"), weapon_strings[i]))
weaponp->wi_flags2 |= WIF2_NO_LIFE_LOST_IF_MISSED;
else if (!stricmp(NOX("can be targeted"), weapon_strings[i]))
weaponp->wi_flags2 |= WIF2_CAN_BE_TARGETED;
else if (!stricmp(NOX("show on radar"), weapon_strings[i]))
weaponp->wi_flags2 |= WIF2_SHOWN_ON_RADAR;
else if (!stricmp(NOX("show friendly on radar"), weapon_strings[i]))
weaponp->wi_flags2 |= WIF2_SHOW_FRIENDLY;
else if (!stricmp(NOX("capital+"), weapon_strings[i]))
weaponp->wi_flags2 |= WIF2_CAPITAL_PLUS;
else if (!stricmp(NOX("chain external model fps"), weapon_strings[i]))
weaponp->wi_flags2 |= WIF2_EXTERNAL_WEAPON_FP;
else if (!stricmp(NOX("external model launcher"), weapon_strings[i]))
weaponp->wi_flags2 |= WIF2_EXTERNAL_WEAPON_LNCH;
else if (!stricmp(NOX("takes blast damage"), weapon_strings[i]))
weaponp->wi_flags2 |= WIF2_TAKES_BLAST_DAMAGE;
else if (!stricmp(NOX("takes shockwave damage"), weapon_strings[i]))
weaponp->wi_flags2 |= WIF2_TAKES_SHOCKWAVE_DAMAGE;
else if (!stricmp(NOX("hide from radar"), weapon_strings[i]))
weaponp->wi_flags2 |= WIF2_DONT_SHOW_ON_RADAR;
else if (!stricmp(NOX("render flak"), weapon_strings[i]))
weaponp->wi_flags2 |= WIF2_RENDER_FLAK;
else if (!stricmp(NOX("ciws"), weapon_strings[i]))
weaponp->wi_flags2 |= WIF2_CIWS;
else if (!stricmp(NOX("anti-subsystem beam"), weapon_strings[i]))
weaponp->wi_flags2 |= WIF2_ANTISUBSYSBEAM;
else if (!stricmp(NOX("no primary linking"), weapon_strings[i]))
weaponp->wi_flags3 |= WIF3_NOLINK;
else if (!stricmp(NOX("same emp time for capships"), weapon_strings[i]))
weaponp->wi_flags3 |= WIF3_USE_EMP_TIME_FOR_CAPSHIP_TURRETS;
else
Warning(LOCATION, "Bogus string in weapon flags: %s\n", weapon_strings[i]);
}
// Goober5000 - fix up pierce/nopierce flags, per Mantis #2442
if (set_pierce)
weaponp->wi_flags2 |= WIF2_PIERCE_SHIELDS;
if (set_nopierce)
weaponp->wi_flags2 &= ~WIF2_PIERCE_SHIELDS;
// set default tech room status - Goober5000
if (weaponp->wi_flags & WIF_IN_TECH_DATABASE)
weaponp->wi_flags2 |= WIF2_DEFAULT_IN_TECH_DATABASE;
// SWARM, CORKSCREW and FLAK should be mutually exclusive
if (weaponp->wi_flags & WIF_FLAK)
{
if ((weaponp->wi_flags & WIF_SWARM) || (weaponp->wi_flags & WIF_CORKSCREW))
{
Warning(LOCATION, "Swarm, Corkscrew, and Flak are mutually exclusive! Removing Swarm and Corkscrew attributes.\n");
weaponp->wi_flags &= ~WIF_SWARM;
weaponp->wi_flags &= ~WIF_CORKSCREW;
}
}
else
{
if ((weaponp->wi_flags & WIF_SWARM) && (weaponp->wi_flags & WIF_CORKSCREW))
{
Warning(LOCATION, "Swarm and Corkscrew are mutually exclusive! Defaulting to Swarm.\n");
weaponp->wi_flags &= ~WIF_CORKSCREW;
}
}
if (weaponp->wi_flags2 & WIF2_LOCAL_SSM)
{
if (!(weaponp->wi_flags & WIF_HOMING) || (weaponp->subtype !=WP_MISSILE))
{
Warning(LOCATION, "local ssm must be guided missile: %s", weaponp->name);
}
}
if ((weaponp->wi_flags2 & WIF2_SMALL_ONLY) && (weaponp->wi_flags & WIF_HUGE))
{
Warning(LOCATION,"\"small only\" and \"huge\" flags are mutually exclusive.\nThey are used together in %s\nAI will most likely not use this weapon",weaponp->name);
}
if (!(weaponp->wi_flags & WIF_SPAWN) && (weaponp->wi_flags2 & WIF2_SMART_SPAWN))
{
Warning(LOCATION,"\"smart spawn\" flag used without \"spawn\" flag in %s\n",weaponp->name);
}
if ((weaponp->wi_flags2 & WIF2_INHERIT_PARENT_TARGET) && (!(weaponp->wi_flags & WIF_CHILD)))
{
Warning(LOCATION,"Weapon %s has the \"inherit parent target\" flag, but not the \"child\" flag. No changes in behavior will occur.", weaponp->name);
}
if (!(weaponp->wi_flags & WIF_HOMING_HEAT) && (weaponp->wi_flags2 & WIF2_UNTARGETED_HEAT_SEEKER))
{
Warning(LOCATION,"Weapon '%s' has the \"untargeted heat seeker\" flag, but Homing Type is not set to \"HEAT\".", weaponp->name);
}
}
void parse_shockwave_info(shockwave_create_info *sci, char *pre_char)
{
char buf[NAME_LENGTH];
sprintf(buf, "%sShockwave damage:", pre_char);
if(optional_string(buf)) {
stuff_float(&sci->damage);
}
sprintf(buf, "%sShockwave damage type:", pre_char);
if(optional_string(buf)) {
stuff_string(buf, F_NAME, NAME_LENGTH);
sci->damage_type_idx_sav = damage_type_add(buf);
sci->damage_type_idx = sci->damage_type_idx_sav;
}
sprintf(buf, "%sBlast Force:", pre_char);
if(optional_string(buf)) {
stuff_float(&sci->blast);
}
sprintf(buf, "%sInner Radius:", pre_char);
if(optional_string(buf)) {
stuff_float(&sci->inner_rad);
}
sprintf(buf, "%sOuter Radius:", pre_char);
if(optional_string(buf)) {
stuff_float(&sci->outer_rad);
}
if (sci->outer_rad < sci->inner_rad) {
Warning(LOCATION, "Shockwave outer radius must be greater than or equal to the inner radius!");
sci->outer_rad = sci->inner_rad;
}
sprintf(buf, "%sShockwave Speed:", pre_char);
if(optional_string(buf)) {
stuff_float(&sci->speed);
}
sprintf(buf, "%sShockwave Rotation:", pre_char);
if(optional_string(buf)) {
float angs[3];
stuff_float_list(angs, 3);
for(int i = 0; i < 3; i++)
{
angs[i] = angs[i] * (PI2/180.0f);
while(angs[i] < 0)
{
angs[i] += PI2;
}
while(angs[i] > PI2)
{
angs[i] -= PI2;
}
}
sci->rot_angles.p = angs[0];
sci->rot_angles.b = angs[1];
sci->rot_angles.h = angs[2];
}
sprintf(buf, "%sShockwave Model:", pre_char);
if(optional_string(buf)) {
stuff_string(sci->pof_name, F_NAME, MAX_FILENAME_LEN);
}
sprintf(buf, "%sShockwave Name:", pre_char);
if(optional_string(buf)) {
stuff_string(sci->name, F_NAME, MAX_FILENAME_LEN);
}
}
void init_weapon_entry(int weap_info_index)
{
Assert(weap_info_index > -1 && weap_info_index < MAX_WEAPON_TYPES);
weapon_info *wip = &Weapon_info[weap_info_index];
int i, j;
wip->wi_flags = WIF_DEFAULT_VALUE;
wip->wi_flags2 = WIF2_DEFAULT_VALUE;
wip->subtype = WP_UNUSED;
wip->render_type = WRT_NONE;
wip->title[0] = 0;
wip->desc = NULL;
wip->tech_title[0] = 0;
wip->tech_anim_filename[0] = 0;
wip->tech_desc = NULL;
wip->tech_model[0] = '\0';
wip->hud_filename[0] = '\0';
wip->hud_image_index = -1;
wip->pofbitmap_name[0] = '\0';
wip->model_num = -1;
wip->hud_target_lod = -1;
wip->num_detail_levels = -1;
for ( i = 0; i < MAX_MODEL_DETAIL_LEVELS; i++ )
{
wip->detail_distance[i] = -1;
}
vm_vec_zero(&wip->closeup_pos);
wip->closeup_zoom = 1.0f;
generic_anim_init(&wip->laser_bitmap);
generic_anim_init(&wip->laser_glow_bitmap);
gr_init_color(&wip->laser_color_1, 255, 255, 255);
gr_init_color(&wip->laser_color_2, 255, 255, 255);
wip->laser_length = 10.0f;
wip->laser_head_radius = 1.0f;
wip->laser_tail_radius = 1.0f;
wip->external_model_name[0] = '\0';
wip->external_model_num = -1;
wip->weapon_submodel_rotate_accell = 10.0f;
wip->weapon_submodel_rotate_vel = 0.0f;
wip->mass = 1.0f;
wip->max_speed = 10.0f;
wip->free_flight_time = 0.0f;
wip->fire_wait = 1.0f;
wip->damage = 0.0f;
wip->damage_type_idx = -1;
wip->damage_type_idx_sav = -1;
wip->armor_type_idx = -1;
wip->arm_time = 0;
wip->arm_dist = 0.0f;
wip->arm_radius = 0.0f;
wip->det_range = 0.0f;
wip->det_radius = 0.0f;
wip->flak_targeting_accuracy = 60.0f; // Standard value as defined in flak.cpp
wip->flak_detonation_accuracy = 65.0f;
wip->untargeted_flak_range_penalty = 20.0f;
wip->armor_factor = 1.0f;
wip->shield_factor = 1.0f;
wip->subsystem_factor = 1.0f;
wip->life_min = -1.0f;
wip->life_max = -1.0f;
wip->lifetime = 1.0f;
wip->energy_consumed = 0.0f;
wip->cargo_size = 1.0f;
wip->turn_time = 1.0f;
wip->fov = 0; //should be cos(pi), not pi
wip->min_lock_time = 0.0f;
wip->lock_pixels_per_sec = 50;
wip->catchup_pixels_per_sec = 50;
wip->catchup_pixel_penalty = 50;
wip->seeker_strength = 1.0f;
wip->swarm_count = -1;
// *Default is 150 -Et1
wip->SwarmWait = SWARM_MISSILE_DELAY;
wip->pre_launch_snd = -1;
wip->pre_launch_snd_min_interval = 0;
wip->launch_snd = -1;
wip->impact_snd = -1;
wip->disarmed_impact_snd = -1;
wip->flyby_snd = -1;
wip->rearm_rate = 1.0f;
wip->weapon_range = 999999999.9f;
// *Minimum weapon range, default is 0 -Et1
wip->WeaponMinRange = 0.0f;
wip->num_spawn_weapons_defined = 0;
for (i = 0; i < MAX_SPAWN_TYPES_PER_WEAPON; i++)
{
wip->spawn_info[i].spawn_type = -1;
wip->spawn_info[i].spawn_angle = 180;
wip->spawn_info[i].spawn_count = DEFAULT_WEAPON_SPAWN_COUNT;
}
// Trails
wip->tr_info.pt = vmd_zero_vector;
wip->tr_info.w_start = 1.0f;
wip->tr_info.w_end = 1.0f;
wip->tr_info.a_start = 1.0f;
wip->tr_info.a_end = 1.0f;
wip->tr_info.max_life = 1.0f;
wip->tr_info.stamp = 0;
generic_bitmap_init(&wip->tr_info.texture, NULL);
wip->tr_info.n_fade_out_sections = 0;
wip->icon_filename[0] = 0;
wip->anim_filename[0] = 0;
wip->impact_explosion_radius = 1.0f;
wip->impact_weapon_expl_index = -1;
wip->dinky_impact_explosion_radius = 1.0f;
wip->dinky_impact_weapon_expl_index = -1;
wip->flash_impact_weapon_expl_index = -1;
wip->flash_impact_explosion_radius = 0.0f;
wip->piercing_impact_explosion_radius = 0.0f;
wip->piercing_impact_particle_count = 0;
wip->piercing_impact_particle_life = 0.0f;
wip->piercing_impact_particle_velocity = 0.0f;
wip->piercing_impact_weapon_expl_index = -1;
wip->piercing_impact_particle_back_velocity = 0.0f;
wip->piercing_impact_particle_variance = 0.0f;
wip->muzzle_flash = -1;
wip->emp_intensity = EMP_DEFAULT_INTENSITY;
wip->emp_time = EMP_DEFAULT_TIME; // Goober5000: <-- Look! I fixed a Volition bug! Gimme $5, Dave!
wip->weapon_reduce = ESUCK_DEFAULT_WEAPON_REDUCE;
wip->afterburner_reduce = ESUCK_DEFAULT_AFTERBURNER_REDUCE;
//customizeable corkscrew stuff
wip->cs_num_fired=4;
wip->cs_radius=1.25f;
wip->cs_delay=30;
wip->cs_crotate=1;
wip->cs_twist=5.0f;
wip->elec_time=8000;
wip->elec_eng_mult=1.0f;
wip->elec_weap_mult=1.0f;
wip->elec_beam_mult=1.0f;
wip->elec_sensors_mult=1.0f;
wip->elec_randomness=2000;
wip->elec_use_new_style=0;
wip->lssm_warpout_delay=0; //delay between launch and warpout (ms)
wip->lssm_warpin_delay=0; //delay between warpout and warpin (ms)
wip->lssm_stage5_vel=0; //velocity during final stage
wip->lssm_warpin_radius=0;
wip->lssm_lock_range=1000000.0f; //local ssm lock range (optional)
wip->cm_aspect_effectiveness = 1.0f;
wip->cm_heat_effectiveness = 1.0f;
wip->cm_effective_rad = MAX_CMEASURE_TRACK_DIST;
wip->b_info.beam_type = -1;
wip->b_info.beam_life = -1.0f;
wip->b_info.beam_warmup = -1;
wip->b_info.beam_warmdown = -1;
wip->b_info.beam_muzzle_radius = 0.0f;
wip->b_info.beam_particle_count = -1;
wip->b_info.beam_particle_radius = 0.0f;
wip->b_info.beam_particle_angle = 0.0f;
wip->b_info.beam_loop_sound = -1;
wip->b_info.beam_warmup_sound = -1;
wip->b_info.beam_warmdown_sound = -1;
wip->b_info.beam_num_sections = 0;
wip->b_info.beam_shots = 1;
wip->b_info.beam_shrink_factor = 0.0f;
wip->b_info.beam_shrink_pct = 0.0f;
wip->b_info.range = BEAM_FAR_LENGTH;
wip->b_info.damage_threshold = 1.0f;
wip->b_info.beam_width = -1.0f;
generic_anim_init(&wip->b_info.beam_glow, NULL);
generic_anim_init(&wip->b_info.beam_particle_ani, NULL);
for (i = 0; i < MAX_IFFS; i++)
for (j = 0; j < NUM_SKILL_LEVELS; j++)
wip->b_info.beam_iff_miss_factor[i][j] = 0.00001f;
//WMC - Okay, so this is needed now
beam_weapon_section_info *bsip;
for (i = 0; i < MAX_BEAM_SECTIONS; i++) {
bsip = &wip->b_info.sections[i];
generic_anim_init(&bsip->texture, NULL);
bsip->width = 1.0f;
bsip->flicker = 0.1f;
bsip->z_add = i2fl(MAX_BEAM_SECTIONS - i - 1);
bsip->tile_type = 0;
bsip->tile_factor = 1.0f;
bsip->translation = 0.0f;
}
for (size_t s = 0; s < MAX_PARTICLE_SPEWERS; s++) { // default values for everything -nuke
wip->particle_spewers[s].particle_spew_type = PSPEW_NONE; // added by nuke
wip->particle_spewers[s].particle_spew_count = 1;
wip->particle_spewers[s].particle_spew_time = 25;
wip->particle_spewers[s].particle_spew_vel = 0.4f;
wip->particle_spewers[s].particle_spew_radius = 2.0f;
wip->particle_spewers[s].particle_spew_lifetime = 0.15f;
wip->particle_spewers[s].particle_spew_scale = 0.8f;
wip->particle_spewers[s].particle_spew_z_scale = 1.0f; // added by nuke
wip->particle_spewers[s].particle_spew_rotation_rate = 10.0f;
wip->particle_spewers[s].particle_spew_offset = vmd_zero_vector;
wip->particle_spewers[s].particle_spew_velocity = vmd_zero_vector;
generic_anim_init(&wip->particle_spewers[s].particle_spew_anim, NULL);
}
wip->tag_level = -1;
wip->tag_time = -1.0f;
wip->SSM_index =-1; // tag C SSM index, wich entry in the SSM table this weapon calls -Bobboau
wip->field_of_fire = 0.0f;
wip->fof_spread_rate = 0.0f;
wip->fof_reset_rate = 0.0f;
wip->max_fof_spread = 0.0f;
wip->shots = 1;
wip->alpha_max = 1.0f;
wip->alpha_min = 0.0f;
wip->alpha_cycle = 0.0f;
// this can get reset after the constructor, so be sure it's correct
wip->shockwave.damage_type_idx = -1;
wip->shockwave.damage_type_idx_sav = -1;
wip->weapon_hitpoints = 0;
wip->burst_delay = 1.0f; // 1 second, just incase its not defined
wip->burst_shots = 0;
wip->burst_flags = 0;
generic_anim_init( &wip->thruster_flame );
generic_anim_init( &wip->thruster_glow );
wip->thruster_glow_factor = 1.0f;
wip->target_lead_scaler = 0.0f;
wip->selection_effect = Default_weapon_select_effect;
wip->hud_locked_snd = -1;
wip->hud_tracking_snd = -1;
wip->hud_in_flight_snd = -1;
}
// function to parse the information for a specific weapon type.
// return 0 if successful, otherwise return -1
#define WEAPONS_MULTITEXT_LENGTH 2048
int parse_weapon(int subtype, bool replace)
{
char buf[WEAPONS_MULTITEXT_LENGTH];
weapon_info *wip = NULL;
char fname[NAME_LENGTH];
int iff, idx;
int primary_rearm_rate_specified=0;
bool first_time = false;
bool create_if_not_found = true;
int wi_flags = WIF_DEFAULT_VALUE;
int wi_flags2 = WIF2_DEFAULT_VALUE;
int wi_flags3 = WIF3_DEFAULT_VALUE;
required_string("$Name:");
stuff_string(fname, F_NAME, NAME_LENGTH);
diag_printf ("Weapon name -- %s\n", fname);
if(optional_string("+nocreate")) {
if(!replace) {
Warning(LOCATION, "+nocreate flag used for weapon in non-modular table");
}
create_if_not_found = false;
}
strcpy_s(parse_error_text, "");
strcpy_s(parse_error_text, "\nin weapon: ");
strcat_s(parse_error_text, fname);
strcat_s(parse_error_text, "\n");
//Remove @ symbol
//these used to be used to denote weapons that would
//only be parsed in demo builds
if ( fname[0] == '@' ) {
backspace(fname);
}
int w_id = weapon_info_lookup(fname);
if(w_id != -1)
{
wip = &Weapon_info[w_id];
if(!replace)
{
Warning(LOCATION, "Weapon name %s already exists in weapons.tbl. All weapon names must be unique; the second entry has been skipped", wip->name);
if ( !skip_to_start_of_string_either("$Name:", "#End")) {
Int3();
}
return -1;
}
}
else
{
//Don't create weapon if it has +nocreate and is in a modular table.
if(!create_if_not_found && replace)
{
if ( !skip_to_start_of_string_either("$Name:", "#End")) {
Int3();
}
return -1;
}
if(Num_weapon_types >= MAX_WEAPON_TYPES) {
Warning(LOCATION, "Too many weapon classes before '%s'; maximum is %d, so only the first %d will be used", fname, MAX_WEAPON_TYPES, Num_weapon_types);
//Skip the rest of the ships in non-modular tables, since we can't add them.
if(!replace) {
if ( !skip_to_start_of_string_either("$Name:", "#End")) {
Int3();
}
}
return -1;
}
wip = &Weapon_info[Num_weapon_types];
init_weapon_entry(Num_weapon_types);
first_time = true;
strcpy_s(wip->name, fname);
Num_weapon_types++;
}
if(optional_string("$Alt name:"))
stuff_string(wip->alt_name, F_NAME, NAME_LENGTH);
//Set subtype
if(optional_string("$Subtype:"))
{
stuff_string(fname, F_NAME, NAME_LENGTH);
if(!stricmp("Primary", fname)) {
wip->subtype = WP_LASER;
} else if(!stricmp("Secondary", fname)) {
wip->subtype = WP_MISSILE;
} else {
Warning(LOCATION, "Unknown subtype on weapon '%s'", wip->name);
}
}
else if(wip->subtype != WP_UNUSED && !first_time)
{
if(wip->subtype != subtype) {
Warning(LOCATION, "Type of weapon %s entry does not agree with original entry type.", wip->name);
}
}
else
{
wip->subtype = subtype;
}
if (optional_string("+Title:")) {
stuff_string(wip->title, F_NAME, WEAPON_TITLE_LEN);
}
if (optional_string("+Description:")) {
if (wip->desc != NULL) {
vm_free(wip->desc);
wip->desc = NULL;
}
stuff_malloc_string(&wip->desc, F_MULTITEXT);
}
if (optional_string("+Tech Title:")) {
stuff_string(wip->tech_title, F_NAME, NAME_LENGTH);
}
if (optional_string("+Tech Anim:")) {
stuff_string(wip->tech_anim_filename, F_NAME, MAX_FILENAME_LEN);
}
if (optional_string("+Tech Description:")) {
if (wip->tech_desc != NULL) {
vm_free(wip->tech_desc);
wip->tech_desc = NULL;
}
stuff_malloc_string(&wip->tech_desc, F_MULTITEXT);
}
if (optional_string("$Tech Model:")) {
stuff_string(wip->tech_model, F_NAME, MAX_FILENAME_LEN);
if (optional_string("+Closeup_pos:")) {
stuff_vec3d(&wip->closeup_pos);
}
if (optional_string("+Closeup_zoom:")) {
stuff_float(&wip->closeup_zoom);
}
}
// Weapon fadein effect, used when no ani is specified or weapon_select_3d is active
wip->selection_effect = Default_weapon_select_effect; // By default, use the FS2 effect
if(optional_string("$Selection Effect:")) {
char effect[NAME_LENGTH];
stuff_string(effect, F_NAME, NAME_LENGTH);
if (!stricmp(effect, "FS2"))
wip->selection_effect = 2;
else if (!stricmp(effect, "FS1"))
wip->selection_effect = 1;
else if (!stricmp(effect, "off"))
wip->selection_effect = 0;
}
//Check for the HUD image string
if(optional_string("$HUD Image:")) {
stuff_string(wip->hud_filename, F_NAME, MAX_FILENAME_LEN);
}
// Read the model file. It can be a POF file or none.
// If there is no model file (Model file: = "none") then we use our special
// laser renderer which requires inner, middle and outer information.
if ( optional_string("$Model file:") ) {
stuff_string(wip->pofbitmap_name, F_NAME, MAX_FILENAME_LEN);
if ( VALID_FNAME(wip->pofbitmap_name) )
wip->render_type = WRT_POF;
diag_printf("Model pof file -- %s\n", wip->pofbitmap_name );
}
// a special LOD level to use when rendering the weapon in the hud targetbox
if ( optional_string( "$POF target LOD:" ) )
stuff_int(&wip->hud_target_lod);
if(optional_string("$Detail distance:")) {
wip->num_detail_levels = stuff_int_list(wip->detail_distance, MAX_MODEL_DETAIL_LEVELS, RAW_INTEGER_TYPE);
}
if ( optional_string("$External Model File:") )
stuff_string(wip->external_model_name, F_NAME, MAX_FILENAME_LEN);
if ( optional_string("$Submodel Rotation Speed:") )
stuff_float(&wip->weapon_submodel_rotate_vel);
if ( optional_string("$Submodel Rotation Acceleration:") )
stuff_float(&wip->weapon_submodel_rotate_accell);
// No POF or AVI file specified, render as special laser type.(?)
ubyte r,g,b;
// laser bitmap itself
if ( optional_string("@Laser Bitmap:") ) {
stuff_string(fname, F_NAME, NAME_LENGTH);
if (wip->render_type == WRT_POF) {
mprintf(("WARNING: Weapon '%s' has both LASER and POF render types! Will only use POF type!\n", wip->name));
generic_anim_init(&wip->laser_bitmap, NULL);
} else {
generic_anim_init(&wip->laser_bitmap, fname);
wip->render_type = WRT_LASER;
}
}
// optional laser glow
if ( optional_string("@Laser Glow:") ) {
stuff_string(fname, F_NAME, NAME_LENGTH);
if (wip->render_type != WRT_LASER) {
mprintf(("WARNING: Laser glow specified on non-LASER type weapon (%s)!\n", wip->name));
Int3();
} else {
generic_anim_init(&wip->laser_glow_bitmap, fname);
}
}
if(optional_string("@Laser Color:"))
{
stuff_ubyte(&r);
stuff_ubyte(&g);
stuff_ubyte(&b);
gr_init_color( &wip->laser_color_1, r, g, b );
}
// optional string for cycling laser colors
if(optional_string("@Laser Color2:")){
stuff_ubyte(&r);
stuff_ubyte(&g);
stuff_ubyte(&b);
gr_init_color( &wip->laser_color_2, r, g, b );
} else {
gr_init_color( &wip->laser_color_2, wip->laser_color_1.red, wip->laser_color_1.green, wip->laser_color_1.blue );
}
if(optional_string("@Laser Length:")) {
stuff_float(&wip->laser_length);
}
if(optional_string("@Laser Head Radius:")) {
stuff_float(&wip->laser_head_radius);
}
if(optional_string("@Laser Tail Radius:")) {
stuff_float(&wip->laser_tail_radius );
}
if(optional_string("$Mass:")) {
stuff_float( &(wip->mass) );
// Goober5000 - hack in order to make the beam whack behavior of these three beams match all other beams
// this relies on Bobboau's beam whack hack in beam_apply_whack()
if ((!strcmp(wip->name, "SAAA") && (wip->mass == 4.0f))
|| (!strcmp(wip->name, "MjolnirBeam") && (wip->mass == 1000.0f))
|| (!strcmp(wip->name, "MjolnirBeam#home") && (wip->mass == 1000.0f)))
{
wip->mass = 100.0f;
}
diag_printf ("Weapon mass -- %7.3f\n", wip->mass);
}
if(optional_string("$Velocity:")) {
stuff_float( &(wip->max_speed) );
diag_printf ("Weapon mass -- %7.3f\n", wip->max_speed);
}
if(optional_string("$Fire Wait:")) {
stuff_float( &(wip->fire_wait) );
diag_printf ("Weapon fire wait -- %7.3f\n", wip->fire_wait);
}
if(optional_string("$Damage:")) {
stuff_float(&wip->damage);
//WMC - now that shockwave damage can be set for them individually,
//do this automagically
if(first_time) {
wip->shockwave.damage = wip->damage;
}
}
if(optional_string("$Damage Type:")) {
//This is checked for validity on every armor type
//If it's invalid (or -1), then armor has no effect
stuff_string(buf, F_NAME, WEAPONS_MULTITEXT_LENGTH);
wip->damage_type_idx_sav = damage_type_add(buf);
wip->damage_type_idx = wip->damage_type_idx_sav;
}
if(optional_string("$Arm time:")) {
float flit;
stuff_float(&flit);
wip->arm_time = fl2f(flit);
}
if(optional_string("$Arm distance:")) {
stuff_float(&wip->arm_dist);
}
if(optional_string("$Arm radius:")) {
stuff_float(&wip->arm_radius);
}
if(optional_string("$Detonation Range:")) {
stuff_float(&wip->det_range);
}
if(optional_string("$Detonation Radius:")) {
stuff_float(&wip->det_radius);
}
if(optional_string("$Flak Detonation Accuracy:")) {
stuff_float(&wip->flak_detonation_accuracy);
}
if(optional_string("$Flak Targeting Accuracy:")) {
stuff_float(&wip->flak_targeting_accuracy);
}
if(optional_string("$Untargeted Flak Range Penalty:")) {
stuff_float(&wip->untargeted_flak_range_penalty);
}
parse_shockwave_info(&wip->shockwave, "$");
//Retain compatibility
if(first_time)
{
wip->dinky_shockwave = wip->shockwave;
wip->dinky_shockwave.damage /= 4.0f;
}
if(optional_string("$Dinky shockwave:"))
{
parse_shockwave_info(&wip->dinky_shockwave, "+");
}
if(optional_string("$Armor Factor:")) {
stuff_float(&wip->armor_factor);
}
if(optional_string("$Shield Factor:")) {
stuff_float(&wip->shield_factor);
}
if(optional_string("$Subsystem Factor:")) {
stuff_float(&wip->subsystem_factor);
}
if(optional_string("$Lifetime Min:")) {
stuff_float(&wip->life_min);
if(wip->life_min < 0.0f) {
wip->life_min = 0.0f;
Warning(LOCATION, "Lifetime min for weapon '%s' cannot be less than 0. Setting to 0.\n", wip->name);
}
}
if(optional_string("$Lifetime Max:")) {
stuff_float(&wip->life_max);
if(wip->life_max < 0.0f) {
wip->life_max = 0.0f;
Warning(LOCATION, "Lifetime max for weapon '%s' cannot be less than 0. Setting to 0.\n", wip->name);
} else if (wip->life_max < wip->life_min) {
wip->life_max = wip->life_min + 0.1f;
Warning(LOCATION, "Lifetime max for weapon '%s' cannot be less than its Lifetime Min (%d) value. Setting to %d.\n", wip->name, wip->life_min, wip->life_max);
} else {
wip->lifetime = (wip->life_min+wip->life_max)*0.5f;
}
}
if(wip->life_min >= 0.0f && wip->life_max < 0.0f) {
wip->lifetime = wip->life_min;
wip->life_min = -1.0f;
Warning(LOCATION, "Lifetime min, but not lifetime max, specified for weapon %s. Assuming static lifetime of %.2f seconds.\n", wip->lifetime);
}
if(optional_string("$Lifetime:")) {
if(wip->life_min >= 0.0f || wip->life_max >= 0.0f) {
Warning(LOCATION, "Lifetime min or max specified, but $Lifetime was also specified; min or max will be used.");
}
stuff_float(&wip->lifetime);
}
if(optional_string("$Energy Consumed:")) {
stuff_float(&wip->energy_consumed);
}
// Goober5000: cargo size is checked for div-0 errors... see below (must parse flags first)
if(optional_string("$Cargo Size:"))
{
stuff_float(&wip->cargo_size);
}
bool is_homing=false;
if(optional_string("$Homing:")) {
stuff_boolean(&is_homing);
}
if (is_homing || (wip->wi_flags & WIF_HOMING))
{
char temp_type[NAME_LENGTH];
// the following five items only need to be recorded if the weapon is a homing weapon
if(optional_string("+Type:"))
{
stuff_string(temp_type, F_NAME, NAME_LENGTH);
if (!stricmp(temp_type, NOX("HEAT")))
{
if(wip->wi_flags & WIF_HOMING_ASPECT) {
wip->wi_flags &= ~WIF_HOMING_ASPECT;
}
if(wip->wi_flags & WIF_HOMING_JAVELIN) {
wip->wi_flags &= ~WIF_HOMING_JAVELIN;
}
wip->wi_flags |= WIF_HOMING_HEAT | WIF_TURNS;
wi_flags |= WIF_HOMING_HEAT | WIF_TURNS;
}
else if (!stricmp(temp_type, NOX("ASPECT")))
{
if(wip->wi_flags & WIF_HOMING_HEAT) {
wip->wi_flags &= ~WIF_HOMING_HEAT;
}
if(wip->wi_flags & WIF_HOMING_JAVELIN) {
wip->wi_flags &= ~WIF_HOMING_JAVELIN;
}
wip->wi_flags |= WIF_HOMING_ASPECT | WIF_TURNS;
wi_flags |= WIF_HOMING_ASPECT | WIF_TURNS;
}
else if (!stricmp(temp_type, NOX("JAVELIN")))
{
if(wip->wi_flags & WIF_HOMING_HEAT) {
wip->wi_flags &= ~WIF_HOMING_HEAT;
}
if(wip->wi_flags & WIF_HOMING_ASPECT) {
wip->wi_flags &= ~WIF_HOMING_ASPECT;
}
wip->wi_flags |= (WIF_HOMING_JAVELIN | WIF_TURNS);
wi_flags |= (WIF_HOMING_JAVELIN | WIF_TURNS);
}
//If you want to add another weapon, remember you need to reset
//ALL homing flags.
}
if (wip->wi_flags & WIF_HOMING_HEAT)
{
float view_cone_angle;
if(optional_string("+Turn Time:")) {
stuff_float(&wip->turn_time);
}
if(optional_string("+View Cone:")) {
stuff_float(&view_cone_angle);
wip->fov = (float)cos((float)(ANG_TO_RAD(view_cone_angle/2.0f)));
}
if (optional_string("+Seeker Strength:"))
{
//heat default seeker strength is 3
stuff_float(&wip->seeker_strength);
wip->wi_flags2 |= WIF2_CUSTOM_SEEKER_STR;
if (wip->seeker_strength <= 0)
{
Warning(LOCATION,"Seeker Strength for missile \'%s\' must be greater than zero\nReseting value to default.", wip->name);
wip->seeker_strength = 3.0f;
wip->wi_flags2 &= ~WIF2_CUSTOM_SEEKER_STR;
}
}
else
{
if(!(wip->wi_flags2 & WIF2_CUSTOM_SEEKER_STR))
wip->seeker_strength = 3.0f;
}
if (optional_string("+Target Lead Scaler:"))
{
stuff_float(&wip->target_lead_scaler);
if (wip->target_lead_scaler == 0.0f)
wip->wi_flags2 &= ~WIF2_VARIABLE_LEAD_HOMING;
else {
wip->wi_flags2 |= WIF2_VARIABLE_LEAD_HOMING;
wi_flags2 |= WIF2_VARIABLE_LEAD_HOMING;
}
}
}
else if ((wip->wi_flags & WIF_HOMING_ASPECT) || (wip->wi_flags & WIF_HOMING_JAVELIN))
{
if(optional_string("+Turn Time:")) {
stuff_float(&wip->turn_time);
}
if(optional_string("+View Cone:")) {
float view_cone_angle;
stuff_float(&view_cone_angle);
wip->fov = (float)cos((float)(ANG_TO_RAD(view_cone_angle/2.0f)));
}
if(optional_string("+Min Lock Time:")) { // minimum time (in seconds) to achieve lock
stuff_float(&wip->min_lock_time);
}
if(optional_string("+Lock Pixels/Sec:")) { // pixels/sec moved while locking
stuff_int(&wip->lock_pixels_per_sec);
}
if(optional_string("+Catch-up Pixels/Sec:")) { // pixels/sec moved while catching-up for a lock
stuff_int(&wip->catchup_pixels_per_sec);
}
if(optional_string("+Catch-up Penalty:")) {
// number of extra pixels to move while locking as a penalty for catching up for a lock
stuff_int(&wip->catchup_pixel_penalty);
}
if (optional_string("+Seeker Strength:"))
{
//aspect default seeker strength is 2
stuff_float(&wip->seeker_strength);
wip->wi_flags2 |= WIF2_CUSTOM_SEEKER_STR;
if (wip->seeker_strength <= 0)
{
Warning(LOCATION,"Seeker Strength for missile \'%s\' must be greater than zero\nReseting value to default.", wip->name);
wip->seeker_strength = 2.0f;
wip->wi_flags2 &= ~WIF2_CUSTOM_SEEKER_STR;
}
}
else
{
if(!(wip->wi_flags2 & WIF2_CUSTOM_SEEKER_STR))
wip->seeker_strength = 2.0f;
}
if (optional_string("+Target Lead Scaler:"))
{
stuff_float(&wip->target_lead_scaler);
if (wip->target_lead_scaler == 1.0f)
wip->wi_flags2 &= ~WIF2_VARIABLE_LEAD_HOMING;
else {
wip->wi_flags2 |= WIF2_VARIABLE_LEAD_HOMING;
wi_flags2 |= WIF2_VARIABLE_LEAD_HOMING;
}
}
if (wip->wi_flags & WIF_LOCKED_HOMING) {
// locked homing missiles have a much longer lifespan than the AI think they do
wip->max_lifetime = wip->lifetime * LOCKED_HOMING_EXTENDED_LIFE_FACTOR;
}
}
else
{
Error(LOCATION, "Illegal homing type = %s.\nMust be HEAT, ASPECT or JAVELIN.\n", temp_type);
}
}
// swarm missiles
int s_count;
if(optional_string("$Swarm:"))
{
wip->swarm_count = SWARM_DEFAULT_NUM_MISSILES_FIRED;
stuff_int(&s_count);
wip->swarm_count = (short)s_count;
// flag as being a swarm weapon
wip->wi_flags |= WIF_SWARM;
wi_flags |= WIF_SWARM;
}
// *Swarm wait token -Et1
if((wip->wi_flags & WIF_SWARM) && optional_string( "+SwarmWait:" ))
{
float SwarmWait;
stuff_float( &SwarmWait );
if( SwarmWait > 0.0f && SwarmWait * wip->swarm_count < wip->fire_wait )
{
wip->SwarmWait = int( SwarmWait * 1000 );
}
}
if(optional_string("$Free Flight Time:")) {
stuff_float(&(wip->free_flight_time));
} else if(first_time && is_homing) {
wip->free_flight_time = HOMING_DEFAULT_FREE_FLIGHT_TIME;
}
if(optional_string("$Free Flight Speed:")) {
float temp;
stuff_float(&temp);
nprintf(("Warning", "Ignoring free flight speed for weapon '%s'\n", wip->name));
}
//Optional one-shot sound to play at the beginning of firing
parse_sound("$PreLaunchSnd:", &wip->pre_launch_snd, wip->name);
//Optional delay for Pre-Launch sound
if(optional_string("+PreLaunchSnd Min Interval:"))
{
stuff_int(&wip->pre_launch_snd_min_interval);
}
//Launch sound
parse_sound("$LaunchSnd:", &wip->launch_snd, wip->name);
//Impact sound
parse_sound("$ImpactSnd:", &wip->impact_snd, wip->name);
//Disarmed impact sound
parse_sound("$Disarmed ImpactSnd:", &wip->impact_snd, wip->name);
parse_sound("$FlyBySnd:", &wip->flyby_snd, wip->name);
parse_sound("$TrackingSnd:", &wip->hud_tracking_snd, wip->name);
parse_sound("$LockedSnd:", &wip->hud_locked_snd, wip->name);
parse_sound("$InFlightSnd:", &wip->hud_in_flight_snd, wip->name);
if (optional_string("+Inflight sound type:"))
{
SCP_string type;
stuff_string(type, F_NAME);
if (!stricmp(type.c_str(), "TARGETED"))
{
wip->in_flight_play_type = TARGETED;
}
else if (!stricmp(type.c_str(), "UNTARGETED"))
{
wip->in_flight_play_type = UNTARGETED;
}
else if (!stricmp(type.c_str(), "ALWAYS"))
{
wip->in_flight_play_type = ALWAYS;
}
else
{
Warning(LOCATION, "Unknown in-flight sound type \"%s\"!", type.c_str());
wip->in_flight_play_type = ALWAYS;
}
}
if(optional_string("$Model:"))
{
wip->render_type = WRT_POF;
stuff_string(wip->pofbitmap_name, F_NAME, MAX_FILENAME_LEN);
}
// handle rearm rate - modified by Goober5000
primary_rearm_rate_specified = 0;
float rearm_rate;
// Anticipate rearm rate for ballistic primaries
if (optional_string("$Rearm Rate:"))
{
if (subtype != WP_MISSILE) {
primary_rearm_rate_specified = 1;
}
stuff_float( &rearm_rate );
if (rearm_rate > 0.0f)
{
wip->rearm_rate = 1.0f/rearm_rate;
}
else
{
Warning(LOCATION, "Rearm wait of less than 0 on weapon %s; setting to 1", wip->name);
}
}
if (optional_string("+Weapon Range:")) {
stuff_float(&wip->weapon_range);
}
if( optional_string( "+Weapon Min Range:" ) )
{
float MinRange;
stuff_float( &MinRange );
if( MinRange > 0.0f && MinRange < MIN( wip->max_speed * wip->lifetime, wip->weapon_range ) )
{
wip->WeaponMinRange = MinRange;
}
else
{
Warning(LOCATION, "Invalid minimum range on weapon %s; setting to 0", wip->name);
}
}
parse_wi_flags(wip, wi_flags, wi_flags2, wi_flags3);
// be friendly; make sure ballistic flags are synchronized - Goober5000
// primary
if (subtype == WP_LASER)
{
// ballistic
if (wip->wi_flags2 & WIF2_BALLISTIC)
{
// rearm rate not specified
if (!primary_rearm_rate_specified && first_time)
{
Warning(LOCATION, "$Rearm Rate for ballistic primary %s not specified. Defaulting to 100...\n", wip->name);
wip->rearm_rate = 100.0f;
}
}
// not ballistic
else
{
// rearm rate specified
if (primary_rearm_rate_specified)
{
Warning(LOCATION, "$Rearm Rate specified for non-ballistic primary %s\n", wip->name);
}
}
}
// secondary
else
{
// ballistic
if (wip->wi_flags2 & WIF2_BALLISTIC)
{
Warning(LOCATION, "Secondary weapon %s can't be ballistic. Removing this flag...\n", wip->name);
wip->wi_flags2 &= ~WIF2_BALLISTIC;
}
}
// also make sure EMP is friendly - Goober5000
if (wip->wi_flags & WIF_EMP)
{
if (!wip->shockwave.outer_rad)
{
Warning(LOCATION, "Outer blast radius of weapon %s is zero - EMP will not work.\nAdd $Outer Radius to weapon table entry.\n", wip->name);
}
}
// also make sure secondaries and ballistic primaries do not have 0 cargo size
if (subtype == WP_MISSILE || wip->wi_flags2 & WIF2_BALLISTIC)
{
if (wip->cargo_size == 0.0f)
{
Warning(LOCATION, "Cargo size of weapon %s cannot be 0. Setting to 1.\n", wip->name);
wip->cargo_size = 1.0f;
}
}
if ( optional_string("$Trail:") ) {
trail_info *ti = &wip->tr_info;
wip->wi_flags |= WIF_TRAIL; // missile leaves a trail
if ( optional_string("+Start Width:") )
stuff_float(&ti->w_start);
if ( optional_string("+End Width:") )
stuff_float(&ti->w_end);
if ( optional_string("+Start Alpha:") )
stuff_float(&ti->a_start);
if ( optional_string("+End Alpha:") )
stuff_float(&ti->a_end);
if ( optional_string("+Max Life:") ) {
stuff_float(&ti->max_life);
ti->stamp = fl2i(1000.0f*ti->max_life)/(NUM_TRAIL_SECTIONS+1);
}
if ( optional_string("+Bitmap:") ) {
stuff_string(fname, F_NAME, NAME_LENGTH);
generic_bitmap_init(&ti->texture, fname);
}
if ( optional_string("+Faded Out Sections:") ) {
stuff_int(&ti->n_fade_out_sections);
}
}
// read in filename for icon that is used in weapons selection
if ( optional_string("$Icon:") ) {
stuff_string(wip->icon_filename, F_NAME, MAX_FILENAME_LEN);
}
// read in filename for animation that is used in weapons selection
if ( optional_string("$Anim:") ) {
stuff_string(wip->anim_filename, F_NAME, MAX_FILENAME_LEN);
}
if ( optional_string("$Impact Explosion:") ) {
stuff_string(fname, F_NAME, NAME_LENGTH);
if ( VALID_FNAME(fname) )
wip->impact_weapon_expl_index = Weapon_explosions.Load(fname);
}
if ( optional_string("$Impact Explosion Radius:") )
stuff_float(&wip->impact_explosion_radius);
if ( optional_string("$Dinky Impact Explosion:") ) {
stuff_string(fname, F_NAME, NAME_LENGTH);
if ( VALID_FNAME(fname) )
wip->dinky_impact_weapon_expl_index = Weapon_explosions.Load(fname);
} else if (first_time) {
wip->dinky_impact_weapon_expl_index = wip->impact_weapon_expl_index;
}
if ( optional_string("$Dinky Impact Explosion Radius:") )
stuff_float(&wip->dinky_impact_explosion_radius);
else if (first_time)
wip->dinky_impact_explosion_radius = wip->impact_explosion_radius;
if ( optional_string("$Piercing Impact Explosion:") ) {
stuff_string(fname, F_NAME, NAME_LENGTH);
if ( VALID_FNAME(fname) )
wip->piercing_impact_weapon_expl_index = Weapon_explosions.Load(fname);
}
if ( optional_string("$Piercing Impact Radius:") )
stuff_float(&wip->piercing_impact_explosion_radius);
if ( optional_string("$Piercing Impact Velocity:") )
stuff_float(&wip->piercing_impact_particle_velocity);
if ( optional_string("$Piercing Impact Splash Velocity:") )
stuff_float(&wip->piercing_impact_particle_back_velocity);
if ( optional_string("$Piercing Impact Variance:") )
stuff_float(&wip->piercing_impact_particle_variance);
if ( optional_string("$Piercing Impact Life:") )
stuff_float(&wip->piercing_impact_particle_life);
if ( optional_string("$Piercing Impact Particles:") )
stuff_int(&wip->piercing_impact_particle_count);
// muzzle flash
if ( optional_string("$Muzzleflash:") ) {
stuff_string(fname, F_NAME, NAME_LENGTH);
// look it up
wip->muzzle_flash = mflash_lookup(fname);
}
if (wip->muzzle_flash > -1)
wip->wi_flags |= WIF_MFLASH;
// EMP optional stuff (if WIF_EMP is not set, none of this matters, anyway)
if( optional_string("$EMP Intensity:") ){
stuff_float(&wip->emp_intensity);
}
if( optional_string("$EMP Time:") ){
stuff_float(&wip->emp_time);
}
// Energy suck optional stuff (if WIF_ENERGY_SUCK is not set, none of this matters anyway)
if( optional_string("$Leech Weapon:") ){
stuff_float(&wip->weapon_reduce);
}
if( optional_string("$Leech Afterburner:") ){
stuff_float(&wip->afterburner_reduce);
}
if (optional_string("$Corkscrew:"))
{
if(optional_string("+Num Fired:")) {
stuff_int(&wip->cs_num_fired);
}
if(optional_string("+Radius:")) {
stuff_float(&wip->cs_radius);
}
if(optional_string("+Fire Delay:")) {
stuff_int(&wip->cs_delay);
}
if(optional_string("+Counter rotate:")) {
stuff_boolean(&wip->cs_crotate);
}
if(optional_string("+Twist:")) {
stuff_float(&wip->cs_twist);
}
}
//electronics tag optional stuff
//Note that I made all these optional in the interest of modular tables.
//TODO: Possibly add a warning on first_time define?
if (optional_string("$Electronics:"))
{
if(optional_string("+New Style:")) {
wip->elec_use_new_style=1;
}
else if(optional_string("+Old Style:")) {
wip->elec_use_new_style=0;
}
//New only -WMC
if(optional_string("+Intensity:")) {
float temp;
stuff_float(&temp);
Warning(LOCATION, "+Intensity is deprecated");
}
if(optional_string("+Lifetime:")) {
stuff_int(&wip->elec_time);
}
//New only -WMC
if(optional_string("+Engine Multiplier:")) {
stuff_float(&wip->elec_eng_mult);
if(!wip->elec_use_new_style)Warning(LOCATION, "+Engine multiplier may only be used with new style electronics");
}
//New only -WMC
if(optional_string("+Weapon Multiplier:")) {
stuff_float(&wip->elec_weap_mult);
if(!wip->elec_use_new_style)Warning(LOCATION, "+Weapon multiplier may only be used with new style electronics");
}
//New only -WMC
if(optional_string("+Beam Turret Multiplier:")) {
stuff_float(&wip->elec_beam_mult);
if(!wip->elec_use_new_style)Warning(LOCATION, "+Beam turret multiplier may only be used with new style electronics");
}
//New only -WMC
if(optional_string("+Sensors Multiplier:")) {
stuff_float(&wip->elec_sensors_mult);
if(!wip->elec_use_new_style)Warning(LOCATION, "+Sensors multiplier may only be used with new style electronics");
}
if(optional_string("+Randomness Time:")) {
stuff_int(&wip->elec_randomness);
}
}
//read in the spawn angle info
//if the weapon isn't a spawn weapon, then this is not going to be used.
int num_spawn_angs_defined = 0;
float dum_float;
while (optional_string("$Spawn Angle:"))
{
stuff_float(&dum_float);
if (num_spawn_angs_defined < MAX_SPAWN_TYPES_PER_WEAPON)
{
wip->spawn_info[num_spawn_angs_defined].spawn_angle = dum_float;
num_spawn_angs_defined++;
}
}
if (wip->wi_flags2 & WIF2_LOCAL_SSM && optional_string("$Local SSM:"))
{
if(optional_string("+Warpout Delay:")) {
stuff_int(&wip->lssm_warpout_delay);
}
if(optional_string("+Warpin Delay:")) {
stuff_int(&wip->lssm_warpin_delay);
}
if(optional_string("+Stage 5 Velocity:")) {
stuff_float(&wip->lssm_stage5_vel);
}
if(optional_string("+Warpin Radius:")) {
stuff_float(&wip->lssm_warpin_radius);
}
if (optional_string("+Lock Range:")) {
stuff_float(&wip->lssm_lock_range);
}
}
if (optional_string("$Countermeasure:"))
{
if (!(wip->wi_flags & WIF_CMEASURE))
{
Warning(LOCATION,"Weapon \'%s\' has countermeasure information defined, but the \"countermeasure\" flag wasn\'t found in the \'$Flags:\' field.\n", wip->name);
}
if (optional_string("+Heat Effectiveness:"))
stuff_float(&wip->cm_heat_effectiveness);
if (optional_string("+Aspect Effectiveness:"))
stuff_float(&wip->cm_aspect_effectiveness);
if (optional_string("+Effective Radius:"))
stuff_float(&wip->cm_effective_rad);
}
// beam weapon optional stuff
if ( optional_string("$BeamInfo:") ) {
// beam type
if(optional_string("+Type:")) {
stuff_int(&wip->b_info.beam_type);
}
// how long it lasts
if(optional_string("+Life:")) {
stuff_float(&wip->b_info.beam_life);
}
// warmup time
if(optional_string("+Warmup:")) {
stuff_int(&wip->b_info.beam_warmup);
}
// warmdowm time
if(optional_string("+Warmdown:")) {
stuff_int(&wip->b_info.beam_warmdown);
}
// muzzle glow radius
if(optional_string("+Radius:")) {
stuff_float(&wip->b_info.beam_muzzle_radius);
}
// particle spew count
if(optional_string("+PCount:")) {
stuff_int(&wip->b_info.beam_particle_count);
}
// particle radius
if(optional_string("+PRadius:")) {
stuff_float(&wip->b_info.beam_particle_radius);
}
// angle off turret normal
if(optional_string("+PAngle:")) {
stuff_float(&wip->b_info.beam_particle_angle);
}
// particle bitmap/ani
if ( optional_string("+PAni:") ) {
stuff_string(fname, F_NAME, NAME_LENGTH);
generic_anim_init(&wip->b_info.beam_particle_ani, fname);
}
// magic miss #
if(optional_string("+Miss Factor:")) {
for(idx=0; idx<NUM_SKILL_LEVELS; idx++) {
float temp;
if(!stuff_float_optional(&temp)) {
break;
}
// an unspecified Miss Factor should apply to all IFFs
for(iff=0; iff<Num_iffs; iff++) {
wip->b_info.beam_iff_miss_factor[iff][idx] = temp;
}
}
}
// now check miss factors for each IFF
for(iff=0; iff<Num_iffs; iff++) {
char miss_factor_string[NAME_LENGTH + 15];
sprintf(miss_factor_string, "+%s Miss Factor:", Iff_info[iff].iff_name);
if(optional_string(miss_factor_string)) {
// this Miss Factor applies only to the specified IFF
for(idx=0; idx<NUM_SKILL_LEVELS; idx++) {
if(!stuff_float_optional(&wip->b_info.beam_iff_miss_factor[iff][idx])) {
break;
}
}
}
}
// beam fire sound
parse_sound("+BeamSound:", &wip->b_info.beam_loop_sound, wip->name);
// warmup sound
parse_sound("+WarmupSound:", &wip->b_info.beam_warmup_sound, wip->name);
// warmdown sound
parse_sound("+WarmdownSound:", &wip->b_info.beam_warmdown_sound, wip->name);
// glow bitmap
if (optional_string("+Muzzleglow:") ) {
stuff_string(fname, F_NAME, NAME_LENGTH);
generic_anim_init(&wip->b_info.beam_glow, fname);
}
// # of shots (only used for type D beams)
if(optional_string("+Shots:")) {
stuff_int(&wip->b_info.beam_shots);
}
// make sure that we have at least one shot so that TYPE_D beams will work
if ( (wip->b_info.beam_type == BEAM_TYPE_D) && (wip->b_info.beam_shots < 1) ) {
Warning( LOCATION, "Type D beam weapon, '%s', has less than one \"+Shots\" specified! It must be set to at least 1!!", wip->name);
wip->b_info.beam_shots = 1;
}
// shrinkage
if(optional_string("+ShrinkFactor:")) {
stuff_float(&wip->b_info.beam_shrink_factor);
}
if(optional_string("+ShrinkPct:")) {
stuff_float(&wip->b_info.beam_shrink_pct);
}
if (optional_string("+Range:")) {
stuff_float(&wip->b_info.range);
}
if ( optional_string("+Attenuation:") )
stuff_float(&wip->b_info.damage_threshold);
if ( optional_string("+BeamWidth:") )
stuff_float(&wip->b_info.beam_width);
if ( optional_string("+Beam Flash Effect:") ) {
stuff_string(fname, F_NAME, NAME_LENGTH);
if ( VALID_FNAME(fname) )
wip->flash_impact_weapon_expl_index = Weapon_explosions.Load(fname);
}
if ( optional_string("+Beam Flash Radius:") )
stuff_float(&wip->flash_impact_explosion_radius);
if ( optional_string("+Beam Piercing Effect:") ) {
stuff_string(fname, F_NAME, NAME_LENGTH);
if ( VALID_FNAME(fname) )
wip->piercing_impact_weapon_expl_index = Weapon_explosions.Load(fname);
}
if ( optional_string("+Beam Piercing Radius:") )
stuff_float(&wip->piercing_impact_explosion_radius);
if ( optional_string("+Beam Piercing Effect Velocity:") )
stuff_float(&wip->piercing_impact_particle_velocity);
if ( optional_string("+Beam Piercing Splash Effect Velocity:") )
stuff_float(&wip->piercing_impact_particle_back_velocity);
if ( optional_string("+Beam Piercing Effect Variance:") )
stuff_float(&wip->piercing_impact_particle_variance);
// beam sections
while ( optional_string("$Section:") ) {
beam_weapon_section_info *bsip = NULL, tbsw;
bool nocreate = false, remove = false;
int bsw_index_override = -1;
if ( optional_string("+Index:") ) {
stuff_int(&bsw_index_override);
if ( optional_string("+remove") ) {
nocreate = true;
remove = true;
}
if ( (bsw_index_override < 0) || (!remove && (bsw_index_override >= wip->b_info.beam_num_sections)) )
Warning(LOCATION, "Invalid +Index value of %d specified for beam section on weapon '%s'; valid values at this point are %d to %d.", bsw_index_override, wip->name, 0, wip->b_info.beam_num_sections -1);
}
if ( optional_string("+nocreate") )
nocreate = true;
// Where are we saving data?
if (bsw_index_override >= 0) {
if (bsw_index_override < wip->b_info.beam_num_sections) {
bsip = &wip->b_info.sections[bsw_index_override];
} else {
if ( !nocreate ) {
if ( (bsw_index_override == wip->b_info.beam_num_sections) && (bsw_index_override < MAX_BEAM_SECTIONS) ) {
bsip = &wip->b_info.sections[wip->b_info.beam_num_sections++];
} else {
if ( !remove )
Warning(LOCATION, "Invalid index for manually-indexed beam section %d (max %d) on weapon %s.", bsw_index_override, MAX_BEAM_SECTIONS, wip->name);
bsip = &tbsw;
memset( bsip, 0, sizeof(beam_weapon_section_info) );
generic_anim_init(&bsip->texture, NULL);
}
} else {
if ( !remove )
Warning(LOCATION, "Invalid index for manually-indexed beam section %d, and +nocreate specified, on weapon %s", bsw_index_override, wip->name);
bsip = &tbsw;
memset( bsip, 0, sizeof(beam_weapon_section_info) );
generic_anim_init(&bsip->texture, NULL);
}
}
} else {
if (wip->b_info.beam_num_sections < MAX_BEAM_SECTIONS) {
bsip = &wip->b_info.sections[wip->b_info.beam_num_sections++];
generic_anim_init(&bsip->texture, NULL);
} else {
Warning(LOCATION, "Too many beam sections for weapon %s - max is %d", wip->name, MAX_BEAM_SECTIONS);
bsip = &tbsw;
memset( bsip, 0, sizeof(beam_weapon_section_info) );
generic_anim_init(&bsip->texture, NULL);
}
}
// section width
if ( optional_string("+Width:") )
stuff_float(&bsip->width);
// texture
if ( optional_string("+Texture:") ) {
stuff_string(fname, F_NAME, NAME_LENGTH);
generic_anim_init(&bsip->texture, fname);
}
// The E -- Dummied out due to not being used anywhere
if ( optional_string("+RGBA Inner:") ) {
ubyte dummy;
stuff_ubyte(&dummy);
stuff_ubyte(&dummy);
stuff_ubyte(&dummy);
stuff_ubyte(&dummy);
}
// The E -- Dummied out due to not being used anywhere
if ( optional_string("+RGBA Outer:") ) {
ubyte dummy;
stuff_ubyte(&dummy);
stuff_ubyte(&dummy);
stuff_ubyte(&dummy);
stuff_ubyte(&dummy);
}
// flicker
if ( optional_string("+Flicker:") ) {
stuff_float(&bsip->flicker);
//Sanity
if (bsip->flicker < 0.0f || bsip->flicker > 1.0f) {
mprintf(("WARNING: Invalid value found for +Flicker on section %d of beam %s. Valid range is 0.0 to 1.0, values will be adjusted.\n", wip->b_info.beam_num_sections, wip->name));
CLAMP(bsip->flicker, 0.0f, 1.0f);
}
}
// zadd
if ( optional_string("+Zadd:") )
stuff_float(&bsip->z_add);
// beam texture tileing factor -Bobboau
if ( optional_string("+Tile Factor:") ) {
stuff_float(&bsip->tile_factor);
stuff_int(&bsip->tile_type);
}
// beam texture moveing stuff -Bobboau
if ( optional_string("+Translation:") )
stuff_float(&bsip->translation);
// if we are actually removing this index then reset it and we'll
// clean up the entries later
if (remove) {
memset( bsip, 0, sizeof(beam_weapon_section_info) );
generic_anim_init(&bsip->texture, NULL);
}
}
}
while ( optional_string("$Pspew:") ) {
int spew_index = -1;
// check for pspew flag
if (!( wip->wi_flags & WIF_PARTICLE_SPEW )) {
Warning(LOCATION, "$Pspew specified for weapon %s but this weapon does not have the \"Particle Spew\" weapon flag set. Automatically setting the flag", wip->name);
wip->wi_flags |= WIF_PARTICLE_SPEW;
}
// index for xmt edit, replace and remove support
if (optional_string("+Index:")) {
stuff_int(&spew_index);
if (spew_index < 0 || spew_index >= MAX_PARTICLE_SPEWERS) {
Warning(LOCATION, "+Index in particle spewer out of range. It must be between 0 and %i. Tag will be ignored.", MAX_PARTICLE_SPEWERS);
spew_index = -1;
}
}
// check for remove flag
if (optional_string("+Remove")) {
if (spew_index < 0) {
Warning(LOCATION, "+Index not specified or is out of range, can not remove spewer.");
} else { // restore defaults
wip->particle_spewers[spew_index].particle_spew_type = PSPEW_NONE;
wip->particle_spewers[spew_index].particle_spew_count = 1;
wip->particle_spewers[spew_index].particle_spew_time = 25;
wip->particle_spewers[spew_index].particle_spew_vel = 0.4f;
wip->particle_spewers[spew_index].particle_spew_radius = 2.0f;
wip->particle_spewers[spew_index].particle_spew_lifetime = 0.15f;
wip->particle_spewers[spew_index].particle_spew_scale = 0.8f;
wip->particle_spewers[spew_index].particle_spew_z_scale = 1.0f;
wip->particle_spewers[spew_index].particle_spew_rotation_rate = 10.0f;
wip->particle_spewers[spew_index].particle_spew_offset = vmd_zero_vector;
wip->particle_spewers[spew_index].particle_spew_velocity = vmd_zero_vector;
generic_anim_init(&wip->particle_spewers[spew_index].particle_spew_anim, NULL);
}
} else { // were not removing the spewer
if (spew_index < 0) { // index us ether not used or is invalid, so figure out where to put things
//find a free slot in the pspew info array
for (size_t s = 0; s < MAX_PARTICLE_SPEWERS; s++) {
if (wip->particle_spewers[s].particle_spew_type == PSPEW_NONE) {
spew_index = s;
break;
}
}
}
// no empty spot found, the modder tried to define too many spewers, or screwed up the xmts, or my code sucks
if ( spew_index < 0 ) {
Warning(LOCATION, "Too many particle spewers, max number of spewers is %i.", MAX_PARTICLE_SPEWERS);
} else { // we have a valid index, now parse the spewer already
if (optional_string("+Type:")) { // added type field for pspew types, 0 is the default for reverse compatability -nuke
char temp_pspew_type[NAME_LENGTH];
stuff_string(temp_pspew_type, F_NAME, NAME_LENGTH);
if (!stricmp(temp_pspew_type, NOX("DEFAULT"))) {
wip->particle_spewers[spew_index].particle_spew_type = PSPEW_DEFAULT;
} else if (!stricmp(temp_pspew_type, NOX("HELIX"))) {
wip->particle_spewers[spew_index].particle_spew_type = PSPEW_HELIX;
} else if (!stricmp(temp_pspew_type, NOX("SPARKLER"))) { // new types can be added here
wip->particle_spewers[spew_index].particle_spew_type = PSPEW_SPARKLER;
} else if (!stricmp(temp_pspew_type, NOX("RING"))) {
wip->particle_spewers[spew_index].particle_spew_type = PSPEW_RING;
} else if (!stricmp(temp_pspew_type, NOX("PLUME"))) {
wip->particle_spewers[spew_index].particle_spew_type = PSPEW_PLUME;
} else {
wip->particle_spewers[spew_index].particle_spew_type = PSPEW_DEFAULT;
}
// for compatibility with existing tables that don't have a type tag
} else if (wip->particle_spewers[spew_index].particle_spew_type == PSPEW_NONE) { // make sure the omission of type wasn't to edit an existing entry
wip->particle_spewers[spew_index].particle_spew_type = PSPEW_DEFAULT;
}
if (optional_string("+Count:")) {
stuff_int(&wip->particle_spewers[spew_index].particle_spew_count);
}
if (optional_string("+Time:")) {
stuff_int(&wip->particle_spewers[spew_index].particle_spew_time);
}
if (optional_string("+Vel:")) {
stuff_float(&wip->particle_spewers[spew_index].particle_spew_vel);
}
if (optional_string("+Radius:")) {
stuff_float(&wip->particle_spewers[spew_index].particle_spew_radius);
}
if (optional_string("+Life:")) {
stuff_float(&wip->particle_spewers[spew_index].particle_spew_lifetime);
}
if (optional_string("+Scale:")) {
stuff_float(&wip->particle_spewers[spew_index].particle_spew_scale);
}
if (optional_string("+Z Scale:")) {
stuff_float(&wip->particle_spewers[spew_index].particle_spew_z_scale);
}
if (optional_string("+Rotation Rate:")) {
stuff_float(&wip->particle_spewers[spew_index].particle_spew_rotation_rate);
}
if (optional_string("+Offset:")) {
stuff_vec3d(&wip->particle_spewers[spew_index].particle_spew_offset);
}
if (optional_string("+Initial Velocity:")) {
stuff_vec3d(&wip->particle_spewers[spew_index].particle_spew_velocity);
}
if (optional_string("+Bitmap:")) {
stuff_string(fname, F_NAME, MAX_FILENAME_LEN);
generic_anim_init(&wip->particle_spewers[spew_index].particle_spew_anim, fname);
}
}
}
}
// check to see if the pspew flag was enabled but no pspew tags were given, for compatability with retail tables
if (wip->wi_flags & WIF_PARTICLE_SPEW) {
bool nospew = true;
for (size_t s = 0; s < MAX_PARTICLE_SPEWERS; s++)
if (wip->particle_spewers[s].particle_spew_type != PSPEW_NONE) {
nospew = false;
}
if (nospew) { // set first spewer to default
wip->particle_spewers[0].particle_spew_type = PSPEW_DEFAULT;
}
}
// tag weapon optional stuff
if( optional_string("$Tag:")){
stuff_int(&wip->tag_level);
stuff_float(&wip->tag_time);
wip->wi_flags |= WIF_TAG;
}
if( optional_string("$SSM:")){
stuff_int(&wip->SSM_index);
}// SSM index -Bobboau
if(optional_string("$FOF:")){
stuff_float(&wip->field_of_fire);
if(optional_string("+FOF Spread Rate:")){
stuff_float(&wip->fof_spread_rate);
if(required_string("+FOF Reset Rate:")){
stuff_float(&wip->fof_reset_rate);
}
if(required_string("+Max FOF:")){
float max_fof;
stuff_float(&max_fof);
wip->max_fof_spread = max_fof - wip->field_of_fire;
if (wip->max_fof_spread <= 0.0f) {
Warning(LOCATION, "WARNING: +Max FOF must be at least as big as $FOF for '%s'! Defaulting to match $FOF, no spread will occur!", wip->name);
wip->max_fof_spread = 0.0f;
}
}
}
}
if( optional_string("$Shots:")){
stuff_int(&wip->shots);
}
//Left in for compatibility
if ( optional_string("$decal:") ) {
mprintf(("WARNING: The decal system has been deactivated in FSO builds. Entries for weapon %s will be discarded.\n", wip->name));
required_string("+texture:");
stuff_string(fname, F_NAME, NAME_LENGTH);
if ( optional_string("+backface texture:") ) {
stuff_string(fname, F_NAME, NAME_LENGTH);
}
float bogus;
required_string("+radius:");
stuff_float(&bogus);
if ( optional_string("+burn time:") ) {
stuff_float(&bogus);
}
}
if (optional_string("$Transparent:")) {
wip->wi_flags2 |= WIF2_TRANSPARENT;
required_string("+Alpha:");
stuff_float(&wip->alpha_max);
if (wip->alpha_max > 1.0f)
wip->alpha_max = 1.0f;
if (wip->alpha_max <= 0.0f) {
Warning(LOCATION, "WARNING: Alpha is set to 0 or a negative value for '%s'! Defaulting to 1.0!", wip->name);
}
if (optional_string("+Alpha Min:")) {
stuff_float(&wip->alpha_min);
CLAMP(wip->alpha_min, 0.0f, 1.0f);
}
if (optional_string("+Alpha Cycle:")) {
stuff_float(&wip->alpha_cycle);
if (wip->alpha_max == wip->alpha_min)
Warning(LOCATION, "WARNING: Alpha is set to cycle for '%s', but max and min values are the same!", wip->name);
}
}
if (optional_string("$Weapon Hitpoints:")) {
stuff_int(&wip->weapon_hitpoints);
}
// making sure bombs get their hitpoints assigned
if ((wip->wi_flags & WIF_BOMB) && (wip->weapon_hitpoints == 0)) {
wip->weapon_hitpoints = 50;
}
if(optional_string("$Armor Type:")) {
stuff_string(buf, F_NAME, WEAPONS_MULTITEXT_LENGTH);
wip->armor_type_idx = armor_type_get_idx(buf);
if(wip->armor_type_idx == -1)
Warning(LOCATION,"Invalid armor name %s specified for weapon %s", buf, wip->name);
}
if (optional_string("$Burst Shots:")) {
stuff_int(&wip->burst_shots);
if (wip->burst_shots > 0)
wip->burst_shots--;
}
if (optional_string("$Burst Delay:")) {
int temp;
stuff_int(&temp);
if (temp > 0) {
wip->burst_delay = ((float) temp) / 1000.0f;
}
}
if (optional_string("$Burst Flags:")) {
parse_string_flag_list((int*)&wip->burst_flags, Burst_fire_flags, Num_burst_fire_flags);
}
if (optional_string("$Thruster Flame Effect:")) {
stuff_string(fname, F_NAME, NAME_LENGTH);
if (VALID_FNAME(fname))
generic_anim_init( &wip->thruster_flame, fname );
}
if (optional_string("$Thruster Glow Effect:")) {
stuff_string(fname, F_NAME, NAME_LENGTH);
if (VALID_FNAME(fname))
generic_anim_init( &wip->thruster_glow, fname );
}
if (optional_string("$Thruster Glow Radius Factor:")) {
stuff_float(&wip->thruster_glow_factor);
}
//pretty stupid if a target must be tagged to shoot tag missiles at it
if ((wip->wi_flags & WIF_TAG) && (wip->wi_flags2 & WIF2_TAGGED_ONLY))
{
Warning(LOCATION, "%s is a tag missile, but the target must be tagged to shoot it", wip->name);
}
// if burst delay is longer than firewait skip the whole burst fire option
if (wip->burst_delay >= wip->fire_wait)
wip->burst_shots = 0;
/* Generate a substitution pattern for this weapon.
This pattern is very naive such that is calculates the lowest common demoniator as being all of
the periods multiplied together.
*/
while ( optional_string("$substitute:") ) {
char subname[NAME_LENGTH];
int period = 0;
int index = 0;
int offset = 0;
stuff_string(subname, F_NAME, NAME_LENGTH);
if ( optional_string("+period:") ) {
stuff_int(&period);
if ( period <= 0 ) {
Warning(LOCATION, "Substitution '%s' for weapon '%s' requires a period greater than 0. Setting period to 1.", subname, wip->name);
period = 1;
}
if ( optional_string("+offset:") ) {
stuff_int(&offset);
if ( offset <= 0 ) {
Warning(LOCATION, "Period offset for substitution '%s' of weapon '%s' has to be greater than 0. Setting offset to 1.", subname, wip->name);
offset = 1;
}
}
} else if ( optional_string("+index:") ) {
stuff_int(&index);
if ( index < 0 ) {
Warning(LOCATION, "Substitution '%s' for weapon '%s' requires an index greater than 0. Setting index to 0.", subname, wip->name);
index = 0;
}
}
// we are going to use weapon substition so, make sure that the pattern array has at least one element
if ( wip->weapon_substitution_pattern_names.empty() ) {
// pattern is empty, initialize pattern with the weapon being currently parsed.
wip->weapon_substitution_pattern_names.push_back(wip->name);
}
// if tbler specifies a period then determine if we can fit the resulting pattern
// neatly into the pattern array.
if ( period > 0 ) {
if ( (wip->weapon_substitution_pattern_names.size() % period) > 0 ) {
// not neat, need to expand the pattern so that our freqency pattern fits completly.
size_t current_size = wip->weapon_substitution_pattern_names.size();
wip->weapon_substitution_pattern_names.resize(current_size*period);
// now duplicate the current pattern into the new area so the current pattern holds
for ( size_t i = current_size; i < wip->weapon_substitution_pattern_names.size(); i++) {
wip->weapon_substitution_pattern_names[i] = wip->weapon_substitution_pattern_names[i%current_size];
}
}
/* Apply the substituted weapon at the requested period, barrel
shifted by offset if needed.*/
for ( size_t pos = (period + offset - 1) % period;
pos < wip->weapon_substitution_pattern_names.size(); pos += period )
{
wip->weapon_substitution_pattern_names[pos] = subname;
}
} else {
// assume that tbler wanted to specify a index for the new weapon.
// make sure that there is enough room
if ( !(index < (int)wip->weapon_substitution_pattern_names.size()) ) {
// need to make the pattern bigger by filling the extra with the current weapon.
size_t current_size = wip->weapon_substitution_pattern_names.size();
wip->weapon_substitution_pattern_names.resize(current_size+1, subname);
}
wip->weapon_substitution_pattern_names[index] = subname;
}
}
//Optional score for destroying this weapon.
if (optional_string("$Score:")) {
stuff_int(&wip->score);
}
return WEAPON_INFO_INDEX(wip);
}
/**
* For all weapons that spawn weapons, given an index at weaponp->spawn_type,
* convert the strings in Spawn_names to indices in the Weapon_types array.
*/
void translate_spawn_types()
{
int i, j, k;
for (i = 0; i < Num_weapon_types; i++)
{
for (j = 0; j < Weapon_info[i].num_spawn_weapons_defined; j++)
{
if ( (Weapon_info[i].spawn_info[j].spawn_type > -1) && (Weapon_info[i].spawn_info[j].spawn_type < Num_spawn_types) )
{
int spawn_type = Weapon_info[i].spawn_info[j].spawn_type;
Assert( spawn_type < Num_spawn_types );
for (k = 0; k < Num_weapon_types; k++)
{
if ( !stricmp(Spawn_names[spawn_type], Weapon_info[k].name) )
{
Weapon_info[i].spawn_info[j].spawn_type = (short)k;
if (i == k)
Warning(LOCATION, "Weapon %s spawns itself. Infinite recursion?\n", Weapon_info[i].name);
break;
}
}
}
}
}
}
static char Default_cmeasure_name[NAME_LENGTH] = "";
void parse_weaponstbl(char *filename)
{
int rval;
// open localization
lcl_ext_open();
if ((rval = setjmp(parse_abort)) != 0)
{
mprintf(("TABLES: Unable to parse '%s'! Error code = %i.\n", filename, rval));
lcl_ext_close();
return;
}
read_file_text(filename, CF_TYPE_TABLES);
reset_parse();
if(optional_string("#Primary Weapons"))
{
while (required_string_either("#End", "$Name:")) {
// AL 28-3-98: If parse_weapon() fails, try next .tbl weapon
if ( parse_weapon(WP_LASER, Parsing_modular_table) < 0 ) {
continue;
}
}
required_string("#End");
}
if(optional_string("#Secondary Weapons"))
{
while (required_string_either("#End", "$Name:")) {
// AL 28-3-98: If parse_weapon() fails, try next .tbl weapon
if ( parse_weapon(WP_MISSILE, Parsing_modular_table) < 0) {
continue;
}
}
required_string("#End");
}
if(optional_string("#Beam Weapons"))
{
while (required_string_either("#End", "$Name:")) {
// AL 28-3-98: If parse_weapon() fails, try next .tbl weapon
if ( parse_weapon(WP_BEAM, Parsing_modular_table) < 0) {
continue;
}
}
required_string("#End");
}
strcpy_s(parse_error_text, "in the counter measure table entry");
if(optional_string("#Countermeasures"))
{
while (required_string_either("#End", "$Name:"))
{
int idx = parse_weapon(WP_MISSILE, Parsing_modular_table);
if(idx < 0) {
continue;
}
//Make sure cmeasure flag is set
Weapon_info[idx].wi_flags |= WIF_CMEASURE;
//Set cmeasure index
if(!strlen(Default_cmeasure_name)) {
//We can't be sure that index will be the same after sorting, so save the name
strcpy_s(Default_cmeasure_name, Weapon_info[idx].name);
}
}
required_string("#End");
}
strcpy_s(parse_error_text, "");
// Read in a list of weapon_info indicies that are an ordering of the player weapon precedence.
// This list is used to select an alternate weapon when a particular weapon is not available
// during weapon selection.
if ( (!Parsing_modular_table && required_string("$Player Weapon Precedence:")) || optional_string("$Player Weapon Precedence:") )
{
strcpy_s(parse_error_text, "in the player weapon precedence list");
Num_player_weapon_precedence = stuff_int_list(Player_weapon_precedence, MAX_WEAPON_TYPES, WEAPON_LIST_TYPE);
strcpy_s(parse_error_text, "");
}
// add tbl/tbm to multiplayer validation list
fs2netd_add_table_validation(filename);
// close localization
lcl_ext_close();
}
//uses a simple bucket sort to sort weapons, order of importance is:
//Lasers
//Beams
//Child primary weapons
//Fighter missiles and bombs
//Capital missiles and bombs
//Child secondary weapons
void weapon_sort_by_type()
{
weapon_info *lasers = NULL, *big_lasers = NULL, *beams = NULL, *missiles = NULL, *big_missiles = NULL, *child_primaries = NULL, *child_secondaries = NULL;
int num_lasers = 0, num_big_lasers = 0, num_beams = 0, num_missiles = 0, num_big_missiles = 0, num_child_primaries = 0, num_child_secondaries = 0;
int i, weapon_index;
// get the initial count of each weapon type
for (i = 0; i < MAX_WEAPON_TYPES; i++) {
switch (Weapon_info[i].subtype)
{
case WP_UNUSED:
continue;
case WP_LASER:
if (Weapon_info[i].wi_flags & WIF_CHILD)
num_child_primaries++;
else if (Weapon_info[i].wi_flags & WIF_BIG_ONLY)
num_big_lasers++;
else
num_lasers++;
break;
case WP_BEAM:
num_beams++;
break;
case WP_MISSILE:
if (Weapon_info[i].wi_flags & WIF_CHILD)
num_child_secondaries++;
else if (Weapon_info[i].wi_flags & WIF_BIG_ONLY)
num_big_missiles++;
else
num_missiles++;
break;
default:
continue;
}
}
// allocate the buckets
if (num_lasers) {
lasers = new weapon_info[num_lasers];
Verify( lasers != NULL );
num_lasers = 0;
}
if (num_big_lasers) {
big_lasers = new weapon_info[num_big_lasers];
Verify( big_lasers != NULL );
num_big_lasers = 0;
}
if (num_beams) {
beams = new weapon_info[num_beams];
Verify( beams != NULL );
num_beams = 0;
}
if (num_missiles) {
missiles = new weapon_info[num_missiles];
Verify( missiles != NULL );
num_missiles = 0;
}
if (num_big_missiles) {
big_missiles = new weapon_info[num_big_missiles];
Verify( big_missiles != NULL );
num_big_missiles = 0;
}
if (num_child_primaries) {
child_primaries = new weapon_info[num_child_primaries];
Verify( child_primaries != NULL );
num_child_primaries = 0;
}
if (num_child_secondaries) {
child_secondaries = new weapon_info[num_child_secondaries];
Verify( child_secondaries != NULL );
num_child_secondaries = 0;
}
// fill the buckets
for (i = 0; i < MAX_WEAPON_TYPES; i++) {
switch (Weapon_info[i].subtype)
{
case WP_UNUSED:
continue;
case WP_LASER:
if (Weapon_info[i].wi_flags & WIF_CHILD)
child_primaries[num_child_primaries++] = Weapon_info[i];
else if (Weapon_info[i].wi_flags & WIF_BIG_ONLY)
big_lasers[num_big_lasers++] = Weapon_info[i];
else
lasers[num_lasers++] = Weapon_info[i];
break;
case WP_BEAM:
beams[num_beams++] = Weapon_info[i];
break;
case WP_MISSILE:
if (Weapon_info[i].wi_flags & WIF_CHILD)
child_secondaries[num_child_secondaries++] = Weapon_info[i];
else if (Weapon_info[i].wi_flags & WIF_BIG_ONLY)
big_missiles[num_big_missiles++] = Weapon_info[i];
else
missiles[num_missiles++]=Weapon_info[i];
break;
default:
continue;
}
}
weapon_index = 0;
// reorder the weapon_info structure according to our rules defined above
for (i = 0; i < num_lasers; i++, weapon_index++)
Weapon_info[weapon_index] = lasers[i];
for (i = 0; i < num_big_lasers; i++, weapon_index++)
Weapon_info[weapon_index] = big_lasers[i];
for (i = 0; i < num_beams; i++, weapon_index++)
Weapon_info[weapon_index] = beams[i];
for (i = 0; i < num_child_primaries; i++, weapon_index++)
Weapon_info[weapon_index] = child_primaries[i];
// designate start of secondary weapons so that we'll have the correct offset later on
First_secondary_index = weapon_index;
for (i = 0; i < num_missiles; i++, weapon_index++)
Weapon_info[weapon_index] = missiles[i];
for (i = 0; i < num_big_missiles; i++, weapon_index++)
Weapon_info[weapon_index] = big_missiles[i];
for (i = 0; i < num_child_secondaries; i++, weapon_index++)
Weapon_info[weapon_index] = child_secondaries[i];
if (lasers) delete [] lasers;
if (big_lasers) delete [] big_lasers;
if (beams) delete [] beams;
if (missiles) delete [] missiles;
if (big_missiles) delete [] big_missiles;
if (child_primaries) delete [] child_primaries;
if (child_secondaries) delete [] child_secondaries;
}
/**
* Do any post-parse cleaning on weapon entries
*/
void weapon_clean_entries()
{
weapon_info *wip;
int i;
for (i = 0; i < Num_weapon_types; i++) {
wip = &Weapon_info[i];
if (wip->wi_flags & WIF_BEAM) {
// clean up any beam sections which may have been deleted
int removed = 0;
for (int s_idx = 0; s_idx < wip->b_info.beam_num_sections; s_idx++) {
if ( !strlen(wip->b_info.sections[s_idx].texture.filename) ) {
int new_idx = s_idx + 1;
while (new_idx < MAX_BEAM_SECTIONS) {
memcpy( &wip->b_info.sections[new_idx-1], &wip->b_info.sections[new_idx], sizeof(beam_weapon_section_info) );
new_idx++;
}
removed++;
}
}
if (removed) {
mprintf(("NOTE: weapon-cleanup is removing %i stale beam sections, out of %i original, from '%s'.\n", removed, wip->b_info.beam_num_sections, wip->name));
wip->b_info.beam_num_sections -= removed;
}
}
}
}
void weapon_release_bitmaps()
{
int i, j;
weapon_info *wip;
// not for FRED...
if (Fred_running)
return;
// if we are just going to load them all again any, keep everything
if (Cmdline_load_all_weapons)
return;
for (i = 0; i < Num_weapon_types; i++) {
wip = &Weapon_info[i];
// go ahead and clear out models, the model paging code will actually take care of
// releasing this stuff if needed, but we have to keep track of current modelnums ourselves
if (wip->render_type == WRT_POF)
wip->model_num = -1;
// we are only interested in what we don't need for this mission
if ( used_weapons[i] )
continue;
if (wip->render_type == WRT_LASER) {
if (wip->laser_bitmap.first_frame >= 0) {
bm_release(wip->laser_bitmap.first_frame);
wip->laser_bitmap.first_frame = -1;
}
// now for the glow
if (wip->laser_glow_bitmap.first_frame >= 0) {
bm_release(wip->laser_glow_bitmap.first_frame);
wip->laser_glow_bitmap.first_frame = -1;
}
}
if (wip->wi_flags & WIF_BEAM) {
// particle animation
if (wip->b_info.beam_particle_ani.first_frame >= 0) {
bm_release(wip->b_info.beam_particle_ani.first_frame);
wip->b_info.beam_particle_ani.first_frame = -1;
}
// muzzle glow
if (wip->b_info.beam_glow.first_frame >= 0) {
bm_release(wip->b_info.beam_glow.first_frame);
wip->b_info.beam_glow.first_frame = -1;
}
// section textures
for (j = 0; j < wip->b_info.beam_num_sections; j++) {
beam_weapon_section_info *bsi = &wip->b_info.sections[j];
if (bsi->texture.first_frame >= 0) {
bm_release(bsi->texture.first_frame);
bsi->texture.first_frame = -1;
}
}
}
if (wip->wi_flags & WIF_TRAIL) {
if (wip->tr_info.texture.bitmap_id >= 0) {
bm_release(wip->tr_info.texture.bitmap_id);
wip->tr_info.texture.bitmap_id = -1;
}
}
if (wip->wi_flags & WIF_PARTICLE_SPEW) { // tweaked for multiple particle spews -nuke
for (size_t s = 0; s < MAX_PARTICLE_SPEWERS; s++) { // just bitmaps that got loaded
if (wip->particle_spewers[s].particle_spew_type != PSPEW_NONE){
if (wip->particle_spewers[s].particle_spew_anim.first_frame >= 0) {
bm_release(wip->particle_spewers[s].particle_spew_anim.first_frame);
wip->particle_spewers[s].particle_spew_anim.first_frame = -1;
}
}
}
}
if (wip->thruster_flame.first_frame >= 0) {
bm_release(wip->thruster_flame.first_frame);
wip->thruster_flame.first_frame = -1;
}
if (wip->thruster_glow.first_frame >= 0) {
bm_release(wip->thruster_glow.first_frame);
wip->thruster_glow.first_frame = -1;
}
}
}
bool weapon_is_used(int weapon_index)
{
Assert( (weapon_index >= 0) || (weapon_index < Num_weapon_types) );
return (used_weapons[weapon_index] > 0);
}
void weapon_load_bitmaps(int weapon_index)
{
weapon_info *wip;
// not for FRED...
if (Fred_running)
return;
if ( (weapon_index < 0) || (weapon_index >= Num_weapon_types) ) {
Int3();
return;
}
wip = &Weapon_info[weapon_index];
if ( (wip->render_type == WRT_LASER) && (wip->laser_bitmap.first_frame < 0) ) {
wip->laser_bitmap.first_frame = bm_load(wip->laser_bitmap.filename);
if (wip->laser_bitmap.first_frame >= 0) {
wip->laser_bitmap.num_frames = 1;
wip->laser_bitmap.total_time = 1;
}
// fall back to an animated type
else if ( generic_anim_load(&wip->laser_bitmap) ) {
mprintf(("Could not find a usable bitmap for '%s'!\n", wip->name));
Warning(LOCATION, "Could not find a usable bitmap (%s) for weapon '%s'!\n", wip->laser_bitmap.filename, wip->name);
}
// now see if we also have a glow
if ( strlen(wip->laser_glow_bitmap.filename) ) {
wip->laser_glow_bitmap.first_frame = bm_load(wip->laser_glow_bitmap.filename);
if (wip->laser_glow_bitmap.first_frame >= 0) {
wip->laser_glow_bitmap.num_frames = 1;
wip->laser_glow_bitmap.total_time = 1;
}
// fall back to an animated type
else if ( generic_anim_load(&wip->laser_glow_bitmap) ) {
mprintf(("Could not find a usable glow bitmap for '%s'!\n", wip->name));
Warning(LOCATION, "Could not find a usable glow bitmap (%s) for weapon '%s'!\n", wip->laser_glow_bitmap.filename, wip->name);
}
}
}
if (wip->wi_flags & WIF_BEAM) {
// particle animation
if ( (wip->b_info.beam_particle_ani.first_frame < 0) && strlen(wip->b_info.beam_particle_ani.filename) )
generic_anim_load(&wip->b_info.beam_particle_ani);
// muzzle glow
if ( (wip->b_info.beam_glow.first_frame < 0) && strlen(wip->b_info.beam_glow.filename) ) {
if ( generic_anim_load(&wip->b_info.beam_glow) ) {
// animated version failed to load, try static instead
wip->b_info.beam_glow.first_frame = bm_load(wip->b_info.beam_glow.filename);
if (wip->b_info.beam_glow.first_frame >= 0) {
wip->b_info.beam_glow.num_frames = 1;
wip->b_info.beam_glow.total_time = 1;
} else {
mprintf(("Could not find a usable muzzle glow bitmap for '%s'!\n", wip->name));
Warning(LOCATION, "Could not find a usable muzzle glow bitmap (%s) for weapon '%s'!\n", wip->b_info.beam_glow.filename, wip->name);
}
}
}
// section textures
for (int i = 0; i < wip->b_info.beam_num_sections; i++) {
beam_weapon_section_info *bsi = &wip->b_info.sections[i];
if ( (bsi->texture.first_frame < 0) && strlen(bsi->texture.filename) ) {
if ( generic_anim_load(&bsi->texture) ) {
// animated version failed to load, try static instead
bsi->texture.first_frame = bm_load(bsi->texture.filename);
if (bsi->texture.first_frame >= 0) {
bsi->texture.num_frames = 1;
bsi->texture.total_time = 1;
} else {
mprintf(("Could not find a usable beam section (%i) bitmap for '%s'!\n", i, wip->name));
Warning(LOCATION, "Could not find a usable beam section (%i) bitmap (%s) for weapon '%s'!\n", i, bsi->texture.filename, wip->name);
}
}
}
}
}
if ( (wip->wi_flags & WIF_TRAIL) && (wip->tr_info.texture.bitmap_id < 0) )
generic_bitmap_load(&wip->tr_info.texture);
//WMC - Don't try to load an anim if no anim is specified, Mmkay?
if (wip->wi_flags & WIF_PARTICLE_SPEW) {
for (size_t s = 0; s < MAX_PARTICLE_SPEWERS; s++) { // looperfied for multiple pspewers -nuke
if (wip->particle_spewers[s].particle_spew_type != PSPEW_NONE){
if ((wip->particle_spewers[s].particle_spew_anim.first_frame < 0)
&& (wip->particle_spewers[s].particle_spew_anim.filename[0] != '\0') ) {
wip->particle_spewers[s].particle_spew_anim.first_frame = bm_load(wip->particle_spewers[s].particle_spew_anim.filename);
if (wip->particle_spewers[s].particle_spew_anim.first_frame >= 0) {
wip->particle_spewers[s].particle_spew_anim.num_frames = 1;
wip->particle_spewers[s].particle_spew_anim.total_time = 1;
}
// fall back to an animated type
else if ( generic_anim_load(&wip->particle_spewers[s].particle_spew_anim) ) {
mprintf(("Could not find a usable particle spew bitmap for '%s'!\n", wip->name));
Warning(LOCATION, "Could not find a usable particle spew bitmap (%s) for weapon '%s'!\n", wip->particle_spewers[s].particle_spew_anim.filename, wip->name);
}
}
}
}
}
// load alternate thruster textures
if (strlen(wip->thruster_flame.filename)) {
generic_anim_load(&wip->thruster_flame);
}
if (strlen(wip->thruster_glow.filename)) {
wip->thruster_glow.first_frame = bm_load(wip->thruster_glow.filename);
if (wip->thruster_glow.first_frame >= 0) {
wip->thruster_glow.num_frames = 1;
wip->thruster_glow.total_time = 1;
} else {
generic_anim_load(&wip->thruster_glow);
}
}
// if this weapon isn't already marked as used, then mark it as such now
// (this should really only happen if the player is cheating)
if ( !used_weapons[weapon_index] )
used_weapons[weapon_index]++;
}
/**
* Checks all of the weapon infos for substitution patterns and caches the weapon_index of any that it finds.
*/
void weapon_generate_indexes_for_substitution() {
for (int i = 0; i < MAX_WEAPON_TYPES; i++) {
weapon_info *wip = &(Weapon_info[i]);
if ( wip->weapon_substitution_pattern_names.size() > 0 ) {
wip->weapon_substitution_pattern.resize(wip->weapon_substitution_pattern_names.size());
for ( size_t j = 0; j < wip->weapon_substitution_pattern_names.size(); j++ ) {
int weapon_index = -1;
if ( stricmp("none", wip->weapon_substitution_pattern_names[j].c_str()) != 0 ) {
weapon_index = weapon_info_lookup(wip->weapon_substitution_pattern_names[j].c_str());
if ( weapon_index == -1 ) { // invalid sub weapon
Warning(LOCATION, "Weapon '%s' requests substitution with '%s' which does not seem to exist",
wip->name, wip->weapon_substitution_pattern_names[j].c_str());
continue;
}
}
wip->weapon_substitution_pattern[j] = weapon_index;
}
wip->weapon_substitution_pattern_names.clear();
}
}
}
void weapon_do_post_parse()
{
weapon_info *wip;
int first_cmeasure_index = -1;
int i;
weapon_sort_by_type(); // NOTE: This has to be first thing!
weapon_clean_entries();
weapon_generate_indexes_for_substitution();
Default_cmeasure_index = -1;
// run through weapons list and deal with individual issues
for (i = 0; i < Num_weapon_types; i++) {
wip = &Weapon_info[i];
// set default counter-measure index from the saved name
if ( (Default_cmeasure_index < 0) && strlen(Default_cmeasure_name) ) {
if ( !stricmp(wip->name, Default_cmeasure_name) ) {
Default_cmeasure_index = i;
}
}
// catch a fall back cmeasure index, just in case
if ( (first_cmeasure_index < 0) && (wip->wi_flags & WIF_CMEASURE) )
first_cmeasure_index = i;
}
// catch cmeasure fallback
if (Default_cmeasure_index < 0)
Default_cmeasure_index = first_cmeasure_index;
// translate all spawn type weapons to referrence the appropriate spawned weapon entry
translate_spawn_types();
}
void weapon_expl_info_init()
{
int i;
parse_weapon_expl_tbl("weapon_expl.tbl");
// check for, and load, modular tables
parse_modular_table(NOX("*-wxp.tbm"), parse_weapon_expl_tbl);
// we've got our list so pass it off for final checking and loading
for (i = 0; i < (int)LOD_checker.size(); i++) {
Weapon_explosions.Load( LOD_checker[i].filename, LOD_checker[i].num_lods );
}
// done
LOD_checker.clear();
}
void weapon_reset_info()
{
memset( Weapon_info, 0, sizeof(weapon_info) * MAX_WEAPON_TYPES );
for (int i = 0; i < MAX_WEAPON_TYPES; i++)
init_weapon_entry(i);
}
/**
* This will get called once at game startup
*/
void weapon_init()
{
if ( !Weapons_inited ) {
//Init weapon explosion info
weapon_expl_info_init();
// parse weapons.tbl
weapon_reset_info();
Num_weapon_types = 0;
Num_spawn_types = 0;
parse_weaponstbl("weapons.tbl");
parse_modular_table(NOX("*-wep.tbm"), parse_weaponstbl);
// do post-parse cleanup
weapon_do_post_parse();
Weapons_inited = 1;
}
weapon_level_init();
}
/**
* Call from game_shutdown() only!!
*/
void weapon_close()
{
int i;
for (i = 0; i<MAX_WEAPON_TYPES; i++) {
if (Weapon_info[i].desc) {
vm_free(Weapon_info[i].desc);
Weapon_info[i].desc = NULL;
}
if (Weapon_info[i].tech_desc) {
vm_free(Weapon_info[i].tech_desc);
Weapon_info[i].tech_desc = NULL;
}
}
if (used_weapons != NULL) {
delete[] used_weapons;
used_weapons = NULL;
}
if (Spawn_names != NULL) {
for (i=0; i<Num_spawn_types; i++) {
if (Spawn_names[i] != NULL) {
vm_free(Spawn_names[i]);
Spawn_names[i] = NULL;
}
}
vm_free(Spawn_names);
Spawn_names = NULL;
}
}
/**
* This will get called at the start of each level.
*/
void weapon_level_init()
{
int i;
// Reset everything between levels
Num_weapons = 0;
for (i=0; i<MAX_WEAPONS; i++) {
Weapons[i].objnum = -1;
Weapons[i].weapon_info_index = -1;
}
for (i=0; i<MAX_WEAPON_TYPES; i++) {
Weapon_info[i].damage_type_idx = Weapon_info[i].damage_type_idx_sav;
Weapon_info[i].shockwave.damage_type_idx = Weapon_info[i].shockwave.damage_type_idx_sav;
}
trail_level_init(); // reset all missile trails
swarm_level_init();
missile_obj_list_init();
cscrew_level_init();
// emp effect
emp_level_init();
if (used_weapons == NULL)
used_weapons = new int[Num_weapon_types];
Assert( used_weapons != NULL );
// clear out used_weapons between missions
if (used_weapons != NULL)
memset(used_weapons, 0, Num_weapon_types * sizeof(int));
Weapon_flyby_sound_timer = timestamp(0);
Weapon_impact_timer = 1; // inited each level, used to reduce impact sounds
}
MONITOR( NumWeaponsRend )
const float weapon_glow_scale_f = 2.3f;
const float weapon_glow_scale_r = 2.3f;
const float weapon_glow_scale_l = 1.5f;
const int weapon_glow_alpha = 217; // (0.85 * 255);
void weapon_render(object *obj)
{
int num;
weapon_info *wip;
weapon *wp;
color c;
MONITOR_INC(NumWeaponsRend, 1);
Assert(obj->type == OBJ_WEAPON);
num = obj->instance;
wp = &Weapons[num];
wip = &Weapon_info[Weapons[num].weapon_info_index];
if (wip->wi_flags2 & WIF2_TRANSPARENT) {
if (wp->alpha_current == -1.0f) {
wp->alpha_current = wip->alpha_max;
} else if (wip->alpha_cycle > 0.0f) {
if (wp->alpha_backward) {
wp->alpha_current += wip->alpha_cycle;
if (wp->alpha_current > wip->alpha_max) {
wp->alpha_current = wip->alpha_max;
wp->alpha_backward = 0;
}
} else {
wp->alpha_current -= wip->alpha_cycle;
if (wp->alpha_current < wip->alpha_min) {
wp->alpha_current = wip->alpha_min;
wp->alpha_backward = 1;
}
}
}
}
switch (wip->render_type)
{
case WRT_LASER:
{
if(wip->laser_length < 0.0001f)
return;
// turn off fogging for good measure
gr_fog_set(GR_FOGMODE_NONE, 0, 0, 0);
int alpha = 255;
int framenum = 0;
if (wip->laser_bitmap.first_frame >= 0) {
gr_set_color_fast(&wip->laser_color_1);
if (wip->laser_bitmap.num_frames > 1) {
wp->laser_bitmap_frame += flFrametime;
// Sanity checks
if (wp->laser_bitmap_frame < 0.0f)
wp->laser_bitmap_frame = 0.0f;
if (wp->laser_bitmap_frame > 100.0f)
wp->laser_bitmap_frame = 0.0f;
while (wp->laser_bitmap_frame > wip->laser_bitmap.total_time)
wp->laser_bitmap_frame -= wip->laser_bitmap.total_time;
framenum = fl2i( (wp->laser_bitmap_frame * wip->laser_bitmap.num_frames) / wip->laser_bitmap.total_time );
CLAMP(framenum, 0, wip->laser_bitmap.num_frames-1);
}
if (wip->wi_flags2 & WIF2_TRANSPARENT)
alpha = fl2i(wp->alpha_current * 255.0f);
vec3d headp;
vm_vec_scale_add(&headp, &obj->pos, &obj->orient.vec.fvec, wip->laser_length);
wp->weapon_flags &= ~WF_CONSIDER_FOR_FLYBY_SOUND;
if ( batch_add_laser(wip->laser_bitmap.first_frame + framenum, &headp, wip->laser_head_radius, &obj->pos, wip->laser_tail_radius, alpha, alpha, alpha) ) {
wp->weapon_flags |= WF_CONSIDER_FOR_FLYBY_SOUND;
}
}
// maybe draw laser glow bitmap
if (wip->laser_glow_bitmap.first_frame >= 0) {
// get the laser color
weapon_get_laser_color(&c, obj);
// *Tail point "getting bigger" as well as headpoint isn't being taken into consideration, so
// it caused uneven glow between the head and tail, which really shows in big lasers. So...fixed! -Et1
vec3d headp2, tailp;
vm_vec_scale_add(&headp2, &obj->pos, &obj->orient.vec.fvec, wip->laser_length * weapon_glow_scale_l);
vm_vec_scale_add(&tailp, &obj->pos, &obj->orient.vec.fvec, wip->laser_length * (1 - weapon_glow_scale_l) );
framenum = 0;
if (wip->laser_glow_bitmap.num_frames > 1) {
wp->laser_glow_bitmap_frame += flFrametime;
// Sanity checks
if (wp->laser_glow_bitmap_frame < 0.0f)
wp->laser_glow_bitmap_frame = 0.0f;
if (wp->laser_glow_bitmap_frame > 100.0f)
wp->laser_glow_bitmap_frame = 0.0f;
while (wp->laser_glow_bitmap_frame > wip->laser_glow_bitmap.total_time)
wp->laser_glow_bitmap_frame -= wip->laser_glow_bitmap.total_time;
framenum = fl2i( (wp->laser_glow_bitmap_frame * wip->laser_glow_bitmap.num_frames) / wip->laser_glow_bitmap.total_time );
CLAMP(framenum, 0, wip->laser_glow_bitmap.num_frames-1);
}
if (wip->wi_flags2 & WIF2_TRANSPARENT) {
alpha = fl2i(wp->alpha_current * 255.0f);
alpha -= 38; // take 1.5f into account for the normal glow alpha
if (alpha < 0)
alpha = 0;
} else {
alpha = weapon_glow_alpha;
}
batch_add_laser(wip->laser_glow_bitmap.first_frame + framenum, &headp2, wip->laser_head_radius * weapon_glow_scale_f, &tailp, wip->laser_tail_radius * weapon_glow_scale_r, (c.red*alpha)/255, (c.green*alpha)/255, (c.blue*alpha)/255);
}
break;
}
case WRT_POF:
{
uint render_flags = MR_NORMAL|MR_IS_MISSILE|MR_NO_LIGHTING;
if (Cmdline_missile_lighting && !(wip->wi_flags2 & WIF2_MR_NO_LIGHTING))
render_flags &= ~MR_NO_LIGHTING;
if (wip->wi_flags2 & WIF2_TRANSPARENT) {
model_set_alpha(wp->alpha_current);
render_flags |= MR_ALL_XPARENT;
}
model_clear_instance(wip->model_num);
if ( (wip->wi_flags & WIF_THRUSTER) && ((wp->thruster_bitmap > -1) || (wp->thruster_glow_bitmap > -1)) ) {
float ft;
mst_info mst;
// Add noise to thruster geometry.
ft = 1.0f; // Always use 1.0f for missiles
ft *= (1.0f + frand()/5.0f - 1.0f/10.0f);
if (ft > 1.0f)
ft = 1.0f;
mst.length.xyz.x = ft;
mst.length.xyz.y = ft;
mst.length.xyz.z = ft;
mst.primary_bitmap = wp->thruster_bitmap;
mst.primary_glow_bitmap = wp->thruster_glow_bitmap;
mst.glow_rad_factor = wip->thruster_glow_factor;
mst.glow_noise = wp->thruster_glow_noise;
model_set_thrust(wip->model_num, &mst);
render_flags |= MR_SHOW_THRUSTERS;
}
//don't render local ssm's when they are still in subspace
if (wp->lssm_stage==3)
break;
int clip_plane=0;
//start a clip plane
if (wp->lssm_stage==2)
{
object *wobj=&Objects[wp->lssm_warp_idx]; //warphole object
clip_plane=1;
g3_start_user_clip_plane(&wobj->pos,&wobj->orient.vec.fvec);
}
model_render(wip->model_num, &obj->orient, &obj->pos, render_flags);
wp->weapon_flags |= WF_CONSIDER_FOR_FLYBY_SOUND;
if (clip_plane)
{
g3_stop_user_clip_plane();
}
break;
}
default:
Warning(LOCATION, "Unknown weapon rendering type = %i for weapon %s\n", wip->render_type, wip->name);
}
}
void weapon_delete(object *obj)
{
weapon *wp;
int num;
Script_system.SetHookObjects(2, "Weapon", obj, "Self", obj);
Script_system.RunCondition(CHA_ONWEAPONDELETE);
Script_system.RemHookVars(2, "Weapon", "Self");
num = obj->instance;
Assert( Weapons[num].objnum == OBJ_INDEX(obj));
wp = &Weapons[num];
Assert(wp->weapon_info_index >= 0);
wp->weapon_info_index = -1;
if (wp->swarm_index >= 0) {
swarm_delete(wp->swarm_index);
wp->swarm_index = -1;
}
if(wp->cscrew_index >= 0) {
cscrew_delete(wp->cscrew_index);
wp->cscrew_index = -1;
}
if (wp->missile_list_index >= 0) {
missle_obj_list_remove(wp->missile_list_index);
wp->missile_list_index = -1;
}
if (wp->trail_ptr != NULL) {
trail_object_died(wp->trail_ptr);
wp->trail_ptr = NULL;
}
if (wp->hud_in_flight_snd_sig >= 0 && snd_is_playing(wp->hud_in_flight_snd_sig))
{
snd_stop(wp->hud_in_flight_snd_sig);
}
wp->objnum = -1;
Num_weapons--;
Assert(Num_weapons >= 0);
}
/**
* Check if missile is newly locked onto the Player, maybe play a launch warning
*/
void weapon_maybe_play_warning(weapon *wp)
{
if ( wp->homing_object == Player_obj ) {
if ( !(wp->weapon_flags & WF_LOCK_WARNING_PLAYED) ) {
wp->weapon_flags |= WF_LOCK_WARNING_PLAYED;
// Use heatlock-warning sound for Heat and Javelin for now
// Possibly add an additional third sound later
if ( (Weapon_info[wp->weapon_info_index].wi_flags & WIF_HOMING_HEAT) ||
(Weapon_info[wp->weapon_info_index].wi_flags & WIF_HOMING_JAVELIN) ) {
snd_play(&Snds[ship_get_sound(Player_obj, SND_HEATLOCK_WARN)]);
} else {
Assert(Weapon_info[wp->weapon_info_index].wi_flags & WIF_HOMING_ASPECT);
snd_play(&Snds[ship_get_sound(Player_obj, SND_ASPECTLOCK_WARN)]);
}
}
}
}
#define CMEASURE_DETONATE_DISTANCE 40.0f
/**
* Detonate all missiles near this countermeasure.
*/
void detonate_nearby_missiles(object *killer_objp)
{
if(killer_objp->type != OBJ_WEAPON) {
Int3();
return;
}
missile_obj *mop;
mop = GET_FIRST(&Missile_obj_list);
while(mop != END_OF_LIST(&Missile_obj_list)) {
object *objp;
weapon *wp;
objp = &Objects[mop->objnum];
wp = &Weapons[objp->instance];
if (iff_x_attacks_y(Weapons[killer_objp->instance].team, wp->team)) {
if ( Missiontime - wp->creation_time > F1_0/2) {
if (vm_vec_dist_quick(&killer_objp->pos, &objp->pos) < CMEASURE_DETONATE_DISTANCE) {
if (wp->lifeleft > 0.2f) {
wp->lifeleft = 0.2f;
}
}
}
}
mop = mop->next;
}
}
/**
* Find an object for weapon #num (object *weapon_objp) to home on due to heat.
*/
void find_homing_object(object *weapon_objp, int num)
{
object *objp, *old_homing_objp;
weapon_info *wip;
weapon *wp;
ship *sp;
ship_info *sip;
float best_dist;
int homing_object_team;
float dist;
float dot;
vec3d vec_to_object;
ship_subsys *target_engines = NULL;
wp = &Weapons[num];
wip = &Weapon_info[Weapons[num].weapon_info_index];
best_dist = 99999.9f;
// save the old homing object so that multiplayer servers can give the right information
// to clients if the object changes
old_homing_objp = wp->homing_object;
wp->homing_object = &obj_used_list;
// Scan all objects, find a weapon to home on.
for ( objp = GET_FIRST(&obj_used_list); objp !=END_OF_LIST(&obj_used_list); objp = GET_NEXT(objp) ) {
if ((objp->type == OBJ_SHIP) || ((objp->type == OBJ_WEAPON) && (Weapon_info[Weapons[objp->instance].weapon_info_index].wi_flags & WIF_CMEASURE)))
{
//WMC - Spawn weapons shouldn't go for protected ships
// ditto for untargeted heat seekers - niffiwan
if ( (objp->flags & OF_PROTECTED) &&
((wp->weapon_flags & WF_SPAWNED) || (wip->wi_flags2 & WIF2_UNTARGETED_HEAT_SEEKER)) )
continue;
// Spawned weapons should never home in on their parent - even in multiplayer dogfights where they would pass the iff test below
if ((wp->weapon_flags & WF_SPAWNED) && (objp == &Objects[weapon_objp->parent]))
continue;
homing_object_team = obj_team(objp);
if (iff_x_attacks_y(wp->team, homing_object_team))
{
if ( objp->type == OBJ_SHIP )
{
sp = &Ships[objp->instance];
sip = &Ship_info[sp->ship_info_index];
//if the homing weapon is a huge weapon and the ship that is being
//looked at is not huge, then don't home
if ((wip->wi_flags & WIF_HUGE) &&
(sip->flags & (SIF_SMALL_SHIP | SIF_NOT_FLYABLE | SIF_HARMLESS)))
{
continue;
}
// AL 2-17-98: If ship is immune to sensors, can't home on it (Sandeep says so)!
if ( sp->flags & SF_HIDDEN_FROM_SENSORS ) {
continue;
}
// Goober5000: if missiles can't home on sensor-ghosted ships,
// they definitely shouldn't home on stealth ships
if ( sp->flags2 & SF2_STEALTH && (The_mission.ai_profile->flags & AIPF_FIX_HEAT_SEEKER_STEALTH_BUG) ) {
continue;
}
if (wip->wi_flags & WIF_HOMING_JAVELIN)
{
target_engines = ship_get_closest_subsys_in_sight(sp, SUBSYSTEM_ENGINE, &weapon_objp->pos);
if (!target_engines)
continue;
}
// MK, 9/4/99.
// If this is a player object, make sure there aren't already too many homers.
// Only in single player. In multiplayer, we don't want to restrict it in dogfight on team vs. team.
// For co-op, it's probably also OK.
if (!( Game_mode & GM_MULTIPLAYER )) {
int num_homers = compute_num_homing_objects(objp);
if (The_mission.ai_profile->max_allowed_player_homers[Game_skill_level] < num_homers)
continue;
}
}
else if (objp->type == OBJ_WEAPON)
{
//don't attempt to home on weapons if the weapon is a huge weapon or is a javelin homing weapon.
if (wip->wi_flags & (WIF_HUGE | WIF_HOMING_JAVELIN))
continue;
//don't look for local ssms that are gone for the time being
if (Weapons[objp->instance].lssm_stage == 3)
continue;
}
dist = vm_vec_normalized_dir(&vec_to_object, &objp->pos, &weapon_objp->pos);
if (objp->type == OBJ_WEAPON && (Weapon_info[Weapons[objp->instance].weapon_info_index].wi_flags & WIF_CMEASURE)) {
dist *= 0.5f;
}
dot = vm_vec_dot(&vec_to_object, &weapon_objp->orient.vec.fvec);
if (dot > wip->fov) {
if (dist < best_dist) {
best_dist = dist;
wp->homing_object = objp;
wp->target_sig = objp->signature;
wp->homing_subsys = target_engines;
cmeasure_maybe_alert_success(objp);
}
}
}
}
}
if (wp->homing_object == Player_obj)
weapon_maybe_play_warning(wp);
// if the old homing object is different that the new one, send a packet to clients
if ( MULTIPLAYER_MASTER && (old_homing_objp != wp->homing_object) ) {
send_homing_weapon_info( num );
}
}
/**
* Scan all countermeasures. Maybe make weapon_objp home on it.
*/
void find_homing_object_cmeasures_1(object *weapon_objp)
{
object *objp;
weapon *wp, *cm_wp;
weapon_info *wip, *cm_wip;
float best_dot, dist, dot;
wp = &Weapons[weapon_objp->instance];
wip = &Weapon_info[wp->weapon_info_index];
best_dot = wip->fov; // Note, setting to this avoids comparison below.
for ( objp = GET_FIRST(&obj_used_list); objp !=END_OF_LIST(&obj_used_list); objp = GET_NEXT(objp) )
{
//first check if its a weapon, then setup the pointers
if (objp->type == OBJ_WEAPON)
{
cm_wp = &Weapons[objp->instance];
cm_wip = &Weapon_info[cm_wp->weapon_info_index];
if (cm_wip->wi_flags & WIF_CMEASURE)
{
//don't have a weapon try to home in on itself
if (objp==weapon_objp)
continue;
//don't have a weapon try to home in on missiles fired by the same team, unless its the traitor team.
if ((wp->team == cm_wp->team) && (wp->team != Iff_traitor))
continue;
vec3d vec_to_object;
dist = vm_vec_normalized_dir(&vec_to_object, &objp->pos, &weapon_objp->pos);
if (dist < cm_wip->cm_effective_rad)
{
float chance;
if (wip->wi_flags & WIF_HOMING_ASPECT) {
// aspect seeker this likely to chase a countermeasure
chance = cm_wip->cm_aspect_effectiveness/wip->seeker_strength;
} else {
// heat seeker and javelin HS this likely to chase a countermeasure
chance = cm_wip->cm_heat_effectiveness/wip->seeker_strength;
}
if ((objp->signature != wp->cmeasure_ignore_objnum) && (objp->signature != wp->cmeasure_chase_objnum))
{
if (frand() >= chance) {
wp->cmeasure_ignore_objnum = objp->signature; // Don't process this countermeasure again.
} else {
wp->cmeasure_chase_objnum = objp->signature; // Don't process this countermeasure again.
}
}
if (objp->signature != wp->cmeasure_ignore_objnum)
{
dot = vm_vec_dot(&vec_to_object, &weapon_objp->orient.vec.fvec);
if (dot > best_dot)
{
best_dot = dot;
wp->homing_object = objp;
cmeasure_maybe_alert_success(objp);
}
}
}
}
}
}
}
/**
* Someone launched countermeasures.
* For all heat-seeking homing objects, see if should favor tracking a countermeasure instead.
*/
void find_homing_object_cmeasures()
{
object *weapon_objp;
if (Cmeasures_homing_check == 0)
return;
if (Cmeasures_homing_check <= 0)
Cmeasures_homing_check = 1;
Cmeasures_homing_check--;
for (weapon_objp = GET_FIRST(&obj_used_list); weapon_objp != END_OF_LIST(&obj_used_list); weapon_objp = GET_NEXT(weapon_objp) ) {
if (weapon_objp->type == OBJ_WEAPON) {
weapon_info *wip = &Weapon_info[Weapons[weapon_objp->instance].weapon_info_index];
if (wip->wi_flags & WIF_HOMING)
find_homing_object_cmeasures_1(weapon_objp);
}
}
}
/**
* Find object with signature "sig" and make weapon home on it.
*/
void find_homing_object_by_sig(object *weapon_objp, int sig)
{
ship_obj *sop;
weapon *wp;
object *old_homing_objp;
wp = &Weapons[weapon_objp->instance];
// save the old object so that multiplayer masters know whether to send a homing update packet
old_homing_objp = wp->homing_object;
sop = GET_FIRST(&Ship_obj_list);
while(sop != END_OF_LIST(&Ship_obj_list)) {
object *objp;
objp = &Objects[sop->objnum];
if (objp->signature == sig) {
wp->homing_object = objp;
wp->target_sig = objp->signature;
break;
}
sop = sop->next;
}
// if the old homing object is different that the new one, send a packet to clients
if ( MULTIPLAYER_MASTER && (old_homing_objp != wp->homing_object) ) {
send_homing_weapon_info( weapon_objp->instance );
}
}
/**
* Make weapon num home. It's also object *obj.
*/
void weapon_home(object *obj, int num, float frame_time)
{
weapon *wp;
weapon_info *wip;
object *hobjp;
Assert(obj->type == OBJ_WEAPON);
Assert(obj->instance == num);
wp = &Weapons[num];
wip = &Weapon_info[wp->weapon_info_index];
hobjp = Weapons[num].homing_object;
//local ssms home only in stages 1 and 5
if ( (wp->lssm_stage==2) || (wp->lssm_stage==3) || (wp->lssm_stage==4))
return;
float max_speed;
if ((wip->wi_flags2 & WIF2_LOCAL_SSM) && (wp->lssm_stage==5))
max_speed=wip->lssm_stage5_vel;
else
max_speed=wip->max_speed;
// If not [free-flight-time] gone by, don't home yet.
// Goober5000 - this has been fixed back to more closely follow the original logic. Remember, the retail code
// had 0.5 second of free flight time, the first half of which was spent ramping up to full speed.
if ((hobjp == &obj_used_list) || ( f2fl(Missiontime - wp->creation_time) < (wip->free_flight_time / 2) )) {
// If this is a heat seeking homing missile and [free-flight-time] has elapsed since firing
// and we don't have a target (else we wouldn't be inside the IF), find a new target.
if ((wip->wi_flags & WIF_HOMING_HEAT) &&
(f2fl(Missiontime - wp->creation_time) > wip->free_flight_time))
{
find_homing_object(obj, num);
}
else if (MULTIPLAYER_MASTER && (wip->wi_flags & WIF_LOCKED_HOMING) && (wp->weapon_flags & WF_HOMING_UPDATE_NEEDED)) {
wp->weapon_flags &= ~WF_HOMING_UPDATE_NEEDED;
send_homing_weapon_info(num);
}
// since free_flight_time can now be 0, guard against that
if (wip->free_flight_time > 0.0f) {
if (obj->phys_info.speed > max_speed) {
obj->phys_info.speed -= frame_time * (2 / wip->free_flight_time);
} else if ((obj->phys_info.speed < max_speed / (2 / wip->free_flight_time)) && (wip->wi_flags & WIF_HOMING_HEAT)) {
obj->phys_info.speed = max_speed / (2 / wip->free_flight_time);
}
}
// no free_flight_time, so immediately set desired speed
else {
obj->phys_info.speed = max_speed;
}
// set velocity using whatever speed we have
vm_vec_copy_scale( &obj->phys_info.desired_vel, &obj->orient.vec.fvec, obj->phys_info.speed);
return;
}
// AL 4-8-98: If original target for aspect lock missile is lost, stop homing
// WCS - or javelin
if (wip->wi_flags & WIF_LOCKED_HOMING) {
if ( wp->target_sig > 0 ) {
if ( wp->homing_object->signature != wp->target_sig ) {
wp->homing_object = &obj_used_list;
return;
}
}
}
// AL 4-13-98: Stop homing on a subsystem if parent ship has changed
if (wip->wi_flags & WIF_HOMING_HEAT) {
if ( wp->target_sig > 0 ) {
if ( wp->homing_object->signature != wp->target_sig ) {
wp->homing_subsys = NULL;
}
}
}
// If target subsys is dead make missile pick random spot on target as attack point.
if (wp->homing_subsys != NULL) {
if (wp->homing_subsys->flags & SSF_MISSILES_IGNORE_IF_DEAD) {
if ((wp->homing_subsys->max_hits > 0) && (wp->homing_subsys->current_hits <= 0)) {
wp->homing_object = &obj_used_list;
return;
}
}
}
// Make sure Javelin HS missiles always home on engine subsystems if ships
if ((wip->wi_flags & WIF_HOMING_JAVELIN) &&
(hobjp->type == OBJ_SHIP) &&
(wp->target_sig > 0) &&
(wp->homing_subsys != NULL) &&
(wp->homing_subsys->system_info->type != SUBSYSTEM_ENGINE)) {
ship *enemy = &Ships[ship_get_by_signature(wp->target_sig)];
wp->homing_subsys = ship_get_closest_subsys_in_sight(enemy, SUBSYSTEM_ENGINE, &Objects[wp->objnum].pos);
}
// If Javelin HS missile doesn't home in on a subsystem but homing in on a
// ship, lose lock alltogether
// Javelins can only home in one Engines or bombs.
if ((wip->wi_flags & WIF_HOMING_JAVELIN) &&
(hobjp->type == OBJ_SHIP) &&
(wp->target_sig > 0) &&
(wp->homing_subsys == NULL)) {
wp->homing_object = &obj_used_list;
return;
}
switch (hobjp->type) {
case OBJ_NONE:
if (wip->wi_flags & WIF_LOCKED_HOMING) {
find_homing_object_by_sig(obj, wp->target_sig);
} else {
find_homing_object(obj, num);
}
return;
break;
case OBJ_SHIP:
if (hobjp->signature != wp->target_sig) {
if (wip->wi_flags & WIF_LOCKED_HOMING) {
find_homing_object_by_sig(obj, wp->target_sig);
} else {
find_homing_object(obj, num);
}
return;
}
break;
case OBJ_WEAPON:
// don't home on countermeasures or non-bombs, that's handled elsewhere
if ( ((Weapon_info[Weapons[hobjp->instance].weapon_info_index].wi_flags & WIF_CMEASURE) && !(The_mission.ai_profile->flags2 & AIPF2_ASPECT_LOCK_COUNTERMEASURE)) || !(Weapon_info[Weapons[hobjp->instance].weapon_info_index].wi_flags & WIF_BOMB) )
break;
if (wip->wi_flags & WIF_LOCKED_HOMING) {
find_homing_object_by_sig(obj, wp->target_sig);
} else {
find_homing_object(obj, num);
}
break;
default:
return;
}
// See if this weapon is the nearest homing object to the object it is homing on.
// If so, update some fields in the target object's ai_info.
if (hobjp != &obj_used_list) {
float dist;
dist = vm_vec_dist_quick(&obj->pos, &hobjp->pos);
if (hobjp->type == OBJ_SHIP) {
ai_info *aip;
aip = &Ai_info[Ships[hobjp->instance].ai_index];
if ((aip->nearest_locked_object == -1) || (dist < aip->nearest_locked_distance)) {
aip->nearest_locked_object = obj-Objects;
aip->nearest_locked_distance = dist;
}
}
}
// If the object it is homing on is still valid, home some more!
if (hobjp != &obj_used_list) {
float old_dot, vel;
vec3d vec_to_goal;
vec3d target_pos; // position of what the homing missile is seeking
vm_vec_zero(&target_pos);
// the homing missile may be seeking a subsystem on a ship. If so, we need to calculate the
// world coordinates of that subsystem so the homing missile can seek it out.
// For now, March 7, 1997, MK, heat seeking homing missiles will be able to home on
// any subsystem. Probably makes sense for them to only home on certain kinds of subsystems.
if ( (wp->homing_subsys != NULL) && !(wip->wi_flags2 & WIF2_NON_SUBSYS_HOMING) ) {
get_subsystem_world_pos(hobjp, Weapons[num].homing_subsys, &target_pos);
wp->homing_pos = target_pos; // store the homing position in weapon data
Assert( !vm_is_vec_nan(&wp->homing_pos) );
} else {
float fov;
float dist;
dist = vm_vec_dist_quick(&obj->pos, &hobjp->pos);
if (hobjp->type == OBJ_WEAPON && (Weapon_info[Weapons[hobjp->instance].weapon_info_index].wi_flags & WIF_CMEASURE))
{
if (dist < CMEASURE_DETONATE_DISTANCE)
{
// Make this missile detonate soon. Not right away, not sure why. Seems better.
if (iff_x_attacks_y(Weapons[hobjp->instance].team, wp->team)) {
detonate_nearby_missiles(hobjp);
return;
}
}
}
fov = -1.0f;
int pick_homing_point = 0;
if ( IS_VEC_NULL(&wp->homing_pos) ) {
pick_homing_point = 1;
}
// Update homing position if it hasn't been set, you're within 500 meters, or every half second, approximately.
// For large objects, don't lead them.
if (hobjp->radius < 40.0f) {
target_pos = hobjp->pos;
wp->homing_pos = target_pos;
} else if ( pick_homing_point || (dist < 500.0f) || (rand_chance(flFrametime, 2.0f)) ) {
if (hobjp->type == OBJ_SHIP) {
if ( !pick_homing_point ) {
// ensure that current attack point is only updated in world coords (ie not pick a different vertex)
wp->pick_big_attack_point_timestamp = 0;
}
if ( pick_homing_point && !(wip->wi_flags2 & WIF2_NON_SUBSYS_HOMING) ) {
// If *any* player is parent of homing missile, then use position where lock indicator is
if ( Objects[obj->parent].flags & OF_PLAYER_SHIP ) {
player *pp;
// determine the player
pp = Player;
if ( Game_mode & GM_MULTIPLAYER ) {
int pnum;
pnum = multi_find_player_by_object( &Objects[obj->parent] );
if ( pnum != -1 ){
pp = Net_players[pnum].m_player;
}
}
// If player has apect lock, we don't want to find a homing point on the closest
// octant... setting the timestamp to 0 ensures this.
if (wip->wi_flags & WIF_LOCKED_HOMING) {
wp->pick_big_attack_point_timestamp = 0;
} else {
wp->pick_big_attack_point_timestamp = 1;
}
if ( pp && pp->locking_subsys ) {
wp->big_attack_point = pp->locking_subsys->system_info->pnt;
} else {
vm_vec_zero(&wp->big_attack_point);
}
}
}
ai_big_pick_attack_point(hobjp, obj, &target_pos, fov);
} else {
target_pos = hobjp->pos;
}
wp->homing_pos = target_pos;
Assert( !vm_is_vec_nan(&wp->homing_pos) );
} else
target_pos = wp->homing_pos;
}
// Couldn't find a lock.
if (IS_VEC_NULL(&target_pos))
return;
// Cause aspect seeking weapon to home at target's predicted position.
// But don't use predicted position if dot product small or negative.
// If do this, with a ship headed towards missile, could choose a point behind missile.
float dist_to_target, time_to_target;
dist_to_target = vm_vec_normalized_dir(&vec_to_goal, &target_pos, &obj->pos);
time_to_target = dist_to_target/max_speed;
vec3d tvec;
tvec = obj->phys_info.vel;
vm_vec_normalize(&tvec);
old_dot = vm_vec_dot(&tvec, &vec_to_goal);
// If a weapon has missed its target, detonate it.
// This solves the problem of a weapon circling the center of a subsystem that has been blown away.
// Problem: It does not do impact damage, just proximity damage.
if ((dist_to_target < flFrametime * obj->phys_info.speed * 4.0f + 10.0f) &&
(old_dot < wip->fov) &&
(wp->lifeleft > 0.01f) &&
(wp->homing_object) &&
(wp->homing_object->type == OBJ_SHIP))
{
wp->lifeleft = 0.01f;
}
// Only lead target if more than one second away. Otherwise can miss target. I think this
// is what's causing Harbingers to miss the super destroyer. -- MK, 4/15/98
if ((old_dot > 0.1f) && (time_to_target > 0.1f)) {
if (wip->wi_flags2 & WIF2_VARIABLE_LEAD_HOMING) {
vm_vec_scale_add2(&target_pos, &hobjp->phys_info.vel, (0.33f * wip->target_lead_scaler * MIN(time_to_target, 6.0f)));
} else if (wip->wi_flags & WIF_LOCKED_HOMING) {
vm_vec_scale_add2(&target_pos, &hobjp->phys_info.vel, MIN(time_to_target, 2.0f));
}
}
// If a HEAT seeking (rather than ASPECT seeking) homing missile, verify that target is in viewcone.
if (wip->wi_flags & WIF_HOMING_HEAT) {
if ((old_dot < wip->fov) && (dist_to_target > wip->shockwave.inner_rad*1.1f)) { // Delay finding new target one frame to allow detonation.
find_homing_object(obj, num);
return; // Maybe found a new homing object. Return, process more next frame.
} else // Subtract out life based on how far from target this missile points.
if ((wip->fov < 0.95f) && !(wip->wi_flags2 & WIF2_NO_LIFE_LOST_IF_MISSED)) {
wp->lifeleft -= flFrametime * (0.95f - old_dot);
}
} else if (wip->wi_flags & WIF_LOCKED_HOMING) { // subtract life as if max turn is 90 degrees.
if ((wip->fov < 0.95f) && !(wip->wi_flags2 & WIF2_NO_LIFE_LOST_IF_MISSED))
wp->lifeleft -= flFrametime * (0.95f - old_dot);
} else {
Warning(LOCATION, "Tried to make weapon '%s' home, but found it wasn't aspect-seeking or heat-seeking or a Javelin!", wip->name);
}
// Control speed based on dot product to goal. If close to straight ahead, move
// at max speed, else move slower based on how far from ahead.
if (old_dot < 0.90f) {
obj->phys_info.speed = MAX(0.2f, old_dot* (float) fabs(old_dot));
if (obj->phys_info.speed < max_speed*0.75f)
obj->phys_info.speed = max_speed*0.75f;
} else
obj->phys_info.speed = max_speed;
// For first second of weapon's life, it doesn't fly at top speed. It ramps up.
if (Missiontime - wp->creation_time < i2f(1)) {
float t;
t = f2fl(Missiontime - wp->creation_time);
obj->phys_info.speed *= t*t;
}
Assert( obj->phys_info.speed > 0.0f );
vm_vec_copy_scale( &obj->phys_info.desired_vel, &obj->orient.vec.fvec, obj->phys_info.speed);
// turn the missile towards the target only if non-swarm. Homing swarm missiles choose
// a different vector to turn towards, this is done in swarm_update_direction().
if ( wp->swarm_index < 0 ) {
ai_turn_towards_vector(&target_pos, obj, frame_time, wip->turn_time, NULL, NULL, 0.0f, 0, NULL);
vel = vm_vec_mag(&obj->phys_info.desired_vel);
vm_vec_copy_scale(&obj->phys_info.desired_vel, &obj->orient.vec.fvec, vel);
}
}
}
// as Mike K did with ships -- break weapon into process_pre and process_post for code to execute
// before and after physics movement
void weapon_process_pre( object *obj, float frame_time)
{
if(obj->type != OBJ_WEAPON)
return;
weapon *wp = &Weapons[obj->instance];
weapon_info *wip = &Weapon_info[wp->weapon_info_index];
// if the object is a corkscrew style weapon, process it now
if((obj->type == OBJ_WEAPON) && (Weapons[obj->instance].cscrew_index >= 0)){
cscrew_process_pre(obj);
}
//WMC - Originally flak_maybe_detonate, moved here.
if(wp->det_range > 0.0f)
{
vec3d temp;
vm_vec_sub(&temp, &obj->pos, &wp->start_pos);
if(vm_vec_mag(&temp) >= wp->det_range){
weapon_detonate(obj);
}
}
//WMC - Maybe detonate weapon anyway!
if(wip->det_radius > 0.0f)
{
if((wp->homing_object != NULL) && (wp->homing_object->type != 0))
{
if(vm_vec_dist(&wp->homing_pos, &obj->pos) <= wip->det_radius)
{
weapon_detonate(obj);
}
} else if(wp->target_num > -1)
{
if(vm_vec_dist(&obj->pos, &Objects[wp->target_num].pos) <= wip->det_radius)
{
weapon_detonate(obj);
}
}
}
}
int Homing_hits = 0, Homing_misses = 0;
MONITOR( NumWeapons )
/**
* Maybe play a "whizz sound" if close enough to view position
*/
void weapon_maybe_play_flyby_sound(object *weapon_objp, weapon *wp)
{
// don't play flyby sounds too close together
if ( !timestamp_elapsed(Weapon_flyby_sound_timer) ) {
return;
}
if ( !(wp->weapon_flags & WF_PLAYED_FLYBY_SOUND) && (wp->weapon_flags & WF_CONSIDER_FOR_FLYBY_SOUND) ) {
float dist, dot, radius;
if ( (Weapon_info[wp->weapon_info_index].wi_flags & WIF_CORKSCREW) ) {
dist = vm_vec_dist_quick(&weapon_objp->last_pos, &Eye_position);
} else {
dist = vm_vec_dist_quick(&weapon_objp->pos, &Eye_position);
}
if ( Viewer_obj ) {
radius = Viewer_obj->radius;
} else {
radius = 0.0f;
}
if ( (dist > radius) && (dist < 55) ) {
vec3d vec_to_weapon;
vm_vec_sub(&vec_to_weapon, &weapon_objp->pos, &Eye_position);
vm_vec_normalize(&vec_to_weapon);
// ensure laser is in front of eye
dot = vm_vec_dot(&vec_to_weapon, &Eye_matrix.vec.fvec);
if ( dot < 0.1 ) {
return;
}
// ensure that laser is moving in similar direction to fvec
dot = vm_vec_dot(&vec_to_weapon, &weapon_objp->orient.vec.fvec);
if ( (dot < -0.80) && (dot > -0.98) ) {
if(Weapon_info[wp->weapon_info_index].flyby_snd != -1) {
snd_play_3d( &Snds[Weapon_info[wp->weapon_info_index].flyby_snd], &weapon_objp->pos, &Eye_position );
} else {
if ( Weapon_info[wp->weapon_info_index].subtype == WP_LASER ) {
snd_play_3d( &Snds[SND_WEAPON_FLYBY], &weapon_objp->pos, &Eye_position );
}
}
Weapon_flyby_sound_timer = timestamp(200);
wp->weapon_flags |= WF_PLAYED_FLYBY_SOUND;
}
}
}
}
// process a weapon after physics movement. MWA reorders some of the code on 8/13 for multiplayer. When
// adding something to this function, decide whether or not a client in a multiplayer game needs to do
// what is normally done in a single player game. Things like plotting an object on a radar, effect
// for exhaust are things that are done on all machines. Things which calculate weapon targets, new
// velocities, etc, are server only functions and should go after the if ( !MULTIPLAYER_MASTER ) statement
// See Allender if you cannot decide what to do.
void weapon_process_post(object * obj, float frame_time)
{
int num;
weapon_info *wip;
weapon *wp;
MONITOR_INC( NumWeapons, 1 );
Assert(obj->type == OBJ_WEAPON);
num = obj->instance;
#ifndef NDEBUG
int objnum;
objnum = OBJ_INDEX(obj);
Assert( Weapons[num].objnum == objnum );
#endif
wp = &Weapons[num];
wp->lifeleft -= frame_time;
wip = &Weapon_info[wp->weapon_info_index];
if (wip->wi_flags2 & WIF2_LOCAL_SSM)
{
if ((wp->lssm_stage != 5) && (wp->lssm_stage != 0))
{
wp->lifeleft += frame_time;
}
}
// check life left. Multiplayer client code will go through here as well. We must be careful in weapon_hit
// when killing a missile that spawn child weapons!!!!
if ( wp->lifeleft < 0.0f ) {
if ( wip->subtype & WP_MISSILE ) {
if(Game_mode & GM_MULTIPLAYER){
if ( !MULTIPLAYER_CLIENT || (MULTIPLAYER_CLIENT && (wp->lifeleft < -2.0f)) || (MULTIPLAYER_CLIENT && (wip->wi_flags & WIF_CHILD))) { // don't call this function multiplayer client -- host will send this packet to us
weapon_detonate(obj);
}
} else {
weapon_detonate(obj);
}
if (wip->wi_flags & WIF_HOMING) {
Homing_misses++;
}
} else {
obj->flags |= OF_SHOULD_BE_DEAD;
}
return;
}
// plot homing missiles on the radar
if (((wip->wi_flags & WIF_BOMB) || (wip->wi_flags2 & WIF2_SHOWN_ON_RADAR)) && !(wip->wi_flags2 & WIF2_DONT_SHOW_ON_RADAR)) {
if ( hud_gauge_active(HUD_RADAR) ) {
radar_plot_object( obj );
}
}
// trail missiles
if ((wip->wi_flags & WIF_TRAIL) && !(wip->wi_flags & WIF_CORKSCREW)) {
if ( (wp->trail_ptr != NULL ) && (wp->lssm_stage!=3)) {
if (trail_stamp_elapsed(wp->trail_ptr)) {
trail_add_segment( wp->trail_ptr, &obj->pos );
trail_set_stamp(wp->trail_ptr);
} else {
trail_set_segment( wp->trail_ptr, &obj->pos );
}
}
}
if ( wip->wi_flags & WIF_THRUSTER ) {
ship_do_weapon_thruster_frame( wp, obj, flFrametime );
}
// maybe play a "whizz sound" if close enough to view position
#ifndef NDEBUG
if ( Weapon_flyby_sound_enabled ) {
weapon_maybe_play_flyby_sound(obj, wp);
}
#else
weapon_maybe_play_flyby_sound(obj, wp);
#endif
// If our target is still valid, then update some info.
if (wp->target_num != -1) {
if (Objects[wp->target_num].signature == wp->target_sig) {
float cur_dist;
vec3d v0;
vm_vec_avg(&v0, &obj->pos, &obj->last_pos);
cur_dist = vm_vec_dist_quick(&v0, &Objects[wp->target_num].pos);
if (cur_dist < wp->nearest_dist) {
wp->nearest_dist = cur_dist;
} else if (cur_dist > wp->nearest_dist + 1.0f) {
float dot;
vec3d tvec;
ai_info *parent_aip;
parent_aip = NULL;
if (obj->parent != Player_obj-Objects) {
parent_aip = &Ai_info[Ships[Objects[obj->parent].instance].ai_index];
}
vm_vec_normalized_dir(&tvec, &v0, &Objects[wp->target_num].pos);
dot = vm_vec_dot(&tvec, &Objects[wp->target_num].orient.vec.fvec);
wp->target_num = -1;
// Learn! If over-shooting or under-shooting, compensate.
// Really need to compensate for left/right errors. This does no good against someone circling
// in a plane perpendicular to the attacker's forward vector.
if (parent_aip != NULL) {
if (cur_dist > 100.0f)
parent_aip->lead_scale = 0.0f;
if (dot < -0.1f){
parent_aip->lead_scale += cur_dist/2000.0f;
} else if (dot > 0.1f) {
parent_aip->lead_scale -= cur_dist/2000.0f;
}
if (fl_abs(parent_aip->lead_scale) > 1.0f){
parent_aip->lead_scale *= 0.9f;
}
}
}
}
}
if(wip->wi_flags & WIF_PARTICLE_SPEW){
weapon_maybe_spew_particle(obj);
}
// a single player or multiplayer server function -- it affects actual weapon movement.
if (wip->wi_flags & WIF_HOMING) {
weapon_home(obj, num, frame_time);
// If this is a swarm type missile,
if ( wp->swarm_index >= 0 ) {
swarm_update_direction(obj, frame_time);
}
if( wp->cscrew_index >= 0) {
cscrew_process_post(obj);
}
}
//local ssm stuff
if (wip->wi_flags2 & WIF2_LOCAL_SSM)
{
//go into subspace if the missile is locked and its time to warpout
if ((wp->lssm_stage==1) && (timestamp_elapsed(wp->lssm_warpout_time)))
{
//if we don't have a lock at this point, just stay in normal space
if (wp->homing_object == &obj_used_list)
{
wp->lssm_stage=0;
return;
}
//point where to warpout
vec3d warpout;
//create a warp effect
vm_vec_copy_scale(&warpout,&obj->phys_info.vel,3.0f);
//set the time the warphole stays open, minimum of 7 seconds
wp->lssm_warp_time = ((obj->radius * 2) / (obj->phys_info.speed)) +1.5f;
wp->lssm_warp_time = MAX(wp->lssm_warp_time,7.0f);
//calculate the percerentage of the warpholes life at which the missile is fully in subspace.
wp->lssm_warp_pct = 1.0f - (3.0f/wp->lssm_warp_time);
//create the warphole
vm_vec_add2(&warpout,&obj->pos);
wp->lssm_warp_idx=fireball_create(&warpout, FIREBALL_WARP, FIREBALL_WARP_EFFECT, -1,obj->radius*1.5f,1,&vmd_zero_vector,wp->lssm_warp_time,0,&obj->orient);
wp->lssm_stage=2;
}
//its just entered subspace subspace. don't collide or render
if ((wp->lssm_stage==2) && (fireball_lifeleft_percent(&Objects[wp->lssm_warp_idx]) <= wp->lssm_warp_pct))
{
uint flags=obj->flags & ~(OF_RENDERS | OF_COLLIDES);
obj_set_flags(obj, flags);
//get the position of the target, and estimate its position when it warps out
//so we have an idea of where it will be.
vm_vec_scale_add(&wp->lssm_target_pos,&Objects[wp->target_num].pos,&Objects[wp->target_num].phys_info.vel,(float)wip->lssm_warpin_delay/1000.0f);
wp->lssm_stage=3;
}
//time to warp in.
if ((wp->lssm_stage==3) && (timestamp_elapsed(wp->lssm_warpin_time)))
{
vec3d warpin;
object* target_objp=wp->homing_object;
vec3d fvec;
matrix orient;
//spawn the ssm at a random point in a circle around the target
vm_vec_random_in_circle(&warpin, &wp->lssm_target_pos, &target_objp->orient, wip->lssm_warpin_radius + target_objp->radius,1);
//orient the missile properly
vm_vec_sub(&fvec,&wp->lssm_target_pos, &warpin);
vm_vector_2_matrix(&orient,&fvec,NULL,NULL);
//create a warpin effect
wp->lssm_warp_idx=fireball_create(&warpin, FIREBALL_WARP, FIREBALL_WARP_EFFECT, -1,obj->radius*1.5f,0,&vmd_zero_vector,wp->lssm_warp_time,0,&orient);
obj->orient=orient;
obj->pos=warpin;
obj->phys_info.speed=0;
obj->phys_info.desired_vel = vmd_zero_vector;
obj->phys_info.vel = obj->phys_info.desired_vel;
wp->lssm_stage=4;
}
//done warping in. render and collide it. let the fun begin
if ((wp->lssm_stage==4) && (fireball_lifeleft_percent(&Objects[wp->lssm_warp_idx]) <=0.5f))
{
vm_vec_copy_scale(&obj->phys_info.desired_vel, &obj->orient.vec.fvec, wip->lssm_stage5_vel );
obj->phys_info.vel = obj->phys_info.desired_vel;
obj->phys_info.speed = vm_vec_mag(&obj->phys_info.desired_vel);
wp->lssm_stage=5;
uint flags=obj->flags | OF_RENDERS | OF_COLLIDES;
obj_set_flags(obj,flags);
}
}
if (wip->hud_in_flight_snd >= 0 && obj->parent_sig == Player_obj->signature)
{
bool play_sound = false;
switch (wip->in_flight_play_type)
{
case TARGETED:
play_sound = wp->homing_object != &obj_used_list;
break;
case UNTARGETED:
play_sound = wp->homing_object == &obj_used_list;
break;
case ALWAYS:
play_sound = true;
break;
default:
Error(LOCATION, "Unknown in-flight sound status %d!", (int) wip->in_flight_play_type);
break;
}
if (play_sound)
{
if (wp->hud_in_flight_snd_sig < 0 || !snd_is_playing(wp->hud_in_flight_snd_sig))
{
wp->hud_in_flight_snd_sig = snd_play_looping(&Snds[wip->hud_in_flight_snd]);
}
}
}
}
/**
* Update weapon tracking information.
*/
void weapon_set_tracking_info(int weapon_objnum, int parent_objnum, int target_objnum, int target_is_locked, ship_subsys *target_subsys)
{
object *parent_objp;
weapon *wp;
weapon_info *wip;
int targeting_same = 0;
if ( weapon_objnum < 0 ) {
return;
}
Assert(Objects[weapon_objnum].type == OBJ_WEAPON);
wp = &Weapons[Objects[weapon_objnum].instance];
wip = &Weapon_info[wp->weapon_info_index];
if (parent_objnum >= 0) {
parent_objp = &Objects[parent_objnum];
Assert(parent_objp->type == OBJ_SHIP);
} else {
parent_objp = NULL;
}
if ( parent_objp == NULL || Ships[parent_objp->instance].ai_index >= 0 ) {
int target_team = -1;
if ( target_objnum >= 0 ) {
int obj_type = Objects[target_objnum].type;
if ( (obj_type == OBJ_SHIP) || (obj_type == OBJ_WEAPON) ) {
target_team = obj_team(&Objects[target_objnum]);
}
}
// determining if we're targeting the same team
if (parent_objp != NULL && Ships[parent_objp->instance].team == target_team){
targeting_same = 1;
} else {
targeting_same = 0;
}
if ((target_objnum != -1) && (!targeting_same || (MULTI_DOGFIGHT && (target_team == Iff_traitor))) ) {
wp->target_num = target_objnum;
wp->target_sig = Objects[target_objnum].signature;
wp->nearest_dist = 99999.0f;
if ( (wip->wi_flags & WIF_HOMING_ASPECT) && target_is_locked) {
wp->homing_object = &Objects[target_objnum];
wp->homing_subsys = target_subsys;
weapon_maybe_play_warning(wp);
} else if ( (wip->wi_flags & WIF_HOMING_JAVELIN) && target_is_locked) {
if ((Objects[target_objnum].type == OBJ_SHIP) &&
( (wp->homing_subsys == NULL) ||
(wp->homing_subsys->system_info->type != SUBSYSTEM_ENGINE) )) {
ship *target_ship = &Ships[Objects[target_objnum].instance];
wp->homing_subsys = ship_get_closest_subsys_in_sight(target_ship, SUBSYSTEM_ENGINE, &Objects[weapon_objnum].pos);
if (wp->homing_subsys == NULL) {
wp->homing_object = &obj_used_list;
} else {
Assert(wp->homing_subsys->parent_objnum == target_objnum);
wp->homing_object = &Objects[target_objnum];
weapon_maybe_play_warning(wp);
}
} else {
wp->homing_object = &Objects[target_objnum];
wp->homing_subsys = target_subsys;
weapon_maybe_play_warning(wp);
}
} else if ( wip->wi_flags & WIF_HOMING_HEAT ) {
// Make a heat seeking missile try to home. If the target is outside the view cone, it will
// immediately drop it and try to find one in its view cone.
if ((target_objnum != -1) && !(wip->wi_flags2 & WIF2_UNTARGETED_HEAT_SEEKER)) {
wp->homing_object = &Objects[target_objnum];
wp->homing_subsys = target_subsys;
weapon_maybe_play_warning(wp);
} else {
wp->homing_object = &obj_used_list;
wp->homing_subsys = NULL;
}
}
} else {
wp->target_num = -1;
wp->target_sig = -1;
}
// If missile is locked on target, increase its lifetime by 20% since missiles can be fired at limit of range
// as defined by velocity*lifeleft, but missiles often slow down a bit, plus can be fired at a moving away target.
// Confusing to many players when their missiles run out of gas before getting to target.
// DB - removed 7:14 pm 9/6/99. was totally messing up lifetimes for all weapons.
// MK, 7:11 am, 9/7/99. Put it back in, but with a proper check here to make sure it's an aspect seeker and
// put a sanity check in the color changing laser code that was broken by this code.
if (target_is_locked && (wp->target_num != -1) && (wip->wi_flags & WIF_LOCKED_HOMING) ) {
wp->lifeleft *= LOCKED_HOMING_EXTENDED_LIFE_FACTOR;
if (MULTIPLAYER_MASTER) {
wp->weapon_flags |= WF_HOMING_UPDATE_NEEDED;
}
}
ai_update_danger_weapon(target_objnum, weapon_objnum);
}
}
inline size_t* get_pointer_to_weapon_fire_pattern_index(int weapon_type, ship* shipp, ship_subsys * src_turret) {
Assert( shipp != NULL );
ship_weapon* ship_weapon_p = &(shipp->weapons);
if(src_turret)
{
ship_weapon_p = &src_turret->weapons;
}
Assert( ship_weapon_p != NULL );
// search for the corresponding bank pattern index for the weapon_type that is being fired.
// Note: Because a weapon_type may not be unique to a weapon bank per ship this search may attribute
// the weapon to the wrong bank. Hopefully this isn't a problem.
for ( int pi = 0; pi < MAX_SHIP_PRIMARY_BANKS; pi++ ) {
if ( ship_weapon_p->primary_bank_weapons[pi] == weapon_type ) {
return &(ship_weapon_p->primary_bank_pattern_index[pi]);
}
}
for ( int si = 0; si < MAX_SHIP_SECONDARY_BANKS; si++ ) {
if ( ship_weapon_p->secondary_bank_weapons[si] == weapon_type ) {
return &(ship_weapon_p->secondary_bank_pattern_index[si]);
}
}
return NULL;
}
/**
* Create a weapon object
*
* @return Index of weapon in the Objects[] array, -1 if the weapon object was not created
*/
int Weapons_created = 0;
int weapon_create( vec3d * pos, matrix * porient, int weapon_type, int parent_objnum, int group_id, int is_locked, int is_spawned, float fof_cooldown, ship_subsys * src_turret)
{
int n, objnum;
int num_deleted;
object *objp, *parent_objp=NULL;
weapon *wp;
weapon_info *wip;
Assert(weapon_type >= 0 && weapon_type < Num_weapon_types);
wip = &Weapon_info[weapon_type];
// beam weapons should never come through here!
if(wip->wi_flags & WIF_BEAM)
{
Warning(LOCATION, "An attempt to fire a beam ('%s') through weapon_create() was made.\n", wip->name);
return -1;
}
parent_objp = NULL;
if(parent_objnum >= 0){
parent_objp = &Objects[parent_objnum];
}
if ( (wip->weapon_substitution_pattern.size() > 0) && (parent_objp != NULL)) {
// using substitution
// get to the instance of the gun
Assertion( parent_objp->type == OBJ_SHIP, "Expected type OBJ_SHIP, got %d", parent_objp->type );
Assertion( (parent_objp->instance < MAX_SHIPS) && (parent_objp->instance >= 0),
"Ship index is %d, which is out of range [%d,%d)", parent_objp->instance, 0, MAX_SHIPS);
ship* parent_shipp = &(Ships[parent_objp->instance]);
Assert( parent_shipp != NULL );
size_t *position = get_pointer_to_weapon_fire_pattern_index(weapon_type, parent_shipp, src_turret);
Assertion( position != NULL, "'%s' is trying to fire a weapon that is not selected", Ships[parent_objp->instance].ship_name );
*position = ++(*position) % wip->weapon_substitution_pattern.size();
if ( wip->weapon_substitution_pattern[*position] == -1 ) {
// weapon doesn't want any sub
return -1;
} else if ( wip->weapon_substitution_pattern[*position] != weapon_type ) {
// weapon wants to sub with weapon other than me
return weapon_create(pos, porient, wip->weapon_substitution_pattern[*position], parent_objnum, group_id, is_locked, is_spawned, fof_cooldown);
}
}
num_deleted = 0;
if (Num_weapons >= MAX_WEAPONS-5) {
//No, do remove for AI ships -- MK, 3/12/98 // don't need to try and delete weapons for ai ships
//if ( !(Objects[parent_objnum].flags & OF_PLAYER_SHIP) )
// return -1;
num_deleted = collide_remove_weapons();
nprintf(("WARNING", "Deleted %d weapons because of lack of slots\n", num_deleted));
if (num_deleted == 0){
return -1;
}
}
for (n=0; n<MAX_WEAPONS; n++ ){
if (Weapons[n].weapon_info_index < 0){
break;
}
}
if (n == MAX_WEAPONS) {
// if we supposedly deleted weapons above, what happened here!!!!
if (num_deleted){
Int3(); // get allender -- something funny is going on!!!
}
return -1;
}
// make sure we are loaded and useable
if ( (wip->render_type == WRT_POF) && (wip->model_num < 0) ) {
wip->model_num = model_load(wip->pofbitmap_name, 0, NULL);
if (wip->model_num < 0) {
Int3();
return -1;
}
}
// make sure that our textures are loaded as well
if ( !used_weapons[weapon_type] )
weapon_load_bitmaps(weapon_type);
//I am hopeing that this way does not alter the input orient matrix
//Feild of Fire code -Bobboau
matrix morient;
matrix *orient;
if(porient != NULL) {
morient = *porient;
} else {
morient = vmd_identity_matrix;
}
orient = &morient;
float combined_fof = wip->field_of_fire;
// If there is a fof_cooldown value, increase the spread linearly
if (fof_cooldown != 0.0f) {
combined_fof = wip->field_of_fire + (fof_cooldown * wip->max_fof_spread);
}
if(combined_fof > 0.0f){
vec3d f;
vm_vec_random_cone(&f, &orient->vec.fvec, combined_fof);
vm_vec_normalize(&f);
vm_vector_2_matrix( orient, &f, NULL, NULL);
}
Weapons_created++;
objnum = obj_create( OBJ_WEAPON, parent_objnum, n, orient, pos, 2.0f, OF_RENDERS | OF_COLLIDES | OF_PHYSICS );
Assert(objnum >= 0);
objp = &Objects[objnum];
// Create laser n!
wp = &Weapons[n];
// check if laser or dumbfire missile
// set physics flag to allow optimization
if ((wip->subtype == WP_LASER) || ((wip->subtype == WP_MISSILE) && !(wip->wi_flags & WIF_HOMING))) {
// set physics flag
objp->phys_info.flags |= PF_CONST_VEL;
}
wp->start_pos = *pos;
wp->objnum = objnum;
wp->homing_object = &obj_used_list; // Assume not homing on anything.
wp->homing_subsys = NULL;
wp->creation_time = Missiontime;
wp->group_id = group_id;
// we don't necessarily need a parent
if(parent_objp != NULL){
Assert(parent_objp->type == OBJ_SHIP); // Get Mike, a non-ship has fired a weapon!
Assert((parent_objp->instance >= 0) && (parent_objp->instance < MAX_SHIPS));
wp->team = Ships[parent_objp->instance].team;
wp->species = Ship_info[Ships[parent_objp->instance].ship_info_index].species;
} else {
// ugh - we need to prevent bad array accesses
wp->team = Iff_traitor;
wp->species = 0;
}
wp->turret_subsys = NULL;
vm_vec_zero(&wp->homing_pos);
wp->weapon_flags = 0;
wp->target_sig = -1;
wp->cmeasure_ignore_objnum = -1;
wp->cmeasure_chase_objnum = -1;
wp->det_range = wip->det_range;
// Init the thruster info
wp->thruster_bitmap = -1;
wp->thruster_frame = 0.0f;
wp->thruster_glow_bitmap = -1;
wp->thruster_glow_noise = 1.0f;
wp->thruster_glow_frame = 0.0f;
// init the laser info
wp->laser_bitmap_frame = 0.0f;
wp->laser_glow_bitmap_frame = 0.0f;
if ( wip->wi_flags & WIF_SWARM ) {
wp->swarm_index = (short)swarm_create();
} else {
wp->swarm_index = -1;
}
// if this is a particle spewing weapon, setup some stuff
if (wip->wi_flags & WIF_PARTICLE_SPEW) {
for (size_t s = 0; s < MAX_PARTICLE_SPEWERS; s++) { // allow for multiple time values
if (wip->particle_spewers[s].particle_spew_type != PSPEW_NONE) {
wp->particle_spew_time[s] = -1;
wp->particle_spew_rand = frand_range(0, PI2); // per weapon randomness
}
}
}
// assign the network signature. The starting sig is sent to all clients, so this call should
// result in the same net signature numbers getting assigned to every player in the game
if ( Game_mode & GM_MULTIPLAYER ) {
if(wip->subtype == WP_MISSILE){
Objects[objnum].net_signature = multi_assign_network_signature( MULTI_SIG_NON_PERMANENT );
// for weapons that respawn, add the number of respawnable weapons to the net signature pool
// to reserve N signatures for the spawned weapons
if ( wip->wi_flags & WIF_SPAWN ){
multi_set_network_signature( (ushort)(Objects[objnum].net_signature + wip->total_children_spawned), MULTI_SIG_NON_PERMANENT );
}
} else {
Objects[objnum].net_signature = multi_assign_network_signature( MULTI_SIG_NON_PERMANENT );
}
// for multiplayer clients, when creating lasers, add some more life to the lasers. This helps
// to overcome some problems associated with lasers dying on client machine before they get message
// from server saying it hit something.
}
//Check if we want to gen a random number
//This is used for lifetime min/max
float rand_val;
if ( Game_mode & GM_NORMAL ){
rand_val = frand();
} else {
rand_val = static_randf(Objects[objnum].net_signature);
}
wp->weapon_info_index = weapon_type;
if(wip->life_min < 0.0f && wip->life_max < 0.0f) {
wp->lifeleft = wip->lifetime;
} else {
wp->lifeleft = (rand_val) * (wip->life_max - wip->life_min) / wip->life_min;
if((wip->wi_flags & WIF_CMEASURE) && (parent_objp->flags & OF_PLAYER_SHIP)) {
wp->lifeleft *= The_mission.ai_profile->cmeasure_life_scale[Game_skill_level];
}
wp->lifeleft = wip->life_min + wp->lifeleft * (wip->life_max - wip->life_min);
}
if(wip->wi_flags & WIF_CMEASURE) {
//2-frame homing check, to fend off sync errors
Cmeasures_homing_check = 2;
}
// Make remote detonate missiles look like they're getting detonated by firer simply by giving them variable lifetimes.
if (parent_objp != NULL && !(parent_objp->flags & OF_PLAYER_SHIP) && (wip->wi_flags & WIF_REMOTE)) {
wp->lifeleft = wp->lifeleft/2.0f + rand_val * wp->lifeleft/2.0f;
}
objp->phys_info.mass = wip->mass;
objp->phys_info.side_slip_time_const = 0.0f;
objp->phys_info.rotdamp = 0.0f;
vm_vec_zero(&objp->phys_info.max_vel);
objp->phys_info.max_vel.xyz.z = wip->max_speed;
vm_vec_zero(&objp->phys_info.max_rotvel);
objp->shield_quadrant[0] = wip->damage;
if (wip->weapon_hitpoints > 0){
objp->hull_strength = (float) wip->weapon_hitpoints;
} else {
objp->hull_strength = 0.0f;
}
if ( wip->render_type == WRT_POF ) {
objp->radius = model_get_radius(wip->model_num);
} else if ( wip->render_type == WRT_LASER ) {
objp->radius = wip->laser_head_radius;
}
// Set desired velocity and initial velocity.
// For lasers, velocity is always the same.
// For missiles, it is a small amount plus the firing ship's velocity.
// For missiles, the velocity trends towards some goal.
// Note: If you change how speed works here, such as adding in speed of parent ship, you'll need to change the AI code
// that predicts collision points. See Mike Kulas or Dave Andsager. (Or see ai_get_weapon_speed().)
if (!(wip->wi_flags & WIF_HOMING)) {
vm_vec_copy_scale(&objp->phys_info.desired_vel, &objp->orient.vec.fvec, objp->phys_info.max_vel.xyz.z );
objp->phys_info.vel = objp->phys_info.desired_vel;
objp->phys_info.speed = vm_vec_mag(&objp->phys_info.desired_vel);
} else {
// For weapons that home, set velocity to sum of forward component of parent's velocity and 1/4 weapon's max speed.
// Note that it is important to extract the forward component of the parent's velocity to factor out sliding, else
// the missile will not be moving forward.
if(parent_objp != NULL){
if (wip->free_flight_time > 0.0)
vm_vec_copy_scale(&objp->phys_info.desired_vel, &objp->orient.vec.fvec, vm_vec_dot(&parent_objp->phys_info.vel, &parent_objp->orient.vec.fvec) + objp->phys_info.max_vel.xyz.z/4 );
else
vm_vec_copy_scale(&objp->phys_info.desired_vel, &objp->orient.vec.fvec, objp->phys_info.max_vel.xyz.z );
} else {
if (!is_locked && wip->free_flight_time > 0.0)
{
vm_vec_copy_scale(&objp->phys_info.desired_vel, &objp->orient.vec.fvec, objp->phys_info.max_vel.xyz.z/4 );
}
else
{
vm_vec_copy_scale(&objp->phys_info.desired_vel, &objp->orient.vec.fvec, objp->phys_info.max_vel.xyz.z );
}
}
objp->phys_info.vel = objp->phys_info.desired_vel;
objp->phys_info.speed = vm_vec_mag(&objp->phys_info.vel);
}
wp->weapon_max_vel = objp->phys_info.max_vel.xyz.z;
// Turey - maybe make the initial speed of the weapon take into account the velocity of the parent.
// Improves aiming during gliding.
if ((parent_objp != NULL) && (The_mission.ai_profile->flags & AIPF_USE_ADDITIVE_WEAPON_VELOCITY)) {
vm_vec_add2( &objp->phys_info.vel, &parent_objp->phys_info.vel );
wp->weapon_max_vel += vm_vec_mag( &parent_objp->phys_info.vel );
objp->phys_info.speed = vm_vec_mag(&objp->phys_info.vel);
}
// create the corkscrew
if ( wip->wi_flags & WIF_CORKSCREW ) {
wp->cscrew_index = (short)cscrew_create(objp);
} else {
wp->cscrew_index = -1;
}
if (wip->wi_flags2 & WIF2_LOCAL_SSM)
{
Assert(parent_objp); //local ssms must have a parent
wp->lssm_warpout_time=timestamp(wip->lssm_warpout_delay);
wp->lssm_warpin_time=timestamp(wip->lssm_warpout_delay + wip->lssm_warpin_delay);
wp->lssm_stage=1;
}
else{
wp->lssm_stage=-1;
}
// if this is a flak weapon shell, make it so
// NOTE : this function will change some fundamental things about the weapon object
if ( (wip->wi_flags & WIF_FLAK) && !(wip->wi_flags2 & WIF2_RENDER_FLAK) ) {
obj_set_flags(&Objects[wp->objnum], Objects[wp->objnum].flags & ~(OF_RENDERS));
}
wp->missile_list_index = -1;
// If this is a missile, then add it to the Missile_obj_list
if ( wip->subtype == WP_MISSILE ) {
wp->missile_list_index = missile_obj_list_add(objnum);
}
if (wip->wi_flags & WIF_TRAIL /*&& !(wip->wi_flags & WIF_CORKSCREW) */) {
wp->trail_ptr = trail_create(&wip->tr_info);
if ( wp->trail_ptr != NULL ) {
// Add two segments. One to stay at launch pos, one to move.
trail_add_segment( wp->trail_ptr, &objp->pos );
trail_add_segment( wp->trail_ptr, &objp->pos );
}
}
else
{
//If a weapon has no trails, make sure we don't try to do anything with them.
wp->trail_ptr = NULL;
}
// Ensure weapon flyby sound doesn't get played for player lasers
if ( parent_objp == Player_obj ) {
wp->weapon_flags |= WF_PLAYED_FLYBY_SOUND;
}
wp->pick_big_attack_point_timestamp = timestamp(1);
// Set detail levels for POF-type weapons.
if (Weapon_info[wp->weapon_info_index].model_num != -1) {
polymodel * pm;
int i;
pm = model_get(Weapon_info[wp->weapon_info_index].model_num);
for (i=0; i<pm->n_detail_levels; i++){
// for weapons, detail levels are all preset to -1
if (wip->detail_distance[i] >= 0)
pm->detail_depth[i] = i2fl(wip->detail_distance[i]);
else
pm->detail_depth[i] = (objp->radius*20.0f + 20.0f) * i;
}
#ifndef NDEBUG
// since debug builds always have cheats enabled, we don't necessarily get the chance
// to enable thrusters for previously non-loaded weapons (ie, weapons_page_in_cheats())
// when using cheat-keys, so we need to make sure and enable thrusters here if needed
if (pm->n_thrusters > 0) {
wip->wi_flags |= WIF_THRUSTER;
}
#endif
}
// if the weapon was fired locked
if(is_locked){
wp->weapon_flags |= WF_LOCKED_WHEN_FIRED;
}
//if the weapon was spawned from a spawning type weapon
if(is_spawned){
wp->weapon_flags |= WF_SPAWNED;
}
wp->alpha_current = -1.0f;
wp->alpha_backward = 0;
wp->collisionOccured = false;
wp->hud_in_flight_snd_sig = -1;
Num_weapons++;
// reset the damage record fields (for scoring purposes)
wp->total_damage_received = 0.0f;
for(int i=0;i<MAX_WEP_DAMAGE_SLOTS;i++)
{
wp->damage_ship[i] = 0.0f;
wp->damage_ship_id[i] = -1;
}
if (Weapons_inherit_parent_collision_group) {
Objects[objnum].collision_group_id = Objects[parent_objnum].collision_group_id;
}
return objnum;
}
/**
* Spawn child weapons from object *objp.
*/
void spawn_child_weapons(object *objp)
{
int i, j;
int child_id;
int parent_num;
ushort starting_sig;
weapon *wp;
weapon_info *wip, *child_wip;
Assert(objp->type == OBJ_WEAPON);
Assert((objp->instance >= 0) && (objp->instance < MAX_WEAPONS));
wp = &Weapons[objp->instance];
Assert((wp->weapon_info_index >= 0) && (wp->weapon_info_index < MAX_WEAPON_TYPES));
wip = &Weapon_info[wp->weapon_info_index];
parent_num = objp->parent;
if (parent_num >= 0) {
if ((Objects[parent_num].type != objp->parent_type) || (Objects[parent_num].signature != objp->parent_sig)) {
mprintf(("Warning: Parent of spawn weapon does not exist. Not spawning.\n"));
return;
}
}
starting_sig = 0;
if ( Game_mode & GM_MULTIPLAYER ) {
// get the next network signature and save it. Set the next usable network signature to be
// the passed in objects signature + 1. We "reserved" N of these slots when we created objp
// for it's spawned children.
starting_sig = multi_get_next_network_signature( MULTI_SIG_NON_PERMANENT );
multi_set_network_signature( objp->net_signature, MULTI_SIG_NON_PERMANENT );
}
for (i = 0; i < wip->num_spawn_weapons_defined; i++)
{
for (j = 0; j < wip->spawn_info[i].spawn_count; j++)
{
int weapon_objnum;
vec3d tvec, pos;
matrix orient;
child_id = wip->spawn_info[i].spawn_type;
child_wip = &Weapon_info[child_id];
// for multiplayer, use the static randvec functions based on the network signatures to provide
// the randomness so that it is the same on all machines.
if ( Game_mode & GM_MULTIPLAYER ) {
static_rand_cone(objp->net_signature + j, &tvec, &objp->orient.vec.fvec, wip->spawn_info[i].spawn_angle);
} else {
vm_vec_random_cone(&tvec, &objp->orient.vec.fvec, wip->spawn_info[i].spawn_angle);
}
vm_vec_scale_add(&pos, &objp->pos, &tvec, objp->radius);
vm_vector_2_matrix(&orient, &tvec, NULL, NULL);
weapon_objnum = weapon_create(&pos, &orient, child_id, parent_num, -1, wp->weapon_flags & WF_LOCKED_WHEN_FIRED, 1);
//if the child inherits parent target, do it only if the parent weapon was locked to begin with
if ((child_wip->wi_flags2 & WIF2_INHERIT_PARENT_TARGET) && (wp->homing_object != &obj_used_list))
{
//Deal with swarm weapons
if (wp->swarm_index >= 0) {
swarm_info *swarmp;
swarmp = &Swarm_missiles[wp->swarm_index];
weapon_set_tracking_info(weapon_objnum, parent_num, swarmp->homing_objnum, 1, wp->homing_subsys);
} else {
weapon_set_tracking_info(weapon_objnum, parent_num, wp->target_num, 1, wp->homing_subsys);
}
}
// Assign a little randomness to lifeleft so they don't all disappear at the same time.
if (weapon_objnum != -1) {
float rand_val;
if ( Game_mode & GM_NORMAL ){
rand_val = frand();
} else {
rand_val = static_randf(objp->net_signature + j);
}
Weapons[Objects[weapon_objnum].instance].lifeleft *= rand_val*0.4f + 0.8f;
}
}
}
// in multiplayer, reset the next network signature to the one that was saved.
if ( Game_mode & GM_MULTIPLAYER ){
multi_set_network_signature( starting_sig, MULTI_SIG_NON_PERMANENT );
}
}
/**
* Figures out whether to play disarmed or armed hit sound, checks that the
* chosen one exists, and plays it
*/
void weapon_play_impact_sound(weapon_info *wip, vec3d *hitpos, bool is_armed)
{
if(is_armed)
{
if(wip->impact_snd != -1) {
snd_play_3d( &Snds[wip->impact_snd], hitpos, &Eye_position );
}
}
else
{
if(wip->disarmed_impact_snd != -1) {
snd_play_3d(&Snds[wip->disarmed_impact_snd], hitpos, &Eye_position);
}
}
}
/**
* Play a sound effect when a weapon hits a ship
*
* To elimate the "stereo" effect of two lasers hitting at nearly
* the same time, and to reduce the number of sound channels used,
* only play one impact sound if IMPACT_SOUND_DELTA has elapsed
*
* @note Uses Weapon_impact_timer global for timer variable
*/
void weapon_hit_do_sound(object *hit_obj, weapon_info *wip, vec3d *hitpos, bool is_armed)
{
int is_hull_hit;
float shield_str;
// If non-missiles (namely lasers) expire without hitting a ship, don't play impact sound
if ( wip->subtype != WP_MISSILE ) {
if ( !hit_obj ) {
// flak weapons make sounds
if(wip->wi_flags & WIF_FLAK)
{
weapon_play_impact_sound(wip, hitpos, is_armed);
}
return;
}
switch(hit_obj->type) {
case OBJ_SHIP:
// do nothing
break;
case OBJ_ASTEROID:
if ( timestamp_elapsed(Weapon_impact_timer) ) {
weapon_play_impact_sound(wip, hitpos, is_armed);
Weapon_impact_timer = timestamp(IMPACT_SOUND_DELTA);
}
return;
break;
default:
return;
}
}
if ( hit_obj == NULL ) {
weapon_play_impact_sound(wip, hitpos, is_armed);
return;
}
if ( timestamp_elapsed(Weapon_impact_timer) ) {
is_hull_hit = 1;
if ( hit_obj->type == OBJ_SHIP ) {
shield_str = ship_quadrant_shield_strength(hit_obj, hitpos);
} else {
shield_str = 0.0f;
}
// play a shield hit if shields are above 10% max in this quadrant
if ( shield_str > 0.1f ) {
is_hull_hit = 0;
}
if ( !is_hull_hit ) {
// Play a shield impact sound effect
if ( hit_obj == Player_obj ) {
snd_play_3d( &Snds[SND_SHIELD_HIT_YOU], hitpos, &Eye_position );
// AL 12-15-97: Add missile impact sound even when shield is hit
if ( wip->subtype == WP_MISSILE ) {
snd_play_3d( &Snds[SND_PLAYER_HIT_MISSILE], hitpos, &Eye_position);
}
} else {
snd_play_3d( &Snds[SND_SHIELD_HIT], hitpos, &Eye_position );
}
} else {
// Play a hull impact sound effect
switch ( wip->subtype ) {
case WP_LASER:
if ( hit_obj == Player_obj )
snd_play_3d( &Snds[SND_PLAYER_HIT_LASER], hitpos, &Eye_position );
else {
weapon_play_impact_sound(wip, hitpos, is_armed);
}
break;
case WP_MISSILE:
if ( hit_obj == Player_obj )
snd_play_3d( &Snds[SND_PLAYER_HIT_MISSILE], hitpos, &Eye_position);
else {
weapon_play_impact_sound(wip, hitpos, is_armed);
}
break;
default:
nprintf(("Warning","WARNING ==> Cannot determine sound to play for weapon impact\n"));
break;
} // end switch
}
Weapon_impact_timer = timestamp(IMPACT_SOUND_DELTA);
}
}
extern bool turret_weapon_has_flags(ship_weapon *swp, int flags);
/**
* Distrupt any subsystems that fall into damage sphere of this Electronics missile
*
* @param ship_objp Pointer to ship that holds subsystem
* @param blast_pos World pos of weapon blast
* @param wi_index Weapon info index of weapon causing blast
*/
void weapon_do_electronics_effect(object *ship_objp, vec3d *blast_pos, int wi_index)
{
weapon_info *wip;
ship *shipp;
ship_subsys *ss;
model_subsystem *psub;
vec3d subsys_world_pos;
float dist;
shipp = &Ships[ship_objp->instance];
wip = &Weapon_info[wi_index];
for ( ss = GET_FIRST(&shipp->subsys_list); ss != END_OF_LIST(&shipp->subsys_list); ss = GET_NEXT(ss) )
{
psub = ss->system_info;
// convert subsys point to world coords
vm_vec_unrotate(&subsys_world_pos, &psub->pnt, &ship_objp->orient);
vm_vec_add2(&subsys_world_pos, &ship_objp->pos);
// see if subsys point is within damage sphere
dist = vm_vec_dist_quick(blast_pos, &subsys_world_pos);
if ( dist < wip->shockwave.outer_rad )
{
float disrupt_time = (float)wip->elec_time;
//use new style electronics disruption
if (wip->elec_use_new_style)
{
//if its an engine subsytem, take the multiplier into account
if (psub->type==SUBSYSTEM_ENGINE)
{
disrupt_time*=wip->elec_eng_mult;
}
//if its a turret or weapon subsytem, take the multiplier into account
if ((psub->type==SUBSYSTEM_TURRET) || (psub->type==SUBSYSTEM_WEAPONS))
{
//disrupt beams
//WMC - do this even if there are other types of weapons on the turret.
//I figure, the big fancy electronics on beams will be used for the other
//weapons as well. No reason having two targeting computers on a turret.
//Plus, it's easy and fast to code. :)
if ((psub->type==SUBSYSTEM_TURRET) && turret_weapon_has_flags(&ss->weapons, WIF_BEAM))
{
disrupt_time*=wip->elec_beam_mult;
}
//disrupt other weapons
else
{
disrupt_time*=wip->elec_weap_mult;
}
}
//disrupt sensor and awacs systems.
if ((psub->type==SUBSYSTEM_SENSORS) || (psub->flags & MSS_FLAG_AWACS))
{
disrupt_time*=wip->elec_sensors_mult;
}
}
//add a little randomness to the disruption time
disrupt_time += frand_range(-1.0f, 1.0f) * wip->elec_randomness;
//disrupt this subsystem for the calculated time
//if it turns out to be less than 0 seconds, don't bother
if (disrupt_time > 0)
{
ship_subsys_set_disrupted(ss, fl2i(disrupt_time));
}
}
}
}
/**
* Calculate the damage for an object based on the location of an area-effect
* explosion.
*
* @param objp Object pointer ship receiving blast effect
* @param pos World pos of blast center
* @param inner_rad Smallest radius at which full damage is done
* @param outer_rad Radius at which no damage is done
* @param max_blast Maximum blast possible from explosion
* @param max_damage Maximum damage possible from explosion
* @param blast OUTPUT PARAMETER: receives blast value from explosion
* @param damage OUTPUT PARAMETER: receives damage value from explosion
* @param limit A limit on the area, needed for shockwave damage
*
* @return No damage occurred, -1
* @return Damage occured, 0
*/
int weapon_area_calc_damage(object *objp, vec3d *pos, float inner_rad, float outer_rad, float max_blast, float max_damage, float *blast, float *damage, float limit)
{
float dist;
vec3d box_pt;
// if object receiving the blast is a ship, use the bbox for distances
// otherwise use the objects radius
// could possibly exclude SIF_SMALL_SHIP (& other small objects) from using the bbox
if (objp->type == OBJ_SHIP) {
int inside = get_nearest_bbox_point(objp, pos, &box_pt);
if (inside) {
dist = 0.0001f;
} else {
dist = vm_vec_dist_quick(pos, &box_pt);
}
} else {
dist = vm_vec_dist_quick(&objp->pos, pos) - objp->radius;
}
if ( (dist > outer_rad) || (dist > limit) ) {
return -1; // spheres don't intersect at all
}
if ( dist < inner_rad ) {
// damage is maximum within inner radius
*damage = max_damage;
*blast = max_blast;
} else {
float dist_to_outer_rad_squared = (outer_rad-dist)*(outer_rad-dist);
float total_dist_squared = (inner_rad-outer_rad)*(inner_rad-outer_rad);
// this means the inner and outer radii are basically equal... and since we aren't within the inner radius,
// we fudge the law of excluded middle to place ourselves outside the outer radius
if (total_dist_squared < 0.0001f) {
return -1; // avoid divide-by-zero; we won't take damage anyway
}
// AL 2-24-98: drop off damage relative to square of distance
Assert(dist_to_outer_rad_squared <= total_dist_squared);
*damage = max_damage * dist_to_outer_rad_squared/total_dist_squared;
*blast = (dist - outer_rad) * max_blast /(inner_rad - outer_rad);
}
return 0;
}
/**
* Apply the blast effects of an explosion to a ship
*
* @param force_apply_pos World pos of where force is applied to object
* @param ship_objp Object pointer of ship receiving the blast
* @param blast_pos World pos of blast center
* @param blast Force of blast
* @param make_shockwave Boolean, whether to create a shockwave or not
*/
void weapon_area_apply_blast(vec3d *force_apply_pos, object *ship_objp, vec3d *blast_pos, float blast, int make_shockwave)
{
#define SHAKE_CONST 3000
vec3d force, vec_blast_to_ship, vec_ship_to_impact;
polymodel *pm;
// don't waste time here if there is no blast force
if ( blast == 0.0f )
return;
// apply blast force based on distance from center of explosion
vm_vec_sub(&vec_blast_to_ship, &ship_objp->pos, blast_pos);
vm_vec_normalize_safe(&vec_blast_to_ship);
vm_vec_copy_scale(&force, &vec_blast_to_ship, blast );
vm_vec_sub(&vec_ship_to_impact, blast_pos, &ship_objp->pos);
pm = model_get(Ship_info[Ships[ship_objp->instance].ship_info_index].model_num);
Assert ( pm != NULL );
if (make_shockwave) {
physics_apply_shock (&force, blast, &ship_objp->phys_info, &ship_objp->orient, &pm->mins, &pm->maxs, pm->rad);
if (ship_objp == Player_obj) {
joy_ff_play_vector_effect(&vec_blast_to_ship, blast * 2.0f);
}
} else {
ship_apply_whack( &force, &vec_ship_to_impact, ship_objp);
}
}
/**
* Do the area effect for a weapon
*
* @param wobjp Object pointer to weapon causing explosion
* @param sci Shockwave info
* @param pos World pos of explosion center
* @param other_obj Object pointer to ship that weapon impacted on (can be NULL)
*/
void weapon_do_area_effect(object *wobjp, shockwave_create_info *sci, vec3d *pos, object *other_obj)
{
weapon_info *wip;
object *objp;
float damage, blast;
wip = &Weapon_info[Weapons[wobjp->instance].weapon_info_index];
// only blast ships and asteroids
// And (some) weapons
for ( objp = GET_FIRST(&obj_used_list); objp !=END_OF_LIST(&obj_used_list); objp = GET_NEXT(objp) ) {
if ( (objp->type != OBJ_SHIP) && (objp->type != OBJ_ASTEROID) && (objp->type != OBJ_WEAPON) ) {
continue;
}
if ( objp->type == OBJ_WEAPON ) {
// only apply to missiles with hitpoints
weapon_info* wip2 = &Weapon_info[Weapons[objp->instance].weapon_info_index];
if (wip2->weapon_hitpoints <= 0 || !(wip2->wi_flags2 & WIF2_TAKES_BLAST_DAMAGE) || (wip->wi_flags2 & WIF2_CIWS))
continue;
}
if ( objp->type == OBJ_SHIP ) {
// don't blast navbuoys
if ( ship_get_SIF(objp->instance) & SIF_NAVBUOY ) {
continue;
}
}
if ( weapon_area_calc_damage(objp, pos, sci->inner_rad, sci->outer_rad, sci->blast, sci->damage, &blast, &damage, sci->outer_rad) == -1 ){
continue;
}
// scale damage
damage *= weapon_get_damage_scale(wip, wobjp, other_obj);
weapon_info* target_wip;
switch ( objp->type ) {
case OBJ_SHIP:
ship_apply_global_damage(objp, wobjp, pos, damage);
weapon_area_apply_blast(NULL, objp, pos, blast, 0);
break;
case OBJ_ASTEROID:
asteroid_hit(objp, NULL, NULL, damage);
break;
case OBJ_WEAPON:
target_wip = &Weapon_info[Weapons[objp->instance].weapon_info_index];
if (target_wip->armor_type_idx >= 0)
damage = Armor_types[target_wip->armor_type_idx].GetDamage(damage, wip->damage_type_idx, 1.0f);
objp->hull_strength -= damage;
if (objp->hull_strength < 0.0f) {
Weapons[objp->instance].lifeleft = 0.01f;
Weapons[objp->instance].weapon_flags |= WF_DESTROYED_BY_WEAPON;
}
break;
default:
Int3();
break;
}
} // end for
// if this weapon has the "Electronics" flag set, then disrupt subsystems in sphere
if ( (other_obj != NULL) && (wip->wi_flags & WIF_ELECTRONICS) ) {
if ( other_obj->type == OBJ_SHIP ) {
weapon_do_electronics_effect(other_obj, pos, Weapons[wobjp->instance].weapon_info_index);
}
}
}
// ----------------------------------------------------------------------
// weapon_armed(weapon)
//
// Call to figure out if a weapon is armed or not
//
//Weapon is armed when...
//1: Weapon is shot down by weapon
//OR
//1: weapon is destroyed before arm time
//2: weapon is destroyed before arm distance from ship
//3: weapon is outside arm radius from target ship
bool weapon_armed(weapon *wp, bool hit_target)
{
Assert(wp != NULL);
weapon_info *wip = &Weapon_info[wp->weapon_info_index];
if((wp->weapon_flags & WF_DESTROYED_BY_WEAPON)
&& !wip->arm_time
&& wip->arm_dist == 0.0f
&& wip->arm_radius == 0.0f)
{
return false;
}
else
{
object *wobj = &Objects[wp->objnum];
object *pobj;
if(wobj->parent > -1) {
pobj = &Objects[wobj->parent];
} else {
pobj = NULL;
}
if( ((wip->arm_time) && ((Missiontime - wp->creation_time) < wip->arm_time))
|| ((wip->arm_dist) && (pobj != NULL && pobj->type != OBJ_NONE && (vm_vec_dist(&wobj->pos, &pobj->pos) < wip->arm_dist))))
{
return false;
}
if(wip->arm_radius && (!hit_target)) {
if(wp->homing_object == NULL)
return false;
if(vm_vec_dist(&wobj->pos, &wp->homing_pos) > wip->arm_radius)
return false;
}
}
return true;
}
/**
* Called when a weapon hits something (or, in the case of
* missiles explodes for any particular reason)
*/
void weapon_hit( object * weapon_obj, object * other_obj, vec3d * hitpos, int quadrant )
{
Assert(weapon_obj != NULL);
if(weapon_obj == NULL){
return;
}
Assert((weapon_obj->type == OBJ_WEAPON) && (weapon_obj->instance >= 0) && (weapon_obj->instance < MAX_WEAPONS));
if((weapon_obj->type != OBJ_WEAPON) || (weapon_obj->instance < 0) || (weapon_obj->instance >= MAX_WEAPONS)){
return;
}
int num = weapon_obj->instance;
int weapon_type = Weapons[num].weapon_info_index;
int expl_ani_handle;
weapon_info *wip;
weapon *wp;
bool hit_target = false;
object *other_objp;
ship_obj *so;
ship *shipp;
int objnum;
Assert((weapon_type >= 0) && (weapon_type < MAX_WEAPONS));
if((weapon_type < 0) || (weapon_type >= MAX_WEAPONS)){
return;
}
wp = &Weapons[weapon_obj->instance];
wip = &Weapon_info[weapon_type];
objnum = wp->objnum;
// check if the weapon actually hit the intended target
if (wp->homing_object != NULL)
if (wp->homing_object == other_obj)
hit_target = true;
//This is an expensive check
bool armed_weapon = weapon_armed(&Weapons[num], hit_target);
// if this is the player ship, and is a laser hit, skip it. wait for player "pain" to take care of it
if ((other_obj != Player_obj) || (wip->subtype != WP_LASER) || !MULTIPLAYER_CLIENT) {
weapon_hit_do_sound(other_obj, wip, hitpos, armed_weapon);
}
if ( wip->impact_weapon_expl_index > -1 && armed_weapon)
{
expl_ani_handle = Weapon_explosions.GetAnim(wip->impact_weapon_expl_index, hitpos, wip->impact_explosion_radius);
particle_create( hitpos, &vmd_zero_vector, 0.0f, wip->impact_explosion_radius, PARTICLE_BITMAP_PERSISTENT, expl_ani_handle );
}
else if(wip->dinky_impact_weapon_expl_index > -1 && !armed_weapon)
{
expl_ani_handle = Weapon_explosions.GetAnim(wip->dinky_impact_weapon_expl_index, hitpos, wip->dinky_impact_explosion_radius);
particle_create( hitpos, &vmd_zero_vector, 0.0f, wip->dinky_impact_explosion_radius, PARTICLE_BITMAP_PERSISTENT, expl_ani_handle );
}
if((other_obj != NULL) && (quadrant == -1) && (wip->piercing_impact_weapon_expl_index > -1 && armed_weapon)) {
if ((other_obj->type == OBJ_SHIP) || (other_obj->type == OBJ_DEBRIS)) {
int ok_to_draw = 1;
if (other_obj->type == OBJ_SHIP) {
float draw_limit, hull_pct;
int dmg_type_idx, piercing_type;
ship *shipp = &Ships[other_obj->instance];
hull_pct = other_obj->hull_strength / shipp->ship_max_hull_strength;
dmg_type_idx = wip->damage_type_idx;
draw_limit = Ship_info[shipp->ship_info_index].piercing_damage_draw_limit;
if (shipp->armor_type_idx != -1) {
piercing_type = Armor_types[shipp->armor_type_idx].GetPiercingType(dmg_type_idx);
if (piercing_type == SADTF_PIERCING_DEFAULT) {
draw_limit = Armor_types[shipp->armor_type_idx].GetPiercingLimit(dmg_type_idx);
} else if ((piercing_type == SADTF_PIERCING_NONE) || (piercing_type == SADTF_PIERCING_RETAIL)) {
ok_to_draw = 0;
}
}
if (hull_pct > draw_limit)
ok_to_draw = 0;
}
if (ok_to_draw) {
particle_emitter pe;
vec3d null_v;
vm_vec_zero(&null_v);
expl_ani_handle = Weapon_explosions.GetAnim(wip->piercing_impact_weapon_expl_index, hitpos, wip->piercing_impact_explosion_radius);
pe.max_vel = 2.0f * wip->piercing_impact_particle_velocity;
pe.min_vel = 0.5f * wip->piercing_impact_particle_velocity;
pe.max_life = 2.0f * wip->piercing_impact_particle_life;
pe.min_life = 0.25f * wip->piercing_impact_particle_life;
pe.num_high = 2 * wip->piercing_impact_particle_count;
pe.num_low = wip->piercing_impact_particle_count / 2;
pe.pos = weapon_obj->pos;
pe.normal = weapon_obj->last_orient.vec.fvec;
pe.normal_variance = wip->piercing_impact_particle_variance;
pe.max_rad = 2.0f * wip->piercing_impact_explosion_radius;
pe.min_rad = 0.5f * wip->piercing_impact_explosion_radius;
pe.vel = null_v;
particle_emit(&pe, PARTICLE_BITMAP, expl_ani_handle, 10.0f);
if (wip->piercing_impact_particle_back_velocity != 0.0f) {
pe.max_vel = 2.0f * wip->piercing_impact_particle_back_velocity;
pe.min_vel = 0.5f * wip->piercing_impact_particle_back_velocity;
pe.num_high /= 2;
pe.num_low /= 2;
particle_emit(&pe, PARTICLE_BITMAP, expl_ani_handle, 10.0f);
}
}
}
}
// For all objects that had this weapon as a target, wipe it out, forcing find of a new enemy
for ( so = GET_FIRST(&Ship_obj_list); so != END_OF_LIST(&Ship_obj_list); so = GET_NEXT(so) ) {
other_objp = &Objects[so->objnum];
Assert(other_objp->instance != -1);
shipp = &Ships[other_objp->instance];
Assert(shipp->ai_index != -1);
ai_info *aip = &Ai_info[shipp->ai_index];
if (aip->target_objnum == objnum) {
set_target_objnum(aip, -1);
// If this ship had a dynamic goal of chasing this weapon, clear the dynamic goal.
if (aip->resume_goal_time != -1)
aip->active_goal = AI_GOAL_NONE;
}
if (aip->goal_objnum == objnum) {
aip->goal_objnum = -1;
aip->goal_signature = -1;
}
if (aip->guard_objnum == objnum) {
aip->guard_objnum = -1;
aip->guard_signature = -1;
}
if (aip->hitter_objnum == objnum) {
aip->hitter_objnum = -1;
}
}
// single player and multiplayer masters evaluate the scoring and kill stuff
if (!MULTIPLAYER_CLIENT) {
//If this is a bomb, set it up for scoring. -Halleck
if (wip->wi_flags & WIF_BOMB) {
scoring_eval_kill_on_weapon(weapon_obj, other_obj);
}
}
weapon_obj->flags |= OF_SHOULD_BE_DEAD;
//Set shockwaves flag
int sw_flag = SW_WEAPON;
if ( ((other_obj) && (other_obj->type == OBJ_WEAPON)) || (Weapons[num].weapon_flags & WF_DESTROYED_BY_WEAPON)) {
sw_flag |= SW_WEAPON_KILL;
}
//Which shockwave?
shockwave_create_info *sci = &wip->shockwave;
if(!armed_weapon) {
sci = &wip->dinky_shockwave;
}
// check if this is an area effect weapon (i.e. has a blast radius)
if (sci->inner_rad != 0.0f || sci->outer_rad != 0.0f)
{
if(sci->speed > 0.0f) {
shockwave_create(OBJ_INDEX(weapon_obj), hitpos, sci, sw_flag, -1);
}
else {
weapon_do_area_effect(weapon_obj, sci, hitpos, other_obj);
}
}
// check if this is an EMP weapon
if(wip->wi_flags & WIF_EMP){
emp_apply(&weapon_obj->pos, wip->shockwave.inner_rad, wip->shockwave.outer_rad, wip->emp_intensity, wip->emp_time, (wip->wi_flags3 & WIF3_USE_EMP_TIME_FOR_CAPSHIP_TURRETS) != 0);
}
// spawn weapons - note the change from FS 1 multiplayer.
if (wip->wi_flags & WIF_SPAWN){
spawn_child_weapons(weapon_obj);
}
}
void weapon_detonate(object *objp)
{
Assert(objp != NULL);
if(objp == NULL){
return;
}
Assert((objp->type == OBJ_WEAPON) && (objp->instance >= 0));
if((objp->type != OBJ_WEAPON) || (objp->instance < 0)){
return;
}
// send a detonate packet in multiplayer
if(MULTIPLAYER_MASTER){
send_weapon_detonate_packet(objp);
}
// call weapon hit
// Wanderer - use last frame pos for the corkscrew missiles
if ( (Weapon_info[Weapons[objp->instance].weapon_info_index].wi_flags & WIF_CORKSCREW) ) {
weapon_hit(objp, NULL, &objp->last_pos);
} else {
weapon_hit(objp, NULL, &objp->pos);
}
}
// Group_id: If you should quad lasers, they should all have the same group id.
// This will be used to optimize lighting, since each group only needs to cast one light.
// Call this to get a new group id, then pass it to each weapon_create call for all the
// weapons in the group. Number will be between 0 and WEAPON_MAX_GROUP_IDS and will
// get reused.
int weapon_create_group_id()
{
static int current_id = 0;
int n = current_id;
current_id++;
if ( current_id >= WEAPON_MAX_GROUP_IDS ) {
current_id = 0;
}
return n;
}
/**
* Call before weapons_page_in to mark a weapon as used
*/
void weapon_mark_as_used(int weapon_type)
{
if (weapon_type < 0)
return;
if ( used_weapons == NULL )
return;
Assert( weapon_type < MAX_WEAPON_TYPES );
if (weapon_type < Num_weapon_types) {
used_weapons[weapon_type]++;
}
}
void weapons_page_in()
{
int i, j, idx;
Assert( used_weapons != NULL );
// for weapons in weaponry pool
for (i = 0; i < Num_teams; i++) {
for (j = 0; j < Team_data[i].num_weapon_choices; j++) {
used_weapons[Team_data[i].weaponry_pool[j]] += Team_data[i].weaponry_count[j];
}
}
// this grabs all spawn weapon types (Cluster Baby, etc.) which can't be
// assigned directly to a ship
for (i = 0; i < Num_weapon_types; i++) {
// we only want entries that already exist
if ( !used_weapons[i] )
continue;
// if it's got a spawn type then grab it
for (j = 0; j < Weapon_info[i].num_spawn_weapons_defined; j++)
{
used_weapons[(int)Weapon_info[i].spawn_info[j].spawn_type]++;
}
}
// release anything loaded that we don't have marked as used for this mission
if ( !Cmdline_load_all_weapons )
weapon_release_bitmaps();
// Page in bitmaps for all used weapons
for (i = 0; i < Num_weapon_types; i++) {
if ( !Cmdline_load_all_weapons ) {
if ( !used_weapons[i] ) {
nprintf(("Weapons", "Not loading weapon id %d (%s)\n", i, Weapon_info[i].name));
continue;
}
}
weapon_load_bitmaps(i);
weapon_info *wip = &Weapon_info[i];
wip->wi_flags &= (~WIF_THRUSTER); // Assume no thrusters
switch (wip->render_type)
{
case WRT_POF:
{
wip->model_num = model_load( wip->pofbitmap_name, 0, NULL );
polymodel *pm = model_get( wip->model_num );
// If it has a model, and the model pof has thrusters, then set
// the flags
if (pm->n_thrusters > 0) {
wip->wi_flags |= WIF_THRUSTER;
}
for (j = 0; j < pm->n_textures; j++)
pm->maps[j].PageIn();
break;
}
case WRT_LASER:
{
bm_page_in_texture( wip->laser_bitmap.first_frame );
bm_page_in_texture( wip->laser_glow_bitmap.first_frame );
break;
}
default:
Assertion(wip->render_type != WRT_POF && wip->render_type != WRT_LASER, "Weapon %s does not have a valid rendering type. Type passed: %d\n", wip->name, wip->render_type); // Invalid weapon rendering type.
}
wip->external_model_num = -1;
if ( strlen(wip->external_model_name) )
wip->external_model_num = model_load( wip->external_model_name, 0, NULL );
if (wip->external_model_num == -1)
wip->external_model_num = wip->model_num;
//Load shockwaves
wip->shockwave.load();
wip->dinky_shockwave.load();
//Explosions
Weapon_explosions.PageIn(wip->impact_weapon_expl_index);
Weapon_explosions.PageIn(wip->dinky_impact_weapon_expl_index);
Weapon_explosions.PageIn(wip->flash_impact_weapon_expl_index);
Weapon_explosions.PageIn(wip->piercing_impact_weapon_expl_index);
// trail bitmaps
if ( (wip->wi_flags & WIF_TRAIL) && (wip->tr_info.texture.bitmap_id > -1) )
bm_page_in_texture( wip->tr_info.texture.bitmap_id );
// if this is a beam weapon, page in its stuff
if (wip->wi_flags & WIF_BEAM) {
// all beam sections
for (idx = 0; idx < wip->b_info.beam_num_sections; idx++)
bm_page_in_texture(wip->b_info.sections[idx].texture.first_frame);
// muzzle glow
bm_page_in_texture(wip->b_info.beam_glow.first_frame);
// particle ani
bm_page_in_texture(wip->b_info.beam_particle_ani.first_frame);
}
if (wip->wi_flags & WIF_PARTICLE_SPEW) {
for (size_t s = 0; s < MAX_PARTICLE_SPEWERS; s++) { // looped, multi particle spew -nuke
if (wip->particle_spewers[s].particle_spew_type != PSPEW_NONE) {
bm_page_in_texture(wip->particle_spewers[s].particle_spew_anim.first_frame);
}
}
}
// muzzle flashes
if (wip->muzzle_flash >= 0)
mflash_mark_as_used(wip->muzzle_flash);
bm_page_in_texture(wip->thruster_flame.first_frame);
bm_page_in_texture(wip->thruster_glow.first_frame);
}
}
/**
* Page_in function for cheaters, grabs all weapons that weren't already in a mission
* and loads the models for them.
*
* Non-model graphics elements will get loaded when they are rendered for the first time.
* Maybe not the best way to do this but faster and a lot less error prone.
*/
void weapons_page_in_cheats()
{
int i;
// don't bother if they are all loaded already
if ( Cmdline_load_all_weapons )
return;
Assert( used_weapons != NULL );
// force a page in of all muzzle flashes
mflash_page_in(true);
// page in models for all weapon types that aren't already loaded
for (i = 0; i < Num_weapon_types; i++) {
// skip over anything that's already loaded
if (used_weapons[i])
continue;
weapon_load_bitmaps(i);
weapon_info *wip = &Weapon_info[i];
wip->wi_flags &= (~WIF_THRUSTER); // Assume no thrusters
if ( wip->render_type == WRT_POF ) {
wip->model_num = model_load( wip->pofbitmap_name, 0, NULL );
polymodel *pm = model_get( wip->model_num );
// If it has a model, and the model pof has thrusters, then set
// the flags
if ( pm->n_thrusters > 0 ) {
wip->wi_flags |= WIF_THRUSTER;
}
}
wip->external_model_num = -1;
if ( strlen(wip->external_model_name) )
wip->external_model_num = model_load( wip->external_model_name, 0, NULL );
if (wip->external_model_num == -1)
wip->external_model_num = wip->model_num;
//Load shockwaves
wip->shockwave.load();
wip->dinky_shockwave.load();
used_weapons[i]++;
}
}
/**
* Get the "color" of the laser at the given moment (since glowing lasers can cycle colors)
*/
void weapon_get_laser_color(color *c, object *objp)
{
weapon *wep;
weapon_info *winfo;
float pct;
// sanity
if (c == NULL)
return;
// sanity
Assert(objp != NULL);
Assert(objp->type == OBJ_WEAPON);
Assert(objp->instance >= 0);
Assert(Weapons[objp->instance].weapon_info_index >= 0);
if ( (objp == NULL) || (objp->type != OBJ_WEAPON) || (objp->instance < 0) || (Weapons[objp->instance].weapon_info_index < 0) )
return;
wep = &Weapons[objp->instance];
winfo = &Weapon_info[wep->weapon_info_index];
// if we're a one-color laser
if ( (winfo->laser_color_2.red == winfo->laser_color_1.red) && (winfo->laser_color_2.green == winfo->laser_color_1.green) && (winfo->laser_color_2.blue == winfo->laser_color_1.blue) ) {
*c = winfo->laser_color_1;
return;
}
int r = winfo->laser_color_1.red;
int g = winfo->laser_color_1.green;
int b = winfo->laser_color_1.blue;
// lifetime pct
pct = 1.0f - (wep->lifeleft / winfo->lifetime);
CLAMP(pct, 0.0f, 0.5f);
if (pct > 0.0f) {
pct *= 2.0f;
r += fl2i((winfo->laser_color_2.red - winfo->laser_color_1.red) * pct);
g += fl2i((winfo->laser_color_2.green - winfo->laser_color_1.green) * pct);
b += fl2i((winfo->laser_color_2.blue - winfo->laser_color_1.blue) * pct);
}
// otherwise interpolate between the colors
gr_init_color( c, r, g, b );
}
// default weapon particle spew data
int Weapon_particle_spew_count = 1;
int Weapon_particle_spew_time = 25;
float Weapon_particle_spew_vel = 0.4f;
float Weapon_particle_spew_radius = 2.0f;
float Weapon_particle_spew_lifetime = 0.15f;
float Weapon_particle_spew_scale = 0.8f;
/**
* For weapons flagged as particle spewers, spew particles. wheee
*/
void weapon_maybe_spew_particle(object *obj)
{
weapon *wp;
weapon_info *wip;
int idx;
// check some stuff
Assert(obj->type == OBJ_WEAPON);
Assert(obj->instance >= 0);
Assert(Weapons[obj->instance].weapon_info_index >= 0);
Assert(Weapon_info[Weapons[obj->instance].weapon_info_index].wi_flags & WIF_PARTICLE_SPEW);
wp = &Weapons[obj->instance];
wip = &Weapon_info[wp->weapon_info_index];
vec3d spawn_pos, spawn_vel, output_pos, output_vel, input_pos, input_vel;
for (int psi = 0; psi < MAX_PARTICLE_SPEWERS; psi++) { // iterate through spewers -nuke
if (wip->particle_spewers[psi].particle_spew_type != PSPEW_NONE) {
// if the weapon's particle timestamp has elapsed
if ((wp->particle_spew_time[psi] == -1) || timestamp_elapsed(wp->particle_spew_time[psi])) {
// reset the timestamp
wp->particle_spew_time[psi] = timestamp(wip->particle_spewers[0].particle_spew_time);
// turn normals and origins to world space if we need to
if (!vm_vec_same(&wip->particle_spewers[psi].particle_spew_offset, &vmd_zero_vector)) { // don't xform unused vectors
vm_vec_unrotate(&spawn_pos, &wip->particle_spewers[psi].particle_spew_offset, &obj->orient);
} else {
spawn_pos = vmd_zero_vector;
}
if (!vm_vec_same(&wip->particle_spewers[psi].particle_spew_velocity, &vmd_zero_vector)) {
vm_vec_unrotate(&spawn_vel, &wip->particle_spewers[psi].particle_spew_velocity, &obj->orient);
} else {
spawn_vel = vmd_zero_vector;
}
// spew some particles
if (wip->particle_spewers[psi].particle_spew_type == PSPEW_DEFAULT) // default pspew type
{ // do the default pspew
vec3d direct, direct_temp, particle_pos;
vec3d null_vec = ZERO_VECTOR;
vec3d vel;
float ang;
for (idx = 0; idx < wip->particle_spewers[psi].particle_spew_count; idx++) {
// get the backward vector of the weapon
direct = obj->orient.vec.fvec;
vm_vec_negate(&direct);
// randomly perturb x, y and z
// uvec
ang = frand_range(-PI_2,PI_2); // fl_radian(frand_range(-90.0f, 90.0f)); -optimized by nuke
vm_rot_point_around_line(&direct_temp, &direct, ang, &null_vec, &obj->orient.vec.fvec);
direct = direct_temp;
vm_vec_scale(&direct, wip->particle_spewers[psi].particle_spew_scale);
// rvec
ang = frand_range(-PI_2,PI_2); // fl_radian(frand_range(-90.0f, 90.0f)); -optimized by nuke
vm_rot_point_around_line(&direct_temp, &direct, ang, &null_vec, &obj->orient.vec.rvec);
direct = direct_temp;
vm_vec_scale(&direct, wip->particle_spewers[psi].particle_spew_scale);
// fvec
ang = frand_range(-PI_2,PI_2); // fl_radian(frand_range(-90.0f, 90.0f)); -optimized by nuke
vm_rot_point_around_line(&direct_temp, &direct, ang, &null_vec, &obj->orient.vec.uvec);
direct = direct_temp;
vm_vec_scale(&direct, wip->particle_spewers[psi].particle_spew_scale);
// get a velocity vector of some percentage of the weapon's velocity
vel = obj->phys_info.vel;
vm_vec_scale(&vel, wip->particle_spewers[psi].particle_spew_vel);
// maybe add in offset and initial velocity
if (!vm_vec_same(&spawn_vel, &vmd_zero_vector)) { // add in particle velocity if its available
vm_vec_add2(&vel, &spawn_vel);
}
if (!vm_vec_same(&spawn_pos, &vmd_zero_vector)) { // add offset if available
vm_vec_add2(&direct, &spawn_pos);
}
if (wip->wi_flags & WIF_CORKSCREW) {
vm_vec_add(&particle_pos, &obj->last_pos, &direct);
} else {
vm_vec_add(&particle_pos, &obj->pos, &direct);
}
// emit the particle
if (wip->particle_spewers[psi].particle_spew_anim.first_frame < 0) {
particle_create(&particle_pos, &vel, wip->particle_spewers[psi].particle_spew_lifetime, wip->particle_spewers[psi].particle_spew_radius, PARTICLE_SMOKE);
} else {
particle_create(&particle_pos, &vel, wip->particle_spewers[psi].particle_spew_lifetime, wip->particle_spewers[psi].particle_spew_radius, PARTICLE_BITMAP, wip->particle_spewers[psi].particle_spew_anim.first_frame);
}
}
} else if (wip->particle_spewers[psi].particle_spew_type == PSPEW_HELIX) { // helix
float segment_length = wip->max_speed * flFrametime; // determine how long the segment is
float segment_angular_length = PI2 * wip->particle_spewers[psi].particle_spew_rotation_rate * flFrametime; // determine how much the segment rotates
float rotation_value = (wp->lifeleft * PI2 * wip->particle_spewers[psi].particle_spew_rotation_rate) + wp->particle_spew_rand; // calculate a rotational start point based on remaining life
float inc = 1.0f / wip->particle_spewers[psi].particle_spew_count; // determine our incriment
float particle_rot;
vec3d input_pos_l = ZERO_VECTOR;
for (float is = 0; is < 1; is += inc ) { // use iterator as a scaler
particle_rot = rotation_value + (segment_angular_length * is); // find what point of the rotation were at
input_vel.xyz.x = sinf(particle_rot) * wip->particle_spewers[psi].particle_spew_scale; // determine x/y velocity based on scale and rotation
input_vel.xyz.y = cosf(particle_rot) * wip->particle_spewers[psi].particle_spew_scale;
input_vel.xyz.z = wip->max_speed * wip->particle_spewers[psi].particle_spew_vel; // velocity inheritance
vm_vec_unrotate(&output_vel, &input_vel, &obj->orient); // orient velocity to weapon
input_pos_l.xyz.x = input_vel.xyz.x * flFrametime * (1.0f - is); // interpolate particle motion
input_pos_l.xyz.y = input_vel.xyz.y * flFrametime * (1.0f - is);
input_pos_l.xyz.z = segment_length * is; // position particle correctly on the z axis
vm_vec_unrotate(&input_pos, &input_pos_l, &obj->orient); // orient to weapon
vm_vec_sub(&output_pos, &obj->pos, &input_pos); // translate to world space
//maybe add in offset and initial velocity
if (!vm_vec_same(&spawn_vel, &vmd_zero_vector)) { // add particle velocity if needed
vm_vec_add2(&output_vel, &spawn_vel);
}
if (!vm_vec_same(&spawn_pos, &vmd_zero_vector)) { // add offset if needed
vm_vec_add2(&output_pos, &spawn_pos);
}
//emit particles
if (wip->particle_spewers[psi].particle_spew_anim.first_frame < 0) {
particle_create(&output_pos, &output_vel, wip->particle_spewers[psi].particle_spew_lifetime, wip->particle_spewers[psi].particle_spew_radius, PARTICLE_SMOKE);
} else {
particle_create(&output_pos, &output_vel, wip->particle_spewers[psi].particle_spew_lifetime, wip->particle_spewers[psi].particle_spew_radius, PARTICLE_BITMAP, wip->particle_spewers[psi].particle_spew_anim.first_frame);
}
}
} else if (wip->particle_spewers[psi].particle_spew_type == PSPEW_SPARKLER) { // sparkler
vec3d temp_vel;
output_vel = obj->phys_info.vel;
vm_vec_scale(&output_vel, wip->particle_spewers[psi].particle_spew_vel);
for (idx = 0; idx < wip->particle_spewers[psi].particle_spew_count; idx++) {
// create a random unit vector and scale it
vm_vec_rand_vec_quick(&input_vel);
vm_vec_scale(&input_vel, wip->particle_spewers[psi].particle_spew_scale);
if (wip->particle_spewers[psi].particle_spew_z_scale != 1.0f) { // don't do the extra math for spherical effect
temp_vel = input_vel;
temp_vel.xyz.z *= wip->particle_spewers[psi].particle_spew_z_scale; // for an ovoid particle effect to better combine with laser effects
vm_vec_unrotate(&input_vel, &temp_vel, &obj->orient); // so it has to be rotated
}
vm_vec_add2(&output_vel, &input_vel); // add to weapon velocity
output_pos = obj->pos;
// maybe add in offset and initial velocity
if (!vm_vec_same(&spawn_vel, &vmd_zero_vector)) { // add particle velocity if needed
vm_vec_add2(&output_vel, &spawn_vel);
}
if (!vm_vec_same(&spawn_pos, &vmd_zero_vector)) { // add offset if needed
vm_vec_add2(&output_pos, &spawn_pos);
}
// emit particles
if (wip->particle_spewers[psi].particle_spew_anim.first_frame < 0) {
particle_create(&output_pos, &output_vel, wip->particle_spewers[psi].particle_spew_lifetime, wip->particle_spewers[psi].particle_spew_radius, PARTICLE_SMOKE);
} else {
particle_create(&output_pos, &output_vel, wip->particle_spewers[psi].particle_spew_lifetime, wip->particle_spewers[psi].particle_spew_radius, PARTICLE_BITMAP, wip->particle_spewers[psi].particle_spew_anim.first_frame);
}
}
} else if (wip->particle_spewers[psi].particle_spew_type == PSPEW_RING) {
float inc = PI2 / wip->particle_spewers[psi].particle_spew_count;
for (float ir = 0; ir < PI2; ir += inc) { // use iterator for rotation
input_vel.xyz.x = sinf(ir) * wip->particle_spewers[psi].particle_spew_scale; // generate velocity from rotation data
input_vel.xyz.y = cosf(ir) * wip->particle_spewers[psi].particle_spew_scale;
input_vel.xyz.z = obj->phys_info.fspeed * wip->particle_spewers[psi].particle_spew_vel;
vm_vec_unrotate(&output_vel, &input_vel, &obj->orient); // rotate it to model
output_pos = obj->pos;
// maybe add in offset amd iitial velocity
if (!vm_vec_same(&spawn_vel, &vmd_zero_vector)) { // add particle velocity if needed
vm_vec_add2(&output_vel, &spawn_vel);
}
if (!vm_vec_same(&spawn_pos, &vmd_zero_vector)) { // add offset if needed
vm_vec_add2(&output_pos, &spawn_pos);
}
// emit particles
if (wip->particle_spewers[psi].particle_spew_anim.first_frame < 0) {
particle_create(&output_pos, &output_vel, wip->particle_spewers[psi].particle_spew_lifetime, wip->particle_spewers[psi].particle_spew_radius, PARTICLE_SMOKE);
} else {
particle_create(&output_pos, &output_vel, wip->particle_spewers[psi].particle_spew_lifetime, wip->particle_spewers[psi].particle_spew_radius, PARTICLE_BITMAP, wip->particle_spewers[psi].particle_spew_anim.first_frame);
}
}
} else if (wip->particle_spewers[psi].particle_spew_type == PSPEW_PLUME) {
float ang_rand, len_rand, sin_ang, cos_ang;
vec3d input_pos_l = ZERO_VECTOR;
for (int i = 0; i < wip->particle_spewers[psi].particle_spew_count; i++) {
// use polar coordinates to ensure a disk shaped spew plane
ang_rand = frand_range(-PI,PI);
len_rand = frand() * wip->particle_spewers[psi].particle_spew_scale;
sin_ang = sinf(ang_rand);
cos_ang = cosf(ang_rand);
// compute velocity
input_vel.xyz.x = wip->particle_spewers[psi].particle_spew_z_scale * -sin_ang;
input_vel.xyz.y = wip->particle_spewers[psi].particle_spew_z_scale * -cos_ang;
input_vel.xyz.z = obj->phys_info.fspeed * wip->particle_spewers[psi].particle_spew_vel;
vm_vec_unrotate(&output_vel, &input_vel, &obj->orient); // rotate it to model
// place particle on a disk prependicular to the weapon normal and rotate to model space
input_pos_l.xyz.x = sin_ang * len_rand;
input_pos_l.xyz.y = cos_ang * len_rand;
vm_vec_unrotate(&input_pos, &input_pos_l, &obj->orient); // rotate to world
vm_vec_sub(&output_pos, &obj->pos, &input_pos); // translate to world
// maybe add in offset amd iitial velocity
if (!vm_vec_same(&spawn_vel, &vmd_zero_vector)) { // add particle velocity if needed
vm_vec_add2(&output_vel, &spawn_vel);
}
if (!vm_vec_same(&spawn_pos, &vmd_zero_vector)) { // add offset if needed
vm_vec_add2(&output_pos, &spawn_pos);
}
//emit particles
if (wip->particle_spewers[psi].particle_spew_anim.first_frame < 0) {
particle_create(&output_pos, &output_vel, wip->particle_spewers[psi].particle_spew_lifetime, wip->particle_spewers[psi].particle_spew_radius, PARTICLE_SMOKE);
} else {
particle_create(&output_pos, &output_vel, wip->particle_spewers[psi].particle_spew_lifetime, wip->particle_spewers[psi].particle_spew_radius, PARTICLE_BITMAP, wip->particle_spewers[psi].particle_spew_anim.first_frame);
}
}
}
}
}
}
}
/**
* Debug console functionality
*/
void pspew_display_dcf()
{
dc_printf("Particle spew settings\n\n");
dc_printf("Particle spew count (pspew_count) : %d\n", Weapon_particle_spew_count);
dc_printf("Particle spew time (pspew_time) : %d\n", Weapon_particle_spew_time);
dc_printf("Particle spew velocity (pspew_vel) : %f\n", Weapon_particle_spew_vel);
dc_printf("Particle spew size (pspew_size) : %f\n", Weapon_particle_spew_radius);
dc_printf("Particle spew lifetime (pspew_life) : %f\n", Weapon_particle_spew_lifetime);
dc_printf("Particle spew scale (psnew_scale) : %f\n", Weapon_particle_spew_scale);
}
DCF(pspew_count, "Number of particles spewed at a time")
{
dc_get_arg(ARG_INT);
if(Dc_arg_type & ARG_INT){
Weapon_particle_spew_count = Dc_arg_int;
}
pspew_display_dcf();
}
DCF(pspew_time, "Time between particle spews")
{
dc_get_arg(ARG_INT);
if(Dc_arg_type & ARG_INT){
Weapon_particle_spew_time = Dc_arg_int;
}
pspew_display_dcf();
}
DCF(pspew_vel, "Relative velocity of particles (0.0 - 1.0)")
{
dc_get_arg(ARG_FLOAT);
if(Dc_arg_type & ARG_FLOAT){
Weapon_particle_spew_vel = Dc_arg_float;
}
pspew_display_dcf();
}
DCF(pspew_size, "Size of spewed particles")
{
dc_get_arg(ARG_FLOAT);
if(Dc_arg_type & ARG_FLOAT){
Weapon_particle_spew_radius = Dc_arg_float;
}
pspew_display_dcf();
}
DCF(pspew_life, "Lifetime of spewed particles")
{
dc_get_arg(ARG_FLOAT);
if(Dc_arg_type & ARG_FLOAT){
Weapon_particle_spew_lifetime = Dc_arg_float;
}
pspew_display_dcf();
}
DCF(pspew_scale, "How far away particles are from the weapon path")
{
dc_get_arg(ARG_FLOAT);
if(Dc_arg_type & ARG_FLOAT){
Weapon_particle_spew_scale = Dc_arg_float;
}
pspew_display_dcf();
}
/**
* Return a scale factor for damage which should be applied for 2 collisions
*/
float weapon_get_damage_scale(weapon_info *wip, object *wep, object *target)
{
weapon *wp;
int from_player = 0;
float total_scale = 1.0f;
float hull_pct;
int is_big_damage_ship = 0;
// Goober5000 - additional sanity (target can be NULL)
Assert(wip);
Assert(wep);
// sanity
if((wip == NULL) || (wep == NULL) || (target == NULL)){
return 1.0f;
}
// don't scale any damage if its not a weapon
if((wep->type != OBJ_WEAPON) || (wep->instance < 0) || (wep->instance >= MAX_WEAPONS)){
return 1.0f;
}
wp = &Weapons[wep->instance];
// was the weapon fired by the player
from_player = 0;
if((wep->parent >= 0) && (wep->parent < MAX_OBJECTS) && (Objects[wep->parent].flags & OF_PLAYER_SHIP)){
from_player = 1;
}
// if this is a lockarm weapon, and it was fired unlocked
if((wip->wi_flags & WIF_LOCKARM) && !(wp->weapon_flags & WF_LOCKED_WHEN_FIRED)){
total_scale *= 0.1f;
}
// if the hit object was a ship and we're doing damage scaling
if ( (target->type == OBJ_SHIP) &&
!(The_mission.ai_profile->flags & AIPF_DISABLE_WEAPON_DAMAGE_SCALING) &&
!(Ship_info[Ships[target->instance].ship_info_index].flags2 & SIF2_DISABLE_WEAPON_DAMAGE_SCALING)
) {
ship_info *sip;
// get some info on the ship
Assert((target->instance >= 0) && (target->instance < MAX_SHIPS));
if((target->instance < 0) || (target->instance >= MAX_SHIPS)){
return total_scale;
}
sip = &Ship_info[Ships[target->instance].ship_info_index];
// get hull pct of the ship currently
hull_pct = get_hull_pct(target);
// if it has hit a supercap ship and is not a supercap class weapon
if((sip->flags & SIF_SUPERCAP) && !(wip->wi_flags & WIF_SUPERCAP)){
// if the supercap is around 3/4 damage, apply nothing
if(hull_pct <= 0.75f){
return 0.0f;
} else {
total_scale *= SUPERCAP_DAMAGE_SCALE;
}
}
// determine if this is a big damage ship
is_big_damage_ship = (sip->flags & SIF_BIG_DAMAGE);
// if this is a large ship, and is being hit by flak
if(is_big_damage_ship && (wip->wi_flags & WIF_FLAK)){
total_scale *= FLAK_DAMAGE_SCALE;
}
// if the weapon is a small weapon being fired at a big ship
if( is_big_damage_ship && !(wip->wi_flags & (WIF_HURTS_BIG_SHIPS)) ){
// if the player is firing it
if ( from_player && !(The_mission.ai_profile->flags2 & AIPF2_PLAYER_WEAPON_SCALE_FIX)) {
// if it's a laser weapon
if(wip->subtype == WP_LASER){
total_scale *= 0.01f;
} else {
total_scale *= 0.05f;
}
}
// scale based on hull
if(hull_pct > 0.1f){
total_scale *= hull_pct;
} else {
return 0.0f;
}
}
}
return total_scale;
}
void pause_in_flight_sounds()
{
for (int i = 0; i < MAX_WEAPONS; i++)
{
if (Weapons[i].objnum != -1)
{
weapon* wp = &Weapons[i];
if (wp->hud_in_flight_snd_sig >= 0 && snd_is_playing(wp->hud_in_flight_snd_sig))
{
// Stop sound, it will be restarted in the first frame after the game is unpaused
snd_stop(wp->hud_in_flight_snd_sig);
}
}
}
}
void weapon_pause_sounds()
{
// Pause all beam sounds
beam_pause_sounds();
// Pause in-flight sounds
pause_in_flight_sounds();
}
void weapon_unpause_sounds()
{
// Pause all beam sounds
beam_unpause_sounds();
}
|