Adjust fallen changes

* Restore old map load() used in minimap
* Change tabs to 4 spaces
* Add missing cmake file
This commit is contained in:
Eduardo Bart 2012-06-21 00:05:44 -03:00
parent 6b0d922dd9
commit f3499efe83
17 changed files with 4629 additions and 4590 deletions

View File

@ -251,26 +251,26 @@ std::string FileStream::getString()
uint8 FileStream::readNode(uint8 &oldNode, uint32 &type)
{
if (!oldNode) {
if ((oldNode = getU8()) == 0xFE) {
type = getU32();
return oldNode;
} else {
dump << "Failed to read new node.";
return 0;
}
}
if (!oldNode) {
if ((oldNode = getU8()) == 0xFE) {
type = getU32();
return oldNode;
} else {
dump << "Failed to read new node.";
return 0;
}
}
assert(getU8() == 0xFF);
if ((oldNode = getU8()) == 0xFE) {
type = getU32();
return oldNode;
} else {
dump << "Failed to read node with old type: " << type;
return 0;
}
assert(getU8() == 0xFF);
if ((oldNode = getU8()) == 0xFE) {
type = getU32();
return oldNode;
} else {
dump << "Failed to read node with old type: " << type;
return 0;
}
return 0;
return 0;
}
void FileStream::addU8(uint8 v)

View File

@ -59,7 +59,7 @@ public:
void addU32(uint8 v);
void addU64(uint8 v);
uint8 readNode(uint8 &oldNode, uint32 &type);
uint8 readNode(uint8 &oldNode, uint32 &type);
private:
std::string m_name;
PHYSFS_File *m_fileHandle;

View File

@ -36,76 +36,76 @@ TiXmlString::Rep TiXmlString::nullrep_ = { 0, 0, { '\0' } };
void TiXmlString::reserve (size_type cap)
{
if (cap > capacity())
{
TiXmlString tmp;
tmp.init(length(), cap);
memcpy(tmp.start(), data(), length());
swap(tmp);
}
if (cap > capacity())
{
TiXmlString tmp;
tmp.init(length(), cap);
memcpy(tmp.start(), data(), length());
swap(tmp);
}
}
TiXmlString& TiXmlString::assign(const char* str, size_type len)
{
size_type cap = capacity();
if (len > cap || cap > 3*(len + 8))
{
TiXmlString tmp;
tmp.init(len);
memcpy(tmp.start(), str, len);
swap(tmp);
}
else
{
memmove(start(), str, len);
set_size(len);
}
return *this;
size_type cap = capacity();
if (len > cap || cap > 3*(len + 8))
{
TiXmlString tmp;
tmp.init(len);
memcpy(tmp.start(), str, len);
swap(tmp);
}
else
{
memmove(start(), str, len);
set_size(len);
}
return *this;
}
TiXmlString& TiXmlString::append(const char* str, size_type len)
{
size_type newsize = length() + len;
if (newsize > capacity())
{
reserve (newsize + capacity());
}
memmove(finish(), str, len);
set_size(newsize);
return *this;
size_type newsize = length() + len;
if (newsize > capacity())
{
reserve (newsize + capacity());
}
memmove(finish(), str, len);
set_size(newsize);
return *this;
}
TiXmlString operator + (const TiXmlString & a, const TiXmlString & b)
{
TiXmlString tmp;
tmp.reserve(a.length() + b.length());
tmp += a;
tmp += b;
return tmp;
TiXmlString tmp;
tmp.reserve(a.length() + b.length());
tmp += a;
tmp += b;
return tmp;
}
TiXmlString operator + (const TiXmlString & a, const char* b)
{
TiXmlString tmp;
TiXmlString::size_type b_len = static_cast<TiXmlString::size_type>( strlen(b) );
tmp.reserve(a.length() + b_len);
tmp += a;
tmp.append(b, b_len);
return tmp;
TiXmlString tmp;
TiXmlString::size_type b_len = static_cast<TiXmlString::size_type>( strlen(b) );
tmp.reserve(a.length() + b_len);
tmp += a;
tmp.append(b, b_len);
return tmp;
}
TiXmlString operator + (const char* a, const TiXmlString & b)
{
TiXmlString tmp;
TiXmlString::size_type a_len = static_cast<TiXmlString::size_type>( strlen(a) );
tmp.reserve(a_len + b.length());
tmp.append(a, a_len);
tmp += b;
return tmp;
TiXmlString tmp;
TiXmlString::size_type a_len = static_cast<TiXmlString::size_type>( strlen(a) );
tmp.reserve(a_len + b.length());
tmp.append(a, a_len);
tmp += b;
return tmp;
}
#endif // TIXML_USE_STL
#endif // TIXML_USE_STL

View File

