diff --git a/apps/openmw-mp/Books.cpp b/apps/openmw-mp/Books.cpp index e49024d7a..0aa5e1e9c 100644 --- a/apps/openmw-mp/Books.cpp +++ b/apps/openmw-mp/Books.cpp @@ -40,7 +40,7 @@ void Books::addBook(const std::string &bookId) std::string Books::getBookId(unsigned i) const { - if (i >= player->bookChanges.count) + if (i >= player->bookChanges.books.size()) return "invalid"; return player->bookChanges.books.at(i).bookId; @@ -48,7 +48,7 @@ std::string Books::getBookId(unsigned i) const unsigned Books::getChanges() const { - return player->bookChanges.count; + return player->bookChanges.books.size(); } void Books::reset() diff --git a/apps/openmw-mp/Dialogue.cpp b/apps/openmw-mp/Dialogue.cpp index 98c142043..c35d66136 100644 --- a/apps/openmw-mp/Dialogue.cpp +++ b/apps/openmw-mp/Dialogue.cpp @@ -59,5 +59,5 @@ std::string Dialogue::getTopicId(unsigned int i) const unsigned int Dialogue::getChanges() const { - return player->topicChanges.count; + return player->topicChanges.topics.size(); } diff --git a/apps/openmw-mp/Inventory.cpp b/apps/openmw-mp/Inventory.cpp index ca443ec17..75a1fac74 100644 --- a/apps/openmw-mp/Inventory.cpp +++ b/apps/openmw-mp/Inventory.cpp @@ -73,7 +73,7 @@ void Inventory::InitializeInventoryChanges() int Inventory::getChangesSize() const { - return netActor->getNetCreature()->inventoryChanges.count; + return netActor->getNetCreature()->inventoryChanges.items.size(); } void Inventory::equipItem(unsigned short slot, const std::string& refId, unsigned int count, int charge) diff --git a/apps/openmw/mwmp/LocalPlayer.cpp b/apps/openmw/mwmp/LocalPlayer.cpp index d47f239c7..39fbf170f 100644 --- a/apps/openmw/mwmp/LocalPlayer.cpp +++ b/apps/openmw/mwmp/LocalPlayer.cpp @@ -1091,7 +1091,6 @@ void LocalPlayer::sendInventory() inventoryChanges.items.push_back(item); } - inventoryChanges.count = (unsigned int) inventoryChanges.items.size(); inventoryChanges.action = InventoryChanges::SET; getNetworking()->getPlayerPacket(ID_PLAYER_INVENTORY)->setPlayer(this); getNetworking()->getPlayerPacket(ID_PLAYER_INVENTORY)->Send(); diff --git a/components/openmw-mp/Base/BasePlayer.hpp b/components/openmw-mp/Base/BasePlayer.hpp index bafa2a09e..31a88f799 100644 --- a/components/openmw-mp/Base/BasePlayer.hpp +++ b/components/openmw-mp/Base/BasePlayer.hpp @@ -84,7 +84,6 @@ namespace mwmp struct AttributeChanges { std::vector attributeIndexes; - unsigned int count; }; // Track only the indexes of the skills that have been changed, @@ -92,19 +91,16 @@ namespace mwmp struct SkillChanges { std::vector skillIndexes; - unsigned int count; }; struct JournalChanges { std::vector journalItems; - unsigned int count; }; struct FactionChanges { std::vector factions; - unsigned int count; enum FACTION_ACTION { @@ -119,31 +115,27 @@ namespace mwmp struct TopicChanges { std::vector topics; - unsigned int count; }; struct KillChanges { std::vector kills; - unsigned int count; }; struct BookChanges { std::vector books; - unsigned int count; }; struct MapChanges { std::vector cellsExplored; - unsigned int count; }; struct SpellbookChanges { std::vector spells; - unsigned int count; + enum ACTION_TYPE { SET = 0, @@ -156,7 +148,6 @@ namespace mwmp struct CellStateChanges { std::vector cellStates; - unsigned int count; }; enum RESURRECT_TYPE @@ -225,9 +216,7 @@ namespace mwmp BasePlayer(RakNet::RakNetGUID guid) : guid(guid) { inventoryChanges.action = 0; - inventoryChanges.count = 0; spellbookChanges.action = 0; - spellbookChanges.count = 0; useCreatureName = false; isWerewolf = false; } diff --git a/components/openmw-mp/Base/BaseStructs.hpp b/components/openmw-mp/Base/BaseStructs.hpp index 307ec20e0..f75048866 100644 --- a/components/openmw-mp/Base/BaseStructs.hpp +++ b/components/openmw-mp/Base/BaseStructs.hpp @@ -22,7 +22,6 @@ namespace mwmp struct InventoryChanges { std::vector items; - unsigned int count; enum ACTION_TYPE { SET = 0, diff --git a/components/openmw-mp/Packets/BasePacket.cpp b/components/openmw-mp/Packets/BasePacket.cpp index 65b7f5f3c..483e783cf 100644 --- a/components/openmw-mp/Packets/BasePacket.cpp +++ b/components/openmw-mp/Packets/BasePacket.cpp @@ -42,9 +42,9 @@ void BasePacket::SetSendStream(RakNet::BitStream *bitStream) void BasePacket::SetStreams(RakNet::BitStream *inStream, RakNet::BitStream *outStream) { - if (inStream != 0) + if (inStream != nullptr) bsRead = inStream; - if (outStream != 0) + if (outStream != nullptr) bsSend = outStream; } diff --git a/components/openmw-mp/Packets/BasePacket.hpp b/components/openmw-mp/Packets/BasePacket.hpp index 03b912366..26b48e2d7 100644 --- a/components/openmw-mp/Packets/BasePacket.hpp +++ b/components/openmw-mp/Packets/BasePacket.hpp @@ -76,7 +76,7 @@ namespace mwmp bs->Read(data); } - void RW(std::string &str, bool write, bool compress = 0) + void RW(std::string &str, bool write, bool compress = false) { if (write) { @@ -101,10 +101,10 @@ namespace mwmp } protected: - unsigned char packetID; + uint8_t packetID; PacketReliability reliability; PacketPriority priority; - int orderChannel; + char orderChannel; RakNet::BitStream *bsRead, *bsSend, *bs; RakNet::RakPeerInterface *peer; RakNet::RakNetGUID guid; diff --git a/components/openmw-mp/Packets/Player/PacketGUIWindow.cpp b/components/openmw-mp/Packets/Player/PacketGUIWindow.cpp index c2509196f..2cc284a6a 100644 --- a/components/openmw-mp/Packets/Player/PacketGUIWindow.cpp +++ b/components/openmw-mp/Packets/Player/PacketGUIWindow.cpp @@ -24,7 +24,7 @@ void PacketGUIWindow::Packet(RakNet::BitStream *bs, bool send) int32_t size; if (send) - size = player->guiWindow.widgets.size(); + size = static_cast(player->guiWindow.widgets.size()); RW(size, send); if(!send) diff --git a/components/openmw-mp/Packets/Player/PacketPlayerActiveSkills.cpp b/components/openmw-mp/Packets/Player/PacketPlayerActiveSkills.cpp index c19a1e223..39f9b6b36 100644 --- a/components/openmw-mp/Packets/Player/PacketPlayerActiveSkills.cpp +++ b/components/openmw-mp/Packets/Player/PacketPlayerActiveSkills.cpp @@ -16,43 +16,40 @@ void PacketPlayerActiveSkills::Packet(RakNet::BitStream *bs, bool send) { PlayerPacket::Packet(bs, send); - unsigned long spells = 0; + uint32_t spellCount = 0; if (send) - spells = player->activeSpells.mSpells.size(); + spellCount = static_cast(player->activeSpells.mSpells.size()); - RW(spells, send); + RW(spellCount, send); - if (send) - for (ESM::ActiveSpells::TContainer::const_iterator spell = player->activeSpells.mSpells.begin(); - spell != player->activeSpells.mSpells.end(); ++spell) - { - RW(spell->first, true); - RW(spell->second.mTimeStamp, true); - unsigned long effects = spell->second.mEffects.size(); - RW(effects, true); + auto fnRWSpell = [this, &send](ESM::ActiveSpells::TContainer::value_type &spell) { + RW(spell.first, send); + RW(spell.second.mTimeStamp, send); + uint32_t effectsCount; + + if(send) + effectsCount = static_cast(spell.second.mEffects.size()); + + RW(effectsCount, send); - for (std::vector::const_iterator effect = spell->second.mEffects.begin(); - effect != spell->second.mEffects.end(); ++effect) - RW(effect, true); + if(!send) + spell.second.mEffects.resize(effectsCount); + for (auto &&effect : spell.second.mEffects) + RW(effect, send); + }; + + if (send) + for (auto && spell : player->activeSpells.mSpells) + { + fnRWSpell(spell); } else - for (unsigned int i = 0; i < spells; i++) + for (unsigned int i = 0; i < spellCount; i++) { ESM::ActiveSpells::TContainer::value_type spell; - - RW(spell.first, false); - RW(spell.second.mTimeStamp, false); - unsigned long effects; - RW(effects, false); - - ESM::ActiveEffect effect; - for (unsigned int j = 0; j < effects; j++) - { - RW(effect, false); - spell.second.mEffects.push_back(effect); - } + fnRWSpell(spell); player->activeSpells.mSpells.insert(spell); } } diff --git a/components/openmw-mp/Packets/Player/PacketPlayerAttribute.cpp b/components/openmw-mp/Packets/Player/PacketPlayerAttribute.cpp index 0ba1fc1db..03cc51d69 100644 --- a/components/openmw-mp/Packets/Player/PacketPlayerAttribute.cpp +++ b/components/openmw-mp/Packets/Player/PacketPlayerAttribute.cpp @@ -13,23 +13,23 @@ void PacketPlayerAttribute::Packet(RakNet::BitStream *bs, bool send) { PlayerPacket::Packet(bs, send); + unsigned count; if (send) - player->attributeChanges.count = (unsigned int)(player->attributeChanges.attributeIndexes.size()); - else - player->attributeChanges.attributeIndexes.clear(); + count = (unsigned int)(player->attributeChanges.attributeIndexes.size()); - RW(player->attributeChanges.count, send); + RW(count, send); - for (unsigned int i = 0; i < player->attributeChanges.count; i++) + if(!send) { - int attributeId; - - if (send) - attributeId = player->attributeChanges.attributeIndexes.at(i); + player->attributeChanges.attributeIndexes.clear(); + player->attributeChanges.attributeIndexes.resize(count); + } - RW(attributeId, send); + for (auto &&attributeIndex : player->attributeChanges.attributeIndexes) + { + RW(attributeIndex, send); - RW(player->creatureStats.mAttributes[attributeId], send); - RW(player->npcStats.mSkillIncrease[attributeId], send); + RW(player->creatureStats.mAttributes[attributeIndex], send); + RW(player->npcStats.mSkillIncrease[attributeIndex], send); } } diff --git a/components/openmw-mp/Packets/Player/PacketPlayerBook.cpp b/components/openmw-mp/Packets/Player/PacketPlayerBook.cpp index 2e2531fc5..faed80603 100644 --- a/components/openmw-mp/Packets/Player/PacketPlayerBook.cpp +++ b/components/openmw-mp/Packets/Player/PacketPlayerBook.cpp @@ -13,23 +13,21 @@ void PacketPlayerBook::Packet(RakNet::BitStream *bs, bool send) { PlayerPacket::Packet(bs, send); + uint32_t count; + if (send) - player->bookChanges.count = (unsigned int)(player->bookChanges.books.size()); - else - player->bookChanges.books.clear(); + count = static_cast(player->bookChanges.books.size()); - RW(player->bookChanges.count, send); + RW(count, send); - for (unsigned int i = 0; i < player->bookChanges.count; i++) + if(!send) { - Book book; - - if (send) - book = player->bookChanges.books.at(i); - - RW(book.bookId, send, 1); + player->bookChanges.books.clear(); + player->bookChanges.books.resize(count); + } - if (!send) - player->bookChanges.books.push_back(book); + for (auto &&book : player->bookChanges.books) + { + RW(book.bookId, send, true); } } diff --git a/components/openmw-mp/Packets/Player/PacketPlayerCellState.cpp b/components/openmw-mp/Packets/Player/PacketPlayerCellState.cpp index 0546d86d7..30540f7c7 100644 --- a/components/openmw-mp/Packets/Player/PacketPlayerCellState.cpp +++ b/components/openmw-mp/Packets/Player/PacketPlayerCellState.cpp @@ -13,25 +13,24 @@ void mwmp::PacketPlayerCellState::Packet(RakNet::BitStream *bs, bool send) { PlayerPacket::Packet(bs, send); + uint32_t count; + if (send) - player->cellStateChanges.count = (unsigned int)(player->cellStateChanges.cellStates.size()); - else - player->cellStateChanges.cellStates.clear(); + count = static_cast(player->cellStateChanges.cellStates.size()); - RW(player->cellStateChanges.count, send); - for (unsigned int i = 0; i < player->cellStateChanges.count; i++) + RW(count, send); + + if(!send) { - CellState cellState; + player->cellStateChanges.cellStates.clear(); + player->cellStateChanges.cellStates.resize(count); + } - if (send) - cellState = player->cellStateChanges.cellStates.at(i); - + for (auto &&cellState : player->cellStateChanges.cellStates) + { RW(cellState.type, send); - RW(cellState.cell.mData, send, 1); - RW(cellState.cell.mName, send, 1); - - if (!send) - player->cellStateChanges.cellStates.push_back(cellState); + RW(cellState.cell.mData, send, true); + RW(cellState.cell.mName, send, true); } } diff --git a/components/openmw-mp/Packets/Player/PacketPlayerClass.cpp b/components/openmw-mp/Packets/Player/PacketPlayerClass.cpp index e6e89eeae..f7428d690 100644 --- a/components/openmw-mp/Packets/Player/PacketPlayerClass.cpp +++ b/components/openmw-mp/Packets/Player/PacketPlayerClass.cpp @@ -18,8 +18,8 @@ void mwmp::PacketPlayerClass::Packet(RakNet::BitStream *bs, bool send) if (player->charClass.mId.empty()) // custom class { - RW(player->charClass.mName, send, 1); - RW(player->charClass.mDescription, send, 1); - RW(player->charClass.mData, send, 1); + RW(player->charClass.mName, send, true); + RW(player->charClass.mDescription, send, true); + RW(player->charClass.mData, send, true); } } diff --git a/components/openmw-mp/Packets/Player/PacketPlayerDeath.hpp b/components/openmw-mp/Packets/Player/PacketPlayerDeath.hpp index d558a5cfc..ba48a56ee 100644 --- a/components/openmw-mp/Packets/Player/PacketPlayerDeath.hpp +++ b/components/openmw-mp/Packets/Player/PacketPlayerDeath.hpp @@ -22,7 +22,7 @@ namespace mwmp { PlayerPacket::Packet(bs, send); - RW(player->deathReason, send, 1); + RW(player->deathReason, send, true); } }; } diff --git a/components/openmw-mp/Packets/Player/PacketPlayerEquipment.cpp b/components/openmw-mp/Packets/Player/PacketPlayerEquipment.cpp index 07fcfe8e4..faee42358 100644 --- a/components/openmw-mp/Packets/Player/PacketPlayerEquipment.cpp +++ b/components/openmw-mp/Packets/Player/PacketPlayerEquipment.cpp @@ -16,10 +16,10 @@ void PacketPlayerEquipment::Packet(RakNet::BitStream *bs, bool send) { PlayerPacket::Packet(bs, send); - for (int i = 0; i < 19; i++) + for (auto &equipedItem : player->equipedItems) { - RW(player->equipedItems[i].refId, send, 1); - RW(player->equipedItems[i].count, send); - RW(player->equipedItems[i].charge, send); + RW(equipedItem.refId, send, true); + RW(equipedItem.count, send); + RW(equipedItem.charge, send); } } diff --git a/components/openmw-mp/Packets/Player/PacketPlayerFaction.cpp b/components/openmw-mp/Packets/Player/PacketPlayerFaction.cpp index e81750b42..b0c6add95 100644 --- a/components/openmw-mp/Packets/Player/PacketPlayerFaction.cpp +++ b/components/openmw-mp/Packets/Player/PacketPlayerFaction.cpp @@ -15,21 +15,22 @@ void PacketPlayerFaction::Packet(RakNet::BitStream *bs, bool send) RW(player->factionChanges.action, send); + uint32_t count; + if (send) - player->factionChanges.count = (unsigned int)(player->factionChanges.factions.size()); - else - player->factionChanges.factions.clear(); + count = static_cast(player->factionChanges.factions.size()); - RW(player->factionChanges.count, send); + RW(count, send); - for (unsigned int i = 0; i < player->factionChanges.count; i++) + if(!send) { - Faction faction; - - if (send) - faction = player->factionChanges.factions.at(i); + player->factionChanges.factions.clear(); + player->factionChanges.factions.resize(count); + } - RW(faction.factionId, send, 1); + for (auto &&faction : player->factionChanges.factions) + { + RW(faction.factionId, send, true); if (player->factionChanges.action == FactionChanges::RANK) RW(faction.rank, send); @@ -39,8 +40,5 @@ void PacketPlayerFaction::Packet(RakNet::BitStream *bs, bool send) if (player->factionChanges.action == FactionChanges::REPUTATION) RW(faction.reputation, send); - - if (!send) - player->factionChanges.factions.push_back(faction); } } diff --git a/components/openmw-mp/Packets/Player/PacketPlayerInventory.cpp b/components/openmw-mp/Packets/Player/PacketPlayerInventory.cpp index e48c28941..11131d51e 100644 --- a/components/openmw-mp/Packets/Player/PacketPlayerInventory.cpp +++ b/components/openmw-mp/Packets/Player/PacketPlayerInventory.cpp @@ -19,25 +19,23 @@ void PacketPlayerInventory::Packet(RakNet::BitStream *bs, bool send) RW(player->inventoryChanges.action, send); + uint32_t count; + if (send) - player->inventoryChanges.count = (unsigned int) (player->inventoryChanges.items.size()); - else - player->inventoryChanges.items.clear(); + count = static_cast(player->inventoryChanges.items.size()); - RW(player->inventoryChanges.count, send); + RW(count, send); - for (unsigned int i = 0; i < player->inventoryChanges.count; i++) + if(!send) { - Item item; - - if (send) - item = player->inventoryChanges.items.at(i); + player->inventoryChanges.items.clear(); + player->inventoryChanges.items.resize(count); + } - RW(item.refId, send, 1); + for (auto &&item : player->inventoryChanges.items) + { + RW(item.refId, send, true); RW(item.count, send); RW(item.charge, send); - - if (!send) - player->inventoryChanges.items.push_back(item); } } diff --git a/components/openmw-mp/Packets/Player/PacketPlayerJail.cpp b/components/openmw-mp/Packets/Player/PacketPlayerJail.cpp index a265314f2..3ed9cba8d 100644 --- a/components/openmw-mp/Packets/Player/PacketPlayerJail.cpp +++ b/components/openmw-mp/Packets/Player/PacketPlayerJail.cpp @@ -16,6 +16,6 @@ void PacketPlayerJail::Packet(RakNet::BitStream *bs, bool send) RW(player->jailDays, send); RW(player->ignoreJailTeleportation, send); RW(player->ignoreJailSkillIncreases, send); - RW(player->jailProgressText, send, 1); - RW(player->jailEndText, send, 1); + RW(player->jailProgressText, send, true); + RW(player->jailEndText, send, true); } diff --git a/components/openmw-mp/Packets/Player/PacketPlayerJournal.cpp b/components/openmw-mp/Packets/Player/PacketPlayerJournal.cpp index 83f2c1af3..4e50715b1 100644 --- a/components/openmw-mp/Packets/Player/PacketPlayerJournal.cpp +++ b/components/openmw-mp/Packets/Player/PacketPlayerJournal.cpp @@ -13,30 +13,26 @@ void PacketPlayerJournal::Packet(RakNet::BitStream *bs, bool send) { PlayerPacket::Packet(bs, send); + uint32_t count; + if (send) - player->journalChanges.count = (unsigned int)(player->journalChanges.journalItems.size()); - else - player->journalChanges.journalItems.clear(); + count = static_cast(player->journalChanges.journalItems.size()); - RW(player->journalChanges.count, send); + RW(count, send); - for (unsigned int i = 0; i < player->journalChanges.count; i++) + if(!send) { - JournalItem journalItem; - - if (send) - journalItem = player->journalChanges.journalItems.at(i); + player->journalChanges.journalItems.clear(); + player->journalChanges.journalItems.resize(count); + } + for (auto &&journalItem : player->journalChanges.journalItems) + { RW(journalItem.type, send); - RW(journalItem.quest, send, 1); + RW(journalItem.quest, send, true); RW(journalItem.index, send); if (journalItem.type == JournalItem::ENTRY) - { - RW(journalItem.actorRefId, send, 1); - } - - if (!send) - player->journalChanges.journalItems.push_back(journalItem); + RW(journalItem.actorRefId, send, true); } } diff --git a/components/openmw-mp/Packets/Player/PacketPlayerKillCount.cpp b/components/openmw-mp/Packets/Player/PacketPlayerKillCount.cpp index df648dd35..1893304b6 100644 --- a/components/openmw-mp/Packets/Player/PacketPlayerKillCount.cpp +++ b/components/openmw-mp/Packets/Player/PacketPlayerKillCount.cpp @@ -9,25 +9,23 @@ mwmp::PacketPlayerKillCount::PacketPlayerKillCount(RakNet::RakPeerInterface *pee void mwmp::PacketPlayerKillCount::Packet(RakNet::BitStream *bs, bool send) { PlayerPacket::Packet(bs, send); + + uint32_t count; if (send) - player->killChanges.count = (unsigned int)(player->killChanges.kills.size()); - else - player->killChanges.kills.clear(); + count = static_cast(player->killChanges.kills.size()); - RW(player->killChanges.count, send); + RW(count, send); - for (unsigned int i = 0; i < player->killChanges.count; i++) + if(!send) { - Kill kill; - - if (send) - kill = player->killChanges.kills.at(i); + player->killChanges.kills.clear(); + player->killChanges.kills.resize(count); + } - RW(kill.refId, send, 1); + for (auto &&kill : player->killChanges.kills) + { + RW(kill.refId, send, true); RW(kill.number, send); - - if (!send) - player->killChanges.kills.push_back(kill); } } diff --git a/components/openmw-mp/Packets/Player/PacketPlayerMap.cpp b/components/openmw-mp/Packets/Player/PacketPlayerMap.cpp index 9027f55c9..804873c04 100644 --- a/components/openmw-mp/Packets/Player/PacketPlayerMap.cpp +++ b/components/openmw-mp/Packets/Player/PacketPlayerMap.cpp @@ -12,25 +12,23 @@ PacketPlayerMap::PacketPlayerMap(RakNet::RakPeerInterface *peer) : PlayerPacket( void PacketPlayerMap::Packet(RakNet::BitStream *bs, bool send) { PlayerPacket::Packet(bs, send); + + uint32_t count; if (send) - player->mapChanges.count = (unsigned int)(player->mapChanges.cellsExplored.size()); - else - player->mapChanges.cellsExplored.clear(); + count = static_cast(player->mapChanges.cellsExplored.size()); - RW(player->mapChanges.count, send); + RW(count, send); - for (unsigned int i = 0; i < player->mapChanges.count; i++) + if(!send) { - ESM::Cell cellExplored; - - if (send) - cellExplored = player->mapChanges.cellsExplored.at(i); - - RW(cellExplored.mData, send, 1); - RW(cellExplored.mName, send, 1); + player->mapChanges.cellsExplored.clear(); + player->mapChanges.cellsExplored.resize(count); + } - if (!send) - player->mapChanges.cellsExplored.push_back(cellExplored); + for (auto &&cellExplored : player->mapChanges.cellsExplored) + { + RW(cellExplored.mData, send, true); + RW(cellExplored.mName, send, true); } } diff --git a/components/openmw-mp/Packets/Player/PacketPlayerPosition.cpp b/components/openmw-mp/Packets/Player/PacketPlayerPosition.cpp index 379cc4ad9..9dc55b41a 100644 --- a/components/openmw-mp/Packets/Player/PacketPlayerPosition.cpp +++ b/components/openmw-mp/Packets/Player/PacketPlayerPosition.cpp @@ -29,10 +29,10 @@ void PacketPlayerPosition::Packet(RakNet::BitStream *bs, bool send) dir = (player->direction.pos[0] >= 0 ? (unsigned char)(player->direction.pos[0]) : (unsigned char) 0x3) << 2; // pack direction dir += (player->direction.pos[1] >= 0 ? (unsigned char)(player->direction.pos[1]) : (unsigned char) 0x3); } - RW(rot[0], send, 1); - RW(rot[1], send, 1); + RW(rot[0], send, true); + RW(rot[1], send, true); - RW(player->position.pos, send, 1); + RW(player->position.pos, send, true); RW(dir, send); if (!send) diff --git a/components/openmw-mp/Packets/Player/PacketPlayerSkill.cpp b/components/openmw-mp/Packets/Player/PacketPlayerSkill.cpp index f293e9e27..acb692fe7 100644 --- a/components/openmw-mp/Packets/Player/PacketPlayerSkill.cpp +++ b/components/openmw-mp/Packets/Player/PacketPlayerSkill.cpp @@ -17,21 +17,22 @@ PacketPlayerSkill::PacketPlayerSkill(RakNet::RakPeerInterface *peer) : PlayerPac void PacketPlayerSkill::Packet(RakNet::BitStream *bs, bool send) { PlayerPacket::Packet(bs, send); + + uint32_t count; if (send) - player->skillChanges.count = (unsigned int)(player->skillChanges.skillIndexes.size()); - else - player->skillChanges.skillIndexes.clear(); + count = static_cast(player->skillChanges.skillIndexes.size()); - RW(player->skillChanges.count, send); + RW(count, send); - for (unsigned int i = 0; i < player->skillChanges.count; i++) + if(!send) { - int skillId; - - if (send) - skillId = player->skillChanges.skillIndexes.at(i); + player->skillChanges.skillIndexes.clear(); + player->skillChanges.skillIndexes.resize(count); + } + for (auto && skillId : player->skillChanges.skillIndexes) + { RW(skillId, send); RW(player->npcStats.mSkills[skillId], send); } diff --git a/components/openmw-mp/Packets/Player/PacketPlayerSpellbook.cpp b/components/openmw-mp/Packets/Player/PacketPlayerSpellbook.cpp index b9737390d..8f1d4589c 100644 --- a/components/openmw-mp/Packets/Player/PacketPlayerSpellbook.cpp +++ b/components/openmw-mp/Packets/Player/PacketPlayerSpellbook.cpp @@ -15,58 +15,56 @@ void PacketPlayerSpellbook::Packet(RakNet::BitStream *bs, bool send) RW(player->spellbookChanges.action, send); + uint32_t changesCount; + if (send) - player->spellbookChanges.count = (unsigned int) (player->spellbookChanges.spells.size()); - else - player->spellbookChanges.spells.clear(); + changesCount = static_cast(player->spellbookChanges.spells.size()); - RW(player->spellbookChanges.count, send); + RW(changesCount, send); - for (unsigned int i = 0; i < player->spellbookChanges.count; i++) + if(!send) { - ESM::Spell spell; + player->spellbookChanges.spells.clear(); + player->spellbookChanges.spells.resize(changesCount); + } - if (send) - spell = player->spellbookChanges.spells.at(i); + for (auto &&spell : player->spellbookChanges.spells) + { - RW(spell.mId, send, 1); + RW(spell.mId, send, true); if(spell.mId.find("$dynamic") != string::npos) { - RW(spell.mName, send, 1); + RW(spell.mName, send, true); - RW(spell.mData.mType, send, 1); - RW(spell.mData.mCost, send, 1); - RW(spell.mData.mFlags, send, 1); + RW(spell.mData.mType, send, true); + RW(spell.mData.mCost, send, true); + RW(spell.mData.mFlags, send, true); - int effectCount = 0; + uint32_t effectCount; if (send) - effectCount = spell.mEffects.mList.size(); + effectCount = static_cast(spell.mEffects.mList.size()); - RW(effectCount, send, 1); + RW(effectCount, send, true); + + if (!send) + { + spell.mEffects.mList.resize(effectCount); + } - for (unsigned int j = 0; j < effectCount; j++) + for (auto &&effect : spell.mEffects.mList) { - ESM::ENAMstruct effect; - if (send) - effect = spell.mEffects.mList.at(j); - - RW(effect.mEffectID, send, 1); - RW(effect.mSkill, send, 1); - RW(effect.mAttribute, send, 1); - RW(effect.mRange, send, 1); - RW(effect.mArea, send, 1); - RW(effect.mDuration, send, 1); - RW(effect.mMagnMin, send, 1); - RW(effect.mMagnMax, send, 1); - - if(!send) - spell.mEffects.mList.push_back(effect); + + RW(effect.mEffectID, send, true); + RW(effect.mSkill, send, true); + RW(effect.mAttribute, send, true); + RW(effect.mRange, send, true); + RW(effect.mArea, send, true); + RW(effect.mDuration, send, true); + RW(effect.mMagnMin, send, true); + RW(effect.mMagnMax, send, true); } } - - if (!send) - player->spellbookChanges.spells.push_back(spell); } } diff --git a/components/openmw-mp/Packets/Player/PacketPlayerTopic.cpp b/components/openmw-mp/Packets/Player/PacketPlayerTopic.cpp index 4fbdefc60..38b9eab53 100644 --- a/components/openmw-mp/Packets/Player/PacketPlayerTopic.cpp +++ b/components/openmw-mp/Packets/Player/PacketPlayerTopic.cpp @@ -12,24 +12,16 @@ PacketPlayerTopic::PacketPlayerTopic(RakNet::RakPeerInterface *peer) : PlayerPac void PacketPlayerTopic::Packet(RakNet::BitStream *bs, bool send) { PlayerPacket::Packet(bs, send); + + uint32_t count; if (send) - player->topicChanges.count = (unsigned int)(player->topicChanges.topics.size()); - else - player->topicChanges.topics.clear(); + count = static_cast(player->topicChanges.topics.size()); - RW(player->topicChanges.count, send); + RW(count, send); - for (unsigned int i = 0; i < player->topicChanges.count; i++) + for (auto &&topic : player->topicChanges.topics) { - Topic topic; - - if (send) - topic = player->topicChanges.topics.at(i); - - RW(topic.topicId, send, 1); - - if (!send) - player->topicChanges.topics.push_back(topic); + RW(topic.topicId, send, true); } }