forked from mirror/openmw-tes3mp
refactored special variable code
This commit is contained in:
parent
f785659297
commit
ac112ef972
7 changed files with 58 additions and 94 deletions
|
@ -41,7 +41,7 @@ add_openmw_dir (mwscript
|
||||||
locals scriptmanagerimp compilercontext interpretercontext cellextensions miscextensions
|
locals scriptmanagerimp compilercontext interpretercontext cellextensions miscextensions
|
||||||
guiextensions soundextensions skyextensions statsextensions containerextensions
|
guiextensions soundextensions skyextensions statsextensions containerextensions
|
||||||
aiextensions controlextensions extensions globalscripts ref dialogueextensions
|
aiextensions controlextensions extensions globalscripts ref dialogueextensions
|
||||||
animationextensions transformationextensions consoleextensions userextensions
|
animationextensions transformationextensions consoleextensions userextensions locals
|
||||||
)
|
)
|
||||||
|
|
||||||
add_openmw_dir (mwsound
|
add_openmw_dir (mwsound
|
||||||
|
|
|
@ -13,7 +13,6 @@
|
||||||
#include "../mwbase/environment.hpp"
|
#include "../mwbase/environment.hpp"
|
||||||
#include "../mwbase/soundmanager.hpp"
|
#include "../mwbase/soundmanager.hpp"
|
||||||
#include "../mwbase/windowmanager.hpp"
|
#include "../mwbase/windowmanager.hpp"
|
||||||
#include "../mwbase/scriptmanager.hpp"
|
|
||||||
|
|
||||||
#include "../mwworld/containerstore.hpp"
|
#include "../mwworld/containerstore.hpp"
|
||||||
#include "../mwworld/class.hpp"
|
#include "../mwworld/class.hpp"
|
||||||
|
@ -245,27 +244,10 @@ namespace MWGui
|
||||||
invStore.equip(slot, invStore.end());
|
invStore.equip(slot, invStore.end());
|
||||||
std::string script = MWWorld::Class::get(*it).getScript(*it);
|
std::string script = MWWorld::Class::get(*it).getScript(*it);
|
||||||
|
|
||||||
/* Unset OnPCEquip Variable on item's script, if it has a script with that variable declared */
|
// Unset OnPCEquip Variable on item's script, if it has a script with that variable declared
|
||||||
if(script != "")
|
if(script != "")
|
||||||
{
|
(*it).mRefData->getLocals().setVarByInt(script, "onpcequip", 0);
|
||||||
Compiler::Locals locals = MWBase::Environment::get().getScriptManager()->getLocals(script);
|
|
||||||
int index = locals.getIndex("onpcequip");
|
|
||||||
char type = locals.getType("onpcequip");
|
|
||||||
if(index != -1)
|
|
||||||
{
|
|
||||||
switch(type)
|
|
||||||
{
|
|
||||||
case 's':
|
|
||||||
(*it).mRefData->getLocals().mShorts.at (index) = 0; break;
|
|
||||||
|
|
||||||
case 'l':
|
|
||||||
(*it).mRefData->getLocals().mLongs.at (index) = 0; break;
|
|
||||||
|
|
||||||
case 'f':
|
|
||||||
(*it).mRefData->getLocals().mFloats.at (index) = 0.0; break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
41
apps/openmw/mwscript/locals.cpp
Normal file
41
apps/openmw/mwscript/locals.cpp
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
#include "locals.hpp"
|
||||||
|
|
||||||
|
#include "../mwbase/environment.hpp"
|
||||||
|
#include "../mwbase/scriptmanager.hpp"
|
||||||
|
#include <components/compiler/locals.hpp>
|
||||||
|
|
||||||
|
namespace MWScript
|
||||||
|
{
|
||||||
|
void Locals::configure (const ESM::Script& script)
|
||||||
|
{
|
||||||
|
mShorts.clear();
|
||||||
|
mShorts.resize (script.mData.mNumShorts, 0);
|
||||||
|
mLongs.clear();
|
||||||
|
mLongs.resize (script.mData.mNumLongs, 0);
|
||||||
|
mFloats.clear();
|
||||||
|
mFloats.resize (script.mData.mNumFloats, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Locals::setVarByInt(const std::string& script, const std::string& var, int val)
|
||||||
|
{
|
||||||
|
Compiler::Locals locals = MWBase::Environment::get().getScriptManager()->getLocals(script);
|
||||||
|
int index = locals.getIndex(var);
|
||||||
|
char type = locals.getType(var);
|
||||||
|
if(index != -1)
|
||||||
|
{
|
||||||
|
switch(type)
|
||||||
|
{
|
||||||
|
case 's':
|
||||||
|
mShorts.at (index) = val; break;
|
||||||
|
|
||||||
|
case 'l':
|
||||||
|
mLongs.at (index) = val; break;
|
||||||
|
|
||||||
|
case 'f':
|
||||||
|
mFloats.at (index) = val; break;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
|
@ -8,21 +8,16 @@
|
||||||
|
|
||||||
namespace MWScript
|
namespace MWScript
|
||||||
{
|
{
|
||||||
struct Locals
|
class Locals
|
||||||
{
|
{
|
||||||
std::vector<Interpreter::Type_Short> mShorts;
|
public:
|
||||||
std::vector<Interpreter::Type_Integer> mLongs;
|
std::vector<Interpreter::Type_Short> mShorts;
|
||||||
std::vector<Interpreter::Type_Float> mFloats;
|
std::vector<Interpreter::Type_Integer> mLongs;
|
||||||
|
std::vector<Interpreter::Type_Float> mFloats;
|
||||||
|
|
||||||
|
void configure (const ESM::Script& script);
|
||||||
|
bool setVarByInt(const std::string& script, const std::string& var, int val);
|
||||||
|
|
||||||
void configure (const ESM::Script& script)
|
|
||||||
{
|
|
||||||
mShorts.clear();
|
|
||||||
mShorts.resize (script.mData.mNumShorts, 0);
|
|
||||||
mLongs.clear();
|
|
||||||
mLongs.resize (script.mData.mNumLongs, 0);
|
|
||||||
mFloats.clear();
|
|
||||||
mFloats.resize (script.mData.mNumFloats, 0);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
#include "../mwbase/environment.hpp"
|
#include "../mwbase/environment.hpp"
|
||||||
#include "../mwbase/world.hpp"
|
#include "../mwbase/world.hpp"
|
||||||
#include "../mwbase/windowmanager.hpp"
|
#include "../mwbase/windowmanager.hpp"
|
||||||
#include "../mwbase/scriptmanager.hpp"
|
|
||||||
|
|
||||||
#include <components/compiler/locals.hpp>
|
#include <components/compiler/locals.hpp>
|
||||||
|
|
||||||
|
@ -113,24 +112,6 @@ namespace MWWorld
|
||||||
|
|
||||||
/* Set OnPCEquip Variable on item's script, if the player is equipping it, and it has a script with that variable declared */
|
/* Set OnPCEquip Variable on item's script, if the player is equipping it, and it has a script with that variable declared */
|
||||||
if(equipped && actor == MWBase::Environment::get().getWorld()->getPlayer().getPlayer() && script != "")
|
if(equipped && actor == MWBase::Environment::get().getWorld()->getPlayer().getPlayer() && script != "")
|
||||||
{
|
(*it).mRefData->getLocals().setVarByInt(script, "onpcequip", 1);
|
||||||
Compiler::Locals locals = MWBase::Environment::get().getScriptManager()->getLocals(script);
|
|
||||||
int index = locals.getIndex("onpcequip");
|
|
||||||
char type = locals.getType("onpcequip");
|
|
||||||
if(index != -1)
|
|
||||||
{
|
|
||||||
switch(type)
|
|
||||||
{
|
|
||||||
case 's':
|
|
||||||
(*it).mRefData->getLocals().mShorts.at (index) = 1; break;
|
|
||||||
|
|
||||||
case 'l':
|
|
||||||
(*it).mRefData->getLocals().mLongs.at (index) = 1; break;
|
|
||||||
|
|
||||||
case 'f':
|
|
||||||
(*it).mRefData->getLocals().mFloats.at (index) = 1.0; break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,27 +88,10 @@ MWWorld::ContainerStoreIterator MWWorld::ContainerStore::add (const Ptr& ptr)
|
||||||
|
|
||||||
if(&(MWWorld::Class::get (player).getContainerStore (player)) == this)
|
if(&(MWWorld::Class::get (player).getContainerStore (player)) == this)
|
||||||
{
|
{
|
||||||
cell = 0; // Items in players inventory have cell set to 0, so their scripts will never be removed
|
cell = 0; // Items in player's inventory have cell set to 0, so their scripts will never be removed
|
||||||
|
|
||||||
// Set OnPCAdd special variable, if it is declared
|
// Set OnPCAdd special variable, if it is declared
|
||||||
Compiler::Locals locals = MWBase::Environment::get().getScriptManager()->getLocals(script);
|
item.mRefData->getLocals().setVarByInt(script, "onpcadd", 1);
|
||||||
int index = locals.getIndex("onpcadd");
|
|
||||||
char type = locals.getType("onpcadd");
|
|
||||||
|
|
||||||
if(index != -1)
|
|
||||||
{
|
|
||||||
switch(type)
|
|
||||||
{
|
|
||||||
case 's':
|
|
||||||
item.mRefData->getLocals().mShorts.at (index) = 1; break;
|
|
||||||
|
|
||||||
case 'l':
|
|
||||||
item.mRefData->getLocals().mLongs.at (index) = 1; break;
|
|
||||||
|
|
||||||
case 'f':
|
|
||||||
item.mRefData->getLocals().mFloats.at (index) = 1.0; break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
cell = player.getCell();
|
cell = player.getCell();
|
||||||
|
|
|
@ -1277,27 +1277,9 @@ namespace MWWorld
|
||||||
{
|
{
|
||||||
std::string script = MWWorld::Class::get(item).getScript(item);
|
std::string script = MWWorld::Class::get(item).getScript(item);
|
||||||
|
|
||||||
/* Set OnPCDrop Variable on item's script, if it has a script with that variable declared */
|
// Set OnPCDrop Variable on item's script, if it has a script with that variable declared
|
||||||
if(script != "")
|
if(script != "")
|
||||||
{
|
item.mRefData->getLocals().setVarByInt(script, "onpcdrop", 1);
|
||||||
Compiler::Locals locals = MWBase::Environment::get().getScriptManager()->getLocals(script);
|
|
||||||
int index = locals.getIndex("onpcdrop");
|
|
||||||
char type = locals.getType("onpcdrop");
|
|
||||||
if(index != -1)
|
|
||||||
{
|
|
||||||
switch(type)
|
|
||||||
{
|
|
||||||
case 's':
|
|
||||||
item.mRefData->getLocals().mShorts.at (index) = 1; break;
|
|
||||||
|
|
||||||
case 'l':
|
|
||||||
item.mRefData->getLocals().mLongs.at (index) = 1; break;
|
|
||||||
|
|
||||||
case 'f':
|
|
||||||
item.mRefData->getLocals().mFloats.at (index) = 1.0; break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool World::placeObject (const Ptr& object, float cursorX, float cursorY)
|
bool World::placeObject (const Ptr& object, float cursorX, float cursorY)
|
||||||
|
|
Loading…
Reference in a new issue