SRL Archive - Bugs

MSToTile


Coh3n

2010-12-14 17:22:51

Was just wondering if this would be possible. I know TileToMS was a huge pain, but would MSToTile be the same? If you don't understand, I just want to input a point on the main screen and have the function return the tile it's on, if possible. :)

Nava2

2010-12-14 17:23:28

Unless you know the height, I cannot see it being remotely possible.

Coh3n

2010-12-14 17:24:32

From: Nava2
Unless you know the height, I cannot see it being remotely possible.

Awe, lame! Thanks though. :)

TRiLeZ

2010-12-14 17:42:49

You could loop through every tile on the screen, and calculate the point, and which ever point is closest the the point you are converting, is the point of the tile that the point you are converting is closest to.

MylesMadness

2010-12-14 17:43:50

From: TRiLeZ
You could loop through every tile on the screen, and calculate the point, and which ever point is closest the the point you are converting, is the point of the tile that the point you are converting is closest to.
That doesn't sound slow or anything…

Wizzup?

2010-12-14 17:55:17

From: MylesMadness
That doesn't sound slow or anything…


Not particularly, no. Considering there really aren't that many tiles around you. (Unless getting the tiles takes a while)

lordsaturn

2010-12-14 18:17:06

function MSToTile(Pt: TPoint): TTile;
var
loc, aTile: TTile;
aPt: TPoint;
lowDist, tmpDist, x, y, maxX, maxY: integer;
begin
Result := Point(-1, -1);
//if not PointOnMS(Pt) then Exit;
lowDist := -1;
loc := GetMyPos;
maxX := 10;
maxY := -10;
for x := -10 to maxX do //adjust boundaries depending on camera angle
for y := 10 downto maxY do //yaxis inverted
begin
aTile := Tile(loc.x + x, loc.y + y);
aPt := TileToMS(aTile, 10); //adjust height
if (aPt.x > -1) then //saves time rather than doing TileOnMS
begin
if (lowDist = -1) then
begin
maxX := x*-1; //+1 to be safe?
maxY := y*-1; //-1 to be safe?
lowDist := tmpDist;
Result := aTile;
end else
if (tmpDist < lowDist) then
begin
lowDist := tmpDist;
Result := aTile;
end;
end;
end;
end;

BenLand100

2010-12-14 18:37:08

This would be rather easy to do, although its slightly different than other calculations and afaik no one has recent hooks for it. Remember, the client does it all the time when you click. You just need to figure out how.

Coh3n

2010-12-14 19:42:36

Awesome, I'm glad to know it's possible.

@lordsaturn
Did you quickly write that up, or have you actually used that before? :)

lordsaturn

2010-12-14 21:11:44

From: Coh3n
Awesome, I'm glad to know it's possible.

@lordsaturn
Did you quickly write that up, or have you actually used that before? :)


I wrote it in the quick reply box. Like benland said, use the maths and not the function I wrote.

Coh3n

2010-12-14 21:40:57

Okay thanks guys. :)

Quickmarch

2010-12-15 06:15:29


private void screenToTile_convert(int[] ai) {
SDToolkit toolkit = ((SDToolkit) getClient().getCurrentToolkit());
SDViewport internalViewport = toolkit.getInternalViewport();

float i = ai[0] - internalViewport.getOffsetX();
float j = ai[1] - internalViewport.getOffsetY();
float k = ai[2] - internalViewport.getOffsetZ();

ai[0] = (int) ((internalViewport.getXX() * i) + (internalViewport.getYX() * j) + (internalViewport.getZX() * k));
ai[1] = (int) ((internalViewport.getXY() * i) + (internalViewport.getYY() * j) + (internalViewport.getZY() * k));
ai[2] = (int) ((internalViewport.getXZ() * i) + (internalViewport.getYZ() * j) + (internalViewport.getZZ() * k));
}

