UMSPawn
Class MovieHeadAnimate

source: e:\games\UnrealTournament\UMSPawn\Classes\MovieHeadAnimate.uc
Core.Object
   |
   +--Engine.Actor
      |
      +--UMS1_6.UMS
         |
         +--UMSPawn.MovieHeadAnimate
Direct Known Subclasses:None

class MovieHeadAnimate
extends UMS1_6.UMS

//============================================================================= // MovieHeadAnimate. // by Hugh Macdonald //=============================================================================
Variables
 int CurrentCommand
 name HeadAnimation[50]
 rotator HeadRotation[50]
 float HeadScriptVals[50]
 string HeadScript[50]
 Texture HeadSkins[80]
 Pawn MyPawn
 string PawnName
 float WaitTime
 float WaitTimes[50]
 bool bRolling

States
Rolling, Waiting

Function Summary
 string CutOutWord(string Word, string Message)
     
//Takes "word" out of "message" and returns the new string.
 void ExecuteAnimate(string Command)
     
//*******************************************************************
//Head changing stuff
//*******************************************************************
 void ExecuteNextCommand()
     
//Grab the next command from the HeadScript and execute it.
 void ExecuteRotate(string Command)
 void ExecuteSkinChange(string Command)
 void ExecuteTrack(string Command)
 Actor FindActor(string ActorName)
     
//*******************************************************************
//Finding stuff
//*******************************************************************
 Pawn FindPawn(string PawnName)
 string GetFirstWord(String Message)
     
//This returns the first word (everything before the first space) of 
//the string it is given.
 void GoBackToMyTrailer()


State Rolling Function Summary


State Waiting Function Summary



Source Code


