forked from teamnwah/openmw-tes3coop
Merge branch 'master' into dialogue
Conflicts: apps/openmw/CMakeLists.txt apps/openmw/mwclass/creature.cpp apps/openmw/mwclass/creature.hpp apps/openmw/mwclass/npc.cpp apps/openmw/mwclass/npc.hppactorid
commit
8086933282
@ -0,0 +1,31 @@
|
||||
#ifndef GAME_MWCLASS_CONTAINERUTIL_H
|
||||
#define GAME_MWCLASS_CONTAINERUTIL_H
|
||||
|
||||
#include <components/esm_store/cell_store.hpp>
|
||||
|
||||
#include "../mwworld/ptr.hpp"
|
||||
#include "../mwworld/containerstore.hpp"
|
||||
|
||||
namespace MWClass
|
||||
{
|
||||
template<typename T>
|
||||
void insertIntoContainerStore (const MWWorld::Ptr& ptr,
|
||||
ESMS::CellRefList<T, MWWorld::RefData>& containerStore)
|
||||
{
|
||||
if (!ptr.isEmpty())
|
||||
{
|
||||
// TODO check stacking
|
||||
|
||||
ESMS::LiveCellRef<T, MWWorld::RefData> cellRef;
|
||||
|
||||
cellRef.base = ptr.get<T>()->base;
|
||||
cellRef.ref = ptr.getCellRef();
|
||||
cellRef.mData = ptr.getRefData();
|
||||
|
||||
containerStore.list.push_back (cellRef);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@ -0,0 +1,273 @@
|
||||
|
||||
#include "containerextensions.hpp"
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
#include <components/compiler/extensions.hpp>
|
||||
|
||||
#include <components/interpreter/interpreter.hpp>
|
||||
#include <components/interpreter/runtime.hpp>
|
||||
#include <components/interpreter/opcodes.hpp>
|
||||
|
||||
#include "../mwworld/manualref.hpp"
|
||||
#include "../mwworld/class.hpp"
|
||||
#include "../mwworld/containerutil.hpp"
|
||||
|
||||
#include "interpretercontext.hpp"
|
||||
|
||||
namespace MWScript
|
||||
{
|
||||
namespace Container
|
||||
{
|
||||
class OpAddItem : public Interpreter::Opcode0
|
||||
{
|
||||
public:
|
||||
|
||||
virtual void execute (Interpreter::Runtime& runtime)
|
||||
{
|
||||
MWScript::InterpreterContext& context
|
||||
= static_cast<MWScript::InterpreterContext&> (runtime.getContext());
|
||||
|
||||
std::string item = runtime.getStringLiteral (runtime[0].mInteger);
|
||||
runtime.pop();
|
||||
|
||||
Interpreter::Type_Integer count = runtime[0].mInteger;
|
||||
runtime.pop();
|
||||
|
||||
if (count<0)
|
||||
throw std::runtime_error ("second argument for AddItem must be non-negative");
|
||||
|
||||
MWWorld::Ptr ptr = context.getReference();
|
||||
|
||||
MWWorld::ManualRef ref (context.getWorld().getStore(), item);
|
||||
|
||||
ref.getPtr().getRefData().setCount (count);
|
||||
|
||||
MWWorld::Class::get (ref.getPtr()).insertIntoContainer (ref.getPtr(),
|
||||
MWWorld::Class::get (ptr).getContainerStore (ptr));
|
||||
}
|
||||
};
|
||||
|
||||
class OpAddItemExplicit : public Interpreter::Opcode0
|
||||
{
|
||||
public:
|
||||
|
||||
virtual void execute (Interpreter::Runtime& runtime)
|
||||
{
|
||||
MWScript::InterpreterContext& context
|
||||
= static_cast<MWScript::InterpreterContext&> (runtime.getContext());
|
||||
|
||||
std::string id = runtime.getStringLiteral (runtime[0].mInteger);
|
||||
runtime.pop();
|
||||
|
||||
std::string item = runtime.getStringLiteral (runtime[0].mInteger);
|
||||
runtime.pop();
|
||||
|
||||
Interpreter::Type_Integer count = runtime[0].mInteger;
|
||||
runtime.pop();
|
||||
|
||||
if (count<0)
|
||||
throw std::runtime_error ("second argument for AddItem must be non-negative");
|
||||
|
||||
MWWorld::Ptr ptr = context.getWorld().getPtr (id, false);
|
||||
|
||||
MWWorld::ManualRef ref (context.getWorld().getStore(), item);
|
||||
|
||||
ref.getPtr().getRefData().setCount (count);
|
||||
|
||||
MWWorld::Class::get (ref.getPtr()).insertIntoContainer (ref.getPtr(),
|
||||
MWWorld::Class::get (ptr).getContainerStore (ptr));
|
||||
}
|
||||
};
|
||||
|
||||
class OpGetItemCount : public Interpreter::Opcode0
|
||||
{
|
||||
public:
|
||||
|
||||
virtual void execute (Interpreter::Runtime& runtime)
|
||||
{
|
||||
MWScript::InterpreterContext& context
|
||||
= static_cast<MWScript::InterpreterContext&> (runtime.getContext());
|
||||
|
||||
std::string item = runtime.getStringLiteral (runtime[0].mInteger);
|
||||
runtime.pop();
|
||||
|
||||
MWWorld::Ptr ptr = context.getReference();
|
||||
|
||||
std::vector<MWWorld::Ptr> list;
|
||||
|
||||
MWWorld::listItemsInContainer (item,
|
||||
MWWorld::Class::get (ptr).getContainerStore (ptr),
|
||||
context.getWorld().getStore(), list);
|
||||
|
||||
Interpreter::Type_Integer sum = 0;
|
||||
|
||||
for (std::vector<MWWorld::Ptr>::iterator iter (list.begin()); iter!=list.end();
|
||||
++iter)
|
||||
{
|
||||
sum += iter->getRefData().getCount();
|
||||
}
|
||||
|
||||
runtime.push (sum);
|
||||
}
|
||||
};
|
||||
|
||||
class OpGetItemCountExplicit : public Interpreter::Opcode0
|
||||
{
|
||||
public:
|
||||
|
||||
virtual void execute (Interpreter::Runtime& runtime)
|
||||
{
|
||||
MWScript::InterpreterContext& context
|
||||
= static_cast<MWScript::InterpreterContext&> (runtime.getContext());
|
||||
|
||||
std::string id = runtime.getStringLiteral (runtime[0].mInteger);
|
||||
runtime.pop();
|
||||
|
||||
std::string item = runtime.getStringLiteral (runtime[0].mInteger);
|
||||
runtime.pop();
|
||||
|
||||
MWWorld::Ptr ptr = context.getWorld().getPtr (id, false);
|
||||
|
||||
std::vector<MWWorld::Ptr> list;
|
||||
|
||||
MWWorld::listItemsInContainer (item,
|
||||
MWWorld::Class::get (ptr).getContainerStore (ptr),
|
||||
context.getWorld().getStore(), list);
|
||||
|
||||
Interpreter::Type_Integer sum = 0;
|
||||
|
||||
for (std::vector<MWWorld::Ptr>::iterator iter (list.begin()); iter!=list.end();
|
||||
++iter)
|
||||
{
|
||||
sum += iter->getRefData().getCount();
|
||||
}
|
||||
|
||||
runtime.push (sum);
|
||||
}
|
||||
};
|
||||
|
||||
class OpRemoveItem : public Interpreter::Opcode0
|
||||
{
|
||||
public:
|
||||
|
||||
virtual void execute (Interpreter::Runtime& runtime)
|
||||
{
|
||||
MWScript::InterpreterContext& context
|
||||
= static_cast<MWScript::InterpreterContext&> (runtime.getContext());
|
||||
|
||||
std::string item = runtime.getStringLiteral (runtime[0].mInteger);
|
||||
runtime.pop();
|
||||
|
||||
Interpreter::Type_Integer count = runtime[0].mInteger;
|
||||
runtime.pop();
|
||||
|
||||
if (count<0)
|
||||
throw std::runtime_error ("second argument for RemoveItem must be non-negative");
|
||||
|
||||
MWWorld::Ptr ptr = context.getReference();
|
||||
|
||||
std::vector<MWWorld::Ptr> list;
|
||||
|
||||
MWWorld::listItemsInContainer (item,
|
||||
MWWorld::Class::get (ptr).getContainerStore (ptr),
|
||||
context.getWorld().getStore(), list);
|
||||
|
||||
for (std::vector<MWWorld::Ptr>::iterator iter (list.begin());
|
||||
iter!=list.end() && count;
|
||||
++iter)
|
||||
{
|
||||
if (iter->getRefData().getCount()<=count)
|
||||
{
|
||||
count -= iter->getRefData().getCount();
|
||||
iter->getRefData().setCount (0);
|
||||
}
|
||||
else
|
||||
{
|
||||
iter->getRefData().setCount (iter->getRefData().getCount()-count);
|
||||
count = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// To be fully compatible with original Morrowind, we would need to check if
|
||||
// count is >= 0 here and throw an exception. But let's be tollerant instead.
|
||||
}
|
||||
};
|
||||
|
||||
class OpRemoveItemExplicit : public Interpreter::Opcode0
|
||||
{
|
||||
public:
|
||||
|
||||
virtual void execute (Interpreter::Runtime& runtime)
|
||||
{
|
||||
MWScript::InterpreterContext& context
|
||||
= static_cast<MWScript::InterpreterContext&> (runtime.getContext());
|
||||
|
||||
std::string id = runtime.getStringLiteral (runtime[0].mInteger);
|
||||
runtime.pop();
|
||||
|
||||
std::string item = runtime.getStringLiteral (runtime[0].mInteger);
|
||||
runtime.pop();
|
||||
|
||||
Interpreter::Type_Integer count = runtime[0].mInteger;
|
||||
runtime.pop();
|
||||
|
||||
if (count<0)
|
||||
throw std::runtime_error ("second argument for RemoveItem must be non-negative");
|
||||
|
||||
MWWorld::Ptr ptr = context.getWorld().getPtr (id, false);
|
||||
|
||||
std::vector<MWWorld::Ptr> list;
|
||||
|
||||
MWWorld::listItemsInContainer (item,
|
||||
MWWorld::Class::get (ptr).getContainerStore (ptr),
|
||||
context.getWorld().getStore(), list);
|
||||
|
||||
for (std::vector<MWWorld::Ptr>::iterator iter (list.begin());
|
||||
iter!=list.end() && count;
|
||||
++iter)
|
||||
{
|
||||
if (iter->getRefData().getCount()<=count)
|
||||
{
|
||||
count -= iter->getRefData().getCount();
|
||||
iter->getRefData().setCount (0);
|
||||
}
|
||||
else
|
||||
{
|
||||
iter->getRefData().setCount (iter->getRefData().getCount()-count);
|
||||
count = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// To be fully compatible with original Morrowind, we would need to check if
|
||||
// count is >= 0 here and throw an exception. But let's be tollerant instead.
|
||||
}
|
||||
};
|
||||
|
||||
const int opcodeAddItem = 0x2000076;
|
||||
const int opcodeAddItemExplicit = 0x2000077;
|
||||
const int opcodeGetItemCount = 0x2000078;
|
||||
const int opcodeGetItemCountExplicit = 0x2000079;
|
||||
const int opcodeRemoveItem = 0x200007a;
|
||||
const int opcodeRemoveItemExplicit = 0x200007b;
|
||||
|
||||
void registerExtensions (Compiler::Extensions& extensions)
|
||||
{
|
||||
extensions.registerInstruction ("additem", "cl", opcodeAddItem, opcodeAddItemExplicit);
|
||||
extensions.registerFunction ("getitemcount", 'l', "c", opcodeGetItemCount,
|
||||
opcodeGetItemCountExplicit);
|
||||
extensions.registerInstruction ("removeitem", "cl", opcodeRemoveItem,
|
||||
opcodeRemoveItemExplicit);
|
||||
}
|
||||
|
||||
void installOpcodes (Interpreter::Interpreter& interpreter)
|
||||
{
|
||||
interpreter.installSegment5 (opcodeAddItem, new OpAddItem);
|
||||
interpreter.installSegment5 (opcodeAddItemExplicit, new OpAddItemExplicit);
|
||||
interpreter.installSegment5 (opcodeGetItemCount, new OpGetItemCount);
|
||||
interpreter.installSegment5 (opcodeGetItemCountExplicit, new OpGetItemCountExplicit);
|
||||
interpreter.installSegment5 (opcodeRemoveItem, new OpRemoveItem);
|
||||
interpreter.installSegment5 (opcodeRemoveItemExplicit, new OpRemoveItemExplicit);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
#ifndef GAME_SCRIPT_CONTAINEREXTENSIONS_H
|
||||
#define GAME_SCRIPT_CONTAINEREXTENSIONS_H
|
||||
|
||||
namespace Compiler
|
||||
{
|
||||
class Extensions;
|
||||
}
|
||||
|
||||
namespace Interpreter
|
||||
{
|
||||
class Interpreter;
|
||||
}
|
||||
|
||||
namespace MWScript
|
||||
{
|
||||
/// \brief stats-related script functionality (creatures and NPCs)
|
||||
namespace Container
|
||||
{
|
||||
void registerExtensions (Compiler::Extensions& extensions);
|
||||
|
||||
void installOpcodes (Interpreter::Interpreter& interpreter);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@ -0,0 +1,23 @@
|
||||
|
||||
#include "actiontake.hpp"
|
||||
|
||||
#include "class.hpp"
|
||||
#include "environment.hpp"
|
||||
#include "world.hpp"
|
||||
|
||||
namespace MWWorld
|
||||
{
|
||||
ActionTake::ActionTake (const MWWorld::Ptr& object) : mObject (object) {}
|
||||
|
||||
void ActionTake::execute (Environment& environment)
|
||||
{
|
||||
// insert into player's inventory
|
||||
MWWorld::Ptr player = environment.mWorld->getPtr ("player", true);
|
||||
|
||||
MWWorld::Class::get (mObject).insertIntoContainer (mObject,
|
||||
MWWorld::Class::get (player).getContainerStore (player));
|
||||
|
||||
// remove from world
|
||||
environment.mWorld->deleteObject (mObject);
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
#ifndef GAME_MWWORLD_ACTIONTAKE_H
|
||||
#define GAME_MWWORLD_ACTIONTAKE_H
|
||||
|
||||
#include "action.hpp"
|
||||
#include "ptr.hpp"
|
||||
|
||||
namespace MWWorld
|
||||
{
|
||||
class ActionTake : public Action
|
||||
{
|
||||
MWWorld::Ptr mObject;
|
||||
|
||||
public:
|
||||
|
||||
ActionTake (const MWWorld::Ptr& object);
|
||||
|
||||
virtual void execute (Environment& environment);
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
@ -0,0 +1,43 @@
|
||||
|
||||
#include "containerutil.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
template<typename T>
|
||||
void listItemsInContainerImp (const std::string& id,
|
||||
ESMS::CellRefList<T, MWWorld::RefData>& containerStore,
|
||||
const ESMS::RecListT<T>& store, std::vector<MWWorld::Ptr>& list)
|
||||
{
|
||||
if (const T *record = store.search (id))
|
||||
{
|
||||
for (typename ESMS::CellRefList<T, MWWorld::RefData>::List::iterator iter
|
||||
(containerStore.list.begin());
|
||||
iter!=containerStore.list.end(); ++iter)
|
||||
{
|
||||
if (iter->base==record)
|
||||
list.push_back (MWWorld::Ptr (&*iter, 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace MWWorld
|
||||
{
|
||||
void listItemsInContainer (const std::string& id,
|
||||
ContainerStore<MWWorld::RefData>& containerStore,
|
||||
const ESMS::ESMStore& store, std::vector<Ptr>& list)
|
||||
{
|
||||
listItemsInContainerImp (id, containerStore.potions, store.potions, list);
|
||||
listItemsInContainerImp (id, containerStore.appas, store.appas, list);
|
||||
listItemsInContainerImp (id, containerStore.armors, store.armors, list);
|
||||
listItemsInContainerImp (id, containerStore.books, store.books, list);
|
||||
listItemsInContainerImp (id, containerStore.clothes, store.clothes, list);
|
||||
listItemsInContainerImp (id, containerStore.ingreds, store.ingreds, list);
|
||||
listItemsInContainerImp (id, containerStore.lights, store.lights, list);
|
||||
listItemsInContainerImp (id, containerStore.lockpicks, store.lockpicks, list);
|
||||
listItemsInContainerImp (id, containerStore.miscItems, store.miscItems, list);
|
||||
listItemsInContainerImp (id, containerStore.probes, store.probes, list);
|
||||
listItemsInContainerImp (id, containerStore.repairs, store.repairs, list);
|
||||
listItemsInContainerImp (id, containerStore.weapons, store.weapons, list);
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
#ifndef GAME_MWWORLD_CONTAINERUTIL_H
|
||||
#define GAME_MWWORLD_CONTAINERUTIL_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <components/esm_store/store.hpp>
|
||||
|
||||
#include "containerstore.hpp"
|
||||
#include "ptr.hpp"
|
||||
#include "refdata.hpp"
|
||||
|
||||
namespace MWWorld
|
||||
{
|
||||
void listItemsInContainer (const std::string& id, ContainerStore<MWWorld::RefData>& containerStore,
|
||||
const ESMS::ESMStore& store, std::vector<Ptr>& list);
|
||||
///< append all references with the given id to list.
|
||||
}
|
||||
|
||||
#endif
|
@ -0,0 +1,103 @@
|
||||
#ifndef GAME_MWWORLD_MANUALREF_H
|
||||
#define GAME_MWWORLD_MANUALREF_H
|
||||
|
||||
#include <boost/any.hpp>
|
||||
|
||||
#include <components/esm_store/cell_store.hpp>
|
||||
#include <components/esm_store/store.hpp>
|
||||
|
||||
#include "ptr.hpp"
|
||||
|
||||
namespace MWWorld
|
||||
{
|
||||
/// \brief Manually constructed live cell ref
|
||||
class ManualRef
|
||||
{
|
||||
boost::any mRef;
|
||||
Ptr mPtr;
|
||||
|
||||
ManualRef (const ManualRef&);
|
||||
ManualRef& operator= (const ManualRef&);
|
||||
|
||||
template<typename T>
|
||||
bool create (const ESMS::RecListT<T>& list, const std::string& name)
|
||||
{
|
||||
if (const T *instance = list.search (name))
|
||||
{
|
||||
ESMS::LiveCellRef<T, RefData> ref;
|
||||
ref.base = instance;
|
||||
|
||||
mRef = ref;
|
||||
mPtr = Ptr (&boost::any_cast<ESMS::LiveCellRef<T, RefData>&> (mRef), 0);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool create (const ESMS::RecListWithIDT<T>& list, const std::string& name)
|
||||
{
|
||||
if (const T *instance = list.search (name))
|
||||
{
|
||||
ESMS::LiveCellRef<T, RefData> ref;
|
||||
ref.base = instance;
|
||||
|
||||
mRef = ref;
|
||||
mPtr = Ptr (&boost::any_cast<ESMS::LiveCellRef<T, RefData>&> (mRef), 0);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
ManualRef (const ESMS::ESMStore& store, const std::string& name)
|
||||
{
|
||||
// create
|
||||
if (!create (store.activators, name) &&
|
||||
!create (store.potions, name) &&
|
||||
!create (store.appas, name) &&
|
||||
!create (store.armors, name) &&
|
||||
!create (store.books, name) &&
|
||||
!create (store.clothes, name) &&
|
||||
!create (store.containers, name) &&
|
||||
!create (store.creatures, name) &&
|
||||
!create (store.doors, name) &&
|
||||
!create (store.ingreds, name) &&
|
||||
!create (store.creatureLists, name) &&
|
||||
!create (store.itemLists, name) &&
|
||||
!create (store.lights, name) &&
|
||||
!create (store.lockpicks, name) &&
|
||||
!create (store.miscItems, name) &&
|
||||
!create (store.npcs, name) &&
|
||||
!create (store.probes, name) &&
|
||||
!create (store.repairs, name) &&
|
||||
!create (store.statics, name) &&
|
||||
!create (store.weapons, name))
|
||||
throw std::logic_error ("failed to create manual cell ref for " + name);
|
||||
|
||||
// initialise
|
||||
ESM::CellRef& cellRef = mPtr.getCellRef();
|
||||
cellRef.refnum = -1;
|
||||
cellRef.scale = 1;
|
||||
cellRef.factIndex = 0;
|
||||
cellRef.charge = 0;
|
||||
cellRef.intv = 0;
|
||||
cellRef.nam9 = 0;
|
||||
cellRef.teleport = false;
|
||||
cellRef.lockLevel = 0;
|
||||
cellRef.unam = 0;
|
||||
}
|
||||
|
||||
const Ptr& getPtr() const
|
||||
{
|
||||
return mPtr;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue