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

UnrealGame.HoldObjective


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
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
//==============================================================================
// HoldObjective
//==============================================================================
// Created by Laurent Delayen
// © 2003, Epic Games, Inc.  All Rights Reserved
//==============================================================================

class HoldObjective extends ProximityObjective;

var()   name            MoverTag;
var     Array<Mover>    LinkedMover;

struct TouchingPlayer
{
    var Controller  C;
    var float       TouchTime;
};

var array<TouchingPlayer>   TouchingPlayers;        // List of touching players (for score sharing)
var Controller              LastPlayerTouching;

var array<Actor>    Touchers;       // List of touching actors (used for TrueTouch() en TrueUnTouch() events)

var float   TotalHeldTime;
var bool    bIsHeld, bIsTriggerControl;

var()   bool    bLocationFX;
var     Emitter LocationFX;

replication
{
    unreliable if ( (Role==ROLE_Authority) && bReplicateObjective && bNetDirty )
        bIsHeld;
}


simulated function PostBeginPlay()
{
    local Mover myMover;

    super.PostBeginPlay();

    if ( MoverTag == '' )
        warn( Self @ "MoverTag not defined!!!" );
    else
    {
        ForEach AllActors(class'Mover', myMover, MoverTag)
        {
            if ( myMover.InitialState == 'TriggerControl' )
                bIsTriggerControl = true;

            LinkedMover[LinkedMover.Length] = myMover;
            if ( myMover.Event == '' )
                warn( myMover @ "doesn't have it's Event set. It should trigger back the HoldObjective" @ Self );
        }
    }
}

/* TellBotHowToDisable()
tell bot what to do to disable me.
return true if valid/useable instructions were given
*/
function bool TellBotHowToDisable(Bot B)
{
    local Bot NextBot;
    if ( (VSize(B.Pawn.Location - Location) < 1000) && B.LineOfSightTo(self) )
    {
        // if teammate already touching, then don't need to
        for ( NextBot=B.Squad.SquadMembers; NextBot!=None; NextBot=NextBot.NextSquadMember )
            if ( (NextBot != B) && (NextBot.Pawn != None) && NextBot.Pawn.ReachedDestination(self) )
                return false;
    }
    if ( (B.Enemy != None) && (B.Skill > 4*FRand()) && (B.Pawn.Health < 250 * FRand()) && B.Pawn.ReachedDestination(self) )
        B.bShieldSelf = true;
    return Super.TellBotHowToDisable(B);
}


event Touch( Actor Other )
{
    local Pawn  P;

    P = Pawn( Other );
    if ( P != None && IsRelevant(P, true) )
        AddNewTouchingPlayer( P.Controller );
}

event UnTouch( Actor Other )
{
    local Pawn  P;

    P = Pawn( Other );
    if ( P != None && IsRelevant(P, true) )
        RemoveTouchingPlayer( P.Controller );
}

/* ToucherDied() called when Pawn P dies, to untrigger player only triggers */
function PlayerToucherDied( Pawn P )
{
    RemoveTouchingPlayer( P.GetKillerController() );
}


function AddNewTouchingPlayer( Controller C )
{
    local int               i;
    local TouchingPlayer    TP;

    TP.C = C;
    TP.TouchTime = Level.TimeSeconds;
    TouchingPlayers[TouchingPlayers.Length] = TP;

    bIsHeld = true;
    CheckPlayCriticalAlarm();

    for ( i=0; i<LinkedMover.Length; i++ )
        LinkedMover[i].Trigger( Self, C.Pawn );

    if ( C != None )
    {
        for ( i=0;i<4;i++ )
            if ( C.GoalList[i] == self )
            {
                C.GoalList[i] = None;
                break;
            }
    }
}

function RemoveTouchingPlayer( Controller C )
{
    local int   i, j;
    local float HoldTime;

    for ( i=0;i<TouchingPlayers.Length;i++ )
        if ( TouchingPlayers[i].C == C )
        {
            HoldTime = Level.TimeSeconds - TouchingPlayers[i].TouchTime;
            if ( !bIsTriggerControl && HoldTime > 0 )
            {
                AddScorer( C, HoldTime );
                TotalHeldTime += HoldTime;
            }
            LastPlayerTouching = C;
            DelayedDamageInstigatorController = C;
            TouchingPlayers.Remove(i,1);
            if ( TouchingPlayers.Length == 0 )
            {
                bIsHeld = false;
                CheckPlayCriticalAlarm();
            }

            for ( j=0;j<LinkedMover.Length;j++ )
            {
                LinkedMover[j].UnTrigger( Self, C.Pawn );
            }

            break;
        }
}


