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

UT2004RPG.RPGArtifactManager


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
//The artifact manager spawns artifacts at random PathNodes.
//It tries to make sure there's at least one artifact of every type available
class RPGArtifactManager extends Info
    config(UT2004RPG);

var config int ArtifactDelay; //spawn an artifact every this many seconds - zero disables
var config int MaxArtifacts;
var config int MaxHeldArtifacts; //maximum number of artifacts a player can hold
var config array<class<RPGArtifact> > Artifacts; // FIXME: obsolete, for backwards compatibility
struct ArtifactChance
{
    var class<RPGArtifact> ArtifactClass;
    var int Chance;
};
var config array<ArtifactChance> AvailableArtifacts;
var int TotalArtifactChance; // precalculated total Chance of all artifacts
var array<RPGArtifact> CurrentArtifacts;
var array<PathNode> PathNodes;

var localized string PropsDisplayText[3];
var localized string PropsDescText[3];

function PostBeginPlay()
{
    local NavigationPoint N;
    local int x;

    Super.PostBeginPlay();

    for (x = 0; x < AvailableArtifacts.length; x++)
        if (AvailableArtifacts[x].ArtifactClass == None || !AvailableArtifacts[x].ArtifactClass.static.ArtifactIsAllowed(Level.Game))
        {
            AvailableArtifacts.Remove(x, 1);
            x--;
        }

    if (ArtifactDelay > 0 && MaxArtifacts > 0 && AvailableArtifacts.length > 0)
    {
        for (N = Level.NavigationPointList; N != None; N = N.NextNavigationPoint)
            if (PathNode(N) != None && !N.IsA('FlyingPathNode'))
                PathNodes[PathNodes.length] = PathNode(N);

        for (x = 0; x < AvailableArtifacts.length; x++)
        {
            TotalArtifactChance += AvailableArtifacts[x].Chance;
        }
    }
    else
        Destroy();
}

function MatchStarting()
{
    SetTimer(ArtifactDelay, true);
}

// select a random artifact based on the Chance entries in the artifact list and return its index
function int GetRandomArtifactIndex()
{
    local int i;
    local int Chance;

    Chance = Rand(TotalArtifactChance);
    for (i = 0; i < AvailableArtifacts.Length; i++)
    {
        Chance -= AvailableArtifacts[i].Chance;
        if (Chance < 0)
        {
            return i;
        }
    }
}

function Timer()
{
    local int Chance, Count, x;
    local bool bTryAgain;

    for (x = 0; x < CurrentArtifacts.length; x++)
        if (CurrentArtifacts[x] == None)
        {
            CurrentArtifacts.Remove(x, 1);
            x--;
        }

    if (CurrentArtifacts.length >= MaxArtifacts)
        return;

    if (CurrentArtifacts.length >= AvailableArtifacts.length)
    {
        //there's one of everything already
        Chance = GetRandomArtifactIndex();
        SpawnArtifact(Chance);
        return;
    }

    while (Count < 250)
    {
        // FIXME: make this not slow (just advance through list until we find one that isn't in use)
        Chance = GetRandomArtifactIndex();
        for (x = 0; x < CurrentArtifacts.length; x++)
            if (CurrentArtifacts[x].Class == AvailableArtifacts[Chance].ArtifactClass)
            {
                bTryAgain = true;
                x = CurrentArtifacts.length;
            }
        if (!bTryAgain)
        {
            SpawnArtifact(Chance);
            return;
        }
        bTryAgain = false;
        Count++;
    }
}

