Rename ThingType classes

This commit is contained in:
Eduardo Bart 2012-07-19 18:22:52 -03:00
parent 09b4705a33
commit a6d53532d2
19 changed files with 166 additions and 165 deletions

View File

@ -567,6 +567,7 @@ void Application::registerLuaFunctions()
g_lua.bindClassMemberFunction<UIGridLayout>("setCellWidth", &UIGridLayout::setCellWidth);
g_lua.bindClassMemberFunction<UIGridLayout>("setCellHeight", &UIGridLayout::setCellHeight);
g_lua.bindClassMemberFunction<UIGridLayout>("setCellSpacing", &UIGridLayout::setCellSpacing);
g_lua.bindClassMemberFunction<UIGridLayout>("setFlow", &UIGridLayout::setFlow);
g_lua.bindClassMemberFunction<UIGridLayout>("setNumColumns", &UIGridLayout::setNumColumns);
g_lua.bindClassMemberFunction<UIGridLayout>("setNumLines", &UIGridLayout::setNumLines);
g_lua.bindClassMemberFunction<UIGridLayout>("asUIGridLayout", &UIGridLayout::asUIGridLayout);

View File

@ -69,10 +69,10 @@ set(otclient_SOURCES ${otclient_SOURCES}
${CMAKE_CURRENT_LIST_DIR}/thing.h
${CMAKE_CURRENT_LIST_DIR}/thingtypemanager.cpp
${CMAKE_CURRENT_LIST_DIR}/thingtypemanager.h
${CMAKE_CURRENT_LIST_DIR}/thingtypedat.cpp
${CMAKE_CURRENT_LIST_DIR}/thingtypedat.h
${CMAKE_CURRENT_LIST_DIR}/thingtypeotb.cpp
${CMAKE_CURRENT_LIST_DIR}/thingtypeotb.h
${CMAKE_CURRENT_LIST_DIR}/thingtype.cpp
${CMAKE_CURRENT_LIST_DIR}/thingtype.h
${CMAKE_CURRENT_LIST_DIR}/itemtype.cpp
${CMAKE_CURRENT_LIST_DIR}/itemtype.h
${CMAKE_CURRENT_LIST_DIR}/tile.cpp
${CMAKE_CURRENT_LIST_DIR}/tile.h
${CMAKE_CURRENT_LIST_DIR}/houses.cpp

View File

@ -113,7 +113,7 @@ void Creature::internalDrawOutfit(const Point& dest, float scaleFactor, bool ani
if(yPattern > 0 && !(m_outfit.getAddons() & (1 << (yPattern-1))))
continue;
auto datType = rawGetDatType();
auto datType = rawGetThingType();
datType->draw(dest, scaleFactor, 0, xPattern, yPattern, 0, animationPhase);
if(getLayers() > 1) {
@ -155,7 +155,7 @@ void Creature::internalDrawOutfit(const Point& dest, float scaleFactor, bool ani
if(m_outfit.getCategory() == DatEffectCategory)
animationPhase = std::min(animationPhase+1, getAnimationPhases());
rawGetDatType()->draw(dest, scaleFactor, 0, 0, 0, 0, animationPhase);
rawGetThingType()->draw(dest, scaleFactor, 0, 0, 0, 0, animationPhase);
}
}
@ -551,12 +551,12 @@ Point Creature::getDrawOffset()
return drawOffset;
}
const ThingTypeDatPtr& Creature::getDatType()
const ThingTypePtr& Creature::getThingType()
{
return g_things.getDatType(m_outfit.getId(), m_outfit.getCategory());
return g_things.getThingType(m_outfit.getId(), m_outfit.getCategory());
}
ThingTypeDat* Creature::rawGetDatType()
ThingType* Creature::rawGetThingType()
{
return g_things.rawGetDatType(m_outfit.getId(), m_outfit.getCategory());
return g_things.rawGetThingType(m_outfit.getId(), m_outfit.getCategory());
}

View File

@ -96,8 +96,8 @@ public:
CreaturePtr asCreature() { return std::static_pointer_cast<Creature>(shared_from_this()); }
bool isCreature() { return true; }
const ThingTypeDatPtr& getDatType();
ThingTypeDat *rawGetDatType();
const ThingTypePtr& getThingType();
ThingType *rawGetThingType();
protected:
virtual void updateWalkAnimation(int totalPixelsWalked);

View File

@ -44,8 +44,8 @@ class Effect;
class Missile;
class AnimatedText;
class StaticText;
class ThingTypeDat;
class ThingTypeOtb;
class ThingType;
class ItemType;
class House;
class Town;
class CreatureType;
@ -64,15 +64,15 @@ typedef std::shared_ptr<Effect> EffectPtr;
typedef std::shared_ptr<Missile> MissilePtr;
typedef std::shared_ptr<AnimatedText> AnimatedTextPtr;
typedef std::shared_ptr<StaticText> StaticTextPtr;
typedef std::shared_ptr<ThingTypeDat> ThingTypeDatPtr;
typedef std::shared_ptr<ThingTypeOtb> ThingTypeOtbPtr;
typedef std::shared_ptr<ThingType> ThingTypePtr;
typedef std::shared_ptr<ItemType> ItemTypePtr;
typedef std::shared_ptr<House> HousePtr;
typedef std::shared_ptr<Town> TownPtr;
typedef std::shared_ptr<CreatureType> CreatureTypePtr;
typedef std::vector<ThingPtr> ThingList;
typedef std::vector<ThingTypeDatPtr> ThingTypeDatList;
typedef std::vector<ThingTypeOtbPtr> ThingTypeOtbList;
typedef std::vector<ThingTypePtr> ThingTypeList;
typedef std::vector<ItemTypePtr> ItemTypeList;
typedef std::vector<HousePtr> HouseList;
typedef std::vector<TownPtr> TownList;
typedef std::unordered_map<Position, TilePtr, PositionHasher> TileMap;

View File

@ -32,7 +32,7 @@ void Effect::draw(const Point& dest, float scaleFactor, bool animate)
int animationPhase = 0;
if(animate)
animationPhase = std::min((int)(m_animationTimer.ticksElapsed() / Otc::EFFECT_TICKS_PER_FRAME), getAnimationPhases() - 1);
rawGetDatType()->draw(dest, scaleFactor, 0, 0, 0, 0, animationPhase);
rawGetThingType()->draw(dest, scaleFactor, 0, 0, 0, 0, animationPhase);
}
void Effect::startAnimation()
@ -51,12 +51,12 @@ void Effect::setId(uint32 id)
m_id = id;
}
const ThingTypeDatPtr& Effect::getDatType()
const ThingTypePtr& Effect::getThingType()
{
return g_things.getDatType(m_id, DatEffectCategory);
return g_things.getThingType(m_id, DatEffectCategory);
}
ThingTypeDat *Effect::rawGetDatType()
ThingType *Effect::rawGetThingType()
{
return g_things.rawGetDatType(m_id, DatEffectCategory);
return g_things.rawGetThingType(m_id, DatEffectCategory);
}

