SRL Archive - SRL Archives

DTMFromInv


mixster

2008-04-13 21:42:07

Noticed that inventory DTM's seemed to follow a similar pattern, so I decided to make something that should help with making DTM's. It creates a DTM using the variable 'oDTM' based on the inventory slot 'slot' you put in with 'refPts' number of subpoints. This is a first version, so don't expect it to be 100% polished off, but I felt it was worthy of a mention and feel free to improve upon where you see fit.

procedure DTMFromInv(var oDTM: Integer; slot, refPts: Integer);
var
Skel: TDTM;
mainPt: TDTMPointDef;
subPts: array of TDTMPointDef;
outPts: TPointArray;
invBoxC: TBox;
i, outRat, rI: Integer;
begin
invBoxC := InvBox(slot);
if not FindColorsTolerance(outPts, 65536, invBoxC.x1, invBoxC.y1, invBoxC.x2, invBoxC.y2, 1) then
begin
Writeln('Unable to create DTM from inventory slot');
Exit;
end;
with mainPt do
begin
x := (invBoxC.x1 + invBoxC.x2) div 2;
y := (invBoxC.y1 + invBoxC.y2) div 2;
areasize:= 0;
areashape:= 0;
color:= GetColor(mainPt.x, mainPt.y);
tolerance:= 422;
end;
if GetArrayLength(outPts) < refPts then
Exit;
SetArrayLength(subPts, refPts);
outRat := GetArrayLength(outPts) div refPts;
for i := 0 to refPts - 1 do
begin
rI := Random(Random(outRat));
with subPts[i] do
begin
x := outPts[(i * outRat) + rI].x;
y := outPts[(i * outRat) + rI].y;
areasize:= 0;
areashape:= 0;
color:= 65536;
tolerance:= 1;
end;
end;
Skel.MainPoint := mainPt;
Skel.SubPoints := subPts;
oDTM := AddDTM(Skel);
end;
P.S. I do know about the double Random() - I used that as I wanted a low number without restricting it to very low numbers, so it makes it more likely to get a lowish number, but with bigger items and fewer reference points will still make it able to choose quite high random numbers so that the subpoints aren't as evenly spaced.
Edit: Updated the colour and tested for a bit with a couple of ores and bars it worked well with finding bars made from different bars and same with ores (tin and copper ores, bronze and iron bars).

HyperSecret

2008-04-14 01:42:57

have u tried this out actually? isnt the 'black' color in the inventory 65536? so shouldnt it be


if not FindColorsTolerance(outPts, 65536, invBoxC.x1, invBoxC.y1, invBoxC.x2, invBoxC.y2, 1) then

ShowerThoughts

2008-04-14 01:47:26

From: HyperSecret
have u tried this out actually? isnt the 'black' color in the inventory 65536? so shouldnt it be


if not FindColorsTolerance(outPts, 65536, invBoxC.x1, invBoxC.y1, invBoxC.x2, invBoxC.y2, 1) then


Yes i see it now to, he maybe thought that it was 0 but in the inv it is the color you stated above

Santa_Clause

2008-04-14 02:06:06

My version:

function MakeDDTM(InventorySpot : Integer; ItemName : string) : Integer;
var
I : Integer;
DDTMBox : TBox;
DDTMMainPoint : TPoint;
DDTMPoints : TPointArray;
DDTMSubPoints : TPointArrayArray;
DDTM : TDTM;
begin
if not(InRange(InventorySpot, 1, 28)) then
begin
WriteLn('Inventory Spot Must Be Between 1 And 28, Inclusive');
WriteLn('Exiting');
Exit;
end;

DDTMBox := InvBox(InventorySpot);
DDTMMainPoint := ItemCoords(InventorySpot);
FindColorsTolerance(DDTMPoints, 65536, DDTMBox.X1, DDTMBox.Y1, DDTMBox.X2, DDTMBox.Y2, 0);

DDTMSubPoints := TPAToATPA(DDTMPoints, 10);

WriteLn(ItemName + 'Main.X := ' + IntToStr(DDTMMainPoint.X));
WriteLn(ItemName + 'Main.Y := ' + IntToStr(DDTMMainPoint.Y));
WriteLn(ItemName + 'Main.AreaSize := 0');
WriteLn(ItemName + 'Main.AreaShape := 0');
WriteLn(ItemName + 'Main.Color := ' + IntToStr(GetColor(DDTMMainPoint.X, DDTMMainPoint.Y)));
WriteLn(ItemName + 'Main.Tolerance := 255');

