Coh3n
2010-07-09 15:38:57
From: Coh3n
Alright guys I worked on this for the last hour or so. What I have here is a similar system to walking, except for minimap areas. There's both color and reflection relocation points (a path may or may not work) in the TLocation record, just like there is in the TPath record.Couple things:
const
RELOCATE_MIN_DIST = 3;
type
TMMColorArea = record
Symbol : string;
DTM : Integer;
W, H : Integer;
Colors : TIntegerArray;
Tolerances : TIntegerArray;
Counts : TIntegerArray;
Bounds : TBox;
end;
TMMColorAreaArray = array of TMMLocation;
type
TLocation = record
Name : string;
Constant : Integer;
RelocatePoints: TPointArray; // Length of these arrays have to be the same,
RelocateAreas : TIntegerArray; // similar to the length of Color/Ref walking paths
end;
var
MSI_ColorAreas: array[0..AREA_ARRAY_LENGTH] of TMMColorArea;
function MSI_LoadColorArea(Which: Integer): Boolean;
begin
case Which of
GE_YEWS_1:
with MSI_ColorAreas[Which] do
begin
end;
GE_YEWS_2:
with MSI_ColorAreas[Which] do
begin
end;
end;
Result := (MSI_ColorAreas[Which].DTM <> -1);
end;
procedure MSI_LoadAllColorAreas;
var
i: Integer;
begin
for i := 0 to High(MSI_ColorAreas) do
MSI_LoadColorArea(i);
end;
{******************************************************************************}
{ function MSI_RelocateColor(...): Boolean; }
{ By: marpis }
{ Description: Finds a location in minimap. First tries to find DTM, then }
{ colors, and if still not found it will find it by symbol }
{******************************************************************************}
function MSI_RelocateColor(var P: TPoint; Location, Index: Integer): Boolean;
Var
SA, EA, tmp_Ang: Extended;
N, I, II, III, H, HH, X, Y, Score, Step: Integer;
ATPA: T2DPointArray;
tmp_TPA: TPointArray;
X1, Y1, X2, Y2: Integer;
Loc: TLocation;
begin
Result := False;
P := Point(-1, -1);
if (not LoggedIn) then
Exit;
if (Length(MSI_Locations[Location].RelocateAreas) <= 0) then
Exit;
Loc := MSI_ColorAreas[MSI_Locations[Location].RelocateAreas[Index]];
Step := (Loc.W * Loc.H) / 10;
{ DTM Search }
if (Loc.DTM > -1) then
while (N < 10) do
begin
if FindDTMRotated(Loc.DTM, X, Y, MMX1, MMY1, MMX2, MMY2, SA, EA, 0.02, tmp_Ang) then
begin
Result := True;
P := Point(X, Y);
MSI_SubDebug('Found relocation point via DTM: (' + IntToStr(P.X) + ', ' + IntToStr(P.Y) + ')');
Exit;
end;
Inc(N);
SA := SA - (N * 0.02);
EA := EA + (N * 0.02);
end;
{ Color search }
if (Length(Loc.Colors) > 0) then
begin
H := High(Loc.Colors);
SetLength(ATPA, H + 1);
for I := 0 to H do
begin
FindColorsSpiralTolerance(MMCX, MMCY, ATPA[I], Loc.Colors[I], MMX1, MMY1, MMX2, MMY2, Loc.Tolerances[I]);
FilterPointsPie(ATPA[I], 0.0, 360.0, 0.0, 76.0, MMCX, MMCY);
end;
{ Go through every TPA that contains one color. }
for I := 0 to H do
begin
HH := High(ATPA[I]);
{ Go through every 10th point in ATPA[I] to avoid lag. }
for II := 0 to HH do
begin
if ((II mod Step) <> 0) then
Continue;
Score := 0;
X1 := ATPA[I][II].X - (Loc.W / 2);
Y1 := ATPA[I][II].Y - (Loc.H / 2);
X2 := ATPA[I][II].X + (Loc.W / 2);
Y2 := ATPA[I][II].Y + (Loc.H / 2);
{ Go through every TPA again, calculating surrounding color counts. }
for III := 0 to H do
begin
tmp_TPA := MSI_ReturnPointsInBox(ATPA[III], IntToBox(X1, Y1, X2, Y2));
if (Length(tmp_TPA) >= Loc.Counts[III]) then
Inc(Score);
end;
{ If there are enough points of all colors, the location has been found. }
if (Score = H) then
begin
Result := True;
X := (X1 + X2) shr 1;
Y := (Y1 + Y2) shr 1;
P := Point(X, Y);
MSI_SubDebug('Found relocation point via color: (' + IntToStr(P.X) + ', ' + IntToStr(P.Y) + ')');
Exit;
end;
end;
end;
end;
{ Symbol Search }
if (Loc.Symbol <> '') then
if FindSymbol(X, Y, Loc.Symbol) then
begin
Result := True;
P := Point(X, Y);
MSI_SubDebug('Found relocation point via symbol: (' + IntToStr(P.X) + ', ' + IntToStr(P.Y) + ')');
Exit;
end;
end;
function MSI_RelocateRef(var p: TPoint; Location, Index: Integer): Boolean;
begin
Result := False;
p := Point(-1, -1);
{$IFDEF REFLECTION}
P := TileToMM(MSI_Locations[Location].RelocatePoints[Index]);
Result := ((p.x > 0) and (p.y > 0));
{$ENDIF}
end;
function MSI_Relocate(Loc: Integer): Boolean;
var
i: Integer;
p: TPoint;
begin
MSI_AddHeader('MSI_Relocate');
for i := 0 to High(MSI_Locations[Loc].RelocatePoints) do
begin
if (not MSI_RelocateRef(p, Loc, i)) then
if (not MSI_RelocateColor(p, Loc, i)) then
Exit;
if (Distance(p.x, p.y, MMCX, MMCY) > RELOCATE_MIN_DIST) then
begin
Mouse(p.x, p.y, 4, 4, True);
MSI_SubDebug('Walking to Point(' + IntToStr(p.x) + ', ' + IntToStr(p.y) + ')');
MSI_Flag;
Result := True;
Break;
end;
end;
MSI_CloseHeader('MSI_Relocate: ' + BoolToStr(Result));
end;
- I kept RELOCATE_MIN_DIST a constant because I really don't think it needs to be location specific. However, I could easily be proved to be wrong.
- All of this code (excluding const, vars and types) would go in Relocate.simba, unless there's a better place.
What do you guys think?