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
|
//
//
#include "animation_handle.h"
#include "cockpit_display.h"
#include "enums.h"
#include "message.h"
#include "modelinstance.h"
#include "object.h"
#include "order.h"
#include "parse_object.h"
#include "ship.h"
#include "ship_bank.h"
#include "shipclass.h"
#include "subsystem.h"
#include "team.h"
#include "texture.h"
#include "vecmath.h"
#include "weaponclass.h"
#include "wing.h"
#include "ai/aigoals.h"
#include "globalincs/utility.h"
#include "hud/hudets.h"
#include "hud/hudshield.h"
#include "mission/missionlog.h"
#include "mission/missionmessage.h"
#include "model/model.h"
#include "network/multiutil.h"
#include "object/object.h"
#include "object/objectdock.h"
#include "parse/parselo.h"
#include "playerman/player.h"
#include "ship/ship.h"
#include "ship/shipfx.h"
#include "ship/shiphit.h"
extern void ship_reset_disabled_physics(object *objp, int ship_class);
extern bool sexp_check_flag_arrays(const char *flag_name, Object::Object_Flags &object_flag, Ship::Ship_Flags &ship_flags, Mission::Parse_Object_Flags &parse_obj_flag, AI::AI_Flags &ai_flag);
extern void sexp_alter_ship_flag_helper(object_ship_wing_point_team &oswpt, bool future_ships, Object::Object_Flags object_flag, Ship::Ship_Flags ship_flag, Mission::Parse_Object_Flags parse_obj_flag, AI::AI_Flags ai_flag, bool set_flag);
namespace scripting {
namespace api {
//**********HANDLE: Ship
ADE_OBJ_DERIV(l_Ship, object_h, "ship", "Ship handle", l_Object);
ADE_INDEXER(l_Ship, "string/number NameOrIndex", "Array of ship subsystems", "subsystem", "Subsystem handle, or invalid subsystem handle if index or ship handle is invalid")
{
object_h *objh;
const char* s = nullptr;
ship_subsys_h *sub = nullptr;
if(!ade_get_args(L, "o|so", l_Ship.GetPtr(&objh), &s, l_Subsystem.GetPtr(&sub)))
return ade_set_error(L, "o", l_Subsystem.Set(ship_subsys_h()));
if(!objh->isValid())
return ade_set_error(L, "o", l_Subsystem.Set(ship_subsys_h()));
ship *shipp = &Ships[objh->objp()->instance];
ship_subsys *ss = ship_get_subsys(shipp, s);
if(ss == NULL)
{
int idx = atoi(s);
if(idx > 0 && idx <= ship_get_num_subsys(shipp))
{
idx--; //Lua->FS2
ss = ship_get_indexed_subsys(shipp, idx);
}
}
if(ss == NULL)
return ade_set_error(L, "o", l_Subsystem.Set(ship_subsys_h()));
return ade_set_args(L, "o", l_Subsystem.Set(ship_subsys_h(objh->objp(), ss)));
}
ADE_FUNC(__len, l_Ship, NULL, "Number of subsystems on ship", "number", "Subsystem number, or 0 if handle is invalid")
{
object_h *objh;
if(!ade_get_args(L, "o", l_Ship.GetPtr(&objh)))
return ade_set_error(L, "i", 0);
if(!objh->isValid())
return ade_set_error(L, "i", 0);
return ade_set_args(L, "i", ship_get_num_subsys(&Ships[objh->objp()->instance]));
}
ADE_FUNC(setFlag, l_Ship, "boolean set_it, string flag_name", "Sets or clears one or more flags - this function can accept an arbitrary number of flag arguments. The flag names can be any string that the alter-ship-flag SEXP operator supports.", nullptr, "Returns nothing")
{
object_h *objh;
bool set_it;
const char *flag_name;
if (!ade_get_args(L, "obs", l_Ship.GetPtr(&objh), &set_it, &flag_name))
return ADE_RETURN_NIL;
int skip_args = 2; // not 3 because there will be one more below
if (!objh->isValid())
return ADE_RETURN_NIL;
auto shipp = &Ships[objh->objp()->instance];
object_ship_wing_point_team oswpt(shipp);
do {
auto object_flag = Object::Object_Flags::NUM_VALUES;
auto ship_flag = Ship::Ship_Flags::NUM_VALUES;
auto parse_obj_flag = Mission::Parse_Object_Flags::NUM_VALUES;
auto ai_flag = AI::AI_Flags::NUM_VALUES;
sexp_check_flag_arrays(flag_name, object_flag, ship_flag, parse_obj_flag, ai_flag);
if (object_flag == Object::Object_Flags::NUM_VALUES && ship_flag == Ship::Ship_Flags::NUM_VALUES && ai_flag == AI::AI_Flags::NUM_VALUES)
{
Warning(LOCATION, "Ship/object/ai flag '%s' not found!", flag_name);
return ADE_RETURN_NIL;
}
sexp_alter_ship_flag_helper(oswpt, true, object_flag, ship_flag, parse_obj_flag, ai_flag, set_it);
// read the next flag
internal::Ade_get_args_skip = ++skip_args;
} while (ade_get_args(L, "|s", &flag_name) > 0);
return ADE_RETURN_NIL;
}
ADE_FUNC(getFlag, l_Ship, "string flag_name", "Checks whether one or more flags are set - this function can accept an arbitrary number of flag arguments. The flag names can be any string that the alter-ship-flag SEXP operator supports.", "boolean", "Returns whether all flags are set, or nil if the ship is not valid")
{
object_h *objh;
const char *flag_name;
if (!ade_get_args(L, "os", l_Ship.GetPtr(&objh), &flag_name))
return ADE_RETURN_NIL;
int skip_args = 1; // not 2 because there will be one more below
if (!objh->isValid())
return ADE_RETURN_NIL;
auto objp = objh->objp();
auto shipp = &Ships[objp->instance];
auto aip = &Ai_info[shipp->ai_index];
do {
auto object_flag = Object::Object_Flags::NUM_VALUES;
auto ship_flag = Ship::Ship_Flags::NUM_VALUES;
auto parse_obj_flag = Mission::Parse_Object_Flags::NUM_VALUES;
auto ai_flag = AI::AI_Flags::NUM_VALUES;
sexp_check_flag_arrays(flag_name, object_flag, ship_flag, parse_obj_flag, ai_flag);
if (object_flag == Object::Object_Flags::NUM_VALUES && ship_flag == Ship::Ship_Flags::NUM_VALUES && ai_flag == AI::AI_Flags::NUM_VALUES)
{
Warning(LOCATION, "Ship/object/ai flag '%s' not found!", flag_name);
return ADE_RETURN_FALSE;
}
// now check the flags
if (object_flag != Object::Object_Flags::NUM_VALUES)
{
if (!(objp->flags[object_flag]))
return ADE_RETURN_FALSE;
}
if (ship_flag != Ship::Ship_Flags::NUM_VALUES)
{
if (!(shipp->flags[ship_flag]))
return ADE_RETURN_FALSE;
}
// we don't check parse flags, except for one that can be an object flag in reverse
if (parse_obj_flag == Mission::Parse_Object_Flags::OF_No_collide)
{
if (objp->flags[Object::Object_Flags::Collides])
return ADE_RETURN_FALSE;
}
if (ai_flag != AI::AI_Flags::NUM_VALUES)
{
if (!(aip->ai_flags[ai_flag]))
return ADE_RETURN_FALSE;
}
// read the next flag
internal::Ade_get_args_skip = ++skip_args;
} while (ade_get_args(L, "|s", &flag_name) > 0);
// if we're still here, all the flags we were looking for were present
return ADE_RETURN_TRUE;
}
static int ship_getset_helper(lua_State* L, int ship::* field, bool canSet = false, bool canBeNegative = false)
{
object_h* objh;
int value;
if (!ade_get_args(L, "o|i", l_Ship.GetPtr(&objh), &value))
return ADE_RETURN_NIL;
if (!objh->isValid())
return ADE_RETURN_NIL;
ship* shipp = &Ships[objh->objp()->instance];
if (ADE_SETTING_VAR)
{
if (canSet)
{
if (canBeNegative || value >= 0)
shipp->*field = value;
}
else
LuaError(L, "This property is read only.");
}
return ade_set_args(L, "i", shipp->*field);
}
ADE_VIRTVAR(ShieldArmorClass, l_Ship, "string", "Current Armor class of the ships' shield", "string", "Armor class name, or empty string if none is set")
{
object_h *objh;
const char* s = nullptr;
const char *name = nullptr;
if(!ade_get_args(L, "o|s", l_Ship.GetPtr(&objh), &s))
return ade_set_error(L, "s", "");
if(!objh->isValid())
return ade_set_error(L, "s", "");
ship *shipp = &Ships[objh->objp()->instance];
int atindex;
if (ADE_SETTING_VAR && s != nullptr) {
atindex = armor_type_get_idx(s);
shipp->shield_armor_type_idx = atindex;
} else {
atindex = shipp->shield_armor_type_idx;
}
if (atindex != -1)
name = Armor_types[atindex].GetNamePtr();
else
name = "";
return ade_set_args(L, "s", name);
}
ADE_VIRTVAR(ImpactDamageClass, l_Ship, "string", "Current Impact Damage class", "string", "Impact Damage class name, or empty string if none is set")
{
object_h *objh;
const char* s = nullptr;
const char *name = nullptr;
if(!ade_get_args(L, "o|s", l_Ship.GetPtr(&objh), &s))
return ade_set_error(L, "s", "");
if(!objh->isValid())
return ade_set_error(L, "s", "");
ship *shipp = &Ships[objh->objp()->instance];
int damage_index;
if (ADE_SETTING_VAR && s != nullptr) {
damage_index = find_item_with_name(Damage_types, s);
shipp->collision_damage_type_idx = damage_index;
} else {
damage_index = shipp->collision_damage_type_idx;
}
if (damage_index != -1)
name = Damage_types[damage_index].name;
else
name = "";
return ade_set_args(L, "s", name);
}
ADE_VIRTVAR(ArmorClass, l_Ship, "string", "Current Armor class", "string", "Armor class name, or empty string if none is set")
{
object_h *objh;
const char* s = nullptr;
const char *name = nullptr;
if(!ade_get_args(L, "o|s", l_Ship.GetPtr(&objh), &s))
return ade_set_error(L, "s", "");
if(!objh->isValid())
return ade_set_error(L, "s", "");
ship *shipp = &Ships[objh->objp()->instance];
int atindex;
if (ADE_SETTING_VAR && s != nullptr) {
atindex = armor_type_get_idx(s);
shipp->armor_type_idx = atindex;
} else {
atindex = shipp->armor_type_idx;
}
if (atindex != -1)
name = Armor_types[atindex].GetNamePtr();
else
name = "";
return ade_set_args(L, "s", name);
}
ADE_VIRTVAR(Name, l_Ship, "string", "Ship name. This is the actual name of the ship. Use <i>getDisplayString</i> to get the string which should be displayed to the player.", "string", "Ship name, or empty string if handle is invalid")
{
object_h *objh;
const char* s = nullptr;
if(!ade_get_args(L, "o|s", l_Ship.GetPtr(&objh), &s))
return ade_set_error(L, "s", "");
if(!objh->isValid())
return ade_set_error(L, "s", "");
ship *shipp = &Ships[objh->objp()->instance];
if(ADE_SETTING_VAR && s != nullptr) {
auto len = sizeof(shipp->ship_name);
strncpy(shipp->ship_name, s, len);
shipp->ship_name[len - 1] = 0;
}
return ade_set_args(L, "s", shipp->ship_name);
}
ADE_VIRTVAR(DisplayName, l_Ship, "string", "Ship display name", "string", "The display name of the ship or empty if there is no display string")
{
object_h *objh;
const char* s = nullptr;
if(!ade_get_args(L, "o|s", l_Ship.GetPtr(&objh), &s))
return ade_set_error(L, "s", "");
if(!objh->isValid())
return ade_set_error(L, "s", "");
ship *shipp = &Ships[objh->objp()->instance];
if(ADE_SETTING_VAR && s != nullptr) {
shipp->display_name = s;
// for compatibility reasons, if we are setting this to the empty string, clear the flag
shipp->flags.set(Ship::Ship_Flags::Has_display_name, s[0] != 0);
}
return ade_set_args(L, "s", shipp->display_name.c_str());
}
ADE_FUNC(isPlayer, l_Ship, nullptr, "Checks whether the ship is a player ship", "boolean", "Whether the ship is a player ship")
{
object_h* objh;
if (!ade_get_args(L, "o", l_Ship.GetPtr(&objh)))
return ade_set_error(L, "b", false);
if (!objh->isValid())
return ade_set_error(L, "b", false);
// singleplayer
if (!(Game_mode & GM_MULTIPLAYER))
{
if (Player_obj == objh->objp())
return ADE_RETURN_TRUE;
else
return ADE_RETURN_FALSE;
}
// multiplayer
else
{
// try and find the player
int np_index = multi_find_player_by_object(objh->objp());
if ((np_index >= 0) && (np_index < MAX_PLAYERS))
return ADE_RETURN_TRUE;
else
return ADE_RETURN_FALSE;
}
}
ADE_VIRTVAR(AfterburnerFuelLeft, l_Ship, "number", "Afterburner fuel left", "number", "Afterburner fuel left, or 0 if handle is invalid")
{
object_h *objh;
float fuel = -1.0f;
if(!ade_get_args(L, "o|f", l_Ship.GetPtr(&objh), &fuel))
return ade_set_error(L, "f", 0.0f);
if(!objh->isValid())
return ade_set_error(L, "f", 0.0f);
ship *shipp = &Ships[objh->objp()->instance];
if(ADE_SETTING_VAR && fuel >= 0.0f)
shipp->afterburner_fuel = fuel;
return ade_set_args(L, "f", shipp->afterburner_fuel);
}
ADE_VIRTVAR(AfterburnerFuelMax, l_Ship, "number", "Afterburner fuel capacity", "number", "Afterburner fuel capacity, or 0 if handle is invalid")
{
object_h *objh;
float fuel = -1.0f;
if(!ade_get_args(L, "o|f", l_Ship.GetPtr(&objh), &fuel))
return ade_set_error(L, "f", 0.0f);
if(!objh->isValid())
return ade_set_error(L, "f", 0.0f);
ship_info *sip = &Ship_info[Ships[objh->objp()->instance].ship_info_index];
if(ADE_SETTING_VAR && fuel >= 0.0f)
sip->afterburner_fuel_capacity = fuel;
return ade_set_args(L, "f", sip->afterburner_fuel_capacity);
}
ADE_VIRTVAR(Class, l_Ship, "shipclass", "Ship class", "shipclass", "Ship class, or invalid shipclass handle if ship handle is invalid")
{
object_h *objh;
int idx=-1;
if(!ade_get_args(L, "o|o", l_Ship.GetPtr(&objh), l_Shipclass.Get(&idx)))
return ade_set_error(L, "o", l_Shipclass.Set(-1));
if(!objh->isValid())
return ade_set_error(L, "o", l_Shipclass.Set(-1));
ship *shipp = &Ships[objh->objp()->instance];
if(ADE_SETTING_VAR && idx > -1) {
change_ship_type(objh->objp()->instance, idx, 1);
if (shipp == Player_ship) {
// update HUD and RTT cockpit gauges if applicable
set_current_hud();
ship_close_cockpit_displays(Player_ship);
ship_init_cockpit_displays(Player_ship);
}
}
if(shipp->ship_info_index < 0)
return ade_set_error(L, "o", l_Shipclass.Set(-1));
return ade_set_args(L, "o", l_Shipclass.Set(shipp->ship_info_index));
}
ADE_VIRTVAR(CountermeasuresLeft, l_Ship, "number", "Number of countermeasures left", "number", "Countermeasures left, or 0 if ship handle is invalid")
{
object_h *objh;
int newcm = -1;
if(!ade_get_args(L, "o|i", l_Ship.GetPtr(&objh), &newcm))
return ade_set_error(L, "i", 0);
if(!objh->isValid())
return ade_set_error(L, "i", 0);
ship *shipp = &Ships[objh->objp()->instance];
if(ADE_SETTING_VAR && newcm > -1)
shipp->cmeasure_count = newcm;
return ade_set_args(L, "i", shipp->cmeasure_count);
}
ADE_VIRTVAR(CockpitDisplays, l_Ship, "displays", "An array of the cockpit displays on this ship.<br>NOTE: Only the ship of the player has these", "displays", "displays handle or invalid handle on error")
{
object_h *objh;
cockpit_displays_h *cdh = NULL;
if(!ade_get_args(L, "o|o", l_Ship.GetPtr(&objh), l_CockpitDisplays.GetPtr(&cdh)))
return ade_set_error(L, "o", l_CockpitDisplays.Set(cockpit_displays_h()));
if(!objh->isValid())
return ade_set_error(L, "o", l_CockpitDisplays.Set(cockpit_displays_h()));
if(ADE_SETTING_VAR)
{
LuaError(L, "Attempted to use incomplete feature: Cockpit displays copy");
}
return ade_set_args(L, "o", l_CockpitDisplays.Set(cockpit_displays_h(objh->objnum)));
}
ADE_VIRTVAR(CountermeasureClass, l_Ship, "weaponclass", "Weapon class mounted on this ship's countermeasure point", "weaponclass", "Countermeasure hardpoint weapon class, or invalid weaponclass handle if no countermeasure class or ship handle is invalid")
{
object_h *objh;
int newcm = -1;
if(!ade_get_args(L, "o|o", l_Ship.GetPtr(&objh), l_Weaponclass.Get(&newcm)))
return ade_set_error(L, "o", l_Weaponclass.Set(-1));;
if(!objh->isValid())
return ade_set_error(L, "o", l_Weaponclass.Set(-1));;
ship *shipp = &Ships[objh->objp()->instance];
if(ADE_SETTING_VAR) {
shipp->current_cmeasure = newcm;
}
if(shipp->current_cmeasure > -1)
return ade_set_args(L, "o", l_Weaponclass.Set(shipp->current_cmeasure));
else
return ade_set_error(L, "o", l_Weaponclass.Set(-1));;
}
ADE_VIRTVAR(HitpointsMax, l_Ship, "number", "Total hitpoints", "number", "Ship maximum hitpoints, or 0 if handle is invalid")
{
object_h *objh;
float newhits = -1;
if(!ade_get_args(L, "o|f", l_Ship.GetPtr(&objh), &newhits))
return ade_set_error(L, "f", 0.0f);
if(!objh->isValid())
return ade_set_error(L, "f", 0.0f);
ship *shipp = &Ships[objh->objp()->instance];
if(ADE_SETTING_VAR && newhits > -1)
shipp->ship_max_hull_strength = newhits;
return ade_set_args(L, "f", shipp->ship_max_hull_strength);
}
ADE_VIRTVAR(ShieldRegenRate, l_Ship, "number", "Maximum percentage/100 of shield energy regenerated per second. For example, 0.02 = 2% recharge per second.", "number", "Ship maximum shield regeneration rate, or 0 if handle is invalid")
{
object_h *objh;
float new_shield_regen = -1;
if (!ade_get_args(L, "o|f", l_Ship.GetPtr(&objh), &new_shield_regen))
return ade_set_error(L, "f", 0.0f);
if(!objh->isValid())
return ade_set_error(L, "f", 0.0f);
ship *shipp = &Ships[objh->objp()->instance];
if (ADE_SETTING_VAR && new_shield_regen > -1)
shipp->max_shield_regen_per_second = new_shield_regen;
return ade_set_args(L, "f", shipp->max_shield_regen_per_second);
}
ADE_VIRTVAR(WeaponRegenRate, l_Ship, "number", "Maximum percentage/100 of weapon energy regenerated per second. For example, 0.02 = 2% recharge per second.", "number", "Ship maximum weapon regeneration rate, or 0 if handle is invalid")
{
object_h *objh;
float new_weapon_regen = -1;
if (!ade_get_args(L, "o|f", l_Ship.GetPtr(&objh), &new_weapon_regen))
return ade_set_error(L, "f", 0.0f);
if(!objh->isValid())
return ade_set_error(L, "f", 0.0f);
ship *shipp = &Ships[objh->objp()->instance];
if (ADE_SETTING_VAR && new_weapon_regen > -1)
shipp->max_weapon_regen_per_second = new_weapon_regen;
return ade_set_args(L, "f", shipp->max_weapon_regen_per_second);
}
ADE_VIRTVAR(WeaponEnergyLeft, l_Ship, "number", "Current weapon energy reserves", "number", "Ship current weapon energy reserve level, or 0 if invalid")
{
object_h *objh;
float neweng = -1;
if(!ade_get_args(L, "o|f", l_Ship.GetPtr(&objh), &neweng))
return ade_set_error(L, "f", 0.0f);
if(!objh->isValid())
return ade_set_error(L, "f", 0.0f);
ship *shipp = &Ships[objh->objp()->instance];
if(ADE_SETTING_VAR && neweng > -1)
shipp->weapon_energy = neweng;
return ade_set_args(L, "f", shipp->weapon_energy);
}
ADE_VIRTVAR(WeaponEnergyMax, l_Ship, "number", "Maximum weapon energy", "number", "Ship maximum weapon energy reserve level, or 0 if invalid")
{
object_h *objh;
float neweng = -1;
if(!ade_get_args(L, "o|f", l_Ship.GetPtr(&objh), &neweng))
return ade_set_error(L, "f", 0.0f);
if(!objh->isValid())
return ade_set_error(L, "f", 0.0f);
ship_info *sip = &Ship_info[Ships[objh->objp()->instance].ship_info_index];
if(ADE_SETTING_VAR && neweng > -1)
sip->max_weapon_reserve = neweng;
return ade_set_args(L, "f", sip->max_weapon_reserve);
}
ADE_VIRTVAR(AutoaimFOV, l_Ship, "number", "FOV of ship's autoaim, if any", "number", "FOV (in degrees), or 0 if ship uses no autoaim or if handle is invalid")
{
object_h *objh;
float fov = -1;
if(!ade_get_args(L, "o|f", l_Ship.GetPtr(&objh), &fov))
return ade_set_error(L, "f", 0.0f);
if(!objh->isValid())
return ade_set_error(L, "f", 0.0f);
ship *shipp = &Ships[objh->objp()->instance];
if(ADE_SETTING_VAR && fov >= 0.0f) {
if (fov > 180.0)
fov = 180.0;
shipp->autoaim_fov = fov * PI / 180.0f;
}
return ade_set_args(L, "f", shipp->autoaim_fov * 180.0f / PI);
}
ADE_VIRTVAR(PrimaryTriggerDown, l_Ship, "boolean", "Determines if primary trigger is pressed or not", "boolean", "True if pressed, false if not, nil if ship handle is invalid")
{
object_h *objh;
bool trig = false;
if(!ade_get_args(L, "o|b", l_Ship.GetPtr(&objh), &trig))
return ADE_RETURN_NIL;
if(!objh->isValid())
return ADE_RETURN_NIL;
ship *shipp = &Ships[objh->objp()->instance];
if(ADE_SETTING_VAR)
{
if(trig)
shipp->flags.set(Ship::Ship_Flags::Trigger_down);
else
shipp->flags.remove(Ship::Ship_Flags::Trigger_down);
}
if (shipp->flags[Ship::Ship_Flags::Trigger_down])
return ADE_RETURN_TRUE;
else
return ADE_RETURN_FALSE;
}
ADE_VIRTVAR(PrimaryBanks, l_Ship, "weaponbanktype", "Array of primary weapon banks", "weaponbanktype", "Primary weapon banks, or invalid weaponbanktype handle if ship handle is invalid")
{
object_h *objh;
ship_banktype_h *swh = nullptr;
if(!ade_get_args(L, "o|o", l_Ship.GetPtr(&objh), l_WeaponBankType.GetPtr(&swh)))
return ade_set_error(L, "o", l_WeaponBankType.Set(ship_banktype_h()));
if(!objh->isValid())
return ade_set_error(L, "o", l_WeaponBankType.Set(ship_banktype_h()));
ship_weapon *dst = &Ships[objh->objp()->instance].weapons;
if(ADE_SETTING_VAR && swh && swh->isValid()) {
ship_weapon *src = &Ships[swh->objh.objp()->instance].weapons;
dst->current_primary_bank = src->current_primary_bank;
dst->num_primary_banks = src->num_primary_banks;
memcpy(dst->next_primary_fire_stamp, src->next_primary_fire_stamp, sizeof(dst->next_primary_fire_stamp));
memcpy(dst->primary_animation_done_time, src->primary_animation_done_time, sizeof(dst->primary_animation_done_time));
memcpy(dst->primary_animation_position, src->primary_animation_position, sizeof(dst->primary_animation_position));
memcpy(dst->primary_bank_ammo, src->primary_bank_ammo, sizeof(dst->primary_bank_ammo));
memcpy(dst->primary_bank_capacity, src->primary_bank_capacity, sizeof(dst->primary_bank_capacity));
memcpy(dst->primary_bank_rearm_time, src->primary_bank_rearm_time, sizeof(dst->primary_bank_rearm_time));
memcpy(dst->primary_bank_start_ammo, src->primary_bank_start_ammo, sizeof(dst->primary_bank_start_ammo));
memcpy(dst->primary_bank_weapons, src->primary_bank_weapons, sizeof(dst->primary_bank_weapons));
}
return ade_set_args(L, "o", l_WeaponBankType.Set(ship_banktype_h(objh->objp(), dst, SWH_PRIMARY)));
}
ADE_VIRTVAR(SecondaryBanks, l_Ship, "weaponbanktype", "Array of secondary weapon banks", "weaponbanktype", "Secondary weapon banks, or invalid weaponbanktype handle if ship handle is invalid")
{
object_h *objh;
ship_banktype_h *swh = nullptr;
if(!ade_get_args(L, "o|o", l_Ship.GetPtr(&objh), l_WeaponBankType.GetPtr(&swh)))
return ade_set_error(L, "o", l_WeaponBankType.Set(ship_banktype_h()));
if(!objh->isValid())
return ade_set_error(L, "o", l_WeaponBankType.Set(ship_banktype_h()));
ship_weapon *dst = &Ships[objh->objp()->instance].weapons;
if(ADE_SETTING_VAR && swh && swh->isValid()) {
ship_weapon *src = &Ships[swh->objh.objp()->instance].weapons;
dst->current_secondary_bank = src->current_secondary_bank;
dst->num_secondary_banks = src->num_secondary_banks;
memcpy(dst->next_secondary_fire_stamp, src->next_secondary_fire_stamp, sizeof(dst->next_secondary_fire_stamp));
memcpy(dst->secondary_animation_done_time, src->secondary_animation_done_time, sizeof(dst->secondary_animation_done_time));
memcpy(dst->secondary_animation_position, src->secondary_animation_position, sizeof(dst->secondary_animation_position));
memcpy(dst->secondary_bank_ammo, src->secondary_bank_ammo, sizeof(dst->secondary_bank_ammo));
memcpy(dst->secondary_bank_capacity, src->secondary_bank_capacity, sizeof(dst->secondary_bank_capacity));
memcpy(dst->secondary_bank_rearm_time, src->secondary_bank_rearm_time, sizeof(dst->secondary_bank_rearm_time));
memcpy(dst->secondary_bank_start_ammo, src->secondary_bank_start_ammo, sizeof(dst->secondary_bank_start_ammo));
memcpy(dst->secondary_bank_weapons, src->secondary_bank_weapons, sizeof(dst->secondary_bank_weapons));
memcpy(dst->secondary_next_slot, src->secondary_next_slot, sizeof(dst->secondary_next_slot));
}
return ade_set_args(L, "o", l_WeaponBankType.Set(ship_banktype_h(objh->objp(), dst, SWH_SECONDARY)));
}
ADE_VIRTVAR(TertiaryBanks, l_Ship, "weaponbanktype", "Array of tertiary weapon banks", "weaponbanktype", "Tertiary weapon banks, or invalid weaponbanktype handle if ship handle is invalid")
{
object_h *objh;
ship_banktype_h *swh = nullptr;
if(!ade_get_args(L, "o|o", l_Ship.GetPtr(&objh), l_WeaponBankType.GetPtr(&swh)))
return ade_set_error(L, "o", l_WeaponBankType.Set(ship_banktype_h()));
if(!objh->isValid())
return ade_set_error(L, "o", l_WeaponBankType.Set(ship_banktype_h()));
ship_weapon *dst = &Ships[objh->objp()->instance].weapons;
if(ADE_SETTING_VAR && swh && swh->isValid()) {
ship_weapon *src = &Ships[swh->objh.objp()->instance].weapons;
dst->current_tertiary_bank = src->current_tertiary_bank;
dst->num_tertiary_banks = src->num_tertiary_banks;
dst->next_tertiary_fire_stamp = src->next_tertiary_fire_stamp;
dst->tertiary_bank_ammo = src->tertiary_bank_ammo;
dst->tertiary_bank_capacity = src->tertiary_bank_capacity;
dst->tertiary_bank_rearm_time = src->tertiary_bank_rearm_time;
dst->tertiary_bank_start_ammo = src->tertiary_bank_start_ammo;
}
return ade_set_args(L, "o", l_WeaponBankType.Set(ship_banktype_h(objh->objp(), dst, SWH_TERTIARY)));
}
ADE_VIRTVAR(Target, l_Ship, "object", "Target of ship. Value may also be a deriviative of the 'object' class, such as 'ship'.", "object", "Target object, or invalid object handle if no target or ship handle is invalid")
{
object_h *objh;
object_h *newh = nullptr;
//WMC - Maybe use two argument return capabilities of Lua to set/return subsystem?
if(!ade_get_args(L, "o|o", l_Ship.GetPtr(&objh), l_Object.GetPtr(&newh)))
return ade_set_error(L, "o", l_Object.Set(object_h()));
if(!objh->isValid())
return ade_set_error(L, "o", l_Object.Set(object_h()));
ai_info *aip = NULL;
if(Ships[objh->objp()->instance].ai_index > -1)
aip = &Ai_info[Ships[objh->objp()->instance].ai_index];
else
return ade_set_error(L, "o", l_Object.Set(object_h()));
if(ADE_SETTING_VAR && !(newh && aip->target_signature == newh->sig)) {
// we have a different target, or are clearng the target
if(newh && newh->isValid()) {
aip->target_objnum = newh->objnum;
aip->target_signature = newh->sig;
aip->target_time = 0.0f;
set_targeted_subsys(aip, nullptr, -1);
if (aip == Player_ai)
hud_shield_hit_reset(newh->objp());
} else if (lua_isnil(L, 2)) {
aip->target_objnum = -1;
aip->target_signature = -1;
aip->target_time = 0.0f;
set_targeted_subsys(aip, nullptr, -1);
}
}
return ade_set_object_with_breed(L, aip->target_objnum);
}
ADE_VIRTVAR(TargetSubsystem, l_Ship, "subsystem", "Target subsystem of ship.", "subsystem", "Target subsystem, or invalid subsystem handle if no target or ship handle is invalid")
{
object_h *oh;
ship_subsys_h *newh = nullptr;
//WMC - Maybe use two argument return capabilities of Lua to set/return subsystem?
if(!ade_get_args(L, "o|o", l_Ship.GetPtr(&oh), l_Subsystem.GetPtr(&newh)))
return ade_set_error(L, "o", l_Subsystem.Set(ship_subsys_h()));
if(!oh->isValid())
return ade_set_error(L, "o", l_Subsystem.Set(ship_subsys_h()));
ai_info *aip = NULL;
if(Ships[oh->objp()->instance].ai_index > -1)
aip = &Ai_info[Ships[oh->objp()->instance].ai_index];
else
return ade_set_error(L, "o", l_Subsystem.Set(ship_subsys_h()));
if(ADE_SETTING_VAR)
{
if(newh && newh->isValid())
{
if (aip == Player_ai) {
if (aip->target_signature != newh->objh.sig)
hud_shield_hit_reset(newh->objh.objp());
Ships[Objects[newh->ss->parent_objnum].instance].last_targeted_subobject[Player_num] = newh->ss;
}
aip->target_objnum = newh->objh.objnum;
aip->target_signature = newh->objh.sig;
aip->target_time = 0.0f;
set_targeted_subsys(aip, newh->ss, aip->target_objnum);
}
else
{
aip->target_objnum = -1;
aip->target_signature = -1;
aip->target_time = 0.0f;
set_targeted_subsys(aip, NULL, -1);
}
}
return ade_set_args(L, "o", l_Subsystem.Set(ship_subsys_h(&Objects[aip->target_objnum], aip->targeted_subsys)));
}
ADE_VIRTVAR(Team, l_Ship, "team", "Ship's team", "team", "Ship team, or invalid team handle if ship handle is invalid")
{
object_h *oh=NULL;
int nt=-1;
if(!ade_get_args(L, "o|o", l_Ship.GetPtr(&oh), l_Team.Get(&nt)))
return ade_set_error(L, "o", l_Team.Set(-1));
if(!oh->isValid())
return ade_set_error(L, "o", l_Team.Set(-1));
ship *shipp = &Ships[oh->objp()->instance];
if(ADE_SETTING_VAR && nt > -1) {
shipp->team = nt;
}
return ade_set_args(L, "o", l_Team.Set(shipp->team));
}
ADE_VIRTVAR(PersonaIndex, l_Ship, "number", "Persona index", "number", "The index of the persona from messages.tbl, 0 if no persona is set")
{
object_h *objh;
int p_index = -1;
if(!ade_get_args(L, "o|i", l_Ship.GetPtr(&objh), &p_index))
return ade_set_error(L, "i", 0);
if(!objh->isValid())
return ade_set_error(L, "i", 0);
ship *shipp = &Ships[objh->objp()->instance];
if(ADE_SETTING_VAR && p_index > 0)
shipp->persona_index = p_index - 1;
return ade_set_args(L, "i", shipp->persona_index + 1);
}
ADE_VIRTVAR(Textures, l_Ship, "modelinstancetextures", "Gets ship textures", "modelinstancetextures", "Ship textures, or invalid shiptextures handle if ship handle is invalid")
{
object_h *sh = nullptr;
object_h *dh;
if(!ade_get_args(L, "o|o", l_Ship.GetPtr(&dh), l_Ship.GetPtr(&sh)))
return ade_set_error(L, "o", l_ModelInstanceTextures.Set(modelinstance_h()));
if(!dh->isValid())
return ade_set_error(L, "o", l_ModelInstanceTextures.Set(modelinstance_h()));
polymodel_instance *dest = model_get_instance(Ships[dh->objp()->instance].model_instance_num);
if(ADE_SETTING_VAR && sh && sh->isValid()) {
polymodel_instance *src = model_get_instance(Ships[sh->objp()->instance].model_instance_num);
if (src->texture_replace != nullptr)
{
dest->texture_replace = std::make_shared<model_texture_replace>(*src->texture_replace);
}
}
return ade_set_args(L, "o", l_ModelInstanceTextures.Set(modelinstance_h(dest)));
}
ADE_VIRTVAR(FlagAffectedByGravity, l_Ship, "boolean", "Checks for the \"affected-by-gravity\" flag", "boolean", "True if flag is set, false if flag is not set and nil on error")
{
object_h *objh=NULL;
bool set = false;
if (!ade_get_args(L, "o|b", l_Ship.GetPtr(&objh), &set))
return ADE_RETURN_NIL;
if (!objh->isValid())
return ADE_RETURN_NIL;
ship *shipp = &Ships[objh->objp()->instance];
if(ADE_SETTING_VAR)
{
shipp->flags.set(Ship::Ship_Flags::Affected_by_gravity, set);
}
if (shipp->flags[Ship::Ship_Flags::Affected_by_gravity])
return ADE_RETURN_TRUE;
else
return ADE_RETURN_FALSE;
}
ADE_VIRTVAR(Disabled, l_Ship, "boolean", "The disabled state of this ship", "boolean", "true if ship is disabled, false otherwise")
{
object_h *objh=NULL;
bool set = false;
if (!ade_get_args(L, "o|b", l_Ship.GetPtr(&objh), &set))
return ADE_RETURN_FALSE;
if (!objh->isValid())
return ADE_RETURN_FALSE;
ship *shipp = &Ships[objh->objp()->instance];
if(ADE_SETTING_VAR)
{
shipp->flags.set(Ship::Ship_Flags::Disabled, set);
if(set)
{
mission_log_add_entry(LOG_SHIP_DISABLED, shipp->ship_name, NULL );
}
else
{
ship_reset_disabled_physics( &Objects[shipp->objnum], shipp->ship_info_index );
}
}
if (shipp->flags[Ship::Ship_Flags::Disabled])
return ADE_RETURN_TRUE;
else
return ADE_RETURN_FALSE;
}
ADE_VIRTVAR(Stealthed, l_Ship, "boolean", "Stealth status of this ship", "boolean", "true if stealthed, false otherwise or on error")
{
object_h *objh=NULL;
bool stealthed = false;
if (!ade_get_args(L, "o|b", l_Ship.GetPtr(&objh), &stealthed))
return ADE_RETURN_FALSE;
if (!objh->isValid())
return ADE_RETURN_FALSE;
ship *shipp = &Ships[objh->objp()->instance];
if(ADE_SETTING_VAR)
{
shipp->flags.set(Ship::Ship_Flags::Stealth, stealthed);
}
if (shipp->flags[Ship::Ship_Flags::Stealth])
return ADE_RETURN_TRUE;
else
return ADE_RETURN_FALSE;
}
ADE_VIRTVAR(HiddenFromSensors, l_Ship, "boolean", "Hidden from sensors status of this ship", "boolean", "true if invisible to hidden from sensors, false otherwise or on error")
{
object_h *objh=NULL;
bool hidden = false;
if (!ade_get_args(L, "o|b", l_Ship.GetPtr(&objh), &hidden))
return ADE_RETURN_FALSE;
if (!objh->isValid())
return ADE_RETURN_FALSE;
ship *shipp = &Ships[objh->objp()->instance];
if(ADE_SETTING_VAR)
{
shipp->flags.set(Ship::Ship_Flags::Hidden_from_sensors, hidden);
}
if (shipp->flags[Ship::Ship_Flags::Hidden_from_sensors])
return ADE_RETURN_TRUE;
else
return ADE_RETURN_FALSE;
}
ADE_VIRTVAR(Gliding, l_Ship, "boolean", "Specifies whether this ship is currently gliding or not.", "boolean", "true if gliding, false otherwise or in case of error")
{
object_h *objh=NULL;
bool gliding = false;
if (!ade_get_args(L, "o|b", l_Ship.GetPtr(&objh), &gliding))
return ADE_RETURN_FALSE;
if (!objh->isValid())
return ADE_RETURN_FALSE;
ship *shipp = &Ships[objh->objp()->instance];
if(ADE_SETTING_VAR)
{
if (Ship_info[shipp->ship_info_index].can_glide)
{
object_set_gliding(&Objects[shipp->objnum], gliding, true);
}
}
if (objh->objp()->phys_info.flags & PF_GLIDING || objh->objp()->phys_info.flags & PF_FORCE_GLIDE)
return ADE_RETURN_TRUE;
else
return ADE_RETURN_FALSE;
}
ADE_VIRTVAR(EtsEngineIndex, l_Ship, "number", "(SET not implemented, see EtsSetIndexes)", "number", "Ships ETS Engine index value, 0 to MAX_ENERGY_INDEX")
{
object_h *objh=NULL;
int ets_idx = 0;
if (!ade_get_args(L, "o|i", l_Ship.GetPtr(&objh), &ets_idx))
return ade_set_error(L, "i", 0);
if (!objh->isValid())
return ade_set_error(L, "i", 0);
if(ADE_SETTING_VAR)
LuaError(L, "Attempted to set incomplete feature: ETS Engine Index (see EtsSetIndexes)");
return ade_set_args(L, "i", Ships[objh->objp()->instance].engine_recharge_index);
}
ADE_VIRTVAR(EtsShieldIndex, l_Ship, "number", "(SET not implemented, see EtsSetIndexes)", "number", "Ships ETS Shield index value, 0 to MAX_ENERGY_INDEX")
{
object_h *objh=NULL;
int ets_idx = 0;
if (!ade_get_args(L, "o|i", l_Ship.GetPtr(&objh), &ets_idx))
return ade_set_error(L, "i", 0);
if (!objh->isValid())
return ade_set_error(L, "i", 0);
if(ADE_SETTING_VAR)
LuaError(L, "Attempted to set incomplete feature: ETS Shield Index (see EtsSetIndexes)");
return ade_set_args(L, "i", Ships[objh->objp()->instance].shield_recharge_index);
}
ADE_VIRTVAR(EtsWeaponIndex, l_Ship, "number", "(SET not implemented, see EtsSetIndexes)", "number", "Ships ETS Weapon index value, 0 to MAX_ENERGY_INDEX")
{
object_h *objh=NULL;
int ets_idx = 0;
if (!ade_get_args(L, "o|i", l_Ship.GetPtr(&objh), &ets_idx))
return ade_set_error(L, "i", 0);
if (!objh->isValid())
return ade_set_error(L, "i", 0);
if(ADE_SETTING_VAR)
LuaError(L, "Attempted to set incomplete feature: ETS Weapon Index (see EtsSetIndexes)");
return ade_set_args(L, "i", Ships[objh->objp()->instance].weapon_recharge_index);
}
ADE_VIRTVAR(Orders, l_Ship, "shiporders", "Array of ship orders", "shiporders", "Ship orders, or invalid handle if ship handle is invalid")
{
object_h *objh = NULL;
object_h *newh = NULL;
if(!ade_get_args(L, "o|o", l_Ship.GetPtr(&objh), l_ShipOrders.GetPtr(&newh)))
return ade_set_error(L, "o", l_ShipOrders.Set(object_h()));
if(!objh->isValid())
return ade_set_error(L, "o", l_ShipOrders.Set(object_h()));;
if(ADE_SETTING_VAR)
{
LuaError(L, "Attempted to use incomplete feature: Ai orders copy. Use giveOrder instead");
}
return ade_set_args(L, "o", l_ShipOrders.Set(object_h(objh->objp())));
}
ADE_VIRTVAR(WaypointSpeedCap, l_Ship, "number", "Waypoint speed cap", "number", "The limit on the ship's speed for traversing waypoints. -1 indicates no speed cap. 0 will be returned if handle is invalid.")
{
object_h* objh;
int speed_cap = -1;
if (!ade_get_args(L, "o|i", l_Ship.GetPtr(&objh), &speed_cap))
return ade_set_error(L, "i", 0);
if (!objh->isValid())
return ade_set_error(L, "i", 0);
ship* shipp = &Ships[objh->objp()->instance];
ai_info* aip = &Ai_info[shipp->ai_index];
if (ADE_SETTING_VAR)
{
// cap speed to range (-1, 32767) to store within int
CLAMP(speed_cap, -1, 32767);
aip->waypoint_speed_cap = speed_cap;
}
return ade_set_args(L, "i", aip->waypoint_speed_cap);
}
template <typename LOC>
static int ship_getset_location_helper(lua_State* L, LOC ship::* field, const char* location_type, const char** location_names, size_t location_names_size)
{
object_h* objh;
const char* s = nullptr;
if (!ade_get_args(L, "o|s", l_Ship.GetPtr(&objh), &s))
return ADE_RETURN_NIL;
if (!objh->isValid())
return ADE_RETURN_NIL;
ship* shipp = &Ships[objh->objp()->instance];
if (ADE_SETTING_VAR && s != nullptr)
{
int location = string_lookup(s, location_names, location_names_size);
if (location < 0)
{
Warning(LOCATION, "%s location '%s' not found.", location_type, s);
return ADE_RETURN_NIL;
}
shipp->*field = static_cast<LOC>(location);
}
return ade_set_args(L, "s", location_names[static_cast<int>(shipp->*field)]);
}
ADE_VIRTVAR(ArrivalLocation, l_Ship, "string", "The ship's arrival location", "string", "Arrival location, or nil if handle is invalid")
{
return ship_getset_location_helper(L, &ship::arrival_location, "Arrival", Arrival_location_names, MAX_ARRIVAL_NAMES);
}
ADE_VIRTVAR(DepartureLocation, l_Ship, "string", "The ship's departure location", "string", "Departure location, or nil if handle is invalid")
{
return ship_getset_location_helper(L, &ship::departure_location, "Departure", Departure_location_names, MAX_DEPARTURE_NAMES);
}
static int ship_getset_anchor_helper(lua_State* L, int ship::* field)
{
object_h* objh;
const char* s = nullptr;
if (!ade_get_args(L, "o|s", l_Ship.GetPtr(&objh), &s))
return ADE_RETURN_NIL;
if (!objh->isValid())
return ADE_RETURN_NIL;
ship* shipp = &Ships[objh->objp()->instance];
if (ADE_SETTING_VAR && s != nullptr)
{
shipp->*field = (stricmp(s, "<no anchor>") == 0) ? -1 : get_parse_name_index(s);
}
return ade_set_args(L, "s", (shipp->*field >= 0) ? Parse_names[shipp->*field].c_str() : "<no anchor>");
}
ADE_VIRTVAR(ArrivalAnchor, l_Ship, "string", "The ship's arrival anchor", "string", "Arrival anchor, or nil if handle is invalid")
{
return ship_getset_anchor_helper(L, &ship::arrival_anchor);
}
ADE_VIRTVAR(DepartureAnchor, l_Ship, "string", "The ship's departure anchor", "string", "Departure anchor, or nil if handle is invalid")
{
return ship_getset_anchor_helper(L, &ship::departure_anchor);
}
ADE_VIRTVAR(ArrivalPathMask, l_Ship, "number", "The ship's arrival path mask", "number", "Arrival path mask, or nil if handle is invalid")
{
return ship_getset_helper(L, &ship::arrival_path_mask, true);
}
ADE_VIRTVAR(DeparturePathMask, l_Ship, "number", "The ship's departure path mask", "number", "Departure path mask, or nil if handle is invalid")
{
return ship_getset_helper(L, &ship::departure_path_mask, true);
}
ADE_VIRTVAR(ArrivalDelay, l_Ship, "number", "The ship's arrival delay", "number", "Arrival delay, or nil if handle is invalid")
{
return ship_getset_helper(L, &ship::arrival_delay, true);
}
ADE_VIRTVAR(DepartureDelay, l_Ship, "number", "The ship's departure delay", "number", "Departure delay, or nil if handle is invalid")
{
return ship_getset_helper(L, &ship::departure_delay, true);
}
ADE_VIRTVAR(ArrivalDistance, l_Ship, "number", "The ship's arrival distance", "number", "Arrival distance, or nil if handle is invalid")
{
return ship_getset_helper(L, &ship::arrival_distance, true);
}
extern int sendMessage_sub(lua_State* L, const void* sender, int messageSource, int messageIdx, float delay, enum_h* ehp);
ADE_FUNC(sendMessage,
l_Ship,
"message message, [number delay=0.0, enumeration priority = MESSAGE_PRIORITY_NORMAL]",
"Sends a message from the given ship with the given priority.<br>"
"If delay is specified, the message will be delayed by the specified time in seconds.",
"boolean",
"true if successful, false otherwise")
{
int messageIdx = -1;
float delay = 0.0f;
object_h* ship_h = nullptr;
enum_h* ehp = nullptr;
if (!ade_get_args(L, "oo|fob", l_Ship.GetPtr(&ship_h), l_Message.Get(&messageIdx), &delay, l_Enum.GetPtr(&ehp)))
return ADE_RETURN_FALSE;
if (ship_h == nullptr || !ship_h->isValid())
return ADE_RETURN_FALSE;
return sendMessage_sub(L, &Ships[ship_h->objp()->instance], MESSAGE_SOURCE_SHIP, messageIdx, delay, ehp);
}
ADE_FUNC(turnTowardsPoint,
l_Ship,
"vector target, [boolean respectDifficulty = true, vector turnrateModifier /* 100% of tabled values in all rotation axes by default */, number bank /* native bank-on-heading by default */ ]",
"turns the ship towards the specified point during this frame",
nullptr,
nullptr)
{
object_h shiph;
vec3d* target;
bool diffTurn = true;
vec3d* modifier = nullptr;
float bank = 0.0f;
int argnum = ade_get_args(L, "oo|bof", l_Ship.Get(&shiph), l_Vector.GetPtr(&target), &diffTurn, l_Vector.GetPtr(&modifier), &bank);
if (argnum == 0) {
return ADE_RETURN_NIL;
}
ai_turn_towards_vector(target, shiph.objp(), nullptr, nullptr, bank, (diffTurn ? 0 : AITTV_FAST) | (argnum >= 5 ? AITTV_FORCE_DELTA_BANK : 0), nullptr, modifier);
return ADE_RETURN_NIL;
}
ADE_FUNC(turnTowardsOrientation,
l_Ship,
"orientation target, [boolean respectDifficulty = true, vector turnrateModifier /* 100% of tabled values in all rotation axes by default */]",
"turns the ship towards the specified orientation during this frame",
nullptr,
nullptr)
{
object_h ship;
matrix_h* target;
bool diffTurn = true;
vec3d* modifier = nullptr;
int argnum = ade_get_args(L, "oo|bo", l_Ship.Get(&ship), l_Matrix.GetPtr(&target), &diffTurn, l_Vector.GetPtr(&modifier));
if (argnum == 0) {
return ADE_RETURN_NIL;
}
matrix* mat = target->GetMatrix();
vec3d targetVec = mat->vec.fvec + ship.objp()->pos;
ai_turn_towards_vector(&targetVec, ship.objp(), nullptr, nullptr, 0.0f, (diffTurn ? 0 : AITTV_FAST), &mat->vec.rvec, modifier);
return ADE_RETURN_NIL;
}
ADE_FUNC(getCenterPosition, l_Ship, nullptr, "Returns the position of the ship's physical center, which may not be the position of the origin of the model", "vector", "World position of the center of the ship, or nil if an error occurred")
{
object_h *shiph;
vec3d center_pos, actual_local_center;
if (!ade_get_args(L, "o", l_Ship.GetPtr(&shiph)))
return ADE_RETURN_NIL;
// find local center
ship_class_get_actual_center(&Ship_info[Ships[shiph->objp()->instance].ship_info_index], &actual_local_center);
// find world position of the center
vm_vec_unrotate(¢er_pos, &actual_local_center, &shiph->objp()->orient);
vm_vec_add2(¢er_pos, &shiph->objp()->pos);
return ade_set_args(L, "o", l_Vector.Set(center_pos));
}
ADE_FUNC(kill, l_Ship, "[object Killer, vector Hitpos]", "Kills the ship. Set \"Killer\" to a ship (or a weapon fired by that ship) to credit it for the kill in the mission log. Set it to the ship being killed to self-destruct. Set \"Hitpos\" to the world coordinates of the weapon impact.", "boolean", "True if successful, false or nil otherwise")
{
object_h *victim, *killer = nullptr;
vec3d *hitpos = nullptr;
if(!ade_get_args(L, "o|oo", l_Ship.GetPtr(&victim), l_Object.GetPtr(&killer), l_Vector.GetPtr(&hitpos)))
return ADE_RETURN_NIL;
if(!victim->isValid())
return ADE_RETURN_NIL;
if(killer && !killer->isValid())
return ADE_RETURN_NIL;
// use the current hull percentage for damage-after-death purposes
// (note that this does not actually affect scoring)
float percent_killed = get_hull_pct(victim->objp());
ship_hit_kill(victim->objp(), killer ? killer->objp() : nullptr, hitpos, percent_killed, (killer && victim->sig == killer->sig), true);
return ADE_RETURN_TRUE;
}
ADE_FUNC(checkVisibility,
l_Ship,
"[ship viewer]",
"checks if a ship can appear on the viewer's radar. If a viewer is not provided it assumes the viewer is the "
"player.\n",
"number",
"Returns 0 - not visible, 1 - partially visible, 2 - fully visible")
{
object_h* v1 = nullptr;
object_h* v2 = nullptr;
if (!ade_get_args(L, "o|o", l_Ship.GetPtr(&v1), l_Ship.GetPtr(&v2)))
return ade_set_error(L, "i", 0);
if (!v1 || !v1->isValid())
return ade_set_error(L, "i", 0);
if (v2 && !v2->isValid())
return ade_set_error(L, "i", 0);
ship* viewer_shipp = nullptr;
ship* viewed_shipp = nullptr;
viewed_shipp = &Ships[v1->objp()->instance];
if (v2)
viewer_shipp = &Ships[v2->objp()->instance];
return ade_set_args(L, "i", ship_check_visibility(viewed_shipp, viewer_shipp));
}
ADE_FUNC(addShipEffect, l_Ship, "string name, number durationMillis", "Activates an effect for this ship. Effect names are defined in Post_processing.tbl, and need to be implemented in the main shader. This functions analogous to the ship-effect sexp. NOTE: only one effect can be active at any time, adding new effects will override effects already in progress.\n", "boolean", "Returns true if the effect was successfully added, false otherwise") {
object_h *shiph;
const char* effect = nullptr;
int duration;
int effect_num;
if (!ade_get_args(L, "o|si", l_Ship.GetPtr(&shiph), &effect, &duration))
return ade_set_error(L, "b", false);
if (!shiph->isValid())
return ade_set_error(L, "b", false);
effect_num = get_effect_from_name(effect);
if (effect_num == -1)
return ade_set_error(L, "b", false);
ship* shipp = &Ships[shiph->objp()->instance];
shipp->shader_effect_num = effect_num;
shipp->shader_effect_duration = duration;
shipp->shader_effect_timestamp = _timestamp(duration);
return ade_set_args(L, "b", true);
}
ADE_FUNC(hasShipExploded, l_Ship, NULL, "Checks if the ship explosion event has already happened", "number", "Returns 1 if first explosion timestamp is passed, 2 if second is passed, 0 otherwise")
{
object_h *shiph;
if(!ade_get_args(L, "o", l_Ship.GetPtr(&shiph)))
return ade_set_error(L, "i", 0);
if(!shiph->isValid())
return ade_set_error(L, "i", 0);
ship *shipp = &Ships[shiph->objp()->instance];
if (shipp->flags[Ship::Ship_Flags::Dying]) {
if (shipp->final_death_time == 0) {
return ade_set_args(L, "i", 2);
}
if (shipp->pre_death_explosion_happened == 1) {
return ade_set_args(L, "i", 1);
}
return ade_set_args(L, "i", 3);
}
return ade_set_args(L, "i", 0);
}
ADE_FUNC(isArrivingWarp, l_Ship, nullptr, "Checks if the ship is arriving via warp. This includes both stage 1 (when the portal is opening) and stage 2 (when the ship is moving through the portal).", "boolean", "True if the ship is warping in, false otherwise")
{
object_h *shiph;
if (!ade_get_args(L, "o", l_Ship.GetPtr(&shiph)))
return ade_set_error(L, "b", false);
if (!shiph->isValid())
return ade_set_error(L, "b", false);
ship *shipp = &Ships[shiph->objp()->instance];
return ade_set_args(L, "b", shipp->is_arriving(ship::warpstage::BOTH, false));
}
ADE_FUNC(isDepartingWarp, l_Ship, nullptr, "Checks if the ship is departing via warp", "boolean", "True if the Depart_warp flag is set, false otherwise")
{
object_h *shiph;
if (!ade_get_args(L, "o", l_Ship.GetPtr(&shiph)))
return ade_set_error(L, "b", false);
if (!shiph->isValid())
return ade_set_error(L, "b", false);
ship *shipp = &Ships[shiph->objp()->instance];
return ade_set_args(L, "b", shipp->flags[Ship::Ship_Flags::Depart_warp]);
}
ADE_FUNC(isDepartingDockbay, l_Ship, nullptr, "Checks if the ship is departing via warp", "boolean", "True if the Depart_dockbay flag is set, false otherwise")
{
object_h *shiph;
if (!ade_get_args(L, "o", l_Ship.GetPtr(&shiph)))
return ade_set_error(L, "b", false);
if (!shiph->isValid())
return ade_set_error(L, "b", false);
ship *shipp = &Ships[shiph->objp()->instance];
return ade_set_args(L, "b", shipp->flags[Ship::Ship_Flags::Depart_dockbay]);
}
ADE_FUNC(isDying, l_Ship, nullptr, "Checks if the ship is dying (doing its death roll or exploding)", "boolean", "True if the Dying flag is set, false otherwise")
{
object_h *shiph;
if (!ade_get_args(L, "o", l_Ship.GetPtr(&shiph)))
return ade_set_error(L, "b", false);
if (!shiph->isValid())
return ade_set_error(L, "b", false);
ship *shipp = &Ships[shiph->objp()->instance];
return ade_set_args(L, "b", shipp->flags[Ship::Ship_Flags::Dying]);
}
ADE_FUNC(fireCountermeasure, l_Ship, NULL, "Launches a countermeasure from the ship", "boolean", "Whether countermeasure was launched or not")
{
object_h *objh;
if(!ade_get_args(L, "o", l_Ship.GetPtr(&objh)))
return ade_set_error(L, "b", false);
if(!objh->isValid())
return ade_set_error(L, "b", false);
return ade_set_args(L, "b", ship_launch_countermeasure(objh->objp()) != 0);
}
ADE_FUNC(firePrimary, l_Ship, NULL, "Fires ship primary bank(s)", "number", "Number of primary banks fired")
{
object_h *objh;
if(!ade_get_args(L, "o", l_Ship.GetPtr(&objh)))
return ade_set_error(L, "i", 0);
if(!objh->isValid())
return ade_set_error(L, "i", 0);
int i = 0;
i += ship_fire_primary(objh->objp());
return ade_set_args(L, "i", i);
}
ADE_FUNC(fireSecondary, l_Ship, NULL, "Fires ship secondary bank(s)", "number", "Number of secondary banks fired")
{
object_h *objh;
if(!ade_get_args(L, "o", l_Ship.GetPtr(&objh)))
return ade_set_error(L, "i", 0);
if(!objh->isValid())
return ade_set_error(L, "i", 0);
return ade_set_args(L, "i", ship_fire_secondary(objh->objp(), 0));
}
ADE_FUNC_DEPRECATED(getAnimationDoneTime, l_Ship, "number Type, number Subtype", "Gets time that animation will be done", "number", "Time (seconds), or 0 if ship handle is invalid",
gameversion::version(22, 0, 0, 0),
"To account for the new animation tables, please use getSubmodelAnimationTime()")
{
object_h *objh;
const char* s = nullptr;
int subtype=-1;
if(!ade_get_args(L, "o|si", l_Ship.GetPtr(&objh), &s, &subtype))
return ade_set_error(L, "f", 0.0f);
if(!objh->isValid())
return ade_set_error(L, "f", 0.0f);
auto type = animation::anim_match_type(s);
if(type == animation::ModelAnimationTriggerType::None)
return ADE_RETURN_FALSE;
int time_ms = Ship_info[Ships[objh->objp()->instance].ship_info_index].animations.getAll(model_get_instance(Ships[objh->objp()->instance].model_instance_num), type, subtype).getTime();
float time_s = (float)time_ms / 1000.0f;
return ade_set_args(L, "f", time_s);
}
ADE_FUNC(clearOrders, l_Ship, NULL, "Clears a ship's orders list", "boolean", "True if successful, otherwise false or nil")
{
object_h *objh = NULL;
if(!ade_get_args(L, "o", l_Object.GetPtr(&objh)))
return ADE_RETURN_NIL;
if(!objh->isValid())
return ade_set_error(L, "b", false);
//The actual clearing of the goals
ai_clear_ship_goals( &Ai_info[Ships[objh->objp()->instance].ai_index]);
return ADE_RETURN_TRUE;
}
ADE_FUNC(giveOrder, l_Ship, "enumeration Order, [object Target=nil, subsystem TargetSubsystem=nil, number Priority=1.0, shipclass TargetShipclass=nil]", "Uses the goal code to execute orders", "boolean", "True if order was given, otherwise false or nil")
{
object_h *objh = NULL;
enum_h *eh = NULL;
float priority = 1.0f;
int sclass = -1;
object_h *tgh = NULL;
ship_subsys_h *tgsh = NULL;
if(!ade_get_args(L, "oo|oofo", l_Object.GetPtr(&objh), l_Enum.GetPtr(&eh), l_Object.GetPtr(&tgh), l_Subsystem.GetPtr(&tgsh), &priority, l_Shipclass.Get(&sclass)))
return ADE_RETURN_NIL;
if(!objh->isValid() || !eh->isValid())
return ade_set_error(L, "b", false);
//wtf...
if(priority < 0.0f)
return ade_set_error(L, "b", false);
if(priority > 2.0f)
priority = 2.0f;
bool tgh_valid = tgh && tgh->isValid();
bool tgsh_valid = tgsh && tgsh->isValid();
int ai_mode = AI_GOAL_NONE;
int ai_submode = -1234567;
const char *ai_shipname = NULL;
switch(eh->index)
{
case LE_ORDER_ATTACK:
{
if(tgsh_valid)
{
ai_mode = AI_GOAL_DESTROY_SUBSYSTEM;
ai_shipname = Ships[tgh->objp()->instance].ship_name;
ai_submode = ship_find_subsys( &Ships[tgsh->objh.objp()->instance], tgsh->ss->system_info->subobj_name );
}
else if(tgh_valid && tgh->objp()->type == OBJ_WEAPON)
{
ai_mode = AI_GOAL_CHASE_WEAPON;
ai_submode = tgh->objp()->instance;
}
else if(tgh_valid && tgh->objp()->type == OBJ_SHIP)
{
ai_mode = AI_GOAL_CHASE;
ai_shipname = Ships[tgh->objp()->instance].ship_name;
ai_submode = SM_ATTACK;
}
break;
}
case LE_ORDER_DOCK:
{
ai_shipname = Ships[tgh->objp()->instance].ship_name;
ai_mode = AI_GOAL_DOCK;
ai_submode = AIS_DOCK_0;
break;
}
case LE_ORDER_WAYPOINTS:
{
if(tgh_valid && tgh->objp()->type == OBJ_WAYPOINT)
{
ai_mode = AI_GOAL_WAYPOINTS;
waypoint_list *wp_list = find_waypoint_list_with_instance(tgh->objp()->instance);
if(wp_list != NULL)
ai_shipname = wp_list->get_name();
}
break;
}
case LE_ORDER_WAYPOINTS_ONCE:
{
if(tgh_valid && tgh->objp()->type == OBJ_WAYPOINT)
{
ai_mode = AI_GOAL_WAYPOINTS_ONCE;
waypoint_list *wp_list = find_waypoint_list_with_instance(tgh->objp()->instance);
if(wp_list != NULL)
ai_shipname = wp_list->get_name();
}
break;
}
case LE_ORDER_DEPART:
{
ai_mode = AI_GOAL_WARP;
ai_submode = -1;
break;
}
case LE_ORDER_FORM_ON_WING:
{
if(tgh_valid && tgh->objp()->type == OBJ_SHIP)
{
ai_mode = AI_GOAL_FORM_ON_WING;
ai_shipname = Ships[tgh->objp()->instance].ship_name;
ai_submode = 0;
}
break;
}
case LE_ORDER_UNDOCK:
{
ai_mode = AI_GOAL_UNDOCK;
ai_submode = AIS_UNDOCK_0;
if(tgh_valid && tgh->objp()->type == OBJ_SHIP)
{
ai_shipname = Ships[tgh->objp()->instance].ship_name;
}
break;
}
case LE_ORDER_GUARD:
{
if(tgh_valid && tgh->objp()->type == OBJ_SHIP)
{
ai_mode = AI_GOAL_GUARD;
ai_submode = AIS_GUARD_PATROL;
ai_shipname = Ships[tgh->objp()->instance].ship_name;
}
break;
}
case LE_ORDER_DISABLE:
case LE_ORDER_DISABLE_TACTICAL:
{
if(tgh_valid && tgh->objp()->type == OBJ_SHIP)
{
ai_mode = (eh->index == LE_ORDER_DISABLE) ? AI_GOAL_DISABLE_SHIP : AI_GOAL_DISABLE_SHIP_TACTICAL;
ai_submode = -SUBSYSTEM_ENGINE;
ai_shipname = Ships[tgh->objp()->instance].ship_name;
}
break;
}
case LE_ORDER_DISARM:
case LE_ORDER_DISARM_TACTICAL:
{
if(tgh_valid && tgh->objp()->type == OBJ_SHIP)
{
ai_mode = (eh->index == LE_ORDER_DISARM) ? AI_GOAL_DISARM_SHIP : AI_GOAL_DISARM_SHIP_TACTICAL;
ai_submode = -SUBSYSTEM_TURRET;
ai_shipname = Ships[tgh->objp()->instance].ship_name;
}
break;
}
case LE_ORDER_ATTACK_ANY:
{
ai_mode = AI_GOAL_CHASE_ANY;
ai_submode = SM_ATTACK;
break;
}
case LE_ORDER_IGNORE:
case LE_ORDER_IGNORE_NEW:
{
if(tgh_valid && tgh->objp()->type == OBJ_SHIP)
{
ai_mode = (eh->index == LE_ORDER_IGNORE) ? AI_GOAL_IGNORE : AI_GOAL_IGNORE_NEW;
ai_submode = 0;
ai_shipname = Ships[tgh->objp()->instance].ship_name;
}
break;
}
case LE_ORDER_EVADE:
{
if(tgh_valid && tgh->objp()->type == OBJ_SHIP)
{
ai_mode = AI_GOAL_EVADE_SHIP;
ai_shipname = Ships[tgh->objp()->instance].ship_name;
}
break;
}
case LE_ORDER_STAY_NEAR:
{
if(tgh_valid && tgh->objp()->type == OBJ_SHIP)
{
ai_mode = AI_GOAL_STAY_NEAR_SHIP;
ai_shipname = Ships[tgh->objp()->instance].ship_name;
ai_submode = -1;
}
break;
}
case LE_ORDER_KEEP_SAFE_DISTANCE:
{
if(tgh_valid && tgh->objp()->type == OBJ_SHIP)
{
ai_mode = AI_GOAL_KEEP_SAFE_DISTANCE;
ai_shipname = Ships[tgh->objp()->instance].ship_name;
ai_submode = -1;
}
break;
}
case LE_ORDER_REARM:
{
if(tgh_valid && tgh->objp()->type == OBJ_SHIP)
{
ai_mode = AI_GOAL_REARM_REPAIR;
ai_shipname = Ships[tgh->objp()->instance].ship_name;
ai_submode = 0;
}
break;
}
case LE_ORDER_STAY_STILL:
{
ai_mode = AI_GOAL_STAY_STILL;
if(tgh_valid && tgh->objp()->type == OBJ_SHIP)
{
ai_shipname = Ships[tgh->objp()->instance].ship_name;
}
break;
}
case LE_ORDER_PLAY_DEAD:
{
ai_mode = AI_GOAL_PLAY_DEAD;
break;
}
case LE_ORDER_PLAY_DEAD_PERSISTENT:
{
ai_mode = AI_GOAL_PLAY_DEAD_PERSISTENT;
break;
}
case LE_ORDER_FLY_TO:
{
if(tgh_valid && tgh->objp()->type == OBJ_SHIP)
{
ai_mode = AI_GOAL_FLY_TO_SHIP;
ai_shipname = Ships[tgh->objp()->instance].ship_name;
ai_submode = 0;
}
break;
}
case LE_ORDER_ATTACK_WING:
{
if(tgh_valid && tgh->objp()->type == OBJ_SHIP)
{
ship *shipp = &Ships[tgh->objp()->instance];
if (shipp->wingnum != -1)
{
ai_mode = AI_GOAL_CHASE_WING;
ai_shipname = Wings[shipp->wingnum].name;
ai_submode = SM_ATTACK;
}
}
break;
}
case LE_ORDER_GUARD_WING:
{
if(tgh_valid && tgh->objp()->type == OBJ_SHIP)
{
ship *shipp = &Ships[tgh->objp()->instance];
if (shipp->wingnum != -1)
{
ai_mode = AI_GOAL_GUARD_WING;
ai_shipname = Wings[shipp->wingnum].name;
ai_submode = AIS_GUARD_STATIC;
}
}
break;
}
case LE_ORDER_ATTACK_SHIP_CLASS:
{
if(sclass >= 0)
{
ai_mode = AI_GOAL_CHASE_SHIP_CLASS;
ai_shipname = Ship_info[sclass].name;
ai_submode = SM_ATTACK;
}
break;
}
default:
return ade_set_error(L, "b", false);
}
//Nothing got set!
if(ai_mode == AI_GOAL_NONE)
return ade_set_error(L, "b", false);
//Fire off the goal
ai_add_ship_goal_scripting(ai_mode, ai_submode, (int)(priority*100.0f), ai_shipname, &Ai_info[Ships[objh->objp()->instance].ai_index]);
return ADE_RETURN_TRUE;
}
ADE_FUNC(doManeuver,
l_Ship,
"number Duration, number Heading, number Pitch, number Bank, boolean ApplyAllRotation, number Vertical, number "
"Sideways, number Forward, boolean ApplyAllMovement, number ManeuverBitfield",
"Sets ship maneuver over the defined time period",
"boolean",
"True if maneuver order was given, otherwise false or nil")
{
object_h *objh;
float heading, pitch, bank, up, sideways, forward;
bool apply_all_rotate = false, apply_all_move = false;
int duration, maneuver_flags = 0;
if(!ade_get_args(L, "oifffbfffb|i", l_Ship.GetPtr(&objh), &duration, &heading, &pitch, &bank, &apply_all_rotate, &up, &sideways, &forward, &apply_all_move, &maneuver_flags))
return ADE_RETURN_NIL;
ship *shipp = &Ships[objh->objp()->instance];
ai_info *aip = &Ai_info[shipp->ai_index];
control_info *cip = &aip->ai_override_ci;
if (!(maneuver_flags & CIF_DONT_OVERRIDE_OLD_MANEUVERS)) {
aip->ai_override_flags.reset();
}
bool applied_rot = false;
bool applied_lat = false;
if (apply_all_rotate) {
aip->ai_override_flags.set(AI::Maneuver_Override_Flags::Full_rot);
cip->heading = heading;
cip->pitch = pitch;
cip->bank = bank;
applied_rot = true;
} else {
if (heading != 0) {
cip->heading = heading;
aip->ai_override_flags.set(AI::Maneuver_Override_Flags::Heading);
applied_rot = true;
}
if (pitch != 0) {
cip->pitch = pitch;
aip->ai_override_flags.set(AI::Maneuver_Override_Flags::Pitch);
applied_rot = true;
}
if (bank != 0) {
cip->bank = bank;
aip->ai_override_flags.set(AI::Maneuver_Override_Flags::Roll);
applied_rot = true;
}
}
if (apply_all_move) {
aip->ai_override_flags.set(AI::Maneuver_Override_Flags::Full_lat);
cip->vertical = up;
cip->sideways = sideways;
cip->forward = forward;
applied_lat = true;
} else {
if (up != 0) {
cip->vertical = up;
aip->ai_override_flags.set(AI::Maneuver_Override_Flags::Up);
applied_lat = true;
}
if (sideways != 0) {
cip->sideways = sideways;
aip->ai_override_flags.set(AI::Maneuver_Override_Flags::Sideways);
applied_lat = true;
}
if (forward != 0) {
cip->forward = forward;
aip->ai_override_flags.set(AI::Maneuver_Override_Flags::Forward);
applied_lat = true;
}
}
// handle infinite timestamps
if (duration >= 2) {
if (applied_rot)
aip->ai_override_rot_timestamp = timestamp(duration);
if (applied_lat)
aip->ai_override_lat_timestamp = timestamp(duration);
}
else {
if (applied_rot) {
aip->ai_override_rot_timestamp = timestamp(10);
aip->ai_override_flags.set(AI::Maneuver_Override_Flags::Rotational_never_expire);
}
if (applied_lat) {
aip->ai_override_lat_timestamp = timestamp(10);
aip->ai_override_flags.set(AI::Maneuver_Override_Flags::Lateral_never_expire);
}
}
if (maneuver_flags & CIF_DONT_BANK_WHEN_TURNING) {
aip->ai_override_flags.set(AI::Maneuver_Override_Flags::Dont_bank_when_turning);
}
if (maneuver_flags & CIF_DONT_CLAMP_MAX_VELOCITY) {
aip->ai_override_flags.set(AI::Maneuver_Override_Flags::Dont_clamp_max_velocity);
}
if (maneuver_flags & CIF_INSTANTANEOUS_ACCELERATION) {
aip->ai_override_flags.set(AI::Maneuver_Override_Flags::Instantaneous_acceleration);
}
return ADE_RETURN_TRUE;
}
ADE_FUNC_DEPRECATED(triggerAnimation, l_Ship, "string Type, [number Subtype, boolean Forwards, boolean Instant]",
"Triggers an animation. Type is the string name of the animation type, "
"Subtype is the subtype number, such as weapon bank #, Forwards and Instant are boolean, defaulting to true & false respectively."
"<br><strong>IMPORTANT: Function is in testing and should not be used with official mod releases</strong>",
"boolean",
"True if successful, false or nil otherwise",
gameversion::version(22, 0, 0, 0),
"To account for the new animation tables, please use triggerSubmodelAnimation()")
{
object_h *objh;
const char* s = nullptr;
bool b = true;
bool instant = false;
int subtype=-1;
if(!ade_get_args(L, "o|sibb", l_Ship.GetPtr(&objh), &s, &subtype, &b, &instant))
return ADE_RETURN_NIL;
if(!objh->isValid())
return ADE_RETURN_NIL;
auto type = animation::anim_match_type(s);
if(type == animation::ModelAnimationTriggerType::None)
return ADE_RETURN_FALSE;
Ship_info[Ships[objh->objp()->instance].ship_info_index].animations.getAll(model_get_instance(Ships[objh->objp()->instance].model_instance_num), type, subtype).start(b ? animation::ModelAnimationDirection::FWD : animation::ModelAnimationDirection::RWD, instant, instant);
return ADE_RETURN_TRUE;
}
ADE_FUNC(triggerSubmodelAnimation, l_Ship, "string type, string triggeredBy, [boolean forwards = true, boolean resetOnStart = false, boolean completeInstant = false, boolean pause = false]",
"Triggers an animation. If used often with the same type / triggeredBy, consider using getSubmodelAnimation for performance reasons. "
"Type is the string name of the animation type, triggeredBy is a closer specification which animation should trigger. See *-anim.tbm specifications. "
"Forwards controls the direction of the animation. ResetOnStart will cause the animation to play from its initial state, as opposed to its current state. CompleteInstant will immediately complete the animation. Pause will instead stop the animation at the current state.",
"boolean",
"True if successful, false or nil otherwise")
{
object_h* objh;
const char* type = nullptr;
const char* trigger = nullptr;
bool forwards = true;
bool forced = false;
bool instant = false;
bool pause = false;
if (!ade_get_args(L, "oss|bbbb", l_Ship.GetPtr(&objh), &type, &trigger, &forwards, &forced, &instant, &pause))
return ADE_RETURN_NIL;
if (!objh->isValid())
return ADE_RETURN_NIL;
auto animtype = animation::anim_match_type(type);
if (animtype == animation::ModelAnimationTriggerType::None)
return ADE_RETURN_FALSE;
ship* shipp = &Ships[objh->objp()->instance];
return Ship_info[shipp->ship_info_index].animations.parseScripted(model_get_instance(shipp->model_instance_num), animtype, trigger).start(forwards ? animation::ModelAnimationDirection::FWD : animation::ModelAnimationDirection::RWD, forced || instant, instant, pause) ? ADE_RETURN_TRUE : ADE_RETURN_FALSE;
}
ADE_FUNC(getSubmodelAnimation, l_Ship, "string type, string triggeredBy",
"Gets an animation handle. Type is the string name of the animation type, triggeredBy is a closer specification which animation should trigger. See *-anim.tbm specifications. ",
"animation_handle",
"The animation handle for the specified animation, nil if invalid arguments.")
{
object_h* objh;
const char* type = nullptr;
const char* trigger = nullptr;
if (!ade_get_args(L, "oss", l_Ship.GetPtr(&objh), &type, &trigger))
return ADE_RETURN_NIL;
if (!objh->isValid())
return ADE_RETURN_NIL;
auto animtype = animation::anim_match_type(type);
if (animtype == animation::ModelAnimationTriggerType::None)
return ade_set_args(L, "o", l_AnimationHandle.Set(animation::ModelAnimationSet::AnimationList{}));
ship* shipp = &Ships[objh->objp()->instance];
return ade_set_args(L, "o", l_AnimationHandle.Set(Ship_info[shipp->ship_info_index].animations.parseScripted(model_get_instance(shipp->model_instance_num), animtype, trigger)));
}
ADE_FUNC(stopLoopingSubmodelAnimation, l_Ship, "string type, string triggeredBy",
"Stops a currently looping animation after it has finished its current loop. If used often with the same type / triggeredBy, consider using getSubmodelAnimation for performance reasons. Type is the string name of the animation type, "
"triggeredBy is a closer specification which animation was triggered. See *-anim.tbm specifications. ",
"boolean",
"True if successful, false or nil otherwise")
{
object_h* objh;
const char* type = nullptr;
const char* trigger = nullptr;
if (!ade_get_args(L, "oss", l_Ship.GetPtr(&objh), &type, &trigger))
return ADE_RETURN_NIL;
if (!objh->isValid())
return ADE_RETURN_NIL;
auto animtype = animation::anim_match_type(type);
if (animtype == animation::ModelAnimationTriggerType::None)
return ADE_RETURN_FALSE;
ship* shipp = &Ships[objh->objp()->instance];
Ship_info[shipp->ship_info_index].animations.parseScripted(model_get_instance(shipp->model_instance_num), animtype, trigger).setFlag(animation::Animation_Instance_Flags::Stop_after_next_loop);
return ADE_RETURN_TRUE;
}
ADE_FUNC(setAnimationSpeed, l_Ship, "string type, string triggeredBy, [number speedMultiplier = 1.0]",
"Sets the speed multiplier at which an animation runs. If used often with the same type / triggeredBy, consider using getSubmodelAnimation for performance reasons. Anything other than 1 will not work in multiplayer. Type is the string name of the animation type, "
"triggeredBy is a closer specification which animation should trigger. See *-anim.tbm specifications.",
nullptr,
nullptr)
{
object_h* objh;
const char* type = nullptr;
const char* trigger = nullptr;
float speed = 1.0f;
if (!ade_get_args(L, "oss|f", l_Ship.GetPtr(&objh), &type, &trigger, &speed))
return ADE_RETURN_NIL;
if (!objh->isValid())
return ADE_RETURN_NIL;
auto animtype = animation::anim_match_type(type);
if (animtype == animation::ModelAnimationTriggerType::None)
return ADE_RETURN_NIL;
ship* shipp = &Ships[objh->objp()->instance];
Ship_info[shipp->ship_info_index].animations.parseScripted(model_get_instance(shipp->model_instance_num), animtype, trigger).setSpeed(speed);
return ADE_RETURN_NIL;
}
ADE_FUNC(getSubmodelAnimationTime, l_Ship, "string type, string triggeredBy", "Gets time that animation will be done. If used often with the same type / triggeredBy, consider using getSubmodelAnimation for performance reasons.", "number", "Time (seconds), or 0 if ship handle is invalid")
{
object_h* objh;
const char* type = nullptr;
const char* trigger = nullptr;
if (!ade_get_args(L, "oss", l_Ship.GetPtr(&objh), &type, &trigger))
return ade_set_error(L, "f", 0.0f);
if (!objh->isValid())
return ade_set_error(L, "f", 0.0f);
auto animtype = animation::anim_match_type(type);
if (animtype == animation::ModelAnimationTriggerType::None)
return ade_set_error(L, "f", 0.0f);
ship* shipp = &Ships[objh->objp()->instance];
int time_ms = Ship_info[shipp->ship_info_index].animations.parseScripted(model_get_instance(shipp->model_instance_num), animtype, trigger).getTime();
float time_s = (float)time_ms / 1000.0f;
return ade_set_args(L, "f", time_s);
}
ADE_FUNC(updateSubmodelMoveable, l_Ship, "string name, table values",
"Updates a moveable animation. Name is the name of the moveable. For what values needs to contain, please refer to the table below, depending on the type of the moveable:"
"Orientation:\r\n"
"\tThree numbers, x, y, z rotation respectively, in degrees\r\n"
"Rotation:\r\n"
"\tThree numbers, x, y, z rotation respectively, in degrees\r\n"
"Axis Rotation:\r\n"
"\tOne number, rotation angle in degrees\r\n"
"Inverse Kinematics:\r\n"
"\tThree required numbers: x, y, z position target relative to base, in 1/100th meters\r\n"
"\tThree optional numbers: x, y, z rotation target relative to base, in degrees\r\n",
"boolean",
"True if successful, false or nil otherwise")
{
object_h* objh;
const char* name = nullptr;
luacpp::LuaTable values;
if (!ade_get_args(L, "ost", l_Ship.GetPtr(&objh), &name, &values))
return ADE_RETURN_NIL;
if (!objh->isValid())
return ADE_RETURN_NIL;
SCP_vector<linb::any> valuesMoveable;
if (values.isValid()) {
for (const auto& object : values) {
if (object.second.is(luacpp::ValueType::NUMBER)) {
// This'll lua-error internally if it's not fed only objects. Additionally, catch the lua exception and then carry on
try {
valuesMoveable.emplace_back(object.second.getValue<int>());
}
catch (const luacpp::LuaException& /*e*/) {
// We were likely fed a float.
// Since we can't actually tell whether that's the case before we try to get the value, and the attempt to get the value is printing a LuaError itself, just eat the exception here and return
return ADE_RETURN_FALSE;
}
}
else {
//This happens on a non-userdata value, i.e. a number
LuaError(L, "Value table contained non-numbers! Aborting...");
return ADE_RETURN_FALSE;
}
}
}
ship* shipp = &Ships[objh->objp()->instance];
return Ship_info[shipp->ship_info_index].animations.updateMoveable(model_get_instance(shipp->model_instance_num), name, valuesMoveable) ? ADE_RETURN_TRUE : ADE_RETURN_FALSE;
}
ADE_FUNC(warpIn, l_Ship, NULL, "Warps ship in", "boolean", "True if successful, or nil if ship handle is invalid")
{
object_h *objh;
if(!ade_get_args(L, "o", l_Ship.GetPtr(&objh)))
return ADE_RETURN_NIL;
if(!objh->isValid())
return ADE_RETURN_NIL;
shipfx_warpin_start(objh->objp());
return ADE_RETURN_TRUE;
}
ADE_FUNC(warpOut, l_Ship, NULL, "Warps ship out", "boolean", "True if successful, or nil if ship handle is invalid")
{
object_h *objh;
if(!ade_get_args(L, "o", l_Ship.GetPtr(&objh)))
return ADE_RETURN_NIL;
if(!objh->isValid())
return ADE_RETURN_NIL;
shipfx_warpout_start(objh->objp());
return ADE_RETURN_TRUE;
}
ADE_FUNC(canWarp, l_Ship, nullptr, "Checks whether ship has a working subspace drive, is allowed to use it, and is not disabled or limited by subsystem strength.", "boolean", "True if successful, or nil if ship handle is invalid")
{
object_h *objh;
if(!ade_get_args(L, "o", l_Ship.GetPtr(&objh)))
return ADE_RETURN_NIL;
if(!objh->isValid())
return ADE_RETURN_NIL;
ship *shipp = &Ships[objh->objp()->instance];
if( ship_can_warp_full_check(shipp) ){
return ADE_RETURN_TRUE;
}
return ADE_RETURN_FALSE;
}
ADE_FUNC(canBayDepart, l_Ship, nullptr, "Checks whether ship has a bay departure location and if its mother ship is present.", "boolean", "True if successful, or nil if ship handle is invalid")
{
object_h *objh;
if(!ade_get_args(L, "o", l_Ship.GetPtr(&objh)))
return ADE_RETURN_NIL;
if(!objh->isValid())
return ADE_RETURN_NIL;
ship *shipp = &Ships[objh->objp()->instance];
if( ship_can_bay_depart(shipp) ){
return ADE_RETURN_TRUE;
}
return ADE_RETURN_FALSE;
}
// Aardwolf's function for finding if a ship should be drawn as blue on the radar/minimap
ADE_FUNC_DEPRECATED(isWarpingIn, l_Ship, NULL, "Checks if ship is in stage 1 of warping in", "boolean", "True if the ship is in stage 1 of warping in; false if not; nil for an invalid handle",
gameversion::version(24, 2, 0, 0),
"This function's name may imply that it tests for the entire warping sequence. To avoid confusion, it has been deprecated in favor of isWarpingStage1.")
{
object_h *objh;
if(!ade_get_args(L, "o", l_Ship.GetPtr(&objh)))
return ADE_RETURN_NIL;
if(!objh->isValid())
return ADE_RETURN_NIL;
ship *shipp = &Ships[objh->objp()->instance];
if(shipp->is_arriving(ship::warpstage::STAGE1, false)){
return ADE_RETURN_TRUE;
}
return ADE_RETURN_FALSE;
}
// This has functionality identical to isWarpingIn
ADE_FUNC(isWarpingStage1, l_Ship, NULL, "Checks if ship is in stage 1 of warping in, which is the stage when the warp portal is opening but before the ship has gone through. During this stage, the ship's radar blip is blue, while the ship itself is invisible, does not collide, and has velocity 0.", "boolean", "True if the ship is in stage 1 of warping in; false if not; nil for an invalid handle")
{
object_h *objh;
if(!ade_get_args(L, "o", l_Ship.GetPtr(&objh)))
return ADE_RETURN_NIL;
if(!objh->isValid())
return ADE_RETURN_NIL;
ship *shipp = &Ships[objh->objp()->instance];
if(shipp->is_arriving(ship::warpstage::STAGE1, false)){
return ADE_RETURN_TRUE;
}
return ADE_RETURN_FALSE;
}
ADE_FUNC(isWarpingStage2, l_Ship, NULL, "Checks if ship is in stage 2 of warping in, which is the stage when it is traversing the warp portal. Stage 2 ends as soon as the ship is completely through the portal and does not include portal closing or ship deceleration.", "boolean", "True if the ship is in stage 2 of warping in; false if not; nil for an invalid handle")
{
object_h *objh;
if(!ade_get_args(L, "o", l_Ship.GetPtr(&objh)))
return ADE_RETURN_NIL;
if(!objh->isValid())
return ADE_RETURN_NIL;
ship *shipp = &Ships[objh->objp()->instance];
if(shipp->is_arriving(ship::warpstage::STAGE2, false)){
return ADE_RETURN_TRUE;
}
return ADE_RETURN_FALSE;
}
ADE_FUNC(getEMP, l_Ship, NULL, "Returns the current emp effect strength acting on the object", "number", "Current EMP effect strength or NIL if object is invalid")
{
object_h *objh = NULL;
object *obj = NULL;
if (!ade_get_args(L, "o", l_Ship.GetPtr(&objh))) {
return ADE_RETURN_NIL;
}
if(!objh->isValid())
return ADE_RETURN_NIL;
obj = objh->objp();
ship *shipp = &Ships[obj->instance];
return ade_set_args(L, "f", shipp->emp_intensity);
}
ADE_FUNC(getTimeUntilExplosion, l_Ship, nullptr, "Returns the time in seconds until the ship explodes (the ship's final_death_time timestamp)", "number", "Time until explosion or -1, if invalid handle or ship isn't exploding")
{
object_h *objh = nullptr;
if (!ade_get_args(L, "o", l_Ship.GetPtr(&objh)))
return ade_set_error(L, "f", -1.0f);
if(!objh->isValid())
return ade_set_error(L, "f", -1.0f);
ship *shipp = &Ships[objh->objp()->instance];
if (!timestamp_valid(shipp->final_death_time))
return ade_set_args(L, "f", -1.0f);
int time_until = timestamp_until(shipp->final_death_time);
return ade_set_args(L, "f", (i2fl(time_until) / 1000.0f));
}
ADE_FUNC(setTimeUntilExplosion, l_Ship, "number Time", "Sets the time in seconds until the ship explodes (the ship's final_death_time timestamp). This function will only work if the ship is in its death roll but hasn't exploded yet, which can be checked via isDying() or getTimeUntilExplosion().", "boolean", "True if successful, false if the ship is invalid or not currently exploding")
{
object_h *objh = nullptr;
float delta_s;
if (!ade_get_args(L, "of", l_Ship.GetPtr(&objh), &delta_s))
return ade_set_error(L, "b", false);
if (!objh->isValid())
return ade_set_error(L, "b", false);
ship *shipp = &Ships[objh->objp()->instance];
if (!timestamp_valid(shipp->final_death_time))
return ade_set_args(L, "b", false);
int delta_ms = fl2i(delta_s * 1000.0f);
if (delta_ms < 2)
delta_ms = 2;
shipp->final_death_time = timestamp(delta_ms);
return ade_set_args(L, "b", true);
}
ADE_FUNC(getCallsign, l_Ship, NULL, "Gets the callsign of the ship in the current mission", "string", "The callsign or an empty string if the ship doesn't have a callsign or an error occurs")
{
object_h *objh = NULL;
if (!ade_get_args(L, "o", l_Ship.GetPtr(&objh))) {
return ade_set_error(L, "s", "");
}
if(!objh->isValid())
return ade_set_error(L, "s", "");
ship *shipp = &Ships[objh->objp()->instance];
if (shipp->callsign_index < 0)
return ade_set_args(L, "s", "");
char temp_callsign[NAME_LENGTH];
*temp_callsign = 0;
strcpy(temp_callsign, mission_parse_lookup_callsign_index(shipp->callsign_index));
if (*temp_callsign)
return ade_set_args(L, "s", temp_callsign);
else
return ade_set_args(L, "s", "");
}
ADE_FUNC(getAltClassName, l_Ship, NULL, "Gets the alternate class name of the ship", "string", "The alternate class name or an empty string if the ship doesn't have such a thing or an error occurs")
{
object_h *objh = NULL;
if (!ade_get_args(L, "o", l_Ship.GetPtr(&objh))) {
return ade_set_error(L, "s", "");
}
if(!objh->isValid())
return ade_set_error(L, "s", "");
ship *shipp = &Ships[objh->objp()->instance];
if (shipp->alt_type_index < 0)
return ade_set_args(L, "s", "");
char temp_altname[NAME_LENGTH];
strcpy_s(temp_altname, mission_parse_lookup_alt_index(shipp->alt_type_index));
if (*temp_altname)
return ade_set_args(L, "s", temp_altname);
else
return ade_set_args(L, "s", "");
}
ADE_FUNC(getMaximumSpeed, l_Ship, "[number energy = 0.333]", "Gets the maximum speed of the ship with the given energy on the engines", "number", "The maximum speed or -1 on error")
{
object_h *objh = NULL;
float energy = 0.333f;
if (!ade_get_args(L, "o|f", l_Ship.GetPtr(&objh), &energy)) {
return ade_set_error(L, "f", -1.0f);
}
if(!objh->isValid())
return ade_set_error(L, "f", -1.0f);
if (energy < 0.0f || energy > 1.0f)
{
LuaError(L, "Invalid energy level %f! Needs to be in [0, 1].", energy);
return ade_set_args(L, "f", -1.0f);
}
else
{
return ade_set_args(L, "f", ets_get_max_speed(objh->objp(), energy));
}
}
ADE_FUNC(EtsSetIndexes, l_Ship, "number EngineIndex, number ShieldIndex, number WeaponIndex",
"Sets ships ETS systems to specified values",
"boolean",
"True if successful, false if target ships ETS was missing, or only has one system")
{
object_h *objh=NULL;
int ets_idx[num_retail_ets_gauges] = {0};
if (!ade_get_args(L, "oiii", l_Ship.GetPtr(&objh), &ets_idx[ENGINES], &ets_idx[SHIELDS], &ets_idx[WEAPONS]))
return ADE_RETURN_FALSE;
if (!objh->isValid())
return ADE_RETURN_FALSE;
sanity_check_ets_inputs(ets_idx);
int sindex = objh->objp()->instance;
if (validate_ship_ets_indxes(sindex, ets_idx)) {
set_recharge_rates(objh->objp(), ets_idx[SHIELDS], ets_idx[WEAPONS], ets_idx[ENGINES]);
return ADE_RETURN_TRUE;
} else {
return ADE_RETURN_FALSE;
}
}
ADE_FUNC(getParsedShip, l_Ship, nullptr, "Returns the parsed ship that was used to create this ship, if any", "parse_object", "The parsed ship, an invalid handle if no parsed ship exists, or nil if the current handle is invalid")
{
object_h *objh = nullptr;
if (!ade_get_args(L, "o", l_Ship.GetPtr(&objh)))
return ade_set_error(L, "o", l_ParseObject.Set(parse_object_h(nullptr)));
if(!objh->isValid())
return ade_set_error(L, "o", l_ParseObject.Set(parse_object_h(nullptr)));
auto shipp = &Ships[objh->objp()->instance];
auto ship_entry = ship_registry_get(shipp->ship_name);
if (!ship_entry || !ship_entry->has_p_objp())
return ade_set_args(L, "o", l_ParseObject.Set(parse_object_h(nullptr)));
return ade_set_args(L, "o", l_ParseObject.Set(parse_object_h(ship_entry->p_objp())));
}
ADE_FUNC(getWing, l_Ship, NULL, "Returns the ship's wing", "wing", "Wing handle, or invalid wing handle if ship is not part of a wing")
{
object_h *objh = NULL;
ship *shipp = NULL;
if (!ade_get_args(L, "o", l_Ship.GetPtr(&objh)))
return ade_set_error(L, "o", l_Wing.Set(-1));
if(!objh->isValid())
return ade_set_error(L, "o", l_Wing.Set(-1));
shipp = &Ships[objh->objp()->instance];
return ade_set_args(L, "o", l_Wing.Set(shipp->wingnum));
}
ADE_FUNC(getDisplayString, l_Ship, nullptr, "Returns the string which should be used when displaying the name of the ship to the player", "string", "The display string or empty if handle is invalid")
{
object_h *objh = nullptr;
ship *shipp = nullptr;
if (!ade_get_args(L, "o", l_Ship.GetPtr(&objh)))
return ade_set_error(L, "s", "");
if(!objh->isValid())
return ade_set_error(L, "s", "");
shipp = &Ships[objh->objp()->instance];
return ade_set_args(L, "s", shipp->get_display_name());
}
ADE_FUNC(vanish, l_Ship, nullptr, "Vanishes this ship from the mission. Works in Singleplayer only and will cause the ship exit to not be logged.", "boolean", "True if the deletion was successful, false otherwise.")
{
object_h* objh = nullptr;
if (!ade_get_args(L, "o", l_Ship.GetPtr(&objh)))
return ade_set_error(L, "b", false);
if (!objh->isValid())
return ade_set_error(L, "b", false);
ship_actually_depart(objh->objp()->instance, SHIP_VANISHED);
return ade_set_args(L, "b", true);
}
ADE_FUNC(setGlowPointBankActive, l_Ship, "boolean active, [number bank]", "Activates or deactivates one or more of a ship's glow point banks - this function can accept an arbitrary number of bank arguments. Omit the bank number or specify -1 to activate or deactivate all banks.", nullptr, "Returns nothing")
{
object_h* objh = nullptr;
bool active, at_least_one = false, do_all = false;
int bank_num;
if (!ade_get_args(L, "ob", l_Ship.GetPtr(&objh), &active))
return ADE_RETURN_NIL;
int skip_args = 1; // not 2 because there will be one more before we read the first number
if (!objh->isValid())
return ADE_RETURN_NIL;
auto shipp = &Ships[objh->objp()->instance];
// read as many bank numbers as we have
while (internal::Ade_get_args_skip = ++skip_args, ade_get_args(L, "|i", &bank_num) > 0)
{
if (bank_num < 0)
{
do_all = true;
break;
}
at_least_one = true;
if (static_cast<size_t>(bank_num) < shipp->glow_point_bank_active.size())
shipp->glow_point_bank_active[bank_num] = active;
}
// set all banks
if (!at_least_one || do_all)
{
for (size_t i = 0; i < shipp->glow_point_bank_active.size(); ++i)
shipp->glow_point_bank_active[i] = active;
}
return ADE_RETURN_NIL;
}
ADE_FUNC(numDocked, l_Ship, nullptr, "Returns the number of ships this ship is directly docked with", "number", "The number of ships")
{
object_h *docker_objh = nullptr;
if (!ade_get_args(L, "o", l_Ship.GetPtr(&docker_objh)))
return ADE_RETURN_NIL;
if (docker_objh == nullptr || !docker_objh->isValid())
return ADE_RETURN_NIL;
return ade_set_args(L, "i", dock_count_direct_docked_objects(docker_objh->objp()));
}
ADE_FUNC(isDocked, l_Ship, "[ship... dockee_ships]", "Returns whether this ship is docked to all of the specified dockee ships, or is docked at all if no ships are specified", "boolean", "Returns whether the ship is docked")
{
bool found_arg = false;
int skip_args = 1;
object_h *docker_objh = nullptr, *dockee_objh = nullptr;
if (!ade_get_args(L, "o", l_Ship.GetPtr(&docker_objh)))
return ADE_RETURN_NIL;
if (docker_objh == nullptr || !docker_objh->isValid())
return ADE_RETURN_NIL;
while (true)
{
// read the next ship
internal::Ade_get_args_skip = skip_args++;
if (ade_get_args(L, "|o", l_Ship.GetPtr(&dockee_objh)) == 0)
break;
found_arg = true;
// make sure ship exists
if (dockee_objh == nullptr || !dockee_objh->isValid())
continue;
// see if we are docked to it
if (!dock_check_find_direct_docked_object(docker_objh->objp(), dockee_objh->objp()))
return ADE_RETURN_FALSE;
}
// all ships passed
if (found_arg)
return ADE_RETURN_TRUE;
// if we didn't find any specified ships, then see if we are docked at all
return object_is_docked(docker_objh->objp()) ? ADE_RETURN_TRUE : ADE_RETURN_FALSE;
}
ADE_FUNC(setDocked, l_Ship, "ship dockee_ship, [string | number docker_point, string | number dockee_point]", "Immediately docks this ship with another ship.", "boolean", "Returns whether the docking was successful, or nil if an input was invalid")
{
object_h *docker_objh = nullptr, *dockee_objh = nullptr;
int docker_point = -1, dockee_point = -1;
if (!ade_get_args(L, "oo", l_Ship.GetPtr(&docker_objh), l_Ship.GetPtr(&dockee_objh)))
return ADE_RETURN_NIL;
if (docker_objh == nullptr || dockee_objh == nullptr || !docker_objh->isValid() || !dockee_objh->isValid())
return ADE_RETURN_NIL;
// cannot dock an object to itself
if (docker_objh->objp()->instance == dockee_objh->objp()->instance)
return ADE_RETURN_FALSE;
auto docker_shipp = &Ships[docker_objh->objp()->instance];
auto dockee_shipp = &Ships[dockee_objh->objp()->instance];
auto docker_pm = model_get(Ship_info[docker_shipp->ship_info_index].model_num);
auto dockee_pm = model_get(Ship_info[dockee_shipp->ship_info_index].model_num);
if (lua_isnumber(L, 3))
{
ade_get_args(L, "**i", &docker_point);
docker_point--; // Lua --> C/C++
}
else if (lua_isstring(L, 3))
{
const char *name = nullptr;
ade_get_args(L, "**s", &name);
docker_point = model_find_dock_name_index(Ship_info[docker_shipp->ship_info_index].model_num, name);
}
else
{
docker_point = 0;
}
if (lua_isnumber(L, 4))
{
ade_get_args(L, "***i", &dockee_point);
dockee_point--; // Lua --> C/C++
}
else if (lua_isstring(L, 4))
{
const char* name = nullptr;
ade_get_args(L, "***s", &name);
dockee_point = model_find_dock_name_index(Ship_info[dockee_shipp->ship_info_index].model_num, name);
}
else
{
dockee_point = 0;
}
if (docker_point < 0 || docker_point >= docker_pm->n_docks)
{
Warning(LOCATION, "Invalid docker point specified for ship '%s'", docker_shipp->ship_name);
return ADE_RETURN_NIL;
}
if (dockee_point < 0 || dockee_point >= dockee_pm->n_docks)
{
Warning(LOCATION, "Invalid dockee point specified for ship '%s'", dockee_shipp->ship_name);
return ADE_RETURN_NIL;
}
//Make sure that the specified dockpoints are all free (if not, do nothing)
if (dock_find_object_at_dockpoint(docker_objh->objp(), docker_point) != nullptr ||
dock_find_object_at_dockpoint(dockee_objh->objp(), dockee_point) != nullptr)
{
// at least one of the specified dockpoints is occupied
return ADE_RETURN_FALSE;
}
//Set docked
dock_orient_and_approach(docker_objh->objp(), docker_point, dockee_objh->objp(), dockee_point, DOA_DOCK_STAY);
ai_do_objects_docked_stuff(docker_objh->objp(), docker_point, dockee_objh->objp(), dockee_point, true);
return ADE_RETURN_TRUE;
}
static int jettison_helper(lua_State *L, object_h *docker_objh, float jettison_speed, int skip_args)
{
object_h *dockee_objh = nullptr;
bool found_arg = false;
int num_ships_undocked = 0;
while (true)
{
// read the next ship
internal::Ade_get_args_skip = skip_args++;
if (ade_get_args(L, "|o", l_Ship.GetPtr(&dockee_objh)) == 0)
break;
found_arg = true;
// make sure ship exists
if (dockee_objh == nullptr || !dockee_objh->isValid())
continue;
// make sure we are docked to it
if (!dock_check_find_direct_docked_object(docker_objh->objp(), dockee_objh->objp()))
continue;
object_jettison_cargo(docker_objh->objp(), dockee_objh->objp(), jettison_speed, true);
num_ships_undocked++;
}
// if we didn't find any specified ships, then we need to jettison all of them
if (!found_arg)
{
// Goober5000 - as with ai_deathroll_start, we can't simply iterate through the dock list while we're
// undocking things. So just repeatedly jettison the first object.
while (object_is_docked(docker_objh->objp()))
{
object_jettison_cargo(docker_objh->objp(), dock_get_first_docked_object(docker_objh->objp()), jettison_speed, true);
num_ships_undocked++;
}
}
return ade_set_args(L, "i", num_ships_undocked);
}
ADE_FUNC(setUndocked, l_Ship, "[ship... dockee_ships /* All docked ships by default */]", "Immediately undocks one or more dockee ships from this ship.", "number", "Returns the number of ships undocked")
{
object_h *docker_objh = nullptr;
if (!ade_get_args(L, "o", l_Ship.GetPtr(&docker_objh)))
return ADE_RETURN_NIL;
if (docker_objh == nullptr || !docker_objh->isValid())
return ADE_RETURN_NIL;
return jettison_helper(L, docker_objh, 0.0f, 1);
}
ADE_FUNC(jettison, l_Ship, "number jettison_speed, [ship... dockee_ships /* All docked ships by default */]", "Jettisons one or more dockee ships from this ship at the specified speed.", "number", "Returns the number of ships jettisoned")
{
object_h *docker_objh = nullptr;
float jettison_speed = 0.0f;
if (!ade_get_args(L, "of", l_Ship.GetPtr(&docker_objh), &jettison_speed))
return ADE_RETURN_NIL;
if (docker_objh == nullptr || !docker_objh->isValid())
return ADE_RETURN_NIL;
return jettison_helper(L, docker_objh, jettison_speed, 2);
}
ADE_FUNC(AddElectricArc, l_Ship, "vector firstPoint, vector secondPoint, number duration, number width",
"Creates an electric arc on the ship between two points in the ship's reference frame, for the specified duration in seconds, and the specified width in meters.",
"number",
"The arc index if successful, 0 otherwise")
{
object_h* objh = nullptr;
vec3d* v1;
vec3d* v2;
float duration = 0.0f;
float width = 0.0f;
if (!ade_get_args(L, "oooff", l_Ship.GetPtr(&objh), l_Vector.GetPtr(&v1), l_Vector.GetPtr(&v2), &duration, &width))
return ade_set_error(L, "i", 0);
if (!objh->isValid())
return ade_set_error(L, "i", 0);
auto shipp = &Ships[objh->objp()->instance];
// spawn the arc in the first unused slot
for (int i = 0; i < MAX_ARC_EFFECTS; i++) {
if (!shipp->arc_timestamp[i].isValid()) {
shipp->arc_timestamp[i] = _timestamp(fl2i(duration * MILLISECONDS_PER_SECOND));
shipp->arc_pts[i][0] = *v1;
shipp->arc_pts[i][1] = *v2;
//Set the arc colors
shipp->arc_primary_color_1[i] = Arc_color_damage_p1;
shipp->arc_primary_color_2[i] = Arc_color_damage_p2;
shipp->arc_secondary_color[i] = Arc_color_damage_s1;
shipp->arc_type[i] = MARC_TYPE_SCRIPTED;
shipp->arc_width[i] = width;
return ade_set_args(L, "i", i + 1); // FS2 -> Lua
}
}
return ade_set_args(L, "i", 0);
}
ADE_FUNC(DeleteElectricArc, l_Ship, "number index",
"Removes the specified electric arc from the ship.",
nullptr,
nullptr)
{
object_h* objh = nullptr;
int index;
if (!ade_get_args(L, "oi", l_Ship.GetPtr(&objh), &index))
return ADE_RETURN_NIL;
if (!objh->isValid())
return ADE_RETURN_NIL;
auto shipp = &Ships[objh->objp()->instance];
index--; // Lua -> FS2
if (index >= 0 && index < MAX_ARC_EFFECTS)
{
shipp->arc_timestamp[index] = TIMESTAMP::invalid();
}
return ADE_RETURN_NIL;
}
ADE_FUNC(ModifyElectricArc, l_Ship, "number index, vector firstPoint, vector secondPoint, [number width]",
"Sets the endpoints (in the ship's reference frame) and width of the specified electric arc on the ship, .",
nullptr,
nullptr)
{
object_h* objh = nullptr;
int index;
vec3d* v1;
vec3d* v2;
float width = 0.0f;
int args = ade_get_args(L, "oioo|f", l_Ship.GetPtr(&objh), &index, l_Vector.GetPtr(&v1), l_Vector.GetPtr(&v2), &width);
if (args < 4)
return ADE_RETURN_NIL;
if (!objh->isValid())
return ADE_RETURN_NIL;
auto shipp = &Ships[objh->objp()->instance];
index--; // Lua -> FS2
if (index >= 0 && index < MAX_ARC_EFFECTS)
{
shipp->arc_pts[index][0] = *v1;
shipp->arc_pts[index][1] = *v2;
if (args == 5)
shipp->arc_width[index] = width;
}
return ADE_RETURN_NIL;
}
}
}
|