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

UTV2004s.utvMutator


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
//-----------------------------------------------------------
//
//-----------------------------------------------------------
class utvMutator extends Mutator;

var string origcontroller;
var class<PlayerController> origcclass;

var array<int> utvId;

//C is the owner
function CreateInitialUtvReplication(Controller c)
{
    local utvReplicationInfo uri;
    local Controller p;

    foreach dynamicactors(class'Controller', p) {
        if (p != c) {
            //Log("Initially spawning utvReplicationInfo for player " $ p.PlayerReplicationInfo.PlayerName $ " owner " $ c.PlayerReplicationInfo.PlayerName);
            uri = Spawn(class'utvReplicationInfo', c);
            uri.OwnerCtrl = p;
        }
    }
}

//C is the possible new player
function CreateUtvReplication(Controller c)
{
    local utvReplicationInfo uri;
    local PlayerController pc;
    local bool found;

    foreach dynamicactors(class'PlayerController', pc) {
        //Only spawn these for controllers that are utv in seeall mode
        if (!pc.bAllActorsRelevant)
            continue;

        found = false;
        foreach dynamicactors(class'utvReplicationInfo', uri) {
            if ((uri.OwnerPlayer == c.PlayerReplicationInfo) && (uri.Owner == pc)) {
                found = true;
                break;
            }
        }
        if (!found) {
            //Log("Spawning utvReplicationInfo for player " $ c.PlayerReplicationInfo.PlayerName $ " owner " $ pc.PlayerReplicationInfo.PlayerName);
            uri = Spawn(class'utvReplicationInfo', pc);
            uri.OwnerCtrl = c;
        }
    }
}

function Tick(float deltaTime)
{
    local PlayerController pc;
    local int i;

    super.Tick(deltaTime);

    if (utvId.Length > 0) {
        foreach dynamicactors(class'PlayerController', pc) {
            for (i = 0; i < utvId.Length; ++i) {
                if (pc.PlayerReplicationInfo.PlayerID == utvId[i]) {
                    CreateInitialUtvReplication(pc);
                    Log(FriendlyName $ ": Found new UTV player: " $ pc.PlayerReplicationInfo.PlayerName);
                    utvId.Remove(i, 1);
                    i--;
                }
            }
        }
    }
}

//Returns a suitable UTV-spectator class. Knows about UTComp and TTM
function string GetNewController()
{
    local string cur;
    local string newc;
    cur = Level.Game.PlayerControllerClassName;

    //Utcomp?
    if (InStr(cur, "BS_") > 0) {
        newc = Repl(cur, "BS_", "UTV_BS_", false);
        Log(FriendlyName $ ": UTComp detected, using class " $ newc);
    }
    else if (InStr(cur, "TTM_PlayerController") > 0) {
        newc = Repl(cur, "TTM_PlayerController", "TTM_UTV_Spectator", false);
        Log(FriendlyName $ ": TTM detected, using class " $ newc);
    }
    else {
        newc = FriendlyName $ ".utvSpectator";
        Log(FriendlyName $ ": Using class " $ newc);
    }

    return newc;
}

function ModifyLogin(out string Portal, out string Options)
{
    local bool bSeeAll;
    local bool bSpectator;

    super.ModifyLogin (Portal, Options);

    if (Level.game == none) {
        Log (FriendlyName $ ": Level.game is none?");
        return;
    }

    //If we replaced the controller last time round, make sure to restore it
    if (origcontroller != "") {
        Level.Game.PlayerControllerClassName = origcontroller;
        Level.Game.PlayerControllerClass = origcclass;
        origcontroller = "";
    }

    bSpectator = ( Level.Game.ParseOption( Options, "SpectatorOnly" ) ~= "1" );
    bSeeAll = ( Level.Game.ParseOption( Options, "UTVSeeAll" ) ~= "1" );

    if (bSeeAll && bSpectator) {
       Log(FriendlyName $ ": Player with id " $ Level.Game.CurrentID $ " is requesting SeeAll");

       utvId[utvId.Length] = Level.Game.CurrentID;

       origcontroller = Level.Game.PlayerControllerClassName;
       origcclass = Level.Game.PlayerControllerClass;
       Level.Game.PlayerControllerClassName = GetNewController();
       Level.Game.PlayerControllerClass = none;
    }
}

function ModifyPlayer(Pawn Other)
{
    super.ModifyPlayer(Other);

    CreateUtvReplication(Other.Controller);
}

function NotifyLogout(Controller Exiting)
{
    local utvReplicationInfo uri;
    local PlayerController pc;

    super.NotifyLogout(Exiting);

    //Log if seeall players leave
    pc = PlayerController(Exiting);
    if ((pc != none) && (pc.bAllActorsRelevant)) {
        Log(FriendlyName $ ": SeeAll enabled player " $ Exiting.PlayerReplicationInfo.PlayerName $ " (" $ Exiting.PlayerReplicationInfo.PlayerID $ ") leaving");
    }

    //Remove all utvReplicationInfos associated with the leaving player
    foreach dynamicactors(class'utvReplicationInfo', uri) {
        if ((uri.OwnerCtrl == Exiting) || (uri.Owner == Exiting)) {
            //Log("Removing utvReplication for pawn " $ Exiting $ " player " $ uri.Owner);
            uri.Destroy();
        }
    }
}

defaultproperties
{
     bAddToServerPackages=Wahr
     FriendlyName="UTV2004S"
     Description="Required to support UTV2004 SeeAll mode"
     bAlwaysTick=Wahr
}

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