I have recoded all turning to be by keyboard, and have refined it to where it works very nicely.
For those of you who can't wait until the next version, here is the code to replace.
Go into the RunToLocs file and Replace the TurnToAngle() function with this code.
Code: Select all
'---------------------------------------------------------------------------
'---------------------------------------------------------------------------
' Turns using Keyboard
Sub TurnToAngle(angle)
Dim i, x, y, a, a2, savA, TurnTimer, howClose
Dim kLeft, kRight, factor, t
' Might want to make them INI's if people are remapping the arrow keys, but I don't find that likely
kRight=VirtualKey.VK_RIGHT
kLeft=VirtualKey.VK_LEFT
' howClose is set to what is considered an angle match.
' you can set it to 0 when you are reading the locs from the back-end and it doesn't do a /loc
' but when it does, set it to something higher - say 5
howClose=1
objDebug.Print "*** TurnToAngle(" & angle & ")", 0
Set TurnTimer = New TimerClass
Call TurnTimer.SetDebugLevel(2) ' We don't want to see all the details of this timer...
Call TurnTimer.StartTimer("TurnTimer", 10) ' Should never take more than 10 seconds to turn!!
Do While (TRUE)
if(TurnTimer.TimerCheck()) then
objDebug.Print "*** ERROR: Timed out in TurnToAngle(10 seconds) - should never happen!!", 0
exit Do
end if
GetLocation()
a = angle-CurLoc.GetDir()
objDebug.Print "Turn to: " & angle & " - CUR ANGLE: " & CurLoc.GetDir() & " Angle Diff: " & a, 0
objDebug.Print "Angle Diff=" & a, 0
if Abs(a) > 180 then
savA = a
a = 360-Abs(a)
' Have to reverse the angle
if (savA > 0) then
a=a*-1
end if
objDebug.Print "Angle Diff (after converting to < 180)=" & a, 0
end if
StatusBar2("Turn to: " & angle & " - CUR ANGLE: " & CurLoc.GetDir() & " Angle Diff: " & a)
if abs(a) <= howClose then
objDebug.Print "WE are there! HowClose=" & howClose & " abs(a)=" & abs(a), 0
exit Do
end if
'Pause(2000)
a2 = Abs(a)
if a2 >=0 and a2 < 3 then factor = 0.06 end if
if a2 >=3 and a2 < 10 then factor = 0.07 end if
if a2 >=10 and a2 < 20 then factor = 0.08 end if
if a2 >=20 and a2 < 30 then factor = 0.09 end if
if a2 >=30 and a2 < 40 then factor = 0.10 end if
if a2 >=40 and a2 < 50 then factor = 0.11 end if
if a2 >=50 and a2 < 60 then factor = 0.125 end if
if a2 >=60 and a2 < 70 then factor = 0.13 end if
if a2 >=70 and a2 < 80 then factor = 0.135 end if
if a2 >=80 then factor = 0.14 end if
t = a2 / factor
objDebug.Print "A2=" & a2 & " factor=" & factor & " t=" & t, 0
if a > 0 then
objDebug.Print "+ TURN RIGHT Turning MS=" & t, 0
XUScriptHost.KeyDown(CInt(kRight))
Pause(t)
XUScriptHost.KeyUp(CInt(kRight))
else
objDebug.Print "- TURN LEFT Turning MS=" & t, 0
XUScriptHost.KeyDown(CInt(kLeft))
Pause(t)
XUScriptHost.KeyUp(CInt(kLeft))
end if
if (CheckForAdd()) then
exit sub ' If we got jumped - exit and FIGHT!
end if
Loop
end Sub
Tell me how it works for you.
Rich