Exemplo n.º 1
0
 public override void AddAll(ProbabilityPool <T> rhs)
 {
     foreach (ProbabilityItem <T> p in rhs)
     {
         Add(p.Item, p.Multiplier, p.Unique);
     }
 }
Exemplo n.º 2
0
    public void Test <T>(ProbabilityPool <T> pool, int max, bool print)
    {
        System.Random random = new System.Random();
        pool.Freshen();
        Dictionary <T, int> dict = new Dictionary <T, int>();

        for (int i = 0; i < max; i++)
        {
            T   c = pool.Get(random);
            int num;
            if (!dict.TryGetValue(c, out num))
            {
                num = 0;
            }
            num++;
            if (print)
            {
                BigBoss.Debug.w(Logs.Main, "Picked " + num + " " + c);
            }
            dict[c] = num;
        }

        pool.ToLog(Logs.Main);

        BigBoss.Debug.w(Logs.Main, "Real probability out of " + max);
        foreach (KeyValuePair <T, int> pair in dict)
        {
            BigBoss.Debug.w(Logs.Main, "  " + pair.Key + ": " + ((double)pair.Value / max * 100d) + " - " + pair.Value);
        }
    }
Exemplo n.º 3
0
 public static DrawAction <GenSpace> MergeIn <T>(ProbabilityPool <T> elements, System.Random random, Theme theme, GridType type = GridType.Doodad, bool typeOnlyDefault = false, bool themeOnlyDefault = false)
     where T : ThemeElement
 {
     return((arr, x, y) =>
     {
         MergeIn(arr, x, y, new GenDeploy(elements.Get(random)), theme, type, typeOnlyDefault, themeOnlyDefault);
         return true;
     });
 }
Exemplo n.º 4
0
    protected void Clear()
    {
        if (curLevel != -1)
        {
            currentPool = ProbabilityPool <T> .Create();

            curLevel = -1;
        }
    }
Exemplo n.º 5
0
    static PrimitiveCombiner()
    {
        defaultPrimitives = ProbabilityPool <BaseRoomMod> .Create();

        defaultPrimitives.Add(new CircleRoom(), .5, true);
        defaultPrimitives.Add(new SquareRoom(), 1);
        defaultPrimitives.Add(new RectangularRoom(), 1.5);
        defaultAmount = ProbabilityPool <byte> .Create();

        defaultAmount.Add(2, 5);
        defaultAmount.Add(3, 1);
        defaultAmount.Add(4, .4);
    }
Exemplo n.º 6
0
    protected bool ApplyMod <T>(RoomSpec spec, ProbabilityPool <T> mods)
        where T : RoomModifier
    {
        mods.BeginTaking();
        T mod;

        while (mods.Take(spec.Random, out mod))
        {
            #region DEBUG
            float stepTime = 0;
            if (BigBoss.Debug.logging(Logs.LevelGenMain))
            {
                BigBoss.Debug.w(Logs.LevelGenMain, "   Applying: " + mod);
            }
            if (BigBoss.Debug.logging(Logs.LevelGen))
            {
                stepTime = Time.realtimeSinceStartup;
                BigBoss.Debug.w(Logs.LevelGen, "Applying: " + mod);
            }
            #endregion
            Container2D <GenSpace> backupGrid = new MultiMap <GenSpace>(spec.Grids);
            if (mod.Modify(spec))
            {
                #region DEBUG
                if (BigBoss.Debug.logging(Logs.LevelGen))
                {
                    spec.Grids.ToLog(Logs.LevelGen, "Applying " + mod + " took " + (Time.realtimeSinceStartup - stepTime) + " seconds.");
                }
                #endregion
                mods.EndTaking();
                return(true);
            }
            else
            {
                spec.Grids = backupGrid;
                #region DEBUG
                if (BigBoss.Debug.logging(Logs.LevelGen))
                {
                    spec.Grids.ToLog(Logs.LevelGen, "Couldn't apply mod.  Processing " + mod + " took " + (Time.realtimeSinceStartup - stepTime) + " seconds.");
                }
                #endregion
            }
        }
        mods.EndTaking();
        return(false);
    }
