From e69a6d11400ea2a4f108f4a335e22eb5b4a51310 Mon Sep 17 00:00:00 2001 From: Eduardo Bart Date: Wed, 31 Aug 2011 12:03:33 -0300 Subject: [PATCH] move datmanager to thingstype --- CMakeLists.txt | 2 +- src/framework/platform/x11platform.cpp | 2 +- src/otclient/const.h | 18 -- src/otclient/core/creature.cpp | 20 +- src/otclient/core/creature.h | 2 +- src/otclient/core/datmanager.cpp | 227 ------------------ src/otclient/core/effect.cpp | 10 +- src/otclient/core/effect.h | 2 +- src/otclient/core/item.cpp | 32 +-- src/otclient/core/item.h | 2 +- src/otclient/core/thing.cpp | 2 +- src/otclient/core/thing.h | 4 +- src/otclient/core/thingstype.cpp | 222 +++++++++++++++++ .../core/{datmanager.h => thingstype.h} | 25 +- src/otclient/core/thingtype.h | 130 ++++++++++ src/otclient/core/tile.cpp | 34 +-- src/otclient/net/protocolgameparse.cpp | 6 +- src/otclient/otclient.cpp | 24 -- src/otclient/otclientluafunctions.cpp | 4 +- 19 files changed, 425 insertions(+), 343 deletions(-) delete mode 100644 src/otclient/core/datmanager.cpp create mode 100644 src/otclient/core/thingstype.cpp rename src/otclient/core/{datmanager.h => thingstype.h} (63%) create mode 100644 src/otclient/core/thingtype.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 2148a00d..060b725b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,7 +58,7 @@ SET(SOURCES # otclient core src/otclient/core/game.cpp src/otclient/core/map.cpp - src/otclient/core/datmanager.cpp + src/otclient/core/thingstype.cpp src/otclient/core/spritemanager.cpp src/otclient/core/item.cpp src/otclient/core/tile.cpp diff --git a/src/framework/platform/x11platform.cpp b/src/framework/platform/x11platform.cpp index c3ac574e..9f348838 100644 --- a/src/framework/platform/x11platform.cpp +++ b/src/framework/platform/x11platform.cpp @@ -528,7 +528,7 @@ bool Platform::createWindow(int x, int y, int width, int height, int minWidth, i x11.visual->visual, AllocNone); - // setup window attributes + // setup window type XSetWindowAttributes wa; wa.colormap = x11.colormap; wa.border_pixel = 0; diff --git a/src/otclient/const.h b/src/otclient/const.h index 4fbde909..8d1cf5bb 100644 --- a/src/otclient/const.h +++ b/src/otclient/const.h @@ -80,24 +80,6 @@ namespace Otc LastDatFlag = 255 }; - enum ThingAttributesGroup { - ThingNoGroup = 0, - ThingGroundGroup, - ThingContainerGroup, - ThingWeaponGroup, - ThingAmmunitionGroup, - ThingArmorGroup, - ThingRuneGroup, - ThingTeleportGroup, - ThingMagicFieldGroup, - ThingWriteableGroup, - ThingKeyGroup, - ThingSplashGroup, - ThingFluidGroup, - ThingDoorGroup, - ThingLastGroup - }; - enum ThingType { Item, Creature, diff --git a/src/otclient/core/creature.cpp b/src/otclient/core/creature.cpp index 11d9f277..b8f89323 100644 --- a/src/otclient/core/creature.cpp +++ b/src/otclient/core/creature.cpp @@ -21,7 +21,7 @@ */ #include "creature.h" -#include "datmanager.h" +#include "thingstype.h" #include "localplayer.h" #include "map.h" #include @@ -68,10 +68,10 @@ void Creature::draw(int x, int y) x += m_walkOffsetX; y += m_walkOffsetY; - const ThingAttributes& attributes = getAttributes(); + const ThingType& type = getType(); // Render creature - for(m_yPattern = 0; m_yPattern < attributes.yPattern; m_yPattern++) { + for(m_yPattern = 0; m_yPattern < type.yPattern; m_yPattern++) { // continue if we dont have this addon. if(m_yPattern > 0 && !(m_outfit.addons & (1 << (m_yPattern-1)))) @@ -81,7 +81,7 @@ void Creature::draw(int x, int y) internalDraw(x, y, 0); // draw mask if exists - if(attributes.layers > 1) { + if(type.layers > 1) { // switch to blend color mode g_graphics.bindBlendFunc(Fw::BlendColorzing); @@ -108,7 +108,7 @@ void Creature::draw(int x, int y) } // Update animation and position - if(m_walking && attributes.animationPhases > 1) { + if(m_walking && type.animationPhases > 1) { if(g_platform.getTicks() - m_lastTicks >= m_walkTimePerPixel) { int pixelsWalked = std::floor((g_platform.getTicks() - m_lastTicks) / m_walkTimePerPixel); @@ -125,8 +125,8 @@ void Creature::draw(int x, int y) m_walkOffsetX = std::max(m_walkOffsetX - pixelsWalked, 0); int walkOffset = std::max(std::abs(m_walkOffsetX), std::abs(m_walkOffsetY)); - if(walkOffset % (int)std::ceil(32 / (float)attributes.animationPhases) == 0) { - if((m_animation+1) % attributes.animationPhases == 0) + if(walkOffset % (int)std::ceil(32 / (float)type.animationPhases) == 0) { + if((m_animation+1) % type.animationPhases == 0) m_animation = 1; else m_animation++; @@ -239,7 +239,7 @@ void Creature::walk(const Position& position) ThingPtr ground = g_map.getThing(m_position, 0); if(ground) - groundSpeed = ground->getAttributes().groundSpeed; + groundSpeed = ground->getType().groundSpeed; float walkTime = walkTimeFactor * 1000.0 * (float)groundSpeed / m_speed; walkTime = walkTime == 0 ? 1000 : walkTime; @@ -266,9 +266,9 @@ void Creature::setHealthPercent(uint8 healthPercent) onHealthPercentChange(oldHealthPercent); } -const ThingAttributes& Creature::getAttributes() +const ThingType& Creature::getType() { - return g_dat.getCreatureAttributes(m_outfit.type); + return g_thingsType.getCreatureType(m_outfit.type); } void Creature::onHealthPercentChange(int) diff --git a/src/otclient/core/creature.h b/src/otclient/core/creature.h index 5565830e..63d46afe 100644 --- a/src/otclient/core/creature.h +++ b/src/otclient/core/creature.h @@ -66,7 +66,7 @@ public: uint8 getShield() { return m_shield; } uint8 getEmblem() { return m_emblem; } bool getImpassable() { return m_impassable; } - const ThingAttributes& getAttributes(); + const ThingType& getType(); void onHealthPercentChange(int); diff --git a/src/otclient/core/datmanager.cpp b/src/otclient/core/datmanager.cpp deleted file mode 100644 index 85266dcd..00000000 --- a/src/otclient/core/datmanager.cpp +++ /dev/null @@ -1,227 +0,0 @@ -/* - * Copyright (c) 2010-2011 OTClient - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "datmanager.h" -#include "spritemanager.h" -#include "thing.h" -#include - -DatManager g_dat; - -bool DatManager::load(const std::string& file) -{ - try { - std::stringstream fin; - g_resources.loadFile(file, fin); - - m_signature = Fw::getU32(fin); - int numItems = Fw::getU16(fin); - int numCreatures = Fw::getU16(fin); - int numEffects = Fw::getU16(fin); - int numShots = Fw::getU16(fin); - - m_itemsAttributes.resize(numItems); - for(int id = 100; id < numItems; ++id) - parseThingAttributes(fin, m_itemsAttributes[id - 100]); - - m_creaturesAttributes.resize(numItems); - for(int id = 0; id < numCreatures; ++id) - parseThingAttributes(fin, m_creaturesAttributes[id]); - - m_effectsAttributes.resize(numItems); - for(int id = 0; id < numEffects; ++id) - parseThingAttributes(fin, m_effectsAttributes[id]); - - m_shotsAttributes.resize(numItems); - for(int id = 0; id < numShots; ++id) - parseThingAttributes(fin, m_shotsAttributes[id]); - - return true; - } catch(std::exception& e) { - logError("failed to load dat from '", file, "': ", e.what()); - return false; - } -} - -void DatManager::unload() -{ - m_itemsAttributes.clear(); - m_creaturesAttributes.clear(); - m_effectsAttributes.clear(); - m_shotsAttributes.clear(); -} - -void DatManager::parseThingAttributes(std::stringstream& fin, ThingAttributes& thingAttributes) -{ - assert(fin.good()); - - while(true) { - uint8 opt; - fin.read((char*)&opt, 1); - - if(opt == Otc::LastDatFlag) - break; - - parseThingAttributesOpt(fin, thingAttributes, opt); - } - - thingAttributes.width = Fw::getU8(fin); - thingAttributes.height = Fw::getU8(fin); - - if(thingAttributes.width > 1 || thingAttributes.height > 1) - thingAttributes.exactSize = Fw::getU8(fin); - else - thingAttributes.exactSize = 32; - - thingAttributes.layers = Fw::getU8(fin); - thingAttributes.xPattern = Fw::getU8(fin); - thingAttributes.yPattern = Fw::getU8(fin); - thingAttributes.zPattern = Fw::getU8(fin); - thingAttributes.animationPhases = Fw::getU8(fin); - - int totalSprites = thingAttributes.width - * thingAttributes.height - * thingAttributes.layers - * thingAttributes.xPattern - * thingAttributes.yPattern - * thingAttributes.zPattern - * thingAttributes.animationPhases; - - thingAttributes.sprites.resize(totalSprites); - for(uint16 i = 0; i < totalSprites; i++) - thingAttributes.sprites[i] = Fw::getU16(fin); -} - -void DatManager::parseThingAttributesOpt(std::stringstream& fin, ThingAttributes& thingAttributes, uint8 opt) -{ - switch(opt) { - case Otc::DatGround: // Grounds, must be drawn first - thingAttributes.groundSpeed = Fw::getU16(fin); - thingAttributes.isGround = true; - break; - case Otc::DatGroundClip: // Objects that clips (has transparent pixels) and must be drawn just after ground (e.g: ground borders) - thingAttributes.isGroundClip = true; - break; - case Otc::DatOnBottom: // Bottom items, must be drawn above general items and below creatures (e.g: stairs) - thingAttributes.isOnBottom = true; - break; - case Otc::DatOnTop: // Top items, must be drawn above creatures (e.g: doors) - thingAttributes.isOnTop = true; - break; - case Otc::DatContainer: // Containers - thingAttributes.isContainer = true; - break; - case Otc::DatStackable: // Stackable - thingAttributes.isStackable = true; - break; - case Otc::DatForceUse: // Items that are automatically used when step over? - thingAttributes.isForceUse = true; - break; - case Otc::DatMultiUse: // Usable items - thingAttributes.isMultiUse = true; - break; - case Otc::DatWritable: // Writable - thingAttributes.isWritable = true; - thingAttributes.maxTextLength = Fw::getU16(fin); - break; - case Otc::DatWritableOnce: // Writable once. objects that can't be edited by players - thingAttributes.isWritableOnce = true; - thingAttributes.maxTextLength = Fw::getU16(fin); - break; - case Otc::DatFluidContainer: // Fluid containers - thingAttributes.fluidParam = Fw::getU8(fin); - break; - case Otc::DatSplash: // Splashes - thingAttributes.isStackable = true; - break; - case Otc::DatBlockWalk: // Blocks solid objects (creatures, walls etc) - thingAttributes.isNotWalkable = true; - break; - case Otc::DatNotMovable: // Not movable - thingAttributes.isNotMoveable = true; - break; - case Otc::DatBlockProjectile: // Blocks missiles (walls, magic wall etc) - thingAttributes.isNotProjectable = true; - break; - case Otc::DatBlockPathFind: // Blocks pathfind algorithms (monsters) - thingAttributes.isNotPathable = true; - break; - case Otc::DatPickupable: // Pickupable - thingAttributes.isPickupable = true; - break; - case Otc::DatHangable: // Hangable objects (wallpaper etc) - thingAttributes.isHangable = true; - break; - case Otc::DatHookSouth: // Horizontal walls - thingAttributes.isHookSouth = true; - break; - case Otc::DatHookEast: // Vertical walls - thingAttributes.isHookEast = true; - break; - case Otc::DatRotable: // Rotable - thingAttributes.isRotable = true; - break; - case Otc::DatLight: // Light info - thingAttributes.hasLight = true; - thingAttributes.lightLevel = Fw::getU16(fin); - thingAttributes.lightColor = Fw::getU16(fin); - break; - case Otc::DatDontHide: // A few monuments that are not supposed to be hidden by floors - break; - case Otc::DatTranslucent: // Grounds that are translucent - thingAttributes.isTranslucent = true; - break; - case Otc::DatDisplacment: // Must shift draw - thingAttributes.xDisplacment = Fw::getU16(fin); - thingAttributes.yDisplacment = Fw::getU16(fin); - break; - case Otc::DatElevation: // Must elevate draw - thingAttributes.elevation = Fw::getU16(fin); - break; - case Otc::DatLyingCorpse: // Some corpses - thingAttributes.isLyingCorpse = true; - break; - case Otc::DatAnimateAlways: // Unknown, check if firesword is a kind of AnimateAlways. - thingAttributes.isAnimatedAlways = true; - break; - case Otc::DatMinimapColor: // Minimap color - thingAttributes.hasMiniMapColor = true; - thingAttributes.miniMapColor = Fw::getU16(fin); - break; - case Otc::DatLensHelp: // Used for giving players tips? - thingAttributes.isLensHelp = true; - thingAttributes.lensHelpParam = Fw::getU16(fin); - break; - case Otc::DatFullGround: // Grounds that has no transparent pixels - thingAttributes.isFullGround = true; - break; - case Otc::DatIgnoreLook: // Ignore look, then looks at the item on the bottom of it - thingAttributes.isIgnoreLook = true; - break; - case Otc::DatClothe: // Clothes - break; - case Otc::DatAnimation: // Not used in 8.62 - break; - default: - throw std::runtime_error(Fw::mkstr("unknown .dat byte code: ", (int)opt)); - } -} diff --git a/src/otclient/core/effect.cpp b/src/otclient/core/effect.cpp index a2b8431a..b3a6db85 100644 --- a/src/otclient/core/effect.cpp +++ b/src/otclient/core/effect.cpp @@ -21,7 +21,7 @@ */ #include "effect.h" -#include "datmanager.h" +#include "thingstype.h" #include "map.h" #include #include @@ -36,8 +36,8 @@ void Effect::draw(int x, int y) { if(!m_finished) { if(g_platform.getTicks() - m_lastTicks > 75) { - const ThingAttributes& attributes = getAttributes(); - if(m_animation+1 == attributes.animationPhases) { + const ThingType& type = getType(); + if(m_animation+1 == type.animationPhases) { g_dispatcher.addEvent(std::bind(&Map::removeThingByPtr, &g_map, asThing())); m_finished = true; } @@ -50,7 +50,7 @@ void Effect::draw(int x, int y) } } -const ThingAttributes& Effect::getAttributes() +const ThingType& Effect::getType() { - return g_dat.getEffectAttributes(m_id); + return g_thingsType.getEffectType(m_id); } diff --git a/src/otclient/core/effect.h b/src/otclient/core/effect.h index 28dc38cc..e5037940 100644 --- a/src/otclient/core/effect.h +++ b/src/otclient/core/effect.h @@ -35,7 +35,7 @@ public: bool finished() { return m_finished; } - const ThingAttributes& getAttributes(); + const ThingType& getType(); EffectPtr asEffect() { return std::static_pointer_cast(shared_from_this()); } diff --git a/src/otclient/core/item.cpp b/src/otclient/core/item.cpp index 0c6d9e1c..a2279487 100644 --- a/src/otclient/core/item.cpp +++ b/src/otclient/core/item.cpp @@ -21,7 +21,7 @@ */ #include "item.h" -#include "datmanager.h" +#include "thingstype.h" #include "spritemanager.h" #include "thing.h" #include @@ -34,21 +34,21 @@ Item::Item() : Thing(Otc::Item) void Item::draw(int x, int y) { - const ThingAttributes& attributes = g_dat.getItemAttributes(m_id); + const ThingType& type = g_thingsType.getItemType(m_id); - if(attributes.animationPhases > 1) { + if(type.animationPhases > 1) { if(g_platform.getTicks() - m_lastTicks > 500) { m_animation++; m_lastTicks = g_platform.getTicks(); } } - /*if(attributes.group == Otc::ThingSplashGroup || attributes.group == Otc::ThingFluidGroup) { - //xPattern = m_count % attributes.xPattern; - //yPattern = m_count / attributes.yPattern; + /*if(type.group == Otc::ThingSplashGroup || type.group == Otc::ThingFluidGroup) { + //xPattern = m_count % type.xPattern; + //yPattern = m_count / type.yPattern; }*/ - for(int b = 0; b < attributes.layers; b++) + for(int b = 0; b < type.layers; b++) internalDraw(x, y, b); } @@ -59,27 +59,27 @@ void Item::setCount(int count) onCountChange(oldCount); } -const ThingAttributes& Item::getAttributes() +const ThingType& Item::getType() { - return g_dat.getItemAttributes(m_id); + return g_thingsType.getItemType(m_id); } void Item::onPositionChange(const Position&) { - const ThingAttributes& attributes = g_dat.getItemAttributes(m_id); + const ThingType& type = g_thingsType.getItemType(m_id); - if(attributes.isNotMoveable) { - m_xPattern = m_position.x % attributes.xPattern; - m_yPattern = m_position.y % attributes.yPattern; - m_zPattern = m_position.z % attributes.zPattern; + if(type.isNotMoveable) { + m_xPattern = m_position.x % type.xPattern; + m_yPattern = m_position.y % type.yPattern; + m_zPattern = m_position.z % type.zPattern; } } void Item::onCountChange(int) { - const ThingAttributes& attributes = g_dat.getItemAttributes(m_id); + const ThingType& type = g_thingsType.getItemType(m_id); - if(attributes.isStackable && attributes.xPattern == 4 && attributes.yPattern == 2) { + if(type.isStackable && type.xPattern == 4 && type.yPattern == 2) { if(m_count < 5) { m_xPattern = m_count-1; m_yPattern = 0; diff --git a/src/otclient/core/item.h b/src/otclient/core/item.h index e7f805c3..8885fa8c 100644 --- a/src/otclient/core/item.h +++ b/src/otclient/core/item.h @@ -36,7 +36,7 @@ public: void setCount(int count); int getCount() { return m_count; } - const ThingAttributes& getAttributes(); + const ThingType& getType(); void onPositionChange(const Position&); void onCountChange(int); diff --git a/src/otclient/core/thing.cpp b/src/otclient/core/thing.cpp index 4024a1b8..74d63405 100644 --- a/src/otclient/core/thing.cpp +++ b/src/otclient/core/thing.cpp @@ -42,7 +42,7 @@ void Thing::setPosition(const Position& position) void Thing::internalDraw(int x, int y, int layers, Otc::SpriteMask mask) { - const ThingAttributes& type = getAttributes(); + const ThingType& type = getType(); for(int yi = 0; yi < type.height; yi++) { for(int xi = 0; xi < type.width; xi++) { diff --git a/src/otclient/core/thing.h b/src/otclient/core/thing.h index 7414e7b6..e94b6b99 100644 --- a/src/otclient/core/thing.h +++ b/src/otclient/core/thing.h @@ -24,7 +24,7 @@ #define THING_H #include "declarations.h" -#include "thingattributes.h" +#include "thingtype.h" #include struct Light @@ -47,7 +47,7 @@ public: uint32 getId() const { return m_id; } Otc::ThingType getType() const { return m_type; } Position getPosition() const { return m_position; } - virtual const ThingAttributes& getAttributes() = 0; + virtual const ThingType& getType() = 0; virtual void onPositionChange(const Position&) {} diff --git a/src/otclient/core/thingstype.cpp b/src/otclient/core/thingstype.cpp new file mode 100644 index 00000000..d2628f48 --- /dev/null +++ b/src/otclient/core/thingstype.cpp @@ -0,0 +1,222 @@ +/* + * Copyright (c) 2010-2011 OTClient + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "thingstype.h" +#include "spritemanager.h" +#include "thing.h" +#include + +ThingsType g_thingsType; + +bool ThingsType::load(const std::string& file) +{ + try { + std::stringstream fin; + g_resources.loadFile(file, fin); + + m_signature = Fw::getU32(fin); + int numItems = Fw::getU16(fin); + int numCreatures = Fw::getU16(fin); + int numEffects = Fw::getU16(fin); + int numShots = Fw::getU16(fin); + + m_itemsType.resize(numItems); + for(int id = 100; id < numItems; ++id) + parseThingType(fin, m_itemsType[id - 100]); + + m_creaturesType.resize(numItems); + for(int id = 0; id < numCreatures; ++id) + parseThingType(fin, m_creaturesType[id]); + + m_effectsType.resize(numItems); + for(int id = 0; id < numEffects; ++id) + parseThingType(fin, m_effectsType[id]); + + m_shotsType.resize(numItems); + for(int id = 0; id < numShots; ++id) + parseThingType(fin, m_shotsType[id]); + + return true; + } catch(std::exception& e) { + logError("failed to load dat from '", file, "': ", e.what()); + return false; + } +} + +void ThingsType::unload() +{ + m_itemsType.clear(); + m_creaturesType.clear(); + m_effectsType.clear(); + m_shotsType.clear(); +} + +void ThingsType::parseThingType(std::stringstream& fin, ThingType& thingType) +{ + assert(fin.good()); + + bool done = false; + while(!done) { + uint8 opt = Fw::getU8(fin); + + switch(opt) { + case Otc::DatGround: // Grounds, must be drawn first + thingType.groundSpeed = Fw::getU16(fin); + thingType.isGround = true; + break; + case Otc::DatGroundClip: // Objects that clips (has transparent pixels) and must be drawn just after ground (e.g: ground borders) + thingType.isGroundClip = true; + break; + case Otc::DatOnBottom: // Bottom items, must be drawn above general items and below creatures (e.g: stairs) + thingType.isOnBottom = true; + break; + case Otc::DatOnTop: // Top items, must be drawn above creatures (e.g: doors) + thingType.isOnTop = true; + break; + case Otc::DatContainer: // Containers + thingType.isContainer = true; + break; + case Otc::DatStackable: // Stackable + thingType.isStackable = true; + break; + case Otc::DatForceUse: // Items that are automatically used when step over? + thingType.isForceUse = true; + break; + case Otc::DatMultiUse: // Usable items + thingType.isMultiUse = true; + break; + case Otc::DatWritable: // Writable + thingType.isWritable = true; + thingType.maxTextLength = Fw::getU16(fin); + break; + case Otc::DatWritableOnce: // Writable once. objects that can't be edited by players + thingType.isWritableOnce = true; + thingType.maxTextLength = Fw::getU16(fin); + break; + case Otc::DatFluidContainer: // Fluid containers + thingType.isFluidContainer = true; + break; + case Otc::DatSplash: // Splashes + thingType.isStackable = true; + break; + case Otc::DatBlockWalk: // Blocks solid objects (creatures, walls etc) + thingType.isNotWalkable = true; + break; + case Otc::DatNotMovable: // Not movable + thingType.isNotMoveable = true; + break; + case Otc::DatBlockProjectile: // Blocks missiles (walls, magic wall etc) + thingType.isNotProjectable = true; + break; + case Otc::DatBlockPathFind: // Blocks pathfind algorithms (monsters) + thingType.isNotPathable = true; + break; + case Otc::DatPickupable: // Pickupable + thingType.isPickupable = true; + break; + case Otc::DatHangable: // Hangable objects (wallpaper etc) + thingType.isHangable = true; + break; + case Otc::DatHookSouth: // Horizontal walls + thingType.isHookSouth = true; + break; + case Otc::DatHookEast: // Vertical walls + thingType.isHookEast = true; + break; + case Otc::DatRotable: // Rotable + thingType.isRotable = true; + break; + case Otc::DatLight: // Light info + thingType.hasLight = true; + thingType.lightLevel = Fw::getU16(fin); + thingType.lightColor = Fw::getU16(fin); + break; + case Otc::DatDontHide: // A few monuments that are not supposed to be hidden by floors + break; + case Otc::DatTranslucent: // Grounds that are translucent + thingType.isTranslucent = true; + break; + case Otc::DatDisplacment: // Must shift draw + thingType.xDisplacment = Fw::getU16(fin); + thingType.yDisplacment = Fw::getU16(fin); + break; + case Otc::DatElevation: // Must elevate draw + thingType.elevation = Fw::getU16(fin); + break; + case Otc::DatLyingCorpse: // Some corpses + thingType.isLyingCorpse = true; + break; + case Otc::DatAnimateAlways: // Unknown, check if firesword is a kind of AnimateAlways. + thingType.isAnimatedAlways = true; + break; + case Otc::DatMinimapColor: // Minimap color + thingType.hasMiniMapColor = true; + thingType.miniMapColor = Fw::getU16(fin); + break; + case Otc::DatLensHelp: // Used for giving players tips? + thingType.isLensHelp = true; + thingType.lensHelpParam = Fw::getU16(fin); + break; + case Otc::DatFullGround: // Grounds that has no transparent pixels + thingType.isFullGround = true; + break; + case Otc::DatIgnoreLook: // Ignore look, then looks at the item on the bottom of it + thingType.isIgnoreLook = true; + break; + case Otc::DatClothe: // Clothes + break; + case Otc::DatAnimation: // Not used in 8.62 + break; + case Otc::LastDatFlag: + done = true; + break; + default: + throw std::runtime_error(Fw::mkstr("unknown .dat byte code: ", (int)opt)); + } + } + + thingType.width = Fw::getU8(fin); + thingType.height = Fw::getU8(fin); + + if(thingType.width > 1 || thingType.height > 1) + thingType.exactSize = Fw::getU8(fin); + else + thingType.exactSize = 32; + + thingType.layers = Fw::getU8(fin); + thingType.xPattern = Fw::getU8(fin); + thingType.yPattern = Fw::getU8(fin); + thingType.zPattern = Fw::getU8(fin); + thingType.animationPhases = Fw::getU8(fin); + + int totalSprites = thingType.width + * thingType.height + * thingType.layers + * thingType.xPattern + * thingType.yPattern + * thingType.zPattern + * thingType.animationPhases; + + thingType.sprites.resize(totalSprites); + for(uint16 i = 0; i < totalSprites; i++) + thingType.sprites[i] = Fw::getU16(fin); +} diff --git a/src/otclient/core/datmanager.h b/src/otclient/core/thingstype.h similarity index 63% rename from src/otclient/core/datmanager.h rename to src/otclient/core/thingstype.h index eac45899..3bccfae2 100644 --- a/src/otclient/core/datmanager.h +++ b/src/otclient/core/thingstype.h @@ -24,33 +24,32 @@ #define DATMANAGER_H #include -#include "thingattributes.h" +#include "thingtype.h" -class DatManager +class ThingsType { public: bool load(const std::string& file); void unload(); - void parseThingAttributes(std::stringstream& fin, ThingAttributes& thingAttributes); - void parseThingAttributesOpt(std::stringstream& fin, ThingAttributes& thingAttributes, uint8 opt); + void parseThingType(std::stringstream& fin, ThingType& thingType); - ThingAttributes& getItemAttributes(uint16 id) { return m_itemsAttributes[id - 100]; } - ThingAttributes& getCreatureAttributes(uint16 id) { return m_creaturesAttributes[id]; } - ThingAttributes& getEffectAttributes(uint16 id) { return m_effectsAttributes[id]; } - ThingAttributes& getShotAttributes(uint16 id) { return m_shotsAttributes[id]; } + ThingType& getItemType(uint16 id) { return m_itemsType[id - 100]; } + ThingType& getCreatureType(uint16 id) { return m_creaturesType[id]; } + ThingType& getEffectType(uint16 id) { return m_effectsType[id]; } + ThingType& getShotType(uint16 id) { return m_shotsType[id]; } uint32 getSignature() { return m_signature; } private: uint32 m_signature; - ThingAttributesList m_itemsAttributes; - ThingAttributesList m_creaturesAttributes; - ThingAttributesList m_effectsAttributes; - ThingAttributesList m_shotsAttributes; + ThingTypeList m_itemsType; + ThingTypeList m_creaturesType; + ThingTypeList m_effectsType; + ThingTypeList m_shotsType; }; -extern DatManager g_dat; +extern ThingsType g_thingsType; #endif diff --git a/src/otclient/core/thingtype.h b/src/otclient/core/thingtype.h new file mode 100644 index 00000000..aa4d94f4 --- /dev/null +++ b/src/otclient/core/thingtype.h @@ -0,0 +1,130 @@ +/* + * Copyright (c) 2010-2011 OTClient + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef THINGATTRIBUTES_H +#define THINGATTRIBUTES_H + +#include "declarations.h" + +struct ThingType +{ + ThingType() { + layers = 0; + width = height = 0; + exactSize = 0; + xPattern = yPattern = zPattern = 0; + animationPhases = 0; + xDisplacment = yDisplacment = 0; + elevation = 0; + + isGround = false; + isGroundClip = false; + isOnBottom = false; + isOnTop = false; + isContainer = false; + isStackable = false; + isForceUse = false; + isMultiUse = false; + isWritable = false; + isWritableOnce = false; + isFluidContainer = false; + isSplash = false; + isNotWalkable = false; + isNotMoveable = false; + isNotProjectable = false; + isNotPathable = false; + isPickupable = false; + isHangable = false; + isHookSouth = false; + isHookEast = false; + isRotable = false; + isDontHide = false; + isTranslucent = false; + isLyingCorpse = false; + isAnimatedAlways = false; + isLensHelp = false; + isFullGround = false; + isIgnoreLook = false; + isClothe = false; + hasLight = false; + hasMiniMapColor = false; + + groundSpeed = 0; + fluidParam = 0; + maxTextLength = 0; + lightLevel = lightColor = 0; + miniMapColor = 0; + lensHelpParam = 0; + } + + uint8 layers; + uint8 width, height; + uint8 exactSize; + uint8 xPattern, yPattern, zPattern; + uint8 animationPhases; + uint16 xDisplacment, yDisplacment; + uint16 elevation; + std::vector sprites; + + bool isGround; + bool isGroundClip; + bool isOnBottom; + bool isOnTop; + bool isContainer; + bool isStackable; + bool isForceUse; + bool isMultiUse; + bool isWritable; + bool isWritableOnce; + bool isFluidContainer; + bool isSplash; + bool isNotWalkable; + bool isNotMoveable; + bool isNotProjectable; + bool isNotPathable; + bool isPickupable; + bool isHangable; + bool isHookSouth; + bool isHookEast; + bool isRotable; + bool isDontHide; + bool isTranslucent; + bool isLyingCorpse; + bool isAnimatedAlways; + bool isLensHelp; + bool isFullGround; + bool isIgnoreLook; + bool isClothe; + bool hasLight; + bool hasMiniMapColor; + + uint16 groundSpeed; + uint8 fluidParam; + uint16 maxTextLength; + uint16 lightLevel, lightColor; + uint16 miniMapColor; + uint16 lensHelpParam; +}; + +typedef std::vector ThingTypeList; + +#endif diff --git a/src/otclient/core/tile.cpp b/src/otclient/core/tile.cpp index 5548fe2f..c5f4d94d 100644 --- a/src/otclient/core/tile.cpp +++ b/src/otclient/core/tile.cpp @@ -22,7 +22,7 @@ #include "tile.h" #include "item.h" -#include "datmanager.h" +#include "thingstype.h" #include "map.h" #include "game.h" #include "localplayer.h" @@ -43,29 +43,29 @@ void Tile::draw(int x, int y) for(auto it = m_itemsTop.rbegin(), end = m_itemsTop.rend(); it != end; ++it) { const ThingPtr& thing = *it; - const ThingAttributes& thingAttributes = thing->getAttributes(); + const ThingType& thingType = thing->getType(); - if(thingAttributes.isGroundClip) { + if(thingType.isGroundClip) { thing->draw(x - m_drawNextOffset, y - m_drawNextOffset); - m_drawNextOffset += thingAttributes.elevation; + m_drawNextOffset += thingType.elevation; } } for(auto it = m_itemsTop.rbegin(), end = m_itemsTop.rend(); it != end; ++it) { const ThingPtr& thing = *it; - const ThingAttributes& thingAttributes = thing->getAttributes(); + const ThingType& thingType = thing->getType(); - if(thingAttributes.isOnBottom) { + if(thingType.isOnBottom) { thing->draw(x - m_drawNextOffset, y - m_drawNextOffset); - m_drawNextOffset += thingAttributes.elevation; + m_drawNextOffset += thingType.elevation; } } for(auto it = m_itemsBottom.rbegin(), end = m_itemsBottom.rend(); it != end; ++it) { const ThingPtr& thing = *it; - const ThingAttributes& thingAttributes = thing->getAttributes(); + const ThingType& thingType = thing->getType(); thing->draw(x - m_drawNextOffset, y - m_drawNextOffset); - m_drawNextOffset += thingAttributes.elevation; + m_drawNextOffset += thingType.elevation; } for(auto it = m_creatures.rbegin(), end = m_creatures.rend(); it != end; ++it) { @@ -80,9 +80,9 @@ void Tile::draw(int x, int y) for(auto it = m_itemsTop.rbegin(), end = m_itemsTop.rend(); it != end; ++it) { const ThingPtr& thing = *it; - const ThingAttributes& thingAttributes = thing->getAttributes(); + const ThingType& thingType = thing->getType(); - if(thingAttributes.isOnTop) { + if(thingType.isOnTop) { thing->draw(x, y); } } @@ -94,13 +94,13 @@ void Tile::addThing(ThingPtr thing, int stackpos) if(!thing) return; - const ThingAttributes& thingAttributes = thing->getAttributes(); + const ThingType& thingType = thing->getType(); if(thing->asItem()) { - if(thingAttributes.isGround) + if(thingType.isGround) m_ground = thing; else { - if(thingAttributes.isGroundClip || thingAttributes.isOnBottom || thingAttributes.isOnTop) + if(thingType.isGroundClip || thingType.isOnBottom || thingType.isOnTop) m_itemsTop.push_back(thing); else { if(stackpos == -1) @@ -171,9 +171,9 @@ void Tile::removeThingByPtr(ThingPtr thing) { // Items if(thing->asItem()) { - const ThingAttributes& thingAttributes = thing->getAttributes(); + const ThingType& thingType = thing->getType(); - if(!(thingAttributes.isGroundClip || thingAttributes.isOnBottom || thingAttributes.isOnTop)) { + if(!(thingType.isGroundClip || thingType.isOnBottom || thingType.isOnTop)) { for(auto it = m_itemsBottom.begin(), end = m_itemsBottom.end(); it != end; ++it) { if(*it == thing) { m_itemsBottom.erase(it); @@ -240,7 +240,7 @@ int Tile::getStackSize(int stop) bool Tile::isOpaque() { - if(m_ground && !m_ground->getAttributes().isTranslucent) + if(m_ground && !m_ground->getType().isTranslucent) return true; return false; } diff --git a/src/otclient/net/protocolgameparse.cpp b/src/otclient/net/protocolgameparse.cpp index 18afe016..ce278c27 100644 --- a/src/otclient/net/protocolgameparse.cpp +++ b/src/otclient/net/protocolgameparse.cpp @@ -23,7 +23,7 @@ #include "protocolgame.h" #include -#include +#include #include #include #include @@ -1037,8 +1037,8 @@ ItemPtr ProtocolGame::internalGetItem(InputMessage& msg, uint16 id) id = msg.getU16(); item->setId(id); - const ThingAttributes& itemAttributes = g_dat.getItemAttributes(id); - if(itemAttributes.isStackable || itemAttributes.isFluidContainer || itemAttributes.isSplash == Otc::ThingSplashGroup) + const ThingType& itemType = g_thingsType.getItemType(id); + if(itemType.isStackable || itemType.isFluidContainer || itemType.isSplash) item->setCount(msg.getU8()); return item; diff --git a/src/otclient/otclient.cpp b/src/otclient/otclient.cpp index 02c3b94f..29d8061f 100644 --- a/src/otclient/otclient.cpp +++ b/src/otclient/otclient.cpp @@ -37,8 +37,6 @@ #include #include #include -#include "core/datmanager.h" -#include "core/item.h" OTClient g_client; @@ -231,28 +229,6 @@ void OTClient::render() { // everything is rendered by UI components g_ui.render(); - - // utility for viewing dat items - /* - int count = 0; - auto maxSize = g_graphics.getScreenSize(); - ItemPtr item(new Item); - int x = 32; - int y = 32; - for(int i=100;i<11803;++i) { - if(g_dat.getItemAttributes(i).group == Otc::ThingGroundGroup && !g_dat.getItemAttributes(i).changesFloor) { - item->setId(i); - item->draw(x, y); - x += 64; - if(x > g_graphics.getScreenSize().width()) { - x = 32; - y += 64; - if(y > maxSize.height()) - break; - } - } - } - */ } void OTClient::loadConfigurations() diff --git a/src/otclient/otclientluafunctions.cpp b/src/otclient/otclientluafunctions.cpp index db1ad403..186f893f 100644 --- a/src/otclient/otclientluafunctions.cpp +++ b/src/otclient/otclientluafunctions.cpp @@ -30,7 +30,7 @@ #include #include #include -#include +#include #include #include #include @@ -40,7 +40,7 @@ void OTClient::registerLuaFunctions() { g_lua.bindGlobalFunction("exit", std::bind(&OTClient::exit, &g_client)); g_lua.bindGlobalFunction("setOnClose", std::bind(&OTClient::setOnClose, &g_client, _1)); - g_lua.bindGlobalFunction("importDat", std::bind(&DatManager::load, &g_dat, _1)); + g_lua.bindGlobalFunction("importDat", std::bind(&ThingsType::load, &g_thingsType, _1)); g_lua.bindGlobalFunction("importSpr", std::bind(&SpriteManager::load, &g_sprites, _1)); g_lua.registerClass();