Coh3n
2010-07-25 16:01:02
[INDENT]Hello! :)
I've noticed a few things the last couple days that we could change to make things easier and more orgainzed. We can eliminate some unneeded functions and make it even easier to add scripts!
Well, that's all I've noticed for now. If you see anything else, don't be afraid to post. :)
Cheers,
Coh3n[/INDENT]
I've noticed a few things the last couple days that we could change to make things easier and more orgainzed. We can eliminate some unneeded functions and make it even easier to add scripts!
- Add StartLoc & EndLoc attributes to the TScript record. This would mean we wouldn't have to update the following functions every time a new script is added.
- MSI_WalkToLoc and MSI_WalkToBank could be replaced with something like this:
- MSI_LoadRefPath and MSI_LoadColorPath would be replaced with:
- [COMMITTED TLocation Record] Add StartLocStr and EndLocStr to the TScript record. With these, we wouldn't need an MSI_LocToText function. Although, this may not be needed because once we introduce the relocator, each TLocation will have a Name attribute associated with it.
- [COMMITTED] MSI_ToolToText and MSI_GetItemNames aren't needed as we can just use MSI_Items[ItemHere].Name.
- In MSI_AutoObjects, we can use a skill case rather than a script case. This will mean we only have to update that function when a new skill is added. This can also be done with MSI_AddToProggy in Debug.simba.
- Add WhichBank to the TScript record so MSI_BankMaterials can be edited so that it doesn't need updating with every script.
function MSI_Walk(ToLoc: Boolean): Boolean;
var
Script: TScript;
begin
if (not LoggedIn) then
Exit;
MSI_Debug('MSI_WalkToLoc', 'Location = '+MSI_LocToText(MSI_Players[CurrentPlayer].Location), DEBUG_SMALL_DETAILS);
with MSI_Players[CurrentPlayer] do
begin
Script := MSI_Scripts[Scripts[CurrentScript]];
if (ToLoc) then
Result := (Location = Script.EndLoc)
else
Result := (Location = Script.StartLoc);
if (Result) then
Exit;
if (ToLoc) then
begin
if (Location = Script.StartLoc) then
Result := MSI_PerformWalk(Script.StartLoc, Script.EndLoc);
end else
if (Location = Script.EndLoc) then
Result := MSI_PerformWalk(Script.EndLoc, Script.StartLoc);
end;
end;
function MSI_LoadRefPath(ToLoc: Boolean): TPointArray;
var
Script: TScript;
begin
Script := MSI_Scripts[MSI_Players[CurrentPlayer].Scripts[CurrentScript]];
if (ToLoc) then
Result := MSI_Scripts[Script].PathRefTo
else
Result := MSI_Scripts[Script].PathRefFrom;
end;
function MSI_AutoObjects: Boolean;
var
objects: TIntegerArray;
scriptConst: Integer;
begin
if (not LoggedIn) then
Exit;
MakeCompass(MSI_Scripts[MSI_Players[CurrentPlayer].Scripts[CurrentScript]].CompassAng);
scriptConst := MSI_Players[CurrentPlayer].Scripts[CurrentScript];
objects := MSI_VarToIntArray(MSI_Players[CurrentPlayer].Objects[CurrentScript]);
case MSI_Scripts[scriptConst].SkillConstant of
SKILL_WOODCUTTING:
Result := MSI_ChopInvFull(objects);
SKILL_MINING:
Result := MSI_MineInvFull(objects);
else
MSI_Debug('MSI_AutoObjects', 'Invalid player script!', DEBUG_FUNCTIONS);
end;
if (MSI_Scripts[scriptConst].BankType = NoBank) then //drop the items if not banking
begin
MSI_CountItems;
MSI_DropAll;
MSI_AddToProggy(PROG_ADD_LOADS, -1, -1, -1);
Result := True;
end;
end;
function MSI_BankMaterials: Boolean;
var
intItems: TIntegerArray;
itemsDeposited: TBooleanArray;
i: Integer;
depAll: Boolean;
Script: TScript;
begin
if (not LoggedIn) then
Exit;
Script := MSI_Scripts[MSI_Players[CurrentPlayer].Scripts[CurrentScript]];
MSI_CountItems;
if (MSI_Players[CurrentPlayer].Location = Script.StartLoc) then
if (not MSI_OpenBank(Script.WhichBank, MSI_Players[CurrentPlayer].Pin)) then
begin
ProgressReportArray[CurrentPlayer].FalseReason := 'Failed to open bank: '+IntToStr(Script.WhichBank);
Exit;
end;
with MSI_Players[CurrentPlayer] do
begin
SetLength(itemsDeposited, Length(Items[CurrentScript]));
for i := 0 to High(Items[CurrentScript]) do
begin
intItems := MSI_VarToIntArray(Items[CurrentScript][i]);
itemsDeposited[i] := MSI_Deposit(intItems, [], depAll);
if (depAll) then
Break;
end;
end;
if (not depAll) then
for i := 0 to High(itemsDeposited) do
if (not itemsDeposited[i]) then
begin
Result := False;
ProgressReportArray[CurrentPlayer].FalseReason := 'Failed to deposit items';
Exit;
end;
MSI_AddToProggy(PROG_ADD_LOADS, -1, -1, -1);
Inc(Stats_CustomVars[STATS_BANKS]);
MSI_SendStats;
Result := True;
CloseBank;
end;
Well, that's all I've noticed for now. If you see anything else, don't be afraid to post. :)
Cheers,
Coh3n[/INDENT]