Home
2011-10-27 12:01:49
Hello.
Me and euphemism have been working on this function for a while to provide very accurate and time saving ability to use your middlemouse to change Minimap Direction and / or Mainscreen camerangle and vice versa.
Enjoy!
This function sets the compass direction and camera angle by dragging the mouse while holding down the middle mouse button.
[Background]
Movement across the X-axis results in compass change, and movement across the Y-axis results in change of camera angle.
If one swipes from the very left or right of the screen, to the very edge of the other side, the compass swings 180 degrees.
Armed with this knowledge, we can divide that pixel distance (the 'X_Axis' constant) by 180 to find out how far to move along the X-axis, in pixels, to change one degree. This is where the 'DegToPx' constant to come from.
Camera angle is a bit different. The Y-axis change from the top of the screen to the bottom is, if I recall, 333 pixels. If the camera is at either extreme (all the way up, all the way down), and you swipe from the very top or bottom to the other side, you will find that the camera reaches the other extreme after roughly 278 pixels of change, meaning there is a further distance of 55 pixels to cover before reaching the other side of the screen. This means that their is a dead space where camera angle does not change.
Armed with this information, we can divide 278 by however many steps we want available to get from one camera extreme to the other. This is how the variable 'AngleStep' is determined within the function. The variable 'AngleStep' is how far to move along the Y-axis, in pixels, to change the camera angle one camera step. Home and I decided on 10.
[/Background]
The function first gets the compass direction in degrees, and checks to see if either of the parameters have been set to an empty string (''). If the direction is within 3.0 degrees, I think it is, of the direction set by the user, and CameraAngle is '', then it exits. Otherwise, if it is within 3.0 degrees, or is '', and the CameraAngle is a valid number, then the function knows that it is not changing the direction.
If setting the compass direction, the function sees what the shortest way to get to the specified compass direction is and decides to swipe left-to-right, or right-to-left accordingly. It then determines the distance to change across the X-axis to get to the specified compass direction. If setting camera angle, the function decides to start somewhere randomly within 55 pixels of the top or bottom of the mainscreen.
The function takes two mouse swipes to complete. The function takes the determined X change, and splits it randomly into two values: 'XChange1' and 'XChange2'. The first swipe's X change is equal to XChange1', and the Y change is that 278 pixels required to get to one of the camera extremes (It has to do this because we are not able to determine the camera angle). The second swipe's X change is equal to 'XChange2', and the function calculates the Y change required to get to the specified camera angle, and moves that distance across the Y-axis.
Once the function has set the compass direction and camera angle, it then goes back and checks to see if the compass direction is within 3.0 degrees of the specified direction. If not, it performs a third swipe across the X-axis to correct the compass direction.
~Home & euphemism
Me and euphemism have been working on this function for a while to provide very accurate and time saving ability to use your middlemouse to change Minimap Direction and / or Mainscreen camerangle and vice versa.
Enjoy!
This function sets the compass direction and camera angle by dragging the mouse while holding down the middle mouse button.
[Background]
Movement across the X-axis results in compass change, and movement across the Y-axis results in change of camera angle.
If one swipes from the very left or right of the screen, to the very edge of the other side, the compass swings 180 degrees.
Armed with this knowledge, we can divide that pixel distance (the 'X_Axis' constant) by 180 to find out how far to move along the X-axis, in pixels, to change one degree. This is where the 'DegToPx' constant to come from.
Camera angle is a bit different. The Y-axis change from the top of the screen to the bottom is, if I recall, 333 pixels. If the camera is at either extreme (all the way up, all the way down), and you swipe from the very top or bottom to the other side, you will find that the camera reaches the other extreme after roughly 278 pixels of change, meaning there is a further distance of 55 pixels to cover before reaching the other side of the screen. This means that their is a dead space where camera angle does not change.
Armed with this information, we can divide 278 by however many steps we want available to get from one camera extreme to the other. This is how the variable 'AngleStep' is determined within the function. The variable 'AngleStep' is how far to move along the Y-axis, in pixels, to change the camera angle one camera step. Home and I decided on 10.
[/Background]
The function first gets the compass direction in degrees, and checks to see if either of the parameters have been set to an empty string (''). If the direction is within 3.0 degrees, I think it is, of the direction set by the user, and CameraAngle is '', then it exits. Otherwise, if it is within 3.0 degrees, or is '', and the CameraAngle is a valid number, then the function knows that it is not changing the direction.
If setting the compass direction, the function sees what the shortest way to get to the specified compass direction is and decides to swipe left-to-right, or right-to-left accordingly. It then determines the distance to change across the X-axis to get to the specified compass direction. If setting camera angle, the function decides to start somewhere randomly within 55 pixels of the top or bottom of the mainscreen.
The function takes two mouse swipes to complete. The function takes the determined X change, and splits it randomly into two values: 'XChange1' and 'XChange2'. The first swipe's X change is equal to XChange1', and the Y change is that 278 pixels required to get to one of the camera extremes (It has to do this because we are not able to determine the camera angle). The second swipe's X change is equal to 'XChange2', and the function calculates the Y change required to get to the specified camera angle, and moves that distance across the Y-axis.
Once the function has set the compass direction and camera angle, it then goes back and checks to see if the compass direction is within 3.0 degrees of the specified direction. If not, it performs a third swipe across the X-axis to correct the compass direction.
program New;
{$i SRL\SRL.scar}
procedure Setup;
begin
SetupSRL;
ClearDebug;
end;
const
DegToPx = 2.838;
X_Axis = 511;
{*******************************************************************************
function SetScreenMouse(Direction, CameraAngle: Variant) :Boolean;
By: Home & euphemism
Description: Aligns RS to specified direction and camera angle.
Direction: Enter a compass angle ('n', 's', 'e', 'w') or degree (23.3, 25, 205.2)
It will move the compass to that angle using Middle Mouse. Also accepts
'random', and 'rand' to make the compass a random direction.
Use ('') for no movement.
CameraAngle: Enter a camera angle (0 - 10) Ex. ('1') or (1) It will move the
mainscreen to that camera angle using Middle Mouse. (0 lowest, 10 highest)
Use ('') for no movement.
*******************************************************************************}
function SetScreenMouse(Direction, CameraAngle: Variant) :Boolean;
var
ii: Integer;
i, DirectionDeg, StartAngle, Fraction: Extended;
AngleStep, DirFalseSet, FractionInt, NumOfSteps, WaitTime, TempMouse, YStart,
OffX, X, XChange1, XChange2, Y, YChange1, YChange2: Integer;
Left, SetCamera, SetDirection, TopOfScreen: Boolean;
begin
SetCamera := True;
SetDirection := True;
for ii := 0 to 2 do
begin
Result := False;
StartAngle := rs_GetCompassAngleDegrees;
DirFalseSet := 0;
if (StartAngle < 0) or (not LoggedIn) then Exit;
case VarType(Direction) of
varInteger, varDouble: DirectionDeg := FixD(Direction + 0.0);
varString: begin
i := StrToFloatDef(Direction,-1337);
if i = -1337 then
begin
case LowerCase(Direction) of
'n': DirectionDeg := 0;
'w': DirectionDeg := 270;
's': DirectionDeg := 180;
'e': DirectionDeg := 90;
'random', 'rand': DirectionDeg := RandomRange(0, 360);
'' : SetDirection := False;
end;
end else
DirectionDeg := FixD(i);
end;
end;
case VarType(CameraAngle) of
varString:
begin
if CameraAngle = '' then
SetCamera := False
else
CameraAngle := StrToInt(CameraAngle);
end;
end;
i := 0.0;
if ((not SetDirection) and (not SetCamera)) then
begin
Result := True;
Exit
end;
if (((MinE(Abs(StartAngle - DirectionDeg),
MinE(Abs(StartAngle - (DirectionDeg + 360)),
Abs((StartAngle + 360) - DirectionDeg)))) <= 3.0) and (SetCamera)) then
begin
SetDirection := False;
end;
if (((MinE(Abs(StartAngle - DirectionDeg),
MinE(Abs(StartAngle - (DirectionDeg + 360)),
Abs((StartAngle + 360) - DirectionDeg)))) <= 3.0) and (not SetCamera)) then
begin
Result := True;
Exit;
end;
if SetDirection then
begin
Left := (Round((360 - StartAngle) + DirectionDeg)
mod 360 <= Round((StartAngle + 360) - DirectionDeg) mod 360);
WaitTime := RandomRange(30, 90);
if Left then
begin
DirectionDeg := 360 + DirectionDeg - StartAngle;
OffX := - 5;
end else
begin
DirectionDeg := 360 - DirectionDeg + StartAngle;
OffX := 5;
end;
end else
begin
Left := RBool;
end;
if MouseSpeed > 14 then
begin
TempMouse := MouseSpeed
MouseSpeed := RandomRange(14, 15);
end;
if not SetDirection then
Fraction := 1
else
Fraction := DirectionDeg * DegToPx / X_Axis
- Floor(DirectionDeg * DegToPx / X_Axis);
if Fraction > 0 then
begin
FractionInt := Round(MSX2 * Fraction);
if SetDirection then
begin
XChange1 := RandomRange(0, FractionInt);
XChange2 := FractionInt - XChange1;
DirFalseSet := 0;
end else
begin
DirFalseSet := RandomRange(7, 511);
XChange1 := DirFalseSet;
XChange2 := 0;
OffX := 0;
end;
NumOfSteps := 10;
AngleStep := Ceil((278 / NumOfSteps));
TopOfScreen := RBool;
if SetCamera then
begin
CameraAngle := NumOfSteps - CameraAngle;
if TopOfScreen then
begin
YStart := RandomRange(MSY1, MSY1 + 55);
YChange1 := YStart + RandomRange(278, 280);
YChange2 := (CameraAngle * AngleStep) * -1;
end else
begin
YStart := RandomRange(MSY2, MSY2 - 55);
YChange1 := YStart - RandomRange(278, 280);
YChange2 := ((NumOfSteps - CameraAngle) * AngleStep);
end;
end else
begin
YStart := RandomRange(10, 330);
YChange1 := YStart;
YChange2 := 0;
end;
GetMousePos(X, Y);
if ii <> 0 then
begin
MMouse(X, Y, 0, 0);
end else
begin
if not Left then
begin
if not ii <> 0 then
MMouse(MSX2 - DirFalseSet, YStart, 0, 0)
else
MMouse(MSX2, Y, 0, 0);
end else
begin
if not ii <> 0 then
MMouse(MSX1 + DirFalseSet, YStart, 0, 0)
else
MMouse(MSX1, Y, 0, 0);
end;
end;
GetMousePos(X, Y);
HoldMouse(X, Y, mouse_Middle);
Wait(WaitTime);
if ((ii = 0) and (SetCamera))then
begin
if not Left then
begin
MMouse(MSX2 - XChange1, YChange1, 0, 0);
Wait(WaitTime);
GetMousePos(X, Y);
ReleaseMouse(X, Y, mouse_Middle);
Wait(WaitTime);
HoldMouse(MSX2 - XChange1, Y, mouse_Middle);
MMouse(((MSX2 - XChange1) - XChange2 + OffX), Y + YChange2, 0, 0);
end else
begin
MMouse(MSX1 + XChange1, YChange1, 0, 0);
Wait(WaitTime);
GetMousePos(X, Y);
ReleaseMouse(X, Y, mouse_Middle);
Wait(WaitTime);
HoldMouse(MSX1 + XChange1, Y, mouse_Middle);
MMouse(((MSX1 + XChange1) + XChange2 + OffX), Y + YChange2, 0, 0);
end;
end else
begin
if not Left then
MMouse(X - (FractionInt + 5), Y, 0, 0)
else
MMouse(X + (FractionInt - 5), Y, 0, 0);
end;
Wait(WaitTime);
GetMousePos(X, Y);
ReleaseMouse(X, Y, mouse_Middle);
Wait(WaitTime);
end;
SetCamera := False;
end;
MouseSpeed := TempMouse;
end;
var
Direc: String;
Angl: Integer;
begin
Setup;
Direc := IntToStr(RandomRange(0, 360));
Angl := RandomRange(0, 10);
WriteLn('Rotating compass to ' + Direc + ' and setting camera angle to ' + IntToStr(Angl));
SetScreenMouse(Direc, Angl);
end.
~Home & euphemism