This repository has been archived by the owner on Mar 14, 2021. It is now read-only.
forked from nickgammon/plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GMCP_Mapper.xml
2048 lines (1599 loc) · 52.3 KB
/
GMCP_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
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE muclient [
<!ENTITY show_vnums "true" >
<!ENTITY show_timing "false" >
<!ENTITY show_completed "false" >
<!ENTITY show_database_mods "true" >
<!ENTITY show_other_areas "true" >
<!ENTITY show_area_exits "true" >
<!ENTITY show_up_down "false" >
<!ENTITY speedwalk_prefix "" >
]>
<muclient>
<plugin
name="GMCP_Mapper"
author="Nick Gammon"
id="eed15e155069264149674479"
language="Lua"
purpose="Draws map for GMCP MUDs"
date_written="2010-03-04"
date_modified="2015-05-06"
requires="4.51"
version="1.7"
save_state="y"
>
<description trim="y">
<![CDATA[
AUTOMATIC MAPPER ... by Nick Gammon
The window can be dragged to a new location by dragging the room name.
Your current room is always in the center with a bolder border.
LH-click on a room to speed-walk to it. RH-click on a room for options.
LH-click on the "*" button on the bottom-left corner to configure it.
** WHY DOES THE MAP CHANGE? **
The mapper draws from your room outwards - that is, it draws your room's exits
first, then the rooms leading from those rooms, and so on.
Eventually it finds an overlap, and draws a short "stub" line to indicate there
is a room there which there isn't space to draw. If you get closer to that
room the stub will disappear and the room(s) in question will be drawn.
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
FINDING THINGS
mapper bookmarks --> show nearby rooms that you bookmarked
mapper find <text> --> full-text search (eg. shop OR baker)
mapper areas --> show path to nearby areas (zones)
mapper heal --> show nearby healers
mapper shop --> show nearby shops/banks etc.
mapper train --> show nearby trainers
mapper quest --> show nearby quest-givers
mapper where <room> --> show directions to a room
MOVING
mapper goto <room> --> walk to a room by its room number
mapper stop --> cancel any current speedwalk
mapper resume --> resume last speedwalk or hyperlinked speedwalk
]]>
</description>
</plugin>
<aliases>
<!-- 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>
<!-- finding aliases -->
<alias
match="^mapper find ([\w* %d/"]+)$"
enabled="y"
sequence="100"
script="map_find"
regexp="y"
>
</alias>
<alias
match="mapper areas"
enabled="y"
sequence="100"
script="map_areas"
>
</alias>
<alias
match="^mapper shops?$"
regexp="y"
enabled="y"
sequence="100"
script="map_shops"
>
</alias>
<alias
match="^mapper train\w*$"
regexp="y"
enabled="y"
sequence="100"
script="map_trainers"
>
</alias>
<alias
match="^mapper quest\w*$"
regexp="y"
enabled="y"
sequence="100"
script="map_quests"
>
</alias>
<alias
match="^mapper heal\w*$"
regexp="y"
enabled="y"
sequence="100"
script="map_healers"
>
</alias>
<alias
match="mapper goto *"
enabled="y"
sequence="100"
script="map_goto"
>
</alias>
<alias
match="mapper where *"
enabled="y"
sequence="100"
script="map_where"
>
</alias>
<alias
match="^mapper book\w*$"
regexp="y"
enabled="y"
sequence="100"
script="map_bookmarks"
>
</alias>
<alias
match="mapper resume"
enabled="y"
sequence="100"
script="map_resume"
>
</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>
<!-- auto-swim -->
<trigger
enabled="y"
match="There's water ahead of you. You'll have to * to make it through."
sequence="100"
>
<send>%1</send>
</trigger>
<trigger
enabled="y"
match="You'll have to swim to make it through the water in that direction."
send_to="12"
sequence="100"
>
<send>
if last_direction_moved then
Send ("swim " .. last_direction_moved)
end -- if
</send>
</trigger>
<!-- auto-open -->
<trigger
enabled="y"
regexp="y"
match="^There is a door in the way"
send_to="12"
sequence="100"
>
<send>
if last_direction_moved then
Send ("open door " .. last_direction_moved)
end -- if
</send>
</trigger>
<!-- various messages that cancel speedwalks -->
<trigger
enabled="y"
match="Now now\, don\'t be so hasty\!$"
regexp="y"
script="mapper.cancel_speedwalk"
sequence="100"
>
</trigger>
<trigger
enabled="y"
match="^You cannot walk through"
regexp="y"
script="mapper.cancel_speedwalk"
sequence="100"
>
</trigger>
<trigger
enabled="y"
match="As you stroll in, you feel your feet slipping on something slimy."
script="mapper.cancel_speedwalk"
sequence="100"
>
<send>stand</send>
</trigger>
<trigger
enabled="y"
match="The door is locked."
script="mapper.cancel_speedwalk"
sequence="100"
>
</trigger>
<trigger
enabled="y"
match="You are regaining balance and are unable to move."
script="mapper.cancel_speedwalk"
sequence="100"
>
</trigger>
<trigger
enabled="y"
match="You are surrounded by a pocket of air and so must move normally through water."
script="mapper.cancel_speedwalk"
sequence="100"
>
</trigger>
<trigger
enabled="y"
match="You fumble about drunkenly."
script="mapper.cancel_speedwalk"
sequence="100"
>
</trigger>
<trigger
enabled="y"
match="You are asleep and can do nothing. WAKE will attempt to wake you."
script="mapper.cancel_speedwalk"
sequence="100"
>
</trigger>
<trigger
enabled="y"
match="You must be standing first."
script="mapper.cancel_speedwalk"
sequence="100"
>
</trigger>
<trigger
enabled="y"
match="You need to use a boat, fly, or swim underwater to go there."
script="mapper.cancel_speedwalk"
sequence="100"
>
</trigger>
<trigger
enabled="y"
match="You can't * while sitting."
script="mapper.cancel_speedwalk"
sequence="100"
>
</trigger>
<trigger
enabled="y"
regexp="y"
match="^You dream about "
script="mapper.cancel_speedwalk"
sequence="100"
>
</trigger>
<trigger
enabled="y"
match="Alas, you cannot go that way."
script="mapper.cancel_speedwalk"
sequence="100"
>
</trigger>
</triggers>
<!-- Plugin help -->
<aliases>
<alias
script="OnHelp"
match="mapper help"
enabled="y"
>
</alias>
</aliases>
<!-- Script -->
<script>
local show_vnums = &show_vnums;
local show_timing = &show_timing;
local show_completed = &show_completed;
local show_database_mods = &show_database_mods;
local show_other_areas = &show_other_areas;
local show_up_down = &show_up_down;
local show_area_exits = &show_area_exits;
local speedwalk_prefix = "&speedwalk_prefix;"
<![CDATA[
require "serialize"
require "checkplugin"
require "json"
mapper = require "mapper"
default_config = {
-- assorted colours
BACKGROUND_COLOUR = { name = "Background", colour = ColourNameToRGB "lightseagreen", },
ROOM_COLOUR = { name = "Room", colour = ColourNameToRGB "cyan", },
EXIT_COLOUR = { name = "Exit", colour = ColourNameToRGB "darkgreen", },
EXIT_COLOUR_UP_DOWN = { name = "Exit up/down", colour = ColourNameToRGB "darkmagenta", },
EXIT_COLOUR_IN_OUT = { name = "Exit in/out", colour = ColourNameToRGB "#3775E8", },
OUR_ROOM_COLOUR = { name = "Our room", colour = ColourNameToRGB "black", },
UNKNOWN_ROOM_COLOUR = { name = "Unknown room", colour = ColourNameToRGB "#00CACA", },
DIFFERENT_AREA_COLOUR = { name = "Another area", colour = ColourNameToRGB "#009393", },
SHOP_FILL_COLOUR = { name = "Shop", colour = ColourNameToRGB "darkolivegreen", },
POSTOFFICE_FILL_COLOUR = { name = "Post Office", colour = ColourNameToRGB "yellowgreen", },
BANK_FILL_COLOUR = { name = "Bank", colour = ColourNameToRGB "gold", },
NEWSROOM_FILL_COLOUR = { name = "Newsroom", colour = ColourNameToRGB "lightblue", },
MAPPER_NOTE_COLOUR = { name = "Messages", colour = ColourNameToRGB "lightgreen" },
ROOM_NAME_TEXT = { name = "Room name text", colour = ColourNameToRGB "#BEF3F1", },
ROOM_NAME_FILL = { name = "Room name fill", colour = ColourNameToRGB "#105653", },
ROOM_NAME_BORDER = { name = "Room name box", colour = ColourNameToRGB "black", },
AREA_NAME_TEXT = { name = "Area name text", colour = ColourNameToRGB "#BEF3F1",},
AREA_NAME_FILL = { name = "Area name fill", colour = ColourNameToRGB "#105653", },
AREA_NAME_BORDER = { name = "Area name box", colour = ColourNameToRGB "black", },
FONT = { name = get_preferred_font {"Dina", "Lucida Console", "Fixedsys", "Courier", "Sylfaen",} ,
size = 8
} ,
-- size of map window
WINDOW = { width = 400, height = 400 },
-- how far from where we are standing to draw (rooms)
SCAN = { depth = 30 },
-- speedwalk delay
DELAY = { time = 0.3 },
-- how many seconds to show "recent visit" lines (default 3 minutes)
LAST_VISIT_TIME = { time = 60 * 3 },
}
local rooms = {}
local areas = {}
local environments = {}
local user_terrain_colour = {}
room_not_in_database = {}
room_in_database = {}
function dbcheck (code)
if code ~= sqlite3.OK and -- no error
code ~= sqlite3.ROW and -- completed OK with another row of data
code ~= sqlite3.DONE then -- completed OK, no more rows
local err = db:errmsg () -- the rollback will change the error message
db:exec ("ROLLBACK") -- rollback any transaction to unlock the database
error (err, 2) -- show error in caller's context
end -- if
end -- dbcheck
function fixsql (s)
if s then
return "'" .. (string.gsub (s, "'", "''")) .. "'" -- replace single quotes with two lots of single quotes
else
return "NULL"
end -- if
end -- fixsql
function fixbool (b)
if b then
return 1
else
return 0
end -- if
end -- fixbool
function save_room_to_database (uid, title)
assert (uid, "No UID supplied to save_room_to_database")
dbcheck (db:execute (string.format (
"INSERT INTO rooms (uid, name, area, date_added) VALUES (%s, %s, '0', DATETIME('NOW'));",
fixsql (uid),
fixsql (title)
)))
dbcheck (db:execute (string.format ([[
INSERT INTO rooms_lookup (uid, name) VALUES (%s, %s);
]], fixsql (uid),
fixsql (title)
)))
room_not_in_database [uid] = false
if show_database_mods then
mapper.mapprint ("Added room", uid, "to database. Name:", title)
end -- if
end -- function save_room_to_database
function save_exits_to_database (uid, exits)
local room = rooms [uid]
db:exec ("BEGIN TRANSACTION;")
for dir in string.gmatch (exits, "[^,]+") do
-- fix up in and out
dir = ({ ['i'] = "in", o = "out", }) [dir] or dir
dbcheck (db:execute (string.format ([[
INSERT INTO exits (dir, fromuid, touid, date_added)
VALUES (%s, %s, %s, DATETIME('NOW'));
]], fixsql (dir), -- direction (eg. "n")
fixsql (uid), -- from current room
fixsql (0) -- destination room (not known)
)))
if show_database_mods then
mapper.mapprint ("Added exit", dir, "from room", uid, "to database.")
end -- if
room.exits [dir] = "0"
end -- for each exit
db:exec ("COMMIT;")
end -- function save_room_to_database
function save_full_exits_to_database (uid, exits)
local room = rooms [uid]
db:exec ("BEGIN TRANSACTION;")
for exit in string.gmatch (exits, "[^,]+") do
dir, touid = string.match (exit, "^(%a+)%((%d+)%)$")
touid = tonumber (touid)
if dir then
-- fix up in and out
dir = ({ ['i'] = "in", o = "out", }) [dir] or dir
dbcheck (db:execute (string.format ([[
INSERT INTO exits (dir, fromuid, touid, date_added)
VALUES (%s, %s, %s, DATETIME('NOW'));
]], fixsql (dir), -- direction (eg. "n")
fixsql (uid), -- from current room
fixsql (touid) -- destination room
)))
if show_database_mods then
mapper.mapprint ("Added exit", dir, "from room", uid, "to room", touid, "to database.")
end -- if
room.exits [dir] = touid
else
mapper.maperror ("Cannot make sense of:", exit)
end -- if can decode
end -- for each exit
db:exec ("COMMIT;")
end -- function save_full_exits_to_database
function fix_up_exit ()
local room = rooms [from_room]
dbcheck (db:execute (string.format ([[
UPDATE exits SET touid = %s WHERE fromuid = %s AND dir = %s;
]],
fixsql (current_room), -- destination room
fixsql (from_room), -- from previous room
fixsql (last_direction_moved) -- direction (eg. "n")
)))
if show_database_mods then
mapper.mapprint ("Fixed exit", last_direction_moved, "from room", from_room, "to be to", current_room)
end -- if
room.exits [last_direction_moved] = current_room
last_direction_moved = nil
from_room = nil
end -- fix_up_exit
function save_environment_to_database (uid, s)
local room = rooms [uid]
dbcheck (db:execute (string.format ([[
UPDATE rooms SET terrain = %s WHERE uid = %s;
]],
fixsql (s), -- environment
fixsql (uid) -- room
)))
room.terrain = s
if show_database_mods then
mapper.mapprint ("Fixed room", uid, "to have environment:", s)
end -- if
end -- save_environment_to_database
function save_info_to_database (uid, s)
local room = rooms [uid]
dbcheck (db:execute (string.format ([[
UPDATE rooms SET info = %s WHERE uid = %s;
]],
fixsql (s), -- info
fixsql (uid) -- room
)))
room.info = s
if show_database_mods then
mapper.mapprint ("Fixed room", uid, "to have info:", s)
end -- if
end -- save_info_to_database
function save_coordinates_to_database (uid, s)
local room = rooms [uid]
local area, x, y, z = string.match (s, "^(.-),([%d-]+),([%d-]+),([%d-]+)")
if x then
dbcheck (db:execute (string.format ([[
UPDATE rooms SET x = %i, y = %i, z = %i, area = %s WHERE uid = %s;
]],
x, y, z, fixsql (area), -- coordinates, area
fixsql (uid) -- room
)))
room.x = x
room.y = y
room.z = z
room.area = area
if show_database_mods then
mapper.mapprint ("Fixed room", uid, "to have coordinates:", x, y, z, "and area", area)
end -- if
else
mapper.maperror ("Cannot make sense of coordinates:", s)
end -- if
end -- save_coordinates_to_database
function load_room_from_database (uid)
local room
uid = tonumber (uid)
assert (uid, "No UID supplied to load_room_from_database")
-- if not in database, don't look again
if room_not_in_database [uid] then
return nil
end -- no point looking
for row in db:nrows(string.format ("SELECT * FROM rooms WHERE uid = %s", fixsql (uid))) do
room = {
name = row.name,
area = row.area,
building = row.building,
terrain = row.terrain,
info = row.info,
notes = row.notes,
x = row.x,
y = row.y,
z = row.z,
exits = {} }
for exitrow in db:nrows(string.format ("SELECT * FROM exits WHERE fromuid = %s", fixsql (uid))) do
room.exits [exitrow.dir] = tonumber (exitrow.touid)
end -- for each exit
end -- finding room
if room then
rooms [uid] = room
for row in db_bm:nrows(string.format ("SELECT * FROM bookmarks WHERE uid = %s", fixsql (uid))) do
rooms [uid].notes = row.notes
end -- finding room
return room
end -- if found
room_not_in_database [uid] = true
return nil
end -- load_room_from_database
function create_tables ()
-- create rooms table
dbcheck (db:execute[[
PRAGMA foreign_keys = ON;
PRAGMA journal_mode = WAL;
CREATE TABLE IF NOT EXISTS areas (
areaid INTEGER PRIMARY KEY AUTOINCREMENT,
uid TEXT NOT NULL, -- vnum or how the MUD identifies the area
name TEXT, -- name of area
date_added DATE, -- date added to database
UNIQUE (uid)
);
CREATE TABLE IF NOT EXISTS environments (
environmentid INTEGER PRIMARY KEY AUTOINCREMENT,
uid TEXT NOT NULL, -- code for the environment
name TEXT, -- name of environment
color INTEGER, -- ANSI colour code
date_added DATE, -- date added to database
UNIQUE (uid)
);
CREATE INDEX IF NOT EXISTS name_index ON environments (name);
CREATE TABLE IF NOT EXISTS rooms (
roomid INTEGER PRIMARY KEY AUTOINCREMENT,
uid TEXT NOT NULL, -- vnum or how the MUD identifies the room
name TEXT, -- name of room
area TEXT, -- which area
building TEXT, -- which building it is in
terrain TEXT, -- eg. road OR water
info TEXT, -- eg. shop,postoffice
notes TEXT, -- player notes
x INTEGER,
y INTEGER,
z INTEGER,
date_added DATE, -- date added to database
UNIQUE (uid)
);
CREATE INDEX IF NOT EXISTS info_index ON rooms (info);
CREATE INDEX IF NOT EXISTS terrain_index ON rooms (terrain);
CREATE INDEX IF NOT EXISTS area_index ON rooms (area);
CREATE TABLE IF NOT EXISTS exits (
exitid INTEGER PRIMARY KEY AUTOINCREMENT,
dir TEXT NOT NULL, -- direction, eg. "n", "s"
fromuid STRING NOT NULL, -- exit from which room (in rooms table)
touid STRING NOT NULL, -- exit to which room (in rooms table)
date_added DATE -- date added to database
);
CREATE INDEX IF NOT EXISTS fromuid_index ON exits (fromuid);
CREATE INDEX IF NOT EXISTS touid_index ON exits (touid);
]])
-- check if rooms_lookup table exists
local table_exists
for a in db:nrows "SELECT * FROM sqlite_master WHERE name = 'rooms_lookup' AND type = 'table'" do
table_exists = true
end -- for
if not table_exists then
dbcheck (db:execute "CREATE VIRTUAL TABLE rooms_lookup USING FTS3(uid, name);")
-- in case we only deleted the rooms_lookup table to save space in the download
dbcheck (db:execute "INSERT INTO rooms_lookup (uid, name) SELECT uid, name FROM rooms;")
end -- if
-- create bookmarks and terrain colours table in separate database
dbcheck (db_bm:execute[[
PRAGMA foreign_keys = ON;
CREATE TABLE IF NOT EXISTS bookmarks (
id INTEGER PRIMARY KEY AUTOINCREMENT,
uid TEXT NOT NULL, -- vnum of room
notes TEXT, -- user notes
date_added DATE, -- date added to database
UNIQUE (uid)
);
CREATE TABLE IF NOT EXISTS terrain (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL, -- terrain name
color INTEGER, -- RGB code
date_added DATE, -- date added to database
UNIQUE (name)
);
]])
end -- function create_tables
function get_room (uid)
-- check we got room at all
if not uid then
-- return nil
end -- if
uid = tonumber (uid)
-- look it up
local ourroom = rooms [uid]
-- not cached - see if in database
if not ourroom then
ourroom = load_room_from_database (uid)
rooms [uid] = ourroom -- cache for later
end -- not in cache
if not ourroom then
return nil
end -- if
local room = copytable.deep (ourroom)
room.area = areas [room.area] or string.format ("%s", room.area or "<unknown>")
if uid == current_room then
current_area = room.area
end -- if
-- build hover message
local environmentname = room.terrain
if tonumber (environmentname) then
environmentname = environments [tonumber (environmentname)]
end -- convert to name
local terrain = ""
if environmentname then
terrain = "\nTerrain: " .. capitalize (environmentname)
end -- if terrain known
local info = ""
if room.info then
info = "\nInfo: " .. capitalize (room.info)
end -- if info known
local notes = ""
if room.notes then
notes = "\nBookmark: " .. room.notes
end -- if notes
local texits = {}
for dir in pairs (room.exits) do
table.insert (texits, dir)
end -- for
table.sort (texits)
local areaname = room.area or "Unknown"
if tonumber (areaname) then
areaname = areas [tonumber (areaname)]
end -- convert to name
room.hovermessage = string.format (
"%s\tExits: %s\nRoom: %s\nArea: %s%s%s%s",
room.name,
table.concat (texits, ", "),
uid,
areaname or "Unknown",
terrain,
info,
notes
-- depth,
-- table.concat (path, ",")
)
room.bordercolour = config.ROOM_COLOUR.colour
room.borderpen = 0 -- solid
room.borderpenwidth = 1
room.fillcolour = 0xff0000
room.fillbrush = 1 -- no fill
-- special room fill colours
if room.info then
if string.match (room.info, "shop") then
room.fillcolour = config.SHOP_FILL_COLOUR.colour
room.fillbrush = 8
elseif string.match (room.info, "postoffice") then
room.fillcolour = config.POSTOFFICE_FILL_COLOUR.colour
room.fillbrush = 8
elseif string.match (room.info, "bank") then
room.fillcolour = config.BANK_FILL_COLOUR.colour
room.fillbrush = 8
elseif string.match (room.info, "newsroom") then
room.fillcolour = config.NEWSROOM_FILL_COLOUR.colour
room.fillbrush = 8
end -- if
else
-- use terrain colour
if environmentname then
if user_terrain_colour [environmentname] then
room.fillcolour = user_terrain_colour [environmentname]
room.fillbrush = 0 -- solid
elseif terrain_colours [environmentname] then
room.fillcolour = colour_lookup [terrain_colours [environmentname]]
room.fillbrush = 0 -- solid
end
end -- if environmentname
end -- if
if uid == current_room then
room.bordercolour = config.OUR_ROOM_COLOUR.colour
room.borderpenwidth = 2
elseif room.area ~= current_area then
room.bordercolour = config.DIFFERENT_AREA_COLOUR.colour
end -- not in this area
-- make exits strings
for k, v in pairs (room.exits) do
room.exits [k] = tostring (v)
end -- for
return room
end -- get_room
function room_edit_bookmark (room, uid)
local notes, found
for row in db_bm:nrows(string.format ("SELECT * FROM bookmarks WHERE uid = %s", fixsql (uid))) do
notes = row.notes
found = true
end -- finding room
if found then
newnotes = utils.inputbox ("Modify room comment (clear it to delete from database)", room.name, notes)
else
newnotes = utils.inputbox ("Enter room comment (creates a bookmark for this room)", room.name, notes)
end -- if
if not newnotes then
return
end -- if cancelled
if newnotes == "" then
if not found then
mapper.mapprint ("No comment entered, bookmark not saved.")
return
else
dbcheck (db_bm:execute (string.format (
"DELETE FROM bookmarks WHERE uid = %s;",
fixsql (uid)
)))
mapper.mapprint ("Bookmark for room", uid, "deleted. Was previously:", notes)
rooms [uid].notes = nil
return
end -- if
end -- if
if notes == newnotes then
return -- no change made
end -- if
if found then
dbcheck (db_bm:execute (string.format (
"UPDATE bookmarks SET notes = %s, date_added = DATETIME('NOW') WHERE uid = %s;",
fixsql (newnotes),
fixsql (uid)
)))
mapper.mapprint ("Bookmark for room", uid, "changed to:", newnotes)
else
dbcheck (db_bm:execute (string.format (
"INSERT INTO bookmarks (uid, notes, date_added) VALUES (%s, %s, DATETIME('NOW'));",
fixsql (uid),
fixsql (newnotes)
)))
mapper.mapprint ("Bookmark added to room", uid, ":", newnotes)
end -- if
rooms [uid].notes = newnotes
end -- room_edit_bookmark
function room_edit_terrain_colour (room, uid)
if not room.terrain then
utils.msgbox ("This room does not have a terrain type", "Unknown terrain!", "ok", "!", 1)