· 6 years ago · Oct 11, 2019, 05:48 AM
1<?xml version="1.0" encoding="iso-8859-1"?>
2<!DOCTYPE muclient>
3<!-- Saved on Friday, July 26, 2019, 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 "CleftMapper" generated by Plugin Wizard -->
16
17<muclient>
18<plugin
19 name="CleftMUSH_Mapper_v3_02"
20 author="Asmodeus"
21 id="dd07d6dbe73fe0bd02ddb62c"
22 language="Lua"
23 purpose="Shows the map for Cleft of Dimensions"
24 save_state="y"
25 date_written="2019-07-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 <alias
86 match="mapper resume"
87 enabled="y"
88 sequence="100"
89 script="map_resume"
90 >
91
92 </alias>
93 <alias
94 match="go"
95 enabled="y"
96 sequence="100"
97 script="map_resume"
98 >
99
100 </alias>
101 <alias
102 match="mapper stop"
103 enabled="y"
104 sequence="100"
105 script="mapper.cancel_speedwalk"
106 >
107 </alias>
108 <alias
109 match="mapper print"
110 enabled="y"
111 sequence="100"
112 send_to="14"
113 >
114<send>print("Room UID: ", current_room)</send>
115 </alias>
116 <alias
117 match="mapper debug"
118 enabled="y"
119 sequence="100"
120 send_to="14"
121 >
122<send>
123print("Current Room UID: ", current_room)
124print("Room Name: ", name)
125print("Terrain: ", terrain)
126print("Exits: ", exits)
127print("Current Area: ", current_area)
128print("Area: ", area)
129print("Info: ", info)
130</send>
131 </alias>
132 <!-- MAPPER CEXIT STUFF -->
133 <alias
134 match="^mapper cexit (.+)$"
135 enabled="y"
136 sequence="100"
137 script="custom_exit"
138 regexp="y"
139 ></alias>
140 <alias
141 match="^mapper cexit_wait (.+)$"
142 enabled="y"
143 sequence="100"
144 script="change_cexit_delay"
145 regexp="y"
146 ></alias>
147 <!-- show/hide mapper -->
148
149 <alias
150 match="mapper hide"
151 enabled="y"
152 sequence="100"
153 script="mapper.hide"
154 >
155 </alias>
156
157 <alias
158 match="mapper show"
159 enabled="y"
160 sequence="100"
161 script="mapper.show"
162 >
163 </alias>
164<alias
165 match="^mapper help( (.*))?$"
166 enabled="y"
167 regexp="y"
168 script="OnHelp"
169></alias>
170
171<alias
172 match="^mapper updown$"
173 enabled="y"
174 regexp="y"
175 send_to="12"
176>
177<send>
178 mapper.show_up_down = not mapper.show_up_down
179 mapper.draw (current_room)
180</send>
181</alias>
182
183<alias
184 match="^mapper underlines?$"
185 enabled="y"
186 regexp="y"
187 send_to="12"
188>
189<send>
190 NoUnderline_hyperlinks = not NoUnderline_hyperlinks
191 Note("Mapper hyperlinks will " ..(NoUnderline_hyperlinks and "no longer" or "now").." be underlined.")
192 SetVariable("NoUnderline_hyperlinks", NoUnderline_hyperlinks and "1" or "0")
193</send>
194</alias>
195 <alias
196 match="mapper goto *"
197 enabled="y"
198 sequence="100"
199 script="map_goto"
200 >
201 </alias>
202<alias
203 match="mapper find *"
204 ignore_case="y"
205 enabled="y"
206 sequence="100"
207 script="map_find"
208 regexp="n"
209></alias>
210<alias
211 match="find *"
212 ignore_case="y"
213 enabled="y"
214 sequence="100"
215 script="map_find"
216 regexp="n"
217></alias>
218<alias
219 match="mapper findpath * *"
220 enabled="y"
221 sequence="100"
222 omit_from_output="y"
223 script="findpathfast"
224></alias>
225
226 <alias
227 match="mapper where *"
228 enabled="y"
229 sequence="100"
230 script="map_where"
231 >
232 </alias>
233 <alias
234 match="mapper backup"
235 enabled="y"
236 sequence="100"
237 script="backup_db"
238 >
239 </alias>
240 <alias
241 match="^mapper delete room (\d\w+)$"
242 enabled="y"
243 regexp="y"
244 script="delete_room_alias"
245>
246</alias>
247<alias
248 match="^mapper delete area (.+)$"
249 enabled="y"
250 regexp="y"
251 script="delete_area_alias"
252>
253</alias>
254
255
256<alias
257 match="^mapper flag (.*)$"
258 enabled="y"
259 regexp="y"
260 sequence="100"
261 script="updateRoomInfo">
262</alias>
263<alias
264 match="^mapper uid$"
265 enabled="y"
266 regexp="y"
267 sequence="100"
268 script="updateRoomUid">
269</alias>
270
271<alias
272 match="^mapper draw room$"
273 enabled="y"
274 regexp="y"
275 sequence="100"
276 send_to="14">
277<send>mapper.draw (uid)</send>
278</alias>
279 <alias
280 enabled="n"
281 group="look"
282 name="Lookthing"
283 keep_evaluating="y"
284 match="^l (\w|\d).*$"
285 omit_from_output="n"
286 regexp="y"
287 send_to="12"
288 sequence="5"
289 ><send>
290EnableTrigger ("get_room_name", false)
291EnableTrigger ("get_description_line", false)
292EnableTrigger ("Exits_Line", false)
293Execute("look %1")
294DoAfterSpecial (0.1, 'EnableTrigger ("get_room_name", true)', sendto.script)
295DoAfterSpecial (0.1, 'EnableTrigger ("Exits_Line", true)', sendto.script)
296</send>
297 </alias>
298
299
300<alias
301match="UpdateTownSpecial"
302enabled="n"
303sequence="100"
304>
305<send>
306where shops | prefix {Where Shop}
307where banks | prefix {Where Bank}
308where teachers | prefix {Where Teacher}
309where forges | prefix {Where Forge}
310</send>
311</alias>
312
313</aliases>
314
315
316<!-- Triggers -->
317
318<triggers>
319 <trigger
320 enabled="y"
321 match="You can't see a thing!"
322 sequence="100"
323 send_to="14"
324 >
325<send>last_direction_moved = nil
326</send>
327 </trigger>
328 <trigger
329 enabled="n"
330 match="*left of Dimensions (c) 2000, Lunar Saber"
331 name="login"
332 sequence="100"
333 send_to="14"
334 >
335<send>EnableTrigger ("get_room_name", false)
336EnableTrigger ("get_description_line", false)
337EnableTrigger ("Exits_Line", false)
338</send>
339 </trigger>
340 <trigger
341 enabled="n"
342 match="*econnecting."
343 name="reconnect"
344 sequence="100"
345 send_to="14"
346 >
347<send>DoAfterSpecial (0.5, 'EnableTrigger ("get_room_name", true)', sendto.script)
348DoAfterSpecial (0.5, 'EnableTrigger ("get_description_line", true)', sendto.script)
349DoAfterSpecial (0.5, 'EnableTrigger ("Exits_Line", true)', sendto.script)
350</send>
351 </trigger>
352 <trigger
353 enabled="y"
354 match="^You are blinded!$"
355 sequence="100"
356 send_to="14"
357 >
358<send>EnableTrigger ("get_room_name", false)
359EnableTrigger ("get_description_line", false)
360EnableTrigger ("Exits_Line", false)
361</send>
362 </trigger>
363 <trigger
364 enabled="y"
365 match="^You can't see a thing!$"
366 sequence="100"
367 send_to="14"
368 >
369<send>
370EnableTrigger ("get_room_name", false)
371EnableTrigger ("get_description_line", false)
372EnableTrigger ("Exits_Line", false)
373</send>
374 </trigger>
375 <trigger
376 enabled="y"
377 match="^You blink and your eyes clear.$"
378 sequence="100"
379 send_to="14"
380 >
381<send>
382EnableTrigger ("get_room_name", true)
383EnableTrigger ("get_description_line", true)
384EnableTrigger ("Exits_Line", true)
385</send>
386 </trigger>
387 <trigger
388 enabled="y"
389 match="^You rub the dirt out of your eyes.$"
390 sequence="100"
391 send_to="14"
392 >
393<send>
394EnableTrigger ("get_room_name", true)
395EnableTrigger ("get_description_line", true)
396EnableTrigger ("Exits_Line", true)
397</send>
398 </trigger>
399 <trigger
400 enabled="n"
401 match="*t)(t)(t)(t)(t)(t)(t)(t)(t)(t)(t)(t)(t)(t)(t)(t)(t)(t)(t)(t)(t)(t)(t)(t)(t)(t)"
402 name="connect"
403 sequence="100"
404 send_to="14"
405 >
406<send>DoAfterSpecial (0.5, 'EnableTrigger ("get_room_name", true)', sendto.script)
407DoAfterSpecial (0.5, 'EnableTrigger ("get_description_line", true)', sendto.script)
408DoAfterSpecial (0.5, 'EnableTrigger ("Exits_Line", true)', sendto.script)
409</send>
410 </trigger>
411 <trigger
412 enabled="y"
413 match="[Room][*][ [ DaRkNeSs ] ]"
414 omit_from_output="y"
415 sequence="1"
416 send_to="14"
417 >
418<send></send>
419 </trigger>
420 <trigger
421 enabled="y"
422 match="[Last_Dir: * ]"
423 name="moved_direction"
424 omit_from_output="y"
425 sequence="1"
426 script="moved_direction"
427 >
428 </trigger>
429 <trigger
430 enabled="y"
431 match="^(\s|)\[Start_Desc\]$"
432 omit_from_log="y"
433 omit_from_output="y"
434 regexp="y"
435 send_to="14"
436 sequence="100"
437 ><send>EnableTrigger ("get_description_line", true)</send>
438</trigger>
439 <trigger
440 enabled="y"
441 match="^\[Room\]\[(?<terrain>.*)\]\[ (?<name>.*) \]$"
442 name="process_room_name"
443 regexp="y"
444 omit_from_output="y"
445 sequence="100"
446 send_to="14"
447 >
448 <send>
449terrain="%1"
450name="%2"
451 if rooms ~= nil and
452 rooms[uid] ~= nil and
453 rooms[uid].notes ~= nil and
454 rooms[uid].notes ~= ""
455 then
456 mapper.mapprint("*** MAPPER NOTE *** ->", rooms[uid].notes)
457end
458</send>
459 </trigger>
460 <trigger
461 enabled="y"
462 match="[UID]: *"
463 omit_from_output="y"
464 name="process_room_desc"
465 sequence="100"
466 script="room_number"
467 >
468 </trigger>
469 <trigger
470 enabled="y"
471 match="[Exits: *]"
472 omit_from_output="y"
473 keep_evaluating="y"
474 send_to="12"
475 sequence="100"
476 >
477 <send>local subTable = { ["S"] = "south", ["W"] = "west", ["E"] = "east", ["U"] = "up", ["D"] = "down", ["SW"] = "sw", ["NW"] = "nw", ["NE"] = "ne", ["SE"] = "se", ["N"] = "north", ["none"] = "none " }
478local result = "%1"
479result = string.gsub(result, "%[", "")
480result = string.gsub(result, "%]", "")
481
482for word in string.gmatch(result, "%w+") do
483 if subTable[word] then
484 result = result:gsub(word, subTable[word], 1)
485 end
486end
487Simulate("\\n[Exits2: " .. result .. "]\\n")</send>
488 </trigger>
489 <trigger
490 enabled="y"
491 match="[Exits2: * ]"
492 omit_from_output="y"
493 name="Exits_Line"
494 sequence="100"
495 send_to="14"
496 >
497 <send>process_exits("%1")</send>
498 </trigger>
499 <trigger
500 enabled="y"
501 keep_evaluating="y"
502 match="^\s*[a-zA-Z\~\.\+\;\,\_\-\`\'\d][^\n].*$"
503 name="get_room_name"
504 script="process_room_name"
505 regexp="y"
506 sequence="90"
507 send_to="14"
508 ><send></send>
509 </trigger>
510 <trigger
511 keep_evaluating="y"
512 match="^(.*|\s.*)$"
513 name="get_description_line"
514 script="process_description_line"
515 sequence="100"
516 regexp="y"
517 send_to="14"
518 ><send></send>
519 </trigger>
520 <trigger
521 enabled="y"
522 match="(] Exits: * [)"
523 name="got_exits1"
524 sequence="100"
525 send_to="14"
526 >
527<send>EnableTrigger ("get_description_line", false)
528</send>
529 </trigger>
530 <trigger
531 enabled="y"
532 match="Alas, you cannot go that way."
533 script="cannot_walk"
534 sequence="100"
535 ></trigger>
536 <trigger
537 enabled="y"
538 match="You can't float."
539 script="cannot_walk"
540 sequence="100"
541 ></trigger>
542 <trigger
543 enabled="y"
544 match="* would be left behind."
545 script="cannot_walk"
546 sequence="100"
547 ></trigger>
548 <trigger
549 enabled="y"
550 match="You are too exhausted to continue your stealthy movement!"
551 script="cannot_walk"
552 sequence="100"
553 ></trigger>
554 <trigger
555 enabled="y"
556 match="You are too exhausted."
557 script="cannot_walk"
558 sequence="100"
559 ></trigger>
560 <trigger
561 enabled="y"
562 match="You follow * *."
563 script="cannot_walk"
564 sequence="100"
565 ></trigger>
566 <trigger
567 enabled="y"
568 match="You'll have to climb to go there."
569 script="cannot_walk"
570 sequence="100"
571 ></trigger>
572 <trigger
573 enabled="y"
574 match="You can't just walk away from a fight!"
575 script="cannot_walk"
576 sequence="100"
577 ></trigger>
578 <trigger
579 enabled="y"
580 match="The * is closed."
581 script="cannot_walk"
582 sequence="100"
583 ></trigger>
584 <trigger
585 enabled="y"
586 match="You slam face-first into the door on your way *. WHAM!"
587 script="cannot_walk"
588 sequence="100"
589 ></trigger>
590 <trigger
591 enabled="y"
592 match="You drunkenly slam face-first into the wall on your way *. WHAM!"
593 script="cannot_walk"
594 sequence="100"
595 ></trigger>
596 <trigger
597 enabled="y"
598 match="You almost go *, but suddenly realize that there's no exit there."
599 script="cannot_walk"
600 sequence="100"
601 ></trigger>
602 <trigger
603 enabled="y"
604 match="You almost go *, but suddenly realize that the door is closed."
605 script="cannot_walk"
606 sequence="100"
607 ></trigger>
608 <trigger
609 enabled="y"
610 match="You need a boat to go there."
611 script="cannot_walk"
612 sequence="100"
613 ></trigger>
614 <trigger
615 enabled="y"
616 match="You can't drive this vehicle into water."
617 script="cannot_walk"
618 sequence="100"
619 ></trigger>
620 <trigger
621 enabled="y"
622 match="You can't drive this vehicle indoors."
623 script="cannot_walk"
624 sequence="100"
625 ></trigger>
626 <trigger
627 enabled="y"
628 match="You need to be able to swim or be on a seaworthy vehicle to go there."
629 script="cannot_walk"
630 sequence="100"
631 ></trigger>
632 <trigger
633 enabled="y"
634 match="No way! You are still fighting!"
635 script="cannot_walk"
636 sequence="100"
637 ></trigger>
638 <trigger
639 enabled="y"
640 match="Maybe you should finish fighting first?"
641 script="cannot_walk"
642 sequence="100"
643 ></trigger>
644 <trigger
645 enabled="y"
646 match="The wind is roaring in from the *, pushing you back."
647 script="cannot_walk"
648 sequence="100"
649 ></trigger>
650 <trigger
651 enabled="y"
652 match="You can't drive this vehicle into empty air."
653 script="cannot_walk"
654 sequence="100"
655 ></trigger>
656 <trigger
657 enabled="y"
658 match="^The (door|gate) is closed\.$"
659 regexp="y"
660 name="Door_Closed"
661 script="Door_Closed"
662 sequence="100"
663 >
664 </trigger>
665 <trigger
666 enabled="y"
667 match="The wooden door is closed."
668 regexp=""
669 name="woodendoor_closed"
670 script="Door_Closed"
671 sequence="100"
672 >
673 </trigger>
674<trigger
675 enabled="y"
676 match="^{Where (.*)}\w{1,2}(?:.*->)?\s+(.*)$"
677 regexp="y"
678 name="InfoUpdate"
679 script="updateRoomInfo"
680 sequence="100"
681>
682</trigger>
683</triggers>
684
685<!-- Timers -->
686
687<timers>
688 <timer
689 name="backup_timer"
690 enabled="y"
691 script="backup_db"
692 hour="1" minute="01" second="59"
693 active_closed="y" >
694 </timer>
695</timers>
696
697<!-- Script -->
698
699
700<script>
701local show_other_areas = &show_other_areas;
702<![CDATA[
703
704mapper = require "cleftmapper"
705require "serialize"
706require "copytable"
707require "wait"
708uid = -999
709current_room=nil
710current_area = -999
711expected_exit=-666
712from_room=""
713last_direction_moved=nil
714terrain = 0
715area = "<No area>"
716last_backup = GetVariable("last_backup") or 0
717notes = 0
718default_width = 269
719default_height = 335
720local posx = 100
721local posy = 100
722local DIFFERENT_AREA_COLOUR = "#ff0000"
723areaname = -999
724last_direction_moved = nil
725OUR_ROOM_COLOUR = tonumber(GetVariable("OUR_ROOM_COLOUR")) or 0x0000FF
726
727
728count = 0
729roomcount = 0
730rooms = {}
731local user_terrain_colour = {}
732
733local cleftmush_dirs = {
734 ["10"] = "n",
735 ["12"] = "s",
736 ["16"] = "ne",
737 ["19"] = "sw",
738 ["18"] = "se",
739 ["17"] = "nw",
740 ["13"] = "w",
741 ["11"] = "e",
742 ["14"] = "u",
743 ["15"] = "d",
744 ["99"] = "unk" -- idk what to do here (nothing?) (i'm not sure either, maybe wait till it happens and you can duplicate it)
745}
746
747valid_direction = {
748n = "n",
749s = "s",
750e = "e",
751w = "w",
752u = "u",
753d = "d",
754ne = "ne",
755sw = "sw",
756nw = "nw",
757no="n",
758ea="e",
759so="s",
760we="w",
761se = "se",
762north = "n",
763south = "s",
764east = "e",
765west = "w",
766up = "u",
767down = "d",
768northeast = "ne",
769northwest = "nw",
770southeast = "se",
771southwest = "sw",
772['in'] = "in",
773out = "out",
774} -- end of valid_direction
775
776-- for calculating the way back
777local inverse_direction = {
778 n = "s",
779 s = "n",
780 e = "w",
781 w = "e",
782 u = "d",
783 d = "u",
784 ne = "sw",
785 sw = "ne",
786 nw = "se",
787 se = "nw",
788 ['in'] = "out",
789 out = "in",
790 } -- end of inverse_direction
791
792
793terrain_color = {}
794
795
796
797
798-- -----------------------------------------------------------------
799-- Here on room name
800-- -----------------------------------------------------------------
801function process_room_name (name, line, wildcards, styles)
802 local name = line
803
804 if debugging then
805 ColourNote ("yellow", "", "process_room_name: " .. name)
806 end -- if
807
808 -- ignore exits lines
809 if string.match (name, "^%(] Exits: ") then
810 return
811 end -- if
812
813 -- ignore really long lines
814 if #name > 75 then
815 return
816 end -- if
817 --if #name < 1 then
818 --return
819 --end -- if
820 room_name = name
821
822 --EnableTrigger ("get_description_line", true)
823 EnableTrigger ("get_room_name", false)
824
825 desc = {}
826--print("Name: ", name)
827--print("Desc: ", desc)
828 just_got_room_name = true
829end -- got_room_name
830
831-- -----------------------------------------------------------------
832-- process_description_line : Here on one line of the description
833-- -----------------------------------------------------------------
834function process_description_line (name, line, wildcards)
835
836 if Trim (line) == "" then
837 return
838 end -- if
839
840 if debugging then
841 ColourNote ("yellow", "", "process_description_line: " .. line)
842 end -- if
843
844 if not desc then
845 ColourNote ("yellow", "", "No current description")
846 end -- if
847
848 if just_got_room_name then
849
850 -- false alarm!
851 if line:sub (1, 2) ~= " " then
852 --print("FALSE ALARM")
853 just_got_room_name = false
854 EnableTrigger ("get_description_line", false)
855
856 exits = nil
857
858 return
859 end -- if
860
861 end -- if
862
863 just_got_room_name = false
864
865 -- add to the current description
866 if Trim (line) ~= "" then
867 table.insert (desc, line)
868 end -- if
869 if line:match(".* is carrying%:") then
870 print("Line Matched It works")
871 return
872else
873end
874
875end -- process_description_line
876
877
878
879-----------------------------------------
880-- ADDING TRIGGER STUFF
881-----------------------------------------
882
883function room_number(name, line, args)
884 uid = args[1] -- this was in the <send> previously
885 from_room = current_room or ""
886 current_room = args[1]
887end
888
889function moved_direction(name, line, args)
890last_direction_moved = cleftmush_dirs[args[1]] or nil
891end
892
893------------------------------------------
894--Update Town Special Procedure
895------------------------------------------
896
897function updateRoomInfo(name, line, wildcards)
898 local roomtype, room, roomuid, matchFound = wildcards[1], wildcards[2], current_room or 0, false
899
900 if room then
901 for i,v in pairs(rooms) do
902 if v.name == Trim(room) then
903 roomuid = i
904 matchFound = true
905 break
906 end
907 end
908 else
909 matchFound = true
910 end
911
912 if matchFound == true then
913 if not rooms[roomuid].info then
914 rooms[roomuid].info = roomtype
915 else
916 if not string.find(rooms[roomuid].info, roomtype) then
917 rooms[roomuid].info = rooms[roomuid].info .. roomtype
918 add_update_room(roomuid, rooms[roomuid])
919 end
920 end
921 mapper.draw(roomuid)
922 else
923 print("Room not mapped!")
924 end
925end
926
927function updateRoomName()
928 newname = utils.inputbox ("Enter new name for " .. current_room, name)
929print("New NAME: ", newname)
930 rooms[current_room].name = newname
931 add_update_room(newname, rooms[current_room])
932print("current_room: ", current_room)
933print("Name: ", name)
934 mapper.draw(current_room)
935end
936function updateRoomUid()
937 newuid = utils.inputbox ("Enter new UID for " .. current_room, uid)
938 print("New UID: ", newuid)
939 update_uid(newuid, uid)
940 rooms[current_room].uid = newuid
941 current_room = newuid
942 print("current_room: ", current_room)
943 print("UID: ", uid)
944 mapper.draw(current_room)
945end
946
947function update_uid(newuid, olduid)
948tprint(rooms[current_room])
949 sql = [[UPDATE rooms SET uid = ']]..newuid..[[' WHERE uid = ']]..olduid..[[']]
950 run_sql(sql)
951end
952
953
954-----------------------------------------
955-- DONE ADDING TRIGGER STUFF
956-----------------------------------------
957
958function room_edit_note(room, vuid, newnotes)
959 if vuid == nil and current_room ~= nil then
960 vuid = current_room
961 room = rooms[vuid]
962 end
963
964 if vuid == nil then -- still nothing?
965 print("No room received from the mud yet. Try using the 'LOOK' command first.")
966 return
967 end
968
969 if newnotes == nil or newnotes == "" then
970 if room.notes ~= nil and room.notes ~= "" then
971 newnotes = utils.inputbox("Modify room comment (clear it to delete from database)", room.name, room.notes)
972 else
973 newnotes = utils.inputbox("Enter room comment (creates a note for this room)", room.name, room.notes)
974 end -- if
975 end
976
977 if not newnotes then
978 return
979 end -- if cancelled
980
981 if newnotes == "" then
982 if room.notes == nil or room.notes == "" then
983 mapper.mapprint("No comment entered, note not saved.")
984 return
985 else
986 mapper.mapprint("Note from room " .. current_room .. " deleted. Was previously: " .. room.notes)
987 rooms[current_room].notes = ""
988 add_update_room(current_room, rooms[current_room])
989 mapper.draw(current_room)
990 end
991 end
992
993 if rooms[current_room].notes == newnotes then
994 return -- no change made
995 end
996
997 local oldNote = room.note
998
999 rooms[current_room].notes = newnotes
1000 add_update_room(current_room, rooms[current_room])
1001 mapper.draw(current_room)
1002
1003 if oldNote ~= nil and #oldNote > 0 then
1004 mapper.mapprint("Note for room", current_room, "changed to:", newnotes)
1005 else
1006 mapper.mapprint("Note added to room", current_room, ":", newnotes)
1007 end
1008end
1009------------------------------------------------------------------------------------------------
1010-- CUSTOM EXIT SHIT, HAVE FUN.. HEH.
1011------------------------------------------------------------------------------------------------
1012BASE_CEXIT_DELAY = 2
1013
1014function change_cexit_delay(name, line, wildcards)
1015 temp_cexit_delay = tonumber(wildcards[1])
1016 if not compact_mode then Note("") end
1017 if temp_cexit_delay == nil or temp_cexit_delay < BASE_CEXIT_DELAY or temp_cexit_delay > 40 then
1018 Note("CEXIT_DELAY FAILED: Invalid delay given ("..wildcards[1].."). Must be a number from 2 to 40.")
1019 temp_cexit_delay = nil
1020 end
1021 Note("CEXIT_DELAY: The next mapper custom exit will have ".. (temp_cexit_delay or BASE_CEXIT_DELAY) .." seconds to complete.\n")
1022end
1023
1024function ExecuteWithWaits(cexit_command)
1025 wait.make (function()
1026 --SendNoEcho("echo {begin running}")
1027 local partial_cexit_command = cexit_command
1028 local strbegin,strend = string.find(partial_cexit_command,";?wait%(%d*.?%d+%);?")
1029 while strbegin do
1030 strbegin,strend = string.find(partial_cexit_command,";?wait%(%d*.?%d+%);?")
1031 if strbegin ~= nil and strbegin ~= 1 then
1032 Execute(string.sub(partial_cexit_command,1,strbegin-1))
1033 end
1034 if strend then
1035 local wait_time = tonumber(string.match(string.sub(partial_cexit_command,strbegin,strend),"wait%((%d*.?%d+)%)"))
1036 --SendNoEcho("echo {mapper_wait}wait("..wait_time..")")
1037 line, wildcards = wait.regexp("^\\{mapper_wait\\}wait\\(([0-9]*\\.?[0-9]+)\\)",nil,trigger_flag.OmitFromOutput)
1038 Note("CEXIT WAIT: waiting for "..wait_time.." seconds before continuing.")
1039 CallPlugin("abc1a0944ae4af7586ce88dc", "BufferedRepaint")
1040 wait.time(wait_time)
1041 partial_cexit_command = string.sub(partial_cexit_command, strend+1)
1042 end
1043 end
1044 Execute(partial_cexit_command)
1045 SendNoEcho("echo {end running}")
1046 end)
1047end
1048
1049-- custom_exit function contributed by Spartacus
1050
1051function custom_exit (name, line, wildcards)
1052
1053 local remap = {
1054 n = "north",
1055 w = "west",
1056 s = "south",
1057 e = "east",
1058 u = "up",
1059 d = "down"
1060 }
1061 local cexit_command = wildcards [1] or ""
1062 local cexit_start
1063
1064 if cexit_command == "" then
1065 world.Note("Nothing to do!")
1066 return
1067 end -- if cexit_command
1068
1069 -- Note: Since the addition of the ignore_exits_mismatch room flag, I think this is no longer true.
1070 -- Getting rid of the remap allows one to draw custom exit linkages between nomap rooms.
1071 ------------------------------------
1072 -- the current system makes standard letter exit (n,e,s,w,d,u) cexits not usable, so remap them
1073 -- to their long word forms
1074 --if remap[cexit_command] then
1075 -- cexit_command = remap[cexit_command]
1076 --end
1077 if current_room then
1078 cexit_start = current_room
1079 else
1080 world.Note("CEXIT FAILED: No room received from the mud yet. Try using the 'LOOK' command first.")
1081 return
1082 end -- if current_room
1083
1084 if cexit_start == "-1" then
1085 world.Note ("CEXIT FAILED: You cannot link custom exits from unmappable rooms.")
1086 return
1087 end
1088
1089 wait.make (function()
1090 local cexit_delay = temp_cexit_delay or BASE_CEXIT_DELAY
1091 local added_waits = 0
1092 for wait_secs in string.gmatch(cexit_command, "wait%((%d*.?%d+)%)") do
1093 added_waits = added_waits + tonumber(wait_secs)
1094 end
1095 world.Note("CEXIT: WAIT FOR CONFIRMATION BEFORE MOVING.\nThis should take about "..cexit_delay+added_waits.." seconds"..(((added_waits ~= 0) and " (includes "..added_waits.." seconds in added waits)") or "")..".")
1096 CallPlugin("abc1a0944ae4af7586ce88dc", "BufferedRepaint")
1097 ExecuteWithWaits(cexit_command)
1098
1099 wait.time(cexit_delay+added_waits)
1100 temp_cexit_delay = nil
1101 cexit_dest = current_room
1102 if cexit_dest then
1103 if cexit_dest == "-1" then
1104 world.Note ("CEXIT FAILED: You cannot link custom exits to unmappable rooms.")
1105 elseif cexit_dest ~= cexit_start then
1106 world.Note (string.format("Custom Exit CONFIRMED: %s (%s) -> %s", cexit_start, cexit_command, cexit_dest))
1107 run_sql(string.format ("INSERT OR REPLACE INTO exits (dir, fromuid, touid) VALUES (%s, %s, %s);",
1108 fix_sql (cexit_command), -- direction (eg. "n")
1109 fix_sql (cexit_start), -- from current room
1110 fix_sql (cexit_dest) -- destination room
1111 ))
1112 rooms[cexit_start].exits[cexit_command] = cexit_dest
1113 --rooms[cexit_start].exit_locks[cexit_command] = "0"
1114 mapper.draw (current_room)
1115 else
1116 world.Note (string.format("CEXIT FAILED: Custom Exit %s leads back here!", cexit_command))
1117 end
1118 else
1119 world.Note ("CEXIT FAILED: Need to know where we ended up.")
1120 end
1121 end)
1122end -- custom_exit
1123
1124last_area_requested = ""
1125
1126
1127-- -----------------------------------------------------------------
1128-- Here on "Exits:" line ----- we have changed rooms
1129-- -----------------------------------------------------------------
1130
1131function process_exits (exits_str)
1132
1133 EnableTrigger ("get_room_name", true)
1134 EnableTrigger ("get_description_line", false)
1135 --Note("process exits")
1136 if current_room == from_room then
1137 --if #desc < 2 then
1138 --Note(current_room, ", ", from_room)
1139 --print("From Room: ", from_room)
1140 --print("Current Room: ", current_room)
1141 --Note("same room")
1142 --just_got_room_name = false
1143 --return
1144 end -- if
1145
1146 desc = table.concat (desc, "\n")
1147
1148 -- generate a "room ID" by hashing the room name, description and exits
1149 uid = utils.tohex (utils.md5 (name .. desc .. terrain .. exits_str))
1150 uid = uid:sub (1, 25)
1151 -- break up exits into individual directions
1152 exits = {}
1153
1154 for exit in string.gmatch (exits_str, "%w+") do
1155 local ex = valid_direction [exit]
1156 if ex then
1157 exits [ex] = "-666" -- don't know where it goes yet
1158 end -- if
1159 end -- for
1160--print("Name: ", name)
1161--print("Desc: ", desc)
1162 if #desc < 2 then
1163 return
1164elseif #desc > 2200 then
1165 return
1166end -- for
1167Simulate("\n[UID]: ", uid)
1168
1169--print("Name: ", name)
1170--print("Desc: ", desc)
1171--print("Terrain: ", terrain)
1172--print("Current Room: ", current_room)
1173--print("Exits: ", exits_str)
1174Simulate("\nLast Dir: ", last_direction_moved)
1175
1176
1177 -- add to table if not known
1178 --Note("add room to table")
1179 if not rooms [uid] then
1180 rooms [uid] = { name = name, desc = desc, exits = exits, area=area, fillcolour=terrain_color[terrain], fillbrush=0, bordercolour=0xffffff }
1181 add_update_room(uid, rooms[uid])
1182 end -- if
1183
1184 -- save so we know current room later on
1185 current_room = uid
1186
1187 -- add exit into mapper
1188 --Note("add exit")
1189 if from_room ~= "" and last_direction_moved then -- we were in a room # that we got from kxwt, and then moved to another room
1190 --Note("rooms[", from_room, "].exits[", last_direction_moved, "] = ", current_room)
1191 rooms[from_room].exits[last_direction_moved] = current_room
1192 add_update_room(from_room, rooms[from_room])
1193 last_direction_moved = nil -- remove last direction so updating a room only happens when we walk somewhere
1194 end
1195--if last_direction_moved ~= nil then
1196--EnableTrigger ("get_room_name", true)
1197--end
1198
1199 -- call mapper to draw this room
1200 mapper.draw (uid)
1201 just_got_room_name = false
1202 -- if expected_exit == "-666" and from_room then
1203 -- fix_up_exit ()
1204 -- end -- exit was wrong
1205
1206 -- return
1207end -- process_exits
1208
1209function fix_up_exit ()
1210 local room = rooms [from_room]
1211
1212 run_sql(string.format ("UPDATE exits SET touid = %s WHERE fromuid = %s AND dir = %s;",
1213 fix_sql (current_room), -- destination room
1214 fix_sql (from_room), -- from previous room
1215 fix_sql (last_direction_moved) -- direction (eg. "n")
1216 ))
1217
1218-- if show_database_mods then
1219 mapper.mapprint ("Fixed exit", last_direction_moved, "from room", from_room, "to be to", current_room)
1220-- end -- if
1221
1222 room.exits [last_direction_moved] = current_room
1223
1224 last_direction_moved = nil
1225 from_room = nil
1226end -- fix_up_exit
1227
1228-- -----------------------------------------------------------------
1229-- for converting things like ^ $ * etc. into "escaped" sequences
1230-- -----------------------------------------------------------------
1231function fix_regexp_magic_characters (r)
1232 return string.gsub (r, "[%^%$%(%)%%%.%[%]%*%+%-%?]", "%%%1")
1233end -- fix_regexp_magic_characters
1234
1235-- -----------------------------------------------------------------
1236-- mapper 'get_room' callback - it wants to know about room uid
1237-- -----------------------------------------------------------------
1238
1239function get_room (uid)
1240
1241
1242 if not rooms [uid] then
1243 return nil
1244 end -- if
1245
1246 local room = copytable.deep (rooms [uid])
1247 local notes = ""
1248 if room.notes and room.notes ~= "" then
1249 notes = "\nNote: " .. room.notes
1250 end -- if notes
1251
1252 local texits = {}
1253 for dir in pairs (room.exits) do
1254 table.insert (texits, dir)
1255 end -- for
1256 table.sort (texits)
1257
1258 if uid == current_room then
1259 current_area = room.area or "Cleft of Dimensions" -- assume every room is in this area
1260 --current_area = room.area
1261 end -- if
1262 --room.area = "Cleft of Dimensions" -- assume every room is in this area
1263 room.hovermessage = string.format (
1264"%s\tExits: %s\nRoom: %s\nDescription: %s \nArea: %s\nTerrain:%s \nNotes: %s",
1265 room.name,
1266 table.concat (texits, ", "),
1267 uid,
1268 room.desc,
1269 room.area,
1270 terrain,
1271 room.notes
1272 -- depth,
1273 -- table.concat (path, ",")
1274 )
1275
1276
1277 -- SPECIAL ROOM COLOUR FILLS
1278special_room = false
1279 if room.info and room.info ~= "" then
1280 if string.match (room.info, "waypoint") then
1281 special_room = true
1282 elseif string.match (room.info, "bank") then
1283 special_room = true
1284 elseif string.match (room.info, "alchemyguild") then
1285 special_room = true
1286 elseif string.match (room.info, "teacher") then
1287 special_room = true
1288 elseif string.match (room.info, "employer") then
1289 special_room = true
1290 elseif string.match (room.info, "priest") then
1291 special_room = true
1292 elseif string.match (room.info, "forge") then
1293 special_room = true
1294 elseif string.match (room.info, "warriortrainer") then
1295 special_room = true
1296 elseif string.match (room.info, "thieftrainer") then
1297 special_room = true
1298 elseif string.match (room.info, "druidtrainer") then
1299 special_room = true
1300 elseif string.match (room.info, "clerictrainer") then
1301 special_room = true
1302 elseif string.match (room.info, "magetrainer") then
1303 special_room = true
1304 elseif string.match (room.info, "morgue") then
1305 special_room = true
1306 elseif string.match (room.info, "rangertrainer") then
1307 special_room = true
1308 elseif string.match (room.info, "quest") then
1309 special_room = true
1310 elseif string.match (room.info, "fountain") then
1311 special_room = true
1312 elseif string.match (room.info, "gato") then
1313 special_room = true
1314 elseif string.match (room.info, "moti") then
1315 special_room = true
1316
1317 end
1318end -- if
1319 if uid == current_room and special_room then
1320 room.bordercolour = mapper.OUR_ROOM_COLOUR.colour
1321 room.borderpenwidth = 3
1322 elseif room.area ~= current_area then
1323 room.bordercolour = ColourNameToRGB "red"
1324 end -- not in this area
1325 return room
1326
1327
1328end -- get_room
1329
1330function show_this_room (name, line, wildcards)
1331 local room = rooms[current_room]
1332 if room ~= nil then
1333 Note("Details about this room:")
1334 Note("+---------------------------+")
1335 Note("Name: "..(name or ""))
1336 Note("ID: "..(uid or ""))
1337 Note("Area: "..(area or ""))
1338 Note("Terrain: "..(terrain or ""))
1339 Note("Info: "..(room.info or ""))
1340 Note("Notes: "..(room.notes or ""))
1341 Note("Exits: "..(room.exits or ""))
1342else
1343 Note("THISROOM ERROR: You need to type 'LOOK' first to initialize the mapper before trying to get room information.")
1344 end
1345end -- show_this_room
1346
1347function our_room_colour ()
1348 local clr = PickColour(OUR_ROOM_COLOUR or 0)
1349 if clr ~= -1 then
1350 OUR_ROOM_COLOUR = clr
1351 mapper.OUR_ROOM_COLOUR.colour = clr
1352 SaveState()
1353 end
1354end
1355
1356
1357function room_click (uid, flags)
1358
1359 -- check we got room at all
1360 if not uid then
1361 return nil
1362 end -- if
1363
1364 -- look it up
1365 local room = rooms [uid]
1366
1367 -- not cached - see if in database
1368 if not room then
1369return
1370 end -- not in cache
1371
1372 if not room then
1373 return
1374 end -- if still not there
1375
1376 local function checkmark (which)
1377 if rooms [uid] [which] then
1378 return "+"
1379 else
1380 return ""
1381 end -- if
1382 end -- checkmark
1383
1384
1385 local handlers = {
1386 { name = "(NOT-YET-IMPLEMENTED)Edit bookmark", func = room_edit_bookmark} ,
1387 { name = "-", } ,
1388 { name = "(NOT-YET-IMPLEMENTED)Add Exit", func = room_add_exit} ,
1389 { name = "Change Exit", func = room_change_exit} ,
1390 { name = "Delete Current Room", func = delete_room_click} ,
1391 { name = "-", } ,
1392 { name = checkmark ("shop") .. "Mark as Shop", func = room_toggle_shop } ,
1393 { name = "-", } ,
1394 { name = "Current Room Border Color", func = our_room_colour} ,
1395 } -- handlers
1396
1397 local t, tf = {}, {}
1398 for _, v in pairs (handlers) do
1399 table.insert (t, v.name)
1400 tf [v.name] = v.func
1401 end -- for
1402
1403 local choice = WindowMenu (mapper.win,
1404 WindowInfo (mapper.win, 14),
1405 WindowInfo (mapper.win, 15),
1406 table.concat (t, "|"))
1407
1408 local f = tf [choice]
1409
1410 if f then
1411 f (room, uid)
1412 end -- if handler found
1413
1414end -- room_click
1415
1416
1417
1418
1419
1420-- -----------------------------------------------------------------
1421-- map_find: mapper find xxx
1422-- -----------------------------------------------------------------
1423function map_find (name, line, wildcards)
1424
1425 mapper.mapprint (string.rep ("-", 25) .. " Mapper search " .. string.rep ("-", 25))
1426
1427 local reset = ANSI (0)
1428 local bold = ANSI (1)
1429 local unbold = ANSI (22)
1430
1431 local matches = { }
1432 local count = 0
1433 local target = Trim (wildcards [1]:lower ())
1434
1435 if target == "" then
1436 mapper.maperror ("No search string specified")
1437 return
1438 end -- if
1439
1440 if not mapper.check_we_can_find () then
1441 return
1442 end -- if find not OK
1443
1444 -- fix up any regular expression "magic" letters to be escaped by a %
1445 local fixed_target = fix_regexp_magic_characters (target)
1446
1447 -- fix up for caseless searches in the room description (eg. "a" becomes "[aA]")
1448 local caseless_target = string.gsub (fixed_target, "(%a)", function (a)
1449 return "[" .. a:lower () .. a:upper () .. "]"
1450 end -- function
1451 )
1452
1453 -- do a simple string search to find matching rooms
1454 for k, v in pairs (rooms) do
1455
1456 -- don't want nil descriptions
1457 if not v.description then
1458 v.description = ""
1459 end -- if no description
1460
1461 if string.find (v.name:lower (), fixed_target) or
1462 string.find (v.description:lower (), fixed_target) then
1463 matches [k] = true
1464 count = count + 1
1465 end -- if match
1466 end -- for each room
1467
1468 local function show_snippet (uid)
1469 local room = rooms [uid]
1470 if not room then
1471 return
1472 end -- if
1473
1474 -- don't bother if the wanted words was in the room name
1475 if string.find (room.name:lower (), fixed_target) then
1476 return
1477 end -- if
1478
1479 -- otherwise show the wanted word in the description, in bold
1480 AnsiNote (reset .. string.gsub (room.desc, caseless_target, bold .. "%1" .. unbold))
1481
1482 end -- show_snippet
1483
1484 -- see if nearby
1485 mapper.find (
1486 function (uid)
1487 local room = matches [uid]
1488 if room then
1489 matches [uid] = nil
1490 end -- if
1491 return room, next (matches) == nil
1492 end, -- function
1493 show_vnums, -- show vnum?
1494 count, -- how many to expect
1495 false, -- don't auto-walk
1496 show_snippet -- show find snippet
1497 )
1498end -- map_find
1499
1500
1501
1502-- -----------------------------------------------------------------
1503-- map_goto for: mapper goto xxx
1504-- -----------------------------------------------------------------
1505function map_goto (name, line, wildcards)
1506 local wanted = wildcards [1]
1507 -- check valid string
1508 if string.match (wanted, "%D") then
1509 mapper.maperror ("Room number must be numeric, you entered: " .. wanted)
1510 return
1511 end -- if
1512
1513 -- see if already there
1514 if current_room and string.match (current_room, "^" .. wanted) then
1515 mapper.mapprint ("You are already in that room.")
1516 return
1517 end -- if
1518 -- find desired room
1519 mapper.find (
1520 function (uid)
1521 local found = string.match (uid, "^" .. wanted)
1522 return found, found
1523 end, -- function
1524 show_vnums, -- show vnum?
1525 1, -- how many to expect
1526 true -- just walk there
1527 )
1528end -- map_goto
1529
1530function map_resume (name, line, wildcards)
1531
1532 local wanted = mapper.last_hyperlink_uid or mapper.last_speedwalk_uid
1533
1534 if not wanted then
1535 mapper.print "No outstanding speedwalks or hyperlinks."
1536 return
1537 end -- if nothing to do
1538
1539 -- find desired room
1540 mapper.find (
1541 function (uid)
1542 return uid == wanted, uid == wanted
1543 end, -- function
1544 show_vnums, -- show vnum?
1545 1, -- how many to expect
1546 true -- just walk there
1547 )
1548
1549end -- map_resume
1550
1551-- -----------------------------------------------------------------
1552-- map_where: Show where a room is
1553-- -----------------------------------------------------------------
1554function map_where (name, line, wildcards)
1555 if not mapper.check_we_can_find () then
1556 return
1557 end -- if
1558 local wanted = wildcards [1]
1559 if current_room and wanted == current_room then
1560 mapper.mapprint ("You are already in that room.")
1561 return
1562 end -- if
1563 local paths = mapper.find_paths (current_room,
1564 function (uid)
1565 return uid == wanted, -- wanted room?
1566 uid == wanted -- stop searching?
1567 end)
1568 local uid, item = next (paths, nil) -- extract first (only) path
1569 -- nothing? room not found
1570 if not item then
1571 mapper.mapprint (string.format ("Room %s not found", wanted))
1572 return
1573 end -- if
1574 -- turn into speedwalk
1575 local path = mapper.build_speedwalk (item.path)
1576 -- display it
1577 mapper.mapprint (string.format ("Path to %s is: %s", wanted, path))
1578end -- map_where
1579
1580-- -----------------------------------------------------------------
1581-- cannot_walk - we tried to walk but failed
1582-- -----------------------------------------------------------------
1583function cannot_walk (name, line, wildcards)
1584 mapper.cancel_speedwalk ()
1585 just_got_room_name = false
1586 last_direction_moved = nil
1587 EnableTrigger ("get_room_name", true)
1588 EnableTrigger ("get_description_line", false)
1589
1590
1591
1592-- mapper.mapprint ("Attempt to walk cancelled.")
1593
1594end -- cannot_walk
1595function check_for_cannot_go (name, line, wildcards)
1596 if cannot_move_messages [line] then
1597 cannot_walk ()
1598 end -- if
1599end -- check_for_cannot_go
1600
1601 --function OnPluginSent (sText)
1602-- if valid_direction [sText] then
1603-- last_direction_moved = valid_direction [sText]
1604 -- Note("Just moved", last_direction_moved)
1605-- if current_room and rooms [current_room] then
1606-- expected_exit = rooms [current_room].exits [last_direction_moved]
1607-- if expected_exit then
1608-- from_room = current_room
1609-- end -- if
1610 -- Note("expected exit for this direction is to room", expected_exit)
1611-- end -- if
1612-- end -- if
1613 --end -- function
1614
1615
1616function confirm_delete_area(a)
1617 response = utils.umsgbox("Delete area: "..a.."?", "Delete Area", "okcancel", "?", 2)
1618 if response == "ok" then
1619 delete_area(a)
1620 end
1621end
1622
1623function Door_Closed (name, line, wildcards)
1624
1625local dirs = {
1626 n = "north",
1627 s = "south",
1628 e = "east",
1629 w = "west",
1630 u = "up",
1631 d = "down",
1632 ne = "northeast",
1633 sw = "southwest",
1634 nw = "northwest",
1635 se = "southeast",
1636 ['in'] = "in",
1637 out = "out",
1638 } -- end of available
1639
1640 if last_direction_moved then
1641 Send ("open " .. dirs [last_direction_moved])
1642 Send (dirs [last_direction_moved])
1643 end -- if
1644
1645end -- Door_Closed
1646
1647
1648-- -----------------------------------------------------------------
1649-- check_for_cannot_go - look up the line in a table of failure messages
1650-- see table: cannot_move_messages
1651-- -----------------------------------------------------------------
1652function check_for_cannot_go (name, line, wildcards)
1653
1654 for _, v in ipairs (cannot_move_messages) do
1655 if string.find (line, v) then
1656 cannot_walk ()
1657 break
1658 end -- if match
1659 end -- for each message
1660end -- check_for_cannot_go
1661
1662function findpathfast(name, line, wildcards)
1663 local src = wildcards[1]
1664 local dest = wildcards[2]
1665 rooms[src] = load_room_from_database(src)
1666 rooms[dest] = load_room_from_database(dest)
1667
1668 if rooms[src] == nil then
1669 mapper.mapprint (string.format ("Room %s not known.", src))
1670 end
1671 if rooms[dest] == nil then
1672 mapper.mapprint (string.format ("Room %s not known.", dest))
1673 end
1674 if rooms[src] == nil or rooms[dest] == nil then
1675 return
1676 end
1677
1678 local foundpath = findpath(src, dest)
1679 if foundpath == nil then
1680 mapper.mapprint (string.format ("Path from %s to %s not found.", wildcards[1], wildcards[2]))
1681 return
1682 end
1683
1684 -- turn into speedwalk
1685 local speedwalk = mapper.build_speedwalk (foundpath, speedwalk_prefix)
1686
1687 -- display it
1688 if speedwalk ~= nil then
1689 mapper.mapprint (string.format ("Path from %s to %s is: %s", wildcards[1], wildcards[2], speedwalk))
1690 else
1691 mapper.mapprint ("Pick different start and end rooms.")
1692 end
1693end
1694
1695function blackindigoPrint(msg)
1696 ColourNote("blueviolet","black",msg)
1697end
1698function blackredPrint(msg)
1699 ColourNote("black","red",msg)
1700end
1701function whiteindigoPrint(msg)
1702 ColourNote("white","indigo",msg)
1703end
1704
1705
1706function setup_terrain_colors()
1707terrain_color["0"]=tonumber("0x000000")--NOTSET
1708terrain_color["inside"]=tonumber("0x606060")--Inside
1709terrain_color["city"]=tonumber("0x907040")--City
1710terrain_color["field"]=tonumber("0x00ff00")--Field
1711terrain_color["forest"]=tonumber("0x008000")--Forest
1712terrain_color["hills"]=tonumber("0x409040")--Hills
1713terrain_color["mountain"]=tonumber("0xc0c0c0")--Mountain
1714terrain_color["mount2"]=tonumber("0x406080")--Mount2
1715terrain_color["swim"]=ColourNameToRGB("blue")--Swim
1716terrain_color["water"]=ColourNameToRGB("blue")--Water
1717terrain_color["noswim"]=ColourNameToRGB("darkblue")--NoSwim
1718terrain_color["unused"]=tonumber("0xc0c0c0")--Unused
1719terrain_color["air"]=tonumber("0x808080")--Air
1720terrain_color["desert"]=tonumber("0x00ffff")--Desert (proper color)
1721terrain_color["swamp"]=tonumber("0x406080")--Swamp
1722terrain_color["road"]=ColourNameToRGB("saddlebrown")--Road
1723terrain_color["enter"]=tonumber("0x606060")--Enter
1724terrain_color["snow"]=ColourNameToRGB("navajowhite")--Snow
1725terrain_color["rock"]=tonumber("0x808080")--Rock
1726terrain_color["jungle"]=tonumber("0x20c040")--Jungle
1727terrain_color["ruins"]=tonumber("0x806060")--Ruins
1728terrain_color["coastline"]=ColourNameToRGB("blue")--Coastal
1729terrain_color["developed"]=tonumber("0x021e6c")--Developed
1730terrain_color["void"]=tonumber("0x303030")--Void
1731terrain_color["lava"]=ColourNameToRGB("red")--Lava
1732 -- end of terrain_color
1733end
1734
1735
1736-- -----------------------------------------------------------------
1737-- Plugin Install
1738-- -----------------------------------------------------------------
1739
1740function OnPluginInstall ()
1741
1742 config = {} -- in case not found
1743 setup_terrain_colors()
1744
1745 -- get saved configuration
1746 assert (loadstring (GetVariable ("config") or "")) ()
1747
1748 -- and rooms
1749 --assert (loadstring (GetVariable ("rooms") or "")) ()
1750
1751 -- new stuff for sql data
1752 check_create_db()
1753 load_rooms()
1754
1755 -- initialize mapper
1756
1757 mapper.init { config = config,
1758 get_room = get_room, findpath = findpath,
1759 room_click = room_click, -- called on RH click on room square,
1760 show_help = OnHelp, -- to show help,
1761 show_other_areas = show_other_areas, -- want to see areas other than the current one?
1762}
1763 mapper.mapprint (string.format ("CleftMUSH Mapper installed, version %0.1f", mapper.VERSION))
1764
1765
1766end -- OnPluginInstall
1767
1768function OnHelp (name, line, wildcards)
1769 local help_header = " [Cleft Mush Mapper Help] "
1770
1771 local help_index = [[
1772 Mapper Help Index
1773=============================================================================
1774 mapper help --> Show this list
1775-----------------------------------------------------------------------------
1776 mapper help config --> Commands for configuring the mapper
1777 mapper help moving --> Commands for moving between rooms
1778 mapper help utils --> Other utilitarian commands
1779 mapper help searching --> Used for finding notes, shops, banks, etc
1780=============================================================================
1781]]
1782 local help_table = {
1783 ['config'] = {
1784['header'] = [[===== CONFIGURATION =============>]],
1785[[mapper help --> This help
1786 > (or click the "?" button on the top right)]],
1787[[mapper zoom out --> Zoom out]],
1788[[mapper zoom in --> Zoom in]],
1789[[mapper hide --> Hide map]],
1790[[mapper show --> Show map]],
1791[[mapper updown --> Toggle up/down exit drawing]],
1792[[mapper underlines --> Toggle underlining of clickable links]]
1793},
1794
1795 ['utils'] = {
1796['header'] = [[===== UTILITIES =================>]],
1797[[mapper backup --> Creates a backup of the mapper database]],
1798[[mapper addnote --> Add a new note to the current room]],
1799[[mapper addnote <note> --> Ditto, but skips the dialog]]
1800},
1801 ['searching'] = {
1802['header'] = [[===== SEARCHING =================>]],
1803[[mapper find <text> --> Full-text search the whole database]],
1804[[]],
1805[[mapper where <room id> --> Show directions to a room number]]
1806},
1807
1808
1809 ['moving'] = {
1810['header'] = [[===== MOVING ====================>]],
1811[[mapper goto <room id> --> Run to a room by its room number]]
1812}
1813}
1814
1815 local function show_help(helps)
1816 blackindigoPrint("")
1817 blackindigoPrint(helps['header'])
1818 blackindigoPrint("")
1819 for i,v in ipairs(helps) do
1820 blackindigoPrint(v)
1821 end
1822 end
1823
1824 blackindigoPrint("")
1825 whiteindigoPrint(help_header)
1826 blackindigoPrint("+---------------------------------------------------------------------------+")
1827 badnews = true
1828 if wildcards and wildcards[2] ~= "" then
1829 badnews = false
1830 if wildcards[2] == "all" then
1831 show_help(help_table['config'])
1832 show_help(help_table['exits'])
1833 show_help(help_table['searching'])
1834 show_help(help_table['moving'])
1835 show_help(help_table['utils'])
1836 elseif wildcards[2] == "config" then
1837 show_help(help_table['config'])
1838 elseif wildcards[2] == "searching" then
1839 show_help(help_table['searching'])
1840 elseif wildcards[2] == "moving" then
1841 show_help(help_table['moving'])
1842 elseif wildcards[2] == "utils" then
1843 show_help(help_table['utils'])
1844 elseif wildcards[2]:find("search ") == 1 then
1845 local st, en = wildcards[2]:find("search ")
1846 local pattern = Trim(wildcards[2]:sub(en+1))
1847 ColourTell("cornflower","black","Searching help for: ")
1848 ColourNote("red","black",pattern)
1849 if pattern ~= "" then
1850 for k,v in pairs(help_table) do
1851 local done_header = false
1852 for j,w in ipairs(v) do
1853 if (w ~= "") and (w:find("--------",nil,true) == nil) and (w:find(pattern) ~= nil) then
1854 if not done_header then
1855 blackindigoPrint("")
1856 blackindigoPrint(v['header'])
1857 done_header = true
1858 end
1859 blackindigoPrint("")
1860 local wtable = w:split(pattern)
1861 for i,v in ipairs(wtable) do
1862 ColourTell("cornflower","black",v)
1863 if (i < #wtable) then
1864 ColourTell("red", "black", pattern)
1865 end
1866 end
1867 Note("")
1868 end
1869 end
1870 end
1871 else
1872 badnews = true
1873 end
1874 else
1875 badnews = true
1876 end
1877 end
1878 if badnews then
1879 blackindigoPrint("")
1880 mapper.mapprint (world.GetPluginInfo (world.GetPluginID (), 3))
1881 blackindigoPrint("")
1882 blackindigoPrint(help_index)
1883 end
1884 blackindigoPrint("")
1885 blackindigoPrint("+---------------------------------------------------------------------------+")
1886 blackindigoPrint("")
1887end
1888
1889
1890-- -----------------------------------------------------------------
1891-- Plugin Save State
1892-- -----------------------------------------------------------------
1893
1894function OnPluginSaveState ()
1895 mapper.save_state ()
1896 SetVariable ("config", "config = " .. serialize.save_simple (config))
1897 SetVariable("last_backup", last_backup)
1898SetVariable("OUR_ROOM_COLOUR", OUR_ROOM_COLOUR) -- Color of Room Border
1899end -- OnPluginSaveState
1900
1901------------------------------------------
1902-- start of sql additions
1903------------------------------------------
1904function delete_room_alias(name, line, wildcards)
1905 local num = wildcards[1]
1906 if num then
1907 delete_room(num)
1908 end
1909end
1910
1911function delete_room_click(name, line, wildcards)
1912 local num = current_room
1913 if num then
1914 delete_room(num)
1915 end
1916end
1917
1918function delete_area_alias(name, line, wildcards)
1919 local a = wildcards[1]
1920 if a then
1921 delete_area(a)
1922 end
1923end
1924
1925function delete_room(num) -- delete room from rooms
1926 for r, tbl in pairs(rooms) do -- for each room in table
1927 if tostring(r) == tostring(num) then
1928 rooms[r] = nil -- setting table item to nil deletes it
1929 end
1930 end
1931 run_sql([[DELETE FROM rooms WHERE uid = ']]..num..[[']])
1932 Note("Deleted ", num, ".")
1933 SendNoEcho("look")
1934end
1935
1936function delete_area(a)
1937 local cnt = 0
1938 for r, tbl in pairs(rooms) do -- for each room in table
1939 if tostring(tbl.area) == tostring(a) then
1940 rooms[r] = nil -- setting table item to nil deletes it
1941 cnt = cnt + 1
1942 end
1943 end
1944 run_sql([[DELETE FROM rooms WHERE area = ']]..fix_sql(a)..[[']])
1945 Note("Deleted ", cnt, " rooms in '", a, "' area.")
1946end
1947
1948function clean_file_name(f)
1949 f = string.gsub(f, "[^%w]", "")
1950 return f
1951end
1952
1953function fix_sql(s)
1954 if not s then -- nil value
1955 return ""
1956 end
1957 return string.gsub(s, "'", "''")
1958end
1959
1960function run_sql(sql)
1961 local db = assert(sqlite3.open(GetInfo(66)..clean_file_name(WorldName())..".db"))
1962 --Note(sql)
1963 rslt = db:exec(sql)
1964 --Note(rslt)
1965 db:close()
1966end
1967
1968function load_rooms()
1969 rooms = {}
1970sql = [[
1971 UPDATE rooms SET fillcolour = 0 WHERE fillcolour = ''
1972 ]]
1973run_sql(sql)
1974 sql = [[
1975 SELECT * FROM rooms ORDER BY uid ASC;
1976 ]]
1977 local db = assert(sqlite3.open(GetInfo(66)..clean_file_name(WorldName())..".db"))
1978 local cnt = 0
1979 for row in db:nrows(sql) do
1980 cnt = cnt + 1
1981 rooms[row.uid] = {
1982 name = row.name,
1983 desc = row.desc,
1984 area = row.area,
1985 fillcolour = row.fillcolour,
1986 fillbrush = row.fillbrush,
1987 bordercolour = row.bordercolour,
1988 info = row.info,
1989 notes = row.notes,
1990 exits = loadstring("return "..row.exits)()
1991 }
1992 end
1993 Note("Loaded ", cnt, " rooms from database.")
1994 db:close()
1995
1996 if tonumber(last_backup) == 0 then
1997 backup_db()
1998 end
1999end
2000
2001function check_update_room(uid, room)
2002 if not rooms[uid] or (serialize.save_simple(room) ~= serialize.save_simple(rooms[uid])) then
2003 add_update_room(uid, room)
2004 end
2005end
2006
2007function add_update_room(uid, room)
2008 sql = [[
2009 INSERT OR REPLACE INTO rooms (uid, name, desc, area, fillcolour, fillbrush, bordercolour, info, notes, exits)
2010 VALUES
2011 (']]..uid..[[',
2012 ']]..fix_sql(room.name)..[[',
2013 ']]..fix_sql(room.desc)..[[',
2014 ']]..fix_sql(room.area)..[[',
2015 ']]..fix_sql(room.fillcolour)..[[',
2016 ']]..fix_sql(room.fillbrush)..[[',
2017 ']]..fix_sql(room.bordercolour)..[[',
2018 ']]..fix_sql(room.info)..[[',
2019 ']]..fix_sql(room.notes)..[[',
2020 ']]..fix_sql(serialize.save_simple(room.exits))..[[')
2021 ]]
2022 run_sql(sql)
2023end
2024
2025function check_create_db()
2026 sql = [[
2027 CREATE TABLE IF NOT EXISTS rooms (
2028 uid TEXT PRIMARY KEY,
2029 name TEXT,
2030 desc TEXT,
2031 area TEXT,
2032 fillcolour INTEGER,
2033 fillbrush INTEGER,
2034 bordercolour INTEGER,
2035 info TEXT,
2036 notes TEXT,
2037 exits TEXT
2038 )
2039 ]]
2040 run_sql(sql)
2041end
2042
2043------------------------------------------
2044-- end of sql additions
2045------------------------------------------
2046function room_delete_exit (room, uid, exit)
2047 local chosen_exit = exit
2048
2049 if chosen_exit == nil then
2050 local available = {} -- end of available
2051
2052 -- construct available exits list for display
2053 for k,v in pairs (room.exits) do
2054 available [k] = k .. " --> " .. room.exits [k]
2055 temp_room = k
2056print ("AvailableK: ", available [k])
2057print ("Available: ", available )
2058print ("Temp_Room: ", temp_room)
2059print ("RoomsK: ", room.exits [k])
2060 room.exits[k] = nil -- setting table item to nil deletes it
2061 SendNoEcho("look")
2062 end -- for
2063
2064 if next (available) == nil then
2065 utils.msgbox ("There are no exits from this room.", "No exits!", "ok", "!", 1)
2066 return
2067 end -- not known
2068 local chosen_exit = utils.listbox ("Choose exit to delete", "Exits ...", available )
2069 if not chosen_exit then
2070 return
2071 end
2072 end
2073 print("Temp_Room: ", temp_room)
2074 print("AvailableK: ", available [k])
2075
2076 room.exits[temp_room] = nil -- setting table item to nil deletes it
2077 run_sql([[DELETE FROM rooms WHERE uid = ']]..room.exits[temp_room]..[[']])
2078 mapper.mapprint ("Deleted exit '"..chosen_exit.."' from room "..uid.." from database.")
2079 mapper.mapprint ("Deleted exit '"..chosen_exit.."' from room "..uid.." from database.")
2080
2081 -- update in-memory table
2082 add_update_room(uid, rooms[uid])
2083
2084 mapper.draw (uid)
2085
2086end -- room_delete_exit
2087
2088function room_change_exit (room, uid, exit)
2089 local chosen_exit = exit
2090
2091 if chosen_exit == nil then
2092 local available = {} -- end of available
2093
2094 -- construct available exits list for display
2095 for k,v in pairs (room.exits) do
2096 available [k] = k .. " --> " .. room.exits [k]
2097 temp_room = k
2098 end -- for
2099
2100 if next (available) == nil then
2101 utils.msgbox ("There are no exits from this room.", "No exits!", "ok", "!", 1)
2102 return
2103 end -- not known
2104
2105 local chosen_exit = utils.listbox ("Choose exit to change destination of:", "Exits ...", available )
2106 if not chosen_exit then
2107 return
2108 end
2109--print("Chosen_Exit: ", chosen_exit)
2110--print ("Temp_Room: ", temp_room)
2111--print ("exitsK: ", room.exits[chosen_exit])
2112temp_exit = chosen_exit
2113 end
2114--print("Chosen_Exit: ", chosen_exit)
2115--print ("Temp_Room: ", temp_room)
2116--print ("exitsK: ", room.exits[chosen_exit])
2117--print ("TempExit: ", temp_exit)
2118 exit_destination = utils.inputbox ("Enter destination room identifier (number) for " .. temp_exit, room.name, room.exits[temp_exit])
2119
2120 if not exit_destination then
2121 return
2122 end -- cancelled
2123
2124 -- look it up
2125 local dest_room = rooms [exit_destination]
2126
2127 -- not cached - see if in database
2128 if not dest_room then
2129 dest_room = load_room_from_database (exit_destination)
2130 rooms [exit_destination] = dest_room -- cache for later
2131 end -- not in cache
2132
2133 if not dest_room then
2134 utils.msgbox ("Room " .. exit_destination .. " does not exist.", "Room does not exist!", "ok", "!", 1)
2135 return
2136 end -- if still not there
2137
2138 if exit_destination ~= room.exits[temp_exit] then
2139 run_sql(string.format ([[
2140 UPDATE exits SET touid = %s WHERE dir = %s AND fromuid = %s;
2141 ]],
2142 fix_sql (exit_destination),
2143 fix_sql (temp_exit), -- direction (eg. "n")
2144 fix_sql (uid) -- from current room
2145 ))
2146
2147 mapper.mapprint ("Modified exit", temp_exit, "from room", uid, "to be to room", exit_destination, "in database.")
2148
2149 -- update in-memory table
2150 rooms [uid].exits [temp_exit] = exit_destination
2151 mapper.draw (current_room)
2152 else
2153 mapper.mapprint ("Destination unchanged for exit '"..temp_exit.."'.")
2154 end
2155
2156end -- room_change_exit
2157
2158
2159------------------------------------------
2160-- backup stuff
2161------------------------------------------
2162-- If you want to do manual backups, make an alias with: script="backup_db"
2163------------------------------------------
2164
2165function backup_db()
2166 Note("Creating database backup.")
2167 local bk_nm = GetInfo(66).."db_backups\\"..clean_file_name(WorldName())..".db."..os.date("%A")
2168 ffi = require("ffi")
2169 ffi.cdef[[
2170 bool CreateDirectoryA(const char *lpPathName, void *lpSecurityAttributes);
2171 bool CopyFileA(const char* lpExistingFileName, const char * lpNewFileName, bool bFailIfExists);
2172 unsigned long GetLastError(void);
2173 ]]
2174
2175 succ = ffi.C.CreateDirectoryA(GetInfo(66).."db_backups\\", nil)
2176 err_no = ffi.C.GetLastError()
2177 if err_no and err_no ~= 183 and err_no ~= 127 then
2178 Note("Error creating directory: ", err_no)
2179 end
2180
2181 succ = ffi.C.CopyFileA(GetInfo(66)..clean_file_name(WorldName())..".db", bk_nm, false)
2182
2183 Note("Backup created: ", bk_nm)
2184 last_backup = os.time()
2185end
2186
2187------------------------------------------
2188-- end backup stuff
2189------------------------------------------
2190
2191-- Special thanks to Fiendish, Endymion, Valour, and Nick Gammon for all of their assistance with the mapper, and the original basis from which its built.
2192
2193]]>
2194</script>
2195
2196
2197</muclient>