diff --git a/apps/openmw-mp/Player.hpp b/apps/openmw-mp/Player.hpp index edbc223e5..2b06ef42e 100644 --- a/apps/openmw-mp/Player.hpp +++ b/apps/openmw-mp/Player.hpp @@ -78,6 +78,7 @@ public: mwmp::TopicChanges topicChangesBuffer; mwmp::KillChanges killChangesBuffer; mwmp::BookChanges bookChangesBuffer; + mwmp::MapChanges mapChangesBuffer; private: CellController::TContainer cells; diff --git a/apps/openmw-mp/Script/Functions/Cells.cpp b/apps/openmw-mp/Script/Functions/Cells.cpp index 88b73f1de..db2685708 100644 --- a/apps/openmw-mp/Script/Functions/Cells.cpp +++ b/apps/openmw-mp/Script/Functions/Cells.cpp @@ -113,6 +113,15 @@ bool CellFunctions::IsChangingRegion(unsigned short pid) noexcept return player->isChangingRegion; } +void CellFunctions::AddCellExplored(unsigned short pid, const char* cellDescription) noexcept +{ + Player *player; + GET_PLAYER(pid, player, ); + + ESM::Cell cellExplored = Utils::getCellFromDescription(cellDescription); + player->mapChangesBuffer.cellsExplored.push_back(cellExplored); +} + void CellFunctions::SendCell(unsigned short pid) noexcept { Player *player; @@ -121,3 +130,15 @@ void CellFunctions::SendCell(unsigned short pid) noexcept mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_CELL_CHANGE)->setPlayer(player); mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_CELL_CHANGE)->Send(false); } + +void CellFunctions::SendMapChanges(unsigned short pid) noexcept +{ + Player *player; + GET_PLAYER(pid, player, ); + + std::swap(player->mapChanges, player->mapChangesBuffer); + mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_MAP)->setPlayer(player); + mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_MAP)->Send(false); + player->mapChanges = std::move(player->mapChangesBuffer); + player->mapChangesBuffer.cellsExplored.clear(); +} diff --git a/apps/openmw-mp/Script/Functions/Cells.hpp b/apps/openmw-mp/Script/Functions/Cells.hpp index db878283a..e918dd262 100644 --- a/apps/openmw-mp/Script/Functions/Cells.hpp +++ b/apps/openmw-mp/Script/Functions/Cells.hpp @@ -19,7 +19,10 @@ {"GetRegion", CellFunctions::GetRegion},\ {"IsChangingRegion", CellFunctions::IsChangingRegion},\ \ - {"SendCell", CellFunctions::SendCell} + {"AddCellExplored", CellFunctions::AddCellExplored},\ + \ + {"SendCell", CellFunctions::SendCell},\ + {"SendMapChanges", CellFunctions::SendMapChanges} class CellFunctions @@ -40,7 +43,10 @@ public: static const char *GetRegion(unsigned short pid) noexcept; static bool IsChangingRegion(unsigned short pid) noexcept; + static void AddCellExplored(unsigned short pid, const char* cellDescription) noexcept; + static void SendCell(unsigned short pid) noexcept; + static void SendMapChanges(unsigned short pid) noexcept; }; #endif //OPENMW_CELLAPI_HPP diff --git a/apps/openmw-mp/processors/player/ProcessorPlayerMap.hpp b/apps/openmw-mp/processors/player/ProcessorPlayerMap.hpp index e22e21c79..e1620df9e 100644 --- a/apps/openmw-mp/processors/player/ProcessorPlayerMap.hpp +++ b/apps/openmw-mp/processors/player/ProcessorPlayerMap.hpp @@ -17,9 +17,9 @@ namespace mwmp { DEBUG_PRINTF(strPacketID.c_str()); - packet.Send(true); - - Script::Call(player.getId()); + // Not currently implemented + // + // To be dealt with later to save explored areas on local maps } }; } diff --git a/apps/openmw/mwbase/windowmanager.hpp b/apps/openmw/mwbase/windowmanager.hpp index f103ce191..882c54f4f 100644 --- a/apps/openmw/mwbase/windowmanager.hpp +++ b/apps/openmw/mwbase/windowmanager.hpp @@ -179,6 +179,16 @@ namespace MWBase virtual void changeCell(const MWWorld::CellStore* cell) = 0; ///< change the active cell + /* + Start of tes3mp addition + + Allow setting a cell as explored from elsewhere in the code + */ + virtual void setCellExplored(const MWWorld::CellStore* cell) = 0; + /* + End of tes3mp addition + */ + virtual void setFocusObject(const MWWorld::Ptr& focus) = 0; virtual void setFocusObjectScreenCoords(float min_x, float min_y, float max_x, float max_y) = 0; diff --git a/apps/openmw/mwgui/windowmanagerimp.cpp b/apps/openmw/mwgui/windowmanagerimp.cpp index 786c5a37b..eb6a8bed2 100644 --- a/apps/openmw/mwgui/windowmanagerimp.cpp +++ b/apps/openmw/mwgui/windowmanagerimp.cpp @@ -1058,6 +1058,19 @@ namespace MWGui } } + /* + Start of tes3mp addition + + Allow setting a cell as explored from elsewhere in the code + */ + void WindowManager::setCellExplored(const MWWorld::CellStore* cell) + { + mMap->cellExplored(cell->getCell()->getGridX(), cell->getCell()->getGridY()); + } + /* + End of tes3mp addition + */ + void WindowManager::setActiveMap(int x, int y, bool interior) { mMap->setActiveCell(x,y, interior); diff --git a/apps/openmw/mwgui/windowmanagerimp.hpp b/apps/openmw/mwgui/windowmanagerimp.hpp index ea7b4c14c..fa374a078 100644 --- a/apps/openmw/mwgui/windowmanagerimp.hpp +++ b/apps/openmw/mwgui/windowmanagerimp.hpp @@ -214,6 +214,16 @@ namespace MWGui virtual void changeCell(const MWWorld::CellStore* cell); ///< change the active cell + /* + Start of tes3mp addition + + Allow setting a cell as explored from elsewhere in the code + */ + virtual void setCellExplored(const MWWorld::CellStore* cell); + /* + End of tes3mp addition + */ + virtual void setFocusObject(const MWWorld::Ptr& focus); virtual void setFocusObjectScreenCoords(float min_x, float min_y, float max_x, float max_y); diff --git a/apps/openmw/mwmp/LocalPlayer.cpp b/apps/openmw/mwmp/LocalPlayer.cpp index 9d2ea017c..42e62f7b7 100644 --- a/apps/openmw/mwmp/LocalPlayer.cpp +++ b/apps/openmw/mwmp/LocalPlayer.cpp @@ -991,6 +991,21 @@ void LocalPlayer::setBooks() ptrNpcStats.flagAsUsed(book.bookId); } +void LocalPlayer::setMapExplored() +{ + MWWorld::Ptr player = getPlayerPtr(); + MWMechanics::NpcStats &ptrNpcStats = player.getClass().getNpcStats(player); + + for (const auto &cellExplored : mapChanges.cellsExplored) + { + MWWorld::CellStore *ptrCellStore = Main::get().getCellController()->getCellStore(cellExplored); + + if (!ptrCellStore) continue; + + MWBase::Environment::get().getWindowManager()->setCellExplored(ptrCellStore); + } +} + void LocalPlayer::sendClass() { MWBase::World *world = MWBase::Environment::get().getWorld(); diff --git a/apps/openmw/mwmp/LocalPlayer.hpp b/apps/openmw/mwmp/LocalPlayer.hpp index f441f3dba..425b825c6 100644 --- a/apps/openmw/mwmp/LocalPlayer.hpp +++ b/apps/openmw/mwmp/LocalPlayer.hpp @@ -61,6 +61,7 @@ namespace mwmp void setFactions(); void setKills(); void setBooks(); + void setMapExplored(); void sendClass(); void sendInventory(); diff --git a/apps/openmw/mwmp/processors/player/ProcessorPlayerMap.hpp b/apps/openmw/mwmp/processors/player/ProcessorPlayerMap.hpp index b900c4f35..803c7e10d 100644 --- a/apps/openmw/mwmp/processors/player/ProcessorPlayerMap.hpp +++ b/apps/openmw/mwmp/processors/player/ProcessorPlayerMap.hpp @@ -15,7 +15,10 @@ namespace mwmp virtual void Do(PlayerPacket &packet, BasePlayer *player) { - // Placeholder to be filled in later + if (isLocal()) + { + static_cast(player)->setMapExplored(); + } } }; } diff --git a/components/openmw-mp/Base/BasePlayer.hpp b/components/openmw-mp/Base/BasePlayer.hpp index ef4d20fd6..4da795c3f 100644 --- a/components/openmw-mp/Base/BasePlayer.hpp +++ b/components/openmw-mp/Base/BasePlayer.hpp @@ -107,6 +107,12 @@ namespace mwmp unsigned int count; }; + struct MapChanges + { + std::vector cellsExplored; + unsigned int count; + }; + struct InventoryChanges { std::vector items; @@ -201,6 +207,7 @@ namespace mwmp TopicChanges topicChanges; KillChanges killChanges; BookChanges bookChanges; + MapChanges mapChanges; CellStateChanges cellStateChanges; ESM::ActiveSpells activeSpells; diff --git a/components/openmw-mp/Packets/Player/PacketPlayerMap.cpp b/components/openmw-mp/Packets/Player/PacketPlayerMap.cpp index 528b0ec5d..9027f55c9 100644 --- a/components/openmw-mp/Packets/Player/PacketPlayerMap.cpp +++ b/components/openmw-mp/Packets/Player/PacketPlayerMap.cpp @@ -13,5 +13,24 @@ void PacketPlayerMap::Packet(RakNet::BitStream *bs, bool send) { PlayerPacket::Packet(bs, send); - // Placeholder to be filled in later + if (send) + player->mapChanges.count = (unsigned int)(player->mapChanges.cellsExplored.size()); + else + player->mapChanges.cellsExplored.clear(); + + RW(player->mapChanges.count, send); + + for (unsigned int i = 0; i < player->mapChanges.count; i++) + { + ESM::Cell cellExplored; + + if (send) + cellExplored = player->mapChanges.cellsExplored.at(i); + + RW(cellExplored.mData, send, 1); + RW(cellExplored.mName, send, 1); + + if (!send) + player->mapChanges.cellsExplored.push_back(cellExplored); + } }