1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-27 03:35:27 +00:00

Merge remote-tracking branch 'upstream/master' into pathfinding

# Conflicts:
#	apps/openmw/mwmechanics/aipackage.cpp
#	apps/openmw/mwmechanics/aipackage.hpp
This commit is contained in:
mrcheko 2016-07-12 00:45:01 +03:00
commit b4e94e2aae
11 changed files with 52 additions and 47 deletions

View File

@ -7,6 +7,7 @@
#include "../mwbase/world.hpp" #include "../mwbase/world.hpp"
#include "../mwbase/windowmanager.hpp" #include "../mwbase/windowmanager.hpp"
#include "../mwbase/mechanicsmanager.hpp" #include "../mwbase/mechanicsmanager.hpp"
#include "../mwbase/soundmanager.hpp"
#include "../mwworld/ptr.hpp" #include "../mwworld/ptr.hpp"
#include "../mwworld/failedaction.hpp" #include "../mwworld/failedaction.hpp"
@ -136,7 +137,8 @@ namespace MWClass
MWWorld::Ptr player = MWBase::Environment::get().getWorld ()->getPlayerPtr(); MWWorld::Ptr player = MWBase::Environment::get().getWorld ()->getPlayerPtr();
MWWorld::InventoryStore& invStore = player.getClass().getInventoryStore(player); MWWorld::InventoryStore& invStore = player.getClass().getInventoryStore(player);
bool needKey = ptr.getCellRef().getLockLevel() > 0; bool isLocked = ptr.getCellRef().getLockLevel() > 0;
bool isTrapped = !ptr.getCellRef().getTrap().empty();
bool hasKey = false; bool hasKey = false;
std::string keyName; std::string keyName;
@ -154,18 +156,26 @@ namespace MWClass
} }
} }
if (needKey && hasKey) if ((isLocked || isTrapped) && hasKey)
{ {
MWBase::Environment::get().getWindowManager ()->messageBox (keyName + " #{sKeyUsed}"); MWBase::Environment::get().getWindowManager ()->messageBox (keyName + " #{sKeyUsed}");
unlock(ptr); if(isLocked)
unlock(ptr);
// using a key disarms the trap // using a key disarms the trap
ptr.getCellRef().setTrap(""); if(isTrapped)
{
ptr.getCellRef().setTrap("");
MWBase::Environment::get().getSoundManager()->playSound3D(ptr,
"Disarm Trap", 1.0f, 1.0f, MWBase::SoundManager::Play_TypeSfx,
MWBase::SoundManager::Play_Normal);
isTrapped = false;
}
} }
if (!needKey || hasKey) if (!isLocked || hasKey)
{ {
if(ptr.getCellRef().getTrap().empty()) if(!isTrapped)
{ {
boost::shared_ptr<MWWorld::Action> action (new MWWorld::ActionOpen(ptr)); boost::shared_ptr<MWWorld::Action> action (new MWWorld::ActionOpen(ptr));
return action; return action;
@ -173,7 +183,7 @@ namespace MWClass
else else
{ {
// Activate trap // Activate trap
boost::shared_ptr<MWWorld::Action> action(new MWWorld::ActionTrap(actor, ptr.getCellRef().getTrap(), ptr)); boost::shared_ptr<MWWorld::Action> action(new MWWorld::ActionTrap(ptr.getCellRef().getTrap(), ptr));
action->setSound(trapActivationSound); action->setSound(trapActivationSound);
return action; return action;
} }

View File

@ -107,7 +107,8 @@ namespace MWClass
MWWorld::ContainerStore &invStore = actor.getClass().getContainerStore(actor); MWWorld::ContainerStore &invStore = actor.getClass().getContainerStore(actor);
bool needKey = ptr.getCellRef().getLockLevel() > 0; bool isLocked = ptr.getCellRef().getLockLevel() > 0;
bool isTrapped = !ptr.getCellRef().getTrap().empty();
bool hasKey = false; bool hasKey = false;
std::string keyName; std::string keyName;
@ -125,21 +126,29 @@ namespace MWClass
} }
} }
if (needKey && hasKey) if ((isLocked || isTrapped) && hasKey)
{ {
if(actor == MWMechanics::getPlayer()) if(actor == MWMechanics::getPlayer())
MWBase::Environment::get().getWindowManager()->messageBox(keyName + " #{sKeyUsed}"); MWBase::Environment::get().getWindowManager()->messageBox(keyName + " #{sKeyUsed}");
unlock(ptr); //Call the function here. because that makes sense. if(isLocked)
unlock(ptr); //Call the function here. because that makes sense.
// using a key disarms the trap // using a key disarms the trap
ptr.getCellRef().setTrap(""); if(isTrapped)
{
ptr.getCellRef().setTrap("");
MWBase::Environment::get().getSoundManager()->playSound3D(ptr,
"Disarm Trap", 1.0f, 1.0f, MWBase::SoundManager::Play_TypeSfx,
MWBase::SoundManager::Play_Normal);
isTrapped = false;
}
} }
if (!needKey || hasKey) if (!isLocked || hasKey)
{ {
if(!ptr.getCellRef().getTrap().empty()) if(isTrapped)
{ {
// Trap activation // Trap activation
boost::shared_ptr<MWWorld::Action> action(new MWWorld::ActionTrap(actor, ptr.getCellRef().getTrap(), ptr)); boost::shared_ptr<MWWorld::Action> action(new MWWorld::ActionTrap(ptr.getCellRef().getTrap(), ptr));
action->setSound(trapActivationSound); action->setSound(trapActivationSound);
return action; return action;
} }

View File

@ -68,7 +68,6 @@ namespace MWMechanics
if (mRemainingDuration <= 0) if (mRemainingDuration <= 0)
{ {
mRemainingDuration = mDuration; mRemainingDuration = mDuration;
mStarted = false; // Reset to false so this package will build path again when repeating
return true; return true;
} }
} }
@ -100,7 +99,6 @@ namespace MWMechanics
if(pathTo(actor,point,duration)) //Returns true on path complete if(pathTo(actor,point,duration)) //Returns true on path complete
{ {
mRemainingDuration = mDuration; mRemainingDuration = mDuration;
mStarted = false; // Reset to false so this package will build path again when repeating
return true; return true;
} }
mMaxDist = 450; mMaxDist = 450;

