SRL Archive - SRL Bugs

rs_CompassAngle fix, again


ReadySteadyGo

2011-11-28 16:17:01

(* start math.simba additions *)
type
TVector = record
a: Extended;
b: Extended;
Magnitude: Extended;
end;


function fixRad(rad: Extended): Extended; // by Nava2
var
math_2pi: Extended;
begin
math_2pi := 2*pi;
result := rad;

while (result >= math_2pi) do
result := result - math_2pi;

while (result < 0) do
result := result + math_2pi;
end;

function AngleBetween(v1, v2: TVector): Extended;
var
a1, a2: Extended;
begin
a1 := ArcTan2(v1.b, v1.a);
a2 := ArcTan2(v2.b, v2.a);

Result := fixRad(a1 - a2)
end;


procedure Normalise(var vect: TVector);
begin
vect.a := vect.a / vect.Magnitude;
vect.b := vect.b / vect.Magnitude;
vect.Magnitude := 1;
end;

function CreateVector(Origin, vPoint: TPoint; NormaliseV: Boolean): TVector;
begin
Result.a := vPoint.x - Origin.x;
Result.b := 0 - (vPoint.y - Origin.y); // inverts y axis as well
Result.Magnitude := Sqrt(Sqr(Result.a) + Sqr(Result.b));
if NormaliseV then
Normalise(Result);
end;

(* end math.simba additions *)

function rs_GetCompassAngleRadians: Extended;
var
tpa: TPointArray;
atpa: T2DPointArray;
i, h, l: Integer;
VectorArray: Array of TVector;
RefPoint: TPoint;
angles: TExtendedArray;
math_2pi: Extended;
begin
math_2pi := 2*pi;

{ Colour of 3 E/S/W dots }
FindColorsTolerance(tpa, 2370604, 529, 9, 558, 39, 0);

atpa := SplitTPA(tpa, 1);

h := High(atpa);
setLength(tpa, h+1);
l := 0;
for i := 0 to h do
{ Gets rid of dots under length of 3 and get the MiddleTPA }
if high(atpa[i]) > 4 then
begin
tpa[l] := MiddleTPA(atpa[i]);
inc(l);
end;

if l <> 3 then
Exit;

setLength(tpa, l);

FilterPointsDist(tpa, 9, 20, 543, 24);

SetLength(VectorArray, 3);

for i := 0 to 2 do
VectorArray[i] := CreateVector(Point(543, 24), tpa[i], True);

angles := [AngleBetween(VectorArray[0], VectorArray[1]),
AngleBetween(VectorArray[1], VectorArray[2]),
AngleBetween(VectorArray[2], VectorArray[0])];

for i := 0 to 2 do
begin
if angles[i] > pi then
angles[i] := math_2pi - angles[i];
{ compare angle between, > 100 then it's the south dot }
if angles[i] > radians(100) then
begin
case i of
0: RefPoint := tpa[2];
1: RefPoint := tpa[0];
2: RefPoint := tpa[1];
end;
{ break the loop, we have reference pt. }
break;
end;
end;


{ Using the south dot to measure compass angle.. }
Result := ArcTan2(-(RefPoint.Y - 24), RefPoint.X - 543) - Radians(80);
Result := fixRad(Result - Pi - 0.05*Pi);
end;

function rs_GetCompassAngleDegrees: Extended;
begin
Result := Degrees(rs_GetCompassAngleRadians());
end;

weequ

2011-11-28 16:50:35

Excellent. So this version works?

Coh3n

2011-11-28 17:41:25

What's the difference between this and the other one you posted. Also, you could have just posted on the same thread, no need for a new one.

ReadySteadyGo

2011-11-28 17:48:51

Compass was updated in rs, the difference is the colour and filterpointsdist. Wiz said to just post a new thread.

Coh3n

2011-11-28 17:49:29

Alright. I'll commit this now.

rswiz

2011-11-28 18:15:22

how do i do this, do i just add it in somewhere? plz help =P

Coh3n

2011-11-28 18:21:47

It has been added to SRL, just wait for you SRL to automatically update.

YoHoJo

2011-11-28 18:21:55

Since the thread title now says [Committed] that means it was added to SRL.
So if you just go to Simaba, click the SRL tab, and click update it will update it for you (but it does take a few minutes before simba recognized there was an update if you see the sane number for local version and remote version when you update, or if you see no update available, then you need to wait a few more minutes before you try updating again.
SRL Updater: Local Version - "834" | Remote Version = "834"

Coh3n

2011-11-28 19:10:51

This didn't work for me at all. It returned 0 when I was around 180 degrees which caused SPS to fail.

Wyn

2011-11-28 19:17:32

From: Coh3n
This didn't work for me at all. It returned 0 when I was around 180 degrees which caused SPS to fail.


Ditto.

Gu3st...

2011-11-28 19:22:44

From: Coh3n
This didn't work for me at all. It returned 0 when I was around 180 degrees which caused SPS to fail.
You didn't test it before committing it?

Coh3n

2011-11-28 19:37:41

For the first time ever. The only thing changed was the colour and I assumed it was tested before posted.

That's my mistake.

Gu3st...

2011-11-28 19:41:19

From: Coh3n
For the first time ever. The only thing changed was the colour and I assumed it was tested before posted.

That's my mistake.
Even the best can make mistakes :)

ReadySteadyGo

2011-11-28 19:48:55

This is so weird. Perhaps the colours are dynamic. Of course I tested it, I'm not just blindly committing a fix…

Coh3n

2011-11-28 19:54:14

From: ReadySteadyGo
This is so weird. Perhaps the colours are dynamic. Of course I tested it, I'm not just blindly committing a fix…
Shush! :fiery:

Brandon

2011-11-28 19:56:47

Definitely doesn't work.. if anything, it made scripts worse.. My script no longer runs to the middle but rather to the very far left on minimap lol. reverted back to normal :P and now it rotates and can't stop.

Flight

2011-11-28 20:12:14

I say for now we use Fakawi's way of getting to North and remove the angle check (?) in SPS. I'll give it a shot to make sure it works.

Coh3n

2011-11-28 20:20:56

Removing the angle check in SPS will work, but it will slow things down because there's a 1-2 second wait in SetAngle no matter what.

DaWu

2011-11-28 20:29:18

Just revert to old one, it works for clickNorth atleast, and makes sps work as long as u dont rotate.

Flight

2011-11-28 20:30:25

Yeah that'll present itself as a problem later on with scripts that make good use of random camera movement. For the record I disabled SPS's angle check, added Fakawi's North procedure and put in a SetAngle and it's working fine for me so far, but I only call it once upon logging in initially or after a break.

Just another random idea but… could we not do something along the lines of making a rough bitmap of the "N" symbol on the MM and checking if that bitmap is within a coordinate range to tell us if we're facing north or not? We have BitmapRotated, ect… I know it would be limited to north only, but if it worked that should take care of SPS.

Harry

2011-11-28 20:30:55

Fakawi's needs some failsafes, if anyone's going to commit it ;)

