-
Notifications
You must be signed in to change notification settings - Fork 15
/
Inquisition_Mapper.xml
694 lines (576 loc) · 17.6 KB
/
Inquisition_Mapper.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<muclient>
<plugin
name="Inquisition_Mapper"
author="Nick Gammon"
id="2a5655924080806ca252f1e6"
language="Lua"
purpose="Mapper for The Inquisition"
save_state="y"
date_written="2018-01-15"
date_modified="2018-01-16 13:09"
requires="5.00"
version="1.4"
>
<description trim="y">
<![CDATA[
THE INQUISITION MAPPER ... by Nick Gammon
ACTIONS
mapper help --> this help (or click the "?" button on the bottom right)
mapper zoom out --> zoom out
mapper zoom in --> zoom in
mapper hide --> hide map
mapper show --> show map
FINDING
mapper find <word> --> find a room matching part of a name / description
mapper where <vnum> --> show directions to a room
MOVING
mapper goto <room> --> walk to a room by its room number (vnum)
mapper stop --> cancel any current speedwalk
]]>
</description>
</plugin>
<aliases>
<alias
match="mapper help"
script="OnHelp"
enabled="y"
>
</alias>
<!-- finding stuff -->
<alias
match="mapper find *"
enabled="y"
sequence="100"
script="map_find"
>
</alias>
<alias
match="mapper where *"
enabled="y"
sequence="100"
script="map_where"
>
</alias>
<!-- zooming aliases -->
<alias
match="mapper zoom out"
enabled="y"
sequence="100"
omit_from_command_history="y"
omit_from_output="y"
script="mapper.zoom_out"
>
</alias>
<alias
match="mapper zoom in"
enabled="y"
sequence="100"
omit_from_command_history="y"
omit_from_output="y"
script="mapper.zoom_in"
>
</alias>
<alias
match="mapper goto *"
enabled="y"
sequence="100"
script="map_goto"
>
</alias>
<!-- cancel speedwalking -->
<alias
match="mapper stop"
enabled="y"
sequence="100"
script="mapper.cancel_speedwalk"
>
</alias>
<!-- show/hide mapper -->
<alias
match="mapper hide"
enabled="y"
sequence="100"
script="mapper.hide"
>
</alias>
<alias
match="mapper show"
enabled="y"
sequence="100"
script="mapper.show"
>
</alias>
</aliases>
<triggers>
<trigger
enabled="y"
match="[RPXP Gain: *] [HP:* MV:* P:*] * (vnum *)*"
script="got_prompt"
sequence="100"
name="prompt"
keep_evaluating="y"
>
</trigger>
<trigger
back_colour="8"
enabled="y"
match="^([^\[].*)$"
match_back_colour="y"
match_text_colour="y"
script="got_room_name"
text_colour="9"
keep_evaluating="y"
sequence="90"
regexp="y"
bold="y"
match_bold="y"
name="room_name"
>
</trigger>
<trigger
back_colour="8"
enabled="y"
match="^\["
match_back_colour="y"
match_text_colour="y"
script="got_weather_line"
text_colour="9"
keep_evaluating="y"
sequence="90"
regexp="y"
bold="y"
match_bold="y"
name="weather_line"
>
</trigger>
<trigger
back_colour="8"
enabled="y"
match="[ Exits: * ]"
match_back_colour="y"
match_bold="y"
match_inverse="y"
match_italic="y"
match_text_colour="y"
script="got_exits"
sequence="100"
text_colour="14"
>
</trigger>
<trigger
enabled="n"
match="*"
script="got_description_line"
sequence="200"
name="description_line"
>
</trigger>
<!--
Things which prevent us moving.
Right now we assume they are yellow on black in bold. If this isn't (always) the case
change match_text_colour, match_back_colour and match_bold to be "n" (as appropriate).
See "cannot_move_messages" table further down for the exact messages that are matched on.
-->
<trigger
match="*"
enabled="y"
match_back_colour="y"
match_text_colour="y"
match_bold="y"
bold="y"
text_colour="3"
back_colour="8"
script="check_for_cannot_go"
keep_evaluating="y"
sequence="1"
>
</trigger>
</triggers>
<!-- Script -->
<script>
<![CDATA[
-- mapper module
require "mapper"
-- configuration table
config = {
OUR_ROOM_COLOUR = { name = "Our room", colour = ColourNameToRGB "black", },
}
-- all the rooms we have come across
rooms = { }
-- for serialization
require "serialize"
-- -----------------------------------------------------------------
-- these commands will be considered "room changing" commands
-- -----------------------------------------------------------------
local valid_direction = {
n = "n",
s = "s",
e = "e",
w = "w",
u = "u",
d = "d",
ne = "ne",
sw = "sw",
nw = "nw",
se = "se",
north = "n",
south = "s",
east = "e",
west = "w",
up = "u",
down = "d",
northeast = "ne",
northwest = "nw",
southeast = "se",
southwest = "sw",
["in"] = "in",
out = "out",
} -- end of valid_direction
-- for calculating the way back
local inverse_direction = {
n = "s",
s = "n",
e = "w",
w = "e",
u = "d",
d = "u",
ne = "sw",
sw = "ne",
nw = "se",
se = "nw",
["in"] = "out",
out = "in",
} -- end of inverse_direction
-- put messages from the MUD which stop you moving here ...
-- Use * for wildcards, everything else matches literally.
local cannot_move_messages = {
"Nah... * feels too relaxed...",
"In * dreams, or what?",
-- add more here
}
-- -----------------------------------------------------------------
-- for converting things like ^ $ * etc. into "escaped" sequences
-- -----------------------------------------------------------------
function fix_regexp_magic_characters (r)
return string.gsub (r, "[%^%$%(%)%%%.%[%]%*%+%-%?]", "%%%1")
end -- fix_regexp_magic_characters
-- -----------------------------------------------------------------
-- mapper 'get_room' callback - it wants to know about room uid
-- -----------------------------------------------------------------
function get_room (uid)
room = rooms [uid]
if not room then
return nil
end -- if not found
-- how to draw this particular room
room.bordercolour = config.ROOM_COLOUR.colour
room.borderpen = miniwin.pen_solid
room.borderpenwidth = 1
room.fillbrush = miniwin.brush_null -- no fill
-- draw current room in bolder colour
if uid == current_room then
room.bordercolour = config.OUR_ROOM_COLOUR.colour
room.borderpenwidth = 2
end -- not in this area
room.area = "The Inquisition" -- assume every room is in this area
local texits = {}
for dir in pairs (room.exits) do
table.insert (texits, dir)
end -- for
table.sort (texits)
room.hovermessage = string.format (
"%s\tExits: %s\nVnum: %s\n\n%s",
room.name,
table.concat (texits, ", "),
uid,
room.description or ""
)
return room
end -- get_room
-- -----------------------------------------------------------------
-- Plugin Install
-- -----------------------------------------------------------------
function OnPluginInstall ()
assert (loadstring (GetVariable ("config") or "")) ()
assert (loadstring (GetVariable ("rooms") or "")) ()
-- initialize mapper
mapper.init {
config = config, -- ie. colours, sizes
get_room = get_room, -- info about room (uid)
show_help = OnHelp, -- to show help
}
mapper.mapprint (string.format ("MUSHclient mapper installed, version %0.1f", mapper.VERSION))
ColourNote ("orange", "", "Mapper plugin 'save state' file name is:")
ColourNote ("yellow", "", (string.format ("%s%s-%s-state.xml",
GetInfo (85), GetWorldID (), GetPluginID ())))
mapper.mapprint ("Consider backing up the above file regularly as it has the mapper database in it.")
-- fix up wildcards in "cannot_move_messages" table
for k, v in ipairs (cannot_move_messages) do
-- replace wildcard (asterisk) by 0x00
v = string.gsub (v, '%*', string.char (0))
-- fix all other characters like periods
v = fix_regexp_magic_characters (v)
-- put the wildcards back (convert 0x00 to ".*")
cannot_move_messages [k] = string.gsub (v, string.char (0), '.*' )
end -- for each message
end -- OnPluginInstall
-- -----------------------------------------------------------------
-- Plugin Help
-- -----------------------------------------------------------------
function OnHelp ()
mapper.mapprint (string.format ("[MUSHclient mapper, version %0.1f]", mapper.VERSION))
mapper.mapprint (GetPluginInfo (GetPluginID (), 3))
end
-- -----------------------------------------------------------------
-- Here on prompt
-- -----------------------------------------------------------------
function got_prompt (name, line, wildcards)
uid = wildcards [6] -- change this if you change the prompt trigger
-- assume we know the room name and description by now
-- add to rooms table if not there
if not rooms [uid] then
rooms [uid] = { name = room_name, exits = {}, description = room_description or ""}
mapper.mapprint (string.format ("Added room <%s> (vnum %s) to the mapper database", room_name, uid))
end -- if
if rooms [uid].description ~= room_description then
rooms [uid].description = room_description
-- mapper.mapprint ("Updating room description to be: " .. room_description)
end -- if description not previously found
-- add stub entries for known exits
if next (rooms [uid].exits) == nil and current_exits then
for exit in string.gmatch (current_exits, "%a+") do
local direction = valid_direction [exit]
if direction then
rooms [uid].exits [direction] = 0 -- dummy non-existent room
end -- if a known exit direction
end -- for each exit word
end -- if no exits known
-- if we changed rooms assume that our last movement sent us here
if uid ~= current_room
and current_room
and last_direction_moved then
-- previous room led here
rooms [current_room].exits [last_direction_moved] = uid
-- assume inverse direction leads back
rooms [uid].exits [inverse_direction [last_direction_moved]] = current_room
last_direction_moved = nil -- we have to move again now
end -- if
-- this is now our current room
current_room = uid
-- draw this room
mapper.draw (current_room)
-- await more exits
current_exits = nil
end -- got_prompt
-- -----------------------------------------------------------------
-- Here on room name
-- -----------------------------------------------------------------
function got_room_name (name, line, wildcards)
local name = wildcards [1]
-- ignore really long lines
if #name > 60 then
return
end -- if
room_name = name
current_exits = nil
description = { }
room_description = nil
end -- got_room_name
-- -----------------------------------------------------------------
-- Here on "exits" line
-- -----------------------------------------------------------------
function got_exits (name, line, wildcards)
-- remember the exits
current_exits = wildcards [1]
EnableTrigger ("description_line", false)
room_description = Trim (table.concat (description, "\n"))
description = { }
end -- got_exits
-- -----------------------------------------------------------------
-- try to detect when we send a movement command
-- -----------------------------------------------------------------
function OnPluginSent (sText)
local direction = valid_direction [sText]
if direction then
last_direction_moved = direction
end -- if
end -- OnPluginSent
-- -----------------------------------------------------------------
-- on saving state, serialize the rooms and configuration
-- -----------------------------------------------------------------
function OnPluginSaveState ()
SetVariable ("config", "config = " .. serialize.save_simple (config))
-- just save the relevant stuff - you may need to update this if you add more things
local wanted_keys = { "name", "exits", "description" }
local saved_rooms = { }
for k, v in pairs (rooms) do
saved_rooms [k] = { }
for i, j in ipairs (wanted_keys) do
saved_rooms [k] [j] = v [j]
end -- for
end -- for
SetVariable ("rooms", "rooms = " .. serialize.save_simple (saved_rooms))
end -- function OnPluginSaveState
-- -----------------------------------------------------------------
-- map_find: mapper find xxx
-- -----------------------------------------------------------------
function map_find (name, line, wildcards)
mapper.mapprint (string.rep ("-", 25) .. " Mapper search " .. string.rep ("-", 25))
local reset = ANSI (0)
local bold = ANSI (1)
local unbold = ANSI (22)
local matches = { }
local count = 0
local target = Trim (wildcards [1]:lower ())
if target == "" then
mapper.maperror ("No search string specified")
return
end -- if
if not mapper.check_we_can_find () then
return
end -- if find not OK
-- fix up any regular expression "magic" letters to be escaped by a %
local fixed_target = fix_regexp_magic_characters (target)
-- fix up for caseless searches in the room description (eg. "a" becomes "[aA]")
local caseless_target = string.gsub (fixed_target, "(%a)", function (a)
return "[" .. a:lower () .. a:upper () .. "]"
end -- function
)
-- do a simple string search to find matching rooms
for k, v in pairs (rooms) do
-- don't want nil descriptions
if not v.description then
v.description = ""
end -- if no description
if string.find (v.name:lower (), fixed_target) or
string.find (v.description:lower (), fixed_target) then
matches [k] = true
count = count + 1
end -- if match
end -- for each room
local function show_snippet (uid)
local room = rooms [uid]
if not room then
return
end -- if
-- don't bother if the wanted words was in the room name
if string.find (room.name:lower (), fixed_target) then
return
end -- if
-- otherwise show the wanted word in the description, in bold
AnsiNote (reset .. string.gsub (room.description, caseless_target, bold .. "%1" .. unbold))
end -- show_snippet
-- see if nearby
mapper.find (
function (uid)
local room = matches [uid]
if room then
matches [uid] = nil
end -- if
return room, next (matches) == nil
end, -- function
show_vnums, -- show vnum?
count, -- how many to expect
false, -- don't auto-walk
show_snippet -- show find snippet
)
end -- map_find
-- -----------------------------------------------------------------
-- map_goto for: mapper goto xxx
-- -----------------------------------------------------------------
function map_goto (name, line, wildcards)
local wanted = wildcards [1]
-- check valid string
if string.match (wanted, "%D") then
mapper.maperror ("Room number must be numeric, you entered: " .. wanted)
return
end -- if
-- see if already there
if current_room and string.match (current_room, "^" .. wanted) then
mapper.mapprint ("You are already in that room.")
return
end -- if
-- find desired room
mapper.find (
function (uid)
local found = string.match (uid, "^" .. wanted)
return found, found
end, -- function
show_vnums, -- show vnum?
1, -- how many to expect
true -- just walk there
)
end -- map_goto
-- -----------------------------------------------------------------
-- got_weather_line: Called when we get the weather line (the description follows)
-- -----------------------------------------------------------------
function got_weather_line (name, line, wildcards)
EnableTrigger ("description_line", true)
description = { }
end -- got_weather_line
-- -----------------------------------------------------------------
-- got_description_line: Called for each line of the room description
-- -----------------------------------------------------------------
function got_description_line (name, line, wildcards)
-- stop collecting descriptions after a blank line
if Trim (line) == "" then
EnableTrigger ("description_line", false)
end -- if blank line
table.insert (description, line) -- build up the description
end -- got_description_line
-- -----------------------------------------------------------------
-- map_where: Show where a room is
-- -----------------------------------------------------------------
function map_where (name, line, wildcards)
if not mapper.check_we_can_find () then
return
end -- if
local wanted = wildcards [1]
if current_room and wanted == current_room then
mapper.mapprint ("You are already in that room.")
return
end -- if
local paths = mapper.find_paths (current_room,
function (uid)
return uid == wanted, -- wanted room?
uid == wanted -- stop searching?
end)
local uid, item = next (paths, nil) -- extract first (only) path
-- nothing? room not found
if not item then
mapper.mapprint (string.format ("Room %s not found", wanted))
return
end -- if
-- turn into speedwalk
local path = mapper.build_speedwalk (item.path)
-- display it
mapper.mapprint (string.format ("Path to %s is: %s", wanted, path))
end -- map_where
-- -----------------------------------------------------------------
-- cannot_walk - we tried to walk but failed
-- -----------------------------------------------------------------
function cannot_walk (name, line, wildcards)
mapper.cancel_speedwalk ()
room_description = nil
current_exits = nil
room_name = nil
last_direction_moved = nil
-- mapper.mapprint ("Attempt to walk cancelled.")
end -- cannot_walk
-- -----------------------------------------------------------------
-- check_for_cannot_go - look up the line in a table of failure messages
-- see table: cannot_move_messages
-- -----------------------------------------------------------------
function check_for_cannot_go (name, line, wildcards)
for _, v in ipairs (cannot_move_messages) do
if string.find (line, v) then
cannot_walk ()
break
end -- if match
end -- for each message
end -- check_for_cannot_go
]]>
</script>
</muclient>