Nava2
2008-08-30 12:07:39
Okay, so, my hardest project yet. An abyss runner.
So, whats the problem with this:
I get an out of range error.
P.S. Sorry, I know its reflection :P
So, whats the problem with this:
program New;
{.include SRL/SRL/misc/smart.scar}
{.include SRL\SRL.Scar}
{.include SRL/SRL/reflection/reflection.scar}
var
AlterTPA : TPointArray;
procedure DeclareGlobalPaths;
begin
{Path := [Point(3039, 4855), Point(3050, 4851), Point(3060, 4840),
Point(3062, 4831), Point(3059, 4822), Point(3050, 4812),
Point(3042, 4810), Point(3027, 4812), Point(3017, 4822),
Point(3017, 4834), Point(3020, 4843), Point(3029, 4851)];}
AlterTPA := [Point(3040, 4845), Point(3044, 4842), Point(3049, 4839),
Point(3050, 4837), Point(3051, 4833), Point(3050, 4829),
Point(3047, 4825), Point(3044, 4822), Point(3039, 4821),
Point(3031, 4825), Point(3029, 4830), Point(3027, 4834),
Point(3028, 4837), Point(3035, 4842)];
end;
function FindMeOnPath(var Index: integer; Path: TPointArray; MaxDist: integer): boolean;
var
I, H, DistC, DistS : integer;
begin
Status('FindMeOnPath');
H := High(Path);
DistS := DistanceFrom(Path[0]);
for I := 0 to H do
begin
if not TileOnMM(Path[I]) then Continue;
DistC := DistanceFrom(Path[I]);
if DistC < DistS then
begin
DistS := DistC
Index := I;
end;
end;
Result := DistS < MaxDist;
end;
{function WalkPathEx(Path: TPointArray; Index1, Index2, Random, Distance: integer): boolean;
var
I, Z : integer;
begin
Status('WalkPath');
for I := Index1 to Index2 do
begin
if DistanceFrom(Path[I]) < Distance then
Continue;
Status('WalkPath: ' + IntToStr(Index2 - Index1) + ' points left on Path.');
Result := WalkToTile(Path[I], Random, Distance);
if not Result then Inc(Z);
ABnAR;
end;
Result := Z <> Length(Path);
end; }
{*******************************************************************************
Function WalkToTile(Tile: TPoint; Randomness, FlagD: Integer): Boolean;
By: Wizzup and TheGuyWhoGotOn
Description: Walks to the tile using minimap.
*******************************************************************************}
Function WalkToTileEx(Tile: TPoint; Randomness, FlagD: Integer): Boolean;
Var
wTile: TPoint;
t: Integer;
Begin
Tile.X := RandomRange(Tile.X-Randomness, Tile.X+Randomness);
Tile.Y := RandomRange(Tile.Y-Randomness, Tile.Y+Randomness);
wTile := TileToMM(Tile);
If Not rs_OnMiniMap(wTile.X, wTile.Y) Then
Begin
Result := False;
Exit;
End;
Result := True;
MFNF(wTile.x, wTile.y, -1, -1);
t := getsystemtime;
R_FFlag(FlagD);
Result := DistanceFrom(Tile) <= FlagD;
End;
function SetupWalkPortal(Alter : String): TIntegerArray;
var
I : Integer;
begin
if not FindMeOnPath(I, AlterTPA, 7) then
begin
SRL_Warn('SetupWalkPortal', 'NOT IN ABYSS.', Warn_AllVersions);
Exit;
end else
Result[0] := I;
case Lowercase(Alter) of
'wizard': Result[1] := 0;
'chaos' : Result[1] := 1;
'law' : Result[1] := 2;
'death' : Result[1] := 3;
'water' : Result[1] := 4;
'soul' : Result[1] := 5;
'air' : Result[1] := 6;
'mind' : Result[1] := 7;
'body' : Result[1] := 8;
'earth' : Result[1] := 9;
'fire' : Result[1] := 10;
'blood' : Result[1] := 11;
'cosmic': Result[1] := 12;
'nature': Result[1] := 13;
end;
end;
procedure ReArray(var Arr: TPointArray; StartingIndex: Integer);
var
I, I2, H, H2 : Integer;
ArrEx : TPointArray;
begin
SetLength(ArrEx, Length(Arr));
H := High(Arr);
for I := StartingIndex to H do
ArrEx[i - StartingIndex] := Arr[i];
H2 := StartingIndex - 1;
I2 := H - StartingIndex + 1;
for i := 0 to H2 do
ArrEx[I2 + i] := Arr[i];
Arr := ArrEx;
end;
procedure ReArrayInv(var Arr: TPointArray; StartingIndex: Integer);
var
I, H, H2, Z : Integer;
ArrEx : TPointArray;
begin
SetLength(ArrEx, Length(Arr));
for I := StartingIndex downto 0 do
begin
ArrEx[z] := Arr[i];
Inc(z);
end;
H := High(Arr);
H2 := StartingIndex + 1;
Z := H2;
for i := H downto H2 do
begin
ArrEx[z] := Arr[i];
Inc(Z);
end;
Arr := ArrEx;
end;
function WalkPathPortal(Portal : string): boolean;
var
IndexArray : TIntegerArray;
AlterTPAEx : TPointArray;
I, Z : integer;
B, A1, A2 : extended;
begin
Result := False;
AlterTPAEx := AlterTPA;
IndexArray := SetupWalkPortal(Portal);
B := Abs(4832 - AlterTPAEx[IndexArray[0]].y);
A1 := ArcSin(B / Hypot(Abs(3040 - AlterTPAEx[IndexArray[0]].x), B));
Writeln('Angle 1 is ' + FloatToStr(A1) + ' radians.');
B := Abs(4832 - AlterTPAEx[IndexArray[1]].y);
A2 := ArcSin(B / Hypot(Abs(3040 - AlterTPAEx[IndexArray[1]].x), B));
Writeln('Angle 2 is ' + FloatToStr(A1) + ' radians.');
if (Abs(A1 - A2) < 180) then
ReArrayInv(AlterTPAEx, IndexArray[0])
else
ReArray(AlterTPAEx, IndexArray[0]);
Z := Round(Abs(IndexArray[0] - IndexArray[1]));
Status('WalkPath');
for I := 0 to Z do
begin
if DistanceFrom(AlterTPAEx[I]) < 3 then
Continue;
Status('WalkPath: ' + IntToStr(Z - I) + ' points left on Path.');
if not WalkToTileEx(AlterTPAEx[I], 1, 3) then
begin
Writeln('Did not make it to Tile ' + IntToStr(AlterTPAEx[i].x) + ', ' + IntToStr(AlterTPAEx[i].y) + '.');
Exit;
end;
end;
Result := true;
end;
var
BoolArr : Array of Boolean;
q : integer;
begin
SmartSetupEx(115, true, true, false);
SetTargetDC(SmartGetDC);
SetupSRL;
repeat
if IsFKeyDown(2) then
begin
SetLength(BoolArr, Length(BoolArr) + 1);
BoolArr[Q] := WalkPathPortal('nature');
Inc(q);
end;
until IsFKeyDown(3);
for Q := 0 to High(BoolArr[q]) do
Writeln('Attempt ' + IntToStr(q) + ': ' + BoolToStr(BoolArr[q]));
end.I get an out of range error.
[Runtime Error] : Out Of Range in line 30 in script C:\Documents and Settings\Kevin\Desktop\abyss solver.scarP.S. Sorry, I know its reflection :P