@ -30,18 +30,18 @@ distribution.
#include <assert.h>
#include <string.h>
/* 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
used. Be nice to old compilers and macro it here:
/* 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
used. Be nice to old compilers and macro it here:
*/
#if defined(_MSC_VER) && (_MSC_VER >= 1200 )
// Microsoft visual studio, version 6 and higher.
#define TIXML_EXPLICIT explicit
// Microsoft visual studio, version 6 and higher.
#define TIXML_EXPLICIT explicit
#elif defined(__GNUC__) && (__GNUC__ >= 3 )
// GCC version 3 and higher.s
#define TIXML_EXPLICIT explicit
// GCC version 3 and higher.s
#define TIXML_EXPLICIT explicit
#else
#define TIXML_EXPLICIT
#define TIXML_EXPLICIT
#endif
@ -55,211 +55,211 @@ distribution.
class TiXmlString
{
public :
// The size type used
typedef size_t size_type;
// The size type used
typedef size_t size_type;
// Error value for find primitive
static const size_type npos; // = -1;
// Error value for find primitive
static const size_type npos; // = -1;
// TiXmlString empty constructor
TiXmlString () : rep_(&nullrep_)
{
}
// TiXmlString empty constructor
TiXmlString () : rep_(&nullrep_)
{
}
// TiXmlString copy constructor
TiXmlString ( const TiXmlString & copy) : rep_(0)
{
init(copy.length());
memcpy(start(), copy.data(), length());
}
// TiXmlString copy constructor
TiXmlString ( const TiXmlString & copy) : rep_(0)
{
init(copy.length());
memcpy(start(), copy.data(), length());
}
// TiXmlString constructor, based on a string
TIXML_EXPLICIT TiXmlString ( const char * copy) : rep_(0)
{
init( static_cast<size_type>( strlen(copy) ));
memcpy(start(), copy, length());
}
// TiXmlString constructor, based on a string
TIXML_EXPLICIT TiXmlString ( const char * copy) : rep_(0)
{
init( static_cast<size_type>( strlen(copy) ));
memcpy(start(), copy, length());
}
// TiXmlString constructor, based on a string
TIXML_EXPLICIT TiXmlString ( const char * str, size_type len) : rep_(0)
{
init(len);
memcpy(start(), str, len);
}
// TiXmlString constructor, based on a string
TIXML_EXPLICIT TiXmlString ( const char * str, size_type len) : rep_(0)
{
init(len);
memcpy(start(), str, len);
}
// TiXmlString destructor
~TiXmlString ()
{
quit();
}
// TiXmlString destructor
~TiXmlString ()
{
quit();
}
TiXmlString& operator = (const char * copy)
{
return assign( copy, (size_type)strlen(copy));
}
TiXmlString& operator = (const char * copy)
{
return assign( copy, (size_type)strlen(copy));
}
TiXmlString& operator = (const TiXmlString & copy)
{
return assign(copy.start(), copy.length());
}
TiXmlString& operator = (const TiXmlString & copy)
{
return assign(copy.start(), copy.length());
}
// += operator. Maps to append
TiXmlString& operator += (const char * suffix)
{
return append(suffix, static_cast<size_type>( strlen(suffix) ));
}
// += operator. Maps to append
TiXmlString& operator += (const char * suffix)
{
return append(suffix, static_cast<size_type>( strlen(suffix) ));
}
// += operator. Maps to append
TiXmlString& operator += (char single)
{
return append(&single, 1);
}
// += operator. Maps to append
TiXmlString& operator += (char single)
{
return append(&single, 1);
}
// += operator. Maps to append
TiXmlString& operator += (const TiXmlString & suffix)
{
return append(suffix.data(), suffix.length());
}
// += operator. Maps to append
TiXmlString& operator += (const TiXmlString & suffix)
{
return append(suffix.data(), suffix.length());
}
// Convert a TiXmlString into a null-terminated char *
const char * c_str () const { return rep_->str; }
// Convert a TiXmlString into a null-terminated char *
const char * c_str () const { return rep_->str; }
// Convert a TiXmlString into a char * (need not be null terminated).
const char * data () const { return rep_->str; }
// Convert a TiXmlString into a char * (need not be null terminated).
const char * data () const { return rep_->str; }
// Return the length of a TiXmlString
size_type length () const { return rep_->size; }
// Return the length of a TiXmlString
size_type length () const { return rep_->size; }
// Alias for length()
size_type size () const { return rep_->size; }
// Alias for length()
size_type size () const { return rep_->size; }
// Checks if a TiXmlString is empty
bool empty () const { return rep_->size == 0; }
// Checks if a TiXmlString is empty
bool empty () const { return rep_->size == 0; }
// Return capacity of string
size_type capacity () const { return rep_->capacity; }
// Return capacity of string
size_type capacity () const { return rep_->capacity; }
// single char extraction
const char& at (size_type index) const
{
assert( index < length() );
return rep_->str[ index ];
}
// single char extraction
const char& at (size_type index) const
{
assert( index < length() );
return rep_->str[ index ];
}
// [] operator
char& operator [] (size_type index) const
{
assert( index < length() );
return rep_->str[ index ];
}
// [] operator
char& operator [] (size_type index) const
{
assert( index < length() );
return rep_->str[ index ];
}
// find a char in a string. Return TiXmlString::npos if not found
size_type find (char lookup) const
{
return find(lookup, 0);
}
// find a char in a string. Return TiXmlString::npos if not found
size_type find (char lookup) const
{
return find(lookup, 0);
}
// find a char in a string from an offset. Return TiXmlString::npos if not found
size_type find (char tofind, size_type offset) const
{
if (offset >= length()) return npos;
// find a char in a string from an offset. Return TiXmlString::npos if not found
size_type find (char tofind, size_type offset) const
{
if (offset >= length()) return npos;
for (const char* p = c_str() + offset; *p != '\0'; ++p)
{
if (*p == tofind) return static_cast< size_type >( p - c_str() );
}
return npos;
}
for (const char* p = c_str() + offset; *p != '\0'; ++p)
{
if (*p == tofind) return static_cast< size_type >( p - c_str() );
}
return npos;
}
void clear ()
{
//Lee:
//The original was just too strange, though correct:
// TiXmlString().swap(*this);
//Instead use the quit & re-init:
quit();
init(0,0);
}
void clear ()
{
//Lee:
//The original was just too strange, though correct:
// TiXmlString().swap(*this);
//Instead use the quit & re-init:
quit();
init(0,0);
}
/* 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.
*/
void reserve (size_type cap);
/* 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.
*/
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)
{
Rep* r = rep_;
rep_ = other.rep_;
other.rep_ = r;
}
void swap (TiXmlString& other)
{
Rep* r = rep_;
rep_ = other.rep_;
other.rep_ = r;
}
private:
void init(size_type sz) { init(sz, sz); }
void set_size(size_type sz) { rep_->str[ rep_->size = sz ] = '\0'; }
char* start() const { return rep_->str; }
char* finish() const { return rep_->str + rep_->size; }
void init(size_type sz) { init(sz, sz); }
void set_size(size_type sz) { rep_->str[ rep_->size = sz ] = '\0'; }
char* start() const { return rep_->str; }
char* finish() const { return rep_->str + rep_->size; }
struct Rep
{
size_type size, capacity;
char str[1];
};
struct Rep
{
size_type size, capacity;
char str[1];
};
void init(size_type sz, size_type cap)
{
if (cap)
{
// Lee: the original form:
// rep_ = static_cast<Rep*>(operator new(sizeof(Rep) + cap));
// doesn't work in some cases of new being overloaded. Switching
// to the normal allocation, although use an 'int' for systems
// that are overly picky about structure alignment.
const size_type bytesNeeded = sizeof(Rep) + cap;
const size_type intsNeeded = ( bytesNeeded + sizeof(int) - 1 ) / sizeof( int );
rep_ = reinterpret_cast<Rep*>( new int[ intsNeeded ] );
void init(size_type sz, size_type cap)
{
if (cap)
{
// Lee: the original form:
// rep_ = static_cast<Rep*>(operator new(sizeof(Rep) + cap));
// doesn't work in some cases of new being overloaded. Switching
// to the normal allocation, although use an 'int' for systems
// that are overly picky about structure alignment.
const size_type bytesNeeded = sizeof(Rep) + cap;
const size_type intsNeeded = ( bytesNeeded + sizeof(int) - 1 ) / sizeof( int );
rep_ = reinterpret_cast<Rep*>( new int[ intsNeeded ] );
rep_->str[ rep_->size = sz ] = '\0';
rep_->capacity = cap;
}
else
{
rep_ = &nullrep_;
}
}
rep_->str[ rep_->size = sz ] = '\0';
rep_->capacity = cap;
}
else
{
rep_ = &nullrep_;
}
}
void quit()
{
if (rep_ != &nullrep_)
{
// 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.
delete [] ( reinterpret_cast<int*>( rep_ ) );
}
}
void quit()
{
if (rep_ != &nullrep_)
{
// 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.
delete [] ( reinterpret_cast<int*>( rep_ ) );
}
}
Rep * rep_;
static Rep nullrep_;
Rep * rep_;
static Rep nullrep_;
} ;
inline bool operator == (const TiXmlString & a, const TiXmlString & b)
{
return ( a.length() == b.length() ) // optimization on some platforms
&& ( strcmp(a.c_str(), b.c_str()) == 0 ); // actual compare
return ( a.length() == b.length() ) // optimization on some platforms
&& ( strcmp(a.c_str(), b.c_str()) == 0 ); // actual compare
}
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); }
@ -285,21 +285,21 @@ class TiXmlOutStream : public TiXmlString
{
public :
// TiXmlOutStream << operator.
TiXmlOutStream & operator << (const TiXmlString & in)
{
*this += in;
return *this;
}
// TiXmlOutStream << operator.
TiXmlOutStream & operator << (const TiXmlString & in)
{
*this += in;
return *this;
}
// TiXmlOutStream << operator.
TiXmlOutStream & operator << (const char * in)
{
*this += in;
return *this;
}
// TiXmlOutStream << operator.
TiXmlOutStream & operator << (const char * in)
{
*this += in;
return *this;
}
} ;
#endif // TIXML_STRING_INCLUDED
#endif // TIXML_USE_STL
#endif // TIXML_STRING_INCLUDED
#endif // TIXML_USE_STL

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -33,20 +33,20 @@ distribution.
const char* TiXmlBase::errorString[ TiXmlBase::TIXML_ERROR_STRING_COUNT ] =
{
"No error",
"Error",
"Failed to open file",
"Error parsing Element.",
"Failed to read Element name",
"Error reading Element value.",
"Error reading Attributes.",
"Error: empty tag.",
"Error reading end tag.",
"Error parsing Unknown.",
"Error parsing Comment.",
"Error parsing Declaration.",
"Error document empty.",
"Error null (0) or unexpected EOF found in input stream.",
"Error parsing CDATA.",
"Error when TiXmlDocument added to document, because TiXmlDocument can only be at the root.",
"No error",
"Error",
"Failed to open file",
"Error parsing Element.",
"Failed to read Element name",
"Error reading Element value.",
"Error reading Attributes.",
"Error: empty tag.",
"Error reading end tag.",
"Error parsing Unknown.",
"Error parsing Comment.",
"Error parsing Declaration.",
"Error document empty.",
"Error null (0) or unexpected EOF found in input stream.",
"Error parsing CDATA.",
"Error when TiXmlDocument added to document, because TiXmlDocument can only be at the root.",
};

