Simba Code:
program BasicPaint;
{$DEFINE SMART8}
{$I SRL-OSR/SRL.Simba}
{$I SRL-OSR/SRL/misc/SmartGraphics.Simba}
var
Events: TStringArray;
Ores: Integer;
Status: String;
function ClockReel(digit: integer): string; // Convert 1 digit integer into a clock reel
begin
if (digit < 10) then // Checks if the number is less than 10
begin
result := '0' + inttostr(digit); // Adds the extra zero to the result.
Exit; // Exits function to avoid default result.
end;
result := inttostr(digit); // Default result
end;
function Timize(Time: Integer): String; // Converts seconds into HH:MM:SS format
var
seconds, minutes, hours: integer; // Declare our clock variables.
begin
if (time < 60) then // Checks less than 60 for an easy result.
begin
seconds := time;
Result := '0:00:' + clockReel(time); // Returns the result in HH:MM:SS
Exit;
end;
hours := floor(time / 3600); // Finds the amount of hours.
time := time - (hours * 3600); // Subtracts the hours of time.
minutes := floor(time / 60); // Finds the amount of minutes.
time := time - (minutes * 60); // Subtracts the mintues of time.
seconds := time; // Sets the remainder of time as seconds.
Result := (inttostr(hours) + ':' + clockReel(minutes) + ':' + clockReel(seconds)); // Returns the result in HH:MM:SS
end;
Procedure Paint (Running: boolean);
var
i, titleBMP, bgColor: integer;
begin
bgColor := clGreen; // The color we want the background to be by default.
titleBMP := BitmapFromString(37, 37, 'meJy9lm1rE0EUhesP8IMfCkUILa' +
'GURUIITSSlNKa4mBgJUimoUIooRYWiIIggCAUR/Ns+6WmPl9lN3Gx' +
'q4bJMNjPz3Jczd7Z3OOldW/fR08XWC5OrzLftDkbJDhUX1sPF5TWW' +
'1GPdpt2mk/WKfmdtTbYirgoayoPBtDN61Z2cmGgHFruxAFeKZqudf' +
't7Oj2Hlb77xc2urw3NjsxuNN2g+2lI4QxWaWMJh6402iPvNvUaWN9' +
'tTBnJjRRw2S9Q1S7h7G9kVa2cIC2PgqJP01sDFuBSaWJut8RUuy/U' +
'X9d0//jB4/Xl48kXEZXEiynlXzWmUweV9s3NAHgA9efd9dPYDNC+r' +
'7JwY78VSKcUCYYMoRSnt4/cX00+/rasFrEarj5Pb3WG2P0YhrcMjO' +
'2nxK42y6BWTwYmFTT7+FK40pTO3s10Er/P1cHq69+KMp86a0nh3vS' +
'kR2hS1/mUhVRNLOFI6L58KTecLSv/5W4rOk7FxaJLQMCvfueInM9n' + // This is out bitmap for our paint.
'/2fkvWDwJM5kTWeQQU2hQCA1XeTI2Dk3OcFk+s0vxxx0kEoISbh5L' +
'k6kX5tAOXp4/Pv1KgBBjJ4mFk/69A+4hD+Fi4ZIDaBbSchrtKuMiL' +
'jkCgmogqTi0UhwgSdFplJ8YYRqnTAq33TkSTrn1eYkSKu3V6orIGJ' +
'0oNNKIkzLQ/8TNO6TzcNa/QkNgYjFQO/IZL+LcRX019MrusqQJWyG' +
'UTCAZkUYcFnE6jMbpjdS4AKeSYZRMFKA2J0qpnp2aS5xewlLTdp8p' +
'ZjISmcAmUn4ExYqorMxRKa2HvxfEdRdN+mSRqCODJSB3J7Ooo0vpf' +
'30ZxUY6D6eKEFcRpN1QrFm++JQurmyLJ7brYjMpBpiAoop0Xaqsci' +
'lWp7i22LiKFSydqcYbcWry8bOEHbx2xU9BqdE4HUaVL/kEupEvT7b' +
'VwVdxYbn3KsAboUScPnV0RmD5Zlk2tCq4XtnXS/Uy1cBFFS0liXq4' +
'uKS2PCriiqD/hCsNahXl/wEFu3Iw');
if (not (running)) then // Checks our running boolean to see if we need to change colors.
bgColor := clRed; // Change the color to red if the script is not running.
SMART_ClearCanvas; // Clears the SMART canvas every time we call the function.
// ================ Begin code for Paint ================
// ================ End code for Paint ================
end;
Procedure Log (event: String; timestamp: boolean); // WriteLn's & Records an event and updates paint. Adds timestamp if specified.
var
stamp: String; // Declare timestamp
begin
stamp := ''; // Sets default to blank.
status := event; // Changes our script status to the event.
if (timestamp) then // Checks out input
stamp := '[' + timize(round (GetTimeRunning / 1000)) + '] '; // Adds timestamp to event.
setLength (events, Length (events) + 1); // Add blank event to our array
events[Length(events) - 1] := stamp + event; // Changes our blank event to inputted event.
WriteLn (stamp + event); // Prints the event in simba.
Paint(true); // Updates our paint. Script is running ok so true
end;
Procedure Fail;
begin
if (randomrange(1,500) = 1) then // Choose a number between 1 and 500
begin // and checks if it is one.
Log ('Unsolvable random found, terminating script...', false); // Randomly terminates script.
Paint (false); // Paints one last time, Running as false.
wait(5000); // Waits 5 seconds.
terminatescript; // Terminates script.
end;
end;
Procedure MainLoop; // The main loop of our script.
var
i, inventory: integer; // Declares variables.
begin
repeat // Repeats forever.
repeat // Repeats until inventory is full.
if (randomrange(1,5) = 1) then // Randomly chooses 1 to 5
begin // and checks if it is 1
Ores := Ores + 1; // We mined an ore!
Inventory := Inventory + 1; // Adding the ore to inventory
Log ('We managed to mine an iron ore!', true); // Logging the event.
end;
wait(100);
Fail;
until (inventory >= 28); // Checks if our inventory is full.
Log ('We have a full inventory, banking...', true); // Logs that we have full inventory.
for i:= 1 to 5 do // Walks to bank in 5 steps.
begin
wait(randomrange(200,400)); // Simulated walking.
Log ('Walking to bank, step ' + inttostr (i) + '/5', true); // Adding our events and changing status.
Fail; // The random chance of failing.
end;
wait(randomrange(200,400)); // Simulates banking time.
Log ('Successfully banked 28 iron ore!', true); // Adds our event and changes status.
inventory := 0; // Resets our inventory to zero.
for i:= 1 to 5 do // Walks back to mine in 5 steps.
begin
wait(randomrange(200,400)); // Simulates walking time taken.
Log ('Walking back to mine, step ' + inttostr (i) + '/5', true); // Adds event and changes status
Fail; // The random chance of failing.
end;
wait(randomrange(200,400)); // Simulating walking back to mine
Log ('Successfully walked back to the mine!', true); // Adds our event and changes status.
until (false);
end;
begin
setupSRL; // Sets up SRL;
MainLoop; // The main loop of the script.
Paint(false); // Paints one last time, this time with Running as false.
end.
Simba Code:
program BasicPaint;
{$DEFINE SMART8}
{$I SRL-OSR/SRL.Simba}
{$I SRL-OSR/SRL/misc/SmartGraphics.Simba}
var
Events: TStringArray;
Ores: Integer;
Status: String;
function ClockReel(digit: integer): string; // Convert 1 digit integer into a clock reel
begin
if (digit < 10) then // Checks if the number is less than 10
begin
result := '0' + inttostr(digit); // Adds the extra zero to the result.
Exit; // Exits function to avoid default result.
end;
result := inttostr(digit); // Default result
end;
function Timize(Time: Integer): String; // Converts seconds into HH:MM:SS format
var
seconds, minutes, hours: integer; // Declare our clock variables.
begin
if (time < 60) then // Checks less than 60 for an easy result.
begin
seconds := time;
Result := '0:00:' + clockReel(time); // Returns the result in HH:MM:SS
Exit;
end;
hours := floor(time / 3600); // Finds the amount of hours.
time := time - (hours * 3600); // Subtracts the hours of time.
minutes := floor(time / 60); // Finds the amount of minutes.
time := time - (minutes * 60); // Subtracts the mintues of time.
seconds := time; // Sets the remainder of time as seconds.
Result := (inttostr(hours) + ':' + clockReel(minutes) + ':' + clockReel(seconds)); // Returns the result in HH:MM:SS
end;
Procedure Paint (Running: boolean);
var
i, titleBMP, bgColor: integer;
begin
bgColor := clGreen; // The color we want the background to be by default.
titleBMP := BitmapFromString(37, 37, 'meJy9lm1rE0EUhesP8IMfCkUILa' +
'GURUIITSSlNKa4mBgJUimoUIooRYWiIIggCAUR/Ns+6WmPl9lN3Gx' +
'q4bJMNjPz3Jczd7Z3OOldW/fR08XWC5OrzLftDkbJDhUX1sPF5TWW' +
'1GPdpt2mk/WKfmdtTbYirgoayoPBtDN61Z2cmGgHFruxAFeKZqudf' +
't7Oj2Hlb77xc2urw3NjsxuNN2g+2lI4QxWaWMJh6402iPvNvUaWN9' +
'tTBnJjRRw2S9Q1S7h7G9kVa2cIC2PgqJP01sDFuBSaWJut8RUuy/U' +
'X9d0//jB4/Xl48kXEZXEiynlXzWmUweV9s3NAHgA9efd9dPYDNC+r' +
'7JwY78VSKcUCYYMoRSnt4/cX00+/rasFrEarj5Pb3WG2P0YhrcMjO' +
'2nxK42y6BWTwYmFTT7+FK40pTO3s10Er/P1cHq69+KMp86a0nh3vS' +
'kR2hS1/mUhVRNLOFI6L58KTecLSv/5W4rOk7FxaJLQMCvfueInM9n' + // This is out bitmap for our paint.
'/2fkvWDwJM5kTWeQQU2hQCA1XeTI2Dk3OcFk+s0vxxx0kEoISbh5L' +
'k6kX5tAOXp4/Pv1KgBBjJ4mFk/69A+4hD+Fi4ZIDaBbSchrtKuMiL' +
'jkCgmogqTi0UhwgSdFplJ8YYRqnTAq33TkSTrn1eYkSKu3V6orIGJ' +
'0oNNKIkzLQ/8TNO6TzcNa/QkNgYjFQO/IZL+LcRX019MrusqQJWyG' +
'UTCAZkUYcFnE6jMbpjdS4AKeSYZRMFKA2J0qpnp2aS5xewlLTdp8p' +
'ZjISmcAmUn4ExYqorMxRKa2HvxfEdRdN+mSRqCODJSB3J7Ooo0vpf' +
'30ZxUY6D6eKEFcRpN1QrFm++JQurmyLJ7brYjMpBpiAoop0Xaqsci' +
'lWp7i22LiKFSydqcYbcWry8bOEHbx2xU9BqdE4HUaVL/kEupEvT7b' +
'VwVdxYbn3KsAboUScPnV0RmD5Zlk2tCq4XtnXS/Uy1cBFFS0liXq4' +
'uKS2PCriiqD/hCsNahXl/wEFu3Iw');
if (not (running)) then // Checks our running boolean to see if we need to change colors.
bgColor := clRed; // Change the color to red if the script is not running.
SMART_ClearCanvas; // Clears the SMART canvas every time we call the function.
// ================ Begin code for Paint ================
// Print the title text
SMART_DrawTextEx (false, 22, 312, 'BigChars07', 'Iron AutoMiner', 65536);
// Draw the iron ore bitmap
SMARt_DrawBitmap(false, titleBMP, point(260, 310));
// Frees the bitmap
Freebitmap (titleBMP);
// Draw the big, surrounding black box as a border
SMART_DrawBoxEx(false, true, inttobox (7, 345, 512, 475), 65536);
// This draws the main green box, containing stats/events
SMART_DrawBoxEx(false, true, inttobox (17, 355, 502, 428), bgColor);
//Draws another black box to cut the first in half.
SMART_DrawBoxEx(false, true, inttobox (200, 349, 207, 451), 65536);
// Draws a box inside to create the lower green area, for status.
SMART_DrawBoxEx(false, true, inttobox (17, 438, 502, 465), bgcolor);
// Draws the line dividing 'status' and the actual status.
SMART_DrawBoxEx(false, true, inttobox (130, 437, 137, 467), 65536);
// Types 'Status' in large font
SMART_DrawTextEx (false, 27, 435, 'BigChars07', 'Status ', 65536);
// Types the actual status of the script.
SMART_DrawTextEx (false, 220, 445, 'UpChars07', Status, 65536);
// Types out how long the script has been running
SMART_DrawTextEx (false, 416, 328, 'UpChars07', '[' + timize(round (GetTimeRunning / 1000)) + ']', clWhite);
// Types out the ores mined.
SMART_DrawTextEx (false, 25, 371 - 13, 'SmallCharsNS07', 'Ore Mined: ', 65536);
SMART_DrawTextEx (false, 125, 371 - 13, 'SmallCharsNS07', GroupDigits (ores, ','), 65536);
// Types out the profit earned
SMART_DrawTextEx (false, 25, 410, 'SmallCharsNS07', 'Profit: ', 65536);
SMART_DrawTextEx (false, 125, 410, 'SmallCharsNS07', GroupDigits (ores * 95, ','), 65536);
// Types out the profit per hour
SMART_DrawTextEx (false, 25, 384 - 13, 'SmallCharsNS07', 'Profit/hour: ', 65536);
SMART_DrawTextEx (false, 125, 384 - 13, 'SmallCharsNS07', GroupDigits (round(1000 * (strtofloat ((floattostr (3600 * ores * 100))) / (StrToFloat (IntToStr (GetTimeRunning))))), ','), 65536);
// Types out experience
SMART_DrawTextEx (false, 25, 397 - 13, 'SmallCharsNS07', 'EXP: ', 65536);
SMART_DrawTextEx (false, 125, 397 - 13, 'SmallCharsNS07', GroupDigits (ores * 35, ','), 65536);
// Types out experience per hour
SMART_DrawTextEx (false, 25, 397, 'SmallCharsNS07', 'EXP/hour: ', 65536);
SMART_DrawTextEx (false, 125, 397, 'SmallCharsNS07', GroupDigits (Round(1000 * (strtofloat ((floattostr (3600 * 9.5 * ores))) / (StrToFloat (IntToStr (GetTimeRunning))))), ','), 65536);
// Types out events if there are less than five.
if (length(events) < 5) then
begin
for i := 0 to Length (events) - 1 do
begin
SMART_DrawTextEx (false, 220, 358 + (i * 13), 'SmallCharsNS07', events[i], 65536);
end;
end else
// Types out events if there are more than five.
begin
for i := length(events) - 5 to Length (events) - 1 do
begin
SMART_DrawTextEx (false, 220, 358 + ((Length(events) - i - 1) * 13), 'SmallCharsNS07', events[i], 65536);
end;
end;
// ================ End code for Paint ================
end;
Procedure Log (event: String; timestamp: boolean); // WriteLn's & Records an event and updates paint. Adds timestamp if specified.
var
stamp: String; // Declare timestamp
begin
stamp := ''; // Sets default to blank.
status := event; // Changes our script status to the event.
if (timestamp) then // Checks out input
stamp := '[' + timize(round (GetTimeRunning / 1000)) + '] '; // Adds timestamp to event.
setLength (events, Length (events) + 1); // Add blank event to our array
events[Length(events) - 1] := stamp + event; // Changes our blank event to inputted event.
WriteLn (stamp + event); // Prints the event in simba.
Paint(true); // Updates our paint. Script is running ok so true
end;
Procedure Fail;
begin
if (randomrange(1,500) = 1) then // Choose a number between 1 and 500
begin // and checks if it is one.
Log ('Unsolvable random found, terminating script...', false); // Randomly terminates script.
Paint (false); // Paints one last time, Running as false.
wait(5000); // Waits 5 seconds.
terminatescript; // Terminates script.
end;
end;
Procedure MainLoop; // The main loop of our script.
var
i, inventory: integer; // Declares variables.
begin
repeat // Repeats forever.
repeat // Repeats until inventory is full.
Log ('Attempting to mine an iron ore...', true); // Logging the event.
if (randomrange(1,5) = 1) then // Randomly chooses 1 to 5
begin // and checks if it is 1
Ores := Ores + 1; // We mined an ore!
Inventory := Inventory + 1; // Adding the ore to inventory
Log ('We managed to mine an iron ore!', true); // Logging the event.
end;
wait(100);
Fail;
until (inventory >= 28); // Checks if our inventory is full.
Log ('We have a full inventory, banking...', true); // Logs that we have full inventory.
for i:= 1 to 5 do // Walks to bank in 5 steps.
begin
wait(randomrange(200,400)); // Simulated walking.
Log ('Walking to bank, step ' + inttostr (i) + '/5', true); // Adding our events and changing status.
Fail; // The random chance of failing.
end;
wait(randomrange(200,400)); // Simulates banking time.
Log ('Successfully banked 28 iron ore!', true); // Adds our event and changes status.
inventory := 0; // Resets our inventory to zero.
for i:= 1 to 5 do // Walks back to mine in 5 steps.
begin
wait(randomrange(200,400)); // Simulates walking time taken.
Log ('Walking back to mine, step ' + inttostr (i) + '/5', true); // Adds event and changes status
Fail; // The random chance of failing.
end;
wait(randomrange(200,400)); // Simulating walking back to mine
Log ('Successfully walked back to the mine!', true); // Adds our event and changes status.
until (false);
end;
Procedure Kill; // Procedure to be called when the script terminates for whatever reason.
begin
writeLn ('Script terminated, you must restart.'); // Quick writeLn to inform the user that the script has ended.
Paint(false); // Tells the paint function we are no longer running. Effectively colors background to red.
end;
begin
setupSRL; // Sets up SRL;
AddOnTerminate('kill'); // Will call this function whenever the script is terminated, for any and all reasons.
MainLoop; // The main loop of the script.
Paint(false); // Paints one last time, this time with Running as false.
end.