1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-20 14:23:53 +00:00

Add initial player inventory when new game is started

This commit is contained in:
scrawl 2013-04-15 02:56:23 +02:00
parent 9bc07e6221
commit 2693b78536
15 changed files with 62 additions and 46 deletions

View file

@ -368,6 +368,7 @@ void OMW::Engine::prepareEngine (Settings::Manager & settings)
mEnvironment.setWorld( new MWWorld::World (*mOgre, mFileCollections, mMaster, mPlugins,
mResDir, mCfgMgr.getCachePath(), mNewGame, mEncoder, mFallbackMap,
mActivationDistanceOverride));
MWBase::Environment::get().getWorld()->setupPlayer(mNewGame);
//Load translation data
mTranslationDataStorage.setEncoder(mEncoder);

View file

@ -321,6 +321,7 @@ namespace MWBase
virtual void changeVanityModeScale(float factor) = 0;
virtual bool vanityRotateCamera(float * rot) = 0;
virtual void setupPlayer(bool newGame) = 0;
virtual void renderPlayer() = 0;
virtual void setupExternalRendering (MWRender::ExternalRendering& rendering) = 0;

View file

@ -292,7 +292,7 @@ namespace MWClass
ref->mBase = record;
}
int Armor::canBeEquipped(const MWWorld::Ptr &ptr, const MWWorld::Ptr &npc) const
std::pair<int, std::string> Armor::canBeEquipped(const MWWorld::Ptr &ptr, const MWWorld::Ptr &npc) const
{
MWWorld::InventoryStore& invStore = MWWorld::Class::get(npc).getInventoryStore(npc);
@ -317,10 +317,7 @@ namespace MWClass
{
if((*itr).mPart == ESM::PRT_Head)
{
if(npc == MWBase::Environment::get().getWorld()->getPlayer().getPlayer() )
MWBase::Environment::get().getWindowManager()->messageBox ("#{sNotifyMessage13}");
return 0;
return std::make_pair(0, "#{sNotifyMessage13}");
}
}
}
@ -331,9 +328,7 @@ namespace MWClass
{
if((*itr).mPart == ESM::PRT_LFoot || (*itr).mPart == ESM::PRT_RFoot)
{
if(npc == MWBase::Environment::get().getWorld()->getPlayer().getPlayer() )
MWBase::Environment::get().getWindowManager()->messageBox ("#{sNotifyMessage14}");
return 0;
return std::make_pair(0, "#{sNotifyMessage14}");
}
}
}
@ -344,7 +339,7 @@ namespace MWClass
MWWorld::ContainerStoreIterator weapon = invStore.getSlot(MWWorld::InventoryStore::Slot_CarriedRight);
if(weapon == invStore.end())
return 1;
return std::make_pair(1,"");
if(weapon->get<ESM::Weapon>()->mBase->mData.mType == ESM::Weapon::LongBladeTwoHand ||
weapon->get<ESM::Weapon>()->mBase->mData.mType == ESM::Weapon::BluntTwoClose ||
@ -354,12 +349,12 @@ namespace MWClass
weapon->get<ESM::Weapon>()->mBase->mData.mType == ESM::Weapon::MarksmanBow ||
weapon->get<ESM::Weapon>()->mBase->mData.mType == ESM::Weapon::MarksmanCrossbow)
{
return 3;
return std::make_pair(3,"");
}
return 1;
return std::make_pair(1,"");
}
}
return 1;
return std::make_pair(1,"");
}
boost::shared_ptr<MWWorld::Action> Armor::use (const MWWorld::Ptr& ptr) const

View file

@ -67,8 +67,9 @@ namespace MWClass
virtual void applyEnchantment(const MWWorld::Ptr &ptr, const std::string& enchId, int enchCharge, const std::string& newName) const;
virtual int canBeEquipped(const MWWorld::Ptr &ptr, const MWWorld::Ptr &npc) const;
///< Return 0 if player cannot equip item. 1 if can equip. 2 if it's twohanded weapon. 3 if twohanded weapon conflicts with that.
virtual std::pair<int, std::string> canBeEquipped(const MWWorld::Ptr &ptr, const MWWorld::Ptr &npc) const;
///< Return 0 if player cannot equip item. 1 if can equip. 2 if it's twohanded weapon. 3 if twohanded weapon conflicts with that. \n
/// Second item in the pair specifies the error message
virtual boost::shared_ptr<MWWorld::Action> use (const MWWorld::Ptr& ptr)
const;

View file

