Initial VillageGen implementation.
WIP, doesn't generate anything yet. Ref.: 740.
This commit is contained in:
parent
7e71f1f7dc
commit
c0727c4265
3726
src/Generating/Prefabs/PlainsVillagePrefabs.cpp
Normal file
3726
src/Generating/Prefabs/PlainsVillagePrefabs.cpp
Normal file
File diff suppressed because it is too large
Load Diff
15
src/Generating/Prefabs/PlainsVillagePrefabs.h
Normal file
15
src/Generating/Prefabs/PlainsVillagePrefabs.h
Normal file
@ -0,0 +1,15 @@
|
||||
|
||||
// PlainsVillagePrefabs.h
|
||||
|
||||
// Declares the prefabs in the group PlainsVillage
|
||||
|
||||
#include "../Prefab.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
extern const cPrefab::sDef g_PlainsVillagePrefabs[];
|
||||
extern const cPrefab::sDef g_PlainsVillageStartingPrefabs[];
|
||||
extern const size_t g_PlainsVillagePrefabsCount;
|
||||
extern const size_t g_PlainsVillageStartingPrefabsCount;
|
1887
src/Generating/Prefabs/SandVillagePrefabs.cpp
Normal file
1887
src/Generating/Prefabs/SandVillagePrefabs.cpp
Normal file
File diff suppressed because it is too large
Load Diff
15
src/Generating/Prefabs/SandVillagePrefabs.h
Normal file
15
src/Generating/Prefabs/SandVillagePrefabs.h
Normal file
@ -0,0 +1,15 @@
|
||||
|
||||
// SandVillagePrefabs.h
|
||||
|
||||
// Declares the prefabs in the group SandVillage
|
||||
|
||||
#include "../Prefab.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
extern const cPrefab::sDef g_SandVillagePrefabs[];
|
||||
extern const cPrefab::sDef g_SandVillageStartingPrefabs[];
|
||||
extern const size_t g_SandVillagePrefabsCount;
|
||||
extern const size_t g_SandVillageStartingPrefabsCount;
|
116
src/Generating/VillageGen.cpp
Normal file
116
src/Generating/VillageGen.cpp
Normal file
@ -0,0 +1,116 @@
|
||||
|
||||
// VillageGen.cpp
|
||||
|
||||
// Implements the cVillageGen class representing the village generator
|
||||
|
||||
#include "Globals.h"
|
||||
#include "VillageGen.h"
|
||||
#include "Prefabs/PlainsVillagePrefabs.h"
|
||||
#include "Prefabs/SandVillagePrefabs.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class cVillageGen::cVillage :
|
||||
public cGridStructGen::cStructure
|
||||
{
|
||||
typedef cGridStructGen::cStructure super;
|
||||
|
||||
public:
|
||||
cVillage(int a_Seed, int a_OriginX, int a_OriginZ, cPrefabPiecePool & a_Prefabs) :
|
||||
super(a_OriginX, a_OriginZ),
|
||||
m_Seed(a_Seed),
|
||||
m_Prefabs(a_Prefabs)
|
||||
{
|
||||
}
|
||||
|
||||
protected:
|
||||
/** Seed for the random functions */
|
||||
int m_Seed;
|
||||
|
||||
/** Prefabs to use for buildings */
|
||||
cPrefabPiecePool & m_Prefabs;
|
||||
|
||||
// cGrdStructGen::cStructure overrides:
|
||||
virtual void DrawIntoChunk(cChunkDesc & a_Chunk) override
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
} ;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// cVillageGen:
|
||||
|
||||
cPrefabPiecePool cVillageGen::m_SandVillage (g_SandVillagePrefabs, g_SandVillagePrefabsCount, g_SandVillageStartingPrefabs, g_SandVillageStartingPrefabsCount);
|
||||
cPrefabPiecePool cVillageGen::m_PlainsVillage(g_PlainsVillagePrefabs, g_PlainsVillagePrefabsCount, g_PlainsVillageStartingPrefabs, g_PlainsVillageStartingPrefabsCount);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
cVillageGen::cVillageGen(int a_Seed, int a_GridSize, cBiomeGen & a_BiomeGen, cTerrainHeightGen & a_HeightGen) :
|
||||
super(a_Seed, a_GridSize, a_GridSize, 128, 128, 100),
|
||||
m_BiomeGen(a_BiomeGen),
|
||||
m_HeightGen(a_HeightGen)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
cGridStructGen::cStructurePtr cVillageGen::CreateStructure(int a_OriginX, int a_OriginZ)
|
||||
{
|
||||
// Generate the biomes for the chunk surrounding the origin:
|
||||
int ChunkX, ChunkZ;
|
||||
cChunkDef::BlockToChunk(a_OriginX, a_OriginZ, ChunkX, ChunkZ);
|
||||
cChunkDef::BiomeMap Biomes;
|
||||
m_BiomeGen.GenBiomes(ChunkX, ChunkZ, Biomes);
|
||||
|
||||
// Check if all the biomes are village-friendly:
|
||||
// If just one is not, no village is created, because it's likely that an unfriendly biome is too close
|
||||
cPrefabPiecePool * VillagePrefabs = NULL;
|
||||
for (size_t i = 0; i < ARRAYCOUNT(Biomes); i++)
|
||||
{
|
||||
switch (Biomes[i])
|
||||
{
|
||||
case biDesert:
|
||||
case biDesertM:
|
||||
{
|
||||
// These biomes allow sand villages
|
||||
VillagePrefabs = &m_SandVillage;
|
||||
break;
|
||||
}
|
||||
case biPlains:
|
||||
case biSavanna:
|
||||
case biSavannaM:
|
||||
case biSunflowerPlains:
|
||||
{
|
||||
// These biomes allow plains-style villages
|
||||
VillagePrefabs = &m_PlainsVillage;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
// Village-unfriendly biome, bail out with zero structure:
|
||||
return cStructurePtr();
|
||||
}
|
||||
} // switch (Biomes[i])
|
||||
} // for i - Biomes[]
|
||||
|
||||
// Create a village based on the chosen prefabs:
|
||||
if (VillagePrefabs == NULL)
|
||||
{
|
||||
return cStructurePtr();
|
||||
}
|
||||
return cStructurePtr(new cVillage(m_Seed, a_OriginX, a_OriginZ, *VillagePrefabs));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
48
src/Generating/VillageGen.h
Normal file
48
src/Generating/VillageGen.h
Normal file
@ -0,0 +1,48 @@
|
||||
|
||||
// VillageGen.h
|
||||
|
||||
// Declares the cVillageGen class representing the village generator
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "GridStructGen.h"
|
||||
#include "PrefabPiecePool.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class cVillageGen :
|
||||
public cGridStructGen
|
||||
{
|
||||
typedef cGridStructGen super;
|
||||
public:
|
||||
cVillageGen(int a_Seed, int a_GridSize, cBiomeGen & a_BiomeGen, cTerrainHeightGen & a_HeightGen);
|
||||
|
||||
protected:
|
||||
class cVillage; // fwd: VillageGen.cpp
|
||||
|
||||
/** The prefabs for the sand village. We're not exactly using the cPiecePool functionality, only the containment. */
|
||||
static cPrefabPiecePool m_SandVillage;
|
||||
|
||||
/** The prefabs for the plains village. We're not exactly using the cPiecePool functionality, only the containment. */
|
||||
static cPrefabPiecePool m_PlainsVillage;
|
||||
|
||||
/** The underlying biome generator that defines whether the village is created or not */
|
||||
cBiomeGen & m_BiomeGen;
|
||||
|
||||
/** The underlying height generator, used to position the prefabs crossing chunk borders */
|
||||
cTerrainHeightGen & m_HeightGen;
|
||||
|
||||
|
||||
// cGridStructGen overrides:
|
||||
virtual cStructurePtr CreateStructure(int a_OriginX, int a_OriginZ) override;
|
||||
} ;
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user