Skip to content
This repository has been archived by the owner on Dec 6, 2018. It is now read-only.

Commit

Permalink
Rewrote Animating.simba to use AveragePixelShift (much more accurate …
Browse files Browse the repository at this point in the history
…now); Added a 'Track' attribute to TMSObject: now if WaitToMove is true, will call flag else MSI_TrackObject, if both are true will call MSI_TrackObject; Removed MSI_Animations global array (will eventually do with all global arrays); Added CLAY_SOFT item.
  • Loading branch information
cohenadair committed Apr 2, 2011
1 parent ea1aa13 commit bf3c743
Show file tree
Hide file tree
Showing 8 changed files with 224 additions and 88 deletions.
152 changes: 93 additions & 59 deletions MSI/Core/Animating.simba
Original file line number Diff line number Diff line change
Expand Up @@ -10,82 +10,103 @@ The source for can be found

*)

const
// PLB = Player Box (a tight box around the player)
PLBX1 = MSCX - 10;
PLBY1 = MSCY - 25;
PLBX2 = MSCX + 15;
PLBY2 = MSCY + 15;

(*
MSI_LoadAnimation
~~~~~~~~~~~~~~~~~
MSI_GetAnimation
~~~~~~~~~~~~~~~~

.. code-block:: pascal

procedure MSI_LoadAnimation(Anim: Integer);
procedure MSI_GetAnimation(Anim: Integer): TAnimation;

Loads the animation 'Anim' (sets 'Anim' in the MSI_Animations global array).
This procedure should only be called in MSI_LoadAllAnimations. 'Anim' represents
the animation constants MSI uses, which can be found in Globals.simba.
Gets the TAnimation record of the animation 'Anim'. 'Anim' represents one of
the animation constants in
`Globals.simba <https://github.com/SRL/MSI/raw/master/MSI/Core/Globals.simba>`_.

.. note::

| Author: Coh3n
| Last Updated: 12 March 2011 by IPwnz
| Last Updated: 31 March 2011 by Coh3n

Example:

.. code-block:: pascal

var
anim: TAnimation;
begin
anim := MSI_GetAnimation(ANIM_FISHING);
end;
*)
procedure MSI_LoadAnimation(Anim: Integer);
function MSI_GetAnimation(Anim: Integer): TAnimation;
begin
case Anim of
ANIM_IDLE:
with Result do
begin
Name := 'Player Idle';
MinPixelShift := 10;
MaxPixelShift := 60;
PixelBox := IntToBox(PLBX1, PLBY1, PLBX2, PLBY2);
Interval := 25;
MaxTime := 125;
WaitTime := 500;
end;

ANIM_ALCH_LOW:
with MSI_Animations[Anim] do
with Result do
begin
Name := 'Low Alching';
MinPixelShift := 500;
MaxPixelShift := 10000;
PixelBox := IntToBox(MSCX - 30, MSCY - 40, MSCX + 30, MSCY + 15);
Interval := 200;
MaxWait := 2000;
MaxTime := 2000;
WaitTime := 2000;
end;

ANIM_ALCH_HIGH:
with MSI_Animations[Anim] do
with Result do
begin
Name := 'High Alching';
MinPixelShift := 500;
MaxPixelShift := 10000;
PixelBox := IntToBox(MSCX - 30, MSCY - 40, MSCX + 30, MSCY + 15);
Interval := 200;
MaxWait := 3000;
MaxTime := 3000;
WaitTime := 3000;
end;

ANIM_FISHING:
with MSI_Animations[Anim] do
with Result do
begin
Name := 'Fishing';
MinPixelShift := 750;
MaxPixelShift := 10000;
PixelBox := IntToBox(MSCX - 25, MSCY - 30, MSCX + 25, MSCY + 25);
Interval := 1250;
MaxWait := 3000;
MaxTime := 3000;
WaitTime := 3000;
end;
end;
end;