@ -238,7 +238,7 @@ namespace MWClass
ref->mBase = record;
}
int Clothing::canBeEquipped(const MWWorld::Ptr &ptr, const MWWorld::Ptr &npc) const
std::pair<int, std::string> Clothing::canBeEquipped(const MWWorld::Ptr &ptr, const MWWorld::Ptr &npc) const
{
// slots that this item can be equipped in
std::pair<std::vector<int>, bool> slots = MWWorld::Class::get(ptr).getEquipmentSlots(ptr);
@ -260,12 +260,7 @@ namespace MWClass
for(std::vector<ESM::PartReference>::iterator itr = parts.begin(); itr != parts.end(); ++itr)
{
if((*itr).mPart == ESM::PRT_Head)
{
if(npc == MWBase::Environment::get().getWorld()->getPlayer().getPlayer() )
MWBase::Environment::get().getWindowManager()->messageBox ("#{sNotifyMessage13}");
return 0;
}
return std::make_pair(0, "#{sNotifyMessage13}");
}
}
@ -274,19 +269,12 @@ namespace MWClass
for(std::vector<ESM::PartReference>::iterator itr = parts.begin(); itr != parts.end(); ++itr)
{
if((*itr).mPart == ESM::PRT_LFoot || (*itr).mPart == ESM::PRT_RFoot)
{
if(npc == MWBase::Environment::get().getWorld()->getPlayer().getPlayer() )
{
MWBase::Environment::get().getWindowManager()->messageBox ("#{sNotifyMessage15}");
}
return 0;
}
return std::make_pair(0, "#{sNotifyMessage15}");
}
}
}
}
return 1;
return std::make_pair (1, "");
}
boost::shared_ptr<MWWorld::Action> Clothing::use (const MWWorld::Ptr& ptr) const

View file

@ -61,8 +61,9 @@ namespace MWClass
virtual void applyEnchantment(const MWWorld::Ptr &ptr, const std::string& enchId, int enchCharge, const std::string& newName) const;
virtual int canBeEquipped(const MWWorld::Ptr &ptr, const MWWorld::Ptr &npc) const;
virtual std::pair<int, std::string> canBeEquipped(const MWWorld::Ptr &ptr, const MWWorld::Ptr &npc) const;
///< Return 0 if player cannot equip item. 1 if can equip. 2 if it's twohanded weapon. 3 if twohanded weapon conflicts with that.
/// Second item in the pair specifies the error message
virtual boost::shared_ptr<MWWorld::Action> use (const MWWorld::Ptr& ptr)
const;

View file

@ -384,7 +384,7 @@ namespace MWClass
ref->mBase = record;
}
int Weapon::canBeEquipped(const MWWorld::Ptr &ptr, const MWWorld::Ptr &npc) const
std::pair<int, std::string> Weapon::canBeEquipped(const MWWorld::Ptr &ptr, const MWWorld::Ptr &npc) const
{
std::pair<std::vector<int>, bool> slots = MWWorld::Class::get(ptr).getEquipmentSlots(ptr);
@ -402,12 +402,12 @@ namespace MWClass
ptr.get<ESM::Weapon>()->mBase->mData.mType == ESM::Weapon::MarksmanBow ||
ptr.get<ESM::Weapon>()->mBase->mData.mType == ESM::Weapon::MarksmanCrossbow)
{
return 2;
return std::make_pair (2, "");
}
return 1;
return std::make_pair (1, "");
}
}
return 0;
return std::make_pair (0, "");
}
boost::shared_ptr<MWWorld::Action> Weapon::use (const MWWorld::Ptr& ptr) const

View file

@ -67,8 +67,9 @@ namespace MWClass
virtual void applyEnchantment(const MWWorld::Ptr &ptr, const std::string& enchId, int enchCharge, const std::string& newName) const;
virtual int canBeEquipped(const MWWorld::Ptr &ptr, const MWWorld::Ptr &npc) const;
virtual std::pair<int, std::string> canBeEquipped(const MWWorld::Ptr &ptr, const MWWorld::Ptr &npc) const;
///< Return 0 if player cannot equip item. 1 if can equip. 2 if it's twohanded weapon. 3 if twohanded weapon conflicts with that.
/// Second item in the pair specifies the error message
virtual boost::shared_ptr<MWWorld::Action> use (const MWWorld::Ptr& ptr)
const;

View file

