# SpatialFear.SFSeqCounter

00001 00002 00003 00004 00005 00006 00007 00008 00009 00010 00011 00012 00013 00014 00015 00016 00017 00018 00019 00020 00021 00022 00023 00024 00025 00026 00027 00028 00029 00030 00031 00032 00033 00034 00035 00036 00037 00038 00039 00040 00041 00042 00043 00044 00045 00046 00047 00048 00049 00050 00051 00052 00053 00054 00055 00056 00057 00058 00059 00060 00061 00062 00063 00064 00065 00066 00067 00068 00069 00070 00071 00072 00073 00074 00075 00076 00077 00078 00079 00080 00081 00082 00083 00084 00085 00086 00087 00088 00089 00090 00091 00092 00093 00094 00095 00096 00097 00098 00099 00100 00101 00102 00103 00104 00105 00106 00107 00108 00109 |
    //=============================================================================
    // Spatial Fear
    // SFSeqCounter: waits until it has been triggered 'NumToCount' times, and then
    // it sends Trigger/UnTrigger events to actors whose names match 'EventName'.
    // Uses the SFSeqTrigger class to check for right trigger order (sequence)
    // Author: Markus Nuebel
    //=============================================================================

    class SFSeqCounter extends SFCounter;

    var (Counter) localized  string ResetMessage;    // Message displayed when the sequence is triggered in a wrong order
    var (Counter) bool				ResetOnSucces;	 // Enables/Disables counter reset on successful completion of the sequence. Default: false.
    var (Counter) float 			fFreezeTimeAfterReset; // Time delay, to freeze the counter after success. Without freeze time the counter immediately starts counting again when still on the last trigger, default: 3.0 secs
    var (Events) name SuccessEvent; // Event to broadcast in case of a successfull completion. 	Goes out to all actors, with matching tag, not only SFTriggers.
    var (Events) name FailureEvent; // event to broadcast in case of a failed sequence completion. 	Goes out to all actors, with matching tag, not only SFTriggers.

    var int		nNextSequence; // Private. Next expected counter to fire.
    var bool	bFreeze; // Private. Freeze state

    // Fires a normal event
    function FireEvent(name nameEvent, actor Other)
    {
    	local actor A;

    	// Broadcast the Trigger message to all matching actors.
    	if( nameEvent != '' )
    		foreach AllActors( class 'Actor', A, nameEvent )
    		{
    			//class'SFUtils'.Static.sfLogEx(10,"Sending event " $ nameEvent $ " to " $A.name);
    			A.Trigger( Other, Other.Instigator );
    		}
    }

    // Called by a SFTrigger, that fires
    function TriggerCounter(int Sequence, actor Other, pawn EventInstigator )
    {
    	//class'SFUtils'.Static.sfLogEx(10,"Received event from SFTrigger: " $ string(Sequence) $ " Other: " $ Other.name);

    	// Check for freeze state
    	if(bFreeze)
    		return;

    	// First check, if out of sequense
    	if(Sequence > nNextSequence)
    	{
    		//class'SFUtils'.Static.sfLogEx(10,"OutOfOrder");
    		// Reset this counter and all Triggers
    		ResetAll(EventInstigator, false);
    		// Notify other actors
    		FireEvent(FailureEvent, Other);
    		return;
    	}

    	// Check for correct order
    	if(Sequence == nNextSequence)
    	{
    		//class'SFUtils'.Static.sfLogEx(10,"InOrder");
    		// Increment counter
    		nNextSequence++;
    		// Advise base class to count
    		Super.Trigger(Other, EventInstigator);
    		// Eventually reset all to defaults
    		if((NumToCount == 0) && ResetOnSucces)
    		{
    			// Reset state
    			ResetAll(EventInstigator, true);
    			// Notify other actors
    			FireEvent(SuccessEvent, Other);
    		}
    	}
    }

    // Resets the freeze state
    event timer()
    {
    	//class'SFUtils'.Static.sfLogEx(10,"Resetting freeze state");
    	bFreeze = false;
    }

    // Resets this counter and all triggers
    function ResetAll(pawn EventInstigator, bool bSuccess)
    {
    	local SFSeqTrigger A;
    	//class'SFUtils'.Static.sfLogEx(10,"Reset Sequence Counter");

    	// Display reset message
    	if( !bSuccess && bShowMessage && ResetMessage != "" )
    		EventInstigator.ClientMessage( ResetMessage  );
    	// Reset the base counter
    	Reset();
    	// Reset counter
    	nNextSequence=0;

    	// Check for success
    	if(bSuccess)
    	{
    		//Freeze counter to prevent new events during reset time
    		bFreeze=true;
    		SetTimer(fFreezeTimeAfterReset, false);
    		//class'SFUtils'.Static.sfLogEx(10,"Freezed counter");
    	}
    }

    defaultproperties
    {
         ResetMessage="Wrong order, try again!"
         fFreezeTimeAfterReset=3.000000
    }

class file time: 12/7/2003 3:58:24 PM - creation time: 12/7/2003 4:03:45 PM
Created with UnCodeX