lalala
This commit is contained in:
parent
02f89dd8be
commit
28825a3298
|
@ -120,7 +120,6 @@ R unsafe_cast(const T& t, R def) {
|
|||
return def;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -214,10 +214,20 @@ inline std::string utf8StringToLatin1(uchar *utf8) {
|
|||
}
|
||||
|
||||
// Convert string to lower case
|
||||
inline std::string tolower(std::string& str) { return boost::algorithm::to_lower_copy(str); }
|
||||
inline std::string tolower(const std::string& str)
|
||||
{
|
||||
std::string _str = str;
|
||||
boost::algorithm::to_lower(_str);
|
||||
return _str;
|
||||
}
|
||||
|
||||
// Convert string to upper case
|
||||
inline std::string toupper(std::string& str) { return boost::algorithm::to_upper_copy(str); }
|
||||
inline std::string toupper(const std::string& str)
|
||||
{
|
||||
std::string _str = str;
|
||||
boost::algorithm::to_upper(_str);
|
||||
return _str;
|
||||
}
|
||||
|
||||
// utility for printing messages into stdout
|
||||
template<class... T>
|
||||
|
|
|
@ -596,16 +596,10 @@ const std::string* TiXmlElement::Attribute( const std::string& name ) const
|
|||
|
||||
const char* TiXmlElement::Attribute( const char* name, int* i ) const
|
||||
{
|
||||
const TiXmlAttribute* attrib = attributeSet.Find( name );
|
||||
const char* result = 0;
|
||||
|
||||
if ( attrib ) {
|
||||
result = attrib->Value();
|
||||
if ( i ) {
|
||||
attrib->QueryIntValue( i );
|
||||
}
|
||||
}
|
||||
return result;
|
||||
int p = readType<int>(name);
|
||||
if(i)
|
||||
*i = p;
|
||||
return Attribute(name);
|
||||
}
|
||||
|
||||
|
||||
|
@ -625,19 +619,12 @@ const std::string* TiXmlElement::Attribute( const std::string& name, int* i ) co
|
|||
}
|
||||
#endif
|
||||
|
||||
|
||||
const char* TiXmlElement::Attribute( const char* name, double* d ) const
|
||||
const char* TiXmlElement::Attribute(const char *name, double *d) const
|
||||
{
|
||||
const TiXmlAttribute* attrib = attributeSet.Find( name );
|
||||
const char* result = 0;
|
||||
|
||||
if ( attrib ) {
|
||||
result = attrib->Value();
|
||||
if ( d ) {
|
||||
attrib->QueryDoubleValue( d );
|
||||
}
|
||||
}
|
||||
return result;
|
||||
double p = readType<double>(name);
|
||||
if(d)
|
||||
*d = p;
|
||||
return Attribute(name);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -40,6 +40,10 @@ distribution.
|
|||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include <framework/global.h>
|
||||
#include <otclient/position.h>
|
||||
#include <framework/stdext/cast.h>
|
||||
|
||||
// Help out windows:
|
||||
#if defined( _DEBUG ) && !defined( DEBUG )
|
||||
#define DEBUG
|
||||
|
@ -200,6 +204,9 @@ class TiXmlBase
|
|||
friend class TiXmlDocument;
|
||||
|
||||
public:
|
||||
TiXmlBase( const TiXmlBase& ) = delete;
|
||||
void operator=( const TiXmlBase& base ) = delete;
|
||||
|
||||
TiXmlBase() : userData(0) {}
|
||||
virtual ~TiXmlBase() {}
|
||||
|
||||
|
@ -396,9 +403,6 @@ protected:
|
|||
static void ConvertUTF32ToUTF8( unsigned long input, char* output, int* length );
|
||||
|
||||
private:
|
||||
TiXmlBase( const TiXmlBase& ); // not implemented.
|
||||
void operator=( const TiXmlBase& base ); // not allowed.
|
||||
|
||||
struct Entity
|
||||
{
|
||||
const char* str;
|
||||
|
@ -428,6 +432,9 @@ class TiXmlNode : public TiXmlBase
|
|||
friend class TiXmlElement;
|
||||
|
||||
public:
|
||||
TiXmlNode( const TiXmlNode& ) = delete;
|
||||
void operator=( const TiXmlNode& base ) = delete;
|
||||
|
||||
#ifdef TIXML_USE_STL
|
||||
|
||||
/** An input stream operator, for every class. Tolerant of newlines and
|
||||
|
@ -764,10 +771,6 @@ protected:
|
|||
|
||||
TiXmlNode* prev;
|
||||
TiXmlNode* next;
|
||||
|
||||
private:
|
||||
TiXmlNode( const TiXmlNode& ); // not implemented.
|
||||
void operator=( const TiXmlNode& base ); // not allowed.
|
||||
};
|
||||
|
||||
|
||||
|
@ -977,6 +980,18 @@ public:
|
|||
*/
|
||||
const char* Attribute( const char* name, double* d ) const;
|
||||
|
||||
template<typename T = std::string>
|
||||
inline T readType(const std::string& str) const { return stdext::unsafe_cast<T>(Attribute(str)); }
|
||||
|
||||
Position readPos(const std::string& base = std::string()) const
|
||||
{
|
||||
return Position(readType<uint16>(base + "x"), readType<uint16>(base + "y"), readType<uint8>(base + "z"));
|
||||
}
|
||||
|
||||
Point readPoint() const
|
||||
{
|
||||
return Point(readType<int>("x"), readType<int>("y"));
|
||||
}
|
||||
/** QueryIntAttribute examines the attribute - it is an alternative to the
|
||||
Attribute() method with richer error checking.
|
||||
If the attribute is an integer, it is stored in 'value' and
|
||||
|
|
|
@ -160,11 +160,6 @@ class Monster : public Creature
|
|||
public:
|
||||
MonsterPtr asMonster() { return std::static_pointer_cast<Monster>(shared_from_this()); }
|
||||
bool isMonster() { return true; }
|
||||
|
||||
Position getPos() { return m_pos; }
|
||||
void setPos(const Position& pos) { m_pos = pos; }
|
||||
private:
|
||||
Position m_pos;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -42,29 +42,21 @@ void House::setTile(const TilePtr& tile)
|
|||
m_tiles.push_back(tile);
|
||||
}
|
||||
|
||||
#define fugly_get(attrib, type) stdext::unsafe_cast<type>(elem->Attribute((attrib)))
|
||||
|
||||
void House::load(const TiXmlElement *elem)
|
||||
{
|
||||
std::string name = elem->Attribute("name");
|
||||
if(name.empty())
|
||||
name = stdext::format("UnNamed house #%u", getId());
|
||||
|
||||
uint32 rent = fugly_get("rent", uint32);
|
||||
m_rent = rent;
|
||||
m_rent = elem->readType<uint32>("rent");
|
||||
m_size = elem->readType<uint32>("size");
|
||||
|
||||
uint32 townId = fugly_get("townid", uint32);
|
||||
uint32 townId = elem->readType<uint32>("townid");
|
||||
if(!g_map.getTown(townId))
|
||||
stdext::throw_exception(stdext::format("invalid town id for house %d", townId));
|
||||
|
||||
uint32 size = fugly_get("size", uint32);
|
||||
if(size == 0)
|
||||
size = 1;
|
||||
|
||||
m_size = size;
|
||||
m_isGuildHall = fugly_get("guildhall", bool);
|
||||
addDoor(0, Position(fugly_get("entryx", uint16), fugly_get("entryy", uint16),
|
||||
fugly_get("entryz", uint8)));
|
||||
m_isGuildHall = elem->readType<bool>("rent");
|
||||
addDoor(0, elem->readPos());
|
||||
}
|
||||
|
||||
void Houses::addHouse(const HousePtr& house)
|
||||
|
@ -103,7 +95,7 @@ void Houses::load(const std::string& fileName)
|
|||
if(elem->ValueTStr() != "house")
|
||||
stdext::throw_exception("invalid house tag.");
|
||||
|
||||
uint32 houseId = fugly_get("houseid", uint32);
|
||||
uint32 houseId = elem->readType<uint32>("houseid");
|
||||
HousePtr house = getHouse(houseId);
|
||||
if(!house)
|
||||
house = HousePtr(new House(houseId)), addHouse(house);
|
||||
|
|
|
@ -378,7 +378,6 @@ void Map::saveOtbm(const std::string &fileName)
|
|||
|
||||
void Map::loadSpawns(const std::string &fileName)
|
||||
{
|
||||
#define cast(NAME, TYPE, NODE) stdext::unsafe_cast<TYPE>(NODE->Attribute((NAME)))
|
||||
if(!m_monsters.isLoaded())
|
||||
stdext::throw_exception("cannot load spawns; monsters aren't loaded.");
|
||||
|
||||
|
@ -394,7 +393,7 @@ void Map::loadSpawns(const std::string &fileName)
|
|||
if (node->ValueTStr() != "spawn")
|
||||
stdext::throw_exception("invalid spawn node");
|
||||
|
||||
Position centerPos(cast("x", uint16, node), cast("y", uint16, node), cast("z", uint8, node));
|
||||
Position centerPos = node->readPos("center");
|
||||
for(TiXmlElement* mType = node->FirstChildElement(); mType; mType = mType->NextSiblingElement()) {
|
||||
if (mType->ValueStr() != "monster")
|
||||
stdext::throw_exception("invalid spawn-subnode");
|
||||
|
@ -404,7 +403,7 @@ void Map::loadSpawns(const std::string &fileName)
|
|||
if (!m)
|
||||
stdext::throw_exception(stdext::format("unkown monster %s", mName));
|
||||
|
||||
Point off(cast("x", int, mType), cast("y", int, mType));
|
||||
Point off = mType->readPoint();
|
||||
Position mPos(centerPos.x + off.x, centerPos.y + off.y, centerPos.z);
|
||||
addThing(m, mPos, -1);
|
||||
}
|
||||
|
|
|
@ -151,7 +151,7 @@ public:
|
|||
// town/house/monster related
|
||||
TownPtr getTown(uint32 tid) { return m_towns.getTown(tid); }
|
||||
HousePtr getHouse(uint32 hid) { return m_houses.getHouse(hid); }
|
||||
MonsterPtr getMonster(const std::string& name);
|
||||
MonsterPtr getMonster(const std::string &name);
|
||||
|
||||
void setLight(const Light& light) { m_light = light; }
|
||||
void setCentralPosition(const Position& centralPosition);
|
||||
|
|
|
@ -48,7 +48,6 @@ void Monsters::loadMonsters(const std::string& file)
|
|||
|
||||
void Monsters::loadSingleMonster(const std::string& file, const MonsterPtr& m)
|
||||
{
|
||||
#define read(str) stdext::unsafe_cast<int>(attrib->Attribute((str)))
|
||||
if (!m || std::find(m_monsters.begin(), m_monsters.end(), m) != m_monsters.end())
|
||||
stdext::throw_exception("reloading monsters is not supported yet.");
|
||||
|
||||
|
@ -64,18 +63,18 @@ void Monsters::loadSingleMonster(const std::string& file, const MonsterPtr& m)
|
|||
if(attrib->ValueStr() == "look") {
|
||||
Outfit out;
|
||||
|
||||
int type = read("type");
|
||||
int type = attrib->readType<int>("type");
|
||||
if (type <= 0)
|
||||
type = read("typeex");
|
||||
type = attrib->readType<int>("typeex");
|
||||
if(type) {
|
||||
out.setId(type);
|
||||
{
|
||||
out.setHead(read("head"));
|
||||
out.setBody(read("body"));
|
||||
out.setLegs(read("legs"));
|
||||
out.setFeet(read("feet"));
|
||||
out.setAddons(read("addons"));
|
||||
out.setMount(read("mount"));
|
||||
out.setHead(attrib->readType<int>(("head")));
|
||||
out.setBody(attrib->readType<int>(("body")));
|
||||
out.setLegs(attrib->readType<int>(("legs")));
|
||||
out.setFeet(attrib->readType<int>(("feet")));
|
||||
out.setAddons(attrib->readType<int>(("addons")));
|
||||
out.setMount(attrib->readType<int>(("mount")));
|
||||
}
|
||||
} else
|
||||
stdext::throw_exception(stdext::format("invalid look type/typeex for monster %s", m->getName()));
|
||||
|
@ -90,14 +89,12 @@ MonsterPtr Monsters::getMonster(const std::string& name)
|
|||
{
|
||||
auto it = std::find_if(m_monsters.begin(), m_monsters.end(),
|
||||
[=] (const MonsterPtr& m) -> bool { return m->getName() == name; });
|
||||
if (it != m_monsters.end())
|
||||
return *it;
|
||||
return nullptr;
|
||||
return it != m_monsters.end() ? *it : nullptr;
|
||||
}
|
||||
|
||||
MonsterPtr Monsters::getMonsterByPos(const Position& pos)
|
||||
{
|
||||
auto it = std::find_if(m_monsters.begin(), m_monsters.end(),
|
||||
[=] (const MonsterPtr& m) -> bool { return m->getPos() == pos; });
|
||||
[=] (const MonsterPtr& m) -> bool { return m->getPosition() == pos; });
|
||||
return it != m_monsters.end() ? *it : nullptr;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue