示例#1
0
        /// <summary>
        /// Adds a decor provider to the list.
        /// </summary>
        /// <param name="prefabID">The prefab ID of the provider.</param>
        /// <param name="provider">The provider to add.</param>
        /// <param name="decor">The provider's current decor score.</param>
        /// <returns>true if the decor score was changed, or false otherwise.</returns>
        public bool AddDecorProvider(Tag prefabID, DecorProvider provider, float decor)
        {
            BestDecorList values = null;
            bool          add    = false;

            if (provider == null)
            {
                throw new ArgumentNullException("provider");
            }
            lock (decorProviders) {
                if (decor < 0.0f && negativeDecor != null)
                {
                    // Hard mode mwahaha
                    if (!negativeDecor.ContainsKey(provider))
                    {
                        negativeDecor.Add(provider, decor);
                        Grid.Decor[cell] += decor;
                        add = true;
                    }
                }
                else if (!decorProviders.TryGetValue(prefabID, out values))
                {
                    decorProviders.Add(prefabID, values = new BestDecorList(cell));
                    UpdateNumPositive();
                }
            }
            if (values != null)
            {
                lock (values) {
                    add = values.AddDecorItem(decor, provider);
                }
            }
            return(add);
        }
示例#2
0
        /// <summary>
        /// Retrieves the decor score provided by the provider.
        /// </summary>
        /// <param name="provider">The decor provider to check.</param>
        /// <returns>The score provided by that provider, or 0 if it does not provide decor there.</returns>
        public float GetDecorProvidedBy(DecorProvider provider)
        {
            BestDecorList values = null;
            float         decor  = 0.0f;

            if (provider == null)
            {
                throw new ArgumentNullException("provider");
            }
            lock (decorProviders) {
                if (negativeDecor == null || !negativeDecor.TryGetValue(provider, out decor))
                {
                    decorProviders.TryGetValue(provider.PrefabID(), out values);
                }
            }
            if (values != null && provider == values.BestProvider)
            {
                decor = values.BestDecor;
            }
            return(decor);
        }
示例#3
0
        /// <summary>
        /// Removes a decor provider from the list.
        /// </summary>
        /// <param name="prefabID">The prefab ID of the provider.</param>
        /// <param name="provider">The provider to remove.</param>
        /// <param name="decor">The provider's current decor score.</param>
        /// <returns>true if the decor score was changed, or false otherwise.</returns>
        public bool RemoveDecorProvider(Tag prefabID, DecorProvider provider, float decor)
        {
            BestDecorList values  = null;
            bool          removed = false;

            if (provider == null)
            {
                throw new ArgumentNullException("provider");
            }
            lock (decorProviders) {
                if (decor < 0.0f && negativeDecor != null)
                {
                    // Remove in hard mode, single = is intentional
                    if (removed = negativeDecor.Remove(provider))
                    {
                        Grid.Decor[cell] -= decor;
                    }
                }
                else
                {
                    decorProviders.TryGetValue(prefabID, out values);
                }
            }
            if (values != null)
            {
                int count;
                // Lock the right things at the right times
                lock (values) {
                    removed = values.RemoveDecorItem(decor, provider);
                    count   = values.Count;
                }
                if (count < 1)
                {
                    lock (decorProviders) {
                        decorProviders.Remove(prefabID);
                    }
                }
            }
            return(removed);
        }