Is there a simple bit of code already out there that finds the DTM nearest to the center of MS?
Thanks in advance.
Is there a simple bit of code already out there that finds the DTM nearest to the center of MS?
Thanks in advance.
Current projects:
[ AeroGuardians (GotR minigame), Motherlode Miner, Blast furnace ]
"I won't fall in your gravity. Open your eyes,
you're the Earth and I'm the sky..."
MSCX and MSCY are the main screen points.
Search around there.
Yes, but the 'searching' is what I'm asking about. I guess since no one's posted anything then no such code exists.
Current projects:
[ AeroGuardians (GotR minigame), Motherlode Miner, Blast furnace ]
"I won't fall in your gravity. Open your eyes,
you're the Earth and I'm the sky..."
Simba Code:{***
function GetClosestDTM(DTMs: TIntegerArray; SearchBox: TBox; P: TPoint; var ResultPoint: TPoint): Boolean;
By: TomTuff
Desc: Finds all the DTMs in the TIA within the SearchBox, then finds the closest one
to point "P". Point is stored in ResultPoint as well.
***}
function GetClosestDTM(DTMs: TIntegerArray; SearchBox: TBox; P: TPoint; var ResultPoint: TPoint): Boolean;
var
ATPA: T2DPointArray;
i: Integer;
TPA: TPointArray;
begin
SetLength(ATPA, Length(DTMs));
for i := 0 to High(DTMs) do
FindDTMs(DTMs[i], ATPA[i], SearchBox.X1, SearchBox.Y1, SearchBox.X2, SearchBox.X2);
Result := (Length(TPA) > 0);
if not(Result) then
Exit;
TPA := MergeATPA(ATPA);
SortTPAFrom(TPA, P);
ResultPoint := TPA[0];
end;
Use as you wish
What I would do would be just use a for loop. After each iteration, just increase .x2 and .y2 by ten, and decrease .x1 and .y1 by ten, until your search area is too big or whatever.
I think there's a better way to do it but whatever.![]()
P (TPoint) would be the center of your search box, or do we leave that bank to get defined later in the function?
Looks awesome by the way, I really appreciate it. I'll test it in a while and see what I come up with.
Current projects:
[ AeroGuardians (GotR minigame), Motherlode Miner, Blast furnace ]
"I won't fall in your gravity. Open your eyes,
you're the Earth and I'm the sky..."
Wouldn't you need to free the DTMs within this procedure?
Current projects:
[ AeroGuardians (GotR minigame), Motherlode Miner, Blast furnace ]
"I won't fall in your gravity. Open your eyes,
you're the Earth and I'm the sky..."
I'd keep the DTMs as a global declaration anyways if you use them a lot.
(Scripts outdated until I update for new SRL changes)
AK Smelter & Crafter [SRL-Stats] - Fast Fighter [TUT] [SRL-Stats]
If you PM me with a stupid question or one listed in FAQ I will NOT respond. -Narcle
Summer = me busy, won't be around much.
Ok, I'll declare the DTMs globally and free them within the function that calls this. Thanks guys, and rep for you TomTuff.
I think just one more question. How are you grabbing the point, or even the x/y of the result point, from your function? I've tried this:
Here's your function that I modified:
Simba Code:Function GetClosestDTM(DTMs: TIntegerArray): Boolean;
Var
i: Integer;
TPA: TPointArray;
ResultPoint: TPoint;
ATPA: T2DPointArray;
begin
SetLength(ATPA, Length(DTMs));
for i := 0 to High(DTMs) do
FindDTMs(DTMs[i], ATPA[i], MSX1, MSY1, MSX2, MSY2);
Result := (Length(TPA) > 0);
if not(Result) then
Exit;
TPA := MergeATPA(ATPA);
SortTPAFrom(TPA, Point(MSCX,MSCY));
ResultPoint := TPA[0];
end;
And in another function, I tried to use this to deprive the X/Y from that:
Simba Code:X := GetClosestDTM(RockDTM).ResultPoint.x;
Y := GetClosestDTM(RockDTM).ResultPoint.y;
Edit: Even tried getting the ResultPoint itself, then drawing the x/y from the point, but I keep getting compile errors and it's beyond me why it doesn't work. It's probably a really simple mistake and I'm sure I'll feel really stupid when someone answers it.
Edit2: Nevermind, I did changed the result type that your function outputs and grabbed the point from it, then deprived the x/y from the result's point. I'll test it to see if it works now.![]()
Last edited by Flight; 04-21-2011 at 03:49 AM.
Current projects:
[ AeroGuardians (GotR minigame), Motherlode Miner, Blast furnace ]
"I won't fall in your gravity. Open your eyes,
you're the Earth and I'm the sky..."
There are currently 1 users browsing this thread. (0 members and 1 guests)