SRL Archive - SRL Archives

ItemToDTM(Slot: integer): integer;


marpis

2009-04-09 09:08:27

I don't think this needs much introduction.

EDIT 9/April/2009, 08:08 AM : Added RAaSTPA to make the DTM use less memory.

{*******************************************************************************
function ItemToDTM(Slot: integer): integer;
By: marpis
Description: Creates a DTM of an item in inventory.
*******************************************************************************}
function ItemToDTM(Slot: integer): integer;
var
i: integer;
TPA: TPointArray;
Box: TBox;
P: TPoint;
dtmMainPoint: TDTMPointDef;
dtmSubPoints: Array of TDTMPointDef;
TempTDTM: TDTM;
begin
if (Slot < 1) or (Slot > 28) then
begin
writeln('[ERROR] ItemToDTM: '+inttostr(slot)+' is not a valid inventory slot!');
exit;
end;
Box:= InvBox(slot);
FindColorsTolerance(TPA, 65536, Box.x1, Box.y1, Box.x2, Box.y2, 0);
if Length(TPA) < 10 then
begin
writeln('[ERROR] ItemToDTM: Item not found in slot '+inttostr(slot)+'!');
exit;
end;
RAaSTPA(TPA, 5); // thanks Zeph
SetArrayLength(dtmSubPoints, Length(TPA));
P:= TPA[0];
dtmMainPoint.x := P.x;
dtmMainPoint.y := P.y;
dtmMainPoint.AreaSize := 0;
dtmMainPoint.AreaShape := 0;
dtmMainPoint.Color := 65536;
dtmMainPoint.Tolerance := 0;
for i:= 1 to High(TPA) do
begin
P:= TPA[i];
dtmSubPoints[i].x := P.x;
dtmSubPoints[i].y := P.y;
dtmSubPoints[i].AreaSize := 0;
dtmSubPoints[i].AreaShape := 0;
dtmSubPoints[i].Color := 65536;
dtmSubPoints[i].Tolerance := 0;
end;
TempTDTM.MainPoint := dtmMainPoint;
TempTDTM.SubPoints := dtmSubPoints;
Result := AddDTM(TempTDTM);
end;

Laur€ns

2009-04-09 09:24:35

Two words: Good Job! Is it OK if I use this in my (upcoming) TzHaar miner?

marpis

2009-04-09 09:43:17

Ofcourse, that's why i made it. i hope it gets in the next SRL rev :)