SRL Archive - MSI Suggestions

Changes throughout the core


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!

  1. 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:

    • 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;
    • MSI_LoadRefPath and MSI_LoadColorPath would be replaced with:

    • 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;
  2. [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.
  3. [COMMITTED] MSI_ToolToText and MSI_GetItemNames aren't needed as we can just use MSI_Items[ItemHere].Name.
  4. 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.

  5. 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;
  6. Add WhichBank to the TScript record so MSI_BankMaterials can be edited so that it doesn't need updating with every script.

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

3Garrett3

2010-07-25 16:05:47

I think we should do it all except for #2, because the relocator will take care of it or introduce another change whenever it gets done.

Coh3n

2010-07-25 16:06:53

From: 3Garrett3
I think we should do it all except for #2, because the relocator will take care of it or introduce another change whenever it gets done.

Thanks, and yeah that seems more logical anyway.

Sabzi

2010-07-25 16:27:27

I thought there is a reason for those cases. I was always wondering why it isn't done like this. Well, I was wrong and there were no reason for those cases :p.
note to self: next time, don't be shy and suggest your stupid things

Coh3n

2010-07-25 16:29:04

From: Sabzi
I thought there is a reason for those cases. I was always wondering why it isn't done like this. Well, I was wrong and there were no reason for those cases :p.
note to self: next time, don't be shy and suggest your stupid things

Lol, yeah don't be shy. ;)

I'm not sure why I didn't see this before. I was actually looking for a way to minimize what we had to add for different scripts.

marpis

2010-07-25 19:12:32

The best thing would be to make it possible to add scripts just by adding a new record, along with new functions required of course..

Coh3n

2010-07-25 19:36:50

From: marpis
The best thing would be to make it possible to add scripts just by adding a new record, along with new functions required of course..

Yeah I know. That was my original plan, but there are difficulties that you run into. Eventually I hope for it to be this way though.

Naum

2010-07-27 08:24:31

Just remember, if you all want to change something make sure the tutorials are kept well versed with it also.

Sir R. M8gic1an

2010-07-27 11:32:53

Very good, etc.

As you'll probably have noticed I haven't been around much lately, so I won't make long posts, to be able to respond to everything.

~RM


//if (Location = Script.EndLoc) then
if (Location = ToLoc) then
begin
Result := True;
Exit;
end;

Coh3n

2010-07-27 19:03:40

From: Rasta Magician
Very good, etc.

As you'll probably have noticed I haven't been around much lately, so I won't make long posts, to be able to respond to everything.

~RM


//if (Location = Script.EndLoc) then
if (Location = ToLoc) then
begin
Result := True;
Exit;
end;

I don't know how that would work, but you pointed out the error to me. :p If you're suggesting maying ToLoc an Integer and the location to walk to, we could. That would require getting the current players location and going from there.


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;
Kind of an ugly function though. :o

3Garrett3

2010-07-27 19:33:45

From: Coh3n

Kind of an ugly function though. :o


Not many portions of MSI strike me as a beautiful looking function :p

Coh3n

2010-07-27 19:44:46

From: 3Garrett3
Not many portions of MSI strike me as a beautiful looking function :p

Haha yeah I guess you have a point there. :p

Sir R. M8gic1an

2010-07-29 19:33:00

The final bit looks good :)

~RM

Coh3n

2010-07-30 22:35:07

From: Rasta Magician
The final bit looks good :)

~RM

Awesome. :) I'll be able to start applying this, the recloator and the pointers on monday (I'll probably make a new thread, so keep an eye open).

Coh3n

2010-08-02 20:21:34

Committed a couple things. Also added MSI_AddToProggy to point 4.

Coh3n

2010-08-04 14:50:11

Committed everything, plus a TPath type which is used in the TScript records.

I'll be updating all the necessary tutorials shortly.

marpis

2010-08-06 02:10:27

Whee! :)

Now we can add locations by just making the record!

Coh3n

2010-08-06 11:06:51

From: marpis
Whee! :)

Now we can add locations by just making the record!

Ideally yeah. I haven't actually added a new script since this update, but I'm 98% sure that I didn't leave anything out. :p