euphemism

ClimbStairs(): Boolean;

Dec 4th, 2011
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 2.66 KB | None | 0 0
  1. function StairAutoColor(var TheColor: Integer): Boolean;
  2. var
  3.   arP: TPointArray;
  4.   arC: TIntegerArray;
  5.   tmpCTS, i, arL: Integer;
  6.   X, Y, Z: Extended;
  7. begin
  8.   tmpCTS := GetColorToleranceSpeed;
  9.   ColorToleranceSpeed(2);
  10.   SetColorSpeed2Modifiers(0.18, 0.14);
  11.  
  12.   FindColorsSpiralTolerance(MMCX, MMCY, arP, 5332585, MMX1, MMY1, MMX2, MMY2, 4);
  13.   if (Length(arP) = 0) then
  14.   begin
  15.     Result := False;
  16.     ColorToleranceSpeed(tmpCTS);
  17.     SetColorSpeed2Modifiers(0.2, 0.2);
  18.     Exit;
  19.   end;
  20.  
  21.   arC := GetColors(arP);
  22.   ClearSameIntegers(arC);
  23.   arL := High(arC);
  24.  
  25.   for i := 0 to arL do
  26.   begin
  27.     ColorToXYZ(arC[i], X, Y, Z);
  28.  
  29.     if (X >= 9.37) and (X <= 13.60) and (Y >= 9.62) and (Y <= 13.87) and (Z >= 7.82) and (Z <= 11.21) then
  30.     begin
  31.       TheColor := arC[i];
  32.       Result := True;
  33.       Break;
  34.     end;
  35.   end;
  36.  
  37.   ColorToleranceSpeed(tmpCTS);
  38.   SetColorSpeed2Modifiers(0.2, 0.2);
  39.  
  40.   if (i = arL + 1) then
  41.     Result := False;
  42. end;
  43.  
  44. function ClimbStairs(GoingUp: Boolean): Boolean;
  45. var
  46.   CTS, I, Len, StairColor, Tol, X, Y: Integer;
  47.   Hue, Sat: Extended;
  48.   StairOptions, UpTextOptions: TStringArray;
  49.   StairCenters, StairTPA: TPointArray;
  50.   StairATPA: T2DPointArray;
  51. begin
  52.  
  53.   Result := False;
  54.  
  55.   if not StairAutoColor(StairColor) then
  56.     StairColor := 5332585;
  57.  
  58.   Hue := 0.18; Sat := 0.14; Tol := 4;
  59.   UpTextOptions := ['limb', 'air', 'case', 'stair'];
  60.  
  61.   if GoingUp then
  62.     StairOptions := ['Climb-up', 'up', 'b-u']
  63.   else
  64.     StairOptions := ['Climb-down', 'down', 'b-d', 'ow'];
  65.  
  66.   CTS := GetColorToleranceSpeed;
  67.   SetColorToleranceSpeed(2);
  68.   SetColorSpeed2Modifiers(Hue, Sat);
  69.  
  70.   while Tol < 30 do
  71.   begin
  72.  
  73.     if not FindColorsTolerance(StairTPA, StairColor, MSX1, MSY1, MSX2, MSY2, Tol)
  74.      then
  75.       IncEx(Tol, 5)
  76.     else
  77.       Break;
  78.   end;
  79.  
  80.   if Length(StairTPA) = 0 then
  81.     Exit;
  82.  
  83.   SetColorSpeed2Modifiers(0.2, 0.2);
  84.   SetColorToleranceSpeed(CTS);
  85.  
  86.   SplitTPAExWrap(StairTPA, 24, 24, StairATPA);
  87.   SortATPASize(StairATPA, True);
  88.  
  89.   Len := Length(StairATPA);
  90.   SetLength(StairCenters, Len);
  91.  
  92.   for I := 0 to (Len - 1) do
  93.     StairCenters[i] := MiddleTPA(StairATPA[i]);
  94.  
  95.   for I := 0 to (Len - 1) do
  96.   begin
  97.  
  98.     MouseBox(StairCenters[i].x - 8, StairCenters[i].y - 8,
  99.      StairCenters[i].x + 10, StairCenters[i].y + 10, 3);
  100.  
  101.     if not WaitUpTextMulti(UpTextOptions, 500) then
  102.       Continue;
  103.  
  104.     GetMousePos(X, Y);
  105.     Mouse(X, Y, 0, 0, False);
  106.  
  107.     if WaitOptionMulti(StairOptions, 500) then
  108.     begin
  109.  
  110.       SMART_DrawDotsEx(True, StairATPA[i], clWhite);
  111.       Wait(800 + Random(300));
  112.       ClearRSCanvas(SMART_Canvas.canvas);
  113.  
  114.       Result := True;
  115.       Break;
  116.     end;
  117.   end;
  118. end;
Advertisement
Add Comment
Please, Sign In to add comment