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.
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).
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).