function SpawnArtifact(int Index)
{
    local Pickup APickup;
    local Controller C;
    local RPGArtifact Inv;
    local int NumMonsters, PickedMonster, CurrentMonster;

    if (Level.Game.IsA('Invasion'))
    {
        NumMonsters = int(Level.Game.GetPropertyText("NumMonsters"));
        if (NumMonsters <= CurrentArtifacts.length)
            return;
        do
        {
            PickedMonster = Rand(NumMonsters);
            for (C = Level.ControllerList; C != None; C = C.NextController)
                if (C.Pawn != None && C.Pawn.IsA('Monster') && !C.IsA('FriendlyMonsterController'))
                {
                    if (CurrentMonster >= PickedMonster)
                    {
                        //Assumes monster doesn't get inventory from anywhere else!
                        if (RPGArtifact(C.Pawn.Inventory) == None)
                        {
                            Inv = spawn(AvailableArtifacts[Index].ArtifactClass);
                            Inv.GiveTo(C.Pawn);
                            break;
                        }
                    }
                    else
                        CurrentMonster++;
                }
        } until (Inv != None)

        if (Inv != None)
            CurrentArtifacts[CurrentArtifacts.length] = Inv;
    }
    else
    {
        APickup = spawn(AvailableArtifacts[Index].ArtifactClass.default.PickupClass,,, PathNodes[Rand(PathNodes.length)].Location);
        if (APickup == None)
            return;
        APickup.RespawnEffect();
        APickup.RespawnTime = 0.0;
        APickup.AddToNavigation();
        APickup.bDropped = true;
        APickup.Inventory = spawn(AvailableArtifacts[Index].ArtifactClass);
        CurrentArtifacts[CurrentArtifacts.length] = RPGArtifact(APickup.Inventory);
    }
}

static function FillPlayInfo(PlayInfo PlayInfo)
{
    local int i;

    Super.FillPlayInfo(PlayInfo);

    PlayInfo.AddSetting("UT2004RPG", "MaxArtifacts", default.PropsDisplayText[i++], 3, 10, "Text", "2;0:25");
    PlayInfo.AddSetting("UT2004RPG", "ArtifactDelay", default.PropsDisplayText[i++], 30, 10, "Text", "3;1:100");
    PlayInfo.AddSetting("UT2004RPG", "MaxHeldArtifacts", default.PropsDisplayText[i++], 0, 10, "Text", "2;0:99");
}

static function string GetDescriptionText(string PropName)
{
    switch (PropName)
    {
        case "MaxArtifacts":    return default.PropsDescText[0];
        case "ArtifactDelay":   return default.PropsDescText[1];
        case "MaxHeldArtifacts":return default.PropsDescText[2];
    }
}

// update artifact list to latest version
static final function UpdateArtifactList()
{
    local int i;

    if (default.Artifacts.length > 0 && default.AvailableArtifacts.length == 6)
    {
        default.AvailableArtifacts.length = default.Artifacts.length;
        for (i = 0; i < default.Artifacts.length; i++)
        {
            default.AvailableArtifacts[i].ArtifactClass = default.Artifacts[i];
            default.AvailableArtifacts[i].Chance = 1;
        }
        default.Artifacts.length = 0;
        StaticSaveConfig();
    }
}

defaultproperties
{
     ArtifactDelay=30
     MaxArtifacts=6
     AvailableArtifacts(0)=(ArtifactClass=Class'UT2004RPG.ArtifactInvulnerability',Chance=1)
     AvailableArtifacts(1)=(ArtifactClass=Class'UT2004RPG.ArtifactFlight',Chance=1)
     AvailableArtifacts(2)=(ArtifactClass=Class'UT2004RPG.ArtifactTripleDamage',Chance=1)
     AvailableArtifacts(3)=(ArtifactClass=Class'UT2004RPG.ArtifactLightningRod',Chance=1)
     AvailableArtifacts(4)=(ArtifactClass=Class'UT2004RPG.ArtifactTeleport',Chance=1)
     AvailableArtifacts(5)=(ArtifactClass=Class'UT2004RPG.ArtifactMonsterSummon',Chance=1)
     PropsDisplayText(0)="Max Artifacts"
     PropsDisplayText(1)="Artifact Spawn Delay"
     PropsDisplayText(2)="Max Artifacts a Player Can Hold"
     PropsDescText(0)="Maximum number of artifacts in the level at once."
     PropsDescText(1)="Spawn an artifact every this many seconds."
     PropsDescText(2)="The maximum number of artifacts a player can carry at once (0 for infinity)"
     bBlockZeroExtentTraces=False
     bBlockNonZeroExtentTraces=False
}

Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames
Class file time: Sat 15/7/2006 17:15:14.000 - Creation time: Wed 7/2/2007 19:16:50.140 - Created with UnCodeX