00001	//=============================================================================
00002	// MovieHeadAnimate.
00003	// by Hugh Macdonald
00004	//=============================================================================
00005	class MovieHeadAnimate expands UMS;
00006	
00007	//This is the pawn who's head is being animated
00008	var() string PawnName;
00009	var pawn MyPawn;
00010	var() string HeadScript[50];
00011	var() name HeadAnimation[50];
00012	var() rotator HeadRotation[50];
00013	var() float HeadScriptVals[50];
00014	var() float WaitTimes[50];
00015	var() texture HeadSkins[80];
00016	var bool bRolling;
00017	var int CurrentCommand;
00018	var float WaitTime;
00019	
00020	//MovieLipSynch will start using the HeadScript if triggered.
00021	event Trigger( Actor other, Pawn instigator )
00022	{
00023	    MyPawn = FindPawn(PawnName);
00024	    bRolling = true;
00025	}
00026	
00027	//Grab the next command from the HeadScript and execute it.
00028	function ExecuteNextCommand()
00029	{
00030	    local string Command, Word;
00031	
00032	    Command=HeadScript[CurrentCommand];
00033	
00034	    Word=GetFirstWord(Command);
00035	    Command = CutOutWord(Word, Command);
00036	
00037	    switch(Word)
00038	    {
00039	        case "Anim":
00040	            ExecuteAnimate(Command);
00041	            break;
00042	        case "Rotate":
00043	            ExecuteRotate(Command);
00044	            break;
00045	        case "Track":
00046	            ExecuteTrack(Command);
00047	            break;
00048	        case "Skin":
00049	            ExecuteSkinChange(Command);
00050	            break;
00051	     }
00052	
00053	    //Now wait the appropriate amount of time before doing the next
00054	    //command.
00055	    if (CurrentCommand != 0)
00056	    {
00057	        WaitTime = WaitTimes[CurrentCommand];
00058	        GotoState('Waiting');
00059	    }
00060	
00061	    CurrentCommand++;
00062	
00063	    
00064	}
00065	
00066	function GoBackToMyTrailer()
00067	{
00068	    Destroy();
00069	}
00070	
00071	//State used to wait.
00072	auto state Waiting
00073	{
00074	Begin:
00075	StartWaiting:
00076	    Sleep(WaitTime);
00077	    GotoState('Rolling');
00078	}
00079	
00080	//State used to execute commands.
00081	state Rolling
00082	{
00083	Begin:
00084	    if(!bRolling)
00085	        GotoState('Waiting');
00086	ExecuteCommand:
00087	    if(bRolling)
00088	        ExecuteNextCommand();
00089	CheckForWait:
00090	    Goto'Begin';
00091	}
00092	
00093	
00094	
00095	//*******************************************************************
00096	//Head changing stuff
00097	//*******************************************************************
00098	
00099	function ExecuteAnimate(string Command)
00100	{
00101	    local float Time;
00102	    local name Animation;
00103	
00104	    Time = HeadScriptVals[CurrentCommand];
00105	    Animation = HeadAnimation[CurrentCommand];
00106	
00107	    MovieHead(MyPawn.Weapon).DoAnimate(Animation, Time);
00108	}
00109	
00110	
00111	function ExecuteRotate(string Command)
00112	{
00113	    local string Word;
00114	    local actor RotateTarget;
00115	    local vector TargetVector;
00116	    local rotator TargetRotation;
00117	    local float Time;
00118	    
00119	    Word = GetFirstWord(Command);
00120	    Command = CutOutWord(Word, Command);
00121	
00122	    //to something, or not to something, that is the question
00123	    if(Word ~= "to")
00124	    {
00125	        //If no name after to, use the value in ScriptVectors
00126	        if(Command == "")
00127	            RotateTarget = NONE;
00128	        else
00129	            RotateTarget = FindActor(Command);
00130	        
00131	        if(RotateTarget != NONE)
00132	            TargetVector = RotateTarget.Location;
00133	
00134	        TargetRotation = rotator(TargetVector - MyPawn.Weapon.Location);
00135	    }    
00136	    else
00137	        TargetRotation = MyPawn.Weapon.Rotation + HeadRotation[CurrentCommand];
00138	        
00139	    Time = HeadScriptVals[CurrentCommand];
00140	
00141	    TargetRotation-=MyPawn.Rotation;
00142	    
00143	    MovieHead(MyPawn.Weapon).DoRotate(TargetRotation, RotateTarget, Time);
00144	}
00145	
00146	function ExecuteSkinChange(string Command)
00147	{
00148	    local int ElementNum, DesiredSkin;
00149	
00150	    DesiredSkin = int(Command);
00151	    ElementNum = HeadScriptVals[CurrentCommand];
00152	
00153	    if(ElementNum >= 0 && ElementNum <= 7)
00154	        MovieHead(MyPawn.Weapon).MultiSkins[ElementNum] = HeadSkins[DesiredSkin];
00155	    else
00156	        MovieHead(MyPawn.Weapon).Skin = HeadSkins[DesiredSkin];
00157	
00158	}
00159	
00160	function ExecuteTrack(string Command)
00161	{
00162	    local actor TargetActor;
00163	    local rotator TrackDirections;
00164	    
00165	    TargetActor = FindActor(Command);
00166	    TrackDirections = HeadRotation[CurrentCommand];
00167	    MovieHead(MyPawn.Weapon).DoTrack(TargetActor, TrackDirections);
00168	}
00169	
00170	
00171	//*******************************************************************
00172	//Finding stuff
00173	//*******************************************************************
00174	
00175	function Actor FindActor(string ActorName)
00176	{
00177	    local Actor A;
00178	
00179	    foreach AllActors(class 'Actor', A)
00180	        if (ActorName ~= string(A.Tag) || ActorName ~= string(A.Name))
00181	               return A;
00182	    //If there is no matching actor, return none.
00183	    return NONE;
00184	}
00185	
00186	
00187	function Pawn FindPawn(string PawnName)
00188	{
00189	    local Pawn P;
00190	
00191	    foreach AllActors(class'Pawn', P)
00192	        if (PawnName ~= string(P.Tag) || PawnName ~= string(P.Name))
00193	               return P;
00194	    //If there is no matching pawn, return none.
00195	    return NONE;
00196	}
00197	
00198	
00199	//*******************************************************************
00200	//String Stuff
00201	//*******************************************************************
00202	
00203	//This returns the first word (everything before the first space) of 
00204	//the string it is given.
00205	function string GetFirstWord(String Message)
00206	{
00207	    local int lcv, MessLength;
00208	    local String Parser, FirstWord;
00209	    
00210	    MessLength = Len(Message);
00211	    
00212	    for(lcv = 0; lcv < MessLength; lcv++)
00213	    {
00214	        Parser = Mid(Message, lcv, 1);
00215	        
00216	        if(Parser == " ")
00217	            break;
00218	    }
00219	    
00220	    FirstWord = Mid(Message, 0, lcv);
00221	    
00222	    return FirstWord;
00223	}
00224	
00225	//Takes "word" out of "message" and returns the new string.
00226	function string CutOutWord(string Word, string Message)
00227	{
00228	    local int Pos, WordLength, MessageLength;
00229	    local String NewMessage;
00230	    
00231	    WordLength = Len(Word);
00232	    MessageLength = Len(Message);
00233	    Pos = InStr(Message, Word);
00234	    
00235	    //if Word is not in Message, then return a blank string
00236	    if(Pos < 0)
00237	        return "";
00238	    
00239	    //If we are at the end of the message, just get what is before
00240	    //the word, but not the space before it.  If not, get what is
00241	    //before and after, and get rid of the space after the word.
00242	    if((Pos + WordLength) >= MessageLength)
00243	        NewMessage = Mid(Message,0,Pos);
00244	    else
00245	        NewMessage = Mid(Message,0,Pos) $ Mid(Message, (Pos + WordLength + 1));
00246	
00247	    return NewMessage;
00248	}
00249	
00250	defaultproperties
00251	{
00252	}

End Source Code