Cleanups and fixes

pull/1/head
Allofich 9 years ago
parent 199607423b
commit c02695e56d

@ -17,7 +17,7 @@ MWWorld::Action::Action (bool keepSound, const Ptr& target) : mKeepSound (keepSo
MWWorld::Action::~Action() {}
void MWWorld::Action::execute (const Ptr& actor)
void MWWorld::Action::execute (const Ptr& actor, float distanceToObject, bool useDistance)
{
if(!mSoundId.empty())
{
@ -41,36 +41,10 @@ void MWWorld::Action::execute (const Ptr& actor)
);
}
}
executeImp(actor);
}
void MWWorld::Action::execute (const Ptr& actor, float distanceToObject)
{
if(!mSoundId.empty())
{
if(mKeepSound && actor == MWMechanics::getPlayer())
MWBase::Environment::get().getSoundManager()->playSound(mSoundId, 1.0, 1.0,
MWBase::SoundManager::Play_TypeSfx, MWBase::SoundManager::Play_Normal, mSoundOffset
);
else
{
bool local = mTarget.isEmpty() || !mTarget.isInCell(); // no usable target
if(mKeepSound)
MWBase::Environment::get().getSoundManager()->playSound3D(
(local ? actor : mTarget).getRefData().getPosition().asVec3(),
mSoundId, 1.0, 1.0, MWBase::SoundManager::Play_TypeSfx,
MWBase::SoundManager::Play_Normal, mSoundOffset
);
else
MWBase::Environment::get().getSoundManager()->playSound3D(local ? actor : mTarget,
mSoundId, 1.0, 1.0, MWBase::SoundManager::Play_TypeSfx,
MWBase::SoundManager::Play_Normal, mSoundOffset
);
}
}
executeImp(actor, distanceToObject);
if (useDistance)
executeImp(actor, distanceToObject);
else
executeImp(actor);
}
void MWWorld::Action::setSound (const std::string& id)

@ -37,8 +37,7 @@ namespace MWWorld
virtual bool isNullAction() { return false; }
///< Is running this action a no-op? (default false)
void execute (const Ptr& actor);
void execute (const Ptr& actor, float distanceToObject);
void execute (const Ptr& actor, float distanceToObject = 0, bool useDistance = false);
void setSound (const std::string& id);
void setSoundOffset(float offset);

@ -1,40 +1,36 @@
#include "actiontrap.hpp"
#include "../mwmechanics/spellcasting.hpp"
#include "../mwbase/environment.hpp"
#include "../mwbase/world.hpp"
namespace MWWorld
{
void ActionTrap::executeImp(const Ptr &actor, float distance)
{
osg::Vec3f actorPosition(actor.getRefData().getPosition().asVec3());
osg::Vec3f trapPosition(mTrapSource.getRefData().getPosition().asVec3());
float activationDistance = MWBase::Environment::get().getWorld()->getMaxActivationDistance();
// GUI calcs if object in activation distance include object and player geometry
//const float fudgeFactor = 1.25f;
// Hack: if actor is beyond activation range, then assume actor is using telekinesis
// to open door/container.
// Note, can't just detonate the trap at the trapped object's location and use the blast
// Note: can't just detonate the trap at the trapped object's location and use the blast
// radius, because for most trap spells this is 1 foot, much less than the activation distance.
// Using the activation distance as the trap range.
if (distance < activationDistance)
{
// assume actor touched trap
// actor activated object within range of trap
MWMechanics::CastSpell cast(mTrapSource, actor);
cast.mHitPosition = actorPosition;
cast.cast(mSpellId);
}
else
{
// assume telekinesis used
// actor activated object outside range of trap
MWMechanics::CastSpell cast(mTrapSource, mTrapSource);
cast.mHitPosition = trapPosition;
cast.cast(mSpellId);
}
mTrapSource.getCellRef().setTrap("");
}
}