@ -155,6 +155,18 @@ namespace MWMechanics
stat.setCurrent (stat.getModified());
creatureStats.setDynamic (i, stat);
}
// unequip any items that may not be equipped. we need this for when the race is changed to a beast race
MWWorld::InventoryStore& invStore = MWWorld::Class::get(ptr).getInventoryStore(ptr);
for (int i=0; i<MWWorld::InventoryStore::Slots; ++i)
{
MWWorld::ContainerStoreIterator it = invStore.getSlot(i);
if (it != invStore.end())
{
if (!MWWorld::Class::get(*it).canBeEquipped(*it, ptr).first)
invStore.equip(i, invStore.end());
}
}
}
MechanicsManager::MechanicsManager()

View file

@ -21,7 +21,13 @@ namespace MWWorld
MWWorld::Ptr object = getTarget();
MWWorld::InventoryStore& invStore = MWWorld::Class::get(actor).getInventoryStore(actor);
switch(MWWorld::Class::get (object).canBeEquipped (object, actor))
std::pair <int, std::string> result = MWWorld::Class::get (object).canBeEquipped (object, actor);
// display error message if the player tried to equip something
if (!result.second.empty() && actor == MWBase::Environment::get().getWorld()->getPlayer().getPlayer())
MWBase::Environment::get().getWindowManager()->messageBox(result.second);
switch(result.first)
{
case 0:
return;
@ -48,8 +54,6 @@ namespace MWWorld
assert(it != invStore.end());
std::string npcRace = actor.get<ESM::NPC>()->mBase->mRace;
bool equipped = false;
// equip the item in the first free slot

View file

@ -264,9 +264,9 @@ namespace MWWorld
throw std::runtime_error ("class can't be enchanted");
}
int Class::canBeEquipped(const MWWorld::Ptr &ptr, const MWWorld::Ptr &npc) const
std::pair<int, std::string> Class::canBeEquipped(const MWWorld::Ptr &ptr, const MWWorld::Ptr &npc) const
{
return 1;
return std::make_pair (1, "");
}
void Class::adjustPosition(const MWWorld::Ptr& ptr) const

View file

@ -245,8 +245,9 @@ namespace MWWorld
virtual void applyEnchantment(const MWWorld::Ptr &ptr, const std::string& enchId, int enchCharge, const std::string& newName) const;
virtual int canBeEquipped(const MWWorld::Ptr &ptr, const MWWorld::Ptr &npc) const;
virtual std::pair<int, std::string> canBeEquipped(const MWWorld::Ptr &ptr, const MWWorld::Ptr &npc) const;
///< Return 0 if player cannot equip item. 1 if can equip. 2 if it's twohanded weapon. 3 if twohanded weapon conflicts with that.
/// Second item in the pair specifies the error message
virtual Ptr
copyToCell(const Ptr &ptr, CellStore &cell) const;

View file

@ -186,7 +186,7 @@ void MWWorld::InventoryStore::autoEquip (const MWWorld::Ptr& npc)
}
}
switch(MWWorld::Class::get (test).canBeEquipped (test, npc))
switch(MWWorld::Class::get (test).canBeEquipped (test, npc).first)
{
case 0:
continue;

View file

@ -24,6 +24,7 @@
#include "manualref.hpp"
#include "cellfunctors.hpp"
#include "containerstore.hpp"
#include "inventorystore.hpp"
using namespace Ogre;
@ -210,9 +211,6 @@ namespace MWWorld
mStore.setUp();
mPlayer = new MWWorld::Player (mStore.get<ESM::NPC>().find ("player"), *this);
mRendering->attachCameraTo(mPlayer->getPlayer());
// global variables
mGlobalVariables = new Globals (mStore);
@ -1369,6 +1367,18 @@ namespace MWWorld
return mRendering->vanityRotateCamera(rot);
}
void World::setupPlayer(bool newGame)
{
const ESM::NPC* player = mStore.get<ESM::NPC>().find ("player");
mPlayer = new MWWorld::Player (player, *this);
mRendering->attachCameraTo(mPlayer->getPlayer());
if (newGame)
{
MWWorld::Class::get(mPlayer->getPlayer()).getContainerStore(mPlayer->getPlayer()).fill(player->mInventory, "", mStore);
MWWorld::Class::get(mPlayer->getPlayer()).getInventoryStore(mPlayer->getPlayer()).autoEquip (mPlayer->getPlayer());
}
}
void World::renderPlayer()
{
mRendering->renderPlayer(mPlayer->getPlayer());

View file

@ -363,6 +363,7 @@ namespace MWWorld
virtual bool vanityRotateCamera(float * rot);
virtual void setupPlayer(bool newGame);
virtual void renderPlayer();
virtual void setupExternalRendering (MWRender::ExternalRendering& rendering);