forked from teamnwah/openmw-tes3coop
GetEffect can accept an effect ID string as well
This commit is contained in:
parent
c1dfa980bf
commit
73437dfdca
4 changed files with 53 additions and 8 deletions
|
@ -1,6 +1,8 @@
|
|||
|
||||
#include "miscextensions.hpp"
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
#include <libs/openengine/ogre/fader.hpp>
|
||||
|
||||
#include <components/compiler/extensions.hpp>
|
||||
|
@ -317,10 +319,15 @@ namespace MWScript
|
|||
{
|
||||
MWWorld::Ptr ptr = R()(runtime);
|
||||
|
||||
int key = runtime[0].mInteger;
|
||||
std::string effect = runtime.getStringLiteral(runtime[0].mInteger);
|
||||
runtime.pop();
|
||||
|
||||
runtime.push (MWWorld::Class::get(ptr).getCreatureStats (ptr).getMagicEffects ().get (
|
||||
char *end;
|
||||
long key = strtol(effect.c_str(), &end, 10);
|
||||
if(key < 0 || key > 32767 || *end != '\0')
|
||||
key = ESM::MagicEffect::effectStringToId(effect);
|
||||
|
||||
runtime.push(MWWorld::Class::get(ptr).getCreatureStats(ptr).getMagicEffects().get(
|
||||
MWMechanics::EffectKey(key)).mMagnitude > 0);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -238,7 +238,7 @@ namespace Compiler
|
|||
extensions.registerInstruction ("wakeuppc", "", opcodeWakeUpPc);
|
||||
extensions.registerInstruction ("playbink", "Sl", opcodePlayBink);
|
||||
extensions.registerFunction ("getlocked", 'l', "", opcodeGetLocked, opcodeGetLockedExplicit);
|
||||
extensions.registerFunction ("geteffect", 'l', "l", opcodeGetEffect, opcodeGetEffectExplicit);
|
||||
extensions.registerFunction ("geteffect", 'l', "S", opcodeGetEffect, opcodeGetEffectExplicit);
|
||||
extensions.registerInstruction ("addsoulgem", "cc", opcodeAddSoulGem, opcodeAddSoulGemExplicit);
|
||||
extensions.registerInstruction ("removesoulgem", "c", opcodeRemoveSoulGem, opcodeRemoveSoulGemExplicit);
|
||||
extensions.registerInstruction ("drop", "cl", opcodeDrop, opcodeDropExplicit);
|
||||
|
|
|
@ -83,7 +83,8 @@ void MagicEffect::save(ESMWriter &esm)
|
|||
esm.writeHNOString("DESC", mDescription);
|
||||
}
|
||||
|
||||
std::string MagicEffect::effectIdToString(short effectID)
|
||||
|
||||
static std::map<short,std::string> genNameMap()
|
||||
{
|
||||
// Map effect ID to GMST name
|
||||
// http://www.uesp.net/morrow/hints/mweffects.shtml
|
||||
|
@ -235,10 +236,43 @@ std::string MagicEffect::effectIdToString(short effectID)
|
|||
// tribunal
|
||||
names[137] ="sEffectSummonFabricant";
|
||||
|
||||
if (names.find(effectID) == names.end())
|
||||
throw std::runtime_error( std::string("Unimplemented effect ID ") + boost::lexical_cast<std::string>(effectID));
|
||||
return names;
|
||||
}
|
||||
const std::map<short,std::string> MagicEffect::sNames = genNameMap();
|
||||
|
||||
return names[effectID];
|
||||
const std::string &MagicEffect::effectIdToString(short effectID)
|
||||
{
|
||||
std::map<short,std::string>::const_iterator name = sNames.find(effectID);
|
||||
if(name == sNames.end())
|
||||
throw std::runtime_error(std::string("Unimplemented effect ID ")+boost::lexical_cast<std::string>(effectID));
|
||||
|
||||
return name->second;
|
||||
}
|
||||
|
||||
class FindSecond {
|
||||
const std::string &mName;
|
||||
|
||||
public:
|
||||
FindSecond(const std::string &name) : mName(name) { }
|
||||
|
||||
bool operator()(const std::pair<short,std::string> &item) const
|
||||
{
|
||||
if(Misc::StringUtils::ciEqual(item.second, mName))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
short MagicEffect::effectStringToId(const std::string &effect)
|
||||
{
|
||||
std::map<short,std::string>::const_iterator name;
|
||||
|
||||
name = std::find_if(sNames.begin(), sNames.end(), FindSecond(effect));
|
||||
if(name == sNames.end())
|
||||
throw std::runtime_error(std::string("Unimplemented effect ")+effect);
|
||||
|
||||
return name->first;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#define OPENMW_ESM_MGEF_H
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
namespace ESM
|
||||
{
|
||||
|
@ -42,7 +43,10 @@ struct MagicEffect
|
|||
float mSpeed, mSize, mSizeCap;
|
||||
}; // 36 bytes
|
||||
|
||||
static std::string effectIdToString(short effectID);
|
||||
static const std::map<short,std::string> sNames;
|
||||
|
||||
static const std::string &effectIdToString(short effectID);
|
||||
static short effectStringToId(const std::string &effect);
|
||||
|
||||
|
||||
MEDTstruct mData;
|
||||
|
|
Loading…
Reference in a new issue