SRL Archive - Reflection Discussion

Tiles between A and B


Flight

2011-03-28 22:05:32

Pretty simple question and I'd imagine the snippet to write these tiles is also simple.

Basically, is there a way to dump the tiles' X/Y coordinates between a start tile and end tile? Just writing the X/Y of every tile in between the two points?

i luffs yeww

2011-03-28 22:07:49

I'm confus. Do you mean the size of each tile? Or just.. EndTile.x - StartTile.x; EndTile.y - StartTile.y;?

HarryJames

2011-03-28 22:07:57

Not that I know of, becuase walls and curves would need to be accounted for, so you can either use the pathmaker or a procedure like this;


//HarryJames
Procedure MakePath;
var
me:TMe;
i:Integer;
Begin
writeln('Path := [');
repeat
Begin
Me := GetMe;
writeln('Tile(' + ToStr(Me.Tile.X) + ', ' + ToStr(Me.Tile.Y) + '), ');
wait(3500);
End;
until(false);
End;

Sex

2011-03-28 22:15:37

Um, just a diagonal path or what? It's just math bro :p.

TomTuff

2011-03-28 22:27:46

It handles special cases (Same point, vertical line, horizontal line), but I don't know how to get the angle from PointA to PointB :p If I knew how I could go from there.
procedure LineFromPoints(PointA, PointB: TPoint; var TPA: TPointArray);
var
i: Integer;
P: TPoint;
H: Extended;
begin
if (PointA = PointB) then //Special case: Same Points
begin
SetLength(TPA, 1);
TPA[0] := PointA;
Exit;
end;
if (PointA.x = PointB.x) then //Special Case: Vertical Line
begin
SetLength(TPA, PointB.y - PointA.y + 1);
for i := 0 to High(TPA) do
TPA[i] := Point(PointA.x, PointA.y + i);
Exit;
end;
if (PointA.y = PointB.y) then //Special Case: Horizontal Line
begin
SetLengtH(TPA, PointB.x - PointA.x + 1);
for i := 0 to High(TPA) do
TPA[i] := POint(PointA.x + i, PointA.y);
Exit;
end;
end;

Flight

2011-03-28 22:30:11

Nevermind, I think I'll just write my own. Yes, diagonal path.

footballjds

2011-03-28 22:34:07

From: Flight
Nevermind, I think I'll just write my own. Yes, diagonal path.


Tiles are really TPoints, remember this and you can do anything, maybe even stop world hunger.

Converting 20 tiles into an array of TPoints and then manipulating them is pretty simple :D

Flight

2011-03-28 22:36:32

Yes Tom, that's along the lines of what I'm looking for.

Here's a visual example. The red point is your start tile to end tile, the blue line is the direct path to the tiles. The yellow tiles in is the part I want to find out.


footballjds

2011-03-28 22:42:02

Use the Pythagorean theorem.

the hypotenuse(the diagonal line) relates to the vertical and horizontal line in this fashion:

a*a + b*b = c*c

where a and b are the vertical and horizontal lines and c is the diagonal line. This works for any right angle'd triangle.
and if you always want the true diagonal between those points you will always be able to make an imaginary right triangle to go off of.
if you are confused im a bad teacher.

Flight

2011-03-28 22:44:57

Not just angled paths, vertical and horizontal as well. The angled line I gave as an example was just that, an example.

TomTuff

2011-03-28 22:46:17

From: footballjds
Use the Pythagorean theorem.

the hypotenuse(the diagonal line) relates to the vertical and horizontal line in this fashion:

a*a + b*b = c*c

where a and b are the vertical and horizontal lines and c is the diagonal line. This works for any right angle'd triangle.
and if you always want the true diagonal between those points you will always be able to make an imaginary right triangle to go off of.
if you are confused im a bad teacher.


Or just do Hypot(PointB.x - PointA.x, PointB.y - PointA.y) :) But I don't know how to get the angle to go from PointA - the Pythagorean theorem isn't enough.

Brandon

2011-03-28 23:09:27

Apparently your using dependent on the sin ratios (the Pythagorean theorem) but u also forgot that the cosine and sine laws were derived from it aswell:

a = b² + c² - 2bcCosA

that should do it or:

SinA/a = SinB/b = SinC/c

If u had a picture of what u wanna do, I'd definitely do the math for u since math is my favourite subject along with the sciences… anything else can suck it.

i luffs yeww

2011-03-28 23:11:25

It's incredibly easy to get all of the angles etc., if you're looking at a triangle. But paths aren't even polygons so I'm confus.

Ogre

2011-03-28 23:17:31

The size of the tiles should differ depending on how far from the center of the screen they are, dependent on camera angle shouldn't they? So wouldn't you just want to find the tiles between the two points and use TileToMSEx (the end of the tile minus the beginning) or something like that?

Edit: I may be completely off..

Wanted

2011-03-28 23:18:11

{.include SRL/SRL.scar}
{.include SRL/SRL/misc/debug.scar}

const
X1 = 100;
Y1 = 100;
X2 = 200;
Y2 = 200;

var
TPA: TPointArray;

begin
SetUpSRL;
TPA := TPAFromBox(IntToBox(X1, Y1, X2, Y2));
FilterPointsLine(TPA, (ArcTan2(Y2 - Y1, X2 - X1) + (Pi / 2)), Distance(X1, Y1, X2, Y2), X1, Y1);
DebugTPA(TPA, '');
end.

TRiLeZ

2011-03-28 23:32:03

To find distance of path:

Sqrt(pow(endX - startX, 2) + pow(endY - startY, 2));

Then, calculate x and y steps and move through the line.