Exemplo n.º 7
0
    public void Init()
    {
        _pool = ProbabilityPool <ThemeElement> .Create();

        foreach (PrefabProbabilityContainer cont in Elements)
        {
            if (cont.Item == null)
            {
                throw new ArgumentException("Prefab has to be not null");
            }
            if (cont.Multiplier <= 0)
            {
                cont.Multiplier = 1f;
            }
            _pool.Add(cont.Item, cont.Multiplier, cont.Unique);
        }
    }
Exemplo n.º 8
0
    public void Init()
    {
        _pool = ProbabilityPool <T> .Create();

        foreach (PrefabProbabilityContainer cont in Elements)
        {
            if (cont.Item == null)
            {
                throw new ArgumentException("Prefab has to be not null");
            }
            T t = cont.Item.GetComponentInChildren <T>();
            if (t == null)
            {
                throw new ArgumentException("Prefab of type " + cont.Item.GetType() + " has to be of type " + typeof(T));
            }
            _pool.Add(t, cont.Multiplier, cont.Unique);
        }
    }
Exemplo n.º 9
0
        public void Initialize(SectionTemplate sectionTemplate)
        {
            this.template = sectionTemplate;

#if UNITY_EDITOR
            gameObject.name = template.name;
#endif

            wallPool    = new GameObjectPool <WallColumn>(transform, template.WallColumnPrefab, template.MaxColumnCount);
            powerUpPool = new ProbabilityPool <PowerUp>(transform, template.GetPrefabProbabilityPairs(), template.MaxPowerUpCount);

            foreach (var pool in powerUpPool.GetPools())
            {
                foreach (var powerUp in pool.PooledItemsNonAloc)
                {
                    powerUp.Initialize(pool.PoolItem);
                }
            }
        }
Exemplo n.º 10
0
    public void SetFor(ushort level)
    {
        if (curLevel == level)
        {
            return;
        }
        currentPool = ProbabilityPool <T> .Create();

        foreach (ProbContainer prototype in prototypePool)
        {
            double multiplier = levelCurve(level, prototype.Level);
            multiplier = prototype.Multiplier * multiplier;
            if (multiplier < MAX_MULTIPLIER && multiplier > MIN_MULTIPLIER)
            {
                currentPool.Add(prototype.Item, multiplier, prototype.Unique);
            }
        }
        curLevel = level;
    }
Exemplo n.º 11
0
    public override void AddAll(ProbabilityPool <T> rhs)
    {
        LeveledPool <T> lrhs = rhs as LeveledPool <T>;

        if (lrhs == null)
        {
            foreach (ProbabilityItem <T> p in rhs)
            {
                AddInternal(p.Item, p.Multiplier, p.Unique, 1);
            }
        }
        else
        {
            foreach (ProbabilityItem <T> p in rhs)
            {
                ProbContainer cont = (ProbContainer)p;
                AddInternal(cont.Item, cont.Multiplier, cont.Unique, cont.Level);
            }
        }
        Clear();
    }
Exemplo n.º 12
0
 public abstract void AddAll(ProbabilityPool <T> rhs);
Exemplo n.º 13
0
 public PrimitiveCombiner(ProbabilityPool <byte> amountPool)
     : this(defaultPrimitives, amountPool)
 {
 }
Exemplo n.º 14
0
 public PrimitiveCombiner(ProbabilityPool <BaseRoomMod> roomPool)
     : this(roomPool, defaultAmount)
 {
 }
Exemplo n.º 15
0
 public PrimitiveCombiner(ProbabilityPool <BaseRoomMod> roomPool, ProbabilityPool <byte> amountPool)
 {
     _primitives = roomPool;
     _amounts    = amountPool;
 }
Exemplo n.º 16
0
 public override void AddAll(ProbabilityPool <ThemeElement> rhs)
 {
     pool.AddAll(rhs);
 }
Exemplo n.º 17
0
 public override void AddAll(ProbabilityPool <T> rhs)
 {
     _pool.AddAll(rhs);
 }