From: Perttu Ahola Date: Sun, 13 Nov 2011 01:17:42 +0000 (+0200) Subject: Better spawn position finding and checking X-Git-Url: http://81.2.79.47:8989/gitweb/?a=commitdiff_plain;h=7372282a725cc9633eba3bb7bae8f4055e3235bb;p=zefram%2Fminetest%2Fminetest_engine.git Better spawn position finding and checking --- diff --git a/src/server.cpp b/src/server.cpp index 52e9dc87..33038872 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -4136,8 +4136,7 @@ v3f findSpawnPos(ServerMap &map) { //return v3f(50,50,50)*BS; - v2s16 nodepos; - s16 groundheight = 0; + v3s16 nodepos; #if 0 nodepos = v2s16(0,0); @@ -4150,13 +4149,11 @@ v3f findSpawnPos(ServerMap &map) { s32 range = 1 + i; // We're going to try to throw the player to this position - nodepos = v2s16(-range + (myrand()%(range*2)), + v2s16 nodepos2d = v2s16(-range + (myrand()%(range*2)), -range + (myrand()%(range*2))); - v2s16 sectorpos = getNodeSectorPos(nodepos); - // Get sector (NOTE: Don't get because it's slow) - //m_env.getMap().emergeSector(sectorpos); + //v2s16 sectorpos = getNodeSectorPos(nodepos2d); // Get ground height at point (fallbacks to heightmap function) - groundheight = map.findGroundLevel(nodepos); + s16 groundheight = map.findGroundLevel(nodepos2d); // Don't go underwater if(groundheight < WATER_LEVEL) { @@ -4169,22 +4166,33 @@ v3f findSpawnPos(ServerMap &map) //infostream<<"-> Underwater"<= 2){ + is_good = true; + nodepos.Y -= 1; + break; + } + } + nodepos.Y++; + } + if(is_good){ + // Found a good place + //infostream<<"Searched through "<