Here is my TRiBot code for doing this:

public RSTile[] generateStraightPath(RSTile target) {
ArrayList<RSTile> path = new ArrayList<RSTile>();

RSTile myTile = this.me.character.getPos();
int distance = myTile.distanceTo(target);
if (distance <= 1 || !this.me.calculations.tileToMinimap(target).equals(
new Point(-1, -1)))
return new RSTile[] { target };
int xDist = (target.x > myTile.x ? target.x - myTile.x : myTile.x
- target.x);
int yDist = (target.y > myTile.y ? target.y - myTile.y : myTile.y
- target.y);
int xStep = xDist / distance;
int yStep = yDist / distance;

for (int i = 1; i <= distance; i++) {
int x = (target.x > myTile.x ? myTile.x + (xStep * i) : myTile.x
- (xStep * i));
int y = (target.y > myTile.y ? myTile.y + (yStep * i) : myTile.y
- (yStep * i));
path.add(new RSTile(x, y));
}

return path.toArray(new RSTile[path.size()]);
}

Wanted

2011-03-28 23:51:13

Whoops. Forgot about radian/degree BS.

{.include SRL/SRL.scar}
{.include SRL/SRL/misc/debug.scar}

const
X1 = 100;
Y1 = 100;
X2 = 200;
Y2 = 200;

var
TPA: TPointArray;

begin
SetUpSRL;
TPA := TPAFromBox(IntToBox(X1, Y1, X2, Y2));
FilterPointsLine(TPA, (ArcTan2(Y2 - Y1, X2 - X1) + (Pi / 2)), Distance(X1, Y1, X2, Y2), X1, Y1);
DebugTPA(TPA, '');
end.

I'll post it for Tiles in a sec, I think it might be different for tiles with the TPAFromBox.

Flight

2011-03-29 00:22:49

Thank you TRiLeZ, that's as close to anything as what I was looking for. And thanks everyone else for the suggestions, but I wasn't looking for an angle finder or distance finder. Hence this is I posted under Reflection because I'm I want to work directly with tiles themselves. This "for (int i = 1; i <= distance; i++) {" would give me each tile in between the start and end, and I can go on from there.

Definitely rep+ for you.

Flight

2011-03-29 02:00:30

If you're still around TriLeZ I've another quick question. What is the equivalent of this formula converted to Simba code?

int x = (target.x > myTile.x ? myTile.x + (xStep * i) : myTile.x
- (xStep * i));
int y = (target.y > myTile.y ? myTile.y + (yStep * i) : myTile.y
- (yStep * i));
How would you write that in Simba keeping the target.x/y, myTile.x/y, and x/yStep? I haven't seen a formula written like this before so I'm not sure how to re-write it for Simba.

Ogre

2011-03-29 02:07:57

From: Flight
If you're still around TriLeZ I've another quick question. What is the equivalent of this formula converted to Simba code?

int x = (target.x > myTile.x ? myTile.x + (xStep * i) : myTile.x
- (xStep * i));
int y = (target.y > myTile.y ? myTile.y + (yStep * i) : myTile.y
- (yStep * i));
How would you write that in Simba keeping the target.x/y, myTile.x/y, and x/yStep? I haven't seen a formula written like this before so I'm not sure how to re-write it for Simba.


var
x, y: Integer;
begin
if (target.x > myTile.x) then
x := myTile.x + (xStep * i)
else
x := myTile.x - (xStep * i));
if (target.y > myTile.y) then
y := myTile.y + (yStep * i)
else
myTile.y - (yStep * i));
end;

Flight

2011-03-29 05:30:30

Ah thank you Ogre. Also thanks for throwing in your handful of 'mistakes' in that bit of code. May I ask why?

masterBB

2011-03-29 05:39:23

From: Flight
Ah thank you Ogre. Also thanks for throwing in your handful of 'mistakes' in that bit of code. May I ask why?


He just gave you the perfect translation to simba, don't see no mistakes?

Flight

2011-03-29 05:44:45

From: masterBB
He just gave you the perfect translation to simba, don't see no mistakes?


x := myTile.x + (xStep * i)
^Lacks a comma.
x := myTile.x - (xStep * i));
^1 extra ")"
 y := myTile.y + (yStep * i)
^Lacks a comma.
myTile.y - (yStep * i));
Lacks "y :=" and 1 extra ")"

Emaziz

2011-03-29 05:46:57

From: Flight
x := myTile.x + (xStep * i)
^Lacks a comma.
x := myTile.x - (xStep * i));
^1 extra ")"
 y := myTile.y + (yStep * i)
^Lacks a comma.
myTile.y - (yStep * i));
Lacks "y :=" and 1 extra ")"


Do you know how the "else" statement works? :p

Flight

2011-03-29 05:53:19

Apparently not mate. Like I've mentioned before, Pascal is all so new for me, simple bits of code even like this differs from Java, which is just what I'm accustomed to.

Emaziz

2011-03-29 07:58:54

Sorry, that was a little bit bitchy and I forgot which thread it was :p

if (something) then
writeln('Something!');
else
writeln('Not something!');
That would not compile because the semi colon at writeln('Something') sort of ends the if statement. You need to leave the semi colon out in order to let it compile, like this:
if (something) then
writeln('Something!')
else
writeln('Not something!');

Flight

2011-03-29 08:29:24

Ah right, thanks for that tip, Emaziz. :) I surely did not know that.

Ogre

2011-03-29 12:18:00

Oh lol, sorry about the extra ) and a missing "y :=", dunno why I typed that, and yeah, Emaziz explained the semicolon :)