summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--src/net/itemhandler.cpp42
-rw-r--r--src/net/protocol.h3
-rw-r--r--src/resources/mapreader.cpp1
4 files changed, 27 insertions, 25 deletions
diff --git a/ChangeLog b/ChangeLog
index 3cabf4b4..d2cc233c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2007-01-03 Guillaume Melquiond <guillaume.melquiond@gmail.com>
+
+ * src/resources/mapreader.cpp: Fixed memory leak on error.
+ * src/net/protocol.h, src/net/itemhandler.cpp: Added support for items
+ dropped on map.
+
2007-01-01 Guillaume Melquiond <guillaume.melquiond@gmail.com>
* src/being.h, src/being.cpp, src/game.cpp: Made getSpriteDirection
diff --git a/src/net/itemhandler.cpp b/src/net/itemhandler.cpp
index 2961f71b..fffb3a45 100644
--- a/src/net/itemhandler.cpp
+++ b/src/net/itemhandler.cpp
@@ -32,9 +32,7 @@
ItemHandler::ItemHandler()
{
static const Uint16 _messages[] = {
- SMSG_ITEM_VISIBLE,
- SMSG_ITEM_DROPPED,
- SMSG_ITEM_REMOVE,
+ GPMSG_ITEMS,
0
};
handledMessages = _messages;
@@ -42,28 +40,26 @@ ItemHandler::ItemHandler()
void ItemHandler::handleMessage(MessageIn &msg)
{
- Uint32 id;
- Uint16 x, y;
- Sint16 itemId;
-
switch (msg.getId())
{
- case SMSG_ITEM_VISIBLE:
- case SMSG_ITEM_DROPPED:
- id = msg.readLong();
- itemId = msg.readShort();
- msg.readByte(); // identify flag
- x = msg.readShort();
- y = msg.readShort();
-
- floorItemManager->create(id, itemId, x, y, engine->getCurrentMap());
- break;
+ case GPMSG_ITEMS:
+ {
+ while (msg.getUnreadLength())
+ {
+ int itemId = msg.readShort();
+ int x = msg.readShort();
+ int y = msg.readShort();
+ int id = (x << 16) | y; // dummy id
- case SMSG_ITEM_REMOVE:
- FloorItem *item;
- item = floorItemManager->findById(msg.readLong());
- if (item)
- floorItemManager->destroy(item);
- break;
+ if (itemId)
+ {
+ floorItemManager->create(id, itemId, x / 32, y / 32, engine->getCurrentMap());
+ }
+ else if (FloorItem *item = floorItemManager->findById(id))
+ {
+ floorItemManager->destroy(item);
+ }
+ }
+ } break;
}
}
diff --git a/src/net/protocol.h b/src/net/protocol.h
index de908c53..685d3161 100644
--- a/src/net/protocol.h
+++ b/src/net/protocol.h
@@ -155,6 +155,7 @@ enum {
GPMSG_BEING_LEAVE = 0x0201, // W being id
PGMSG_WALK = 0x0260, // W*2 destination
GPMSG_BEINGS_MOVE = 0x0280, // { W being id, B flags [, C position] [, W*2 destination] }*
+ GPMSG_ITEMS = 0x0281, // { W item id, W*2 position }*
PGMSG_ATTACK = 0x0290, // B direction
GPMSG_BEING_ATTACK = 0x0291, // W being id
PGMSG_SAY = 0x02A0, // S text
@@ -163,7 +164,7 @@ enum {
GPMSG_USE_RESPONSE = 0x0301, // B error
PGMSG_EQUIP = 0x0302, // L item id, B slot
GPMSG_EQUIP_RESPONSE = 0x0303, // B error
- GPMSG_BEINGS_DAMAGE = 0x0310, // { W being id, W ammount }*
+ GPMSG_BEINGS_DAMAGE = 0x0310, // { W being id, W amount }*
// Chat
CPMSG_ERROR = 0x0401, // B error
diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp
index 09a6eb74..4569ced7 100644
--- a/src/resources/mapreader.cpp
+++ b/src/resources/mapreader.cpp
@@ -181,7 +181,6 @@ MapReader::readMap(const std::string &filename)
if (!node || !xmlStrEqual(node->name, BAD_CAST "map")) {
logger->log("Error: Not a map file (%s)!", filename.c_str());
- return NULL;
}
else
{