Update item OTBM attributes reader
* Fix some lua errors generated by playMusic * Fix possible crash when starting otcliet without dat loaded
This commit is contained in:
parent
7cd49712f8
commit
b0e6b3b8fb
|
@ -107,8 +107,10 @@ void SoundManager::poll()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SoundManager::preload(const std::string& filename)
|
void SoundManager::preload(std::string filename)
|
||||||
{
|
{
|
||||||
|
filename = g_resources.resolvePath(filename);
|
||||||
|
|
||||||
auto it = m_buffers.find(filename);
|
auto it = m_buffers.find(filename);
|
||||||
if(it != m_buffers.end())
|
if(it != m_buffers.end())
|
||||||
return;
|
return;
|
||||||
|
@ -130,11 +132,13 @@ void SoundManager::enableSound(bool enable)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SoundManager::play(const std::string& filename)
|
void SoundManager::play(std::string filename)
|
||||||
{
|
{
|
||||||
if(!m_soundEnabled)
|
if(!m_soundEnabled || filename.empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
filename = g_resources.resolvePath(filename);
|
||||||
|
|
||||||
SoundSourcePtr soundSource = createSoundSource(filename);
|
SoundSourcePtr soundSource = createSoundSource(filename);
|
||||||
if(!soundSource) {
|
if(!soundSource) {
|
||||||
g_logger.error(stdext::format("unable to play '%s'", filename));
|
g_logger.error(stdext::format("unable to play '%s'", filename));
|
||||||
|
@ -154,17 +158,21 @@ void SoundManager::enableMusic(bool enable)
|
||||||
|
|
||||||
m_musicEnabled = enable;
|
m_musicEnabled = enable;
|
||||||
|
|
||||||
if(enable)
|
if(enable && !m_currentMusic.empty())
|
||||||
playMusic(m_currentMusic, 3.0f);
|
playMusic(m_currentMusic, 3.0f);
|
||||||
else
|
else
|
||||||
m_musicSource = nullptr;
|
m_musicSource = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SoundManager::playMusic(const std::string& filename, float fadetime)
|
void SoundManager::playMusic(std::string filename, float fadetime)
|
||||||
{
|
{
|
||||||
|
if(filename.empty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
filename = g_resources.resolvePath(filename);
|
||||||
|
|
||||||
if(m_currentMusic == filename && m_musicSource)
|
if(m_currentMusic == filename && m_musicSource)
|
||||||
return;
|
return;
|
||||||
m_currentMusic = g_resources.resolvePath(filename);
|
|
||||||
|
|
||||||
if(!m_musicEnabled)
|
if(!m_musicEnabled)
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -38,12 +38,12 @@ public:
|
||||||
void terminate();
|
void terminate();
|
||||||
void poll();
|
void poll();
|
||||||
|
|
||||||
void preload(const std::string& filename);
|
void preload(std::string filename);
|
||||||
void enableSound(bool enable);
|
void enableSound(bool enable);
|
||||||
void play(const std::string& filename);
|
void play(std::string filename);
|
||||||
|
|
||||||
void enableMusic(bool enable);
|
void enableMusic(bool enable);
|
||||||
void playMusic(const std::string& filename, float fadetime);
|
void playMusic(std::string filename, float fadetime);
|
||||||
void stopMusic(float fadetime = 0);
|
void stopMusic(float fadetime = 0);
|
||||||
|
|
||||||
bool isMusicEnabled() { return m_musicEnabled; }
|
bool isMusicEnabled() { return m_musicEnabled; }
|
||||||
|
|
|
@ -199,55 +199,32 @@ bool Item::isValid()
|
||||||
|
|
||||||
void Item::unserializeItem(const BinaryTreePtr &in)
|
void Item::unserializeItem(const BinaryTreePtr &in)
|
||||||
{
|
{
|
||||||
while (in->canRead()) {
|
try {
|
||||||
uint8 attrType = in->getU8();
|
while(in->canRead()) {
|
||||||
if(attrType == 0)
|
int attrib = in->getU8();
|
||||||
|
if(attrib == 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// fugly switch yes?
|
switch(attrib) {
|
||||||
switch ((AttrTypes_t)attrType) {
|
|
||||||
case ATTR_COUNT:
|
case ATTR_COUNT:
|
||||||
setSubType(in->getU8());
|
case ATTR_RUNE_CHARGES:
|
||||||
|
setCount(in->getU8());
|
||||||
break;
|
break;
|
||||||
case ATTR_CHARGES:
|
case ATTR_CHARGES:
|
||||||
setSubType(in->getU16());
|
setCount(in->getU16());
|
||||||
break;
|
|
||||||
case ATTR_ACTION_ID:
|
|
||||||
setActionId(in->getU16());
|
|
||||||
break;
|
|
||||||
case ATTR_UNIQUE_ID:
|
|
||||||
setUniqueId(in->getU16());
|
|
||||||
break;
|
|
||||||
case ATTR_NAME:
|
|
||||||
m_attribs.set(ATTR_NAME, in->getString());
|
|
||||||
break;
|
|
||||||
case ATTR_TEXT:
|
|
||||||
m_attribs.set(ATTR_TEXT, in->getString());
|
|
||||||
break;
|
|
||||||
case ATTR_DESC:
|
|
||||||
m_attribs.set(ATTR_DESC, in->getString());
|
|
||||||
break;
|
|
||||||
case ATTR_CONTAINER_ITEMS:
|
|
||||||
m_attribs.set(ATTR_CONTAINER_ITEMS, in->getU32());
|
|
||||||
break;
|
break;
|
||||||
case ATTR_HOUSEDOORID:
|
case ATTR_HOUSEDOORID:
|
||||||
m_attribs.set(ATTR_HOUSEDOORID, in->getU8());
|
case ATTR_SCRIPTPROTECTED:
|
||||||
|
case ATTR_DUALWIELD:
|
||||||
|
case ATTR_DECAYING_STATE:
|
||||||
|
m_attribs.set(attrib, in->getU8());
|
||||||
break;
|
break;
|
||||||
|
case ATTR_ACTION_ID:
|
||||||
|
case ATTR_UNIQUE_ID:
|
||||||
case ATTR_DEPOT_ID:
|
case ATTR_DEPOT_ID:
|
||||||
m_attribs.set(ATTR_DEPOT_ID, in->getU16());
|
m_attribs.set(attrib, in->getU16());
|
||||||
break;
|
|
||||||
case ATTR_TELE_DEST: {
|
|
||||||
Position teleportDestination;
|
|
||||||
teleportDestination.x = in->getU16();
|
|
||||||
teleportDestination.y = in->getU16();
|
|
||||||
teleportDestination.z = in->getU8();
|
|
||||||
m_attribs.set(ATTR_TELE_DEST, teleportDestination);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case ATTR_ARTICLE:
|
|
||||||
case ATTR_WRITTENBY:
|
|
||||||
in->getString();
|
|
||||||
break;
|
break;
|
||||||
|
case ATTR_CONTAINER_ITEMS:
|
||||||
case ATTR_ATTACK:
|
case ATTR_ATTACK:
|
||||||
case ATTR_EXTRAATTACK:
|
case ATTR_EXTRAATTACK:
|
||||||
case ATTR_DEFENSE:
|
case ATTR_DEFENSE:
|
||||||
|
@ -260,18 +237,30 @@ void Item::unserializeItem(const BinaryTreePtr &in)
|
||||||
case ATTR_SLEEPERGUID:
|
case ATTR_SLEEPERGUID:
|
||||||
case ATTR_SLEEPSTART:
|
case ATTR_SLEEPSTART:
|
||||||
case ATTR_ATTRIBUTE_MAP:
|
case ATTR_ATTRIBUTE_MAP:
|
||||||
in->skip(4);
|
m_attribs.set(attrib, in->getU32());
|
||||||
break;
|
break;
|
||||||
case ATTR_SCRIPTPROTECTED:
|
case ATTR_TELE_DEST: {
|
||||||
case ATTR_DUALWIELD:
|
Position pos;
|
||||||
case ATTR_DECAYING_STATE:
|
pos.x = in->getU16();
|
||||||
case ATTR_RUNE_CHARGES:
|
pos.y = in->getU16();
|
||||||
in->skip(1);
|
pos.z = in->getU8();
|
||||||
|
m_attribs.set(attrib, pos);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case ATTR_NAME:
|
||||||
|
case ATTR_TEXT:
|
||||||
|
case ATTR_DESC:
|
||||||
|
case ATTR_ARTICLE:
|
||||||
|
case ATTR_WRITTENBY:
|
||||||
|
m_attribs.set(attrib, in->getString());
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
stdext::throw_exception(stdext::format("invalid item attribute %d", (int)attrType));
|
stdext::throw_exception(stdext::format("invalid item attribute %d", attrib));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch(stdext::exception& e) {
|
||||||
|
g_logger.error(stdext::format("Failed to unserialize OTBM item: %s", e.what()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Item::isMoveable()
|
bool Item::isMoveable()
|
||||||
|
|
|
@ -31,6 +31,8 @@
|
||||||
enum AttrTypes_t
|
enum AttrTypes_t
|
||||||
{
|
{
|
||||||
ATTR_END = 0,
|
ATTR_END = 0,
|
||||||
|
//ATTR_DESCRIPTION = 1,
|
||||||
|
//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,
|
||||||
|
@ -39,7 +41,9 @@ enum AttrTypes_t
|
||||||
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_RUNE_CHARGES = 12,
|
ATTR_RUNE_CHARGES = 12,
|
||||||
|
//ATTR_EXT_HOUSE_FILE = 13,
|
||||||
ATTR_HOUSEDOORID = 14,
|
ATTR_HOUSEDOORID = 14,
|
||||||
ATTR_COUNT = 15,
|
ATTR_COUNT = 15,
|
||||||
ATTR_DURATION = 16,
|
ATTR_DURATION = 16,
|
||||||
|
|
|
@ -43,6 +43,9 @@ void ThingTypeManager::init()
|
||||||
m_datLoaded = false;
|
m_datLoaded = false;
|
||||||
m_xmlLoaded = false;
|
m_xmlLoaded = false;
|
||||||
m_otbLoaded = false;
|
m_otbLoaded = false;
|
||||||
|
for(int i = 0; i < DatLastCategory; ++i)
|
||||||
|
m_datTypes[i].resize(1, m_nullDatType);
|
||||||
|
m_otbTypes.resize(1, m_nullOtbType);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ThingTypeManager::terminate()
|
void ThingTypeManager::terminate()
|
||||||
|
|
Loading…
Reference in New Issue