doom0791
2011-02-10 02:15:11
I'm relatively new to using TPA's and ATPA's and I was wondering how I can improve this procedure. The point of the procedure is to find groups of TPoints within a TPA, and sort those groups into an ATPA.
I'm writing this because I'm creating a hybrid auto-fighter, and I need a way of detecting each of the monsters, preferably using color.
The procedure itself works, but it gets slow, and is inefficient. I want to speed up the process so that I can use this procedure to find all monsters in the screen using color and then check if each monster is in a fight and have it fight one that isn't in a fight.
Even if I can't get it to be really fast that's okay because this will only be a backup option to reflection findings.
Sorry it's so messy. This procedure is kicking my butt!
Thanks in advance!
~DooM
I'm writing this because I'm creating a hybrid auto-fighter, and I need a way of detecting each of the monsters, preferably using color.
procedure FindObjInTPA(SearchTPA : TPointArray; var Objs : T2dPointArray);
var
i, j, k, STL, OATL, OTL : Integer;
Temp : Boolean;
begin
if GetArrayLength(SearchTPA) > 0 then
begin
SetArrayLength(Objs, 1); //Set initial condition for Objs ATPA
SetArrayLength(Objs[0], 1); //^^
Objs[0][0] := SearchTPA[0]; //^^
STL := High(SearchTPA);
for i := 1 to STL do // For all TPoints in SearchTPA
begin
Temp := False;
OATL := High(Objs);
//***Find out if SearchTPA[i] is near any TPoint in Objs***
for j := 0 to OATL do // For all TPAs in Objs
begin
OTL := High(Objs[j])
for k := 0 to OTL do // For all Points in Objs[k]
begin
if Distance(SearchTPA[i].x, SearchTPA[i].y, Objs[j][k].x, Objs[j][k].y) < 25 then //Find out if SearchTPA[i] is near any TPoint in Objs[k]
begin
SetArrayLength(Objs[j], GetArrayLength(Objs[j])+1);
Objs[j][High(Objs[j])] := SearchTPA[i];
Temp := True;
//WriteLn('Break A');
Break;
end;
end;
if Temp then
begin
//WriteLn('Break B');
Break;
end;
end;
//***If SearchTPA[i] is not near a point in Objs[k] then increase size of***
//***Objs and add SearchTPA[i] to the new TPA. ***
if not Temp then
begin
SetArrayLength(Objs, GetArrayLength(Objs) + 1);
WriteLn('Objs Length: ' + IntToStr(GetArrayLength(Objs)));
SetArrayLength(Objs[High(Objs)], 1);
Objs[High(Objs)][0] := SearchTPA[i];
end;
end;
end;
end;The procedure itself works, but it gets slow, and is inefficient. I want to speed up the process so that I can use this procedure to find all monsters in the screen using color and then check if each monster is in a fight and have it fight one that isn't in a fight.
Even if I can't get it to be really fast that's okay because this will only be a backup option to reflection findings.
Sorry it's so messy. This procedure is kicking my butt!
Thanks in advance!
~DooM