-
Notifications
You must be signed in to change notification settings - Fork 1
/
run_simulation.py
4667 lines (4108 loc) · 242 KB
/
run_simulation.py
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
import os
import concurrent.futures
import multiprocessing as mp
import pandas as pd
import time as tm
import pandas as pd
import sys
import random
def dungeon_simr(suffix, periodic_checks, verbosity, usepath):
import timeit
import time
#start = timeit.timeit()
t0 = time.time()
import sys
import os
import numpy as np
import pandas as pd
import random
import time
import datetime
import copy
import json
import pickle
import math
from monsters import monster_tables, monster_subtables_wet
from treasure import select_gemstone, update_gemstone, select_jewellery, select_magic_item, treasure_choice
VERBOSITY = verbosity
PI = math.pi
#ARGV = sys.argv
#standard algorithm
LEVEL = "Y"
#if len(ARGV) > 2:
#LEVEL = ARGV[2]
#stub to handle making a dungeon of just one level
#this would be checked to disable level descent in periodi check
#also in traps that go down, substitute
#pass location?
def roll_dice(number, sides):
roll = random.randint(number,sides)
return roll
def in_dungeon(coord):
inside = False
if coord in dungeon:
inside = True
return inside
def coord_limits(dungeon):
minx = 9999
maxx = -9999
miny = 9999
maxy = -9999
minz = 9999
maxz = -9999
for key in dungeon:
if key[0] > maxx:
maxx = key[0]
if key[0] < minx:
minx = key[0]
if key[1] > maxy:
maxy = key[1]
if key[1] < miny:
miny = key[1]
if key[2] > maxz:
maxz = key[2]
if key[2] < minz:
minz = key[2]
coord_min = (minx,miny,minz)
coord_max = (maxx,maxy,maxz)
return [coord_min, coord_max]
def coord_random(dungeon):
coordlist = list(dungeon.keys())
c = roll_dice(1,len(coordlist))
for index, key in enumerate(dungeon):
if index + 1 == c:
#return dungeon[key]
return (key[0],key[1],key[2])
##make arrrays for each level
def coord_edge(dungeon):
minx = 9999
maxx = -9999
miny = 9999
maxy = -9999
minz = 9999
maxz = -9999
for key in dungeon:
if key[0] > maxx:
maxx = key[0]
if key[0] < minx:
minx = key[0]
if key[1] > maxy:
maxy = key[1]
if key[1] < miny:
miny = key[1]
if key[2] > maxz:
maxz = key[2]
if key[2] < minz:
minz = key[2]
coord_min = (minx,miny,minz)
coord_max = (maxx,maxy,maxz)
coordlist = list(dungeon.keys())
c = roll_dice(1,len(coordlist))
non_edge = []
for index, key in enumerate(dungeon):
if key[0] != minx and key[1] != miny and key[0] != maxx and key[1] != maxy:
non_edge.append((key[0],key[1],key[2]))
return non_edge
def random_check():
pc_dict = {}
pc = roll_dice(1,20)
if pc <= 2:
pc_dict['direction'] = 'ahead'
pc_dict['check'] = 6
elif pc >= 3 and pc <= 5:
pc_dict['direction'] = 'exit'
pc_dict['check'] = 6
elif pc >= 6 and pc <= 10:
pc_dict['direction'] = 'side'
pc_dict['check'] = 3
elif pc >= 11 and pc <= 13:
pc_dict['direction'] = 'turn'
pc_dict['check'] = 3
elif pc >= 14 and pc <= 16:
pc_dict['direction'] = 'room'
pc_dict['check'] = 3
elif pc == 17:
pc_dict['direction'] = 'level'
pc_dict['check'] = 'up_down'
if LEVEL == "N": #make this what you like or could be config
pc_dict['direction'] = 'room'
pc_dict['check'] = 3
elif pc == 18:
pc_dict['direction'] = 'stop'
pc_dict['check'] = 'spy_things'
elif pc == 19:
pc_dict['direction'] = 'bad_things'
pc_dict['check'] = 3
elif pc == 20:
pc_dict['direction'] = 'random_encounter'
pc_dict['check'] = 'roll_again'
if VERBOSITY:
print("RANDOM_CHECK",pc, pc_dict['direction'])
#test purposes
#pc_dict['direction'] = 'ahead'
return pc_dict
def passage_make(coord, loop=3,xmod=0,ymod=0,zmod=0,xloop=0,yloop=0,zloop=0,xwidth=0,ywidth=0): #check this
p_dict = width()
#print("PDICTBEFORE:",p_dict)
#print("CHECKWIDTH:",p_dict['width'],"LOOP:",loop,"COORD:",coord)
#print("PDICT:",p_dict)
if p_dict['width'] <= 1: #0.5 width do cosmetically later
new_coord = coord
for y in range(loop):
will_fit = in_dungeon((coord[0]+xmod+xloop*y,coord[1]+ymod+yloop*y,coord[2]+zmod+zloop*y))
if VERBOSITY:
print("loop:","willfit:",will_fit,(coord[0]+xmod+xloop*y,coord[1]+ymod+yloop*y,coord[2]+zmod+zloop*y))
if not will_fit:
dungeon[(coord[0]+xmod+xloop*y,coord[1]+ymod+yloop*y,coord[2]+zmod+zloop*y)] = {}
dungeon[(coord[0]+xmod+xloop*y,coord[1]+ymod+yloop*y,coord[2]+zmod+zloop*y)]['fill'] = 'C'
new_coord = (coord[0]+xmod+xloop*y,coord[1]+ymod+yloop*y,coord[2]+zmod+zloop*y)
else:
break
else: #do column width first, then do fancy parts #work out new_coord?? #default go to xpos/right for now
if VERBOSITY:
print("FANCY WIDTH:",p_dict)
for w in range(p_dict['width']):
new_coord = coord
for y in range(loop):
#print("COORD BEFORE:",(coord[0]+xmod+xloop*y+xwidth*w,coord[1]+ymod+yloop*y+ywidth*w,coord[2]+zmod+zloop*loop))
will_fit = in_dungeon((coord[0]+xmod+xloop*y+xwidth*w,coord[1]+ymod+yloop*y+ywidth*w,coord[2]+zmod+zloop*loop))
#print("width:",w,"loop:","willfit:",will_fit,(coord[0]+xmod+xloop*y+xwidth*w,coord[1]+ymod+yloop*y+ywidth*w,coord[2]+zmod+zloop*loop))
if not will_fit:
dungeon[(coord[0]+xmod+xloop*y+xwidth*w,coord[1]+ymod+yloop*y+ywidth*w,coord[2]+zmod+zloop*y)] = {}
if y == 1: #approx midpoint fill - could random 3/4 it but for 3s will be in middle anyway wrong for 6 ok for 3
dungeon[(coord[0]+xmod+xloop*y+xwidth*w,coord[1]+ymod+yloop*y+ywidth*w,coord[2]+zmod+zloop*y)]['fill'] = 'C' + p_dict['fill']
else:
dungeon[(coord[0]+xmod+xloop*y+xwidth*w,coord[1]+ymod+yloop*y+ywidth*w,coord[2]+zmod+zloop*y)]['fill'] = 'C'
new_coord = (coord[0]+xmod+xloop*y+xwidth*w,coord[1]+ymod+yloop*y+ywidth*w,coord[2]+zmod+zloop*y)
else:
break
return new_coord
def check_action(pc_dict, coord, room_stack):
## need a current 'orientation' 'L R A B
if pc_dict['direction'] == 'ahead':
if 1 == 1:
#new_coord = coord
new_coord = passage_make(coord,loop=6,ymod=1,yloop=1,xwidth=1)
elif pc_dict['direction'] == 'exit':
'''
e_dict['beyond'] = 'P'
e_dict['beyond'] = 'A'
e_dict['beyond'] = '4AB'
e_dict['beyond'] = '4BA'
e_dict['beyond'] = 'Room'
'''
new_coord = coord
e_dict = exit(coord)
#test L parallel
if 1 == 2: #disable tests
e_dict['beyond'] = 'P'
#e_dict['beyond'] = '4BA'
#e_dict['beyond'] = '4AB'
e_dict['beyond'] = 'A'
#e_dict['direction'] = 'L'
#e_dict['direction'] = 'R'
e_dict['direction'] = 'A'
if VERBOSITY:
print("EDICT:",e_dict)
if e_dict['direction'] == 'L':
if e_dict['type'] == 'N':
exit_stack[(coord[0]-1,coord[1],coord[2])] = {}
if e_dict['beyond'] == 'P':
will_fit = in_dungeon((coord[0]-1,coord[1],coord[2]))
if not will_fit: #fit the zero door site
dungeon[(coord[0]-1,coord[1],coord[2])] = {}
dungeon[(coord[0]-1,coord[1],coord[2])]['fill'] = 'Cd'
new_coord = passage_make(coord, xmod=-1,ymod=-1,yloop=-1,xwidth=1)
new_coord = passage_make(coord, xmod=-1,ymod=1,yloop=1,xwidth=1)
if e_dict['beyond'] == 'A':
#print("IN BRANCH")
d = roll_dice(1,20)
if d >=3 and d <= 5:
will_fit = in_dungeon((coord[0]-1,coord[1],coord[2]))
if not will_fit:
exit_stack[(coord[0]-1,coord[1],coord[2])] = {}
else:
#30m passage that direction
new_coord = passage_make(coord, xmod=-1,xloop=-1, ywidth=1)
if e_dict['beyond'] == '4AB': ##45 A
which_way = roll_dice(1,2)
if which_way == 1: #corridor left
new_coord = passage_make(coord, xmod=-1,xloop=-1,ymod=1,yloop=1,ywidth=1)
else:
new_coord = passage_make(coord, xmod=1,xloop=1,ymod=1,yloop=1,ywidth=1)
if e_dict['beyond'] == '4BA': ##45 A
which_way = roll_dice(1,2)
if which_way == 1: #corridor left
new_coord = passage_make(coord, xmod=-1,xloop=-1,ymod=-1,yloop=-1,ywidth=1)
else:
new_coord = passage_make(coord, xmod=1,xloop=1,ymod=-1,yloop=-1,ywidth=1)
if e_dict['beyond'] == 'Room':
#want those we randomly position lr
new_coord = coord
#new part!
#if coming from here pass door to room function?
#dungeon[coord]['fill'] = dungeon[coord]['fill'] + 'd' #add door indicator
#not Rd room??
shape_dict = room(coord, room_stack, size='Rd' ) ## different type to get slightly different table pass Rd to indicate from door
#room_stack = shape_dict['room_stack']
#each room part check for inside
if VERBOSITY:
print("ROOM SHAPE:",shape_dict)
## do simple version first of x directions and y directions of rectangular
rm = room_make(shape_dict, coord)
if rm == "GOOD":
secret_doors(shape_dict)
elif e_dict['direction'] == 'R':
if e_dict['type'] == 'N':
exit_stack[(coord[0]+1,coord[1],coord[2])] = {}
if e_dict['beyond'] == 'P':
will_fit = in_dungeon((coord[0]+1,coord[1],coord[2]))
if not will_fit: #fit the zero door site
dungeon[(coord[0]+1,coord[1],coord[2])] = {}
dungeon[(coord[0]+1,coord[1],coord[2])]['fill'] = 'Cd'
new_coord = passage_make(coord, xmod=1,ymod=-1,yloop=-1,xwidth=1)
new_coord = passage_make(coord, xmod=1,ymod=1,yloop=1,xwidth=1)
if e_dict['beyond'] == 'A':
d = roll_dice(1,20)
#d = 20 #test number
if d >=3 and d <= 5:
will_fit = in_dungeon((coord[0]+1,coord[1],coord[2]))
if not will_fit:
exit_stack[(coord[0]+1,coord[1],coord[2])] = {}
else:
#30m passage that direction
if VERBOSITY:
print("CHECKEDICT",e_dict)
new_coord = passage_make(coord, xmod=1,xloop=1, ywidth=1)
if e_dict['beyond'] == '4AB': ##45 A
which_way = roll_dice(1,2)
if which_way == 1: #corridor left
new_coord = passage_make(coord, xmod=-1,xloop=-1,ymod=1,yloop=1,ywidth=1)
else:
new_coord = passage_make(coord, xmod=1,xloop=1,ymod=1,yloop=1,ywidth=1)
if e_dict['beyond'] == '4BA': ##45 A
which_way = roll_dice(1,2)
if which_way == 1: #corridor left
new_coord = passage_make(coord, xmod=-1,xloop=-1,ymod=-1,yloop=-1,ywidth=1)
else:
new_coord = passage_make(coord, xmod=1,xloop=1,ymod=-1,yloop=-1,ywidth=1)
if e_dict['beyond'] == 'Room':
#want those we randomly position lr
new_coord = coord
#dungeon[coord]['fill'] = dungeon[coord]['fill'] + 'd' #add door indicator
## check for room or chamber
rt = roll_dice(1,10)
if rt <=8:
#room
shape_dict = room(coord, room_stack,size='Rd') ## different type to get slightly different table indicate room from door
else:
#chamber
shape_dict = room(coord, room_stack)
#each room part check for inside
if VERBOSITY:
print("ROOM SHAPE:",shape_dict)
rm = room_make(shape_dict, coord)
if rm == "GOOD":
secret_doors(shape_dict)
else: #final branch ahead
if e_dict['type'] == 'N':
exit_stack[(coord[0],coord[1]+1,coord[2])] = {}
if e_dict['beyond'] == 'P':
will_fit = in_dungeon((coord[0],coord[1]+1,coord[2]))
if not will_fit:
#dungeon[(coord[0],coord[1]+1,coord[2])] = {}
#handle very first cool being cooridor door creation
if (coord[0],coord[1],coord[2]) not in dungeon:
dungeon[(coord[0],coord[1],coord[2])] = {}
dungeon[(coord[0],coord[1],coord[2])]['fill'] = 'Cd'
new_coord = (coord[0],coord[1]+1,coord[2])
# 10 x 10 room need to check contents!
new_coord = coord
shape_dict = room(coord, room_stack, size="10") #10 is special case to mandate 1 roll for size
if VERBOSITY:
print("ROOM SHAPE:",shape_dict)
# set Cd above for doors to indicate door to room ahead
rm = room_make(shape_dict, coord)
if rm == "GOOD":
secret_doors(shape_dict)
if e_dict['beyond'] == 'A':
d = roll_dice(1,20)
d = 20 #test number
if d >=3 and d <= 5:
will_fit = in_dungeon((coord[0],coord[1]+1,coord[2]))
if not will_fit:
exit_stack[(coord[0],coord[1]+1,coord[2])] = {}
else:
#30m passage that direction
if VERBOSITY:
print("CHECKEDICT",e_dict)
new_coord = passage_make(coord, ymod=1,yloop=1, xwidth=1)
if e_dict['beyond'] == '4AB': ##45 A - need to make facing for R different eventually
which_way = roll_dice(1,2)
if e_dict['beyond'] == '4AB': ##45 A
which_way = roll_dice(1,2)
if which_way == 1: #corridor left
new_coord = passage_make(coord, xmod=-1,xloop=-1,ymod=1,yloop=1,ywidth=1)
else:
new_coord = passage_make(coord, xmod=1,xloop=1,ymod=1,yloop=1,ywidth=1)
if e_dict['beyond'] == '4BA': ##45 A
which_way = roll_dice(1,2)
if which_way == 1: #corridor left
new_coord = passage_make(coord, xmod=-1,xloop=-1,ymod=-1,yloop=-1,ywidth=1)
else:
new_coord = passage_make(coord, xmod=1,xloop=1,ymod=-1,yloop=-1,ywidth=1)
if e_dict['beyond'] == 'Room':
#want those we randomly position lr
new_coord = coord
#if coming from here pass door to room function?
#dungeon[coord]['fill'] = dungeon[coord]['fill'] + 'd' #add door indicator
shape_dict = room(coord, room_stack, size='Rd' ) ## different type to get slightly different table pass Rd to indicate from door
#each room part check for inside
if VERBOSITY:
print("ROOM SHAPE:",shape_dict)
## do simple version first of x directions and y directions of rectangular
rm = room_make(shape_dict, coord)
if rm == "GOOD":
secret_doors(shape_dict)
## got to proceed with direction/type of exit
elif pc_dict['direction'] == 'side':
new_coord = coord
s_dict = side(coord)
if VERBOSITY:
print("S_DICT:",s_dict)
if s_dict['direction'] == 'L90':
new_coord = passage_make(coord,xmod=-1,xloop=-1,ywidth=1)
elif s_dict['direction'] == 'R90':
new_coord = passage_make(coord,xmod=1,xloop=1,ywidth=1)
elif s_dict['direction'] == 'L45':
new_coord = passage_make(coord,xmod=-1,xloop=-1,ymod=1,yloop=1,xwidth=1)
elif s_dict['direction'] == 'R45':
new_coord = passage_make(coord,xmod=1,xloop=1,ymod=1,yloop=1,xwidth=1)
elif s_dict['direction'] == 'L135':
new_coord = passage_make(coord,xmod=-1,xloop=-1,ymod=-1,yloop=-1,xwidth=1)
elif s_dict['direction'] == 'R135':
new_coord = passage_make(coord,xmod=1,xloop=1,ymod=-1,yloop=-1,xwidth=1)
elif s_dict['direction'] == 'T':
which_way = roll_dice(1,2)
new_coord_left = passage_make(coord,xmod=-1,xloop=-1,ywidth=1)
new_coord_right = passage_make(coord,xmod=1,xloop=1,ywidth=1)
if which_way == 1:
new_coord = new_coord_left
else:
new_coord = new_coord_right
elif s_dict['direction'] == 'Y':
which_way = roll_dice(1,2) #got to move this up
new_coord_left = passage_make(coord,xmod=-1,xloop=-1,ymod=1,yloop=1,xwidth=1)
new_coord_right = passage_make(coord,xmod=1,xloop=1,ymod=1,yloop=1,xwidth=1)
if which_way == 1:
new_coord = new_coord_left
else:
new_coord = new_coord_right
elif s_dict['direction'] == 'P': #plus
which_way = roll_dice(1,3)
new_coord_left = passage_make(coord,xmod=-1,xloop=-1,ywidth=1)
new_coord_right = passage_make(coord,xmod=1,xloop=1,ywidth=1)
new_coord_ahead = passage_make(coord,ymod=1,yloop=1,xwidth=1)
if which_way == 1:
new_coord = new_coord_left
elif which_way == 2:
new_coord = new_coord_right
else:
new_coord = new_coord_ahead
else:
#s_dict['direction'] == 'X': 45 and 135
which_way = roll_dice(1,4) ##got to move this up
new_coord_left = passage_make(coord,xmod=-1,xloop=-1,ymod=1,yloop=1,xwidth=1)
new_coord_right = passage_make(coord,xmod=1,xloop=1,ymod=1,yloop=1,xwidth=1)
new_coord_left_back = passage_make(coord,xmod=-1,xloop=-1,ymod=-1,yloop=-1,xwidth=1)
new_coord_right_back = passage_make(coord,xmod=1,xloop=1,ymod=-1,yloop=-1,xwidth=1)
if which_way == 1:
new_coord = new_coord_left
elif which_way == 2:
new_coord = new_coord_right
elif which_way == 3:
new_coord = new_coord_left_back
else:
new_coord = new_coord_right_back
elif pc_dict['direction'] == 'turn':
new_coord = coord
t_dict = turn(coord)
if VERBOSITY:
print("T_DICT:",t_dict)
t = roll_dice(1,20)
if t_dict['direction'] == 'L90':
new_coord = passage_make(coord,xmod=-1,xloop=-1,ywidth=1)
elif t_dict['direction'] == 'R90':
new_coord = passage_make(coord,xmod=1,xloop=1,ywidth=1)
elif t_dict['direction'] == 'L45':
new_coord = passage_make(coord,xmod=-1,xloop=-1,ymod=1,yloop=1,xwidth=1)
elif t_dict['direction'] == 'R45':
new_coord = passage_make(coord,xmod=1,xloop=1,ymod=1,yloop=1,xwidth=1)
elif t_dict['direction'] == 'L135':
new_coord = passage_make(coord,xmod=-1,xloop=-1,ymod=-1,yloop=-1,xwidth=1)
else: #t_dict['direction'] == 'R135'
new_coord = passage_make(coord,xmod=1,xloop=1,ymod=-1,yloop=-1,xwidth=1)
elif pc_dict['direction'] == 'room':
'''
lr = roll_dict(1,2)
shape_dict['size'] = [2,2]
shape_dict['size'] = [4,4]
shape_dict['size'] = [1,2]
shape_dict['size'] = [2,4]
shape_dict['size'] = [4,6]
shape_dict['size'] = [3,4]
others
shape_dict['size'] = [1,1]
shape_dict['size'] = [3,3]
shape_dict['size'] = [2,3]
shape_dict['size'] = [2,3]
shape_dict['size'] = [3,5]
shape_dict = fancy_shape()
'''
#want those we randomly position lr
new_coord = coord
shape_dict = room(coord, room_stack) #if another room pass not C="R"
#room_stack = shape_dict['room_stack']
#each room part check for inside
if VERBOSITY:
print("ROOM SHAPE:",shape_dict)
rm = room_make(shape_dict, coord)
if rm == "GOOD":
secret_doors(shape_dict)
elif pc_dict['direction'] == 'level':
new_coord = coord
level_dict = level(coord)
new_coord = level_dict['new_coord']
level_stack[new_coord] = level_dict
if VERBOSITY:
print("LEVEL:",level_dict)
if level_dict['check'] > 0:
#go ahead 3 on check 3
for y in range(level_dict['check']):
will_fit = in_dungeon((coord[0],coord[1]+1+y,coord[2]))
if not will_fit:
dungeon[(coord[0],coord[1]+1+y,coord[2])] = {}
dungeon[(coord[0],coord[1]+1+y,coord[2])]['fill'] = 'C'
new_coord = (coord[0],coord[1]+1+y,coord[2])
else:
break
if level_dict['room'] == 'Y':
#do room check
shape_dict = room(coord, room_stack) #if another room pass not C="R"
if VERBOSITY:
print("ROOM SHAPE:",shape_dict)
rm = room_make(shape_dict, coord)
if rm == "GOOD":
secret_doors(shape_dict)
return new_coord
elif pc_dict['direction'] == 'stop':
new_coord = coord
check_coord_L = (new_coord[0]-1,new_coord[1],new_coord[2])
check_coord_R = (new_coord[0]+1,new_coord[1],new_coord[2])
check_coord_A = (new_coord[0],new_coord[1]+1,new_coord[2])
dead_end = True
dead_end_count = 0
if check_coord_L not in dungeon:
## need to check if in dungeons where putting Ds
e_dict_f = fancy_exit(coord)
if 'S' in e_dict_f:
e_dict = {}
e_dict['direction'] = 'L'
e_dict['coord'] = (coord[0]-1,coord[1],coord[2])
e_dict['type'] = e_dict_f['type']
exit_stack[coord] = e_dict
dead_end = False
if check_coord_R not in dungeon:
## need to check if in dungeons where putting Ds
e_dict_f = fancy_exit(coord)
if 'S' in e_dict_f:
e_dict = {}
e_dict['direction'] = 'R'
e_dict['coord'] = (coord[0]+1,coord[1],coord[2])
e_dict['type'] = e_dict_f['type']
exit_stack[coord] = e_dict
dead_end = False
if check_coord_A not in dungeon:
## need to check if in dungeons where putting Ds and handle can't go through dead ends
e_dict_f = fancy_exit(coord)
if 'S' in e_dict_f:
e_dict = {}
e_dict['direction'] = 'R'
e_dict['coord'] = (coord[0],coord[1]+1,coord[2])
e_dict['type'] = e_dict_f['type']
exit_stack[coord] = e_dict
dead_end = False
#this will also need checking for facing etc.
if dead_end == True:
#need to check for secret doors here
#only in left, right and ahead
#put SD dict in to handle the directions, or a dict that can be read out?
#or make a dead end dict as no rooms here
will_fit = in_dungeon((new_coord[0],new_coord[1]+1,new_coord[2]))
if not will_fit:
dungeon[(new_coord[0],new_coord[1]+1,new_coord[2])] = {}
dungeon[(new_coord[0],new_coord[1]+1,new_coord[2])]['fill'] = 'D'
dead_end_dict[(new_coord[0],new_coord[1]+1,new_coord[2])] = 'ymax'
#dead_end_dict[(new_coord[0],new_coord[1]+1,new_coord[2])] = {}
s = roll_dice(1,20)
if s <= 5:
dungeon[(new_coord[0],new_coord[1]+1,new_coord[2])]['fill'] = 'Dsd'
e_dict = exit((new_coord[0],new_coord[1]+1,new_coord[2]))
exit_direction_full((new_coord[0],new_coord[1]+1,new_coord[2]), e_dict)
will_fit = in_dungeon((new_coord[0]-1,new_coord[1],new_coord[2]))
if not will_fit:
dungeon[(new_coord[0]-1,new_coord[1],new_coord[2])] = {}
dungeon[(new_coord[0]-1,new_coord[1],new_coord[2])]['fill'] = 'D'
dead_end_dict[(new_coord[0]-1,new_coord[1],new_coord[2])] = 'xmin'
s = roll_dice(1,20)
if s <= 5:
dungeon[(new_coord[0]-1,new_coord[1],new_coord[2])]['fill'] = 'Dsd'
e_dict = exit((new_coord[0]-1,new_coord[1],new_coord[2]))
exit_direction_full((new_coord[0]-1,new_coord[1],new_coord[2]), e_dict)
will_fit = in_dungeon((new_coord[0]+1,new_coord[1],new_coord[2]))
if not will_fit:
dungeon[(new_coord[0]+1,new_coord[1],new_coord[2])] = {}
dungeon[(new_coord[0]+1,new_coord[1],new_coord[2])]['fill'] = 'D'
dead_end_dict[(new_coord[0]+1,new_coord[1],new_coord[2])] = 'xmax'
s = roll_dice(1,20)
if s <= 5:
dungeon[(new_coord[0]-1,new_coord[1],new_coord[2])]['fill'] = 'Dsd'
e_dict = exit((new_coord[0]+1,new_coord[1],new_coord[2]))
exit_direction_full((new_coord[0]+1,new_coord[1],new_coord[2]), e_dict)
## add angle parts
will_fit = in_dungeon((new_coord[0]-1,new_coord[1]+1,new_coord[2]))
if not will_fit:
dungeon[(new_coord[0]-1,new_coord[1]+1,new_coord[2])] = {}
dungeon[(new_coord[0]-1,new_coord[1]+1,new_coord[2])]['fill'] = 'D'
will_fit = in_dungeon((new_coord[0]+1,new_coord[1]+1,new_coord[2]))
if not will_fit:
dungeon[(new_coord[0]+1,new_coord[1]+1,new_coord[2])] = {}
dungeon[(new_coord[0]+1,new_coord[1]+1,new_coord[2])]['fill'] = 'D'
#need to retrace to last on exit stack?
if VERBOSITY:
print("DEAD END")
for key in exit_stack:
## this needs to be checked for level
new_coord = key
return new_coord
elif pc_dict['direction'] == 'bad_things':
trap_stack['key_count'] += 1
new_coord = coord
t_dict = bad_things(coord, room_stack)
if VERBOSITY:
print("TRAP:",t_dict)
if 'chute' in t_dict['trap']['type'] or 'elevator' in t_dict['trap']['type']:
level_stack[new_coord] = t_dict
new_coord = t_dict['new_coord']
for x in range(3): #checking again in 3
will_fit = in_dungeon((coord[0],coord[1]+x+1,coord[2]))
if not will_fit:
dungeon[(coord[0],coord[1]+x+1,coord[2])] = {}
dungeon[(coord[0],coord[1]+x+1,coord[2])]['fill'] = 'C'
new_coord = (coord[0],coord[1]+x+1,coord[2])
else:
break
elif pc_dict['direction'] == 'random_encounter':
if VERBOSITY:
print("WANDERING MONSTER")
new_coord = coord
roll_first = random_check()
#"+1 like trap - wm"
result_coord = check_action(roll_first, new_coord, room_stack)
new_coord = result_coord
will_fit = in_dungeon((coord[0],coord[1]+1,coord[2])) #square for monster
if not will_fit:
dungeon[(coord[0],coord[1]+1,coord[2])] = {}
dungeon[(coord[0],coord[1]+1,coord[2])]['fill'] = 'wm'
else:
if VERBOSITY:
print('wm filled up check:',dungeon[(coord[0],coord[1]+1,coord[2])])
#dungeon[(coord[0],coord[1]+1,coord[2])]['fill'] = 'wm' #get this to work
# do fill test to not write over other fills like 'monsters
if 'fill' in dungeon[(coord[0],coord[1]+1,coord[2])]:
dungeon[(coord[0],coord[1]+1,coord[2])]['fill'] = dungeon[(coord[0],coord[1]+1,coord[2])]['fill'] + 'wm' #get this to work'wm' #get this to work
else:
dungeon[(coord[0],coord[1]+1,coord[2])]['fill'] = 'wm'
if VERBOSITY:
print('wm key check',dungeon[(coord[0],coord[1]+1,coord[2])])
wm_coord = (coord[0],coord[1]+1,coord[2])
wandering_monster_stack['key_count'] +=1
wandering_monster_stack[wandering_monster_stack['key_count']] = {}
wandering_monster_stack[wandering_monster_stack['key_count']][wm_coord] = {}
wandering_monster_stack[wandering_monster_stack['key_count']][wm_coord]['level'] = level_matrix(abs(coord[2]))
wandering_monster_stack[wandering_monster_stack['key_count']][wm_coord]['type'] = 'NA'
wandering_monster_stack[wandering_monster_stack['key_count']][wm_coord]['No'] = 0
wandering_monster_stack[wandering_monster_stack['key_count']][wm_coord]['XP'] = 0
try:
wm_dict = monster_tables(wandering_monster_stack[wandering_monster_stack['key_count']][wm_coord]['level'])
wandering_monster_stack[wandering_monster_stack['key_count']][wm_coord]['type'] = wm_dict['name']
wandering_monster_stack[wandering_monster_stack['key_count']][wm_coord]['No'] = wm_dict['no']
#wandering_monster_stack[wandering_monster_stack['key_count']][wm_coord]['wm_dict'] = wm_dict
checkdragon = False
for cd in [r':young',r':sub',r':adult',r':old',r':very',r':ancient','Tiamat','Bahamut',':2-']:
if cd in wandering_monster_stack[wandering_monster_stack['key_count']][wm_coord]['type']:
checkdragon = True
if VERBOSITY:
print("checking dragon", checkdragon)
#wandering_monster_stack[wandering_monster_stack['key_count']][wm_coord]['checkdrg'] = checkdragon
if 'Subtable' not in wandering_monster_stack[wandering_monster_stack['key_count']][wm_coord]['type']:
if not checkdragon:
if VERBOSITY:
print("WM_DATA1st NoSubtable - monster")
#print(all_d)
wm_data = all_d[wm_dict['name'].lower()]
wandering_monster_stack[wandering_monster_stack['key_count']][wm_coord]['XP'] = wm_data['XPtotal']
wandering_monster_stack[wandering_monster_stack['key_count']][wm_coord]['lair'] = wm_data['lair']
wandering_monster_stack[wandering_monster_stack['key_count']][wm_coord]['treasure_individual'] = wm_data['treasure_individual']
wandering_monster_stack[wandering_monster_stack['key_count']][wm_coord]['treasure_lair'] = wm_data['treasure_lair']
if VERBOSITY:
print("WM_DATA",wm_data)
print("WM_DICTNAME",wm_dict['name'])
wandering_monster_subtable.append('monster')
else:
if VERBOSITY:
print(wm_dict)
print("DragonSubtable")
print("DRAGON WM_DICT:",wm_dict)
#type ok above already
wandering_monster_stack[wandering_monster_stack['key_count']][wm_coord]['No'] = int(wm_dict['no'][0])
dname = wm_dict['details']['name'].split(':')[0]
wm_data = dragon_d[dname]
if VERBOSITY:
print("Dragon dname", dname)
print("Dragon WM Data", wm_data)
wandering_monster_stack[wandering_monster_stack['key_count']][wm_coord]['lair'] = wm_data['lair']
wandering_monster_stack[wandering_monster_stack['key_count']][wm_coord]['treasure_individual'] = wm_data['treasure_individual']
wandering_monster_stack[wandering_monster_stack['key_count']][wm_coord]['treasure_lair'] = wm_data['treasure_lair']
wandering_monster_stack[wandering_monster_stack['key_count']][wm_coord]['XP'] = xp_d[wandering_monster_stack[wandering_monster_stack['key_count']][wm_coord]['level']]
if VERBOSITY:
print("DragonSubtableWM:",wandering_monster_stack[wandering_monster_stack['key_count']][wm_coord])
wandering_monster_subtable.append('dragon')
if 'HumanSubtable' in wm_dict['name']:
if VERBOSITY:
print("HumanSubtable from wm")
wandering_monster_stack[wandering_monster_stack['key_count']][wm_coord]['type'] = wm_dict['details'][0]
wandering_monster_stack[wandering_monster_stack['key_count']][wm_coord]['No'] = wm_dict['details'][1]
if 'Character' not in wm_dict['details']:
wm_data = human_d['human-' + wm_dict['details'][0].lower()]
wandering_monster_stack[wandering_monster_stack['key_count']][wm_coord]['XP'] = wm_data['XPtotal']
wandering_monster_stack[wandering_monster_stack['key_count']][wm_coord]['lair'] = wm_data['lair']
wandering_monster_stack[wandering_monster_stack['key_count']][wm_coord]['treasure_individual'] = wm_data['treasure_individual']
wandering_monster_stack[wandering_monster_stack['key_count']][wm_coord]['treasure_lair'] = wm_data['treasure_lair']
if VERBOSITY:
print("WM_DATA",wm_data)
print("human subtable check wmdict details:",wm_dict['details'])
if 'Character' in wm_dict['details']:
if VERBOSITY:
print("HumanSubtable-Character - implementing")
wandering_monster_stack[wandering_monster_stack['key_count']][wm_coord]['type'] = wm_dict['details']
wandering_monster_stack[wandering_monster_stack['key_count']][wm_coord]['No'] = 9
wandering_monster_stack[wandering_monster_stack['key_count']][wm_coord]['lair'] = '0%'
wandering_monster_stack[wandering_monster_stack['key_count']][wm_coord]['treasure_individual'] = [] #have to work out
wandering_monster_stack[wandering_monster_stack['key_count']][wm_coord]['treasure_lair'] = [] #have to work out
#print(wandering_monster_stack[wandering_monster_stack['key_count']][wm_coord])
wandering_monster_subtable.append('human-character')
else:
if VERBOSITY:
print("HumanSubtable-second branch basic human")
print("WM_DATA",wm_data)
print(wandering_monster_stack[wandering_monster_stack['key_count']][wm_coord])
wandering_monster_subtable.append('human')
if VERBOSITY:
print("IN HUMAN")
if 'CharacterSubtable' in wm_dict['name']:
if VERBOSITY:
print("CharacterSubtable") #this works
wandering_monster_stack[wandering_monster_stack['key_count']][wm_coord]['type'] = wm_dict['details']
wandering_monster_stack[wandering_monster_stack['key_count']][wm_coord]['No'] = 9
wandering_monster_stack[wandering_monster_stack['key_count']][wm_coord]['lair'] = '0%'
wandering_monster_stack[wandering_monster_stack['key_count']][wm_coord]['treasure_individual'] = [] #have to work out
wandering_monster_stack[wandering_monster_stack['key_count']][wm_coord]['treasure_lair'] = [] #have to work out
#print("CharacterSubtableWM:", wandering_monster_stack[wandering_monster_stack['key_count']][wm_coord])
wandering_monster_subtable.append('character')
except Exception as wmE:
#bound to be parsing problems in the monster tables until vetted dragons and characters etc.
print("error:",wmE) #log to a file to see a pattern
error_dict[error_dict['key_count']] = wmE
error_dict['type']['key_count'] = "wm roll error for level: " + str(wandering_monster_stack[wandering_monster_stack['key_count']][wm_coord]['level'])
error_dict['key_count'] += 1
return new_coord
#basic above options seem good, now to go through specifics and see what needs adding and finessing
#specific functions
def exit(coord):
'''
note fancy exit for doors on locations already mapped
'''
e_dict = {}
e_dict['type'] = 'N'
d = roll_dice(1,20)
if VERBOSITY:
print("EXIT CHECK",d)
if d <= 6:
e_dict['direction'] = 'L'
will_fit = in_dungeon((coord[0]-1,coord[1],coord[2]))
if not will_fit:
e_dict['coord'] = (coord[0]-1,coord[1],coord[2])
else:
e_dict['coord'] = (coord[0]-1,coord[1],coord[2])
e_dict['type'] = 'S'
elif d>=7 and d <= 12:
e_dict['direction'] = 'R'
will_fit = in_dungeon((coord[0]-1,coord[1],coord[2]))
if not will_fit:
e_dict['coord'] = (coord[0]+1,coord[1],coord[2])
else:
e_dict['coord'] = (coord[0]+1,coord[1],coord[2])
e_dict['type'] = 'S'
else:
e_dict['direction'] = 'A'
will_fit = in_dungeon((coord[0]-1,coord[1],coord[2]))
if not will_fit:
e_dict['coord'] = (coord[0],coord[1]+1,coord[2])
else:
e_dict['coord'] = (coord[0],coord[1]+1,coord[2])
e_dict['type'] = 'S'
b = roll_dice(1,20)
if b <= 4:
e_dict['beyond'] = 'P'
elif b>=5 and b <= 8:
e_dict['beyond'] = 'A'
elif b==9:
e_dict['beyond'] = '4AB'
elif b==10:
e_dict['beyond'] = '4BA'
else:
e_dict['beyond'] = 'Room'
exit_stack[coord] = e_dict
return e_dict
def exit_beyond():
e_dict = {}
b = roll_dice(1,20)
if b <= 4:
e_dict['beyond'] = 'P'
elif b>=5 and b <= 8:
e_dict['beyond'] = 'A'
elif b==9:
e_dict['beyond'] = '45AB'
elif b==10:
e_dict['beyond'] = '45BA'
else:
e_dict['beyond'] = 'Room'
return e_dict
def fancy_exit(coord):
e_dict_f = {}
s = roll_dice(1,20)
if s < 5:
e_dict_f['type'] = 'S'
elif s>=5 and s <= 10:
e_dict_f['type'] = 'OW'
else:
e_dict_f['type'] = 'OPP'
return e_dict_f
def side(coord):
s_dict = {}
s = roll_dice(1,20)
if VERBOSITY:
print("SIDE CHECK",s)
if s <= 2:
s_dict['direction'] = 'L90'
if s >= 3 and s <= 4:
s_dict['direction'] = 'R90'
if s == 5 :
s_dict['direction'] = 'L45'
if s == 6 :
s_dict['direction'] = 'R45'
if s == 7 :
s_dict['direction'] = 'L135'
if s == 8 :
s_dict['direction'] = 'R135'
if s == 9 :
s_dict['direction'] = 'L45'
if s == 10 :
s_dict['direction'] = 'R45'
if s >= 11 and s <= 13:
s_dict['direction'] = 'T'
if s >= 14 and s <= 15:
s_dict['direction'] = 'Y'
if s >= 16 and s <= 19:
s_dict['direction'] = 'P'
if s == 20:
s_dict['direction'] = 'X'
return s_dict
def turn(coord):
t_dict = {}
t = roll_dice(1,20)
if VERBOSITY:
print("TURN CHECK",t)
if t <= 8:
t_dict['direction'] = 'L90'
if t == 9:
t_dict['direction'] = 'L45'
if t == 10 :
t_dict['direction'] = 'L135'
if t >= 11 and t <= 18:
t_dict['direction'] = 'R90'
if t == 19:
t_dict['direction'] = 'R45'
if t == 20:
t_dict['direction'] = 'R135'
return t_dict
def room(coord, room_stack, size="C", content=None ):
'''