mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-16 19:19:56 +00:00
[General] Simplify vectorContains
This commit is contained in:
parent
3aa125ceda
commit
fa2bf0663e
13 changed files with 29 additions and 34 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -85,16 +85,6 @@ bool Utils::compareDoubles(double a, double b, double epsilon)
|
|||
return fabs(a - b) < epsilon;
|
||||
}
|
||||
|
||||
bool Utils::vectorContains(std::vector<int>* vectorChecked, int value)
|
||||
{
|
||||
return std::find(vectorChecked->begin(), vectorChecked->end(), value) != vectorChecked->end();
|
||||
}
|
||||
|
||||
bool Utils::vectorContains(std::vector<std::string>* vectorChecked, std::string value)
|
||||
{
|
||||
return std::find(vectorChecked->begin(), vectorChecked->end(), value) != vectorChecked->end();
|
||||
}
|
||||
|
||||
std::string Utils::toString(int num)
|
||||
{
|
||||
std::ostringstream stream;
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#ifndef UTILS_HPP
|
||||
#define UTILS_HPP
|
||||
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
@ -27,8 +28,11 @@ namespace Utils
|
|||
|
||||
bool compareDoubles(double a, double b, double epsilon);
|
||||
|
||||
bool vectorContains(std::vector<int>* vectorChecked, int value);
|
||||
bool vectorContains(std::vector<std::string>* vectorChecked, std::string value);
|
||||
template <class Type>
|
||||
bool vectorContains(const std::vector<Type> &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);
|
||||
|
||||
|
|
Loading…
Reference in a new issue