Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Nick Gammon December 18, 2010
file 1948 lines (1528 sloc) 51.056 kb
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
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE muclient [
<!ENTITY show_vnums "true" >
  <!ENTITY show_timing "false" >
  <!ENTITY show_completed "false" >
  <!ENTITY show_database_mods "true" >
  <!ENTITY show_other_areas "false" >
  <!ENTITY show_area_exits "true" >
  <!ENTITY show_up_down "false" >
  <!ENTITY speedwalk_prefix "" >
]>

<muclient>
<plugin
   name="ATCP_Mapper"
   author="Nick Gammon"
   id="a80b38e2f618fbda79a6440c"
   language="Lua"
   purpose="Draws map for ATCP MUDs"
   date_written="2010-03-04"
   date_modified="2010-11-26"
   requires="4.51"
   version="1.6"
   save_state="y"
   >
<description trim="y">
<![CDATA[
AUTOMATIC MAPPER ... by Nick Gammon

The window can be dragged to a new location by dragging the room name.

Your current room is always in the center with a bolder border.

LH-click on a room to speed-walk to it. RH-click on a room for options.

LH-click on the "*" button on the bottom-left corner to configure it.

** WHY DOES THE MAP CHANGE? **

The mapper draws from your room outwards - that is, it draws your room's exits
first, then the rooms leading from those rooms, and so on.

Eventually it finds an overlap, and draws a short "stub" line to indicate there
is a room there which there isn't space to draw. If you get closer to that
room the stub will disappear and the room(s) in question will be drawn.

ACTIONS

mapper help --> this help (or click the "?" button on the bottom right)
mapper zoom out --> zoom out (or use the mouse-wheel)
mapper zoom in --> zoom in (or use the mouse-wheel)
mapper hide --> hide map
mapper show --> show map

FINDING THINGS

mapper bookmarks --> show nearby rooms that you bookmarked
mapper find <text> --> full-text search (eg. shop OR baker)
mapper areas --> show path to nearby areas (zones)
mapper heal --> show nearby healers
mapper shop --> show nearby shops/banks etc.
mapper train --> show nearby trainers
mapper quest --> show nearby quest-givers
mapper where <room> --> show directions to a room

MOVING

mapper goto <room> --> walk to a room by its room number
mapper stop --> cancel any current speedwalk
mapper resume --> resume last speedwalk or hyperlinked speedwalk

]]>
</description>

</plugin>

<aliases>
 
  <!-- zooming aliases -->

 <alias
   match="mapper zoom out"
   enabled="y"
   sequence="100"
   omit_from_command_history="y"
   omit_from_output="y"
   script="mapper.zoom_out"
  >
  </alias>
  
<alias
   match="mapper zoom in"
   enabled="y"
   sequence="100"
   omit_from_command_history="y"
   omit_from_output="y"
   script="mapper.zoom_in"
  >
  </alias>
    
  <!-- finding aliases -->
  
 <alias
   match="^mapper find ([\w* %d/&quot;]+)$"
   enabled="y"
   sequence="100"
   script="map_find"
   regexp="y"
  >
  
  </alias>
    
 <alias
   match="mapper areas"
   enabled="y"
   sequence="100"
   script="map_areas"
  >
  
  </alias>
    
 <alias
   match="^mapper shops?$"
   regexp="y"
   enabled="y"
   sequence="100"
   script="map_shops"
  >
  
  </alias>

 <alias
   match="^mapper train\w*$"
   regexp="y"
   enabled="y"
   sequence="100"
   script="map_trainers"
  >
  
  </alias>

 <alias
   match="^mapper quest\w*$"
   regexp="y"
   enabled="y"
   sequence="100"
   script="map_quests"
  >
  
  </alias>
        
<alias
   match="^mapper heal\w*$"
   regexp="y"
   enabled="y"
   sequence="100"
   script="map_healers"
  >
  
  </alias>
    
 <alias
   match="mapper goto *"
   enabled="y"
   sequence="100"
   script="map_goto"
  >
  
  </alias>
    
 <alias
   match="mapper where *"
   enabled="y"
   sequence="100"
   script="map_where"
  >
  
  </alias>
    
  <alias
   match="^mapper book\w*$"
   regexp="y"
   enabled="y"
   sequence="100"
   script="map_bookmarks"
  >
  
  </alias>
    
 <alias
   match="mapper resume"
   enabled="y"
   sequence="100"
   script="map_resume"
  >
  
  </alias>
    
  <!-- cancel speedwalking -->
  
 <alias
   match="mapper stop"
   enabled="y"
   sequence="100"
   script="mapper.cancel_speedwalk"
  >
  </alias>

  <!-- show/hide mapper -->
      
  <alias
   match="mapper hide"
   enabled="y"
   sequence="100"
   script="mapper.hide"
  >
  </alias>
  
   <alias
   match="mapper show"
   enabled="y"
   sequence="100"
   script="mapper.show"
  >
  </alias>
  
</aliases>

