SRL Archive - OSR Help

PointInTPA


Brandon

2012-05-05 03:21:39

I use:

if (PointInTPA(Point(MSCX, MSCY), TPA)) then
writeln('Point Is In TPA');

Yet it never writes anything.. yet according to this debug picture.. the point is in the TPA:


Seeing as MSCX, MSCY is the player's position and Red is a Debug colour of Smart_DrawDots(TPA), my character is clearly within the TPA..

Now if I do:

if (PointInBox(Point(MSCX, MSCY), GetTPABounds(TPA))) then
writeln('Point is within the TPA');

it writes it every single time.. Not only that, if I print the entire TPA, the MSCX, MSCY is also in there.. I don't understand why :S

John

2012-05-05 03:39:08

maybe…
if (PointInTPA(Point(MSCX, MSCY), TPA)) then
begin
writeln('Point Is In TPA');
end;


?? Just a guess

Brandon

2012-05-05 03:43:35

^ That's the same thing.. Also there is a problem with the FindTPAInTPA as well.. I make a TPA of an object on the mainscreen.. I debug it, it shows up perfectly fine and draws 100% of the time.. I do:

findTPAInTPA(Object, TPAFromBox(IntToBox(MSX1, MSY1, MSX2, MSY2)); and it returns false..

Don't know why but that function says that the tpa is not found in the mainscreen when clearly it's debugging it flawlessly.

This says it is though:

Function TPAInTPA(Search, EntireTPA: TPointArray): Boolean;
var
NotIn, IsIn, I, L: Integer;
begin
NotIn:= 0; IsIn:= 0;
L:= Length(Search) - 1;
For I:= 0 To L do
begin
if (PointInBox(Search[I], GetTPABounds(EntireTPA))) then
Inc(IsIn)
else
Inc(NotIn);
end;

Result:= NotIn < IsIn;
end;

But the above is extremely slow..

euphemism

2012-05-05 03:44:41

As far as I know, 'PointInTPA' checks to see if the given TPoint is within the given TPointArray, not if a given TPoint falls within the bounds of the given TPointArray.

Brandon

2012-05-05 03:47:20

From: euphemism
As far as I know, 'PointInTPA' checks to see if the given TPoint is within the given TPointArray, not if a given TPoint falls within the bounds of the given TPointArray.


But if I print that TPA, the TPoint "IS" in the TPA.. which doesn't make sense if it's returning false..

if I do:


For I:= 0 To High(TPA) do
begin
if (TPA[I] = Point(MSCX, Point(MSCY)) then
Result:= True;
end;

The above returns true all the time!

Home

2012-05-05 04:41:14

From: ggzz
But if I print that TPA, the TPoint "IS" in the TPA.. which doesn't make sense if it's returning false..

if I do:


For I:= 0 To High(TPA) do
begin
if (TPA[I] = Point(MSCX, Point(MSCY)) then
Result:= True;
end;

The above returns true all the time!



Like Euph said, it will check if the Point exists in TPointArray, not if it's in the bounds.

Above doesn't compile and for me it doesn't always return True.

~Home

JuKKa

2012-05-05 05:14:48

PointInBox(); then eighter use GetTPABounds() or use PointToBox(); For "getTPABounds" i think u need a "aTPA" for it to work correctly.

Im writing this in the morning and still bit sleepy ;)

masterBB

2012-05-05 05:53:31

From tpa.pas:
{/\
Results true if a point is in a TPointArray.
Notes: In actuallys means IN the array, not in the box shaped by the array.
/\}

function PointInTPA(const p: TPoint;const arP: TPointArray): Boolean;
var
i, l: Integer;
begin
l := High(arP);
if l < 0 then
Exit(false);
Result := True;
for i := 0 to l do
if (arP[i].x = p.x) and (arP[i].y = p.y) then
Exit;
Result := False;
end;

On the example you posted it is supposed to result false since the character isn't red, and that is where the main screen center coordinates are.

edit:
Improved performance from you code:
Function TPAInTPA(Search, EntireTPA: TPointArray): Boolean;
var
I, L: Integer;
bounds:TBox;
begin
result := true;
bounds := GetTPABounds(EntireTPA);
L:= High(Search);
for I:= 0 To L do
if (PointInBox(Search[I], bounds)) then
Exit;
result := false;
end;

Coh3n

2012-05-07 16:04:28

Like others have explained, PointInTPA returns true if the point is in the array. What you want is for it to return true if the player is in the bounds of the TPA.

function playerInTPABounds(tpa: TPointArray): boolean;
begin
result := pointInBox(point(MSCX, MSCY), getTPABounds(tpa));
end;
Also, I'm moving this to Scripting Help.

E: For the FindTPAInTPA issue, your parameters aren't right. You're missing a "matches" var. Can you post how you're using it? I'm testing it with this and it works just fine.

program new;

function testFindTPAInTPA(): boolean;
var
totalTPA, searchTPA, matches: TPointArray;
begin
totalTPA := TPAFromBox(intToBox(0, 0, 20, 20));
searchTPA := TPAFromBox(intToBox(5, 5, 10, 10));

result := findTPAInTPA(searchTPA, totalTPA, matches);
end;

begin
clearDebug();
writeln(toStr(testFindTPAInTPA()));
end.