PDA

View Full Version : MakeCompassEx



BobboHobbo
03-05-2008, 11:37 AM
I dont know if has been made, but here it is. Just has Nw, Se,Ne and so on degrees added to the normal MakeCompass.

function MakeCompassEx(Direction: string): Boolean;
var
StartAngle, Angle, DirectionDeg, i: Extended;
Left: Boolean;
Mark, DirectionDegBH: Integer;
begin
Result := False;
StartAngle := (rs_GetCompassAngleDegrees);
if (StartAngle < 0) or (not LoggedIn) then Exit;
try
DirectionDeg := FixD(StrToFloat(Direction));
except
case LowerCase(Direction) of
'n': DirectionDeg := 0;
'w': DirectionDeg := 90;
's': DirectionDeg := 180;
'e': DirectionDeg := 270;
'nw': DirectionDeg := 30;
'ne': DirectionDeg := 330;
'sw': DirectionDeg := 135;
'se': DirectionDeg := 225;
end;
end;
if (MinE(Abs(StartAngle - DirectionDeg), MinE(Abs(StartAngle - (DirectionDeg + 360)), Abs((StartAngle + 360) - DirectionDeg)))) <= 8.0 then
begin
Result := True;
Exit;
end;
Left := (Round((360 - StartAngle) + DirectionDeg) mod 360 > Round((StartAngle + 360) - DirectionDeg) mod 360);
if Left then
KeyDown(VK_LEFT)
else
KeyDown(VK_RIGHT);
Wait(10);
MarkTime(Mark);
repeat
Wait(1);
Angle := rs_GetCompassAngleDegrees;
if ((TimeFromMark(Mark) > 6000) and (i < 1.0)) or
((TimeFromMark(Mark) > 10000) and (i < 2.0)) or
((TimeFromMark(Mark) > 14000) and (i < 3.0)) then
begin
i := i + 1.0;
end;
until ((MinE(Abs(Angle - DirectionDeg), MinE(Abs(Angle - (DirectionDeg + 360)), Abs((Angle + 360) - DirectionDeg)))) <= (7.0 + i))
or (TimeFromMark(Mark) > 14000)
or (Angle < 0);
if Left then
KeyUp(VK_Left)
else
KeyUp(VK_Right);
Wait(10);
Result := ((MinE(Abs(Angle - DirectionDeg), MinE(Abs(Angle - (DirectionDeg + 360)), Abs((Angle + 360) - DirectionDeg)))) <= (7.0 + i));
end;

malotthouse
03-05-2008, 01:20 PM
It looks good. I don't really know why u would use anything other than the cardinal directions unless your like radial walking and want the thing between north and east.

but i might use it for kicks and giggles

JuKKa
03-05-2008, 01:23 PM
why not just enter

MakeCompass('45');

etc?

n3ss3s
03-05-2008, 01:33 PM
BH, North is 0, West is 270, South is 180, and East is 90.

NorthEast = 45
NorthWest = 315
SouthWest = 225
SouthEast = 135

PriSoner
03-05-2008, 01:41 PM
BH, North is 0, West is 270, South is 180, and East is 90.

NorthEast = 45
NorthWest = 315
SouthWest = 225
SouthEast = 135

Under normal circumstances that would be true however MakeCompass and rs_GetCompassAngleDegrees do not follow the conventional clockwise but works in the reverse... Confused me no end when I was writing my compass functions!! :confused:

BobboHobbo is still wrong though with ne & nw. Just a minor error.

The Relavent section should be:

'n': DirectionDeg := 0;
'w': DirectionDeg := 90;
's': DirectionDeg := 180;
'e': DirectionDeg := 270;
'nw': DirectionDeg := 45;
'ne': DirectionDeg := 315;
'sw': DirectionDeg := 135;
'se': DirectionDeg := 225;

Personally i think just using degrees gives you much more flexibility, however given that they are in reverse this would avoid confusion for many.

mastaraymond
03-06-2008, 02:44 PM
Compasses are different than math circles..