<triggers>

  <!-- auto-swim -->
 
 <trigger
   enabled="y"
   match="There's water ahead of you. You'll have to * to make it through."
   sequence="100"
  >
  <send>%1</send>
  </trigger>
  
 <trigger
   enabled="y"
   match="You'll have to swim to make it through the water in that direction."
   send_to="12"
   sequence="100"
  >
  <send>
    if last_direction_moved then
      Send ("swim " .. last_direction_moved)
    end -- if
  </send>
  </trigger>
  
  <!-- auto-open -->
  
  <trigger
   enabled="y"
   regexp="y"
   match="^There is a door in the way"
   send_to="12"
   sequence="100"
  >
  <send>
    if last_direction_moved then
      Send ("open door " .. last_direction_moved)
    end -- if
  </send>
  </trigger>
  
  <!-- various messages that cancel speedwalks -->
  
  <trigger
   enabled="y"
   match="Now now\, don\'t be so hasty\!$"
   regexp="y"
   script="mapper.cancel_speedwalk"
   sequence="100"
  >
  </trigger>
  
  <trigger
   enabled="y"
   match="^You cannot walk through"
   regexp="y"
   script="mapper.cancel_speedwalk"
   sequence="100"
  >
  </trigger>
  
  <trigger
   enabled="y"
   match="As you stroll in, you feel your feet slipping on something slimy."
   script="mapper.cancel_speedwalk"
   sequence="100"
  >
  <send>stand</send>
  </trigger>
  
  <trigger
   enabled="y"
   match="The door is locked."
   script="mapper.cancel_speedwalk"
   sequence="100"
  >
  </trigger>
  
  <trigger
   enabled="y"
   match="You are regaining balance and are unable to move."
   script="mapper.cancel_speedwalk"
   sequence="100"
  >
  </trigger>
  <trigger
   enabled="y"
   match="You are surrounded by a pocket of air and so must move normally through water."
   script="mapper.cancel_speedwalk"
   sequence="100"
  >
  </trigger>
  <trigger
   enabled="y"
   match="You fumble about drunkenly."
   script="mapper.cancel_speedwalk"
   sequence="100"
  >
  </trigger>
  
  <trigger
   enabled="y"
   match="You are asleep and can do nothing. WAKE will attempt to wake you."
   script="mapper.cancel_speedwalk"
   sequence="100"
  >
  </trigger>
  
   <trigger
   enabled="y"
   match="You must be standing first."
   script="mapper.cancel_speedwalk"
   sequence="100"
  >
  </trigger>
  
   <trigger
   enabled="y"
   match="You need to use a boat, fly, or swim underwater to go there."
   script="mapper.cancel_speedwalk"
   sequence="100"
  >
  </trigger>
  
  <trigger
   enabled="y"
   match="You can't * while sitting."
   script="mapper.cancel_speedwalk"
   sequence="100"
  >
  </trigger>
  
 <trigger
   enabled="y"
   regexp="y"
   match="^You dream about "
   script="mapper.cancel_speedwalk"
   sequence="100"
  >
  </trigger>
   
 <trigger
   enabled="y"
   match="There is no exit in that direction."
   script="mapper.cancel_speedwalk"
   sequence="100"
  >
  </trigger>
  
 <trigger
   enabled="y"
   match="Alas, you cannot go that way."
   script="mapper.cancel_speedwalk"
   sequence="100"
  >
  </trigger>
  
</triggers>



<!-- Plugin help -->

<aliases>
  <alias
   script="OnHelp"
   match="mapper help"
   enabled="y"
  >
  </alias>
</aliases>

<!-- Script -->


<script>

local show_vnums = &show_vnums;
local show_timing = &show_timing;
local show_completed = &show_completed;
local show_database_mods = &show_database_mods;
local show_other_areas = &show_other_areas;
local show_up_down = &show_up_down;
local show_area_exits = &show_area_exits;
local speedwalk_prefix = "&speedwalk_prefix;"

