diff options
author | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2008-10-09 19:42:13 +0000 |
---|---|---|
committer | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2008-10-09 19:42:13 +0000 |
commit | 3fe1772b1e00344365e3cf8204225be19925b9e5 (patch) | |
tree | 0f66dddac8e14787096c01368611efa53f453134 /src/net/beinghandler.cpp | |
parent | 8cc0423b0c0aaa5dd9e91f673a691e5e634988c1 (diff) | |
download | mana-3fe1772b1e00344365e3cf8204225be19925b9e5.tar.gz mana-3fe1772b1e00344365e3cf8204225be19925b9e5.tar.bz2 mana-3fe1772b1e00344365e3cf8204225be19925b9e5.tar.xz mana-3fe1772b1e00344365e3cf8204225be19925b9e5.zip |
Merged the movement branch into trunk
I consider this the only way forward. In my tests this code isn't actually
doing worse than what was there before. Of course some cases are a bit broken,
and I'm open to any kind of feedback so that we can fix those issues.
Diffstat (limited to 'src/net/beinghandler.cpp')
-rw-r--r-- | src/net/beinghandler.cpp | 370 |
1 files changed, 25 insertions, 345 deletions
diff --git a/src/net/beinghandler.cpp b/src/net/beinghandler.cpp index b1c502e1..7e37aa27 100644 --- a/src/net/beinghandler.cpp +++ b/src/net/beinghandler.cpp @@ -48,18 +48,6 @@ const int EMOTION_TIME = 150; /**< Duration of emotion icon */ BeingHandler::BeingHandler() { static const Uint16 _messages[] = { - //SMSG_BEING_VISIBLE, - //SMSG_BEING_MOVE, - //SMSG_BEING_REMOVE, - //SMSG_BEING_ACTION, - //SMSG_BEING_LEVELUP, - //SMSG_BEING_EMOTION, - //SMSG_BEING_CHANGE_LOOKS, - //SMSG_BEING_NAME_RESPONSE, - //SMSG_PLAYER_UPDATE_1, - //SMSG_PLAYER_UPDATE_2, - //SMSG_PLAYER_MOVE, - //0x0119, GPMSG_BEING_ATTACK, GPMSG_BEING_ENTER, GPMSG_BEING_LEAVE, @@ -74,15 +62,6 @@ BeingHandler::BeingHandler() void BeingHandler::handleMessage(MessageIn &msg) { - /* - Uint32 id; - Uint16 job, speed; - Uint16 headBottom, headTop, headMid; - Sint16 param1; - Sint8 type; - Being *srcBeing, *dstBeing; - */ - switch (msg.getId()) { case GPMSG_BEING_ENTER: @@ -106,322 +85,6 @@ void BeingHandler::handleMessage(MessageIn &msg) case GPMSG_BEING_LOOKS_CHANGE: handleBeingLooksChangeMessage(msg); break; - - - /* - case SMSG_BEING_VISIBLE: - case SMSG_BEING_MOVE: - // Information about a being in range - id = msg.readInt32(); - speed = msg.readInt16(); - msg.readInt16(); // unknown - msg.readInt16(); // unknown - msg.readInt16(); // option - job = msg.readInt16(); // class - - dstBeing = beingManager->findBeing(id); - - if (!dstBeing) - { - // Being with id >= 110000000 and job 0 are better - // known as ghosts, so don't create those. - if (job == 0 && id >= 110000000) - { - break; - } - - dstBeing = beingManager->createBeing(id, job); - } - else if (msg.getId() == 0x0078) - { - dstBeing->clearPath(); - dstBeing->mFrame = 0; - dstBeing->mWalkTime = tick_time; - dstBeing->setAction(Being::STAND); - } - - // Prevent division by 0 when calculating frame - if (speed == 0) { speed = 150; } - - dstBeing->setWalkSpeed(speed); - dstBeing->mJob = job; - dstBeing->setHairStyle(msg->readInt16()); - dstBeing->setSprite( - Being::WEAPON_SPRITE, msg->readInt16()); - dstBeing->setSprite( - Being::BOTTOMCLOTHES_SPRITE, msg->readInt16()); - - if (msg.getId() == SMSG_BEING_MOVE) - { - msg.readInt32(); // server tick - } - - msg->readInt16(); // shield - headTop = msg->readInt16(); - headMid = msg->readInt16(); - dstBeing->setSprite(Being::HAT_SPRITE, headTop); - dstBeing->setSprite(Being::TOPCLOTHES_SPRITE, headMid); - dstBeing->setHairColor(msg->readInt16()); - msg->readInt16(); // unknown - msg->readInt16(); // head dir - msg->readInt16(); // guild - msg->readInt16(); // unknown - msg->readInt16(); // unknown - msg->readInt16(); // manner - msg->readInt16(); // karma - msg->readInt8(); // unknown - dstBeing->setSex(1 - msg->readInt8()); // sex - - if (msg.getId() == SMSG_BEING_MOVE) - { - //Uint16 srcX, srcY, dstX, dstY; - //msg.readCoordinatePair(srcX, srcY, dstX, dstY); - //dstBeing->setAction(Being::STAND); - //dstBeing->mX = srcX; - //dstBeing->mY = srcY; - //dstBeing->setDestination(dstX, dstY); - } - else - { - //Uint8 dir; - //msg->readCoordinates(dstBeing->mX, dstBeing->mY, dir); - //dstBeing->setDirection(dir); - } - - msg.readInt8(); // unknown - msg.readInt8(); // unknown - msg.readInt8(); // unknown / sit - break; - - case SMSG_BEING_REMOVE: - // A being should be removed or has died - dstBeing = beingManager->findBeing(msg.readInt32()); - - if (!dstBeing) - break; - - if (msg.readInt8() == 1) - { - dstBeing->setAction(Being::DEAD); - } - else - { - beingManager->destroyBeing(dstBeing); - } - - if (dstBeing == player_node->getTarget()) - { - player_node->stopAttack(); - } - break; - - case SMSG_BEING_ACTION: - srcBeing = beingManager->findBeing(msg.readInt32()); - dstBeing = beingManager->findBeing(msg.readInt32()); - msg.readInt32(); // server tick - msg.readInt32(); // src speed - msg.readInt32(); // dst speed - param1 = msg.readInt16(); - msg.readInt16(); // param 2 - type = msg.readInt8(); - msg.readInt16(); // param 3 - - switch (type) - { - case 0: // Damage - if (dstBeing) { - dstBeing->takeDamage(param1); - } - if (srcBeing) { - srcBeing->handleAttack(dstBeing, param1); - } - break; - - case 2: // Sit - if (srcBeing) { - srcBeing->mFrame = 0; - srcBeing->setAction(Being::SIT); - } - break; - - case 3: // Stand up - if (srcBeing) { - srcBeing->mFrame = 0; - srcBeing->setAction(Being::STAND); - } - break; - } - break; - - case SMSG_BEING_LEVELUP: - id = (Uint32) msg->readInt32(); - - if (id == player_node->getId()) { - logger->log("Level up"); - sound.playSfx("sfx/levelup.ogg"); - } - else { - logger->log("Someone else went level up"); - } - Particle *levelupFX; - if (msg->readInt32() == 0) { // type - levelupFX = particleEngine->addEffect( - "graphics/particles/levelup.particle.xml", 0, 0); - } - else { - levelupFX = particleEngine->addEffect( - "graphics/particles/skillup.particle.xml", 0, 0); - } - beingManager->findBeing(id)->controlParticle(levelupFX); - break; - - case SMSG_BEING_EMOTION: - if (!(dstBeing = beingManager->findBeing(msg.readInt32()))) - { - break; - } - - dstBeing->mEmotion = msg.readInt8(); - dstBeing->mEmotionTime = EMOTION_TIME; - break; - - case SMSG_BEING_CHANGE_LOOKS: - { - if (!(dstBeing = beingManager->findBeing(msg.readInt32()))) - { - break; - } - - int type = msg.readInt8(); - int id = msg.readInt8(); - - switch (type) { - case 1: - dstBeing->setHairStyle(id); - break; - case 2: - dstBeing->setSprite(Being::WEAPON_SPRITE, id); - break; - case 3: // Change lower headgear for eAthena, pants for us - dstBeing->setSprite( - Being::BOTTOMCLOTHES_SPRITE, id); - break; - case 4: // Change upper headgear for eAthena, hat for us - dstBeing->setSprite( - Being::HAT_SPRITE, id); - break; - case 5: // Change middle headgear for eathena, armor for us - dstBeing->setSprite( - Being::TOPCLOTHES_SPRITE, id); - break; - case 6: - dstBeing->setHairColor(id); - break; - default: - logger->log("SMSG_BEING_CHANGE_LOOKS: unsupported type: " - "%d, id: %d", type, id); - break; - } - } - break; - - case SMSG_BEING_NAME_RESPONSE: - if ((dstBeing = beingManager->findBeing(msg.readInt32()))) - { - dstBeing->setName(msg.readString(24)); - } - break; - - case SMSG_PLAYER_UPDATE_1: - case SMSG_PLAYER_UPDATE_2: - case SMSG_PLAYER_MOVE: - // An update about a player, potentially including movement. - id = msg.readInt32(); - speed = msg.readInt16(); - msg.readInt16(); // option 1 - msg.readInt16(); // option 2 - msg.readInt16(); // option - job = msg.readInt16(); - - dstBeing = beingManager->findBeing(id); - - if (!dstBeing) - { - dstBeing = beingManager->createBeing(id, job); - } - - dstBeing->setWalkSpeed(speed); - dstBeing->mJob = job; - dstBeing->setHairStyle(msg->readInt16()); - dstBeing->setSprite( - Being::WEAPON_SPRITE, msg->readInt16()); - msg->readInt16(); // item id 2 - headBottom = msg->readInt16(); - - if (msg.getId() == SMSG_PLAYER_MOVE) - { - msg.readInt32(); // server tick - } - - headTop = msg.readInt16(); - headMid = msg.readInt16(); - dstBeing->setHairColor(msg.readInt16()); - msg.readInt16(); // unknown - msg.readInt16(); // head dir - msg.readInt32(); // guild - msg.readInt32(); // emblem - msg.readInt16(); // manner - msg.readInt8(); // karma - dstBeing->setSex(1 - msg.readInt8()); // sex - dstBeing->setSprite( - Being::BOTTOMCLOTHES_SPRITE, headBottom); - dstBeing->setSprite(Being::HAT_SPRITE, headTop); - dstBeing->setSprite(Being::TOPCLOTHES_SPRITE, headMid); - - if (msg.getId() == SMSG_PLAYER_MOVE) - { - //Uint16 srcX, srcY, dstX, dstY; - //msg.readCoordinatePair(srcX, srcY, dstX, dstY); - //dstBeing->mX = srcX; - //dstBeing->mY = srcY; - //dstBeing->setDestination(dstX, dstY); - } - else - { - //Uint8 dir; - //msg->readCoordinates(dstBeing->mX, dstBeing->mY, dir); - //dstBeing->setDirection(dir); - } - - msg.readInt8(); // unknown - msg.readInt8(); // unknown - - if (msg.getId() == SMSG_PLAYER_UPDATE_1) - { - if (msg.readInt8() == 2) - { - dstBeing->setAction(Being::SIT); - } - } - else if (msg.getId() == SMSG_PLAYER_MOVE) - { - msg.readInt8(); // unknown - } - - msg.readInt8(); // Lv - msg.readInt8(); // unknown - - dstBeing->mWalkTime = tick_time; - dstBeing->mFrame = 0; - break; - - case 0x0119: - // Change in players look - logger->log("0x0119 %i %i %i %x %i", msg->readInt32(), - msg->readInt16(), msg->readInt16(), msg->readInt16(), - msg->readInt8()); - break; - */ } } @@ -453,8 +116,7 @@ static void handleLooks(Player *being, MessageIn &msg) } } -void -BeingHandler::handleBeingEnterMessage(MessageIn &msg) +void BeingHandler::handleBeingEnterMessage(MessageIn &msg) { int type = msg.readInt8(); int id = msg.readInt16(); @@ -481,7 +143,8 @@ BeingHandler::handleBeingEnterMessage(MessageIn &msg) Player *p = static_cast< Player * >(being); int hs = msg.readInt8(), hc = msg.readInt8(); p->setHairStyle(hs, hc); - p->setGender(msg.readInt8() == GENDER_MALE ? GENDER_MALE : GENDER_FEMALE); + p->setGender(msg.readInt8() == GENDER_MALE ? + GENDER_MALE : GENDER_FEMALE); handleLooks(p, msg); } break; @@ -498,7 +161,7 @@ BeingHandler::handleBeingEnterMessage(MessageIn &msg) return; } - being->setPositionInPixels(px, py); + being->setPosition(px, py); being->setDestination(px, py); being->setAction(action); } @@ -518,7 +181,17 @@ void BeingHandler::handleBeingsMoveMessage(MessageIn &msg) int id = msg.readInt16(); int flags = msg.readInt8(); Being *being = beingManager->findBeing(id); - int sx = 0, sy = 0, dx = 0, dy = 0, speed = 0; + int sx = 0; + int sy = 0; + int dx = 0; + int dy = 0; + int speed = 0; + + printf("handleBeingsMoveMessage for %p (%s | %s)\n", + (void*) being, + (flags & MOVING_POSITION) ? "pos" : "", + (flags & MOVING_DESTINATION) ? "dest" : ""); + if (flags & MOVING_POSITION) { Uint16 sx2, sy2; @@ -543,12 +216,19 @@ void BeingHandler::handleBeingsMoveMessage(MessageIn &msg) } if (speed) { - being->setWalkSpeed(speed * 10); + /* The speed on the server is the cost of moving from one tile to + * the next. Beings get 1000 cost units per second. The speed is + * transferred as devided by 10, so that slower speeds fit in a + * byte. Here we convert the speed to pixels per second. + */ + const float tilesPerSecond = 100.0f / speed; + being->setWalkSpeed((int) (tilesPerSecond * 32)); } - if (abs(being->getPixelX() - sx) + abs(being->getPixelY() - sy) > 4 * 32) + if (abs(being->getPixelX() - sx) + + abs(being->getPixelY() - sy) > 4 * 32) { // Too large a desynchronization. - being->setPositionInPixels(sx, sy); + being->setPosition(sx, sy); being->setDestination(dx, dy); } else if (!(flags & MOVING_POSITION)) |