Spawns: add function to find a spawn to place a creature on
This commit is contained in:
parent
f615b80fbc
commit
b9b9a32b83
|
@ -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);
|
||||
|
|
|
@ -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; }
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue