[Tutorial] Adding more tiles to game window - Updated 7/6/2018

Flatlander

Species Developer
Joined
Feb 17, 2009
Messages
2,458
Best answers
3
Reaction score
1,284
Location
Texas
This is a tutorial showing how to add more tiles to the OTClient window. (Make the screen bigger)

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)) {
To This:
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);
To This:
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);
}
To This:
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);
To This:
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);
To This:
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);
To This:
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);
To This:
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);
To 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 - 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);
To This:
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);
If you are using 0.3.6 then you will also need to change this:
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);
}
To This:
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);
}
To This:
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:

Snooby

Active Member
Joined
Jul 2, 2014
Messages
364
Best answers
0
Reaction score
83
Location
Sweden
Could you post an image of how it looks? If you have a preview server to run it :p

Also, is it possible to increase the screen by how many tiles as you wish? That way you could increase it enough so it'll just a little more than playable then disable the possibility to stretch the screen, would be super quality instead of stretched sprites :p
 
OP
Flatlander

Flatlander

Species Developer
Joined
Feb 17, 2009
Messages
2,458
Best answers
3
Reaction score
1,284
Location
Texas
Could you post an image of how it looks? If you have a preview server to run it :p

Also, is it possible to increase the screen by how many tiles as you wish? That way you could increase it enough so it'll just a little more than playable then disable the possibility to stretch the screen, would be super quality instead of stretched sprites :p
Yep, You can make it as many tiles as you want and just set the default zoom on the OTClient as far away or close as you want.

I don't know why you'd want to send more tiles than you can see though... thats just extra work the server has to do that isn't being used.
 

lord vortexx

Member
Joined
Dec 14, 2008
Messages
92
Best answers
0
Reaction score
3
I made the tutorial form , but it happened that



used as follows
static const int32_t maxViewportX = 18; //min value: maxClientViewportX + 1
static const int32_t maxViewportY = 18; //min value: maxClientViewportY + 1
static const int32_t maxClientViewportX = 14;
static const int32_t maxClientViewportY = 12;
 
OP
Flatlander

Flatlander

Species Developer
Joined
Feb 17, 2009
Messages
2,458
Best answers
3
Reaction score
1,284
Location
Texas
I made the tutorial form , but it happened that



used as follows
static const int32_t maxViewportX = 18; //min value: maxClientViewportX + 1
static const int32_t maxViewportY = 18; //min value: maxClientViewportY + 1
static const int32_t maxClientViewportX = 14;
static const int32_t maxClientViewportY = 12;
Did you also change the otclient and recompile it? and also which version of TFS are you using?

And can you provide your protocolgame.cpp from TFS and map.cpp from otclient?
 
Last edited:
OP
Flatlander

Flatlander

Species Developer
Joined
Feb 17, 2009
Messages
2,458
Best answers
3
Reaction score
1,284
Location
Texas
Working Niceeeeeeee

Glad it works! I literally didn't test it, I went to the TFS github, and opened protocolgame.cpp and searched for " 8" and each line that was related to sending tiles to the client I changed, lol thats basically it.
 

Huntre

Member
Joined
Mar 22, 2011
Messages
70
Best answers
1
Reaction score
6
do not have the 0.3.6

void ProtocolGame::sendMapDescription(const Position& pos)
 

Animera

* * * * *
Joined
Dec 9, 2008
Messages
2,307
Best answers
1
Reaction score
424
Location
ANIMERA.ONLINE
@Flatlander

I am really happy with you in our community, you keep thinking outside the box and keep a lot of people amazed with your ideas or works... cannot wait the day when i got coding skills like you do hehehe...

really proud of what your are contributing to the community! Great job.
 

lord vortexx

Member
Joined
Dec 14, 2008
Messages
92
Best answers
0
Reaction score
3
I am using TFS 1.0 to the latest commit the OtClient.


