SRL Archive - OSR Help

advanced help


Feroc1ty

2009-08-08 21:52:11

here is the code, if you can't figure it out when you hit run you wont be able to help me out anyway, for some reason the bitch doesnt wanna do what its told, it somehow successfully arrives at the wrong location so heres the code, if you need further explanation ill give it to ya


program New;

function path1: TPointArray;
begin
SetLength(Result, 8);

Result[0] := Point(0, 0);
Result[1] := Point(0, 1);
Result[2] := Point(0, 2);
Result[3] := Point(0, 3);
Result[4] := Point(0, 4);
Result[5] := Point(0, 5);
Result[6] := Point(0, 6);
Result[7] := Point(0, 7);
end;

function path2: TPointArray;
begin
SetLength(Result, 8);

Result[0] := Point(0, 0);
Result[1] := Point(1, 1);
Result[2] := Point(2, 2);
Result[3] := Point(3, 3);
Result[4] := Point(4, 4);
Result[5] := Point(5, 5);
Result[6] := Point(6, 6);
Result[7] := Point(7, 7);
end;

function path3: TPointArray;
begin
SetLength(Result, 8);

Result[0] := Point(0, 0);
Result[1] := Point(1, 0);
Result[2] := Point(2, 0);
Result[3] := Point(3, 0);
Result[4] := Point(4, 0);
Result[5] := Point(5, 0);
Result[6] := Point(6, 0);
Result[7] := Point(7, 0);
end;

function path4: TPointArray;
begin
SetLength(Result, 8);

Result[0] := Point(7, 0);
Result[1] := Point(7, 1);
Result[2] := Point(7, 2);
Result[3] := Point(7, 3);
Result[4] := Point(7, 4);
Result[5] := Point(7, 5);
Result[6] := Point(7, 6);
Result[7] := Point(7, 7);
end;

function path5: TPointArray;
begin
SetLength(Result, 8);

Result[0] := Point(0, 7);
Result[1] := Point(1, 7);
Result[2] := Point(2, 7);
Result[3] := Point(3, 7);
Result[4] := Point(4, 7);
Result[5] := Point(5, 7);
Result[6] := Point(6, 7);
Result[7] := Point(7, 7);
end;

function IntinArr(int:integer; comp:array of integer):boolean;
var i:integer;
begin
result := false;
for i := 0 to High(comp) do
begin
if comp[i] = int then
begin
result := true;
exit;
end;
end;
end;

type path = record
node: TPointArray;
avg, first,last: TPoint;
index: integer;
connection: array of integer;
end;

var paths:array of path;
curindex: integer;

function CalcAvginTPA(tpa:TPointArray):TPoint;
var i:integer;
begin
for i := 0 to high(tpa) do
begin
result.x := result.x + tpa[i].x;
result.y := result.y + tpa[i].y;
end;
result.x := Round(result.x / getarraylength(tpa));
result.y := Round(result.y / getarraylength(tpa));
end;

function CreatePath(node:TPointArray):integer;
begin
SetArrayLength(paths, curindex+1);
paths[curindex].node := node;
paths[curindex].index := curindex;
paths[curindex].avg := CalcAvginTPA(node);
paths[curindex].first := node[0];
paths[curindex].last := node[high(node)];
result := curindex;
curindex := curindex + 1;
end;

procedure LinkPath(i,y:integer);
begin
if IntinArr(i, paths[y].connection) = true then
begin
writeln('Following paths are already linked: ' + inttostr(i) + ':' + inttostr(y) + ' so fix your script because you''re losing efficiency!');
exit;
end;
SetArrayLength(paths[i].connection, GetArrayLength(paths[i].connection)+1);
SetArrayLength(paths[y].connection, GetArrayLength(paths[y].connection)+1);
paths[i].connection[High(paths[i].connection)] := paths[y].index;
paths[y].connection[High(paths[y].connection)] := paths[i].index;
end;


var charx,chary, destx, desty:integer;
arrived: boolean;

function TPt(x,y:integer):TPoint;
begin
result.x := x;
result.y := y;
end;

function AngleBetweenPoints(y1,y2,x1,x2:integer):extended;
begin
result := Abs(Arctan2(y2-y1,x2-x1) * 180 / Pi);
end;

procedure MoveTo(p:TPoint);
begin
charx := p.x;
chary := p.y;
writeln('Moved to :' + inttostr(p.x) + ',' + inttostr(p.y));
end;

procedure Initialize();
begin
CreatePath(path1());
CreatePath(path2());
CreatePath(path3());
CreatePath(path4());
CreatePath(path5());
LinkPath(0,1);
LinkPath(0,2);
LinkPath(1,2);
LinkPath(1,3);
LinkPath(1,4);
LinkPath(3,4);
end;

procedure AutoMoveThroughTPA(start,inc:integer; node:TPointArray);
var i:integer;
begin
i := start - inc;
repeat
i := i + inc;
MoveTo(node[i]);
if (node[i].x = destx) and (node[i].y = desty) then
begin
arrived := true;
exit;
end;
wait(100);
until (((i = 0) and (i <> start)) or ((i = high(node)) and (high(node) <> start)))
end;

