aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.World/StrongholdPieces.h
blob: c9751baec47254c22e3342f84c4e0738c7b8441f (plain)
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
#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
	};

	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:
		StrongholdPiece(int genDepth);

        enum SmallDoorType
		{
            OPENING, WOOD_DOOR, GRATES, IRON_DOOR,
        };

		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
	{
	private:
		const int steps;

	public:
		FillerCorridor(int genDepth, Random *random, BoundingBox *corridorBox, int direction);

        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
	{
	private:
		static const int width = 5;
		static const int height = 11;
		static const int depth = 5;
		
		const bool isSource;
		const SmallDoorType entryDoor;

	public:
		StairsDown(int genDepth, Random *random, int west, int north);
		StairsDown(int genDepth, Random *random, BoundingBox *stairsBox, int direction);

        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:
		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(int genDepth, Random *random, int west, int north, Level *level); // 4J Added level param
		virtual TilePos *getLocatorPosition();
    };

    /**
     * 
     *
     */
public:
	class Straight : public StrongholdPiece
	{
	private:
		static const int width = 5;
		static const int height = 5;
		static const int depth = 7;

		const SmallDoorType entryDoor;
		const bool leftChild;
		const bool rightChild;

	public:
		Straight(int genDepth, Random *random, BoundingBox *stairsBox, int direction);
		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
	{
	private:
		static const int width = 5;
        static const int height = 5;
        static const int depth = 7;
		static const int TREASURE_ITEMS_COUNT = 14;
		static WeighedTreasure *treasureItems[TREASURE_ITEMS_COUNT];

        const SmallDoorType entryDoor;
        boolean hasPlacedChest;

	public:
		ChestCorridor(int genDepth, Random *random, BoundingBox *stairsBox, int direction);
        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
	{
	private:
		static const int width = 5;
		static const int height = 11;
		static const int depth = 8;

		const SmallDoorType entryDoor;

	public:
		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
	{

	protected:
		static const int width = 5;
		static const int height = 5;
		static const int depth = 5;

		const SmallDoorType entryDoor;

	public:
		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:
		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
	{
	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:
		const SmallDoorType entryDoor;
        const int type;
	public:
		RoomCrossing(int genDepth, Random *random, BoundingBox *stairsBox, int direction);
        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
	{
	protected:
		static const int width = 9;
		static const int height = 5;
		static const int depth = 11;

        const SmallDoorType entryDoor;

	public:
		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
	{
	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;

        const SmallDoorType entryDoor;
	private:
		const bool isTall;

	public:
		Library(int genDepth, Random *random, BoundingBox *roomBox, int direction);
        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
	{
	protected:
		static const int width = 10;
        static const int height = 9;
        static const int depth = 11;

        const SmallDoorType entryDoor;

	private:
		bool leftLow, leftHigh, rightLow, rightHigh;

	public:
		FiveCrossing(int genDepth, Random *random, BoundingBox *stairsBox, int direction);
        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
	{
	protected:
		static const int width = 11;
        static const int height = 8;
        static const int depth = 16;

	private:
		bool hasPlacedMobSpawner;

	public:
		PortalRoom(int genDepth, Random *random, BoundingBox *stairsBox, int direction);
		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;
};