Coh3n

2011-11-28 21:12:38

I fixed this. ReadySteadyGo was using a tolerance of 0 which I changed to 5. He also used "if (length <> 3) then" and I switched to "if (length < 3) then". From what I tested, it works, so please let me know when your guys' SRL updates.

funnyman9292

2011-11-28 21:23:43

From: Coh3n
From what I tested, it works, so please let me know when your guys' SRL updates.
My SLR updated and i'm still running into the same problem, also when im attacking shifters or whatever their called the script constantly right clicks to attack them. It will do that until they die. Also the bot seems to be confused and sometimes is unable to find the enemy and instead right clicks in the center of my screen. This doesnt slow stuff down it just pretty much screams that i'm a bot.

Coh3n

2011-11-28 21:29:09

From: funnyman9292
My SLR updated and i'm still running into the same problem, also when im attacking shifters or whatever their called the script constantly right clicks to attack them. It will do that until they die. Also the bot seems to be confused and sometimes is unable to find the enemy and instead right clicks in the center of my screen. This doesnt slow stuff down it just pretty much screams that i'm a bot.
I committed this like 5 minutes ago. Your update was probably from an earlier update. The shifter thing has nothing to do with this, it's something you have to post on the thread from which you downloaded the script.

euphemism

2011-11-28 21:31:18

From: funnyman9292
My SLR updated and i'm still running into the same problem, also when im attacking shifters or whatever their called the script constantly right clicks to attack them. It will do that until they die. Also the bot seems to be confused and sometimes is unable to find the enemy and instead right clicks in the center of my screen. This doesnt slow stuff down it just pretty much screams that i'm a bot.


You are still running into compass rotation/accuracy issues? Also, the rest of your post is detailing problems with Weequ's Pest Controller. Notice the title of this thread "[Committed] rs_CompassAngle fix, again" this thread is about fixing the compass, not Weequ's script. Please post in the script's thread if you are having problems with it.

E: Ninja'd by Coh3n <3

grats

2011-11-28 21:32:55

is this the reason for constant spinning in scripts that use compass angle?

been out most of today it looks like the compass changed

yea doesn't seem to work for me either

Coh3n

2011-11-28 21:36:16

I think so yes, and it wasn't working all the time. Everything should be fine in the next SRL update.

Wyn

2011-11-28 22:28:35

From: Coh3n
I think so yes, and it wasn't working all the time. Everything should be fine in the next SRL update.


Can you atleast post the fix so I don't need to wait a random hour…?

Narcle

2011-12-03 17:47:08

This has been giving some people out of range errors. I looked it over and got into it. This is my revised compass:

Function rs_GetCompassAngleRadians: Extended;
var
TPA: TPointArray;
T, M: TPoint;
B: TBox;
S: Extended;
begin
B := IntToBox(529, 9, 557, 39);
with B do
FindColorsSpiralTolerance(T.x, T.y, TPA,65536, x1, y1, x2, y2, 0);
if Length(TPA) < 1 then
Exit;
M := MiddleBox(B);
T := MiddleTPA(TPA);
Result := ArcTan2(-(T.Y - M.Y), T.X - M.X+0.5) + Radians(90);
Result := fixRad(Result - Pi);
end;

Its only off by 2.6 degrees instead of over 5 when a pixel shift happens.