-s16 ServerMap::findGroundLevel(v2s16 p2d)
-{
-#if 0
- /*
- Uh, just do something random...
- */
- // Find existing map from top to down
- s16 max=63;
- s16 min=-64;
- v3s16 p(p2d.X, max, p2d.Y);
- for(; p.Y>min; p.Y--)
- {
- MapNode n = getNodeNoEx(p);
- if(n.getContent() != CONTENT_IGNORE)
- break;
- }
- if(p.Y == min)
- goto plan_b;
- // If this node is not air, go to plan b
- if(getNodeNoEx(p).getContent() != CONTENT_AIR)
- goto plan_b;
- // Search existing walkable and return it
- for(; p.Y>min; p.Y--)
- {
- MapNode n = getNodeNoEx(p);
- if(content_walkable(n.d) && n.getContent() != CONTENT_IGNORE)
- return p.Y;
- }
-
- // Move to plan b
-plan_b:
-#endif
-
- /*
- Determine from map generator noise functions
- */
-
- s16 level = m_emerge->getGroundLevelAtPoint(p2d);
- return level;
-
- //double level = base_rock_level_2d(m_seed, p2d) + AVERAGE_MUD_AMOUNT;
- //return (s16)level;
-}
-
-bool ServerMap::loadFromFolders() {
- if (!dbase->initialized() &&
- !fs::PathExists(m_savedir + DIR_DELIM + "map.sqlite"))
- return true;
- return false;
-}
-
-void ServerMap::createDirs(std::string path)
-{
- if (!fs::CreateAllDirs(path)) {
- m_dout<<"ServerMap: Failed to create directory "
- <<"\""<<path<<"\""<<std::endl;
- throw BaseException("ServerMap failed to create directory");
- }
-}
-
-std::string ServerMap::getSectorDir(v2s16 pos, int layout)
-{
- char cc[9];
- switch(layout)
- {
- case 1:
- snprintf(cc, 9, "%.4x%.4x",
- (unsigned int) pos.X & 0xffff,
- (unsigned int) pos.Y & 0xffff);
-
- return m_savedir + DIR_DELIM + "sectors" + DIR_DELIM + cc;
- case 2:
- snprintf(cc, 9, (std::string("%.3x") + DIR_DELIM + "%.3x").c_str(),
- (unsigned int) pos.X & 0xfff,
- (unsigned int) pos.Y & 0xfff);
-
- return m_savedir + DIR_DELIM + "sectors2" + DIR_DELIM + cc;
- default:
- assert(false);
- return "";
- }
-}
-
-v2s16 ServerMap::getSectorPos(const std::string &dirname)
-{
- unsigned int x = 0, y = 0;
- int r;
- std::string component;
- fs::RemoveLastPathComponent(dirname, &component, 1);
- if(component.size() == 8)
- {
- // Old layout
- r = sscanf(component.c_str(), "%4x%4x", &x, &y);
- }
- else if(component.size() == 3)
- {
- // New layout
- fs::RemoveLastPathComponent(dirname, &component, 2);
- r = sscanf(component.c_str(), (std::string("%3x") + DIR_DELIM + "%3x").c_str(), &x, &y);
- // Sign-extend the 12 bit values up to 16 bits...
- if(x & 0x800) x |= 0xF000;
- if(y & 0x800) y |= 0xF000;
- }
- else
- {
- r = -1;
- }
-
- FATAL_ERROR_IF(r != 2, "getSectorPos()");
- v2s16 pos((s16)x, (s16)y);
- return pos;
-}
-
-v3s16 ServerMap::getBlockPos(const std::string §ordir, const std::string &blockfile)
-{
- v2s16 p2d = getSectorPos(sectordir);
-
- if(blockfile.size() != 4){
- throw InvalidFilenameException("Invalid block filename");
- }
- unsigned int y;
- int r = sscanf(blockfile.c_str(), "%4x", &y);
- if(r != 1)
- throw InvalidFilenameException("Invalid block filename");
- return v3s16(p2d.X, y, p2d.Y);
-}
-
-std::string ServerMap::getBlockFilename(v3s16 p)
-{
- char cc[5];
- snprintf(cc, 5, "%.4x", (unsigned int)p.Y&0xffff);
- return cc;
-}
-