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

UT2k4Assault.PlayerSpawnManager


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
//=============================================================================
// PlayerSpawnManager
//
// In Assault Player.PlayerReplicationInfo.Team and PlayerStart.TeamNumber do not match!
// The SpawnManager makes the connection between the team number and the right PlayerStart
// Taking in account things like:
// - which team is attacking or defending
// - multiple (consecutively triggered or not) spawn areas
// - forced pawn class with specific spawn areas
//
// How to use:
// - Add a PlayerSpawnManager for each Spawn area in the level
// - Due to the way UT handles playerstarts, 
//			you must have PlayerStart actors with TeamNumber=0 in the Level
//
// Parameters are self explanatory
//
//=============================================================================

class PlayerSpawnManager extends Info
    placeable;

var()   enum EPSM_AssaultTeam
{
    EPSM_Attackers,
    EPSM_Defenders,
} AssaultTeam;

var()   enum EPSM_ForcePossessPawn
{
    EPSM_None,                              // No Force..
    EPSM_ForcedPawnClass,                   // Forces Pawn class override at spawn
    EPSM_ForceDefaultPawnClass,             // Forces controller to use his default Pawn Class when spawning
} OverridePawnClass;

var()   class<Pawn> ForcedPawnClass;            
var()   int         PlayerStartTeam;            // TeamNumber of the PlayerStart actors the manager is pointing to
var()   bool        bEnabled;                   // Spawn manager active?

// backup
var     bool    BACKUP_bEnabled;
var() bool  bAllowTeleporting;  // Allow players to teleport there when it's enabled.

// Memory/Network/CPU optimizations
// When PlayerSpawnManager is trigger disabled, auto kill vehicles and shutdown vehicle factories
var()   editinline  array<Name> DisabledVehicleFactoriesTag;    // Disable vehicle factories (and kill child)


simulated function PostBeginPlay()
{
    super.PostBeginPlay();

    BACKUP_bEnabled = bEnabled;
}

simulated function UpdatePrecacheMaterials()
{
    super.UpdatePrecacheMaterials();

    if ( (ForcedPawnClass != None) && ( Level.NetMode != NM_DedicatedServer ) )
        ForcedPawnClass.static.StaticPrecache( Level );
}

function SetEnabled( bool bNewStatus )
{
    local ASVehicleFactory  ASVF;
    local int               i;

    if ( bNewStatus == bEnabled )
        return;

    bEnabled = bNewStatus;
    if ( !bEnabled )
    {
        if ( DisabledVehicleFactoriesTag.Length > 0 )
        {
            ForEach DynamicActors(class'ASVehicleFactory', ASVF)
                for (i=0; i<DisabledVehicleFactoriesTag.Length; i++)
                {
                    if ( ASVF.Tag == DisabledVehicleFactoriesTag[i] )
                        ASVF.ShutDown();
                }
        }
    }
    else if ( bAllowTeleporting )
        ASGameInfo(Level.Game).NewSpawnAreaEnabled( AssaultTeam == EPSM_Defenders );
}

function Trigger( actor Other, Pawn EventInstigator )
{
    if ( bEnabled )
        TriggerEvent( Event, Self, EventInstigator); // to enable another PlayerSpawnManager for example

    SetEnabled( !bEnabled );
}


// Check if a PlayerStart is valid
singular function bool ApprovePlayerStart(PlayerStart P, byte Team, Controller Player)
{
    Local name  OverrideTag;

    if ( Player == None || Player.Event == 'None' )
        OverrideTag = '';
    else
        OverrideTag = Player.Event;

    // Is PlayerSpawnManager active?
    if ( !bEnabled && OverrideTag == '' )
        return false;

    // Are we dealing with the right PlayerSpawnManger?
    if ( P.TeamNumber != PlayerStartTeam )
        return false;

    // Is the PlayerStart for the correct Player's Team ?
    if ( Level.Game.IsA('ASGameInfo') )
    {
        if ( AssaultTeam == EPSM_Attackers ) 
        { 
            if ( !ASGameInfo(Level.Game).IsAttackingTeam(Team) ) return false; 
        }
        else if ( ASGameInfo(Level.Game).IsAttackingTeam(Team) ) return false;
    }   

    // Forced PlayerSpawnManager?
    if ( OverrideTag != '' && OverrideTag != Tag )
        return false;

    return true;
}

// Player spawned
function String PawnClassOverride(Controller C, NavigationPoint NP, byte Team)
{
    if ( OverridePawnClass == EPSM_None )
        return "";

    if ( C==None || NP==None || !NP.IsA('PlayerStart') )
        return "";

    if ( !ApprovePlayerStart(PlayerStart(NP), Team, C) )
        return "";

    // Pawn class override
    if ( OverridePawnClass == EPSM_ForcedPawnClass && ForcedPawnClass != None )
        return String(ForcedPawnClass);

    if ( OverridePawnClass == EPSM_ForceDefaultPawnClass ) /*obsolete*/
        return "";

    return "";
}


/* Reset() 
reset actor to initial state - used when restarting level without reloading.
*/
function Reset()
{
    super.Reset();
    bEnabled = BACKUP_bEnabled;
}


//=============================================================================
// defaultproperties
//=============================================================================

defaultproperties
{
     OverridePawnClass=EPSM_ForceDefaultPawnClass
     bEnabled=Wahr
     bAllowTeleporting=Wahr
     bNoDelete=Wahr
}

Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames
Class file time: Fr 30.3.2007 08:43:52.000 - Creation time: Mo 16.4.2007 11:20:52.453 - Created with UnCodeX