SRL Archive - SRL Suggestions

procedure TurnToNearestNPC();


mr. pali

2012-12-29 15:59:45

Hey so I recently got some code to work for this. Included is some Smart_Draw to show proof of concept. It can be removed. The function goes something like this: (I found it helpful for my autofighter). Its a two function/procedure thingy, it could easily be condensed into one.



function TurnToMMPoint(P: TPoint,minRandomnessDegrees, maxRandomnessDegrees : integer): Extended;
var //credits to Fl1ght. co-written by mr. pali
d, current,final :extended;
begin
d := ArcTan2((P.Y - MMCY), (P.X - MMCX ));
Result := degrees((fixRad(d-Pi)))- 90;
Result := radians(result);
current := rs_GetCompassAngleDegrees();
current := radians(current);
final := (Result + current);
final:= degrees(final);
MakeCompass(final + randomrange(minRandomnessDegrees , maxRandomnessDegrees))
DebugLines('Turning to nearest NPC');
end;

procedure turnToNpc();
var // creds to p1ng. co-written by mr. pali
i:integer;
NPCArray : TPointArray;
NPCPoint:Tpoint;
begin
NPCArray := GetMinimapDots('NPC');
if Length(NPCArray) < 1 then
Exit;
SortTPAFrom(NPCArray, Point(MMCX, MMCY));
for i := 0 to High(NPCArray) do
begin
NPCPoint := NPCArray[i];

SMART_ClearCanvasArea(IntToBox(524,7,709,159));
SMART_DrawBoxEx(false,false,IntToBox((NPCPoint.x)-3,(NPCPoint.y)-3,(NPCPoint.x)+3,(NPCPoint.y)+3),ClYellow);
SMART_Drawline(false,NPCPoint,point(MMCX,MMCY),CLRed);
SMART_DrawLine(false,point(MMCX,7),point(MMCX,MMCY),CLBlue);

TurnToMMPoint(NPCPoint,-10,10);
exit;
end;
end;


If someone higher up wanted to clean this up and submit it to the SRL include, I'd be a happy camper :).

Ian

2012-12-29 16:02:03

Looks handy. You could put it in Snippets :)

Gu3st...

2012-12-29 16:06:03

The original function TurnToMMPoint that Flight posted: Can you post it here? I think that one is much neater and should work just fine.

mr. pali

2012-12-29 16:16:59

From: Zyt3x
The original function TurnToMMPoint that Flight posted: Can you post it here? I think that one is much neater and should work just fine.


that function didn't work for me, i spent an hour or two modifying it to this point, where it is working.

the problem was, his function didn't take into account the current compass position.


function TurnToMMPoint(P: TPoint): Extended; //by flight
begin
Result := ArcTan2((P.Y - MMCY), (P.X - MMCX));
Result := (Degrees(fixRad(Result-Pi))-90);

MakeCompass(Result);
end;

Gu3st...

2012-12-29 16:36:21

From: mr. pali
that function didn't work for me, i spent an hour or two modifying it to this point, where it is working.

the problem was, his function didn't take into account the current compass position.


function TurnToMMPoint(P: TPoint): Extended; //by flight
begin
Result := ArcTan2((P.Y - MMCY), (P.X - MMCX));
Result := (Degrees(fixRad(Result-Pi))-90);

MakeCompass(Result);
end;


function TurnToMMPoint(P: TPoint): Extended; //by flight
begin
Result := ArcTan2((P.Y - MMCY), (P.X - MMCX));
Result := (Degrees(fixRad(Result-Pi))-90);

MakeCompass(rs_GetCurrentCompassDegree - Result);
end;

mr. pali

2012-12-29 17:21:52

Yea but then you're adding degrees and you're gonna have problems. You need to use radians, then at the end convert it to degrees.