Flatlander
Species Developer
This is a tutorial showing how to add more tiles to the OTClient window. (Make the screen bigger)
Update:
in const.h
I was notified increasing this number could resolve some issues.
This is actually a bigger problem than it should be, because TFS doesn't use maxViewPort everywhere it should. So lets change that first!
I will do this for TFS 1.0, since it is basically the same edits for TFS 0.3.6, and maybe i'll learn something doing it for TFS 1.0.
Most of our edits (almost all of them) will be in protocalgame.cpp
First we need to edit:
bool ProtocolGame::canSee(int32_t x, int32_t y, int32_t z) const
Change This:
To This:
Then in:
void ProtocolGame::sendMapDescription(const Position& pos)
Change This:
To This:
Then in:
void ProtocolGame::sendMoveCreature(const Creature* creature, const Position& newPos, int32_t newStackPos, const Position& oldPos, int32_t oldStackPos, bool teleport)
Change This:
To This:
Then in:
void ProtocolGame::MoveUpCreature(NetworkMessage& msg, const Creature* creature, const Position& newPos, const Position& oldPos)
Change This:
To This:
And Change This:
To This:
And Change This:
To This:
Then in:
void ProtocolGame::MoveDownCreature(NetworkMessage& msg, const Creature* creature, const Position& newPos, const Position& oldPos)
Change This:
To This:
And Change This:
To This:
And right below that change this:
To This:
If you are using 0.3.6 then you will also need to change this:
To This:
And I think that is all for protocolgame.cpp.
Now in map.h you can change these numbers to whatever you desire:
Generally:
The maxClientViewport is how far the client can see.
and maxViewport is how far monsters see.
Then under map.cpp in the OTClient:
Change these:
To This:
If you extended your game-window and need creatures to "act" to you with the new distance, @Animera helped with code for that.
[Tutorial] Adding more tiles to game window - Updated 6/23/16
I think this should all work, if you have any issues PLEASE post them so I can correct problems with this tutorial.
If you have errors, please post both your protocolgame.cpp from TFS and map.cpp from OTClient. (So I can make sure you did it right before I look into it myself)
Update:
in const.h
Code:
#define NETWORKMESSAGE_MAXSIZE 24590
I was notified increasing this number could resolve some issues.
This is actually a bigger problem than it should be, because TFS doesn't use maxViewPort everywhere it should. So lets change that first!
I will do this for TFS 1.0, since it is basically the same edits for TFS 0.3.6, and maybe i'll learn something doing it for TFS 1.0.
Most of our edits (almost all of them) will be in protocalgame.cpp
First we need to edit:
bool ProtocolGame::canSee(int32_t x, int32_t y, int32_t z) const
Change This:
Code:
if ((x >= myPos.getX() - 8 + offsetz) && (x <= myPos.getX() + 9 + offsetz) &&
(y >= myPos.getY() - 6 + offsetz) && (y <= myPos.getY() + 7 + offsetz)) {
Code:
if ((x >= myPos.getX() - Map::maxClientViewportX + offsetz) && (x <= myPos.getX() + (Map::maxClientViewportX+1) + offsetz) &&
(y >= myPos.getY() - Map::maxClientViewportY + offsetz) && (y <= myPos.getY() + (Map::maxClientViewportY+1) + offsetz)) {
Then in:
void ProtocolGame::sendMapDescription(const Position& pos)
Change This:
Code:
GetMapDescription(pos.x - 8, pos.y - 6, pos.z, 18, 14, msg);
Code:
GetMapDescription(pos.x - Map::maxClientViewportX, pos.y - Map::maxClientViewportY, pos.z, (Map::maxClientViewportX+1)*2, (Map::maxClientViewportY+1)*2, msg);
Then in:
void ProtocolGame::sendMoveCreature(const Creature* creature, const Position& newPos, int32_t newStackPos, const Position& oldPos, int32_t oldStackPos, bool teleport)
Change This:
Code:
if (oldPos.y > newPos.y) { // north, for old x
msg.AddByte(0x65);
GetMapDescription(oldPos.x - 8, newPos.y - 6, newPos.z, 18, 1, msg);
} else if (oldPos.y < newPos.y) { // south, for old x
msg.AddByte(0x67);
GetMapDescription(oldPos.x - 8, newPos.y + 7, newPos.z, 18, 1, msg);
}
if (oldPos.x < newPos.x) { // east, [with new y]
msg.AddByte(0x66);
GetMapDescription(newPos.x + 9, newPos.y - 6, newPos.z, 1, 14, msg);
} else if (oldPos.x > newPos.x) { // west, [with new y]
msg.AddByte(0x68);
GetMapDescription(newPos.x - 8, newPos.y - 6, newPos.z, 1, 14, msg);
}
Code:
if (oldPos.y > newPos.y) { // north, for old x
msg.AddByte(0x65);
GetMapDescription(oldPos.x - Map::maxClientViewportX, newPos.y - Map::maxClientViewportY, newPos.z, (Map::maxClientViewportX+1)*2, 1, msg);
} else if (oldPos.y < newPos.y) { // south, for old x
msg.AddByte(0x67);
GetMapDescription(oldPos.x - Map::maxClientViewportX, newPos.y + (Map::maxClientViewportY+1), newPos.z, (Map::maxClientViewportX+1)*2, 1, msg);
}
if (oldPos.x < newPos.x) { // east, [with new y]
msg.AddByte(0x66);
GetMapDescription(newPos.x + (Map::maxClientViewportX+1), newPos.y - Map::maxClientViewportY, newPos.z, 1, (Map::maxClientViewportY+1)*2, msg);
} else if (oldPos.x > newPos.x) { // west, [with new y]
msg.AddByte(0x68);
GetMapDescription(newPos.x - Map::maxClientViewportX, newPos.y - Map::maxClientViewportY, newPos.z, 1, (Map::maxClientViewportY+1)*2, msg);
}
Then in:
void ProtocolGame::MoveUpCreature(NetworkMessage& msg, const Creature* creature, const Position& newPos, const Position& oldPos)
Change This:
Code:
if (newPos.z == 7) {
int32_t skip = -1;
GetFloorDescription(msg, oldPos.x - 8, oldPos.y - 6, 5, 18, 14, 3, skip); //(floor 7 and 6 already set)
GetFloorDescription(msg, oldPos.x - 8, oldPos.y - 6, 4, 18, 14, 4, skip);
GetFloorDescription(msg, oldPos.x - 8, oldPos.y - 6, 3, 18, 14, 5, skip);
GetFloorDescription(msg, oldPos.x - 8, oldPos.y - 6, 2, 18, 14, 6, skip);
GetFloorDescription(msg, oldPos.x - 8, oldPos.y - 6, 1, 18, 14, 7, skip);
GetFloorDescription(msg, oldPos.x - 8, oldPos.y - 6, 0, 18, 14, 8, skip);
Code:
if (newPos.z == 7) {
int32_t skip = -1;
GetFloorDescription(msg, oldPos.x - Map::maxClientViewportX, oldPos.y - Map::maxClientViewportY, 5, (Map::maxClientViewportX+1)*2, (Map::maxClientViewportY+1)*2, 3, skip); //(floor 7 and 6 already set)
GetFloorDescription(msg, oldPos.x - Map::maxClientViewportX, oldPos.y - Map::maxClientViewportY, 4, (Map::maxClientViewportX+1)*2, (Map::maxClientViewportY+1)*2, 4, skip);
GetFloorDescription(msg, oldPos.x - Map::maxClientViewportX, oldPos.y - Map::maxClientViewportY, 3, (Map::maxClientViewportX+1)*2, (Map::maxClientViewportY+1)*2, 5, skip);
GetFloorDescription(msg, oldPos.x - Map::maxClientViewportX, oldPos.y - Map::maxClientViewportY, 2, (Map::maxClientViewportX+1)*2, (Map::maxClientViewportY+1)*2, 6, skip);
GetFloorDescription(msg, oldPos.x - Map::maxClientViewportX, oldPos.y - Map::maxClientViewportY, 1, (Map::maxClientViewportX+1)*2, (Map::maxClientViewportY+1)*2, 7, skip);
GetFloorDescription(msg, oldPos.x - Map::maxClientViewportX, oldPos.y - Map::maxClientViewportY, 0, (Map::maxClientViewportX+1)*2, (Map::maxClientViewportY+1)*2, 8, skip);
And Change This:
Code:
else if (newPos.z > 7) {
int32_t skip = -1;
GetFloorDescription(msg, oldPos.x - 8, oldPos.y - 6, oldPos.getZ() - 3, 18, 14, 3, skip);
Code:
else if (newPos.z > 7) {
int32_t skip = -1;
GetFloorDescription(msg, oldPos.x - Map::maxClientViewportX, oldPos.y - Map::maxClientViewportY, oldPos.getZ() - 3, (Map::maxClientViewportX+1)*2, (Map::maxClientViewportY+1)*2, 3, skip);
And Change This:
Code:
//moving up a floor up makes us out of sync
//west
msg.AddByte(0x68);
GetMapDescription(oldPos.x - 8, oldPos.y - 5, newPos.z, 1, 14, msg);
//north
msg.AddByte(0x65);
GetMapDescription(oldPos.x - 8, oldPos.y - 6, newPos.z, 18, 1, msg);
Code:
//moving up a floor up makes us out of sync
//west
msg.AddByte(0x68);
GetMapDescription(oldPos.x - Map::maxClientViewportX, oldPos.y - (Map::maxClientViewportY-1), newPos.z, 1, (Map::maxClientViewportY+1)*2, msg);
//north
msg.AddByte(0x65);
GetMapDescription(oldPos.x - Map::maxClientViewportX, oldPos.y - Map::maxClientViewportY, newPos.z, (Map::maxClientViewportX+1)*2, 1, msg);
Then in:
void ProtocolGame::MoveDownCreature(NetworkMessage& msg, const Creature* creature, const Position& newPos, const Position& oldPos)
Change This:
Code:
//going from surface to underground
if (newPos.z == 8) {
int32_t skip = -1;
GetFloorDescription(msg, oldPos.x - 8, oldPos.y - 6, newPos.z, 18, 14, -1, skip);
GetFloorDescription(msg, oldPos.x - 8, oldPos.y - 6, newPos.z + 1, 18, 14, -2, skip);
GetFloorDescription(msg, oldPos.x - 8, oldPos.y - 6, newPos.z + 2, 18, 14, -3, skip);
Code:
//going from surface to underground
if (newPos.z == 8) {
int32_t skip = -1;
GetFloorDescription(msg, oldPos.x - Map::maxClientViewportX, oldPos.y - Map::maxClientViewportY, newPos.z, (Map::maxClientViewportX+1)*2, (Map::maxClientViewportY+1)*2, -1, skip);
GetFloorDescription(msg, oldPos.x - Map::maxClientViewportX, oldPos.y - Map::maxClientViewportY, newPos.z + 1, (Map::maxClientViewportX+1)*2, (Map::maxClientViewportY+1)*2, -2, skip);
GetFloorDescription(msg, oldPos.x - Map::maxClientViewportX, oldPos.y - Map::maxClientViewportY, newPos.z + 2, (Map::maxClientViewportX+1)*2, (Map::maxClientViewportY+1)*2, -3, skip);
And Change This:
Code:
//going further down
else if (newPos.z > oldPos.z && newPos.z > 8 && newPos.z < 14) {
int32_t skip = -1;
GetFloorDescription(msg, oldPos.x - 8, oldPos.y - 6, newPos.z + 2, 18, 14, -3, skip);
Code:
//going further down
else if (newPos.z > oldPos.z && newPos.z > 8 && newPos.z < 14) {
int32_t skip = -1;
GetFloorDescription(msg, oldPos.x - Map::maxClientViewportX, oldPos.y - Map::maxClientViewportY, newPos.z + 2, (Map::maxClientViewportX+1)*2, (Map::maxClientViewportY+1)*2, -3, skip);
And right below that change this:
Code:
//moving down a floor makes us out of sync
//east
msg.addByte(0x66);
GetMapDescription(oldPos.x + 9, oldPos.y - 7, newPos.z, 1, 14, msg);
//south
msg.addByte(0x67);
GetMapDescription(oldPos.x - 8, oldPos.y + 7, newPos.z, 18, 1, msg);
Code:
//moving down a floor makes us out of sync
//east
msg.addByte(0x66);
GetMapDescription(oldPos.x + Map::maxClientViewportX+1, oldPos.y - (Map::maxClientViewportY+1), newPos.z, 1, ((Map::maxClientViewportY+1)*2), msg);
//south
msg.addByte(0x67);
GetMapDescription(oldPos.x - Map::maxClientViewportX, oldPos.y + (Map::maxClientViewportY+1), newPos.z, ((Map::maxClientViewportX+1)*2), 1, msg);
Code:
void ProtocolGame::AddMapDescription(NetworkMessage_ptr msg, const Position& pos)
{
msg->put<char>(0x64);
msg->putPosition(player->getPosition());
GetMapDescription(pos.x - 8, pos.y - 6, pos.z, 18, 14, msg);
}
Code:
void ProtocolGame::AddMapDescription(NetworkMessage_ptr msg, const Position& pos)
{
msg->put<char>(0x64);
msg->putPosition(player->getPosition());
GetMapDescription(pos.x - Map::maxClientViewportX, pos.y - Map::maxClientViewportY, pos.z, (Map::maxClientViewportX+1)*2, (Map::maxClientViewportY+1)*2, msg);
}
And I think that is all for protocolgame.cpp.
Now in map.h you can change these numbers to whatever you desire:
Code:
static const int32_t maxViewportX = 11; //min value: maxClientViewportX + 1
static const int32_t maxViewportY = 11; //min value: maxClientViewportY + 1
static const int32_t maxClientViewportX = 8;
static const int32_t maxClientViewportY = 6;
Generally:
The maxClientViewport is how far the client can see.
and maxViewport is how far monsters see.
Then under map.cpp in the OTClient:
Change these:
Code:
void Map::resetAwareRange()
{
AwareRange range;
range.left = 8;
range.top = 6;
range.bottom = 7;
range.right = 9;
setAwareRange(range);
}
Code:
{
AwareRange range;
range.left = 8; //Change this to = maxClientViewportX
range.top = 6; //Change this to = maxClientViewportY
range.bottom = range.top+1;
range.right = range.left+1;
setAwareRange(range);
}
If you extended your game-window and need creatures to "act" to you with the new distance, @Animera helped with code for that.
[Tutorial] Adding more tiles to game window - Updated 6/23/16
I think this should all work, if you have any issues PLEASE post them so I can correct problems with this tutorial.
If you have errors, please post both your protocolgame.cpp from TFS and map.cpp from OTClient. (So I can make sure you did it right before I look into it myself)
Last edited: