From 9088bad0b0e2d66929f60b2fac9d0471a0b7c5c9 Mon Sep 17 00:00:00 2001 From: Henrique Date: Wed, 24 Aug 2011 00:58:23 -0300 Subject: [PATCH] addons, item count, stackpos fix --- src/otclient/core/creature.cpp | 59 ++++++++++++++------------ src/otclient/core/item.cpp | 30 +++++++++++-- src/otclient/core/map.cpp | 8 ++-- src/otclient/core/map.h | 6 +-- src/otclient/core/tile.cpp | 35 ++++++++++----- src/otclient/core/tile.h | 8 ++-- src/otclient/net/protocolgameparse.cpp | 2 +- 7 files changed, 94 insertions(+), 54 deletions(-) diff --git a/src/otclient/core/creature.cpp b/src/otclient/core/creature.cpp index 66467e8f..78e6f1a2 100644 --- a/src/otclient/core/creature.cpp +++ b/src/otclient/core/creature.cpp @@ -1,8 +1,6 @@ - #include "creature.h" +#include "creature.h" #include "datmanager.h" #include -#include -#include "game.h" #include Creature::Creature() : Thing(THING_CREATURE) @@ -13,34 +11,41 @@ Creature::Creature() : Thing(THING_CREATURE) void Creature::draw(int x, int y) { - //ThingAttributes *creatureAttributes = getAttributes(); int anim = 0; - // draw outfit - internalDraw(x, y, 0, m_direction, 0, 0, anim); - const ThingAttributes& attributes = getAttributes(); - if(attributes.blendframes > 1) { - g_graphics.bindBlendFunc(BLEND_COLORIZING); - - for(int mask = 0; mask < 4; ++mask) { - - int outfitColorId = 0; - if(mask == SpriteMaskYellow) - outfitColorId = m_outfit.head; - else if(mask == SpriteMaskRed) - outfitColorId = m_outfit.body; - else if(mask == SpriteMaskGreen) - outfitColorId = m_outfit.legs; - else if(mask == SpriteMaskBlue) - outfitColorId = m_outfit.feet; - - g_graphics.bindColor(OutfitColors[outfitColorId]); - internalDraw(x, y, 1, m_direction, 0, 0, anim, (SpriteMask)mask); - } + for(int ydiv = 0; ydiv < attributes.ydiv; ydiv++) { + + // continue if we dont have this addon. + if(ydiv > 0 && !(m_outfit.addons & (1 << (ydiv-1)))) + continue; + + // draw white item + internalDraw(x, y, 0, m_direction, ydiv, 0, anim); + + // draw mask if exists + if(attributes.blendframes > 1) { + g_graphics.bindBlendFunc(BLEND_COLORIZING); - g_graphics.bindBlendFunc(BLEND_NORMAL); - g_graphics.bindColor(Color::white); + for(int mask = 0; mask < 4; ++mask) { + + int outfitColorId = 0; + if(mask == SpriteMaskYellow) + outfitColorId = m_outfit.head; + else if(mask == SpriteMaskRed) + outfitColorId = m_outfit.body; + else if(mask == SpriteMaskGreen) + outfitColorId = m_outfit.legs; + else if(mask == SpriteMaskBlue) + outfitColorId = m_outfit.feet; + + g_graphics.bindColor(OutfitColors[outfitColorId]); + internalDraw(x, y, 1, m_direction, ydiv, 0, anim, (SpriteMask)mask); + } + + g_graphics.bindBlendFunc(BLEND_NORMAL); + g_graphics.bindColor(Color::white); + } } } diff --git a/src/otclient/core/item.cpp b/src/otclient/core/item.cpp index 09c651b9..76ea0a68 100644 --- a/src/otclient/core/item.cpp +++ b/src/otclient/core/item.cpp @@ -1,7 +1,6 @@ #include "item.h" #include "datmanager.h" #include "spritemanager.h" -#include #include "thing.h" Item::Item() : Thing(THING_ITEM) @@ -15,9 +14,32 @@ void Item::draw(int x, int y) int xdiv = 0, ydiv = 0, zdiv = 0, anim = 0; - if(attributes.group == THING_GROUP_SPLASH || attributes.group == THING_GROUP_FLUID || attributes.stackable) { - //cDivX = subType % itemAttributes->xdiv; - //cDivY = subType / itemAttributes->xdiv; + if(attributes.group == THING_GROUP_SPLASH || attributes.group == THING_GROUP_FLUID) { + //xdiv = m_count % attributes.xdiv; + //ydiv = m_count / attributes.ydiv; + + } + else if(attributes.stackable) { + if(m_count < 5) { + xdiv = m_count-1; + ydiv = 0; + } + else if(m_count < 10) { + xdiv = 0; + ydiv = 1; + } + else if(m_count < 25) { + xdiv = 1; + ydiv = 1; + } + else if(m_count < 50) { + xdiv = 2; + ydiv = 1; + } + else if(m_count <= 100) { + xdiv = 3; + ydiv = 1; + } } else if(!attributes.moveable) { xdiv = m_position.x % attributes.xdiv; diff --git a/src/otclient/core/map.cpp b/src/otclient/core/map.cpp index e709e0d4..630c565b 100644 --- a/src/otclient/core/map.cpp +++ b/src/otclient/core/map.cpp @@ -40,7 +40,7 @@ void Map::draw(const Rect& rect) for(int jz = 6; jz >= 0; --jz) { Position coverPos = Position(playerPos.x+(7-jz)-1, playerPos.y+(7-jz)-1, jz); if(const TilePtr& tile = m_tiles[coverPos]) { - if(tile->getStackSize() > 0 && jz < playerPos.z) { + if(tile->getStackSize(3) > 0 && jz < playerPos.z) { drawFloorStop = jz; break; } @@ -99,7 +99,7 @@ void Map::draw(const Rect& rect) } } -void Map::addThing(ThingPtr thing, uint8 stackpos) +void Map::addThing(ThingPtr thing, int stackpos) { if(!thing) return; @@ -115,7 +115,7 @@ void Map::addThing(ThingPtr thing, uint8 stackpos) m_creatures[thing->getId()] = creature; } -ThingPtr Map::getThing(const Position& pos, uint8 stackpos) +ThingPtr Map::getThing(const Position& pos, int stackpos) { if(const TilePtr& tile = m_tiles[pos]) { return tile->getThing(stackpos); @@ -123,7 +123,7 @@ ThingPtr Map::getThing(const Position& pos, uint8 stackpos) return ThingPtr(); } -void Map::removeThing(const Position& pos, uint8 stackpos) +void Map::removeThing(const Position& pos, int stackpos) { if(TilePtr& tile = m_tiles[pos]) { tile->removeThing(stackpos); diff --git a/src/otclient/core/map.h b/src/otclient/core/map.h index 8009618c..0cbeddbb 100644 --- a/src/otclient/core/map.h +++ b/src/otclient/core/map.h @@ -10,9 +10,9 @@ class Map public: void draw(const Rect& rect); - void addThing(ThingPtr thing, uint8 stackpos = 0); - ThingPtr getThing(const Position& pos, uint8 stackpos); - void removeThing(const Position& pos, uint8 stackpos); + void addThing(ThingPtr thing, int stackpos = -1); + ThingPtr getThing(const Position& pos, int stackpos); + void removeThing(const Position& pos, int stackpos); void removeThingByPtr(ThingPtr thing); void clean(); diff --git a/src/otclient/core/tile.cpp b/src/otclient/core/tile.cpp index 843c8dd7..a5ec7651 100644 --- a/src/otclient/core/tile.cpp +++ b/src/otclient/core/tile.cpp @@ -72,8 +72,9 @@ void Tile::draw(int x, int y) } } -void Tile::addThing(ThingPtr thing, uint8 stackpos) +void Tile::addThing(ThingPtr thing, int stackpos) { + // TODO: rework this. that -1 sucks if(!thing) return; @@ -89,8 +90,13 @@ void Tile::addThing(ThingPtr thing, uint8 stackpos) else { if(thingAttributes.alwaysOnTop) m_itemsTop.push_back(thing); - else - m_itemsBottom.push_back(thing); + else { + if(stackpos == -1) + m_itemsBottom.push_back(thing); + else { + m_itemsBottom.insert(m_itemsBottom.begin()+(stackpos-getStackSize(2)), thing); + } + } } } else if(thing->asCreature()) { @@ -101,7 +107,7 @@ void Tile::addThing(ThingPtr thing, uint8 stackpos) } } -ThingPtr Tile::getThing(uint8 stackpos) +ThingPtr Tile::getThing(unsigned int stackpos) { if(stackpos == 0) return m_ground; @@ -121,7 +127,7 @@ ThingPtr Tile::getThing(uint8 stackpos) return ThingPtr(); } -void Tile::removeThing(uint8 stackpos) +void Tile::removeThing(unsigned int stackpos) { if(stackpos == 0) { m_ground.reset(); @@ -205,13 +211,20 @@ void Tile::clean() m_effects.clear(); } -int Tile::getStackSize() +int Tile::getStackSize(int stop) { - int ret = 0; - if(m_ground) - ret++; - ret += m_itemsBottom.size(); - ret += m_creatures.size(); + int ret = m_ground ? 1 : 0; + if(stop == 0) + return ret; + ret += m_itemsTop.size(); + if(stop == 1) + return ret; + + ret += m_creatures.size(); + if(stop == 2) + return ret; + + ret += m_itemsBottom.size(); return ret; } diff --git a/src/otclient/core/tile.h b/src/otclient/core/tile.h index 7c196585..c81cb235 100644 --- a/src/otclient/core/tile.h +++ b/src/otclient/core/tile.h @@ -11,16 +11,16 @@ public: void draw(int x, int y); - void addThing(ThingPtr thing, uint8 stackpos); - ThingPtr getThing(uint8 stackpos); - void removeThing(uint8 stackpos); + void addThing(ThingPtr thing, int stackpos); + ThingPtr getThing(unsigned int stackpos); + void removeThing(unsigned int stackpos); void removeThingByPtr(ThingPtr thing); void clean(); bool hasGround() { return (!!m_ground); } - int getStackSize(); + int getStackSize(int stop); std::deque getCreatures() { return m_creatures; } int getDrawNextOffset() { return m_drawNextOffset; } diff --git a/src/otclient/net/protocolgameparse.cpp b/src/otclient/net/protocolgameparse.cpp index 2695260f..0d4a91ef 100644 --- a/src/otclient/net/protocolgameparse.cpp +++ b/src/otclient/net/protocolgameparse.cpp @@ -923,7 +923,7 @@ void ProtocolGame::setTileDescription(InputMessage& msg, Position position) ThingPtr thing = internalGetThing(msg); if(thing) thing->setPosition(position); - g_map.addThing(thing, stackpos); + g_map.addThing(thing); } stackpos++; }