public Point screenToTile(int screenX, int screenY) {
SDToolkit toolkit = ((SDToolkit) getClient().getCurrentToolkit());

int minZ = toolkit.getMinZ();
int minX = ((screenX - 260) * minZ) / 512;
int minY = ((screenY - 171) * minZ) / 512;

int maxZ = toolkit.getMaxZ();
int maxX = ((screenX - 260) * maxZ) / 512;
int maxY = ((screenY - 171) * maxZ) / 512;

int minXYZ[] = {
minX, minY, minZ
};
screenToTile_convert(minXYZ);
int maxXYZ[] = {
maxX, maxY, maxZ
};
screenToTile_convert(maxXYZ);
float f = 0.0F;
int j8 = maxXYZ[0] - minXYZ[0];
int i9 = maxXYZ[1] - minXYZ[1];
int k9 = maxXYZ[2] - minXYZ[2];

int planeX = -1;
int planeY = -1;
for (; f < 1.0F; f = (float) ((double) f + 0.01D)) {
int pixelX = (int) ((float) minXYZ[0] + (float) j8 * f);
planeX = pixelX >> 9;

int pixelY = (int) (f * (float) k9 + (float) minXYZ[2]);
planeY = pixelY >> 9;

if (planeX <= 0 || planeY <= 0 || planeX >= 104 || planeY >= 104) {
continue;
}
int plane = getCurrentPlane();
if (plane < 3 && (getClient().getGroundData()[1][planeX][planeY] & 2) != 0) {
plane++;
}
if ((float) getTileHeight(pixelX, pixelY) >= (float) minXYZ[1] + (float) i9 * f) {
continue;
}
break;
}
return new Point(planeX, planeY);
}

Taken from the client about 4 months ago (i've just tested it just now - it should work). It's in java so if you need help converting it, just pm me/contact me on msn.

Bad Boy JH

2010-12-15 06:57:15

what about something like
GetHeight(Point, Tile, OffX, Offy)

just an idea, could be useful for development (gets heights of objects)

BenLand100

2010-12-15 10:10:46

From: Bad Boy JH
what about something like
GetHeight(Point, Tile, OffX, Offy)

just an idea, could be useful for development (gets heights of objects)

You all should already have code to get the tile height of a tile in whatever function converts tile coordinates to screen coordinates. Just pull it out.

Coh3n

2010-12-15 14:49:20

From: Quickmarch

private void screenToTile_convert(int[] ai) {
SDToolkit toolkit = ((SDToolkit) getClient().getCurrentToolkit());
SDViewport internalViewport = toolkit.getInternalViewport();

float i = ai[0] - internalViewport.getOffsetX();
float j = ai[1] - internalViewport.getOffsetY();
float k = ai[2] - internalViewport.getOffsetZ();

ai[0] = (int) ((internalViewport.getXX() * i) + (internalViewport.getYX() * j) + (internalViewport.getZX() * k));
ai[1] = (int) ((internalViewport.getXY() * i) + (internalViewport.getYY() * j) + (internalViewport.getZY() * k));
ai[2] = (int) ((internalViewport.getXZ() * i) + (internalViewport.getYZ() * j) + (internalViewport.getZZ() * k));
}

public Point screenToTile(int screenX, int screenY) {
SDToolkit toolkit = ((SDToolkit) getClient().getCurrentToolkit());

int minZ = toolkit.getMinZ();
int minX = ((screenX - 260) * minZ) / 512;
int minY = ((screenY - 171) * minZ) / 512;

int maxZ = toolkit.getMaxZ();
int maxX = ((screenX - 260) * maxZ) / 512;
int maxY = ((screenY - 171) * maxZ) / 512;

int minXYZ[] = {
minX, minY, minZ
};
screenToTile_convert(minXYZ);
int maxXYZ[] = {
maxX, maxY, maxZ
};
screenToTile_convert(maxXYZ);
float f = 0.0F;
int j8 = maxXYZ[0] - minXYZ[0];
int i9 = maxXYZ[1] - minXYZ[1];
int k9 = maxXYZ[2] - minXYZ[2];

int planeX = -1;
int planeY = -1;
for (; f < 1.0F; f = (float) ((double) f + 0.01D)) {
int pixelX = (int) ((float) minXYZ[0] + (float) j8 * f);
planeX = pixelX >> 9;

int pixelY = (int) (f * (float) k9 + (float) minXYZ[2]);
planeY = pixelY >> 9;

if (planeX <= 0 || planeY <= 0 || planeX >= 104 || planeY >= 104) {
continue;
}
int plane = 0;
if (plane < 3 && (getClient().getGroundData()[1][planeX][planeY] & 2) != 0) {
plane++;
}
if ((float) getTileHeight(pixelX, pixelY) >= (float) minXYZ[1] + (float) i9 * f) {
continue;
}
break;
}
return new Point(planeX, planeY);
}

Taken from the client about 4 months ago (i've just tested it just now - it should work). It's in java so if you need help converting it, just pm me/contact me on msn.



Very nice, thank you! :)

I'll work on converting it when I have more time.

Gu3st...

2010-12-15 15:35:06

From: Coh3n
Very nice, thank you! :)

