SRL Archive - SRL Archives

PatternDropArray


ape

2009-10-16 20:29:00

This is a method I made during the production of my auto miner. It drops the specified inventory slot array in a randomly selected pattern. It has 7 base patterns built in and these can be reversed adding up to 14 different patterns.

Patterns include:
  • Snake Columns: Follows up and down each column without skipping.
  • Snake Rows: Similar to columns
  • Box Spiral: Follows through all inventory slots in a spiral pattern.
  • Columns: Drops each column separately starting at the top/bottom of each one consistently.
  • Rows: Similar behavior as columns except with rows.
  • Every other row: Self explanatory.
  • Every other column: Self explanatory.
{*******************************************************************************
procedure DropPatternEx(InvSlots: TIntegerArray; Exclude: Boolean);
By: Ape
Description: Drops items in slots specified in "InvSlots" in 14 randomly selected patterns.
If Exclude is True, it will drop all slots, except the specified slots.
If Exclude is False, it will drop only the specified slots.
Usage: "DropPatternEx([1, 3, 5, 8], False);" drops slots 1, 3, 5, 8.
"DropPatternEx([1, 3, 5, 8], True);" drops all slots except 1, 3, 5, 8.
*******************************************************************************}
procedure DropPatternEx(InvSlots: TIntegerArray; Exclude: Boolean);
var
I: Byte;
Ptn: TIntegerArray;
begin
SetLength(Ptn, 28);
Gametab(tab_inv);

{ -Patterns-
0: Snake columns
1: Snake rows
2: Box spiral
3: Columns
4: Rows
5: Every other row
6: Every other column }

case Random(7) of
0: Ptn:=[1,5,9,13,17,21,25,26,22,18,14,10,6,2,3,7,11,15,19,23,27,28,24,20,16,12,8,4];
1: Ptn:=[1,2,3,4,8,7,6,5,9,10,11,12,16,15,14,13,17,18,19,20,24,23,22,21,25,26,27,28];
2: Ptn:=[1,2,3,4,8,12,16,20,24,28,27,26,25,21,17,13,9,5,6,7,11,15,19,23,22,18,14,10];
3: Ptn:=[1,5,9,13,17,21,25,2,6,10,14,18,22,26,3,7,11,15,19,23,27,4,8,12,16,20,24,28];
4: Ptn:=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28];
5: Ptn:=[1,2,3,4,9,10,11,12,17,18,19,20,25,26,27,28,5,6,7,8,13,14,15,16,21,22,23,24];
6: Ptn:=[1,5,9,13,17,21,25,4,8,12,16,20,24,28,2,6,10,14,18,22,26,3,7,11,15,19,23,27];
end;

if Random(2) = 1 then
InvertTIA(Ptn);

for I := 0 to 27 do
if(Exclude)then
if (not InIntArray(InvSlots, Ptn[I])) then
DropItem(Ptn[i])
else
if (InIntArray(InvSlots, Ptn[I])) then
DropItem(Ptn[i]);

end;

{*******************************************************************************
procedure DropAll;
By: Ape
Description: Drops all items in inventory using patterns.
*******************************************************************************}
procedure DropAll;
begin
DropPatternEx([], True);
end;

{*******************************************************************************
procedure DropAllExcept(IgnoreInvSlots: TIntegerArray);
By: Ape
Description: Drops all items except specified in inventory using patterns.
*******************************************************************************}
procedure DropAllExcept(IgnoreInvSlots: TIntegerArray);
begin
DropPatternEx(IgnoreInvSlots, True);
end;

{*******************************************************************************
procedure DropArray(InvSlots: TIntegerArray);
By: Ape
Description: Drops item positioned equivalent to numbers in "InvSlots" array.
Example: "DropArray([2, 4, 9, 12]);" would drop items in InvSlot 2, 4, 9 and 12.
*******************************************************************************}
procedure DropArray(InvSlots: TIntegerArray);
begin
DropPatternEx(InvSlots, False);
end;

{*******************************************************************************
(DEPRECATED)Procedure DropPattern(Which: Integer);(DEPRECATED)
By: Ape
Description: Drops all items in inventory using DropAll; (DEPRECATED)
WARNING: This method is out of date! Use "DropAll;" instead!
*******************************************************************************}
procedure DropPattern(Which: Integer);
begin
DropAll;
end;

EvilChicken!

2009-10-16 21:06:49

Can you try to implement the patterns that aren't already existing, to DropPattern in Inventory.scar?

ape

2009-10-16 21:40:44

From: EvilChicken!
Can you try to implement the patterns that aren't already existing, to DropPattern in Inventory.scar?


Sure, it is possible. I am not going to program them out as Rasta did as it is quite pointless. Perhaps we could figure out a way to merge/rework the two in some manner.

I have updated the method so that it can be implemented into all multi drop methods in SRL. I have also rewritten these for your convenience. This now makes DropPattern deprecated. I have included a modified DropPattern method that utilizes my dropping method so no scripts will be broken. Enjoy.

Nava2

2009-10-17 14:40:02

I think that this should be able to be picked.

So using constants makes more sense.

Also, why not have a "LoadInventoryPattern(pattern: Integer): TIntegerArray"

ape

2009-10-17 15:48:32

From: Nava2
I think that this should be able to be picked.

So using constants makes more sense.

Also, why not have a "LoadInventoryPattern(pattern: Integer): TIntegerArray"


I see what you mean now. But this would limit the number of patterns that get used? I think it would most likely be safer if it changed randomly as it does now. Maybe I could make it so if it is left as default, it chooses randomly, otherwise it will pick the chosen pattern?

Nava2

2009-10-17 15:51:33

Why would it limit anything?

Someone could do:
var
intArr: TIntegerArray;
begin
intArr := [dropPattern_Snake, dropPattern_Columns];
//...
DropPattern(intArr[Random(Length(inArr))]);

etc etc

ape

2009-10-17 20:01:27

From: Nava2
Why would it limit anything?

Someone could do:
var
intArr: TIntegerArray;
begin
intArr := [dropPattern_Snake, dropPattern_Columns];
//...
DropPattern(intArr[Random(Length(inArr))]);

etc etc


I see, this would not require much work at all. We could check to see if the constant has remained at it's default value, and if so, it would randomly pick one. Otherwise, we could have an array as you are suggesting. I will implement this soon.

Nava2

2009-10-19 14:21:01

I meant naming each one with a constant for in the case. The constant wouldn't change but stay the same and just let the choice go better