File diff suppressed because it is too large Load Diff

View File

@ -48,6 +48,8 @@ SET(otclient_SOURCES ${otclient_SOURCES}
${CMAKE_CURRENT_LIST_DIR}/core/shadermanager.h
${CMAKE_CURRENT_LIST_DIR}/core/item.cpp
${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.h
${CMAKE_CURRENT_LIST_DIR}/core/map.cpp

View File

@ -192,67 +192,67 @@ void Item::setId(uint32 id)
bool Item::unserializeAttr(FileStreamPtr fin)
{
uint8 attrType;
while ((attrType = fin->getU8()) != 0)
readAttr((AttrTypes_t)attrType, fin);
uint8 attrType;
while ((attrType = fin->getU8()) != 0)
readAttr((AttrTypes_t)attrType, fin);
return true;
return true;
}
void Item::readAttr(AttrTypes_t attrType, FileStreamPtr fin)
{
switch (attrType) {
case ATTR_COUNT:
setSubType(fin->getU8());
break;
case ATTR_ACTION_ID:
setActionId(fin->getU16());
break;
case ATTR_UNIQUE_ID:
setUniqueId(fin->getU16());
break;
case ATTR_NAME:
setName(fin->getString());
break;
case ATTR_ARTICLE:
fin->getString();
case ATTR_ATTACK: // \/ not needed.
case ATTR_EXTRAATTACK:
case ATTR_DEFENSE:
case ATTR_EXTRADEFENSE:
case ATTR_ARMOR:
case ATTR_ATTACKSPEED:
case ATTR_HPPITCHANCE:
case ATTR_DURATION:
fin->getU32();
break;
case ATTR_SCRIPTPROTECTED:
case ATTR_DUALWIELD:
case ATTR_DECAYING_STATE:
case ATTR_HPPOUSEDOORID:
fin->getU8();
break;
case ATTR_TEXT:
setText(fin->getString());
break;
case ATTR_WRITTENDATE:
fin->getU32();
break;
case ATTR_WRITTENBY:
fin->getString();
break;
case ATTR_DESC:
setDescription(fin->getString());
break;
case ATTR_RUNE_CHARGES:
fin->getU8();
break;
case ATTR_TELE_DEST: // Teleport should read that.
case ATTR_SLEEPERGUID: // Bed should read that.
case ATTR_SLEEPSTART:
case ATTR_CONTAINER_ITEMS:
case ATTR_ATTRIBUTE_MAP:
default:
break;
}
switch (attrType) {
case ATTR_COUNT:
setSubType(fin->getU8());
break;
case ATTR_ACTION_ID:
setActionId(fin->getU16());
break;
case ATTR_UNIQUE_ID:
setUniqueId(fin->getU16());
break;
case ATTR_NAME:
setName(fin->getString());
break;
case ATTR_ARTICLE:
fin->getString();
case ATTR_ATTACK: // \/ not needed.
case ATTR_EXTRAATTACK:
case ATTR_DEFENSE:
case ATTR_EXTRADEFENSE:
case ATTR_ARMOR:
case ATTR_ATTACKSPEED:
case ATTR_HPPITCHANCE:
case ATTR_DURATION:
fin->getU32();
break;
case ATTR_SCRIPTPROTECTED:
case ATTR_DUALWIELD:
case ATTR_DECAYING_STATE:
case ATTR_HPPOUSEDOORID:
fin->getU8();
break;
case ATTR_TEXT:
setText(fin->getString());
break;
case ATTR_WRITTENDATE:
fin->getU32();
break;
case ATTR_WRITTENBY:
fin->getString();
break;
case ATTR_DESC:
setDescription(fin->getString());
break;
case ATTR_RUNE_CHARGES:
fin->getU8();
break;
case ATTR_TELE_DEST: // Teleport should read that.
case ATTR_SLEEPERGUID: // Bed should read that.
case ATTR_SLEEPSTART:
case ATTR_CONTAINER_ITEMS:
case ATTR_ATTRIBUTE_MAP:
default:
break;
}
}

View File

@ -27,44 +27,44 @@
#include "thing.h"
enum AttrTypes_t {
ATTR_END = 0,
//ATTR_DESCRIPTION = 1,
//ATTR_EXT_FILE = 2,
ATTR_TILE_FLAGS = 3,
ATTR_ACTION_ID = 4,
ATTR_UNIQUE_ID = 5,
ATTR_TEXT = 6,
ATTR_DESC = 7,
ATTR_TELE_DEST = 8,
ATTR_ITEM = 9,
ATTR_DEPOT_ID = 10,
//ATTR_EXT_SPAWN_FILE = 11,
ATTR_RUNE_CHARGES = 12,
//ATTR_EXT_HPPOUSE_FILE = 13,
ATTR_HPPOUSEDOORID = 14,
ATTR_COUNT = 15,
ATTR_DURATION = 16,
ATTR_DECAYING_STATE = 17,
ATTR_WRITTENDATE = 18,
ATTR_WRITTENBY = 19,
ATTR_SLEEPERGUID = 20,
ATTR_SLEEPSTART = 21,
ATTR_CHARGES = 22,
ATTR_CONTAINER_ITEMS = 23,
ATTR_NAME = 30,
ATTR_PLURALNAME = 31,
ATTR_ATTACK = 33,
ATTR_EXTRAATTACK = 34,
ATTR_DEFENSE = 35,
ATTR_EXTRADEFENSE = 36,
ATTR_ARMOR = 37,
ATTR_ATTACKSPEED = 38,
ATTR_HPPITCHANCE = 39,
ATTR_SHOOTRANGE = 40,
ATTR_ARTICLE = 41,
ATTR_SCRIPTPROTECTED = 42,
ATTR_DUALWIELD = 43,
ATTR_ATTRIBUTE_MAP = 128
ATTR_END = 0,
//ATTR_DESCRIPTION = 1,
//ATTR_EXT_FILE = 2,
ATTR_TILE_FLAGS = 3,
ATTR_ACTION_ID = 4,
ATTR_UNIQUE_ID = 5,
ATTR_TEXT = 6,
ATTR_DESC = 7,
ATTR_TELE_DEST = 8,
ATTR_ITEM = 9,
ATTR_DEPOT_ID = 10,
//ATTR_EXT_SPAWN_FILE = 11,
ATTR_RUNE_CHARGES = 12,
//ATTR_EXT_HPPOUSE_FILE = 13,
ATTR_HPPOUSEDOORID = 14,
ATTR_COUNT = 15,
ATTR_DURATION = 16,
ATTR_DECAYING_STATE = 17,
ATTR_WRITTENDATE = 18,
ATTR_WRITTENBY = 19,
ATTR_SLEEPERGUID = 20,
ATTR_SLEEPSTART = 21,
ATTR_CHARGES = 22,
ATTR_CONTAINER_ITEMS = 23,
ATTR_NAME = 30,
ATTR_PLURALNAME = 31,
ATTR_ATTACK = 33,
ATTR_EXTRAATTACK = 34,
ATTR_DEFENSE = 35,
ATTR_EXTRADEFENSE = 36,
ATTR_ARMOR = 37,
ATTR_ATTACKSPEED = 38,
ATTR_HPPITCHANCE = 39,
ATTR_SHOOTRANGE = 40,
ATTR_ARTICLE = 41,
ATTR_SCRIPTPROTECTED = 42,
ATTR_DUALWIELD = 43,
ATTR_ATTRIBUTE_MAP = 128
};
class Item : public Thing
@ -80,33 +80,33 @@ public:
void setCountOrSubType(int value) { m_countOrSubType = value; }
void setCount(int count) { m_countOrSubType = count; }
void setSubType(int subType) { m_countOrSubType = subType; }
void setActionId(int actionId) { m_actionId = actionId; }
void setUniqueId(int uniqueId) { m_uniqueId = uniqueId; }
void setName(const std::string &name) { m_name = name; }
void setText(const std::string &text) { m_text = text; }
void setDescription(const std::string &description) { m_description = description; }
void setActionId(int actionId) { m_actionId = actionId; }
void setUniqueId(int uniqueId) { m_uniqueId = uniqueId; }
void setName(const std::string &name) { m_name = name; }
void setText(const std::string &text) { m_text = text; }
void setDescription(const std::string &description) { m_description = description; }
int getCountOrSubType() { return m_countOrSubType; }
int getSubType() { return m_countOrSubType; }
int getCount() { return m_countOrSubType; }
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()); }
bool isItem() { return true; }
// TODO: These should be abstract and declared in i.e containers, doors, etc.
bool unserializeAttr(FileStreamPtr fin);
bool unserializeItemNode(FileStreamPtr fin, uint8) { return unserializeAttr(fin); }
void readAttr(AttrTypes_t attrType, FileStreamPtr fin);
// TODO: These should be abstract and declared in i.e containers, doors, etc.
bool unserializeAttr(FileStreamPtr fin);
bool unserializeItemNode(FileStreamPtr fin, uint8) { return unserializeAttr(fin); }
void readAttr(AttrTypes_t attrType, FileStreamPtr fin);
bool isMovable() { return false; }
bool isMovable() { return false; }
private:
uint16 m_id;
uint8 m_countOrSubType;
uint32 m_actionId, m_uniqueId;
std::string m_name, m_text, m_description;
uint32 m_actionId, m_uniqueId;
std::string m_name, m_text, m_description;
PainterShaderProgramPtr m_shaderProgram;
};

