SRL Archive - MSI Suggestions

DDTMs


Coh3n

2010-04-28 16:00:29

I've got it working and everything. Not sure how I feel about how the colors are declared and I have a sneaking feeling RM is going to say something like "No hard-coded values in MSI!" or something like that. :p

I will switch them all the constants if need be.


{******************************************************************************}
{ function MSI_GetDTMInfo(which: Integer): TIntegerArray; }
{ By: Coh3n }
{ Description: Gets the coodinates for the DTM points }
{******************************************************************************}
function MSI_GetDTMInfo(which: Integer): TIntegerArray;
begin
case which of
HATCHET_BRONZE..HATCHET_RUNE:
Result := [ 921, 515, 909, 534, 908, 525, 915, 512, 925, 519 ];

LOGS_NORMAL..LOGS_YEW:
Result := [ 1155, 290, 1164, 281, 1164, 290, 1147, 294, 1143, 280 ];

else
MSI_Debug('MSI_GetDTMInfo', 'Invalid item constant!', DEBUG_FUNCTIONS);
end;
end;

{******************************************************************************}
{ function MSI_LoadDTM(which: Integer): Integer; }
{ By: Coh3n and Ejjman1 }
{ Description: Loads the DTM specified by 'which' }
{******************************************************************************}
function MSI_LoadDTM(which: Integer): Integer;
var
dtmMainPoint: TDTMPointDef;
dtmSubPoints: Array [0..4] of TDTMPointDef;
TempTDTM: TDTM;
pts: TIntegerArray;
clr, i: Integer;
begin
pts := MSI_GetDTMInfo(which);
case which of
HATCHET_BRONZE: clr := 1649466;
HATCHET_IRON: clr := 3618618;
HATCHET_STEEL: clr := 5855581;
HATCHET_MITHRIL: clr := 4599598;
HATCHET_ADAMANT: clr := 3291698;
HATCHET_RUNE: clr := 4932921;

LOGS_NORMAL: clr := 2704989;
LOGS_OAK: clr := 3760771;
LOGS_WILLOW: clr := 1325634;
LOGS_MAPLE: clr := 800853;
LOGS_YEW: clr := 668228;
end;

with dtmMainPoint do
begin
x := pts[DTM_X1];
y := pts[DTM_Y1];
AreaSize := 0;
AreaShape := 0;
Color := clr;
Tolerance := DTM_TOLERANCE;
end;

for i := 0 to High(dtmSubPoints) do
with dtmSubPoints[i] do
begin
AreaSize := 0;
AreaShape := 0;

if (i > 0) then
begin
Color := SRL_OUTLINE_BLACK
Tolerance := 0;
end else begin
Color := clr;
Tolerance := DTM_TOLERANCE;
end;
end;

dtmSubPoints[0].x := pts[DTM_X1];
dtmSubPoints[0].y := pts[DTM_Y1];

dtmSubPoints[1].x := pts[DTM_X2];
dtmSubPoints[1].y := pts[DTM_Y2];

dtmSubPoints[2].x := pts[DTM_X3];
dtmSubPoints[2].y := pts[DTM_Y3];

dtmSubPoints[3].x := pts[DTM_X4];
dtmSubPoints[3].y := pts[DTM_Y4];

dtmSubPoints[4].x := pts[DTM_X5];
dtmSubPoints[4].y := pts[DTM_Y5];

TempTDTM.MainPoint := dtmMainPoint;
TempTDTM.SubPoints := dtmSubPoints;
Result := AddDTM(TempTDTM);
end;

In the public thread we talked about using MSI_GetItem to get the item's colors, but that doesn't work because MSI_GetItem calls MSI_LoadDTM, which calls MSI_GetItem, etc., etc., thus causing a mass amount of lag, not to mention it not working. :p

Naum also mentioned using a TIntegerArray for the colors, but I thought this was more readable, etc. Please update if there's a better method. :)

NCDS

2010-04-28 16:35:35

I personally think the colors should definitely be constants.

That alone would help with user readability if we were to put them in an array, which has my vote ;), as opposed to using a case statement.

Coh3n

2010-04-28 16:55:43

From: NCDS
I personally think the colors should definitely be constants.

That alone would help with user readability if we were to put them in an array, which has my vote ;), as opposed to using a case statement.

I thought about that too. If it was in an array, and they were constants, it may not be that bad.

Sir R. M8gic1an

2010-05-02 13:36:50

humm.

The colors as they are atm do not seem bad to me tbh. However, to expand on the array idea..


var //global
ColorArray: TIntegerArray;

Proc SetupColors;
begin
ColorArray[HATCHET_RUNE] := 00000;
//and so on..
end;

or


function GetItemColor(which: integer): integer;
begin
case which of
HATCHET_RUNE: Result := 000000;
//...
end;
end;

But I really don't see the usefulness of

HATCHET_RUNE_COLOR

Seems like overloading work / consts / crowded / etc

I would suggest using the second function, at is would make the GetDDTM function cleaner.

~RM

Coh3n

2010-05-02 17:00:46

I like the second one also. I'm surprised I didn't do that initially, I usually think of things like that. :p

E: Done.