Fix NPC/Monster rendering for OTBM

This commit is contained in:
niczkx 2012-08-07 03:12:44 -06:00
parent a2db210012
commit 6feaeff8cc
7 changed files with 46 additions and 18 deletions

View File

@ -167,7 +167,7 @@ void ResourceManager::loadFile(const std::string& fileName, std::iostream& out)
std::ifstream fin(fileName); std::ifstream fin(fileName);
if(!fin) { if(!fin) {
out.clear(std::ios::failbit); 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 { } else {
out << fin.rdbuf(); out << fin.rdbuf();
} }

View File

@ -23,6 +23,7 @@
#include "string.h" #include "string.h"
#include "format.h" #include "format.h"
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp>
#include <ctype.h>
namespace stdext { namespace stdext {
@ -113,6 +114,31 @@ void trim(std::string& str)
boost::trim(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) bool ends_with(const std::string& str, const std::string& test)
{ {
return boost::ends_with(str, test); return boost::ends_with(str, test);

View File

@ -46,6 +46,8 @@ std::string utf8_to_latin1(uchar *utf8);
void tolower(std::string& str); void tolower(std::string& str);
void toupper(std::string& str); void toupper(std::string& str);
void trim(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 ends_with(const std::string& str, const std::string& test);
bool starts_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); void replace_all(std::string& str, const std::string& search, const std::string& replacement);

View File

@ -970,14 +970,6 @@ public:
return ret; return ret;
} }
Point readPoint() const
{
Point ret;
ret.x = readType<int>("x");
ret.y = readType<int>("y");
return ret;
}
/** Template form of the attribute query which will try to read the /** Template form of the attribute query which will try to read the
attribute into the specified type. Very easy, very powerful, but attribute into the specified type. Very easy, very powerful, but
be careful to make sure to call this with the correct type. be careful to make sure to call this with the correct type.

View File

@ -56,16 +56,19 @@ void Creatures::loadSingleCreature(const std::string& file)
void Creatures::loadNpcs(const std::string& folder) 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)) if(!boost::filesystem::exists(npcPath))
stdext::throw_exception(stdext::format("NPCs folder '%s' was not found.", folder)); stdext::throw_exception(stdext::format("NPCs folder '%s' was not found.", folder));
for(boost::filesystem::directory_iterator it(npcPath), end; it != end; ++it) { for(boost::filesystem::directory_iterator it(npcPath), end; it != end; ++it) {
std::string f = it->path().string(); std::string f = it->path().filename().string();
if(boost::filesystem::is_directory(it->status()) || ((f.size() > 4 ? f.substr(f.size() - 4) : "") != ".xml")) if(boost::filesystem::is_directory(it->status()))
continue; continue;
loadCreatureBuffer(g_resources.loadFile(f)); std::string tmp = folder;
if(!stdext::ends_with(tmp, "/"))
tmp += "/";
loadCreatureBuffer(g_resources.loadFile(tmp + f));
} }
} }

View File

@ -103,6 +103,7 @@ void OTClient::registerLuaFunctions()
g_lua.bindSingletonFunction("g_map", "loadOtcm", &Map::loadOtcm, &g_map); 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", "saveOtcm", &Map::saveOtcm, &g_map);
g_lua.bindSingletonFunction("g_map", "loadMonsters", &Map::loadMonsters, &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", "loadSingleCreature", &Map::loadSingleCreature, &g_map);
g_lua.bindSingletonFunction("g_map", "getTown", &Map::getTown, &g_map); g_lua.bindSingletonFunction("g_map", "getTown", &Map::getTown, &g_map);
g_lua.bindSingletonFunction("g_map", "getHouse", &Map::getHouse, &g_map); g_lua.bindSingletonFunction("g_map", "getHouse", &Map::getHouse, &g_map);

View File

@ -209,10 +209,8 @@ void Map::loadOtbm(const std::string& fileName)
g_logger.debug("OTBM read successfully."); g_logger.debug("OTBM read successfully.");
fin->close(); fin->close();
/*
loadSpawns(getSpawnFile()); loadSpawns(getSpawnFile());
m_houses.load(getHouseFile()); // m_houses.load(getHouseFile());
*/
} }
void Map::saveOtbm(const std::string &fileName) void Map::saveOtbm(const std::string &fileName)
@ -381,9 +379,15 @@ void Map::loadSpawns(const std::string &fileName)
cType->setSpawnTime(cNode->readType<int>("spawntime")); cType->setSpawnTime(cNode->readType<int>("spawntime"));
CreaturePtr creature(new Creature); CreaturePtr creature(new Creature);
creature->setOutfit(cType->getOutfit()); creature->setOutfit(cType->getOutfit());
creature->setName(cType->getName());
addThing(creature, centerPos + cNode->readPoint()); stdext::ucwords(cName);
creature->setName(cName);
centerPos.x += cNode->readType<int>("x");
centerPos.y += cNode->readType<int>("y");
centerPos.z = cNode->readType<int>("z");
addThing(creature, centerPos, 4);
} }
} }
} }