1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383
|
#if defined(TILES)
#include "cata_tiles.h"
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdint>
#include <iterator>
#include <optional>
#include <set>
#include <stdexcept>
#include <tuple>
#include <unordered_set>
#include "action.h"
#include "avatar.h"
#include "cached_options.h"
#include "calendar.h"
#include "cata_assert.h"
#include "cata_utility.h"
#include "catacharset.h"
#include "character.h"
#include "character_id.h"
#include "clzones.h"
#include "color.h"
#include "creature_tracker.h"
#include "cursesdef.h"
#include "cursesport.h"
#include "debug.h"
#include "field.h"
#include "field_type.h"
#include "filesystem.h"
#include "game.h"
#include "game_constants.h"
#include "int_id.h"
#include "item.h"
#include "item_factory.h"
#include "itype.h"
#include "json.h"
#include "json_loader.h"
#include "map.h"
#include "map_extras.h"
#include "map_memory.h"
#include "mapdata.h"
#include "mod_tileset.h"
#include "monster.h"
#include "monstergenerator.h"
#include "mtype.h"
#include "npc.h"
#include "output.h"
#include "overlay_ordering.h"
#include "path_info.h"
#include "pixel_minimap.h"
#include "rect_range.h"
#include "scent_map.h"
#include "sdl_utils.h"
#include "sdl_wrappers.h"
#include "sdltiles.h"
#include "sounds.h"
#include "string_formatter.h"
#include "string_id.h"
#include "submap.h"
#include "tileray.h"
#include "translations.h"
#include "trap.h"
#include "type_id.h"
#include "units_utility.h"
#include "veh_type.h"
#include "vehicle.h"
#include "vpart_position.h"
#include "weather.h"
#include "weighted_list.h"
#define dbg(x) DebugLog((x),D_SDL) << __FILE__ << ":" << __LINE__ << ": "
static const efftype_id effect_ridden( "ridden" );
static const itype_id itype_corpse( "corpse" );
static const trait_id trait_INATTENTIVE( "INATTENTIVE" );
static const trap_str_id tr_unfinished_construction( "tr_unfinished_construction" );
static const std::string ITEM_HIGHLIGHT( "highlight_item" );
static const std::string ZOMBIE_REVIVAL_INDICATOR( "zombie_revival_indicator" );
static const std::array<std::string, 8> multitile_keys = {{
"center",
"corner",
"edge",
"t_connection",
"end_piece",
"unconnected",
"open",
"broken"
}
};
static const std::string empty_string;
static const std::array<std::string, 15> TILE_CATEGORY_IDS = {{
"", // TILE_CATEGORY::NONE,
"vehicle_part", // TILE_CATEGORY::VEHICLE_PART,
"terrain", // TILE_CATEGORY::TERRAIN,
"item", // TILE_CATEGORY::ITEM,
"furniture", // TILE_CATEGORY::FURNITURE,
"trap", // TILE_CATEGORY::TRAP,
"field", // TILE_CATEGORY::FIELD,
"lighting", // TILE_CATEGORY::LIGHTING,
"monster", // TILE_CATEGORY::MONSTER,
"bullet", // TILE_CATEGORY::BULLET,
"hit_entity", // TILE_CATEGORY::HIT_ENTITY,
"weather", // TILE_CATEGORY::WEATHER,
"overmap_terrain", // TILE_CATEGORY::OVERMAP_TERRAIN
"map_extra", // TILE_CATEGORY::MAP_EXTRA
"overmap_note", // TILE_CATEGORY::OVERMAP_NOTE
}
};
static_assert( TILE_CATEGORY_IDS.size() == static_cast<size_t>( TILE_CATEGORY::last ),
"TILE_CATEGORY_IDS must match list of TILE_CATEGORY values" );
namespace
{
std::string get_ascii_tile_id( const uint32_t sym, const int FG, const int BG )
{
return std::string( { 'A', 'S', 'C', 'I', 'I', '_', static_cast<char>( sym ),
static_cast<char>( FG ), static_cast<char>( BG )
} );
}
pixel_minimap_mode pixel_minimap_mode_from_string( const std::string &mode )
{
if( mode == "solid" ) {
return pixel_minimap_mode::solid;
} else if( mode == "squares" ) {
return pixel_minimap_mode::squares;
} else if( mode == "dots" ) {
return pixel_minimap_mode::dots;
}
debugmsg( "Unsupported pixel minimap mode \"" + mode + "\"." );
return pixel_minimap_mode::solid;
}
} // namespace
static int msgtype_to_tilecolor( const game_message_type type, const bool bOldMsg )
{
const int iBold = bOldMsg ? 0 : 8;
switch( type ) {
case m_good:
return iBold + catacurses::green;
case m_bad:
return iBold + catacurses::red;
case m_mixed:
case m_headshot:
return iBold + catacurses::magenta;
case m_neutral:
return iBold + catacurses::white;
case m_warning:
case m_critical:
return iBold + catacurses::yellow;
case m_info:
case m_grazing:
return iBold + catacurses::blue;
default:
break;
}
return -1;
}
formatted_text::formatted_text( const std::string &text, const int color,
const direction text_direction )
: text( text ), color( color )
{
switch( text_direction ) {
case direction::NORTHWEST:
case direction::WEST:
case direction::SOUTHWEST:
alignment = text_alignment::right;
break;
case direction::NORTH:
case direction::CENTER:
case direction::SOUTH:
alignment = text_alignment::center;
break;
default:
alignment = text_alignment::left;
break;
}
}
cata_tiles::cata_tiles( const SDL_Renderer_Ptr &renderer, const GeometryRenderer_Ptr &geometry,
tileset_cache &cache ) :
renderer( renderer ),
geometry( geometry ),
cache( cache ),
minimap( renderer, geometry )
{
cata_assert( renderer );
tile_height = 0;
tile_width = 0;
in_animation = false;
do_draw_explosion = false;
do_draw_custom_explosion = false;
do_draw_bullet = false;
do_draw_hit = false;
do_draw_line = false;
do_draw_cursor = false;
do_draw_highlight = false;
do_draw_weather = false;
do_draw_sct = false;
do_draw_zones = false;
nv_goggles_activated = false;
on_options_changed();
}
cata_tiles::~cata_tiles() = default;
void cata_tiles::on_options_changed()
{
memory_map_mode = get_option <std::string>( "MEMORY_MAP_MODE" );
pixel_minimap_settings settings;
settings.mode =
pixel_minimap_mode_from_string( get_option<std::string>( "PIXEL_MINIMAP_MODE" ) );
settings.brightness = get_option<int>( "PIXEL_MINIMAP_BRIGHTNESS" );
settings.beacon_size = get_option<int>( "PIXEL_MINIMAP_BEACON_SIZE" );
settings.beacon_blink_interval = get_option<int>( "PIXEL_MINIMAP_BLINK" );
settings.square_pixels = get_option<bool>( "PIXEL_MINIMAP_RATIO" );
settings.scale_to_fit = get_option<bool>( "PIXEL_MINIMAP_SCALE_TO_FIT" );
minimap->set_settings( settings );
}
void tileset::clear()
{
tile_values.clear();
shadow_tile_values.clear();
night_tile_values.clear();
overexposed_tile_values.clear();
memory_tile_values.clear();
duplicate_ids.clear();
tile_ids.clear();
for( std::unordered_map<std::string, season_tile_value> &m : tile_ids_by_season ) {
m.clear();
}
item_layer_data.clear();
field_layer_data.clear();
}
const tile_type *tileset::find_tile_type( const std::string &id ) const
{
const auto iter = tile_ids.find( id );
return iter != tile_ids.end() ? &iter->second : nullptr;
}
std::optional<tile_lookup_res>
tileset::find_tile_type_by_season( const std::string &id, season_type season ) const
{
cata_assert( season < season_type::NUM_SEASONS );
const auto iter = tile_ids_by_season[season].find( id );
if( iter == tile_ids_by_season[season].end() ) {
return std::nullopt;
}
const tileset::season_tile_value &res = iter->second;
if( res.season_tile ) {
return *res.season_tile;
} else if( res.default_tile ) { // can skip this check, but just in case
return tile_lookup_res( iter->first, *res.default_tile );
}
debugmsg( "empty record found in `tile_ids_by_season` for key: %s", id );
return std::nullopt;
}
tile_type &tileset::create_tile_type( const std::string &id, tile_type &&new_tile_type )
{
// Must overwrite existing tile
// TODO: c++17 - replace [] + find() with insert_or_assign()
tile_ids[id] = std::move( new_tile_type );
auto inserted = tile_ids.find( id );
const std::string &inserted_id = inserted->first;
tile_type &inserted_tile = inserted->second;
// populate cache by season
constexpr size_t suffix_len = 15;
// NOLINTNEXTLINE(cata-use-mdarray,modernize-avoid-c-arrays)
constexpr char season_suffix[NUM_SEASONS][suffix_len] = {
"_season_spring", "_season_summer", "_season_autumn", "_season_winter"
};
bool has_season_suffix = false;
for( int i = 0; i < NUM_SEASONS; i++ ) {
if( string_ends_with( id, season_suffix[i] ) ) {
has_season_suffix = true;
// key is id without _season suffix
season_tile_value &value = tile_ids_by_season[i][id.substr( 0,
id.size() - strlen( season_suffix[i] ) )];
// value stores reference to string id with _season suffix
value.season_tile = tile_lookup_res( inserted_id, inserted_tile );
break;
}
}
// tile doesn't have _season suffix, add it as "default" into all four seasons
if( !has_season_suffix ) {
for( auto &by_season_map : tile_ids_by_season ) {
by_season_map[id].default_tile = &inserted_tile;
}
}
return inserted_tile;
}
void cata_tiles::load_tileset( const std::string &tileset_id, const bool precheck,
const bool force, const bool pump_events )
{
if( tileset_ptr && tileset_ptr->get_tileset_id() == tileset_id && !force ) {
return;
}
// TODO: move into clear or somewhere else.
// reset the overlay ordering from the previous loaded tileset
tileset_mutation_overlay_ordering.clear();
tileset_ptr = cache.load_tileset( tileset_id, renderer, precheck, force, pump_events );
set_draw_scale( 16 );
// Precalculate fog transparency
// On isometric tilesets, fog intensity scales with zlevel_height in tile_config.json
fog_alpha = is_isometric() ? std::min( std::max( int( 255.0f - 255.0f * pow( 155.0f / 255.0f,
zlevel_height / 100.0f ) ), 40 ), 150 ) : 100;
}
void cata_tiles::reinit()
{
set_draw_scale( 16 );
RenderClear( renderer );
}
static void get_tile_information( const cata_path &config_path, std::string &json_path,
std::string &tileset_path, std::string &layering_path )
{
const std::string default_json = PATH_INFO::defaulttilejson();
const std::string default_tileset = PATH_INFO::defaulttilepng();
const std::string default_layering = PATH_INFO::defaultlayeringjson();
// Get JSON and TILESET vars from config
const auto reader = [&]( std::istream & fin ) {
while( !fin.eof() ) {
std::string sOption;
fin >> sOption;
if( string_starts_with( sOption, "JSON" ) ) {
fin >> json_path;
dbg( D_INFO ) << "JSON path set to [" << json_path << "].";
} else if( string_starts_with( sOption, "TILESET" ) ) {
fin >> tileset_path;
dbg( D_INFO ) << "TILESET path set to [" << tileset_path << "].";
} else if( string_starts_with( sOption, "LAYERING" ) ) {
fin >> layering_path;
dbg( D_INFO ) << "LAYERING path set to [" << layering_path << "].";
} else {
getline( fin, sOption );
}
}
};
if( !read_from_file( config_path, reader ) ) {
json_path = default_json;
tileset_path = default_tileset;
layering_path = default_layering;
}
if( json_path.empty() ) {
json_path = default_json;
dbg( D_INFO ) << "JSON set to default [" << json_path << "].";
}
if( tileset_path.empty() ) {
tileset_path = default_tileset;
dbg( D_INFO ) << "TILESET set to default [" << tileset_path << "].";
}
if( layering_path.empty() ) {
layering_path = default_layering;
dbg( D_INFO ) << "TILESET set to default [" << layering_path << "].";
}
}
template<typename PixelConverter>
static SDL_Surface_Ptr apply_color_filter( const SDL_Surface_Ptr &original,
PixelConverter pixel_converter )
{
cata_assert( original );
SDL_Surface_Ptr surf = create_surface_32( original->w, original->h );
cata_assert( surf );
throwErrorIf( SDL_BlitSurface( original.get(), nullptr, surf.get(), nullptr ) != 0,
"SDL_BlitSurface failed" );
SDL_Color *pix = static_cast<SDL_Color *>( surf->pixels );
for( int y = 0, ey = surf->h; y < ey; ++y ) {
for( int x = 0, ex = surf->w; x < ex; ++x, ++pix ) {
if( pix->a == 0x00 ) {
// This check significantly improves the performance since
// vast majority of pixels in the tilesets are completely transparent.
continue;
}
*pix = pixel_converter( *pix );
}
}
return surf;
}
static bool is_contained( const SDL_Rect &smaller, const SDL_Rect &larger )
{
return smaller.x >= larger.x &&
smaller.y >= larger.y &&
smaller.x + smaller.w <= larger.x + larger.w &&
smaller.y + smaller.h <= larger.y + larger.h;
}
void tileset_cache::loader::copy_surface_to_texture( const SDL_Surface_Ptr &surf,
const point &offset, std::vector<texture> &target )
{
cata_assert( surf );
const rect_range<SDL_Rect> input_range( sprite_width, sprite_height,
point( surf->w / sprite_width,
surf->h / sprite_height ) );
const std::shared_ptr<SDL_Texture> texture_ptr = CreateTextureFromSurface( renderer, surf );
cata_assert( texture_ptr );
for( const SDL_Rect rect : input_range ) {
cata_assert( offset.x % sprite_width == 0 );
cata_assert( offset.y % sprite_height == 0 );
const point pos( offset + point( rect.x, rect.y ) );
cata_assert( pos.x % sprite_width == 0 );
cata_assert( pos.y % sprite_height == 0 );
const size_t index = this->offset + ( pos.x / sprite_width ) + ( pos.y / sprite_height ) *
( tile_atlas_width / sprite_width );
cata_assert( index < target.size() );
cata_assert( target[index].dimension() == std::make_pair( 0, 0 ) );
target[index] = texture( texture_ptr, rect );
}
}
void tileset_cache::loader::create_textures_from_tile_atlas( const SDL_Surface_Ptr &tile_atlas,
const point &offset )
{
cata_assert( tile_atlas );
/** perform color filter conversion here */
using tiles_pixel_color_entry = std::tuple<std::vector<texture>*, std::string>;
std::array<tiles_pixel_color_entry, 5> tile_values_data = {{
{ std::make_tuple( &ts.tile_values, "color_pixel_none" ) },
{ std::make_tuple( &ts.shadow_tile_values, "color_pixel_grayscale" ) },
{ std::make_tuple( &ts.night_tile_values, "color_pixel_nightvision" ) },
{ std::make_tuple( &ts.overexposed_tile_values, "color_pixel_overexposed" ) },
{ std::make_tuple( &ts.memory_tile_values, tilecontext->memory_map_mode ) }
}
};
for( tiles_pixel_color_entry &entry : tile_values_data ) {
std::vector<texture> *tile_values = std::get<0>( entry );
color_pixel_function_pointer color_pixel_function = get_color_pixel_function( std::get<1>
( entry ) );
if( !color_pixel_function ) {
// TODO: Move it inside apply_color_filter.
copy_surface_to_texture( tile_atlas, offset, *tile_values );
} else {
copy_surface_to_texture( apply_color_filter( tile_atlas, color_pixel_function ), offset,
*tile_values );
}
}
}
template<typename T>
static void extend_vector_by( std::vector<T> &vec, const size_t additional_size )
{
vec.resize( vec.size() + additional_size );
}
void tileset_cache::loader::load_tileset( const cata_path &img_path, const bool pump_events )
{
cata_assert( sprite_width > 0 );
cata_assert( sprite_height > 0 );
const SDL_Surface_Ptr tile_atlas = load_image( img_path.get_unrelative_path().u8string().c_str() );
cata_assert( tile_atlas );
tile_atlas_width = tile_atlas->w;
if( R >= 0 && R <= 255 && G >= 0 && G <= 255 && B >= 0 && B <= 255 ) {
const Uint32 key = SDL_MapRGB( tile_atlas->format, 0, 0, 0 );
throwErrorIf( SDL_SetColorKey( tile_atlas.get(), SDL_TRUE, key ) != 0,
"SDL_SetColorKey failed" );
throwErrorIf( SDL_SetSurfaceRLE( tile_atlas.get(), 1 ), "SDL_SetSurfaceRLE failed" );
}
SDL_RendererInfo info;
throwErrorIf( SDL_GetRendererInfo( renderer.get(), &info ) != 0, "SDL_GetRendererInfo failed" );
// Software rendering stores textures as surfaces with run-length encoding, which makes
// extracting a part in the middle of the texture slow. Therefore this "simulates" that the
// renderer only supports one tile
// per texture. Each tile will go on its own texture object.
if( info.flags & SDL_RENDERER_SOFTWARE ) {
info.max_texture_width = sprite_width;
info.max_texture_height = sprite_height;
}
// for debugging only: force a very small maximal texture size, as to trigger
// splitting the tile atlas.
#if 0
// +1 to check correct rounding
info.max_texture_width = sprite_width * 10 + 1;
info.max_texture_height = sprite_height * 20 + 1;
#endif
const int min_tile_xcount = 128;
const int min_tile_ycount = min_tile_xcount * 2;
if( info.max_texture_width == 0 ) {
info.max_texture_width = sprite_width * min_tile_xcount;
DebugLog( D_INFO, DC_ALL ) << "SDL_RendererInfo max_texture_width was set to 0. " <<
" Changing it to " << info.max_texture_width;
} else {
throwErrorIf( info.max_texture_width < sprite_width,
"Maximal texture width is smaller than tile width" );
}
if( info.max_texture_height == 0 ) {
info.max_texture_height = sprite_height * min_tile_ycount;
DebugLog( D_INFO, DC_ALL ) << "SDL_RendererInfo max_texture_height was set to 0. " <<
" Changing it to " << info.max_texture_height;
} else {
throwErrorIf( info.max_texture_height < sprite_height,
"Maximal texture height is smaller than tile height" );
}
// Number of tiles in each dimension that fits into a (maximal) SDL texture.
// If the tile atlas contains more than that, we have to split it.
const int max_tile_xcount = info.max_texture_width / sprite_width;
const int max_tile_ycount = info.max_texture_height / sprite_height;
// Range over the tile atlas, wherein each rectangle fits into the maximal
// SDL texture size. In other words: a range over the parts into which the
// tile atlas needs to be split.
const rect_range<SDL_Rect> output_range(
max_tile_xcount * sprite_width,
max_tile_ycount * sprite_height,
point( divide_round_up( tile_atlas->w, info.max_texture_width ),
divide_round_up( tile_atlas->h, info.max_texture_height ) ) );
const int expected_tilecount = ( tile_atlas->w / sprite_width ) *
( tile_atlas->h / sprite_height );
extend_vector_by( ts.tile_values, expected_tilecount );
extend_vector_by( ts.shadow_tile_values, expected_tilecount );
extend_vector_by( ts.night_tile_values, expected_tilecount );
extend_vector_by( ts.overexposed_tile_values, expected_tilecount );
extend_vector_by( ts.memory_tile_values, expected_tilecount );
for( const SDL_Rect sub_rect : output_range ) {
cata_assert( sub_rect.x % sprite_width == 0 );
cata_assert( sub_rect.y % sprite_height == 0 );
cata_assert( sub_rect.w % sprite_width == 0 );
cata_assert( sub_rect.h % sprite_height == 0 );
SDL_Surface_Ptr smaller_surf;
if( is_contained( SDL_Rect{ 0, 0, tile_atlas->w, tile_atlas->h }, sub_rect ) ) {
// can use tile_atlas directly, it is completely contained in the output rectangle
} else {
// Need a temporary surface that contains the parts of the tile atlas that fit
// into sub_rect. But doesn't always need to be as large as sub_rect.
const int w = std::min( tile_atlas->w - sub_rect.x, sub_rect.w );
const int h = std::min( tile_atlas->h - sub_rect.y, sub_rect.h );
smaller_surf = ::create_surface_32( w, h );
cata_assert( smaller_surf );
const SDL_Rect inp{ sub_rect.x, sub_rect.y, w, h };
throwErrorIf( SDL_BlitSurface( tile_atlas.get(), &inp, smaller_surf.get(),
nullptr ) != 0, "SDL_BlitSurface failed" );
}
const SDL_Surface_Ptr &surf_to_use = smaller_surf ? smaller_surf : tile_atlas;
cata_assert( surf_to_use );
create_textures_from_tile_atlas( surf_to_use, point( sub_rect.x, sub_rect.y ) );
if( pump_events ) {
inp_mngr.pump_events();
}
}
size = expected_tilecount;
}
void cata_tiles::set_draw_scale( int scale )
{
cata_assert( tileset_ptr );
const int mult = tileset_ptr->get_tile_pixelscale() * scale;
const int div = 16;
tile_width = tileset_ptr->get_tile_width() * mult / div;
tile_height = tileset_ptr->get_tile_height() * mult / div;
max_tile_extent = tileset_ptr->get_max_tile_extent();
// Rounding down because the extent may be negative
max_tile_extent.p_min.x = divide_round_down( max_tile_extent.p_min.x * mult, div );
max_tile_extent.p_min.y = divide_round_down( max_tile_extent.p_min.y * mult, div );
max_tile_extent.p_max.x = divide_round_down( max_tile_extent.p_max.x * mult, div );
max_tile_extent.p_max.y = divide_round_down( max_tile_extent.p_max.y * mult, div );
zlevel_height = tileset_ptr->get_zlevel_height();
}
void tileset_cache::loader::load( const std::string &tileset_id, const bool precheck,
const bool pump_events )
{
std::string json_conf;
std::string layering;
std::string tileset_path;
cata_path tileset_root;
bool has_layering = true;
const auto tset_iter = TILESETS.find( tileset_id );
if( tset_iter != TILESETS.end() ) {
tileset_root = tset_iter->second;
dbg( D_INFO ) << '"' << tileset_id << '"' << " tileset: found config file path: " <<
tileset_root;
get_tile_information( tileset_root / PATH_INFO::tileset_conf(),
json_conf, tileset_path, layering );
dbg( D_INFO ) << "Current tileset is: " << tileset_id;
} else {
dbg( D_ERROR ) << "Tileset \"" << tileset_id << "\" from options is invalid";
json_conf = PATH_INFO::defaulttilejson();
tileset_path = PATH_INFO::defaulttilepng();
layering = PATH_INFO::defaultlayeringjson();
}
cata_path json_path = tileset_root / fs::u8path( json_conf );
cata_path img_path = tileset_root / fs::u8path( tileset_path );
cata_path layering_path = tileset_root / fs::u8path( layering );
dbg( D_INFO ) << "Attempting to Load LAYERING file " << layering_path;
std::ifstream layering_file( layering_path.get_unrelative_path(),
std::ifstream::in | std::ifstream::binary );
if( !layering_file.good() ) {
has_layering = false;
//throw std::runtime_error(std::string("Failed to open layering info json: ") + layering_path);
}
dbg( D_INFO ) << "Attempting to Load JSON file " << json_path;
std::optional<JsonValue> config_json = json_loader::from_path_opt( json_path );
if( !config_json.has_value() ) {
throw std::runtime_error( std::string( "Failed to open tile info json: " ) +
json_path.generic_u8string() );
}
JsonObject config = ( *config_json ).get_object();
config.allow_omitted_members();
// "tile_info" section must exist.
if( !config.has_member( "tile_info" ) ) {
config.throw_error( "\"tile_info\" missing" );
}
for( const JsonObject curr_info : config.get_array( "tile_info" ) ) {
ts.tile_height = curr_info.get_int( "height" );
ts.tile_width = curr_info.get_int( "width" );
ts.max_tile_extent = half_open_rectangle<point>( point_zero, { ts.tile_width, ts.tile_height } );
ts.zlevel_height = curr_info.get_int( "zlevel_height", 0 );
ts.tile_isometric = curr_info.get_bool( "iso", false );
ts.tile_pixelscale = curr_info.get_float( "pixelscale", 1.0f );
ts.prevent_occlusion_min_dist = curr_info.get_float( "retract_dist_min", -1.0f );
ts.prevent_occlusion_max_dist = curr_info.get_float( "retract_dist_max", 0.0f );
}
if( precheck ) {
config.allow_omitted_members();
return;
}
ts.clear();
// Load tile information if available.
offset = 0;
load_internal( config, tileset_root, img_path, pump_events );
// Load mod tilesets if available
for( const mod_tileset &mts : all_mod_tilesets ) {
// Set sprite_id offset to separate from other tilesets.
sprite_id_offset = offset;
tileset_root = mts.get_base_path();
json_path = mts.get_full_path();
if( !mts.is_compatible( tileset_id ) ) {
dbg( D_ERROR ) << "Mod tileset in \"" << json_path << "\" is not compatible with \""
<< tileset_id << "\".";
continue;
}
dbg( D_INFO ) << "Attempting to Load JSON file " << json_path;
std::optional<JsonValue> mod_config_json_opt = json_loader::from_path_opt( json_path );
if( !mod_config_json_opt.has_value() ) {
throw std::runtime_error( std::string( "Failed to open tile info json: " ) +
json_path.generic_u8string() );
}
JsonValue &mod_config_json = *mod_config_json_opt;
const auto mark_visited = []( const JsonObject & jobj ) {
// These fields have been visited in load_mod_tileset
jobj.get_string_array( "compatibility" );
};
int num_in_file = 1;
if( mod_config_json.test_array() ) {
for( const JsonObject mod_config : mod_config_json.get_array() ) {
if( mod_config.get_string( "type" ) == "mod_tileset" ) {
mark_visited( mod_config );
if( num_in_file == mts.num_in_file() ) {
// visit this if it exists, it's used elsewhere
if( mod_config.has_member( "compatibility" ) ) {
mod_config.get_member( "compatibility" );
}
load_internal( mod_config, tileset_root, img_path, pump_events );
break;
}
num_in_file++;
}
}
} else {
JsonObject mod_config = mod_config_json.get_object();
mark_visited( mod_config );
load_internal( mod_config, tileset_root, img_path, pump_events );
}
}
// loop through all tile ids and eliminate empty/invalid things
for( auto it = ts.tile_ids.begin(); it != ts.tile_ids.end(); ) {
// second is the tile_type describing that id
tile_type &td = it->second;
process_variations_after_loading( td.fg );
process_variations_after_loading( td.bg );
// All tiles need at least foreground or background data, otherwise they are useless.
if( td.bg.empty() && td.fg.empty() ) {
dbg( D_ERROR ) << "tile " << it->first << " has no (valid) foreground nor background";
ts.tile_ids.erase( it++ );
} else {
++it;
}
}
if( !ts.find_tile_type( "unknown" ) ) {
dbg( D_ERROR ) << "The tileset you're using has no 'unknown' tile defined!";
}
ensure_default_item_highlight();
ts.tileset_id = tileset_id;
// set up layering data
if( has_layering ) {
JsonValue layering_json = json_loader::from_path( layering_path );
JsonObject layer_config = layering_json.get_object();
layer_config.allow_omitted_members();
// "variants" section must exist.
if( !layer_config.has_member( "variants" ) ) {
layer_config.throw_error( "\"variants\" missing" );
}
load_layers( layer_config );
}
}
void tileset_cache::loader::load_internal( const JsonObject &config,
const cata_path &tileset_root,
const cata_path &img_path, const bool pump_events )
{
if( config.has_array( "tiles-new" ) ) {
// new system, several entries
// When loading multiple tileset images this defines where
// the tiles from the most recently loaded image start from.
for( const JsonObject tile_part_def : config.get_array( "tiles-new" ) ) {
const cata_path tileset_image_path = tileset_root / tile_part_def.get_string( "file" );
R = -1;
G = -1;
B = -1;
if( tile_part_def.has_object( "transparency" ) ) {
JsonObject tra = tile_part_def.get_object( "transparency" );
R = tra.get_int( "R" );
G = tra.get_int( "G" );
B = tra.get_int( "B" );
}
sprite_width = tile_part_def.get_int( "sprite_width", ts.tile_width );
sprite_height = tile_part_def.get_int( "sprite_height", ts.tile_height );
// Now load the tile definitions for the loaded tileset image.
sprite_offset.x = tile_part_def.get_int( "sprite_offset_x", 0 );
sprite_offset.y = tile_part_def.get_int( "sprite_offset_y", 0 );
sprite_offset_retracted.x = tile_part_def.get_int( "sprite_offset_x_retracted", sprite_offset.x );
sprite_offset_retracted.y = tile_part_def.get_int( "sprite_offset_y_retracted", sprite_offset.y );
sprite_pixelscale = tile_part_def.get_float( "pixelscale", 1.0 );
// Update maximum tile extent
ts.max_tile_extent = half_open_rectangle<point> {
{
std::min( ts.max_tile_extent.p_min.x,
std::min( sprite_offset.x, sprite_offset_retracted.x ) ),
std::min( ts.max_tile_extent.p_min.y,
std::min( sprite_offset.y, sprite_offset_retracted.y ) ),
}, {
std::max( ts.max_tile_extent.p_max.x,
sprite_width + std::max( sprite_offset.x, sprite_offset_retracted.x ) ),
std::max( ts.max_tile_extent.p_max.y,
sprite_height + std::max( sprite_offset.y, sprite_offset_retracted.y ) ),
}
};
// First load the tileset image to get the number of available tiles.
dbg( D_INFO ) << "Attempting to Load Tileset file " << tileset_image_path;
load_tileset( tileset_image_path, pump_events );
load_tilejson_from_file( tile_part_def );
if( tile_part_def.has_member( "ascii" ) ) {
load_ascii( tile_part_def );
}
// Make sure the tile definitions of the next tileset image don't
// override the current ones.
offset += size;
if( pump_events ) {
inp_mngr.pump_events();
}
}
} else {
sprite_width = ts.tile_width;
sprite_height = ts.tile_height;
sprite_offset = point_zero;
sprite_offset_retracted = point_zero;
sprite_pixelscale = 1.0;
R = -1;
G = -1;
B = -1;
// old system, no tile file path entry, only one array of tiles
dbg( D_INFO ) << "Attempting to Load Tileset file " << img_path;
load_tileset( img_path, pump_events );
load_tilejson_from_file( config );
offset = size;
}
// allows a tileset to override the order of mutation images being applied to a character
if( config.has_array( "overlay_ordering" ) ) {
load_overlay_ordering_into_array( config, tileset_mutation_overlay_ordering );
}
// offset should be the total number of sprites loaded from every tileset image
// eliminate any sprite references that are too high to exist
// also eliminate negative sprite references
}
void tileset_cache::loader::load_layers( const JsonObject &config )
{
for( const JsonObject item : config.get_array( "variants" ) ) {
if( item.has_member( "context" ) && ( item.has_array( "item_variants" ) ||
item.has_array( "field_variants" ) ) ) {
std::string context;
context = item.get_string( "context" );
std::vector<layer_variant> item_variants;
std::vector<layer_variant> field_variants;
if( item.has_array( "item_variants" ) ) {
for( const JsonObject vars : item.get_array( "item_variants" ) ) {
if( vars.has_member( "item" ) && vars.has_array( "sprite" ) && vars.has_member( "layer" ) ) {
layer_variant v;
v.id = vars.get_string( "item" );
v.layer = vars.get_int( "layer" );
v.offset = point( vars.get_int( "offset_x", 0 ), vars.get_int( "offset_y", 0 ) );
int total_weight = 0;
for( const JsonObject sprites : vars.get_array( "sprite" ) ) {
std::string id = sprites.get_string( "id" );
int weight = sprites.get_int( "weight", 1 );
v.sprite.emplace( id, weight );
total_weight += weight;
}
v.total_weight = total_weight;
item_variants.push_back( v );
} else {
config.throw_error( "item_variants configured incorrectly" );
}
}
// sort them based on layering so we can draw them correctly
std::sort( item_variants.begin(), item_variants.end(), []( const layer_variant & a,
const layer_variant & b ) {
return a.layer < b.layer;
} );
ts.item_layer_data.emplace( context, item_variants );
}
if( item.has_array( "field_variants" ) ) {
for( const JsonObject vars : item.get_array( "field_variants" ) ) {
if( vars.has_member( "field" ) && vars.has_array( "sprite" ) ) {
layer_variant v;
v.id = vars.get_string( "field" );
v.offset = point( vars.get_int( "offset_x", 0 ), vars.get_int( "offset_y", 0 ) );
int total_weight = 0;
for( const JsonObject sprites : vars.get_array( "sprite" ) ) {
std::string id = sprites.get_string( "id" );
int weight = sprites.get_int( "weight", 1 );
v.sprite.emplace( id, weight );
total_weight += weight;
}
v.total_weight = total_weight;
field_variants.push_back( v );
} else {
config.throw_error( "field_variants configured incorrectly" );
}
}
ts.field_layer_data.emplace( context, field_variants );
}
} else {
config.throw_error( "layering configured incorrectly" );
}
}
}
void tileset_cache::loader::process_variations_after_loading(
weighted_int_list<std::vector<int>> &vs ) const
{
// loop through all of the variations
for( auto &v : vs ) {
// in a given variation, erase any invalid sprite ids
v.obj.erase(
std::remove_if(
v.obj.begin(),
v.obj.end(),
[&]( int id ) {
return id >= offset || id < 0;
} ),
v.obj.end()
);
}
// erase any variations with no valid sprite ids left
vs.erase(
std::remove_if(
vs.begin(),
vs.end(),
[&]( const weighted_object<int, std::vector<int>> &o ) {
return o.obj.empty();
}
),
vs.end()
);
// populate the bookkeeping table used for selecting sprite variations
vs.precalc();
}
void tileset_cache::loader::add_ascii_subtile( tile_type &curr_tile, const std::string &t_id,
int sprite_id, const std::string &s_id )
{
const std::string m_id = t_id + "_" + s_id;
tile_type curr_subtile;
curr_subtile.fg.add( std::vector<int>( {sprite_id} ), 1 );
curr_subtile.rotates = true;
curr_tile.available_subtiles.push_back( s_id );
ts.create_tile_type( m_id, std::move( curr_subtile ) );
}
void tileset_cache::loader::load_ascii( const JsonObject &config )
{
if( !config.has_member( "ascii" ) ) {
config.throw_error( "\"ascii\" section missing" );
}
for( const JsonObject entry : config.get_array( "ascii" ) ) {
load_ascii_set( entry );
}
}
void tileset_cache::loader::load_ascii_set( const JsonObject &entry )
{
// tile for ASCII char 0 is at `in_image_offset`,
// the other ASCII chars follow from there.
const int in_image_offset = entry.get_int( "offset" );
if( in_image_offset >= size ) {
entry.throw_error_at( "offset", "invalid offset (out of range)" );
}
// color, of the ASCII char. Can be -1 to indicate all/default colors.
int FG = -1;
const std::string scolor = entry.get_string( "color", "DEFAULT" );
if( scolor == "BLACK" ) {
FG = catacurses::black;
} else if( scolor == "RED" ) {
FG = catacurses::red;
} else if( scolor == "GREEN" ) {
FG = catacurses::green;
} else if( scolor == "YELLOW" ) {
FG = catacurses::yellow;
} else if( scolor == "BLUE" ) {
FG = catacurses::blue;
} else if( scolor == "MAGENTA" ) {
FG = catacurses::magenta;
} else if( scolor == "CYAN" ) {
FG = catacurses::cyan;
} else if( scolor == "WHITE" ) {
FG = catacurses::white;
} else if( scolor == "DEFAULT" ) {
FG = -1;
} else {
entry.throw_error_at( "color", "invalid color for ASCII" );
}
// Add an offset for bold colors (ncurses has this bold attribute,
// this mimics it). bold does not apply to default color.
if( FG != -1 && entry.get_bool( "bold", false ) ) {
FG += 8;
}
const int base_offset = offset + in_image_offset;
// Finally load all 256 ASCII chars (actually extended ASCII)
for( int ascii_char = 0; ascii_char < 256; ascii_char++ ) {
const int index_in_image = ascii_char + in_image_offset;
if( index_in_image < 0 || index_in_image >= size ) {
// Out of range is ignored for now.
continue;
}
const std::string id = get_ascii_tile_id( ascii_char, FG, -1 );
tile_type curr_tile;
curr_tile.offset = sprite_offset;
curr_tile.offset_retracted = sprite_offset_retracted;
curr_tile.pixelscale = sprite_pixelscale;
auto &sprites = *curr_tile.fg.add( std::vector<int>( {index_in_image + offset} ), 1 );
switch( ascii_char ) {
// box bottom/top side (horizontal line)
case LINE_OXOX_C:
sprites[0] = 205 + base_offset;
break;
// box left/right side (vertical line)
case LINE_XOXO_C:
sprites[0] = 186 + base_offset;
break;
// box top left
case LINE_OXXO_C:
sprites[0] = 201 + base_offset;
break;
// box top right
case LINE_OOXX_C:
sprites[0] = 187 + base_offset;
break;
// box bottom right
case LINE_XOOX_C:
sprites[0] = 188 + base_offset;
break;
// box bottom left
case LINE_XXOO_C:
sprites[0] = 200 + base_offset;
break;
// box bottom north T (left, right, up)
case LINE_XXOX_C:
sprites[0] = 202 + base_offset;
break;
// box bottom east T (up, right, down)
case LINE_XXXO_C:
sprites[0] = 208 + base_offset;
break;
// box bottom south T (left, right, down)
case LINE_OXXX_C:
sprites[0] = 203 + base_offset;
break;
// box X (left down up right)
case LINE_XXXX_C:
sprites[0] = 206 + base_offset;
break;
// box bottom east T (left, down, up)
case LINE_XOXX_C:
sprites[0] = 184 + base_offset;
break;
}
if( ascii_char == LINE_XOXO_C || ascii_char == LINE_OXOX_C ) {
curr_tile.rotates = false;
curr_tile.multitile = true;
add_ascii_subtile( curr_tile, id, 206 + base_offset, "center" );
add_ascii_subtile( curr_tile, id, 201 + base_offset, "corner" );
add_ascii_subtile( curr_tile, id, 186 + base_offset, "edge" );
add_ascii_subtile( curr_tile, id, 203 + base_offset, "t_connection" );
add_ascii_subtile( curr_tile, id, 210 + base_offset, "end_piece" );
add_ascii_subtile( curr_tile, id, 219 + base_offset, "unconnected" );
}
ts.create_tile_type( id, std::move( curr_tile ) );
}
}
void tileset_cache::loader::load_tilejson_from_file( const JsonObject &config )
{
if( !config.has_member( "tiles" ) ) {
config.throw_error( "\"tiles\" section missing" );
}
for( const JsonObject entry : config.get_array( "tiles" ) ) {
std::vector<std::string> ids;
if( entry.has_string( "id" ) ) {
ids.push_back( entry.get_string( "id" ) );
} else if( entry.has_array( "id" ) ) {
ids = entry.get_string_array( "id" );
}
for( const std::string &t_id : ids ) {
tile_type &curr_tile = load_tile( entry, t_id );
curr_tile.offset = sprite_offset;
curr_tile.offset_retracted = sprite_offset_retracted;
curr_tile.pixelscale = sprite_pixelscale;
bool t_multi = entry.get_bool( "multitile", false );
bool t_rota = entry.get_bool( "rotates", t_multi );
int t_h3d = entry.get_int( "height_3d", 0 );
if( t_multi ) {
// fetch additional tiles
for( const JsonObject subentry : entry.get_array( "additional_tiles" ) ) {
const std::string s_id = subentry.get_string( "id" );
const std::string m_id = str_cat( t_id, "_", s_id );
tile_type &curr_subtile = load_tile( subentry, m_id );
curr_subtile.offset = sprite_offset;
curr_subtile.offset_retracted = sprite_offset_retracted;
curr_subtile.pixelscale = sprite_pixelscale;
curr_subtile.rotates = true;
curr_subtile.height_3d = t_h3d;
curr_subtile.animated = subentry.get_bool( "animated", false );
curr_tile.available_subtiles.push_back( s_id );
}
} else if( entry.has_array( "additional_tiles" ) ) {
try {
entry.throw_error( "Additional tiles defined, but 'multitile' is not true." );
} catch( const JsonError &err ) {
debugmsg( "(json-error)\n%s", err.what() );
}
}
// write the information of the base tile to curr_tile
curr_tile.multitile = t_multi;
curr_tile.rotates = t_rota;
curr_tile.height_3d = t_h3d;
curr_tile.animated = entry.get_bool( "animated", false );
}
}
dbg( D_INFO ) << "Tile Width: " << ts.tile_width << " Tile Height: " << ts.tile_height <<
" Tile Definitions: " << ts.tile_ids.size();
}
/**
* Load a tile definition and add it to the @ref tileset::tile_ids map.
* All loaded tiles go into one vector (@ref tileset::tile_values), their index in it is their id.
* The JSON data (loaded here) contains tile ids relative to the associated image.
* They are translated into global ids by adding the @p offset, which is the number of
* previously loaded tiles (excluding the tiles from the associated image).
* @param id The id of the new tile definition (which is the key in @ref tileset::tile_ids).
* Any existing definition of the same id is overridden.
* @return A reference to the loaded tile inside the @ref tileset::tile_ids map.
*/
tile_type &tileset_cache::loader::load_tile( const JsonObject &entry, const std::string &id )
{
if( ts.find_tile_type( id ) ) {
ts.duplicate_ids.insert( id );
}
tile_type curr_subtile;
load_tile_spritelists( entry, curr_subtile.fg, "fg" );
load_tile_spritelists( entry, curr_subtile.bg, "bg" );
return ts.create_tile_type( id, std::move( curr_subtile ) );
}
void tileset_cache::loader::load_tile_spritelists( const JsonObject &entry,
weighted_int_list<std::vector<int>> &vs,
const std::string_view objname ) const
{
// json array indicates rotations or variations
if( entry.has_array( objname ) ) {
JsonArray g_array = entry.get_array( objname );
// int elements of array indicates rotations
// create one variation, populate sprite_ids with list of ints
if( g_array.test_int() ) {
std::vector<int> v;
for( const int entry : g_array ) {
const int sprite_id = entry + sprite_id_offset;
if( sprite_id >= 0 ) {
v.push_back( sprite_id );
}
}
vs.add( v, 1 );
}
// object elements of array indicates variations
// create one variation per object
else if( g_array.test_object() ) {
for( const JsonObject vo : g_array ) {
std::vector<int> v;
int weight = vo.get_int( "weight" );
// negative weight is invalid
if( weight < 0 ) {
vo.throw_error_at( objname, "Invalid weight for sprite variation (<0)" );
}
// int sprite means one sprite
if( vo.has_int( "sprite" ) ) {
const int sprite_id = vo.get_int( "sprite" ) + sprite_id_offset;
if( sprite_id >= 0 ) {
v.push_back( sprite_id );
}
}
// array sprite means rotations
else if( vo.has_array( "sprite" ) ) {
for( const int entry : vo.get_array( "sprite" ) ) {
const int sprite_id = entry + sprite_id_offset;
if( sprite_id >= 0 ) {
v.push_back( sprite_id );
}
}
}
if( v.size() != 1 &&
v.size() != 2 &&
v.size() != 4 ) {
vo.throw_error_at( objname, "Invalid number of sprites (not 1, 2, or 4)" );
}
vs.add( v, weight );
}
}
}
// json int indicates a single sprite id
else if( entry.has_int( objname ) && entry.get_int( objname ) >= 0 ) {
vs.add( std::vector<int>( {entry.get_int( objname ) + sprite_id_offset} ), 1 );
}
}
static std::map<tripoint, int> display_npc_attack_potential()
{
avatar &you = get_avatar();
npc avatar_as_npc;
std::ostringstream os;
JsonOut jsout( os );
jsout.write( you );
JsonValue jsin = json_loader::from_string( os.str() );
jsin.read( avatar_as_npc );
avatar_as_npc.regen_ai_cache();
avatar_as_npc.evaluate_best_weapon( nullptr );
std::map<tripoint, int> effectiveness_map;
std::vector<npc_attack_rating> effectiveness =
avatar_as_npc.get_current_attack()->all_evaluations( avatar_as_npc, nullptr );
for( const npc_attack_rating &effectiveness_at_point : effectiveness ) {
if( !effectiveness_at_point.value() ) {
continue;
}
effectiveness_map[effectiveness_at_point.target()] = *effectiveness_at_point.value();
}
return effectiveness_map;
}
void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int height,
std::multimap<point, formatted_text> &overlay_strings,
color_block_overlay_container &color_blocks )
{
if( !g ) {
return;
}
#if defined(__ANDROID__)
// Attempted bugfix for Google Play crash - prevent divide-by-zero if no tile
// width/height specified
if( tile_width == 0 || tile_height == 0 ) {
return;
}
#endif
{
//set clipping to prevent drawing over stuff we shouldn't
SDL_Rect clipRect = {dest.x, dest.y, width, height};
printErrorIf( SDL_RenderSetClipRect( renderer.get(), &clipRect ) != 0,
"SDL_RenderSetClipRect failed" );
//fill render area with black to prevent artifacts where no new pixels are drawn
geometry->rect( renderer, clipRect, SDL_Color() );
}
const point s = get_window_base_tile_counts( point( width, height ) );
init_light();
map &here = get_map();
const visibility_variables &cache = here.get_visibility_variables_cache();
o = is_isometric() ? center.xy() : center.xy() - point( POSX, POSY );
op = dest;
screentile_width = s.x;
screentile_height = s.y;
// Limit draw depth to vertical vision setting
const int max_draw_depth = fov_3d_z_range;
const int num_ranges = is_isometric() ? 1 + std::max( 0, max_draw_depth ) : 1;
std::vector<half_open_rectangle<point>> z_any_tile_range( num_ranges );
for( int z = 0; z < num_ranges; ++z ) {
z_any_tile_range[z] = get_window_any_tile_range( { width, height }, -z );
}
const half_open_rectangle<point> &top_any_tile_range = z_any_tile_range[0];
const half_open_rectangle<point> &bottom_any_tile_range = z_any_tile_range[num_ranges - 1];
cata_assert( top_any_tile_range.p_min.x == bottom_any_tile_range.p_min.x );
cata_assert( top_any_tile_range.p_max.x == bottom_any_tile_range.p_max.x );
cata_assert( top_any_tile_range.p_min.y >= bottom_any_tile_range.p_min.y );
cata_assert( top_any_tile_range.p_max.y >= bottom_any_tile_range.p_max.y );
const int min_col = top_any_tile_range.p_min.x;
const int max_col = top_any_tile_range.p_max.x;
const int min_row = bottom_any_tile_range.p_min.y;
const int max_row = top_any_tile_range.p_max.y;
avatar &you = get_avatar();
//limit the render area to maximum view range (121x121 square centered on player)
const point min_visible( you.posx() % SEEX, you.posy() % SEEY );
const point max_visible( ( you.posx() % SEEX ) + ( MAPSIZE - 1 ) * SEEX,
( you.posy() % SEEY ) + ( MAPSIZE - 1 ) * SEEY );
const int draw_min_z = std::max( you.posz() - max_draw_depth, -OVERMAP_DEPTH );
const level_cache &ch = here.access_cache( center.z );
// Map memory should be at least the size of the view range
// so that new tiles can be memorized, and at least the size of the display
// since at farthest zoom displayed area may be bigger than view range.
point min_mm_reg = min_visible;
point max_mm_reg = max_visible;
if( is_isometric() ) {
std::optional<point> northmost = tile_to_player( { min_col, min_row } );
if( !northmost.has_value() ) {
northmost = tile_to_player( { min_col + 1, min_row } );
}
std::optional<point> southmost = tile_to_player( { max_col, max_row } );
if( !southmost.has_value() ) {
southmost = tile_to_player( { max_col - 1, max_row } );
}
std::optional<point> westmost = tile_to_player( { min_col, max_row } );
if( !westmost.has_value() ) {
westmost = tile_to_player( { min_col + 1, max_row } );
}
std::optional<point> eastmost = tile_to_player( { max_col, min_row } );
if( !eastmost.has_value() ) {
eastmost = tile_to_player( { max_col - 1, min_row } );
}
if( northmost.has_value() && southmost.has_value()
&& westmost.has_value() && eastmost.has_value() ) {
min_mm_reg = point( std::min( min_mm_reg.x, westmost->x ),
std::min( min_mm_reg.y, northmost->y ) );
max_mm_reg = point( std::max( max_mm_reg.x, eastmost->x ),
std::max( max_mm_reg.y, southmost->y ) );
}
} else {
std::optional<point> northwest = tile_to_player( { min_col, min_row } );
std::optional<point> southeast = tile_to_player( { max_col, max_row } );
if( northwest.has_value() && southeast.has_value() ) {
min_mm_reg = point( std::min( min_mm_reg.x, northwest->x ),
std::min( max_mm_reg.y, northwest->y ) );
max_mm_reg = point( std::max( max_mm_reg.x, southeast->x ),
std::max( max_mm_reg.y, southeast->y ) );
}
}
//invalidate draw_points_cache if viewport dimensions have changed
point top_left( min_col, min_row );
point bottom_right( max_col, max_row );
if( top_left != here.prev_top_left || bottom_right != here.prev_bottom_right || o != here.prev_o ) {
set_draw_cache_dirty();
}
here.prev_top_left = top_left;
here.prev_bottom_right = bottom_right;
here.prev_o = o;
you.prepare_map_memory_region(
here.getglobal( tripoint( min_mm_reg, center.z ) ),
here.getglobal( tripoint( max_mm_reg, center.z ) )
);
//set up a default tile for the edges outside the render area
visibility_type offscreen_type = visibility_type::HIDDEN;
if( cache.u_is_boomered ) {
offscreen_type = visibility_type::BOOMER_DARK;
}
//retrieve night vision goggle status once per draw
auto vision_cache = you.get_vision_modes();
nv_goggles_activated = vision_cache[NV_GOGGLES];
// check that the creature for which we'll draw the visibility map is still alive at that point
if( g->display_overlay_state( ACTION_DISPLAY_VISIBILITY ) &&
g->displaying_visibility_creature ) {
const Creature *creature = g->displaying_visibility_creature;
const auto is_same_creature_predicate = [&creature]( const Creature & c ) {
return creature == &c;
};
if( g->get_creature_if( is_same_creature_predicate ) == nullptr ) {
g->displaying_visibility_creature = nullptr;
}
}
const point half_tile( tile_width / 2, 0 );
const point quarter_tile( tile_width / 4, tile_height / 4 );
const auto apply_visible = [&]( const tripoint & np, const level_cache & ch, map & here ) {
return np.y < min_visible.y || np.y > max_visible.y ||
np.x < min_visible.x || np.x > max_visible.x ||
would_apply_vision_effects( here.get_visibility( ch.visibility_cache[np.x][np.y],
cache ) );
};
std::map<tripoint, int> npc_attack_rating_map;
int max_npc_effectiveness = 0;
if( g->display_overlay_state( ACTION_DISPLAY_NPC_ATTACK_POTENTIAL ) ) {
npc_attack_rating_map = display_npc_attack_potential();
for( const std::pair<const tripoint, int> &pair : npc_attack_rating_map ) {
max_npc_effectiveness = std::max( pair.second, max_npc_effectiveness );
}
}
if( here.draw_points_cache_dirty ) {
here.draw_points_cache_dirty = false;
// overlay_strings and color_blocks are generated with draw_points and thus are cleared together
here.draw_points_cache.clear();
here.overlay_strings_cache.clear();
here.color_blocks_cache = {};
if( g->display_overlay_state( ACTION_DISPLAY_VEHICLE_AI ) ) {
for( const wrapped_vehicle &elem : here.get_vehicles() ) {
const vehicle &veh = *elem.v;
const point veh_pos = veh.global_pos3().xy();
for( const auto &overlay_data : veh.get_debug_overlay_data() ) {
const point pt = veh_pos + std::get<0>( overlay_data );
const int color = std::get<1>( overlay_data );
const std::string &text = std::get<2>( overlay_data );
overlay_strings.emplace( player_to_screen( pt ),
formatted_text( text, color,
text_alignment::left ) );
}
}
}
// Generate new draw points
creature_tracker &creatures = get_creature_tracker();
for( int row = min_row; row < max_row; row ++ ) {
// Reserve columns on each row
for( int zlevel = center.z; zlevel >= draw_min_z; zlevel -- ) {
here.draw_points_cache[zlevel][row].reserve( std::max( 0, max_col - min_col ) );
}
for( int col = min_col; col < max_col; col ++ ) {
const std::optional<point> temp = tile_to_player( { col, row } );
if( !temp.has_value() ) {
continue;
}
for( int zlevel = center.z; zlevel >= draw_min_z; zlevel -- ) {
const tripoint pos( temp.value(), zlevel );
const tripoint_abs_ms pos_global = here.getglobal( pos );
const int &x = pos.x;
const int &y = pos.y;
const bool is_center_z = zlevel == center.z;
const level_cache &ch2 = here.access_cache( zlevel );
// light level is used for choosing between grayscale filter and normal lit tiles.
lit_level ll;
// invisible to normal eyes
std::array<bool, 5> invisible;
invisible[0] = false;
if( y < min_visible.y || y > max_visible.y || x < min_visible.x || x > max_visible.x ) {
if( has_memory_at( pos_global ) ) {
ll = lit_level::MEMORIZED;
invisible[0] = true;
} else if( has_draw_override( pos ) ) {
ll = lit_level::DARK;
invisible[0] = true;
} else {
if( would_apply_vision_effects( offscreen_type ) ) {
here.draw_points_cache[zlevel][row].emplace_back( tile_render_info::common{ pos, 0 },
tile_render_info::vision_effect{ offscreen_type } );
}
break;
}
} else {
ll = ch2.visibility_cache[x][y];
}
if( is_center_z ) {
// Add scent value to the overlay_strings list for every visible tile when
// displaying scent
if( g->display_overlay_state( ACTION_DISPLAY_SCENT ) && !invisible[0] ) {
const int scent_value = get_scent().get( pos );
if( scent_value > 0 ) {
here.overlay_strings_cache.emplace( player_to_screen( point( x, y ) ) + half_tile,
formatted_text( std::to_string( scent_value ),
8 + catacurses::yellow, direction::NORTH ) );
}
}
// Add scent type to the overlay_strings list for every visible tile when
// displaying scent
if( g->display_overlay_state( ACTION_DISPLAY_SCENT_TYPE ) && !invisible[0] ) {
const scenttype_id scent_type = get_scent().get_type( pos );
if( !scent_type.is_empty() ) {
here.overlay_strings_cache.emplace( player_to_screen( point( x, y ) ) + half_tile,
formatted_text( scent_type.c_str(),
8 + catacurses::yellow, direction::NORTH ) );
}
}
if( g->display_overlay_state( ACTION_DISPLAY_RADIATION ) ) {
const auto rad_override = radiation_override.find( pos );
const bool rad_overridden = rad_override != radiation_override.end();
if( rad_overridden || !invisible[0] ) {
const int rad_value = rad_overridden ? rad_override->second :
here.get_radiation( pos );
catacurses::base_color col;
if( rad_value > 0 ) {
col = catacurses::green;
} else {
col = catacurses::cyan;
}
here.overlay_strings_cache.emplace( player_to_screen( point( x, y ) ) + half_tile,
formatted_text( std::to_string( rad_value ),
8 + col, direction::NORTH ) );
}
}
if( g->display_overlay_state( ACTION_DISPLAY_NPC_ATTACK_POTENTIAL ) ) {
if( npc_attack_rating_map.count( pos ) ) {
const int val = npc_attack_rating_map.at( pos );
short color;
if( val <= 0 ) {
color = catacurses::red;
} else if( val == max_npc_effectiveness ) {
color = catacurses::cyan;
} else {
color = catacurses::white;
}
here.overlay_strings_cache.emplace( player_to_screen( point( x, y ) ) + half_tile,
formatted_text( std::to_string( val ), color,
direction::NORTH ) );
}
}
// Add temperature value to the overlay_strings list for every visible tile when
// displaying temperature
if( g->display_overlay_state( ACTION_DISPLAY_TEMPERATURE ) && !invisible[0] ) {
const units::temperature temp_value = get_weather().get_temperature( pos );
const float celsius_temp_value = units::to_celsius( temp_value );
short color;
const short bold = 8;
if( celsius_temp_value > 40 ) {
color = catacurses::red;
} else if( celsius_temp_value > 25 ) {
color = catacurses::yellow + bold;
} else if( celsius_temp_value > 10 ) {
color = catacurses::green + bold;
} else if( celsius_temp_value > 0 ) {
color = catacurses::white + bold;
} else if( celsius_temp_value > -10 ) {
color = catacurses::cyan + bold;
} else {
color = catacurses::blue + bold;
}
std::string temp_str;
if( get_option<std::string>( "USE_CELSIUS" ) == "celsius" ) {
temp_str = string_format( "%.0f", celsius_temp_value );
} else if( get_option<std::string>( "USE_CELSIUS" ) == "kelvin" ) {
temp_str = string_format( "%.0f", units::to_kelvin( temp_value ) );
} else {
temp_str = string_format( "%.0f", units::to_fahrenheit( temp_value ) );
}
here.overlay_strings_cache.emplace( player_to_screen( point( x, y ) ),
formatted_text( temp_str, color,
text_alignment::left ) );
}
if( g->display_overlay_state( ACTION_DISPLAY_VISIBILITY ) &&
g->displaying_visibility_creature && !invisible[0] ) {
const bool visibility = g->displaying_visibility_creature->sees( pos );
// color overlay.
SDL_Color block_color = visibility ? windowsPalette[catacurses::green] :
SDL_Color{ 192, 192, 192, 255 };
block_color.a = 100;
here.color_blocks_cache.first = SDL_BLENDMODE_BLEND;
here.color_blocks_cache.second.emplace( player_to_screen( point( x, y ) ), block_color );
// overlay string
std::string visibility_str = visibility ? "+" : "-";
here.overlay_strings_cache.emplace( player_to_screen( point( x, y ) ) + quarter_tile,
formatted_text( visibility_str, catacurses::black,
direction::NORTH ) );
}
static std::vector<SDL_Color> lighting_colors;
// color hue in the range of [0..10], 0 being white, 10 being blue
auto draw_debug_tile = [&]( const int color_hue, const std::string & text ) {
if( lighting_colors.empty() ) {
SDL_Color white = { 255, 255, 255, 255 };
SDL_Color blue = { 0, 0, 255, 255 };
lighting_colors = color_linear_interpolate( white, blue, 9 );
}
point tile_pos = player_to_screen( point( x, y ) );
// color overlay
SDL_Color color = lighting_colors[std::min( std::max( 0, color_hue ), 10 )];
color.a = 100;
here.color_blocks_cache.first = SDL_BLENDMODE_BLEND;
here.color_blocks_cache.second.emplace( tile_pos, color );
// string overlay
here.overlay_strings_cache.emplace(
tile_pos + quarter_tile,
formatted_text( text, catacurses::black, direction::NORTH ) );
};
if( g->display_overlay_state( ACTION_DISPLAY_LIGHTING ) ) {
if( g->displaying_lighting_condition == 0 ) {
const float light = here.ambient_light_at( {x, y, center.z} );
// note: lighting will be constrained in the [1.0, 11.0] range.
int intensity =
static_cast<int>( std::max( 1.0, LIGHT_AMBIENT_LIT - light + 1.0 ) ) - 1;
draw_debug_tile( intensity, string_format( "%.1f", light ) );
}
}
if( g->display_overlay_state( ACTION_DISPLAY_TRANSPARENCY ) ) {
const float tr = here.light_transparency( {x, y, center.z} );
int intensity = tr <= LIGHT_TRANSPARENCY_SOLID ? 10 : static_cast<int>
( ( tr - LIGHT_TRANSPARENCY_OPEN_AIR ) * 8 );
draw_debug_tile( intensity, string_format( "%.2f", tr ) );
}
if( g->display_overlay_state( ACTION_DISPLAY_REACHABILITY_ZONES ) ) {
tripoint tile_pos( x, y, center.z );
int value = here.reachability_cache_value( tile_pos,
g->debug_rz_display.r_cache_vertical, g->debug_rz_display.quadrant );
// use color to denote reachability from you to the target tile according to the
// cache
bool reachable = here.has_potential_los( you.pos(), tile_pos );
draw_debug_tile( reachable ? 0 : 6, std::to_string( value ) );
}
}
if( !invisible[0] ) {
const visibility_type vis_type = here.get_visibility( ll, cache );
if( would_apply_vision_effects( vis_type ) ) {
const Creature *critter = creatures.creature_at( pos, true );
if( has_draw_override( pos ) || has_memory_at( pos_global ) ||
( critter &&
( critter->has_flag( mon_flag_ALWAYS_VISIBLE )
|| you.sees_with_infrared( *critter )
|| you.sees_with_specials( *critter ) ) ) ) {
invisible[0] = true;
} else {
here.draw_points_cache[zlevel][row].emplace_back( tile_render_info::common{ pos, 0 },
tile_render_info::vision_effect{ vis_type } );
break;
}
}
}
for( int i = 0; i < 4; i++ ) {
const tripoint np = pos + neighborhood[i];
invisible[1 + i] = apply_visible( np, ch2, here );
}
here.draw_points_cache[zlevel][row].emplace_back( tile_render_info::common{ pos, 0 },
tile_render_info::sprite{ ll, invisible } );
// Stop building draw points below when floor reached
if( here.dont_draw_lower_floor( pos ) ) {
break;
}
}
}
}
}
overlay_strings = here.overlay_strings_cache;
color_blocks = here.color_blocks_cache;
// List all layers for a single z-level
const std::array<decltype( &cata_tiles::draw_furniture ), 11> drawing_layers = {{
&cata_tiles::draw_terrain, &cata_tiles::draw_furniture, &cata_tiles::draw_graffiti, &cata_tiles::draw_trap, &cata_tiles::draw_part_con,
&cata_tiles::draw_field_or_item,
&cata_tiles::draw_vpart_no_roof, &cata_tiles::draw_vpart_roof,
&cata_tiles::draw_critter_at, &cata_tiles::draw_zone_mark,
&cata_tiles::draw_zombie_revival_indicators
}
};
// Legacy code to use when vertical vision range is 0
const std::array<decltype( &cata_tiles::draw_furniture ), 14> drawing_layers_legacy = {{
&cata_tiles::draw_terrain, &cata_tiles::draw_furniture, &cata_tiles::draw_graffiti, &cata_tiles::draw_trap, &cata_tiles::draw_part_con,
&cata_tiles::draw_field_or_item, &cata_tiles::draw_vpart_below,
&cata_tiles::draw_critter_at_below, &cata_tiles::draw_terrain_below,
&cata_tiles::draw_vpart_no_roof, &cata_tiles::draw_vpart_roof,
&cata_tiles::draw_critter_at, &cata_tiles::draw_zone_mark,
&cata_tiles::draw_zombie_revival_indicators
}
};
// Skip drawing shadow of critters above if there is no shadow sprite
bool do_draw_shadow = false;
if( find_tile_looks_like( "shadow", TILE_CATEGORY::NONE, "" ) ) {
do_draw_shadow = true;
}
if( max_draw_depth <= 0 ) {
// Legacy draw mode
for( int row = min_row; row < max_row; row ++ ) {
for( auto f : drawing_layers_legacy ) {
for( tile_render_info &p : here.draw_points_cache[center.z][row] ) {
if( const tile_render_info::vision_effect * const
var = std::get_if<tile_render_info::vision_effect>( &p.var ) ) {
if( f == &cata_tiles::draw_terrain ) {
apply_vision_effects( p.com.pos, var->vis, p.com.height_3d );
}
} else if( const tile_render_info::sprite * const
var = std::get_if<tile_render_info::sprite>( &p.var ) ) {
( this->*f )( p.com.pos, var->ll, p.com.height_3d, var->invisible, false );
}
}
}
}
} else {
// Multi z-level draw mode
// Start drawing from the lowest visible z-level (some off-screen tiles
// are considered visible here to simplify the logic.)
int cur_zlevel = draw_min_z;
while( cur_zlevel <= center.z ) {
const half_open_rectangle<point> &cur_any_tile_range = is_isometric()
? z_any_tile_range[center.z - cur_zlevel] : top_any_tile_range;
// For each row
for( int row = cur_any_tile_range.p_min.y; row < cur_any_tile_range.p_max.y; row ++ ) {
// Set base height for each tile
for( tile_render_info &p : here.draw_points_cache[cur_zlevel][row] ) {
p.com.height_3d = ( cur_zlevel - center.z ) * zlevel_height;
}
// For each layer
for( auto f : drawing_layers ) {
// For each tile
for( tile_render_info &p : here.draw_points_cache[cur_zlevel][row] ) {
if( const tile_render_info::vision_effect * const
var = std::get_if<tile_render_info::vision_effect>( &p.var ) ) {
if( f == &cata_tiles::draw_terrain ) {
apply_vision_effects( p.com.pos, var->vis, p.com.height_3d );
}
} else if( const tile_render_info::sprite * const
var = std::get_if<tile_render_info::sprite>( &p.var ) ) {
// Get visibility variables
lit_level ll = var->ll;
std::array<bool, 5> invisible = var->invisible;
if( f == &cata_tiles::draw_vpart_no_roof || f == &cata_tiles::draw_vpart_roof ) {
int temp_height_3d = p.com.height_3d;
// Reset height_3d to base when drawing vehicles
p.com.height_3d = ( cur_zlevel - center.z ) * zlevel_height;
// Draw
if( !( this->*f )( p.com.pos, ll, p.com.height_3d, invisible, false ) ) {
// If no vpart drawn, revert height_3d changes
p.com.height_3d = temp_height_3d;
}
} else if( f == &cata_tiles::draw_critter_at ) {
// Draw
if( !( this->*f )( p.com.pos, ll, p.com.height_3d, invisible, false ) && do_draw_shadow &&
here.dont_draw_lower_floor( p.com.pos ) ) {
// Draw shadow of flying critters on bottom-most tile if no other critter drawn
draw_critter_above( p.com.pos, ll, p.com.height_3d, invisible );
}
} else {
// Draw
( this->*f )( p.com.pos, ll, p.com.height_3d, invisible, false );
}
}
}
}
}
cur_zlevel += 1;
}
}
// display number of monsters to spawn in mapgen preview
for( int row = top_any_tile_range.p_min.y; row < top_any_tile_range.p_max.y; row ++ ) {
for( const tile_render_info &p : here.draw_points_cache[center.z][row] ) {
const tile_render_info::sprite *const
var = std::get_if<tile_render_info::sprite>( &p.var );
if( !var ) {
continue;
}
const auto mon_override = monster_override.find( p.com.pos );
if( mon_override != monster_override.end() ) {
const int count = std::get<1>( mon_override->second );
const bool more = std::get<2>( mon_override->second );
if( count > 1 || more ) {
std::string text = "x" + std::to_string( count );
if( more ) {
text += "+";
}
overlay_strings.emplace( player_to_screen( p.com.pos.xy() ) + half_tile,
formatted_text( text, catacurses::red,
direction::NORTH ) );
}
}
if( !var->invisible[0] ) {
here.memory_cache_ter_set_dirty( p.com.pos, false );
}
}
}
// tile overrides are already drawn in the previous code
void_radiation_override();
void_terrain_override();
void_furniture_override();
void_graffiti_override();
void_trap_override();
void_field_override();
void_item_override();
void_vpart_override();
void_draw_below_override();
void_monster_override();
//Memorize everything the character just saw even if it wasn't displayed.
for( int mem_y = min_visible.y; mem_y <= max_visible.y; mem_y++ ) {
for( int mem_x = min_visible.x; mem_x <= max_visible.x; mem_x++ ) {
const point colrow = player_to_tile( { mem_x, mem_y } );
if( is_isometric() && top_any_tile_range.contains( colrow ) ) {
continue;
}
const tripoint p( mem_x, mem_y, center.z );
lit_level lighting = ch.visibility_cache[p.x][p.y];
// `apply_vision_effects` does not memorize anything so we only need
// to call `would_apply_vision_effects` here.
if( would_apply_vision_effects( here.get_visibility( lighting, cache ) ) ) {
continue;
}
int height_3d = 0;
std::array<bool, 5> invisible;
invisible[0] = false;
for( int i = 0; i < 4; i++ ) {
const tripoint np = p + neighborhood[i];
invisible[1 + i] = apply_visible( np, ch, here );
}
//calling draw to memorize (and only memorize) everything.
//bypass cache check in case we learn something new about the terrain's connections
draw_terrain( p, lighting, height_3d, invisible, true );
if( here.memory_cache_dec_is_dirty( p ) ) {
you.memorize_clear_decoration( here.getglobal( p ), "" );
draw_furniture( p, lighting, height_3d, invisible, true );
draw_trap( p, lighting, height_3d, invisible, true );
draw_part_con( p, lighting, height_3d, invisible, true );
draw_vpart_no_roof( p, lighting, height_3d, invisible, true );
draw_vpart_roof( p, lighting, height_3d, invisible, true );
here.memory_cache_dec_set_dirty( p, false );
}
}
}
in_animation = do_draw_explosion || do_draw_custom_explosion ||
do_draw_bullet || do_draw_hit || do_draw_line ||
do_draw_cursor || do_draw_highlight || do_draw_weather ||
do_draw_sct || do_draw_zones || do_draw_async_anim;
draw_footsteps_frame( center );
if( in_animation ) {
if( do_draw_explosion ) {
draw_explosion_frame();
}
if( do_draw_custom_explosion ) {
draw_custom_explosion_frame();
}
if( do_draw_bullet ) {
draw_bullet_frame();
}
if( do_draw_hit ) {
draw_hit_frame();
void_hit();
}
if( do_draw_line ) {
draw_line();
void_line();
}
if( do_draw_weather ) {
draw_weather_frame();
void_weather();
}
if( do_draw_sct ) {
draw_sct_frame( overlay_strings );
void_sct();
}
if( do_draw_zones ) {
draw_zones_frame();
void_zones();
}
if( do_draw_cursor ) {
draw_cursor();
void_cursor();
}
if( do_draw_highlight ) {
draw_highlight();
void_highlight();
}
if( do_draw_async_anim ) {
draw_async_anim();
}
} else if( you.view_offset != tripoint_zero && !you.in_vehicle ) {
// check to see if player is located at ter
draw_from_id_string( "cursor", TILE_CATEGORY::NONE, empty_string,
tripoint( g->ter_view_p.xy(), center.z ), 0, 0, lit_level::LIT,
false );
}
if( you.controlling_vehicle ) {
std::optional<tripoint> indicator_offset = g->get_veh_dir_indicator_location( true );
if( indicator_offset ) {
draw_from_id_string( "cursor", TILE_CATEGORY::NONE, empty_string,
indicator_offset->xy() +
tripoint( you.posx(), you.posy(), center.z ),
0, 0, lit_level::LIT, false );
}
}
printErrorIf( SDL_RenderSetClipRect( renderer.get(), nullptr ) != 0,
"SDL_RenderSetClipRect failed" );
}
void cata_tiles::set_draw_cache_dirty()
{
get_map().draw_points_cache_dirty = true;
}
void cata_tiles::draw_minimap( const point &dest, const tripoint ¢er, int width, int height )
{
minimap->set_type( is_isometric() ? pixel_minimap_type::iso : pixel_minimap_type::ortho );
minimap->draw( SDL_Rect{ dest.x, dest.y, width, height }, center );
}
point cata_tiles::get_window_base_tile_counts( const point &size ) const
{
if( is_isometric() ) {
// |---sx---|
// w |
// ~
// 1\ }h
// /\/\/\/\2\ --
// \/\/\/\3\/ |
// /\/\/\/\4\ sy
// \/\/\/\5\/ |
// /\/\/\/\6\ --
//
// The rhombuses above represent the basic tiles excluding any extra
// pixel that represents things in the z direction. `w = tile_width / 2`
// is half basic tile width and `h = tile_width / 4` is half basic tile
// height. `tile_height` is unrelated to and can be large than the basic
// tile height `tile_width / 2`.
//
// There is no strict requirement about the exact position of pixels
// in a sprite, except that the basic tiles should be able to densely
// tile the screen area, and any extra pixels should only be used to
// represent the z direction because they will be occluded by sprites in
// the next row and occlude sprites in the previous row.
//
// Only the area from (0, 0) to (tile_width, tile_width / 2) is
// considered when checking which tiles are on-screen, and the exact
// position of pixels is disregarded. The numbers in the figure above
// denote the first to the last drawn cells in the vertical direction.
// Therefore, we can see that,
//
// cols = 1 + divide_round_up(sx, w)
// rows = 1 + divide_round_up(sy, h)
// ||
// \/
const int columns = divide_round_up( size.x * 2, tile_width ) + 1;
const int rows = divide_round_up( size.y * 4, tile_width ) + 1;
return point( columns, rows );
} else {
// Only the area from (0, 0) to (tile_width, tile_height) is considered
// when checking which tiles are on-screen.
const int columns = divide_round_up( size.x, tile_width );
const int rows = divide_round_up( size.y, tile_height );
return point( columns, rows );
}
}
half_open_rectangle<point> cata_tiles::get_window_any_tile_range(
const point &size, const int z ) const
{
// (following comments in get_window_base_tile_counts)
//
// Based on the maximum tile extent, these ensure that any tile that can be
// possibly on screen is included in the range.
if( is_isometric() ) {
// z-level below => negative z_height => smaller row_beg and row_end
const int z_height = zlevel_height * z;
const int col_beg = divide_round_down( ( tile_width - max_tile_extent.p_max.x ) * 2,
tile_width );
const int col_end = divide_round_up( ( size.x - max_tile_extent.p_min.x ) * 2,
tile_width ) + 1;
const int row_beg = divide_round_down( ( z_height + tile_height
- max_tile_extent.p_max.y ) * 4,
tile_width );
// The difference between the default sprite height `tile_height` and
// base tile height `tile_width / 2` should be added to the tile extent
// here. Because `player_to_screen` shifts the sprite up by this extra
// height, it means this extra height should be subtracted from the
// minimum extent.
// (sy + zh - miny + th - tw / 2) / (tw / 4) + 1 =>
const int row_end = divide_round_up( ( size.y + z_height
- max_tile_extent.p_min.y + tile_height ) * 4,
tile_width ) - 1;
return { { col_beg, row_beg }, { col_end, row_end } };
} else {
const int col_beg = divide_round_down( tile_width - max_tile_extent.p_max.x, tile_width );
const int col_end = divide_round_up( size.x - max_tile_extent.p_min.x, tile_width );
const int row_beg = divide_round_down( tile_height - max_tile_extent.p_max.y, tile_height );
const int row_end = divide_round_up( size.y - max_tile_extent.p_min.y, tile_height );
return { { col_beg, row_beg }, { col_end, row_end } };
}
}
half_open_rectangle<point> cata_tiles::get_window_full_base_tile_range( const point &size ) const
{
if( is_isometric() ) {
// (following comments in get_window_base_tile_counts)
//
// Only the area from (0, 0) to (tile_width, tile_width / 2) is
// considered when checking which tiles are fully on-screen, and the
// exact position of pixels is disregarded. In the figure above, as
// opposed to 1-6, only 2-5 are fully shown on-screen. Therefore, we can
// see that,
//
// cols = divide_round_down(sx, w) - 1
// rows = divide_round_down(sy, h) - 1
// ||
// \/
const int columns = divide_round_down( size.x * 2, tile_width ) - 1;
const int rows = divide_round_down( size.y * 4, tile_width ) - 1;
//NOLINTNEXTLINE(cata-use-named-point-constants): the name would be confusing here (screen 'NSWE' are not map NSWE)
return { { 1, 1 }, { columns + 1, rows + 1 } };
} else {
// Only the area from (0, 0) to (tile_width, tile_height) is considered
// when checking which tiles are fully on-screen.
const int columns = divide_round_down( size.x, tile_width );
const int rows = divide_round_down( size.y, tile_height );
return { point_zero, { columns, rows } };
}
}
std::optional<point> cata_tiles::tile_to_player( const point &colrow ) const
{
if( is_isometric() ) {
// (following comments in get_window_base_tile_counts)
//
// Based on the screen tile pattern, the player position can be calculated
// from the column and row numbers as follows
if( modulo( colrow.y - screentile_height / 2, 2 )
!= modulo( colrow.x - screentile_width / 2, 2 ) ) {
return std::nullopt;
}
return o + point {
divide_round_down( colrow.x - colrow.y - screentile_width / 2
+ screentile_height / 2, 2 ),
divide_round_down( colrow.y + colrow.x - screentile_height / 2
- screentile_width / 2, 2 ),
};
} else {
return colrow + o;
}
}
point cata_tiles::player_to_tile( const point &pos ) const
{
// (calculate the screen position according to cata_tiles::tile_to_player)
if( is_isometric() ) {
// (division rounded down):
//
// pos.x = ( col - row - sx / 2 + sy / 2 ) / 2 + o.x;
// pos.y = ( row + col - sy / 2 - sx / 2 ) / 2 + o.y;
// ( col - sx / 2 ) % 2 = ( row - sy / 2 ) % 2
// ||
// \/
const int col = pos.y + pos.x + screentile_width / 2 - o.y - o.x;
const int row = pos.y - pos.x + screentile_height / 2 - o.y + o.x;
return { col, row };
} else {
return pos - o;
}
}
point cata_tiles::player_to_screen( const point &pos ) const
{
const point colrow = player_to_tile( pos );
if( is_isometric() ) {
// To ensure the first fully drawn basic tile (col or row = 1, according
// to the definition in get_window_full_base_tile_range) starts at 0,
return op + point {
// left = ( col - 1 ) * ( tw / 2.0 ) =>
divide_round_down( ( colrow.x - 1 ) * tile_width, 2 ),
// top = ( row - 1 ) * ( tw / 4.0 ) - th + tw / 2.0 =>
// (shifted so that sprites with default height end at the basic height
// of `tile_width / 4`)
divide_round_down( ( colrow.y + 1 ) * tile_width, 4 ) - tile_height,
};
} else {
return op + point { colrow.x * tile_width, colrow.y * tile_height };
}
}
bool cata_tiles::draw_from_id_string( const std::string &id, const tripoint &pos, int subtile,
int rota,
lit_level ll, bool apply_night_vision_goggles )
{
int nullint = 0;
return cata_tiles::draw_from_id_string( id, TILE_CATEGORY::NONE, empty_string, pos, subtile,
rota, ll, apply_night_vision_goggles, nullint, 0 );
}
bool cata_tiles::draw_from_id_string( const std::string &id, TILE_CATEGORY category,
const std::string &subcategory, const tripoint &pos,
int subtile, int rota, lit_level ll,
bool apply_night_vision_goggles )
{
int nullint = 0;
return cata_tiles::draw_from_id_string( id, category, subcategory, pos, subtile, rota,
ll, apply_night_vision_goggles, nullint, 0 );
}
bool cata_tiles::draw_from_id_string( const std::string &id, const tripoint &pos, int subtile,
int rota,
lit_level ll, bool apply_night_vision_goggles,
int &height_3d )
{
return cata_tiles::draw_from_id_string( id, TILE_CATEGORY::NONE, empty_string, pos, subtile,
rota, ll, apply_night_vision_goggles, height_3d, 0 );
}
bool cata_tiles::draw_from_id_string( const std::string &id, TILE_CATEGORY category,
const std::string &subcategory, const tripoint &pos,
int subtile, int rota, lit_level ll,
bool apply_night_vision_goggles, int &height_3d, int intensity )
{
return cata_tiles::draw_from_id_string_internal( id, category, subcategory, pos, subtile, rota,
ll, -1, apply_night_vision_goggles, height_3d, intensity, "", point() );
}
bool cata_tiles::draw_from_id_string( const std::string &id, TILE_CATEGORY category,
const std::string &subcategory, const tripoint &pos,
int subtile, int rota, lit_level ll,
bool apply_night_vision_goggles, int &height_3d )
{
return cata_tiles::draw_from_id_string_internal( id, category, subcategory, pos, subtile, rota,
ll, -1, apply_night_vision_goggles, height_3d, 0, "", point() );
}
bool cata_tiles::draw_from_id_string( const std::string &id, TILE_CATEGORY category,
const std::string &subcategory, const tripoint &pos,
int subtile, int rota, lit_level ll,
bool apply_night_vision_goggles, int &height_3d,
int intensity_level, const std::string &variant )
{
return cata_tiles::draw_from_id_string_internal( id, category, subcategory, pos, subtile, rota,
ll, -1, apply_night_vision_goggles, height_3d, intensity_level,
variant, point() );
}
bool cata_tiles::draw_from_id_string( const std::string &id, TILE_CATEGORY category,
const std::string &subcategory, const tripoint &pos,
int subtile, int rota, lit_level ll,
bool apply_night_vision_goggles, int &height_3d,
int intensity_level, const std::string &variant,
const point &offset )
{
return cata_tiles::draw_from_id_string_internal( id, category, subcategory, pos, subtile, rota,
ll, -1, apply_night_vision_goggles, height_3d, intensity_level,
variant, offset );
}
bool cata_tiles::draw_from_id_string_internal( const std::string &id, const tripoint &pos,
int subtile,
int rota,
lit_level ll, int retract, bool apply_night_vision_goggles, int &height_3d )
{
return cata_tiles::draw_from_id_string_internal( id, TILE_CATEGORY::NONE, empty_string, pos,
subtile,
rota, ll, retract, apply_night_vision_goggles, height_3d, 0, "", point() );
}
std::optional<tile_lookup_res>
cata_tiles::find_tile_with_season( const std::string &id ) const
{
const season_type season = season_of_year( calendar::turn );
return tileset_ptr->find_tile_type_by_season( id, season );
}
template<typename T>
std::optional<tile_lookup_res>
cata_tiles::find_tile_looks_like_by_string_id( const std::string_view id, TILE_CATEGORY category,
const int looks_like_jumps_limit ) const
{
const string_id<T> s_id( id );
if( !s_id.is_valid() ) {
return std::nullopt;
}
const T &obj = s_id.obj();
return find_tile_looks_like( obj.looks_like, category, "", looks_like_jumps_limit - 1 );
}
std::optional<tile_lookup_res>
cata_tiles::find_tile_looks_like( const std::string &id, TILE_CATEGORY category,
const std::string &variant,
const int looks_like_jumps_limit ) const
{
if( id.empty() || looks_like_jumps_limit <= 0 ) {
return std::nullopt;
}
/*
* Note on memory management:
* This method must returns pointers to the objects (std::string *id and tile_type * tile)
* that are valid when this method returns. Ideally they should have the lifetime
* that is equal or exceeds lifetime of `this` or `this::tileset_ptr`.
* For example, `id` argument may have shorter lifetime and thus should not be returned!
* The result of `find_tile_with_season` is OK to be returned, because it's guaranteed to
* return pointers to the keys and values that are stored inside the `tileset_ptr`.
*/
// Try the variant first
if( !variant.empty() ) {
if( category != TILE_CATEGORY::VEHICLE_PART ) {
if( auto ret = find_tile_with_season( id + "_var_" + variant ) ) {
return ret; // with variant
}
} else {
std::string_view variant_chunk = variant;
while( !variant_chunk.empty() ) {
if( auto ret = find_tile_with_season( id + "_" + std::string( variant_chunk ) ) ) {
return ret; // with variant, but vehicle parts have weird variant suffixes
}
const size_t next_start = variant_chunk.rfind( '_' );
if( next_start != std::string::npos ) {
variant_chunk = variant_chunk.substr( 0, next_start );
} else {
variant_chunk = variant_chunk.substr( 0, 0 );
}
}
}
}
if( auto ret = find_tile_with_season( id ) ) {
return ret; // no variant
}
// Then do looks_like
switch( category ) {
case TILE_CATEGORY::FURNITURE:
return find_tile_looks_like_by_string_id<furn_t>( id, category,
looks_like_jumps_limit );
case TILE_CATEGORY::TERRAIN:
return find_tile_looks_like_by_string_id<ter_t>( id, category, looks_like_jumps_limit );
case TILE_CATEGORY::FIELD:
return find_tile_looks_like_by_string_id<field_type>( id, category,
looks_like_jumps_limit );
case TILE_CATEGORY::MONSTER:
return find_tile_looks_like_by_string_id<mtype>( id, category, looks_like_jumps_limit );
case TILE_CATEGORY::OVERMAP_TERRAIN: {
std::optional<tile_lookup_res> ret;
const oter_type_str_id type_tmp( id );
if( !type_tmp.is_valid() ) {
return ret;
}
int jump_limit = looks_like_jumps_limit;
for( const std::string &looks_like : type_tmp.obj().looks_like ) {
ret = find_tile_looks_like( looks_like, category, "", jump_limit - 1 );
if( ret.has_value() ) {
return ret;
}
jump_limit--;
if( jump_limit <= 0 ) {
return ret;
}
}
return ret;
}
case TILE_CATEGORY::VEHICLE_PART: {
const int lljl = looks_like_jumps_limit - 1;
// vehicle parts start with vp_ for their tiles, but not their IDs
const vpart_id vpid( id.substr( 3 ) );
if( !vpid.is_valid() ) {
return std::nullopt;
}
const std::string &looks_like = vpid->looks_like;
if( looks_like.empty() ) {
return std::nullopt;
}
if( auto ret = find_tile_looks_like( "vp_" + looks_like, category, variant, lljl ) ) {
return ret;
}
if( auto ret = find_tile_looks_like( looks_like, category, variant, lljl ) ) {
return ret;
}
return std::nullopt;
}
case TILE_CATEGORY::ITEM: {
if( !item::type_is_defined( itype_id( id ) ) ) {
if( string_starts_with( id, "corpse_" ) ) {
return find_tile_looks_like(
"corpse", category, "", looks_like_jumps_limit - 1
);
}
return std::nullopt;
}
const itype *new_it = item::find_type( itype_id( id ) );
return find_tile_looks_like( new_it->looks_like.str(), category, "",
looks_like_jumps_limit - 1 );
}
default:
return std::nullopt;
}
}
bool cata_tiles::find_overlay_looks_like( const bool male, const std::string &overlay,
const std::string &variant, std::string &draw_id )
{
bool exists = false;
std::string looks_like;
std::string over_type;
if( string_starts_with( overlay, "worn_" ) ) {
looks_like = overlay.substr( 5 );
over_type = "worn_";
} else if( string_starts_with( overlay, "wielded_" ) ) {
looks_like = overlay.substr( 8 );
over_type = "wielded_";
} else {
looks_like = overlay;
}
// Try to draw variants, then fall back to drawing the base
// We can potentially do this twice for a variant of an active mutation
for( int i = 0; i < 2; ++i ) {
draw_id.clear();
str_append( draw_id,
( male ? "overlay_male_" : "overlay_female_" ), over_type, looks_like, "_var_",
variant );
if( tileset_ptr->find_tile_type( draw_id ) ) {
return true;
}
draw_id.clear();
str_append( draw_id, "overlay_", over_type, looks_like, "_var_", variant );
if( tileset_ptr->find_tile_type( draw_id ) ) {
return true;
}
if( string_starts_with( looks_like, "mutation_active_" ) ) {
looks_like = "mutation_" + looks_like.substr( 16 );
continue;
}
break;
}
for( int cnt = 0; cnt < 10 && !looks_like.empty(); cnt++ ) {
draw_id.clear();
str_append( draw_id,
( male ? "overlay_male_" : "overlay_female_" ), over_type, looks_like );
if( tileset_ptr->find_tile_type( draw_id ) ) {
exists = true;
break;
}
draw_id.clear();
str_append( draw_id, "overlay_", over_type, looks_like );
if( tileset_ptr->find_tile_type( draw_id ) ) {
exists = true;
break;
}
if( string_starts_with( looks_like, "mutation_active_" ) ) {
looks_like = "mutation_" + looks_like.substr( 16 );
continue;
}
if( !item::type_is_defined( itype_id( looks_like ) ) ) {
break;
}
const itype *new_it = item::find_type( itype_id( looks_like ) );
looks_like = new_it->looks_like.str();
}
return exists;
}
bool cata_tiles::draw_from_id_string_internal( const std::string &id, TILE_CATEGORY category,
const std::string &subcategory, const tripoint &pos,
int subtile, int rota, lit_level ll, int retract,
bool apply_night_vision_goggles, int &height_3d,
int intensity_level, const std::string &variant,
const point &offset )
{
bool nv_color_active = apply_night_vision_goggles && get_option<bool>( "NV_GREEN_TOGGLE" );
// If the ID string does not produce a drawable tile
// it will revert to the "unknown" tile.
// The "unknown" tile is one that is highly visible so you kinda can't miss it :D
const tile_type *tt = nullptr;
std::optional<tile_lookup_res> res;
// translate from player-relative to screen relative tile position
const point screen_pos = player_to_screen( pos.xy() );
if( retract < 0 && ( prevent_occlusion_transp || prevent_occlusion_retract ) ) {
if( prevent_occlusion == 0 ) {
retract = 0;
} else if( prevent_occlusion == 1 ) {
retract = 100;
} else {
const float distance = o.distance( pos.xy() );
const float d_min = prevent_occlusion_min_dist > 0.0 ? prevent_occlusion_min_dist :
tileset_ptr->get_prevent_occlusion_min_dist();
const float d_max = prevent_occlusion_max_dist > 0.0 ? prevent_occlusion_max_dist :
tileset_ptr->get_prevent_occlusion_max_dist();
const float d_range = d_max - d_min;
const float d_slope = d_range <= 0.0f ? 100.0 : 1.0 / d_range;
retract = static_cast<int>( 100.0 * ( 1.0 - clamp( ( distance - d_min ) * d_slope, 0.0f, 1.0f ) ) );
}
if( prevent_occlusion_transp && retract > 0 ) {
res = find_tile_looks_like( id + "_transparent", category, variant );
if( res ) {
tt = &res -> tile();
}
}
}
// check if there is an available intensity tile and if there is use that instead of the basic tile
// this is only relevant for fields
if( intensity_level > 0 ) {
res = find_tile_looks_like( id + "_int" + std::to_string( intensity_level ), category, variant );
if( res ) {
tt = &res -> tile();
}
}
// if a tile with intensity hasn't already been found then fall back to a base tile
if( !res ) {
res = find_tile_looks_like( id, category, variant );
if( res ) {
tt = &res -> tile();
}
}
map &here = get_map();
const std::string &found_id = res ? res->id() : id;
if( !tt ) {
// Use fog overlay as fallback for transparent terrain
if( category == TILE_CATEGORY::TERRAIN && !here.dont_draw_lower_floor( pos ) ) {
draw_zlevel_overlay( pos, ll, height_3d );
// t_open_air is plentiful at high z-levels
// Skipping the rest of the fallback code will significantly improve performance
if( id == "t_open_air" ) {
return true;
}
}
uint32_t sym = UNKNOWN_UNICODE;
nc_color col = c_white;
if( category == TILE_CATEGORY::FURNITURE ) {
const furn_str_id fid( found_id );
if( fid.is_valid() ) {
const furn_t &f = fid.obj();
sym = f.symbol();
col = f.color();
}
} else if( category == TILE_CATEGORY::TERRAIN ) {
const ter_str_id tid( found_id );
if( tid.is_valid() ) {
const ter_t &t = tid.obj();
sym = t.symbol();
col = t.color();
}
} else if( category == TILE_CATEGORY::MONSTER ) {
const mtype_id mid( found_id );
if( mid.is_valid() ) {
const mtype &mt = mid.obj();
sym = UTF8_getch( mt.sym );
col = mt.color;
}
} else if( category == TILE_CATEGORY::VEHICLE_PART ) {
const vpart_id vpid( string_starts_with( found_id, "vp_" ) ? found_id.substr( 3 ) : found_id );
if( vpid.is_valid() ) {
const vpart_info &vpi = *vpid;
if( vpi.variants.count( variant ) ) {
const vpart_variant &vv = vpi.variants.at( variant );
if( subtile == open_ ) {
sym = '\'';
} else {
sym = vv.get_symbol_curses( 90_degrees * rota, subtile == broken );
}
col = vpi.color;
subtile = -1;
rota = 0;
} else if( ll != lit_level::MEMORIZED ) {
debugmsg( "invalid variant '%s' on vpart_id '%s'", variant, vpid.str() );
}
} else if( ll != lit_level::MEMORIZED ) {
debugmsg( "invalid vpart_id '%s'", vpid.str() );
}
} else if( category == TILE_CATEGORY::FIELD ) {
const field_type_id fid = field_type_id( found_id );
sym = fid->get_intensity_level().symbol;
col = fid->get_intensity_level().color;
} else if( category == TILE_CATEGORY::TRAP ) {
const trap_str_id tmp( found_id );
if( tmp.is_valid() ) {
const trap &t = tmp.obj();
sym = t.sym;
col = t.color;
}
} else if( category == TILE_CATEGORY::ITEM ) {
item tmp;
if( string_starts_with( found_id, "corpse_" ) ) {
tmp = item( itype_corpse, calendar::turn_zero );
} else {
tmp = item( found_id, calendar::turn_zero );
}
if( !variant.empty() ) {
tmp.set_itype_variant( variant );
} else {
tmp.clear_itype_variant();
}
sym = static_cast<uint8_t>( tmp.symbol().empty() ? ' ' : tmp.symbol().front() );
col = tmp.color();
} else if( category == TILE_CATEGORY::OVERMAP_TERRAIN ) {
const oter_type_str_id tmp( id );
if( tmp.is_valid() ) {
if( !tmp->is_linear() ) {
// if rota is for a omt with connections, it can be outside the bounds of
// om_direction::type. We can't do anything about that now, so just stay inbounds
rota %= om_direction::size;
sym = tmp->get_rotated( static_cast<om_direction::type>( rota ) )->get_uint32_symbol();
} else {
sym = tmp->symbol;
}
col = tmp->color;
}
} else if( category == TILE_CATEGORY::OVERMAP_NOTE ) {
sym = static_cast<uint8_t>( id[5] );
col = color_from_string( id.substr( 7, id.length() - 1 ) );
}
// Special cases for walls
switch( sym ) {
case LINE_XOXO:
case LINE_XOXO_UNICODE:
sym = LINE_XOXO_C;
break;
case LINE_OXOX:
case LINE_OXOX_UNICODE:
sym = LINE_OXOX_C;
break;
case LINE_XXOO:
case LINE_XXOO_UNICODE:
sym = LINE_XXOO_C;
break;
case LINE_OXXO:
case LINE_OXXO_UNICODE:
sym = LINE_OXXO_C;
break;
case LINE_OOXX:
case LINE_OOXX_UNICODE:
sym = LINE_OOXX_C;
break;
case LINE_XOOX:
case LINE_XOOX_UNICODE:
sym = LINE_XOOX_C;
break;
case LINE_XXXO:
case LINE_XXXO_UNICODE:
sym = LINE_XXXO_C;
break;
case LINE_XXOX:
case LINE_XXOX_UNICODE:
sym = LINE_XXOX_C;
break;
case LINE_XOXX:
case LINE_XOXX_UNICODE:
sym = LINE_XOXX_C;
break;
case LINE_OXXX:
case LINE_OXXX_UNICODE:
sym = LINE_OXXX_C;
break;
case LINE_XXXX:
case LINE_XXXX_UNICODE:
sym = LINE_XXXX_C;
break;
default:
// sym goes unchanged
break;
}
if( sym != 0 && sym < 256 ) {
// see cursesport.cpp, function wattron
const int pairNumber = col.to_color_pair_index();
const cata_cursesport::pairs &colorpair = cata_cursesport::colorpairs[pairNumber];
// What about isBlink?
const bool isBold = col.is_bold();
const int FG = colorpair.FG + ( isBold ? 8 : 0 );
std::string generic_id = get_ascii_tile_id( sym, FG, -1 );
// do not rotate fallback tiles!
if( sym != LINE_XOXO_C && sym != LINE_OXOX_C ) {
rota = 0;
}
if( tileset_ptr->find_tile_type( generic_id ) ) {
return draw_from_id_string_internal( generic_id, pos, subtile, rota,
ll, retract, nv_color_active, height_3d );
}
// Try again without color this time (using default color).
generic_id = get_ascii_tile_id( sym, -1, -1 );
if( tileset_ptr->find_tile_type( generic_id ) ) {
return draw_from_id_string_internal( generic_id, pos, subtile, rota,
ll, retract, nv_color_active, height_3d );
}
}
}
// if id is not found, try to find a tile for the category+subcategory combination
const std::string &category_id = TILE_CATEGORY_IDS[static_cast<size_t>( category )];
if( !tt ) {
if( !category_id.empty() && !subcategory.empty() ) {
tt = tileset_ptr->find_tile_type( "unknown_" + category_id + "_" + subcategory );
}
}
// if at this point we have no tile, try just the category
if( !tt ) {
if( !category_id.empty() ) {
tt = tileset_ptr->find_tile_type( "unknown_" + category_id );
}
}
// if we still have no tile, we're out of luck, fall back to unknown
if( !tt ) {
tt = tileset_ptr->find_tile_type( "unknown" );
}
// this really shouldn't happen, but the tileset creator might have forgotten to define
// an unknown tile
if( !tt ) {
return false;
}
const tile_type &display_tile = *tt;
// check to see if the display_tile is multitile, and if so if it has the key related to
// subtile
if( subtile != -1 && display_tile.multitile ) {
const auto &display_subtiles = display_tile.available_subtiles;
const auto end = std::end( display_subtiles );
if( std::find( begin( display_subtiles ), end, multitile_keys[subtile] ) != end ) {
// append subtile name to tile and re-find display_tile
return draw_from_id_string_internal(
found_id + "_" + multitile_keys[subtile], category, subcategory, pos, -1, rota, ll,
retract, nv_color_active, height_3d, 0, "", point() );
}
}
auto simple_point_hash = []( const auto & p ) {
return p.x + p.y * 65536;
};
// seed the PRNG to get a reproducible random int
// TODO: faster solution here
unsigned int seed = 0;
creature_tracker &creatures = get_creature_tracker();
// TODO: determine ways other than category to differentiate more types of sprites
switch( category ) {
case TILE_CATEGORY::TERRAIN:
case TILE_CATEGORY::FIELD:
case TILE_CATEGORY::LIGHTING:
// stationary map tiles, seed based on map coordinates
seed = simple_point_hash( here.getabs( pos ) );
break;
case TILE_CATEGORY::VEHICLE_PART:
// vehicle parts, seed based on coordinates within the vehicle
// TODO: also use some vehicle id, for less predictability
{
// new scope for variable declarations
const auto vp_override = vpart_override.find( pos );
const bool vp_overridden = vp_override != vpart_override.end();
if( vp_overridden ) {
const vpart_id &vp_id = std::get<0>( vp_override->second );
if( vp_id ) {
const point &mount = std::get<4>( vp_override->second );
seed = simple_point_hash( mount );
}
} else {
const optional_vpart_position vp = here.veh_at( pos );
if( vp ) {
seed = simple_point_hash( vp->mount() );
}
}
}
break;
case TILE_CATEGORY::FURNITURE: {
// If the furniture is not movable, we'll allow seeding by the position
// since we won't get the behavior that occurs where the tile constantly
// changes when the player grabs the furniture and drags it, causing the
// seed to change.
const furn_str_id fid( found_id );
if( fid.is_valid() ) {
const furn_t &f = fid.obj();
if( !f.is_movable() ) {
seed = simple_point_hash( here.getabs( pos ) );
}
}
}
break;
case TILE_CATEGORY::OVERMAP_TERRAIN:
case TILE_CATEGORY::MAP_EXTRA:
seed = simple_point_hash( pos );
break;
case TILE_CATEGORY::NONE:
// graffiti
if( found_id == "graffiti" ) {
seed = std::hash<std::string> {}( here.graffiti_at( pos ) );
} else if( string_starts_with( found_id, "graffiti" ) ) {
seed = simple_point_hash( here.getabs( pos ) );
}
break;
case TILE_CATEGORY::ITEM:
case TILE_CATEGORY::TRAP:
case TILE_CATEGORY::BULLET:
case TILE_CATEGORY::HIT_ENTITY:
case TILE_CATEGORY::WEATHER:
// TODO: come up with ways to make random sprites consistent for these types
break;
case TILE_CATEGORY::MONSTER:
// FIXME: add persistent id to Creature type, instead of using monster pointer address
if( monster_override.find( pos ) == monster_override.end() ) {
seed = reinterpret_cast<uintptr_t>( creatures.creature_at<monster>( pos ) );
}
break;
default:
// player
if( string_starts_with( found_id, "player_" ) ) {
seed = std::hash<std::string> {}( get_player_character().name );
break;
}
// NPC
if( string_starts_with( found_id, "npc_" ) ) {
if( npc *const guy = creatures.creature_at<npc>( pos ) ) {
seed = guy->getID().get_value();
break;
}
}
}
// make sure we aren't going to rotate the tile if it shouldn't be rotated
if( !display_tile.rotates && !( category == TILE_CATEGORY::NONE )
&& !( category == TILE_CATEGORY::MONSTER ) ) {
rota = 0;
}
unsigned int loc_rand = 0;
// only bother mixing up a hash/random value if the tile has some sprites to randomly pick
// between
if( display_tile.fg.size() > 1 || display_tile.bg.size() > 1 ) {
static const auto rot32 = []( const unsigned int x, const int k ) {
return ( x << k ) | ( x >> ( 32 - k ) );
};
// use a fair mix function to turn the "random" seed into a random int
// taken from public domain code at http://burtleburtle.net/bob/c/lookup3.c 2015/12/11
unsigned int a = seed;
unsigned int b = -seed;
unsigned int c = seed * seed;
c ^= b;
c -= rot32( b, 14 );
a ^= c;
a -= rot32( c, 11 );
b ^= a;
b -= rot32( a, 25 );
c ^= b;
c -= rot32( b, 16 );
a ^= c;
a -= rot32( c, 4 );
b ^= a;
b -= rot32( a, 14 );
c ^= b;
c -= rot32( b, 24 );
loc_rand = c;
// idle tile animations:
if( display_tile.animated ) {
// idle animations run during the user's turn, and the animation speed
// needs to be defined by the tileset to look good, so we use system clock:
std::chrono::steady_clock::time_point now = std::chrono::steady_clock::now();
auto now_ms = std::chrono::time_point_cast<std::chrono::milliseconds>( now );
std::chrono::milliseconds value = now_ms.time_since_epoch();
// aiming roughly at the standard 60 frames per second:
int animation_frame = value.count() / 17;
// offset by log_rand so that everything does not blink at the same time:
animation_frame += loc_rand;
int frames_in_loop = display_tile.fg.get_weight();
if( frames_in_loop == 1 ) {
frames_in_loop = display_tile.bg.get_weight();
}
// loc_rand is actually the weighed index of the selected tile, and
// for animations the "weight" is the number of frames to show the tile for:
loc_rand = animation_frame % frames_in_loop;
}
}
if( ! prevent_occlusion_retract ) {
retract = 0;
}
//draw it!
draw_tile_at( display_tile, screen_pos, loc_rand, rota, ll,
nv_color_active, retract, height_3d, offset );
return true;
}
bool cata_tiles::draw_sprite_at(
const tile_type &tile, const weighted_int_list<std::vector<int>> &svlist,
const point &p, unsigned int loc_rand, bool rota_fg, int rota, lit_level ll,
bool apply_night_vision_goggles, int retract, int &height_3d, const point &offset )
{
const std::vector<int> *picked = svlist.pick( loc_rand );
if( !picked ) {
return true;
}
const std::vector<int> &spritelist = *picked;
if( spritelist.empty() ) {
return true;
}
int ret = 0;
// blit foreground based on rotation
bool rotate_sprite = false;
int sprite_num = 0;
if( !rota_fg && spritelist.size() == 1 ) {
// don't rotate, a background tile without manual rotations
rotate_sprite = false;
sprite_num = 0;
} else if( spritelist.size() == 1 ) {
// just one tile, apply SDL sprite rotation if not in isometric mode
rotate_sprite = true;
sprite_num = 0;
} else {
// multiple rotated tiles defined, don't apply sprite rotation after picking one
rotate_sprite = false;
// two tiles, tile 0 is N/S, tile 1 is E/W
// four tiles, 0=N, 1=E, 2=S, 3=W
// extending this to more than 4 rotated tiles will require changing rota to degrees
sprite_num = rota % spritelist.size();
}
const int sprite_index = spritelist[sprite_num];
const texture *sprite_tex = tileset_ptr->get_tile( sprite_index );
//use night vision colors when in use
//then use low light tile if available
if( ll == lit_level::MEMORIZED ) {
if( const texture *ptr = tileset_ptr->get_memory_tile( sprite_index ) ) {
sprite_tex = ptr;
}
} else if( apply_night_vision_goggles ) {
if( ll != lit_level::LOW ) {
if( const texture *ptr = tileset_ptr->get_overexposed_tile( sprite_index ) ) {
sprite_tex = ptr;
}
} else {
if( const texture *ptr = tileset_ptr->get_night_tile( sprite_index ) ) {
sprite_tex = ptr;
}
}
} else if( ll == lit_level::LOW ) {
if( const texture *ptr = tileset_ptr->get_shadow_tile( sprite_index ) ) {
sprite_tex = ptr;
}
}
int width = 0;
int height = 0;
std::tie( width, height ) = sprite_tex->dimension();
const point &tile_offset = retract <= 0
? tile.offset
: ( retract >= 100
? tile.offset_retracted
: tile.offset
+ ( ( tile.offset_retracted - tile.offset ) * retract ) / 100
);
SDL_Rect destination;
// Using divide_round_down because the offset might be negative.
destination.x = p.x + divide_round_down( ( tile_offset.x + offset.x ) * tile_width,
tileset_ptr->get_tile_width() );
destination.y = p.y + divide_round_down( ( tile_offset.y + offset.y - height_3d ) * tile_width,
tileset_ptr->get_tile_width() );
destination.w = width * tile_width * tile.pixelscale / tileset_ptr->get_tile_width();
destination.h = height * tile_height * tile.pixelscale / tileset_ptr->get_tile_height();
if( rotate_sprite ) {
if( rota == -1 ) {
// flip horizontally
ret = sprite_tex->render_copy_ex(
renderer, &destination, 0, nullptr,
static_cast<SDL_RendererFlip>( SDL_FLIP_HORIZONTAL ) );
} else {
switch( rota % 4 ) {
default:
case 0:
// unrotated (and 180, with just two sprites)
ret = sprite_tex->render_copy_ex( renderer, &destination, 0, nullptr,
SDL_FLIP_NONE );
break;
case 1:
// 90 degrees (and 270, with just two sprites)
#if defined(_WIN32) && defined(CROSS_LINUX)
// For an unknown reason, additional offset is required in direct3d mode
// for cross-compilation from Linux to Windows
if( direct3d_mode ) {
destination.y -= 1;
}
#endif
if( !is_isometric() ) {
// never rotate isometric tiles
ret = sprite_tex->render_copy_ex( renderer, &destination, -90, nullptr,
SDL_FLIP_NONE );
} else {
ret = sprite_tex->render_copy_ex( renderer, &destination, 0, nullptr,
SDL_FLIP_NONE );
}
break;
case 2:
// 180 degrees, implemented with flips instead of rotation
if( !is_isometric() ) {
// never flip isometric tiles vertically
ret = sprite_tex->render_copy_ex(
renderer, &destination, 0, nullptr,
static_cast<SDL_RendererFlip>( SDL_FLIP_HORIZONTAL | SDL_FLIP_VERTICAL ) );
} else {
ret = sprite_tex->render_copy_ex( renderer, &destination, 0, nullptr,
SDL_FLIP_NONE );
}
break;
case 3:
// 270 degrees
#if defined(_WIN32) && defined(CROSS_LINUX)
// For an unknown reason, additional offset is required in direct3d mode
// for cross-compilation from Linux to Windows
if( direct3d_mode ) {
destination.x -= 1;
}
#endif
if( !is_isometric() ) {
// never rotate isometric tiles
ret = sprite_tex->render_copy_ex( renderer, &destination, 90, nullptr,
SDL_FLIP_NONE );
} else {
ret = sprite_tex->render_copy_ex( renderer, &destination, 0, nullptr,
SDL_FLIP_NONE );
}
break;
}
}
} else {
// don't rotate, same as case 0 above
ret = sprite_tex->render_copy_ex( renderer, &destination, 0, nullptr, SDL_FLIP_NONE );
}
printErrorIf( ret != 0, "SDL_RenderCopyEx() failed" );
// this reference passes all the way back up the call chain back to
// cata_tiles::draw() here.draw_points_cache[z][row][col].com.height_3d
// where we are accumulating the height of every sprite stacked up in a tile
height_3d += tile.height_3d;
return true;
}
bool cata_tiles::draw_tile_at(
const tile_type &tile, const point &p, unsigned int loc_rand, int rota,
lit_level ll, bool apply_night_vision_goggles, int retract, int &height_3d,
const point &offset )
{
int fake_int = height_3d;
draw_sprite_at( tile, tile.bg, p, loc_rand, /*fg:*/ false, rota, ll,
apply_night_vision_goggles, retract, fake_int, offset );
draw_sprite_at( tile, tile.fg, p, loc_rand, /*fg:*/ true, rota, ll,
apply_night_vision_goggles, retract, height_3d, offset );
return true;
}
bool cata_tiles::would_apply_vision_effects( const visibility_type visibility ) const
{
return visibility != visibility_type::CLEAR;
}
bool cata_tiles::apply_vision_effects( const tripoint &pos,
const visibility_type visibility,
int &height_3d )
{
if( !would_apply_vision_effects( visibility ) ) {
return false;
}
std::string light_name;
switch( visibility ) {
case visibility_type::HIDDEN:
light_name = "lighting_hidden";
break;
case visibility_type::LIT:
light_name = "lighting_lowlight_light";
break;
case visibility_type::BOOMER:
light_name = "lighting_boomered_light";
break;
case visibility_type::BOOMER_DARK:
light_name = "lighting_boomered_dark";
break;
case visibility_type::DARK:
light_name = "lighting_lowlight_dark";
break;
case visibility_type::CLEAR:
// should never happen
break;
}
// lighting is never rotated, though, could possibly add in random rotation?
draw_from_id_string( light_name, TILE_CATEGORY::LIGHTING, empty_string, pos, 0, 0,
lit_level::LIT, false, height_3d );
return true;
}
bool cata_tiles::has_memory_at( const tripoint_abs_ms &p ) const
{
const memorized_tile &mt = get_avatar().get_memorized_tile( p );
return !mt.get_ter_id().empty() || !mt.get_dec_id().empty();
}
const memorized_tile &cata_tiles::get_terrain_memory_at( const tripoint_abs_ms &p ) const
{
const memorized_tile &mt = get_avatar().get_memorized_tile( p );
if( !mt.get_ter_id().empty() ) {
return mt;
}
return mm_submap::default_tile;
}
const memorized_tile &cata_tiles::get_furniture_memory_at( const tripoint_abs_ms &p ) const
{
const memorized_tile &mt = get_avatar().get_memorized_tile( p );
if( string_starts_with( mt.get_dec_id(), "f_" ) ) {
return mt;
}
return mm_submap::default_tile;
}
const memorized_tile &cata_tiles::get_trap_memory_at( const tripoint_abs_ms &p ) const
{
const memorized_tile &mt = get_avatar().get_memorized_tile( p );
if( string_starts_with( mt.get_dec_id(), "tr_" ) ) {
return mt;
}
return mm_submap::default_tile;
}
const memorized_tile &cata_tiles::get_vpart_memory_at( const tripoint_abs_ms &p ) const
{
const memorized_tile &mt = get_avatar().get_memorized_tile( p );
if( string_starts_with( mt.get_dec_id(), "vp_" ) ) {
return mt;
}
return mm_submap::default_tile;
}
void cata_tiles::draw_square_below( const point &p, const nc_color &col, const int sizefactor )
{
const SDL_Color sdlcol = curses_color_to_SDL( col );
SDL_Rect sdlrect;
const point screen = player_to_screen( p );
if( is_isometric() ) {
// See comments in get_window_base_tile_counts for an explanation of tile width and height
// tw / sizefactor * 3.0 / 4.0
sdlrect.w = ( tile_width * 3 ) / ( sizefactor * 4 );
if( tile_width % 2 != sdlrect.w % 2 ) {
sdlrect.w++;
}
// (tw / 2.0) / sizefactor * 3.0 / 4.0
sdlrect.h = ( tile_width * 3 ) / ( sizefactor * 8 );
if( tile_width / 2 % 2 != sdlrect.h % 2 ) {
sdlrect.h++;
}
// scrx + (tw - rectw) / 2.0
sdlrect.x = screen.x + divide_round_down( tile_width - sdlrect.w, 2 );
// scry + th - tw / 2.0 + (tw / 2.0 - recth) / 2.0
// Adding th and subtracting tw/2 here to cancel out the shifting in player_to_screen.
sdlrect.y = screen.y + tile_height + divide_round_down( -tile_width - sdlrect.h * 2, 4 );
} else {
sdlrect.w = tile_width / sizefactor;
if( tile_width % 2 != sdlrect.w % 2 ) {
sdlrect.w++;
}
sdlrect.h = tile_height / sizefactor;
if( tile_height % 2 != sdlrect.h % 2 ) {
sdlrect.h++;
}
sdlrect.x = screen.x + divide_round_down( tile_width - sdlrect.w, 2 );
sdlrect.y = screen.y + divide_round_down( tile_height - sdlrect.h, 2 );
}
geometry->rect( renderer, sdlrect, sdlcol );
}
bool cata_tiles::draw_terrain_below( const tripoint &p, const lit_level, int &,
const std::array<bool, 5> &invisible, const bool memorize_only )
{
if( memorize_only ) {
return false;
}
map &here = get_map();
const auto low_override = draw_below_override.find( p );
const bool low_overridden = low_override != draw_below_override.end();
if( low_overridden ? !low_override->second :
( invisible[0] || here.dont_draw_lower_floor( p ) ) ) {
return false;
}
tripoint pbelow = tripoint( p.xy(), p.z - 1 );
nc_color col = c_dark_gray;
const ter_t &curr_ter = here.ter( pbelow ).obj();
const furn_t &curr_furn = here.furn( pbelow ).obj();
int part_below;
int sizefactor = 2;
if( curr_furn.has_flag( ter_furn_flag::TFLAG_SEEN_FROM_ABOVE ) || curr_furn.movecost < 0 ) {
col = curr_furn.color();
} else if( const vehicle *veh = here.veh_at_internal( pbelow, part_below ) ) {
const int roof = veh->roof_at_part( part_below );
const auto vpobst = vpart_position( const_cast<vehicle &>( *veh ),
part_below ).obstacle_at_part();
col = ( roof >= 0 || vpobst ) ? c_light_gray : c_magenta;
sizefactor = ( roof >= 0 || vpobst ) ? 4 : 2;
} else if( curr_ter.has_flag( ter_furn_flag::TFLAG_SEEN_FROM_ABOVE ) ||
curr_ter.has_flag( ter_furn_flag::TFLAG_NO_FLOOR ) ||
curr_ter.has_flag( ter_furn_flag::TFLAG_NO_FLOOR_WATER ) ||
curr_ter.movecost == 0 ) {
col = curr_ter.color();
} else {
sizefactor = 4;
col = curr_ter.color();
}
draw_square_below( pbelow.xy(), col, sizefactor );
return true;
}
bool cata_tiles::draw_terrain( const tripoint &p, const lit_level ll, int &height_3d,
const std::array<bool, 5> &invisible, const bool memorize_only )
{
map &here = get_map();
const auto override = terrain_override.find( p );
const bool overridden = override != terrain_override.end();
bool neighborhood_overridden = overridden;
if( !neighborhood_overridden ) {
for( const point &dir : neighborhood ) {
if( terrain_override.find( p + dir ) != terrain_override.end() ) {
neighborhood_overridden = true;
break;
}
}
}
// first memorize the actual terrain
const ter_id &t = here.ter( p );
const std::string &tname = t.id().str();
// Legacy mode does not draw fog sprites
if( fov_3d_z_range == 0 && tname == "t_open_air" ) {
return false;
}
if( t && !invisible[0] ) {
int subtile = 0;
int rotation = 0;
const std::bitset<NUM_TERCONN> &connect_group = t.obj().connect_to_groups;
const std::bitset<NUM_TERCONN> &rotate_group = t.obj().rotate_to_groups;
if( connect_group.any() ) {
get_connect_values( p, subtile, rotation, connect_group, rotate_group, {} );
// re-memorize previously seen terrain in case new connections have been seen
here.memory_cache_ter_set_dirty( p, true );
} else {
get_terrain_orientation( p, rotation, subtile, {}, invisible, rotate_group );
// do something to get other terrain orientation values
}
if( here.memory_cache_ter_is_dirty( p ) ) {
get_avatar().memorize_terrain( here.getglobal( p ), tname, subtile, rotation );
}
// draw the actual terrain if there's no override
if( !neighborhood_overridden ) {
return memorize_only
? false
: draw_from_id_string( tname, TILE_CATEGORY::TERRAIN, empty_string, p, subtile,
rotation, ll, nv_goggles_activated, height_3d );
}
}
if( invisible[0] ? overridden : neighborhood_overridden ) {
// and then draw the override terrain
const ter_id &t2 = overridden ? override->second : t;
if( t2 ) {
// both the current and neighboring overrides may change the appearance
// of the tile, so always re-calculate it.
int subtile = 0;
int rotation = 0;
const std::bitset<NUM_TERCONN> &connect_group = t2.obj().connect_to_groups;
const std::bitset<NUM_TERCONN> &rotate_group = t2.obj().rotate_to_groups;
if( connect_group.any() ) {
get_connect_values( p, subtile, rotation, connect_group, rotate_group, terrain_override );
} else {
get_terrain_orientation( p, rotation, subtile, terrain_override, invisible, rotate_group );
}
const std::string &tname = t2.id().str();
// tile overrides are never memorized
// tile overrides are always shown with full visibility
const lit_level lit = overridden ? lit_level::LIT : ll;
const bool nv = overridden ? false : nv_goggles_activated;
return memorize_only
? false
: draw_from_id_string( tname, TILE_CATEGORY::TERRAIN, empty_string, p, subtile,
rotation, lit, nv, height_3d );
}
} else if( invisible[0] ) {
// try drawing memory if invisible and not overridden
const memorized_tile &mt = get_terrain_memory_at( here.getglobal( p ) );
if( !mt.get_ter_id().empty() ) {
return memorize_only
? false
: draw_from_id_string(
mt.get_ter_id(), TILE_CATEGORY::TERRAIN, empty_string, p, mt.get_ter_subtile(),
mt.get_ter_rotation(), lit_level::MEMORIZED, nv_goggles_activated, height_3d );
}
}
return false;
}
bool cata_tiles::draw_furniture( const tripoint &p, const lit_level ll, int &height_3d,
const std::array<bool, 5> &invisible, const bool memorize_only )
{
avatar &you = get_avatar();
const auto override = furniture_override.find( p );
const bool overridden = override != furniture_override.end();
bool neighborhood_overridden = overridden;
if( !neighborhood_overridden ) {
for( const point &dir : neighborhood ) {
if( furniture_override.find( p + dir ) != furniture_override.end() ) {
neighborhood_overridden = true;
break;
}
}
}
map &here = get_map();
// first memorize the actual furniture
const furn_id &f = here.furn( p );
if( f && !invisible[0] ) {
const std::array<int, 4> neighborhood = {
static_cast<int>( here.furn( p + point_south ) ),
static_cast<int>( here.furn( p + point_east ) ),
static_cast<int>( here.furn( p + point_west ) ),
static_cast<int>( here.furn( p + point_north ) )
};
int subtile = 0;
int rotation = 0;
const std::bitset<NUM_TERCONN> &connect_group = f.obj().connect_to_groups;
const std::bitset<NUM_TERCONN> &rotate_group = f.obj().rotate_to_groups;
if( connect_group.any() ) {
get_furn_connect_values( p, subtile, rotation, connect_group, rotate_group, {} );
} else {
get_tile_values_with_ter( p, f.to_i(), neighborhood, subtile, rotation, rotate_group );
}
const std::string &fname = f.id().str();
if( !( you.get_grab_type() == object_type::FURNITURE
&& p == you.pos() + you.grab_point )
&& here.memory_cache_dec_is_dirty( p ) ) {
you.memorize_decoration( here.getglobal( p ), fname, subtile, rotation );
}
// draw the actual furniture if there's no override
if( !neighborhood_overridden ) {
return memorize_only
? false
: draw_from_id_string( fname, TILE_CATEGORY::FURNITURE, empty_string, p, subtile,
rotation, ll, nv_goggles_activated, height_3d );
}
}
if( invisible[0] ? overridden : neighborhood_overridden ) {
// and then draw the override furniture
const furn_id &f2 = overridden ? override->second : f;
if( f2 ) {
// both the current and neighboring overrides may change the appearance
// of the tile, so always re-calculate it.
const auto furn = [&]( const tripoint & q, const bool invis ) -> furn_id {
const auto it = furniture_override.find( q );
return it != furniture_override.end() ? it->second :
( !overridden || !invis ) ? here.furn( q ) : f_null;
};
const std::array<int, 4> neighborhood = {
static_cast<int>( furn( p + point_south, invisible[1] ) ),
static_cast<int>( furn( p + point_east, invisible[2] ) ),
static_cast<int>( furn( p + point_west, invisible[3] ) ),
static_cast<int>( furn( p + point_north, invisible[4] ) )
};
int subtile = 0;
int rotation = 0;
const std::bitset<NUM_TERCONN> &connect_group = f.obj().connect_to_groups;
const std::bitset<NUM_TERCONN> &rotate_group = f.obj().rotate_to_groups;
if( connect_group.any() ) {
get_furn_connect_values( p, subtile, rotation, connect_group, rotate_group, {} );
} else {
get_tile_values_with_ter( p, f.to_i(), neighborhood, subtile, rotation, rotate_group );
}
get_tile_values_with_ter( p, f2.to_i(), neighborhood, subtile, rotation, 0 );
const std::string &fname = f2.id().str();
// tile overrides are never memorized
// tile overrides are always shown with full visibility
const lit_level lit = overridden ? lit_level::LIT : ll;
const bool nv = overridden ? false : nv_goggles_activated;
return memorize_only
? false
: draw_from_id_string( fname, TILE_CATEGORY::FURNITURE, empty_string, p, subtile,
rotation, lit, nv, height_3d );
}
} else if( invisible[0] ) {
// try drawing memory if invisible and not overridden
const memorized_tile &mt = get_furniture_memory_at( here.getglobal( p ) );
if( !mt.get_dec_id().empty() ) {
return memorize_only
? false
: draw_from_id_string(
mt.get_dec_id(), TILE_CATEGORY::FURNITURE, empty_string, p, mt.get_dec_subtile(),
mt.get_dec_rotation(), lit_level::MEMORIZED, nv_goggles_activated, height_3d );
}
}
return false;
}
bool cata_tiles::draw_trap( const tripoint &p, const lit_level ll, int &height_3d,
const std::array<bool, 5> &invisible, const bool memorize_only )
{
const auto override = trap_override.find( p );
const bool overridden = override != trap_override.end();
bool neighborhood_overridden = overridden;
if( !neighborhood_overridden ) {
for( const point &dir : neighborhood ) {
if( trap_override.find( p + dir ) != trap_override.end() ) {
neighborhood_overridden = true;
break;
}
}
}
avatar &you = get_avatar();
map &here = get_map();
// first memorize the actual trap
const trap &tr = here.tr_at( p );
if( !tr.is_null() && !invisible[0] && tr.can_see( p, you ) ) {
const std::array<int, 4> neighborhood = {
static_cast<int>( here.tr_at( p + point_south ).loadid ),
static_cast<int>( here.tr_at( p + point_east ).loadid ),
static_cast<int>( here.tr_at( p + point_west ).loadid ),
static_cast<int>( here.tr_at( p + point_north ).loadid )
};
int subtile = 0;
int rotation = 0;
get_tile_values( tr.loadid.to_i(), neighborhood, subtile, rotation, 0 );
const std::string trname = tr.loadid.id().str();
if( here.memory_cache_dec_is_dirty( p ) ) {
you.memorize_decoration( here.getglobal( p ), trname, subtile, rotation );
}
// draw the actual trap if there's no override
if( !neighborhood_overridden ) {
return memorize_only
? false
: draw_from_id_string( trname, TILE_CATEGORY::TRAP, empty_string, p, subtile,
rotation, ll, nv_goggles_activated, height_3d );
}
}
if( overridden || ( !invisible[0] && neighborhood_overridden &&
tr.can_see( p, you ) ) ) {
// and then draw the override trap
const trap_id &tr2 = overridden ? override->second : tr.loadid;
if( tr2 ) {
// both the current and neighboring overrides may change the appearance
// of the tile, so always re-calculate it.
const auto tr_at = [&]( const tripoint & q, const bool invis ) -> trap_id {
const auto it = trap_override.find( q );
return it != trap_override.end() ? it->second :
( !overridden || !invis ) ? here.tr_at( q ).loadid : tr_null;
};
const std::array<int, 4> neighborhood = {
static_cast<int>( tr_at( p + point_south, invisible[1] ) ),
static_cast<int>( tr_at( p + point_east, invisible[2] ) ),
static_cast<int>( tr_at( p + point_west, invisible[3] ) ),
static_cast<int>( tr_at( p + point_north, invisible[4] ) )
};
int subtile = 0;
int rotation = 0;
get_tile_values( tr2.to_i(), neighborhood, subtile, rotation, 0 );
const std::string &trname = tr2.id().str();
// tile overrides are never memorized
// tile overrides are always shown with full visibility
const lit_level lit = overridden ? lit_level::LIT : ll;
const bool nv = overridden ? false : nv_goggles_activated;
return memorize_only
? false
: draw_from_id_string( trname, TILE_CATEGORY::TRAP, empty_string, p, subtile,
rotation, lit, nv, height_3d );
}
} else if( invisible[0] ) {
// try drawing memory if invisible and not overridden
const memorized_tile &mt = get_trap_memory_at( here.getglobal( p ) );
if( !mt.get_dec_id().empty() ) {
return memorize_only
? false
: draw_from_id_string(
mt.get_dec_id(), TILE_CATEGORY::TRAP, empty_string, p, mt.get_dec_subtile(), mt.get_dec_rotation(),
lit_level::MEMORIZED, nv_goggles_activated, height_3d );
}
}
return false;
}
bool cata_tiles::draw_part_con( const tripoint &p, const lit_level ll, int &height_3d,
const std::array<bool, 5> &invisible, const bool memorize_only )
{
map &here = get_map();
// FIXME: fix tripoint type
if( here.partial_con_at( tripoint_bub_ms( p ) ) != nullptr && !invisible[0] ) {
avatar &you = get_avatar();
std::string const &trname = tr_unfinished_construction.str();;
if( here.memory_cache_dec_is_dirty( p ) ) {
you.memorize_decoration( here.getglobal( p ), trname, 0, 0 );
}
return memorize_only
? false
: draw_from_id_string( trname, TILE_CATEGORY::TRAP, empty_string, p, 0,
0, ll, nv_goggles_activated, height_3d );
}
return false;
}
bool cata_tiles::draw_graffiti( const tripoint &p, const lit_level ll, int &height_3d,
const std::array<bool, 5> &invisible, const bool memorize_only )
{
if( memorize_only ) {
return false;
}
map &here = get_map();
const auto override = graffiti_override.find( p );
const bool overridden = override != graffiti_override.end();
if( overridden ? !override->second : ( invisible[0] || !here.has_graffiti_at( p ) ) ) {
return false;
}
const lit_level lit = overridden ? lit_level::LIT : ll;
const int rotation = here.passable( p ) ? 1 : 0;
const std::string tile = "graffiti_" +
to_upper_case( string_replace( remove_punctuations( here.graffiti_at( p ) ), " ",
"_" ) ).substr( 0, 32 );
return draw_from_id_string( tileset_ptr->find_tile_type( tile ) ? tile : "graffiti",
TILE_CATEGORY::NONE, empty_string, p, 0, rotation, lit, false, height_3d );
}
bool cata_tiles::draw_field_or_item( const tripoint &p, const lit_level ll, int &height_3d,
const std::array<bool, 5> &invisible, const bool memorize_only )
{
if( memorize_only ) {
return false;
}
const auto fld_override = field_override.find( p );
const bool fld_overridden = fld_override != field_override.end();
map &here = get_map();
const field_type_id &fld = fld_overridden ?
fld_override->second : here.field_at( p ).displayed_field_type();
bool ret_draw_field = false;
bool ret_draw_items = false;
// go through each field and draw it
if( !fld_overridden ) {
const maptile &tile = here.maptile_at( p );
for( const std::pair<const field_type_id, field_entry> &fd_pr : here.field_at( p ) ) {
const field_type_id &fld = fd_pr.first;
if( !invisible[0] && fld.obj().display_field ) {
const lit_level lit = ll;
const bool nv = nv_goggles_activated;
auto has_field = [&]( field_type_id fld, const tripoint & q, const bool invis ) -> field_type_id {
// go through the fields and see if they are equal
field_type_id found = fd_null;
for( std::pair<const field_type_id, field_entry> &this_fld : here.field_at( q ) )
{
if( this_fld.first == fld ) {
found = fld;
}
}
const auto it = field_override.find( q );
return it != field_override.end() ? it->second :
( !fld_overridden || !invis ) ? found : fd_null;
};
// for rotation information
const std::array<int, 4> neighborhood = { {
static_cast<int>( has_field( fld, p + point_south, invisible[1] ) ),
static_cast<int>( has_field( fld, p + point_east, invisible[2] ) ),
static_cast<int>( has_field( fld, p + point_west, invisible[3] ) ),
static_cast<int>( has_field( fld, p + point_north, invisible[4] ) )
}
};
int subtile = 0;
int rotation = 0;
get_tile_values( fld.to_i(), neighborhood, subtile, rotation, 0 );
//get field intensity
int intensity = fd_pr.second.get_field_intensity();
bool has_drawn = false;
// start by drawing the layering data if available
// start for checking if layer data is available for the furniture
auto itt = tileset_ptr->field_layer_data.find( tile.get_furn_t().id.str() );
if( itt != tileset_ptr->field_layer_data.end() ) {
// the furniture has layer info
// go through all the layer variants
for( const layer_variant &layer_var : itt->second ) {
if( fld.id().str() == layer_var.id ) {
// get the sprite to draw
// roll should be based on the maptile seed to keep visuals consistent
int roll = 1;
std::string sprite_to_draw;
for( const auto &sprite_list : layer_var.sprite ) {
roll = roll - sprite_list.second;
if( roll < 0 ) {
sprite_to_draw = sprite_list.first;
break;
}
}
// if we have found info on the item go through and draw its stuff
ret_draw_field = draw_from_id_string( sprite_to_draw, TILE_CATEGORY::FIELD, empty_string, p,
subtile, rotation, lit, nv, height_3d, intensity, "", layer_var.offset );
has_drawn = true;
break;
}
}
} else {
// check if the terrain has data
auto itt = tileset_ptr->field_layer_data.find( tile.get_ter_t().id.str() );
if( itt != tileset_ptr->field_layer_data.end() ) {
// the furniture has layer info
// go through all the layer variants
for( const layer_variant &layer_var : itt->second ) {
if( fld.id().str() == layer_var.id ) {
// get the sprite to draw
// roll should be based on the maptile seed to keep visuals consistent
int roll = 1;
std::string sprite_to_draw;
for( const auto &sprite_list : layer_var.sprite ) {
roll = roll - sprite_list.second;
if( roll < 0 ) {
sprite_to_draw = sprite_list.first;
break;
}
}
// if we have found info on the item go through and draw its stuff
ret_draw_field = draw_from_id_string( sprite_to_draw, TILE_CATEGORY::FIELD, empty_string, p,
subtile, rotation, lit, nv, height_3d, intensity, "", layer_var.offset );
has_drawn = true;
break;
}
}
}
}
// draw the default sprite
if( !has_drawn ) {
ret_draw_field = draw_from_id_string( fld.id().str(), TILE_CATEGORY::FIELD, empty_string,
p, subtile, rotation, lit, nv, height_3d, intensity );
}
}
}
} else {
// draw the override
const field_type_id &fld = fld_override->second;
if( fld.obj().display_field ) {
const lit_level lit = lit_level::LIT;
const bool nv = false;
auto field_at = [&]( const tripoint & q, const bool invis ) -> field_type_id {
const auto it = field_override.find( q );
return it != field_override.end() ? it->second :
( !fld_overridden || !invis ) ? here.field_at( q ).displayed_field_type() : fd_null;
};
// for rotation information
const std::array<int, 4> neighborhood = {
static_cast<int>( field_at( p + point_south, invisible[1] ) ),
static_cast<int>( field_at( p + point_east, invisible[2] ) ),
static_cast<int>( field_at( p + point_west, invisible[3] ) ),
static_cast<int>( field_at( p + point_north, invisible[4] ) )
};
int subtile = 0;
int rotation = 0;
get_tile_values( fld.to_i(), neighborhood, subtile, rotation, 0 );
//get field intensity
int intensity = fld_overridden ? 0 : here.field_at( p ).displayed_intensity();
ret_draw_field = draw_from_id_string( fld.id().str(), TILE_CATEGORY::FIELD, empty_string,
p, subtile, rotation, lit, nv, height_3d, intensity );
}
}
if( fld.obj().display_items ) {
const auto it_override = item_override.find( p );
const bool it_overridden = it_override != item_override.end();
itype_id it_id;
mtype_id mon_id;
std::string variant;
bool hilite = false;
bool drawtop = true;
const itype *it_type;
const maptile &tile = here.maptile_at( p );
if( !invisible[0] ) {
// start by drawing the layering data if available
// start for checking if layer data is available for the furniture
auto itt = tileset_ptr->item_layer_data.find( tile.get_furn_t().id.str() );
if( itt != tileset_ptr->item_layer_data.end() ) {
// the furniture has layer info
// go through all the layer variants
for( const layer_variant &layer_var : itt->second ) {
for( const item &i : tile.get_items() ) {
if( i.typeId().str() == layer_var.id ) {
// if an item matches draw it and break
const std::string layer_it_category = i.typeId()->get_item_type_string();
const lit_level layer_lit = ll;
const bool layer_nv = nv_goggles_activated;
// get the sprite to draw
// roll should be based on the maptile seed to keep visuals consistent
int roll = i.seed % layer_var.total_weight;
std::string sprite_to_draw;
for( const auto &sprite_list : layer_var.sprite ) {
roll = roll - sprite_list.second;
if( roll < 0 ) {
sprite_to_draw = sprite_list.first;
break;
}
}
if( i.has_itype_variant() ) {
variant = i.itype_variant().id;
}
// if we have found info on the item go through and draw its stuff
draw_from_id_string( sprite_to_draw, TILE_CATEGORY::ITEM, layer_it_category, p, 0,
0, layer_lit, layer_nv, height_3d, 0, variant, layer_var.offset );
// if the top item is already being layered don't draw it later
if( i.typeId() == tile.get_uppermost_item().typeId() ) {
drawtop = false;
}
break;
}
}
}
} else {
// check if the terrain has data
auto itt = tileset_ptr->item_layer_data.find( tile.get_ter_t().id.str() );
if( itt != tileset_ptr->item_layer_data.end() ) {
// the furniture has layer info
// go through all the layer variants
for( const layer_variant &layer_var : itt->second ) {
for( const item &i : tile.get_items() ) {
if( i.typeId().str() == layer_var.id ) {
// if an item matches draw it and break
const std::string layer_it_category = i.typeId()->get_item_type_string();
const lit_level layer_lit = ll;
const bool layer_nv = nv_goggles_activated;
// get the sprite to draw
// roll should be based on the maptile seed to keep visuals consistent
int roll = i.seed % layer_var.total_weight;
std::string sprite_to_draw;
for( const auto &sprite_list : layer_var.sprite ) {
roll = roll - sprite_list.second;
if( roll < 0 ) {
sprite_to_draw = sprite_list.first;
break;
}
}
if( i.has_itype_variant() ) {
variant = i.itype_variant().id;
}
// if we have found info on the item go through and draw its stuff
draw_from_id_string( sprite_to_draw, TILE_CATEGORY::ITEM, layer_it_category, p, 0,
0, layer_lit, layer_nv, height_3d, 0, variant, layer_var.offset );
// if the top item is already being layered don't draw it later
if( i.typeId() == tile.get_uppermost_item().typeId() ) {
drawtop = false;
}
break;
}
}
}
}
}
}
variant.clear();
if( drawtop || it_overridden ) {
if( it_overridden ) {
it_id = std::get<0>( it_override->second );
mon_id = std::get<1>( it_override->second );
hilite = std::get<2>( it_override->second );
it_type = item::find_type( it_id );
} else if( !invisible[0] && here.sees_some_items( p, get_player_character() ) ) {
const item &itm = tile.get_uppermost_item();
if( itm.has_itype_variant() ) {
variant = itm.itype_variant().id;
}
const mtype *const mon = itm.get_mtype();
it_id = itm.typeId();
mon_id = mon ? mon->id : mtype_id::NULL_ID();
hilite = tile.get_item_count() > 1;
it_type = itm.type;
} else {
it_type = nullptr;
}
if( it_type && !it_id.is_null() ) {
const std::string disp_id = it_id == itype_corpse && mon_id ?
"corpse_" + mon_id.str() : it_id.str();
const std::string it_category = it_type->get_item_type_string();
const lit_level lit = it_overridden ? lit_level::LIT : ll;
const bool nv = it_overridden ? false : nv_goggles_activated;
ret_draw_items = draw_from_id_string( disp_id, TILE_CATEGORY::ITEM, it_category, p, 0,
0, lit, nv, height_3d, 0, variant );
if( ret_draw_items && hilite ) {
draw_item_highlight( p, height_3d );
}
}
}
// we may still need to draw the highlight
else if( tile.get_item_count() > 1 && here.sees_some_items( p, get_player_character() ) ) {
draw_item_highlight( p, height_3d );
}
}
return ret_draw_field && ret_draw_items;
}
bool cata_tiles::draw_vpart_below( const tripoint &p, const lit_level /*ll*/, int &/*height_3d*/,
const std::array<bool, 5> &invisible, const bool memorize_only )
{
if( memorize_only ) {
return false;
}
const auto low_override = draw_below_override.find( p );
const bool low_overridden = low_override != draw_below_override.end();
if( low_overridden ? !low_override->second : ( invisible[0] ||
get_map().dont_draw_lower_floor( p ) ) ) {
return false;
}
tripoint pbelow( p.xy(), p.z - 1 );
int height_3d_below = 0;
std::array<bool, 5> below_invisible;
std::fill( below_invisible.begin(), below_invisible.end(), false );
return draw_vpart_no_roof( pbelow, lit_level::LOW, height_3d_below, below_invisible,
memorize_only );
}
bool cata_tiles::draw_vpart_no_roof( const tripoint &p, lit_level ll, int &height_3d,
const std::array<bool, 5> &invisible, const bool memorize_only )
{
return draw_vpart( p, ll, height_3d, invisible, false, memorize_only );
}
bool cata_tiles::draw_vpart_roof( const tripoint &p, lit_level ll, int &height_3d,
const std::array<bool, 5> &invisible, const bool memorize_only )
{
return draw_vpart( p, ll, height_3d, invisible, true, memorize_only );
}
bool cata_tiles::draw_vpart( const tripoint &p, lit_level ll, int &height_3d,
const std::array<bool, 5> &invisible, bool roof, const bool memorize_only )
{
const auto override = vpart_override.find( p );
const bool overridden = override != vpart_override.end();
map &here = get_map();
// first memorize the actual vpart
const optional_vpart_position ovp = here.veh_at( p );
if( ovp && !invisible[0] ) {
const vehicle &veh = ovp->vehicle();
const vpart_display vd = veh.get_display_of_tile( ovp->mount() );
if( !vd.id.is_null() ) {
const int subtile = vd.is_open ? open_ : vd.is_broken ? broken : 0;
const int rotation = angle_to_dir4( 270_degrees - veh.face.dir() );
avatar &you = get_avatar();
if( !veh.forward_velocity() && !veh.player_in_control( you )
&& !( you.get_grab_type() == object_type::VEHICLE
&& veh.get_points().count( you.pos() + you.grab_point ) )
&& here.memory_cache_dec_is_dirty( p ) ) {
you.memorize_decoration( here.getglobal( p ), vd.get_tileset_id(), subtile, rotation );
}
if( !overridden ) {
int height_3d_temp = height_3d;
const bool ret = memorize_only
? false
: draw_from_id_string( "vp_" + vd.id.str(), TILE_CATEGORY::VEHICLE_PART,
empty_string, p, subtile, rotation, ll,
nv_goggles_activated, height_3d_temp, 0, vd.variant.id );
if( ret && vd.has_cargo ) {
draw_item_highlight( p, height_3d_temp );
}
// Do not increment height_3d for roof vparts
if( !roof ) {
height_3d = height_3d_temp;
}
return ret;
}
}
}
if( overridden ) {
// and then draw the override vpart
const vpart_id &vp2 = std::get<0>( override->second );
if( vp2 ) {
const char part_mod = std::get<1>( override->second );
const int subtile = part_mod == 1 ? open_ : part_mod == 2 ? broken : 0;
const int rotation = angle_to_dir4( 270_degrees - std::get<2>( override->second ) );
const int draw_highlight = std::get<3>( override->second );
const std::string vpname = "vp_" + vp2.str();
// tile overrides are never memorized
// tile overrides are always shown with full visibility
int height_3d_temp = height_3d;
const bool ret = memorize_only
? false
: draw_from_id_string( vpname, TILE_CATEGORY::VEHICLE_PART, empty_string, p, subtile,
rotation, lit_level::LIT, false, height_3d_temp );
if( ret && draw_highlight ) {
draw_item_highlight( p, height_3d_temp );
}
if( !roof ) {
height_3d = height_3d_temp;
}
return ret;
}
} else if( !roof && invisible[0] ) {
// try drawing memory if invisible and not overridden
const memorized_tile &t = get_vpart_memory_at( here.getglobal( p ) );
std::string_view tid = t.get_dec_id();
if( !tid.empty() ) {
int height_3d_temp = height_3d;
std::string_view tvar;
const size_t variant_separator = tid.find( vehicles::variant_separator );
if( variant_separator != std::string::npos ) {
tvar = tid.substr( variant_separator + 1 );
tid = tid.substr( 0, variant_separator );
}
return memorize_only
? false
: draw_from_id_string(
std::string( tid ), TILE_CATEGORY::VEHICLE_PART, empty_string, p, t.get_dec_subtile(),
t.get_dec_rotation(), lit_level::MEMORIZED, nv_goggles_activated, height_3d_temp, 0,
std::string( tvar ) );
}
}
return false;
}
bool cata_tiles::draw_critter_at_below( const tripoint &p, const lit_level, int &,
const std::array<bool, 5> &invisible, const bool memorize_only )
{
if( memorize_only ) {
return false;
}
// Check if we even need to draw below. If not, bail.
const auto low_override = draw_below_override.find( p );
const bool low_overridden = low_override != draw_below_override.end();
if( low_overridden ? !low_override->second : ( invisible[0] ||
get_map().dont_draw_lower_floor( p ) ) ) {
return false;
}
tripoint pbelow( p.xy(), p.z - 1 );
// Get the critter at the location below. If there isn't one,
// we can bail.
const Creature *critter = get_creature_tracker().creature_at( pbelow, true );
if( critter == nullptr ) {
return false;
}
Character &you = get_player_character();
// Check if the player can actually see the critter. We don't care if
// it's via infrared or not, just whether or not they're seen. If not,
// we can bail.
if( !you.sees( *critter ) &&
!( you.sees_with_infrared( *critter ) || you.sees_with_specials( *critter ) ) ) {
return false;
}
draw_square_below( pbelow.xy(), c_red, 2 );
return true;
}
bool cata_tiles::draw_critter_at( const tripoint &p, lit_level ll, int &height_3d,
const std::array<bool, 5> &invisible, const bool memorize_only )
{
if( memorize_only ) {
return false;
}
bool result;
bool is_player;
bool sees_player;
Creature::Attitude attitude;
Character &you = get_player_character();
const Creature *pcritter = get_creature_tracker().creature_at( p, true );
const bool always_visible = pcritter && pcritter->has_flag( mon_flag_ALWAYS_VISIBLE );
const auto override = monster_override.find( p );
if( override != monster_override.end() ) {
const mtype_id id = std::get<0>( override->second );
if( !id ) {
return false;
}
is_player = false;
sees_player = false;
attitude = std::get<3>( override->second );
const std::string &chosen_id = id.str();
const std::string &ent_subcategory = id.obj().species.empty() ?
empty_string : id.obj().species.begin()->str();
result = draw_from_id_string( chosen_id, TILE_CATEGORY::MONSTER, ent_subcategory, p,
corner, 0, lit_level::LIT, false, height_3d );
} else if( !invisible[0] || always_visible ) {
if( pcritter == nullptr ) {
return false;
}
const Creature &critter = *pcritter;
if( !you.sees( critter ) ) {
if( you.sees_with_infrared( critter ) ||
you.sees_with_specials( critter ) ) {
return draw_from_id_string( "infrared_creature", TILE_CATEGORY::NONE, empty_string,
p, 0, 0, lit_level::LIT, false, height_3d );
}
return false;
}
result = false;
sees_player = false;
is_player = false;
attitude = Creature::Attitude::ANY;
const monster *m = dynamic_cast<const monster *>( &critter );
if( m != nullptr ) {
const TILE_CATEGORY ent_category = TILE_CATEGORY::MONSTER;
std::string ent_subcategory = empty_string;
if( !m->type->species.empty() ) {
ent_subcategory = m->type->species.begin()->str();
}
const int subtile = corner;
// depending on the toggle flip sprite left or right
int rot_facing = -2;
if( m->facing == FacingDirection::RIGHT ) {
rot_facing = 0;
} else if( m->facing == FacingDirection::LEFT ) {
rot_facing = -1;
}
if( rot_facing >= -1 ) {
const mtype_id ent_name = m->type->id;
std::string chosen_id = ent_name.str();
if( m->has_effect( effect_ridden ) ) {
int pl_under_height = 6;
if( m->mounted_player ) {
draw_entity_with_overlays( *m->mounted_player, p, ll, pl_under_height );
}
const std::string prefix = "rid_";
std::string copy_id = chosen_id;
const std::string ridden_id = copy_id.insert( 0, prefix );
const tile_type *tt = tileset_ptr->find_tile_type( ridden_id );
if( tt ) {
chosen_id = ridden_id;
}
}
result = draw_from_id_string( chosen_id, ent_category, ent_subcategory, p,
subtile, rot_facing, ll, false, height_3d );
sees_player = m->sees( you );
attitude = m->attitude_to( you );
}
}
const Character *pl = dynamic_cast<const Character *>( &critter );
if( pl != nullptr ) {
draw_entity_with_overlays( *pl, p, ll, height_3d );
result = true;
if( pl->is_avatar() ) {
is_player = true;
} else {
sees_player = pl->sees( you );
attitude = pl->attitude_to( you );
}
}
} else {
// invisible
if( pcritter == nullptr ) {
return false;
}
// scope_is_blocking is true if player is aiming and aim FOV limits obscure that position
const bool scope_is_blocking = you.is_avatar() && you.as_avatar()->cant_see( p );
const bool sees_with_infrared = !scope_is_blocking && you.sees_with_infrared( *pcritter );
if( sees_with_infrared || you.sees_with_specials( *pcritter ) ) {
// try drawing infrared creature if invisible and not overridden
// return directly without drawing overlay
return draw_from_id_string( "infrared_creature", TILE_CATEGORY::NONE, empty_string, p,
0, 0, lit_level::LIT, false, height_3d );
} else {
return false;
}
}
if( result && !is_player ) {
std::string draw_id = "overlay_" + Creature::attitude_raw_string( attitude );
if( sees_player && !you.has_trait( trait_INATTENTIVE ) ) {
draw_id += "_sees_player";
}
if( tileset_ptr->find_tile_type( draw_id ) ) {
draw_from_id_string( draw_id, TILE_CATEGORY::NONE, empty_string, p, 0, 0,
lit_level::LIT, false, height_3d );
}
}
return result;
}
bool cata_tiles::draw_critter_above( const tripoint &p, lit_level ll, int &height_3d,
const std::array<bool, 5> &invisible )
{
if( invisible[0] ) {
return false;
}
tripoint scan_p( p.xy(), p.z + 1 );
map &here = get_map();
Character &you = get_player_character();
const Creature *pcritter = nullptr;
// Search for a creature above
while( pcritter == nullptr && !here.dont_draw_lower_floor( scan_p ) &&
scan_p.z - you.pos().z <= fov_3d_z_range ) {
pcritter = get_creature_tracker().creature_at( scan_p, true );
scan_p.z++;
}
// Abort if no creature found
if( pcritter == nullptr ) {
return false;
}
const Creature &critter = *pcritter;
// Draw shadow
if( draw_from_id_string( "shadow", TILE_CATEGORY::NONE, empty_string, p,
0, 0, ll, false, height_3d ) && scan_p.z - 1 > you.pos().z && you.sees( critter ) ) {
bool is_player = false;
bool sees_player = false;
Creature::Attitude attitude = Creature::Attitude::ANY;
// Get critter status disposition if monster
const monster *m = dynamic_cast<const monster *>( &critter );
if( m != nullptr ) {
sees_player = m->sees( you );
attitude = m->attitude_to( you );
}
// Get critter status disposition if character
const Character *pl = dynamic_cast<const Character *>( &critter );
if( pl != nullptr ) {
if( pl->is_avatar() ) {
is_player = true;
} else {
sees_player = pl->sees( you );
attitude = pl->attitude_to( you );
}
}
// Draw overlay for shadow owner
if( !is_player ) {
std::string draw_id = "overlay_" + Creature::attitude_raw_string( attitude );
if( sees_player && !you.has_trait( trait_INATTENTIVE ) ) {
draw_id += "_sees_player";
}
if( tileset_ptr->find_tile_type( draw_id ) ) {
draw_from_id_string( draw_id, TILE_CATEGORY::NONE, empty_string, p, 0, 0,
lit_level::LIT, false, height_3d );
}
}
return true;
} else {
return false;
}
}
bool cata_tiles::draw_zone_mark( const tripoint &p, lit_level ll, int &height_3d,
const std::array<bool, 5> &invisible, const bool memorize_only )
{
if( memorize_only ) {
return false;
}
if( invisible[0] ) {
return false;
}
if( !g->is_zones_manager_open() ) {
return false;
}
const zone_manager &mgr = zone_manager::get_manager();
const tripoint_abs_ms abs = get_map().getglobal( p );
const zone_data *zone = mgr.get_bottom_zone( abs );
if( zone && zone->has_options() ) {
const mark_option *option = dynamic_cast<const mark_option *>( &zone->get_options() );
if( option && !option->get_mark().empty() ) {
return draw_from_id_string( option->get_mark(), TILE_CATEGORY::NONE, empty_string, p,
0, 0, ll, nv_goggles_activated, height_3d );
}
}
return false;
}
bool cata_tiles::draw_zombie_revival_indicators( const tripoint &pos, const lit_level /*ll*/,
int &height_3d, const std::array<bool, 5> &invisible, const bool memorize_only )
{
if( memorize_only ) {
return false;
}
map &here = get_map();
if( tileset_ptr->find_tile_type( ZOMBIE_REVIVAL_INDICATOR ) && !invisible[0] &&
item_override.find( pos ) == item_override.end() &&
here.could_see_items( pos, get_player_character() ) ) {
for( item &i : here.i_at( pos ) ) {
if( i.can_revive() ) {
return draw_from_id_string( ZOMBIE_REVIVAL_INDICATOR, TILE_CATEGORY::NONE,
empty_string, pos, 0, 0, lit_level::LIT, false, height_3d );
}
}
}
return false;
}
void cata_tiles::draw_zlevel_overlay( const tripoint &p, const lit_level ll, int &height_3d )
{
// Draws zlevel fog using geometry renderer
// Slower than sprites so only use as fallback when sprite missing
const point screen = player_to_screen( p.xy() );
SDL_Rect draw_rect;
if( is_isometric() ) {
// See comments in get_window_base_tile_counts for an explanation of tile width
// and height.
//
// Because different tilesets may have different tile shapes, we cannot
// draw a tile that fits every tileset, so this only acts as a placeholder
// and the tilesets should make a tile that matches the shape of other
// sprites.
draw_rect.x = screen.x;
// scry
// + th - tw / 2.0 /* cancel out the shifting in player_to_screen */
// - height_3d
// + tw / 8.0 /* shift 1/4 of normal height to avoid overlap among overlays */
draw_rect.y = screen.y + tile_height - tile_width * 3 / 8 - height_3d;
draw_rect.w = tile_width;
// Make the tile half the normal height to avoid overlap among overlays
draw_rect.h = tile_width / 4;
} else {
draw_rect.x = screen.x;
draw_rect.y = screen.y - height_3d;
draw_rect.w = tile_width;
draw_rect.h = tile_height;
}
// Overlay color is based on light level
SDL_Color fog_color = curses_color_to_SDL( c_black );
if( ll == lit_level::BRIGHT_ONLY || ll == lit_level::BRIGHT || ll == lit_level::LIT ) {
fog_color = curses_color_to_SDL( c_light_gray );
} else if( ll == lit_level::LOW ) {
fog_color = curses_color_to_SDL( c_dark_gray );
}
// Setting for fog transparency
// On isometric tilesets, fog intensity scales with zlevel_height in tile_config.json
fog_color.a = fog_alpha;
// Change blend mode for transparency to work
// Disable after to avoid visual bugs
SetRenderDrawBlendMode( renderer, SDL_BLENDMODE_BLEND );
geometry->rect( renderer, draw_rect, fog_color );
SetRenderDrawBlendMode( renderer, SDL_BLENDMODE_NONE );
}
void cata_tiles::draw_entity_with_overlays( const Character &ch, const tripoint &p, lit_level ll,
int &height_3d )
{
std::string ent_name;
if( ch.is_npc() ) {
ent_name = ch.male ? "npc_male" : "npc_female";
} else {
ent_name = ch.male ? "player_male" : "player_female";
}
// first draw the character itself(i guess this means a tileset that
// takes this seriously needs a naked sprite)
int prev_height_3d = height_3d;
// depending on the toggle flip sprite left or right
if( ch.facing == FacingDirection::RIGHT ) {
draw_from_id_string( ent_name, TILE_CATEGORY::NONE, "", p, corner, 0, ll, false,
height_3d );
} else if( ch.facing == FacingDirection::LEFT ) {
draw_from_id_string( ent_name, TILE_CATEGORY::NONE, "", p, corner, -1, ll, false,
height_3d );
}
// next up, draw all the overlays
std::vector<std::pair<std::string, std::string>> overlays = ch.get_overlay_ids();
for( const std::pair<std::string, std::string> &overlay : overlays ) {
std::string draw_id = overlay.first;
if( find_overlay_looks_like( ch.male, overlay.first, overlay.second, draw_id ) ) {
int overlay_height_3d = prev_height_3d;
if( ch.facing == FacingDirection::RIGHT ) {
draw_from_id_string( draw_id, TILE_CATEGORY::NONE, "", p, corner, /*rota:*/ 0, ll,
false, overlay_height_3d );
} else if( ch.facing == FacingDirection::LEFT ) {
draw_from_id_string( draw_id, TILE_CATEGORY::NONE, "", p, corner, /*rota:*/ -1, ll,
false, overlay_height_3d );
}
// the tallest height-having overlay is the one that counts
height_3d = std::max( height_3d, overlay_height_3d );
}
}
}
bool cata_tiles::draw_item_highlight( const tripoint &pos, int &height_3d )
{
return draw_from_id_string( ITEM_HIGHLIGHT, TILE_CATEGORY::NONE, empty_string, pos, 0, 0,
lit_level::LIT, false, height_3d );
}
std::shared_ptr<const tileset> tileset_cache::load_tileset( const std::string &tileset_id,
const SDL_Renderer_Ptr &renderer, const bool precheck, const bool force, const bool pump_events )
{
const auto get_or_create_tileset = [&]() {
const auto it = tilesets_.find( tileset_id );
if( it == tilesets_.end() || it->second.expired() ) {
std::shared_ptr<tileset> new_ts = std::make_shared<tileset>();
loader loader( *new_ts, renderer );
loader.load( tileset_id, precheck, pump_events );
tilesets_.emplace( tileset_id, new_ts );
return new_ts;
}
return it->second.lock();
};
std::shared_ptr<tileset> ts = get_or_create_tileset();
if( force || ( ts->get_tileset_id().empty() && !precheck ) ) {
loader loader( *ts, renderer );
loader.load( tileset_id, precheck, pump_events );
}
return ts;
}
void tileset_cache::loader::ensure_default_item_highlight()
{
if( ts.find_tile_type( ITEM_HIGHLIGHT ) ) {
return;
}
const Uint8 highlight_alpha = 127;
int index = ts.tile_values.size();
const SDL_Surface_Ptr surface = create_surface_32( ts.tile_width, ts.tile_height );
cata_assert( surface );
throwErrorIf( SDL_FillRect( surface.get(), nullptr, SDL_MapRGBA( surface->format, 0, 0, 127,
highlight_alpha ) ) != 0, "SDL_FillRect failed" );
ts.tile_values.emplace_back( CreateTextureFromSurface( renderer, surface ),
SDL_Rect{ 0, 0, ts.tile_width, ts.tile_height } );
ts.tile_ids[ITEM_HIGHLIGHT].fg.add( std::vector<int>( {index} ), 1 );
}
/* Animation Functions */
/* -- Inits */
void cata_tiles::init_explosion( const tripoint &p, int radius )
{
do_draw_explosion = true;
exp_pos = p;
exp_rad = radius;
}
void cata_tiles::init_custom_explosion_layer( const std::map<tripoint, explosion_tile> &layer )
{
do_draw_custom_explosion = true;
custom_explosion_layer = layer;
}
void cata_tiles::init_draw_bullet( const tripoint &p, std::string name )
{
do_draw_bullet = true;
bul_pos = p;
bul_id = std::move( name );
}
void cata_tiles::init_draw_hit( const tripoint &p, std::string name )
{
do_draw_hit = true;
hit_pos = p;
hit_entity_id = std::move( name );
}
void cata_tiles::init_draw_line( const tripoint &p, std::vector<tripoint> trajectory,
std::string name, bool target_line )
{
do_draw_line = true;
is_target_line = target_line;
line_pos = p;
line_endpoint_id = std::move( name );
line_trajectory = std::move( trajectory );
}
void cata_tiles::init_draw_cursor( const tripoint &p )
{
do_draw_cursor = true;
cursors.emplace_back( p );
}
void cata_tiles::init_draw_highlight( const tripoint &p )
{
do_draw_highlight = true;
highlights.emplace_back( p );
}
void cata_tiles::init_draw_weather( weather_printable weather, std::string name )
{
do_draw_weather = true;
weather_name = std::move( name );
anim_weather = std::move( weather );
}
void cata_tiles::init_draw_sct()
{
do_draw_sct = true;
}
void cata_tiles::init_draw_zones( const tripoint &_start, const tripoint &_end,
const tripoint &_offset )
{
do_draw_zones = true;
zone_start = _start;
zone_end = _end;
zone_offset = _offset;
}
void cata_tiles::init_draw_async_anim( const tripoint &p, const std::string &tile_id )
{
do_draw_async_anim = true;
async_anim_layer[ p ] = tile_id;
}
void cata_tiles::init_draw_radiation_override( const tripoint &p, const int rad )
{
radiation_override.emplace( p, rad );
}
void cata_tiles::init_draw_terrain_override( const tripoint &p, const ter_id &id )
{
terrain_override.emplace( p, id );
}
void cata_tiles::init_draw_furniture_override( const tripoint &p, const furn_id &id )
{
furniture_override.emplace( p, id );
}
void cata_tiles::init_draw_graffiti_override( const tripoint &p, const bool has )
{
graffiti_override.emplace( p, has );
}
void cata_tiles::init_draw_trap_override( const tripoint &p, const trap_id &id )
{
trap_override.emplace( p, id );
}
void cata_tiles::init_draw_field_override( const tripoint &p, const field_type_id &id )
{
field_override.emplace( p, id );
}
void cata_tiles::init_draw_item_override( const tripoint &p, const itype_id &id,
const mtype_id &mid, const bool hilite )
{
item_override.emplace( p, std::make_tuple( id, mid, hilite ) );
}
void cata_tiles::init_draw_vpart_override( const tripoint &p, const vpart_id &id,
const int part_mod, const units::angle &veh_dir, const bool hilite, const point &mount )
{
vpart_override.emplace( p, std::make_tuple( id, part_mod, veh_dir, hilite, mount ) );
}
void cata_tiles::init_draw_below_override( const tripoint &p, const bool draw )
{
draw_below_override.emplace( p, draw );
}
void cata_tiles::init_draw_monster_override( const tripoint &p, const mtype_id &id, const int count,
const bool more, const Creature::Attitude att )
{
monster_override.emplace( p, std::make_tuple( id, count, more, att ) );
}
/* -- Void Animators */
void cata_tiles::void_explosion()
{
do_draw_explosion = false;
exp_pos = {-1, -1, -1};
exp_rad = -1;
}
void cata_tiles::void_custom_explosion()
{
do_draw_custom_explosion = false;
custom_explosion_layer.clear();
}
void cata_tiles::void_bullet()
{
do_draw_bullet = false;
bul_pos = { -1, -1, -1 };
bul_id.clear();
}
void cata_tiles::void_hit()
{
do_draw_hit = false;
hit_pos = { -1, -1, -1 };
hit_entity_id.clear();
}
void cata_tiles::void_line()
{
do_draw_line = false;
is_target_line = false;
line_pos = { -1, -1, -1 };
line_endpoint_id.clear();
line_trajectory.clear();
}
void cata_tiles::void_cursor()
{
do_draw_cursor = false;
cursors.clear();
}
void cata_tiles::void_highlight()
{
do_draw_highlight = false;
highlights.clear();
}
void cata_tiles::void_weather()
{
do_draw_weather = false;
weather_name.clear();
anim_weather.vdrops.clear();
}
void cata_tiles::void_sct()
{
do_draw_sct = false;
}
void cata_tiles::void_zones()
{
do_draw_zones = false;
}
void cata_tiles::void_async_anim()
{
do_draw_async_anim = false;
async_anim_layer.clear();
}
void cata_tiles::void_radiation_override()
{
radiation_override.clear();
}
void cata_tiles::void_terrain_override()
{
terrain_override.clear();
}
void cata_tiles::void_furniture_override()
{
furniture_override.clear();
}
void cata_tiles::void_graffiti_override()
{
graffiti_override.clear();
}
void cata_tiles::void_trap_override()
{
trap_override.clear();
}
void cata_tiles::void_field_override()
{
field_override.clear();
}
void cata_tiles::void_item_override()
{
item_override.clear();
}
void cata_tiles::void_vpart_override()
{
vpart_override.clear();
}
void cata_tiles::void_draw_below_override()
{
draw_below_override.clear();
}
void cata_tiles::void_monster_override()
{
monster_override.clear();
}
bool cata_tiles::has_draw_override( const tripoint &p ) const
{
return radiation_override.find( p ) != radiation_override.end() ||
terrain_override.find( p ) != terrain_override.end() ||
furniture_override.find( p ) != furniture_override.end() ||
graffiti_override.find( p ) != graffiti_override.end() ||
trap_override.find( p ) != trap_override.end() ||
field_override.find( p ) != field_override.end() ||
item_override.find( p ) != item_override.end() ||
vpart_override.find( p ) != vpart_override.end() ||
draw_below_override.find( p ) != draw_below_override.end() ||
monster_override.find( p ) != monster_override.end();
}
/* -- Animation Renders */
void cata_tiles::draw_explosion_frame()
{
std::string exp_name = "explosion";
int subtile = 0;
int rotation = 0;
for( int i = 1; i < exp_rad; ++i ) {
subtile = corner;
rotation = 0;
draw_from_id_string( exp_name, exp_pos + point( -i, -i ),
subtile, rotation++, lit_level::LIT, nv_goggles_activated );
draw_from_id_string( exp_name, exp_pos + point( -i, i ),
subtile, rotation++, lit_level::LIT, nv_goggles_activated );
draw_from_id_string( exp_name, exp_pos + point( i, i ),
subtile, rotation++, lit_level::LIT, nv_goggles_activated );
draw_from_id_string( exp_name, exp_pos + point( i, -i ),
subtile, rotation, lit_level::LIT, nv_goggles_activated );
subtile = edge;
for( int j = 1 - i; j < 0 + i; j++ ) {
rotation = 0;
draw_from_id_string( exp_name, exp_pos + point( j, -i ),
subtile, rotation, lit_level::LIT, nv_goggles_activated );
draw_from_id_string( exp_name, exp_pos + point( j, i ),
subtile, rotation, lit_level::LIT, nv_goggles_activated );
rotation = 1;
draw_from_id_string( exp_name, exp_pos + point( -i, j ),
subtile, rotation, lit_level::LIT, nv_goggles_activated );
draw_from_id_string( exp_name, exp_pos + point( i, j ),
subtile, rotation, lit_level::LIT, nv_goggles_activated );
}
}
}
void cata_tiles::draw_custom_explosion_frame()
{
// TODO: Make the drawing code handle all the missing tiles: <^>v and *
// TODO: Add more explosion tiles, like "strong explosion", so that it displays more info
static const std::string exp_strong = "explosion";
static const std::string exp_medium = "explosion_medium";
static const std::string exp_weak = "explosion_weak";
int subtile = 0;
int rotation = 0;
for( const auto &pr : custom_explosion_layer ) {
const explosion_neighbors ngh = pr.second.neighborhood;
const nc_color col = pr.second.color;
switch( ngh ) {
case N_NORTH:
case N_SOUTH:
subtile = edge;
rotation = 1;
break;
case N_WEST:
case N_EAST:
subtile = edge;
rotation = 0;
break;
case N_NORTH | N_SOUTH:
case N_NORTH | N_SOUTH | N_WEST:
case N_NORTH | N_SOUTH | N_EAST:
subtile = edge;
rotation = 1;
break;
case N_WEST | N_EAST:
case N_WEST | N_EAST | N_NORTH:
case N_WEST | N_EAST | N_SOUTH:
subtile = edge;
rotation = 0;
break;
case N_SOUTH | N_EAST:
subtile = corner;
rotation = 0;
break;
case N_NORTH | N_EAST:
subtile = corner;
rotation = 1;
break;
case N_NORTH | N_WEST:
subtile = corner;
rotation = 2;
break;
case N_SOUTH | N_WEST:
subtile = corner;
rotation = 3;
break;
case N_NO_NEIGHBORS:
case N_WEST | N_EAST | N_NORTH | N_SOUTH:
// Needs some special tile
subtile = edge;
break;
}
const tripoint &p = pr.first;
std::string explosion_tile_id;
// Use target sprite if exist, otherwise col will determine fallback sprite
if( pr.second.tile_name &&
find_tile_looks_like( *pr.second.tile_name, TILE_CATEGORY::NONE, "" ) ) {
explosion_tile_id = *pr.second.tile_name;
} else if( col == c_red ) {
explosion_tile_id = exp_strong;
} else if( col == c_yellow ) {
explosion_tile_id = exp_medium;
} else if( col == c_black ) {
// c_black results in no fallback sprite
return;
} else {
explosion_tile_id = exp_weak;
}
draw_from_id_string( explosion_tile_id, p, subtile, rotation, lit_level::LIT,
nv_goggles_activated );
}
}
void cata_tiles::draw_bullet_frame()
{
draw_from_id_string( bul_id, TILE_CATEGORY::BULLET, empty_string, bul_pos, 0, 0,
lit_level::LIT, false );
}
void cata_tiles::draw_hit_frame()
{
std::string hit_overlay = "animation_hit";
draw_from_id_string( hit_entity_id, TILE_CATEGORY::HIT_ENTITY, empty_string, hit_pos, 0, 0,
lit_level::LIT, false );
draw_from_id_string( hit_overlay, hit_pos, 0, 0, lit_level::LIT, false );
}
void cata_tiles::draw_line()
{
if( line_trajectory.empty() ) {
return;
}
static std::string line_overlay = "animation_line";
if( !is_target_line || get_player_view().sees( line_pos ) ) {
for( auto it = line_trajectory.begin(); it != line_trajectory.end() - 1; ++it ) {
draw_from_id_string( line_overlay, *it, 0, 0, lit_level::LIT, false );
}
}
draw_from_id_string( line_endpoint_id, line_trajectory.back(), 0, 0, lit_level::LIT, false );
}
void cata_tiles::draw_cursor()
{
for( const tripoint &p : cursors ) {
draw_from_id_string( "cursor", p, 0, 0, lit_level::LIT, false );
}
}
void cata_tiles::draw_highlight()
{
for( const tripoint &p : highlights ) {
draw_from_id_string( "highlight", p, 0, 0, lit_level::LIT, false );
}
}
void cata_tiles::draw_weather_frame()
{
for( auto &vdrop : anim_weather.vdrops ) {
// TODO: Z-level awareness if weather ever happens on anything but z-level 0.
point p( vdrop.first, vdrop.second );
if( !is_isometric() ) {
// currently in ASCII screen coordinates
const std::optional temp = tile_to_player( p );
if( !temp.has_value() ) {
continue;
}
p = temp.value();
}
const tripoint pos( p, 0 );
draw_from_id_string( weather_name, TILE_CATEGORY::WEATHER, empty_string, pos, 0, 0,
lit_level::LIT, nv_goggles_activated );
}
}
void cata_tiles::draw_sct_frame( std::multimap<point, formatted_text> &overlay_strings )
{
const bool use_font = get_option<bool>( "ANIMATION_SCT_USE_FONT" );
tripoint player_pos = get_player_character().pos();
for( const scrollingcombattext::cSCT &sct : SCT.vSCT ) {
const point iD( sct.getPosX(), sct.getPosY() );
const int full_text_length = utf8_width( sct.getText() );
point iOffset;
for( int j = 0; j < 2; ++j ) {
std::string sText = sct.getText( ( j == 0 ) ? "first" : "second" );
int FG = msgtype_to_tilecolor( sct.getMsgType( ( j == 0 ) ? "first" : "second" ),
sct.getStep() >= scrollingcombattext::iMaxSteps / 2 );
if( use_font ) {
const direction direction = sct.getDirection();
// Compensate for string length offset added at SCT creation
// (it will be readded using font size and proper encoding later).
const int direction_offset = ( -displace_XY( direction ).x + 1 ) *
full_text_length / 2;
overlay_strings.emplace(
player_to_screen( iD + point( direction_offset, 0 ) ),
formatted_text( sText, FG, direction ) );
} else {
for( char &it : sText ) {
const std::string generic_id = get_ascii_tile_id( it, FG, -1 );
if( tileset_ptr->find_tile_type( generic_id ) ) {
draw_from_id_string( generic_id, TILE_CATEGORY::NONE, empty_string,
iD + tripoint( iOffset, player_pos.z ),
0, 0, lit_level::LIT, false );
}
if( is_isometric() ) {
iOffset.y++;
}
iOffset.x++;
}
}
}
}
}
void cata_tiles::draw_zones_frame()
{
tripoint player_pos = get_player_character().pos();
for( int iY = zone_start.y; iY <= zone_end.y; ++ iY ) {
for( int iX = zone_start.x; iX <= zone_end.x; ++iX ) {
draw_from_id_string( "highlight", TILE_CATEGORY::NONE, empty_string,
zone_offset.xy() + tripoint( iX, iY, player_pos.z ),
0, 0, lit_level::LIT, false );
}
}
}
void cata_tiles::draw_async_anim()
{
// game::draw_async_anim can be called multiple times, storing each animation to be played in async_anim_layer
// Iterate through every tripoint-tileid pair in async_anim_layer
for( const auto &anim : async_anim_layer ) {
const tripoint p = anim.first;
const std::string tile_id = anim.second;
// Only draw if sprite found
if( find_tile_looks_like( tile_id, TILE_CATEGORY::NONE, "" ) ) {
draw_from_id_string( tile_id, p, 0, 0, lit_level::LIT, nv_goggles_activated );
}
}
}
void cata_tiles::draw_footsteps_frame( const tripoint ¢er )
{
static const std::string id_footstep = "footstep";
static const std::string id_footstep_above = "footstep_above";
static const std::string id_footstep_below = "footstep_below";
const tile_type *tl_above = tileset_ptr->find_tile_type( id_footstep_above );
const tile_type *tl_below = tileset_ptr->find_tile_type( id_footstep_below );
for( const tripoint &pos : sounds::get_footstep_markers() ) {
if( pos.z > center.z && tl_above ) {
draw_from_id_string( id_footstep_above, pos, 0, 0, lit_level::LIT, false );
} else if( pos.z < center.z && tl_below ) {
draw_from_id_string( id_footstep_below, pos, 0, 0, lit_level::LIT, false );
} else {
draw_from_id_string( id_footstep, pos, 0, 0, lit_level::LIT, false );
}
}
}
/* END OF ANIMATION FUNCTIONS */
void cata_tiles::tile_loading_report_dups()
{
std::vector<std::string> dups_list;
const std::unordered_set<std::string> &dups_set = tileset_ptr->get_duplicate_ids();
std::copy( dups_set.begin(), dups_set.end(), std::back_inserter( dups_list ) );
// NOLINTNEXTLINE(cata-use-localized-sorting)
std::sort( dups_list.begin(), dups_list.end() );
std::string res;
for( const std::string &s : dups_list ) {
res += s;
res += " ";
}
DebugLog( D_INFO, DC_ALL ) << "Have duplicates: " << res;
}
void cata_tiles::init_light()
{
g->reset_light_level();
}
void cata_tiles::get_terrain_orientation( const tripoint &p, int &rota, int &subtile,
const std::map<tripoint, ter_id> &ter_override, const std::array<bool, 5> &invisible,
const std::bitset<NUM_TERCONN> &rotate_group )
{
map &here = get_map();
const bool overridden = ter_override.find( p ) != ter_override.end();
const auto ter = [&]( const tripoint & q, const bool invis ) -> ter_id {
const auto override = ter_override.find( q );
return override != ter_override.end() ? override->second :
( !overridden || !invis ) ? here.ter( q ) : t_null;
};
// get terrain at x,y
const ter_id tid = ter( p, invisible[0] );
if( tid == t_null ) {
subtile = 0;
rota = 0;
return;
}
// get terrain neighborhood
const std::array<ter_id, 4> neighborhood = {
ter( p + point_south, invisible[1] ),
ter( p + point_east, invisible[2] ),
ter( p + point_west, invisible[3] ),
ter( p + point_north, invisible[4] )
};
char val = 0;
// populate connection information
for( int i = 0; i < 4; ++i ) {
if( neighborhood[i] == tid ) {
val += 1 << i;
}
}
uint8_t rotation_targets = get_map().get_known_rotates_to( p, rotate_group, {} );
get_rotation_and_subtile( val, rotation_targets, rota, subtile );
}
void cata_tiles::get_rotation_and_subtile( const char val, const char rot_to, int &rotation,
int &subtile )
{
const bool no_rotation = rot_to == CHAR_MAX;
switch( val ) {
// no connections
case 0:
subtile = unconnected;
if( no_rotation ) {
rotation = 0;
break;
}
rotation = get_rotation_unconnected( rot_to );
break;
// all connections
case 15:
subtile = center;
rotation = 0;
break;
// end pieces
// rotations:
//
// --> edge index
// Nw, Ws, Sw, Es,
// Ne, Wn, Se, En, |
// N+, W+, S+, E+, V get_rotation_... return index
// N-, W-, S-, E-
//
// (Nw = north end piece, rotated to west)
case 8:
// vertical end piece S
subtile = end_piece;
if( no_rotation ) {
rotation = 2;
break;
}
rotation = 2 + 4 * get_rotation_edge_ns( rot_to );
break;
case 4:
// horizontal end piece E
subtile = end_piece;
if( no_rotation ) {
rotation = 3;
break;
}
rotation = 3 + 4 * get_rotation_edge_ew( rot_to );
break;
case 2:
// horizontal end piece W
subtile = end_piece;
if( no_rotation ) {
rotation = 1;
break;
}
rotation = 1 + 4 * get_rotation_edge_ew( rot_to );
break;
case 1:
// vertical end piece N
subtile = end_piece;
if( no_rotation ) {
rotation = 0;
break;
}
rotation = 4 * get_rotation_edge_ns( rot_to );
break;
// edges
// rotations:
//
// --> edge index
// NSw, EWs,
// NSe, EWn, |
// NS+, EW+, V get_rotation_... return index
// NS-, EW-,
//
// (NSw = north-south edge, rotated to west)
case 9:
// vertical edge
subtile = edge;
if( no_rotation ) {
rotation = 0;
break;
}
rotation = 2 * get_rotation_edge_ns( rot_to );
break;
case 6:
// horizontal edge
subtile = edge;
if( no_rotation ) {
rotation = 1;
break;
}
rotation = 1 + 2 * get_rotation_edge_ew( rot_to );
break;
// corners
case 12:
subtile = corner;
rotation = 2;
break;
case 10:
subtile = corner;
rotation = 1;
break;
case 3:
subtile = corner;
rotation = 0;
break;
case 5:
subtile = corner;
rotation = 3;
break;
// all t_connections
case 14:
subtile = t_connection;
rotation = 2;
break;
case 11:
subtile = t_connection;
rotation = 1;
break;
case 7:
subtile = t_connection;
rotation = 0;
break;
case 13:
subtile = t_connection;
rotation = 3;
break;
}
}
int cata_tiles::get_rotation_edge_ns( const char rot_to )
{
if( ( rot_to & static_cast<int>( NEIGHBOUR::EAST ) ) == static_cast<int>( NEIGHBOUR::EAST ) ) {
if( ( rot_to & static_cast<int>( NEIGHBOUR::WEST ) ) == static_cast<int>( NEIGHBOUR::WEST ) ) {
// EW
return 2;
} else {
// Ew
return 1;
}
} else { // east -
if( ( rot_to & static_cast<int>( NEIGHBOUR::WEST ) ) == static_cast<int>( NEIGHBOUR::WEST ) ) {
// eW
return 0;
} else {
// ew
return 3;
}
}
}
int cata_tiles::get_rotation_edge_ew( const char rot_to )
{
if( ( rot_to & static_cast<int>( NEIGHBOUR::NORTH ) ) == static_cast<int>( NEIGHBOUR::NORTH ) ) {
if( ( rot_to & static_cast<int>( NEIGHBOUR::SOUTH ) ) == static_cast<int>( NEIGHBOUR::SOUTH ) ) {
// NS
return 2;
} else {
// Ns
return 1;
}
} else { // north -
if( ( rot_to & static_cast<int>( NEIGHBOUR::SOUTH ) ) == static_cast<int>( NEIGHBOUR::SOUTH ) ) {
// nS
return 0;
} else {
// ns
return 3;
}
}
}
int cata_tiles::get_rotation_unconnected( const char rot_to )
{
int rotation = 0;
switch( rot_to ) {
// Catch no and all first for performance; these are the last sprites!
case 0: // NONE
rotation = 15;
break;
case 15: // ALL
rotation = 12;
break;
// Cases for single tile to rotate to -> easy
case static_cast<int>( NEIGHBOUR::NORTH ):
rotation = 2;
break;
case static_cast<int>( NEIGHBOUR::EAST ):
rotation = 3;
break;
case static_cast<int>( NEIGHBOUR::SOUTH ):
rotation = 0;
break;
case static_cast<int>( NEIGHBOUR::WEST ):
rotation = 1;
break;
// Two tiles, resulting in diagonal
case 10: // NE
rotation = 6;
break;
case 3: // SE
rotation = 7;
break;
case 5: // SW
rotation = 4;
break;
case 12: // NW
rotation = 5;
break;
// Cases for three tiles to rotate to -> easy
// Arranged to fallback / modulo to fitting index 0-4
case 14: // 3 but south --> modulo = north
rotation = 10;
break;
case 11: // 3 but west --> modulo = east
rotation = 11;
break;
case 7: // 3 but north --> modulo = south
rotation = 8;
break;
case 13: // 3 but east --> modulo = west
rotation = 9;
break;
// Two opposing tiles, (No tiles, all tiles; see first cases)
case 9: // N-S
rotation = 14;
break;
case 6: // E-W
rotation = 13;
break;
}
return rotation;
}
void cata_tiles::get_connect_values( const tripoint &p, int &subtile, int &rotation,
const std::bitset<NUM_TERCONN> &connect_group,
const std::bitset<NUM_TERCONN> &rotate_to_group,
const std::map<tripoint, ter_id> &ter_override )
{
uint8_t connections = get_map().get_known_connections( p, connect_group, ter_override );
uint8_t rotation_targets = get_map().get_known_rotates_to( p, rotate_to_group, ter_override );
get_rotation_and_subtile( connections, rotation_targets, rotation, subtile );
}
void cata_tiles::get_furn_connect_values( const tripoint &p, int &subtile, int &rotation,
const std::bitset<NUM_TERCONN> &connect_group, const std::bitset<NUM_TERCONN> &rotate_to_group,
const std::map<tripoint, furn_id> &furn_override )
{
uint8_t connections = get_map().get_known_connections_f( p, connect_group, furn_override );
uint8_t rotation_targets = get_map().get_known_rotates_to_f( p, rotate_to_group, {}, {} );
get_rotation_and_subtile( connections, rotation_targets, rotation, subtile );
}
void cata_tiles::get_tile_values( const int t, const std::array<int, 4> &tn, int &subtile,
int &rotation, const char rotation_targets )
{
std::array<bool, 4> connects;
char val = 0;
for( int i = 0; i < 4; ++i ) {
connects[i] = ( tn[i] == t );
if( connects[i] ) {
val += 1 << i;
}
}
get_rotation_and_subtile( val, rotation_targets, rotation, subtile );
}
void cata_tiles::get_tile_values_with_ter(
const tripoint &p, const int t, const std::array<int, 4> &tn, int &subtile, int &rotation,
const std::bitset<NUM_TERCONN> &rotate_to_group )
{
map &here = get_map();
uint8_t rotation_targets = get_map().get_known_rotates_to_f( p, rotate_to_group, {} );
//check if furniture should connect to itself
if( here.has_flag( ter_furn_flag::TFLAG_NO_SELF_CONNECT, p ) ||
here.has_flag( ter_furn_flag::TFLAG_ALIGN_WORKBENCH, p ) ) {
//if we don't ever connect to ourself just return unconnected to be used further
get_rotation_and_subtile( 0, rotation_targets, rotation, subtile );
} else {
//if we do connect to ourself (tables, counters etc.) calculate based on neighbours
get_tile_values( t, tn, subtile, rotation, rotation_targets );
}
// calculate rotation for unconnected tiles based on surrounding walls
// if not any rotates_to neighbours
if( subtile == unconnected && ( rotation_targets == 0 || rotation_targets == CHAR_MAX ) ) {
int val = 0;
bool use_furniture = false;
if( here.has_flag( ter_furn_flag::TFLAG_ALIGN_WORKBENCH, p ) ) {
for( int i = 0; i < 4; ++i ) {
// align to furniture that has the workbench quality
const tripoint &pt = p + four_adjacent_offsets[i];
if( here.has_furn( pt ) && here.furn( pt ).obj().workbench ) {
val += 1 << i;
use_furniture = true;
}
}
}
// if still unaligned, try aligning to walls
if( val == 0 ) {
for( int i = 0; i < 4; ++i ) {
const tripoint &pt = p + four_adjacent_offsets[i];
if( here.has_flag( ter_furn_flag::TFLAG_WALL, pt ) ||
here.has_flag( ter_furn_flag::TFLAG_WINDOW, pt ) ||
here.has_flag( ter_furn_flag::TFLAG_DOOR, pt ) ) {
val += 1 << i;
}
}
}
switch( val ) {
case 4: // south wall
case 14: // north opening T
rotation = 2;
break;
case 2: // east wall
case 6: // southeast corner
case 5: // E/W corridor
case 7: // east opening T
rotation = 1;
break;
case 8: // west wall
case 12: // southwest corner
case 13: // west opening T
rotation = 3;
break;
case 0: // no walls
case 1: // north wall
case 3: // northeast corner
case 9: // northwest corner
case 10: // N/S corridor
case 11: // south opening T
case 15: // surrounded
default: // just in case
rotation = rotate_to_group.none() ? 0 : 15;
break;
}
//
if( use_furniture ) {
rotation = ( rotation + 2 ) % 4;
}
}
}
void cata_tiles::do_tile_loading_report()
{
DebugLog( D_INFO, DC_ALL ) << "Loaded tileset: " << get_option<std::string>( "TILES" );
if( !g->is_core_data_loaded() ) {
// There's nothing to do anymore without the core data.
return;
}
tile_loading_report_seq_types( vehicles::parts::get_all(), TILE_CATEGORY::VEHICLE_PART, "vp_" );
tile_loading_report_count<ter_t>( ter_t::count(), TILE_CATEGORY::TERRAIN );
std::map<itype_id, const itype *> items;
for( const itype *e : item_controller->all() ) {
items.emplace( e->get_id(), e );
}
tile_loading_report_map( items, TILE_CATEGORY::ITEM );
tile_loading_report_count<furn_t>( furn_t::count(), TILE_CATEGORY::FURNITURE );
tile_loading_report_count<trap>( trap::count(), TILE_CATEGORY::TRAP );
tile_loading_report_count<field_type>( field_type::count(), TILE_CATEGORY::FIELD );
// TODO: LIGHTING
tile_loading_report_seq_types( MonsterGenerator::generator().get_all_mtypes(),
TILE_CATEGORY::MONSTER );
// TODO: BULLET
// TODO: HIT_ENTITY
// TODO: WEATHER
std::vector<oter_type_str_id> oter_types;
for( const oter_t &oter : overmap_terrains::get_all() ) {
oter_types.push_back( oter.get_type_id() );
}
std::sort( oter_types.begin(), oter_types.end() );
oter_types.erase( std::unique( oter_types.begin(), oter_types.end() ), oter_types.end() );
tile_loading_report_seq_ids( oter_types, TILE_CATEGORY::OVERMAP_TERRAIN );
std::vector<map_extra_id> map_extra_ids = MapExtras::get_all_function_names();
map_extra_ids.erase(
std::remove_if( map_extra_ids.begin(), map_extra_ids.end(),
[]( const map_extra_id & id ) {
return !id->autonote;
} ), map_extra_ids.end() );
tile_loading_report_seq_ids( map_extra_ids, TILE_CATEGORY::MAP_EXTRA );
// TODO: OVERMAP_NOTE
static_assert( static_cast<int>( TILE_CATEGORY::last ) == 15,
"If you add more tile categories then update this tile loading report and then "
"increment the value in this static_assert accordingly" );
tile_loading_report_dups();
// needed until DebugLog ostream::flush bugfix lands
DebugLog( D_INFO, DC_ALL );
}
template<typename Iter, typename Func>
void cata_tiles::lr_generic( Iter begin, Iter end, Func id_func, TILE_CATEGORY category,
const std::string &prefix )
{
std::string missing_list;
std::string missing_with_looks_like_list;
for( ; begin != end; ++begin ) {
const std::string id_string = id_func( begin );
if( !tileset_ptr->find_tile_type( prefix + id_string ) &&
!find_tile_looks_like( id_string, category, "" ) ) {
missing_list.append( id_string + " " );
} else if( !tileset_ptr->find_tile_type( prefix + id_string ) ) {
missing_with_looks_like_list.append( id_string + " " );
}
}
const std::string &category_name = TILE_CATEGORY_IDS[static_cast<size_t>( category )];
DebugLog( D_INFO, DC_ALL ) << "Missing " << category_name << ": " << missing_list;
DebugLog( D_INFO, DC_ALL ) << "Missing " << category_name <<
" (but looks_like tile exists): " << missing_with_looks_like_list;
}
template <typename maptype>
void cata_tiles::tile_loading_report_map( const maptype &tiletypemap, TILE_CATEGORY category,
const std::string &prefix )
{
lr_generic( tiletypemap.begin(), tiletypemap.end(),
[]( const decltype( tiletypemap.begin() ) & v ) {
// c_str works for std::string and for string_id!
return v->first.c_str();
}, category, prefix );
}
template <typename Sequence>
void cata_tiles::tile_loading_report_seq_types( const Sequence &tiletypes, TILE_CATEGORY category,
const std::string &prefix )
{
lr_generic( tiletypes.begin(), tiletypes.end(),
[]( const decltype( tiletypes.begin() ) & v ) {
return v->id.c_str();
}, category, prefix );
}
template <typename Sequence>
void cata_tiles::tile_loading_report_seq_ids( const Sequence &tiletypes, TILE_CATEGORY category,
const std::string &prefix )
{
lr_generic( tiletypes.begin(), tiletypes.end(),
[]( const decltype( tiletypes.begin() ) & v ) {
// c_str works for std::string and for string_id!
return v->c_str();
}, category, prefix );
}
template <typename base_type>
void cata_tiles::tile_loading_report_count( const size_t count, TILE_CATEGORY category,
const std::string &prefix )
{
lr_generic( static_cast<size_t>( 0 ), count,
[]( const size_t i ) {
return int_id<base_type>( i ).id().str();
}, category, prefix );
}
std::vector<options_manager::id_and_option> cata_tiles::build_renderer_list()
{
std::vector<options_manager::id_and_option> renderer_names;
std::vector<options_manager::id_and_option> default_renderer_names = {
# if defined(_WIN32)
{ "direct3d", to_translation( "direct3d" ) },
# endif
{ "software", to_translation( "software" ) },
{ "opengl", to_translation( "opengl" ) },
{ "opengles2", to_translation( "opengles2" ) },
};
int numRenderDrivers = SDL_GetNumRenderDrivers();
for( int ii = 0; ii < numRenderDrivers; ii++ ) {
SDL_RendererInfo ri;
SDL_GetRenderDriverInfo( ii, &ri );
// First default renderer name we will put first on the list. We can use it later as
// default value.
if( ri.name == default_renderer_names.front().first ) {
renderer_names.emplace( renderer_names.begin(), default_renderer_names.front() );
} else {
renderer_names.emplace_back( ri.name, no_translation( ri.name ) );
}
}
DebugLog( D_INFO, DC_ALL ) << "SDL render devices: " << enumerate_as_string( renderer_names,
[]( const options_manager::id_and_option & iao ) {
return iao.first;
}, enumeration_conjunction::none );
return renderer_names.empty() ? default_renderer_names : renderer_names;
}
std::vector<options_manager::id_and_option> cata_tiles::build_display_list()
{
std::vector<options_manager::id_and_option> display_names;
std::vector<options_manager::id_and_option> default_display_names = {
{ "0", to_translation( "Display 0" ) }
};
int numdisplays = SDL_GetNumVideoDisplays();
display_names.reserve( numdisplays );
for( int i = 0 ; i < numdisplays ; i++ ) {
display_names.emplace_back( std::to_string( i ),
no_translation( SDL_GetDisplayName( i ) ) );
}
return display_names.empty() ? default_display_names : display_names;
}
#endif // SDL_TILES
|