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
|
/* SCCS Id: @(#)makedefs.c 3.4 2002/08/14 */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/* Copyright (c) M. Stephenson, 1990, 1991. */
/* Copyright (c) Dean Luick, 1990. */
/* NetHack may be freely redistributed. See license for details. */
#define MAKEDEFS_C /* use to conditionally include file sections */
/* #define DEBUG */ /* uncomment for debugging info */
#include "config.h"
#include "permonst.h"
#include "objclass.h"
#include "monsym.h"
#include "artilist.h"
#include "dungeon.h"
#include "obj.h"
#include "monst.h"
#include "you.h"
#include "flag.h"
#include "dlb.h"
/* version information */
#ifdef SHORT_FILENAMES
#include "patchlev.h"
#else
#include "patchlevel.h"
#endif
#ifdef MAC
# if defined(__SC__) || defined(__MRC__) /* MPW compilers */
# define MPWTOOL
#include <CursorCtl.h>
#include <string.h>
#include <ctype.h>
# else /* MAC without MPWTOOL */
# define MACsansMPWTOOL
# endif
#endif /* MAC */
#ifndef MPWTOOL
# define SpinCursor(x)
#endif
#if defined(GL_GRAPHICS) || defined(SDL_GRAPHICS)
#include "winGL.h" /* get glHack version */
#endif
#define Fprintf (void) fprintf
#define Fclose (void) fclose
#define Unlink (void) unlink
#if !defined(AMIGA) || defined(AZTEC_C)
#define rewind(fp) fseek((fp),0L,SEEK_SET) /* guarantee a return value */
#endif
#if defined(UNIX) && !defined(LINT) && !defined(GCC_WARN)
static const char SCCS_Id[] = "@(#)makedefs.c\t3.4\t2002/02/03";
#endif
/* names of files to be generated */
#define DATE_FILE "date.h"
#define MONST_FILE "pm.h"
#define ONAME_FILE "onames.h"
#ifndef OPTIONS_FILE
#define OPTIONS_FILE "options"
#endif
#define ORACLE_FILE "oracles"
#define DATA_FILE "data"
#define RUMOR_FILE "rumors"
#define DGN_I_FILE "dungeon.def"
#define DGN_O_FILE "dungeon.pdf"
#define MON_STR_C "monstr.c"
#define QTXT_I_FILE "quest.txt"
#define QTXT_O_FILE "quest.dat"
#define VIS_TAB_H "vis_tab.h"
#define VIS_TAB_C "vis_tab.c"
/* locations for those files */
#ifdef AMIGA
# define FILE_PREFIX
# define INCLUDE_TEMPLATE "NH:include/t.%s"
# define SOURCE_TEMPLATE "NH:src/%s"
# define DGN_TEMPLATE "NH:dat/%s" /* where dungeon.pdf file goes */
# define DATA_TEMPLATE "NH:slib/%s"
# define DATA_IN_TEMPLATE "NH:dat/%s"
#else /* not AMIGA */
# if defined(MAC) && !defined(__MACH__)
/* MacOS 9 or earlier */
# define INCLUDE_TEMPLATE ":include:%s"
# define SOURCE_TEMPLATE ":src:%s"
# define DGN_TEMPLATE ":dat:%s" /* where dungeon.pdf file goes */
# if __SC__ || __MRC__
# define DATA_TEMPLATE ":Dungeon:%s"
# else
# define DATA_TEMPLATE ":lib:%s"
# endif /* __SC__ || __MRC__ */
# define DATA_IN_TEMPLATE ":dat:%s"
# else /* neither AMIGA nor MAC */
# ifdef OS2
# define INCLUDE_TEMPLATE "..\\include\\%s"
# define SOURCE_TEMPLATE "..\\src\\%s"
# define DGN_TEMPLATE "..\\dat\\%s" /* where dungeon.pdf file goes */
# define DATA_TEMPLATE "..\\dat\\%s"
# define DATA_IN_TEMPLATE "..\\dat\\%s"
# else /* not AMIGA, MAC, or OS2 */
# define INCLUDE_TEMPLATE "../include/%s"
# define SOURCE_TEMPLATE "../src/%s"
# define DGN_TEMPLATE "../dat/%s" /* where dungeon.pdf file goes */
# define DATA_TEMPLATE "../dat/%s"
# define DATA_IN_TEMPLATE "../dat/%s"
# endif /* else !OS2 */
# endif /* else !MAC */
#endif /* else !AMIGA */
static const char
*Dont_Edit_Code =
"/* This source file is generated by 'makedefs'. Do not edit. */\n",
*Dont_Edit_Data =
"#\tThis data file is generated by 'makedefs'. Do not edit. \n";
static struct version_info version;
/* definitions used for vision tables */
#define TEST_WIDTH COLNO
#define TEST_HEIGHT ROWNO
#define BLOCK_WIDTH (TEST_WIDTH + 10)
#define BLOCK_HEIGHT TEST_HEIGHT /* don't need extra spaces */
#define MAX_ROW (BLOCK_HEIGHT + TEST_HEIGHT)
#define MAX_COL (BLOCK_WIDTH + TEST_WIDTH)
/* Use this as an out-of-bound value in the close table. */
#define CLOSE_OFF_TABLE_STRING "99" /* for the close table */
#define FAR_OFF_TABLE_STRING "0xff" /* for the far table */
#define sign(z) ((z) < 0 ? -1 : ((z) ? 1 : 0))
#ifdef VISION_TABLES
static char xclear[MAX_ROW][MAX_COL];
#endif
/*-end of vision defs-*/
static char in_line[256], filename[60];
#ifdef FILE_PREFIX
/* if defined, a first argument not starting with - is
* taken as a text string to be prepended to any
* output filename generated */
char *file_prefix="";
#endif
#ifdef MACsansMPWTOOL
int FDECL(main, (void));
#else
int FDECL(main, (int,char **));
#endif
void FDECL(do_makedefs, (char *));
void NDECL(do_objs);
void NDECL(do_data);
void NDECL(do_dungeon);
void NDECL(do_date);
void NDECL(do_options);
void NDECL(do_monstr);
void NDECL(do_permonst);
void NDECL(do_questtxt);
void NDECL(do_rumors);
void NDECL(do_oracles);
void NDECL(do_vision);
extern void NDECL(monst_init); /* monst.c */
extern void NDECL(objects_init); /* objects.c */
static void NDECL(make_version);
static char *FDECL(version_string, (char *));
static char *FDECL(version_id_string, (char *));
static char *FDECL(xcrypt, (const char *));
static int FDECL(check_control, (char *));
static char *FDECL(without_control, (char *));
static boolean FDECL(d_filter, (char *));
static boolean FDECL(h_filter, (char *));
static boolean FDECL(ranged_attk,(struct permonst*));
static int FDECL(mstrength,(struct permonst *));
static void NDECL(build_savebones_compat_string);
static boolean FDECL(qt_comment, (char *));
static boolean FDECL(qt_control, (char *));
static int FDECL(get_hdr, (char *));
static boolean FDECL(new_id, (char *));
static boolean FDECL(known_msg, (int,int));
static void FDECL(new_msg, (char *,int,int));
static void FDECL(do_qt_control, (char *));
static void FDECL(do_qt_text, (char *));
static void NDECL(adjust_qt_hdrs);
static void NDECL(put_qt_hdrs);
#ifdef VISION_TABLES
static void NDECL(H_close_gen);
static void NDECL(H_far_gen);
static void NDECL(C_close_gen);
static void NDECL(C_far_gen);
static int FDECL(clear_path, (int,int,int,int));
#endif
static char *FDECL(tmpdup, (const char *));
static char *FDECL(limit, (char *,int));
static char *FDECL(eos, (char *));
/* input, output, tmp */
static FILE *ifp, *ofp, *tfp;
#if defined(__BORLANDC__) && !defined(_WIN32)
extern unsigned _stklen = STKSIZ;
#endif
#ifdef MACsansMPWTOOL
int
main(void)
{
const char *def_options = "odemvpqrhz";
char buf[100];
int len;
printf("Enter options to run: [%s] ", def_options);
fflush(stdout);
fgets(buf, 100, stdin);
len = strlen(buf);
if (len <= 1)
Strcpy(buf, def_options);
else
buf[len-1] = 0; /* remove return */
do_makedefs(buf);
exit(EXIT_SUCCESS);
return 0;
}
#else /* ! MAC */
int
main(argc, argv)
int argc;
char *argv[];
{
if ( (argc != 2)
#ifdef FILE_PREFIX
&& (argc != 3)
#endif
) {
Fprintf(stderr, "Bad arg count (%d).\n", argc-1);
(void) fflush(stderr);
return 1;
}
#ifdef FILE_PREFIX
if(argc >=2 && argv[1][0]!='-'){
file_prefix=argv[1];
argc--;argv++;
}
#endif
do_makedefs(&argv[1][1]);
exit(EXIT_SUCCESS);
/*NOTREACHED*/
return 0;
}
#endif
void
do_makedefs(options)
char *options;
{
boolean more_than_one;
/* Note: these initializers don't do anything except guarantee that
we're linked properly.
*/
monst_init();
objects_init();
/* construct the current version number */
make_version();
more_than_one = strlen(options) > 1;
while (*options) {
if (more_than_one)
Fprintf(stderr, "makedefs -%c\n", *options);
switch (*options) {
case 'o':
case 'O': do_objs();
break;
case 'd':
case 'D': do_data();
break;
case 'e':
case 'E': do_dungeon();
break;
case 'm':
case 'M': do_monstr();
break;
case 'v':
case 'V': do_date();
do_options();
break;
case 'p':
case 'P': do_permonst();
break;
case 'q':
case 'Q': do_questtxt();
break;
case 'r':
case 'R': do_rumors();
break;
case 'h':
case 'H': do_oracles();
break;
case 'z':
case 'Z': do_vision();
break;
default: Fprintf(stderr, "Unknown option '%c'.\n",
*options);
(void) fflush(stderr);
exit(EXIT_FAILURE);
}
options++;
}
if (more_than_one) Fprintf(stderr, "Completed.\n"); /* feedback */
}
/* trivial text encryption routine which can't be broken with `tr' */
static
char *xcrypt(str)
const char *str;
{ /* duplicated in src/hacklib.c */
static char buf[BUFSZ];
register const char *p;
register char *q;
register int bitmask;
for (bitmask = 1, p = str, q = buf; *p; q++) {
*q = *p++;
if (*q & (32|64)) *q ^= bitmask;
if ((bitmask <<= 1) >= 32) bitmask = 1;
}
*q = '\0';
return buf;
}
void
do_rumors()
{
char infile[60];
long true_rumor_size;
filename[0]='\0';
#ifdef FILE_PREFIX
Strcat(filename,file_prefix);
#endif
Sprintf(eos(filename), DATA_TEMPLATE, RUMOR_FILE);
if (!(ofp = fopen(filename, WRTMODE))) {
perror(filename);
exit(EXIT_FAILURE);
}
Fprintf(ofp,"%s",Dont_Edit_Data);
Sprintf(infile, DATA_IN_TEMPLATE, RUMOR_FILE);
Strcat(infile, ".tru");
if (!(ifp = fopen(infile, RDTMODE))) {
perror(infile);
Fclose(ofp);
Unlink(filename); /* kill empty output file */
exit(EXIT_FAILURE);
}
/* get size of true rumors file */
#ifndef VMS
(void) fseek(ifp, 0L, SEEK_END);
true_rumor_size = ftell(ifp);
#else
/* seek+tell is only valid for stream format files; since rumors.%%%
might be in record format, count the actual data bytes instead.
*/
true_rumor_size = 0;
while (fgets(in_line, sizeof in_line, ifp) != 0)
true_rumor_size += strlen(in_line); /* includes newline */
#endif /* VMS */
Fprintf(ofp,"%06lx\n", true_rumor_size);
(void) fseek(ifp, 0L, SEEK_SET);
/* copy true rumors */
while (fgets(in_line, sizeof in_line, ifp) != 0)
(void) fputs(xcrypt(in_line), ofp);
Fclose(ifp);
Sprintf(infile, DATA_IN_TEMPLATE, RUMOR_FILE);
Strcat(infile, ".fal");
if (!(ifp = fopen(infile, RDTMODE))) {
perror(infile);
Fclose(ofp);
Unlink(filename); /* kill incomplete output file */
exit(EXIT_FAILURE);
}
/* copy false rumors */
while (fgets(in_line, sizeof in_line, ifp) != 0)
(void) fputs(xcrypt(in_line), ofp);
Fclose(ifp);
Fclose(ofp);
return;
}
/*
* 3.4.1: way back in 3.2.1 `flags.nap' became unconditional but
* TIMED_DELAY was erroneously left in VERSION_FEATURES and has
* been there up through 3.4.0. Simply removing it now would
* break save file compatibility with 3.4.0 files, so we will
* explicitly mask it out during version checks.
* This should go away in the next version update.
*/
#define IGNORED_FEATURES ( 0L \
| (1L << 23) /* TIMED_DELAY */ \
)
static void
make_version()
{
register int i;
/*
* integer version number
*/
version.incarnation = ((unsigned long)VERSION_MAJOR << 24) |
((unsigned long)VERSION_MINOR << 16) |
((unsigned long)PATCHLEVEL << 8) |
((unsigned long)EDITLEVEL);
/*
* encoded feature list
* Note: if any of these magic numbers are changed or reassigned,
* EDITLEVEL in patchlevel.h should be incremented at the same time.
* The actual values have no special meaning, and the category
* groupings are just for convenience.
*/
version.feature_set = (unsigned long)(0L
/* levels and/or topology (0..4) */
#ifdef REINCARNATION
| (1L << 1)
#endif
#ifdef SINKS
| (1L << 2)
#endif
/* monsters (5..9) */
#ifdef KOPS
| (1L << 6)
#endif
#ifdef MAIL
| (1L << 7)
#endif
/* objects (10..14) */
#ifdef TOURIST
| (1L << 10)
#endif
#ifdef STEED
| (1L << 11)
#endif
#ifdef GOLDOBJ
| (1L << 12)
#endif
/* flag bits and/or other global variables (15..26) */
#ifdef TEXTCOLOR
| (1L << 17)
#endif
#ifdef INSURANCE
| (1L << 18)
#endif
#ifdef ELBERETH
| (1L << 19)
#endif
#ifdef EXP_ON_BOTL
| (1L << 20)
#endif
#ifdef SCORE_ON_BOTL
| (1L << 21)
#endif
/* data format [COMPRESS excluded] (27..31) */
#ifdef ZEROCOMP
| (1L << 27)
#endif
#ifdef RLECOMP
| (1L << 28)
#endif
);
/*
* Value used for object & monster sanity check.
* (NROFARTIFACTS<<24) | (NUM_OBJECTS<<12) | (NUMMONS<<0)
*/
for (i = 1; artifact_names[i]; i++) continue;
version.entity_count = (unsigned long)(i - 1);
for (i = 1; objects[i].oc_class != ILLOBJ_CLASS; i++) continue;
version.entity_count = (version.entity_count << 12) | (unsigned long)i;
for (i = 0; mons[i].mlet; i++) continue;
version.entity_count = (version.entity_count << 12) | (unsigned long)i;
/*
* Value used for compiler (word size/field alignment/padding) check.
*/
version.struct_sizes = (((unsigned long)sizeof (struct flag) << 24) |
((unsigned long)sizeof (struct obj) << 17) |
((unsigned long)sizeof (struct monst) << 10) |
((unsigned long)sizeof (struct you)));
return;
}
static char *
version_string(outbuf)
char *outbuf;
{
Sprintf(outbuf, "%d.%d.%d", VERSION_MAJOR, VERSION_MINOR, PATCHLEVEL);
#ifdef BETA
Sprintf(eos(outbuf), "-%d", EDITLEVEL);
#endif
return outbuf;
}
static char *
version_id_string(outbuf)
char *outbuf;
{
char subbuf[64], versbuf[64];
subbuf[0] = '\0';
#ifdef PORT_SUB_ID
subbuf[0] = ' ';
Strcpy(&subbuf[1], PORT_SUB_ID);
#endif
#ifdef BETA
Strcat(subbuf, " Beta");
#endif
Sprintf(outbuf, "%s NetHack%s Version %s.",
PORT_ID, subbuf, version_string(versbuf));
return outbuf;
}
void
do_date()
{
long clocktim = 0;
char *c, cbuf[60], buf[BUFSZ];
const char *ul_sfx;
filename[0]='\0';
#ifdef FILE_PREFIX
Strcat(filename,file_prefix);
#endif
Sprintf(eos(filename), INCLUDE_TEMPLATE, DATE_FILE);
if (!(ofp = fopen(filename, WRTMODE))) {
perror(filename);
exit(EXIT_FAILURE);
}
Fprintf(ofp,"/*\tSCCS Id: @(#)date.h\t3.4\t2002/02/03 */\n\n");
Fprintf(ofp,"%s",Dont_Edit_Code);
#ifdef KR1ED
(void) time(&clocktim);
Strcpy(cbuf, ctime(&clocktim));
#else
(void) time((time_t *)&clocktim);
Strcpy(cbuf, ctime((time_t *)&clocktim));
#endif
for (c = cbuf; *c; c++) if (*c == '\n') break;
*c = '\0'; /* strip off the '\n' */
Fprintf(ofp,"\n");
#ifdef NHSTDC
ul_sfx = "UL";
#else
ul_sfx = "L";
#endif
Fprintf(ofp,"#define VERSION_NUMBER 0x%08lx%s\n",
version.incarnation, ul_sfx);
Fprintf(ofp,"#define VERSION_FEATURES 0x%08lx%s\n",
version.feature_set, ul_sfx);
#ifdef IGNORED_FEATURES
Fprintf(ofp,"#define IGNORED_FEATURES 0x%08lx%s\n",
(unsigned long) IGNORED_FEATURES, ul_sfx);
#endif
Fprintf(ofp,"#define VERSION_SANITY1 0x%08lx%s\n",
version.entity_count, ul_sfx);
Fprintf(ofp,"#define VERSION_SANITY2 0x%08lx%s\n",
version.struct_sizes, ul_sfx);
Fprintf(ofp,"\n");
Fprintf(ofp,"#define VERSION_STRING \"%s\"\n", version_string(buf));
Fprintf(ofp,"#define VERSION_ID \\\n \"%s\"\n",
version_id_string(buf));
Fprintf(ofp,"\n");
#ifdef AMIGA
{
struct tm *tm = localtime((time_t *) &clocktim);
Fprintf(ofp,"#define AMIGA_VERSION_STRING ");
Fprintf(ofp,"\"\\0$VER: NetHack %d.%d.%d (%d.%d.%d)\"\n",
VERSION_MAJOR, VERSION_MINOR, PATCHLEVEL,
tm->tm_mday, tm->tm_mon+1, tm->tm_year+1900);
}
#endif
Fclose(ofp);
return;
}
static char save_bones_compat_buf[BUFSZ];
static void
build_savebones_compat_string()
{
#ifdef VERSION_COMPATIBILITY
unsigned long uver = VERSION_COMPATIBILITY;
#endif
Strcpy(save_bones_compat_buf,
"save and bones files accepted from version");
#ifdef VERSION_COMPATIBILITY
Sprintf(eos(save_bones_compat_buf), "s %lu.%lu.%lu through %d.%d.%d",
((uver & 0xFF000000L) >> 24), ((uver & 0x00FF0000L) >> 16),
((uver & 0x0000FF00L) >> 8),
VERSION_MAJOR, VERSION_MINOR, PATCHLEVEL);
#else
Sprintf(eos(save_bones_compat_buf), " %d.%d.%d only",
VERSION_MAJOR, VERSION_MINOR, PATCHLEVEL);
#endif
}
static const char *build_opts[] = {
#ifdef AMIGA_WBENCH
"Amiga WorkBench support",
#endif
#ifdef ANSI_DEFAULT
"ANSI default terminal",
#endif
#ifdef AUTOPICKUP_EXCEPTIONS
"autopickup_exceptions",
#endif
#ifdef TEXTCOLOR
"color",
#endif
#ifdef COM_COMPL
"command line completion",
#endif
#ifdef COMPRESS
"data file compression",
#endif
#ifdef DLB
"data librarian",
#endif
#ifdef WIZARD
"debug mode",
#endif
#ifdef ELBERETH
"Elbereth",
#endif
#ifdef EXP_ON_BOTL
"experience points on status line",
#endif
#ifdef MFLOPPY
"floppy drive support",
#endif
#ifdef GOLDOBJ
"gold object in inventories",
#endif
#ifdef INSURANCE
"insurance files for recovering from crashes",
#endif
#ifdef KOPS
"Keystone Kops",
#endif
#ifdef HOLD_LOCKFILE_OPEN
"exclusive lock on level 0 file",
#endif
#ifdef LOGFILE
"log file",
#endif
#ifdef MAIL
"mail daemon",
#endif
#ifdef GNUDOS
"MSDOS protected mode",
#endif
#ifdef NEWS
"news file",
#endif
#ifdef OVERLAY
# ifdef MOVERLAY
"MOVE overlays",
# else
# ifdef VROOMM
"VROOMM overlays",
# else
"overlays",
# endif
# endif
#endif
#ifdef REDO
"redo command",
#endif
#ifdef REINCARNATION
"rogue level",
#endif
#ifdef STEED
"saddles and riding",
#endif
#ifdef SCORE_ON_BOTL
"score on status line",
#endif
#ifdef CLIPPING
"screen clipping",
#endif
#ifdef NO_TERMS
# ifdef MAC
"screen control via mactty",
# endif
# ifdef SCREEN_BIOS
"screen control via BIOS",
# endif
# ifdef SCREEN_DJGPPFAST
"screen control via DJGPP fast",
# endif
# ifdef SCREEN_VGA
"screen control via VGA graphics",
# endif
# ifndef MSWIN_GRAPHICS
# ifdef WIN32CON
"screen control via WIN32 console I/O",
# endif
# endif
#endif
#ifdef SEDUCE
"seduction",
#endif
#ifdef SHELL
"shell command",
#endif
#ifdef SINKS
"sinks",
#endif
#ifdef SUSPEND
"suspend command",
#endif
#ifdef TERMINFO
"terminal info library",
#else
# if defined(TERMLIB) || ((!defined(MICRO) && !defined(WIN32)) && defined(TTY_GRAPHICS))
"terminal capability library",
# endif
#endif
#ifdef TIMED_DELAY
"timed wait for display effects",
#endif
#ifdef TOURIST
"tourists",
#endif
#ifdef USER_SOUNDS
# ifdef USER_SOUNDS_REGEX
"user sounds via regular expressions",
# else
"user sounds via pmatch",
# endif
#endif
#ifdef PREFIXES_IN_USE
"variable playground",
#endif
#ifdef VISION_TABLES
"vision tables",
#endif
#ifdef WALLIFIED_MAZE
"walled mazes",
#endif
#ifdef ZEROCOMP
"zero-compressed save files",
#endif
save_bones_compat_buf,
"basic NetHack features"
};
static const char *window_opts[] = {
#ifdef TTY_GRAPHICS
"traditional tty-based graphics",
#endif
#ifdef X11_GRAPHICS
"X11",
#endif
#ifdef QT_GRAPHICS
"Qt",
#endif
#ifdef GNOME_GRAPHICS
"Gnome",
#endif
#ifdef GL_GRAPHICS
"GL",
#endif
#ifdef GL3D_GRAPHICS
"GL3D",
#endif
#ifdef SDL_GRAPHICS
"SDL",
#endif
#ifdef MAC
"Mac",
#endif
#ifdef AMIGA_INTUITION
"Amiga Intuition",
#endif
#ifdef GEM_GRAPHICS
"Gem",
#endif
#ifdef MSWIN_GRAPHICS
"mswin",
#endif
#ifdef BEOS_GRAPHICS
"BeOS InterfaceKit",
#endif
0
};
void
do_options()
{
register int i, length;
register const char *str, *indent = " ";
filename[0]='\0';
#ifdef FILE_PREFIX
Strcat(filename,file_prefix);
#endif
Sprintf(eos(filename), DATA_TEMPLATE, OPTIONS_FILE);
if (!(ofp = fopen(filename, WRTMODE))) {
perror(filename);
exit(EXIT_FAILURE);
}
/* AJA: This is for glHack only. Not needed if merged into main
* NetHack codebase.
*/
#if defined(GL_GRAPHICS) || defined(SDL_GRAPHICS)
Fprintf(ofp,
"\n glHack version %s\n", GLHACK_VER_STR);
#endif
build_savebones_compat_string();
Fprintf(ofp,
#ifdef BETA
"\n NetHack version %d.%d.%d [beta]\n",
#else
"\n NetHack version %d.%d.%d\n",
#endif
VERSION_MAJOR, VERSION_MINOR, PATCHLEVEL);
Fprintf(ofp,"\nOptions compiled into this edition:\n");
length = COLNO + 1; /* force 1st item onto new line */
for (i = 0; i < SIZE(build_opts); i++) {
str = build_opts[i];
if (length + strlen(str) > COLNO - 5)
Fprintf(ofp,"\n%s", indent), length = strlen(indent);
else
Fprintf(ofp," "), length++;
Fprintf(ofp,"%s", str), length += strlen(str);
Fprintf(ofp,(i < SIZE(build_opts) - 1) ? "," : "."), length++;
}
Fprintf(ofp,"\n\nSupported windowing systems:\n");
length = COLNO + 1; /* force 1st item onto new line */
for (i = 0; i < SIZE(window_opts) - 1; i++) {
str = window_opts[i];
if (length + strlen(str) > COLNO - 5)
Fprintf(ofp,"\n%s", indent), length = strlen(indent);
else
Fprintf(ofp," "), length++;
Fprintf(ofp,"%s", str), length += strlen(str);
Fprintf(ofp, ","), length++;
}
Fprintf(ofp, "\n%swith a default of %s.", indent, DEFAULT_WINDOW_SYS);
Fprintf(ofp,"\n\n");
Fclose(ofp);
return;
}
/* routine to decide whether to discard something from data.base */
static boolean
d_filter(line)
char *line;
{
if (*line == '#') return TRUE; /* ignore comment lines */
return FALSE;
}
/*
*
New format (v3.1) of 'data' file which allows much faster lookups [pr]
"do not edit" first record is a comment line
01234567 hexadecimal formatted offset to text area
name-a first name of interest
123,4 offset to name's text, and number of lines for it
name-b next name of interest
name-c multiple names which share same description also
456,7 share a single offset,count line
. sentinel to mark end of names
789,0 dummy record containing offset, count of EOF
text-a 4 lines of descriptive text for name-a
text-a at file position 0x01234567L + 123L
text-a
text-a
text-b/text-c 7 lines of text for names-b and -c
text-b/text-c at fseek(0x01234567L + 456L)
...
*
*/
void
do_data()
{
char infile[60], tempfile[60];
boolean ok;
long txt_offset;
int entry_cnt, line_cnt;
Sprintf(tempfile, DATA_TEMPLATE, "database.tmp");
filename[0]='\0';
#ifdef FILE_PREFIX
Strcat(filename,file_prefix);
#endif
Sprintf(eos(filename), DATA_TEMPLATE, DATA_FILE);
Sprintf(infile, DATA_IN_TEMPLATE, DATA_FILE);
Strcat(infile,
#ifdef SHORT_FILENAMES
".bas"
#else
".base"
#endif
);
if (!(ifp = fopen(infile, RDTMODE))) { /* data.base */
perror(infile);
exit(EXIT_FAILURE);
}
if (!(ofp = fopen(filename, WRTMODE))) { /* data */
perror(filename);
Fclose(ifp);
exit(EXIT_FAILURE);
}
if (!(tfp = fopen(tempfile, WRTMODE))) { /* database.tmp */
perror(tempfile);
Fclose(ifp);
Fclose(ofp);
Unlink(filename);
exit(EXIT_FAILURE);
}
/* output a dummy header record; we'll rewind and overwrite it later */
Fprintf(ofp, "%s%08lx\n", Dont_Edit_Data, 0L);
entry_cnt = line_cnt = 0;
/* read through the input file and split it into two sections */
while (fgets(in_line, sizeof in_line, ifp)) {
if (d_filter(in_line)) continue;
if (*in_line > ' ') { /* got an entry name */
/* first finish previous entry */
if (line_cnt) Fprintf(ofp, "%d\n", line_cnt), line_cnt = 0;
/* output the entry name */
(void) fputs(in_line, ofp);
entry_cnt++; /* update number of entries */
} else if (entry_cnt) { /* got some descriptive text */
/* update previous entry with current text offset */
if (!line_cnt) Fprintf(ofp, "%ld,", ftell(tfp));
/* save the text line in the scratch file */
(void) fputs(in_line, tfp);
line_cnt++; /* update line counter */
}
}
/* output an end marker and then record the current position */
if (line_cnt) Fprintf(ofp, "%d\n", line_cnt);
Fprintf(ofp, ".\n%ld,%d\n", ftell(tfp), 0);
txt_offset = ftell(ofp);
Fclose(ifp); /* all done with original input file */
/* reprocess the scratch file; 1st format an error msg, just in case */
Sprintf(in_line, "rewind of \"%s\"", tempfile);
if (rewind(tfp) != 0) goto dead_data;
/* copy all lines of text from the scratch file into the output file */
while (fgets(in_line, sizeof in_line, tfp))
(void) fputs(in_line, ofp);
/* finished with scratch file */
Fclose(tfp);
Unlink(tempfile); /* remove it */
/* update the first record of the output file; prepare error msg 1st */
Sprintf(in_line, "rewind of \"%s\"", filename);
ok = (rewind(ofp) == 0);
if (ok) {
Sprintf(in_line, "header rewrite of \"%s\"", filename);
ok = (fprintf(ofp, "%s%08lx\n", Dont_Edit_Data, txt_offset) >= 0);
}
if (!ok) {
dead_data: perror(in_line); /* report the problem */
/* close and kill the aborted output file, then give up */
Fclose(ofp);
Unlink(filename);
exit(EXIT_FAILURE);
}
/* all done */
Fclose(ofp);
return;
}
/* routine to decide whether to discard something from oracles.txt */
static boolean
h_filter(line)
char *line;
{
static boolean skip = FALSE;
char tag[sizeof in_line];
SpinCursor(3);
if (*line == '#') return TRUE; /* ignore comment lines */
if (sscanf(line, "----- %s", tag) == 1) {
skip = FALSE;
#ifndef SINKS
if (!strcmp(tag, "SINKS")) skip = TRUE;
#endif
#ifndef ELBERETH
if (!strcmp(tag, "ELBERETH")) skip = TRUE;
#endif
} else if (skip && !strncmp(line, "-----", 5))
skip = FALSE;
return skip;
}
static const char *special_oracle[] = {
"\"...it is rather disconcerting to be confronted with the",
"following theorem from [Baker, Gill, and Solovay, 1975].",
"",
"Theorem 7.18 There exist recursive languages A and B such that",
" (1) P(A) == NP(A), and",
" (2) P(B) != NP(B)",
"",
"This provides impressive evidence that the techniques that are",
"currently available will not suffice for proving that P != NP or ",
"that P == NP.\" [Garey and Johnson, p. 185.]"
};
/*
The oracle file consists of a "do not edit" comment, a decimal count N
and set of N+1 hexadecimal fseek offsets, followed by N multiple-line
records, separated by "---" lines. The first oracle is a special case.
The input data contains just those multi-line records, separated by
"-----" lines.
*/
void
do_oracles()
{
char infile[60], tempfile[60];
boolean in_oracle, ok;
long txt_offset, offset, fpos;
int oracle_cnt;
register int i;
Sprintf(tempfile, DATA_TEMPLATE, "oracles.tmp");
filename[0]='\0';
#ifdef FILE_PREFIX
Strcat(filename, file_prefix);
#endif
Sprintf(eos(filename), DATA_TEMPLATE, ORACLE_FILE);
Sprintf(infile, DATA_IN_TEMPLATE, ORACLE_FILE);
Strcat(infile, ".txt");
if (!(ifp = fopen(infile, RDTMODE))) {
perror(infile);
exit(EXIT_FAILURE);
}
if (!(ofp = fopen(filename, WRTMODE))) {
perror(filename);
Fclose(ifp);
exit(EXIT_FAILURE);
}
if (!(tfp = fopen(tempfile, WRTMODE))) { /* oracles.tmp */
perror(tempfile);
Fclose(ifp);
Fclose(ofp);
Unlink(filename);
exit(EXIT_FAILURE);
}
/* output a dummy header record; we'll rewind and overwrite it later */
Fprintf(ofp, "%s%5d\n", Dont_Edit_Data, 0);
/* handle special oracle; it must come first */
(void) fputs("---\n", tfp);
Fprintf(ofp, "%05lx\n", ftell(tfp)); /* start pos of special oracle */
for (i = 0; i < SIZE(special_oracle); i++) {
(void) fputs(xcrypt(special_oracle[i]), tfp);
(void) fputc('\n', tfp);
}
SpinCursor(3);
oracle_cnt = 1;
(void) fputs("---\n", tfp);
Fprintf(ofp, "%05lx\n", ftell(tfp)); /* start pos of first oracle */
in_oracle = FALSE;
while (fgets(in_line, sizeof in_line, ifp)) {
SpinCursor(3);
if (h_filter(in_line)) continue;
if (!strncmp(in_line, "-----", 5)) {
if (!in_oracle) continue;
in_oracle = FALSE;
oracle_cnt++;
(void) fputs("---\n", tfp);
Fprintf(ofp, "%05lx\n", ftell(tfp));
/* start pos of this oracle */
} else {
in_oracle = TRUE;
(void) fputs(xcrypt(in_line), tfp);
}
}
if (in_oracle) { /* need to terminate last oracle */
oracle_cnt++;
(void) fputs("---\n", tfp);
Fprintf(ofp, "%05lx\n", ftell(tfp)); /* eof position */
}
/* record the current position */
txt_offset = ftell(ofp);
Fclose(ifp); /* all done with original input file */
/* reprocess the scratch file; 1st format an error msg, just in case */
Sprintf(in_line, "rewind of \"%s\"", tempfile);
if (rewind(tfp) != 0) goto dead_data;
/* copy all lines of text from the scratch file into the output file */
while (fgets(in_line, sizeof in_line, tfp))
(void) fputs(in_line, ofp);
/* finished with scratch file */
Fclose(tfp);
Unlink(tempfile); /* remove it */
/* update the first record of the output file; prepare error msg 1st */
Sprintf(in_line, "rewind of \"%s\"", filename);
ok = (rewind(ofp) == 0);
if (ok) {
Sprintf(in_line, "header rewrite of \"%s\"", filename);
ok = (fprintf(ofp, "%s%5d\n", Dont_Edit_Data, oracle_cnt) >=0);
}
if (ok) {
Sprintf(in_line, "data rewrite of \"%s\"", filename);
for (i = 0; i <= oracle_cnt; i++) {
#ifndef VMS /* alpha/vms v1.0; this fflush seems to confuse ftell */
if (!(ok = (fflush(ofp) == 0))) break;
#endif
if (!(ok = (fpos = ftell(ofp)) >= 0)) break;
if (!(ok = (fseek(ofp, fpos, SEEK_SET) >= 0))) break;
if (!(ok = (fscanf(ofp, "%5lx", &offset) == 1))) break;
#ifdef MAC
# ifdef __MWERKS__
/*
MetroWerks CodeWarrior Pro 1's (AKA CW12) version of MSL
(ANSI C Libraries) needs this rewind or else the fprintf
stops working. This may also be true for CW11, but has
never been checked.
*/
rewind(ofp);
# endif
#endif
if (!(ok = (fseek(ofp, fpos, SEEK_SET) >= 0))) break;
if (!(ok = (fprintf(ofp, "%05lx\n", offset + txt_offset) >= 0)))
break;
}
}
if (!ok) {
dead_data: perror(in_line); /* report the problem */
/* close and kill the aborted output file, then give up */
Fclose(ofp);
Unlink(filename);
exit(EXIT_FAILURE);
}
/* all done */
Fclose(ofp);
return;
}
static struct deflist {
const char *defname;
boolean true_or_false;
} deflist[] = {
#ifdef REINCARNATION
{ "REINCARNATION", TRUE },
#else
{ "REINCARNATION", FALSE },
#endif
{ 0, 0 } };
static int
check_control(s)
char *s;
{
int i;
if(s[0] != '%') return(-1);
for(i = 0; deflist[i].defname; i++)
if(!strncmp(deflist[i].defname, s+1, strlen(deflist[i].defname)))
return(i);
return(-1);
}
static char *
without_control(s)
char *s;
{
return(s + 1 + strlen(deflist[check_control(in_line)].defname));
}
void
do_dungeon()
{
int rcnt = 0;
Sprintf(filename, DATA_IN_TEMPLATE, DGN_I_FILE);
if (!(ifp = fopen(filename, RDTMODE))) {
perror(filename);
exit(EXIT_FAILURE);
}
filename[0]='\0';
#ifdef FILE_PREFIX
Strcat(filename, file_prefix);
#endif
Sprintf(eos(filename), DGN_TEMPLATE, DGN_O_FILE);
if (!(ofp = fopen(filename, WRTMODE))) {
perror(filename);
exit(EXIT_FAILURE);
}
Fprintf(ofp,"%s",Dont_Edit_Data);
while (fgets(in_line, sizeof in_line, ifp) != 0) {
SpinCursor(3);
rcnt++;
if(in_line[0] == '#') continue; /* discard comments */
recheck:
if(in_line[0] == '%') {
int i = check_control(in_line);
if(i >= 0) {
if(!deflist[i].true_or_false) {
while (fgets(in_line, sizeof in_line, ifp) != 0)
if(check_control(in_line) != i) goto recheck;
} else
(void) fputs(without_control(in_line),ofp);
} else {
Fprintf(stderr, "Unknown control option '%s' in file %s at line %d.\n",
in_line, DGN_I_FILE, rcnt);
exit(EXIT_FAILURE);
}
} else
(void) fputs(in_line,ofp);
}
Fclose(ifp);
Fclose(ofp);
return;
}
static boolean
ranged_attk(ptr) /* returns TRUE if monster can attack at range */
register struct permonst *ptr;
{
register int i, j;
register int atk_mask = (1<<AT_BREA) | (1<<AT_SPIT) | (1<<AT_GAZE);
for(i = 0; i < NATTK; i++) {
if((j=ptr->mattk[i].aatyp) >= AT_WEAP || (atk_mask & (1<<j)))
return TRUE;
}
return(FALSE);
}
/* This routine is designed to return an integer value which represents
* an approximation of monster strength. It uses a similar method of
* determination as "experience()" to arrive at the strength.
*/
static int
mstrength(ptr)
struct permonst *ptr;
{
int i, tmp2, n, tmp = ptr->mlevel;
if(tmp > 49) /* special fixed hp monster */
tmp = 2*(tmp - 6) / 4;
/* For creation in groups */
n = (!!(ptr->geno & G_SGROUP));
n += (!!(ptr->geno & G_LGROUP)) << 1;
/* For ranged attacks */
if (ranged_attk(ptr)) n++;
/* For higher ac values */
n += (ptr->ac < 4);
n += (ptr->ac < 0);
/* For very fast monsters */
n += (ptr->mmove >= 18);
/* For each attack and "special" attack */
for(i = 0; i < NATTK; i++) {
tmp2 = ptr->mattk[i].aatyp;
n += (tmp2 > 0);
n += (tmp2 == AT_MAGC);
n += (tmp2 == AT_WEAP && (ptr->mflags2 & M2_STRONG));
}
/* For each "special" damage type */
for(i = 0; i < NATTK; i++) {
tmp2 = ptr->mattk[i].adtyp;
if ((tmp2 == AD_DRLI) || (tmp2 == AD_STON) || (tmp2 == AD_DRST)
|| (tmp2 == AD_DRDX) || (tmp2 == AD_DRCO) || (tmp2 == AD_WERE))
n += 2;
else if (strcmp(ptr->mname, "grid bug")) n += (tmp2 != AD_PHYS);
n += ((int) (ptr->mattk[i].damd * ptr->mattk[i].damn) > 23);
}
/* Leprechauns are special cases. They have many hit dice so they
can hit and are hard to kill, but they don't really do much damage. */
if (!strcmp(ptr->mname, "leprechaun")) n -= 2;
/* Finally, adjust the monster level 0 <= n <= 24 (approx.) */
if(n == 0) tmp--;
else if(n >= 6) tmp += ( n / 2 );
else tmp += ( n / 3 + 1);
return((tmp >= 0) ? tmp : 0);
}
void
do_monstr()
{
register struct permonst *ptr;
register int i, j;
/*
* create the source file, "monstr.c"
*/
filename[0]='\0';
#ifdef FILE_PREFIX
Strcat(filename, file_prefix);
#endif
Sprintf(eos(filename), SOURCE_TEMPLATE, MON_STR_C);
if (!(ofp = fopen(filename, WRTMODE))) {
perror(filename);
exit(EXIT_FAILURE);
}
Fprintf(ofp,"%s",Dont_Edit_Code);
Fprintf(ofp,"#include \"config.h\"\n");
Fprintf(ofp,"\nconst int monstr[] = {\n");
for (ptr = &mons[0], j = 0; ptr->mlet; ptr++) {
SpinCursor(3);
i = mstrength(ptr);
Fprintf(ofp,"%2d,%c", i, (++j & 15) ? ' ' : '\n');
}
/* might want to insert a final 0 entry here instead of just newline */
Fprintf(ofp,"%s};\n", (j & 15) ? "\n" : "");
Fprintf(ofp,"\nvoid NDECL(monstr_init);\n");
Fprintf(ofp,"\nvoid\n");
Fprintf(ofp,"monstr_init()\n");
Fprintf(ofp,"{\n");
Fprintf(ofp," return;\n");
Fprintf(ofp,"}\n");
Fprintf(ofp,"\n/*monstr.c*/\n");
Fclose(ofp);
return;
}
void
do_permonst()
{
int i;
char *c, *nam;
filename[0]='\0';
#ifdef FILE_PREFIX
Strcat(filename, file_prefix);
#endif
Sprintf(eos(filename), INCLUDE_TEMPLATE, MONST_FILE);
if (!(ofp = fopen(filename, WRTMODE))) {
perror(filename);
exit(EXIT_FAILURE);
}
Fprintf(ofp,"/*\tSCCS Id: @(#)pm.h\t3.4\t2002/02/03 */\n\n");
Fprintf(ofp,"%s",Dont_Edit_Code);
Fprintf(ofp,"#ifndef PM_H\n#define PM_H\n");
if (strcmp(mons[0].mname, "playermon") != 0)
Fprintf(ofp,"\n#define\tPM_PLAYERMON\t(-1)");
for (i = 0; mons[i].mlet; i++) {
SpinCursor(3);
Fprintf(ofp,"\n#define\tPM_");
if (mons[i].mlet == S_HUMAN &&
!strncmp(mons[i].mname, "were", 4))
Fprintf(ofp, "HUMAN_");
for (nam = c = tmpdup(mons[i].mname); *c; c++)
if (*c >= 'a' && *c <= 'z') *c -= (char)('a' - 'A');
else if (*c < 'A' || *c > 'Z') *c = '_';
Fprintf(ofp,"%s\t%d", nam, i);
}
Fprintf(ofp,"\n\n#define\tNUMMONS\t%d\n", i);
Fprintf(ofp,"\n#endif /* PM_H */\n");
Fclose(ofp);
return;
}
/* Start of Quest text file processing. */
#include "qtext.h"
static struct qthdr qt_hdr;
static struct msghdr msg_hdr[N_HDR];
static struct qtmsg *curr_msg;
static int qt_line;
static boolean in_msg;
#define NO_MSG 1 /* strlen of a null line returned by fgets() */
static boolean
qt_comment(s)
char *s;
{
if(s[0] == '#') return(TRUE);
return((boolean)(!in_msg && strlen(s) == NO_MSG));
}
static boolean
qt_control(s)
char *s;
{
return((boolean)(s[0] == '%' && (s[1] == 'C' || s[1] == 'E')));
}
static int
get_hdr (code)
char *code;
{
int i;
for(i = 0; i < qt_hdr.n_hdr; i++)
if(!strncmp(code, qt_hdr.id[i], LEN_HDR)) return (++i);
return(0);
}
static boolean
new_id (code)
char *code;
{
if(qt_hdr.n_hdr >= N_HDR) {
Fprintf(stderr, OUT_OF_HEADERS, qt_line);
return(FALSE);
}
strncpy(&qt_hdr.id[qt_hdr.n_hdr][0], code, LEN_HDR);
msg_hdr[qt_hdr.n_hdr].n_msg = 0;
qt_hdr.offset[qt_hdr.n_hdr++] = 0L;
return(TRUE);
}
static boolean
known_msg(num, id)
int num, id;
{
int i;
for(i = 0; i < msg_hdr[num].n_msg; i++)
if(msg_hdr[num].qt_msg[i].msgnum == id) return(TRUE);
return(FALSE);
}
static void
new_msg(s, num, id)
char *s;
int num, id;
{
struct qtmsg *qt_msg;
if(msg_hdr[num].n_msg >= N_MSG) {
Fprintf(stderr, OUT_OF_MESSAGES, qt_line);
} else {
qt_msg = &(msg_hdr[num].qt_msg[msg_hdr[num].n_msg++]);
qt_msg->msgnum = id;
qt_msg->delivery = s[2];
qt_msg->offset = qt_msg->size = 0L;
curr_msg = qt_msg;
}
}
static void
do_qt_control(s)
char *s;
{
char code[BUFSZ];
int num, id = 0;
switch(s[1]) {
case 'C': if(in_msg) {
Fprintf(stderr, CREC_IN_MSG, qt_line);
break;
} else {
in_msg = TRUE;
if (sscanf(&s[4], "%s %5d", code, &id) != 2) {
Fprintf(stderr, UNREC_CREC, qt_line);
break;
}
num = get_hdr(code);
if (!num && !new_id(code))
break;
num = get_hdr(code)-1;
if(known_msg(num, id))
Fprintf(stderr, DUP_MSG, qt_line);
else new_msg(s, num, id);
}
break;
case 'E': if(!in_msg) {
Fprintf(stderr, END_NOT_IN_MSG, qt_line);
break;
} else in_msg = FALSE;
break;
default: Fprintf(stderr, UNREC_CREC, qt_line);
break;
}
}
static void
do_qt_text(s)
char *s;
{
if (!in_msg) {
Fprintf(stderr, TEXT_NOT_IN_MSG, qt_line);
}
curr_msg->size += strlen(s);
return;
}
static void
adjust_qt_hdrs()
{
int i, j;
long count = 0L, hdr_offset = sizeof(int) +
(sizeof(char)*LEN_HDR + sizeof(long)) * qt_hdr.n_hdr;
for(i = 0; i < qt_hdr.n_hdr; i++) {
qt_hdr.offset[i] = hdr_offset;
hdr_offset += sizeof(int) + sizeof(struct qtmsg) * msg_hdr[i].n_msg;
}
for(i = 0; i < qt_hdr.n_hdr; i++)
for(j = 0; j < msg_hdr[i].n_msg; j++) {
msg_hdr[i].qt_msg[j].offset = hdr_offset + count;
count += msg_hdr[i].qt_msg[j].size;
}
return;
}
static void
put_qt_hdrs()
{
int i;
/*
* The main header record.
*/
#ifdef DEBUG
Fprintf(stderr, "%ld: header info.\n", ftell(ofp));
#endif
(void) fwrite((genericptr_t)&(qt_hdr.n_hdr), sizeof(int), 1, ofp);
(void) fwrite((genericptr_t)&(qt_hdr.id[0][0]), sizeof(char)*LEN_HDR,
qt_hdr.n_hdr, ofp);
(void) fwrite((genericptr_t)&(qt_hdr.offset[0]), sizeof(long),
qt_hdr.n_hdr, ofp);
#ifdef DEBUG
for(i = 0; i < qt_hdr.n_hdr; i++)
Fprintf(stderr, "%c @ %ld, ", qt_hdr.id[i], qt_hdr.offset[i]);
Fprintf(stderr, "\n");
#endif
/*
* The individual class headers.
*/
for(i = 0; i < qt_hdr.n_hdr; i++) {
#ifdef DEBUG
Fprintf(stderr, "%ld: %c header info.\n", ftell(ofp),
qt_hdr.id[i]);
#endif
(void) fwrite((genericptr_t)&(msg_hdr[i].n_msg), sizeof(int),
1, ofp);
(void) fwrite((genericptr_t)&(msg_hdr[i].qt_msg[0]),
sizeof(struct qtmsg), msg_hdr[i].n_msg, ofp);
#ifdef DEBUG
{ int j;
for(j = 0; j < msg_hdr[i].n_msg; j++)
Fprintf(stderr, "msg %d @ %ld (%ld)\n",
msg_hdr[i].qt_msg[j].msgnum,
msg_hdr[i].qt_msg[j].offset,
msg_hdr[i].qt_msg[j].size);
}
#endif
}
}
void
do_questtxt()
{
Sprintf(filename, DATA_IN_TEMPLATE, QTXT_I_FILE);
if(!(ifp = fopen(filename, RDTMODE))) {
perror(filename);
exit(EXIT_FAILURE);
}
filename[0]='\0';
#ifdef FILE_PREFIX
Strcat(filename, file_prefix);
#endif
Sprintf(eos(filename), DATA_TEMPLATE, QTXT_O_FILE);
if(!(ofp = fopen(filename, WRBMODE))) {
perror(filename);
Fclose(ifp);
exit(EXIT_FAILURE);
}
qt_hdr.n_hdr = 0;
qt_line = 0;
in_msg = FALSE;
while (fgets(in_line, 80, ifp) != 0) {
SpinCursor (3);
qt_line++;
if(qt_control(in_line)) do_qt_control(in_line);
else if(qt_comment(in_line)) continue;
else do_qt_text(in_line);
}
(void) rewind(ifp);
in_msg = FALSE;
adjust_qt_hdrs();
put_qt_hdrs();
while (fgets(in_line, 80, ifp) != 0) {
if(qt_control(in_line)) {
in_msg = (in_line[1] == 'C');
continue;
} else if(qt_comment(in_line)) continue;
#ifdef DEBUG
Fprintf(stderr, "%ld: %s", ftell(stdout), in_line);
#endif
(void) fputs(xcrypt(in_line), ofp);
}
Fclose(ifp);
Fclose(ofp);
return;
}
static char temp[32];
static char *
limit(name,pref) /* limit a name to 30 characters length */
char *name;
int pref;
{
(void) strncpy(temp, name, pref ? 26 : 30);
temp[pref ? 26 : 30] = 0;
return temp;
}
void
do_objs()
{
int i, sum = 0;
char *c, *objnam;
int nspell = 0;
int prefix = 0;
char class = '\0';
boolean sumerr = FALSE;
filename[0]='\0';
#ifdef FILE_PREFIX
Strcat(filename, file_prefix);
#endif
Sprintf(eos(filename), INCLUDE_TEMPLATE, ONAME_FILE);
if (!(ofp = fopen(filename, WRTMODE))) {
perror(filename);
exit(EXIT_FAILURE);
}
Fprintf(ofp,"/*\tSCCS Id: @(#)onames.h\t3.4\t2002/02/03 */\n\n");
Fprintf(ofp,"%s",Dont_Edit_Code);
Fprintf(ofp,"#ifndef ONAMES_H\n#define ONAMES_H\n\n");
for(i = 0; !i || objects[i].oc_class != ILLOBJ_CLASS; i++) {
SpinCursor(3);
objects[i].oc_name_idx = objects[i].oc_descr_idx = i; /* init */
if (!(objnam = tmpdup(OBJ_NAME(objects[i])))) continue;
/* make sure probabilities add up to 1000 */
if(objects[i].oc_class != class) {
if (sum && sum != 1000) {
Fprintf(stderr, "prob error for class %d (%d%%)",
class, sum);
(void) fflush(stderr);
sumerr = TRUE;
}
class = objects[i].oc_class;
sum = 0;
}
for (c = objnam; *c; c++)
if (*c >= 'a' && *c <= 'z') *c -= (char)('a' - 'A');
else if (*c < 'A' || *c > 'Z') *c = '_';
switch (class) {
case WAND_CLASS:
Fprintf(ofp,"#define\tWAN_"); prefix = 1; break;
case RING_CLASS:
Fprintf(ofp,"#define\tRIN_"); prefix = 1; break;
case POTION_CLASS:
Fprintf(ofp,"#define\tPOT_"); prefix = 1; break;
case SPBOOK_CLASS:
Fprintf(ofp,"#define\tSPE_"); prefix = 1; nspell++; break;
case SCROLL_CLASS:
Fprintf(ofp,"#define\tSCR_"); prefix = 1; break;
case AMULET_CLASS:
/* avoid trouble with stupid C preprocessors */
Fprintf(ofp,"#define\t");
if(objects[i].oc_material == PLASTIC) {
Fprintf(ofp,"FAKE_AMULET_OF_YENDOR\t%d\n", i);
prefix = -1;
break;
}
break;
case GEM_CLASS:
/* avoid trouble with stupid C preprocessors */
if(objects[i].oc_material == GLASS) {
Fprintf(ofp,"/* #define\t%s\t%d */\n",
objnam, i);
prefix = -1;
break;
}
default:
Fprintf(ofp,"#define\t");
}
if (prefix >= 0)
Fprintf(ofp,"%s\t%d\n", limit(objnam, prefix), i);
prefix = 0;
sum += objects[i].oc_prob;
}
/* check last set of probabilities */
if (sum && sum != 1000) {
Fprintf(stderr, "prob error for class %d (%d%%)", class, sum);
(void) fflush(stderr);
sumerr = TRUE;
}
Fprintf(ofp,"#define\tLAST_GEM\t(JADE)\n");
Fprintf(ofp,"#define\tMAXSPELL\t%d\n", nspell+1);
Fprintf(ofp,"#define\tNUM_OBJECTS\t%d\n", i);
Fprintf(ofp, "\n/* Artifacts (unique objects) */\n\n");
for (i = 1; artifact_names[i]; i++) {
SpinCursor(3);
for (c = objnam = tmpdup(artifact_names[i]); *c; c++)
if (*c >= 'a' && *c <= 'z') *c -= (char)('a' - 'A');
else if (*c < 'A' || *c > 'Z') *c = '_';
if (!strncmp(objnam, "THE_", 4))
objnam += 4;
#ifdef TOURIST
/* fudge _platinum_ YENDORIAN EXPRESS CARD */
if (!strncmp(objnam, "PLATINUM_", 9))
objnam += 9;
#endif
Fprintf(ofp,"#define\tART_%s\t%d\n", limit(objnam, 1), i);
}
Fprintf(ofp, "#define\tNROFARTIFACTS\t%d\n", i-1);
Fprintf(ofp,"\n#endif /* ONAMES_H */\n");
Fclose(ofp);
if (sumerr) exit(EXIT_FAILURE);
return;
}
static char *
tmpdup(str)
const char *str;
{
static char buf[128];
if (!str) return (char *)0;
(void)strncpy(buf, str, 127);
return buf;
}
static char *
eos(str)
char *str;
{
while (*str) str++;
return str;
}
/*
* macro used to control vision algorithms:
* VISION_TABLES => generate tables
*/
void
do_vision()
{
#ifdef VISION_TABLES
int i, j;
/* Everything is clear. xclear may be malloc'ed.
* Block the upper left corner (BLOCK_HEIGHTxBLOCK_WIDTH)
*/
for (i = 0; i < MAX_ROW; i++)
for (j = 0; j < MAX_COL; j++)
if (i < BLOCK_HEIGHT && j < BLOCK_WIDTH)
xclear[i][j] = '\000';
else
xclear[i][j] = '\001';
#endif /* VISION_TABLES */
SpinCursor(3);
/*
* create the include file, "vis_tab.h"
*/
filename[0]='\0';
#ifdef FILE_PREFIX
Strcat(filename, file_prefix);
#endif
Sprintf(filename, INCLUDE_TEMPLATE, VIS_TAB_H);
if (!(ofp = fopen(filename, WRTMODE))) {
perror(filename);
exit(EXIT_FAILURE);
}
Fprintf(ofp,"%s",Dont_Edit_Code);
Fprintf(ofp,"#ifdef VISION_TABLES\n");
#ifdef VISION_TABLES
H_close_gen();
H_far_gen();
#endif /* VISION_TABLES */
Fprintf(ofp,"\n#endif /* VISION_TABLES */\n");
Fclose(ofp);
SpinCursor(3);
/*
* create the source file, "vis_tab.c"
*/
filename[0]='\0';
#ifdef FILE_PREFIX
Strcat(filename, file_prefix);
#endif
Sprintf(filename, SOURCE_TEMPLATE, VIS_TAB_C);
if (!(ofp = fopen(filename, WRTMODE))) {
perror(filename);
Sprintf(filename, INCLUDE_TEMPLATE, VIS_TAB_H);
Unlink(filename);
exit(EXIT_FAILURE);
}
Fprintf(ofp,"%s",Dont_Edit_Code);
Fprintf(ofp,"#include \"config.h\"\n");
Fprintf(ofp,"#ifdef VISION_TABLES\n");
Fprintf(ofp,"#include \"vis_tab.h\"\n");
SpinCursor(3);
#ifdef VISION_TABLES
C_close_gen();
C_far_gen();
Fprintf(ofp,"\nvoid vis_tab_init() { return; }\n");
#endif /* VISION_TABLES */
SpinCursor(3);
Fprintf(ofp,"\n#endif /* VISION_TABLES */\n");
Fprintf(ofp,"\n/*vis_tab.c*/\n");
Fclose(ofp);
return;
}
#ifdef VISION_TABLES
/*-------------- vision tables --------------*\
*
* Generate the close and far tables. This is done by setting up a
* fake dungeon and moving our source to different positions relative
* to a block and finding the first/last visible position. The fake
* dungeon is all clear execpt for the upper left corner (BLOCK_HEIGHT
* by BLOCK_WIDTH) is blocked. Then we move the source around relative
* to the corner of the block. For each new position of the source
* we check positions on rows "kittycorner" from the source. We check
* positions until they are either in sight or out of sight (depends on
* which table we are generating). The picture below shows the setup
* for the generation of the close table. The generation of the far
* table would switch the quadrants of the '@' and the "Check rows
* here".
*
*
* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX,,,,,,,,, Check rows here ,,,,,,,,,,,,
* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXB,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
* ...............................
* ...............................
* .........@.....................
* ...............................
*
* Table generation figure (close_table). The 'X's are blocked points.
* The 'B' is a special blocked point. The '@' is the source. The ','s
* are the target area. The '.' are just open areas.
*
*
* Example usage of close_table[][][].
*
* The table is as follows:
*
* dy = |row of '@' - row of 'B'| - 1
* dx = |col of '@' - col of 'B'|
*
* The first indices are the deltas from the source '@' and the block 'B'.
* You must check for the value inside the abs value bars being zero. If
* so then the block is on the same row and you don't need to do a table
* lookup. The last value:
*
* dcy = |row of block - row to be checked|
*
* Is the value of the first visible spot on the check row from the
* block column. So
*
* first visible col = close_table[dy][dx][dcy] + col of 'B'
*
\*-------------- vision tables --------------*/
static void
H_close_gen()
{
Fprintf(ofp,"\n/* Close */\n");
Fprintf(ofp,"#define CLOSE_MAX_SB_DY %2d\t/* |src row - block row| - 1\t*/\n",
TEST_HEIGHT-1);
Fprintf(ofp,"#define CLOSE_MAX_SB_DX %2d\t/* |src col - block col|\t*/\n",
TEST_WIDTH);
Fprintf(ofp,"#define CLOSE_MAX_BC_DY %2d\t/* |block row - check row|\t*/\n",
TEST_HEIGHT);
Fprintf(ofp,"typedef struct {\n");
Fprintf(ofp," unsigned char close[CLOSE_MAX_SB_DX][CLOSE_MAX_BC_DY];\n");
Fprintf(ofp,"} close2d;\n");
Fprintf(ofp,"extern close2d close_table[CLOSE_MAX_SB_DY];\n");
return;
}
static void
H_far_gen()
{
Fprintf(ofp,"\n/* Far */\n");
Fprintf(ofp,"#define FAR_MAX_SB_DY %2d\t/* |src row - block row|\t*/\n",
TEST_HEIGHT);
Fprintf(ofp,"#define FAR_MAX_SB_DX %2d\t/* |src col - block col| - 1\t*/\n",
TEST_WIDTH-1);
Fprintf(ofp,"#define FAR_MAX_BC_DY %2d\t/* |block row - check row| - 1\t*/\n",
TEST_HEIGHT-1);
Fprintf(ofp,"typedef struct {\n");
Fprintf(ofp," unsigned char far_q[FAR_MAX_SB_DX][FAR_MAX_BC_DY];\n");
Fprintf(ofp,"} far2d;\n");
Fprintf(ofp,"extern far2d far_table[FAR_MAX_SB_DY];\n");
return;
}
static void
C_close_gen()
{
int i,dx,dy;
int src_row, src_col; /* source */
int block_row, block_col; /* block */
int this_row;
int no_more;
const char *delim;
block_row = BLOCK_HEIGHT-1;
block_col = BLOCK_WIDTH-1;
Fprintf(ofp,"\n#ifndef FAR_TABLE_ONLY\n");
Fprintf(ofp,"\nclose2d close_table[CLOSE_MAX_SB_DY] = {\n");
#ifndef no_vision_progress
Fprintf(stderr,"\nclose:");
#endif
for (dy = 1; dy < TEST_HEIGHT; dy++) {
src_row = block_row + dy;
Fprintf(ofp, "/* DY = %2d (- 1)*/\n {{\n", dy);
#ifndef no_vision_progress
Fprintf(stderr," %2d",dy), (void)fflush(stderr);
#endif
for (dx = 0; dx < TEST_WIDTH; dx++) {
src_col = block_col - dx;
Fprintf(ofp, " /*%2d*/ {", dx);
no_more = 0;
for (this_row = 0; this_row < TEST_HEIGHT; this_row++) {
delim = (this_row < TEST_HEIGHT - 1) ? "," : "";
if (no_more) {
Fprintf(ofp, "%s%s", CLOSE_OFF_TABLE_STRING, delim);
continue;
}
SpinCursor(3);
/* Find the first column that we can see. */
for (i = block_col+1; i < MAX_COL; i++) {
if (clear_path(src_row,src_col,block_row-this_row,i))
break;
}
if (i == MAX_COL) no_more = 1;
Fprintf(ofp, "%2d%s", i - block_col, delim);
}
Fprintf(ofp, "}%s", (dx < TEST_WIDTH - 1) ? ",\n" : "\n");
}
Fprintf(ofp," }},\n");
}
Fprintf(ofp,"}; /* close_table[] */\n"); /* closing brace for table */
Fprintf(ofp,"#endif /* !FAR_TABLE_ONLY */\n");
#ifndef no_vision_progress
Fprintf(stderr,"\n");
#endif
return;
}
static void
C_far_gen()
{
int i,dx,dy;
int src_row, src_col; /* source */
int block_row, block_col; /* block */
int this_row;
const char *delim;
block_row = BLOCK_HEIGHT-1;
block_col = BLOCK_WIDTH-1;
Fprintf(ofp,"\n#ifndef CLOSE_TABLE_ONLY\n");
Fprintf(ofp,"\nfar2d far_table[FAR_MAX_SB_DY] = {\n");
#ifndef no_vision_progress
Fprintf(stderr,"\n_far_:");
#endif
for (dy = 0; dy < TEST_HEIGHT; dy++) {
src_row = block_row - dy;
Fprintf(ofp, "/* DY = %2d */\n {{\n", dy);
#ifndef no_vision_progress
Fprintf(stderr," %2d",dy), (void)fflush(stderr);
#endif
for (dx = 1; dx < TEST_WIDTH; dx++) {
src_col = block_col + dx;
Fprintf(ofp, " /*%2d(-1)*/ {", dx);
for (this_row = block_row+1; this_row < block_row+TEST_HEIGHT;
this_row++) {
delim = (this_row < block_row + TEST_HEIGHT - 1) ? "," : "";
SpinCursor(3);
/* Find first col that we can see. */
for (i = 0; i <= block_col; i++) {
if (clear_path(src_row,src_col,this_row,i)) break;
}
if (block_col-i < 0)
Fprintf(ofp, "%s%s", FAR_OFF_TABLE_STRING, delim);
else
Fprintf(ofp, "%2d%s", block_col - i, delim);
}
Fprintf(ofp, "}%s", (dx < TEST_WIDTH - 1) ? ",\n" : "\n");
}
Fprintf(ofp," }},\n");
}
Fprintf(ofp,"}; /* far_table[] */\n"); /* closing brace for table */
Fprintf(ofp,"#endif /* !CLOSE_TABLE_ONLY */\n");
#ifndef no_vision_progress
Fprintf(stderr,"\n");
#endif
return;
}
/*
* "Draw" a line from the hero to the given location. Stop if we hit a
* wall.
*
* Generalized integer Bresenham's algorithm (fast line drawing) for
* all quadrants. From _Procedural Elements for Computer Graphics_, by
* David F. Rogers. McGraw-Hill, 1985.
*
* I have tried a little bit of optimization by pulling compares out of
* the inner loops.
*
* NOTE: This had better *not* be called from a position on the
* same row as the hero.
*/
static int
clear_path(you_row,you_col,y2,x2)
int you_row, you_col, y2, x2;
{
int dx, dy, s1, s2;
register int i, error, x, y, dxs, dys;
x = you_col; y = you_row;
dx = abs(x2-you_col); dy = abs(y2-you_row);
s1 = sign(x2-you_col); s2 = sign(y2-you_row);
if (s1 == 0) { /* same column */
if (s2 == 1) { /* below (larger y2 value) */
for (i = you_row+1; i < y2; i++)
if (!xclear[i][you_col]) return 0;
} else { /* above (smaller y2 value) */
for (i = y2+1; i < you_row; i++)
if (!xclear[i][you_col]) return 0;
}
return 1;
}
/*
* Lines at 0 and 90 degrees have been weeded out.
*/
if (dy > dx) {
error = dx; dx = dy; dy = error; /* swap the values */
dxs = dx << 1; /* save the shifted values */
dys = dy << 1;
error = dys - dx; /* NOTE: error is used as a temporary above */
for (i = 0; i < dx; i++) {
if (!xclear[y][x]) return 0; /* plot point */
while (error >= 0) {
x += s1;
error -= dxs;
}
y += s2;
error += dys;
}
} else {
dxs = dx << 1; /* save the shifted values */
dys = dy << 1;
error = dys - dx;
for (i = 0; i < dx; i++) {
if (!xclear[y][x]) return 0; /* plot point */
while (error >= 0) {
y += s2;
error -= dxs;
}
x += s1;
error += dys;
}
}
return 1;
}
#endif /* VISION_TABLES */
#ifdef STRICT_REF_DEF
NEARDATA struct flag flags;
# ifdef ATTRIB_H
struct attribs attrmax, attrmin;
# endif
#endif /* STRICT_REF_DEF */
/*makedefs.c*/
|