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
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 .. 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). Gets the TAnimation record of the animation 'Anim'. 'Anim' represents one of
This procedure should only be called in MSI_LoadAllAnimations. 'Anim' represents the animation constants in
the animation constants MSI uses, which can be found in Globals.simba. `Globals.simba <https://github.com/SRL/MSI/raw/master/MSI/Core/Globals.simba>`_.


.. note:: .. note::


| Author: Coh3n | 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 begin
case Anim of 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: ANIM_ALCH_LOW:
with MSI_Animations[Anim] do with Result do
begin begin
Name := 'Low Alching'; Name := 'Low Alching';
MinPixelShift := 500; MinPixelShift := 500;
MaxPixelShift := 10000;
PixelBox := IntToBox(MSCX - 30, MSCY - 40, MSCX + 30, MSCY + 15); PixelBox := IntToBox(MSCX - 30, MSCY - 40, MSCX + 30, MSCY + 15);
Interval := 200; Interval := 200;
MaxWait := 2000; MaxTime := 2000;
WaitTime := 2000;
end; end;


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


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


(* ANIM_CHOPPING:
MSI_LoadAllAnimations with Result do
~~~~~~~~~~~~~~~~~~~~~ begin

Name := 'Chopping';
.. code-block:: pascal MinPixelShift := 180;

MaxPixelShift := 360;
procedure MSI_LoadAllAnimations(); PixelBox := IntToBox(PLBX1, PLBY1, PLBX2, PLBY2);

Interval := 35;
Loads all the animations into the MSI_Animations array. This procedure should MaxTime := 175; // (35 * 5) = 175 (Gets the average pixel shift from 5 tries)
only be called in SetupMSI. WaitTime := 700; // (175 * 4) = 700 (Has to fail 4 times to not be animating)

end;
.. note:: end;

| 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);
end; end;


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


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


Example: Example:


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


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


.. code-block:: pascal .. 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 Simply waits while the player is animating. Doesn't perform antiban or check for
randoms; just waits. randoms; just waits.


.. note:: .. note::


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


Example: Example:


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

t := (GetSystemTime + MaxWait);


while (GetSystemTime < t) do while (true) do
begin begin
if (not MSI_IsAnimating(Anim)) then t := (getSystemTime + waitTime);
Break; 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; end;
end; end;
Expand Down
28 changes: 18 additions & 10 deletions MSI/Core/Globals.simba
Expand Up @@ -426,7 +426,9 @@ const
MSI_RUNE_SOUL = 172; MSI_RUNE_SOUL = 172;
MSI_RUNE_ASTRAL = 173; 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 Object Constants
Expand Down Expand Up @@ -605,16 +607,17 @@ Example:


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

ANIM_ALCH_LOW = 10; ANIM_ALCH_LOW = 10;
ANIM_ALCH_HIGH = 11; ANIM_ALCH_HIGH = 11;


ANIM_FISHING = 20; ANIM_FISHING = 20;

ANIM_CHOPPING = 21;
ANIM_ARRAY_LENGTH = 20;


(* (*
Recipe Constants Recipe Constants
Expand Down Expand Up @@ -715,7 +718,7 @@ type
TMSObject = record TMSObject = record
X, Y : Integer; X, Y : Integer;
Name : string; Name : string;
UpText : string; // Set to '' if RightClickOnly := True UpText : string; // Set to '' if RightClickOnly := True
Option : string; Option : string;
Exp : Extended; Exp : Extended;
Colors : TIntegerArray; Colors : TIntegerArray;
Expand All @@ -725,12 +728,13 @@ type
Sat : Extended; Sat : Extended;
W, H : Integer; W, H : Integer;
Accuracy : Integer; // Min pixels to be found in each TPA 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 ExcludeSelf : Boolean; // Exclude pixels in a box around the player
RightClickOnly : Boolean; RightClickOnly : Boolean;
Tries : Integer; Tries : Integer;
Anim : Boolean; // Set to true if object is animating 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 MaxTime : Integer; // Max time (in ms) to wait for the object to disappear
BadColors : TIntegerArray; BadColors : TIntegerArray;
BadColorTolerance: Integer; BadColorTolerance: Integer;
Expand Down Expand Up @@ -1023,9 +1027,11 @@ type
TAnimation = record TAnimation = record
Name : string; Name : string;
MinPixelShift : Integer; // Minimum pixel shift for animation MinPixelShift : Integer; // Minimum pixel shift for animation
MaxPixelShift : Integer; // Maximum pixel shift
PixelBox : TBox; // Box to check for pixel shift PixelBox : TBox; // Box to check for pixel shift
Interval : Integer; // How long 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; end;


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



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


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

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


CLAY_SOFT: Result := 802904;

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


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


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

0 comments on commit bf3c743

Please sign in to comment.