jhildy
2008-10-04 13:08:41
ok i have decided to make an anywhere walker like nexus has and im stuck because i cant get the actual path building right but i got the function to find the next point in the path to work. Basically what the next point function does is find the closest point that's within minimap range to the endpoint. I just can't get the build path to work. I have not scripted in a long time so if its some obvious mistake just tell me.
program New;
{.include Srl/SRL.scar}
var MapArr,FPath: array of tpoint;
var l: integer;
function LoadPath: TPointArray;
begin
SetLength(Result, 158);
Result[0] := Point(3222, 3217);
Result[1] := Point(3224, 3225);
Result[2] := Point(3224, 3212);
Result[3] := Point(3219, 3209);
Result[4] := Point(3215, 3205);
Result[5] := Point(3209, 3203);
Result[6] := Point(3218, 3227);
Result[7] := Point(3210, 3231);
Result[8] := Point(3228, 3217);
Result[9] := Point(3235, 3218);
Result[10] := Point(3236, 3213);
Result[11] := Point(3235, 3207);
Result[12] := Point(3237, 3202);
Result[13] := Point(3235, 3198);
Result[14] := Point(3234, 3225);
Result[15] := Point(3241, 3224);
Result[16] := Point(3251, 3224);
Result[17] := Point(3258, 3226);
Result[18] := Point(3266, 3226);
Result[19] := Point(3261, 3236);
Result[20] := Point(3256, 3244);
Result[21] := Point(3249, 3241);
Result[22] := Point(3250, 3235);
Result[23] := Point(3247, 3232);
Result[24] := Point(3254, 3249);
Result[25] := Point(3246, 3250);
Result[26] := Point(3242, 3245);
Result[27] := Point(3250, 3257);
Result[28] := Point(3242, 3264);
Result[29] := Point(3252, 3265);
Result[30] := Point(3260, 3261);
Result[31] := Point(3261, 3276);
Result[32] := Point(3251, 3286);
Result[33] := Point(3241, 3279);
Result[34] := Point(3240, 3293);
Result[35] := Point(3233, 3293);
Result[36] := Point(3242, 3307);
Result[37] := Point(3231, 3307);
Result[38] := Point(3228, 3320);
Result[39] := Point(3220, 3328);
Result[40] := Point(3209, 3336);
Result[41] := Point(3248, 3324);
Result[42] := Point(3244, 3316);
Result[43] := Point(3240, 3314);
Result[44] := Point(3259, 3323);
Result[45] := Point(3261, 3308);
Result[46] := Point(3269, 3328);
Result[47] := Point(3277, 3330);
Result[48] := Point(3293, 3333);
Result[49] := Point(3304, 3334);
Result[50] := Point(3290, 3344);
Result[51] := Point(3273, 3345);
Result[52] := Point(3268, 3339);
Result[53] := Point(3253, 3343);
Result[54] := Point(3242, 3349);
Result[55] := Point(3240, 3335);
Result[56] := Point(3227, 3341);
Result[57] := Point(3229, 3357);
Result[58] := Point(3239, 3365);
Result[59] := Point(3254, 3364);
Result[60] := Point(3269, 3366);
Result[61] := Point(3280, 3354);
Result[62] := Point(3248, 3375);
Result[63] := Point(3212, 3363);
Result[64] := Point(3222, 3356);
Result[65] := Point(3210, 3377);
Result[66] := Point(3202, 3365);
Result[67] := Point(3202, 3349);
Result[68] := Point(3186, 3360);
Result[69] := Point(3196, 3372);
Result[70] := Point(3176, 3370);
Result[71] := Point(3171, 3363);
Result[72] := Point(3212, 3385);
Result[73] := Point(3195, 3379);
Result[74] := Point(3212, 3394);
Result[75] := Point(3222, 3391);
Result[76] := Point(3234, 3390);
Result[77] := Point(3243, 3389);
Result[78] := Point(3251, 3389);
Result[79] := Point(3251, 3397);
Result[80] := Point(3259, 3402);
Result[81] := Point(3242, 3402);
Result[82] := Point(3236, 3401);
Result[83] := Point(3229, 3409);
Result[84] := Point(3234, 3417);
Result[85] := Point(3245, 3414);
Result[86] := Point(3259, 3411);
Result[87] := Point(3265, 3420);
Result[88] := Point(3261, 3427);
Result[89] := Point(3254, 3422);
Result[90] := Point(3247, 3428);
Result[91] := Point(3234, 3428);
Result[92] := Point(3225, 3426);
Result[93] := Point(3223, 3415);
Result[94] := Point(3218, 3427);
Result[95] := Point(3211, 3417);
Result[96] := Point(3210, 3409);
Result[97] := Point(3211, 3401);
Result[98] := Point(3200, 3413);
Result[99] := Point(3199, 3419);
Result[100] := Point(3192, 3408);
Result[101] := Point(3188, 3403);
Result[102] := Point(3179, 3414);
Result[103] := Point(3183, 3425);
Result[104] := Point(3196, 3428);
Result[105] := Point(3207, 3431);
Result[106] := Point(3207, 3425);
Result[107] := Point(3216, 3431);
Result[108] := Point(3213, 3435);
Result[109] := Point(3224, 3439);
Result[110] := Point(3233, 3447);
Result[111] := Point(3243, 3441);
Result[112] := Point(3249, 3447);
Result[113] := Point(3239, 3434);
Result[114] := Point(3264, 3438);
Result[115] := Point(3268, 3431);
Result[116] := Point(3199, 3444);
Result[117] := Point(3190, 3451);
Result[118] := Point(3181, 3447);
Result[119] := Point(3186, 3439);
Result[120] := Point(3175, 3436);
Result[121] := Point(3171, 3450);
Result[122] := Point(3166, 3462);
Result[123] := Point(3166, 3474);
Result[124] := Point(3176, 3483);
Result[125] := Point(3184, 3494);
Result[126] := Point(3172, 3503);
Result[127] := Point(3158, 3502);
Result[128] := Point(3151, 3493);
Result[129] := Point(3156, 3480);
Result[130] := Point(3165, 3485);
Result[131] := Point(3152, 3473);
Result[132] := Point(3143, 3479);
Result[133] := Point(3145, 3492);
Result[134] := Point(3145, 3505);
Result[135] := Point(3158, 3511);
Result[136] := Point(3174, 3511);
Result[137] := Point(3187, 3512);
Result[138] := Point(3191, 3502);
Result[139] := Point(3159, 3456);
Result[140] := Point(3153, 3446);
Result[141] := Point(3147, 3442);
Result[142] := Point(3145, 3428);
Result[143] := Point(3154, 3422);
Result[144] := Point(3141, 3420);
Result[145] := Point(3133, 3425);
Result[146] := Point(3135, 3437);
Result[147] := Point(3125, 3436);
Result[148] := Point(3124, 3425);
Result[149] := Point(3130, 3416);
Result[150] := Point(3173, 3427);
Result[151] := Point(3152, 3416);
Result[152] := Point(3133, 3448);
Result[153] := Point(3135, 3459);
Result[154] := Point(3127, 3459);
Result[155] := Point(3122, 3444);
Result[156] := Point(3115, 3431);
Result[157] := Point(3108, 3420);
end;
Function FindPathSPEP(Path: array of tpoint): array of Tpoint;
var ClosestSP,ClosestEP: Tpoint;
var i,arrlength: integer;
begin
for i:=0 to (getarraylength(MapArr) - 1) do
begin
if ((distance(MapArr[i].x, MapArr[i].y, Path[0].x, Path[0].y))<
(distance(ClosestSP.x, ClosestSP.y, Path[0].x, Path[0].y))) then
ClosestSP:=MapArr[i];
end;
writeln('Closest starting point is ' + inttostr(ClosestSP.x) + ',' +inttostr(ClosestSP.y));
arrlength:=getarraylength(path) - 1;
for i:=0 to (getarraylength(MapArr) - 1) do
begin
if ((distance(MapArr[i].x, MapArr[i].y, Path[arrlength].x, Path[arrlength].y))<
(distance(ClosestEP.x, ClosestEP.y, Path[arrlength].x, Path[arrlength].y))) then
ClosestEP:=MapArr[i];
end;
writeln('Closest ending point is ' + inttostr(ClosestEP.x) + ',' +inttostr(ClosestEP.y));
result:=[ClosestSP,ClosestEP];
end;
Function FindNextClosestPoint(StartPoint, Destination: Tpoint): tpoint;
var x: integer;
var cP: tpoint;
begin
for x:= 0 to (getarraylength(MapArr) - 1) do
begin
if (distance(startpoint.x, startpoint.y, MapArr[x].x, MapArr[x].y)<= 17)
then
begin
if (distance(MapArr[x].x, MapArr[x].y, Destination.x, Destination.y) <
distance(cP.x, cP.y, Destination.x, Destination.y)) then
cP := MapArr[x];
end;
end;
writeln(inttostr(cP.x) + ',' + inttostr(cP.y));
result:= cP;
end;
Function BuildPath(StartPoint, Endpoint: Tpoint): TPointArray;
var tempP: array [0..157] of tpoint;
var y,p,ar: integer;
label qr;
begin
writeln('1');
repeat
qr:
writeln('2');
// ar:= getarraylength(tempP) +1;
writeln('i');
// setarraylength(tempP,ar);
if y=0 then
begin
writeln('3');
tempP[0]:= FindNextClosestPoint(StartPoint, Endpoint);
inc(y);
goto qr;
end;
begin
writeln('4');
if (distance(tempP[y].x,tempP[y].y,Endpoint.x,Endpoint.y)<= 17) and (not y = 0) then
begin
writeln('5');
tempP[y]:=Endpoint;
break;
end;
if not(distance(tempP[y].x,tempP[y].y,Endpoint.x,Endpoint.y)<= 17) then
begin
tempP[y]:= FindNextClosestPoint(tempP[y-1], Endpoint);
writeln(inttostr(tempP[y].x) + 'x' + inttostr(tempP[y].y));
end;
end;
inc(y)
inc(p);
until(p>getarraylength(MapArr));
result:= tempP;
if (p>getarraylength(MapArr)) then
writeln('Failed to build path');
end;
begin
MapArr := LoadPath;
FPath := BuildPath(point(3207,3204), point(3134,3449));
writeln(inttostr(getarraylength(FPath)));
for l:= 0 to (getarraylength(Fpath)-1) do
begin
writeln(inttostr(FPath[l].x) + 'x' + inttostr(FPath[l].y));
end;
end.