Merge remote-tracking branch 'greye/player-dynamics' into next

actorid
Marc Zinnschlag 12 years ago
commit 2be60041f3

@ -29,6 +29,7 @@ namespace ESM
struct Class; struct Class;
struct Potion; struct Potion;
struct Spell; struct Spell;
struct NPC;
} }
namespace MWRender namespace MWRender
@ -230,24 +231,28 @@ namespace MWBase
///< Toggle a render mode. ///< Toggle a render mode.
///< \return Resulting mode ///< \return Resulting mode
virtual std::pair<std::string, const ESM::Potion *> createRecord (const ESM::Potion& record) virtual const ESM::Potion *createRecord (const ESM::Potion& record)
= 0; = 0;
///< Create a new recrod (of type potion) in the ESM store. ///< Create a new recrod (of type potion) in the ESM store.
/// \return ID, pointer to created record /// \return pointer to created record
virtual std::pair<std::string, const ESM::Spell *> createRecord (const ESM::Spell& record) virtual const ESM::Spell *createRecord (const ESM::Spell& record)
= 0; = 0;
///< Create a new recrod (of type spell) in the ESM store. ///< Create a new recrod (of type spell) in the ESM store.
/// \return ID, pointer to created record /// \return pointer to created record
virtual std::pair<std::string, const ESM::Class *> createRecord (const ESM::Class& record) virtual const ESM::Class *createRecord (const ESM::Class& record)
= 0; = 0;
///< Create a new recrod (of type class) in the ESM store. ///< Create a new recrod (of type class) in the ESM store.
/// \return ID, pointer to created record /// \return pointer to created record
virtual const ESM::Cell *createRecord (const ESM::Cell& record) = 0; virtual const ESM::Cell *createRecord (const ESM::Cell& record) = 0;
///< Create a new recrod (of type cell) in the ESM store. ///< Create a new recrod (of type cell) in the ESM store.
/// \return ID, pointer to created record /// \return pointer to created record
virtual const ESM::NPC *createRecord(const ESM::NPC &record) = 0;
///< Create a new recrod (of type npc) in the ESM store.
/// \return pointer to created record
virtual void playAnimationGroup (const MWWorld::Ptr& ptr, const std::string& groupName, virtual void playAnimationGroup (const MWWorld::Ptr& ptr, const std::string& groupName,
int mode, int number = 1) = 0; int mode, int number = 1) = 0;

@ -559,6 +559,7 @@ void CharacterCreation::onCreateClassDialogDone(WindowBase* parWindow)
klass.mData.mSkills[i][1] = majorSkills[i]; klass.mData.mSkills[i][1] = majorSkills[i];
klass.mData.mSkills[i][0] = minorSkills[i]; klass.mData.mSkills[i][0] = minorSkills[i];
} }
MWBase::Environment::get().getMechanicsManager()->setPlayerClass(klass); MWBase::Environment::get().getMechanicsManager()->setPlayerClass(klass);
mPlayerClass = klass; mPlayerClass = klass;
mWM->setPlayerClass(klass); mWM->setPlayerClass(klass);

