mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-16 20:49:56 +00:00
New API
SetExterior(pid, x, y) GetExteriorX(pid) GetExteriorY(pid) also "SetCell" will now move to the named external cells (e.g. SetCell(pid, "Balmora"))
This commit is contained in:
parent
39dafc5ea7
commit
7107136808
6 changed files with 93 additions and 20 deletions
|
@ -79,8 +79,6 @@ void ScriptFunctions::SetCell(unsigned short pid, const char *name) noexcept
|
|||
|
||||
cout << " in to cell \"" << player->GetCell()->mName << "\"" << endl;
|
||||
|
||||
player->GetCell()->mData.mFlags |= 1;
|
||||
|
||||
mwmp::Networking::Get().GetController()->GetPacket(ID_GAME_CELL)->Send(player, false);
|
||||
mwmp::Networking::Get().GetController()->GetPacket(ID_GAME_CELL)->Send(player, true);
|
||||
}
|
||||
|
@ -94,6 +92,43 @@ const char* ScriptFunctions::GetCell(unsigned short pid) noexcept
|
|||
return player->GetCell()->mName.c_str();
|
||||
}
|
||||
|
||||
void ScriptFunctions::SetExterior(unsigned short pid, int x, int y) noexcept
|
||||
{
|
||||
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;
|
||||
|
||||
/*cout << "TEST1 : " << player->GetCell()->mData.mFlags << endl;
|
||||
player->GetCell()->mData.mFlags &= ~1;
|
||||
cout << "TEST2 : " << player->GetCell()->mData.mFlags << endl;*/
|
||||
|
||||
player->GetCell()->mCellId.mIndex.mX = x;
|
||||
player->GetCell()->mCellId.mIndex.mY = y;
|
||||
|
||||
mwmp::Networking::Get().GetController()->GetPacket(ID_GAME_CELL)->Send(player, false);
|
||||
mwmp::Networking::Get().GetController()->GetPacket(ID_GAME_CELL)->Send(player, true);
|
||||
}
|
||||
|
||||
int ScriptFunctions::GetExteriorX(unsigned short pid) noexcept
|
||||
{
|
||||
Player *player;
|
||||
GET_PLAYER(pid, player,0);
|
||||
return player->GetCell()->mCellId.mIndex.mX;
|
||||
}
|
||||
|
||||
int ScriptFunctions::GetExteriorY(unsigned short pid) noexcept
|
||||
{
|
||||
Player *player;
|
||||
GET_PLAYER(pid, player,0);
|
||||
return player->GetCell()->mCellId.mIndex.mY;
|
||||
}
|
||||
|
||||
bool ScriptFunctions::IsInInterior(unsigned short pid) noexcept
|
||||
{
|
||||
Player *player;
|
||||
|
|
|
@ -48,6 +48,10 @@ public:
|
|||
static void SetCell(unsigned short pid, const char *name) noexcept;
|
||||
static const char *GetCell(unsigned short pid) noexcept;
|
||||
|
||||
static void SetExterior(unsigned short pid, int x, int y) noexcept;
|
||||
static int GetExteriorX(unsigned short pid) noexcept;
|
||||
static int GetExteriorY(unsigned short pid) noexcept;
|
||||
|
||||
static bool IsInInterior(unsigned short pid) noexcept;
|
||||
|
||||
static void SetName(unsigned short pid, const char *name) noexcept;
|
||||
|
@ -162,6 +166,9 @@ public:
|
|||
|
||||
{"GetCell", ScriptFunctions::GetCell},
|
||||
{"SetCell", ScriptFunctions::SetCell},
|
||||
{"SetExterior", ScriptFunctions::SetExterior},
|
||||
{"GetExteriorX", ScriptFunctions::GetExteriorX},
|
||||
{"GetExteriorY", ScriptFunctions::GetExteriorY},
|
||||
{"IsInInterior", ScriptFunctions::IsInInterior},
|
||||
|
||||
{"GetName", ScriptFunctions::GetName},
|
||||
|
|
|
@ -128,6 +128,44 @@ void LocalPlayer::setPosition()
|
|||
world->rotateObject(player, Position()->rot[0], Position()->rot[1], Position()->rot[2]);
|
||||
}
|
||||
|
||||
void LocalPlayer::setCell()
|
||||
{
|
||||
MWBase::World *world = MWBase::Environment::get().getWorld();
|
||||
MWWorld::Ptr player = world->getPlayerPtr();
|
||||
ESM::Position pos;
|
||||
|
||||
world->getPlayer().setTeleported(true);
|
||||
|
||||
int x = GetCell()->mCellId.mIndex.mX;
|
||||
int y = GetCell()->mCellId.mIndex.mY;
|
||||
ESM::CellId curCell = player.mCell->getCell()->mCellId;
|
||||
if(x != curCell.mIndex.mX || y != curCell.mIndex.mY)
|
||||
{
|
||||
cout << "Exterior location: " << x << ", " << y << endl;
|
||||
world->indexToPosition (x, y, pos.pos[0], pos.pos[1], true);
|
||||
pos.pos[2] = 0;
|
||||
|
||||
pos.rot[0] = pos.rot[1] = pos.rot[2] = 0;
|
||||
|
||||
world->changeToExteriorCell (pos, true);
|
||||
world->fixPosition(player);
|
||||
}
|
||||
else if (world->findExteriorPosition(GetCell()->mName, pos))
|
||||
{
|
||||
cout << "Exterior location: " << GetCell()->mName << endl;
|
||||
world->changeToExteriorCell(pos, true);
|
||||
world->fixPosition(player);
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "Interior location: " << GetCell()->mName << endl;
|
||||
world->findInteriorPosition(GetCell()->mName, pos);
|
||||
world->changeToInteriorCell(GetCell()->mName, pos, true);
|
||||
}
|
||||
|
||||
updateCell(true);
|
||||
}
|
||||
|
||||
|
||||
void LocalPlayer::updateInventory(bool forceUpdate)
|
||||
{
|
||||
|
|
|
@ -30,6 +30,7 @@ namespace mwmp
|
|||
void updateDrawStateAndFlags(bool forceUpdate = false);
|
||||
|
||||
void setPosition();
|
||||
void setCell();
|
||||
|
||||
void CharGen(int stageFirst, int stageEnd);
|
||||
|
||||
|
|
|
@ -414,19 +414,13 @@ void Networking::ReciveMessage(RakNet::Packet *packet)
|
|||
{
|
||||
if(id == myid)
|
||||
{
|
||||
myPacket->Packet(&bsIn, getLocalPlayer(), false);
|
||||
|
||||
if(!getLocalPlayer()->GetCell()->isExterior())
|
||||
if (packet->length == myPacket->headerSize())
|
||||
getLocalPlayer()->updateCell(true);
|
||||
else
|
||||
{
|
||||
cout << "location: " << getLocalPlayer()->GetCell()->mName << endl;
|
||||
|
||||
MWBase::World *world = MWBase::Environment::get().getWorld();
|
||||
ESM::Position pos;
|
||||
world->findInteriorPosition(getLocalPlayer()->GetCell()->mName, pos);
|
||||
world->changeToInteriorCell(getLocalPlayer()->GetCell()->mName, pos, true);
|
||||
myPacket->Packet(&bsIn, getLocalPlayer(), false);
|
||||
getLocalPlayer()->setCell();
|
||||
}
|
||||
|
||||
getLocalPlayer()->updateCell(true);
|
||||
}
|
||||
else if(pl != 0)
|
||||
{
|
||||
|
|
|
@ -19,11 +19,9 @@ void mwmp::PacketCell::Packet(RakNet::BitStream *bs, mwmp::BasePlayer *player, b
|
|||
|
||||
RW(player->GetCell()->mData.mFlags, send);
|
||||
|
||||
if(player->GetCell()->isExterior())
|
||||
{
|
||||
RW(player->GetCell()->mCellId.mIndex.mX, send);
|
||||
RW(player->GetCell()->mCellId.mIndex.mY, send);
|
||||
}
|
||||
else
|
||||
RW(player->GetCell()->mName, send);
|
||||
|
||||
RW(player->GetCell()->mCellId.mIndex.mX, send);
|
||||
RW(player->GetCell()->mCellId.mIndex.mY, send);
|
||||
|
||||
RW(player->GetCell()->mName, send);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue