-
Notifications
You must be signed in to change notification settings - Fork 1
/
dungeongen_point01.py
1146 lines (1028 loc) · 40.9 KB
/
dungeongen_point01.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
#Dungeon Generator v0.03
# Chris Pack
# Creates a dungeon of between 5 and 100 rooms for a party of level 1-20.
# Based on the dungeon generator in the AD&D DMG by Gary Gygax
#=====================================================
from Tkinter import *
import random
import tkMessageBox
from Pmw import initialise, Balloon
dungeon = []
rooms_in_dungeon = 0#so now I can add x rooms to a dungeon and then know to stop
pixels_per_square = 48
def draw_door(acanvas,adoor):
point1x,point1y = adoor.get_coordinates()
point1x *= pixels_per_square
point1y *= pixels_per_square
point2x = point1x
point2y = point1y
facing = adoor.direction
if adoor.printme == 1:
if facing == "east":
point1x += .75 * pixels_per_square
point1y += .25 * pixels_per_square
point2x += 1 * pixels_per_square
point2y += .75 * pixels_per_square
elif facing == "south":
point1x += .25 * pixels_per_square
point1y += .75 * pixels_per_square
point2x += .75 * pixels_per_square
point2y += 1 * pixels_per_square
elif facing == "west":
point1x += 0 * pixels_per_square
point1y += .25 * pixels_per_square
point2x += .25 * pixels_per_square
point2y += .75 * pixels_per_square
elif facing == "north":
point1x += .25 * pixels_per_square
point1y += 0 * pixels_per_square
point2x += .75 * pixels_per_square
point2y += .25 * pixels_per_square
else:
pass
#print "You cannot face Dennis!"
acanvas.create_rectangle(point1x, point1y, point2x, point2y, fill="brown")
def create_a_room(number):
temprand = random.randint(1,number)
if temprand == 10:
return 8, 12
elif temprand == 9:
return 8, 8
elif temprand == 8:
return 6,8
elif temprand == 7:
return 8,6
elif temprand == 6:
return 6,6
elif temprand == 5:
return 4,4
elif temprand == 4:
return 2,4
elif temprand == 3:
return 4,2
elif temprand == 2:
return 2,2
elif temprand == 1:
return 1,3
def find_a_room(dungeon_list):
for room in dungeon_list:
if room.room_type == "room" or room.room_type == "hall":
if room.doors_finished == False:
room.doors_finished = True
return True, room
else:
pass
#print "room ", room, " is done."
#print "No unfinished rooms in dungeon"
return False, room
def fill_a_room(empty_room):
random_number = 3#guaranteed by fair die roll to be random #number of doors to add
roomx,roomy = empty_room.get_coordinates()
roomwide,roomtall = empty_room.get_size()
#two parts:
#====================================================
#Fill-a-Room part 1: insert number of doors into room
#====================================================
for doors_to_add in range (0, random_number):
tempdoorin = Feature()
tempdoorout = Feature()
templocx = 1
templocy = 1
templocx2 = 1
templocy2 = 1
tempfacing = "east"#if facing = east, new second door facing "west"
tempfacing2 = "east"
temptype = "door"
stilltrying = True
sidestried = 0
#if there is no door in locxy place door
#if there is a door in xy, move to next wall
while stilltrying and (sidestried < 4):
if tempfacing == "east":
templocx = roomx + roomwide -1
templocy = roomy + roomtall/2
tempfacing2 = "west"
templocx2 = templocx + 1
templocy2 = templocy
if tempfacing == "south":
templocx = roomx + roomwide/2
templocy = roomy + roomtall - 1
tempfacing2 = "north"
templocx2 = templocx
templocy2 = templocy + 1
if tempfacing == "west":
templocx = roomx
templocy = roomy + roomtall/2
tempfacing2 = "east"
templocx2 = templocx - 1
templocy2 = templocy
if tempfacing == "north":
templocx = roomx + roomwide/2
templocy = roomy
tempfacing2 = "south"
templocx2 = templocx
templocy2 = templocy - 1
#make sure there isn't enother door in this spot already
for each_door in dungeon:
if each_door.feat_type == "door":
if each_door.are_you_in_this_square((templocx,templocy)):
tempdoorin.door_is_legal = 0
#here I switch the door wall and try another
if tempdoorin.door_is_legal == 1:
#print "this door is legal"
tempdoorin.set_coordinates(templocx,templocy)
tempdoorin.set_direction(tempfacing)
tempdoorin.feat_type = temptype
empty_room.add_door(tempdoorin)#create door
tempdoorout.set_coordinates(templocx2,templocy2)
tempdoorout.set_direction(tempfacing2)
tempdoorout.feat_type = temptype
#tempdoorout.printme = 0
dungeon.append(tempdoorout)#create shadow door
tempdoorin.partnerdoor = tempdoorout
tempdoorout.partnerdoor = tempdoorin
stilltrying = False
else:
if tempfacing == "east":
tempfacing = "south"
elif tempfacing == "south":
tempfacing = "west"
elif tempfacing == "west":
tempfacing = "north"
elif tempfacing == "north":
tempfacing = "east"
sidestried +=1
tempdoorin.door_is_legal = 1
#print "end of doors loop, restarting"
if sidestried >3:
pass
#print "tried all the times and couldn't place another door"
#====================================================
#Fill-a-Room part 2: insert rooms onto doors
#====================================================
if empty_room.num_of_doors == 0:
pass
#print "no doors in this room"
#ERROR this should never happen
for this_door in empty_room.doors:
temp_room = Room()
temp_loc_x = 0
temp_loc_y = 0
temp_size_x = 3
temp_size_y = 3
temp_type = "room"
temp_door_facing = this_door.get_direction()
randkey = 0
randkey = random.randint(1,10)
while randkey > 0:
temp_size_x, temp_size_y = create_a_room(randkey)
if temp_size_x == 1:
temp_type = "hall"
if temp_door_facing == "east" or temp_door_facing == "west":
temp_size_x = 3
temp_size_y = 1
if temp_door_facing == "north":
temp_loc_x = this_door.x_coordinate - (temp_size_x/2)
temp_loc_y = this_door.y_coordinate - temp_size_y
if temp_door_facing == "south":
temp_loc_x = this_door.x_coordinate - (temp_size_x/2)
temp_loc_y = this_door.y_coordinate
temp_loc_y = temp_loc_y + 1
if temp_door_facing == "east":
temp_loc_x = this_door.x_coordinate
temp_loc_x = temp_loc_x + 1
temp_loc_y = this_door.y_coordinate - (temp_size_y/2)
if temp_door_facing == "west":
temp_loc_x = this_door.x_coordinate - temp_size_x
temp_loc_y = this_door.y_coordinate - (temp_size_y/2)
#new room location x and Y now determined, now look for conflicts.
temp_room.set_coordinates(temp_loc_x, temp_loc_y)
temp_room.set_size(temp_size_x,temp_size_y)
temp_room.set_type(temp_type)
temp_room.get_my_coordinates_list()
#====================================================================
for each_room in dungeon:
if each_room.room_type == "room" or each_room.room_type == "hall":
for room_coordinates in range (0, len(each_room.my_coordinates)):
if temp_room.are_you_in_this_square(each_room.my_coordinates[room_coordinates]):
temp_room.room_is_legal = 0
#====================================================================
if temp_room.room_is_legal == 1:
temp_room.add_room()#win
#print "this room is legal"
randkey = 1
this_door.printme = 1
this_door.partnerdoor.printme = 1
#stilltrying = False
else:
this_door.printme = 0
this_door.partnerdoor.printme = 0
#flag this door and it's shadow door DO NOT PRINT
temp_room.room_is_legal = 1
#===========================================================
randkey -= 1
def get_monster(cr):
crmin = cr - 1
crmax = cr + 1
temprand = random.randint(crmin, crmax)
if temprand == 0:
monsterrand = random.randint(1, 14)
#return "Level 0 monster"
if monsterrand == 1:
return "CR 1/8 Bat, p. 131"
elif monsterrand == 2:
return "CR 1/4 Kobold, p.183"
elif monsterrand == 3:
return "CR 1/4 Rat, p. 132"
elif monsterrand == 4:
return "CR 1/4 Mite, p. 207"
elif monsterrand == 5:
return "CR 1/3 Dire Rat, p. 232"
elif monsterrand == 6:
return "Cr 1/3 Duergar, p. 117"
elif monsterrand == 7:
return "CR 1/3 Fire Beetle, p. 33"
elif monsterrand == 8:
return "CR 1/3 Goblin, p. 156"
elif monsterrand == 9:
return "CR 1/3 Orc, p. 222"
elif monsterrand == 10:
return "Cr 1/3 Skeleton, Human, p. 250"
elif monsterrand == 11:
return "CR 1/2 Giant Centipede, p. 43"
elif monsterrand == 12:
return "CR 1/2 Hobgoblin, p. 175"
elif monsterrand == 13:
return "CR 1/2 Stirge, p. 260"
elif monsterrand == 14:
return "CR 1/2 Vegepygmy, p. 273"
elif monsterrand == 15:
return "CR 1/2 Zombie, Human, p. 288"
else:
return "CR 1/4 Kobold, p.183"
elif temprand == 1:
#return "Level 1 monster"
monsterrand = random.randint(1, 11)
if monsterrand == 1:
return "CR 1 Darkmantle, p. 55"
elif monsterrand == 2:
return "CR 1 Earth Elemental, small, p. 122"
elif monsterrand == 3:
return "CR 1 Ghoul, p. 146"
elif monsterrand == 4:
return "CR 1 Giant Spider, p. 258"
elif monsterrand == 5:
return "CR 1 Gnoll, p. 155"
elif monsterrand == 6:
return "Cr 1 Goblin Dog, p. 157"
elif monsterrand == 7:
return "CR 1 Spider Swarm, p. 258"
elif monsterrand == 8:
return "CR 1 Troglodyte, p. 267"
elif monsterrand == 9:
return "CR 1 Kobolds (2), p. 183"
elif monsterrand == 10:
return "Cr 1 Dire Rats (2), p. 232"
elif monsterrand == 11:
return "CR 1 Drow (2), p. 114"
else:
return "CR 1/4 Kobold, p.183"
elif temprand == 2:
#return "Level 2 monster"
monsterrand = random.randint(1, 17)
if monsterrand == 1:
return "CR 2 Giant Ant, p. 16"
elif monsterrand == 2:
return "CR 2 Dire Bat, p. 30"
elif monsterrand == 3:
return "CR 2 Bat Swarm, p. 30"
elif monsterrand == 4:
return "CR 2 Bugbear, p. 38"
elif monsterrand == 5:
return "CR 2 Cave Fisher, p. 41"
elif monsterrand == 6:
return "CR 2 Choker, p. 45"
elif monsterrand == 7:
return "CR 2 Dark Creeper, p. 53"
elif monsterrand == 8:
return "CR 2 Demon, Dretch, p. 60"
elif monsterrand == 9:
return "CR 2 Demon, Quast, p. 66"
elif monsterrand == 10:
return "CR 2 Iron Cobra, p. 182"
elif monsterrand == 11:
return "CR 2 Wererat, p. 197"
elif monsterrand == 12:
return "CR 2 Werewolf, p. 198"
elif monsterrand == 13:
return "CR 2 Morlock, p. 209"
elif monsterrand == 14:
return "CR 2 Rat Swarm, p. 232"
elif monsterrand == 15:
return "CR 2 Skeletal Champion, p. 252"
elif monsterrand == 16:
return "CR 2 Vargoville, p. 272"
elif monsterrand == 17:
return "CR 2 Kobolds (3), p. 183"
else:
return "CR 1/4 Kobold, p.183"
elif temprand == 3:
#return "Level 3 monster"
monsterrand = random.randint(1, 14)
if monsterrand == 1:
return "CR 3 Medium Animated Object, p. 14"
elif monsterrand == 2:
return "CR 3 Derro, p. 70"
elif monsterrand == 3:
return "CR 3 Drow Noble, p. 115"
elif monsterrand == 4:
return "CR 3 Medium Earth Elemental, p. 122"
elif monsterrand == 5:
return "CR 3 Gelatinous Cube, p. 138"
elif monsterrand == 6:
return "Cr 3 Hell Hound, p. 173"
elif monsterrand == 7:
return "CR 3 Ogre, p. 220"
elif monsterrand == 8:
return "CR 3 Rust Monster, p. 238"
elif monsterrand == 9:
return "CR 3 Shadow, p. 245"
elif monsterrand == 10:
return "Cr 3 Violet Fungus, p. 274"
elif monsterrand == 11:
return "CR 3 Wight, p. 276"
elif monsterrand == 12:
return "CR 3 Yeth Hound, p. 286"
elif monsterrand == 13:
return "CR 3 Kobolds (4), p. 183"
elif monsterrand == 14:
return "CR 3 Dire Rat + 2 Rat Swarms, p. 232"
else:
return "CR 1/4 Kobold, p.183"
elif temprand == 4:
#return "Level 4 monster"
monsterrand = random.randint(1, 12)
if monsterrand == 1:
return "CR 4 Hound, Archon, p.19"
elif monsterrand == 2:
return "CR 4 Barghest, p. 27"
elif monsterrand == 3:
return "CR 4 Beetle, Giant Stag, p. 33"
elif monsterrand == 4:
return "CR 4 Centipede Swarm, p. 43"
elif monsterrand == 5:
return "CR 4 Dark Stalker, p. 54"
elif monsterrand == 6:
return "Cr 4 Gargoyle, p. 137"
elif monsterrand == 7:
return "CR 4 Hydra, p. 178"
elif monsterrand == 8:
return "CR 4 Mimic, p. 205"
elif monsterrand == 9:
return "CR 4 Minotaur, p. 206"
elif monsterrand == 10:
return "Cr 4 Otyugh, p. 223"
elif monsterrand == 11:
return "CR 4 Kobolds (5), p. 183"
elif monsterrand == 12:
return "CR 4 Dire Rats (2) + Rat Swarm, p. 232"
else:
return "CR 1/4 Kobold, p.183"
elif temprand == 5:
#return "Level 5 monster"
monsterrand = random.randint(1, 16)
if monsterrand == 1:
return "CR 5 Army Ant Swarm, p. 16"
elif monsterrand == 2:
return "CR 5 Basidirond, p. 28"
elif monsterrand == 3:
return "CR 5 Basilisk, p. 29"
elif monsterrand == 4:
return "CR 5 Cloaker, p. 47"
elif monsterrand == 5:
return "CR 5 Cyclops, p. 52"
elif monsterrand == 6:
return "CR 5 Large Earth Elemental, p. 122"
elif monsterrand == 7:
return "CR 5 Gibbering Mouther, p. 153"
elif monsterrand == 8:
return "CR 5 Manticore, p. 199"
elif monsterrand == 9:
return "CR 5 Mummy, p. 210"
elif monsterrand == 10:
return "CR 5 Ochre Jelly, p. 218"
elif monsterrand == 11:
return "CR 5 Phase Spider, p. 226"
elif monsterrand == 12:
return "CR 5 Troll, p. 268"
elif monsterrand == 13:
return "CR 5 Wraith, p. 281"
elif monsterrand == 14:
return "CR 5 Dire Rat (4) + 2 Rat Swarms, p. 232"
elif monsterrand == 15:
return "CR 5 Rust Monster (2), p. 238"
elif monsterrand == 16:
return "CR 5 Kobolds (6), p. 183"
else:
return "CR 1/4 Kobold, p.183"
elif temprand == 6:
#return "Level 6 monster"
monsterrand = random.randint(1, 10)
if monsterrand == 1:
return "CR 6 Demon, Babau, p. 57"
elif monsterrand == 2:
return "CR 6 Wood Golem, p. 164"
elif monsterrand == 3:
return "CR 6 Half-Fiend Minotaur, p. 171"
elif monsterrand == 4:
return "CR 6 Lamia, p. 186"
elif monsterrand == 5:
return "CR 6 Salamander, p. 240"
elif monsterrand == 6:
return "CR 6 Xill, p. 283"
elif monsterrand == 7:
return "CR 6 Xorn, p. 284"
elif monsterrand == 8:
return "CR 6 Drow Noble + 4 Drow, p. 114"
elif monsterrand == 9:
return "CR 6 Ogre (3), p. 220"
elif monsterrand == 10:
return "CR 6 Kobolds (8), p. 183"
else:
return "CR 1/4 Kobold, p.183"
elif temprand == 7:
#return "Level 7 monster"
monsterrand = random.randint(1, 10)
if monsterrand == 1:
return "CR 7 Black Pudding, p. 35"
elif monsterrand == 2:
return "CR 7 Demon, Shadow, p. 67"
elif monsterrand == 3:
return "CR 7 Black Dragon, young, p. 92"
elif monsterrand == 4:
return "CR 7 Drider, p. 113"
elif monsterrand == 5:
return "CR 7 Huge Earth Elemental, p. 122"
elif monsterrand == 6:
return "CR 7 Ghost, p. 144"
elif monsterrand == 7:
return "CR 7 Flesh Golem, p. 160"
elif monsterrand == 8:
return "CR 7 Spectre, p. 256"
elif monsterrand == 9:
return "CR 7 Ochre Jelly (3), p. 218"
elif monsterrand == 10:
return "CR 7 Kobolds (12), p. 183"
else:
return "CR 1/4 Kobold, p.183"
elif temprand == 8:
#return "Level 8 monster"
monsterrand = random.randint(1, 9)
if monsterrand == 1:
return "CR 8 Demon, Mabasu, p. 64"
elif monsterrand == 2:
return "CR 8 Intellect Devourer, p. 180"
elif monsterrand == 3:
return "CR 8 Green Dragon, young, p. 96"
elif monsterrand == 4:
return "CR 8 Mohrg, p. 180"
elif monsterrand == 5:
return "CR 8 Dark Naga, p. 211"
elif monsterrand == 6:
return "CR 8 Oni, Ogre Mage, p. 221"
elif monsterrand == 7:
return "CR 8 Greater Shadow, p. 245"
elif monsterrand == 8:
return "CR 8 Drow Noble + 8 Drow, p. 114"
elif monsterrand == 9:
return "CR 8 Kobolds (16), p. 183"
else:
return "CR 1/4 Kobold, p.183"
elif temprand == 9:
#return "Level 9 monster"
monsterrand = random.randint(1, 8)
if monsterrand == 1:
return "CR 9 Demon, Urock, p. 67"
elif monsterrand == 2:
return "CR 9 Greater Earth Elemental, p. 123"
elif monsterrand == 3:
return "CR 9 Nessian Hell Hound, p. 173"
elif monsterrand == 4:
return "CR 9 Spirit Naga, p. 213"
elif monsterrand == 5:
return "CR 9 Vampire, p. 270"
elif monsterrand == 6:
return "CR 9 Black Pudding (2), p. 35"
elif monsterrand == 7:
return "CR 9 Drider (2), p. 113"
elif monsterrand == 8:
return "CR 9 Flesh Golem (2), p. 160"
else:
return "CR 1/4 Kobold, p.183"
elif temprand == 10:
#return "Level 10 monster"
monsterrand = random.randint(1, 6)
if monsterrand == 1:
return "CR 10 Bebilith, p. 32"
elif monsterrand == 2:
return "CR 10 Devourer, p. 82"
elif monsterrand == 3:
return "CR 10 Red Dragon, young, p. 98"
elif monsterrand == 4:
return "CR 10 Clay Golem, p. 159"
elif monsterrand == 5:
return "CR 10 Greater Shadow (2), p. 245"
elif monsterrand == 6:
return "CR 10 Black Pudding (3), p. 35"
else:
return "CR 1/4 Kobold, p.183"
elif temprand == 11:
#return "Level 11 monster"
monsterrand = random.randint(1, 5)
if monsterrand == 1:
return "CR 11 Black Dragon, adult, p. 82"
elif monsterrand == 2:
return "CR 11 Elder Earth Elemental, p. 123"
elif monsterrand == 3:
return "CR 11 Stone Golem, p. 163"
elif monsterrand == 4:
return "CR 11 Retriever, p. 234"
elif monsterrand == 5:
return "CR 11 Vampire (2), p. 270"
else:
return "CR 1/4 Kobold, p.183"
elif temprand == 12:
#return "Level 12 monster"
monsterrand = random.randint(1, 6)
if monsterrand == 1:
return "CR 12 Green Dragon, adult, p. 96"
elif monsterrand == 2:
return "CR 12 Lich, p. 188"
elif monsterrand == 3:
return "CR 12 Purple Worm, p. 230"
elif monsterrand == 4:
return "CR 12 Clay Golem (2), p. 159"
elif monsterrand == 5:
return "CR 12 Bebilith (2), p. 32"
elif monsterrand == 6:
return "CR 12 Roper, p. 237"
else:
return "CR 1/4 Kobold, p.183"
elif temprand == 13:
#return "Level 13 monster"
monsterrand = random.randint(1, 5)
if monsterrand == 1:
return "CR 13 Demon, Glabrezu, p. 61"
elif monsterrand == 2:
return "CR 13 Elder Earth Elemental (2), p. 123"
elif monsterrand == 3:
return "CR 13 Stone Golem (2), p. 163"
elif monsterrand == 4:
return "CR 13 Iron Golem, p. 162"
elif monsterrand == 5:
return "CR 13 Regriever (2), p. 234"
else:
return "CR 1/4 Kobold, p.183"
elif temprand == 14:
#return "Level 14 monster"
monsterrand = random.randint(1, 5)
if monsterrand == 1:
return "CR 14 Demon, Nalfeshnee, p. 65"
elif monsterrand == 2:
return "CR 14 Red Dragon, adult, p. 98"
elif monsterrand == 3:
return "CR 14 Crag Linnorm, p. 190"
elif monsterrand == 4:
return "CR 14 Lich (2) + 2 Zombies, Human, p. 188, 288"
elif monsterrand == 5:
return "CR 14 Stone Golem (3), p. 163"
else:
return "CR 1/4 Kobold, p.183"
elif temprand == 15:
#return "Level 15 monster"
monsterrand = random.randint(1, 3)
if monsterrand == 1:
return "CR 15 Red Dragon, adult + Red Dragon, young, p. 82"
elif monsterrand == 2:
return "CR 15 Neothelid, p. 214"
elif monsterrand == 3:
return "CR 15 Iron Golem (2), p. 162"
else:
return "CR 1/4 Kobold, p.183"
elif temprand == 16:
#return "Level 16 monster"
monsterrand = random.randint(1, 6)
if monsterrand == 1:
return "CR 16 Black Dragon, Ancient, p. 93"
elif monsterrand == 2:
return "CR 16 Iron Golem (3), p. 162"
elif monsterrand == 3:
return "CR 16 Demon, Nalfeshnee (2), p. 65"
elif monsterrand == 4:
return "CR 16 Red Dragon, adult (2), p. 98"
elif monsterrand == 5:
return "CR 16 Crag Linnorm (2), p. 190"
elif monsterrand == 6:
return "CR 16 Lich (4) + 6 Zombies, Human, p. 188, 288"
else:
return "CR 1/4 Kobold, p.183"
elif temprand == 17:
#return "Level 17 monster"
monsterrand = random.randint(1, 3)
if monsterrand == 1:
return "CR 17 Demon, Marilith, p. 63"
elif monsterrand == 2:
return "CR 17 Green Dragon, Ancient, p. 97"
elif monsterrand == 3:
return "CR 17 Iron Golem (4), p. 162"
else:
return "CR 1/4 Kobold, p.183"
elif temprand == 18:
#return "Level 18 monster"
monsterrand = random.randint(1, 3)
if monsterrand == 1:
return "CR 18 Neothelid (2), p. 214"
elif monsterrand == 2:
return "CR 18 Black Dragon, Ancient (2), p. 97"
elif monsterrand == 3:
return "CR 18 Iron Golem (5), p. 162"
else:
return "CR 1/4 Kobold, p.183"
elif temprand == 19:
#return "Level 19 monster"
monsterrand = random.randint(1, 3)
if monsterrand == 1:
return "CR 19 Green Dragon, Ancient (2), p. 97"
elif monsterrand == 2:
return "CR 19 Red Dragon, Ancient, p. 99"
elif monsterrand == 3:
return "CR 19 Demon, Marilith (2), p. 63"
else:
return "CR 1/4 Kobold, p.183"
elif temprand == 20:
#return "Level 20 monster"
monsterrand = random.randint(1, 2)
if monsterrand == 1:
return "CR 20 Demon, Balor, p. 58"
elif monsterrand == 2:
return "CR 20 Demon, Marilith (3), p. 63"
else:
return "CR 1/4 Kobold, p.183"
elif temprand == 21:
#return "Level 21 monster"
monsterrand = random.randint(1, 3)
if monsterrand == 1:
return "CR 20 Demon, Balor (2), p. 58"
elif monsterrand == 2:
return "CR 19 Red Dragon, Ancient (2), p. 99"
elif monsterrand == 3:
return "CR 25 Tarrasque"
else:
return "CR 1/4 Kobold, p.183"
else:
return "Dread Gazebo"#it is too late. You have angered the gazebo.
class Room:
#room_type: room, hall, stairs? grand hall? chamber?
def __init__(self):
self.room_type = 0
self.feat_type = 0
self.x_coordinate = 0
self.y_coordinate = 0
self.x_size = 0
self.y_size = 0
self.num_of_doors = 0
self.doors = []
self.doors_finished = False
self.my_coordinates = []
self.room_is_legal = 1
def __str__(self):
return "room("+ ", ".join([str(self.x_coordinate), str(self.y_coordinate), str(self.x_size), str(self.y_size)])+ ")"
def get_my_coordinates_list(self):
for width in range(0, self.x_size):
for height in range(0, self.y_size):
tempx = width + self.x_coordinate
tempy = height + self.y_coordinate
self.my_coordinates.append((tempx,tempy))
def set_coordinates(self, x, y):
self.x_coordinate = x
self.y_coordinate = y
def set_size(self, x, y):
self.x_size = x
self.y_size = y
def set_type(self, roomtype):
self.room_type = roomtype
def get_coordinates(self):
return self.x_coordinate, self.y_coordinate
def get_size(self):
return self.x_size, self.y_size
def are_you_in_this_square(self, (x, y)):
tempxsize = self.x_size
tempxstart = self.x_coordinate
tempxfinish = tempxstart + tempxsize -1
tempysize = self.y_size
tempystart = self.y_coordinate
tempyfinish = tempystart + tempysize -1
if (((x >= tempxstart) and (x <= tempxfinish)) and ((y>= tempystart) and (y<= tempyfinish))):
return True#the coordinate passed in is in the room's range
else:
return False
def add_door(self,door):
dungeon.append(door)
self.doors.append(door)
self.num_of_doors = len(self.doors)
def get_doors(self):
return self.num_of_doors
def add_room(self):
dungeon.append(self)
global rooms_in_dungeon
if self.room_type == "room":#only count "rooms" for the purpose of dungeon size. halls are boring.
rooms_in_dungeon += 1
self.get_my_coordinates_list()
class Feature:
#feat_type: door, monster, stairs, trap, treasure
def __init__(self):
self.my_room = 0
self.room_type = 0
self.feat_type = 0
self.x_coordinate = 0
self.y_coordinate = 0
self.x_size = 1
self.y_size = 1
self.direction = "north" #exits are north,south,and dennis
self.door_is_legal = 1
self.printme = 1
self.partnerdoor = 0
self.monsterdata = ""
def __str__(self):
return "door("+ ", ".join([str(self.x_coordinate), str(self.y_coordinate), str(self.x_size), str(self.y_size)])+ ")"
def set_size(self, x, y):
self.x_size = x
self.y_size = y
def set_coordinates(self, x, y):
self.x_coordinate = x
self.y_coordinate = y
def get_coordinates(self):
return self.x_coordinate, self.y_coordinate
def get_type(self):
return self.feat_type
def get_direction(self):
return self.direction
def set_direction(self, newdirection):
self.direction = newdirection
#def place_door(self, wallsize):
#pass
def are_you_in_this_square(self, (x, y)):
tempx = self.x_coordinate
tempy = self.y_coordinate
if (x == tempx and y == tempy):
return True#the coordinate passed in is in the door's range
else:
return False
#def is_door(self,x, y):#arguments: theoretical door x/y
#pass
#=================================================
#----- main program start
#=================================================
def make_a_dungeon(rooms, rating, dungeon):
#create static starting room
entry = Room()
entry.set_coordinates(5, 5)
entry.set_size(3,5)
entry.set_type("room")
entry.add_room()
entry.doors_finished = True
#doors out of room
door1_1 = Feature()
door1_1.feat_type = "door"
door1_1.set_direction("east")
door1_1.set_coordinates(7,7)
door1_2 = Feature()
door1_2.feat_type = "door"
door1_2.set_direction("south")
door1_2.set_coordinates(6,9)
door1_3 = Feature()
door1_3.feat_type = "door"
door1_3.set_direction("west")
door1_3.set_coordinates(5,7)
door1_4 = Feature()
door1_4.feat_type = "door"
door1_4.set_direction("north")
door1_4.set_coordinates(6,5)
entry.add_door(door1_1)
entry.add_door(door1_2)
entry.add_door(door1_3)
entry.add_door(door1_4)
#doors into next room
door2_1 = Feature()
door2_1.feat_type = "door"
door2_1.set_direction("west")
door2_1.set_coordinates(8,7)
door2_2 = Feature()
door2_2.feat_type = "door"
door2_2.set_direction("north")
door2_2.set_coordinates(6,10)
door2_3 = Feature()
door2_3.feat_type = "door"
door2_3.set_direction("east")
door2_3.set_coordinates(4,7)
door2_4 = Feature()
door2_4.feat_type = "door"
door2_4.set_direction("south")
door2_4.set_coordinates(6,4)
dungeon.append(door2_1)#we don't add shadow doors
dungeon.append(door2_2)
dungeon.append(door2_3)
dungeon.append(door2_4)
for this_door in entry.doors:
temp_room = Room()
temp_loc_x = 0
temp_loc_y = 0
temp_size_x = 3
temp_size_y = 3
temp_type = "room"
temp_door_facing = this_door.get_direction()
if temp_door_facing == "north":
temp_loc_x = this_door.x_coordinate - (temp_size_x/2)
temp_loc_y = this_door.y_coordinate - temp_size_y
if temp_door_facing == "south":
temp_loc_x = this_door.x_coordinate - (temp_size_x/2)
temp_loc_y = this_door.y_coordinate
temp_loc_y = temp_loc_y + 1
if temp_door_facing == "east":
temp_loc_x = this_door.x_coordinate
temp_loc_x = temp_loc_x + 1
temp_loc_y = this_door.y_coordinate - (temp_size_y/2)
if temp_door_facing == "west":
temp_loc_x = this_door.x_coordinate - temp_size_x
temp_loc_y = this_door.y_coordinate - (temp_size_y/2)
temp_room.set_coordinates(temp_loc_x,temp_loc_y)
temp_room.set_size(temp_size_x,temp_size_y)
temp_room.room_type = temp_type
temp_room.add_room()
#======================================================================
#------------------------ Main loop -----------------------
#======================================================================
while rooms_in_dungeon < rooms:
ohdeargod = True
ohdeargod, current_room = find_a_room(dungeon)
if ohdeargod == False:
#no rooms left to add doors to, and not enough rooms in dungeon
break#this shouldn't happen
#current_room is now set to the first room in the dungeon list without doors
fill_a_room(current_room)
#print "end of dungeon building loop, max rooms reached" #done with the whole thing.
#manually add stairs to the first room
tempfeature = Feature()
tempfeature.feat_type = "stairs"
tempfeature.set_coordinates(6,7)
dungeon.append(tempfeature)
#populate the dungeon with level appropriate encounters
for each_room in dungeon:
evil = 0
monster = 0
if each_room.room_type == "room":
evil = random.randint(0,1)#50/50 chance of a monster in a room
if evil == 1:
tempfeature = Feature()
tempfeature.feat_type = "monster"
tempfeature.monsterdata = get_monster(rating)
tempx, tempy = each_room.get_coordinates()
tempfeature.set_coordinates(tempx + 1, tempy + 1)
dungeon.append(tempfeature)
return dungeon
#=======================================================================
#------------------------ Display loop ------------------------
#=======================================================================
def generatedungeon(rooms, cr):
global rooms_in_dungeon
global dungeon
rooms_in_dungeon = 0
dungeon = []
make_a_dungeon(int(rooms), int(cr), dungeon)
draw_everything(tehcanvas, dungeon)