View File

@ -41,8 +41,8 @@ public:
EffectPtr asEffect() { return std::static_pointer_cast<Effect>(shared_from_this()); }
bool isEffect() { return true; }
const ThingTypeDatPtr& getDatType();
ThingTypeDat *rawGetDatType();
const ThingTypePtr& getThingType();
ThingType *rawGetThingType();
private:
Timer m_animationTimer;

View File

@ -171,7 +171,7 @@ void Item::draw(const Point& dest, float scaleFactor, bool animate)
zPattern = m_position.z % getNumPatternZ();
}
rawGetDatType()->draw(dest, scaleFactor, 0, xPattern, yPattern, zPattern, animationPhase);
rawGetThingType()->draw(dest, scaleFactor, 0, xPattern, yPattern, zPattern, animationPhase);
}
void Item::setId(uint32 id)
@ -187,7 +187,7 @@ void Item::setOtbId(uint16 id)
{
if(!g_things.isValidOtbId(id))
id = 0;
auto otbType = g_things.getOtbType(id);
auto otbType = g_things.getItemType(id);
m_id = otbType->getClientId();
m_otbId = id;
}
@ -265,7 +265,7 @@ void Item::unserializeItem(const BinaryTreePtr &in)
bool Item::isMoveable()
{
return !rawGetDatType()->isNotMoveable();
return !rawGetThingType()->isNotMoveable();
}
ItemPtr Item::clone()
@ -275,12 +275,12 @@ ItemPtr Item::clone()
return item;
}
const ThingTypeDatPtr& Item::getDatType()
const ThingTypePtr& Item::getThingType()
{
return g_things.getDatType(m_id, DatItemCategory);
return g_things.getThingType(m_id, DatItemCategory);
}
ThingTypeDat* Item::rawGetDatType()
ThingType* Item::rawGetThingType()
{
return g_things.rawGetDatType(m_id, DatItemCategory);
return g_things.rawGetThingType(m_id, DatItemCategory);
}