I'll work on converting it when I have more time.
You accidentally quoted lordsaturn too in your post :p

Btw, What are you planning, Coh3n?

Coh3n

2010-12-15 15:37:52

From: Zyt3x
You accidentally quoted lordsaturn too in your post :p

Btw, What are you planning, Coh3n?

Not exactly sure how that happened. :o

It's just an idea about a way to improve MSI's tracking. I'll make a post in the hybrid thread later today.

TRiLeZ

2010-12-15 19:54:53

From: Quickmarch

private void screenToTile_convert(int[] ai) {
SDToolkit toolkit = ((SDToolkit) getClient().getCurrentToolkit());
SDViewport internalViewport = toolkit.getInternalViewport();

float i = ai[0] - internalViewport.getOffsetX();
float j = ai[1] - internalViewport.getOffsetY();
float k = ai[2] - internalViewport.getOffsetZ();

ai[0] = (int) ((internalViewport.getXX() * i) + (internalViewport.getYX() * j) + (internalViewport.getZX() * k));
ai[1] = (int) ((internalViewport.getXY() * i) + (internalViewport.getYY() * j) + (internalViewport.getZY() * k));
ai[2] = (int) ((internalViewport.getXZ() * i) + (internalViewport.getYZ() * j) + (internalViewport.getZZ() * k));
}

public Point screenToTile(int screenX, int screenY) {
SDToolkit toolkit = ((SDToolkit) getClient().getCurrentToolkit());

int minZ = toolkit.getMinZ();
int minX = ((screenX - 260) * minZ) / 512;
int minY = ((screenY - 171) * minZ) / 512;

int maxZ = toolkit.getMaxZ();
int maxX = ((screenX - 260) * maxZ) / 512;
int maxY = ((screenY - 171) * maxZ) / 512;

int minXYZ[] = {
minX, minY, minZ
};
screenToTile_convert(minXYZ);
int maxXYZ[] = {
maxX, maxY, maxZ
};
screenToTile_convert(maxXYZ);
float f = 0.0F;
int j8 = maxXYZ[0] - minXYZ[0];
int i9 = maxXYZ[1] - minXYZ[1];
int k9 = maxXYZ[2] - minXYZ[2];

int planeX = -1;
int planeY = -1;
for (; f < 1.0F; f = (float) ((double) f + 0.01D)) {
int pixelX = (int) ((float) minXYZ[0] + (float) j8 * f);
planeX = pixelX >> 9;

int pixelY = (int) (f * (float) k9 + (float) minXYZ[2]);
planeY = pixelY >> 9;

if (planeX <= 0 || planeY <= 0 || planeX >= 104 || planeY >= 104) {
continue;
}
int plane = 0;
if (plane < 3 && (getClient().getGroundData()[1][planeX][planeY] & 2) != 0) {
plane++;
}
if ((float) getTileHeight(pixelX, pixelY) >= (float) minXYZ[1] + (float) i9 * f) {
continue;
}
break;
}
return new Point(planeX, planeY);
}

Taken from the client about 4 months ago (i've just tested it just now - it should work). It's in java so if you need help converting it, just pm me/contact me on msn.


Do you know where you would find this code in the modern day client?

Quickmarch

2010-12-16 02:27:19

From: TRiLeZ
Do you know where you would find this code in the modern day client?


Search for the string " -> <col=ff9040>".

The method (I think) is used for compiling the options for the choose-option dialog. They've also changed the structure slightly but in essence it's exactly the same as it was 3 or 4 months ago.