diff --git a/src/client/creatures.cpp b/src/client/creatures.cpp index 9a9b2fb0..57d64283 100644 --- a/src/client/creatures.cpp +++ b/src/client/creatures.cpp @@ -369,6 +369,20 @@ SpawnPtr CreatureManager::getSpawn(const Position& centerPos) return nullptr; } +SpawnPtr CreatureManager::getSpawnForPlacePos(const Position& pos) +{ + for (const auto& pair : m_spawns) { + const Position& centerPos = pair.first; + const SpawnPtr& spawn = pair.second; + + if (isInZone(pos, centerPos, spawn->getRadius())) + return spawn; + } + + g_logger.debug(stdext::format("failed to find spawn at %s", stdext::to_string(pos))); + return nullptr; +} + SpawnPtr CreatureManager::addSpawn(const Position& centerPos, int radius) { auto iter = m_spawns.find(centerPos); diff --git a/src/client/creatures.h b/src/client/creatures.h index b20b1d58..4e2fb531 100644 --- a/src/client/creatures.h +++ b/src/client/creatures.h @@ -121,6 +121,7 @@ public: const CreatureTypePtr& getCreatureByLook(int look); SpawnPtr getSpawn(const Position& centerPos); + SpawnPtr getSpawnForPlacePos(const Position& pos); SpawnPtr addSpawn(const Position& centerPos, int radius); bool isLoaded() { return m_loaded; } diff --git a/src/client/luafunctions.cpp b/src/client/luafunctions.cpp index f71dace8..031a19de 100644 --- a/src/client/luafunctions.cpp +++ b/src/client/luafunctions.cpp @@ -155,6 +155,7 @@ void Client::registerLuaFunctions() g_lua.bindSingletonFunction("g_creatures", "getCreatureByName", &CreatureManager::getCreatureByName, &g_creatures); g_lua.bindSingletonFunction("g_creatures", "getCreatureByLook", &CreatureManager::getCreatureByLook, &g_creatures); g_lua.bindSingletonFunction("g_creatures", "getSpawn", &CreatureManager::getSpawn, &g_creatures); + g_lua.bindSingletonFunction("g_creatures", "getSpawnForPlacePos", &CreatureManager::getSpawnForPlacePos, &g_creatures); g_lua.bindSingletonFunction("g_creatures", "addSpawn", &CreatureManager::addSpawn, &g_creatures); g_lua.bindSingletonFunction("g_creatures", "loadMonsters", &CreatureManager::loadMonsters, &g_creatures); g_lua.bindSingletonFunction("g_creatures", "loadNpcs", &CreatureManager::loadNpcs, &g_creatures);