-
Notifications
You must be signed in to change notification settings - Fork 3
/
LucidNightmareNavigator.lua
1437 lines (1180 loc) · 39.5 KB
/
LucidNightmareNavigator.lua
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
-- Lucid Nightmare Navigator
-- by Wonderpants of Thrall
-- loosely based on LNH by Vildiesel EU - Well of Eternity
local addonName, addon = ...
local ng
local player_icon = "interface\\worldmap\\WorldMapArrow"
local containerW, containerH = 50000, 50000
local buttonW, buttonH = 18, 18
-- This 1-indexing is madness
--
--
-- THIS IS LUA!!!!!!!!!
--
local north = 1
local east = 2
local south = 3
local west = 4
local direction_strings = {"North","East","South","West"}
local color_strings = {"Yellow","Blue","Red","Green","Purple"}
local EHHPOIStrings = {
"#Y","#B","#R","#G","#P",
"$Y","$B","$R","$G","$P"
}
local yellow = 1
local blue = 2
local red = 3
local green = 4
local purple = 5
local pool = {}
local map = {}
local rooms = {}
local current_room
local mf, scrollframe, container, playerframe = nil
local last_dir, last_room_number
local wall_buttons = {}
local guidance_buttons = {}
-- Quality Discount Function Pointers:
local navigateKludge
local resetVisitedKludge
-- Help navigate to unexplored territory
local navtarget = 11
local poirooms = {}
--local doors = {{{-1378, 680},{-1300,710}}, -- north
-- {{-1440, 600},{-1410,660}}, -- east
-- {{-1520, 680},{-1460,710}}, -- south
-- {{-1460, 740},{-1410,800}}} -- west
local function getOppositeDir(dir)
if dir == north then return south
elseif dir == east then return west
elseif dir == south then return north
else return east end
end
local function detectDir(x, y)
if y > -1410 then
return north
elseif y < -1440 then
return south
elseif x < 660 then
return east
elseif x > 720 then
return west
end
end
local function centerCam(x, y)
scrollframe:SetHorizontalScroll(x - 250 + buttonW / 2)
scrollframe:SetVerticalScroll(y - 250 + buttonH / 2)
end
local function resetVisited()
for k,v in pairs(rooms) do
v.visited = false
end
end
local function getUnusedButton()
if #pool > 0 then
return tremove(pool, 1)
else
local btn = ng:New(addonName, "Frame", "room" .. tostring(#rooms), container)
btn:SetSize(buttonW, buttonH)
btn.text = btn:CreateFontString()
btn.text:SetFont("Fonts\\FRIZQT__.TTF", 8)
btn.text:SetAllPoints()
btn.text:SetText("")
btn.links = {}
dir = 1
for dir=1,4 do
btn.links[dir] = ng:New(addonName, "Frame", "room" .. tostring(#rooms) .. "w" .. tostring(dir), btn)
btn.links[dir]:SetBackdropColor(0.7, 0.7, 0.7, 1)
btn.links[dir]:SetBackdropBorderColor(0.7, 0.7, 0.7, 1)
btn.links[dir]:SetSize(3, 3)
btn.links[dir]:Show()
end
btn.links[north]:SetPoint("TOP", btn, "TOP", 0, 3)
btn.links[south]:SetPoint("BOTTOM", btn, "BOTTOM", 0, -3)
btn.links[east]:SetPoint("RIGHT", btn, "RIGHT", 3, 0)
btn.links[west]:SetPoint("LEFT", btn, "LEFT", -3, 0)
return btn
end
end
local function createButton(r)
local btn = getUnusedButton()
btn:SetPoint("TOPLEFT", container, "TOPLEFT", r.x, -r.y)
btn:SetBackdropColor(1, 1, 1, 1)
btn:SetBackdropBorderColor(0, 0, 0, 0)
btn:Show()
r.button = btn
end
local function resetColor(r, c, t)
for k,v in pairs(rooms) do
if v ~= r and v.POI_c == c and v.POI_t == t then
if t == "rune" then
v.button:SetBackdropColor(1, 1, 1, 1)
else
v.button:SetBackdropBorderColor(0, 0, 0, 0)
end
v.POI_c = nil
end
end
end
local function setRoomNumber(r)
--last_room_number = last_room_number + 1
if r.index < 100 then
r.button.text:SetTextHeight(10)
else
r.button.text:SetTextHeight(8)
end
r.button.text:SetText("|cff000000"..r.index.."|r")
--r.number = last_room_number
end
local function recolorRoom(r)
--resetColor(r, r.POI_c, r.POI_t)
local func = r.POI_t == "rune" and r.button.SetBackdropColor or r.button.SetBackdropBorderColor
if r.POI_c == yellow then
func(r.button, 1, 1, 0, 1)
elseif r.POI_c == blue then
func(r.button, 0, 0.6, 1, 1)
elseif r.POI_c == green then
func(r.button, 0, 1, 0, 1)
elseif r.POI_c == purple then
func(r.button, 1, 0, 1, 1)
elseif r.POI_c == red then
func(r.button, 1, 0, 0, 1)
else -- clear
r.button:SetBackdropColor(1, 1, 1, 1)
r.button:SetBackdropBorderColor(0, 0, 0, 0)
end
for dir=1,4 do
if r.walls[dir] then
r.button.links[dir]:Hide()
else
r.button.links[dir]:Show()
end
end
end
local function newRoom()
local r = {}
r.neighbors = {}
r.walls = {false, false, false, false}
--print("Making a new room")
--print ("r.walls[2]: ", r.walls[2])
r.visited = false --used for graph traversals
r.index = #rooms+1
r.poi_index=0
rooms[r.index] = r
return r
end
local function getRotation(dir)
if dir == west then
return 90
elseif dir == south then
return 180
elseif dir == east then
return 270
elseif dir == north then
return 0
end
end
local function updateWallButtonText()
for i=1,4 do
if (current_room == nil) then
wall_buttons[i]:SetText("No "..direction_strings[i].." Wall")
elseif (current_room.walls[i]) then
wall_buttons[i]:SetText("Wall to the "..direction_strings[i])
else
wall_buttons[i]:SetText("No "..direction_strings[i].." Wall")
end
end
end
local function setCurrentRoom(r)
current_room = r
if (r == nil) then
print("setCurrentRoom: Current room is nil!")
return
end
if (r.x == nil) then
print("setCurrentRoom: Current r.x is nil!",r.index)
r.x = 0
end
if (r.y == nil) then
print("setCurrentRoom: Current r.y is nil!",r.index)
r.y = 0
end
centerCam(r.x, r.y)
playerframe:SetParent(r.button)
playerframe:ClearAllPoints()
playerframe:SetAllPoints()
playerframe.tex:SetRotation(math.rad(getRotation(last_dir or north)))
updateWallButtonText()
end
local function setRoomXY(lastRoom, direction, newRoom)
local dir = direction
local r = newRoom
local dx, dy = 0, 0
if dir == north then
dy = -buttonH - 5
elseif dir == east then
dx = buttonW + 5
elseif dir == south then
dy = buttonH + 5
elseif dir == west then
dx = -buttonW - 5
end
local offsetX, offsetY = dx, dy
while true do
local found
-- Keep from drawing rooms on top of each other on the map
for k,v in pairs(rooms) do
if v.x == lastRoom.x + offsetX and v.y == lastRoom.y + offsetY then
offsetX = offsetX + dx
offsetY = offsetY + dy
found = true
end
end
if not found then
break
end
end
r.x = lastRoom.x + offsetX
r.y = lastRoom.y + offsetY
end
local function addRoom(dir)
local r = newRoom()
current_room.neighbors[dir] = r
r.neighbors[getOppositeDir(dir)] = current_room
setRoomXY(current_room, dir, r)
createButton(r)
setRoomNumber(r)
return r
end
local function EraseRooms()
for k,v in pairs(rooms) do
v.button:Hide()
pool[#pool + 1] = v.button
end
wipe(rooms)
wipe(map)
wipe(poirooms)
last_dir = north
end
local function ResetMap()
EraseRooms()
map[1] = newRoom()
map[1].x = containerW / 2
map[1].y = containerH / 2
last_room_number = 0
createButton(map[1])
setRoomNumber(map[1])
setCurrentRoom(map[1])
end
local ly, lx = 0, 0
local function update()
local y, x = UnitPosition("player")
if math.abs(x - lx) > 70 or math.abs(y - ly) > 70 then
local dir = detectDir(lx, ly)
if dir then
last_dir = dir
--print("-> Movement detected! dir = ", dir, ", Neighbors: ", current_room.neighbors[dir])
setCurrentRoom(current_room.neighbors[dir] or addRoom(dir))
navigateKludge()
end
end
lx = x
ly = y
end
local default_theme = {
l0_color = "000000ff",
l0_border = "191919FF",
l0_texture = "Interface\\Buttons\\GreyscaleRamp64",
l3_color = "999999FF",
l3_border = "000000FF",
l3_texture = "Interface\\Buttons\\WHITE8X8",
l3_texture = "spells\\ICETEXTURE_MAGE",
thumb = "19B219FF",
highlight = "00FFffFF",
-- fonts
f_label_name = "Fonts\\FRIZQT__.ttf",
f_label_h = 11,
f_label_flags = "",
f_label_color = "FFFFFFFF",
f_button_name = "Fonts\\FRIZQT__.ttf",
f_button_h = 11,
f_button_flags = "",
f_button_color = "FFFFFFFF",
}
local function luaSucksQueueInit(crappyLuaQueue, minIndex, maxIndex)
minIndex = 1
maxIndex = 0
return minIndex, maxIndex
end
local function luaSucksQueuePush(crappyLuaQueue, minIndex, maxIndex, newVal)
crappyLuaQueue[maxIndex+1] = newVal
return minIndex, maxIndex+1
end
local function luaSucksQueuePop(crappyLuaQueue, minIndex, maxIndex)
if (minIndex > maxIndex) then
return minIndex, maxIndex, nil
end
local newMin = minIndex + 1
return newMin, maxIndex, crappyLuaQueue[minIndex]
end
--Returns true if empty
local function luaSucksQueueEmpty(crappyLuaQueue, minIndex, maxIndex)
if (minIndex > maxIndex) then
return true
end
return false
end
local function deDuplicateMap(orig, dupe)
-- User has reached a second copy of the original room, spider out from this copy of the room and the original and erase duplicate rooms
if (orig == dupe) then
return
end
local roomQueue = {}
local rq1 = 1
local rq2 = 1
local dupeQueue = {}
local dq1 = 1
local dq2 = 1
rq1, rq2 = luaSucksQueueInit(roomQueue, rq1, rq2)
dq1, dq2 = luaSucksQueueInit(dupeQueue, dq1, dq2)
resetVisitedKludge()
-- PERFORMANCE WARNING!!! This Lua table is actually
-- some sort of bloated associative array, NOT a normal queue
rq1, rq2 = luaSucksQueuePush(roomQueue, rq1, rq2, orig)
dq1, dq2 = luaSucksQueuePush(dupeQueue, dq1, dq2, dupe)
while (not luaSucksQueueEmpty(roomQueue, rq1, rq2)) do
local cur
local dcur
rq1, rq2, cur = luaSucksQueuePop(roomQueue, rq1, rq2)
dq1, dq2, dcur = luaSucksQueuePop(dupeQueue, dq1, dq2)
if (not cur.visited) then
cur.visited = true
for i=1,4 do
if (dcur ~= nil and cur ~= nil) then
if (cur.walls[i] ~= dcur.walls[i]) then
--print("AH CRAP, room " .. cur.index .. " might be a trap, since it doesn't match " .. dcur.index);
end
end
end
for i=1,4 do
local n = cur.neighbors[i]
local n2 = nil
if (dcur ~= nil) then
n2 = dcur.neighbors[i]
end
if (n == nil) then
if (n2 ~= nil) then
--print ("Moving "..n2.index..", attaching to "..cur.index.." instead of "..dcur.index)
cur.neighbors[i] = n2
n2.neighbors[getOppositeDir(i)] = cur
rq1, rq2 = luaSucksQueuePush(roomQueue, rq1, rq2, n2)
dq1, dq2 = luaSucksQueuePush(dupeQueue, dq1, dq2, nil)
end
else
rq1, rq2 = luaSucksQueuePush(roomQueue, rq1, rq2, n)
dq1, dq2 = luaSucksQueuePush(dupeQueue, dq1, dq2, n2)
end
end
if (dcur ~= nil) then
dcur.dupedTo = cur
-- Wipe out all references to the duplicate room, and recycle
-- its button:
if (dcur.poi_index ~= 0) then
cur.poi_index = dcur.poi_index
poirooms[cur.poi_index] = cur
print("poi index",cur.poi_index," was ",dcur.index," now ", cur.index)
end
wipe(dcur.neighbors)
wipe(dcur.walls)
rooms[dcur.index] = nil
if (dcur.button ~= nil) then
dcur.button:Hide()
pool[#pool + 1] = dcur.button
end
end
end
end
--print ("Done de-duplicating map!")
if (current_room == dupe) then
current_room = orig
setCurrentRoom(current_room)
end
end
local poi_warned = 0
local function setPOIClick(self)
if (self.poi_index == nil) then
-- Clear room
if (poirooms[current_room.poi_index] ~= nil) then
poirooms[current_room.poi_index] = nil
end
current_room.POI_t = self.t
current_room.POI_c = self.c
recolorRoom(current_room)
end
if (poirooms[self.poi_index] == current_room) then
return
end
--TODO: Warning popup before de-duplicating the map
if (poirooms[self.poi_index] ~= nil and poi_warned ~= self.poi_index) then
print ("WOAH WOAH WOAH, this point of interest was already defined as room "..poirooms[self.poi_index].index.."! Click again to confirm a loop in the map and de-duplicate nodes")
poi_warned = self.poi_index
return
end
poi_warned = 0
if (poirooms[self.poi_index] ~= nil) then
deDuplicateMap(poirooms[self.poi_index], current_room)
else
if (poirooms[current_room.poi_index] ~= nil) then
poirooms[current_room.poi_index] = nil
end
poirooms[self.poi_index] = current_room
current_room.poi_index = self.poi_index
current_room.POI_t = self.t
current_room.POI_c = self.c
recolorRoom(current_room)
end
end
local function updateNavButtonText()
for i=1,11 do
local btn = guidance_buttons[i]
local text = ""
if (i == 11) then
text = "Unexplored Territory"
elseif (i > 0 and i < 6) then
text = color_strings[i].." Rune"
elseif (i > 5 and i < 11) then
text = color_strings[i-5].." Orb"
end
if (i == navtarget) then
text = "["..text.."]"
end
btn:SetText(text)
end
end
eb = {}
local EHHPOINums = {}
for i=1,#EHHPOIStrings do
EHHPOINums[EHHPOIStrings[i]] = i
end
function ehhPOINum(ehhPOIStr)
local poiNum = EHHPOINums[ehhPOIStr]
if (poiNum == nil) then
print("Error parsing input, could not understand "..ehhPOIStr)
end
return poiNum
end
-- Woe upon any who dares to try and run this cursed code
-- function importFromEHH(t)
-- print("Loading this map:")
-- print(t)
-- map[1] = newRoom()
-- for x=1,#rooms do
-- if map[1] == rooms[x] then
-- print ("Found 'im, ", x)
-- end
-- if map[1].index == rooms[x].index then
-- print ("Found 'im!, ", x)
-- end
-- end
-- map[1].x = containerW / 2
-- map[1].y = containerH / 2
-- last_room_number = 0
-- -- createButton(map[1])
-- -- setRoomNumber(map[1])
-- -- setCurrentRoom(map[1])
-- -- recolorRoom(map[1])
-- local poiStr = string.sub(t,1,2)
-- local poiNum = ehhPOINum(poiStr)
-- map[1].poi_index = poiNum
-- poirooms[map[1].poi_index] = map[1]
-- local toBeDeduplicatedOrigs = {}
-- local toBeDeduplicatedDupes = {}
-- local cur = map[1]
-- for i=3,string.len(t) do
-- local c = string.sub(t,i, i)
-- if (c == "\n") then
-- cur = nil
-- elseif (c == "$" or c == "#") then
-- poiStr = string.sub(t,i,i+1)
-- poiNum = ehhPOINum(poiStr)
-- if (cur == nil) then
-- if (poirooms[poiNum] == nil) then
-- -- Create a new room, set it as this POI, will attach to the
-- -- rest of the map later
-- cur = newRoom()
-- poirooms[poiNum] = cur
-- cur.poi_index = poiNum
-- else
-- cur = poirooms[poiNum]
-- end
-- else
-- if (poirooms[poiNum] == nil) then
-- poirooms[poiNum] = cur
-- cur.poi_index = poiNum
-- else
-- local dupe = cur
-- local orig = poirooms[poiNum]
-- toBeDeduplicatedOrigs[#toBeDeduplicatedOrigs+1] = orig
-- toBeDeduplicatedDupes[#toBeDeduplicatedDupes+1] = dupe
-- end
-- end
-- elseif (c == "N") then
-- dir = 1
-- local r = newRoom()
-- cur.neighbors[dir] = r
-- r.neighbors[getOppositeDir(dir)] = cur
-- cur = r
-- elseif (c == "E") then
-- dir = 2
-- local r = newRoom()
-- cur.neighbors[dir] = r
-- r.neighbors[getOppositeDir(dir)] = cur
-- cur = r
-- elseif (c == "S") then
-- dir = 3
-- local r = newRoom()
-- cur.neighbors[dir] = r
-- r.neighbors[getOppositeDir(dir)] = cur
-- cur = r
-- elseif (c == "W") then
-- dir = 4
-- local r = newRoom()
-- cur.neighbors[dir] = r
-- r.neighbors[getOppositeDir(dir)] = cur
-- cur = r
-- end
-- end
-- for x=1,#rooms do
-- if map[1] == rooms[x] then
-- print ("2 Found 'im, ", x)
-- end
-- if map[1].index == rooms[x].index then
-- print ("2 Found 'im!, ", x)
-- end
-- end
-- for i=1,#toBeDeduplicatedOrigs do
-- local orig = toBeDeduplicatedOrigs[i]
-- local orig_loop = orig
-- local dupe = toBeDeduplicatedDupes[i]
-- local dupe_loop = dupe
-- while(orig.dupedTo ~= nil) do
-- orig = orig.dupedTo
-- if (orig == orig_loop) then
-- print("Found a loop")
-- break
-- end
-- end
-- while(dupe.dupedTo ~= nil) do
-- dupe = dupe.dupedTo
-- if (dupe == dupe_loop) then
-- print("Found a loop")
-- break
-- end
-- end
-- if (orig.dupedTo ~= nil and dupe.dupedTo ~= nil) then
-- deDuplicateMap(orig, dupe)
-- end
-- --dupe.dupedTo = orig
-- end
-- while(map[1].dupedTo ~= nil) do
-- print("map[1] was duped..")
-- map[1] = map[1].dupedTo
-- end
-- print("Built room graph, now creating a UI map..")
-- resetVisited()
-- for x=1,#rooms do
-- if map[1] == rooms[x] then
-- print ("3 Found 'im, ", x)
-- end
-- if map[1].index == rooms[x].index then
-- print ("3 Found 'im!, ", x)
-- end
-- end
-- -- Spider out over the map and give all the rooms UI buttons
-- local roomQueue = {}
-- local rq1 = 1
-- local rq2 = 1
-- rq1, rq2 = luaSucksQueueInit(roomQueue, rq1, rq2)
-- rq1, rq2 = luaSucksQueuePush(roomQueue, rq1, rq2, map[1])
-- while (not luaSucksQueueEmpty(roomQueue, rq1, rq2)) do
-- rq1, rq2, cur = luaSucksQueuePop(roomQueue, rq1, rq2)
-- --print(rq1,rq2,cur.index,cur.visited,cur.neighbors[1] == nil,cur.neighbors[2] == nil,cur.neighbors[3] == nil,cur.neighbors[4] == nil)
-- if (cur ~= nil) then
-- cur.visited = true
-- createButton(cur)
-- setRoomNumber(cur)
-- recolorRoom(cur)
-- for i=1,4 do
-- local n = cur.neighbors[i]
-- if (n ~= nil) then
-- if (n.visited == false) then
-- setRoomXY(cur, i, n)
-- rq1, rq2 = luaSucksQueuePush(roomQueue, rq1, rq2, n)
-- end
-- end
-- end
-- end
-- end
-- setCurrentRoom(map[1])
-- end
function importMap()
print("WARNING! You must load the map from the same room as you were when you saved the map")
EraseRooms()
local t = eb:GetText()
-- t = [[
-- #YE#BNNEES#R
-- ]]
print("Loading this map:")
print(t)
-- if (string.sub(t,1,1) == "$" or string.sub(t,1,1) == "#") then
-- print("Importing map from EndlessHallsHelper!")
-- return importFromEHH(t)
-- end
local l = string.len(t)
print("Length:",l)
local i = 1
while (i <= l) do
--Lua seems to strip newlines out of the string when I read
-- it, just end rooms with a "-" token to work around it
local l1,l2 = string.find(t,"-",i,true)
if (l2 == nil) then
l2 = l
end
local line = string.sub(t,i,l2-1)
i = l2
--print (line)
local substrings = {}
local j=1
local linelength = string.len(line)
while (j <= linelength) do
local t1,t2 = string.find(line,",",j,true)
if (t1 == nil) then
t2 = l+1
end
local token = string.sub(line,j,t2-1)
j = t2
substrings[#substrings+1] = token
j = j+1
end
last_room_number = #rooms
local room = {}
room.index = tonumber(substrings[1])
if (room.index ~= nil) then
room.poi_index = tonumber(substrings[2])
room.neighbor_indices = {}
for neighbor=1,4 do
room.neighbor_indices[neighbor] = tonumber(substrings[2+neighbor])
end
room.walls = {false, false, false, false}
for wall=1,4 do
room.walls[wall] = (substrings[6+wall]=="W")
end
room.visited=false
room.neighbors={}
rooms[room.index] = room
room.x = tonumber(substrings[11])
room.y = tonumber(substrings[12])
if (substrings[13]=="current") then
print ("Current room is ",room.index)
current_room = room
end
else
print("Ignoring line '"..line.."'")
end
i = i + 1
end
for k,v in pairs(rooms) do
for neighbor=1,4 do
local nIndex = v.neighbor_indices[neighbor]
if (v.neighbor_indices[neighbor] ~= nil) then
if (rooms[nIndex] == nil) then
print("Error, room ", v.index, " indicates it's neighbors with room ",nIndex,",which was not found")
else
v.neighbors[neighbor] = rooms[nIndex]
end
end
end
if (v.poi_index > 5) then
v.POI_c = v.poi_index - 5
v.POI_t = "orb"
poirooms[v.poi_index] = v
elseif (v.poi_index > 0) then
v.POI_c = v.poi_index
v.POI_t = "rune"
poirooms[v.poi_index] = v
end
createButton(v)
recolorRoom(v)
setRoomNumber(v)
if (v == current_room) then
setCurrentRoom(v)
end
end
end
local Exporting_To_EHH = false
local EHH_Directions = ""
function dumpMap()
local serialized = "index,poi,north_neighbor,east_neighbor,south_neighbor,west_neighbor,n_wall,e_wall,s_wall,w_wall,x,y,current,-\n"
local dirLetters = {"N","E","S","W"}
for k,v in pairs(rooms) do
serialized=serialized..v.index..","..v.poi_index
local neighborString = ""
local wallString = ""
local serializedNeighbors = ""
local serializedWalls = ""
for i=1,4 do
if (v.walls[i]) then
serializedWalls=serializedWalls..",W"
wallString = wallString..dirLetters[i]..":W,"
else
serializedWalls=serializedWalls..", "
wallString = wallString..dirLetters[i]..": ,"
end
if (v.neighbors[i] == nil) then
serializedNeighbors=serializedNeighbors..", "
neighborString = neighborString..dirLetters[i]..":X,"
else
serializedNeighbors=serializedNeighbors..","..v.neighbors[i].index
neighborString = neighborString..dirLetters[i]..":"..v.neighbors[i].index..","
end
end
serialized=serialized..serializedNeighbors..serializedWalls
serialized=serialized..","..v.x..","..v.y..","
local curString = ""
if (current_room == v) then
serialized=serialized.."current,"
curString = " (YOU ARE HERE) "
else
serialized=serialized..","
end
serialized=serialized.."-\n"
print("Room "..(k)..curString.." POI: ",v.poi_index," N:[",neighborString,"] W:[",wallString,"]")
end
eb:SetText(serialized)
end
local function outputGuidanceToEHH(directions, POIs, targetRoom, startingRoom)
local steps = (table.getn(directions)-1)
--print("Guiding from " .. tostring(startingRoom.poi_index) .. " to " .. tostring(targetRoom.poi_index))
local dirLetters = {"N","E","S","W"}
local navString = "" .. EHHPOIStrings[startingRoom.poi_index]
if (targetRoom.poi_index == 11) then
print("Error, EHH does not care about unexplored rooms")
return
end
--directions[1] is always "0" due to a lazy design decision
for i=2,#directions do
navString = navString..dirLetters[directions[i]]
if (POIs[i] ~= 0) then
navString = navString .. EHHPOIStrings[POIs[i]]
end
end
print(navString)
EHH_Directions = EHH_Directions .. navString .. "\n"
end
local function outputGuidance(directions)
local steps = (table.getn(directions)-1)
local navString = ""
if (navtarget == 11) then
if (steps ~= 1) then
print ("Hello, user! I have detected an unexplored room ",steps," steps from here!")
else
navString = navString.."Unexplored room: "
end
else
if (steps ~= 1) then
local destStr = ""
if (navtarget > 5) then
destStr = color_strings[navtarget - 5]
destStr = destStr.." Orb"
elseif (navtarget > 0) then
destStr = color_strings[navtarget]
destStr = destStr.." Rune"
end
print ("Hello, user! I have detected your destination ("..destStr..") ",steps," steps from here!")
end
end
--directions[1] is always "0" due to a lazy design decision
for i=2,4 do
if (directions[i] == nil) then
navString = navString.."You will have arrived at your destination!"
break
end
navString = navString.."Go "..direction_strings[directions[i]]..", then "
if (i == 4) then
navString = navString.."..."
end
end
print(navString)
end
local function navigateToUnexplored()
-- perform a depth-first traversal until you encounter an unexplored room
-- and then print out directions to it for the user
local roomstack = {}
local roomstacksize = 0
local directionsStack = {}
resetVisited()
-- PERFORMANCE WARNING!!! This Lua table is actually
-- some sort of bloated associative array, NOT a normal stack
table.insert(roomstack, current_room)
roomstacksize = roomstacksize + 1
-- Directions: 0 is the starting point,
-- after that it's an array of directions taken to get
-- to the current room
local tempDirections = {0}