-
Notifications
You must be signed in to change notification settings - Fork 8
/
mapmap.lic
865 lines (836 loc) · 30.4 KB
/
mapmap.lic
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
=begin
This make map good.
;mapmap help
tillmen@lichproject.org
=end
if $version.split('.').collect { |num| num.rjust(4, '0') }.join('.') < '0004.0002.0000'
echo 'This script requires Lich version 4.2 or higher.'
exit
end
# stay out of player's homes
neighborhoods = /^\[Liabo Circle|^\[Tiger Court|^\[Cothinar Gardens|^\[North Shore|^\[Golvern Street|^\[Rock Garden|^\[Riverbank|^\[Pebble Court|^\[Hedgerow|^\[Pig Puddle Lane|^\[Meadowlands|^\[Ravenswood|^\[Cobblestone Court|^\[Orc's Nest Road|^\[Tiger Court Lane|^\[Shanty Town|^\[Bay's Watch|^\[West Bank|^\[Dragonsclaw Arms|^\[Coastal Cliffs, Gnarled Trees|^\[Coastal Cliffs, Ledges|^\[Coastal Cliffs, Rocky Slope|^\[Marble Springs|^\[Curlew Brook|^\[Highpark|^\[Windmill Burrow|^\[Dabbings Mews|^\[Spitfire Alley|^\[Magical Burrow|^\[Pinefar Preserve|^\[Coastal Cliffs, (?:Waterfront|Fenvaok's Roost|Overhang)|^\[Carousel Court|^\[Port Valley|^\[Khan'Kel Bazaar|^\[Lough Ne'halin|^\[Cavernfast|^\[Noralgar Hollow|^\[Hummingbird Pond|^\[Boreas Meadows|^\[Boreas Hills|^\[Boreas Ridge|^\[Tyramia Hollow|^\[Glarstim Cavern|^\[Royal Court|^\[Ebondrift|^\[Cypress Walk|^\[Kwagmire Kourt|^\[Market Bend|^\[Behlayr/
# most of these rooms will not cause errors when using the map database, but will screw up the database if this script tries to map them automatically
#error_rooms = [ 6634, 5730, 7487, 7313, 2925, 1809, 1810, 1273, 14120, 14121, 14614, 14618, 3953, 3951, 3950, 3947, 3949, 3948, 3970, 3968, 3967, 3966, 3964, 3939, 3941, 3942, 3938, 3943, 3944, 3961, 3958, 3955, 14718, 4137, 4136, 10118, 5868, 13966, 13429, 13445, 13210, 2897, 2896, 2881, 3204, 15690, 9073, 3035, 2925, 2894, 2895, 2877, 2882, 2883, 2898, 2899, 2900, 16131, 16130, 16011, 11153, 11184, 11186, 11188, 11189, 11190, 4315, 16445, 16309, 5873, 5874, 5871, 7313, 16806, 13245, 8594, 8593, 8592, 8591, 8598, 8597, 8596, 8595, 15950, 15948, 16918, 785, 9828, 14118, 2595, 2596, 2597, 2611, 2616, 2618, 2617, 5943, 13532, 1932, 188, 228, 7453, 7455, 17319, 7443, 7438, 11668, 11667 ]
map_done = map_pending = fix_done = fix_pending = map_history = nil
find_dupe_paths = proc { |room|
find_dupes = Hash.new
room.wayto.values.each { |way|
if way.class == String
find_dupes[way] = find_dupes[way].to_i + 1
end
}
find_dupes.each_pair { |way,count|
if count > 1
echo "#{room.id}: duplicate paths in this room (#{way})"
map_history.puts "#{room.id}: duplicate paths in this room (#{way})"
end
}
}
def mapmap_move(dir)
timeout = 8
end_time = Time.now.to_i + timeout
tried_open = false
room_count = XMLData.room_count
loop {
clear
put dir
begin
sleep 0.01
if XMLData.room_count > room_count
return true
end
if Time.now.to_i >= end_time
return nil
end
redo_move = false
for line in clear
if line =~ /can't go there|^Where are you trying to go|^What were you referring to\?|^I could not find what you were referring to\.$|^You can't climb that\.$|^How do you plan to do that here\?$|^You take a few steps towards|^You're going to have to climb that\.$|^You cannot do that\.$|^You settle yourself on|^You shouldn't annoy|^You can't|^That's probably not a very good idea|^Maybe you should look at the [\w\s]+ and work with one at a time\.$|^You are already|^You (?:walk|step) over to|^Sorry, you aren't allowed to enter here\.$|^The [\w\s]+ is too far away|^You may not pass\.$|becomes? impassable\.$|prevents you from entering\.$|Please leave promptly\.$|^That looks like someplace only performers should go\.$|is too far above you to attempt that\.$|^Uh, yeah\. Right\.$|^Definitely NOT a good idea\.$|^You will have to climb that\.$|^Your attempt fails|^You'll have to wait|^A thunderous voice resounds within your mind: "DO NOT BRING YOUR FOUL SOUL IN HERE!"$|^Rushing heedlessly .*, your feet slip on a patch of ice, sending you reeling|^You will have to swim|^I don't think that is such a good idea|^You sit down|^I could not find what you were refering to\.|^A thick wall of bramble blocks further travel in that direction\.|^You gingerly place your weight on the porch swing|^You pick out a comfortable-looking pillow/
return false
elsif line =~ /^An unseen force prevents you\.$|^As you climb, your grip gives way and you fall down|^Rushing heedlessly up the slope, your feet slip on a patch of ice, sending you reeling\. Spinning, your legs give way and you fall to the ground, sliding down the mountain!$/
return nil
elsif line =~ /(?:appears|seems) to be closed\.$/
return false if tried_open
fput dir.sub(/go|climb/, 'open')
redo_move = true
tried_open = true
break
elsif line =~ /^(\.\.\.w|W)ait ([0-9]+) sec(onds)?\.$/
if $2.to_i > 1
sleep ($2.to_i - 0.2)
else
sleep 0.3
end
end_time = Time.now.to_i + timeout
redo_move = true
break
elsif line =~ /will have to stand up first|must be standing first|You'll have to get up first\.|But you're already sitting!|Shouldn't you be standing first/
fput 'stand'
waitrt?
redo_move = true
break
elsif line =~ /^Sorry, you may only type ahead/
sleep 1
end_time = Time.now.to_i + timeout
redo_move = true
break
elsif line == 'You are still stunned.'
wait_while { stunned? }
end_time = Time.now.to_i + timeout
redo_move = true
break
elsif line =~ /^Running heedlessly/
waitrt?
fput 'stand' unless standing?
waitrt?
put dir
next
end
end
end until redo_move
}
end
combine_rooms = proc { |this_room, that_room|
first_room = Room[[this_room.to_i, that_room.to_i].min]
second_room = Room[[this_room.to_i, that_room.to_i].max]
second_room.title.each { |title| first_room.title.push(title) unless first_room.title.include?(title) }
second_room.desc.each { |desc| first_room.desc.push(desc) unless first_room.desc.include?(desc) }
second_room.paths.each { |paths| first_room.paths.push(paths) unless first_room.paths.include?(paths) }
if first_room.location.nil?
first_room.location = second_room.location
end
second_room.wayto.each_pair { |adj_room,way|
unless first_room.wayto.keys.include?(adj_room)
first_room.wayto[adj_room] = way
first_room.timeto[adj_room] = second_room.timeto[adj_room]
end
}
map_done.delete(second_room.id)
map_pending.delete(second_room.id.to_s)
fix_done.delete(second_room.id)
fix_pending.delete(second_room.id.to_s)
Map.list[second_room.id] = nil
key = second_room.id.to_s
Map.list.each { |room|
if room.wayto.keys.include?(key)
room.wayto[first_room.id.to_s] = room.wayto[key]
room.timeto[first_room.id.to_s] = room.timeto[key]
room.wayto.delete(key)
room.timeto.delete(key)
end
}
Map.list.each { |room|
room.wayto.each_pair { |rm,way|
if (way.class == Proc) and way._dump =~ /#{second_room.id.to_s}/
respond
respond "#{room.id} => #{rm}"
respond way._dump
respond
clear
echo 'this path refrences the deleted room number'
echo "replace #{second_room.id} with #{first_room.id}? (send yes/no)"
respond
line = nil
line = get until line =~ /^yes$|^no$/i
if line =~ /^yes$/i
room.wayto[rm] = StringProc.new(way._dump.gsub(second_room.id.to_s, first_room.id.to_s))
end
end
}
}
}
if script.vars[1] =~ /new|clear/i
lazy = GameSettings['lazy']
GameSettings.clear
GameSettings['lazy'] = lazy
echo 'mapping session cleared'
exit
elsif script.vars[1] =~ /boundary/i
if script.vars[2] =~ /^[0-9]+$/
unless room = Room[script.vars[2]]
echo 'error: invalid room number'
exit
end
else
unless room = Room.current
echo 'error: current room is not in the map database'
exit
end
end
GameSettings['map_done'] ||= Array.new
GameSettings['map_done'].push(room.id)
GameSettings['fix_done'] ||= Array.new
GameSettings['fix_done'].push(room.id)
GameSettings['map_pending'] ||= Hash.new
GameSettings['map_pending'].delete(room.id.to_s)
GameSettings['fix_pending'] ||= Hash.new
GameSettings['fix_pending'].delete(room.id.to_s)
echo 'boundary set'
exit
elsif script.vars[1] =~ /location/i
GameSettings['map_done'] ||= Array.new
GameSettings['fix_done'] ||= Array.new
GameSettings['map_pending'] ||= Hash.new
GameSettings['fix_pending'] ||= Hash.new
Map.list.each { |room|
if room.location
GameSettings['map_done'].push(room.id)
GameSettings['fix_done'].push(room.id)
GameSettings['map_pending'].delete(room.id.to_s)
GameSettings['fix_pending'].delete(room.id.to_s)
end
}
echo 'all rooms with location info set as boundaries'
exit
elsif script.vars[1] =~ /lazy/i
if GameSettings['lazy'] = !GameSettings['lazy']
echo 'the script is now lazy'
else
echo 'the script is no longer lazy'
end
elsif script.vars[1] == 'info'
add_commas = proc { |num| num.to_s.reverse.scan(/(?:\d*\.)?\d{1,3}-?/).join(',').reverse }
empty_count = desc_count = simple_count = mini_count = narost_count = location_count = total_tags = 0
unique_tags = Hash.new
Map.list.each { |room|
empty_count += 1 if room.nil?
desc_count += 1 if room.desc.length > 1
narost_count += 1 if room.map_name
location_count += 1 if room.location
total_tags += room.tags.length.to_i
room.wayto.values.each { |way|
simple_count += 1 if way.class == String
mini_count += 1 if way.class == Proc
}
room.tags.each { |tag| unique_tags[tag] = true }
}
unique_tags = unique_tags.length
respond
respond " map size: #{add_commas.call(Map.list.length).rjust(7)}"
respond " nils: #{add_commas.call(empty_count).rjust(7)}"
respond "rooms with multiple descriptions: #{add_commas.call(desc_count).rjust(7)}"
respond " rooms with narost info: #{add_commas.call(narost_count).rjust(7)}"
respond " rooms with location info: #{add_commas.call(location_count).rjust(7)}"
respond " total rooms: #{add_commas.call(Map.list.length - empty_count).rjust(7)}"
respond
respond " simple directions: #{add_commas.call(simple_count).rjust(7)}"
respond " mini-script directions: #{add_commas.call(mini_count).rjust(7)}"
respond " total directions: #{add_commas.call(simple_count + mini_count).rjust(7)}"
respond
respond " unique tags: #{add_commas.call(unique_tags).rjust(7)}"
respond " total tags: #{add_commas.call(total_tags).rjust(7)}"
respond
exit
elsif script.vars[1] == 'check'
echo 'looking for invalid wayto keys...'
total = 0
count = 0
Map.list.each { |room| room.wayto.keys.each { |key| total += 1 if key.class != String } }
if total > 0
Map.list.each { |room|
room.wayto.keys.each { |key|
if key.class != String
echo "#{count+=1} of #{total}"
respond room
respond room.wayto.inspect
respond room.timeto.inspect
clear
echo "delete path #{room.id} => #{key} (#{key.class})?"
echo 'send yes/no'
respond
response = nil
response = get until response =~ /^yes$|^no$/
if response == 'yes'
room.wayto.delete(key)
room.timeto.delete(key)
end
end
}
}
else
echo '...found none'
end
echo 'looking for invalid timeto keys...'
total = 0
count = 0
Map.list.each { |room| room.timeto.keys.each { |key| total += 1 if key.class != String } }
if total > 0
Map.list.each { |room|
room.timeto.keys.each { |key|
if key.class != String
echo "#{count+=1} of #{total}"
respond room
respond room.wayto.inspect
respond room.timeto.inspect
clear
echo "delete path #{room.id} => #{key} (#{key.class})?"
echo 'send yes/no'
respond
response = nil
response = get until response =~ /^yes$|^no$/
if response == 'yes'
room.wayto.delete(key)
room.timeto.delete(key)
end
end
}
}
else
echo '...found none'
end
echo 'looking for loner wayto keys...'
total = 0
count = 0
Map.list.each { |room| room.wayto.keys.each { |key| total += 1 unless room.timeto[key] } }
if total > 0
Map.list.each { |room|
room.wayto.keys.each { |key|
unless room.timeto[key]
echo "#{count+=1} of #{total}"
respond room
respond room.wayto.inspect
respond room.timeto.inspect
clear
echo "set default timeto (0.2) for #{room.id} => #{key} ?"
echo 'send yes/no'
respond
response = nil
response = get until response =~ /^yes$|^no$/
if response == 'yes'
room.timeto[key] = 0.2
end
end
}
}
else
echo '...found none'
end
echo 'looking for loner timeto keys...'
total = 0
count = 0
Map.list.each { |room| room.timeto.keys.each { |key| total += 1 unless room.wayto[key] } }
if total > 0
Map.list.each { |room|
room.timeto.keys.each { |key|
unless room.wayto[key]
echo "#{count+=1} of #{total}"
respond room
respond room.wayto.inspect
respond room.timeto.inspect
clear
echo "delete path #{room.id} => #{key} (#{key.class})?"
echo 'send yes/no'
respond
response = nil
response = get until response =~ /^yes$|^no$/
if response == 'yes'
room.wayto.delete(key)
room.timeto.delete(key)
end
end
}
}
else
echo '...found none'
end
echo 'looking for rooms with a path to itself...'
total = 0
count = 0
Map.list.each { |room| total += 1 unless room.nil? or room.wayto[room.id.to_s].nil? }
if total > 0
Map.list.each { |room|
next if room.nil?
unless room.wayto[room.id.to_s].nil?
echo "#{count+=1} of #{total}"
respond room
respond room.wayto.inspect
respond
clear
echo "delete path #{room.id} => #{room.wayto[room.id.to_s]} => #{room.id}?"
echo 'send yes/no'
respond
response = nil
response = get until response =~ /^yes$|^no$/
if response == 'yes'
room.wayto.delete(room.id.to_s)
end
end
}
else
echo '...found none'
end
echo 'looking for identical paths with different destinations...'
da_rooms = Array.new
Map.list.each { |room|
room.wayto.each { |first_room_id,first_path|
room.wayto.each { |second_room_id,second_path|
if (first_path == second_path) and (first_room_id != second_room_id)
respond "#{room.id} => #{first_room_id}: #{first_path}"
da_rooms.push(room.id) unless da_rooms.include?(room.id)
end
}
}
}
if da_rooms.empty?
echo '...found none'
else
echo "closest: #{Room.current.find_nearest(da_rooms)}"
end
no_location = Map.list.find_all { |room| !room.nil? and room.location.nil? }.collect { |room| room.id }
unless no_location.empty?
echo "nearest room without location info: #{Room.current.find_nearest(no_location)}"
end
town_list = {
"Ta'Illistim" => 188,
"Wehnimer's" => 228,
"Solhaven" => 1438,
"Icemule Trace" => 2300,
"Teras Isle" => 1932,
"River's Rest" => 10861,
"Zul Logoth" => 1005,
"Ta'Vaalor" => 3519,
}
normal_travel_time = {
"Ta'Illistim" => {
"Wehnimer's" => 1353,
'Solhaven' => 1381,
'Icemule Trace' => 1364,
'Teras Isle' => 0,
"River's Rest" => 1981,
'Zul Logoth' => 283,
"Ta'Vaalor" => 329,
},
"Wehnimer's" => {
"Ta'Illistim" => 1348,
'Solhaven' => 36,
'Icemule Trace' => 28,
'Teras Isle' => 0,
"River's Rest" => 636,
'Zul Logoth' => 1068,
"Ta'Vaalor" => 1666,
},
'Solhaven' => {
"Ta'Illistim" => 1376,
"Wehnimer's" => 36,
'Icemule Trace' => 56,
'Teras Isle' => 0,
"River's Rest" => 602,
'Zul Logoth' => 1095,
"Ta'Vaalor" => 1694,
},
'Icemule Trace' => {
"Ta'Illistim" => 1359,
"Wehnimer's" => 28,
'Solhaven' => 56,
'Teras Isle' => 0,
"River's Rest" => 656,
'Zul Logoth' => 1078,
"Ta'Vaalor" => 1677,
},
'Teras Isle' => {
"Ta'Illistim" => 0,
"Wehnimer's" => 0,
'Solhaven' => 0,
'Icemule Trace' => 0,
"River's Rest" => 0,
'Zul Logoth' => 0,
"Ta'Vaalor" => 0,
},
"River's Rest" => {
"Ta'Illistim" => 1975,
"Wehnimer's" => 635,
'Solhaven' => 602,
'Icemule Trace' => 656,
'Teras Isle' => 0,
'Zul Logoth' => 1695,
"Ta'Vaalor" => 2294,
},
'Zul Logoth' => {
"Ta'Illistim" => 280,
"Wehnimer's" => 1069,
'Solhaven' => 1097,
'Icemule Trace' => 1081,
'Teras Isle' => 0,
"River's Rest" => 1697,
"Ta'Vaalor" => 598,
},
"Ta'Vaalor" => {
"Ta'Illistim" => 320,
"Wehnimer's" => 1663,
'Solhaven' => 1690,
'Icemule Trace' => 1674,
'Teras Isle' => 0,
"River's Rest" => 2290,
'Zul Logoth' => 593,
},
}
echo 'checking travel times between towns...'
changed = false
town_list.each_pair { |start_town_name,start_town_id|
previous, shortest_distances = Map.dijkstra(start_town_id)
town_list.each_pair { |end_town_name,end_town_id|
next if start_town_id == end_town_id
est_time = shortest_distances[end_town_id]
unless normal_travel_time[start_town_name][end_town_name] == est_time.to_i
echo "#{start_town_name} => #{end_town_name}: changed from #{normal_travel_time[start_town_name][end_town_name]} to #{est_time.to_i}"
changed = true
end
}
}
echo '...done'
exit
elsif script.vars[1] == 'map'
map_done = GameSettings['map_done'] || Array.new
map_pending = GameSettings['map_pending'] || Hash.new
echo map_pending.inspect
fix_done = GameSettings['fix_done'] || Array.new
fix_pending = GameSettings['fix_pending'] || Hash.new
map_history = File.open("#{$temp_dir}mapmap_history.txt", 'a') if $SAFE == 0
before_dying {
File.close(map_history) rescue()
GameSettings['map_done'] = map_done
GameSettings['map_pending'] = map_pending
GameSettings['fix_done'] = fix_done
GameSettings['fix_pending'] = fix_pending
# Map.save
}
loop {
room = Room.current_or_new
if map_done.include?(room.id)
next_room = nil
room.wayto.keys.each { |adj_room|
if map_pending.keys.include?(adj_room)
next_room = adj_room
break
end
}
unless next_room
next_room = room.find_nearest(map_pending.keys)
end
unless next_room or GameSettings['lazy']
all_room_ids = Map.list.collect { |rm| rm.id unless rm.nil? } - map_done
next_room = room.find_nearest(all_room_ids)
end
unless next_room
if [ 5730, 1273 ].include?(room.id)
move 'go ladder'
next
elsif room.id == 3742
move 'go arch'
next
elsif [ 3357, 13173 ].include?(room.id)
move 'out'
next
elsif room.id == 16445
move "go ##{GameObj.loot.find { |obj| obj.noun == 'door' }.id}"
next
else
unless map_pending.empty?
if checkpaths.include?('out')
move 'out'
next
end
echo "Stuck. #{map_done.length} rooms checked."
map_history.puts "Stuck. #{map_done.length} rooms checked."
else
echo "Done. #{map_done.length} rooms checked."
map_history.puts "Done. #{map_done.length} rooms checked."
end
exit
end
end
start_script 'go2', [ next_room.to_s, '_disable_confirm_', 'typeahead=0' ]
wait_while { running? 'go2' }
else
unless map_pending.keys.include?(room.id.to_s)
map_pending[room.id.to_s] = XMLData.room_exits.to_a + GameObj.loot.to_a
GameObj.room_desc.to_a.each { |obj| map_pending[room.id.to_s].push(obj) unless GameObj.loot.find{ |l| l.id == obj.id } }
# spitfire, don't jump off plank and die and stuff
# GameObj.room_desc.to_a.each { |obj| map_pending[room.id.to_s].push(obj) unless GameObj.loot.find{ |l| l.id == obj.id } or obj.noun == 'plank' }
for obj in map_pending[room.id.to_s]
next unless obj.class == GameObj
crap = Array.new
status_tags
clear
put "look ##{obj.id}"
end_time = Time.now + 1
while Time.now < end_time
sleep 0.1
while line = get?
crap.concat(line.scan(/<a exist="[^"]+" noun="[^"]+">.*?<\/a>/))
if line =~ /#{obj.noun}|You see nothing unusual\./
end_time -= 1
break
end
end
end
status_tags
for xml_obj in crap
xml_obj =~ /<a exist="([^"]+)" noun="([^"]+)">(.*?)<\/a>/
new_obj = GameObj.new($1, $2, $3)
unless GameObj.pcs.any? { |pc| pc.id == new_obj.id } or map_pending[room.id.to_s].any? { |o| (o.class == GameObj) and (o.id == new_obj.id) }
map_pending[room.id.to_s].push(new_obj)
end
end
end
map_pending[room.id.to_s].delete_if { |obj| (obj.class == GameObj) and (obj.noun == 'moat') }
if XMLData.room_title =~ neighborhoods
map_pending[room.id.to_s].delete_if { |obj| (obj.class == GameObj) and (obj.noun !~ /path|gate|trail|footbridge|winery|bridge|stair|step/) }
end
end
# unless map_pending.keys.include?(room.id.to_s)
# map_pending[room.id.to_s] = XMLData.room_exits.to_a
# #GameObj.loot.to_a.each { |obj| map_pending[room.id.to_s].push(obj) if obj.noun == 'barrier' }
# end
if map_pending[room.id.to_s].empty?
map_done.push(room.id)
map_pending.delete(room.id.to_s)
find_dupe_paths.call(room)
next
end
path = map_pending[room.id.to_s].pop
if map_pending[room.id.to_s].empty?
map_done.push(room.id)
map_pending.delete(room.id.to_s)
find_dupe_paths.call(room)
end
if path.class == String
path_options = [ path, "swim #{path}" ]
elsif path.class == GameObj
if (GameObj.loot.to_a + GameObj.room_desc.to_a).find { |obj| (obj.noun =~ /^#{path.noun}/) and (obj.id != path.id) }
path_words = path.name.split
if path.noun.split.length == 2
path_options = [ "go #{path.noun.downcase}", "climb #{path.noun.downcase}" ]
elsif path_words.length == 1
if path_words.first == path.noun
path_options = [ "go #{path.noun.downcase}", "climb #{path.noun.downcase}" ]
else
path_options = [ "go #{path.name.downcase} #{path.noun.downcase}", "climb #{path.name.downcase} #{path.noun.downcase}" ]
end
elsif (path_words == 2) and (path_words.last == path.noun)
path_options = [ "go #{path.name.downcase}", "climb #{path.name.downcase}" ]
else
path_words.delete_if { |word| word =~ /^#{path.noun}$|^of$|^some$|^an?$|^the$|^to$|^into$|^in$|^on$|^at$|^through$|^with$/i }
path_options = Array.new
path_words.reverse.each { |word|
path_options.push "go #{word.downcase} #{path.noun.downcase}"
path_options.push "climb #{word.downcase} #{path.noun.downcase}"
}
end
else
path_options = [ "go #{path.noun.downcase}", "climb #{path.noun.downcase}" ]
end
else
echo "#{room.id}: What the hell?"
map_history.puts "#{room.id}: What the hell?"
end
path_options.each { |option|
sleep 0.05
if mapmap_move(option)
adj_room = Room.current_or_new
if room == adj_room
echo "#{room.id}: move appeared to succeed, but not really."
map_history.puts "#{room.id}: move appeared to succeed, but not really."
break
elsif room.tags.include?('no-auto-map') or adj_room.tags.include?('no-auto-map')
echo "#{room.id} => #{adj_room.id}: marked as error room; not saving move."
map_history.puts "#{room.id} => #{adj_room.id}: marked as error room; not saving move."
break
end
if room.wayto[adj_room.id.to_s].class == Proc
echo "#{room.id} => #{adj_room.id}: not overwriting proc. "
map_history.puts "#{room.id} => #{adj_room.id}: not overwriting proc. "
elsif room.timeto[adj_room.id.to_s].class == Proc
echo "#{room.id} => #{adj_room.id}: not overwriting proc. "
map_history.puts "#{room.id} => #{adj_room.id}: not overwriting proc. "
elsif room.wayto[adj_room.id.to_s] != option
echo "#{room.id} => #{adj_room.id}: #{room.wayto[adj_room.id.to_s] || 'nil'} => #{option} "
map_history.puts("#{room.id} => #{adj_room.id}: #{room.wayto[adj_room.id.to_s] || 'nil'} => #{option} ")
room.wayto[adj_room.id.to_s] = option
room.timeto[adj_room.id.to_s] = 0.2
end
break
end
}
end
}
elsif script.vars[1] == 'fix'
map_done = GameSettings['map_done'] || Array.new
map_pending = GameSettings['map_pending'] || Hash.new
fix_done = GameSettings['fix_done'] || Array.new
fix_pending = GameSettings['fix_pending'] || Hash.new
map_history = File.open("#{$temp_dir}mapmap_history.txt", 'a')
before_dying {
File.close(map_history) rescue()
GameSettings['map_done'] = map_done
GameSettings['map_pending'] = map_pending
GameSettings['fix_done'] = fix_done
GameSettings['fix_pending'] = fix_pending
# Map.save
}
loop {
room = Room.current_or_new
if room.nil?
echo 'Current room is unknown. Use map mode.'
exit
end
if fix_done.include?(room.id)
next_room = nil
room.wayto.keys.each { |adj_room|
if fix_pending.keys.include?(adj_room)
next_room = adj_room
break
end
}
unless next_room
next_room = room.find_nearest(fix_pending.keys)
end
unless next_room or GameSettings['lazy']
all_room_ids = Map.list.collect { |rm| rm.id unless rm.nil? } - fix_done
next_room = room.find_nearest(all_room_ids)
end
unless next_room
if [ 5730, 1273, 13245 ].include?(room.id)
move 'go ladder'
next
elsif room.id == 3742
move 'go arch'
next
elsif [ 3357, 13173 ].include?(room.id)
move 'out'
next
elsif room.id == 16445
move "go ##{GameObj.loot.find { |obj| obj.noun == 'door' }.id}"
next
else
unless fix_pending.empty?
if checkpaths.include?('out')
move 'out'
next
end
echo "Stuck. #{fix_done.length} rooms checked."
map_history.puts "Stuck. #{fix_done.length} rooms checked."
else
echo "Done. #{fix_done.length} rooms checked."
map_history.puts "Done. #{fix_done.length} rooms checked."
end
exit
end
end
start_script 'go2', [ next_room.to_s, '_disable_confirm_', 'typeahead=0' ]
wait_while { running? 'go2' }
else
unless fix_pending.keys.include?(room.id.to_s)
fix_pending[room.id.to_s] = Array.new
room.wayto.each_pair { |rm,way| fix_pending[room.id.to_s].push(rm) if (way.class == String) and (way !~ /^go .*?table$/) }
# excluding the barrier is helpful when mapping the Scatter
# room.wayto.each_pair { |rm,way| fix_pending[room.id.to_s].push(rm) if (way.class == String) and (way !~ /^go .*?table$|^go barrier$/) }
fix_pending[room.id.to_s].delete_if { |rm| (room.timeto[rm].class == Proc) and room.timeto[rm].call.nil? }
end
if fix_pending[room.id.to_s].empty?
fix_done.push(room.id)
fix_pending.delete(room.id.to_s)
next
end
adj_room = fix_pending[room.id.to_s].pop
if fix_pending[room.id.to_s].empty?
fix_done.push(room.id)
fix_pending.delete(room.id.to_s)
end
path = room.wayto[adj_room]
next unless path
result = move(path)
if result
real_adj_room = Room.current_or_new
unless adj_room == real_adj_room.id.to_s
adj_room_obj = Room[adj_room]
if adj_room_obj.location and real_adj_room.location and (adj_room_obj.location != real_adj_room.location)
line = 'no'
elsif adj_room_obj.title.first =~ /^\[([A-z]+)'s? (?:Magic Shoppe|Outfitting|Weaponry|General Store|Combat Gear|Armory|Lockpicks)\]$/
player_shop_owner = $1
if real_adj_room.title.first =~ /^\[#{player_shop_owner}'s? (?:Magic Shoppe|Outfitting|Weaponry|General Store|Combat Gear|Armory)\]$/
line = 'yes'
else
line = 'no'
end
else
respond
respond Room[adj_room.to_i]
respond Room[adj_room.to_i].wayto.inspect
respond "location: #{Room[adj_room.to_i].location.inspect}"
respond
respond real_adj_room
respond real_adj_room.wayto.inspect
respond "location: #{real_adj_room.location.inspect}"
respond
clear
echo 'Are these the same room? (send yes/no/ignore)'
respond
line = nil
line = get until line =~ /^yes$|^no$|^ignore$/i
end
if line =~ /^yes$/i
combine_rooms.call(adj_room.to_i, real_adj_room.id)
elsif line =~ /^no$/i
if room.tags.include?('no-auto-map') or real_adj_room.tags.include?('no-auto-map')
echo "marked as error room; not adding path"
map_history.puts "marked as error room; not adding path"
else
echo "adding: #{room.id} => #{real_adj_room.id}: #{room.wayto[adj_room]}"
map_history.puts "adding: #{room.id} => #{real_adj_room.id}: #{room.wayto[adj_room]}"
room.wayto[real_adj_room.id.to_s] = room.wayto[adj_room]
room.timeto[real_adj_room.id.to_s] = 0.2
end
echo "deleting: #{room.id} => #{adj_room}: #{room.wayto[adj_room]}"
map_history.puts "deleting: #{room.id} => #{adj_room}: #{room.wayto[adj_room]}"
room.wayto.delete(adj_room)
room.timeto.delete(adj_room)
end
end
elsif result == false
echo "deleting: #{room.id} => #{adj_room}: #{room.wayto[adj_room]}"
map_history.puts "deleting: #{room.id} => #{adj_room}: #{room.wayto[adj_room]}"
room.wayto.delete(adj_room)
room.timeto.delete(adj_room)
elsif result.nil?
nil
# temporary error, ignore
end
end
}
elsif script.vars[1] == 'combine'
combine_rooms.call(script.vars[2].to_i, script.vars[3].to_i)
else
script_starter = "#{$lich_char}#{script.name}"
script_spacerr = "#{$lich_char.gsub(/./,' ')}#{script.name.gsub(/./,' ')}"
respond
respond "This script edits your local map database, which will be overwritten if updater is set to update your map database."
respond
respond "Usage:"
respond
respond " #{script_starter} boundary Marks the current room as already checked, which"
respond " #{script_spacerr} may keep the script in an area while mapping."
respond
respond " #{script_starter} lazy Toggles the lazy setting. If the script is not lazy,"
respond " #{script_spacerr} it will seek out the closest unchecked room when all"
respond " #{script_spacerr} pending rooms are done."
respond
respond " #{script_starter} map Map mode. Finds new rooms and directions and adds"
respond " #{script_spacerr} them to the map database."
respond
respond " #{script_starter} fix Fix mode. Tests existing directions in the map database"
respond " #{script_spacerr} and makes sure they lead to the room they're supposed to."
respond " #{script_spacerr} This mode allows you to add multiple room descriptions."
respond
respond " #{script_starter} new Starts a new mapping session, which just means no rooms"
respond " #{script_spacerr} are marked done or pending."
respond
respond " #{script_starter} check Does some quick checks on the map database without moving."
respond " #{script_spacerr} Use \";go2 shortcut=off\" first or it will tell you the distances"
respond " #{script_spacerr} between towns are wrong."
respond
respond " #{script_starter} info Shows a few stats."
respond
respond "This script is not foolproof."
respond
exit
end