View File

@ -23,7 +23,6 @@ MWMechanics::AiPackage::~AiPackage() {}
MWMechanics::AiPackage::AiPackage() : MWMechanics::AiPackage::AiPackage() :
mTimer(AI_REACTION_TIME + 1.0f), // to force initial pathbuild mTimer(AI_REACTION_TIME + 1.0f), // to force initial pathbuild
mStarted(false),
mIsShortcutting(false), mIsShortcutting(false),
mShortcutProhibited(false), mShortcutFailPos() mShortcutProhibited(false), mShortcutFailPos()
{ {
@ -90,8 +89,7 @@ bool MWMechanics::AiPackage::pathTo(const MWWorld::Ptr& actor, const ESM::Pathgr
if (!mIsShortcutting) if (!mIsShortcutting)
{ {
if (!mStarted // If repeating an AI package (mStarted = false), build a new path so package doesn't immediately end if (wasShortcutting || doesPathNeedRecalc(dest)) // if need to rebuild path
|| wasShortcutting || doesPathNeedRecalc(dest)) // if need to rebuild path
{ {
mPathFinder.buildSyncedPath(start, dest, actor.getCell()); mPathFinder.buildSyncedPath(start, dest, actor.getCell());
@ -122,7 +120,6 @@ bool MWMechanics::AiPackage::pathTo(const MWWorld::Ptr& actor, const ESM::Pathgr
} }
mTimer = 0; mTimer = 0;
mStarted = true;
} }
if (isDestReached || mPathFinder.checkPathCompleted(pos.pos[0], pos.pos[1])) // if path is finished if (isDestReached || mPathFinder.checkPathCompleted(pos.pos[0], pos.pos[1])) // if path is finished
@ -250,9 +247,7 @@ bool MWMechanics::AiPackage::checkWayIsClearForActor(const ESM::Pathgrid::Point&
bool MWMechanics::AiPackage::doesPathNeedRecalc(const ESM::Pathgrid::Point& newDest) bool MWMechanics::AiPackage::doesPathNeedRecalc(const ESM::Pathgrid::Point& newDest)
{ {
if (mPathFinder.getPath().empty()) return true; return mPathFinder.getPath().empty() || (distance(mPathFinder.getPath().back(), newDest) > 10);
return (distance(mPathFinder.getPath().back(), newDest) > 10);
} }
bool MWMechanics::AiPackage::isTargetMagicallyHidden(const MWWorld::Ptr& target) bool MWMechanics::AiPackage::isTargetMagicallyHidden(const MWWorld::Ptr& target)

View File

@ -124,11 +124,6 @@ namespace MWMechanics
bool mShortcutProhibited; // shortcutting may be prohibited after unsuccessful attempt bool mShortcutProhibited; // shortcutting may be prohibited after unsuccessful attempt
ESM::Pathgrid::Point mShortcutFailPos; // position of last shortcut fail ESM::Pathgrid::Point mShortcutFailPos; // position of last shortcut fail
// Set to true once package starts actually being executed
bool mStarted;
ESM::Pathgrid::Point mPrevDest;
private: private:
bool isNearInactiveCell(const ESM::Position& actorPos); bool isNearInactiveCell(const ESM::Position& actorPos);
}; };

View File

@ -58,13 +58,9 @@ namespace MWMechanics
if (!isWithinMaxRange(osg::Vec3f(mX, mY, mZ), pos.asVec3())) if (!isWithinMaxRange(osg::Vec3f(mX, mY, mZ), pos.asVec3()))
return false; return false;
if (!mStarted)
mStarted = true;
if (pathTo(actor, ESM::Pathgrid::Point(static_cast<int>(mX), static_cast<int>(mY), static_cast<int>(mZ)), duration)) if (pathTo(actor, ESM::Pathgrid::Point(static_cast<int>(mX), static_cast<int>(mY), static_cast<int>(mZ)), duration))
{ {
actor.getClass().getMovementSettings(actor).mPosition[1] = 0; actor.getClass().getMovementSettings(actor).mPosition[1] = 0;
mStarted = false; // Reset to false so this package will build path again when repeating
return true; return true;
} }
return false; return false;

View File

@ -1305,7 +1305,9 @@ bool CharacterController::updateWeaponState()
if(!resultMessage.empty()) if(!resultMessage.empty())
MWBase::Environment::get().getWindowManager()->messageBox(resultMessage); MWBase::Environment::get().getWindowManager()->messageBox(resultMessage);
if(!resultSound.empty()) if(!resultSound.empty())
MWBase::Environment::get().getSoundManager()->playSound(resultSound, 1.0f, 1.0f); MWBase::Environment::get().getSoundManager()->playSound3D(target,
resultSound, 1.0f, 1.0f, MWBase::SoundManager::Play_TypeSfx,
MWBase::SoundManager::Play_Normal);
} }
else if (ammunition) else if (ammunition)
{ {

View File

@ -18,10 +18,9 @@ namespace MWWorld
public: public:
/// @param spellId /// @param spellId
/// @param actor Actor that activated the trap
/// @param trapSource /// @param trapSource
ActionTrap (const Ptr& actor, const std::string& spellId, const Ptr& trapSource) ActionTrap (const std::string& spellId, const Ptr& trapSource)
: Action(false, actor), mSpellId(spellId), mTrapSource(trapSource) {} : Action(false, trapSource), mSpellId(spellId), mTrapSource(trapSource) {}
}; };
} }

View File

@ -1722,7 +1722,8 @@ namespace MWWorld
MWWorld::Ptr World::getFacedObject(float maxDistance, bool ignorePlayer) MWWorld::Ptr World::getFacedObject(float maxDistance, bool ignorePlayer)
{ {
maxDistance += mRendering->getCameraDistance(); const float camDist = mRendering->getCameraDistance();
maxDistance += camDist;
MWWorld::Ptr facedObject; MWWorld::Ptr facedObject;
MWRender::RenderingManager::RayResult rayToObject; MWRender::RenderingManager::RayResult rayToObject;
@ -1737,7 +1738,7 @@ namespace MWWorld
facedObject = rayToObject.mHitObject; facedObject = rayToObject.mHitObject;
if (rayToObject.mHit) if (rayToObject.mHit)
mDistanceToFacedObject = rayToObject.mRatio * maxDistance; mDistanceToFacedObject = (rayToObject.mRatio * maxDistance) - camDist;
else else
mDistanceToFacedObject = -1; mDistanceToFacedObject = -1;
return facedObject; return facedObject;

View File

@ -48,14 +48,14 @@ class NIFFile
public: public:
/// Used if file parsing fails /// Used if file parsing fails
void fail(const std::string &msg) void fail(const std::string &msg) const
{ {
std::string err = " NIFFile Error: " + msg; std::string err = " NIFFile Error: " + msg;
err += "\nFile: " + filename; err += "\nFile: " + filename;
throw std::runtime_error(err); throw std::runtime_error(err);
} }
/// Used when something goes wrong, but not catastrophically so /// Used when something goes wrong, but not catastrophically so
void warn(const std::string &msg) void warn(const std::string &msg) const
{ {
std::cerr << " NIFFile Warning: " << msg <<std::endl std::cerr << " NIFFile Warning: " << msg <<std::endl
<< "File: " << filename <<std::endl; << "File: " << filename <<std::endl;
@ -90,9 +90,9 @@ public:
bool getUseSkinning() const; bool getUseSkinning() const;
/// Get the name of the file /// Get the name of the file
std::string getFilename(){ return filename; } std::string getFilename() const { return filename; }
}; };
typedef boost::shared_ptr<Nif::NIFFile> NIFFilePtr; typedef boost::shared_ptr<const Nif::NIFFile> NIFFilePtr;

View File

@ -321,8 +321,8 @@ namespace NifOsg
continue; continue;
} }
if (!(ctrl->flags & Nif::NiNode::ControllerFlag_Active)) // Vanilla seems to ignore the "active" flag for NiKeyframeController,
continue; // so we don't want to skip inactive controllers here.
const Nif::NiStringExtraData *strdata = static_cast<const Nif::NiStringExtraData*>(extra.getPtr()); const Nif::NiStringExtraData *strdata = static_cast<const Nif::NiStringExtraData*>(extra.getPtr());
const Nif::NiKeyframeController *key = static_cast<const Nif::NiKeyframeController*>(ctrl.getPtr()); const Nif::NiKeyframeController *key = static_cast<const Nif::NiKeyframeController*>(ctrl.getPtr());
@ -918,9 +918,9 @@ namespace NifOsg
emitter->setShooter(shooter); emitter->setShooter(shooter);
osgParticle::BoxPlacer* placer = new osgParticle::BoxPlacer; osgParticle::BoxPlacer* placer = new osgParticle::BoxPlacer;
placer->setXRange(-partctrl->offsetRandom.x(), partctrl->offsetRandom.x()); placer->setXRange(-partctrl->offsetRandom.x() / 2.f, partctrl->offsetRandom.x() / 2.f);
placer->setYRange(-partctrl->offsetRandom.y(), partctrl->offsetRandom.y()); placer->setYRange(-partctrl->offsetRandom.y() / 2.f, partctrl->offsetRandom.y() / 2.f);
placer->setZRange(-partctrl->offsetRandom.z(), partctrl->offsetRandom.z()); placer->setZRange(-partctrl->offsetRandom.z() / 2.f, partctrl->offsetRandom.z() / 2.f);
emitter->setPlacer(placer); emitter->setPlacer(placer);
return emitter; return emitter;