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