mirror of https://github.com/OpenMW/openmw.git
Merge branch 'split_actorutil_hpp' into 'master'
Split apps/openmw/mwmechanics/actorutil.hpp See merge request OpenMW/openmw!2056just_say_no_to_geode
commit
cef4ce2c01
@ -0,0 +1,40 @@
|
||||
#ifndef OPENMW_MWMECHANICS_AISETTING_H
|
||||
#define OPENMW_MWMECHANICS_AISETTING_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "../mwbase/environment.hpp"
|
||||
#include "../mwbase/world.hpp"
|
||||
|
||||
#include "../mwworld/esmstore.hpp"
|
||||
|
||||
#include "creaturestats.hpp"
|
||||
|
||||
namespace MWMechanics
|
||||
{
|
||||
template<class T>
|
||||
void setBaseAISetting(const std::string& id, MWMechanics::CreatureStats::AiSetting setting, int value)
|
||||
{
|
||||
T copy = *MWBase::Environment::get().getWorld()->getStore().get<T>().find(id);
|
||||
switch (setting)
|
||||
{
|
||||
case MWMechanics::CreatureStats::AiSetting::AI_Hello:
|
||||
copy.mAiData.mHello = value;
|
||||
break;
|
||||
case MWMechanics::CreatureStats::AiSetting::AI_Fight:
|
||||
copy.mAiData.mFight = value;
|
||||
break;
|
||||
case MWMechanics::CreatureStats::AiSetting::AI_Flee:
|
||||
copy.mAiData.mFlee = value;
|
||||
break;
|
||||
case MWMechanics::CreatureStats::AiSetting::AI_Alarm:
|
||||
copy.mAiData.mAlarm = value;
|
||||
break;
|
||||
default:
|
||||
assert(false);
|
||||
}
|
||||
MWBase::Environment::get().getWorld()->createOverrideRecord(copy);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@ -0,0 +1,20 @@
|
||||
#ifndef OPENMW_MWMECHANICS_CREATURECUSTOMDATARESETTER_H
|
||||
#define OPENMW_MWMECHANICS_CREATURECUSTOMDATARESETTER_H
|
||||
|
||||
#include "../mwworld/ptr.hpp"
|
||||
|
||||
namespace MWMechanics
|
||||
{
|
||||
struct CreatureCustomDataResetter
|
||||
{
|
||||
MWWorld::Ptr mPtr;
|
||||
|
||||
~CreatureCustomDataResetter()
|
||||
{
|
||||
if (!mPtr.isEmpty())
|
||||
mPtr.getRefData().setCustomData({});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
@ -0,0 +1,14 @@
|
||||
#ifndef OPENMW_MWMECHANICS_GREETINGSTATE_H
|
||||
#define OPENMW_MWMECHANICS_GREETINGSTATE_H
|
||||
|
||||
namespace MWMechanics
|
||||
{
|
||||
enum GreetingState
|
||||
{
|
||||
Greet_None,
|
||||
Greet_InProgress,
|
||||
Greet_Done
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
@ -0,0 +1,42 @@
|
||||
#ifndef OPENMW_MWMECHANICS_INVENTORY_H
|
||||
#define OPENMW_MWMECHANICS_INVENTORY_H
|
||||
|
||||
#include "../mwbase/environment.hpp"
|
||||
#include "../mwbase/world.hpp"
|
||||
|
||||
#include "../mwworld/esmstore.hpp"
|
||||
|
||||
#include <components/misc/stringops.hpp>
|
||||
#include <components/esm3/loadcont.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
|
||||
namespace MWMechanics
|
||||
{
|
||||
template <class T>
|
||||
void modifyBaseInventory(const std::string& actorId, const std::string& itemId, int amount)
|
||||
{
|
||||
T copy = *MWBase::Environment::get().getWorld()->getStore().get<T>().find(actorId);
|
||||
for (auto& it : copy.mInventory.mList)
|
||||
{
|
||||
if (Misc::StringUtils::ciEqual(it.mItem, itemId))
|
||||
{
|
||||
const int sign = it.mCount < 1 ? -1 : 1;
|
||||
it.mCount = sign * std::max(it.mCount * sign + amount, 0);
|
||||
MWBase::Environment::get().getWorld()->createOverrideRecord(copy);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (amount > 0)
|
||||
{
|
||||
ESM::ContItem cont;
|
||||
cont.mItem = itemId;
|
||||
cont.mCount = amount;
|
||||
copy.mInventory.mList.push_back(cont);
|
||||
MWBase::Environment::get().getWorld()->createOverrideRecord(copy);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue