diff options
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | src/beingmanager.cpp | 27 | ||||
-rw-r--r-- | src/beingmanager.h | 2 | ||||
-rw-r--r-- | src/net/beinghandler.cpp | 41 |
4 files changed, 40 insertions, 36 deletions
@@ -1,3 +1,9 @@ +2007-10-18 Guillaume Melquiond <guillaume.melquiond@gmail.com> + + * src/beingmanager.h, src/beingmanager.cpp, src/net/beinghandler.cpp: + Removed guess of being type from class number. Factored handler for new + beings. + 2007-10-15 Bjørn Lindeijer <bjorn@lindeijer.nl> * src/gui/viewport.h, src/gui/viewport.cpp: Put drawing of debug path diff --git a/src/beingmanager.cpp b/src/beingmanager.cpp index a5be17d2..56865841 100644 --- a/src/beingmanager.cpp +++ b/src/beingmanager.cpp @@ -21,6 +21,8 @@ * $Id$ */ +#include <cassert> + #include "beingmanager.h" #include "localplayer.h" @@ -28,6 +30,7 @@ #include "npc.h" #include "player.h" +#include "net/protocol.h" #include "utils/dtor.h" class FindBeingFunctor @@ -59,18 +62,24 @@ void BeingManager::setPlayer(LocalPlayer *player) mBeings.push_back(player); } -Being* BeingManager::createBeing(Uint16 id, Uint16 job) +Being* BeingManager::createBeing(int id, int type, int subtype) { Being *being; - if (job < 10) - being = new Player(id, job, mMap); - else if (job >= 100 & job < 200) - being = new NPC(id, job, mMap); - else if (job >= 1000 && job < 1200) - being = new Monster(id, job, mMap); - else - being = new Being(id, job, mMap); + switch (type) + { + case OBJECT_PLAYER: + being = new Player(id, subtype, mMap); + break; + case OBJECT_NPC: + being = new NPC(id, subtype, mMap); + break; + case OBJECT_MONSTER: + being = new Monster(id, subtype, mMap); + break; + default: + assert(false); + } mBeings.push_back(being); return being; diff --git a/src/beingmanager.h b/src/beingmanager.h index f97a23f4..81f85622 100644 --- a/src/beingmanager.h +++ b/src/beingmanager.h @@ -48,7 +48,7 @@ class BeingManager /** * Create a being and add it to the list of beings. */ - Being* createBeing(Uint16 id, Uint16 job); + Being *createBeing(int id, int type, int subtype); /** * Remove a Being. diff --git a/src/net/beinghandler.cpp b/src/net/beinghandler.cpp index b88d443e..020d24af 100644 --- a/src/net/beinghandler.cpp +++ b/src/net/beinghandler.cpp @@ -449,18 +449,18 @@ static void handleLooks(Being *being, MessageIn &msg) void BeingHandler::handleBeingEnterMessage(MessageIn &msg) { - int type = msg.readByte(); // type + int type = msg.readByte(); int id = msg.readShort(); Being::Action action = (Being::Action)msg.readByte(); - Uint16 px = msg.readShort(); - Uint16 py = msg.readShort(); + int px = msg.readShort(); + int py = msg.readShort(); + Being *being; switch (type) { case OBJECT_PLAYER: { std::string name = msg.readString(); - Being *being; if (player_node->getName() == name) { being = player_node; @@ -468,41 +468,30 @@ BeingHandler::handleBeingEnterMessage(MessageIn &msg) } else { - being = beingManager->createBeing(id, 0); + being = beingManager->createBeing(id, type, 0); being->setName(name); } being->setHairStyle(msg.readByte()); being->setHairColor(msg.readByte()); being->setSex(msg.readByte()); - being->mX = px; - being->mY = py; - being->setDestination(px, py); - being->setAction(action); handleLooks(being, msg); } break; case OBJECT_MONSTER: - { - int monsterId = msg.readShort(); - Being *being; - being = beingManager->createBeing(id, monsterId); - being->mX = px; - being->mY = py; - being->setDestination(px, py); - being->setAction(action); - } break; - case OBJECT_NPC: { - int npcId = msg.readShort(); - Being *being; - being = beingManager->createBeing(id, npcId); - being->mX = px; - being->mY = py; - being->setDestination(px, py); - being->setAction(action); + int subtype = msg.readShort(); + being = beingManager->createBeing(id, type, subtype); } break; + + default: + return; } + + being->mX = px; + being->mY = py; + being->setDestination(px, py); + being->setAction(action); } void BeingHandler::handleBeingLeaveMessage(MessageIn &msg) |