Spaces:
Running
Running
File size: 112,883 Bytes
ba76fcc e401758 ba76fcc e401758 ba76fcc e401758 ba76fcc e401758 ba76fcc |
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 |
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Advanced Tactical Terrain Simulator - 6 Nations Military</title>
<style>
.discord-badge {
position: fixed;
top: 10px;
left: 10px;
z-index: 9999;
}
* { margin:0; padding:0; box-sizing:border-box; }
body { font-family:'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; background:#0a0a0a; color:#fff; overflow:hidden; }
#container { display:flex; height:100vh; }
#sidebar {
width:420px; background:linear-gradient(180deg,#1a1a1a 0%,#2a2a2a 100%);
padding:15px; overflow-y:auto; border-right:3px solid #444;
}
#map-container { flex:1; position:relative; background:#000; min-width:0; min-height:480px; }
#map-canvas, #terrain-background, #contour-canvas {
width:100%; height:100%; position:absolute; top:0; left:0;
image-rendering:auto;
}
#terrain-background { z-index:1; }
#contour-canvas { z-index:2; pointer-events:none; }
#map-canvas { cursor:crosshair; z-index:3; }
.battlefield-divider {
position:absolute; left:0; right:0; height:3px;
background:linear-gradient(90deg,transparent 0%,#ff0000 10%,#ffff00 50%,#ff0000 90%,transparent 100%);
z-index:10; pointer-events:none; box-shadow:0 0 10px rgba(255,0,0,0.5);
}
#blue-zone, #red-zone {
position:absolute; left:50%; transform:translateX(-50%); font-weight:bold; font-size:16px;
text-shadow:2px 2px 4px rgba(0,0,0,0.8); z-index:20;
}
#blue-zone { top:10px; color:#2196F3; }
#red-zone { bottom:10px; color:#f44336; }
.control-section { margin-bottom:20px; padding:12px; background:rgba(40,40,40,0.9); border-radius:8px; border:1px solid #555; }
.control-section h3 {
margin-bottom:10px; color:#4CAF50; font-size:13px; text-transform:uppercase; letter-spacing:1px;
border-bottom:1px solid #333; padding-bottom:5px;
}
.terrain-selector { display:grid; grid-template-columns:repeat(2, 1fr); gap:8px; margin-bottom:15px; }
.terrain-btn {
padding:10px; background:#333; border:2px solid #555; color:#fff; cursor:pointer;
border-radius:5px; transition:all .3s; font-size:11px; text-align:center;
}
.terrain-btn:hover { background:#444; border-color:#4CAF50; }
.terrain-btn.active { background:#4CAF50; border-color:#4CAF50; }
.country-selector { display:grid; grid-template-columns:repeat(2,1fr); gap:8px; margin-bottom:15px; }
.country-btn {
padding:10px; border:2px solid #666; background:#444; color:#fff; cursor:pointer;
border-radius:5px; transition:all .3s; font-weight:bold; font-size:11px; text-align:center;
}
.country-btn:hover { transform:translateY(-2px); box-shadow:0 3px 10px rgba(0,0,0,0.5); }
.country-btn.active { border-width:3px; }
.country-btn.roka { border-color:#2196F3; }
.country-btn.kpa { border-color:#f44336; }
.country-btn.usa { border-color:#1976D2; }
.country-btn.russia { border-color:#D32F2F; }
.country-btn.ukraine { border-color:#FFD700; }
.country-btn.china { border-color:#FF5722; }
.country-btn.active.roka { background:linear-gradient(135deg,#2196F3 0%,#1976D2 100%); }
.country-btn.active.kpa { background:linear-gradient(135deg,#f44336 0%,#d32f2f 100%); }
.country-btn.active.usa { background:linear-gradient(135deg,#1976D2 0%,#0D47A1 100%); }
.country-btn.active.russia { background:linear-gradient(135deg,#D32F2F 0%,#B71C1C 100%); }
.country-btn.active.ukraine { background:linear-gradient(135deg,#FFD700 0%,#FFC107 100%); color:#000; }
.country-btn.active.china { background:linear-gradient(135deg,#FF5722 0%,#E64A19 100%); }
.side-selector { display:flex; gap:10px; margin-bottom:10px; }
.side-btn {
flex:1; padding:8px; border:2px solid #666; background:#333; color:#fff; cursor:pointer;
border-radius:5px; transition:all .3s; font-size:11px; text-align:center;
}
.side-btn.active { background:#4CAF50; border-color:#4CAF50; }
.unit-hierarchy { margin-bottom:15px; max-height:300px; overflow-y:auto; }
.unit-level-title { font-size:12px; color:#888; margin-bottom:5px; font-weight:bold; }
.unit-options { display:grid; grid-template-columns:repeat(2,1fr); gap:5px; }
.unit-btn {
padding:8px; background:#3a3a3a; border:2px solid #555; color:#fff; cursor:pointer;
border-radius:4px; transition:all .3s; font-size:10px; text-align:center;
}
.unit-btn:hover { background:#4a4a4a; border-color:#4CAF50; transform:translateY(-1px); }
.unit-btn.active { background:#4CAF50; border-color:#4CAF50; }
#info-panel { padding:12px; background:rgba(50,50,50,0.9); border-radius:6px; font-size:11px; line-height:1.6; }
#info-panel div { margin:4px 0; padding:4px; background:rgba(30,30,30,0.8); border-radius:3px; }
.weapons-list { font-size:10px; color:#aaa; margin-left:10px; }
.status-bar {
position:absolute; bottom:0; left:0; right:0; background:rgba(0,0,0,0.9);
padding:10px 20px; display:flex; justify-content:space-between; align-items:center;
backdrop-filter:blur(10px); z-index:20; border-top:1px solid #333;
}
.coordinates { color:#4CAF50; font-family:'Courier New', monospace; font-size:12px; }
.control-buttons { display:grid; grid-template-columns:repeat(2,1fr); gap:8px; }
.control-btn {
padding:10px; background:linear-gradient(135deg,#555 0%,#444 100%);
border:1px solid #666; color:#fff; cursor:pointer; border-radius:5px; transition:all .3s; font-size:11px;
}
.control-btn:hover { background:linear-gradient(135deg,#666 0%,#555 100%); transform:translateY(-1px); }
.ai-deploy-btn {
width:100%; padding:15px; background:linear-gradient(135deg,#667eea 0%,#764ba2 100%);
border:none; color:#fff; cursor:pointer; border-radius:5px; font-size:13px; font-weight:bold; transition:all .3s; margin-bottom:10px;
}
.ai-deploy-btn:hover { transform:scale(1.02); box-shadow:0 5px 15px rgba(102,126,234,0.4); }
.stats { display:grid; grid-template-columns:repeat(2,1fr); gap:8px; margin-top:10px; }
.stat-item { padding:8px; background:rgba(30,30,30,0.8); border-radius:5px; text-align:center; border:1px solid #333; }
.stat-value { font-size:16px; font-weight:bold; color:#4CAF50; }
.stat-label { font-size:10px; color:#888; margin-top:2px; }
.legend {
position:absolute; top:20px; right:20px; background:rgba(0,0,0,0.9);
padding:12px; border-radius:8px; backdrop-filter:blur(10px); z-index:20; border:1px solid #333; font-size:11px;
}
.legend-title { color:#4CAF50; font-weight:bold; margin-bottom:8px; border-bottom:1px solid #333; padding-bottom:5px; }
.legend-item { display:flex; align-items:center; margin:5px 0; }
.legend-symbol { width:25px; height:20px; margin-right:8px; display:flex; align-items:center; justify-content:center; font-weight:bold; font-size:14px; }
.scale-indicator {
position:absolute; bottom:50px; right:20px; background:rgba(0,0,0,0.9);
padding:10px; border-radius:5px; z-index:20; border:1px solid #333; font-size:11px;
color:#4CAF50;
}
.terrain-controls {
display:flex; gap:8px; margin-top:10px; flex-wrap:wrap;
}
.terrain-control-btn {
padding:6px 12px; background:#444; border:1px solid #666; color:#fff;
cursor:pointer; border-radius:4px; font-size:10px; transition:all .3s;
}
.terrain-control-btn:hover { background:#555; border-color:#4CAF50; }
.terrain-control-btn.active { background:#4CAF50; border-color:#4CAF50; }
.speed-control {
margin-top:15px; padding:15px; background:rgba(30,30,30,0.9); border-radius:8px; border:1px solid #666;
}
.speed-control-title {
font-size:12px; color:#FFC107; margin-bottom:10px; font-weight:bold; text-transform:uppercase;
display:flex; align-items:center; justify-content:space-between;
}
.speed-slider-container { position:relative; margin:15px 0; }
.speed-slider {
width:100%; -webkit-appearance:none; appearance:none; height:8px;
background:linear-gradient(90deg, #333 0%, #666 100%); outline:none; opacity:0.9;
border-radius:4px; cursor:pointer;
}
.speed-slider:hover { opacity:1; }
.speed-slider::-webkit-slider-thumb {
-webkit-appearance:none; appearance:none; width:20px; height:20px;
background:linear-gradient(135deg, #FFC107 0%, #FF9800 100%); cursor:pointer;
border-radius:50%; border:2px solid #fff; box-shadow:0 2px 6px rgba(0,0,0,0.5);
}
.speed-slider::-moz-range-thumb {
width:20px; height:20px; background:linear-gradient(135deg, #FFC107 0%, #FF9800 100%);
cursor:pointer; border-radius:50%; border:2px solid #fff; box-shadow:0 2px 6px rgba(0,0,0,0.5);
}
.speed-marks {
display:flex; justify-content:space-between; margin-top:8px; font-size:10px; color:#888;
}
.speed-mark { text-align:center; cursor:pointer; transition:color 0.3s; }
.speed-mark:hover { color:#FFC107; }
.speed-mark.active { color:#FFC107; font-weight:bold; }
.current-speed {
margin-top:10px; padding:8px; background:rgba(255,193,7,0.1); border:1px solid #FFC107;
border-radius:4px; text-align:center; font-size:12px; color:#FFC107;
}
.time-display {
display:grid; grid-template-columns:repeat(2,1fr); gap:8px; margin-top:10px;
}
.time-item {
padding:6px; background:rgba(40,40,40,0.8); border-radius:4px; text-align:center;
border:1px solid #444;
}
.time-label { font-size:9px; color:#888; }
.time-value { font-size:11px; color:#4CAF50; font-weight:bold; }
.zoom-controls {
position:absolute; top:20px; left:20px; background:rgba(0,0,0,0.9);
padding:8px; border-radius:8px; z-index:20; border:1px solid #333;
display:flex; gap:5px; align-items:center;
}
.zoom-btn {
width:30px; height:30px; background:#444; border:1px solid #666; color:#fff;
cursor:pointer; border-radius:4px; font-size:16px; transition:all .3s;
display:flex; align-items:center; justify-content:center;
}
.zoom-btn:hover { background:#555; border-color:#4CAF50; }
.zoom-level { color:#4CAF50; font-size:11px; margin:0 8px; min-width:50px; text-align:center; }
::-webkit-scrollbar { width:8px; }
::-webkit-scrollbar-track { background:#1a1a1a; }
::-webkit-scrollbar-thumb { background:#555; border-radius:4px; }
::-webkit-scrollbar-thumb:hover { background:#666; }
</style>
</head>
<body>
<a href="https://discord.gg/openfreeai" target="_blank" class="discord-badge">
<img src="https://img.shields.io/static/v1?label=Discord&message=Openfree%20AI&color=%230000ff&labelColor=%23800080&logo=discord&logoColor=white&style=for-the-badge" alt="badge">
</a>
<div id="container">
<div id="sidebar">
<div class="control-section">
<h3>๐บ๏ธ OPERATION TERRAIN</h3>
<div class="terrain-selector">
<button class="terrain-btn active" data-terrain="urban">๐๏ธ Urban Warfare<br><small>Cities, Roads, Villages</small></button>
<button class="terrain-btn" data-terrain="mountain">โฐ๏ธ Mountain Highland<br><small>Rough Terrain, Villages</small></button>
</div>
<div class="terrain-controls">
<button class="terrain-control-btn active" id="toggle-contours">๐ Contours</button>
<button class="terrain-control-btn active" id="toggle-roads">๐ฃ๏ธ Roads</button>
<button class="terrain-control-btn active" id="toggle-rivers">๐ง Rivers</button>
<button class="terrain-control-btn" id="toggle-heatmap">๐ก๏ธ Heatmap</button>
<button class="terrain-control-btn" id="regenerate-terrain">๐ New Terrain</button>
</div>
</div>
<div class="control-section">
<h3>โ๏ธ MISSION TYPE</h3>
<div style="display:grid; grid-template-columns:1fr 1fr; gap:10px; margin-bottom:10px;">
<div style="padding:10px; background:rgba(33,150,243,0.2); border-radius:5px; border:1px solid #2196F3;">
<div style="font-size:11px; color:#2196F3; margin-bottom:5px;">BLUE TEAM MISSION</div>
<select id="blue-mission" style="width:100%; padding:5px; background:#333; color:#fff; border:1px solid #2196F3; border-radius:3px;">
<option value="attack">๐ก๏ธ ATTACK</option>
<option value="defend">๐ก๏ธ DEFEND</option>
</select>
</div>
<div style="padding:10px; background:rgba(244,67,54,0.2); border-radius:5px; border:1px solid #f44336;">
<div style="font-size:11px; color:#f44336; margin-bottom:5px;">RED TEAM MISSION</div>
<select id="red-mission" style="width:100%; padding:5px; background:#333; color:#fff; border:1px solid #f44336; border-radius:3px;">
<option value="attack">๐ก๏ธ ATTACK</option>
<option value="defend" selected>๐ก๏ธ DEFEND</option>
</select>
</div>
</div>
<div style="padding:8px; background:rgba(76,175,80,0.2); border-radius:5px; border:1px solid #4CAF50;">
<div style="font-size:10px; color:#4CAF50; line-height:1.4;">
<strong>Lanchester's Law Applied:</strong><br>
Defenders get 3:1 advantage ratio<br>
High ground provides additional bonus
</div>
</div>
</div>
<div class="control-section">
<h3>๐๏ธ NATION & FORCE SELECTION</h3>
<div class="side-selector">
<button class="side-btn active" data-side="blue">BLUE TEAM (South)</button>
<button class="side-btn" data-side="red">RED TEAM (North)</button>
</div>
<div class="country-selector">
<button class="country-btn roka active" data-country="roka">๐ฐ๐ท South Korea<br/>ROK</button>
<button class="country-btn kpa" data-country="kpa">๐ฐ๐ต North Korea<br/>DPRK</button>
<button class="country-btn usa" data-country="usa">๐บ๐ธ United States<br/>USA</button>
<button class="country-btn russia" data-country="russia">๐ท๐บ Russia<br/>RUS</button>
<button class="country-btn ukraine" data-country="ukraine">๐บ๐ฆ Ukraine<br/>UKR</button>
<button class="country-btn china" data-country="china">๐จ๐ณ China<br/>PRC</button>
</div>
<div class="unit-hierarchy" id="units-list">
<!-- Unit list will be dynamically generated -->
</div>
</div>
<div class="control-section">
<h3>๐ฒ QUICK DEPLOYMENT</h3>
<div style="display:grid; grid-template-columns:1fr 1fr; gap:8px;">
<button class="control-btn" id="random-blue" style="background:linear-gradient(135deg,#2196F3 0%,#1976D2 100%);">
๐ฒ Deploy Blue Regiment
</button>
<button class="control-btn" id="random-red" style="background:linear-gradient(135deg,#f44336 0%,#d32f2f 100%);">
๐ฒ Deploy Red Regiment
</button>
</div>
<button class="control-btn" id="random-both" style="width:100%; margin-top:8px; background:linear-gradient(135deg,#667eea 0%,#764ba2 100%);">
โ๏ธ Full Battle Setup
</button>
<p style="font-size:10px; color:#888; text-align:center; margin-top:10px;">
Deploys full regiment with proper organization
</p>
</div>
<div class="control-section">
<h3>๐ COMBAT POWER ANALYSIS</h3>
<div class="stats">
<div class="stat-item"><div class="stat-value" id="blue-units">0</div><div class="stat-label">Blue Forces</div></div>
<div class="stat-item"><div class="stat-value" id="red-units">0</div><div class="stat-label">Red Forces</div></div>
<div class="stat-item"><div class="stat-value" id="firepower-ratio">0%</div><div class="stat-label">Fire Superiority</div></div>
<div class="stat-item"><div class="stat-value" id="coverage">0%</div><div class="stat-label">Fire Coverage</div></div>
</div>
</div>
<div class="control-section">
<h3>๐ SELECTED UNIT INFO</h3>
<div id="info-panel">
<div>Unit: <span id="unit-name">-</span></div>
<div>Nation: <span id="unit-country">-</span></div>
<div>Size: <span id="unit-size">-</span></div>
<div>Strength: <span id="unit-strength">-</span></div>
<div>Weapons:<div class="weapons-list" id="unit-weapons">-</div></div>
<div>Effective Range: <span id="unit-range">-</span></div>
<div>Position: <span id="unit-position">-</span></div>
<div>Elevation: <span id="unit-elevation">-</span></div>
</div>
</div>
<div class="control-section">
<h3>โ๏ธ OPERATION TOOLS</h3>
<div class="control-buttons">
<button class="control-btn" id="analyze-coverage">Fire Coverage Analysis</button>
<button class="control-btn" id="analyze-terrain">Terrain Analysis</button>
<button class="control-btn" id="run-simulation">Combat Simulation</button>
<button class="control-btn" id="clear-all">Clear All</button>
</div>
</div>
<div class="control-section">
<h3>๐ฅ BATTLE COMMAND</h3>
<button class="control-btn" id="start-battle" style="width:100%; padding:15px; background:linear-gradient(135deg,#ff5252 0%,#ff1744 100%); font-size:14px; font-weight:bold;">
โ๏ธ START ENGAGEMENT
</button>
<button class="control-btn" id="pause-battle" style="width:100%; padding:10px; margin-top:5px; background:#666; display:none;">
โธ๏ธ PAUSE BATTLE
</button>
<div class="speed-control">
<div class="speed-control-title">
<span>โฑ๏ธ BATTLE TIME SPEED</span>
<span id="speed-display">1 MIN</span>
</div>
<div class="speed-slider-container">
<input type="range" class="speed-slider" id="speed-slider" min="0" max="4" value="0" step="1">
<div class="speed-marks">
<div class="speed-mark active" data-speed="0">1M</div>
<div class="speed-mark" data-speed="1">10M</div>
<div class="speed-mark" data-speed="2">1H</div>
<div class="speed-mark" data-speed="3">6H</div>
<div class="speed-mark" data-speed="4">1D</div>
</div>
</div>
<div class="current-speed" id="current-speed">
1 second = 1 minute of battle time
</div>
<div class="time-display">
<div class="time-item">
<div class="time-label">Battle Time</div>
<div class="time-value" id="battle-time">00:00:00</div>
</div>
<div class="time-item">
<div class="time-label">Real Time</div>
<div class="time-value" id="real-time">00:00:00</div>
</div>
</div>
</div>
<div style="margin-top:10px; padding:10px; background:rgba(30,30,30,0.8); border-radius:5px;">
<div style="font-size:11px; color:#888;">Battle Status</div>
<div id="battle-status" style="font-size:12px; color:#4CAF50; margin-top:5px;">Standby</div>
<div style="margin-top:10px;">
<div style="font-size:10px; color:#888;">Blue Casualties</div>
<div id="blue-casualties" style="font-size:14px; color:#2196F3;">0</div>
</div>
<div style="margin-top:5px;">
<div style="font-size:10px; color:#888;">Red Casualties</div>
<div id="red-casualties" style="font-size:14px; color:#f44336;">0</div>
</div>
</div>
</div>
</div>
<div id="map-container">
<canvas id="terrain-background"></canvas>
<canvas id="contour-canvas"></canvas>
<canvas id="map-canvas"></canvas>
<div class="zoom-controls">
<button class="zoom-btn" id="zoom-in">+</button>
<div class="zoom-level" id="zoom-level">100%</div>
<button class="zoom-btn" id="zoom-out">โ</button>
</div>
<div class="battlefield-divider" style="top:40%;"></div>
<div id="blue-zone">[ BLUE FORCE SECTOR ]</div>
<div id="red-zone">[ RED FORCE SECTOR ]</div>
<div class="legend">
<div class="legend-title">Unit Symbols</div>
<div class="legend-item"><div class="legend-symbol" style="color:#2196F3;">โ </div><span>Blue Battalion</span></div>
<div class="legend-item"><div class="legend-symbol" style="color:#2196F3;">โ</div><span>Blue Company</span></div>
<div class="legend-item"><div class="legend-symbol" style="color:#2196F3;">โฒ</div><span>Blue Platoon</span></div>
<div class="legend-item"><div class="legend-symbol" style="color:#f44336;">โ </div><span>Red Battalion</span></div>
<div class="legend-item"><div class="legend-symbol" style="color:#f44336;">โ</div><span>Red Company</span></div>
<div class="legend-item"><div class="legend-symbol" style="color:#f44336;">โฒ</div><span>Red Platoon</span></div>
</div>
<div class="scale-indicator" id="scale-indicator">
Battle Area: 20km ร 15km<br>
Scale: 1:5000<br>
Grid: 100m
</div>
<div class="status-bar">
<div class="coordinates">
Pos: X=<span id="mouse-x">0</span>, Y=<span id="mouse-y">0</span> |
Real: <span id="real-coords">0,0</span>km |
Elev: <span id="elevation">0</span>m |
Slope: <span id="slope">0</span>ยฐ |
Terrain: <span id="terrain-type">-</span>
</div>
<button class="control-btn" id="generate-report" style="padding:8px 20px;">๐ Operation Report</button>
</div>
</div>
</div>
<script>
// ===== Constants/Globals =====
let METERS_PER_PIXEL = 25;
const CONTACT_RADIUS = 20;
const SCALE = 5000;
const CONTOUR_INTERVAL = 0.05;
const TICK_INTERVAL = 100; // 100ms per tick
let canvas, ctx, terrainCanvas, terrainCtx, contourCanvas, contourCtx;
let selectedCountry = 'roka';
let selectedSide = 'blue';
let selectedUnitType = 'infantry_company';
let selectedTerrain = 'urban';
let units = [];
let heightMap = [];
let roads = [];
let rivers = [];
let settlements = [];
let mapWidth = 0, mapHeight = 0;
let battlefieldDivider = 0;
let zoomLevel = 1;
let offsetX = 0, offsetY = 0;
let isDragging = false;
let dragStartClientX = 0, dragStartClientY = 0;
let dragStartOffsetX = 0, dragStartOffsetY = 0;
let seed = Math.random() * 10000;
let blueMission = 'attack';
let redMission = 'defend';
let showContours = true;
let showRoads = true;
let showRivers = true;
let showHeatmap = false;
let battleActive = false;
let battleInterval = null;
let battleAnimationFrame = null;
let blueCasualties = 0;
let redCasualties = 0;
let explosions = [];
let bulletTrails = [];
let battleSpeed = 0;
let battleTimeElapsed = 0;
let realTimeElapsed = 0;
let battleStartTime = 0;
const speedMultipliers = [60, 600, 3600, 21600, 86400];
const speedLabels = ['1 MIN', '10 MIN', '1 HOUR', '6 HOURS', '1 DAY'];
const speedDescriptions = [
'1 second = 1 minute of battle time',
'1 second = 10 minutes of battle time',
'1 second = 1 hour of battle time',
'1 second = 6 hours of battle time',
'1 second = 1 day of battle time'
];
// ===== Country Unit Specifications =====
const countryUnits = {
roka: {
hq:{name:'HQ Battalion',symbol:'โฌ',size:'battalion',strength:50,weapons:['Command Systems','K2 Rifle','Intel Equipment'],range:1000,firepower:30,speed:50},
infantry_company:{name:'Infantry Company',symbol:'โ',size:'company',strength:140,weapons:['K2 Rifle','K201 Grenade Launcher','K3 LMG','K6 HMG'],range:800,firepower:100,speed:100},
infantry_platoon:{name:'Infantry Platoon',symbol:'โฒ',size:'platoon',strength:40,weapons:['K2 Rifle','K201 GL','K3 LMG'],range:600,firepower:40,speed:100},
mortar_81mm:{name:'81mm Mortar Company',symbol:'โ',size:'company',strength:80,weapons:['KM29A1 81mm Mortar','K2 Rifle'],range:5700,firepower:150,speed:80},
antitank_platoon:{name:'AT Platoon',symbol:'โ',size:'platoon',strength:35,weapons:['Hyungung ATGM','Panzerfaust 3','K2 Rifle'],range:2500,firepower:120,speed:100},
tank_company:{name:'Tank Company',symbol:'โ ',size:'company',strength:60,weapons:['K2 Black Panther (120mm)','K6 HMG'],range:4000,firepower:350,speed:500},
mech_company:{name:'Mechanized Company',symbol:'โฃ',size:'company',strength:120,weapons:['K21 IFV (40mm)','K6 HMG','K2 Rifle'],range:3000,firepower:250,speed:800},
artillery_155mm:{name:'K9 SPH Battalion',symbol:'โฌข',size:'battalion',strength:150,weapons:['K9 Thunder 155mm SPH','K2 Rifle'],range:18000,firepower:500,speed:400},
mlrs_chunmoo:{name:'Chunmoo MLRS Company',symbol:'โ',size:'company',strength:90,weapons:['K239 Chunmoo MLRS','K2 Rifle'],range:20000,firepower:600,speed:400},
attack_heli:{name:'AH-64E Company',symbol:'โ',size:'company',strength:40,weapons:['AH-64E Apache (30mm)','Hellfire Missile','Hydra 70 Rocket'],range:8000,firepower:450,speed:3000},
attack_drone:{name:'Attack Drone Company',symbol:'โ',size:'company',strength:30,weapons:['Loitering Munition','Recon Drone','Small Guided Missile'],range:10000,firepower:200,speed:1500},
air_defense:{name:'Cheonma AD Platoon',symbol:'โฆ',size:'platoon',strength:40,weapons:['Cheonma SAM','Shingung MANPADS','K2 Rifle'],range:3500,firepower:100,speed:400},
support_company:{name:'Support Company',symbol:'โ',size:'company',strength:150,weapons:['Transport Vehicles','Maintenance Equipment','K2 Rifle'],range:500,firepower:30,speed:500}
},
kpa: {
hq:{name:'HQ Battalion',symbol:'โฌ',size:'battalion',strength:45,weapons:['Command Systems','AK-74','Intel Equipment'],range:800,firepower:25,speed:50},
infantry_company:{name:'Infantry Company',symbol:'โ',size:'company',strength:130,weapons:['AK-74/Type-88','RPK LMG','RPG-7','PKM MG'],range:700,firepower:85,speed:100},
infantry_platoon:{name:'Infantry Platoon',symbol:'โฒ',size:'platoon',strength:35,weapons:['AK-74/Type-88','RPK LMG'],range:500,firepower:35,speed:100},
light_infantry:{name:'Light Infantry Platoon',symbol:'โฝ',size:'platoon',strength:30,weapons:['AK-74','RPG-7','LMG'],range:600,firepower:40,speed:120},
mortar_82mm:{name:'82mm Mortar Company',symbol:'โ',size:'company',strength:75,weapons:['82mm Mortar','AK-74'],range:4000,firepower:130,speed:80},
antitank_platoon:{name:'AT Platoon',symbol:'โ',size:'platoon',strength:30,weapons:['Bulsae-3 ATGM','RPG-7','AK-74'],range:2000,firepower:100,speed:100},
tank_company:{name:'Tank Company',symbol:'โ ',size:'company',strength:55,weapons:['Chonma/Songun Tank (125mm)','PKT MG'],range:3500,firepower:300,speed:400},
mech_company:{name:'Mechanized Company',symbol:'โฃ',size:'company',strength:110,weapons:['BMP-2 (30mm)','PKT MG','AK-74'],range:2500,firepower:200,speed:700},
mrls_company:{name:'BM-21 MLRS Company',symbol:'โ',size:'company',strength:90,weapons:['BM-21 122mm MLRS','AK-74'],range:20000,firepower:400,speed:400},
artillery_152mm:{name:'152mm SPH Battalion',symbol:'โฌข',size:'battalion',strength:140,weapons:['2S3 Akatsiya 152mm SPH','AK-74'],range:17300,firepower:400,speed:350},
attack_heli:{name:'Mi-24 Attack Heli',symbol:'โ',size:'company',strength:35,weapons:['Mi-24 Hind (12.7mm)','AT-2 Missile','S-5 Rocket'],range:6000,firepower:350,speed:2500},
antiair_platoon:{name:'AAA Platoon',symbol:'โฆ',size:'platoon',strength:35,weapons:['ZPU-4 14.5mm AAA','SA-7 MANPADS','AK-74'],range:3000,firepower:80,speed:300},
support_company:{name:'Support Company',symbol:'โ',size:'company',strength:140,weapons:['Transport Vehicles','Maintenance Equipment','AK-74'],range:400,firepower:25,speed:400}
},
usa: {
hq:{name:'Battalion HQ',symbol:'โฌ',size:'battalion',strength:60,weapons:['Command Systems','M4A1 Carbine','SINCGARS Radio'],range:1200,firepower:35,speed:50},
infantry_company:{name:'Infantry Company',symbol:'โ',size:'company',strength:150,weapons:['M4A1 Carbine','M249 SAW','M240B MG','M320 GL','AT4'],range:900,firepower:120,speed:100},
infantry_platoon:{name:'Infantry Platoon',symbol:'โฒ',size:'platoon',strength:45,weapons:['M4A1 Carbine','M249 SAW','M320 GL'],range:700,firepower:50,speed:100},
ranger_platoon:{name:'Ranger Platoon',symbol:'โ',size:'platoon',strength:40,weapons:['M4A1 SOPMOD','Mk48 MG','Carl Gustaf','M320 GL'],range:1000,firepower:80,speed:150},
mortar_120mm:{name:'120mm Mortar Platoon',symbol:'โ',size:'platoon',strength:60,weapons:['M120 120mm Mortar','M4A1 Carbine'],range:7200,firepower:180,speed:80},
javelin_team:{name:'Javelin Team',symbol:'โ',size:'squad',strength:12,weapons:['FGM-148 Javelin','M4A1 Carbine'],range:4750,firepower:150,speed:100},
abrams_platoon:{name:'M1A2 Platoon',symbol:'โ ',size:'platoon',strength:16,weapons:['M1A2 SEPv3 Abrams (120mm)','M2 .50 Cal','M240 MG'],range:4000,firepower:400,speed:600},
bradley_platoon:{name:'Bradley Platoon',symbol:'โฃ',size:'platoon',strength:28,weapons:['M2A3 Bradley (25mm)','TOW Missile','M240C MG'],range:3000,firepower:280,speed:900},
stryker_platoon:{name:'Stryker Platoon',symbol:'โข',size:'platoon',strength:36,weapons:['M1296 Stryker ICV (30mm)','M2 .50 Cal','M4A1 Carbine'],range:2500,firepower:220,speed:1000},
paladin_battery:{name:'M109A7 Battery',symbol:'โฌข',size:'battery',strength:100,weapons:['M109A7 Paladin 155mm SPH','M4A1 Carbine'],range:20000,firepower:550,speed:400},
himars_battery:{name:'HIMARS Battery',symbol:'โ',size:'battery',strength:80,weapons:['M142 HIMARS','GMLRS Rockets','M4A1 Carbine'],range:20000,firepower:700,speed:500},
apache_company:{name:'AH-64E Company',symbol:'โ',size:'company',strength:45,weapons:['AH-64E Apache (30mm)','AGM-114 Hellfire','Hydra 70 Rockets'],range:8000,firepower:500,speed:3000},
reaper_team:{name:'MQ-9 Reaper',symbol:'โ',size:'team',strength:10,weapons:['MQ-9 Reaper','AGM-114 Hellfire','GBU-12 Paveway'],range:15000,firepower:300,speed:2000},
patriot_battery:{name:'Patriot Battery',symbol:'โฆ',size:'battery',strength:90,weapons:['MIM-104 Patriot','PAC-3 MSE','M4A1 Carbine'],range:20000,firepower:200,speed:400},
support_company:{name:'Support Company',symbol:'โ',size:'company',strength:160,weapons:['M1083 FMTV','M4A1 Carbine'],range:500,firepower:35,speed:600}
},
russia: {
hq:{name:'Battalion HQ',symbol:'โฌ',size:'battalion',strength:55,weapons:['Command Systems','AK-12','R-187 Azart Radio'],range:1000,firepower:30,speed:50},
motor_rifle_company:{name:'Motor Rifle Company',symbol:'โ',size:'company',strength:135,weapons:['AK-12','PKP Pecheneg','RPG-7V2','AGS-30'],range:800,firepower:95,speed:100},
motor_rifle_platoon:{name:'Motor Rifle Platoon',symbol:'โฒ',size:'platoon',strength:38,weapons:['AK-12','PKP Pecheneg','RPG-7V2'],range:600,firepower:40,speed:100},
vdv_platoon:{name:'VDV Platoon',symbol:'โ',size:'platoon',strength:35,weapons:['AK-12','PKP Pecheneg','RPG-28','AGS-30'],range:800,firepower:65,speed:150},
mortar_120mm:{name:'120mm Mortar',symbol:'โ',size:'battery',strength:70,weapons:['2S12 Sani 120mm Mortar','AK-12'],range:7100,firepower:160,speed:80},
kornet_team:{name:'Kornet-EM Team',symbol:'โ',size:'squad',strength:10,weapons:['9M133 Kornet-EM ATGM','AK-12'],range:8000,firepower:140,speed:100},
t90_platoon:{name:'T-90M Platoon',symbol:'โ ',size:'platoon',strength:12,weapons:['T-90M Proryv (125mm)','Kord 12.7mm','PKT 7.62mm'],range:4000,firepower:380,speed:500},
t72_company:{name:'T-72B3 Company',symbol:'โ ',size:'company',strength:39,weapons:['T-72B3M (125mm)','Kord 12.7mm','PKT 7.62mm'],range:3500,firepower:320,speed:450},
bmp3_platoon:{name:'BMP-3 Platoon',symbol:'โฃ',size:'platoon',strength:30,weapons:['BMP-3 (100mm+30mm)','PKT 7.62mm','AK-12'],range:3000,firepower:260,speed:750},
btr82_platoon:{name:'BTR-82A Platoon',symbol:'โข',size:'platoon',strength:32,weapons:['BTR-82A (30mm)','PKT 7.62mm','AK-12'],range:2000,firepower:180,speed:900},
msta_battery:{name:'2S19 Msta-S',symbol:'โฌข',size:'battery',strength:120,weapons:['2S19 Msta-S 152mm SPH','AK-12'],range:20000,firepower:480,speed:400},
grad_battery:{name:'BM-21 Grad',symbol:'โ',size:'battery',strength:90,weapons:['BM-21 Grad 122mm MLRS','AK-12'],range:20000,firepower:450,speed:400},
ka52_squadron:{name:'Ka-52 Squadron',symbol:'โ',size:'squadron',strength:30,weapons:['Ka-52 Alligator (30mm)','Vikhr ATGM','S-8 Rockets'],range:10000,firepower:420,speed:2800},
orlan_team:{name:'Orlan-10 UAV',symbol:'โ',size:'team',strength:8,weapons:['Orlan-10 UAV','Laser Designator'],range:12000,firepower:50,speed:1200},
pantsir_battery:{name:'Pantsir-S1',symbol:'โฆ',size:'battery',strength:50,weapons:['Pantsir-S1 (30mm)','57E6 SAM','AK-12'],range:20000,firepower:150,speed:400},
support_company:{name:'Support Company',symbol:'โ',size:'company',strength:150,weapons:['KamAZ-5350','AK-12'],range:400,firepower:25,speed:500}
},
ukraine: {
hq:{name:'Battalion HQ',symbol:'โฌ',size:'battalion',strength:50,weapons:['Command Systems','AK-74M','Harris Radio'],range:1000,firepower:30,speed:50},
mech_infantry_company:{name:'Mech Infantry Company',symbol:'โ',size:'company',strength:130,weapons:['AK-74M','Fort-221','PKM','RPG-7'],range:750,firepower:90,speed:100},
infantry_platoon:{name:'Infantry Platoon',symbol:'โฒ',size:'platoon',strength:36,weapons:['AK-74M','Fort-221','PKM'],range:600,firepower:38,speed:100},
azov_platoon:{name:'Azov Platoon',symbol:'โ',size:'platoon',strength:35,weapons:['M4 WAC-47','Mk48 MG','NLAW','Carl Gustaf'],range:900,firepower:70,speed:120},
mortar_120mm:{name:'120mm Mortar',symbol:'โ',size:'battery',strength:65,weapons:['M120-15 Molot 120mm','AK-74M'],range:7000,firepower:155,speed:80},
stugna_team:{name:'Stugna-P Team',symbol:'โ',size:'squad',strength:8,weapons:['Stugna-P ATGM','AK-74M'],range:5000,firepower:130,speed:100},
nlaw_team:{name:'NLAW Team',symbol:'โ',size:'squad',strength:6,weapons:['NLAW','AK-74M'],range:800,firepower:100,speed:100},
t64_company:{name:'T-64BV Company',symbol:'โ ',size:'company',strength:39,weapons:['T-64BV (125mm)','NSVT 12.7mm','PKT 7.62mm'],range:3500,firepower:300,speed:450},
bmp2_platoon:{name:'BMP-2 Platoon',symbol:'โฃ',size:'platoon',strength:28,weapons:['BMP-2 (30mm)','Konkurs ATGM','PKT 7.62mm'],range:2500,firepower:200,speed:700},
btr4_platoon:{name:'BTR-4E Platoon',symbol:'โข',size:'platoon',strength:30,weapons:['BTR-4E (30mm)','Barrier ATGM','KT-7.62 MG'],range:2500,firepower:210,speed:850},
m777_battery:{name:'M777 Battery',symbol:'โฌข',size:'battery',strength:100,weapons:['M777 155mm Howitzer','AK-74M'],range:20000,firepower:450,speed:300},
caesar_battery:{name:'CAESAR Battery',symbol:'โฌข',size:'battery',strength:80,weapons:['CAESAR 155mm SPG','AK-74M'],range:20000,firepower:470,speed:450},
himars_battery:{name:'M142 HIMARS',symbol:'โ',size:'battery',strength:70,weapons:['M142 HIMARS','GMLRS','AK-74M'],range:20000,firepower:650,speed:500},
bayraktar_team:{name:'Bayraktar TB2',symbol:'โ',size:'team',strength:12,weapons:['Bayraktar TB2','MAM-L','MAM-C'],range:15000,firepower:250,speed:1800},
gepard_platoon:{name:'Gepard SPAAG',symbol:'โฆ',size:'platoon',strength:20,weapons:['Flakpanzer Gepard (35mm)','AK-74M'],range:5500,firepower:120,speed:400},
support_company:{name:'Support Company',symbol:'โ',size:'company',strength:140,weapons:['KrAZ-6322','AK-74M'],range:400,firepower:25,speed:500}
},
china: {
hq:{name:'Battalion HQ',symbol:'โฌ',size:'battalion',strength:55,weapons:['Command Systems','QBZ-95','Digital Radio'],range:1100,firepower:32,speed:50},
infantry_company:{name:'Infantry Company',symbol:'โ',size:'company',strength:145,weapons:['QBZ-95','QJY-88 MG','PF-98 RPG','QLZ-87 GL'],range:850,firepower:105,speed:100},
infantry_platoon:{name:'Infantry Platoon',symbol:'โฒ',size:'platoon',strength:42,weapons:['QBZ-95','QJY-88 MG','PF-89 RPG'],range:650,firepower:45,speed:100},
special_forces:{name:'Special Forces',symbol:'โ',size:'platoon',strength:30,weapons:['QBZ-95-1','CS/LR4 Sniper','HJ-12 ATGM','QJY-201 MG'],range:1200,firepower:85,speed:150},
mortar_120mm:{name:'120mm Mortar Company',symbol:'โ',size:'company',strength:75,weapons:['PP87 120mm Mortar','QBZ-95'],range:6800,firepower:165,speed:80},
hj12_team:{name:'HJ-12 AT Team',symbol:'โ',size:'squad',strength:8,weapons:['HJ-12 ATGM','QBZ-95'],range:4000,firepower:135,speed:100},
type99a_company:{name:'Type 99A Tank Company',symbol:'โ ',size:'company',strength:39,weapons:['ZTZ-99A (125mm)','QJC-88 12.7mm','Type 86 MG'],range:4000,firepower:370,speed:550},
zbd04_platoon:{name:'ZBD-04A IFV Platoon',symbol:'โฃ',size:'platoon',strength:30,weapons:['ZBD-04A (100mm+30mm)','HJ-8 ATGM','Type 86 MG'],range:3000,firepower:270,speed:800},
zbl08_platoon:{name:'ZBL-08 APC Platoon',symbol:'โข',size:'platoon',strength:33,weapons:['ZBL-08 (30mm)','HJ-73C ATGM','QJC-88 MG'],range:2500,firepower:220,speed:950},
plz05_battery:{name:'PLZ-05 SPH Battalion',symbol:'โฌข',size:'battalion',strength:120,weapons:['PLZ-05 155mm SPH','QBZ-95'],range:20000,firepower:520,speed:400},
pcl191_battery:{name:'PCL-191 MLRS',symbol:'โ',size:'battery',strength:90,weapons:['PCL-191 MLRS System','QBZ-95'],range:20000,firepower:750,speed:450},
wz10_squadron:{name:'WZ-10 Squadron',symbol:'โ',size:'squadron',strength:35,weapons:['WZ-10 (23mm)','HJ-10 ATGM','TY-90 AAM'],range:8000,firepower:430,speed:2700},
ch5_team:{name:'CH-5 UAV',symbol:'โ',size:'team',strength:10,weapons:['CH-5 UAV','AR-1 Missile','AR-2 Missile'],range:14000,firepower:280,speed:1600},
hq17_battery:{name:'HQ-17 SAM',symbol:'โฆ',size:'battery',strength:60,weapons:['HQ-17 SAM System','35mm AAA','QBZ-95'],range:15000,firepower:140,speed:400},
support_company:{name:'Support Company',symbol:'โ',size:'company',strength:155,weapons:['Dongfeng Mengshi','QBZ-95'],range:450,firepower:28,speed:600}
}
};
const countryInfo = {
roka: { name: 'ROK Army', color: '#2196F3' },
kpa: { name: 'Korean People\'s Army', color: '#f44336' },
usa: { name: 'US Army', color: '#1976D2' },
russia: { name: 'Russian Ground Forces', color: '#D32F2F' },
ukraine: { name: 'Ukrainian Army', color: '#FFD700' },
china: { name: 'PLA Ground Force', color: '#FF5722' }
};
// Mission type controls
document.getElementById('blue-mission').addEventListener('change', function() {
blueMission = this.value;
if (blueMission === 'defend' && redMission === 'defend') {
redMission = 'attack';
document.getElementById('red-mission').value = 'attack';
} else if (blueMission === 'attack' && redMission === 'attack') {
redMission = 'defend';
document.getElementById('red-mission').value = 'defend';
}
});
document.getElementById('red-mission').addEventListener('change', function() {
redMission = this.value;
if (redMission === 'defend' && blueMission === 'defend') {
blueMission = 'attack';
document.getElementById('blue-mission').value = 'attack';
} else if (redMission === 'attack' && blueMission === 'attack') {
blueMission = 'defend';
document.getElementById('blue-mission').value = 'defend';
}
});
// ===== CRITICAL FIX: Common View Transform =====
function applyViewTransform(context) {
context.save();
context.translate(mapWidth/2, mapHeight/2);
context.scale(zoomLevel, zoomLevel);
context.translate(-mapWidth/2 + offsetX, -mapHeight/2 + offsetY);
}
function restoreViewTransform(context) {
context.restore();
}
// ===== Enhanced Terrain System =====
function noise(x, y, scale, octaves) {
let value = 0;
let amplitude = 1;
let frequency = scale;
let maxValue = 0;
for (let i = 0; i < octaves; i++) {
value += amplitude * simpleNoise(x * frequency + seed, y * frequency + seed);
maxValue += amplitude;
amplitude *= 0.5;
frequency *= 2;
}
return value / maxValue;
}
function simpleNoise(x, y) {
const n = Math.sin(x * 12.9898 + y * 78.233) * 43758.5453;
return (n - Math.floor(n)) * 2 - 1;
}
function generateTerrain() {
console.log('Generating terrain:', selectedTerrain);
seed = Math.random() * 10000;
heightMap = [];
roads = [];
rivers = [];
settlements = [];
const gridSize = 50;
for (let y = 0; y < gridSize; y++) {
heightMap[y] = [];
for (let x = 0; x < gridSize; x++) {
let height = 0;
switch(selectedTerrain) {
case 'mountain':
height = noise(x, y, 0.03, 4) * 0.6;
height = Math.pow(Math.abs(height), 1.2) * Math.sign(height);
break;
case 'urban':
height = noise(x, y, 0.015, 2) * 0.1 + 0.15;
break;
default:
height = 0.3;
}
height = Math.max(0, Math.min(1, (height + 1) / 2));
heightMap[y][x] = height;
}
}
generateRoads(gridSize);
generateRivers(gridSize);
generateSettlements(gridSize);
console.log('Terrain generated successfully');
}
function generateRoads(gridSize) {
roads = [];
// ๋๋ก๋ฅผ ๋ ๋ง์ด ์์ฑ (๊ธฐ์กด๋ณด๋ค 2๋ฐฐ)
const numRoads = selectedTerrain === 'urban' ? 16 : 8;
// ์ฃผ์ ๋๋ก ๋คํธ์ํฌ ์์ฑ
for (let i = 0; i < numRoads; i++) {
const road = [];
let x, y, targetX, targetY;
if (i < 4) {
// ๋จ๋ถ ์ฐ๊ฒฐ ์ฃผ์ ๋๋ก
x = (gridSize / 4) * (i + 0.5) + (Math.random() - 0.5) * 10;
y = 0;
targetX = x + (Math.random() - 0.5) * 20;
targetY = gridSize - 1;
} else if (i < 8) {
// ๋์ ์ฐ๊ฒฐ ์ฃผ์ ๋๋ก
x = 0;
y = (gridSize / 4) * (i - 3.5) + (Math.random() - 0.5) * 10;
targetX = gridSize - 1;
targetY = y + (Math.random() - 0.5) * 20;
} else {
// ๋๊ฐ์ ๋ฐ ๋ณด์กฐ ๋๋ก
x = Math.random() * gridSize;
y = Math.random() * gridSize;
targetX = Math.random() * gridSize;
targetY = Math.random() * gridSize;
}
const maxSteps = 100;
for (let step = 0; step < maxSteps; step++) {
road.push({ x: Math.floor(x), y: Math.floor(y) });
const dx = targetX - x;
const dy = targetY - y;
const dist = Math.sqrt(dx * dx + dy * dy);
if (dist < 2) break;
const angle = Math.atan2(dy, dx);
// ๋๋ก๋ฅผ ์ข ๋ ์ง์ ์ ์ผ๋ก
x += Math.cos(angle) * 1.5 + (Math.random() - 0.5) * 0.3;
y += Math.sin(angle) * 1.5 + (Math.random() - 0.5) * 0.3;
x = Math.max(0, Math.min(gridSize - 1, x));
y = Math.max(0, Math.min(gridSize - 1, y));
}
if (road.length > 5) {
roads.push(road);
}
}
}
function generateRivers(gridSize) {
rivers = [];
const numRivers = selectedTerrain === 'mountain' ? 3 : 1;
for (let i = 0; i < numRivers; i++) {
const river = [];
let x = Math.random() * gridSize;
let y = Math.random() * gridSize;
const maxSteps = 100;
for (let step = 0; step < maxSteps; step++) {
const ix = Math.floor(x);
const iy = Math.floor(y);
if (ix < 0 || ix >= gridSize || iy < 0 || iy >= gridSize) break;
river.push({ x: ix, y: iy });
let moved = false;
const currentHeight = heightMap[iy] && heightMap[iy][ix] ? heightMap[iy][ix] : 0;
for (let attempts = 0; attempts < 8; attempts++) {
const angle = Math.random() * Math.PI * 2;
const nx = x + Math.cos(angle) * 1.5;
const ny = y + Math.sin(angle) * 1.5;
const nix = Math.floor(nx);
const niy = Math.floor(ny);
if (nix >= 0 && nix < gridSize && niy >= 0 && niy < gridSize) {
const nextHeight = heightMap[niy] && heightMap[niy][nix] ? heightMap[niy][nix] : 0;
if (nextHeight <= currentHeight) {
x = nx;
y = ny;
moved = true;
break;
}
}
}
if (!moved) {
x += (Math.random() - 0.5) * 2;
y += (Math.random() - 0.5) * 2;
}
x = Math.max(0, Math.min(gridSize - 1, x));
y = Math.max(0, Math.min(gridSize - 1, y));
if (currentHeight < 0.2) break;
}
if (river.length > 5) {
rivers.push(river);
}
}
}
function generateSettlements(gridSize) {
settlements = [];
// ๋๋ก ๊ต์ฐจ์ ๊ณผ ๋๋ก๋ณ์ ๋ง์ ๋ฐฐ์น
const villagePositions = [];
// ๋๋ก ๊ต์ฐจ์ ์ฐพ๊ธฐ
for (let i = 0; i < roads.length - 1; i++) {
for (let j = i + 1; j < roads.length; j++) {
for (let p1 of roads[i]) {
for (let p2 of roads[j]) {
const dist = Math.sqrt(Math.pow(p1.x - p2.x, 2) + Math.pow(p1.y - p2.y, 2));
if (dist < 3) {
villagePositions.push({
x: Math.floor((p1.x + p2.x) / 2),
y: Math.floor((p1.y + p2.y) / 2),
importance: 2 // ๊ต์ฐจ์ ์ ์ค์๋ ๋์
});
}
}
}
}
}
// ๋๋ก๋ณ์ ์ถ๊ฐ ๋ง์ ๋ฐฐ์น
for (let road of roads) {
const numVillages = Math.floor(road.length / 15) + 1;
for (let i = 0; i < numVillages; i++) {
const idx = Math.floor(Math.random() * road.length);
const point = road[idx];
if (point) {
villagePositions.push({
x: point.x + Math.floor((Math.random() - 0.5) * 2),
y: point.y + Math.floor((Math.random() - 0.5) * 2),
importance: 1
});
}
}
}
// ์ค๋ณต ์ ๊ฑฐ ๋ฐ ์ต์ข
๋ง์ ์์ฑ
const uniquePositions = [];
for (let pos of villagePositions) {
let tooClose = false;
for (let existing of uniquePositions) {
const dist = Math.sqrt(Math.pow(pos.x - existing.x, 2) + Math.pow(pos.y - existing.y, 2));
if (dist < 5) {
tooClose = true;
break;
}
}
if (!tooClose && pos.x >= 0 && pos.x < gridSize && pos.y >= 0 && pos.y < gridSize) {
uniquePositions.push(pos);
}
}
// ๋ง์ ์์ฑ
for (let pos of uniquePositions) {
const height = heightMap[pos.y][pos.x];
if (height > 0.15 && height < 0.8) { // ๋ฌผ๊ณผ ๋์ ์ฐ ์ ์ธ
let type, size;
if (selectedTerrain === 'urban') {
if (pos.importance === 2 && Math.random() < 0.5) {
type = 'city';
size = 12 + Math.random() * 8;
} else if (pos.importance === 2 || Math.random() < 0.3) {
type = 'town';
size = 8 + Math.random() * 4;
} else {
type = 'village';
size = 4 + Math.random() * 3;
}
} else { // mountain
if (pos.importance === 2 && Math.random() < 0.3) {
type = 'town';
size = 6 + Math.random() * 3;
} else {
type = 'village';
size = 3 + Math.random() * 2;
}
}
settlements.push({
x: pos.x,
y: pos.y,
type: type,
size: size,
importance: pos.importance
});
}
}
console.log(`Generated ${settlements.length} settlements along ${roads.length} roads`);
}
// ===== FIXED: drawTerrain with View Transform =====
function drawTerrain() {
if (!terrainCtx || !heightMap || heightMap.length === 0) return;
const gridSize = heightMap.length;
const cellWidth = mapWidth / gridSize;
const cellHeight = mapHeight / gridSize;
terrainCtx.clearRect(0, 0, mapWidth, mapHeight);
applyViewTransform(terrainCtx);
try {
for (let y = 0; y < gridSize; y++) {
for (let x = 0; x < gridSize; x++) {
if (!heightMap[y] || heightMap[y][x] === undefined) continue;
const height = heightMap[y][x];
if (showHeatmap) {
const hue = (1 - height) * 240;
terrainCtx.fillStyle = `hsl(${hue}, 70%, 50%)`;
} else {
terrainCtx.fillStyle = getTerrainColor(height);
}
terrainCtx.fillRect(
x * cellWidth,
y * cellHeight,
cellWidth + 1,
cellHeight + 1
);
}
}
if (showRivers && rivers && rivers.length > 0) {
rivers.forEach(river => {
if (!river || river.length === 0) return;
terrainCtx.strokeStyle = '#4682B4';
terrainCtx.lineWidth = 3;
terrainCtx.beginPath();
river.forEach((point, index) => {
if (!point) return;
const x = point.x * cellWidth;
const y = point.y * cellHeight;
if (index === 0) {
terrainCtx.moveTo(x, y);
} else {
terrainCtx.lineTo(x, y);
}
});
terrainCtx.stroke();
});
}
if (showRoads && roads && roads.length > 0) {
roads.forEach(road => {
if (!road || road.length === 0) return;
terrainCtx.strokeStyle = '#555';
terrainCtx.lineWidth = 2;
terrainCtx.setLineDash([5, 3]);
terrainCtx.beginPath();
road.forEach((point, index) => {
if (!point) return;
const x = point.x * cellWidth;
const y = point.y * cellHeight;
if (index === 0) {
terrainCtx.moveTo(x, y);
} else {
terrainCtx.lineTo(x, y);
}
});
terrainCtx.stroke();
terrainCtx.setLineDash([]);
});
}
if (settlements && settlements.length > 0) {
settlements.forEach(settlement => {
if (!settlement) return;
const x = settlement.x * cellWidth;
const y = settlement.y * cellHeight;
if (settlement.type === 'city') {
terrainCtx.fillStyle = '#666';
terrainCtx.fillRect(x - settlement.size/2, y - settlement.size/2, settlement.size, settlement.size);
terrainCtx.strokeStyle = '#333';
terrainCtx.strokeRect(x - settlement.size/2, y - settlement.size/2, settlement.size, settlement.size);
} else if (settlement.type === 'town') {
terrainCtx.fillStyle = '#7A6A5A';
terrainCtx.fillRect(x - settlement.size/2, y - settlement.size/2, settlement.size, settlement.size);
} else if (settlement.type === 'village') {
terrainCtx.fillStyle = '#8B7355';
terrainCtx.beginPath();
terrainCtx.arc(x, y, settlement.size, 0, Math.PI * 2);
terrainCtx.fill();
}
});
}
} catch(error) {
console.error('Error drawing terrain:', error);
}
restoreViewTransform(terrainCtx);
}
// ===== FIXED: drawContours with View Transform =====
function drawContours() {
if (!contourCtx || !showContours || !heightMap || heightMap.length === 0) return;
const gridSize = heightMap.length;
const cellWidth = mapWidth / gridSize;
const cellHeight = mapHeight / gridSize;
contourCtx.clearRect(0, 0, mapWidth, mapHeight);
applyViewTransform(contourCtx);
const contourLevels = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9];
try {
for (let level of contourLevels) {
contourCtx.beginPath();
for (let y = 0; y < gridSize - 1; y++) {
for (let x = 0; x < gridSize - 1; x++) {
if (!heightMap[y] || !heightMap[y+1] ||
heightMap[y][x] === undefined || heightMap[y][x+1] === undefined ||
heightMap[y+1][x] === undefined || heightMap[y+1][x+1] === undefined) {
continue;
}
const corners = [
heightMap[y][x],
heightMap[y][x + 1],
heightMap[y + 1][x + 1],
heightMap[y + 1][x]
];
drawContourCell(
x * cellWidth,
y * cellHeight,
cellWidth,
cellHeight,
corners,
level
);
}
}
if (level % 0.2 === 0) {
contourCtx.lineWidth = 2;
contourCtx.strokeStyle = 'rgba(0, 0, 0, 0.5)';
} else {
contourCtx.lineWidth = 1;
contourCtx.strokeStyle = 'rgba(0, 0, 0, 0.3)';
}
contourCtx.stroke();
}
} catch(error) {
console.error('Error drawing contours:', error);
}
restoreViewTransform(contourCtx);
}
function drawContourCell(x, y, width, height, corners, level) {
let state = 0;
if (corners[0] > level) state |= 1;
if (corners[1] > level) state |= 2;
if (corners[2] > level) state |= 4;
if (corners[3] > level) state |= 8;
switch(state) {
case 1: case 14:
drawLine(contourCtx, x, y + height * interpolate(corners[0], corners[3], level),
x + width * interpolate(corners[0], corners[1], level), y);
break;
case 2: case 13:
drawLine(contourCtx, x + width * interpolate(corners[0], corners[1], level), y,
x + width, y + height * interpolate(corners[1], corners[2], level));
break;
case 3: case 12:
drawLine(contourCtx, x, y + height * interpolate(corners[0], corners[3], level),
x + width, y + height * interpolate(corners[1], corners[2], level));
break;
case 4: case 11:
drawLine(contourCtx, x + width, y + height * interpolate(corners[1], corners[2], level),
x + width * interpolate(corners[3], corners[2], level), y + height);
break;
case 5:
drawLine(contourCtx, x, y + height * interpolate(corners[0], corners[3], level),
x + width * interpolate(corners[0], corners[1], level), y);
drawLine(contourCtx, x + width, y + height * interpolate(corners[1], corners[2], level),
x + width * interpolate(corners[3], corners[2], level), y + height);
break;
case 6: case 9:
drawLine(contourCtx, x + width * interpolate(corners[0], corners[1], level), y,
x + width * interpolate(corners[3], corners[2], level), y + height);
break;
case 7: case 8:
drawLine(contourCtx, x, y + height * interpolate(corners[0], corners[3], level),
x + width * interpolate(corners[3], corners[2], level), y + height);
break;
case 10:
drawLine(contourCtx, x + width * interpolate(corners[0], corners[1], level), y,
x + width, y + height * interpolate(corners[1], corners[2], level));
drawLine(contourCtx, x, y + height * interpolate(corners[0], corners[3], level),
x + width * interpolate(corners[3], corners[2], level), y + height);
break;
}
}
function interpolate(v1, v2, level) {
if (v1 === v2) return 0;
return (level - v1) / (v2 - v1);
}
function drawLine(context, x1, y1, x2, y2) {
context.moveTo(x1, y1);
context.lineTo(x2, y2);
}
function getTerrainColor(height) {
if (height < 0.15) return '#0d4f8b';
if (height < 0.25) return '#1e7eb8';
if (height < 0.35) return '#61a861';
if (height < 0.45) return '#8fc68f';
if (height < 0.55) return '#c4d4aa';
if (height < 0.65) return '#f5deb3';
if (height < 0.75) return '#d2b48c';
if (height < 0.85) return '#8b5a2b';
return '#d9d9d9'; // ์ฐํ ํ์์ผ๋ก ๋ณ๊ฒฝ
}
function getHeightAt(x, y) {
if (!heightMap || heightMap.length === 0) return 0.3;
const gridSize = heightMap.length;
const cellWidth = mapWidth / gridSize;
const cellHeight = mapHeight / gridSize;
const gridX = Math.floor(x / cellWidth);
const gridY = Math.floor(y / cellHeight);
if (gridX >= 0 && gridX < gridSize && gridY >= 0 && gridY < gridSize) {
if (heightMap[gridY] && heightMap[gridY][gridX] !== undefined) {
return heightMap[gridY][gridX];
}
}
return 0.3;
}
function getSlope(x, y) {
if (!heightMap || heightMap.length === 0) return 0;
const gridSize = heightMap.length;
const cellWidth = mapWidth / gridSize;
const cellHeight = mapHeight / gridSize;
const gx = Math.floor(x / cellWidth);
const gy = Math.floor(y / cellHeight);
if (gx <= 0 || gx >= gridSize - 1 || gy <= 0 || gy >= gridSize - 1) return 0;
// ๊ณ ๋ ์ค์ผ์ผ: 0~1 -> 0~1000m
const h = (ix, iy) => (heightMap[iy]?.[ix] ?? 0) * 1000;
const dzdx = (h(gx+1, gy) - h(gx-1, gy)) / (2 * cellWidth * METERS_PER_PIXEL);
const dzdy = (h(gx, gy+1) - h(gx, gy-1)) / (2 * cellHeight * METERS_PER_PIXEL);
const gradient = Math.sqrt(dzdx*dzdx + dzdy*dzdy); // ์ํ 1m๋น ๊ณ ๋ ๋ณํ(m/m)
const angleRad = Math.atan(gradient);
return Math.round(angleRad * 180 / Math.PI); // ๋ ๋จ์
}
// ===== Initialization =====
window.addEventListener('DOMContentLoaded', () => {
console.log('Initializing simulator...');
canvas = document.getElementById('map-canvas');
terrainCanvas = document.getElementById('terrain-background');
contourCanvas = document.getElementById('contour-canvas');
if (!canvas || !terrainCanvas || !contourCanvas) {
console.error('Canvas elements not found');
return;
}
ctx = canvas.getContext('2d');
terrainCtx = terrainCanvas.getContext('2d');
contourCtx = contourCanvas.getContext('2d');
if (!ctx || !terrainCtx || !contourCtx) {
console.error('Canvas context initialization failed');
return;
}
// Initialize canvas size first
setCanvasSizeWithDPR();
// Setup event listeners
setupEventListeners();
setupSpeedControl();
updateUnitsList();
// Generate and draw terrain
try {
generateTerrain();
drawTerrain();
drawContours();
drawMap();
console.log('Terrain generated and drawn successfully');
} catch(error) {
console.error('Error during initialization:', error);
}
});
function setCanvasSizeWithDPR(){
const container = document.getElementById('map-container');
if (!container) {
console.error('Map container not found');
return;
}
const rect = container.getBoundingClientRect();
const dpr = window.devicePixelRatio || 1;
// Ensure minimum size
mapWidth = Math.max(600, Math.floor(rect.width));
mapHeight = Math.max(400, Math.floor(rect.height));
battlefieldDivider = Math.floor(mapHeight * 0.4);
METERS_PER_PIXEL = ((20000 / mapWidth) + (15000 / mapHeight)) / 2;
console.log(`Canvas size: ${mapWidth}x${mapHeight}, DPR: ${dpr}, Scale: ${METERS_PER_PIXEL}m/px`);
// Set canvas display size
terrainCanvas.style.width = mapWidth + 'px';
terrainCanvas.style.height = mapHeight + 'px';
contourCanvas.style.width = mapWidth + 'px';
contourCanvas.style.height = mapHeight + 'px';
canvas.style.width = mapWidth + 'px';
canvas.style.height = mapHeight + 'px';
// Set canvas actual size with DPR
terrainCanvas.width = mapWidth * dpr;
terrainCanvas.height = mapHeight * dpr;
contourCanvas.width = mapWidth * dpr;
contourCanvas.height = mapHeight * dpr;
canvas.width = mapWidth * dpr;
canvas.height = mapHeight * dpr;
// Scale context for DPR
terrainCtx.scale(dpr, dpr);
contourCtx.scale(dpr, dpr);
ctx.scale(dpr, dpr);
const scaleText = `Battle Area: 20km ร 15km<br>Scale: 1:${SCALE}<br>Grid: ${Math.round(METERS_PER_PIXEL)}m/px`;
document.getElementById('scale-indicator').innerHTML = scaleText;
}
function setupEventListeners() {
document.querySelectorAll('.terrain-btn').forEach(btn=>{
btn.addEventListener('click', function(){ selectTerrain(this.getAttribute('data-terrain'), this); });
});
document.getElementById('toggle-contours').addEventListener('click', function() {
showContours = !showContours;
this.classList.toggle('active');
drawContours();
});
document.getElementById('toggle-roads').addEventListener('click', function() {
showRoads = !showRoads;
this.classList.toggle('active');
drawTerrain();
});
document.getElementById('toggle-rivers').addEventListener('click', function() {
showRivers = !showRivers;
this.classList.toggle('active');
drawTerrain();
});
document.getElementById('toggle-heatmap').addEventListener('click', function() {
showHeatmap = !showHeatmap;
this.classList.toggle('active');
drawTerrain();
});
document.getElementById('regenerate-terrain').addEventListener('click', function() {
generateTerrain();
drawTerrain();
drawContours();
});
document.querySelectorAll('.side-btn').forEach(btn=>{
btn.addEventListener('click', function(){ selectSide(this.getAttribute('data-side')); });
});
document.querySelectorAll('.country-btn').forEach(btn=>{
btn.addEventListener('click', function(){ selectCountry(this.getAttribute('data-country')); });
});
document.getElementById('zoom-in').addEventListener('click', zoomIn);
document.getElementById('zoom-out').addEventListener('click', zoomOut);
document.getElementById('random-blue').addEventListener('click', () => randomRegimentDeployment('blue'));
document.getElementById('random-red').addEventListener('click', () => randomRegimentDeployment('red'));
document.getElementById('random-both').addEventListener('click', randomFullBattleSetup);
document.getElementById('analyze-coverage').addEventListener('click', analyzeCoverage);
document.getElementById('analyze-terrain').addEventListener('click', analyzeTerrain);
document.getElementById('run-simulation').addEventListener('click', runSimulation);
document.getElementById('clear-all').addEventListener('click', clearAll);
document.getElementById('generate-report').addEventListener('click', generateReport);
document.getElementById('start-battle').addEventListener('click', startBattle);
document.getElementById('pause-battle').addEventListener('click', pauseBattle);
canvas.addEventListener('click', handleMapClick);
canvas.addEventListener('mousemove', handleMouseMove);
canvas.addEventListener('mousedown', handleMouseDown);
canvas.addEventListener('mouseup', handleMouseUp);
canvas.addEventListener('wheel', handleWheel, { passive: false });
canvas.addEventListener('contextmenu', (e) => e.preventDefault()); // ์ฐํด๋ฆญ ๋ฉ๋ด ๋ฐฉ์ง
// Window resize handler
window.addEventListener('resize', () => {
setCanvasSizeWithDPR();
drawTerrain();
drawContours();
drawMap();
});
}
function setupSpeedControl() {
const slider = document.getElementById('speed-slider');
const speedDisplay = document.getElementById('speed-display');
const currentSpeed = document.getElementById('current-speed');
const speedMarks = document.querySelectorAll('.speed-mark');
slider.addEventListener('input', function() {
battleSpeed = parseInt(this.value);
updateSpeedDisplay();
});
speedMarks.forEach(mark => {
mark.addEventListener('click', function() {
const speed = parseInt(this.getAttribute('data-speed'));
slider.value = speed;
battleSpeed = speed;
updateSpeedDisplay();
});
});
function updateSpeedDisplay() {
speedDisplay.textContent = speedLabels[battleSpeed];
currentSpeed.textContent = speedDescriptions[battleSpeed];
speedMarks.forEach(mark => {
mark.classList.remove('active');
if (parseInt(mark.getAttribute('data-speed')) === battleSpeed) {
mark.classList.add('active');
}
});
}
}
function formatTime(seconds) {
const hours = Math.floor(seconds / 3600);
const minutes = Math.floor((seconds % 3600) / 60);
const secs = Math.floor(seconds % 60);
return `${String(hours).padStart(2, '0')}:${String(minutes).padStart(2, '0')}:${String(secs).padStart(2, '0')}`;
}
function updateTimeDisplay() {
if (battleActive && battleStartTime) {
const now = Date.now();
const realDelta = (now - battleStartTime) / 1000; // seconds
realTimeElapsed = realDelta;
// Calculate battle time based on speed multiplier
battleTimeElapsed = realDelta * speedMultipliers[battleSpeed];
document.getElementById('battle-time').textContent = formatTime(battleTimeElapsed);
document.getElementById('real-time').textContent = formatTime(realTimeElapsed);
}
}
// ===== Zoom Functions with Cursor-centered Zoom =====
function zoomAt(cx, cy, factor) {
const prevZoom = zoomLevel;
const newZoom = Math.min(4, Math.max(0.5, zoomLevel * factor));
if (newZoom === prevZoom) return;
const rect = canvas.getBoundingClientRect();
const scaleX = mapWidth / rect.width;
const scaleY = mapHeight / rect.height;
// ํ๋ฉด ์ขํ -> ๋งต ์ขํ
const x = ((cx - rect.left) * scaleX - mapWidth/2) / prevZoom + mapWidth/2 - offsetX;
const y = ((cy - rect.top) * scaleY - mapHeight/2) / prevZoom + mapHeight/2 - offsetY;
zoomLevel = newZoom;
// ์ปค์๊ฐ ๊ฐ๋ฆฌํค๋ ์๋ ํฌ์ธํธ๊ฐ ํ๋ฉด์ ๊ณ ์ ๋๋๋ก ์คํ์
๋ณด์
const x2 = ((cx - rect.left) * scaleX - mapWidth/2) / zoomLevel + mapWidth/2 - offsetX;
const y2 = ((cy - rect.top) * scaleY - mapHeight/2) / zoomLevel + mapHeight/2 - offsetY;
offsetX += (x2 - x);
offsetY += (y2 - y);
updateZoomDisplay();
drawMap();
drawTerrain();
drawContours();
}
function zoomIn(e) {
const rect = canvas.getBoundingClientRect();
const cx = e?.clientX ?? (rect.left + rect.width/2);
const cy = e?.clientY ?? (rect.top + rect.height/2);
zoomAt(cx, cy, 1.2);
}
function zoomOut(e) {
const rect = canvas.getBoundingClientRect();
const cx = e?.clientX ?? (rect.left + rect.width/2);
const cy = e?.clientY ?? (rect.top + rect.height/2);
zoomAt(cx, cy, 1/1.2);
}
function updateZoomDisplay() {
document.getElementById('zoom-level').textContent = Math.round(zoomLevel * 100) + '%';
}
function handleWheel(e) {
e.preventDefault();
if (e.deltaY < 0) {
zoomIn(e);
} else {
zoomOut(e);
}
}
function handleMouseDown(e) {
// ์ค๋ฒํผ, ์ฐ๋ฒํผ, ๋๋ Shift+์ขํด๋ฆญ ํ์ฉ
if (e.button === 1 || e.button === 2 || (e.button === 0 && e.shiftKey)) {
isDragging = true;
dragStartClientX = e.clientX;
dragStartClientY = e.clientY;
dragStartOffsetX = offsetX;
dragStartOffsetY = offsetY;
canvas.style.cursor = 'grabbing';
e.preventDefault();
}
}
function handleMouseUp() {
isDragging = false;
canvas.style.cursor = 'crosshair';
}
// ===== Selection Functions =====
function selectTerrain(type, element){
selectedTerrain = type;
document.querySelectorAll('.terrain-btn').forEach(b=>b.classList.remove('active'));
if(element) element.classList.add('active');
if(battleActive) {
pauseBattle();
}
try {
generateTerrain();
drawTerrain();
drawContours();
drawMap();
} catch(error) {
console.error('Error generating terrain:', error);
alert('Error generating terrain. Please try again.');
}
}
function selectSide(side){
selectedSide = side;
document.querySelectorAll('.side-btn').forEach(b=>b.classList.remove('active'));
document.querySelector(`.side-btn[data-side="${side}"]`).classList.add('active');
}
function selectCountry(country){
selectedCountry = country;
document.querySelectorAll('.country-btn').forEach(b=>b.classList.remove('active'));
document.querySelector(`.country-btn[data-country="${country}"]`).classList.add('active');
updateUnitsList();
}
function updateUnitsList(){
const unitsList = document.getElementById('units-list');
const units = countryUnits[selectedCountry];
const info = countryInfo[selectedCountry];
let html = `<div class="unit-level-title" style="color:${info.color}; margin-bottom:10px;">${info.name} Order of Battle</div>`;
html += '<div class="unit-options">';
for(const [key, unit] of Object.entries(units)){
html += `<button class="unit-btn${key === 'infantry_company' ? ' active' : ''}" data-unit="${key}">${unit.name}</button>`;
}
html += '</div>';
unitsList.innerHTML = html;
selectedUnitType = 'infantry_company';
document.querySelectorAll('.unit-btn').forEach(btn=>{
btn.addEventListener('click', function(){ selectUnit(this.getAttribute('data-unit'), this); });
});
}
function selectUnit(type, element){
selectedUnitType = type;
document.querySelectorAll('.unit-btn').forEach(b=>b.classList.remove('active'));
if(element) element.classList.add('active');
}
// ===== Map Drawing =====
function drawMap(){
if(!ctx || !mapWidth || !mapHeight) {
console.error('Canvas not ready for drawing');
return;
}
ctx.clearRect(0, 0, mapWidth, mapHeight);
applyViewTransform(ctx);
ctx.strokeStyle = 'rgba(255,255,0,0.5)';
ctx.lineWidth = 2;
ctx.setLineDash([15, 5]);
ctx.beginPath();
ctx.moveTo(0, battlefieldDivider);
ctx.lineTo(mapWidth, battlefieldDivider);
ctx.stroke();
ctx.setLineDash([]);
units.forEach(u => {
drawUnit(u);
if(u.selected) drawUnitRange(u);
});
restoreViewTransform(ctx);
}
function drawUnit(unit){
if(unit.health<=0) return;
const spec = countryUnits[unit.country][unit.type];
const unitColor = unit.side === 'blue' ? '#2196F3' : '#f44336';
ctx.save();
ctx.globalAlpha = Math.max(0.3, unit.health/100);
ctx.font = `bold ${spec.size==='battalion'?'20px':spec.size==='company'?'16px':'14px'} Arial`;
ctx.textAlign='center'; ctx.textBaseline='middle';
ctx.fillStyle = unit.isRetreating? '#888' : unitColor;
ctx.fillText(spec.symbol, unit.x, unit.y);
ctx.font='8px Arial';
ctx.fillStyle='rgba(255,255,255,0.7)';
const countryEmoji = {roka:'๐ฐ๐ท',kpa:'๐ฐ๐ต',usa:'๐บ๐ธ',russia:'๐ท๐บ',ukraine:'๐บ๐ฆ',china:'๐จ๐ณ'};
ctx.fillText(countryEmoji[unit.country], unit.x, unit.y-20);
ctx.font='10px Arial'; ctx.fillStyle='rgba(255,255,255,0.85)';
ctx.fillText(spec.name, unit.x, unit.y+15);
ctx.fillStyle='rgba(0,0,0,0.5)'; ctx.fillRect(unit.x-20, unit.y-25, 40, 4);
const hpColor = unit.health>60? '#4CAF50' : unit.health>30? '#FFC107' : '#F44336';
ctx.fillStyle=hpColor; ctx.fillRect(unit.x-20, unit.y-25, 40*(unit.health/100), 4);
if(unit.inCombat && !unit.isRetreating){ ctx.strokeStyle='#FF5722'; ctx.lineWidth=2; ctx.beginPath(); ctx.arc(unit.x,unit.y,25,0,Math.PI*2); ctx.stroke(); }
if(unit.selected){ ctx.strokeStyle='#ffeb3b'; ctx.lineWidth=2; ctx.beginPath(); ctx.arc(unit.x,unit.y,20,0,Math.PI*2); ctx.stroke(); }
ctx.restore();
}
function drawUnitRange(unit){
const spec = countryUnits[unit.country][unit.type];
const r = spec.range / METERS_PER_PIXEL;
ctx.strokeStyle = unit.side === 'blue' ? 'rgba(33,150,243,0.2)' : 'rgba(244,67,54,0.2)';
ctx.lineWidth=1; ctx.setLineDash([5,5]);
ctx.beginPath(); ctx.arc(unit.x, unit.y, r, 0, Math.PI*2); ctx.stroke(); ctx.setLineDash([]);
}
// ===== FIXED: Input Handling with proper coordinate transformation =====
function handleMapClick(e){
if (isDragging) return;
const rect = canvas.getBoundingClientRect();
const scaleX = mapWidth / rect.width;
const scaleY = mapHeight / rect.height;
const x = ((e.clientX - rect.left) * scaleX - mapWidth/2) / zoomLevel + mapWidth/2 - offsetX;
const y = ((e.clientY - rect.top) * scaleY - mapHeight/2) / zoomLevel + mapHeight/2 - offsetY;
console.log(`Click at: ${x}, ${y}, Side: ${selectedSide}, Divider: ${battlefieldDivider}`);
let clicked = null;
units.forEach(u => {
const d = Math.hypot(u.x - x, u.y - y);
if(d < 20) clicked = u;
u.selected = false;
});
if(clicked){
clicked.selected = true;
updateUnitInfo(clicked);
console.log('Selected unit:', clicked);
} else {
if(selectedSide === 'red' && y > battlefieldDivider){
alert('โ ๏ธ Red Team units can only be deployed in the northern sector!');
return;
}
if(selectedSide === 'blue' && y < battlefieldDivider){
alert('โ ๏ธ Blue Team units can only be deployed in the southern sector!');
return;
}
const height = getHeightAt(x, y);
if(height < 0.15){
alert('โ ๏ธ Cannot deploy units on water!');
return;
}
console.log('Placing unit at:', x, y);
placeUnit(x, y);
}
drawMap();
}
function placeUnit(x, y){
const newUnit = {
id: Date.now(),
type: selectedUnitType,
country: selectedCountry,
side: selectedSide,
x: x,
y: y,
targetX: x,
targetY: y,
selected: false,
health: 100,
morale: 100,
ammo: 100,
isRetreating: false,
inCombat: false,
lastFired: 0,
kills: 0,
currentTarget: null,
mission: selectedSide === 'blue' ? blueMission : redMission
};
units.push(newUnit);
console.log('Unit placed:', newUnit);
updateStats();
drawMap();
}
// ===== FIXED: Mouse Move with drag redraw =====
function handleMouseMove(e){
const rect = canvas.getBoundingClientRect();
const scaleX = mapWidth / rect.width;
const scaleY = mapHeight / rect.height;
if (isDragging) {
// ์ค์ ๊ณ ๋ คํด ์ด๋๋ ์ถ์
const dx = (e.clientX - dragStartClientX) * scaleX / zoomLevel;
const dy = (e.clientY - dragStartClientY) * scaleY / zoomLevel;
offsetX = dragStartOffsetX + dx;
offsetY = dragStartOffsetY + dy;
drawMap();
drawTerrain();
drawContours();
return;
}
const x = ((e.clientX - rect.left) * scaleX - mapWidth/2) / zoomLevel + mapWidth/2 - offsetX;
const y = ((e.clientY - rect.top) * scaleY - mapHeight/2) / zoomLevel + mapHeight/2 - offsetY;
const realX = Math.round(x * METERS_PER_PIXEL / 1000);
const realY = Math.round(y * METERS_PER_PIXEL / 1000);
const height = getHeightAt(x, y);
const elevation = Math.round(height * 1000);
const slope = getSlope(x, y);
document.getElementById('mouse-x').textContent = Math.round(x);
document.getElementById('mouse-y').textContent = Math.round(y);
document.getElementById('real-coords').textContent = `${realX},${realY}`;
document.getElementById('elevation').textContent = elevation;
document.getElementById('slope').textContent = slope;
let terrainType = 'Plains';
if (height < 0.2) terrainType = 'Water';
else if (height < 0.35) terrainType = 'Lowland';
else if (height < 0.55) terrainType = 'Hills';
else if (height < 0.75) terrainType = 'Highland';
else terrainType = 'Mountain';
document.getElementById('terrain-type').textContent = terrainType;
}
function updateUnitInfo(unit){
const spec = countryUnits[unit.country][unit.type];
const info = countryInfo[unit.country];
const elevation = Math.round(getHeightAt(unit.x, unit.y) * 1000);
document.getElementById('unit-name').textContent = spec.name;
document.getElementById('unit-country').textContent = info.name;
document.getElementById('unit-size').textContent = spec.size==='battalion'?'Battalion':spec.size==='company'?'Company':spec.size==='platoon'?'Platoon':'Squad';
document.getElementById('unit-strength').textContent = spec.strength+' troops';
document.getElementById('unit-weapons').innerHTML = spec.weapons.join('<br>');
document.getElementById('unit-range').textContent = spec.range+'m';
document.getElementById('unit-position').textContent = `(${Math.round(unit.x)}, ${Math.round(unit.y)})`;
document.getElementById('unit-elevation').textContent = elevation+'m';
}
function updateStats(){
const blueCount = units.filter(u=>u.side==='blue').length;
const redCount = units.filter(u=>u.side==='red').length;
document.getElementById('blue-units').textContent = blueCount;
document.getElementById('red-units').textContent = redCount;
let blueF=0, redF=0;
units.forEach(u=>{
const spec = countryUnits[u.country][u.type];
if(u.side==='blue') blueF += spec.firepower;
else redF += spec.firepower;
});
const total = blueF+redF;
const ratio = total>0? Math.round((blueF/total)*100):0;
document.getElementById('firepower-ratio').textContent = ratio+'%';
}
// ===== Random Deployment Functions (Fixed rendering issue) =====
function randomRegimentDeployment(side) {
const existingUnits = units.filter(u => u.side === side);
if (existingUnits.length > 0) {
if (!confirm(`Remove existing ${side} units and deploy new regiment?`)) return;
units = units.filter(u => u.side !== side);
}
const country = side === 'blue' ?
['roka', 'usa', 'ukraine'][Math.floor(Math.random() * 3)] :
['kpa', 'russia', 'china'][Math.floor(Math.random() * 3)];
const deployment = [];
deployment.push({ type: 'hq', x: mapWidth/2, y: side === 'blue' ? mapHeight * 0.85 : mapHeight * 0.15 });
for (let b = 0; b < 3; b++) {
const bx = (mapWidth / 4) * (b + 1);
const by = side === 'blue' ? mapHeight * 0.7 : mapHeight * 0.3;
for (let c = 0; c < 3; c++) {
const cx = bx + (Math.random() - 0.5) * 100;
const cy = by + (side === 'blue' ? 1 : -1) * c * 40;
deployment.push({ type: 'infantry_company', x: cx, y: cy });
}
}
// Fixed: Use correct unit types for each country
const mortarType = country === 'roka' ? 'mortar_81mm' :
country === 'kpa' ? 'mortar_82mm' :
country === 'usa' ? 'mortar_120mm' :
country === 'russia' ? 'mortar_120mm' :
country === 'ukraine' ? 'mortar_120mm' :
'mortar_120mm';
// Fixed: Country-specific AT types
const atTypeMap = {
roka: 'antitank_platoon',
kpa: 'antitank_platoon',
usa: 'javelin_team',
russia: 'kornet_team',
ukraine: 'stugna_team',
china: 'hj12_team'
};
const atType = atTypeMap[country];
deployment.push({ type: mortarType, x: mapWidth * 0.2, y: side === 'blue' ? mapHeight * 0.8 : mapHeight * 0.2 });
deployment.push({ type: atType, x: mapWidth * 0.8, y: side === 'blue' ? mapHeight * 0.8 : mapHeight * 0.2 });
// Deploy all units at once and then redraw
deployment.forEach((d, idx) => {
units.push({
id: Date.now() + idx,
type: d.type,
country: country,
side: side,
x: d.x,
y: d.y,
targetX: d.x,
targetY: d.y,
selected: false,
health: 100,
morale: 100,
ammo: 100,
isRetreating: false,
inCombat: false,
lastFired: 0,
kills: 0,
currentTarget: null,
mission: side === 'blue' ? blueMission : redMission
});
});
// Update and redraw everything
updateStats();
drawMap();
console.log(`Deployed ${deployment.length} ${side} units`);
}
function randomFullBattleSetup() {
if (units.length > 0) {
if (!confirm('Clear all units and deploy full battle setup?')) return;
units = [];
}
// Deploy both teams
randomRegimentDeployment('red');
randomRegimentDeployment('blue');
// Force redraw after both deployments
setTimeout(() => {
drawMap();
updateStats();
}, 100);
}
function analyzeCoverage(){
// ๋จผ์ ๋งต์ ํด๋ฆฌ์ดํ๊ณ ๊ธฐ๋ณธ ๋ ์ด์ด ๋ค์ ๊ทธ๋ฆผ
drawMap();
let covered=0, total=0;
for(let x=0;x<mapWidth;x+=20){
for(let y=battlefieldDivider;y<mapHeight;y+=20){
total++;
let ok=false;
for (const u of units){
if(u.side!=='blue') continue;
const spec = countryUnits[u.country][u.type];
const d = Math.hypot(u.x-x, u.y-y);
if (d <= spec.range / METERS_PER_PIXEL) {
ok=true;
break;
}
}
if(ok) covered++;
}
}
const pct = total>0? Math.round((covered/total)*100):0;
document.getElementById('coverage').textContent = pct+'%';
ctx.save();
ctx.globalAlpha=0.15;
for (const u of units){
if(u.side==='blue'){
const spec = countryUnits[u.country][u.type];
const r = spec.range/METERS_PER_PIXEL;
const g = ctx.createRadialGradient(u.x,u.y,0,u.x,u.y,r);
g.addColorStop(0,'rgba(33,150,243,0.5)');
g.addColorStop(1,'rgba(33,150,243,0)');
ctx.fillStyle=g;
ctx.beginPath();
ctx.arc(u.x,u.y,r,0,Math.PI*2);
ctx.fill();
}
}
ctx.restore();
}
function analyzeTerrain(){
const avgHeight = heightMap.flat().reduce((a,b)=>a+b,0) / (heightMap.length * heightMap[0].length);
const maxHeight = Math.max(...heightMap.flat());
const minHeight = Math.min(...heightMap.flat());
alert(`Terrain Analysis\n\nTerrain Type: ${selectedTerrain}\nAverage Elevation: ${Math.round(avgHeight*1000)}m\nMax Elevation: ${Math.round(maxHeight*1000)}m\nMin Elevation: ${Math.round(minHeight*1000)}m\n\nTactical Considerations:\nโข High ground provides range advantage\nโข Rivers create natural barriers\nโข Roads enable rapid movement\nโข Urban areas provide cover`);
}
function runSimulation(){
const blueForces = units.filter(u=>u.side==='blue');
const redForces = units.filter(u=>u.side==='red');
if(blueForces.length===0 || redForces.length===0){ alert('Both sides must have units deployed for simulation!'); return; }
let blueStrength=0, redStrength=0, blueFire=0, redFire=0;
blueForces.forEach(u=>{
const s = countryUnits[u.country][u.type];
const height = getHeightAt(u.x, u.y);
const heightBonus = height > 0.6 ? 1.2 : 1.0;
blueStrength += s.strength;
blueFire += s.firepower * ((u.health??100)/100) * heightBonus;
});
redForces.forEach(u=>{
const s = countryUnits[u.country][u.type];
const height = getHeightAt(u.x, u.y);
const heightBonus = height > 0.6 ? 1.2 : 1.0;
redStrength += s.strength;
redFire += s.firepower * ((u.health??100)/100) * heightBonus;
});
if (blueMission === 'defend' && redMission === 'attack') {
blueFire *= 3.0;
} else if (redMission === 'defend' && blueMission === 'attack') {
redFire *= 3.0;
}
if ((blueMission === 'defend' || redMission === 'defend') &&
(selectedTerrain === 'urban' || selectedTerrain === 'mountain')) {
if (blueMission === 'defend') blueFire *= 1.2;
if (redMission === 'defend') redFire *= 1.2;
}
const totalFp = blueFire + redFire;
const winProb = totalFp>0? (blueFire/totalFp*100):50;
let advice='';
if(winProb>70) advice='โ
Overwhelming Superiority - Full Attack Viable';
else if(winProb>60) advice='โ
Offensive Operations Favorable';
else if(winProb>40) advice='โ ๏ธ Cautious Approach Required';
else advice='๐จ Critical Situation - Consider withdrawal';
const missionStatus = `\n[Mission Type]\nโข Blue Team: ${blueMission.toUpperCase()}\nโข Red Team: ${redMission.toUpperCase()}\n`;
const lanchesterNote = blueMission === 'defend' || redMission === 'defend' ?
'\n[Lanchester\'s Law Applied]\nโข Defender has 3:1 combat advantage\n' : '';
alert(`๐ฏ Combat Simulation Results\n\n[Force Analysis]\nโข Blue Firepower: ${Math.round(blueFire)}\nโข Red Firepower: ${Math.round(redFire)}\nโข Terrain: ${selectedTerrain}${missionStatus}${lanchesterNote}\n[Battle Prediction]\nโข Blue Victory Probability: ${winProb.toFixed(1)}%\n\n[Tactical Recommendation]\n${advice}`);
}
function generateReport(){
const blueForces = units.filter(u=>u.side==='blue');
const redForces = units.filter(u=>u.side==='red');
let report = 'โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ\n';
report += ' TACTICAL OPERATION REPORT\n';
report += 'โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ\n\n';
report += `Report Time: ${new Date().toLocaleString('en-US')}\n`;
report += `Terrain Type: ${selectedTerrain}\n`;
report += `Map Scale: 1:${SCALE}\n`;
report += `Operation Area: 20km ร 15km\n\n`;
report += `โถ Blue Forces: ${blueForces.length} units\n`;
report += `โถ Red Forces: ${redForces.length} units\n\n`;
if(blueCasualties>0 || redCasualties>0){
report += `[Combat Losses]\n`;
report += `โข Blue Team: ${blueCasualties} casualties\n`;
report += `โข Red Team: ${redCasualties} casualties\n\n`;
}
if(battleTimeElapsed > 0){
report += `[Battle Duration]\n`;
report += `โข Battle Time: ${formatTime(battleTimeElapsed)}\n`;
report += `โข Real Time: ${formatTime(realTimeElapsed)}\n`;
}
alert(report);
}
function clearAll(){
if(!confirm('Clear all units and reset?')) return;
units=[];
battleActive=false;
// Stop battle sound
battleSound.pause();
battleSound.currentTime = 0;
if(battleInterval) clearInterval(battleInterval);
if(battleAnimationFrame) cancelAnimationFrame(battleAnimationFrame);
blueCasualties=0;
redCasualties=0;
explosions=[];
bulletTrails=[];
battleTimeElapsed=0;
realTimeElapsed=0;
battleStartTime = 0;
document.getElementById('battle-status').textContent='Standby';
document.getElementById('blue-casualties').textContent='0';
document.getElementById('red-casualties').textContent='0';
document.getElementById('battle-time').textContent='00:00:00';
document.getElementById('real-time').textContent='00:00:00';
document.getElementById('start-battle').style.display='block';
document.getElementById('start-battle').textContent='โ๏ธ START ENGAGEMENT';
document.getElementById('pause-battle').style.display='none';
drawMap();
updateStats();
document.getElementById('coverage').textContent='0%';
}
// ===== Battle System with Realistic Movement and Sound =====
const battleSound = new Audio('war.mp3');
battleSound.loop = true;
battleSound.volume = 0.7;
function startBattle(){
const blueForces = units.filter(u=>u.side==='blue' && u.health>0);
const redForces = units.filter(u=>u.side==='red' && u.health>0);
if(blueForces.length===0 || redForces.length===0){
alert('Both sides must have units to start battle!');
return;
}
battleActive = true;
battleStartTime = Date.now();
battleTimeElapsed = 0;
realTimeElapsed = 0;
// Start battle sound
battleSound.currentTime = 0;
battleSound.play().catch(e => console.log('Audio play failed:', e));
console.log('Battle started at:', battleStartTime);
document.getElementById('battle-status').textContent = '๐ฅ ENGAGED';
document.getElementById('start-battle').style.display = 'none';
document.getElementById('pause-battle').style.display = 'block';
// Clear any existing intervals
if(battleInterval) {
clearInterval(battleInterval);
battleInterval = null;
}
if(battleAnimationFrame) {
cancelAnimationFrame(battleAnimationFrame);
battleAnimationFrame = null;
}
// Start the battle loop
startBattleLoop();
}
function startBattleLoop() {
// Battle logic update every 100ms (10 times per second)
battleInterval = setInterval(() => {
if(battleActive) {
battleTick();
updateTimeDisplay();
}
}, TICK_INTERVAL);
// Start continuous animation
function animate() {
if(battleActive) {
// Clear canvas
ctx.clearRect(0, 0, mapWidth, mapHeight);
// Apply transform
ctx.save();
ctx.translate(mapWidth/2, mapHeight/2);
ctx.scale(zoomLevel, zoomLevel);
ctx.translate(-mapWidth/2 + offsetX, -mapHeight/2 + offsetY);
// Draw battlefield divider
ctx.strokeStyle = 'rgba(255,255,0,0.5)';
ctx.lineWidth = 2;
ctx.setLineDash([15, 5]);
ctx.beginPath();
ctx.moveTo(0, battlefieldDivider);
ctx.lineTo(mapWidth, battlefieldDivider);
ctx.stroke();
ctx.setLineDash([]);
// Draw all units
units.forEach(u => {
if(u.health > 0) {
drawUnit(u);
if(u.selected) drawUnitRange(u);
}
});
// Draw battle effects
explosions.forEach(exp => {
ctx.save();
ctx.globalAlpha = exp.opacity;
ctx.fillStyle = exp.color;
ctx.beginPath();
ctx.arc(exp.x, exp.y, exp.radius, 0, Math.PI * 2);
ctx.fill();
ctx.restore();
});
bulletTrails.forEach(b => {
ctx.save();
ctx.strokeStyle = b.color;
ctx.lineWidth = 2;
ctx.globalAlpha = 1 - b.progress;
const cx = b.from.x + (b.to.x - b.from.x) * b.progress;
const cy = b.from.y + (b.to.y - b.from.y) * b.progress;
ctx.beginPath();
ctx.moveTo(b.from.x, b.from.y);
ctx.lineTo(cx, cy);
ctx.stroke();
ctx.restore();
});
ctx.restore();
battleAnimationFrame = requestAnimationFrame(animate);
}
}
animate();
}
function pauseBattle(){
battleActive = false;
// Pause battle sound
battleSound.pause();
if(battleInterval) {
clearInterval(battleInterval);
battleInterval = null;
}
if(battleAnimationFrame) {
cancelAnimationFrame(battleAnimationFrame);
battleAnimationFrame = null;
}
document.getElementById('battle-status').textContent = 'โธ๏ธ PAUSED';
document.getElementById('start-battle').style.display = 'block';
document.getElementById('start-battle').textContent = 'โถ๏ธ RESUME BATTLE';
document.getElementById('pause-battle').style.display = 'none';
// Redraw static map
drawMap();
}
function battleTick(){
if(!battleActive) return;
const res = checkVictoryConditions();
if(res){
endBattle(res);
return;
}
// Move and update all units
units.forEach(u => {
if(u.health <= 0) return;
// AI decision making
makeAIDecision(u);
// Move the unit with realistic speed
moveUnitRealistic(u);
// Combat
if(u.inCombat && !u.isRetreating) {
engageEnemy(u);
}
// Recover morale
if(!u.inCombat && u.morale < 100) {
u.morale = Math.min(100, u.morale + 0.5);
}
});
// Update visual effects
explosions = explosions.filter(e => {
e.radius += 2;
e.opacity -= 0.05;
return e.opacity > 0;
});
bulletTrails = bulletTrails.filter(b => {
b.progress += 0.1;
return b.progress < 1;
});
}
function makeAIDecision(unit){
const spec = countryUnits[unit.country][unit.type];
const info = findNearestEnemy(unit);
if(!info) return;
const {target, dist} = info;
const rangePx = spec.range / METERS_PER_PIXEL;
const unitHeight = getHeightAt(unit.x, unit.y);
const targetHeight = getHeightAt(target.x, target.y);
const heightAdvantage = unitHeight > targetHeight;
// HQ units stay back
if (unit.type === 'hq') {
if (unit.side === 'blue' && unit.y < battlefieldDivider + 100) {
unit.targetY = Math.max(battlefieldDivider + 100, unit.y);
} else if (unit.side === 'red' && unit.y > battlefieldDivider - 100) {
unit.targetY = Math.min(battlefieldDivider - 100, unit.y);
}
}
// Retreat if low health
if(unit.health < 30 || unit.morale < 20){
unit.isRetreating = true;
unit.inCombat = false;
unit.currentTarget = null;
unit.targetX = unit.x + (Math.random() - 0.5) * 50;
unit.targetY = (unit.side === 'blue') ? (mapHeight - 50) : 50;
return;
} else {
unit.isRetreating = false;
}
const effectiveRange = rangePx * (heightAdvantage ? 1.2 : 1.0);
// In range - engage
if(dist <= effectiveRange){
unit.inCombat = true;
unit.currentTarget = target;
if (unit.mission === 'defend') {
// Defenders hold position
unit.targetX = unit.x;
unit.targetY = unit.y;
}
else if (unit.mission === 'attack') {
// Attackers try to maintain optimal range but move more cautiously
const angle = Math.atan2(target.y - unit.y, target.x - unit.x);
const optimal = effectiveRange * 0.8;
if (dist > optimal) {
// Move forward cautiously - reduced from 20 to 5 pixels
unit.targetX = unit.x + Math.cos(angle) * 5;
unit.targetY = unit.y + Math.sin(angle) * 5;
} else {
// Small tactical movements
unit.targetX = unit.x + (Math.random() - 0.5) * 2;
unit.targetY = unit.y + (Math.random() - 0.5) * 2;
}
}
return;
}
// Out of range - move toward enemy
unit.inCombat = false;
unit.currentTarget = null;
if (unit.mission === 'attack') {
const angle = Math.atan2(target.y - unit.y, target.x - unit.x);
// Reduced advance distance from 100 to 20 pixels
const advanceDistance = Math.min(20, dist - effectiveRange * 0.8);
unit.targetX = unit.x + Math.cos(angle) * advanceDistance;
unit.targetY = unit.y + Math.sin(angle) * advanceDistance;
// Don't let HQ cross divider
if (unit.type === 'hq') {
if (unit.side === 'blue') {
unit.targetY = Math.min(battlefieldDivider - 50, unit.targetY);
} else {
unit.targetY = Math.max(battlefieldDivider + 50, unit.targetY);
}
}
} else if (unit.mission === 'defend') {
// Defenders make very small adjustments
if (dist < effectiveRange * 1.5) {
unit.targetX = unit.x + (Math.random() - 0.5) * 5;
unit.targetY = unit.y + (Math.random() - 0.5) * 5;
}
}
}
// New realistic movement function with road and village bonuses
function moveUnitRealistic(unit) {
const dx = unit.targetX - unit.x;
const dy = unit.targetY - unit.y;
const dist = Math.hypot(dx, dy);
if(dist < 0.5) {
unit.x = unit.targetX;
unit.y = unit.targetY;
return;
}
// Get unit specification for speed
const spec = countryUnits[unit.country][unit.type];
// Base speed in meters per minute (realistic military speeds)
let speedMPM = spec.speed || 100; // Default 100m/min for infantry
// Convert to pixels per tick
const gameMinutesPerTick = 0.1 * speedMultipliers[battleSpeed] / 60;
const metersPerTick = speedMPM * gameMinutesPerTick;
let pixelsPerTick = metersPerTick / METERS_PER_PIXEL;
// Check if unit is on or near a road (massive speed boost)
const gridSize = heightMap.length;
const cellWidth = mapWidth / gridSize;
const cellHeight = mapHeight / gridSize;
const gridX = Math.floor(unit.x / cellWidth);
const gridY = Math.floor(unit.y / cellHeight);
let onRoad = false;
for (let road of roads) {
for (let point of road) {
const roadDist = Math.sqrt(Math.pow(gridX - point.x, 2) + Math.pow(gridY - point.y, 2));
if (roadDist < 2) { // Within 2 grid cells of road
onRoad = true;
break;
}
}
if (onRoad) break;
}
if (onRoad) {
// Roads provide 2.5x speed for vehicles, 1.5x for infantry
if (spec.symbol === 'โ ' || spec.symbol === 'โฃ' || spec.symbol === 'โข' ||
spec.symbol === 'โฌข' || spec.symbol === 'โ') {
pixelsPerTick *= 2.5; // Vehicles move much faster on roads
} else {
pixelsPerTick *= 1.5; // Infantry also benefits from roads
}
}
// Terrain effects
const height = getHeightAt(unit.x, unit.y);
const slope = getSlope(unit.x, unit.y);
let terrainMultiplier = 1.0;
// Slope penalties (reduced when on road)
if (!onRoad) {
if (slope > 30) {
terrainMultiplier *= 0.3;
} else if (slope > 15) {
terrainMultiplier *= 0.5;
} else if (slope > 5) {
terrainMultiplier *= 0.8;
}
} else {
// Roads reduce slope penalties
if (slope > 30) {
terrainMultiplier *= 0.6;
} else if (slope > 15) {
terrainMultiplier *= 0.8;
}
}
// Check if in a settlement (slows movement for attackers)
let inSettlement = false;
for (let settlement of settlements) {
const settlementX = settlement.x * cellWidth;
const settlementY = settlement.y * cellHeight;
const settlementDist = Math.hypot(unit.x - settlementX, unit.y - settlementY);
if (settlementDist < settlement.size * 2) {
inSettlement = true;
// Defenders move normally in settlements, attackers are slowed
const unitMission = unit.side === 'blue' ? blueMission : redMission;
if (unitMission === 'attack') {
terrainMultiplier *= 0.5; // Attackers move slowly through urban areas
}
break;
}
}
// Terrain type penalties (modified)
if (!onRoad && !inSettlement) {
if (selectedTerrain === 'urban') {
terrainMultiplier *= 0.7;
} else if (selectedTerrain === 'mountain') {
terrainMultiplier *= 0.5;
}
}
// Water is very slow for ground units
if (height < 0.2) {
// Air units not affected by water
if (!spec.symbol.includes('โ') && !unit.type.includes('heli') && !unit.type.includes('drone')) {
terrainMultiplier *= 0.1;
}
}
// Apply status modifiers
if (unit.isRetreating) {
terrainMultiplier *= 1.3;
}
if (unit.health < 50) {
terrainMultiplier *= 0.8;
}
// Calculate final speed
let finalSpeed = pixelsPerTick * terrainMultiplier;
// Ensure minimum movement
finalSpeed = Math.max(0.1, finalSpeed);
// Move the unit
if (dist > finalSpeed) {
unit.x += (dx / dist) * finalSpeed;
unit.y += (dy / dist) * finalSpeed;
} else {
unit.x = unit.targetX;
unit.y = unit.targetY;
}
}
function findNearestEnemy(unit){
const enemies = units.filter(u=>u.side!==unit.side && u.health>0);
if(enemies.length===0) return null;
let best=null, bestD=Infinity;
enemies.forEach(e=>{
const d = Math.hypot(unit.x-e.x, unit.y-e.y);
if(d<bestD){ bestD=d; best=e; }
});
return { target:best, dist:bestD };
}
function engageEnemy(unit){
if(!unit.currentTarget || unit.currentTarget.health<=0){
const info = findNearestEnemy(unit);
if(!info) { unit.inCombat=false; return; }
unit.currentTarget = info.target;
}
const spec = countryUnits[unit.country][unit.type];
const targetDist = Math.hypot(unit.x-unit.currentTarget.x, unit.y-unit.currentTarget.y);
const maxRange = spec.range / METERS_PER_PIXEL;
if (targetDist > maxRange) {
unit.inCombat = false;
unit.currentTarget = null;
return;
}
const now = Date.now();
// ๋ฐ์ฌ ๊ฐ๊ฒฉ(ํ๋ ฅ์ ๋ฐ๋ผ)
let fireRate = 3000 / (spec.firepower / 50);
if(now - unit.lastFired < fireRate) return;
unit.lastFired = now;
const rangePercentage = targetDist / maxRange;
// ๋ช
์ค๋ฅ ๊ณ์ฐ
let accuracy = 0.9 - (rangePercentage * 0.4);
const unitHeight = getHeightAt(unit.x, unit.y);
const targetHeight = getHeightAt(unit.currentTarget.x, unit.currentTarget.y);
if (unitHeight > targetHeight) {
accuracy *= 1.2;
}
const unitMission = unit.side === 'blue' ? blueMission : redMission;
const targetMission = unit.currentTarget.side === 'blue' ? blueMission : redMission;
let combatMultiplier = 1.0;
if (unitMission === 'defend' && targetMission === 'attack') {
combatMultiplier = 3.0; // ๋ฐฉ์ด์ ์ฐ์ (3:1)
accuracy *= 1.3;
} else if (unitMission === 'attack' && targetMission === 'defend') {
combatMultiplier = 0.33;
accuracy *= 0.7;
}
// ์ ์ฐฉ์ง(๋์/๋ง์) ๋ฐฉ์ด ๋ณด๋์ค
const gridSize = heightMap.length;
const cellWidth = mapWidth / gridSize;
const cellHeight = mapHeight / gridSize;
let targetInSettlement = false;
for (let settlement of settlements) {
const settlementX = settlement.x * cellWidth;
const settlementY = settlement.y * cellHeight;
const settlementDist = Math.hypot(unit.currentTarget.x - settlementX, unit.currentTarget.y - settlementY);
if (settlementDist < settlement.size * 2) {
targetInSettlement = true;
if (targetMission === 'defend') {
combatMultiplier *= 0.3; // ํฐ ํผํด ๊ฒฝ๊ฐ
accuracy *= 0.6; // ๋ช
์ค๋ฅ ํ๋ฝ
if (settlement.type === 'city') {
combatMultiplier *= 0.5;
accuracy *= 0.7;
} else if (settlement.type === 'town') {
combatMultiplier *= 0.7;
accuracy *= 0.8;
}
}
break;
}
}
if (targetMission === 'defend' && !targetInSettlement) {
if (selectedTerrain === 'urban' || selectedTerrain === 'mountain') {
combatMultiplier *= 0.8;
if (unitMission === 'defend') {
accuracy *= 1.1;
}
}
}
accuracy = Math.max(0.1, Math.min(0.95, accuracy));
// ์๊ฐ ํจ๊ณผ(ํ๋ ๊ถค์ )
let trailColor = (unit.side==='blue'?'#2196F3':'#f44336');
bulletTrails.push({
from:{x:unit.x, y:unit.y},
to:{x:unit.currentTarget.x, y:unit.currentTarget.y},
color:trailColor,
progress:0
});
if(Math.random() < accuracy){
let damage = (spec.firepower/10) * (Math.random()*0.5 + 0.75);
damage *= combatMultiplier;
damage *= (1 - rangePercentage * 0.3);
unit.currentTarget.health -= damage;
unit.currentTarget.morale -= damage/2;
explosions.push({
x:unit.currentTarget.x,
y:unit.currentTarget.y,
radius:10,
color:(unit.side==='blue'?'#2196F3':'#f44336'),
opacity:0.8
});
if(unit.currentTarget.health<=0){
const targetSpec = countryUnits[unit.currentTarget.country][unit.currentTarget.type];
const casualties = targetSpec.strength;
if(unit.currentTarget.side==='blue'){
blueCasualties += casualties;
document.getElementById('blue-casualties').textContent = blueCasualties;
}else{
redCasualties += casualties;
document.getElementById('red-casualties').textContent = redCasualties;
}
unit.kills++;
unit.currentTarget.inCombat=false;
// HQ ๊ฒฉํ ์ ์๊ตฐ ์ฌ๊ธฐ ์ ํ
if (unit.currentTarget.type === 'hq') {
units.filter(u => u.side === unit.currentTarget.side && u.health > 0)
.forEach(u => u.morale -= 30);
}
}
}
}
function checkVictoryConditions(){
const blueAlive = units.filter(u=>u.side==='blue' && u.health>0);
const redAlive = units.filter(u=>u.side==='red' && u.health>0);
if(blueAlive.length===0 && redAlive.length===0) return 'draw';
const blueHQ = units.find(u => u.side === 'blue' && u.type === 'hq');
const redHQ = units.find(u => u.side === 'red' && u.type === 'hq');
if (blueHQ && blueHQ.health <= 0) {
return 'red_victory_hq';
}
if (redHQ && redHQ.health <= 0) {
return 'blue_victory_hq';
}
if (blueHQ && blueHQ.health > 0) {
const enemiesNearby = units.filter(u =>
u.side === 'red' &&
u.health > 0 &&
Math.hypot(u.x - blueHQ.x, u.y - blueHQ.y) < 150
);
if (enemiesNearby.length >= 4) {
const angles = enemiesNearby.map(e =>
Math.atan2(e.y - blueHQ.y, e.x - blueHQ.x)
);
const quadrants = new Set(angles.map(a => Math.floor((a + Math.PI) / (Math.PI/2))));
if (quadrants.size >= 3) {
return 'red_victory_encircle';
}
}
}
if (redHQ && redHQ.health > 0) {
const enemiesNearby = units.filter(u =>
u.side === 'blue' &&
u.health > 0 &&
Math.hypot(u.x - redHQ.x, u.y - redHQ.y) < 150
);
if (enemiesNearby.length >= 4) {
const angles = enemiesNearby.map(e =>
Math.atan2(e.y - redHQ.y, e.x - redHQ.x)
);
const quadrants = new Set(angles.map(a => Math.floor((a + Math.PI) / (Math.PI/2))));
if (quadrants.size >= 3) {
return 'blue_victory_encircle';
}
}
}
const blueAll = units.filter(u=>u.side==='blue');
const redAll = units.filter(u=>u.side==='red');
if(blueAlive.length < Math.max(1, Math.floor(blueAll.length*0.1))) return 'red_victory_attrition';
if(redAlive.length < Math.max(1, Math.floor(redAll.length*0.1))) return 'blue_victory_attrition';
return '';
}
function endBattle(result){
battleActive=false;
// Stop battle sound
battleSound.pause();
battleSound.currentTime = 0;
if(battleInterval) clearInterval(battleInterval);
if(battleAnimationFrame) cancelAnimationFrame(battleAnimationFrame);
let message='';
let details='';
switch(result){
case 'blue_victory_hq':
message='๐ต BLUE TEAM VICTORY!';
details='Enemy command destroyed - Red forces in disarray';
break;
case 'red_victory_hq':
message='๐ด RED TEAM VICTORY!';
details='Enemy command destroyed - Blue forces in disarray';
break;
case 'blue_victory_encircle':
message='๐ต BLUE TEAM VICTORY!';
details='Red HQ encircled and forced to surrender';
break;
case 'red_victory_encircle':
message='๐ด RED TEAM VICTORY!';
details='Blue HQ encircled and forced to surrender';
break;
case 'blue_victory_attrition':
message='๐ต BLUE TEAM VICTORY!';
details='Red forces decimated - 90% casualties';
break;
case 'red_victory_attrition':
message='๐ด RED TEAM VICTORY!';
details='Blue forces decimated - 90% casualties';
break;
case 'draw':
message='โ๏ธ MUTUAL DESTRUCTION';
details='Both forces annihilated';
break;
default:
message='Battle Ended';
break;
}
document.getElementById('battle-status').textContent='Battle Ended';
document.getElementById('start-battle').style.display='block';
document.getElementById('start-battle').textContent='โ๏ธ START ENGAGEMENT';
document.getElementById('pause-battle').style.display='none';
alert(`Battle Complete!\n\n${message}\n${details}\n\n[Battle Results]\nBlue Casualties: ${blueCasualties}\nRed Casualties: ${redCasualties}\n\n[Battle Duration]\nBattle Time: ${formatTime(battleTimeElapsed)}\nReal Time: ${formatTime(realTimeElapsed)}\n\n[Victory Conditions]\nโข HQ Destruction\nโข Complete Encirclement\nโข 90% Force Attrition`);
}
</script>
</body>
</html> |