void GameStateManager::SwitchToState(GameStateID gsid) { switch (gsid) { case GSID_TITLE: PrepareState(m_titleScreen); break; case GSID_MAIN: PrepareState(m_game); break; default: throw std::runtime_error("Cannot recognise the given GameStateID"); } }
void cEndGen::ComposeTerrain(cChunkDesc & a_ChunkDesc) { if (IsChunkOutsideRange(a_ChunkDesc.GetChunkX(), a_ChunkDesc.GetChunkZ())) { a_ChunkDesc.FillBlocks(E_BLOCK_AIR, 0); return; } PrepareState(a_ChunkDesc.GetChunkX(), a_ChunkDesc.GetChunkZ()); int MaxY = std::min((int)(1.75 * m_IslandSizeY + 1), cChunkDef::Height - 1); for (int z = 0; z < cChunkDef::Width; z++) { for (int x = 0; x < cChunkDef::Width; x++) { for (int y = MaxY; y > 0; y--) { if (m_NoiseArray[y * 17 * 17 + z * 17 + x] <= 0) { a_ChunkDesc.SetBlockTypeMeta(x, y, z, E_BLOCK_END_STONE, 0); } else { a_ChunkDesc.SetBlockTypeMeta(x, y, z, E_BLOCK_AIR, 0); } } // for y } // for x } // for z }
void cEndGen::GenHeightMap(int a_ChunkX, int a_ChunkZ, cChunkDef::HeightMap & a_HeightMap) { if (IsChunkOutsideRange(a_ChunkX, a_ChunkZ)) { for (unsigned int i = 0; i < ARRAYCOUNT(a_HeightMap); i++) { a_HeightMap[i] = 0; } return; } PrepareState(a_ChunkX, a_ChunkZ); int MaxY = std::min((int)(1.75 * m_IslandSizeY + 1), cChunkDef::Height - 1); for (int z = 0; z < cChunkDef::Width; z++) { for (int x = 0; x < cChunkDef::Width; x++) { cChunkDef::SetHeight(a_HeightMap, x, z, MaxY); for (int y = MaxY; y > 0; y--) { if (m_NoiseArray[y * 17 * 17 + z * 17 + x] <= 0) { cChunkDef::SetHeight(a_HeightMap, x, z, y); break; } } // for y } // for x } // for z }
void cDistortedHeightmap::ComposeTerrain(cChunkDesc & a_ChunkDesc) { // Prepare the internal state for generating this chunk: PrepareState(a_ChunkDesc.GetChunkX(), a_ChunkDesc.GetChunkZ()); // Compose: a_ChunkDesc.FillBlocks(E_BLOCK_AIR, 0); for (int z = 0; z < cChunkDef::Width; z++) { for (int x = 0; x < cChunkDef::Width; x++) { ComposeColumn(a_ChunkDesc, x, z); } // for x } // for z }
///////////////////////////////////////////////////////////////////////////// // Prepare "m_bitmaps[???]" for all possible states // // HDC hDC - DC used to create memory DCs for bitmap preparation // // HBITMAP &bmpDest - this parameter is one of the following: // m_bitmaps[ 0 ] : BOX_ON bitmap // m_bitmaps[ 1 ] : BOX_OFF bitmap // ... // m_bitmaps[ 5 ] : BOX_DISABLED_2 bitmap // // int nState - specifies the state of the CB and can be: // BOX_ON // BOX_OFF // BOX_LDOWN_1 // BOX_LDOWN_2 // BOX_DISABLED_1 // BOX_DISABLED_2 ///////////////////////////////////////////////////////////////////////////// void ZCheckBox::PrepareBitmaps( HDC hDC ) { m_nHeight = GetMinHeight( hDC ); if ( m_nHeight < BOX_SIZE ) m_nHeight = BOX_SIZE; PrepareState( hDC, m_bitmaps[ 0 ], BOX_ON ); PrepareState( hDC, m_bitmaps[ 1 ], BOX_OFF ); PrepareState( hDC, m_bitmaps[ 2 ], BOX_LDOWN_1 ); PrepareState( hDC, m_bitmaps[ 3 ], BOX_LDOWN_2 ); PrepareState( hDC, m_bitmaps[ 4 ], BOX_DISABLED_1 ); PrepareState( hDC, m_bitmaps[ 5 ], BOX_DISABLED_2 ); }
void cDistortedHeightmap::GenHeightMap(int a_ChunkX, int a_ChunkZ, cChunkDef::HeightMap & a_HeightMap) { PrepareState(a_ChunkX, a_ChunkZ); for (int z = 0; z < cChunkDef::Width; z++) { for (int x = 0; x < cChunkDef::Width; x++) { int NoiseArrayIdx = x + 17 * 257 * z; cChunkDef::SetHeight(a_HeightMap, x, z, m_SeaLevel - 1); for (int y = cChunkDef::Height - 1; y > m_SeaLevel - 1; y--) { int HeightMapHeight = (int)m_DistortedHeightmap[NoiseArrayIdx + 17 * y]; if (y < HeightMapHeight) { cChunkDef::SetHeight(a_HeightMap, x, z, y); break; } } // for y } // for x } // for z }
void cDistortedHeightmap::ComposeTerrain(cChunkDesc & a_ChunkDesc) { // Frequencies for the ocean floor selecting noise: NOISE_DATATYPE FrequencyX = 3; NOISE_DATATYPE FrequencyZ = 3; // Prepare the internal state for generating this chunk: PrepareState(a_ChunkDesc.GetChunkX(), a_ChunkDesc.GetChunkZ()); // Compose: a_ChunkDesc.FillBlocks(E_BLOCK_AIR, 0); for (int z = 0; z < cChunkDef::Width; z++) { for (int x = 0; x < cChunkDef::Width; x++) { int NoiseArrayIdx = x + 17 * 257 * z; int LastAir = a_ChunkDesc.GetHeight(x, z) + 1; bool HasHadWater = false; for (int y = LastAir - 1; y > 0; y--) { int HeightMapHeight = (int)m_DistortedHeightmap[NoiseArrayIdx + 17 * y]; if (y >= HeightMapHeight) { // "air" part LastAir = y; if (y < m_SeaLevel) { a_ChunkDesc.SetBlockType(x, y, z, E_BLOCK_STATIONARY_WATER); HasHadWater = true; } continue; } // "ground" part: if (y < LastAir - 4) { a_ChunkDesc.SetBlockType(x, y, z, E_BLOCK_STONE); continue; } if (HasHadWater) { // Decide between clay, sand and dirt NOISE_DATATYPE NoiseX = ((NOISE_DATATYPE)(m_CurChunkX * cChunkDef::Width + x)) / FrequencyX; NOISE_DATATYPE NoiseY = ((NOISE_DATATYPE)(m_CurChunkZ * cChunkDef::Width + z)) / FrequencyZ; NOISE_DATATYPE Val = m_OceanFloorSelect.CubicNoise2D(NoiseX, NoiseY); if (Val < -0.95) { // Clay: switch (LastAir - y) { case 0: case 1: { a_ChunkDesc.SetBlockType(x, y, z, E_BLOCK_CLAY); break; } case 2: case 3: { a_ChunkDesc.SetBlockType(x, y, z, E_BLOCK_SAND); break; } case 4: { a_ChunkDesc.SetBlockType(x, y, z, E_BLOCK_SANDSTONE); break; } } // switch (floor depth) } else if (Val < 0) { a_ChunkDesc.SetBlockType(x, y, z, (y < LastAir - 3) ? E_BLOCK_SANDSTONE : E_BLOCK_SAND); } else { a_ChunkDesc.SetBlockType(x, y, z, E_BLOCK_DIRT); } } else { switch (a_ChunkDesc.GetBiome(x, z)) { case biOcean: case biPlains: case biExtremeHills: case biForest: case biTaiga: case biSwampland: case biRiver: case biFrozenOcean: case biFrozenRiver: case biIcePlains: case biIceMountains: case biForestHills: case biTaigaHills: case biExtremeHillsEdge: case biJungle: case biJungleHills: { a_ChunkDesc.SetBlockType(x, y, z, (y == LastAir - 1) ? E_BLOCK_GRASS : E_BLOCK_DIRT); break; } case biDesertHills: case biDesert: case biBeach: { a_ChunkDesc.SetBlockType(x, y, z, (y < LastAir - 3) ? E_BLOCK_SANDSTONE : E_BLOCK_SAND); break; } case biMushroomIsland: case biMushroomShore: { a_ChunkDesc.SetBlockType(x, y, z, (y == LastAir - 1) ? E_BLOCK_MYCELIUM : E_BLOCK_DIRT); break; } } } } // for y a_ChunkDesc.SetBlockType(x, 0, z, E_BLOCK_BEDROCK); } // for x } // for z }