mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-03-03 15:19:42 +00:00
[General] Implement PlayerMap packet, part 1
This commit is contained in:
parent
ad4b1d05bb
commit
71313c5aa6
12 changed files with 112 additions and 6 deletions
|
@ -78,6 +78,7 @@ public:
|
||||||
mwmp::TopicChanges topicChangesBuffer;
|
mwmp::TopicChanges topicChangesBuffer;
|
||||||
mwmp::KillChanges killChangesBuffer;
|
mwmp::KillChanges killChangesBuffer;
|
||||||
mwmp::BookChanges bookChangesBuffer;
|
mwmp::BookChanges bookChangesBuffer;
|
||||||
|
mwmp::MapChanges mapChangesBuffer;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CellController::TContainer cells;
|
CellController::TContainer cells;
|
||||||
|
|
|
@ -113,6 +113,15 @@ bool CellFunctions::IsChangingRegion(unsigned short pid) noexcept
|
||||||
return player->isChangingRegion;
|
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
|
void CellFunctions::SendCell(unsigned short pid) noexcept
|
||||||
{
|
{
|
||||||
Player *player;
|
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)->setPlayer(player);
|
||||||
mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_CELL_CHANGE)->Send(false);
|
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();
|
||||||
|
}
|
||||||
|
|
|
@ -19,7 +19,10 @@
|
||||||
{"GetRegion", CellFunctions::GetRegion},\
|
{"GetRegion", CellFunctions::GetRegion},\
|
||||||
{"IsChangingRegion", CellFunctions::IsChangingRegion},\
|
{"IsChangingRegion", CellFunctions::IsChangingRegion},\
|
||||||
\
|
\
|
||||||
{"SendCell", CellFunctions::SendCell}
|
{"AddCellExplored", CellFunctions::AddCellExplored},\
|
||||||
|
\
|
||||||
|
{"SendCell", CellFunctions::SendCell},\
|
||||||
|
{"SendMapChanges", CellFunctions::SendMapChanges}
|
||||||
|
|
||||||
|
|
||||||
class CellFunctions
|
class CellFunctions
|
||||||
|
@ -40,7 +43,10 @@ public:
|
||||||
static const char *GetRegion(unsigned short pid) noexcept;
|
static const char *GetRegion(unsigned short pid) noexcept;
|
||||||
static bool IsChangingRegion(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 SendCell(unsigned short pid) noexcept;
|
||||||
|
static void SendMapChanges(unsigned short pid) noexcept;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //OPENMW_CELLAPI_HPP
|
#endif //OPENMW_CELLAPI_HPP
|
||||||
|
|
|
@ -17,9 +17,9 @@ namespace mwmp
|
||||||
{
|
{
|
||||||
DEBUG_PRINTF(strPacketID.c_str());
|
DEBUG_PRINTF(strPacketID.c_str());
|
||||||
|
|
||||||
packet.Send(true);
|
// Not currently implemented
|
||||||
|
//
|
||||||
Script::Call<Script::CallbackIdentity("OnPlayerMap")>(player.getId());
|
// To be dealt with later to save explored areas on local maps
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -179,6 +179,16 @@ namespace MWBase
|
||||||
virtual void changeCell(const MWWorld::CellStore* cell) = 0;
|
virtual void changeCell(const MWWorld::CellStore* cell) = 0;
|
||||||
///< change the active 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) = 0;
|
||||||
|
/*
|
||||||
|
End of tes3mp addition
|
||||||
|
*/
|
||||||
|
|
||||||
virtual void setFocusObject(const MWWorld::Ptr& focus) = 0;
|
virtual void setFocusObject(const MWWorld::Ptr& focus) = 0;
|
||||||
virtual void setFocusObjectScreenCoords(float min_x, float min_y, float max_x, float max_y) = 0;
|
virtual void setFocusObjectScreenCoords(float min_x, float min_y, float max_x, float max_y) = 0;
|
||||||
|
|
||||||
|
|
|
@ -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)
|
void WindowManager::setActiveMap(int x, int y, bool interior)
|
||||||
{
|
{
|
||||||
mMap->setActiveCell(x,y, interior);
|
mMap->setActiveCell(x,y, interior);
|
||||||
|
|
|
@ -214,6 +214,16 @@ namespace MWGui
|
||||||
|
|
||||||
virtual void changeCell(const MWWorld::CellStore* cell); ///< change the active cell
|
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 setFocusObject(const MWWorld::Ptr& focus);
|
||||||
virtual void setFocusObjectScreenCoords(float min_x, float min_y, float max_x, float max_y);
|
virtual void setFocusObjectScreenCoords(float min_x, float min_y, float max_x, float max_y);
|
||||||
|
|
||||||
|
|
|
@ -991,6 +991,21 @@ void LocalPlayer::setBooks()
|
||||||
ptrNpcStats.flagAsUsed(book.bookId);
|
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()
|
void LocalPlayer::sendClass()
|
||||||
{
|
{
|
||||||
MWBase::World *world = MWBase::Environment::get().getWorld();
|
MWBase::World *world = MWBase::Environment::get().getWorld();
|
||||||
|
|
|
@ -61,6 +61,7 @@ namespace mwmp
|
||||||
void setFactions();
|
void setFactions();
|
||||||
void setKills();
|
void setKills();
|
||||||
void setBooks();
|
void setBooks();
|
||||||
|
void setMapExplored();
|
||||||
|
|
||||||
void sendClass();
|
void sendClass();
|
||||||
void sendInventory();
|
void sendInventory();
|
||||||
|
|
|
@ -15,7 +15,10 @@ namespace mwmp
|
||||||
|
|
||||||
virtual void Do(PlayerPacket &packet, BasePlayer *player)
|
virtual void Do(PlayerPacket &packet, BasePlayer *player)
|
||||||
{
|
{
|
||||||
// Placeholder to be filled in later
|
if (isLocal())
|
||||||
|
{
|
||||||
|
static_cast<LocalPlayer*>(player)->setMapExplored();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -107,6 +107,12 @@ namespace mwmp
|
||||||
unsigned int count;
|
unsigned int count;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct MapChanges
|
||||||
|
{
|
||||||
|
std::vector<ESM::Cell> cellsExplored;
|
||||||
|
unsigned int count;
|
||||||
|
};
|
||||||
|
|
||||||
struct InventoryChanges
|
struct InventoryChanges
|
||||||
{
|
{
|
||||||
std::vector<Item> items;
|
std::vector<Item> items;
|
||||||
|
@ -201,6 +207,7 @@ namespace mwmp
|
||||||
TopicChanges topicChanges;
|
TopicChanges topicChanges;
|
||||||
KillChanges killChanges;
|
KillChanges killChanges;
|
||||||
BookChanges bookChanges;
|
BookChanges bookChanges;
|
||||||
|
MapChanges mapChanges;
|
||||||
CellStateChanges cellStateChanges;
|
CellStateChanges cellStateChanges;
|
||||||
|
|
||||||
ESM::ActiveSpells activeSpells;
|
ESM::ActiveSpells activeSpells;
|
||||||
|
|
|
@ -13,5 +13,24 @@ void PacketPlayerMap::Packet(RakNet::BitStream *bs, bool send)
|
||||||
{
|
{
|
||||||
PlayerPacket::Packet(bs, 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue