Merge remote-tracking branch 'PotatoesMaster/werewolf' into werewolf

Conflicts:
	apps/openmw/mwmechanics/actors.cpp
	apps/openmw/mwscript/statsextensions.cpp
pull/51/head
Chris Robinson 12 years ago
commit 2bac4566c0

@ -105,6 +105,9 @@ namespace MWBase
virtual void toggleVisible (MWGui::GuiWindow wnd) = 0;
virtual void forceHide(MWGui::GuiWindow wnd) = 0;
virtual void unsetForceHide(MWGui::GuiWindow wnd) = 0;
/// Disallow all inventory mode windows
virtual void disallowAll() = 0;

@ -386,6 +386,9 @@ namespace MWBase
/// Returns true if teleport spell effects are allowed.
virtual bool isTeleportingEnabled() const = 0;
/// Turn actor into werewolf or normal form.
virtual void setWerewolf(const MWWorld::Ptr& actor, bool werewolf) = 0;
};
}

@ -76,7 +76,7 @@ void ContainerItemModel::copyItem (const ItemStack& item, size_t count)
const MWWorld::Ptr& source = mItemSources[mItemSources.size()-1];
int origCount = item.mBase.getRefData().getCount();
item.mBase.getRefData().setCount(count);
MWWorld::ContainerStoreIterator it = MWWorld::Class::get(source).getContainerStore(source).add(item.mBase);
MWWorld::ContainerStoreIterator it = MWWorld::Class::get(source).getContainerStore(source).add(item.mBase, source);
if (*it != item.mBase)
item.mBase.getRefData().setCount(origCount);
else

@ -10,6 +10,7 @@
#include "../mwworld/class.hpp"
#include "../mwmechanics/creaturestats.hpp"
#include "../mwmechanics/npcstats.hpp"
#include "inventorywindow.hpp"
#include "console.hpp"
@ -494,7 +495,14 @@ namespace MWGui
MyGUI::Gui::getInstance().destroyWidget(mWeapImage->getChildAt(0));
mWeapStatus->setProgressRange(100);
mWeapStatus->setProgressPosition(0);
mWeapImage->setImageTexture("icons\\k\\stealth_handtohand.dds");
MWBase::World *world = MWBase::Environment::get().getWorld();
MWWorld::Ptr player = world->getPlayer().getPlayer();
if (MWWorld::Class::get(player).getNpcStats(player).isWerewolf())
mWeapImage->setImageTexture("icons\\k\\tx_werewolf_hand.dds");
else
mWeapImage->setImageTexture("icons\\k\\stealth_handtohand.dds");
mWeapBox->clearUserStrings();
}

@ -42,7 +42,7 @@ void InventoryItemModel::copyItem (const ItemStack& item, size_t count)
{
int origCount = item.mBase.getRefData().getCount();
item.mBase.getRefData().setCount(count);
MWWorld::ContainerStoreIterator it = MWWorld::Class::get(mActor).getContainerStore(mActor).add(item.mBase);
MWWorld::ContainerStoreIterator it = MWWorld::Class::get(mActor).getContainerStore(mActor).add(item.mBase, mActor);
if (*it != item.mBase)
item.mBase.getRefData().setCount(origCount);
else

@ -304,7 +304,7 @@ namespace MWGui
int origCount = ptr.getRefData().getCount();
ptr.getRefData().setCount(mDragAndDrop->mDraggedCount);
it = invStore.add(ptr);
it = invStore.add(ptr, mPtr);
ptr.getRefData().setCount(origCount);
mDragAndDrop->mSourceModel->removeItem(mDragAndDrop->mItem, mDragAndDrop->mDraggedCount);
@ -481,7 +481,7 @@ namespace MWGui
// add to player inventory
// can't use ActionTake here because we need an MWWorld::Ptr to the newly inserted object
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer();
MWWorld::Ptr newObject = *MWWorld::Class::get (player).getContainerStore (player).add (object);
MWWorld::Ptr newObject = *MWWorld::Class::get (player).getContainerStore (player).add (object, player);
// remove from world
MWBase::Environment::get().getWorld()->deleteObject (object);

@ -225,7 +225,7 @@ namespace MWGui
assert(amount > 0);
MWWorld::ManualRef ref(MWBase::Environment::get().getWorld()->getStore(), "Gold_001");
ref.getPtr().getRefData().setCount(amount);
playerStore.add(ref.getPtr());
playerStore.add(ref.getPtr(), player);
}
}

@ -105,6 +105,7 @@ namespace MWGui
, mGui(NULL)
, mGarbageDialogs()
, mShown(GW_ALL)
, mForceHidden(GW_None)
, mAllowed(GW_ALL)
, mRestAllowed(true)
, mShowFPSLevel(fpsLevel)
@ -435,7 +436,7 @@ namespace MWGui
// This is controlled both by what windows the
// user has opened/closed (the 'shown' variable) and by what
// windows we are allowed to show (the 'allowed' var.)
int eff = mShown & mAllowed;
int eff = mShown & mAllowed & ~mForceHidden;
// Show the windows we want
mMap ->setVisible(eff & GW_Map);
@ -1127,7 +1128,19 @@ namespace MWGui
void WindowManager::toggleVisible (GuiWindow wnd)
{
mShown = (mShown & wnd) ? (GuiWindow) (mShown & ~wnd) : (GuiWindow) (mShown | wnd);
mShown = (GuiWindow)(mShown ^ wnd);
updateVisible();
}
void WindowManager::forceHide(GuiWindow wnd)
{
mForceHidden = (GuiWindow)(mForceHidden | wnd);
updateVisible();
}
void WindowManager::unsetForceHide(GuiWindow wnd)
{
mForceHidden = (GuiWindow)(mForceHidden & ~wnd);
updateVisible();
}

@ -115,6 +115,9 @@ namespace MWGui
virtual void toggleVisible(GuiWindow wnd);
virtual void forceHide(MWGui::GuiWindow wnd);
virtual void unsetForceHide(MWGui::GuiWindow wnd);
// Disallow all inventory mode windows
virtual void disallowAll();
@ -341,6 +344,7 @@ namespace MWGui
void cleanupGarbage();
GuiWindow mShown; // Currently shown windows in inventory mode
GuiWindow mForceHidden; // Hidden windows (overrides mShown)
/* Currently ALLOWED windows in inventory mode. This is used at
the start of the game, when windows are enabled one by one

@ -39,10 +39,8 @@ namespace MWMechanics
void Actors::updateNpc (const MWWorld::Ptr& ptr, float duration, bool paused)
{
if (!paused && ptr.getRefData().getHandle()!="player")
MWWorld::Class::get (ptr).getInventoryStore (ptr).autoEquip (ptr);
if(!paused)
updateDrowning(ptr,duration);
updateDrowning(ptr, duration);
}
void Actors::adjustMagicEffects (const MWWorld::Ptr& creature)

@ -34,7 +34,7 @@ namespace MWMechanics
float mDuration;
void updateNpc (const MWWorld::Ptr& ptr, float duration, bool paused);
void updateNpc(const MWWorld::Ptr &ptr, float duration, bool paused);
void adjustMagicEffects (const MWWorld::Ptr& creature);

@ -287,7 +287,7 @@ void MWMechanics::Alchemy::addPotion (const std::string& name)
}
MWWorld::ManualRef ref (MWBase::Environment::get().getWorld()->getStore(), record->mId);
MWWorld::Class::get (mAlchemist).getContainerStore (mAlchemist).add (ref.getPtr());
MWWorld::Class::get (mAlchemist).getContainerStore (mAlchemist).add (ref.getPtr(), mAlchemist);
}
void MWMechanics::Alchemy::increaseSkill()

@ -65,7 +65,7 @@ namespace MWMechanics
if(boost::iequals(mSoulGemPtr.get<ESM::Miscellaneous>()->mBase->mId, "Misc_SoulGem_Azura"))
{
MWWorld::ManualRef azura (MWBase::Environment::get().getWorld()->getStore(), "Misc_SoulGem_Azura");
MWWorld::Class::get (player).getContainerStore (player).add (azura.getPtr());
MWWorld::Class::get (player).getContainerStore (player).add (azura.getPtr(), player);
}
if(mSelfEnchanting)
@ -93,7 +93,7 @@ namespace MWMechanics
MWWorld::ManualRef ref (MWBase::Environment::get().getWorld()->getStore(), mOldItemId);
ref.getPtr().getRefData().setCount (mOldItemCount-1);
MWWorld::Class::get (player).getContainerStore (player).add (ref.getPtr());
MWWorld::Class::get (player).getContainerStore (player).add (ref.getPtr(), player);
if(!mSelfEnchanting)
payForEnchantment();

@ -13,7 +13,9 @@
#include <components/esm/loadgmst.hpp>
#include <components/esm/loadfact.hpp>
#include "../mwworld/class.hpp"
#include "../mwworld/esmstore.hpp"
#include "../mwworld/player.hpp"
#include "../mwbase/environment.hpp"
#include "../mwbase/world.hpp"

@ -32,7 +32,7 @@ void Repair::repair(const MWWorld::Ptr &itemToRepair)
if (mTool.getRefData().getCount() > 1 && uses == ref->mBase->mData.mUses)
{
MWWorld::ContainerStore& store = MWWorld::Class::get(player).getContainerStore(player);
MWWorld::ContainerStoreIterator it = store.add(mTool);
MWWorld::ContainerStoreIterator it = store.add(mTool, player);
it->getRefData().setCount(mTool.getRefData().getCount()-1);
it->getCellRef().mCharge = -1;

@ -65,7 +65,7 @@ namespace MWScript
ref.getPtr().getRefData().setLocals(*esmscript);
}
MWWorld::Class::get (ptr).getContainerStore (ptr).add (ref.getPtr());
MWWorld::Class::get (ptr).getContainerStore (ptr).add (ref.getPtr(), ptr);
// Spawn a messagebox (only for items added to player's inventory and if player is talking to someone)
if (ptr == MWBase::Environment::get().getWorld ()->getPlayer ().getPlayer() )

@ -343,5 +343,9 @@ op 0x2000213: HitOnMe
op 0x2000214: HitOnMe, explicit
op 0x2000215: DisableTeleporting
op 0x2000216: EnableTeleporting
op 0x2000217: BecomeWerewolf
op 0x2000218: BecomeWerewolfExplicit
op 0x2000219: UndoWerewolf
op 0x200021a: UndoWerewolfExplicit
opcodes 0x2000217-0x3ffffff unused
opcodes 0x200021b-0x3ffffff unused

@ -347,7 +347,7 @@ namespace MWScript
ref.getPtr().getCellRef().mSoul = creature;
MWWorld::Class::get (ptr).getContainerStore (ptr).add (ref.getPtr());
MWWorld::Class::get (ptr).getContainerStore (ptr).add (ref.getPtr(), ptr);
}
};

@ -1057,6 +1057,18 @@ namespace MWScript
}
};
template <class R, bool set>
class OpSetWerewolf : public Interpreter::Opcode0
{
public:
virtual void execute (Interpreter::Runtime& runtime)
{
MWWorld::Ptr ptr = R()(runtime);
MWBase::Environment::get().getWorld()->setWerewolf(ptr, set);
}
};
void installOpcodes (Interpreter::Interpreter& interpreter)
{
@ -1121,6 +1133,7 @@ namespace MWScript
interpreter.installSegment5 (Compiler::Stats::opcodeRemoveSpell, new OpRemoveSpell<ImplicitRef>);
interpreter.installSegment5 (Compiler::Stats::opcodeRemoveSpellExplicit,
new OpRemoveSpell<ExplicitRef>);
interpreter.installSegment5 (Compiler::Stats::opcodeGetSpell, new OpGetSpell<ImplicitRef>);
interpreter.installSegment5 (Compiler::Stats::opcodeGetSpellExplicit, new OpGetSpell<ExplicitRef>);
@ -1176,6 +1189,11 @@ namespace MWScript
interpreter.installSegment5 (Compiler::Stats::opcodeIsWerewolf, new OpIsWerewolf<ImplicitRef>);
interpreter.installSegment5 (Compiler::Stats::opcodeIsWerewolfExplicit, new OpIsWerewolf<ExplicitRef>);
interpreter.installSegment5 (Compiler::Stats::opcodeBecomeWerewolf, new OpSetWerewolf<ImplicitRef, true>);
interpreter.installSegment5 (Compiler::Stats::opcodeBecomeWerewolfExplicit, new OpSetWerewolf<ExplicitRef, true>);
interpreter.installSegment5 (Compiler::Stats::opcodeUndoWerewolf, new OpSetWerewolf<ImplicitRef, false>);
interpreter.installSegment5 (Compiler::Stats::opcodeUndoWerewolfExplicit, new OpSetWerewolf<ExplicitRef, false>);
}
}
}

@ -17,7 +17,7 @@ namespace MWWorld
// insert into player's inventory
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPtr ("player", true);
MWWorld::Class::get (player).getContainerStore (player).add (getTarget());
MWWorld::Class::get (player).getContainerStore (player).add (getTarget(), player);
MWBase::Environment::get().getWorld()->deleteObject (getTarget());
}

@ -74,9 +74,9 @@ bool MWWorld::ContainerStore::stacks(const Ptr& ptr1, const Ptr& ptr2)
return false;
}
MWWorld::ContainerStoreIterator MWWorld::ContainerStore::add (const Ptr& ptr)
MWWorld::ContainerStoreIterator MWWorld::ContainerStore::add (const Ptr& itemPtr, const Ptr& actorPtr)
{
MWWorld::ContainerStoreIterator it = addImp(ptr);
MWWorld::ContainerStoreIterator it = addImp(itemPtr);
MWWorld::Ptr item = *it;
std::string script = MWWorld::Class::get(item).getScript(item);

@ -65,7 +65,7 @@ namespace MWWorld
ContainerStoreIterator end();
ContainerStoreIterator add (const Ptr& ptr);
virtual ContainerStoreIterator add (const Ptr& itemPtr, const Ptr& actorPtr);
///< Add the item pointed to by \a ptr to this container. (Stacks automatically if needed)
///
/// \note The item pointed to is not required to exist beyond this function call.

@ -64,6 +64,22 @@ MWWorld::InventoryStore& MWWorld::InventoryStore::operator= (const InventoryStor
return *this;
}
MWWorld::ContainerStoreIterator MWWorld::InventoryStore::add(const Ptr& itemPtr, const Ptr& actorPtr)
{
const MWWorld::ContainerStoreIterator& retVal = MWWorld::ContainerStore::add(itemPtr, actorPtr);
// Auto-equip items if an armor/clothing item is added, but not for the player nor werewolves
if ((actorPtr.getRefData().getHandle() != "player")
&& !(MWWorld::Class::get(actorPtr).getNpcStats(actorPtr).isWerewolf()))
{
std::string type = itemPtr.getTypeName();
if ((type == typeid(ESM::Armor).name()) || (type == typeid(ESM::Clothing).name()))
autoEquip(actorPtr);
}
return retVal;
}
void MWWorld::InventoryStore::equip (int slot, const ContainerStoreIterator& iterator)
{
if (slot<0 || slot>=static_cast<int> (mSlots.size()))
@ -110,6 +126,23 @@ void MWWorld::InventoryStore::equip (int slot, const ContainerStoreIterator& ite
flagAsModified();
}
void MWWorld::InventoryStore::unequipAll(const MWWorld::Ptr& actor)
{
for (int slot=0; slot < MWWorld::InventoryStore::Slots; ++slot)
{
MWWorld::ContainerStoreIterator it = getSlot(slot);
if (it != end())
{
equip(slot, end());
std::string script = MWWorld::Class::get(*it).getScript(*it);
// Unset OnPCEquip Variable on item's script, if it has a script with that variable declared
if((actor.getRefData().getHandle() == "player") && (script != ""))
(*it).mRefData->getLocals().setVarByInt(script, "onpcequip", 0);
}
}
}
MWWorld::ContainerStoreIterator MWWorld::InventoryStore::getSlot (int slot)
{
if (slot<0 || slot>=static_cast<int> (mSlots.size()))

@ -65,6 +65,17 @@ namespace MWWorld
InventoryStore& operator= (const InventoryStore& store);
virtual ContainerStoreIterator add (const Ptr& itemPtr, const Ptr& actorPtr);
///< Add the item pointed to by \a ptr to this container. (Stacks automatically if needed)
/// Auto-equip items if specific conditions are fulfilled (see the implementation).
///
/// \note The item pointed to is not required to exist beyond this function call.
///
/// \attention Do not add items to an existing stack by increasing the count instead of
/// calling this function!
///
/// @return if stacking happened, return iterator to the item that was stacked against, otherwise iterator to the newly inserted item.
void equip (int slot, const ContainerStoreIterator& iterator);
///< \note \a iterator can be an end-iterator
@ -78,6 +89,9 @@ namespace MWWorld
ContainerStoreIterator getSlot (int slot);
void unequipAll(const MWWorld::Ptr& actor);
///< Unequip all currently equipped items.
void autoEquip (const MWWorld::Ptr& npc);
///< Auto equip items according to stats and item value.

@ -16,6 +16,7 @@
#include "../mwmechanics/creaturestats.hpp"
#include "../mwmechanics/movement.hpp"
#include "../mwmechanics/npcstats.hpp"
#include "../mwrender/sky.hpp"
#include "../mwrender/animation.hpp"
@ -1859,4 +1860,36 @@ namespace MWWorld
return mTeleportEnabled;
}
void World::setWerewolf(const MWWorld::Ptr& actor, bool werewolf)
{
MWMechanics::NpcStats& npcStats = Class::get(actor).getNpcStats(actor);
// The actor does not have to change state
if (npcStats.isWerewolf() == werewolf)
return;
npcStats.setWerewolf(werewolf);
MWWorld::InventoryStore& invStore = MWWorld::Class::get(actor).getInventoryStore(actor);
if (werewolf)
invStore.unequipAll(actor);
if (actor.getRefData().getHandle() == "player")
{
// Update the GUI only when called on the player
MWBase::WindowManager* windowManager = MWBase::Environment::get().getWindowManager();
if (werewolf)
{
windowManager->forceHide(MWGui::GW_Inventory);
windowManager->forceHide(MWGui::GW_Magic);
windowManager->unsetSelectedWeapon();
}
else
{
windowManager->unsetForceHide(MWGui::GW_Inventory);
windowManager->unsetForceHide(MWGui::GW_Magic);
}
}
}
}

@ -430,6 +430,8 @@ namespace MWWorld
/// Returns true if teleport spell effects are allowed.
virtual bool isTeleportingEnabled() const;
virtual void setWerewolf(const MWWorld::Ptr& actor, bool werewolf);
};
}

@ -418,6 +418,9 @@ namespace Compiler
extensions.registerFunction ("ondeath", 'l', "", opcodeOnDeath, opcodeOnDeathExplicit);
extensions.registerFunction ("iswerewolf", 'l', "", opcodeIsWerewolf, opcodeIsWerewolfExplicit);
extensions.registerInstruction("becomewerewolf", "", opcodeBecomeWerewolf, opcodeBecomeWerewolfExplicit);
extensions.registerInstruction("undowerewolf", "", opcodeUndoWerewolf, opcodeUndoWerewolfExplicit);
}
}
@ -458,4 +461,4 @@ namespace Compiler
extensions.registerInstruction ("user4", "", opcodeUser4, opcodeUser4);
}
}
}
}

@ -333,8 +333,6 @@ namespace Compiler
const int opcodeGetRace = 0x20001d9;
const int opcodeGetRaceExplicit = 0x20001da;
const int opcodeGetWerewolfKills = 0x20001e2;
const int opcodePcExpelled = 0x20018;
const int opcodePcExpelledExplicit = 0x20019;
const int opcodePcExpell = 0x2001a;
@ -347,8 +345,15 @@ namespace Compiler
const int opcodeLowerRankExplicit = 0x20001eb;
const int opcodeOnDeath = 0x20001fc;
const int opcodeOnDeathExplicit = 0x2000205;
const int opcodeBecomeWerewolf = 0x2000217;
const int opcodeBecomeWerewolfExplicit = 0x2000218;
const int opcodeUndoWerewolf = 0x2000219;
const int opcodeUndoWerewolfExplicit = 0x200021a;
const int opcodeIsWerewolf = 0x20001fd;
const int opcodeIsWerewolfExplicit = 0x20001fe;
const int opcodeGetWerewolfKills = 0x20001e2;
}
namespace Transformation
@ -404,4 +409,4 @@ namespace Compiler
}
}
#endif
#endif

Loading…
Cancel
Save