@ -108,7 +108,8 @@ namespace MWGui
void LevelupDialog::open() void LevelupDialog::open()
{ {
MWWorld::Ptr player = MWBase::Environment::get().getWorld ()->getPlayer().getPlayer(); MWBase::World *world = MWBase::Environment::get().getWorld();
MWWorld::Ptr player = world->getPlayer().getPlayer();
MWMechanics::CreatureStats& creatureStats = MWWorld::Class::get(player).getCreatureStats (player); MWMechanics::CreatureStats& creatureStats = MWWorld::Class::get(player).getCreatureStats (player);
MWMechanics::NpcStats& pcStats = MWWorld::Class::get(player).getNpcStats (player); MWMechanics::NpcStats& pcStats = MWWorld::Class::get(player).getNpcStats (player);
@ -119,20 +120,13 @@ namespace MWGui
setAttributeValues(); setAttributeValues();
const ESM::NPC *playerData = player.get<ESM::NPC>()->mBase;
// set class image // set class image
const ESM::Class& playerClass = MWBase::Environment::get().getWorld ()->getPlayer ().getClass (); const ESM::Class *cls =
// retrieve the ID to this class world->getStore().get<ESM::Class>().find(playerData->mClass);
std::string classId;
const MWWorld::Store<ESM::Class> &classes = mClassImage->setImageTexture ("textures\\levelup\\" + cls->mId + ".dds");
MWBase::Environment::get().getWorld()->getStore().get<ESM::Class>();
MWWorld::Store<ESM::Class>::iterator it = classes.begin();
for (; it != classes.end(); ++it)
{
if (playerClass.mName == it->mName)
classId = it->mId;
}
mClassImage->setImageTexture ("textures\\levelup\\" + classId + ".dds");
/// \todo replace this with INI-imported texts /// \todo replace this with INI-imported texts
int level = creatureStats.getLevel ()+1; int level = creatureStats.getLevel ()+1;

@ -336,12 +336,12 @@ namespace MWGui
MWBase::Environment::get().getSoundManager()->playSound ("Item Gold Up", 1.0, 1.0); MWBase::Environment::get().getSoundManager()->playSound ("Item Gold Up", 1.0, 1.0);
std::pair<std::string, const ESM::Spell*> result = MWBase::Environment::get().getWorld()->createRecord(mSpell); const ESM::Spell* spell = MWBase::Environment::get().getWorld()->createRecord(mSpell);
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer(); MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer();
MWMechanics::CreatureStats& stats = MWWorld::Class::get(player).getCreatureStats(player); MWMechanics::CreatureStats& stats = MWWorld::Class::get(player).getCreatureStats(player);
MWMechanics::Spells& spells = stats.getSpells(); MWMechanics::Spells& spells = stats.getSpells();
spells.add (result.first); spells.add (spell->mId);
MWBase::Environment::get().getSoundManager()->playSound ("Item Gold Up", 1.0, 1.0); MWBase::Environment::get().getSoundManager()->playSound ("Item Gold Up", 1.0, 1.0);

@ -253,7 +253,10 @@ void StatsWindow::onFrame ()
setFactions(PCstats.getFactionRanks()); setFactions(PCstats.getFactionRanks());
setBirthSign(MWBase::Environment::get().getWorld()->getPlayer().getBirthsign()); const std::string &signId =
MWBase::Environment::get().getWorld()->getPlayer().getBirthSign();
setBirthSign(signId);
if (mChanged) if (mChanged)
updateSkillArea(); updateSkillArea();
@ -426,11 +429,13 @@ void StatsWindow::updateSkillArea()
if (!mMiscSkills.empty()) if (!mMiscSkills.empty())
addSkills(mMiscSkills, "sSkillClassMisc", "Misc Skills", coord1, coord2); addSkills(mMiscSkills, "sSkillClassMisc", "Misc Skills", coord1, coord2);
const MWWorld::ESMStore &store = MWBase::Environment::get().getWorld()->getStore(); MWBase::World *world = MWBase::Environment::get().getWorld();
const MWWorld::ESMStore &store = world->getStore();
const ESM::NPC *player =
world->getPlayer().getPlayer().get<ESM::NPC>()->mBase;
// race tooltip // race tooltip
const ESM::Race* playerRace = const ESM::Race* playerRace = store.get<ESM::Race>().find(player->mRace);
store.get<ESM::Race>().find (MWBase::Environment::get().getWorld()->getPlayer().getRace());
MyGUI::Widget* raceWidget; MyGUI::Widget* raceWidget;
getWidget(raceWidget, "RaceText"); getWidget(raceWidget, "RaceText");
@ -440,11 +445,14 @@ void StatsWindow::updateSkillArea()
// class tooltip // class tooltip
MyGUI::Widget* classWidget; MyGUI::Widget* classWidget;
const ESM::Class& playerClass = MWBase::Environment::get().getWorld()->getPlayer().getClass();
const ESM::Class *playerClass =
store.get<ESM::Class>().find(player->mClass);
getWidget(classWidget, "ClassText"); getWidget(classWidget, "ClassText");
ToolTips::createClassToolTip(classWidget, playerClass); ToolTips::createClassToolTip(classWidget, *playerClass);
getWidget(classWidget, "Class_str"); getWidget(classWidget, "Class_str");
ToolTips::createClassToolTip(classWidget, playerClass); ToolTips::createClassToolTip(classWidget, *playerClass);
if (!mFactions.empty()) if (!mFactions.empty())
{ {

@ -83,7 +83,6 @@ WindowManager::WindowManager(
, mSpellCreationDialog(NULL) , mSpellCreationDialog(NULL)
, mEnchantingDialog(NULL) , mEnchantingDialog(NULL)
, mTrainingWindow(NULL) , mTrainingWindow(NULL)
, mPlayerClass()
, mPlayerName() , mPlayerName()
, mPlayerRaceId() , mPlayerRaceId()
, mPlayerAttributes() , mPlayerAttributes()
@ -499,8 +498,7 @@ void WindowManager::setValue (const std::string& id, int value)
void WindowManager::setPlayerClass (const ESM::Class &class_) void WindowManager::setPlayerClass (const ESM::Class &class_)
{ {
mPlayerClass = class_; mStatsWindow->setValue("class", class_.mName);
mStatsWindow->setValue("class", mPlayerClass.mName);
} }
void WindowManager::configureSkills (const SkillList& major, const SkillList& minor) void WindowManager::configureSkills (const SkillList& major, const SkillList& minor)

@ -261,7 +261,6 @@ namespace MWGui
/// \todo get rid of this stuff. Move it to the respective UI element classes, if needed. /// \todo get rid of this stuff. Move it to the respective UI element classes, if needed.
// Various stats about player as needed by window manager // Various stats about player as needed by window manager
ESM::Class mPlayerClass;
std::string mPlayerName; std::string mPlayerName;
std::string mPlayerRaceId; std::string mPlayerRaceId;
std::map<int, MWMechanics::Stat<int> > mPlayerAttributes; std::map<int, MWMechanics::Stat<int> > mPlayerAttributes;

@ -279,7 +279,7 @@ void MWMechanics::Alchemy::addPotion (const std::string& name)
newRecord.mEffects.mList = mEffects; newRecord.mEffects.mList = mEffects;
record = MWBase::Environment::get().getWorld()->createRecord (newRecord).second; record = MWBase::Environment::get().getWorld()->createRecord (newRecord);
} }
MWWorld::ManualRef ref (MWBase::Environment::get().getWorld()->getStore(), record->mId); MWWorld::ManualRef ref (MWBase::Environment::get().getWorld()->getStore(), record->mId);

@ -38,15 +38,16 @@ namespace MWMechanics
creatureStats.getAttribute(6).setBase (player->mNpdt52.mPersonality); creatureStats.getAttribute(6).setBase (player->mNpdt52.mPersonality);
creatureStats.getAttribute(7).setBase (player->mNpdt52.mLuck); creatureStats.getAttribute(7).setBase (player->mNpdt52.mLuck);
const MWWorld::ESMStore &esmStore =
MWBase::Environment::get().getWorld()->getStore();
// race // race
if (mRaceSelected) if (mRaceSelected)
{ {
const ESM::Race *race = const ESM::Race *race =
MWBase::Environment::get().getWorld()->getStore().get<ESM::Race>().find ( esmStore.get<ESM::Race>().find(player->mRace);
MWBase::Environment::get().getWorld()->getPlayer().getRace()
);
bool male = MWBase::Environment::get().getWorld()->getPlayer().isMale(); bool male = (player->mFlags & ESM::NPC::Female) == 0;
for (int i=0; i<8; ++i) for (int i=0; i<8; ++i)
{ {
@ -89,11 +90,13 @@ namespace MWMechanics
} }
// birthsign // birthsign
if (!MWBase::Environment::get().getWorld()->getPlayer().getBirthsign().empty()) const std::string &signId =
MWBase::Environment::get().getWorld()->getPlayer().getBirthSign();
if (!signId.empty())
{ {
const ESM::BirthSign *sign = const ESM::BirthSign *sign =
MWBase::Environment::get().getWorld()->getStore().get<ESM::BirthSign>().find ( esmStore.get<ESM::BirthSign>().find(signId);
MWBase::Environment::get().getWorld()->getPlayer().getBirthsign());
for (std::vector<std::string>::const_iterator iter (sign->mPowers.mList.begin()); for (std::vector<std::string>::const_iterator iter (sign->mPowers.mList.begin());
iter!=sign->mPowers.mList.end(); ++iter) iter!=sign->mPowers.mList.end(); ++iter)
@ -105,11 +108,12 @@ namespace MWMechanics
// class // class
if (mClassSelected) if (mClassSelected)
{ {
const ESM::Class& class_ = MWBase::Environment::get().getWorld()->getPlayer().getClass(); const ESM::Class *class_ =
esmStore.get<ESM::Class>().find(player->mClass);
for (int i=0; i<2; ++i) for (int i=0; i<2; ++i)
{ {
int attribute = class_.mData.mAttribute[i]; int attribute = class_->mData.mAttribute[i];
if (attribute>=0 && attribute<8) if (attribute>=0 && attribute<8)
{ {
creatureStats.getAttribute(attribute).setBase ( creatureStats.getAttribute(attribute).setBase (
@ -123,7 +127,7 @@ namespace MWMechanics
for (int i2=0; i2<5; ++i2) for (int i2=0; i2<5; ++i2)
{ {
int index = class_.mData.mSkills[i2][i]; int index = class_->mData.mSkills[i2][i];
if (index>=0 && index<27) if (index>=0 && index<27)
{ {
@ -134,12 +138,12 @@ namespace MWMechanics
} }
const MWWorld::Store<ESM::Skill> &skills = const MWWorld::Store<ESM::Skill> &skills =
MWBase::Environment::get().getWorld()->getStore().get<ESM::Skill>(); esmStore.get<ESM::Skill>();
MWWorld::Store<ESM::Skill>::iterator iter = skills.begin(); MWWorld::Store<ESM::Skill>::iterator iter = skills.begin();
for (; iter != skills.end(); ++iter) for (; iter != skills.end(); ++iter)
{ {
if (iter->mData.mSpecialization==class_.mData.mSpecialization) if (iter->mData.mSpecialization==class_->mData.mSpecialization)
{ {
int index = iter->mIndex; int index = iter->mIndex;
@ -266,12 +270,18 @@ namespace MWMechanics
MWBase::WindowManager *winMgr = MWBase::WindowManager *winMgr =
MWBase::Environment::get().getWindowManager(); MWBase::Environment::get().getWindowManager();
MWBase::World *world = MWBase::Environment::get().getWorld(); MWBase::World *world = MWBase::Environment::get().getWorld();
MWWorld::Player &player = world->getPlayer(); const ESM::NPC *player =
world->getPlayer().getPlayer().get<ESM::NPC>()->mBase;
winMgr->setValue ("name", player.getName()); const ESM::Race *race =
winMgr->setValue ("race", world->getStore().get<ESM::Race>().find (player.getRace())->mName); world->getStore().get<ESM::Race>().find(player->mRace);
winMgr->setValue ("class", player.getClass().mName); const ESM::Class *cls =
world->getStore().get<ESM::Class>().find(player->mClass);
winMgr->setValue ("name", player->mName);
winMgr->setValue ("race", race->mName);
winMgr->setValue ("class", cls->mName);
mUpdatePlayer = false; mUpdatePlayer = false;
@ -280,8 +290,8 @@ namespace MWMechanics
for (int i=0; i<5; ++i) for (int i=0; i<5; ++i)
{ {
minorSkills[i] = player.getClass().mData.mSkills[i][0]; minorSkills[i] = cls->mData.mSkills[i][0];
majorSkills[i] = player.getClass().mData.mSkills[i][1]; majorSkills[i] = cls->mData.mSkills[i][1];
} }
winMgr->configureSkills (majorSkills, minorSkills); winMgr->configureSkills (majorSkills, minorSkills);
@ -297,14 +307,33 @@ namespace MWMechanics
void MechanicsManager::setPlayerName (const std::string& name) void MechanicsManager::setPlayerName (const std::string& name)
{ {
MWBase::Environment::get().getWorld()->getPlayer().setName (name); MWBase::World *world = MWBase::Environment::get().getWorld();
ESM::NPC player =
*world->getPlayer().getPlayer().get<ESM::NPC>()->mBase;
player.mName = name;
world->createRecord(player);
mUpdatePlayer = true; mUpdatePlayer = true;
} }
void MechanicsManager::setPlayerRace (const std::string& race, bool male) void MechanicsManager::setPlayerRace (const std::string& race, bool male)
{ {
MWBase::Environment::get().getWorld()->getPlayer().setGender (male); MWBase::World *world = MWBase::Environment::get().getWorld();
MWBase::Environment::get().getWorld()->getPlayer().setRace (race);
ESM::NPC player =
*world->getPlayer().getPlayer().get<ESM::NPC>()->mBase;
player.mRace = race;
player.mFlags |= ESM::NPC::Female;
if (male) {
player.mFlags ^= ESM::NPC::Female;
}
world->createRecord(player);
mRaceSelected = true; mRaceSelected = true;
buildPlayer(); buildPlayer();
mUpdatePlayer = true; mUpdatePlayer = true;
@ -312,24 +341,38 @@ namespace MWMechanics
void MechanicsManager::setPlayerBirthsign (const std::string& id) void MechanicsManager::setPlayerBirthsign (const std::string& id)
{ {
MWBase::Environment::get().getWorld()->getPlayer().setBirthsign (id); MWBase::Environment::get().getWorld()->getPlayer().setBirthSign(id);
buildPlayer(); buildPlayer();
mUpdatePlayer = true; mUpdatePlayer = true;
} }
void MechanicsManager::setPlayerClass (const std::string& id) void MechanicsManager::setPlayerClass (const std::string& id)
{ {
MWBase::Environment::get().getWorld()->getPlayer().setClass ( MWBase::World *world = MWBase::Environment::get().getWorld();
*MWBase::Environment::get().getWorld()->getStore().get<ESM::Class>().find (id)
); ESM::NPC player =
*world->getPlayer().getPlayer().get<ESM::NPC>()->mBase;
player.mClass = id;
world->createRecord(player);
mClassSelected = true; mClassSelected = true;
buildPlayer(); buildPlayer();
mUpdatePlayer = true; mUpdatePlayer = true;
} }
void MechanicsManager::setPlayerClass (const ESM::Class& class_) void MechanicsManager::setPlayerClass (const ESM::Class &cls)
{ {
MWBase::Environment::get().getWorld()->getPlayer().setClass (class_); MWBase::World *world = MWBase::Environment::get().getWorld();
const ESM::Class *ptr = world->createRecord(cls);
ESM::NPC player =
*world->getPlayer().getPlayer().get<ESM::NPC>()->mBase;
player.mClass = ptr->mId;
world->createRecord(player);
mClassSelected = true; mClassSelected = true;
buildPlayer(); buildPlayer();
mUpdatePlayer = true; mUpdatePlayer = true;

@ -146,8 +146,13 @@ namespace MWWorld
} }
template <class T> template <class T>
T *insert(const T &x) { const T *insert(const T &x) {
Store<T> &store = const_cast<Store<T> &>(get<T>()); Store<T> &store = const_cast<Store<T> &>(get<T>());
if (store.search(x.mId) != 0) {
std::ostringstream msg;
msg << "Try to override existing record '" << x.mId << "'";
throw std::runtime_error(msg.str());
}
T record = x; T record = x;
std::ostringstream id; std::ostringstream id;
@ -168,10 +173,30 @@ namespace MWWorld
}; };
template <> template <>
inline ESM::Cell *ESMStore::insert<ESM::Cell>(const ESM::Cell &cell) { inline const ESM::Cell *ESMStore::insert<ESM::Cell>(const ESM::Cell &cell) {
return mCells.insert(cell); return mCells.insert(cell);
} }
template <>
inline const ESM::NPC *ESMStore::insert<ESM::NPC>(const ESM::NPC &npc) {
if (StringUtils::ciEqual(npc.mId, "player")) {
return mNpcs.insert(npc);
} else if (mNpcs.search(npc.mId) != 0) {
std::ostringstream msg;
msg << "Try to override existing record '" << npc.mId << "'";
throw std::runtime_error(msg.str());
}
ESM::NPC record = npc;
std::ostringstream id;
id << "$dynamic" << mDynamicCount++;
record.mId = id.str();
ESM::NPC *ptr = mNpcs.insert(record);
mIds[ptr->mId] = ESM::REC_NPC_;
return ptr;
}
template <> template <>
inline const Store<ESM::Activator> &ESMStore::get<ESM::Activator>() const { inline const Store<ESM::Activator> &ESMStore::get<ESM::Activator>() const {
return mActivators; return mActivators;

@ -13,33 +13,16 @@
namespace MWWorld namespace MWWorld
{ {
Player::Player (const ESM::NPC *player, const MWBase::World& world) : Player::Player (const ESM::NPC *player, const MWBase::World& world)
mCellStore (0), mClass (0), : mCellStore(0),
mAutoMove (false), mForwardBackward (0) mAutoMove(false),
mForwardBackward (0)
{ {
mPlayer.mBase = player; mPlayer.mBase = player;
mPlayer.mRef.mRefID = "player"; mPlayer.mRef.mRefID = "player";
mName = player->mName;
mMale = !(player->mFlags & ESM::NPC::Female);
mRace = player->mRace;
float* playerPos = mPlayer.mData.getPosition().pos; float* playerPos = mPlayer.mData.getPosition().pos;
playerPos[0] = playerPos[1] = playerPos[2] = 0; playerPos[0] = playerPos[1] = playerPos[2] = 0;
/// \todo Do not make a copy of classes defined in esm/p records.
mClass = new ESM::Class (*world.getStore().get<ESM::Class>().find (player->mClass));
}
Player::~Player()
{
delete mClass;
}
void Player::setClass (const ESM::Class& class_)
{
ESM::Class *new_class = new ESM::Class (class_);
delete mClass;
mClass = new_class;
} }
void Player::setDrawState (MWMechanics::DrawState_ state) void Player::setDrawState (MWMechanics::DrawState_ state)
@ -102,5 +85,4 @@ namespace MWWorld
MWWorld::Ptr ptr = getPlayer(); MWWorld::Ptr ptr = getPlayer();
return MWWorld::Class::get(ptr).getNpcStats(ptr).getDrawState(); return MWWorld::Class::get(ptr).getNpcStats(ptr).getDrawState();
} }
} }

@ -1,8 +1,6 @@
#ifndef GAME_MWWORLD_PLAYER_H #ifndef GAME_MWWORLD_PLAYER_H
#define GAME_MWWORLD_PLAYER_H #define GAME_MWWORLD_PLAYER_H
#include "OgreCamera.h"
#include "../mwworld/cellstore.hpp" #include "../mwworld/cellstore.hpp"
#include "../mwworld/refdata.hpp" #include "../mwworld/refdata.hpp"
#include "../mwworld/ptr.hpp" #include "../mwworld/ptr.hpp"
@ -21,21 +19,17 @@ namespace MWWorld
/// \brief NPC object representing the player and additional player data /// \brief NPC object representing the player and additional player data
class Player class Player
{ {
LiveCellRef<ESM::NPC> mPlayer; LiveCellRef<ESM::NPC> mPlayer;
MWWorld::CellStore *mCellStore; MWWorld::CellStore *mCellStore;
std::string mName; std::string mSign;
bool mMale;
std::string mRace; bool mAutoMove;
std::string mBirthsign; int mForwardBackward;
ESM::Class *mClass;
bool mAutoMove;
int mForwardBackward;
public: public:
Player(const ESM::NPC *player, const MWBase::World& world); Player(const ESM::NPC *player, const MWBase::World& world);
~Player();
void setCell (MWWorld::CellStore *cellStore) void setCell (MWWorld::CellStore *cellStore)
{ {
mCellStore = cellStore; mCellStore = cellStore;
@ -47,55 +41,16 @@ namespace MWWorld
return ptr; return ptr;
} }
void setName (const std::string& name) void setBirthSign(const std::string &sign) {
{ mSign = sign;
mName = name;
}
void setGender (bool male)
{
mMale = male;
} }
void setRace (const std::string& race) const std::string &getBirthSign() const {
{ return mSign;
mRace = race;
} }
void setBirthsign (const std::string& birthsign)
{
mBirthsign = birthsign;
}
void setClass (const ESM::Class& class_);
void setDrawState (MWMechanics::DrawState_ state); void setDrawState (MWMechanics::DrawState_ state);
std::string getName() const
{
return mName;
}
bool isMale() const
{
return mMale;
}
std::string getRace() const
{
return mRace;
}
std::string getBirthsign() const
{
return mBirthsign;
}
const ESM::Class& getClass() const
{
return *mClass;
}
bool getAutoMove() const bool getAutoMove() const
{ {
return mAutoMove; return mAutoMove;

@ -168,26 +168,6 @@ namespace MWWorld
} }
} }
T *search(const std::string &id) {
std::string key = StringUtils::lowerCase(id);
typename Dynamic::iterator dit = mDynamic.find(key);
if (dit != mDynamic.end()) {
return &dit->second;
}
return 0;
}
T *find(const std::string &id) {
T *ptr = search(id);
if (ptr == 0) {
std::ostringstream msg;
msg << "Object '" << id << "' not found (non-const)";
throw std::runtime_error(msg.str());
}
return ptr;
}
T *insert(const T &item) { T *insert(const T &item) {
std::string id = StringUtils::lowerCase(item.mId); std::string id = StringUtils::lowerCase(item.mId);
std::pair<typename Dynamic::iterator, bool> result = std::pair<typename Dynamic::iterator, bool> result =
@ -523,43 +503,6 @@ namespace MWWorld
} }
} }
ESM::Cell *search(const std::string &id) {
std::string key = StringUtils::lowerCase(id);
DynamicInt::iterator it = mDynamicInt.find(key);
if (it != mDynamicInt.end()) {
return &it->second;
}
return 0;
}
ESM::Cell *find(const std::string &id) {
ESM::Cell *ptr = search(id);
if (ptr == 0) {
std::ostringstream msg;
msg << "Interior '" << id << "' not found (non-const)";
throw std::runtime_error(msg.str());
}
return ptr;
}
ESM::Cell *search(int x, int y) {
DynamicExt::iterator it = mDynamicExt.find(std::make_pair(x, y));
if (it != mDynamicExt.end()) {
return &it->second;
}
return 0;
}
ESM::Cell *find(int x, int y) {
ESM::Cell *ptr = search(x, y);
if (ptr == 0) {
std::ostringstream msg;
msg << "Exterior at (" << x << ", " << y << ") not found (non-const";
throw std::runtime_error(msg.str());
}
return ptr;
}
ESM::Cell *insert(const ESM::Cell &cell) { ESM::Cell *insert(const ESM::Cell &cell) {
if (search(cell) != 0) { if (search(cell) != 0) {
std::ostringstream msg; std::ostringstream msg;

@ -779,22 +779,19 @@ namespace MWWorld
return mRendering->toggleRenderMode (mode); return mRendering->toggleRenderMode (mode);
} }
std::pair<std::string, const ESM::Potion *> World::createRecord (const ESM::Potion& record) const ESM::Potion *World::createRecord (const ESM::Potion& record)
{ {
const ESM::Potion *ptr = mStore.insert(record); return mStore.insert(record);
return std::make_pair(ptr->mId, ptr);
} }
std::pair<std::string, const ESM::Class *> World::createRecord (const ESM::Class& record) const ESM::Class *World::createRecord (const ESM::Class& record)
{ {
const ESM::Class *ptr = mStore.insert(record); return mStore.insert(record);
return std::make_pair(ptr->mId, ptr);
} }
std::pair<std::string, const ESM::Spell *> World::createRecord (const ESM::Spell& record) const ESM::Spell *World::createRecord (const ESM::Spell& record)
{ {
const ESM::Spell *ptr = mStore.insert(record); return mStore.insert(record);
return std::make_pair(ptr->mId, ptr);
} }
const ESM::Cell *World::createRecord (const ESM::Cell& record) const ESM::Cell *World::createRecord (const ESM::Cell& record)
@ -802,6 +799,11 @@ namespace MWWorld
return mStore.insert(record); return mStore.insert(record);
} }
const ESM::NPC *World::createRecord(const ESM::NPC &record)
{
return mStore.insert(record);
}
void World::playAnimationGroup (const MWWorld::Ptr& ptr, const std::string& groupName, int mode, void World::playAnimationGroup (const MWWorld::Ptr& ptr, const std::string& groupName, int mode,
int number) int number)
{ {

@ -250,21 +250,26 @@ namespace MWWorld
///< Toggle a render mode. ///< Toggle a render mode.
///< \return Resulting mode ///< \return Resulting mode
virtual std::pair<std::string, const ESM::Potion *> createRecord (const ESM::Potion& record); virtual const ESM::Potion *createRecord (const ESM::Potion& record);
///< Create a new recrod (of type potion) in the ESM store. ///< Create a new recrod (of type potion) in the ESM store.
/// \return ID, pointer to created record /// \return pointer to created record
virtual std::pair<std::string, const ESM::Spell *> createRecord (const ESM::Spell& record); virtual const ESM::Spell *createRecord (const ESM::Spell& record);
///< Create a new recrod (of type spell) in the ESM store. ///< Create a new recrod (of type spell) in the ESM store.
/// \return ID, pointer to created record /// \return pointer to created record
virtual std::pair<std::string, const ESM::Class *> createRecord (const ESM::Class& record); virtual const ESM::Class *createRecord (const ESM::Class& record);
///< Create a new recrod (of type class) in the ESM store. ///< Create a new recrod (of type class) in the ESM store.
/// \return ID, pointer to created record /// \return pointer to created record
virtual const ESM::Cell *createRecord (const ESM::Cell& record); virtual const ESM::Cell *createRecord (const ESM::Cell& record);
///< Create a new recrod (of type cell) in the ESM store. ///< Create a new recrod (of type cell) in the ESM store.
/// \return ID, pointer to created record /// \return pointer to created record
virtual const ESM::NPC *createRecord(const ESM::NPC &record);
///< Create a new recrod (of type npc) in the ESM store.
/// \return pointer to created record
virtual void playAnimationGroup (const MWWorld::Ptr& ptr, const std::string& groupName, virtual void playAnimationGroup (const MWWorld::Ptr& ptr, const std::string& groupName,
int mode, int number = 1); int mode, int number = 1);

Loading…
Cancel
Save