Log in

View Full Version : Bug in MakeCompass.



mastaraymond
06-30-2007, 06:25 PM
Well this isn't a question but a bug. You all know the MakeCompass command i guess well there is a small bug in it, which means you always turn the long way instead of the small one. To fix this do the following:

Go to Srl\core\MapWalk.scar

at line 94 and 95 you should see this

if StartPos > EndPos then Left_Right := True
else if StartPos < EndPos then Left_Right := False


Change it to:

If (LowerCase(Side) = 'n') or (LowerCase(Side) = 's') then
begin;
if StartPos > EndPos then Left_Right := False
else if StartPos < EndPos then Left_Right := True
else exit;
end else
begin;
if StartPos > EndPos then Left_Right := True
else if StartPos < EndPos then Left_Right := False
else exit;
end;

Now it will always rotate the shortest way :spot:.

rotflmfwao
06-30-2007, 07:41 PM
Thanks!

passiondrive
07-01-2007, 06:36 PM
Nice, not that it makes much of a difference though :p

Starblaster100
07-01-2007, 06:50 PM
Not sure about that, consider these two scenarios:

If our StartPos is 10 degrees and EndPos 330 degrees, then the shortest way will be to rotate leftwards. StartPos < EndPos therefore Left_right will be true.

However, If our StartPos is 350 degrees and EndPos 320 degrees, then the shortest way will be to rotate leftwards. StartPos > EndPos therefore Left_right will be False (This is now not the shortest way to rotate the compass!)

Its not as easy as that ;)

mastaraymond
07-01-2007, 08:51 PM
Not sure about that, consider these two scenarios:

If our StartPos is 10 degrees and EndPos 330 degrees, then the shortest way will be to rotate leftwards. StartPos < EndPos therefore Left_right will be true.

However, If our StartPos is 350 degrees and EndPos 320 degrees, then the shortest way will be to rotate leftwards. StartPos > EndPos therefore Left_right will be False (This is now not the shortest way to rotate the compass!)

Its not as easy as that ;)Yes i know that, i found that problem too. I don't know when i changed this it mostly turns the shortest way. So i consider it as a bug ^^. If you don't, please remove this topic because it doesn't makes sense then. I have got a way to fix this, if you want me to i can do it:p I think it is because i tested it at makeCompass('n') :D

Starblaster100
07-01-2007, 08:59 PM
There is no need to delete the topic. However, if you want to, I know you have the option to delete your own topic.

It's a good challenge - making a procedure to rotate the compass the shortest distance. It took me a good hour to get my head around the maths ;)

nielsie95
07-01-2007, 09:14 PM
How about something like this:


program New;

procedure CompassDir(Start, Angle: Integer);
var
Left: Boolean;
begin
if Min(iAbs((Angle - (360 + Start)) mod 360), iAbs((Angle - (180 + Start)) mod 360)) = iAbs((Angle - (360 + Start)) mod 360) then Left := True;
if Left then WriteLn('Turn Left!') else WriteLn('Turn Right!');
end;

begin
CompassDir(0, 350);
end.


The actual line you need:


Min(iAbs((Angle - (360 + Start)) mod 360), iAbs((Angle - (180 + Start)) mod 360)) = iAbs((Angle - (360 + Start)) mod 360) then Left := True;


Where Start is the Starting angle and Angle is the EndAngle.

mastaraymond
07-01-2007, 09:16 PM
Check first post i found it, it works 100%. Please edit my bug tracker to! I tested it and it works at all angles etc. :D.
change it to:

If (LowerCase(Side) = 'n') or (LowerCase(Side) = 's') then
begin;
if StartPos > EndPos then Left_Right := False
else if StartPos < EndPos then Left_Right := True
else exit;
end else
begin;
if StartPos > EndPos then Left_Right := True
else if StartPos < EndPos then Left_Right := False
else exit;
end;

Venom666
07-01-2007, 09:35 PM
kool, nice work

Esteban
07-05-2007, 04:19 PM
still makes the compass whatever direction the long way.