function Pathable(path:integer):boolean;
begin
if Distance(charx, chary, paths[path].first.x, paths[path].first.y) < Distance(charx, chary, paths[path].last.x, paths[path].last.y)then
begin
result := ((charx = paths[path].first.x) and (chary = paths[path].first.y));
end else
begin
result := ((charx = paths[path].last.x) and (chary = paths[path].last.y));
end;
end;

procedure TakePath(path:integer);
begin
if Distance(charx, chary, paths[path].first.x, paths[path].first.y) < Distance(charx, chary, paths[path].last.x, paths[path].last.y) then
begin
AutoMoveThroughTPA(0, 1, paths[path].node)
end else
begin
AutoMoveThroughTPA(high(paths[path].node), -1, paths[path].node)
end;
end;

function DegreeDiff(A, B:extended):extended;
begin
result:= Abs(A-B);
if result>180.0 then
result:= 180.0-(result-180.0);
end;

function move(x,y:integer):boolean;
var p, n, curpath, lastpath:integer;
c, cd: extended;
node: TPointArray;
begin
c := 360;
arrived := false;
destx := x;
desty := y;
// Get Closest path
curpath := 0;
node := paths[curpath].node;
// Get Closest Point in TPA
p := 3;
// Finish first TPA
cd := AngleBetweenPoints(chary, y, charx, x);
if DegreeDiff(cd,AngleBetweenPoints(node[p+1].y, y,node[p+1].x,x)) < DegreeDiff(cd,AngleBetweenPoints(node[p-1].y, y,node[p-1].x,x)) then
begin
AutoMoveThroughTPA(p+1, 1, node);
end else
begin
AutoMoveThroughTPA(p-1, -1, node);
end;

repeat
cd := AngleBetweenPoints(chary, y, charx, x);
for p := 0 to high(paths[curpath].connection) do
begin
if (c > DegreeDiff(cd, AngleBetweenPoints(y, paths[paths[curpath].connection[p]].avg.y, x, paths[paths[curpath].connection[p]].avg.x))) {and (p <> lastpath) and (Pathable(p) = true)} then
begin
c := AngleBetweenPoints(y, paths[paths[curpath].connection[p]].avg.y, x, paths[paths[curpath].connection[p]].avg.x);
n := p;
end;
c := 360;
TakePath(n);
lastpath := curpath;
curpath := n;
end;
until (arrived = true)

end;

begin
Initialize;
MoveTo(TPt(0,3));
Move(0,7);
end.

Shuttleu

2009-08-08 22:38:51

well if you tell us what the problem is then we may be able to help without having to see if anything goes wrong

~shut

Coh3n

2009-08-09 03:14:36

From: Shuttleu
well if you tell us what the problem is then we may be able to help without having to see if anything goes wrong

~shut


That would help us out greatly. Just looking at your code you have a lot of needless begin..end nests. An if..then statement will do the first line of code below it without a begin..end nest, for example:


if blah then
begin
blah2
end else
begin
blah3
end;

Can become:


if blah then
blah2
else
blah3

See what I mean?

Also, if you want to save some lines, and have your code slightly more advanced, you can load your walk paths like this:


function Paths(i : Integer): TPointArray;
begin
case i of
0: Result := [Point(0, 0), Point(0, 1), Point(0, 2), Point(0, 3), Point(0, 4)
Point(0, 5), Point(0, 6), Point(0, 7)];
1: Result := [Point(0, 0), Point(1, 1), Point(2, 2), Point(3, 3), Point(4, 4)
Point(5, 5), Point(6, 6), Point(7, 7)];
//The rest of the walk paths here...
end;

This way you save a lot of lines, and if you want to load the first path all you have to say is:


Paths(0);

I know you didn't ask for any of that, but I thought I'd just help you out anyway. :) Expanding on your problem would help us out a lot. :)

Cheers!

Feroc1ty

2009-08-09 06:03:17

From: Coh3n
That would help us out greatly. Just looking at your code you have a lot of needless begin..end nests. An if..then statement will do the first line of code below it without a begin..end nest, for example:


if blah then
begin
blah2
end else
begin
blah3
end;

Can become:


if blah then
blah2
else
blah3

See what I mean?

Also, if you want to save some lines, and have your code slightly more advanced, you can load your walk paths like this:


function Paths(i : Integer): TPointArray;
begin
case i of
0: Result := [Point(0, 0), Point(0, 1), Point(0, 2), Point(0, 3), Point(0, 4)
Point(0, 5), Point(0, 6), Point(0, 7)];
1: Result := [Point(0, 0), Point(1, 1), Point(2, 2), Point(3, 3), Point(4, 4)
Point(5, 5), Point(6, 6), Point(7, 7)];
//The rest of the walk paths here...
end;

This way you save a lot of lines, and if you want to load the first path all you have to say is:


Paths(0);

