Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames

FrightScript.ContainerCrane


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
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
/*
	--------------------------------------------------------------
	Container Crane
	--------------------------------------------------------------

    An Animated Container Crane mesh whos animation is controlled by the
    the progress state of an Objective condition.

    Animation is played only on the client.

    Author :  Alex Quick

	--------------------------------------------------------------
*/

class ContainerCrane extends Actor
placeable;

// Tag of the condition which control's this Crane's animation.
var () const name AssociatedConditionTag;
// Object reference to the condition which controls this Crane's animation
var private KF_ObjectiveCondition AssociatedCondition;
// Name of the animation the Crane plays when its lowering / raising its winch.
var () const name WinchLoweringAnim;
// The Current frame the animation is playing (used for interpolation)
var float CurrentAnimFramePct;
// The last position in the animation expressed as a percent.
var float LastAnimFramePct;
// True if the animation is not playing in reverse.
var bool bPlayingForward;


// Struct representing a sound effect we should play at some time during the animation.

struct SAnimSoundEffect
{
    // reference to the actual sound in the package.
    var () sound  SoundToPlay;
    // The frame %age to start playing the sound at.  (i.e  In a 600 frame animation if you want to play at frame 300, this value should be 0.5 )
    var () float  StartFramePct;
    // the frame %age to stop playing the sound at.
    var () float  EndFramePct;
    // Is this a looping sound or not.  If not,  'EndFramePct' has no actual relevance.
    var () bool   bLooping;
    // Has this sound been played already?  Only has real relevance to non-looping sounds.
    var    bool   bPlayed;
};

var () array<SAnimSoundEffect>  AnimSounds;

var float ConditionCompletionPct;

replication
{
    unreliable if(Role == Role_Authority && bNetDirty)
        ConditionCompletionPct;
}


function PostbeginPlay()
{
    local KF_ObjectiveCondition Condition;

    foreach AllObjects(class 'KF_ObjectiveCondition', Condition)
    {
        if(Condition.Tag == AssociatedConditionTag)
        {
            AssociatedCondition = Condition;
            NetupdateFrequency = 1.f / Condition.ConditionRepInterval;   // Sync net update rates.
            break;
        }
    }
}

simulated function Tick(float DeltaTime)
{
    local bool bOldDirection;
    local int i;

    if(Role == Role_Authority && AssociatedCondition != none && AssociatedCondition.bActive)
    {
        ConditionCompletionPct = AssociatedCondition.GetCompletionPct();
    }

    LastAnimFramePct = CurrentAnimFramePct;
    CurrentAnimFramePct = Lerp(DeltaTime,CurrentAnimFramePct,ConditionCompletionPct);

    bOldDirection = bPlayingForward;
    bPlayingForward = CurrentAnimFramePct >= LastAnimFramePct;

    // Animation is reversing , reset sounds.
    if(Role == Role_Authority && bOldDirection != bPlayingForward)
    {
        for(i = 0 ; i < AnimSounds.length ; i ++)
        {
            AnimSounds[i].bPlayed = false;
        }
    }

    if(Level.NetMode != NM_DedicatedServer &&
    ConditionCompletionPct != CurrentAnimFramePct &&
    ConditionCompletionPct < 1.f)
    {
        SetAnimFramePct(CurrentAnimFramePct);
    }

    if(CurrentAnimFramePct > 0.f)
    {
        PlayAnimSounds(CurrentAnimFramePct);
    }
}

function PlayAnimSounds(float CurrentPct)
{
    local int i;
    local Sound AmbSoundToPlay;
    local bool bShouldPlaySound;
    local bool bReversing;

    if(Role < Role_Authority)
    {
        return;
    }

    for(i = 0 ; i < AnimSounds.length ; i ++)
    {
        if(AnimSounds[i].SoundToPlay != none)
        {
            bReversing = !bPlayingForward;

            // Play Looped sounds.  There can only be one of these at a time.
            if(AnimSounds[i].bLooping)
            {
                bShouldPlaySound = CurrentPct >= AnimSounds[i].StartFramePct && (AnimSounds[i].EndFramePct == 0.f || CurrentPct <= AnimSounds[i].EndFramePct) ;
                if(bShouldPlaySound)
                {
                    AnimSounds[i].bPlayed = true;
                    AmbSoundToPlay = AnimSounds[i].SoundToPlay;
                }
            }
            else  // Play one-off sounds.  These can overlap.
            {
                bShouldPlaySound = !AnimSounds[i].bPlayed && CurrentPct >= AnimSounds[i].StartFramePct ;
                if(bShouldPlaySound)
                {
                    AnimSounds[i].bPlayed = true;
                    PlaySound(AnimSounds[i].SoundToPlay,SLOT_None,((SoundVolume/255) * 2.0),true,SoundRadius,,!bFullVolume);
                }
            }
        }
    }

    if(AmbSoundToPlay != AmbientSound)
    {
        AmbientSound = AmbSoundToPlay;
    }
}


simulated function SetAnimFramePct( float NewPct)
{
	PlayAnim( WinchLoweringAnim, 1.0f,0.f);
    SetAnimFrame(NewPct,0);
}

defaultproperties
{
     WinchLoweringAnim="LowerCrane"
     DrawType=DT_Mesh
     bNoDelete=True
     bAlwaysRelevant=True
     RemoteRole=ROLE_SimulatedProxy
     Mesh=SkeletalMesh'FrightYard_SKM.SKM_DockCrane'
     bFullVolume=True
     SoundVolume=255
     SoundRadius=2000.000000
}

Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames
Class file time: Fri 13-10-2023 03:17:26.000 - Creation time: Fri 13-10-2023 03:19:00.819 - Created with UnCodeX