View File

@ -30,209 +30,209 @@ ItemLoader g_itemLoader;
ItemLoader::~ItemLoader()
{
m_items.clear();
m_items.clear();
}
ItemDataPtr ItemLoader::getType(uint16 id) const
{
for (const ItemDataPtr &it : m_items) {
if (it->id == id)
return it;
}
for (const ItemDataPtr &it : m_items) {
if (it->id == id)
return it;
}
return nullptr;
return nullptr;
}
void ItemLoader::addType(uint16 id, ItemDataPtr type)
{
if (getType(id))
return;
if (getType(id))
return;
m_items.push_back(type);
m_items.push_back(type);
}
bool ItemLoader::loadOtb(const std::string &name)
{
FileStreamPtr fin = g_resources.openFile(name);
if (!fin) {
g_logger.error(stdext::format("failed to open file '%s'", name));
return false;
}
FileStreamPtr fin = g_resources.openFile(name);
if (!fin) {
g_logger.error(stdext::format("failed to open file '%s'", name));
return false;
}
fin->getU32(); // skip version
fin->getU32(); // skip version
uint32 type;
uint8 node = fin->readNode(node, type);
uint32 type;
uint8 node = fin->readNode(node, type);
fin->getU32(); // skip flags...
if (fin->getU8() == 0x01) { // version
fin->getU8(); // skip length.
dwMajorVersion = fin->getU32();
dwMinorVersion = fin->getU32();
dwBuildNumber = fin->getU32();
}
fin->getU32(); // skip flags...
if (fin->getU8() == 0x01) { // version
fin->getU8(); // skip length.
dwMajorVersion = fin->getU32();
dwMinorVersion = fin->getU32();
dwBuildNumber = fin->getU32();
}
uint16 lastId = 99;
ItemDataPtr newItem;
uint16 lastId = 99;
ItemDataPtr newItem;
while ((node = fin->readNode(node, type))) {
if (!(newItem = ItemDataPtr(new ItemData))) {
g_logger.error("failed to read new item from OTB");
return false;
}
while ((node = fin->readNode(node, type))) {
if (!(newItem = ItemDataPtr(new ItemData))) {
g_logger.error("failed to read new item from OTB");
return false;
}
newItem->group = (ItemGroup)type;
fin->getU32(); // skip flags
newItem->group = (ItemGroup)type;
fin->getU32(); // skip flags
ItemAttrib attr;
while ((attr = (ItemAttrib)fin->getU8())) {
uint16 dsize = fin->getU16();
switch (attr) {
case ServerId: {
if (dsize != sizeof(uint16)) {
g_logger.error("Invalid data size");
return false;
}
ItemAttrib attr;
while ((attr = (ItemAttrib)fin->getU8())) {
uint16 dsize = fin->getU16();
switch (attr) {
case ServerId: {
if (dsize != sizeof(uint16)) {
g_logger.error("Invalid data size");
return false;
}
uint16 serverId = fin->getU16();
if (serverId > 20000 && serverId < 20100) {
serverId -= 20000;
} else if (lastId > 99 && lastId != serverId - 1) {
static ItemDataPtr dummyItemType(new ItemData);
while (lastId != serverId - 1) {
dummyItemType->id = ++lastId;
addType(lastId, dummyItemType);
}
}
uint16 serverId = fin->getU16();
if (serverId > 20000 && serverId < 20100) {
serverId -= 20000;
} else if (lastId > 99 && lastId != serverId - 1) {
static ItemDataPtr dummyItemType(new ItemData);
while (lastId != serverId - 1) {
dummyItemType->id = ++lastId;
addType(lastId, dummyItemType);
}
}
newItem->id = serverId;
lastId = serverId;
break;
} case ClientId: {
newItem->clientId = fin->getU16();
break;
} case Speed: {
fin->getU16(); // skip speed
break;
} case Light2: {
if (!fin->seek(dsize)) {
g_logger.error(stdext::format("fail to skip light block with size %d", dsize));
return false;
}
} default: {
if (!fin->seek(dsize)) {
g_logger.error(stdext::format("fail to skip unknown data with size %d", dsize));
return false;
}
}
}
}
newItem->id = serverId;
lastId = serverId;
break;
} case ClientId: {
newItem->clientId = fin->getU16();
break;
} case Speed: {
fin->getU16(); // skip speed
break;
} case Light2: {
if (!fin->seek(dsize)) {
g_logger.error(stdext::format("fail to skip light block with size %d", dsize));
return false;
}
} default: {
if (!fin->seek(dsize)) {
g_logger.error(stdext::format("fail to skip unknown data with size %d", dsize));
return false;
}
}
}
}
addType(newItem->id, newItem);
}
addType(newItem->id, newItem);
}
return true;
return true;
}
bool ItemLoader::loadXML(const std::string &name)
{
TiXmlDocument doc(name.c_str());
if (!doc.LoadFile()) {
g_logger.error(stdext::format("failed to load xml '%s'", name));
return false;
}
TiXmlDocument doc(name.c_str());
if (!doc.LoadFile()) {
g_logger.error(stdext::format("failed to load xml '%s'", name));
return false;
}
TiXmlElement* root = doc.FirstChildElement();
if (!root) {
g_logger.error("invalid xml root");
return false;
}
TiXmlElement* root = doc.FirstChildElement();
if (!root) {
g_logger.error("invalid xml root");
return false;
}
if (root->ValueTStr() != "items") {
g_logger.error("invalid xml tag name, should be 'items'");
return false;
}
if (root->ValueTStr() != "items") {
g_logger.error("invalid xml tag name, should be 'items'");
return false;
}
for (TiXmlElement *element = root->FirstChildElement(); element; element = element->NextSiblingElement()) {
if (element->ValueTStr() != "item")
continue;
for (TiXmlElement *element = root->FirstChildElement(); element; element = element->NextSiblingElement()) {
if (element->ValueTStr() != "item")
continue;
std::string name = element->Attribute("id");
if (name.empty())
continue;
std::string name = element->Attribute("id");
if (name.empty())
continue;
uint16 id = stdext::unsafe_cast<uint16>(element->Attribute("id"));
uint16 idEx = 0;
if (!id) {
bool found = false;
// fallback into reading fromid and toid
uint16 fromid = stdext::unsafe_cast<uint16>(element->Attribute("fromid"));
uint16 toid = stdext::unsafe_cast<uint16>(element->Attribute("toid"));
ItemDataPtr iType;
for (int __id = fromid; __id < toid; ++__id) {
if (!(iType = getType(__id)))
continue;
uint16 id = stdext::unsafe_cast<uint16>(element->Attribute("id"));
uint16 idEx = 0;
if (!id) {
bool found = false;
// fallback into reading fromid and toid
uint16 fromid = stdext::unsafe_cast<uint16>(element->Attribute("fromid"));
uint16 toid = stdext::unsafe_cast<uint16>(element->Attribute("toid"));
ItemDataPtr iType;
for (int __id = fromid; __id < toid; ++__id) {
if (!(iType = getType(__id)))
continue;
iType->name = name;
idEx = iType->id == fromid ? fromid : toid;
found = true;
}
iType->name = name;
idEx = iType->id == fromid ? fromid : toid;
found = true;
}
if (!found)
continue;
}
if (!found)
continue;
}
ItemDataPtr iType = getType(id);
if (!iType) {
iType = ItemDataPtr(new ItemData);
iType->id = idEx ? idEx : id;
iType->name = name;
addType(iType->id, iType);
}
ItemDataPtr iType = getType(id);
if (!iType) {
iType = ItemDataPtr(new ItemData);
iType->id = idEx ? idEx : id;
iType->name = name;
addType(iType->id, iType);
}
iType->name = name;
iType->name = name;
for (TiXmlElement *attr = element->FirstChildElement(); attr; attr = attr->NextSiblingElement()) {
if (attr->ValueTStr() != "attribute")
continue;
for (TiXmlElement *attr = element->FirstChildElement(); attr; attr = attr->NextSiblingElement()) {
if (attr->ValueTStr() != "attribute")
continue;
std::string key = attr->Attribute("key");
std::string value = attr->Attribute("value");
if (key == "type") {
if (value == "magicfield")
iType->group = IsMagicField;
else if (value == "key")
iType->group = IsKey;
else if (value == "depot")
iType->isDepot = true;
else if (value == "teleport")
iType->group = IsTeleport;
else if (value == "bed")
iType->isBed = true;
else if (value == "door")
iType->group = IsDoor;
} else if (key == "name") {
iType->name = value;
} else if (key == "description") {
iType->description = value;
} else if (key == "weight") {
iType->weight = stdext::unsafe_cast<double>(stdext::unsafe_cast<double>(value) / 100.f);
} else if (key == "containerSize") {
int containerSize = stdext::unsafe_cast<int>(value);
if (containerSize)
iType->containerSize = containerSize;
iType->group = IsContainer;
} else if (key == "writeable") {
if (!value.empty())
iType->group = IsWritable;
} else if (key == "maxTextLen") {
iType->maxTextLength = stdext::unsafe_cast<int>(value);
} else if (key == "charges") {
iType->charges = stdext::unsafe_cast<int>(value);
}
}
}
std::string key = attr->Attribute("key");
std::string value = attr->Attribute("value");
if (key == "type") {
if (value == "magicfield")
iType->group = IsMagicField;
else if (value == "key")
iType->group = IsKey;
else if (value == "depot")
iType->isDepot = true;
else if (value == "teleport")
iType->group = IsTeleport;
else if (value == "bed")
iType->isBed = true;
else if (value == "door")
iType->group = IsDoor;
} else if (key == "name") {
iType->name = value;
} else if (key == "description") {
iType->description = value;
} else if (key == "weight") {
iType->weight = stdext::unsafe_cast<double>(stdext::unsafe_cast<double>(value) / 100.f);
} else if (key == "containerSize") {
int containerSize = stdext::unsafe_cast<int>(value);
if (containerSize)
iType->containerSize = containerSize;
iType->group = IsContainer;
} else if (key == "writeable") {
if (!value.empty())
iType->group = IsWritable;
} else if (key == "maxTextLen") {
iType->maxTextLength = stdext::unsafe_cast<int>(value);
} else if (key == "charges") {
iType->charges = stdext::unsafe_cast<int>(value);
}
}
}
doc.Clear();
return true;
doc.Clear();
return true;
}