/* Award Assault score to player(s) who completed the objective */
function AwardAssaultScore( int Score )
{
    local int   i;
    local float HoldTime, BestHeldTime;

    // Add touching time of current touchers
    if ( TouchingPlayers.Length > 0 )
        for (i=0; i<TouchingPlayers.Length; i++)
            if ( TouchingPlayers[i].C != None )
            {
                HoldTime = Level.TimeSeconds - TouchingPlayers[i].TouchTime;
                AddScorer( TouchingPlayers[i].C, HoldTime );
                TotalHeldTime += HoldTime;

                // Force Trophy on player currently holding objective for the longest time
                if ( HoldTime > BestHeldTime )
                {
                    BestHeldTime    = HoldTime;
                    DisabledBy      = TouchingPlayers[i].C.PlayerReplicationInfo;
                }
            }

    // Convert Scorers Pct to real Pct...
    for (i=0; i<Scorers.Length; i++)
        Scorers[i].Pct = Scorers[i].Pct / TotalHeldTime;

    ShareScore( Score, "Objective_Completed" );
}

/* Called by mover once completed */
function Trigger(Actor Other, Pawn Instigator)
{
    local int   i;
    local float BestTime;
    local Pawn  RealInstigator;

    if ( bDisabled )
        return;

    if ( bBotOnlyObjective )
    {
        RealInstigator = None;
    }
    else
    {
        // Set the players triggering the objective for the longest time to be the instigator
        if ( TouchingPlayers.Length > 0 )
        {
            for (i=0; i<TouchingPlayers.Length; i++)
            {
                if ( BestTime == 0 || TouchingPlayers[i].TouchTime < BestTime )
                {
                    if ( TouchingPlayers[i].C.Pawn != None )
                    {
                        BestTime            = TouchingPlayers[i].TouchTime;
                        RealInstigator      = TouchingPlayers[i].C.Pawn;
                        LastPlayerTouching  = TouchingPlayers[i].C;         // in case RealInstigator doesn't exist when sharing scores.
                    }
                    else
                        DelayedDamageInstigatorController = TouchingPlayers[i].C;   // Pawn may be dead...
                }
            }
        }

        if ( RealInstigator == None )
        {
            if ( Instigator != None && Instigator.Controller != None )
            {
                RealInstigator      = Instigator;
                LastPlayerTouching  = Instigator.Controller;
            }
            else if ( LastPlayerTouching != None && LastPlayerTouching.Pawn != None )
            {
                RealInstigator = LastPlayerTouching.Pawn;
            }
            else if ( DelayedDamageInstigatorController != None )
            {
                RealInstigator = DelayedDamageInstigatorController.Pawn;
            }
        }
    }

    DisableObjective( RealInstigator );
}

/* triggered by intro cinematic to auto complete objective */
function CompleteObjective( Pawn Instigator )
{
    local int i;

    for ( i=0;i<LinkedMover.Length;i++ )
        LinkedMover[i].Trigger( Self, Instigator );
}

/* Reset()
reset actor to initial state - used when restarting level without reloading.
*/
function Reset()
{
    LastPlayerTouching      = None;
    Touchers.Length         = 0;
    TouchingPlayers.Length  = 0;
    TotalHeldTime           = 0;
    bIsHeld                 = false;

    super.Reset();
}

/* returns objective's progress status 1->0 (=disabled)
    Assumes mover(s) only have 1 keyframe */
simulated function float GetObjectiveProgress()
{
    local int   i, BestMover;
    local float BestTime;

    if ( !bDisabled && LinkedMover.Length > 0 )
    {
        // If linked to several movers, pick longest MoveTime
        for ( i=0;i<LinkedMover.Length;i++ )
            if ( LinkedMover[i].MoveTime > BestTime )
            {
                BestTime    = LinkedMover[i].MoveTime;
                BestMover   = i;
            }

        if ( LinkedMover[BestMover].KeyNum >= LinkedMover[BestMover].PrevKeyNum )
            return  (1.f - LinkedMover[BestMover].PhysAlpha);   // opening
        else
            return  LinkedMover[BestMover].PhysAlpha;           // closing
    }
    return 0;
}

/* holdobjective critical when in a critical volume or when holding it */
simulated function bool IsCritical()
{
    return (IsActive() && (bIsCritical || bIsHeld));
}

/* Add pulsing overlay on objective's physical representation */
simulated function SetObjectiveOverlay( bool bShow )
{
    super.SetObjectiveOverlay( bShow );

    // Toggle stand location FX
    if ( bLocationFX && Level.NetMode != NM_DedicatedServer )
    {
        if ( LocationFX == None )
            LocationFX = Spawn(class'FX_HoldObjective', Self,, Location - CollisionHeight*0.95*vect(0,0,1) );

        if ( LocationFX != None )
            LocationFX.bHidden = !bShow;
    }
}

simulated function UpdatePrecacheMaterials()
{
    Level.AddPrecacheMaterial(Material'AS_FX_TX.Emitter.HoldArrow');
    super.UpdatePrecacheMaterials();
}

defaultproperties
{
     bLocationFX=True
     ObjectiveName="Hold Objective"
     ObjectiveTypeIcon=FinalBlend'AS_FX_TX.Icons.OBJ_Hold_FB'
     ObjectiveDescription="Touch and Hold Objective to disable it."
     Objective_Info_Attacker="Hold Objective"
     bReceivePlayerToucherDiedNotify=True
}

Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames
Class file time: Mon 23/10/2006 20:38:48.000 - Creation time: Wed 7/2/2007 19:16:41.625 - Created with UnCodeX