View File

@ -26,7 +26,7 @@
#include <framework/global.h>
#include <framework/util/attribstorage.h>
#include "thing.h"
#include "thingtypeotb.h"
#include "itemtype.h"
enum AttrTypes_t
{
@ -117,8 +117,8 @@ public:
ItemPtr asItem() { return std::static_pointer_cast<Item>(shared_from_this()); }
bool isItem() { return true; }
const ThingTypeDatPtr& getDatType();
ThingTypeDat *rawGetDatType();
const ThingTypePtr& getThingType();
ThingType *rawGetThingType();
private:
uint16 m_id;

View File

@ -22,17 +22,17 @@
#include "thingtypemanager.h"
#include "thingtypeotb.h"
#include "thingtype.h"
#include <framework/core/filestream.h>
#include <framework/core/binarytree.h>
ThingTypeOtb::ThingTypeOtb()
ItemType::ItemType()
{
m_category = OtbInvalidCateogry;
}
void ThingTypeOtb::unserialize(const BinaryTreePtr& node)
void ItemType::unserialize(const BinaryTreePtr& node)
{
m_null = false;
@ -53,10 +53,10 @@ void ThingTypeOtb::unserialize(const BinaryTreePtr& node)
if(serverId > 20000 && serverId < 20100) {
serverId -= 20000;
} else if(lastId > 99 && lastId != serverId - 1) {
static ThingTypeOtbPtr dummyType(g_things.getNullOtbType());
static ItemTypePtr dummyType(g_things.getNullItemType());
while(lastId != serverId - 1) {
dummyType->setServerId(++lastId);
g_things.addOtbType(dummyType);
g_things.addItemType(dummyType);
}
}
assert(len == 2);

View File

@ -21,8 +21,8 @@
*/
#ifndef THINGTYPEOTB_H
#define THINGTYPEOTB_H
#ifndef ITEMTYPE_H
#define ITEMTYPE_H
#include <framework/core/declarations.h>
#include <framework/luaengine/luaobject.h>
@ -82,10 +82,10 @@ enum OtbAttrib {
OtbLastAttrib
};
class ThingTypeOtb : public LuaObject
class ItemType : public LuaObject
{
public:
ThingTypeOtb();
ItemType();
void unserialize(const BinaryTreePtr& node);

View File

@ -63,7 +63,7 @@ void Missile::draw(const Point& dest, float scaleFactor, bool animate)
}
float fraction = m_animationTimer.ticksElapsed() / m_duration;
rawGetDatType()->draw(dest + m_delta * fraction * scaleFactor, scaleFactor, 0, xPattern, yPattern, 0, 0);
rawGetThingType()->draw(dest + m_delta * fraction * scaleFactor, scaleFactor, 0, xPattern, yPattern, 0, 0);
}
void Missile::setPath(const Position& fromPosition, const Position& toPosition)
@ -88,12 +88,12 @@ void Missile::setId(uint32 id)
m_id = id;
}
const ThingTypeDatPtr& Missile::getDatType()
const ThingTypePtr& Missile::getThingType()
{
return g_things.getDatType(m_id, DatMissileCategory);
return g_things.getThingType(m_id, DatMissileCategory);
}
ThingTypeDat* Missile::rawGetDatType()
ThingType* Missile::rawGetThingType()
{
return g_things.rawGetDatType(m_id, DatMissileCategory);
return g_things.rawGetThingType(m_id, DatMissileCategory);
}

View File

@ -45,8 +45,8 @@ public:
MissilePtr asMissile() { return std::static_pointer_cast<Missile>(shared_from_this()); }
bool isMissile() { return true; }
const ThingTypeDatPtr& getDatType();
ThingTypeDat *rawGetDatType();
const ThingTypePtr& getThingType();
ThingType *rawGetThingType();
private:
Timer m_animationTimer;

