diff --git a/src/client/creatures.cpp b/src/client/creatures.cpp index d6498775..8325cac0 100644 --- a/src/client/creatures.cpp +++ b/src/client/creatures.cpp @@ -144,6 +144,14 @@ void Spawn::removeCreature(const Position& pos) } } +std::vector Spawn::getCreatures() +{ + std::vector creatures; + for (auto p : m_creatures) + creatures.push_back(p.second); + return creatures; +} + CreaturePtr CreatureType::cast() { CreaturePtr ret(new Creature); @@ -399,5 +407,12 @@ SpawnPtr CreatureManager::addSpawn(const Position& centerPos, int radius) return ret; } -/* vim: set ts=4 sw=4 et: */ +std::vector CreatureManager::getSpawns() +{ + std::vector spawns; + for (auto p : m_spawns) + spawns.push_back(p.second); + return spawns; +} +/* vim: set ts=4 sw=4 et: */ diff --git a/src/client/creatures.h b/src/client/creatures.h index 4e2fb531..5ddc5bf6 100644 --- a/src/client/creatures.h +++ b/src/client/creatures.h @@ -61,6 +61,7 @@ public: void setCenterPos(const Position& pos) { m_attribs.set(SpawnAttrCenter, pos); } Position getCenterPos() { return m_attribs.get(SpawnAttrCenter); } + std::vector getCreatures(); void addCreature(const Position& placePos, const CreatureTypePtr& cType); void removeCreature(const Position& pos); void clear() { m_creatures.clear(); } @@ -120,6 +121,7 @@ public: const CreatureTypePtr& getCreatureByName(std::string name); const CreatureTypePtr& getCreatureByLook(int look); + std::vector getSpawns(); SpawnPtr getSpawn(const Position& centerPos); SpawnPtr getSpawnForPlacePos(const Position& pos); SpawnPtr addSpawn(const Position& centerPos, int radius); diff --git a/src/client/declarations.h b/src/client/declarations.h index c3dc86c7..17c4fe17 100644 --- a/src/client/declarations.h +++ b/src/client/declarations.h @@ -82,6 +82,8 @@ typedef std::list TownList; typedef std::list ItemList; typedef std::vector ItemVector; typedef std::unordered_map TileMap; +typedef std::unordered_map CreatureMap; +typedef std::unordered_map SpawnMap; // net class ProtocolLogin; diff --git a/src/client/luafunctions.cpp b/src/client/luafunctions.cpp index 2f86a9fd..965079e1 100644 --- a/src/client/luafunctions.cpp +++ b/src/client/luafunctions.cpp @@ -172,6 +172,7 @@ void Client::registerLuaFunctions() g_lua.bindSingletonFunction("g_creatures", "isSpawnLoaded", &CreatureManager::isSpawnLoaded, &g_creatures); g_lua.bindSingletonFunction("g_creatures", "clear", &CreatureManager::clear, &g_creatures); g_lua.bindSingletonFunction("g_creatures", "clearSpawns", &CreatureManager::clearSpawns, &g_creatures); + g_lua.bindSingletonFunction("g_creatures", "getSpawns", &CreatureManager::getSpawns, &g_creatures); g_lua.registerSingletonClass("g_game"); g_lua.bindSingletonFunction("g_game", "loginWorld", &Game::loginWorld, &g_game); @@ -398,6 +399,7 @@ void Client::registerLuaFunctions() g_lua.bindClassMemberFunction("getCenterPos", &Spawn::getCenterPos); g_lua.bindClassMemberFunction("addCreature", &Spawn::addCreature); g_lua.bindClassMemberFunction("removeCreature", &Spawn::removeCreature); + g_lua.bindClassMemberFunction("getCreatures", &Spawn::getCreatures); g_lua.registerClass(); g_lua.bindClassStaticFunction("create", []{ return TownPtr(new Town); });