Vector3 DestroyMissionObjectiveImplementation::findValidSpawnPosition(Zone* zone) { Vector3 position; float newX = spawnActiveArea->getPositionX() + (256.0f - (float) System::random(512)); float newY = spawnActiveArea->getPositionY() + (256.0f - (float) System::random(512)); float height = zone->getHeight(newX, newY); float waterHeight; PlanetManager* planetManager = zone->getPlanetManager(); float distance = 128; int tries = 0; float size = mission.get()->getSize(); position.set(newX, height, newY); while ((!planetManager->isSpawningPermittedAt(newX, newY, size) || CollisionManager::checkSphereCollision(position, size + 25.f , zone)) && tries < 256) { newX = spawnActiveArea->getPositionX() + (distance - (float) System::random(distance * 2)); newY = spawnActiveArea->getPositionY() + (distance - (float) System::random(distance * 2)); height = zone->getHeight(newX, newY); position.set(newX, height, newY); ++tries; //Increase distance every if 32 tries failed. if (tries % 32 == 0) { distance = distance * 2; } } if (tries == 128) { //Failed to find a spawn point for the lair, fail mission. getPlayerOwner().get()->sendSystemMessage("@mission/mission_generic:failed"); fail(); } //info("found with tries " + String::valueOf(tries), true); return position; }