diff --git a/apps/openmw-mp/Script/Functions/Items.cpp b/apps/openmw-mp/Script/Functions/Items.cpp index 3d717cd41..bc41a3e87 100644 --- a/apps/openmw-mp/Script/Functions/Items.cpp +++ b/apps/openmw-mp/Script/Functions/Items.cpp @@ -45,7 +45,7 @@ void ItemFunctions::EquipItem(unsigned short pid, unsigned short slot, const cha player->equipmentItems[slot].charge = charge; player->equipmentItems[slot].enchantmentCharge = enchantmentCharge; - if (!Utils::vectorContains(&player->equipmentIndexChanges, slot)) + if (!Utils::vectorContains(player->equipmentIndexChanges, slot)) player->equipmentIndexChanges.push_back(slot); } diff --git a/apps/openmw-mp/Script/Functions/Stats.cpp b/apps/openmw-mp/Script/Functions/Stats.cpp index fe3d876e6..9a3cb2c0c 100644 --- a/apps/openmw-mp/Script/Functions/Stats.cpp +++ b/apps/openmw-mp/Script/Functions/Stats.cpp @@ -358,7 +358,7 @@ void StatsFunctions::SetHealthBase(unsigned short pid, double value) noexcept player->creatureStats.mDynamic[0].mBase = value; - if (!Utils::vectorContains(&player->statsDynamicIndexChanges, 0)) + if (!Utils::vectorContains(player->statsDynamicIndexChanges, 0)) player->statsDynamicIndexChanges.push_back(0); } @@ -369,7 +369,7 @@ void StatsFunctions::SetHealthCurrent(unsigned short pid, double value) noexcept player->creatureStats.mDynamic[0].mCurrent = value; - if (!Utils::vectorContains(&player->statsDynamicIndexChanges, 0)) + if (!Utils::vectorContains(player->statsDynamicIndexChanges, 0)) player->statsDynamicIndexChanges.push_back(0); } @@ -380,7 +380,7 @@ void StatsFunctions::SetMagickaBase(unsigned short pid, double value) noexcept player->creatureStats.mDynamic[1].mBase = value; - if (!Utils::vectorContains(&player->statsDynamicIndexChanges, 1)) + if (!Utils::vectorContains(player->statsDynamicIndexChanges, 1)) player->statsDynamicIndexChanges.push_back(1); } @@ -391,7 +391,7 @@ void StatsFunctions::SetMagickaCurrent(unsigned short pid, double value) noexcep player->creatureStats.mDynamic[1].mCurrent = value; - if (!Utils::vectorContains(&player->statsDynamicIndexChanges, 1)) + if (!Utils::vectorContains(player->statsDynamicIndexChanges, 1)) player->statsDynamicIndexChanges.push_back(1); } @@ -402,7 +402,7 @@ void StatsFunctions::SetFatigueBase(unsigned short pid, double value) noexcept player->creatureStats.mDynamic[2].mBase = value; - if (!Utils::vectorContains(&player->statsDynamicIndexChanges, 2)) + if (!Utils::vectorContains(player->statsDynamicIndexChanges, 2)) player->statsDynamicIndexChanges.push_back(2); } @@ -413,7 +413,7 @@ void StatsFunctions::SetFatigueCurrent(unsigned short pid, double value) noexcep player->creatureStats.mDynamic[2].mCurrent = value; - if (!Utils::vectorContains(&player->statsDynamicIndexChanges, 2)) + if (!Utils::vectorContains(player->statsDynamicIndexChanges, 2)) player->statsDynamicIndexChanges.push_back(2); } @@ -427,7 +427,7 @@ void StatsFunctions::SetAttributeBase(unsigned short pid, unsigned short attribu player->creatureStats.mAttributes[attributeId].mBase = value; - if (!Utils::vectorContains(&player->attributeIndexChanges, attributeId)) + if (!Utils::vectorContains(player->attributeIndexChanges, attributeId)) player->attributeIndexChanges.push_back(attributeId); } @@ -441,7 +441,7 @@ void StatsFunctions::ClearAttributeModifier(unsigned short pid, unsigned short a player->creatureStats.mAttributes[attributeId].mMod = 0; - if (!Utils::vectorContains(&player->attributeIndexChanges, attributeId)) + if (!Utils::vectorContains(player->attributeIndexChanges, attributeId)) player->attributeIndexChanges.push_back(attributeId); } @@ -455,7 +455,7 @@ void StatsFunctions::SetSkillBase(unsigned short pid, unsigned short skillId, in player->npcStats.mSkills[skillId].mBase = value; - if (!Utils::vectorContains(&player->skillIndexChanges, skillId)) + if (!Utils::vectorContains(player->skillIndexChanges, skillId)) player->skillIndexChanges.push_back(skillId); } @@ -469,7 +469,7 @@ void StatsFunctions::ClearSkillModifier(unsigned short pid, unsigned short skill player->npcStats.mSkills[skillId].mMod = 0; - if (!Utils::vectorContains(&player->skillIndexChanges, skillId)) + if (!Utils::vectorContains(player->skillIndexChanges, skillId)) player->skillIndexChanges.push_back(skillId); } @@ -483,7 +483,7 @@ void StatsFunctions::SetSkillProgress(unsigned short pid, unsigned short skillId player->npcStats.mSkills[skillId].mProgress = value; - if (!Utils::vectorContains(&player->skillIndexChanges, skillId)) + if (!Utils::vectorContains(player->skillIndexChanges, skillId)) player->skillIndexChanges.push_back(skillId); } @@ -497,7 +497,7 @@ void StatsFunctions::SetSkillIncrease(unsigned short pid, unsigned int attribute player->npcStats.mSkillIncrease[attributeId] = value; - if (!Utils::vectorContains(&player->attributeIndexChanges, attributeId)) + if (!Utils::vectorContains(player->attributeIndexChanges, attributeId)) player->attributeIndexChanges.push_back(attributeId); } diff --git a/apps/openmw/mwclass/apparatus.cpp b/apps/openmw/mwclass/apparatus.cpp index d8ec93742..b4b219ef2 100644 --- a/apps/openmw/mwclass/apparatus.cpp +++ b/apps/openmw/mwclass/apparatus.cpp @@ -53,7 +53,7 @@ namespace MWClass { mwmp::BaseWorldstate *worldstate = mwmp::Main::get().getNetworking()->getWorldstate(); - if (worldstate->hasPlacedObjectCollision || Utils::vectorContains(&worldstate->enforcedCollisionRefIds, ptr.getCellRef().getRefId())) + if (worldstate->hasPlacedObjectCollision || Utils::vectorContains(worldstate->enforcedCollisionRefIds, ptr.getCellRef().getRefId())) { if (worldstate->useActorCollisionForPlacedObjects) physics.addObject(ptr, model, MWPhysics::CollisionType_Actor); diff --git a/apps/openmw/mwclass/armor.cpp b/apps/openmw/mwclass/armor.cpp index e6096e73f..2670804fe 100644 --- a/apps/openmw/mwclass/armor.cpp +++ b/apps/openmw/mwclass/armor.cpp @@ -59,7 +59,7 @@ namespace MWClass { mwmp::BaseWorldstate *worldstate = mwmp::Main::get().getNetworking()->getWorldstate(); - if (worldstate->hasPlacedObjectCollision || Utils::vectorContains(&worldstate->enforcedCollisionRefIds, ptr.getCellRef().getRefId())) + if (worldstate->hasPlacedObjectCollision || Utils::vectorContains(worldstate->enforcedCollisionRefIds, ptr.getCellRef().getRefId())) { if (worldstate->useActorCollisionForPlacedObjects) physics.addObject(ptr, model, MWPhysics::CollisionType_Actor); diff --git a/apps/openmw/mwclass/book.cpp b/apps/openmw/mwclass/book.cpp index de7e2d4e8..0ab6579e1 100644 --- a/apps/openmw/mwclass/book.cpp +++ b/apps/openmw/mwclass/book.cpp @@ -56,7 +56,7 @@ namespace MWClass { mwmp::BaseWorldstate *worldstate = mwmp::Main::get().getNetworking()->getWorldstate(); - if (worldstate->hasPlacedObjectCollision || Utils::vectorContains(&worldstate->enforcedCollisionRefIds, ptr.getCellRef().getRefId())) + if (worldstate->hasPlacedObjectCollision || Utils::vectorContains(worldstate->enforcedCollisionRefIds, ptr.getCellRef().getRefId())) { if (worldstate->useActorCollisionForPlacedObjects) physics.addObject(ptr, model, MWPhysics::CollisionType_Actor); diff --git a/apps/openmw/mwclass/clothing.cpp b/apps/openmw/mwclass/clothing.cpp index e5cba7f98..3f08c3e78 100644 --- a/apps/openmw/mwclass/clothing.cpp +++ b/apps/openmw/mwclass/clothing.cpp @@ -55,7 +55,7 @@ namespace MWClass { mwmp::BaseWorldstate *worldstate = mwmp::Main::get().getNetworking()->getWorldstate(); - if (worldstate->hasPlacedObjectCollision || Utils::vectorContains(&worldstate->enforcedCollisionRefIds, ptr.getCellRef().getRefId())) + if (worldstate->hasPlacedObjectCollision || Utils::vectorContains(worldstate->enforcedCollisionRefIds, ptr.getCellRef().getRefId())) { if (worldstate->useActorCollisionForPlacedObjects) physics.addObject(ptr, model, MWPhysics::CollisionType_Actor); diff --git a/apps/openmw/mwclass/ingredient.cpp b/apps/openmw/mwclass/ingredient.cpp index a41469860..af33b4f7a 100644 --- a/apps/openmw/mwclass/ingredient.cpp +++ b/apps/openmw/mwclass/ingredient.cpp @@ -56,7 +56,7 @@ namespace MWClass { mwmp::BaseWorldstate *worldstate = mwmp::Main::get().getNetworking()->getWorldstate(); - if (worldstate->hasPlacedObjectCollision || Utils::vectorContains(&worldstate->enforcedCollisionRefIds, ptr.getCellRef().getRefId())) + if (worldstate->hasPlacedObjectCollision || Utils::vectorContains(worldstate->enforcedCollisionRefIds, ptr.getCellRef().getRefId())) { if (worldstate->useActorCollisionForPlacedObjects) physics.addObject(ptr, model, MWPhysics::CollisionType_Actor); diff --git a/apps/openmw/mwclass/misc.cpp b/apps/openmw/mwclass/misc.cpp index eaa40a01c..2f156c822 100644 --- a/apps/openmw/mwclass/misc.cpp +++ b/apps/openmw/mwclass/misc.cpp @@ -63,7 +63,7 @@ namespace MWClass { mwmp::BaseWorldstate *worldstate = mwmp::Main::get().getNetworking()->getWorldstate(); - if (worldstate->hasPlacedObjectCollision || Utils::vectorContains(&worldstate->enforcedCollisionRefIds, ptr.getCellRef().getRefId())) + if (worldstate->hasPlacedObjectCollision || Utils::vectorContains(worldstate->enforcedCollisionRefIds, ptr.getCellRef().getRefId())) { if (worldstate->useActorCollisionForPlacedObjects) physics.addObject(ptr, model, MWPhysics::CollisionType_Actor); diff --git a/apps/openmw/mwclass/potion.cpp b/apps/openmw/mwclass/potion.cpp index 7fd4b4666..2b41b7dbb 100644 --- a/apps/openmw/mwclass/potion.cpp +++ b/apps/openmw/mwclass/potion.cpp @@ -57,7 +57,7 @@ namespace MWClass { mwmp::BaseWorldstate *worldstate = mwmp::Main::get().getNetworking()->getWorldstate(); - if (worldstate->hasPlacedObjectCollision || Utils::vectorContains(&worldstate->enforcedCollisionRefIds, ptr.getCellRef().getRefId())) + if (worldstate->hasPlacedObjectCollision || Utils::vectorContains(worldstate->enforcedCollisionRefIds, ptr.getCellRef().getRefId())) { if (worldstate->useActorCollisionForPlacedObjects) physics.addObject(ptr, model, MWPhysics::CollisionType_Actor); diff --git a/apps/openmw/mwclass/repair.cpp b/apps/openmw/mwclass/repair.cpp index c9b24ce2b..c1a832a59 100644 --- a/apps/openmw/mwclass/repair.cpp +++ b/apps/openmw/mwclass/repair.cpp @@ -53,7 +53,7 @@ namespace MWClass { mwmp::BaseWorldstate *worldstate = mwmp::Main::get().getNetworking()->getWorldstate(); - if (worldstate->hasPlacedObjectCollision || Utils::vectorContains(&worldstate->enforcedCollisionRefIds, ptr.getCellRef().getRefId())) + if (worldstate->hasPlacedObjectCollision || Utils::vectorContains(worldstate->enforcedCollisionRefIds, ptr.getCellRef().getRefId())) { if (worldstate->useActorCollisionForPlacedObjects) physics.addObject(ptr, model, MWPhysics::CollisionType_Actor); diff --git a/apps/openmw/mwclass/weapon.cpp b/apps/openmw/mwclass/weapon.cpp index 7bb3ccb32..1b4c46666 100644 --- a/apps/openmw/mwclass/weapon.cpp +++ b/apps/openmw/mwclass/weapon.cpp @@ -57,7 +57,8 @@ namespace MWClass { mwmp::BaseWorldstate *worldstate = mwmp::Main::get().getNetworking()->getWorldstate(); - if (worldstate->hasPlacedObjectCollision || Utils::vectorContains(&worldstate->enforcedCollisionRefIds, ptr.getCellRef().getRefId())) + if (worldstate->hasPlacedObjectCollision || + Utils::vectorContains(worldstate->enforcedCollisionRefIds, ptr.getCellRef().getRefId())) { if (worldstate->useActorCollisionForPlacedObjects) physics.addObject(ptr, model, MWPhysics::CollisionType_Actor); diff --git a/components/openmw-mp/Utils.cpp b/components/openmw-mp/Utils.cpp index 4c32acf83..a4a4b6e7b 100644 --- a/components/openmw-mp/Utils.cpp +++ b/components/openmw-mp/Utils.cpp @@ -85,16 +85,6 @@ bool Utils::compareDoubles(double a, double b, double epsilon) return fabs(a - b) < epsilon; } -bool Utils::vectorContains(std::vector* vectorChecked, int value) -{ - return std::find(vectorChecked->begin(), vectorChecked->end(), value) != vectorChecked->end(); -} - -bool Utils::vectorContains(std::vector* vectorChecked, std::string value) -{ - return std::find(vectorChecked->begin(), vectorChecked->end(), value) != vectorChecked->end(); -} - std::string Utils::toString(int num) { std::ostringstream stream; diff --git a/components/openmw-mp/Utils.hpp b/components/openmw-mp/Utils.hpp index 318a4f150..abeae9cb5 100644 --- a/components/openmw-mp/Utils.hpp +++ b/components/openmw-mp/Utils.hpp @@ -5,6 +5,7 @@ #ifndef UTILS_HPP #define UTILS_HPP +#include #include #include #include @@ -27,8 +28,11 @@ namespace Utils bool compareDoubles(double a, double b, double epsilon); - bool vectorContains(std::vector* vectorChecked, int value); - bool vectorContains(std::vector* vectorChecked, std::string value); + template + bool vectorContains(const std::vector &vectorChecked, const Type &value) + { + return std::find(vectorChecked.begin(), vectorChecked.end(), value) != vectorChecked.end(); + } std::string replaceString(const std::string &source, const char *find, const char *replace);