· 6 years ago · Mar 07, 2019, 05:58 AM
1<?xml version="1.0" encoding="iso-8859-1"?>
2<!DOCTYPE muclient>
3<!-- Saved on Monday, April 26, 2018, 7:21 AM -->
4<!-- MuClient version 4.51 -->
5<!DOCTYPE muclient [
6 <!ENTITY show_vnums "true" >
7 <!ENTITY show_timing "false" >
8 <!ENTITY show_completed "false" >
9 <!ENTITY show_database_mods "true" >
10 <!ENTITY show_other_areas "true" >
11 <!ENTITY show_area_exits "true" >
12 <!ENTITY show_up_down "false" >
13 <!ENTITY speedwalk_prefix "" >
14]>
15<!-- Plugin "AlterAeonMapper" generated by Plugin Wizard -->
16
17<muclient>
18<plugin
19 name="DemonMUSH_Mapper"
20 author="Master Vivi, Endymion, Valour"
21 id="dd07d6dbe73fe0bd02ddb63d"
22 language="Lua"
23 purpose="Shows the mapper for Alter Aeon"
24 save_state="y"
25 date_written="2010-04-26 07:21:01"
26 requires="4.51"
27 version="1.0"
28 >
29
30</plugin>
31
32<aliases>
33
34 <!-- zooming aliases -->
35
36 <alias
37 match="mapper zoom out"
38 enabled="y"
39 sequence="100"
40 omit_from_command_history="y"
41 omit_from_output="y"
42 script="mapper.zoom_out"
43 >
44 </alias>
45
46<alias
47 match="mapper zoom in"
48 enabled="y"
49 sequence="100"
50 omit_from_command_history="y"
51 omit_from_output="y"
52 script="mapper.zoom_in"
53 >
54 </alias>
55<alias
56 match="mapper thisroom"
57 enabled="y"
58 sequence="100"
59 script="show_this_room"
60 regexp="n">
61</alias>
62<alias
63 match="^mapper addnote( .*)?$"
64 regexp="y"
65 enabled="y"
66 sequence="100"
67 send_to="12"
68>
69<send>
70 room_edit_note(nil,nil,Trim("%1"))
71</send>
72</alias>
73<alias
74 match="^mapper next( .*)?$"
75 enabled="y"
76 regexp="y"
77 sequence="100"
78 send_to="12"
79>
80<send>
81mapper.gotoNextResult(Trim("%1"))
82</send>
83</alias>
84
85 <!-- show/hide mapper -->
86
87 <alias
88 match="mapper hide"
89 enabled="y"
90 sequence="100"
91 script="mapper.hide"
92 >
93 </alias>
94
95 <alias
96 match="mapper show"
97 enabled="y"
98 sequence="100"
99 script="mapper.show"
100 >
101 </alias>
102<alias
103 match="^mapper help( (.*))?$"
104 enabled="y"
105 regexp="y"
106 script="OnHelp"
107></alias>
108
109<alias
110 match="^mapper updown$"
111 enabled="y"
112 regexp="y"
113 send_to="12"
114>
115<send>
116 mapper.show_up_down = not mapper.show_up_down
117 mapper.draw (current_room)
118</send>
119</alias>
120
121<alias
122 match="^mapper underlines?$"
123 enabled="y"
124 regexp="y"
125 send_to="12"
126>
127<send>
128 NoUnderline_hyperlinks = not NoUnderline_hyperlinks
129 Note("Mapper hyperlinks will " ..(NoUnderline_hyperlinks and "no longer" or "now").." be underlined.")
130 SetVariable("NoUnderline_hyperlinks", NoUnderline_hyperlinks and "1" or "0")
131</send>
132</alias>
133 <alias
134 match="mapper goto *"
135 enabled="y"
136 sequence="100"
137 script="map_goto"
138 >
139 </alias>
140<alias
141 match="mapper find *"
142 enabled="y"
143 sequence="100"
144 script="map_find"
145 regexp="n"
146></alias>
147<alias
148 match="mapper findpath * *"
149 enabled="y"
150 sequence="100"
151 omit_from_output="y"
152 script="findpathfast"
153></alias>
154
155 <alias
156 match="mapper where *"
157 enabled="y"
158 sequence="100"
159 script="map_where"
160 >
161 </alias>
162 <alias
163 match="mapper backup"
164 enabled="y"
165 sequence="100"
166 script="backup_db"
167 >
168 </alias>
169 <alias
170 match="^mapper delete room (\d+)$"
171 enabled="y"
172 regexp="y"
173 script="delete_room_alias"
174>
175</alias>
176<alias
177 match="^mapper delete area (.+)$"
178 enabled="y"
179 regexp="y"
180 script="delete_area_alias"
181>
182</alias>
183
184
185</aliases>
186
187
188<!-- Triggers -->
189
190<triggers>
191 <trigger
192 enabled="y"
193 match="kxwt_rshort *"
194 name="process_room_name"
195 sequence="100"
196 send_to="14"
197 >
198 <send>
199 name="%1"
200 if rooms ~= nil and
201 rooms[uid] ~= nil and
202 rooms[uid].notes ~= nil and
203 rooms[uid].notes ~= ""
204 then
205 mapper.mapprint("Note:", rooms[uid].notes)
206 end
207 </send>
208 </trigger>
209 <trigger
210 enabled="y"
211 match="kxwt_rvnum *"
212 name="process_room_desc"
213 sequence="100"
214 script="room_number"
215 >
216 </trigger>
217 <trigger
218 enabled="y"
219 match="kxwt_walkdir *"
220 name="moved_direction"
221 sequence="100"
222 script="moved_direction"
223 >
224 </trigger>
225 <trigger
226 enabled="y"
227 match="kxwt_terrain *"
228 name="process_terrain"
229 sequence="100"
230 send_to="14"
231 >
232 <send>terrain="%1"</send>
233 </trigger>
234 <trigger
235 enabled="y"
236 match="kxwt_area * *"
237 name="process_area"
238 sequence="100"
239 send_to="14"
240 >
241 <send>area="%2"</send>
242 </trigger>
243 <trigger
244 enabled="y"
245 match="[Exits: *]"
246 name="Exits_Line"
247 sequence="100"
248 send_to="14"
249 >
250 <send>process_exits("%1")</send>
251 </trigger>
252 <trigger
253 enabled="y"
254 match="Alas, you cannot go that way."
255 script="mapper.cancel_speedwalk"
256 sequence="100"
257 ></trigger>
258 <trigger
259 enabled="y"
260 match="* would be left behind."
261 script="mapper.cancel_speedwalk"
262 sequence="100"
263 ></trigger>
264 <trigger
265 enabled="y"
266 match="You are too exhausted to continue your stealthy movement!"
267 script="mapper.cancel_speedwalk"
268 sequence="100"
269 ></trigger>
270 <trigger
271 enabled="y"
272 match="You are too exhausted."
273 script="mapper.cancel_speedwalk"
274 sequence="100"
275 ></trigger>
276 <trigger
277 enabled="y"
278 match="You follow * *."
279 script="mapper.cancel_speedwalk"
280 sequence="100"
281 ></trigger>
282 <trigger
283 enabled="y"
284 match="You'll have to climb to go there."
285 script="mapper.cancel_speedwalk"
286 sequence="100"
287 ></trigger>
288 <trigger
289 enabled="y"
290 match="You can't just walk away from a fight!"
291 script="mapper.cancel_speedwalk"
292 sequence="100"
293 ></trigger>
294 <trigger
295 enabled="y"
296 match="The * is closed."
297 script="mapper.cancel_speedwalk"
298 sequence="100"
299 ></trigger>
300 <trigger
301 enabled="y"
302 match="* blocks your path, preventing you from passing."
303 script="mapper.cancel_speedwalk"
304 sequence="100"
305 ></trigger>
306 <trigger
307 enabled="y"
308 match="^The (door|gate) is closed\.$"
309 regexp="y"
310 name="Door_Closed"
311 script="Door_Closed"
312 sequence="100"
313 >
314 </trigger>
315 <trigger
316 enabled="y"
317 match="The wooden door is closed."
318 regexp=""
319 name="woodendoor_closed"
320 script="Door_Closed"
321 sequence="100"
322 >
323 </trigger>
324</triggers>
325
326<!-- Timers -->
327
328<timers>
329 <timer
330 name="backup_timer"
331 enabled="y"
332 script="backup_db"
333 hour="7" minute="59" second="59"
334 active_closed="y" >
335 </timer>
336</timers>
337
338<!-- Script -->
339
340
341<script>
342local show_other_areas = &show_other_areas;
343<![CDATA[
344
345mapper = require "altermapper"
346require "serialize"
347require "copytable"
348uid = 0
349current_room=nil
350current_area = 0
351expected_exit=-666
352from_room=""
353last_direction_moved=nil
354terrain = 0
355area = 0
356last_backup = GetVariable("last_backup") or 0
357notes = 0
358default_width = 269
359default_height = 335
360local posx = 100
361local posy = 100
362local DIFFERENT_AREA_COLOUR = "#ff0000"
363
364
365count = 0
366roomcount = 0
367rooms = {}
368local user_terrain_colour = {}
369
370local kxwt_dirs = {
371 ["0"] = "n",
372 ["2"] = "s",
373 ["4"] = "ne",
374 ["6"] = "sw",
375 ["5"] = "se",
376 ["7"] = "nw",
377 ["3"] = "w",
378 ["1"] = "e",
379 ["20"] = "u",
380 ["30"] = "d",
381 ["99"] = "unk" -- idk what to do here (nothing?) (i'm not sure either, maybe wait till it happens and you can duplicate it)
382}
383
384valid_direction = {
385n = "n",
386s = "s",
387e = "e",
388w = "w",
389u = "u",
390d = "d",
391ne = "ne",
392sw = "sw",
393nw = "nw",
394no="n",
395ea="e",
396so="s",
397we="w",
398se = "se",
399north = "n",
400south = "s",
401east = "e",
402west = "w",
403up = "u",
404down = "d",
405northeast = "ne",
406northwest = "nw",
407southeast = "se",
408southwest = "sw",
409['in'] = "in",
410out = "out",
411} -- end of valid_direction
412
413
414terrain_color = {}
415
416-----------------------------------------
417-- ADDIING TRIGGER STUFF
418-----------------------------------------
419
420function room_number(name, line, args)
421 uid = args[1] -- this was in the <send> previously
422 from_room = current_room or ""
423 current_room = args[1]
424end
425
426function moved_direction(name, line, args)
427 last_direction_moved = kxwt_dirs[args[1]] or "unk"
428end
429
430
431
432-----------------------------------------
433-- DONE ADDING TRIGGER STUFF
434-----------------------------------------
435
436function room_edit_note(room, vuid, newnotes)
437 if vuid == nil and current_room ~= nil then
438 vuid = current_room
439 room = rooms[vuid]
440 end
441
442 if vuid == nil then -- still nothing?
443 print("No room received from the mud yet. Try using the 'LOOK' command first.")
444 return
445 end
446
447 if newnotes == nil or newnotes == "" then
448 if room.notes ~= nil and room.notes ~= "" then
449 newnotes = utils.inputbox("Modify room comment (clear it to delete from database)", room.name, room.notes)
450 else
451 newnotes = utils.inputbox("Enter room comment (creates a note for this room)", room.name, room.notes)
452 end -- if
453 end
454
455 if not newnotes then
456 return
457 end -- if cancelled
458
459 if newnotes == "" then
460 if room.notes == nil or room.notes == "" then
461 mapper.mapprint("No comment entered, note not saved.")
462 return
463 else
464 mapper.mapprint("Note from room " .. current_room .. " deleted. Was previously: " .. room.notes)
465 rooms[current_room].notes = ""
466 add_update_room(current_room, rooms[current_room])
467 mapper.draw(current_room)
468 end
469 end
470
471 if rooms[current_room].notes == newnotes then
472 return -- no change made
473 end
474
475 local oldNote = room.note
476
477 rooms[current_room].notes = newnotes
478 add_update_room(current_room, rooms[current_room])
479 mapper.draw(current_room)
480
481 if oldNote ~= nil and #oldNote > 0 then
482 mapper.mapprint("Note for room", current_room, "changed to:", newnotes)
483 else
484 mapper.mapprint("Note added to room", current_room, ":", newnotes)
485 end
486end
487
488
489-- -----------------------------------------------------------------
490-- Here on "Exits:" line ----- we have changed rooms
491-- -----------------------------------------------------------------
492
493function process_exits (exits_str)
494 --Note("process exits")
495 if current_room == from_room then
496 --Note(current_room, ", ", from_room)
497 --Note("same room")
498 --return
499 end
500
501 -- genereate a "room ID" by hashing the room name, description and exits
502 -- break up exits into individual directions
503 exits = {}
504
505 for exit in string.gmatch (exits_str, "%w+") do
506 local ex = valid_direction [exit]
507 if ex then
508 exits [ex] = "-666" -- don't know where it goes yet
509 end -- if
510 end -- for
511
512 -- add to table if not known
513 --Note("add room to table")
514 if not rooms [uid] then
515 rooms [uid] = { name = name, desc = uid, exits = exits, area=area, fillcolour=terrain_color[terrain], fillbrush=0, bordercolour=0xffffff }
516 add_update_room(uid, rooms[uid])
517 end -- if
518
519 -- save so we know current room later on
520 current_room = uid
521
522 -- add exit into mapper
523 --Note("add exit")
524 if from_room ~= "" and last_direction_moved then -- we were in a room # that we got from kxwt, and then moved to another room
525 --Note("rooms[", from_room, "].exits[", last_direction_moved, "] = ", current_room)
526 rooms[from_room].exits[last_direction_moved] = current_room
527 add_update_room(from_room, rooms[from_room])
528 last_direction_moved = nil -- remove last direction so updating a room only happens when we walk somewhere
529 end
530
531 -- call mapper to draw this room
532 mapper.draw (uid)
533
534end -- process_exits
535
536-- -----------------------------------------------------------------
537-- Here on white coloured line - this is a room name or room exits
538-- -----------------------------------------------------------------
539
540function Name_Or_Exits (name, line, wildcards)
541
542 exits = string.match (line, "^Exits: (.*)")
543
544 if exits then
545 process_exits (exits)
546 end -- if
547
548 roomname = line
549 roomdesc = nil
550
551end -- Name_Or_Exits
552
553-- -----------------------------------------------------------------
554-- Here on yellow line - part of room description
555-- -----------------------------------------------------------------
556
557function Name_Line (name, line, wildcards)
558 roomdesc = (roomdesc or "" ) .. line .. "\n"
559end -- Name_Or_Exits
560-- -----------------------------------------------------------------
561-- for converting things like ^ $ * etc. into "escaped" sequences
562-- -----------------------------------------------------------------
563function fix_regexp_magic_characters (r)
564 return string.gsub (r, "[%^%$%(%)%%%.%[%]%*%+%-%?]", "%%%1")
565end -- fix_regexp_magic_characters
566
567-- -----------------------------------------------------------------
568-- mapper 'get_room' callback - it wants to know about room uid
569-- -----------------------------------------------------------------
570
571function get_room (uid)
572
573
574 if not rooms [uid] then
575 return nil
576 end -- if
577
578 local room = copytable.deep (rooms [uid])
579 local notes = ""
580 if room.notes and room.notes ~= "" then
581 notes = "\nNote: " .. room.notes
582 end -- if notes
583
584 local texits = {}
585 for dir in pairs (room.exits) do
586 table.insert (texits, dir)
587 end -- for
588 table.sort (texits)
589
590 if uid == current_room then
591 current_area = room.area
592 end -- if
593
594 room.hovermessage = string.format (
595"%s\tExits: %s\nRoom: %s\nArea: %s \nTerrain: %s%s",
596 room.name,
597 table.concat (texits, ", "),
598 uid,
599 area,
600 terrain,
601 notes
602 -- depth,
603 -- table.concat (path, ",")
604 )
605
606 if uid == current_room then
607 room.bordercolour = ColourNameToRGB "red"
608 room.borderpenwidth = 2
609 elseif room.area ~= current_area then
610 room.bordercolour = ColourNameToRGB "red"
611 end -- not in this area
612
613 return room
614
615
616end -- get_room
617
618function show_this_room (name, line, wildcards)
619 local room = rooms[current_room]
620 if room ~= nil then
621 Note("Details about this room:")
622 Note("+---------------------------+")
623 Note("Name: "..(name or ""))
624 Note("ID: "..(uid or ""))
625 Note("Area: "..(area or ""))
626 Note("Terrain: "..(terrain or ""))
627 Note("Info: "..(room.info or ""))
628 Note("Notes: "..(room.notes or ""))
629 Note("Exits: "..(room.exits or ""))
630else
631 Note("THISROOM ERROR: You need to type 'LOOK' first to initialize the mapper before trying to get room information.")
632 end
633end -- show_this_room
634
635function room_click (uid, flags)
636
637 -- check we got room at all
638 if not uid then
639 return nil
640 end -- if
641
642 -- look it up
643 local room = rooms [uid]
644
645 -- not cached - see if in database
646 if not room then
647return
648 end -- not in cache
649
650 if not room then
651 return
652 end -- if still not there
653
654 local handlers = {}
655 table.insert(handlers, { name = "Edit Note", func = room_edit_note})
656 table.insert(handlers, { name = "Edit Terrain Colour", func = room_edit_terrain_colour})
657 table.insert(handlers, { name = "-", })
658
659 table.insert(handlers, { name = ">Change Exit", })
660 for ex, to in pairs(room.exits) do
661 table.insert(handlers, { name = ex.." -> "..to, func = room_change_exit, param = ex})
662 end
663
664 table.insert(handlers, { name = "<", })
665
666 table.insert(handlers, { name = "-", })
667 table.insert(handlers, { name = (room.ignore_exits_mismatch and "+" or "").."Ignore Exits Mismatch Here", func = ignore_mismatch_toggle, param = room.ignore_exits_mismatch})
668 table.insert(handlers, { name = ">Delete Exit", })
669 for ex, to in pairs(room.exits) do
670 table.insert(handlers, { name = ex.." -> "..to, func = room_delete_exit, param = ex})
671 end
672 table.insert(handlers, { name = "<", })
673
674 table.insert(handlers, { name = "Delete Room", func = room_purgeroom})
675
676 rc, a, b, c = CallPlugin("60840c9013c7cc57777ae0ac", "getCurrentState")
677 if rc == 0 and a == true then
678 if b == 1 then
679 table.insert(handlers, {name = "-"})
680 table.insert(handlers, {name = "Show Continent Bigmap", func = function() Execute("bigmap on") end })
681 elseif c == 1 then
682 table.insert(handlers, {name = "-"})
683 table.insert(handlers, {name = "Merge Continent Bigmap Into GMCP Mapper", func = function() Execute("bigmap merge") end })
684 end
685 end
686 local t, tf = {}, {}
687 for i, v in ipairs(handlers) do
688 table.insert (t, v.name)
689 if v.func then
690 table.insert(tf, v)
691 end
692 end -- for
693
694 local choice = WindowMenu (mapper.win,
695 WindowInfo (mapper.win, 14),
696 WindowInfo (mapper.win, 15),
697 "!"..table.concat (t, "|"))
698
699 if choice ~= "" then
700 local f = tf[tonumber(choice)]
701 if f then
702 f.func(room, uid, f.param)
703 end -- if handler found
704 end
705end -- room_click
706
707
708-- -----------------------------------------------------------------
709-- map_find: mapper find xxx
710-- -----------------------------------------------------------------
711function map_find (name, line, wildcards)
712
713 mapper.mapprint (string.rep ("-", 25) .. " Mapper search " .. string.rep ("-", 25))
714
715 local reset = ANSI (0)
716 local bold = ANSI (1)
717 local unbold = ANSI (22)
718
719 local matches = { }
720 local count = 0
721 local target = Trim (wildcards [1]:lower ())
722
723 if target == "" then
724 mapper.maperror ("No search string specified")
725 return
726 end -- if
727
728 if not mapper.check_we_can_find () then
729 return
730 end -- if find not OK
731
732 -- fix up any regular expression "magic" letters to be escaped by a %
733 local fixed_target = fix_regexp_magic_characters (target)
734
735 -- fix up for caseless searches in the room description (eg. "a" becomes "[aA]")
736 local caseless_target = string.gsub (fixed_target, "(%a)", function (a)
737 return "[" .. a:lower () .. a:upper () .. "]"
738 end -- function
739 )
740
741 -- do a simple string search to find matching rooms
742 for k, v in pairs (rooms) do
743
744 -- don't want nil descriptions
745 if not v.description then
746 v.description = ""
747 end -- if no description
748
749 if string.find (v.name:lower (), fixed_target) or
750 string.find (v.description:lower (), fixed_target) then
751 matches [k] = true
752 count = count + 1
753 end -- if match
754 end -- for each room
755
756 local function show_snippet (uid)
757 local room = rooms [uid]
758 if not room then
759 return
760 end -- if
761
762 -- don't bother if the wanted words was in the room name
763 if string.find (room.name:lower (), fixed_target) then
764 return
765 end -- if
766
767 -- otherwise show the wanted word in the description, in bold
768 AnsiNote (reset .. string.gsub (room.description, caseless_target, bold .. "%1" .. unbold))
769
770 end -- show_snippet
771
772 -- see if nearby
773 mapper.find (
774 function (uid)
775 local room = matches [uid]
776 if room then
777 matches [uid] = nil
778 end -- if
779 return room, next (matches) == nil
780 end, -- function
781 show_vnums, -- show vnum?
782 count, -- how many to expect
783 false, -- don't auto-walk
784 show_snippet -- show find snippet
785 )
786end -- map_find
787
788
789
790-- -----------------------------------------------------------------
791-- map_goto for: mapper goto xxx
792-- -----------------------------------------------------------------
793function map_goto (name, line, wildcards)
794 local wanted = wildcards [1]
795 -- check valid string
796 if string.match (wanted, "%D") then
797 mapper.maperror ("Room number must be numeric, you entered: " .. wanted)
798 return
799 end -- if
800
801 -- see if already there
802 if current_room and string.match (current_room, "^" .. wanted) then
803 mapper.mapprint ("You are already in that room.")
804 return
805 end -- if
806 -- find desired room
807 mapper.find (
808 function (uid)
809 local found = string.match (uid, "^" .. wanted)
810 return found, found
811 end, -- function
812 show_vnums, -- show vnum?
813 1, -- how many to expect
814 true -- just walk there
815 )
816end -- map_goto
817
818-- -----------------------------------------------------------------
819-- map_where: Show where a room is
820-- -----------------------------------------------------------------
821function map_where (name, line, wildcards)
822 if not mapper.check_we_can_find () then
823 return
824 end -- if
825 local wanted = wildcards [1]
826 if current_room and wanted == current_room then
827 mapper.mapprint ("You are already in that room.")
828 return
829 end -- if
830 local paths = mapper.find_paths (current_room,
831 function (uid)
832 return uid == wanted, -- wanted room?
833 uid == wanted -- stop searching?
834 end)
835 local uid, item = next (paths, nil) -- extract first (only) path
836 -- nothing? room not found
837 if not item then
838 mapper.mapprint (string.format ("Room %s not found", wanted))
839 return
840 end -- if
841 -- turn into speedwalk
842 local path = mapper.build_speedwalk (item.path)
843 -- display it
844 mapper.mapprint (string.format ("Path to %s is: %s", wanted, path))
845end -- map_where
846
847-- -----------------------------------------------------------------
848-- cannot_walk - we tried to walk but failed
849-- -----------------------------------------------------------------
850function cannot_walk (name, line, wildcards)
851 mapper.cancel_speedwalk ()
852 room_description = nil
853 current_exits = nil
854 room_name = nil
855 last_direction_moved = nil
856-- mapper.mapprint ("Attempt to walk cancelled.")
857
858end -- cannot_walk
859
860function confirm_delete_area(a)
861 response = utils.umsgbox("Delete area: "..a.."?", "Delete Area", "okcancel", "?", 2)
862 if response == "ok" then
863 delete_area(a)
864 end
865end
866
867function Door_Closed (name, line, wildcards)
868
869local dirs = {
870 n = "north",
871 s = "south",
872 e = "east",
873 w = "west",
874 u = "up",
875 d = "down",
876 ne = "northeast",
877 sw = "southwest",
878 nw = "northwest",
879 se = "southeast",
880 ['in'] = "in",
881 out = "out",
882 } -- end of available
883
884 if last_direction_moved then
885 Send ("open " .. dirs [last_direction_moved])
886 Send (dirs [last_direction_moved])
887 end -- if
888
889end -- Door_Closed
890
891
892-- -----------------------------------------------------------------
893-- check_for_cannot_go - look up the line in a table of failure messages
894-- see table: cannot_move_messages
895-- -----------------------------------------------------------------
896function check_for_cannot_go (name, line, wildcards)
897
898 for _, v in ipairs (cannot_move_messages) do
899 if string.find (line, v) then
900 cannot_walk ()
901 break
902 end -- if match
903 end -- for each message
904end -- check_for_cannot_go
905
906function findpathfast(name, line, wildcards)
907 local src = wildcards[1]
908 local dest = wildcards[2]
909 rooms[src] = load_room_from_database(src)
910 rooms[dest] = load_room_from_database(dest)
911
912 if rooms[src] == nil then
913 mapper.mapprint (string.format ("Room %s not known.", src))
914 end
915 if rooms[dest] == nil then
916 mapper.mapprint (string.format ("Room %s not known.", dest))
917 end
918 if rooms[src] == nil or rooms[dest] == nil then
919 return
920 end
921
922 local foundpath = findpath(src, dest)
923 if foundpath == nil then
924 mapper.mapprint (string.format ("Path from %s to %s not found.", wildcards[1], wildcards[2]))
925 return
926 end
927
928 -- turn into speedwalk
929 local speedwalk = mapper.build_speedwalk (foundpath, speedwalk_prefix)
930
931 -- display it
932 if speedwalk ~= nil then
933 mapper.mapprint (string.format ("Path from %s to %s is: %s", wildcards[1], wildcards[2], speedwalk))
934 else
935 mapper.mapprint ("Pick different start and end rooms.")
936 end
937end
938
939function blackindigoPrint(msg)
940 ColourNote("blueviolet","black",msg)
941end
942function blackredPrint(msg)
943 ColourNote("black","red",msg)
944end
945function whiteindigoPrint(msg)
946 ColourNote("white","indigo",msg)
947end
948
949
950function setup_terrain_colors()
951terrain_color["0"]=tonumber("0x000000")--NOTSET
952terrain_color["1"]=tonumber("0x606060")--Building
953terrain_color["2"]=tonumber("0x805a22")--Town
954terrain_color["3"]=tonumber("0x00ff00")--FIELD
955terrain_color["4"]=tonumber("0x00c000")--LFOREST
956terrain_color["5"]=tonumber("0x008000")--TFOREST
957terrain_color["6"]=tonumber("0x004000")--DFOREST
958terrain_color["7"]=tonumber("0x406080")--SWAMP
959terrain_color["8"]=tonumber("0x60a060")--PLATEAU
960terrain_color["9"]=tonumber("0x00ffff")--SANDY
961terrain_color["10"]=tonumber("0xc0c0c0")--MOUNTAIN
962terrain_color["11"]=tonumber("0x808080")--ROCK
963terrain_color["12"]=tonumber("0x00ffff")--DESERT
964terrain_color["13"]=tonumber("0x805080")--TUNDRA
965terrain_color["14"]=ColourNameToRGB("lightyellow")--BEACH
966terrain_color["15"]=tonumber("0x409040")--HILL
967terrain_color["16"]=ColourNameToRGB("navajowhite")--DUNES
968terrain_color["17"]=tonumber("0x20c040")--JUNGLE
969terrain_color["18"]=ColourNameToRGB("darkblue")--OCEAN
970terrain_color["19"]=tonumber("0x00f0f0")--STREAM
971terrain_color["20"]=ColourNameToRGB("blue")--RIVER
972terrain_color["21"]=tonumber("0x021e6c")--UNDERWATER
973terrain_color["22"]=tonumber("0x303030")--UNDERGROUND
974terrain_color["23"]=ColourNameToRGB("lightskyblue")--AIR
975terrain_color["24"]=tonumber("0x82f8e6")--ICE
976terrain_color["25"]=ColourNameToRGB("red")--LAVA
977terrain_color["26"]=tonumber("0x806060")--RUINS
978terrain_color["27"]=tonumber("0x404040")--CAVE
979terrain_color["28"]=tonumber("0x907040")--CITY
980terrain_color["29"]=tonumber("0x20a060")--MARSH
981terrain_color["30"]=tonumber("0xf0f0a0")--WASTELAND
982terrain_color["31"]=tonumber("0xffffff")--CLOUD
983terrain_color["32"]=ColourNameToRGB("blue")--WATER
984terrain_color["33"]=tonumber("0x808080")--METAL
985terrain_color["34"]=tonumber("0x006000")--TAIGA
986terrain_color["35"]=tonumber("0x404040")--SEWER
987terrain_color["36"]=ColourNameToRGB("indigo")--SHADOW
988terrain_color["37"]=ColourNameToRGB("indigo")--CATACOMB
989terrain_color["38"]=ColourNameToRGB("olivedrab")--MIRE
990terrain_color["39"]=ColourNameToRGB("indigo")--CRYSTAL
991 -- end of terrain_color
992end
993
994-- -----------------------------------------------------------------
995-- Plugin Install
996-- -----------------------------------------------------------------
997
998function OnPluginInstall ()
999
1000 config = {} -- in case not found
1001 setup_terrain_colors()
1002
1003 -- get saved configuration
1004 assert (loadstring (GetVariable ("config") or "")) ()
1005
1006 -- and rooms
1007 --assert (loadstring (GetVariable ("rooms") or "")) ()
1008
1009 -- new stuff for sql data
1010 check_create_db()
1011 load_rooms()
1012
1013 -- initialize mapper
1014
1015 mapper.init { config = config,
1016 get_room = get_room, findpath = findpath,
1017 room_click = room_click, -- called on RH click on room square,
1018 show_help = OnHelp, -- to show help,
1019 show_other_areas = show_other_areas, -- want to see areas other than the current one?
1020}
1021 mapper.mapprint (string.format ("MUSHclient mapper installed, version %0.1f", mapper.VERSION))
1022
1023end -- OnPluginInstall
1024
1025function OnHelp (name, line, wildcards)
1026 local help_header = " [Demon Mush Mapper Help] "
1027
1028 local help_index = [[
1029 Mapper Help Index
1030=============================================================================
1031 mapper help --> Show this list
1032-----------------------------------------------------------------------------
1033 mapper help config --> Commands for configuring the mapper
1034 mapper help moving --> Commands for moving between rooms
1035 mapper help utils --> Other utilitarian commands
1036 mapper help searching --> Used for finding notes, shops, guildmasters, etc
1037=============================================================================
1038]]
1039 local help_table = {
1040 ['config'] = {
1041['header'] = [[===== CONFIGURATION =============>]],
1042[[mapper help --> This help
1043 > (or click the "?" button on the top right)]],
1044[[mapper zoom out --> Zoom out]],
1045[[mapper zoom in --> Zoom in]],
1046[[mapper hide --> Hide map]],
1047[[mapper show --> Show map]],
1048[[mapper updown --> Toggle up/down exit drawing]],
1049[[mapper underlines --> Toggle underlining of clickable links]]
1050},
1051
1052 ['utils'] = {
1053['header'] = [[===== UTILITIES =================>]],
1054[[mapper backup --> Creates a backup of the mapper database]],
1055[[mapper addnote --> Add a new note to the current room]],
1056[[mapper addnote <note> --> Ditto, but skips the dialog]]
1057},
1058 ['searching'] = {
1059['header'] = [[===== SEARCHING =================>]],
1060[[mapper find <text> --> Full-text search the whole database]],
1061[[]],
1062[[mapper notes --> Show nearby rooms that you marked with notes]],
1063[[mapper notes <here/area> --> Ditto]],
1064[[mapper shops --> Show all shops/banks]],
1065[[mapper shops <here/area> --> Ditto]],
1066[[mapper train --> Show all trainers]],
1067[[mapper train <here/area> --> Ditto]],
1068[[mapper quest --> Show all quest-givers]],
1069[[mapper quest <here/area> --> Ditto]],
1070[[]],
1071[[mapper next --> Visit the next room in the most recent
1072 > list of results.]],
1073[[mapper next <index> --> Ditto, but skip to the given result index.]],
1074[[mapper where <room id> --> Show directions to a room number]]
1075},
1076
1077
1078 ['moving'] = {
1079['header'] = [[===== MOVING ====================>]],
1080[[mapper goto <room id> --> Run to a room by its room number]]
1081}
1082}
1083
1084 local function show_help(helps)
1085 blackindigoPrint("")
1086 blackindigoPrint(helps['header'])
1087 blackindigoPrint("")
1088 for i,v in ipairs(helps) do
1089 blackindigoPrint(v)
1090 end
1091 end
1092
1093 blackindigoPrint("")
1094 whiteindigoPrint(help_header)
1095 blackindigoPrint("+---------------------------------------------------------------------------+")
1096 badnews = true
1097 if wildcards and wildcards[2] ~= "" then
1098 badnews = false
1099 if wildcards[2] == "all" then
1100 show_help(help_table['config'])
1101 show_help(help_table['exits'])
1102 show_help(help_table['searching'])
1103 show_help(help_table['moving'])
1104 show_help(help_table['utils'])
1105 elseif wildcards[2] == "config" then
1106 show_help(help_table['config'])
1107 elseif wildcards[2] == "searching" then
1108 show_help(help_table['searching'])
1109 elseif wildcards[2] == "moving" then
1110 show_help(help_table['moving'])
1111 elseif wildcards[2] == "utils" then
1112 show_help(help_table['utils'])
1113 elseif wildcards[2]:find("search ") == 1 then
1114 local st, en = wildcards[2]:find("search ")
1115 local pattern = Trim(wildcards[2]:sub(en+1))
1116 ColourTell("cornflower","black","Searching help for: ")
1117 ColourNote("red","black",pattern)
1118 if pattern ~= "" then
1119 for k,v in pairs(help_table) do
1120 local done_header = false
1121 for j,w in ipairs(v) do
1122 if (w ~= "") and (w:find("--------",nil,true) == nil) and (w:find(pattern) ~= nil) then
1123 if not done_header then
1124 blackindigoPrint("")
1125 blackindigoPrint(v['header'])
1126 done_header = true
1127 end
1128 blackindigoPrint("")
1129 local wtable = w:split(pattern)
1130 for i,v in ipairs(wtable) do
1131 ColourTell("cornflower","black",v)
1132 if (i < #wtable) then
1133 ColourTell("red", "black", pattern)
1134 end
1135 end
1136 Note("")
1137 end
1138 end
1139 end
1140 else
1141 badnews = true
1142 end
1143 else
1144 badnews = true
1145 end
1146 end
1147 if badnews then
1148 blackindigoPrint("")
1149 mapper.mapprint (world.GetPluginInfo (world.GetPluginID (), 3))
1150 blackindigoPrint("")
1151 blackindigoPrint(help_index)
1152 end
1153 blackindigoPrint("")
1154 blackindigoPrint("+---------------------------------------------------------------------------+")
1155 blackindigoPrint("")
1156end
1157
1158
1159-- -----------------------------------------------------------------
1160-- Plugin Save State
1161-- -----------------------------------------------------------------
1162
1163function OnPluginSaveState ()
1164 mapper.save_state ()
1165 SetVariable ("config", "config = " .. serialize.save_simple (config))
1166 SetVariable("last_backup", last_backup)
1167end -- OnPluginSaveState
1168
1169------------------------------------------
1170-- start of sql additions
1171------------------------------------------
1172function delete_room_alias(name, line, wildcards)
1173 local num = wildcards[1]
1174 if num then
1175 delete_room(num)
1176 end
1177end
1178
1179function delete_area_alias(name, line, wildcards)
1180 local a = wildcards[1]
1181 if a then
1182 delete_area(a)
1183 end
1184end
1185
1186function delete_room(num) -- delete room from rooms
1187 for r, tbl in pairs(rooms) do -- for each room in table
1188 if tostring(r) == tostring(num) then
1189 rooms[r] = nil -- setting table item to nil deletes it
1190 end
1191 end
1192 run_sql([[DELETE FROM rooms WHERE uid = ']]..num..[[']])
1193 Note("Deleted ", num, ".")
1194 SendNoEcho("look")
1195end
1196
1197function delete_area(a)
1198 local cnt = 0
1199 for r, tbl in pairs(rooms) do -- for each room in table
1200 if tostring(tbl.area) == tostring(a) then
1201 rooms[r] = nil -- setting table item to nil deletes it
1202 cnt = cnt + 1
1203 end
1204 end
1205 run_sql([[DELETE FROM rooms WHERE area = ']]..fix_sql(a)..[[']])
1206 Note("Deleted ", cnt, " rooms in '", a, "' area.")
1207end
1208
1209function clean_file_name(f)
1210 f = string.gsub(f, "[^%w]", "")
1211 return f
1212end
1213
1214function fix_sql(s)
1215 if not s then -- nil value
1216 return ""
1217 end
1218 return string.gsub(s, "'", "''")
1219end
1220
1221function run_sql(sql)
1222 local db = assert(sqlite3.open(GetInfo(66)..clean_file_name(WorldName())..".db"))
1223 --Note(sql)
1224 rslt = db:exec(sql)
1225 --Note(rslt)
1226 db:close()
1227end
1228
1229function load_rooms()
1230 rooms = {}
1231sql = [[
1232 UPDATE rooms SET fillcolour = 0 WHERE fillcolour = ''
1233 ]]
1234run_sql(sql)
1235 sql = [[
1236 SELECT * FROM rooms ORDER BY uid ASC;
1237 ]]
1238 local db = assert(sqlite3.open(GetInfo(66)..clean_file_name(WorldName())..".db"))
1239 local cnt = 0
1240 for row in db:nrows(sql) do
1241 cnt = cnt + 1
1242 rooms[row.uid] = {
1243 name = row.name,
1244 desc = row.desc,
1245 area = row.area,
1246 fillcolour = row.fillcolour,
1247 fillbrush = row.fillbrush,
1248 bordercolour = row.bordercolour,
1249 info = row.info,
1250 notes = row.notes,
1251 exits = loadstring("return "..row.exits)()
1252 }
1253 end
1254 Note("Loaded ", cnt, " rooms from database.")
1255 db:close()
1256
1257 if tonumber(last_backup) == 0 then
1258 backup_db()
1259 end
1260end
1261
1262function check_update_room(uid, room)
1263 if not rooms[uid] or (serialize.save_simple(room) ~= serialize.save_simple(rooms[uid])) then
1264 add_update_room(uid, room)
1265 end
1266end
1267
1268function add_update_room(uid, room)
1269 sql = [[
1270 INSERT OR REPLACE INTO rooms (uid, name, desc, area, fillcolour, fillbrush, bordercolour, info, notes, exits)
1271 VALUES
1272 (']]..uid..[[',
1273 ']]..fix_sql(room.name)..[[',
1274 ']]..room.desc..[[',
1275 ']]..fix_sql(room.area)..[[',
1276 ']]..fix_sql(room.fillcolour)..[[',
1277 ']]..fix_sql(room.fillbrush)..[[',
1278 ']]..fix_sql(room.bordercolour)..[[',
1279 ']]..fix_sql(room.info)..[[',
1280 ']]..fix_sql(room.notes)..[[',
1281 ']]..fix_sql(serialize.save_simple(room.exits))..[[')
1282 ]]
1283 run_sql(sql)
1284end
1285
1286function check_create_db()
1287 sql = [[
1288 CREATE TABLE IF NOT EXISTS rooms (
1289 uid TEXT PRIMARY KEY,
1290 name TEXT,
1291 desc TEXT,
1292 area TEXT,
1293 fillcolour INTEGER,
1294 fillbrush INTEGER,
1295 bordercolour INTEGER,
1296 info TEXT,
1297 notes TEXT,
1298 exits TEXT
1299 )
1300 ]]
1301 run_sql(sql)
1302end
1303
1304------------------------------------------
1305-- end of sql additions
1306------------------------------------------
1307
1308------------------------------------------
1309-- backup stuff
1310------------------------------------------
1311-- If you want to do manual backups, make an alias with: script="backup_db"
1312------------------------------------------
1313
1314function backup_db()
1315 Note("Creating database backup.")
1316 local bk_nm = GetInfo(66).."db_backups\\"..clean_file_name(WorldName())..".db."..os.date("%A")
1317 ffi = require("ffi")
1318 ffi.cdef[[
1319 bool CreateDirectoryA(const char *lpPathName, void *lpSecurityAttributes);
1320 bool CopyFileA(const char* lpExistingFileName, const char * lpNewFileName, bool bFailIfExists);
1321 unsigned long GetLastError(void);
1322 ]]
1323
1324 succ = ffi.C.CreateDirectoryA(GetInfo(66).."db_backups\\", nil)
1325 err_no = ffi.C.GetLastError()
1326 if err_no and err_no ~= 183 and err_no ~= 127 then
1327 Note("Error creating directory: ", err_no)
1328 end
1329
1330 succ = ffi.C.CopyFileA(GetInfo(66)..clean_file_name(WorldName())..".db", bk_nm, false)
1331
1332 Note("Backup created: ", bk_nm)
1333 last_backup = os.time()
1334end
1335
1336------------------------------------------
1337-- end backup stuff
1338------------------------------------------
1339]]>
1340</script>
1341
1342
1343</muclient>