View File

@ -26,92 +26,92 @@
#include "declarations.h"
enum ItemGroup {
IsGround,
IsContainer,
IsWeapon,
IsAmmunition,
IsArmor,
IsCharges,
IsTeleport,
IsMagicField,
IsWritable,
IsKey,
IsSplash,
IsFluid,
IsDoor,
InvalidGroup
IsGround,
IsContainer,
IsWeapon,
IsAmmunition,
IsArmor,
IsCharges,
IsTeleport,
IsMagicField,
IsWritable,
IsKey,
IsSplash,
IsFluid,
IsDoor,
InvalidGroup
};
enum ItemAttrib {
First = 0x10,
ServerId = First,
ClientId,
Name, /* deprecated */
Desc, /*deprecated*/
Speed,
Slot, /*deprecated*/
MaxItems, /*deprecated*/
Weight, /*deprecated*/
Weapon, /*deprecated*/
Amu, /*deprecated*/
Armor, /*deprecated*/
MagLevel, /*deprecated*/
MagicField, /*deprecated*/
Writable, /*deprecated*/
RotateTo, /*deprecated*/
Decay, /*deprecated*/
SpriteHash,
MinimapColor,
Attr07,
Attr08,
Light,
First = 0x10,
ServerId = First,
ClientId,
Name, /* deprecated */
Desc, /*deprecated*/
Speed,
Slot, /*deprecated*/
MaxItems, /*deprecated*/
Weight, /*deprecated*/
Weapon, /*deprecated*/
Amu, /*deprecated*/
Armor, /*deprecated*/
MagLevel, /*deprecated*/
MagicField, /*deprecated*/
Writable, /*deprecated*/
RotateTo, /*deprecated*/
Decay, /*deprecated*/
SpriteHash,
MinimapColor,
Attr07,
Attr08,
Light,
// 1-byte aligned
Decay2, /*deprecated*/
Weapon2, /*deprecated*/
Amu2, /*deprecated*/
Armor2, /*deprecated*/
Writable2, /*deprecated*/
Light2,
TopOrder,
Wrtiable3 /*deprecated*/
// 1-byte aligned
Decay2, /*deprecated*/
Weapon2, /*deprecated*/
Amu2, /*deprecated*/
Armor2, /*deprecated*/
Writable2, /*deprecated*/
Light2,
TopOrder,
Wrtiable3 /*deprecated*/
};
struct ItemData {
uint16 id;
uint16 clientId;
std::string name, description;
int containerSize;
ItemGroup group;
double weight;
uint16 id;
uint16 clientId;
std::string name, description;
int containerSize;
ItemGroup group;
double weight;
// xml stuff.
bool isDepot;
bool isBed;
uint32 maxTextLength;
uint32 charges;
// xml stuff.
bool isDepot;
bool isBed;
uint32 maxTextLength;
uint32 charges;
};
class ItemLoader
{
public:
uint32 dwMajorVersion;
uint32 dwMinorVersion;
uint32 dwBuildNumber;
uint32 dwMajorVersion;
uint32 dwMinorVersion;
uint32 dwBuildNumber;
ItemLoader() : m_otbLoaded(false), m_xmlLoaded(false) { }
~ItemLoader();
ItemLoader() : m_otbLoaded(false), m_xmlLoaded(false) { }
~ItemLoader();
bool loadOtb(const std::string &name);
bool loadXML(const std::string &name);
bool loadOtb(const std::string &name);
bool loadXML(const std::string &name);
bool isLoaded() { return m_otbLoaded && m_xmlLoaded; }
ItemDataPtr getType(uint16 id) const;
void addType(uint16 id, ItemDataPtr type);
bool isLoaded() { return m_otbLoaded && m_xmlLoaded; }
ItemDataPtr getType(uint16 id) const;
void addType(uint16 id, ItemDataPtr type);
private:
ItemDataList m_items;
bool m_otbLoaded, m_xmlLoaded;
ItemDataList m_items;
bool m_otbLoaded, m_xmlLoaded;
};
extern ItemLoader g_itemLoader;

