mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-20 11:53:52 +00:00
Feature #701: Spawn levelled creatures in cells
This commit is contained in:
parent
5049f3b134
commit
9653355cf1
4 changed files with 55 additions and 1 deletions
|
@ -3,6 +3,24 @@
|
||||||
|
|
||||||
#include <components/esm/loadlevlist.hpp>
|
#include <components/esm/loadlevlist.hpp>
|
||||||
|
|
||||||
|
#include "../mwmechanics/levelledlist.hpp"
|
||||||
|
|
||||||
|
#include "../mwworld/customdata.hpp"
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
struct CustomData : public MWWorld::CustomData
|
||||||
|
{
|
||||||
|
// TODO: save the creature we spawned here
|
||||||
|
virtual MWWorld::CustomData *clone() const;
|
||||||
|
};
|
||||||
|
|
||||||
|
MWWorld::CustomData *CustomData::clone() const
|
||||||
|
{
|
||||||
|
return new CustomData (*this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
namespace MWClass
|
namespace MWClass
|
||||||
{
|
{
|
||||||
std::string CreatureLevList::getName (const MWWorld::Ptr& ptr) const
|
std::string CreatureLevList::getName (const MWWorld::Ptr& ptr) const
|
||||||
|
@ -16,4 +34,33 @@ namespace MWClass
|
||||||
|
|
||||||
registerClass (typeid (ESM::CreatureLevList).name(), instance);
|
registerClass (typeid (ESM::CreatureLevList).name(), instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CreatureLevList::insertObjectRendering(const MWWorld::Ptr &ptr, MWRender::RenderingInterface &renderingInterface) const
|
||||||
|
{
|
||||||
|
ensureCustomData(ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CreatureLevList::ensureCustomData(const MWWorld::Ptr &ptr) const
|
||||||
|
{
|
||||||
|
if (!ptr.getRefData().getCustomData())
|
||||||
|
{
|
||||||
|
std::auto_ptr<CustomData> data (new CustomData);
|
||||||
|
|
||||||
|
MWWorld::LiveCellRef<ESM::CreatureLevList> *ref =
|
||||||
|
ptr.get<ESM::CreatureLevList>();
|
||||||
|
|
||||||
|
std::string id = MWMechanics::getLevelledItem(ref->mBase, true);
|
||||||
|
|
||||||
|
if (!id.empty())
|
||||||
|
{
|
||||||
|
const MWWorld::ESMStore& store = MWBase::Environment::get().getWorld()->getStore();
|
||||||
|
MWWorld::ManualRef ref(store, id);
|
||||||
|
ref.getPtr().getCellRef().mPos = ptr.getCellRef().mPos;
|
||||||
|
// TODO: hold on to this for respawn purposes later
|
||||||
|
MWBase::Environment::get().getWorld()->safePlaceObject(ref.getPtr(), *ptr.getCell() , ptr.getCellRef().mPos);
|
||||||
|
}
|
||||||
|
|
||||||
|
ptr.getRefData().setCustomData(data.release());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,8 @@ namespace MWClass
|
||||||
{
|
{
|
||||||
class CreatureLevList : public MWWorld::Class
|
class CreatureLevList : public MWWorld::Class
|
||||||
{
|
{
|
||||||
|
void ensureCustomData (const MWWorld::Ptr& ptr) const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
virtual std::string getName (const MWWorld::Ptr& ptr) const;
|
virtual std::string getName (const MWWorld::Ptr& ptr) const;
|
||||||
|
@ -14,6 +16,9 @@ namespace MWClass
|
||||||
/// can return an empty string.
|
/// can return an empty string.
|
||||||
|
|
||||||
static void registerSelf();
|
static void registerSelf();
|
||||||
|
|
||||||
|
virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const;
|
||||||
|
///< Add reference into a cell for rendering
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include "../mwworld/class.hpp"
|
#include "../mwworld/class.hpp"
|
||||||
#include "../mwbase/world.hpp"
|
#include "../mwbase/world.hpp"
|
||||||
#include "../mwbase/environment.hpp"
|
#include "../mwbase/environment.hpp"
|
||||||
|
#include "../mwmechanics/creaturestats.hpp"
|
||||||
|
|
||||||
namespace MWMechanics
|
namespace MWMechanics
|
||||||
{
|
{
|
||||||
|
|
|
@ -487,7 +487,6 @@ namespace MWWorld
|
||||||
insertCellRefList(mRendering, cell.mContainers, cell, *mPhysics, rescale, loadingListener);
|
insertCellRefList(mRendering, cell.mContainers, cell, *mPhysics, rescale, loadingListener);
|
||||||
insertCellRefList(mRendering, cell.mDoors, cell, *mPhysics, rescale, loadingListener);
|
insertCellRefList(mRendering, cell.mDoors, cell, *mPhysics, rescale, loadingListener);
|
||||||
insertCellRefList(mRendering, cell.mIngreds, cell, *mPhysics, rescale, loadingListener);
|
insertCellRefList(mRendering, cell.mIngreds, cell, *mPhysics, rescale, loadingListener);
|
||||||
insertCellRefList(mRendering, cell.mCreatureLists, cell, *mPhysics, rescale, loadingListener);
|
|
||||||
insertCellRefList(mRendering, cell.mItemLists, cell, *mPhysics, rescale, loadingListener);
|
insertCellRefList(mRendering, cell.mItemLists, cell, *mPhysics, rescale, loadingListener);
|
||||||
insertCellRefList(mRendering, cell.mLights, cell, *mPhysics, rescale, loadingListener);
|
insertCellRefList(mRendering, cell.mLights, cell, *mPhysics, rescale, loadingListener);
|
||||||
insertCellRefList(mRendering, cell.mLockpicks, cell, *mPhysics, rescale, loadingListener);
|
insertCellRefList(mRendering, cell.mLockpicks, cell, *mPhysics, rescale, loadingListener);
|
||||||
|
@ -499,6 +498,8 @@ namespace MWWorld
|
||||||
// Load NPCs and creatures _after_ everything else (important for adjustPosition to work correctly)
|
// Load NPCs and creatures _after_ everything else (important for adjustPosition to work correctly)
|
||||||
insertCellRefList(mRendering, cell.mCreatures, cell, *mPhysics, rescale, loadingListener);
|
insertCellRefList(mRendering, cell.mCreatures, cell, *mPhysics, rescale, loadingListener);
|
||||||
insertCellRefList(mRendering, cell.mNpcs, cell, *mPhysics, rescale, loadingListener);
|
insertCellRefList(mRendering, cell.mNpcs, cell, *mPhysics, rescale, loadingListener);
|
||||||
|
// Since this adds additional creatures, load afterwards, or they would be loaded twice
|
||||||
|
insertCellRefList(mRendering, cell.mCreatureLists, cell, *mPhysics, rescale, loadingListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Scene::addObjectToScene (const Ptr& ptr)
|
void Scene::addObjectToScene (const Ptr& ptr)
|
||||||
|
|
Loading…
Reference in a new issue