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
|
/*
===========================================================================
Copyright (C) 2025 the OpenMoHAA team
This file is part of OpenMoHAA source code.
OpenMoHAA source code is free software; you can redistribute it
and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the License,
or (at your option) any later version.
OpenMoHAA source code is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OpenMoHAA source code; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
===========================================================================
*/
// scriptslave.cpp: Standard scripted objects. Controlled by ScriptThread. These objects
// are bmodel objects created in the editor and controlled by an external
// text based script. Commands are interpretted on by one and executed
// upon a signal from the script master. The base script object can
// perform several different relative and specific rotations and translations
// and can cause other parts of the script to be executed when touched, damaged,
// touched, or used.
//
#include "g_local.h"
#include "g_phys.h"
#include "class.h"
#include "mover.h"
#include "scriptmaster.h"
#include "scriptthread.h"
#include "scriptslave.h"
#include "scriptexception.h"
#include "sentient.h"
#include "weapon.h"
#include "gibs.h"
#include "explosion.h"
#include "game.h"
#include "debuglines.h"
#include "weaputils.h"
#include "parm.h"
/*****************************************************************************/
/*QUAKED script_object (0 0.5 1) ? NOT_SOLID
******************************************************************************/
Event EV_ScriptSlave_DoMove
(
"move",
EV_DEFAULT,
NULL,
NULL,
"Move the script slave.",
EV_NORMAL
);
Event EV_ScriptSlave_WaitMove
(
"waitmove",
EV_DEFAULT,
NULL,
NULL,
"Move the script slave and wait until finished.",
EV_NORMAL
);
Event EV_ScriptSlave_Stop
(
"stop",
EV_DEFAULT,
NULL,
NULL,
"Stop the script slave."
);
Event EV_ScriptSlave_ThreadMove
(
"threadmove",
EV_DEFAULT,
"s",
"label",
"Move the script slave and create thread which waits until finished."
);
Event EV_ScriptSlave_Angles
(
"angles",
EV_DEFAULT,
"v",
"angles",
"Sets the angles.",
EV_NORMAL
);
Event EV_ScriptSlave_Trigger
(
"trigger",
EV_DEFAULT,
"e",
"ent",
"Trigger entities target.",
EV_NORMAL
);
Event EV_ScriptSlave_Next
(
"next",
EV_DEFAULT,
NULL,
NULL,
"Goto the next waypoint.",
EV_NORMAL
);
Event EV_ScriptSlave_JumpTo
(
"jumpto",
EV_DEFAULT,
"s",
"vector_or_entity",
"Jump to specified vector or entity.",
EV_NORMAL
);
Event EV_ScriptSlave_MoveTo
(
"moveto",
EV_DEFAULT,
"s",
"vector_or_entity",
"Move to the specified vector or entity.",
EV_NORMAL
);
Event EV_ScriptSlave_Speed
(
"speed",
EV_DEFAULT,
"f",
"speed",
"Sets the speed.",
EV_NORMAL
);
Event EV_ScriptSlave_Time
(
"time",
EV_DEFAULT,
"f",
"travel_time",
"Sets the travel time.",
EV_NORMAL
);
Event EV_ScriptSlave_MoveUp
(
"moveUp",
EV_DEFAULT,
"f",
"dist",
"Move the position up.",
EV_NORMAL
);
Event EV_ScriptSlave_MoveDown
(
"moveDown",
EV_DEFAULT,
"f",
"dist",
"Move the position down.",
EV_NORMAL
);
Event EV_ScriptSlave_MoveNorth
(
"moveNorth",
EV_DEFAULT,
"f",
"dist",
"Move the position north.",
EV_NORMAL
);
Event EV_ScriptSlave_MoveSouth
(
"moveSouth",
EV_DEFAULT,
"f",
"dist",
"Move the position south.",
EV_NORMAL
);
Event EV_ScriptSlave_MoveEast
(
"moveEast",
EV_DEFAULT,
"f",
"dist",
"Move the position east.",
EV_NORMAL
);
Event EV_ScriptSlave_MoveWest
(
"moveWest",
EV_DEFAULT,
"f",
"dist",
"Move the position west.",
EV_NORMAL
);
Event EV_ScriptSlave_MoveForward
(
"moveForward",
EV_DEFAULT,
"f",
"dist",
"Move the position forward.",
EV_NORMAL
);
Event EV_ScriptSlave_MoveBackward
(
"moveBackward",
EV_DEFAULT,
"f",
"dist",
"Move the position backward.",
EV_NORMAL
);
Event EV_ScriptSlave_MoveLeft
(
"moveLeft",
EV_DEFAULT,
"f",
"dist",
"Move the position left.",
EV_NORMAL
);
Event EV_ScriptSlave_MoveRight
(
"moveRight",
EV_DEFAULT,
"f",
"dist",
"Move the position right.",
EV_NORMAL
);
Event EV_ScriptSlave_MoveOffset
(
"moveOffset",
EV_DEFAULT,
"v",
"dist",
"Move the position by the offset vector.",
EV_NORMAL
);
Event EV_ScriptSlave_RotateXDownTo
(
"rotateXdownto",
EV_DEFAULT,
"f",
"angle",
"Rotate the x down to angle.",
EV_NORMAL
);
Event EV_ScriptSlave_RotateYDownTo
(
"rotateYdownto",
EV_DEFAULT,
"f",
"angle",
"Rotate the y down to angle.",
EV_NORMAL
);
Event EV_ScriptSlave_RotateZDownTo
(
"rotateZdownto",
EV_DEFAULT,
"f",
"angle",
"Rotate the z down to angle.",
EV_NORMAL
);
Event EV_ScriptSlave_RotateAxisDownTo
(
"rotateaxisdownto",
EV_DEFAULT,
"if",
"axis angle",
"Rotate the specified axis down to angle.",
EV_NORMAL
);
Event EV_ScriptSlave_RotateXUpTo
(
"rotateXupto",
EV_DEFAULT,
"f",
"angle",
"Rotate the x up to angle.",
EV_NORMAL
);
Event EV_ScriptSlave_RotateYUpTo
(
"rotateYupto",
EV_DEFAULT,
"f",
"angle",
"Rotate the y up to angle.",
EV_NORMAL
);
Event EV_ScriptSlave_RotateZUpTo
(
"rotateZupto",
EV_DEFAULT,
"f",
"angle",
"Rotate the z up to angle.",
EV_NORMAL
);
Event EV_ScriptSlave_RotateAxisUpTo
(
"rotateaxisupto",
EV_DEFAULT,
"if",
"axis angle",
"Rotate the specified axis up to angle.",
EV_NORMAL
);
Event EV_ScriptSlave_RotateXDown
(
"rotateXdown",
EV_DEFAULT,
"f",
"angle",
"Rotate the x down by the specified amount.",
EV_NORMAL
);
Event EV_ScriptSlave_RotateYDown
(
"rotateYdown",
EV_DEFAULT,
"f",
"angle",
"Rotate the y down by the specified amount.",
EV_NORMAL
);
Event EV_ScriptSlave_RotateZDown
(
"rotateZdown",
EV_DEFAULT,
"f",
"angle",
"Rotate the z down by the specified amount.",
EV_NORMAL
);
Event EV_ScriptSlave_RotateAxisDown
(
"rotateaxisdown",
EV_DEFAULT,
"if",
"axis angle",
"Rotate the specified axis down by the specified amount.",
EV_NORMAL
);
Event EV_ScriptSlave_RotateXUp
(
"rotateXup",
EV_DEFAULT,
"f",
"angle",
"Rotate the x up by the specified amount.",
EV_NORMAL
);
Event EV_ScriptSlave_RotateYUp
(
"rotateYup",
EV_DEFAULT,
"f",
"angle",
"Rotate the y up by the specified amount.",
EV_NORMAL
);
Event EV_ScriptSlave_RotateZUp
(
"rotateZup",
EV_DEFAULT,
"f",
"angle",
"Rotate the z up by the specified amount.",
EV_NORMAL
);
Event EV_ScriptSlave_RotateAxisUp
(
"rotateaxisup",
EV_DEFAULT,
"if",
"axis angle",
"Rotate the specified axis up by the specified amount.",
EV_NORMAL
);
Event EV_ScriptSlave_RotateX
(
"rotateX",
EV_DEFAULT,
"f",
"avelocity",
"Rotate about the x axis at the specified angular velocity.",
EV_NORMAL
);
Event EV_ScriptSlave_RotateY
(
"rotateY",
EV_DEFAULT,
"f",
"avelocity",
"Rotate about the y axis at the specified angular velocity.",
EV_NORMAL
);
Event EV_ScriptSlave_RotateZ
(
"rotateZ",
EV_DEFAULT,
"f",
"avelocity",
"Rotate about the z axis at the specified angular velocity.",
EV_NORMAL
);
Event EV_ScriptSlave_RotateAxis
(
"rotateaxis",
EV_DEFAULT,
"if",
"axis avelocity",
"Rotate about the specified axis at the specified angular velocity.",
EV_NORMAL
);
Event EV_ScriptSlave_RotateDownTo
(
"rotatedownto",
EV_DEFAULT,
"v",
"direction",
"Rotate down to the specified direction.",
EV_NORMAL
);
Event EV_ScriptSlave_RotateUpTo
(
"rotateupto",
EV_DEFAULT,
"v",
"direction",
"Rotate up to the specified direction.",
EV_NORMAL
);
Event EV_ScriptSlave_RotateTo
(
"rotateto",
EV_DEFAULT,
"v",
"direction",
"Rotate to the specified direction.",
EV_NORMAL
);
Event EV_ScriptSlave_SetDamage
(
"setdamage",
EV_DEFAULT,
"i",
"damage",
"Set the damage.",
EV_NORMAL
);
Event EV_ScriptSlave_SetMeansOfDeath
(
"setmeansofdeath",
EV_DEFAULT,
"s",
"means_of_death",
"Set the damage means of death.",
EV_NORMAL
);
Event EV_ScriptSlave_SetDamageSpawn
(
"dmg",
EV_DEFAULT,
"i",
"damage",
"Set the damage.",
EV_NORMAL
);
Event EV_ScriptSlave_FollowPath
(
"followpath",
EV_DEFAULT,
"eSSSSSS",
"path arg1 arg2 arg3 arg4 arg5 arg6",
"Makes the script slave follow the specified path. The allowable arguments are ignoreangles,\n"
"ignorevelocity, normalangles, loop, and a number specifying the start time.",
EV_NORMAL
);
Event EV_ScriptSlave_FollowPath_RelativeYaw
(
"path_relativeyaw",
EV_DEFAULT,
"f",
"relativeYaw",
"Makes the script slave follow the specified path with a yaw offset,",
EV_NORMAL
);
Event EV_ScriptSlave_EndPath
(
"endpath",
EV_DEFAULT,
NULL,
NULL,
"Stop following the path",
EV_NORMAL
);
Event EV_ScriptSlave_MoveDone
(
"scriptslave_movedone",
EV_DEFAULT,
NULL,
NULL,
"Called when the script slave is doen moving",
EV_NORMAL
);
Event EV_ScriptSlave_FollowingPath
(
"scriptslave_followingpath",
EV_DEFAULT,
NULL,
NULL,
"Called every frame to actually follow the path",
EV_NORMAL
);
Event EV_ScriptSlave_Explode
(
"explode",
EV_DEFAULT,
"f",
"damage",
"Creates an explosion at the script slave's position",
EV_NORMAL
);
Event EV_ScriptSlave_NotShootable
(
"notshootable",
EV_DEFAULT,
NULL,
NULL,
"Makes the script slave not shootable",
EV_NORMAL
);
Event EV_ScriptSlave_OpenAreaPortal
(
"openportal",
EV_DEFAULT,
NULL,
NULL,
"Open the area portal enclosed in this object",
EV_NORMAL
);
Event EV_ScriptSlave_CloseAreaPortal
(
"closeportal",
EV_DEFAULT,
NULL,
NULL,
"Close the area portal enclosed in this object",
EV_NORMAL
);
Event EV_ScriptSlave_PhysicsOn
(
"physics_on",
EV_DEFAULT,
"I",
"no_collide_entity",
"Turn physics on this script object on\n"
"If no_collide_entity is set to 1 then the script slave will not collide with other entities",
EV_NORMAL
);
Event EV_ScriptSlave_PhysicsOff
(
"physics_off",
EV_DEFAULT,
NULL,
NULL,
"Turn physics off this script object on",
EV_NORMAL
);
Event EV_ScriptSlave_PhysicsVelocity
(
"physics_velocity",
EV_DEFAULT,
"v",
"impulseVector",
"Add a physical impulse to an object when it is being physically simulated",
EV_NORMAL
);
Event EV_ScriptSlave_FlyPath
(
"flypath",
EV_DEFAULT,
"efff",
"array speed acceleration look_ahead",
"Makes the script slave fly the specified path with speed and acceleration until reached_distance close to "
"position",
EV_NORMAL
);
Event EV_ScriptSlave_ModifyFlyPath
(
"modifyflypath",
EV_DEFAULT,
"efff",
"array speed acceleration look_ahead",
"Makes the script slave fly the specified path with speed and acceleration until reached_distance close to "
"position",
EV_NORMAL
);
Event EV_ScriptSlave_NormalAngles
(
"normalangles",
EV_DEFAULT,
"b",
"bUseNormalAngles",
"Sets the object to use normal angles when travelling on a spline path",
EV_NORMAL
);
CLASS_DECLARATION(Mover, ScriptSlave, "script_object") {
{&EV_Bind, &ScriptSlave::BindEvent },
{&EV_Unbind, &ScriptSlave::EventUnbind },
{&EV_ScriptSlave_DoMove, &ScriptSlave::DoMove },
{&EV_ScriptSlave_WaitMove, &ScriptSlave::WaitMove },
{&EV_ScriptSlave_Stop, &ScriptSlave::Stop },
{&EV_ScriptSlave_ThreadMove, &ScriptSlave::ThreadMove },
{&EV_ScriptSlave_Angles, &ScriptSlave::SetAnglesEvent },
{&EV_SetAngle, &ScriptSlave::SetAngleEvent },
{&EV_Model, &ScriptSlave::SetModelEvent },
{&EV_ScriptSlave_Trigger, &ScriptSlave::TriggerEvent },
{&EV_ScriptSlave_Next, &ScriptSlave::GotoNextWaypoint },
{&EV_ScriptSlave_JumpTo, &ScriptSlave::JumpTo },
{&EV_ScriptSlave_MoveTo, &ScriptSlave::MoveToEvent },
{&EV_ScriptSlave_Speed, &ScriptSlave::SetSpeed },
{&EV_ScriptSlave_Time, &ScriptSlave::SetTime },
{&EV_ScriptSlave_MoveUp, &ScriptSlave::MoveUp },
{&EV_ScriptSlave_MoveDown, &ScriptSlave::MoveDown },
{&EV_ScriptSlave_MoveNorth, &ScriptSlave::MoveNorth },
{&EV_ScriptSlave_MoveSouth, &ScriptSlave::MoveSouth },
{&EV_ScriptSlave_MoveEast, &ScriptSlave::MoveEast },
{&EV_ScriptSlave_MoveWest, &ScriptSlave::MoveWest },
{&EV_ScriptSlave_MoveForward, &ScriptSlave::MoveForward },
{&EV_ScriptSlave_MoveBackward, &ScriptSlave::MoveBackward },
{&EV_ScriptSlave_MoveLeft, &ScriptSlave::MoveLeft },
{&EV_ScriptSlave_MoveRight, &ScriptSlave::MoveRight },
{&EV_ScriptSlave_MoveOffset, &ScriptSlave::MoveOffset },
{&EV_ScriptSlave_RotateXDownTo, &ScriptSlave::RotateXdownto },
{&EV_ScriptSlave_RotateYDownTo, &ScriptSlave::RotateYdownto },
{&EV_ScriptSlave_RotateZDownTo, &ScriptSlave::RotateZdownto },
{&EV_ScriptSlave_RotateXUpTo, &ScriptSlave::RotateXupto },
{&EV_ScriptSlave_RotateYUpTo, &ScriptSlave::RotateYupto },
{&EV_ScriptSlave_RotateZUpTo, &ScriptSlave::RotateZupto },
{&EV_ScriptSlave_RotateXDown, &ScriptSlave::RotateXdown },
{&EV_ScriptSlave_RotateYDown, &ScriptSlave::RotateYdown },
{&EV_ScriptSlave_RotateZDown, &ScriptSlave::RotateZdown },
{&EV_ScriptSlave_RotateXUp, &ScriptSlave::RotateXup },
{&EV_ScriptSlave_RotateYUp, &ScriptSlave::RotateYup },
{&EV_ScriptSlave_RotateZUp, &ScriptSlave::RotateZup },
{&EV_ScriptSlave_RotateX, &ScriptSlave::RotateX },
{&EV_ScriptSlave_RotateY, &ScriptSlave::RotateY },
{&EV_ScriptSlave_RotateZ, &ScriptSlave::RotateZ },
{&EV_ScriptSlave_RotateAxisDownTo, &ScriptSlave::RotateAxisdownto },
{&EV_ScriptSlave_RotateAxisUpTo, &ScriptSlave::RotateAxisupto },
{&EV_ScriptSlave_RotateAxisDown, &ScriptSlave::RotateAxisdown },
{&EV_ScriptSlave_RotateAxisUp, &ScriptSlave::RotateAxisup },
{&EV_ScriptSlave_RotateAxis, &ScriptSlave::RotateZ },
{&EV_ScriptSlave_SetDamage, &ScriptSlave::SetDamage },
{&EV_ScriptSlave_SetMeansOfDeath, &ScriptSlave::SetMeansOfDeath },
{&EV_ScriptSlave_SetDamageSpawn, &ScriptSlave::SetDamage },
{&EV_ScriptSlave_FollowPath, &ScriptSlave::FollowPath },
{&EV_ScriptSlave_FollowPath_RelativeYaw, &ScriptSlave::FollowPathRelativeYaw},
{&EV_ScriptSlave_EndPath, &ScriptSlave::EndPath },
{&EV_ScriptSlave_FollowingPath, &ScriptSlave::FollowingPath },
{&EV_Touch, &ScriptSlave::TouchFunc },
{&EV_Blocked, &ScriptSlave::BlockFunc },
{&EV_Activate, &ScriptSlave::TriggerFunc },
{&EV_Use, &ScriptSlave::UseFunc },
{&EV_ScriptSlave_MoveDone, &ScriptSlave::MoveEnd },
{&EV_Damage, &ScriptSlave::DamageFunc },
{&EV_ScriptSlave_RotateDownTo, &ScriptSlave::Rotatedownto },
{&EV_ScriptSlave_RotateUpTo, &ScriptSlave::Rotateupto },
{&EV_ScriptSlave_RotateTo, &ScriptSlave::Rotateto },
{&EV_ScriptSlave_Explode, &ScriptSlave::Explode },
{&EV_ScriptSlave_NotShootable, &ScriptSlave::NotShootable },
{&EV_ScriptSlave_OpenAreaPortal, &ScriptSlave::OpenPortal },
{&EV_ScriptSlave_CloseAreaPortal, &ScriptSlave::ClosePortal },
{&EV_ScriptSlave_PhysicsOn, &ScriptSlave::PhysicsOn },
{&EV_ScriptSlave_PhysicsOff, &ScriptSlave::PhysicsOff },
{&EV_ScriptSlave_PhysicsVelocity, &ScriptSlave::PhysicsVelocity },
{&EV_ScriptSlave_FlyPath, &ScriptSlave::EventFlyPath },
{&EV_ScriptSlave_ModifyFlyPath, &ScriptSlave::EventModifyFlyPath },
{&EV_ScriptSlave_NormalAngles, &ScriptSlave::EventNormalAngles },
{NULL, NULL }
};
cvar_t *g_showflypath;
ScriptSlave::ScriptSlave()
{
g_showflypath = gi.Cvar_Get("g_showflypath", "0", 0);
AddWaitTill(STRING_TOUCH);
AddWaitTill(STRING_BLOCK);
AddWaitTill(STRING_TRIGGER);
AddWaitTill(STRING_USE);
AddWaitTill(STRING_DAMAGE);
if (LoadingSavegame) {
// Archive function will setup all necessary data
return;
}
// this is a normal entity
edict->s.eType = ET_GENERAL;
splineTime = 0;
ignoreangles = false;
ignorevelocity = false;
moving = false;
speed = 100;
takedamage = DAMAGE_YES;
waypoint = NULL;
traveltime = 0;
commandswaiting = false;
splinePath = NULL;
splineangles = false;
m_fFollowRelativeYaw = 0;
attack_finished = 0;
dmg = 2;
dmg_means_of_death = MOD_CRUSH;
setMoveType(MOVETYPE_PUSH);
if (spawnflags & 2) {
edict->s.renderfx = RF_ALWAYSDRAW;
}
setSolidType(SOLID_NOT);
m_pCurPath = NULL;
m_iCurNode = 0;
m_fCurSpeed = 0;
m_fLookAhead = 0;
m_fIdealSpeed = 0;
m_fIdealAccel = 0;
m_fIdealDistance = 100;
if (spawnflags & 1) {
PostEvent(EV_BecomeNonSolid, EV_POSTSPAWN);
}
edict->s.eFlags |= EF_LINKANGLES;
}
ScriptSlave::~ScriptSlave()
{
if (splinePath) {
delete splinePath;
splinePath = NULL;
}
}
void ScriptSlave::CheckNewOrders(void)
{
// make sure position and angles are current
if (!commandswaiting) {
commandswaiting = true;
NewAngles = localangles;
NewPos = localorigin;
}
}
void ScriptSlave::NewMove(void)
{
float dist;
CheckNewOrders();
commandswaiting = false;
if (RegisterSize(0)) {
Event ev = Event(EV_DelayThrow);
ev.AddConstString(STRING_FAIL);
BroadcastEvent(0, ev);
}
if (m_pCurPath || splinePath) {
PostEvent(EV_ScriptSlave_FollowingPath, 0);
} else {
float t = traveltime;
if (t == 0) {
dist = Vector(NewPos - localorigin).length();
t = dist / speed;
}
LinearInterpolate(NewPos, NewAngles, t, EV_ScriptSlave_MoveDone);
}
}
void ScriptSlave::BindEvent(Event *ev)
{
Entity *ent;
ent = ev->GetEntity(1);
if (ent) {
bind(ent);
}
// make sure position and angles are current
NewAngles = localangles;
NewPos = localorigin;
}
void ScriptSlave::EventUnbind(Event *ev)
{
unbind();
// make sure position and angles are current
NewAngles = localangles;
NewPos = localorigin;
}
void ScriptSlave::DoMove(Event *ev)
{
NewMove();
}
void ScriptSlave::WaitMove(Event *ev)
{
NewMove();
Register(0, Director.CurrentScriptThread());
}
void ScriptSlave::Stop(Event *ev)
{
commandswaiting = false;
if (RegisterSize(0)) {
Event newev(EV_DelayThrow);
newev.AddConstString(STRING_FAIL);
BroadcastEvent(0, newev);
}
Mover::Stop();
}
void ScriptSlave::ThreadMove(Event *ev)
{
NewMove();
Register(0, CreateThreadInternal(ev->GetValue(1)));
}
void ScriptSlave::MoveEnd(Event *ev)
{
Unregister(0);
}
void ScriptSlave::SetAnglesEvent(Event *ev)
{
CheckNewOrders();
SetAngles(ev);
NewAngles = localangles;
}
void ScriptSlave::SetAngleEvent(Event *ev)
{
float angle;
angle = ev->GetFloat(1);
if (angle == -1) {
ForwardDir = Vector(0, 0, 90);
} else if (angle == -2) {
ForwardDir = Vector(0, 0, -90);
} else {
ForwardDir = Vector(0, angle, 0);
}
}
void ScriptSlave::SetModelEvent(Event *ev)
{
str m;
m = ev->GetString(1);
edict->r.svFlags &= ~SVF_NOCLIENT;
if (!m || strstr(m, ".tik")) {
setSolidType(SOLID_BBOX);
setModel(m);
if (!edict->s.modelindex) {
hideModel();
setSolidType(SOLID_NOT);
}
} else if (strstr(m, ".spr")) {
setModel(m);
if (!edict->s.modelindex) {
hideModel();
}
setSolidType(SOLID_NOT);
} else {
setModel(m);
if (edict->s.modelindex) {
setSolidType(SOLID_BSP);
} else {
hideModel();
setSolidType(SOLID_NOT);
}
}
if (!edict->s.modelindex) {
hideModel();
setSolidType(SOLID_NOT);
}
}
void ScriptSlave::TriggerEvent(Event *ev)
{
Entity *ent;
Event *e;
ent = ev->GetEntity(1);
if (ent) {
target = ent->TargetName();
e = new Event(EV_Trigger_ActivateTargets);
//fixme
//get "other"
e->AddEntity(world);
ProcessEvent(e);
}
}
void ScriptSlave::GotoNextWaypoint(Event *ev)
{
CheckNewOrders();
if (!waypoint) {
ScriptError("%s is currently not at a waypoint", TargetName().c_str());
return;
}
waypoint = (Waypoint *)G_FindTarget(NULL, waypoint->Target());
if (!waypoint) {
ScriptError("%s could not find waypoint %s", TargetName().c_str(), waypoint->Target().c_str());
return;
} else {
NewPos = waypoint->origin;
}
}
void ScriptSlave::JumpTo(Event *ev)
{
Entity *part;
//
// see if it is a vector
//
if (ev->IsVectorAt(1)) {
NewPos = ev->GetVector(1);
if (bindmaster) {
localorigin = bindmaster->getLocalVector(NewPos - bindmaster->origin);
} else {
localorigin = NewPos;
}
for (part = this; part; part = part->teamchain) {
part->setOrigin();
part->origin.copyTo(part->edict->s.origin2);
part->edict->s.renderfx |= RF_FRAMELERP;
}
} else {
waypoint = ev->GetWaypoint(1);
if (waypoint) {
NewPos = waypoint->origin;
if (bindmaster) {
localorigin = bindmaster->getLocalVector(NewPos - bindmaster->origin);
} else {
localorigin = NewPos;
}
for (part = this; part; part = part->teamchain) {
part->setOrigin();
part->origin.copyTo(part->edict->s.origin2);
part->edict->s.renderfx |= RF_FRAMELERP;
}
}
}
}
void ScriptSlave::MoveToEvent(Event *ev)
{
CheckNewOrders();
//
// see if it is a vector
//
if (ev->IsVectorAt(1)) {
NewPos = ev->GetVector(1);
} else {
SimpleEntity* ent;
ent = ev->GetSimpleEntity(1);
if (ent) {
//
// see if it is a waypoint
//
if (ent->IsSubclassOfWaypoint()) {
waypoint = static_cast<Waypoint*>(ent);
}
// use the entity's origin
NewPos = ent->origin;
}
}
}
void ScriptSlave::SetSpeed(Event *ev)
{
speed = ev->GetFloat(1);
traveltime = 0;
}
void ScriptSlave::SetTime(Event *ev)
{
traveltime = ev->GetFloat(1);
}
// Relative move commands
void ScriptSlave::MoveUp(Event *ev)
{
CheckNewOrders();
NewPos[2] += ev->GetFloat(1);
}
void ScriptSlave::MoveDown(Event *ev)
{
CheckNewOrders();
NewPos[2] -= ev->GetFloat(1);
}
void ScriptSlave::MoveNorth(Event *ev)
{
CheckNewOrders();
NewPos[1] += ev->GetFloat(1);
}
void ScriptSlave::MoveSouth(Event *ev)
{
CheckNewOrders();
NewPos[1] -= ev->GetFloat(1);
}
void ScriptSlave::MoveEast(Event *ev)
{
CheckNewOrders();
NewPos[0] += ev->GetFloat(1);
}
void ScriptSlave::MoveWest(Event *ev)
{
CheckNewOrders();
NewPos[0] -= ev->GetFloat(1);
}
void ScriptSlave::MoveForward(Event *ev)
{
Vector v;
Vector t;
CheckNewOrders();
t = NewAngles + ForwardDir;
t.AngleVectorsLeft(&v, NULL, NULL);
NewPos += v * ev->GetFloat(1);
}
void ScriptSlave::MoveBackward(Event *ev)
{
Vector v;
Vector t;
CheckNewOrders();
t = NewAngles + ForwardDir;
t.AngleVectorsLeft(&v, NULL, NULL);
NewPos -= v * ev->GetFloat(1);
}
void ScriptSlave::MoveLeft(Event *ev)
{
Vector v;
Vector t;
CheckNewOrders();
t = NewAngles + ForwardDir;
t.AngleVectorsLeft(NULL, &v, NULL);
NewPos += v * ev->GetFloat(1);
}
void ScriptSlave::MoveRight(Event *ev)
{
Vector t;
Vector v;
CheckNewOrders();
t = NewAngles + ForwardDir;
t.AngleVectorsLeft(NULL, &v, NULL);
NewPos -= v * ev->GetFloat(1);
}
void ScriptSlave::MoveOffset(Event *ev)
{
CheckNewOrders();
NewPos += ev->GetVector(1);
}
// exact rotate commands
void ScriptSlave::RotateXdownto(Event *ev)
{
CheckNewOrders();
NewAngles[0] = ev->GetFloat(1);
if (NewAngles[0] > localangles[0]) {
NewAngles[0] -= 360;
}
}
void ScriptSlave::RotateYdownto(Event *ev)
{
CheckNewOrders();
NewAngles[1] = ev->GetFloat(1);
if (NewAngles[1] > localangles[1]) {
NewAngles[1] -= 360;
}
}
void ScriptSlave::RotateZdownto(Event *ev)
{
CheckNewOrders();
NewAngles[2] = ev->GetFloat(1);
if (NewAngles[2] > localangles[2]) {
NewAngles[2] -= 360;
}
}
void ScriptSlave::RotateAxisdownto(Event *ev)
{
int axis;
CheckNewOrders();
axis = ev->GetInteger(1);
NewAngles[axis] = ev->GetFloat(2);
if (NewAngles[axis] > localangles[axis]) {
NewAngles[axis] -= 360;
}
}
void ScriptSlave::RotateXupto(Event *ev)
{
CheckNewOrders();
NewAngles[0] = ev->GetFloat(1);
if (NewAngles[0] < localangles[0]) {
NewAngles[0] += 360;
}
}
void ScriptSlave::RotateYupto(Event *ev)
{
CheckNewOrders();
NewAngles[1] = ev->GetFloat(1);
if (NewAngles[1] < localangles[1]) {
NewAngles[1] += 360;
}
}
void ScriptSlave::RotateZupto(Event *ev)
{
CheckNewOrders();
NewAngles[2] = ev->GetFloat(1);
if (NewAngles[2] < localangles[2]) {
NewAngles[2] += 360;
}
}
void ScriptSlave::RotateAxisupto(Event *ev)
{
int axis;
CheckNewOrders();
axis = ev->GetInteger(1);
NewAngles[axis] = ev->GetFloat(2);
if (NewAngles[axis] < localangles[axis]) {
NewAngles[axis] += 360;
}
}
// full vector rotation
void ScriptSlave::Rotatedownto(Event *ev)
{
Vector ang;
CheckNewOrders();
ang = ev->GetVector(1);
NewAngles[0] = ang[0];
if (NewAngles[0] > localangles[0]) {
NewAngles[0] -= 360;
}
NewAngles[1] = ang[1];
if (NewAngles[1] > localangles[1]) {
NewAngles[1] -= 360;
}
NewAngles[2] = ang[2];
if (NewAngles[2] > localangles[2]) {
NewAngles[2] -= 360;
}
}
void ScriptSlave::Rotateupto(Event *ev)
{
Vector ang;
CheckNewOrders();
ang = ev->GetVector(1);
NewAngles[0] = ang[0];
if (NewAngles[0] < localangles[0]) {
NewAngles[0] += 360;
}
NewAngles[1] = ang[1];
if (NewAngles[1] < localangles[1]) {
NewAngles[1] += 360;
}
NewAngles[2] = ang[2];
if (NewAngles[2] < localangles[2]) {
NewAngles[2] += 360;
}
}
void ScriptSlave::Rotateto(Event *ev)
{
Vector ang;
CheckNewOrders();
ang = ev->GetVector(1);
NewAngles = ang;
}
// Relative rotate commands
void ScriptSlave::RotateXdown(Event *ev)
{
CheckNewOrders();
NewAngles[0] = localangles[0] - ev->GetFloat(1);
}
void ScriptSlave::RotateYdown(Event *ev)
{
CheckNewOrders();
NewAngles[1] = localangles[1] - ev->GetFloat(1);
}
void ScriptSlave::RotateZdown(Event *ev)
{
CheckNewOrders();
NewAngles[2] = localangles[2] - ev->GetFloat(1);
}
void ScriptSlave::RotateAxisdown(Event *ev)
{
int axis;
CheckNewOrders();
axis = ev->GetInteger(1);
NewAngles[axis] = localangles[axis] - ev->GetFloat(2);
}
void ScriptSlave::RotateXup(Event *ev)
{
CheckNewOrders();
NewAngles[0] = localangles[0] + ev->GetFloat(1);
}
void ScriptSlave::RotateYup(Event *ev)
{
CheckNewOrders();
NewAngles[1] = localangles[1] + ev->GetFloat(1);
}
void ScriptSlave::RotateZup(Event *ev)
{
CheckNewOrders();
NewAngles[2] = localangles[2] + ev->GetFloat(1);
}
void ScriptSlave::RotateAxisup(Event *ev)
{
int axis;
CheckNewOrders();
axis = ev->GetInteger(1);
NewAngles[axis] = localangles[axis] + ev->GetFloat(2);
}
void ScriptSlave::RotateX(Event *ev)
{
avelocity[0] = ev->GetFloat(1);
}
void ScriptSlave::RotateY(Event *ev)
{
avelocity[1] = ev->GetFloat(1);
}
void ScriptSlave::RotateZ(Event *ev)
{
avelocity[2] = ev->GetFloat(1);
}
void ScriptSlave::RotateAxis(Event *ev)
{
int axis;
axis = ev->GetInteger(1);
avelocity[axis] = ev->GetFloat(2);
}
void ScriptSlave::TouchFunc(Event* ev)
{
parm.other = ev->GetEntity(1);
parm.owner = parm.other;
Unregister(STRING_TOUCH);
}
void ScriptSlave::BlockFunc(Event* ev)
{
Entity* other;
other = ev->GetEntity(1);
if (level.time >= attack_finished) {
attack_finished = level.time + 0.5;
if (dmg) {
other->Damage(this, this, dmg, origin, vec_zero, vec_zero, 0, 0, dmg_means_of_death);
}
}
parm.other = ev->GetEntity(1);
parm.owner = parm.other;
Unregister(STRING_BLOCK);
}
void ScriptSlave::TriggerFunc(Event* ev)
{
parm.other = ev->GetEntity(1);
parm.owner = parm.other;
Unregister(STRING_TRIGGER);
}
void ScriptSlave::UseFunc(Event* ev)
{
parm.other = ev->GetEntity(1);
parm.owner = parm.other;
Unregister(STRING_USE);
}
void ScriptSlave::DamageFunc(Event *ev)
{
Unregister(STRING_DAMAGE);
}
void ScriptSlave::SetDamage(Event *ev)
{
dmg = ev->GetInteger(1);
}
void ScriptSlave::SetMeansOfDeath(Event *ev)
{
dmg_means_of_death = MOD_string_to_int(ev->GetString(1));
}
void ScriptSlave::CreatePath(SplinePath *path, splinetype_t type)
{
SplinePath *node;
if (!splinePath) {
splinePath = new BSpline;
}
splinePath->Clear();
splinePath->SetType(type);
node = path;
while (node != NULL) {
splinePath->AppendControlPoint(node->origin, node->angles, node->speed);
node = node->GetNext();
if (node == path) {
break;
}
}
}
void ScriptSlave::FollowPath(Event *ev)
{
int i, argnum;
SimpleEntity *ent;
str token;
SplinePath *path;
qboolean clamp;
float starttime;
ent = ev->GetSimpleEntity(1);
argnum = 2;
starttime = -2;
clamp = true;
ignoreangles = false;
ignorevelocity = false;
splineangles = true;
for (i = argnum; i <= ev->NumArgs(); i++) {
token = ev->GetString(i);
if (!Q_stricmp(token, "ignoreangles")) {
ignoreangles = true;
} else if (!Q_stricmp(token, "ignorevelocity")) {
ignorevelocity = true;
} else if (!Q_stricmp(token, "normalangles")) {
splineangles = false;
} else if (!Q_stricmp(token, "loop")) {
clamp = false;
} else if (IsNumeric(token)) {
starttime = atof(token);
// Fixed in OPM
// HACKHACK
//
// There is a bug in mohaa where the token's raw pointer is directly used
// but then the token can be freed before comparison, which cause
// starttime to be always 0.
// OPM is correct here but for compatibility purpose the bug have to be reproduced.
// Otherwise, for example the final bomber plane in t3l2 will not fly.
if (!ev->IsStringAt(i)) {
starttime = 0;
}
} else {
ScriptError("Unknown followpath command %s.", token.c_str());
}
}
if (ent && ent->IsSubclassOfSplinePath()) {
path = (SplinePath *)ent;
if (clamp) {
CreatePath(path, SPLINE_CLAMP);
} else {
CreatePath(path, SPLINE_LOOP);
}
splineTime = starttime;
CancelEventsOfType(EV_ScriptSlave_FollowingPath);
if (!ignoreangles) {
avelocity = vec_zero;
}
if (!ignorevelocity) {
velocity = vec_zero;
}
}
}
void ScriptSlave::FollowPathRelativeYaw(Event *ev)
{
m_fFollowRelativeYaw = ev->GetFloat(1);
}
void ScriptSlave::EndPath(Event *ev)
{
if (!splinePath) {
return;
}
delete splinePath;
splinePath = NULL;
if (!ignorevelocity) {
velocity = vec_zero;
}
if (!ignoreangles) {
avelocity = vec_zero;
}
}
void ScriptSlave::FollowingPath(Event *ev)
{
Vector pos;
Vector orient;
float speed_multiplier;
if (m_pCurPath && m_pCurPath->m_iPoints) {
Vector vAngles;
Vector vDeltaAngles;
Vector vDelta;
float *vTmp;
Vector vPrev;
Vector vCur;
Vector vTotal;
float fCoef;
Vector vWishPosition;
Vector vWishAngles;
Vector vNextWishAngles;
Vector primal_angles;
Vector n_angles;
if (g_showflypath && g_showflypath->integer) {
for (int i = 0; i < m_pCurPath->m_iPoints; i++) {
vTmp = m_pCurPath->GetByNode(i, NULL);
VectorCopy((vTmp + 1), vCur);
G_DebugBBox(vCur, Vector(-32, -32, -32), Vector(32, 32, 32), 0, 1, 1, 1);
for (int ii = 0; ii <= 8; ii++) {
vTmp = m_pCurPath->GetByNode(i + ii / 10.0, NULL);
VectorCopy((vTmp + 1), vPrev);
vTmp = m_pCurPath->GetByNode(i + ii / 10.0 + m_fLookAhead, NULL);
VectorCopy((vTmp + 1), vCur);
G_DebugLine(vPrev, vCur, 0, 1, 0, 1);
}
}
}
if (m_iCurNode > 0) {
// Get previous node
vTmp = m_pCurPath->GetByNode(m_iCurNode - 1, NULL);
vPrev = (vTmp + 1);
// Get current node
vTmp = m_pCurPath->GetByNode(m_iCurNode, NULL);
vCur = (vTmp + 1);
vDelta = vCur - vPrev;
m_vIdealDir = vDelta;
VectorNormalize(m_vIdealDir);
angles.AngleVectorsLeft(&vWishAngles);
fCoef = ProjectLineOnPlane(vWishAngles, DotProduct(origin, vWishAngles), vPrev, vCur, NULL);
vTmp = m_pCurPath->GetByNode(m_iCurNode - (1.0 - fCoef), NULL);
vTmp = m_pCurPath->Get(vTmp[0] + m_fLookAhead, NULL);
vWishPosition = (vTmp + 1);
if (fCoef > 1.0f) {
m_iCurNode++;
if (m_iCurNode >= m_pCurPath->m_iPoints) {
velocity = vec_zero;
avelocity = vec_zero;
delete m_pCurPath;
m_pCurPath = NULL;
m_iCurNode = 0;
moving = false;
ProcessEvent(EV_ScriptSlave_MoveDone);
return;
}
}
} else {
vTmp = m_pCurPath->GetByNode(m_iCurNode, NULL);
vWishPosition = (vTmp + 1);
vDelta = vWishPosition - origin;
if (vDelta.length() <= 32.0f) {
m_iCurNode++;
if (m_iCurNode >= m_pCurPath->m_iPoints) {
velocity = vec_zero;
avelocity = vec_zero;
delete m_pCurPath;
m_pCurPath = NULL;
m_iCurNode = 0;
moving = false;
ProcessEvent(EV_ScriptSlave_MoveDone);
return;
}
}
}
vDelta = vWishPosition - origin;
if (vDelta.length() > 0.0f) {
vDelta.normalize();
VectorToAngles(vDelta, vNextWishAngles);
//
// Added in 2.0
// Relative yaw
vNextWishAngles[1] += m_fFollowRelativeYaw;
if (m_fFollowRelativeYaw == 180) {
vNextWishAngles[0] *= -1;
}
} else {
vNextWishAngles = angles;
AngleVectorsLeft(angles, vDelta, NULL, NULL);
}
vAngles = angles;
for (int i = 0; i < 3; i++) {
float change, error;
n_angles[i] = vNextWishAngles[i] - angles[i];
if (n_angles[i] > 180) {
n_angles[i] -= 360;
} else if (n_angles[i] < -180) {
n_angles[i] += 360;
}
change = level.frametime * 360.0f;
error = 0.33f * n_angles[i];
if (error < -change) {
error = -change;
} else if (error > change) {
error = change;
}
primal_angles[i] = angles[i] + error;
}
setAngles(primal_angles);
vDeltaAngles = (angles - vAngles) * level.frametime;
if (vDeltaAngles[0] > 180.0f || vDeltaAngles[0] <= -180.0f) {
vDeltaAngles[0] = 0.0f;
}
if (vDeltaAngles[1] > 180.0f || vDeltaAngles[1] <= -180.0f) {
vDeltaAngles[1] = 0.0f;
}
if (vDeltaAngles[2] > 180.0f || vDeltaAngles[2] <= -180.0f) {
vDeltaAngles[2] = 0.0f;
}
if (vDeltaAngles[0] > -1.0f || vDeltaAngles[0] < 1.0f) {
vDeltaAngles[0] = 0.0f;
}
if (vDeltaAngles[1] > -1.0f || vDeltaAngles[1] < 1.0f) {
vDeltaAngles[1] = 0.0f;
}
if (vDeltaAngles[2] > -1.0f || vDeltaAngles[2] < 1.0f) {
vDeltaAngles[2] = 0.0f;
}
avelocity = vDeltaAngles;
velocity = vDelta * m_fCurSpeed;
if (m_fIdealSpeed > m_fCurSpeed) {
m_fCurSpeed += m_fIdealAccel * level.frametime;
if (m_fCurSpeed > m_fIdealSpeed) {
m_fCurSpeed = m_fIdealSpeed;
}
} else if (m_fIdealSpeed < m_fCurSpeed) {
m_fCurSpeed -= m_fIdealAccel * level.frametime;
if (m_fCurSpeed < m_fIdealSpeed) {
m_fCurSpeed = m_fIdealSpeed;
}
}
} else {
if (!splinePath) {
return;
}
if ((splinePath->GetType() == SPLINE_CLAMP) && (splineTime > (splinePath->EndPoint() - 2))) {
delete splinePath;
splinePath = NULL;
if (!ignorevelocity) {
velocity = vec_zero;
}
if (!ignoreangles) {
avelocity = vec_zero;
}
moving = false;
ProcessEvent(EV_ScriptSlave_MoveDone);
return;
}
speed_multiplier = splinePath->Eval(splineTime, pos, orient);
splineTime += level.frametime * speed_multiplier;
velocity = (pos - origin) * (1 / level.frametime);
if (!ignoreangles) {
if (splineangles) {
avelocity = (orient - angles) * (1 / level.frametime);
} else {
float len;
len = velocity.length();
if (len > 0.05) {
Vector ang;
Vector dir;
float aroll;
aroll = avelocity[ROLL];
dir = velocity * (1 / len);
ang = dir.toAngles();
avelocity = (ang - angles) * (1 / level.frametime);
avelocity[ROLL] = aroll;
} else {
avelocity = vec_zero;
}
}
}
}
PostEvent(EV_ScriptSlave_FollowingPath, level.frametime);
}
void ScriptSlave::Explode(Event *ev)
{
float damage;
if (ev->NumArgs()) {
damage = ev->GetFloat(1);
} else {
damage = 120.0f;
}
CreateExplosion(origin, damage, this, this, this);
}
void ScriptSlave::NotShootable(Event *ev)
{
setContents(0);
}
void ScriptSlave::OpenPortal(Event *ev)
{
gi.AdjustAreaPortalState(this->edict, true);
}
void ScriptSlave::ClosePortal(Event *ev)
{
gi.AdjustAreaPortalState(this->edict, false);
}
void ScriptSlave::PhysicsOn(Event *ev)
{
commandswaiting = false;
setMoveType(MOVETYPE_BOUNCE);
setSolidType(SOLID_BBOX);
velocity = Vector(0, 0, 1);
edict->clipmask = MASK_SOLID | CONTENTS_BODY;
if (ev->NumArgs() == 1 && ev->GetInteger(1)) {
edict->clipmask &= ~MASK_SCRIPT_SLAVE;
}
}
void ScriptSlave::PhysicsOff(Event *ev)
{
Event *event;
commandswaiting = false;
setMoveType(MOVETYPE_PUSH);
edict->clipmask = 0;
// become solid again
event = new Event(EV_Model);
event->AddString(model);
PostEvent(event, 0);
}
void ScriptSlave::PhysicsVelocity(Event *ev)
{
velocity += ev->GetVector(1);
}
void ScriptSlave::EventFlyPath(Event *ev)
{
SimpleEntity *path;
m_fIdealDistance = 100.0f;
m_fLookAhead = 256.0f;
m_fIdealAccel = 35.0f;
m_fIdealSpeed = 250.0f;
if (ev->NumArgs() != 1 && ev->NumArgs() != 2 && ev->NumArgs() != 3 && ev->NumArgs() != 4) {
ScriptError("wrong number of arguments");
}
if (ev->NumArgs() > 1) {
m_fIdealSpeed = ev->GetFloat(2);
}
if (ev->NumArgs() > 2) {
m_fIdealAccel = ev->GetFloat(3);
}
if (ev->NumArgs() > 3) {
m_fLookAhead = ev->GetFloat(4);
}
path = ev->GetSimpleEntity(1);
if (!path) {
ScriptError("ScriptSlave Given FlyPath Command with NULL path.");
}
if (m_pCurPath) {
delete m_pCurPath;
}
m_pCurPath = new cSpline<4, 512>;
SetupPath(m_pCurPath, path);
m_iCurNode = 0;
CancelEventsOfType(EV_ScriptSlave_FollowingPath);
}
void ScriptSlave::EventModifyFlyPath(Event *ev)
{
m_fIdealDistance = 100.0f;
if (ev->NumArgs() != 1 && ev->NumArgs() != 2 && ev->NumArgs() != 3) {
ScriptError("wrong number of arguments");
}
if (ev->NumArgs() > 0) {
m_fIdealSpeed = ev->GetFloat(1);
}
if (ev->NumArgs() > 1) {
m_fIdealAccel = ev->GetFloat(2);
}
if (ev->NumArgs() > 2) {
m_fLookAhead = ev->GetFloat(3);
}
}
void ScriptSlave::EventNormalAngles(Event *ev)
{
splineangles = !ev->GetBoolean(1);
ignoreangles = false;
}
void ScriptSlave::SetupPath(cSpline<4, 512> *pPath, SimpleEntity *se)
{
str name;
int iObjNum = 0;
Vector vLastOrigin;
SimpleEntity *ent;
int i = 1;
static cSpline<4, 512> *pTmpPath = new cSpline<4, 512>;
if (!pPath) {
return;
}
pPath->Reset();
pTmpPath->Reset();
vLastOrigin = se->origin;
name = se->Target();
if (name.length()) {
for(ent = se; ent; ent = ent->Next()) {
Vector vDelta;
vec4_t vTmp;
vDelta = vLastOrigin - ent->origin;
if (vDelta.length() == 0 && i > 1) {
Com_Printf("^~^~^Warning: ScriptSlave Flying with a Path that contains 2 equal points\n");
} else {
vTmp[0] = iObjNum++;
vTmp[1] = ent->origin[0];
vTmp[2] = ent->origin[1];
vTmp[3] = ent->origin[2];
pTmpPath->Add(vTmp, 0);
vLastOrigin = ent->origin;
}
if (ent == se && i > 1) {
break;
}
i++;
}
}
if (pTmpPath->m_iPoints > 2) {
float* vTmp;
float fCurLength = 0;
vec3_t vLastOrigin;
vec3_t origin;
vec3_t vDelta;
pPath->Reset();
vTmp = pTmpPath->GetByNode(0, NULL);
VectorCopy((vTmp + 1), vLastOrigin);
VectorCopy((vTmp + 1), origin);
for (i = 0; i < pTmpPath->m_iPoints; i++) {
vec4_t vTmp2;
vTmp = pTmpPath->GetByNode(i, NULL);
VectorCopy((vTmp + 1), vLastOrigin);
VectorSubtract(vLastOrigin, origin, vDelta);
fCurLength += VectorLength(vDelta);
vTmp2[0] = fCurLength;
vTmp2[1] = vLastOrigin[0];
vTmp2[2] = vLastOrigin[1];
vTmp2[3] = vLastOrigin[2];
pPath->Add(vTmp2, 0);
VectorCopy(vLastOrigin, origin);
}
}
}
/*****************************************************************************/
/*QUAKED script_model (0 0.5 1) (0 0 0) (0 0 0) NOT_SOLID
******************************************************************************/
Event EV_ScriptModel_SetAnim
(
"anim",
EV_DEFAULT,
"s",
"anim_name",
"Sets the script model's animation",
EV_NORMAL
);
Event EV_ScriptModel_AnimDone
(
"animdone",
EV_ZERO,
NULL,
NULL,
"Script model animation has finished.",
EV_NORMAL
);
Event EV_ScriptModel_MoveAnim
(
"moveanim",
EV_DEFAULT,
"s",
"animName",
"Makes the script model play an animation and move with the deltas contained in the animation",
EV_NORMAL
);
Event EV_ScriptModel_MovingAnim
(
"moving_from_anim",
EV_DEFAULT,
NULL,
NULL,
"The script model is moving based on an animation",
EV_NORMAL
);
CLASS_DECLARATION(ScriptSlave, ScriptModel, "script_model") {
{&EV_SetAngle, &ScriptModel::SetAngleEvent },
{&EV_ScriptModel_SetAnim, &ScriptModel::SetAnimEvent },
{&EV_Model, &ScriptModel::SetModelEvent },
{&EV_ScriptModel_AnimDone, &ScriptModel::AnimDoneEvent },
{&EV_ScriptModel_MoveAnim, &ScriptModel::MoveAnimEvent },
{&EV_ScriptModel_MovingAnim, &ScriptModel::MovingFromAnimEvent},
{NULL, NULL },
};
ScriptModel::ScriptModel()
{
// this is a tiki model
edict->s.eType = ET_MODELANIM;
AddWaitTill(STRING_ANIMDONE);
}
void ScriptModel::SetModelEvent(Event *ev)
{
ScriptSlave::SetModelEvent(ev);
if (edict->tiki && !mins.length() && !maxs.length()) {
gi.TIKI_CalculateBounds(edict->tiki, edict->s.scale, mins, maxs);
}
}
void ScriptModel::SetAnimEvent(Event *ev)
{
str animname;
animname = ev->GetString(1);
if (animname.length() && edict->tiki) {
int animnum;
animnum = gi.Anim_NumForName(edict->tiki, animname);
if (animnum >= 0) {
NewAnim(animnum, EV_ScriptModel_AnimDone);
RestartAnimSlot(0);
}
}
}
void ScriptModel::AnimDoneEvent(Event *ev)
{
CancelEventsOfType(EV_ScriptModel_MovingAnim);
Unregister(STRING_ANIMDONE);
}
void ScriptModel::MoveAnimEvent(Event *ev)
{
str animName;
int animNum;
animName = ev->GetString(1);
if (!animName.length()) {
return;
}
animNum = gi.Anim_NumForName(edict->tiki, animName.c_str());
if (animNum < 0) {
ScriptError("ScriptModel could not find animation %s.", animName.c_str());
}
NewAnim(animNum, EV_ScriptModel_AnimDone);
RestartAnimSlot(0);
PostEvent(EV_ScriptModel_MovingAnim, 0);
}
void ScriptModel::MovingFromAnimEvent(Event *ev)
{
Vector newOrigin;
Vector newAngles;
// calculate velocity
newOrigin = origin + frame_delta;
velocity = (newOrigin - origin) / level.frametime;
// calculate angular velocity
newAngles = angles + Vector(0, angular_delta, 0);
avelocity = (newAngles - angles) / level.frametime;
PostEvent(EV_ScriptModel_MovingAnim, level.frametime);
}
void ScriptModel::SetAngleEvent(Event *ev)
{
float angle;
angle = ev->GetFloat(1);
if (angle == -1) {
ForwardDir = Vector(0, 0, 90);
localangles = Vector(-90, 0, 0);
} else if (angle == -2) {
ForwardDir = Vector(0, 0, -90);
localangles = Vector(90, 0, 0);
} else {
ForwardDir = Vector(0, angle, 0);
localangles = Vector(0, angle, 0);
}
setAngles(localangles);
}
void ScriptModel::GibEvent(Event *ev)
{
int num, power;
float scale;
setSolidType(SOLID_NOT);
hideModel();
if (!com_blood->integer) {
PostEvent(EV_Remove, 0);
return;
}
num = ev->GetInteger(1);
power = ev->GetInteger(2);
scale = ev->GetFloat(3);
power = -power;
if (ev->NumArgs() > 3) {
CreateGibs(this, power, scale, num, ev->GetString(4));
} else {
CreateGibs(this, power, scale, num);
}
PostEvent(EV_Remove, 0);
}
/*****************************************************************************/
/*QUAKED script_model_realdamage (0 0.5 1) (0 0 0) (0 0 0) NOT_SOLID ALWAYS_DRAW
******************************************************************************/
/*****************************************************************************/
CLASS_DECLARATION(ScriptModel, ScriptModelRealDamage, "script_model_realdamage") {
{&EV_Damage, &ScriptModelRealDamage::EventDamage},
{NULL, NULL }
};
ScriptModelRealDamage::ScriptModelRealDamage()
{
RemoveWaitTill(STRING_DAMAGE);
}
void ScriptModelRealDamage::EventDamage(Event *ev)
{
Entity::DamageEvent(ev);
}
/*****************************************************************************/
/*QUAKED script_origin (1.0 0 0) (-8 -8 -8) (8 8 8)
Used as an alternate origin for objects. Bind the object to the script_origin
in order to simulate changing that object's origin.
******************************************************************************/
// Added in 2.30
Event EV_ScriptOrigin_SetAngle
(
"angle",
EV_DEFAULT,
"f",
"newAngle",
"set the angles of the entity using just one value.\n"
"Sets the yaw of the entity or an up and down\n"
"direction if newAngle is [0-359] or -1 or -2"
);
// Added in 2.30
Event EV_ScriptOrigin_GetAngle
(
"angle",
EV_DEFAULT,
NULL,
NULL,
"get the angles of the entity using just one value.\n"
"Gets the yaw of the entity or an up and down\n"
"direction if newAngle is [0-359] or -1 or -2",
EV_GETTER
);
CLASS_DECLARATION(ScriptSlave, ScriptOrigin, "script_origin") {
{&EV_Model, &ScriptOrigin::SetModelEvent},
//
// Added in 2.30
//
{&EV_ScriptOrigin_SetAngle, &ScriptOrigin::SetAngleEvent},
{&EV_ScriptOrigin_GetAngle, &ScriptOrigin::GetAngleEvent},
{NULL, NULL }
};
ScriptOrigin::ScriptOrigin()
{
setContents(0);
setSolidType(SOLID_NOT);
}
void ScriptOrigin::SetAngleEvent(Event* ev)
{
float angle;
if (g_target_game < target_game_e::TG_MOHTT) {
// Restore the old behavior on previous versions (below 2.30).
// For example, higgins rangers in m3l1a would not face forward
return ScriptSlave::SetAngleEvent(ev);
}
angle = ev->GetFloat(1);
if (angle == -1) {
ForwardDir = Vector(0, 0, 90);
localangles = Vector(-90, 0, 0);
} else if (angle == -2) {
ForwardDir = Vector(0, 0, -90);
localangles = Vector(90, 0, 0);
} else {
ForwardDir = Vector(0, angle, 0);
localangles = Vector(0, angle, 0);
}
setAngles(localangles);
}
void ScriptOrigin::GetAngleEvent(Event* ev)
{
Vector forward;
angles.AngleVectorsLeft(&forward);
ev->AddFloat(G_GetAngle(forward));
}
/*****************************************************************************/
/*QUAKED script_skyorigin (1.0 0 0) ?
Used to specify the origin of a portal sky
******************************************************************************/
CLASS_DECLARATION(ScriptSlave, ScriptSkyOrigin, "script_skyorigin") {
{NULL, NULL}
};
ScriptSkyOrigin::ScriptSkyOrigin()
{
edict->s.renderfx |= RF_SKYORIGIN;
edict->r.svFlags &= ~SVF_NOCLIENT;
setContents(0);
setSolidType(SOLID_NOT);
}
Event EV_ScriptSimpleStrafingGunfire_On
(
"on",
EV_DEFAULT,
NULL,
NULL,
"Turn the gunfire on.",
EV_NORMAL
);
Event EV_ScriptSimpleStrafingGunfire_Off
(
"off",
EV_DEFAULT,
NULL,
NULL,
"Turn the gunfire off.",
EV_NORMAL
);
Event EV_ScriptSimpleStrafingGunfire_Fire
(
"fire",
EV_DEFAULT,
NULL,
NULL,
"Fire.",
EV_NORMAL
);
Event EV_ScriptSimpleStrafingGunfire_TracerFreq
(
"tracerfreq",
EV_DEFAULT,
"f",
NULL,
"Set the frequency of the tracers",
EV_NORMAL
);
Event EV_ScriptSimpleStrafingGunfire_ProjectileModel
(
"projectile",
EV_DEFAULT,
"s",
NULL,
"Set the projectile model",
EV_NORMAL
);
CLASS_DECLARATION(ScriptSlave, ScriptSimpleStrafingGunfire, "script_simplestrafinggunfire") {
{&EV_ScriptSimpleStrafingGunfire_On, &ScriptSimpleStrafingGunfire::GunOn },
{&EV_ScriptSimpleStrafingGunfire_Off, &ScriptSimpleStrafingGunfire::GunOff },
{&EV_ScriptSimpleStrafingGunfire_Fire, &ScriptSimpleStrafingGunfire::GunFire },
{&EV_Weapon_FireDelay, &ScriptSimpleStrafingGunfire::SetFireDelay },
{&EV_Weapon_SetBulletRange, &ScriptSimpleStrafingGunfire::SetRange },
{&EV_Weapon_SetBulletSpread, &ScriptSimpleStrafingGunfire::SetSpread },
{&EV_Weapon_SetBulletDamage, &ScriptSimpleStrafingGunfire::SetDamage },
{&EV_Weapon_SetBulletKnockback, &ScriptSimpleStrafingGunfire::SetKnockback },
{&EV_Weapon_SetBulletThroughWood, &ScriptSimpleStrafingGunfire::SetThroughWood },
{&EV_Weapon_SetBulletThroughMetal, &ScriptSimpleStrafingGunfire::SetThroughMetal },
{&EV_Weapon_SetBulletCount, &ScriptSimpleStrafingGunfire::SetBulletCount },
{&EV_ScriptSimpleStrafingGunfire_TracerFreq, &ScriptSimpleStrafingGunfire::SetTracerFreq },
{&EV_ScriptSimpleStrafingGunfire_ProjectileModel, &ScriptSimpleStrafingGunfire::SetProjectileModel},
{NULL, NULL }
};
ScriptSimpleStrafingGunfire::ScriptSimpleStrafingGunfire()
{
isOn = false;
fireDelay = 0.05f;
range = 4000;
spread = Vector(100, 100, 0);
damage = 100;
knockback = 0;
throughWood = 0;
throughMetal = 0;
bulletCount = 1;
tracerCount = 0;
tracerFrequency = 0;
projectileModel = "models/projectiles/stukaround.tik";
}
void ScriptSimpleStrafingGunfire::GunOn(Event *ev)
{
isOn = true;
CancelEventsOfType(&EV_ScriptSimpleStrafingGunfire_Fire);
PostEvent(EV_ScriptSimpleStrafingGunfire_Fire, 0.05f);
}
void ScriptSimpleStrafingGunfire::GunOff(Event *ev)
{
isOn = false;
CancelEventsOfType(&EV_ScriptSimpleStrafingGunfire_Fire);
}
void ScriptSimpleStrafingGunfire::GunFire(Event *ev)
{
Vector dir, right, up;
Vector horzAngles;
AngleVectors(angles, NULL, NULL, up);
dir = -1 * up;
VectorToAngles(dir, horzAngles);
AngleVectors(horzAngles, NULL, right, up);
dir = dir * range + right * grandom() * spread.x;
dir += up * grandom() * spread.y;
dir.normalize();
ProjectileAttack(origin, dir, this, projectileModel, 1, 0, NULL);
// continue firing
PostEvent(EV_ScriptSimpleStrafingGunfire_Fire, fireDelay);
}
void ScriptSimpleStrafingGunfire::Archive(Archiver& arc)
{
ScriptSlave::Archive(arc);
arc.ArchiveBoolean(&isOn);
arc.ArchiveFloat(&fireDelay);
arc.ArchiveFloat(&range);
arc.ArchiveVector(&spread);
arc.ArchiveFloat(&damage);
arc.ArchiveFloat(&knockback);
arc.ArchiveFloat(&throughWood);
arc.ArchiveFloat(&throughMetal);
arc.ArchiveInteger(&bulletCount);
arc.ArchiveInteger(&tracerCount);
arc.ArchiveInteger(&tracerFrequency);
arc.ArchiveString(&projectileModel);
}
Event EV_ScriptAimedStrafingGunfire_AimTarget
(
"aimtarget",
EV_DEFAULT,
"e",
NULL,
"Set the aim target.",
EV_NORMAL
);
CLASS_DECLARATION(ScriptSimpleStrafingGunfire, ScriptAimedStrafingGunfire, "script_aimedstrafinggunfire") {
{&EV_ScriptAimedStrafingGunfire_AimTarget, &ScriptAimedStrafingGunfire::SetAimTarget},
{&EV_ScriptSimpleStrafingGunfire_Fire, &ScriptAimedStrafingGunfire::GunFire },
{NULL, NULL }
};
ScriptAimedStrafingGunfire::ScriptAimedStrafingGunfire()
{
aimTarget = NULL;
}
void ScriptAimedStrafingGunfire::GunFire(Event *ev)
{
if (!aimTarget) {
ScriptSimpleStrafingGunfire::GunFire(ev);
return;
}
Vector dir, right, up;
Vector horzAngles;
dir = aimTarget->origin - origin;
dir.normalize();
VectorToAngles(dir, horzAngles);
AngleVectors(horzAngles, NULL, right, up);
dir = dir * range + right * grandom() * spread.x;
dir += up * grandom() * spread.y;
dir.normalize();
ProjectileAttack(origin, dir, this, projectileModel, 1, 0, NULL);
// continue firing
PostEvent(EV_ScriptSimpleStrafingGunfire_Fire, fireDelay);
}
void ScriptAimedStrafingGunfire::Archive(Archiver& arc)
{
ScriptSimpleStrafingGunfire::Archive(arc);
arc.ArchiveObjectPointer((Class **)&aimTarget);
}
|