I know you didn't ask for any of that, but I thought I'd just help you out anyway. :) Expanding on your problem would help us out a lot. :)

Cheers!


thanks for your useless post i won't consider any of it

@shut if you ran the code and looked at the result and compared to what it was supposed to do which is quite obvious you'd instantly realize whats wrong unless you're an amateur coder in which case you won't be able to help anyways

Awkwardsaw

2009-08-09 06:25:37

From: Feroc1ty
thanks for your useless post i won't consider any of it

@shut if you ran the code and looked at the result and compared to what it was supposed to do which is quite obvious you'd instantly realize whats wrong unless you're an amateur coder in which case you won't be able to help anyways


i was going to post explaining how to fix it, but after reading that, i dont think i will, and delete my example for you.

Smarter Child

2009-08-09 06:37:11

Wtf, he was just trying to help you improve yourself, i would have helped, but your a sad messed up person.
Just because you suck, and you know he's better than you, you have to be so rude?

And shuttleu is much better than you :).

Edit: Sorry if i was rude, but you were rude to Coh3n, so it gives me the right to be rude to you. If you apologize i will apologize too.

Awkwardsaw

2009-08-09 06:39:34

From: Smarter Child
Wtf, he was just trying to help you improve yourself, i would have helped, but your a sad messed up person.
Just because you suck, and you know he's better than you, you have to be so rude?

And shuttleu i much better than you :).


that was a little rude too :(

Sean[714]

2009-08-09 06:41:06

From: Feroc1ty
thanks for your useless post i won't consider any of it

@shut if you ran the code and looked at the result and compared to what it was supposed to do which is quite obvious you'd instantly realize whats wrong unless you're an amateur coder in which case you won't be able to help anyways



wow.. if i was a admin you would be banned right now. our comunity dosnt need imature children like yourself

Edit: oops.. this is Lance, i didnt realize that i was logged into oo00o. hes my brother and im on his computer atm xP

Coh3n

2009-08-09 06:51:19

From: Feroc1ty
thanks for your useless post i won't consider any of it


Good luck gaining respect in this community with that attitude, I'll be sure not to help you out next time, I apologize.

From: Awkwardsaw
that was a little rude too :(


He was just making a point, considering what Feroc1ty said, I wouldn't consider that rude at all.

ZaSz

2009-08-09 07:17:33

From: Feroc1ty
thanks for your useless post i won't consider any of it

@shut if you ran the code and looked at the result and compared to what it was supposed to do which is quite obvious you'd instantly realize whats wrong unless you're an amateur coder in which case you won't be able to help anyways


You insulted members… That were both really trying help…

If you applied for members right now, I would vote no even if the script was 100% perfect.

Feroc1ty

2009-08-09 08:00:17

From: ZaSz
You insulted members… That were both really trying help…

If you applied for members right now, I would vote no even if the script was 100% perfect.


as if anyone cares what you have to say, you're a nobody.

and akward, considering how bad you are, theres no way you knew the solution, so your post didnt make me feel bad in any way, just put a smirk on my face for your attempt at what you so call trolling

Coh3n

2009-08-09 08:05:12

From: Feroc1ty
as if anyone cares what you have to say, you're a nobody.

and akward, considering how bad you are, theres no way you knew the solution, so your post didnt make me feel bad in any way, just put a smirk on my face for your attempt at what you so call trolling


Your asking for a ban. Disrespect to anyone on these forums are highly frowned upon, whether you think you're superior to them or not.

Feroc1ty

2009-08-09 08:07:36

From: Coh3n
Your asking for a ban. Disrespect to anyone on these forums are highly frowned upon, whether you think you're superior to them or not.


think? I know.

Coh3n

2009-08-09 08:09:54

From: Feroc1ty
think? I know.


Okay.

ZaSz

2009-08-09 08:26:38

From: Feroc1ty
think? I know.


Then wtf is wrong with you.

ZephyrsFury

2009-08-09 08:31:40

You, Feroc1ty, never seem to understand that flaming people who try to help you won't get you anywhere. Furthermore your arrogance is getting on my nerves…

bullzeye95

2009-08-09 10:15:30

From: ZephyrsFury
You, Feroc1ty, never seem to understand that flaming people who try to help you won't get you anywhere. Furthermore your arrogance is getting on my nerves…


I suggest you ban him temporarily. If this doesn't stop him from being rude, make it permanent. Everybody complaining won't solve anything. He obviously doesn't care.

Feroc1ty

2009-08-09 10:43:50

From: bullzeye95
I suggest you ban him temporarily. If this doesn't stop him from being rude, make it permanent. Everybody complaining won't solve anything. He obviously doesn't care.


And you care enough to post something offtopic?

Every single post here is offtopic, not a single one points out the issue, or even attempts to solve the issue; a couple people somewhat tried to help but their attempts were utter failures that ended up discriminating my code when it's fine the way it is.

ZephyrsFury

2009-08-09 10:49:57

I guess since everyone here is too stupid and inferior to you there is no point in keeping this thread open.