예제 #1
0
        protected void BuildRandomFlags(FlagManager manager, ServerConfig.FlagInfo flagInfo)
        {
            if (!flagInfo.SpawnRandomFlags)
            {
                return;
            }

            SpawnableFlags.Clear();

            if (flagInfo.RandomFlags.UseGoodFlags)
            {
                SpawnableFlags.AddRange(FlagTypeList.GoodFlags);
            }

            if (flagInfo.RandomFlags.UseBadFlags)
            {
                SpawnableFlags.AddRange(FlagTypeList.BadFlags);
                if (flagInfo.AllowGeno)
                {
                    SpawnableFlags.Add(FlagTypeList.Genocide);
                }
            }

            foreach (var f in flagInfo.RandomFlags.UseFlags)
            {
                FlagType t = FlagTypeList.GetFromAbriv(f);
                if (t != null && !SpawnableFlags.Contains(t))
                {
                    SpawnableFlags.Add(t);
                }
            }

            foreach (var f in flagInfo.RandomFlags.IgnoreFlags)
            {
                FlagType t = FlagTypeList.GetFromAbriv(f);
                if (t != null && SpawnableFlags.Contains(t))
                {
                    SpawnableFlags.Remove(t);
                }
            }

            DesiredFlagCount = 0;
            if (SpawnableFlags.Count == 0)
            {
                return;
            }

            // randomize the flag list
            int             count      = SpawnableFlags.Count;
            List <FlagType> randoFlags = new List <FlagType>();

            for (int i = 0; i < count; i++)
            {
                FlagType t = SpawnableFlags[State.World.RNG.Next(SpawnableFlags.Count)];
                SpawnableFlags.Remove(t);
                randoFlags.Add(t);
            }
            SpawnableFlags = randoFlags;


            // see how many random flags we need to spawn this time
            DesiredFlagCount = GetRandomFlagCount();

            if (DesiredFlagCount > 0)
            {
                Logger.Log2("Spawning " + DesiredFlagCount.ToString() + " flags from pool " + String.Join <FlagType>(" ", SpawnableFlags.ToArray()));
            }

            for (int i = 0; i < DesiredFlagCount; i++)
            {
                FlagType ft = null;
                if (DesiredFlagCount < SpawnableFlags.Count)
                {
                    ft = SpawnableFlags[i];    // no dupes
                }
                else
                {
                    ft = GetRandomFlag();
                }

                if (FlagValidForGameType(ft))
                {
                    manager.InitFlag(ft);
                }
            }
        }