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
|
#pragma once
#include "StructurePiece.h"
class StrongholdPieces
{
private:
static const int SMALL_DOOR_WIDTH = 3;
static const int SMALL_DOOR_HEIGHT = 3;
static const int MAX_DEPTH = 50;
// the dungeon starts at 64 and traverses downwards to this point
static const int LOWEST_Y_POSITION = 10;
static const bool CHECK_AIR;
// 4J - added to replace use of Class<? extends StrongholdPiece> within this class
enum EPieceClass
{
EPieceClass_NULL,
EPieceClass_Straight,
EPieceClass_PrisonHall,
EPieceClass_LeftTurn,
EPieceClass_RightTurn,
EPieceClass_RoomCrossing,
EPieceClass_StraightStairsDown,
EPieceClass_StairsDown,
EPieceClass_FiveCrossing,
EPieceClass_ChestCorridor,
EPieceClass_Library,
EPieceClass_PortalRoom
};
public:
static void loadStatic();
private:
class PieceWeight
{
public:
EPieceClass pieceClass; // 4J - was Class<? extends StrongholdPiece>
const int weight;
int placeCount;
int maxPlaceCount;
PieceWeight(EPieceClass pieceClass, int weight, int maxPlaceCount);
virtual bool doPlace(int depth);
bool isValid();
};
// 4J - added, java uses a local specialisation of these classes when instancing to achieve the same thing
class PieceWeight_Library : public PieceWeight
{
public:
PieceWeight_Library(EPieceClass pieceClass, int weight, int maxPlaceCount) : PieceWeight(pieceClass, weight, maxPlaceCount) {}
virtual bool doPlace(int depth) { return PieceWeight::doPlace(depth) && depth > 4; }
};
class PieceWeight_PortalRoom : public PieceWeight
{
public:
PieceWeight_PortalRoom(EPieceClass pieceClass, int weight, int maxPlaceCount) : PieceWeight(pieceClass, weight, maxPlaceCount) {}
virtual bool doPlace(int depth) { return PieceWeight::doPlace(depth) && depth > 5; }
};
static list<PieceWeight *> currentPieces;
static EPieceClass imposedPiece;
static int totalWeight;
public:
static void resetPieces();
class StartPiece;
private:
class StrongholdPiece;
static bool updatePieceWeight();
static StrongholdPiece *findAndCreatePieceFactory(EPieceClass pieceClass, list<StructurePiece*> *pieces, Random *random, int footX, int footY, int footZ, int direction, int depth);
static StrongholdPiece *generatePieceFromSmallDoor(StartPiece *startPiece, list<StructurePiece *> *pieces, Random *random, int footX, int footY, int footZ, int direction, int depth);
static StructurePiece *generateAndAddPiece(StartPiece *startPiece, list<StructurePiece *> *pieces, Random *random, int footX, int footY, int footZ, int direction, int depth);
/**
*
*
*/
private:
class StrongholdPiece : public StructurePiece
{
protected:
enum SmallDoorType
{
OPENING, WOOD_DOOR, GRATES, IRON_DOOR,
};
SmallDoorType entryDoor;
public:
StrongholdPiece();
protected:
StrongholdPiece(int genDepth);
virtual void addAdditonalSaveData(CompoundTag *tag);
virtual void readAdditonalSaveData(CompoundTag *tag);
void generateSmallDoor(Level *level, Random *random, BoundingBox *chunkBB, SmallDoorType doorType, int footX, int footY, int footZ);
SmallDoorType randomSmallDoor(Random *random);
StructurePiece *generateSmallDoorChildForward(StartPiece *startPiece, list<StructurePiece *> *pieces, Random *random, int xOff, int yOff);
StructurePiece *generateSmallDoorChildLeft(StartPiece *startPiece, list<StructurePiece *> *pieces, Random *random, int yOff, int zOff);
StructurePiece *generateSmallDoorChildRight(StartPiece *startPiece, list<StructurePiece *> *pieces, Random *random, int yOff, int zOff);
static bool isOkBox(BoundingBox *box, StartPiece *startRoom); // 4J added startRoom param
};
/**
* Corridor pieces that connects unconnected ends.
*
*/
public:
class FillerCorridor : public StrongholdPiece
{
public:
static StructurePiece *Create() { return new FillerCorridor(); }
virtual EStructurePiece GetType() { return eStructurePiece_FillerCorridor; }
private:
int steps;
public:
FillerCorridor();
FillerCorridor(int genDepth, Random *random, BoundingBox *corridorBox, int direction);
protected:
virtual void addAdditonalSaveData(CompoundTag *tag);
virtual void readAdditonalSaveData(CompoundTag *tag);
public:
static BoundingBox *findPieceBox(list<StructurePiece *> *pieces, Random *random, int footX, int footY, int footZ, int direction);
virtual bool postProcess(Level *level, Random *random, BoundingBox *chunkBB);
};
/**
*
*
*/
public:
class StairsDown : public StrongholdPiece
{
public:
static StructurePiece *Create() { return new StairsDown(); }
virtual EStructurePiece GetType() { return eStructurePiece_StairsDown; }
private:
static const int width = 5;
static const int height = 11;
static const int depth = 5;
bool isSource;
public:
StairsDown();
StairsDown(int genDepth, Random *random, int west, int north);
StairsDown(int genDepth, Random *random, BoundingBox *stairsBox, int direction);
protected:
virtual void addAdditonalSaveData(CompoundTag *tag);
virtual void readAdditonalSaveData(CompoundTag *tag);
public:
virtual void addChildren(StructurePiece *startPiece, list<StructurePiece *> *pieces, Random *random);
static StairsDown *createPiece(list<StructurePiece *> *pieces, Random *random, int footX, int footY, int footZ, int direction, int genDepth);
virtual bool postProcess(Level *level, Random *random, BoundingBox *chunkBB);
};
public:
class PortalRoom;
class StartPiece : public StairsDown
{
public:
virtual EStructurePiece GetType() { return eStructurePiece_StrongholdStartPiece; }
public:
bool isLibraryAdded;
PieceWeight *previousPiece;
PortalRoom *portalRoomPiece;
Level *m_level; // 4J added
// this queue is used so that the addChildren calls are
// called in a random order
vector<StructurePiece *> pendingChildren;
StartPiece();
StartPiece(int genDepth, Random *random, int west, int north, Level *level); // 4J Added level param
virtual TilePos *getLocatorPosition();
};
/**
*
*
*/
public:
class Straight : public StrongholdPiece
{
public:
static StructurePiece *Create() { return new Straight(); }
virtual EStructurePiece GetType() { return eStructurePiece_Straight; }
private:
static const int width = 5;
static const int height = 5;
static const int depth = 7;
bool leftChild;
bool rightChild;
public:
Straight();
Straight(int genDepth, Random *random, BoundingBox *stairsBox, int direction);
protected:
virtual void addAdditonalSaveData(CompoundTag *tag);
virtual void readAdditonalSaveData(CompoundTag *tag);
public:
virtual void addChildren(StructurePiece *startPiece, list<StructurePiece *> *pieces, Random *random);
static Straight *createPiece(list<StructurePiece *> *pieces, Random *random, int footX, int footY, int footZ, int direction, int genDepth);
virtual bool postProcess(Level *level, Random *random, BoundingBox *chunkBB);
};
/**
*
*
*/
class ChestCorridor : public StrongholdPiece
{
public:
static StructurePiece *Create() { return new ChestCorridor(); }
virtual EStructurePiece GetType() { return eStructurePiece_ChestCorridor; }
private:
static const int width = 5;
static const int height = 5;
static const int depth = 7;
static const int TREASURE_ITEMS_COUNT = 18;
static WeighedTreasure *treasureItems[TREASURE_ITEMS_COUNT];
bool hasPlacedChest;
public:
ChestCorridor();
ChestCorridor(int genDepth, Random *random, BoundingBox *stairsBox, int direction);
protected:
virtual void addAdditonalSaveData(CompoundTag *tag);
virtual void readAdditonalSaveData(CompoundTag *tag);
public:
virtual void addChildren(StructurePiece *startPiece, list<StructurePiece *> *pieces, Random *random);
static ChestCorridor *createPiece(list<StructurePiece *> *pieces, Random *random, int footX, int footY, int footZ, int direction, int genDepth);
virtual bool postProcess(Level *level, Random *random, BoundingBox *chunkBB);
};
/**
*
*
*/
public:
class StraightStairsDown : public StrongholdPiece
{
public:
static StructurePiece *Create() { return new StraightStairsDown(); }
virtual EStructurePiece GetType() { return eStructurePiece_StraightStairsDown; }
private:
static const int width = 5;
static const int height = 11;
static const int depth = 8;
public:
StraightStairsDown();
StraightStairsDown(int genDepth, Random *random, BoundingBox *stairsBox, int direction);
virtual void addChildren(StructurePiece *startPiece, list<StructurePiece *> *pieces, Random *random);
static StraightStairsDown *createPiece(list<StructurePiece *> *pieces, Random *random, int footX, int footY, int footZ, int direction, int genDepth);
virtual bool postProcess(Level *level, Random *random, BoundingBox *chunkBB);
};
/**
*
*
*/
public:
class LeftTurn : public StrongholdPiece
{
public:
static StructurePiece *Create() { return new LeftTurn(); }
virtual EStructurePiece GetType() { return eStructurePiece_LeftTurn; }
protected:
static const int width = 5;
static const int height = 5;
static const int depth = 5;
public:
LeftTurn();
LeftTurn(int genDepth, Random *random, BoundingBox *stairsBox, int direction);
virtual void addChildren(StructurePiece *startPiece, list<StructurePiece *> *pieces, Random *random);
static LeftTurn *createPiece(list<StructurePiece *> *pieces, Random *random, int footX, int footY, int footZ, int direction, int genDepth);
virtual bool postProcess(Level *level, Random *random, BoundingBox *chunkBB);
};
/**
*
*
*/
public:
class RightTurn : public LeftTurn
{
public:
static StructurePiece *Create() { return new RightTurn(); }
virtual EStructurePiece GetType() { return eStructurePiece_RightTurn; }
public:
RightTurn();
RightTurn(int genDepth, Random *random, BoundingBox *stairsBox, int direction);
virtual void addChildren(StructurePiece *startPiece, list<StructurePiece *> *pieces, Random *random);
virtual bool postProcess(Level *level, Random *random, BoundingBox *chunkBB);
};
/**
*
*
*/
public:
class RoomCrossing : public StrongholdPiece
{
public:
static StructurePiece *Create() { return new RoomCrossing(); }
virtual EStructurePiece GetType() { return eStructurePiece_StrongholdRoomCrossing; }
private:
static const int SMALL_TREASURE_ITEMS_COUNT = 7; // 4J added
static WeighedTreasure *smallTreasureItems[SMALL_TREASURE_ITEMS_COUNT];
protected:
static const int width = 11;
static const int height = 7;
static const int depth = 11;
protected:
int type;
public:
RoomCrossing();
RoomCrossing(int genDepth, Random *random, BoundingBox *stairsBox, int direction);
protected:
virtual void addAdditonalSaveData(CompoundTag *tag);
virtual void readAdditonalSaveData(CompoundTag *tag);
public:
virtual void addChildren(StructurePiece *startPiece, list<StructurePiece *> *pieces, Random *random);
static RoomCrossing *createPiece(list<StructurePiece *> *pieces, Random *random, int footX, int footY, int footZ, int direction, int genDepth);
virtual bool postProcess(Level *level, Random *random, BoundingBox *chunkBB);
};
/**
*
*
*/
public:
class PrisonHall : public StrongholdPiece
{
public:
static StructurePiece *Create() { return new PrisonHall(); }
virtual EStructurePiece GetType() { return eStructurePiece_PrisonHall; }
protected:
static const int width = 9;
static const int height = 5;
static const int depth = 11;
public:
PrisonHall();
PrisonHall(int genDepth, Random *random, BoundingBox *stairsBox, int direction);
virtual void addChildren(StructurePiece *startPiece, list<StructurePiece *> *pieces, Random *random);
static PrisonHall *createPiece(list<StructurePiece *> *pieces, Random *random, int footX, int footY, int footZ, int direction, int genDepth);
virtual bool postProcess(Level *level, Random *random, BoundingBox *chunkBB);
};
/**
*
*
*/
public:
class Library : public StrongholdPiece
{
public:
static StructurePiece *Create() { return new Library(); }
virtual EStructurePiece GetType() { return eStructurePiece_Library; }
private:
static const int LIBRARY_TREASURE_ITEMS_COUNT = 4; // 4J added
static WeighedTreasure *libraryTreasureItems[LIBRARY_TREASURE_ITEMS_COUNT];
protected:
static const int width = 14;
static const int height = 6;
static const int tallHeight = 11;
static const int depth = 15;
private:
bool isTall;
public:
Library();
Library(int genDepth, Random *random, BoundingBox *roomBox, int direction);
protected:
virtual void addAdditonalSaveData(CompoundTag *tag);
virtual void readAdditonalSaveData(CompoundTag *tag);
public:
static Library *createPiece(list<StructurePiece *> *pieces, Random *random, int footX, int footY, int footZ, int direction, int genDepth);
virtual bool postProcess(Level *level, Random *random, BoundingBox *chunkBB);
};
/**
*
*
*/
public:
class FiveCrossing : public StrongholdPiece
{
public:
static StructurePiece *Create() { return new FiveCrossing(); }
virtual EStructurePiece GetType() { return eStructurePiece_FiveCrossing; }
protected:
static const int width = 10;
static const int height = 9;
static const int depth = 11;
private:
bool leftLow, leftHigh, rightLow, rightHigh;
public:
FiveCrossing();
FiveCrossing(int genDepth, Random *random, BoundingBox *stairsBox, int direction);
protected:
virtual void addAdditonalSaveData(CompoundTag *tag);
virtual void readAdditonalSaveData(CompoundTag *tag);
public:
virtual void addChildren(StructurePiece *startPiece, list<StructurePiece *> *pieces, Random *random);
static FiveCrossing *createPiece(list<StructurePiece *> *pieces, Random *random, int footX, int footY, int footZ, int direction, int genDepth);
virtual bool postProcess(Level *level, Random *random, BoundingBox *chunkBB);
};
/**
*
*
*/
class PortalRoom : public StrongholdPiece
{
public:
static StructurePiece *Create() { return new PortalRoom(); }
virtual EStructurePiece GetType() { return eStructurePiece_PortalRoom; }
protected:
static const int width = 11;
static const int height = 8;
static const int depth = 16;
private:
bool hasPlacedMobSpawner;
public:
PortalRoom();
PortalRoom(int genDepth, Random *random, BoundingBox *stairsBox, int direction);
protected:
virtual void addAdditonalSaveData(CompoundTag *tag);
virtual void readAdditonalSaveData(CompoundTag *tag);
public:
void addChildren(StructurePiece *startPiece, list<StructurePiece *> *pieces, Random *random);
static PortalRoom *createPiece(list<StructurePiece *> *pieces, Random *random, int footX, int footY, int footZ, int direction, int genDepth);
bool postProcess(Level *level, Random *random, BoundingBox *chunkBB);
};
private:
class SmoothStoneSelector : public StructurePiece::BlockSelector
{
public:
virtual void next(Random *random, int worldX, int worldY, int worldZ, bool isEdge);
};
static const SmoothStoneSelector *smoothStoneSelector;
};
|