View File

@ -75,12 +75,12 @@ int Thing::getStackpos()
}
}
const ThingTypeDatPtr& Thing::getDatType()
const ThingTypePtr& Thing::getThingType()
{
return g_things.getNullDatType();
return g_things.getNullThingType();
}
ThingTypeDat* Thing::rawGetDatType()
ThingType* Thing::rawGetThingType()
{
return g_things.getNullDatType().get();
return g_things.getNullThingType().get();
}

View File

@ -24,7 +24,7 @@
#define THING_H
#include "declarations.h"
#include "thingtypedat.h"
#include "thingtype.h"
#include "thingtypemanager.h"
#include <framework/luaengine/luaobject.h>
@ -73,63 +73,63 @@ public:
virtual bool isStaticText() { return false; }
// type shortcuts
virtual const ThingTypeDatPtr& getDatType();
virtual ThingTypeDat *rawGetDatType();
Size getSize() { return rawGetDatType()->getSize(); }
int getWidth() { return rawGetDatType()->getWidth(); }
int getHeight() { return rawGetDatType()->getHeight(); }
Point getDisplacement() { return rawGetDatType()->getDisplacement(); }
int getDisplacementX() { return rawGetDatType()->getDisplacementX(); }
int getDisplacementY() { return rawGetDatType()->getDisplacementY(); }
int getExactSize() { return rawGetDatType()->getExactSize(); }
int getLayers() { return rawGetDatType()->getLayers(); }
int getNumPatternX() { return rawGetDatType()->getNumPatternX(); }
int getNumPatternY() { return rawGetDatType()->getNumPatternY(); }
int getNumPatternZ() { return rawGetDatType()->getNumPatternZ(); }
int getAnimationPhases() { return rawGetDatType()->getAnimationPhases(); }
int getGroundSpeed() { return rawGetDatType()->getGroundSpeed(); }
int getMaxTextLength() { return rawGetDatType()->getMaxTextLength(); }
Light getLight() { return rawGetDatType()->getLight(); }
int getMinimapColor() { return rawGetDatType()->getMinimapColor(); }
int getLensHelp() { return rawGetDatType()->getLensHelp(); }
int getClothSlot() { return rawGetDatType()->getClothSlot(); }
int getElevation() { return rawGetDatType()->getElevation(); }
bool isGround() { return rawGetDatType()->isGround(); }
bool isGroundBorder() { return rawGetDatType()->isGroundBorder(); }
bool isOnBottom() { return rawGetDatType()->isOnBottom(); }
bool isOnTop() { return rawGetDatType()->isOnTop(); }
bool isContainer() { return rawGetDatType()->isContainer(); }
bool isStackable() { return rawGetDatType()->isStackable(); }
bool isForceUse() { return rawGetDatType()->isForceUse(); }
bool isMultiUse() { return rawGetDatType()->isMultiUse(); }
bool isWritable() { return rawGetDatType()->isWritable(); }
bool isChargeable() { return rawGetDatType()->isChargeable(); }
bool isWritableOnce() { return rawGetDatType()->isWritableOnce(); }
bool isFluidContainer() { return rawGetDatType()->isFluidContainer(); }
bool isSplash() { return rawGetDatType()->isSplash(); }
bool isNotWalkable() { return rawGetDatType()->isNotWalkable(); }
bool isNotMoveable() { return rawGetDatType()->isNotMoveable(); }
bool blockProjectile() { return rawGetDatType()->blockProjectile(); }
bool isNotPathable() { return rawGetDatType()->isNotPathable(); }
bool isPickupable() { return rawGetDatType()->isPickupable(); }
bool isHangable() { return rawGetDatType()->isHangable(); }
bool isHookSouth() { return rawGetDatType()->isHookSouth(); }
bool isHookEast() { return rawGetDatType()->isHookEast(); }
bool isRotateable() { return rawGetDatType()->isRotateable(); }
bool hasLight() { return rawGetDatType()->hasLight(); }
bool isDontHide() { return rawGetDatType()->isDontHide(); }
bool isTranslucent() { return rawGetDatType()->isTranslucent(); }
bool hasDisplacement() { return rawGetDatType()->hasDisplacement(); }
bool hasElevation() { return rawGetDatType()->hasElevation(); }
bool isLyingCorpse() { return rawGetDatType()->isLyingCorpse(); }
bool isAnimateAlways() { return rawGetDatType()->isAnimateAlways(); }
bool hasMiniMapColor() { return rawGetDatType()->hasMiniMapColor(); }
bool hasLensHelp() { return rawGetDatType()->hasLensHelp(); }
bool isFullGround() { return rawGetDatType()->isFullGround(); }
bool isIgnoreLook() { return rawGetDatType()->isIgnoreLook(); }
bool isCloth() { return rawGetDatType()->isCloth(); }
bool isMarketable() { return rawGetDatType()->isMarketable(); }
MarketData getMarketData() { return rawGetDatType()->getMarketData(); }
virtual const ThingTypePtr& getThingType();
virtual ThingType *rawGetThingType();
Size getSize() { return rawGetThingType()->getSize(); }
int getWidth() { return rawGetThingType()->getWidth(); }
int getHeight() { return rawGetThingType()->getHeight(); }
Point getDisplacement() { return rawGetThingType()->getDisplacement(); }
int getDisplacementX() { return rawGetThingType()->getDisplacementX(); }
int getDisplacementY() { return rawGetThingType()->getDisplacementY(); }
int getExactSize() { return rawGetThingType()->getExactSize(); }
int getLayers() { return rawGetThingType()->getLayers(); }
int getNumPatternX() { return rawGetThingType()->getNumPatternX(); }
int getNumPatternY() { return rawGetThingType()->getNumPatternY(); }
int getNumPatternZ() { return rawGetThingType()->getNumPatternZ(); }
int getAnimationPhases() { return rawGetThingType()->getAnimationPhases(); }
int getGroundSpeed() { return rawGetThingType()->getGroundSpeed(); }
int getMaxTextLength() { return rawGetThingType()->getMaxTextLength(); }
Light getLight() { return rawGetThingType()->getLight(); }
int getMinimapColor() { return rawGetThingType()->getMinimapColor(); }
int getLensHelp() { return rawGetThingType()->getLensHelp(); }
int getClothSlot() { return rawGetThingType()->getClothSlot(); }
int getElevation() { return rawGetThingType()->getElevation(); }
bool isGround() { return rawGetThingType()->isGround(); }
bool isGroundBorder() { return rawGetThingType()->isGroundBorder(); }
bool isOnBottom() { return rawGetThingType()->isOnBottom(); }
bool isOnTop() { return rawGetThingType()->isOnTop(); }
bool isContainer() { return rawGetThingType()->isContainer(); }
bool isStackable() { return rawGetThingType()->isStackable(); }
bool isForceUse() { return rawGetThingType()->isForceUse(); }
bool isMultiUse() { return rawGetThingType()->isMultiUse(); }
bool isWritable() { return rawGetThingType()->isWritable(); }
bool isChargeable() { return rawGetThingType()->isChargeable(); }
bool isWritableOnce() { return rawGetThingType()->isWritableOnce(); }
bool isFluidContainer() { return rawGetThingType()->isFluidContainer(); }
bool isSplash() { return rawGetThingType()->isSplash(); }
bool isNotWalkable() { return rawGetThingType()->isNotWalkable(); }
bool isNotMoveable() { return rawGetThingType()->isNotMoveable(); }
bool blockProjectile() { return rawGetThingType()->blockProjectile(); }
bool isNotPathable() { return rawGetThingType()->isNotPathable(); }
bool isPickupable() { return rawGetThingType()->isPickupable(); }
bool isHangable() { return rawGetThingType()->isHangable(); }
bool isHookSouth() { return rawGetThingType()->isHookSouth(); }
bool isHookEast() { return rawGetThingType()->isHookEast(); }
bool isRotateable() { return rawGetThingType()->isRotateable(); }
bool hasLight() { return rawGetThingType()->hasLight(); }
bool isDontHide() { return rawGetThingType()->isDontHide(); }
bool isTranslucent() { return rawGetThingType()->isTranslucent(); }
bool hasDisplacement() { return rawGetThingType()->hasDisplacement(); }
bool hasElevation() { return rawGetThingType()->hasElevation(); }
bool isLyingCorpse() { return rawGetThingType()->isLyingCorpse(); }
bool isAnimateAlways() { return rawGetThingType()->isAnimateAlways(); }
bool hasMiniMapColor() { return rawGetThingType()->hasMiniMapColor(); }
bool hasLensHelp() { return rawGetThingType()->hasLensHelp(); }
bool isFullGround() { return rawGetThingType()->isFullGround(); }
bool isIgnoreLook() { return rawGetThingType()->isIgnoreLook(); }
bool isCloth() { return rawGetThingType()->isCloth(); }
bool isMarketable() { return rawGetThingType()->isMarketable(); }
MarketData getMarketData() { return rawGetThingType()->getMarketData(); }
protected:

