summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-02-11 14:58:14 +0300
committerAndrei Karas <akaras@inbox.ru>2012-02-11 14:58:14 +0300
commitc14086d6a08fb2ea644eec9fafa0374604c98991 (patch)
tree29a00277b215a32e019fd06cab4b9ac709ac775c
parent7e19d626711ecf70035b32ee99098fc7fc3419fe (diff)
downloadmanaverse-c14086d6a08fb2ea644eec9fafa0374604c98991.tar.gz
manaverse-c14086d6a08fb2ea644eec9fafa0374604c98991.tar.bz2
manaverse-c14086d6a08fb2ea644eec9fafa0374604c98991.tar.xz
manaverse-c14086d6a08fb2ea644eec9fafa0374604c98991.zip
Add relative pixel based position to item drops (floor items).
-rw-r--r--src/actorspritemanager.cpp5
-rw-r--r--src/actorspritemanager.h3
-rw-r--r--src/flooritem.cpp21
-rw-r--r--src/flooritem.h12
-rw-r--r--src/net/ea/itemhandler.cpp37
-rw-r--r--src/net/ea/itemhandler.h4
-rw-r--r--src/net/tmwa/itemhandler.cpp7
7 files changed, 46 insertions, 43 deletions
diff --git a/src/actorspritemanager.cpp b/src/actorspritemanager.cpp
index fa6d49d38..89a592005 100644
--- a/src/actorspritemanager.cpp
+++ b/src/actorspritemanager.cpp
@@ -240,10 +240,11 @@ Being *ActorSpriteManager::createBeing(int id, ActorSprite::Type type,
}
FloorItem *ActorSpriteManager::createItem(int id, int itemId, int x, int y,
- int amount, unsigned char color)
+ int amount, unsigned char color,
+ int subX, int subY)
{
FloorItem *floorItem = new FloorItem(id, itemId, x, y,
- mMap, amount, color);
+ mMap, amount, color, subX, subY);
mActors.insert(floorItem);
return floorItem;
diff --git a/src/actorspritemanager.h b/src/actorspritemanager.h
index a78e3ad49..d30bad426 100644
--- a/src/actorspritemanager.h
+++ b/src/actorspritemanager.h
@@ -63,7 +63,8 @@ class ActorSpriteManager: public ConfigListener
* Create a FloorItem and add it to the list of ActorSprites.
*/
FloorItem *createItem(int id, int itemId, int x, int y,
- int amount, unsigned char color);
+ int amount, unsigned char color,
+ int subX, int subY);
/**
* Destroys the given ActorSprite at the end of
diff --git a/src/flooritem.cpp b/src/flooritem.cpp
index 6e4926f2e..111019546 100644
--- a/src/flooritem.cpp
+++ b/src/flooritem.cpp
@@ -38,13 +38,8 @@
#include "debug.h"
-FloorItem::FloorItem(int id,
- int itemId,
- int x,
- int y,
- Map *map,
- int amount,
- unsigned char color):
+FloorItem::FloorItem(int id, int itemId, int x, int y, Map *map, int amount,
+ unsigned char color, int subX, int subY):
ActorSprite(id),
mItemId(itemId),
mX(x),
@@ -60,16 +55,8 @@ FloorItem::FloorItem(int id,
setMap(map);
if (map)
{
- // TODO: Eventually, we probably should fix all sprite offsets so that
- // these translations aren't necessary anymore. The sprites know
- // best where their base point should be.
- mPos.x = static_cast<float>(x * map->getTileWidth() + 16);
-#ifdef MANASERV_SUPPORT
- mPos.y = static_cast<float>(y * map->getTileHeight() +
- ((Net::getNetworkType() == ServerInfo::MANASERV) ? 15 : 32));
-#else
- mPos.y = static_cast<float>(y * map->getTileHeight() + 32);
-#endif
+ mPos.x = static_cast<float>(x * map->getTileWidth() + subX);
+ mPos.y = static_cast<float>(y * map->getTileHeight() + subY);
}
else
{
diff --git a/src/flooritem.h b/src/flooritem.h
index 95427c252..1f3126078 100644
--- a/src/flooritem.h
+++ b/src/flooritem.h
@@ -42,14 +42,12 @@ class FloorItem : public ActorSprite
* @param y the y position in tiles
* @param map the map this item is on
* @param amount the item amount
+ * @param color the item color
+ * @param subX the x pixel relative position
+ * @param subY the y pixel relative position
*/
- FloorItem(int id,
- int itemId,
- int x,
- int y,
- Map *map,
- int amount,
- unsigned char color);
+ FloorItem(int id, int itemId, int x, int y, Map *map, int amount,
+ unsigned char color, int subX, int subY);
Type getType() const
{ return FLOOR_ITEM; }
diff --git a/src/net/ea/itemhandler.cpp b/src/net/ea/itemhandler.cpp
index e08fe2cd1..7a6ee2743 100644
--- a/src/net/ea/itemhandler.cpp
+++ b/src/net/ea/itemhandler.cpp
@@ -35,28 +35,39 @@ ItemHandler::ItemHandler()
{
}
-void ItemHandler::processItemVisible(Net::MessageIn &msg, bool isDrop)
+void ItemHandler::processItemVisible(Net::MessageIn &msg)
{
int id = msg.readInt32();
int itemId = msg.readInt16();
unsigned char identify = msg.readInt8(); // identify flag
int x = msg.readInt16();
int y = msg.readInt16();
- int amount1 = msg.readInt16();
- int amount2 = msg.readInt16();
+ int amount = msg.readInt16();
+ int subX = msg.readInt8() + 16 - 8;
+ int subY = msg.readInt8() + 32 - 8;
if (actorSpriteManager)
{
- if (!isDrop)
- {
- actorSpriteManager->createItem(id, itemId,
- x, y, amount1, identify);
- }
- else
- {
- actorSpriteManager->createItem(id, itemId,
- x, y, amount2, identify);
- }
+ actorSpriteManager->createItem(id, itemId,
+ x, y, amount, identify, subX, subY);
+ }
+}
+
+void ItemHandler::processItemDropped(Net::MessageIn &msg)
+{
+ int id = msg.readInt32();
+ int itemId = msg.readInt16();
+ unsigned char identify = msg.readInt8(); // identify flag
+ int x = msg.readInt16();
+ int y = msg.readInt16();
+ int subX = msg.readInt8() + 16 - 8;
+ int subY = msg.readInt8() + 32 - 8;
+ int amount = msg.readInt16();
+
+ if (actorSpriteManager)
+ {
+ actorSpriteManager->createItem(id, itemId,
+ x, y, amount, identify, subX, subY);
}
}
diff --git a/src/net/ea/itemhandler.h b/src/net/ea/itemhandler.h
index 1d0747c61..d5c268d2e 100644
--- a/src/net/ea/itemhandler.h
+++ b/src/net/ea/itemhandler.h
@@ -34,9 +34,11 @@ class ItemHandler
public:
ItemHandler();
- void processItemVisible(Net::MessageIn &msg, bool isDrop);
+ void processItemVisible(Net::MessageIn &msg);
void processItemRemove(Net::MessageIn &msg);
+
+ void processItemDropped(Net::MessageIn &msg);
};
} // namespace Ea
diff --git a/src/net/tmwa/itemhandler.cpp b/src/net/tmwa/itemhandler.cpp
index ce03044c7..d84d2f38d 100644
--- a/src/net/tmwa/itemhandler.cpp
+++ b/src/net/tmwa/itemhandler.cpp
@@ -48,9 +48,12 @@ void ItemHandler::handleMessage(Net::MessageIn &msg)
switch (msg.getId())
{
case SMSG_ITEM_VISIBLE:
+ processItemVisible(msg);
+ break;
+
case SMSG_ITEM_DROPPED:
- processItemVisible(msg, msg.getId() == SMSG_ITEM_DROPPED);
- break;
+ processItemDropped(msg);
+ break;
case SMSG_ITEM_REMOVE:
processItemRemove(msg);