Here's my plugin:
Simba Code:
library GALILEO;
{$mode objfpc}{$H+}
uses
Classes, sysutils
{ you can add units after this };
type
TIntegerArray = Array of Integer;
T3DIntegerArray = Array of Array of Array of Integer;
function G_ColorBoxesMatch(B1, B2: TIntegerArray; tol: extended): boolean; register;
begin
if (B1[0] >= Round(B2[0]*(1-tol))) and (B1[0] <= Round(B2[0]*(1+tol))) and
(B1[1] >= Round(B2[1]*(1-tol))) and (B1[1] <= Round(B2[1]*(1+tol))) and
(B1[2] >= Round(B2[2]*(1-tol))) and (B1[2] <= Round(B2[2]*(1+tol))) then
begin
Result := True;
Exit;
end;
end;
procedure G_FindMapInMapEx(var fx, fy: integer; LargeMap, SmallMap: T3DIntegerArray; tol: extended); register;
var
x, y, HighX, HighY: integer;
xx, yy: integer;
Matching, BestMatch: integer;
begin
fX := -1;
fY := -1;
BestMatch := 0;
HighX := High(LargeMap) - 19;
HighY := High(LargeMap[0]) - 19;
for x := 0 to HighX do
for y := 0 to HighY do
begin
Matching := 0;
for xx := 0 to 19 do
for yy := 0 to 19 do
if G_ColorBoxesMatch(LargeMap[x+xx][y+yy], SmallMap[xx][yy], tol) then
Inc(Matching);
if Matching > BestMatch then
begin
BestMatch := Matching;
fX := x*5 + 50; // cause we want the center
fY := y*5 + 50;
end;
end;
end;
////// TYPES //////////////////////////////////////////////////////////////////
function GetTypeCount(): Integer; stdcall; export;
begin
Result := 1;
end;
function GetTypeInfo(x: Integer; var sType, sTypeDef: string): integer; stdcall;
begin
case x of
0: begin
sType := 'T3DIntegerArray';
sTypeDef := 'Array of Array of Array of Integer;';
end;
else
Result := -1;
end;
end;
////// EXPORTING /////////////////////////////////////////////////////////////
function GetFunctionCount(): Integer; stdcall; export;
begin
Result := 2;
end;
function GetFunctionCallingConv(x : Integer) : Integer; stdcall; export;
begin
Result := 0;
case x of
0..1 : Result := 1;
end;
end;
function GetFunctionInfo(x: Integer; var ProcAddr: Pointer; var ProcDef: PChar): Integer; stdcall; export;
begin
case x of
0:
begin
ProcAddr := @G_ColorBoxesMatch;
StrPCopy(ProcDef, 'function G_ColorBoxesMatch(B1, B2: TIntegerArray; tol: extended): boolean;');
end;
1:
begin
ProcAddr := @G_FindMapInMapEx;
StrPCopy(ProcDef, 'procedure G_FindMapInMapEx(var fx, fy: integer; LargeMap, SmallMap: T3DIntegerArray; tol: extended);');
end;
else
x := -1;
end;
Result := x;
end;
exports GetTypeCount;
exports GetTypeInfo;
exports GetFunctionCount;
exports GetFunctionInfo;
exports GetFunctionCallingConv;
{$IFDEF WINDOWS}{$R GALILEO.rc}{$ENDIF}
begin
end.
and the problem is that G_FindMapInMapEx keeps resulting (50, 50) as fx, fy, which means that it "finds" us at (0, 0) and then adds the 50 as constants. See the code and you'll understand.
Regardless of the Minimap parameter values, it does the same. What to do?
The problem could be, that ColorBoxesMatch always results True. If that is the case, why is that and how to solve the problem?