SRL Archive - OSR Help

GetInnerTPABound


riwu

2012-11-03 07:54:53

I'm trying to figure out how to get the red box in the image. One way would be to get the TPA of the black pixels and try to find the 'inner bound', and another way would be to get the pixels of the white outline and clear those excess ones at the top.
I have no idea how to get the 'inner bound' of the black TPA, but for clearing i'm thinking of using (after sorting by size) ATPA[1]'s nearest point to center to remove the upper points (taking compass into consideration), but that may not work for some parts of the area in Ghorrock though.

Any better ideas? Or how to find the TPA innerbound?

Kasi

2012-11-03 08:11:28

RAaSTPAEx(TPA, W, H);

Depending on the angle of the compass, made the width frequent, and the height less frequent, you could try RAaSTPAEx(TPA, 3, 7) or something along those lines. then split the TPA left, SplitTPAEx(TPA, 4, 6); it might not be perfect but in theory it should work?

just keep trying different scenarios, and different numbers

riwu

2012-11-03 08:16:09

From: Kasi
RAaSTPAEx(TPA, W, H);

Depending on the angle of the compass, made the width frequent, and the height less frequent, you could try RAaSTPAEx(TPA, 3, 7) or something along those lines. then split the TPA left, SplitTPAEx(TPA, 4, 6); it might not be perfect but in theory it should work?

just keep trying different scenarios, and different numbers

Isn't RAaSTPAEx something like TPAtoATPAEx + MiddleTPA? So i'll end up with a few points on random positions? How would that work?

Kasi

2012-11-03 08:20:06

From: riwu
Isn't RAaSTPAEx something like TPAtoATPAEx + MiddleTPA? So i'll end up with a few points on random positions? How would that work?


because instead of finding all the grey color, it'll find the grey color and remove points too close together, Split TPA works in boxes. if you place the points too far apart from each other they will be split into different boxes, i can attempt to make that thing for you later today if you still dont understand

slushpuppy

2012-11-03 08:20:19

http://villavu.com/forum/showthread.php?t=76467

I wouldn't recommend you use that directly, but the logic should work for you.

Kasi

2012-11-03 08:24:29

From: slushpuppy
http://villavu.com/forum/showthread.php?t=76467

I wouldn't recommend you use that directly, but the logic should work for you.


That seems quite nice also :D

riwu

2012-11-03 10:47:33

From: Kasi
because instead of finding all the grey color, it'll find the grey color and remove points too close together, Split TPA works in boxes. if you place the points too far apart from each other they will be split into different boxes, i can attempt to make that thing for you later today if you still dont understand

So i'll find the grey ground colors, then RAaSTPAEx, and i would end up with something like 1 point in the red box, and another 2 or more points in the narrow path? Still don't get it :S

From: slushpuppy
http://villavu.com/forum/showthread.php?t=76467

I wouldn't recommend you use that directly, but the logic should work for you.

Thanks.
What does
ArcTan2(o.y - pt.y, o.x - pt.x) * 180 / Pi;
do?

ArcTan2 will return inverse of angle alpha, given the opposite and adjacent length? And then you check whether it is within an empty array degArray? I'm confused what it does :confused:

Brandon

2012-11-03 10:51:48

What? It returns the actual angle not the inverse :S

Then it converts it to radians.

Brandon

2012-11-03 11:06:55

Change the coords and colours and it should work. Perhaps even use a different CTS. I did this based off that picture on the OP.


{$I SRL/SRL.Simba}
{$I SRL/SRL/Misc/Debug.Simba}

Function GetBoxMinimap: TBox;
var
TPA: TPointArray;
ATPA: T2DPointArray;
Begin
FindColorsTolerance(TPA, 7433839, MMBox.X1, MMBox.Y1, MMBox.X2, MMBox.Y2, 25);
If (Length(TPA) < 1) Then Exit;

ATPA := FloodFilLTPA(TPA);
If (Length(ATPA) < 1) Then Exit;
SortATPAFromFirstPoint(ATPA, Point(300, 300)); //Middle Of MM.
Result := GetTPABounds(ATPA[0]);
End;

var
F: TBox;
begin
SetupSRL;
F := GetBoxMinimap;
MMouse(F.X1, F.Y1, 0, 0);
Wait(1500);
MMouse(F.X2, F.Y2, 0, 0);
end.

riwu

2012-11-03 22:36:41

From: Brandon
What? It returns the actual angle not the inverse :S

Then it converts it to radians.

Ugg yeah, dunno what i was talking.
But the degArray is an empty array of length 1 when 'foundIndex := inArray(tmp,degArray)' is called?

From: Brandon
Change the coords and colours and it should work. Perhaps even use a different CTS. I did this based off that picture on the OP.


{$I SRL/SRL.Simba}
{$I SRL/SRL/Misc/Debug.Simba}

Function GetBoxMinimap: TBox;
var
TPA: TPointArray;
ATPA: T2DPointArray;
Begin
FindColorsTolerance(TPA, 7433839, MMBox.X1, MMBox.Y1, MMBox.X2, MMBox.Y2, 25);
If (Length(TPA) < 1) Then Exit;

ATPA := FloodFilLTPA(TPA);
If (Length(ATPA) < 1) Then Exit;
SortATPAFromFirstPoint(ATPA, Point(300, 300)); //Middle Of MM.
Result := GetTPABounds(ATPA[0]);
End;

var
F: TBox;
begin
SetupSRL;
F := GetBoxMinimap;
MMouse(F.X1, F.Y1, 0, 0);
Wait(1500);
MMouse(F.X2, F.Y2, 0, 0);
end.

What does FloodFillTPA do? Difference between it and SplitTPA/TPAtoATPA?
No time to ponder through those 100 lines of code now so would you mind giving me a brief description? :)

Anyway i tried the code, the result is almost there:
May be able to fix it if i understand FloodFillTPA.


I kept thinking about the black pixel and white outline earlier on, totally forget about the grey ground.
Just tried using SplitTPA to get the larger path first, then
SortTPAByX(ATPA[0], true);
TPAtoATPAExWrap(ATPA[0], 40, 50, ATPA);
Came up with what i wanted, but will be another hour of work to make it compass compatible and work with different areas..

Thanks for the help, repped :)

Gu3st...

2012-11-03 23:01:16

Nice work guys, love the teamwork :) What are you working on..?

riwu

2012-11-03 23:07:06

From: Zyt3x
Nice work guys, love the teamwork :) What are you working on..?

My Waterfiend script. I'm trying to keep the player to 1 area because if it wander too far to other parts of the map the Wf will turn aggressive again.

Any idea what FloodFillTPA/FindGapsTPA does and the difference between it and SplitTpa/TPAtoATPA?

Gu3st...

2012-11-03 23:10:46

https://docs.villavu.com/simba/scriptref/tpa.html

CTRL + F "FloodFill" or "FindGaps"

riwu

2012-11-03 23:18:33

From: Zyt3x
https://docs.villavu.com/simba/scriptref/tpa.html

CTRL + F "FloodFill" or "FindGaps"

Yeah i've searched that and searched on forum/google as well. Doesn't describe much at all. (mostly just give the function name and parameters..)

Guess my best bet would be https://github.com/MerlijnWajer/Simba/blob/master/Units/MMLCore/tpa.pas. Need to find another time to slowly read through the code…

slushpuppy

2012-11-04 00:47:28

From: riwu
Ugg yeah, dunno what i was talking.
But the degArray is an empty array of length 1 when 'foundIndex := inArray(tmp,degArray)' is called?


Essentially my snippet searches for white borders in a 360 degree arc. then consolidates the result to return an area as small as possible