forked from teamnwah/openmw-tes3coop
update coc behaviour for interior cells
This commit is contained in:
parent
de5898c953
commit
a3094b808e
1 changed files with 71 additions and 11 deletions
|
@ -34,25 +34,85 @@ namespace MWScript
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
static bool findInteriorPosition(const std::string &name, ESM::Position &pos)
|
||||||
|
{
|
||||||
|
typedef MWWorld::CellRefList<ESM::Door>::List DoorList;
|
||||||
|
|
||||||
|
pos.rot[0] = pos.rot[1] = pos.rot[2] = 0;
|
||||||
|
pos.pos[0] = pos.pos[1] = pos.pos[2] = 0;
|
||||||
|
|
||||||
|
MWBase::World *world = MWBase::Environment::get().getWorld();
|
||||||
|
MWWorld::CellStore *cellStore = world->getInterior(name);
|
||||||
|
|
||||||
|
if (0 == cellStore) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const DoorList &doors = cellStore->mDoors.mList;
|
||||||
|
for (DoorList::const_iterator it = doors.begin(); it != doors.end(); ++it) {
|
||||||
|
if (!it->mRef.mTeleport) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
MWWorld::CellStore *source = 0;
|
||||||
|
|
||||||
|
// door to exterior
|
||||||
|
if (it->mRef.mDestCell.empty()) {
|
||||||
|
int x, y;
|
||||||
|
const float *pos = it->mRef.mDoorDest.pos;
|
||||||
|
world->positionToIndex(pos[0], pos[1], x, y);
|
||||||
|
source = world->getExterior(x, y);
|
||||||
|
}
|
||||||
|
// door to interior
|
||||||
|
else {
|
||||||
|
source = world->getInterior(it->mRef.mDestCell);
|
||||||
|
}
|
||||||
|
if (0 != source) {
|
||||||
|
// Find door leading to our current teleport door
|
||||||
|
// and use it destination to position inside cell.
|
||||||
|
const DoorList &doors = source->mDoors.mList;
|
||||||
|
for (DoorList::const_iterator jt = doors.begin(); jt != doors.end(); ++jt) {
|
||||||
|
if (it->mRef.mTeleport &&
|
||||||
|
Misc::StringUtils::ciEqual(name, jt->mRef.mDestCell))
|
||||||
|
{
|
||||||
|
/// \note Using _any_ door pointed to the interior,
|
||||||
|
/// not the one pointed to current door.
|
||||||
|
pos = jt->mRef.mDoorDest;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool findExteriorPosition(const std::string &name, ESM::Position &pos)
|
||||||
|
{
|
||||||
|
MWBase::World *world = MWBase::Environment::get().getWorld();
|
||||||
|
|
||||||
|
if (const ESM::Cell *ext = world->getExterior(name)) {
|
||||||
|
world->indexToPosition(ext->mData.mX, ext->mData.mY, pos.pos[0], pos.pos[1], true);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
virtual void execute (Interpreter::Runtime& runtime)
|
virtual void execute (Interpreter::Runtime& runtime)
|
||||||
{
|
{
|
||||||
std::string cell = runtime.getStringLiteral (runtime[0].mInteger);
|
std::string cell = runtime.getStringLiteral (runtime[0].mInteger);
|
||||||
runtime.pop();
|
runtime.pop();
|
||||||
|
|
||||||
ESM::Position pos;
|
ESM::Position pos;
|
||||||
pos.rot[0] = pos.rot[1] = pos.rot[2] = 0;
|
MWBase::World *world = MWBase::Environment::get().getWorld();
|
||||||
pos.pos[2] = 0;
|
|
||||||
|
|
||||||
if (const ESM::Cell *exterior = MWBase::Environment::get().getWorld()->getExterior (cell))
|
if (findExteriorPosition(cell, pos)) {
|
||||||
{
|
world->changeToExteriorCell(pos);
|
||||||
MWBase::Environment::get().getWorld()->indexToPosition (exterior->mData.mX, exterior->mData.mY,
|
|
||||||
pos.pos[0], pos.pos[1], true);
|
|
||||||
MWBase::Environment::get().getWorld()->changeToExteriorCell (pos);
|
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
// Change to interior even if findInteriorPosition()
|
||||||
pos.pos[0] = pos.pos[1] = 0;
|
// yields false. In this case position will be zero-point.
|
||||||
MWBase::Environment::get().getWorld()->changeToInteriorCell (cell, pos);
|
findInteriorPosition(cell, pos);
|
||||||
|
world->changeToInteriorCell(cell, pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue