aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.World/VillagePieces.h
blob: 7570d65bb05a62e1608ea02441d14b3f80a5fe2c (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
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
#pragma once
#include "StructurePiece.h"

class BiomeSource;

class VillagePieces
{

private:
	static const int MAX_DEPTH = 50;
	static const int BASE_ROAD_DEPTH = 3;
	// the dungeon starts at 64 and traverses downwards to this point
	static const int LOWEST_Y_POSITION = 10;

public:
	static const int SIZE_SMALL = 0;
	static const int SIZE_BIG = 1;
	static const int SIZE_BIGGEST = 2;

	// 4J - added to replace use of Class<? extends VillagePiece> within this class
	enum EPieceClass
	{
		EPieceClass_SimpleHouse,
		EPieceClass_SmallTemple,
		EPieceClass_BookHouse,
		EPieceClass_SmallHut,
		EPieceClass_PigHouse,
		EPieceClass_DoubleFarmland,
		EPieceClass_Farmland,
		EPieceClass_Smithy,
		EPieceClass_TwoRoomHouse
	};

	static void loadStatic();

	class PieceWeight
	{
	public:
		EPieceClass pieceClass;		// 4J - EPieceClass was Class<? extends VillagePiece>
		const int weight;
		int placeCount;
		int maxPlaceCount;

		PieceWeight(EPieceClass pieceClass, int weight, int maxPlaceCount);	// 4J - EPieceClass was Class<? extends VillagePiece>
		bool doPlace(int depth);
		bool isValid();
	};

	static list<PieceWeight *> *createPieceSet(Random *random, int villageSize);		// 4J - was ArrayList

	class StartPiece;
private:
	class VillagePiece;
	static int updatePieceWeight(list<PieceWeight *> *currentPieces);		// 4J = was array list
	static VillagePiece *findAndCreatePieceFactory(StartPiece *startPiece, PieceWeight *piece, list<StructurePiece *> *pieces, Random *random, int footX, int footY, int footZ, int direction, int depth);
	static VillagePiece *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);
	static StructurePiece *generateAndAddRoadPiece(StartPiece *startPiece, list<StructurePiece *> *pieces, Random *random, int footX, int footY, int footZ, int direction, int depth);


	/**
	* 
	*
	*/
private:
	class VillagePiece : public StructurePiece
	{
	protected:
		int heightPosition;
	private:
		int spawnedVillagerCount;
		bool isDesertVillage;
	protected:
		StartPiece *startPiece;

		VillagePiece();
		VillagePiece(StartPiece *startPiece, int genDepth);
		virtual void addAdditonalSaveData(CompoundTag *tag);
		virtual void readAdditonalSaveData(CompoundTag *tag);
		StructurePiece *generateHouseNorthernLeft(StartPiece *startPiece, list<StructurePiece *> *pieces, Random *random, int yOff, int zOff);
		StructurePiece *generateHouseNorthernRight(StartPiece *startPiece, list<StructurePiece *> *pieces, Random *random, int yOff, int zOff);
		int getAverageGroundHeight(Level *level, BoundingBox *chunkBB);
		static bool isOkBox(BoundingBox *box, StartPiece *startRoom); // 4J added startRoom param
		void spawnVillagers(Level *level, BoundingBox *chunkBB, int x, int y, int z, int count);
		virtual int getVillagerProfession(int villagerNumber);
		virtual int biomeBlock(int tile, int data);
		virtual int biomeData(int tile, int data);
		virtual void placeBlock(Level *level, int block, int data, int x, int y, int z, BoundingBox *chunkBB);
		virtual void generateBox(Level *level, BoundingBox *chunkBB, int x0, int y0, int z0, int x1, int y1, int z1, int edgeTile, int fillTile, bool skipAir);
		virtual void fillColumnDown(Level *level, int block, int data, int x, int startY, int z, BoundingBox *chunkBB);
	};

	/**
	* 
	*
	*/
public:
	class Well : public VillagePiece
	{
	public:
		static StructurePiece *Create() { return new Well(); }
		virtual EStructurePiece GetType() { return eStructurePiece_Well; }

	private:
		static const int width = 6;
		static const int height = 15;
		static const int depth = 6;

	public:
		Well();
		Well(StartPiece *startPiece, int genDepth, Random *random, int west, int north);
		Well(StartPiece *startPiece, 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 StartPiece : public Well
	{
	public:
		virtual EStructurePiece GetType() { return eStructurePiece_VillageStartPiece; }

	public:
		// these fields are only used in generation step and aren't serialized :{
		BiomeSource *biomeSource;
		bool isDesertVillage;

		int villageSize;
		bool isLibraryAdded;
		PieceWeight *previousPiece;
		list<PieceWeight *> *pieceSet;
		Level *m_level;

		// these queues are used so that the addChildren calls are called in a random order
		vector<StructurePiece *> pendingHouses;
		vector<StructurePiece *> pendingRoads;

		StartPiece();
		StartPiece(BiomeSource *biomeSource, int genDepth, Random *random, int west, int north, list<PieceWeight *> *pieceSet, int villageSize, Level *level); // 4J Added level param
		virtual ~StartPiece();

		BiomeSource *getBiomeSource();

	};

public:
	class VillageRoadPiece : public VillagePiece
	{
	protected:
		VillageRoadPiece() {}
		VillageRoadPiece(StartPiece *startPiece, int genDepth) : VillagePiece(startPiece, genDepth) {}
	};

	/**
	* 
	*
	*/
public:
	class StraightRoad : public VillageRoadPiece
	{
	public:
		static StructurePiece *Create() { return new StraightRoad(); }
		virtual EStructurePiece GetType() { return eStructurePiece_StraightRoad; }

	private:
		static const int width = 3;
		int length;
	public:
		StraightRoad();
		StraightRoad(StartPiece *startPiece, int genDepth, Random *random, BoundingBox *stairsBox, int direction);

	protected:
		void addAdditonalSaveData(CompoundTag *tag);
		void readAdditonalSaveData(CompoundTag *tag);

	public:
		virtual void addChildren(StructurePiece *startPiece, list<StructurePiece *> *pieces, Random *random);
		static BoundingBox *findPieceBox(StartPiece *startPiece, list<StructurePiece *> *pieces, Random *random, int footX, int footY, int footZ, int direction);
		virtual bool postProcess(Level *level, Random *random, BoundingBox *chunkBB);
	};

	/**
	* 
	*
	*/
public:
	class SimpleHouse : public VillagePiece
	{
	public:
		static StructurePiece *Create() { return new SimpleHouse(); }
		virtual EStructurePiece GetType() { return eStructurePiece_SimpleHouse; }

	private:
		static const int width = 5;
		static const int height = 6;
		static const int depth = 5;

	private:
		bool hasTerrace;

	public:
		SimpleHouse();
		SimpleHouse(StartPiece *startPiece, int genDepth, Random *random, BoundingBox *stairsBox, int direction);

	protected:
		void addAdditonalSaveData(CompoundTag *tag);
		void readAdditonalSaveData(CompoundTag *tag);

	public:
		static SimpleHouse *createPiece(StartPiece *startPiece, 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 SmallTemple : public VillagePiece
	{
	public:
		static StructurePiece *Create() { return new SmallTemple(); }
		virtual EStructurePiece GetType() { return eStructurePiece_SmallTemple; }

	private:
		static const int width = 5;
		static const int height = 12;
		static const int depth = 9;

		int heightPosition;

	public:
		SmallTemple();
		SmallTemple(StartPiece *startPiece, int genDepth, Random *random, BoundingBox *stairsBox, int direction);

		static SmallTemple *createPiece(StartPiece *startPiece, list<StructurePiece *> *pieces, Random *random, int footX, int footY, int footZ, int direction, int genDepth);
		virtual bool postProcess(Level *level, Random *random, BoundingBox *chunkBB);
		virtual int getVillagerProfession(int villagerNumber);
	};

public:
	class BookHouse : public VillagePiece
	{
	public:
		static StructurePiece *Create() { return new BookHouse(); }
		virtual EStructurePiece GetType() { return eStructurePiece_BookHouse; }

	private:
		static const int width = 9;
		static const int height = 9;
		static const int depth = 6;

		int heightPosition;

	public:
		BookHouse();
		BookHouse(StartPiece *startPiece, int genDepth, Random *random, BoundingBox *stairsBox, int direction);

		static BookHouse *createPiece(StartPiece *startPiece, list<StructurePiece *> *pieces, Random *random, int footX, int footY, int footZ, int direction, int genDepth);
		virtual bool postProcess(Level *level, Random *random, BoundingBox *chunkBB);
		virtual int getVillagerProfession(int villagerNumber);
	};

public:
	class SmallHut : public VillagePiece
	{
	public:
		static StructurePiece *Create() { return new SmallHut(); }
		virtual EStructurePiece GetType() { return eStructurePiece_SmallHut; }


	private:
		static const int width = 4;
		static const int height = 6;
		static const int depth = 5;

		bool lowCeiling;
		int tablePlacement;

	public:
		SmallHut();
		SmallHut(StartPiece *startPiece, int genDepth, Random *random, BoundingBox *stairsBox, int direction);

	protected:
		virtual void addAdditonalSaveData(CompoundTag *tag);
		virtual void readAdditonalSaveData(CompoundTag *tag);

	public:
		static SmallHut *createPiece(StartPiece *startPiece, 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 PigHouse : public VillagePiece
	{
	public:
		static StructurePiece *Create() { return new PigHouse(); }
		virtual EStructurePiece GetType() { return eStructurePiece_PigHouse; }


	private:
		static const int width = 9;
		static const int height = 7;
		static const int depth = 11;

	public:
		PigHouse();
		PigHouse(StartPiece *startPiece, int genDepth, Random *random, BoundingBox *stairsBox, int direction);
		static PigHouse *createPiece(StartPiece *startPiece, list<StructurePiece *> *pieces, Random *random, int footX, int footY, int footZ, int direction, int genDepth);
		virtual bool postProcess(Level *level, Random *random, BoundingBox *chunkBB);
		virtual int getVillagerProfession(int villagerNumber);
	};

public:
	class TwoRoomHouse : public VillagePiece
	{
	public:
		static StructurePiece *Create() { return new TwoRoomHouse(); }
		virtual EStructurePiece GetType() { return eStructurePiece_TwoRoomHouse; }

	private:
		static const int width = 9;
		static const int height = 7;
		static const int depth = 12;

		int heightPosition;

	public:
		TwoRoomHouse();
		TwoRoomHouse(StartPiece *startPiece, int genDepth, Random *random, BoundingBox *stairsBox, int direction);
		static TwoRoomHouse *createPiece(StartPiece *startPiece, 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 Smithy : public VillagePiece
	{
	public:
		static StructurePiece *Create() { return new Smithy(); }
		virtual EStructurePiece GetType() { return eStructurePiece_Smithy; }


	private:
		static const int width = 10;
		static const int height = 6;
		static const int depth = 7;

		bool hasPlacedChest;

		static WeighedTreasureArray treasureItems;

	public:
		static void staticCtor();

		Smithy();
		Smithy(StartPiece *startPiece, int genDepth, Random *random, BoundingBox *stairsBox, int direction);
		static Smithy *createPiece(StartPiece *startPiece, list<StructurePiece *> *pieces, Random *random, int footX, int footY, int footZ, int direction, int genDepth);

	protected:
		void addAdditonalSaveData(CompoundTag *tag);
		void readAdditonalSaveData(CompoundTag *tag);

	public:
		virtual bool postProcess(Level *level, Random *random, BoundingBox *chunkBB);
		virtual int getVillagerProfession(int villagerNumber);
	};

public:
	class Farmland : public VillagePiece
	{
	public:
		static StructurePiece *Create() { return new Farmland(); }
		virtual EStructurePiece GetType() { return eStructurePiece_Farmland; }


	private:
		static const int width = 7;
		static const int height = 4;
		static const int depth = 9;

		int cropsA;
		int cropsB;

		int selectCrops(Random *random);

	public:
		Farmland();
		Farmland(StartPiece *startPiece, int genDepth, Random *random, BoundingBox *stairsBox, int direction);

	protected:
		virtual void addAdditonalSaveData(CompoundTag *tag);
		virtual void readAdditonalSaveData(CompoundTag *tag);

	public:
		static Farmland *createPiece(StartPiece *startPiece, 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 DoubleFarmland : public VillagePiece
	{
	public:
		static StructurePiece *Create() { return new DoubleFarmland(); }
		virtual EStructurePiece GetType() { return eStructurePiece_DoubleFarmland; }

	private:
		static const int width = 13;
		static const int height = 4;
		static const int depth = 9;

		int heightPosition;

		int cropsA;
		int cropsB;
		int cropsC;
		int cropsD;

		int selectCrops(Random *random);

	public:
		DoubleFarmland();
		DoubleFarmland(StartPiece *startPiece, int genDepth, Random *random, BoundingBox *stairsBox, int direction);

	protected:
		virtual void addAdditonalSaveData(CompoundTag *tag);
		virtual void readAdditonalSaveData(CompoundTag *tag);

	public:
		static DoubleFarmland *createPiece(StartPiece *startPiece, 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 LightPost : public VillagePiece
	{
	public:
		static StructurePiece *Create() { return new LightPost(); }
		virtual EStructurePiece GetType() { return eStructurePiece_LightPost; }

	private:
		static const int width = 3;
		static const int height = 4;
		static const int depth = 2;

		int heightPosition;

	public:
		LightPost();
		LightPost(StartPiece *startPiece, int genDepth, Random *random, BoundingBox *box, int direction);
		static BoundingBox *findPieceBox(StartPiece *startPiece, list<StructurePiece *> *pieces, Random *random, int footX, int footY, int footZ, int direction);
		virtual bool postProcess(Level *level, Random *random, BoundingBox *chunkBB);
	};
};