diff --git a/apps/openmw-mp/Script/Functions/Translocations.cpp b/apps/openmw-mp/Script/Functions/Translocations.cpp index 7fa33686d..dfe1be340 100644 --- a/apps/openmw-mp/Script/Functions/Translocations.cpp +++ b/apps/openmw-mp/Script/Functions/Translocations.cpp @@ -79,8 +79,6 @@ void ScriptFunctions::SetCell(unsigned short pid, const char *name) noexcept cout << " in to cell \"" << player->GetCell()->mName << "\"" << endl; - player->GetCell()->mData.mFlags |= 1; - mwmp::Networking::Get().GetController()->GetPacket(ID_GAME_CELL)->Send(player, false); mwmp::Networking::Get().GetController()->GetPacket(ID_GAME_CELL)->Send(player, true); } @@ -94,6 +92,43 @@ const char* ScriptFunctions::GetCell(unsigned short pid) noexcept return player->GetCell()->mName.c_str(); } +void ScriptFunctions::SetExterior(unsigned short pid, int x, int y) noexcept +{ + Player *player; + GET_PLAYER(pid, player,); + + cout << "attempt to move player (pid: " << pid << " name: " << player->Npc()->mName << ") from "; + if(!player->GetCell()->isExterior()) + cout << "\"" << player->GetCell()->mName << "\""; + else + cout << "exterior: " << player->GetCell()->mCellId.mIndex.mX << ", " << player->GetCell()->mCellId.mIndex.mY; + cout << " in to exterior cell \"" << x << ", " << y << "\"" << endl; + + /*cout << "TEST1 : " << player->GetCell()->mData.mFlags << endl; + player->GetCell()->mData.mFlags &= ~1; + cout << "TEST2 : " << player->GetCell()->mData.mFlags << endl;*/ + + player->GetCell()->mCellId.mIndex.mX = x; + player->GetCell()->mCellId.mIndex.mY = y; + + mwmp::Networking::Get().GetController()->GetPacket(ID_GAME_CELL)->Send(player, false); + mwmp::Networking::Get().GetController()->GetPacket(ID_GAME_CELL)->Send(player, true); +} + +int ScriptFunctions::GetExteriorX(unsigned short pid) noexcept +{ + Player *player; + GET_PLAYER(pid, player,0); + return player->GetCell()->mCellId.mIndex.mX; +} + +int ScriptFunctions::GetExteriorY(unsigned short pid) noexcept +{ + Player *player; + GET_PLAYER(pid, player,0); + return player->GetCell()->mCellId.mIndex.mY; +} + bool ScriptFunctions::IsInInterior(unsigned short pid) noexcept { Player *player; diff --git a/apps/openmw-mp/Script/ScriptFunctions.hpp b/apps/openmw-mp/Script/ScriptFunctions.hpp index 41dc8c275..be339c1e6 100644 --- a/apps/openmw-mp/Script/ScriptFunctions.hpp +++ b/apps/openmw-mp/Script/ScriptFunctions.hpp @@ -48,6 +48,10 @@ public: static void SetCell(unsigned short pid, const char *name) noexcept; static const char *GetCell(unsigned short pid) noexcept; + static void SetExterior(unsigned short pid, int x, int y) noexcept; + static int GetExteriorX(unsigned short pid) noexcept; + static int GetExteriorY(unsigned short pid) noexcept; + static bool IsInInterior(unsigned short pid) noexcept; static void SetName(unsigned short pid, const char *name) noexcept; @@ -162,6 +166,9 @@ public: {"GetCell", ScriptFunctions::GetCell}, {"SetCell", ScriptFunctions::SetCell}, + {"SetExterior", ScriptFunctions::SetExterior}, + {"GetExteriorX", ScriptFunctions::GetExteriorX}, + {"GetExteriorY", ScriptFunctions::GetExteriorY}, {"IsInInterior", ScriptFunctions::IsInInterior}, {"GetName", ScriptFunctions::GetName}, diff --git a/apps/openmw/mwmp/LocalPlayer.cpp b/apps/openmw/mwmp/LocalPlayer.cpp index 5a6ac6042..6fc5fb0ed 100644 --- a/apps/openmw/mwmp/LocalPlayer.cpp +++ b/apps/openmw/mwmp/LocalPlayer.cpp @@ -128,6 +128,44 @@ void LocalPlayer::setPosition() world->rotateObject(player, Position()->rot[0], Position()->rot[1], Position()->rot[2]); } +void LocalPlayer::setCell() +{ + MWBase::World *world = MWBase::Environment::get().getWorld(); + MWWorld::Ptr player = world->getPlayerPtr(); + ESM::Position pos; + + world->getPlayer().setTeleported(true); + + int x = GetCell()->mCellId.mIndex.mX; + int y = GetCell()->mCellId.mIndex.mY; + ESM::CellId curCell = player.mCell->getCell()->mCellId; + if(x != curCell.mIndex.mX || y != curCell.mIndex.mY) + { + cout << "Exterior location: " << x << ", " << y << endl; + world->indexToPosition (x, y, pos.pos[0], pos.pos[1], true); + pos.pos[2] = 0; + + pos.rot[0] = pos.rot[1] = pos.rot[2] = 0; + + world->changeToExteriorCell (pos, true); + world->fixPosition(player); + } + else if (world->findExteriorPosition(GetCell()->mName, pos)) + { + cout << "Exterior location: " << GetCell()->mName << endl; + world->changeToExteriorCell(pos, true); + world->fixPosition(player); + } + else + { + cout << "Interior location: " << GetCell()->mName << endl; + world->findInteriorPosition(GetCell()->mName, pos); + world->changeToInteriorCell(GetCell()->mName, pos, true); + } + + updateCell(true); +} + void LocalPlayer::updateInventory(bool forceUpdate) { diff --git a/apps/openmw/mwmp/LocalPlayer.hpp b/apps/openmw/mwmp/LocalPlayer.hpp index 0ff0c37a6..cafc5a51f 100644 --- a/apps/openmw/mwmp/LocalPlayer.hpp +++ b/apps/openmw/mwmp/LocalPlayer.hpp @@ -30,6 +30,7 @@ namespace mwmp void updateDrawStateAndFlags(bool forceUpdate = false); void setPosition(); + void setCell(); void CharGen(int stageFirst, int stageEnd); diff --git a/apps/openmw/mwmp/Networking.cpp b/apps/openmw/mwmp/Networking.cpp index 01628a7ce..572071c6f 100644 --- a/apps/openmw/mwmp/Networking.cpp +++ b/apps/openmw/mwmp/Networking.cpp @@ -414,19 +414,13 @@ void Networking::ReciveMessage(RakNet::Packet *packet) { if(id == myid) { - myPacket->Packet(&bsIn, getLocalPlayer(), false); - - if(!getLocalPlayer()->GetCell()->isExterior()) + if (packet->length == myPacket->headerSize()) + getLocalPlayer()->updateCell(true); + else { - cout << "location: " << getLocalPlayer()->GetCell()->mName << endl; - - MWBase::World *world = MWBase::Environment::get().getWorld(); - ESM::Position pos; - world->findInteriorPosition(getLocalPlayer()->GetCell()->mName, pos); - world->changeToInteriorCell(getLocalPlayer()->GetCell()->mName, pos, true); + myPacket->Packet(&bsIn, getLocalPlayer(), false); + getLocalPlayer()->setCell(); } - - getLocalPlayer()->updateCell(true); } else if(pl != 0) { diff --git a/components/openmw-mp/Packets/PacketCell.cpp b/components/openmw-mp/Packets/PacketCell.cpp index 9cf8bb1f6..e37d36275 100644 --- a/components/openmw-mp/Packets/PacketCell.cpp +++ b/components/openmw-mp/Packets/PacketCell.cpp @@ -19,11 +19,9 @@ void mwmp::PacketCell::Packet(RakNet::BitStream *bs, mwmp::BasePlayer *player, b RW(player->GetCell()->mData.mFlags, send); - if(player->GetCell()->isExterior()) - { - RW(player->GetCell()->mCellId.mIndex.mX, send); - RW(player->GetCell()->mCellId.mIndex.mY, send); - } - else - RW(player->GetCell()->mName, send); + + RW(player->GetCell()->mCellId.mIndex.mX, send); + RW(player->GetCell()->mCellId.mIndex.mY, send); + + RW(player->GetCell()->mName, send); }