Nava2
2008-09-10 21:06:40
So, I can not for the life of me figure out why this doesnt work properly.
It is supposed to take the position you are in, and walk to the alter specified. In the abyss.
If ANYONE can help me, thank you very very much.
Just press play, then log in your player. Then hit F2, write the alter, and watch it go. :)
Thanks in advance.
It is supposed to take the position you are in, and walk to the alter specified. In the abyss.
If ANYONE can help me, thank you very very much.
Just press play, then log in your player. Then hit F2, write the alter, and watch it go. :)
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, 4842), Point(3044, 4843), Point(3050, 4839),
Point(3051, 4837), Point(3052, 4833), Point(3051, 4829),
Point(3047, 4824), Point(3044, 4821), Point(3039, 4820),
Point(3030, 4825), Point(3027, 4830), Point(3026, 4834),
Point(3027, 4837), Point(3035, 4843)];
end;
{*******************************************************************************
procedure RemoveElement(Index : Integer; var Arr : Array);
By: MylesMadness
Description: Removed Piece Index of an Array, the Array is defined by the user.
*******************************************************************************}
Procedure RemoveElement(Index : Integer; var Arr : TPointArray);
var
I, H : Integer;
begin
H := High(Arr);
for I := Index to H do
Arr[Index] := Arr[Index + 1];
SetArrayLength(Arr, High(Arr));
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;
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;
Writeln('error in walktotileex');
Exit;
End;
Result := True;
MFNF(wTile.x, wTile.y, -1, -1);
R_FFlag(FlagD);
Result := DistanceFrom(Tile) <= FlagD;
End;
function SetupWalkPortal(Alter : String): TIntegerArray;
var
I : Integer;
begin
SetLength(Result, 2);
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; Invert: boolean);
var
I, I2, H, H2 : Integer;
ArrEx : TPointArray;
begin
SetLength(ArrEx, Length(Arr));
H := High(Arr);
case Invert of
true: begin
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];
end;
false: begin
for I := StartingIndex downto 0 do
begin
ArrEx[I2] := Arr[i];
Inc(I2);
end;
H2 := StartingIndex + 1;
I2 := H2;
for i := H downto H2 do
begin
ArrEx[I2] := Arr[i];
Inc(I2);
end;
end;
end;
Arr := ArrEx;
end;
// Metagen
// Finds the closest tile in the in the array of tiles to the player
Function FindClosestTile(TPA : TPointArray) : Integer;
var
i, Dist, MinDist, MinIndex : Integer;
MyPos : TPoint;
begin
MinDist := 65535;
MyPos := GetMyPos
for i := 0 to high(TPA) do
begin
Dist := Distance(TPA[i].x, TPA[i].y, MyPos.x, MyPos.y);
if Dist < MinDist then
begin
MinIndex := i;
MinDist := Dist;
end;
end;
result := MinIndex;
Writeln('Closest Tile Is: ' + IntToStr(Result));
end;
// Metagen
//Returns in a TPoint:
//x as: The tile the player is closest to
//y as: The last tile in the array that can be sequentially seen.
Function TileRange(TPA : TPointArray) : TPoint;
var
I, H : Integer;
begin
FindMeOnPath(result.x, TPA, 20000);
H := high(TPA)
for i := result.x to H do
begin
if not TileOnMM(TPA[i]) then
begin
if i = Result.x then
begin
Writeln('Could Not Find The Path');
Logout;
Exit;
end;
result.y := Max(i-1, Result.x);
WriteLn('TileRange is: ' + inttostr(result.x) + ', ' + IntToStr(result.y));
exit;
end;
end;
WriteLn('Can See All Remaining Points');
result.y := High(TPA);
WriteLn('TileRange is: ' + inttostr(result.x) + ', ' + IntToStr(result.y));
end;
// Metagen
// Picks a good human-like next point in the array to walk to and returns
// the array index
Function GenerateNextPathPoint(TPA : TPointArray) : Integer;
var
PathRange : TPoint;
Variance : Integer;
begin
PathRange := TileRange(TPA);
Variance := (PathRange.y - PathRange.x) / 4;
WriteLn('Variance Is: ' + IntToStr(Variance));
Result := PathRange.y - Variance - Random(Variance);
Writeln('Next Path Point: ' + IntToStr(Result));
end;
function WalkPathPortal(Portal : string): boolean;
var
IndexArray : TIntegerArray;
AlterTPAEx : TPointArray;
I, Z, NextTile : 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(A2) + ' radians.');
ReArray(AlterTPAEx, IndexArray[0], (Round(Abs(A1 - A2)) >= 1))
Writeln('passed');
Status('WalkPath');
Z := Round(Abs(IndexArray[1] - IndexArray[0]));
NextTile := GenerateNextPathPoint(AlterTPAEx);
Writeln(IntToStr(NextTile));
for I := 0 to High(AlterTPAEx) do
if I <> NextTile then
begin
NextTile := Min(GenerateNextPathPoint(AlterTPAEx), Z);
Writeln(IntToStr(NextTile));
if not WalkToTileEx(AlterTPAEx[NextTile], 1, 4) then
begin
Writeln('Did not make it to Tile ' + IntToStr(AlterTPAEx[NextTile].x) + ', ' + IntToStr(AlterTPAEx[NextTile].y) + '.');
Exit;
end;
if (DistanceFrom(AlterTPA[IndexArray[1]]) < 4) or (NextTile = Z) then
Break;
end;
Result := true;
end;
var
BoolArr : Array of Boolean;
q : integer;
s : string;
Me : TMe;
begin
SmartSetupEx(115, true, true, false);
SetTargetDC(SmartGetDC);
SetupSRL;
DeclareGlobalPaths;
repeat
Wait(1);
if IsFKeyDown(2) then
begin
SetLength(BoolArr, Length(BoolArr) + 1);
S := ReadLn('Which alter?');
BoolArr[Q] := WalkPathPortal(s);
Writeln(BoolToStr(BoolArr[Q]) + ' ' + S);
Inc(q);
Me := GetMe;
while Me.Speed > 0 do
begin
Wait(100);
Me := GetMe;
end;
end;
until IsFKeyDown(3);
for Q := 0 to High(BoolArr) do
Writeln('Attempt ' + IntToStr(q) + ': ' + BoolToStr(BoolArr[q]));
end.Thanks in advance.