forked from orphu/mcdungeon
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathruins.py
3004 lines (2801 loc) · 125 KB
/
ruins.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
from copy import copy
import inspect
import math
import random
import sys
import cave_factory
import cfg
import items
import materials
import perlin
from pymclevel import nbt
from utils import (
findChunkDepths,
get_entity_mob_tags,
get_entity_other_tags,
get_entity_item_tags,
iterate_cube,
iterate_cylinder,
iterate_disc,
iterate_ellipse,
iterate_four_walls,
iterate_spiral,
iterate_tube,
Vec,
Vec2f,
weighted_choice,
)
_desert_biomes = (2, 17, 130)
_ice_biomes = (140, 12)
_mesa_biomes = (37, 38, 39, 165, 166, 167)
_swamp_jungle_biomes = (6, 21, 22, 23, 149, 151)
class Blank(object):
_name = 'blank'
_dnamesA = (
('', 10),
('Abysmal ', 10),
('Accursed ', 10),
('Ancient ', 10),
('Bitter ', 10),
('Black ', 10),
('Bleak ', 10),
('Brutal ', 10),
('Corrupt ', 10),
('Crooked ', 10),
('Cruel ', 10),
('Crumbling ', 10),
('Cursed ', 10),
('Dark ', 10),
('Decayed ', 10),
('Defiled ', 10),
('Devious ', 10),
('Deep ', 10),
('Dim ', 10),
('Dire ', 10),
('Dusk ', 10),
('Endless ', 10),
('Evil ', 10),
('Faded ', 10),
('Fallen ', 10),
('Forbidden ', 10),
('Forgotten ', 10),
('Forsaken ', 10),
('Foul ', 10),
('Grey ', 10),
('Grievous ', 10),
('Grim ', 10),
('Grizzly ', 10),
('Harrowing ', 10),
('Harsh ', 10),
('Hoary ', 10),
('Haunted ', 10),
('Hidden ', 10),
('Howling ', 10),
('Infernal ', 10),
('Lost ', 10),
('Low ', 10),
('Miasmic ', 10),
('Misty ', 10),
('Mouldering ', 10),
('Mysterious ', 10),
('Murderous ', 10),
('Murky ', 10),
('Oppressive ', 10),
('Putrid ', 10),
('Rotting ', 10),
('Ruined ', 10),
('Serpentine ', 10),
('Shadow ', 10),
('Sunken ', 10),
('Tainted ', 10),
('Torturous ', 10),
('Vicious ', 10),
('Vile ', 10),
('Wailing ', 10),
('Wicked ', 10),
('Wretched ', 10),
('Whispering ', 10),
)
_dnamesB = (
('{A}Catacombs', 3),
('{A}Crypt', 1),
('{{owners}} Crypt', 1),
('Crypt of {{owner}}', 1),
('{A}Dungeon', 3),
('{A}Fortress', 1),
('{{owners}} Fortress', 1),
('Fortress of {{owner}}', 1),
('{{owners}} Hall', 3),
('{A}Keep', 1),
('{{owners}} Keep', 1),
('{A}Mines', 3),
('{A}Ruins', 3),
('{A}Temple', 1),
('{{owners}} Temple', 1),
('Temple to {{owner}}', 1),
('{A}Tomb', 1),
('{{owners}} Tomb', 1),
('Tomb of {{owner}}', 1),
)
def __init__(self, parent):
self.parent = parent
self.pos = copy(parent.pos)
cx = (parent.parent.position.x + parent.loc.x) >> 4
cz = (parent.parent.position.z + parent.loc.z) >> 4
self.chunk = Vec(cx, 0, cz)
# print 'ruin chunk:', self.chunk
def placed(self, world):
self.depth = self.parent.parent.good_chunks[(
self.chunk.x,
self.chunk.z
)]
self.vtrans = max(
self.parent.parent.position.y - 1,
self.depth
) - self.parent.parent.position.y
self.loc = Vec(self.pos.x * self.parent.parent.room_size,
-self.vtrans,
self.pos.z * self.parent.parent.room_size)
self.setData()
@classmethod
def nameDungeon(self):
# Name this place
A = weighted_choice(self._dnamesA)
name = weighted_choice(self._dnamesB).format(A=A)
return name
def setData(self):
pass
def render(self):
pass
class EvilRunestones(Blank):
_name = 'evilrunestones'
_dnamesB = (
('{A}Gates', 2),
('{A}Pillars', 2),
('{A}Pit', 2),
('{A}Runestones', 2),
('{A}Stones', 2),
('{A}Teeth', 2),
)
def render(self):
# For most of this one, we render directly to the chunk structure.
# This works out better in the end.
height = int(self.parent.parent.room_height * cfg.tower)
# This chunk
cx = (self.parent.parent.position.x + self.parent.loc.x) >> 4
cz = (self.parent.parent.position.z + self.parent.loc.z) >> 4
chunk = self.parent.parent.world.getChunk(cx, cz)
# dungeon y
dy = self.parent.parent.position.y
# Noise function
pn = perlin.SimplexNoise(256)
# Replacement setblock function.
def sb(p, mat, chunk=chunk):
chunk.Blocks[p.x, p.z, p.y] = mat.val
chunk.Data[p.x, p.z, p.y] = mat.data
# Height of the runestones
runes = {}
for x in xrange(16):
for z in xrange(16):
runes[x, z] = random.randint(height / 2, height)
# Iterate over the chunk
for x in xrange(16):
for z in xrange(16):
# find the height at this block
y = chunk.HeightMap[z, x]
while (
y > 0 and
chunk.Blocks[x, z, y] not in materials.heightmap_solids
):
y = y - 1
q = Vec(x, y, z)
# create a chest
if (x == 2 and z == 2):
cp = Vec(cx * 16 + x - self.parent.parent.position.x,
self.parent.parent.position.y - y - 1,
cz * 16 + z - self.parent.parent.position.z)
self.parent.parent.setblock(cp, materials.Chest)
self.parent.parent.addchest(cp, 0)
# The portal exit point is here
self.parent.parent.dinfo['portal_exit'] = cp.up(2)
for r in iterate_cube(q.down(2), q.trans(0, height, 0)):
sb(r, materials.Air)
continue
# If we are above the entrance, clear the air and continue
if (x >= 6 and x <= 9 and z >= 6 and z <= 9):
for r in iterate_cube(
Vec(q.x, dy, q.z),
q.trans(0, height, 0)
):
sb(r, materials.Air)
continue
# Draw some creeping Netherrack and SoulSand.
# Clear the air above
for r in iterate_cube(q.down(1), q.trans(0, height, 0)):
if chunk.Blocks[r.x, r.z, r.y] != materials.Obsidian.val:
sb(r, materials.Air)
d = ((Vec2f(q.x, q.z) - Vec2f(7, 7)).mag()) / 16
n = (pn.noise3(q.x / 4.0, 0, q.z / 4.0) + 1.0) / 2.0
if (n >= d + .20):
sb(q, materials.Netherrack)
# Netherrack might be on fire!
if random.randint(1, 100) <= 5:
sb(q.down(1), materials.Fire)
elif (n > d):
sb(q, materials.SoulSand)
# We are on an edge. Draw a runestone.
# N/S edges
if ((x == 0 or x == 15) and z >= 3 and z <= 9 and z % 3 == 0):
h = runes[x, z]
for r in iterate_cube(q, q.trans(0, h, 0)):
sb(r, materials.Obsidian)
for r in iterate_cube(q.trans(0, h, 0), q.trans(0, h, 3)):
sb(r, materials.Obsidian)
for r in iterate_cube(q.trans(0, 0, 3), q.trans(0, h, 3)):
sb(r, materials.Obsidian)
# E/W edges
if ((z == 0 or z == 15) and x >= 3 and x <= 9 and x % 3 == 0):
h = runes[x, z]
for r in iterate_cube(q, q.trans(0, h, 0)):
sb(r, materials.Obsidian)
for r in iterate_cube(q.trans(0, h, 0), q.trans(3, h, 0)):
sb(r, materials.Obsidian)
for r in iterate_cube(q.trans(3, 0, 0), q.trans(3, h, 0)):
sb(r, materials.Obsidian)
class StepPyramid(Blank):
_name = 'steppyramid'
_dnamesB = (
('{A}Catacombs', 3),
('{A}Ruins', 3),
('{A}Temple', 1),
('{{owners}} Temple', 1),
('Temple to {{owner}}', 1),
('{A}Tomb', 1),
('{{owners}} Tomb', 1),
('Tomb of {{owner}}', 1),
('{A}Pyramid', 1),
('{{owners}} Pyramid', 1),
('Pyramid of {{owner}}', 1),
)
def setData(self):
# The StepPyramid will be 4x4 chunks.
# Figure out if we have to move West or North to fit.
xsize = self.parent.parent.xsize
zsize = self.parent.parent.zsize
self.spos = copy(self.pos)
while self.spos.x > xsize - 4:
self.spos.x -= 1
while self.spos.z > zsize - 4:
self.spos.z -= 1
# Now go through and override the ruins on any chunks we cover
# to be blank.
for p in iterate_cube(Vec(self.spos.x, 0, self.spos.z),
Vec(self.spos.x + 3, 0, self.spos.z + 3)):
if p == self.pos:
continue
blank = new('blank', self.parent.parent.rooms[p])
self.parent.parent.rooms[p].ruins = [blank]
# Find the low point in this region
for p in iterate_cube(Vec(self.spos.x, 0, self.spos.z),
Vec(self.spos.x + 3, 0, self.spos.z + 3)):
cx = (self.parent.parent.position.x >> 4) + p.x
cz = (self.parent.parent.position.z >> 4) + p.z
self.depth = min(self.depth,
self.parent.parent.good_chunks[(cx, cz)])
self.depth = max(self.depth, 62, self.parent.parent.position.y)
self.vtrans = self.depth - self.parent.parent.position.y + 1
self.loc = Vec(self.spos.x * self.parent.parent.room_size,
-self.vtrans,
self.spos.z * self.parent.parent.room_size)
# Figure out how high the entrances should be.
# min is 2, max is 22.
cx = self.parent.parent.position.x >> 4
cz = self.parent.parent.position.z >> 4
world = self.parent.parent.world
# N side
(low1, high1) = findChunkDepths(Vec(cx, 0, cz + 1), world)
(low2, high2) = findChunkDepths(Vec(cx, 0, cz + 2), world)
self.ent_n = min(
22, max(
1, high1 - self.depth, high2 - self.depth) + 1)
# S side
(low1, high1) = findChunkDepths(Vec(cx + 3, 0, cz + 1), world)
(low2, high2) = findChunkDepths(Vec(cx + 3, 0, cz + 2), world)
self.ent_s = min(
22, max(
1, high1 - self.depth, high2 - self.depth) + 1)
# E side
(low1, high1) = findChunkDepths(Vec(cx + 1, 0, cz + 3), world)
(low2, high2) = findChunkDepths(Vec(cx + 2, 0, cz + 3), world)
self.ent_e = min(
22, max(
1, high1 - self.depth, high2 - self.depth) + 1)
# W side
(low1, high1) = findChunkDepths(Vec(cx + 1, 0, cz), world)
(low2, high2) = findChunkDepths(Vec(cx + 2, 0, cz), world)
self.ent_w = min(
22, max(
1, high1 - self.depth, high2 - self.depth) + 1)
def render(self):
# Biome materials
if self.parent.parent.biome in _desert_biomes:
mat_ext = materials.SmoothSandstone
mat_block = materials.meta_decoratedsandstone
mat_ruins = materials.meta_decoratedsandstone
mat_stair = materials.SandstoneStairs
mat_slab = materials.SandstoneSlab
mat_floor = materials.Sand
elif self.parent.parent.biome in _ice_biomes:
mat_ext = materials.PackedIce
mat_block = materials.Ice
mat_ruins = materials.PackedIce
mat_stair = materials.QuartzStairs
mat_slab = materials.QuartzSlab
mat_floor = materials.PackedIce
elif self.parent.parent.biome in _mesa_biomes:
mat_ext = materials.SmoothRedSandstone
mat_block = materials.meta_decoratedredsandstone
mat_ruins = materials.meta_decoratedredsandstone
mat_stair = materials.RedSandstoneStairs
mat_slab = materials.RedSandstoneSlab
mat_floor = materials.RedSand
elif self.parent.parent.biome in _swamp_jungle_biomes:
mat_ext = materials.meta_mossycobble
mat_block = materials.meta_mossycobble
mat_ruins = materials.meta_mossystonebrick
mat_stair = materials.StoneStairs
mat_slab = materials.StoneBrickSlab
mat_floor = materials.Stone
else:
mat_ext = materials.meta_mossystonebrick
mat_block = materials.meta_mossystonebrick
mat_ruins = materials.meta_mossystonebrick
mat_stair = materials.StoneBrickStairs
mat_slab = materials.StoneSlab
mat_floor = materials.Stone
c1 = self.loc
c3 = c1 + Vec(self.parent.parent.room_size * 4 - 1,
0,
self.parent.parent.room_size * 4 - 1)
# corner of the inner shaft
start = Vec(self.parent.loc.x + 5,
c1.y,
self.parent.loc.z + 5)
# Walls and airspace of the pyramid
for y in xrange(29):
for p in iterate_cube(c1.trans(y + 1, -y, y + 1),
c3.trans(-y - 1, -y, -y - 1)):
self.parent.parent.setblock(p, materials.Air)
for p in iterate_four_walls(c1.trans(y, -y, y),
c3.trans(-y, -y, -y), 0):
self.parent.parent.setblock(p, mat_ext)
# In swamp/jungle the steps are extra steppy.
if (
y % 2 == 0 and
self.parent.parent.biome in _swamp_jungle_biomes
):
self.parent.parent.setblock(p.up(1), mat_ext)
# Floor. From pyramid base to just above ceiling.
for p in iterate_four_walls(c1,
c3, c1.y):
self.parent.parent.setblock(p, mat_ext, hide=True)
# Cover the floor with stuff
pn = perlin.SimplexNoise(256)
for p in iterate_cube(c1, c3):
d = ((Vec2f(p.x, p.z) - Vec2f(c1.x + 32, c1.z + 32)).mag()) / 64
n = (pn.noise3(p.x / 4.0, p.y / 4.0, p.z / 4.0) + 1.0) / 2.0
if (n >= d + .20):
self.parent.parent.setblock(p, mat_floor)
elif (n >= d + .10):
self.parent.parent.setblock(p, mat_ruins)
elif (n >= d):
self.parent.parent.setblock(p, materials.Gravel)
else:
self.parent.parent.setblock(p, mat_block)
# Build internal ruins.
cchance = 80
for p in iterate_cube(Vec(0, 0, 0), Vec(3, 0, 3)):
wfunc = iterate_four_walls
if random.randint(1, 100) <= 50:
wfunc = iterate_tube
pp1 = c1.trans(p.x * 16 + 1, 0, p.z * 16 + 1)
pp2 = pp1.trans(13, 0, 13)
# place a chest here
if random.randint(1, 100) <= cchance:
cchance /= 5
cp = pp1.trans(3, -1, 3)
if random.randint(1, 100) <= 50:
self.parent.parent.setblock(cp, materials.Chest)
self.parent.parent.addchest(cp, 0)
else:
self.parent.parent.setblock(cp, materials.Spawner)
self.parent.parent.addspawner(cp, tier=0)
height = 5
for j in wfunc(pp1, pp2, 0):
depth = (pn.noise3(j.x / 4.0,
0,
j.z / 4.0) + 1.0) / 2.0 * height
for x in iterate_cube(j, j.up(depth)):
if (
x in self.parent.parent.blocks and
self.parent.parent.blocks[x].material == materials.Air
):
self.parent.parent.setblock(x, mat_ruins)
# Clean up the stairwell shaft. Clear the air, make a half step around
# it, extend the walls, and redraw the stairs.
self.parent.parent.entrance.height = abs(-c1.y - 2) + 2
for p in iterate_cube(start, start.trans(5, -c1.y - 1, 5)):
self.parent.parent.setblock(p, materials.Air)
for p in iterate_four_walls(Vec(start.x, -1, start.z),
Vec(start.x + 5, -1, start.z + 5), -c1.y - 2):
self.parent.parent.setblock(p, materials._wall)
for p in iterate_four_walls(start, start.trans(5, 0, 5), 0):
self.parent.parent.setblock(p, materials.StoneSlab)
mat = materials.OakWoodSlab
if random.randint(1, 100) <= 50:
mat = materials.StoneSlab
for p in iterate_spiral(Vec(start.x + 1, 7, start.z + 1),
Vec(start.x + 5, 7, start.z + 5),
(abs(c1.y) + 3) * 2):
self.parent.parent.setblock(
Vec(p.x, 0 + int(p.y / 2), p.z), mat, mat.data + ((p.y & 1) ^ 1) * 8)
# Entrances.
# Draw stairs up the sides.
for y in xrange(29):
# North Side
# caps on either side
self.parent.parent.setblock(c1.trans(y, -y - 1, 29), mat_slab)
self.parent.parent.setblock(c1.trans(y, -y - 1, 34), mat_slab)
# draw different stuff depending on the height
# Go ahead and draw exterior stairs at every level.
# (we'll overwrite some below)
for p in iterate_cube(c1.trans(y, -y, 30),
c1.trans(y, -y, 33)):
self.parent.parent.setblock(p,
mat_stair, 0)
self.parent.parent.delblock(p.up(1))
self.parent.parent.setblock(p.trans(1, 0, 0),
mat_block)
# Above floor, but below entry level,
# draw the interior stairs and airspace.
if (y > 0 and y <= self.ent_n):
for p in iterate_cube(c1.trans(y, -y, 28),
c1.trans(y, -y, 35)):
for x in xrange(2, 6):
self.parent.parent.setblock(p.trans(x, 0, 0),
materials.Air, 0)
self.parent.parent.setblock(p.trans(6, 0, 0),
mat_stair, 0)
self.parent.parent.setblock(p.trans(7, 0, 0),
mat_block, 0)
# At entry level, draw a platform floor.
if (self.ent_n == y):
for p in iterate_cube(c1.trans(y + 1, -y, 30),
c1.trans(y + 8, -y, 33)):
self.parent.parent.setblock(p, mat_block)
# Above the entry platform, draw some walls
if (y > self.ent_n and y < self.ent_n + 4):
p = c1.trans(y, -y, 30)
self.parent.parent.setblock(p, mat_block)
self.parent.parent.setblock(p.trans(1, 0, 0), mat_block)
self.parent.parent.setblock(p.trans(0, 0, 1), materials.Air)
self.parent.parent.setblock(p.trans(1, 0, 1), materials.Air)
self.parent.parent.setblock(p.trans(0, 0, 2), materials.Air)
self.parent.parent.setblock(p.trans(1, 0, 2), materials.Air)
self.parent.parent.setblock(p.trans(0, 0, 3), mat_block)
self.parent.parent.setblock(p.trans(1, 0, 3), mat_block)
# Add a ceiling for the entryway.
if (y == self.ent_n + 4):
p = c1.trans(y - 3, -y, 30)
self.parent.parent.setblock(p.trans(1, 1, 0), mat_block)
self.parent.parent.setblock(p.trans(0, 1, 0), mat_block)
self.parent.parent.setblock(p.trans(0, 2, 0), mat_block)
p = c1.trans(y - 3, -y, 33)
self.parent.parent.setblock(p.trans(1, 1, 0), mat_block)
self.parent.parent.setblock(p.trans(0, 1, 0), mat_block)
self.parent.parent.setblock(p.trans(0, 2, 0), mat_block)
for p in iterate_cube(c1.trans(y - 3, -y, 30),
c1.trans(y + 1, -y, 33)):
self.parent.parent.setblock(p, mat_block)
# South Side
self.parent.parent.setblock(c1.trans(63 - y, -y - 1, 29), mat_slab)
self.parent.parent.setblock(c1.trans(63 - y, -y - 1, 34), mat_slab)
for p in iterate_cube(c1.trans(63 - y, -y, 30),
c1.trans(63 - y, -y, 33)):
self.parent.parent.setblock(p,
mat_stair, 1)
self.parent.parent.delblock(p.up(1))
self.parent.parent.setblock(p.trans(-1, 0, 0),
mat_block, 0)
if (y > 0 and y <= self.ent_s):
for p in iterate_cube(c1.trans(63 - y, -y, 28),
c1.trans(63 - y, -y, 35)):
for x in xrange(2, 6):
self.parent.parent.setblock(p.trans(-x, 0, 0),
materials.Air, 0)
self.parent.parent.setblock(p.trans(-6, 0, 0),
mat_stair, 1)
self.parent.parent.setblock(p.trans(-7, 0, 0),
mat_block, 0)
if (self.ent_s == y):
for p in iterate_cube(c1.trans(63 - y - 1, -y, 30),
c1.trans(63 - y - 8, -y, 33)):
self.parent.parent.setblock(p, mat_block)
if (y > self.ent_s and y < self.ent_s + 4):
p = c1.trans(63 - y, -y, 30)
self.parent.parent.setblock(p, mat_block)
self.parent.parent.setblock(p.trans(-1, 0, 0), mat_block)
self.parent.parent.setblock(p.trans(0, 0, 1), materials.Air)
self.parent.parent.setblock(p.trans(-1, 0, 1), materials.Air)
self.parent.parent.setblock(p.trans(0, 0, 2), materials.Air)
self.parent.parent.setblock(p.trans(-1, 0, 2), materials.Air)
self.parent.parent.setblock(p.trans(0, 0, 3), mat_block)
self.parent.parent.setblock(p.trans(-1, 0, 3), mat_block)
if (y == self.ent_s + 4):
p = c1.trans(63 - y + 3, -y, 30)
self.parent.parent.setblock(p.trans(-1, 1, 0), mat_block)
self.parent.parent.setblock(p.trans(0, 1, 0), mat_block)
self.parent.parent.setblock(p.trans(0, 2, 0), mat_block)
p = c1.trans(63 - y + 3, -y, 33)
self.parent.parent.setblock(p.trans(-1, 1, 0), mat_block)
self.parent.parent.setblock(p.trans(0, 1, 0), mat_block)
self.parent.parent.setblock(p.trans(0, 2, 0), mat_block)
for p in iterate_cube(c1.trans(63 - y + 3, -y, 30),
c1.trans(63 - y - 1, -y, 33)):
self.parent.parent.setblock(p, mat_block)
# West Side
self.parent.parent.setblock(c1.trans(29, -y - 1, y), mat_slab)
self.parent.parent.setblock(c1.trans(34, -y - 1, y), mat_slab)
for p in iterate_cube(c1.trans(30, -y, y),
c1.trans(33, -y, y)):
self.parent.parent.setblock(p, mat_stair, 2)
self.parent.parent.delblock(p.up(1))
self.parent.parent.setblock(p.trans(0, 0, 1),
mat_block, 0)
if (y > 0 and y <= self.ent_w):
for p in iterate_cube(c1.trans(28, -y, y),
c1.trans(35, -y, y)):
for x in xrange(2, 6):
self.parent.parent.setblock(p.trans(0, 0, x),
materials.Air, 0)
self.parent.parent.setblock(p.trans(0, 0, 6),
mat_stair, 2)
self.parent.parent.setblock(p.trans(0, 0, 7),
mat_block, 0)
if (self.ent_w == y):
for p in iterate_cube(c1.trans(30, -y, y + 1),
c1.trans(33, -y, y + 8)):
self.parent.parent.setblock(p, mat_block)
if (y > self.ent_w and y < self.ent_w + 4):
p = c1.trans(30, -y, y)
self.parent.parent.setblock(p, mat_block)
self.parent.parent.setblock(p.trans(0, 0, 1), mat_block)
self.parent.parent.setblock(p.trans(1, 0, 0), materials.Air)
self.parent.parent.setblock(p.trans(1, 0, 1), materials.Air)
self.parent.parent.setblock(p.trans(2, 0, 0), materials.Air)
self.parent.parent.setblock(p.trans(2, 0, 1), materials.Air)
self.parent.parent.setblock(p.trans(3, 0, 0), mat_block)
self.parent.parent.setblock(p.trans(3, 0, 1), mat_block)
if (y == self.ent_w + 4):
p = c1.trans(30, -y, y - 3)
self.parent.parent.setblock(p.trans(0, 1, 1), mat_block)
self.parent.parent.setblock(p.trans(0, 1, 0), mat_block)
self.parent.parent.setblock(p.trans(0, 2, 0), mat_block)
p = c1.trans(33, -y, y - 3)
self.parent.parent.setblock(p.trans(0, 1, 1), mat_block)
self.parent.parent.setblock(p.trans(0, 1, 0), mat_block)
self.parent.parent.setblock(p.trans(0, 2, 0), mat_block)
for p in iterate_cube(c1.trans(30, -y, y - 3),
c1.trans(33, -y, y + 1)):
self.parent.parent.setblock(p, mat_block)
# East Side
self.parent.parent.setblock(c1.trans(29, -y - 1, 63 - y), mat_slab)
self.parent.parent.setblock(c1.trans(34, -y - 1, 63 - y), mat_slab)
for p in iterate_cube(c1.trans(30, -y, 63 - y),
c1.trans(33, -y, 63 - y)):
self.parent.parent.setblock(p,
mat_stair, 3)
self.parent.parent.delblock(p.up(1))
self.parent.parent.setblock(p.trans(0, 0, -1),
mat_block, 0)
if (y > 0 and y <= self.ent_e):
for p in iterate_cube(c1.trans(28, -y, 63 - y),
c1.trans(35, -y, 63 - y)):
for x in xrange(2, 6):
self.parent.parent.setblock(p.trans(0, 0, -x),
materials.Air, 0)
self.parent.parent.setblock(p.trans(0, 0, -6),
mat_stair, 3)
self.parent.parent.setblock(p.trans(0, 0, -7),
mat_block, 0)
if (self.ent_e == y):
for p in iterate_cube(c1.trans(30, -y, 63 - y - 1),
c1.trans(33, -y, 63 - y - 8)):
self.parent.parent.setblock(p, mat_block)
if (y > self.ent_e and y < self.ent_e + 4):
p = c1.trans(30, -y, 63 - y)
self.parent.parent.setblock(p, mat_block)
self.parent.parent.setblock(p.trans(0, 0, -1), mat_block)
self.parent.parent.setblock(p.trans(1, 0, 0), materials.Air)
self.parent.parent.setblock(p.trans(1, 0, -1), materials.Air)
self.parent.parent.setblock(p.trans(2, 0, 0), materials.Air)
self.parent.parent.setblock(p.trans(2, 0, -1), materials.Air)
self.parent.parent.setblock(p.trans(3, 0, 0), mat_block)
self.parent.parent.setblock(p.trans(3, 0, -1), mat_block)
if (y == self.ent_e + 4):
p = c1.trans(30, -y, 63 - y + 3)
self.parent.parent.setblock(p.trans(0, 1, -1), mat_block)
self.parent.parent.setblock(p.trans(0, 1, 0), mat_block)
self.parent.parent.setblock(p.trans(0, 2, 0), mat_block)
p = c1.trans(33, -y, 63 - y + 3)
self.parent.parent.setblock(p.trans(0, 1, -1), mat_block)
self.parent.parent.setblock(p.trans(0, 1, 0), mat_block)
self.parent.parent.setblock(p.trans(0, 2, 0), mat_block)
for p in iterate_cube(c1.trans(30, -y, 63 - y + 3),
c1.trans(33, -y, 63 - y - 1)):
self.parent.parent.setblock(p, mat_block)
# Topper
# Deserts have a fancy glass tipped pyramid
if (
self.parent.parent.biome in _desert_biomes or
self.parent.parent.biome in _mesa_biomes
):
# Orange glass in mesas
if (self.parent.parent.biome in _mesa_biomes):
topperglass = materials.OrangeStainedGlass
else:
topperglass = materials.Glass
for y in xrange(29, 33):
for p in iterate_cube(c1.trans(y, -y, y),
c3.trans(-y, -y, -y)):
self.parent.parent.setblock(p, materials.Air)
for p in iterate_four_walls(c1.trans(y - 1, -y, y - 1),
c3.trans(-y + 1, -y, -y + 1), 0):
self.parent.parent.setblock(p, topperglass)
for p in iterate_cube(c1.trans(29, -28, 29),
c3.trans(-29, -28, -29)):
self.parent.parent.setblock(p, mat_block)
for p in iterate_cube(c1.trans(32, -31, 32),
c3.trans(-32, -28, -32)):
self.parent.parent.setblock(p, materials.Air)
# holes in the glass
for p in iterate_cube(c1.trans(32, -30, 28),
c3.trans(-32, -29, -28)):
self.parent.parent.setblock(p, materials.Air)
for p in iterate_cube(c1.trans(28, -30, 32),
c3.trans(-28, -29, -32)):
self.parent.parent.setblock(p, materials.Air)
# Spires
if self.parent.parent.biome in _desert_biomes:
for y in xrange(6):
self.parent.parent.setblock(c1.trans(20, -20 - y, 20),
materials.ChiseledSandstone)
self.parent.parent.setblock(c1.trans(43, -20 - y, 20),
materials.ChiseledSandstone)
self.parent.parent.setblock(c3.trans(-20, -20 - y, -20),
materials.ChiseledSandstone)
self.parent.parent.setblock(c3.trans(-43, -20 - y, -20),
materials.ChiseledSandstone)
for y in xrange(2):
self.parent.parent.setblock(c1.trans(20, -26 - y, 20),
materials.Fence)
self.parent.parent.setblock(c1.trans(43, -26 - y, 20),
materials.Fence)
self.parent.parent.setblock(c3.trans(-20, -26 - y, -20),
materials.Fence)
self.parent.parent.setblock(c3.trans(-43, -26 - y, -20),
materials.Fence)
# swamps and jungles are myan-like
elif self.parent.parent.biome in _swamp_jungle_biomes:
# Supports
self.parent.parent.setblock(c1.trans(29, -29, 29),
materials.StoneBrickStairs)
self.parent.parent.setblock(c1.trans(29, -30, 29),
materials.StoneBrickStairs, 1)
self.parent.parent.setblock(c1.trans(29, -31, 29),
materials.StoneBrickStairs)
self.parent.parent.setblock(c1.trans(34, -29, 29),
materials.StoneBrickStairs, 1)
self.parent.parent.setblock(c1.trans(34, -30, 29),
materials.StoneBrickStairs)
self.parent.parent.setblock(c1.trans(34, -31, 29),
materials.StoneBrickStairs, 1)
self.parent.parent.setblock(c1.trans(29, -29, 34),
materials.StoneBrickStairs)
self.parent.parent.setblock(c1.trans(29, -30, 34),
materials.StoneBrickStairs, 1)
self.parent.parent.setblock(c1.trans(29, -31, 34),
materials.StoneBrickStairs)
self.parent.parent.setblock(c3.trans(-29, -29, -29),
materials.StoneBrickStairs, 1)
self.parent.parent.setblock(c3.trans(-29, -30, -29),
materials.StoneBrickStairs)
self.parent.parent.setblock(c3.trans(-29, -31, -29),
materials.StoneBrickStairs, 1)
# Roof
for p in iterate_cube(c1.trans(29, -32, 29),
c3.trans(-29, -32, -29)):
self.parent.parent.setblock(p, materials.ChiseledStoneBrick)
for p in iterate_cube(c1.trans(29, -28, 29),
c3.trans(-29, -28, -29)):
self.parent.parent.setblock(p, mat_floor)
for p in iterate_cube(c1.trans(32, -32, 32),
c3.trans(-32, -28, -32)):
self.parent.parent.setblock(p, materials.Air)
# Other toppers
else:
# Supports
self.parent.parent.setblock(c1.trans(29, -29, 29), mat_block)
self.parent.parent.setblock(c1.trans(29, -30, 29), mat_block)
self.parent.parent.setblock(c1.trans(34, -29, 29), mat_block)
self.parent.parent.setblock(c1.trans(34, -30, 29), mat_block)
self.parent.parent.setblock(c1.trans(29, -29, 34), mat_block)
self.parent.parent.setblock(c1.trans(29, -30, 34), mat_block)
self.parent.parent.setblock(c3.trans(-29, -29, -29), mat_block)
self.parent.parent.setblock(c3.trans(-29, -30, -29), mat_block)
# Roof
for p in iterate_cube(c1.trans(28, -31, 28),
c3.trans(-28, -31, -28)):
self.parent.parent.setblock(p, mat_slab)
for p in iterate_cube(c1.trans(29, -28, 29),
c3.trans(-29, -28, -29)):
self.parent.parent.setblock(p, mat_block)
for p in iterate_cube(c1.trans(32, -31, 32),
c3.trans(-32, -28, -32)):
self.parent.parent.setblock(p, materials.Air)
# Supply chest
p = c1.trans(30, -29, 30)
self.parent.parent.setblock(p, materials.Chest)
self.parent.parent.addchest(p, 0)
# Portal exit point
self.parent.parent.dinfo['portal_exit'] = p + Vec(p.w(1).x,
c1.y + 29,
p.s(1).z)
class RoundTowerEntrance(Blank):
_name = 'roundtowerentrance'
_ruin = False
_mat = materials.meta_mossystonebrick
_stair = materials.StoneBrickStairs
_biome = True
_dnamesB = (
('{A}Catacombs', 3),
('{A}Crypt', 1),
('{{owners}} Crypt', 1),
('Crypt of {{owner}}', 1),
('{A}Dungeon', 3),
('{A}Fortress', 1),
('{{owners}} Fortress', 1),
('Fortress of {{owner}}', 1),
('{{owners}} Hall', 3),
('{A}Keep', 1),
('{{owners}} Keep', 1),
('{A}Mines', 3),
('{A}Ruins', 3),
('{A}Tower', 3),
('{{owners}} Tower', 3),
('Tower to {{owner}}', 3),
('{A}Tomb', 1),
('{{owners}} Tomb', 1),
('Tomb of {{owner}}', 1),
)
def render(self):
# adjust to biomes if needed
if self._biome is True:
# Desert
if self.parent.parent.biome in _desert_biomes:
self._mat = materials.meta_decoratedsandstone
self._stair = materials.SandstoneStairs
# Ice Spikes
elif self.parent.parent.biome in _ice_biomes:
self._mat = materials.PackedIce
self._stair = materials.QuartzStairs
# Mesas
elif self.parent.parent.biome in _mesa_biomes:
self._mat = materials.HardenedClay
self._stair = materials.OakWoodStairs
# Swamps and such
elif self.parent.parent.biome in _swamp_jungle_biomes:
self._mat = materials.meta_mossycobble
self._stair = materials.StoneStairs
# The room floor Y location
room_floor = self.parent.loc.y + self.parent.parent.room_height - 3
# The height of one room
rheight = self.parent.parent.room_height
# Entrance Level
elev = room_floor - self.parent.parent.entrance.low_height
# Ground level
glev = room_floor - self.parent.parent.entrance.high_height
# Chest level
clev = glev - rheight
# Battlement level
blev = glev - rheight * 2 * cfg.tower
maxlev = (self.parent.parent.world.Height -
self.parent.parent.position.y)
if -blev >= maxlev:
blev = -maxlev + 2
# corner of the inner shaft
start = Vec(self.parent.loc.x + 6,
glev,
self.parent.loc.z + 6)
# Corner of the inner wall
wstart = start.trans(-1, 0, -1)
# B Level is the upper battlements level
b1 = Vec(wstart.x - 1, blev, wstart.z - 1)
b2 = b1.trans(7, 0, 0)
b3 = b1.trans(7, 0, 7)
b4 = b1.trans(0, 0, 7)
# C level is the chest level
c1 = Vec(wstart.x - 4, clev, wstart.z - 4)
c2 = c1.trans(13, 0, 0)
c3 = c1.trans(13, 0, 13)
c4 = c1.trans(0, 0, 13)
# lower tower from ground up to chest level.
# The floor
for p in iterate_cylinder(Vec(c1.x, glev, c1.z),
Vec(c3.x, elev + 1, c3.z)):
self.parent.parent.setblock(p, self._mat)
# The ceiling
for p in iterate_cylinder(Vec(c1.x, clev + 1, c1.z),
Vec(c3.x, clev + 1, c3.z)):
self.parent.parent.setblock(p, self._mat)
# Outer wall and airspace
for p in iterate_cylinder(c1.down(2),
Vec(c3.x, glev, c3.z)):
self.parent.parent.setblock(p, materials.Air)
for p in iterate_tube(Vec(c1.x, elev, c1.z),
Vec(c3.x, elev, c3.z),
abs(elev - clev)):
self.parent.parent.setblock(p, self._mat)
# Battlements
for p in iterate_cube(Vec(0, 0, 0), Vec(5, 0, 5)):
if (((p.x + p.z) & 1) == 1):
self.parent.parent.setblock(c1 + p, materials.Air)
self.parent.parent.setblock(c2.trans(-p.x, p.y, p.z),
materials.Air)
self.parent.parent.setblock(c3.trans(-p.x, p.y, -p.z),
materials.Air)
self.parent.parent.setblock(c4.trans(p.x, p.y, -p.z),
materials.Air)
# Upper tower from chest level to battlement
for p in iterate_cylinder(b1, Vec(b3.x, clev, b3.z)):
self.parent.parent.setblock(p, self._mat)
for p in iterate_cube(Vec(0, 0, 0), Vec(4, 0, 4)):
if (((p.x + p.z) & 1) == 1):
self.parent.parent.setblock(b1 + p, materials.Air)
self.parent.parent.setblock(b2.trans(-p.x, p.y, p.z),
materials.Air)
self.parent.parent.setblock(b3.trans(-p.x, p.y, -p.z),
materials.Air)
self.parent.parent.setblock(b4.trans(p.x, p.y, -p.z),
materials.Air)
# Chest level openings
# W/E
for p in iterate_cube(Vec(b1.x + 3, clev, b1.z),
Vec(b1.x + 4, clev - 2, b1.z + 7)):
self.parent.parent.setblock(p, materials.Air)
# N/S
for p in iterate_cube(Vec(b1.x, clev, b1.z + 3),
Vec(b1.x + 7, clev - 2, b1.z + 4)):
self.parent.parent.setblock(p, materials.Air)
# Ground level openings
# W side
for p in iterate_cube(wstart.trans(2, 0, 0), wstart.trans(3, -2, -4)):
self.parent.parent.setblock(p, materials.Air)
# E side
for p in iterate_cube(wstart.trans(2, 0, 5), wstart.trans(3, -2, 9)):
self.parent.parent.setblock(p, materials.Air)
# N side
for p in iterate_cube(wstart.trans(0, 0, 2), wstart.trans(-4, -2, 3)):
self.parent.parent.setblock(p, materials.Air)
# S side
for p in iterate_cube(wstart.trans(5, 0, 2), wstart.trans(9, -2, 3)):
self.parent.parent.setblock(p, materials.Air)
# Clear air space inside the stairwell shaft
for p in iterate_cube(Vec(wstart.x + 1, elev + 1, wstart.z + 1),
Vec(wstart.x + 4, blev - 2, wstart.z + 4)):
self.parent.parent.setblock(p, materials.Air)
# Internal columns
for p in iterate_cube(Vec(b1.x + 1, elev, b1.z + 1),
Vec(b1.x + 1, clev, b1.z + 1)):
self.parent.parent.setblock(p, materials.StoneDoubleSlab)
for p in iterate_cube(Vec(b2.x - 1, elev, b2.z + 1),
Vec(b2.x - 1, clev, b2.z + 1)):
self.parent.parent.setblock(p, materials.StoneDoubleSlab)
for p in iterate_cube(Vec(b3.x - 1, elev, b3.z - 1),
Vec(b3.x - 1, clev, b3.z - 1)):
self.parent.parent.setblock(p, materials.StoneDoubleSlab)
for p in iterate_cube(Vec(b4.x + 1, elev, b4.z - 1),
Vec(b4.x + 1, clev, b4.z - 1)):
self.parent.parent.setblock(p, materials.StoneDoubleSlab)
# (re)draw the staircase
self.parent.parent.entrance.height = abs(room_floor - elev - 1)
mat = materials.OakWoodSlab
if random.randint(1, 100) <= 50:
mat = materials.StoneSlab
for p in iterate_spiral(Vec(start.x, room_floor + 4, start.z),
Vec(start.x + 4, room_floor + 4, start.z + 4),
(room_floor - blev) * 2):
self.parent.parent.setblock(
Vec(p.x, p.y / 2, p.z), mat, mat.data + ((p.y & 1) ^ 1) * 8)
# Supply chest
pos = Vec(b1.x, clev, b1.z - 1)
self.parent.parent.setblock(pos, materials.Chest)
self.parent.parent.addchest(pos, 0)
# Portal exit point
self.parent.parent.dinfo['portal_exit'] = Vec(pos.w(1).x,
clev,
pos.s(1).z)
# Add a few details with upside-down stairs
N = 2 + 4 # Data values for a north side stair
S = 3 + 4 # South
E = 1 + 4 # East
W = 0 + 4 # West
sb = self.parent.parent.setblock
# Ground level archways
sb(c1.trans(6, 3, 0), self._stair, E)
sb(c1.trans(7, 3, 0), self._stair, W)
sb(c4.trans(6, 3, 0), self._stair, E)
sb(c4.trans(7, 3, 0), self._stair, W)
sb(c1.trans(0, 3, 6), self._stair, S)
sb(c1.trans(0, 3, 7), self._stair, N)
sb(c2.trans(0, 3, 6), self._stair, S)
sb(c2.trans(0, 3, 7), self._stair, N)
# Ruin
if self._ruin is True:
ruinBlocks(b1.trans(0, rheight - 1, 0),
b3.trans(0, rheight - 1, 0),
rheight,
self.parent.parent)
# Sandbar island
if (self.parent.parent.entrance.inwater is False):
return
d = 2
s1 = Vec(wstart.x - 3, glev + 1, wstart.z - 3)
s3 = Vec(wstart.x + 8, glev + 1, wstart.z + 8)
for y in xrange(rheight):
for p in iterate_disc(s1.trans(-d, y, -d),
s3.trans(d, y, d)):
if (p not in self.parent.parent.blocks):
self.parent.parent.setblock(p, materials._sandbar)
d += 1
class SquareTowerEntrance(Blank):
_name = 'squaretowerentrance'
_ruin = False
_mat = materials.meta_mossystonebrick
_stair = materials.StoneBrickStairs
_support = materials.StoneBrickStairs