(*
MSI_LoadAllAnimations
~~~~~~~~~~~~~~~~~~~~~

.. code-block:: pascal

procedure MSI_LoadAllAnimations();

Loads all the animations into the MSI_Animations array. This procedure should
only be called in SetupMSI.

.. note::

| Author: Coh3n
| Last Updated: 07 February 2011 by Coh3n

*)
procedure MSI_LoadAllAnimations();
var
i: Integer;
begin
for i := 0 to High(MSI_Animations) do
MSI_LoadAnimation(i);
ANIM_CHOPPING:
with Result do
begin
Name := 'Chopping';
MinPixelShift := 180;
MaxPixelShift := 360;
PixelBox := IntToBox(PLBX1, PLBY1, PLBX2, PLBY2);
Interval := 35;
MaxTime := 175; // (35 * 5) = 175 (Gets the average pixel shift from 5 tries)
WaitTime := 700; // (175 * 4) = 700 (Has to fail 4 times to not be animating)
end;
end;
end;

(*
Expand All @@ -102,7 +123,7 @@ constants found in Globals.simba.
.. note::

| Author: Coh3n
| Last Updated: 07 February 2011 by Coh3n
| Last Updated: 31 March 2011 by Coh3n

Example:

Expand All @@ -114,14 +135,17 @@ Example:
Wait(RandomRange(200, 800));
end;
*)
function MSI_IsAnimating(Anim: Integer): Boolean;
function MSI_IsAnimating(Anim: TAnimation): Boolean;
var
avg: integer;
begin
with MSI_Animations[Anim] do
if (PixelShift(PixelBox, Interval) > MinPixelShift) then
begin
MSI_SubDebug('We are animating: ' + Name);
Result := True;
end;
with Anim do
begin
avg := averagePixelShift(pixelBox, interval, maxTime);
result := inRange(avg, minPixelShift, maxPixelShift);

//MSI_SubDebug('Average pixel shift = ' + intToStr(avg));
end;
end;

(*
Expand All @@ -130,15 +154,15 @@ MSI_WaitWhileAnimating

.. code-block:: pascal

procedure MSI_WaitWhileAnimating(Anim: Integer);
procedure MSI_WaitWhileAnimating(Anim: TAnimation);

Simply waits while the player is animating. Doesn't perform antiban or check for
randoms; just waits.

.. note::

| Author: Coh3n
| Last Updated: 07 February 2011 by Coh3n
| Last Updated: 31 March 2011 by Coh3n

Example:

Expand All @@ -147,23 +171,33 @@ Example:
if (MSI_CastInvItem(SPELL_ALCH_HIGH, 16)) then
MSI_WaitWhileAnimating(ANIM_ALCH_HIGH);
*)
procedure MSI_WaitWhileAnimating(Anim: Integer);
procedure MSI_WaitWhileAnimating(Anim: TAnimation);
var
t: Integer;
t: integer;
b: boolean;
begin
with MSI_Animations[Anim] do
with Anim do
begin
if (MSI_SetupVars[SETUP_DEBUG_SMART]) then
SMART_DrawBoxEx(True, PixelBox, clRed);

t := (GetSystemTime + MaxWait);
SMART_DrawBoxEx(true, pixelBox, clYellow);

while (GetSystemTime < t) do
while (true) do
begin
if (not MSI_IsAnimating(Anim)) then
Break;
t := (getSystemTime + waitTime);
while (getSystemTime < t) do
begin
if (MSI_IsAnimating(Anim)) then
begin
b := true;
break;
end;

b := false;
wait(10);
end;

Wait(RandomRange(10, 30));
if (not b) then
break;
end;
end;
end;
Expand Down
28 changes: 18 additions & 10 deletions MSI/Core/Globals.simba
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,9 @@ const
MSI_RUNE_SOUL = 172;
MSI_RUNE_ASTRAL = 173;

ITEM_ARRAY_LENGTH = 173; // Change to the highest item constant
CLAY_SOFT = 180;

ITEM_ARRAY_LENGTH = 180; // Change to the highest item constant

(*
Object Constants
Expand Down Expand Up @@ -605,16 +607,17 @@ Example:

function GetHighAlchAnimation(): TAnimation;
begin
Result := MSI_Animations[ANIM_ALCH_HIGH];
Result := MSI_GetAnimation(ANIM_ALCH_HIGH);
end;
*)
const
ANIM_IDLE = 0;

ANIM_ALCH_LOW = 10;
ANIM_ALCH_HIGH = 11;

ANIM_FISHING = 20;

