Adjust fallen changes
* Restore old map load() used in minimap * Change tabs to 4 spaces * Add missing cmake file
This commit is contained in:
parent
6b0d922dd9
commit
f3499efe83
|
@ -251,26 +251,26 @@ std::string FileStream::getString()
|
||||||
|
|
||||||
uint8 FileStream::readNode(uint8 &oldNode, uint32 &type)
|
uint8 FileStream::readNode(uint8 &oldNode, uint32 &type)
|
||||||
{
|
{
|
||||||
if (!oldNode) {
|
if (!oldNode) {
|
||||||
if ((oldNode = getU8()) == 0xFE) {
|
if ((oldNode = getU8()) == 0xFE) {
|
||||||
type = getU32();
|
type = getU32();
|
||||||
return oldNode;
|
return oldNode;
|
||||||
} else {
|
} else {
|
||||||
dump << "Failed to read new node.";
|
dump << "Failed to read new node.";
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(getU8() == 0xFF);
|
assert(getU8() == 0xFF);
|
||||||
if ((oldNode = getU8()) == 0xFE) {
|
if ((oldNode = getU8()) == 0xFE) {
|
||||||
type = getU32();
|
type = getU32();
|
||||||
return oldNode;
|
return oldNode;
|
||||||
} else {
|
} else {
|
||||||
dump << "Failed to read node with old type: " << type;
|
dump << "Failed to read node with old type: " << type;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileStream::addU8(uint8 v)
|
void FileStream::addU8(uint8 v)
|
||||||
|
|
|
@ -59,7 +59,7 @@ public:
|
||||||
void addU32(uint8 v);
|
void addU32(uint8 v);
|
||||||
void addU64(uint8 v);
|
void addU64(uint8 v);
|
||||||
|
|
||||||
uint8 readNode(uint8 &oldNode, uint32 &type);
|
uint8 readNode(uint8 &oldNode, uint32 &type);
|
||||||
private:
|
private:
|
||||||
std::string m_name;
|
std::string m_name;
|
||||||
PHYSFS_File *m_fileHandle;
|
PHYSFS_File *m_fileHandle;
|
||||||
|
|
|
@ -36,76 +36,76 @@ TiXmlString::Rep TiXmlString::nullrep_ = { 0, 0, { '\0' } };
|
||||||
|
|
||||||
void TiXmlString::reserve (size_type cap)
|
void TiXmlString::reserve (size_type cap)
|
||||||
{
|
{
|
||||||
if (cap > capacity())
|
if (cap > capacity())
|
||||||
{
|
{
|
||||||
TiXmlString tmp;
|
TiXmlString tmp;
|
||||||
tmp.init(length(), cap);
|
tmp.init(length(), cap);
|
||||||
memcpy(tmp.start(), data(), length());
|
memcpy(tmp.start(), data(), length());
|
||||||
swap(tmp);
|
swap(tmp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TiXmlString& TiXmlString::assign(const char* str, size_type len)
|
TiXmlString& TiXmlString::assign(const char* str, size_type len)
|
||||||
{
|
{
|
||||||
size_type cap = capacity();
|
size_type cap = capacity();
|
||||||
if (len > cap || cap > 3*(len + 8))
|
if (len > cap || cap > 3*(len + 8))
|
||||||
{
|
{
|
||||||
TiXmlString tmp;
|
TiXmlString tmp;
|
||||||
tmp.init(len);
|
tmp.init(len);
|
||||||
memcpy(tmp.start(), str, len);
|
memcpy(tmp.start(), str, len);
|
||||||
swap(tmp);
|
swap(tmp);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
memmove(start(), str, len);
|
memmove(start(), str, len);
|
||||||
set_size(len);
|
set_size(len);
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TiXmlString& TiXmlString::append(const char* str, size_type len)
|
TiXmlString& TiXmlString::append(const char* str, size_type len)
|
||||||
{
|
{
|
||||||
size_type newsize = length() + len;
|
size_type newsize = length() + len;
|
||||||
if (newsize > capacity())
|
if (newsize > capacity())
|
||||||
{
|
{
|
||||||
reserve (newsize + capacity());
|
reserve (newsize + capacity());
|
||||||
}
|
}
|
||||||
memmove(finish(), str, len);
|
memmove(finish(), str, len);
|
||||||
set_size(newsize);
|
set_size(newsize);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TiXmlString operator + (const TiXmlString & a, const TiXmlString & b)
|
TiXmlString operator + (const TiXmlString & a, const TiXmlString & b)
|
||||||
{
|
{
|
||||||
TiXmlString tmp;
|
TiXmlString tmp;
|
||||||
tmp.reserve(a.length() + b.length());
|
tmp.reserve(a.length() + b.length());
|
||||||
tmp += a;
|
tmp += a;
|
||||||
tmp += b;
|
tmp += b;
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
TiXmlString operator + (const TiXmlString & a, const char* b)
|
TiXmlString operator + (const TiXmlString & a, const char* b)
|
||||||
{
|
{
|
||||||
TiXmlString tmp;
|
TiXmlString tmp;
|
||||||
TiXmlString::size_type b_len = static_cast<TiXmlString::size_type>( strlen(b) );
|
TiXmlString::size_type b_len = static_cast<TiXmlString::size_type>( strlen(b) );
|
||||||
tmp.reserve(a.length() + b_len);
|
tmp.reserve(a.length() + b_len);
|
||||||
tmp += a;
|
tmp += a;
|
||||||
tmp.append(b, b_len);
|
tmp.append(b, b_len);
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
TiXmlString operator + (const char* a, const TiXmlString & b)
|
TiXmlString operator + (const char* a, const TiXmlString & b)
|
||||||
{
|
{
|
||||||
TiXmlString tmp;
|
TiXmlString tmp;
|
||||||
TiXmlString::size_type a_len = static_cast<TiXmlString::size_type>( strlen(a) );
|
TiXmlString::size_type a_len = static_cast<TiXmlString::size_type>( strlen(a) );
|
||||||
tmp.reserve(a_len + b.length());
|
tmp.reserve(a_len + b.length());
|
||||||
tmp.append(a, a_len);
|
tmp.append(a, a_len);
|
||||||
tmp += b;
|
tmp += b;
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif // TIXML_USE_STL
|
#endif // TIXML_USE_STL
|
||||||
|
|
|
@ -30,18 +30,18 @@ distribution.
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* The support for explicit isn't that universal, and it isn't really
|
/* The support for explicit isn't that universal, and it isn't really
|
||||||
required - it is used to check that the TiXmlString class isn't incorrectly
|
required - it is used to check that the TiXmlString class isn't incorrectly
|
||||||
used. Be nice to old compilers and macro it here:
|
used. Be nice to old compilers and macro it here:
|
||||||
*/
|
*/
|
||||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200 )
|
#if defined(_MSC_VER) && (_MSC_VER >= 1200 )
|
||||||
// Microsoft visual studio, version 6 and higher.
|
// Microsoft visual studio, version 6 and higher.
|
||||||
#define TIXML_EXPLICIT explicit
|
#define TIXML_EXPLICIT explicit
|
||||||
#elif defined(__GNUC__) && (__GNUC__ >= 3 )
|
#elif defined(__GNUC__) && (__GNUC__ >= 3 )
|
||||||
// GCC version 3 and higher.s
|
// GCC version 3 and higher.s
|
||||||
#define TIXML_EXPLICIT explicit
|
#define TIXML_EXPLICIT explicit
|
||||||
#else
|
#else
|
||||||
#define TIXML_EXPLICIT
|
#define TIXML_EXPLICIT
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
@ -55,211 +55,211 @@ distribution.
|
||||||
class TiXmlString
|
class TiXmlString
|
||||||
{
|
{
|
||||||
public :
|
public :
|
||||||
// The size type used
|
// The size type used
|
||||||
typedef size_t size_type;
|
typedef size_t size_type;
|
||||||
|
|
||||||
// Error value for find primitive
|
// Error value for find primitive
|
||||||
static const size_type npos; // = -1;
|
static const size_type npos; // = -1;
|
||||||
|
|
||||||
|
|
||||||
// TiXmlString empty constructor
|
// TiXmlString empty constructor
|
||||||
TiXmlString () : rep_(&nullrep_)
|
TiXmlString () : rep_(&nullrep_)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
// TiXmlString copy constructor
|
// TiXmlString copy constructor
|
||||||
TiXmlString ( const TiXmlString & copy) : rep_(0)
|
TiXmlString ( const TiXmlString & copy) : rep_(0)
|
||||||
{
|
{
|
||||||
init(copy.length());
|
init(copy.length());
|
||||||
memcpy(start(), copy.data(), length());
|
memcpy(start(), copy.data(), length());
|
||||||
}
|
}
|
||||||
|
|
||||||
// TiXmlString constructor, based on a string
|
// TiXmlString constructor, based on a string
|
||||||
TIXML_EXPLICIT TiXmlString ( const char * copy) : rep_(0)
|
TIXML_EXPLICIT TiXmlString ( const char * copy) : rep_(0)
|
||||||
{
|
{
|
||||||
init( static_cast<size_type>( strlen(copy) ));
|
init( static_cast<size_type>( strlen(copy) ));
|
||||||
memcpy(start(), copy, length());
|
memcpy(start(), copy, length());
|
||||||
}
|
}
|
||||||
|
|
||||||
// TiXmlString constructor, based on a string
|
// TiXmlString constructor, based on a string
|
||||||
TIXML_EXPLICIT TiXmlString ( const char * str, size_type len) : rep_(0)
|
TIXML_EXPLICIT TiXmlString ( const char * str, size_type len) : rep_(0)
|
||||||
{
|
{
|
||||||
init(len);
|
init(len);
|
||||||
memcpy(start(), str, len);
|
memcpy(start(), str, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TiXmlString destructor
|
// TiXmlString destructor
|
||||||
~TiXmlString ()
|
~TiXmlString ()
|
||||||
{
|
{
|
||||||
quit();
|
quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
TiXmlString& operator = (const char * copy)
|
TiXmlString& operator = (const char * copy)
|
||||||
{
|
{
|
||||||
return assign( copy, (size_type)strlen(copy));
|
return assign( copy, (size_type)strlen(copy));
|
||||||
}
|
}
|
||||||
|
|
||||||
TiXmlString& operator = (const TiXmlString & copy)
|
TiXmlString& operator = (const TiXmlString & copy)
|
||||||
{
|
{
|
||||||
return assign(copy.start(), copy.length());
|
return assign(copy.start(), copy.length());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// += operator. Maps to append
|
// += operator. Maps to append
|
||||||
TiXmlString& operator += (const char * suffix)
|
TiXmlString& operator += (const char * suffix)
|
||||||
{
|
{
|
||||||
return append(suffix, static_cast<size_type>( strlen(suffix) ));
|
return append(suffix, static_cast<size_type>( strlen(suffix) ));
|
||||||
}
|
}
|
||||||
|
|
||||||
// += operator. Maps to append
|
// += operator. Maps to append
|
||||||
TiXmlString& operator += (char single)
|
TiXmlString& operator += (char single)
|
||||||
{
|
{
|
||||||
return append(&single, 1);
|
return append(&single, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// += operator. Maps to append
|
// += operator. Maps to append
|
||||||
TiXmlString& operator += (const TiXmlString & suffix)
|
TiXmlString& operator += (const TiXmlString & suffix)
|
||||||
{
|
{
|
||||||
return append(suffix.data(), suffix.length());
|
return append(suffix.data(), suffix.length());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Convert a TiXmlString into a null-terminated char *
|
// Convert a TiXmlString into a null-terminated char *
|
||||||
const char * c_str () const { return rep_->str; }
|
const char * c_str () const { return rep_->str; }
|
||||||
|
|
||||||
// Convert a TiXmlString into a char * (need not be null terminated).
|
// Convert a TiXmlString into a char * (need not be null terminated).
|
||||||
const char * data () const { return rep_->str; }
|
const char * data () const { return rep_->str; }
|
||||||
|
|
||||||
// Return the length of a TiXmlString
|
// Return the length of a TiXmlString
|
||||||
size_type length () const { return rep_->size; }
|
size_type length () const { return rep_->size; }
|
||||||
|
|
||||||
// Alias for length()
|
// Alias for length()
|
||||||
size_type size () const { return rep_->size; }
|
size_type size () const { return rep_->size; }
|
||||||
|
|
||||||
// Checks if a TiXmlString is empty
|
// Checks if a TiXmlString is empty
|
||||||
bool empty () const { return rep_->size == 0; }
|
bool empty () const { return rep_->size == 0; }
|
||||||
|
|
||||||
// Return capacity of string
|
// Return capacity of string
|
||||||
size_type capacity () const { return rep_->capacity; }
|
size_type capacity () const { return rep_->capacity; }
|
||||||
|
|
||||||
|
|
||||||
// single char extraction
|
// single char extraction
|
||||||
const char& at (size_type index) const
|
const char& at (size_type index) const
|
||||||
{
|
{
|
||||||
assert( index < length() );
|
assert( index < length() );
|
||||||
return rep_->str[ index ];
|
return rep_->str[ index ];
|
||||||
}
|
}
|
||||||
|
|
||||||
// [] operator
|
// [] operator
|
||||||
char& operator [] (size_type index) const
|
char& operator [] (size_type index) const
|
||||||
{
|
{
|
||||||
assert( index < length() );
|
assert( index < length() );
|
||||||
return rep_->str[ index ];
|
return rep_->str[ index ];
|
||||||
}
|
}
|
||||||
|
|
||||||
// find a char in a string. Return TiXmlString::npos if not found
|
// find a char in a string. Return TiXmlString::npos if not found
|
||||||
size_type find (char lookup) const
|
size_type find (char lookup) const
|
||||||
{
|
{
|
||||||
return find(lookup, 0);
|
return find(lookup, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// find a char in a string from an offset. Return TiXmlString::npos if not found
|
// find a char in a string from an offset. Return TiXmlString::npos if not found
|
||||||
size_type find (char tofind, size_type offset) const
|
size_type find (char tofind, size_type offset) const
|
||||||
{
|
{
|
||||||
if (offset >= length()) return npos;
|
if (offset >= length()) return npos;
|
||||||
|
|
||||||
for (const char* p = c_str() + offset; *p != '\0'; ++p)
|
for (const char* p = c_str() + offset; *p != '\0'; ++p)
|
||||||
{
|
{
|
||||||
if (*p == tofind) return static_cast< size_type >( p - c_str() );
|
if (*p == tofind) return static_cast< size_type >( p - c_str() );
|
||||||
}
|
}
|
||||||
return npos;
|
return npos;
|
||||||
}
|
}
|
||||||
|
|
||||||
void clear ()
|
void clear ()
|
||||||
{
|
{
|
||||||
//Lee:
|
//Lee:
|
||||||
//The original was just too strange, though correct:
|
//The original was just too strange, though correct:
|
||||||
// TiXmlString().swap(*this);
|
// TiXmlString().swap(*this);
|
||||||
//Instead use the quit & re-init:
|
//Instead use the quit & re-init:
|
||||||
quit();
|
quit();
|
||||||
init(0,0);
|
init(0,0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Function to reserve a big amount of data when we know we'll need it. Be aware that this
|
/* Function to reserve a big amount of data when we know we'll need it. Be aware that this
|
||||||
function DOES NOT clear the content of the TiXmlString if any exists.
|
function DOES NOT clear the content of the TiXmlString if any exists.
|
||||||
*/
|
*/
|
||||||
void reserve (size_type cap);
|
void reserve (size_type cap);
|
||||||
|
|
||||||
TiXmlString& assign (const char* str, size_type len);
|
TiXmlString& assign (const char* str, size_type len);
|
||||||
|
|
||||||
TiXmlString& append (const char* str, size_type len);
|
TiXmlString& append (const char* str, size_type len);
|
||||||
|
|
||||||
void swap (TiXmlString& other)
|
void swap (TiXmlString& other)
|
||||||
{
|
{
|
||||||
Rep* r = rep_;
|
Rep* r = rep_;
|
||||||
rep_ = other.rep_;
|
rep_ = other.rep_;
|
||||||
other.rep_ = r;
|
other.rep_ = r;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void init(size_type sz) { init(sz, sz); }
|
void init(size_type sz) { init(sz, sz); }
|
||||||
void set_size(size_type sz) { rep_->str[ rep_->size = sz ] = '\0'; }
|
void set_size(size_type sz) { rep_->str[ rep_->size = sz ] = '\0'; }
|
||||||
char* start() const { return rep_->str; }
|
char* start() const { return rep_->str; }
|
||||||
char* finish() const { return rep_->str + rep_->size; }
|
char* finish() const { return rep_->str + rep_->size; }
|
||||||
|
|
||||||
struct Rep
|
struct Rep
|
||||||
{
|
{
|
||||||
size_type size, capacity;
|
size_type size, capacity;
|
||||||
char str[1];
|
char str[1];
|
||||||
};
|
};
|
||||||
|
|
||||||
void init(size_type sz, size_type cap)
|
void init(size_type sz, size_type cap)
|
||||||
{
|
{
|
||||||
if (cap)
|
if (cap)
|
||||||
{
|
{
|
||||||
// Lee: the original form:
|
// Lee: the original form:
|
||||||
// rep_ = static_cast<Rep*>(operator new(sizeof(Rep) + cap));
|
// rep_ = static_cast<Rep*>(operator new(sizeof(Rep) + cap));
|
||||||
// doesn't work in some cases of new being overloaded. Switching
|
// doesn't work in some cases of new being overloaded. Switching
|
||||||
// to the normal allocation, although use an 'int' for systems
|
// to the normal allocation, although use an 'int' for systems
|
||||||
// that are overly picky about structure alignment.
|
// that are overly picky about structure alignment.
|
||||||
const size_type bytesNeeded = sizeof(Rep) + cap;
|
const size_type bytesNeeded = sizeof(Rep) + cap;
|
||||||
const size_type intsNeeded = ( bytesNeeded + sizeof(int) - 1 ) / sizeof( int );
|
const size_type intsNeeded = ( bytesNeeded + sizeof(int) - 1 ) / sizeof( int );
|
||||||
rep_ = reinterpret_cast<Rep*>( new int[ intsNeeded ] );
|
rep_ = reinterpret_cast<Rep*>( new int[ intsNeeded ] );
|
||||||
|
|
||||||
rep_->str[ rep_->size = sz ] = '\0';
|
rep_->str[ rep_->size = sz ] = '\0';
|
||||||
rep_->capacity = cap;
|
rep_->capacity = cap;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
rep_ = &nullrep_;
|
rep_ = &nullrep_;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void quit()
|
void quit()
|
||||||
{
|
{
|
||||||
if (rep_ != &nullrep_)
|
if (rep_ != &nullrep_)
|
||||||
{
|
{
|
||||||
// The rep_ is really an array of ints. (see the allocator, above).
|
// The rep_ is really an array of ints. (see the allocator, above).
|
||||||
// Cast it back before delete, so the compiler won't incorrectly call destructors.
|
// Cast it back before delete, so the compiler won't incorrectly call destructors.
|
||||||
delete [] ( reinterpret_cast<int*>( rep_ ) );
|
delete [] ( reinterpret_cast<int*>( rep_ ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Rep * rep_;
|
Rep * rep_;
|
||||||
static Rep nullrep_;
|
static Rep nullrep_;
|
||||||
|
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
|
|
||||||
inline bool operator == (const TiXmlString & a, const TiXmlString & b)
|
inline bool operator == (const TiXmlString & a, const TiXmlString & b)
|
||||||
{
|
{
|
||||||
return ( a.length() == b.length() ) // optimization on some platforms
|
return ( a.length() == b.length() ) // optimization on some platforms
|
||||||
&& ( strcmp(a.c_str(), b.c_str()) == 0 ); // actual compare
|
&& ( strcmp(a.c_str(), b.c_str()) == 0 ); // actual compare
|
||||||
}
|
}
|
||||||
inline bool operator < (const TiXmlString & a, const TiXmlString & b)
|
inline bool operator < (const TiXmlString & a, const TiXmlString & b)
|
||||||
{
|
{
|
||||||
return strcmp(a.c_str(), b.c_str()) < 0;
|
return strcmp(a.c_str(), b.c_str()) < 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool operator != (const TiXmlString & a, const TiXmlString & b) { return !(a == b); }
|
inline bool operator != (const TiXmlString & a, const TiXmlString & b) { return !(a == b); }
|
||||||
|
@ -285,21 +285,21 @@ class TiXmlOutStream : public TiXmlString
|
||||||
{
|
{
|
||||||
public :
|
public :
|
||||||
|
|
||||||
// TiXmlOutStream << operator.
|
// TiXmlOutStream << operator.
|
||||||
TiXmlOutStream & operator << (const TiXmlString & in)
|
TiXmlOutStream & operator << (const TiXmlString & in)
|
||||||
{
|
{
|
||||||
*this += in;
|
*this += in;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TiXmlOutStream << operator.
|
// TiXmlOutStream << operator.
|
||||||
TiXmlOutStream & operator << (const char * in)
|
TiXmlOutStream & operator << (const char * in)
|
||||||
{
|
{
|
||||||
*this += in;
|
*this += in;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
#endif // TIXML_STRING_INCLUDED
|
#endif // TIXML_STRING_INCLUDED
|
||||||
#endif // TIXML_USE_STL
|
#endif // TIXML_USE_STL
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -33,20 +33,20 @@ distribution.
|
||||||
|
|
||||||
const char* TiXmlBase::errorString[ TiXmlBase::TIXML_ERROR_STRING_COUNT ] =
|
const char* TiXmlBase::errorString[ TiXmlBase::TIXML_ERROR_STRING_COUNT ] =
|
||||||
{
|
{
|
||||||
"No error",
|
"No error",
|
||||||
"Error",
|
"Error",
|
||||||
"Failed to open file",
|
"Failed to open file",
|
||||||
"Error parsing Element.",
|
"Error parsing Element.",
|
||||||
"Failed to read Element name",
|
"Failed to read Element name",
|
||||||
"Error reading Element value.",
|
"Error reading Element value.",
|
||||||
"Error reading Attributes.",
|
"Error reading Attributes.",
|
||||||
"Error: empty tag.",
|
"Error: empty tag.",
|
||||||
"Error reading end tag.",
|
"Error reading end tag.",
|
||||||
"Error parsing Unknown.",
|
"Error parsing Unknown.",
|
||||||
"Error parsing Comment.",
|
"Error parsing Comment.",
|
||||||
"Error parsing Declaration.",
|
"Error parsing Declaration.",
|
||||||
"Error document empty.",
|
"Error document empty.",
|
||||||
"Error null (0) or unexpected EOF found in input stream.",
|
"Error null (0) or unexpected EOF found in input stream.",
|
||||||
"Error parsing CDATA.",
|
"Error parsing CDATA.",
|
||||||
"Error when TiXmlDocument added to document, because TiXmlDocument can only be at the root.",
|
"Error when TiXmlDocument added to document, because TiXmlDocument can only be at the root.",
|
||||||
};
|
};
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -48,6 +48,8 @@ SET(otclient_SOURCES ${otclient_SOURCES}
|
||||||
${CMAKE_CURRENT_LIST_DIR}/core/shadermanager.h
|
${CMAKE_CURRENT_LIST_DIR}/core/shadermanager.h
|
||||||
${CMAKE_CURRENT_LIST_DIR}/core/item.cpp
|
${CMAKE_CURRENT_LIST_DIR}/core/item.cpp
|
||||||
${CMAKE_CURRENT_LIST_DIR}/core/item.h
|
${CMAKE_CURRENT_LIST_DIR}/core/item.h
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}/core/itemloader.cpp
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}/core/itemloader.h
|
||||||
${CMAKE_CURRENT_LIST_DIR}/core/localplayer.cpp
|
${CMAKE_CURRENT_LIST_DIR}/core/localplayer.cpp
|
||||||
${CMAKE_CURRENT_LIST_DIR}/core/localplayer.h
|
${CMAKE_CURRENT_LIST_DIR}/core/localplayer.h
|
||||||
${CMAKE_CURRENT_LIST_DIR}/core/map.cpp
|
${CMAKE_CURRENT_LIST_DIR}/core/map.cpp
|
||||||
|
|
|
@ -192,67 +192,67 @@ void Item::setId(uint32 id)
|
||||||
|
|
||||||
bool Item::unserializeAttr(FileStreamPtr fin)
|
bool Item::unserializeAttr(FileStreamPtr fin)
|
||||||
{
|
{
|
||||||
uint8 attrType;
|
uint8 attrType;
|
||||||
while ((attrType = fin->getU8()) != 0)
|
while ((attrType = fin->getU8()) != 0)
|
||||||
readAttr((AttrTypes_t)attrType, fin);
|
readAttr((AttrTypes_t)attrType, fin);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Item::readAttr(AttrTypes_t attrType, FileStreamPtr fin)
|
void Item::readAttr(AttrTypes_t attrType, FileStreamPtr fin)
|
||||||
{
|
{
|
||||||
switch (attrType) {
|
switch (attrType) {
|
||||||
case ATTR_COUNT:
|
case ATTR_COUNT:
|
||||||
setSubType(fin->getU8());
|
setSubType(fin->getU8());
|
||||||
break;
|
break;
|
||||||
case ATTR_ACTION_ID:
|
case ATTR_ACTION_ID:
|
||||||
setActionId(fin->getU16());
|
setActionId(fin->getU16());
|
||||||
break;
|
break;
|
||||||
case ATTR_UNIQUE_ID:
|
case ATTR_UNIQUE_ID:
|
||||||
setUniqueId(fin->getU16());
|
setUniqueId(fin->getU16());
|
||||||
break;
|
break;
|
||||||
case ATTR_NAME:
|
case ATTR_NAME:
|
||||||
setName(fin->getString());
|
setName(fin->getString());
|
||||||
break;
|
break;
|
||||||
case ATTR_ARTICLE:
|
case ATTR_ARTICLE:
|
||||||
fin->getString();
|
fin->getString();
|
||||||
case ATTR_ATTACK: // \/ not needed.
|
case ATTR_ATTACK: // \/ not needed.
|
||||||
case ATTR_EXTRAATTACK:
|
case ATTR_EXTRAATTACK:
|
||||||
case ATTR_DEFENSE:
|
case ATTR_DEFENSE:
|
||||||
case ATTR_EXTRADEFENSE:
|
case ATTR_EXTRADEFENSE:
|
||||||
case ATTR_ARMOR:
|
case ATTR_ARMOR:
|
||||||
case ATTR_ATTACKSPEED:
|
case ATTR_ATTACKSPEED:
|
||||||
case ATTR_HPPITCHANCE:
|
case ATTR_HPPITCHANCE:
|
||||||
case ATTR_DURATION:
|
case ATTR_DURATION:
|
||||||
fin->getU32();
|
fin->getU32();
|
||||||
break;
|
break;
|
||||||
case ATTR_SCRIPTPROTECTED:
|
case ATTR_SCRIPTPROTECTED:
|
||||||
case ATTR_DUALWIELD:
|
case ATTR_DUALWIELD:
|
||||||
case ATTR_DECAYING_STATE:
|
case ATTR_DECAYING_STATE:
|
||||||
case ATTR_HPPOUSEDOORID:
|
case ATTR_HPPOUSEDOORID:
|
||||||
fin->getU8();
|
fin->getU8();
|
||||||
break;
|
break;
|
||||||
case ATTR_TEXT:
|
case ATTR_TEXT:
|
||||||
setText(fin->getString());
|
setText(fin->getString());
|
||||||
break;
|
break;
|
||||||
case ATTR_WRITTENDATE:
|
case ATTR_WRITTENDATE:
|
||||||
fin->getU32();
|
fin->getU32();
|
||||||
break;
|
break;
|
||||||
case ATTR_WRITTENBY:
|
case ATTR_WRITTENBY:
|
||||||
fin->getString();
|
fin->getString();
|
||||||
break;
|
break;
|
||||||
case ATTR_DESC:
|
case ATTR_DESC:
|
||||||
setDescription(fin->getString());
|
setDescription(fin->getString());
|
||||||
break;
|
break;
|
||||||
case ATTR_RUNE_CHARGES:
|
case ATTR_RUNE_CHARGES:
|
||||||
fin->getU8();
|
fin->getU8();
|
||||||
break;
|
break;
|
||||||
case ATTR_TELE_DEST: // Teleport should read that.
|
case ATTR_TELE_DEST: // Teleport should read that.
|
||||||
case ATTR_SLEEPERGUID: // Bed should read that.
|
case ATTR_SLEEPERGUID: // Bed should read that.
|
||||||
case ATTR_SLEEPSTART:
|
case ATTR_SLEEPSTART:
|
||||||
case ATTR_CONTAINER_ITEMS:
|
case ATTR_CONTAINER_ITEMS:
|
||||||
case ATTR_ATTRIBUTE_MAP:
|
case ATTR_ATTRIBUTE_MAP:
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,44 +27,44 @@
|
||||||
#include "thing.h"
|
#include "thing.h"
|
||||||
|
|
||||||
enum AttrTypes_t {
|
enum AttrTypes_t {
|
||||||
ATTR_END = 0,
|
ATTR_END = 0,
|
||||||
//ATTR_DESCRIPTION = 1,
|
//ATTR_DESCRIPTION = 1,
|
||||||
//ATTR_EXT_FILE = 2,
|
//ATTR_EXT_FILE = 2,
|
||||||
ATTR_TILE_FLAGS = 3,
|
ATTR_TILE_FLAGS = 3,
|
||||||
ATTR_ACTION_ID = 4,
|
ATTR_ACTION_ID = 4,
|
||||||
ATTR_UNIQUE_ID = 5,
|
ATTR_UNIQUE_ID = 5,
|
||||||
ATTR_TEXT = 6,
|
ATTR_TEXT = 6,
|
||||||
ATTR_DESC = 7,
|
ATTR_DESC = 7,
|
||||||
ATTR_TELE_DEST = 8,
|
ATTR_TELE_DEST = 8,
|
||||||
ATTR_ITEM = 9,
|
ATTR_ITEM = 9,
|
||||||
ATTR_DEPOT_ID = 10,
|
ATTR_DEPOT_ID = 10,
|
||||||
//ATTR_EXT_SPAWN_FILE = 11,
|
//ATTR_EXT_SPAWN_FILE = 11,
|
||||||
ATTR_RUNE_CHARGES = 12,
|
ATTR_RUNE_CHARGES = 12,
|
||||||
//ATTR_EXT_HPPOUSE_FILE = 13,
|
//ATTR_EXT_HPPOUSE_FILE = 13,
|
||||||
ATTR_HPPOUSEDOORID = 14,
|
ATTR_HPPOUSEDOORID = 14,
|
||||||
ATTR_COUNT = 15,
|
ATTR_COUNT = 15,
|
||||||
ATTR_DURATION = 16,
|
ATTR_DURATION = 16,
|
||||||
ATTR_DECAYING_STATE = 17,
|
ATTR_DECAYING_STATE = 17,
|
||||||
ATTR_WRITTENDATE = 18,
|
ATTR_WRITTENDATE = 18,
|
||||||
ATTR_WRITTENBY = 19,
|
ATTR_WRITTENBY = 19,
|
||||||
ATTR_SLEEPERGUID = 20,
|
ATTR_SLEEPERGUID = 20,
|
||||||
ATTR_SLEEPSTART = 21,
|
ATTR_SLEEPSTART = 21,
|
||||||
ATTR_CHARGES = 22,
|
ATTR_CHARGES = 22,
|
||||||
ATTR_CONTAINER_ITEMS = 23,
|
ATTR_CONTAINER_ITEMS = 23,
|
||||||
ATTR_NAME = 30,
|
ATTR_NAME = 30,
|
||||||
ATTR_PLURALNAME = 31,
|
ATTR_PLURALNAME = 31,
|
||||||
ATTR_ATTACK = 33,
|
ATTR_ATTACK = 33,
|
||||||
ATTR_EXTRAATTACK = 34,
|
ATTR_EXTRAATTACK = 34,
|
||||||
ATTR_DEFENSE = 35,
|
ATTR_DEFENSE = 35,
|
||||||
ATTR_EXTRADEFENSE = 36,
|
ATTR_EXTRADEFENSE = 36,
|
||||||
ATTR_ARMOR = 37,
|
ATTR_ARMOR = 37,
|
||||||
ATTR_ATTACKSPEED = 38,
|
ATTR_ATTACKSPEED = 38,
|
||||||
ATTR_HPPITCHANCE = 39,
|
ATTR_HPPITCHANCE = 39,
|
||||||
ATTR_SHOOTRANGE = 40,
|
ATTR_SHOOTRANGE = 40,
|
||||||
ATTR_ARTICLE = 41,
|
ATTR_ARTICLE = 41,
|
||||||
ATTR_SCRIPTPROTECTED = 42,
|
ATTR_SCRIPTPROTECTED = 42,
|
||||||
ATTR_DUALWIELD = 43,
|
ATTR_DUALWIELD = 43,
|
||||||
ATTR_ATTRIBUTE_MAP = 128
|
ATTR_ATTRIBUTE_MAP = 128
|
||||||
};
|
};
|
||||||
|
|
||||||
class Item : public Thing
|
class Item : public Thing
|
||||||
|
@ -80,33 +80,33 @@ public:
|
||||||
void setCountOrSubType(int value) { m_countOrSubType = value; }
|
void setCountOrSubType(int value) { m_countOrSubType = value; }
|
||||||
void setCount(int count) { m_countOrSubType = count; }
|
void setCount(int count) { m_countOrSubType = count; }
|
||||||
void setSubType(int subType) { m_countOrSubType = subType; }
|
void setSubType(int subType) { m_countOrSubType = subType; }
|
||||||
void setActionId(int actionId) { m_actionId = actionId; }
|
void setActionId(int actionId) { m_actionId = actionId; }
|
||||||
void setUniqueId(int uniqueId) { m_uniqueId = uniqueId; }
|
void setUniqueId(int uniqueId) { m_uniqueId = uniqueId; }
|
||||||
void setName(const std::string &name) { m_name = name; }
|
void setName(const std::string &name) { m_name = name; }
|
||||||
void setText(const std::string &text) { m_text = text; }
|
void setText(const std::string &text) { m_text = text; }
|
||||||
void setDescription(const std::string &description) { m_description = description; }
|
void setDescription(const std::string &description) { m_description = description; }
|
||||||
|
|
||||||
int getCountOrSubType() { return m_countOrSubType; }
|
int getCountOrSubType() { return m_countOrSubType; }
|
||||||
int getSubType() { return m_countOrSubType; }
|
int getSubType() { return m_countOrSubType; }
|
||||||
int getCount() { return m_countOrSubType; }
|
int getCount() { return m_countOrSubType; }
|
||||||
uint32 getId() { return m_id; }
|
uint32 getId() { return m_id; }
|
||||||
std::string getName() { return m_name; }
|
std::string getName() { return m_name; }
|
||||||
|
|
||||||
ItemPtr asItem() { return std::static_pointer_cast<Item>(shared_from_this()); }
|
ItemPtr asItem() { return std::static_pointer_cast<Item>(shared_from_this()); }
|
||||||
bool isItem() { return true; }
|
bool isItem() { return true; }
|
||||||
|
|
||||||
// TODO: These should be abstract and declared in i.e containers, doors, etc.
|
// TODO: These should be abstract and declared in i.e containers, doors, etc.
|
||||||
bool unserializeAttr(FileStreamPtr fin);
|
bool unserializeAttr(FileStreamPtr fin);
|
||||||
bool unserializeItemNode(FileStreamPtr fin, uint8) { return unserializeAttr(fin); }
|
bool unserializeItemNode(FileStreamPtr fin, uint8) { return unserializeAttr(fin); }
|
||||||
void readAttr(AttrTypes_t attrType, FileStreamPtr fin);
|
void readAttr(AttrTypes_t attrType, FileStreamPtr fin);
|
||||||
|
|
||||||
bool isMovable() { return false; }
|
bool isMovable() { return false; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint16 m_id;
|
uint16 m_id;
|
||||||
uint8 m_countOrSubType;
|
uint8 m_countOrSubType;
|
||||||
uint32 m_actionId, m_uniqueId;
|
uint32 m_actionId, m_uniqueId;
|
||||||
std::string m_name, m_text, m_description;
|
std::string m_name, m_text, m_description;
|
||||||
PainterShaderProgramPtr m_shaderProgram;
|
PainterShaderProgramPtr m_shaderProgram;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -30,209 +30,209 @@ ItemLoader g_itemLoader;
|
||||||
|
|
||||||
ItemLoader::~ItemLoader()
|
ItemLoader::~ItemLoader()
|
||||||
{
|
{
|
||||||
m_items.clear();
|
m_items.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemDataPtr ItemLoader::getType(uint16 id) const
|
ItemDataPtr ItemLoader::getType(uint16 id) const
|
||||||
{
|
{
|
||||||
for (const ItemDataPtr &it : m_items) {
|
for (const ItemDataPtr &it : m_items) {
|
||||||
if (it->id == id)
|
if (it->id == id)
|
||||||
return it;
|
return it;
|
||||||
}
|
}
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ItemLoader::addType(uint16 id, ItemDataPtr type)
|
void ItemLoader::addType(uint16 id, ItemDataPtr type)
|
||||||
{
|
{
|
||||||
if (getType(id))
|
if (getType(id))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_items.push_back(type);
|
m_items.push_back(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ItemLoader::loadOtb(const std::string &name)
|
bool ItemLoader::loadOtb(const std::string &name)
|
||||||
{
|
{
|
||||||
FileStreamPtr fin = g_resources.openFile(name);
|
FileStreamPtr fin = g_resources.openFile(name);
|
||||||
if (!fin) {
|
if (!fin) {
|
||||||
g_logger.error(stdext::format("failed to open file '%s'", name));
|
g_logger.error(stdext::format("failed to open file '%s'", name));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
fin->getU32(); // skip version
|
fin->getU32(); // skip version
|
||||||
|
|
||||||
uint32 type;
|
uint32 type;
|
||||||
uint8 node = fin->readNode(node, type);
|
uint8 node = fin->readNode(node, type);
|
||||||
|
|
||||||
fin->getU32(); // skip flags...
|
fin->getU32(); // skip flags...
|
||||||
if (fin->getU8() == 0x01) { // version
|
if (fin->getU8() == 0x01) { // version
|
||||||
fin->getU8(); // skip length.
|
fin->getU8(); // skip length.
|
||||||
dwMajorVersion = fin->getU32();
|
dwMajorVersion = fin->getU32();
|
||||||
dwMinorVersion = fin->getU32();
|
dwMinorVersion = fin->getU32();
|
||||||
dwBuildNumber = fin->getU32();
|
dwBuildNumber = fin->getU32();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16 lastId = 99;
|
uint16 lastId = 99;
|
||||||
ItemDataPtr newItem;
|
ItemDataPtr newItem;
|
||||||
|
|
||||||
while ((node = fin->readNode(node, type))) {
|
while ((node = fin->readNode(node, type))) {
|
||||||
if (!(newItem = ItemDataPtr(new ItemData))) {
|
if (!(newItem = ItemDataPtr(new ItemData))) {
|
||||||
g_logger.error("failed to read new item from OTB");
|
g_logger.error("failed to read new item from OTB");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
newItem->group = (ItemGroup)type;
|
newItem->group = (ItemGroup)type;
|
||||||
fin->getU32(); // skip flags
|
fin->getU32(); // skip flags
|
||||||
|
|
||||||
ItemAttrib attr;
|
ItemAttrib attr;
|
||||||
while ((attr = (ItemAttrib)fin->getU8())) {
|
while ((attr = (ItemAttrib)fin->getU8())) {
|
||||||
uint16 dsize = fin->getU16();
|
uint16 dsize = fin->getU16();
|
||||||
switch (attr) {
|
switch (attr) {
|
||||||
case ServerId: {
|
case ServerId: {
|
||||||
if (dsize != sizeof(uint16)) {
|
if (dsize != sizeof(uint16)) {
|
||||||
g_logger.error("Invalid data size");
|
g_logger.error("Invalid data size");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16 serverId = fin->getU16();
|
uint16 serverId = fin->getU16();
|
||||||
if (serverId > 20000 && serverId < 20100) {
|
if (serverId > 20000 && serverId < 20100) {
|
||||||
serverId -= 20000;
|
serverId -= 20000;
|
||||||
} else if (lastId > 99 && lastId != serverId - 1) {
|
} else if (lastId > 99 && lastId != serverId - 1) {
|
||||||
static ItemDataPtr dummyItemType(new ItemData);
|
static ItemDataPtr dummyItemType(new ItemData);
|
||||||
while (lastId != serverId - 1) {
|
while (lastId != serverId - 1) {
|
||||||
dummyItemType->id = ++lastId;
|
dummyItemType->id = ++lastId;
|
||||||
addType(lastId, dummyItemType);
|
addType(lastId, dummyItemType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
newItem->id = serverId;
|
newItem->id = serverId;
|
||||||
lastId = serverId;
|
lastId = serverId;
|
||||||
break;
|
break;
|
||||||
} case ClientId: {
|
} case ClientId: {
|
||||||
newItem->clientId = fin->getU16();
|
newItem->clientId = fin->getU16();
|
||||||
break;
|
break;
|
||||||
} case Speed: {
|
} case Speed: {
|
||||||
fin->getU16(); // skip speed
|
fin->getU16(); // skip speed
|
||||||
break;
|
break;
|
||||||
} case Light2: {
|
} case Light2: {
|
||||||
if (!fin->seek(dsize)) {
|
if (!fin->seek(dsize)) {
|
||||||
g_logger.error(stdext::format("fail to skip light block with size %d", dsize));
|
g_logger.error(stdext::format("fail to skip light block with size %d", dsize));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} default: {
|
} default: {
|
||||||
if (!fin->seek(dsize)) {
|
if (!fin->seek(dsize)) {
|
||||||
g_logger.error(stdext::format("fail to skip unknown data with size %d", dsize));
|
g_logger.error(stdext::format("fail to skip unknown data with size %d", dsize));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
addType(newItem->id, newItem);
|
addType(newItem->id, newItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ItemLoader::loadXML(const std::string &name)
|
bool ItemLoader::loadXML(const std::string &name)
|
||||||
{
|
{
|
||||||
TiXmlDocument doc(name.c_str());
|
TiXmlDocument doc(name.c_str());
|
||||||
if (!doc.LoadFile()) {
|
if (!doc.LoadFile()) {
|
||||||
g_logger.error(stdext::format("failed to load xml '%s'", name));
|
g_logger.error(stdext::format("failed to load xml '%s'", name));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
TiXmlElement* root = doc.FirstChildElement();
|
TiXmlElement* root = doc.FirstChildElement();
|
||||||
if (!root) {
|
if (!root) {
|
||||||
g_logger.error("invalid xml root");
|
g_logger.error("invalid xml root");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (root->ValueTStr() != "items") {
|
if (root->ValueTStr() != "items") {
|
||||||
g_logger.error("invalid xml tag name, should be 'items'");
|
g_logger.error("invalid xml tag name, should be 'items'");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (TiXmlElement *element = root->FirstChildElement(); element; element = element->NextSiblingElement()) {
|
for (TiXmlElement *element = root->FirstChildElement(); element; element = element->NextSiblingElement()) {
|
||||||
if (element->ValueTStr() != "item")
|
if (element->ValueTStr() != "item")
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
std::string name = element->Attribute("id");
|
std::string name = element->Attribute("id");
|
||||||
if (name.empty())
|
if (name.empty())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
uint16 id = stdext::unsafe_cast<uint16>(element->Attribute("id"));
|
uint16 id = stdext::unsafe_cast<uint16>(element->Attribute("id"));
|
||||||
uint16 idEx = 0;
|
uint16 idEx = 0;
|
||||||
if (!id) {
|
if (!id) {
|
||||||
bool found = false;
|
bool found = false;
|
||||||
// fallback into reading fromid and toid
|
// fallback into reading fromid and toid
|
||||||
uint16 fromid = stdext::unsafe_cast<uint16>(element->Attribute("fromid"));
|
uint16 fromid = stdext::unsafe_cast<uint16>(element->Attribute("fromid"));
|
||||||
uint16 toid = stdext::unsafe_cast<uint16>(element->Attribute("toid"));
|
uint16 toid = stdext::unsafe_cast<uint16>(element->Attribute("toid"));
|
||||||
ItemDataPtr iType;
|
ItemDataPtr iType;
|
||||||
for (int __id = fromid; __id < toid; ++__id) {
|
for (int __id = fromid; __id < toid; ++__id) {
|
||||||
if (!(iType = getType(__id)))
|
if (!(iType = getType(__id)))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
iType->name = name;
|
iType->name = name;
|
||||||
idEx = iType->id == fromid ? fromid : toid;
|
idEx = iType->id == fromid ? fromid : toid;
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!found)
|
if (!found)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemDataPtr iType = getType(id);
|
ItemDataPtr iType = getType(id);
|
||||||
if (!iType) {
|
if (!iType) {
|
||||||
iType = ItemDataPtr(new ItemData);
|
iType = ItemDataPtr(new ItemData);
|
||||||
iType->id = idEx ? idEx : id;
|
iType->id = idEx ? idEx : id;
|
||||||
iType->name = name;
|
iType->name = name;
|
||||||
addType(iType->id, iType);
|
addType(iType->id, iType);
|
||||||
}
|
}
|
||||||
|
|
||||||
iType->name = name;
|
iType->name = name;
|
||||||
|
|
||||||
for (TiXmlElement *attr = element->FirstChildElement(); attr; attr = attr->NextSiblingElement()) {
|
for (TiXmlElement *attr = element->FirstChildElement(); attr; attr = attr->NextSiblingElement()) {
|
||||||
if (attr->ValueTStr() != "attribute")
|
if (attr->ValueTStr() != "attribute")
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
std::string key = attr->Attribute("key");
|
std::string key = attr->Attribute("key");
|
||||||
std::string value = attr->Attribute("value");
|
std::string value = attr->Attribute("value");
|
||||||
if (key == "type") {
|
if (key == "type") {
|
||||||
if (value == "magicfield")
|
if (value == "magicfield")
|
||||||
iType->group = IsMagicField;
|
iType->group = IsMagicField;
|
||||||
else if (value == "key")
|
else if (value == "key")
|
||||||
iType->group = IsKey;
|
iType->group = IsKey;
|
||||||
else if (value == "depot")
|
else if (value == "depot")
|
||||||
iType->isDepot = true;
|
iType->isDepot = true;
|
||||||
else if (value == "teleport")
|
else if (value == "teleport")
|
||||||
iType->group = IsTeleport;
|
iType->group = IsTeleport;
|
||||||
else if (value == "bed")
|
else if (value == "bed")
|
||||||
iType->isBed = true;
|
iType->isBed = true;
|
||||||
else if (value == "door")
|
else if (value == "door")
|
||||||
iType->group = IsDoor;
|
iType->group = IsDoor;
|
||||||
} else if (key == "name") {
|
} else if (key == "name") {
|
||||||
iType->name = value;
|
iType->name = value;
|
||||||
} else if (key == "description") {
|
} else if (key == "description") {
|
||||||
iType->description = value;
|
iType->description = value;
|
||||||
} else if (key == "weight") {
|
} else if (key == "weight") {
|
||||||
iType->weight = stdext::unsafe_cast<double>(stdext::unsafe_cast<double>(value) / 100.f);
|
iType->weight = stdext::unsafe_cast<double>(stdext::unsafe_cast<double>(value) / 100.f);
|
||||||
} else if (key == "containerSize") {
|
} else if (key == "containerSize") {
|
||||||
int containerSize = stdext::unsafe_cast<int>(value);
|
int containerSize = stdext::unsafe_cast<int>(value);
|
||||||
if (containerSize)
|
if (containerSize)
|
||||||
iType->containerSize = containerSize;
|
iType->containerSize = containerSize;
|
||||||
iType->group = IsContainer;
|
iType->group = IsContainer;
|
||||||
} else if (key == "writeable") {
|
} else if (key == "writeable") {
|
||||||
if (!value.empty())
|
if (!value.empty())
|
||||||
iType->group = IsWritable;
|
iType->group = IsWritable;
|
||||||
} else if (key == "maxTextLen") {
|
} else if (key == "maxTextLen") {
|
||||||
iType->maxTextLength = stdext::unsafe_cast<int>(value);
|
iType->maxTextLength = stdext::unsafe_cast<int>(value);
|
||||||
} else if (key == "charges") {
|
} else if (key == "charges") {
|
||||||
iType->charges = stdext::unsafe_cast<int>(value);
|
iType->charges = stdext::unsafe_cast<int>(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
doc.Clear();
|
doc.Clear();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,92 +26,92 @@
|
||||||
#include "declarations.h"
|
#include "declarations.h"
|
||||||
|
|
||||||
enum ItemGroup {
|
enum ItemGroup {
|
||||||
IsGround,
|
IsGround,
|
||||||
IsContainer,
|
IsContainer,
|
||||||
IsWeapon,
|
IsWeapon,
|
||||||
IsAmmunition,
|
IsAmmunition,
|
||||||
IsArmor,
|
IsArmor,
|
||||||
IsCharges,
|
IsCharges,
|
||||||
IsTeleport,
|
IsTeleport,
|
||||||
IsMagicField,
|
IsMagicField,
|
||||||
IsWritable,
|
IsWritable,
|
||||||
IsKey,
|
IsKey,
|
||||||
IsSplash,
|
IsSplash,
|
||||||
IsFluid,
|
IsFluid,
|
||||||
IsDoor,
|
IsDoor,
|
||||||
InvalidGroup
|
InvalidGroup
|
||||||
};
|
};
|
||||||
|
|
||||||
enum ItemAttrib {
|
enum ItemAttrib {
|
||||||
First = 0x10,
|
First = 0x10,
|
||||||
ServerId = First,
|
ServerId = First,
|
||||||
ClientId,
|
ClientId,
|
||||||
Name, /* deprecated */
|
Name, /* deprecated */
|
||||||
Desc, /*deprecated*/
|
Desc, /*deprecated*/
|
||||||
Speed,
|
Speed,
|
||||||
Slot, /*deprecated*/
|
Slot, /*deprecated*/
|
||||||
MaxItems, /*deprecated*/
|
MaxItems, /*deprecated*/
|
||||||
Weight, /*deprecated*/
|
Weight, /*deprecated*/
|
||||||
Weapon, /*deprecated*/
|
Weapon, /*deprecated*/
|
||||||
Amu, /*deprecated*/
|
Amu, /*deprecated*/
|
||||||
Armor, /*deprecated*/
|
Armor, /*deprecated*/
|
||||||
MagLevel, /*deprecated*/
|
MagLevel, /*deprecated*/
|
||||||
MagicField, /*deprecated*/
|
MagicField, /*deprecated*/
|
||||||
Writable, /*deprecated*/
|
Writable, /*deprecated*/
|
||||||
RotateTo, /*deprecated*/
|
RotateTo, /*deprecated*/
|
||||||
Decay, /*deprecated*/
|
Decay, /*deprecated*/
|
||||||
SpriteHash,
|
SpriteHash,
|
||||||
MinimapColor,
|
MinimapColor,
|
||||||
Attr07,
|
Attr07,
|
||||||
Attr08,
|
Attr08,
|
||||||
Light,
|
Light,
|
||||||
|
|
||||||
// 1-byte aligned
|
// 1-byte aligned
|
||||||
Decay2, /*deprecated*/
|
Decay2, /*deprecated*/
|
||||||
Weapon2, /*deprecated*/
|
Weapon2, /*deprecated*/
|
||||||
Amu2, /*deprecated*/
|
Amu2, /*deprecated*/
|
||||||
Armor2, /*deprecated*/
|
Armor2, /*deprecated*/
|
||||||
Writable2, /*deprecated*/
|
Writable2, /*deprecated*/
|
||||||
Light2,
|
Light2,
|
||||||
TopOrder,
|
TopOrder,
|
||||||
Wrtiable3 /*deprecated*/
|
Wrtiable3 /*deprecated*/
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ItemData {
|
struct ItemData {
|
||||||
uint16 id;
|
uint16 id;
|
||||||
uint16 clientId;
|
uint16 clientId;
|
||||||
std::string name, description;
|
std::string name, description;
|
||||||
int containerSize;
|
int containerSize;
|
||||||
ItemGroup group;
|
ItemGroup group;
|
||||||
double weight;
|
double weight;
|
||||||
|
|
||||||
// xml stuff.
|
// xml stuff.
|
||||||
bool isDepot;
|
bool isDepot;
|
||||||
bool isBed;
|
bool isBed;
|
||||||
uint32 maxTextLength;
|
uint32 maxTextLength;
|
||||||
uint32 charges;
|
uint32 charges;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ItemLoader
|
class ItemLoader
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
uint32 dwMajorVersion;
|
uint32 dwMajorVersion;
|
||||||
uint32 dwMinorVersion;
|
uint32 dwMinorVersion;
|
||||||
uint32 dwBuildNumber;
|
uint32 dwBuildNumber;
|
||||||
|
|
||||||
ItemLoader() : m_otbLoaded(false), m_xmlLoaded(false) { }
|
ItemLoader() : m_otbLoaded(false), m_xmlLoaded(false) { }
|
||||||
~ItemLoader();
|
~ItemLoader();
|
||||||
|
|
||||||
bool loadOtb(const std::string &name);
|
bool loadOtb(const std::string &name);
|
||||||
bool loadXML(const std::string &name);
|
bool loadXML(const std::string &name);
|
||||||
|
|
||||||
bool isLoaded() { return m_otbLoaded && m_xmlLoaded; }
|
bool isLoaded() { return m_otbLoaded && m_xmlLoaded; }
|
||||||
ItemDataPtr getType(uint16 id) const;
|
ItemDataPtr getType(uint16 id) const;
|
||||||
void addType(uint16 id, ItemDataPtr type);
|
void addType(uint16 id, ItemDataPtr type);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ItemDataList m_items;
|
ItemDataList m_items;
|
||||||
bool m_otbLoaded, m_xmlLoaded;
|
bool m_otbLoaded, m_xmlLoaded;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern ItemLoader g_itemLoader;
|
extern ItemLoader g_itemLoader;
|
||||||
|
|
|
@ -54,227 +54,258 @@ void Map::notificateTileUpdateToMapViews(const Position& pos)
|
||||||
mapView->onTileUpdate(pos);
|
mapView->onTileUpdate(pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Map::load(const std::string& fileName)
|
bool Map::loadOTBM(const std::string& fileName)
|
||||||
{
|
{
|
||||||
FileStreamPtr fin = g_resources.openFile(fileName);
|
FileStreamPtr fin = g_resources.openFile(fileName);
|
||||||
if (!fin) {
|
if (!fin) {
|
||||||
g_logger.error(stdext::format("Unable to load map '%s'", fileName));
|
g_logger.error(stdext::format("Unable to load map '%s'", fileName));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!g_itemLoader.isLoaded()) {
|
if (!g_itemLoader.isLoaded()) {
|
||||||
g_logger.error(stdext::format("OTB and XML are not loaded yet to load a map."));
|
g_logger.error(stdext::format("OTB and XML are not loaded yet to load a map."));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32 type = 0;
|
uint32 type = 0;
|
||||||
uint8 root = fin->readNode(root, type);
|
uint8 root = fin->readNode(root, type);
|
||||||
|
|
||||||
uint32 headerVersion = fin->getU32();
|
uint32 headerVersion = fin->getU32();
|
||||||
if (!headerVersion || headerVersion > 3) {
|
if (!headerVersion || headerVersion > 3) {
|
||||||
g_logger.error("Unknown OTBM version detected.");
|
g_logger.error("Unknown OTBM version detected.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32 headerMajorItems = fin->getU32();
|
uint32 headerMajorItems = fin->getU32();
|
||||||
if (headerMajorItems < 3) {
|
if (headerMajorItems < 3) {
|
||||||
g_logger.error("This map needs to be upgraded.");
|
g_logger.error("This map needs to be upgraded.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (headerMajorItems > g_itemLoader.dwMajorVersion) {
|
if (headerMajorItems > g_itemLoader.dwMajorVersion) {
|
||||||
g_logger.error("This map was saved with different OTB version.");
|
g_logger.error("This map was saved with different OTB version.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t headerMinorItems = fin->getU32();
|
uint32_t headerMinorItems = fin->getU32();
|
||||||
if (headerMinorItems > g_itemLoader.dwMinorVersion)
|
if (headerMinorItems > g_itemLoader.dwMinorVersion)
|
||||||
g_logger.warning("This map needs an updated OTB.");
|
g_logger.warning("This map needs an updated OTB.");
|
||||||
|
|
||||||
uint8 node = fin->readNode(root, type);
|
uint8 node = fin->readNode(root, type);
|
||||||
if (type != OTBM_MAP_DATA) {
|
if (type != OTBM_MAP_DATA) {
|
||||||
g_logger.error("Could not read data node.");
|
g_logger.error("Could not read data node.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string tmp;
|
std::string tmp;
|
||||||
uint8 attribute;
|
uint8 attribute;
|
||||||
while ((attribute = fin->getU8())) {
|
while ((attribute = fin->getU8())) {
|
||||||
tmp = fin->getString();
|
tmp = fin->getString();
|
||||||
switch (attribute) {
|
switch (attribute) {
|
||||||
case OTBM_ATTR_DESCRIPTION:
|
case OTBM_ATTR_DESCRIPTION:
|
||||||
if (!m_description.empty())
|
if (!m_description.empty())
|
||||||
m_description += "\n" + tmp;
|
m_description += "\n" + tmp;
|
||||||
else
|
else
|
||||||
m_description = tmp;
|
m_description = tmp;
|
||||||
break;
|
break;
|
||||||
case OTBM_ATTR_SPAWN_FILE:
|
case OTBM_ATTR_SPAWN_FILE:
|
||||||
m_spawnFile = fileName.substr(0, fileName.rfind('/') + 1) + tmp;
|
m_spawnFile = fileName.substr(0, fileName.rfind('/') + 1) + tmp;
|
||||||
break;
|
break;
|
||||||
case OTBM_ATTR_HOUSE_FILE:
|
case OTBM_ATTR_HOUSE_FILE:
|
||||||
m_houseFile = fileName.substr(0, fileName.rfind('/') + 1) + tmp;
|
m_houseFile = fileName.substr(0, fileName.rfind('/') + 1) + tmp;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
g_logger.error(stdext::format("Invalid attribute '%c'", attribute));
|
g_logger.error(stdext::format("Invalid attribute '%c'", attribute));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dump << m_description;
|
dump << m_description;
|
||||||
|
|
||||||
uint8 nodeMapData;
|
uint8 nodeMapData;
|
||||||
do {
|
do {
|
||||||
nodeMapData = fin->readNode(node, type);
|
nodeMapData = fin->readNode(node, type);
|
||||||
|
|
||||||
if (type == OTBM_TILE_AREA) {
|
if (type == OTBM_TILE_AREA) {
|
||||||
uint16 baseX = fin->getU16(), baseY = fin->getU16();
|
uint16 baseX = fin->getU16(), baseY = fin->getU16();
|
||||||
uint8 pz = fin->getU8();
|
uint8 pz = fin->getU8();
|
||||||
|
|
||||||
uint8 nodeTile;
|
uint8 nodeTile;
|
||||||
do {
|
do {
|
||||||
nodeTile = fin->readNode(nodeMapData, type);
|
nodeTile = fin->readNode(nodeMapData, type);
|
||||||
|
|
||||||
if (type == OTBM_TILE || type == OTBM_HOUSETILE) {
|
if (type == OTBM_TILE || type == OTBM_HOUSETILE) {
|
||||||
TilePtr tile = 0;
|
TilePtr tile = 0;
|
||||||
ItemPtr ground = 0;
|
ItemPtr ground = 0;
|
||||||
uint32 flags = 0;
|
uint32 flags = 0;
|
||||||
|
|
||||||
uint16 px = baseX + fin->getU16(), py = fin->getU16();
|
uint16 px = baseX + fin->getU16(), py = fin->getU16();
|
||||||
Position pos(px, py, pz);
|
Position pos(px, py, pz);
|
||||||
|
|
||||||
// TODO: Houses.
|
// TODO: Houses.
|
||||||
if (type == OTBM_HOUSETILE) {
|
if (type == OTBM_HOUSETILE) {
|
||||||
uint32 hId = fin->getU32();
|
uint32 hId = fin->getU32();
|
||||||
|
|
||||||
tile = createTile(pos);
|
tile = createTile(pos);
|
||||||
// TODO: add it to house.
|
// TODO: add it to house.
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8 tileAttr;
|
uint8 tileAttr;
|
||||||
while ((tileAttr = fin->getU8())) {
|
while ((tileAttr = fin->getU8())) {
|
||||||
switch (tileAttr) {
|
switch (tileAttr) {
|
||||||
case OTBM_ATTR_TILE_FLAGS: {
|
case OTBM_ATTR_TILE_FLAGS: {
|
||||||
uint32 _flags = fin->getU32();
|
uint32 _flags = fin->getU32();
|
||||||
|
|
||||||
if ((_flags & TILESTATE_PROTECTIONZONE) == TILESTATE_PROTECTIONZONE)
|
if ((_flags & TILESTATE_PROTECTIONZONE) == TILESTATE_PROTECTIONZONE)
|
||||||
flags |= TILESTATE_PROTECTIONZONE;
|
flags |= TILESTATE_PROTECTIONZONE;
|
||||||
else if ((_flags & TILESTATE_OPTIONALZONE) == TILESTATE_OPTIONALZONE)
|
else if ((_flags & TILESTATE_OPTIONALZONE) == TILESTATE_OPTIONALZONE)
|
||||||
flags |= TILESTATE_OPTIONALZONE;
|
flags |= TILESTATE_OPTIONALZONE;
|
||||||
else if ((_flags & TILESTATE_HPPARDCOREZONE) == TILESTATE_HPPARDCOREZONE)
|
else if ((_flags & TILESTATE_HPPARDCOREZONE) == TILESTATE_HPPARDCOREZONE)
|
||||||
flags |= TILESTATE_HPPARDCOREZONE;
|
flags |= TILESTATE_HPPARDCOREZONE;
|
||||||
|
|
||||||
if ((_flags & TILESTATE_NOLOGOUT) == TILESTATE_NOLOGOUT)
|
if ((_flags & TILESTATE_NOLOGOUT) == TILESTATE_NOLOGOUT)
|
||||||
flags |= TILESTATE_NOLOGOUT;
|
flags |= TILESTATE_NOLOGOUT;
|
||||||
|
|
||||||
if ((_flags & TILESTATE_REFRESH) == TILESTATE_REFRESH)
|
if ((_flags & TILESTATE_REFRESH) == TILESTATE_REFRESH)
|
||||||
flags |= TILESTATE_REFRESH;
|
flags |= TILESTATE_REFRESH;
|
||||||
break;
|
break;
|
||||||
} case OTBM_ATTR_ITEM: {
|
} case OTBM_ATTR_ITEM: {
|
||||||
ItemPtr item = Item::create(fin->getU16());
|
ItemPtr item = Item::create(fin->getU16());
|
||||||
if (!item) {
|
if (!item) {
|
||||||
g_logger.error(stdext::format("failed to create new item at tile pos %d, %d, %d", px, py, pz));
|
g_logger.error(stdext::format("failed to create new item at tile pos %d, %d, %d", px, py, pz));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tile) {
|
if (tile) {
|
||||||
tile->addThing(item);
|
tile->addThing(item);
|
||||||
} else if (item->isGround()) {
|
} else if (item->isGround()) {
|
||||||
ground = item;
|
ground = item;
|
||||||
} else {
|
} else {
|
||||||
tile = createTile(pos);
|
tile = createTile(pos);
|
||||||
tile->addThing(ground);
|
tile->addThing(ground);
|
||||||
tile->addThing(item);
|
tile->addThing(item);
|
||||||
}
|
}
|
||||||
} default: {
|
} default: {
|
||||||
g_logger.error(stdext::format("invalid tile attribute at pos %d, %d, %d", px, py, pz));
|
g_logger.error(stdext::format("invalid tile attribute at pos %d, %d, %d", px, py, pz));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8 nodeItem;
|
uint8 nodeItem;
|
||||||
do {
|
do {
|
||||||
nodeItem = fin->readNode(nodeTile, type);
|
nodeItem = fin->readNode(nodeTile, type);
|
||||||
|
|
||||||
if (type == OTBM_ITEM) {
|
if (type == OTBM_ITEM) {
|
||||||
ItemPtr item = Item::create(fin->getU16());
|
ItemPtr item = Item::create(fin->getU16());
|
||||||
if (!item) {
|
if (!item) {
|
||||||
g_logger.error(stdext::format("failed to create new item at pos %d, %d, %d", px, py, pz));
|
g_logger.error(stdext::format("failed to create new item at pos %d, %d, %d", px, py, pz));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item->unserializeItemNode(fin, nodeItem)) {
|
if (item->unserializeItemNode(fin, nodeItem)) {
|
||||||
if (/* house && */item->isMovable()) {
|
if (/* house && */item->isMovable()) {
|
||||||
g_logger.warning(stdext::format("Movable item found in house: %d at pos %d %d %d", item->getId(),
|
g_logger.warning(stdext::format("Movable item found in house: %d at pos %d %d %d", item->getId(),
|
||||||
px, py, pz));
|
px, py, pz));
|
||||||
item = 0;
|
item = 0;
|
||||||
} else if (tile) {
|
} else if (tile) {
|
||||||
tile->addThing(item);
|
tile->addThing(item);
|
||||||
} else if (item->isGround()) {
|
} else if (item->isGround()) {
|
||||||
ground = item;
|
ground = item;
|
||||||
} else {
|
} else {
|
||||||
tile = createTile(pos);
|
tile = createTile(pos);
|
||||||
tile->addThing(ground);
|
tile->addThing(ground);
|
||||||
tile->addThing(item);
|
tile->addThing(item);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
g_logger.error(stdext::format("failed to unserialize item with %d at pos %d %d %d", item->getId(),
|
g_logger.error(stdext::format("failed to unserialize item with %d at pos %d %d %d", item->getId(),
|
||||||
px, py, pz));
|
px, py, pz));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
g_logger.error(stdext::format("Unknown item node type %d", type));
|
g_logger.error(stdext::format("Unknown item node type %d", type));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} while (nodeItem);
|
} while (nodeItem);
|
||||||
|
|
||||||
if (!tile) {
|
if (!tile) {
|
||||||
tile = createTile(pos);
|
tile = createTile(pos);
|
||||||
tile->addThing(ground);
|
tile->addThing(ground);
|
||||||
}
|
}
|
||||||
|
|
||||||
tile->setFlags((tileflags_t)flags);
|
tile->setFlags((tileflags_t)flags);
|
||||||
} else {
|
} else {
|
||||||
g_logger.error(stdext::format("Unknown tile node type %d", type));
|
g_logger.error(stdext::format("Unknown tile node type %d", type));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} while (nodeTile);
|
} while (nodeTile);
|
||||||
} else if (type == OTBM_TOWNS) {
|
} else if (type == OTBM_TOWNS) {
|
||||||
uint8 nodeTown;
|
uint8 nodeTown;
|
||||||
do {
|
do {
|
||||||
nodeTown = fin->readNode(nodeMapData, type);
|
nodeTown = fin->readNode(nodeMapData, type);
|
||||||
|
|
||||||
if (type == OTBM_TOWN) {
|
if (type == OTBM_TOWN) {
|
||||||
uint32 townId = fin->getU32();
|
uint32 townId = fin->getU32();
|
||||||
std::string townName = fin->getString();
|
std::string townName = fin->getString();
|
||||||
|
|
||||||
Position townCoords(fin->getU16(), fin->getU16(), fin->getU8());
|
Position townCoords(fin->getU16(), fin->getU16(), fin->getU8());
|
||||||
} else {
|
} else {
|
||||||
g_logger.error(stdext::format("Unknown town node type %d", type));
|
g_logger.error(stdext::format("Unknown town node type %d", type));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} while (nodeTown);
|
} while (nodeTown);
|
||||||
} else if (type == OTBM_WAYPOINTS && headerVersion > 1) {
|
} else if (type == OTBM_WAYPOINTS && headerVersion > 1) {
|
||||||
uint8 nodeWaypoint;
|
uint8 nodeWaypoint;
|
||||||
do {
|
do {
|
||||||
nodeWaypoint = fin->readNode(nodeMapData, type);
|
nodeWaypoint = fin->readNode(nodeMapData, type);
|
||||||
|
|
||||||
if (type == OTBM_WAYPOINT) {
|
if (type == OTBM_WAYPOINT) {
|
||||||
std::string name = fin->getString();
|
std::string name = fin->getString();
|
||||||
Position waypointPos(fin->getU16(), fin->getU16(), fin->getU8());
|
Position waypointPos(fin->getU16(), fin->getU16(), fin->getU8());
|
||||||
}
|
}
|
||||||
} while (nodeWaypoint);
|
} while (nodeWaypoint);
|
||||||
} else {
|
} else {
|
||||||
g_logger.error(stdext::format("Unknown map node %d", type));
|
g_logger.error(stdext::format("Unknown map node %d", type));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} while (nodeMapData);
|
} while (nodeMapData);
|
||||||
|
|
||||||
// TODO: Load house & spawns.
|
// TODO: Load house & spawns.
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Map::save(const std::string& fileName)
|
bool Map::loadOTCM(const std::string& fileName)
|
||||||
|
{
|
||||||
|
if(!g_resources.fileExists(fileName)) {
|
||||||
|
g_logger.error(stdext::format("Unable to load map '%s'", fileName));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::stringstream in;
|
||||||
|
g_resources.loadFile(fileName, in);
|
||||||
|
|
||||||
|
while(!in.eof()) {
|
||||||
|
Position pos;
|
||||||
|
in.read((char*)&pos, sizeof(pos));
|
||||||
|
|
||||||
|
uint16 id;
|
||||||
|
in.read((char*)&id, sizeof(id));
|
||||||
|
while(id != 0xFFFF) {
|
||||||
|
ItemPtr item = Item::create(id);
|
||||||
|
if(item->isStackable() || item->isFluidContainer() || item->isFluid()) {
|
||||||
|
uint8 countOrSubType;
|
||||||
|
in.read((char*)&countOrSubType, sizeof(countOrSubType));
|
||||||
|
item->setCountOrSubType(countOrSubType);
|
||||||
|
}
|
||||||
|
addThing(item, pos, 255);
|
||||||
|
in.read((char*)&id, sizeof(id));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Map::saveOTCM(const std::string& fileName)
|
||||||
{
|
{
|
||||||
std::stringstream out;
|
std::stringstream out;
|
||||||
|
|
||||||
|
|
|
@ -29,50 +29,50 @@
|
||||||
|
|
||||||
enum OTBM_AttrTypes_t
|
enum OTBM_AttrTypes_t
|
||||||
{
|
{
|
||||||
OTBM_ATTR_DESCRIPTION = 1,
|
OTBM_ATTR_DESCRIPTION = 1,
|
||||||
OTBM_ATTR_EXT_FILE = 2,
|
OTBM_ATTR_EXT_FILE = 2,
|
||||||
OTBM_ATTR_TILE_FLAGS = 3,
|
OTBM_ATTR_TILE_FLAGS = 3,
|
||||||
OTBM_ATTR_ACTION_ID = 4,
|
OTBM_ATTR_ACTION_ID = 4,
|
||||||
OTBM_ATTR_UNIQUE_ID = 5,
|
OTBM_ATTR_UNIQUE_ID = 5,
|
||||||
OTBM_ATTR_TEXT = 6,
|
OTBM_ATTR_TEXT = 6,
|
||||||
OTBM_ATTR_DESC = 7,
|
OTBM_ATTR_DESC = 7,
|
||||||
OTBM_ATTR_TELE_DEST = 8,
|
OTBM_ATTR_TELE_DEST = 8,
|
||||||
OTBM_ATTR_ITEM = 9,
|
OTBM_ATTR_ITEM = 9,
|
||||||
OTBM_ATTR_DEPOT_ID = 10,
|
OTBM_ATTR_DEPOT_ID = 10,
|
||||||
OTBM_ATTR_SPAWN_FILE = 11,
|
OTBM_ATTR_SPAWN_FILE = 11,
|
||||||
OTBM_ATTR_RUNE_CHARGES = 12,
|
OTBM_ATTR_RUNE_CHARGES = 12,
|
||||||
OTBM_ATTR_HOUSE_FILE = 13,
|
OTBM_ATTR_HOUSE_FILE = 13,
|
||||||
OTBM_ATTR_HPPOUSEDOORID = 14,
|
OTBM_ATTR_HPPOUSEDOORID = 14,
|
||||||
OTBM_ATTR_COUNT = 15,
|
OTBM_ATTR_COUNT = 15,
|
||||||
OTBM_ATTR_DURATION = 16,
|
OTBM_ATTR_DURATION = 16,
|
||||||
OTBM_ATTR_DECAYING_STATE = 17,
|
OTBM_ATTR_DECAYING_STATE = 17,
|
||||||
OTBM_ATTR_WRITTENDATE = 18,
|
OTBM_ATTR_WRITTENDATE = 18,
|
||||||
OTBM_ATTR_WRITTENBY = 19,
|
OTBM_ATTR_WRITTENBY = 19,
|
||||||
OTBM_ATTR_SLEEPERGUID = 20,
|
OTBM_ATTR_SLEEPERGUID = 20,
|
||||||
OTBM_ATTR_SLEEPSTART = 21,
|
OTBM_ATTR_SLEEPSTART = 21,
|
||||||
OTBM_ATTR_CHARGES = 22,
|
OTBM_ATTR_CHARGES = 22,
|
||||||
OTBM_ATTR_CONTAINER_ITEMS = 23,
|
OTBM_ATTR_CONTAINER_ITEMS = 23,
|
||||||
OTBM_ATTR_ATTRIBUTE_MAP = 128
|
OTBM_ATTR_ATTRIBUTE_MAP = 128
|
||||||
};
|
};
|
||||||
|
|
||||||
enum OTBM_NodeTypes_t
|
enum OTBM_NodeTypes_t
|
||||||
{
|
{
|
||||||
OTBM_ROOTV2 = 1,
|
OTBM_ROOTV2 = 1,
|
||||||
OTBM_MAP_DATA = 2,
|
OTBM_MAP_DATA = 2,
|
||||||
OTBM_ITEM_DEF = 3,
|
OTBM_ITEM_DEF = 3,
|
||||||
OTBM_TILE_AREA = 4,
|
OTBM_TILE_AREA = 4,
|
||||||
OTBM_TILE = 5,
|
OTBM_TILE = 5,
|
||||||
OTBM_ITEM = 6,
|
OTBM_ITEM = 6,
|
||||||
OTBM_TILE_SQUARE = 7,
|
OTBM_TILE_SQUARE = 7,
|
||||||
OTBM_TILE_REF = 8,
|
OTBM_TILE_REF = 8,
|
||||||
OTBM_SPAWNS = 9,
|
OTBM_SPAWNS = 9,
|
||||||
OTBM_SPAWN_AREA = 10,
|
OTBM_SPAWN_AREA = 10,
|
||||||
OTBM_MONSTER = 11,
|
OTBM_MONSTER = 11,
|
||||||
OTBM_TOWNS = 12,
|
OTBM_TOWNS = 12,
|
||||||
OTBM_TOWN = 13,
|
OTBM_TOWN = 13,
|
||||||
OTBM_HOUSETILE = 14,
|
OTBM_HOUSETILE = 14,
|
||||||
OTBM_WAYPOINTS = 15,
|
OTBM_WAYPOINTS = 15,
|
||||||
OTBM_WAYPOINT = 16
|
OTBM_WAYPOINT = 16
|
||||||
};
|
};
|
||||||
|
|
||||||
class Map
|
class Map
|
||||||
|
@ -82,8 +82,12 @@ public:
|
||||||
void removeMapView(const MapViewPtr& mapView);
|
void removeMapView(const MapViewPtr& mapView);
|
||||||
void notificateTileUpdateToMapViews(const Position& pos);
|
void notificateTileUpdateToMapViews(const Position& pos);
|
||||||
|
|
||||||
bool load(const std::string& fileName);
|
bool loadOTCM(const std::string& fileName);
|
||||||
void save(const std::string& fileName);
|
void saveOTCM(const std::string& fileName);
|
||||||
|
|
||||||
|
bool loadOTBM(const std::string& fileName);
|
||||||
|
//void saveOTBM(const std::string& fileName);
|
||||||
|
|
||||||
void clean();
|
void clean();
|
||||||
void cleanDynamicThings();
|
void cleanDynamicThings();
|
||||||
void cleanTexts();
|
void cleanTexts();
|
||||||
|
@ -138,7 +142,7 @@ private:
|
||||||
Light m_light;
|
Light m_light;
|
||||||
Position m_centralPosition;
|
Position m_centralPosition;
|
||||||
|
|
||||||
std::string m_description, m_spawnFile, m_houseFile;
|
std::string m_description, m_spawnFile, m_houseFile;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern Map g_map;
|
extern Map g_map;
|
||||||
|
|
|
@ -28,22 +28,22 @@
|
||||||
|
|
||||||
enum tileflags_t
|
enum tileflags_t
|
||||||
{
|
{
|
||||||
TILESTATE_NONE = 0,
|
TILESTATE_NONE = 0,
|
||||||
TILESTATE_PROTECTIONZONE = 1 << 0,
|
TILESTATE_PROTECTIONZONE = 1 << 0,
|
||||||
TILESTATE_TRASHED = 1 << 1,
|
TILESTATE_TRASHED = 1 << 1,
|
||||||
TILESTATE_OPTIONALZONE = 1 << 2,
|
TILESTATE_OPTIONALZONE = 1 << 2,
|
||||||
TILESTATE_NOLOGOUT = 1 << 3,
|
TILESTATE_NOLOGOUT = 1 << 3,
|
||||||
TILESTATE_HPPARDCOREZONE = 1 << 4,
|
TILESTATE_HPPARDCOREZONE = 1 << 4,
|
||||||
TILESTATE_REFRESH = 1 << 5,
|
TILESTATE_REFRESH = 1 << 5,
|
||||||
|
|
||||||
// internal usage
|
// internal usage
|
||||||
TILESTATE_HOUSE = 1 << 6,
|
TILESTATE_HOUSE = 1 << 6,
|
||||||
TILESTATE_TELEPORT = 1 << 17,
|
TILESTATE_TELEPORT = 1 << 17,
|
||||||
TILESTATE_MAGICFIELD = 1 << 18,
|
TILESTATE_MAGICFIELD = 1 << 18,
|
||||||
TILESTATE_MAILBOX = 1 << 19,
|
TILESTATE_MAILBOX = 1 << 19,
|
||||||
TILESTATE_TRASHHOLDER = 1 << 20,
|
TILESTATE_TRASHHOLDER = 1 << 20,
|
||||||
TILESTATE_BED = 1 << 21,
|
TILESTATE_BED = 1 << 21,
|
||||||
TILESTATE_DEPOT = 1 << 22
|
TILESTATE_DEPOT = 1 << 22
|
||||||
};
|
};
|
||||||
|
|
||||||
class Tile : public LuaObject
|
class Tile : public LuaObject
|
||||||
|
@ -98,7 +98,7 @@ public:
|
||||||
bool canErase();
|
bool canErase();
|
||||||
|
|
||||||
TilePtr asTile() { return std::static_pointer_cast<Tile>(shared_from_this()); }
|
TilePtr asTile() { return std::static_pointer_cast<Tile>(shared_from_this()); }
|
||||||
void setFlags(tileflags_t flags) { m_flags |= (uint32)flags; }
|
void setFlags(tileflags_t flags) { m_flags |= (uint32)flags; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<CreaturePtr> m_walkingCreatures;
|
std::vector<CreaturePtr> m_walkingCreatures;
|
||||||
|
@ -106,7 +106,7 @@ private:
|
||||||
std::vector<ThingPtr> m_things;
|
std::vector<ThingPtr> m_things;
|
||||||
Position m_position;
|
Position m_position;
|
||||||
uint8 m_drawElevation;
|
uint8 m_drawElevation;
|
||||||
uint32 m_flags;
|
uint32 m_flags;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -76,8 +76,10 @@ void OTClient::registerLuaFunctions()
|
||||||
g_lua.bindSingletonFunction("g_map", "removeCreatureById", &Map::removeCreatureById, &g_map);
|
g_lua.bindSingletonFunction("g_map", "removeCreatureById", &Map::removeCreatureById, &g_map);
|
||||||
g_lua.bindSingletonFunction("g_map", "getSpectators", &Map::getSpectators, &g_map);
|
g_lua.bindSingletonFunction("g_map", "getSpectators", &Map::getSpectators, &g_map);
|
||||||
g_lua.bindSingletonFunction("g_map", "findPath", &Map::findPath, &g_map);
|
g_lua.bindSingletonFunction("g_map", "findPath", &Map::findPath, &g_map);
|
||||||
g_lua.bindSingletonFunction("g_map", "load", &Map::load, &g_map);
|
g_lua.bindSingletonFunction("g_map", "loadOTBM", &Map::loadOTBM, &g_map);
|
||||||
g_lua.bindSingletonFunction("g_map", "save", &Map::save, &g_map);
|
//g_lua.bindSingletonFunction("g_map", "saveOTBM", &Map::save, &g_map);
|
||||||
|
g_lua.bindSingletonFunction("g_map", "loadOTCM", &Map::loadOTCM, &g_map);
|
||||||
|
g_lua.bindSingletonFunction("g_map", "saveOTCM", &Map::saveOTCM, &g_map);
|
||||||
|
|
||||||
g_lua.registerSingletonClass("g_game");
|
g_lua.registerSingletonClass("g_game");
|
||||||
g_lua.bindSingletonFunction("g_game", "loginWorld", &Game::loginWorld, &g_game);
|
g_lua.bindSingletonFunction("g_game", "loginWorld", &Game::loginWorld, &g_game);
|
||||||
|
|
Loading…
Reference in New Issue