forked from mirror/openmw-tes3mp
[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::KillChanges killChangesBuffer;
|
||||
mwmp::BookChanges bookChangesBuffer;
|
||||
mwmp::MapChanges mapChangesBuffer;
|
||||
|
||||
private:
|
||||
CellController::TContainer cells;
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -17,9 +17,9 @@ namespace mwmp
|
|||
{
|
||||
DEBUG_PRINTF(strPacketID.c_str());
|
||||
|
||||
packet.Send(true);
|
||||
|
||||
Script::Call<Script::CallbackIdentity("OnPlayerMap")>(player.getId());
|
||||
// Not currently implemented
|
||||
//
|
||||
// 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;
|
||||
///< 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;
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -61,6 +61,7 @@ namespace mwmp
|
|||
void setFactions();
|
||||
void setKills();
|
||||
void setBooks();
|
||||
void setMapExplored();
|
||||
|
||||
void sendClass();
|
||||
void sendInventory();
|
||||
|
|
|
@ -15,7 +15,10 @@ namespace mwmp
|
|||
|
||||
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;
|
||||
};
|
||||
|
||||
struct MapChanges
|
||||
{
|
||||
std::vector<ESM::Cell> cellsExplored;
|
||||
unsigned int count;
|
||||
};
|
||||
|
||||
struct InventoryChanges
|
||||
{
|
||||
std::vector<Item> items;
|
||||
|
@ -201,6 +207,7 @@ namespace mwmp
|
|||
TopicChanges topicChanges;
|
||||
KillChanges killChanges;
|
||||
BookChanges bookChanges;
|
||||
MapChanges mapChanges;
|
||||
CellStateChanges cellStateChanges;
|
||||
|
||||
ESM::ActiveSpells activeSpells;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue