summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-01-23 20:41:50 +0300
committerAndrei Karas <akaras@inbox.ru>2012-01-23 20:41:50 +0300
commitbac1df3b9ac0e3327e8de812793d0a18cfd64cba (patch)
tree46cf157684952f5aeccd59875917abb222024df8 /src
parent7d60bf1c04fce4ed16144aece76e594e0e217960 (diff)
downloadmanaverse-bac1df3b9ac0e3327e8de812793d0a18cfd64cba.tar.gz
manaverse-bac1df3b9ac0e3327e8de812793d0a18cfd64cba.tar.bz2
manaverse-bac1df3b9ac0e3327e8de812793d0a18cfd64cba.tar.xz
manaverse-bac1df3b9ac0e3327e8de812793d0a18cfd64cba.zip
Add moving camera commands from npc.
Diffstat (limited to 'src')
-rw-r--r--src/gui/viewport.cpp41
-rw-r--r--src/gui/viewport.h8
-rw-r--r--src/net/tmwa/network.cpp2
-rw-r--r--src/net/tmwa/npchandler.cpp52
-rw-r--r--src/net/tmwa/npchandler.h2
5 files changed, 97 insertions, 8 deletions
diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp
index 1407415fd..f4c6c315f 100644
--- a/src/gui/viewport.cpp
+++ b/src/gui/viewport.cpp
@@ -875,3 +875,44 @@ bool Viewport::isPopupMenuVisible()
{
return mPopupMenu ? mPopupMenu->isVisible() : false;
}
+
+void Viewport::moveCameraToActor(int actorId, int x, int y)
+{
+ if (!player_node)
+ return;
+
+ Actor *actor = actorSpriteManager->findBeing(actorId);
+ if (!actor)
+ return;
+ Vector actorPos = actor->getPosition();
+ Vector playerPos = player_node->getPosition();
+ mCameraMode = 1;
+ mCameraRelativeX = actorPos.x - playerPos.x + x;
+ mCameraRelativeY = actorPos.y - playerPos.y + y;
+}
+
+void Viewport::moveCameraToPosition(int x, int y)
+{
+ if (!player_node)
+ return;
+
+ Vector playerPos = player_node->getPosition();
+ mCameraMode = 1;
+
+ mCameraRelativeX = x - playerPos.x;
+ mCameraRelativeY = y - playerPos.y;
+}
+
+void Viewport::moveCameraRelative(int x, int y)
+{
+ mCameraMode = 1;
+ mCameraRelativeX += x;
+ mCameraRelativeY += y;
+}
+
+void Viewport::returnCamera()
+{
+ mCameraMode = 0;
+ mCameraRelativeX = 0;
+ mCameraRelativeY = 0;
+}
diff --git a/src/gui/viewport.h b/src/gui/viewport.h
index b25f51242..0f56e9426 100644
--- a/src/gui/viewport.h
+++ b/src/gui/viewport.h
@@ -250,6 +250,14 @@ class Viewport : public WindowContainer, public gcn::MouseListener,
bool isPopupMenuVisible();
+ void moveCameraToActor(int actorId, int x = 0, int y = 0);
+
+ void moveCameraToPosition(int x, int y);
+
+ void moveCameraRelative(int x, int y);
+
+ void returnCamera();
+
protected:
friend class ActorSpriteManager;
diff --git a/src/net/tmwa/network.cpp b/src/net/tmwa/network.cpp
index 08ba1db10..31329eafb 100644
--- a/src/net/tmwa/network.cpp
+++ b/src/net/tmwa/network.cpp
@@ -83,7 +83,7 @@ short packet_lengths[] =
-1, -1, 20, 10, 32, 9, 34, 14, 2, 6, 48, 56, -1, 4, 5, 10,
// #0x0200
26, 0, 0, 0, 18, 0, 0, 0, 0, 0, 0, 19, 10, 0, 0, 0,
- 2, -1, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 2, -1, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-1, 122, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
};
diff --git a/src/net/tmwa/npchandler.cpp b/src/net/tmwa/npchandler.cpp
index 5e305070e..c395eb1b8 100644
--- a/src/net/tmwa/npchandler.cpp
+++ b/src/net/tmwa/npchandler.cpp
@@ -25,6 +25,7 @@
#include "localplayer.h"
#include "gui/npcdialog.h"
+#include "gui/viewport.h"
#include "net/messagein.h"
#include "net/net.h"
@@ -97,7 +98,7 @@ void NpcHandler::handleMessage(Net::MessageIn &msg)
break;
case SMSG_NPC_COMMAND:
- processNpcCommand(msg);
+ processNpcCommand(msg, npcId);
break;
default:
@@ -239,13 +240,52 @@ int NpcHandler::getNpc(Net::MessageIn &msg, bool haveLength)
return npcId;
}
-void NpcHandler::processNpcCommand(Net::MessageIn &msg)
+void NpcHandler::processNpcCommand(Net::MessageIn &msg, int npcId)
{
const int cmd = msg.readInt16();
- if (cmd == 0)
- mRequestLang = true;
- else
- logger->log("unknown npc command: %d", cmd);
+ switch (cmd)
+ {
+ case 0:
+ mRequestLang = true;
+ break;
+
+ case 1:
+ if (viewport)
+ viewport->moveCameraToActor(npcId);
+ break;
+
+ case 2:
+ if (viewport)
+ {
+ const int id = msg.readInt32();
+ const int x = msg.readInt16();
+ const int y = msg.readInt16();
+ if (!id)
+ viewport->moveCameraToPosition(x, y);
+ else
+ viewport->moveCameraToActor(id, x, y);
+ }
+ break;
+
+ case 3:
+ if (viewport)
+ viewport->returnCamera();
+ break;
+
+ case 4:
+ if (viewport)
+ {
+ msg.readInt32(); // id
+ const int x = msg.readInt16();
+ const int y = msg.readInt16();
+ viewport->moveCameraRelative(x, y);
+ }
+ break;
+
+ default:
+ logger->log("unknown npc command: %d", cmd);
+ break;
+ }
}
void NpcHandler::processLangReuqest(Net::MessageIn &msg A_UNUSED, int npcId)
diff --git a/src/net/tmwa/npchandler.h b/src/net/tmwa/npchandler.h
index 648b1e5d9..1cfcacb20 100644
--- a/src/net/tmwa/npchandler.h
+++ b/src/net/tmwa/npchandler.h
@@ -66,7 +66,7 @@ class NpcHandler : public MessageHandler, public Ea::NpcHandler
int getNpc(Net::MessageIn &msg, bool haveLength);
- void processNpcCommand(Net::MessageIn &msg);
+ void processNpcCommand(Net::MessageIn &msg, int npcId);
void processLangReuqest(Net::MessageIn &msg, int npcId);