Break out ocean ruins and shipwrecks to their own functions.

This commit is contained in:
Tom Schumm 2018-07-08 20:01:00 -07:00
parent 369105baa8
commit ab45a0a1d2
3 changed files with 83 additions and 53 deletions

View File

@ -109,18 +109,10 @@ int main(int argc, char *argv[])
{
base = moveStructure(qhcandidates[i], regPosX, regPosZ);
qhpos[0] = getStructurePos(
featureSeed, FEATURE_REGION_SIZE, FEATURE_CHUNK_RANGE,
base, 0+regPosX, 0+regPosZ);
qhpos[1] = getStructurePos(
featureSeed, FEATURE_REGION_SIZE, FEATURE_CHUNK_RANGE,
base, 0+regPosX, 1+regPosZ);
qhpos[2] = getStructurePos(
featureSeed, FEATURE_REGION_SIZE, FEATURE_CHUNK_RANGE,
base, 1+regPosX, 0+regPosZ);
qhpos[3] = getStructurePos(
featureSeed, FEATURE_REGION_SIZE, FEATURE_CHUNK_RANGE,
base, 1+regPosX, 1+regPosZ);
qhpos[0] = getStructurePos(featureSeed, base, 0+regPosX, 0+regPosZ);
qhpos[1] = getStructurePos(featureSeed, base, 0+regPosX, 1+regPosZ);
qhpos[2] = getStructurePos(featureSeed, base, 1+regPosX, 0+regPosZ);
qhpos[3] = getStructurePos(featureSeed, base, 1+regPosX, 1+regPosZ);
/*
for(j = 0; j < 4; j++)

View File

@ -690,35 +690,68 @@ int getBiomeAtPos(const LayerStack g, const Pos pos)
return biomeID;
}
Pos getOceanRuinPos(int64_t seed, const int64_t regionX, const int64_t regionZ) {
Pos pos;
// set seed
seed = regionX*341873128712 + regionZ*132897987541 + seed + OCEAN_RUIN_SEED;
seed = (seed ^ 0x5DEECE66DLL);// & ((1LL << 48) - 1);
seed = (seed * 0x5DEECE66DLL + 0xBLL) & 0xffffffffffff;
// Java RNG treats powers of 2 as a special case.
pos.x = (8 * (seed >> 17)) >> 31;
seed = (seed * 0x5DEECE66DLL + 0xBLL) & 0xffffffffffff;
pos.z = (8 * (seed >> 17)) >> 31;
pos.x = regionX*256 + (pos.x << 4) + 8;
pos.z = regionZ*256 + (pos.z << 4) + 8;
return pos;
}
Pos getShipwreckPos(int64_t seed, const int64_t regionX, const int64_t regionZ) {
Pos pos;
// set seed
seed = regionX*341873128712 + regionZ*132897987541 + seed + SHIPWRECK_SEED;
seed = (seed ^ 0x5DEECE66DLL);// & ((1LL << 48) - 1);
seed = (seed * 0x5DEECE66DLL + 0xBLL) & 0xffffffffffff;
pos.x = (seed >> 17) % 7;
seed = (seed * 0x5DEECE66DLL + 0xBLL) & 0xffffffffffff;
pos.z = (seed >> 17) % 7;
pos.x = regionX*240 + (pos.x << 4) + 8;
pos.z = regionZ*240 + (pos.z << 4) + 8;
return pos;
}
/* getStructurePos
* ---------------
* Fast implementation for finding the block position at which the structure
* generation attempt will occur in the specified region.
* This function applies for scattered-feature structureSeeds and villages.
*/
Pos getStructurePos(const int64_t structureSeed, const int regionSize, const int chunkRange,
int64_t seed, const int64_t regionX, const int64_t regionZ)
Pos getStructurePos(const int64_t structureSeed, int64_t seed,
const int64_t regionX, const int64_t regionZ)
{
Pos pos;
// set seed
seed = regionX*341873128712 + regionZ*132897987541 + seed + structureSeed;
seed = (seed ^ 0x5DEECE66DLL);// & ((1LL << 48) - 1);
seed = (seed * 0x5DEECE66DLL + 0xBLL) & 0xffffffffffff;
if ((chunkRange & (chunkRange-1)) == 0) {
// Java RNG treats powers of 2 as a special case.
pos.x = (chunkRange * (seed >> 17)) >> 31;
seed = (seed * 0x5DEECE66DLL + 0xBLL) & 0xffffffffffff;
pos.z = (chunkRange * (seed >> 17)) >> 31;
} else {
pos.x = (seed >> 17) % chunkRange;
seed = (seed * 0x5DEECE66DLL + 0xBLL) & 0xffffffffffff;
pos.z = (seed >> 17) % chunkRange;
}
pos.x = (seed >> 17) % 24;
pos.x = ((regionX*regionSize + pos.x) << 4) + 8;
pos.z = ((regionZ*regionSize + pos.z) << 4) + 8;
seed = (seed * 0x5DEECE66DLL + 0xBLL) & 0xffffffffffff;
pos.z = (seed >> 17) % 24;
pos.x = regionX*512 + (pos.x << 4) + 8;
pos.z = regionZ*512 + (pos.z << 4) + 8;
return pos;
}
@ -729,8 +762,8 @@ Pos getStructurePos(const int64_t structureSeed, const int regionSize, const int
* the structure generation attempt will occur.
* This function applies for scattered-feature structureSeeds and villages.
*/
Pos getStructureChunkInRegion(const int64_t structureSeed, const int chunkRange,
int64_t seed, const int regionX, const int regionZ)
Pos getStructureChunkInRegion(const int64_t structureSeed, int64_t seed,
const int regionX, const int regionZ)
{
/*
// Vanilla like implementation.
@ -743,21 +776,14 @@ Pos getStructureChunkInRegion(const int64_t structureSeed, const int chunkRange,
*/
Pos pos;
// set seed
seed = regionX*341873128712 + regionZ*132897987541 + seed + structureSeed;
seed = (seed ^ 0x5DEECE66DLL);// & ((1LL << 48) - 1);
seed = (seed * 0x5DEECE66DLL + 0xBLL) & 0xffffffffffff;
if ((chunkRange & (chunkRange-1)) == 0) {
// Java RNG treats powers of 2 as a special case.
pos.x = (chunkRange * (seed >> 17)) >> 31;
seed = (seed * 0x5DEECE66DLL + 0xBLL) & 0xffffffffffff;
pos.z = (chunkRange * (seed >> 17)) >> 31;
} else {
pos.x = (seed >> 17) % chunkRange;
seed = (seed * 0x5DEECE66DLL + 0xBLL) & 0xffffffffffff;
pos.z = (seed >> 17) % chunkRange;
}
pos.x = (seed >> 17) % 24;
seed = (seed * 0x5DEECE66DLL + 0xBLL) & 0xffffffffffff;
pos.z = (seed >> 17) % 24;
return pos;
}

View File

@ -162,6 +162,29 @@ void search4QuadBases(const char *fnam, int threads, const int64_t structureSeed
int getBiomeAtPos(const LayerStack g, const Pos pos);
/* getOceanRuinPos
* ---------------
* Fast implementation for finding the block position at which an ocean ruin
* generation attempt will occur in the specified region.
*/
Pos getOceanRuinPos(int64_t seed, const int64_t regionX, const int64_t regionZ);
/* getShipwreckPos
* ---------------
* Fast implementation for finding the block position at which a shipwreck
* generation attempt will occur in the specified region.
*/
Pos getShipwreckPos(int64_t seed, const int64_t regionX, const int64_t regionZ);
/* getStructurePos
* ---------------
* Fast implementation for finding the block position at which the structure
* generation attempt will occur in the specified region.
* This function applies for scattered-feature structureSeeds and villages.
*/
Pos getStructurePos(const int64_t structureSeed, int64_t seed,
const int64_t regionX, const int64_t regionZ);
/* getStructureChunkInRegion
* -------------------------
* Finds the chunk position within the specified region (a square region of
@ -170,19 +193,8 @@ int getBiomeAtPos(const LayerStack g, const Pos pos);
*
* This function applies for scattered-feature structureSeeds and villages.
*/
Pos getStructureChunkInRegion(const int64_t structureSeed, const int chunkRange,
int64_t seed, const int regionX, const int regionZ);
/* getStructurePos
* ---------------
* Fast implementation for finding the block position at which the structure
* generation attempt will occur in the specified region.
* This function applies for scattered-feature structureSeeds and villages.
*/
Pos getStructurePos(const int64_t structureSeed, const int chunkRange,
const int regionSize, int64_t seed, const int64_t regionX, const int64_t regionZ);
Pos getStructureChunkInRegion(const int64_t structureSeed, int64_t seed,
const int regionX, const int regionZ);
/* getOceanMonumentPos
* -------------------