-
Notifications
You must be signed in to change notification settings - Fork 15
/
Lands_Of_Redemption_Mapper.xml
733 lines (589 loc) · 18.3 KB
/
Lands_Of_Redemption_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
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient [
<!ENTITY show_database_mods "true" >
<!ENTITY speedwalk_prefix "" >
<!ENTITY debugging "false" >
]>
<muclient>
<plugin
name="Lands_Of_Redemption_Mapper"
author="Nick Gammon"
id="7c54b861a8cd3c4745c28834"
language="Lua"
purpose="Mapper for Lands of Redemption"
save_state="y"
date_written="2015-05-09"
requires="4.61"
version="1.0"
>
<description trim="y">
<![CDATA[
AUTOMATIC MAPPER ... by Nick Gammon
ACTIONS
mapper help --> this help (or click the "?" button on the bottom right)
mapper zoom out --> zoom out (or use the mouse-wheel)
mapper zoom in --> zoom in (or use the mouse-wheel)
mapper hide --> hide map
mapper show --> show map
mapper find <text> --> search
mapper where <room> --> show directions to a room by ID (can specify part ID)
mapper goto <room> --> walk to a room by its room ID
]]>
</description>
</plugin>
<aliases>
<alias
match="mapper help"
script="OnHelp"
enabled="y"
>
</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 hide"
enabled="y"
sequence="100"
script="mapper.hide"
>
</alias>
<alias
match="mapper show"
enabled="y"
sequence="100"
script="mapper.show"
>
</alias>
<!-- finding aliases -->
<alias
match="^mapper find ([\w* %d/"]+)$"
enabled="y"
sequence="100"
script="map_find"
regexp="y"
>
</alias>
<alias
match="mapper where *"
enabled="y"
sequence="100"
script="map_where"
>
</alias>
<alias
match="mapper goto *"
enabled="y"
sequence="100"
script="map_goto"
>
</alias>
<alias
match="mapper *"
enabled="y"
sequence="110"
send_to="12"
>
<send>
mapper.maperror ("Unknown mapper command: %1")
OnHelp ()
</send>
</alias>
</aliases>
<triggers>
<!-- Things which prevent us moving -->
<trigger
enabled="y"
match="*"
script="check_for_cannot_go"
keep_evaluating="y"
sequence="1"
>
</trigger>
<trigger
enabled="y"
keep_evaluating="y"
match="^\s*[a-zA-Z]"
name="got_room_name"
script="process_room_name"
regexp="y"
sequence="90"
>
</trigger>
<trigger
enabled="y"
keep_evaluating="y"
match="<*"
script="got_prompt"
sequence="90"
>
</trigger>
<trigger
keep_evaluating="y"
match="*"
name="got_description_line"
script="process_description_line"
sequence="100"
>
</trigger>
<trigger
enabled="y"
match="[Exits: *]"
name="got_exits"
script="process_exits_line"
sequence="90"
>
</trigger>
</triggers>
<!-- Script -->
<script>
local show_database_mods = &show_database_mods;
local speedwalk_prefix = "&speedwalk_prefix;"
local debugging = &debugging;
<![CDATA[
-- mapper module
require "mapper"
require "serialize" -- needed to serialize table to string
-- configuration table
config = {
OUR_ROOM_COLOUR = { name = "Our room", colour = ColourNameToRGB "black", },
SHOP_FILL_COLOUR = { name = "Shop", colour = ColourNameToRGB "darkolivegreen", },
}
-- all the rooms we have come across
rooms = { }
-- -----------------------------------------------------------------
-- 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
local cannot_move_messages = { }
-- put messages from the MUD which stop you moving here ...
for _, v in ipairs {
"You are too exhausted.",
"You take a running start and slam head first into a wall.",
"WHAM! Face first into the wall! Good one spaz.",
"THUD! Your sore face suggests there wasn't a secret passage there afterall.",
"You aren't allowed in there.",
"Alas, you cannot go that way.",
"In your dreams, or what?",
"You stumble all over yourself trying to do in that direction.",
"The door is closed.",
"You huff and puff trying to go that way, but, alas, you can't!.",
"No way! You are still fighting!",
"You need a boat to go there.",
-- add more here
} do cannot_move_messages [v] = true end
-- -----------------------------------------------------------------
-- 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
if string.find (room.name:lower (), "%f[%a]shop%f[%A]") then
room.fillcolour = config.SHOP_FILL_COLOUR.colour
room.fillbrush = 8
end -- if
-- 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 = "Lands of Redemption" -- assume every room is in this area
-- build hover message
local texits = {}
for dir, where in pairs (room.exits) do
if where == 0 then
where = "?"
end -- if
table.insert (texits, dir .. " --> " .. where:sub (1, 5))
end -- for
table.sort (texits)
room.hovermessage = string.format (
"%s\tExits: %s\nRoom: %s\n\n%s",
room.name,
table.concat (texits, ", "),
uid:sub (1, 5),
room.description
)
return room
end -- get_room
-- -----------------------------------------------------------------
-- Plugin Install
-- -----------------------------------------------------------------
function OnPluginInstall ()
-- initialize mapper
mapper.init {
config = config, -- ie. colours, sizes
get_room = get_room, -- info about room (uid)
show_help = OnHelp, -- to show help
speedwalk_prefix = speedwalk_prefix, -- how to speedwalk
-- room_click = room_click, -- called on RH click on room square
}
mapper.mapprint (string.format ("MUSHclient mapper installed, version %0.1f", mapper.VERSION))
-- on plugin install, convert variable into Lua table
assert (loadstring (GetVariable ("rooms") or "")) ()
assert (rooms, "Uh oh, no rooms table.")
end -- OnPluginInstall
-- -----------------------------------------------------------------
-- Plugin Help
-- -----------------------------------------------------------------
function OnHelp ()
mapper.mapprint (string.format ("[MUSHclient mapper, version %0.1f]", mapper.VERSION))
mapper.mapprint (world.GetPluginInfo (world.GetPluginID (), 3))
end
-- -----------------------------------------------------------------
-- end_of_description : we believe this is the end of the room description
-- -----------------------------------------------------------------
function end_of_description ()
EnableTrigger ("got_description_line", false)
EnableTrigger ("got_room_name", true)
if not current_description or #current_description == 0 then
if debugging then
ColourNote ("yellow", "", "No description")
end -- if
return
end -- if
if not current_exits then
if debugging then
ColourNote ("yellow", "", "No exits")
end -- if
return
end -- if
room_description = table.concat (current_description, "\n")
exits_string = table.concat (current_exits, ",")
-- generate a "room ID" by hashing the room name, description and exits
uid = utils.tohex (utils.md5 (room_name .. room_description .. exits_string))
uid = uid:sub (1, 25)
if debugging then
ColourNote ("cyan", "", room_description)
ColourNote ("darkorange", "", "last_direction_moved = " .. (last_direction_moved or "none"))
ColourNote ("darkorange", "", "current_room = " .. (current_room or "none"))
end -- if
-- assume we know the room name by now
-- add to rooms table if not there
if not rooms [uid] then
rooms [uid] = { name = room_name, exits = current_exits, description = room_description }
if show_database_mods then
mapper.mapprint ("Added room", uid, "to database. Name:", room_name)
for k, v in pairs (current_exits) do
mapper.mapprint ("Added exit", k, "to database.")
end -- for
end -- if
end -- if
if current_room and rooms [current_room] and not rooms [current_room].exits then
rooms [current_room].exits = { }
end -- if
-- 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
if rooms [current_room] then
if rooms [current_room].exits [last_direction_moved] ~= uid and show_database_mods then
mapper.mapprint ("Fixed exit ", last_direction_moved, "from", current_room, "to here in database")
end -- if
rooms [current_room].exits [last_direction_moved] = uid
end -- if
-- assume inverse direction leads back
rooms [uid].exits [inverse_direction [last_direction_moved]] = current_room
end -- if
-- this is now our current room
current_room = uid
-- remove exits the room had, but now no longer has
for k, v in pairs (rooms [uid].exits) do
if not current_exits [k] then
rooms [uid].exits [k] = nil
if show_database_mods then
mapper.mapprint ("Removing exit: " .. k)
end -- if
end -- if
end -- for each exit this room has
-- add in exits we know about but which aren't there
for k, v in pairs (current_exits) do
if not rooms [uid].exits [k] then
rooms [uid].exits [k] = 0
if show_database_mods then
mapper.mapprint ("Adding exit: " .. k)
end -- if
end -- if
end -- for
-- draw this room
mapper.draw (current_room)
current_description = nil
current_exits = nil
room_name = nil
just_got_room_name = false
last_direction_moved = nil
end -- end_of_description
-- -----------------------------------------------------------------
-- Here on prompt
-- -----------------------------------------------------------------
function got_prompt (name, line, wildcards)
if debugging then
ColourNote ("yellow", "", "got_prompt")
end -- if
end_of_description ()
end -- got_prompt
-- -----------------------------------------------------------------
-- Here on room name
-- -----------------------------------------------------------------
function process_room_name (name, line, wildcards, styles)
local name = line
if debugging then
ColourNote ("yellow", "", "process_room_name: " .. name)
end -- if
-- ignore exits lines
if string.match (name, "^%[Exits: ") then
return
end -- if
-- ignore really long lines
if #name > 50 then
return
end -- if
room_name = name
EnableTrigger ("got_description_line", true)
EnableTrigger ("got_room_name", false)
current_description = { }
just_got_room_name = true
end -- got_room_name
-- -----------------------------------------------------------------
-- process_description_line : Here on one line of the description
-- -----------------------------------------------------------------
function process_description_line (name, line, wildcards)
if Trim (line) == "" then
return
end -- if
if debugging then
ColourNote ("yellow", "", "process_description_line: " .. line)
end -- if
if not current_description then
ColourNote ("yellow", "", "No current description")
end -- if
if just_got_room_name then
-- false alarm!
if line:sub (1, 2) ~= " " then
just_got_room_name = false
EnableTrigger ("got_description_line", false)
current_description = nil
current_exits = nil
room_name = nil
return
end -- if
end -- if
just_got_room_name = false
-- add to the current description
if Trim (line) ~= "" then
table.insert (current_description, line)
end -- if
end -- process_description_line
-- -----------------------------------------------------------------
-- process_exits_line : Here on [Exits: north east south west] or similar
-- -----------------------------------------------------------------
function process_exits_line (name, line, wildcards)
current_exits = { }
for w in string.gmatch (line, "%a+") do
dir = valid_direction [w]
if dir then
current_exits [dir] = 0
end -- if
end -- for
if debugging then
ColourNote ("yellow", "", "Exits: " .. line)
ColourNote ("yellow", "", #current_exits .. " changed exits")
end -- if
end_of_description ()
end -- process_exits_line
-- -----------------------------------------------------------------
-- try to detect when we send a movement command
-- -----------------------------------------------------------------
function OnPluginSent (sText)
last_direction_moved = valid_direction [sText]
end -- OnPluginSent
-- -----------------------------------------------------------------
-- OnPluginSaveState - save rooms info
-- -----------------------------------------------------------------
function OnPluginSaveState ()
-- just save the relevant stuff
wanted_keys = { "name", "area", "exits", "description" }
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 - find stuff
-- -----------------------------------------------------------------
function map_find (name, line, wildcards)
local found_rooms = {}
local count = 0
local wanted = wildcards [1]:lower ()
-- find matching rooms
for k, v in pairs (rooms) do
if string.find (v.description:lower (), wanted, 1, true)
or string.find (v.name:lower (), wanted, 1, true) then
found_rooms [k] = true
count = count + 1
end -- if
end -- finding room
-- see if nearby
mapper.find (
function (uid)
local room = found_rooms [uid]
if room then
found_rooms [uid] = nil
end -- if
return room, next (found_rooms) == nil
end, -- function
show_vnums, -- show vnum?
count, -- how many to expect
false -- don't auto-walk
)
end -- map_find
-- -----------------------------------------------------------------
-- cannot_walk - we tried to walk but failed
-- -----------------------------------------------------------------
function cannot_walk (name, line, wildcards)
mapper.cancel_speedwalk ()
current_description = nil
current_exits = nil
room_name = nil
just_got_room_name = false
last_direction_moved = nil
if show_database_mods then
mapper.mapprint ("Attempt to walk cancelled.")
end -- if
end -- cannot_walk
-- -----------------------------------------------------------------
-- map_goto - go to a room
-- -----------------------------------------------------------------
function map_goto (name, line, wildcards)
local wanted = wildcards [1]:upper ()
if #wanted < 3 then
mapper.mapprint ("Specify at least 3 characters of room ID.")
return
end -- if
if current_room and string.find (current_room:upper (), "^" .. wanted) then
mapper.mapprint ("You are already in that room.")
return
end -- if
-- find desired room
mapper.find (
function (uid)
local found = string.find (uid:upper (), "^" .. wanted)
return found, -- wanted room?
found -- stop searching?
end, -- function
show_vnums, -- show vnum?
1, -- how many to expect
true -- just walk there
)
end -- map_goto
-- -----------------------------------------------------------------
-- map_where - where is a room
-- -----------------------------------------------------------------
function map_where (name, line, wildcards)
if not mapper.check_we_can_find () then
return
end -- if
local wanted = wildcards [1]:upper ()
if #wanted < 3 then
mapper.mapprint ("Specify at least 3 characters of room ID.")
return
end -- if
if current_room and string.find (current_room:upper (), "^" .. wanted) then
mapper.mapprint ("You are already in that room.")
return
end -- if
local paths = mapper.find_paths (current_room,
function (uid)
local found = string.find (uid:upper (), "^" .. wanted)
return found, -- wanted room?
found -- 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
-- -----------------------------------------------------------------
-- 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)
if cannot_move_messages [line] then
cannot_walk ()
end -- if
end -- check_for_cannot_go
]]>
</script>
</muclient>