Results 1 to 7 of 7

Thread: Useless code in AutoColor.scar

  1. #1
    Join Date
    Mar 2007
    Posts
    3,116
    Mentioned
    0 Post(s)
    Quoted
    2 Post(s)

    Default Useless code in AutoColor.scar

    You don't need that 3 lines for changing a color to rgb. Just do ColorToRGB(TestColor, Red, Green, Blue)Heres a all changed one:
    SCAR Code:
    //-----------------------------------------------------------------//
    //--               Scar Standard Resource Library                --//
    //--               » AutoColorFinding Routines                   --//
    //-----------------------------------------------------------------//

    //  » function  FindWaterColor: Integer;                                            | by Tarajunky
    //  » function  FindRoadColor: Integer;                                             | by Tarajunky
    //  » function  FindVarrockRoadColor: Integer;                                      | by Tarajunky
    //  » function  FindFallyRoadColor: Integer;                                        | by Tarajunky
    //  » function  FindRockColor: Integer;                                             | by Tarajunky
    //  » function  FindStoneColor: Integer;                                            | by Tarajunky
    //  » function  FindDirtRoadColor: Integer;                                         | by Tarajunky
    //  » function  FindBridgeColor: Integer;                                           | by Tarajunky
    //  » function  FindLadderColor: Integer;                                           | by Tarajunky
    //  » function  AutoColorThis(Bitmap, MaxTol, X1, Y1, X2, Y2:Integer) : integer;    | by Sumilion

    {*******************************************************************************
    function FindWaterColor: Integer;
    By: Tarajunky
    Description: Autodetects Water Color on Minimap
    *******************************************************************************}


    function FindWaterColor: Integer;
    var
      GC, a, l, TestColor, Red, Green, Blue : integer;
    var
      P:array of Tpoint;
    begin
      GC := 12095356;
      Flag;
      FindColorsSpiralTolerance(MMCX, MMCY, P, GC, MMX1, MMY1, MMX2, MMY2, 60);
      l:=GetArrayLength(P);
      for a:= 0 to l-1 do
      begin
        if rs_OnMinimap(P[a].x,P[a].y) then
        begin
          TestColor := GetColor(P[a].x,P[a].y);
          if SimilarColors(TestColor,GC,50) then
          begin
            ColorToRGB(TestColor, Red, Green, Blue)
            if Green - Red <= 33 then if Green - Red >= 18 then
              if Blue - Red >= 55 then if Blue - Red <= 72 then
                if Blue - Green >= 33 then if Blue - Green <= 52 then
                  if GetColor(P[a].x + 2, P[a].y + 2) = TestColor then
                    if GetColor(P[a].x + 1, P[a].y + 1) = TestColor then
                      if GetColor(P[a].x, P[a].y + 2) = TestColor then
                        if GetColor(P[a].x + 2, P[a].y) = TestColor then
                          if GetColor(P[a].x, P[a].y + 1) = TestColor then
                            if GetColor(P[a].x + 1, P[a].y) = TestColor then
                              if GetColor(P[a].x + 2, P[a].y + 1) = TestColor then
                                if GetColor(P[a].x + 1, P[a].y + 2) = TestColor then
                                begin
                                  Result := TestColor;
                                  WaterColor := TestColor;
                                  WriteLn('WaterColor = ' + IntToStr(TestColor));
                                  Exit;
                                end;
          end;
        end;
      end;
      WriteLn('Could not find Water Color!');
      Result := 0;
    end;

    {*******************************************************************************
    function FindRoadColor: Integer;
    By: Tarajunky
    Description: Autodetects Normal Road Color on Minimap
    *******************************************************************************}


    function FindRoadColor: Integer;
    var
      GC, a, l, TestColor, Red, Green, Blue : integer;
    var
      P:array of Tpoint;
    begin
      GC := 5987170;
      Flag;
      FindColorsSpiralTolerance(MMCX, MMCY, P, GC, MMX1, MMY1, MMX2, MMY2, 60);
      l:=GetArrayLength(P);
      for a:= 0 to l-1 do
      begin
        if rs_OnMinimap(P[a].x,P[a].y) then
        begin
          TestColor := GetColor(P[a].x,P[a].y);
          if SimilarColors(TestColor,GC,60) then
          begin
            ColorToRGB(TestColor, Red, Green, Blue)
            if Red - Green <= 10 then if Red - Green >= 5 then
              if Red - Blue <= 10 then if Red - Blue >= 5 then
                if GetColor(P[a].x + 5, P[a].y + 5) = TestColor then
                  if GetColor(P[a].x + 3, P[a].y + 3) = TestColor then
                    if GetColor(P[a].x, P[a].y + 5) = TestColor then
                      if GetColor(P[a].x + 5, P[a].y) = TestColor then
                        if GetColor(P[a].x, P[a].y + 3) = TestColor then
                          if GetColor(P[a].x + 3, P[a].y) = TestColor then
                            if GetColor(P[a].x + 5, P[a].y + 3) = TestColor then
                              if GetColor(P[a].x + 3, P[a].y + 5) = TestColor then
                              begin
                                Result := TestColor;
                                RoadColor := TestColor;
                                WriteLn('RoadColor = ' + IntToStr(TestColor));
                                Exit;
                              end;
          end;
        end;
      end;
      WriteLn('Could not find Road Color!');
      Result := 0;
    end;

    {*******************************************************************************
    function FindVarrockRoadColor: Integer;
    By: Tarajunky
    Description: Autodetects Varrock Road Color on Minimap
    *******************************************************************************}


    function FindVarrockRoadColor: Integer;
    var
      GC, a, l, TestColor, Red, Green, Blue : integer;
    var
      P:array of Tpoint;
    begin
      GC := 7304312;
      Flag;
      FindColorsSpiralTolerance(MMCX, MMCY, P, GC, MMX1, MMY1, MMX2, MMY2, 60);
      l:=GetArrayLength(P);
      for a:= 0 to l-1 do
      begin
        if rs_OnMinimap(P[a].x,P[a].y) then
        begin
          TestColor := GetColor(P[a].x,P[a].y);
          if SimilarColors(TestColor,GC,60) then
          begin
            ColorToRGB(TestColor, Red, Green, Blue)
            if Red - Blue <= 12 then if Red - Blue >= 8 then
              if Red - Green <= 6 then if Red - Green >= -1 then
                if Green - Blue <= 10 then if Green - Blue >= 4 then
                  if GetColor(P[a].x + 5, P[a].y + 5) = TestColor then
                    if GetColor(P[a].x + 3, P[a].y + 3) = TestColor then
                      if GetColor(P[a].x, P[a].y + 5) = TestColor then
                        if GetColor(P[a].x + 5, P[a].y) = TestColor then
                          if GetColor(P[a].x, P[a].y + 3) = TestColor then
                            if GetColor(P[a].x + 3, P[a].y) = TestColor then
                              if GetColor(P[a].x + 5, P[a].y + 3) = TestColor then
                                if GetColor(P[a].x + 3, P[a].y + 5) = TestColor then
                                begin
                                  Result := TestColor;
                                  WriteLn('Varrock RoadColor = ' +
                                    IntToStr(TestColor));
                                  Exit;
                                end;
          end;
        end;
      end;
      WriteLn('Could not find Varrock Road Color!');
      Result := 0;
    end;

    {*******************************************************************************
    function FindFallyRoadColor: Integer;
    By: Tarajunky
    Description: Autodetects Falador Road Color on Minimap
    *******************************************************************************}


    function FindFallyRoadColor: Integer;
    var
      GC, a, l, TestColor, Red, Green, Blue : integer;
    var
      P:array of Tpoint;
    begin
      GC := 6187637;
      Flag;
      FindColorsSpiralTolerance(MMCX, MMCY, P, GC, MMX1, MMY1, MMX2, MMY2, 60);
      l:=GetArrayLength(P);
      for a:= 0 to l-1 do
      begin
        if rs_OnMinimap(P[a].x,P[a].y) then
        begin
          TestColor := GetColor(P[a].x,P[a].y);
          if SimilarColors(TestColor,GC,50) then
          begin
            ColorToRGB(TestColor, Red, Green, Blue)
            if Red - Blue >= 18 then if Red - Blue <= 33 then
              if Red - Green <= 15 then if Red - Green >= 0 then
                if Green - Blue >= 8 then if Green - Blue <= 30 then
                  if GetColor(P[a].x + 5, P[a].y + 5) = TestColor then
                    if GetColor(P[a].x + 3, P[a].y + 3) = TestColor then
                      if GetColor(P[a].x, P[a].y + 5) = TestColor then
                        if GetColor(P[a].x + 5, P[a].y) = TestColor then
                          if GetColor(P[a].x, P[a].y + 3) = TestColor then
                            if GetColor(P[a].x + 3, P[a].y) = TestColor then
                              if GetColor(P[a].x + 5, P[a].y + 3) = TestColor then
                                if GetColor(P[a].x + 3, P[a].y + 5) = TestColor then
                                begin
                                  Result := TestColor;
                                  WriteLn('Falador RoadColor = ' +
                                    IntToStr(TestColor));
                                  Exit;
                                end;
          end;
        end;
      end;
      WriteLn('Could not find Falador Road Color!');
      Result := 0;
    end;

    {*******************************************************************************
    function FindRockColor: Integer;
    By: Tarajunky
    Description: Autodetecs Rock (Gray) Color on Minimap
    *******************************************************************************}


    function FindRockColor: Integer;
    var
      GC, a, l, TestColor: integer;
    var
      P:array of Tpoint;
    begin
      GC := 6444639;
      Flag;
      FindColorsSpiralTolerance(MMCX,MMCY, P, GC, MMX1,MMY1,MMX2,MMY2, 75);
      l:=GetArrayLength(P);
      for a:= 0 to l-1 do
      begin
        TestColor := GetColor(P[a].x,P[a].y);
        if (GetColor(P[a].x-1,P[a].y)=TestColor-789772) then
        begin
          Result := TestColor;
          WriteLn('Rock Color = ' + IntToStr(TestColor));
          Exit;
        end;
      end;
      WriteLn('Could not find Rock Color!');
      Result := 0;
    end;

    {*******************************************************************************
    function FindStoneColor: Integer;
    By: Tarajunky
    Description: Autodetecs Stone (Mine Rock) Color on Minimap
    *******************************************************************************}


    function FindStoneColor: Integer;
    var
      GC, a, l, TestColor: integer;
    var
      P:array of Tpoint;
    begin
      GC := 3561615;
      Flag;
      FindColorsSpiralTolerance(MMCX, MMCY, P, GC, MMX1,MMY1,MMX2,MMY2, 60);
      l:=GetArrayLength(P);
      for a:= 0 to l-1 do
      begin
        TestColor := GetColor(P[a].x,P[a].y);
        if (GetColor(P[a].x-1,P[a].y)=TestColor-461068) then
        begin
          Result := TestColor;
          WriteLn('Stone Color = ' + IntToStr(TestColor));
          Exit;
        end;
      end;
      WriteLn('Could not find Stone Color!');
      Result := 0;
    end;

    {*******************************************************************************
    function FindDirtRoadColor: Integer;
    By: Tarajunky
    Description: Autodetects Dirt Road Color on Minimap
    *******************************************************************************}


    function FindDirtRoadColor: Integer;
    var
      GC, a, l, TestColor, Red, Green, Blue, x, y : integer;
    var
      P:array of Tpoint;
    begin
      if WaterColor = 0 then WaterColor:=FindWaterColor;
      if not (FindColor(x, y, WaterColor, MMX1, MMY1, MMX2, MMY2)) then
        WaterColor := FindWaterColor;
      GC := 4548987;
      Flag;
      FindColorsSpiralTolerance(MMCX, MMCY, P, GC, MMX1, MMY1, MMX2, MMY2, 140);
      l:=GetArrayLength(P);
      for a:= 0 to l-1 do
      begin
        if rs_OnMinimap(P[a].x,P[a].y) then
        begin
          TestColor := GetColor(P[a].x,P[a].y);
          if SimilarColors(TestColor,GC,140) then
          begin
            ColorToRGB(TestColor, Red, Green, Blue)
            if Red - Green <= 33 then if Red - Green >= 5 then if Red <= 120 then
              if Green - Blue >= 17 then if Green - Blue <= 58 then
                if Blue <=45 then if Red - Blue >= 30 then if Red - Blue <= 75 then
                  if GetColor(P[a].x + 5, P[a].y + 5) = TestColor then
                    if GetColor(P[a].x + 3, P[a].y + 3) = TestColor then
                      if GetColor(P[a].x, P[a].y + 5) = TestColor then
                        if GetColor(P[a].x + 5, P[a].y) = TestColor then
                          if GetColor(P[a].x, P[a].y + 3) = TestColor then
                            if GetColor(P[a].x + 3, P[a].y) = TestColor then
                              if GetColor(P[a].x + 5, P[a].y + 3) = TestColor then
                                if GetColor(P[a].x + 3, P[a].y + 5) = TestColor then
                                  if ((WaterColor = 0) or not (FindColor(x, y,
                                    WaterColor, P[a].x - 10, P[a].y - 10,
                                    P[a].x + 10, P[a].y + 10))) then
                                    begin
                                      Result := TestColor;
                                      WriteLn('Dirt Road Color = ' +
                                      IntToStr(TestColor));
                                      Exit;
                                    end;
          end;
        end;
      end;
      WriteLn('Could not find Dirt Road Color!');
      Result := 0;
    end;

    {*******************************************************************************
    function FindBridgeColor: Integer;
    By: Tarajunky
    Description: Autodetects Bridge Color on Minimap
    *******************************************************************************}


    function FindBridgeColor: Integer;
    var
      GC, a, l, TestColor, x, y: integer;
    var
      P:array of Tpoint;
    begin
      if WaterColor = 0 then WaterColor := FindWaterColor;
      if not(FindColor(x, y, WaterColor, MMX1, MMY1, MMX2, MMY2)) then
        WaterColor := FindWaterColor;
      if WaterColor = 0 then
      begin
        WriteLn('No water on screen... aborting');
        Result := 0;
        Exit;
      end;
      GC := 1389645;
      Flag;
      FindColorsSpiralTolerance(MMCX, MMCY, P, GC, MMX1, MMY1, MMX2, MMY2, 60);
      l:=GetArrayLength(P);
      for a:= 0 to l-1 do
      begin
        if rs_OnMinimap(P[a].x,P[a].y) then
        begin
          TestColor := GetColor(P[a].x,P[a].y);
          if GetColor(P[a].x,P[a].y-1)=WaterColor then
          begin
            if GetColor(P[a].x-1,P[a].y)=Testcolor+198926 then
            begin
              Result := TestColor;
              WriteLn('Bridge Color = ' + IntToStr(TestColor));
              Exit;
            end;
          end;
        end;
      end;
      WriteLn('Could not find Bridge Color!');
      Result := 0;
    end;

    {*******************************************************************************
    function FindLadderColor: Integer;
    By: Tarajunky
    Description: Autodetects Ladder Color on Minimap
    *******************************************************************************}


    function FindLadderColor:integer;
    var
      GC, ColorCount, a, i, j, n, l, TestColor, Red, Green, Blue : integer;
    var
      ColorArray : array of integer;
    var
      P : array of Tpoint;
    begin
      GC := 10837;
      Flag;
      FindColorsSpiralTolerance(MMCX, MMCY, P, GC, MMX1, MMY1, MMX2, MMY2, 60);
      l:=GetArrayLength(P);
      SetArrayLength(ColorArray,32);
      l:=GetArrayLength(P);
      for a:= 0 to l-1 do
      begin
        if rs_OnMinimap(P[a].x,P[a].y) then
        begin
          TestColor := GetColor(P[a].x,P[a].y);
          if SimilarColors(TestColor,GC,60) then
          begin
            ColorToRGB(TestColor, Red, Green, Blue)
            if Blue <= 30 then if Red - Blue <= 105 then if Red <= 115 then
              if Green <= 70 then if Green >= 5 then if Green - Blue >= 5 then
                if Green - Blue <= 60 then if Red >= 55 then
                  if Red - Green >= 25 then if Red - Green <= 65 then
                    if Red - Blue >= 55 then
                    begin
                      n:=0;
                      for i:= 0 to 3 do
                      begin
                        for j:= 0 to 7 do
                        begin
                          ColorArray[n]:=GetColor(P[a].x+i,P[a].y-3+j);
                          n:=n+1;
                        end;
                      end;
                      ColorCount:=0;
                      for n:= 0 to 31 do
                      begin
                        if ColorArray[n]=TestColor then ColorCount:=ColorCount+1;
                      end;
                      if ColorCount<17 then if ColorCount>12 then
                      begin
                        Result := TestColor;
                        WriteLn('Ladder color = ' + IntToStr(TestColor)
                        +
                        ' at ' + IntToStr(P[a].x) + ',' + IntToStr(P[a].y));
                        Exit;
                      end;
                    end;
          end;
        end;
      end;
      WriteLn('Could not find Ladder Color!');
      Result := 0;
    end;

    {*******************************************************************************
    function AutoColorThis(Bitmap, MaxTol, X1, Y1, X2, Y2: Integer): Integer;
    By: Sumilion
    Description: Resturns exact color of a bmp with tol found on the screen.
    *******************************************************************************}


    function AutoColorThis(Bitmap, MaxTol, X1, Y1, X2, Y2: Integer): Integer;
    var
      lTol, Ax, Ay: Integer;
    begin
      Result := 0;
      repeat;
        if (FindBitmapToleranceIn(Bitmap, Ax, Ay, X1, Y1, X2, Y2, lTol)) then
        begin
          Result := GetColor(Ax, Ay);
          Exit;
        end;
        lTol := lTol + 5;
      until (lTol >= MaxTol);
      srl_Warn('AutoColorThis', 'The Color was not found', warn_Warning);
      WriteLn('Color NOT found.');
    end;

  2. #2
    Join Date
    Nov 2007
    Location
    Chile
    Posts
    1,901
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    They use ColorToRGB... that was rev# 14


  3. #3
    Join Date
    Mar 2007
    Posts
    3,116
    Mentioned
    0 Post(s)
    Quoted
    2 Post(s)

    Default

    I just went thorough #15 and changed all of them for that post. Its not changed on mine for some reason...

  4. #4
    Join Date
    Jun 2007
    Location
    La Mirada, CA
    Posts
    2,484
    Mentioned
    1 Post(s)
    Quoted
    3 Post(s)

    Default

    its not a big worry its obviously just the way tara liked to do it in the time he made the functions...maybe it ends up being faster?

    "Failure is the opportunity to begin again more intelligently" (Henry Ford)


  5. #5
    Join Date
    Mar 2006
    Posts
    3,051
    Mentioned
    1 Post(s)
    Quoted
    0 Post(s)

    Default

    Well, SCAR and SRL have evolved past my autocolor functions. My philosophy is that if it ain't broke don't fix it. But if someone wants to clean up the code, that's a good way to contribute. As long as you triple check it, and don't stuff it up.


  6. #6
    Join Date
    Dec 2006
    Location
    Copy pastin to my C#
    Posts
    3,788
    Mentioned
    8 Post(s)
    Quoted
    29 Post(s)

    Default

    Usually when Tara makes something it is a bit weird, but it tends to always work

  7. #7
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    2,984
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    Well I'm thinking about replacing all those functions with one function, a customizable one even. But it would need some growing up, basically all I need is a load of colors from water for example. Anyone got colors from water, ladder, road, etc. ?
    Administrator's Warning:


Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Scar = Useless?
    By Dspider0 in forum OSR Help
    Replies: 3
    Last Post: 07-11-2008, 09:41 AM
  2. need help with autocolor.scar
    By lilboy543 in forum OSR Help
    Replies: 3
    Last Post: 05-22-2008, 12:52 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •