The Wiki for Tale 4 is in read-only mode and is available for archival and reference purposes only. Please visit the current Tale 11 Wiki in the meantime.

If you have any issues with this Wiki, please post in #wiki-editing on Discord or contact Brad in-game.

User:Kinslayer/Macros/KinsBarrelMonkey

From A Tale in the Desert
< User:Kinslayer‎ | Macros
Revision as of 08:26, 4 September 2009 by Kinslayer (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

This is my Barrel Vice macro for SCAR Divi. If you like this macro, or have any problems, let me know! I love feedback.

TODO:

  • Seriously clean up the code
  • Add a GUI for options/debug/info
  • Add support for multiple barrel vices running at once.
{.Script Info:
# ScriptName  = Kin's Barrel Monkey
# Author      = Kinslayer
# Description = Barrel Vice Macro
# Version     = 0.1
# Date        = 9/4/2009
# Comments    = [email protected]
#               Ingame: Kinslayer
#               Newest version available at http://www.atitd.org/wiki/tale4/User:Kinslayer/Macros
# Instruction = Pin Barrel vice window anywhere, have all materials you need on you.
#               If barrel has been started already, only wood is needed, otherwise
                make sure you have straps and boards as well. Try to have 100+ wood
                at all times.
/Script Info}

program BarrelMonkey;
//---------
//Settings
//---------
Const
     //Amount of time in milleseconds to wait before rescanning
     //If in doubt, leave this alone.
     CheckTime = 200;
     //This will track the Barrel vice window, so you can move it around
     //But it uses extra CPU
     //false = off (Default)
     //True = on
     UseActiveScan = False;
     //This tells the script whether to add a bundle at once when starting,
     //to decrease the amount used overall. You can disable this if you
     //Already have fuel in the barrel vice when starting the script
     //(Eg. You had to restart the script) Otherwise, leave this on.
     UseFastlane = True;
     //At what flame height 2 wood will not be added.
     MaxFlameHeight = 90;


var
   Fuel: Integer;
   Fuelx: Integer;
   Fuely: Integer;
   
   Flame: Integer;
   Flamex: Integer;
   Flamey:Integer;
   
   Heat: Integer;
   Heatx: Integer;
   Heaty:Integer;

   Progress: Integer;
   Progressx: Integer;
   Progressy:Integer;
   
   Stoke: Integer;
   Stokex: Integer;
   Stokey:Integer;

   Tick: Integer;
   RedTick: Integer;
   
   NoWood: Integer;
   
   MakeBarrel: Integer;
   MakeBarrelx: Integer;
   MakeBarrely: Integer;
   
   Ticks: Integer;
   
   Stop: Boolean;
   
   i: Integer;
   
   LastAction: String;
   
   SaveX: Integer;
   SaveY: Integer;
   
   AlmostDone: Boolean;
   
   WoodUsed: Integer;


procedure LoadMasks;
begin
       Fuel := BitmapFromString(24, 9, 'beNpdUUty00AQ9XEgsCMklI8B4' +
       'RAhqwSKHRU2UBwhqVCxPpY8kiJbSYBDkFilz8zIssuSNfqMZVucgR' +
       '45K09NTfXn9evuN53OzuFEX0VmGer1xEoeegtXLbBRYlQEehlq6Vh' +
       'JHqWKoNzXODUBnwfa7G9vMVbBBkBNLWBgvlpTtJqYYK9ndvrYy1wF' +
       'kGXYr7DGico8OR1fl0TLfXVJkajFeupK4ILNPCi3AAw863gEkTqy/' +
       'qX3qauwYABuRUzo3n29d3r87vDVsxvpaw4TEqNNWTk2t7vknrSOjC' +
       'KQC1/mpC+yWGuSEczD2kZFoJ19eDuUz6GvfvH5zf7zzFczX9nulbW' +
       'YnbPEIsux3MyNbHyV+5KgDcVbU5W5V+nDpSj3r8s2yLyfCwGTRbsQ' +
       'lVhjngTyruKbVrF+k9xlrlxRC9z1zNlpV1F7GdmCBxsFscAVVQRVV' +
       'M99Bf5lM78X81CrWfwGfj4ZCp42uJqO6tjOCaqnt8BftjqzcAB21W' +
       'oFGoL44kfoYDMfdg/2htKXJnFAjY8nR4Ihtj6dvB8p55zqLFC7By8' +
       '4RTxC7WAwA3rSJHKAClbjkV3Hzq3+DZDblKN/h3eT/GrSP93Dl9vg' +
       'HfpRTx24TwtOnM5/X2hroA==');

       Flame := BitmapFromString(33, 9, 'beNplkuuK00AUx/s4ovvNS3Ef' +
       'QhDW9fIGWkHcVUERFVF2P/gEgrht2jSZNJe2u7Lr+gpC2yQzuZg0S' +
       'Zt7UvoInpnKfliHYfjz58w5c35zGo1LK8V8YYkgYqO3mHHRtJ0Y3a' +
       'XeXs64DPdLW8wwXzpyOOFik88sofbVOhiVrpxhIYIYa1C6SukMEiy' +
       'kZADZEtyDbPNJd2kKsBOMUiLmFgJzMesGEyjBJZiPjW5uS4Wj1L6W' +
       '4H5uSdGES7GUElR5ShUMa3+YEyGadlIila5a+RoItkWoBdn+/O4uD' +
       'DGm+WUa4yhgRno/xvJFd2r7Y25rIPZb9zaO0v6033qw0aP+YW4rC0' +
       'O4ffPaq2ePtptb0tH7BEMv4iYgmvWg/YwImQVVUGlLFJQpxiaCvuD' +
       '90rfX4FSOykrsFLYifH3D9P3KOz5GX0CXzuj5k12VO1iH5xp/2Lxx' +
       'dWkOFjrf+G9BwvV8CCIjCCoCbUCRE4pu5dGmMqtf+wr8EYVpcKU7q' +
       'HyFfSLHbgmVKxXskanZARNiQAczFJNhao0SDKDUdfgTzCVW5PbnF0' +
       '8fXlSvwx9wFs649k/DCSWwwFo9P11Fv2jXevfSawt3nLuj2KJ4gyk' +
       'X6TyQTLC0xGjlj2kJEzEUuxmwwqyL4ORfifA8mFInMtVqflrOz0An' +
       'BhsSXciwlBE5mPZSouXeSWpTJuG0HekcHTnSB1ArBgrGBk756G2Ou' +
       'Zetu6DXAfUrT4UN38dGokfnx2NgMdpr7SidD3AxMYXm9Svw3QV7Le' +
       'uiBxMVGighcu7ABFI/tTSNP9gE7D2+Q0Exv/KPS28czRCDqRbeeB2' +
       'ese40ILB9a2tzBX1/B8OZu3LjL8Xl8kc=');

       Heat := BitmapFromString(26, 9, 'beNp1UduK1EAQzd/4oPgkXtbvE' +
       'NQX/QAVkV1RHwR3QRf0F5TVcTLXTDLJJJMZXcFPWHV7kg6d+066O5' +
       '0h8wdWJyoiWIRQdbrqVNUpRQErA6tO3SpxqtguVjogInK29KuI5iJ' +
       'e0MDmgS2i5SY7FrFbZ5+rxD5DwzXqZd86kLxG4wIbhaczYkPI/YEI' +
       'RgXqsFWXom7Dr9WFWxIDCplvUE8TsQU+IJvUFqGen3YZ1rMfMvkM9' +
       'Qt/DN8ajSBk/ohjvUB9inoUfZT8WIfanSsXHj+8vXP5vPZhH0IRmc' +
       'pv0zsHIpwqfxnDRuts0kWdH9fZUnYPJVhF7tPdu7PhmypxDfUV0ML' +
       'K4FehXWcLc3Ao1SAT6hnNphonFgtmyn+MB7LvNl+K2K6SuUQIbOpw' +
       'bNSp0w5ZkmmOhg0baDgB3WhDWHgmDCPITBBLNDwcm//wg9SG+nL33' +
       's0/iAjnhS/Tsu9dUIljizZhibUq0DdEr6OpIEazheTcRCaEfDXIT9' +
       '61suw9uAV3B2Xka7Jg2Go3pagPx2JYVrGVVuIJ88YV0bkn71L62t7' +
       '9G6a6L4IJnObapXPwl+K/f17iETyBT1e9ogEHb5+tT9X05KidGdas' +
       '008idLb5F+gokdCpk+X1qxfbhPHRCxDHHLxuwyeP7jRK2pw4hnr4S' +
       'wpPU34CX4yHLg==');

       Progress := BitmapFromString(47, 11, 'beNpVVGuT02QU5u8siHzZ' +
       'hb34J3RUdHR0/MbIjCA7rHxAQWXRD46OnxgvAwvZpm2SNpduS7vl4' +
       'sogIAvD9pLrNkmTtLlnuusf8HnTlcFM5p33nLx5zznPeZ6jVQ+98p' +
       'w/86GnSJ7M211m2GVGcjXURLfHxuZGqIuBIaR2MzHr6bCROe09737' +
       'qbIZaNbVuT5wWPmVuOx22E7OxHz7aj57sh4/3gofp8O7E+yMyW5m7' +
       'lbn3cSC1626v5MkMfkzNxkgRcHk4qEdmEzmM1FpgSKnTXpo/ujB3x' +
       'JPZ3eeUtVN0ZW6ssPZOwVe4QK2M+6WxzPoKGw9qkVlH0MQSR731UO' +
       'Myu5YMqrFeiTU2VJlkIGZOfeK29vx2MsDNLZyfuHcyZzNzkFXL7eH' +
       'Ocmo30mELaSR2K7aa0aCOZGLnz8DcnPiPM28LptevYHVkAWtg1EeK' +
       'tHji6BS6xfljgSaiQJy8cO6TA+fcEazpkNSVmiLWzLkz8e6+sXDsw' +
       'rmPFo+/JtHf+UqFX786PY+S3W6h/PvK1JyfOxwNxNAQp6av150+G+' +
       'i10NiAOezQWKlrK0636PXLZ0+9xa19BXC8fomnriyffjtU2fOfvSf' +
       'Qq6m9MZKL3NqXOJ8MeKwS/XWsc8mgdmH54zr30553Vyp+vzT/eqCT' +
       'myUGnq169eexJsHkqW8y9x5HXd0LHqTD+9Nk0L5hpzBWK/OzM8un3' +
       '3E7FJzqX784HQp4Yj+WS4HKen3aV0lEtCyPXsucBpIZyyT5xCRIhj' +
       'Ll92+GCvHEejHRy7HGkBA94hHoK2hx5t52+yWYqCLSKoEuTLw7iXU' +
       'bmL9K4LOfnvQ1yXqxnrepFlttgEbAd++RvbaReQ/yuKRM8HM/eBgo' +
       'wpR4E4+UFhtiZIiT0dah/z8jmWXXLi3kDeWpS9az66VfVxZmZ2Cya' +
       'xfBsXggjPLCI3PTU8TYarmQj1EzttfgtDtFMNmTy1MofJWDBCAoYu' +
       'bO2KolZg37SOdzoEhdE7cJWUFNJNv06T/Z89Ru7422QqOJF8qSSj/' +
       'ktOSIVAdNqfxjXgjadA8mSVsRdl8UfE1w+8xYLuvbN+Hcfb7u9sqo' +
       'aPn0SZ5aDfC1x1QIZ96FnFfOfCCsX4VS+JuXpwSOdDZPqRrIxXjAf' +
       '/H5+1LpSmbxgUwvzh12u9TZU29GegX0y5Mp4p6xXOHpVYK83YTc/u' +
       'NMxe4WERflj2VGf3qdINMtQMhEy2pl8fiRA+bPzgQqE2osgi6eIM6' +
       'FuRlu7SIBSsvhMrhILePrxJGWThz8JdGrGAhQzdQU6W9BxZdmlbqc' +
       'mCIKJNrpMw7eHmnKWK6Cq8qj3/RtCqMmVxODToF10BoGDjwHGSpcq' +
       'FRjg/dlmiNkOIwh4ytMavLJgMxGTLbYqGRDIVLpSKHHcsHZuYU1IF' +
       'MIIBedbgH9xc2x2cCIi4w6ojuyNOxxu88KdqeE0PYO1XtwTXlyQ/3' +
       '7xu4zCglYLyhkCMIY27ecXhl9dDoEtJfknJ9FF4qRXgW1MtSoshit' +
       'mdWIdAFyC+RShMwJB1CCgMkG/jvdMmQSajxejCBwD7QP/wUHbL2a');

       Stoke := BitmapFromString(29, 9, 'beNpVUttu00AQzd9QnL40V76' +
       'jDagSrzSiNG3hEakoVQn0DwqNUpI2iXdr594HxBcQ23FkO77F8SUi' +
       'fAhnbSrBarSamd2dOefM3nz09X4xn07FK595WimXljMaLfoIlzNiS' +
       '21zeofMUiWO3IHvqdSV2jgNFzTUiK92YKFO1wsh0LpBEmqkmNt+d/' +
       'QyNEaBMbj7el7IpoPYx0NH4l1FNKfUkXvuTLQlavwkjtJ3lR5rqvC' +
       'uTDxV8LWeP+/7qhDp4lJGo17yfOM8hEYfkCxWR1jNe6l/liXRfIZ7' +
       'pMN5qGCMGFpjEMRWyKX5m4tAHz7Lb1cOSsDJN2rFXBohaV6AnSN1b' +
       'QmMepEh4KE97bgKrRzs3X754MrQ4b5Tr568fr6aU5yuzVFkjk4PX/' +
       'i6COftm33h9jOwkSarGZnjk8P9BEwhwzWvzgBgbQ5jnAQiJIAdmXr' +
       'zYWBMYvoEO21+oq3LaMEU27g/kPntffe1/toaMy66GMAM0deF43Ip' +
       't7MVsu6sGpB7cwbblXlr+s1TeV9jYTLQQo7rNqrwkdxYD6n/F34CL' +
       'FwMsAMeMoHOfFZNEbx5PDuZ2rEIq7gLKCcP+WaNtmq+Jkax2pgRHK' +
       'BdW5NClmtfV0OdNT16tYsQThCXbderK20AbZtX723p3tMGyOAOkjE' +
       'FAi6YV6dxjhanTNvLX+ZkbY4xtePyHko9DnoLTG2p5amkfX2WJN1p' +
       'Pbfz5K/4WQ5zXOnJr2YfeKVRJKEGpMOkkmvkD12DojM=');
       Tick := BitmapFromString(1, 12, 'beNqr/8fC3MTKepmN7S9WpK//t' +
       'x4A46sNBg==');
       RedTick := BitmapFromString(1, 11, 'beNqrr7/KyvKfjRUT/QMifb' +
       '1/ANIFDIU=');
       NoWood := BitmapFromString(46, 9, 'beNo9lNty2lYYhf0yre3cdYw' +
       'TO+/QxuC4h+vOdGwg4xiwEy46vuor1HXBAqEDCHEY+6bvkNqMQNKW' +
       'BEWAzkjgySN0STRlNJq9f0l7f/9aayNRW1tbS729NERXZdt3ZUxDv' +
       'R2NxWjcDgiPKe6uwgR6e232PMKFhrDUW8+z/mf7YWX2A9JyVc4l7N' +
       'JoRhMxINxSb7oqE2hNFOPVxqKjMFjcGjG2wvua4JLmatoPtNZBavc' +
       'gtXORzbza2zE+VUr5k6vzH8NxNxp3C9ljfHv57odo0l9N7/GomDvx' +
       'Ce8TIdA7a/PeI2DuATsad55nD6HR8dQWiq4CWnapibh7hEfRUVuWz' +
       'MWN6KKjNj0izofsTGIdVcDU10Ts9f40PZeYhcSc/3KU//nbwtnRZf' +
       '7YU5lQ40HYZ65LueNQFyKjXcq9LebeYl80fpja3Up+h/sv0E406a7' +
       'M3uuXL/4rpnZcuRZovCNTxVx6U3x/erSR1FMYDGZPlPlYtUe0DwG1' +
       'FioLqT4bULbcMB8rL7/5CnixQUYPImAXqBHfjU5kdFF3FQ79gl+4K' +
       'wekCf5u/RpCraY9KHnP/2aNeFvmhOpVMZsGcCGbOdzfdWTakZkvJK' +
       'wzrMX7Dqh/Pt24ckJCYjZLurUGVVTmAypJRRyG0OAf+OvC2ZtQZ0v' +
       '5zNoUns2YMDKaQWK3TyAa5wyrnkJjup4246eTNvpyZcYe1ZOlhE3q' +
       '7BFjJVfSC+uMaE/lFkMKF/SE3Zs3UbelO5BYUi1h5i7fwYX0ZT5jS' +
       'dWAIGzsh/OTD+ffwyafQBMmsbu5mvUQRTBj+jxvxzyzrjWigYokJ+' +
       'EUEjzBI6ybXAkYtzS4QEMeKtawutQaS0KHWrymM7y1h7e+WoM4CTP' +
       'To3/FprgwDsdtHI2PFz+BBFI7iKLKJev3Prt/ebqIhMQMG8XGwlyq' +
       'A8NLNkULuHuEQe+OQpuDSiImDQyPNGyZdgmDTwC8Njsb4/ByoPNuc' +
       'kiBuhEcRsNfhAE+QqV4TYWxhnV7WC+cpTu1j+uJ4IyoXr0MEz25Ws' +
       'q96dfLs79hfU2krkq5dOxsLt2hyvOnCr56tbe98T0ax/l0CedrGOM' +
       'vQlhPRbhQzB65ch0hx6m5OP1u9njrydRB6mtXrs4ff1883VjSH4FS' +
       'TUhqzugO0iEeB6ntL2dnF8fKh006/3p/Z1PEU9gKEsj+/5vcTSHWR' +
       'EV3DQzmT38m7iOxjRBSEPZgbxsMpVwGR2/xL1zd4HU=');
       MakeBarrel := BitmapFromString(80, 10, 'beNplVllzFNcV1p9xwD' +
       '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' +
       '');
end;
procedure FindBmps;
begin
FindBitmap(Fuel,Fuelx,Fuely);
FindBitmap(Flame,Flamex,Flamey);
FindBitmap(Heat,Heatx,Heaty);
FindBitmap(Progress,Progressx,Progressy);
FindBitmap(Stoke,Stokex,Stokey);
FindBitmap(MakeBarrel,MakeBarrelX,MakeBarrelY);
end;

//Tick Counting functions, Perform all the code to convert
//blue/red bars to something we can work with easily

Function ReturnFuel: Integer;
begin
     Ticks:= CountBitmapTolerance(Tick,Fuelx + 28 ,Fuely - 4, Fuelx + 154,Fuely + 11,2);
     if (Ticks = 0) then
     begin
     Result:= 0;
     end;
     if (Ticks = 3) then
     begin
     Result:= 1;
     end;
     if (Ticks = 10) then
     begin
     Result:= 2;
     end;
     if (Ticks = 16) then
     begin
     Result:= 3;
     end;
     if (Ticks = 22) then
     begin
     Result:= 4;
     end;
     if (Ticks = 28) then
     begin;
     Result:= 5;
     end;
     if (Ticks = 35) then
     begin;
     Result:= 6;
     end;
     if (Ticks = 41) then
     begin;
     Result:= 7;
     if (Ticks >= 42) then
     Result:= 8;
     end;
end;

Function ReturnFlame: Integer;
begin
Ticks:= CountBitMapTolerance(Tick,Flamex + 38, Flamey - 4,Flamex + 162,Flamey + 11,3);
Result:= Ticks;
end;

Function ReturnHeat: Integer;
begin
if((CountBitMapTolerance(RedTick,Heatx + 31, Heaty - 4,Heatx + 155,Heaty + 11,3)) <= 0) then
begin
Ticks:= CountBitMapTolerance(Tick,Heatx + 31, Heaty - 4,Heatx + 155,Heaty + 11,3);
Result:= Ticks;
end else
Ticks:= CountBitMapTolerance(RedTick,Heatx + 31, Heaty - 4,Heatx + 155,Heaty + 11,3);
Result:= Ticks;
end;

Function ReturnProgress: Integer;
begin
Ticks:= CountBitMapTolerance(Tick,Progressx + 52, Progressy - 4,Progressx + 176,Progressy + 11,3);
Result:= Ticks;
end;

Function ReturnBarrel: Boolean;
begin
  if (CountBitmap(MakeBarrel,0,0,2000,2000) >= 1) then
    begin
    Result:= True;
    end;
  if (CountBitmap(MakeBarrel,0,0,2000,2000) <= 0) then
    begin
    Result:= False;
    end;
end;

procedure Setup;
begin
LoadMasks();
FindBmps();
Stop:= False;
end;



procedure Debug;
begin
  //i:= i + 1;
  ClearDebug();
  Writeln('Kins Barrel Monkey Debug Output')
  Writeln('/Chat Kinslayer if you have any problems')
  Writeln('------------------');
  Writeln('FuelLoc ' + IntToStr(Fuelx) + ' ' + IntToStr(Fuely));
  Writeln('FlameLoc ' + IntToStr(Flamex) + ' ' + IntToStr(Flamey));
  Writeln('HeatLoc ' + IntToStr(Heatx) + ' ' + IntToStr(Heaty));
  Writeln('ProgressLoc ' + IntToStr(Progressx) + ' ' + IntToStr(Progressy));
  Writeln('StokeLoc ' + IntToStr(Stokex) + ' ' + IntToStr(Stokey));
  Writeln('------------------');
  Writeln('Fuel:     ' + IntToStr(ReturnFuel()));
  Writeln('Flame:    ' + IntToStr(ReturnFlame()));
  Writeln('Heat:     ' + IntToStr(ReturnHeat()));
  Writeln('Progress: ' + IntToStr(ReturnProgress()));
  Writeln('Time:     ' + IntToStr(GetTickCount()));
  Writeln('Last:     ' + LastAction);
  Writeln('WoodUsed: ' + IntToStr(WoodUsed));
  Writeln('------------------');
end;

Procedure SilentMouseClick(x: Integer; y: Integer; left: boolean);
  begin
    GetMousePos(SaveX,SaveY);
    MoveMouse(x,y);
    ClickMouse(x,y,left);
    MoveMouse(SaveX,SaveY);
  end;

Procedure StokeFire(count: Integer);
  begin
        for i:= 1 to count do
          begin
          SilentMouseClick(Stokex,stokey,true);
        end;
      WoodUsed:= WoodUsed + count;
      LastAction:= 'Stoked Fire ' + IntToStr(count) + ' times';
  end;

begin
  Setup();
  LastAction:= 'Setup';
  Debug();
  if (ReturnBarrel = True) then
    begin
    SilentMouseClick(MakeBarrelx + 10, MakeBarrely + 3, True);
    end;
  if (UseFastLane = True) then
    begin
      StokeFire(7);
      sleep(10000);
    end;
    
  while(Stop = False) do
    begin
    Debug();
      if (UseActiveScan = True) then
        begin
          FindBmps();
        end;
      if (ReturnProgress >= 70) then
      begin
      AlmostDone:= True;
      end;
      if (AlmostDone = True) then
        begin
          if (ReturnProgress = 0) then
          begin
            if (ReturnFlame = 0) then
            begin
              Stop:= True
          end;
        end;
      end;
      // No fuel
      if(ReturnFuel <= 0) then
        begin
        if (Stop = False) then
        begin
          if (ReturnFlame >= MaxFlameHeight) then
            begin
            StokeFire(1);
            end;
          if (ReturnFlame <= MaxFlameHeight) then
            begin
            StokeFire(2);
            end;
            end;
        end;
      //1 Fuel
      if (ReturnFuel = 1) then
        begin
        if (Stop = False) then
        begin
          if (ReturnFlame >= MaxFlameHeight) then
          begin
          LastAction:= 'Fire Hot. Waiting';
          end;
          if (ReturnFlame <= MaxFlameHeight) then
            begin
            StokeFire(1);
            end;
            end;
        end;
      //2 Fuel
      if (ReturnFuel = 2 ) then
        begin
        if (Stop = False) then
        begin
        LastAction:= 'Lots of fuel, waiting';
        end;
        end;
      Sleep(CheckTime);
    end;
end.