diff --git a/src/framework/core/resourcemanager.cpp b/src/framework/core/resourcemanager.cpp index 52adf907..3f54a1ec 100644 --- a/src/framework/core/resourcemanager.cpp +++ b/src/framework/core/resourcemanager.cpp @@ -167,7 +167,7 @@ void ResourceManager::loadFile(const std::string& fileName, std::iostream& out) std::ifstream fin(fileName); if(!fin) { out.clear(std::ios::failbit); - stdext::throw_exception(stdext::format("unable to file '%s': %s", fileName.c_str(), PHYSFS_getLastError())); + stdext::throw_exception(stdext::format("unable to load file '%s': %s", fileName.c_str(), PHYSFS_getLastError())); } else { out << fin.rdbuf(); } diff --git a/src/framework/stdext/string.cpp b/src/framework/stdext/string.cpp index c4556566..32359f27 100644 --- a/src/framework/stdext/string.cpp +++ b/src/framework/stdext/string.cpp @@ -23,6 +23,7 @@ #include "string.h" #include "format.h" #include +#include namespace stdext { @@ -113,6 +114,31 @@ void trim(std::string& str) boost::trim(str); } +char upchar(char c) +{ +#if defined(__GNUC__) && __GNUC__ >= 3 + return ::toupper(c); // use the one from global scope "ctype.h" +#else + if((c >= 97 && c <= 122) || (c <= -1 && c >= -32)) + c -= 32; + + return c; +#endif +} + +void ucwords(std::string& str) +{ + uint32 strLen = str.length(); + if(strLen == 0) + return; + + str[0] = upchar(str[0]); + for(uint32 i = 1; i < strLen; ++i) { + if(str[i - 1] == ' ') + str[i] = upchar(str[i]); + } +} + bool ends_with(const std::string& str, const std::string& test) { return boost::ends_with(str, test); diff --git a/src/framework/stdext/string.h b/src/framework/stdext/string.h index 07b2ef8c..1708a18a 100644 --- a/src/framework/stdext/string.h +++ b/src/framework/stdext/string.h @@ -46,6 +46,8 @@ std::string utf8_to_latin1(uchar *utf8); void tolower(std::string& str); void toupper(std::string& str); void trim(std::string& str); +void ucwords(std::string& str); +char upchar(char c); bool ends_with(const std::string& str, const std::string& test); bool starts_with(const std::string& str, const std::string& test); void replace_all(std::string& str, const std::string& search, const std::string& replacement); diff --git a/src/framework/xml/tinyxml.h b/src/framework/xml/tinyxml.h index 0b93fea9..9907c6c0 100644 --- a/src/framework/xml/tinyxml.h +++ b/src/framework/xml/tinyxml.h @@ -970,14 +970,6 @@ public: return ret; } - Point readPoint() const - { - Point ret; - ret.x = readType("x"); - ret.y = readType("y"); - return ret; - } - /** Template form of the attribute query which will try to read the attribute into the specified type. Very easy, very powerful, but be careful to make sure to call this with the correct type. diff --git a/src/otclient/creatures.cpp b/src/otclient/creatures.cpp index fcb83007..278aa25a 100644 --- a/src/otclient/creatures.cpp +++ b/src/otclient/creatures.cpp @@ -56,16 +56,19 @@ void Creatures::loadSingleCreature(const std::string& file) void Creatures::loadNpcs(const std::string& folder) { - boost::filesystem::path npcPath(folder); + boost::filesystem::path npcPath(boost::filesystem::current_path().generic_string() + folder); if(!boost::filesystem::exists(npcPath)) stdext::throw_exception(stdext::format("NPCs folder '%s' was not found.", folder)); for(boost::filesystem::directory_iterator it(npcPath), end; it != end; ++it) { - std::string f = it->path().string(); - if(boost::filesystem::is_directory(it->status()) || ((f.size() > 4 ? f.substr(f.size() - 4) : "") != ".xml")) + std::string f = it->path().filename().string(); + if(boost::filesystem::is_directory(it->status())) continue; - loadCreatureBuffer(g_resources.loadFile(f)); + std::string tmp = folder; + if(!stdext::ends_with(tmp, "/")) + tmp += "/"; + loadCreatureBuffer(g_resources.loadFile(tmp + f)); } } diff --git a/src/otclient/luafunctions.cpp b/src/otclient/luafunctions.cpp index e5b7e4df..6838bb0d 100644 --- a/src/otclient/luafunctions.cpp +++ b/src/otclient/luafunctions.cpp @@ -103,6 +103,7 @@ void OTClient::registerLuaFunctions() g_lua.bindSingletonFunction("g_map", "loadOtcm", &Map::loadOtcm, &g_map); g_lua.bindSingletonFunction("g_map", "saveOtcm", &Map::saveOtcm, &g_map); g_lua.bindSingletonFunction("g_map", "loadMonsters", &Map::loadMonsters, &g_map); + g_lua.bindSingletonFunction("g_map", "loadNpcs", &Map::loadNpcs, &g_map); g_lua.bindSingletonFunction("g_map", "loadSingleCreature", &Map::loadSingleCreature, &g_map); g_lua.bindSingletonFunction("g_map", "getTown", &Map::getTown, &g_map); g_lua.bindSingletonFunction("g_map", "getHouse", &Map::getHouse, &g_map); diff --git a/src/otclient/mapio.cpp b/src/otclient/mapio.cpp index c110135d..720f4c72 100644 --- a/src/otclient/mapio.cpp +++ b/src/otclient/mapio.cpp @@ -209,10 +209,8 @@ void Map::loadOtbm(const std::string& fileName) g_logger.debug("OTBM read successfully."); fin->close(); - /* loadSpawns(getSpawnFile()); - m_houses.load(getHouseFile()); - */ +// m_houses.load(getHouseFile()); } void Map::saveOtbm(const std::string &fileName) @@ -381,9 +379,15 @@ void Map::loadSpawns(const std::string &fileName) cType->setSpawnTime(cNode->readType("spawntime")); CreaturePtr creature(new Creature); creature->setOutfit(cType->getOutfit()); - creature->setName(cType->getName()); - addThing(creature, centerPos + cNode->readPoint()); + stdext::ucwords(cName); + creature->setName(cName); + + centerPos.x += cNode->readType("x"); + centerPos.y += cNode->readType("y"); + centerPos.z = cNode->readType("z"); + + addThing(creature, centerPos, 4); } } }