SRL Archive - News and General

Finding Colour on a tile?


HarryJames

2011-04-14 07:45:17

Is it possible to have a TTile, and then search for a colour on the bounds of that tile?
It'd have to be reflection though.

I'm trying this as a means of getting around the lack of model support, for objects that have holes in them, or similar. (things like railings etc).

**BANNED The Man

2011-04-14 07:51:23

So you want to search for a colour in a tile with reflection… no.

JuKKa

2011-04-14 07:55:08


Var
Tile: TTile;
MSPoint: TPoint;

Begin
Tile := Tile(3030, 3030); //example
MSPoint := TileToMS(Tile, 0);
FindColorsTolerance(TPA, Color, MSPoint.X - 10, MSPoint.Y - 10, MSPoint.X + 10, MSPoint.Y + 10, Tolerance);
End.

Thats how I would do it

HarryJames

2011-04-14 07:57:27

Thanks JuKKa, I presume that the MM would have to be set to the highest angle for this to work though, without incorporating some harder math to work out the offset due to height etc.

KingKong

2011-04-14 08:29:40

This should be better since it takes top left and bottom right of tile:
Var
TPA: TPointArray;
Topleft, Downright: TPoint;
Begin
TopLeft := TileToMSEx(Tile(69, 69), 0, 0, 0);
Downright := TileToMSEx(Tile(69, 69), 1, 1, 0);
FindColorsTolerance(TPA, Color, TopLeft.x, Topleft.y, DownRight.x, Downright.y, 15);
End.

**BANNED The Man

2011-04-14 08:43:14

FindColorsSpiralTolerance
iirc

Then set your boundaries :)

Flight

2011-04-14 10:35:39

From: HarryJames
…for objects that have holes in them, or similar. (things like railings etc).


You can get an object at a certain tile whether it be interactable / ground object / wall object / or decoration (I believe). Basically, if the object has any kind of a right-click menu at all (even 'examine' only) then it's interactable, so the 'railings' you're referring to might be a ground object because they're placed on the base tile, like you said, but doesn't have a right-click menu therefore it's not interactable.

Now if you're determined to use color inside that tile's box then I'm sure you could look at SRL's method for converting the Reflection tile to your screen position in the form of a box.

function TileToMSEx(tile: TTile; offx, offy : extended; height : integer) : TPoint;
var
pixelX, pixelY, pixelZ: extended;
begin
pixelX:= (tile.x - SmartGetFieldInt(0,hook_static_BaseX) + offX) * 512.0;
pixelY:= GetTileHeight(tile) - height;
pixelZ:= (tile.y - SmartGetFieldInt(0,hook_static_BaseY) + offY) * 512.0;
Result := World3DToScreen(pixelX, pixelY, pixelZ);
if not PointInBox(Result, IntToBox(MSX1, MSY1, MSX2, MSY2))then
begin
Result.x := -1;
Result.y := -1;
end;
end;

That returns a point which would be the absolute center of your tile. You'd have to look look through "World3DToScreen" or whatever to find the distance from that center point to the edge of the tile (in any direction), this will give you the radius and you can use that to find the box's XS/YS and XE/YE. Then just search within those parameters for your color.

I'm sorry if I'm a bit unclear, but I am trying to explain it as straight-forward as possible.