<![CDATA[

require "serialize"
require "checkplugin"
mapper = require "mapper"


default_config = {
-- assorted colours
BACKGROUND_COLOUR = { name = "Background", colour = ColourNameToRGB "lightseagreen", },
ROOM_COLOUR = { name = "Room", colour = ColourNameToRGB "cyan", },
EXIT_COLOUR = { name = "Exit", colour = ColourNameToRGB "darkgreen", },
EXIT_COLOUR_UP_DOWN = { name = "Exit up/down", colour = ColourNameToRGB "darkmagenta", },
EXIT_COLOUR_IN_OUT = { name = "Exit in/out", colour = ColourNameToRGB "#3775E8", },
OUR_ROOM_COLOUR = { name = "Our room", colour = ColourNameToRGB "black", },
UNKNOWN_ROOM_COLOUR = { name = "Unknown room", colour = ColourNameToRGB "#00CACA", },
DIFFERENT_AREA_COLOUR = { name = "Another area", colour = ColourNameToRGB "#009393", },
SHOP_FILL_COLOUR = { name = "Shop", colour = ColourNameToRGB "darkolivegreen", },
POSTOFFICE_FILL_COLOUR = { name = "Post Office", colour = ColourNameToRGB "yellowgreen", },
BANK_FILL_COLOUR = { name = "Bank", colour = ColourNameToRGB "gold", },
NEWSROOM_FILL_COLOUR = { name = "Newsroom", colour = ColourNameToRGB "lightblue", },
MAPPER_NOTE_COLOUR = { name = "Messages", colour = ColourNameToRGB "lightgreen" },
ROOM_NAME_TEXT = { name = "Room name text", colour = ColourNameToRGB "#BEF3F1", },
ROOM_NAME_FILL = { name = "Room name fill", colour = ColourNameToRGB "#105653", },
ROOM_NAME_BORDER = { name = "Room name box", colour = ColourNameToRGB "black", },
AREA_NAME_TEXT = { name = "Area name text", colour = ColourNameToRGB "#BEF3F1",},
AREA_NAME_FILL = { name = "Area name fill", colour = ColourNameToRGB "#105653", },
AREA_NAME_BORDER = { name = "Area name box", colour = ColourNameToRGB "black", },
FONT = { name = get_preferred_font {"Dina", "Lucida Console", "Fixedsys", "Courier", "Sylfaen",} ,
size = 8
} ,
-- size of map window
WINDOW = { width = 400, height = 400 },
-- how far from where we are standing to draw (rooms)
SCAN = { depth = 30 },
-- speedwalk delay
DELAY = { time = 0.3 },
-- how many seconds to show "recent visit" lines (default 3 minutes)
LAST_VISIT_TIME = { time = 60 * 3 },
}

local rooms = {}
local areas = {}
local environments = {}
local user_terrain_colour = {}

room_not_in_database = {}
room_in_database = {}

function dbcheck (code)

if code ~= sqlite3.OK and -- no error
code ~= sqlite3.ROW and -- completed OK with another row of data
code ~= sqlite3.DONE then -- completed OK, no more rows
local err = db:errmsg () -- the rollback will change the error message
db:exec ("ROLLBACK") -- rollback any transaction to unlock the database
error (err, 2) -- show error in caller's context
end -- if

end -- dbcheck

function fixsql (s)
if s then
return "'" .. (string.gsub (s, "'", "''")) .. "'" -- replace single quotes with two lots of single quotes
else
return "NULL"
end -- if
end -- fixsql

function fixbool (b)
if b then
return 1
else
return 0
end -- if
end -- fixbool

function save_room_to_database (uid, title)
assert (uid, "No UID supplied to save_room_to_database")
dbcheck (db:execute (string.format (
"INSERT INTO rooms (uid, name, area, date_added) VALUES (%s, %s, '0', DATETIME('NOW'));",
fixsql (uid),
fixsql (title)
)))
dbcheck (db:execute (string.format ([[
INSERT INTO rooms_lookup (uid, name) VALUES (%s, %s);
]], fixsql (uid),
fixsql (title)
)))
room_not_in_database [uid] = false
if show_database_mods then
mapper.mapprint ("Added room", uid, "to database. Name:", title)
end -- if
end -- function save_room_to_database
function save_exits_to_database (uid, exits)
local room = rooms [uid]
db:exec ("BEGIN TRANSACTION;")

for dir in string.gmatch (exits, "[^,]+") do

-- fix up in and out
dir = ({ ['i'] = "in", o = "out", }) [dir] or dir
dbcheck (db:execute (string.format ([[
INSERT INTO exits (dir, fromuid, touid, date_added)
VALUES (%s, %s, %s, DATETIME('NOW'));
]], fixsql (dir), -- direction (eg. "n")
fixsql (uid), -- from current room
fixsql (0) -- destination room (not known)
)))
if show_database_mods then
mapper.mapprint ("Added exit", dir, "from room", uid, "to database.")
end -- if
room.exits [dir] = "0"
end -- for each exit
db:exec ("COMMIT;")
end -- function save_room_to_database

function save_full_exits_to_database (uid, exits)
local room = rooms [uid]
db:exec ("BEGIN TRANSACTION;")

for exit in string.gmatch (exits, "[^,]+") do

dir, touid = string.match (exit, "^(%a+)%((%d+)%)$")
if dir then
-- fix up in and out
dir = ({ ['i'] = "in", o = "out", }) [dir] or dir
dbcheck (db:execute (string.format ([[
INSERT INTO exits (dir, fromuid, touid, date_added)
VALUES (%s, %s, %s, DATETIME('NOW'));
]], fixsql (dir), -- direction (eg. "n")
fixsql (uid), -- from current room
fixsql (touid) -- destination room
)))
if show_database_mods then
mapper.mapprint ("Added exit", dir, "from room", uid, "to room", touid, "to database.")
end -- if
room.exits [dir] = touid
else
mapper.maperror ("Cannot make sense of:", exit)
end -- if can decode
end -- for each exit
db:exec ("COMMIT;")
end -- function save_full_exits_to_database

function fix_up_exit ()

local room = rooms [from_room]
dbcheck (db:execute (string.format ([[
UPDATE exits SET touid = %s WHERE fromuid = %s AND dir = %s;
]],
fixsql (current_room), -- destination room
fixsql (from_room), -- from previous room
fixsql (last_direction_moved) -- direction (eg. "n")
)))
if show_database_mods then
mapper.mapprint ("Fixed exit", last_direction_moved, "from room", from_room, "to be to", current_room)
end -- if
room.exits [last_direction_moved] = current_room
last_direction_moved = nil
from_room = nil
end -- fix_up_exit

function save_environment_to_database (uid, s)
local room = rooms [uid]

dbcheck (db:execute (string.format ([[
UPDATE rooms SET terrain = %s WHERE uid = %s;
]],
fixsql (s), -- environment
fixsql (uid) -- room
)))
room.terrain = s
if show_database_mods then
mapper.mapprint ("Fixed room", uid, "to have environment:", s)
end -- if
end -- save_environment_to_database

function save_info_to_database (uid, s)
local room = rooms [uid]

dbcheck (db:execute (string.format ([[
UPDATE rooms SET info = %s WHERE uid = %s;
]],
fixsql (s), -- info
fixsql (uid) -- room
)))
room.info = s
if show_database_mods then
mapper.mapprint ("Fixed room", uid, "to have info:", s)
end -- if
end -- save_info_to_database

function save_coordinates_to_database (uid, s)
local room = rooms [uid]

local area, x, y, z = string.match (s, "^(.-),([%d-]+),([%d-]+),([%d-]+)")
if x then
dbcheck (db:execute (string.format ([[
UPDATE rooms SET x = %i, y = %i, z = %i, area = %s WHERE uid = %s;
]],
x, y, z, fixsql (area), -- coordinates, area
fixsql (uid) -- room
)))
room.x = x
room.y = y
room.z = z
room.area = area
if show_database_mods then
mapper.mapprint ("Fixed room", uid, "to have coordinates:", x, y, z, "and area", area)
end -- if
else
mapper.maperror ("Cannot make sense of coordinates:", s)
end -- if
end -- save_coordinates_to_database

function load_room_from_database (uid)

local room
assert (uid, "No UID supplied to load_room_from_database")
-- if not in database, don't look again
if room_not_in_database [uid] then
return nil
end -- no point looking
for row in db:nrows(string.format ("SELECT * FROM rooms WHERE uid = %s", fixsql (uid))) do
room = {
name = row.name,
area = row.area,
building = row.building,
terrain = row.terrain,
info = row.info,
notes = row.notes,
x = row.x,
y = row.y,
z = row.z,
exits = {} }
for exitrow in db:nrows(string.format ("SELECT * FROM exits WHERE fromuid = %s", fixsql (uid))) do
room.exits [exitrow.dir] = tostring (exitrow.touid)
end -- for each exit
end -- finding room

if room then
rooms [uid] = room
for row in db_bm:nrows(string.format ("SELECT * FROM bookmarks WHERE uid = %s", fixsql (uid))) do
rooms [uid].notes = row.notes
end -- finding room
return room
end -- if found
room_not_in_database [uid] = true
return nil
end -- load_room_from_database

function create_tables ()
-- create rooms table
dbcheck (db:execute[[
PRAGMA foreign_keys = ON;
PRAGMA journal_mode = WAL;
CREATE TABLE IF NOT EXISTS areas (
areaid INTEGER PRIMARY KEY AUTOINCREMENT,
uid TEXT NOT NULL, -- vnum or how the MUD identifies the area
name TEXT, -- name of area
date_added DATE, -- date added to database
UNIQUE (uid)
);

CREATE TABLE IF NOT EXISTS environments (
environmentid INTEGER PRIMARY KEY AUTOINCREMENT,
uid TEXT NOT NULL, -- code for the environment
name TEXT, -- name of environment
color INTEGER, -- ANSI colour code
date_added DATE, -- date added to database
UNIQUE (uid)
);
CREATE INDEX IF NOT EXISTS name_index ON environments (name);
CREATE TABLE IF NOT EXISTS rooms (
roomid INTEGER PRIMARY KEY AUTOINCREMENT,
uid TEXT NOT NULL, -- vnum or how the MUD identifies the room
name TEXT, -- name of room
area TEXT, -- which area
building TEXT, -- which building it is in
terrain TEXT, -- eg. road OR water
info TEXT, -- eg. shop,postoffice
notes TEXT, -- player notes
x INTEGER,
y INTEGER,
z INTEGER,
date_added DATE, -- date added to database
UNIQUE (uid)
);
CREATE INDEX IF NOT EXISTS info_index ON rooms (info);
CREATE INDEX IF NOT EXISTS terrain_index ON rooms (terrain);
CREATE INDEX IF NOT EXISTS area_index ON rooms (area);

CREATE TABLE IF NOT EXISTS exits (
exitid INTEGER PRIMARY KEY AUTOINCREMENT,
dir TEXT NOT NULL, -- direction, eg. "n", "s"
fromuid STRING NOT NULL, -- exit from which room (in rooms table)
touid STRING NOT NULL, -- exit to which room (in rooms table)
date_added DATE, -- date added to database
FOREIGN KEY(fromuid) REFERENCES rooms(uid)
);
CREATE INDEX IF NOT EXISTS fromuid_index ON exits (fromuid);
CREATE INDEX IF NOT EXISTS touid_index ON exits (touid);
]])
-- check if rooms_lookup table exists
local table_exists
for a in db:nrows "SELECT * FROM sqlite_master WHERE name = 'rooms_lookup' AND type = 'table'" do
table_exists = true
end -- for
if not table_exists then
dbcheck (db:execute "CREATE VIRTUAL TABLE rooms_lookup USING FTS3(uid, name);")
-- in case we only deleted the rooms_lookup table to save space in the download
dbcheck (db:execute "INSERT INTO rooms_lookup (uid, name) SELECT uid, name FROM rooms;")
end -- if
-- create bookmarks and terrain colours table in separate database
dbcheck (db_bm:execute[[
PRAGMA foreign_keys = ON;
CREATE TABLE IF NOT EXISTS bookmarks (
id INTEGER PRIMARY KEY AUTOINCREMENT,
uid TEXT NOT NULL, -- vnum of room
notes TEXT, -- user notes
date_added DATE, -- date added to database
UNIQUE (uid)
);
CREATE TABLE IF NOT EXISTS terrain (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL, -- terrain name
color INTEGER, -- RGB code
date_added DATE, -- date added to database
UNIQUE (name)
);
]])
end -- function create_tables

function get_room (uid)

-- check we got room at all
if not uid then
-- return nil
end -- if
-- look it up
local ourroom = rooms [uid]
-- not cached - see if in database
if not ourroom then
ourroom = load_room_from_database (uid)
rooms [uid] = ourroom -- cache for later
end -- not in cache
if not ourroom then
return nil
end -- if

local room = copytable.deep (ourroom)
room.area = areas [room.area] or string.format ("Area %s", room.area or "<unknown>")
if uid == current_room then
current_area = room.area
end -- if
-- build hover message
local environmentname = room.terrain
if tonumber (environmentname) then
environmentname = environments [tonumber (environmentname)]
end -- convert to name
local terrain = ""
if environmentname then
terrain = "\nTerrain: " .. capitalize (environmentname)
end -- if terrain known
local info = ""
if room.info then
info = "\nInfo: " .. capitalize (room.info)
end -- if info known
local notes = ""
if room.notes then
notes = "\nBookmark: " .. room.notes
end -- if notes
local texits = {}
for dir in pairs (room.exits) do
table.insert (texits, dir)
end -- for
table.sort (texits)
local areaname = room.area or "Unknown"
if tonumber (areaname) then
areaname = areas [tonumber (areaname)]
end -- convert to name
room.hovermessage = string.format (
"%s\tExits: %s\nRoom: %s\nArea: %s%s%s%s",
room.name,
table.concat (texits, ", "),
uid,
areaname,
terrain,
info,
notes
-- depth,
-- table.concat (path, ",")
)
room.bordercolour = config.ROOM_COLOUR.colour
room.borderpen = 0 -- solid
room.borderpenwidth = 1
room.fillcolour = 0xff0000
room.fillbrush = 1 -- no fill
-- special room fill colours
if room.info then
if string.match (room.info, "shop") then
room.fillcolour = config.SHOP_FILL_COLOUR.colour
room.fillbrush = 8
elseif string.match (room.info, "postoffice") then
room.fillcolour = config.POSTOFFICE_FILL_COLOUR.colour
room.fillbrush = 8
elseif string.match (room.info, "bank") then
room.fillcolour = config.BANK_FILL_COLOUR.colour
room.fillbrush = 8
elseif string.match (room.info, "newsroom") then
room.fillcolour = config.NEWSROOM_FILL_COLOUR.colour
room.fillbrush = 8
end -- if
else
-- use terrain colour
if environmentname then
if user_terrain_colour [environmentname] then
room.fillcolour = user_terrain_colour [environmentname]
room.fillbrush = 0 -- solid
elseif terrain_colours [environmentname] then
room.fillcolour = colour_lookup [terrain_colours [environmentname]]
room.fillbrush = 0 -- solid
end
end -- if environmentname
end -- if
if uid == current_room then
room.bordercolour = config.OUR_ROOM_COLOUR.colour
room.borderpenwidth = 2
elseif room.area ~= current_area then
room.bordercolour = config.DIFFERENT_AREA_COLOUR.colour
end -- not in this area
return room
end -- get_room

function room_edit_bookmark (room, uid)

local notes, found
for row in db_bm:nrows(string.format ("SELECT * FROM bookmarks WHERE uid = %s", fixsql (uid))) do
notes = row.notes
found = true
end -- finding room
if found then
newnotes = utils.inputbox ("Modify room comment (clear it to delete from database)", room.name, notes)
else
newnotes = utils.inputbox ("Enter room comment (creates a bookmark for this room)", room.name, notes)
end -- if
if not newnotes then
return
end -- if cancelled
if newnotes == "" then
if not found then
mapper.mapprint ("No comment entered, bookmark not saved.")
return
else
dbcheck (db_bm:execute (string.format (
"DELETE FROM bookmarks WHERE uid = %s;",
fixsql (uid)
)))
mapper.mapprint ("Bookmark for room", uid, "deleted. Was previously:", notes)
rooms [uid].notes = nil
return
end -- if
end -- if
if notes == newnotes then
return -- no change made
end -- if
if found then
dbcheck (db_bm:execute (string.format (
"UPDATE bookmarks SET notes = %s, date_added = DATETIME('NOW') WHERE uid = %s;",
fixsql (newnotes),
fixsql (uid)
)))
mapper.mapprint ("Bookmark for room", uid, "changed to:", newnotes)
else
dbcheck (db_bm:execute (string.format (
"INSERT INTO bookmarks (uid, notes, date_added) VALUES (%s, %s, DATETIME('NOW'));",
fixsql (uid),
fixsql (newnotes)
)))
mapper.mapprint ("Bookmark added to room", uid, ":", newnotes)
end -- if
rooms [uid].notes = newnotes
end -- room_edit_bookmark

function room_edit_terrain_colour (room, uid)

if not room.terrain then
utils.msgbox ("This room does not have a terrain type", "Unknown terrain!", "ok", "!", 1)
return
end -- not known
local environmentname = room.terrain
if tonumber (environmentname) then
environmentname = environments [tonumber (environmentname)]
end -- convert to name
local colour
local colourtype = terrain_colours [environmentname]
if colourtype then
colour = colour_lookup [colourtype]
end -- if type known

if user_terrain_colour [environmentname] then
colour = user_terrain_colour [environmentname]
end -- if already have user colour
local newcolour = PickColour (colour or 0x000000)
if newcolour == -1 or newcolour == colour then
return
end -- cancelled
if user_terrain_colour [environmentname] then
dbcheck (db_bm:execute (string.format (
"UPDATE terrain SET color = %s, date_added = DATETIME('NOW') WHERE name = %s;",
fixsql (newcolour),
fixsql (environmentname)
)))
mapper.mapprint ("Colour for terrain '" .. environmentname .. "' changed to:", RGBColourToName (newcolour))
else
dbcheck (db_bm:execute (string.format (
"INSERT INTO terrain (name, color, date_added) VALUES (%s, %s, DATETIME('NOW'));",
fixsql (environmentname),
fixsql (newcolour)
)))
mapper.mapprint ("Colour for terrain '" .. environmentname .. "' is now", RGBColourToName (newcolour))
end -- if
user_terrain_colour [environmentname] = newcolour

mapper.draw (current_room)

end -- room_edit_terrain_colour

function room_add_exit (room, uid)

local available = {
n = "North",
s = "South",
e = "East",
w = "West",
u = "Up",
d = "Down",
ne = "Northeast",
sw = "Southwest",
nw = "Northwest",
se = "Southeast",
['in'] = "In",
out = "Out",
} -- end of available

-- remove existing exits
for k in pairs (room.exits) do
available [k] = nil
end -- for
if next (available) == nil then
utils.msgbox ("All exits already used.", "No free exits!", "ok", "!", 1)
return
end -- not known
local chosen_exit = utils.listbox ("Choose exit to add", "Exits ...", available )
if not chosen_exit then
return
end
exit_destination = utils.inputbox ("Enter destination room identifier (number) for " .. available [chosen_exit], room.name, "")

if not exit_destination then
return
end -- cancelled
-- look it up
local dest_room = rooms [exit_destination]
-- not cached - see if in database
if not dest_room then
dest_room = load_room_from_database (exit_destination)
rooms [exit_destination] = dest_room -- cache for later
end -- not in cache
if not dest_room then
utils.msgbox ("Room " .. exit_destination .. " does not exist.", "Room does not exist!", "ok", "!", 1)
return
end -- if still not there

dbcheck (db:execute (string.format ([[
INSERT INTO exits (dir, fromuid, touid, date_added)
VALUES (%s, %s, %s, DATETIME('NOW'));
]], fixsql (chosen_exit), -- direction (eg. "n")
fixsql (uid), -- from current room
fixsql (exit_destination) -- destination room
)))
if show_database_mods then
mapper.mapprint ("Added exit", available [chosen_exit], "from room", uid, "to room", exit_destination, "to database.")
end -- if
-- update in-memory table
rooms [uid].exits [chosen_exit] = exit_destination
mapper.draw (current_room)
end -- room_add_exit


function room_delete_exit (room, uid)

local available = {
n = "North",
s = "South",
e = "East",
w = "West",
u = "Up",
d = "Down",
ne = "Northeast",
sw = "Southwest",
nw = "Northwest",
se = "Southeast",
['in'] = "In",
out = "Out",
} -- end of available

-- remove non-existent exits
for k in pairs (available) do
if room.exits [k] then
available [k] = available [k] .. " --> " .. room.exits [k]
else
available [k] = nil
end -- if not a room exit
end -- for
if next (available) == nil then
utils.msgbox ("There are no exits from this room.", "No exits!", "ok", "!", 1)
return
end -- not known
local chosen_exit = utils.listbox ("Choose exit to delete", "Exits ...", available )
if not chosen_exit then
return
end

dbcheck (db:execute (string.format ([[
DELETE FROM exits WHERE dir = %s AND fromuid = %s;
]], fixsql (chosen_exit), -- direction (eg. "n")
fixsql (uid) -- from current room
)))
if show_database_mods then
mapper.mapprint ("Deleted exit", available [chosen_exit], "from room", uid, "from database.")
end -- if
-- update in-memory table
rooms [uid].exits [chosen_exit] = nil
mapper.draw (current_room)
end -- room_delete_exit


function room_change_exit (room, uid)

local available = {
n = "North",
s = "South",
e = "East",
w = "West",
u = "Up",
d = "Down",
ne = "Northeast",
sw = "Southwest",
nw = "Northwest",
se = "Southeast",
['in'] = "In",
out = "Out",
} -- end of available

-- remove non-existent exits
for k in pairs (available) do
if room.exits [k] then
available [k] = available [k] .. " --> " .. room.exits [k]
else
available [k] = nil
end -- if not a room exit
end -- for
if next (available) == nil then
utils.msgbox ("There are no exits from this room.", "No exits!", "ok", "!", 1)
return
end -- not known
local chosen_exit = utils.listbox ("Choose exit to change destination of:", "Exits ...", available )
if not chosen_exit then
return
end

exit_destination = utils.inputbox ("Enter destination room identifier (number) for " .. available [chosen_exit], room.name, "")

if not exit_destination then
return
end -- cancelled
-- look it up
local dest_room = rooms [exit_destination]
-- not cached - see if in database
if not dest_room then
dest_room = load_room_from_database (exit_destination)
rooms [exit_destination] = dest_room -- cache for later
end -- not in cache
if not dest_room then
utils.msgbox ("Room " .. exit_destination .. " does not exist.", "Room does not exist!", "ok", "!", 1)
return
end -- if still not there
dbcheck (db:execute (string.format ([[
UPDATE exits SET touid = %s WHERE dir = %s AND fromuid = %s;
]], fixsql (exit_destination),
fixsql (chosen_exit), -- direction (eg. "n")
fixsql (uid) -- from current room
)))
if show_database_mods then
mapper.mapprint ("Modified exit", available [chosen_exit], "from room", uid, "to be to room", exit_destination, "in database.")
end -- if
-- update in-memory table
rooms [uid].exits [chosen_exit] = exit_destination
mapper.draw (current_room)
end -- room_change_exit

function change_room_area (room, uid)
if next (areas) == nil then
mapper.maperror("There are no available areas to choose from.")
return
end -- if
local chosen_area = utils.listbox ("Choose the area this room belongs to:", "Areas ...", areas)
if not chosen_area then
return
end -- if
rooms[uid].area = chosen_area
mapper.draw (current_room)
dbcheck (db:execute (string.format ([[
UPDATE rooms SET area = %s WHERE uid = %s;
]], fixsql (chosen_area), -- area (e.g. "1" for "western ithmia")
fixsql (uid) -- from current room
)))
end -- change_room_area

function add_area (room, uid)
local roomname
local roomarea
for row in db:nrows(string.format ("SELECT name, area FROM rooms WHERE uid = %s", fixsql (uid))) do
roomname = row.name
roomarea = row.area
end -- finding room

if roomname == nil then
mapper.maperror("Cannot find this room in the database")
return
end -- if
local area_name = utils.inputbox ("Name for area: " .. roomarea,
"Choose the name for this area",
areas [roomarea] )
if not area_name or area_name == "" then
return
end -- if

db:exec ("BEGIN TRANSACTION")
-- get rid of old area description, if any
local exists = db:execute (string.format (
"DELETE FROM areas WHERE uid = %s;",
fixsql (roomarea)
)) == sqlite3.OK
dbcheck (db:execute (string.format (
"INSERT INTO areas (uid, name, date_added) VALUES (%s, %s, DATETIME('NOW'));",
fixsql (roomarea),
fixsql (area_name)
)))

db:exec ("COMMIT")
local action = "Added"
if exists then
action = "Changed"
end -- if
mapper.mapprint (string.format ("%s area '%s' with area code '%s'",
action, area_name, roomarea))
areas [roomarea] = area_name
mapper.draw (current_room)
end -- add_area

function room_click (uid, flags)

-- check we got room at all
if not uid then
return nil
end -- if
-- look it up
local room = rooms [uid]
-- not cached - see if in database
if not room then
room = load_room_from_database (uid)
rooms [uid] = room -- cache for later
end -- not in cache
if not room then
return
end -- if still not there
local handlers = {
{ name = "Edit bookmark", func = room_edit_bookmark} ,
{ name = "Edit terrain colour", func = room_edit_terrain_colour} ,
{ name = "-", } ,
-- { name = "^Exits", } ,
{ name = "Add Exit", func = room_add_exit} ,
{ name = "Change Exit", func = room_change_exit} ,
{ name = "Delete Exit", func = room_delete_exit} ,
{ name = "-", } ,
{ name = "Set area for room", func = change_room_area} ,
{ name = "Update area name", func = add_area} ,
} -- handlers
local t, tf = {}, {}
for _, v in pairs (handlers) do
table.insert (t, v.name)
tf [v.name] = v.func
end -- for
local choice = WindowMenu (mapper.win,
WindowInfo (mapper.win, 14),
WindowInfo (mapper.win, 15),
table.concat (t, "|"))
local f = tf [choice]
if f then
f (room, uid)
end -- if handler found
end -- room_click

function OnPluginInstall ()
config = {} -- in case not found

-- get saved configuration
assert (loadstring (GetVariable ("config") or "")) ()

-- allow for additions to config
for k, v in pairs (default_config) do
config [k] = config [k] or v
end -- for
-- initialize mapper engine
mapper.init { config = config, -- colours, timing etc.
get_room = get_room, -- get_room (uid) called to get room info
show_help = OnHelp, -- to show help
room_click = room_click, -- called on RH click on room square
timing = show_timing, -- want to see timing
show_completed = show_completed, -- want to see "Speedwalk completed." message
show_other_areas = show_other_areas, -- want to see areas other than the current one?
show_up_down = show_up_down, -- want to follow up/down exits?
show_area_exits = show_area_exits, -- want to see area exits?
speedwalk_prefix = speedwalk_prefix, -- how to speedwalk
}
mapper.mapprint (string.format ("MUSHclient mapper installed, version %0.1f", mapper.VERSION))
-- open databases on disk
db = assert (sqlite3.open(GetInfo (66) .. Trim (WorldAddress ()) .. "_" .. WorldPort () .. ".db"))
db_bm = assert (sqlite3.open(GetInfo (66) .. Trim (WorldAddress ()) .. "_" .. WorldPort () .. "_bookmarks.db"))
create_tables () -- create database structure if necessary
-- grab all area names
for row in db:nrows("SELECT * FROM areas") do
areas [row.uid] = row.name
end -- finding areas
-- grab all user terrain info
for row in db_bm:nrows("SELECT * FROM terrain") do
user_terrain_colour [row.name] = row.color
end -- finding terrains
-- grab all environment names
for row in db:nrows("SELECT * FROM environments") do
environments [tonumber (row.uid)] = row.name
terrain_colours [row.name] = tonumber (row.color)
end -- finding environments
end -- OnPluginInstall

function OnPluginEnable ()
mapper.show ()
end -- OnPluginDisable

function OnPluginDisable ()
mapper.hide ()
end -- OnPluginDisable

-- hide window on removal
function OnPluginClose ()
mapper.hide ()
-- close databases
db:close()
db_bm:close()
end -- OnPluginClose

function OnPluginSaveState ()
mapper.save_state ()
SetVariable ("config", "config = " .. serialize.save_simple (config))
end -- OnPluginSaveState
terrain_colours = {}


-- ANSI colours lookup (for terrain_colours)

colour_lookup = {
[0] = ColourNameToRGB "black",
[1] = ColourNameToRGB "maroon",
[2] = ColourNameToRGB "green",
[3] = ColourNameToRGB "olive",
[4] = ColourNameToRGB "navy",
[5] = ColourNameToRGB "purple",
[6] = ColourNameToRGB "teal",
[7] = ColourNameToRGB "silver",
[8] = ColourNameToRGB "gray",
[9] = ColourNameToRGB "red",
[10] = ColourNameToRGB "lime",
[11] = ColourNameToRGB "yellow",
[12] = ColourNameToRGB "blue",
[13] = ColourNameToRGB "magenta",
[14] = ColourNameToRGB "cyan",
[15] = ColourNameToRGB "white",
} -- end of colour_lookup


-- here when location changes, eg. : Room.Num 7476
function got_room_number (s)
local room_number = s
if not room_number then
return
end -- no room number

current_room = room_number
mapper.draw (room_number)
if expected_exit == "0" and from_room then
fix_up_exit ()
end -- exit was wrong

end -- got_room_number

-- we got a room name, eg. : Room.Brief On the edge of a great plain
function got_room_name (s)
local brief = s
if not current_room then
return
end -- don't have room
local room = rooms [current_room]
-- not cached - see if in database
if not room then
room = load_room_from_database (current_room)
end -- not in cache
if not room then
save_room_to_database (current_room, brief)
mapper.draw (current_room) -- redraw room with name
end -- if room not there
end -- got_room_name

-- we got room exits, eg. : Room.Exits ne,sw,nw
function got_room_exit (s)
-- don't do if we are expecting full exits at some stage
if full_exits_found then
return
end -- if

local exits = string.match (s, "^([%a,]+)$")
if not (current_room and exits) then
return
end -- if
local room = rooms [current_room]
-- not cached - see if in database
if not room then
room = load_room_from_database (current_room)
end -- not in cache
if room and next (room.exits) == nil then
save_exits_to_database (current_room, exits)
mapper.draw (current_room) -- redraw room with exits
end -- need to save exits


end -- got_room_exit

function got_vitals (s)
-- ignore
end -- function got_vitals

-- we got room exits, eg. : Room.FullExits ne(8564),w(8428)
function got_room_full_exits (s)
full_exits_found = true
local exits = string.match (s, "^([%a,(%d)]+)$")
if not (current_room and exits) then
return
end -- if
local room = rooms [current_room]
-- not cached - see if in database
if not room then
room = load_room_from_database (current_room)
end -- not in cache
if room and next (room.exits) == nil then
save_full_exits_to_database (current_room, exits)
mapper.draw (current_room) -- redraw room with exits
end -- need to save exits

end -- got_room_exit

-- we got room environment, eg. : Urban
function got_environment (s)
if not current_room then
return
end -- if
local room = rooms [current_room]
-- not cached - see if in database
if not room then
room = load_room_from_database (current_room)
end -- not in cache
if room and room.terrain == nil then
save_environment_to_database (current_room, s)
mapper.draw (current_room) -- redraw room with environment
end -- need to save environment

end -- got_environment

-- we got room coordinates, eg. : "38,3,1,0"
function got_coordinates (s)
if not current_room then
return
end -- if
local room = rooms [current_room]
-- not cached - see if in database
if not room then
room = load_room_from_database (current_room)
end -- not in cache
if room and (room.area == nil or tonumber (room.area) == 0) then
save_coordinates_to_database (current_room, s)
mapper.draw (current_room) -- redraw room with area
end -- need to save environment

end -- got_coordinates

-- we got room info, eg. : shops,postoffice
function got_info (s)
if not current_room then
return
end -- if
local room = rooms [current_room]
-- not cached - see if in database
if not room then
room = load_room_from_database (current_room)
end -- not in cache
if room and room.info == nil then
save_info_to_database (current_room, s)
mapper.draw (current_room) -- redraw room with info
end -- need to save environment

end -- got_info

handlers = {
[1] = got_vitals, -- eg. "H:496/496 M:412/412 E:1380/1380 W:960/960 NL:89/100"
-- health mana endurance willpower experience
[2] = got_room_name, -- eg. "Continuing on the Parade of Zarathustra"
[3] = got_room_exit, -- eg. "n,s"
[4] = got_room_number, -- eg. "401"
[5] = got_room_full_exits, -- eg. "ne(8564),w(8428)"
[6] = got_environment, -- eg. "Urban"
[7] = got_coordinates, -- eg. "38,3,1,0"
[8] = got_info, -- eg. "shops,postoffice"
}
function OnPluginBroadcast (msg, id, name, text)
if id == "85f72d0e263d75df7bde6f00" then
local f = handlers [msg]
if f then
f (text)
end -- have handler
end -- if ATCP message
end

function map_find (name, line, wildcards)
local rooms = {}
local count = 0
-- find matching rooms using FTS3
for row in db:nrows(string.format ("SELECT uid, name FROM rooms_lookup WHERE rooms_lookup MATCH %s", fixsql (wildcards [1]))) do
rooms [row.uid] = true
count = count + 1
end -- finding room
-- see if nearby
mapper.find (
function (uid)
local room = rooms [uid]
if room then
rooms [uid] = nil
end -- if
return room, next (rooms) == nil
end, -- function
show_vnums, -- show vnum?
count, -- how many to expect
false -- don't auto-walk
)
end -- map_find


function map_find_special (which_ones)

local wanted_items = {}

for _, v in ipairs (which_ones) do
wanted_items [v:lower ()] = true
end
local rooms = {}
local count = 0
-- build table of special places (with info in them)
for row in db:nrows(string.format ("SELECT uid, name, info FROM rooms WHERE info IS NOT NULL")) do
if row.info ~= "" then
local wanted = false
local t = {}
for item in string.gmatch (row.info, "[^,]+") do
if wanted_items [item:lower ()] then
wanted = true
table.insert (t, capitalize (item))
end -- if
end -- for
if wanted then
rooms [row.uid] = table.concat(t, ", ")
count = count + 1
end -- if
end -- if
end -- finding room
-- find such places
mapper.find (
function (uid)
local room = rooms [uid]
if room then
rooms [uid] = nil
end -- if
return room, next (rooms) == nil -- room will be type of info (eg. shop)
end, -- function
show_vnums, -- show vnum?
count, -- how many to expect
false -- don't auto-walk
)
end -- map_find_special

--[[
for _, v in ipairs ({
-- "guild", "healer", "trainer", "questor",
}) do wanted_items [v] = true end
--]]
function map_shops (name, line, wildcards)
map_find_special { "shop", "postoffice", "bank", "newsroom", }
end -- map_shops

function map_trainers (name, line, wildcards)
map_find_special { "trainer", }
end -- map_trainers

function map_quests (name, line, wildcards)
map_find_special { "questor", }
end -- map_quests

function map_healers (name, line, wildcards)
map_find_special { "healers", }
end -- map_healers

function map_goto (name, line, wildcards)

local wanted = wildcards [1]
if current_room and wanted == current_room then
mapper.mapprint ("You are already in that room.")
return
end -- if
-- find desired room
mapper.find (
function (uid)
return uid == wanted, uid == wanted
end, -- function
show_vnums, -- show vnum?
1, -- how many to expect
true -- just walk there
)
end -- map_goto

function map_where (name, line, wildcards)

if not mapper.check_we_can_find () then
return
end -- if

local wanted = wildcards [1]
if current_room and wanted == current_room then
mapper.mapprint ("You are already in that room.")
return
end -- if
local paths = mapper.find_paths (current_room,
function (uid)
return uid == wanted, -- wanted room?
uid == wanted -- stop searching?
end)

local uid, item = next (paths, nil) -- extract first (only) path
-- nothing? room not found
if not item then
mapper.mapprint (string.format ("Room %s not found", wanted))
return
end -- if
-- turn into speedwalk
local path = mapper.build_speedwalk (item.path)
-- display it
mapper.mapprint (string.format ("Path to %s is: %s", wanted, path))
end -- map_where

function map_resume (name, line, wildcards)

local wanted = mapper.last_hyperlink_uid or mapper.last_speedwalk_uid
if not wanted then
mapper.print "No outstanding speedwalks or hyperlinks."
return
end -- if nothing to do
-- find desired room
mapper.find (
function (uid)
return uid == wanted, uid == wanted
end, -- function
show_vnums, -- show vnum?
1, -- how many to expect
true -- just walk there
)
end -- map_resume

function map_bookmarks (name, line, wildcards)

local rooms = {}
local count = 0
-- build table of special places (with info in them)
for row in db_bm:nrows(string.format ("SELECT uid, notes FROM bookmarks")) do
rooms [row.uid] = capitalize (row.notes)
count = count + 1
end -- finding room
-- find such places
mapper.find (
function (uid)
local room = rooms [uid]
if room then
rooms [uid] = nil
end -- if
return room, next (rooms) == nil -- room will be type of info (eg. shop)
end, -- function
show_vnums, -- show vnum?
count, -- how many to expect
false -- don't auto-walk
)
end -- map_bookmarks

function map_areas (name, line, wildcards)

local wanted_areas = {}
local count = 0
if next (areas) == nil then
mapper.maperror "No areas known."
return
end -- if
-- build table of all areas, keyed by area code
for k, v in pairs (areas) do
wanted_areas [k] = v
count = count + 1
end -- for
-- find all areas
mapper.find (
function (uid)
local room = rooms [uid]
local reason
-- if this room is in the list of wanted areas then save its path
if wanted_areas[room.area] then
reason = wanted_areas [room.area]
wanted_areas [room.area] = nil
end -- found one!
return reason, next (wanted_areas) == nil
end, -- function
show_vnums, -- show vnum?
count, -- how many to expect
false -- don't auto-walk
)
end -- map_areas


valid_direction = {
n = "n",
s = "s",
e = "e",
w = "w",
u = "u",
d = "d",
ne = "ne",
sw = "sw",
nw = "nw",
se = "se",
north = "n",
south = "s",
east = "e",
west = "w",
up = "u",
down = "d",
northeast = "ne",
northwest = "nw",
southeast = "se",
southwest = "sw",
['in'] = "in",
out = "out",
} -- end of valid_direction
-- try to detect when we send a movement command
function OnPluginSent (sText)
if valid_direction [sText] then
last_direction_moved = valid_direction [sText]
-- print ("Just moved", last_direction_moved)
if current_room and rooms [current_room] then
expected_exit = rooms [current_room].exits [last_direction_moved]
if expected_exit then
from_room = current_room
end -- if
-- print ("expected exit for this direction is to room", expected_exit)
end -- if
end -- if
end -- function

function OnPluginConnect ()
mapper.cancel_speedwalk ()
-- DoAfter (3, "look") -- force mapper update
end -- OnPluginConnect

function OnPluginDisconnect ()
mapper.cancel_speedwalk ()
end -- OnPluginConnect

function OnHelp ()
mapper.mapprint (string.format ("[MUSHclient mapper, version %0.1f]", mapper.VERSION))
mapper.mapprint (world.GetPluginInfo (world.GetPluginID (), 3))
end

function OnPluginListChanged ()
do_plugin_check_now ("85f72d0e263d75df7bde6f00", "ATCP_NJG") -- check we have ATCP plugin
end -- OnPluginListChanged

]]>
</script>

</muclient>
Something went wrong with that request. Please try again.