I had to do this
static const int32_t maxClientViewportX = 15;
static const int32_t maxClientViewportY = 11;
static const int32_t maxClientViewportX2 = 14;
static const int32_t maxClientViewportY2 = 12;
and everywhere they were
Map::maxClientViewportX and Map::maxClientViewportY switched to Map::maxClientViewportX2 and Map::maxClientViewportY2

and in map.cpp

range.left = 14; //Change this to = maxClientViewportX
range.top = 12; //Change this to = maxClientViewportY
range.bottom = range.top+1;
range.right = range.left+1;
Thus apparently worked!
 
OP
Flatlander

Flatlander

Species Developer
Joined
Feb 17, 2009
Messages
2,458
Best answers
3
Reaction score
1,284
Location
Texas
do not have the 0.3.6

void ProtocolGame::sendMapDescription(const Position& pos)
Thanks! I updated the topic with the following:

If you are using 0.3.6 then you will also need to change this:
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);
}
To This:
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);
}
 
OP
Flatlander

Flatlander

Species Developer
Joined
Feb 17, 2009
Messages
2,458
Best answers
3
Reaction score
1,284
Location
Texas
I am using TFS 1.0 to the latest commit the OtClient.


I had to do this


and everywhere they were
Map::maxClientViewportX and Map::maxClientViewportY switched to Map::maxClientViewportX2 and Map::maxClientViewportY2

and in map.cpp



Thus apparently worked!
Can you let me know WHY you had to do that?
 

Pawcio6

Member
Joined
Sep 26, 2009
Messages
115
Best answers
0
Reaction score
3
Im using 0.3.6 and i changed maxClientViewportX to 14 and maxClientViewportY to 12 recompiled tfs and otclient but when i enter to game tile size on screen are same but i can see in battle window and names and health bars on screen of creatures that are few tiles further. That creature whose i dont see on screen I can target on battle and kill it with target spell.I tried to change gameinterface.lua but it dont help should i change something else?

Edit
found in uigamemap.lua
Code:
gameMap:setVisibleDimension({width = 29, height = 11})
now i have more tiles on screen but when i try to make height more than 11 its still 11 on screen and width make smaller its some kind of limit? when height is 11, width works fine even 40+
 
Last edited:
OP
Flatlander

Flatlander

Species Developer
Joined
Feb 17, 2009
Messages
2,458
Best answers
3
Reaction score
1,284
Location
Texas
Im using 0.3.6 and i changed maxClientViewportX to 14 and maxClientViewportY to 12 recompiled tfs and otclient but when i enter to game tile size on screen are same but i can see in battle window and names and health bars on screen of creatures that are few tiles further. That creature whose i dont see on screen I can target on battle and kill it with target spell.I tried to change gameinterface.lua but it dont help should i change something else?

Edit
found in uigamemap.lua
Code:
gameMap:setVisibleDimension({width = 29, height = 11})
now i have more tiles on screen but when i try to make height more than 11 its still 11 on screen and width make smaller its some kind of limit? when height is 11, width works fine even 40+
I'm not exactly sure, but you can hold down CTRL and use - or = (Next to backspace) to zoom in and out,

Can you post a picture of how it looks? What happens if you do more than 11 height?
 

Pawcio6

Member
Joined
Sep 26, 2009
Messages
115
Best answers
0
Reaction score
3
my bad its only happens on vievmode 0 changed mode to 1 and it works fine thanks
 

Colors

Joined
Mar 22, 2013
Messages
934
Best answers
3
Reaction score
250
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);
}
To This:
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);
}
Those are the only changes that I need to make in the OTC? Because is not working for me... I still see the normal window size in OTC, but the normal client debugs.

@EDIT: I'm using latest version of OTC and TFS.
 
Last edited:
OP
Flatlander

Flatlander

Species Developer
Joined
Feb 17, 2009
Messages
2,458
Best answers
3
Reaction score
1,284
Location
Texas
Well it sends more tiles, but you will have to choose what you want your zoom to be.

if you hold down CTRL and press = and - (Next to the backspace) you will zoom out and zoom in.

You can change stuff related to the zooming without editing source.

You do this in gameinterface.lua.
 
Top