From 9935f56d461edd26ab11ef2aa92d8d07bdfd9310 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Wed, 17 Jan 2018 08:09:57 +0200 Subject: [PATCH] [General] Use doubles instead of ints for enchantmentCharge Additionally, include enchantmentCharges for items in PlayerEquipment packets. --- apps/openmw-mp/Script/Functions/Actors.cpp | 4 ++-- apps/openmw-mp/Script/Functions/Actors.hpp | 4 ++-- apps/openmw-mp/Script/Functions/Items.cpp | 8 ++++---- apps/openmw-mp/Script/Functions/Items.hpp | 8 ++++---- apps/openmw-mp/Script/Functions/World.cpp | 8 ++++---- apps/openmw-mp/Script/Functions/World.hpp | 8 ++++---- components/openmw-mp/Base/BaseEvent.hpp | 4 ++-- components/openmw-mp/Base/BaseStructs.hpp | 2 +- .../openmw-mp/Packets/Player/PacketPlayerEquipment.cpp | 2 ++ 9 files changed, 25 insertions(+), 23 deletions(-) diff --git a/apps/openmw-mp/Script/Functions/Actors.cpp b/apps/openmw-mp/Script/Functions/Actors.cpp index 1f50cbf55..c195f4b4b 100644 --- a/apps/openmw-mp/Script/Functions/Actors.cpp +++ b/apps/openmw-mp/Script/Functions/Actors.cpp @@ -163,7 +163,7 @@ int ActorFunctions::GetActorEquipmentItemCharge(unsigned int i, unsigned short s return readActorList->baseActors.at(i).equipedItems[slot].charge; } -int ActorFunctions::GetActorEquipmentItemEnchantmentCharge(unsigned int i, unsigned short slot) noexcept +double ActorFunctions::GetActorEquipmentItemEnchantmentCharge(unsigned int i, unsigned short slot) noexcept { return readActorList->baseActors.at(i).equipedItems[slot].enchantmentCharge; } @@ -267,7 +267,7 @@ void ActorFunctions::SetActorFatigueModified(double value) noexcept tempActor.creatureStats.mDynamic[2].mMod = value; } -void ActorFunctions::EquipActorItem(unsigned short slot, const char *refId, unsigned int count, int charge, int enchantmentCharge) noexcept +void ActorFunctions::EquipActorItem(unsigned short slot, const char *refId, unsigned int count, int charge, double enchantmentCharge) noexcept { tempActor.equipedItems[slot].refId = refId; tempActor.equipedItems[slot].count = count; diff --git a/apps/openmw-mp/Script/Functions/Actors.hpp b/apps/openmw-mp/Script/Functions/Actors.hpp index c1ae6bce2..d3dbc8200 100644 --- a/apps/openmw-mp/Script/Functions/Actors.hpp +++ b/apps/openmw-mp/Script/Functions/Actors.hpp @@ -308,7 +308,7 @@ public: * \param slot The slot of the equipment item. * \return The enchantment charge. */ - static int GetActorEquipmentItemEnchantmentCharge(unsigned int i, unsigned short slot) noexcept; + static double GetActorEquipmentItemEnchantmentCharge(unsigned int i, unsigned short slot) noexcept; /** * \brief Check whether there is any positional data for the actor at a certain index in @@ -492,7 +492,7 @@ public: * \param enchantmentCharge The enchantment charge of the item. * \return void */ - static void EquipActorItem(unsigned short slot, const char* refId, unsigned int count, int charge, int enchantmentCharge = -1) noexcept; + static void EquipActorItem(unsigned short slot, const char* refId, unsigned int count, int charge, double enchantmentCharge = -1) noexcept; /** * \brief Unequip the item in a certain slot of the equipment of the temporary actor stored diff --git a/apps/openmw-mp/Script/Functions/Items.cpp b/apps/openmw-mp/Script/Functions/Items.cpp index 7ff6fc8e7..1bc35a829 100644 --- a/apps/openmw-mp/Script/Functions/Items.cpp +++ b/apps/openmw-mp/Script/Functions/Items.cpp @@ -35,7 +35,7 @@ unsigned int ItemFunctions::GetInventoryChangesSize(unsigned short pid) noexcept return player->inventoryChanges.count; } -void ItemFunctions::EquipItem(unsigned short pid, unsigned short slot, const char *refId, unsigned int count, int charge, int enchantmentCharge) noexcept +void ItemFunctions::EquipItem(unsigned short pid, unsigned short slot, const char *refId, unsigned int count, int charge, double enchantmentCharge) noexcept { Player *player; GET_PLAYER(pid, player,); @@ -54,7 +54,7 @@ void ItemFunctions::UnequipItem(unsigned short pid, unsigned short slot) noexcep ItemFunctions::EquipItem(pid, slot, "", 0, -1, -1); } -void ItemFunctions::AddItem(unsigned short pid, const char* refId, unsigned int count, int charge, int enchantmentCharge) noexcept +void ItemFunctions::AddItem(unsigned short pid, const char* refId, unsigned int count, int charge, double enchantmentCharge) noexcept { Player *player; GET_PLAYER(pid, player, ); @@ -117,7 +117,7 @@ int ItemFunctions::GetEquipmentItemCharge(unsigned short pid, unsigned short slo return player->equipedItems[slot].charge; } -int ItemFunctions::GetEquipmentItemEnchantmentCharge(unsigned short pid, unsigned short slot) noexcept +double ItemFunctions::GetEquipmentItemEnchantmentCharge(unsigned short pid, unsigned short slot) noexcept { Player *player; GET_PLAYER(pid, player, 0); @@ -152,7 +152,7 @@ int ItemFunctions::GetInventoryItemCharge(unsigned short pid, unsigned int i) no return player->inventoryChanges.items.at(i).charge; } -int ItemFunctions::GetInventoryItemEnchantmentCharge(unsigned short pid, unsigned int i) noexcept +double ItemFunctions::GetInventoryItemEnchantmentCharge(unsigned short pid, unsigned int i) noexcept { Player *player; GET_PLAYER(pid, player, 0); diff --git a/apps/openmw-mp/Script/Functions/Items.hpp b/apps/openmw-mp/Script/Functions/Items.hpp index 9350be896..b19c396b3 100644 --- a/apps/openmw-mp/Script/Functions/Items.hpp +++ b/apps/openmw-mp/Script/Functions/Items.hpp @@ -41,10 +41,10 @@ public: static int GetEquipmentSize() noexcept; static unsigned int GetInventoryChangesSize(unsigned short pid) noexcept; - static void EquipItem(unsigned short pid, unsigned short slot, const char* refId, unsigned int count, int charge, int enchantmentCharge = -1) noexcept; + static void EquipItem(unsigned short pid, unsigned short slot, const char* refId, unsigned int count, int charge, double enchantmentCharge = -1) noexcept; static void UnequipItem(unsigned short pid, unsigned short slot) noexcept; - static void AddItem(unsigned short pid, const char* refId, unsigned int count, int charge, int enchantmentCharge = -1) noexcept; + static void AddItem(unsigned short pid, const char* refId, unsigned int count, int charge, double enchantmentCharge = -1) noexcept; static void RemoveItem(unsigned short pid, const char* refId, unsigned short count) noexcept; static bool HasItemEquipped(unsigned short pid, const char* refId); @@ -52,12 +52,12 @@ public: static const char *GetEquipmentItemRefId(unsigned short pid, unsigned short slot) noexcept; static int GetEquipmentItemCount(unsigned short pid, unsigned short slot) noexcept; static int GetEquipmentItemCharge(unsigned short pid, unsigned short slot) noexcept; - static int GetEquipmentItemEnchantmentCharge(unsigned short pid, unsigned short slot) noexcept; + static double GetEquipmentItemEnchantmentCharge(unsigned short pid, unsigned short slot) noexcept; static const char *GetInventoryItemRefId(unsigned short pid, unsigned int i) noexcept; static int GetInventoryItemCount(unsigned short pid, unsigned int i) noexcept; static int GetInventoryItemCharge(unsigned short pid, unsigned int i) noexcept; - static int GetInventoryItemEnchantmentCharge(unsigned short pid, unsigned int i) noexcept; + static double GetInventoryItemEnchantmentCharge(unsigned short pid, unsigned int i) noexcept; static void SendEquipment(unsigned short pid) noexcept; static void SendInventoryChanges(unsigned short pid, bool toOthers = false) noexcept; diff --git a/apps/openmw-mp/Script/Functions/World.cpp b/apps/openmw-mp/Script/Functions/World.cpp index 871582051..4423d1d05 100644 --- a/apps/openmw-mp/Script/Functions/World.cpp +++ b/apps/openmw-mp/Script/Functions/World.cpp @@ -69,7 +69,7 @@ int WorldFunctions::GetObjectCharge(unsigned int i) noexcept return readEvent->worldObjects.at(i).charge; } -int WorldFunctions::GetObjectEnchantmentCharge(unsigned int i) noexcept +double WorldFunctions::GetObjectEnchantmentCharge(unsigned int i) noexcept { return readEvent->worldObjects.at(i).enchantmentCharge; } @@ -152,7 +152,7 @@ int WorldFunctions::GetContainerItemCharge(unsigned int objectIndex, unsigned in .containerItems.at(itemIndex).charge; } -int WorldFunctions::GetContainerItemEnchantmentCharge(unsigned int objectIndex, unsigned int itemIndex) noexcept +double WorldFunctions::GetContainerItemEnchantmentCharge(unsigned int objectIndex, unsigned int itemIndex) noexcept { return readEvent->worldObjects.at(objectIndex) .containerItems.at(itemIndex).enchantmentCharge; @@ -204,7 +204,7 @@ void WorldFunctions::SetObjectCharge(int charge) noexcept tempWorldObject.charge = charge; } -void WorldFunctions::SetObjectEnchantmentCharge(int enchantmentCharge) noexcept +void WorldFunctions::SetObjectEnchantmentCharge(double enchantmentCharge) noexcept { tempWorldObject.enchantmentCharge = enchantmentCharge; } @@ -282,7 +282,7 @@ void WorldFunctions::SetContainerItemCharge(int charge) noexcept tempContainerItem.charge = charge; } -void WorldFunctions::SetContainerItemEnchantmentCharge(int enchantmentCharge) noexcept +void WorldFunctions::SetContainerItemEnchantmentCharge(double enchantmentCharge) noexcept { tempContainerItem.enchantmentCharge = enchantmentCharge; } diff --git a/apps/openmw-mp/Script/Functions/World.hpp b/apps/openmw-mp/Script/Functions/World.hpp index 485d3a365..7667254a5 100644 --- a/apps/openmw-mp/Script/Functions/World.hpp +++ b/apps/openmw-mp/Script/Functions/World.hpp @@ -158,7 +158,7 @@ public: * \param i The index of the object. * \return The enchantment charge. */ - static int GetObjectEnchantmentCharge(unsigned int i) noexcept; + static double GetObjectEnchantmentCharge(unsigned int i) noexcept; /** * \brief Get the gold value of the object at a certain index in the read event's object @@ -307,7 +307,7 @@ public: * \param itemIndex The index of the container item. * \return The enchantment charge. */ - static int GetContainerItemEnchantmentCharge(unsigned int objectIndex, unsigned int itemIndex) noexcept; + static double GetContainerItemEnchantmentCharge(unsigned int objectIndex, unsigned int itemIndex) noexcept; /** * \brief Get the action count of the container item at a certain itemIndex in the container @@ -414,7 +414,7 @@ public: * \param charge The enchantment charge. * \return void */ - static void SetObjectEnchantmentCharge(int enchantmentCharge) noexcept; + static void SetObjectEnchantmentCharge(double enchantmentCharge) noexcept; /** * \brief Set the gold value of the temporary world object stored on the server. @@ -542,7 +542,7 @@ public: * \param charge The enchantment charge. * \return void */ - static void SetContainerItemEnchantmentCharge(int enchantmentCharge) noexcept; + static void SetContainerItemEnchantmentCharge(double enchantmentCharge) noexcept; /** * \brief Add a copy of the server's temporary world object to the server's temporary event. diff --git a/components/openmw-mp/Base/BaseEvent.hpp b/components/openmw-mp/Base/BaseEvent.hpp index f7718412c..081f189c0 100644 --- a/components/openmw-mp/Base/BaseEvent.hpp +++ b/components/openmw-mp/Base/BaseEvent.hpp @@ -12,7 +12,7 @@ namespace mwmp std::string refId; int count; int charge; - int enchantmentCharge; + double enchantmentCharge; int actionCount; @@ -29,7 +29,7 @@ namespace mwmp int mpNum; int count; int charge; - int enchantmentCharge; + double enchantmentCharge; int goldValue; ESM::Position position; diff --git a/components/openmw-mp/Base/BaseStructs.hpp b/components/openmw-mp/Base/BaseStructs.hpp index b915a903c..798323c91 100644 --- a/components/openmw-mp/Base/BaseStructs.hpp +++ b/components/openmw-mp/Base/BaseStructs.hpp @@ -12,7 +12,7 @@ namespace mwmp std::string refId; int count; int charge; - int enchantmentCharge; + double enchantmentCharge; inline bool operator==(const Item& rhs) { diff --git a/components/openmw-mp/Packets/Player/PacketPlayerEquipment.cpp b/components/openmw-mp/Packets/Player/PacketPlayerEquipment.cpp index 07fcfe8e4..4b54c006c 100644 --- a/components/openmw-mp/Packets/Player/PacketPlayerEquipment.cpp +++ b/components/openmw-mp/Packets/Player/PacketPlayerEquipment.cpp @@ -5,6 +5,7 @@ #include "PacketPlayerEquipment.hpp" #include + using namespace mwmp; PacketPlayerEquipment::PacketPlayerEquipment(RakNet::RakPeerInterface *peer) : PlayerPacket(peer) @@ -21,5 +22,6 @@ void PacketPlayerEquipment::Packet(RakNet::BitStream *bs, bool send) RW(player->equipedItems[i].refId, send, 1); RW(player->equipedItems[i].count, send); RW(player->equipedItems[i].charge, send); + RW(player->equipedItems[i].enchantmentCharge, send); } }