@ -1,5 +1,4 @@
#include "worldimp.hpp"
#include <iostream>
#include <osg/Group>
#include <osg/ComputeBoundsVisitor>
@ -151,7 +150,7 @@ namespace MWWorld
mSky (true), mCells (mStore, mEsm),
mGodMode(false), mScriptsEnabled(true), mContentFiles (contentFiles),
mActivationDistanceOverride (activationDistanceOverride), mStartupScript(startupScript),
mStartCell (startCell), mTeleportEnabled(true),
mStartCell (startCell), mDistanceToFacedObject(0), mTeleportEnabled(true),
mLevitationEnabled(true), mGoToJail(false), mDaysInPrison(0)
{
mPhysics = new MWPhysics::PhysicsSystem(resourceSystem, rootNode);
@ -1012,10 +1011,11 @@ namespace MWWorld
MWWorld::Ptr World::getFacedObject()
{
MWWorld::Ptr facedObject;
float distanceToObject;
if (MWBase::Environment::get().getWindowManager()->isGuiMode() &&
MWBase::Environment::get().getWindowManager()->isConsoleMode())
facedObject = getFacedObject(getMaxActivationDistance() * 50, false);
facedObject = getFacedObject(getMaxActivationDistance() * 50, distanceToObject, false);
else
{
float telekinesisRangeBonus =
@ -1024,7 +1024,6 @@ namespace MWWorld
telekinesisRangeBonus = feetToGameUnits(telekinesisRangeBonus);
float activationDistance = getMaxActivationDistance() + telekinesisRangeBonus;
float distanceToObject;
facedObject = getFacedObject(activationDistance, distanceToObject, true);
@ -1036,6 +1035,8 @@ namespace MWWorld
return 0;
}
mDistanceToFacedObject = distanceToObject;
mFacedObject = facedObject;
return facedObject;
}
@ -1718,22 +1719,6 @@ namespace MWWorld
}
}
MWWorld::Ptr World::getFacedObject(float maxDistance, bool ignorePlayer)
{
maxDistance += mRendering->getCameraDistance();
if (MWBase::Environment::get().getWindowManager()->isGuiMode())
{
float x, y;
MWBase::Environment::get().getWindowManager()->getMousePosition(x, y);
return mRendering->castCameraToViewportRay(x, y, maxDistance, ignorePlayer).mHitObject;
}
else
{
return mRendering->castCameraToViewportRay(0.5f, 0.5f, maxDistance, ignorePlayer).mHitObject;
}
}
MWWorld::Ptr World::getFacedObject(float maxDistance, float& distance, bool ignorePlayer)
{
maxDistance += mRendering->getCameraDistance();
@ -3228,20 +3213,20 @@ namespace MWWorld
if (object.getRefData().activate())
{
boost::shared_ptr<MWWorld::Action> action = (object.getClass().activate(object, actor));
if (object.getCellRef().getTrap() != "") // If the object is trapped, do a distance check to account for opening with telekinesis
if (object.getCellRef().getTrap() != "")
{
float distanceToObject;
if (actor == getPlayerPtr()) // If the actor doing the activation is the player, get distance using the raycast in getFacedObject()
MWWorld::Ptr result = getFacedObject(1.0f, distanceToObject, true);
else // Otherwise do a position-based distance check
// For the distance check to a trapped object, use the raycast-derived distance if we have it
if (actor == getPlayerPtr() && (object == mFacedObject))
action->execute (actor, mDistanceToFacedObject, true);
else // Otherwise use a position comparison
{
osg::Vec3f actorPosition(actor.getRefData().getPosition().asVec3());
osg::Vec3f objectPosition(object.getRefData().getPosition().asVec3());
distanceToObject = (objectPosition - actorPosition).length();
}
action->execute (actor, distanceToObject);
action->execute (actor, (objectPosition - actorPosition).length(), true);
}
}
action->execute (actor);
else
action->execute (actor);
}
}

@ -128,10 +128,6 @@ namespace MWWorld
void updateWindowManager ();
void updatePlayer(bool paused);
/// Return faced object
MWWorld::Ptr getFacedObject(float maxDistance, bool ignorePlayer=true);
/// Return faced object and distance from player to it
MWWorld::Ptr getFacedObject(float maxDistance, float& distanceToObject, bool ignorePlayer=true);
public: // FIXME
@ -160,6 +156,10 @@ namespace MWWorld
const std::vector<std::string>& content, ContentLoader& contentLoader);
float mSwimHeightScale;
float mDistanceToFacedObject;
MWWorld::Ptr mFacedObject;
bool isUnderwater(const MWWorld::ConstPtr &object, const float heightRatio) const;
///< helper function for implementing isSwimming(), isSubmerged(), isWading()

Loading…
Cancel
Save