ANIM_ARRAY_LENGTH = 20;
ANIM_FISHING = 20;
ANIM_CHOPPING = 21;

(*
Recipe Constants
Expand Down Expand Up @@ -715,7 +718,7 @@ type
TMSObject = record
X, Y : Integer;
Name : string;
UpText : string; // Set to '' if RightClickOnly := True
UpText : string; // Set to '' if RightClickOnly := True
Option : string;
Exp : Extended;
Colors : TIntegerArray;
Expand All @@ -725,12 +728,13 @@ type
Sat : Extended;
W, H : Integer;
Accuracy : Integer; // Min pixels to be found in each TPA
SearchArea : TBox; // Box to search for object. Carries the Values of MSBox by default.
SearchArea : TBox; // Box to search for object. Carries the Values of MSBox by default.
ExcludeSelf : Boolean; // Exclude pixels in a box around the player
RightClickOnly : Boolean;
Tries : Integer;
Anim : Boolean; // Set to true if object is animating
WaitToMove : Boolean; // When ClickLeft, wait till we have stopped moving?
WaitToMove : Boolean; // When clicked, wait till we have stopped moving? Calls Flag;
Track : Boolean; // When clicked, track the object while the player moves? Calls MSI_TrackObject;
MaxTime : Integer; // Max time (in ms) to wait for the object to disappear
BadColors : TIntegerArray;
BadColorTolerance: Integer;
Expand Down Expand Up @@ -1023,9 +1027,11 @@ type
TAnimation = record
Name : string;
MinPixelShift : Integer; // Minimum pixel shift for animation
MaxPixelShift : Integer; // Maximum pixel shift
PixelBox : TBox; // Box to check for pixel shift
Interval : Integer; // How long to check for pixel shift
MaxWait : Integer; // Maximum wait time for animation
MaxTime : Integer; // Gets the average pixel shift over MaxTime
WaitTime : Integer; // How long to wait for animation in ms
end;

TAnimationArray = array of TAnimation;
Expand Down Expand Up @@ -1081,5 +1087,7 @@ var
MSI_Pointers : array[0..POINTER_ARRAY_LENGTH] of TPointer;
MSI_Obstacles : array[0..OBS_ARRAY_LENGTH] of TObstacle;
MSI_Recipes : array[0..RECIPES_ARRAY_LENGTH - 1] of TRecipe;
MSI_Animations: array[0..ANIM_ARRAY_LENGTH] of TAnimation;
MSI_Spells : array[0..SPELL_ARRAY_LENGTH] of TMagicSpell;



20 changes: 20 additions & 0 deletions MSI/Core/Items.simba
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,15 @@ begin
Point(576, 451)
];

CLAY_SOFT:
Result := [
Point(28, 25),
Point(16, 27),
Point(27, 13),
Point(39, 26),
Point(28, 33)
];

else
MSI_SubDebug('MSI_GetDTMPoints: Invalid item constant - ' + IntToStr(which));
end;
Expand Down Expand Up @@ -430,6 +439,8 @@ begin
MSI_RUNE_SOUL : Result := 0;
MSI_RUNE_ASTRAL: Result := 0;

CLAY_SOFT: Result := 802904;

else
MSI_SubDebug('MSI_GetItemColor: Invalid item constant - '+IntToStr(Which));
end;
Expand Down Expand Up @@ -1307,6 +1318,15 @@ begin
Stackable := True;
EquipLevel := -1;
end;

CLAY_SOFT:
with MSI_Items[whichItem] do
begin
Name := 'Soft Clay'; // Name of the item
UpText := ['oft clay']; // Uptext
Stackable := False; // Is it stackable?
EquipLevel := -1; // Set to -1 if it can't be equipped
end;
end;

Result := (MSI_Items[whichItem].Name <> '');
Expand Down
1 change: 1 addition & 0 deletions MSI/Core/Mainloop.simba
Original file line number Diff line number Diff line change
Expand Up @@ -1121,6 +1121,7 @@ begin
MSI_ClearFile(PATH_REMOTE);
MSI_FreeAllItems;
FreeSRL;
SMART_FreeDebug();

for i := 0 to High(MSI_Files) do
CloseFile(MSI_Files[i]);
Expand Down

0 comments on commit bf3c743

Please sign in to comment.