aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.World/StructureStart.cpp
blob: 22a4312c381141277eaf4c2271f7ab3038d7d001 (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
#include "stdafx.h"
#include "net.minecraft.world.level.h"
#include "StructureStart.h"
#include "StructurePiece.h"
#include "BoundingBox.h"


StructureStart::StructureStart()
{
	boundingBox = NULL;		// 4J added initialiser
}

StructureStart::~StructureStart()
{
	for(AUTO_VAR(it, pieces.begin()); it != pieces.end(); it++ )
	{
		delete (*it);
	}
	delete boundingBox;
}

BoundingBox *StructureStart::getBoundingBox()
{
	return boundingBox;
}

list<StructurePiece *> *StructureStart::getPieces()
{
	return &pieces;
}

void StructureStart::postProcess(Level *level, Random *random, BoundingBox *chunkBB)
{
	AUTO_VAR(it, pieces.begin());

	while( it != pieces.end() )
	{
		if( (*it)->getBoundingBox()->intersects(chunkBB) && !(*it)->postProcess(level, random, chunkBB))
		{
            // this piece can't be placed, so remove it to avoid future
            // attempts
			it = pieces.erase(it);
		}
		else
		{
			it++;
		}
	}
}

void StructureStart::calculateBoundingBox()
{
    boundingBox = BoundingBox::getUnknownBox();

	for( AUTO_VAR(it, pieces.begin()); it != pieces.end(); it++ )
	{
		StructurePiece *piece = *it;
		boundingBox->expand(piece->getBoundingBox());
	}
}

void StructureStart::moveBelowSeaLevel(Level *level, Random *random, int offset)
{
	const int MAX_Y = level->seaLevel - offset;

    // set lowest possible position (at bedrock)
    int y1Pos = boundingBox->getYSpan() + 1;
    // move up randomly within the available span
    if (y1Pos < MAX_Y)
	{
        y1Pos += random->nextInt(MAX_Y - y1Pos);
    }

    // move all bounding boxes
    int dy = y1Pos - boundingBox->y1;
    boundingBox->move(0, dy, 0);
	for( AUTO_VAR(it, pieces.begin()); it != pieces.end(); it++ )
	{
		StructurePiece *piece = *it;
        piece->getBoundingBox()->move(0, dy, 0);
    }
}

void StructureStart::moveInsideHeights(Level *level, Random *random, int lowestAllowed, int highestAllowed)
{
    int heightSpan = highestAllowed - lowestAllowed + 1 - boundingBox->getYSpan();
    int y0Pos = 1;

    if (heightSpan > 1)
	{
        y0Pos = lowestAllowed + random->nextInt(heightSpan);
    }
	else
	{
        y0Pos = lowestAllowed;
    }

    // move all bounding boxes
    int dy = y0Pos - boundingBox->y0;
    boundingBox->move(0, dy, 0);
	for( AUTO_VAR(it, pieces.begin()); it != pieces.end(); it++ )
	{
		StructurePiece *piece = *it;
        piece->getBoundingBox()->move(0, dy, 0);
    }
}

bool StructureStart::isValid()
{
	return true;
}