mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-21 10:53:51 +00:00
Implemented OnPCDrop special variable
Scripts are responsible for resetting to 0, as investigation showed that is how vanilla handled it.
This commit is contained in:
parent
0fc5ee5149
commit
9ad08520fd
2 changed files with 42 additions and 7 deletions
|
@ -2,11 +2,13 @@
|
|||
|
||||
#include <components/bsa/bsa_archive.hpp>
|
||||
#include <components/files/collections.hpp>
|
||||
#include <components/compiler/locals.hpp>
|
||||
|
||||
#include "../mwbase/environment.hpp"
|
||||
#include "../mwbase/soundmanager.hpp"
|
||||
#include "../mwbase/mechanicsmanager.hpp"
|
||||
#include "../mwbase/windowmanager.hpp"
|
||||
#include "../mwbase/scriptmanager.hpp"
|
||||
|
||||
#include "../mwrender/sky.hpp"
|
||||
#include "../mwrender/player.hpp"
|
||||
|
@ -1271,6 +1273,33 @@ namespace MWWorld
|
|||
mRendering->toggleWater();
|
||||
}
|
||||
|
||||
void World::PCDropped (const Ptr& 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 */
|
||||
if(script != "")
|
||||
{
|
||||
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)
|
||||
{
|
||||
std::pair<bool, Ogre::Vector3> result = mPhysics->castRay(cursorX, cursorY);
|
||||
|
@ -1293,9 +1322,10 @@ namespace MWWorld
|
|||
pos.pos[1] = -result.second[2];
|
||||
pos.pos[2] = result.second[1];
|
||||
|
||||
copyObjectToCell(object, *cell, pos);
|
||||
Ptr dropped = copyObjectToCell(object, *cell, pos);
|
||||
PCDropped(dropped);
|
||||
object.getRefData().setCount(0);
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1310,8 +1340,8 @@ namespace MWWorld
|
|||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
World::copyObjectToCell(const Ptr &object, CellStore &cell, const ESM::Position &pos)
|
||||
|
||||
Ptr World::copyObjectToCell(const Ptr &object, CellStore &cell, const ESM::Position &pos)
|
||||
{
|
||||
/// \todo add searching correct cell for position specified
|
||||
MWWorld::Ptr dropped =
|
||||
|
@ -1335,6 +1365,8 @@ namespace MWWorld
|
|||
}
|
||||
addContainerScripts(dropped, &cell);
|
||||
}
|
||||
|
||||
return dropped;
|
||||
}
|
||||
|
||||
void World::dropObjectOnGround (const Ptr& actor, const Ptr& object)
|
||||
|
@ -1355,7 +1387,9 @@ namespace MWWorld
|
|||
mPhysics->castRay(orig, dir, len);
|
||||
pos.pos[2] = hit.second.z;
|
||||
|
||||
copyObjectToCell(object, *cell, pos);
|
||||
Ptr dropped = copyObjectToCell(object, *cell, pos);
|
||||
if(actor == mPlayer->getPlayer()) // Only call if dropped by player
|
||||
PCDropped(dropped);
|
||||
object.getRefData().setCount(0);
|
||||
}
|
||||
|
||||
|
|
|
@ -91,8 +91,8 @@ namespace MWWorld
|
|||
bool moveObjectImp (const Ptr& ptr, float x, float y, float z);
|
||||
///< @return true if the active cell (cell player is in) changed
|
||||
|
||||
virtual void
|
||||
copyObjectToCell(const Ptr &ptr, CellStore &cell, const ESM::Position &pos);
|
||||
|
||||
Ptr copyObjectToCell(const Ptr &ptr, CellStore &cell, const ESM::Position &pos);
|
||||
|
||||
void updateWindowManager ();
|
||||
void performUpdateSceneQueries ();
|
||||
|
@ -107,6 +107,7 @@ namespace MWWorld
|
|||
|
||||
void removeContainerScripts(const Ptr& reference);
|
||||
void addContainerScripts(const Ptr& reference, Ptr::CellStore* cell);
|
||||
void PCDropped (const Ptr& item);
|
||||
|
||||
public:
|
||||
|
||||
|
|
Loading…
Reference in a new issue