From c4949ac5d991ed8ee176815465891fb7b19c2bff Mon Sep 17 00:00:00 2001 From: Koncord Date: Tue, 2 Jan 2018 12:44:53 +0800 Subject: [PATCH] [General] Change regular enums to enum class --- apps/openmw-mp/CellController.cpp | 2 +- apps/openmw-mp/CellState.cpp | 6 ++- apps/openmw-mp/CellState.hpp | 2 +- apps/openmw-mp/Factions.cpp | 4 +- apps/openmw-mp/Factions.hpp | 4 +- apps/openmw-mp/GUI.cpp | 10 ++-- apps/openmw-mp/Inventory.cpp | 24 ++++----- apps/openmw-mp/Inventory.hpp | 4 +- apps/openmw-mp/Object.cpp | 6 +-- apps/openmw-mp/Player.cpp | 2 +- apps/openmw-mp/Quests.cpp | 4 +- apps/openmw-mp/Quests.hpp | 4 +- .../processors/world/ProcessorContainer.hpp | 4 +- apps/openmw/mwgui/container.cpp | 6 +-- apps/openmw/mwmechanics/actors.cpp | 2 +- apps/openmw/mwmechanics/aicombat.cpp | 10 ++-- apps/openmw/mwmechanics/character.cpp | 4 +- apps/openmw/mwmp/Cell.cpp | 4 +- apps/openmw/mwmp/GUIController.cpp | 2 +- apps/openmw/mwmp/LocalActor.cpp | 4 +- apps/openmw/mwmp/LocalPlayer.cpp | 32 ++++++------ apps/openmw/mwmp/LocalPlayer.hpp | 2 +- apps/openmw/mwmp/MechanicsHelper.cpp | 4 +- apps/openmw/mwmp/WorldEvent.cpp | 12 ++--- .../player/ProcessorGUIMessageBox.hpp | 12 ++--- .../player/ProcessorPlayerInventory.hpp | 5 +- .../player/ProcessorPlayerSpellbook.hpp | 7 ++- .../processors/world/ProcessorContainer.hpp | 4 +- apps/openmw/mwworld/scene.cpp | 4 +- components/openmw-mp/Base/BaseEvent.hpp | 12 ++--- components/openmw-mp/Base/BasePlayer.hpp | 49 ++++++++++--------- components/openmw-mp/Base/BaseStructs.hpp | 22 +++++---- .../openmw-mp/Packets/PacketPreInit.cpp | 35 +++++++------ .../Packets/Player/PacketGUIBoxes.cpp | 4 +- .../Packets/Player/PacketPlayerFaction.cpp | 6 +-- .../Packets/Player/PacketPlayerJournal.cpp | 2 +- 36 files changed, 166 insertions(+), 154 deletions(-) diff --git a/apps/openmw-mp/CellController.cpp b/apps/openmw-mp/CellController.cpp index d62b07e1c..7450b5446 100644 --- a/apps/openmw-mp/CellController.cpp +++ b/apps/openmw-mp/CellController.cpp @@ -140,7 +140,7 @@ void CellController::update(Player *player) { for (auto cell : player->cellStateChanges.cellStates) { - if (cell.type == mwmp::CellState::LOAD) + if (cell.type == mwmp::CellState::Type::Load) { Cell *c = addCell(cell.cell); c->addPlayer(player); diff --git a/apps/openmw-mp/CellState.cpp b/apps/openmw-mp/CellState.cpp index e1693c4bd..04f62c6c8 100644 --- a/apps/openmw-mp/CellState.cpp +++ b/apps/openmw-mp/CellState.cpp @@ -6,6 +6,8 @@ #include "CellState.hpp" +#include + void CellState::Init(LuaState &lua) { lua.getState()->new_usertype("CellState", @@ -14,12 +16,12 @@ void CellState::Init(LuaState &lua) ); } -CellState::CellState(mwmp::CellState state) : state(state) +CellState::CellState(mwmp::CellState state) : state(std::move(state)) { } -int CellState::getStateType() const +mwmp::CellState::Type CellState::getStateType() const { return state.type; } diff --git a/apps/openmw-mp/CellState.hpp b/apps/openmw-mp/CellState.hpp index 8e11a81a2..c297822c8 100644 --- a/apps/openmw-mp/CellState.hpp +++ b/apps/openmw-mp/CellState.hpp @@ -16,7 +16,7 @@ public: explicit CellState(mwmp::CellState state); public: - int getStateType() const; + mwmp::CellState::Type getStateType() const; std::string getDescription() const; private: diff --git a/apps/openmw-mp/Factions.cpp b/apps/openmw-mp/Factions.cpp index 3761429a0..1dedbf17f 100644 --- a/apps/openmw-mp/Factions.cpp +++ b/apps/openmw-mp/Factions.cpp @@ -40,12 +40,12 @@ void Factions::processUpdate() clear(); } -int Factions::getFactionChangesAction() const +mwmp::FactionChanges::Type Factions::getFactionChangesAction() const { return player->factionChanges.action; } -void Factions::setFactionChangesAction(int action) +void Factions::setFactionChangesAction(mwmp::FactionChanges::Type action) { player->factionChanges.action = action; setChanged(); diff --git a/apps/openmw-mp/Factions.hpp b/apps/openmw-mp/Factions.hpp index 28c43a53c..f695d3620 100644 --- a/apps/openmw-mp/Factions.hpp +++ b/apps/openmw-mp/Factions.hpp @@ -43,8 +43,8 @@ public: ~Factions(); - int getFactionChangesAction() const; - void setFactionChangesAction(int action); + mwmp::FactionChanges::Type getFactionChangesAction() const; + void setFactionChangesAction(mwmp::FactionChanges::Type action); void addFaction(Faction faction); Faction getFaction(int id) const; diff --git a/apps/openmw-mp/GUI.cpp b/apps/openmw-mp/GUI.cpp index bfb8316c4..08b6be7a3 100644 --- a/apps/openmw-mp/GUI.cpp +++ b/apps/openmw-mp/GUI.cpp @@ -39,7 +39,7 @@ void GUI::messageBox(int id, const char *label) { player->guiMessageBox.id = id; player->guiMessageBox.label = label; - player->guiMessageBox.type = Player::GUIMessageBox::MessageBox; + player->guiMessageBox.type = Player::GUIMessageBox::Type::MessageBox; setChanged(); } @@ -49,7 +49,7 @@ void GUI::customMessageBox(int id, const char *label, const char *buttons) player->guiMessageBox.id = id; player->guiMessageBox.label = label; player->guiMessageBox.buttons = buttons; - player->guiMessageBox.type = Player::GUIMessageBox::CustomMessageBox; + player->guiMessageBox.type = Player::GUIMessageBox::Type::CustomMessageBox; setChanged(); } @@ -58,7 +58,7 @@ void GUI::inputDialog(int id, const char *label) { player->guiMessageBox.id = id; player->guiMessageBox.label = label; - player->guiMessageBox.type = Player::GUIMessageBox::InputDialog; + player->guiMessageBox.type = Player::GUIMessageBox::Type::InputDialog; setChanged(); } @@ -68,7 +68,7 @@ void GUI::passwordDialog(int id, const char *label, const char *note) player->guiMessageBox.id = id; player->guiMessageBox.label = label; player->guiMessageBox.note = note; - player->guiMessageBox.type = Player::GUIMessageBox::PasswordDialog; + player->guiMessageBox.type = Player::GUIMessageBox::Type::PasswordDialog; setChanged(); } @@ -78,7 +78,7 @@ void GUI::listBox(int id, const char *label, const char *items) player->guiMessageBox.id = id; player->guiMessageBox.label = label; player->guiMessageBox.data = items; - player->guiMessageBox.type = Player::GUIMessageBox::ListBox; + player->guiMessageBox.type = Player::GUIMessageBox::Type::ListBox; setChanged(); } diff --git a/apps/openmw-mp/Inventory.cpp b/apps/openmw-mp/Inventory.cpp index 8e5e91886..f3391d084 100644 --- a/apps/openmw-mp/Inventory.cpp +++ b/apps/openmw-mp/Inventory.cpp @@ -33,7 +33,7 @@ void Inventory::Init(LuaState &lua) ); } -Inventory::Inventory(NetActor *actor) : netActor(actor), equipmentChanged(false), inventoryChanged(0) +Inventory::Inventory(NetActor *actor) : netActor(actor), equipmentChanged(false), inventoryChanged(mwmp::InventoryChanges::Type::None) { printf("Inventory::Inventory()\n"); } @@ -89,7 +89,7 @@ void Inventory::update() void Inventory::InitializeInventoryChanges() { netActor->getNetCreature()->inventoryChanges.items.clear(); - netActor->getNetCreature()->inventoryChanges.action = mwmp::InventoryChanges::SET; + netActor->getNetCreature()->inventoryChanges.action = mwmp::InventoryChanges::Type::Set; } int Inventory::getChangesSize() const @@ -121,9 +121,9 @@ void Inventory::unequipItem( unsigned short slot) void Inventory::addItem(const std::string &refId, unsigned int count, int charge, int enchantmentCharge) { - if (inventoryChanged == mwmp::InventoryChanges::REMOVE) + if (inventoryChanged == mwmp::InventoryChanges::Type::Remove) return; - if (inventoryChanged == 0) + if (inventoryChanged == mwmp::InventoryChanges::Type::None) InitializeInventoryChanges(); mwmp::Item item; @@ -133,17 +133,17 @@ void Inventory::addItem(const std::string &refId, unsigned int count, int charge item.enchantmentCharge = enchantmentCharge; netActor->getNetCreature()->inventoryChanges.items.push_back(item); - netActor->getNetCreature()->inventoryChanges.action = mwmp::InventoryChanges::ADD; - if (inventoryChanged == 0 && netActor->isPlayer()) + netActor->getNetCreature()->inventoryChanges.action = mwmp::InventoryChanges::Type::Add; + if (inventoryChanged == mwmp::InventoryChanges::Type::None && netActor->isPlayer()) netActor->toPlayer()->addToUpdateQueue(); inventoryChanged = netActor->getNetCreature()->inventoryChanges.action; } void Inventory::removeItem(const std::string &refId, unsigned short count) { - if (inventoryChanged == mwmp::InventoryChanges::ADD) + if (inventoryChanged == mwmp::InventoryChanges::Type::Add) return; - if (inventoryChanged == 0) + if (inventoryChanged == mwmp::InventoryChanges::Type::None) InitializeInventoryChanges(); mwmp::Item item; @@ -151,8 +151,8 @@ void Inventory::removeItem(const std::string &refId, unsigned short count) item.count = count; netActor->getNetCreature()->inventoryChanges.items.push_back(item); - netActor->getNetCreature()->inventoryChanges.action = mwmp::InventoryChanges::REMOVE; - if (inventoryChanged == 0 && netActor->isPlayer()) + netActor->getNetCreature()->inventoryChanges.action = mwmp::InventoryChanges::Type::Remove; + if (inventoryChanged == mwmp::InventoryChanges::Type::None && netActor->isPlayer()) netActor->toPlayer()->addToUpdateQueue(); inventoryChanged = netActor->getNetCreature()->inventoryChanges.action; } @@ -191,10 +191,10 @@ bool Inventory::isEquipmentChanged() void Inventory::resetInventoryFlag() { - inventoryChanged = 0; + inventoryChanged = mwmp::InventoryChanges::Type::None; } -int Inventory::inventoryChangeType() +mwmp::InventoryChanges::Type Inventory::inventoryChangeType() { return inventoryChanged; } diff --git a/apps/openmw-mp/Inventory.hpp b/apps/openmw-mp/Inventory.hpp index eb9901e5e..da3ee3046 100644 --- a/apps/openmw-mp/Inventory.hpp +++ b/apps/openmw-mp/Inventory.hpp @@ -16,7 +16,7 @@ public: static void Init(LuaState &lua); bool isEquipmentChanged(); void resetEquipmentFlag(); - int inventoryChangeType(); + mwmp::InventoryChanges::Type inventoryChangeType(); void resetInventoryFlag(); public: explicit Inventory(NetActor *netActor); @@ -57,7 +57,7 @@ private: // not controlled pointer NetActor *netActor; bool equipmentChanged; - int inventoryChanged; + mwmp::InventoryChanges::Type inventoryChanged; }; diff --git a/apps/openmw-mp/Object.cpp b/apps/openmw-mp/Object.cpp index eea5419f1..ff6b1a0b2 100644 --- a/apps/openmw-mp/Object.cpp +++ b/apps/openmw-mp/Object.cpp @@ -350,7 +350,7 @@ void ObjectController::sendObjects(shared_ptr player, shared_ptrguid; e.cell = cell; } @@ -514,7 +514,7 @@ void ObjectController::sendContainers(shared_ptr player, shared_ptrguid; for (auto &object : *objects) @@ -535,7 +535,7 @@ void ObjectController::sendContainers(shared_ptr player, shared_ptr player) { mwmp::BaseEvent event; - event.action = mwmp::BaseEvent::REQUEST; + event.action = mwmp::BaseEvent::Action::Request; event.guid = player->guid; event.cell = player->cell; diff --git a/apps/openmw-mp/Player.cpp b/apps/openmw-mp/Player.cpp index bee49eb61..380649d11 100644 --- a/apps/openmw-mp/Player.cpp +++ b/apps/openmw-mp/Player.cpp @@ -218,7 +218,7 @@ void Player::update() inventory.resetEquipmentFlag(); } - if (inventory.inventoryChangeType() != 0) + if (inventory.inventoryChangeType() != mwmp::InventoryChanges::Type::None) { auto packet = plPCtrl->GetPacket(ID_PLAYER_INVENTORY); packet->setPlayer(this); diff --git a/apps/openmw-mp/Quests.cpp b/apps/openmw-mp/Quests.cpp index f7a3e079a..7d1e4133b 100644 --- a/apps/openmw-mp/Quests.cpp +++ b/apps/openmw-mp/Quests.cpp @@ -50,12 +50,12 @@ void JournalItem::setIndex(int index) item.index = index; } -int JournalItem::getType() const +mwmp::JournalItem::Type JournalItem::getType() const { return item.type; } -void JournalItem::setType(int type) +void JournalItem::setType(mwmp::JournalItem::Type type) { item.type = type; } diff --git a/apps/openmw-mp/Quests.hpp b/apps/openmw-mp/Quests.hpp index d6eb67276..a2b678258 100644 --- a/apps/openmw-mp/Quests.hpp +++ b/apps/openmw-mp/Quests.hpp @@ -25,8 +25,8 @@ public: int getIndex() const; void setIndex(int index); - int getType() const; - void setType(int type); + mwmp::JournalItem::Type getType() const; + void setType(mwmp::JournalItem::Type type); std::string getActorRefId() const; void setActorRefId(const std::string &refid); diff --git a/apps/openmw-mp/processors/world/ProcessorContainer.hpp b/apps/openmw-mp/processors/world/ProcessorContainer.hpp index fc5892eeb..9b12f5950 100644 --- a/apps/openmw-mp/processors/world/ProcessorContainer.hpp +++ b/apps/openmw-mp/processors/world/ProcessorContainer.hpp @@ -18,12 +18,12 @@ namespace mwmp void Do(WorldPacket &packet, const std::shared_ptr &player, BaseEvent &event) override { LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Received %s from %s", strPacketID.c_str(), player->npc.mName.c_str()); - LOG_APPEND(Log::LOG_INFO, "- action: %i", event.action); + LOG_APPEND(Log::LOG_INFO, "- action: %i", (int) event.action); // Until we have a timestamp-based system, send packets pertaining to more // than one container (i.e. replies to server requests for container contents) // only to players who have the container's cell loaded - if (event.action == BaseEvent::SET && event.worldObjects.size() > 1) + if (event.action == BaseEvent::Action::Set && event.worldObjects.size() > 1) { Cell *serverCell = CellController::get().getCell(event.cell); diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index 54b248a0d..221286a0c 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -114,7 +114,7 @@ namespace MWGui mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->getWorldEvent(); worldEvent->reset(); worldEvent->cell = *mPtr.getCell()->getCell(); - worldEvent->action = mwmp::BaseEvent::REMOVE; + worldEvent->action = mwmp::BaseEvent::Action::Remove; mwmp::WorldObject worldObject; worldObject.refId = mPtr.getCellRef().getRefId(); @@ -160,7 +160,7 @@ namespace MWGui mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->getWorldEvent(); worldEvent->reset(); worldEvent->cell = *mPtr.getCell()->getCell(); - worldEvent->action = mwmp::BaseEvent::ADD; + worldEvent->action = mwmp::BaseEvent::Action::Add; mwmp::WorldObject worldObject; worldObject.refId = mPtr.getCellRef().getRefId(); @@ -330,7 +330,7 @@ namespace MWGui mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->getWorldEvent(); worldEvent->reset(); worldEvent->cell = *mPtr.getCell()->getCell(); - worldEvent->action = mwmp::BaseEvent::SET; + worldEvent->action = mwmp::BaseEvent::Action::Set; mwmp::WorldObject worldObject; worldObject.refId = mPtr.getCellRef().getRefId(); diff --git a/apps/openmw/mwmechanics/actors.cpp b/apps/openmw/mwmechanics/actors.cpp index aced04812..1f4ef6f7c 100644 --- a/apps/openmw/mwmechanics/actors.cpp +++ b/apps/openmw/mwmechanics/actors.cpp @@ -1330,7 +1330,7 @@ namespace MWMechanics if (localAttack->pressed != state) { MechanicsHelper::resetAttack(localAttack); - localAttack->type = mwmp::Attack::MELEE; + localAttack->type = mwmp::Attack::Type::Melee; localAttack->pressed = state; localAttack->shouldSend = true; } diff --git a/apps/openmw/mwmechanics/aicombat.cpp b/apps/openmw/mwmechanics/aicombat.cpp index 6dd98905a..19f462b37 100644 --- a/apps/openmw/mwmechanics/aicombat.cpp +++ b/apps/openmw/mwmechanics/aicombat.cpp @@ -222,7 +222,7 @@ namespace MWMechanics if (localAttack && localAttack->pressed != storage.mAttack) { MechanicsHelper::resetAttack(localAttack); - localAttack->type = mwmp::Attack::MELEE; + localAttack->type = mwmp::Attack::Type::Melee; localAttack->pressed = storage.mAttack; localAttack->shouldSend = true; } @@ -291,10 +291,10 @@ namespace MWMechanics */ mwmp::Attack *localAttack = MechanicsHelper::getLocalAttack(actor); - if (localAttack && localAttack->pressed != false) + if (localAttack && localAttack->pressed) { MechanicsHelper::resetAttack(localAttack); - localAttack->type = mwmp::Attack::MELEE; + localAttack->type = mwmp::Attack::Type::Melee; localAttack->pressed = false; localAttack->shouldSend = true; } @@ -644,10 +644,10 @@ namespace MWMechanics */ mwmp::Attack *localAttack = MechanicsHelper::getLocalAttack(actor); - if (localAttack && localAttack->pressed != true) + if (localAttack && !localAttack->pressed) { MechanicsHelper::resetAttack(localAttack); - localAttack->type = mwmp::Attack::MELEE; + localAttack->type = mwmp::Attack::Type::Melee; localAttack->pressed = true; localAttack->shouldSend = true; } diff --git a/apps/openmw/mwmechanics/character.cpp b/apps/openmw/mwmechanics/character.cpp index fbcb7371a..9289ba32d 100644 --- a/apps/openmw/mwmechanics/character.cpp +++ b/apps/openmw/mwmechanics/character.cpp @@ -1098,7 +1098,7 @@ bool CharacterController::updateCreatureState() if (localAttack) { MechanicsHelper::resetAttack(localAttack); - localAttack->type = mwmp::Attack::MAGIC; + localAttack->type = mwmp::Attack::Type::Magic; localAttack->pressed = true; localAttack->shouldSend = true; } @@ -1379,7 +1379,7 @@ bool CharacterController::updateWeaponState() if (localAttack) { MechanicsHelper::resetAttack(localAttack); - localAttack->type = mwmp::Attack::MAGIC; + localAttack->type = mwmp::Attack::Type::Magic; localAttack->pressed = true; localAttack->shouldSend = true; } diff --git a/apps/openmw/mwmp/Cell.cpp b/apps/openmw/mwmp/Cell.cpp index 239f6c6ff..efd4f6d3d 100644 --- a/apps/openmw/mwmp/Cell.cpp +++ b/apps/openmw/mwmp/Cell.cpp @@ -255,12 +255,12 @@ void Cell::readAttack(ActorList& actorList) // Set the correct drawState here if we've somehow we've missed a previous // AnimFlags packet - if (actor->attack.type == mwmp::Attack::MELEE && actor->drawState != 1) + if (actor->attack.type == mwmp::Attack::Type::Melee && actor->drawState != 1) { actor->drawState = 1; actor->setAnimFlags(); } - else if (actor->attack.type == mwmp::Attack::MAGIC && actor->drawState != 2) + else if (actor->attack.type == mwmp::Attack::Type::Magic && actor->drawState != 2) { actor->drawState = 2; actor->setAnimFlags(); diff --git a/apps/openmw/mwmp/GUIController.cpp b/apps/openmw/mwmp/GUIController.cpp index e4c3170e5..920a965a4 100644 --- a/apps/openmw/mwmp/GUIController.cpp +++ b/apps/openmw/mwmp/GUIController.cpp @@ -177,7 +177,7 @@ void mwmp::GUIController::showInputBox(const BasePlayer::GUIMessageBox &guiMessa mInputBox = 0; mInputBox = new TextInputDialog(); - mInputBox->setEditPassword(guiMessageBox.type == BasePlayer::GUIMessageBox::PasswordDialog); + mInputBox->setEditPassword(guiMessageBox.type == BasePlayer::GUIMessageBox::Type::PasswordDialog); mInputBox->setTextLabel(guiMessageBox.label); mInputBox->setTextNote(guiMessageBox.note); diff --git a/apps/openmw/mwmp/LocalActor.cpp b/apps/openmw/mwmp/LocalActor.cpp index e45f4b8c5..023b6b383 100644 --- a/apps/openmw/mwmp/LocalActor.cpp +++ b/apps/openmw/mwmp/LocalActor.cpp @@ -31,7 +31,7 @@ LocalActor::LocalActor() wasForceMoveJumping = false; wasFlying = false; - attack.type = Attack::MELEE; + attack.type = Attack::Type::Melee; attack.shouldSend = false; attack.instant = false; @@ -237,7 +237,7 @@ void LocalActor::updateAttack() { if (attack.shouldSend) { - if (attack.type == Attack::MAGIC) + if (attack.type == Attack::Type::Magic) { MWMechanics::CreatureStats &attackerStats = ptr.getClass().getCreatureStats(ptr); attack.spellId = attackerStats.getSpells().getSelectedSpell(); diff --git a/apps/openmw/mwmp/LocalPlayer.cpp b/apps/openmw/mwmp/LocalPlayer.cpp index 0b9015492..f3300eff5 100644 --- a/apps/openmw/mwmp/LocalPlayer.cpp +++ b/apps/openmw/mwmp/LocalPlayer.cpp @@ -538,7 +538,7 @@ void LocalPlayer::updateAttack() { if (attack.shouldSend) { - if (attack.type == Attack::MAGIC) + if (attack.type == Attack::Type::Magic) { attack.spellId = MWBase::Environment::get().getWindowManager()->getSelectedSpell(); @@ -690,7 +690,7 @@ void LocalPlayer::addJournalItems() { MWWorld::Ptr ptrFound; - if (journalItem.type == JournalItem::ENTRY) + if (journalItem.type == JournalItem::Type::Entry) { ptrFound = MWBase::Environment::get().getWorld()->searchPtr(journalItem.actorRefId, false); @@ -700,7 +700,7 @@ void LocalPlayer::addJournalItems() try { - if (journalItem.type == JournalItem::ENTRY) + if (journalItem.type == JournalItem::Type::Entry) MWBase::Environment::get().getJournal()->addEntry(journalItem.quest, journalItem.index, ptrFound); else MWBase::Environment::get().getJournal()->setJournalIndex(journalItem.quest, journalItem.index); @@ -1080,7 +1080,7 @@ void LocalPlayer::setFactions() if (!ptrNpcStats.isInFaction(faction.factionId)) ptrNpcStats.joinFaction(faction.factionId); - if (factionChanges.action == mwmp::FactionChanges::RANK) + if (factionChanges.action == mwmp::FactionChanges::Type::Rank) { // While the faction rank is different in the packet than in the NpcStats, // adjust the NpcStats accordingly @@ -1092,7 +1092,7 @@ void LocalPlayer::setFactions() ptrNpcStats.lowerRank(faction.factionId); } } - else if (factionChanges.action == mwmp::FactionChanges::EXPULSION) + else if (factionChanges.action == mwmp::FactionChanges::Type::Expulsion) { // If the expelled state is different in the packet than in the NpcStats, // adjust the NpcStats accordingly @@ -1105,7 +1105,7 @@ void LocalPlayer::setFactions() } } - else if (factionChanges.action == mwmp::FactionChanges::REPUTATION) + else if (factionChanges.action == mwmp::FactionChanges::Type::Reputation) ptrNpcStats.setFactionReputation(faction.factionId, faction.reputation); } } @@ -1183,7 +1183,7 @@ void LocalPlayer::sendInventory() inventoryChanges.items.push_back(item); } - inventoryChanges.action = InventoryChanges::SET; + inventoryChanges.action = InventoryChanges::Type::Set; getNetworking()->getPlayerPacket(ID_PLAYER_INVENTORY)->setPlayer(this); getNetworking()->getPlayerPacket(ID_PLAYER_INVENTORY)->Send(); } @@ -1202,7 +1202,7 @@ void LocalPlayer::sendSpellbook() spellbookChanges.spells.push_back(*spell.first); } - spellbookChanges.action = SpellbookChanges::SET; + spellbookChanges.action = SpellbookChanges::Type::Set; getNetworking()->getPlayerPacket(ID_PLAYER_SPELLBOOK)->setPlayer(this); getNetworking()->getPlayerPacket(ID_PLAYER_SPELLBOOK)->Send(); } @@ -1225,7 +1225,7 @@ void LocalPlayer::sendSpellAddition(std::string id) spell.mId = id; spellbookChanges.spells.push_back(spell); - spellbookChanges.action = SpellbookChanges::ADD; + spellbookChanges.action = SpellbookChanges::Type::Add; getNetworking()->getPlayerPacket(ID_PLAYER_SPELLBOOK)->setPlayer(this); getNetworking()->getPlayerPacket(ID_PLAYER_SPELLBOOK)->Send(); } @@ -1241,7 +1241,7 @@ void LocalPlayer::sendSpellRemoval(std::string id) spell.mId = id; spellbookChanges.spells.push_back(spell); - spellbookChanges.action = SpellbookChanges::REMOVE; + spellbookChanges.action = SpellbookChanges::Type::Remove; getNetworking()->getPlayerPacket(ID_PLAYER_SPELLBOOK)->setPlayer(this); getNetworking()->getPlayerPacket(ID_PLAYER_SPELLBOOK)->Send(); } @@ -1295,7 +1295,7 @@ void LocalPlayer::sendJournalEntry(const std::string& quest, int index, const MW journalChanges.journalItems.clear(); mwmp::JournalItem journalItem; - journalItem.type = JournalItem::ENTRY; + journalItem.type = JournalItem::Type::Entry; journalItem.quest = quest; journalItem.index = index; journalItem.actorRefId = actor.getCellRef().getRefId(); @@ -1311,7 +1311,7 @@ void LocalPlayer::sendJournalIndex(const std::string& quest, int index) journalChanges.journalItems.clear(); mwmp::JournalItem journalItem; - journalItem.type = JournalItem::INDEX; + journalItem.type = JournalItem::Type::Index; journalItem.quest = quest; journalItem.index = index; @@ -1324,7 +1324,7 @@ void LocalPlayer::sendJournalIndex(const std::string& quest, int index) void LocalPlayer::sendFactionRank(const std::string& factionId, int rank) { factionChanges.factions.clear(); - factionChanges.action = FactionChanges::RANK; + factionChanges.action = FactionChanges::Type::Rank; mwmp::Faction faction; faction.factionId = factionId; @@ -1339,7 +1339,7 @@ void LocalPlayer::sendFactionRank(const std::string& factionId, int rank) void LocalPlayer::sendFactionExpulsionState(const std::string& factionId, bool isExpelled) { factionChanges.factions.clear(); - factionChanges.action = FactionChanges::EXPULSION; + factionChanges.action = FactionChanges::Type::Expulsion; mwmp::Faction faction; faction.factionId = factionId; @@ -1354,7 +1354,7 @@ void LocalPlayer::sendFactionExpulsionState(const std::string& factionId, bool i void LocalPlayer::sendFactionReputation(const std::string& factionId, int reputation) { factionChanges.factions.clear(); - factionChanges.action = FactionChanges::REPUTATION; + factionChanges.action = FactionChanges::Type::Reputation; mwmp::Faction faction; faction.factionId = factionId; @@ -1439,7 +1439,7 @@ void LocalPlayer::clearCurrentContainer() currentContainer.mpNum = 0; } -void LocalPlayer::storeCellState(const ESM::Cell& cell, int stateType) +void LocalPlayer::storeCellState(const ESM::Cell& cell, mwmp::CellState::Type stateType) { std::vector::iterator iter; diff --git a/apps/openmw/mwmp/LocalPlayer.hpp b/apps/openmw/mwmp/LocalPlayer.hpp index 9a19fb4a5..442260bd0 100644 --- a/apps/openmw/mwmp/LocalPlayer.hpp +++ b/apps/openmw/mwmp/LocalPlayer.hpp @@ -89,7 +89,7 @@ namespace mwmp void clearCurrentContainer(); void storeCurrentContainer(const MWWorld::Ptr& container); - void storeCellState(const ESM::Cell& cell, int stateType); + void storeCellState(const ESM::Cell& cell, mwmp::CellState::Type stateType); void playAnimation(); void playSpeech(); diff --git a/apps/openmw/mwmp/MechanicsHelper.cpp b/apps/openmw/mwmp/MechanicsHelper.cpp index 9092eec9c..37c728958 100644 --- a/apps/openmw/mwmp/MechanicsHelper.cpp +++ b/apps/openmw/mwmp/MechanicsHelper.cpp @@ -167,7 +167,7 @@ void MechanicsHelper::processAttack(Attack attack, const MWWorld::Ptr& attacker) } // Get the weapon used (if hand-to-hand, weapon = inv.end()) - if (attack.type == attack.MELEE) + if (attack.type == Attack::Type::Melee) { MWWorld::Ptr weapon; @@ -201,7 +201,7 @@ void MechanicsHelper::processAttack(Attack attack, const MWWorld::Ptr& attacker) attack.success); } } - else if (attack.type == attack.MAGIC) + else if (attack.type == Attack::Type::Magic) { if (attack.instant) { diff --git a/apps/openmw/mwmp/WorldEvent.cpp b/apps/openmw/mwmp/WorldEvent.cpp index 46420ee7c..04fa2cd1d 100644 --- a/apps/openmw/mwmp/WorldEvent.cpp +++ b/apps/openmw/mwmp/WorldEvent.cpp @@ -69,13 +69,13 @@ void WorldEvent::editContainers(MWWorld::CellStore* cellStore) MWWorld::ContainerStore& containerStore = ptrFound.getClass().getContainerStore(ptrFound); // If we are setting the entire contents, clear the current ones - if (action == BaseEvent::SET) + if (action == BaseEvent::Action::Set) containerStore.clear(); MWWorld::Ptr ownerPtr = MWBase::Environment::get().getWorld()->getPlayerPtr(); for (const auto &containerItem : worldObject.containerItems) { - if (action == BaseEvent::ADD || action == BaseEvent::SET) + if (action == BaseEvent::Action::Add || action == BaseEvent::Action::Set) { // Create a ManualRef to be able to set item charge MWWorld::ManualRef ref(MWBase::Environment::get().getWorld()->getStore(), containerItem.refId, 1); @@ -92,7 +92,7 @@ void WorldEvent::editContainers(MWWorld::CellStore* cellStore) containerStore.add(newPtr, containerItem.count, ownerPtr, true); } - else if (action == BaseEvent::REMOVE) + else if (action == BaseEvent::Action::Remove) { // We have to find the right item ourselves because ContainerStore has no method // accounting for charge @@ -122,8 +122,8 @@ void WorldEvent::editContainers(MWWorld::CellStore* cellStore) // Was this a SET or ADD action on an actor's container, and are we the authority // over the actor? If so, autoequip the actor - if ((action == BaseEvent::ADD || action == BaseEvent::SET) && ptrFound.getClass().isActor() && - mwmp::Main::get().getCellController()->isLocalActor(ptrFound)) + if ((action == BaseEvent::Action::Add || action == BaseEvent::Action::Set) && ptrFound.getClass().isActor() + && mwmp::Main::get().getCellController()->isLocalActor(ptrFound)) { MWWorld::InventoryStore& invStore = ptrFound.getClass().getInventoryStore(ptrFound); invStore.autoEquip(ptrFound); @@ -941,7 +941,7 @@ void WorldEvent::sendContainers(MWWorld::CellStore* cellStore) { reset(); cell = *cellStore->getCell(); - action = BaseEvent::SET; + action = BaseEvent::Action::Set; MWWorld::CellRefList *containerList = cellStore->getContainers(); diff --git a/apps/openmw/mwmp/processors/player/ProcessorGUIMessageBox.hpp b/apps/openmw/mwmp/processors/player/ProcessorGUIMessageBox.hpp index 4f79a491e..f200804e6 100644 --- a/apps/openmw/mwmp/processors/player/ProcessorGUIMessageBox.hpp +++ b/apps/openmw/mwmp/processors/player/ProcessorGUIMessageBox.hpp @@ -22,22 +22,22 @@ namespace mwmp { if (isLocal()) { - LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "ID_GUI_MESSAGEBOX, Type %d, MSG %s", player->guiMessageBox.type, + LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "ID_GUI_MESSAGEBOX, Type %d, MSG %s", (int) player->guiMessageBox.type, player->guiMessageBox.label.c_str()); switch(player->guiMessageBox.type) { - case BasePlayer::GUIMessageBox::MessageBox: + case BasePlayer::GUIMessageBox::Type::MessageBox: Main::get().getGUIController()->showMessageBox(player->guiMessageBox); break; - case BasePlayer::GUIMessageBox::CustomMessageBox: + case BasePlayer::GUIMessageBox::Type::CustomMessageBox: Main::get().getGUIController()->showCustomMessageBox(player->guiMessageBox); break; - case BasePlayer::GUIMessageBox::InputDialog: - case BasePlayer::GUIMessageBox::PasswordDialog: + case BasePlayer::GUIMessageBox::Type::InputDialog: + case BasePlayer::GUIMessageBox::Type::PasswordDialog: Main::get().getGUIController()->showInputBox(player->guiMessageBox); break; - case BasePlayer::GUIMessageBox::ListBox: + case BasePlayer::GUIMessageBox::Type::ListBox: Main::get().getGUIController()->showDialogList(player->guiMessageBox); break; } diff --git a/apps/openmw/mwmp/processors/player/ProcessorPlayerInventory.hpp b/apps/openmw/mwmp/processors/player/ProcessorPlayerInventory.hpp index e0def5aa1..1e913a912 100644 --- a/apps/openmw/mwmp/processors/player/ProcessorPlayerInventory.hpp +++ b/apps/openmw/mwmp/processors/player/ProcessorPlayerInventory.hpp @@ -28,11 +28,10 @@ namespace mwmp else { LocalPlayer &localPlayer = static_cast(*player); - int inventoryAction = localPlayer.inventoryChanges.action; - if (inventoryAction == InventoryChanges::ADD) + if (localPlayer.inventoryChanges.action == InventoryChanges::Type::Add) localPlayer.addItems(); - else if (inventoryAction == InventoryChanges::REMOVE) + else if (localPlayer.inventoryChanges.action == InventoryChanges::Type::Remove) localPlayer.removeItems(); else // InventoryChanges::SET localPlayer.setInventory(); diff --git a/apps/openmw/mwmp/processors/player/ProcessorPlayerSpellbook.hpp b/apps/openmw/mwmp/processors/player/ProcessorPlayerSpellbook.hpp index b2ece550f..caaa85a9a 100644 --- a/apps/openmw/mwmp/processors/player/ProcessorPlayerSpellbook.hpp +++ b/apps/openmw/mwmp/processors/player/ProcessorPlayerSpellbook.hpp @@ -29,12 +29,11 @@ namespace mwmp else { LocalPlayer &localPlayer = static_cast(*player); - - int spellbookAction = localPlayer.spellbookChanges.action; - if (spellbookAction == SpellbookChanges::ADD) + + if (localPlayer.spellbookChanges.action == SpellbookChanges::Type::Add) localPlayer.addSpells(); - else if (spellbookAction == SpellbookChanges::REMOVE) + else if (localPlayer.spellbookChanges.action == SpellbookChanges::Type::Remove) localPlayer.removeSpells(); else // SpellbookChanges::SET localPlayer.setSpellbook(); diff --git a/apps/openmw/mwmp/processors/world/ProcessorContainer.hpp b/apps/openmw/mwmp/processors/world/ProcessorContainer.hpp index cb2a3b4c8..ee5f261b5 100644 --- a/apps/openmw/mwmp/processors/world/ProcessorContainer.hpp +++ b/apps/openmw/mwmp/processors/world/ProcessorContainer.hpp @@ -17,10 +17,10 @@ namespace mwmp { BaseObjectProcessor::Do(packet, event); - LOG_APPEND(Log::LOG_VERBOSE, "- action: %i", event.action); + LOG_APPEND(Log::LOG_VERBOSE, "- action: %i", (int)event.action); // If we've received a request for information, comply with it - if (event.action == mwmp::BaseEvent::REQUEST) + if (event.action == mwmp::BaseEvent::Action::Request) event.sendContainers(ptrCellStore); // Otherwise, edit containers based on the information received else diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index 9c354f21d..48c59ab75 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -266,7 +266,7 @@ namespace MWWorld Store a cell unload for the LocalPlayer */ - mwmp::Main::get().getLocalPlayer()->storeCellState(*(*iter)->getCell(), mwmp::CellState::UNLOAD); + mwmp::Main::get().getLocalPlayer()->storeCellState(*(*iter)->getCell(), mwmp::CellState::Type::Unload); /* End of tes3mp addition */ @@ -347,7 +347,7 @@ namespace MWWorld Store a cell load for the LocalPlayer */ - mwmp::Main::get().getLocalPlayer()->storeCellState(*cell->getCell(), mwmp::CellState::LOAD); + mwmp::Main::get().getLocalPlayer()->storeCellState(*cell->getCell(), mwmp::CellState::Type::Load); /* End of tes3mp addition */ diff --git a/components/openmw-mp/Base/BaseEvent.hpp b/components/openmw-mp/Base/BaseEvent.hpp index 33d62ceec..47f90c234 100644 --- a/components/openmw-mp/Base/BaseEvent.hpp +++ b/components/openmw-mp/Base/BaseEvent.hpp @@ -76,12 +76,12 @@ namespace mwmp } - enum WORLD_ACTION + enum class Action : uint8_t { - SET = 0, - ADD = 1, - REMOVE = 2, - REQUEST = 3 + Set = 0, + Add, + Remove, + Request }; RakNet::RakNetGUID guid; @@ -91,7 +91,7 @@ namespace mwmp ESM::Cell cell; std::string consoleCommand; - unsigned char action; // 0 - Clear and set in entirety, 1 - Add item, 2 - Remove item, 3 - Request items + Action action; bool isValid; }; diff --git a/components/openmw-mp/Base/BasePlayer.hpp b/components/openmw-mp/Base/BasePlayer.hpp index c5807f828..7e42f711a 100644 --- a/components/openmw-mp/Base/BasePlayer.hpp +++ b/components/openmw-mp/Base/BasePlayer.hpp @@ -46,15 +46,15 @@ namespace mwmp { std::string quest; int index; - enum JOURNAL_ITEM_TYPE + enum class Type { - ENTRY = 0, - INDEX = 1 + Entry = 0, + Index = 1 }; std::string actorRefId; - int type; // 0 - An entire entry, 1 - An index + Type type; }; struct Faction @@ -101,13 +101,13 @@ namespace mwmp { ESM::Cell cell; - enum CELL_STATE_ACTION + enum class Type: uint8_t { - LOAD = 0, - UNLOAD = 1 + Load = 0, + Unload }; - int type; // 0 - Cell load, 1 - Cell unload + Type type; }; struct JournalChanges @@ -119,14 +119,14 @@ namespace mwmp { std::vector factions; - enum FACTION_ACTION + enum class Type: uint8_t { - RANK = 0, - EXPULSION = 1, - REPUTATION = 2 + Rank = 0, + Expulsion, + Reputation }; - int action; // 0 - Rank, 1 - Expulsion state, 2 - Both + Type action; }; struct TopicChanges @@ -153,13 +153,14 @@ namespace mwmp { std::vector spells; - enum ACTION_TYPE + enum class Type: int8_t { - SET = 0, - ADD, - REMOVE + None = -1, + Set = 0, + Add, + Remove }; - int action; // 0 - Clear and set in entirety, 1 - Add spell, 2 - Remove spell + Type action; }; struct QuickKeyChanges @@ -191,9 +192,7 @@ namespace mwmp struct GUIMessageBox { - int id; - int type; - enum GUI_TYPE + enum class Type: uint8_t { MessageBox = 0, CustomMessageBox, @@ -201,6 +200,10 @@ namespace mwmp PasswordDialog, ListBox }; + + int id; + Type type; + std::string label; std::string note; std::string buttons; @@ -237,8 +240,8 @@ namespace mwmp BasePlayer(RakNet::RakNetGUID guid) : guid(guid) { - inventoryChanges.action = 0; - spellbookChanges.action = 0; + inventoryChanges.action = InventoryChanges::Type::None; + spellbookChanges.action = SpellbookChanges::Type::None; useCreatureName = false; isWerewolf = false; } diff --git a/components/openmw-mp/Base/BaseStructs.hpp b/components/openmw-mp/Base/BaseStructs.hpp index 0ac6018ed..5a3290c52 100644 --- a/components/openmw-mp/Base/BaseStructs.hpp +++ b/components/openmw-mp/Base/BaseStructs.hpp @@ -23,13 +23,14 @@ namespace mwmp struct InventoryChanges { std::vector items; - enum ACTION_TYPE + enum class Type: int8_t { - SET = 0, - ADD, - REMOVE + None = -1, + Set = 0, + Add, + Remove }; - int action; // 0 - Clear and set in entirety, 1 - Add item, 2 - Remove item + Type action; // 0 - Clear and set in entirety, 1 - Add item, 2 - Remove item }; struct Target @@ -47,14 +48,15 @@ namespace mwmp Target target; - char type; // 0 - melee, 1 - magic, 2 - throwable - enum TYPE + enum class Type: uint8_t { - MELEE = 0, - MAGIC, - THROWABLE + Melee = 0, + Magic, + Throwable }; + Type type; + std::string spellId; // id of spell (e.g. "fireball") float damage; diff --git a/components/openmw-mp/Packets/PacketPreInit.cpp b/components/openmw-mp/Packets/PacketPreInit.cpp index cc5e2c95e..91e5e28e7 100644 --- a/components/openmw-mp/Packets/PacketPreInit.cpp +++ b/components/openmw-mp/Packets/PacketPreInit.cpp @@ -15,30 +15,37 @@ void mwmp::PacketPreInit::Packet(RakNet::BitStream *bs, bool send) { BasePacket::Packet(bs, send); - size_t size = checksums->size(); + uint16_t size = checksums->size(); RW(size, send); - for (size_t i = 0; i < size; i++) + if(!send) { - PluginPair ppair; - if (send) - ppair = (*checksums)[i]; + if(size > 256) + return; + checksums->clear(); + checksums->resize(size); + } + + for (auto &&ppair : *checksums) + { RW(ppair.first, send); - size_t hashSize = ppair.second.size(); + uint8_t hashSize = ppair.second.size(); + RW(hashSize, send); - for (size_t j = 0; j < hashSize; j++) + + if(!send) + { + if(hashSize > 16) + return; + ppair.second.resize(hashSize); + } + + for (auto &&hash :ppair.second) { - unsigned hash; - if (send) - hash = ppair.second[j]; RW(hash, send); - if (!send) - ppair.second.push_back(hash); } - if (!send) - checksums->push_back(ppair); } } diff --git a/components/openmw-mp/Packets/Player/PacketGUIBoxes.cpp b/components/openmw-mp/Packets/Player/PacketGUIBoxes.cpp index 2283da3a1..67154dc94 100644 --- a/components/openmw-mp/Packets/Player/PacketGUIBoxes.cpp +++ b/components/openmw-mp/Packets/Player/PacketGUIBoxes.cpp @@ -23,9 +23,9 @@ void PacketGUIBoxes::Packet(RakNet::BitStream *bs, bool send) RW(player->guiMessageBox.data, send); - if (player->guiMessageBox.type == BasePlayer::GUIMessageBox::CustomMessageBox) + if (player->guiMessageBox.type == BasePlayer::GUIMessageBox::Type::CustomMessageBox) RW(player->guiMessageBox.buttons, send); - else if (player->guiMessageBox.type == BasePlayer::GUIMessageBox::PasswordDialog) + else if (player->guiMessageBox.type == BasePlayer::GUIMessageBox::Type::PasswordDialog) RW(player->guiMessageBox.note, send); } diff --git a/components/openmw-mp/Packets/Player/PacketPlayerFaction.cpp b/components/openmw-mp/Packets/Player/PacketPlayerFaction.cpp index 6fb68cdf5..4ac3dc12a 100644 --- a/components/openmw-mp/Packets/Player/PacketPlayerFaction.cpp +++ b/components/openmw-mp/Packets/Player/PacketPlayerFaction.cpp @@ -32,13 +32,13 @@ void PacketPlayerFaction::Packet(RakNet::BitStream *bs, bool send) { RW(faction.factionId, send, true); - if (player->factionChanges.action == FactionChanges::RANK) + if (player->factionChanges.action == FactionChanges::Type::Rank) RW(faction.rank, send); - if (player->factionChanges.action == FactionChanges::EXPULSION) + if (player->factionChanges.action == FactionChanges::Type::Expulsion) RW(faction.isExpelled, send); - if (player->factionChanges.action == FactionChanges::REPUTATION) + if (player->factionChanges.action == FactionChanges::Type::Reputation) RW(faction.reputation, send); } } diff --git a/components/openmw-mp/Packets/Player/PacketPlayerJournal.cpp b/components/openmw-mp/Packets/Player/PacketPlayerJournal.cpp index f366c8add..087339b64 100644 --- a/components/openmw-mp/Packets/Player/PacketPlayerJournal.cpp +++ b/components/openmw-mp/Packets/Player/PacketPlayerJournal.cpp @@ -32,7 +32,7 @@ void PacketPlayerJournal::Packet(RakNet::BitStream *bs, bool send) RW(journalItem.quest, send, true); RW(journalItem.index, send); - if (journalItem.type == JournalItem::ENTRY) + if (journalItem.type == JournalItem::Type::Entry) RW(journalItem.actorRefId, send, true); } }