They turn to the other side ^^

Compass:

http://www.ke4nyv.com/compass.jpg

Unit circle:

http://upload.wikimedia.org/wikipedia/commons/thumb/c/c9/Unit_circle_angles.svg/600px-Unit_circle_angles.svg.png

n3ss3s
03-06-2008, 02:56 PM
Also, if we are dealing with a 0..360 circle, you can't just say that for example NW is 45, because it doesn't matter in which direction you go, NW is always 315. AFAIK?



program New;
begin
Writeln(FloatToStr(Degrees(ArcTan2(-1 , 1))));
end.


There. -45, not 45.

So, if you calculate the point on the arc using Sin and Cos, it's the same wether you use -45 or 315, but not 45. :)

PriSoner
03-06-2008, 06:42 PM
Compasses are different than math circles..

They turn to the other side ^^

Yes i know.. my point was that we are dealing with Compass functions and not maths circles.. therefore you would expect inputting degrees into a Compass function to conform to Compass specifications and not Maths Circles..

Anyway the current Compass fuctions don't even conform the the Maths circle standard as they have been rotated by counter-clockwise by 90 degrees to make 0 degrees North :confused: ...

It confused me greatly, because when I wrote my function I went to the trouble of making the degrees coresspond to the Compass standard only to find out that none of the other compass functions in SRL were compatible..:duh:

n3ss3s
03-06-2008, 07:09 PM
I don't understand what you're saying... Look, if Rs_GetCompassAngleDegrees returns 270, and you make the compass 180, you made it point South.

mastaraymond
03-06-2008, 07:13 PM
Thats why we need some conversion to use ArcTan, sin and cos on Compass functions..

tarajunky
03-06-2008, 07:42 PM
LOL, I tried and tried to change the compass numbers. Every time I would make them conform to an actual compass and then adjust all the relevant functions to work with it, someone would screw something up and then change it back. Oh well.

SRL's compass output has always been "degrees compass is rotated to the right" or some weird definition.

So when you're facing west, the compass is rotated 90 degrees to the right. When facing east, the compass is rotated 270 degrees to the right. Etc.

PriSoner
03-06-2008, 07:56 PM
I don't understand what you're saying... Look, if Rs_GetCompassAngleDegrees returns 270, and you make the compass 180, you made it point South.

yes making compass 180 makes it point south which is correct regardless.

but if you MakeCompass('90'); it points West instead of East.

and if as you say you use rs_GetCompassAngleDegrees and it returns 270 you are actually pointing East wheras on a Compass 270 degree would mean you were pointing West..

mastaraymond
03-06-2008, 08:34 PM
yes making compass 180 makes it point south which is correct regardless.

but if you MakeCompass('90'); it points West instead of East.

and if as you say you use rs_GetCompassAngleDegrees and it returns 270 you are actually pointing East wheras on a Compass 270 degree would mean you were pointing West..
Then you dont know howto read the compass.. (I guess....).

Look at this images, should explain all. The red line on the MM Compass is the north..

http://i30.tinypic.com/2uyklzm.jpg

Basicly, its the "inner" circle that turns around, while the "outside" of the circle (the one with the degrees) stands at an set position..

tarajunky
03-06-2008, 10:07 PM
The compass pointer can't point West. It can only point North. That's what a compass does. So in your example, the point of the compass is pointing North (LEFT), and the player is facing East (UP). Since you're facing East, and since East is at 90 degrees on your standard reference compass, why should the angle function return anything but 90?

It comes down to whether you want to the angle function to tell you which angle you're facing, or which angle the compass pointer is pointing. RS used to have NESW letters on the compass without any pointer. Would the current angle system make any sense at all if the pointer went away?

No, it wouldn't because the current system is backwards.

PriSoner
03-07-2008, 01:21 AM
at the end of the day this is all irrelevant, it's wrong but it's so engrained it realistically couldn't be fixed without screwing up a lot of scripts..

the only time it should/could be fixed is with SRL5