Bind missing C++ functions into lua

Signed-off-by: otfallen <f.fallen45@gmail.com>
master
otfallen 12 years ago
parent 68d2347ee5
commit 1156059af1

@ -144,6 +144,7 @@ CreaturePtr CreatureType::cast()
CreatureManager::CreatureManager()
{
m_nullCreature = CreatureTypePtr(new CreatureType);
m_nullSpawn = SpawnPtr(new Spawn);
}
void CreatureManager::clearSpawns()
@ -330,3 +331,20 @@ const CreatureTypePtr& CreatureManager::getCreatureByLook(int look)
g_logger.warning(stdext::format("could not find creature with looktype: %d", look));
return m_nullCreature;
}
const SpawnPtr& CreatureManager::getSpawn(const Position& centerPos)
{
// TODO instead of a list, a map could do better...
auto findFun = [=] (const SpawnPtr& sp) -> bool
{
const Position& center = sp->getCenterPos();
return center == centerPos;
};
auto it = std::find_if(m_spawns.begin(), m_spawns.end(), findFun);
if(it != m_spawns.end())
return *it;
// Let it be debug so in release versions it shouldn't annoy the user
g_logger.debug(stdext::format("failed to find spawn at center %s",stdext::to_string(centerPos)));
return m_nullSpawn;
}

@ -80,7 +80,7 @@ public:
void setSpawnTime(int32 spawnTime) { m_attribs.set(CreatureAttrSpawnTime, spawnTime); }
int32 getSpawnTime() { return m_attribs.get<int32>(CreatureAttrSpawnTime); }
void setName(const std::string& name) { m_attribs.set(CreatureAttrName, name); dump << "set"<<getName(); }
void setName(const std::string& name) { m_attribs.set(CreatureAttrName, name); }
std::string getName() { return m_attribs.get<std::string>(CreatureAttrName); }
void setOutfit(const Outfit& o) { m_attribs.set(CreatureAttrOutfit, o); }
@ -111,6 +111,7 @@ public:
const CreatureTypePtr& getCreatureByName(std::string name);
const CreatureTypePtr& getCreatureByLook(int look);
const SpawnPtr& getSpawn(const Position& centerPos);
bool isLoaded() { return m_loaded; }
bool isSpawnLoaded() { return m_spawnLoaded; }
@ -126,6 +127,7 @@ private:
std::vector<SpawnPtr> m_spawns;
stdext::boolean<false> m_loaded, m_spawnLoaded;
CreatureTypePtr m_nullCreature;
SpawnPtr m_nullSpawn;
};
extern CreatureManager g_creatures;

@ -110,12 +110,14 @@ void OTClient::registerLuaFunctions()
g_lua.bindSingletonFunction("g_map", "saveOtcm", &Map::saveOtcm, &g_map);
g_lua.bindSingletonFunction("g_map", "getHouseFile", &Map::getHouseFile, &g_map);
g_lua.bindSingletonFunction("g_map", "getSpawnFile", &Map::getSpawnFile, &g_map);
g_lua.bindSingletonFunction("g_map", "createTile", &Map::createTile, &g_map);
g_lua.registerSingletonClass("g_creatures");
g_lua.bindSingletonFunction("g_creatures", "getCreatures", &CreatureManager::getCreatures, &g_creatures);
g_lua.bindSingletonFunction("g_creatures", "getSpawns", &CreatureManager::getSpawns, &g_creatures);
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::getSpawns, &g_creatures);
g_lua.bindSingletonFunction("g_creatures", "loadMonsters", &CreatureManager::loadMonsters, &g_creatures);
g_lua.bindSingletonFunction("g_creatures", "loadNpcs", &CreatureManager::loadNpcs, &g_creatures);
g_lua.bindSingletonFunction("g_creatures", "loadSingleCreature", &CreatureManager::loadSingleCreature, &g_creatures);
@ -376,6 +378,7 @@ void OTClient::registerLuaFunctions()
g_lua.registerClass<Item, Thing>();
g_lua.bindClassStaticFunction<Item>("create", &Item::create);
g_lua.bindClassStaticFunction<Item>("createOtb", &Item::createFromOtb);
g_lua.bindClassMemberFunction<Item>("clone", &Item::clone);
g_lua.bindClassMemberFunction<Item>("setCount", &Item::setCount);
g_lua.bindClassMemberFunction<Item>("getCount", &Item::getCount);

@ -197,7 +197,6 @@ private:
std::unordered_map<uint, TileBlock> m_tileBlocks[Otc::MAX_Z+1];
std::unordered_map<uint32, CreaturePtr> m_knownCreatures;
std::unordered_map<Position, CreatureTypePtr, PositionHasher> m_creatureTypes;
std::array<std::vector<MissilePtr>, Otc::MAX_Z+1> m_floorMissiles;
std::vector<AnimatedTextPtr> m_animatedTexts;
std::vector<StaticTextPtr> m_staticTexts;

Loading…
Cancel
Save