mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-16 21:49:55 +00:00
Improve logic for script-induced cell changes
This commit is contained in:
parent
01af4f3bbc
commit
4d7130b12f
4 changed files with 30 additions and 26 deletions
|
@ -6,6 +6,7 @@
|
|||
#include <components/openmw-mp/NetworkMessages.hpp>
|
||||
#include <apps/openmw-mp/Player.hpp>
|
||||
#include <apps/openmw-mp/Networking.hpp>
|
||||
#include <components/openmw-mp/Log.hpp>
|
||||
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
@ -65,19 +66,20 @@ void TranslocationFunctions::SetCell(unsigned short pid, const char *name) noexc
|
|||
Player *player;
|
||||
GET_PLAYER(pid, player,);
|
||||
|
||||
/*if (player->GetCell()->mName == name)
|
||||
return;*/
|
||||
LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Script is moving %s from %s to %s",
|
||||
player->Npc()->mName.c_str(),
|
||||
player->GetCell()->getDescription().c_str(),
|
||||
name);
|
||||
|
||||
cout << "attempt to move player (pid: " << pid << " name: " << player->Npc()->mName << ") from ";
|
||||
if (!player->GetCell()->isExterior())
|
||||
cout << "\"" << player->GetCell()->mName << "\"";
|
||||
else
|
||||
cout << "exterior";
|
||||
// If the player is currently in an exterior, turn on the interior flag
|
||||
// from the cell so the player doesn't get teleported to their exterior
|
||||
// grid position (which we haven't changed)
|
||||
if (player->GetCell()->isExterior()) {
|
||||
player->GetCell()->mData.mFlags |= ESM::Cell::Interior;
|
||||
}
|
||||
|
||||
player->GetCell()->mName = name;
|
||||
|
||||
cout << " in to cell \"" << player->GetCell()->mName << "\"" << endl;
|
||||
|
||||
mwmp::Networking::Get().GetController()->GetPacket(ID_GAME_CELL)->Send(player, false);
|
||||
}
|
||||
|
||||
|
@ -94,14 +96,18 @@ void TranslocationFunctions::SetExterior(unsigned short pid, int x, int y) noexc
|
|||
Player *player;
|
||||
GET_PLAYER(pid, player,);
|
||||
|
||||
cout << "attempt to move player (pid: " << pid << " name: " << player->Npc()->mName << ") from ";
|
||||
if (!player->GetCell()->isExterior())
|
||||
cout << "\"" << player->GetCell()->mName << "\"";
|
||||
else
|
||||
cout << "exterior: " << player->GetCell()->mCellId.mIndex.mX << ", " << player->GetCell()->mCellId.mIndex.mY;
|
||||
cout << " in to exterior cell \"" << x << ", " << y << "\"" << endl;
|
||||
LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Script is moving %s from %s to %i,%i",
|
||||
player->Npc()->mName.c_str(),
|
||||
player->GetCell()->getDescription().c_str(),
|
||||
x,
|
||||
y);
|
||||
|
||||
// If the player is currently in an interior, turn off the interior flag
|
||||
// from the cell
|
||||
if (!player->GetCell()->isExterior()) {
|
||||
player->GetCell()->mData.mFlags &= ~ESM::Cell::Interior;
|
||||
}
|
||||
|
||||
player->GetCell()->mName = "";
|
||||
player->GetCell()->mCellId.mIndex.mX = x;
|
||||
player->GetCell()->mCellId.mIndex.mY = y;
|
||||
|
||||
|
@ -122,12 +128,12 @@ int TranslocationFunctions::GetExteriorY(unsigned short pid) noexcept
|
|||
return player->GetCell()->mCellId.mIndex.mY;
|
||||
}
|
||||
|
||||
bool TranslocationFunctions::IsInInterior(unsigned short pid) noexcept
|
||||
bool TranslocationFunctions::IsInExterior(unsigned short pid) noexcept
|
||||
{
|
||||
Player *player;
|
||||
GET_PLAYER(pid, player, false);
|
||||
|
||||
return !player->GetCell()->isExterior();
|
||||
return player->GetCell()->isExterior();
|
||||
}
|
||||
|
||||
void TranslocationFunctions::GetAngle(unsigned short pid, float *x, float *y, float *z) noexcept
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
{"SetExterior", TranslocationFunctions::SetExterior},\
|
||||
{"GetExteriorX", TranslocationFunctions::GetExteriorX},\
|
||||
{"GetExteriorY", TranslocationFunctions::GetExteriorY},\
|
||||
{"IsInInterior", TranslocationFunctions::IsInInterior}
|
||||
{"IsInExterior", TranslocationFunctions::IsInExterior}
|
||||
|
||||
|
||||
class TranslocationFunctions
|
||||
|
@ -37,7 +37,6 @@ public:
|
|||
static double GetPosZ(unsigned short pid) noexcept;
|
||||
static void SetPos(unsigned short pid, double x, double y, double z) noexcept;
|
||||
|
||||
|
||||
static void GetAngle(unsigned short pid, float *x, float *y, float *z) noexcept;
|
||||
static double GetAngleX(unsigned short pid) noexcept;
|
||||
static double GetAngleY(unsigned short pid) noexcept;
|
||||
|
@ -51,7 +50,7 @@ public:
|
|||
static int GetExteriorX(unsigned short pid) noexcept;
|
||||
static int GetExteriorY(unsigned short pid) noexcept;
|
||||
|
||||
static bool IsInInterior(unsigned short pid) noexcept;
|
||||
static bool IsInExterior(unsigned short pid) noexcept;
|
||||
};
|
||||
|
||||
#endif //OPENMW_TRANSLOCATIONS_HPP
|
||||
|
|
|
@ -201,7 +201,7 @@ void LocalPlayer::setCell()
|
|||
int y = GetCell()->mCellId.mIndex.mY;
|
||||
ESM::CellId curCell = player.mCell->getCell()->mCellId;
|
||||
|
||||
if (GetCell()->mName.empty())
|
||||
if (GetCell()->isExterior())
|
||||
{
|
||||
world->indexToPosition(x, y, pos.pos[0], pos.pos[1], true);
|
||||
pos.pos[2] = 0;
|
||||
|
@ -417,7 +417,6 @@ void LocalPlayer::updateCell(bool forceUpdate)
|
|||
}
|
||||
else if (_cell->isExterior())
|
||||
{
|
||||
|
||||
if (_cell->mCellId.mIndex.mX != GetCell()->mCellId.mIndex.mX)
|
||||
{
|
||||
shouldUpdate = true;
|
||||
|
@ -439,7 +438,8 @@ void LocalPlayer::updateCell(bool forceUpdate)
|
|||
(*GetCell()) = *_cell;
|
||||
isExterior = _cell->isExterior();
|
||||
|
||||
// Make sure the position is updated before a cell packet is sent
|
||||
// Make sure the position is updated before a cell packet is sent, or else
|
||||
// cell change events in server scripts will have the wrong player position
|
||||
updatePosition(true);
|
||||
|
||||
RakNet::BitStream bs;
|
||||
|
|
|
@ -19,7 +19,6 @@ void mwmp::PacketCell::Packet(RakNet::BitStream *bs, mwmp::BasePlayer *player, b
|
|||
|
||||
RW(player->GetCell()->mData.mFlags, send);
|
||||
|
||||
|
||||
RW(player->GetCell()->mCellId.mIndex.mX, send);
|
||||
RW(player->GetCell()->mCellId.mIndex.mY, send);
|
||||
|
||||
|
|
Loading…
Reference in a new issue