1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-03-03 15:19:42 +00:00

Merge remote-tracking branch 'kcat/master'

Conflicts:
	extern/sdl4ogre/cursormanager.hpp
This commit is contained in:
Marc Zinnschlag 2013-09-02 10:54:18 +02:00
commit b737d958e1
5 changed files with 51 additions and 92 deletions

View file

@ -33,46 +33,48 @@ namespace MWMechanics
bool AiTravel::execute (const MWWorld::Ptr& actor) bool AiTravel::execute (const MWWorld::Ptr& actor)
{ {
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer(); MWBase::World *world = MWBase::Environment::get().getWorld();
ESM::Position pos = actor.getRefData().getPosition(); ESM::Position pos = actor.getRefData().getPosition();
bool cellChange = actor.getCell()->mCell->mData.mX != cellX || actor.getCell()->mCell->mData.mY != cellY; Movement &movement = actor.getClass().getMovementSettings(actor);
const ESM::Pathgrid *pathgrid = const ESM::Cell *cell = actor.getCell()->mCell;
MWBase::Environment::get().getWorld()->getStore().get<ESM::Pathgrid>().search(*actor.getCell()->mCell);
if(actor.getCell()->mCell->mData.mX != player.getCell()->mCell->mData.mX) MWWorld::Ptr player = world->getPlayer().getPlayer();
if(cell->mData.mX != player.getCell()->mCell->mData.mX)
{ {
int sideX = sgn(actor.getCell()->mCell->mData.mX - player.getCell()->mCell->mData.mX); int sideX = sgn(cell->mData.mX - player.getCell()->mCell->mData.mX);
//check if actor is near the border of an inactive cell. If so, disable aitravel. //check if actor is near the border of an inactive cell. If so, stop walking.
if(sideX * (pos.pos[0] - actor.getCell()->mCell->mData.mX * ESM::Land::REAL_SIZE) > sideX * (ESM::Land::REAL_SIZE / if(sideX * (pos.pos[0] - cell->mData.mX*ESM::Land::REAL_SIZE) >
2.0 - 200)) sideX * (ESM::Land::REAL_SIZE/2.0f - 200.0f))
{ {
MWWorld::Class::get(actor).getMovementSettings(actor).mPosition[1] = 0; movement.mPosition[1] = 0;
return true; return false;
} }
} }
if(actor.getCell()->mCell->mData.mY != player.getCell()->mCell->mData.mY) if(cell->mData.mY != player.getCell()->mCell->mData.mY)
{ {
int sideY = sgn(actor.getCell()->mCell->mData.mY - player.getCell()->mCell->mData.mY); int sideY = sgn(cell->mData.mY - player.getCell()->mCell->mData.mY);
//check if actor is near the border of an inactive cell. If so, disable aitravel. //check if actor is near the border of an inactive cell. If so, stop walking.
if(sideY * (pos.pos[1] - actor.getCell()->mCell->mData.mY * ESM::Land::REAL_SIZE) > sideY * (ESM::Land::REAL_SIZE / if(sideY * (pos.pos[1] - cell->mData.mY*ESM::Land::REAL_SIZE) >
2.0 - 200)) sideY * (ESM::Land::REAL_SIZE/2.0f - 200.0f))
{ {
MWWorld::Class::get(actor).getMovementSettings(actor).mPosition[1] = 0; movement.mPosition[1] = 0;
return true; return false;
} }
} }
const ESM::Pathgrid *pathgrid = world->getStore().get<ESM::Pathgrid>().search(*cell);
bool cellChange = cell->mData.mX != cellX || cell->mData.mY != cellY;
if(!mPathFinder.isPathConstructed() || cellChange) if(!mPathFinder.isPathConstructed() || cellChange)
{ {
cellX = actor.getCell()->mCell->mData.mX; cellX = cell->mData.mX;
cellY = actor.getCell()->mCell->mData.mY; cellY = cell->mData.mY;
float xCell = 0; float xCell = 0;
float yCell = 0; float yCell = 0;
if (actor.getCell()->mCell->isExterior()) if(cell->isExterior())
{ {
xCell = actor.getCell()->mCell->mData.mX * ESM::Land::REAL_SIZE; xCell = cell->mData.mX * ESM::Land::REAL_SIZE;
yCell = actor.getCell()->mCell->mData.mY * ESM::Land::REAL_SIZE; yCell = cell->mData.mY * ESM::Land::REAL_SIZE;
} }
ESM::Pathgrid::Point dest; ESM::Pathgrid::Point dest;
@ -90,13 +92,13 @@ namespace MWMechanics
if(mPathFinder.checkPathCompleted(pos.pos[0], pos.pos[1], pos.pos[2])) if(mPathFinder.checkPathCompleted(pos.pos[0], pos.pos[1], pos.pos[2]))
{ {
MWWorld::Class::get(actor).getMovementSettings(actor).mPosition[1] = 0; movement.mPosition[1] = 0;
return true; return true;
} }
float zAngle = mPathFinder.getZAngleToNext(pos.pos[0], pos.pos[1]); float zAngle = mPathFinder.getZAngleToNext(pos.pos[0], pos.pos[1]);
MWBase::Environment::get().getWorld()->rotateObject(actor, 0, 0, zAngle, false); world->rotateObject(actor, 0, 0, zAngle, false);
MWWorld::Class::get(actor).getMovementSettings(actor).mPosition[1] = 1; movement.mPosition[1] = 1;
return false; return false;
} }

View file

@ -65,10 +65,11 @@ namespace MWMechanics
bool AiWander::execute (const MWWorld::Ptr& actor) bool AiWander::execute (const MWWorld::Ptr& actor)
{ {
MWBase::World *world = MWBase::Environment::get().getWorld();
if(mDuration) if(mDuration)
{ {
// End package if duration is complete or mid-night hits: // End package if duration is complete or mid-night hits:
MWWorld::TimeStamp currentTime = MWBase::Environment::get().getWorld()->getTimeStamp(); MWWorld::TimeStamp currentTime = world->getTimeStamp();
if(currentTime.getHour() >= mStartTime.getHour() + mDuration) if(currentTime.getHour() >= mStartTime.getHour() + mDuration)
{ {
if(!mRepeat) if(!mRepeat)
@ -96,8 +97,7 @@ namespace MWMechanics
if(!mStoredAvailableNodes) if(!mStoredAvailableNodes)
{ {
mStoredAvailableNodes = true; mStoredAvailableNodes = true;
mPathgrid = mPathgrid = world->getStore().get<ESM::Pathgrid>().search(*actor.getCell()->mCell);
MWBase::Environment::get().getWorld()->getStore().get<ESM::Pathgrid>().search(*actor.getCell()->mCell);
mCellX = actor.getCell()->mCell->mData.mX; mCellX = actor.getCell()->mCell->mData.mX;
mCellY = actor.getCell()->mCell->mData.mY; mCellY = actor.getCell()->mCell->mData.mY;
@ -150,37 +150,8 @@ namespace MWMechanics
} }
} }
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer();
bool cellChange = actor.getCell()->mCell->mData.mX != mCellX || actor.getCell()->mCell->mData.mY != mCellY;
if(actor.getCell()->mCell->mData.mX != player.getCell()->mCell->mData.mX)
{
int sideX = sgn(actor.getCell()->mCell->mData.mX - player.getCell()->mCell->mData.mX);
// Check if actor is near the border of an inactive cell. If so, disable AiWander.
// FIXME: This *should* pause the AiWander package instead of terminating it.
if(sideX * (pos.pos[0] - actor.getCell()->mCell->mData.mX * ESM::Land::REAL_SIZE) > sideX * (ESM::Land::REAL_SIZE /
2.0 - 200))
{
stopWalking(actor);
return true;
}
}
if(actor.getCell()->mCell->mData.mY != player.getCell()->mCell->mData.mY)
{
int sideY = sgn(actor.getCell()->mCell->mData.mY - player.getCell()->mCell->mData.mY);
// Check if actor is near the border of an inactive cell. If so, disable AiWander.
// FIXME: This *should* pause the AiWander package instead of terminating it.
if(sideY * (pos.pos[1] - actor.getCell()->mCell->mData.mY * ESM::Land::REAL_SIZE) > sideY * (ESM::Land::REAL_SIZE /
2.0 - 200))
{
stopWalking(actor);
return true;
}
}
// Don't try to move if you are in a new cell (ie: positioncell command called) but still play idles. // Don't try to move if you are in a new cell (ie: positioncell command called) but still play idles.
if(mDistance && (cellChange || (mCellX != actor.getCell()->mCell->mData.mX || mCellY != actor.getCell()->mCell->mData.mY))) if(mDistance && (mCellX != actor.getCell()->mCell->mData.mX || mCellY != actor.getCell()->mCell->mData.mY))
mDistance = 0; mDistance = 0;
if(mChooseAction) if(mChooseAction)
@ -207,7 +178,7 @@ namespace MWMechanics
else else
{ {
// Play idle animation and recreate vanilla (broken?) behavior of resetting start time of AIWander: // Play idle animation and recreate vanilla (broken?) behavior of resetting start time of AIWander:
MWWorld::TimeStamp currentTime = MWBase::Environment::get().getWorld()->getTimeStamp(); MWWorld::TimeStamp currentTime = world->getTimeStamp();
mStartTime = currentTime; mStartTime = currentTime;
playIdle(actor, mPlayedIdle); playIdle(actor, mPlayedIdle);
mChooseAction = false; mChooseAction = false;
@ -264,18 +235,10 @@ namespace MWMechanics
if(mWalking) if(mWalking)
{ {
float zAngle = mPathFinder.getZAngleToNext(pos.pos[0], pos.pos[1]); float zAngle = mPathFinder.getZAngleToNext(pos.pos[0], pos.pos[1]);
MWBase::Environment::get().getWorld()->rotateObject(actor, 0, 0, zAngle,false); world->rotateObject(actor, 0, 0, zAngle, false);
MWWorld::Class::get(actor).getMovementSettings(actor).mPosition[1] = 1; MWWorld::Class::get(actor).getMovementSettings(actor).mPosition[1] = 1;
// Unclog path nodes by allowing the NPC to be a small distance away from the center. This way two NPCs can be if(mPathFinder.checkPathCompleted(pos.pos[0], pos.pos[1], pos.pos[2]))
// at the same path node at the same time and both will complete instead of endlessly walking into eachother:
Ogre::Vector3 destNodePos(mCurrentNode.mX, mCurrentNode.mY, mCurrentNode.mZ);
Ogre::Vector3 actorPos(actor.getRefData().getPosition().pos);
actorPos[0] = actorPos[0] - mXCell;
actorPos[1] = actorPos[1] - mYCell;
float distance = actorPos.squaredDistance(destNodePos);
if(distance < 1200 || mPathFinder.checkPathCompleted(pos.pos[0], pos.pos[1], pos.pos[2]))
{ {
stopWalking(actor); stopWalking(actor);
mMoveNow = false; mMoveNow = false;

View file

@ -147,13 +147,13 @@ namespace MWMechanics
mIsPathConstructed = false; mIsPathConstructed = false;
} }
void PathFinder::buildPath(ESM::Pathgrid::Point startPoint, ESM::Pathgrid::Point endPoint, void PathFinder::buildPath(const ESM::Pathgrid::Point &startPoint, const ESM::Pathgrid::Point &endPoint,
const ESM::Pathgrid* pathGrid, float xCell, float yCell, bool allowShortcuts) const ESM::Pathgrid *pathGrid, float xCell, float yCell, bool allowShortcuts)
{ {
if(allowShortcuts) if(allowShortcuts)
{ {
if(MWBase::Environment::get().getWorld()->castRay(startPoint.mX, startPoint.mY, startPoint.mZ, endPoint.mX, endPoint.mY, if(MWBase::Environment::get().getWorld()->castRay(startPoint.mX, startPoint.mY, startPoint.mZ,
endPoint.mZ)) endPoint.mX, endPoint.mY, endPoint.mZ))
allowShortcuts = false; allowShortcuts = false;
} }
@ -184,14 +184,14 @@ namespace MWMechanics
mIsPathConstructed = false; mIsPathConstructed = false;
} }
float PathFinder::getZAngleToNext(float x, float y) float PathFinder::getZAngleToNext(float x, float y) const
{ {
// This should never happen (programmers should have an if statement checking mIsPathConstructed that prevents this call // This should never happen (programmers should have an if statement checking mIsPathConstructed that prevents this call
// if otherwise). // if otherwise).
if(mPath.empty()) if(mPath.empty())
return 0; return 0;
ESM::Pathgrid::Point nextPoint = *mPath.begin(); const ESM::Pathgrid::Point &nextPoint = *mPath.begin();
float directionX = nextPoint.mX - x; float directionX = nextPoint.mX - x;
float directionY = nextPoint.mY - y; float directionY = nextPoint.mY - y;
float directionResult = sqrt(directionX * directionX + directionY * directionY); float directionResult = sqrt(directionX * directionX + directionY * directionY);
@ -205,7 +205,7 @@ namespace MWMechanics
return true; return true;
ESM::Pathgrid::Point nextPoint = *mPath.begin(); ESM::Pathgrid::Point nextPoint = *mPath.begin();
if(distanceZCorrected(nextPoint, x, y, z) < 40) if(distanceZCorrected(nextPoint, x, y, z) < 64)
{ {
mPath.pop_front(); mPath.pop_front();
if(mPath.empty()) if(mPath.empty())
@ -217,15 +217,5 @@ namespace MWMechanics
return false; return false;
} }
std::list<ESM::Pathgrid::Point> PathFinder::getPath()
{
return mPath;
}
bool PathFinder::isPathConstructed()
{
return mIsPathConstructed;
}
} }

View file

@ -12,15 +12,18 @@ namespace MWMechanics
PathFinder(); PathFinder();
void clearPath(); void clearPath();
void buildPath(ESM::Pathgrid::Point startPoint, ESM::Pathgrid::Point endPoint, void buildPath(const ESM::Pathgrid::Point &startPoint, const ESM::Pathgrid::Point &endPoint,
const ESM::Pathgrid* pathGrid, float xCell = 0, float yCell = 0, bool allowShortcuts = 1); const ESM::Pathgrid* pathGrid, float xCell = 0, float yCell = 0,
bool allowShortcuts = true);
bool checkPathCompleted(float x, float y, float z); bool checkPathCompleted(float x, float y, float z);
///< \Returns true if the last point of the path has been reached. ///< \Returns true if the last point of the path has been reached.
float getZAngleToNext(float x, float y); float getZAngleToNext(float x, float y) const;
std::list<ESM::Pathgrid::Point> getPath(); bool isPathConstructed() const
bool isPathConstructed(); {
return mIsPathConstructed;
}
private: private:
std::list<ESM::Pathgrid::Point> mPath; std::list<ESM::Pathgrid::Point> mPath;

View file

@ -5,6 +5,7 @@
#include <string> #include <string>
#include <OgreTexture.h> #include <OgreTexture.h>
#include <OgrePrerequisites.h>
namespace SFO namespace SFO
{ {