for I := 0 to High(DDTMSubPoints) do
begin
WriteLn(' ');
WriteLn(ItemName + 'Sub[' + IntToStr(I) + '].X := ' + IntToStr(DDTMSubPoints[I][0].X));
WriteLn(ItemName + 'Sub[' + IntToStr(I) + '].Y := ' + IntToStr(DDTMSubPoints[I][0].Y));
WriteLn(ItemName + 'Sub[' + IntToStr(I) + '].AreaSize := 0');
WriteLn(ItemName + 'Sub[' + IntToStr(I) + '].AreaShape := 0');
WriteLn(ItemName + 'Sub[' + IntToStr(I) + '].Color := 65536');
WriteLn(ItemName + 'Sub[' + IntToStr(I) + '].Tolerance := 0');
end;

SetLength(DDTM, Length(DDTMSubPoints));

DDTM.MainPoint := DDTMMainPoint;
DDTM.SubPoints := DDTMSubPoints;
Result := AddDTM(DDTM);
end;

Mine doesn't let you pick number of reference points though.

ShowerThoughts

2008-04-14 02:24:13

From: Santa_Clause
My version:

function MakeDDTM(InventorySpot : Integer; ItemName : string) : Integer;
var
I : Integer;
DDTMBox : TBox;
DDTMMainPoint : TPoint;
DDTMPoints : TPointArray;
DDTMSubPoints : TPointArrayArray;
DDTM : TDTM;
begin
if not(InRange(InventorySpot, 1, 28)) then
begin
WriteLn('Inventory Spot Must Be Between 1 And 28, Inclusive');
WriteLn('Exiting');
Exit;
end;

DDTMBox := InvBox(InventorySpot);
DDTMMainPoint := ItemCoords(InventorySpot);
FindColorsTolerance(DDTMPoints, 65536, DDTMBox.X1, DDTMBox.Y1, DDTMBox.X2, DDTMBox.Y2, 0);

DDTMSubPoints := TPAToATPA(DDTMPoints, 10);

WriteLn(ItemName + 'Main.X := ' + IntToStr(DDTMMainPoint.X));
WriteLn(ItemName + 'Main.Y := ' + IntToStr(DDTMMainPoint.Y));
WriteLn(ItemName + 'Main.AreaSize := 0');
WriteLn(ItemName + 'Main.AreaShape := 0');
WriteLn(ItemName + 'Main.Color := ' + IntToStr(GetColor(DDTMMainPoint.X, DDTMMainPoint.Y)));
WriteLn(ItemName + 'Main.Tolerance := 255');

for I := 0 to High(DDTMSubPoints) do
begin
WriteLn(' ');
WriteLn(ItemName + 'Sub[' + IntToStr(I) + '].X := ' + IntToStr(DDTMSubPoints[I][0].X));
WriteLn(ItemName + 'Sub[' + IntToStr(I) + '].Y := ' + IntToStr(DDTMSubPoints[I][0].Y));
WriteLn(ItemName + 'Sub[' + IntToStr(I) + '].AreaSize := 0');
WriteLn(ItemName + 'Sub[' + IntToStr(I) + '].AreaShape := 0');
WriteLn(ItemName + 'Sub[' + IntToStr(I) + '].Color := 65536');
WriteLn(ItemName + 'Sub[' + IntToStr(I) + '].Tolerance := 0');
end;

SetLength(DDTM, Length(DDTMSubPoints));

DDTM.MainPoint := DDTMMainPoint;
DDTM.SubPoints := DDTMSubPoints;
Result := AddDTM(DDTM);
end;

Mine doesn't let you pick number of reference points though.


Does it works good? or just regular?

Santa_Clause

2008-04-14 04:48:39

Ask me in private message and I'll answer. No need to hijack his thread.

n3ss3s

2008-04-14 07:30:26

I don't want to hijack this thread nor bother to pm you -

WriteLn(ItemName + 'Main.Tolerance := 255');


What the…?

mixster

2008-04-14 08:28:07

I don't script on RS that much, so I wasn't aware of the change in colours, but I'll update that quickly and test it for a bit. I made it ad half two in the morning, so I just wanted to post it up for some feedback when I woke up.
And n3ss3s, I'm guessing you put the name of the item so it makes your DTM's more easily organised, so if you wanted a log DTM, you would get logMain and logSub as your DDTM points instead of just having mainPoints and subPoints which can get confusing if ou having more than 1 DDTM.
Edit: Updated it and tested it for a bit and ti worked well matching items and matching in different slots etc. so I'm calling it a success, though it fails miserably with 1 gp, but that's probably because it's too small :(

mastaraymond

2008-04-14 09:58:31

Be sure the subpoints aren't in the left upper corner, since the yellow text might ruin it..