From 7ffb7603683bfd652fd89edf683a864cd1879532 Mon Sep 17 00:00:00 2001 From: niczkx Date: Sun, 15 Jul 2012 21:12:03 +0300 Subject: [PATCH 1/3] trolo --- src/otclient/houses.cpp | 2 -- src/otclient/towns.cpp | 2 -- 2 files changed, 4 deletions(-) diff --git a/src/otclient/houses.cpp b/src/otclient/houses.cpp index f7e93e33..08dbc78b 100644 --- a/src/otclient/houses.cpp +++ b/src/otclient/houses.cpp @@ -22,8 +22,6 @@ #include "map.h" -Houses g_houses; - House::House(uint32 hId, const std::string &name, const Position &pos) : m_id(hId), m_name(name) { diff --git a/src/otclient/towns.cpp b/src/otclient/towns.cpp index 1f84dabb..6faee33d 100644 --- a/src/otclient/towns.cpp +++ b/src/otclient/towns.cpp @@ -22,8 +22,6 @@ #include "towns.h" -Towns g_towns; - Town::Town(uint32 tid, const std::string& name, const Position& pos) : m_id(tid), m_name(name) { From 98c42404460c7d25ac5f2187e2032d670290d8a5 Mon Sep 17 00:00:00 2001 From: Eduardo Bart Date: Sun, 15 Jul 2012 02:46:56 -0300 Subject: [PATCH 2/3] Changes for the mapeditor --- src/framework/ui/uiwidget.cpp | 2 ++ src/otclient/item.cpp | 7 +++++ src/otclient/item.h | 1 + src/otclient/luafunctions.cpp | 1 + src/otclient/map.cpp | 8 ++--- src/otclient/protocolgameparse.cpp | 4 +-- src/otclient/tile.cpp | 48 +++++++++++++++++++++++------- src/otclient/tile.h | 1 + 8 files changed, 56 insertions(+), 16 deletions(-) diff --git a/src/framework/ui/uiwidget.cpp b/src/framework/ui/uiwidget.cpp index 3f98cefa..0a7165a1 100644 --- a/src/framework/ui/uiwidget.cpp +++ b/src/framework/ui/uiwidget.cpp @@ -815,10 +815,12 @@ void UIWidget::setLayout(const UILayoutPtr& layout) bool UIWidget::setRect(const Rect& rect) { + /* if(rect.width() > 8192 || rect.height() > 8192) { g_logger.error(stdext::format("attempt to set huge rect size (%s) for %s", stdext::to_string(rect), m_id)); return false; } + */ // only update if the rect really changed Rect oldRect = m_rect; if(rect == oldRect) diff --git a/src/otclient/item.cpp b/src/otclient/item.cpp index 08cd4a26..c4e9de30 100644 --- a/src/otclient/item.cpp +++ b/src/otclient/item.cpp @@ -293,3 +293,10 @@ bool Item::isMoveable() "Invalid dat type for item %d", m_id)); return false; } + +ItemPtr Item::clone() +{ + ItemPtr item = ItemPtr(new Item); + *(item.get()) = *this; + return item; +} diff --git a/src/otclient/item.h b/src/otclient/item.h index 0f22bd82..c68a879c 100644 --- a/src/otclient/item.h +++ b/src/otclient/item.h @@ -96,6 +96,7 @@ public: uint8 getDoorId() { return m_doorId; } bool isValid(); + ItemPtr clone(); ItemPtr asItem() { return std::static_pointer_cast(shared_from_this()); } bool isItem() { return true; } diff --git a/src/otclient/luafunctions.cpp b/src/otclient/luafunctions.cpp index 2df9dd06..8d63edc5 100644 --- a/src/otclient/luafunctions.cpp +++ b/src/otclient/luafunctions.cpp @@ -314,6 +314,7 @@ void OTClient::registerLuaFunctions() g_lua.registerClass(); g_lua.bindClassStaticFunction("create", &Item::create); + g_lua.bindClassMemberFunction("clone", &Item::clone); g_lua.bindClassMemberFunction("setCount", &Item::setCount); g_lua.bindClassMemberFunction("getCount", &Item::getCount); g_lua.bindClassMemberFunction("getId", &Item::getId); diff --git a/src/otclient/map.cpp b/src/otclient/map.cpp index 2a9d7b32..49af4a55 100644 --- a/src/otclient/map.cpp +++ b/src/otclient/map.cpp @@ -218,7 +218,7 @@ void Map::loadOtbm(const std::string& fileName) } else if(item->isDoor()) house->addDoor(item->getDoorId(), pos); } else if(tile) - addThing(item, pos, 255); + addThing(item, pos); else if(item->isGround()) ground = item; else @@ -438,7 +438,7 @@ bool Map::loadOtcm(const std::string& fileName) item->setCountOrSubType(countOrSubType); if(item->isValid()) - addThing(item, pos, 255); + addThing(item, pos); } } @@ -632,7 +632,7 @@ bool Map::removeThing(const ThingPtr& thing) m_staticTexts.erase(it); return true; } - } else if(TilePtr tile = thing->getTile()) + } else if(const TilePtr& tile = thing->getTile()) return tile->removeThing(thing); return false; @@ -651,7 +651,7 @@ TilePtr Map::createTileEx(const Position& pos, const Items&... items) TilePtr tile = getOrCreateTile(pos); auto vec = {items...}; for (auto it : vec) - addThing(it, pos, 255); + addThing(it, pos); return tile; } diff --git a/src/otclient/protocolgameparse.cpp b/src/otclient/protocolgameparse.cpp index c8e27e9d..58d3002e 100644 --- a/src/otclient/protocolgameparse.cpp +++ b/src/otclient/protocolgameparse.cpp @@ -512,7 +512,7 @@ void ProtocolGame::parseCreatureMove(const InputMessagePtr& msg) if(!g_map.removeThing(thing)) g_logger.traceError("could not remove thing"); - g_map.addThing(thing, newPos); + g_map.addThing(thing, newPos, -1); } void ProtocolGame::parseOpenContainer(const InputMessagePtr& msg) @@ -1306,7 +1306,7 @@ void ProtocolGame::setTileDescription(const InputMessagePtr& msg, Position posit g_logger.traceError(stdext::format("too many things, stackpos=%d, pos=%s", stackPos, stdext::to_string(position))); ThingPtr thing = getThing(msg); - g_map.addThing(thing, position, -1); + g_map.addThing(thing, position, -2); } stackPos++; } diff --git a/src/otclient/tile.cpp b/src/otclient/tile.cpp index 85aa0871..b0ad32bc 100644 --- a/src/otclient/tile.cpp +++ b/src/otclient/tile.cpp @@ -163,14 +163,15 @@ ThingPtr Tile::addThing(const ThingPtr& thing, int stackPos) return nullptr; } + // the items stackpos follows this order: + // 0 - ground + // 1 - ground borders + // 2 - bottom (walls) + // 3 - on top (doors) + // 4 - creatures, from top to bottom + // 5 - items, from top to bottom if(stackPos < 0) { - // the items stackpos follows this order: - // 0 - ground - // 1 - ground borders - // 2 - bottom (walls) - // 3 - on top (doors) - // 4 - creatures, from top to bottom - // 5 - items, from top to bottom + bool prepend = (stackPos == -2); stackPos = 0; int priority = thing->getStackPriority(); for(stackPos = 0; stackPos < (int)m_things.size(); ++stackPos) { @@ -180,7 +181,7 @@ ThingPtr Tile::addThing(const ThingPtr& thing, int stackPos) if(priority == 4 && otherPriority == 4) break; } - if(otherPriority > priority) + if((prepend && otherPriority > priority) || (!prepend && otherPriority >= priority)) break; } } else if(stackPos > (int)m_things.size()) @@ -233,6 +234,14 @@ ThingPtr Tile::getThing(int stackPos) return nullptr; } +EffectPtr Tile::getEffect(uint16 id) +{ + for(const EffectPtr& effect : m_effects) + if(effect->getId() == id) + return effect; + return nullptr; +} + bool Tile::hasThing(const ThingPtr& thing) { return std::find(m_things.begin(), m_things.end(), thing) != m_things.end(); @@ -246,11 +255,30 @@ int Tile::getThingStackpos(const ThingPtr& thing) return -1; } -ThingPtr Tile::getTopThing() +ThingPtr Tile:: getTopThing() { + for(const ThingPtr& thing : m_things) { + if(!thing->isGround() && !thing->isGroundBorder() && !thing->isOnBottom() && !thing->isOnTop() && !thing->isCreature()) + return thing; + } + for(const ThingPtr& thing : m_things) { + if(!thing->isGround() && !thing->isGroundBorder() && !thing->isOnBottom() && !thing->isOnTop()) + return thing; + } + for(const ThingPtr& thing : m_things) { + if(!thing->isGround() && !thing->isGroundBorder() && !thing->isOnBottom()) + return thing; + } + for(const ThingPtr& thing : m_things) { + if(!thing->isGround() && !thing->isGroundBorder()) + return thing; + } + for(const ThingPtr& thing : m_things) { + if(!thing->isGround()) + return thing; + } if(isEmpty()) return nullptr; - return m_things[m_things.size() - 1]; } diff --git a/src/otclient/tile.h b/src/otclient/tile.h index c3936234..a2bc9d46 100644 --- a/src/otclient/tile.h +++ b/src/otclient/tile.h @@ -66,6 +66,7 @@ public: ThingPtr addThing(const ThingPtr& thing, int stackPos = -1); bool removeThing(ThingPtr thing); ThingPtr getThing(int stackPos); + EffectPtr getEffect(uint16 id); bool hasThing(const ThingPtr& thing); int getThingStackpos(const ThingPtr& thing); ThingPtr getTopThing(); From 1b0c527ad6eed22ae82c41bd60edc3036f6130e3 Mon Sep 17 00:00:00 2001 From: Eduardo Bart Date: Sun, 15 Jul 2012 03:16:40 -0300 Subject: [PATCH 3/3] Fix Thing::getTopThing --- src/framework/luaengine/luaobject.h | 2 ++ src/otclient/tile.cpp | 22 +++------------------- 2 files changed, 5 insertions(+), 19 deletions(-) diff --git a/src/framework/luaengine/luaobject.h b/src/framework/luaengine/luaobject.h index e7722dad..dd694148 100644 --- a/src/framework/luaengine/luaobject.h +++ b/src/framework/luaengine/luaobject.h @@ -82,6 +82,8 @@ public: LuaObjectPtr asLuaObject() { return shared_from_this(); } + void operator=(const LuaObject& other) { } + private: int m_fieldsTableRef; int m_metatableRef; diff --git a/src/otclient/tile.cpp b/src/otclient/tile.cpp index b0ad32bc..7c58beff 100644 --- a/src/otclient/tile.cpp +++ b/src/otclient/tile.cpp @@ -171,9 +171,9 @@ ThingPtr Tile::addThing(const ThingPtr& thing, int stackPos) // 4 - creatures, from top to bottom // 5 - items, from top to bottom if(stackPos < 0) { - bool prepend = (stackPos == -2); stackPos = 0; int priority = thing->getStackPriority(); + bool prepend = (stackPos == -2 || priority <= 3); for(stackPos = 0; stackPos < (int)m_things.size(); ++stackPos) { int otherPriority = m_things[stackPos]->getStackPriority(); if(!g_game.getFeature(Otc::GameReverseCreatureStack)) { @@ -257,28 +257,12 @@ int Tile::getThingStackpos(const ThingPtr& thing) ThingPtr Tile:: getTopThing() { + if(isEmpty()) + return nullptr; for(const ThingPtr& thing : m_things) { if(!thing->isGround() && !thing->isGroundBorder() && !thing->isOnBottom() && !thing->isOnTop() && !thing->isCreature()) return thing; } - for(const ThingPtr& thing : m_things) { - if(!thing->isGround() && !thing->isGroundBorder() && !thing->isOnBottom() && !thing->isOnTop()) - return thing; - } - for(const ThingPtr& thing : m_things) { - if(!thing->isGround() && !thing->isGroundBorder() && !thing->isOnBottom()) - return thing; - } - for(const ThingPtr& thing : m_things) { - if(!thing->isGround() && !thing->isGroundBorder()) - return thing; - } - for(const ThingPtr& thing : m_things) { - if(!thing->isGround()) - return thing; - } - if(isEmpty()) - return nullptr; return m_things[m_things.size() - 1]; }