View File

@ -54,227 +54,258 @@ void Map::notificateTileUpdateToMapViews(const Position& pos)
mapView->onTileUpdate(pos);
}
bool Map::load(const std::string& fileName)
bool Map::loadOTBM(const std::string& fileName)
{
FileStreamPtr fin = g_resources.openFile(fileName);
if (!fin) {
g_logger.error(stdext::format("Unable to load map '%s'", fileName));
return false;
}
FileStreamPtr fin = g_resources.openFile(fileName);
if (!fin) {
g_logger.error(stdext::format("Unable to load map '%s'", fileName));
return false;
}
if (!g_itemLoader.isLoaded()) {
g_logger.error(stdext::format("OTB and XML are not loaded yet to load a map."));
return false;
}
if (!g_itemLoader.isLoaded()) {
g_logger.error(stdext::format("OTB and XML are not loaded yet to load a map."));
return false;
}
uint32 type = 0;
uint8 root = fin->readNode(root, type);
uint32 type = 0;
uint8 root = fin->readNode(root, type);
uint32 headerVersion = fin->getU32();
if (!headerVersion || headerVersion > 3) {
g_logger.error("Unknown OTBM version detected.");
return false;
}
uint32 headerVersion = fin->getU32();
if (!headerVersion || headerVersion > 3) {
g_logger.error("Unknown OTBM version detected.");
return false;
}
uint32 headerMajorItems = fin->getU32();
if (headerMajorItems < 3) {
g_logger.error("This map needs to be upgraded.");
return false;
}
uint32 headerMajorItems = fin->getU32();
if (headerMajorItems < 3) {
g_logger.error("This map needs to be upgraded.");
return false;
}
if (headerMajorItems > g_itemLoader.dwMajorVersion) {
g_logger.error("This map was saved with different OTB version.");
return false;
}
if (headerMajorItems > g_itemLoader.dwMajorVersion) {
g_logger.error("This map was saved with different OTB version.");
return false;
}
uint32_t headerMinorItems = fin->getU32();
if (headerMinorItems > g_itemLoader.dwMinorVersion)
g_logger.warning("This map needs an updated OTB.");
uint32_t headerMinorItems = fin->getU32();
if (headerMinorItems > g_itemLoader.dwMinorVersion)
g_logger.warning("This map needs an updated OTB.");
uint8 node = fin->readNode(root, type);
if (type != OTBM_MAP_DATA) {
g_logger.error("Could not read data node.");
return false;
}
uint8 node = fin->readNode(root, type);
if (type != OTBM_MAP_DATA) {
g_logger.error("Could not read data node.");
return false;
}
std::string tmp;
uint8 attribute;
while ((attribute = fin->getU8())) {
tmp = fin->getString();
switch (attribute) {
case OTBM_ATTR_DESCRIPTION:
if (!m_description.empty())
m_description += "\n" + tmp;
else
m_description = tmp;
break;
case OTBM_ATTR_SPAWN_FILE:
m_spawnFile = fileName.substr(0, fileName.rfind('/') + 1) + tmp;
break;
case OTBM_ATTR_HOUSE_FILE:
m_houseFile = fileName.substr(0, fileName.rfind('/') + 1) + tmp;
break;
default:
g_logger.error(stdext::format("Invalid attribute '%c'", attribute));
break;
}
}
std::string tmp;
uint8 attribute;
while ((attribute = fin->getU8())) {
tmp = fin->getString();
switch (attribute) {
case OTBM_ATTR_DESCRIPTION:
if (!m_description.empty())
m_description += "\n" + tmp;
else
m_description = tmp;
break;
case OTBM_ATTR_SPAWN_FILE:
m_spawnFile = fileName.substr(0, fileName.rfind('/') + 1) + tmp;
break;
case OTBM_ATTR_HOUSE_FILE:
m_houseFile = fileName.substr(0, fileName.rfind('/') + 1) + tmp;
break;
default:
g_logger.error(stdext::format("Invalid attribute '%c'", attribute));
break;
}
}
dump << m_description;
dump << m_description;
uint8 nodeMapData;
do {
nodeMapData = fin->readNode(node, type);
uint8 nodeMapData;
do {
nodeMapData = fin->readNode(node, type);
if (type == OTBM_TILE_AREA) {
uint16 baseX = fin->getU16(), baseY = fin->getU16();
uint8 pz = fin->getU8();
if (type == OTBM_TILE_AREA) {
uint16 baseX = fin->getU16(), baseY = fin->getU16();
uint8 pz = fin->getU8();
uint8 nodeTile;
do {
nodeTile = fin->readNode(nodeMapData, type);
uint8 nodeTile;
do {
nodeTile = fin->readNode(nodeMapData, type);
if (type == OTBM_TILE || type == OTBM_HOUSETILE) {
TilePtr tile = 0;
ItemPtr ground = 0;
uint32 flags = 0;
if (type == OTBM_TILE || type == OTBM_HOUSETILE) {
TilePtr tile = 0;
ItemPtr ground = 0;
uint32 flags = 0;
uint16 px = baseX + fin->getU16(), py = fin->getU16();
Position pos(px, py, pz);
uint16 px = baseX + fin->getU16(), py = fin->getU16();
Position pos(px, py, pz);
// TODO: Houses.
if (type == OTBM_HOUSETILE) {
uint32 hId = fin->getU32();
// TODO: Houses.
if (type == OTBM_HOUSETILE) {
uint32 hId = fin->getU32();
tile = createTile(pos);
// TODO: add it to house.
}
tile = createTile(pos);
// TODO: add it to house.
}
uint8 tileAttr;
while ((tileAttr = fin->getU8())) {
switch (tileAttr) {
case OTBM_ATTR_TILE_FLAGS: {
uint32 _flags = fin->getU32();
uint8 tileAttr;
while ((tileAttr = fin->getU8())) {
switch (tileAttr) {
case OTBM_ATTR_TILE_FLAGS: {
uint32 _flags = fin->getU32();
if ((_flags & TILESTATE_PROTECTIONZONE) == TILESTATE_PROTECTIONZONE)
flags |= TILESTATE_PROTECTIONZONE;
else if ((_flags & TILESTATE_OPTIONALZONE) == TILESTATE_OPTIONALZONE)
flags |= TILESTATE_OPTIONALZONE;
else if ((_flags & TILESTATE_HPPARDCOREZONE) == TILESTATE_HPPARDCOREZONE)
flags |= TILESTATE_HPPARDCOREZONE;
if ((_flags & TILESTATE_PROTECTIONZONE) == TILESTATE_PROTECTIONZONE)
flags |= TILESTATE_PROTECTIONZONE;
else if ((_flags & TILESTATE_OPTIONALZONE) == TILESTATE_OPTIONALZONE)
flags |= TILESTATE_OPTIONALZONE;
else if ((_flags & TILESTATE_HPPARDCOREZONE) == TILESTATE_HPPARDCOREZONE)
flags |= TILESTATE_HPPARDCOREZONE;
if ((_flags & TILESTATE_NOLOGOUT) == TILESTATE_NOLOGOUT)
flags |= TILESTATE_NOLOGOUT;
if ((_flags & TILESTATE_NOLOGOUT) == TILESTATE_NOLOGOUT)
flags |= TILESTATE_NOLOGOUT;
if ((_flags & TILESTATE_REFRESH) == TILESTATE_REFRESH)
flags |= TILESTATE_REFRESH;
break;
} case OTBM_ATTR_ITEM: {
ItemPtr item = Item::create(fin->getU16());
if (!item) {
g_logger.error(stdext::format("failed to create new item at tile pos %d, %d, %d", px, py, pz));
return false;
}
if ((_flags & TILESTATE_REFRESH) == TILESTATE_REFRESH)
flags |= TILESTATE_REFRESH;
break;
} case OTBM_ATTR_ITEM: {
ItemPtr item = Item::create(fin->getU16());
if (!item) {
g_logger.error(stdext::format("failed to create new item at tile pos %d, %d, %d", px, py, pz));
return false;
}
if (tile) {
tile->addThing(item);
} else if (item->isGround()) {
ground = item;
} else {
tile = createTile(pos);
tile->addThing(ground);
tile->addThing(item);
}
} default: {
g_logger.error(stdext::format("invalid tile attribute at pos %d, %d, %d", px, py, pz));
return false;
}
}
}
if (tile) {
tile->addThing(item);
} else if (item->isGround()) {
ground = item;
} else {
tile = createTile(pos);
tile->addThing(ground);
tile->addThing(item);
}
} default: {
g_logger.error(stdext::format("invalid tile attribute at pos %d, %d, %d", px, py, pz));
return false;
}
}
}
uint8 nodeItem;
do {
nodeItem = fin->readNode(nodeTile, type);
uint8 nodeItem;
do {
nodeItem = fin->readNode(nodeTile, type);
if (type == OTBM_ITEM) {
ItemPtr item = Item::create(fin->getU16());
if (!item) {
g_logger.error(stdext::format("failed to create new item at pos %d, %d, %d", px, py, pz));
return false;
}
if (type == OTBM_ITEM) {
ItemPtr item = Item::create(fin->getU16());
if (!item) {
g_logger.error(stdext::format("failed to create new item at pos %d, %d, %d", px, py, pz));
return false;
}
if (item->unserializeItemNode(fin, nodeItem)) {
if (/* house && */item->isMovable()) {
g_logger.warning(stdext::format("Movable item found in house: %d at pos %d %d %d", item->getId(),
px, py, pz));
item = 0;
} else if (tile) {
tile->addThing(item);
} else if (item->isGround()) {
ground = item;
} else {
tile = createTile(pos);
tile->addThing(ground);
tile->addThing(item);
}
} else {
g_logger.error(stdext::format("failed to unserialize item with %d at pos %d %d %d", item->getId(),
px, py, pz));
return false;
}
} else {
g_logger.error(stdext::format("Unknown item node type %d", type));
return false;
}
} while (nodeItem);
if (item->unserializeItemNode(fin, nodeItem)) {
if (/* house && */item->isMovable()) {
g_logger.warning(stdext::format("Movable item found in house: %d at pos %d %d %d", item->getId(),
px, py, pz));
item = 0;
} else if (tile) {
tile->addThing(item);
} else if (item->isGround()) {
ground = item;
} else {
tile = createTile(pos);
tile->addThing(ground);
tile->addThing(item);
}
} else {
g_logger.error(stdext::format("failed to unserialize item with %d at pos %d %d %d", item->getId(),
px, py, pz));
return false;
}
} else {
g_logger.error(stdext::format("Unknown item node type %d", type));
return false;
}
} while (nodeItem);
if (!tile) {
tile = createTile(pos);
tile->addThing(ground);
}
if (!tile) {
tile = createTile(pos);
tile->addThing(ground);
}
tile->setFlags((tileflags_t)flags);
} else {
g_logger.error(stdext::format("Unknown tile node type %d", type));
return false;
}
} while (nodeTile);
} else if (type == OTBM_TOWNS) {
uint8 nodeTown;
do {
nodeTown = fin->readNode(nodeMapData, type);
tile->setFlags((tileflags_t)flags);
} else {
g_logger.error(stdext::format("Unknown tile node type %d", type));
return false;
}
} while (nodeTile);
} else if (type == OTBM_TOWNS) {
uint8 nodeTown;
do {
nodeTown = fin->readNode(nodeMapData, type);
if (type == OTBM_TOWN) {
uint32 townId = fin->getU32();
std::string townName = fin->getString();
if (type == OTBM_TOWN) {
uint32 townId = fin->getU32();
std::string townName = fin->getString();
Position townCoords(fin->getU16(), fin->getU16(), fin->getU8());
} else {
g_logger.error(stdext::format("Unknown town node type %d", type));
return false;
}
} while (nodeTown);
} else if (type == OTBM_WAYPOINTS && headerVersion > 1) {
uint8 nodeWaypoint;
do {
nodeWaypoint = fin->readNode(nodeMapData, type);
Position townCoords(fin->getU16(), fin->getU16(), fin->getU8());
} else {
g_logger.error(stdext::format("Unknown town node type %d", type));
return false;
}
} while (nodeTown);
} else if (type == OTBM_WAYPOINTS && headerVersion > 1) {
uint8 nodeWaypoint;
do {
nodeWaypoint = fin->readNode(nodeMapData, type);
if (type == OTBM_WAYPOINT) {
std::string name = fin->getString();
Position waypointPos(fin->getU16(), fin->getU16(), fin->getU8());
}
} while (nodeWaypoint);
} else {
g_logger.error(stdext::format("Unknown map node %d", type));
return false;
}
} while (nodeMapData);
if (type == OTBM_WAYPOINT) {
std::string name = fin->getString();
Position waypointPos(fin->getU16(), fin->getU16(), fin->getU8());
}
} while (nodeWaypoint);
} else {
g_logger.error(stdext::format("Unknown map node %d", type));
return false;
}
} while (nodeMapData);
// TODO: Load house & spawns.
// TODO: Load house & spawns.
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;

View File

@ -29,50 +29,50 @@
enum OTBM_AttrTypes_t
{
OTBM_ATTR_DESCRIPTION = 1,
OTBM_ATTR_EXT_FILE = 2,
OTBM_ATTR_TILE_FLAGS = 3,
OTBM_ATTR_ACTION_ID = 4,
OTBM_ATTR_UNIQUE_ID = 5,
OTBM_ATTR_TEXT = 6,
OTBM_ATTR_DESC = 7,
OTBM_ATTR_TELE_DEST = 8,
OTBM_ATTR_ITEM = 9,
OTBM_ATTR_DEPOT_ID = 10,
OTBM_ATTR_SPAWN_FILE = 11,
OTBM_ATTR_RUNE_CHARGES = 12,
OTBM_ATTR_HOUSE_FILE = 13,
OTBM_ATTR_HPPOUSEDOORID = 14,
OTBM_ATTR_COUNT = 15,
OTBM_ATTR_DURATION = 16,
OTBM_ATTR_DECAYING_STATE = 17,
OTBM_ATTR_WRITTENDATE = 18,
OTBM_ATTR_WRITTENBY = 19,
OTBM_ATTR_SLEEPERGUID = 20,
OTBM_ATTR_SLEEPSTART = 21,
OTBM_ATTR_CHARGES = 22,
OTBM_ATTR_CONTAINER_ITEMS = 23,
OTBM_ATTR_ATTRIBUTE_MAP = 128
OTBM_ATTR_DESCRIPTION = 1,
OTBM_ATTR_EXT_FILE = 2,
OTBM_ATTR_TILE_FLAGS = 3,
OTBM_ATTR_ACTION_ID = 4,
OTBM_ATTR_UNIQUE_ID = 5,
OTBM_ATTR_TEXT = 6,
OTBM_ATTR_DESC = 7,
OTBM_ATTR_TELE_DEST = 8,
OTBM_ATTR_ITEM = 9,
OTBM_ATTR_DEPOT_ID = 10,
OTBM_ATTR_SPAWN_FILE = 11,
OTBM_ATTR_RUNE_CHARGES = 12,
OTBM_ATTR_HOUSE_FILE = 13,
OTBM_ATTR_HPPOUSEDOORID = 14,
OTBM_ATTR_COUNT = 15,
OTBM_ATTR_DURATION = 16,
OTBM_ATTR_DECAYING_STATE = 17,
OTBM_ATTR_WRITTENDATE = 18,
OTBM_ATTR_WRITTENBY = 19,
OTBM_ATTR_SLEEPERGUID = 20,
OTBM_ATTR_SLEEPSTART = 21,
OTBM_ATTR_CHARGES = 22,
OTBM_ATTR_CONTAINER_ITEMS = 23,
OTBM_ATTR_ATTRIBUTE_MAP = 128
};
enum OTBM_NodeTypes_t
{
OTBM_ROOTV2 = 1,
OTBM_MAP_DATA = 2,
OTBM_ITEM_DEF = 3,
OTBM_TILE_AREA = 4,
OTBM_TILE = 5,
OTBM_ITEM = 6,
OTBM_TILE_SQUARE = 7,
OTBM_TILE_REF = 8,
OTBM_SPAWNS = 9,
OTBM_SPAWN_AREA = 10,
OTBM_MONSTER = 11,
OTBM_TOWNS = 12,
OTBM_TOWN = 13,
OTBM_HOUSETILE = 14,
OTBM_WAYPOINTS = 15,
OTBM_WAYPOINT = 16
OTBM_ROOTV2 = 1,
OTBM_MAP_DATA = 2,
OTBM_ITEM_DEF = 3,
OTBM_TILE_AREA = 4,
OTBM_TILE = 5,
OTBM_ITEM = 6,
OTBM_TILE_SQUARE = 7,
OTBM_TILE_REF = 8,
OTBM_SPAWNS = 9,
OTBM_SPAWN_AREA = 10,
OTBM_MONSTER = 11,
OTBM_TOWNS = 12,
OTBM_TOWN = 13,
OTBM_HOUSETILE = 14,
OTBM_WAYPOINTS = 15,
OTBM_WAYPOINT = 16
};
class Map
@ -82,8 +82,12 @@ public:
void removeMapView(const MapViewPtr& mapView);
void notificateTileUpdateToMapViews(const Position& pos);
bool load(const std::string& fileName);
void save(const std::string& fileName);
bool loadOTCM(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 cleanDynamicThings();
void cleanTexts();
@ -138,7 +142,7 @@ private:
Light m_light;
Position m_centralPosition;
std::string m_description, m_spawnFile, m_houseFile;
std::string m_description, m_spawnFile, m_houseFile;
};
extern Map g_map;

View File

@ -28,22 +28,22 @@
enum tileflags_t
{
TILESTATE_NONE = 0,
TILESTATE_PROTECTIONZONE = 1 << 0,
TILESTATE_TRASHED = 1 << 1,
TILESTATE_OPTIONALZONE = 1 << 2,
TILESTATE_NOLOGOUT = 1 << 3,
TILESTATE_HPPARDCOREZONE = 1 << 4,
TILESTATE_REFRESH = 1 << 5,
TILESTATE_NONE = 0,
TILESTATE_PROTECTIONZONE = 1 << 0,
TILESTATE_TRASHED = 1 << 1,
TILESTATE_OPTIONALZONE = 1 << 2,
TILESTATE_NOLOGOUT = 1 << 3,
TILESTATE_HPPARDCOREZONE = 1 << 4,
TILESTATE_REFRESH = 1 << 5,
// internal usage
TILESTATE_HOUSE = 1 << 6,
TILESTATE_TELEPORT = 1 << 17,
TILESTATE_MAGICFIELD = 1 << 18,
TILESTATE_MAILBOX = 1 << 19,
TILESTATE_TRASHHOLDER = 1 << 20,
TILESTATE_BED = 1 << 21,
TILESTATE_DEPOT = 1 << 22
// internal usage
TILESTATE_HOUSE = 1 << 6,
TILESTATE_TELEPORT = 1 << 17,
TILESTATE_MAGICFIELD = 1 << 18,
TILESTATE_MAILBOX = 1 << 19,
TILESTATE_TRASHHOLDER = 1 << 20,
TILESTATE_BED = 1 << 21,
TILESTATE_DEPOT = 1 << 22
};
class Tile : public LuaObject
@ -98,7 +98,7 @@ public:
bool canErase();
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:
std::vector<CreaturePtr> m_walkingCreatures;
@ -106,7 +106,7 @@ private:
std::vector<ThingPtr> m_things;
Position m_position;
uint8 m_drawElevation;
uint32 m_flags;
uint32 m_flags;
};
#endif

View File

@ -76,8 +76,10 @@ void OTClient::registerLuaFunctions()
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", "findPath", &Map::findPath, &g_map);
g_lua.bindSingletonFunction("g_map", "load", &Map::load, &g_map);
g_lua.bindSingletonFunction("g_map", "save", &Map::save, &g_map);
g_lua.bindSingletonFunction("g_map", "loadOTBM", &Map::loadOTBM, &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.bindSingletonFunction("g_game", "loginWorld", &Game::loginWorld, &g_game);