View File

@ -20,7 +20,7 @@
* THE SOFTWARE.
*/
#include "thingtypedat.h"
#include "thingtype.h"
#include "spritemanager.h"
#include "game.h"
@ -30,7 +30,7 @@
#include <framework/graphics/texturemanager.h>
#include <framework/core/filestream.h>
ThingTypeDat::ThingTypeDat()
ThingType::ThingType()
{
m_category = DatInvalidCategory;
m_id = 0;
@ -41,7 +41,7 @@ ThingTypeDat::ThingTypeDat()
m_layers = 0;
}
void ThingTypeDat::unserialize(uint16 clientId, DatCategory category, const FileStreamPtr& fin)
void ThingType::unserialize(uint16 clientId, DatCategory category, const FileStreamPtr& fin)
{
m_null = false;
m_id = clientId;
@ -133,7 +133,7 @@ void ThingTypeDat::unserialize(uint16 clientId, DatCategory category, const File
m_texturesFramesOffsets.resize(m_animationPhases);
}
void ThingTypeDat::draw(const Point& dest, float scaleFactor, int layer, int xPattern, int yPattern, int zPattern, int animationPhase)
void ThingType::draw(const Point& dest, float scaleFactor, int layer, int xPattern, int yPattern, int zPattern, int animationPhase)
{
if(m_null)
return;
@ -157,7 +157,7 @@ void ThingTypeDat::draw(const Point& dest, float scaleFactor, int layer, int xPa
g_painter->drawTexturedRect(screenRect, texture, textureRect);
}
const TexturePtr& ThingTypeDat::getTexture(int animationPhase)
const TexturePtr& ThingType::getTexture(int animationPhase)
{
TexturePtr& animationPhaseTexture = m_textures[animationPhase];
if(!animationPhaseTexture) {
@ -230,7 +230,7 @@ const TexturePtr& ThingTypeDat::getTexture(int animationPhase)
return animationPhaseTexture;
}
Size ThingTypeDat::getBestTextureDimension(int w, int h, int count)
Size ThingType::getBestTextureDimension(int w, int h, int count)
{
const int MAX = 32;
@ -264,7 +264,7 @@ Size ThingTypeDat::getBestTextureDimension(int w, int h, int count)
return bestDimension;
}
uint ThingTypeDat::getSpriteIndex(int w, int h, int l, int x, int y, int z, int a) {
uint ThingType::getSpriteIndex(int w, int h, int l, int x, int y, int z, int a) {
uint index =
((((((a % m_animationPhases)
* m_numPatternZ + z)
@ -277,7 +277,7 @@ uint ThingTypeDat::getSpriteIndex(int w, int h, int l, int x, int y, int z, int
return index;
}
uint ThingTypeDat::getTextureIndex(int l, int x, int y, int z) {
uint ThingType::getTextureIndex(int l, int x, int y, int z) {
return ((l * m_numPatternZ + z)
* m_numPatternY + y)
* m_numPatternX + x;

View File

@ -104,10 +104,10 @@ struct Light {
uint8 color;
};
class ThingTypeDat : public LuaObject
class ThingType : public LuaObject
{
public:
ThingTypeDat();
ThingType();
void unserialize(uint16 clientId, DatCategory category, const FileStreamPtr& fin);

View File

@ -23,8 +23,8 @@
#include "thingtypemanager.h"
#include "spritemanager.h"
#include "thing.h"
#include "thingtypedat.h"
#include "thingtypeotb.h"
#include "thingtype.h"
#include "itemtype.h"
#include <framework/core/resourcemanager.h>
#include <framework/core/filestream.h>
@ -35,8 +35,8 @@ ThingTypeManager g_things;
void ThingTypeManager::init()
{
m_nullDatType = ThingTypeDatPtr(new ThingTypeDat);
m_nullOtbType = ThingTypeOtbPtr(new ThingTypeOtb);
m_nullThingType = ThingTypePtr(new ThingType);
m_nullItemType = ItemTypePtr(new ItemType);
m_datSignature = 0;
m_otbMinorVersion = 0;
m_otbMajorVersion = 0;
@ -44,8 +44,8 @@ void ThingTypeManager::init()
m_xmlLoaded = false;
m_otbLoaded = false;
for(int i = 0; i < DatLastCategory; ++i)
m_datTypes[i].resize(1, m_nullDatType);
m_otbTypes.resize(1, m_nullOtbType);
m_datTypes[i].resize(1, m_nullThingType);
m_otbTypes.resize(1, m_nullItemType);
}
void ThingTypeManager::terminate()
@ -53,8 +53,8 @@ void ThingTypeManager::terminate()
for(int i = 0; i < DatLastCategory; ++i)
m_datTypes[i].clear();
m_otbTypes.clear();
m_nullDatType = nullptr;
m_nullOtbType = nullptr;
m_nullThingType = nullptr;
m_nullItemType = nullptr;
}
bool ThingTypeManager::loadDat(const std::string& file)
@ -69,7 +69,7 @@ bool ThingTypeManager::loadDat(const std::string& file)
int numThings[DatLastCategory];
for(int category = 0; category < DatLastCategory; ++category) {
int count = fin->getU16() + 1;
m_datTypes[category].resize(count, m_nullDatType);
m_datTypes[category].resize(count, m_nullThingType);
}
for(int category = 0; category < DatLastCategory; ++category) {
@ -77,7 +77,7 @@ bool ThingTypeManager::loadDat(const std::string& file)
if(category == DatItemCategory)
firstId = 100;
for(uint16 id = firstId; id < m_datTypes[category].size(); ++id) {
ThingTypeDatPtr type(new ThingTypeDat);
ThingTypePtr type(new ThingType);
type->unserialize(id, (DatCategory)category, fin);
m_datTypes[category][id] = type;
}
@ -112,11 +112,11 @@ void ThingTypeManager::loadOtb(const std::string& file)
root->getU32(); // build number
root->skip(128); // description
m_otbTypes.resize(root->getChildren().size(), m_nullOtbType);
m_otbTypes.resize(root->getChildren().size(), m_nullItemType);
for(const BinaryTreePtr& node : root->getChildren()) {
ThingTypeOtbPtr otbType(new ThingTypeOtb);
ItemTypePtr otbType(new ItemType);
otbType->unserialize(node);
addOtbType(otbType);
addItemType(otbType);
}
m_otbLoaded = true;
@ -141,9 +141,9 @@ void ThingTypeManager::loadXml(const std::string& file)
uint16 id = element->readType<uint16>("id");
if(id > 20000 && id < 20100) {
id -= 20000;
ThingTypeOtbPtr newType(new ThingTypeOtb);
ItemTypePtr newType(new ItemType);
newType->setServerId(id);
addOtbType(newType);
addItemType(newType);
}
if(id != 0)
@ -166,12 +166,12 @@ void ThingTypeManager::parseItemType(uint16 id, TiXmlElement* elem)
if(serverId > 20000 && id < 20100) {
serverId -= 20000;
ThingTypeOtbPtr newType(new ThingTypeOtb);
ItemTypePtr newType(new ItemType);
newType->setServerId(serverId);
addOtbType(newType);
addItemType(newType);
}
ThingTypeOtbPtr otbType = getOtbType(serverId);
ItemTypePtr otbType = getItemType(serverId);
otbType->setName(elem->Attribute("name"));
for(TiXmlElement* attrib = elem->FirstChildElement(); attrib; attrib = attrib->NextSiblingElement()) {
if(attrib->ValueStr() != "attribute")
@ -184,41 +184,41 @@ void ThingTypeManager::parseItemType(uint16 id, TiXmlElement* elem)
}
}
void ThingTypeManager::addOtbType(const ThingTypeOtbPtr& otbType)
void ThingTypeManager::addItemType(const ItemTypePtr& otbType)
{
uint16 id = otbType->getServerId();
if(m_otbTypes.size() <= id)
m_otbTypes.resize(id+1, m_nullOtbType);
m_otbTypes.resize(id+1, m_nullItemType);
m_otbTypes[id] = otbType;
}
const ThingTypeOtbPtr& ThingTypeManager::findOtbForClientId(uint16 id)
const ItemTypePtr& ThingTypeManager::findOtbForClientId(uint16 id)
{
if(m_otbTypes.empty())
return m_nullOtbType;
return m_nullItemType;
for(const ThingTypeOtbPtr& otbType : m_otbTypes) {
for(const ItemTypePtr& otbType : m_otbTypes) {
if(otbType->getClientId() == id)
return otbType;
}
return m_nullOtbType;
return m_nullItemType;
}
const ThingTypeDatPtr& ThingTypeManager::getDatType(uint16 id, DatCategory category)
const ThingTypePtr& ThingTypeManager::getThingType(uint16 id, DatCategory category)
{
if(category >= DatLastCategory || id >= m_datTypes[category].size()) {
g_logger.error(stdext::format("invalid thing type client id %d in category %d", id, category));
return m_nullDatType;
return m_nullThingType;
}
return m_datTypes[category][id];
}
const ThingTypeOtbPtr& ThingTypeManager::getOtbType(uint16 id)
const ItemTypePtr& ThingTypeManager::getItemType(uint16 id)
{
if(id >= m_otbTypes.size()) {
g_logger.error(stdext::format("invalid thing type server id %d", id));
return m_nullOtbType;
return m_nullItemType;
}
return m_otbTypes[id];
}

View File

@ -26,8 +26,8 @@
#include <framework/global.h>
#include <framework/core/declarations.h>
#include "thingtypedat.h"
#include "thingtypeotb.h"
#include "thingtype.h"
#include "itemtype.h"
class ThingTypeManager
{
@ -40,16 +40,16 @@ public:
void loadXml(const std::string& file);
void parseItemType(uint16 id, TiXmlElement *elem);
void addOtbType(const ThingTypeOtbPtr& otbType);
const ThingTypeOtbPtr& findOtbForClientId(uint16 id);
void addItemType(const ItemTypePtr& otbType);
const ItemTypePtr& findOtbForClientId(uint16 id);
const ThingTypeDatPtr& getNullDatType() { return m_nullDatType; }
const ThingTypeOtbPtr& getNullOtbType() { return m_nullOtbType; }
const ThingTypePtr& getNullThingType() { return m_nullThingType; }
const ItemTypePtr& getNullItemType() { return m_nullItemType; }
const ThingTypeDatPtr& getDatType(uint16 id, DatCategory category);
const ThingTypeOtbPtr& getOtbType(uint16 id);
ThingTypeDat* rawGetDatType(uint16 id, DatCategory category) { return m_datTypes[category][id].get(); }
ThingTypeOtb* rawGetOtbType(uint16 id) { return m_otbTypes[id].get(); }
const ThingTypePtr& getThingType(uint16 id, DatCategory category);
const ItemTypePtr& getItemType(uint16 id);
ThingType* rawGetThingType(uint16 id, DatCategory category) { return m_datTypes[category][id].get(); }
ItemType* rawGetItemType(uint16 id) { return m_otbTypes[id].get(); }
uint32 getDatSignature() { return m_datSignature; }
uint32 getOtbMajorVersion() { return m_otbMajorVersion; }
@ -63,11 +63,11 @@ public:
bool isValidOtbId(uint16 id) { return id >= 1 && id < m_otbTypes.size(); }
private:
ThingTypeDatList m_datTypes[DatLastCategory];
ThingTypeOtbList m_otbTypes;
ThingTypeList m_datTypes[DatLastCategory];
ItemTypeList m_otbTypes;
ThingTypeDatPtr m_nullDatType;
ThingTypeOtbPtr m_nullOtbType;
ThingTypePtr m_nullThingType;
ItemTypePtr m_nullItemType;
bool m_datLoaded;
bool m_xmlLoaded;