vilon
2009-07-10 12:43:24
Hello everyone, felt like the quite recent changes in SRL to Timing.scar should be added to reflection as well.
Here's my outcome:
I tried to keep the same layout for every waiting function, as I belive it's better. Also, I wasn't sure if it would be better to include other similar waiting functions, which already are in the reflection include, but decided to do so.
WaitAnimation is \Characters.scar\function WaitForAnim
WaitAnimationBool is \Characters.scar\function CharAnimBool
WaitToMove is \MMWalk.scar\function WaitToMove
Original credit is kept for the functions I merely slightly changed and/or changed into reflection, which is basicly all of them.
Thoughts/ideas on this?
Here's my outcome:
//------------------------------------------------------------------\\
//-- Scar Non-Standard Resource Library --||
//-- ยป Reflection Routines - Timing --||
//------------------------------------------------------------------//
// * function R_WaitOptionMulti(S: TStringArray; Time: Integer): Boolean; // * by Marpis, N1ke! & vilon
// * function R_WaitOption(S: string; Time: Integer): Boolean; // * by Marpis, N1ke! & vilon
// * function R_WaitActionMulti(S: TStringArray; Time: Integer): Boolean; // * by vilon
// * function R_WaitAction(S: string; Time: Integer): Boolean; // * by vilon
// * function R_WaitUpTextMulti(S: TStringArray; Time: Integer): Boolean; // * by Marpis, N1ke! & vilon
// * function R_WaitUpText(S: string; Time: Integer): Boolean; // * by Marpis, N1ke! & vilon
// * function WaitAnimation(Time: Integer): Integer; // * by lordsaturn & vilon
// * function WaitAnimationBool(Time: Integer): Boolean; // * by vilon
// * function WaitMenu(Time: Integer): Boolean; // * by Drags111 & vilon
// * function WaitToMove(Time: Integer): Boolean; // * by lordsaturn & vilon
function R_ChooseOptionMulti(Options: TStringArray): Boolean; forward;
function R_ChooseActionMulti(Actions: TStringArray): Boolean; forward;
function R_IsUpTextMulti(UpText: TStringArray): Boolean; forward;
function GetAnimation: Integer; forward;
function IsOptionMenuOpen: Boolean; forward;
{*******************************************************************************
function R_WaitOptionMulti(S: TStringArray; Time: Integer): Boolean;
By: Marpis, N1ke! & vilon
Description: Waits for a TStringArray of Options and selects one of them.
*******************************************************************************}
function R_WaitOptionMulti(S: TStringArray; Time: Integer): Boolean;
var
T: Integer;
begin
Result := False;
T := GetSystemTime + Time;
repeat
Result := R_ChooseOptionMulti(S);
Wait(20 + Random(10));
until(Result or (GetSystemTime > T));
end;
{*******************************************************************************
function R_WaitOption(S: string; Time: Integer): Boolean;
By: Marpis, N1ke! & vilon
Description: Waits for an Option and selects it.
*******************************************************************************}
function R_WaitOption(S: string; Time: Integer): Boolean;
begin
Result := R_WaitOptionMulti([S], Time);
end;
{*******************************************************************************
function R_WaitActionMulti(S: TStringArray; Time: Integer): Boolean;
By: vilon
Description: Waits for a TStringArray of Actions and selects one of them.
*******************************************************************************}
function R_WaitActionMulti(S: TStringArray; Time: Integer): Boolean;
var
T: Integer;
begin
Result := False;
T := GetSystemTime + Time;
repeat
Result := R_ChooseActionMulti(S);
Wait(10 + Random(20));
until(Result or (GetSystemTime > T));
end;
{*******************************************************************************
function R_WaitAction(S: string; Time: Integer): Boolean;
By: vilon
Description: Waits for an Action and selects it.
*******************************************************************************}
function R_WaitAction(S: string; Time: Integer): Boolean;
begin
Result := R_WaitActionMulti([S], Time);
end;
{*******************************************************************************
function R_WaitUpTextMulti(S: TStringArray; Time: Integer): Boolean;
By: Marpis, N1ke! & vilon
Description: Waits for a TStringArray of UpText, returns true if found.
*******************************************************************************}
function R_WaitUpTextMulti(S: TStringArray; Time: Integer): Boolean;
var
T: Integer;
begin
Result := False;
T := GetSystemTime + Time;
repeat
Result := R_IsUpTextMulti([S]);
Wait(20 + Random(20));
until(Result or (GetSystemTime > T));
end;
{*******************************************************************************
function R_WaitUpText(S: string; Time: Integer): Boolean;
By: Marpis, N1ke! & vilon
Description: Waits for an UpText, returns true if found.
*******************************************************************************}
function R_WaitUpText(S: string; Time: Integer): Boolean;
begin
Result := R_WaitUpTextMulti([S], Time);
end;
{*******************************************************************************
function WaitAnimation(Time: Integer): Integer;
By: lordsaturn & vilon
Description: Waits for an animation with a timeout. If an animation occurs, the
value will be returned, else returns -1.
*******************************************************************************}
function WaitAnimation(Time: Integer): Integer;
var
T: Integer;
begin
Result := -1;
T := GetSystemTime + Time;
repeat
Result := GetAnimation;
Wait(100);
until((Result <> -1) or (GetSystemTime > T));
end;
{*******************************************************************************
function WaitAnimationBool(Time: Integer): Boolean;
By: vilon
Description: Waits for an animation with a timeout. Returns true on animation.
*******************************************************************************}
function WaitAnimationBool(Time: Integer): Boolean;
begin
Result := (WaitAnimation(Time) <> -1);
end;
{*******************************************************************************
function WaitMenu(Time: Integer): Boolean;
By: Drags111 & vilon
Description: Waits until the menu is open or times out.
*******************************************************************************}
function WaitMenu(Time: Integer): Boolean;
var
T: Integer;
begin
Result := False;
T := GetSystemTime + Time;
repeat
Result := IsOptionMenuOpen;
Wait(10 + Random(20));
until(Result or (GetSystemTime > T));
end;
{*******************************************************************************
function WaitToMove(Time: Integer): Boolean;
By: lordsaturn & vilon
Description: Waits for the local player to move with a timeout. Returns true if
moved, false if timed out.
*******************************************************************************}
function WaitToMove(Time: Integer): Boolean;
var
T, Player: Integer;
begin
Result := False;
T := GetSystemTime + Time;
repeat
Player := SmartGetFieldObject(0, MyPlayer);
Result := (SmartGetFieldInt(Player, CharMotion) > 0);
SmartFreeObject(Player);
Wait(100);
until(Result or (GetSystemTime > T));
end;I tried to keep the same layout for every waiting function, as I belive it's better. Also, I wasn't sure if it would be better to include other similar waiting functions, which already are in the reflection include, but decided to do so.
WaitAnimation is \Characters.scar\function WaitForAnim
WaitAnimationBool is \Characters.scar\function CharAnimBool
WaitToMove is \MMWalk.scar\function WaitToMove
Original credit is kept for the functions I merely slightly changed and/or changed into reflection, which is basicly all of them.
Thoughts/ideas on this?